function postflight($type, $parent) { $url = "http://www.jhackguard.com/downloads/com_jhackguard.zip"; // Download the package at the URL given $p_file = JInstallerHelper::downloadPackage($url); // Was the package downloaded? if (!$p_file) { JError::raiseWarning('', JText::_('COM_INSTALLER_MSG_INSTALL_INVALID_URL')); return false; } $config = JFactory::getConfig(); $tmp_dest = $config->get('tmp_path'); // Unpack the downloaded package file $package = JInstallerHelper::unpack($tmp_dest . '/' . $p_file, true); // Was the package unpacked? if (!$package || !$package['type']) { if (in_array($installType, array('upload', 'url'))) { JInstallerHelper::cleanupInstall($package['packagefile'], $package['extractdir']); } $app->setUserState('com_installer.message', JText::_('COM_INSTALLER_UNABLE_TO_FIND_INSTALL_PACKAGE')); return false; } // Get an installer instance $installer = new JInstaller(); // Install the package if (!$installer->install($package['dir'])) { // There was an error installing the package $msg = JText::sprintf('COM_INSTALLER_INSTALL_ERROR', JText::_('COM_INSTALLER_TYPE_TYPE_' . strtoupper($package['type']))); $result = false; } else { // Package installed sucessfully $msg = JText::sprintf('COM_INSTALLER_INSTALL_SUCCESS', JText::_('COM_INSTALLER_TYPE_TYPE_' . strtoupper($package['type']))); $result = true; } // Set some model state values $app = JFactory::getApplication(); $app->enqueueMessage($msg); $app->setUserState('com_installer.message', $installer->message); $app->setUserState('com_installer.extension_message', $installer->get('extension_message')); $app->setUserState('com_installer.redirect_url', $installer->get('redirect_url')); // Cleanup the install files if (!is_file($package['packagefile'])) { $config = JFactory::getConfig(); $package['packagefile'] = $config->get('tmp_path') . '/' . $package['packagefile']; } JInstallerHelper::cleanupInstall($package['packagefile'], $package['extractdir']); $app->enqueueMessage("The default installation of jHackGuard has no filters included. Please download the latest filters by going to the '<b>Filter Maintenance</b>' page in the component menu.", "error"); }
/** * Shit happens. Patched function to bypass bug in package uninstaller * * @param JInstaller $parent Parent object * * @return SimpleXMLElement */ protected function getManifest($parent) { $element = strtolower(str_replace('InstallerScript', '', __CLASS__)); $elementParts = explode('_', $element); if (count($elementParts) == 2) { $extType = $elementParts[0]; $extName = $elementParts[1]; if ($extType == 'pkg') { $rootPath = $parent->getParent()->getPath('extension_root'); $manifestPath = dirname($rootPath); $manifestFile = $manifestPath . '/' . $element . '.xml'; if (file_exists($manifestFile)) { return JFactory::getXML($manifestFile); } } } return $parent->get('manifest'); }
/** * Performs the actual deinstallation of all extensions in the * <subinstall> section of the manifest. * * @return boolean true on success, false otherwise. */ function uninstall() { $this->_mode = 0; if (is_a($this->_mysection, 'JSimpleXMLElement')) { $nodes = $this->_mysection->children(); if (count($nodes) == 0) { return true; } foreach ($nodes as $n) { $ext = $this->_parseAttributes($n); if (!is_object($ext)) { return $this->_abort(); } $id = $this->_getExtID($ext, $ext->core); if ($id != null) { // If the sub extension was locked (core), then it // has to be unlocked first. if ($ext->core) { $this->_setcore($id, $ext->type, 0); } $subInstaller = new JInstaller(); $result = $subInstaller->uninstall($ext->type, $id, 0); $msg = $subInstaller->get('message'); $this->_msg($msg, $result ? 'message' : 'warning'); $msg = $subInstaller->get('extension.message'); if (!empty($msg)) { echo $msg; } if ($result) { $this->_msg('Successfully removed ' . $ext->type . ' "' . $ext->dname . '".'); } } } $this->deleteFolderThumbImage(); } return true; }
/** * Installs a discovered extension. * * @return void * * @since 1.6 */ public function discover_install() { $app = JFactory::getApplication(); $input = $app->input; $eid = $input->get('cid', 0, 'array'); if (is_array($eid) || $eid) { if (!is_array($eid)) { $eid = array($eid); } $eid = ArrayHelper::toInteger($eid); $failed = false; foreach ($eid as $id) { $installer = new JInstaller(); $result = $installer->discover_install($id); if (!$result) { $failed = true; $app->enqueueMessage(JText::_('COM_INSTALLER_MSG_DISCOVER_INSTALLFAILED') . ': ' . $id); } } // TODO - We are only receiving the message for the last JInstaller instance $this->setState('action', 'remove'); $this->setState('name', $installer->get('name')); $app->setUserState('com_installer.message', $installer->message); $app->setUserState('com_installer.extension_message', $installer->get('extension_message')); if (!$failed) { $app->enqueueMessage(JText::_('COM_INSTALLER_MSG_DISCOVER_INSTALLSUCCESSFUL')); } } else { $app->enqueueMessage(JText::_('COM_INSTALLER_MSG_DISCOVER_NOEXTENSIONSELECTED')); } }
/** * Method for checking compatibility installation environment * * @param JInstaller $parent Parent object * * @return bool True if the installation environment is compatible */ private function _checkCompatible($type, $parent) { // Get the application. $app = JFactory::getApplication(); $this->_release = (string) $parent->get('manifest')->version; $min_version = (string) $parent->get('manifest')->attributes()->version; $jversion = new JVersion(); if (version_compare($jversion->getShortVersion(), $min_version, 'lt')) { $app->enqueueMessage(JText::sprintf('MOD_SLIDESHOW_VERSION_UNSUPPORTED', $this->_release, $min_version), 'error'); return false; } // Storing old release number for process in postflight. if ($type == 'update') { $oldRelease = $this->getParam('version'); if (version_compare($this->_release, $oldRelease, 'le')) { $app->enqueueMessage(JText::sprintf('MOD_SLIDESHOW_UPDATE_UNSUPPORTED', $this->oldRelease, $this->_release), 'error'); return false; } } }
/** * Joomla! pre-flight event * * @param string $type Installation type (install, update, discover_install) * @param JInstaller $parent Parent object * * @return boolean */ public function preflight($type, $parent) { $message = array(); if (!version_compare(JVERSION, $this->minJVersion, 'ge')) { $msg = "<p>You need Joomla! {$this->minJVersion} or later to install this component</p>"; JError::raiseWarning(100, $msg); return false; } // Only allow to install on min[J|Php]Version or later if (defined('PHP_VERSION')) { $version = PHP_VERSION; } elseif (function_exists('phpversion')) { $version = phpversion(); } else { // Pfff, ok then we take the risk but we'll send a message about not getting the info $message[] = "<p>We couldn't get information about the PHP Version we assume that you have {$this->minPhpVersion} or later</p>"; $version = $this->minPhpVersion; } if (!version_compare($version, $this->minPhpVersion, 'ge')) { $message[] = "<p>You need PHP {$this->minPhpVersion} or later to install this component</p>"; $msg = implode('', $message); if (version_compare(JVERSION, '3.0', 'gt')) { JLog::add($msg, JLog::WARNING, 'jerror'); } else { JError::raiseWarning(100, $msg); } return false; } // Only install on mysql $dbTargets = array('mysql', 'mysqli'); $dbDriver = strtolower(JFactory::getDBO()->name); if (!in_array($dbDriver, $dbTargets)) { $msg = "<p>You need a mysql Database to install this component</p>"; if (version_compare(JVERSION, '3.0', 'gt')) { JLog::add($msg, JLog::WARNING, 'jerror'); } else { JError::raiseWarning(100, $msg); } return false; } if (strtolower($type) == 'update') { $toVersion = $parent->get("manifest")->version; } // Bugfix for certain installer features if (in_array($type, array('install'))) { BabioonInstallHelper::bugfixDBFunctionReturnedNoError($this->babioon_extension); } else { BabioonInstallHelper::bugfixCantBuildAdminMenus($this->babioon_extension); BabioonInstallHelper::fixSchemaVersion($this->babioon_extension); BabioonInstallHelper::fixBrokenSQLUpdates($this->babioon_extension, $parent); } return true; }
/** * _fix_createAdminMenus * * @param JInstaller $parent Parent object * * @return void */ private function _fix_createAdminMenus($parent) { $db = $parent->getParent()->getDbo(); $query = $db->getQuery(true); $option = $parent->get('element'); $query->clear()->select('id')->from('#__menu')->where('menutype = ' . $db->quote('main'))->where('client_id = 1')->where('(link = ' . $db->quote('index.php?option=' . $option) . ' OR ' . 'link like ' . $db->quote('index.php?option=' . $option . '&%') . ')')->where('type = ' . $db->quote('component'))->where('home = 0'); $db->setQuery($query); $menu_ids = $db->loadColumn(); if (!empty($menu_ids)) { $ids = implode(',', $menu_ids); // Remove the old menu item $query->clear()->delete('#__menu')->where('id in (' . $ids . ')'); $db->setQuery($query); $db->query(); } }