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