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