1 |
238
|
stefan
|
<?php
|
2 |
|
|
|
3 |
|
|
// $Id$
|
4 |
|
|
|
5 |
|
|
/*
|
6 |
|
|
|
7 |
|
|
Website Baker Project <http://www.websitebaker.org/>
|
8 |
547
|
Ruebenwurz
|
Copyright (C) 2004-2008, 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 |
546
|
doc
|
// if(HOME_FOLDERS AND ($_SESSION['GROUP_ID']!='1')) {
|
160 |
|
|
if(HOME_FOLDERS AND (!in_array('1',split(",",$_SESSION['GROUPS_ID'])))) {
|
161 |
|
|
|
162 |
238
|
stefan
|
$query_home_folders = $database->query("SELECT home_folder FROM ".TABLE_PREFIX."users WHERE home_folder != '".$admin->get_home_folder()."'");
|
163 |
|
|
if($query_home_folders->numRows() > 0) {
|
164 |
|
|
while($folder = $query_home_folders->fetchRow()) {
|
165 |
|
|
$home_folders[$folder['home_folder']] = $folder['home_folder'];
|
166 |
|
|
}
|
167 |
|
|
}
|
168 |
|
|
function remove_home_subs($directory = '/', $home_folders) {
|
169 |
|
|
if($handle = opendir(WB_PATH.MEDIA_DIRECTORY.$directory)) {
|
170 |
|
|
// Loop through the dirs to check the home folders sub-dirs are not shown
|
171 |
|
|
while(false !== ($file = readdir($handle))) {
|
172 |
|
|
if(substr($file, 0, 1) != '.' AND $file != '.svn' AND $file != 'index.php') {
|
173 |
|
|
if(is_dir(WB_PATH.MEDIA_DIRECTORY.$directory.'/'.$file)) {
|
174 |
|
|
if($directory != '/') { $file = $directory.'/'.$file; } else { $file = '/'.$file; }
|
175 |
|
|
foreach($home_folders AS $hf) {
|
176 |
|
|
$hf_length = strlen($hf);
|
177 |
|
|
if($hf_length > 0) {
|
178 |
|
|
if(substr($file, 0, $hf_length+1) == $hf) {
|
179 |
|
|
$home_folders[$file] = $file;
|
180 |
|
|
}
|
181 |
|
|
}
|
182 |
|
|
}
|
183 |
|
|
$home_folders = remove_home_subs($file, $home_folders);
|
184 |
|
|
}
|
185 |
|
|
}
|
186 |
|
|
}
|
187 |
|
|
}
|
188 |
|
|
return $home_folders;
|
189 |
|
|
}
|
190 |
|
|
$home_folders = remove_home_subs('/', $home_folders);
|
191 |
|
|
}
|
192 |
|
|
return $home_folders;
|
193 |
|
|
}
|
194 |
|
|
|
195 |
|
|
// Function to create directories
|
196 |
|
|
function make_dir($dir_name, $dir_mode = OCTAL_DIR_MODE) {
|
197 |
|
|
if(!file_exists($dir_name)) {
|
198 |
|
|
$umask = umask(0);
|
199 |
|
|
mkdir($dir_name, $dir_mode);
|
200 |
|
|
umask($umask);
|
201 |
|
|
return true;
|
202 |
|
|
} else {
|
203 |
|
|
return false;
|
204 |
|
|
}
|
205 |
|
|
}
|
206 |
|
|
|
207 |
|
|
// Function to chmod files and directories
|
208 |
|
|
function change_mode($name) {
|
209 |
|
|
if(OPERATING_SYSTEM != 'windows') {
|
210 |
|
|
// Only chmod if os is not windows
|
211 |
|
|
if(is_dir($name)) {
|
212 |
|
|
$mode = OCTAL_DIR_MODE;
|
213 |
|
|
} else {
|
214 |
|
|
$mode = OCTAL_FILE_MODE;
|
215 |
|
|
}
|
216 |
|
|
if(file_exists($name)) {
|
217 |
|
|
$umask = umask(0);
|
218 |
|
|
chmod($name, $mode);
|
219 |
|
|
umask($umask);
|
220 |
|
|
return true;
|
221 |
|
|
} else {
|
222 |
|
|
return false;
|
223 |
|
|
}
|
224 |
|
|
} else {
|
225 |
|
|
return true;
|
226 |
|
|
}
|
227 |
|
|
}
|
228 |
|
|
|
229 |
|
|
// Function to figure out if a parent exists
|
230 |
|
|
function is_parent($page_id) {
|
231 |
|
|
global $database;
|
232 |
|
|
// Get parent
|
233 |
|
|
$query = $database->query("SELECT parent FROM ".TABLE_PREFIX."pages WHERE page_id = '$page_id'");
|
234 |
|
|
$fetch = $query->fetchRow();
|
235 |
|
|
// If parent isnt 0 return its ID
|
236 |
|
|
if($fetch['parent'] == '0') {
|
237 |
|
|
return false;
|
238 |
|
|
} else {
|
239 |
|
|
return $fetch['parent'];
|
240 |
|
|
}
|
241 |
|
|
}
|
242 |
|
|
|
243 |
|
|
// Function to work out level
|
244 |
|
|
function level_count($page_id) {
|
245 |
|
|
global $database;
|
246 |
|
|
// Get page parent
|
247 |
|
|
$query_page = $database->query("SELECT parent FROM ".TABLE_PREFIX."pages WHERE page_id = '$page_id' LIMIT 1");
|
248 |
|
|
$fetch_page = $query_page->fetchRow();
|
249 |
|
|
$parent = $fetch_page['parent'];
|
250 |
|
|
if($parent > 0) {
|
251 |
|
|
// Get the level of the parent
|
252 |
|
|
$query_parent = $database->query("SELECT level FROM ".TABLE_PREFIX."pages WHERE page_id = '$parent' LIMIT 1");
|
253 |
|
|
$fetch_parent = $query_parent->fetchRow();
|
254 |
|
|
$level = $fetch_parent['level'];
|
255 |
|
|
return $level+1;
|
256 |
|
|
} else {
|
257 |
|
|
return 0;
|
258 |
|
|
}
|
259 |
|
|
}
|
260 |
|
|
|
261 |
|
|
// Function to work out root parent
|
262 |
|
|
function root_parent($page_id) {
|
263 |
|
|
global $database;
|
264 |
|
|
// Get page details
|
265 |
|
|
$query_page = $database->query("SELECT parent,level FROM ".TABLE_PREFIX."pages WHERE page_id = '$page_id' LIMIT 1");
|
266 |
|
|
$fetch_page = $query_page->fetchRow();
|
267 |
|
|
$parent = $fetch_page['parent'];
|
268 |
|
|
$level = $fetch_page['level'];
|
269 |
|
|
if($level == 1) {
|
270 |
|
|
return $parent;
|
271 |
|
|
} elseif($parent == 0) {
|
272 |
400
|
Ruebenwurz
|
return $page_id;
|
273 |
238
|
stefan
|
} else {
|
274 |
|
|
// Figure out what the root parents id is
|
275 |
|
|
$parent_ids = array_reverse(get_parent_ids($page_id));
|
276 |
|
|
return $parent_ids[0];
|
277 |
|
|
}
|
278 |
|
|
}
|
279 |
|
|
|
280 |
|
|
// Function to get page title
|
281 |
|
|
function get_page_title($id) {
|
282 |
|
|
global $database;
|
283 |
|
|
// Get title
|
284 |
|
|
$query = $database->query("SELECT page_title FROM ".TABLE_PREFIX."pages WHERE page_id = '$id'");
|
285 |
|
|
$fetch = $query->fetchRow();
|
286 |
|
|
// Return title
|
287 |
|
|
return $fetch['page_title'];
|
288 |
|
|
}
|
289 |
|
|
|
290 |
|
|
// Function to get a pages menu title
|
291 |
|
|
function get_menu_title($id) {
|
292 |
|
|
// Connect to the database
|
293 |
|
|
$database = new database();
|
294 |
|
|
// Get title
|
295 |
|
|
$query = $database->query("SELECT menu_title FROM ".TABLE_PREFIX."pages WHERE page_id = '$id'");
|
296 |
|
|
$fetch = $query->fetchRow();
|
297 |
|
|
// Return title
|
298 |
|
|
return $fetch['menu_title'];
|
299 |
|
|
}
|
300 |
|
|
|
301 |
|
|
// Function to get all parent page titles
|
302 |
|
|
function get_parent_titles($parent_id) {
|
303 |
|
|
$titles[] = get_menu_title($parent_id);
|
304 |
|
|
if(is_parent($parent_id) != false) {
|
305 |
|
|
$parent_titles = get_parent_titles(is_parent($parent_id));
|
306 |
|
|
$titles = array_merge($titles, $parent_titles);
|
307 |
|
|
}
|
308 |
|
|
return $titles;
|
309 |
|
|
}
|
310 |
|
|
|
311 |
|
|
// Function to get all parent page id's
|
312 |
|
|
function get_parent_ids($parent_id) {
|
313 |
|
|
$ids[] = $parent_id;
|
314 |
|
|
if(is_parent($parent_id) != false) {
|
315 |
|
|
$parent_ids = get_parent_ids(is_parent($parent_id));
|
316 |
|
|
$ids = array_merge($ids, $parent_ids);
|
317 |
|
|
}
|
318 |
|
|
return $ids;
|
319 |
|
|
}
|
320 |
|
|
|
321 |
|
|
// Function to genereate page trail
|
322 |
|
|
function get_page_trail($page_id) {
|
323 |
|
|
return implode(',', array_reverse(get_parent_ids($page_id)));
|
324 |
|
|
}
|
325 |
|
|
|
326 |
|
|
// Function to get all sub pages id's
|
327 |
|
|
function get_subs($parent, $subs) {
|
328 |
|
|
// Connect to the database
|
329 |
|
|
$database = new database();
|
330 |
|
|
// Get id's
|
331 |
|
|
$query = $database->query("SELECT page_id FROM ".TABLE_PREFIX."pages WHERE parent = '$parent'");
|
332 |
|
|
if($query->numRows() > 0) {
|
333 |
|
|
while($fetch = $query->fetchRow()) {
|
334 |
|
|
$subs[] = $fetch['page_id'];
|
335 |
|
|
// Get subs of this sub
|
336 |
|
|
$subs = get_subs($fetch['page_id'], $subs);
|
337 |
|
|
}
|
338 |
|
|
}
|
339 |
|
|
// Return subs array
|
340 |
|
|
return $subs;
|
341 |
|
|
}
|
342 |
|
|
|
343 |
504
|
Ruebenwurz
|
// Function as replacement for php's htmlspecialchars()
|
344 |
442
|
Ruebenwurz
|
function my_htmlspecialchars($string) {
|
345 |
476
|
Ruebenwurz
|
$string = preg_replace("/&(?=[#a-z0-9]+;)/i", "_x_", $string);
|
346 |
490
|
Ruebenwurz
|
$string = strtr($string, array("<"=>"<", ">"=>">", "&"=>"&", "\""=>""", "\'"=>"'"));
|
347 |
476
|
Ruebenwurz
|
$string = preg_replace("/_x_(?=[#a-z0-9]+;)/i", "&", $string);
|
348 |
442
|
Ruebenwurz
|
return($string);
|
349 |
|
|
}
|
350 |
|
|
|
351 |
|
|
// Function to convert a string from $from- to $to-encoding, using mysql
|
352 |
|
|
function my_mysql_iconv($string, $from, $to) {
|
353 |
482
|
Ruebenwurz
|
// keep current character set values
|
354 |
|
|
global $database;
|
355 |
|
|
$query = $database->query("SELECT @@character_set_client");
|
356 |
|
|
if($query->numRows() > 0) {
|
357 |
|
|
$res = $query->fetchRow();
|
358 |
|
|
$character_set_database = $res['@@character_set_client'];
|
359 |
|
|
} else { echo mysql_error()."\n<br />"; }
|
360 |
|
|
$query = $database->query("SELECT @@character_set_results");
|
361 |
|
|
if($query->numRows() > 0) {
|
362 |
|
|
$res = $query->fetchRow();
|
363 |
|
|
$character_set_results = $res['@@character_set_results'];
|
364 |
|
|
} else { echo mysql_error()."\n<br />"; }
|
365 |
|
|
$query = $database->query("SELECT @@collation_connection");
|
366 |
|
|
if($query->numRows() > 0) {
|
367 |
|
|
$res = $query->fetchRow();
|
368 |
|
|
$collation_results = $res['@@collation_connection'];
|
369 |
|
|
} else { echo mysql_error()."\n<br />"; }
|
370 |
|
|
// set new character set values
|
371 |
|
|
$query = $database->query("SET character_set_client=$from");
|
372 |
|
|
$query = $database->query("SET character_set_results=$to");
|
373 |
|
|
$query = $database->query("SET collation_connection=utf8_unicode_ci");
|
374 |
442
|
Ruebenwurz
|
$string_escaped = mysql_real_escape_string($string);
|
375 |
482
|
Ruebenwurz
|
// convert the string
|
376 |
|
|
$query = $database->query("SELECT '$string_escaped'");
|
377 |
|
|
if($query->numRows() > 0) {
|
378 |
|
|
$res = $query->fetchRow();
|
379 |
|
|
$converted_string = $res[0];
|
380 |
|
|
} else { echo mysql_error()."\n<br />"; }
|
381 |
|
|
// restore previous character set values
|
382 |
|
|
$query = $database->query("SET character_set_client=$character_set_database");
|
383 |
|
|
$query = $database->query("SET character_set_results=$character_set_results");
|
384 |
|
|
$query = $database->query("SET collation_connection=$collation_results");
|
385 |
442
|
Ruebenwurz
|
return $converted_string;
|
386 |
|
|
}
|
387 |
|
|
|
388 |
455
|
Ruebenwurz
|
// Function as wrapper for mb_convert_encoding
|
389 |
461
|
Ruebenwurz
|
// converts $charset_in to $charset_out or
|
390 |
|
|
// UTF-8 to HTML-ENTITIES or HTML-ENTITIES to UTF-8
|
391 |
455
|
Ruebenwurz
|
function mb_convert_encoding_wrapper($string, $charset_out, $charset_in) {
|
392 |
464
|
Ruebenwurz
|
if ($charset_out == $charset_in) {
|
393 |
|
|
return $string;
|
394 |
|
|
}
|
395 |
476
|
Ruebenwurz
|
$use_iconv = true;
|
396 |
|
|
$use_mbstring = true;
|
397 |
482
|
Ruebenwurz
|
/*
|
398 |
476
|
Ruebenwurz
|
if(version_compare(PHP_VERSION, "5.1.0", "<")) {
|
399 |
|
|
$use_mbstring = false; // don't rely on mb_convert_encoding if php<5.1.0
|
400 |
|
|
$use_iconv = false; // don't rely on iconv neither
|
401 |
|
|
}
|
402 |
482
|
Ruebenwurz
|
*/
|
403 |
476
|
Ruebenwurz
|
|
404 |
461
|
Ruebenwurz
|
// try mb_convert_encoding(). This can handle to or from HTML-ENTITIES, too
|
405 |
476
|
Ruebenwurz
|
if ($use_mbstring && function_exists('mb_convert_encoding')) {
|
406 |
461
|
Ruebenwurz
|
// there's no GB2312 or ISO-8859-11 encoding in php's mb_* functions
|
407 |
|
|
if ($charset_in=='ISO-8859-11' || $charset_in=='GB2312') {
|
408 |
476
|
Ruebenwurz
|
if ($use_iconv && function_exists('iconv')) {
|
409 |
461
|
Ruebenwurz
|
$string = iconv($charset_in, 'UTF-8', $string);
|
410 |
455
|
Ruebenwurz
|
}
|
411 |
461
|
Ruebenwurz
|
else {
|
412 |
|
|
if ($charset_in == 'GB2312') {
|
413 |
|
|
$string=my_mysql_iconv($string, 'gb2312', 'utf8');
|
414 |
|
|
} else {
|
415 |
|
|
$string=my_mysql_iconv($string, 'tis620', 'utf8');
|
416 |
|
|
}
|
417 |
|
|
}
|
418 |
|
|
$charset_in='UTF-8';
|
419 |
|
|
if ($charset_out == 'UTF-8') {
|
420 |
|
|
return $string;
|
421 |
|
|
}
|
422 |
455
|
Ruebenwurz
|
}
|
423 |
461
|
Ruebenwurz
|
if ($charset_out=='ISO-8859-11' || $charset_out=='GB2312') {
|
424 |
|
|
$string=mb_convert_encoding($string, 'UTF-8', $charset_in);
|
425 |
476
|
Ruebenwurz
|
if ($use_iconv && function_exists('iconv')) {
|
426 |
461
|
Ruebenwurz
|
$string = iconv('UTF-8', $charset_out, $string);
|
427 |
455
|
Ruebenwurz
|
}
|
428 |
461
|
Ruebenwurz
|
else {
|
429 |
|
|
if ($charset_out == 'GB2312') {
|
430 |
|
|
$string=my_mysql_iconv($string, 'utf8', 'gb2312');
|
431 |
|
|
} else {
|
432 |
|
|
$string=my_mysql_iconv($string, 'utf8', 'tis620');
|
433 |
455
|
Ruebenwurz
|
}
|
434 |
|
|
}
|
435 |
461
|
Ruebenwurz
|
} else {
|
436 |
490
|
Ruebenwurz
|
$string = strtr($string, array("<"=>"&_lt;", ">"=>"&_gt;", "&"=>"&_amp;", """=>"&_quot;", "'"=>"&_#39;"));
|
437 |
461
|
Ruebenwurz
|
$string=mb_convert_encoding($string, $charset_out, $charset_in);
|
438 |
490
|
Ruebenwurz
|
$string = strtr($string, array("&_lt;"=>"<", "&_gt;"=>">", "&_amp;"=>"&", "&_quot;"=>""", "&_#39;"=>"'"));
|
439 |
455
|
Ruebenwurz
|
}
|
440 |
461
|
Ruebenwurz
|
return $string;
|
441 |
455
|
Ruebenwurz
|
}
|
442 |
461
|
Ruebenwurz
|
|
443 |
|
|
// try iconv(). This can't handle to or from HTML-ENTITIES.
|
444 |
476
|
Ruebenwurz
|
if ($use_iconv && function_exists('iconv') && $charset_out!='HTML-ENTITIES' && $charset_in!='HTML-ENTITIES' ) {
|
445 |
461
|
Ruebenwurz
|
$string = iconv($charset_in, $charset_out, $string);
|
446 |
|
|
return $string;
|
447 |
|
|
}
|
448 |
|
|
|
449 |
476
|
Ruebenwurz
|
// do the UTF-8->HTML-ENTITIES or HTML-ENTITIES->UTF-8 translation if mb_convert_encoding isn't available
|
450 |
461
|
Ruebenwurz
|
if (($charset_in=='HTML-ENTITIES' && $charset_out=='UTF-8') || ($charset_in=='UTF-8' && $charset_out=='HTML-ENTITIES')) {
|
451 |
476
|
Ruebenwurz
|
$string = string_decode_encode_entities($string, $charset_out, $charset_in);
|
452 |
461
|
Ruebenwurz
|
return $string;
|
453 |
|
|
}
|
454 |
|
|
|
455 |
|
|
// mb_convert_encoding() and iconv() aren't available, so use my_mysql_iconv()
|
456 |
|
|
if ($charset_in == 'ISO-8859-1') { $mysqlcharset_from = 'latin1'; }
|
457 |
|
|
elseif ($charset_in == 'ISO-8859-2') { $mysqlcharset_from = 'latin2'; }
|
458 |
|
|
elseif ($charset_in == 'ISO-8859-3') { $mysqlcharset_from = 'latin1'; }
|
459 |
|
|
elseif ($charset_in == 'ISO-8859-4') { $mysqlcharset_from = 'latin7'; }
|
460 |
|
|
elseif ($charset_in == 'ISO-8859-5') { $string = convert_cyr_string ($string, "iso8859-5", "windows-1251" ); $mysqlcharset_from = 'cp1251'; }
|
461 |
|
|
elseif ($charset_in == 'ISO-8859-6') { $mysqlcharset_from = ''; } //?
|
462 |
|
|
elseif ($charset_in == 'ISO-8859-7') { $mysqlcharset_from = 'greek'; }
|
463 |
|
|
elseif ($charset_in == 'ISO-8859-8') { $mysqlcharset_from = 'hebrew'; }
|
464 |
|
|
elseif ($charset_in == 'ISO-8859-9') { $mysqlcharset_from = 'latin5'; }
|
465 |
|
|
elseif ($charset_in == 'ISO-8859-10') { $mysqlcharset_from = 'latin1'; }
|
466 |
|
|
elseif ($charset_in == 'BIG5') { $mysqlcharset_from = 'big5'; }
|
467 |
|
|
elseif ($charset_in == 'ISO-2022-JP') { $mysqlcharset_from = ''; } //?
|
468 |
|
|
elseif ($charset_in == 'ISO-2022-KR') { $mysqlcharset_from = ''; } //?
|
469 |
|
|
elseif ($charset_in == 'GB2312') { $mysqlcharset_from = 'gb2312'; }
|
470 |
|
|
elseif ($charset_in == 'ISO-8859-11') { $mysqlcharset_from = 'tis620'; }
|
471 |
|
|
elseif ($charset_in == 'UTF-8') { $mysqlcharset_from = 'utf8'; }
|
472 |
|
|
else { $mysqlcharset_from = 'latin1'; }
|
473 |
|
|
|
474 |
|
|
if ($charset_out == 'ISO-8859-1') { $mysqlcharset_to = 'latin1'; }
|
475 |
|
|
elseif ($charset_out == 'ISO-8859-2') { $mysqlcharset_to = 'latin2'; }
|
476 |
|
|
elseif ($charset_out == 'ISO-8859-3') { $mysqlcharset_to = 'latin1'; }
|
477 |
|
|
elseif ($charset_out == 'ISO-8859-4') { $mysqlcharset_to = 'latin7'; }
|
478 |
|
|
elseif ($charset_out == 'ISO-8859-5') { $mysqlcharset_to = 'cp1251'; } // use convert_cyr_string afterwards
|
479 |
|
|
elseif ($charset_out == 'ISO-8859-6') { $mysqlcharset_to = ''; } //?
|
480 |
|
|
elseif ($charset_out == 'ISO-8859-7') { $mysqlcharset_to = 'greek'; }
|
481 |
|
|
elseif ($charset_out == 'ISO-8859-8') { $mysqlcharset_to = 'hebrew'; }
|
482 |
|
|
elseif ($charset_out == 'ISO-8859-9') { $mysqlcharset_to = 'latin5'; }
|
483 |
|
|
elseif ($charset_out == 'ISO-8859-10') { $mysqlcharset_to = 'latin1'; }
|
484 |
|
|
elseif ($charset_out == 'BIG5') { $mysqlcharset_to = 'big5'; }
|
485 |
|
|
elseif ($charset_out == 'ISO-2022-JP') { $mysqlcharset_to = ''; } //?
|
486 |
|
|
elseif ($charset_out == 'ISO-2022-KR') { $mysqlcharset_to = ''; } //?
|
487 |
|
|
elseif ($charset_out == 'GB2312') { $mysqlcharset_to = 'gb2312'; }
|
488 |
|
|
elseif ($charset_out == 'ISO-8859-11') { $mysqlcharset_to = 'tis620'; }
|
489 |
|
|
elseif ($charset_out == 'UTF-8') { $mysqlcharset_to = 'utf8'; }
|
490 |
|
|
else { $mysqlcharset_to = 'latin1'; }
|
491 |
|
|
|
492 |
|
|
if ($mysqlcharset_from!="" && $mysqlcharset_to!="" && $mysqlcharset_from!=$mysqlcharset_to) {
|
493 |
|
|
$string=my_mysql_iconv($string, $mysqlcharset_from, $mysqlcharset_to);
|
494 |
|
|
if ($mysqlcharset_to == 'cp1251') {
|
495 |
|
|
$string = convert_cyr_string ($string, "windows-1251", "iso-8859-5" );
|
496 |
|
|
}
|
497 |
|
|
return($string);
|
498 |
|
|
}
|
499 |
|
|
|
500 |
|
|
// $string is unchanged. This will happen if we have to deal with ISO-8859-6 or ISO-2022-JP or -KR
|
501 |
|
|
// and mbstring _and_ iconv aren't available.
|
502 |
|
|
return $string;
|
503 |
455
|
Ruebenwurz
|
}
|
504 |
476
|
Ruebenwurz
|
|
505 |
|
|
// Decodes or encodes html-entities. Works for utf-8 only!
|
506 |
|
|
function string_decode_encode_entities($string, $out='HTML-ENTITIES', $in='UTF-8') {
|
507 |
|
|
if(!(($in=='UTF-8' || $in=='HTML-ENTITIES') && ($out=='UTF-8' || $out=='HTML-ENTITIES'))) {
|
508 |
|
|
return $string;
|
509 |
|
|
}
|
510 |
|
|
$named_to_numbered_entities=array(
|
511 |
|
|
'Á'=>'Á','á'=>'á',
|
512 |
|
|
'Â'=>'Â','â'=>'â','´'=>'´','Æ'=>'Æ','æ'=>'æ',
|
513 |
|
|
'À'=>'À','à'=>'à','ℵ'=>'ℵ','Α'=>'Α','α'=>'α',
|
514 |
478
|
Ruebenwurz
|
'∧'=>'∧','∠'=>'∠','''=>''','Å'=>'Å','å'=>'å',
|
515 |
476
|
Ruebenwurz
|
'≈'=>'≈','Ã'=>'Ã','ã'=>'ã','Ä'=>'Ä','ä'=>'ä',
|
516 |
|
|
'„'=>'„','Β'=>'Β','β'=>'β','¦'=>'¦','•'=>'•',
|
517 |
|
|
'∩'=>'∩','Ç'=>'Ç','ç'=>'ç','¸'=>'¸','¢'=>'¢',
|
518 |
|
|
'Χ'=>'Χ','χ'=>'χ','ˆ'=>'ˆ','♣'=>'♣','≅'=>'≅',
|
519 |
|
|
'©'=>'©','↵'=>'↵','∪'=>'∪','¤'=>'¤','‡'=>'‡',
|
520 |
|
|
'†'=>'†','⇓'=>'⇓','↓'=>'↓','°'=>'°','Δ'=>'Δ',
|
521 |
|
|
'δ'=>'δ','♦'=>'&v#9830;','÷'=>'÷','É'=>'É','é'=>'é',
|
522 |
|
|
'Ê'=>'Ê','ê'=>'ê','È'=>'È','è'=>'è','∅'=>'∅',
|
523 |
|
|
' '=>' ',' '=>' ','Ε'=>'Ε','ε'=>'ε','≡'=>'≡',
|
524 |
|
|
'Η'=>'Η','η'=>'η','Ð'=>'Ð','ð'=>'ð','Ë'=>'Ë','ë'=>'ë',
|
525 |
|
|
'€'=>'€','∃'=>'∃','ƒ'=>'ƒ','∀'=>'∀','½'=>'½',
|
526 |
|
|
'¼'=>'¼','¾'=>'¾','⁄'=>'⁄','Γ'=>'Γ','γ'=>'γ',
|
527 |
478
|
Ruebenwurz
|
'≥'=>'≥','⇔'=>'⇔','↔'=>'↔','♥'=>'♥',
|
528 |
476
|
Ruebenwurz
|
'…'=>'…','Í'=>'Í','í'=>'í','Î'=>'Î','î'=>'î',
|
529 |
|
|
'¡'=>'¡','Ì'=>'Ì','ì'=>'ì','ℑ'=>'ℑ','∞'=>'∞',
|
530 |
|
|
'∫'=>'∫','Ι'=>'Ι','ι'=>'ι','¿'=>'¿','∈'=>'∈',
|
531 |
|
|
'Ï'=>'Ï','ï'=>'ï','Κ'=>'Κ','κ'=>'κ','Λ'=>'Λ',
|
532 |
|
|
'λ'=>'λ','⟨'=>'〈','«'=>'«','⇐'=>'⇐','←'=>'←',
|
533 |
|
|
'⌈'=>'⌈','“'=>'“','≤'=>'≤','⌊'=>'⌊','∗'=>'∗',
|
534 |
478
|
Ruebenwurz
|
'◊'=>'◊','‎'=>'‎','‹'=>'‹','‘'=>'‘',
|
535 |
476
|
Ruebenwurz
|
'¯'=>'¯','—'=>'—','µ'=>'µ','·'=>'·','−'=>'−',
|
536 |
|
|
'Μ'=>'Μ','μ'=>'μ','∇'=>'∇',' '=>' ','–'=>'–',
|
537 |
|
|
'≠'=>'≠','∋'=>'∋','¬'=>'¬','∉'=>'∉','⊄'=>'⊄',
|
538 |
|
|
'Ñ'=>'Ñ','ñ'=>'ñ','Ν'=>'Ν','ν'=>'ν','Ó'=>'Ó',
|
539 |
|
|
'ó'=>'ó','Ô'=>'Ô','ô'=>'ô','Œ'=>'Œ','œ'=>'œ',
|
540 |
|
|
'Ò'=>'Ò','ò'=>'ò','‾'=>'‾','Ω'=>'Ω','ω'=>'ω',
|
541 |
|
|
'Ο'=>'Ο','ο'=>'ο','⊕'=>'⊕','∨'=>'∨','ª'=>'ª',
|
542 |
|
|
'º'=>'º','Ø'=>'Ø','ø'=>'ø','Õ'=>'Õ','õ'=>'õ',
|
543 |
|
|
'⊗'=>'⊗','Ö'=>'Ö','ö'=>'ö','¶'=>'¶','∂'=>'∂',
|
544 |
|
|
'‰'=>'‰','⊥'=>'⊥','Φ'=>'Φ','φ'=>'φ','Π'=>'Π',
|
545 |
|
|
'π'=>'π','ϖ'=>'ϖ','±'=>'±','£'=>'£','″'=>'″',
|
546 |
|
|
'′'=>'′','∏'=>'∏','∝'=>'∝','Ψ'=>'Ψ','ψ'=>'ψ',
|
547 |
|
|
'"'=>'"','√'=>'√','⟩'=>'〉','»'=>'»','⇒'=>'⇒',
|
548 |
|
|
'→'=>'→','⌉'=>'⌉','”'=>'”','ℜ'=>'ℜ','®'=>'®',
|
549 |
|
|
'⌋'=>'⌋','Ρ'=>'Ρ','ρ'=>'ρ','‏'=>'‏','›'=>'›',
|
550 |
|
|
'’'=>'’','‚'=>'‚','Š'=>'Š','š'=>'š','⋅'=>'⋅',
|
551 |
|
|
'§'=>'§','­'=>'­','Σ'=>'Σ','σ'=>'σ','ς'=>'ς',
|
552 |
|
|
'∼'=>'∼','♠'=>'♠','⊂'=>'⊂','⊆'=>'⊆','∑'=>'∑',
|
553 |
|
|
'⊃'=>'⊃','¹'=>'¹','²'=>'²','³'=>'³','⊇'=>'⊇',
|
554 |
|
|
'ß'=>'ß','Τ'=>'Τ','τ'=>'τ','∴'=>'∴','Θ'=>'Θ',
|
555 |
|
|
'θ'=>'θ','ϑ'=>'ϑ',' '=>' ','Þ'=>'Þ','þ'=>'þ',
|
556 |
|
|
'˜'=>'˜','×'=>'×','™'=>'™','Ú'=>'Ú','ú'=>'ú',
|
557 |
|
|
'⇑'=>'⇑','↑'=>'↑','Û'=>'Û','û'=>'û','Ù'=>'Ù',
|
558 |
|
|
'ù'=>'ù','¨'=>'¨','ϒ'=>'ϒ','Υ'=>'Υ','υ'=>'υ',
|
559 |
|
|
'Ü'=>'Ü','ü'=>'ü','℘'=>'℘','Ξ'=>'Ξ','ξ'=>'ξ',
|
560 |
|
|
'Ý'=>'Ý','ý'=>'ý','¥'=>'¥','Ÿ'=>'Ÿ','ÿ'=>'ÿ',
|
561 |
|
|
'Ζ'=>'Ζ','ζ'=>'ζ','‍'=>'‍','‌'=>'‌'
|
562 |
|
|
);
|
563 |
|
|
$numbered_to_named_entities=array(
|
564 |
|
|
'Á'=>'Á','á'=>'á','Â'=>'Â','â'=>'â','´'=>'´',
|
565 |
|
|
'Æ'=>'Æ','æ'=>'æ','À'=>'À','à'=>'à','ℵ'=>'ℵ',
|
566 |
478
|
Ruebenwurz
|
'Α'=>'Α','α'=>'α','∧'=>'∧','∠'=>'∠',
|
567 |
476
|
Ruebenwurz
|
'''=>''','Å'=>'Å','å'=>'å','≈'=>'≈','Ã'=>'Ã',
|
568 |
|
|
'ã'=>'ã','Ä'=>'Ä','ä'=>'ä','„'=>'„','Β'=>'Β',
|
569 |
|
|
'β'=>'β','¦'=>'¦','•'=>'•','∩'=>'∩','Ç'=>'Ç',
|
570 |
|
|
'ç'=>'ç','¸'=>'¸','¢'=>'¢','Χ'=>'Χ','χ'=>'χ',
|
571 |
|
|
'ˆ'=>'ˆ','♣'=>'♣','≅'=>'≅','©'=>'©','↵'=>'↵',
|
572 |
|
|
'∪'=>'∪','¤'=>'¤','‡'=>'‡','†'=>'†','⇓'=>'⇓',
|
573 |
|
|
'↓'=>'↓','°'=>'°','Δ'=>'Δ','δ'=>'δ','&v#9830;'=>'♦',
|
574 |
|
|
'÷'=>'÷','É'=>'É','é'=>'é','Ê'=>'Ê','ê'=>'ê',
|
575 |
|
|
'È'=>'È','è'=>'è','∅'=>'∅',' '=>' ',' '=>' ',
|
576 |
|
|
'Ε'=>'Ε','ε'=>'ε','≡'=>'≡','Η'=>'Η','η'=>'η',
|
577 |
|
|
'Ð'=>'Ð','ð'=>'ð','Ë'=>'Ë','ë'=>'ë','€'=>'€',
|
578 |
|
|
'∃'=>'∃','ƒ'=>'ƒ','∀'=>'∀','½'=>'½','¼'=>'¼',
|
579 |
|
|
'¾'=>'¾','⁄'=>'⁄','Γ'=>'Γ','γ'=>'γ','≥'=>'≥',
|
580 |
478
|
Ruebenwurz
|
'⇔'=>'⇔','↔'=>'↔','♥'=>'♥','…'=>'…',
|
581 |
476
|
Ruebenwurz
|
'Í'=>'Í','í'=>'í','Î'=>'Î','î'=>'î','¡'=>'¡',
|
582 |
|
|
'Ì'=>'Ì','ì'=>'ì','ℑ'=>'ℑ','∞'=>'∞','∫'=>'∫',
|
583 |
|
|
'Ι'=>'Ι','ι'=>'ι','¿'=>'¿','∈'=>'∈','Ï'=>'Ï',
|
584 |
|
|
'ï'=>'ï','Κ'=>'Κ','κ'=>'κ','Λ'=>'Λ','λ'=>'λ',
|
585 |
|
|
'〈'=>'⟨','«'=>'«','⇐'=>'⇐','←'=>'←','⌈'=>'⌈',
|
586 |
|
|
'“'=>'“','≤'=>'≤','⌊'=>'⌊','∗'=>'∗','◊'=>'◊',
|
587 |
478
|
Ruebenwurz
|
'‎'=>'‎','‹'=>'‹','‘'=>'‘','¯'=>'¯',
|
588 |
476
|
Ruebenwurz
|
'—'=>'—','µ'=>'µ','·'=>'·','−'=>'−','Μ'=>'Μ',
|
589 |
|
|
'μ'=>'μ','∇'=>'∇',' '=>' ','–'=>'–','≠'=>'≠',
|
590 |
|
|
'∋'=>'∋','¬'=>'¬','∉'=>'∉','⊄'=>'⊄','Ñ'=>'Ñ',
|
591 |
|
|
'ñ'=>'ñ','Ν'=>'Ν','ν'=>'ν','Ó'=>'Ó','ó'=>'ó',
|
592 |
|
|
'Ô'=>'Ô','ô'=>'ô','Œ'=>'Œ','œ'=>'œ','Ò'=>'Ò',
|
593 |
|
|
'ò'=>'ò','‾'=>'‾','Ω'=>'Ω','ω'=>'ω','Ο'=>'Ο',
|
594 |
|
|
'ο'=>'ο','⊕'=>'⊕','∨'=>'∨','ª'=>'ª','º'=>'º',
|
595 |
|
|
'Ø'=>'Ø','ø'=>'ø','Õ'=>'Õ','õ'=>'õ','⊗'=>'⊗',
|
596 |
|
|
'Ö'=>'Ö','ö'=>'ö','¶'=>'¶','∂'=>'∂','‰'=>'‰',
|
597 |
|
|
'⊥'=>'⊥','Φ'=>'Φ','φ'=>'φ','Π'=>'Π','π'=>'π','ϖ'=>'ϖ',
|
598 |
|
|
'±'=>'±','£'=>'£','″'=>'″','′'=>'′','∏'=>'∏',
|
599 |
|
|
'∝'=>'∝','Ψ'=>'Ψ','ψ'=>'ψ','"'=>'"','√'=>'√',
|
600 |
|
|
'〉'=>'⟩','»'=>'»','⇒'=>'⇒','→'=>'→','⌉'=>'⌉',
|
601 |
|
|
'”'=>'”','ℜ'=>'ℜ','®'=>'®','⌋'=>'⌋','Ρ'=>'Ρ',
|
602 |
|
|
'ρ'=>'ρ','‏'=>'‏','›'=>'›','’'=>'’','‚'=>'‚',
|
603 |
|
|
'Š'=>'Š','š'=>'š','⋅'=>'⋅','§'=>'§','­'=>'­',
|
604 |
|
|
'Σ'=>'Σ','σ'=>'σ','ς'=>'ς','∼'=>'∼','♠'=>'♠',
|
605 |
|
|
'⊂'=>'⊂','⊆'=>'⊆','∑'=>'∑','⊃'=>'⊃','¹'=>'¹',
|
606 |
|
|
'²'=>'²','³'=>'³','⊇'=>'⊇','ß'=>'ß','Τ'=>'Τ',
|
607 |
|
|
'τ'=>'τ','∴'=>'∴','Θ'=>'Θ','θ'=>'θ','ϑ'=>'ϑ',
|
608 |
|
|
' '=>' ','Þ'=>'Þ','þ'=>'þ','˜'=>'˜','×'=>'×',
|
609 |
|
|
'™'=>'™','Ú'=>'Ú','ú'=>'ú','⇑'=>'⇑','↑'=>'↑',
|
610 |
|
|
'Û'=>'Û','û'=>'û','Ù'=>'Ù','ù'=>'ù','¨'=>'¨',
|
611 |
|
|
'ϒ'=>'ϒ','Υ'=>'Υ','υ'=>'υ','Ü'=>'Ü','ü'=>'ü',
|
612 |
|
|
'℘'=>'℘','Ξ'=>'Ξ','ξ'=>'ξ','Ý'=>'Ý','ý'=>'ý',
|
613 |
|
|
'¥'=>'¥','Ÿ'=>'Ÿ','ÿ'=>'ÿ','Ζ'=>'Ζ','ζ'=>'ζ','‍'=>'‍',
|
614 |
|
|
'‌'=>'‌'
|
615 |
|
|
);
|
616 |
|
|
|
617 |
|
|
if ($in == 'HTML-ENTITIES') {
|
618 |
|
|
$string = strtr($string, $named_to_numbered_entities);
|
619 |
|
|
$string = preg_replace("/&#([0-9]+);/e", "code_to_utf8($1)", $string);
|
620 |
|
|
}
|
621 |
|
|
elseif ($out == 'HTML-ENTITIES') {
|
622 |
|
|
$char = "";
|
623 |
504
|
Ruebenwurz
|
$i=0;
|
624 |
|
|
$len=strlen($string);
|
625 |
|
|
if($len==0) return $string;
|
626 |
|
|
do {
|
627 |
|
|
if(ord($string{$i}) <= 127) $ud = $string{$i++};
|
628 |
|
|
elseif(ord($string{$i}) <= 223) $ud = (ord($string{$i++})-192)*64 + (ord($string{$i++})-128);
|
629 |
|
|
elseif(ord($string{$i}) <= 239) $ud = (ord($string{$i++})-224)*4096 + (ord($string{$i++})-128)*64 + (ord($string{$i++})-128);
|
630 |
|
|
elseif(ord($string{$i}) <= 247) $ud = (ord($string{$i++})-240)*262144 + (ord($string{$i++})-128)*4096 + (ord($string{$i++})-128)*64 + (ord($string{$i++})-128);
|
631 |
|
|
elseif(ord($string{$i}) <= 251) $ud = ord($string{$i++}); // error!
|
632 |
|
|
if($ud > 127) {
|
633 |
|
|
$char .= "&#$ud;";
|
634 |
|
|
} else {
|
635 |
|
|
$char .= $ud;
|
636 |
|
|
}
|
637 |
|
|
} while($i < $len);
|
638 |
476
|
Ruebenwurz
|
$string = $char;
|
639 |
|
|
$string = strtr($string, $numbered_to_named_entities);
|
640 |
493
|
Ruebenwurz
|
// do ' and "
|
641 |
|
|
$string = strtr($string, array('\''=>''', '\"'=>'"'));
|
642 |
476
|
Ruebenwurz
|
}
|
643 |
|
|
return $string;
|
644 |
|
|
}
|
645 |
|
|
|
646 |
|
|
// support-function for string_decode_encode_entities()
|
647 |
455
|
Ruebenwurz
|
function code_to_utf8($num) {
|
648 |
|
|
if ($num <= 0x7F) {
|
649 |
|
|
return chr($num);
|
650 |
|
|
} elseif ($num <= 0x7FF) {
|
651 |
|
|
return chr(($num >> 6) + 192) . chr(($num & 63) + 128);
|
652 |
|
|
} elseif ($num <= 0xFFFF) {
|
653 |
|
|
return chr(($num >> 12) + 224) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128);
|
654 |
|
|
} elseif ($num <= 0x1FFFFF) {
|
655 |
|
|
return chr(($num >> 18) + 240) . chr((($num >> 12) & 63) + 128) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128);
|
656 |
|
|
}
|
657 |
|
|
return " ";
|
658 |
|
|
}
|
659 |
|
|
|
660 |
445
|
Ruebenwurz
|
// Function to convert a string from mixed html-entities/umlauts to pure utf-8-umlauts
|
661 |
|
|
function string_to_utf8($string, $charset=DEFAULT_CHARSET) {
|
662 |
|
|
$charset = strtoupper($charset);
|
663 |
|
|
if ($charset == '') { $charset = 'ISO-8859-1'; }
|
664 |
|
|
|
665 |
461
|
Ruebenwurz
|
if (!is_UTF8($string)) {
|
666 |
455
|
Ruebenwurz
|
$string=mb_convert_encoding_wrapper($string, 'UTF-8', $charset);
|
667 |
442
|
Ruebenwurz
|
}
|
668 |
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
|
669 |
|
|
// and mb_string AND iconv aren't available.
|
670 |
461
|
Ruebenwurz
|
if (is_UTF8($string)) {
|
671 |
|
|
$string=mb_convert_encoding_wrapper($string, 'HTML-ENTITIES', 'UTF-8');
|
672 |
|
|
$string=mb_convert_encoding_wrapper($string, 'UTF-8', 'HTML-ENTITIES');
|
673 |
|
|
} else {
|
674 |
464
|
Ruebenwurz
|
// nothing we can do here :-(
|
675 |
461
|
Ruebenwurz
|
}
|
676 |
442
|
Ruebenwurz
|
return($string);
|
677 |
|
|
}
|
678 |
|
|
|
679 |
461
|
Ruebenwurz
|
// function to check if a string is UTF-8
|
680 |
464
|
Ruebenwurz
|
function is_UTF8 ($str) {
|
681 |
|
|
if (strlen($str) < 4000) {
|
682 |
|
|
// 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.
|
683 |
|
|
// 4000 works for me ...
|
684 |
|
|
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);
|
685 |
|
|
} else {
|
686 |
|
|
$isUTF8 = true;
|
687 |
|
|
while($str{0}) {
|
688 |
|
|
if (preg_match("/^[\x09\x0A\x0D\x20-\x7E]/", $str)) { $str = substr($str, 1); continue; }
|
689 |
|
|
if (preg_match("/^[\xC2-\xDF][\x80-\xBF]/", $str)) { $str = substr($str, 2); continue; }
|
690 |
|
|
if (preg_match("/^\xE0[\xA0-\xBF][\x80-\xBF]/", $str)) { $str = substr($str, 3); continue; }
|
691 |
|
|
if (preg_match("/^[\xE1-\xEC\xEE\xEF][\x80-\xBF]{2}/", $str)) { $str = substr($str, 3); continue; }
|
692 |
|
|
if (preg_match("/^\xED[\x80-\x9F][\x80-\xBF]/", $str)) { $str = substr($str, 3); continue; }
|
693 |
|
|
if (preg_match("/^\xF0[\x90-\xBF][\x80-\xBF]{2}/", $str)) { $str = substr($str, 4); continue; }
|
694 |
|
|
if (preg_match("/^[\xF1-\xF3][\x80-\xBF]{3}/", $str)) { $str = substr($str, 4); continue; }
|
695 |
|
|
if (preg_match("/^\xF4[\x80-\x8F][\x80-\xBF]{2}/", $str)) { $str = substr($str, 4); continue; }
|
696 |
|
|
if (preg_match("/^$/", $str)) { break; }
|
697 |
|
|
$isUTF8 = false;
|
698 |
|
|
break;
|
699 |
|
|
}
|
700 |
|
|
return ($isUTF8);
|
701 |
|
|
}
|
702 |
461
|
Ruebenwurz
|
}
|
703 |
|
|
|
704 |
445
|
Ruebenwurz
|
// Function to convert a string from mixed html-entities/umlauts to pure $charset_out-umlauts
|
705 |
504
|
Ruebenwurz
|
function entities_to_umlauts($string, $charset_out=DEFAULT_CHARSET) {
|
706 |
445
|
Ruebenwurz
|
$charset_out = strtoupper($charset_out);
|
707 |
461
|
Ruebenwurz
|
if ($charset_out == '') { $charset_out = 'ISO-8859-1'; }
|
708 |
476
|
Ruebenwurz
|
$charset_in = strtoupper(DEFAULT_CHARSET);
|
709 |
504
|
Ruebenwurz
|
require_once(WB_PATH.'/framework/charsets_table.php');
|
710 |
|
|
global $iso_8859_2_to_utf8, $iso_8859_3_to_utf8, $iso_8859_4_to_utf8, $iso_8859_5_to_utf8, $iso_8859_6_to_utf8, $iso_8859_7_to_utf8, $iso_8859_8_to_utf8, $iso_8859_9_to_utf8, $iso_8859_10_to_utf8, $iso_8859_11_to_utf8;
|
711 |
|
|
global $utf8_to_iso_8859_2, $utf8_to_iso_8859_3, $utf8_to_iso_8859_4, $utf8_to_iso_8859_5, $utf8_to_iso_8859_6, $utf8_to_iso_8859_7, $utf8_to_iso_8859_8, $utf8_to_iso_8859_9, $utf8_to_iso_8859_10, $utf8_to_iso_8859_11;
|
712 |
|
|
|
713 |
|
|
// string to utf-8, entities_to_utf8
|
714 |
|
|
if (substr($charset_in,0,8) == 'ISO-8859' || $charset_in == 'UTF-8') {
|
715 |
476
|
Ruebenwurz
|
if ($charset_in == 'ISO-8859-1') {
|
716 |
|
|
$string=utf8_encode($string);
|
717 |
504
|
Ruebenwurz
|
} elseif ($charset_in == 'ISO-8859-2') {
|
718 |
|
|
$string = strtr($string, $iso_8859_2_to_utf8);
|
719 |
|
|
} elseif ($charset_in == 'ISO-8859-3') {
|
720 |
|
|
$string = strtr($string, $iso_8859_3_to_utf8);
|
721 |
|
|
} elseif ($charset_in == 'ISO-8859-4') {
|
722 |
|
|
$string = strtr($string, $iso_8859_4_to_utf8);
|
723 |
|
|
} elseif ($charset_in == 'ISO-8859-5') {
|
724 |
|
|
$string = strtr($string, $iso_8859_5_to_utf8);
|
725 |
|
|
} elseif ($charset_in == 'ISO-8859-6') {
|
726 |
|
|
$string = strtr($string, $iso_8859_6_to_utf8);
|
727 |
|
|
} elseif ($charset_in == 'ISO-8859-7') {
|
728 |
|
|
$string = strtr($string, $iso_8859_7_to_utf8);
|
729 |
|
|
} elseif ($charset_in == 'ISO-8859-8') {
|
730 |
|
|
$string = strtr($string, $iso_8859_8_to_utf8);
|
731 |
|
|
} elseif ($charset_in == 'ISO-8859-9') {
|
732 |
|
|
$string = strtr($string, $iso_8859_9_to_utf8);
|
733 |
|
|
} elseif ($charset_in == 'ISO-8859-10') {
|
734 |
|
|
$string = strtr($string, $iso_8859_10_to_utf8);
|
735 |
|
|
} elseif ($charset_in == 'ISO-8859-11') {
|
736 |
|
|
$string = strtr($string, $iso_8859_11_to_utf8);
|
737 |
476
|
Ruebenwurz
|
}
|
738 |
|
|
// decode html-entities
|
739 |
|
|
if(preg_match("/&[#a-zA-Z0-9]+;/", $string)) {
|
740 |
|
|
$string=string_decode_encode_entities($string, 'UTF-8', 'HTML-ENTITIES');
|
741 |
504
|
Ruebenwurz
|
//$string=mb_convert_encoding_wrapper($string, 'HTML-ENTITIES', 'UTF-8'); // alternative to string_decode_encode_entities()
|
742 |
478
|
Ruebenwurz
|
//$string=mb_convert_encoding_wrapper($string, 'UTF-8', 'HTML-ENTITIES');
|
743 |
476
|
Ruebenwurz
|
}
|
744 |
|
|
}
|
745 |
|
|
else {
|
746 |
|
|
$string = string_to_utf8($string); // will decode html-entities, too.
|
747 |
|
|
}
|
748 |
|
|
// string to $charset_out
|
749 |
|
|
if($charset_out == 'ISO-8859-1') {
|
750 |
|
|
$string=utf8_decode($string);
|
751 |
504
|
Ruebenwurz
|
} elseif($charset_out == 'ISO-8859-2') {
|
752 |
|
|
$string = strtr($string, $utf8_to_iso_8859_2);
|
753 |
|
|
} elseif($charset_out == 'ISO-8859-3') {
|
754 |
|
|
$string = strtr($string, $utf8_to_iso_8859_3);
|
755 |
|
|
} elseif($charset_out == 'ISO-8859-4') {
|
756 |
|
|
$string = strtr($string, $utf8_to_iso_8859_4);
|
757 |
|
|
} elseif($charset_out == 'ISO-8859-5') {
|
758 |
|
|
$string = strtr($string, $utf8_to_iso_8859_5);
|
759 |
|
|
} elseif($charset_out == 'ISO-8859-6') {
|
760 |
|
|
$string = strtr($string, $utf8_to_iso_8859_6);
|
761 |
|
|
} elseif($charset_out == 'ISO-8859-7') {
|
762 |
|
|
$string = strtr($string, $utf8_to_iso_8859_7);
|
763 |
|
|
} elseif($charset_out == 'ISO-8859-8') {
|
764 |
|
|
$string = strtr($string, $utf8_to_iso_8859_8);
|
765 |
|
|
} elseif($charset_out == 'ISO-8859-9') {
|
766 |
|
|
$string = strtr($string, $utf8_to_iso_8859_9);
|
767 |
|
|
} elseif($charset_out == 'ISO-8859-10') {
|
768 |
|
|
$string = strtr($string, $utf8_to_iso_8859_10);
|
769 |
|
|
} elseif($charset_out == 'ISO-8859-11') {
|
770 |
|
|
$string = strtr($string, $utf8_to_iso_8859_11);
|
771 |
|
|
} elseif($charset_out != 'UTF-8') {
|
772 |
|
|
if(is_UTF8($string)) {
|
773 |
|
|
$string=mb_convert_encoding_wrapper($string, $charset_out, 'UTF-8');
|
774 |
|
|
}
|
775 |
476
|
Ruebenwurz
|
}
|
776 |
|
|
return $string;
|
777 |
|
|
}
|
778 |
445
|
Ruebenwurz
|
|
779 |
|
|
// Function to convert a string from mixed html-entitites/$charset_in-umlauts to pure html-entities
|
780 |
504
|
Ruebenwurz
|
function umlauts_to_entities($string, $charset_in=DEFAULT_CHARSET) {
|
781 |
445
|
Ruebenwurz
|
$charset_in = strtoupper($charset_in);
|
782 |
461
|
Ruebenwurz
|
if ($charset_in == "") { $charset_in = 'ISO-8859-1'; }
|
783 |
504
|
Ruebenwurz
|
require_once(WB_PATH.'/framework/charsets_table.php');
|
784 |
|
|
global $iso_8859_2_to_utf8, $iso_8859_3_to_utf8, $iso_8859_4_to_utf8, $iso_8859_5_to_utf8, $iso_8859_6_to_utf8, $iso_8859_7_to_utf8, $iso_8859_8_to_utf8, $iso_8859_9_to_utf8, $iso_8859_10_to_utf8, $iso_8859_11_to_utf8;
|
785 |
476
|
Ruebenwurz
|
|
786 |
504
|
Ruebenwurz
|
// string to utf-8, umlauts_to_entities
|
787 |
|
|
if ($charset_in == 'UTF-8' || substr($charset_in,0,8) == 'ISO-8859') {
|
788 |
476
|
Ruebenwurz
|
if ($charset_in == 'ISO-8859-1') {
|
789 |
|
|
$string=utf8_encode($string);
|
790 |
504
|
Ruebenwurz
|
} elseif ($charset_in == 'ISO-8859-2') {
|
791 |
|
|
$string = strtr($string, $iso_8859_2_to_utf8);
|
792 |
|
|
} elseif ($charset_in == 'ISO-8859-3') {
|
793 |
|
|
$string = strtr($string, $iso_8859_3_to_utf8);
|
794 |
|
|
} elseif ($charset_in == 'ISO-8859-4') {
|
795 |
|
|
$string = strtr($string, $iso_8859_4_to_utf8);
|
796 |
|
|
} elseif ($charset_in == 'ISO-8859-5') {
|
797 |
|
|
$string = strtr($string, $iso_8859_5_to_utf8);
|
798 |
|
|
} elseif ($charset_in == 'ISO-8859-6') {
|
799 |
|
|
$string = strtr($string, $iso_8859_6_to_utf8);
|
800 |
|
|
} elseif ($charset_in == 'ISO-8859-7') {
|
801 |
|
|
$string = strtr($string, $iso_8859_7_to_utf8);
|
802 |
|
|
} elseif ($charset_in == 'ISO-8859-8') {
|
803 |
|
|
$string = strtr($string, $iso_8859_8_to_utf8);
|
804 |
|
|
} elseif ($charset_in == 'ISO-8859-9') {
|
805 |
|
|
$string = strtr($string, $iso_8859_9_to_utf8);
|
806 |
|
|
} elseif ($charset_in == 'ISO-8859-10') {
|
807 |
|
|
$string = strtr($string, $iso_8859_10_to_utf8);
|
808 |
|
|
} elseif ($charset_in == 'ISO-8859-11') {
|
809 |
|
|
$string = strtr($string, $iso_8859_11_to_utf8);
|
810 |
476
|
Ruebenwurz
|
}
|
811 |
|
|
// encode html-entities
|
812 |
504
|
Ruebenwurz
|
$string=string_decode_encode_entities($string, 'HTML-ENTITIES', 'UTF-8');
|
813 |
482
|
Ruebenwurz
|
//$string=mb_convert_encoding_wrapper($string, 'HTML-ENTITIES', 'UTF-8');
|
814 |
461
|
Ruebenwurz
|
}
|
815 |
476
|
Ruebenwurz
|
else {
|
816 |
|
|
$string = string_to_utf8($string, $charset_in);
|
817 |
|
|
// encode html-entities
|
818 |
|
|
if (is_UTF8($string)) {
|
819 |
482
|
Ruebenwurz
|
$string=string_decode_encode_entities($string, 'HTML-ENTITIES', 'UTF-8');
|
820 |
|
|
//$string=mb_convert_encoding_wrapper($string, 'HTML-ENTITIES', 'UTF-8');
|
821 |
476
|
Ruebenwurz
|
}
|
822 |
|
|
}
|
823 |
|
|
return $string;
|
824 |
442
|
Ruebenwurz
|
}
|
825 |
|
|
|
826 |
482
|
Ruebenwurz
|
function umlauts_to_defcharset($string, $charset) {
|
827 |
|
|
$charset_out = strtoupper(DEFAULT_CHARSET);
|
828 |
|
|
if ($charset_out == "") { $charset_out = 'ISO-8859-1'; }
|
829 |
504
|
Ruebenwurz
|
require_once(WB_PATH.'/framework/charsets_table.php');
|
830 |
|
|
global $utf8_to_iso_8859_2, $utf8_to_iso_8859_3, $utf8_to_iso_8859_4, $utf8_to_iso_8859_5, $utf8_to_iso_8859_6, $utf8_to_iso_8859_7, $utf8_to_iso_8859_8, $utf8_to_iso_8859_9, $utf8_to_iso_8859_10, $utf8_to_iso_8859_11;
|
831 |
482
|
Ruebenwurz
|
|
832 |
|
|
if($charset_out == $charset) {
|
833 |
|
|
return $string;
|
834 |
|
|
}
|
835 |
504
|
Ruebenwurz
|
|
836 |
|
|
if($charset == 'UTF-8') {
|
837 |
|
|
if($charset_out == 'ISO-8859-1') {
|
838 |
|
|
$string = utf8_decode($string);
|
839 |
|
|
} elseif ($charset_out == 'ISO-8859-2') {
|
840 |
|
|
$string = strtr($string, $utf8_to_iso_8859_2);
|
841 |
|
|
} elseif ($charset_out == 'ISO-8859-3') {
|
842 |
|
|
$string = strtr($string, $utf8_to_iso_8859_3);
|
843 |
|
|
} elseif ($charset_out == 'ISO-8859-4') {
|
844 |
|
|
$string = strtr($string, $utf8_to_iso_8859_4);
|
845 |
|
|
} elseif ($charset_out == 'ISO-8859-5') {
|
846 |
|
|
$string = strtr($string, $utf8_to_iso_8859_5);
|
847 |
|
|
} elseif ($charset_out == 'ISO-8859-6') {
|
848 |
|
|
$string = strtr($string, $utf8_to_iso_8859_6);
|
849 |
|
|
} elseif ($charset_out == 'ISO-8859-7') {
|
850 |
|
|
$string = strtr($string, $utf8_to_iso_8859_7);
|
851 |
|
|
} elseif ($charset_out == 'ISO-8859-8') {
|
852 |
|
|
$string = strtr($string, $utf8_to_iso_8859_8);
|
853 |
|
|
} elseif ($charset_out == 'ISO-8859-9') {
|
854 |
|
|
$string = strtr($string, $utf8_to_iso_8859_9);
|
855 |
|
|
} elseif ($charset_out == 'ISO-8859-10') {
|
856 |
|
|
$string = strtr($string, $utf8_to_iso_8859_10);
|
857 |
|
|
} elseif ($charset_out == 'ISO-8859-11') {
|
858 |
|
|
$string = strtr($string, $utf8_to_iso_8859_11);
|
859 |
|
|
}
|
860 |
|
|
else {
|
861 |
|
|
$string=mb_convert_encoding_wrapper($string, $charset_out, $charset);
|
862 |
|
|
}
|
863 |
482
|
Ruebenwurz
|
}
|
864 |
|
|
else {
|
865 |
504
|
Ruebenwurz
|
$string=mb_convert_encoding_wrapper($string, $charset_out, $charset);
|
866 |
482
|
Ruebenwurz
|
}
|
867 |
|
|
|
868 |
|
|
return $string;
|
869 |
|
|
}
|
870 |
|
|
|
871 |
445
|
Ruebenwurz
|
// translate any latin/greek/cyrillic html-entities to their plain 7bit equivalents
|
872 |
461
|
Ruebenwurz
|
// and numbered-entities into hex
|
873 |
442
|
Ruebenwurz
|
function entities_to_7bit($string) {
|
874 |
|
|
require(WB_PATH.'/framework/convert.php');
|
875 |
|
|
$string = strtr($string, $conversion_array);
|
876 |
461
|
Ruebenwurz
|
$string = preg_replace('/&#([0-9]+);/e', "dechex('$1')", $string);
|
877 |
442
|
Ruebenwurz
|
return($string);
|
878 |
|
|
}
|
879 |
|
|
|
880 |
238
|
stefan
|
// Function to convert a page title to a page filename
|
881 |
|
|
function page_filename($string) {
|
882 |
442
|
Ruebenwurz
|
$string = entities_to_7bit(umlauts_to_entities($string));
|
883 |
238
|
stefan
|
// Now replace spaces with page spcacer
|
884 |
547
|
Ruebenwurz
|
$string = trim($string);
|
885 |
|
|
$string = preg_replace('/(\s)+/', PAGE_SPACER, $string);
|
886 |
238
|
stefan
|
// Now remove all bad characters
|
887 |
|
|
$bad = array(
|
888 |
|
|
'\'', /* / */ '"', /* " */ '<', /* < */ '>', /* > */
|
889 |
|
|
'{', /* { */ '}', /* } */ '[', /* [ */ ']', /* ] */ '`', /* ` */
|
890 |
|
|
'!', /* ! */ '@', /* @ */ '#', /* # */ '$', /* $ */ '%', /* % */
|
891 |
|
|
'^', /* ^ */ '&', /* & */ '*', /* * */ '(', /* ( */ ')', /* ) */
|
892 |
|
|
'=', /* = */ '+', /* + */ '|', /* | */ '/', /* / */ '\\', /* \ */
|
893 |
|
|
';', /* ; */ ':', /* : */ ',', /* , */ '?' /* ? */
|
894 |
|
|
);
|
895 |
|
|
$string = str_replace($bad, '', $string);
|
896 |
|
|
// Now convert to lower-case
|
897 |
|
|
$string = strtolower($string);
|
898 |
|
|
// If there are any weird language characters, this will protect us against possible problems they could cause
|
899 |
|
|
$string = str_replace(array('%2F', '%'), array('/', ''), urlencode($string));
|
900 |
|
|
// Finally, return the cleaned string
|
901 |
|
|
return $string;
|
902 |
|
|
}
|
903 |
|
|
|
904 |
|
|
// Function to convert a desired media filename to a clean filename
|
905 |
|
|
function media_filename($string) {
|
906 |
442
|
Ruebenwurz
|
$string = entities_to_7bit(umlauts_to_entities($string));
|
907 |
238
|
stefan
|
// Now remove all bad characters
|
908 |
|
|
$bad = array(
|
909 |
|
|
'\'', // '
|
910 |
|
|
'"', // "
|
911 |
|
|
'`', // `
|
912 |
|
|
'!', // !
|
913 |
|
|
'@', // @
|
914 |
|
|
'#', // #
|
915 |
|
|
'$', // $
|
916 |
|
|
'%', // %
|
917 |
|
|
'^', // ^
|
918 |
|
|
'&', // &
|
919 |
|
|
'*', // *
|
920 |
|
|
'=', // =
|
921 |
|
|
'+', // +
|
922 |
|
|
'|', // |
|
923 |
|
|
'/', // /
|
924 |
|
|
'\\', // \
|
925 |
|
|
';', // ;
|
926 |
|
|
':', // :
|
927 |
|
|
',', // ,
|
928 |
|
|
'?' // ?
|
929 |
|
|
);
|
930 |
|
|
$string = str_replace($bad, '', $string);
|
931 |
|
|
// Clean any page spacers at the end of string
|
932 |
|
|
$string = trim($string);
|
933 |
|
|
// Finally, return the cleaned string
|
934 |
|
|
return $string;
|
935 |
|
|
}
|
936 |
|
|
|
937 |
|
|
// Function to work out a page link
|
938 |
|
|
if(!function_exists('page_link')) {
|
939 |
|
|
function page_link($link) {
|
940 |
242
|
stefan
|
global $admin;
|
941 |
|
|
return $admin->page_link($link);
|
942 |
238
|
stefan
|
}
|
943 |
|
|
}
|
944 |
|
|
|
945 |
|
|
// Create a new file in the pages directory
|
946 |
|
|
function create_access_file($filename,$page_id,$level) {
|
947 |
501
|
ryan
|
global $admin, $MESSAGE;
|
948 |
238
|
stefan
|
if(!is_writable(WB_PATH.PAGES_DIRECTORY.'/')) {
|
949 |
|
|
$admin->print_error($MESSAGE['PAGES']['CANNOT_CREATE_ACCESS_FILE']);
|
950 |
|
|
} else {
|
951 |
|
|
// First make sure parent folder exists
|
952 |
|
|
$parent_folders = explode('/',str_replace(WB_PATH.PAGES_DIRECTORY, '', dirname($filename)));
|
953 |
|
|
$parents = '';
|
954 |
|
|
foreach($parent_folders AS $parent_folder) {
|
955 |
|
|
if($parent_folder != '/' AND $parent_folder != '') {
|
956 |
|
|
$parents .= '/'.$parent_folder;
|
957 |
|
|
if(!file_exists(WB_PATH.PAGES_DIRECTORY.$parents)) {
|
958 |
|
|
make_dir(WB_PATH.PAGES_DIRECTORY.$parents);
|
959 |
|
|
}
|
960 |
|
|
}
|
961 |
|
|
}
|
962 |
|
|
// The depth of the page directory in the directory hierarchy
|
963 |
|
|
// '/pages' is at depth 1
|
964 |
|
|
$pages_dir_depth=count(explode('/',PAGES_DIRECTORY))-1;
|
965 |
|
|
// Work-out how many ../'s we need to get to the index page
|
966 |
|
|
$index_location = '';
|
967 |
|
|
for($i = 0; $i < $level + $pages_dir_depth; $i++) {
|
968 |
|
|
$index_location .= '../';
|
969 |
|
|
}
|
970 |
|
|
$content = ''.
|
971 |
|
|
'<?php
|
972 |
|
|
$page_id = '.$page_id.';
|
973 |
|
|
require("'.$index_location.'config.php");
|
974 |
|
|
require(WB_PATH."/index.php");
|
975 |
|
|
?>';
|
976 |
|
|
$handle = fopen($filename, 'w');
|
977 |
|
|
fwrite($handle, $content);
|
978 |
|
|
fclose($handle);
|
979 |
|
|
// Chmod the file
|
980 |
|
|
change_mode($filename, 'file');
|
981 |
|
|
}
|
982 |
|
|
}
|
983 |
|
|
|
984 |
|
|
// Function for working out a file mime type (if the in-built PHP one is not enabled)
|
985 |
|
|
if(!function_exists('mime_content_type')) {
|
986 |
|
|
function mime_content_type($file) {
|
987 |
|
|
$file = escapeshellarg($file);
|
988 |
|
|
return trim(`file -bi $file`);
|
989 |
|
|
}
|
990 |
|
|
}
|
991 |
|
|
|
992 |
|
|
// Generate a thumbnail from an image
|
993 |
|
|
function make_thumb($source, $destination, $size) {
|
994 |
|
|
// Check if GD is installed
|
995 |
|
|
if(extension_loaded('gd') AND function_exists('imageCreateFromJpeg')) {
|
996 |
|
|
// First figure out the size of the thumbnail
|
997 |
|
|
list($original_x, $original_y) = getimagesize($source);
|
998 |
|
|
if ($original_x > $original_y) {
|
999 |
|
|
$thumb_w = $size;
|
1000 |
|
|
$thumb_h = $original_y*($size/$original_x);
|
1001 |
|
|
}
|
1002 |
|
|
if ($original_x < $original_y) {
|
1003 |
|
|
$thumb_w = $original_x*($size/$original_y);
|
1004 |
|
|
$thumb_h = $size;
|
1005 |
|
|
}
|
1006 |
|
|
if ($original_x == $original_y) {
|
1007 |
|
|
$thumb_w = $size;
|
1008 |
|
|
$thumb_h = $size;
|
1009 |
|
|
}
|
1010 |
|
|
// Now make the thumbnail
|
1011 |
|
|
$source = imageCreateFromJpeg($source);
|
1012 |
|
|
$dst_img = ImageCreateTrueColor($thumb_w, $thumb_h);
|
1013 |
|
|
imagecopyresampled($dst_img,$source,0,0,0,0,$thumb_w,$thumb_h,$original_x,$original_y);
|
1014 |
|
|
imagejpeg($dst_img, $destination);
|
1015 |
|
|
// Clear memory
|
1016 |
|
|
imagedestroy($dst_img);
|
1017 |
|
|
imagedestroy($source);
|
1018 |
|
|
// Return true
|
1019 |
|
|
return true;
|
1020 |
|
|
} else {
|
1021 |
|
|
return false;
|
1022 |
|
|
}
|
1023 |
|
|
}
|
1024 |
|
|
|
1025 |
|
|
// Function to work-out a single part of an octal permission value
|
1026 |
|
|
function extract_permission($octal_value, $who, $action) {
|
1027 |
|
|
// Make sure the octal value is 4 chars long
|
1028 |
|
|
if(strlen($octal_value) == 0) {
|
1029 |
|
|
$octal_value = '0000';
|
1030 |
|
|
} elseif(strlen($octal_value) == 1) {
|
1031 |
|
|
$octal_value = '000'.$octal_value;
|
1032 |
|
|
} elseif(strlen($octal_value) == 2) {
|
1033 |
|
|
$octal_value = '00'.$octal_value;
|
1034 |
|
|
} elseif(strlen($octal_value) == 3) {
|
1035 |
|
|
$octal_value = '0'.$octal_value;
|
1036 |
|
|
} elseif(strlen($octal_value) == 4) {
|
1037 |
|
|
$octal_value = ''.$octal_value;
|
1038 |
|
|
} else {
|
1039 |
|
|
$octal_value = '0000';
|
1040 |
|
|
}
|
1041 |
|
|
// Work-out what position of the octal value to look at
|
1042 |
|
|
switch($who) {
|
1043 |
|
|
case 'u':
|
1044 |
|
|
$position = '1';
|
1045 |
|
|
break;
|
1046 |
|
|
case 'user':
|
1047 |
|
|
$position = '1';
|
1048 |
|
|
break;
|
1049 |
|
|
case 'g':
|
1050 |
|
|
$position = '2';
|
1051 |
|
|
break;
|
1052 |
|
|
case 'group':
|
1053 |
|
|
$position = '2';
|
1054 |
|
|
break;
|
1055 |
|
|
case 'o':
|
1056 |
|
|
$position = '3';
|
1057 |
|
|
break;
|
1058 |
|
|
case 'others':
|
1059 |
|
|
$position = '3';
|
1060 |
|
|
break;
|
1061 |
|
|
}
|
1062 |
|
|
// Work-out how long the octal value is and ajust acording
|
1063 |
|
|
if(strlen($octal_value) == 4) {
|
1064 |
|
|
$position = $position+1;
|
1065 |
|
|
} elseif(strlen($octal_value) != 3) {
|
1066 |
|
|
exit('Error');
|
1067 |
|
|
}
|
1068 |
|
|
// Now work-out what action the script is trying to look-up
|
1069 |
|
|
switch($action) {
|
1070 |
|
|
case 'r':
|
1071 |
|
|
$action = 'r';
|
1072 |
|
|
break;
|
1073 |
|
|
case 'read':
|
1074 |
|
|
$action = 'r';
|
1075 |
|
|
break;
|
1076 |
|
|
case 'w':
|
1077 |
|
|
$action = 'w';
|
1078 |
|
|
break;
|
1079 |
|
|
case 'write':
|
1080 |
|
|
$action = 'w';
|
1081 |
|
|
break;
|
1082 |
|
|
case 'e':
|
1083 |
|
|
$action = 'e';
|
1084 |
|
|
break;
|
1085 |
|
|
case 'execute':
|
1086 |
|
|
$action = 'e';
|
1087 |
|
|
break;
|
1088 |
|
|
}
|
1089 |
|
|
// Get the value for "who"
|
1090 |
|
|
$value = substr($octal_value, $position-1, 1);
|
1091 |
|
|
// Now work-out the details of the value
|
1092 |
|
|
switch($value) {
|
1093 |
|
|
case '0':
|
1094 |
|
|
$r = false;
|
1095 |
|
|
$w = false;
|
1096 |
|
|
$e = false;
|
1097 |
|
|
break;
|
1098 |
|
|
case '1':
|
1099 |
|
|
$r = false;
|
1100 |
|
|
$w = false;
|
1101 |
|
|
$e = true;
|
1102 |
|
|
break;
|
1103 |
|
|
case '2':
|
1104 |
|
|
$r = false;
|
1105 |
|
|
$w = true;
|
1106 |
|
|
$e = false;
|
1107 |
|
|
break;
|
1108 |
|
|
case '3':
|
1109 |
|
|
$r = false;
|
1110 |
|
|
$w = true;
|
1111 |
|
|
$e = true;
|
1112 |
|
|
break;
|
1113 |
|
|
case '4':
|
1114 |
|
|
$r = true;
|
1115 |
|
|
$w = false;
|
1116 |
|
|
$e = false;
|
1117 |
|
|
break;
|
1118 |
|
|
case '5':
|
1119 |
|
|
$r = true;
|
1120 |
|
|
$w = false;
|
1121 |
|
|
$e = true;
|
1122 |
|
|
break;
|
1123 |
|
|
case '6':
|
1124 |
|
|
$r = true;
|
1125 |
|
|
$w = true;
|
1126 |
|
|
$e = false;
|
1127 |
|
|
break;
|
1128 |
|
|
case '7':
|
1129 |
|
|
$r = true;
|
1130 |
|
|
$w = true;
|
1131 |
|
|
$e = true;
|
1132 |
|
|
break;
|
1133 |
|
|
default:
|
1134 |
|
|
$r = false;
|
1135 |
|
|
$w = false;
|
1136 |
|
|
$e = false;
|
1137 |
|
|
}
|
1138 |
|
|
// And finally, return either true or false
|
1139 |
|
|
return $$action;
|
1140 |
|
|
}
|
1141 |
|
|
|
1142 |
|
|
// Function to delete a page
|
1143 |
|
|
function delete_page($page_id) {
|
1144 |
|
|
|
1145 |
501
|
ryan
|
global $admin, $database, $MESSAGE;
|
1146 |
238
|
stefan
|
|
1147 |
|
|
// Find out more about the page
|
1148 |
|
|
$database = new database();
|
1149 |
|
|
$query = "SELECT page_id,menu_title,page_title,level,link,parent,modified_by,modified_when FROM ".TABLE_PREFIX."pages WHERE page_id = '$page_id'";
|
1150 |
|
|
$results = $database->query($query);
|
1151 |
|
|
if($database->is_error()) {
|
1152 |
|
|
$admin->print_error($database->get_error());
|
1153 |
|
|
}
|
1154 |
|
|
if($results->numRows() == 0) {
|
1155 |
|
|
$admin->print_error($MESSAGE['PAGES']['NOT_FOUND']);
|
1156 |
|
|
}
|
1157 |
|
|
$results_array = $results->fetchRow();
|
1158 |
|
|
$parent = $results_array['parent'];
|
1159 |
|
|
$level = $results_array['level'];
|
1160 |
|
|
$link = $results_array['link'];
|
1161 |
|
|
$page_title = ($results_array['page_title']);
|
1162 |
|
|
$menu_title = ($results_array['menu_title']);
|
1163 |
|
|
|
1164 |
|
|
// Get the sections that belong to the page
|
1165 |
|
|
$query_sections = $database->query("SELECT section_id,module FROM ".TABLE_PREFIX."sections WHERE page_id = '$page_id'");
|
1166 |
|
|
if($query_sections->numRows() > 0) {
|
1167 |
|
|
while($section = $query_sections->fetchRow()) {
|
1168 |
|
|
// Set section id
|
1169 |
|
|
$section_id = $section['section_id'];
|
1170 |
|
|
// Include the modules delete file if it exists
|
1171 |
|
|
if(file_exists(WB_PATH.'/modules/'.$section['module'].'/delete.php')) {
|
1172 |
|
|
require(WB_PATH.'/modules/'.$section['module'].'/delete.php');
|
1173 |
|
|
}
|
1174 |
|
|
}
|
1175 |
|
|
}
|
1176 |
|
|
|
1177 |
|
|
// Update the pages table
|
1178 |
|
|
$query = "DELETE FROM ".TABLE_PREFIX."pages WHERE page_id = '$page_id'";
|
1179 |
|
|
$database->query($query);
|
1180 |
|
|
if($database->is_error()) {
|
1181 |
|
|
$admin->print_error($database->get_error());
|
1182 |
|
|
}
|
1183 |
|
|
|
1184 |
|
|
// Update the sections table
|
1185 |
|
|
$query = "DELETE FROM ".TABLE_PREFIX."sections WHERE page_id = '$page_id'";
|
1186 |
|
|
$database->query($query);
|
1187 |
|
|
if($database->is_error()) {
|
1188 |
|
|
$admin->print_error($database->get_error());
|
1189 |
|
|
}
|
1190 |
|
|
|
1191 |
|
|
// Include the ordering class or clean-up ordering
|
1192 |
|
|
require_once(WB_PATH.'/framework/class.order.php');
|
1193 |
|
|
$order = new order(TABLE_PREFIX.'pages', 'position', 'page_id', 'parent');
|
1194 |
|
|
$order->clean($parent);
|
1195 |
|
|
|
1196 |
|
|
// Unlink the page access file and directory
|
1197 |
|
|
$directory = WB_PATH.PAGES_DIRECTORY.$link;
|
1198 |
546
|
doc
|
$filename = $directory.'.php';
|
1199 |
238
|
stefan
|
$directory .= '/';
|
1200 |
546
|
doc
|
if(file_exists($filename) && substr($filename,0,1<>'.')) {
|
1201 |
238
|
stefan
|
if(!is_writable(WB_PATH.PAGES_DIRECTORY.'/')) {
|
1202 |
|
|
$admin->print_error($MESSAGE['PAGES']['CANNOT_DELETE_ACCESS_FILE']);
|
1203 |
|
|
} else {
|
1204 |
|
|
unlink($filename);
|
1205 |
546
|
doc
|
if(file_exists($directory)) {
|
1206 |
238
|
stefan
|
rm_full_dir($directory);
|
1207 |
|
|
}
|
1208 |
|
|
}
|
1209 |
|
|
}
|
1210 |
|
|
|
1211 |
|
|
}
|
1212 |
|
|
|
1213 |
|
|
// Load module into DB
|
1214 |
|
|
function load_module($directory, $install = false) {
|
1215 |
249
|
stefan
|
global $database,$admin,$MESSAGE;
|
1216 |
238
|
stefan
|
if(file_exists($directory.'/info.php')) {
|
1217 |
|
|
require($directory.'/info.php');
|
1218 |
|
|
if(isset($module_name)) {
|
1219 |
|
|
if(!isset($module_license)) { $module_license = 'GNU General Public License'; }
|
1220 |
|
|
if(!isset($module_platform) AND isset($module_designed_for)) { $module_platform = $module_designed_for; }
|
1221 |
|
|
if(!isset($module_function) AND isset($module_type)) { $module_function = $module_type; }
|
1222 |
|
|
$module_function = strtolower($module_function);
|
1223 |
|
|
// Check that it doesn't already exist
|
1224 |
|
|
$result = $database->query("SELECT addon_id FROM ".TABLE_PREFIX."addons WHERE directory = '".$module_directory."' LIMIT 0,1");
|
1225 |
|
|
if($result->numRows() == 0) {
|
1226 |
|
|
// Load into DB
|
1227 |
|
|
$query = "INSERT INTO ".TABLE_PREFIX."addons ".
|
1228 |
|
|
"(directory,name,description,type,function,version,platform,author,license) ".
|
1229 |
|
|
"VALUES ('$module_directory','$module_name','".addslashes($module_description)."','module',".
|
1230 |
|
|
"'$module_function','$module_version','$module_platform','$module_author','$module_license')";
|
1231 |
|
|
$database->query($query);
|
1232 |
|
|
// Run installation script
|
1233 |
|
|
if($install == true) {
|
1234 |
|
|
if(file_exists($directory.'/install.php')) {
|
1235 |
|
|
require($directory.'/install.php');
|
1236 |
|
|
}
|
1237 |
|
|
}
|
1238 |
|
|
}
|
1239 |
|
|
}
|
1240 |
|
|
}
|
1241 |
|
|
}
|
1242 |
|
|
|
1243 |
|
|
// Load template into DB
|
1244 |
|
|
function load_template($directory) {
|
1245 |
|
|
global $database;
|
1246 |
|
|
if(file_exists($directory.'/info.php')) {
|
1247 |
|
|
require($directory.'/info.php');
|
1248 |
|
|
if(isset($template_name)) {
|
1249 |
|
|
if(!isset($template_license)) { $template_license = 'GNU General Public License'; }
|
1250 |
|
|
if(!isset($template_platform) AND isset($template_designed_for)) { $template_platform = $template_designed_for; }
|
1251 |
|
|
// Check that it doesn't already exist
|
1252 |
|
|
$result = $database->query("SELECT addon_id FROM ".TABLE_PREFIX."addons WHERE directory = '".$template_directory."' LIMIT 0,1");
|
1253 |
|
|
if($result->numRows() == 0) {
|
1254 |
|
|
// Load into DB
|
1255 |
|
|
$query = "INSERT INTO ".TABLE_PREFIX."addons ".
|
1256 |
|
|
"(directory,name,description,type,version,platform,author,license) ".
|
1257 |
|
|
"VALUES ('$template_directory','$template_name','".addslashes($template_description)."','template',".
|
1258 |
|
|
"'$template_version','$template_platform','$template_author','$template_license')";
|
1259 |
|
|
$database->query($query);
|
1260 |
|
|
}
|
1261 |
|
|
}
|
1262 |
|
|
}
|
1263 |
|
|
}
|
1264 |
|
|
|
1265 |
|
|
// Load language into DB
|
1266 |
|
|
function load_language($file) {
|
1267 |
|
|
global $database;
|
1268 |
|
|
if(file_exists($file)) {
|
1269 |
|
|
require($file);
|
1270 |
|
|
if(isset($language_name)) {
|
1271 |
|
|
if(!isset($language_license)) { $language_license = 'GNU General Public License'; }
|
1272 |
|
|
if(!isset($language_platform) AND isset($language_designed_for)) { $language_platform = $language_designed_for; }
|
1273 |
|
|
// Check that it doesn't already exist
|
1274 |
|
|
$result = $database->query("SELECT addon_id FROM ".TABLE_PREFIX."addons WHERE directory = '".$language_code."' LIMIT 0,1");
|
1275 |
|
|
if($result->numRows() == 0) {
|
1276 |
|
|
// Load into DB
|
1277 |
|
|
$query = "INSERT INTO ".TABLE_PREFIX."addons ".
|
1278 |
|
|
"(directory,name,type,version,platform,author,license) ".
|
1279 |
|
|
"VALUES ('$language_code','$language_name','language',".
|
1280 |
|
|
"'$language_version','$language_platform','$language_author','$language_license')";
|
1281 |
|
|
$database->query($query);
|
1282 |
|
|
}
|
1283 |
|
|
}
|
1284 |
|
|
}
|
1285 |
|
|
}
|
1286 |
|
|
|
1287 |
373
|
Ruebenwurz
|
// Upgrade module info in DB, optionally start upgrade script
|
1288 |
|
|
function upgrade_module($directory, $upgrade = false) {
|
1289 |
|
|
global $database, $admin, $MESSAGE;
|
1290 |
|
|
$directory = WB_PATH . "/modules/$directory";
|
1291 |
|
|
if(file_exists($directory.'/info.php')) {
|
1292 |
|
|
require($directory.'/info.php');
|
1293 |
|
|
if(isset($module_name)) {
|
1294 |
|
|
if(!isset($module_license)) { $module_license = 'GNU General Public License'; }
|
1295 |
|
|
if(!isset($module_platform) AND isset($module_designed_for)) { $module_platform = $module_designed_for; }
|
1296 |
|
|
if(!isset($module_function) AND isset($module_type)) { $module_function = $module_type; }
|
1297 |
|
|
$module_function = strtolower($module_function);
|
1298 |
|
|
// Check that it does already exist
|
1299 |
|
|
$result = $database->query("SELECT addon_id FROM ".TABLE_PREFIX."addons WHERE directory = '".$module_directory."' LIMIT 0,1");
|
1300 |
|
|
if($result->numRows() > 0) {
|
1301 |
|
|
// Update in DB
|
1302 |
|
|
$query = "UPDATE " . TABLE_PREFIX . "addons SET " .
|
1303 |
|
|
"version = '$module_version', " .
|
1304 |
|
|
"description = '" . addslashes($module_description) . "', " .
|
1305 |
|
|
"platform = '$module_platform', " .
|
1306 |
|
|
"author = '$module_author', " .
|
1307 |
|
|
"license = '$module_license'" .
|
1308 |
|
|
"WHERE directory = '$module_directory'";
|
1309 |
|
|
$database->query($query);
|
1310 |
|
|
// Run upgrade script
|
1311 |
|
|
if($upgrade == true) {
|
1312 |
|
|
if(file_exists($directory.'/upgrade.php')) {
|
1313 |
|
|
require($directory.'/upgrade.php');
|
1314 |
|
|
}
|
1315 |
|
|
}
|
1316 |
|
|
}
|
1317 |
|
|
}
|
1318 |
|
|
}
|
1319 |
|
|
}
|
1320 |
|
|
|
1321 |
543
|
thorn
|
?>
|