Project

General

Profile

1 1664 darkviper
<?php
2
/**
3
 *
4
 * @category        admin
5
 * @package         pages
6 1706 Luisehahne
 * @author          Ryan Djurovich, WebsiteBaker Project
7
 * @copyright       2009-2012, WebsiteBaker Org. e.V.
8 1840 Luisehahne
 * @link            http://www.websitebaker2.org/
9 1664 darkviper
 * @license         http://www.gnu.org/licenses/gpl.html
10
 * @platform        WebsiteBaker 2.8.x
11
 * @requirements    PHP 5.2.2 and higher
12
 * @version         $Id$
13 1840 Luisehahne
 * @filesource      $HeadURL$
14 1664 darkviper
 * @lastmodified    $Date$
15
 *
16
 */
17
18
// Create new admin object and print admin header
19 1825 Luisehahne
if(!defined('WB_URL'))
20
{
21 1869 Luisehahne
	$config_file = realpath('../../config.php');
22
	if(file_exists($config_file) && !defined('WB_URL'))
23
	{
24
		require($config_file);
25
	}
26 1825 Luisehahne
}
27
if(!class_exists('admin', false)){ include(WB_PATH.'/framework/class.admin.php'); }
28 1664 darkviper
29 1760 Luisehahne
$lang_dir = dirname(__FILE__).'/languages/';
30
$lang = file_exists($lang_dir.LANGUAGE.'.php') ? LANGUAGE : 'EN';
31 1840 Luisehahne
//require_once($lang_dir.$lang.'.php');
32
if( !isset($TEXT['PAGE_LANG_LOADED']) ) { require($lang_dir.$lang.'.php'); }
33 1760 Luisehahne
34 1664 darkviper
// suppress to print the header, so no new FTAN will be set
35
$admin = new admin('Pages', 'pages_settings',false);
36 1760 Luisehahne
$pagetree_url = ADMIN_URL.'/pages/index.php';
37
38 1664 darkviper
// Get page id
39 1735 Luisehahne
if(!isset($_POST['page_id']) || (isset($_POST['page_id']) && preg_match('/[^0-9a-z]/i',$_POST['page_id'])) )
40 1664 darkviper
{
41
	header("Location: index.php");
42
	exit(0);
43
} else {
44
//	$page_id = $admin->checkIDKEY('page_id');
45 1706 Luisehahne
//	$page_id = (int)$_POST['page_id']; || preg_match('/[^0-9a-f]/i',$_POST['page_id'])
46 1664 darkviper
	if((!($page_id = $admin->checkIDKEY('page_id')))) {
47 1735 Luisehahne
		$admin->print_header();
48 1760 Luisehahne
		$admin->print_error($MESSAGE['GENERIC_SECURITY_ACCESS'], $pagetree_url);
49 1664 darkviper
	}
50
}
51
52
/*
53
if( (!($page_id = $admin->checkIDKEY('page_id', 0, $_SERVER['REQUEST_METHOD']))) )
54
{
55
	$admin->print_error($MESSAGE['GENERIC_SECURITY_ACCESS']);
56
}
57
*/
58
$target_url = ADMIN_URL.'/pages/settings.php?page_id='.$page_id;
59
60
if (!$admin->checkFTAN())
61
{
62
	$admin->print_header();
63
	$admin->print_error($MESSAGE['GENERIC_SECURITY_ACCESS'],$target_url);
64
}
65 1825 Luisehahne
66 1664 darkviper
// After check print the header
67
$admin->print_header();
68
69 1849 Luisehahne
if(isset($_POST['extendet_submit'])) {
70
//	$val = (((($page_exented=='1') ? $page_exented : 0)) + 1) % 2;
71
	$val = (defined('PAGE_EXTENDET') ? filter_var(PAGE_EXTENDET, FILTER_VALIDATE_BOOLEAN, FILTER_NULL_ON_FAILURE) : false);
72
	$sql  = (defined('PAGE_EXTENDET') ? 'UPDATE `' : 'INSERT INTO `') . TABLE_PREFIX . 'settings` SET ';
73
	$sql .= '`name`=\'page_extendet\', ';
74
	$sql .= '`value`=\''.($val ? 'false' : 'true').'\' ';
75
	$sql .= (defined('PAGE_EXTENDET') ? 'WHERE `name`=\'page_extendet\'' : '');
76 1825 Luisehahne
    if($database->query($sql)) {
77
        // redirect to backend
78
echo "<p style=\"text-align:center;\"> If the script</strong> could not be start automatically.\n" .
79
     "Please click <a style=\"font-weight:bold;\" " .
80
     "href=\"".$target_url."\">on this link</a> to start the script!</p>\n";
81
echo "<script type=\"text/javascript\">
82
<!--
83
// Get the location object
84
var locationObj = document.location;
85
// Set the value of the location object
86
document.location = '$target_url';
87
-->
88
</script>";
89
90
    } else {
91
    	$admin->print_error($database->get_error(), $target_url );
92
    }
93
}
94
95 1664 darkviper
// Include the WB functions file
96 1825 Luisehahne
if(!function_exists('directory_list')) { require(WB_PATH.'/framework/functions.php'); }
97 1664 darkviper
98
// Get values
99
$page_title = str_replace(array("[[", "]]"), '', htmlspecialchars($admin->get_post_escaped('page_title')));
100
$menu_title = str_replace(array("[[", "]]"), '', htmlspecialchars($admin->get_post_escaped('menu_title')));
101 1760 Luisehahne
$seo_title = str_replace(array("[[", "]]"), '', htmlspecialchars($admin->get_post_escaped('seo_title')));
102 1664 darkviper
$page_code = intval($admin->get_post('page_code')) ;
103
$description = str_replace(array("[[", "]]"), '', htmlspecialchars($admin->add_slashes($admin->get_post('description'))));
104
$keywords = str_replace(array("[[", "]]"), '', htmlspecialchars($admin->add_slashes($admin->get_post('keywords'))));
105
$parent = intval($admin->get_post('parent')); // fix secunia 2010-91-3
106
$visibility = $admin->get_post_escaped('visibility');
107
if (!in_array($visibility, array('public', 'private', 'registered', 'hidden', 'none'))) {$visibility = 'public';} // fix secunia 2010-93-3
108
$template = preg_replace('/[^a-z0-9_-]/i', "", $admin->get_post('template')); // fix secunia 2010-93-3
109
$template = (($template == DEFAULT_TEMPLATE ) ? '' : $template);
110
$target = preg_replace("/\W/", "", $admin->get_post('target'));
111 1782 Luisehahne
$aAdminGroups   = (isset($_POST['admin_groups']) ? $_POST['admin_groups'] : array('1'));
112 1664 darkviper
$aAdminUsers    = (isset($_POST['admin_users']) ? $_POST['admin_users'] : array());
113 1782 Luisehahne
$aViewingGroups = (isset($_POST['viewing_groups']) ? $_POST['viewing_groups'] : array('1'));
114 1664 darkviper
$aViewingUsers  = (isset($_POST['viewing_users']) ? $_POST['viewing_users'] : array());
115
$searching = intval($admin->get_post('searching'));
116
$language = strtoupper($admin->get_post('language'));
117
$language = (preg_match('/^[A-Z]{2}$/', $language) ? $language : DEFAULT_LANGUAGE);
118
$menu = intval($admin->get_post('menu')); // fix secunia 2010-91-3
119 1749 Luisehahne
$menu = ($menu==0) ? 1 : $menu;
120 1664 darkviper
$page_code = (isset($_POST['page_code']) ? intval($_POST['page_code']) : 0);
121 1681 darkviper
$sPageIcon = (isset($_POST['page_icon']) ? $_POST['page_icon'] : 0);
122
$sMenuIcon0 = (isset($_POST['menu_icon_0']) ? $_POST['menu_icon_0'] : 0);
123
$sMenuIcon1 = (isset($_POST['menu_icon_1']) ? $_POST['menu_icon_1'] : 0);
124
125 1664 darkviper
// Validate data
126
if($page_title == '' || substr($page_title,0,1)=='.')
127
{
128 1760 Luisehahne
	$admin->print_error($MESSAGE['PAGES_BLANK_PAGE_TITLE'],$target_url);
129 1664 darkviper
}
130
if($menu_title == '' || substr($menu_title,0,1)=='.')
131
{
132 1760 Luisehahne
	$admin->print_error($MESSAGE['PAGES_BLANK_MENU_TITLE'],$target_url);
133 1664 darkviper
}
134 1760 Luisehahne
if($seo_title == '' || substr($seo_title,0,1)=='.')
135
{
136 1869 Luisehahne
	$seo_title = $menu_title;
137 1760 Luisehahne
}
138 1664 darkviper
139
// Get existing perms
140 1760 Luisehahne
$sql  = 'SELECT `parent`,`link`,`position`,`admin_groups`,`admin_users`,`menu_title` ';
141
$sql .= 'FROM `'.TABLE_PREFIX.'pages` WHERE `page_id`='.$page_id;
142
143 1664 darkviper
$results = $database->query($sql);
144
145 1760 Luisehahne
$results_array = $results->fetchRow(MYSQL_ASSOC);
146 1664 darkviper
$old_parent = $results_array['parent'];
147
$old_link = $results_array['link'];
148
$old_position = $results_array['position'];
149
150 1706 Luisehahne
if($admin->ami_group_member('1')) {
151
	if(!$admin->ami_group_member($results_array['admin_groups']) &&
152
	   !$admin->is_group_match($admin->get_user_id(), $results_array['admin_users']))
153
	{
154
		$admin->print_error($MESSAGE['PAGES_INSUFFICIENT_PERMISSIONS']);
155
	}
156
	// Setup admin groups
157
	$aAdminGroups = (is_array($aAdminGroups) ? $aAdminGroups : array(1));
158
	array_unshift($aAdminGroups, 1);
159 1788 Luisehahne
	$sAdminGroups = implode(',', array_unique($aAdminGroups));
160 1706 Luisehahne
	$sAdminGroups = (preg_match('/^,|[^0-9,]|,,|,$/', $sAdminGroups) ? '1' : $sAdminGroups);
161
162
	$aAdminUsers = (is_array($aAdminUsers) ? $aAdminUsers : array());
163
	$sAdminUsers = implode(',', array_diff($aAdminUsers, array(0)));
164
	$sAdminUsers = (preg_match('/^,|[^0-9,]|,,|,$/', $sAdminUsers) ? array() : $sAdminUsers);
165 1664 darkviper
}
166
167
$aViewingGroups = (is_array($aViewingGroups) ? $aViewingGroups : array(1));
168
array_unshift($aViewingGroups, 1);
169 1788 Luisehahne
$sViewingGroups = implode(',', array_unique($aViewingGroups));
170 1664 darkviper
$sViewingGroups = (preg_match('/^,|[^0-9,]|,,|,$/', $sViewingGroups) ? '1' : $sViewingGroups);
171
172
$aViewingUsers = (is_array($aViewingUsers) ? $aViewingUsers : array());
173
$sViewingUsers = implode(',', array_diff($aViewingUsers, array(0)));
174
$sViewingUsers = (preg_match('/^,|[^0-9,]|,,|,$/', $sViewingUsers) ? array() : $sViewingUsers);
175
176 1681 darkviper
$sPageIcon = (($sPageIcon == '0') ? '' : $sPageIcon);
177
if(!is_readable(WB_PATH.$sPageIcon)) { $sPageIcon = ''; }
178
$sMenuIcon0 = (($sMenuIcon0 == '0') ? '' : $sMenuIcon0);
179
if(!is_readable(WB_PATH.$sMenuIcon0)) { $sMenuIcon0 = ''; }
180
$sMenuIcon1 = (($sMenuIcon1 == '0') ? '' : $sMenuIcon1);
181
if(!is_readable(WB_PATH.$sMenuIcon1)) { $sMenuIcon1 = ''; }
182
183 1664 darkviper
// If needed, get new order
184
if($parent != $old_parent)
185
{
186
	// Include ordering class
187
	require(WB_PATH.'/framework/class.order.php');
188
	$order = new order(TABLE_PREFIX.'pages', 'position', 'page_id', 'parent');
189
	// Get new order
190
	$position = $order->get_new($parent);
191
	// Clean new order
192
	$order->clean($parent);
193
} else {
194
	$position = $old_position;
195
}
196
197
// Work out level and root parent
198
if ($parent!='0')
199
{
200
	$level = level_count($parent)+1;
201
	$root_parent = root_parent($parent);
202 1760 Luisehahne
} else {
203 1754 Luisehahne
// Work out level
204
    $level = level_count($page_id);
205
// Work out root parent
206
    $root_parent = root_parent($page_id);
207 1664 darkviper
}
208
209 1760 Luisehahne
$link = '/'.page_filename($seo_title);
210
211 1664 darkviper
// Work-out what the link should be
212 1760 Luisehahne
if($parent == '0') {
213 1869 Luisehahne
	if($link == '/index' || $link == '/intro')
214
	{
215
		$link .= '_' .$page_id;
216
		$filename = WB_PATH.PAGES_DIRECTORY.$link .PAGE_EXTENSION;
217
218
	} else {
219
	    $filename = WB_PATH.PAGES_DIRECTORY.$link.PAGE_EXTENSION;
220
	}
221 1664 darkviper
} else {
222
	$parent_section = '';
223
	$parent_titles = array_reverse(get_parent_titles($parent));
224 1760 Luisehahne
225 1664 darkviper
	foreach($parent_titles AS $parent_title)
226
    {
227 1760 Luisehahne
		$parent_section .= '/'.page_filename($parent_title);
228 1664 darkviper
	}
229 1760 Luisehahne
230 1664 darkviper
	if($parent_section == '/')
231
    {
232
      $parent_section = '';
233
    }
234 1760 Luisehahne
235
	$link = $parent_section.$link;
236 1869 Luisehahne
	$filename = WB_PATH.PAGES_DIRECTORY.$link.PAGE_EXTENSION;
237 1664 darkviper
}
238
239
// Check if a page with same page filename exists
240
// $database = new database();
241
$sql = 'SELECT `page_id`,`page_title` FROM `'.TABLE_PREFIX.'pages` WHERE `link` = "'.$link.'" AND `page_id` != '.$page_id;
242 1760 Luisehahne
243 1664 darkviper
$get_same_page = $database->query($sql);
244
245
if($get_same_page->numRows() > 0)
246
{
247 1760 Luisehahne
	$admin->print_error($MESSAGE['PAGES_PAGE_EXISTS'], $target_url);
248 1664 darkviper
}
249
250
// Update page with new order
251
$sql = 'UPDATE `'.TABLE_PREFIX.'pages` SET `parent`='.$parent.', `position`='.$position.' WHERE `page_id`='.$page_id.'';
252
// $database = new database();
253
$database->query($sql);
254
255
// Get page trail
256
$page_trail = get_page_trail($page_id);
257
258
// Update page settings in the pages table
259
$sql = 'UPDATE `'.TABLE_PREFIX.'pages` '
260 1869 Luisehahne
	 . 'SET `parent`='.$parent.', '
261
	 .     '`page_title`=\''.$page_title.'\', '
262
	 .     '`tooltip`=\''.$page_title.'\', '
263
	 .     '`page_icon` =\''.$database->escapeString($sPageIcon).'\', '
264
	 .     '`menu_title`=\''.$menu_title.'\', '
265
	 .     '`menu_icon_0` =\''.$database->escapeString($sMenuIcon0).'\', '
266
	 .     '`menu_icon_1` =\''.$database->escapeString($sMenuIcon1).'\', '
267
	 .     '`menu`='.$menu.', '
268
	 .     '`level`='.$level.', '
269
	 .     '`page_trail`=\''.$page_trail.'\', '
270
	 .     '`root_parent`='.$root_parent.', '
271
	 .     '`link`=\''.$link.'\', '
272
	 .     '`template`=\''.$template.'\', '
273
	 .     '`target`=\''.$target.'\', '
274
	 .     '`description`=\''.$description.'\', '
275
	 .     '`keywords`=\''.$keywords.'\', '
276
	 .     '`position`='.$position.', '
277
	 .     '`visibility`=\''.$visibility.'\', '
278
	 .     '`searching`='.$searching.', '
279
	 .     '`language`=\''.$language.'\', ';
280 1706 Luisehahne
if($admin->ami_group_member('1')) {
281
	$sql .= ''
282 1760 Luisehahne
	     . '`admin_groups`=\''.$sAdminGroups.'\', '
283
	     . '`admin_users`=\''.$sAdminUsers.'\', ';
284 1706 Luisehahne
}
285 1869 Luisehahne
	$sql .= ''
286
	 . '`viewing_groups`=\''.$sViewingGroups.'\', '
287
	 . '`viewing_users`=\''.$sViewingUsers.'\', '
288
	 . '`page_code`='.$page_code.' '
289
	 . 'WHERE `page_id`='.$page_id;
290 1706 Luisehahne
291 1664 darkviper
if(!$database->query($sql)) {
292
	$target_url = ADMIN_URL.'/pages/settings.php?page_id='.$page_id;
293
	$admin->print_error($database->get_error(), $target_url );
294
}
295 1760 Luisehahne
296 1664 darkviper
// Clean old order if needed
297
if($parent != $old_parent)
298
{
299
	$order->clean($old_parent);
300
}
301
302 1868 Luisehahne
// using standard function by core,
303
function fix_page_trail($page_id) {
304 1869 Luisehahne
	global $database,$admin,$target_url,$pagetree_url,$MESSAGE;
305 1664 darkviper
306 1869 Luisehahne
	$target_url = (isset($_POST['back_submit'])) ? $pagetree_url : $target_url;
307
308
	// Work out level
309
	$level = level_count($page_id);
310
	// Work out root parent
311
	$root_parent = root_parent($page_id);
312
	// Work out page trail
313
	$page_trail = get_page_trail($page_id);
314
	// Update page with new level and link
315
	$sql  = 'UPDATE `'.TABLE_PREFIX.'pages` SET ';
316
	$sql .= '`root_parent` = '.$root_parent.', ';
317
	$sql .= '`level` = '.$level.', ';
318
	$sql .= '`page_trail` = "'.$page_trail.'" ';
319
	$sql .= 'WHERE `page_id` = '.$page_id;
320 1868 Luisehahne
321 1869 Luisehahne
	if($database->query($sql)) {
322
		$admin->print_success($MESSAGE['PAGES_SAVED_SETTINGS'], $target_url );
323
	} else {
324
		$admin->print_error($database->get_error(), $target_url );
325
	}
326 1868 Luisehahne
}
327
328
// Fix sub-pages page trail
329
fix_page_trail($page_id);
330
331
/**
332
 *
333
 * BEGIN page "access file" code
334
 * first check for existing pages directory
335
 * if not exists try to create
336
 * otherwise acess denied
337
 *
338
 */
339 1869 Luisehahne
340
$bCanCreateAcessFiles = make_dir(WB_PATH.PAGES_DIRECTORY);
341
$bCanCreateAcessFiles = (($bCanCreateAcessFiles==true) ? file_exists(WB_PATH) && is_writable(WB_PATH.PAGES_DIRECTORY) : false );
342 1868 Luisehahne
if( !$bCanCreateAcessFiles )
343 1664 darkviper
{
344 1760 Luisehahne
	$admin->print_error($MESSAGE['PAGES_CANNOT_CREATE_ACCESS_FILE'], $target_url);
345 1664 darkviper
} else {
346 1868 Luisehahne
// Create a new file in the /pages dir if title changed
347
348 1869 Luisehahne
	$old_filename = WB_PATH.PAGES_DIRECTORY.$old_link.PAGE_EXTENSION;
349 1760 Luisehahne
350 1664 darkviper
	// First check if we need to create a new file
351
	if(($old_link != $link) || (!file_exists($old_filename)))
352 1869 Luisehahne
	{
353 1664 darkviper
		// Delete old file
354
		$old_filename = WB_PATH.PAGES_DIRECTORY.$old_link.PAGE_EXTENSION;
355
		if(file_exists($old_filename))
356 1869 Luisehahne
		{
357 1664 darkviper
			unlink($old_filename);
358
		}
359 1760 Luisehahne
360 1664 darkviper
		// Create access file
361
		create_access_file($filename,$page_id,$level);
362 1869 Luisehahne
		if(!file_exists($filename)) {
363
			$admin->print_error($MESSAGE['PAGES_CANNOT_CREATE_ACCESS_FILE']);
364
		}
365 1664 darkviper
		// Move a directory for this page
366 1840 Luisehahne
		if(is_readable(WB_PATH.PAGES_DIRECTORY.$old_link.'/') && is_dir(WB_PATH.PAGES_DIRECTORY.$old_link.'/'))
367 1869 Luisehahne
		{
368 1664 darkviper
			rename(WB_PATH.PAGES_DIRECTORY.$old_link.'/', WB_PATH.PAGES_DIRECTORY.$link.'/');
369
		}
370
		// Update any pages that had the old link with the new one
371
		$old_link_len = strlen($old_link);
372 1869 Luisehahne
		$sql = '';
373 1664 darkviper
		$query_subs = $database->query("SELECT page_id,link,level FROM ".TABLE_PREFIX."pages WHERE link LIKE '%$old_link/%' ORDER BY LEVEL ASC");
374
375
		if($query_subs->numRows() > 0)
376 1869 Luisehahne
		{
377 1664 darkviper
			while($sub = $query_subs->fetchRow())
378 1869 Luisehahne
			{
379 1664 darkviper
				// Double-check to see if it contains old link
380 1869 Luisehahne
				if(substr($sub['link'], 0, $old_link_len) == $old_link) {
381 1664 darkviper
					// Get new link
382
					$replace_this = $old_link;
383
					$old_sub_link_len =strlen($sub['link']);
384
					$new_sub_link = $link.'/'.substr($sub['link'],$old_link_len+1,$old_sub_link_len);
385
					// Work out level
386
					$new_sub_level = level_count($sub['page_id']);
387
					// Update level and link
388
					$database->query("UPDATE ".TABLE_PREFIX."pages SET link = '$new_sub_link', level = '$new_sub_level' WHERE page_id = '".$sub['page_id']."' LIMIT 1");
389
					// Re-write the access file for this page
390
					$old_subpage_file = WB_PATH.PAGES_DIRECTORY.$new_sub_link.PAGE_EXTENSION;
391 1869 Luisehahne
					if(file_exists($old_subpage_file)) {
392 1664 darkviper
						unlink($old_subpage_file);
393
					}
394 1869 Luisehahne
					$sAccessFile = WB_PATH.PAGES_DIRECTORY.$new_sub_link.PAGE_EXTENSION;
395 1766 Luisehahne
					create_access_file($sAccessFile, $sub['page_id'], $new_sub_level);
396 1869 Luisehahne
					if(!file_exists($sAccessFile)) {
397
						$admin->print_error($MESSAGE['PAGES_CANNOT_CREATE_ACCESS_FILE']);
398
					}
399 1766 Luisehahne
400 1664 darkviper
				}
401
			}
402
		}
403
	}
404
}
405
406
$admin->print_footer();