From 843224cdbdcf6c56b34a843d2440015bf1073ddd Mon Sep 17 00:00:00 2001 From: Denis Ryabov Date: Wed, 19 Jan 2022 19:41:22 +0300 Subject: [PATCH] pre-check required Joomla and PHP versions --- .../language/en-GB/en-GB.com_jedchecker.ini | 1 + .../components/com_jedchecker/script.php | 114 ------------------ script.php | 27 ++++- 3 files changed, 26 insertions(+), 116 deletions(-) delete mode 100644 administrator/components/com_jedchecker/script.php diff --git a/administrator/components/com_jedchecker/language/en-GB/en-GB.com_jedchecker.ini b/administrator/components/com_jedchecker/language/en-GB/en-GB.com_jedchecker.ini index 84f8178..3a95421 100644 --- a/administrator/components/com_jedchecker/language/en-GB/en-GB.com_jedchecker.ini +++ b/administrator/components/com_jedchecker/language/en-GB/en-GB.com_jedchecker.ini @@ -21,6 +21,7 @@ COM_JEDCHECKER_RULE_PH3="License tag missing or incorrect in XML install file" COM_JEDCHECKER_RULE_PH3_DESC="An install file should include the license information in a license-tag. The license must be GPL or GPL compatible." COM_JEDCHECKER_EVERYTHING_SEEMS_TO_BE_FINE_WITH_THAT_RULE="Congratulations, everything seems to be fine with that rule!" COM_JEDCHECKER_DEVELOPED_BY="JED Checker is a JED project." +COM_JEDCHECKER_JOOMLA_VERSION_INCOMPATIBLE="JED Checker is incompatible with the Joomla! version that you run on this site: %s. You would need at least Joomla! version %s. Aborting installation" COM_JEDCHECKER_PHP_VERSION_INCOMPATIBLE="JED Checker is incompatible with the PHP version that you run on this site: %s. You would need at least PHP Version %s. Aborting installation" COM_JEDCHECKER_ERROR_HTML_INDEX_NOT_FOUND="Missing index.html in this directory." COM_JEDCHECKER_ERROR_JEXEC_NOT_FOUND="The JEXEC security check was not found in this file." diff --git a/administrator/components/com_jedchecker/script.php b/administrator/components/com_jedchecker/script.php deleted file mode 100644 index 8e7c9d2..0000000 --- a/administrator/components/com_jedchecker/script.php +++ /dev/null @@ -1,114 +0,0 @@ - - * - * @license GNU General Public License version 2 or later; see LICENSE.txt - */ - -defined('_JEXEC') or die('Restricted access'); - -/** - * Class Com_JedcheckerInstallerScript - * - * @since 1.5 - */ -class Com_JedcheckerInstallerScript -{ - protected $extension = 'com_jedchecker'; - - protected $parent; - - /** - * Function executed before the the installation - * - * @param string $type - the installation type - * @param JInstallerComponent $parent - the parent class - */ - public function preflight($type, $parent) - { - $this->parent = $parent; - - if (version_compare(PHP_VERSION, '5.3.10', '<')) - { - $this->loadLanguage(); - - $msg = JText::sprintf('COM_JEDCHECKER_PHP_VERSION_INCOMPATIBLE', PHP_VERSION, '5.3.10'); - echo "

$msg

"; - - return false; - } - } - - /** - * Update cleans out any old rules. - * - * @param JInstallerComponent $parent Is the class calling this method. - * - * @return bool|null If this returns false, Joomla will abort the update and undo everything already done. - */ - public function update($parent) - { - $this->loadLanguage(); - - // Doing it this way in case there are other old rules to be deleted - $oldRules = array('htmlindexes'); - - foreach ($oldRules as $rule) - { - $rulePhpFile = JPATH_ADMINISTRATOR . '/components/' . $this->extension . '/libraries/rules/' . $rule . '.php'; - $ruleIniFile = JPATH_ADMINISTRATOR . '/components/' . $this->extension . '/libraries/rules/' . $rule . '.ini'; - - // Remove the rule's php file - if (file_exists($rulePhpFile)) - { - if (JFile::delete($rulePhpFile)) - { - $msg = JText::sprintf('COM_JEDCHECKER_OLD_RULE_X_PHP_FILE_REMOVED', $rule); - } - else - { - $msg = JText::sprintf('COM_JEDCHECKER_OLD_RULE_X_PHP_FILE_NOT_REMOVED', $rule); - } - - echo "

$msg

"; - } - - // Remove the rule's ini file - if (file_exists($ruleIniFile)) - { - if (JFile::delete($ruleIniFile)) - { - $msg = JText::sprintf('COM_JEDCHECKER_OLD_RULE_X_INI_FILE_REMOVED', $rule); - } - else - { - $msg = JText::sprintf('COM_JEDCHECKER_OLD_RULE_X_INI_FILE_NOT_REMOVED', $rule); - } - - echo "

$msg

"; - } - } - } - - /** - * Load language necessary during the installation - * - * @return void - */ - public function loadLanguage() - { - $extension = $this->extension; - $jlang = JFactory::getLanguage(); - $path = $this->parent->getParent()->getPath('source') . '/administrator'; - $jlang->load($extension, $path, 'en-GB', true); - $jlang->load($extension, $path, $jlang->getDefault(), true); - $jlang->load($extension, $path, null, true); - $jlang->load($extension . '.sys', $path, 'en-GB', true); - $jlang->load($extension . '.sys', $path, $jlang->getDefault(), true); - $jlang->load($extension . '.sys', $path, null, true); - } -} diff --git a/script.php b/script.php index 1da1ede..a76e5bb 100644 --- a/script.php +++ b/script.php @@ -2,7 +2,7 @@ /** * @package Joomla.JEDChecker * - * @copyright Copyright (C) 2017 - 2019 Open Source Matters, Inc. All rights reserved. + * @copyright Copyright (C) 2017 - 2022 Open Source Matters, Inc. All rights reserved. * Copyright (C) 2008 - 2016 compojoom.com . All rights reserved. * @author Daniel Dimitrov * @@ -19,6 +19,9 @@ defined('_JEXEC') or die('Restricted access'); class Com_JedcheckerInstallerScript { protected $extension = 'com_jedchecker'; + protected $min_php = '5.6.0'; + protected $min_joomla = '3.7.0'; + protected $parent; /** * Function executed before the the installation @@ -29,6 +32,26 @@ class Com_JedcheckerInstallerScript public function preflight($type, $parent) { $this->parent = $parent; + + if (version_compare(PHP_VERSION, $this->min_php, '<')) + { + $this->loadLanguage(); + + $msg = JText::sprintf('COM_JEDCHECKER_PHP_VERSION_INCOMPATIBLE', PHP_VERSION, $this->min_php); + JLog::add($msg, JLog::WARNING, 'jerror'); + + return false; + } + + if (version_compare(JVERSION, $this->min_joomla, '<')) + { + $this->loadLanguage(); + + $msg = JText::sprintf('COM_JEDCHECKER_JOOMLA_VERSION_INCOMPATIBLE', JVERSION, $this->min_joomla); + JLog::add($msg, JLog::WARNING, 'jerror'); + + return false; + } } /** @@ -91,7 +114,7 @@ class Com_JedcheckerInstallerScript { $extension = $this->extension; $jlang = JFactory::getLanguage(); - $path = $this->parent->getParent()->getPath('source') . '/administrator'; + $path = $this->parent->getParent()->getPath('source') . '/administrator/components/' . $extension; $jlang->load($extension, $path, 'en-GB', true); $jlang->load($extension, $path, $jlang->getDefault(), true); $jlang->load($extension, $path, null, true);