Revision 1291
Added by Dietmar almost 15 years ago
functions.php | ||
---|---|---|
19 | 19 |
// Stop this file from being accessed directly |
20 | 20 |
if(!defined('WB_URL')) { |
21 | 21 |
header('Location: ../index.php'); |
22 |
exit(0);
|
|
22 |
exit; |
|
23 | 23 |
} |
24 | 24 |
|
25 | 25 |
// Define that this file has been loaded |
... | ... | |
29 | 29 |
function rm_full_dir($directory) |
30 | 30 |
{ |
31 | 31 |
// If suplied dirname is a file then unlink it |
32 |
if (is_file($directory)) { |
|
32 |
if (is_file($directory)) |
|
33 |
{ |
|
33 | 34 |
return unlink($directory); |
34 | 35 |
} |
35 |
|
|
36 | 36 |
// Empty the folder |
37 | 37 |
if (is_dir($directory)) |
38 | 38 |
{ |
... | ... | |
40 | 40 |
while (false !== $entry = $dir->read()) |
41 | 41 |
{ |
42 | 42 |
// Skip pointers |
43 |
if ($entry == '.' || $entry == '..') { |
|
44 |
continue; |
|
45 |
} |
|
46 |
|
|
43 |
if ($entry == '.' || $entry == '..') { continue; } |
|
47 | 44 |
// Deep delete directories |
48 |
if (is_dir("$directory/$entry")) { |
|
49 |
rm_full_dir("$directory/$entry"); |
|
45 |
if (is_dir($directory.'/'.$entry)) |
|
46 |
{ |
|
47 |
rm_full_dir($directory.'/'.$entry); |
|
50 | 48 |
} |
51 | 49 |
else |
52 | 50 |
{ |
53 |
unlink("$directory/$entry");
|
|
51 |
unlink($directory.'/'.$entry);
|
|
54 | 52 |
} |
55 | 53 |
} |
56 |
|
|
57 | 54 |
// Now delete the folder |
58 | 55 |
$dir->close(); |
59 | 56 |
return rmdir($directory); |
... | ... | |
64 | 61 |
function directory_list($directory) |
65 | 62 |
{ |
66 | 63 |
$list = array(); |
67 |
|
|
68 | 64 |
if (is_dir($directory)) |
69 | 65 |
{ |
70 | 66 |
// Open the directory then loop through its contents |
71 | 67 |
$dir = dir($directory); |
72 |
while (false !== $entry = $dir->read()) { |
|
68 |
while (false !== $entry = $dir->read()) |
|
69 |
{ |
|
73 | 70 |
// Skip pointers |
74 |
if(substr($entry, 0, 1) == '.' || $entry == '.svn') { |
|
75 |
continue; |
|
76 |
} |
|
71 |
if($entry[0] == '.') { continue; } |
|
77 | 72 |
// Add dir and contents to list |
78 |
if (is_dir("$directory/$entry")) { |
|
73 |
if (is_dir("$directory/$entry")) |
|
74 |
{ |
|
79 | 75 |
$list = array_merge($list, directory_list("$directory/$entry")); |
80 | 76 |
$list[] = "$directory/$entry"; |
81 | 77 |
} |
82 | 78 |
} |
83 |
|
|
84 | 79 |
$dir->close(); |
85 | 80 |
} |
86 | 81 |
// Now return the list |
... | ... | |
94 | 89 |
{ |
95 | 90 |
// Set the umask to 0 |
96 | 91 |
$umask = umask(0); |
97 |
|
|
98 | 92 |
// Open the directory then loop through its contents |
99 | 93 |
$dir = dir($directory); |
100 |
while (false !== $entry = $dir->read()) { |
|
94 |
while (false !== $entry = $dir->read()) |
|
95 |
{ |
|
101 | 96 |
// Skip pointers |
102 |
if(substr($entry, 0, 1) == '.' || $entry == '.svn') { |
|
103 |
continue; |
|
104 |
} |
|
97 |
if($entry[0] == '.') { continue; } |
|
105 | 98 |
// Chmod the sub-dirs contents |
106 |
if(is_dir("$directory/$entry")) { |
|
107 |
chmod_directory_contents("$directory/$entry", $file_mode); |
|
99 |
if(is_dir("$directory/$entry")) |
|
100 |
{ |
|
101 |
chmod_directory_contents($directory.'/'.$entry, $file_mode); |
|
108 | 102 |
} |
109 | 103 |
change_mode($directory.'/'.$entry); |
110 | 104 |
} |
... | ... | |
115 | 109 |
} |
116 | 110 |
|
117 | 111 |
// Function to open a directory and add to a file list |
118 |
function file_list($directory, $skip = array()) {
|
|
119 |
|
|
112 |
function file_list($directory, $skip = array()) |
|
113 |
{ |
|
120 | 114 |
$list = array(); |
121 | 115 |
$skip_file = false; |
122 |
|
|
123 | 116 |
if (is_dir($directory)) |
124 | 117 |
{ |
125 | 118 |
// Open the directory then loop through its contents |
... | ... | |
128 | 121 |
while (false !== $entry = $dir->read()) |
129 | 122 |
{ |
130 | 123 |
// Skip pointers |
131 |
if($entry == '.' || $entry == '..') |
|
132 |
{ |
|
133 |
$skip_file = true; |
|
134 |
} |
|
124 |
if($entry[0] == '.') { $skip_file = true; } |
|
135 | 125 |
// Check if we to skip anything else |
136 |
if($skip != array()) { |
|
126 |
if($skip != array()) |
|
127 |
{ |
|
137 | 128 |
foreach($skip AS $skip_name) |
138 | 129 |
{ |
139 | 130 |
if($entry == $skip_name) |
... | ... | |
157 | 148 |
} |
158 | 149 |
|
159 | 150 |
// Function to get a list of home folders not to show |
160 |
function get_home_folders() { |
|
151 |
function get_home_folders() |
|
152 |
{ |
|
161 | 153 |
global $database, $admin; |
162 | 154 |
$home_folders = array(); |
163 | 155 |
// Only return home folders is this feature is enabled |
164 | 156 |
// and user is not admin |
165 | 157 |
// if(HOME_FOLDERS AND ($_SESSION['GROUP_ID']!='1')) { |
166 |
if(HOME_FOLDERS AND (!in_array('1',explode(",", $_SESSION['GROUPS_ID'])))) { |
|
167 |
|
|
168 |
$query_home_folders = $database->query("SELECT home_folder FROM ".TABLE_PREFIX."users WHERE home_folder != '".$admin->get_home_folder()."'"); |
|
169 |
if($query_home_folders->numRows() > 0) { |
|
170 |
while($folder = $query_home_folders->fetchRow()) { |
|
158 |
if(HOME_FOLDERS AND (!in_array('1',explode(',', $_SESSION['GROUPS_ID'])))) |
|
159 |
{ |
|
160 |
$sql = 'SELECT `home_folder` FROM `'.TABLE_PREFIX.'users` WHERE `home_folder` != "'.$admin->get_home_folder().'"'; |
|
161 |
$query_home_folders = $database->query($sql); |
|
162 |
if($query_home_folders->numRows() > 0) |
|
163 |
{ |
|
164 |
while($folder = $query_home_folders->fetchRow()) |
|
165 |
{ |
|
171 | 166 |
$home_folders[$folder['home_folder']] = $folder['home_folder']; |
172 | 167 |
} |
173 | 168 |
} |
174 |
function remove_home_subs($directory = '/', $home_folders) { |
|
175 |
if($handle = opendir(WB_PATH.MEDIA_DIRECTORY.$directory)) { |
|
169 |
function remove_home_subs($directory = '/', $home_folders = '') |
|
170 |
{ |
|
171 |
if($handle = opendir(WB_PATH.MEDIA_DIRECTORY.$directory)) |
|
172 |
{ |
|
176 | 173 |
// Loop through the dirs to check the home folders sub-dirs are not shown |
177 |
while(false !== ($file = readdir($handle))) { |
|
178 |
if(substr($file, 0, 1) != '.' AND $file != '.svn' AND $file != 'index.php') { |
|
179 |
if(is_dir(WB_PATH.MEDIA_DIRECTORY.$directory.'/'.$file)) { |
|
180 |
if($directory != '/') { $file = $directory.'/'.$file; } else { $file = '/'.$file; } |
|
181 |
foreach($home_folders AS $hf) { |
|
174 |
while(false !== ($file = readdir($handle))) |
|
175 |
{ |
|
176 |
if($file[0] != '.' AND $file != 'index.php') |
|
177 |
{ |
|
178 |
if(is_dir(WB_PATH.MEDIA_DIRECTORY.$directory.'/'.$file)) |
|
179 |
{ |
|
180 |
if($directory != '/') |
|
181 |
{ |
|
182 |
$file = $directory.'/'.$file; |
|
183 |
} |
|
184 |
else |
|
185 |
{ |
|
186 |
$file = '/'.$file; |
|
187 |
} |
|
188 |
foreach($home_folders AS $hf) |
|
189 |
{ |
|
182 | 190 |
$hf_length = strlen($hf); |
183 |
if($hf_length > 0) { |
|
184 |
if(substr($file, 0, $hf_length+1) == $hf) { |
|
191 |
if($hf_length > 0) |
|
192 |
{ |
|
193 |
if(substr($file, 0, $hf_length+1) == $hf) |
|
194 |
{ |
|
185 | 195 |
$home_folders[$file] = $file; |
186 | 196 |
} |
187 | 197 |
} |
... | ... | |
213 | 223 |
} |
214 | 224 |
|
215 | 225 |
// Function to chmod files and directories |
216 |
function change_mode($name) { |
|
226 |
function change_mode($name) |
|
227 |
{ |
|
217 | 228 |
if(OPERATING_SYSTEM != 'windows') |
218 | 229 |
{ |
219 | 230 |
// Only chmod if os is not windows |
... | ... | |
245 | 256 |
} |
246 | 257 |
|
247 | 258 |
// Function to figure out if a parent exists |
248 |
function is_parent($page_id) { |
|
259 |
function is_parent($page_id) |
|
260 |
{ |
|
249 | 261 |
global $database; |
250 | 262 |
// Get parent |
251 |
$query = $database->query("SELECT parent FROM ".TABLE_PREFIX."pages WHERE page_id = '$page_id'");
|
|
252 |
$fetch = $query->fetchRow();
|
|
263 |
$sql = 'SELECT `parent` FROM `'.TABLE_PREFIX.'pages` WHERE `page_id` = '.$page_id;
|
|
264 |
$parent = $database->get_one($sql);
|
|
253 | 265 |
// If parent isnt 0 return its ID |
254 |
if($fetch['parent'] == '0') { |
|
266 |
if(is_null($parent)) |
|
267 |
{ |
|
255 | 268 |
return false; |
256 |
} else { |
|
257 |
return $fetch['parent']; |
|
258 | 269 |
} |
270 |
else |
|
271 |
{ |
|
272 |
return $parent; |
|
273 |
} |
|
259 | 274 |
} |
260 | 275 |
|
261 | 276 |
// Function to work out level |
262 |
function level_count($page_id) { |
|
277 |
function level_count($page_id) |
|
278 |
{ |
|
263 | 279 |
global $database; |
264 | 280 |
// Get page parent |
265 |
$query_page = $database->query("SELECT parent FROM ".TABLE_PREFIX."pages WHERE page_id = '$page_id' LIMIT 1"); |
|
266 |
$fetch_page = $query_page->fetchRow(); |
|
267 |
$parent = $fetch_page['parent']; |
|
268 |
if($parent > 0) { |
|
269 |
// Get the level of the parent |
|
270 |
$query_parent = $database->query("SELECT level FROM ".TABLE_PREFIX."pages WHERE page_id = '$parent' LIMIT 1"); |
|
271 |
$fetch_parent = $query_parent->fetchRow(); |
|
272 |
$level = $fetch_parent['level']; |
|
281 |
$sql = 'SELECT `parent` FROM `'.TABLE_PREFIX.'pages` WHERE `page_id` = '.$page_id; |
|
282 |
$parent = $database->get_one($sql); |
|
283 |
if($parent > 0) |
|
284 |
{ // Get the level of the parent |
|
285 |
$sql = 'SELECT `level` FROM `'.TABLE_PREFIX.'pages` WHERE `page_id` = '.$parent; |
|
286 |
$level = $database->get_one($sql); |
|
273 | 287 |
return $level+1; |
274 |
} else { |
|
288 |
} |
|
289 |
else |
|
290 |
{ |
|
275 | 291 |
return 0; |
276 | 292 |
} |
277 | 293 |
} |
278 | 294 |
|
279 | 295 |
// Function to work out root parent |
280 |
function root_parent($page_id) { |
|
296 |
function root_parent($page_id) |
|
297 |
{ |
|
281 | 298 |
global $database; |
282 | 299 |
// Get page details |
283 |
$query_page = $database->query("SELECT parent,level FROM ".TABLE_PREFIX."pages WHERE page_id = '$page_id' LIMIT 1"); |
|
300 |
$sql = 'SELECT `parent`, `level` FROM `'.TABLE_PREFIX.'pages` WHERE `page_id` = '.$page_id; |
|
301 |
$query_page = $database->query($sql); |
|
284 | 302 |
$fetch_page = $query_page->fetchRow(); |
285 | 303 |
$parent = $fetch_page['parent']; |
286 | 304 |
$level = $fetch_page['level']; |
287 |
if($level == 1) { |
|
305 |
if($level == 1) |
|
306 |
{ |
|
288 | 307 |
return $parent; |
289 |
} elseif($parent == 0) { |
|
308 |
} |
|
309 |
elseif($parent == 0) |
|
310 |
{ |
|
290 | 311 |
return $page_id; |
291 |
} else { |
|
292 |
// Figure out what the root parents id is |
|
312 |
} |
|
313 |
else |
|
314 |
{ // Figure out what the root parents id is |
|
293 | 315 |
$parent_ids = array_reverse(get_parent_ids($page_id)); |
294 | 316 |
return $parent_ids[0]; |
295 | 317 |
} |
296 | 318 |
} |
297 | 319 |
|
298 | 320 |
// Function to get page title |
299 |
function get_page_title($id) { |
|
321 |
function get_page_title($id) |
|
322 |
{ |
|
300 | 323 |
global $database; |
301 | 324 |
// Get title |
302 |
$query = $database->query("SELECT page_title FROM ".TABLE_PREFIX."pages WHERE page_id = '$id'"); |
|
303 |
$fetch = $query->fetchRow(); |
|
304 |
// Return title |
|
305 |
return $fetch['page_title']; |
|
325 |
$sql = 'SELECT `page_title` FROM `'.TABLE_PREFIX.'pages` WHERE `page_id` = '.$id; |
|
326 |
$page_title = $database->get_one($sql); |
|
327 |
return $page_title; |
|
306 | 328 |
} |
307 | 329 |
|
308 | 330 |
// Function to get a pages menu title |
309 |
function get_menu_title($id) {
|
|
310 |
// Connect to the database
|
|
311 |
$database = new database();
|
|
331 |
function get_menu_title($id) |
|
332 |
{
|
|
333 |
global $database;
|
|
312 | 334 |
// Get title |
313 |
$query = $database->query("SELECT menu_title FROM ".TABLE_PREFIX."pages WHERE page_id = '$id'"); |
|
314 |
$fetch = $query->fetchRow(); |
|
315 |
// Return title |
|
316 |
return $fetch['menu_title']; |
|
335 |
$sql = 'SELECT `menu_title` FROM `'.TABLE_PREFIX.'pages` WHERE `page_id` = '.$id; |
|
336 |
$menu_title = $database->get_one($sql); |
|
337 |
return $menu_title; |
|
317 | 338 |
} |
318 | 339 |
|
319 | 340 |
// Function to get all parent page titles |
320 |
function get_parent_titles($parent_id) { |
|
341 |
function get_parent_titles($parent_id) |
|
342 |
{ |
|
321 | 343 |
$titles[] = get_menu_title($parent_id); |
322 |
if(is_parent($parent_id) != false) { |
|
344 |
if(is_parent($parent_id) != false) |
|
345 |
{ |
|
323 | 346 |
$parent_titles = get_parent_titles(is_parent($parent_id)); |
324 | 347 |
$titles = array_merge($titles, $parent_titles); |
325 | 348 |
} |
... | ... | |
327 | 350 |
} |
328 | 351 |
|
329 | 352 |
// Function to get all parent page id's |
330 |
function get_parent_ids($parent_id) { |
|
353 |
function get_parent_ids($parent_id) |
|
354 |
{ |
|
331 | 355 |
$ids[] = $parent_id; |
332 |
if(is_parent($parent_id) != false) { |
|
356 |
if(is_parent($parent_id) != false) |
|
357 |
{ |
|
333 | 358 |
$parent_ids = get_parent_ids(is_parent($parent_id)); |
334 | 359 |
$ids = array_merge($ids, $parent_ids); |
335 | 360 |
} |
... | ... | |
342 | 367 |
} |
343 | 368 |
|
344 | 369 |
// Function to get all sub pages id's |
345 |
function get_subs($parent, $subs) { |
|
370 |
function get_subs($parent, $subs) |
|
371 |
{ |
|
346 | 372 |
// Connect to the database |
347 |
$database = new database();
|
|
373 |
global $database;
|
|
348 | 374 |
// Get id's |
349 |
$query = $database->query("SELECT page_id FROM ".TABLE_PREFIX."pages WHERE parent = '$parent'"); |
|
350 |
if($query->numRows() > 0) { |
|
351 |
while($fetch = $query->fetchRow()) { |
|
375 |
$sql = 'SELECT `page_id` FROM `'.TABLE_PREFIX.'pages` WHERE `parent` = '.$parent; |
|
376 |
$query = $database->query($sql); |
|
377 |
if($query->numRows() > 0) |
|
378 |
{ |
|
379 |
while($fetch = $query->fetchRow()) |
|
380 |
{ |
|
352 | 381 |
$subs[] = $fetch['page_id']; |
353 | 382 |
// Get subs of this sub |
354 | 383 |
$subs = get_subs($fetch['page_id'], $subs); |
... | ... | |
360 | 389 |
|
361 | 390 |
// Function as replacement for php's htmlspecialchars() |
362 | 391 |
// Will not mangle HTML-entities |
363 |
function my_htmlspecialchars($string) { |
|
392 |
function my_htmlspecialchars($string) |
|
393 |
{ |
|
364 | 394 |
$string = preg_replace('/&(?=[#a-z0-9]+;)/i', '__amp;_', $string); |
365 | 395 |
$string = strtr($string, array('<'=>'<', '>'=>'>', '&'=>'&', '"'=>'"', '\''=>''')); |
366 | 396 |
$string = preg_replace('/__amp;_(?=[#a-z0-9]+;)/i', '&', $string); |
... | ... | |
370 | 400 |
// Convert a string from mixed html-entities/umlauts to pure $charset_out-umlauts |
371 | 401 |
// Will replace all numeric and named entities except > < ' " ' |
372 | 402 |
// In case of error the returned string is unchanged, and a message is emitted. |
373 |
function entities_to_umlauts($string, $charset_out=DEFAULT_CHARSET) { |
|
403 |
function entities_to_umlauts($string, $charset_out=DEFAULT_CHARSET) |
|
404 |
{ |
|
374 | 405 |
require_once(WB_PATH.'/framework/functions-utf8.php'); |
375 | 406 |
return entities_to_umlauts2($string, $charset_out); |
376 | 407 |
} |
377 | 408 |
|
378 | 409 |
// Will convert a string in $charset_in encoding to a pure ASCII string with HTML-entities. |
379 | 410 |
// In case of error the returned string is unchanged, and a message is emitted. |
380 |
function umlauts_to_entities($string, $charset_in=DEFAULT_CHARSET) { |
|
411 |
function umlauts_to_entities($string, $charset_in=DEFAULT_CHARSET) |
|
412 |
{ |
|
381 | 413 |
require_once(WB_PATH.'/framework/functions-utf8.php'); |
382 | 414 |
return umlauts_to_entities2($string, $charset_in); |
383 | 415 |
} |
384 | 416 |
|
385 | 417 |
// Function to convert a page title to a page filename |
386 |
function page_filename($string) { |
|
418 |
function page_filename($string) |
|
419 |
{ |
|
387 | 420 |
require_once(WB_PATH.'/framework/functions-utf8.php'); |
388 | 421 |
$string = entities_to_7bit($string); |
389 | 422 |
// Now remove all bad characters |
... | ... | |
410 | 443 |
} |
411 | 444 |
|
412 | 445 |
// Function to convert a desired media filename to a clean filename |
413 |
function media_filename($string) { |
|
446 |
function media_filename($string) |
|
447 |
{ |
|
414 | 448 |
require_once(WB_PATH.'/framework/functions-utf8.php'); |
415 | 449 |
$string = entities_to_7bit($string); |
416 | 450 |
// Now remove all bad characters |
... | ... | |
446 | 480 |
} |
447 | 481 |
|
448 | 482 |
// Function to work out a page link |
449 |
if(!function_exists('page_link')) { |
|
450 |
function page_link($link) { |
|
483 |
if(!function_exists('page_link')) |
|
484 |
{ |
|
485 |
function page_link($link) |
|
486 |
{ |
|
451 | 487 |
global $admin; |
452 | 488 |
return $admin->page_link($link); |
453 | 489 |
} |
454 | 490 |
} |
455 | 491 |
|
456 | 492 |
// Create a new file in the pages directory |
457 |
function create_access_file($filename,$page_id,$level) { |
|
493 |
function create_access_file($filename,$page_id,$level) |
|
494 |
{ |
|
458 | 495 |
global $admin, $MESSAGE; |
459 |
if(!is_writable(WB_PATH.PAGES_DIRECTORY.'/')) { |
|
496 |
if(!is_writable(WB_PATH.PAGES_DIRECTORY.'/')) |
|
497 |
{ |
|
460 | 498 |
$admin->print_error($MESSAGE['PAGES']['CANNOT_CREATE_ACCESS_FILE']); |
461 |
} else { |
|
499 |
} |
|
500 |
else |
|
501 |
{ |
|
462 | 502 |
// First make sure parent folder exists |
463 | 503 |
$parent_folders = explode('/',str_replace(WB_PATH.PAGES_DIRECTORY, '', dirname($filename))); |
464 | 504 |
$parents = ''; |
465 |
foreach($parent_folders AS $parent_folder) { |
|
466 |
if($parent_folder != '/' AND $parent_folder != '') { |
|
505 |
foreach($parent_folders AS $parent_folder) |
|
506 |
{ |
|
507 |
if($parent_folder != '/' AND $parent_folder != '') |
|
508 |
{ |
|
467 | 509 |
$parents .= '/'.$parent_folder; |
468 |
if(!file_exists(WB_PATH.PAGES_DIRECTORY.$parents)) { |
|
510 |
if(!file_exists(WB_PATH.PAGES_DIRECTORY.$parents)) |
|
511 |
{ |
|
469 | 512 |
make_dir(WB_PATH.PAGES_DIRECTORY.$parents); |
470 | 513 |
} |
471 | 514 |
} |
... | ... | |
475 | 518 |
$pages_dir_depth=count(explode('/',PAGES_DIRECTORY))-1; |
476 | 519 |
// Work-out how many ../'s we need to get to the index page |
477 | 520 |
$index_location = ''; |
478 |
for($i = 0; $i < $level + $pages_dir_depth; $i++) { |
|
521 |
for($i = 0; $i < $level + $pages_dir_depth; $i++) |
|
522 |
{ |
|
479 | 523 |
$index_location .= '../'; |
480 | 524 |
} |
481 | 525 |
$content = ''. |
... | ... | |
493 | 537 |
} |
494 | 538 |
|
495 | 539 |
// Function for working out a file mime type (if the in-built PHP one is not enabled) |
496 |
if(!function_exists('mime_content_type')) { |
|
497 |
function mime_content_type($filename) { |
|
498 |
|
|
499 |
$mime_types = array( |
|
540 |
if(!function_exists('mime_content_type')) |
|
541 |
{ |
|
542 |
function mime_content_type($filename) |
|
543 |
{ |
|
544 |
$mime_types = array( |
|
500 | 545 |
'txt' => 'text/plain', |
501 | 546 |
'htm' => 'text/html', |
502 | 547 |
'html' => 'text/html', |
... | ... | |
555 | 600 |
$temp = explode('.',$filename); |
556 | 601 |
$ext = strtolower(array_pop($temp)); |
557 | 602 |
|
558 |
if (array_key_exists($ext, $mime_types)) { |
|
603 |
if (array_key_exists($ext, $mime_types)) |
|
604 |
{ |
|
559 | 605 |
return $mime_types[$ext]; |
560 | 606 |
} |
561 |
elseif (function_exists('finfo_open')) { |
|
607 |
elseif (function_exists('finfo_open')) |
|
608 |
{ |
|
562 | 609 |
$finfo = finfo_open(FILEINFO_MIME); |
563 | 610 |
$mimetype = finfo_file($finfo, $filename); |
564 | 611 |
finfo_close($finfo); |
565 | 612 |
return $mimetype; |
566 | 613 |
} |
567 |
else { |
|
614 |
else |
|
615 |
{ |
|
568 | 616 |
return 'application/octet-stream'; |
569 | 617 |
} |
570 | 618 |
} |
571 | 619 |
} |
572 | 620 |
|
573 | 621 |
// Generate a thumbnail from an image |
574 |
function make_thumb($source, $destination, $size) { |
|
622 |
function make_thumb($source, $destination, $size) |
|
623 |
{ |
|
575 | 624 |
// Check if GD is installed |
576 |
if(extension_loaded('gd') AND function_exists('imageCreateFromJpeg')) { |
|
625 |
if(extension_loaded('gd') AND function_exists('imageCreateFromJpeg')) |
|
626 |
{ |
|
577 | 627 |
// First figure out the size of the thumbnail |
578 | 628 |
list($original_x, $original_y) = getimagesize($source); |
579 |
if ($original_x > $original_y) { |
|
629 |
if ($original_x > $original_y) |
|
630 |
{ |
|
580 | 631 |
$thumb_w = $size; |
581 | 632 |
$thumb_h = $original_y*($size/$original_x); |
582 | 633 |
} |
583 |
if ($original_x < $original_y) { |
|
634 |
if ($original_x < $original_y) |
|
635 |
{ |
|
584 | 636 |
$thumb_w = $original_x*($size/$original_y); |
585 | 637 |
$thumb_h = $size; |
586 | 638 |
} |
587 |
if ($original_x == $original_y) { |
|
639 |
if ($original_x == $original_y) |
|
640 |
{ |
|
588 | 641 |
$thumb_w = $size; |
589 | 642 |
$thumb_h = $size; |
590 | 643 |
} |
... | ... | |
595 | 648 |
imagejpeg($dst_img, $destination); |
596 | 649 |
// Clear memory |
597 | 650 |
imagedestroy($dst_img); |
598 |
imagedestroy($source);
|
|
651 |
imagedestroy($source);
|
|
599 | 652 |
// Return true |
600 |
return true;
|
|
601 |
} else {
|
|
602 |
return false;
|
|
603 |
}
|
|
653 |
return true;
|
|
654 |
} else {
|
|
655 |
return false;
|
|
656 |
}
|
|
604 | 657 |
} |
605 | 658 |
|
606 |
// Function to work-out a single part of an octal permission value |
|
607 |
function extract_permission($octal_value, $who, $action) { |
|
608 |
// Make sure the octal value is 4 chars long |
|
609 |
if(strlen($octal_value) == 0) { |
|
610 |
$octal_value = '0000'; |
|
611 |
} elseif(strlen($octal_value) == 1) { |
|
612 |
$octal_value = '000'.$octal_value; |
|
613 |
} elseif(strlen($octal_value) == 2) { |
|
614 |
$octal_value = '00'.$octal_value; |
|
615 |
} elseif(strlen($octal_value) == 3) { |
|
616 |
$octal_value = '0'.$octal_value; |
|
617 |
} elseif(strlen($octal_value) == 4) { |
|
618 |
$octal_value = ''.$octal_value; |
|
619 |
} else { |
|
620 |
$octal_value = '0000'; |
|
659 |
/* |
|
660 |
* Function to work-out a single part of an octal permission value |
|
661 |
* |
|
662 |
* @param mixed $octal_value: an octal value as string (i.e. '0777') or real octal integer (i.e. 0777 | 777) |
|
663 |
* @param string $who: char or string for whom the permission is asked( U[ser] / G[roup] / O[thers] ) |
|
664 |
* @param string $action: char or string with the requested action( r[ead..] / w[rite..] / e|x[ecute..] ) |
|
665 |
* @return boolean |
|
666 |
*/ |
|
667 |
function extract_permission($octal_value, $who, $action) |
|
668 |
{ |
|
669 |
// Make sure that all arguments are set and $octal_value is a real octal-integer |
|
670 |
if( ($who == '') or ($action == '') or (preg_match( '/[^0-7]/', (string)$octal_value )) ) |
|
671 |
{ |
|
672 |
return false; // invalid argument, so return false |
|
621 | 673 |
} |
622 |
// Work-out what position of the octal value to look at |
|
623 |
switch($who) { |
|
624 |
case 'u': |
|
625 |
$position = '1'; |
|
626 |
break; |
|
627 |
case 'user': |
|
628 |
$position = '1'; |
|
629 |
break; |
|
630 |
case 'g': |
|
631 |
$position = '2'; |
|
632 |
break; |
|
633 |
case 'group': |
|
634 |
$position = '2'; |
|
635 |
break; |
|
636 |
case 'o': |
|
637 |
$position = '3'; |
|
638 |
break; |
|
639 |
case 'others': |
|
640 |
$position = '3'; |
|
641 |
break; |
|
674 |
// convert $octal_value into a decimal-integer to be sure having a valid value |
|
675 |
$right_mask = octdec($octal_value); |
|
676 |
$action_mask = 0; |
|
677 |
// set the $action related bit in $action_mask |
|
678 |
switch($action[0]) // get action from first char of $action |
|
679 |
{ |
|
680 |
case 'r': |
|
681 |
case 'R': |
|
682 |
$action_mask = 4; // set read-bit only (2^2) |
|
683 |
break; |
|
684 |
case 'w': |
|
685 |
case 'W': |
|
686 |
$action_mask = 2; // set write-bit only (2^1) |
|
687 |
break; |
|
688 |
case 'e': |
|
689 |
case 'E': |
|
690 |
case 'x': |
|
691 |
case 'X': |
|
692 |
$action_mask = 1; // set execute-bit only (2^0) |
|
693 |
break; |
|
694 |
default: |
|
695 |
return false; // undefined action name, so return false |
|
642 | 696 |
} |
643 |
// Work-out how long the octal value is and ajust acording |
|
644 |
if(strlen($octal_value) == 4) { |
|
645 |
$position = $position+1; |
|
646 |
} elseif(strlen($octal_value) != 3) { |
|
647 |
exit('Error'); |
|
697 |
// shift action-mask into the right position |
|
698 |
switch($who[0]) // get who from first char of $who |
|
699 |
{ |
|
700 |
case 'u': |
|
701 |
case 'U': |
|
702 |
$action_mask <<= 3; // shift left 3 bits |
|
703 |
case 'g': |
|
704 |
case 'G': |
|
705 |
$action_mask <<= 3; // shift left 3 bits |
|
706 |
case 'o': |
|
707 |
case 'O': |
|
708 |
/* NOP */ |
|
709 |
break; |
|
710 |
default: |
|
711 |
return false; // undefined who, so return false |
|
648 | 712 |
} |
649 |
// Now work-out what action the script is trying to look-up |
|
650 |
switch($action) { |
|
651 |
case 'r': |
|
652 |
$action = 'r'; |
|
653 |
break; |
|
654 |
case 'read': |
|
655 |
$action = 'r'; |
|
656 |
break; |
|
657 |
case 'w': |
|
658 |
$action = 'w'; |
|
659 |
break; |
|
660 |
case 'write': |
|
661 |
$action = 'w'; |
|
662 |
break; |
|
663 |
case 'e': |
|
664 |
$action = 'e'; |
|
665 |
break; |
|
666 |
case 'execute': |
|
667 |
$action = 'e'; |
|
668 |
break; |
|
669 |
} |
|
670 |
// Get the value for "who" |
|
671 |
$value = substr($octal_value, $position-1, 1); |
|
672 |
// Now work-out the details of the value |
|
673 |
switch($value) { |
|
674 |
case '0': |
|
675 |
$r = false; |
|
676 |
$w = false; |
|
677 |
$e = false; |
|
678 |
break; |
|
679 |
case '1': |
|
680 |
$r = false; |
|
681 |
$w = false; |
|
682 |
$e = true; |
|
683 |
break; |
|
684 |
case '2': |
|
685 |
$r = false; |
|
686 |
$w = true; |
|
687 |
$e = false; |
|
688 |
break; |
|
689 |
case '3': |
|
690 |
$r = false; |
|
691 |
$w = true; |
|
692 |
$e = true; |
|
693 |
break; |
|
694 |
case '4': |
|
695 |
$r = true; |
|
696 |
$w = false; |
|
697 |
$e = false; |
|
698 |
break; |
|
699 |
case '5': |
|
700 |
$r = true; |
|
701 |
$w = false; |
|
702 |
$e = true; |
|
703 |
break; |
|
704 |
case '6': |
|
705 |
$r = true; |
|
706 |
$w = true; |
|
707 |
$e = false; |
|
708 |
break; |
|
709 |
case '7': |
|
710 |
$r = true; |
|
711 |
$w = true; |
|
712 |
$e = true; |
|
713 |
break; |
|
714 |
default: |
|
715 |
$r = false; |
|
716 |
$w = false; |
|
717 |
$e = false; |
|
718 |
} |
|
719 |
// And finally, return either true or false |
|
720 |
return $$action; |
|
713 |
return( ($right_mask & $action_mask) != 0 ); // return result of binary-AND |
|
721 | 714 |
} |
722 | 715 |
|
723 | 716 |
// Function to delete a page |
724 |
function delete_page($page_id) {
|
|
725 |
|
|
717 |
function delete_page($page_id) |
|
718 |
{ |
|
726 | 719 |
global $admin, $database, $MESSAGE; |
727 |
|
|
728 | 720 |
// Find out more about the page |
729 | 721 |
$database = new database(); |
730 |
$query = "SELECT page_id,menu_title,page_title,level,link,parent,modified_by,modified_when FROM ".TABLE_PREFIX."pages WHERE page_id = '$page_id'"; |
|
731 |
$results = $database->query($query); |
|
732 |
if($database->is_error()) { |
|
733 |
$admin->print_error($database->get_error()); |
|
734 |
} |
|
735 |
if($results->numRows() == 0) { |
|
736 |
$admin->print_error($MESSAGE['PAGES']['NOT_FOUND']); |
|
737 |
} |
|
722 |
$sql = 'SELECT `page_id`, `menu_title`, `page_title`, `level`, `link`, `parent`, `modified_by`, `modified_when` '; |
|
723 |
$sql .= 'FROM `'.TABLE_PREFIX.'pages` WHERE `page_id` = '.$page_id; |
|
724 |
$results = $database->query($sql); |
|
725 |
if($database->is_error()) { $admin->print_error($database->get_error()); } |
|
726 |
if($results->numRows() == 0) { $admin->print_error($MESSAGE['PAGES']['NOT_FOUND']); } |
|
738 | 727 |
$results_array = $results->fetchRow(); |
739 |
$parent = $results_array['parent']; |
|
740 |
$level = $results_array['level']; |
|
741 |
$link = $results_array['link']; |
|
742 |
$page_title = ($results_array['page_title']);
|
|
743 |
$menu_title = ($results_array['menu_title']);
|
|
728 |
$parent = $results_array['parent'];
|
|
729 |
$level = $results_array['level'];
|
|
730 |
$link = $results_array['link'];
|
|
731 |
$page_title = $results_array['page_title'];
|
|
732 |
$menu_title = $results_array['menu_title'];
|
|
744 | 733 |
|
745 | 734 |
// Get the sections that belong to the page |
746 |
$query_sections = $database->query("SELECT section_id,module FROM ".TABLE_PREFIX."sections WHERE page_id = '$page_id'"); |
|
747 |
if($query_sections->numRows() > 0) { |
|
748 |
while($section = $query_sections->fetchRow()) { |
|
735 |
$sql = 'SELECT `section_id`, `module` FROM `'.TABLE_PREFIX.'sections` WHERE `page_id` = '.$page_id; |
|
736 |
$query_sections = $database->query($sql); |
|
737 |
if($query_sections->numRows() > 0) |
|
738 |
{ |
|
739 |
while($section = $query_sections->fetchRow()) |
|
740 |
{ |
|
749 | 741 |
// Set section id |
750 | 742 |
$section_id = $section['section_id']; |
751 | 743 |
// Include the modules delete file if it exists |
752 |
if(file_exists(WB_PATH.'/modules/'.$section['module'].'/delete.php')) { |
|
753 |
require(WB_PATH.'/modules/'.$section['module'].'/delete.php'); |
|
744 |
if(file_exists(WB_PATH.'/modules/'.$section['module'].'/delete.php')) |
|
745 |
{ |
|
746 |
include(WB_PATH.'/modules/'.$section['module'].'/delete.php'); |
|
754 | 747 |
} |
755 | 748 |
} |
756 | 749 |
} |
757 |
|
|
758 | 750 |
// Update the pages table |
759 |
$query = "DELETE FROM ".TABLE_PREFIX."pages WHERE page_id = '$page_id'"; |
|
760 |
$database->query($query); |
|
761 |
if($database->is_error()) { |
|
751 |
$sql = 'DELETE FROM `'.TABLE_PREFIX.'pages` WHERE `page_id` = '.$page_id; |
|
752 |
$database->query($sql); |
|
753 |
if($database->is_error()) |
|
754 |
{ |
|
762 | 755 |
$admin->print_error($database->get_error()); |
763 | 756 |
} |
764 |
|
|
765 | 757 |
// Update the sections table |
766 |
$query = "DELETE FROM ".TABLE_PREFIX."sections WHERE page_id = '$page_id'";
|
|
767 |
$database->query($query);
|
|
758 |
$sql = 'DELETE FROM `'.TABLE_PREFIX.'sections` WHERE `page_id` = '.$page_id;
|
|
759 |
$database->query($sql);
|
|
768 | 760 |
if($database->is_error()) { |
769 | 761 |
$admin->print_error($database->get_error()); |
770 | 762 |
} |
771 |
|
|
772 | 763 |
// Include the ordering class or clean-up ordering |
773 |
require_once(WB_PATH.'/framework/class.order.php');
|
|
764 |
include_once(WB_PATH.'/framework/class.order.php');
|
|
774 | 765 |
$order = new order(TABLE_PREFIX.'pages', 'position', 'page_id', 'parent'); |
775 | 766 |
$order->clean($parent); |
776 |
|
|
777 | 767 |
// Unlink the page access file and directory |
778 | 768 |
$directory = WB_PATH.PAGES_DIRECTORY.$link; |
779 | 769 |
$filename = $directory.PAGE_EXTENSION; |
780 | 770 |
$directory .= '/'; |
781 |
if(file_exists($filename)) { |
|
782 |
if(!is_writable(WB_PATH.PAGES_DIRECTORY.'/')) { |
|
771 |
if(file_exists($filename)) |
|
772 |
{ |
|
773 |
if(!is_writable(WB_PATH.PAGES_DIRECTORY.'/')) |
|
774 |
{ |
|
783 | 775 |
$admin->print_error($MESSAGE['PAGES']['CANNOT_DELETE_ACCESS_FILE']); |
784 |
} else { |
|
776 |
} |
|
777 |
else |
|
778 |
{ |
|
785 | 779 |
unlink($filename); |
786 |
if(file_exists($directory) && rtrim($directory,'/')!=WB_PATH.PAGES_DIRECTORY && substr($link, 0, 1) != '.') { |
|
780 |
if( file_exists($directory) && |
|
781 |
(rtrim($directory,'/') != WB_PATH.PAGES_DIRECTORY) && |
|
782 |
(substr($link, 0, 1) != '.')) |
|
783 |
{ |
|
787 | 784 |
rm_full_dir($directory); |
788 | 785 |
} |
789 | 786 |
} |
790 | 787 |
} |
791 |
|
|
792 | 788 |
} |
793 | 789 |
|
794 | 790 |
// Load module into DB |
795 |
function load_module($directory, $install = false) { |
|
791 |
function load_module($directory, $install = false) |
|
792 |
{ |
|
796 | 793 |
global $database,$admin,$MESSAGE; |
794 |
|
|
797 | 795 |
if(is_dir($directory) AND file_exists($directory.'/info.php')) |
798 | 796 |
{ |
799 | 797 |
require($directory.'/info.php'); |
800 | 798 |
if(isset($module_name)) |
801 |
{ |
|
802 |
if(!isset($module_license)) { $module_license = 'GNU General Public License'; } |
|
799 |
{
|
|
800 |
if(!isset($module_license)) { $module_license = 'GNU General Public License'; }
|
|
803 | 801 |
if(!isset($module_platform) AND isset($module_designed_for)) { $module_platform = $module_designed_for; } |
804 |
if(!isset($module_function) AND isset($module_type)) { $module_function = $module_type; } |
|
802 |
if(!isset($module_function) AND isset($module_type)) { $module_function = $module_type; }
|
|
805 | 803 |
$module_function = strtolower($module_function); |
806 | 804 |
// Check that it doesn't already exist |
807 |
$result = $database->query("SELECT addon_id FROM ".TABLE_PREFIX."addons WHERE type = 'module' AND directory = '".$module_directory."' LIMIT 0,1"); |
|
805 |
$sql = 'SELECT `addon_id` FROM `'.TABLE_PREFIX.'addons` '; |
|
806 |
$sql .= 'WHERE `type` = "module" AND `directory` = "'.$module_directory.'" LIMIT 0,1'; |
|
807 |
$result = $database->query($sql); |
|
808 | 808 |
if($result->numRows() == 0) |
809 | 809 |
{ |
810 | 810 |
// Load into DB |
811 |
$query = "INSERT INTO ".TABLE_PREFIX."addons ". |
|
812 |
"(directory,name,description,type,function,version,platform,author,license) ". |
|
813 |
"VALUES ('$module_directory','$module_name','".addslashes($module_description)."','module',". |
|
814 |
"'$module_function','$module_version','$module_platform','$module_author','$module_license')"; |
|
815 |
$database->query($query); |
|
811 |
$sql = 'INSERT INTO `'.TABLE_PREFIX.'addons` SET '; |
|
812 |
$sql .= '`directory` = "'.$module_directory.'", '; |
|
813 |
$sql .= '`name` = "'.$module_name.'", '; |
|
814 |
$sql .= '`description`= "'.addslashes($module_description).'", '; |
|
815 |
$sql .= '`type`= "module", '; |
|
816 |
$sql .= '`function` = "'.$module_function.'", '; |
|
817 |
$sql .= '`version` = "'.$module_version.'", '; |
|
818 |
$sql .= '`platform` = "'.$module_platform.'", '; |
|
819 |
$sql .= '`author` = "'.$module_author.'", '; |
|
820 |
$sql .= '`license` = "'.$module_license.'"'; |
|
821 |
$database->query($sql); |
|
816 | 822 |
// Run installation script |
817 | 823 |
if($install == true) |
818 | 824 |
{ |
819 |
if(file_exists($directory.'/install.php')) { |
|
825 |
if(file_exists($directory.'/install.php')) |
|
826 |
{ |
|
820 | 827 |
require($directory.'/install.php'); |
821 | 828 |
} |
822 | 829 |
} |
... | ... | |
826 | 833 |
} |
827 | 834 |
|
828 | 835 |
// Load template into DB |
829 |
function load_template($directory) { |
|
836 |
function load_template($directory) |
|
837 |
{ |
|
830 | 838 |
global $database; |
831 |
if(is_dir($directory) AND file_exists($directory.'/info.php')) { |
|
839 |
if(is_dir($directory) AND file_exists($directory.'/info.php')) |
|
840 |
{ |
|
832 | 841 |
require($directory.'/info.php'); |
833 |
if(isset($template_name)) { |
|
834 |
if(!isset($template_license)) { $template_license = 'GNU General Public License'; } |
|
842 |
if(isset($template_name)) |
|
843 |
{ |
|
844 |
if(!isset($template_license)) { $template_license = 'GNU General Public License'; } |
|
835 | 845 |
if(!isset($template_platform) AND isset($template_designed_for)) { $template_platform = $template_designed_for; } |
836 |
if(!isset($template_function)) { $template_function = 'template'; } |
|
846 |
if(!isset($template_function)) { $template_function = 'template'; }
|
|
837 | 847 |
// Check that it doesn't already exist |
838 |
$result = $database->query("SELECT addon_id FROM ".TABLE_PREFIX."addons WHERE type = 'template' AND directory = '".$template_directory."' LIMIT 0,1"); |
|
839 |
if($result->numRows() == 0) { |
|
848 |
$sql = 'SELECT `addon_id` FROM `'.TABLE_PREFIX.'addons` '; |
|
849 |
$sql .= 'WHERE `type` = "template" AND `directory` = "'.$template_directory.'" LIMIT 0,1'; |
|
850 |
$result = $database->query($sql); |
|
851 |
if($result->numRows() == 0) |
|
852 |
{ |
|
840 | 853 |
// Load into DB |
841 |
$query = "INSERT INTO ".TABLE_PREFIX."addons ". |
|
842 |
"(directory,name,description,type,function,version,platform,author,license) ". |
|
843 |
"VALUES ('$template_directory','$template_name','".addslashes($template_description)."','template',". |
|
844 |
"'$template_function','$template_version','$template_platform','$template_author','$template_license')"; |
|
845 |
$database->query($query); |
|
854 |
$sql = 'INSERT INTO `'.TABLE_PREFIX.'addons` SET '; |
|
855 |
$sql .= '`directory` = "'.$template_directory.'", '; |
|
856 |
$sql .= '`name` = "'.$template_name.'", '; |
|
857 |
$sql .= '`description`= "'.addslashes($template_description).'", '; |
|
858 |
$sql .= '`type`= "template", '; |
|
859 |
$sql .= '`function` = "'.$template_function.'", '; |
|
860 |
$sql .= '`version` = "'.$template_version.'", '; |
|
861 |
$sql .= '`platform` = "'.$template_platform.'", '; |
|
862 |
$sql .= '`author` = "'.$template_author.'", '; |
|
863 |
$sql .= '`license` = "'.$template_license.'"'; |
|
864 |
$database->query($sql); |
|
846 | 865 |
} |
847 | 866 |
} |
848 | 867 |
} |
849 | 868 |
} |
850 | 869 |
|
851 | 870 |
// Load language into DB |
852 |
function load_language($file) { |
|
871 |
function load_language($file) |
|
872 |
{ |
|
853 | 873 |
global $database; |
854 |
if (file_exists($file) && preg_match('#^([A-Z]{2}.php)#', basename($file))) { |
|
874 |
if (file_exists($file) && preg_match('#^([A-Z]{2}.php)#', basename($file))) |
|
875 |
{ |
|
855 | 876 |
require($file); |
856 |
if(isset($language_name)) { |
|
857 |
if(!isset($language_license)) { $language_license = 'GNU General Public License'; } |
|
877 |
if(isset($language_name)) |
|
878 |
{ |
|
879 |
if(!isset($language_license)) { $language_license = 'GNU General Public License'; } |
|
858 | 880 |
if(!isset($language_platform) AND isset($language_designed_for)) { $language_platform = $language_designed_for; } |
859 | 881 |
// Check that it doesn't already exist |
860 |
$result = $database->query("SELECT addon_id FROM ".TABLE_PREFIX."addons WHERE type = 'language' AND directory = '".$language_code."' LIMIT 0,1"); |
|
861 |
if($result->numRows() == 0) { |
|
882 |
$sql = 'SELECT `addon_id` FROM `'.TABLE_PREFIX.'addons` '; |
|
883 |
$sql .= 'WHERE `type` = "language" AND `directory` = "'.$language_code.'" LIMIT 0,1'; |
|
884 |
$result = $database->query($sql); |
|
885 |
if($result->numRows() == 0) |
|
886 |
{ |
|
862 | 887 |
// Load into DB |
863 |
$query = "INSERT INTO ".TABLE_PREFIX."addons ". |
|
864 |
"(directory,name,type,version,platform,author,license) ". |
|
865 |
"VALUES ('$language_code','$language_name','language',". |
|
866 |
"'$language_version','$language_platform','$language_author','$language_license')"; |
|
867 |
$database->query($query); |
|
888 |
$sql = 'INSERT INTO `'.TABLE_PREFIX.'addons` SET '; |
|
889 |
$sql .= '`directory` = "'.$language_code.'", '; |
|
890 |
$sql .= '`name` = "'.$language_name.'", '; |
|
891 |
$sql .= '`type`= "language", '; |
|
892 |
$sql .= '`version` = "'.$language_version.'", '; |
|
893 |
$sql .= '`platform` = "'.$language_platform.'", '; |
|
894 |
$sql .= '`author` = "'.$language_author.'", '; |
|
895 |
$sql .= '`license` = "'.$language_license.'"'; |
|
896 |
$database->query($sql); |
|
868 | 897 |
} |
869 | 898 |
} |
870 | 899 |
} |
871 | 900 |
} |
872 | 901 |
|
873 | 902 |
// Upgrade module info in DB, optionally start upgrade script |
874 |
function upgrade_module($directory, $upgrade = false) { |
|
903 |
function upgrade_module($directory, $upgrade = false) |
|
904 |
{ |
|
875 | 905 |
global $database, $admin, $MESSAGE; |
876 |
$directory = WB_PATH . "/modules/$directory"; |
|
877 |
if(file_exists($directory.'/info.php')) { |
|
906 |
$directory = WB_PATH.'/modules/'.$directory; |
|
907 |
if(file_exists($directory.'/info.php')) |
|
908 |
{ |
|
878 | 909 |
require($directory.'/info.php'); |
879 |
if(isset($module_name)) { |
|
880 |
if(!isset($module_license)) { $module_license = 'GNU General Public License'; } |
|
910 |
if(isset($module_name)) |
|
911 |
{ |
|
912 |
if(!isset($module_license)) { $module_license = 'GNU General Public License'; } |
|
881 | 913 |
if(!isset($module_platform) AND isset($module_designed_for)) { $module_platform = $module_designed_for; } |
882 |
if(!isset($module_function) AND isset($module_type)) { $module_function = $module_type; } |
|
914 |
if(!isset($module_function) AND isset($module_type)) { $module_function = $module_type; }
|
|
883 | 915 |
$module_function = strtolower($module_function); |
884 | 916 |
// Check that it does already exist |
885 |
$result = $database->query("SELECT addon_id FROM ".TABLE_PREFIX."addons WHERE directory = '".$module_directory."' LIMIT 0,1"); |
|
886 |
if($result->numRows() > 0) { |
|
917 |
$sql = 'SELECT `addon_id` FROM `'.TABLE_PREFIX.'addons` '; |
|
918 |
$sql .= 'WHERE `directory` = "'.$module_directory.'" LIMIT 0,1'; |
|
919 |
$result = $database->query($sql); |
|
920 |
if($result->numRows() > 0) |
|
921 |
{ |
|
887 | 922 |
// Update in DB |
888 |
$query = "UPDATE " . TABLE_PREFIX . "addons SET " .
|
|
889 |
"version = '$module_version', " .
|
|
890 |
"description = '" . addslashes($module_description) . "', " .
|
|
891 |
"platform = '$module_platform', " .
|
|
892 |
"author = '$module_author', " .
|
|
893 |
"license = '$module_license'" .
|
|
894 |
"WHERE directory = '$module_directory'";
|
|
895 |
$database->query($query);
|
|
923 |
$sql = 'UPDATE `'.TABLE_PREFIX.'addons` SET ';
|
|
924 |
$sql .= '`version` = "'.$module_version.'", ';
|
|
925 |
$sql .= '`description` = "'.addslashes($module_description).'", ';
|
|
926 |
$sql .= '`platform` = "'.$module_platform.'", ';
|
|
927 |
$sql .= '`author` = "'.$module_author.'", ';
|
|
928 |
$sql .= '`license` = "'.$module_license.'", ';
|
|
929 |
$sql .= 'WHERE `directory` = "'.$module_directory.'"';
|
|
930 |
$database->query($sql);
|
|
896 | 931 |
// Run upgrade script |
897 |
if($upgrade == true) { |
|
898 |
if(file_exists($directory.'/upgrade.php')) { |
|
932 |
if($upgrade == true) |
|
933 |
{ |
|
934 |
if(file_exists($directory.'/upgrade.php')) |
|
935 |
{ |
|
899 | 936 |
require($directory.'/upgrade.php'); |
900 | 937 |
} |
901 | 938 |
} |
... | ... | |
905 | 942 |
} |
906 | 943 |
|
907 | 944 |
// extracts the content of a string variable from a string (save alternative to including files) |
908 |
if(!function_exists('get_variable_content')) { |
|
909 |
function get_variable_content($search, $data, $striptags=true, $convert_to_entities=true) { |
|
945 |
if(!function_exists('get_variable_content')) |
|
946 |
{ |
|
947 |
function get_variable_content($search, $data, $striptags=true, $convert_to_entities=true) |
|
948 |
{ |
|
910 | 949 |
$match = ''; |
911 | 950 |
// search for $variable followed by 0-n whitespace then by = then by 0-n whitespace |
912 | 951 |
// then either " or ' then 0-n characters then either " or ' followed by 0-n whitespace and ; |
913 | 952 |
// the variable name is returned in $match[1], the content in $match[3] |
914 |
if (preg_match('/(\$' .$search .')\s*=\s*("|\')(.*)\2\s*;/', $data, $match)) { |
|
915 |
if(strip_tags(trim($match[1])) == '$' .$search) { |
|
953 |
if (preg_match('/(\$' .$search .')\s*=\s*("|\')(.*)\2\s*;/', $data, $match)) |
|
954 |
{ |
|
955 |
if(strip_tags(trim($match[1])) == '$' .$search) |
|
956 |
{ |
|
916 | 957 |
// variable name matches, return it's value |
917 | 958 |
$match[3] = ($striptags == true) ? strip_tags($match[3]) : $match[3]; |
918 | 959 |
$match[3] = ($convert_to_entities == true) ? htmlentities($match[3]) : $match[3]; |
Also available in: Unified diff
recoded function extract_permission in /framework/functions.php
change URL_HELP to http://www.websitebaker2.org/ in /framework/class.admin.php
recoded function preprocess in /framework/class.frontend.php
optimize function getVersion in /framework/addon.precheck.inc.php