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.x
|
11
|
* @requirements PHP 5.2.2 and higher
|
12
|
* @version $Id: add.php 2070 2014-01-03 01:21:42Z darkviper $
|
13
|
* @filesource $HeadURL: svn://isteam.dynxs.de/wb-archiv/branches/2.8.x/wb/admin/pages/add.php $
|
14
|
* @lastmodified $Date: 2014-01-03 02:21:42 +0100 (Fri, 03 Jan 2014) $
|
15
|
*
|
16
|
*/
|
17
|
|
18
|
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
|
// Create new admin object and print admin header
|
27
|
if(!class_exists('admin', false)){ include(WB_PATH.'/framework/class.admin.php'); }
|
28
|
$mLang = Translate::getinstance();
|
29
|
$mLang->enableAddon('admin\pages');
|
30
|
|
31
|
// suppress to print the header, so no new FTAN will be set
|
32
|
$admin = new admin('Pages', 'pages_add', false);
|
33
|
if (!$admin->checkFTAN())
|
34
|
{
|
35
|
$admin->print_header();
|
36
|
$admin->print_error($mLang->MESSAGE_GENERIC_SECURITY_ACCESS);
|
37
|
}
|
38
|
|
39
|
// Include the WB functions file
|
40
|
require_once(WB_PATH.'/framework/functions.php');
|
41
|
|
42
|
// Get values
|
43
|
//$title = str_replace(array("[[", "]]"), '', htmlspecialchars($admin->get_post_escaped('title')));
|
44
|
$title = ($admin->StripCodeFromText($admin->get_post('title')));
|
45
|
$module = preg_replace('/[^a-z0-9_-]/i', "", $admin->get_post('type')); // fix secunia 2010-93-4
|
46
|
$parent = intval($admin->get_post('parent')); // fix secunia 2010-91-2
|
47
|
$visibility = $admin->get_post('visibility');
|
48
|
if (!in_array($visibility, array('public', 'private', 'registered', 'hidden', 'none'))) {$visibility = 'public';} // fix secunia 2010-91-2
|
49
|
$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
|
$field_set = $database->field_exists(TABLE_PREFIX.'pages', 'page_code');
|
54
|
|
55
|
// add Admin to admin and viewing-groups
|
56
|
$admin_groups[] = 1;
|
57
|
$viewing_groups[] = 1;
|
58
|
|
59
|
// After check print the header
|
60
|
$admin->print_header();
|
61
|
// check parent page permissions:
|
62
|
if ($parent!=0) {
|
63
|
if (!$admin->get_page_permission($parent,'admin'))
|
64
|
{
|
65
|
$admin->print_error($mLang->MESSAGE_PAGES_INSUFFICIENT_PERMISSIONS);
|
66
|
}
|
67
|
|
68
|
} elseif (!$admin->get_permission('pages_add_l0','system'))
|
69
|
{
|
70
|
$admin->print_error($mLang->MESSAGE_PAGES_INSUFFICIENT_PERMISSIONS);
|
71
|
}
|
72
|
|
73
|
// check module permissions:
|
74
|
if (!$admin->get_permission($module, 'module'))
|
75
|
{
|
76
|
$admin->print_error($mLang->MESSAGE_PAGES_INSUFFICIENT_PERMISSIONS);
|
77
|
}
|
78
|
|
79
|
// Validate data
|
80
|
if($title == '' || substr($title,0,1)=='.')
|
81
|
{
|
82
|
$admin->print_error($title.'::'.$mLang->MESSAGE_PAGES_BLANK_PAGE_TITLE);
|
83
|
}
|
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
|
}
|
95
|
}
|
96
|
if ($admin_perm_ok == false)
|
97
|
{
|
98
|
$admin->print_error($mLang->MESSAGE_PAGES_INSUFFICIENT_PERMISSIONS);
|
99
|
}
|
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
|
$admin->print_error($mLang->MESSAGE_PAGES_INSUFFICIENT_PERMISSIONS);
|
111
|
}
|
112
|
}
|
113
|
|
114
|
$admin_groups = implode(',', $admin_groups);
|
115
|
$viewing_groups = implode(',', $viewing_groups);
|
116
|
|
117
|
// 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
|
// 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
|
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
|
}
|
142
|
$filename = WB_PATH.PAGES_DIRECTORY.$link.PAGE_EXTENSION;
|
143
|
|
144
|
} 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
|
//$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
|
$admin->print_error($MESSAGE['PAGES_PAGE_EXISTS']);
|
170
|
}
|
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
|
$sql = 'INSERT INTO `'.TABLE_PREFIX.'pages` ';
|
194
|
$sql .= 'SET `parent` = '.$parent.', ';
|
195
|
$sql .= '`target` = "_top", ';
|
196
|
$sql .= '`page_title` = "'.$title.'", ';
|
197
|
$sql .= '`menu_title` = "'.$title.'", ';
|
198
|
$sql .= '`tooltip` = "'.$title.'", ';
|
199
|
$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
|
if(!$database->query($sql)) {
|
211
|
if($database->is_error())
|
212
|
{
|
213
|
$admin->print_error($database->get_error());
|
214
|
}
|
215
|
}
|
216
|
|
217
|
// Get the page id
|
218
|
//$page_id = $database->get_one("SELECT LAST_INSERT_ID()");
|
219
|
$page_id = $database->LastInsertId;
|
220
|
// 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
|
/*
|
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
|
// 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
|
$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
|
$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
|
// add position 1 to new page section
|
246
|
$position = 1;
|
247
|
|
248
|
// Add new record into the sections table
|
249
|
// Insert module into DB
|
250
|
$sql = 'INSERT INTO `'.TABLE_PREFIX.'sections` ';
|
251
|
$sql .= 'SET `page_id` = '.(int)$page_id.', ';
|
252
|
$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
|
}
|
266
|
|
267
|
// Create a new file in the /pages dir
|
268
|
create_access_file($filename, $page_id, $level);
|
269
|
|
270
|
if(!file_exists($filename)) {
|
271
|
$admin->print_error($mLang->MESSAGE_PAGES_CANNOT_CREATE_ACCESS_FILE);
|
272
|
}
|
273
|
|
274
|
// Check if there is a db error, otherwise say successful
|
275
|
if($database->is_error()) {
|
276
|
$admin->print_error($database->get_error().' (sections)');
|
277
|
} else {
|
278
|
$admin->print_success($mLang->MESSAGE_PAGES_ADDED, ADMIN_URL.'/pages/modify.php?page_id='.$page_id);
|
279
|
}
|
280
|
|
281
|
$mLang->disableAddon();
|
282
|
// Print admin footer
|
283
|
$admin->print_footer();
|