Project

General

Profile

« Previous | Next » 

Revision 1327

Added by Dietmar over 14 years ago

litte fix to show GMT value in default view
fixed file_list

View differences:

branches/2.8.x/CHANGELOG
11 11
! = Update/Change
12 12

  
13 13
------------------------------------- 2.8.1 -------------------------------------
14
17-Apr-2010 Dietmar Woellbrink (Luisehahne)
15
!	litte fix to show GMT value in default view
16
!	fixed file_list
14 17
15-Apr-2010 Dietmar Woellbrink (Luisehahne)
15 18
!	Update headerinfos admin/interface
16 19
14-Apr-2010 Dietmar Woellbrink (Luisehahne)
branches/2.8.x/wb/admin/interface/version.php
52 52

  
53 53
// check if defined to avoid errors during installation (redirect to admin panel fails if PHP error/warnings are enabled)
54 54
if(!defined('VERSION')) define('VERSION', '2.8.x');
55
if(!defined('REVISION')) define('REVISION', '1326');
55
if(!defined('REVISION')) define('REVISION', '1327');
56 56

  
57 57
?>
branches/2.8.x/wb/admin/preferences/save.php
3 3
 *
4 4
 * @category        admin
5 5
 * @package         preferences
6
 * @author          Independend-Software-Team
6 7
 * @author          WebsiteBaker Project
7 8
 * @copyright       2004-2009, Ryan Djurovich
8 9
 * @copyright       2009-2010, Website Baker Org. e.V.
branches/2.8.x/wb/admin/preferences/index.php
3 3
 *
4 4
 * @category        admin
5 5
 * @package         preferences
6
 * @author          Independend-Software-Team
6 7
 * @author          WebsiteBaker Project
7 8
 * @copyright       2004-2009, Ryan Djurovich
8 9
 * @copyright       2009-2010, Website Baker Org. e.V.
......
58 59
		}
59 60
	}
60 61
// Insert default timezone values
62
	$user_time = true;
61 63
	include_once( ADMIN_PATH.'/interface/timezones.php' );
62 64
	$template->set_block('main_block', 'timezone_list_block', 'timezone_list');
63 65
	foreach( $TIMEZONES AS $hour_offset => $title )
......
68 70
		$template->parse('timezone_list', 'timezone_list_block', true);
69 71
	}
70 72
// Insert date format list
71
	$user_time = true;
72 73
	include_once( ADMIN_PATH.'/interface/date_formats.php' );
73 74
	$template->set_block('main_block', 'date_format_list_block', 'date_format_list');
74 75
	foreach( $DATE_FORMATS AS $format => $title )
......
76 77
		$format = str_replace('|', ' ', $format); // Add's white-spaces (not able to be stored in array key)
77 78
		$template->set_var( 'VALUE', ($format != 'system_default' ? $format : 'system_default') );
78 79
		$template->set_var( 'NAME',  $title );
79
		if( (DATE_FORMAT == $format AND !isset($_SESSION['USE_DEFAULT_DATE_FORMAT'])) OR
80
			('system_default' == $format AND isset($_SESSION['USE_DEFAULT_DATE_FORMAT'])) )
80
		if( (DATE_FORMAT == $format && !isset($_SESSION['USE_DEFAULT_DATE_FORMAT'])) ||
81
			('system_default' == $format && isset($_SESSION['USE_DEFAULT_DATE_FORMAT'])) )
81 82
		{
82 83
			$template->set_var('SELECTED', ' selected="selected"');
83 84
		}else {
......
93 94
		$format = str_replace('|', ' ', $format); // Add's white-spaces (not able to be stored in array key)
94 95
		$template->set_var('VALUE', $format != 'system_default' ? $format : 'system_default' );
95 96
		$template->set_var('NAME',  $title);
96
		if( (TIME_FORMAT == $format AND !isset($_SESSION['USE_DEFAULT_TIME_FORMAT'])) OR
97
		    ('system_default' == $format AND isset($_SESSION['USE_DEFAULT_TIME_FORMAT'])) )
97
		if( (TIME_FORMAT == $format && !isset($_SESSION['USE_DEFAULT_TIME_FORMAT'])) ||
98
		    ('system_default' == $format && isset($_SESSION['USE_DEFAULT_TIME_FORMAT'])) )
98 99
		{
99 100
			$template->set_var('SELECTED', ' selected="selected"');
100 101
		} else {
branches/2.8.x/wb/framework/functions.php
1
<?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)
62
{
63
	$list = array();
64
	if (is_dir($directory))
65
    {
66
    	// Open the directory then loop through its contents
67
    	$dir = dir($directory);
68
    	while (false !== $entry = $dir->read())
69
		{
70
    		// Skip pointers
71
    		if($entry[0] == '.') { continue; }
72
    		// Add dir and contents to list
73
    		if (is_dir("$directory/$entry"))
74
			{
75
    			$list = array_merge($list, directory_list("$directory/$entry"));
76
    			$list[] = "$directory/$entry";
77
    		}
78
    	}
79
        $dir->close();
80
    }
81
    // Now return the list
82
	return $list;
83
}
84

  
85
// Function to open a directory and add to a dir list
86
function chmod_directory_contents($directory, $file_mode)
87
{
88
	if (is_dir($directory))
89
    {
90
    	// Set the umask to 0
91
    	$umask = umask(0);
92
    	// Open the directory then loop through its contents
93
    	$dir = dir($directory);
94
    	while (false !== $entry = $dir->read())
95
		{
96
    		// Skip pointers
97
    		if($entry[0] == '.') { continue; }
98
    		// Chmod the sub-dirs contents
99
    		if(is_dir("$directory/$entry"))
100
			{
101
    			chmod_directory_contents($directory.'/'.$entry, $file_mode);
102
    		}
103
    		change_mode($directory.'/'.$entry);
104
    	}
105
        $dir->close();
106
    	// Restore the umask
107
    	umask($umask);
108
    }
109
}
110

  
111
// Function to open a directory and add to a file list
112
function file_list($directory, $skip = array())
113
{
114
	$list = array();
115
	$skip_file = false;
116
	if (is_dir($directory))
117
    {
118
    	// Open the directory then loop through its contents
119
    	$dir = dir($directory);
120
    }
121
	while (false !== $entry = $dir->read())
122
    {
123
		// Skip pointers
124
		if($entry[0] == '.') { $skip_file = true; }
125
		// Check if we to skip anything else
126
		if($skip != array())
127
		{
128
			foreach($skip AS $skip_name)
129
            {
130
				if($entry == $skip_name)
131
                {
132
					$skip_file = true;
133
				}
134
			}
135
		}
136
		// Add dir and contents to list
137
		if($skip_file != true AND is_file("$directory/$entry"))
138
        {
139
			$list[] = "$directory/$entry";
140
		}
141
		
142
		// Reset the skip file var
143
		$skip_file = false;
144
	}
145
    $dir->close();
146
	// Now delete the folder
147
	return $list;
148
}
149

  
150
// Function to get a list of home folders not to show
151
function get_home_folders()
152
{
153
	global $database, $admin;
154
	$home_folders = array();
155
	// Only return home folders is this feature is enabled
156
	// and user is not admin
157
//	if(HOME_FOLDERS AND ($_SESSION['GROUP_ID']!='1')) {
158
	if(HOME_FOLDERS AND (!in_array('1',explode(',', $_SESSION['GROUPS_ID']))))
159
	{
160
		$sql = 'SELECT `home_folder` FROM `'.TABLE_PREFIX.'users` WHERE `home_folder` != "'.$admin->get_home_folder().'"';
161
		$query_home_folders = $database->query($sql);
162
		if($query_home_folders->numRows() > 0)
163
		{
164
			while($folder = $query_home_folders->fetchRow())
165
			{
166
				$home_folders[$folder['home_folder']] = $folder['home_folder'];
167
			}
168
		}
169
		function remove_home_subs($directory = '/', $home_folders = '')
170
		{
171
			if($handle = opendir(WB_PATH.MEDIA_DIRECTORY.$directory))
172
			{
173
				// Loop through the dirs to check the home folders sub-dirs are not shown
174
				while(false !== ($file = readdir($handle)))
175
				{
176
					if($file[0] != '.' AND $file != 'index.php')
177
					{
178
						if(is_dir(WB_PATH.MEDIA_DIRECTORY.$directory.'/'.$file))
179
						{
180
							if($directory != '/')
181
							{
182
								$file = $directory.'/'.$file;
183
							}
184
							else
185
							{
186
								$file = '/'.$file;
187
							}
188
							foreach($home_folders AS $hf)
189
							{
190
								$hf_length = strlen($hf);
191
								if($hf_length > 0)
192
								{
193
									if(substr($file, 0, $hf_length+1) == $hf)
194
									{
195
										$home_folders[$file] = $file;
196
									}
197
								}
198
							}
199
							$home_folders = remove_home_subs($file, $home_folders);
200
						}
201
					}
202
				}
203
			}
204
			return $home_folders;
205
		}
206
		$home_folders = remove_home_subs('/', $home_folders);
207
	}
208
	return $home_folders;
209
}
210

  
211
// Function to create directories
212
function make_dir($dir_name, $dir_mode = OCTAL_DIR_MODE)
213
{
214
	if(!is_dir($dir_name))
215
    {
216
		$umask = umask(0);
217
		mkdir($dir_name, $dir_mode);
218
		umask($umask);
219
		return true;
220
	} else {
221
		return false;	
222
	}
223
}
224

  
225
// Function to chmod files and directories
226
function change_mode($name)
227
{
228
	if(OPERATING_SYSTEM != 'windows')
229
    {
230
		// Only chmod if os is not windows
231
		if(is_dir($name))
232
        {
233
			$mode = OCTAL_DIR_MODE;
234
		}
235
        else
236
        {
237
			$mode = OCTAL_FILE_MODE;
238
		}
239

  
240
		if(file_exists($name))
241
        {
242
			$umask = umask(0);
243
			chmod($name, $mode);
244
			umask($umask);
245
			return true;
246
		}
247
        else
248
        {
249
			return false;	
250
		}
251
	}
252
    else
253
    {
254
		return true;
255
	}
256
}
257

  
258
// Function to figure out if a parent exists
259
function is_parent($page_id)
260
{
261
	global $database;
262
	// Get parent
263
	$sql = 'SELECT `parent` FROM `'.TABLE_PREFIX.'pages` WHERE `page_id` = '.$page_id;
264
	$parent = $database->get_one($sql);
265
	// If parent isnt 0 return its ID
266
	if(is_null($parent))
267
	{
268
		return false;
269
	}
270
	else
271
	{
272
		return $parent;
273
	}
274
}
275

  
276
// Function to work out level
277
function level_count($page_id)
278
{
279
	global $database;
280
	// Get page parent
281
	$sql = 'SELECT `parent` FROM `'.TABLE_PREFIX.'pages` WHERE `page_id` = '.$page_id;
282
	$parent = $database->get_one($sql);
283
	if($parent > 0) 
284
	{	// Get the level of the parent
285
		$sql = 'SELECT `level` FROM `'.TABLE_PREFIX.'pages` WHERE `page_id` = '.$parent;
286
		$level = $database->get_one($sql);
287
		return $level+1;
288
	}
289
	else
290
	{
291
		return 0;
292
	}
293
}
294

  
295
// Function to work out root parent
296
function root_parent($page_id)
297
{
298
	global $database;
299
	// Get page details
300
	$sql = 'SELECT `parent`, `level` FROM `'.TABLE_PREFIX.'pages` WHERE `page_id` = '.$page_id;
301
	$query_page = $database->query($sql);
302
	$fetch_page = $query_page->fetchRow();
303
	$parent = $fetch_page['parent'];
304
	$level = $fetch_page['level'];	
305
	if($level == 1)
306
	{
307
		return $parent;
308
	}
309
	elseif($parent == 0)
310
	{
311
		return $page_id;
312
	}
313
	else
314
	{	// Figure out what the root parents id is
315
		$parent_ids = array_reverse(get_parent_ids($page_id));
316
		return $parent_ids[0];
317
	}
318
}
319

  
320
// Function to get page title
321
function get_page_title($id)
322
{
323
	global $database;
324
	// Get title
325
	$sql = 'SELECT `page_title` FROM `'.TABLE_PREFIX.'pages` WHERE `page_id` = '.$id;
326
	$page_title = $database->get_one($sql);
327
	return $page_title;
328
}
329

  
330
// Function to get a pages menu title
331
function get_menu_title($id)
332
{
333
	global $database;
334
	// Get title
335
	$sql = 'SELECT `menu_title` FROM `'.TABLE_PREFIX.'pages` WHERE `page_id` = '.$id;
336
	$menu_title = $database->get_one($sql);
337
	return $menu_title;
338
}
339

  
340
// Function to get all parent page titles
341
function get_parent_titles($parent_id)
342
{
343
	$titles[] = get_menu_title($parent_id);
344
	if(is_parent($parent_id) != false)
345
	{
346
		$parent_titles = get_parent_titles(is_parent($parent_id));
347
		$titles = array_merge($titles, $parent_titles);
348
	}
349
	return $titles;
350
}
351

  
352
// Function to get all parent page id's
353
function get_parent_ids($parent_id)
354
{
355
	$ids[] = $parent_id;
356
	if(is_parent($parent_id) != false)
357
	{
358
		$parent_ids = get_parent_ids(is_parent($parent_id));
359
		$ids = array_merge($ids, $parent_ids);
360
	}
361
	return $ids;
362
}
363

  
364
// Function to genereate page trail
365
function get_page_trail($page_id) {
366
	return implode(',', array_reverse(get_parent_ids($page_id)));
367
}
368

  
369
// Function to get all sub pages id's
370
function get_subs($parent, $subs)
371
{
372
	// Connect to the database
373
	global $database;
374
	// Get id's
375
	$sql = 'SELECT `page_id` FROM `'.TABLE_PREFIX.'pages` WHERE `parent` = '.$parent;
376
	$query = $database->query($sql);
377
	if($query->numRows() > 0)
378
	{
379
		while($fetch = $query->fetchRow())
380
		{
381
			$subs[] = $fetch['page_id'];
382
			// Get subs of this sub
383
			$subs = get_subs($fetch['page_id'], $subs);
384
		}
385
	}
386
	// Return subs array
387
	return $subs;
388
}
389

  
390
// Function as replacement for php's htmlspecialchars()
391
// Will not mangle HTML-entities
392
function my_htmlspecialchars($string)
393
{
394
	$string = preg_replace('/&(?=[#a-z0-9]+;)/i', '__amp;_', $string);
395
	$string = strtr($string, array('<'=>'&lt;', '>'=>'&gt;', '&'=>'&amp;', '"'=>'&quot;', '\''=>'&#39;'));
396
	$string = preg_replace('/__amp;_(?=[#a-z0-9]+;)/i', '&', $string);
397
	return($string);
398
}
399

  
400
// Convert a string from mixed html-entities/umlauts to pure $charset_out-umlauts
401
// Will replace all numeric and named entities except &gt; &lt; &apos; &quot; &#039; &nbsp;
402
// In case of error the returned string is unchanged, and a message is emitted.
403
function entities_to_umlauts($string, $charset_out=DEFAULT_CHARSET)
404
{
405
	require_once(WB_PATH.'/framework/functions-utf8.php');
406
	return entities_to_umlauts2($string, $charset_out);
407
}
408

  
409
// Will convert a string in $charset_in encoding to a pure ASCII string with HTML-entities.
410
// In case of error the returned string is unchanged, and a message is emitted.
411
function umlauts_to_entities($string, $charset_in=DEFAULT_CHARSET)
412
{
413
	require_once(WB_PATH.'/framework/functions-utf8.php');
414
	return umlauts_to_entities2($string, $charset_in);
415
}
416

  
417
// Function to convert a page title to a page filename
418
function page_filename($string)
419
{
420
	require_once(WB_PATH.'/framework/functions-utf8.php');
421
	$string = entities_to_7bit($string);
422
	// Now remove all bad characters
423
	$bad = array(
424
	'\'', /* /  */ '"', /* " */	'<', /* < */	'>', /* > */
425
	'{', /* { */	'}', /* } */	'[', /* [ */	']', /* ] */	'`', /* ` */
426
	'!', /* ! */	'@', /* @ */	'#', /* # */	'$', /* $ */	'%', /* % */
427
	'^', /* ^ */	'&', /* & */	'*', /* * */	'(', /* ( */	')', /* ) */
428
	'=', /* = */	'+', /* + */	'|', /* | */	'/', /* / */	'\\', /* \ */
429
	';', /* ; */	':', /* : */	',', /* , */	'?' /* ? */
430
	);
431
	$string = str_replace($bad, '', $string);
432
	// replace multiple dots in filename to single dot and (multiple) dots at the end of the filename to nothing
433
	$string = preg_replace(array('/\.+/', '/\.+$/'), array('.', ''), $string);
434
	// Now replace spaces with page spcacer
435
	$string = trim($string);
436
	$string = preg_replace('/(\s)+/', PAGE_SPACER, $string);
437
	// Now convert to lower-case
438
	$string = strtolower($string);
439
	// If there are any weird language characters, this will protect us against possible problems they could cause
440
	$string = str_replace(array('%2F', '%'), array('/', ''), urlencode($string));
441
	// Finally, return the cleaned string
442
	return $string;
443
}
444

  
445
// Function to convert a desired media filename to a clean filename
446
function media_filename($string)
447
{
448
	require_once(WB_PATH.'/framework/functions-utf8.php');
449
	$string = entities_to_7bit($string);
450
	// Now remove all bad characters
451
	$bad = array(
452
	'\'', // '
453
	'"', // "
454
	'`', // `
455
	'!', // !
456
	'@', // @
457
	'#', // #
458
	'$', // $
459
	'%', // %
460
	'^', // ^
461
	'&', // &
462
	'*', // *
463
	'=', // =
464
	'+', // +
465
	'|', // |
466
	'/', // /
467
	'\\', // \
468
	';', // ;
469
	':', // :
470
	',', // ,
471
	'?' // ?
472
	);
473
	$string = str_replace($bad, '', $string);
474
	// replace multiple dots in filename to single dot and (multiple) dots at the end of the filename to nothing
475
	$string = preg_replace(array('/\.+/', '/\.+$/'), array('.', ''), $string);
476
	// Clean any page spacers at the end of string
477
	$string = trim($string);
478
	// Finally, return the cleaned string
479
	return $string;
480
}
481

  
482
// Function to work out a page link
483
if(!function_exists('page_link'))
484
{
485
	function page_link($link)
486
	{
487
		global $admin;
488
		return $admin->page_link($link);
489
	}
490
}
491

  
492
// Create a new file in the pages directory
493
function create_access_file($filename,$page_id,$level)
494
{
495
	global $admin, $MESSAGE;
496
	if(!is_writable(WB_PATH.PAGES_DIRECTORY.'/'))
497
	{
498
		$admin->print_error($MESSAGE['PAGES']['CANNOT_CREATE_ACCESS_FILE']);
499
	}
500
	else
501
	{
502
		// First make sure parent folder exists
503
		$parent_folders = explode('/',str_replace(WB_PATH.PAGES_DIRECTORY, '', dirname($filename)));
504
		$parents = '';
505
		foreach($parent_folders AS $parent_folder)
506
		{
507
			if($parent_folder != '/' AND $parent_folder != '')
508
			{
509
				$parents .= '/'.$parent_folder;
510
				if(!file_exists(WB_PATH.PAGES_DIRECTORY.$parents))
511
				{
512
					make_dir(WB_PATH.PAGES_DIRECTORY.$parents);
513
				}
514
			}	
515
		}
516
		// The depth of the page directory in the directory hierarchy
517
		// '/pages' is at depth 1
518
		$pages_dir_depth=count(explode('/',PAGES_DIRECTORY))-1;
519
		// Work-out how many ../'s we need to get to the index page
520
		$index_location = '';
521
		for($i = 0; $i < $level + $pages_dir_depth; $i++)
522
		{
523
			$index_location .= '../';
524
		}
525
		$content = ''.
526
'<?php
527
$page_id = '.$page_id.';
528
require("'.$index_location.'config.php");
529
require(WB_PATH."/index.php");
530
?>';
531
		$handle = fopen($filename, 'w');
532
		fwrite($handle, $content);
533
		fclose($handle);
534
		// Chmod the file
535
		change_mode($filename);
536
	}
537
}
538

  
539
// Function for working out a file mime type (if the in-built PHP one is not enabled)
540
if(!function_exists('mime_content_type'))
541
{
542
    function mime_content_type($filename) 
543
	{
544
	    $mime_types = array(
545
            'txt'	=> 'text/plain',
546
            'htm'	=> 'text/html',
547
            'html'	=> 'text/html',
548
            'php'	=> 'text/html',
549
            'css'	=> 'text/css',
550
            'js'	=> 'application/javascript',
551
            'json'	=> 'application/json',
552
            'xml'	=> 'application/xml',
553
            'swf'	=> 'application/x-shockwave-flash',
554
            'flv'	=> 'video/x-flv',
555

  
556
            // images
557
            'png'	=> 'image/png',
558
            'jpe'	=> 'image/jpeg',
559
            'jpeg'	=> 'image/jpeg',
560
            'jpg'	=> 'image/jpeg',
561
            'gif'	=> 'image/gif',
562
            'bmp'	=> 'image/bmp',
563
            'ico'	=> 'image/vnd.microsoft.icon',
564
            'tiff'	=> 'image/tiff',
565
            'tif'	=> 'image/tiff',
566
            'svg'	=> 'image/svg+xml',
567
            'svgz'	=> 'image/svg+xml',
568

  
569
            // archives
570
            'zip'	=> 'application/zip',
571
            'rar'	=> 'application/x-rar-compressed',
572
            'exe'	=> 'application/x-msdownload',
573
            'msi'	=> 'application/x-msdownload',
574
            'cab'	=> 'application/vnd.ms-cab-compressed',
575

  
576
            // audio/video
577
            'mp3'	=> 'audio/mpeg',
578
            'mp4'	=> 'audio/mpeg',
579
            'qt'	=> 'video/quicktime',
580
            'mov'	=> 'video/quicktime',
581

  
582
            // adobe
583
            'pdf'	=> 'application/pdf',
584
            'psd'	=> 'image/vnd.adobe.photoshop',
585
            'ai'	=> 'application/postscript',
586
            'eps'	=> 'application/postscript',
587
            'ps'	=> 'application/postscript',
588

  
589
            // ms office
590
            'doc'	=> 'application/msword',
591
            'rtf'	=> 'application/rtf',
592
            'xls'	=> 'application/vnd.ms-excel',
593
            'ppt'	=> 'application/vnd.ms-powerpoint',
594

  
595
            // open office
596
            'odt'	=> 'application/vnd.oasis.opendocument.text',
597
            'ods'	=> 'application/vnd.oasis.opendocument.spreadsheet',
598
        );
599

  
600
        $temp = explode('.',$filename);
601
        $ext = strtolower(array_pop($temp));
602

  
603
        if (array_key_exists($ext, $mime_types))
604
		{
605
            return $mime_types[$ext];
606
        }
607
        elseif (function_exists('finfo_open'))
608
		{
609
            $finfo = finfo_open(FILEINFO_MIME);
610
            $mimetype = finfo_file($finfo, $filename);
611
            finfo_close($finfo);
612
            return $mimetype;
613
        }
614
        else
615
		{
616
            return 'application/octet-stream';
617
        }
618
    }
619
}
620

  
621
// Generate a thumbnail from an image
622
function make_thumb($source, $destination, $size)
623
{
624
	// Check if GD is installed
625
	if(extension_loaded('gd') AND function_exists('imageCreateFromJpeg'))
626
	{
627
		// First figure out the size of the thumbnail
628
		list($original_x, $original_y) = getimagesize($source);
629
		if ($original_x > $original_y)
630
		{
631
			$thumb_w = $size;
632
			$thumb_h = $original_y*($size/$original_x);
633
		}
634
		if ($original_x < $original_y)
635
		{
636
			$thumb_w = $original_x*($size/$original_y);
637
			$thumb_h = $size;
638
		}
639
		if ($original_x == $original_y)
640
		{
641
			$thumb_w = $size;
642
			$thumb_h = $size;	
643
		}
644
		// Now make the thumbnail
645
		$source = imageCreateFromJpeg($source);
646
		$dst_img = ImageCreateTrueColor($thumb_w, $thumb_h);
647
		imagecopyresampled($dst_img,$source,0,0,0,0,$thumb_w,$thumb_h,$original_x,$original_y);
648
		imagejpeg($dst_img, $destination);
649
		// Clear memory
650
		imagedestroy($dst_img);
651
		imagedestroy($source);
652
	   // Return true
653
		return true;
654
	} else {
655
		return false;
656
	}
657
}
658

  
659
/*
660
 * Function to work-out a single part of an octal permission value
661
 *
662
 * @param mixed $octal_value: an octal value as string (i.e. '0777') or real octal integer (i.e. 0777 | 777)
663
 * @param string $who: char or string for whom the permission is asked( U[ser] / G[roup] / O[thers] )
664
 * @param string $action: char or string with the requested action( r[ead..] / w[rite..] / e|x[ecute..] )
665
 * @return boolean
666
 */
667
function extract_permission($octal_value, $who, $action)
668
{
669
	// Make sure that all arguments are set and $octal_value is a real octal-integer
670
	if( ($who == '') or ($action == '') or (preg_match( '/[^0-7]/', (string)$octal_value )) )
671
	{
672
		return false; // invalid argument, so return false
673
	}
674
	// convert $octal_value into a decimal-integer to be sure having a valid value
675
	$right_mask = octdec($octal_value);
676
	$action_mask = 0;
677
	// set the $action related bit in $action_mask
678
	switch($action[0]) // get action from first char of $action
679
	{
680
		case 'r':
681
		case 'R':
682
			$action_mask = 4; // set read-bit only (2^2)
683
			break;
684
		case 'w':
685
		case 'W':
686
			$action_mask = 2; // set write-bit only (2^1)
687
			break;
688
		case 'e':
689
		case 'E':
690
		case 'x':
691
		case 'X':
692
			$action_mask = 1; // set execute-bit only (2^0)
693
			break;
694
		default:
695
			return false; // undefined action name, so return false
696
	}
697
	// shift action-mask into the right position
698
	switch($who[0]) // get who from first char of $who
699
	{
700
		case 'u':
701
		case 'U':
702
			$action_mask <<= 3; // shift left 3 bits
703
		case 'g':
704
		case 'G':
705
			$action_mask <<= 3; // shift left 3 bits
706
		case 'o':
707
		case 'O':
708
			/* NOP */
709
			break;
710
		default:
711
			return false; // undefined who, so return false
712
	}
713
	return( ($right_mask & $action_mask) != 0 ); // return result of binary-AND
714
}
715

  
716
// Function to delete a page
717
function delete_page($page_id)
718
{
719
	global $admin, $database, $MESSAGE;
720
	// Find out more about the page
721
	$database = new database();
722
	$sql  = 'SELECT `page_id`, `menu_title`, `page_title`, `level`, `link`, `parent`, `modified_by`, `modified_when` ';
723
	$sql .= 'FROM `'.TABLE_PREFIX.'pages` WHERE `page_id` = '.$page_id;
724
	$results = $database->query($sql);
725
	if($database->is_error())    { $admin->print_error($database->get_error()); }
726
	if($results->numRows() == 0) { $admin->print_error($MESSAGE['PAGES']['NOT_FOUND']); }
727
	$results_array = $results->fetchRow();
728
	$parent     = $results_array['parent'];
729
	$level      = $results_array['level'];
730
	$link       = $results_array['link'];
731
	$page_title = $results_array['page_title'];
732
	$menu_title = $results_array['menu_title'];
733
	
734
	// Get the sections that belong to the page
735
	$sql = 'SELECT `section_id`, `module` FROM `'.TABLE_PREFIX.'sections` WHERE `page_id` = '.$page_id;
736
	$query_sections = $database->query($sql);
737
	if($query_sections->numRows() > 0)
738
	{
739
		while($section = $query_sections->fetchRow())
740
		{
741
			// Set section id
742
			$section_id = $section['section_id'];
743
			// Include the modules delete file if it exists
744
			if(file_exists(WB_PATH.'/modules/'.$section['module'].'/delete.php'))
745
			{
746
				include(WB_PATH.'/modules/'.$section['module'].'/delete.php');
747
			}
748
		}
749
	}
750
	// Update the pages table
751
	$sql = 'DELETE FROM `'.TABLE_PREFIX.'pages` WHERE `page_id` = '.$page_id;
752
	$database->query($sql);
753
	if($database->is_error())
754
	{
755
		$admin->print_error($database->get_error());
756
	}
757
	// Update the sections table
758
	$sql = 'DELETE FROM `'.TABLE_PREFIX.'sections` WHERE `page_id` = '.$page_id;
759
	$database->query($sql);
760
	if($database->is_error()) {
761
		$admin->print_error($database->get_error());
762
	}
763
	// Include the ordering class or clean-up ordering
764
	include_once(WB_PATH.'/framework/class.order.php');
765
	$order = new order(TABLE_PREFIX.'pages', 'position', 'page_id', 'parent');
766
	$order->clean($parent);
767
	// Unlink the page access file and directory
768
	$directory = WB_PATH.PAGES_DIRECTORY.$link;
769
	$filename = $directory.PAGE_EXTENSION;
770
	$directory .= '/';
771
	if(file_exists($filename))
772
	{
773
		if(!is_writable(WB_PATH.PAGES_DIRECTORY.'/'))
774
		{
775
			$admin->print_error($MESSAGE['PAGES']['CANNOT_DELETE_ACCESS_FILE']);
776
		}
777
		else
778
		{
779
			unlink($filename);
780
			if( file_exists($directory) &&
781
			   (rtrim($directory,'/') != WB_PATH.PAGES_DIRECTORY) &&
782
			   (substr($link, 0, 1) != '.'))
783
			{
784
				rm_full_dir($directory);
785
			}
786
		}
787
	}
788
}
789

  
790
// Load module into DB
791
function load_module($directory, $install = false)
792
{
793
	global $database,$admin,$MESSAGE;
794

  
795
	if(is_dir($directory) AND file_exists($directory.'/info.php'))
796
	{
797
		require($directory.'/info.php');
798
		if(isset($module_name))
799
		{
800
			if(!isset($module_license))                                  { $module_license = 'GNU General Public License'; }
801
			if(!isset($module_platform) AND isset($module_designed_for)) { $module_platform = $module_designed_for; }
802
			if(!isset($module_function) AND isset($module_type))         { $module_function = $module_type; }
803
			$module_function = strtolower($module_function);
804
			// Check that it doesn't already exist
805
			$sql  = 'SELECT `addon_id` FROM `'.TABLE_PREFIX.'addons` ';
806
			$sql .= 'WHERE `type` = "module" AND `directory` = "'.$module_directory.'" LIMIT 0,1';
807
			$result = $database->query($sql);
808
			if($result->numRows() == 0)
809
			{
810
				// Load into DB
811
				$sql  = 'INSERT INTO `'.TABLE_PREFIX.'addons` SET ';
812
				$sql .= '`directory` = "'.$module_directory.'", ';
813
				$sql .= '`name` = "'.$module_name.'", ';
814
				$sql .= '`description`= "'.addslashes($module_description).'", ';
815
				$sql .= '`type`= "module", ';
816
				$sql .= '`function` = "'.$module_function.'", ';
817
				$sql .= '`version` = "'.$module_version.'", ';
818
				$sql .= '`platform` = "'.$module_platform.'", ';
819
				$sql .= '`author` = "'.addslashes($module_author).'", ';
820
				$sql .= '`license` = "'.addslashes($module_license).'"';
821
				$database->query($sql);
822
				// Run installation script
823
				if($install == true)
824
				{
825
					if(file_exists($directory.'/install.php'))
826
					{
827
						require($directory.'/install.php');
828
					}
829
				}
830
			}
831
		}
832
	}
833
}
834

  
835
// Load template into DB
836
function load_template($directory)
837
{
838
	global $database, $admin;
839
	if(is_dir($directory) AND file_exists($directory.'/info.php'))
840
	{
841
		require($directory.'/info.php');
842
		if(isset($template_name))
843
		{
844
			if(!isset($template_license))
845
            {
846
              $template_license = 'GNU General Public License';
847
            }
848
			if(!isset($template_platform) AND isset($template_designed_for))
849
            {
850
              $template_platform = $template_designed_for;
851
            }
852
			if(!isset($template_function))
853
            {
854
              $template_function = 'template';
855
            }
856
			// Check that it doesn't already exist
857
			$sql  = 'SELECT `addon_id` FROM `'.TABLE_PREFIX.'addons` ';
858
			$sql .= 'WHERE `type` = "template" AND `directory` = "'.$template_directory.'" LIMIT 0,1';
859
			$result = $database->query($sql);
860
			if($result->numRows() == 0)
861
			{
862
				// Load into DB
863
				$sql  = 'INSERT INTO `'.TABLE_PREFIX.'addons` SET ';
864
				$sql .= '`directory` = "'.$template_directory.'", ';
865
				$sql .= '`name` = "'.$template_name.'", ';
866
				$sql .= '`description`= "'.addslashes($template_description).'", ';
867
				$sql .= '`type`= "template", ';
868
				$sql .= '`function` = "'.$template_function.'", ';
869
				$sql .= '`version` = "'.$template_version.'", ';
870
				$sql .= '`platform` = "'.$template_platform.'", ';
871
				$sql .= '`author` = "'.addslashes($template_author).'", ';
872
				$sql .= '`license` = "'.addslashes($template_license).'" ';
873
				$database->query($sql);
874
			}
875
		}
876
	}
877
}
878

  
879
// Load language into DB
880
function load_language($file)
881
{
882
	global $database,$admin;
883
	if (file_exists($file) && preg_match('#^([A-Z]{2}.php)#', basename($file)))
884
	{
885
		require($file);
886
		if(isset($language_name))
887
		{
888
			if(!isset($language_license))                                    { $language_license = 'GNU General Public License'; }
889
			if(!isset($language_platform) AND isset($language_designed_for)) { $language_platform = $language_designed_for; }
890
			// Check that it doesn't already exist
891
			$sql  = 'SELECT `addon_id` FROM `'.TABLE_PREFIX.'addons` ';
892
			$sql .= 'WHERE `type` = "language" AND `directory` = "'.$language_code.'" LIMIT 0,1';
893
			$result = $database->query($sql);
894
			if($result->numRows() == 0)
895
			{
896
				// Load into DB
897
				$sql  = 'INSERT INTO `'.TABLE_PREFIX.'addons` SET ';
898
				$sql .= '`directory` = "'.$language_code.'", ';
899
				$sql .= '`name` = "'.$language_name.'", ';
900
				$sql .= '`type`= "language", ';
901
				$sql .= '`version` = "'.$language_version.'", ';
902
				$sql .= '`platform` = "'.$language_platform.'", ';
903
				$sql .= '`author` = "'.addslashes($language_author).'", ';
904
				$sql .= '`license` = "'.addslashes($language_license).'"';
905
				$database->query($sql);
906
			}
907
		}
908
	}
909
}
910

  
911
// Upgrade module info in DB, optionally start upgrade script
912
function upgrade_module($directory, $upgrade = false)
913
{
914
	global $database, $admin, $MESSAGE;
915
	$directory = WB_PATH.'/modules/'.$directory;
916
	if(file_exists($directory.'/info.php'))
917
	{
918
		require($directory.'/info.php');
919
		if(isset($module_name))
920
		{
921
			if(!isset($module_license))                                  { $module_license = 'GNU General Public License'; }
922
			if(!isset($module_platform) AND isset($module_designed_for)) { $module_platform = $module_designed_for; }
923
			if(!isset($module_function) AND isset($module_type))         { $module_function = $module_type; }
924
			$module_function = strtolower($module_function);
925
			// Check that it does already exist
926
			$sql  = 'SELECT `addon_id` FROM `'.TABLE_PREFIX.'addons` ';
927
			$sql .= 'WHERE `directory` = "'.$module_directory.'" LIMIT 0,1';
928
			$result = $database->query($sql);
929
			if($result->numRows() > 0)
930
			{
931
				// Update in DB
932
				$sql  = 'UPDATE `'.TABLE_PREFIX.'addons` SET ';
933
				$sql .= '`version` = "'.$module_version.'", ';
934
				$sql .= '`description` = "'.addslashes($module_description).'", ';
935
				$sql .= '`platform` = "'.$module_platform.'", ';
936
				$sql .= '`author` = "'.addslashes($module_author).'", ';
937
				$sql .= '`license` = "'.addslashes($module_license).'" ';
938
				$sql .= 'WHERE `directory` = "'.$module_directory.'"';
939
				$database->query($sql);
940
				// Run upgrade script
941
				if($upgrade == true)
942
				{
943
					if(file_exists($directory.'/upgrade.php'))
944
					{
945
						require($directory.'/upgrade.php');
946
					}
947
				}
948
			}
949
		}
950
	}
951
}
952

  
953
// extracts the content of a string variable from a string (save alternative to including files)
954
if(!function_exists('get_variable_content'))
955
{
956
	function get_variable_content($search, $data, $striptags=true, $convert_to_entities=true)
957
	{
958
		$match = '';
959
		// search for $variable followed by 0-n whitespace then by = then by 0-n whitespace
960
		// then either " or ' then 0-n characters then either " or ' followed by 0-n whitespace and ;
961
		// the variable name is returned in $match[1], the content in $match[3]
962
		if (preg_match('/(\$' .$search .')\s*=\s*("|\')(.*)\2\s*;/', $data, $match))
963
		{
964
			if(strip_tags(trim($match[1])) == '$' .$search)
965
			{
966
				// variable name matches, return it's value
967
				$match[3] = ($striptags == true) ? strip_tags($match[3]) : $match[3];
968
				$match[3] = ($convert_to_entities == true) ? htmlentities($match[3]) : $match[3];
969
				return $match[3];
970
			}
971
		}
972
		return false;
973
	}
974
}
975

  
976
?>
1
<?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('<'=>'&lt;', '>'=>'&gt;', '&'=>'&amp;', '"'=>'&quot;', '\''=>'&#39;'));
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 &gt; &lt; &apos; &quot; &#039; &nbsp;
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);
... This diff was truncated because it exceeds the maximum size that can be displayed.

Also available in: Unified diff