1 |
1203
|
Luisehahne
|
<?php
|
2 |
1277
|
Luisehahne
|
/**
|
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 |
1280
|
Luisehahne
|
* @filesource $HeadURL$
|
15 |
|
|
* @lastmodified $Date$
|
16 |
1277
|
Luisehahne
|
*
|
17 |
|
|
*/
|
18 |
1203
|
Luisehahne
|
|
19 |
|
|
// Get page id
|
20 |
1277
|
Luisehahne
|
if(!isset($_POST['page_id']) OR !is_numeric($_POST['page_id']))
|
21 |
|
|
{
|
22 |
1203
|
Luisehahne
|
header("Location: index.php");
|
23 |
|
|
exit(0);
|
24 |
|
|
} else {
|
25 |
|
|
$page_id = $_POST['page_id'];
|
26 |
|
|
}
|
27 |
|
|
|
28 |
|
|
// Create new admin object and print admin header
|
29 |
|
|
require('../../config.php');
|
30 |
|
|
require_once(WB_PATH.'/framework/class.admin.php');
|
31 |
|
|
$admin = new admin('Pages', 'pages_settings');
|
32 |
|
|
|
33 |
|
|
// Include the WB functions file
|
34 |
|
|
require_once(WB_PATH.'/framework/functions.php');
|
35 |
|
|
|
36 |
|
|
// Get values
|
37 |
1301
|
Luisehahne
|
$page_title = htmlspecialchars($admin->get_post_escaped('page_title') );
|
38 |
|
|
$menu_title = htmlspecialchars($admin->get_post_escaped('menu_title') );
|
39 |
1203
|
Luisehahne
|
$page_code = $admin->get_post_escaped('page_code');
|
40 |
1301
|
Luisehahne
|
$description = htmlspecialchars($admin->add_slashes($admin->get_post('description')) );
|
41 |
|
|
$keywords = htmlspecialchars($admin->add_slashes($admin->get_post('keywords')) );
|
42 |
1203
|
Luisehahne
|
$parent = $admin->get_post_escaped('parent');
|
43 |
|
|
$visibility = $admin->get_post_escaped('visibility');
|
44 |
|
|
$template = $admin->get_post_escaped('template');
|
45 |
|
|
$target = $admin->get_post_escaped('target');
|
46 |
|
|
$admin_groups = $admin->get_post_escaped('admin_groups');
|
47 |
|
|
$viewing_groups = $admin->get_post_escaped('viewing_groups');
|
48 |
|
|
$searching = $admin->get_post_escaped('searching');
|
49 |
|
|
$language = $admin->get_post_escaped('language');
|
50 |
|
|
$menu = $admin->get_post_escaped('menu');
|
51 |
|
|
|
52 |
|
|
// Validate data
|
53 |
1277
|
Luisehahne
|
if($page_title == '' || substr($page_title,0,1)=='.')
|
54 |
|
|
{
|
55 |
1203
|
Luisehahne
|
$admin->print_error($MESSAGE['PAGES']['BLANK_PAGE_TITLE']);
|
56 |
|
|
}
|
57 |
1277
|
Luisehahne
|
if($menu_title == '' || substr($menu_title,0,1)=='.')
|
58 |
|
|
{
|
59 |
1203
|
Luisehahne
|
$admin->print_error($MESSAGE['PAGES']['BLANK_MENU_TITLE']);
|
60 |
|
|
}
|
61 |
|
|
|
62 |
|
|
// Get existing perms
|
63 |
1277
|
Luisehahne
|
// $database = new database();
|
64 |
|
|
|
65 |
|
|
$sql = 'SELECT `parent`,`link`,`position`,`admin_groups`,`admin_users` FROM `'.TABLE_PREFIX.'pages` WHERE `page_id`='.$page_id;
|
66 |
|
|
$results = $database->query($sql);
|
67 |
|
|
|
68 |
1203
|
Luisehahne
|
$results_array = $results->fetchRow();
|
69 |
|
|
$old_parent = $results_array['parent'];
|
70 |
|
|
$old_link = $results_array['link'];
|
71 |
|
|
$old_position = $results_array['position'];
|
72 |
|
|
$old_admin_groups = explode(',', str_replace('_', '', $results_array['admin_groups']));
|
73 |
|
|
$old_admin_users = explode(',', str_replace('_', '', $results_array['admin_users']));
|
74 |
|
|
|
75 |
|
|
// Work-out if we should check for existing page_code
|
76 |
1277
|
Luisehahne
|
$sql = 'DESCRIBE `'.TABLE_PREFIX.'pages` `page_code`';
|
77 |
|
|
$field_sql = $database->query($sql);
|
78 |
1203
|
Luisehahne
|
$field_set = $field_sql->numRows();
|
79 |
|
|
|
80 |
|
|
$in_old_group = FALSE;
|
81 |
1301
|
Luisehahne
|
foreach($admin->get_groups_id() as $cur_gid)
|
82 |
|
|
{
|
83 |
|
|
if (in_array($cur_gid, $old_admin_groups))
|
84 |
|
|
{
|
85 |
1203
|
Luisehahne
|
$in_old_group = TRUE;
|
86 |
|
|
}
|
87 |
|
|
}
|
88 |
1277
|
Luisehahne
|
if((!$in_old_group) AND !is_numeric(array_search($admin->get_user_id(), $old_admin_users)))
|
89 |
|
|
{
|
90 |
1203
|
Luisehahne
|
$admin->print_error($MESSAGE['PAGES']['INSUFFICIENT_PERMISSIONS']);
|
91 |
|
|
}
|
92 |
|
|
|
93 |
|
|
// Setup admin groups
|
94 |
|
|
$admin_groups[] = 1;
|
95 |
|
|
//if(!in_array(1, $admin->get_groups_id())) {
|
96 |
|
|
// $admin_groups[] = implode(",",$admin->get_groups_id());
|
97 |
|
|
//}
|
98 |
|
|
$admin_groups = implode(',', $admin_groups);
|
99 |
|
|
// Setup viewing groups
|
100 |
|
|
$viewing_groups[] = 1;
|
101 |
|
|
//if(!in_array(1, $admin->get_groups_id())) {
|
102 |
|
|
// $viewing_groups[] = implode(",",$admin->get_groups_id());
|
103 |
|
|
//}
|
104 |
|
|
$viewing_groups = implode(',', $viewing_groups);
|
105 |
|
|
|
106 |
|
|
// If needed, get new order
|
107 |
1277
|
Luisehahne
|
if($parent != $old_parent)
|
108 |
|
|
{
|
109 |
1203
|
Luisehahne
|
// Include ordering class
|
110 |
|
|
require(WB_PATH.'/framework/class.order.php');
|
111 |
|
|
$order = new order(TABLE_PREFIX.'pages', 'position', 'page_id', 'parent');
|
112 |
|
|
// Get new order
|
113 |
|
|
$position = $order->get_new($parent);
|
114 |
|
|
// Clean new order
|
115 |
|
|
$order->clean($parent);
|
116 |
|
|
} else {
|
117 |
|
|
$position = $old_position;
|
118 |
|
|
}
|
119 |
|
|
|
120 |
|
|
// Work out level and root parent
|
121 |
1277
|
Luisehahne
|
if ($parent!='0')
|
122 |
|
|
{
|
123 |
1203
|
Luisehahne
|
$level = level_count($parent)+1;
|
124 |
|
|
$root_parent = root_parent($parent);
|
125 |
|
|
}
|
126 |
|
|
else {
|
127 |
|
|
$level = '0';
|
128 |
|
|
$root_parent = '0';
|
129 |
|
|
}
|
130 |
|
|
|
131 |
|
|
// Work-out what the link should be
|
132 |
1277
|
Luisehahne
|
if($parent == '0')
|
133 |
|
|
{
|
134 |
1203
|
Luisehahne
|
$link = '/'.page_filename($menu_title);
|
135 |
|
|
// rename menu titles: index && intro to prevent clashes with intro page feature and WB core file /pages/index.php
|
136 |
1277
|
Luisehahne
|
if($link == '/index' || $link == '/intro')
|
137 |
|
|
{
|
138 |
1203
|
Luisehahne
|
$link .= '_' .$page_id;
|
139 |
|
|
$filename = WB_PATH.PAGES_DIRECTORY.'/'.page_filename($menu_title).'_'.$page_id .PAGE_EXTENSION;
|
140 |
|
|
} else {
|
141 |
1277
|
Luisehahne
|
$filename = WB_PATH.PAGES_DIRECTORY.'/'.page_filename($menu_title).PAGE_EXTENSION;
|
142 |
1203
|
Luisehahne
|
}
|
143 |
|
|
} else {
|
144 |
|
|
$parent_section = '';
|
145 |
|
|
$parent_titles = array_reverse(get_parent_titles($parent));
|
146 |
1277
|
Luisehahne
|
foreach($parent_titles AS $parent_title)
|
147 |
|
|
{
|
148 |
1203
|
Luisehahne
|
$parent_section .= page_filename($parent_title).'/';
|
149 |
|
|
}
|
150 |
1277
|
Luisehahne
|
if($parent_section == '/')
|
151 |
|
|
{
|
152 |
|
|
$parent_section = '';
|
153 |
|
|
}
|
154 |
1203
|
Luisehahne
|
$link = '/'.$parent_section.page_filename($menu_title);
|
155 |
1277
|
Luisehahne
|
$filename = WB_PATH.PAGES_DIRECTORY.'/'.$parent_section.page_filename($menu_title).PAGE_EXTENSION;
|
156 |
1203
|
Luisehahne
|
}
|
157 |
|
|
|
158 |
|
|
// Check if a page with same page filename exists
|
159 |
1277
|
Luisehahne
|
// $database = new database();
|
160 |
|
|
$sql = 'SELECT `page_id`,`page_title` FROM `'.TABLE_PREFIX.'pages` WHERE `link` = "'.$link.'" AND `page_id` != '.$page_id;
|
161 |
|
|
$get_same_page = $database->query($sql);
|
162 |
|
|
|
163 |
|
|
if($get_same_page->numRows() > 0)
|
164 |
|
|
{
|
165 |
1203
|
Luisehahne
|
$admin->print_error($MESSAGE['PAGES']['PAGE_EXISTS']);
|
166 |
|
|
}
|
167 |
|
|
|
168 |
|
|
// Update page with new order
|
169 |
1277
|
Luisehahne
|
$sql = 'UPDATE `'.TABLE_PREFIX.'pages` SET `parent`='.$parent.', `position`='.$position.' WHERE `page_id`='.$page_id.'';
|
170 |
|
|
// $database = new database();
|
171 |
|
|
$database->query($sql);
|
172 |
1203
|
Luisehahne
|
|
173 |
|
|
// Get page trail
|
174 |
|
|
$page_trail = get_page_trail($page_id);
|
175 |
|
|
|
176 |
|
|
// Update page settings in the pages table
|
177 |
1277
|
Luisehahne
|
$sql = 'UPDATE `'.TABLE_PREFIX.'pages` SET ';
|
178 |
|
|
$sql .= '`parent` = '.$parent.', ';
|
179 |
|
|
$sql .= '`page_title` = "'.$page_title.'", ';
|
180 |
|
|
$sql .= '`menu_title` = "'.$menu_title.'", ';
|
181 |
|
|
$sql .= '`menu` = '.$menu.', ';
|
182 |
|
|
$sql .= '`level` = '.$level.', ';
|
183 |
|
|
$sql .= '`page_trail` = "'.$page_trail.'", ';
|
184 |
|
|
$sql .= '`root_parent` = '.$root_parent.', ';
|
185 |
|
|
$sql .= '`link` = "'.$link.'", ';
|
186 |
|
|
$sql .= '`template` = "'.$template.'", ';
|
187 |
|
|
$sql .= '`target` = "'.$target.'", ';
|
188 |
|
|
$sql .= '`description` = "'.$description.'", ';
|
189 |
|
|
$sql .= '`keywords` = "'.$keywords.'", ';
|
190 |
|
|
$sql .= '`position` = '.$position.', ';
|
191 |
|
|
$sql .= '`visibility` = "'.$visibility.'", ';
|
192 |
|
|
$sql .= '`searching` = '.$searching.', ';
|
193 |
|
|
$sql .= '`language` = "'.$language.'", ';
|
194 |
|
|
$sql .= '`admin_groups` = "'.$admin_groups.'", ';
|
195 |
|
|
$sql .= '`viewing_groups` = "'.$viewing_groups.'"';
|
196 |
1301
|
Luisehahne
|
$sql .= (defined('PAGE_LANGUAGES') && PAGE_LANGUAGES) && $field_set && (file_exists(WB_PATH.'/modules/mod_multilingual/update_keys.php')) ? ', `page_code` = '.(int)$page_code.' ' : ' ';
|
197 |
1277
|
Luisehahne
|
$sql .= 'WHERE `page_id` = '.$page_id;
|
198 |
|
|
$database->query($sql);
|
199 |
|
|
|
200 |
|
|
$target_url = ADMIN_URL.'/pages/settings.php?page_id='.$page_id;
|
201 |
|
|
if($database->is_error())
|
202 |
1203
|
Luisehahne
|
{
|
203 |
1277
|
Luisehahne
|
$admin->print_error($database->get_error(), $target_url );
|
204 |
1203
|
Luisehahne
|
}
|
205 |
|
|
// Clean old order if needed
|
206 |
1277
|
Luisehahne
|
if($parent != $old_parent)
|
207 |
|
|
{
|
208 |
1203
|
Luisehahne
|
$order->clean($old_parent);
|
209 |
|
|
}
|
210 |
|
|
|
211 |
|
|
/* BEGIN page "access file" code */
|
212 |
|
|
|
213 |
|
|
// Create a new file in the /pages dir if title changed
|
214 |
1277
|
Luisehahne
|
if(!is_writable(WB_PATH.PAGES_DIRECTORY.'/'))
|
215 |
|
|
{
|
216 |
1203
|
Luisehahne
|
$admin->print_error($MESSAGE['PAGES']['CANNOT_CREATE_ACCESS_FILE']);
|
217 |
|
|
} else {
|
218 |
1301
|
Luisehahne
|
$old_filename = WB_PATH.PAGES_DIRECTORY.$old_link.PAGE_EXTENSION;
|
219 |
1203
|
Luisehahne
|
// First check if we need to create a new file
|
220 |
1301
|
Luisehahne
|
if(($old_link != $link) || (!file_exists($old_filename)))
|
221 |
1277
|
Luisehahne
|
{
|
222 |
1203
|
Luisehahne
|
// Delete old file
|
223 |
|
|
$old_filename = WB_PATH.PAGES_DIRECTORY.$old_link.PAGE_EXTENSION;
|
224 |
1277
|
Luisehahne
|
if(file_exists($old_filename))
|
225 |
|
|
{
|
226 |
1203
|
Luisehahne
|
unlink($old_filename);
|
227 |
|
|
}
|
228 |
|
|
// Create access file
|
229 |
|
|
create_access_file($filename,$page_id,$level);
|
230 |
|
|
// Move a directory for this page
|
231 |
1277
|
Luisehahne
|
if(file_exists(WB_PATH.PAGES_DIRECTORY.$old_link.'/') AND is_dir(WB_PATH.PAGES_DIRECTORY.$old_link.'/'))
|
232 |
|
|
{
|
233 |
1203
|
Luisehahne
|
rename(WB_PATH.PAGES_DIRECTORY.$old_link.'/', WB_PATH.PAGES_DIRECTORY.$link.'/');
|
234 |
|
|
}
|
235 |
|
|
// Update any pages that had the old link with the new one
|
236 |
|
|
$old_link_len = strlen($old_link);
|
237 |
1277
|
Luisehahne
|
$sql = '';
|
238 |
1203
|
Luisehahne
|
$query_subs = $database->query("SELECT page_id,link,level FROM ".TABLE_PREFIX."pages WHERE link LIKE '%$old_link/%' ORDER BY LEVEL ASC");
|
239 |
1277
|
Luisehahne
|
|
240 |
|
|
if($query_subs->numRows() > 0)
|
241 |
|
|
{
|
242 |
|
|
while($sub = $query_subs->fetchRow())
|
243 |
|
|
{
|
244 |
1203
|
Luisehahne
|
// Double-check to see if it contains old link
|
245 |
1277
|
Luisehahne
|
if(substr($sub['link'], 0, $old_link_len) == $old_link)
|
246 |
|
|
{
|
247 |
1203
|
Luisehahne
|
// Get new link
|
248 |
|
|
$replace_this = $old_link;
|
249 |
|
|
$old_sub_link_len =strlen($sub['link']);
|
250 |
|
|
$new_sub_link = $link.'/'.substr($sub['link'],$old_link_len+1,$old_sub_link_len);
|
251 |
|
|
// Work out level
|
252 |
|
|
$new_sub_level = level_count($sub['page_id']);
|
253 |
|
|
// Update level and link
|
254 |
|
|
$database->query("UPDATE ".TABLE_PREFIX."pages SET link = '$new_sub_link', level = '$new_sub_level' WHERE page_id = '".$sub['page_id']."' LIMIT 1");
|
255 |
|
|
// Re-write the access file for this page
|
256 |
|
|
$old_subpage_file = WB_PATH.PAGES_DIRECTORY.$new_sub_link.PAGE_EXTENSION;
|
257 |
1277
|
Luisehahne
|
if(file_exists($old_subpage_file))
|
258 |
|
|
{
|
259 |
1203
|
Luisehahne
|
unlink($old_subpage_file);
|
260 |
|
|
}
|
261 |
|
|
create_access_file(WB_PATH.PAGES_DIRECTORY.$new_sub_link.PAGE_EXTENSION, $sub['page_id'], $new_sub_level);
|
262 |
|
|
}
|
263 |
|
|
}
|
264 |
|
|
}
|
265 |
|
|
}
|
266 |
|
|
}
|
267 |
|
|
|
268 |
|
|
// Function to fix page trail of subs
|
269 |
1277
|
Luisehahne
|
function fix_page_trail($parent,$root_parent)
|
270 |
|
|
{
|
271 |
1203
|
Luisehahne
|
// Get objects and vars from outside this function
|
272 |
|
|
global $admin, $template, $database, $TEXT, $MESSAGE;
|
273 |
|
|
// Get page list from database
|
274 |
1277
|
Luisehahne
|
// $database = new database();
|
275 |
1203
|
Luisehahne
|
$query = "SELECT page_id FROM ".TABLE_PREFIX."pages WHERE parent = '$parent'";
|
276 |
|
|
$get_pages = $database->query($query);
|
277 |
|
|
// Insert values into main page list
|
278 |
1277
|
Luisehahne
|
if($get_pages->numRows() > 0)
|
279 |
|
|
{
|
280 |
|
|
while($page = $get_pages->fetchRow())
|
281 |
|
|
{
|
282 |
1203
|
Luisehahne
|
// Fix page trail
|
283 |
1277
|
Luisehahne
|
|
284 |
1203
|
Luisehahne
|
$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']."'");
|
285 |
|
|
// Run this query on subs
|
286 |
|
|
fix_page_trail($page['page_id'],$root_parent);
|
287 |
|
|
}
|
288 |
|
|
}
|
289 |
|
|
}
|
290 |
1277
|
Luisehahne
|
|
291 |
1203
|
Luisehahne
|
// Fix sub-pages page trail
|
292 |
|
|
fix_page_trail($page_id,$root_parent);
|
293 |
|
|
|
294 |
|
|
/* END page "access file" code */
|
295 |
|
|
|
296 |
1277
|
Luisehahne
|
$pagetree_url = ADMIN_URL.'/pages/index.php';
|
297 |
|
|
$target_url = ADMIN_URL.'/pages/settings.php?page_id='.$page_id;
|
298 |
1203
|
Luisehahne
|
// Check if there is a db error, otherwise say successful
|
299 |
1277
|
Luisehahne
|
if($database->is_error())
|
300 |
|
|
{
|
301 |
|
|
$admin->print_error($database->get_error(), $target_url );
|
302 |
1203
|
Luisehahne
|
} else {
|
303 |
1277
|
Luisehahne
|
$admin->print_success($MESSAGE['PAGES']['SAVED_SETTINGS'], $target_url );
|
304 |
1203
|
Luisehahne
|
}
|
305 |
|
|
|
306 |
|
|
// Print admin footer
|
307 |
|
|
$admin->print_footer();
|
308 |
|
|
|
309 |
1277
|
Luisehahne
|
?>
|