Revision 1301
Added by Dietmar over 14 years ago
add.php | ||
---|---|---|
1 |
<?php |
|
2 |
|
|
3 |
// $Id$ |
|
4 |
|
|
5 |
/* |
|
6 |
|
|
7 |
Website Baker Project <http://www.websitebaker.org/> |
|
8 |
Copyright (C) 2004-2009, Ryan Djurovich |
|
9 |
|
|
10 |
Website Baker is free software; you can redistribute it and/or modify |
|
11 |
it under the terms of the GNU General Public License as published by |
|
12 |
the Free Software Foundation; either version 2 of the License, or |
|
13 |
(at your option) any later version. |
|
14 |
|
|
15 |
Website Baker is distributed in the hope that it will be useful, |
|
16 |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
17 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
18 |
GNU General Public License for more details. |
|
19 |
|
|
20 |
You should have received a copy of the GNU General Public License |
|
21 |
along with Website Baker; if not, write to the Free Software |
|
22 |
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
|
23 |
|
|
24 |
*/ |
|
25 |
|
|
26 |
// Create new admin object and print admin header |
|
27 |
require('../../config.php'); |
|
28 |
require_once(WB_PATH.'/framework/class.admin.php'); |
|
29 |
$admin = new admin('Pages', 'pages_add'); |
|
30 |
|
|
31 |
// Include the WB functions file |
|
32 |
require_once(WB_PATH.'/framework/functions.php'); |
|
33 |
|
|
34 |
// Get values |
|
35 |
$title = $admin->get_post_escaped('title'); |
|
36 |
$title = htmlspecialchars($title); |
|
37 |
$module = $admin->get_post('type'); |
|
38 |
$parent = $admin->get_post('parent'); |
|
39 |
$visibility = $admin->get_post('visibility'); |
|
40 |
$admin_groups = $admin->get_post('admin_groups'); |
|
41 |
$viewing_groups = $admin->get_post('viewing_groups'); |
|
42 |
|
|
43 |
// add Admin to admin and viewing-groups |
|
44 |
$admin_groups[] = 1; |
|
45 |
$viewing_groups[] = 1; |
|
46 |
|
|
47 |
if ($parent!=0) { |
|
48 |
if (!$admin->get_page_permission($parent,'admin')) |
|
49 |
$admin->print_error($MESSAGE['PAGES']['INSUFFICIENT_PERMISSIONS']); |
|
50 |
} elseif (!$admin->get_permission('pages_add_l0','system')) { |
|
51 |
$admin->print_error($MESSAGE['PAGES']['INSUFFICIENT_PERMISSIONS']); |
|
52 |
} |
|
53 |
|
|
54 |
// Validate data |
|
55 |
if($title == '' || substr($title,0,1)=='.') { |
|
56 |
$admin->print_error($MESSAGE['PAGES']['BLANK_PAGE_TITLE']); |
|
57 |
} |
|
58 |
|
|
59 |
// Check to see if page created has needed permissions |
|
60 |
if(!in_array(1, $admin->get_groups_id())) { |
|
61 |
$admin_perm_ok = false; |
|
62 |
foreach ($admin_groups as $adm_group) { |
|
63 |
if (in_array($adm_group, $admin->get_groups_id())) { |
|
64 |
$admin_perm_ok = true; |
|
65 |
} |
|
66 |
} |
|
67 |
if ($admin_perm_ok == false) { |
|
68 |
$admin->print_error($MESSAGE['PAGES']['INSUFFICIENT_PERMISSIONS']); |
|
69 |
} |
|
70 |
$admin_perm_ok = false; |
|
71 |
foreach ($viewing_groups as $view_group) { |
|
72 |
if (in_array($view_group, $admin->get_groups_id())) { |
|
73 |
$admin_perm_ok = true; |
|
74 |
} |
|
75 |
} |
|
76 |
if ($admin_perm_ok == false) { |
|
77 |
$admin->print_error($MESSAGE['PAGES']['INSUFFICIENT_PERMISSIONS']); |
|
78 |
} |
|
79 |
} |
|
80 |
|
|
81 |
$admin_groups = implode(',', $admin_groups); |
|
82 |
$viewing_groups = implode(',', $viewing_groups); |
|
83 |
|
|
84 |
// Work-out what the link and page filename should be |
|
85 |
if($parent == '0') { |
|
86 |
$link = '/'.page_filename($title); |
|
87 |
// rename menu titles: index && intro to prevent clashes with intro page feature and WB core file /pages/index.php |
|
88 |
if($link == '/index' || $link == '/intro') { |
|
89 |
$link .= '_0'; |
|
90 |
$filename = WB_PATH .PAGES_DIRECTORY .'/' .page_filename($title) .'_0' .PAGE_EXTENSION; |
|
91 |
} else { |
|
92 |
$filename = WB_PATH.PAGES_DIRECTORY.'/'.page_filename($title).PAGE_EXTENSION; |
|
93 |
} |
|
94 |
} else { |
|
95 |
$parent_section = ''; |
|
96 |
$parent_titles = array_reverse(get_parent_titles($parent)); |
|
97 |
foreach($parent_titles AS $parent_title) { |
|
98 |
$parent_section .= page_filename($parent_title).'/'; |
|
99 |
} |
|
100 |
if($parent_section == '/') { $parent_section = ''; } |
|
101 |
$link = '/'.$parent_section.page_filename($title); |
|
102 |
$filename = WB_PATH.PAGES_DIRECTORY.'/'.$parent_section.page_filename($title).PAGE_EXTENSION; |
|
103 |
make_dir(WB_PATH.PAGES_DIRECTORY.'/'.$parent_section); |
|
104 |
} |
|
105 |
|
|
106 |
// Check if a page with same page filename exists |
|
107 |
$get_same_page = $database->query("SELECT page_id FROM ".TABLE_PREFIX."pages WHERE link = '$link'"); |
|
108 |
if($get_same_page->numRows() > 0 OR file_exists(WB_PATH.PAGES_DIRECTORY.$link.PAGE_EXTENSION) OR file_exists(WB_PATH.PAGES_DIRECTORY.$link.'/')) { |
|
109 |
$admin->print_error($MESSAGE['PAGES']['PAGE_EXISTS']); |
|
110 |
} |
|
111 |
|
|
112 |
// Include the ordering class |
|
113 |
require(WB_PATH.'/framework/class.order.php'); |
|
114 |
$order = new order(TABLE_PREFIX.'pages', 'position', 'page_id', 'parent'); |
|
115 |
// First clean order |
|
116 |
$order->clean($parent); |
|
117 |
// Get new order |
|
118 |
$position = $order->get_new($parent); |
|
119 |
|
|
120 |
// Work-out if the page parent (if selected) has a seperate template or language to the default |
|
121 |
$query_parent = $database->query("SELECT template, language FROM ".TABLE_PREFIX."pages WHERE page_id = '$parent'"); |
|
122 |
if($query_parent->numRows() > 0) { |
|
123 |
$fetch_parent = $query_parent->fetchRow(); |
|
124 |
$template = $fetch_parent['template']; |
|
125 |
$language = $fetch_parent['language']; |
|
126 |
} else { |
|
127 |
$template = ''; |
|
128 |
$language = DEFAULT_LANGUAGE; |
|
129 |
} |
|
130 |
|
|
131 |
// Insert page into pages table |
|
132 |
$query = "INSERT INTO ".TABLE_PREFIX."pages (page_title,menu_title,parent,template,target,position,visibility,searching,menu,language,admin_groups,viewing_groups,modified_when,modified_by) VALUES ('$title','$title','$parent','$template','_top','$position','$visibility','1','1','$language','$admin_groups','$viewing_groups','".time()."','".$admin->get_user_id()."')"; |
|
133 |
$database->query($query); |
|
134 |
if($database->is_error()) { |
|
135 |
$admin->print_error($database->get_error()); |
|
136 |
} |
|
137 |
|
|
138 |
// Get the page id |
|
139 |
$page_id = $database->get_one("SELECT LAST_INSERT_ID()"); |
|
140 |
|
|
141 |
// Work out level |
|
142 |
$level = level_count($page_id); |
|
143 |
// Work out root parent |
|
144 |
$root_parent = root_parent($page_id); |
|
145 |
// Work out page trail |
|
146 |
$page_trail = get_page_trail($page_id); |
|
147 |
|
|
148 |
// Update page with new level and link |
|
149 |
$database->query("UPDATE ".TABLE_PREFIX."pages SET link = '$link', level = '$level', root_parent = '$root_parent', page_trail = '$page_trail' WHERE page_id = '$page_id'"); |
|
150 |
|
|
151 |
// Create a new file in the /pages dir |
|
152 |
create_access_file($filename, $page_id, $level); |
|
153 |
|
|
154 |
// add position 1 to new page |
|
155 |
$position = 1; |
|
156 |
|
|
157 |
// Add new record into the sections table |
|
158 |
$database->query("INSERT INTO ".TABLE_PREFIX."sections (page_id,position,module,block) VALUES ('$page_id','$position', '$module','1')"); |
|
159 |
|
|
160 |
// Get the section id |
|
161 |
$section_id = $database->get_one("SELECT LAST_INSERT_ID()"); |
|
162 |
|
|
163 |
// Include the selected modules add file if it exists |
|
164 |
if(file_exists(WB_PATH.'/modules/'.$module.'/add.php')) { |
|
165 |
require(WB_PATH.'/modules/'.$module.'/add.php'); |
|
166 |
} |
|
167 |
|
|
168 |
// Check if there is a db error, otherwise say successful |
|
169 |
if($database->is_error()) { |
|
170 |
$admin->print_error($database->get_error()); |
|
171 |
} else { |
|
172 |
$admin->print_success($MESSAGE['PAGES']['ADDED'], ADMIN_URL.'/pages/modify.php?page_id='.$page_id); |
|
173 |
} |
|
174 |
|
|
175 |
// Print admin footer |
|
176 |
$admin->print_footer(); |
|
177 |
|
|
1 |
<?php |
|
2 |
/** |
|
3 |
* |
|
4 |
* @category admin |
|
5 |
* @package pages |
|
6 |
* @author WebsiteBaker Project |
|
7 |
* @copyright 2004-2009, Ryan Djurovich |
|
8 |
* @copyright 2009-2010, 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 4.3.4 and higher |
|
13 |
* @version $Id$ |
|
14 |
* @filesource $HeadURL$ |
|
15 |
* @lastmodified $Date$ |
|
16 |
* |
|
17 |
*/ |
|
18 |
|
|
19 |
// Create new admin object and print admin header |
|
20 |
require('../../config.php'); |
|
21 |
require_once(WB_PATH.'/framework/class.admin.php'); |
|
22 |
$admin = new admin('Pages', 'pages_add'); |
|
23 |
|
|
24 |
// Include the WB functions file |
|
25 |
require_once(WB_PATH.'/framework/functions.php'); |
|
26 |
|
|
27 |
// Get values |
|
28 |
$title = $admin->get_post_escaped('title'); |
|
29 |
$title = htmlspecialchars($title); |
|
30 |
$module = $admin->get_post('type'); |
|
31 |
$parent = $admin->get_post('parent'); |
|
32 |
$visibility = $admin->get_post('visibility'); |
|
33 |
$admin_groups = $admin->get_post('admin_groups'); |
|
34 |
$viewing_groups = $admin->get_post('viewing_groups'); |
|
35 |
|
|
36 |
// Work-out if we should check for existing page_code |
|
37 |
$sql = 'DESCRIBE `'.TABLE_PREFIX.'pages` `page_code`'; |
|
38 |
$field_sql = $database->query($sql); |
|
39 |
$field_set = $field_sql->numRows(); |
|
40 |
|
|
41 |
// add Admin to admin and viewing-groups |
|
42 |
$admin_groups[] = 1; |
|
43 |
$viewing_groups[] = 1; |
|
44 |
|
|
45 |
if ($parent!=0) { |
|
46 |
if (!$admin->get_page_permission($parent,'admin')) |
|
47 |
{ |
|
48 |
$admin->print_error($MESSAGE['PAGES']['INSUFFICIENT_PERMISSIONS']); |
|
49 |
} |
|
50 |
|
|
51 |
} elseif (!$admin->get_permission('pages_add_l0','system')) |
|
52 |
{ |
|
53 |
$admin->print_error($MESSAGE['PAGES']['INSUFFICIENT_PERMISSIONS']); |
|
54 |
} |
|
55 |
|
|
56 |
// Validate data |
|
57 |
if($title == '' || substr($title,0,1)=='.') |
|
58 |
{ |
|
59 |
$admin->print_error($MESSAGE['PAGES']['BLANK_PAGE_TITLE']); |
|
60 |
} |
|
61 |
|
|
62 |
// Check to see if page created has needed permissions |
|
63 |
if(!in_array(1, $admin->get_groups_id())) |
|
64 |
{ |
|
65 |
$admin_perm_ok = false; |
|
66 |
foreach ($admin_groups as $adm_group) |
|
67 |
{ |
|
68 |
if (in_array($adm_group, $admin->get_groups_id())) |
|
69 |
{ |
|
70 |
$admin_perm_ok = true; |
|
71 |
} |
|
72 |
} |
|
73 |
if ($admin_perm_ok == false) |
|
74 |
{ |
|
75 |
$admin->print_error($MESSAGE['PAGES']['INSUFFICIENT_PERMISSIONS']); |
|
76 |
} |
|
77 |
$admin_perm_ok = false; |
|
78 |
foreach ($viewing_groups as $view_group) |
|
79 |
{ |
|
80 |
if (in_array($view_group, $admin->get_groups_id())) |
|
81 |
{ |
|
82 |
$admin_perm_ok = true; |
|
83 |
} |
|
84 |
} |
|
85 |
if ($admin_perm_ok == false) |
|
86 |
{ |
|
87 |
$admin->print_error($MESSAGE['PAGES']['INSUFFICIENT_PERMISSIONS']); |
|
88 |
} |
|
89 |
} |
|
90 |
|
|
91 |
$admin_groups = implode(',', $admin_groups); |
|
92 |
$viewing_groups = implode(',', $viewing_groups); |
|
93 |
|
|
94 |
// Work-out what the link and page filename should be |
|
95 |
if($parent == '0') |
|
96 |
{ |
|
97 |
$link = '/'.page_filename($title); |
|
98 |
// rename menu titles: index && intro to prevent clashes with intro page feature and WB core file /pages/index.php |
|
99 |
if($link == '/index' || $link == '/intro') |
|
100 |
{ |
|
101 |
$link .= '_0'; |
|
102 |
$filename = WB_PATH .PAGES_DIRECTORY .'/' .page_filename($title) .'_0' .PAGE_EXTENSION; |
|
103 |
} else { |
|
104 |
$filename = WB_PATH.PAGES_DIRECTORY.'/'.page_filename($title).PAGE_EXTENSION; |
|
105 |
} |
|
106 |
} else { |
|
107 |
$parent_section = ''; |
|
108 |
$parent_titles = array_reverse(get_parent_titles($parent)); |
|
109 |
foreach($parent_titles AS $parent_title) |
|
110 |
{ |
|
111 |
$parent_section .= page_filename($parent_title).'/'; |
|
112 |
} |
|
113 |
if($parent_section == '/') { $parent_section = ''; } |
|
114 |
$link = '/'.$parent_section.page_filename($title); |
|
115 |
$filename = WB_PATH.PAGES_DIRECTORY.'/'.$parent_section.page_filename($title).PAGE_EXTENSION; |
|
116 |
make_dir(WB_PATH.PAGES_DIRECTORY.'/'.$parent_section); |
|
117 |
} |
|
118 |
|
|
119 |
// Check if a page with same page filename exists |
|
120 |
$get_same_page = $database->query("SELECT page_id FROM ".TABLE_PREFIX."pages WHERE link = '$link'"); |
|
121 |
if($get_same_page->numRows() > 0 OR file_exists(WB_PATH.PAGES_DIRECTORY.$link.PAGE_EXTENSION) OR file_exists(WB_PATH.PAGES_DIRECTORY.$link.'/')) |
|
122 |
{ |
|
123 |
$admin->print_error($MESSAGE['PAGES']['PAGE_EXISTS']); |
|
124 |
} |
|
125 |
|
|
126 |
// Include the ordering class |
|
127 |
require(WB_PATH.'/framework/class.order.php'); |
|
128 |
$order = new order(TABLE_PREFIX.'pages', 'position', 'page_id', 'parent'); |
|
129 |
// First clean order |
|
130 |
$order->clean($parent); |
|
131 |
// Get new order |
|
132 |
$position = $order->get_new($parent); |
|
133 |
|
|
134 |
// Work-out if the page parent (if selected) has a seperate template or language to the default |
|
135 |
$query_parent = $database->query("SELECT template, language FROM ".TABLE_PREFIX."pages WHERE page_id = '$parent'"); |
|
136 |
if($query_parent->numRows() > 0) |
|
137 |
{ |
|
138 |
$fetch_parent = $query_parent->fetchRow(); |
|
139 |
$template = $fetch_parent['template']; |
|
140 |
$language = $fetch_parent['language']; |
|
141 |
} else { |
|
142 |
$template = ''; |
|
143 |
$language = DEFAULT_LANGUAGE; |
|
144 |
} |
|
145 |
|
|
146 |
// Insert page into pages table |
|
147 |
$sql = 'INSERT INTO `'.TABLE_PREFIX.'pages` SET '; |
|
148 |
$sql .= '`parent` = '.$parent.', '; |
|
149 |
$sql .= '`target` = "_top", '; |
|
150 |
$sql .= '`page_title` = "'.$title.'", '; |
|
151 |
$sql .= '`menu_title` = "'.$title.'", '; |
|
152 |
$sql .= '`template` = "'.$template.'", '; |
|
153 |
$sql .= '`visibility` = "'.$visibility.'", '; |
|
154 |
$sql .= '`position` = '.$position.', '; |
|
155 |
$sql .= '`menu` = 1, '; |
|
156 |
$sql .= '`language` = "'.$language.'", '; |
|
157 |
$sql .= '`searching` = 1, '; |
|
158 |
$sql .= '`modified_when` = '.time().', '; |
|
159 |
$sql .= '`modified_by` = '.$admin->get_user_id().', '; |
|
160 |
$sql .= '`admin_groups` = "'.$admin_groups.'", '; |
|
161 |
$sql .= '`viewing_groups` = "'.$viewing_groups.'"'; |
|
162 |
|
|
163 |
$database->query($sql); |
|
164 |
/* |
|
165 |
$query = "INSERT INTO ".TABLE_PREFIX."pages |
|
166 |
(page_title,menu_title,parent,template,target,position,visibility,searching,menu,language,admin_groups,viewing_groups,modified_when,modified_by) VALUES |
|
167 |
('$title','$title','$parent','$template','_top','$position','$visibility','1','1','$language','$admin_groups','$viewing_groups','".time()."','".$admin->get_user_id()."')"; |
|
168 |
$database->query($query); |
|
169 |
*/ |
|
170 |
if($database->is_error()) |
|
171 |
{ |
|
172 |
$admin->print_error($database->get_error()); |
|
173 |
} |
|
174 |
|
|
175 |
// Get the page id |
|
176 |
$page_id = $database->get_one("SELECT LAST_INSERT_ID()"); |
|
177 |
|
|
178 |
// Work out level |
|
179 |
$level = level_count($page_id); |
|
180 |
// Work out root parent |
|
181 |
$root_parent = root_parent($page_id); |
|
182 |
// Work out page trail |
|
183 |
$page_trail = get_page_trail($page_id); |
|
184 |
|
|
185 |
// Update page with new level and link |
|
186 |
$sql = 'UPDATE `'.TABLE_PREFIX.'pages` SET '; |
|
187 |
$sql .= '`root_parent` = '.$root_parent.', '; |
|
188 |
$sql .= '`level` = '.$level.', '; |
|
189 |
$sql .= '`link` = "'.$link.'", '; |
|
190 |
$sql .= '`page_trail` = "'.$page_trail.'"'; |
|
191 |
$sql .= (defined('PAGE_LANGUAGES') && PAGE_LANGUAGES) |
|
192 |
&& $field_set |
|
193 |
&& ($language == DEFAULT_LANGUAGE) |
|
194 |
&& (file_exists(WB_PATH.'/modules/mod_multilingual/update_keys.php') |
|
195 |
) |
|
196 |
? ', `page_code` = '.(int)$page_id.' ' : ' '; |
|
197 |
$sql .= 'WHERE `page_id` = '.$page_id; |
|
198 |
$database->query($sql); |
|
199 |
/* |
|
200 |
$database->query("UPDATE ".TABLE_PREFIX."pages SET link = '$link', level = '$level', root_parent = '$root_parent', page_trail = '$page_trail' WHERE page_id = '$page_id'"); |
|
201 |
*/ |
|
202 |
if($database->is_error()) |
|
203 |
{ |
|
204 |
$admin->print_error($database->get_error()); |
|
205 |
} |
|
206 |
// Create a new file in the /pages dir |
|
207 |
create_access_file($filename, $page_id, $level); |
|
208 |
|
|
209 |
// add position 1 to new page |
|
210 |
$position = 1; |
|
211 |
|
|
212 |
// Add new record into the sections table |
|
213 |
$database->query("INSERT INTO ".TABLE_PREFIX."sections (page_id,position,module,block) VALUES ('$page_id','$position', '$module','1')"); |
|
214 |
|
|
215 |
// Get the section id |
|
216 |
$section_id = $database->get_one("SELECT LAST_INSERT_ID()"); |
|
217 |
|
|
218 |
// Include the selected modules add file if it exists |
|
219 |
if(file_exists(WB_PATH.'/modules/'.$module.'/add.php')) { |
|
220 |
require(WB_PATH.'/modules/'.$module.'/add.php'); |
|
221 |
} |
|
222 |
|
|
223 |
// Check if there is a db error, otherwise say successful |
|
224 |
if($database->is_error()) { |
|
225 |
$admin->print_error($database->get_error()); |
|
226 |
} else { |
|
227 |
$admin->print_success($MESSAGE['PAGES']['ADDED'], ADMIN_URL.'/pages/modify.php?page_id='.$page_id); |
|
228 |
} |
|
229 |
|
|
230 |
// Print admin footer |
|
231 |
$admin->print_footer(); |
|
232 |
|
|
178 | 233 |
?> |
179 | 234 |
Also available in: Unified diff
Tickets #932 change deprecated eregi functions
Tickets #948 fixed Multiple use of same parametrised droplet - parameter handling
Upgrade Droplets to Version 1.0.3
update some headerinfos
non existing pages, will be created if clicking save in page settings