1
|
<?php
|
2
|
/**
|
3
|
*
|
4
|
* @category admin
|
5
|
* @package pages
|
6
|
* @author WebsiteBaker Project
|
7
|
* @copyright Ryan Djurovich
|
8
|
* @copyright WebsiteBaker Org. e.V.
|
9
|
* @link http://websitebaker.org/
|
10
|
* @license http://www.gnu.org/licenses/gpl.html
|
11
|
* @platform WebsiteBaker 2.8.3
|
12
|
* @requirements PHP 5.3.6 and higher
|
13
|
* @version $Id: add.php 2 2017-07-02 15:14:29Z Manuela $
|
14
|
* @filesource $HeadURL: svn://isteam.dynxs.de/wb/2.10.x/trunk/admin/pages/add.php $
|
15
|
* @lastmodified $Date: 2017-07-02 17:14:29 +0200 (Sun, 02 Jul 2017) $
|
16
|
*
|
17
|
*/
|
18
|
|
19
|
// Create new admin object and print admin header
|
20
|
if ( !defined( 'WB_PATH' ) ){ require( dirname(dirname((__DIR__))).'/config.php' ); }
|
21
|
if ( !class_exists('admin', false) ) { require(WB_PATH.'/framework/class.admin.php'); }
|
22
|
// suppress to print the header, so no new FTAN will be set
|
23
|
$admin = new admin('Pages', 'pages_add', false);
|
24
|
if (!$admin->checkFTAN())
|
25
|
{
|
26
|
$admin->print_header();
|
27
|
$admin->print_error($MESSAGE['GENERIC_SECURITY_ACCESS'], ADMIN_URL );
|
28
|
}
|
29
|
|
30
|
// Include the WB functions file
|
31
|
require_once(WB_PATH.'/framework/functions.php');
|
32
|
|
33
|
// Get values
|
34
|
$title = $admin->get_post('title');
|
35
|
$title = htmlspecialchars($title);
|
36
|
$module = preg_replace('/[^a-z0-9_-]/i', "", $admin->get_post('type')); // fix secunia 2010-93-4
|
37
|
$parent = intval($admin->get_post('parent')); // fix secunia 2010-91-2
|
38
|
$visibility = $admin->get_post('visibility');
|
39
|
if (!in_array($visibility, array('public', 'private', 'registered', 'hidden', 'none'))) {$visibility = 'public';} // fix secunia 2010-91-2
|
40
|
$admin_groups = $admin->get_post('admin_groups');
|
41
|
$viewing_groups = $admin->get_post('viewing_groups');
|
42
|
|
43
|
// Work-out if we should check for existing page_code
|
44
|
$field_set = $database->field_exists(TABLE_PREFIX.'pages', 'page_code');
|
45
|
|
46
|
// add Admin to admin and viewing-groups
|
47
|
$admin_groups[] = 1;
|
48
|
$viewing_groups[] = 1;
|
49
|
|
50
|
// After check print the header
|
51
|
$admin->print_header();
|
52
|
// check parent page permissions:
|
53
|
if ($parent!=0) {
|
54
|
if (!$admin->get_page_permission($parent,'admin'))
|
55
|
{
|
56
|
$admin->print_error($MESSAGE['PAGES_INSUFFICIENT_PERMISSIONS']);
|
57
|
}
|
58
|
|
59
|
} elseif (!$admin->get_permission('pages_add_l0','system'))
|
60
|
{
|
61
|
$admin->print_error($MESSAGE['PAGES_INSUFFICIENT_PERMISSIONS']);
|
62
|
}
|
63
|
|
64
|
// check module permissions:
|
65
|
if (!$admin->get_permission($module, 'module'))
|
66
|
{
|
67
|
$admin->print_error($MESSAGE['PAGES_INSUFFICIENT_PERMISSIONS']);
|
68
|
}
|
69
|
|
70
|
// Validate data
|
71
|
if($title == '' || substr($title,0,1)=='.')
|
72
|
{
|
73
|
$admin->print_error($MESSAGE['PAGES_BLANK_PAGE_TITLE']);
|
74
|
}
|
75
|
|
76
|
// Check to see if page created has needed permissions
|
77
|
if(!in_array(1, $admin->get_groups_id()))
|
78
|
{
|
79
|
$admin_perm_ok = false;
|
80
|
foreach ($admin_groups as $adm_group)
|
81
|
{
|
82
|
if (in_array($adm_group, $admin->get_groups_id()))
|
83
|
{
|
84
|
$admin_perm_ok = true;
|
85
|
}
|
86
|
}
|
87
|
if ($admin_perm_ok == false)
|
88
|
{
|
89
|
$admin->print_error($MESSAGE['PAGES_INSUFFICIENT_PERMISSIONS']);
|
90
|
}
|
91
|
$admin_perm_ok = false;
|
92
|
foreach ($viewing_groups as $view_group)
|
93
|
{
|
94
|
if (in_array($view_group, $admin->get_groups_id()))
|
95
|
{
|
96
|
$admin_perm_ok = true;
|
97
|
}
|
98
|
}
|
99
|
if ($admin_perm_ok == false)
|
100
|
{
|
101
|
$admin->print_error($MESSAGE['PAGES_INSUFFICIENT_PERMISSIONS']);
|
102
|
}
|
103
|
}
|
104
|
|
105
|
$admin_groups = implode(',', $admin_groups);
|
106
|
$viewing_groups = implode(',', $viewing_groups);
|
107
|
|
108
|
// Work-out what the link and page filename should be
|
109
|
if($parent == '0')
|
110
|
{
|
111
|
$link = '/'.page_filename($title);
|
112
|
// rename menu titles: index && intro to prevent clashes with intro page feature and WB core file /pages/index.php
|
113
|
if($link == '/index' || $link == '/intro')
|
114
|
{
|
115
|
$link .= '_0';
|
116
|
$filename = WB_PATH .PAGES_DIRECTORY .'/' .page_filename($title) .'_0' .PAGE_EXTENSION;
|
117
|
} else {
|
118
|
$filename = WB_PATH.PAGES_DIRECTORY.'/'.page_filename($title).PAGE_EXTENSION;
|
119
|
}
|
120
|
} else {
|
121
|
$parent_section = '';
|
122
|
$parent_titles = array_reverse(get_parent_titles($parent));
|
123
|
foreach($parent_titles AS $parent_title)
|
124
|
{
|
125
|
$parent_section .= page_filename($parent_title).'/';
|
126
|
}
|
127
|
if($parent_section == '/') { $parent_section = ''; }
|
128
|
$link = '/'.$parent_section.page_filename($title);
|
129
|
$filename = WB_PATH.PAGES_DIRECTORY.'/'.$parent_section.page_filename($title).PAGE_EXTENSION;
|
130
|
make_dir(WB_PATH.PAGES_DIRECTORY.'/'.$parent_section);
|
131
|
}
|
132
|
|
133
|
// Check if a page with same page filename exists
|
134
|
$sql = 'SELECT `page_id` FROM `'.TABLE_PREFIX.'pages` '
|
135
|
. 'WHERE `link`=\''.$link.'\'';
|
136
|
$get_same_page = $database->get_one($sql);
|
137
|
if (
|
138
|
$get_same_page OR
|
139
|
file_exists(WB_PATH.PAGES_DIRECTORY.$link.PAGE_EXTENSION) OR
|
140
|
file_exists(WB_PATH.PAGES_DIRECTORY.$link.'/')
|
141
|
) {
|
142
|
$admin->print_error($MESSAGE['PAGES']['PAGE_EXISTS']);
|
143
|
}
|
144
|
|
145
|
// Include the ordering class
|
146
|
require(WB_PATH.'/framework/class.order.php');
|
147
|
$order = new order(TABLE_PREFIX.'pages', 'position', 'page_id', 'parent');
|
148
|
// First clean order
|
149
|
$order->clean($parent);
|
150
|
// Get new order
|
151
|
$position = $order->get_new($parent);
|
152
|
|
153
|
// Work-out if the page parent (if selected) has a seperate template or language to the default
|
154
|
$sql='SELECT `template`, `language` FROM `'.TABLE_PREFIX.'pages` '
|
155
|
. 'WHERE `page_id` = '.(int)$parent;
|
156
|
$query_parent = $database->query($sql);
|
157
|
if ($query_parent->numRows() > 0) {
|
158
|
$fetch_parent = $query_parent->fetchRow( MYSQLI_ASSOC );
|
159
|
$template = $fetch_parent['template'];
|
160
|
$language = $fetch_parent['language'];
|
161
|
} else {
|
162
|
$template = '';
|
163
|
$language = DEFAULT_LANGUAGE;
|
164
|
}
|
165
|
|
166
|
// Insert page into pages table
|
167
|
$sql = 'INSERT INTO `'.TABLE_PREFIX.'pages` '
|
168
|
. 'SET `parent`='.(int)$parent.', '
|
169
|
. '`link` = \'\', '
|
170
|
. '`description`=\'\', '
|
171
|
. '`keywords`=\'\', '
|
172
|
. '`page_trail`=\'\', '
|
173
|
. '`admin_users`=\'\', '
|
174
|
. '`viewing_users`=\'\', '
|
175
|
. '`target`=\'_top\', '
|
176
|
. '`page_title`=\''.$database->escapeString($title).'\', '
|
177
|
. '`menu_title`=\''.$database->escapeString($title).'\', '
|
178
|
. '`template`=\''.$database->escapeString($template).'\', '
|
179
|
. '`visibility`=\''.$database->escapeString($visibility).'\', '
|
180
|
. '`position`='.(int)$position.', '
|
181
|
. '`menu`=1, '
|
182
|
. '`language`=\''.$database->escapeString($language).'\', '
|
183
|
. '`searching`=1, '
|
184
|
. '`modified_when`='.time().', '
|
185
|
. '`modified_by`='.(int)$admin->get_user_id().', '
|
186
|
. '`admin_groups`=\''.$database->escapeString($admin_groups).'\', '
|
187
|
. '`viewing_groups`=\''.$database->escapeString($viewing_groups).'\'';
|
188
|
if (!$database->query($sql)) {
|
189
|
$admin->print_error($database->get_error());
|
190
|
}
|
191
|
// Get the new page id
|
192
|
$page_id = $database->getLastInsertId();
|
193
|
// Work out level
|
194
|
$level = level_count($page_id);
|
195
|
// Work out root parent
|
196
|
$root_parent = root_parent($page_id);
|
197
|
// Work out page trail
|
198
|
$page_trail = get_page_trail($page_id);
|
199
|
// Update page with new level and link
|
200
|
$sql = 'UPDATE `'.TABLE_PREFIX.'pages` SET '
|
201
|
. '`root_parent` = '.(int)$root_parent.', '
|
202
|
. '`level` = '.(int)$level.', '
|
203
|
. '`link` = \''.$database->escapeString($link).'\', '
|
204
|
. ((defined('PAGE_LANGUAGES') && PAGE_LANGUAGES)
|
205
|
&& $field_set
|
206
|
&& ($language == DEFAULT_LANGUAGE)
|
207
|
&& (file_exists(WB_PATH.'/modules/mod_multilingual/update_keys.php')
|
208
|
)
|
209
|
? '`page_code` = '.(int)$page_id.', ' : '')
|
210
|
. '`page_trail`=\''.$database->escapeString($page_trail).'\' '
|
211
|
. 'WHERE `page_id` = '.$page_id;
|
212
|
if (!$database->query($sql)) {
|
213
|
$admin->print_error($database->get_error());
|
214
|
}
|
215
|
// Create a new file in the /pages dir
|
216
|
create_access_file($filename, $page_id, $level);
|
217
|
|
218
|
// add position 1 to new page
|
219
|
$position = 1;
|
220
|
|
221
|
// Add new record into the sections table
|
222
|
$sql = 'INSERT INTO `'.TABLE_PREFIX.'sections` '
|
223
|
. 'SET `page_id`='.(int)$page_id.', '
|
224
|
. '`position`='.(int)$position.', '
|
225
|
. '`module`=\''.$database->escapeString($module).'\', '
|
226
|
. '`block`=1';
|
227
|
if (!$database->query($sql)) {
|
228
|
$admin->print_error($database->get_error());
|
229
|
}
|
230
|
// Get the section id
|
231
|
if (!($section_id = $database->getLastInsertId())) {
|
232
|
$admin->print_error($database->get_error());
|
233
|
}
|
234
|
// Include the selected modules add file if it exists
|
235
|
if (
|
236
|
file_exists(WB_PATH.'/modules/'.$module.'/addon.php') &&
|
237
|
file_exists(WB_PATH.'/modules/'.$module.'/cmd/cmdModify.inc')
|
238
|
) {
|
239
|
$sCommand = 'modify';
|
240
|
// require WB_PATH.'/modules/'.$module.'/addon.php';
|
241
|
$admin->print_success($MESSAGE['PAGES_ADDED'], ADMIN_URL.'/pages/modify.php?page_id='.$page_id);
|
242
|
} else {
|
243
|
if (file_exists(WB_PATH.'/modules/'.$module.'/add.php')) {
|
244
|
require WB_PATH.'/modules/'.$module.'/add.php';
|
245
|
}
|
246
|
$admin->print_success($MESSAGE['PAGES_ADDED'], ADMIN_URL.'/pages/modify.php?page_id='.$page_id);
|
247
|
}
|
248
|
/*
|
249
|
// Include the selected modules add file if it exists
|
250
|
if(file_exists(WB_PATH.'/modules/'.$module.'/add.php')) {
|
251
|
require(WB_PATH.'/modules/'.$module.'/add.php');
|
252
|
}
|
253
|
$admin->print_success($MESSAGE['PAGES']['ADDED'], ADMIN_URL.'/pages/modify.php?page_id='.$page_id);
|
254
|
*/
|
255
|
// Print admin footer
|
256
|
$admin->print_footer();
|