Project

General

Profile

1 1352 Luisehahne
<?php
2
/**
3
 *
4
 * @category        frontend
5
 * @package         framework
6 1705 Luisehahne
 * @author          Ryan Djurovich,WebsiteBaker Project
7 1908 Luisehahne
 * @copyright       2009-2013, WebsiteBaker Org. e.V.
8
 * @link            http://www.websitebaker.org/
9 1352 Luisehahne
 * @license         http://www.gnu.org/licenses/gpl.html
10 1908 Luisehahne
 * @platform        WebsiteBaker 2.8.4
11 1374 Luisehahne
 * @requirements    PHP 5.2.2 and higher
12 1352 Luisehahne
 * @version         $Id$
13 1841 Luisehahne
 * @filesource      $HeadURL$
14 1352 Luisehahne
 * @lastmodified    $Date$
15
 *
16 1866 Luisehahne
 */
17 1496 DarkViper
/* -------------------------------------------------------- */
18
// Must include code to stop this file being accessed directly
19 1499 DarkViper
if(!defined('WB_PATH')) {
20
	require_once(dirname(__FILE__).'/globalExceptionHandler.php');
21
	throw new IllegalFileException();
22
}
23 1496 DarkViper
/* -------------------------------------------------------- */
24 1352 Luisehahne
// Define that this file has been loaded
25
define('FUNCTIONS_FILE_LOADED', true);
26
27 1977 Luisehahne
28 1365 Luisehahne
/**
29 1977 Luisehahne
 * Delete an Accessfiles Tree
30 1978 Luisehahne
 * @param  string  $sDirToDelete
31
 * @param  array   &$aReport  returns report if set
32 1977 Luisehahne
 * @return boolean true/false
33
 * @description    Delete all accessfiles and its depending directory tree
34
 *                 inside the given directory.
35
 */
36 1978 Luisehahne
function DeleteAccessFilesTree($sDirToDelete, array &$aReport = null)
37 1977 Luisehahne
{
38 1978 Luisehahne
		$aReport = array();
39 1977 Luisehahne
        $sBaseDir = realpath($sDirToDelete);
40
        if( $sBaseDir !== false) {
41
		$sBaseDir = rtrim(str_replace('\\', '/', $sBaseDir), '/') . '/';
42
		// scan start directory for access files
43
		foreach (glob($sBaseDir . '*.php', GLOB_MARK) as $sItem) {
44
            $sItem = str_replace('\\', '/', $sItem);
45
			try{
46
				$oAccFile = new AccessFile($sItem);
47
				$oAccFile->delete();
48 1978 Luisehahne
				$aReport = array_merge($aReport, AccessFileHelper::getDelTreeLog());
49 1977 Luisehahne
			}catch(AccessFileIsNoAccessfileException $e) {
50
				continue;
51
			}
52
		}
53
		return true;
54
	}
55
	return false;
56
}
57
58
/**
59 1365 Luisehahne
 * @description: recursively delete a non empty directory
60
 * @param string $directory :
61
 * @param bool $empty : true if you want the folder just emptied, but not deleted
62
 *                      false, or just simply leave it out, the given directory will be deleted, as well
63 1977 Luisehahne
 * @param array $aProtectedFiles optional list of protected files, full path needed
64 1676 Luisehahne
 * @return boolean: true/false
65 1365 Luisehahne
 * @from http://www.php.net/manual/de/function.rmdir.php#98499
66
 */
67 1977 Luisehahne
function rm_full_dir($directory, $empty = false, $aProtectedFiles = null)
68 1676 Luisehahne
{
69 1977 Luisehahne
	$directory = rtrim(str_replace('\\','/',$directory),'/');
70
	if($aProtectedFiles == null) {
71
		$aProtectedFiles = array();
72
	}
73 1765 Luisehahne
    $iErrorReporting = error_reporting(0);
74 1977 Luisehahne
75 1676 Luisehahne
    if (is_file( $directory )&& is_writable( $directory )) {
76 1977 Luisehahne
		if(!in_array(($directory), $aProtectedFiles)) {
77
			$retval = unlink($directory);
78
			clearstatcache();
79
			error_reporting($iErrorReporting);
80
			return $retval;
81
		}else {
82
			return true;
83
		}
84 1352 Luisehahne
    }
85 1676 Luisehahne
    if(!is_writable($directory) || !is_dir($directory)) {
86 1765 Luisehahne
        error_reporting($iErrorReporting);
87 1365 Luisehahne
        return false;
88 1495 DarkViper
    } elseif(!is_readable($directory)) {
89 1765 Luisehahne
        error_reporting($iErrorReporting);
90 1365 Luisehahne
        return false;
91
    } else {
92
        $directoryHandle = opendir($directory);
93
        while ($contents = readdir($directoryHandle))
94
		{
95
            if($contents != '.' && $contents != '..')
96 1352 Luisehahne
			{
97 1365 Luisehahne
                $path = $directory . "/" . $contents;
98 1495 DarkViper
                if(is_dir($path)) {
99 1977 Luisehahne
                    rm_full_dir($path, false, $aProtectedFiles);
100 1365 Luisehahne
                } else {
101 1977 Luisehahne
					if(!in_array($path, $aProtectedFiles)) {
102
				        unlink($path);
103
						clearstatcache();
104
					}
105 1365 Luisehahne
                }
106 1352 Luisehahne
            }
107 1365 Luisehahne
        }
108
        closedir($directoryHandle);
109 1495 DarkViper
        if($empty == false) {
110 1676 Luisehahne
            if(is_dir($directory) && is_writable(dirname($directory))) {
111 1765 Luisehahne
                $retval = rmdir($directory);
112
                error_reporting($iErrorReporting);
113
                return $retval;
114 1676 Luisehahne
            } else {
115 1765 Luisehahne
                error_reporting($iErrorReporting);
116 1676 Luisehahne
				return false;
117 1352 Luisehahne
            }
118
        }
119 1765 Luisehahne
        error_reporting($iErrorReporting);
120 1365 Luisehahne
        return true;
121
    }
122 1352 Luisehahne
}
123
124
/*
125
 * returns a recursive list of all subdirectories from a given directory
126
 * @access  public
127
 * @param   string  $directory: from this dir the recursion will start
128
 * @param   bool    $show_hidden:  if set to TRUE also hidden dirs (.dir) will be shown
129
 * @return  array
130
 * example:
131
 *  /srv/www/httpdocs/wb/media/a/b/c/
132
 *  /srv/www/httpdocs/wb/media/a/b/d/
133
 * directory_list('/srv/www/httpdocs/wb/media/') will return:
134
 *  /a
135
 *  /a/b
136
 *  /a/b/c
137
 *  /a/b/d
138
 */
139
 function directory_list($directory, $show_hidden = false)
140
{
141
	$result_list = array();
142
	if (is_dir($directory))
143
    {
144
    	$dir = dir($directory); // Open the directory
145
    	while (false !== $entry = $dir->read()) // loop through the directory
146
		{
147
			if($entry == '.' || $entry == '..') { continue; } // Skip pointers
148
			if($entry[0] == '.' && $show_hidden == false) { continue; } // Skip hidden files
149 1495 DarkViper
    		if (is_dir("$directory/$entry")) { // Add dir and contents to list
150 1352 Luisehahne
    			$result_list = array_merge($result_list, directory_list("$directory/$entry"));
151
    			$result_list[] = "$directory/$entry";
152
    		}
153
    	}
154
        $dir->close();
155
    }
156 1365 Luisehahne
	// sorting
157 1495 DarkViper
	if(natcasesort($result_list)) {
158 1365 Luisehahne
		// new indexing
159
		$result_list = array_merge($result_list);
160
	}
161 1352 Luisehahne
	return $result_list; // Now return the list
162
}
163
164
// Function to open a directory and add to a dir list
165
function chmod_directory_contents($directory, $file_mode)
166
{
167
	if (is_dir($directory))
168
    {
169
    	// Set the umask to 0
170
    	$umask = umask(0);
171
    	// Open the directory then loop through its contents
172
    	$dir = dir($directory);
173
    	while (false !== $entry = $dir->read())
174
		{
175
    		// Skip pointers
176
    		if($entry[0] == '.') { continue; }
177
    		// Chmod the sub-dirs contents
178 1495 DarkViper
    		if(is_dir("$directory/$entry")) {
179 1352 Luisehahne
    			chmod_directory_contents($directory.'/'.$entry, $file_mode);
180
    		}
181
    		change_mode($directory.'/'.$entry);
182
    	}
183
        $dir->close();
184
    	// Restore the umask
185
    	umask($umask);
186
    }
187
}
188
189 1365 Luisehahne
/**
190
* Scan a given directory for dirs and files.
191
*
192
* usage: scan_current_dir ($root = '' )
193
*
194
* @param     $root   set a absolute rootpath as string. if root is empty the current path will be scan
195
* @param     $search set a search pattern for files, empty search brings all files
196
* @access    public
197
* @return    array    returns a natsort array with keys 'path' and 'filename'
198
*
199
*/
200
if(!function_exists('scan_current_dir'))
201
{
202
	function scan_current_dir($root = '', $search = '/.*/')
203
	{
204
	    $FILE = array();
205
		$array = array();
206
	    clearstatcache();
207
	    $root = empty ($root) ? getcwd() : $root;
208
	    if (($handle = opendir($root)))
209
	    {
210
	    // Loop through the files and dirs an add to list  DIRECTORY_SEPARATOR
211
	        while (false !== ($file = readdir($handle)))
212
	        {
213
	            if (substr($file, 0, 1) != '.' && $file != 'index.php')
214
	            {
215 1495 DarkViper
	                if (is_dir($root.'/'.$file)) {
216 1365 Luisehahne
	                    $FILE['path'][] = $file;
217 1495 DarkViper
	                } elseif (preg_match($search, $file, $array) ) {
218 1365 Luisehahne
	                    $FILE['filename'][] = $array[0];
219
	                }
220
	            }
221
	        }
222
	        $close_verz = closedir($handle);
223
	    }
224
		// sorting
225 1495 DarkViper
	    if (isset ($FILE['path']) && natcasesort($FILE['path'])) {
226 1365 Luisehahne
			// new indexing
227
	        $FILE['path'] = array_merge($FILE['path']);
228
	    }
229
		// sorting
230 1495 DarkViper
	    if (isset ($FILE['filename']) && natcasesort($FILE['filename'])) {
231 1365 Luisehahne
			// new indexing
232
	        $FILE['filename'] = array_merge($FILE['filename']);
233
	    }
234
	    return $FILE;
235
	}
236
}
237
238 1352 Luisehahne
// Function to open a directory and add to a file list
239
function file_list($directory, $skip = array(), $show_hidden = false)
240
{
241
	$result_list = array();
242
	if (is_dir($directory))
243
    {
244
    	$dir = dir($directory); // Open the directory
245
		while (false !== ($entry = $dir->read())) // loop through the directory
246
		{
247
			if($entry == '.' || $entry == '..') { continue; } // Skip pointers
248
			if($entry[0] == '.' && $show_hidden == false) { continue; } // Skip hidden files
249
			if( sizeof($skip) > 0 && in_array($entry, $skip) ) { continue; } // Check if we to skip anything else
250 1495 DarkViper
			if(is_file( $directory.'/'.$entry)) { // Add files to list
251 1352 Luisehahne
				$result_list[] = $directory.'/'.$entry;
252
			}
253
		}
254
		$dir->close(); // Now close the folder object
255
	}
256 1365 Luisehahne
257
    // make the list nice. Not all OS do this itself
258 1495 DarkViper
	if(natcasesort($result_list)) {
259 1365 Luisehahne
		$result_list = array_merge($result_list);
260 1495 DarkViper
	}
261 1352 Luisehahne
	return $result_list;
262
}
263
264 1824 Luisehahne
function remove_home_subs($directory = '/', $home_folders = '')
265
{
266
	if( ($handle = opendir(WB_PATH.MEDIA_DIRECTORY.$directory)) )
267
	{
268
		// Loop through the dirs to check the home folders sub-dirs are not shown
269
		while(false !== ($file = readdir($handle)))
270
		{
271
			if($file[0] != '.' && $file != 'index.php')
272
			{
273
				if(is_dir(WB_PATH.MEDIA_DIRECTORY.$directory.'/'.$file))
274
				{
275
					if($directory != '/') {
276
						$file = $directory.'/'.$file;
277
					}else {
278
						$file = '/'.$file;
279
					}
280
					foreach($home_folders AS $hf)
281
					{
282
						$hf_length = strlen($hf);
283
						if($hf_length > 0) {
284
							if(substr($file, 0, $hf_length+1) == $hf) {
285
								$home_folders[$file] = $file;
286
							}
287
						}
288
					}
289
					$home_folders = remove_home_subs($file, $home_folders);
290
				}
291
			}
292
		}
293
	}
294
	return $home_folders;
295
}
296
297 1352 Luisehahne
// Function to get a list of home folders not to show
298
function get_home_folders()
299
{
300
	global $database, $admin;
301
	$home_folders = array();
302
	// Only return home folders is this feature is enabled
303
	// and user is not admin
304
//	if(HOME_FOLDERS AND ($_SESSION['GROUP_ID']!='1')) {
305
	if(HOME_FOLDERS AND (!in_array('1',explode(',', $_SESSION['GROUPS_ID']))))
306
	{
307 1495 DarkViper
		$sql  = 'SELECT `home_folder` FROM `'.TABLE_PREFIX.'users` ';
308
		$sql .= 'WHERE `home_folder`!=\''.$admin->get_home_folder().'\'';
309 1352 Luisehahne
		$query_home_folders = $database->query($sql);
310
		if($query_home_folders->numRows() > 0)
311
		{
312 1495 DarkViper
			while($folder = $query_home_folders->fetchRow()) {
313 1352 Luisehahne
				$home_folders[$folder['home_folder']] = $folder['home_folder'];
314
			}
315
		}
316
		$home_folders = remove_home_subs('/', $home_folders);
317
	}
318
	return $home_folders;
319
}
320
321 1365 Luisehahne
/*
322
 * @param object &$wb: $wb from frontend or $admin from backend
323
 * @return array: list of new entries
324
 * @description: callback remove path in files/dirs stored in array
325
 * @example: array_walk($array,'remove_path',PATH);
326
 */
327
//
328
function remove_path(&$path, $key, $vars = '')
329
{
330
	$path = str_replace($vars, '', $path);
331
}
332
/*
333
 * @param object &$wb: $wb from frontend or $admin from backend
334
 * @return array: list of ro-dirs
335
 * @description: returns a list of directories beyound /wb/media which are ReadOnly for current user
336
 */
337
function media_dirs_ro( &$wb )
338
{
339
	global $database;
340
	// if user is admin or home-folders not activated then there are no restrictions
341
	$allow_list = array();
342 1495 DarkViper
	if( $wb->get_user_id() == 1 || !HOME_FOLDERS ) {
343 1365 Luisehahne
		return array();
344
	}
345
	// at first read any dir and subdir from /media
346
	$full_list = directory_list( WB_PATH.MEDIA_DIRECTORY );
347
	// add own home_folder to allow-list
348 1495 DarkViper
	if( $wb->get_home_folder() ) {
349 1365 Luisehahne
		// old: $allow_list[] = get_home_folder();
350
		$allow_list[] = $wb->get_home_folder();
351
	}
352
	// get groups of current user
353
	$curr_groups = $wb->get_groups_id();
354
	// if current user is in admin-group
355 1495 DarkViper
	if( ($admin_key = array_search('1', $curr_groups)) !== false)
356 1365 Luisehahne
	{
357
		// remove admin-group from list
358
		unset($curr_groups[$admin_key]);
359
		// search for all users where the current user is admin from
360
		foreach( $curr_groups as $group)
361
		{
362
			$sql  = 'SELECT `home_folder` FROM `'.TABLE_PREFIX.'users` ';
363
			$sql .= 'WHERE (FIND_IN_SET(\''.$group.'\', `groups_id`) > 0) AND `home_folder` <> \'\' AND `user_id` <> '.$wb->get_user_id();
364 1495 DarkViper
			if( ($res_hf = $database->query($sql)) != null ) {
365
				while( $rec_hf = $res_hf->fetchrow() ) {
366 1365 Luisehahne
					$allow_list[] = $rec_hf['home_folder'];
367
				}
368
			}
369
		}
370
	}
371
	$tmp_array = $full_list;
372
	// create a list for readonly dir
373
    $array = array();
374
	while( sizeof($tmp_array) > 0)
375
	{
376
        $tmp = array_shift($tmp_array);
377
        $x = 0;
378 1495 DarkViper
		while($x < sizeof($allow_list)) {
379 1365 Luisehahne
			if(strpos ($tmp,$allow_list[$x])) {
380
				$array[] = $tmp;
381
			}
382
			$x++;
383
		}
384
	}
385
	$full_list = array_diff( $full_list, $array );
386
	$tmp = array();
387
	$full_list = array_merge($tmp,$full_list);
388
	return $full_list;
389
}
390
391
/*
392
 * @param object &$wb: $wb from frontend or $admin from backend
393
 * @return array: list of rw-dirs
394
 * @description: returns a list of directories beyound /wb/media which are ReadWrite for current user
395
 */
396
function media_dirs_rw ( &$wb )
397
{
398
	global $database;
399
	// if user is admin or home-folders not activated then there are no restrictions
400
	// at first read any dir and subdir from /media
401
	$full_list = directory_list( WB_PATH.MEDIA_DIRECTORY );
402
    $array = array();
403
	$allow_list = array();
404 1495 DarkViper
	if( ($wb->ami_group_member('1')) && !HOME_FOLDERS ) {
405 1365 Luisehahne
		return $full_list;
406
	}
407
	// add own home_folder to allow-list
408 1495 DarkViper
	if( $wb->get_home_folder() ) {
409 1365 Luisehahne
	  	$allow_list[] = $wb->get_home_folder();
410
	} else {
411
		$array = $full_list;
412
	}
413
	// get groups of current user
414
	$curr_groups = $wb->get_groups_id();
415
	// if current user is in admin-group
416
	if( ($admin_key = array_search('1', $curr_groups)) == true)
417
	{
418
		// remove admin-group from list
419
		// unset($curr_groups[$admin_key]);
420
		// search for all users where the current user is admin from
421
		foreach( $curr_groups as $group)
422
		{
423
			$sql  = 'SELECT `home_folder` FROM `'.TABLE_PREFIX.'users` ';
424
			$sql .= 'WHERE (FIND_IN_SET(\''.$group.'\', `groups_id`) > 0) AND `home_folder` <> \'\' AND `user_id` <> '.$wb->get_user_id();
425 1495 DarkViper
			if( ($res_hf = $database->query($sql)) != null ) {
426
				while( $rec_hf = $res_hf->fetchrow() ) {
427 1365 Luisehahne
					$allow_list[] = $rec_hf['home_folder'];
428
				}
429
			}
430
		}
431
	}
432
433
	$tmp_array = $full_list;
434
	// create a list for readwrite dir
435
	while( sizeof($tmp_array) > 0)
436
	{
437
        $tmp = array_shift($tmp_array);
438
        $x = 0;
439 1495 DarkViper
		while($x < sizeof($allow_list)) {
440 1365 Luisehahne
			if(strpos ($tmp,$allow_list[$x])) {
441
				$array[] = $tmp;
442
			}
443
			$x++;
444
		}
445
	}
446
	$tmp = array();
447
    $array = array_unique($array);
448
	$full_list = array_merge($tmp,$array);
449
    unset($array);
450
    unset($allow_list);
451
	return $full_list;
452
}
453
454 1352 Luisehahne
// Function to create directories
455 1556 Luisehahne
function make_dir($dir_name, $dir_mode = OCTAL_DIR_MODE, $recursive=true)
456 1352 Luisehahne
{
457 1866 Luisehahne
	$bRetval = is_dir($dir_name);
458
	if(!$bRetval)
459 1352 Luisehahne
    {
460 1759 Luisehahne
		// To create the folder with 0777 permissions, we need to set umask to zero.
461
		$oldumask = umask(0) ;
462 1866 Luisehahne
		$bRetval = mkdir($dir_name, $dir_mode|0711, $recursive);
463 1759 Luisehahne
		umask( $oldumask ) ;
464 1352 Luisehahne
	}
465 1866 Luisehahne
	return $bRetval;
466 1352 Luisehahne
}
467
468 1651 darkviper
/**
469
 * Function to chmod files and/or directories
470 1653 darkviper
 * the function also prevents the owner to loose rw-rights
471 1651 darkviper
 * @param string $sName
472
 * @param int rights in dec-value. 0= use wb-defaults
473 1676 Luisehahne
 * @return bool
474 1651 darkviper
 */
475 1866 Luisehahne
function change_mode($sName, $iMode = 0 )
476 1352 Luisehahne
{
477 1651 darkviper
	$bRetval = true;
478 1759 Luisehahne
    $iErrorReporting = error_reporting(0);
479 1653 darkviper
	$iMode = intval($iMode) & 0777; // sanitize value
480 1705 Luisehahne
	if (strtoupper(substr(PHP_OS, 0, 3)) !== 'WIN')
481 1651 darkviper
	{ // Only chmod if os is not windows
482
		$bRetval = false;
483
		if(!$iMode) {
484
			$iMode = (is_file($sName) ? octdec(STRING_FILE_MODE) : octdec(STRING_DIR_MODE));
485 1352 Luisehahne
		}
486 1653 darkviper
		$iMode |= 0600; // set o+rw
487 1651 darkviper
		if(is_writable($sName)) {
488
			$bRetval = chmod($sName, $iMode);
489 1352 Luisehahne
		}
490
	}
491 1759 Luisehahne
    error_reporting($iErrorReporting);
492 1651 darkviper
	return $bRetval;
493 1352 Luisehahne
}
494
495
// Function to figure out if a parent exists
496
function is_parent($page_id)
497
{
498
	global $database;
499
	// Get parent
500
	$sql = 'SELECT `parent` FROM `'.TABLE_PREFIX.'pages` WHERE `page_id` = '.$page_id;
501
	$parent = $database->get_one($sql);
502
	// If parent isnt 0 return its ID
503 1495 DarkViper
	if(is_null($parent)) {
504 1352 Luisehahne
		return false;
505 1495 DarkViper
	}else {
506 1352 Luisehahne
		return $parent;
507
	}
508
}
509
510
// Function to work out level
511
function level_count($page_id)
512
{
513
	global $database;
514
	// Get page parent
515
	$sql = 'SELECT `parent` FROM `'.TABLE_PREFIX.'pages` WHERE `page_id` = '.$page_id;
516
	$parent = $database->get_one($sql);
517 1495 DarkViper
	if($parent > 0)
518 1352 Luisehahne
	{	// Get the level of the parent
519
		$sql = 'SELECT `level` FROM `'.TABLE_PREFIX.'pages` WHERE `page_id` = '.$parent;
520
		$level = $database->get_one($sql);
521
		return $level+1;
522 1495 DarkViper
	}else {
523 1352 Luisehahne
		return 0;
524
	}
525
}
526
527
// Function to work out root parent
528
function root_parent($page_id)
529
{
530
	global $database;
531
	// Get page details
532
	$sql = 'SELECT `parent`, `level` FROM `'.TABLE_PREFIX.'pages` WHERE `page_id` = '.$page_id;
533 1754 Luisehahne
534 1352 Luisehahne
	$query_page = $database->query($sql);
535 1759 Luisehahne
	$fetch_page = $query_page->fetchRow(MYSQL_ASSOC);
536 1352 Luisehahne
	$parent = $fetch_page['parent'];
537 1495 DarkViper
	$level = $fetch_page['level'];
538
	if($level == 1) {
539 1352 Luisehahne
		return $parent;
540 1754 Luisehahne
	} elseif($parent == 0) {
541 1352 Luisehahne
		return $page_id;
542 1754 Luisehahne
	} else {	// Figure out what the root parents id is
543 1352 Luisehahne
		$parent_ids = array_reverse(get_parent_ids($page_id));
544
		return $parent_ids[0];
545
	}
546
}
547
548
// Function to get page title
549
function get_page_title($id)
550
{
551
	global $database;
552
	// Get title
553
	$sql = 'SELECT `page_title` FROM `'.TABLE_PREFIX.'pages` WHERE `page_id` = '.$id;
554
	$page_title = $database->get_one($sql);
555
	return $page_title;
556
}
557
558
// Function to get a pages menu title
559
function get_menu_title($id)
560
{
561
	global $database;
562
	// Get title
563
	$sql = 'SELECT `menu_title` FROM `'.TABLE_PREFIX.'pages` WHERE `page_id` = '.$id;
564
	$menu_title = $database->get_one($sql);
565
	return $menu_title;
566
}
567 1908 Luisehahne
// Function to get a pages filename in sub
568
function get_sub_filename($id)
569
{
570
	$database = WbDatabase::getInstance();
571
	// Get title
572
	$sql = 'SELECT `link` FROM `'.TABLE_PREFIX.'pages` '
573
	      .'WHERE `page_id` = '.$id.' '
574
	      .  'AND `level`>=0';
575
	$sRetval = basename($database->get_one($sql));
576
	return $sRetval;
577
}
578 1352 Luisehahne
579
// Function to get all parent page titles
580
function get_parent_titles($parent_id)
581
{
582 1908 Luisehahne
	$titles[] = get_sub_filename($parent_id);
583 1495 DarkViper
	if(is_parent($parent_id) != false) {
584 1352 Luisehahne
		$parent_titles = get_parent_titles(is_parent($parent_id));
585
		$titles = array_merge($titles, $parent_titles);
586
	}
587
	return $titles;
588
}
589
590
// Function to get all parent page id's
591
function get_parent_ids($parent_id)
592
{
593
	$ids[] = $parent_id;
594 1495 DarkViper
	if(is_parent($parent_id) != false) {
595 1352 Luisehahne
		$parent_ids = get_parent_ids(is_parent($parent_id));
596
		$ids = array_merge($ids, $parent_ids);
597
	}
598
	return $ids;
599
}
600
601
// Function to genereate page trail
602 1495 DarkViper
function get_page_trail($page_id)
603
{
604 1352 Luisehahne
	return implode(',', array_reverse(get_parent_ids($page_id)));
605
}
606
607
// Function to get all sub pages id's
608 1514 Luisehahne
function get_subs($parent, array $subs )
609 1352 Luisehahne
{
610
	// Connect to the database
611
	global $database;
612
	// Get id's
613
	$sql = 'SELECT `page_id` FROM `'.TABLE_PREFIX.'pages` WHERE `parent` = '.$parent;
614 1514 Luisehahne
	if( ($query = $database->query($sql)) ) {
615 1759 Luisehahne
		while($fetch = $query->fetchRow(MYSQL_ASSOC)) {
616 1352 Luisehahne
			$subs[] = $fetch['page_id'];
617 1514 Luisehahne
			// Get subs of this sub recursive
618 1352 Luisehahne
			$subs = get_subs($fetch['page_id'], $subs);
619
		}
620
	}
621
	// Return subs array
622
	return $subs;
623
}
624
625
// Function as replacement for php's htmlspecialchars()
626
// Will not mangle HTML-entities
627
function my_htmlspecialchars($string)
628
{
629
	$string = preg_replace('/&(?=[#a-z0-9]+;)/i', '__amp;_', $string);
630
	$string = strtr($string, array('<'=>'&lt;', '>'=>'&gt;', '&'=>'&amp;', '"'=>'&quot;', '\''=>'&#39;'));
631
	$string = preg_replace('/__amp;_(?=[#a-z0-9]+;)/i', '&', $string);
632
	return($string);
633
}
634
635
// Convert a string from mixed html-entities/umlauts to pure $charset_out-umlauts
636
// Will replace all numeric and named entities except &gt; &lt; &apos; &quot; &#039; &nbsp;
637
// In case of error the returned string is unchanged, and a message is emitted.
638
function entities_to_umlauts($string, $charset_out=DEFAULT_CHARSET)
639
{
640
	require_once(WB_PATH.'/framework/functions-utf8.php');
641
	return entities_to_umlauts2($string, $charset_out);
642
}
643
644
// Will convert a string in $charset_in encoding to a pure ASCII string with HTML-entities.
645
// In case of error the returned string is unchanged, and a message is emitted.
646
function umlauts_to_entities($string, $charset_in=DEFAULT_CHARSET)
647
{
648
	require_once(WB_PATH.'/framework/functions-utf8.php');
649
	return umlauts_to_entities2($string, $charset_in);
650
}
651
652
// Function to convert a page title to a page filename
653
function page_filename($string)
654
{
655
	require_once(WB_PATH.'/framework/functions-utf8.php');
656
	$string = entities_to_7bit($string);
657
	// Now remove all bad characters
658
	$bad = array(
659
	'\'', /* /  */ '"', /* " */	'<', /* < */	'>', /* > */
660
	'{', /* { */	'}', /* } */	'[', /* [ */	']', /* ] */	'`', /* ` */
661
	'!', /* ! */	'@', /* @ */	'#', /* # */	'$', /* $ */	'%', /* % */
662
	'^', /* ^ */	'&', /* & */	'*', /* * */	'(', /* ( */	')', /* ) */
663
	'=', /* = */	'+', /* + */	'|', /* | */	'/', /* / */	'\\', /* \ */
664
	';', /* ; */	':', /* : */	',', /* , */	'?' /* ? */
665
	);
666
	$string = str_replace($bad, '', $string);
667
	// replace multiple dots in filename to single dot and (multiple) dots at the end of the filename to nothing
668
	$string = preg_replace(array('/\.+/', '/\.+$/'), array('.', ''), $string);
669
	// Now replace spaces with page spcacer
670
	$string = trim($string);
671
	$string = preg_replace('/(\s)+/', PAGE_SPACER, $string);
672
	// Now convert to lower-case
673
	$string = strtolower($string);
674
	// If there are any weird language characters, this will protect us against possible problems they could cause
675
	$string = str_replace(array('%2F', '%'), array('/', ''), urlencode($string));
676
	// Finally, return the cleaned string
677
	return $string;
678
}
679
680 1457 Luisehahne
// Function to convert a desired media filename to a clean mediafilename
681 1352 Luisehahne
function media_filename($string)
682
{
683
	require_once(WB_PATH.'/framework/functions-utf8.php');
684
	$string = entities_to_7bit($string);
685
	// Now remove all bad characters
686 1454 DarkViper
	$bad = array('\'','"','`','!','@','#','$','%','^','&','*','=','+','|','/','\\',';',':',',','?');
687 1352 Luisehahne
	$string = str_replace($bad, '', $string);
688
	// replace multiple dots in filename to single dot and (multiple) dots at the end of the filename to nothing
689 1454 DarkViper
	$string = preg_replace(array('/\.+/', '/\.+$/', '/\s/'), array('.', '', '_'), $string);
690 1352 Luisehahne
	// Clean any page spacers at the end of string
691
	$string = trim($string);
692
	// Finally, return the cleaned string
693
	return $string;
694
}
695
696
// Function to work out a page link
697
if(!function_exists('page_link'))
698
{
699
	function page_link($link)
700
	{
701
		global $admin;
702
		return $admin->page_link($link);
703
	}
704
}
705
706 1866 Luisehahne
707 1468 Luisehahne
// Create a new directory and/or protected file in the given directory
708 1477 Luisehahne
function createFolderProtectFile($sAbsDir='',$make_dir=true)
709 1457 Luisehahne
{
710
	global $admin, $MESSAGE;
711
	$retVal = array();
712 1977 Luisehahne
	$wb_path   = rtrim(str_replace('\/\\', '/', WB_PATH), '/');
713
	$sAppPath  = rtrim(str_replace('\/\\', '/', WB_PATH), '/').'/';
714
	if( ($sAbsDir=='') || ($sAbsDir == $sAppPath) ) { return $retVal;}
715 1457 Luisehahne
716
	if ( $make_dir==true ) {
717
		// Check to see if the folder already exists
718 1866 Luisehahne
		if(is_readable($sAbsDir)) {
719 1477 Luisehahne
			$retVal[] = basename($sAbsDir).'::'.$MESSAGE['MEDIA_DIR_EXISTS'];
720 1457 Luisehahne
		}
721 1977 Luisehahne
		if (!make_dir($sAbsDir) && !is_dir($sAbsDir) ) {
722 1477 Luisehahne
			$retVal[] = basename($sAbsDir).'::'.$MESSAGE['MEDIA_DIR_NOT_MADE'];
723
		} else {
724
			change_mode($sAbsDir);
725 1457 Luisehahne
		}
726 1866 Luisehahne
		return $retVal;
727 1457 Luisehahne
	}
728
729 1908 Luisehahne
//$retVal[] = $sAbsDir;
730
//return $retVal;
731
732 1477 Luisehahne
	if( is_writable($sAbsDir) )
733 1457 Luisehahne
	{
734 1477 Luisehahne
        // if(file_exists($sAbsDir.'/index.php')) { unlink($sAbsDir.'/index.php'); }
735 1457 Luisehahne
	    // Create default "index.php" file
736 1977 Luisehahne
		$iBackSteps = substr_count(str_replace($sAppPath, '', $sAbsDir), '/');
737
		$sIndexFile = str_repeat('../', $iBackSteps).'index.php';
738 1457 Luisehahne
		$sResponse  = $_SERVER['SERVER_PROTOCOL'].' 301 Moved Permanently';
739
		$content =
740
			'<?php'."\n".
741
			'// *** This file is generated by WebsiteBaker Ver.'.VERSION."\n".
742
			'// *** Creation date: '.date('c')."\n".
743
			'// *** Do not modify this file manually'."\n".
744
			'// *** WB will rebuild this file from time to time!!'."\n".
745
			'// *************************************************'."\n".
746
			"\t".'header(\''.$sResponse.'\');'."\n".
747
			"\t".'header(\'Location: '.WB_URL.'/index.php\');'."\n".
748
			'// *************************************************'."\n";
749 1477 Luisehahne
		$filename = $sAbsDir.'/index.php';
750 1484 Luisehahne
751 1457 Luisehahne
		// write content into file
752 1551 Luisehahne
		  if(is_writable($filename) || !file_exists($filename)) {
753
		      if(file_put_contents($filename, $content)) {
754 1866 Luisehahne
		          $retVal[] = change_mode($filename);
755 1765 Luisehahne
		      } else {
756 1551 Luisehahne
		    $retVal[] = $MESSAGE['GENERIC_BAD_PERMISSIONS'].' :: '.$filename;
757
		   }
758
		  }
759
		 } else {
760
		   $retVal[] = $MESSAGE['GENERIC_BAD_PERMISSIONS'];
761
		 }
762
		 return $retVal;
763 1457 Luisehahne
}
764
765
function rebuildFolderProtectFile($dir='')
766
{
767 1675 Luisehahne
	global $MESSAGE;
768 1495 DarkViper
	$retVal = array();
769 1866 Luisehahne
	$tmpVal = array();
770 1495 DarkViper
	$dir = rtrim(str_replace('\/\\', '/', $dir), '/');
771
	try {
772
		$files = array();
773
		$files[] = $dir;
774
		foreach(new RecursiveIteratorIterator(new RecursiveDirectoryIterator($dir)) as $fileInfo) {
775
			$files[] = $fileInfo->getPath();
776
		}
777
		$files = array_unique($files);
778
		foreach( $files as $file) {
779
			$protect_file = rtrim(str_replace('\/\\', '/', $file), '/');
780 1866 Luisehahne
			$tmpVal['file'][] = createFolderProtectFile($protect_file,false);
781 1495 DarkViper
		}
782 1866 Luisehahne
		$retVal = $tmpVal['file'];
783 1495 DarkViper
	} catch ( Exception $e ) {
784
		$retVal[] = $MESSAGE['MEDIA_DIR_ACCESS_DENIED'];
785
	}
786
	return $retVal;
787 1457 Luisehahne
}
788
789
// Create a new file in the pages directory
790 1866 Luisehahne
/**
791
 * createAccessFile()
792
 *
793
 * @param string The full path and filename to the new accessfile
794
 * @param int    Id of the page for which the file should created
795
 * @param mixed  an array with one or more additional statements to include in accessfile.
796
 * @return bool|string true or error message
797
 * @deprecated this function will be replaced by a core method in next version
798
 * @description: Create a new access file in the pages directory and subdirectory also if needed.<br />
799
 * Example: $aOptionalCommands = array(
800
 *                     '$section_id = '.$section_id,
801
 *                     '$mod_var_int = '.$mod_var_int,
802
 *                     'define(\'MOD_CONSTANT\'', '.$mod_var_int.')'
803
 *          );
804
 * forbidden commands: include|require[_once]
805
 * @deprecated   2013/02/19
806
 */
807
808
function create_access_file($sFileName, $iPageId, $iLevel = 0, array $aOptionalCommands = array() )
809 1352 Luisehahne
{
810 1866 Luisehahne
	global $MESSAGE;
811
	$sError = '';
812
// sanitize pathnames for the standard 'trailing slash' scheme
813
	$sAppPath  = rtrim(str_replace('\\', '/', WB_PATH), '/').'/';
814
	$sFileName = str_replace('\\', '/', $sFileName);
815
// try to create the whoole path to the accessfile
816
	$sAccessPath = dirname($sFileName).'/';
817
	if(!($bRetval = is_dir($sAccessPath))) {
818
		$iOldUmask = umask(0) ;
819
		// sanitize directory mode to 'o+rwx/g+x/u+x' and create path
820
		$bRetval = mkdir($sAccessPath, (OCTAL_DIR_MODE |0711), true);
821
		umask($iOldUmask);
822
	}
823
	if($bRetval) {
824
	// check if accessfile is writeable
825
		if(is_writable($sAccessPath) ||
826
		   (file_exists($sFileName) && is_writable($sFileName)) )
827 1352 Luisehahne
		{
828 1866 Luisehahne
		// build content for accessfile
829
			$sContent  = '<?php'."\n"
830
			           . '// *** This file is generated by WebsiteBaker Ver.'.VERSION."\n"
831
			           . '// *** Creation date: '.date('c')."\n"
832
			           . '// *** Do not modify this file manually'."\n"
833
			           . '// *** WB will rebuild this file from time to time!!'."\n"
834
			           . '// *************************************************'."\n"
835
			           . "\t".'$page_id = '.$iPageId.';'."\n";
836
		// analyse OptionalCommands and add it to the accessfile
837
			foreach($aOptionalCommands as $sCommand) {
838
			// loop through all available entries
839
			// remove all leading whitespaces and chars less then \x41(A) except \x24 ($)
840
			// also all trailing whitespaces and \x3B(;) too.
841
				$sNewCmd  = rtrim(ltrim($sCommand, "\x00..\x23\x25..\x40"), ';');
842
				if(preg_match('/^include|^require/i', $sNewCmd)) {
843
				// insert forbidden include|require[_once] command and comment it out
844
					$sContent .= "\t".'// *not allowed command >> * '.$sNewCmd.';'."\n";
845
				}elseif(preg_match('/^define/i', $sNewCmd)) {
846
				// insert active define command and comment it as set deprecated
847
					$sContent .= "\t".$sNewCmd.'; // *deprecated command*'."\n";
848
				}else {
849
				// insert allowed active command
850
					$sContent .= "\t".$sNewCmd.';'."\n";
851 1352 Luisehahne
				}
852 1457 Luisehahne
			}
853 1866 Luisehahne
		// calculate the needed backsteps and create the relative link to index.php
854
			$iBackSteps = substr_count(str_replace($sAppPath, '', $sFileName), '/');
855
			$sIndexFile = str_repeat('../', $iBackSteps).'index.php';
856
		// insert needed require command for index.php
857
			$sContent .= "\t".'require(\''.$sIndexFile.'\');'."\n"
858
			           . '// *************************************************'."\n"
859
			           . '// end of file'."\n";
860
		// write new file out. If the file already exists overwrite its content.
861
			if(file_put_contents($sFileName, $sContent) !== false ) {
862
			// if OS is not windows then chmod the new file
863
				if (strtoupper(substr(PHP_OS, 0, 3)) !== 'WIN') {
864
				// sanitize filemode to 'o-x/g-x/u-x/o+rw' and chmod the new file
865 1871 Luisehahne
					$bRetval = chmod($sFileName, ((OCTAL_FILE_MODE & ~0111)|0600));
866 1866 Luisehahne
				}
867
			}else {
868
		        $sError = $MESSAGE['PAGES_CANNOT_CREATE_ACCESS_FILE'];
869
			}
870
		}else {
871
			$sError = $MESSAGE['UPLOAD_ERR_CANT_WRITE'];
872 1352 Luisehahne
		}
873 1866 Luisehahne
	}else {
874
		$sError = $MESSAGE['UPLOAD_ERR_CANT_WRITE'];
875 1495 DarkViper
	}
876 1866 Luisehahne
	// return boolean true if ok, on error return a message
877
	return ($sError == '' ? true : $sError);
878 1457 Luisehahne
 }
879
880 1352 Luisehahne
// Function for working out a file mime type (if the in-built PHP one is not enabled)
881
if(!function_exists('mime_content_type'))
882
{
883 1457 Luisehahne
    function mime_content_type($filename)
884 1352 Luisehahne
	{
885
	    $mime_types = array(
886
            'txt'	=> 'text/plain',
887
            'htm'	=> 'text/html',
888
            'html'	=> 'text/html',
889
            'php'	=> 'text/html',
890
            'css'	=> 'text/css',
891
            'js'	=> 'application/javascript',
892
            'json'	=> 'application/json',
893
            'xml'	=> 'application/xml',
894
            'swf'	=> 'application/x-shockwave-flash',
895
            'flv'	=> 'video/x-flv',
896
897
            // images
898
            'png'	=> 'image/png',
899
            'jpe'	=> 'image/jpeg',
900
            'jpeg'	=> 'image/jpeg',
901
            'jpg'	=> 'image/jpeg',
902
            'gif'	=> 'image/gif',
903
            'bmp'	=> 'image/bmp',
904
            'ico'	=> 'image/vnd.microsoft.icon',
905
            'tiff'	=> 'image/tiff',
906
            'tif'	=> 'image/tiff',
907
            'svg'	=> 'image/svg+xml',
908
            'svgz'	=> 'image/svg+xml',
909
910
            // archives
911
            'zip'	=> 'application/zip',
912
            'rar'	=> 'application/x-rar-compressed',
913
            'exe'	=> 'application/x-msdownload',
914
            'msi'	=> 'application/x-msdownload',
915
            'cab'	=> 'application/vnd.ms-cab-compressed',
916
917
            // audio/video
918
            'mp3'	=> 'audio/mpeg',
919
            'mp4'	=> 'audio/mpeg',
920
            'qt'	=> 'video/quicktime',
921
            'mov'	=> 'video/quicktime',
922
923
            // adobe
924
            'pdf'	=> 'application/pdf',
925
            'psd'	=> 'image/vnd.adobe.photoshop',
926
            'ai'	=> 'application/postscript',
927
            'eps'	=> 'application/postscript',
928
            'ps'	=> 'application/postscript',
929
930
            // ms office
931
            'doc'	=> 'application/msword',
932
            'rtf'	=> 'application/rtf',
933
            'xls'	=> 'application/vnd.ms-excel',
934
            'ppt'	=> 'application/vnd.ms-powerpoint',
935
936
            // open office
937
            'odt'	=> 'application/vnd.oasis.opendocument.text',
938
            'ods'	=> 'application/vnd.oasis.opendocument.spreadsheet',
939
        );
940
        $temp = explode('.',$filename);
941
        $ext = strtolower(array_pop($temp));
942 1495 DarkViper
        if (array_key_exists($ext, $mime_types)) {
943 1352 Luisehahne
            return $mime_types[$ext];
944 1495 DarkViper
        }elseif (function_exists('finfo_open')) {
945 1352 Luisehahne
            $finfo = finfo_open(FILEINFO_MIME);
946
            $mimetype = finfo_file($finfo, $filename);
947
            finfo_close($finfo);
948
            return $mimetype;
949 1495 DarkViper
        }else {
950 1352 Luisehahne
            return 'application/octet-stream';
951
        }
952
    }
953
}
954
955
// Generate a thumbnail from an image
956
function make_thumb($source, $destination, $size)
957
{
958
	// Check if GD is installed
959 1365 Luisehahne
	if(extension_loaded('gd') && function_exists('imageCreateFromJpeg'))
960 1352 Luisehahne
	{
961
		// First figure out the size of the thumbnail
962
		list($original_x, $original_y) = getimagesize($source);
963 1495 DarkViper
		if ($original_x > $original_y) {
964 1352 Luisehahne
			$thumb_w = $size;
965
			$thumb_h = $original_y*($size/$original_x);
966
		}
967 1495 DarkViper
		if ($original_x < $original_y) {
968 1352 Luisehahne
			$thumb_w = $original_x*($size/$original_y);
969
			$thumb_h = $size;
970
		}
971 1495 DarkViper
		if ($original_x == $original_y) {
972 1352 Luisehahne
			$thumb_w = $size;
973 1495 DarkViper
			$thumb_h = $size;
974 1352 Luisehahne
		}
975
		// Now make the thumbnail
976
		$source = imageCreateFromJpeg($source);
977
		$dst_img = ImageCreateTrueColor($thumb_w, $thumb_h);
978
		imagecopyresampled($dst_img,$source,0,0,0,0,$thumb_w,$thumb_h,$original_x,$original_y);
979
		imagejpeg($dst_img, $destination);
980
		// Clear memory
981
		imagedestroy($dst_img);
982
		imagedestroy($source);
983
	   // Return true
984
		return true;
985
	} else {
986
		return false;
987
	}
988
}
989
990
/*
991
 * Function to work-out a single part of an octal permission value
992
 *
993
 * @param mixed $octal_value: an octal value as string (i.e. '0777') or real octal integer (i.e. 0777 | 777)
994
 * @param string $who: char or string for whom the permission is asked( U[ser] / G[roup] / O[thers] )
995
 * @param string $action: char or string with the requested action( r[ead..] / w[rite..] / e|x[ecute..] )
996
 * @return boolean
997
 */
998
function extract_permission($octal_value, $who, $action)
999
{
1000
	// Make sure that all arguments are set and $octal_value is a real octal-integer
1001 1495 DarkViper
	if(($who == '') || ($action == '') || (preg_match( '/[^0-7]/', (string)$octal_value ))) {
1002 1352 Luisehahne
		return false; // invalid argument, so return false
1003
	}
1004
	// convert $octal_value into a decimal-integer to be sure having a valid value
1005
	$right_mask = octdec($octal_value);
1006
	$action_mask = 0;
1007
	// set the $action related bit in $action_mask
1008 1495 DarkViper
	switch($action[0]) { // get action from first char of $action
1009 1352 Luisehahne
		case 'r':
1010
		case 'R':
1011
			$action_mask = 4; // set read-bit only (2^2)
1012
			break;
1013
		case 'w':
1014
		case 'W':
1015
			$action_mask = 2; // set write-bit only (2^1)
1016
			break;
1017
		case 'e':
1018
		case 'E':
1019
		case 'x':
1020
		case 'X':
1021
			$action_mask = 1; // set execute-bit only (2^0)
1022
			break;
1023
		default:
1024
			return false; // undefined action name, so return false
1025
	}
1026
	// shift action-mask into the right position
1027 1495 DarkViper
	switch($who[0]) { // get who from first char of $who
1028 1352 Luisehahne
		case 'u':
1029
		case 'U':
1030
			$action_mask <<= 3; // shift left 3 bits
1031
		case 'g':
1032
		case 'G':
1033
			$action_mask <<= 3; // shift left 3 bits
1034
		case 'o':
1035
		case 'O':
1036
			/* NOP */
1037
			break;
1038
		default:
1039
			return false; // undefined who, so return false
1040
	}
1041
	return( ($right_mask & $action_mask) != 0 ); // return result of binary-AND
1042
}
1043
1044
// Function to delete a page
1045 1365 Luisehahne
	function delete_page($page_id)
1046 1352 Luisehahne
	{
1047 1365 Luisehahne
		global $admin, $database, $MESSAGE;
1048
		// Find out more about the page
1049 1495 DarkViper
		$sql  = 'SELECT `page_id`, `menu_title`, `page_title`, `level`, ';
1050
		$sql .=        '`link`, `parent`, `modified_by`, `modified_when` ';
1051
		$sql .= 'FROM `'.TABLE_PREFIX.'pages` WHERE `page_id`='.$page_id;
1052 1365 Luisehahne
		$results = $database->query($sql);
1053
		if($database->is_error())    { $admin->print_error($database->get_error()); }
1054 1759 Luisehahne
		if($results->numRows() == 0) { $admin->print_error($MESSAGE['PAGES_NOT_FOUND']); }
1055
		$results_array = $results->fetchRow(MYSQL_ASSOC);
1056 1365 Luisehahne
		$parent     = $results_array['parent'];
1057
		$level      = $results_array['level'];
1058 1859 Luisehahne
		$sPageLink       = $results_array['link'];
1059 1365 Luisehahne
		$page_title = $results_array['page_title'];
1060
		$menu_title = $results_array['menu_title'];
1061
		// Get the sections that belong to the page
1062 1495 DarkViper
		$sql  = 'SELECT `section_id`, `module` FROM `'.TABLE_PREFIX.'sections` ';
1063
		$sql .= 'WHERE `page_id`='.$page_id;
1064 1365 Luisehahne
		$query_sections = $database->query($sql);
1065
		if($query_sections->numRows() > 0)
1066 1352 Luisehahne
		{
1067 1495 DarkViper
			while($section = $query_sections->fetchRow()) {
1068 1365 Luisehahne
				// Set section id
1069
				$section_id = $section['section_id'];
1070
				// Include the modules delete file if it exists
1071 1495 DarkViper
				if(file_exists(WB_PATH.'/modules/'.$section['module'].'/delete.php')) {
1072 1365 Luisehahne
					include(WB_PATH.'/modules/'.$section['module'].'/delete.php');
1073
				}
1074 1352 Luisehahne
			}
1075
		}
1076 1365 Luisehahne
		// Update the sections table
1077 1495 DarkViper
		$sql = 'DELETE FROM `'.TABLE_PREFIX.'sections` WHERE `page_id`='.$page_id;
1078 1365 Luisehahne
		$database->query($sql);
1079
		if($database->is_error()) {
1080
			$admin->print_error($database->get_error());
1081
		}
1082
		// Include the ordering class or clean-up ordering
1083
		include_once(WB_PATH.'/framework/class.order.php');
1084
		$order = new order(TABLE_PREFIX.'pages', 'position', 'page_id', 'parent');
1085
		$order->clean($parent);
1086
		// Unlink the page access file and directory
1087 1859 Luisehahne
		$directory = WB_PATH.PAGES_DIRECTORY.$sPageLink;
1088 1365 Luisehahne
		$filename = $directory.PAGE_EXTENSION;
1089
		$directory .= '/';
1090 1859 Luisehahne
		if(is_writable($filename))
1091 1365 Luisehahne
		{
1092 1495 DarkViper
			if(!is_writable(WB_PATH.PAGES_DIRECTORY.'/')) {
1093 1759 Luisehahne
				$admin->print_error($MESSAGE['PAGES_CANNOT_DELETE_ACCESS_FILE']);
1094 1859 Luisehahne
			} else {
1095 1365 Luisehahne
				unlink($filename);
1096 1859 Luisehahne
				if( is_writable($directory) && (rtrim($directory,'/') != WB_PATH.PAGES_DIRECTORY ) && (substr($sPageLink, 0, 1) != '.') )
1097 1365 Luisehahne
				{
1098
					rm_full_dir($directory);
1099
				}
1100
			}
1101
		}
1102 1859 Luisehahne
		// Update the pages table
1103
		$sql = 'DELETE FROM `'.TABLE_PREFIX.'pages` WHERE `page_id`='.$page_id;
1104
		$database->query($sql);
1105
		if($database->is_error()) {
1106
			$admin->print_error($database->get_error());
1107
		}
1108 1352 Luisehahne
	}
1109 1365 Luisehahne
1110
/*
1111
 * @param string $file: name of the file to read
1112
 * @param int $size: number of maximum bytes to read (0 = complete file)
1113
 * @return string: the content as string, false on error
1114
 */
1115
	function getFilePart($file, $size = 0)
1116 1352 Luisehahne
	{
1117 1365 Luisehahne
		$file_content = '';
1118
		if( file_exists($file) && is_file($file) && is_readable($file))
1119 1352 Luisehahne
		{
1120 1495 DarkViper
			if($size == 0) {
1121 1365 Luisehahne
				$size = filesize($file);
1122
			}
1123 1495 DarkViper
			if(($fh = fopen($file, 'rb'))) {
1124
				if( ($file_content = fread($fh, $size)) !== false ) {
1125 1365 Luisehahne
					return $file_content;
1126
				}
1127
				fclose($fh);
1128
			}
1129 1352 Luisehahne
		}
1130 1365 Luisehahne
		return false;
1131
	}
1132
1133
	/**
1134
	* replace varnames with values in a string
1135
	*
1136
	* @param string $subject: stringvariable with vars placeholder
1137
	* @param array $replace: values to replace vars placeholder
1138
	* @return string
1139
	*/
1140
    function replace_vars($subject = '', &$replace = null )
1141
    {
1142
		if(is_array($replace))
1143 1352 Luisehahne
		{
1144 1495 DarkViper
			foreach ($replace  as $key => $value) {
1145 1365 Luisehahne
				$subject = str_replace("{{".$key."}}", $value, $subject);
1146 1352 Luisehahne
			}
1147
		}
1148 1365 Luisehahne
		return $subject;
1149
    }
1150 1352 Luisehahne
1151 1925 darkviper
function setAccessDeniedToNewTools($sModulName)
1152
{
1153
	$oDb = WbDatabase::getInstance();
1154
	$sql = 'UPDATE `'.$oDb->getTablePrefix.'groups` '
1155
		 . 'SET `module_permissions`= TRIM(LEADING \',\' FROM (CONCAT(`module_permissions`, \','.$sModulName.'\'))) '
1156
	     . 'WHERE `group_id`<>1 AND NOT FIND_IN_SET(\''.$sModulName.'\', `module_permissions`)';
1157
	$oDb->query($sql);
1158
}
1159
1160 1352 Luisehahne
// Load module into DB
1161
function load_module($directory, $install = false)
1162
{
1163
	global $database,$admin,$MESSAGE;
1164 1365 Luisehahne
	$retVal = false;
1165
	if(is_dir($directory) && file_exists($directory.'/info.php'))
1166 1352 Luisehahne
	{
1167
		require($directory.'/info.php');
1168
		if(isset($module_name))
1169
		{
1170 1365 Luisehahne
			if(!isset($module_license)) { $module_license = 'GNU General Public License'; }
1171
			if(!isset($module_platform) && isset($module_designed_for)) { $module_platform = $module_designed_for; }
1172
			if(!isset($module_function) && isset($module_type)) { $module_function = $module_type; }
1173 1352 Luisehahne
			$module_function = strtolower($module_function);
1174
			// Check that it doesn't already exist
1175 1365 Luisehahne
			$sqlwhere = 'WHERE `type` = \'module\' AND `directory` = \''.$module_directory.'\'';
1176
			$sql  = 'SELECT COUNT(*) FROM `'.TABLE_PREFIX.'addons` '.$sqlwhere;
1177 1495 DarkViper
			if( $database->get_one($sql) ) {
1178 1365 Luisehahne
				$sql  = 'UPDATE `'.TABLE_PREFIX.'addons` SET ';
1179
			}else{
1180 1352 Luisehahne
				// Load into DB
1181
				$sql  = 'INSERT INTO `'.TABLE_PREFIX.'addons` SET ';
1182 1365 Luisehahne
				$sqlwhere = '';
1183
			}
1184 1495 DarkViper
			$sql .= '`directory`=\''.$module_directory.'\', ';
1185
			$sql .= '`name`=\''.$module_name.'\', ';
1186
			$sql .= '`description`=\''.addslashes($module_description).'\', ';
1187
			$sql .= '`type`=\'module\', ';
1188
			$sql .= '`function`=\''.$module_function.'\', ';
1189
			$sql .= '`version`=\''.$module_version.'\', ';
1190
			$sql .= '`platform`=\''.$module_platform.'\', ';
1191
			$sql .= '`author`=\''.addslashes($module_author).'\', ';
1192
			$sql .= '`license`=\''.addslashes($module_license).'\'';
1193 1365 Luisehahne
			$sql .= $sqlwhere;
1194 1765 Luisehahne
			$retVal = intval($database->query($sql) ? true : false);
1195 1925 darkviper
			if($retVal && !$sqlwhere &&
1196
			   ($module_function == 'tool' || $module_function == 'page' || $module_function == 'wysiwyg')
1197
			  ) {
1198
				setAccessDeniedToNewTools($module_directory);
1199
			}
1200 1365 Luisehahne
			// Run installation script
1201 1495 DarkViper
			if($install == true) {
1202
				if(file_exists($directory.'/install.php')) {
1203 1365 Luisehahne
					require($directory.'/install.php');
1204 1352 Luisehahne
				}
1205
			}
1206
		}
1207 1765 Luisehahne
        return $retVal;
1208 1352 Luisehahne
	}
1209
}
1210
1211
// Load template into DB
1212
function load_template($directory)
1213
{
1214
	global $database, $admin;
1215 1365 Luisehahne
	$retVal = false;
1216
	if(is_dir($directory) && file_exists($directory.'/info.php'))
1217 1352 Luisehahne
	{
1218
		require($directory.'/info.php');
1219
		if(isset($template_name))
1220
		{
1221 1495 DarkViper
			if(!isset($template_license)) {
1222 1352 Luisehahne
              $template_license = 'GNU General Public License';
1223
            }
1224 1495 DarkViper
			if(!isset($template_platform) && isset($template_designed_for)) {
1225 1352 Luisehahne
              $template_platform = $template_designed_for;
1226
            }
1227 1495 DarkViper
			if(!isset($template_function)) {
1228 1352 Luisehahne
              $template_function = 'template';
1229
            }
1230
			// Check that it doesn't already exist
1231 1495 DarkViper
			$sqlwhere = 'WHERE `type`=\'template\' AND `directory`=\''.$template_directory.'\'';
1232 1365 Luisehahne
			$sql  = 'SELECT COUNT(*) FROM `'.TABLE_PREFIX.'addons` '.$sqlwhere;
1233 1495 DarkViper
			if( $database->get_one($sql) ) {
1234 1365 Luisehahne
				$sql  = 'UPDATE `'.TABLE_PREFIX.'addons` SET ';
1235
			}else{
1236 1352 Luisehahne
				// Load into DB
1237
				$sql  = 'INSERT INTO `'.TABLE_PREFIX.'addons` SET ';
1238 1365 Luisehahne
				$sqlwhere = '';
1239 1352 Luisehahne
			}
1240 1495 DarkViper
			$sql .= '`directory`=\''.$template_directory.'\', ';
1241
			$sql .= '`name`=\''.$template_name.'\', ';
1242
			$sql .= '`description`=\''.addslashes($template_description).'\', ';
1243
			$sql .= '`type`=\'template\', ';
1244
			$sql .= '`function`=\''.$template_function.'\', ';
1245
			$sql .= '`version`=\''.$template_version.'\', ';
1246
			$sql .= '`platform`=\''.$template_platform.'\', ';
1247
			$sql .= '`author`=\''.addslashes($template_author).'\', ';
1248
			$sql .= '`license`=\''.addslashes($template_license).'\' ';
1249 1365 Luisehahne
			$sql .= $sqlwhere;
1250 1765 Luisehahne
			$retVal = intval($database->query($sql) ? true : false);
1251 1352 Luisehahne
		}
1252
	}
1253 1365 Luisehahne
	return $retVal;
1254 1352 Luisehahne
}
1255
1256
// Load language into DB
1257
function load_language($file)
1258
{
1259
	global $database,$admin;
1260 1365 Luisehahne
	$retVal = false;
1261 1352 Luisehahne
	if (file_exists($file) && preg_match('#^([A-Z]{2}.php)#', basename($file)))
1262
	{
1263 1365 Luisehahne
		// require($file);  it's to large
1264
		// read contents of the template language file into string
1265
		$data = @file_get_contents(WB_PATH.'/languages/'.str_replace('.php','',basename($file)).'.php');
1266
		// use regular expressions to fetch the content of the variable from the string
1267 1435 Luisehahne
		$language_name = get_variable_content('language_name', $data, false, false);
1268
		$language_code = get_variable_content('language_code', $data, false, false);
1269
		$language_author = get_variable_content('language_author', $data, false, false);
1270
		$language_version = get_variable_content('language_version', $data, false, false);
1271
		$language_platform = get_variable_content('language_platform', $data, false, false);
1272 1365 Luisehahne
1273 1352 Luisehahne
		if(isset($language_name))
1274
		{
1275 1365 Luisehahne
			if(!isset($language_license)) { $language_license = 'GNU General Public License'; }
1276
			if(!isset($language_platform) && isset($language_designed_for)) { $language_platform = $language_designed_for; }
1277 1352 Luisehahne
			// Check that it doesn't already exist
1278 1495 DarkViper
			$sqlwhere = 'WHERE `type`=\'language\' AND `directory`=\''.$language_code.'\'';
1279 1365 Luisehahne
			$sql  = 'SELECT COUNT(*) FROM `'.TABLE_PREFIX.'addons` '.$sqlwhere;
1280 1495 DarkViper
			if( $database->get_one($sql) ) {
1281 1365 Luisehahne
				$sql  = 'UPDATE `'.TABLE_PREFIX.'addons` SET ';
1282
			}else{
1283 1352 Luisehahne
				// Load into DB
1284
				$sql  = 'INSERT INTO `'.TABLE_PREFIX.'addons` SET ';
1285 1365 Luisehahne
				$sqlwhere = '';
1286 1352 Luisehahne
			}
1287 1495 DarkViper
			$sql .= '`directory`=\''.$language_code.'\', ';
1288
			$sql .= '`name`=\''.$language_name.'\', ';
1289 1747 Luisehahne
            $sql .= '`description`=\'\', ';
1290
			$sql .= '`function`=\'\', ';
1291 1495 DarkViper
			$sql .= '`type`=\'language\', ';
1292
			$sql .= '`version`=\''.$language_version.'\', ';
1293
			$sql .= '`platform`=\''.$language_platform.'\', ';
1294
			$sql .= '`author`=\''.addslashes($language_author).'\', ';
1295
			$sql .= '`license`=\''.addslashes($language_license).'\' ';
1296 1365 Luisehahne
			$sql .= $sqlwhere;
1297 1765 Luisehahne
			$retVal = intval($database->query($sql) ? true : false);
1298 1352 Luisehahne
		}
1299
	}
1300 1365 Luisehahne
	return $retVal;
1301 1352 Luisehahne
}
1302
1303
// Upgrade module info in DB, optionally start upgrade script
1304
function upgrade_module($directory, $upgrade = false)
1305
{
1306
	global $database, $admin, $MESSAGE, $new_module_version;
1307
	$mod_directory = WB_PATH.'/modules/'.$directory;
1308
	if(file_exists($mod_directory.'/info.php'))
1309
	{
1310
		require($mod_directory.'/info.php');
1311
		if(isset($module_name))
1312
		{
1313 1365 Luisehahne
			if(!isset($module_license)) { $module_license = 'GNU General Public License'; }
1314 1352 Luisehahne
			if(!isset($module_platform) && isset($module_designed_for)) { $module_platform = $module_designed_for; }
1315 1365 Luisehahne
			if(!isset($module_function) && isset($module_type)) { $module_function = $module_type; }
1316 1352 Luisehahne
			$module_function = strtolower($module_function);
1317
			// Check that it does already exist
1318
			$sql  = 'SELECT COUNT(*) FROM `'.TABLE_PREFIX.'addons` ';
1319 1495 DarkViper
			$sql .= 'WHERE `directory`=\''.$module_directory.'\'';
1320 1352 Luisehahne
			if( $database->get_one($sql) )
1321
			{
1322
				// Update in DB
1323
				$sql  = 'UPDATE `'.TABLE_PREFIX.'addons` SET ';
1324 1495 DarkViper
				$sql .= '`version`=\''.$module_version.'\', ';
1325
				$sql .= '`description`=\''.addslashes($module_description).'\', ';
1326
				$sql .= '`platform`=\''.$module_platform.'\', ';
1327
				$sql .= '`author`=\''.addslashes($module_author).'\', ';
1328
				$sql .= '`license`=\''.addslashes($module_license).'\' ';
1329
				$sql .= 'WHERE `directory`=\''.$module_directory.'\' ';
1330 1352 Luisehahne
				$database->query($sql);
1331
				if($database->is_error()) {
1332
					$admin->print_error($database->get_error());
1333
				}
1334
				// Run upgrade script
1335 1495 DarkViper
				if($upgrade == true) {
1336
					if(file_exists($mod_directory.'/upgrade.php')) {
1337 1352 Luisehahne
						require($mod_directory.'/upgrade.php');
1338
					}
1339
				}
1340
			}
1341
		}
1342
	}
1343
}
1344
1345
// extracts the content of a string variable from a string (save alternative to including files)
1346
if(!function_exists('get_variable_content'))
1347
{
1348
	function get_variable_content($search, $data, $striptags=true, $convert_to_entities=true)
1349
	{
1350
		$match = '';
1351
		// search for $variable followed by 0-n whitespace then by = then by 0-n whitespace
1352
		// then either " or ' then 0-n characters then either " or ' followed by 0-n whitespace and ;
1353
		// the variable name is returned in $match[1], the content in $match[3]
1354
		if (preg_match('/(\$' .$search .')\s*=\s*("|\')(.*)\2\s*;/', $data, $match))
1355
		{
1356 1495 DarkViper
			if(strip_tags(trim($match[1])) == '$' .$search) {
1357 1352 Luisehahne
				// variable name matches, return it's value
1358
				$match[3] = ($striptags == true) ? strip_tags($match[3]) : $match[3];
1359
				$match[3] = ($convert_to_entities == true) ? htmlentities($match[3]) : $match[3];
1360
				return $match[3];
1361
			}
1362
		}
1363
		return false;
1364
	}
1365
}
1366
1367 1365 Luisehahne
/*
1368
 * @param string $modulname: like saved in addons.directory
1369
 * @param boolean $source: true reads from database, false from info.php
1370
 * @return string:  the version as string, if not found returns null
1371
 */
1372
1373
	function get_modul_version($modulname, $source = true)
1374
	{
1375
		global $database;
1376
		$version = null;
1377
		if( $source != true )
1378
		{
1379 1495 DarkViper
			$sql  = 'SELECT `version` FROM `'.TABLE_PREFIX.'addons` ';
1380
			$sql .= 'WHERE `directory`=\''.$modulname.'\'';
1381 1365 Luisehahne
			$version = $database->get_one($sql);
1382
		} else {
1383
			$info_file = WB_PATH.'/modules/'.$modulname.'/info.php';
1384 1495 DarkViper
			if(file_exists($info_file)) {
1385
				if(($info_file = file_get_contents($info_file))) {
1386 1365 Luisehahne
					$version = get_variable_content('module_version', $info_file, false, false);
1387
					$version = ($version !== false) ? $version : null;
1388
				}
1389
			}
1390
		}
1391
		return $version;
1392
	}
1393
1394
/*
1395
 * @param string $varlist: commaseperated list of varnames to move into global space
1396
 * @return bool:  false if one of the vars already exists in global space (error added to msgQueue)
1397
 */
1398
	function vars2globals_wrapper($varlist)
1399
	{
1400
		$retval = true;
1401
		if( $varlist != '')
1402
		{
1403
			$vars = explode(',', $varlist);
1404
			foreach( $vars as $var)
1405
			{
1406 1495 DarkViper
				if( isset($GLOBALS[$var]) ){
1407 1365 Luisehahne
					ErrorLog::write( 'variabe $'.$var.' already defined in global space!!',__FILE__, __FUNCTION__, __LINE__);
1408
					$retval = false;
1409 1495 DarkViper
				}else {
1410 1365 Luisehahne
					global $$var;
1411
				}
1412
			}
1413
		}
1414
		return $retval;
1415
	}
1416
1417 1400 FrankH
/*
1418
 * filter directory traversal more thoroughly, thanks to hal 9000
1419
 * @param string $dir: directory relative to MEDIA_DIRECTORY
1420
 * @param bool $with_media_dir: true when to include MEDIA_DIRECTORY
1421
 * @return: false if directory traversal detected, real path if not
1422
 */
1423
	function check_media_path($directory, $with_media_dir = true)
1424
	{
1425 1495 DarkViper
		$md = ($with_media_dir) ? MEDIA_DIRECTORY : '';
1426 1400 FrankH
		$dir = realpath(WB_PATH . $md . '/' . utf8_decode($directory));
1427
		$required = realpath(WB_PATH . MEDIA_DIRECTORY);
1428
		if (strstr($dir, $required)) {
1429
			return $dir;
1430
		} else {
1431
			return false;
1432
		}
1433
	}
1434 1475 Luisehahne
1435
/*
1436
urlencode function and rawurlencode are mostly based on RFC 1738.
1437
However, since 2005 the current RFC in use for URIs standard is RFC 3986.
1438
Here is a function to encode URLs according to RFC 3986.
1439
*/
1440
if(!function_exists('url_encode')){
1441
	function url_encode($string) {
1442
	    $string = html_entity_decode($string,ENT_QUOTES,'UTF-8');
1443 1477 Luisehahne
	    $entities = array('%21', '%2A', '%27', '%28', '%29', '%3B', '%3A', '%40', '%26', '%3D', '%2B', '%24', '%2C', '%2F', '%3F', '%25', '%23', '%5B', '%5D');
1444
	    $replacements = array('!', '*', "'", "(", ")", ";", ":", "@", "&", "=", "+", "$", ",", "/", "?", "%", "#", "[", "]");
1445
	    return str_replace($entities,$replacements, rawurlencode($string));
1446 1475 Luisehahne
	}
1447 1705 Luisehahne
}
1448 1765 Luisehahne
1449 1980 Luisehahne
if(!function_exists('rebuild_all_accessfiles'))
1450
{
1451
	function rebuild_all_accessfiles($bShowDetails=false )
1452
	{
1453
		$oDb = WbDatabase::getInstance();
1454
		$oReg = WbAdaptor::getInstance();
1455
	// try to remove access files and build new folder protect files
1456
        $sTreeToDelete = $oReg->AppPath.$oReg->PagesDir;
1457
    	if(($sTreeToDelete!='') && is_writeable($sTreeToDelete)==true)
1458
		{
1459
			$aDeleteLog = array();
1460
            DeleteAccessFilesTree($sTreeToDelete, $aDeleteLog);
1461
		// show details if debug is set
1462
            if($bShowDetails) { $aRetval = $aDeleteLog; }
1463 1908 Luisehahne
    	}
1464 1980 Luisehahne
	// set logging informations
1465
		$aRetval = array_merge((isset($aRetval) ? $aRetval : array()),
1466
		                       createFolderProtectFile(rtrim( $oReg->AppPath.$oReg->PagesDir, '/') ));
1467
	// Reformat/rebuild all existing access files
1468
		$sql  = 'SELECT `page_id`,`root_parent`,`parent`,`link`,`level`,`page_trail` '
1469
		      . 'FROM `'.$oDb->TablePrefix.'pages` '
1470
		      . 'WHERE `link` != \'\' '
1471
		      . 'ORDER BY `link`';
1472
        if (($oPage = $oDb->query($sql)))
1473 1765 Luisehahne
        {
1474 1980 Luisehahne
            $iFileCounter = 0;
1475
		// iterate over all existing page records
1476
            while (($aPageRecord = $oPage->fetchRow(MYSQL_ASSOC)))
1477 1765 Luisehahne
            {
1478 1980 Luisehahne
		// --- begin reorg tree structure ------------------------------------------------
1479
			// rebuild level entries
1480
				$sql = 'SELECT `level`+1 AS `level`, `page_trail` '
1481
				     . 'FROM `'.$oDb->TablePrefix.'pages` '
1482
					 . 'WHERE `page_id`='.$aPageRecord['parent'];
1483
			// search for parent record
1484
				$oParent = $oDb->query($sql);
1485
				if(($aParentRecord = $oParent->fetchRow(MYSQLI_ASSOC)))
1486
				{
1487
				// get values from existing parent record
1488
					$aPageRecord['level'] = intval($aParentRecord['level']);
1489
					$aPageRecord['root_parent'] = intval($aParentRecord['page_trail']);
1490
					$aPageRecord['page_trail'] = (string)$aParentRecord['page_trail'].','.(string)$aPageRecord['page_id'];
1491
				}else
1492
				{
1493
				// set as root record if no parentrecord exists
1494
					$aPageRecord['level'] = 0;
1495
					$aPageRecord['root_parent'] = $aPageRecord['page_id'];
1496
					$aPageRecord['page_trail'] = (string)$aPageRecord['page_id'];
1497
				}
1498
			// update current record with regenerated values
1499
                $sql  = 'UPDATE `'.$oDb->TablePrefix.'pages` '
1500
				      . 'SET `root_parent`='.$aPageRecord['root_parent'].', '
1501
				      .     '`level`='.$aPageRecord['level'].', '
1502
				      .     '`page_trail`=\''.$aPageRecord['page_trail'].'\' '
1503
				      . 'WHERE `page_id`='.$aPageRecord['page_id'];
1504
				$oDb->query($sql);
1505
		// --- end reorg tree structure --------------------------------------------------
1506 1981 Luisehahne
                $sFilename = $oReg->AppPath.$oReg->PagesDir.ltrim($aPageRecord['link'],'/').$oReg->PageExtension;
1507 1980 Luisehahne
				$oAccessFile = new AccessFile($sFilename, $aPageRecord['page_id']);
1508
				$oAccessFile->write();
1509
				unset($oAccessFile);
1510
                $iFileCounter++;
1511 1765 Luisehahne
            }
1512 1980 Luisehahne
            $aRetval[] = 'Number of new formated access files: '.$iFileCounter;
1513 1765 Luisehahne
        }
1514 1980 Luisehahne
		return $aRetval;
1515
	} // end of function rebuild_all_accessfiles()
1516
} // endif
1517 1765 Luisehahne
1518
if(!function_exists('upgrade_modules')){
1519
	function upgrade_modules($aModuleList) {
1520
        global $database;
1521
    	foreach($aModuleList as $sModul) {
1522
    		if(file_exists(WB_PATH.'/modules/'.$sModul.'/upgrade.php')) {
1523
    			$currModulVersion = get_modul_version ($sModul, false);
1524
    			$newModulVersion =  get_modul_version ($sModul, true);
1525
    			if((version_compare($currModulVersion, $newModulVersion) <= 0)) {
1526 1866 Luisehahne
    				require(WB_PATH.'/modules/'.$sModul.'/upgrade.php');
1527 1765 Luisehahne
    			}
1528
    		}
1529
    	}
1530
    }
1531
}