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