1
|
<?php
|
2
|
|
3
|
// $Id: functions.php 479 2007-06-11 16:25:51Z Ruebenwurzel $
|
4
|
|
5
|
/*
|
6
|
|
7
|
Website Baker Project <http://www.websitebaker.org/>
|
8
|
Copyright (C) 2004-2007, Ryan Djurovich
|
9
|
|
10
|
Website Baker is free software; you can redistribute it and/or modify
|
11
|
it under the terms of the GNU General Public License as published by
|
12
|
the Free Software Foundation; either version 2 of the License, or
|
13
|
(at your option) any later version.
|
14
|
|
15
|
Website Baker is distributed in the hope that it will be useful,
|
16
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
17
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
18
|
GNU General Public License for more details.
|
19
|
|
20
|
You should have received a copy of the GNU General Public License
|
21
|
along with Website Baker; if not, write to the Free Software
|
22
|
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
23
|
|
24
|
*/
|
25
|
|
26
|
/*
|
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
|
exit(0);
|
37
|
}
|
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
|
// and user is not admin
|
159
|
if(HOME_FOLDERS AND ($_SESSION['GROUP_ID']!='1')) {
|
160
|
$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
|
return $page_id;
|
271
|
} 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
|
// Function as replecement for php's htmlspecialchars()
|
342
|
function my_htmlspecialchars($string) {
|
343
|
$string = preg_replace("/&(?=[#a-z0-9]+;)/i", "_x_", $string);
|
344
|
$string = strtr($string, array("<"=>"<", ">"=>">", "&"=>"&", "\""=>""", "\'"=>"'"));
|
345
|
$string = preg_replace("/_x_(?=[#a-z0-9]+;)/i", "&", $string);
|
346
|
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
|
// keep current character set values:
|
352
|
$character_set_database = mysql_result(mysql_query("SELECT @@character_set_client"),0,0);
|
353
|
$character_set_results = mysql_result(mysql_query("SELECT @@character_set_results"),0,0);
|
354
|
$collation_results = mysql_result(mysql_query("SELECT @@collation_connection"),0,0);
|
355
|
mysql_query("SET character_set_client=$from");
|
356
|
mysql_query("SET character_set_results=$to");
|
357
|
mysql_query("SET collation_connection=utf8_unicode_ci");
|
358
|
$string_escaped = mysql_real_escape_string($string);
|
359
|
$converted_string = mysql_result(mysql_query("SELECT '$string_escaped'"),0,0);
|
360
|
// restore previous character set values:
|
361
|
mysql_query("SET character_set_client=$character_set_database");
|
362
|
mysql_query("SET character_set_results=$character_set_results");
|
363
|
mysql_query("SET collation_connection=$collation_results");
|
364
|
return $converted_string;
|
365
|
}
|
366
|
|
367
|
// Function as wrapper for mb_convert_encoding
|
368
|
// converts $charset_in to $charset_out or
|
369
|
// UTF-8 to HTML-ENTITIES or HTML-ENTITIES to UTF-8
|
370
|
function mb_convert_encoding_wrapper($string, $charset_out, $charset_in) {
|
371
|
if ($charset_out == $charset_in) {
|
372
|
return $string;
|
373
|
}
|
374
|
$use_iconv = true;
|
375
|
$use_mbstring = true;
|
376
|
if(version_compare(PHP_VERSION, "5.1.0", "<")) {
|
377
|
$use_mbstring = false; // don't rely on mb_convert_encoding if php<5.1.0
|
378
|
$use_iconv = false; // don't rely on iconv neither
|
379
|
}
|
380
|
|
381
|
// try mb_convert_encoding(). This can handle to or from HTML-ENTITIES, too
|
382
|
if ($use_mbstring && function_exists('mb_convert_encoding')) {
|
383
|
// there's no GB2312 or ISO-8859-11 encoding in php's mb_* functions
|
384
|
if ($charset_in=='ISO-8859-11' || $charset_in=='GB2312') {
|
385
|
if ($use_iconv && function_exists('iconv')) {
|
386
|
$string = iconv($charset_in, 'UTF-8', $string);
|
387
|
}
|
388
|
else {
|
389
|
if ($charset_in == 'GB2312') {
|
390
|
$string=my_mysql_iconv($string, 'gb2312', 'utf8');
|
391
|
} else {
|
392
|
$string=my_mysql_iconv($string, 'tis620', 'utf8');
|
393
|
}
|
394
|
}
|
395
|
$charset_in='UTF-8';
|
396
|
if ($charset_out == 'UTF-8') {
|
397
|
return $string;
|
398
|
}
|
399
|
}
|
400
|
if ($charset_out=='ISO-8859-11' || $charset_out=='GB2312') {
|
401
|
$string=mb_convert_encoding($string, 'UTF-8', $charset_in);
|
402
|
if ($use_iconv && function_exists('iconv')) {
|
403
|
$string = iconv('UTF-8', $charset_out, $string);
|
404
|
}
|
405
|
else {
|
406
|
if ($charset_out == 'GB2312') {
|
407
|
$string=my_mysql_iconv($string, 'utf8', 'gb2312');
|
408
|
} else {
|
409
|
$string=my_mysql_iconv($string, 'utf8', 'tis620');
|
410
|
}
|
411
|
}
|
412
|
} else {
|
413
|
$string = strtr($string, array("<"=>"&_lt;", ">"=>"&_gt;", "&"=>"&_amp;", """=>"&_quot;", "'"=>"&_#039;"));
|
414
|
$string=mb_convert_encoding($string, $charset_out, $charset_in);
|
415
|
$string = strtr($string, array("&_lt;"=>"<", "&_gt;"=>">", "&_amp;"=>"&", "&_quot;"=>""", "&_#039;"=>"'"));
|
416
|
}
|
417
|
return $string;
|
418
|
}
|
419
|
|
420
|
// try iconv(). This can't handle to or from HTML-ENTITIES.
|
421
|
if ($use_iconv && function_exists('iconv') && $charset_out!='HTML-ENTITIES' && $charset_in!='HTML-ENTITIES' ) {
|
422
|
$string = iconv($charset_in, $charset_out, $string);
|
423
|
return $string;
|
424
|
}
|
425
|
|
426
|
// do the UTF-8->HTML-ENTITIES or HTML-ENTITIES->UTF-8 translation if mb_convert_encoding isn't available
|
427
|
if (($charset_in=='HTML-ENTITIES' && $charset_out=='UTF-8') || ($charset_in=='UTF-8' && $charset_out=='HTML-ENTITIES')) {
|
428
|
$string = string_decode_encode_entities($string, $charset_out, $charset_in);
|
429
|
return $string;
|
430
|
}
|
431
|
|
432
|
// mb_convert_encoding() and iconv() aren't available, so use my_mysql_iconv()
|
433
|
if ($charset_in == 'ISO-8859-1') { $mysqlcharset_from = 'latin1'; }
|
434
|
elseif ($charset_in == 'ISO-8859-2') { $mysqlcharset_from = 'latin2'; }
|
435
|
elseif ($charset_in == 'ISO-8859-3') { $mysqlcharset_from = 'latin1'; }
|
436
|
elseif ($charset_in == 'ISO-8859-4') { $mysqlcharset_from = 'latin7'; }
|
437
|
elseif ($charset_in == 'ISO-8859-5') { $string = convert_cyr_string ($string, "iso8859-5", "windows-1251" ); $mysqlcharset_from = 'cp1251'; }
|
438
|
elseif ($charset_in == 'ISO-8859-6') { $mysqlcharset_from = ''; } //?
|
439
|
elseif ($charset_in == 'ISO-8859-7') { $mysqlcharset_from = 'greek'; }
|
440
|
elseif ($charset_in == 'ISO-8859-8') { $mysqlcharset_from = 'hebrew'; }
|
441
|
elseif ($charset_in == 'ISO-8859-9') { $mysqlcharset_from = 'latin5'; }
|
442
|
elseif ($charset_in == 'ISO-8859-10') { $mysqlcharset_from = 'latin1'; }
|
443
|
elseif ($charset_in == 'BIG5') { $mysqlcharset_from = 'big5'; }
|
444
|
elseif ($charset_in == 'ISO-2022-JP') { $mysqlcharset_from = ''; } //?
|
445
|
elseif ($charset_in == 'ISO-2022-KR') { $mysqlcharset_from = ''; } //?
|
446
|
elseif ($charset_in == 'GB2312') { $mysqlcharset_from = 'gb2312'; }
|
447
|
elseif ($charset_in == 'ISO-8859-11') { $mysqlcharset_from = 'tis620'; }
|
448
|
elseif ($charset_in == 'UTF-8') { $mysqlcharset_from = 'utf8'; }
|
449
|
else { $mysqlcharset_from = 'latin1'; }
|
450
|
|
451
|
if ($charset_out == 'ISO-8859-1') { $mysqlcharset_to = 'latin1'; }
|
452
|
elseif ($charset_out == 'ISO-8859-2') { $mysqlcharset_to = 'latin2'; }
|
453
|
elseif ($charset_out == 'ISO-8859-3') { $mysqlcharset_to = 'latin1'; }
|
454
|
elseif ($charset_out == 'ISO-8859-4') { $mysqlcharset_to = 'latin7'; }
|
455
|
elseif ($charset_out == 'ISO-8859-5') { $mysqlcharset_to = 'cp1251'; } // use convert_cyr_string afterwards
|
456
|
elseif ($charset_out == 'ISO-8859-6') { $mysqlcharset_to = ''; } //?
|
457
|
elseif ($charset_out == 'ISO-8859-7') { $mysqlcharset_to = 'greek'; }
|
458
|
elseif ($charset_out == 'ISO-8859-8') { $mysqlcharset_to = 'hebrew'; }
|
459
|
elseif ($charset_out == 'ISO-8859-9') { $mysqlcharset_to = 'latin5'; }
|
460
|
elseif ($charset_out == 'ISO-8859-10') { $mysqlcharset_to = 'latin1'; }
|
461
|
elseif ($charset_out == 'BIG5') { $mysqlcharset_to = 'big5'; }
|
462
|
elseif ($charset_out == 'ISO-2022-JP') { $mysqlcharset_to = ''; } //?
|
463
|
elseif ($charset_out == 'ISO-2022-KR') { $mysqlcharset_to = ''; } //?
|
464
|
elseif ($charset_out == 'GB2312') { $mysqlcharset_to = 'gb2312'; }
|
465
|
elseif ($charset_out == 'ISO-8859-11') { $mysqlcharset_to = 'tis620'; }
|
466
|
elseif ($charset_out == 'UTF-8') { $mysqlcharset_to = 'utf8'; }
|
467
|
else { $mysqlcharset_to = 'latin1'; }
|
468
|
|
469
|
if ($mysqlcharset_from!="" && $mysqlcharset_to!="" && $mysqlcharset_from!=$mysqlcharset_to) {
|
470
|
$string=my_mysql_iconv($string, $mysqlcharset_from, $mysqlcharset_to);
|
471
|
if ($mysqlcharset_to == 'cp1251') {
|
472
|
$string = convert_cyr_string ($string, "windows-1251", "iso-8859-5" );
|
473
|
}
|
474
|
return($string);
|
475
|
}
|
476
|
|
477
|
// $string is unchanged. This will happen if we have to deal with ISO-8859-6 or ISO-2022-JP or -KR
|
478
|
// and mbstring _and_ iconv aren't available.
|
479
|
return $string;
|
480
|
}
|
481
|
|
482
|
// Decodes or encodes html-entities. Works for utf-8 only!
|
483
|
function string_decode_encode_entities($string, $out='HTML-ENTITIES', $in='UTF-8') {
|
484
|
if(!(($in=='UTF-8' || $in=='HTML-ENTITIES') && ($out=='UTF-8' || $out=='HTML-ENTITIES'))) {
|
485
|
return $string;
|
486
|
}
|
487
|
$named_to_numbered_entities=array(
|
488
|
'Á'=>'Á','á'=>'á',
|
489
|
'Â'=>'Â','â'=>'â','´'=>'´','Æ'=>'Æ','æ'=>'æ',
|
490
|
'À'=>'À','à'=>'à','ℵ'=>'ℵ','Α'=>'Α','α'=>'α',
|
491
|
'∧'=>'∧','∠'=>'∠','''=>''','Å'=>'Å','å'=>'å',
|
492
|
'≈'=>'≈','Ã'=>'Ã','ã'=>'ã','Ä'=>'Ä','ä'=>'ä',
|
493
|
'„'=>'„','Β'=>'Β','β'=>'β','¦'=>'¦','•'=>'•',
|
494
|
'∩'=>'∩','Ç'=>'Ç','ç'=>'ç','¸'=>'¸','¢'=>'¢',
|
495
|
'Χ'=>'Χ','χ'=>'χ','ˆ'=>'ˆ','♣'=>'♣','≅'=>'≅',
|
496
|
'©'=>'©','↵'=>'↵','∪'=>'∪','¤'=>'¤','‡'=>'‡',
|
497
|
'†'=>'†','⇓'=>'⇓','↓'=>'↓','°'=>'°','Δ'=>'Δ',
|
498
|
'δ'=>'δ','♦'=>'&v#9830;','÷'=>'÷','É'=>'É','é'=>'é',
|
499
|
'Ê'=>'Ê','ê'=>'ê','È'=>'È','è'=>'è','∅'=>'∅',
|
500
|
' '=>' ',' '=>' ','Ε'=>'Ε','ε'=>'ε','≡'=>'≡',
|
501
|
'Η'=>'Η','η'=>'η','Ð'=>'Ð','ð'=>'ð','Ë'=>'Ë','ë'=>'ë',
|
502
|
'€'=>'€','∃'=>'∃','ƒ'=>'ƒ','∀'=>'∀','½'=>'½',
|
503
|
'¼'=>'¼','¾'=>'¾','⁄'=>'⁄','Γ'=>'Γ','γ'=>'γ',
|
504
|
'≥'=>'≥','⇔'=>'⇔','↔'=>'↔','♥'=>'♥',
|
505
|
'…'=>'…','Í'=>'Í','í'=>'í','Î'=>'Î','î'=>'î',
|
506
|
'¡'=>'¡','Ì'=>'Ì','ì'=>'ì','ℑ'=>'ℑ','∞'=>'∞',
|
507
|
'∫'=>'∫','Ι'=>'Ι','ι'=>'ι','¿'=>'¿','∈'=>'∈',
|
508
|
'Ï'=>'Ï','ï'=>'ï','Κ'=>'Κ','κ'=>'κ','Λ'=>'Λ',
|
509
|
'λ'=>'λ','⟨'=>'〈','«'=>'«','⇐'=>'⇐','←'=>'←',
|
510
|
'⌈'=>'⌈','“'=>'“','≤'=>'≤','⌊'=>'⌊','∗'=>'∗',
|
511
|
'◊'=>'◊','‎'=>'‎','‹'=>'‹','‘'=>'‘',
|
512
|
'¯'=>'¯','—'=>'—','µ'=>'µ','·'=>'·','−'=>'−',
|
513
|
'Μ'=>'Μ','μ'=>'μ','∇'=>'∇',' '=>' ','–'=>'–',
|
514
|
'≠'=>'≠','∋'=>'∋','¬'=>'¬','∉'=>'∉','⊄'=>'⊄',
|
515
|
'Ñ'=>'Ñ','ñ'=>'ñ','Ν'=>'Ν','ν'=>'ν','Ó'=>'Ó',
|
516
|
'ó'=>'ó','Ô'=>'Ô','ô'=>'ô','Œ'=>'Œ','œ'=>'œ',
|
517
|
'Ò'=>'Ò','ò'=>'ò','‾'=>'‾','Ω'=>'Ω','ω'=>'ω',
|
518
|
'Ο'=>'Ο','ο'=>'ο','⊕'=>'⊕','∨'=>'∨','ª'=>'ª',
|
519
|
'º'=>'º','Ø'=>'Ø','ø'=>'ø','Õ'=>'Õ','õ'=>'õ',
|
520
|
'⊗'=>'⊗','Ö'=>'Ö','ö'=>'ö','¶'=>'¶','∂'=>'∂',
|
521
|
'‰'=>'‰','⊥'=>'⊥','Φ'=>'Φ','φ'=>'φ','Π'=>'Π',
|
522
|
'π'=>'π','ϖ'=>'ϖ','±'=>'±','£'=>'£','″'=>'″',
|
523
|
'′'=>'′','∏'=>'∏','∝'=>'∝','Ψ'=>'Ψ','ψ'=>'ψ',
|
524
|
'"'=>'"','√'=>'√','⟩'=>'〉','»'=>'»','⇒'=>'⇒',
|
525
|
'→'=>'→','⌉'=>'⌉','”'=>'”','ℜ'=>'ℜ','®'=>'®',
|
526
|
'⌋'=>'⌋','Ρ'=>'Ρ','ρ'=>'ρ','‏'=>'‏','›'=>'›',
|
527
|
'’'=>'’','‚'=>'‚','Š'=>'Š','š'=>'š','⋅'=>'⋅',
|
528
|
'§'=>'§','­'=>'­','Σ'=>'Σ','σ'=>'σ','ς'=>'ς',
|
529
|
'∼'=>'∼','♠'=>'♠','⊂'=>'⊂','⊆'=>'⊆','∑'=>'∑',
|
530
|
'⊃'=>'⊃','¹'=>'¹','²'=>'²','³'=>'³','⊇'=>'⊇',
|
531
|
'ß'=>'ß','Τ'=>'Τ','τ'=>'τ','∴'=>'∴','Θ'=>'Θ',
|
532
|
'θ'=>'θ','ϑ'=>'ϑ',' '=>' ','Þ'=>'Þ','þ'=>'þ',
|
533
|
'˜'=>'˜','×'=>'×','™'=>'™','Ú'=>'Ú','ú'=>'ú',
|
534
|
'⇑'=>'⇑','↑'=>'↑','Û'=>'Û','û'=>'û','Ù'=>'Ù',
|
535
|
'ù'=>'ù','¨'=>'¨','ϒ'=>'ϒ','Υ'=>'Υ','υ'=>'υ',
|
536
|
'Ü'=>'Ü','ü'=>'ü','℘'=>'℘','Ξ'=>'Ξ','ξ'=>'ξ',
|
537
|
'Ý'=>'Ý','ý'=>'ý','¥'=>'¥','Ÿ'=>'Ÿ','ÿ'=>'ÿ',
|
538
|
'Ζ'=>'Ζ','ζ'=>'ζ','‍'=>'‍','‌'=>'‌'
|
539
|
);
|
540
|
$numbered_to_named_entities=array(
|
541
|
'Á'=>'Á','á'=>'á','Â'=>'Â','â'=>'â','´'=>'´',
|
542
|
'Æ'=>'Æ','æ'=>'æ','À'=>'À','à'=>'à','ℵ'=>'ℵ',
|
543
|
'Α'=>'Α','α'=>'α','∧'=>'∧','∠'=>'∠',
|
544
|
'''=>''','Å'=>'Å','å'=>'å','≈'=>'≈','Ã'=>'Ã',
|
545
|
'ã'=>'ã','Ä'=>'Ä','ä'=>'ä','„'=>'„','Β'=>'Β',
|
546
|
'β'=>'β','¦'=>'¦','•'=>'•','∩'=>'∩','Ç'=>'Ç',
|
547
|
'ç'=>'ç','¸'=>'¸','¢'=>'¢','Χ'=>'Χ','χ'=>'χ',
|
548
|
'ˆ'=>'ˆ','♣'=>'♣','≅'=>'≅','©'=>'©','↵'=>'↵',
|
549
|
'∪'=>'∪','¤'=>'¤','‡'=>'‡','†'=>'†','⇓'=>'⇓',
|
550
|
'↓'=>'↓','°'=>'°','Δ'=>'Δ','δ'=>'δ','&v#9830;'=>'♦',
|
551
|
'÷'=>'÷','É'=>'É','é'=>'é','Ê'=>'Ê','ê'=>'ê',
|
552
|
'È'=>'È','è'=>'è','∅'=>'∅',' '=>' ',' '=>' ',
|
553
|
'Ε'=>'Ε','ε'=>'ε','≡'=>'≡','Η'=>'Η','η'=>'η',
|
554
|
'Ð'=>'Ð','ð'=>'ð','Ë'=>'Ë','ë'=>'ë','€'=>'€',
|
555
|
'∃'=>'∃','ƒ'=>'ƒ','∀'=>'∀','½'=>'½','¼'=>'¼',
|
556
|
'¾'=>'¾','⁄'=>'⁄','Γ'=>'Γ','γ'=>'γ','≥'=>'≥',
|
557
|
'⇔'=>'⇔','↔'=>'↔','♥'=>'♥','…'=>'…',
|
558
|
'Í'=>'Í','í'=>'í','Î'=>'Î','î'=>'î','¡'=>'¡',
|
559
|
'Ì'=>'Ì','ì'=>'ì','ℑ'=>'ℑ','∞'=>'∞','∫'=>'∫',
|
560
|
'Ι'=>'Ι','ι'=>'ι','¿'=>'¿','∈'=>'∈','Ï'=>'Ï',
|
561
|
'ï'=>'ï','Κ'=>'Κ','κ'=>'κ','Λ'=>'Λ','λ'=>'λ',
|
562
|
'〈'=>'⟨','«'=>'«','⇐'=>'⇐','←'=>'←','⌈'=>'⌈',
|
563
|
'“'=>'“','≤'=>'≤','⌊'=>'⌊','∗'=>'∗','◊'=>'◊',
|
564
|
'‎'=>'‎','‹'=>'‹','‘'=>'‘','¯'=>'¯',
|
565
|
'—'=>'—','µ'=>'µ','·'=>'·','−'=>'−','Μ'=>'Μ',
|
566
|
'μ'=>'μ','∇'=>'∇',' '=>' ','–'=>'–','≠'=>'≠',
|
567
|
'∋'=>'∋','¬'=>'¬','∉'=>'∉','⊄'=>'⊄','Ñ'=>'Ñ',
|
568
|
'ñ'=>'ñ','Ν'=>'Ν','ν'=>'ν','Ó'=>'Ó','ó'=>'ó',
|
569
|
'Ô'=>'Ô','ô'=>'ô','Œ'=>'Œ','œ'=>'œ','Ò'=>'Ò',
|
570
|
'ò'=>'ò','‾'=>'‾','Ω'=>'Ω','ω'=>'ω','Ο'=>'Ο',
|
571
|
'ο'=>'ο','⊕'=>'⊕','∨'=>'∨','ª'=>'ª','º'=>'º',
|
572
|
'Ø'=>'Ø','ø'=>'ø','Õ'=>'Õ','õ'=>'õ','⊗'=>'⊗',
|
573
|
'Ö'=>'Ö','ö'=>'ö','¶'=>'¶','∂'=>'∂','‰'=>'‰',
|
574
|
'⊥'=>'⊥','Φ'=>'Φ','φ'=>'φ','Π'=>'Π','π'=>'π','ϖ'=>'ϖ',
|
575
|
'±'=>'±','£'=>'£','″'=>'″','′'=>'′','∏'=>'∏',
|
576
|
'∝'=>'∝','Ψ'=>'Ψ','ψ'=>'ψ','"'=>'"','√'=>'√',
|
577
|
'〉'=>'⟩','»'=>'»','⇒'=>'⇒','→'=>'→','⌉'=>'⌉',
|
578
|
'”'=>'”','ℜ'=>'ℜ','®'=>'®','⌋'=>'⌋','Ρ'=>'Ρ',
|
579
|
'ρ'=>'ρ','‏'=>'‏','›'=>'›','’'=>'’','‚'=>'‚',
|
580
|
'Š'=>'Š','š'=>'š','⋅'=>'⋅','§'=>'§','­'=>'­',
|
581
|
'Σ'=>'Σ','σ'=>'σ','ς'=>'ς','∼'=>'∼','♠'=>'♠',
|
582
|
'⊂'=>'⊂','⊆'=>'⊆','∑'=>'∑','⊃'=>'⊃','¹'=>'¹',
|
583
|
'²'=>'²','³'=>'³','⊇'=>'⊇','ß'=>'ß','Τ'=>'Τ',
|
584
|
'τ'=>'τ','∴'=>'∴','Θ'=>'Θ','θ'=>'θ','ϑ'=>'ϑ',
|
585
|
' '=>' ','Þ'=>'Þ','þ'=>'þ','˜'=>'˜','×'=>'×',
|
586
|
'™'=>'™','Ú'=>'Ú','ú'=>'ú','⇑'=>'⇑','↑'=>'↑',
|
587
|
'Û'=>'Û','û'=>'û','Ù'=>'Ù','ù'=>'ù','¨'=>'¨',
|
588
|
'ϒ'=>'ϒ','Υ'=>'Υ','υ'=>'υ','Ü'=>'Ü','ü'=>'ü',
|
589
|
'℘'=>'℘','Ξ'=>'Ξ','ξ'=>'ξ','Ý'=>'Ý','ý'=>'ý',
|
590
|
'¥'=>'¥','Ÿ'=>'Ÿ','ÿ'=>'ÿ','Ζ'=>'Ζ','ζ'=>'ζ','‍'=>'‍',
|
591
|
'‌'=>'‌'
|
592
|
);
|
593
|
|
594
|
if ($in == 'HTML-ENTITIES') {
|
595
|
$string = strtr($string, $named_to_numbered_entities);
|
596
|
$string = preg_replace("/&#([0-9]+);/e", "code_to_utf8($1)", $string);
|
597
|
}
|
598
|
elseif ($out == 'HTML-ENTITIES') {
|
599
|
//$string = preg_replace("/&#([0-9]+);/e", "code_to_utf8($1)", $string);
|
600
|
$char = "";
|
601
|
while (strlen($string) > 0) {
|
602
|
preg_match("/^(.)(.*)$/su", $string, $match);
|
603
|
if (strlen($match[1]) > 1) {
|
604
|
$char .= "&#".uniord($match[1]).";";
|
605
|
} else $char .= $match[1];
|
606
|
$string = $match[2];
|
607
|
}
|
608
|
$string = $char;
|
609
|
$string = strtr($string, $numbered_to_named_entities);
|
610
|
}
|
611
|
return $string;
|
612
|
}
|
613
|
|
614
|
// support-function for string_decode_encode_entities()
|
615
|
function uniord($c) {
|
616
|
$ud = 0;
|
617
|
if (ord($c{0}) >= 0 && ord($c{0}) <= 127) $ud = ord($c{0});
|
618
|
if (ord($c{0}) >= 192 && ord($c{0}) <= 223) $ud = (ord($c{0})-192)*64 + (ord($c{1})-128);
|
619
|
if (ord($c{0}) >= 224 && ord($c{0}) <= 239) $ud = (ord($c{0})-224)*4096 + (ord($c{1})-128)*64 + (ord($c{2})-128);
|
620
|
if (ord($c{0}) >= 240 && ord($c{0}) <= 247) $ud = (ord($c{0})-240)*262144 + (ord($c{1})-128)*4096 + (ord($c{2})-128)*64 + (ord($c{3})-128);
|
621
|
if (ord($c{0}) >= 248 && ord($c{0}) <= 251) $ud = (ord($c{0})-248)*16777216 + (ord($c{1})-128)*262144 + (ord($c{2})-128)*4096 + (ord($c{3})-128)*64 + (ord($c{4})-128);
|
622
|
if (ord($c{0}) >= 252 && ord($c{0}) <= 253) $ud = (ord($c{0})-252)*1073741824 + (ord($c{1})-128)*16777216 + (ord($c{2})-128)*262144 + (ord($c{3})-128)*4096 + (ord($c{4})-128)*64 + (ord($c{5})-128);
|
623
|
if (ord($c{0}) >= 254 && ord($c{0}) <= 255) $ud = false; // error
|
624
|
return $ud;
|
625
|
}
|
626
|
// support-function for mb_convert_encoding_wrapper()
|
627
|
function code_to_utf8($num) {
|
628
|
if ($num <= 0x7F) {
|
629
|
return chr($num);
|
630
|
} elseif ($num <= 0x7FF) {
|
631
|
return chr(($num >> 6) + 192) . chr(($num & 63) + 128);
|
632
|
} elseif ($num <= 0xFFFF) {
|
633
|
return chr(($num >> 12) + 224) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128);
|
634
|
} elseif ($num <= 0x1FFFFF) {
|
635
|
return chr(($num >> 18) + 240) . chr((($num >> 12) & 63) + 128) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128);
|
636
|
}
|
637
|
return " ";
|
638
|
}
|
639
|
|
640
|
// Function to convert a string from mixed html-entities/umlauts to pure utf-8-umlauts
|
641
|
function string_to_utf8($string, $charset=DEFAULT_CHARSET) {
|
642
|
$charset = strtoupper($charset);
|
643
|
if ($charset == '') { $charset = 'ISO-8859-1'; }
|
644
|
|
645
|
if (!is_UTF8($string)) {
|
646
|
$string=mb_convert_encoding_wrapper($string, 'UTF-8', $charset);
|
647
|
}
|
648
|
// check if we really get UTF-8. We don't get UTF-8 if charset is ISO-8859-6 or ISO-2022-JP/KR
|
649
|
// and mb_string AND iconv aren't available.
|
650
|
if (is_UTF8($string)) {
|
651
|
$string=mb_convert_encoding_wrapper($string, 'HTML-ENTITIES', 'UTF-8');
|
652
|
$string=mb_convert_encoding_wrapper($string, 'UTF-8', 'HTML-ENTITIES');
|
653
|
} else {
|
654
|
// nothing we can do here :-(
|
655
|
}
|
656
|
return($string);
|
657
|
}
|
658
|
|
659
|
// function to check if a string is UTF-8
|
660
|
function is_UTF8 ($str) {
|
661
|
if (strlen($str) < 4000) {
|
662
|
// 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.
|
663
|
// 4000 works for me ...
|
664
|
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);
|
665
|
} else {
|
666
|
$isUTF8 = true;
|
667
|
while($str{0}) {
|
668
|
if (preg_match("/^[\x09\x0A\x0D\x20-\x7E]/", $str)) { $str = substr($str, 1); continue; }
|
669
|
if (preg_match("/^[\xC2-\xDF][\x80-\xBF]/", $str)) { $str = substr($str, 2); continue; }
|
670
|
if (preg_match("/^\xE0[\xA0-\xBF][\x80-\xBF]/", $str)) { $str = substr($str, 3); continue; }
|
671
|
if (preg_match("/^[\xE1-\xEC\xEE\xEF][\x80-\xBF]{2}/", $str)) { $str = substr($str, 3); continue; }
|
672
|
if (preg_match("/^\xED[\x80-\x9F][\x80-\xBF]/", $str)) { $str = substr($str, 3); continue; }
|
673
|
if (preg_match("/^\xF0[\x90-\xBF][\x80-\xBF]{2}/", $str)) { $str = substr($str, 4); continue; }
|
674
|
if (preg_match("/^[\xF1-\xF3][\x80-\xBF]{3}/", $str)) { $str = substr($str, 4); continue; }
|
675
|
if (preg_match("/^\xF4[\x80-\x8F][\x80-\xBF]{2}/", $str)) { $str = substr($str, 4); continue; }
|
676
|
if (preg_match("/^$/", $str)) { break; }
|
677
|
$isUTF8 = false;
|
678
|
break;
|
679
|
}
|
680
|
return ($isUTF8);
|
681
|
}
|
682
|
}
|
683
|
|
684
|
// Function to convert a string from mixed html-entities/umlauts to pure $charset_out-umlauts
|
685
|
function entities_to_umlauts($string, $charset_out=DEFAULT_CHARSET, $convert_htmlspecialchars=0) {
|
686
|
$charset_out = strtoupper($charset_out);
|
687
|
if ($charset_out == '') { $charset_out = 'ISO-8859-1'; }
|
688
|
$charset_in = strtoupper(DEFAULT_CHARSET);
|
689
|
|
690
|
// string to utf-8
|
691
|
if ($charset_in == 'ISO-8859-1' || $charset_in == 'UTF-8') {
|
692
|
if ($charset_in == 'ISO-8859-1') {
|
693
|
$string=utf8_encode($string);
|
694
|
}
|
695
|
// decode html-entities
|
696
|
if(preg_match("/&[#a-zA-Z0-9]+;/", $string)) {
|
697
|
$string=string_decode_encode_entities($string, 'UTF-8', 'HTML-ENTITIES');
|
698
|
//$string=mb_convert_encoding_wrapper($string, 'HTML-ENTITIES', 'UTF-8');
|
699
|
//$string=mb_convert_encoding_wrapper($string, 'UTF-8', 'HTML-ENTITIES');
|
700
|
}
|
701
|
}
|
702
|
else {
|
703
|
$string = string_to_utf8($string); // will decode html-entities, too.
|
704
|
}
|
705
|
// string to $charset_out
|
706
|
if($charset_out == 'ISO-8859-1') {
|
707
|
$string=utf8_decode($string);
|
708
|
}
|
709
|
elseif($charset_out != 'UTF-8' && is_UTF8($string)) {
|
710
|
$string=mb_convert_encoding_wrapper($string, $charset_out, 'UTF-8');
|
711
|
}
|
712
|
return $string;
|
713
|
}
|
714
|
|
715
|
// Function to convert a string from mixed html-entitites/$charset_in-umlauts to pure html-entities
|
716
|
function umlauts_to_entities($string, $charset_in=DEFAULT_CHARSET, $convert_htmlspecialchars=0) {
|
717
|
$charset_in = strtoupper($charset_in);
|
718
|
if ($charset_in == "") { $charset_in = 'ISO-8859-1'; }
|
719
|
|
720
|
// string to utf-8
|
721
|
if ($charset_in == 'ISO-8859-1' || $charset_in == 'UTF-8') {
|
722
|
if ($charset_in == 'ISO-8859-1') {
|
723
|
$string=utf8_encode($string);
|
724
|
}
|
725
|
// encode html-entities
|
726
|
//$string=string_decode_encode_entities($string, 'HTML-ENTITIES', 'UTF-8');
|
727
|
$string=mb_convert_encoding_wrapper($string, 'HTML-ENTITIES', 'UTF-8');
|
728
|
}
|
729
|
else {
|
730
|
$string = string_to_utf8($string, $charset_in);
|
731
|
// encode html-entities
|
732
|
if (is_UTF8($string)) {
|
733
|
//$string=string_decode_encode_entities($string, 'HTML-ENTITIES', 'UTF-8');
|
734
|
$string=mb_convert_encoding_wrapper($string, 'HTML-ENTITIES', 'UTF-8');
|
735
|
}
|
736
|
}
|
737
|
return $string;
|
738
|
}
|
739
|
|
740
|
// translate any latin/greek/cyrillic html-entities to their plain 7bit equivalents
|
741
|
// and numbered-entities into hex
|
742
|
function entities_to_7bit($string) {
|
743
|
require(WB_PATH.'/framework/convert.php');
|
744
|
$string = strtr($string, $conversion_array);
|
745
|
$string = preg_replace('/&#([0-9]+);/e', "dechex('$1')", $string);
|
746
|
return($string);
|
747
|
}
|
748
|
|
749
|
// Function to convert a page title to a page filename
|
750
|
function page_filename($string) {
|
751
|
$string = entities_to_7bit(umlauts_to_entities($string));
|
752
|
// Now replace spaces with page spcacer
|
753
|
$string = str_replace(' ', PAGE_SPACER, $string);
|
754
|
// Now remove all bad characters
|
755
|
$bad = array(
|
756
|
'\'', /* / */ '"', /* " */ '<', /* < */ '>', /* > */
|
757
|
'{', /* { */ '}', /* } */ '[', /* [ */ ']', /* ] */ '`', /* ` */
|
758
|
'!', /* ! */ '@', /* @ */ '#', /* # */ '$', /* $ */ '%', /* % */
|
759
|
'^', /* ^ */ '&', /* & */ '*', /* * */ '(', /* ( */ ')', /* ) */
|
760
|
'=', /* = */ '+', /* + */ '|', /* | */ '/', /* / */ '\\', /* \ */
|
761
|
';', /* ; */ ':', /* : */ ',', /* , */ '?' /* ? */
|
762
|
);
|
763
|
$string = str_replace($bad, '', $string);
|
764
|
// Now convert to lower-case
|
765
|
$string = strtolower($string);
|
766
|
// Now remove multiple page spacers
|
767
|
$string = str_replace(PAGE_SPACER.PAGE_SPACER, PAGE_SPACER, $string);
|
768
|
// Clean any page spacers at the end of string
|
769
|
$string = str_replace(PAGE_SPACER, ' ', $string);
|
770
|
$string = trim($string);
|
771
|
$string = str_replace(' ', PAGE_SPACER, $string);
|
772
|
// If there are any weird language characters, this will protect us against possible problems they could cause
|
773
|
$string = str_replace(array('%2F', '%'), array('/', ''), urlencode($string));
|
774
|
// Finally, return the cleaned string
|
775
|
return $string;
|
776
|
}
|
777
|
|
778
|
// Function to convert a desired media filename to a clean filename
|
779
|
function media_filename($string) {
|
780
|
$string = entities_to_7bit(umlauts_to_entities($string));
|
781
|
// Now remove all bad characters
|
782
|
$bad = array(
|
783
|
'\'', // '
|
784
|
'"', // "
|
785
|
'`', // `
|
786
|
'!', // !
|
787
|
'@', // @
|
788
|
'#', // #
|
789
|
'$', // $
|
790
|
'%', // %
|
791
|
'^', // ^
|
792
|
'&', // &
|
793
|
'*', // *
|
794
|
'=', // =
|
795
|
'+', // +
|
796
|
'|', // |
|
797
|
'/', // /
|
798
|
'\\', // \
|
799
|
';', // ;
|
800
|
':', // :
|
801
|
',', // ,
|
802
|
'?' // ?
|
803
|
);
|
804
|
$string = str_replace($bad, '', $string);
|
805
|
// Clean any page spacers at the end of string
|
806
|
$string = trim($string);
|
807
|
// Finally, return the cleaned string
|
808
|
return $string;
|
809
|
}
|
810
|
|
811
|
// Function to work out a page link
|
812
|
if(!function_exists('page_link')) {
|
813
|
function page_link($link) {
|
814
|
global $admin;
|
815
|
return $admin->page_link($link);
|
816
|
}
|
817
|
}
|
818
|
|
819
|
// Create a new file in the pages directory
|
820
|
function create_access_file($filename,$page_id,$level) {
|
821
|
global $admin;
|
822
|
if(!is_writable(WB_PATH.PAGES_DIRECTORY.'/')) {
|
823
|
$admin->print_error($MESSAGE['PAGES']['CANNOT_CREATE_ACCESS_FILE']);
|
824
|
} else {
|
825
|
// First make sure parent folder exists
|
826
|
$parent_folders = explode('/',str_replace(WB_PATH.PAGES_DIRECTORY, '', dirname($filename)));
|
827
|
$parents = '';
|
828
|
foreach($parent_folders AS $parent_folder) {
|
829
|
if($parent_folder != '/' AND $parent_folder != '') {
|
830
|
$parents .= '/'.$parent_folder;
|
831
|
if(!file_exists(WB_PATH.PAGES_DIRECTORY.$parents)) {
|
832
|
make_dir(WB_PATH.PAGES_DIRECTORY.$parents);
|
833
|
}
|
834
|
}
|
835
|
}
|
836
|
// The depth of the page directory in the directory hierarchy
|
837
|
// '/pages' is at depth 1
|
838
|
$pages_dir_depth=count(explode('/',PAGES_DIRECTORY))-1;
|
839
|
// Work-out how many ../'s we need to get to the index page
|
840
|
$index_location = '';
|
841
|
for($i = 0; $i < $level + $pages_dir_depth; $i++) {
|
842
|
$index_location .= '../';
|
843
|
}
|
844
|
$content = ''.
|
845
|
'<?php
|
846
|
$page_id = '.$page_id.';
|
847
|
require("'.$index_location.'config.php");
|
848
|
require(WB_PATH."/index.php");
|
849
|
?>';
|
850
|
$handle = fopen($filename, 'w');
|
851
|
fwrite($handle, $content);
|
852
|
fclose($handle);
|
853
|
// Chmod the file
|
854
|
change_mode($filename, 'file');
|
855
|
}
|
856
|
}
|
857
|
|
858
|
// Function for working out a file mime type (if the in-built PHP one is not enabled)
|
859
|
if(!function_exists('mime_content_type')) {
|
860
|
function mime_content_type($file) {
|
861
|
$file = escapeshellarg($file);
|
862
|
return trim(`file -bi $file`);
|
863
|
}
|
864
|
}
|
865
|
|
866
|
// Generate a thumbnail from an image
|
867
|
function make_thumb($source, $destination, $size) {
|
868
|
// Check if GD is installed
|
869
|
if(extension_loaded('gd') AND function_exists('imageCreateFromJpeg')) {
|
870
|
// First figure out the size of the thumbnail
|
871
|
list($original_x, $original_y) = getimagesize($source);
|
872
|
if ($original_x > $original_y) {
|
873
|
$thumb_w = $size;
|
874
|
$thumb_h = $original_y*($size/$original_x);
|
875
|
}
|
876
|
if ($original_x < $original_y) {
|
877
|
$thumb_w = $original_x*($size/$original_y);
|
878
|
$thumb_h = $size;
|
879
|
}
|
880
|
if ($original_x == $original_y) {
|
881
|
$thumb_w = $size;
|
882
|
$thumb_h = $size;
|
883
|
}
|
884
|
// Now make the thumbnail
|
885
|
$source = imageCreateFromJpeg($source);
|
886
|
$dst_img = ImageCreateTrueColor($thumb_w, $thumb_h);
|
887
|
imagecopyresampled($dst_img,$source,0,0,0,0,$thumb_w,$thumb_h,$original_x,$original_y);
|
888
|
imagejpeg($dst_img, $destination);
|
889
|
// Clear memory
|
890
|
imagedestroy($dst_img);
|
891
|
imagedestroy($source);
|
892
|
// Return true
|
893
|
return true;
|
894
|
} else {
|
895
|
return false;
|
896
|
}
|
897
|
}
|
898
|
|
899
|
// Function to work-out a single part of an octal permission value
|
900
|
function extract_permission($octal_value, $who, $action) {
|
901
|
// Make sure the octal value is 4 chars long
|
902
|
if(strlen($octal_value) == 0) {
|
903
|
$octal_value = '0000';
|
904
|
} elseif(strlen($octal_value) == 1) {
|
905
|
$octal_value = '000'.$octal_value;
|
906
|
} elseif(strlen($octal_value) == 2) {
|
907
|
$octal_value = '00'.$octal_value;
|
908
|
} elseif(strlen($octal_value) == 3) {
|
909
|
$octal_value = '0'.$octal_value;
|
910
|
} elseif(strlen($octal_value) == 4) {
|
911
|
$octal_value = ''.$octal_value;
|
912
|
} else {
|
913
|
$octal_value = '0000';
|
914
|
}
|
915
|
// Work-out what position of the octal value to look at
|
916
|
switch($who) {
|
917
|
case 'u':
|
918
|
$position = '1';
|
919
|
break;
|
920
|
case 'user':
|
921
|
$position = '1';
|
922
|
break;
|
923
|
case 'g':
|
924
|
$position = '2';
|
925
|
break;
|
926
|
case 'group':
|
927
|
$position = '2';
|
928
|
break;
|
929
|
case 'o':
|
930
|
$position = '3';
|
931
|
break;
|
932
|
case 'others':
|
933
|
$position = '3';
|
934
|
break;
|
935
|
}
|
936
|
// Work-out how long the octal value is and ajust acording
|
937
|
if(strlen($octal_value) == 4) {
|
938
|
$position = $position+1;
|
939
|
} elseif(strlen($octal_value) != 3) {
|
940
|
exit('Error');
|
941
|
}
|
942
|
// Now work-out what action the script is trying to look-up
|
943
|
switch($action) {
|
944
|
case 'r':
|
945
|
$action = 'r';
|
946
|
break;
|
947
|
case 'read':
|
948
|
$action = 'r';
|
949
|
break;
|
950
|
case 'w':
|
951
|
$action = 'w';
|
952
|
break;
|
953
|
case 'write':
|
954
|
$action = 'w';
|
955
|
break;
|
956
|
case 'e':
|
957
|
$action = 'e';
|
958
|
break;
|
959
|
case 'execute':
|
960
|
$action = 'e';
|
961
|
break;
|
962
|
}
|
963
|
// Get the value for "who"
|
964
|
$value = substr($octal_value, $position-1, 1);
|
965
|
// Now work-out the details of the value
|
966
|
switch($value) {
|
967
|
case '0':
|
968
|
$r = false;
|
969
|
$w = false;
|
970
|
$e = false;
|
971
|
break;
|
972
|
case '1':
|
973
|
$r = false;
|
974
|
$w = false;
|
975
|
$e = true;
|
976
|
break;
|
977
|
case '2':
|
978
|
$r = false;
|
979
|
$w = true;
|
980
|
$e = false;
|
981
|
break;
|
982
|
case '3':
|
983
|
$r = false;
|
984
|
$w = true;
|
985
|
$e = true;
|
986
|
break;
|
987
|
case '4':
|
988
|
$r = true;
|
989
|
$w = false;
|
990
|
$e = false;
|
991
|
break;
|
992
|
case '5':
|
993
|
$r = true;
|
994
|
$w = false;
|
995
|
$e = true;
|
996
|
break;
|
997
|
case '6':
|
998
|
$r = true;
|
999
|
$w = true;
|
1000
|
$e = false;
|
1001
|
break;
|
1002
|
case '7':
|
1003
|
$r = true;
|
1004
|
$w = true;
|
1005
|
$e = true;
|
1006
|
break;
|
1007
|
default:
|
1008
|
$r = false;
|
1009
|
$w = false;
|
1010
|
$e = false;
|
1011
|
}
|
1012
|
// And finally, return either true or false
|
1013
|
return $$action;
|
1014
|
}
|
1015
|
|
1016
|
// Function to delete a page
|
1017
|
function delete_page($page_id) {
|
1018
|
|
1019
|
global $admin, $database;
|
1020
|
|
1021
|
// Find out more about the page
|
1022
|
$database = new database();
|
1023
|
$query = "SELECT page_id,menu_title,page_title,level,link,parent,modified_by,modified_when FROM ".TABLE_PREFIX."pages WHERE page_id = '$page_id'";
|
1024
|
$results = $database->query($query);
|
1025
|
if($database->is_error()) {
|
1026
|
$admin->print_error($database->get_error());
|
1027
|
}
|
1028
|
if($results->numRows() == 0) {
|
1029
|
$admin->print_error($MESSAGE['PAGES']['NOT_FOUND']);
|
1030
|
}
|
1031
|
$results_array = $results->fetchRow();
|
1032
|
$parent = $results_array['parent'];
|
1033
|
$level = $results_array['level'];
|
1034
|
$link = $results_array['link'];
|
1035
|
$page_title = ($results_array['page_title']);
|
1036
|
$menu_title = ($results_array['menu_title']);
|
1037
|
|
1038
|
// Get the sections that belong to the page
|
1039
|
$query_sections = $database->query("SELECT section_id,module FROM ".TABLE_PREFIX."sections WHERE page_id = '$page_id'");
|
1040
|
if($query_sections->numRows() > 0) {
|
1041
|
while($section = $query_sections->fetchRow()) {
|
1042
|
// Set section id
|
1043
|
$section_id = $section['section_id'];
|
1044
|
// Include the modules delete file if it exists
|
1045
|
if(file_exists(WB_PATH.'/modules/'.$section['module'].'/delete.php')) {
|
1046
|
require(WB_PATH.'/modules/'.$section['module'].'/delete.php');
|
1047
|
}
|
1048
|
}
|
1049
|
}
|
1050
|
|
1051
|
// Update the pages table
|
1052
|
$query = "DELETE FROM ".TABLE_PREFIX."pages WHERE page_id = '$page_id'";
|
1053
|
$database->query($query);
|
1054
|
if($database->is_error()) {
|
1055
|
$admin->print_error($database->get_error());
|
1056
|
}
|
1057
|
|
1058
|
// Update the sections table
|
1059
|
$query = "DELETE FROM ".TABLE_PREFIX."sections WHERE page_id = '$page_id'";
|
1060
|
$database->query($query);
|
1061
|
if($database->is_error()) {
|
1062
|
$admin->print_error($database->get_error());
|
1063
|
}
|
1064
|
|
1065
|
// Include the ordering class or clean-up ordering
|
1066
|
require_once(WB_PATH.'/framework/class.order.php');
|
1067
|
$order = new order(TABLE_PREFIX.'pages', 'position', 'page_id', 'parent');
|
1068
|
$order->clean($parent);
|
1069
|
|
1070
|
// Unlink the page access file and directory
|
1071
|
$directory = WB_PATH.PAGES_DIRECTORY.$link;
|
1072
|
$filename = $directory.'.php';
|
1073
|
$directory .= '/';
|
1074
|
if(file_exists($filename) && substr($filename,0,1<>'.')) {
|
1075
|
if(!is_writable(WB_PATH.PAGES_DIRECTORY.'/')) {
|
1076
|
$admin->print_error($MESSAGE['PAGES']['CANNOT_DELETE_ACCESS_FILE']);
|
1077
|
} else {
|
1078
|
unlink($filename);
|
1079
|
if(file_exists($directory)) {
|
1080
|
rm_full_dir($directory);
|
1081
|
}
|
1082
|
}
|
1083
|
}
|
1084
|
|
1085
|
}
|
1086
|
|
1087
|
// Load module into DB
|
1088
|
function load_module($directory, $install = false) {
|
1089
|
global $database,$admin,$MESSAGE;
|
1090
|
if(file_exists($directory.'/info.php')) {
|
1091
|
require($directory.'/info.php');
|
1092
|
if(isset($module_name)) {
|
1093
|
if(!isset($module_license)) { $module_license = 'GNU General Public License'; }
|
1094
|
if(!isset($module_platform) AND isset($module_designed_for)) { $module_platform = $module_designed_for; }
|
1095
|
if(!isset($module_function) AND isset($module_type)) { $module_function = $module_type; }
|
1096
|
$module_function = strtolower($module_function);
|
1097
|
// Check that it doesn't already exist
|
1098
|
$result = $database->query("SELECT addon_id FROM ".TABLE_PREFIX."addons WHERE directory = '".$module_directory."' LIMIT 0,1");
|
1099
|
if($result->numRows() == 0) {
|
1100
|
// Load into DB
|
1101
|
$query = "INSERT INTO ".TABLE_PREFIX."addons ".
|
1102
|
"(directory,name,description,type,function,version,platform,author,license) ".
|
1103
|
"VALUES ('$module_directory','$module_name','".addslashes($module_description)."','module',".
|
1104
|
"'$module_function','$module_version','$module_platform','$module_author','$module_license')";
|
1105
|
$database->query($query);
|
1106
|
// Run installation script
|
1107
|
if($install == true) {
|
1108
|
if(file_exists($directory.'/install.php')) {
|
1109
|
require($directory.'/install.php');
|
1110
|
}
|
1111
|
}
|
1112
|
}
|
1113
|
}
|
1114
|
}
|
1115
|
}
|
1116
|
|
1117
|
// Load template into DB
|
1118
|
function load_template($directory) {
|
1119
|
global $database;
|
1120
|
if(file_exists($directory.'/info.php')) {
|
1121
|
require($directory.'/info.php');
|
1122
|
if(isset($template_name)) {
|
1123
|
if(!isset($template_license)) { $template_license = 'GNU General Public License'; }
|
1124
|
if(!isset($template_platform) AND isset($template_designed_for)) { $template_platform = $template_designed_for; }
|
1125
|
// Check that it doesn't already exist
|
1126
|
$result = $database->query("SELECT addon_id FROM ".TABLE_PREFIX."addons WHERE directory = '".$template_directory."' LIMIT 0,1");
|
1127
|
if($result->numRows() == 0) {
|
1128
|
// Load into DB
|
1129
|
$query = "INSERT INTO ".TABLE_PREFIX."addons ".
|
1130
|
"(directory,name,description,type,version,platform,author,license) ".
|
1131
|
"VALUES ('$template_directory','$template_name','".addslashes($template_description)."','template',".
|
1132
|
"'$template_version','$template_platform','$template_author','$template_license')";
|
1133
|
$database->query($query);
|
1134
|
}
|
1135
|
}
|
1136
|
}
|
1137
|
}
|
1138
|
|
1139
|
// Load language into DB
|
1140
|
function load_language($file) {
|
1141
|
global $database;
|
1142
|
if(file_exists($file)) {
|
1143
|
require($file);
|
1144
|
if(isset($language_name)) {
|
1145
|
if(!isset($language_license)) { $language_license = 'GNU General Public License'; }
|
1146
|
if(!isset($language_platform) AND isset($language_designed_for)) { $language_platform = $language_designed_for; }
|
1147
|
// Check that it doesn't already exist
|
1148
|
$result = $database->query("SELECT addon_id FROM ".TABLE_PREFIX."addons WHERE directory = '".$language_code."' LIMIT 0,1");
|
1149
|
if($result->numRows() == 0) {
|
1150
|
// Load into DB
|
1151
|
$query = "INSERT INTO ".TABLE_PREFIX."addons ".
|
1152
|
"(directory,name,type,version,platform,author,license) ".
|
1153
|
"VALUES ('$language_code','$language_name','language',".
|
1154
|
"'$language_version','$language_platform','$language_author','$language_license')";
|
1155
|
$database->query($query);
|
1156
|
}
|
1157
|
}
|
1158
|
}
|
1159
|
}
|
1160
|
|
1161
|
// Upgrade module info in DB, optionally start upgrade script
|
1162
|
function upgrade_module($directory, $upgrade = false) {
|
1163
|
global $database, $admin, $MESSAGE;
|
1164
|
$directory = WB_PATH . "/modules/$directory";
|
1165
|
if(file_exists($directory.'/info.php')) {
|
1166
|
require($directory.'/info.php');
|
1167
|
if(isset($module_name)) {
|
1168
|
if(!isset($module_license)) { $module_license = 'GNU General Public License'; }
|
1169
|
if(!isset($module_platform) AND isset($module_designed_for)) { $module_platform = $module_designed_for; }
|
1170
|
if(!isset($module_function) AND isset($module_type)) { $module_function = $module_type; }
|
1171
|
$module_function = strtolower($module_function);
|
1172
|
// Check that it does already exist
|
1173
|
$result = $database->query("SELECT addon_id FROM ".TABLE_PREFIX."addons WHERE directory = '".$module_directory."' LIMIT 0,1");
|
1174
|
if($result->numRows() > 0) {
|
1175
|
// Update in DB
|
1176
|
$query = "UPDATE " . TABLE_PREFIX . "addons SET " .
|
1177
|
"version = '$module_version', " .
|
1178
|
"description = '" . addslashes($module_description) . "', " .
|
1179
|
"platform = '$module_platform', " .
|
1180
|
"author = '$module_author', " .
|
1181
|
"license = '$module_license'" .
|
1182
|
"WHERE directory = '$module_directory'";
|
1183
|
$database->query($query);
|
1184
|
// Run upgrade script
|
1185
|
if($upgrade == true) {
|
1186
|
if(file_exists($directory.'/upgrade.php')) {
|
1187
|
require($directory.'/upgrade.php');
|
1188
|
}
|
1189
|
}
|
1190
|
}
|
1191
|
}
|
1192
|
}
|
1193
|
}
|
1194
|
|
1195
|
?>
|