Project

General

Profile

1
<?php
2

    
3
// $Id: functions.php 249 2005-11-26 08:33:10Z stefan $
4

    
5
/*
6

    
7
 Website Baker Project <http://www.websitebaker.org/>
8
 Copyright (C) 2004-2005, Ryan Djurovich
9

    
10
 Website Baker is free software; you can redistribute it and/or modify
11
 it under the terms of the GNU General Public License as published by
12
 the Free Software Foundation; either version 2 of the License, or
13
 (at your option) any later version.
14

    
15
 Website Baker is distributed in the hope that it will be useful,
16
 but WITHOUT ANY WARRANTY; without even the implied warranty of
17
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18
 GNU General Public License for more details.
19

    
20
 You should have received a copy of the GNU General Public License
21
 along with Website Baker; if not, write to the Free Software
22
 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
23

    
24
*/
25

    
26
/*
27

    
28
Website Baker functions file
29
This file contains general functions used in Website Baker
30

    
31
*/
32

    
33
// Stop this file from being accessed directly
34
if(!defined('WB_URL')) {
35
	header('Location: ../index.php');
36
}
37

    
38
// Define that this file has been loaded
39
define('FUNCTIONS_FILE_LOADED', true);
40

    
41
// Function to remove a non-empty directory
42
function rm_full_dir($directory)
43
{
44
    // If suplied dirname is a file then unlink it
45
    if (is_file($directory)) {
46
        return unlink($directory);
47
    }
48

    
49
    // Empty the folder
50
    $dir = dir($directory);
51
    while (false !== $entry = $dir->read()) {
52
        // Skip pointers
53
        if ($entry == '.' || $entry == '..') {
54
            continue;
55
        }
56

    
57
        // Deep delete directories      
58
        if (is_dir("$directory/$entry")) {
59
            rm_full_dir("$directory/$entry");
60
        } else {
61
            unlink("$directory/$entry");
62
        }
63
    }
64

    
65
    // Now delete the folder
66
    $dir->close();
67
    return rmdir($directory);
68
}
69

    
70
// Function to open a directory and add to a dir list
71
function directory_list($directory) {
72
	
73
	$list = array();
74

    
75
	// Open the directory then loop through its contents
76
	$dir = dir($directory);
77
	while (false !== $entry = $dir->read()) {
78
		// Skip pointers
79
		if(substr($entry, 0, 1) == '.' || $entry == '.svn') {
80
			continue;
81
		}
82
		// Add dir and contents to list
83
		if (is_dir("$directory/$entry")) {
84
			$list = array_merge($list, directory_list("$directory/$entry"));
85
			$list[] = "$directory/$entry";
86
		}
87
	}
88

    
89
	// Now return the list
90
	return $list;
91
}
92

    
93
// Function to open a directory and add to a dir list
94
function chmod_directory_contents($directory, $file_mode) {
95
	
96
	// Set the umask to 0
97
	$umask = umask(0);
98
	
99
	// Open the directory then loop through its contents
100
	$dir = dir($directory);
101
	while (false !== $entry = $dir->read()) {
102
		// Skip pointers
103
		if(substr($entry, 0, 1) == '.' || $entry == '.svn') {
104
			continue;
105
		}
106
		// Chmod the sub-dirs contents
107
		if(is_dir("$directory/$entry")) {
108
			chmod_directory_contents("$directory/$entry", $file_mode);
109
		}
110
		change_mode($directory.'/'.$entry, 'file');
111
	}
112
	
113
	// Restore the umask
114
	umask($umask);
115

    
116
}
117

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

    
148
	// Now delete the folder
149
	return $list;
150
}
151

    
152
// Function to get a list of home folders not to show
153
function get_home_folders() {
154
	global $database, $admin;
155
	$home_folders = array();
156
	// Only return home folders is this feature is enabled
157
	if(HOME_FOLDERS) {
158
		$query_home_folders = $database->query("SELECT home_folder FROM ".TABLE_PREFIX."users WHERE home_folder != '".$admin->get_home_folder()."'");
159
		if($query_home_folders->numRows() > 0) {
160
			while($folder = $query_home_folders->fetchRow()) {
161
				$home_folders[$folder['home_folder']] = $folder['home_folder'];
162
			}
163
		}
164
		function remove_home_subs($directory = '/', $home_folders) {
165
			if($handle = opendir(WB_PATH.MEDIA_DIRECTORY.$directory)) {
166
				// Loop through the dirs to check the home folders sub-dirs are not shown
167
			   while(false !== ($file = readdir($handle))) {
168
					if(substr($file, 0, 1) != '.' AND $file != '.svn' AND $file != 'index.php') {
169
						if(is_dir(WB_PATH.MEDIA_DIRECTORY.$directory.'/'.$file)) {
170
							if($directory != '/') { $file = $directory.'/'.$file; } else { $file = '/'.$file; }
171
							foreach($home_folders AS $hf) {
172
								$hf_length = strlen($hf);
173
								if($hf_length > 0) {
174
									if(substr($file, 0, $hf_length+1) == $hf) {
175
										$home_folders[$file] = $file;
176
									}
177
								}
178
							}
179
							$home_folders = remove_home_subs($file, $home_folders);
180
						}
181
					}
182
				}
183
			}
184
			return $home_folders;
185
		}
186
		$home_folders = remove_home_subs('/', $home_folders);
187
	}
188
	return $home_folders;
189
}
190

    
191
// Function to create directories
192
function make_dir($dir_name, $dir_mode = OCTAL_DIR_MODE) {
193
	if(!file_exists($dir_name)) {
194
		$umask = umask(0);
195
		mkdir($dir_name, $dir_mode);
196
		umask($umask);
197
		return true;
198
	} else {
199
		return false;	
200
	}
201
}
202

    
203
// Function to chmod files and directories
204
function change_mode($name) {
205
	if(OPERATING_SYSTEM != 'windows') {
206
		// Only chmod if os is not windows
207
		if(is_dir($name)) {
208
			$mode = OCTAL_DIR_MODE;
209
		} else {
210
			$mode = OCTAL_FILE_MODE;
211
		}
212
		if(file_exists($name)) {
213
			$umask = umask(0);
214
			chmod($name, $mode);
215
			umask($umask);
216
			return true;
217
		} else {
218
			return false;	
219
		}
220
	} else {
221
		return true;
222
	}
223
}
224

    
225
// Function to figure out if a parent exists
226
function is_parent($page_id) {
227
	global $database;
228
	// Get parent
229
	$query = $database->query("SELECT parent FROM ".TABLE_PREFIX."pages WHERE page_id = '$page_id'");
230
	$fetch = $query->fetchRow();
231
	// If parent isnt 0 return its ID
232
	if($fetch['parent'] == '0') {
233
		return false;
234
	} else {
235
		return $fetch['parent'];
236
	}
237
}
238

    
239
// Function to work out level
240
function level_count($page_id) {
241
	global $database;
242
	// Get page parent
243
	$query_page = $database->query("SELECT parent FROM ".TABLE_PREFIX."pages WHERE page_id = '$page_id' LIMIT 1");
244
	$fetch_page = $query_page->fetchRow();
245
	$parent = $fetch_page['parent'];
246
	if($parent > 0) {
247
		// Get the level of the parent
248
		$query_parent = $database->query("SELECT level FROM ".TABLE_PREFIX."pages WHERE page_id = '$parent' LIMIT 1");
249
		$fetch_parent = $query_parent->fetchRow();
250
		$level = $fetch_parent['level'];
251
		return $level+1;
252
	} else {
253
		return 0;
254
	}
255
}
256

    
257
// Function to work out root parent
258
function root_parent($page_id) {
259
	global $database;
260
	// Get page details
261
	$query_page = $database->query("SELECT parent,level FROM ".TABLE_PREFIX."pages WHERE page_id = '$page_id' LIMIT 1");
262
	$fetch_page = $query_page->fetchRow();
263
	$parent = $fetch_page['parent'];
264
	$level = $fetch_page['level'];	
265
	if($level == 1) {
266
		return $parent;
267
	} elseif($parent == 0) {
268
		return 0;
269
	} else {
270
		// Figure out what the root parents id is
271
		$parent_ids = array_reverse(get_parent_ids($page_id));
272
		return $parent_ids[0];
273
	}
274
}
275

    
276
// Function to get page title
277
function get_page_title($id) {
278
	global $database;
279
	// Get title
280
	$query = $database->query("SELECT page_title FROM ".TABLE_PREFIX."pages WHERE page_id = '$id'");
281
	$fetch = $query->fetchRow();
282
	// Return title
283
	return $fetch['page_title'];
284
}
285

    
286
// Function to get a pages menu title
287
function get_menu_title($id) {
288
	// Connect to the database
289
	$database = new database();
290
	// Get title
291
	$query = $database->query("SELECT menu_title FROM ".TABLE_PREFIX."pages WHERE page_id = '$id'");
292
	$fetch = $query->fetchRow();
293
	// Return title
294
	return $fetch['menu_title'];
295
}
296

    
297
// Function to get all parent page titles
298
function get_parent_titles($parent_id) {
299
	$titles[] = get_menu_title($parent_id);
300
	if(is_parent($parent_id) != false) {
301
		$parent_titles = get_parent_titles(is_parent($parent_id));
302
		$titles = array_merge($titles, $parent_titles);
303
	}
304
	return $titles;
305
}
306

    
307
// Function to get all parent page id's
308
function get_parent_ids($parent_id) {
309
	$ids[] = $parent_id;
310
	if(is_parent($parent_id) != false) {
311
		$parent_ids = get_parent_ids(is_parent($parent_id));
312
		$ids = array_merge($ids, $parent_ids);
313
	}
314
	return $ids;
315
}
316

    
317
// Function to genereate page trail
318
function get_page_trail($page_id) {
319
	return implode(',', array_reverse(get_parent_ids($page_id)));
320
}
321

    
322
// Function to get all sub pages id's
323
function get_subs($parent, $subs) {
324
	// Connect to the database
325
	$database = new database();
326
	// Get id's
327
	$query = $database->query("SELECT page_id FROM ".TABLE_PREFIX."pages WHERE parent = '$parent'");
328
	if($query->numRows() > 0) {
329
		while($fetch = $query->fetchRow()) {
330
			$subs[] = $fetch['page_id'];
331
			// Get subs of this sub
332
			$subs = get_subs($fetch['page_id'], $subs);
333
		}
334
	}
335
	// Return subs array
336
	return $subs;
337
}
338

    
339
// Function to convert a page title to a page filename
340
function page_filename($string) {
341
	// First, translate any non-english characters to their english equivalents
342
	require(WB_PATH.'/framework/convert.php');
343
   $string = strtr($string, $conversion_array);
344
	// Now replace spaces with page spcacer
345
	$string = str_replace(' ', PAGE_SPACER, $string);
346
	// Now remove all bad characters
347
	$bad = array(
348
	'\'', /* /  */ '"', /* " */	'<', /* < */	'>', /* > */
349
	'{', /* { */	'}', /* } */	'[', /* [ */	']', /* ] */	'`', /* ` */
350
	'!', /* ! */	'@', /* @ */	'#', /* # */	'$', /* $ */	'%', /* % */
351
	'^', /* ^ */	'&', /* & */	'*', /* * */	'(', /* ( */	')', /* ) */
352
	'=', /* = */	'+', /* + */	'|', /* | */	'/', /* / */	'\\', /* \ */
353
	';', /* ; */	':', /* : */	',', /* , */	'?' /* ? */
354
	);
355
	$string = str_replace($bad, '', $string);
356
	// Now convert to lower-case
357
	$string = strtolower($string);
358
	// Now remove multiple page spacers
359
	$string = str_replace(PAGE_SPACER.PAGE_SPACER, PAGE_SPACER, $string);
360
	// Clean any page spacers at the end of string
361
	$string = str_replace(PAGE_SPACER, ' ', $string);
362
	$string = trim($string);
363
	$string = str_replace(' ', PAGE_SPACER, $string);
364
	// If there are any weird language characters, this will protect us against possible problems they could cause
365
	$string = str_replace(array('%2F', '%'), array('/', ''), urlencode($string));
366
	// Finally, return the cleaned string
367
	return $string;
368
}
369

    
370
// Function to convert a desired media filename to a clean filename
371
function media_filename($string) {
372
	// First, translate any non-english characters to their english equivalents
373
	require(WB_PATH.'/framework/convert.php');
374
   $string = strtr($string, $conversion_array);
375
	// Now remove all bad characters
376
	$bad = array(
377
	'\'', // '
378
	'"', // "
379
	'`', // `
380
	'!', // !
381
	'@', // @
382
	'#', // #
383
	'$', // $
384
	'%', // %
385
	'^', // ^
386
	'&', // &
387
	'*', // *
388
	'=', // =
389
	'+', // +
390
	'|', // |
391
	'/', // /
392
	'\\', // \
393
	';', // ;
394
	':', // :
395
	',', // ,
396
	'?' // ?
397
	);
398
	$string = str_replace($bad, '', $string);
399
	// Clean any page spacers at the end of string
400
	$string = trim($string);
401
	// Finally, return the cleaned string
402
	return $string;
403
}
404

    
405
// Function to work out a page link
406
if(!function_exists('page_link')) {
407
	function page_link($link) {
408
		global $admin;
409
		return $admin->page_link($link);
410
	}
411
}
412

    
413
// Create a new file in the pages directory
414
function create_access_file($filename,$page_id,$level) {
415
	global $admin;
416
	if(!is_writable(WB_PATH.PAGES_DIRECTORY.'/')) {
417
		$admin->print_error($MESSAGE['PAGES']['CANNOT_CREATE_ACCESS_FILE']);
418
	} else {
419
		// First make sure parent folder exists
420
		$parent_folders = explode('/',str_replace(WB_PATH.PAGES_DIRECTORY, '', dirname($filename)));
421
		$parents = '';
422
		foreach($parent_folders AS $parent_folder) {
423
			if($parent_folder != '/' AND $parent_folder != '') {
424
				$parents .= '/'.$parent_folder;
425
				if(!file_exists(WB_PATH.PAGES_DIRECTORY.$parents)) {
426
					make_dir(WB_PATH.PAGES_DIRECTORY.$parents);
427
				}
428
			}	
429
		}
430
		// The depth of the page directory in the directory hierarchy
431
		// '/pages' is at depth 1
432
		$pages_dir_depth=count(explode('/',PAGES_DIRECTORY))-1;
433
		// Work-out how many ../'s we need to get to the index page
434
		$index_location = '';
435
		for($i = 0; $i < $level + $pages_dir_depth; $i++) {
436
			$index_location .= '../';
437
		}
438
		$content = ''.
439
'<?php
440
$page_id = '.$page_id.';
441
require("'.$index_location.'config.php");
442
require(WB_PATH."/index.php");
443
?>';
444
		$handle = fopen($filename, 'w');
445
		fwrite($handle, $content);
446
		fclose($handle);
447
		// Chmod the file
448
		change_mode($filename, 'file');
449
	}
450
}
451

    
452
// Function for working out a file mime type (if the in-built PHP one is not enabled)
453
if(!function_exists('mime_content_type')) {
454
   function mime_content_type($file) {
455
       $file = escapeshellarg($file);
456
       return trim(`file -bi $file`);
457
   }
458
}
459

    
460
// Generate a thumbnail from an image
461
function make_thumb($source, $destination, $size) {
462
	// Check if GD is installed
463
	if(extension_loaded('gd') AND function_exists('imageCreateFromJpeg')) {
464
		// First figure out the size of the thumbnail
465
		list($original_x, $original_y) = getimagesize($source);
466
		if ($original_x > $original_y) {
467
			$thumb_w = $size;
468
			$thumb_h = $original_y*($size/$original_x);
469
		}
470
		if ($original_x < $original_y) {
471
			$thumb_w = $original_x*($size/$original_y);
472
			$thumb_h = $size;
473
		}
474
		if ($original_x == $original_y) {
475
			$thumb_w = $size;
476
			$thumb_h = $size;	
477
		}
478
		// Now make the thumbnail
479
		$source = imageCreateFromJpeg($source);
480
		$dst_img = ImageCreateTrueColor($thumb_w, $thumb_h);
481
		imagecopyresampled($dst_img,$source,0,0,0,0,$thumb_w,$thumb_h,$original_x,$original_y);
482
		imagejpeg($dst_img, $destination);
483
		// Clear memory
484
		imagedestroy($dst_img);
485
	   imagedestroy($source);
486
	   // Return true
487
	   return true;
488
   } else {
489
   	return false;
490
   }
491
}
492

    
493
// Function to work-out a single part of an octal permission value
494
function extract_permission($octal_value, $who, $action) {
495
	// Make sure the octal value is 4 chars long
496
	if(strlen($octal_value) == 0) {
497
		$octal_value = '0000';
498
	} elseif(strlen($octal_value) == 1) {
499
		$octal_value = '000'.$octal_value;
500
	} elseif(strlen($octal_value) == 2) {
501
		$octal_value = '00'.$octal_value;
502
	} elseif(strlen($octal_value) == 3) {
503
		$octal_value = '0'.$octal_value;
504
	} elseif(strlen($octal_value) == 4) {
505
		$octal_value = ''.$octal_value;
506
	} else {
507
		$octal_value = '0000';
508
	}
509
	// Work-out what position of the octal value to look at
510
	switch($who) {
511
	case 'u':
512
		$position = '1';
513
		break;
514
	case 'user':
515
		$position = '1';
516
		break;
517
	case 'g':
518
		$position = '2';
519
		break;
520
	case 'group':
521
		$position = '2';
522
		break;
523
	case 'o':
524
		$position = '3';
525
		break;
526
	case 'others':
527
		$position = '3';
528
		break;
529
	}
530
	// Work-out how long the octal value is and ajust acording
531
	if(strlen($octal_value) == 4) {
532
		$position = $position+1;
533
	} elseif(strlen($octal_value) != 3) {
534
		exit('Error');
535
	}
536
	// Now work-out what action the script is trying to look-up
537
	switch($action) {
538
	case 'r':
539
		$action = 'r';
540
		break;
541
	case 'read':
542
		$action = 'r';
543
		break;
544
	case 'w':
545
		$action = 'w';
546
		break;
547
	case 'write':
548
		$action = 'w';
549
		break;
550
	case 'e':
551
		$action = 'e';
552
		break;
553
	case 'execute':
554
		$action = 'e';
555
		break;
556
	}
557
	// Get the value for "who"
558
	$value = substr($octal_value, $position-1, 1);
559
	// Now work-out the details of the value
560
	switch($value) {
561
	case '0':
562
		$r = false;
563
		$w = false;
564
		$e = false;
565
		break;
566
	case '1':
567
		$r = false;
568
		$w = false;
569
		$e = true;
570
		break;
571
	case '2':
572
		$r = false;
573
		$w = true;
574
		$e = false;
575
		break;
576
	case '3':
577
		$r = false;
578
		$w = true;
579
		$e = true;
580
		break;
581
	case '4':
582
		$r = true;
583
		$w = false;
584
		$e = false;
585
		break;
586
	case '5':
587
		$r = true;
588
		$w = false;
589
		$e = true;
590
		break;
591
	case '6':
592
		$r = true;
593
		$w = true;
594
		$e = false;
595
		break;
596
	case '7':
597
		$r = true;
598
		$w = true;
599
		$e = true;
600
		break;
601
	default:
602
		$r = false;
603
		$w = false;
604
		$e = false;
605
	}
606
	// And finally, return either true or false
607
	return $$action;
608
}
609

    
610
// Function to delete a page
611
function delete_page($page_id) {
612
	
613
	global $admin, $database;
614
	
615
	// Find out more about the page
616
	$database = new database();
617
	$query = "SELECT page_id,menu_title,page_title,level,link,parent,modified_by,modified_when FROM ".TABLE_PREFIX."pages WHERE page_id = '$page_id'";
618
	$results = $database->query($query);
619
	if($database->is_error()) {
620
		$admin->print_error($database->get_error());
621
	}
622
	if($results->numRows() == 0) {
623
		$admin->print_error($MESSAGE['PAGES']['NOT_FOUND']);
624
	}
625
	$results_array = $results->fetchRow();
626
	$parent = $results_array['parent'];
627
	$level = $results_array['level'];
628
	$link = $results_array['link'];
629
	$page_title = ($results_array['page_title']);
630
	$menu_title = ($results_array['menu_title']);
631
	
632
	// Get the sections that belong to the page
633
	$query_sections = $database->query("SELECT section_id,module FROM ".TABLE_PREFIX."sections WHERE page_id = '$page_id'");
634
	if($query_sections->numRows() > 0) {
635
		while($section = $query_sections->fetchRow()) {
636
			// Set section id
637
			$section_id = $section['section_id'];
638
			// Include the modules delete file if it exists
639
			if(file_exists(WB_PATH.'/modules/'.$section['module'].'/delete.php')) {
640
				require(WB_PATH.'/modules/'.$section['module'].'/delete.php');
641
			}
642
		}
643
	}
644
	
645
	// Update the pages table
646
	$query = "DELETE FROM ".TABLE_PREFIX."pages WHERE page_id = '$page_id'";
647
	$database->query($query);
648
	if($database->is_error()) {
649
		$admin->print_error($database->get_error());
650
	}
651
	
652
	// Update the sections table
653
	$query = "DELETE FROM ".TABLE_PREFIX."sections WHERE page_id = '$page_id'";
654
	$database->query($query);
655
	if($database->is_error()) {
656
		$admin->print_error($database->get_error());
657
	}
658
	
659
	// Include the ordering class or clean-up ordering
660
	require_once(WB_PATH.'/framework/class.order.php');
661
	$order = new order(TABLE_PREFIX.'pages', 'position', 'page_id', 'parent');
662
	$order->clean($parent);
663
	
664
	// Unlink the page access file and directory
665
	$directory = WB_PATH.PAGES_DIRECTORY.$link;
666
	$filename = $directory.'.php';
667
	$directory .= '/';
668
	if(file_exists($filename)) {
669
		if(!is_writable(WB_PATH.PAGES_DIRECTORY.'/')) {
670
			$admin->print_error($MESSAGE['PAGES']['CANNOT_DELETE_ACCESS_FILE']);
671
		} else {
672
			unlink($filename);
673
			if(file_exists($directory)) {
674
				rm_full_dir($directory);
675
			}
676
		}
677
	}
678
	
679
}
680

    
681
// Load module into DB
682
function load_module($directory, $install = false) {
683
	global $database,$admin,$MESSAGE;
684
	if(file_exists($directory.'/info.php')) {
685
		require($directory.'/info.php');
686
		if(isset($module_name)) {
687
			if(!isset($module_license)) { $module_license = 'GNU General Public License'; }
688
			if(!isset($module_platform) AND isset($module_designed_for)) { $module_platform = $module_designed_for; }
689
			if(!isset($module_function) AND isset($module_type)) { $module_function = $module_type; }
690
			$module_function = strtolower($module_function);
691
			// Check that it doesn't already exist
692
			$result = $database->query("SELECT addon_id FROM ".TABLE_PREFIX."addons WHERE directory = '".$module_directory."' LIMIT 0,1");
693
			if($result->numRows() == 0) {
694
				// Load into DB
695
				$query = "INSERT INTO ".TABLE_PREFIX."addons ".
696
				"(directory,name,description,type,function,version,platform,author,license) ".
697
				"VALUES ('$module_directory','$module_name','".addslashes($module_description)."','module',".
698
				"'$module_function','$module_version','$module_platform','$module_author','$module_license')";
699
				$database->query($query);
700
				// Run installation script
701
				if($install == true) {
702
					if(file_exists($directory.'/install.php')) {
703
						require($directory.'/install.php');
704
					}
705
				}
706
			}
707
		}
708
	}
709
}
710

    
711
// Load template into DB
712
function load_template($directory) {
713
	global $database;
714
	if(file_exists($directory.'/info.php')) {
715
		require($directory.'/info.php');
716
		if(isset($template_name)) {
717
			if(!isset($template_license)) { $template_license = 'GNU General Public License'; }
718
			if(!isset($template_platform) AND isset($template_designed_for)) { $template_platform = $template_designed_for; }
719
			// Check that it doesn't already exist
720
			$result = $database->query("SELECT addon_id FROM ".TABLE_PREFIX."addons WHERE directory = '".$template_directory."' LIMIT 0,1");
721
			if($result->numRows() == 0) {
722
				// Load into DB
723
				$query = "INSERT INTO ".TABLE_PREFIX."addons ".
724
				"(directory,name,description,type,version,platform,author,license) ".
725
				"VALUES ('$template_directory','$template_name','".addslashes($template_description)."','template',".
726
				"'$template_version','$template_platform','$template_author','$template_license')";
727
				$database->query($query);
728
			}
729
		}
730
	}
731
}
732

    
733
// Load language into DB
734
function load_language($file) {
735
	global $database;
736
	if(file_exists($file)) {
737
		require($file);
738
		if(isset($language_name)) {
739
			if(!isset($language_license)) { $language_license = 'GNU General Public License'; }
740
			if(!isset($language_platform) AND isset($language_designed_for)) { $language_platform = $language_designed_for; }
741
			// Check that it doesn't already exist
742
			$result = $database->query("SELECT addon_id FROM ".TABLE_PREFIX."addons WHERE directory = '".$language_code."' LIMIT 0,1");
743
			if($result->numRows() == 0) {
744
				// Load into DB
745
				$query = "INSERT INTO ".TABLE_PREFIX."addons ".
746
				"(directory,name,type,version,platform,author,license) ".
747
				"VALUES ('$language_code','$language_name','language',".
748
				"'$language_version','$language_platform','$language_author','$language_license')";
749
	 		$database->query($query);
750
			}
751
		}
752
	}
753
}
754

    
755
?>
(9-9/11)