1 |
1425
|
Luisehahne
|
<?php
|
2 |
|
|
/**
|
3 |
|
|
*
|
4 |
|
|
* @category modules
|
5 |
|
|
* @package news
|
6 |
|
|
* @author WebsiteBaker Project
|
7 |
1918
|
Luisehahne
|
* @copyright 2009-2013, WebsiteBaker Org. e.V.
|
8 |
|
|
* @link http://www.websitebaker.org/
|
9 |
1425
|
Luisehahne
|
* @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$
|
13 |
1918
|
Luisehahne
|
* @filesource $HeadURL$
|
14 |
1425
|
Luisehahne
|
* @lastmodified $Date$
|
15 |
|
|
*
|
16 |
|
|
*/
|
17 |
2028
|
Luisehahne
|
error_reporting(E_ALL);
|
18 |
1457
|
Luisehahne
|
require('../../config.php');
|
19 |
2069
|
darkviper
|
$oReg = WbAdaptor::getInstance();
|
20 |
|
|
$oDb = WbDatabase::getInstance();
|
21 |
|
|
$sNewsLinkSubdir = 'posts/';
|
22 |
|
|
// require_once($oReg->AppPath."include/jscalendar/jscalendar-functions.php");
|
23 |
1457
|
Luisehahne
|
// Get post_id
|
24 |
2069
|
darkviper
|
if (!isset($_POST['post_id']) || !($post_id = intval($_POST['post_id']))) {
|
25 |
|
|
header("Location: ".$oReg->AcpUrl.'pages/index.php');
|
26 |
1457
|
Luisehahne
|
exit( 0 );
|
27 |
2069
|
darkviper
|
}
|
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 |
1457
|
Luisehahne
|
$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 |
2069
|
darkviper
|
require($oReg->AppPath.'modules/admin.php');
|
39 |
|
|
$oReg->getWbConstants();
|
40 |
1457
|
Luisehahne
|
if (!$admin->checkFTAN()) {
|
41 |
|
|
$admin->print_header();
|
42 |
|
|
$admin->print_error($MESSAGE['GENERIC_SECURITY_ACCESS'],
|
43 |
2069
|
darkviper
|
$oReg->AcpUrl.'pages/modify.php?page_id='.$page_id );
|
44 |
1425
|
Luisehahne
|
}
|
45 |
1457
|
Luisehahne
|
$admin->print_header();
|
46 |
1425
|
Luisehahne
|
|
47 |
|
|
// Validate all fields
|
48 |
1457
|
Luisehahne
|
if($admin->get_post('title') == '' AND $admin->get_post('url') == '') {
|
49 |
2069
|
darkviper
|
$recallUrl = $oReg->AppUrl.'modules/news/modify_post.php?page_id='.$page_id.
|
50 |
1457
|
Luisehahne
|
'§ion_id='.$section_id.'&post_id='.$admin->getIDKEY($post_id);
|
51 |
1868
|
Luisehahne
|
$admin->print_error($MESSAGE['GENERIC_FILL_IN_ALL'], $recallUrl);
|
52 |
1918
|
Luisehahne
|
} else {
|
53 |
2069
|
darkviper
|
$short = $admin->ReplaceAbsoluteMediaUrl($admin->get_post('short'));
|
54 |
|
|
$long = $admin->ReplaceAbsoluteMediaUrl($admin->get_post('long'));
|
55 |
1457
|
Luisehahne
|
}
|
56 |
2069
|
darkviper
|
$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 |
1425
|
Luisehahne
|
// Include WB functions file
|
61 |
2069
|
darkviper
|
require($oReg->AppPath.'framework/functions.php');
|
62 |
2077
|
darkviper
|
// Work-out all needed path and filenames
|
63 |
|
|
$sAccessFileRootPath = $oReg->AppPath.$oReg->PagesDir.$sNewsLinkSubdir;
|
64 |
2069
|
darkviper
|
$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 |
2077
|
darkviper
|
// get publisedwhen and publisheduntil
|
70 |
2069
|
darkviper
|
$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 |
2028
|
Luisehahne
|
. 'SET `group_id`='.(int)$group_id.', '
|
77 |
2069
|
darkviper
|
. '`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 |
2028
|
Luisehahne
|
. '`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 |
2069
|
darkviper
|
if ($oDb->query($sql)) {
|
89 |
|
|
// create new accessfile
|
90 |
|
|
$sDoWhat = (($sNewLink == $sOldLink) && (file_exists($sNewFilename)))
|
91 |
|
|
? "nothing"
|
92 |
|
|
: ((file_exists($sOldFilename)) ? "update" : "create");
|
93 |
1950
|
darkviper
|
switch($sDoWhat)
|
94 |
|
|
{
|
95 |
|
|
case "update":
|
96 |
|
|
try {
|
97 |
2069
|
darkviper
|
//// 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 |
1950
|
darkviper
|
}catch(AccessFileException $e) {
|
107 |
|
|
$admin->print_error($e,$sBackUrl);
|
108 |
|
|
}
|
109 |
|
|
break;
|
110 |
|
|
case "create":
|
111 |
|
|
try {
|
112 |
2069
|
darkviper
|
$oAF = new AccessFile($sAccessFileRootPath, $sNewLink, $page_id);
|
113 |
1950
|
darkviper
|
$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 |
1868
|
Luisehahne
|
}
|
124 |
1425
|
Luisehahne
|
// Check if there is a db error, otherwise say successful
|
125 |
2069
|
darkviper
|
if($oDb->is_error()) {
|
126 |
|
|
$recallUrl = $oReg->AppUrl.'modules/news/modify_post.php?page_id='.$page_id.
|
127 |
1457
|
Luisehahne
|
'§ion_id='.$section_id.'&post_id='.$admin->getIDKEY($post_id);
|
128 |
2069
|
darkviper
|
$admin->print_error($oDb->get_error(), $recallUrl);
|
129 |
1457
|
Luisehahne
|
}else {
|
130 |
2069
|
darkviper
|
$admin->print_success($TEXT['SUCCESS'], $oReg->AcpUrl.'pages/modify.php?page_id='.$page_id);
|
131 |
1457
|
Luisehahne
|
}
|
132 |
1425
|
Luisehahne
|
// Print admin footer
|
133 |
2069
|
darkviper
|
$admin->print_footer();
|