1 |
4
|
ryan
|
<?php
|
2 |
|
|
|
3 |
40
|
stefan
|
// $Id$
|
4 |
4
|
ryan
|
|
5 |
|
|
/*
|
6 |
|
|
|
7 |
|
|
Website Baker Project <http://www.websitebaker.org/>
|
8 |
519
|
Ruebenwurz
|
Copyright (C) 2004-2008, Ryan Djurovich
|
9 |
4
|
ryan
|
|
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 |
|
|
*/
|
25 |
|
|
|
26 |
|
|
// Get page id
|
27 |
|
|
if(!isset($_POST['page_id']) OR !is_numeric($_POST['page_id'])) {
|
28 |
|
|
header("Location: index.php");
|
29 |
286
|
stefan
|
exit(0);
|
30 |
4
|
ryan
|
} else {
|
31 |
|
|
$page_id = $_POST['page_id'];
|
32 |
|
|
}
|
33 |
|
|
|
34 |
|
|
// Create new admin object and print admin header
|
35 |
|
|
require('../../config.php');
|
36 |
|
|
require_once(WB_PATH.'/framework/class.admin.php');
|
37 |
|
|
$admin = new admin('Pages', 'pages_settings');
|
38 |
|
|
|
39 |
|
|
// Include the WB functions file
|
40 |
|
|
require_once(WB_PATH.'/framework/functions.php');
|
41 |
|
|
|
42 |
|
|
// Get values
|
43 |
488
|
Ruebenwurz
|
$page_title = $admin->get_post_escaped('page_title');
|
44 |
442
|
Ruebenwurz
|
$page_title = my_htmlspecialchars($page_title);
|
45 |
488
|
Ruebenwurz
|
$menu_title = $admin->get_post_escaped('menu_title');
|
46 |
442
|
Ruebenwurz
|
$menu_title = my_htmlspecialchars($menu_title);
|
47 |
40
|
stefan
|
$description = $admin->add_slashes($admin->get_post('description'));
|
48 |
|
|
$keywords = $admin->add_slashes($admin->get_post('keywords'));
|
49 |
4
|
ryan
|
$parent = $admin->get_post('parent');
|
50 |
|
|
$visibility = $admin->get_post('visibility');
|
51 |
|
|
$template = $admin->get_post('template');
|
52 |
|
|
$target = $admin->get_post('target');
|
53 |
|
|
$admin_groups = $admin->get_post('admin_groups');
|
54 |
|
|
$viewing_groups = $admin->get_post('viewing_groups');
|
55 |
|
|
$searching = $admin->get_post('searching');
|
56 |
|
|
$language = $admin->get_post('language');
|
57 |
|
|
$menu = $admin->get_post('menu');
|
58 |
|
|
|
59 |
|
|
// Validate data
|
60 |
430
|
Ruebenwurz
|
if($page_title == '' || substr($page_title,0,1)=='.') {
|
61 |
4
|
ryan
|
$admin->print_error($MESSAGE['PAGES']['BLANK_PAGE_TITLE']);
|
62 |
|
|
}
|
63 |
428
|
Ruebenwurz
|
if($menu_title == '' || substr($menu_title,0,1)=='.') {
|
64 |
4
|
ryan
|
$admin->print_error($MESSAGE['PAGES']['BLANK_MENU_TITLE']);
|
65 |
|
|
}
|
66 |
|
|
|
67 |
|
|
// Get existing perms
|
68 |
|
|
$database = new database();
|
69 |
|
|
$results = $database->query("SELECT parent,link,position,admin_groups,admin_users FROM ".TABLE_PREFIX."pages WHERE page_id = '$page_id'");
|
70 |
|
|
$results_array = $results->fetchRow();
|
71 |
|
|
$old_parent = $results_array['parent'];
|
72 |
|
|
$old_link = $results_array['link'];
|
73 |
|
|
$old_position = $results_array['position'];
|
74 |
|
|
$old_admin_groups = explode(',', str_replace('_', '', $results_array['admin_groups']));
|
75 |
|
|
$old_admin_users = explode(',', str_replace('_', '', $results_array['admin_users']));
|
76 |
|
|
if(!is_numeric(array_search($admin->get_group_id(), $old_admin_groups)) AND !is_numeric(array_search($admin->get_user_id(), $old_admin_users))) {
|
77 |
|
|
$admin->print_error($MESSAGE['PAGES']['INSUFFICIENT_PERMISSIONS']);
|
78 |
|
|
}
|
79 |
|
|
|
80 |
|
|
// Setup admin groups
|
81 |
|
|
$admin_groups[] = 1;
|
82 |
|
|
if($admin->get_group_id() != 1) {
|
83 |
|
|
$admin_groups[] = $admin->get_group_id();
|
84 |
|
|
}
|
85 |
|
|
$admin_groups = implode(',', $admin_groups);
|
86 |
|
|
// Setup viewing groups
|
87 |
|
|
$viewing_groups[] = 1;
|
88 |
|
|
if($admin->get_group_id() != 1) {
|
89 |
|
|
$viewing_groups[] = $admin->get_group_id();
|
90 |
|
|
}
|
91 |
|
|
$viewing_groups = implode(',', $viewing_groups);
|
92 |
|
|
|
93 |
|
|
// If needed, get new order
|
94 |
|
|
if($parent != $old_parent) {
|
95 |
|
|
// Include ordering class
|
96 |
|
|
require(WB_PATH.'/framework/class.order.php');
|
97 |
|
|
$order = new order(TABLE_PREFIX.'pages', 'position', 'page_id', 'parent');
|
98 |
|
|
// Get new order
|
99 |
|
|
$position = $order->get_new($parent);
|
100 |
|
|
// Clean new order
|
101 |
|
|
$order->clean($parent);
|
102 |
|
|
} else {
|
103 |
|
|
$position = $old_position;
|
104 |
|
|
}
|
105 |
|
|
|
106 |
|
|
// Work out level and root parent
|
107 |
|
|
if ($parent!='0') {
|
108 |
|
|
$level = level_count($parent)+1;
|
109 |
|
|
$root_parent = root_parent($parent);
|
110 |
|
|
}
|
111 |
|
|
else {
|
112 |
|
|
$level = '0';
|
113 |
|
|
$root_parent = '0';
|
114 |
|
|
}
|
115 |
|
|
|
116 |
|
|
// Work-out what the link should be
|
117 |
|
|
if($parent == '0') {
|
118 |
497
|
ryan
|
$link = '/'.page_filename($menu_title);
|
119 |
|
|
$filename = WB_PATH.PAGES_DIRECTORY.'/'.page_filename($menu_title).'.php';
|
120 |
4
|
ryan
|
} else {
|
121 |
|
|
$parent_section = '';
|
122 |
|
|
$parent_titles = array_reverse(get_parent_titles($parent));
|
123 |
|
|
foreach($parent_titles AS $parent_title) {
|
124 |
|
|
$parent_section .= page_filename($parent_title).'/';
|
125 |
|
|
}
|
126 |
|
|
if($parent_section == '/') { $parent_section = ''; }
|
127 |
497
|
ryan
|
$link = '/'.$parent_section.page_filename($menu_title);
|
128 |
|
|
$filename = WB_PATH.PAGES_DIRECTORY.'/'.$parent_section.page_filename($menu_title).'.php';
|
129 |
4
|
ryan
|
}
|
130 |
|
|
|
131 |
|
|
// Check if a page with same page filename exists
|
132 |
|
|
$database = new database();
|
133 |
|
|
$get_same_page = $database->query("SELECT page_id,page_title FROM ".TABLE_PREFIX."pages WHERE link = '$link' and page_id != '$page_id'");
|
134 |
|
|
if($get_same_page->numRows() > 0) {
|
135 |
|
|
$admin->print_error($MESSAGE['PAGES']['PAGE_EXISTS']);
|
136 |
|
|
}
|
137 |
|
|
|
138 |
|
|
// Update page with new order
|
139 |
|
|
$query = "UPDATE ".TABLE_PREFIX."pages SET parent = '$parent', position = '$position' WHERE page_id = '$page_id'";
|
140 |
|
|
$database = new database();
|
141 |
|
|
$database->query($query);
|
142 |
|
|
|
143 |
|
|
// Get page trail
|
144 |
|
|
$page_trail = get_page_trail($page_id);
|
145 |
|
|
|
146 |
|
|
// Make sure link is not overwritten if page uses the menu link module
|
147 |
444
|
Ruebenwurz
|
$query_sections = $database->query("SELECT section_id FROM ".TABLE_PREFIX."sections WHERE page_id = '$page_id' AND module = 'menu_link'");
|
148 |
|
|
if($query_sections->numRows() > 0) {
|
149 |
4
|
ryan
|
$link = $old_link;
|
150 |
444
|
Ruebenwurz
|
}
|
151 |
4
|
ryan
|
|
152 |
|
|
// Update page settings in the pages table
|
153 |
|
|
$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'";
|
154 |
|
|
$database->query($query);
|
155 |
|
|
|
156 |
|
|
// Clean old order if needed
|
157 |
|
|
if($parent != $old_parent) {
|
158 |
|
|
$order->clean($old_parent);
|
159 |
|
|
}
|
160 |
|
|
|
161 |
|
|
/* BEGIN page "access file" code */
|
162 |
|
|
|
163 |
|
|
// Create a new file in the /pages dir if title changed
|
164 |
|
|
if(!is_writable(WB_PATH.PAGES_DIRECTORY.'/')) {
|
165 |
|
|
$admin->print_error($MESSAGE['PAGES']['CANNOT_CREATE_ACCESS_FILE']);
|
166 |
|
|
} else {
|
167 |
|
|
// First check if we need to create a new file
|
168 |
|
|
if($old_link != $link) {
|
169 |
|
|
// Delete old file
|
170 |
497
|
ryan
|
$old_filename = WB_PATH.PAGES_DIRECTORY.$old_link.'.php';
|
171 |
|
|
if(file_exists($old_filename)) {
|
172 |
|
|
unlink($old_filename);
|
173 |
|
|
}
|
174 |
4
|
ryan
|
// Create access file
|
175 |
|
|
create_access_file($filename,$page_id,$level);
|
176 |
|
|
// Move a directory for this page
|
177 |
|
|
if(file_exists(WB_PATH.PAGES_DIRECTORY.$old_link.'/') AND is_dir(WB_PATH.PAGES_DIRECTORY.$old_link.'/')) {
|
178 |
|
|
rename(WB_PATH.PAGES_DIRECTORY.$old_link.'/', WB_PATH.PAGES_DIRECTORY.$link.'/');
|
179 |
|
|
}
|
180 |
|
|
// Update any pages that had the old link with the new one
|
181 |
|
|
$old_link_len = strlen($old_link);
|
182 |
54
|
stefan
|
$query_subs = $database->query("SELECT page_id,link,level FROM ".TABLE_PREFIX."pages WHERE link LIKE '%$old_link/%' ORDER BY LEVEL ASC");
|
183 |
4
|
ryan
|
if($query_subs->numRows() > 0) {
|
184 |
|
|
while($sub = $query_subs->fetchRow()) {
|
185 |
|
|
// Double-check to see if it contains old link
|
186 |
|
|
if(substr($sub['link'], 0, $old_link_len) == $old_link) {
|
187 |
|
|
// Get new link
|
188 |
|
|
$replace_this = $old_link;
|
189 |
54
|
stefan
|
$old_sub_link_len =strlen($sub['link']);
|
190 |
|
|
$new_sub_link = $link.'/'.substr($sub['link'],$old_link_len+1,$old_sub_link_len);
|
191 |
4
|
ryan
|
// Work out level
|
192 |
|
|
$new_sub_level = level_count($sub['page_id']);
|
193 |
54
|
stefan
|
// Update level and link
|
194 |
|
|
$database->query("UPDATE ".TABLE_PREFIX."pages SET link = '$new_sub_link', level = '$new_sub_level' WHERE page_id = '".$sub['page_id']."' LIMIT 1");
|
195 |
4
|
ryan
|
// Re-write the access file for this page
|
196 |
499
|
ryan
|
$old_subpage_file = WB_PATH.PAGES_DIRECTORY.$new_sub_link.'.php';
|
197 |
4
|
ryan
|
if(file_exists($old_subpage_file)) {
|
198 |
|
|
unlink($old_subpage_file);
|
199 |
|
|
}
|
200 |
499
|
ryan
|
create_access_file(WB_PATH.PAGES_DIRECTORY.$new_sub_link.'.php', $sub['page_id'], $new_sub_level);
|
201 |
4
|
ryan
|
}
|
202 |
|
|
}
|
203 |
|
|
}
|
204 |
|
|
}
|
205 |
|
|
}
|
206 |
|
|
|
207 |
|
|
// Function to fix page trail of subs
|
208 |
447
|
Ruebenwurz
|
function fix_page_trail($parent,$root_parent) {
|
209 |
4
|
ryan
|
// Get objects and vars from outside this function
|
210 |
|
|
global $admin, $template, $database, $TEXT, $MESSAGE;
|
211 |
|
|
// Get page list from database
|
212 |
|
|
$database = new database();
|
213 |
|
|
$query = "SELECT page_id FROM ".TABLE_PREFIX."pages WHERE parent = '$parent'";
|
214 |
|
|
$get_pages = $database->query($query);
|
215 |
|
|
// Insert values into main page list
|
216 |
|
|
if($get_pages->numRows() > 0) {
|
217 |
|
|
while($page = $get_pages->fetchRow()) {
|
218 |
|
|
// Fix page trail
|
219 |
447
|
Ruebenwurz
|
$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']."'");
|
220 |
4
|
ryan
|
// Run this query on subs
|
221 |
447
|
Ruebenwurz
|
fix_page_trail($page['page_id'],$root_parent);
|
222 |
4
|
ryan
|
}
|
223 |
|
|
}
|
224 |
|
|
}
|
225 |
|
|
// Fix sub-pages page trail
|
226 |
447
|
Ruebenwurz
|
fix_page_trail($page_id,$root_parent);
|
227 |
4
|
ryan
|
|
228 |
|
|
/* END page "access file" code */
|
229 |
|
|
|
230 |
|
|
// Check if there is a db error, otherwise say successful
|
231 |
|
|
if($database->is_error()) {
|
232 |
|
|
$admin->print_error($database->get_error(), ADMIN_URL.'/pages/settings.php?page_id='.$page_id);
|
233 |
|
|
} else {
|
234 |
|
|
$admin->print_success($MESSAGE['PAGES']['SAVED_SETTINGS'], ADMIN_URL.'/pages/index.php');
|
235 |
|
|
}
|
236 |
|
|
|
237 |
|
|
// Print admin footer
|
238 |
|
|
$admin->print_footer();
|
239 |
|
|
|
240 |
|
|
?>
|