Revision 1277
Added by Dietmar almost 15 years ago
settings2.php | ||
---|---|---|
1 | 1 |
<?php |
2 |
/** |
|
3 |
* |
|
4 |
* @category admin |
|
5 |
* @package pages |
|
6 |
* @author WebsiteBaker Project |
|
7 |
* @copyright 2004-2009, Ryan Djurovich |
|
8 |
* @copyright 2009-2010, 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 4.3.4 and higher |
|
13 |
* @version $Id$ |
|
14 |
* @filesource $HeadURL: $ |
|
15 |
* @lastmodified $Date: $ |
|
16 |
* |
|
17 |
*/ |
|
2 | 18 |
|
3 |
// $Id$ |
|
4 |
|
|
5 |
/* |
|
6 |
|
|
7 |
Website Baker Project <http://www.websitebaker.org/> |
|
8 |
Copyright (C) 2004-2009, Ryan Djurovich |
|
9 |
|
|
10 |
Website Baker is free software; you can redistribute it and/or modify |
|
11 |
it under the terms of the GNU General Public License as published by |
|
12 |
the Free Software Foundation; either version 2 of the License, or |
|
13 |
(at your option) any later version. |
|
14 |
|
|
15 |
Website Baker is distributed in the hope that it will be useful, |
|
16 |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
17 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
18 |
GNU General Public License for more details. |
|
19 |
|
|
20 |
You should have received a copy of the GNU General Public License |
|
21 |
along with Website Baker; if not, write to the Free Software |
|
22 |
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
|
23 |
|
|
24 |
* @category backend |
|
25 |
* @package pages |
|
26 |
* @author(s) Dietmar W?llbrink <Luisehahne>, Dietrich Roland Pehlke <Aldus> |
|
27 |
* @platform WB 2.8.x |
|
28 |
* @require PHP 5.2.11 |
|
29 |
* @license http://www.gnu.org/licenses/gpl.html |
|
30 |
* @link http://project.websitebaker2.org/browser/branches/2.8.x/wb/pages |
|
31 |
* @changeset 2009/11/30 workout for page_code field, ex catchwords and multilangual |
|
32 |
|
|
33 |
*/ |
|
34 |
|
|
35 | 19 |
// Get page id |
36 |
if(!isset($_POST['page_id']) OR !is_numeric($_POST['page_id'])) { |
|
20 |
if(!isset($_POST['page_id']) OR !is_numeric($_POST['page_id'])) |
|
21 |
{ |
|
37 | 22 |
header("Location: index.php"); |
38 | 23 |
exit(0); |
39 | 24 |
} else { |
... | ... | |
68 | 53 |
$menu = $admin->get_post_escaped('menu'); |
69 | 54 |
|
70 | 55 |
// Validate data |
71 |
if($page_title == '' || substr($page_title,0,1)=='.') { |
|
56 |
if($page_title == '' || substr($page_title,0,1)=='.') |
|
57 |
{ |
|
72 | 58 |
$admin->print_error($MESSAGE['PAGES']['BLANK_PAGE_TITLE']); |
73 | 59 |
} |
74 |
if($menu_title == '' || substr($menu_title,0,1)=='.') { |
|
60 |
if($menu_title == '' || substr($menu_title,0,1)=='.') |
|
61 |
{ |
|
75 | 62 |
$admin->print_error($MESSAGE['PAGES']['BLANK_MENU_TITLE']); |
76 | 63 |
} |
77 | 64 |
|
78 | 65 |
// Get existing perms |
79 |
$database = new database(); |
|
80 |
$results = $database->query("SELECT parent,link,position,admin_groups,admin_users FROM ".TABLE_PREFIX."pages WHERE page_id = '$page_id'"); |
|
66 |
// $database = new database(); |
|
67 |
|
|
68 |
$sql = 'SELECT `parent`,`link`,`position`,`admin_groups`,`admin_users` FROM `'.TABLE_PREFIX.'pages` WHERE `page_id`='.$page_id; |
|
69 |
$results = $database->query($sql); |
|
70 |
|
|
81 | 71 |
$results_array = $results->fetchRow(); |
82 | 72 |
$old_parent = $results_array['parent']; |
83 | 73 |
$old_link = $results_array['link']; |
... | ... | |
86 | 76 |
$old_admin_users = explode(',', str_replace('_', '', $results_array['admin_users'])); |
87 | 77 |
|
88 | 78 |
// Work-out if we should check for existing page_code |
89 |
$field_sql = $database->query("DESCRIBE ".TABLE_PREFIX."pages page_code"); |
|
79 |
$sql = 'DESCRIBE `'.TABLE_PREFIX.'pages` `page_code`'; |
|
80 |
$field_sql = $database->query($sql); |
|
90 | 81 |
$field_set = $field_sql->numRows(); |
91 | 82 |
|
92 | 83 |
$in_old_group = FALSE; |
... | ... | |
95 | 86 |
$in_old_group = TRUE; |
96 | 87 |
} |
97 | 88 |
} |
98 |
if((!$in_old_group) AND !is_numeric(array_search($admin->get_user_id(), $old_admin_users))) { |
|
89 |
if((!$in_old_group) AND !is_numeric(array_search($admin->get_user_id(), $old_admin_users))) |
|
90 |
{ |
|
99 | 91 |
$admin->print_error($MESSAGE['PAGES']['INSUFFICIENT_PERMISSIONS']); |
100 | 92 |
} |
101 | 93 |
|
... | ... | |
113 | 105 |
$viewing_groups = implode(',', $viewing_groups); |
114 | 106 |
|
115 | 107 |
// If needed, get new order |
116 |
if($parent != $old_parent) { |
|
108 |
if($parent != $old_parent) |
|
109 |
{ |
|
117 | 110 |
// Include ordering class |
118 | 111 |
require(WB_PATH.'/framework/class.order.php'); |
119 | 112 |
$order = new order(TABLE_PREFIX.'pages', 'position', 'page_id', 'parent'); |
... | ... | |
126 | 119 |
} |
127 | 120 |
|
128 | 121 |
// Work out level and root parent |
129 |
if ($parent!='0') { |
|
122 |
if ($parent!='0') |
|
123 |
{ |
|
130 | 124 |
$level = level_count($parent)+1; |
131 | 125 |
$root_parent = root_parent($parent); |
132 | 126 |
} |
... | ... | |
136 | 130 |
} |
137 | 131 |
|
138 | 132 |
// Work-out what the link should be |
139 |
if($parent == '0') { |
|
133 |
if($parent == '0') |
|
134 |
{ |
|
140 | 135 |
$link = '/'.page_filename($menu_title); |
141 | 136 |
// rename menu titles: index && intro to prevent clashes with intro page feature and WB core file /pages/index.php |
142 |
if($link == '/index' || $link == '/intro') { |
|
137 |
if($link == '/index' || $link == '/intro') |
|
138 |
{ |
|
143 | 139 |
$link .= '_' .$page_id; |
144 | 140 |
$filename = WB_PATH.PAGES_DIRECTORY.'/'.page_filename($menu_title).'_'.$page_id .PAGE_EXTENSION; |
145 | 141 |
} else { |
146 |
$filename = WB_PATH.PAGES_DIRECTORY.'/'.page_filename($menu_title).PAGE_EXTENSION;
|
|
142 |
$filename = WB_PATH.PAGES_DIRECTORY.'/'.page_filename($menu_title).PAGE_EXTENSION; |
|
147 | 143 |
} |
148 | 144 |
} else { |
149 | 145 |
$parent_section = ''; |
150 | 146 |
$parent_titles = array_reverse(get_parent_titles($parent)); |
151 |
foreach($parent_titles AS $parent_title) { |
|
147 |
foreach($parent_titles AS $parent_title) |
|
148 |
{ |
|
152 | 149 |
$parent_section .= page_filename($parent_title).'/'; |
153 | 150 |
} |
154 |
if($parent_section == '/') { $parent_section = ''; } |
|
151 |
if($parent_section == '/') |
|
152 |
{ |
|
153 |
$parent_section = ''; |
|
154 |
} |
|
155 | 155 |
$link = '/'.$parent_section.page_filename($menu_title); |
156 |
$filename = WB_PATH.PAGES_DIRECTORY.'/'.$parent_section.page_filename($menu_title).PAGE_EXTENSION;
|
|
156 |
$filename = WB_PATH.PAGES_DIRECTORY.'/'.$parent_section.page_filename($menu_title).PAGE_EXTENSION; |
|
157 | 157 |
} |
158 | 158 |
|
159 | 159 |
// Check if a page with same page filename exists |
160 |
$database = new database(); |
|
161 |
$get_same_page = $database->query("SELECT page_id,page_title FROM ".TABLE_PREFIX."pages WHERE link = '$link' and page_id != '$page_id'"); |
|
162 |
if($get_same_page->numRows() > 0) { |
|
160 |
// $database = new database(); |
|
161 |
$sql = 'SELECT `page_id`,`page_title` FROM `'.TABLE_PREFIX.'pages` WHERE `link` = "'.$link.'" AND `page_id` != '.$page_id; |
|
162 |
$get_same_page = $database->query($sql); |
|
163 |
|
|
164 |
if($get_same_page->numRows() > 0) |
|
165 |
{ |
|
163 | 166 |
$admin->print_error($MESSAGE['PAGES']['PAGE_EXISTS']); |
164 | 167 |
} |
165 | 168 |
|
166 | 169 |
// Update page with new order |
167 |
$query = "UPDATE ".TABLE_PREFIX."pages SET parent = '$parent', position = '$position' WHERE page_id = '$page_id'";
|
|
168 |
$database = new database(); |
|
169 |
$database->query($query);
|
|
170 |
$sql = 'UPDATE `'.TABLE_PREFIX.'pages` SET `parent`='.$parent.', `position`='.$position.' WHERE `page_id`='.$page_id.'';
|
|
171 |
// $database = new database();
|
|
172 |
$database->query($sql);
|
|
170 | 173 |
|
171 | 174 |
// Get page trail |
172 | 175 |
$page_trail = get_page_trail($page_id); |
173 | 176 |
|
174 | 177 |
// Update page settings in the pages table |
175 |
if((defined('PAGE_LANGUAGES') && PAGE_LANGUAGES) && $field_set ) |
|
178 |
$sql = 'UPDATE `'.TABLE_PREFIX.'pages` SET '; |
|
179 |
$sql .= '`parent` = '.$parent.', '; |
|
180 |
$sql .= '`page_title` = "'.$page_title.'", '; |
|
181 |
$sql .= '`menu_title` = "'.$menu_title.'", '; |
|
182 |
$sql .= '`menu` = '.$menu.', '; |
|
183 |
$sql .= '`level` = '.$level.', '; |
|
184 |
$sql .= '`page_trail` = "'.$page_trail.'", '; |
|
185 |
$sql .= '`root_parent` = '.$root_parent.', '; |
|
186 |
$sql .= '`link` = "'.$link.'", '; |
|
187 |
$sql .= '`template` = "'.$template.'", '; |
|
188 |
$sql .= '`target` = "'.$target.'", '; |
|
189 |
$sql .= '`description` = "'.$description.'", '; |
|
190 |
$sql .= '`keywords` = "'.$keywords.'", '; |
|
191 |
$sql .= '`position` = '.$position.', '; |
|
192 |
$sql .= '`visibility` = "'.$visibility.'", '; |
|
193 |
$sql .= '`searching` = '.$searching.', '; |
|
194 |
$sql .= '`language` = "'.$language.'", '; |
|
195 |
$sql .= '`admin_groups` = "'.$admin_groups.'", '; |
|
196 |
$sql .= '`viewing_groups` = "'.$viewing_groups.'"'; |
|
197 |
$sql .= (defined('PAGE_LANGUAGES') && PAGE_LANGUAGES) && $field_set && (file_exists(WB_PATH.'/modules/mod_multilingual/update_keys.php')) ? ', `page_code` = "'.$page_code.'" ' : ' '; |
|
198 |
$sql .= 'WHERE `page_id` = '.$page_id; |
|
199 |
$database->query($sql); |
|
200 |
|
|
201 |
$target_url = ADMIN_URL.'/pages/settings.php?page_id='.$page_id; |
|
202 |
if($database->is_error()) |
|
176 | 203 |
{ |
177 |
$query = "UPDATE ".TABLE_PREFIX."pages SET parent = '$parent', page_title = '$page_title', menu_title = '$menu_title', menu = '$menu', level = '$level', page_trail = '$page_trail', root_parent = '$root_parent', link = '$link', template = '$template', target = '$target', description = '$description', keywords = '$keywords', position = '$position', visibility = '$visibility', searching = '$searching', language = '$language', admin_groups = '$admin_groups', viewing_groups = '$viewing_groups', page_code = '$page_code' WHERE page_id = '$page_id'"; |
|
178 |
} else |
|
179 |
{ |
|
180 |
$query = "UPDATE ".TABLE_PREFIX."pages SET parent = '$parent', page_title = '$page_title', menu_title = '$menu_title', menu = '$menu', level = '$level', page_trail = '$page_trail', root_parent = '$root_parent', link = '$link', template = '$template', target = '$target', description = '$description', keywords = '$keywords', position = '$position', visibility = '$visibility', searching = '$searching', language = '$language', admin_groups = '$admin_groups', viewing_groups = '$viewing_groups' WHERE page_id = '$page_id'"; |
|
204 |
$admin->print_error($database->get_error(), $target_url ); |
|
181 | 205 |
} |
182 |
|
|
183 |
$database->query($query); |
|
184 |
|
|
185 | 206 |
// Clean old order if needed |
186 |
if($parent != $old_parent) { |
|
207 |
if($parent != $old_parent) |
|
208 |
{ |
|
187 | 209 |
$order->clean($old_parent); |
188 | 210 |
} |
189 | 211 |
|
190 | 212 |
/* BEGIN page "access file" code */ |
191 | 213 |
|
192 | 214 |
// Create a new file in the /pages dir if title changed |
193 |
if(!is_writable(WB_PATH.PAGES_DIRECTORY.'/')) { |
|
215 |
if(!is_writable(WB_PATH.PAGES_DIRECTORY.'/')) |
|
216 |
{ |
|
194 | 217 |
$admin->print_error($MESSAGE['PAGES']['CANNOT_CREATE_ACCESS_FILE']); |
195 | 218 |
} else { |
196 | 219 |
// First check if we need to create a new file |
197 |
if($old_link != $link) { |
|
220 |
if($old_link != $link) |
|
221 |
{ |
|
198 | 222 |
// Delete old file |
199 | 223 |
$old_filename = WB_PATH.PAGES_DIRECTORY.$old_link.PAGE_EXTENSION; |
200 |
if(file_exists($old_filename)) { |
|
224 |
if(file_exists($old_filename)) |
|
225 |
{ |
|
201 | 226 |
unlink($old_filename); |
202 | 227 |
} |
203 | 228 |
// Create access file |
204 | 229 |
create_access_file($filename,$page_id,$level); |
205 | 230 |
// Move a directory for this page |
206 |
if(file_exists(WB_PATH.PAGES_DIRECTORY.$old_link.'/') AND is_dir(WB_PATH.PAGES_DIRECTORY.$old_link.'/')) { |
|
231 |
if(file_exists(WB_PATH.PAGES_DIRECTORY.$old_link.'/') AND is_dir(WB_PATH.PAGES_DIRECTORY.$old_link.'/')) |
|
232 |
{ |
|
207 | 233 |
rename(WB_PATH.PAGES_DIRECTORY.$old_link.'/', WB_PATH.PAGES_DIRECTORY.$link.'/'); |
208 | 234 |
} |
209 | 235 |
// Update any pages that had the old link with the new one |
210 | 236 |
$old_link_len = strlen($old_link); |
237 |
$sql = ''; |
|
211 | 238 |
$query_subs = $database->query("SELECT page_id,link,level FROM ".TABLE_PREFIX."pages WHERE link LIKE '%$old_link/%' ORDER BY LEVEL ASC"); |
212 |
if($query_subs->numRows() > 0) { |
|
213 |
while($sub = $query_subs->fetchRow()) { |
|
239 |
|
|
240 |
if($query_subs->numRows() > 0) |
|
241 |
{ |
|
242 |
while($sub = $query_subs->fetchRow()) |
|
243 |
{ |
|
214 | 244 |
// Double-check to see if it contains old link |
215 |
if(substr($sub['link'], 0, $old_link_len) == $old_link) { |
|
245 |
if(substr($sub['link'], 0, $old_link_len) == $old_link) |
|
246 |
{ |
|
216 | 247 |
// Get new link |
217 | 248 |
$replace_this = $old_link; |
218 | 249 |
$old_sub_link_len =strlen($sub['link']); |
... | ... | |
223 | 254 |
$database->query("UPDATE ".TABLE_PREFIX."pages SET link = '$new_sub_link', level = '$new_sub_level' WHERE page_id = '".$sub['page_id']."' LIMIT 1"); |
224 | 255 |
// Re-write the access file for this page |
225 | 256 |
$old_subpage_file = WB_PATH.PAGES_DIRECTORY.$new_sub_link.PAGE_EXTENSION; |
226 |
if(file_exists($old_subpage_file)) { |
|
257 |
if(file_exists($old_subpage_file)) |
|
258 |
{ |
|
227 | 259 |
unlink($old_subpage_file); |
228 | 260 |
} |
229 | 261 |
create_access_file(WB_PATH.PAGES_DIRECTORY.$new_sub_link.PAGE_EXTENSION, $sub['page_id'], $new_sub_level); |
... | ... | |
234 | 266 |
} |
235 | 267 |
|
236 | 268 |
// Function to fix page trail of subs |
237 |
function fix_page_trail($parent,$root_parent) { |
|
269 |
function fix_page_trail($parent,$root_parent) |
|
270 |
{ |
|
238 | 271 |
// Get objects and vars from outside this function |
239 | 272 |
global $admin, $template, $database, $TEXT, $MESSAGE; |
240 | 273 |
// Get page list from database |
241 |
$database = new database(); |
|
274 |
// $database = new database();
|
|
242 | 275 |
$query = "SELECT page_id FROM ".TABLE_PREFIX."pages WHERE parent = '$parent'"; |
243 | 276 |
$get_pages = $database->query($query); |
244 | 277 |
// Insert values into main page list |
245 |
if($get_pages->numRows() > 0) { |
|
246 |
while($page = $get_pages->fetchRow()) { |
|
278 |
if($get_pages->numRows() > 0) |
|
279 |
{ |
|
280 |
while($page = $get_pages->fetchRow()) |
|
281 |
{ |
|
247 | 282 |
// Fix page trail |
283 |
|
|
248 | 284 |
$database->query("UPDATE ".TABLE_PREFIX."pages SET ".($root_parent != 0 ?"root_parent = '$root_parent', ":"")." page_trail = '".get_page_trail($page['page_id'])."' WHERE page_id = '".$page['page_id']."'"); |
249 | 285 |
// Run this query on subs |
250 | 286 |
fix_page_trail($page['page_id'],$root_parent); |
251 | 287 |
} |
252 | 288 |
} |
253 | 289 |
} |
290 |
|
|
254 | 291 |
// Fix sub-pages page trail |
255 | 292 |
fix_page_trail($page_id,$root_parent); |
256 | 293 |
|
257 | 294 |
/* END page "access file" code */ |
258 | 295 |
|
296 |
$pagetree_url = ADMIN_URL.'/pages/index.php'; |
|
297 |
$target_url = ADMIN_URL.'/pages/settings.php?page_id='.$page_id; |
|
259 | 298 |
// Check if there is a db error, otherwise say successful |
260 |
if($database->is_error()) { |
|
261 |
$admin->print_error($database->get_error(), ADMIN_URL.'/pages/settings.php?page_id='.$page_id); |
|
299 |
if($database->is_error()) |
|
300 |
{ |
|
301 |
$admin->print_error($database->get_error(), $target_url ); |
|
262 | 302 |
} else { |
263 |
$admin->print_success($MESSAGE['PAGES']['SAVED_SETTINGS'], ADMIN_URL.'/pages/index.php');
|
|
303 |
$admin->print_success($MESSAGE['PAGES']['SAVED_SETTINGS'], $target_url );
|
|
264 | 304 |
} |
265 | 305 |
|
266 | 306 |
// Print admin footer |
267 | 307 |
$admin->print_footer(); |
268 | 308 |
|
269 |
?>
|
|
309 |
?> |
Also available in: Unified diff
update headertext