16 |
16 |
*/
|
17 |
17 |
error_reporting(E_ALL);
|
18 |
18 |
require('../../config.php');
|
19 |
|
require_once(WB_PATH."/include/jscalendar/jscalendar-functions.php");
|
|
19 |
$oReg = WbAdaptor::getInstance();
|
|
20 |
$oDb = WbDatabase::getInstance();
|
|
21 |
$sNewsLinkSubdir = 'posts/';
|
|
22 |
// require_once($oReg->AppPath."include/jscalendar/jscalendar-functions.php");
|
20 |
23 |
// Get post_id
|
21 |
|
if(!isset($_POST['post_id']) OR !is_numeric($_POST['post_id'])) {
|
22 |
|
header("Location: ".ADMIN_URL."/pages/index.php");
|
|
24 |
if (!isset($_POST['post_id']) || !($post_id = intval($_POST['post_id']))) {
|
|
25 |
header("Location: ".$oReg->AcpUrl.'pages/index.php');
|
23 |
26 |
exit( 0 );
|
24 |
|
}else {
|
25 |
|
$post_id = intval($_POST['post_id']);
|
26 |
|
}
|
27 |
|
|
|
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 |
// }
|
28 |
34 |
$admin_header = false;
|
29 |
35 |
// Tells script to update when this page was last updated
|
30 |
36 |
$update_when_modified = true;
|
31 |
37 |
// Include WB admin wrapper script
|
32 |
|
require(WB_PATH.'/modules/admin.php');
|
33 |
|
|
|
38 |
require($oReg->AppPath.'modules/admin.php');
|
|
39 |
$oReg->getWbConstants();
|
34 |
40 |
if (!$admin->checkFTAN()) {
|
35 |
41 |
$admin->print_header();
|
36 |
42 |
$admin->print_error($MESSAGE['GENERIC_SECURITY_ACCESS'],
|
37 |
|
ADMIN_URL.'/pages/modify.php?page_id='.$page_id );
|
|
43 |
$oReg->AcpUrl.'pages/modify.php?page_id='.$page_id );
|
38 |
44 |
}
|
39 |
45 |
$admin->print_header();
|
40 |
46 |
|
41 |
47 |
// Validate all fields
|
42 |
|
$title = $admin->StripCodeFromText($admin->get_post('title'));
|
43 |
|
$commenting = $admin->StripCodeFromText($admin->get_post('commenting'));
|
44 |
|
$active = intval($admin->get_post('active'));
|
45 |
|
$old_link = $admin->StripCodeFromText($admin->get_post('link'));
|
46 |
|
$group_id = intval($admin->get_post('group'));
|
47 |
|
|
48 |
48 |
if($admin->get_post('title') == '' AND $admin->get_post('url') == '') {
|
49 |
|
$recallUrl = WB_URL.'/modules/news/modify_post.php?page_id='.$page_id.
|
|
49 |
$recallUrl = $oReg->AppUrl.'modules/news/modify_post.php?page_id='.$page_id.
|
50 |
50 |
'§ion_id='.$section_id.'&post_id='.$admin->getIDKEY($post_id);
|
51 |
51 |
$admin->print_error($MESSAGE['GENERIC_FILL_IN_ALL'], $recallUrl);
|
52 |
52 |
} else {
|
53 |
|
$short = $admin->get_post('short');
|
54 |
|
$long = $admin->get_post('long');
|
55 |
|
$short = $admin->ReplaceAbsoluteMediaUrl($short);
|
56 |
|
$long = $admin->ReplaceAbsoluteMediaUrl($long);
|
|
53 |
$short = $admin->ReplaceAbsoluteMediaUrl($admin->get_post('short'));
|
|
54 |
$long = $admin->ReplaceAbsoluteMediaUrl($admin->get_post('long'));
|
57 |
55 |
}
|
58 |
|
|
|
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'));
|
59 |
60 |
// Include WB functions file
|
60 |
|
require(WB_PATH.'/framework/functions.php');
|
61 |
|
// Work-out what the link should be
|
62 |
|
$sNewFile = page_filename($title).PAGE_SPACER.$post_id;
|
63 |
|
$newLink = '/posts/'.$sNewFile;
|
64 |
|
$sPagesPath = WB_PATH.PAGES_DIRECTORY;
|
65 |
|
$sBackUrl = ADMIN_URL.'/pages/modify.php?page_id='.$page_id;
|
66 |
|
$sNewFilename = $sPagesPath.$newLink.PAGE_EXTENSION;
|
67 |
|
$sOldFilename = $sPagesPath.$old_link.PAGE_EXTENSION;
|
68 |
|
|
|
61 |
require($oReg->AppPath.'framework/functions.php');
|
|
62 |
// Work-out all needed path and filenames
|
|
63 |
$sAccessFsileRootPath = $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 |
69 |
// get publisedwhen and publisheduntil
|
70 |
|
$publishedwhen = jscalendar_to_timestamp($admin->get_post_escaped('publishdate'));
|
71 |
|
if($publishedwhen == '' || $publishedwhen < 1) { $publishedwhen=0; }
|
72 |
|
$publisheduntil = jscalendar_to_timestamp($admin->get_post_escaped('enddate'), $publishedwhen);
|
73 |
|
if($publisheduntil == '' || $publisheduntil < 1) { $publisheduntil=0; }
|
74 |
|
// Update row
|
75 |
|
$sql = 'UPDATE `'.TABLE_PREFIX.'mod_news_posts` '
|
|
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 |
76 |
. 'SET `group_id`='.(int)$group_id.', '
|
77 |
|
. '`title`=\''.$database->escapeString($title).'\', '
|
78 |
|
. '`link`=\''.$database->escapeString($newLink).'\', '
|
79 |
|
. '`content_short`=\''.$database->escapeString($short).'\', '
|
80 |
|
. '`content_long`=\''.$database->escapeString($long).'\', '
|
81 |
|
. '`commenting`=\''.$database->escapeString($commenting).'\', '
|
|
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 |
82 |
. '`active`='.(int)$active.', '
|
83 |
83 |
. '`published_when`='.(int)$publishedwhen.', '
|
84 |
84 |
. '`published_until`='.(int)$publisheduntil.', '
|
85 |
85 |
. '`posted_when`='.time().', '
|
86 |
86 |
. '`posted_by`='.(int)$admin->get_user_id().' '
|
87 |
87 |
. 'WHERE `post_id`='.(int)$post_id;
|
88 |
|
if( $database->query($sql) ) {
|
89 |
|
// create new accessfile
|
90 |
|
$sDoWhat = (($newLink == $old_link) && (file_exists($sNewFilename))) ? "nothing" : "action";
|
91 |
|
if($sDoWhat == "action") {
|
92 |
|
$sDoWhat = (($sDoWhat == "action") && file_exists($sOldFilename)) ? "update" : "create";
|
93 |
|
}
|
94 |
|
|
|
88 |
if ($oDb->query($sql)) {
|
|
89 |
// create new accessfile
|
|
90 |
$sDoWhat = (($sNewLink == $sOldLink) && (file_exists($sNewFilename)))
|
|
91 |
? "nothing"
|
|
92 |
: ((file_exists($sOldFilename)) ? "update" : "create");
|
95 |
93 |
switch($sDoWhat)
|
96 |
94 |
{
|
97 |
95 |
case "update":
|
98 |
96 |
try {
|
99 |
|
// prozedural rename accessfile if link has changed, has to be changed to accessfile class when fixed
|
100 |
|
if(($sNewFilename != $sOldFilename) && (is_writable($sOldFilename))) {
|
101 |
|
if(!rename($sOldFilename,$sNewFilename)) {
|
102 |
|
$admin->print_error($MESSAGE['PAGES_CANNOT_DELETE_ACCESS_FILE'].' - '.$oldLink,$sBackUrl);
|
103 |
|
}
|
104 |
|
}
|
105 |
|
// $oAF = new AccessFile($sOldFilename, $page_id);
|
106 |
|
// $oAF->rename($sNewFile);
|
107 |
|
// unset($oAF);
|
|
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);
|
108 |
106 |
}catch(AccessFileException $e) {
|
109 |
107 |
$admin->print_error($e,$sBackUrl);
|
110 |
108 |
}
|
111 |
109 |
break;
|
112 |
110 |
case "create":
|
113 |
111 |
try {
|
114 |
|
$oAF = new AccessFile($sNewFilename, $page_id);
|
|
112 |
$oAF = new AccessFile($sAccessFileRootPath, $sNewLink, $page_id);
|
115 |
113 |
$oAF->addVar('section_id', $section_id, AccessFile::VAR_INT);
|
116 |
114 |
$oAF->addVar('post_id', $post_id, AccessFile::VAR_INT);
|
117 |
115 |
$oAF->addVar('post_section', $section_id, AccessFile::VAR_INT);
|
... | ... | |
124 |
122 |
}
|
125 |
123 |
}
|
126 |
124 |
// Check if there is a db error, otherwise say successful
|
127 |
|
if($database->is_error()) {
|
128 |
|
$recallUrl = WB_URL.'/modules/news/modify_post.php?page_id='.$page_id.
|
|
125 |
if($oDb->is_error()) {
|
|
126 |
$recallUrl = $oReg->AppUrl.'modules/news/modify_post.php?page_id='.$page_id.
|
129 |
127 |
'§ion_id='.$section_id.'&post_id='.$admin->getIDKEY($post_id);
|
130 |
|
$admin->print_error($database->get_error(), $recallUrl);
|
|
128 |
$admin->print_error($oDb->get_error(), $recallUrl);
|
131 |
129 |
}else {
|
132 |
|
$admin->print_success($TEXT['SUCCESS'], ADMIN_URL.'/pages/modify.php?page_id='.$page_id);
|
|
130 |
$admin->print_success($TEXT['SUCCESS'], $oReg->AcpUrl.'pages/modify.php?page_id='.$page_id);
|
133 |
131 |
}
|
134 |
132 |
// Print admin footer
|
135 |
|
$admin->print_footer();
|
|
133 |
$admin->print_footer();
|
! module News: some little fixes, implementation of AccessFile completed.