1
|
<?php
|
2
|
/**
|
3
|
*
|
4
|
* @category modules
|
5
|
* @package news
|
6
|
* @author WebsiteBaker Project
|
7
|
* @copyright 2004-2009, Ryan Djurovich
|
8
|
* @copyright 2009-2011, Website Baker Org. e.V.
|
9
|
* @link http://www.websitebaker2.org/
|
10
|
* @license http://www.gnu.org/licenses/gpl.html
|
11
|
* @platform WebsiteBaker 2.8.x
|
12
|
* @requirements PHP 5.2.2 and higher
|
13
|
* @version $Id: save_post.php 1457 2011-06-25 17:18:50Z Luisehahne $
|
14
|
* @filesource $HeadURL: svn://isteam.dynxs.de/wb-archiv/tags/2.8.2/wb/modules/news/save_post.php $
|
15
|
* @lastmodified $Date: 2011-06-25 19:18:50 +0200 (Sat, 25 Jun 2011) $
|
16
|
*
|
17
|
*/
|
18
|
|
19
|
function createNewsAccessFile($newLink, $oldLink, $page_id, $section_id, $post_id)
|
20
|
{
|
21
|
global $admin, $MESSAGE;
|
22
|
$sPagesPath = WB_PATH.PAGES_DIRECTORY;
|
23
|
$sPostsPath = $sPagesPath.'/posts';
|
24
|
// create /posts/ - directory if not exists
|
25
|
if(!file_exists($sPostsPath)) {
|
26
|
if(is_writable($sPagesPath)) {
|
27
|
make_dir(WB_PATH.PAGES_DIRECTORY.'/posts/');
|
28
|
}else {
|
29
|
$admin->print_error($MESSAGE['PAGES_CANNOT_CREATE_ACCESS_FILE']);
|
30
|
}
|
31
|
}
|
32
|
// check if /posts/ - dir is writable
|
33
|
if(!is_writable($sPostsPath.'/')) {
|
34
|
$admin->print_error($MESSAGE['PAGES_CANNOT_CREATE_ACCESS_FILE']);
|
35
|
}
|
36
|
// delete old accessfile if link has changed
|
37
|
if(($newLink != $oldLink) && (is_writable($sPostsPath.$oldLink.PAGE_EXTENSION))) {
|
38
|
if(!unlink($sPostsPath.$oldLink.PAGE_EXTENSION)) {
|
39
|
$admin->print_error($MESSAGE['PAGES_CANNOT_DELETE_ACCESS_FILE'].' - '.$oldLink);
|
40
|
}
|
41
|
}
|
42
|
// all ok, now create new accessfile
|
43
|
$newFile = $sPagesPath.$newLink.PAGE_EXTENSION;
|
44
|
// $backSteps = preg_replace('/^'.preg_quote(WB_PATH).'/', '', $sPostsPath);
|
45
|
$backSteps = preg_replace('@^'.preg_quote(WB_PATH).'@', '', $sPostsPath);
|
46
|
$backSteps = str_repeat( '../', substr_count($backSteps, '/'));
|
47
|
$content =
|
48
|
'<?php'."\n".
|
49
|
'// *** This file is generated by WebsiteBaker Ver.'.WB_VERSION."\n".
|
50
|
'// *** Creation date: '.date('c')."\n".
|
51
|
'// *** Do not modify this file manually'."\n".
|
52
|
'// *** WB will rebuild this file from time to time!!'."\n".
|
53
|
'// *************************************************'."\n".
|
54
|
"\t".'$page_id = '.$page_id.';'."\n".
|
55
|
"\t".'$section_id = '.$section_id.';'."\n".
|
56
|
"\t".'$post_id = '.$post_id.';'."\n".
|
57
|
"\t".'$post_section = '.$section_id.';'."\n".
|
58
|
// "\t".'define(\'POST_SECTION\', '.$section_id.');'."\n".
|
59
|
// "\t".'define(\'POST_ID\', '.$post_id.');'."\n".
|
60
|
"\t".'require(\''.$backSteps.'index.php\');'."\n".
|
61
|
'// *************************************************'."\n";
|
62
|
if( file_put_contents($newFile, $content) !== false ) {
|
63
|
// Chmod the file
|
64
|
change_mode($newFile);
|
65
|
}else {
|
66
|
$admin->print_error($MESSAGE['PAGES_CANNOT_CREATE_ACCESS_FILE'],ADMIN_URL.'/pages/modify.php?page_id='.$page_id);
|
67
|
// $admin->print_error($MESSAGE['PAGES_CANNOT_CREATE_ACCESS_FILE'].': '.$newFile);
|
68
|
|
69
|
}
|
70
|
} // end of function createNewsAccessFile
|
71
|
/* ************************************************************************** */
|
72
|
require('../../config.php');
|
73
|
require_once(WB_PATH."/include/jscalendar/jscalendar-functions.php");
|
74
|
// Get post_id
|
75
|
if(!isset($_POST['post_id']) OR !is_numeric($_POST['post_id'])) {
|
76
|
header("Location: ".ADMIN_URL."/pages/index.php");
|
77
|
exit( 0 );
|
78
|
}else {
|
79
|
$post_id = intval($_POST['post_id']);
|
80
|
}
|
81
|
|
82
|
$admin_header = false;
|
83
|
// Tells script to update when this page was last updated
|
84
|
$update_when_modified = true;
|
85
|
// Include WB admin wrapper script
|
86
|
require(WB_PATH.'/modules/admin.php');
|
87
|
|
88
|
if (!$admin->checkFTAN()) {
|
89
|
$admin->print_header();
|
90
|
$admin->print_error($MESSAGE['GENERIC_SECURITY_ACCESS'],
|
91
|
ADMIN_URL.'/pages/modify.php?page_id='.$page_id );
|
92
|
}
|
93
|
$admin->print_header();
|
94
|
|
95
|
// Validate all fields
|
96
|
if($admin->get_post('title') == '' AND $admin->get_post('url') == '') {
|
97
|
$recallUrl = WB_URL.'/modules/news/modify_post.php?page_id='.$page_id.
|
98
|
'§ion_id='.$section_id.'&post_id='.$admin->getIDKEY($post_id);
|
99
|
$admin->print_error($MESSAGE['GENERIC']['FILL_IN_ALL'], $recallUrl);
|
100
|
}else {
|
101
|
$title = $admin->get_post_escaped('title');
|
102
|
$short = $admin->get_post_escaped('short');
|
103
|
$long = $admin->get_post_escaped('long');
|
104
|
$commenting = $admin->get_post_escaped('commenting');
|
105
|
$active = $admin->get_post_escaped('active');
|
106
|
$old_link = $admin->get_post_escaped('link');
|
107
|
$group_id = $admin->get_post_escaped('group');
|
108
|
}
|
109
|
// Get page link URL
|
110
|
$sql = 'SELECT `link` FROM `'.TABLE_PREFIX.'pages` WHERE `page_id`='.(int)$page_id;
|
111
|
$oldLink = $database->get_one($sql);
|
112
|
// Include WB functions file
|
113
|
require(WB_PATH.'/framework/functions.php');
|
114
|
// Work-out what the link should be
|
115
|
$newLink = '/posts/'.page_filename($title).PAGE_SPACER.$post_id;
|
116
|
// create new accessfile
|
117
|
createNewsAccessFile($newLink, $oldLink, $page_id, $section_id, $post_id);
|
118
|
// get publisedwhen and publisheduntil
|
119
|
$publishedwhen = jscalendar_to_timestamp($admin->get_post_escaped('publishdate'));
|
120
|
if($publishedwhen == '' || $publishedwhen < 1) { $publishedwhen=0; }
|
121
|
$publisheduntil = jscalendar_to_timestamp($admin->get_post_escaped('enddate'), $publishedwhen);
|
122
|
if($publisheduntil == '' || $publisheduntil < 1) { $publisheduntil=0; }
|
123
|
// Update row
|
124
|
$sql = 'UPDATE `'.TABLE_PREFIX.'mod_news_posts` ';
|
125
|
$sql .= 'SET `group_id`='.(int)$group_id.', ';
|
126
|
$sql .= '`title`=\''.$title.'\', ';
|
127
|
$sql .= '`link`=\''.$newLink.'\', ';
|
128
|
$sql .= '`content_short`=\''.$short.'\', ';
|
129
|
$sql .= '`content_long`=\''.$long.'\', ';
|
130
|
$sql .= '`commenting`=\''.$commenting.'\', ';
|
131
|
$sql .= '`active`='.(int)$active.', ';
|
132
|
$sql .= '`published_when`='.(int)$publishedwhen.', ';
|
133
|
$sql .= '`published_until`='.(int)$publisheduntil.', ';
|
134
|
$sql .= '`posted_when`='.time().', ';
|
135
|
$sql .= '`posted_by`='.(int)$admin->get_user_id().' ';
|
136
|
$sql .= 'WHERE `post_id`='.(int)$post_id;
|
137
|
$database->query($sql);
|
138
|
// Check if there is a db error, otherwise say successful
|
139
|
if($database->is_error()) {
|
140
|
$recallUrl = WB_URL.'/modules/news/modify_post.php?page_id='.$page_id.
|
141
|
'§ion_id='.$section_id.'&post_id='.$admin->getIDKEY($post_id);
|
142
|
$admin->print_error($database->get_error(), $recallUrl);
|
143
|
}else {
|
144
|
$admin->print_success($TEXT['SUCCESS'], ADMIN_URL.'/pages/modify.php?page_id='.$page_id);
|
145
|
}
|
146
|
// Print admin footer
|
147
|
$admin->print_footer();
|