Project

General

Profile

1 1358 Luisehahne
<?php
2
/**
3
 *
4
 * @category        admin
5
 * @package         pages
6 1707 Luisehahne
 * @author          Ryan Djurovich, WebsiteBaker Project
7 1914 Luisehahne
 * @copyright       2009-2013, WebsiteBaker Org. e.V.
8
 * @link            http://www.websitebaker.org/
9 1358 Luisehahne
 * @license         http://www.gnu.org/licenses/gpl.html
10
 * @platform        WebsiteBaker 2.8.x
11 1373 Luisehahne
 * @requirements    PHP 5.2.2 and higher
12 1358 Luisehahne
 * @version         $Id$
13 1914 Luisehahne
 * @filesource      $HeadURL$
14 1358 Luisehahne
 * @lastmodified    $Date$
15
 *
16
 */
17
18 1868 Luisehahne
if(!defined('WB_URL'))
19
{
20
    $config_file = realpath('../../config.php');
21
    if(file_exists($config_file) && !defined('WB_URL'))
22
    {
23
    	require($config_file);
24
    }
25
}
26 1914 Luisehahne
// Create new admin object and print admin header
27 1868 Luisehahne
if(!class_exists('admin', false)){ include(WB_PATH.'/framework/class.admin.php'); }
28 1914 Luisehahne
$mLang = Translate::getinstance();
29
$mLang->enableAddon('admin\pages');
30
31 1457 Luisehahne
// suppress to print the header, so no new FTAN will be set
32
$admin = new admin('Pages', 'pages_add', false);
33 1358 Luisehahne
if (!$admin->checkFTAN())
34
{
35 1457 Luisehahne
	$admin->print_header();
36 1914 Luisehahne
	$admin->print_error($mLang->MESSAGE_GENERIC_SECURITY_ACCESS);
37 1358 Luisehahne
}
38
39
// Include the WB functions file
40
require_once(WB_PATH.'/framework/functions.php');
41
42
// Get values
43 1914 Luisehahne
//$title = str_replace(array("[[", "]]"), '', htmlspecialchars($admin->get_post_escaped('title')));
44
$title = ($admin->StripCodeFromText($admin->get_post('title')));
45 1494 Luisehahne
$module = preg_replace('/[^a-z0-9_-]/i', "", $admin->get_post('type')); // fix secunia 2010-93-4
46 1475 Luisehahne
$parent = intval($admin->get_post('parent')); // fix secunia 2010-91-2
47 1358 Luisehahne
$visibility = $admin->get_post('visibility');
48 1384 Luisehahne
if (!in_array($visibility, array('public', 'private', 'registered', 'hidden', 'none'))) {$visibility = 'public';} // fix secunia 2010-91-2
49 1358 Luisehahne
$admin_groups = $admin->get_post('admin_groups');
50
$viewing_groups = $admin->get_post('viewing_groups');
51
52
// Work-out if we should check for existing page_code
53 1457 Luisehahne
$field_set = $database->field_exists(TABLE_PREFIX.'pages', 'page_code');
54 1358 Luisehahne
55
// add Admin to admin and viewing-groups
56
$admin_groups[] = 1;
57
$viewing_groups[] = 1;
58
59 1473 Luisehahne
// After check print the header
60
$admin->print_header();
61 1406 FrankH
// check parent page permissions:
62 1358 Luisehahne
if ($parent!=0) {
63
	if (!$admin->get_page_permission($parent,'admin'))
64
    {
65 1914 Luisehahne
        $admin->print_error($mLang->MESSAGE_PAGES_INSUFFICIENT_PERMISSIONS);
66 1358 Luisehahne
    }
67
68
} elseif (!$admin->get_permission('pages_add_l0','system'))
69
{
70 1914 Luisehahne
	$admin->print_error($mLang->MESSAGE_PAGES_INSUFFICIENT_PERMISSIONS);
71 1707 Luisehahne
}
72 1358 Luisehahne
73 1406 FrankH
// check module permissions:
74
if (!$admin->get_permission($module, 'module'))
75
{
76 1914 Luisehahne
	$admin->print_error($mLang->MESSAGE_PAGES_INSUFFICIENT_PERMISSIONS);
77 1707 Luisehahne
}
78 1406 FrankH
79 1358 Luisehahne
// Validate data
80
if($title == '' || substr($title,0,1)=='.')
81
{
82 1914 Luisehahne
	$admin->print_error($title.'::'.$mLang->MESSAGE_PAGES_BLANK_PAGE_TITLE);
83 1358 Luisehahne
}
84
85
// Check to see if page created has needed permissions
86
if(!in_array(1, $admin->get_groups_id()))
87
{
88
	$admin_perm_ok = false;
89
	foreach ($admin_groups as $adm_group)
90
    {
91
		if (in_array($adm_group, $admin->get_groups_id()))
92
        {
93
			$admin_perm_ok = true;
94 1707 Luisehahne
		}
95 1358 Luisehahne
	}
96
	if ($admin_perm_ok == false)
97
    {
98 1914 Luisehahne
		$admin->print_error($mLang->MESSAGE_PAGES_INSUFFICIENT_PERMISSIONS);
99 1358 Luisehahne
	}
100
	$admin_perm_ok = false;
101
	foreach ($viewing_groups as $view_group)
102
    {
103
		if (in_array($view_group, $admin->get_groups_id()))
104
        {
105
			$admin_perm_ok = true;
106
		}
107
	}
108
	if ($admin_perm_ok == false)
109
    {
110 1914 Luisehahne
		$admin->print_error($mLang->MESSAGE_PAGES_INSUFFICIENT_PERMISSIONS);
111 1358 Luisehahne
	}
112
}
113
114
$admin_groups = implode(',', $admin_groups);
115
$viewing_groups = implode(',', $viewing_groups);
116
117 1914 Luisehahne
// preparing root_check to protect system directories and important files from being overwritten if PAGES_DIR = '/'
118
$denied = false;
119
$forbidden  = array();
120
$aTempIniList  = array();
121
$aTempIniList = parse_ini_file(dirname(__FILE__).'/default.ini',true);
122
$bAccessFileOverwrite = $aTempIniList['PagesEnvironment']['AccessFileOverwrite'];
123
$aTempIniList['ProtectedNames']['List'][] = (defined('ADMIN_DIRECTORY') ? trim(ADMIN_DIRECTORY,'/') : 'admin');
124
$aTempIniList['ProtectedNames']['List'][] = (defined('MEDIA_DIRECTORY') ? trim(MEDIA_DIRECTORY,'/') : 'media');
125
$aTempIniList['ProtectedNames']['List'][] = (defined('PAGES_DIRECTORY') ? trim(PAGES_DIRECTORY,'/') : 'pages');
126
$forbidden = $aTempIniList['ProtectedNames'];
127
128
$link = '/'.page_filename($title);
129 1358 Luisehahne
// Work-out what the link and page filename should be
130
if($parent == '0')
131
{
132
	// rename menu titles: index && intro to prevent clashes with intro page feature and WB core file /pages/index.php
133 1914 Luisehahne
	if( defined('PAGES_DIRECTORY') && trim(PAGES_DIRECTORY,'/')=='' ) {
134
// Work-out what the link should be
135
		$denied = in_array(trim($link,'/'), $forbidden['List']);
136
		if( $denied )
137
		{
138
//			$link .= '_'.$iNextPageId;
139
			$admin->print_error($mLang->MESSAGE_PAGES_CANNOT_CREATE_PROTECTED_FILE);
140
		}
141 1358 Luisehahne
	}
142 1914 Luisehahne
	$filename = WB_PATH.PAGES_DIRECTORY.$link.PAGE_EXTENSION;
143 1760 Luisehahne
144 1358 Luisehahne
} else {
145
	$parent_section = '';
146
	$parent_titles = array_reverse(get_parent_titles($parent));
147
	foreach($parent_titles AS $parent_title)
148
    {
149
		$parent_section .= page_filename($parent_title).'/';
150
	}
151
	if($parent_section == '/') { $parent_section = ''; }
152
	$link = '/'.$parent_section.page_filename($title);
153
	$filename = WB_PATH.PAGES_DIRECTORY.'/'.$parent_section.page_filename($title).PAGE_EXTENSION;
154
	make_dir(WB_PATH.PAGES_DIRECTORY.'/'.$parent_section);
155
}
156
157
// Check if a page with same page filename exists
158 1914 Luisehahne
//$get_same_page = $database->query("SELECT page_id FROM ".TABLE_PREFIX."pages WHERE link = '$link'");
159
//if($get_same_page->numRows() > 0 OR file_exists(WB_PATH.PAGES_DIRECTORY.$link.PAGE_EXTENSION) OR file_exists(WB_PATH.PAGES_DIRECTORY.$link.'/'))
160
//{
161
//	$admin->print_error($MESSAGE['PAGES_PAGE_EXISTS']);
162
//}
163
$bLinkExists = file_exists(WB_PATH.PAGES_DIRECTORY.$link.PAGE_EXTENSION) || file_exists(WB_PATH.PAGES_DIRECTORY.$link);
164
165
// UNLOCK TABLES
166
$sql = 'SELECT COUNT(*) FROM `'.TABLE_PREFIX.'pages` '
167
     . 'WHERE `link` = \''.$link.'\' ';
168
if( (($iSamePages = intval($database->get_one($sql))) > 0) || $bLinkExists ){
169 1707 Luisehahne
	$admin->print_error($MESSAGE['PAGES_PAGE_EXISTS']);
170 1358 Luisehahne
}
171
172
// Include the ordering class
173
require(WB_PATH.'/framework/class.order.php');
174
$order = new order(TABLE_PREFIX.'pages', 'position', 'page_id', 'parent');
175
// First clean order
176
$order->clean($parent);
177
// Get new order
178
$position = $order->get_new($parent);
179
180
// Work-out if the page parent (if selected) has a seperate template or language to the default
181
$query_parent = $database->query("SELECT template, language FROM ".TABLE_PREFIX."pages WHERE page_id = '$parent'");
182
if($query_parent->numRows() > 0)
183
{
184
	$fetch_parent = $query_parent->fetchRow();
185
	$template = $fetch_parent['template'];
186
	$language = $fetch_parent['language'];
187
} else {
188
	$template = '';
189
	$language = DEFAULT_LANGUAGE;
190
}
191
192
// Insert page into pages table
193 1914 Luisehahne
$sql  = 'INSERT INTO `'.TABLE_PREFIX.'pages` ';
194
$sql .= 'SET `parent` = '.$parent.', ';
195 1358 Luisehahne
$sql .= '`target` = "_top", ';
196
$sql .= '`page_title` = "'.$title.'", ';
197
$sql .= '`menu_title` = "'.$title.'", ';
198 1772 Luisehahne
$sql .= '`tooltip` = "'.$title.'", ';
199 1358 Luisehahne
$sql .= '`template` = "'.$template.'", ';
200
$sql .= '`visibility` = "'.$visibility.'", ';
201
$sql .= '`position` = '.$position.', ';
202
$sql .= '`menu` = 1, ';
203
$sql .= '`language` = "'.$language.'", ';
204
$sql .= '`searching` = 1, ';
205
$sql .= '`modified_when` = '.time().', ';
206
$sql .= '`modified_by` = '.$admin->get_user_id().', ';
207
$sql .= '`admin_groups` = "'.$admin_groups.'", ';
208
$sql .= '`viewing_groups` = "'.$viewing_groups.'"';
209
210 1914 Luisehahne
if(!$database->query($sql)) {
211
	if($database->is_error())
212
	{
213
		$admin->print_error($database->get_error());
214
	}
215 1358 Luisehahne
}
216
217
// Get the page id
218 1914 Luisehahne
//$page_id = $database->get_one("SELECT LAST_INSERT_ID()");
219
$page_id = $database->LastInsertId;
220 1358 Luisehahne
// Work out level
221
$level = level_count($page_id);
222
// Work out root parent
223
$root_parent = root_parent($page_id);
224
// Work out page trail
225
$page_trail = get_page_trail($page_id);
226
227 1914 Luisehahne
/*
228
$database->query("UPDATE ".TABLE_PREFIX."pages SET link = '$link', level = '$level', root_parent = '$root_parent', page_trail = '$page_trail' WHERE page_id = '$page_id'");
229
*/
230 1358 Luisehahne
// Update page with new level and link
231
$sql  = 'UPDATE `'.TABLE_PREFIX.'pages` SET ';
232
$sql .= '`root_parent` = '.$root_parent.', ';
233
$sql .= '`level` = '.$level.', ';
234 1914 Luisehahne
$sql .= '`link` = \''.$link.'\', ';
235
$sql .= '`page_trail` = \''.$page_trail.'\'';
236
$sql .= ((defined('PAGE_LANGUAGES') && PAGE_LANGUAGES) && $field_set && ($language == DEFAULT_LANGUAGE)
237
                                    && class_exists('m_MultiLingual_Lib') ? ', `page_code` = '.(int)$page_id.' ' : ' ');
238 1358 Luisehahne
$sql .= 'WHERE `page_id` = '.$page_id;
239
$database->query($sql);
240
if($database->is_error())
241
{
242
	$admin->print_error($database->get_error());
243
}
244
245 1868 Luisehahne
// add position 1 to new page section
246 1358 Luisehahne
$position = 1;
247
248
// Add new record into the sections table
249 1754 Luisehahne
// Insert module into DB
250 1914 Luisehahne
$sql  = 'INSERT INTO `'.TABLE_PREFIX.'sections` ';
251
$sql .= 'SET `page_id` = '.(int)$page_id.', ';
252 1754 Luisehahne
$sql .= '`module` = \''.$module.'\', ';
253
$sql .= '`position` = '.(int)$position.', ';
254
$sql .= '`block` = \'1\', ';
255
$sql .= '`publ_start` = \'0\',';
256
$sql .= '`publ_end` = \'0\' ';
257
if($database->query($sql)) {
258
	// Get the section id
259
	$section_id = $database->get_one("SELECT LAST_INSERT_ID()");
260
	// Include the selected modules add file if it exists
261
	if(file_exists(WB_PATH.'/modules/'.$module.'/add.php'))
262
    {
263
		require(WB_PATH.'/modules/'.$module.'/add.php');
264
	}
265 1358 Luisehahne
}
266
267 1868 Luisehahne
// Create a new file in the /pages dir
268
create_access_file($filename, $page_id, $level);
269
270
if(!file_exists($filename)) {
271 1914 Luisehahne
	$admin->print_error($mLang->MESSAGE_PAGES_CANNOT_CREATE_ACCESS_FILE);
272 1868 Luisehahne
}
273
274 1358 Luisehahne
// Check if there is a db error, otherwise say successful
275
if($database->is_error()) {
276 1754 Luisehahne
	$admin->print_error($database->get_error().' (sections)');
277 1358 Luisehahne
} else {
278 1914 Luisehahne
	$admin->print_success($mLang->MESSAGE_PAGES_ADDED, ADMIN_URL.'/pages/modify.php?page_id='.$page_id);
279 1358 Luisehahne
}
280
281 1914 Luisehahne
$mLang->disableAddon();
282 1358 Luisehahne
// Print admin footer
283
$admin->print_footer();