install_dir, 'file'); $filesindir = array(); foreach($files as $file) { if (strstr($file, ".xml"))$filesindir[] = $file; } if (count($filesindir) > 0) { foreach($filesindir as $file) { $packagefile = $this->isPackageFile($file); if (!is_null($packagefile) && $this->installer_file) { $this->xml = $packagefile; return true; } } } else { return false; } } function isPackageFile($p_file) { $xmlDoc = new MiniXMLDoc(); $xmlDoc->fromFile($this->install_dir . $p_file); $islosinstall = &$xmlDoc->getElementByPath('mosinstall'); if ($islosinstall) { // Set the type $this->xtype = $islosinstall->attribute("type"); $this->installer_file = $p_file; return $xmlDoc; } return null; } function copyxmlfiles($filetype, $src, $dest) { $files_element = $this->xml->getElementByPath('mosinstall/' . $filetype); if (is_null($files_element)) return false; $filescopied=0; $files = $files_element->getAllChildren(); foreach($files as $file) { if (basename($file->getValue()) != $file->getValue()) { $newdir = dirname($file->getValue()); if (!is_dir($dest . $newdir))mkdir($dest . $newdir,0777); } copy($src . $file->getValue(), $dest . $file->getValue()); $filescopied++; } return $filescopied; } function copyxml($dest_dir = '') { if ($dest_dir == '') { $dest_dir = $this->install_to; } copy($this->install_dir . $this->installer_file, $dest_dir . $this->installer_file); } function queries($path) { global $conn; // Are there any SQL queries?? $query_element = $this->xml->getElementByPath($path); if (!is_null($query_element)) { $queries = $query_element->getAllChildren(); foreach($queries as $query) { $conn->Execute($query->getValue()); } } } function isWindows() { if (stristr(php_uname(), 'windows')) { return true; } return false; } function isValid() { $ismosinstall = $this->xml->getElementByPath('mosinstall'); if($ismosinstall) { if($this->type==$ismosinstall->attribute("type")) return true; } return false; } function from_dir($dir) { $this->install_dir = dir_name($dir); } function get_installer() { global $package_file, $package_url, $package_dir, $lm_absolute_path; // check url if (strlen(str_replace("http://", "", $package_url)) > 7) { // download file -> unzip -> from dir $url_arr = explode("/", $package_url, 20); $filename = md5($url_arr[ count($url_arr)-1 ]); if (is_file($lm_absolute_path . "uploadfiles/" . $filename))unlink($lm_absolute_path . "uploadfiles/" . $filename); get_url($package_url, $lm_absolute_path . "uploadfiles/" . $filename); $this->extract_file($lm_absolute_path . "uploadfiles/" . $filename, $lm_absolute_path . "uploadfiles/install_" . $filename); return true; } if (isset($_FILES["package_file"]) && $_FILES["package_file"]['name'] != '') { $lm_name = $_FILES["package_file"]['name']; $src = $_FILES["package_file"]["tmp_name"]; $dest = $lm_absolute_path . "uploadfiles/" . $lm_name; move_uploaded_file($src, $dest); $this->extract_file($dest, $lm_absolute_path . "uploadfiles/install_" . $lm_name); return true; } if (strlen(str_replace($lm_absolute_path, "", $package_dir)) > 5) { $this->from_dir($package_dir); return true; } return false; } function extract_file($src_file, $dest_dir) { global $lm_absolute_path; // Find the extension of the file $fileext = substr(strrchr(basename($src_file), '.'), 1); if ($fileext == "gz" || $fileext == "tar") { PclTarExtract($src_file, $dest_dir); if (PclErrorCode() != 1) { // error return false; } $this->from_dir($dest_dir); } else { $zipfile = new PclZip($src_file); if ($this->isWindows()) { define('OS_WINDOWS', 1); } else { define('OS_WINDOWS', 0); } $ret = $zipfile->extract($dest_dir); if ($ret == 0) { // error return false; } $this->from_dir($dest_dir); } // Try to find the correct install dir. in case that the package have subdirs // Save the install dir for later cleanup $filesindir = read_dir($dest_dir , "both"); if (count($filesindir) == 1) { if (is_dir($dest_dir . "/" . $filesindir[0])) { $this->from_dir($dest_dir . "/" . $filesindir[0]); } } return true; } } class Install extends CoreInstall { // install type ( components etc ) function Install($type) { $this->type = $type; } function go() { if (!$this->get_installer())return false; $this->findInstallFile(); if(!$this->isValid())return "&sysmsg="._INSTALL_INCORRECT; switch ($this->type) { case "template" : return $this->install_template(); case "language" : return $this->install_lang(); case "module" : return $this->install_module(); case "limbot" : return $this->install_limbot(); case "component" : return $this->install_component(); case "hack" : return $this->install_hack(); } } function install_lang() { global $lm_absolute_path; $lang_dir = $lm_absolute_path . "lang/"; $e = $this->xml->getElementByPath('mosinstall/name'); $lm_languageName = strtolower($e->getValue()); if (!mkdir($lang_dir . $lm_languageName,0777))return sprintf("&sysmsg="._INSTALL_FAILED_DIR,$lang_dir.$lm_languageName); $this->install_to = $lang_dir . $lm_languageName . "/"; $this->copyxmlfiles('files', $this->install_dir, $this->install_to); $this->copyxml(); return "&sysmsg="._INSTALL_SUCCESS; } function install_template() { global $lm_absolute_path; $lm_template_dir = $lm_absolute_path . "templates/"; $e = $this->xml->getElementByPath('mosinstall/name'); $lm_templateName = strtolower(str_replace(" ", "_", $e->getValue())); $this->install_to = $lm_template_dir . $lm_templateName . "/"; if (!mkdir($this->install_to,0777))return sprintf("&sysmsg="._INSTALL_FAILED_DIR,$this->install_to); $this->copyxmlfiles('files', $this->install_dir, $this->install_to); $this->copyxmlfiles('images', $this->install_dir, $this->install_to); $this->copyxmlfiles('css', $this->install_dir, $this->install_to); $this->copyxml(); return "&sysmsg="._INSTALL_SUCCESS; } function install_module() { global $lm_absolute_path, $conn, $easydb; $e = $this->xml->getElementByPath('mosinstall/name'); $moduleName = $e->getValue(); $this->install_to = $lm_absolute_path . "modules/"; $m_name = $this->xml->getElementByPath('mosinstall/files/filename'); $mod_id = $m_name->attribute("module"); // this is used to install a modules if($conn->GetRow("SELECT * FROM #__modules WHERE module='$mod_id'")){ return "&sysmsg="._INSTALL_FAILED_EXIST; } $this->copyxmlfiles('files', $this->install_dir, $this->install_to); $this->copyxmlfiles('images', $this->install_dir, $this->install_to); $this->copyxml($this->install_to); // queries $order = $easydb->neworder("modules"); $conn->Execute("INSERT INTO #__modules (title,ordering,position,module,iscore) VALUES ('" . $moduleName . "',$order,'left','" . $mod_id . "',1)"); return "&sysmsg="._INSTALL_SUCCESS; } function install_limbot() { global $lm_absolute_path, $conn, $easydb; $e = $this->xml->getElementByPath('mosinstall/name'); $limbotName = $e->getValue(); $this->install_to = $lm_absolute_path . "limbots/"; $b_type = $this->xml->getElementByPath('mosinstall'); $bot_type = $b_type->attribute("group"); $b_name = $this->xml->getElementByPath('mosinstall/files/filename'); $bot_id = $b_name->attribute("mambot"); // this is used to install a modules if($conn->GetRow("SELECT * FROM #__limbots WHERE limbot='$bot_id'")){ return "&sysmsg="._INSTALL_FAILED_EXIST; } $this->copyxmlfiles('files', $this->install_dir, $this->install_to); $this->copyxmlfiles('images', $this->install_dir, $this->install_to); $this->copyxml($this->install_to); // queries $order = $easydb->neworder("limbots"); $conn->Execute("INSERT INTO #__limbots (name,type,element,ordering,iscore) VALUES ('".$limbotName."','".$bot_type."','".$bot_id."',$order,1)"); return "&sysmsg="._INSTALL_SUCCESS; } function install_component() { global $lm_absolute_path, $conn, $easydb; $e = $this->xml->getElementByPath('mosinstall/name'); $componentName = strtolower(str_replace(" ", "_", $e->getValue())); $com_name=$componentName; $this->componentDir = $lm_absolute_path . "components/com_" .$componentName. "/"; $this->componentAdminDir = $lm_absolute_path . "admin/components/com_" .$componentName. "/"; if (!mkdir($this->componentDir,0777))return sprintf("&sysmsg="._INSTALL_FAILED_DIR,$this->componentDir); if (!mkdir($this->componentAdminDir,0777))return sprintf("&sysmsg="._INSTALL_FAILED_DIR,$this->componentAdminDir); // userfiles $front_end=$this->copyxmlfiles('files', $this->install_dir, $this->componentDir); $this->copyxmlfiles('images', $this->install_dir, $this->componentDir); // admin files $back_end=$this->copyxmlfiles('administration/files', $this->install_dir, $this->componentAdminDir); $this->copyxmlfiles('administration/images', $this->install_dir, $this->componentAdminDir); // Is there an un / installfile $installfile_elemet = $this->xml->getElementByPath('mosinstall/installfile'); if (!is_null($installfile_elemet)) { copy($this->install_dir . $installfile_elemet->getValue(), $this->componentAdminDir . $installfile_elemet->getValue()); } $uninstallfile_elemet = $this->xml->getElementByPath('mosinstall/uninstallfile'); if (!is_null($uninstallfile_elemet)) { copy($this->install_dir . $uninstallfile_elemet->getValue(), $this->componentAdminDir . $uninstallfile_elemet->getValue()); } // queries $this->queries('mosinstall/install/queries'); // menus $front_link=""; if($front_end)$front_link="option=$com_name"; $back_link=""; if($back_end)$back_link="com_option=$com_name"; $adminmenu_element = $this->xml->getElementByPath('mosinstall/administration/menu'); if (!is_null($adminmenu_element)) { $adminsubmenu_element = $this->xml->getElementByPath('mosinstall/administration/submenu'); $com_name = strtolower(str_replace(" ", "", $componentName)); $com_admin_menuname = $adminmenu_element->getValue(); if (!is_null($adminsubmenu_element)) { $conn->Execute("INSERT INTO #__components (name,link,admin_menu_link,admin_menu_alt,option_link) VALUES ('$com_admin_menuname','$front_link','$back_link','$com_admin_menuname','com_$com_name')"); $com_admin_menu_id = $conn->Insert_ID(); $com_admin_submenus = $adminsubmenu_element->getAllChildren(); $submenuordering = 0; foreach($com_admin_submenus as $admin_submenu) { if ($admin_submenu->attribute("option")) { $com_admin_menu_link = "com_option=$com_name&option=" . $admin_submenu->attribute("option"); } else if ($admin_submenu->attribute("link")) { $com_admin_menu_link = $admin_submenu->attribute("link"); } else { $com_admin_menu_link = "com_option=$com_name"; } $conn->Execute("INSERT INTO #__components (name,parent,admin_menu_link,admin_menu_alt,option_link) VALUES ('" . $admin_submenu->getValue() . "',$com_admin_menu_id,'$com_admin_menu_link','" . $admin_submenu->getValue() . "','com_$com_name')"); } } else { $conn->Execute("INSERT INTO #__components (name,link,admin_menu_link,admin_menu_alt,option_link) VALUES ('$com_admin_menuname','$front_link','$back_link','$com_admin_menuname','com_$com_name')"); } } $this->copyxml($this->componentAdminDir); //intenal modules ( better to install them along the system ) $module_elemet = $this->xml->getElementByPath('mosinstall/modules'); if (!is_null($module_elemet)) { $modules = $module_elemet->getAllChildren(); foreach($modules as $module) { $minstall=new Install("module"); $minstall->from_dir($this->install_dir.$module->getValue()); $minstall->findInstallFile(); $minstall->install_module(); } } //intenal limbots ( better to install them along the system ) $limbot_elemet = $this->xml->getElementByPath('mosinstall/limbots'); if (!is_null($limbot_elemet)) { $limbots = $limbot_elemet->getAllChildren(); foreach($limbots as $limbot) { $minstall=new Install("limbot"); $minstall->from_dir($this->install_dir.$limbot->getValue()); $minstall->findInstallFile(); $minstall->install_limbot(); } } if (!is_null($installfile_elemet)) { return '&install_file=' . $this->install_dir . $installfile_elemet->getValue() . '&install_dir=' . $this->install_dir; } return "&sysmsg="._INSTALL_SUCCESS; } function install_hack() { global $lm_absolute_path, $conn, $easydb; // Is there an un / installfile $installfile_elemet = $this->xml->getElementByPath('mosinstall/installfile'); if (!is_null($installfile_elemet)) { return '&install_file=' . $this->install_dir . $installfile_elemet->getValue() . '&install_dir=' . $this->install_dir; } return false; } function install_interface($form = '', $title = _INSTALL_TITLE) { global $limbocore, $web_path; if (!isset($web_path))$web_path = "http://"; $gui = new admin_interface(); $gui->add("form", "adminform", "", $form); $gui->add("bar"); $gui->add("com_header", $title); $gui->add("tab_head"); $gui->add("tab_simple", "",$title, ""); if (function_exists('gzopen')) { $gui->add("form_text", "",_INSTALL_UPLOAD_ZIP); $gui->add("form_file", "package_file",_INSTALL_UPLOAD_ZIP_FILE); $gui->add("form_text", "",_INSTALL_ONLINE_ZIP); $gui->add("form_textfield", "package_url",_INSTALL_ONLINE_ZIP_URL,$web_path); } $gui->add("form_text", "",_INSTALL_DIR); $gui->add("form_textfield", "package_dir",_INSTALL_DIR_PATH, $limbocore->getVar('lm_absolute_path')); $gui->add("tab_end"); $gui->add("tab_tail"); $gui->add("bar"); $gui->add("end_form"); $gui->generate(); } } /* uninstall class */ class UnInstall extends CoreInstall { var $uninstall_string = false; function UnInstall($type) { $this->type = $type; } function name($lm_name) { $this->uninstall_string = $lm_name; } function go() { switch ($this->type) { case "template": return $this->uninstall_template(); case "language": return $this->uninstall_language(); case "module": return $this->uninstall_module(); case "limbot": return $this->uninstall_limbot(); case "component": return $this->uninstall_component(); } } function uninstall_module() { global $lm_absolute_path, $conn; if (unlink($lm_absolute_path . "modules/" . $this->uninstall_string . ".php")) { $dir=read_dir($lm_absolute_path . "modules/",'file'); foreach($dir as $file){ if(strstr($file,$this->uninstall_string)) { unlink($lm_absolute_path . "limbots/" .$file); } } $sql = "DELETE FROM #__modules WHERE module='$this->uninstall_string'"; $conn->Execute($sql); return "&sysmsg="._UNINSTALL_SUCCESS; } return "&sysmsg="._UNINSTALL_FAILED; } function uninstall_limbot() { global $lm_absolute_path, $conn; if (unlink($lm_absolute_path . "limbots/" . $this->uninstall_string . ".php")) { //check for other similar files ( delete them 2 ) $dir=read_dir($lm_absolute_path . "limbots/",'file'); foreach($dir as $file){ if(strstr($file,$this->uninstall_string)) { unlink($lm_absolute_path . "limbots/" .$file); }} $sql = "DELETE FROM #__limbots WHERE element='$this->uninstall_string'"; $conn->Execute($sql); unlink($lm_absolute_path . "limbots/" . $this->uninstall_string . ".xml"); return "&sysmsg="._UNINSTALL_SUCCESS; } return "&sysmsg="._UNINSTALL_FAILED; } function uninstall_template() { global $lm_absolute_path; if (deldir($lm_absolute_path . "templates/" . $this->uninstall_string . "/")) return "&sysmsg="._UNINSTALL_SUCCESS; else return "&sysmsg="._UNINSTALL_FAILED; } function uninstall_language() { global $lm_absolute_path; if (deldir($lm_absolute_path . "lang/" . $this->uninstall_string . "/"))return "&sysmsg="._UNINSTALL_SUCCESS; else return "&sysmsg="._UNINSTALL_FAILED; } function uninstall_component() { global $lm_absolute_path, $conn; $uninstall_dir = $lm_absolute_path . "admin/components/" . $this->uninstall_string . "/"; $this->from_dir($uninstall_dir); $this->findInstallFile(); $uninstallfile_elemet = $this->xml->getElementByPath('mosinstall/uninstallfile'); if (!is_null($uninstallfile_elemet)) { if (is_file($lm_absolute_path . "/uploadfiles/" . $uninstallfile_elemet->getValue())) { unlink($lm_absolute_path . "/uploadfiles/" . $uninstallfile_elemet->getValue()); } copy($uninstall_dir . $uninstallfile_elemet->getValue(), $lm_absolute_path . "/uploadfiles/" . $uninstallfile_elemet->getValue()); } $this->queries('mosinstall/uninstall/queries'); deldir($uninstall_dir); deldir($lm_absolute_path . "components/" . $this->uninstall_string . "/"); $module_elemet = $this->xml->getElementByPath('mosinstall/modules'); if (!is_null($module_elemet)) { $modules = $module_elemet->getAllChildren(); foreach($modules as $module) { $muninstall=new UnInstall("module"); $muninstall->name($module->getValue()); $muninstall->go(); } } $limbot_elemet = $this->xml->getElementByPath('mosinstall/limbots'); if (!is_null($limbot_elemet)) { $limbots = $limbot_elemet->getAllChildren(); foreach($limbots as $limbot) { $muninstall=new UnInstall("limbot"); $muninstall->name($limbot->getValue()); $muninstall->go(); } } $conn->Execute("DELETE FROM #__components WHERE option_link='" . $this->uninstall_string . "'"); if (!is_null($uninstallfile_elemet)) { return '&uninstall_file=' . $lm_absolute_path . "/uploadfiles/" . $uninstallfile_elemet->getValue(); } return "&sysmsg="._UNINSTALL_SUCCESS; } } ?>