1
|
<?php
|
2
|
/**
|
3
|
*
|
4
|
* @category modules
|
5
|
* @package news
|
6
|
* @author WebsiteBaker Project
|
7
|
* @copyright 2009-2013, WebsiteBaker Org. e.V.
|
8
|
* @link http://www.websitebaker.org/
|
9
|
* @license http://www.gnu.org/licenses/gpl.html
|
10
|
* @platform WebsiteBaker 2.8.x
|
11
|
* @requirements PHP 5.2.2 and higher
|
12
|
* @version $Id: save_post.php 2077 2014-01-06 23:33:51Z darkviper $
|
13
|
* @filesource $HeadURL: svn://isteam.dynxs.de/wb-archiv/branches/2.8.x/wb/modules/news/save_post.php $
|
14
|
* @lastmodified $Date: 2014-01-07 00:33:51 +0100 (Tue, 07 Jan 2014) $
|
15
|
*
|
16
|
*/
|
17
|
error_reporting(E_ALL);
|
18
|
require('../../config.php');
|
19
|
$oReg = WbAdaptor::getInstance();
|
20
|
$oDb = WbDatabase::getInstance();
|
21
|
$sNewsLinkSubdir = 'posts/';
|
22
|
// require_once($oReg->AppPath."include/jscalendar/jscalendar-functions.php");
|
23
|
// Get post_id
|
24
|
if (!isset($_POST['post_id']) || !($post_id = intval($_POST['post_id']))) {
|
25
|
header("Location: ".$oReg->AcpUrl.'pages/index.php');
|
26
|
exit( 0 );
|
27
|
}
|
28
|
// if(!isset($_POST['post_id']) OR !is_numeric($_POST['post_id'])) {
|
29
|
// header("Location: ".$oReg->AcpUrl.'pages/index.php');
|
30
|
// exit( 0 );
|
31
|
// }else {
|
32
|
// $post_id = intval($_POST['post_id']);
|
33
|
// }
|
34
|
$admin_header = false;
|
35
|
// Tells script to update when this page was last updated
|
36
|
$update_when_modified = true;
|
37
|
// Include WB admin wrapper script
|
38
|
require($oReg->AppPath.'modules/admin.php');
|
39
|
$oReg->getWbConstants();
|
40
|
if (!$admin->checkFTAN()) {
|
41
|
$admin->print_header();
|
42
|
$admin->print_error($MESSAGE['GENERIC_SECURITY_ACCESS'],
|
43
|
$oReg->AcpUrl.'pages/modify.php?page_id='.$page_id );
|
44
|
}
|
45
|
$admin->print_header();
|
46
|
|
47
|
// Validate all fields
|
48
|
if($admin->get_post('title') == '' AND $admin->get_post('url') == '') {
|
49
|
$recallUrl = $oReg->AppUrl.'modules/news/modify_post.php?page_id='.$page_id.
|
50
|
'§ion_id='.$section_id.'&post_id='.$admin->getIDKEY($post_id);
|
51
|
$admin->print_error($MESSAGE['GENERIC_FILL_IN_ALL'], $recallUrl);
|
52
|
} else {
|
53
|
$short = $admin->ReplaceAbsoluteMediaUrl($admin->get_post('short'));
|
54
|
$long = $admin->ReplaceAbsoluteMediaUrl($admin->get_post('long'));
|
55
|
}
|
56
|
$title = $admin->StripCodeFromText($admin->get_post('title'));
|
57
|
$commenting = $admin->StripCodeFromText($admin->get_post('commenting'));
|
58
|
$active = intval($admin->get_post('active'));
|
59
|
$group_id = intval($admin->get_post('group'));
|
60
|
// Include WB functions file
|
61
|
require($oReg->AppPath.'framework/functions.php');
|
62
|
// Work-out all needed path and filenames
|
63
|
$sAccessFileRootPath = $oReg->AppPath.$oReg->PagesDir.$sNewsLinkSubdir;
|
64
|
$sOldLink = preg_replace('/^\/?'.preg_quote($sNewsLinkSubdir, '/').'/', '', str_replace('\\', '/', $admin->StripCodeFromText($admin->get_post('link'))));
|
65
|
$sOldFilename = $sAccessFileRootPath.$sOldLink.$oReg->PageExtension;
|
66
|
$sNewLink = page_filename($title).$oReg->PageSpacer.$post_id;
|
67
|
$sNewFilename = $sAccessFileRootPath.$sNewLink.$oReg->PageExtension;
|
68
|
$sBackUrl = $oReg->AcpUrl.'pages/modify.php?page_id='.$page_id;
|
69
|
// get publisedwhen and publisheduntil
|
70
|
$x = strtotime(preg_replace('/^(\d{1,2})\.(\d{1,2})\.(\d{2,4})(.*)$/s', '\2/\1/\3\4', $admin->get_post_escaped('publishdate')));
|
71
|
$publishedwhen = $x ? $x : 0;
|
72
|
$x = strtotime(preg_replace('/^(\d{1,2})\.(\d{1,2})\.(\d{2,4})(.*)$/s', '\2/\1/\3\4', $admin->get_post_escaped('enddate')), $publishedwhen);
|
73
|
$publisheduntil = $x ? $x : 0;
|
74
|
// Update row in database
|
75
|
$sql = 'UPDATE `'.$oDb->TablePrefix.'mod_news_posts` '
|
76
|
. 'SET `group_id`='.(int)$group_id.', '
|
77
|
. '`title`=\''.$oDb->escapeString($title).'\', '
|
78
|
. '`link`=\''.$oDb->escapeString('/'.$sNewsLinkSubdir.$sNewLink).'\', '
|
79
|
. '`content_short`=\''.$oDb->escapeString($short).'\', '
|
80
|
. '`content_long`=\''.$oDb->escapeString($long).'\', '
|
81
|
. '`commenting`=\''.$oDb->escapeString($commenting).'\', '
|
82
|
. '`active`='.(int)$active.', '
|
83
|
. '`published_when`='.(int)$publishedwhen.', '
|
84
|
. '`published_until`='.(int)$publisheduntil.', '
|
85
|
. '`posted_when`='.time().', '
|
86
|
. '`posted_by`='.(int)$admin->get_user_id().' '
|
87
|
. 'WHERE `post_id`='.(int)$post_id;
|
88
|
if ($oDb->query($sql)) {
|
89
|
// create new accessfile
|
90
|
$sDoWhat = (($sNewLink == $sOldLink) && (file_exists($sNewFilename)))
|
91
|
? "nothing"
|
92
|
: ((file_exists($sOldFilename)) ? "update" : "create");
|
93
|
switch($sDoWhat)
|
94
|
{
|
95
|
case "update":
|
96
|
try {
|
97
|
//// prozedural rename accessfile if link has changed, has to be changed to accessfile class when fixed
|
98
|
// if(($sNewFilename != $sOldFilename) && (is_writable($sOldFilename))) {
|
99
|
// if(!rename($sOldFilename,$sNewFilename)) {
|
100
|
// $admin->print_error($MESSAGE['PAGES_CANNOT_DELETE_ACCESS_FILE'].' - '.$oldLink,$sBackUrl);
|
101
|
// }
|
102
|
// }
|
103
|
$oAF = new AccessFile($sAccessFileRootPath, $sOldLink, $page_id);
|
104
|
$oAF->rename($sNewLink);
|
105
|
unset($oAF);
|
106
|
}catch(AccessFileException $e) {
|
107
|
$admin->print_error($e,$sBackUrl);
|
108
|
}
|
109
|
break;
|
110
|
case "create":
|
111
|
try {
|
112
|
$oAF = new AccessFile($sAccessFileRootPath, $sNewLink, $page_id);
|
113
|
$oAF->addVar('section_id', $section_id, AccessFile::VAR_INT);
|
114
|
$oAF->addVar('post_id', $post_id, AccessFile::VAR_INT);
|
115
|
$oAF->addVar('post_section', $section_id, AccessFile::VAR_INT);
|
116
|
$oAF->write();
|
117
|
unset($oAF);
|
118
|
}catch(AccessFileException $e) {
|
119
|
$admin->print_error($e,$sBackUrl);
|
120
|
}
|
121
|
break;
|
122
|
}
|
123
|
}
|
124
|
// Check if there is a db error, otherwise say successful
|
125
|
if($oDb->is_error()) {
|
126
|
$recallUrl = $oReg->AppUrl.'modules/news/modify_post.php?page_id='.$page_id.
|
127
|
'§ion_id='.$section_id.'&post_id='.$admin->getIDKEY($post_id);
|
128
|
$admin->print_error($oDb->get_error(), $recallUrl);
|
129
|
}else {
|
130
|
$admin->print_success($TEXT['SUCCESS'], $oReg->AcpUrl.'pages/modify.php?page_id='.$page_id);
|
131
|
}
|
132
|
// Print admin footer
|
133
|
$admin->print_footer();
|