Project

General

Profile

1
<?php
2
/**
3
 *
4
 * @category        admin
5
 * @package         pages
6
 * @author          Ryan Djurovich, WebsiteBaker Project
7
 * @copyright       2009-2013, WebsiteBaker Org. e.V.
8
 * @link            http://www.websitebaker.org/
9
 * @license         http://www.gnu.org/licenses/gpl.html
10
 * @platform        WebsiteBaker 2.8.4
11
 * @requirements    PHP 5.2.2 and higher
12
 * @version         $Id: settings_save.php 1986 2013-10-19 00:48:15Z Luisehahne $
13
 * @filesource      $HeadURL: svn://isteam.dynxs.de/wb-archiv/branches/2.8.x/wb/admin/pages/settings_save.php $
14
 * @lastmodified    $Date: 2013-10-19 02:48:15 +0200 (Sat, 19 Oct 2013) $
15
 *
16
 */
17

    
18
// Create new admin object and print admin header
19
if(!defined('WB_URL'))
20
{
21
	$config_file = realpath('../../config.php');
22
	if(file_exists($config_file) && !defined('WB_URL'))
23
	{
24
		require($config_file);
25
	}
26
}
27
if(!class_exists('admin', false)){ include(WB_PATH.'/framework/class.admin.php'); }
28

    
29
//$lang_dir = dirname(__FILE__).'/languages/';
30
//$lang = file_exists($lang_dir.LANGUAGE.'.php') ? LANGUAGE : 'EN';
31
//require_once($lang_dir.$lang.'.php');
32
//if( !isset($mLang->TEXT_PAGE_LANG_LOADED) ) { require($lang_dir.$lang.'.php'); }
33

    
34
// suppress to print the header, so no new FTAN will be set
35
$admin = new admin('Pages', 'pages_settings',false);
36
$pagetree_url = ADMIN_URL.'/pages/index.php';
37

    
38
$mLang = Translate::getinstance();
39
$mLang->enableAddon('admin\pages');
40

    
41
// Get page id
42
if(!isset($_POST['page_id']) || (isset($_POST['page_id']) && preg_match('/[^0-9a-z]/i',$_POST['page_id'])) )
43
{
44
	header("Location: index.php");
45
	exit(0);
46
} else {
47
//	$page_id = $admin->checkIDKEY('page_id');
48
//	$page_id = (int)$_POST['page_id']; || preg_match('/[^0-9a-f]/i',$_POST['page_id'])
49
	if((!($page_id = $admin->checkIDKEY('page_id')))) {
50
		$admin->print_header();
51
		$admin->print_error($mLang->MESSAGE_GENERIC_SECURITY_ACCESS, $pagetree_url);
52
	}
53
}
54

    
55
/*
56
if( (!($page_id = $admin->checkIDKEY('page_id', 0, $_SERVER['REQUEST_METHOD']))) )
57
{
58
	$admin->print_error($MESSAGE['GENERIC_SECURITY_ACCESS']);
59
}
60
*/
61
$target_url = ADMIN_URL.'/pages/settings.php?page_id='.$page_id;
62

    
63
if (!$admin->checkFTAN())
64
{
65
	$admin->print_header();
66
	$admin->print_error($mLang->MESSAGE_GENERIC_SECURITY_ACCESS,$target_url);
67
}
68

    
69
// After check print the header
70
$admin->print_header();
71

    
72
if(isset($_POST['extendet_submit'])) {
73
//	$val = (((($page_exented=='1') ? $page_exented : 0)) + 1) % 2;
74
	$val = (defined('PAGE_EXTENDET') ? filter_var(PAGE_EXTENDET, FILTER_VALIDATE_BOOLEAN, FILTER_NULL_ON_FAILURE) : false);
75
	$sql  = (defined('PAGE_EXTENDET') ? 'UPDATE `' : 'INSERT INTO `') . TABLE_PREFIX . 'settings` SET ';
76
	$sql .= '`name`=\'page_extendet\', ';
77
	$sql .= '`value`=\''.($val ? 'false' : 'true').'\' ';
78
	$sql .= (defined('PAGE_EXTENDET') ? 'WHERE `name`=\'page_extendet\'' : '');
79
    if($database->query($sql)) {
80
// redirect to backend
81
echo "<p style=\"text-align:center;\"> If the script</strong> could not be start automatically.\n" .
82
     "Please click <a style=\"font-weight:bold;\" " .
83
     "href=\"".$target_url."\">on this link</a> to start the script!</p>\n";
84
echo "<script type=\"text/javascript\">
85
<!--
86
// Get the location object
87
var locationObj = document.location;
88
// Set the value of the location object
89
document.location = '$target_url';
90
-->
91
</script>";
92

    
93
    } else {
94
    	$admin->print_error($database->get_error(), $target_url );
95
    }
96
}
97

    
98
// Include the WB functions file
99
if(!function_exists('directory_list')) { require(WB_PATH.'/framework/functions.php'); }
100

    
101
// Get values
102
//$page_title = str_replace(array("[[", "]]"), '', htmlspecialchars($admin->get_post_escaped('page_title')));
103
//$menu_title = str_replace(array("[[", "]]"), '', htmlspecialchars($admin->get_post_escaped('menu_title')));
104
//$seo_title = str_replace(array("[[", "]]"), '', htmlspecialchars($admin->get_post_escaped('seo_title')));
105
//$description = str_replace(array("[[", "]]"), '', htmlspecialchars($admin->add_slashes($admin->get_post('description'))));
106
//$keywords = str_replace(array("[[", "]]"), '', htmlspecialchars($admin->add_slashes($admin->get_post('keywords'))));
107

    
108
$page_title = ($admin->StripCodeFromText($admin->get_post('page_title')));
109
$menu_title = ($admin->StripCodeFromText($admin->get_post('menu_title')));
110
$seo_title = ($admin->StripCodeFromText($admin->get_post('seo_title')));
111
$description = ($admin->StripCodeFromText($admin->get_post('description')));
112
$keywords = ($admin->StripCodeFromText($admin->get_post('keywords')));
113

    
114
$page_code = intval($admin->get_post('page_code')) ;
115
$parent = intval($admin->get_post('parent')); // fix secunia 2010-91-3
116
$visibility = $admin->StripCodeFromText($admin->get_post('visibility'));
117
if (!in_array($visibility, array('public', 'private', 'registered', 'hidden', 'none'))) {$visibility = 'public';} // fix secunia 2010-93-3
118
$template = preg_replace('/[^a-z0-9_-]/i', "", $admin->get_post('template')); // fix secunia 2010-93-3
119
$template = (($template == DEFAULT_TEMPLATE ) ? '' : $template);
120
$target = preg_replace("/\W/", "", $admin->get_post('target'));
121
$aAdminGroups   = (isset($_POST['admin_groups']) ? $_POST['admin_groups'] : array('1'));
122
$aAdminUsers    = (isset($_POST['admin_users']) ? $_POST['admin_users'] : array());
123
$aViewingGroups = (isset($_POST['viewing_groups']) ? $_POST['viewing_groups'] : array('1'));
124
$aViewingUsers  = (isset($_POST['viewing_users']) ? $_POST['viewing_users'] : array());
125
$searching = intval($admin->get_post('searching'));
126
$language = strtoupper($admin->get_post('language'));
127
$language = (preg_match('/^[A-Z]{2}$/', $language) ? $language : DEFAULT_LANGUAGE);
128
$menu = intval($admin->get_post('menu')); // fix secunia 2010-91-3
129
$menu = ($menu==0) ? 1 : $menu;
130
$page_code = (isset($_POST['page_code']) ? intval($_POST['page_code']) : 0);
131
$sPageIcon = (isset($_POST['page_icon']) ? $_POST['page_icon'] : 0);
132
$sMenuIcon0 = (isset($_POST['menu_icon_0']) ? $_POST['menu_icon_0'] : 0);
133
$sMenuIcon1 = (isset($_POST['menu_icon_1']) ? $_POST['menu_icon_1'] : 0);
134

    
135
// Validate data
136
if($page_title == '' || substr($page_title,0,1)=='.')
137
{
138
	$admin->print_error($mLang->PAGES_BLANK_PAGE_TITLE,$target_url);
139
}
140
if($menu_title == '' || substr($menu_title,0,1)=='.')
141
{
142
	$admin->print_error($mLang->MESSAGE_PAGES_BLANK_MENU_TITLE,$target_url);
143
}
144
if($seo_title == '' || substr($seo_title,0,1)=='.')
145
{
146
	$seo_title = $menu_title;
147
}
148

    
149
// Get existing perms
150
$sql  = 'SELECT `parent`,`link`,`position`,`admin_groups`,`admin_users`,`menu_title` ';
151
$sql .= 'FROM `'.TABLE_PREFIX.'pages` WHERE `page_id`='.$page_id;
152
$results = $database->query($sql);
153

    
154
$results_array = $results->fetchRow(MYSQL_ASSOC);
155
$old_parent = $results_array['parent'];
156
$old_link = $results_array['link'];
157
$old_position = $results_array['position'];
158

    
159
if($admin->ami_group_member('1')) {
160
	if(!$admin->ami_group_member($results_array['admin_groups']) &&
161
	   !$admin->is_group_match($admin->get_user_id(), $results_array['admin_users']))
162
	{
163
		$admin->print_error($mLang->MESSAGE_PAGES_INSUFFICIENT_PERMISSIONS);
164
	}
165
	// Setup admin groups
166
	$aAdminGroups = (is_array($aAdminGroups) ? $aAdminGroups : array(1));
167
	array_unshift($aAdminGroups, 1);
168
	$sAdminGroups = implode(',', array_unique($aAdminGroups));
169
	$sAdminGroups = (preg_match('/^,|[^0-9,]|,,|,$/', $sAdminGroups) ? '1' : $sAdminGroups);
170

    
171
	$aAdminUsers = (is_array($aAdminUsers) ? $aAdminUsers : array());
172
	$sAdminUsers = implode(',', array_diff($aAdminUsers, array(0)));
173
	$sAdminUsers = (preg_match('/^,|[^0-9,]|,,|,$/', $sAdminUsers) ? array() : $sAdminUsers);
174
}
175

    
176
$aViewingGroups = (is_array($aViewingGroups) ? $aViewingGroups : array(1));
177
array_unshift($aViewingGroups, 1);
178
$sViewingGroups = implode(',', array_unique($aViewingGroups));
179
$sViewingGroups = (preg_match('/^,|[^0-9,]|,,|,$/', $sViewingGroups) ? '1' : $sViewingGroups);
180

    
181
$aViewingUsers = (is_array($aViewingUsers) ? $aViewingUsers : array());
182
$sViewingUsers = implode(',', array_diff($aViewingUsers, array(0)));
183
$sViewingUsers = (preg_match('/^,|[^0-9,]|,,|,$/', $sViewingUsers) ? array() : $sViewingUsers);
184

    
185
$sPageIcon = (($sPageIcon == '0') ? '' : $sPageIcon);
186
if(!is_readable(WB_PATH.$sPageIcon)) { $sPageIcon = ''; }
187
$sMenuIcon0 = (($sMenuIcon0 == '0') ? '' : $sMenuIcon0);
188
if(!is_readable(WB_PATH.$sMenuIcon0)) { $sMenuIcon0 = ''; }
189
$sMenuIcon1 = (($sMenuIcon1 == '0') ? '' : $sMenuIcon1);
190
if(!is_readable(WB_PATH.$sMenuIcon1)) { $sMenuIcon1 = ''; }
191

    
192
// If needed, get new order
193
if($parent != $old_parent)
194
{
195
	// Include ordering class
196
	require(WB_PATH.'/framework/class.order.php');
197
	$order = new order(TABLE_PREFIX.'pages', 'position', 'page_id', 'parent');
198
	// Get new order
199
	$position = $order->get_new($parent);
200
	// Clean new order
201
	$order->clean($parent);
202
} else {
203
	$position = $old_position;
204
}
205

    
206
// Work out level and root parent
207
if ($parent!='0')
208
{
209
	$level = level_count($parent)+1;
210
	$root_parent = root_parent($parent);
211
} else {
212
// Work out level
213
	$level = level_count($page_id);
214
// Work out root parent
215
	$root_parent = root_parent($page_id);
216
}
217
// preparing root_check to protect system directories and important files from being overwritten if PAGES_DIR = '/'
218
	$denied = false;
219
	$forbidden  = array();
220
	$aTempIniList  = array();
221
	$aTempIniList = parse_ini_file(dirname(__FILE__).'/default.ini',true);
222
	$bAccessFileOverwrite = $aTempIniList['PagesEnvironment']['AccessFileOverwrite'];
223
	$aTempIniList['ProtectedNames']['List'][] = (defined('ADMIN_DIRECTORY') ? trim(ADMIN_DIRECTORY,'/') : 'admin');
224
	$aTempIniList['ProtectedNames']['List'][] = (defined('MEDIA_DIRECTORY') ? trim(MEDIA_DIRECTORY,'/') : 'media');
225
	$aTempIniList['ProtectedNames']['List'][] = (defined('PAGES_DIRECTORY') ? trim(PAGES_DIRECTORY,'/') : 'pages');
226
	$forbidden = $aTempIniList['ProtectedNames'];
227

    
228
$link = '/'.page_filename($seo_title);
229
if( ($parent == '0') ) {
230
	if( defined('PAGES_DIRECTORY') && trim(PAGES_DIRECTORY,'/')=='' ) {
231
// Work-out what the link should be
232
		$denied = in_array(trim($link,'/'), $forbidden['List']);
233
		if( $denied )
234
		{
235
//			$link .= '_' .$page_id;
236
			$admin->print_error($mLang->MESSAGE_PAGES_CANNOT_MODIFY_PROTECTED_FILE);
237
		}
238
	}
239
	$filename = WB_PATH.PAGES_DIRECTORY.$link.PAGE_EXTENSION;
240
} else {
241
	$parent_section = '';
242
	$parent_titles = array_reverse(get_parent_titles($parent));
243

    
244
	foreach($parent_titles AS $parent_title) {
245
		$parent_section .= '/'.page_filename($parent_title);
246
	}
247

    
248
	if($parent_section == '/') {
249
		$parent_section = '';
250
	}
251
	$link = $parent_section.$link;
252
	$filename = WB_PATH.PAGES_DIRECTORY.$link.PAGE_EXTENSION;
253
}
254

    
255
// $database = new database();
256
// Check if a page with same page filename exists
257
$sql = 'SELECT COUNT(*) FROM `'.TABLE_PREFIX.'pages` '
258
     . 'WHERE `link` = \''.$link.'\' '
259
     .   'AND `page_id` != '.$page_id;
260
if( ($iSamePages = intval($database->get_one($sql))) > 0 ){
261
	$admin->print_error($mLang->MESSAGE_PAGES_PAGE_EXISTS, $target_url);
262
}
263

    
264
//if($get_same_page = $database->query($sql)){
265
//	if($get_same_page->numRows() > 0)
266
//	{
267
//		$admin->print_error($mLang->MESSAGE_PAGES_PAGE_EXISTS, $target_url);
268
//	}
269
//}
270

    
271
// Update page with new order
272
//$sql = 'UPDATE `'.TABLE_PREFIX.'pages` SET `parent`='.$parent.', `position`='.$position.' WHERE `page_id`='.$page_id.'';
273
//$database->query($sql);
274

    
275
// Get page trail
276
$page_trail = get_page_trail($page_id);
277

    
278
// Update page settings in the pages table
279
$sql = 'UPDATE `'.TABLE_PREFIX.'pages` '
280
	 . 'SET `parent`='.$parent.', '
281
	 .     '`page_title`=\''.$database->escapeString($page_title).'\', '
282
	 .     '`tooltip`=\''.$database->escapeString($page_title).'\', '
283
	 .     '`page_icon` =\''.$database->escapeString($sPageIcon).'\', '
284
	 .     '`menu_title`=\''.$database->escapeString($menu_title).'\', '
285
	 .     '`menu_icon_0` =\''.$database->escapeString($sMenuIcon0).'\', '
286
	 .     '`menu_icon_1` =\''.$database->escapeString($sMenuIcon1).'\', '
287
	 .     '`menu`='.$menu.', '
288
	 .     '`level`='.$level.', '
289
	 .     '`page_trail`=\''.$page_trail.'\', '
290
	 .     '`root_parent`='.$root_parent.', '
291
	 .     '`link`=\''.$database->escapeString($link).'\', '
292
	 .     '`template`=\''.$template.'\', '
293
	 .     '`target`=\''.$target.'\', '
294
	 .     '`description`=\''.$database->escapeString($description).'\', '
295
	 .     '`keywords`=\''.$database->escapeString($keywords).'\', '
296
	 .     '`position`='.$position.', '
297
	 .     '`visibility`=\''.$visibility.'\', '
298
	 .     '`searching`='.$searching.', '
299
	 .     '`language`=\''.$language.'\', ';
300
if($admin->ami_group_member('1')) {
301
	$sql .= ''
302
	     . '`admin_groups`=\''.$sAdminGroups.'\', '
303
	     . '`admin_users`=\''.$sAdminUsers.'\', ';
304
}
305
	$sql .= ''
306
	 . '`viewing_groups`=\''.$sViewingGroups.'\', '
307
	 . '`viewing_users`=\''.$sViewingUsers.'\', '
308
	 . '`page_code`='.$page_code.' '
309
	 . 'WHERE `page_id`='.$page_id;
310

    
311
if(!$database->query($sql)) {
312
	$target_url = ADMIN_URL.'/pages/settings.php?page_id='.$page_id;
313
	$admin->print_error($database->get_error(), $target_url );
314
}
315

    
316
// Clean old order if needed
317
if($parent != $old_parent)
318
{
319
	$order->clean($old_parent);
320
}
321

    
322
// using standard function by core,
323
function fix_page_trail($page_id) {
324
	global $database,$admin,$target_url,$pagetree_url,$mLang;
325

    
326
	$target_url = (isset($_POST['back_submit'])) ? $pagetree_url : $target_url;
327
	
328
// Work out level
329
	$level = level_count($page_id);
330
// Work out root parent
331
	$root_parent = root_parent($page_id);
332
// Work out page trail
333
	$page_trail = get_page_trail($page_id);
334

    
335
// Update page with new level and link
336
	$sql  = 'UPDATE `'.TABLE_PREFIX.'pages` '
337
	      . 'SET `root_parent` = '.$root_parent.', '
338
	      .     '`level` = '.$level.', '
339
	      .     '`page_trail` = \''.$page_trail.'\' '
340
	      .'WHERE `page_id` = '.$page_id;
341

    
342
	if($database->query($sql)) {
343
		$admin->print_success($mLang->MESSAGE_PAGES_SAVED_SETTINGS, $target_url );
344
	} else {
345
		$admin->print_error($database->get_error(), $target_url );
346
	}
347
}
348

    
349
// Fix sub-pages page trail
350
fix_page_trail($page_id);
351

    
352
/**
353
 * 
354
 * BEGIN page "access file" code
355
 * first check for existing pages directory
356
 * if not exists try to create
357
 * otherwise acess denied
358
 * 
359
 */
360

    
361
$bCanCreateAcessFiles = make_dir(WB_PATH.PAGES_DIRECTORY);
362
$bCanCreateAcessFiles = (($bCanCreateAcessFiles==true) ? file_exists(WB_PATH) && is_writable(WB_PATH.PAGES_DIRECTORY) : false );
363

    
364
if( !$bCanCreateAcessFiles )
365
{
366
	$admin->print_error($mLang->MESSAGE_PAGES_CANNOT_CREATE_ACCESS_FILE, $target_url);
367
} else {
368
// Create a new file in the /pages dir if title changed
369
	$old_filename = WB_PATH.PAGES_DIRECTORY.$old_link.PAGE_EXTENSION;
370
	$sub_pages = get_subs($page_id, array());
371
//	$sub_pages = get_subs($sub_pages['0'], array());
372

    
373
// First check if we need or force to create a new file
374
	if( ($old_link != $link) || (!file_exists($filename)) || ( $bAccessFileOverwrite==true ) ) {
375
// Delete old file
376
		$old_filename = WB_PATH.PAGES_DIRECTORY.$old_link.PAGE_EXTENSION;
377
		if(file_exists($old_filename))
378
		{
379
			unlink($old_filename);
380
		}
381
// Create access file
382
		create_access_file($filename,$page_id,$level);
383
		if(!file_exists($filename)) {
384
			$admin->print_error($mLang->MESSAGE_PAGES_CANNOT_CREATE_ACCESS_FILE);
385
		}
386
// Move a directory for this page
387
		if(is_writeable(WB_PATH.PAGES_DIRECTORY.$old_link.'/') && !is_dir(WB_PATH.PAGES_DIRECTORY.$link.'/'))
388
		{
389
			rename(WB_PATH.PAGES_DIRECTORY.$old_link.'/', WB_PATH.PAGES_DIRECTORY.$link.'/');
390
		}
391
// Update any pages that had the old link with the new one
392
		$old_link_len = strlen($old_link);
393
// $query_subs = $database->query("SELECT page_id,link,level FROM ".TABLE_PREFIX."pages WHERE link LIKE '%$old_link/%' ORDER BY LEVEL ASC");
394
		$sql = 'SELECT `page_id`,`link`,`level` FROM `'.TABLE_PREFIX.'pages` '
395
		      .'WHERE `link` LIKE \'%'.$old_link.'/%\' '
396
		      .'ORDER BY `level` ASC ';
397
		if ($oResSubs = $database->query($sql) ) {
398
			if($oResSubs->numRows() > 0)
399
			{
400
				while($sub = $oResSubs->fetchRow(MYSQL_ASSOC))
401
				{
402
					// Double-check to see if it contains old link
403
					if(substr($sub['link'], 0, $old_link_len) == $old_link) {
404
						// Get new link
405
						$replace_this = $old_link;
406
						$old_sub_link_len =strlen($sub['link']);
407
						$new_sub_link = $link.'/'.substr($sub['link'],$old_link_len+1,$old_sub_link_len);
408
						// Work out level
409
						$new_sub_level = level_count($sub['page_id']);
410
						// Update level and link
411
// $database->query("UPDATE ".TABLE_PREFIX."pages SET link = '$new_sub_link', level = '$new_sub_level' WHERE page_id = '".$sub['page_id']."' LIMIT 1");
412
						$sql = 'UPDATE `'.TABLE_PREFIX.'pages` SET '
413
						      .'`link` = \''.$new_sub_link.'\', '
414
						      .'`level` = '.(int)$new_sub_level.' '
415
						      .'WHERE `page_id` = '.$sub['page_id'];
416
						if( $database->query($sql) ) {
417
							// Re-write the access file for this page
418
							$old_subpage_file = WB_PATH.PAGES_DIRECTORY.$new_sub_link.PAGE_EXTENSION;
419
							if(file_exists($old_subpage_file)) {
420
								unlink($old_subpage_file);
421
							}
422
							$sAccessFile = WB_PATH.PAGES_DIRECTORY.$new_sub_link.PAGE_EXTENSION;
423
							create_access_file($sAccessFile, $sub['page_id'], $new_sub_level);
424
							if(!file_exists($sAccessFile)) {
425
								$admin->print_error($mLang->MESSAGE_PAGES_CANNOT_CREATE_ACCESS_FILE);
426
							} else {
427
							}
428
						}
429
					}
430
				}
431
			}
432
		}
433
	}
434
}
435
$dir = (WB_PATH.PAGES_DIRECTORY);
436
//$aDebugMessage = rebuildFolderProtectFile($dir);
437
//print '<pre style="text-align: left;"><strong>function '.__FUNCTION__.'( '.''.' );</strong>  basename: '.basename(__FILE__).'  line: '.__LINE__.' -> <br />';
438
//print_r( $aDebugMessage ); print '</pre>';
439

    
440
$admin->print_footer();
(24-24/25)