33
2
mirror of https://github.com/joomla-extensions/jedchecker.git synced 2024-12-25 03:36:00 +00:00
jedchecker/script.php

132 lines
3.5 KiB
PHP
Raw Normal View History

2012-05-21 08:52:10 +00:00
<?php
/**
2019-03-09 19:44:14 +00:00
* @package Joomla.JEDChecker
*
* @copyright Copyright (C) 2017 - 2022 Open Source Matters, Inc. All rights reserved.
2019-03-10 16:09:42 +00:00
* Copyright (C) 2008 - 2016 compojoom.com . All rights reserved.
2019-03-10 08:49:52 +00:00
* @author Daniel Dimitrov <daniel@compojoom.com>
*
2019-03-09 19:44:14 +00:00
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
defined('_JEXEC') or die('Restricted access');
use Joomla\CMS\Factory;
use Joomla\CMS\Filesystem\File;
use Joomla\CMS\Installer\Adapter\ComponentAdapter;
use Joomla\CMS\Language\Text;
use Joomla\CMS\Log\Log;
2013-11-11 09:23:05 +00:00
/**
* Class Com_JedcheckerInstallerScript
*
* @since 1.5
*/
class Com_JedcheckerInstallerScript
{
2013-11-11 09:23:05 +00:00
protected $extension = 'com_jedchecker';
protected $min_php = '5.6.0';
protected $min_joomla = '3.8.0';
protected $parent;
2013-11-11 09:23:05 +00:00
/**
* Function executed before the the installation
*
* @param string $type - the installation type
* @param ComponentAdapter $parent - the parent class
2013-11-11 09:23:05 +00:00
*/
public function preflight($type, $parent)
{
$this->parent = $parent;
if (version_compare(PHP_VERSION, $this->min_php, '<'))
{
$this->loadLanguage();
$msg = Text::sprintf('COM_JEDCHECKER_PHP_VERSION_INCOMPATIBLE', PHP_VERSION, $this->min_php);
Log::add($msg, Log::WARNING, 'jerror');
return false;
}
if (version_compare(JVERSION, $this->min_joomla, '<'))
{
$this->loadLanguage();
$msg = Text::sprintf('COM_JEDCHECKER_JOOMLA_VERSION_INCOMPATIBLE', JVERSION, $this->min_joomla);
Log::add($msg, Log::WARNING, 'jerror');
return false;
}
2013-11-11 09:23:05 +00:00
}
/**
* Update cleans out any old rules.
*
* @param ComponentAdapter $parent Is the class calling this method.
2013-11-11 09:23:05 +00:00
*
* @return bool|null If this returns false, Joomla will abort the update and undo everything already done.
*/
public function update($parent)
{
$this->loadLanguage();
2013-11-11 09:23:05 +00:00
// Doing it this way in case there are other old rules to be deleted
$oldRules = array('htmlindexes');
2013-11-11 09:23:05 +00:00
foreach ($oldRules as $rule)
{
$rulePhpFile = JPATH_ADMINISTRATOR . '/components/' . $this->extension . '/libraries/rules/' . $rule . '.php';
$ruleIniFile = JPATH_ADMINISTRATOR . '/components/' . $this->extension . '/libraries/rules/' . $rule . '.ini';
2013-11-11 09:23:05 +00:00
// Remove the rule's php file
if (file_exists($rulePhpFile))
{
if (File::delete($rulePhpFile))
2013-11-11 09:23:05 +00:00
{
$msg = Text::sprintf('COM_JEDCHECKER_OLD_RULE_X_PHP_FILE_REMOVED', $rule);
2013-11-11 09:23:05 +00:00
}
else
{
$msg = Text::sprintf('COM_JEDCHECKER_OLD_RULE_X_PHP_FILE_NOT_REMOVED', $rule);
2013-11-11 09:23:05 +00:00
}
2013-11-11 09:23:05 +00:00
echo "<p>$msg</p>";
}
2013-11-11 09:23:05 +00:00
// Remove the rule's ini file
if (file_exists($ruleIniFile))
{
if (File::delete($ruleIniFile))
2013-11-11 09:23:05 +00:00
{
$msg = Text::sprintf('COM_JEDCHECKER_OLD_RULE_X_INI_FILE_REMOVED', $rule);
2013-11-11 09:23:05 +00:00
}
else
{
$msg = Text::sprintf('COM_JEDCHECKER_OLD_RULE_X_INI_FILE_NOT_REMOVED', $rule);
2013-11-11 09:23:05 +00:00
}
2013-11-11 09:23:05 +00:00
echo "<p>$msg</p>";
}
}
}
2013-11-11 09:23:05 +00:00
/**
* Load language necessary during the installation
*
* @return void
*/
public function loadLanguage()
{
$extension = $this->extension;
$jlang = Factory::getLanguage();
$path = $this->parent->getParent()->getPath('source') . '/administrator/components/' . $extension;
2013-11-11 09:23:05 +00:00
$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);
}
}