Project

General

Profile

1
<?php
2
/**
3
 *
4
 * @category        admin
5
 * @package         pages
6
 * @author          WebsiteBaker Project
7
 * @copyright       2004-2009, Ryan Djurovich
8
 * @copyright       2009-2011, Website Baker Org. e.V.
9
 * @link			http://www.websitebaker2.org/
10
 * @license         http://www.gnu.org/licenses/gpl.html
11
 * @platform        WebsiteBaker 2.8.x
12
 * @requirements    PHP 5.2.2 and higher
13
 * @version         $Id: settings2.php 1407 2011-01-22 17:21:32Z FrankH $
14
 * @filesource		$HeadURL: svn://isteam.dynxs.de/wb-archiv/branches/2.8.x/wb/admin/pages/settings2.php $
15
 * @lastmodified    $Date: 2011-01-22 18:21:32 +0100 (Sat, 22 Jan 2011) $
16
 *
17
 */
18
/* */
19

    
20
// 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
if (!$admin->checkFTAN())
26
{
27
	$admin->print_error($MESSAGE['GENERIC_SECURITY_ACCESS'],'index.php');
28
	exit();
29
}
30

    
31
// Get page id
32
if(!isset($_POST['page_id']) || !is_numeric($_POST['page_id']))
33
{
34
	header("Location: index.php");
35
	exit(0);
36
} else {
37
	$page_id = $_POST['page_id'];
38
}
39

    
40
/*
41
if( (!($page_id = $admin->checkIDKEY('page_id', 0, $_SERVER['REQUEST_METHOD']))) )
42
{
43
	$admin->print_error($MESSAGE['GENERIC_SECURITY_ACCESS']);
44
	exit();
45
}
46
*/
47

    
48
// Include the WB functions file
49
require_once(WB_PATH.'/framework/functions.php');
50

    
51
// Get values
52
$page_title = str_replace(array("[[", "]]"), '', htmlspecialchars($admin->get_post_escaped('page_title')));
53
$menu_title = str_replace(array("[[", "]]"), '', htmlspecialchars($admin->get_post_escaped('menu_title')));
54
$page_code = (int) $admin->get_post_escaped('page_code');
55
$description = str_replace(array("[[", "]]"), '', htmlspecialchars($admin->add_slashes($admin->get_post('description'))));
56
$keywords = str_replace(array("[[", "]]"), '', htmlspecialchars($admin->add_slashes($admin->get_post('keywords'))));
57
$parent = (int) $admin->get_post_escaped('parent'); // fix secunia 2010-91-3
58
$visibility = $admin->get_post_escaped('visibility');
59
if (!in_array($visibility, array('public', 'private', 'registered', 'hidden', 'none'))) {$visibility = 'public';} // fix secunia 2010-93-3
60
$template = preg_replace("/\W/", "", $admin->get_post_escaped('template')); // fix secunia 2010-93-3
61
$target = preg_replace("/\W/", "", $admin->get_post_escaped('target'));
62
$admin_groups = $admin->get_post_escaped('admin_groups');
63
$viewing_groups = $admin->get_post_escaped('viewing_groups');
64
$searching = (int) $admin->get_post_escaped('searching');
65
$language = strtoupper($admin->get_post('language'));
66
$language = (preg_match('/^[A-Z]{2}$/', $language) ? $language : DEFAULT_LANGUAGE);
67
$menu = (int) $admin->get_post_escaped('menu'); // fix secunia 2010-91-3
68

    
69
// Validate data
70
if($page_title == '' || substr($page_title,0,1)=='.')
71
{
72
	$admin->print_error($MESSAGE['PAGES']['BLANK_PAGE_TITLE']);
73
}
74
if($menu_title == '' || substr($menu_title,0,1)=='.')
75
{
76
	$admin->print_error($MESSAGE['PAGES']['BLANK_MENU_TITLE']);
77
}
78

    
79
// Get existing perms
80
// $database = new database();
81

    
82
$sql = 'SELECT `parent`,`link`,`position`,`admin_groups`,`admin_users` FROM `'.TABLE_PREFIX.'pages` WHERE `page_id`='.$page_id;
83
$results = $database->query($sql);
84

    
85
$results_array = $results->fetchRow();
86
$old_parent = $results_array['parent'];
87
$old_link = $results_array['link'];
88
$old_position = $results_array['position'];
89
$old_admin_groups = explode(',', str_replace('_', '', $results_array['admin_groups']));
90
$old_admin_users = explode(',', str_replace('_', '', $results_array['admin_users']));
91

    
92
// Work-out if we should check for existing page_code
93
$sql = 'DESCRIBE `'.TABLE_PREFIX.'pages` `page_code`';
94
$field_sql = $database->query($sql);
95
$field_set = $field_sql->numRows();
96

    
97
$in_old_group = FALSE;
98
foreach($admin->get_groups_id() as $cur_gid)
99
{
100
    if (in_array($cur_gid, $old_admin_groups))
101
    {
102
	$in_old_group = TRUE;
103
    }
104
}
105
if((!$in_old_group) && !is_numeric(array_search($admin->get_user_id(), $old_admin_users)))
106
{
107
	$admin->print_error($MESSAGE['PAGES']['INSUFFICIENT_PERMISSIONS']);
108
}
109

    
110
// Setup admin groups
111
$admin_groups[] = 1;
112
//if(!in_array(1, $admin->get_groups_id())) {
113
//	$admin_groups[] = implode(",",$admin->get_groups_id());
114
//}
115
$admin_groups = preg_replace("/[^\d,]/", "", implode(',', $admin_groups));
116
// Setup viewing groups
117
$viewing_groups[] = 1;
118
//if(!in_array(1, $admin->get_groups_id())) {
119
//	$viewing_groups[] = implode(",",$admin->get_groups_id());
120
//}
121
$viewing_groups = preg_replace("/[^\d,]/", "", implode(',', $viewing_groups));
122

    
123
// If needed, get new order
124
if($parent != $old_parent)
125
{
126
	// Include ordering class
127
	require(WB_PATH.'/framework/class.order.php');
128
	$order = new order(TABLE_PREFIX.'pages', 'position', 'page_id', 'parent');
129
	// Get new order
130
	$position = $order->get_new($parent);
131
	// Clean new order
132
	$order->clean($parent);
133
} else {
134
	$position = $old_position;
135
}
136

    
137
// Work out level and root parent
138
if ($parent!='0')
139
{
140
	$level = level_count($parent)+1;
141
	$root_parent = root_parent($parent);
142
}
143
else {
144
	$level = '0';
145
	$root_parent = '0';
146
}
147

    
148
// Work-out what the link should be
149
if($parent == '0')
150
{
151
	$link = '/'.page_filename($menu_title);
152
	// rename menu titles: index && intro to prevent clashes with intro page feature and WB core file /pages/index.php
153
	if($link == '/index' || $link == '/intro')
154
    {
155
		$link .= '_' .$page_id;
156
		$filename = WB_PATH.PAGES_DIRECTORY.'/'.page_filename($menu_title).'_'.$page_id .PAGE_EXTENSION;
157
	} else {
158
		$filename = WB_PATH.PAGES_DIRECTORY.'/'.page_filename($menu_title).PAGE_EXTENSION;
159
	}
160
} else {
161
	$parent_section = '';
162
	$parent_titles = array_reverse(get_parent_titles($parent));
163
	foreach($parent_titles AS $parent_title)
164
    {
165
		$parent_section .= page_filename($parent_title).'/';
166
	}
167
	if($parent_section == '/')
168
    {
169
      $parent_section = '';
170
    }
171
	$link = '/'.$parent_section.page_filename($menu_title);
172
	$filename = WB_PATH.PAGES_DIRECTORY.'/'.$parent_section.page_filename($menu_title).PAGE_EXTENSION;
173
}
174

    
175
// Check if a page with same page filename exists
176
// $database = new database();
177
$sql = 'SELECT `page_id`,`page_title` FROM `'.TABLE_PREFIX.'pages` WHERE `link` = "'.$link.'" AND `page_id` != '.$page_id;
178
$get_same_page = $database->query($sql);
179

    
180
if($get_same_page->numRows() > 0)
181
{
182
	$admin->print_error($MESSAGE['PAGES']['PAGE_EXISTS']);
183
}
184

    
185
// Update page with new order
186
$sql = 'UPDATE `'.TABLE_PREFIX.'pages` SET `parent`='.$parent.', `position`='.$position.' WHERE `page_id`='.$page_id.'';
187
// $database = new database();
188
$database->query($sql);
189

    
190
// Get page trail
191
$page_trail = get_page_trail($page_id);
192

    
193
// Update page settings in the pages table
194
$sql  = 'UPDATE `'.TABLE_PREFIX.'pages` SET ';
195
$sql .= '`parent` = '.$parent.', ';
196
$sql .= '`page_title` = "'.$page_title.'", ';
197
$sql .= '`menu_title` = "'.$menu_title.'", ';
198
$sql .= '`menu` = '.$menu.', ';
199
$sql .= '`level` = '.$level.', ';
200
$sql .= '`page_trail` = "'.$page_trail.'", ';
201
$sql .= '`root_parent` = '.$root_parent.', ';
202
$sql .= '`link` = "'.$link.'", ';
203
$sql .= '`template` = "'.$template.'", ';
204
$sql .= '`target` = "'.$target.'", ';
205
$sql .= '`description` = "'.$description.'", ';
206
$sql .= '`keywords` = "'.$keywords.'", ';
207
$sql .= '`position` = '.$position.', ';
208
$sql .= '`visibility` = "'.$visibility.'", ';
209
$sql .= '`searching` = '.$searching.', ';
210
$sql .= '`language` = "'.$language.'", ';
211
$sql .= '`admin_groups` = "'.$admin_groups.'", ';
212
$sql .= '`viewing_groups` = "'.$viewing_groups.'"';
213
$sql .= (defined('PAGE_LANGUAGES') && PAGE_LANGUAGES) && $field_set && (file_exists(WB_PATH.'/modules/mod_multilingual/update_keys.php')) ? ', `page_code` = '.(int)$page_code.' ' : ' ';
214
$sql .= 'WHERE `page_id` = '.$page_id;
215
$database->query($sql);
216

    
217
$target_url = ADMIN_URL.'/pages/settings.php?page_id='.$page_id;
218
if($database->is_error())
219
{
220
	$admin->print_error($database->get_error(), $target_url );
221
}
222
// Clean old order if needed
223
if($parent != $old_parent)
224
{
225
	$order->clean($old_parent);
226
}
227

    
228
/* BEGIN page "access file" code */
229

    
230
// Create a new file in the /pages dir if title changed
231
if(!is_writable(WB_PATH.PAGES_DIRECTORY.'/'))
232
{
233
	$admin->print_error($MESSAGE['PAGES']['CANNOT_CREATE_ACCESS_FILE']);
234
} else {
235
    $old_filename = WB_PATH.PAGES_DIRECTORY.$old_link.PAGE_EXTENSION;
236
	// First check if we need to create a new file
237
	if(($old_link != $link) || (!file_exists($old_filename)))
238
    {
239
		// Delete old file
240
		$old_filename = WB_PATH.PAGES_DIRECTORY.$old_link.PAGE_EXTENSION;
241
		if(file_exists($old_filename))
242
        {
243
			unlink($old_filename);
244
		}
245
		// Create access file
246
		create_access_file($filename,$page_id,$level);
247
		// Move a directory for this page
248
		if(file_exists(WB_PATH.PAGES_DIRECTORY.$old_link.'/') && is_dir(WB_PATH.PAGES_DIRECTORY.$old_link.'/'))
249
        {
250
			rename(WB_PATH.PAGES_DIRECTORY.$old_link.'/', WB_PATH.PAGES_DIRECTORY.$link.'/');
251
		}
252
		// Update any pages that had the old link with the new one
253
		$old_link_len = strlen($old_link);
254
        $sql = '';
255
		$query_subs = $database->query("SELECT page_id,link,level FROM ".TABLE_PREFIX."pages WHERE link LIKE '%$old_link/%' ORDER BY LEVEL ASC");
256

    
257
		if($query_subs->numRows() > 0)
258
        {
259
			while($sub = $query_subs->fetchRow())
260
            {
261
				// Double-check to see if it contains old link
262
				if(substr($sub['link'], 0, $old_link_len) == $old_link)
263
                {
264
					// Get new link
265
					$replace_this = $old_link;
266
					$old_sub_link_len =strlen($sub['link']);
267
					$new_sub_link = $link.'/'.substr($sub['link'],$old_link_len+1,$old_sub_link_len);
268
					// Work out level
269
					$new_sub_level = level_count($sub['page_id']);
270
					// Update level and link
271
					$database->query("UPDATE ".TABLE_PREFIX."pages SET link = '$new_sub_link', level = '$new_sub_level' WHERE page_id = '".$sub['page_id']."' LIMIT 1");
272
					// Re-write the access file for this page
273
					$old_subpage_file = WB_PATH.PAGES_DIRECTORY.$new_sub_link.PAGE_EXTENSION;
274
					if(file_exists($old_subpage_file))
275
                    {
276
						unlink($old_subpage_file);
277
					}
278
					create_access_file(WB_PATH.PAGES_DIRECTORY.$new_sub_link.PAGE_EXTENSION, $sub['page_id'], $new_sub_level);
279
				}
280
			}
281
		}
282
	}
283
}
284

    
285
// Function to fix page trail of subs
286
function fix_page_trail($parent,$root_parent)
287
{
288
	// Get objects and vars from outside this function
289
	global $admin, $template, $database, $TEXT, $MESSAGE;
290
	// Get page list from database
291
	// $database = new database();
292
	$query = "SELECT page_id FROM ".TABLE_PREFIX."pages WHERE parent = '$parent'";
293
	$get_pages = $database->query($query);
294
	// Insert values into main page list
295
	if($get_pages->numRows() > 0)
296
    {
297
		while($page = $get_pages->fetchRow())
298
        {
299
			// Fix page trail
300

    
301
			$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']."'");
302
			// Run this query on subs
303
			fix_page_trail($page['page_id'],$root_parent);
304
		}
305
	}
306
}
307

    
308
// Fix sub-pages page trail
309
fix_page_trail($page_id,$root_parent);
310

    
311
/* END page "access file" code */
312

    
313
$pagetree_url = ADMIN_URL.'/pages/index.php';
314
$target_url = ADMIN_URL.'/pages/settings.php?page_id='.$page_id;
315
// Check if there is a db error, otherwise say successful
316
if($database->is_error())
317
{
318
	$admin->print_error($database->get_error(), $target_url );
319
} else {
320
	$admin->print_success($MESSAGE['PAGES']['SAVED_SETTINGS'], $target_url );
321
}
322

    
323
// Print admin footer
324
$admin->print_footer();
325

    
326
?>
(20-20/21)