Project

General

Profile

« Previous | Next » 

Revision 165

Added by ryan about 19 years ago

Added load_addons functions

View differences:

functions.php
682 682
	
683 683
}
684 684

  
685
// Load addons into DB
686
function load_addons($search_dir, $install_modules = false) {
687
	global $database;
688
	if($handle = opendir($search_dir)) {
689
		while(false !== ($file = readdir($handle))) {
690
			if($file != '' AND substr($file, 0, 1) != '.' AND $file != 'admin.php' AND $file != 'index.php') {
691
				// Load info file
692
				if(file_exists($search_dir.'/'.$file.'/info.php')) {
693
					require($search_dir.'/'.$file.'/info.php');
694
				} else {
695
					require($search_dir.'/'.$file);
696
				}
697
				// Get addon type
698
				if(isset($module_name)) {
699
					if(!isset($module_license)) { $module_license = 'GNU General Public License'; }
700
					if(!isset($module_platform) AND isset($module_designed_for)) { $module_platform = $module_designed_for; }
701
					// Check that it doesn't already exist
702
					$result = $database->query("SELECT addon_id FROM ".TABLE_PREFIX."addons WHERE directory = '".$module_directory."' LIMIT 0,1");
703
					if($result->numRows() == 0) {
704
						// Load into DB
705
						$query = "INSERT INTO ".TABLE_PREFIX."addons ".
706
						"(directory,name,description,type,function,version,platform,author,license) ".
707
						"VALUES ('$module_directory','$module_name','".addslashes($module_description)."','module',".
708
						"'$module_function','$module_version','$module_platform','$module_author','$module_license')";
709
						$database->query($query);
710
						// Run installation script
711
						if($install_modules == true) {
712
							require($search_dir.'/'.$file.'/install.php');
713
						}
714
					}
715
				} elseif(isset($template_name)) {
716
					if(!isset($template_license)) { $template_license = 'GNU General Public License'; }
717
					if(!isset($template_platform) AND isset($template_designed_for)) { $template_platform = $template_designed_for; }
718
					// Check that it doesn't already exist
719
					$result = $database->query("SELECT addon_id FROM ".TABLE_PREFIX."addons WHERE directory = '".$template_directory."' LIMIT 0,1");
720
					if($result->numRows() == 0) {
721
						// Load into DB
722
						$query = "INSERT INTO ".TABLE_PREFIX."addons ".
723
						"(directory,name,description,type,version,platform,author,license) ".
724
						"VALUES ('$template_directory','$template_name','".addslashes($template_description)."','template',".
725
						"'$template_version','$template_platform','$template_author','$template_license')";
726
						$database->query($query);
727
					}
728
				} elseif(isset($language_name)) {
729
					if(!isset($language_license)) { $language_license = 'GNU General Public License'; }
730
					if(!isset($language_platform) AND isset($language_designed_for)) { $language_platform = $language_designed_for; }
731
					// Check that it doesn't already exist
732
					$result = $database->query("SELECT addon_id FROM ".TABLE_PREFIX."addons WHERE directory = '".$language_code."' LIMIT 0,1");
733
					if($result->numRows() == 0) {
734
						// Load into DB
735
						$query = "INSERT INTO ".TABLE_PREFIX."addons ".
736
						"(directory,name,type,version,platform,author,license) ".
737
						"VALUES ('$language_code','$language_name','language',".
738
						"'$language_version','$language_platform','$language_author','$language_license')";
739
						$database->query($query);
740
					}
741
				}
742
			}
743
		}
744
		closedir($handle);
745
	} else {
746
		echo 'Can\'t open '.$search_dir;
747
	}
748
}
749

  
685 750
?>

Also available in: Unified diff