14 |
14 |
* @lastmodified $Date$
|
15 |
15 |
*
|
16 |
16 |
*/
|
17 |
|
|
18 |
|
function createNewsAccessFile($newLink, $oldLink, $page_id, $section_id, $post_id)
|
19 |
|
{
|
20 |
|
global $admin, $MESSAGE;
|
21 |
|
$sError = '';
|
22 |
|
$sPagesPath = WB_PATH.PAGES_DIRECTORY;
|
23 |
|
$sPostsPath = $sPagesPath.'/posts';
|
24 |
|
$sBackUrl = ADMIN_URL.'/pages/modify.php?page_id='.$page_id;
|
25 |
|
// delete old accessfile if link has changed
|
26 |
|
if(($newLink != $oldLink) && (is_writable($sPostsPath.$oldLink.PAGE_EXTENSION))) {
|
27 |
|
if(!unlink($sPostsPath.$oldLink.PAGE_EXTENSION)) {
|
28 |
|
$admin->print_error($MESSAGE['PAGES_CANNOT_DELETE_ACCESS_FILE'].' - '.$oldLink,$sBackUrl);
|
29 |
|
}
|
30 |
|
}
|
31 |
|
// all ok, now create new accessfile
|
32 |
|
$newFile = $sPagesPath.$newLink.PAGE_EXTENSION;
|
33 |
|
// $backSteps = preg_replace('/^'.preg_quote(WB_PATH).'/', '', $sPostsPath);
|
34 |
|
$aOptionalCommands = array(
|
35 |
|
'$section_id = '.$section_id,
|
36 |
|
'$post_id = '.$post_id ,
|
37 |
|
'$post_section = '.$section_id
|
38 |
|
);
|
39 |
|
if( ($sError = create_access_file($newFile, $page_id, 0, $aOptionalCommands))!==true )
|
40 |
|
{
|
41 |
|
$admin->print_error($sError,$sBackUrl );
|
42 |
|
}
|
43 |
|
} // end of function createNewsAccessFile
|
44 |
|
/* ************************************************************************** */
|
|
17 |
error_reporting(E_ALL);
|
45 |
18 |
require('../../config.php');
|
46 |
19 |
require_once(WB_PATH."/include/jscalendar/jscalendar-functions.php");
|
47 |
20 |
// Get post_id
|
... | ... | |
65 |
38 |
}
|
66 |
39 |
$admin->print_header();
|
67 |
40 |
|
68 |
|
// $sMediaUrl = WB_URL.MEDIA_DIRECTORY;
|
69 |
|
// $searchfor = '@(<[^>]*=\s*")('.preg_quote($sMediaUrl).')([^">]*".*>)@siU';
|
70 |
41 |
// Validate all fields
|
71 |
42 |
$title = $admin->StripCodeFromText($admin->get_post('title'));
|
72 |
43 |
$commenting = $admin->StripCodeFromText($admin->get_post('commenting'));
|
... | ... | |
81 |
52 |
} else {
|
82 |
53 |
$short = $admin->get_post('short');
|
83 |
54 |
$long = $admin->get_post('long');
|
84 |
|
// if(ini_get('magic_quotes_gpc')==true)
|
85 |
|
// {
|
86 |
|
// $short = $admin->strip_slashes($short);
|
87 |
|
// $long = $admin->strip_slashes($long);
|
88 |
|
// }
|
89 |
|
// $short = preg_replace($searchfor, '$1{SYSVAR:MEDIA_REL}$3', $short );
|
90 |
|
// $long = preg_replace($searchfor, '$1{SYSVAR:MEDIA_REL}$3', $long );
|
91 |
55 |
$short = $admin->ReplaceAbsoluteMediaUrl($short);
|
92 |
56 |
$long = $admin->ReplaceAbsoluteMediaUrl($long);
|
93 |
57 |
}
|
94 |
58 |
|
95 |
|
// Get page link URL
|
96 |
|
$sql = 'SELECT `link` FROM `'.TABLE_PREFIX.'pages` WHERE `page_id`='.(int)$page_id;
|
97 |
|
$oldLink = $database->get_one($sql);
|
98 |
59 |
// Include WB functions file
|
99 |
60 |
require(WB_PATH.'/framework/functions.php');
|
100 |
61 |
// Work-out what the link should be
|
101 |
|
$newLink = '/posts/'.page_filename($title).PAGE_SPACER.$post_id;
|
|
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 |
|
102 |
69 |
// get publisedwhen and publisheduntil
|
103 |
70 |
$publishedwhen = jscalendar_to_timestamp($admin->get_post_escaped('publishdate'));
|
104 |
71 |
if($publishedwhen == '' || $publishedwhen < 1) { $publishedwhen=0; }
|
... | ... | |
118 |
85 |
$sql .= '`posted_when`='.time().', ';
|
119 |
86 |
$sql .= '`posted_by`='.(int)$admin->get_user_id().' ';
|
120 |
87 |
$sql .= 'WHERE `post_id`='.(int)$post_id;
|
121 |
|
if( $database->query($sql) ) {
|
|
88 |
if( $database->query($sql) ) {
|
122 |
89 |
// create new accessfile
|
123 |
|
createNewsAccessFile($newLink, $oldLink, $page_id, $section_id, $post_id);
|
|
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 |
|
|
95 |
switch($sDoWhat)
|
|
96 |
{
|
|
97 |
case "update":
|
|
98 |
try {
|
|
99 |
$oAF = new AccessFile($sOldFilename, $page_id);
|
|
100 |
$oAF->rename($sNewFile);
|
|
101 |
unset($oAF);
|
|
102 |
}catch(AccessFileException $e) {
|
|
103 |
$admin->print_error($e,$sBackUrl);
|
|
104 |
}
|
|
105 |
break;
|
|
106 |
case "create":
|
|
107 |
try {
|
|
108 |
$oAF = new AccessFile($sNewFilename, $page_id);
|
|
109 |
$oAF->addVar('section_id', $section_id, AccessFile::VAR_INT);
|
|
110 |
$oAF->addVar('post_id', $post_id, AccessFile::VAR_INT);
|
|
111 |
$oAF->addVar('post_section', $section_id, AccessFile::VAR_INT);
|
|
112 |
$oAF->write();
|
|
113 |
unset($oAF);
|
|
114 |
}catch(AccessFileException $e) {
|
|
115 |
$admin->print_error($e,$sBackUrl);
|
|
116 |
}
|
|
117 |
break;
|
|
118 |
}
|
124 |
119 |
}
|
125 |
120 |
// Check if there is a db error, otherwise say successful
|
126 |
121 |
if($database->is_error()) {
|
... | ... | |
131 |
126 |
$admin->print_success($TEXT['SUCCESS'], ADMIN_URL.'/pages/modify.php?page_id='.$page_id);
|
132 |
127 |
}
|
133 |
128 |
// Print admin footer
|
134 |
|
$admin->print_footer();
|
|
129 |
$admin->print_footer();
|
class AccessFile implemented in modules/news