Project

General

Profile

1
<?php
2
/**
3
 *
4
 * @category        admin
5
 * @package         pages
6
 * @author          Ryan Djurovich, WebsiteBaker Project
7
 * @copyright       2009-2012, WebsiteBaker Org. e.V.
8
 * @link            http://www.websitebaker2.org/
9
 * @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: settings_save.php 1840 2012-12-23 15:35:25Z Luisehahne $
13
 * @filesource      $HeadURL: svn://isteam.dynxs.de/wb-archiv/branches/2.8.x/wb/admin/pages/settings_save.php $
14
 * @lastmodified    $Date: 2012-12-23 16:35:25 +0100 (Sun, 23 Dec 2012) $
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($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
// Get page id
39
if(!isset($_POST['page_id']) || (isset($_POST['page_id']) && preg_match('/[^0-9a-z]/i',$_POST['page_id'])) )
40
{
41
	header("Location: index.php");
42
	exit(0);
43
} else {
44
//	$page_id = $admin->checkIDKEY('page_id');
45
//	$page_id = (int)$_POST['page_id']; || preg_match('/[^0-9a-f]/i',$_POST['page_id'])
46
	if((!($page_id = $admin->checkIDKEY('page_id')))) {
47
		$admin->print_header();
48
		$admin->print_error($MESSAGE['GENERIC_SECURITY_ACCESS'], $pagetree_url);
49
	}
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

    
66
// After check print the header
67
$admin->print_header();
68

    
69
if(isset($_POST['extended_submit'])) {
70
	$sql = 'SELECT `value` FROM `'.TABLE_PREFIX.'settings` WHERE `name` = \'page_exented\'';
71
	if( ($page_exented = $database->get_one($sql)) != '' ) {
72
		$sql = 'UPDATE ';
73
		$sql_where = 'WHERE `name` = \'page_exented\'';
74
	} else {
75
		$sql = 'INSERT INTO ';
76
		$sql_where = '';
77
	}
78
	$val = (((($page_exented=='1') ? $page_exented : 0)) + 1) % 2;
79

    
80
	$sql .= '`'.TABLE_PREFIX.'settings` ';
81
	$sql .= 'SET `name` = \'page_exented\', ';
82
	$sql .= '`value` = \''.$val.'\' '.$sql_where;
83

    
84
    if($database->query($sql)) {
85
        // redirect to backend
86
echo "<p style=\"text-align:center;\"> If the script</strong> could not be start automatically.\n" .
87
     "Please click <a style=\"font-weight:bold;\" " .
88
     "href=\"".$target_url."\">on this link</a> to start the script!</p>\n";
89
echo "<script type=\"text/javascript\">
90
<!--
91
// Get the location object
92
var locationObj = document.location;
93
// Set the value of the location object
94
document.location = '$target_url';
95
-->
96
</script>";
97

    
98
    } else {
99
    	$admin->print_error($database->get_error(), $target_url );
100
    }
101
}
102

    
103
// Include the WB functions file
104
if(!function_exists('directory_list')) { require(WB_PATH.'/framework/functions.php'); }
105

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

    
133
// Validate data
134
if($page_title == '' || substr($page_title,0,1)=='.')
135
{
136
	$admin->print_error($MESSAGE['PAGES_BLANK_PAGE_TITLE'],$target_url);
137
}
138
if($menu_title == '' || substr($menu_title,0,1)=='.')
139
{
140
	$admin->print_error($MESSAGE['PAGES_BLANK_MENU_TITLE'],$target_url);
141
}
142
if($seo_title == '' || substr($seo_title,0,1)=='.')
143
{
144
    $seo_title = $menu_title;
145
}
146

    
147
// Get existing perms
148
$sql  = 'SELECT `parent`,`link`,`position`,`admin_groups`,`admin_users`,`menu_title` ';
149
$sql .= 'FROM `'.TABLE_PREFIX.'pages` WHERE `page_id`='.$page_id;
150

    
151
$results = $database->query($sql);
152

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

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

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

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

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

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

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

    
205
// Work out level and root parent
206
if ($parent!='0')
207
{
208
	$level = level_count($parent)+1;
209
	$root_parent = root_parent($parent);
210
} else {
211
// Work out level
212
    $level = level_count($page_id);
213
// Work out root parent
214
    $root_parent = root_parent($page_id);
215
}
216

    
217
$link = '/'.page_filename($seo_title);
218

    
219
// Work-out what the link should be
220
if($parent == '0') {
221
    if($link == '/index' || $link == '/intro')
222
    {
223
    	$link .= '_' .$page_id;
224
    	$filename = WB_PATH.PAGES_DIRECTORY.$link .PAGE_EXTENSION;
225

    
226
    } else {
227
        $filename = WB_PATH.PAGES_DIRECTORY.$link.PAGE_EXTENSION;
228
    }
229
} else {
230
	$parent_section = '';
231
	$parent_titles = array_reverse(get_parent_titles($parent));
232

    
233
	foreach($parent_titles AS $parent_title)
234
    {
235
		$parent_section .= '/'.page_filename($parent_title);
236
	}
237

    
238
	if($parent_section == '/')
239
    {
240
      $parent_section = '';
241
    }
242

    
243
	$link = $parent_section.$link;
244
    $filename = WB_PATH.PAGES_DIRECTORY.$link.PAGE_EXTENSION;
245
}
246

    
247
// Check if a page with same page filename exists
248
// $database = new database();
249
$sql = 'SELECT `page_id`,`page_title` FROM `'.TABLE_PREFIX.'pages` WHERE `link` = "'.$link.'" AND `page_id` != '.$page_id;
250

    
251
$get_same_page = $database->query($sql);
252

    
253
if($get_same_page->numRows() > 0)
254
{
255
	$admin->print_error($MESSAGE['PAGES_PAGE_EXISTS'], $target_url);
256
}
257

    
258
// Update page with new order
259
$sql = 'UPDATE `'.TABLE_PREFIX.'pages` SET `parent`='.$parent.', `position`='.$position.' WHERE `page_id`='.$page_id.'';
260
// $database = new database();
261
$database->query($sql);
262

    
263
// Get page trail
264
$page_trail = get_page_trail($page_id);
265

    
266
// Update page settings in the pages table
267
$sql = 'UPDATE `'.TABLE_PREFIX.'pages` '
268
     . 'SET `parent`='.$parent.', '
269
     .     '`page_title`=\''.$page_title.'\', '
270
     .     '`tooltip`=\''.$page_title.'\', '
271
     .     '`page_icon` =\''.mysql_real_escape_string($sPageIcon).'\', '
272
     .     '`menu_title`=\''.$menu_title.'\', '
273
     .     '`menu_icon_0` =\''.mysql_real_escape_string($sMenuIcon0).'\', '
274
     .     '`menu_icon_1` =\''.mysql_real_escape_string($sMenuIcon1).'\', '
275
     .     '`menu`='.$menu.', '
276
     .     '`level`='.$level.', '
277
     .     '`page_trail`=\''.$page_trail.'\', '
278
     .     '`root_parent`='.$root_parent.', '
279
     .     '`link`=\''.$link.'\', '
280
     .     '`template`=\''.$template.'\', '
281
     .     '`target`=\''.$target.'\', '
282
     .     '`description`=\''.$description.'\', '
283
     .     '`keywords`=\''.$keywords.'\', '
284
     .     '`position`='.$position.', '
285
     .     '`visibility`=\''.$visibility.'\', '
286
     .     '`searching`='.$searching.', '
287
     .     '`language`=\''.$language.'\', ';
288
if($admin->ami_group_member('1')) {
289
	$sql .= ''
290
	     . '`admin_groups`=\''.$sAdminGroups.'\', '
291
	     . '`admin_users`=\''.$sAdminUsers.'\', ';
292
}
293
    $sql .= ''
294
         . '`viewing_groups`=\''.$sViewingGroups.'\', '
295
         . '`viewing_users`=\''.$sViewingUsers.'\', '
296
         . '`page_code`='.$page_code.' '
297
         . 'WHERE `page_id`='.$page_id;
298

    
299
if(!$database->query($sql)) {
300
	$target_url = ADMIN_URL.'/pages/settings.php?page_id='.$page_id;
301
	$admin->print_error($database->get_error(), $target_url );
302
}
303

    
304
// Clean old order if needed
305
if($parent != $old_parent)
306
{
307
	$order->clean($old_parent);
308
}
309

    
310
/* BEGIN page "access file" code */
311

    
312
// Create a new file in the /pages dir if title changed
313
if(!is_writable(WB_PATH.PAGES_DIRECTORY.'/'))
314
{
315
	$admin->print_error($MESSAGE['PAGES_CANNOT_CREATE_ACCESS_FILE'], $target_url);
316
} else {
317
    $old_filename = WB_PATH.PAGES_DIRECTORY.$old_link.PAGE_EXTENSION;
318

    
319
	// First check if we need to create a new file
320
	if(($old_link != $link) || (!file_exists($old_filename)))
321
    {
322
		// Delete old file
323
		$old_filename = WB_PATH.PAGES_DIRECTORY.$old_link.PAGE_EXTENSION;
324
		if(file_exists($old_filename))
325
        {
326
			unlink($old_filename);
327
		}
328

    
329
		// Create access file
330
		create_access_file($filename,$page_id,$level);
331
        if(!file_exists($filename)) {
332
        	$admin->print_error($MESSAGE['PAGES_CANNOT_CREATE_ACCESS_FILE']);
333
        }
334
		// Move a directory for this page
335
		if(is_readable(WB_PATH.PAGES_DIRECTORY.$old_link.'/') && is_dir(WB_PATH.PAGES_DIRECTORY.$old_link.'/'))
336
        {
337
			rename(WB_PATH.PAGES_DIRECTORY.$old_link.'/', WB_PATH.PAGES_DIRECTORY.$link.'/');
338
		}
339
		// Update any pages that had the old link with the new one
340
		$old_link_len = strlen($old_link);
341
        $sql = '';
342
		$query_subs = $database->query("SELECT page_id,link,level FROM ".TABLE_PREFIX."pages WHERE link LIKE '%$old_link/%' ORDER BY LEVEL ASC");
343

    
344
		if($query_subs->numRows() > 0)
345
        {
346
			while($sub = $query_subs->fetchRow())
347
            {
348
				// Double-check to see if it contains old link
349
				if(substr($sub['link'], 0, $old_link_len) == $old_link)
350
                {
351
					// Get new link
352
					$replace_this = $old_link;
353
					$old_sub_link_len =strlen($sub['link']);
354
					$new_sub_link = $link.'/'.substr($sub['link'],$old_link_len+1,$old_sub_link_len);
355
					// Work out level
356
					$new_sub_level = level_count($sub['page_id']);
357
					// Update level and link
358
					$database->query("UPDATE ".TABLE_PREFIX."pages SET link = '$new_sub_link', level = '$new_sub_level' WHERE page_id = '".$sub['page_id']."' LIMIT 1");
359
					// Re-write the access file for this page
360
					$old_subpage_file = WB_PATH.PAGES_DIRECTORY.$new_sub_link.PAGE_EXTENSION;
361
					if(file_exists($old_subpage_file))
362
                    {
363
						unlink($old_subpage_file);
364
					}
365
                    $sAccessFile = WB_PATH.PAGES_DIRECTORY.$new_sub_link.PAGE_EXTENSION;
366
					create_access_file($sAccessFile, $sub['page_id'], $new_sub_level);
367
                    if(!file_exists($sAccessFile)) {
368
                    	$admin->print_error($MESSAGE['PAGES_CANNOT_CREATE_ACCESS_FILE']);
369
                    }
370

    
371
				}
372
			}
373
		}
374
	}
375
}
376

    
377
// using standard function by core,
378
function fix_page_trail($page_id) {
379
    global $database,$admin,$target_url,$pagetree_url,$MESSAGE;
380

    
381
    $target_url = (isset($_POST['back_submit'])) ? $pagetree_url : $target_url;
382

    
383
    // Work out level
384
    $level = level_count($page_id);
385
    // Work out root parent
386
    $root_parent = root_parent($page_id);
387
    // Work out page trail
388
    $page_trail = get_page_trail($page_id);
389
    // Update page with new level and link
390
    $sql  = 'UPDATE `'.TABLE_PREFIX.'pages` SET ';
391
    $sql .= '`root_parent` = '.$root_parent.', ';
392
    $sql .= '`level` = '.$level.', ';
393
    $sql .= '`page_trail` = "'.$page_trail.'" ';
394
    $sql .= 'WHERE `page_id` = '.$page_id;
395

    
396
    if($database->query($sql)) {
397
    	$admin->print_success($MESSAGE['PAGES_SAVED_SETTINGS'], $target_url );
398
    } else {
399
    	$admin->print_error($database->get_error(), $target_url );
400
    }
401
}
402

    
403
// Fix sub-pages page trail
404
fix_page_trail($page_id);
405

    
406
$admin->print_footer();
(22-22/23)