1
|
<?php
|
2
|
/*
|
3
|
*
|
4
|
* About WebsiteBaker
|
5
|
*
|
6
|
* Website Baker is a PHP-based Content Management System (CMS)
|
7
|
* designed with one goal in mind: to enable its users to produce websites
|
8
|
* with ease.
|
9
|
*
|
10
|
* LICENSE INFORMATION
|
11
|
*
|
12
|
* WebsiteBaker is free software; you can redistribute it and/or
|
13
|
* modify it under the terms of the GNU General Public License
|
14
|
* as published by the Free Software Foundation; either version 2
|
15
|
* of the License, or (at your option) any later version.
|
16
|
*
|
17
|
* WebsiteBaker is distributed in the hope that it will be useful,
|
18
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
19
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
20
|
* See the GNU General Public License for more details.
|
21
|
*
|
22
|
* You should have received a copy of the GNU General Public License
|
23
|
* along with this program; if not, write to the Free Software
|
24
|
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
25
|
*
|
26
|
* WebsiteBaker Extra Information
|
27
|
*
|
28
|
*
|
29
|
*/
|
30
|
/**
|
31
|
*
|
32
|
* @category modules
|
33
|
* @package news
|
34
|
* @author WebsiteBaker Project
|
35
|
* @copyright 2004-2009, Ryan Djurovich
|
36
|
* @copyright 2009-2010, Website Baker Org. e.V.
|
37
|
* @link http://www.websitebaker2.org/
|
38
|
* @license http://www.gnu.org/licenses/gpl.html
|
39
|
* @platform WebsiteBaker 2.8.x
|
40
|
* @requirements PHP 4.3.4 and higher
|
41
|
* @version $Id: save_post.php 1268 2010-01-22 17:21:02Z Luisehahne $
|
42
|
* @filesource $HeadURL: svn://isteam.dynxs.de/wb-archiv/branches/2.8.x/wb/modules/news/save_post.php $
|
43
|
* @lastmodified $Date: 2010-01-22 18:21:02 +0100 (Fri, 22 Jan 2010) $
|
44
|
*
|
45
|
*/
|
46
|
|
47
|
require('../../config.php');
|
48
|
|
49
|
require_once(WB_PATH."/include/jscalendar/jscalendar-functions.php");
|
50
|
|
51
|
// Get id
|
52
|
if(!isset($_POST['post_id']) OR !is_numeric($_POST['post_id']))
|
53
|
{
|
54
|
header("Location: ".ADMIN_URL."/pages/index.php");
|
55
|
exit( 0 );
|
56
|
}
|
57
|
else
|
58
|
{
|
59
|
$id = $_POST['post_id'];
|
60
|
$post_id = $id;
|
61
|
}
|
62
|
|
63
|
function create_file($filename, $filetime=NULL )
|
64
|
{
|
65
|
global $page_id, $section_id, $post_id;
|
66
|
|
67
|
// We need to create a new file
|
68
|
// First, delete old file if it exists
|
69
|
if(file_exists(WB_PATH.PAGES_DIRECTORY.$filename.PAGE_EXTENSION))
|
70
|
{
|
71
|
$filetime = isset($filetime) ? $filetime : filemtime($filename);
|
72
|
unlink(WB_PATH.PAGES_DIRECTORY.$filename.PAGE_EXTENSION);
|
73
|
}
|
74
|
else {
|
75
|
$filetime = isset($filetime) ? $filetime : time();
|
76
|
}
|
77
|
// The depth of the page directory in the directory hierarchy
|
78
|
// '/pages' is at depth 1
|
79
|
$pages_dir_depth = count(explode('/',PAGES_DIRECTORY))-1;
|
80
|
// Work-out how many ../'s we need to get to the index page
|
81
|
$index_location = '../';
|
82
|
for($i = 0; $i < $pages_dir_depth; $i++)
|
83
|
{
|
84
|
$index_location .= '../';
|
85
|
}
|
86
|
|
87
|
// Write to the filename
|
88
|
$content = ''.
|
89
|
'<?php
|
90
|
$page_id = '.$page_id.';
|
91
|
$section_id = '.$section_id.';
|
92
|
$post_id = '.$post_id.';
|
93
|
define("POST_SECTION", $section_id);
|
94
|
define("POST_ID", $post_id);
|
95
|
require("'.$index_location.'config.php");
|
96
|
require(WB_PATH."/index.php");
|
97
|
?>';
|
98
|
if($handle = fopen($filename, 'w+'))
|
99
|
{
|
100
|
fwrite($handle, $content);
|
101
|
fclose($handle);
|
102
|
if($filetime)
|
103
|
{
|
104
|
touch($filename, $filetime);
|
105
|
}
|
106
|
change_mode($filename);
|
107
|
}
|
108
|
|
109
|
}
|
110
|
|
111
|
// Include WB admin wrapper script
|
112
|
$update_when_modified = true; // Tells script to update when this page was last updated
|
113
|
require(WB_PATH.'/modules/admin.php');
|
114
|
|
115
|
// Validate all fields
|
116
|
if($admin->get_post('title') == '' AND $admin->get_post('url') == '')
|
117
|
{
|
118
|
$admin->print_error($MESSAGE['GENERIC']['FILL_IN_ALL'], WB_URL.'/modules/news/modify_post.php?page_id='.$page_id.'§ion_id='.$section_id.'&post_id='.$id);
|
119
|
}
|
120
|
else
|
121
|
{
|
122
|
$title = $admin->get_post_escaped('title');
|
123
|
$short = $admin->get_post_escaped('short');
|
124
|
$long = $admin->get_post_escaped('long');
|
125
|
$commenting = $admin->get_post_escaped('commenting');
|
126
|
$active = $admin->get_post_escaped('active');
|
127
|
$old_link = $admin->get_post_escaped('link');
|
128
|
$group_id = $admin->get_post_escaped('group');
|
129
|
}
|
130
|
|
131
|
// Get page link URL
|
132
|
$query_page = $database->query("SELECT level,link FROM ".TABLE_PREFIX."pages WHERE page_id = '$page_id'");
|
133
|
$page = $query_page->fetchRow();
|
134
|
$page_level = $page['level'];
|
135
|
$page_link = $page['link'];
|
136
|
|
137
|
// Include WB functions file
|
138
|
require(WB_PATH.'/framework/functions.php');
|
139
|
|
140
|
// Work-out what the link should be
|
141
|
$post_link = '/posts/'.page_filename($title).PAGE_SPACER.$post_id;
|
142
|
|
143
|
// Make sure the post link is set and exists
|
144
|
// Make news post access files dir
|
145
|
make_dir(WB_PATH.PAGES_DIRECTORY.'/posts/');
|
146
|
$file_create_time = '';
|
147
|
if(!is_writable(WB_PATH.PAGES_DIRECTORY.'/posts/'))
|
148
|
{
|
149
|
$admin->print_error($MESSAGE['PAGES']['CANNOT_CREATE_ACCESS_FILE']);
|
150
|
}
|
151
|
elseif(($old_link != $post_link) OR !file_exists(WB_PATH.PAGES_DIRECTORY.$post_link.PAGE_EXTENSION))
|
152
|
{
|
153
|
// We need to create a new file
|
154
|
// First, delete old file if it exists
|
155
|
if(file_exists(WB_PATH.PAGES_DIRECTORY.$old_link.PAGE_EXTENSION))
|
156
|
{
|
157
|
$file_create_time = filemtime($old_link.PAGE_EXTENSION);
|
158
|
unlink(WB_PATH.PAGES_DIRECTORY.$old_link.PAGE_EXTENSION);
|
159
|
}
|
160
|
|
161
|
// Specify the filename
|
162
|
$filename = WB_PATH.PAGES_DIRECTORY.'/'.$post_link.PAGE_EXTENSION;
|
163
|
create_file($filename, $file_create_time);
|
164
|
}
|
165
|
|
166
|
|
167
|
// get publisedwhen and publisheduntil
|
168
|
$publishedwhen = jscalendar_to_timestamp($admin->get_post_escaped('publishdate'));
|
169
|
if($publishedwhen == '' || $publishedwhen < 1)
|
170
|
$publishedwhen=0;
|
171
|
$publisheduntil = jscalendar_to_timestamp($admin->get_post_escaped('enddate'), $publishedwhen);
|
172
|
if($publisheduntil == '' || $publisheduntil < 1)
|
173
|
$publisheduntil=0;
|
174
|
|
175
|
// Update row
|
176
|
$database->query("UPDATE ".TABLE_PREFIX."mod_news_posts SET group_id = '$group_id', title = '$title', link = '$post_link', content_short = '$short', content_long = '$long', commenting = '$commenting', active = '$active', published_when = '$publishedwhen', published_until = '$publisheduntil', posted_when = '".time()."', posted_by = '".$admin->get_user_id()."' WHERE post_id = '$post_id'");
|
177
|
|
178
|
// Check if there is a db error, otherwise say successful
|
179
|
if($database->is_error())
|
180
|
{
|
181
|
$admin->print_error($database->get_error(), WB_URL.'/modules/news/modify_post.php?page_id='.$page_id.'§ion_id='.$section_id.'&post_id='.$id);
|
182
|
}
|
183
|
else
|
184
|
{
|
185
|
$admin->print_success($TEXT['SUCCESS'], ADMIN_URL.'/pages/modify.php?page_id='.$page_id);
|
186
|
}
|
187
|
|
188
|
// Print admin footer
|
189
|
$admin->print_footer();
|
190
|
|
191
|
?>
|