Project

General

Profile

1 238 stefan
<?php
2
3
// $Id$
4
5
/*
6
7
 Website Baker Project <http://www.websitebaker.org/>
8 310 ryan
 Copyright (C) 2004-2006, Ryan Djurovich
9 238 stefan
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 286 stefan
	exit(0);
37 238 stefan
}
38
39
// Define that this file has been loaded
40
define('FUNCTIONS_FILE_LOADED', true);
41
42
// Function to remove a non-empty directory
43
function rm_full_dir($directory)
44
{
45
    // If suplied dirname is a file then unlink it
46
    if (is_file($directory)) {
47
        return unlink($directory);
48
    }
49
50
    // Empty the folder
51
    $dir = dir($directory);
52
    while (false !== $entry = $dir->read()) {
53
        // Skip pointers
54
        if ($entry == '.' || $entry == '..') {
55
            continue;
56
        }
57
58
        // Deep delete directories
59
        if (is_dir("$directory/$entry")) {
60
            rm_full_dir("$directory/$entry");
61
        } else {
62
            unlink("$directory/$entry");
63
        }
64
    }
65
66
    // Now delete the folder
67
    $dir->close();
68
    return rmdir($directory);
69
}
70
71
// Function to open a directory and add to a dir list
72
function directory_list($directory) {
73
74
	$list = array();
75
76
	// Open the directory then loop through its contents
77
	$dir = dir($directory);
78
	while (false !== $entry = $dir->read()) {
79
		// Skip pointers
80
		if(substr($entry, 0, 1) == '.' || $entry == '.svn') {
81
			continue;
82
		}
83
		// Add dir and contents to list
84
		if (is_dir("$directory/$entry")) {
85
			$list = array_merge($list, directory_list("$directory/$entry"));
86
			$list[] = "$directory/$entry";
87
		}
88
	}
89
90
	// Now return the list
91
	return $list;
92
}
93
94
// Function to open a directory and add to a dir list
95
function chmod_directory_contents($directory, $file_mode) {
96
97
	// Set the umask to 0
98
	$umask = umask(0);
99
100
	// Open the directory then loop through its contents
101
	$dir = dir($directory);
102
	while (false !== $entry = $dir->read()) {
103
		// Skip pointers
104
		if(substr($entry, 0, 1) == '.' || $entry == '.svn') {
105
			continue;
106
		}
107
		// Chmod the sub-dirs contents
108
		if(is_dir("$directory/$entry")) {
109
			chmod_directory_contents("$directory/$entry", $file_mode);
110
		}
111
		change_mode($directory.'/'.$entry, 'file');
112
	}
113
114
	// Restore the umask
115
	umask($umask);
116
117
}
118
119
// Function to open a directory and add to a file list
120
function file_list($directory, $skip = array()) {
121
122
	$list = array();
123
	$skip_file = false;
124
125
	// Open the directory then loop through its contents
126
	$dir = dir($directory);
127
	while (false !== $entry = $dir->read()) {
128
		// Skip pointers
129
		if($entry == '.' || $entry == '..') {
130
			$skip_file = true;
131
		}
132
		// Check if we to skip anything else
133
		if($skip != array()) {
134
			foreach($skip AS $skip_name) {
135
				if($entry == $skip_name) {
136
					$skip_file = true;
137
				}
138
			}
139
		}
140
		// Add dir and contents to list
141
		if($skip_file != true AND is_file("$directory/$entry")) {
142
			$list[] = "$directory/$entry";
143
		}
144
145
		// Reset the skip file var
146
		$skip_file = false;
147
	}
148
149
	// Now delete the folder
150
	return $list;
151
}
152
153
// Function to get a list of home folders not to show
154
function get_home_folders() {
155
	global $database, $admin;
156
	$home_folders = array();
157
	// Only return home folders is this feature is enabled
158
	if(HOME_FOLDERS) {
159
		$query_home_folders = $database->query("SELECT home_folder FROM ".TABLE_PREFIX."users WHERE home_folder != '".$admin->get_home_folder()."'");
160
		if($query_home_folders->numRows() > 0) {
161
			while($folder = $query_home_folders->fetchRow()) {
162
				$home_folders[$folder['home_folder']] = $folder['home_folder'];
163
			}
164
		}
165
		function remove_home_subs($directory = '/', $home_folders) {
166
			if($handle = opendir(WB_PATH.MEDIA_DIRECTORY.$directory)) {
167
				// Loop through the dirs to check the home folders sub-dirs are not shown
168
			   while(false !== ($file = readdir($handle))) {
169
					if(substr($file, 0, 1) != '.' AND $file != '.svn' AND $file != 'index.php') {
170
						if(is_dir(WB_PATH.MEDIA_DIRECTORY.$directory.'/'.$file)) {
171
							if($directory != '/') { $file = $directory.'/'.$file; } else { $file = '/'.$file; }
172
							foreach($home_folders AS $hf) {
173
								$hf_length = strlen($hf);
174
								if($hf_length > 0) {
175
									if(substr($file, 0, $hf_length+1) == $hf) {
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
	if(!file_exists($dir_name)) {
195
		$umask = umask(0);
196
		mkdir($dir_name, $dir_mode);
197
		umask($umask);
198
		return true;
199
	} else {
200
		return false;
201
	}
202
}
203
204
// Function to chmod files and directories
205
function change_mode($name) {
206
	if(OPERATING_SYSTEM != 'windows') {
207
		// Only chmod if os is not windows
208
		if(is_dir($name)) {
209
			$mode = OCTAL_DIR_MODE;
210
		} else {
211
			$mode = OCTAL_FILE_MODE;
212
		}
213
		if(file_exists($name)) {
214
			$umask = umask(0);
215
			chmod($name, $mode);
216
			umask($umask);
217
			return true;
218
		} else {
219
			return false;
220
		}
221
	} else {
222
		return true;
223
	}
224
}
225
226
// Function to figure out if a parent exists
227
function is_parent($page_id) {
228
	global $database;
229
	// Get parent
230
	$query = $database->query("SELECT parent FROM ".TABLE_PREFIX."pages WHERE page_id = '$page_id'");
231
	$fetch = $query->fetchRow();
232
	// If parent isnt 0 return its ID
233
	if($fetch['parent'] == '0') {
234
		return false;
235
	} else {
236
		return $fetch['parent'];
237
	}
238
}
239
240
// Function to work out level
241
function level_count($page_id) {
242
	global $database;
243
	// Get page parent
244
	$query_page = $database->query("SELECT parent FROM ".TABLE_PREFIX."pages WHERE page_id = '$page_id' LIMIT 1");
245
	$fetch_page = $query_page->fetchRow();
246
	$parent = $fetch_page['parent'];
247
	if($parent > 0) {
248
		// Get the level of the parent
249
		$query_parent = $database->query("SELECT level FROM ".TABLE_PREFIX."pages WHERE page_id = '$parent' LIMIT 1");
250
		$fetch_parent = $query_parent->fetchRow();
251
		$level = $fetch_parent['level'];
252
		return $level+1;
253
	} else {
254
		return 0;
255
	}
256
}
257
258
// Function to work out root parent
259
function root_parent($page_id) {
260
	global $database;
261
	// Get page details
262
	$query_page = $database->query("SELECT parent,level FROM ".TABLE_PREFIX."pages WHERE page_id = '$page_id' LIMIT 1");
263
	$fetch_page = $query_page->fetchRow();
264
	$parent = $fetch_page['parent'];
265
	$level = $fetch_page['level'];
266
	if($level == 1) {
267
		return $parent;
268
	} elseif($parent == 0) {
269
		return 0;
270
	} else {
271
		// Figure out what the root parents id is
272
		$parent_ids = array_reverse(get_parent_ids($page_id));
273
		return $parent_ids[0];
274
	}
275
}
276
277
// Function to get page title
278
function get_page_title($id) {
279
	global $database;
280
	// Get title
281
	$query = $database->query("SELECT page_title FROM ".TABLE_PREFIX."pages WHERE page_id = '$id'");
282
	$fetch = $query->fetchRow();
283
	// Return title
284
	return $fetch['page_title'];
285
}
286
287
// Function to get a pages menu title
288
function get_menu_title($id) {
289
	// Connect to the database
290
	$database = new database();
291
	// Get title
292
	$query = $database->query("SELECT menu_title FROM ".TABLE_PREFIX."pages WHERE page_id = '$id'");
293
	$fetch = $query->fetchRow();
294
	// Return title
295
	return $fetch['menu_title'];
296
}
297
298
// Function to get all parent page titles
299
function get_parent_titles($parent_id) {
300
	$titles[] = get_menu_title($parent_id);
301
	if(is_parent($parent_id) != false) {
302
		$parent_titles = get_parent_titles(is_parent($parent_id));
303
		$titles = array_merge($titles, $parent_titles);
304
	}
305
	return $titles;
306
}
307
308
// Function to get all parent page id's
309
function get_parent_ids($parent_id) {
310
	$ids[] = $parent_id;
311
	if(is_parent($parent_id) != false) {
312
		$parent_ids = get_parent_ids(is_parent($parent_id));
313
		$ids = array_merge($ids, $parent_ids);
314
	}
315
	return $ids;
316
}
317
318
// Function to genereate page trail
319
function get_page_trail($page_id) {
320
	return implode(',', array_reverse(get_parent_ids($page_id)));
321
}
322
323
// Function to get all sub pages id's
324
function get_subs($parent, $subs) {
325
	// Connect to the database
326
	$database = new database();
327
	// Get id's
328
	$query = $database->query("SELECT page_id FROM ".TABLE_PREFIX."pages WHERE parent = '$parent'");
329
	if($query->numRows() > 0) {
330
		while($fetch = $query->fetchRow()) {
331
			$subs[] = $fetch['page_id'];
332
			// Get subs of this sub
333
			$subs = get_subs($fetch['page_id'], $subs);
334
		}
335
	}
336
	// Return subs array
337
	return $subs;
338
}
339
340
// Function to convert a page title to a page filename
341
function page_filename($string) {
342
	// First, translate any non-english characters to their english equivalents
343
	require(WB_PATH.'/framework/convert.php');
344
   $string = strtr($string, $conversion_array);
345
	// Now replace spaces with page spcacer
346
	$string = str_replace(' ', PAGE_SPACER, $string);
347
	// Now remove all bad characters
348
	$bad = array(
349
	'\'', /* /  */ '"', /* " */	'<', /* < */	'>', /* > */
350
	'{', /* { */	'}', /* } */	'[', /* [ */	']', /* ] */	'`', /* ` */
351
	'!', /* ! */	'@', /* @ */	'#', /* # */	'$', /* $ */	'%', /* % */
352
	'^', /* ^ */	'&', /* & */	'*', /* * */	'(', /* ( */	')', /* ) */
353
	'=', /* = */	'+', /* + */	'|', /* | */	'/', /* / */	'\\', /* \ */
354
	';', /* ; */	':', /* : */	',', /* , */	'?' /* ? */
355
	);
356
	$string = str_replace($bad, '', $string);
357
	// Now convert to lower-case
358
	$string = strtolower($string);
359
	// Now remove multiple page spacers
360
	$string = str_replace(PAGE_SPACER.PAGE_SPACER, PAGE_SPACER, $string);
361
	// Clean any page spacers at the end of string
362
	$string = str_replace(PAGE_SPACER, ' ', $string);
363
	$string = trim($string);
364
	$string = str_replace(' ', PAGE_SPACER, $string);
365
	// If there are any weird language characters, this will protect us against possible problems they could cause
366
	$string = str_replace(array('%2F', '%'), array('/', ''), urlencode($string));
367
	// Finally, return the cleaned string
368
	return $string;
369
}
370
371
// Function to convert a desired media filename to a clean filename
372
function media_filename($string) {
373
	// First, translate any non-english characters to their english equivalents
374
	require(WB_PATH.'/framework/convert.php');
375
   $string = strtr($string, $conversion_array);
376
	// Now remove all bad characters
377
	$bad = array(
378
	'\'', // '
379
	'"', // "
380
	'`', // `
381
	'!', // !
382
	'@', // @
383
	'#', // #
384
	'$', // $
385
	'%', // %
386
	'^', // ^
387
	'&', // &
388
	'*', // *
389
	'=', // =
390
	'+', // +
391
	'|', // |
392
	'/', // /
393
	'\\', // \
394
	';', // ;
395
	':', // :
396
	',', // ,
397
	'?' // ?
398
	);
399
	$string = str_replace($bad, '', $string);
400
	// Clean any page spacers at the end of string
401
	$string = trim($string);
402
	// Finally, return the cleaned string
403
	return $string;
404
}
405
406
// Function to work out a page link
407
if(!function_exists('page_link')) {
408
	function page_link($link) {
409 242 stefan
		global $admin;
410
		return $admin->page_link($link);
411 238 stefan
	}
412
}
413
414
// Create a new file in the pages directory
415
function create_access_file($filename,$page_id,$level) {
416
	global $admin;
417
	if(!is_writable(WB_PATH.PAGES_DIRECTORY.'/')) {
418
		$admin->print_error($MESSAGE['PAGES']['CANNOT_CREATE_ACCESS_FILE']);
419
	} else {
420
		// First make sure parent folder exists
421
		$parent_folders = explode('/',str_replace(WB_PATH.PAGES_DIRECTORY, '', dirname($filename)));
422
		$parents = '';
423
		foreach($parent_folders AS $parent_folder) {
424
			if($parent_folder != '/' AND $parent_folder != '') {
425
				$parents .= '/'.$parent_folder;
426
				if(!file_exists(WB_PATH.PAGES_DIRECTORY.$parents)) {
427
					make_dir(WB_PATH.PAGES_DIRECTORY.$parents);
428
				}
429
			}
430
		}
431
		// The depth of the page directory in the directory hierarchy
432
		// '/pages' is at depth 1
433
		$pages_dir_depth=count(explode('/',PAGES_DIRECTORY))-1;
434
		// Work-out how many ../'s we need to get to the index page
435
		$index_location = '';
436
		for($i = 0; $i < $level + $pages_dir_depth; $i++) {
437
			$index_location .= '../';
438
		}
439
		$content = ''.
440
'<?php
441
$page_id = '.$page_id.';
442
require("'.$index_location.'config.php");
443
require(WB_PATH."/index.php");
444
?>';
445
		$handle = fopen($filename, 'w');
446
		fwrite($handle, $content);
447
		fclose($handle);
448
		// Chmod the file
449
		change_mode($filename, 'file');
450
	}
451
}
452
453
// Function for working out a file mime type (if the in-built PHP one is not enabled)
454
if(!function_exists('mime_content_type')) {
455
   function mime_content_type($file) {
456
       $file = escapeshellarg($file);
457
       return trim(`file -bi $file`);
458
   }
459
}
460
461
// Generate a thumbnail from an image
462
function make_thumb($source, $destination, $size) {
463
	// Check if GD is installed
464
	if(extension_loaded('gd') AND function_exists('imageCreateFromJpeg')) {
465
		// First figure out the size of the thumbnail
466
		list($original_x, $original_y) = getimagesize($source);
467
		if ($original_x > $original_y) {
468
			$thumb_w = $size;
469
			$thumb_h = $original_y*($size/$original_x);
470
		}
471
		if ($original_x < $original_y) {
472
			$thumb_w = $original_x*($size/$original_y);
473
			$thumb_h = $size;
474
		}
475
		if ($original_x == $original_y) {
476
			$thumb_w = $size;
477
			$thumb_h = $size;
478
		}
479
		// Now make the thumbnail
480
		$source = imageCreateFromJpeg($source);
481
		$dst_img = ImageCreateTrueColor($thumb_w, $thumb_h);
482
		imagecopyresampled($dst_img,$source,0,0,0,0,$thumb_w,$thumb_h,$original_x,$original_y);
483
		imagejpeg($dst_img, $destination);
484
		// Clear memory
485
		imagedestroy($dst_img);
486
	   imagedestroy($source);
487
	   // Return true
488
	   return true;
489
   } else {
490
   	return false;
491
   }
492
}
493
494
// Function to work-out a single part of an octal permission value
495
function extract_permission($octal_value, $who, $action) {
496
	// Make sure the octal value is 4 chars long
497
	if(strlen($octal_value) == 0) {
498
		$octal_value = '0000';
499
	} elseif(strlen($octal_value) == 1) {
500
		$octal_value = '000'.$octal_value;
501
	} elseif(strlen($octal_value) == 2) {
502
		$octal_value = '00'.$octal_value;
503
	} elseif(strlen($octal_value) == 3) {
504
		$octal_value = '0'.$octal_value;
505
	} elseif(strlen($octal_value) == 4) {
506
		$octal_value = ''.$octal_value;
507
	} else {
508
		$octal_value = '0000';
509
	}
510
	// Work-out what position of the octal value to look at
511
	switch($who) {
512
	case 'u':
513
		$position = '1';
514
		break;
515
	case 'user':
516
		$position = '1';
517
		break;
518
	case 'g':
519
		$position = '2';
520
		break;
521
	case 'group':
522
		$position = '2';
523
		break;
524
	case 'o':
525
		$position = '3';
526
		break;
527
	case 'others':
528
		$position = '3';
529
		break;
530
	}
531
	// Work-out how long the octal value is and ajust acording
532
	if(strlen($octal_value) == 4) {
533
		$position = $position+1;
534
	} elseif(strlen($octal_value) != 3) {
535
		exit('Error');
536
	}
537
	// Now work-out what action the script is trying to look-up
538
	switch($action) {
539
	case 'r':
540
		$action = 'r';
541
		break;
542
	case 'read':
543
		$action = 'r';
544
		break;
545
	case 'w':
546
		$action = 'w';
547
		break;
548
	case 'write':
549
		$action = 'w';
550
		break;
551
	case 'e':
552
		$action = 'e';
553
		break;
554
	case 'execute':
555
		$action = 'e';
556
		break;
557
	}
558
	// Get the value for "who"
559
	$value = substr($octal_value, $position-1, 1);
560
	// Now work-out the details of the value
561
	switch($value) {
562
	case '0':
563
		$r = false;
564
		$w = false;
565
		$e = false;
566
		break;
567
	case '1':
568
		$r = false;
569
		$w = false;
570
		$e = true;
571
		break;
572
	case '2':
573
		$r = false;
574
		$w = true;
575
		$e = false;
576
		break;
577
	case '3':
578
		$r = false;
579
		$w = true;
580
		$e = true;
581
		break;
582
	case '4':
583
		$r = true;
584
		$w = false;
585
		$e = false;
586
		break;
587
	case '5':
588
		$r = true;
589
		$w = false;
590
		$e = true;
591
		break;
592
	case '6':
593
		$r = true;
594
		$w = true;
595
		$e = false;
596
		break;
597
	case '7':
598
		$r = true;
599
		$w = true;
600
		$e = true;
601
		break;
602
	default:
603
		$r = false;
604
		$w = false;
605
		$e = false;
606
	}
607
	// And finally, return either true or false
608
	return $$action;
609
}
610
611
// Function to delete a page
612
function delete_page($page_id) {
613
614
	global $admin, $database;
615
616
	// Find out more about the page
617
	$database = new database();
618
	$query = "SELECT page_id,menu_title,page_title,level,link,parent,modified_by,modified_when FROM ".TABLE_PREFIX."pages WHERE page_id = '$page_id'";
619
	$results = $database->query($query);
620
	if($database->is_error()) {
621
		$admin->print_error($database->get_error());
622
	}
623
	if($results->numRows() == 0) {
624
		$admin->print_error($MESSAGE['PAGES']['NOT_FOUND']);
625
	}
626
	$results_array = $results->fetchRow();
627
	$parent = $results_array['parent'];
628
	$level = $results_array['level'];
629
	$link = $results_array['link'];
630
	$page_title = ($results_array['page_title']);
631
	$menu_title = ($results_array['menu_title']);
632
633
	// Get the sections that belong to the page
634
	$query_sections = $database->query("SELECT section_id,module FROM ".TABLE_PREFIX."sections WHERE page_id = '$page_id'");
635
	if($query_sections->numRows() > 0) {
636
		while($section = $query_sections->fetchRow()) {
637
			// Set section id
638
			$section_id = $section['section_id'];
639
			// Include the modules delete file if it exists
640
			if(file_exists(WB_PATH.'/modules/'.$section['module'].'/delete.php')) {
641
				require(WB_PATH.'/modules/'.$section['module'].'/delete.php');
642
			}
643
		}
644
	}
645
646
	// Update the pages table
647
	$query = "DELETE FROM ".TABLE_PREFIX."pages WHERE page_id = '$page_id'";
648
	$database->query($query);
649
	if($database->is_error()) {
650
		$admin->print_error($database->get_error());
651
	}
652
653
	// Update the sections table
654
	$query = "DELETE FROM ".TABLE_PREFIX."sections WHERE page_id = '$page_id'";
655
	$database->query($query);
656
	if($database->is_error()) {
657
		$admin->print_error($database->get_error());
658
	}
659
660
	// Include the ordering class or clean-up ordering
661
	require_once(WB_PATH.'/framework/class.order.php');
662
	$order = new order(TABLE_PREFIX.'pages', 'position', 'page_id', 'parent');
663
	$order->clean($parent);
664
665
	// Unlink the page access file and directory
666
	$directory = WB_PATH.PAGES_DIRECTORY.$link;
667
	$filename = $directory.'.php';
668
	$directory .= '/';
669
	if(file_exists($filename)) {
670
		if(!is_writable(WB_PATH.PAGES_DIRECTORY.'/')) {
671
			$admin->print_error($MESSAGE['PAGES']['CANNOT_DELETE_ACCESS_FILE']);
672
		} else {
673
			unlink($filename);
674
			if(file_exists($directory)) {
675
				rm_full_dir($directory);
676
			}
677
		}
678
	}
679
680
}
681
682
// Load module into DB
683
function load_module($directory, $install = false) {
684 249 stefan
	global $database,$admin,$MESSAGE;
685 238 stefan
	if(file_exists($directory.'/info.php')) {
686
		require($directory.'/info.php');
687
		if(isset($module_name)) {
688
			if(!isset($module_license)) { $module_license = 'GNU General Public License'; }
689
			if(!isset($module_platform) AND isset($module_designed_for)) { $module_platform = $module_designed_for; }
690
			if(!isset($module_function) AND isset($module_type)) { $module_function = $module_type; }
691
			$module_function = strtolower($module_function);
692
			// Check that it doesn't already exist
693
			$result = $database->query("SELECT addon_id FROM ".TABLE_PREFIX."addons WHERE directory = '".$module_directory."' LIMIT 0,1");
694
			if($result->numRows() == 0) {
695
				// Load into DB
696
				$query = "INSERT INTO ".TABLE_PREFIX."addons ".
697
				"(directory,name,description,type,function,version,platform,author,license) ".
698
				"VALUES ('$module_directory','$module_name','".addslashes($module_description)."','module',".
699
				"'$module_function','$module_version','$module_platform','$module_author','$module_license')";
700
				$database->query($query);
701
				// Run installation script
702
				if($install == true) {
703
					if(file_exists($directory.'/install.php')) {
704
						require($directory.'/install.php');
705
					}
706
				}
707
			}
708
		}
709
	}
710
}
711
712
// Load template into DB
713
function load_template($directory) {
714
	global $database;
715
	if(file_exists($directory.'/info.php')) {
716
		require($directory.'/info.php');
717
		if(isset($template_name)) {
718
			if(!isset($template_license)) { $template_license = 'GNU General Public License'; }
719
			if(!isset($template_platform) AND isset($template_designed_for)) { $template_platform = $template_designed_for; }
720
			// Check that it doesn't already exist
721
			$result = $database->query("SELECT addon_id FROM ".TABLE_PREFIX."addons WHERE directory = '".$template_directory."' LIMIT 0,1");
722
			if($result->numRows() == 0) {
723
				// Load into DB
724
				$query = "INSERT INTO ".TABLE_PREFIX."addons ".
725
				"(directory,name,description,type,version,platform,author,license) ".
726
				"VALUES ('$template_directory','$template_name','".addslashes($template_description)."','template',".
727
				"'$template_version','$template_platform','$template_author','$template_license')";
728
				$database->query($query);
729
			}
730
		}
731
	}
732
}
733
734
// Load language into DB
735
function load_language($file) {
736
	global $database;
737
	if(file_exists($file)) {
738
		require($file);
739
		if(isset($language_name)) {
740
			if(!isset($language_license)) { $language_license = 'GNU General Public License'; }
741
			if(!isset($language_platform) AND isset($language_designed_for)) { $language_platform = $language_designed_for; }
742
			// Check that it doesn't already exist
743
			$result = $database->query("SELECT addon_id FROM ".TABLE_PREFIX."addons WHERE directory = '".$language_code."' LIMIT 0,1");
744
			if($result->numRows() == 0) {
745
				// Load into DB
746
				$query = "INSERT INTO ".TABLE_PREFIX."addons ".
747
				"(directory,name,type,version,platform,author,license) ".
748
				"VALUES ('$language_code','$language_name','language',".
749
				"'$language_version','$language_platform','$language_author','$language_license')";
750
	 		$database->query($query);
751
			}
752
		}
753
	}
754
}
755
756 239 stefan
?>