1 |
238
|
stefan
|
<?php
|
2 |
|
|
|
3 |
|
|
// $Id$
|
4 |
|
|
|
5 |
|
|
/*
|
6 |
|
|
|
7 |
|
|
Website Baker Project <http://www.websitebaker.org/>
|
8 |
519
|
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 |
|
|
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 |
504
|
Ruebenwurz
|
// Function as replacement for php's htmlspecialchars()
|
342 |
442
|
Ruebenwurz
|
function my_htmlspecialchars($string) {
|
343 |
476
|
Ruebenwurz
|
$string = preg_replace("/&(?=[#a-z0-9]+;)/i", "_x_", $string);
|
344 |
490
|
Ruebenwurz
|
$string = strtr($string, array("<"=>"<", ">"=>">", "&"=>"&", "\""=>""", "\'"=>"'"));
|
345 |
476
|
Ruebenwurz
|
$string = preg_replace("/_x_(?=[#a-z0-9]+;)/i", "&", $string);
|
346 |
442
|
Ruebenwurz
|
return($string);
|
347 |
|
|
}
|
348 |
|
|
|
349 |
|
|
// Function to convert a string from $from- to $to-encoding, using mysql
|
350 |
|
|
function my_mysql_iconv($string, $from, $to) {
|
351 |
482
|
Ruebenwurz
|
// keep current character set values
|
352 |
|
|
global $database;
|
353 |
|
|
$query = $database->query("SELECT @@character_set_client");
|
354 |
|
|
if($query->numRows() > 0) {
|
355 |
|
|
$res = $query->fetchRow();
|
356 |
|
|
$character_set_database = $res['@@character_set_client'];
|
357 |
|
|
} else { echo mysql_error()."\n<br />"; }
|
358 |
|
|
$query = $database->query("SELECT @@character_set_results");
|
359 |
|
|
if($query->numRows() > 0) {
|
360 |
|
|
$res = $query->fetchRow();
|
361 |
|
|
$character_set_results = $res['@@character_set_results'];
|
362 |
|
|
} else { echo mysql_error()."\n<br />"; }
|
363 |
|
|
$query = $database->query("SELECT @@collation_connection");
|
364 |
|
|
if($query->numRows() > 0) {
|
365 |
|
|
$res = $query->fetchRow();
|
366 |
|
|
$collation_results = $res['@@collation_connection'];
|
367 |
|
|
} else { echo mysql_error()."\n<br />"; }
|
368 |
|
|
// set new character set values
|
369 |
|
|
$query = $database->query("SET character_set_client=$from");
|
370 |
|
|
$query = $database->query("SET character_set_results=$to");
|
371 |
|
|
$query = $database->query("SET collation_connection=utf8_unicode_ci");
|
372 |
442
|
Ruebenwurz
|
$string_escaped = mysql_real_escape_string($string);
|
373 |
482
|
Ruebenwurz
|
// convert the string
|
374 |
|
|
$query = $database->query("SELECT '$string_escaped'");
|
375 |
|
|
if($query->numRows() > 0) {
|
376 |
|
|
$res = $query->fetchRow();
|
377 |
|
|
$converted_string = $res[0];
|
378 |
|
|
} else { echo mysql_error()."\n<br />"; }
|
379 |
|
|
// restore previous character set values
|
380 |
|
|
$query = $database->query("SET character_set_client=$character_set_database");
|
381 |
|
|
$query = $database->query("SET character_set_results=$character_set_results");
|
382 |
|
|
$query = $database->query("SET collation_connection=$collation_results");
|
383 |
442
|
Ruebenwurz
|
return $converted_string;
|
384 |
|
|
}
|
385 |
|
|
|
386 |
455
|
Ruebenwurz
|
// Function as wrapper for mb_convert_encoding
|
387 |
461
|
Ruebenwurz
|
// converts $charset_in to $charset_out or
|
388 |
|
|
// UTF-8 to HTML-ENTITIES or HTML-ENTITIES to UTF-8
|
389 |
455
|
Ruebenwurz
|
function mb_convert_encoding_wrapper($string, $charset_out, $charset_in) {
|
390 |
464
|
Ruebenwurz
|
if ($charset_out == $charset_in) {
|
391 |
|
|
return $string;
|
392 |
|
|
}
|
393 |
476
|
Ruebenwurz
|
$use_iconv = true;
|
394 |
|
|
$use_mbstring = true;
|
395 |
482
|
Ruebenwurz
|
/*
|
396 |
476
|
Ruebenwurz
|
if(version_compare(PHP_VERSION, "5.1.0", "<")) {
|
397 |
|
|
$use_mbstring = false; // don't rely on mb_convert_encoding if php<5.1.0
|
398 |
|
|
$use_iconv = false; // don't rely on iconv neither
|
399 |
|
|
}
|
400 |
482
|
Ruebenwurz
|
*/
|
401 |
476
|
Ruebenwurz
|
|
402 |
461
|
Ruebenwurz
|
// try mb_convert_encoding(). This can handle to or from HTML-ENTITIES, too
|
403 |
476
|
Ruebenwurz
|
if ($use_mbstring && function_exists('mb_convert_encoding')) {
|
404 |
461
|
Ruebenwurz
|
// there's no GB2312 or ISO-8859-11 encoding in php's mb_* functions
|
405 |
|
|
if ($charset_in=='ISO-8859-11' || $charset_in=='GB2312') {
|
406 |
476
|
Ruebenwurz
|
if ($use_iconv && function_exists('iconv')) {
|
407 |
461
|
Ruebenwurz
|
$string = iconv($charset_in, 'UTF-8', $string);
|
408 |
455
|
Ruebenwurz
|
}
|
409 |
461
|
Ruebenwurz
|
else {
|
410 |
|
|
if ($charset_in == 'GB2312') {
|
411 |
|
|
$string=my_mysql_iconv($string, 'gb2312', 'utf8');
|
412 |
|
|
} else {
|
413 |
|
|
$string=my_mysql_iconv($string, 'tis620', 'utf8');
|
414 |
|
|
}
|
415 |
|
|
}
|
416 |
|
|
$charset_in='UTF-8';
|
417 |
|
|
if ($charset_out == 'UTF-8') {
|
418 |
|
|
return $string;
|
419 |
|
|
}
|
420 |
455
|
Ruebenwurz
|
}
|
421 |
461
|
Ruebenwurz
|
if ($charset_out=='ISO-8859-11' || $charset_out=='GB2312') {
|
422 |
|
|
$string=mb_convert_encoding($string, 'UTF-8', $charset_in);
|
423 |
476
|
Ruebenwurz
|
if ($use_iconv && function_exists('iconv')) {
|
424 |
461
|
Ruebenwurz
|
$string = iconv('UTF-8', $charset_out, $string);
|
425 |
455
|
Ruebenwurz
|
}
|
426 |
461
|
Ruebenwurz
|
else {
|
427 |
|
|
if ($charset_out == 'GB2312') {
|
428 |
|
|
$string=my_mysql_iconv($string, 'utf8', 'gb2312');
|
429 |
|
|
} else {
|
430 |
|
|
$string=my_mysql_iconv($string, 'utf8', 'tis620');
|
431 |
455
|
Ruebenwurz
|
}
|
432 |
|
|
}
|
433 |
461
|
Ruebenwurz
|
} else {
|
434 |
490
|
Ruebenwurz
|
$string = strtr($string, array("<"=>"&_lt;", ">"=>"&_gt;", "&"=>"&_amp;", """=>"&_quot;", "'"=>"&_#39;"));
|
435 |
461
|
Ruebenwurz
|
$string=mb_convert_encoding($string, $charset_out, $charset_in);
|
436 |
490
|
Ruebenwurz
|
$string = strtr($string, array("&_lt;"=>"<", "&_gt;"=>">", "&_amp;"=>"&", "&_quot;"=>""", "&_#39;"=>"'"));
|
437 |
455
|
Ruebenwurz
|
}
|
438 |
461
|
Ruebenwurz
|
return $string;
|
439 |
455
|
Ruebenwurz
|
}
|
440 |
461
|
Ruebenwurz
|
|
441 |
|
|
// try iconv(). This can't handle to or from HTML-ENTITIES.
|
442 |
476
|
Ruebenwurz
|
if ($use_iconv && function_exists('iconv') && $charset_out!='HTML-ENTITIES' && $charset_in!='HTML-ENTITIES' ) {
|
443 |
461
|
Ruebenwurz
|
$string = iconv($charset_in, $charset_out, $string);
|
444 |
|
|
return $string;
|
445 |
|
|
}
|
446 |
|
|
|
447 |
476
|
Ruebenwurz
|
// do the UTF-8->HTML-ENTITIES or HTML-ENTITIES->UTF-8 translation if mb_convert_encoding isn't available
|
448 |
461
|
Ruebenwurz
|
if (($charset_in=='HTML-ENTITIES' && $charset_out=='UTF-8') || ($charset_in=='UTF-8' && $charset_out=='HTML-ENTITIES')) {
|
449 |
476
|
Ruebenwurz
|
$string = string_decode_encode_entities($string, $charset_out, $charset_in);
|
450 |
461
|
Ruebenwurz
|
return $string;
|
451 |
|
|
}
|
452 |
|
|
|
453 |
|
|
// mb_convert_encoding() and iconv() aren't available, so use my_mysql_iconv()
|
454 |
|
|
if ($charset_in == 'ISO-8859-1') { $mysqlcharset_from = 'latin1'; }
|
455 |
|
|
elseif ($charset_in == 'ISO-8859-2') { $mysqlcharset_from = 'latin2'; }
|
456 |
|
|
elseif ($charset_in == 'ISO-8859-3') { $mysqlcharset_from = 'latin1'; }
|
457 |
|
|
elseif ($charset_in == 'ISO-8859-4') { $mysqlcharset_from = 'latin7'; }
|
458 |
|
|
elseif ($charset_in == 'ISO-8859-5') { $string = convert_cyr_string ($string, "iso8859-5", "windows-1251" ); $mysqlcharset_from = 'cp1251'; }
|
459 |
|
|
elseif ($charset_in == 'ISO-8859-6') { $mysqlcharset_from = ''; } //?
|
460 |
|
|
elseif ($charset_in == 'ISO-8859-7') { $mysqlcharset_from = 'greek'; }
|
461 |
|
|
elseif ($charset_in == 'ISO-8859-8') { $mysqlcharset_from = 'hebrew'; }
|
462 |
|
|
elseif ($charset_in == 'ISO-8859-9') { $mysqlcharset_from = 'latin5'; }
|
463 |
|
|
elseif ($charset_in == 'ISO-8859-10') { $mysqlcharset_from = 'latin1'; }
|
464 |
|
|
elseif ($charset_in == 'BIG5') { $mysqlcharset_from = 'big5'; }
|
465 |
|
|
elseif ($charset_in == 'ISO-2022-JP') { $mysqlcharset_from = ''; } //?
|
466 |
|
|
elseif ($charset_in == 'ISO-2022-KR') { $mysqlcharset_from = ''; } //?
|
467 |
|
|
elseif ($charset_in == 'GB2312') { $mysqlcharset_from = 'gb2312'; }
|
468 |
|
|
elseif ($charset_in == 'ISO-8859-11') { $mysqlcharset_from = 'tis620'; }
|
469 |
|
|
elseif ($charset_in == 'UTF-8') { $mysqlcharset_from = 'utf8'; }
|
470 |
|
|
else { $mysqlcharset_from = 'latin1'; }
|
471 |
|
|
|
472 |
|
|
if ($charset_out == 'ISO-8859-1') { $mysqlcharset_to = 'latin1'; }
|
473 |
|
|
elseif ($charset_out == 'ISO-8859-2') { $mysqlcharset_to = 'latin2'; }
|
474 |
|
|
elseif ($charset_out == 'ISO-8859-3') { $mysqlcharset_to = 'latin1'; }
|
475 |
|
|
elseif ($charset_out == 'ISO-8859-4') { $mysqlcharset_to = 'latin7'; }
|
476 |
|
|
elseif ($charset_out == 'ISO-8859-5') { $mysqlcharset_to = 'cp1251'; } // use convert_cyr_string afterwards
|
477 |
|
|
elseif ($charset_out == 'ISO-8859-6') { $mysqlcharset_to = ''; } //?
|
478 |
|
|
elseif ($charset_out == 'ISO-8859-7') { $mysqlcharset_to = 'greek'; }
|
479 |
|
|
elseif ($charset_out == 'ISO-8859-8') { $mysqlcharset_to = 'hebrew'; }
|
480 |
|
|
elseif ($charset_out == 'ISO-8859-9') { $mysqlcharset_to = 'latin5'; }
|
481 |
|
|
elseif ($charset_out == 'ISO-8859-10') { $mysqlcharset_to = 'latin1'; }
|
482 |
|
|
elseif ($charset_out == 'BIG5') { $mysqlcharset_to = 'big5'; }
|
483 |
|
|
elseif ($charset_out == 'ISO-2022-JP') { $mysqlcharset_to = ''; } //?
|
484 |
|
|
elseif ($charset_out == 'ISO-2022-KR') { $mysqlcharset_to = ''; } //?
|
485 |
|
|
elseif ($charset_out == 'GB2312') { $mysqlcharset_to = 'gb2312'; }
|
486 |
|
|
elseif ($charset_out == 'ISO-8859-11') { $mysqlcharset_to = 'tis620'; }
|
487 |
|
|
elseif ($charset_out == 'UTF-8') { $mysqlcharset_to = 'utf8'; }
|
488 |
|
|
else { $mysqlcharset_to = 'latin1'; }
|
489 |
|
|
|
490 |
|
|
if ($mysqlcharset_from!="" && $mysqlcharset_to!="" && $mysqlcharset_from!=$mysqlcharset_to) {
|
491 |
|
|
$string=my_mysql_iconv($string, $mysqlcharset_from, $mysqlcharset_to);
|
492 |
|
|
if ($mysqlcharset_to == 'cp1251') {
|
493 |
|
|
$string = convert_cyr_string ($string, "windows-1251", "iso-8859-5" );
|
494 |
|
|
}
|
495 |
|
|
return($string);
|
496 |
|
|
}
|
497 |
|
|
|
498 |
|
|
// $string is unchanged. This will happen if we have to deal with ISO-8859-6 or ISO-2022-JP or -KR
|
499 |
|
|
// and mbstring _and_ iconv aren't available.
|
500 |
|
|
return $string;
|
501 |
455
|
Ruebenwurz
|
}
|
502 |
476
|
Ruebenwurz
|
|
503 |
|
|
// Decodes or encodes html-entities. Works for utf-8 only!
|
504 |
|
|
function string_decode_encode_entities($string, $out='HTML-ENTITIES', $in='UTF-8') {
|
505 |
|
|
if(!(($in=='UTF-8' || $in=='HTML-ENTITIES') && ($out=='UTF-8' || $out=='HTML-ENTITIES'))) {
|
506 |
|
|
return $string;
|
507 |
|
|
}
|
508 |
|
|
$named_to_numbered_entities=array(
|
509 |
|
|
'Á'=>'Á','á'=>'á',
|
510 |
|
|
'Â'=>'Â','â'=>'â','´'=>'´','Æ'=>'Æ','æ'=>'æ',
|
511 |
|
|
'À'=>'À','à'=>'à','ℵ'=>'ℵ','Α'=>'Α','α'=>'α',
|
512 |
478
|
Ruebenwurz
|
'∧'=>'∧','∠'=>'∠','''=>''','Å'=>'Å','å'=>'å',
|
513 |
476
|
Ruebenwurz
|
'≈'=>'≈','Ã'=>'Ã','ã'=>'ã','Ä'=>'Ä','ä'=>'ä',
|
514 |
|
|
'„'=>'„','Β'=>'Β','β'=>'β','¦'=>'¦','•'=>'•',
|
515 |
|
|
'∩'=>'∩','Ç'=>'Ç','ç'=>'ç','¸'=>'¸','¢'=>'¢',
|
516 |
|
|
'Χ'=>'Χ','χ'=>'χ','ˆ'=>'ˆ','♣'=>'♣','≅'=>'≅',
|
517 |
|
|
'©'=>'©','↵'=>'↵','∪'=>'∪','¤'=>'¤','‡'=>'‡',
|
518 |
|
|
'†'=>'†','⇓'=>'⇓','↓'=>'↓','°'=>'°','Δ'=>'Δ',
|
519 |
|
|
'δ'=>'δ','♦'=>'&v#9830;','÷'=>'÷','É'=>'É','é'=>'é',
|
520 |
|
|
'Ê'=>'Ê','ê'=>'ê','È'=>'È','è'=>'è','∅'=>'∅',
|
521 |
|
|
' '=>' ',' '=>' ','Ε'=>'Ε','ε'=>'ε','≡'=>'≡',
|
522 |
|
|
'Η'=>'Η','η'=>'η','Ð'=>'Ð','ð'=>'ð','Ë'=>'Ë','ë'=>'ë',
|
523 |
|
|
'€'=>'€','∃'=>'∃','ƒ'=>'ƒ','∀'=>'∀','½'=>'½',
|
524 |
|
|
'¼'=>'¼','¾'=>'¾','⁄'=>'⁄','Γ'=>'Γ','γ'=>'γ',
|
525 |
478
|
Ruebenwurz
|
'≥'=>'≥','⇔'=>'⇔','↔'=>'↔','♥'=>'♥',
|
526 |
476
|
Ruebenwurz
|
'…'=>'…','Í'=>'Í','í'=>'í','Î'=>'Î','î'=>'î',
|
527 |
|
|
'¡'=>'¡','Ì'=>'Ì','ì'=>'ì','ℑ'=>'ℑ','∞'=>'∞',
|
528 |
|
|
'∫'=>'∫','Ι'=>'Ι','ι'=>'ι','¿'=>'¿','∈'=>'∈',
|
529 |
|
|
'Ï'=>'Ï','ï'=>'ï','Κ'=>'Κ','κ'=>'κ','Λ'=>'Λ',
|
530 |
|
|
'λ'=>'λ','⟨'=>'〈','«'=>'«','⇐'=>'⇐','←'=>'←',
|
531 |
|
|
'⌈'=>'⌈','“'=>'“','≤'=>'≤','⌊'=>'⌊','∗'=>'∗',
|
532 |
478
|
Ruebenwurz
|
'◊'=>'◊','‎'=>'‎','‹'=>'‹','‘'=>'‘',
|
533 |
476
|
Ruebenwurz
|
'¯'=>'¯','—'=>'—','µ'=>'µ','·'=>'·','−'=>'−',
|
534 |
|
|
'Μ'=>'Μ','μ'=>'μ','∇'=>'∇',' '=>' ','–'=>'–',
|
535 |
|
|
'≠'=>'≠','∋'=>'∋','¬'=>'¬','∉'=>'∉','⊄'=>'⊄',
|
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 |
|
|
$numbered_to_named_entities=array(
|
562 |
|
|
'Á'=>'Á','á'=>'á','Â'=>'Â','â'=>'â','´'=>'´',
|
563 |
|
|
'Æ'=>'Æ','æ'=>'æ','À'=>'À','à'=>'à','ℵ'=>'ℵ',
|
564 |
478
|
Ruebenwurz
|
'Α'=>'Α','α'=>'α','∧'=>'∧','∠'=>'∠',
|
565 |
476
|
Ruebenwurz
|
'''=>''','Å'=>'Å','å'=>'å','≈'=>'≈','Ã'=>'Ã',
|
566 |
|
|
'ã'=>'ã','Ä'=>'Ä','ä'=>'ä','„'=>'„','Β'=>'Β',
|
567 |
|
|
'β'=>'β','¦'=>'¦','•'=>'•','∩'=>'∩','Ç'=>'Ç',
|
568 |
|
|
'ç'=>'ç','¸'=>'¸','¢'=>'¢','Χ'=>'Χ','χ'=>'χ',
|
569 |
|
|
'ˆ'=>'ˆ','♣'=>'♣','≅'=>'≅','©'=>'©','↵'=>'↵',
|
570 |
|
|
'∪'=>'∪','¤'=>'¤','‡'=>'‡','†'=>'†','⇓'=>'⇓',
|
571 |
|
|
'↓'=>'↓','°'=>'°','Δ'=>'Δ','δ'=>'δ','&v#9830;'=>'♦',
|
572 |
|
|
'÷'=>'÷','É'=>'É','é'=>'é','Ê'=>'Ê','ê'=>'ê',
|
573 |
|
|
'È'=>'È','è'=>'è','∅'=>'∅',' '=>' ',' '=>' ',
|
574 |
|
|
'Ε'=>'Ε','ε'=>'ε','≡'=>'≡','Η'=>'Η','η'=>'η',
|
575 |
|
|
'Ð'=>'Ð','ð'=>'ð','Ë'=>'Ë','ë'=>'ë','€'=>'€',
|
576 |
|
|
'∃'=>'∃','ƒ'=>'ƒ','∀'=>'∀','½'=>'½','¼'=>'¼',
|
577 |
|
|
'¾'=>'¾','⁄'=>'⁄','Γ'=>'Γ','γ'=>'γ','≥'=>'≥',
|
578 |
478
|
Ruebenwurz
|
'⇔'=>'⇔','↔'=>'↔','♥'=>'♥','…'=>'…',
|
579 |
476
|
Ruebenwurz
|
'Í'=>'Í','í'=>'í','Î'=>'Î','î'=>'î','¡'=>'¡',
|
580 |
|
|
'Ì'=>'Ì','ì'=>'ì','ℑ'=>'ℑ','∞'=>'∞','∫'=>'∫',
|
581 |
|
|
'Ι'=>'Ι','ι'=>'ι','¿'=>'¿','∈'=>'∈','Ï'=>'Ï',
|
582 |
|
|
'ï'=>'ï','Κ'=>'Κ','κ'=>'κ','Λ'=>'Λ','λ'=>'λ',
|
583 |
|
|
'〈'=>'⟨','«'=>'«','⇐'=>'⇐','←'=>'←','⌈'=>'⌈',
|
584 |
|
|
'“'=>'“','≤'=>'≤','⌊'=>'⌊','∗'=>'∗','◊'=>'◊',
|
585 |
478
|
Ruebenwurz
|
'‎'=>'‎','‹'=>'‹','‘'=>'‘','¯'=>'¯',
|
586 |
476
|
Ruebenwurz
|
'—'=>'—','µ'=>'µ','·'=>'·','−'=>'−','Μ'=>'Μ',
|
587 |
|
|
'μ'=>'μ','∇'=>'∇',' '=>' ','–'=>'–','≠'=>'≠',
|
588 |
|
|
'∋'=>'∋','¬'=>'¬','∉'=>'∉','⊄'=>'⊄','Ñ'=>'Ñ',
|
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 |
|
|
if ($in == 'HTML-ENTITIES') {
|
616 |
|
|
$string = strtr($string, $named_to_numbered_entities);
|
617 |
|
|
$string = preg_replace("/&#([0-9]+);/e", "code_to_utf8($1)", $string);
|
618 |
|
|
}
|
619 |
|
|
elseif ($out == 'HTML-ENTITIES') {
|
620 |
|
|
$char = "";
|
621 |
504
|
Ruebenwurz
|
$i=0;
|
622 |
|
|
$len=strlen($string);
|
623 |
|
|
if($len==0) return $string;
|
624 |
|
|
do {
|
625 |
|
|
if(ord($string{$i}) <= 127) $ud = $string{$i++};
|
626 |
|
|
elseif(ord($string{$i}) <= 223) $ud = (ord($string{$i++})-192)*64 + (ord($string{$i++})-128);
|
627 |
|
|
elseif(ord($string{$i}) <= 239) $ud = (ord($string{$i++})-224)*4096 + (ord($string{$i++})-128)*64 + (ord($string{$i++})-128);
|
628 |
|
|
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);
|
629 |
|
|
elseif(ord($string{$i}) <= 251) $ud = ord($string{$i++}); // error!
|
630 |
|
|
if($ud > 127) {
|
631 |
|
|
$char .= "&#$ud;";
|
632 |
|
|
} else {
|
633 |
|
|
$char .= $ud;
|
634 |
|
|
}
|
635 |
|
|
} while($i < $len);
|
636 |
476
|
Ruebenwurz
|
$string = $char;
|
637 |
|
|
$string = strtr($string, $numbered_to_named_entities);
|
638 |
493
|
Ruebenwurz
|
// do ' and "
|
639 |
|
|
$string = strtr($string, array('\''=>''', '\"'=>'"'));
|
640 |
476
|
Ruebenwurz
|
}
|
641 |
|
|
return $string;
|
642 |
|
|
}
|
643 |
|
|
|
644 |
|
|
// support-function for string_decode_encode_entities()
|
645 |
455
|
Ruebenwurz
|
function code_to_utf8($num) {
|
646 |
|
|
if ($num <= 0x7F) {
|
647 |
|
|
return chr($num);
|
648 |
|
|
} elseif ($num <= 0x7FF) {
|
649 |
|
|
return chr(($num >> 6) + 192) . chr(($num & 63) + 128);
|
650 |
|
|
} elseif ($num <= 0xFFFF) {
|
651 |
|
|
return chr(($num >> 12) + 224) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128);
|
652 |
|
|
} elseif ($num <= 0x1FFFFF) {
|
653 |
|
|
return chr(($num >> 18) + 240) . chr((($num >> 12) & 63) + 128) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128);
|
654 |
|
|
}
|
655 |
|
|
return " ";
|
656 |
|
|
}
|
657 |
|
|
|
658 |
445
|
Ruebenwurz
|
// Function to convert a string from mixed html-entities/umlauts to pure utf-8-umlauts
|
659 |
|
|
function string_to_utf8($string, $charset=DEFAULT_CHARSET) {
|
660 |
|
|
$charset = strtoupper($charset);
|
661 |
|
|
if ($charset == '') { $charset = 'ISO-8859-1'; }
|
662 |
|
|
|
663 |
461
|
Ruebenwurz
|
if (!is_UTF8($string)) {
|
664 |
455
|
Ruebenwurz
|
$string=mb_convert_encoding_wrapper($string, 'UTF-8', $charset);
|
665 |
442
|
Ruebenwurz
|
}
|
666 |
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
|
667 |
|
|
// and mb_string AND iconv aren't available.
|
668 |
461
|
Ruebenwurz
|
if (is_UTF8($string)) {
|
669 |
|
|
$string=mb_convert_encoding_wrapper($string, 'HTML-ENTITIES', 'UTF-8');
|
670 |
|
|
$string=mb_convert_encoding_wrapper($string, 'UTF-8', 'HTML-ENTITIES');
|
671 |
|
|
} else {
|
672 |
464
|
Ruebenwurz
|
// nothing we can do here :-(
|
673 |
461
|
Ruebenwurz
|
}
|
674 |
442
|
Ruebenwurz
|
return($string);
|
675 |
|
|
}
|
676 |
|
|
|
677 |
461
|
Ruebenwurz
|
// function to check if a string is UTF-8
|
678 |
464
|
Ruebenwurz
|
function is_UTF8 ($str) {
|
679 |
|
|
if (strlen($str) < 4000) {
|
680 |
|
|
// 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.
|
681 |
|
|
// 4000 works for me ...
|
682 |
|
|
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);
|
683 |
|
|
} else {
|
684 |
|
|
$isUTF8 = true;
|
685 |
|
|
while($str{0}) {
|
686 |
|
|
if (preg_match("/^[\x09\x0A\x0D\x20-\x7E]/", $str)) { $str = substr($str, 1); continue; }
|
687 |
|
|
if (preg_match("/^[\xC2-\xDF][\x80-\xBF]/", $str)) { $str = substr($str, 2); continue; }
|
688 |
|
|
if (preg_match("/^\xE0[\xA0-\xBF][\x80-\xBF]/", $str)) { $str = substr($str, 3); continue; }
|
689 |
|
|
if (preg_match("/^[\xE1-\xEC\xEE\xEF][\x80-\xBF]{2}/", $str)) { $str = substr($str, 3); continue; }
|
690 |
|
|
if (preg_match("/^\xED[\x80-\x9F][\x80-\xBF]/", $str)) { $str = substr($str, 3); continue; }
|
691 |
|
|
if (preg_match("/^\xF0[\x90-\xBF][\x80-\xBF]{2}/", $str)) { $str = substr($str, 4); continue; }
|
692 |
|
|
if (preg_match("/^[\xF1-\xF3][\x80-\xBF]{3}/", $str)) { $str = substr($str, 4); continue; }
|
693 |
|
|
if (preg_match("/^\xF4[\x80-\x8F][\x80-\xBF]{2}/", $str)) { $str = substr($str, 4); continue; }
|
694 |
|
|
if (preg_match("/^$/", $str)) { break; }
|
695 |
|
|
$isUTF8 = false;
|
696 |
|
|
break;
|
697 |
|
|
}
|
698 |
|
|
return ($isUTF8);
|
699 |
|
|
}
|
700 |
461
|
Ruebenwurz
|
}
|
701 |
|
|
|
702 |
445
|
Ruebenwurz
|
// Function to convert a string from mixed html-entities/umlauts to pure $charset_out-umlauts
|
703 |
504
|
Ruebenwurz
|
function entities_to_umlauts($string, $charset_out=DEFAULT_CHARSET) {
|
704 |
445
|
Ruebenwurz
|
$charset_out = strtoupper($charset_out);
|
705 |
461
|
Ruebenwurz
|
if ($charset_out == '') { $charset_out = 'ISO-8859-1'; }
|
706 |
476
|
Ruebenwurz
|
$charset_in = strtoupper(DEFAULT_CHARSET);
|
707 |
504
|
Ruebenwurz
|
require_once(WB_PATH.'/framework/charsets_table.php');
|
708 |
|
|
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;
|
709 |
|
|
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;
|
710 |
|
|
|
711 |
|
|
// string to utf-8, entities_to_utf8
|
712 |
|
|
if (substr($charset_in,0,8) == 'ISO-8859' || $charset_in == 'UTF-8') {
|
713 |
476
|
Ruebenwurz
|
if ($charset_in == 'ISO-8859-1') {
|
714 |
|
|
$string=utf8_encode($string);
|
715 |
504
|
Ruebenwurz
|
} elseif ($charset_in == 'ISO-8859-2') {
|
716 |
|
|
$string = strtr($string, $iso_8859_2_to_utf8);
|
717 |
|
|
} elseif ($charset_in == 'ISO-8859-3') {
|
718 |
|
|
$string = strtr($string, $iso_8859_3_to_utf8);
|
719 |
|
|
} elseif ($charset_in == 'ISO-8859-4') {
|
720 |
|
|
$string = strtr($string, $iso_8859_4_to_utf8);
|
721 |
|
|
} elseif ($charset_in == 'ISO-8859-5') {
|
722 |
|
|
$string = strtr($string, $iso_8859_5_to_utf8);
|
723 |
|
|
} elseif ($charset_in == 'ISO-8859-6') {
|
724 |
|
|
$string = strtr($string, $iso_8859_6_to_utf8);
|
725 |
|
|
} elseif ($charset_in == 'ISO-8859-7') {
|
726 |
|
|
$string = strtr($string, $iso_8859_7_to_utf8);
|
727 |
|
|
} elseif ($charset_in == 'ISO-8859-8') {
|
728 |
|
|
$string = strtr($string, $iso_8859_8_to_utf8);
|
729 |
|
|
} elseif ($charset_in == 'ISO-8859-9') {
|
730 |
|
|
$string = strtr($string, $iso_8859_9_to_utf8);
|
731 |
|
|
} elseif ($charset_in == 'ISO-8859-10') {
|
732 |
|
|
$string = strtr($string, $iso_8859_10_to_utf8);
|
733 |
|
|
} elseif ($charset_in == 'ISO-8859-11') {
|
734 |
|
|
$string = strtr($string, $iso_8859_11_to_utf8);
|
735 |
476
|
Ruebenwurz
|
}
|
736 |
|
|
// decode html-entities
|
737 |
|
|
if(preg_match("/&[#a-zA-Z0-9]+;/", $string)) {
|
738 |
|
|
$string=string_decode_encode_entities($string, 'UTF-8', 'HTML-ENTITIES');
|
739 |
504
|
Ruebenwurz
|
//$string=mb_convert_encoding_wrapper($string, 'HTML-ENTITIES', 'UTF-8'); // alternative to string_decode_encode_entities()
|
740 |
478
|
Ruebenwurz
|
//$string=mb_convert_encoding_wrapper($string, 'UTF-8', 'HTML-ENTITIES');
|
741 |
476
|
Ruebenwurz
|
}
|
742 |
|
|
}
|
743 |
|
|
else {
|
744 |
|
|
$string = string_to_utf8($string); // will decode html-entities, too.
|
745 |
|
|
}
|
746 |
|
|
// string to $charset_out
|
747 |
|
|
if($charset_out == 'ISO-8859-1') {
|
748 |
|
|
$string=utf8_decode($string);
|
749 |
504
|
Ruebenwurz
|
} elseif($charset_out == 'ISO-8859-2') {
|
750 |
|
|
$string = strtr($string, $utf8_to_iso_8859_2);
|
751 |
|
|
} elseif($charset_out == 'ISO-8859-3') {
|
752 |
|
|
$string = strtr($string, $utf8_to_iso_8859_3);
|
753 |
|
|
} elseif($charset_out == 'ISO-8859-4') {
|
754 |
|
|
$string = strtr($string, $utf8_to_iso_8859_4);
|
755 |
|
|
} elseif($charset_out == 'ISO-8859-5') {
|
756 |
|
|
$string = strtr($string, $utf8_to_iso_8859_5);
|
757 |
|
|
} elseif($charset_out == 'ISO-8859-6') {
|
758 |
|
|
$string = strtr($string, $utf8_to_iso_8859_6);
|
759 |
|
|
} elseif($charset_out == 'ISO-8859-7') {
|
760 |
|
|
$string = strtr($string, $utf8_to_iso_8859_7);
|
761 |
|
|
} elseif($charset_out == 'ISO-8859-8') {
|
762 |
|
|
$string = strtr($string, $utf8_to_iso_8859_8);
|
763 |
|
|
} elseif($charset_out == 'ISO-8859-9') {
|
764 |
|
|
$string = strtr($string, $utf8_to_iso_8859_9);
|
765 |
|
|
} elseif($charset_out == 'ISO-8859-10') {
|
766 |
|
|
$string = strtr($string, $utf8_to_iso_8859_10);
|
767 |
|
|
} elseif($charset_out == 'ISO-8859-11') {
|
768 |
|
|
$string = strtr($string, $utf8_to_iso_8859_11);
|
769 |
|
|
} elseif($charset_out != 'UTF-8') {
|
770 |
|
|
if(is_UTF8($string)) {
|
771 |
|
|
$string=mb_convert_encoding_wrapper($string, $charset_out, 'UTF-8');
|
772 |
|
|
}
|
773 |
476
|
Ruebenwurz
|
}
|
774 |
|
|
return $string;
|
775 |
|
|
}
|
776 |
445
|
Ruebenwurz
|
|
777 |
|
|
// Function to convert a string from mixed html-entitites/$charset_in-umlauts to pure html-entities
|
778 |
504
|
Ruebenwurz
|
function umlauts_to_entities($string, $charset_in=DEFAULT_CHARSET) {
|
779 |
445
|
Ruebenwurz
|
$charset_in = strtoupper($charset_in);
|
780 |
461
|
Ruebenwurz
|
if ($charset_in == "") { $charset_in = 'ISO-8859-1'; }
|
781 |
504
|
Ruebenwurz
|
require_once(WB_PATH.'/framework/charsets_table.php');
|
782 |
|
|
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;
|
783 |
476
|
Ruebenwurz
|
|
784 |
504
|
Ruebenwurz
|
// string to utf-8, umlauts_to_entities
|
785 |
|
|
if ($charset_in == 'UTF-8' || substr($charset_in,0,8) == 'ISO-8859') {
|
786 |
476
|
Ruebenwurz
|
if ($charset_in == 'ISO-8859-1') {
|
787 |
|
|
$string=utf8_encode($string);
|
788 |
504
|
Ruebenwurz
|
} elseif ($charset_in == 'ISO-8859-2') {
|
789 |
|
|
$string = strtr($string, $iso_8859_2_to_utf8);
|
790 |
|
|
} elseif ($charset_in == 'ISO-8859-3') {
|
791 |
|
|
$string = strtr($string, $iso_8859_3_to_utf8);
|
792 |
|
|
} elseif ($charset_in == 'ISO-8859-4') {
|
793 |
|
|
$string = strtr($string, $iso_8859_4_to_utf8);
|
794 |
|
|
} elseif ($charset_in == 'ISO-8859-5') {
|
795 |
|
|
$string = strtr($string, $iso_8859_5_to_utf8);
|
796 |
|
|
} elseif ($charset_in == 'ISO-8859-6') {
|
797 |
|
|
$string = strtr($string, $iso_8859_6_to_utf8);
|
798 |
|
|
} elseif ($charset_in == 'ISO-8859-7') {
|
799 |
|
|
$string = strtr($string, $iso_8859_7_to_utf8);
|
800 |
|
|
} elseif ($charset_in == 'ISO-8859-8') {
|
801 |
|
|
$string = strtr($string, $iso_8859_8_to_utf8);
|
802 |
|
|
} elseif ($charset_in == 'ISO-8859-9') {
|
803 |
|
|
$string = strtr($string, $iso_8859_9_to_utf8);
|
804 |
|
|
} elseif ($charset_in == 'ISO-8859-10') {
|
805 |
|
|
$string = strtr($string, $iso_8859_10_to_utf8);
|
806 |
|
|
} elseif ($charset_in == 'ISO-8859-11') {
|
807 |
|
|
$string = strtr($string, $iso_8859_11_to_utf8);
|
808 |
476
|
Ruebenwurz
|
}
|
809 |
|
|
// encode html-entities
|
810 |
504
|
Ruebenwurz
|
$string=string_decode_encode_entities($string, 'HTML-ENTITIES', 'UTF-8');
|
811 |
482
|
Ruebenwurz
|
//$string=mb_convert_encoding_wrapper($string, 'HTML-ENTITIES', 'UTF-8');
|
812 |
461
|
Ruebenwurz
|
}
|
813 |
476
|
Ruebenwurz
|
else {
|
814 |
|
|
$string = string_to_utf8($string, $charset_in);
|
815 |
|
|
// encode html-entities
|
816 |
|
|
if (is_UTF8($string)) {
|
817 |
482
|
Ruebenwurz
|
$string=string_decode_encode_entities($string, 'HTML-ENTITIES', 'UTF-8');
|
818 |
|
|
//$string=mb_convert_encoding_wrapper($string, 'HTML-ENTITIES', 'UTF-8');
|
819 |
476
|
Ruebenwurz
|
}
|
820 |
|
|
}
|
821 |
|
|
return $string;
|
822 |
442
|
Ruebenwurz
|
}
|
823 |
|
|
|
824 |
482
|
Ruebenwurz
|
function umlauts_to_defcharset($string, $charset) {
|
825 |
|
|
$charset_out = strtoupper(DEFAULT_CHARSET);
|
826 |
|
|
if ($charset_out == "") { $charset_out = 'ISO-8859-1'; }
|
827 |
504
|
Ruebenwurz
|
require_once(WB_PATH.'/framework/charsets_table.php');
|
828 |
|
|
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;
|
829 |
482
|
Ruebenwurz
|
|
830 |
|
|
if($charset_out == $charset) {
|
831 |
|
|
return $string;
|
832 |
|
|
}
|
833 |
504
|
Ruebenwurz
|
|
834 |
|
|
if($charset == 'UTF-8') {
|
835 |
|
|
if($charset_out == 'ISO-8859-1') {
|
836 |
|
|
$string = utf8_decode($string);
|
837 |
|
|
} elseif ($charset_out == 'ISO-8859-2') {
|
838 |
|
|
$string = strtr($string, $utf8_to_iso_8859_2);
|
839 |
|
|
} elseif ($charset_out == 'ISO-8859-3') {
|
840 |
|
|
$string = strtr($string, $utf8_to_iso_8859_3);
|
841 |
|
|
} elseif ($charset_out == 'ISO-8859-4') {
|
842 |
|
|
$string = strtr($string, $utf8_to_iso_8859_4);
|
843 |
|
|
} elseif ($charset_out == 'ISO-8859-5') {
|
844 |
|
|
$string = strtr($string, $utf8_to_iso_8859_5);
|
845 |
|
|
} elseif ($charset_out == 'ISO-8859-6') {
|
846 |
|
|
$string = strtr($string, $utf8_to_iso_8859_6);
|
847 |
|
|
} elseif ($charset_out == 'ISO-8859-7') {
|
848 |
|
|
$string = strtr($string, $utf8_to_iso_8859_7);
|
849 |
|
|
} elseif ($charset_out == 'ISO-8859-8') {
|
850 |
|
|
$string = strtr($string, $utf8_to_iso_8859_8);
|
851 |
|
|
} elseif ($charset_out == 'ISO-8859-9') {
|
852 |
|
|
$string = strtr($string, $utf8_to_iso_8859_9);
|
853 |
|
|
} elseif ($charset_out == 'ISO-8859-10') {
|
854 |
|
|
$string = strtr($string, $utf8_to_iso_8859_10);
|
855 |
|
|
} elseif ($charset_out == 'ISO-8859-11') {
|
856 |
|
|
$string = strtr($string, $utf8_to_iso_8859_11);
|
857 |
|
|
}
|
858 |
|
|
else {
|
859 |
|
|
$string=mb_convert_encoding_wrapper($string, $charset_out, $charset);
|
860 |
|
|
}
|
861 |
482
|
Ruebenwurz
|
}
|
862 |
|
|
else {
|
863 |
504
|
Ruebenwurz
|
$string=mb_convert_encoding_wrapper($string, $charset_out, $charset);
|
864 |
482
|
Ruebenwurz
|
}
|
865 |
|
|
|
866 |
|
|
return $string;
|
867 |
|
|
}
|
868 |
|
|
|
869 |
445
|
Ruebenwurz
|
// translate any latin/greek/cyrillic html-entities to their plain 7bit equivalents
|
870 |
461
|
Ruebenwurz
|
// and numbered-entities into hex
|
871 |
442
|
Ruebenwurz
|
function entities_to_7bit($string) {
|
872 |
|
|
require(WB_PATH.'/framework/convert.php');
|
873 |
|
|
$string = strtr($string, $conversion_array);
|
874 |
461
|
Ruebenwurz
|
$string = preg_replace('/&#([0-9]+);/e', "dechex('$1')", $string);
|
875 |
442
|
Ruebenwurz
|
return($string);
|
876 |
|
|
}
|
877 |
|
|
|
878 |
238
|
stefan
|
// Function to convert a page title to a page filename
|
879 |
|
|
function page_filename($string) {
|
880 |
442
|
Ruebenwurz
|
$string = entities_to_7bit(umlauts_to_entities($string));
|
881 |
238
|
stefan
|
// Now replace spaces with page spcacer
|
882 |
520
|
Ruebenwurz
|
$string = trim($string);
|
883 |
|
|
$string = preg_replace('/(\s)+/', PAGE_SPACER, $string);
|
884 |
238
|
stefan
|
// Now remove all bad characters
|
885 |
|
|
$bad = array(
|
886 |
|
|
'\'', /* / */ '"', /* " */ '<', /* < */ '>', /* > */
|
887 |
|
|
'{', /* { */ '}', /* } */ '[', /* [ */ ']', /* ] */ '`', /* ` */
|
888 |
|
|
'!', /* ! */ '@', /* @ */ '#', /* # */ '$', /* $ */ '%', /* % */
|
889 |
|
|
'^', /* ^ */ '&', /* & */ '*', /* * */ '(', /* ( */ ')', /* ) */
|
890 |
|
|
'=', /* = */ '+', /* + */ '|', /* | */ '/', /* / */ '\\', /* \ */
|
891 |
|
|
';', /* ; */ ':', /* : */ ',', /* , */ '?' /* ? */
|
892 |
|
|
);
|
893 |
|
|
$string = str_replace($bad, '', $string);
|
894 |
|
|
// Now convert to lower-case
|
895 |
|
|
$string = strtolower($string);
|
896 |
|
|
// If there are any weird language characters, this will protect us against possible problems they could cause
|
897 |
|
|
$string = str_replace(array('%2F', '%'), array('/', ''), urlencode($string));
|
898 |
|
|
// Finally, return the cleaned string
|
899 |
|
|
return $string;
|
900 |
|
|
}
|
901 |
|
|
|
902 |
|
|
// Function to convert a desired media filename to a clean filename
|
903 |
|
|
function media_filename($string) {
|
904 |
442
|
Ruebenwurz
|
$string = entities_to_7bit(umlauts_to_entities($string));
|
905 |
238
|
stefan
|
// Now remove all bad characters
|
906 |
|
|
$bad = array(
|
907 |
|
|
'\'', // '
|
908 |
|
|
'"', // "
|
909 |
|
|
'`', // `
|
910 |
|
|
'!', // !
|
911 |
|
|
'@', // @
|
912 |
|
|
'#', // #
|
913 |
|
|
'$', // $
|
914 |
|
|
'%', // %
|
915 |
|
|
'^', // ^
|
916 |
|
|
'&', // &
|
917 |
|
|
'*', // *
|
918 |
|
|
'=', // =
|
919 |
|
|
'+', // +
|
920 |
|
|
'|', // |
|
921 |
|
|
'/', // /
|
922 |
|
|
'\\', // \
|
923 |
|
|
';', // ;
|
924 |
|
|
':', // :
|
925 |
|
|
',', // ,
|
926 |
|
|
'?' // ?
|
927 |
|
|
);
|
928 |
|
|
$string = str_replace($bad, '', $string);
|
929 |
|
|
// Clean any page spacers at the end of string
|
930 |
|
|
$string = trim($string);
|
931 |
|
|
// Finally, return the cleaned string
|
932 |
|
|
return $string;
|
933 |
|
|
}
|
934 |
|
|
|
935 |
|
|
// Function to work out a page link
|
936 |
|
|
if(!function_exists('page_link')) {
|
937 |
|
|
function page_link($link) {
|
938 |
242
|
stefan
|
global $admin;
|
939 |
|
|
return $admin->page_link($link);
|
940 |
238
|
stefan
|
}
|
941 |
|
|
}
|
942 |
|
|
|
943 |
|
|
// Create a new file in the pages directory
|
944 |
|
|
function create_access_file($filename,$page_id,$level) {
|
945 |
501
|
ryan
|
global $admin, $MESSAGE;
|
946 |
238
|
stefan
|
if(!is_writable(WB_PATH.PAGES_DIRECTORY.'/')) {
|
947 |
|
|
$admin->print_error($MESSAGE['PAGES']['CANNOT_CREATE_ACCESS_FILE']);
|
948 |
|
|
} else {
|
949 |
|
|
// First make sure parent folder exists
|
950 |
|
|
$parent_folders = explode('/',str_replace(WB_PATH.PAGES_DIRECTORY, '', dirname($filename)));
|
951 |
|
|
$parents = '';
|
952 |
|
|
foreach($parent_folders AS $parent_folder) {
|
953 |
|
|
if($parent_folder != '/' AND $parent_folder != '') {
|
954 |
|
|
$parents .= '/'.$parent_folder;
|
955 |
|
|
if(!file_exists(WB_PATH.PAGES_DIRECTORY.$parents)) {
|
956 |
|
|
make_dir(WB_PATH.PAGES_DIRECTORY.$parents);
|
957 |
|
|
}
|
958 |
|
|
}
|
959 |
|
|
}
|
960 |
|
|
// The depth of the page directory in the directory hierarchy
|
961 |
|
|
// '/pages' is at depth 1
|
962 |
|
|
$pages_dir_depth=count(explode('/',PAGES_DIRECTORY))-1;
|
963 |
|
|
// Work-out how many ../'s we need to get to the index page
|
964 |
|
|
$index_location = '';
|
965 |
|
|
for($i = 0; $i < $level + $pages_dir_depth; $i++) {
|
966 |
|
|
$index_location .= '../';
|
967 |
|
|
}
|
968 |
|
|
$content = ''.
|
969 |
|
|
'<?php
|
970 |
|
|
$page_id = '.$page_id.';
|
971 |
|
|
require("'.$index_location.'config.php");
|
972 |
|
|
require(WB_PATH."/index.php");
|
973 |
|
|
?>';
|
974 |
|
|
$handle = fopen($filename, 'w');
|
975 |
|
|
fwrite($handle, $content);
|
976 |
|
|
fclose($handle);
|
977 |
|
|
// Chmod the file
|
978 |
|
|
change_mode($filename, 'file');
|
979 |
|
|
}
|
980 |
|
|
}
|
981 |
|
|
|
982 |
|
|
// Function for working out a file mime type (if the in-built PHP one is not enabled)
|
983 |
|
|
if(!function_exists('mime_content_type')) {
|
984 |
|
|
function mime_content_type($file) {
|
985 |
|
|
$file = escapeshellarg($file);
|
986 |
|
|
return trim(`file -bi $file`);
|
987 |
|
|
}
|
988 |
|
|
}
|
989 |
|
|
|
990 |
|
|
// Generate a thumbnail from an image
|
991 |
|
|
function make_thumb($source, $destination, $size) {
|
992 |
|
|
// Check if GD is installed
|
993 |
|
|
if(extension_loaded('gd') AND function_exists('imageCreateFromJpeg')) {
|
994 |
|
|
// First figure out the size of the thumbnail
|
995 |
|
|
list($original_x, $original_y) = getimagesize($source);
|
996 |
|
|
if ($original_x > $original_y) {
|
997 |
|
|
$thumb_w = $size;
|
998 |
|
|
$thumb_h = $original_y*($size/$original_x);
|
999 |
|
|
}
|
1000 |
|
|
if ($original_x < $original_y) {
|
1001 |
|
|
$thumb_w = $original_x*($size/$original_y);
|
1002 |
|
|
$thumb_h = $size;
|
1003 |
|
|
}
|
1004 |
|
|
if ($original_x == $original_y) {
|
1005 |
|
|
$thumb_w = $size;
|
1006 |
|
|
$thumb_h = $size;
|
1007 |
|
|
}
|
1008 |
|
|
// Now make the thumbnail
|
1009 |
|
|
$source = imageCreateFromJpeg($source);
|
1010 |
|
|
$dst_img = ImageCreateTrueColor($thumb_w, $thumb_h);
|
1011 |
|
|
imagecopyresampled($dst_img,$source,0,0,0,0,$thumb_w,$thumb_h,$original_x,$original_y);
|
1012 |
|
|
imagejpeg($dst_img, $destination);
|
1013 |
|
|
// Clear memory
|
1014 |
|
|
imagedestroy($dst_img);
|
1015 |
|
|
imagedestroy($source);
|
1016 |
|
|
// Return true
|
1017 |
|
|
return true;
|
1018 |
|
|
} else {
|
1019 |
|
|
return false;
|
1020 |
|
|
}
|
1021 |
|
|
}
|
1022 |
|
|
|
1023 |
|
|
// Function to work-out a single part of an octal permission value
|
1024 |
|
|
function extract_permission($octal_value, $who, $action) {
|
1025 |
|
|
// Make sure the octal value is 4 chars long
|
1026 |
|
|
if(strlen($octal_value) == 0) {
|
1027 |
|
|
$octal_value = '0000';
|
1028 |
|
|
} elseif(strlen($octal_value) == 1) {
|
1029 |
|
|
$octal_value = '000'.$octal_value;
|
1030 |
|
|
} elseif(strlen($octal_value) == 2) {
|
1031 |
|
|
$octal_value = '00'.$octal_value;
|
1032 |
|
|
} elseif(strlen($octal_value) == 3) {
|
1033 |
|
|
$octal_value = '0'.$octal_value;
|
1034 |
|
|
} elseif(strlen($octal_value) == 4) {
|
1035 |
|
|
$octal_value = ''.$octal_value;
|
1036 |
|
|
} else {
|
1037 |
|
|
$octal_value = '0000';
|
1038 |
|
|
}
|
1039 |
|
|
// Work-out what position of the octal value to look at
|
1040 |
|
|
switch($who) {
|
1041 |
|
|
case 'u':
|
1042 |
|
|
$position = '1';
|
1043 |
|
|
break;
|
1044 |
|
|
case 'user':
|
1045 |
|
|
$position = '1';
|
1046 |
|
|
break;
|
1047 |
|
|
case 'g':
|
1048 |
|
|
$position = '2';
|
1049 |
|
|
break;
|
1050 |
|
|
case 'group':
|
1051 |
|
|
$position = '2';
|
1052 |
|
|
break;
|
1053 |
|
|
case 'o':
|
1054 |
|
|
$position = '3';
|
1055 |
|
|
break;
|
1056 |
|
|
case 'others':
|
1057 |
|
|
$position = '3';
|
1058 |
|
|
break;
|
1059 |
|
|
}
|
1060 |
|
|
// Work-out how long the octal value is and ajust acording
|
1061 |
|
|
if(strlen($octal_value) == 4) {
|
1062 |
|
|
$position = $position+1;
|
1063 |
|
|
} elseif(strlen($octal_value) != 3) {
|
1064 |
|
|
exit('Error');
|
1065 |
|
|
}
|
1066 |
|
|
// Now work-out what action the script is trying to look-up
|
1067 |
|
|
switch($action) {
|
1068 |
|
|
case 'r':
|
1069 |
|
|
$action = 'r';
|
1070 |
|
|
break;
|
1071 |
|
|
case 'read':
|
1072 |
|
|
$action = 'r';
|
1073 |
|
|
break;
|
1074 |
|
|
case 'w':
|
1075 |
|
|
$action = 'w';
|
1076 |
|
|
break;
|
1077 |
|
|
case 'write':
|
1078 |
|
|
$action = 'w';
|
1079 |
|
|
break;
|
1080 |
|
|
case 'e':
|
1081 |
|
|
$action = 'e';
|
1082 |
|
|
break;
|
1083 |
|
|
case 'execute':
|
1084 |
|
|
$action = 'e';
|
1085 |
|
|
break;
|
1086 |
|
|
}
|
1087 |
|
|
// Get the value for "who"
|
1088 |
|
|
$value = substr($octal_value, $position-1, 1);
|
1089 |
|
|
// Now work-out the details of the value
|
1090 |
|
|
switch($value) {
|
1091 |
|
|
case '0':
|
1092 |
|
|
$r = false;
|
1093 |
|
|
$w = false;
|
1094 |
|
|
$e = false;
|
1095 |
|
|
break;
|
1096 |
|
|
case '1':
|
1097 |
|
|
$r = false;
|
1098 |
|
|
$w = false;
|
1099 |
|
|
$e = true;
|
1100 |
|
|
break;
|
1101 |
|
|
case '2':
|
1102 |
|
|
$r = false;
|
1103 |
|
|
$w = true;
|
1104 |
|
|
$e = false;
|
1105 |
|
|
break;
|
1106 |
|
|
case '3':
|
1107 |
|
|
$r = false;
|
1108 |
|
|
$w = true;
|
1109 |
|
|
$e = true;
|
1110 |
|
|
break;
|
1111 |
|
|
case '4':
|
1112 |
|
|
$r = true;
|
1113 |
|
|
$w = false;
|
1114 |
|
|
$e = false;
|
1115 |
|
|
break;
|
1116 |
|
|
case '5':
|
1117 |
|
|
$r = true;
|
1118 |
|
|
$w = false;
|
1119 |
|
|
$e = true;
|
1120 |
|
|
break;
|
1121 |
|
|
case '6':
|
1122 |
|
|
$r = true;
|
1123 |
|
|
$w = true;
|
1124 |
|
|
$e = false;
|
1125 |
|
|
break;
|
1126 |
|
|
case '7':
|
1127 |
|
|
$r = true;
|
1128 |
|
|
$w = true;
|
1129 |
|
|
$e = true;
|
1130 |
|
|
break;
|
1131 |
|
|
default:
|
1132 |
|
|
$r = false;
|
1133 |
|
|
$w = false;
|
1134 |
|
|
$e = false;
|
1135 |
|
|
}
|
1136 |
|
|
// And finally, return either true or false
|
1137 |
|
|
return $$action;
|
1138 |
|
|
}
|
1139 |
|
|
|
1140 |
|
|
// Function to delete a page
|
1141 |
|
|
function delete_page($page_id) {
|
1142 |
|
|
|
1143 |
501
|
ryan
|
global $admin, $database, $MESSAGE;
|
1144 |
238
|
stefan
|
|
1145 |
|
|
// Find out more about the page
|
1146 |
|
|
$database = new database();
|
1147 |
|
|
$query = "SELECT page_id,menu_title,page_title,level,link,parent,modified_by,modified_when FROM ".TABLE_PREFIX."pages WHERE page_id = '$page_id'";
|
1148 |
|
|
$results = $database->query($query);
|
1149 |
|
|
if($database->is_error()) {
|
1150 |
|
|
$admin->print_error($database->get_error());
|
1151 |
|
|
}
|
1152 |
|
|
if($results->numRows() == 0) {
|
1153 |
|
|
$admin->print_error($MESSAGE['PAGES']['NOT_FOUND']);
|
1154 |
|
|
}
|
1155 |
|
|
$results_array = $results->fetchRow();
|
1156 |
|
|
$parent = $results_array['parent'];
|
1157 |
|
|
$level = $results_array['level'];
|
1158 |
|
|
$link = $results_array['link'];
|
1159 |
|
|
$page_title = ($results_array['page_title']);
|
1160 |
|
|
$menu_title = ($results_array['menu_title']);
|
1161 |
|
|
|
1162 |
|
|
// Get the sections that belong to the page
|
1163 |
|
|
$query_sections = $database->query("SELECT section_id,module FROM ".TABLE_PREFIX."sections WHERE page_id = '$page_id'");
|
1164 |
|
|
if($query_sections->numRows() > 0) {
|
1165 |
|
|
while($section = $query_sections->fetchRow()) {
|
1166 |
|
|
// Set section id
|
1167 |
|
|
$section_id = $section['section_id'];
|
1168 |
|
|
// Include the modules delete file if it exists
|
1169 |
|
|
if(file_exists(WB_PATH.'/modules/'.$section['module'].'/delete.php')) {
|
1170 |
|
|
require(WB_PATH.'/modules/'.$section['module'].'/delete.php');
|
1171 |
|
|
}
|
1172 |
|
|
}
|
1173 |
|
|
}
|
1174 |
|
|
|
1175 |
|
|
// Update the pages table
|
1176 |
|
|
$query = "DELETE FROM ".TABLE_PREFIX."pages WHERE page_id = '$page_id'";
|
1177 |
|
|
$database->query($query);
|
1178 |
|
|
if($database->is_error()) {
|
1179 |
|
|
$admin->print_error($database->get_error());
|
1180 |
|
|
}
|
1181 |
|
|
|
1182 |
|
|
// Update the sections table
|
1183 |
|
|
$query = "DELETE FROM ".TABLE_PREFIX."sections WHERE page_id = '$page_id'";
|
1184 |
|
|
$database->query($query);
|
1185 |
|
|
if($database->is_error()) {
|
1186 |
|
|
$admin->print_error($database->get_error());
|
1187 |
|
|
}
|
1188 |
|
|
|
1189 |
|
|
// Include the ordering class or clean-up ordering
|
1190 |
|
|
require_once(WB_PATH.'/framework/class.order.php');
|
1191 |
|
|
$order = new order(TABLE_PREFIX.'pages', 'position', 'page_id', 'parent');
|
1192 |
|
|
$order->clean($parent);
|
1193 |
|
|
|
1194 |
|
|
// Unlink the page access file and directory
|
1195 |
|
|
$directory = WB_PATH.PAGES_DIRECTORY.$link;
|
1196 |
541
|
Ruebenwurz
|
$filename = $directory.PAGE_EXTENSION;
|
1197 |
238
|
stefan
|
$directory .= '/';
|
1198 |
436
|
doc
|
if(file_exists($filename) && substr($filename,0,1<>'.')) {
|
1199 |
238
|
stefan
|
if(!is_writable(WB_PATH.PAGES_DIRECTORY.'/')) {
|
1200 |
|
|
$admin->print_error($MESSAGE['PAGES']['CANNOT_DELETE_ACCESS_FILE']);
|
1201 |
|
|
} else {
|
1202 |
|
|
unlink($filename);
|
1203 |
|
|
if(file_exists($directory)) {
|
1204 |
|
|
rm_full_dir($directory);
|
1205 |
|
|
}
|
1206 |
|
|
}
|
1207 |
|
|
}
|
1208 |
|
|
|
1209 |
|
|
}
|
1210 |
|
|
|
1211 |
|
|
// Load module into DB
|
1212 |
|
|
function load_module($directory, $install = false) {
|
1213 |
249
|
stefan
|
global $database,$admin,$MESSAGE;
|
1214 |
238
|
stefan
|
if(file_exists($directory.'/info.php')) {
|
1215 |
|
|
require($directory.'/info.php');
|
1216 |
|
|
if(isset($module_name)) {
|
1217 |
|
|
if(!isset($module_license)) { $module_license = 'GNU General Public License'; }
|
1218 |
|
|
if(!isset($module_platform) AND isset($module_designed_for)) { $module_platform = $module_designed_for; }
|
1219 |
|
|
if(!isset($module_function) AND isset($module_type)) { $module_function = $module_type; }
|
1220 |
|
|
$module_function = strtolower($module_function);
|
1221 |
|
|
// Check that it doesn't already exist
|
1222 |
|
|
$result = $database->query("SELECT addon_id FROM ".TABLE_PREFIX."addons WHERE directory = '".$module_directory."' LIMIT 0,1");
|
1223 |
|
|
if($result->numRows() == 0) {
|
1224 |
|
|
// Load into DB
|
1225 |
|
|
$query = "INSERT INTO ".TABLE_PREFIX."addons ".
|
1226 |
|
|
"(directory,name,description,type,function,version,platform,author,license) ".
|
1227 |
|
|
"VALUES ('$module_directory','$module_name','".addslashes($module_description)."','module',".
|
1228 |
|
|
"'$module_function','$module_version','$module_platform','$module_author','$module_license')";
|
1229 |
|
|
$database->query($query);
|
1230 |
|
|
// Run installation script
|
1231 |
|
|
if($install == true) {
|
1232 |
|
|
if(file_exists($directory.'/install.php')) {
|
1233 |
|
|
require($directory.'/install.php');
|
1234 |
|
|
}
|
1235 |
|
|
}
|
1236 |
|
|
}
|
1237 |
|
|
}
|
1238 |
|
|
}
|
1239 |
|
|
}
|
1240 |
|
|
|
1241 |
|
|
// Load template into DB
|
1242 |
|
|
function load_template($directory) {
|
1243 |
|
|
global $database;
|
1244 |
|
|
if(file_exists($directory.'/info.php')) {
|
1245 |
|
|
require($directory.'/info.php');
|
1246 |
|
|
if(isset($template_name)) {
|
1247 |
|
|
if(!isset($template_license)) { $template_license = 'GNU General Public License'; }
|
1248 |
|
|
if(!isset($template_platform) AND isset($template_designed_for)) { $template_platform = $template_designed_for; }
|
1249 |
|
|
// Check that it doesn't already exist
|
1250 |
|
|
$result = $database->query("SELECT addon_id FROM ".TABLE_PREFIX."addons WHERE directory = '".$template_directory."' LIMIT 0,1");
|
1251 |
|
|
if($result->numRows() == 0) {
|
1252 |
|
|
// Load into DB
|
1253 |
|
|
$query = "INSERT INTO ".TABLE_PREFIX."addons ".
|
1254 |
|
|
"(directory,name,description,type,version,platform,author,license) ".
|
1255 |
|
|
"VALUES ('$template_directory','$template_name','".addslashes($template_description)."','template',".
|
1256 |
|
|
"'$template_version','$template_platform','$template_author','$template_license')";
|
1257 |
|
|
$database->query($query);
|
1258 |
|
|
}
|
1259 |
|
|
}
|
1260 |
|
|
}
|
1261 |
|
|
}
|
1262 |
|
|
|
1263 |
|
|
// Load language into DB
|
1264 |
|
|
function load_language($file) {
|
1265 |
|
|
global $database;
|
1266 |
|
|
if(file_exists($file)) {
|
1267 |
|
|
require($file);
|
1268 |
|
|
if(isset($language_name)) {
|
1269 |
|
|
if(!isset($language_license)) { $language_license = 'GNU General Public License'; }
|
1270 |
|
|
if(!isset($language_platform) AND isset($language_designed_for)) { $language_platform = $language_designed_for; }
|
1271 |
|
|
// Check that it doesn't already exist
|
1272 |
|
|
$result = $database->query("SELECT addon_id FROM ".TABLE_PREFIX."addons WHERE directory = '".$language_code."' LIMIT 0,1");
|
1273 |
|
|
if($result->numRows() == 0) {
|
1274 |
|
|
// Load into DB
|
1275 |
|
|
$query = "INSERT INTO ".TABLE_PREFIX."addons ".
|
1276 |
|
|
"(directory,name,type,version,platform,author,license) ".
|
1277 |
|
|
"VALUES ('$language_code','$language_name','language',".
|
1278 |
|
|
"'$language_version','$language_platform','$language_author','$language_license')";
|
1279 |
|
|
$database->query($query);
|
1280 |
|
|
}
|
1281 |
|
|
}
|
1282 |
|
|
}
|
1283 |
|
|
}
|
1284 |
|
|
|
1285 |
373
|
Ruebenwurz
|
// Upgrade module info in DB, optionally start upgrade script
|
1286 |
|
|
function upgrade_module($directory, $upgrade = false) {
|
1287 |
|
|
global $database, $admin, $MESSAGE;
|
1288 |
|
|
$directory = WB_PATH . "/modules/$directory";
|
1289 |
|
|
if(file_exists($directory.'/info.php')) {
|
1290 |
|
|
require($directory.'/info.php');
|
1291 |
|
|
if(isset($module_name)) {
|
1292 |
|
|
if(!isset($module_license)) { $module_license = 'GNU General Public License'; }
|
1293 |
|
|
if(!isset($module_platform) AND isset($module_designed_for)) { $module_platform = $module_designed_for; }
|
1294 |
|
|
if(!isset($module_function) AND isset($module_type)) { $module_function = $module_type; }
|
1295 |
|
|
$module_function = strtolower($module_function);
|
1296 |
|
|
// Check that it does already exist
|
1297 |
|
|
$result = $database->query("SELECT addon_id FROM ".TABLE_PREFIX."addons WHERE directory = '".$module_directory."' LIMIT 0,1");
|
1298 |
|
|
if($result->numRows() > 0) {
|
1299 |
|
|
// Update in DB
|
1300 |
|
|
$query = "UPDATE " . TABLE_PREFIX . "addons SET " .
|
1301 |
|
|
"version = '$module_version', " .
|
1302 |
|
|
"description = '" . addslashes($module_description) . "', " .
|
1303 |
|
|
"platform = '$module_platform', " .
|
1304 |
|
|
"author = '$module_author', " .
|
1305 |
|
|
"license = '$module_license'" .
|
1306 |
|
|
"WHERE directory = '$module_directory'";
|
1307 |
|
|
$database->query($query);
|
1308 |
|
|
// Run upgrade script
|
1309 |
|
|
if($upgrade == true) {
|
1310 |
|
|
if(file_exists($directory.'/upgrade.php')) {
|
1311 |
|
|
require($directory.'/upgrade.php');
|
1312 |
|
|
}
|
1313 |
|
|
}
|
1314 |
|
|
}
|
1315 |
|
|
}
|
1316 |
|
|
}
|
1317 |
|
|
}
|
1318 |
|
|
|
1319 |
399
|
Ruebenwurz
|
?>
|