Revision 1365
Added by Dietmar almost 14 years ago
functions.php | ||
---|---|---|
25 | 25 |
// Define that this file has been loaded |
26 | 26 |
define('FUNCTIONS_FILE_LOADED', true); |
27 | 27 |
|
28 |
// Function to remove a non-empty directory |
|
29 |
function rm_full_dir($directory) |
|
30 |
{ |
|
28 |
/** |
|
29 |
* @description: recursively delete a non empty directory |
|
30 |
* @param string $directory : |
|
31 |
* @param bool $empty : true if you want the folder just emptied, but not deleted |
|
32 |
* false, or just simply leave it out, the given directory will be deleted, as well |
|
33 |
* @return boolean: list of ro-dirs |
|
34 |
* @from http://www.php.net/manual/de/function.rmdir.php#98499 |
|
35 |
*/ |
|
36 |
function rm_full_dir($directory, $empty = false) { |
|
37 |
|
|
38 |
if(substr($directory,-1) == "/") |
|
39 |
{ |
|
40 |
$directory = substr($directory,0,-1); |
|
41 |
} |
|
42 |
|
|
31 | 43 |
// If suplied dirname is a file then unlink it |
32 |
if (is_file($directory))
|
|
44 |
if (is_file( $directory ))
|
|
33 | 45 |
{ |
34 | 46 |
return unlink($directory); |
35 | 47 |
} |
36 |
// Empty the folder |
|
37 |
if (is_dir($directory)) |
|
38 |
{ |
|
39 |
$dir = dir($directory); |
|
40 |
while (false !== $entry = $dir->read()) |
|
41 |
{ |
|
42 |
// Skip pointers |
|
43 |
if ($entry == '.' || $entry == '..') { continue; } |
|
44 |
// Deep delete directories |
|
45 |
if (is_dir($directory.'/'.$entry)) |
|
48 |
|
|
49 |
if(!file_exists($directory) || !is_dir($directory)) |
|
50 |
{ |
|
51 |
return false; |
|
52 |
} elseif(!is_readable($directory)) |
|
53 |
{ |
|
54 |
return false; |
|
55 |
} else { |
|
56 |
$directoryHandle = opendir($directory); |
|
57 |
|
|
58 |
while ($contents = readdir($directoryHandle)) |
|
59 |
{ |
|
60 |
if($contents != '.' && $contents != '..') |
|
46 | 61 |
{ |
47 |
rm_full_dir($directory.'/'.$entry); |
|
62 |
$path = $directory . "/" . $contents; |
|
63 |
|
|
64 |
if(is_dir($path)) |
|
65 |
{ |
|
66 |
rm_full_dir($path); |
|
67 |
} else { |
|
68 |
unlink($path); |
|
69 |
} |
|
48 | 70 |
} |
49 |
else |
|
50 |
{ |
|
51 |
unlink($directory.'/'.$entry); |
|
71 |
} |
|
72 |
|
|
73 |
closedir($directoryHandle); |
|
74 |
|
|
75 |
if($empty == false) |
|
76 |
{ |
|
77 |
if(!rmdir($directory)) |
|
78 |
{ |
|
79 |
return false; |
|
52 | 80 |
} |
53 | 81 |
} |
54 |
// Now delete the folder |
|
55 |
$dir->close(); |
|
56 |
return rmdir($directory); |
|
57 |
} |
|
82 |
|
|
83 |
return true; |
|
84 |
} |
|
58 | 85 |
} |
59 | 86 |
|
60 | 87 |
/* |
... | ... | |
90 | 117 |
} |
91 | 118 |
$dir->close(); |
92 | 119 |
} |
120 |
|
|
121 |
// sorting |
|
122 |
if(natcasesort($result_list)) |
|
123 |
{ |
|
124 |
// new indexing |
|
125 |
$result_list = array_merge($result_list); |
|
126 |
} |
|
93 | 127 |
return $result_list; // Now return the list |
94 | 128 |
} |
95 | 129 |
|
... | ... | |
119 | 153 |
} |
120 | 154 |
} |
121 | 155 |
|
156 |
/** |
|
157 |
* Scan a given directory for dirs and files. |
|
158 |
* |
|
159 |
* usage: scan_current_dir ($root = '' ) |
|
160 |
* |
|
161 |
* @param $root set a absolute rootpath as string. if root is empty the current path will be scan |
|
162 |
* @param $search set a search pattern for files, empty search brings all files |
|
163 |
* @access public |
|
164 |
* @return array returns a natsort array with keys 'path' and 'filename' |
|
165 |
* |
|
166 |
*/ |
|
167 |
if(!function_exists('scan_current_dir')) |
|
168 |
{ |
|
169 |
function scan_current_dir($root = '', $search = '/.*/') |
|
170 |
{ |
|
171 |
$FILE = array(); |
|
172 |
$array = array(); |
|
173 |
clearstatcache(); |
|
174 |
$root = empty ($root) ? getcwd() : $root; |
|
175 |
if (($handle = opendir($root))) |
|
176 |
{ |
|
177 |
// Loop through the files and dirs an add to list DIRECTORY_SEPARATOR |
|
178 |
while (false !== ($file = readdir($handle))) |
|
179 |
{ |
|
180 |
if (substr($file, 0, 1) != '.' && $file != 'index.php') |
|
181 |
{ |
|
182 |
if (is_dir($root.'/'.$file)) |
|
183 |
{ |
|
184 |
$FILE['path'][] = $file; |
|
185 |
} elseif (preg_match($search, $file, $array) ) |
|
186 |
{ |
|
187 |
$FILE['filename'][] = $array[0]; |
|
188 |
} |
|
189 |
} |
|
190 |
} |
|
191 |
$close_verz = closedir($handle); |
|
192 |
} |
|
193 |
|
|
194 |
// sorting |
|
195 |
if (isset ($FILE['path']) && natcasesort($FILE['path'])) |
|
196 |
{ |
|
197 |
// new indexing |
|
198 |
$FILE['path'] = array_merge($FILE['path']); |
|
199 |
} |
|
200 |
// sorting |
|
201 |
if (isset ($FILE['filename']) && natcasesort($FILE['filename'])) |
|
202 |
{ |
|
203 |
// new indexing |
|
204 |
$FILE['filename'] = array_merge($FILE['filename']); |
|
205 |
} |
|
206 |
return $FILE; |
|
207 |
} |
|
208 |
} |
|
209 |
|
|
122 | 210 |
// Function to open a directory and add to a file list |
123 | 211 |
function file_list($directory, $skip = array(), $show_hidden = false) |
124 | 212 |
{ |
... | ... | |
138 | 226 |
} |
139 | 227 |
$dir->close(); // Now close the folder object |
140 | 228 |
} |
141 |
natsort($result_list); // make the list nice. Not all OS do this itself |
|
229 |
|
|
230 |
// make the list nice. Not all OS do this itself |
|
231 |
if(natcasesort($result_list)) |
|
232 |
{ |
|
233 |
$result_list = array_merge($result_list); |
|
234 |
} |
|
235 |
|
|
142 | 236 |
return $result_list; |
143 | 237 |
} |
144 | 238 |
|
... | ... | |
163 | 257 |
} |
164 | 258 |
function remove_home_subs($directory = '/', $home_folders = '') |
165 | 259 |
{ |
166 |
if($handle = opendir(WB_PATH.MEDIA_DIRECTORY.$directory))
|
|
260 |
if( ($handle = opendir(WB_PATH.MEDIA_DIRECTORY.$directory)) )
|
|
167 | 261 |
{ |
168 | 262 |
// Loop through the dirs to check the home folders sub-dirs are not shown |
169 | 263 |
while(false !== ($file = readdir($handle))) |
170 | 264 |
{ |
171 |
if($file[0] != '.' AND $file != 'index.php')
|
|
265 |
if($file[0] != '.' && $file != 'index.php')
|
|
172 | 266 |
{ |
173 | 267 |
if(is_dir(WB_PATH.MEDIA_DIRECTORY.$directory.'/'.$file)) |
174 | 268 |
{ |
... | ... | |
203 | 297 |
return $home_folders; |
204 | 298 |
} |
205 | 299 |
|
300 |
/* |
|
301 |
* @param object &$wb: $wb from frontend or $admin from backend |
|
302 |
* @return array: list of new entries |
|
303 |
* @description: callback remove path in files/dirs stored in array |
|
304 |
* @example: array_walk($array,'remove_path',PATH); |
|
305 |
*/ |
|
306 |
// |
|
307 |
function remove_path(&$path, $key, $vars = '') |
|
308 |
{ |
|
309 |
$path = str_replace($vars, '', $path); |
|
310 |
} |
|
311 |
|
|
312 |
/* |
|
313 |
* @param object &$wb: $wb from frontend or $admin from backend |
|
314 |
* @return array: list of ro-dirs |
|
315 |
* @description: returns a list of directories beyound /wb/media which are ReadOnly for current user |
|
316 |
*/ |
|
317 |
function media_dirs_ro( &$wb ) |
|
318 |
{ |
|
319 |
global $database; |
|
320 |
// if user is admin or home-folders not activated then there are no restrictions |
|
321 |
$allow_list = array(); |
|
322 |
if( $wb->get_user_id() == 1 || !HOME_FOLDERS ) |
|
323 |
{ |
|
324 |
return array(); |
|
325 |
} |
|
326 |
// at first read any dir and subdir from /media |
|
327 |
$full_list = directory_list( WB_PATH.MEDIA_DIRECTORY ); |
|
328 |
// add own home_folder to allow-list |
|
329 |
if( $wb->get_home_folder() ) |
|
330 |
{ |
|
331 |
// old: $allow_list[] = get_home_folder(); |
|
332 |
$allow_list[] = $wb->get_home_folder(); |
|
333 |
} |
|
334 |
// get groups of current user |
|
335 |
$curr_groups = $wb->get_groups_id(); |
|
336 |
// if current user is in admin-group |
|
337 |
if( ($admin_key = array_search('1', $curr_groups)) !== false) |
|
338 |
{ |
|
339 |
// remove admin-group from list |
|
340 |
unset($curr_groups[$admin_key]); |
|
341 |
// search for all users where the current user is admin from |
|
342 |
foreach( $curr_groups as $group) |
|
343 |
{ |
|
344 |
$sql = 'SELECT `home_folder` FROM `'.TABLE_PREFIX.'users` '; |
|
345 |
$sql .= 'WHERE (FIND_IN_SET(\''.$group.'\', `groups_id`) > 0) AND `home_folder` <> \'\' AND `user_id` <> '.$wb->get_user_id(); |
|
346 |
if( ($res_hf = $database->query($sql)) != null ) |
|
347 |
{ |
|
348 |
while( $rec_hf = $res_hf->fetchrow() ) |
|
349 |
{ |
|
350 |
$allow_list[] = $rec_hf['home_folder']; |
|
351 |
} |
|
352 |
} |
|
353 |
} |
|
354 |
} |
|
355 |
$tmp_array = $full_list; |
|
356 |
// create a list for readonly dir |
|
357 |
$array = array(); |
|
358 |
while( sizeof($tmp_array) > 0) |
|
359 |
{ |
|
360 |
$tmp = array_shift($tmp_array); |
|
361 |
$x = 0; |
|
362 |
while($x < sizeof($allow_list)) |
|
363 |
{ |
|
364 |
if(strpos ($tmp,$allow_list[$x])) { |
|
365 |
$array[] = $tmp; |
|
366 |
} |
|
367 |
$x++; |
|
368 |
} |
|
369 |
} |
|
370 |
|
|
371 |
$full_list = array_diff( $full_list, $array ); |
|
372 |
$tmp = array(); |
|
373 |
$full_list = array_merge($tmp,$full_list); |
|
374 |
|
|
375 |
return $full_list; |
|
376 |
} |
|
377 |
|
|
378 |
/* |
|
379 |
* @param object &$wb: $wb from frontend or $admin from backend |
|
380 |
* @return array: list of rw-dirs |
|
381 |
* @description: returns a list of directories beyound /wb/media which are ReadWrite for current user |
|
382 |
*/ |
|
383 |
function media_dirs_rw ( &$wb ) |
|
384 |
{ |
|
385 |
global $database; |
|
386 |
// if user is admin or home-folders not activated then there are no restrictions |
|
387 |
// at first read any dir and subdir from /media |
|
388 |
$full_list = directory_list( WB_PATH.MEDIA_DIRECTORY ); |
|
389 |
$array = array(); |
|
390 |
$allow_list = array(); |
|
391 |
if( ($wb->ami_group_member('1')) && !HOME_FOLDERS ) |
|
392 |
{ |
|
393 |
return $full_list; |
|
394 |
} |
|
395 |
// add own home_folder to allow-list |
|
396 |
if( $wb->get_home_folder() ) |
|
397 |
{ |
|
398 |
$allow_list[] = $wb->get_home_folder(); |
|
399 |
} else { |
|
400 |
$array = $full_list; |
|
401 |
} |
|
402 |
// get groups of current user |
|
403 |
$curr_groups = $wb->get_groups_id(); |
|
404 |
// if current user is in admin-group |
|
405 |
if( ($admin_key = array_search('1', $curr_groups)) == true) |
|
406 |
{ |
|
407 |
// remove admin-group from list |
|
408 |
// unset($curr_groups[$admin_key]); |
|
409 |
// search for all users where the current user is admin from |
|
410 |
foreach( $curr_groups as $group) |
|
411 |
{ |
|
412 |
$sql = 'SELECT `home_folder` FROM `'.TABLE_PREFIX.'users` '; |
|
413 |
$sql .= 'WHERE (FIND_IN_SET(\''.$group.'\', `groups_id`) > 0) AND `home_folder` <> \'\' AND `user_id` <> '.$wb->get_user_id(); |
|
414 |
if( ($res_hf = $database->query($sql)) != null ) |
|
415 |
{ |
|
416 |
while( $rec_hf = $res_hf->fetchrow() ) |
|
417 |
{ |
|
418 |
$allow_list[] = $rec_hf['home_folder']; |
|
419 |
} |
|
420 |
} |
|
421 |
} |
|
422 |
} |
|
423 |
|
|
424 |
$tmp_array = $full_list; |
|
425 |
// create a list for readwrite dir |
|
426 |
while( sizeof($tmp_array) > 0) |
|
427 |
{ |
|
428 |
$tmp = array_shift($tmp_array); |
|
429 |
$x = 0; |
|
430 |
while($x < sizeof($allow_list)) |
|
431 |
{ |
|
432 |
if(strpos ($tmp,$allow_list[$x])) { |
|
433 |
$array[] = $tmp; |
|
434 |
} |
|
435 |
$x++; |
|
436 |
} |
|
437 |
} |
|
438 |
|
|
439 |
$tmp = array(); |
|
440 |
$array = array_unique($array); |
|
441 |
$full_list = array_merge($tmp,$array); |
|
442 |
unset($array); |
|
443 |
unset($allow_list); |
|
444 |
|
|
445 |
return $full_list; |
|
446 |
} |
|
447 |
|
|
206 | 448 |
// Function to create directories |
207 | 449 |
function make_dir($dir_name, $dir_mode = OCTAL_DIR_MODE) |
208 | 450 |
{ |
... | ... | |
617 | 859 |
function make_thumb($source, $destination, $size) |
618 | 860 |
{ |
619 | 861 |
// Check if GD is installed |
620 |
if(extension_loaded('gd') AND function_exists('imageCreateFromJpeg'))
|
|
862 |
if(extension_loaded('gd') && function_exists('imageCreateFromJpeg'))
|
|
621 | 863 |
{ |
622 | 864 |
// First figure out the size of the thumbnail |
623 | 865 |
list($original_x, $original_y) = getimagesize($source); |
... | ... | |
662 | 904 |
function extract_permission($octal_value, $who, $action) |
663 | 905 |
{ |
664 | 906 |
// Make sure that all arguments are set and $octal_value is a real octal-integer |
665 |
if( ($who == '') or ($action == '') or (preg_match( '/[^0-7]/', (string)$octal_value )) )
|
|
907 |
if( ($who == '') || ($action == '') || (preg_match( '/[^0-7]/', (string)$octal_value )) )
|
|
666 | 908 |
{ |
667 | 909 |
return false; // invalid argument, so return false |
668 | 910 |
} |
... | ... | |
709 | 951 |
} |
710 | 952 |
|
711 | 953 |
// Function to delete a page |
712 |
function delete_page($page_id) |
|
713 |
{ |
|
714 |
global $admin, $database, $MESSAGE; |
|
715 |
// Find out more about the page |
|
716 |
$database = new database(); |
|
717 |
$sql = 'SELECT `page_id`, `menu_title`, `page_title`, `level`, `link`, `parent`, `modified_by`, `modified_when` '; |
|
718 |
$sql .= 'FROM `'.TABLE_PREFIX.'pages` WHERE `page_id` = '.$page_id; |
|
719 |
$results = $database->query($sql); |
|
720 |
if($database->is_error()) { $admin->print_error($database->get_error()); } |
|
721 |
if($results->numRows() == 0) { $admin->print_error($MESSAGE['PAGES']['NOT_FOUND']); } |
|
722 |
$results_array = $results->fetchRow(); |
|
723 |
$parent = $results_array['parent']; |
|
724 |
$level = $results_array['level']; |
|
725 |
$link = $results_array['link']; |
|
726 |
$page_title = $results_array['page_title']; |
|
727 |
$menu_title = $results_array['menu_title']; |
|
728 |
|
|
729 |
// Get the sections that belong to the page |
|
730 |
$sql = 'SELECT `section_id`, `module` FROM `'.TABLE_PREFIX.'sections` WHERE `page_id` = '.$page_id; |
|
731 |
$query_sections = $database->query($sql); |
|
732 |
if($query_sections->numRows() > 0) |
|
954 |
function delete_page($page_id) |
|
733 | 955 |
{ |
734 |
while($section = $query_sections->fetchRow()) |
|
956 |
global $admin, $database, $MESSAGE; |
|
957 |
// Find out more about the page |
|
958 |
$sql = 'SELECT `page_id`, `menu_title`, `page_title`, `level`, `link`, `parent`, `modified_by`, `modified_when` '; |
|
959 |
$sql .= 'FROM `'.TABLE_PREFIX.'pages` WHERE `page_id` = '.$page_id; |
|
960 |
$results = $database->query($sql); |
|
961 |
if($database->is_error()) { $admin->print_error($database->get_error()); } |
|
962 |
if($results->numRows() == 0) { $admin->print_error($MESSAGE['PAGES']['NOT_FOUND']); } |
|
963 |
$results_array = $results->fetchRow(); |
|
964 |
$parent = $results_array['parent']; |
|
965 |
$level = $results_array['level']; |
|
966 |
$link = $results_array['link']; |
|
967 |
$page_title = $results_array['page_title']; |
|
968 |
$menu_title = $results_array['menu_title']; |
|
969 |
|
|
970 |
// Get the sections that belong to the page |
|
971 |
$sql = 'SELECT `section_id`, `module` FROM `'.TABLE_PREFIX.'sections` WHERE `page_id` = '.$page_id; |
|
972 |
$query_sections = $database->query($sql); |
|
973 |
if($query_sections->numRows() > 0) |
|
735 | 974 |
{ |
736 |
// Set section id |
|
737 |
$section_id = $section['section_id']; |
|
738 |
// Include the modules delete file if it exists |
|
739 |
if(file_exists(WB_PATH.'/modules/'.$section['module'].'/delete.php')) |
|
975 |
while($section = $query_sections->fetchRow()) |
|
740 | 976 |
{ |
741 |
include(WB_PATH.'/modules/'.$section['module'].'/delete.php'); |
|
977 |
// Set section id |
|
978 |
$section_id = $section['section_id']; |
|
979 |
// Include the modules delete file if it exists |
|
980 |
if(file_exists(WB_PATH.'/modules/'.$section['module'].'/delete.php')) |
|
981 |
{ |
|
982 |
include(WB_PATH.'/modules/'.$section['module'].'/delete.php'); |
|
983 |
} |
|
742 | 984 |
} |
743 | 985 |
} |
986 |
// Update the pages table |
|
987 |
$sql = 'DELETE FROM `'.TABLE_PREFIX.'pages` WHERE `page_id` = '.$page_id; |
|
988 |
$database->query($sql); |
|
989 |
if($database->is_error()) |
|
990 |
{ |
|
991 |
$admin->print_error($database->get_error()); |
|
992 |
} |
|
993 |
// Update the sections table |
|
994 |
$sql = 'DELETE FROM `'.TABLE_PREFIX.'sections` WHERE `page_id` = '.$page_id; |
|
995 |
$database->query($sql); |
|
996 |
if($database->is_error()) { |
|
997 |
$admin->print_error($database->get_error()); |
|
998 |
} |
|
999 |
// Include the ordering class or clean-up ordering |
|
1000 |
include_once(WB_PATH.'/framework/class.order.php'); |
|
1001 |
$order = new order(TABLE_PREFIX.'pages', 'position', 'page_id', 'parent'); |
|
1002 |
$order->clean($parent); |
|
1003 |
// Unlink the page access file and directory |
|
1004 |
$directory = WB_PATH.PAGES_DIRECTORY.$link; |
|
1005 |
$filename = $directory.PAGE_EXTENSION; |
|
1006 |
$directory .= '/'; |
|
1007 |
if(file_exists($filename)) |
|
1008 |
{ |
|
1009 |
if(!is_writable(WB_PATH.PAGES_DIRECTORY.'/')) |
|
1010 |
{ |
|
1011 |
$admin->print_error($MESSAGE['PAGES']['CANNOT_DELETE_ACCESS_FILE']); |
|
1012 |
} |
|
1013 |
else |
|
1014 |
{ |
|
1015 |
unlink($filename); |
|
1016 |
if( file_exists($directory) && |
|
1017 |
(rtrim($directory,'/') != WB_PATH.PAGES_DIRECTORY) && |
|
1018 |
(substr($link, 0, 1) != '.')) |
|
1019 |
{ |
|
1020 |
rm_full_dir($directory); |
|
1021 |
} |
|
1022 |
} |
|
1023 |
} |
|
744 | 1024 |
} |
745 |
// Update the pages table |
|
746 |
$sql = 'DELETE FROM `'.TABLE_PREFIX.'pages` WHERE `page_id` = '.$page_id; |
|
747 |
$database->query($sql); |
|
748 |
if($database->is_error()) |
|
1025 |
|
|
1026 |
/* |
|
1027 |
* @param string $file: name of the file to read |
|
1028 |
* @param int $size: number of maximum bytes to read (0 = complete file) |
|
1029 |
* @return string: the content as string, false on error |
|
1030 |
*/ |
|
1031 |
function getFilePart($file, $size = 0) |
|
749 | 1032 |
{ |
750 |
$admin->print_error($database->get_error()); |
|
751 |
} |
|
752 |
// Update the sections table |
|
753 |
$sql = 'DELETE FROM `'.TABLE_PREFIX.'sections` WHERE `page_id` = '.$page_id; |
|
754 |
$database->query($sql); |
|
755 |
if($database->is_error()) { |
|
756 |
$admin->print_error($database->get_error()); |
|
757 |
} |
|
758 |
// Include the ordering class or clean-up ordering |
|
759 |
include_once(WB_PATH.'/framework/class.order.php'); |
|
760 |
$order = new order(TABLE_PREFIX.'pages', 'position', 'page_id', 'parent'); |
|
761 |
$order->clean($parent); |
|
762 |
// Unlink the page access file and directory |
|
763 |
$directory = WB_PATH.PAGES_DIRECTORY.$link; |
|
764 |
$filename = $directory.PAGE_EXTENSION; |
|
765 |
$directory .= '/'; |
|
766 |
if(file_exists($filename)) |
|
767 |
{ |
|
768 |
if(!is_writable(WB_PATH.PAGES_DIRECTORY.'/')) |
|
1033 |
$file_content = ''; |
|
1034 |
if( file_exists($file) && is_file($file) && is_readable($file)) |
|
769 | 1035 |
{ |
770 |
$admin->print_error($MESSAGE['PAGES']['CANNOT_DELETE_ACCESS_FILE']); |
|
1036 |
if($size == 0) |
|
1037 |
{ |
|
1038 |
$size = filesize($file); |
|
1039 |
} |
|
1040 |
if(($fh = fopen($file, 'rb'))) |
|
1041 |
{ |
|
1042 |
if( ($file_content = fread($fh, $size)) !== false ) |
|
1043 |
{ |
|
1044 |
return $file_content; |
|
1045 |
} |
|
1046 |
fclose($fh); |
|
1047 |
} |
|
771 | 1048 |
} |
772 |
else |
|
1049 |
return false; |
|
1050 |
} |
|
1051 |
|
|
1052 |
/** |
|
1053 |
* replace varnames with values in a string |
|
1054 |
* |
|
1055 |
* @param string $subject: stringvariable with vars placeholder |
|
1056 |
* @param array $replace: values to replace vars placeholder |
|
1057 |
* @return string |
|
1058 |
*/ |
|
1059 |
function replace_vars($subject = '', &$replace = null ) |
|
1060 |
{ |
|
1061 |
if(is_array($replace)) |
|
773 | 1062 |
{ |
774 |
unlink($filename); |
|
775 |
if( file_exists($directory) && |
|
776 |
(rtrim($directory,'/') != WB_PATH.PAGES_DIRECTORY) && |
|
777 |
(substr($link, 0, 1) != '.')) |
|
1063 |
foreach ($replace as $key => $value) |
|
778 | 1064 |
{ |
779 |
rm_full_dir($directory);
|
|
1065 |
$subject = str_replace("{{".$key."}}", $value, $subject);
|
|
780 | 1066 |
} |
781 | 1067 |
} |
782 |
}
|
|
783 |
} |
|
1068 |
return $subject;
|
|
1069 |
}
|
|
784 | 1070 |
|
785 | 1071 |
// Load module into DB |
786 | 1072 |
function load_module($directory, $install = false) |
787 | 1073 |
{ |
788 | 1074 |
global $database,$admin,$MESSAGE; |
789 |
|
|
790 |
if(is_dir($directory) AND file_exists($directory.'/info.php'))
|
|
1075 |
$retVal = false; |
|
1076 |
if(is_dir($directory) && file_exists($directory.'/info.php'))
|
|
791 | 1077 |
{ |
792 | 1078 |
require($directory.'/info.php'); |
793 | 1079 |
if(isset($module_name)) |
794 | 1080 |
{ |
795 |
if(!isset($module_license)) { $module_license = 'GNU General Public License'; }
|
|
796 |
if(!isset($module_platform) AND isset($module_designed_for)) { $module_platform = $module_designed_for; }
|
|
797 |
if(!isset($module_function) AND isset($module_type)) { $module_function = $module_type; }
|
|
1081 |
if(!isset($module_license)) { $module_license = 'GNU General Public License'; } |
|
1082 |
if(!isset($module_platform) && isset($module_designed_for)) { $module_platform = $module_designed_for; }
|
|
1083 |
if(!isset($module_function) && isset($module_type)) { $module_function = $module_type; }
|
|
798 | 1084 |
$module_function = strtolower($module_function); |
799 | 1085 |
// Check that it doesn't already exist |
800 |
$sql = 'SELECT `addon_id` FROM `'.TABLE_PREFIX.'addons` '; |
|
801 |
$sql .= 'WHERE `type` = "module" AND `directory` = "'.$module_directory.'" LIMIT 0,1'; |
|
802 |
$result = $database->query($sql); |
|
803 |
if($result->numRows() == 0) |
|
1086 |
$sqlwhere = 'WHERE `type` = \'module\' AND `directory` = \''.$module_directory.'\''; |
|
1087 |
$sql = 'SELECT COUNT(*) FROM `'.TABLE_PREFIX.'addons` '.$sqlwhere; |
|
1088 |
if( $database->get_one($sql) ) |
|
804 | 1089 |
{ |
1090 |
$sql = 'UPDATE `'.TABLE_PREFIX.'addons` SET '; |
|
1091 |
}else{ |
|
805 | 1092 |
// Load into DB |
806 | 1093 |
$sql = 'INSERT INTO `'.TABLE_PREFIX.'addons` SET '; |
807 |
$sql .= '`directory` = "'.$module_directory.'", '; |
|
808 |
$sql .= '`name` = "'.$module_name.'", '; |
|
809 |
$sql .= '`description`= "'.addslashes($module_description).'", '; |
|
810 |
$sql .= '`type`= "module", '; |
|
811 |
$sql .= '`function` = "'.$module_function.'", '; |
|
812 |
$sql .= '`version` = "'.$module_version.'", '; |
|
813 |
$sql .= '`platform` = "'.$module_platform.'", '; |
|
814 |
$sql .= '`author` = "'.addslashes($module_author).'", '; |
|
815 |
$sql .= '`license` = "'.addslashes($module_license).'"'; |
|
816 |
$database->query($sql); |
|
817 |
// Run installation script |
|
818 |
if($install == true) |
|
1094 |
$sqlwhere = ''; |
|
1095 |
} |
|
1096 |
$sql .= '`directory` = \''.$module_directory.'\', '; |
|
1097 |
$sql .= '`name` = \''.$module_name.'\', '; |
|
1098 |
$sql .= '`description`= \''.addslashes($module_description).'\', '; |
|
1099 |
$sql .= '`type`= \'module\', '; |
|
1100 |
$sql .= '`function` = \''.$module_function.'\', '; |
|
1101 |
$sql .= '`version` = \''.$module_version.'\', '; |
|
1102 |
$sql .= '`platform` = \''.$module_platform.'\', '; |
|
1103 |
$sql .= '`author` = \''.addslashes($module_author).'\', '; |
|
1104 |
$sql .= '`license` = \''.addslashes($module_license).'\''; |
|
1105 |
$sql .= $sqlwhere; |
|
1106 |
$retVal = $database->query($sql); |
|
1107 |
// Run installation script |
|
1108 |
if($install == true) |
|
1109 |
{ |
|
1110 |
if(file_exists($directory.'/install.php')) |
|
819 | 1111 |
{ |
820 |
if(file_exists($directory.'/install.php')) |
|
821 |
{ |
|
822 |
require($directory.'/install.php'); |
|
823 |
} |
|
1112 |
require($directory.'/install.php'); |
|
824 | 1113 |
} |
825 | 1114 |
} |
826 | 1115 |
} |
... | ... | |
831 | 1120 |
function load_template($directory) |
832 | 1121 |
{ |
833 | 1122 |
global $database, $admin; |
834 |
if(is_dir($directory) AND file_exists($directory.'/info.php')) |
|
1123 |
$retVal = false; |
|
1124 |
if(is_dir($directory) && file_exists($directory.'/info.php')) |
|
835 | 1125 |
{ |
836 | 1126 |
require($directory.'/info.php'); |
837 | 1127 |
if(isset($template_name)) |
... | ... | |
840 | 1130 |
{ |
841 | 1131 |
$template_license = 'GNU General Public License'; |
842 | 1132 |
} |
843 |
if(!isset($template_platform) AND isset($template_designed_for))
|
|
1133 |
if(!isset($template_platform) && isset($template_designed_for))
|
|
844 | 1134 |
{ |
845 | 1135 |
$template_platform = $template_designed_for; |
846 | 1136 |
} |
... | ... | |
849 | 1139 |
$template_function = 'template'; |
850 | 1140 |
} |
851 | 1141 |
// Check that it doesn't already exist |
852 |
$sql = 'SELECT `addon_id` FROM `'.TABLE_PREFIX.'addons` '; |
|
853 |
$sql .= 'WHERE `type` = "template" AND `directory` = "'.$template_directory.'" LIMIT 0,1'; |
|
854 |
$result = $database->query($sql); |
|
855 |
if($result->numRows() == 0) |
|
1142 |
$sqlwhere = 'WHERE `type` = \'template\' AND `directory` = \''.$template_directory.'\''; |
|
1143 |
$sql = 'SELECT COUNT(*) FROM `'.TABLE_PREFIX.'addons` '.$sqlwhere; |
|
1144 |
if( $database->get_one($sql) ) |
|
856 | 1145 |
{ |
1146 |
$sql = 'UPDATE `'.TABLE_PREFIX.'addons` SET '; |
|
1147 |
}else{ |
|
857 | 1148 |
// Load into DB |
858 | 1149 |
$sql = 'INSERT INTO `'.TABLE_PREFIX.'addons` SET '; |
859 |
$sql .= '`directory` = "'.$template_directory.'", '; |
|
860 |
$sql .= '`name` = "'.$template_name.'", '; |
|
861 |
$sql .= '`description`= "'.addslashes($template_description).'", '; |
|
862 |
$sql .= '`type`= "template", '; |
|
863 |
$sql .= '`function` = "'.$template_function.'", '; |
|
864 |
$sql .= '`version` = "'.$template_version.'", '; |
|
865 |
$sql .= '`platform` = "'.$template_platform.'", '; |
|
866 |
$sql .= '`author` = "'.addslashes($template_author).'", '; |
|
867 |
$sql .= '`license` = "'.addslashes($template_license).'" '; |
|
868 |
$database->query($sql); |
|
1150 |
$sqlwhere = ''; |
|
869 | 1151 |
} |
1152 |
$sql .= '`directory` = \''.$template_directory.'\', '; |
|
1153 |
$sql .= '`name` = \''.$template_name.'\', '; |
|
1154 |
$sql .= '`description`= \''.addslashes($template_description).'\', '; |
|
1155 |
$sql .= '`type`= \'template\', '; |
|
1156 |
$sql .= '`function` = \''.$template_function.'\', '; |
|
1157 |
$sql .= '`version` = \''.$template_version.'\', '; |
|
1158 |
$sql .= '`platform` = \''.$template_platform.'\', '; |
|
1159 |
$sql .= '`author` = \''.addslashes($template_author).'\', '; |
|
1160 |
$sql .= '`license` = \''.addslashes($template_license).'\' '; |
|
1161 |
$sql .= $sqlwhere; |
|
1162 |
$retVal = $database->query($sql); |
|
870 | 1163 |
} |
871 | 1164 |
} |
1165 |
return $retVal; |
|
872 | 1166 |
} |
873 | 1167 |
|
874 | 1168 |
// Load language into DB |
875 | 1169 |
function load_language($file) |
876 | 1170 |
{ |
877 | 1171 |
global $database,$admin; |
1172 |
$retVal = false; |
|
878 | 1173 |
if (file_exists($file) && preg_match('#^([A-Z]{2}.php)#', basename($file))) |
879 | 1174 |
{ |
880 |
require($file); |
|
1175 |
// require($file); it's to large |
|
1176 |
// read contents of the template language file into string |
|
1177 |
$data = @file_get_contents(WB_PATH.'/languages/'.str_replace('.php','',basename($file)).'.php'); |
|
1178 |
// use regular expressions to fetch the content of the variable from the string |
|
1179 |
$language_name = get_variable_content('language_name', $data, false); |
|
1180 |
$language_code = get_variable_content('language_code', $data, false); |
|
1181 |
$language_author = get_variable_content('language_author', $data); |
|
1182 |
$language_version = get_variable_content('language_version', $data, false); |
|
1183 |
$language_platform = get_variable_content('language_platform', $data, false); |
|
1184 |
|
|
881 | 1185 |
if(isset($language_name)) |
882 | 1186 |
{ |
883 |
if(!isset($language_license)) { $language_license = 'GNU General Public License'; }
|
|
884 |
if(!isset($language_platform) AND isset($language_designed_for)) { $language_platform = $language_designed_for; }
|
|
1187 |
if(!isset($language_license)) { $language_license = 'GNU General Public License'; } |
|
1188 |
if(!isset($language_platform) && isset($language_designed_for)) { $language_platform = $language_designed_for; }
|
|
885 | 1189 |
// Check that it doesn't already exist |
886 |
$sql = 'SELECT `addon_id` FROM `'.TABLE_PREFIX.'addons` '; |
|
887 |
$sql .= 'WHERE `type` = "language" AND `directory` = "'.$language_code.'" LIMIT 0,1'; |
|
888 |
$result = $database->query($sql); |
|
889 |
if($result->numRows() == 0) |
|
1190 |
$sqlwhere = 'WHERE `type` = \'language\' AND `directory` = \''.$language_code.'\''; |
|
1191 |
$sql = 'SELECT COUNT(*) FROM `'.TABLE_PREFIX.'addons` '.$sqlwhere; |
|
1192 |
if( $database->get_one($sql) ) |
|
890 | 1193 |
{ |
1194 |
$sql = 'UPDATE `'.TABLE_PREFIX.'addons` SET '; |
|
1195 |
}else{ |
|
891 | 1196 |
// Load into DB |
892 | 1197 |
$sql = 'INSERT INTO `'.TABLE_PREFIX.'addons` SET '; |
893 |
$sql .= '`directory` = "'.$language_code.'", '; |
|
894 |
$sql .= '`name` = "'.$language_name.'", '; |
|
895 |
$sql .= '`type`= "language", '; |
|
896 |
$sql .= '`version` = "'.$language_version.'", '; |
|
897 |
$sql .= '`platform` = "'.$language_platform.'", '; |
|
898 |
$sql .= '`author` = "'.addslashes($language_author).'", '; |
|
899 |
$sql .= '`license` = "'.addslashes($language_license).'"'; |
|
900 |
$database->query($sql); |
|
1198 |
$sqlwhere = ''; |
|
901 | 1199 |
} |
1200 |
$sql .= '`directory` = \''.$language_code.'\', '; |
|
1201 |
$sql .= '`name` = \''.$language_name.'\', '; |
|
1202 |
$sql .= '`type`= \'language\', '; |
|
1203 |
$sql .= '`version` = \''.$language_version.'\', '; |
|
1204 |
$sql .= '`platform` = \''.$language_platform.'\', '; |
|
1205 |
$sql .= '`author` = \''.addslashes($language_author).'\', '; |
|
1206 |
$sql .= '`license` = \''.addslashes($language_license).'\' '; |
|
1207 |
$sql .= $sqlwhere; |
|
1208 |
$retVal = $database->query($sql); |
|
902 | 1209 |
} |
903 | 1210 |
} |
1211 |
return $retVal; |
|
904 | 1212 |
} |
905 | 1213 |
|
906 | 1214 |
// Upgrade module info in DB, optionally start upgrade script |
... | ... | |
913 | 1221 |
require($mod_directory.'/info.php'); |
914 | 1222 |
if(isset($module_name)) |
915 | 1223 |
{ |
916 |
if(!isset($module_license)) { $module_license = 'GNU General Public License'; }
|
|
1224 |
if(!isset($module_license)) { $module_license = 'GNU General Public License'; } |
|
917 | 1225 |
if(!isset($module_platform) && isset($module_designed_for)) { $module_platform = $module_designed_for; } |
918 |
if(!isset($module_function) && isset($module_type)) { $module_function = $module_type; }
|
|
1226 |
if(!isset($module_function) && isset($module_type)) { $module_function = $module_type; } |
|
919 | 1227 |
$module_function = strtolower($module_function); |
920 | 1228 |
// Check that it does already exist |
921 |
// Check that it does already exist |
|
922 | 1229 |
$sql = 'SELECT COUNT(*) FROM `'.TABLE_PREFIX.'addons` '; |
923 | 1230 |
$sql .= 'WHERE `directory` = \''.$module_directory.'\''; |
924 |
|
|
925 | 1231 |
if( $database->get_one($sql) ) |
926 | 1232 |
{ |
927 | 1233 |
// Update in DB |
928 | 1234 |
$sql = 'UPDATE `'.TABLE_PREFIX.'addons` SET '; |
929 |
$sql .= '`version` = \''.$module_version.'\', ';
|
|
930 |
$sql .= '`description` = \''.addslashes($module_description).'\', ';
|
|
1235 |
$sql .= '`version` = "'.$module_version.'", ';
|
|
1236 |
$sql .= '`description` = "'.addslashes($module_description).'", ';
|
|
931 | 1237 |
$sql .= '`platform` = \''.$module_platform.'\', '; |
932 | 1238 |
$sql .= '`author` = \''.addslashes($module_author).'\', '; |
933 | 1239 |
$sql .= '`license` = \''.addslashes($module_license).'\' '; |
... | ... | |
973 | 1279 |
} |
974 | 1280 |
} |
975 | 1281 |
|
976 |
?> |
|
1282 |
/* |
|
1283 |
* @param string $modulname: like saved in addons.directory |
|
1284 |
* @param boolean $source: true reads from database, false from info.php |
|
1285 |
* @return string: the version as string, if not found returns null |
|
1286 |
*/ |
|
1287 |
|
|
1288 |
function get_modul_version($modulname, $source = true) |
|
1289 |
{ |
|
1290 |
global $database; |
|
1291 |
$version = null; |
|
1292 |
if( $source != true ) |
|
1293 |
{ |
|
1294 |
$sql = 'SELECT `version` FROM `'.TABLE_PREFIX.'addons` WHERE `directory`=\''.$modulname.'\''; |
|
1295 |
$version = $database->get_one($sql); |
|
1296 |
} else { |
|
1297 |
$info_file = WB_PATH.'/modules/'.$modulname.'/info.php'; |
|
1298 |
if(file_exists($info_file)) |
|
1299 |
{ |
|
1300 |
if(($info_file = file_get_contents($info_file))) |
|
1301 |
{ |
|
1302 |
$version = get_variable_content('module_version', $info_file, false, false); |
|
1303 |
$version = ($version !== false) ? $version : null; |
|
1304 |
} |
|
1305 |
} |
|
1306 |
} |
|
1307 |
return $version; |
|
1308 |
} |
|
1309 |
|
|
1310 |
/* |
|
1311 |
* @param string $varlist: commaseperated list of varnames to move into global space |
|
1312 |
* @return bool: false if one of the vars already exists in global space (error added to msgQueue) |
|
1313 |
*/ |
|
1314 |
function vars2globals_wrapper($varlist) |
|
1315 |
{ |
|
1316 |
$retval = true; |
|
1317 |
if( $varlist != '') |
|
1318 |
{ |
|
1319 |
$vars = explode(',', $varlist); |
|
1320 |
foreach( $vars as $var) |
|
1321 |
{ |
|
1322 |
if( isset($GLOBALS[$var]) ) |
|
1323 |
{ |
|
1324 |
ErrorLog::write( 'variabe $'.$var.' already defined in global space!!',__FILE__, __FUNCTION__, __LINE__); |
|
1325 |
$retval = false; |
|
1326 |
}else |
|
1327 |
{ |
|
1328 |
global $$var; |
|
1329 |
} |
|
1330 |
} |
|
1331 |
} |
|
1332 |
return $retval; |
|
1333 |
} |
|
1334 |
|
|
1335 |
|
Also available in: Unified diff
added some functions
set status to 2.8.2 RC3