Project

General

Profile

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