1 |
238
|
stefan
|
<?php
|
2 |
|
|
|
3 |
|
|
// $Id$
|
4 |
|
|
|
5 |
|
|
/*
|
6 |
|
|
|
7 |
|
|
Website Baker Project <http://www.websitebaker.org/>
|
8 |
399
|
Ruebenwurz
|
Copyright (C) 2004-2007, Ryan Djurovich
|
9 |
238
|
stefan
|
|
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 |
|
|
/*
|
27 |
|
|
|
28 |
|
|
Website Baker functions file
|
29 |
|
|
This file contains general functions used in Website Baker
|
30 |
|
|
|
31 |
|
|
*/
|
32 |
|
|
|
33 |
|
|
// Stop this file from being accessed directly
|
34 |
|
|
if(!defined('WB_URL')) {
|
35 |
|
|
header('Location: ../index.php');
|
36 |
286
|
stefan
|
exit(0);
|
37 |
238
|
stefan
|
}
|
38 |
|
|
|
39 |
|
|
// Define that this file has been loaded
|
40 |
|
|
define('FUNCTIONS_FILE_LOADED', true);
|
41 |
|
|
|
42 |
|
|
// Function to remove a non-empty directory
|
43 |
|
|
function rm_full_dir($directory)
|
44 |
|
|
{
|
45 |
|
|
// If suplied dirname is a file then unlink it
|
46 |
|
|
if (is_file($directory)) {
|
47 |
|
|
return unlink($directory);
|
48 |
|
|
}
|
49 |
|
|
|
50 |
|
|
// Empty the folder
|
51 |
|
|
$dir = dir($directory);
|
52 |
|
|
while (false !== $entry = $dir->read()) {
|
53 |
|
|
// Skip pointers
|
54 |
|
|
if ($entry == '.' || $entry == '..') {
|
55 |
|
|
continue;
|
56 |
|
|
}
|
57 |
|
|
|
58 |
|
|
// Deep delete directories
|
59 |
|
|
if (is_dir("$directory/$entry")) {
|
60 |
|
|
rm_full_dir("$directory/$entry");
|
61 |
|
|
} else {
|
62 |
|
|
unlink("$directory/$entry");
|
63 |
|
|
}
|
64 |
|
|
}
|
65 |
|
|
|
66 |
|
|
// Now delete the folder
|
67 |
|
|
$dir->close();
|
68 |
|
|
return rmdir($directory);
|
69 |
|
|
}
|
70 |
|
|
|
71 |
|
|
// Function to open a directory and add to a dir list
|
72 |
|
|
function directory_list($directory) {
|
73 |
|
|
|
74 |
|
|
$list = array();
|
75 |
|
|
|
76 |
|
|
// Open the directory then loop through its contents
|
77 |
|
|
$dir = dir($directory);
|
78 |
|
|
while (false !== $entry = $dir->read()) {
|
79 |
|
|
// Skip pointers
|
80 |
|
|
if(substr($entry, 0, 1) == '.' || $entry == '.svn') {
|
81 |
|
|
continue;
|
82 |
|
|
}
|
83 |
|
|
// Add dir and contents to list
|
84 |
|
|
if (is_dir("$directory/$entry")) {
|
85 |
|
|
$list = array_merge($list, directory_list("$directory/$entry"));
|
86 |
|
|
$list[] = "$directory/$entry";
|
87 |
|
|
}
|
88 |
|
|
}
|
89 |
|
|
|
90 |
|
|
// Now return the list
|
91 |
|
|
return $list;
|
92 |
|
|
}
|
93 |
|
|
|
94 |
|
|
// Function to open a directory and add to a dir list
|
95 |
|
|
function chmod_directory_contents($directory, $file_mode) {
|
96 |
|
|
|
97 |
|
|
// Set the umask to 0
|
98 |
|
|
$umask = umask(0);
|
99 |
|
|
|
100 |
|
|
// Open the directory then loop through its contents
|
101 |
|
|
$dir = dir($directory);
|
102 |
|
|
while (false !== $entry = $dir->read()) {
|
103 |
|
|
// Skip pointers
|
104 |
|
|
if(substr($entry, 0, 1) == '.' || $entry == '.svn') {
|
105 |
|
|
continue;
|
106 |
|
|
}
|
107 |
|
|
// Chmod the sub-dirs contents
|
108 |
|
|
if(is_dir("$directory/$entry")) {
|
109 |
|
|
chmod_directory_contents("$directory/$entry", $file_mode);
|
110 |
|
|
}
|
111 |
|
|
change_mode($directory.'/'.$entry, 'file');
|
112 |
|
|
}
|
113 |
|
|
|
114 |
|
|
// Restore the umask
|
115 |
|
|
umask($umask);
|
116 |
|
|
|
117 |
|
|
}
|
118 |
|
|
|
119 |
|
|
// Function to open a directory and add to a file list
|
120 |
|
|
function file_list($directory, $skip = array()) {
|
121 |
|
|
|
122 |
|
|
$list = array();
|
123 |
|
|
$skip_file = false;
|
124 |
|
|
|
125 |
|
|
// Open the directory then loop through its contents
|
126 |
|
|
$dir = dir($directory);
|
127 |
|
|
while (false !== $entry = $dir->read()) {
|
128 |
|
|
// Skip pointers
|
129 |
|
|
if($entry == '.' || $entry == '..') {
|
130 |
|
|
$skip_file = true;
|
131 |
|
|
}
|
132 |
|
|
// Check if we to skip anything else
|
133 |
|
|
if($skip != array()) {
|
134 |
|
|
foreach($skip AS $skip_name) {
|
135 |
|
|
if($entry == $skip_name) {
|
136 |
|
|
$skip_file = true;
|
137 |
|
|
}
|
138 |
|
|
}
|
139 |
|
|
}
|
140 |
|
|
// Add dir and contents to list
|
141 |
|
|
if($skip_file != true AND is_file("$directory/$entry")) {
|
142 |
|
|
$list[] = "$directory/$entry";
|
143 |
|
|
}
|
144 |
|
|
|
145 |
|
|
// Reset the skip file var
|
146 |
|
|
$skip_file = false;
|
147 |
|
|
}
|
148 |
|
|
|
149 |
|
|
// Now delete the folder
|
150 |
|
|
return $list;
|
151 |
|
|
}
|
152 |
|
|
|
153 |
|
|
// Function to get a list of home folders not to show
|
154 |
|
|
function get_home_folders() {
|
155 |
|
|
global $database, $admin;
|
156 |
|
|
$home_folders = array();
|
157 |
|
|
// Only return home folders is this feature is enabled
|
158 |
325
|
stefan
|
// and user is not admin
|
159 |
|
|
if(HOME_FOLDERS AND ($_SESSION['GROUP_ID']!='1')) {
|
160 |
238
|
stefan
|
$query_home_folders = $database->query("SELECT home_folder FROM ".TABLE_PREFIX."users WHERE home_folder != '".$admin->get_home_folder()."'");
|
161 |
|
|
if($query_home_folders->numRows() > 0) {
|
162 |
|
|
while($folder = $query_home_folders->fetchRow()) {
|
163 |
|
|
$home_folders[$folder['home_folder']] = $folder['home_folder'];
|
164 |
|
|
}
|
165 |
|
|
}
|
166 |
|
|
function remove_home_subs($directory = '/', $home_folders) {
|
167 |
|
|
if($handle = opendir(WB_PATH.MEDIA_DIRECTORY.$directory)) {
|
168 |
|
|
// Loop through the dirs to check the home folders sub-dirs are not shown
|
169 |
|
|
while(false !== ($file = readdir($handle))) {
|
170 |
|
|
if(substr($file, 0, 1) != '.' AND $file != '.svn' AND $file != 'index.php') {
|
171 |
|
|
if(is_dir(WB_PATH.MEDIA_DIRECTORY.$directory.'/'.$file)) {
|
172 |
|
|
if($directory != '/') { $file = $directory.'/'.$file; } else { $file = '/'.$file; }
|
173 |
|
|
foreach($home_folders AS $hf) {
|
174 |
|
|
$hf_length = strlen($hf);
|
175 |
|
|
if($hf_length > 0) {
|
176 |
|
|
if(substr($file, 0, $hf_length+1) == $hf) {
|
177 |
|
|
$home_folders[$file] = $file;
|
178 |
|
|
}
|
179 |
|
|
}
|
180 |
|
|
}
|
181 |
|
|
$home_folders = remove_home_subs($file, $home_folders);
|
182 |
|
|
}
|
183 |
|
|
}
|
184 |
|
|
}
|
185 |
|
|
}
|
186 |
|
|
return $home_folders;
|
187 |
|
|
}
|
188 |
|
|
$home_folders = remove_home_subs('/', $home_folders);
|
189 |
|
|
}
|
190 |
|
|
return $home_folders;
|
191 |
|
|
}
|
192 |
|
|
|
193 |
|
|
// Function to create directories
|
194 |
|
|
function make_dir($dir_name, $dir_mode = OCTAL_DIR_MODE) {
|
195 |
|
|
if(!file_exists($dir_name)) {
|
196 |
|
|
$umask = umask(0);
|
197 |
|
|
mkdir($dir_name, $dir_mode);
|
198 |
|
|
umask($umask);
|
199 |
|
|
return true;
|
200 |
|
|
} else {
|
201 |
|
|
return false;
|
202 |
|
|
}
|
203 |
|
|
}
|
204 |
|
|
|
205 |
|
|
// Function to chmod files and directories
|
206 |
|
|
function change_mode($name) {
|
207 |
|
|
if(OPERATING_SYSTEM != 'windows') {
|
208 |
|
|
// Only chmod if os is not windows
|
209 |
|
|
if(is_dir($name)) {
|
210 |
|
|
$mode = OCTAL_DIR_MODE;
|
211 |
|
|
} else {
|
212 |
|
|
$mode = OCTAL_FILE_MODE;
|
213 |
|
|
}
|
214 |
|
|
if(file_exists($name)) {
|
215 |
|
|
$umask = umask(0);
|
216 |
|
|
chmod($name, $mode);
|
217 |
|
|
umask($umask);
|
218 |
|
|
return true;
|
219 |
|
|
} else {
|
220 |
|
|
return false;
|
221 |
|
|
}
|
222 |
|
|
} else {
|
223 |
|
|
return true;
|
224 |
|
|
}
|
225 |
|
|
}
|
226 |
|
|
|
227 |
|
|
// Function to figure out if a parent exists
|
228 |
|
|
function is_parent($page_id) {
|
229 |
|
|
global $database;
|
230 |
|
|
// Get parent
|
231 |
|
|
$query = $database->query("SELECT parent FROM ".TABLE_PREFIX."pages WHERE page_id = '$page_id'");
|
232 |
|
|
$fetch = $query->fetchRow();
|
233 |
|
|
// If parent isnt 0 return its ID
|
234 |
|
|
if($fetch['parent'] == '0') {
|
235 |
|
|
return false;
|
236 |
|
|
} else {
|
237 |
|
|
return $fetch['parent'];
|
238 |
|
|
}
|
239 |
|
|
}
|
240 |
|
|
|
241 |
|
|
// Function to work out level
|
242 |
|
|
function level_count($page_id) {
|
243 |
|
|
global $database;
|
244 |
|
|
// Get page parent
|
245 |
|
|
$query_page = $database->query("SELECT parent FROM ".TABLE_PREFIX."pages WHERE page_id = '$page_id' LIMIT 1");
|
246 |
|
|
$fetch_page = $query_page->fetchRow();
|
247 |
|
|
$parent = $fetch_page['parent'];
|
248 |
|
|
if($parent > 0) {
|
249 |
|
|
// Get the level of the parent
|
250 |
|
|
$query_parent = $database->query("SELECT level FROM ".TABLE_PREFIX."pages WHERE page_id = '$parent' LIMIT 1");
|
251 |
|
|
$fetch_parent = $query_parent->fetchRow();
|
252 |
|
|
$level = $fetch_parent['level'];
|
253 |
|
|
return $level+1;
|
254 |
|
|
} else {
|
255 |
|
|
return 0;
|
256 |
|
|
}
|
257 |
|
|
}
|
258 |
|
|
|
259 |
|
|
// Function to work out root parent
|
260 |
|
|
function root_parent($page_id) {
|
261 |
|
|
global $database;
|
262 |
|
|
// Get page details
|
263 |
|
|
$query_page = $database->query("SELECT parent,level FROM ".TABLE_PREFIX."pages WHERE page_id = '$page_id' LIMIT 1");
|
264 |
|
|
$fetch_page = $query_page->fetchRow();
|
265 |
|
|
$parent = $fetch_page['parent'];
|
266 |
|
|
$level = $fetch_page['level'];
|
267 |
|
|
if($level == 1) {
|
268 |
|
|
return $parent;
|
269 |
|
|
} elseif($parent == 0) {
|
270 |
400
|
Ruebenwurz
|
return $page_id;
|
271 |
238
|
stefan
|
} else {
|
272 |
|
|
// Figure out what the root parents id is
|
273 |
|
|
$parent_ids = array_reverse(get_parent_ids($page_id));
|
274 |
|
|
return $parent_ids[0];
|
275 |
|
|
}
|
276 |
|
|
}
|
277 |
|
|
|
278 |
|
|
// Function to get page title
|
279 |
|
|
function get_page_title($id) {
|
280 |
|
|
global $database;
|
281 |
|
|
// Get title
|
282 |
|
|
$query = $database->query("SELECT page_title FROM ".TABLE_PREFIX."pages WHERE page_id = '$id'");
|
283 |
|
|
$fetch = $query->fetchRow();
|
284 |
|
|
// Return title
|
285 |
|
|
return $fetch['page_title'];
|
286 |
|
|
}
|
287 |
|
|
|
288 |
|
|
// Function to get a pages menu title
|
289 |
|
|
function get_menu_title($id) {
|
290 |
|
|
// Connect to the database
|
291 |
|
|
$database = new database();
|
292 |
|
|
// Get title
|
293 |
|
|
$query = $database->query("SELECT menu_title FROM ".TABLE_PREFIX."pages WHERE page_id = '$id'");
|
294 |
|
|
$fetch = $query->fetchRow();
|
295 |
|
|
// Return title
|
296 |
|
|
return $fetch['menu_title'];
|
297 |
|
|
}
|
298 |
|
|
|
299 |
|
|
// Function to get all parent page titles
|
300 |
|
|
function get_parent_titles($parent_id) {
|
301 |
|
|
$titles[] = get_menu_title($parent_id);
|
302 |
|
|
if(is_parent($parent_id) != false) {
|
303 |
|
|
$parent_titles = get_parent_titles(is_parent($parent_id));
|
304 |
|
|
$titles = array_merge($titles, $parent_titles);
|
305 |
|
|
}
|
306 |
|
|
return $titles;
|
307 |
|
|
}
|
308 |
|
|
|
309 |
|
|
// Function to get all parent page id's
|
310 |
|
|
function get_parent_ids($parent_id) {
|
311 |
|
|
$ids[] = $parent_id;
|
312 |
|
|
if(is_parent($parent_id) != false) {
|
313 |
|
|
$parent_ids = get_parent_ids(is_parent($parent_id));
|
314 |
|
|
$ids = array_merge($ids, $parent_ids);
|
315 |
|
|
}
|
316 |
|
|
return $ids;
|
317 |
|
|
}
|
318 |
|
|
|
319 |
|
|
// Function to genereate page trail
|
320 |
|
|
function get_page_trail($page_id) {
|
321 |
|
|
return implode(',', array_reverse(get_parent_ids($page_id)));
|
322 |
|
|
}
|
323 |
|
|
|
324 |
|
|
// Function to get all sub pages id's
|
325 |
|
|
function get_subs($parent, $subs) {
|
326 |
|
|
// Connect to the database
|
327 |
|
|
$database = new database();
|
328 |
|
|
// Get id's
|
329 |
|
|
$query = $database->query("SELECT page_id FROM ".TABLE_PREFIX."pages WHERE parent = '$parent'");
|
330 |
|
|
if($query->numRows() > 0) {
|
331 |
|
|
while($fetch = $query->fetchRow()) {
|
332 |
|
|
$subs[] = $fetch['page_id'];
|
333 |
|
|
// Get subs of this sub
|
334 |
|
|
$subs = get_subs($fetch['page_id'], $subs);
|
335 |
|
|
}
|
336 |
|
|
}
|
337 |
|
|
// Return subs array
|
338 |
|
|
return $subs;
|
339 |
|
|
}
|
340 |
|
|
|
341 |
442
|
Ruebenwurz
|
// Function as replecement for php's htmlspecialchars()
|
342 |
|
|
function my_htmlspecialchars($string) {
|
343 |
468
|
Ruebenwurz
|
$string = strtr($string, array("<"=>"<", ">"=>">", "\""=>""", "\'"=>"'"));
|
344 |
442
|
Ruebenwurz
|
return($string);
|
345 |
|
|
}
|
346 |
|
|
|
347 |
|
|
// Function to convert a string from $from- to $to-encoding, using mysql
|
348 |
|
|
function my_mysql_iconv($string, $from, $to) {
|
349 |
|
|
// keep current character set values:
|
350 |
|
|
$character_set_database = mysql_result(mysql_query("SELECT @@character_set_client"),0,0);
|
351 |
|
|
$character_set_results = mysql_result(mysql_query("SELECT @@character_set_results"),0,0);
|
352 |
|
|
$collation_results = mysql_result(mysql_query("SELECT @@collation_connection"),0,0);
|
353 |
|
|
mysql_query("SET character_set_client=$from");
|
354 |
|
|
mysql_query("SET character_set_results=$to");
|
355 |
|
|
mysql_query("SET collation_connection=utf8_unicode_ci");
|
356 |
|
|
$string_escaped = mysql_real_escape_string($string);
|
357 |
|
|
$converted_string = mysql_result(mysql_query("SELECT '$string_escaped'"),0,0);
|
358 |
|
|
// restore previous character set values:
|
359 |
|
|
mysql_query("SET character_set_client=$character_set_database");
|
360 |
|
|
mysql_query("SET character_set_results=$character_set_results");
|
361 |
|
|
mysql_query("SET collation_connection=$collation_results");
|
362 |
|
|
return $converted_string;
|
363 |
|
|
}
|
364 |
|
|
|
365 |
455
|
Ruebenwurz
|
// Function as wrapper for mb_convert_encoding
|
366 |
461
|
Ruebenwurz
|
// converts $charset_in to $charset_out or
|
367 |
|
|
// UTF-8 to HTML-ENTITIES or HTML-ENTITIES to UTF-8
|
368 |
455
|
Ruebenwurz
|
function mb_convert_encoding_wrapper($string, $charset_out, $charset_in) {
|
369 |
464
|
Ruebenwurz
|
if ($charset_out == $charset_in) {
|
370 |
|
|
return $string;
|
371 |
|
|
}
|
372 |
461
|
Ruebenwurz
|
// try mb_convert_encoding(). This can handle to or from HTML-ENTITIES, too
|
373 |
455
|
Ruebenwurz
|
if (function_exists('mb_convert_encoding')) {
|
374 |
461
|
Ruebenwurz
|
// there's no GB2312 or ISO-8859-11 encoding in php's mb_* functions
|
375 |
|
|
if ($charset_in=='ISO-8859-11' || $charset_in=='GB2312') {
|
376 |
|
|
if (function_exists('iconv')) {
|
377 |
|
|
$string = iconv($charset_in, 'UTF-8', $string);
|
378 |
455
|
Ruebenwurz
|
}
|
379 |
461
|
Ruebenwurz
|
else {
|
380 |
|
|
if ($charset_in == 'GB2312') {
|
381 |
|
|
$string=my_mysql_iconv($string, 'gb2312', 'utf8');
|
382 |
|
|
} else {
|
383 |
|
|
$string=my_mysql_iconv($string, 'tis620', 'utf8');
|
384 |
|
|
}
|
385 |
|
|
}
|
386 |
|
|
$charset_in='UTF-8';
|
387 |
|
|
if ($charset_out == 'UTF-8') {
|
388 |
|
|
return $string;
|
389 |
|
|
}
|
390 |
455
|
Ruebenwurz
|
}
|
391 |
461
|
Ruebenwurz
|
if ($charset_out=='ISO-8859-11' || $charset_out=='GB2312') {
|
392 |
|
|
$string=mb_convert_encoding($string, 'UTF-8', $charset_in);
|
393 |
|
|
if (function_exists('iconv')) {
|
394 |
|
|
$string = iconv('UTF-8', $charset_out, $string);
|
395 |
455
|
Ruebenwurz
|
}
|
396 |
461
|
Ruebenwurz
|
else {
|
397 |
|
|
if ($charset_out == 'GB2312') {
|
398 |
|
|
$string=my_mysql_iconv($string, 'utf8', 'gb2312');
|
399 |
|
|
} else {
|
400 |
|
|
$string=my_mysql_iconv($string, 'utf8', 'tis620');
|
401 |
455
|
Ruebenwurz
|
}
|
402 |
|
|
}
|
403 |
461
|
Ruebenwurz
|
} else {
|
404 |
468
|
Ruebenwurz
|
$string = strtr($string, array("<"=>"&_lt;", ">"=>"&_gt;", "&"=>"&_amp;", """=>"&_quot;", "'"=>"&_#039;"));
|
405 |
461
|
Ruebenwurz
|
$string=mb_convert_encoding($string, $charset_out, $charset_in);
|
406 |
468
|
Ruebenwurz
|
$string = strtr($string, array("&_lt;"=>"<", "&_gt;"=>">", "&_amp;"=>"&", "&_quot;"=>""", "&_#039;"=>"'"));
|
407 |
455
|
Ruebenwurz
|
}
|
408 |
461
|
Ruebenwurz
|
return $string;
|
409 |
455
|
Ruebenwurz
|
}
|
410 |
461
|
Ruebenwurz
|
|
411 |
|
|
// try iconv(). This can't handle to or from HTML-ENTITIES.
|
412 |
|
|
if (function_exists('iconv') && $charset_out!='HTML-ENTITIES' && $charset_in!='HTML-ENTITIES' ) {
|
413 |
|
|
$string = iconv($charset_in, $charset_out, $string);
|
414 |
|
|
return $string;
|
415 |
|
|
}
|
416 |
|
|
|
417 |
|
|
// do the UTF-8->HTML-ENTITIES or HTML-ENTITIES->UTF-8 translation
|
418 |
|
|
if (($charset_in=='HTML-ENTITIES' && $charset_out=='UTF-8') || ($charset_in=='UTF-8' && $charset_out=='HTML-ENTITIES')) {
|
419 |
|
|
$named_to_numbered_entities=array(
|
420 |
|
|
' '=>' ','¡'=>'¡','¢'=>'¢','£'=>'£','¤'=>'¤',
|
421 |
|
|
'¥'=>'¥','¦'=>'¦','§'=>'§','¨'=>'¨','ª'=>'ª',
|
422 |
|
|
'«'=>'«','¬'=>'¬','­'=>'­','®'=>'®','¯'=>'¯',
|
423 |
|
|
'°'=>'°','±'=>'±','²'=>'²','³'=>'³','´'=>'´',
|
424 |
|
|
'µ'=>'µ','¶'=>'¶','·'=>'·','¸'=>'¸','¹'=>'¹',
|
425 |
|
|
'º'=>'º','»'=>'»','¼'=>'¼','½'=>'½','¾'=>'¾',
|
426 |
|
|
'¿'=>'¿','÷'=>'÷','∅'=>'∅','€'=>'€',
|
427 |
|
|
'Á'=>'Á','á'=>'á','Â'=>'Â',
|
428 |
|
|
'â'=>'â','Æ'=>'Æ','æ'=>'æ','À'=>'À','à'=>'à',
|
429 |
|
|
'Å'=>'Å','å'=>'å','Ã'=>'Ã','ã'=>'ã','Ä'=>'Ä',
|
430 |
|
|
'ä'=>'ä','Ç'=>'Ç','ç'=>'ç','É'=>'É','é'=>'é',
|
431 |
|
|
'Ê'=>'Ê','ê'=>'ê','È'=>'È','è'=>'è','Ë'=>'Ë',
|
432 |
|
|
'ë'=>'ë','Í'=>'Í','í'=>'í','Î'=>'Î','î'=>'î',
|
433 |
|
|
'Ì'=>'Ì','ì'=>'ì','Ï'=>'Ï','ï'=>'ï','Ñ'=>'Ñ',
|
434 |
|
|
'ñ'=>'ñ','Ó'=>'Ó','ó'=>'ó','Ô'=>'Ô','ô'=>'ô',
|
435 |
|
|
'Œ'=>'Œ','œ'=>'œ','Ò'=>'Ò','ò'=>'ò','Õ'=>'Õ',
|
436 |
|
|
'õ'=>'õ','Ö'=>'Ö','ö'=>'ö','Š'=>'Š','š'=>'š',
|
437 |
|
|
'ß'=>'ß','Ú'=>'Ú','ú'=>'ú','Û'=>'Û','û'=>'û',
|
438 |
|
|
'Ù'=>'Ù','ù'=>'ù','Ü'=>'Ü','ü'=>'ü','Ý'=>'Ý',
|
439 |
|
|
'ý'=>'ý','Ÿ'=>'Ÿ','ÿ'=>'ÿ','©'=>'©','®'=>'®',
|
440 |
|
|
'Ð'=>'Ð','×'=>'×','Ø'=>'Ø','Þ'=>'Þ','ð'=>'ð',
|
441 |
|
|
'ø'=>'ø','þ'=>'þ');
|
442 |
|
|
$numbered_to_named_entities=array('Á'=>'Á','á'=>'á','Â'=>'Â',
|
443 |
|
|
' '=>' ','¡'=>'¡','¢'=>'¢','£'=>'£','¤'=>'¤',
|
444 |
|
|
'¥'=>'¥','¦'=>'¦','§'=>'§','¨'=>'¨','ª'=>'ª',
|
445 |
|
|
'«'=>'«','¬'=>'¬','­'=>'­','®'=>'®','¯'=>'¯',
|
446 |
|
|
'°'=>'°','±'=>'±','²'=>'²','³'=>'³','´'=>'´',
|
447 |
|
|
'µ'=>'µ','¶'=>'¶','·'=>'·','¸'=>'¸','¹'=>'¹',
|
448 |
|
|
'º'=>'º','»'=>'»','¼'=>'¼','½'=>'½','¾'=>'¾',
|
449 |
|
|
'¿'=>'¿','÷'=>'÷','∅'=>'∅','€'=>'€',
|
450 |
|
|
'â'=>'â','Æ'=>'Æ','æ'=>'æ','À'=>'À','à'=>'à',
|
451 |
|
|
'Å'=>'Å','å'=>'å','Ã'=>'Ã','ã'=>'ã','Ä'=>'Ä',
|
452 |
|
|
'ä'=>'ä','Ç'=>'Ç','ç'=>'ç','É'=>'É','é'=>'é',
|
453 |
|
|
'Ê'=>'Ê','ê'=>'ê','È'=>'È','è'=>'è','Ë'=>'Ë',
|
454 |
|
|
'ë'=>'ë','Í'=>'Í','í'=>'í','Î'=>'Î','î'=>'î',
|
455 |
|
|
'Ì'=>'Ì','ì'=>'ì','Ï'=>'Ï','ï'=>'ï','Ñ'=>'Ñ',
|
456 |
|
|
'ñ'=>'ñ','Ó'=>'Ó','ó'=>'ó','Ô'=>'Ô','ô'=>'ô',
|
457 |
|
|
'Œ'=>'Œ','œ'=>'œ','Ò'=>'Ò','ò'=>'ò','Õ'=>'Õ',
|
458 |
|
|
'õ'=>'õ','Ö'=>'Ö','ö'=>'ö','Š'=>'Š','š'=>'š',
|
459 |
|
|
'ß'=>'ß','Ú'=>'Ú','ú'=>'ú','Û'=>'Û','û'=>'û',
|
460 |
|
|
'Ù'=>'Ù','ù'=>'ù','Ü'=>'Ü','ü'=>'ü','Ý'=>'Ý',
|
461 |
|
|
'ý'=>'ý','Ÿ'=>'Ÿ','ÿ'=>'ÿ','©'=>'©','®'=>'®',
|
462 |
|
|
'Ð'=>'Ð','×'=>'×','Ø'=>'Ø','Þ'=>'Þ','ð'=>'ð',
|
463 |
|
|
'ø'=>'ø','þ'=>'þ');
|
464 |
|
|
if ($charset_in == 'HTML-ENTITIES') {
|
465 |
|
|
$string = strtr($string, $named_to_numbered_entities);
|
466 |
|
|
$string = preg_replace("/&#([0-9]+);/e", "code_to_utf8($1)", $string);
|
467 |
|
|
}
|
468 |
|
|
elseif ($charset_out == 'HTML-ENTITIES') {
|
469 |
|
|
$string = preg_replace("/&#([0-9]+);/e", "code_to_utf8($1)", $string);
|
470 |
|
|
$char = "";
|
471 |
|
|
while (strlen($string) > 0) {
|
472 |
|
|
preg_match("/^(.)(.*)$/su", $string, $match);
|
473 |
|
|
if (strlen($match[1]) > 1) {
|
474 |
|
|
$char .= "&#".uniord($match[1]).";";
|
475 |
|
|
} else $char .= $match[1];
|
476 |
|
|
$string = $match[2];
|
477 |
|
|
}
|
478 |
|
|
$string = $char;
|
479 |
|
|
$string = strtr($string, $numbered_to_named_entities);
|
480 |
|
|
}
|
481 |
|
|
return $string;
|
482 |
|
|
}
|
483 |
|
|
|
484 |
|
|
// mb_convert_encoding() and iconv() aren't available, so use my_mysql_iconv()
|
485 |
|
|
if ($charset_in == 'ISO-8859-1') { $mysqlcharset_from = 'latin1'; }
|
486 |
|
|
elseif ($charset_in == 'ISO-8859-2') { $mysqlcharset_from = 'latin2'; }
|
487 |
|
|
elseif ($charset_in == 'ISO-8859-3') { $mysqlcharset_from = 'latin1'; }
|
488 |
|
|
elseif ($charset_in == 'ISO-8859-4') { $mysqlcharset_from = 'latin7'; }
|
489 |
|
|
elseif ($charset_in == 'ISO-8859-5') { $string = convert_cyr_string ($string, "iso8859-5", "windows-1251" ); $mysqlcharset_from = 'cp1251'; }
|
490 |
|
|
elseif ($charset_in == 'ISO-8859-6') { $mysqlcharset_from = ''; } //?
|
491 |
|
|
elseif ($charset_in == 'ISO-8859-7') { $mysqlcharset_from = 'greek'; }
|
492 |
|
|
elseif ($charset_in == 'ISO-8859-8') { $mysqlcharset_from = 'hebrew'; }
|
493 |
|
|
elseif ($charset_in == 'ISO-8859-9') { $mysqlcharset_from = 'latin5'; }
|
494 |
|
|
elseif ($charset_in == 'ISO-8859-10') { $mysqlcharset_from = 'latin1'; }
|
495 |
|
|
elseif ($charset_in == 'BIG5') { $mysqlcharset_from = 'big5'; }
|
496 |
|
|
elseif ($charset_in == 'ISO-2022-JP') { $mysqlcharset_from = ''; } //?
|
497 |
|
|
elseif ($charset_in == 'ISO-2022-KR') { $mysqlcharset_from = ''; } //?
|
498 |
|
|
elseif ($charset_in == 'GB2312') { $mysqlcharset_from = 'gb2312'; }
|
499 |
|
|
elseif ($charset_in == 'ISO-8859-11') { $mysqlcharset_from = 'tis620'; }
|
500 |
|
|
elseif ($charset_in == 'UTF-8') { $mysqlcharset_from = 'utf8'; }
|
501 |
|
|
else { $mysqlcharset_from = 'latin1'; }
|
502 |
|
|
|
503 |
|
|
if ($charset_out == 'ISO-8859-1') { $mysqlcharset_to = 'latin1'; }
|
504 |
|
|
elseif ($charset_out == 'ISO-8859-2') { $mysqlcharset_to = 'latin2'; }
|
505 |
|
|
elseif ($charset_out == 'ISO-8859-3') { $mysqlcharset_to = 'latin1'; }
|
506 |
|
|
elseif ($charset_out == 'ISO-8859-4') { $mysqlcharset_to = 'latin7'; }
|
507 |
|
|
elseif ($charset_out == 'ISO-8859-5') { $mysqlcharset_to = 'cp1251'; } // use convert_cyr_string afterwards
|
508 |
|
|
elseif ($charset_out == 'ISO-8859-6') { $mysqlcharset_to = ''; } //?
|
509 |
|
|
elseif ($charset_out == 'ISO-8859-7') { $mysqlcharset_to = 'greek'; }
|
510 |
|
|
elseif ($charset_out == 'ISO-8859-8') { $mysqlcharset_to = 'hebrew'; }
|
511 |
|
|
elseif ($charset_out == 'ISO-8859-9') { $mysqlcharset_to = 'latin5'; }
|
512 |
|
|
elseif ($charset_out == 'ISO-8859-10') { $mysqlcharset_to = 'latin1'; }
|
513 |
|
|
elseif ($charset_out == 'BIG5') { $mysqlcharset_to = 'big5'; }
|
514 |
|
|
elseif ($charset_out == 'ISO-2022-JP') { $mysqlcharset_to = ''; } //?
|
515 |
|
|
elseif ($charset_out == 'ISO-2022-KR') { $mysqlcharset_to = ''; } //?
|
516 |
|
|
elseif ($charset_out == 'GB2312') { $mysqlcharset_to = 'gb2312'; }
|
517 |
|
|
elseif ($charset_out == 'ISO-8859-11') { $mysqlcharset_to = 'tis620'; }
|
518 |
|
|
elseif ($charset_out == 'UTF-8') { $mysqlcharset_to = 'utf8'; }
|
519 |
|
|
else { $mysqlcharset_to = 'latin1'; }
|
520 |
|
|
|
521 |
|
|
if ($mysqlcharset_from!="" && $mysqlcharset_to!="" && $mysqlcharset_from!=$mysqlcharset_to) {
|
522 |
|
|
$string=my_mysql_iconv($string, $mysqlcharset_from, $mysqlcharset_to);
|
523 |
|
|
if ($mysqlcharset_to == 'cp1251') {
|
524 |
|
|
$string = convert_cyr_string ($string, "windows-1251", "iso-8859-5" );
|
525 |
|
|
}
|
526 |
|
|
return($string);
|
527 |
|
|
}
|
528 |
|
|
|
529 |
|
|
// $string is unchanged. This will happen if we have to deal with ISO-8859-6 or ISO-2022-JP or -KR
|
530 |
|
|
// and mbstring _and_ iconv aren't available.
|
531 |
|
|
return $string;
|
532 |
455
|
Ruebenwurz
|
}
|
533 |
|
|
// support-function for mb_convert_encoding_wrapper()
|
534 |
|
|
function uniord($c) {
|
535 |
|
|
$ud = 0;
|
536 |
|
|
if (ord($c{0}) >= 0 && ord($c{0}) <= 127) $ud = ord($c{0});
|
537 |
|
|
if (ord($c{0}) >= 192 && ord($c{0}) <= 223) $ud = (ord($c{0})-192)*64 + (ord($c{1})-128);
|
538 |
|
|
if (ord($c{0}) >= 224 && ord($c{0}) <= 239) $ud = (ord($c{0})-224)*4096 + (ord($c{1})-128)*64 + (ord($c{2})-128);
|
539 |
|
|
if (ord($c{0}) >= 240 && ord($c{0}) <= 247) $ud = (ord($c{0})-240)*262144 + (ord($c{1})-128)*4096 + (ord($c{2})-128)*64 + (ord($c{3})-128);
|
540 |
|
|
if (ord($c{0}) >= 248 && ord($c{0}) <= 251) $ud = (ord($c{0})-248)*16777216 + (ord($c{1})-128)*262144 + (ord($c{2})-128)*4096 + (ord($c{3})-128)*64 + (ord($c{4})-128);
|
541 |
|
|
if (ord($c{0}) >= 252 && ord($c{0}) <= 253) $ud = (ord($c{0})-252)*1073741824 + (ord($c{1})-128)*16777216 + (ord($c{2})-128)*262144 + (ord($c{3})-128)*4096 + (ord($c{4})-128)*64 + (ord($c{5})-128);
|
542 |
|
|
if (ord($c{0}) >= 254 && ord($c{0}) <= 255) $ud = false; // error
|
543 |
|
|
return $ud;
|
544 |
|
|
}
|
545 |
|
|
// support-function for mb_convert_encoding_wrapper()
|
546 |
|
|
function code_to_utf8($num) {
|
547 |
|
|
if ($num <= 0x7F) {
|
548 |
|
|
return chr($num);
|
549 |
|
|
} elseif ($num <= 0x7FF) {
|
550 |
|
|
return chr(($num >> 6) + 192) . chr(($num & 63) + 128);
|
551 |
|
|
} elseif ($num <= 0xFFFF) {
|
552 |
|
|
return chr(($num >> 12) + 224) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128);
|
553 |
|
|
} elseif ($num <= 0x1FFFFF) {
|
554 |
|
|
return chr(($num >> 18) + 240) . chr((($num >> 12) & 63) + 128) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128);
|
555 |
|
|
}
|
556 |
|
|
return " ";
|
557 |
|
|
}
|
558 |
|
|
|
559 |
445
|
Ruebenwurz
|
// Function to convert a string from mixed html-entities/umlauts to pure utf-8-umlauts
|
560 |
|
|
function string_to_utf8($string, $charset=DEFAULT_CHARSET) {
|
561 |
|
|
$charset = strtoupper($charset);
|
562 |
|
|
if ($charset == '') { $charset = 'ISO-8859-1'; }
|
563 |
|
|
|
564 |
461
|
Ruebenwurz
|
if (!is_UTF8($string)) {
|
565 |
455
|
Ruebenwurz
|
$string=mb_convert_encoding_wrapper($string, 'UTF-8', $charset);
|
566 |
442
|
Ruebenwurz
|
}
|
567 |
464
|
Ruebenwurz
|
// check if we really get UTF-8. We don't get UTF-8 if charset is ISO-8859-6 or ISO-2022-JP/KR
|
568 |
|
|
// and mb_string AND iconv aren't available.
|
569 |
461
|
Ruebenwurz
|
if (is_UTF8($string)) {
|
570 |
|
|
$string=mb_convert_encoding_wrapper($string, 'HTML-ENTITIES', 'UTF-8');
|
571 |
|
|
$string=mb_convert_encoding_wrapper($string, 'UTF-8', 'HTML-ENTITIES');
|
572 |
|
|
} else {
|
573 |
464
|
Ruebenwurz
|
// nothing we can do here :-(
|
574 |
461
|
Ruebenwurz
|
}
|
575 |
442
|
Ruebenwurz
|
return($string);
|
576 |
|
|
}
|
577 |
|
|
|
578 |
461
|
Ruebenwurz
|
// function to check if a string is UTF-8
|
579 |
464
|
Ruebenwurz
|
function is_UTF8 ($str) {
|
580 |
|
|
if (strlen($str) < 4000) {
|
581 |
|
|
// see http://bugs.php.net/bug.php?id=24460 and http://bugs.php.net/bug.php?id=27070 and http://ilia.ws/archives/5-Top-10-ways-to-crash-PHP.html for this.
|
582 |
|
|
// 4000 works for me ...
|
583 |
|
|
return preg_match('/^(?:[\x09\x0A\x0D\x20-\x7E]|[\xC2-\xDF][\x80-\xBF]|\xE0[\xA0-\xBF][\x80-\xBF]|[\xE1-\xEC\xEE\xEF][\x80-\xBF]{2}|\xED[\x80-\x9F][\x80-\xBF]|\xF0[\x90-\xBF][\x80-\xBF]{2}|[\xF1-\xF3][\x80-\xBF]{3}|\xF4[\x80-\x8F][\x80-\xBF]{2})*$/s', $str);
|
584 |
|
|
} else {
|
585 |
|
|
$isUTF8 = true;
|
586 |
|
|
while($str{0}) {
|
587 |
|
|
if (preg_match("/^[\x09\x0A\x0D\x20-\x7E]/", $str)) { $str = substr($str, 1); continue; }
|
588 |
|
|
if (preg_match("/^[\xC2-\xDF][\x80-\xBF]/", $str)) { $str = substr($str, 2); continue; }
|
589 |
|
|
if (preg_match("/^\xE0[\xA0-\xBF][\x80-\xBF]/", $str)) { $str = substr($str, 3); continue; }
|
590 |
|
|
if (preg_match("/^[\xE1-\xEC\xEE\xEF][\x80-\xBF]{2}/", $str)) { $str = substr($str, 3); continue; }
|
591 |
|
|
if (preg_match("/^\xED[\x80-\x9F][\x80-\xBF]/", $str)) { $str = substr($str, 3); continue; }
|
592 |
|
|
if (preg_match("/^\xF0[\x90-\xBF][\x80-\xBF]{2}/", $str)) { $str = substr($str, 4); continue; }
|
593 |
|
|
if (preg_match("/^[\xF1-\xF3][\x80-\xBF]{3}/", $str)) { $str = substr($str, 4); continue; }
|
594 |
|
|
if (preg_match("/^\xF4[\x80-\x8F][\x80-\xBF]{2}/", $str)) { $str = substr($str, 4); continue; }
|
595 |
|
|
if (preg_match("/^$/", $str)) { break; }
|
596 |
|
|
$isUTF8 = false;
|
597 |
|
|
break;
|
598 |
|
|
}
|
599 |
|
|
return ($isUTF8);
|
600 |
|
|
}
|
601 |
461
|
Ruebenwurz
|
}
|
602 |
|
|
|
603 |
445
|
Ruebenwurz
|
// Function to convert a string from mixed html-entities/umlauts to pure $charset_out-umlauts
|
604 |
|
|
function entities_to_umlauts($string, $charset_out=DEFAULT_CHARSET, $convert_htmlspecialchars=0) {
|
605 |
|
|
$charset_out = strtoupper($charset_out);
|
606 |
461
|
Ruebenwurz
|
if ($charset_out == '') { $charset_out = 'ISO-8859-1'; }
|
607 |
445
|
Ruebenwurz
|
$string = string_to_utf8($string);
|
608 |
461
|
Ruebenwurz
|
if($charset_out!='UTF-8' && is_UTF8($string)) {
|
609 |
|
|
$string=mb_convert_encoding_wrapper($string, $charset_out, 'UTF-8');
|
610 |
|
|
}
|
611 |
445
|
Ruebenwurz
|
return($string);
|
612 |
|
|
}
|
613 |
|
|
|
614 |
|
|
// Function to convert a string from mixed html-entitites/$charset_in-umlauts to pure html-entities
|
615 |
468
|
Ruebenwurz
|
function umlauts_to_entities($string, $charset_in=DEFAULT_CHARSET, $convert_htmlspecialchars=0) {
|
616 |
445
|
Ruebenwurz
|
$charset_in = strtoupper($charset_in);
|
617 |
461
|
Ruebenwurz
|
if ($charset_in == "") { $charset_in = 'ISO-8859-1'; }
|
618 |
445
|
Ruebenwurz
|
$string = string_to_utf8($string, $charset_in);
|
619 |
461
|
Ruebenwurz
|
if (is_UTF8($string)) {
|
620 |
|
|
$string=mb_convert_encoding_wrapper($string,'HTML-ENTITIES','UTF-8');
|
621 |
|
|
}
|
622 |
442
|
Ruebenwurz
|
return($string);
|
623 |
|
|
}
|
624 |
|
|
|
625 |
445
|
Ruebenwurz
|
// translate any latin/greek/cyrillic html-entities to their plain 7bit equivalents
|
626 |
461
|
Ruebenwurz
|
// and numbered-entities into hex
|
627 |
442
|
Ruebenwurz
|
function entities_to_7bit($string) {
|
628 |
|
|
require(WB_PATH.'/framework/convert.php');
|
629 |
|
|
$string = strtr($string, $conversion_array);
|
630 |
461
|
Ruebenwurz
|
$string = preg_replace('/&#([0-9]+);/e', "dechex('$1')", $string);
|
631 |
442
|
Ruebenwurz
|
return($string);
|
632 |
|
|
}
|
633 |
|
|
|
634 |
238
|
stefan
|
// Function to convert a page title to a page filename
|
635 |
|
|
function page_filename($string) {
|
636 |
442
|
Ruebenwurz
|
$string = entities_to_7bit(umlauts_to_entities($string));
|
637 |
238
|
stefan
|
// Now replace spaces with page spcacer
|
638 |
|
|
$string = str_replace(' ', PAGE_SPACER, $string);
|
639 |
|
|
// Now remove all bad characters
|
640 |
|
|
$bad = array(
|
641 |
|
|
'\'', /* / */ '"', /* " */ '<', /* < */ '>', /* > */
|
642 |
|
|
'{', /* { */ '}', /* } */ '[', /* [ */ ']', /* ] */ '`', /* ` */
|
643 |
|
|
'!', /* ! */ '@', /* @ */ '#', /* # */ '$', /* $ */ '%', /* % */
|
644 |
|
|
'^', /* ^ */ '&', /* & */ '*', /* * */ '(', /* ( */ ')', /* ) */
|
645 |
|
|
'=', /* = */ '+', /* + */ '|', /* | */ '/', /* / */ '\\', /* \ */
|
646 |
|
|
';', /* ; */ ':', /* : */ ',', /* , */ '?' /* ? */
|
647 |
|
|
);
|
648 |
|
|
$string = str_replace($bad, '', $string);
|
649 |
|
|
// Now convert to lower-case
|
650 |
|
|
$string = strtolower($string);
|
651 |
|
|
// Now remove multiple page spacers
|
652 |
|
|
$string = str_replace(PAGE_SPACER.PAGE_SPACER, PAGE_SPACER, $string);
|
653 |
|
|
// Clean any page spacers at the end of string
|
654 |
|
|
$string = str_replace(PAGE_SPACER, ' ', $string);
|
655 |
|
|
$string = trim($string);
|
656 |
|
|
$string = str_replace(' ', PAGE_SPACER, $string);
|
657 |
|
|
// If there are any weird language characters, this will protect us against possible problems they could cause
|
658 |
|
|
$string = str_replace(array('%2F', '%'), array('/', ''), urlencode($string));
|
659 |
|
|
// Finally, return the cleaned string
|
660 |
|
|
return $string;
|
661 |
|
|
}
|
662 |
|
|
|
663 |
|
|
// Function to convert a desired media filename to a clean filename
|
664 |
|
|
function media_filename($string) {
|
665 |
442
|
Ruebenwurz
|
$string = entities_to_7bit(umlauts_to_entities($string));
|
666 |
238
|
stefan
|
// Now remove all bad characters
|
667 |
|
|
$bad = array(
|
668 |
|
|
'\'', // '
|
669 |
|
|
'"', // "
|
670 |
|
|
'`', // `
|
671 |
|
|
'!', // !
|
672 |
|
|
'@', // @
|
673 |
|
|
'#', // #
|
674 |
|
|
'$', // $
|
675 |
|
|
'%', // %
|
676 |
|
|
'^', // ^
|
677 |
|
|
'&', // &
|
678 |
|
|
'*', // *
|
679 |
|
|
'=', // =
|
680 |
|
|
'+', // +
|
681 |
|
|
'|', // |
|
682 |
|
|
'/', // /
|
683 |
|
|
'\\', // \
|
684 |
|
|
';', // ;
|
685 |
|
|
':', // :
|
686 |
|
|
',', // ,
|
687 |
|
|
'?' // ?
|
688 |
|
|
);
|
689 |
|
|
$string = str_replace($bad, '', $string);
|
690 |
|
|
// Clean any page spacers at the end of string
|
691 |
|
|
$string = trim($string);
|
692 |
|
|
// Finally, return the cleaned string
|
693 |
|
|
return $string;
|
694 |
|
|
}
|
695 |
|
|
|
696 |
|
|
// Function to work out a page link
|
697 |
|
|
if(!function_exists('page_link')) {
|
698 |
|
|
function page_link($link) {
|
699 |
242
|
stefan
|
global $admin;
|
700 |
|
|
return $admin->page_link($link);
|
701 |
238
|
stefan
|
}
|
702 |
|
|
}
|
703 |
|
|
|
704 |
|
|
// Create a new file in the pages directory
|
705 |
|
|
function create_access_file($filename,$page_id,$level) {
|
706 |
|
|
global $admin;
|
707 |
|
|
if(!is_writable(WB_PATH.PAGES_DIRECTORY.'/')) {
|
708 |
|
|
$admin->print_error($MESSAGE['PAGES']['CANNOT_CREATE_ACCESS_FILE']);
|
709 |
|
|
} else {
|
710 |
|
|
// First make sure parent folder exists
|
711 |
|
|
$parent_folders = explode('/',str_replace(WB_PATH.PAGES_DIRECTORY, '', dirname($filename)));
|
712 |
|
|
$parents = '';
|
713 |
|
|
foreach($parent_folders AS $parent_folder) {
|
714 |
|
|
if($parent_folder != '/' AND $parent_folder != '') {
|
715 |
|
|
$parents .= '/'.$parent_folder;
|
716 |
|
|
if(!file_exists(WB_PATH.PAGES_DIRECTORY.$parents)) {
|
717 |
|
|
make_dir(WB_PATH.PAGES_DIRECTORY.$parents);
|
718 |
|
|
}
|
719 |
|
|
}
|
720 |
|
|
}
|
721 |
|
|
// The depth of the page directory in the directory hierarchy
|
722 |
|
|
// '/pages' is at depth 1
|
723 |
|
|
$pages_dir_depth=count(explode('/',PAGES_DIRECTORY))-1;
|
724 |
|
|
// Work-out how many ../'s we need to get to the index page
|
725 |
|
|
$index_location = '';
|
726 |
|
|
for($i = 0; $i < $level + $pages_dir_depth; $i++) {
|
727 |
|
|
$index_location .= '../';
|
728 |
|
|
}
|
729 |
|
|
$content = ''.
|
730 |
|
|
'<?php
|
731 |
|
|
$page_id = '.$page_id.';
|
732 |
|
|
require("'.$index_location.'config.php");
|
733 |
|
|
require(WB_PATH."/index.php");
|
734 |
|
|
?>';
|
735 |
|
|
$handle = fopen($filename, 'w');
|
736 |
|
|
fwrite($handle, $content);
|
737 |
|
|
fclose($handle);
|
738 |
|
|
// Chmod the file
|
739 |
|
|
change_mode($filename, 'file');
|
740 |
|
|
}
|
741 |
|
|
}
|
742 |
|
|
|
743 |
|
|
// Function for working out a file mime type (if the in-built PHP one is not enabled)
|
744 |
|
|
if(!function_exists('mime_content_type')) {
|
745 |
|
|
function mime_content_type($file) {
|
746 |
|
|
$file = escapeshellarg($file);
|
747 |
|
|
return trim(`file -bi $file`);
|
748 |
|
|
}
|
749 |
|
|
}
|
750 |
|
|
|
751 |
|
|
// Generate a thumbnail from an image
|
752 |
|
|
function make_thumb($source, $destination, $size) {
|
753 |
|
|
// Check if GD is installed
|
754 |
|
|
if(extension_loaded('gd') AND function_exists('imageCreateFromJpeg')) {
|
755 |
|
|
// First figure out the size of the thumbnail
|
756 |
|
|
list($original_x, $original_y) = getimagesize($source);
|
757 |
|
|
if ($original_x > $original_y) {
|
758 |
|
|
$thumb_w = $size;
|
759 |
|
|
$thumb_h = $original_y*($size/$original_x);
|
760 |
|
|
}
|
761 |
|
|
if ($original_x < $original_y) {
|
762 |
|
|
$thumb_w = $original_x*($size/$original_y);
|
763 |
|
|
$thumb_h = $size;
|
764 |
|
|
}
|
765 |
|
|
if ($original_x == $original_y) {
|
766 |
|
|
$thumb_w = $size;
|
767 |
|
|
$thumb_h = $size;
|
768 |
|
|
}
|
769 |
|
|
// Now make the thumbnail
|
770 |
|
|
$source = imageCreateFromJpeg($source);
|
771 |
|
|
$dst_img = ImageCreateTrueColor($thumb_w, $thumb_h);
|
772 |
|
|
imagecopyresampled($dst_img,$source,0,0,0,0,$thumb_w,$thumb_h,$original_x,$original_y);
|
773 |
|
|
imagejpeg($dst_img, $destination);
|
774 |
|
|
// Clear memory
|
775 |
|
|
imagedestroy($dst_img);
|
776 |
|
|
imagedestroy($source);
|
777 |
|
|
// Return true
|
778 |
|
|
return true;
|
779 |
|
|
} else {
|
780 |
|
|
return false;
|
781 |
|
|
}
|
782 |
|
|
}
|
783 |
|
|
|
784 |
|
|
// Function to work-out a single part of an octal permission value
|
785 |
|
|
function extract_permission($octal_value, $who, $action) {
|
786 |
|
|
// Make sure the octal value is 4 chars long
|
787 |
|
|
if(strlen($octal_value) == 0) {
|
788 |
|
|
$octal_value = '0000';
|
789 |
|
|
} elseif(strlen($octal_value) == 1) {
|
790 |
|
|
$octal_value = '000'.$octal_value;
|
791 |
|
|
} elseif(strlen($octal_value) == 2) {
|
792 |
|
|
$octal_value = '00'.$octal_value;
|
793 |
|
|
} elseif(strlen($octal_value) == 3) {
|
794 |
|
|
$octal_value = '0'.$octal_value;
|
795 |
|
|
} elseif(strlen($octal_value) == 4) {
|
796 |
|
|
$octal_value = ''.$octal_value;
|
797 |
|
|
} else {
|
798 |
|
|
$octal_value = '0000';
|
799 |
|
|
}
|
800 |
|
|
// Work-out what position of the octal value to look at
|
801 |
|
|
switch($who) {
|
802 |
|
|
case 'u':
|
803 |
|
|
$position = '1';
|
804 |
|
|
break;
|
805 |
|
|
case 'user':
|
806 |
|
|
$position = '1';
|
807 |
|
|
break;
|
808 |
|
|
case 'g':
|
809 |
|
|
$position = '2';
|
810 |
|
|
break;
|
811 |
|
|
case 'group':
|
812 |
|
|
$position = '2';
|
813 |
|
|
break;
|
814 |
|
|
case 'o':
|
815 |
|
|
$position = '3';
|
816 |
|
|
break;
|
817 |
|
|
case 'others':
|
818 |
|
|
$position = '3';
|
819 |
|
|
break;
|
820 |
|
|
}
|
821 |
|
|
// Work-out how long the octal value is and ajust acording
|
822 |
|
|
if(strlen($octal_value) == 4) {
|
823 |
|
|
$position = $position+1;
|
824 |
|
|
} elseif(strlen($octal_value) != 3) {
|
825 |
|
|
exit('Error');
|
826 |
|
|
}
|
827 |
|
|
// Now work-out what action the script is trying to look-up
|
828 |
|
|
switch($action) {
|
829 |
|
|
case 'r':
|
830 |
|
|
$action = 'r';
|
831 |
|
|
break;
|
832 |
|
|
case 'read':
|
833 |
|
|
$action = 'r';
|
834 |
|
|
break;
|
835 |
|
|
case 'w':
|
836 |
|
|
$action = 'w';
|
837 |
|
|
break;
|
838 |
|
|
case 'write':
|
839 |
|
|
$action = 'w';
|
840 |
|
|
break;
|
841 |
|
|
case 'e':
|
842 |
|
|
$action = 'e';
|
843 |
|
|
break;
|
844 |
|
|
case 'execute':
|
845 |
|
|
$action = 'e';
|
846 |
|
|
break;
|
847 |
|
|
}
|
848 |
|
|
// Get the value for "who"
|
849 |
|
|
$value = substr($octal_value, $position-1, 1);
|
850 |
|
|
// Now work-out the details of the value
|
851 |
|
|
switch($value) {
|
852 |
|
|
case '0':
|
853 |
|
|
$r = false;
|
854 |
|
|
$w = false;
|
855 |
|
|
$e = false;
|
856 |
|
|
break;
|
857 |
|
|
case '1':
|
858 |
|
|
$r = false;
|
859 |
|
|
$w = false;
|
860 |
|
|
$e = true;
|
861 |
|
|
break;
|
862 |
|
|
case '2':
|
863 |
|
|
$r = false;
|
864 |
|
|
$w = true;
|
865 |
|
|
$e = false;
|
866 |
|
|
break;
|
867 |
|
|
case '3':
|
868 |
|
|
$r = false;
|
869 |
|
|
$w = true;
|
870 |
|
|
$e = true;
|
871 |
|
|
break;
|
872 |
|
|
case '4':
|
873 |
|
|
$r = true;
|
874 |
|
|
$w = false;
|
875 |
|
|
$e = false;
|
876 |
|
|
break;
|
877 |
|
|
case '5':
|
878 |
|
|
$r = true;
|
879 |
|
|
$w = false;
|
880 |
|
|
$e = true;
|
881 |
|
|
break;
|
882 |
|
|
case '6':
|
883 |
|
|
$r = true;
|
884 |
|
|
$w = true;
|
885 |
|
|
$e = false;
|
886 |
|
|
break;
|
887 |
|
|
case '7':
|
888 |
|
|
$r = true;
|
889 |
|
|
$w = true;
|
890 |
|
|
$e = true;
|
891 |
|
|
break;
|
892 |
|
|
default:
|
893 |
|
|
$r = false;
|
894 |
|
|
$w = false;
|
895 |
|
|
$e = false;
|
896 |
|
|
}
|
897 |
|
|
// And finally, return either true or false
|
898 |
|
|
return $$action;
|
899 |
|
|
}
|
900 |
|
|
|
901 |
|
|
// Function to delete a page
|
902 |
|
|
function delete_page($page_id) {
|
903 |
|
|
|
904 |
|
|
global $admin, $database;
|
905 |
|
|
|
906 |
|
|
// Find out more about the page
|
907 |
|
|
$database = new database();
|
908 |
|
|
$query = "SELECT page_id,menu_title,page_title,level,link,parent,modified_by,modified_when FROM ".TABLE_PREFIX."pages WHERE page_id = '$page_id'";
|
909 |
|
|
$results = $database->query($query);
|
910 |
|
|
if($database->is_error()) {
|
911 |
|
|
$admin->print_error($database->get_error());
|
912 |
|
|
}
|
913 |
|
|
if($results->numRows() == 0) {
|
914 |
|
|
$admin->print_error($MESSAGE['PAGES']['NOT_FOUND']);
|
915 |
|
|
}
|
916 |
|
|
$results_array = $results->fetchRow();
|
917 |
|
|
$parent = $results_array['parent'];
|
918 |
|
|
$level = $results_array['level'];
|
919 |
|
|
$link = $results_array['link'];
|
920 |
|
|
$page_title = ($results_array['page_title']);
|
921 |
|
|
$menu_title = ($results_array['menu_title']);
|
922 |
|
|
|
923 |
|
|
// Get the sections that belong to the page
|
924 |
|
|
$query_sections = $database->query("SELECT section_id,module FROM ".TABLE_PREFIX."sections WHERE page_id = '$page_id'");
|
925 |
|
|
if($query_sections->numRows() > 0) {
|
926 |
|
|
while($section = $query_sections->fetchRow()) {
|
927 |
|
|
// Set section id
|
928 |
|
|
$section_id = $section['section_id'];
|
929 |
|
|
// Include the modules delete file if it exists
|
930 |
|
|
if(file_exists(WB_PATH.'/modules/'.$section['module'].'/delete.php')) {
|
931 |
|
|
require(WB_PATH.'/modules/'.$section['module'].'/delete.php');
|
932 |
|
|
}
|
933 |
|
|
}
|
934 |
|
|
}
|
935 |
|
|
|
936 |
|
|
// Update the pages table
|
937 |
|
|
$query = "DELETE FROM ".TABLE_PREFIX."pages WHERE page_id = '$page_id'";
|
938 |
|
|
$database->query($query);
|
939 |
|
|
if($database->is_error()) {
|
940 |
|
|
$admin->print_error($database->get_error());
|
941 |
|
|
}
|
942 |
|
|
|
943 |
|
|
// Update the sections table
|
944 |
|
|
$query = "DELETE FROM ".TABLE_PREFIX."sections WHERE page_id = '$page_id'";
|
945 |
|
|
$database->query($query);
|
946 |
|
|
if($database->is_error()) {
|
947 |
|
|
$admin->print_error($database->get_error());
|
948 |
|
|
}
|
949 |
|
|
|
950 |
|
|
// Include the ordering class or clean-up ordering
|
951 |
|
|
require_once(WB_PATH.'/framework/class.order.php');
|
952 |
|
|
$order = new order(TABLE_PREFIX.'pages', 'position', 'page_id', 'parent');
|
953 |
|
|
$order->clean($parent);
|
954 |
|
|
|
955 |
|
|
// Unlink the page access file and directory
|
956 |
|
|
$directory = WB_PATH.PAGES_DIRECTORY.$link;
|
957 |
|
|
$filename = $directory.'.php';
|
958 |
|
|
$directory .= '/';
|
959 |
436
|
doc
|
if(file_exists($filename) && substr($filename,0,1<>'.')) {
|
960 |
238
|
stefan
|
if(!is_writable(WB_PATH.PAGES_DIRECTORY.'/')) {
|
961 |
|
|
$admin->print_error($MESSAGE['PAGES']['CANNOT_DELETE_ACCESS_FILE']);
|
962 |
|
|
} else {
|
963 |
|
|
unlink($filename);
|
964 |
|
|
if(file_exists($directory)) {
|
965 |
|
|
rm_full_dir($directory);
|
966 |
|
|
}
|
967 |
|
|
}
|
968 |
|
|
}
|
969 |
|
|
|
970 |
|
|
}
|
971 |
|
|
|
972 |
|
|
// Load module into DB
|
973 |
|
|
function load_module($directory, $install = false) {
|
974 |
249
|
stefan
|
global $database,$admin,$MESSAGE;
|
975 |
238
|
stefan
|
if(file_exists($directory.'/info.php')) {
|
976 |
|
|
require($directory.'/info.php');
|
977 |
|
|
if(isset($module_name)) {
|
978 |
|
|
if(!isset($module_license)) { $module_license = 'GNU General Public License'; }
|
979 |
|
|
if(!isset($module_platform) AND isset($module_designed_for)) { $module_platform = $module_designed_for; }
|
980 |
|
|
if(!isset($module_function) AND isset($module_type)) { $module_function = $module_type; }
|
981 |
|
|
$module_function = strtolower($module_function);
|
982 |
|
|
// Check that it doesn't already exist
|
983 |
|
|
$result = $database->query("SELECT addon_id FROM ".TABLE_PREFIX."addons WHERE directory = '".$module_directory."' LIMIT 0,1");
|
984 |
|
|
if($result->numRows() == 0) {
|
985 |
|
|
// Load into DB
|
986 |
|
|
$query = "INSERT INTO ".TABLE_PREFIX."addons ".
|
987 |
|
|
"(directory,name,description,type,function,version,platform,author,license) ".
|
988 |
|
|
"VALUES ('$module_directory','$module_name','".addslashes($module_description)."','module',".
|
989 |
|
|
"'$module_function','$module_version','$module_platform','$module_author','$module_license')";
|
990 |
|
|
$database->query($query);
|
991 |
|
|
// Run installation script
|
992 |
|
|
if($install == true) {
|
993 |
|
|
if(file_exists($directory.'/install.php')) {
|
994 |
|
|
require($directory.'/install.php');
|
995 |
|
|
}
|
996 |
|
|
}
|
997 |
|
|
}
|
998 |
|
|
}
|
999 |
|
|
}
|
1000 |
|
|
}
|
1001 |
|
|
|
1002 |
|
|
// Load template into DB
|
1003 |
|
|
function load_template($directory) {
|
1004 |
|
|
global $database;
|
1005 |
|
|
if(file_exists($directory.'/info.php')) {
|
1006 |
|
|
require($directory.'/info.php');
|
1007 |
|
|
if(isset($template_name)) {
|
1008 |
|
|
if(!isset($template_license)) { $template_license = 'GNU General Public License'; }
|
1009 |
|
|
if(!isset($template_platform) AND isset($template_designed_for)) { $template_platform = $template_designed_for; }
|
1010 |
|
|
// Check that it doesn't already exist
|
1011 |
|
|
$result = $database->query("SELECT addon_id FROM ".TABLE_PREFIX."addons WHERE directory = '".$template_directory."' LIMIT 0,1");
|
1012 |
|
|
if($result->numRows() == 0) {
|
1013 |
|
|
// Load into DB
|
1014 |
|
|
$query = "INSERT INTO ".TABLE_PREFIX."addons ".
|
1015 |
|
|
"(directory,name,description,type,version,platform,author,license) ".
|
1016 |
|
|
"VALUES ('$template_directory','$template_name','".addslashes($template_description)."','template',".
|
1017 |
|
|
"'$template_version','$template_platform','$template_author','$template_license')";
|
1018 |
|
|
$database->query($query);
|
1019 |
|
|
}
|
1020 |
|
|
}
|
1021 |
|
|
}
|
1022 |
|
|
}
|
1023 |
|
|
|
1024 |
|
|
// Load language into DB
|
1025 |
|
|
function load_language($file) {
|
1026 |
|
|
global $database;
|
1027 |
|
|
if(file_exists($file)) {
|
1028 |
|
|
require($file);
|
1029 |
|
|
if(isset($language_name)) {
|
1030 |
|
|
if(!isset($language_license)) { $language_license = 'GNU General Public License'; }
|
1031 |
|
|
if(!isset($language_platform) AND isset($language_designed_for)) { $language_platform = $language_designed_for; }
|
1032 |
|
|
// Check that it doesn't already exist
|
1033 |
|
|
$result = $database->query("SELECT addon_id FROM ".TABLE_PREFIX."addons WHERE directory = '".$language_code."' LIMIT 0,1");
|
1034 |
|
|
if($result->numRows() == 0) {
|
1035 |
|
|
// Load into DB
|
1036 |
|
|
$query = "INSERT INTO ".TABLE_PREFIX."addons ".
|
1037 |
|
|
"(directory,name,type,version,platform,author,license) ".
|
1038 |
|
|
"VALUES ('$language_code','$language_name','language',".
|
1039 |
|
|
"'$language_version','$language_platform','$language_author','$language_license')";
|
1040 |
|
|
$database->query($query);
|
1041 |
|
|
}
|
1042 |
|
|
}
|
1043 |
|
|
}
|
1044 |
|
|
}
|
1045 |
|
|
|
1046 |
373
|
Ruebenwurz
|
// Upgrade module info in DB, optionally start upgrade script
|
1047 |
|
|
function upgrade_module($directory, $upgrade = false) {
|
1048 |
|
|
global $database, $admin, $MESSAGE;
|
1049 |
|
|
$directory = WB_PATH . "/modules/$directory";
|
1050 |
|
|
if(file_exists($directory.'/info.php')) {
|
1051 |
|
|
require($directory.'/info.php');
|
1052 |
|
|
if(isset($module_name)) {
|
1053 |
|
|
if(!isset($module_license)) { $module_license = 'GNU General Public License'; }
|
1054 |
|
|
if(!isset($module_platform) AND isset($module_designed_for)) { $module_platform = $module_designed_for; }
|
1055 |
|
|
if(!isset($module_function) AND isset($module_type)) { $module_function = $module_type; }
|
1056 |
|
|
$module_function = strtolower($module_function);
|
1057 |
|
|
// Check that it does already exist
|
1058 |
|
|
$result = $database->query("SELECT addon_id FROM ".TABLE_PREFIX."addons WHERE directory = '".$module_directory."' LIMIT 0,1");
|
1059 |
|
|
if($result->numRows() > 0) {
|
1060 |
|
|
// Update in DB
|
1061 |
|
|
$query = "UPDATE " . TABLE_PREFIX . "addons SET " .
|
1062 |
|
|
"version = '$module_version', " .
|
1063 |
|
|
"description = '" . addslashes($module_description) . "', " .
|
1064 |
|
|
"platform = '$module_platform', " .
|
1065 |
|
|
"author = '$module_author', " .
|
1066 |
|
|
"license = '$module_license'" .
|
1067 |
|
|
"WHERE directory = '$module_directory'";
|
1068 |
|
|
$database->query($query);
|
1069 |
|
|
// Run upgrade script
|
1070 |
|
|
if($upgrade == true) {
|
1071 |
|
|
if(file_exists($directory.'/upgrade.php')) {
|
1072 |
|
|
require($directory.'/upgrade.php');
|
1073 |
|
|
}
|
1074 |
|
|
}
|
1075 |
|
|
}
|
1076 |
|
|
}
|
1077 |
|
|
}
|
1078 |
|
|
}
|
1079 |
|
|
|
1080 |
399
|
Ruebenwurz
|
?>
|