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 2081 2014-01-07 17:12:50Z darkviper $
13
 * @filesource      $HeadURL: svn://isteam.dynxs.de/wb-archiv/branches/2.8.x/wb/admin/pages/settings_save.php $
14
 * @lastmodified    $Date: 2014-01-07 18:12:50 +0100 (Tue, 07 Jan 2014) $
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($oLang->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
$oDb   = WbDatabase::getInstance();
38
$oReg  = WbAdaptor::getInstance();
39
$oLang = Translate::getInstance();
40
$oLang->enableAddon('admin\pages');
41

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

    
55
if (!$admin->checkFTAN())
56
{
57
	$admin->print_header();
58
	$admin->print_error($oLang->MESSAGE_GENERIC_SECURITY_ACCESS,$target_url);
59
}
60

    
61
// After check print the header
62
$admin->print_header();
63

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

    
85
    } else {
86
    	$admin->print_error($oDb->get_error(), $target_url );
87
    }
88
}
89

    
90
// Include the WB functions file
91
if(!function_exists('directory_list')) { require(WB_PATH.'/framework/functions.php'); }
92

    
93
// Get values
94
//$page_title = str_replace(array("[[", "]]"), '', htmlspecialchars($admin->get_post_escaped('page_title')));
95
//$menu_title = str_replace(array("[[", "]]"), '', htmlspecialchars($admin->get_post_escaped('menu_title')));
96
//$seo_title = str_replace(array("[[", "]]"), '', htmlspecialchars($admin->get_post_escaped('seo_title')));
97
//$description = str_replace(array("[[", "]]"), '', htmlspecialchars($admin->add_slashes($admin->get_post('description'))));
98
//$keywords = str_replace(array("[[", "]]"), '', htmlspecialchars($admin->add_slashes($admin->get_post('keywords'))));
99

    
100
$page_title = ($admin->StripCodeFromText($admin->get_post('page_title')));
101
$menu_title = ($admin->StripCodeFromText($admin->get_post('menu_title')));
102
$seo_title = ($admin->StripCodeFromText($admin->get_post('seo_title')));
103
$description = ($admin->StripCodeFromText($admin->get_post('description')));
104
$keywords = ($admin->StripCodeFromText($admin->get_post('keywords')));
105

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

    
127
// Validate data
128
if($page_title == '' || substr($page_title,0,1)=='.')
129
{
130
	$admin->print_error($oLang->PAGES_BLANK_PAGE_TITLE,$target_url);
131
}
132
if($menu_title == '' || substr($menu_title,0,1)=='.')
133
{
134
	$admin->print_error($oLang->MESSAGE_PAGES_BLANK_MENU_TITLE,$target_url);
135
}
136
if($seo_title == '' || substr($seo_title,0,1)=='.')
137
{
138
	$seo_title = $menu_title;
139
}
140

    
141
// Get existing perms
142
$sql = 'SELECT `parent`,`link`,`position`,`admin_groups`,`admin_users`,`menu_title` '
143
     . 'FROM `'.$oDb->TablePrefix.'pages` '
144
     . 'WHERE `page_id`='.$page_id;
145
$results = $oDb->doQuery($sql);
146

    
147
$results_array = $results->fetchRow(MYSQL_ASSOC);
148
$old_parent = $results_array['parent'];
149
$old_link = $results_array['link'];
150
$old_position = $results_array['position'];
151

    
152
if($admin->ami_group_member('1')) {
153
	if(!$admin->ami_group_member($results_array['admin_groups']) &&
154
	   !$admin->is_group_match($admin->get_user_id(), $results_array['admin_users']))
155
	{
156
		$admin->print_error($oLang->MESSAGE_PAGES_INSUFFICIENT_PERMISSIONS);
157
	}
158
	// Setup admin groups
159
	$aAdminGroups = (is_array($aAdminGroups) ? $aAdminGroups : array(1));
160
	array_unshift($aAdminGroups, 1);
161
	$sAdminGroups = implode(',', array_unique($aAdminGroups));
162
	$sAdminGroups = (preg_match('/^,|[^0-9,]|,,|,$/', $sAdminGroups) ? '1' : $sAdminGroups);
163

    
164
	$aAdminUsers = (is_array($aAdminUsers) ? $aAdminUsers : array());
165
	$sAdminUsers = implode(',', array_diff($aAdminUsers, array(0)));
166
	$sAdminUsers = (preg_match('/^,|[^0-9,]|,,|,$/', $sAdminUsers) ? array() : $sAdminUsers);
167
}
168

    
169
$aViewingGroups = (is_array($aViewingGroups) ? $aViewingGroups : array(1));
170
array_unshift($aViewingGroups, 1);
171
$sViewingGroups = implode(',', array_unique($aViewingGroups));
172
$sViewingGroups = (preg_match('/^,|[^0-9,]|,,|,$/', $sViewingGroups) ? '1' : $sViewingGroups);
173

    
174
$aViewingUsers = (is_array($aViewingUsers) ? $aViewingUsers : array());
175
$sViewingUsers = implode(',', array_diff($aViewingUsers, array(0)));
176
$sViewingUsers = (preg_match('/^,|[^0-9,]|,,|,$/', $sViewingUsers) ? array() : $sViewingUsers);
177

    
178
$sPageIcon = (($sPageIcon == '0') ? '' : $sPageIcon);
179
if(!is_readable(WB_PATH.$sPageIcon)) { $sPageIcon = ''; }
180
$sMenuIcon0 = (($sMenuIcon0 == '0') ? '' : $sMenuIcon0);
181
if(!is_readable(WB_PATH.$sMenuIcon0)) { $sMenuIcon0 = ''; }
182
$sMenuIcon1 = (($sMenuIcon1 == '0') ? '' : $sMenuIcon1);
183
if(!is_readable(WB_PATH.$sMenuIcon1)) { $sMenuIcon1 = ''; }
184

    
185
// If needed, get new order
186
if($parent != $old_parent)
187
{
188
	// Include ordering class
189
//	require(WB_PATH.'/framework/class.order.php');
190
	$order = new order(TABLE_PREFIX.'pages', 'position', 'page_id', 'parent');
191
	// Get new order
192
	$position = $order->get_new($parent);
193
	// Clean new order
194
	$order->clean($parent);
195
} else {
196
	$position = $old_position;
197
}
198

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

    
221
$link = '/'.page_filename($seo_title);
222
if( ($parent == '0') ) {
223
	if( defined('PAGES_DIRECTORY') && trim(PAGES_DIRECTORY,'/')=='' ) {
224
// Work-out what the link should be
225
		$denied = in_array(trim($link,'/'), $forbidden['List']);
226
		if( $denied )
227
		{
228
//			$link .= '_' .$page_id;
229
			$admin->print_error($oLang->MESSAGE_PAGES_CANNOT_MODIFY_PROTECTED_FILE);
230
		}
231
	}
232
	$filename = WB_PATH.PAGES_DIRECTORY.$link.PAGE_EXTENSION;
233
} else {
234
	$parent_section = '';
235
	$parent_titles = array_reverse(get_parent_titles($parent));
236

    
237
	foreach($parent_titles AS $parent_title) {
238
		$parent_section .= '/'.page_filename($parent_title);
239
	}
240

    
241
	if($parent_section == '/') {
242
		$parent_section = '';
243
	}
244
	$link = $parent_section.$link;
245
	$filename = WB_PATH.PAGES_DIRECTORY.$link.PAGE_EXTENSION;
246
}
247

    
248
// $database = new database();
249
// Check if a page with same page filename exists
250
$sql = 'SELECT COUNT(*) FROM `'.$oDb->TablePrefix.'pages` '
251
     . 'WHERE `link` = \''.$link.'\' '
252
     .   'AND `page_id` != '.$page_id;
253
if( ($iSamePages = intval($oDb->getOne($sql))) > 0 ){
254
	$admin->print_error($oLang->MESSAGE_PAGES_PAGE_EXISTS, $target_url);
255
}
256
// Get page trail
257
$page_trail = get_page_trail($page_id);
258
// Update page settings in the pages table
259
$sql = 'UPDATE `'.$oDb->TablePrefix.'pages` '
260
	 . 'SET `parent`='.$parent.', '
261
	 .     '`page_title`=\''.$oDb->escapeString($page_title).'\', '
262
	 .     '`tooltip`=\''.$oDb->escapeString($page_title).'\', '
263
	 .     '`page_icon` =\''.$oDb->escapeString($sPageIcon).'\', '
264
	 .     '`menu_title`=\''.$oDb->escapeString($menu_title).'\', '
265
	 .     '`menu_icon_0` =\''.$oDb->escapeString($sMenuIcon0).'\', '
266
	 .     '`menu_icon_1` =\''.$oDb->escapeString($sMenuIcon1).'\', '
267
	 .     '`menu`='.$menu.', '
268
	 .     '`level`='.$level.', '
269
	 .     '`page_trail`=\''.$page_trail.'\', '
270
	 .     '`root_parent`='.$root_parent.', '
271
	 .     '`link`=\''.$oDb->escapeString($link).'\', '
272
	 .     '`template`=\''.$template.'\', '
273
	 .     '`target`=\''.$target.'\', '
274
	 .     '`description`=\''.$oDb->escapeString($description).'\', '
275
	 .     '`keywords`=\''.$oDb->escapeString($keywords).'\', '
276
	 .     '`position`='.$position.', '
277
	 .     '`visibility`=\''.$visibility.'\', '
278
	 .     '`searching`='.$searching.', '
279
	 .     '`language`=\''.$language.'\', ';
280
if($admin->ami_group_member('1')) {
281
	$sql .= ''
282
	     . '`admin_groups`=\''.$sAdminGroups.'\', '
283
	     . '`admin_users`=\''.$sAdminUsers.'\', ';
284
}
285
	$sql .= ''
286
	 . '`viewing_groups`=\''.$sViewingGroups.'\', '
287
	 . '`viewing_users`=\''.$sViewingUsers.'\', '
288
	 . '`page_code`='.$page_code.' '
289
	 . 'WHERE `page_id`='.$page_id;
290

    
291
if(!$oDb->doQuery($sql)) {
292
	$target_url = ADMIN_URL.'/pages/settings.php?page_id='.$page_id;
293
	$admin->print_error($oDb->get_error(), $target_url );
294
}
295

    
296
// Clean old order if needed
297
if($parent != $old_parent)
298
{
299
	$order->clean($old_parent);
300
}
301

    
302
// using standard function by core,
303
function fix_page_trail($page_id) {
304
	global $admin, $target_url, $pagetree_url;
305
    $oLang = Translate::getInstance();
306
    $oDb   = WbDatabase::getInstance();
307
	$target_url = (isset($_POST['back_submit'])) ? $pagetree_url : $target_url;
308
	
309
// Work out level
310
	$level = level_count($page_id);
311
// Work out root parent
312
	$root_parent = root_parent($page_id);
313
// Work out page trail
314
	$page_trail = get_page_trail($page_id);
315

    
316
// Update page with new level and link
317
	$sql  = 'UPDATE `'.$oDb->TablePrefix.'pages` '
318
	      . 'SET `root_parent` = '.$root_parent.', '
319
	      .     '`level` = '.$level.', '
320
	      .     '`page_trail` = \''.$page_trail.'\' '
321
	      .'WHERE `page_id` = '.$page_id;
322

    
323
	if($oDb->doQuery($sql)) {
324
		$admin->print_success($oLang->MESSAGE_PAGES_SAVED_SETTINGS, $target_url );
325
	} else {
326
		$admin->print_error($oDb->get_error(), $target_url );
327
	}
328
}
329

    
330
// Fix sub-pages page trail
331
fix_page_trail($page_id);
332

    
333
/**
334
 * 
335
 * BEGIN page "access file" code
336
 * first check for existing pages directory
337
 * if not exists try to create
338
 * otherwise acess denied
339
 * 
340
 */
341

    
342
$bCanCreateAcessFiles = make_dir(WB_PATH.PAGES_DIRECTORY);
343
$bCanCreateAcessFiles = (($bCanCreateAcessFiles==true) ? file_exists(WB_PATH) && is_writable(WB_PATH.PAGES_DIRECTORY) : false );
344

    
345
if( !$bCanCreateAcessFiles )
346
{
347
	$admin->print_error($oLang->MESSAGE_PAGES_CANNOT_CREATE_ACCESS_FILE, $target_url);
348
} else {
349
// Create a new file in the /pages dir if title changed
350
	$old_filename = WB_PATH.PAGES_DIRECTORY.$old_link.PAGE_EXTENSION;
351
	$sub_pages = get_subs($page_id, array());
352
//	$sub_pages = get_subs($sub_pages['0'], array());
353

    
354
// First check if we need or force to create a new file
355
	if( ($old_link != $link) || (!file_exists($filename)) || ( $bAccessFileOverwrite==true ) ) {
356
// Delete old file
357
		$old_filename = WB_PATH.PAGES_DIRECTORY.$old_link.PAGE_EXTENSION;
358
		if(file_exists($old_filename))
359
		{
360
			unlink($old_filename);
361
		}
362
// Create access file
363
        $sNewLink = str_replace($oReg->AppPath.$oReg->PagesDir, '', str_replace('\\', '/', $filename));
364
        try{
365
            $oAccFile = new AccessFile($oReg->AppPath.$oReg->PagesDir, $sNewLink, $page_id);
366
            $oAccFile->write();
367
            unset($oAccFile);
368
        } catch (AccessFileException $e) {
369
            $sMsg = $oLang->MESSAGE_PAGES_CANNOT_CREATE_ACCESS_FILE
370
                  . '<br />'.$e->getMessage();
371
            $admin->print_error($sMsg);
372
        }
373
//		create_access_file($filename,$page_id,$level);
374
//		if(!file_exists($filename)) {
375
//			$admin->print_error($oLang->MESSAGE_PAGES_CANNOT_CREATE_ACCESS_FILE.'');
376
//		}
377
// Move a directory for this page
378
		if(is_writeable(WB_PATH.PAGES_DIRECTORY.$old_link.'/') && !is_dir(WB_PATH.PAGES_DIRECTORY.$link.'/'))
379
		{
380
			rename(WB_PATH.PAGES_DIRECTORY.$old_link.'/', WB_PATH.PAGES_DIRECTORY.$link.'/');
381
		}
382
// Update any pages that had the old link with the new one
383
		$old_link_len = strlen($old_link);
384
// $query_subs = $database->query("SELECT page_id,link,level FROM ".TABLE_PREFIX."pages WHERE link LIKE '%$old_link/%' ORDER BY LEVEL ASC");
385
		$sql = 'SELECT `page_id`,`link`,`level` FROM `'.TABLE_PREFIX.'pages` '
386
		      .'WHERE `link` LIKE \'%'.$old_link.'/%\' '
387
		      .'ORDER BY `level` ASC ';
388
		if ($oResSubs = $database->query($sql) ) {
389
			if($oResSubs->numRows() > 0)
390
			{
391
				while($sub = $oResSubs->fetchRow(MYSQL_ASSOC))
392
				{
393
					// Double-check to see if it contains old link
394
					if(substr($sub['link'], 0, $old_link_len) == $old_link) {
395
						// Get new link
396
						$replace_this = $old_link;
397
						$old_sub_link_len =strlen($sub['link']);
398
						$new_sub_link = $link.'/'.substr($sub['link'],$old_link_len+1,$old_sub_link_len);
399
						// Work out level
400
						$new_sub_level = level_count($sub['page_id']);
401
						// Update level and link
402
// $database->query("UPDATE ".TABLE_PREFIX."pages SET link = '$new_sub_link', level = '$new_sub_level' WHERE page_id = '".$sub['page_id']."' LIMIT 1");
403
						$sql = 'UPDATE `'.TABLE_PREFIX.'pages` SET '
404
						      .'`link` = \''.$new_sub_link.'\', '
405
						      .'`level` = '.(int)$new_sub_level.' '
406
						      .'WHERE `page_id` = '.$sub['page_id'];
407
						if( $database->query($sql) ) {
408
							// Re-write the access file for this page
409
							$old_subpage_file = WB_PATH.PAGES_DIRECTORY.$new_sub_link.PAGE_EXTENSION;
410
							if(file_exists($old_subpage_file)) {
411
								unlink($old_subpage_file);
412
							}
413
							$sAccessFile = WB_PATH.PAGES_DIRECTORY.$new_sub_link.PAGE_EXTENSION;
414
                            $sNewLink = str_replace($oReg->AppPath.$oReg->PagesDir, '', str_replace('\\', '/', $sAccessFile));
415
                            try {
416
                                $oAccFile = new AccessFile(WB_PATH.PAGES_DIRECTORY.'/', $sNewLink, $sub['page_id']);
417
                                $oAccFile->write();
418
                                unset($oAccFile);
419
                            } catch (AccessFileException $e) {
420
                                $sMsg = $oLang->MESSAGE_PAGES_CANNOT_CREATE_ACCESS_FILE
421
                                      . '<br />'.$e->getMessage();
422
                                $admin->print_error($sMsg);
423
                            }
424
//							create_access_file($sAccessFile, $sub['page_id'], $new_sub_level);
425
//							if(!file_exists($sAccessFile)) {
426
//								$admin->print_error($oLang->MESSAGE_PAGES_CANNOT_CREATE_ACCESS_FILE);
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)