1
|
<?php
|
2
|
/**
|
3
|
*
|
4
|
* @category modules
|
5
|
* @package news
|
6
|
* @author WebsiteBaker Project
|
7
|
* @copyright 2009-2011, Website Baker Org. e.V.
|
8
|
* @link http://www.websitebaker2.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 1868 2013-02-19 21:07:19Z Luisehahne $
|
13
|
* @filesource $HeadURL: svn://isteam.dynxs.de/wb-archiv/branches/2.8.x/wb/modules/news/save_post.php $
|
14
|
* @lastmodified $Date: 2013-02-19 22:07:19 +0100 (Tue, 19 Feb 2013) $
|
15
|
*
|
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
|
/* ************************************************************************** */
|
45
|
require('../../config.php');
|
46
|
require_once(WB_PATH."/include/jscalendar/jscalendar-functions.php");
|
47
|
// Get post_id
|
48
|
if(!isset($_POST['post_id']) OR !is_numeric($_POST['post_id'])) {
|
49
|
header("Location: ".ADMIN_URL."/pages/index.php");
|
50
|
exit( 0 );
|
51
|
}else {
|
52
|
$post_id = intval($_POST['post_id']);
|
53
|
}
|
54
|
|
55
|
$admin_header = false;
|
56
|
// Tells script to update when this page was last updated
|
57
|
$update_when_modified = true;
|
58
|
// Include WB admin wrapper script
|
59
|
require(WB_PATH.'/modules/admin.php');
|
60
|
|
61
|
if (!$admin->checkFTAN()) {
|
62
|
$admin->print_header();
|
63
|
$admin->print_error($MESSAGE['GENERIC_SECURITY_ACCESS'],
|
64
|
ADMIN_URL.'/pages/modify.php?page_id='.$page_id );
|
65
|
}
|
66
|
$admin->print_header();
|
67
|
|
68
|
// Validate all fields
|
69
|
if($admin->get_post('title') == '' AND $admin->get_post('url') == '') {
|
70
|
$recallUrl = WB_URL.'/modules/news/modify_post.php?page_id='.$page_id.
|
71
|
'§ion_id='.$section_id.'&post_id='.$admin->getIDKEY($post_id);
|
72
|
$admin->print_error($MESSAGE['GENERIC_FILL_IN_ALL'], $recallUrl);
|
73
|
}else {
|
74
|
$title = $admin->get_post_escaped('title');
|
75
|
$short = $admin->get_post_escaped('short');
|
76
|
$long = $admin->get_post_escaped('long');
|
77
|
$commenting = $admin->get_post_escaped('commenting');
|
78
|
$active = $admin->get_post_escaped('active');
|
79
|
$old_link = $admin->get_post_escaped('link');
|
80
|
$group_id = $admin->get_post_escaped('group');
|
81
|
}
|
82
|
// Get page link URL
|
83
|
$sql = 'SELECT `link` FROM `'.TABLE_PREFIX.'pages` WHERE `page_id`='.(int)$page_id;
|
84
|
$oldLink = $database->get_one($sql);
|
85
|
// Include WB functions file
|
86
|
require(WB_PATH.'/framework/functions.php');
|
87
|
// Work-out what the link should be
|
88
|
$newLink = '/posts/'.page_filename($title).PAGE_SPACER.$post_id;
|
89
|
// get publisedwhen and publisheduntil
|
90
|
$publishedwhen = jscalendar_to_timestamp($admin->get_post_escaped('publishdate'));
|
91
|
if($publishedwhen == '' || $publishedwhen < 1) { $publishedwhen=0; }
|
92
|
$publisheduntil = jscalendar_to_timestamp($admin->get_post_escaped('enddate'), $publishedwhen);
|
93
|
if($publisheduntil == '' || $publisheduntil < 1) { $publisheduntil=0; }
|
94
|
// Update row
|
95
|
$sql = 'UPDATE `'.TABLE_PREFIX.'mod_news_posts` ';
|
96
|
$sql .= 'SET `group_id`='.(int)$group_id.', ';
|
97
|
$sql .= '`title`=\''.$title.'\', ';
|
98
|
$sql .= '`link`=\''.$newLink.'\', ';
|
99
|
$sql .= '`content_short`=\''.$short.'\', ';
|
100
|
$sql .= '`content_long`=\''.$long.'\', ';
|
101
|
$sql .= '`commenting`=\''.$commenting.'\', ';
|
102
|
$sql .= '`active`='.(int)$active.', ';
|
103
|
$sql .= '`published_when`='.(int)$publishedwhen.', ';
|
104
|
$sql .= '`published_until`='.(int)$publisheduntil.', ';
|
105
|
$sql .= '`posted_when`='.time().', ';
|
106
|
$sql .= '`posted_by`='.(int)$admin->get_user_id().' ';
|
107
|
$sql .= 'WHERE `post_id`='.(int)$post_id;
|
108
|
if( $database->query($sql) ) {
|
109
|
// create new accessfile
|
110
|
createNewsAccessFile($newLink, $oldLink, $page_id, $section_id, $post_id);
|
111
|
}
|
112
|
// Check if there is a db error, otherwise say successful
|
113
|
if($database->is_error()) {
|
114
|
$recallUrl = WB_URL.'/modules/news/modify_post.php?page_id='.$page_id.
|
115
|
'§ion_id='.$section_id.'&post_id='.$admin->getIDKEY($post_id);
|
116
|
$admin->print_error($database->get_error(), $recallUrl);
|
117
|
}else {
|
118
|
$admin->print_success($TEXT['SUCCESS'], ADMIN_URL.'/pages/modify.php?page_id='.$page_id);
|
119
|
}
|
120
|
// Print admin footer
|
121
|
$admin->print_footer();
|