33
2
mirror of https://github.com/joomla-extensions/jedchecker.git synced 2024-11-12 00:06:27 +00:00
jedchecker/administrator/components/com_jedchecker/models/rule.php

143 lines
2.8 KiB
PHP
Raw Normal View History

<?php
/**
2019-03-09 19:44:14 +00:00
* @package Joomla.JEDChecker
*
2019-03-10 16:09:42 +00:00
* @copyright Copyright (C) 2017 - 2019 Open Source Matters, Inc. All rights reserved.
* Copyright (C) 2008 - 2016 compojoom.com . All rights reserved.
2019-03-10 08:49:52 +00:00
* @author Daniel Dimitrov <daniel@compojoom.com>
* eaxs <support@projectfork.net>
*
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');
2019-03-09 19:44:14 +00:00
use Joomla\Registry\Registry;
/**
2013-11-05 20:17:39 +00:00
* class JEDcheckerRule
*
* Serves as a base class for all JED rules.
*
2013-11-05 20:17:39 +00:00
* @since 1.0
*/
class JEDcheckerRule extends JObject
{
2013-11-05 20:17:39 +00:00
/**
* The formal ID of this rule. For example: SE1.
*
* @var string
*/
protected $id;
/**
* The title or caption of this rule.
*
* @var string
*/
protected $title;
/**
* The description of this rule.
*
* @var string
*/
protected $description;
/**
* The absolute path to the target extension.
*
* @var string
*/
protected $basedir;
/**
* Optional rule parameters.
*
* @var object
*/
protected $params;
/**
* The report summary
*
* @var array
*/
protected $report;
/**
* Constructor. Initialises variables.
*
* @param mixed $properties - See JObject::__construct
*/
public function __construct($properties = null)
{
// Construct JObject
parent::__construct($properties);
// Initialise vars
if (empty($this->report))
{
// Create a new report
require_once JPATH_COMPONENT_ADMINISTRATOR . '/models/report.php';
$this->report = new JEDcheckerReport($properties);
}
// Try to load the params
if (empty($this->params))
{
$this->params = $this->loadParams();
}
}
/**
* Performs the rule check. This method should be overloaded!
*
* @return void
*/
public function check()
{
// Overload this method
}
/**
* Attempts to load a .ini param file of this rule.
*
2016-05-25 16:10:08 +00:00
* @return Joomla\Registry\Registry
2013-11-05 20:17:39 +00:00
*/
protected function loadParams()
{
// Try to determine the name and location of the params file
$file_name = str_replace('jedcheckerrules', '', strtolower(get_class($this)));
$params_file = JPATH_COMPONENT_ADMINISTRATOR . '/libraries/rules/' . $file_name . '.ini';
2019-03-09 19:44:14 +00:00
$params = new Registry('jedchecker.rule.' . $file_name);
//$params = $registry->getInstance('jedchecker.rule.' . $file_name);
//$params = Joomla\Registry\Registry::getInstance('jedchecker.rule.' . $file_name);
2013-11-05 20:17:39 +00:00
// Load the params from the ini file
if (file_exists($params_file))
{
// Due to a bug in Joomla 2.5.6, this method cannot be used
// $params->loadFile($params_file, 'INI');
// Get the contents of the file
$data = file_get_contents($params_file);
if ($data)
{
$obj = (object) parse_ini_string($data);
if (is_object($obj))
{
$params->loadObject($obj);
}
}
}
return $params;
}
}