mirror of
https://github.com/joomla-extensions/jedchecker.git
synced 2024-11-27 15:26:36 +00:00
phpcs
This commit is contained in:
parent
84fae50f99
commit
b02eb9d174
@ -1,6 +1,6 @@
|
||||
<?php
|
||||
/**
|
||||
* @author Daniel Dimitrov
|
||||
* @author Daniel Dimitrov <daniel@compojoom.com>
|
||||
* @date 04/08/2012
|
||||
* @copyright Copyright (C) 2008 - 2012 compojoom.com . All rights reserved.
|
||||
* @license GNU General Public License version 2 or later; see LICENSE
|
||||
@ -8,89 +8,92 @@
|
||||
|
||||
defined('_JEXEC') or die('Restricted access');
|
||||
|
||||
|
||||
// Include the rule base class
|
||||
require_once(JPATH_COMPONENT_ADMINISTRATOR.'/models/rule.php');
|
||||
|
||||
require_once JPATH_COMPONENT_ADMINISTRATOR . '/models/rule.php';
|
||||
|
||||
/**
|
||||
* This class searches all files for the _JEXEC check
|
||||
* which prevents direct file access.
|
||||
* class JedcheckerRulesEncoding
|
||||
*
|
||||
* This class checks if base64 encoding is used in the files
|
||||
*
|
||||
* @since 1.0
|
||||
*/
|
||||
class jedcheckerRulesEncoding extends JEDcheckerRule
|
||||
class JedcheckerRulesEncoding extends JEDcheckerRule
|
||||
{
|
||||
/**
|
||||
* The formal ID of this rule. For example: SE1.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $id = 'encoding';
|
||||
/**
|
||||
* The formal ID of this rule. For example: SE1.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $id = 'encoding';
|
||||
|
||||
/**
|
||||
* The title or caption of this rule.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $title = 'COM_JEDCHECKER_RULE_ENCODING';
|
||||
/**
|
||||
* The title or caption of this rule.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $title = 'COM_JEDCHECKER_RULE_ENCODING';
|
||||
|
||||
/**
|
||||
* The description of this rule.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $description = 'COM_JEDCHECKER_RULE_ENCODING_DESC';
|
||||
/**
|
||||
* The description of this rule.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $description = 'COM_JEDCHECKER_RULE_ENCODING_DESC';
|
||||
|
||||
/**
|
||||
* Initiates the file search and check
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function check()
|
||||
{
|
||||
// Find all php files of the extension
|
||||
$files = JFolder::files($this->basedir, '.php$', true, true);
|
||||
|
||||
/**
|
||||
* Initiates the file search and check
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function check()
|
||||
{
|
||||
// Find all php files of the extension
|
||||
$files = JFolder::files($this->basedir, '.php$', true, true);
|
||||
// Iterate through all files
|
||||
foreach ($files as $file)
|
||||
{
|
||||
// Try to find the base64 use in the file
|
||||
if ($this->find($file))
|
||||
{
|
||||
// Add as error to the report if it was not found
|
||||
$this->report->addError($file, JText::_('COM_JEDCHECKER_ERROR_ENCODING'));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Iterate through all files
|
||||
foreach($files as $file)
|
||||
{
|
||||
// Try to find the base64 use in the file
|
||||
if($this->find($file)) {
|
||||
// Add as error to the report if it was not found
|
||||
$this->report->addError($file, JText::_('COM_JEDCHECKER_ERROR_ENCODING'));
|
||||
}
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Reads a file and searches for any encoding function defined in the params
|
||||
* Not a very clever way of doing this, but it should be fine for now
|
||||
*
|
||||
* @param string $file The path to the file
|
||||
*
|
||||
* @return boolean True if the statement was found, otherwise False.
|
||||
*/
|
||||
protected function find($file)
|
||||
{
|
||||
$content = (array) file($file);
|
||||
|
||||
// Get the functions to look for
|
||||
$encodings = explode(',', $this->params->get('encodings'));
|
||||
|
||||
/**
|
||||
* Reads a file and searches for any encoding function defined in the params
|
||||
* Not a very clever way of doing this, but it should be fine for now
|
||||
*
|
||||
* @param string $file The path to the file
|
||||
* @return boolean True if the statement was found, otherwise False.
|
||||
*/
|
||||
protected function find($file)
|
||||
{
|
||||
$content = (array) file($file);
|
||||
foreach ($encodings as $encoding)
|
||||
{
|
||||
$encoding = trim($encoding);
|
||||
|
||||
// Get the functions to look for
|
||||
$encodings = explode(',', $this->params->get('encodings'));
|
||||
foreach ($content AS $line)
|
||||
{
|
||||
// Search for "base64"
|
||||
$pos_1 = stripos($line, $encoding);
|
||||
|
||||
foreach($encodings as $encoding) {
|
||||
$encoding = trim($encoding);
|
||||
foreach ($content AS $line)
|
||||
{
|
||||
// Search for "base64"
|
||||
$pos_1 = stripos($line, $encoding);
|
||||
if ($pos_1 !== false)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ($pos_1 !== false) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
@ -1,6 +1,7 @@
|
||||
<?php
|
||||
/**
|
||||
* @author eaxs
|
||||
* @author eaxs <support@projectfork.net>
|
||||
* @author Daniel Dimitrov <daniel@compojoom.com>
|
||||
* @date 07/06/2012
|
||||
* @copyright Copyright (C) 2008 - 2012 compojoom.com . All rights reserved.
|
||||
* @license GNU General Public License version 2 or later; see LICENSE
|
||||
@ -14,11 +15,14 @@ require_once(JPATH_COMPONENT_ADMINISTRATOR . '/models/rule.php');
|
||||
|
||||
|
||||
/**
|
||||
* class JedcheckerRulesGpl
|
||||
*
|
||||
* This class searches all files for the _JEXEC check
|
||||
* which prevents direct file access.
|
||||
*
|
||||
* @since 1.0
|
||||
*/
|
||||
class jedcheckerRulesGpl extends JEDcheckerRule
|
||||
class JedcheckerRulesGpl extends JEDcheckerRule
|
||||
{
|
||||
/**
|
||||
* The formal ID of this rule. For example: SE1.
|
||||
@ -41,7 +45,6 @@ class jedcheckerRulesGpl extends JEDcheckerRule
|
||||
*/
|
||||
protected $description = 'COM_JEDCHECKER_RULE_PH1_DESC';
|
||||
|
||||
|
||||
/**
|
||||
* Initiates the file search and check
|
||||
*
|
||||
@ -64,18 +67,17 @@ class jedcheckerRulesGpl extends JEDcheckerRule
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Reads a file and searches for the _JEXEC statement
|
||||
*
|
||||
* @param string $file The path to the file
|
||||
* @param string $file - The path to the file
|
||||
*
|
||||
* @return boolean True if the statement was found, otherwise False.
|
||||
* @return boolean True if the statement was found, otherwise False.
|
||||
*/
|
||||
protected function find($file)
|
||||
{
|
||||
|
||||
$content = (array) file($file);
|
||||
|
||||
// Get the constants to look for
|
||||
$licenses = $this->params->get('constants');
|
||||
$licenses = explode(',', $licenses);
|
||||
@ -103,9 +105,12 @@ class jedcheckerRulesGpl extends JEDcheckerRule
|
||||
|
||||
if ($gpl || $gnu || $gpl_long)
|
||||
{
|
||||
$this->report->addInfo($file,
|
||||
JText::_('COM_JEDCHECKER_PH1_LICENSE_FOUND') .':' .'<strong>'.$line.'</strong>',
|
||||
$key);
|
||||
$this->report->addInfo(
|
||||
$file,
|
||||
JText::_('COM_JEDCHECKER_PH1_LICENSE_FOUND') . ':' . '<strong>' . $line . '</strong>',
|
||||
$key
|
||||
);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -116,6 +121,7 @@ class jedcheckerRulesGpl extends JEDcheckerRule
|
||||
|
||||
// Search for the license
|
||||
$found = strpos($line, $license);
|
||||
|
||||
// Skip the line if the license is not found
|
||||
if ($found === false)
|
||||
{
|
||||
@ -123,9 +129,12 @@ class jedcheckerRulesGpl extends JEDcheckerRule
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->report->addInfo($file,
|
||||
JText::_('COM_JEDCHECKER_GPL_COMPATIBLE_LICENSE_WAS_FOUND') . ':'. '<strong>'.$line.'</strong>',
|
||||
$key);
|
||||
$this->report->addInfo(
|
||||
$file,
|
||||
JText::_('COM_JEDCHECKER_GPL_COMPATIBLE_LICENSE_WAS_FOUND') . ':' . '<strong>' . $line . '</strong>',
|
||||
$key
|
||||
);
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@ -1,6 +1,7 @@
|
||||
<?php
|
||||
/**
|
||||
* @author eaxs
|
||||
* @author eaxs <support@projectfork.net>
|
||||
* @author Daniel Dimitrov <daniel@ompojoom.com>
|
||||
* @date 07/06/2012
|
||||
* @copyright Copyright (C) 2008 - 2012 compojoom.com . All rights reserved.
|
||||
* @license GNU General Public License version 2 or later; see LICENSE
|
||||
@ -8,80 +9,81 @@
|
||||
|
||||
defined('_JEXEC') or die('Restricted access');
|
||||
|
||||
|
||||
// Include the rule base class
|
||||
require_once(JPATH_COMPONENT_ADMINISTRATOR.'/models/rule.php');
|
||||
|
||||
require_once JPATH_COMPONENT_ADMINISTRATOR . '/models/rule.php';
|
||||
|
||||
/**
|
||||
* class JedcheckerRulesJexec
|
||||
*
|
||||
* This class searches all files for the _JEXEC check
|
||||
* which prevents direct file access.
|
||||
*
|
||||
* @since 1.0
|
||||
*/
|
||||
class jedcheckerRulesJexec extends JEDcheckerRule
|
||||
class JedcheckerRulesJexec extends JEDcheckerRule
|
||||
{
|
||||
/**
|
||||
* The formal ID of this rule. For example: SE1.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $id = 'PH2';
|
||||
/**
|
||||
* The formal ID of this rule. For example: SE1.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $id = 'PH2';
|
||||
|
||||
/**
|
||||
* The title or caption of this rule.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $title = 'COM_JEDCHECKER_RULE_PH2';
|
||||
/**
|
||||
* The title or caption of this rule.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $title = 'COM_JEDCHECKER_RULE_PH2';
|
||||
|
||||
/**
|
||||
* The description of this rule.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $description = 'COM_JEDCHECKER_RULE_PH2_DESC';
|
||||
/**
|
||||
* The description of this rule.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $description = 'COM_JEDCHECKER_RULE_PH2_DESC';
|
||||
|
||||
/**
|
||||
* Initiates the file search and check
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function check()
|
||||
{
|
||||
// Find all php files of the extension
|
||||
$files = JFolder::files($this->basedir, '.php$', true, true);
|
||||
|
||||
/**
|
||||
* Initiates the file search and check
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function check()
|
||||
{
|
||||
// Find all php files of the extension
|
||||
$files = JFolder::files($this->basedir, '.php$', true, true);
|
||||
// Iterate through all files
|
||||
foreach ($files as $file)
|
||||
{
|
||||
// Try to find the _JEXEC check in the file
|
||||
if (!$this->find($file))
|
||||
{
|
||||
// Add as error to the report if it was not found
|
||||
$this->report->addError($file, JText::_('COM_JEDCHECKER_ERROR_JEXEC_NOT_FOUND'));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Iterate through all files
|
||||
foreach($files as $file)
|
||||
{
|
||||
// Try to find the _JEXEC check in the file
|
||||
if(!$this->find($file)) {
|
||||
// Add as error to the report if it was not found
|
||||
$this->report->addError($file, JText::_('COM_JEDCHECKER_ERROR_JEXEC_NOT_FOUND'));
|
||||
}
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Reads a file and searches for the _JEXEC statement
|
||||
*
|
||||
* @param string $file - The path to the file
|
||||
*
|
||||
* @return boolean True if the statement was found, otherwise False.
|
||||
*/
|
||||
protected function find($file)
|
||||
{
|
||||
$content = (array) file($file);
|
||||
|
||||
|
||||
/**
|
||||
* Reads a file and searches for the _JEXEC statement
|
||||
*
|
||||
* @param string $file The path to the file
|
||||
* @return boolean True if the statement was found, otherwise False.
|
||||
*/
|
||||
protected function find($file)
|
||||
{
|
||||
$content = (array) file($file);
|
||||
|
||||
// Get the constants to look for
|
||||
$defines = $this->params->get('constants');
|
||||
$defines = explode(',', $defines);
|
||||
// Get the constants to look for
|
||||
$defines = $this->params->get('constants');
|
||||
$defines = explode(',', $defines);
|
||||
|
||||
$hascode = 0;
|
||||
|
||||
foreach ($content AS $line)
|
||||
{
|
||||
foreach ($content AS $line)
|
||||
{
|
||||
$tline = trim($line);
|
||||
|
||||
if ($tline == '' || $tline == '<?php' || $tline == '?>')
|
||||
@ -94,42 +96,51 @@ class jedcheckerRulesJexec extends JEDcheckerRule
|
||||
$hascode = 1;
|
||||
}
|
||||
|
||||
// Search for "defined"
|
||||
$pos_1 = stripos($line, 'defined');
|
||||
// Search for "defined"
|
||||
$pos_1 = stripos($line, 'defined');
|
||||
|
||||
// Skip the line if "defined" is not found
|
||||
if ($pos_1 === false) {
|
||||
continue;
|
||||
}
|
||||
// Skip the line if "defined" is not found
|
||||
if ($pos_1 === false)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
// Search for "die".
|
||||
// "or" may not be present depending on syntax
|
||||
$pos_3 = stripos($line, 'die');
|
||||
// Skip the line if "die" is not found
|
||||
if ($pos_3 === false) {
|
||||
continue;
|
||||
}
|
||||
// Search for "die".
|
||||
// "or" may not be present depending on syntax
|
||||
$pos_3 = stripos($line, 'die');
|
||||
|
||||
// Search for the constant name
|
||||
foreach ($defines AS $define)
|
||||
{
|
||||
$define = trim($define);
|
||||
// Skip the line if "die" is not found
|
||||
if ($pos_3 === false)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
// Search for the define
|
||||
$pos_2 = strpos($line, $define);
|
||||
// Skip the line if the define is not found
|
||||
if($pos_2 === false) continue;
|
||||
// Search for the constant name
|
||||
foreach ($defines AS $define)
|
||||
{
|
||||
$define = trim($define);
|
||||
|
||||
// Check the position of the words
|
||||
if($pos_2 > $pos_1 && $pos_3 > $pos_2) {
|
||||
unset($content);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
// Search for the define
|
||||
$pos_2 = strpos($line, $define);
|
||||
|
||||
unset($content);
|
||||
// Skip the line if the define is not found
|
||||
if ($pos_2 === false)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
// Check the position of the words
|
||||
if ($pos_2 > $pos_1 && $pos_3 > $pos_2)
|
||||
{
|
||||
unset($content);
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
unset($content);
|
||||
|
||||
return $hascode ? false : true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,6 +1,7 @@
|
||||
<?php
|
||||
/**
|
||||
* @author eaxs
|
||||
* @author eaxs <support@projectfork.net>
|
||||
* @author Daniel Dimitrov <daniel@compojoom.com>
|
||||
* @date 07/06/2012
|
||||
* @copyright Copyright (C) 2008 - 2012 compojoom.com . All rights reserved.
|
||||
* @license GNU General Public License version 2 or later; see LICENSE
|
||||
@ -10,84 +11,88 @@ defined('_JEXEC') or die('Restricted access');
|
||||
|
||||
|
||||
// Include the rule base class
|
||||
require_once(JPATH_COMPONENT_ADMINISTRATOR.'/models/rule.php');
|
||||
require_once JPATH_COMPONENT_ADMINISTRATOR . '/models/rule.php';
|
||||
|
||||
|
||||
/**
|
||||
* This class searches all xml manifestes for a valid license.
|
||||
* class JedcheckerRulesXMLinfo
|
||||
*
|
||||
* This class searches all xml manifestes for specific tags
|
||||
*
|
||||
* @since 1.0
|
||||
*/
|
||||
class jedcheckerRulesXMLinfo extends JEDcheckerRule
|
||||
class JedcheckerRulesXMLinfo extends JEDcheckerRule
|
||||
{
|
||||
/**
|
||||
* The formal ID of this rule. For example: SE1.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $id = 'INFO_XML';
|
||||
/**
|
||||
* The formal ID of this rule. For example: SE1.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $id = 'INFO_XML';
|
||||
|
||||
/**
|
||||
* The title or caption of this rule.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $title = 'COM_JEDCHECKER_INFO_XML';
|
||||
/**
|
||||
* The title or caption of this rule.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $title = 'COM_JEDCHECKER_INFO_XML';
|
||||
|
||||
/**
|
||||
* The description of this rule.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $description = 'COM_JEDCHECKER_INFO_XML_DESC';
|
||||
/**
|
||||
* The description of this rule.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $description = 'COM_JEDCHECKER_INFO_XML_DESC';
|
||||
|
||||
/**
|
||||
* Initiates the search and check
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function check()
|
||||
{
|
||||
// Find all XML files of the extension
|
||||
$files = JFolder::files($this->basedir, '.xml$', true, true);
|
||||
|
||||
/**
|
||||
* Initiates the search and check
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function check()
|
||||
{
|
||||
// Find all XML files of the extension
|
||||
$files = JFolder::files($this->basedir, '.xml$', true, true);
|
||||
// Iterate through all the xml files
|
||||
foreach ($files as $file)
|
||||
{
|
||||
// Try to find the license
|
||||
$this->find($file);
|
||||
}
|
||||
}
|
||||
|
||||
// Iterate through all the xml files
|
||||
foreach ($files as $file)
|
||||
{
|
||||
// Try to find the license
|
||||
$this->find($file);
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Reads a file and searches for the license
|
||||
*
|
||||
* @param string $file - The path to the file
|
||||
*
|
||||
* @return boolean True if the license was found, otherwise False.
|
||||
*/
|
||||
protected function find($file)
|
||||
{
|
||||
$xml = JFactory::getXML($file);
|
||||
|
||||
// Failed to parse the xml file.
|
||||
// Assume that this is not a extension manifest
|
||||
if (!$xml)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Reads a file and searches for the license
|
||||
*
|
||||
* @param string $file The path to the file
|
||||
* @return boolean True if the license was found, otherwise False.
|
||||
*/
|
||||
protected function find($file)
|
||||
{
|
||||
$xml = JFactory::getXML($file);
|
||||
|
||||
// Failed to parse the xml file.
|
||||
// Assume that this is not a extension manifest
|
||||
if (!$xml) return true;
|
||||
|
||||
// Check if this is an extension manifest
|
||||
// 1.5 uses 'install', 1.6 uses 'extension'
|
||||
// Check if this is an extension manifest
|
||||
// 1.5 uses 'install', 1.6 uses 'extension'
|
||||
if ($xml->getName() != 'install' && $xml->getName() != 'extension')
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
$info[] = JText::sprintf('COM_JEDCHECKER_INFO_XML_NAME_XML',(string)$xml->name);
|
||||
$info[] = JText::sprintf('COM_JEDCHECKER_INFO_XML_VERSION_XML', (string)$xml->version);
|
||||
$info[] = JText::sprintf('COM_JEDCHECKER_INFO_XML_CREATIONDATE_XML', (string)$xml->creationDate);
|
||||
$this->report->addInfo($file, implode('<br />',$info));
|
||||
$info[] = JText::sprintf('COM_JEDCHECKER_INFO_XML_NAME_XML', (string) $xml->name);
|
||||
$info[] = JText::sprintf('COM_JEDCHECKER_INFO_XML_VERSION_XML', (string) $xml->version);
|
||||
$info[] = JText::sprintf('COM_JEDCHECKER_INFO_XML_CREATIONDATE_XML', (string) $xml->creationDate);
|
||||
$this->report->addInfo($file, implode('<br />', $info));
|
||||
|
||||
|
||||
// All checks passed. Return true
|
||||
return true;
|
||||
}
|
||||
// All checks passed. Return true
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@ -1,6 +1,7 @@
|
||||
<?php
|
||||
/**
|
||||
* @author eaxs
|
||||
* @author eaxs <support@projectfork.net>
|
||||
* @author Daniel Dimitrov <daniel@compojoom.com>
|
||||
* @date 07/06/2012
|
||||
* @copyright Copyright (C) 2008 - 2012 compojoom.com . All rights reserved.
|
||||
* @license GNU General Public License version 2 or later; see LICENSE
|
||||
@ -8,95 +9,100 @@
|
||||
|
||||
defined('_JEXEC') or die('Restricted access');
|
||||
|
||||
|
||||
// Include the rule base class
|
||||
require_once(JPATH_COMPONENT_ADMINISTRATOR.'/models/rule.php');
|
||||
|
||||
require_once JPATH_COMPONENT_ADMINISTRATOR . '/models/rule.php';
|
||||
|
||||
/**
|
||||
* class JedcheckerRulesXMLlicense
|
||||
*
|
||||
* This class searches all xml manifestes for a valid license.
|
||||
*
|
||||
* @since 1.0
|
||||
*/
|
||||
class jedcheckerRulesXMLlicense extends JEDcheckerRule
|
||||
class JedcheckerRulesXMLlicense extends JEDcheckerRule
|
||||
{
|
||||
/**
|
||||
* The formal ID of this rule. For example: SE1.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $id = 'PH3';
|
||||
/**
|
||||
* The formal ID of this rule. For example: SE1.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $id = 'PH3';
|
||||
|
||||
/**
|
||||
* The title or caption of this rule.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $title = 'COM_JEDCHECKER_RULE_PH3';
|
||||
/**
|
||||
* The title or caption of this rule.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $title = 'COM_JEDCHECKER_RULE_PH3';
|
||||
|
||||
/**
|
||||
* The description of this rule.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $description = 'COM_JEDCHECKER_RULE_PH3_DESC';
|
||||
/**
|
||||
* The description of this rule.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $description = 'COM_JEDCHECKER_RULE_PH3_DESC';
|
||||
|
||||
/**
|
||||
* Initiates the search and check
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function check()
|
||||
{
|
||||
// Find all XML files of the extension
|
||||
$files = JFolder::files($this->basedir, '.xml$', true, true);
|
||||
|
||||
/**
|
||||
* Initiates the search and check
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function check()
|
||||
{
|
||||
// Find all XML files of the extension
|
||||
$files = JFolder::files($this->basedir, '.xml$', true, true);
|
||||
// Iterate through all the xml files
|
||||
foreach ($files as $file)
|
||||
{
|
||||
// Try to find the license
|
||||
$this->find($file);
|
||||
}
|
||||
}
|
||||
|
||||
// Iterate through all the xml files
|
||||
foreach ($files as $file)
|
||||
{
|
||||
// Try to find the license
|
||||
$this->find($file);
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Reads a file and searches for the license
|
||||
*
|
||||
* @param string $file - The path to the file
|
||||
*
|
||||
* @return boolean True if the license was found, otherwise False.
|
||||
*/
|
||||
protected function find($file)
|
||||
{
|
||||
$xml = JFactory::getXML($file);
|
||||
|
||||
// Failed to parse the xml file.
|
||||
// Assume that this is not a extension manifest
|
||||
if (!$xml)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Reads a file and searches for the license
|
||||
*
|
||||
* @param string $file The path to the file
|
||||
* @return boolean True if the license was found, otherwise False.
|
||||
*/
|
||||
protected function find($file)
|
||||
{
|
||||
$xml = JFactory::getXML($file);
|
||||
|
||||
// Failed to parse the xml file.
|
||||
// Assume that this is not a extension manifest
|
||||
if (!$xml) return true;
|
||||
|
||||
// Check if this is an extension manifest
|
||||
// 1.5 uses 'install', 1.6 uses 'extension'
|
||||
// Check if this is an extension manifest
|
||||
// 1.5 uses 'install', 1.6 uses 'extension'
|
||||
if ($xml->getName() != 'install' && $xml->getName() != 'extension')
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
// Check if there's a license tag
|
||||
if (!isset($xml->license)) {
|
||||
$this->report->addError($file, JText::_('COM_JEDCHECKER_ERROR_XML_LICENSE_NOT_FOUND'));
|
||||
return false;
|
||||
}
|
||||
// Check if there's a license tag
|
||||
if (!isset($xml->license))
|
||||
{
|
||||
$this->report->addError($file, JText::_('COM_JEDCHECKER_ERROR_XML_LICENSE_NOT_FOUND'));
|
||||
|
||||
// Check if the license is gpl
|
||||
if (stripos($xml->license, 'gpl') === false &&
|
||||
stripos($xml->license, 'general public license') === false)
|
||||
{
|
||||
$this->report->addCompat($file, JText::_('COM_JEDCHECKER_ERROR_XML_LICENSE_NOT_GPL'));
|
||||
return false;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
// Check if the license is gpl
|
||||
if (stripos($xml->license, 'gpl') === false
|
||||
&& stripos($xml->license, 'general public license') === false)
|
||||
{
|
||||
$this->report->addCompat($file, JText::_('COM_JEDCHECKER_ERROR_XML_LICENSE_NOT_GPL'));
|
||||
|
||||
// All checks passed. Return true
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
// All checks passed. Return true
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@ -1,6 +1,7 @@
|
||||
<?php
|
||||
/**
|
||||
* @author eaxs
|
||||
* @author eaxs <support@projectfork.net>
|
||||
* @author Daniel Dimitrov <daniel@compojoom.com>
|
||||
* @date 07/06/2012
|
||||
* @copyright Copyright (C) 2008 - 2012 compojoom.com . All rights reserved.
|
||||
* @license GNU General Public License version 2 or later; see LICENSE
|
||||
@ -10,122 +11,124 @@ defined('_JEXEC') or die('Restricted access');
|
||||
|
||||
|
||||
/**
|
||||
* class JEDcheckerRule
|
||||
*
|
||||
* Serves as a base class for all JED rules.
|
||||
*
|
||||
* @since 1.0
|
||||
*/
|
||||
class JEDcheckerRule extends JObject
|
||||
{
|
||||
/**
|
||||
* The formal ID of this rule. For example: SE1.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $id;
|
||||
/**
|
||||
* 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 title or caption of this rule.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $title;
|
||||
|
||||
/**
|
||||
* The description of this rule.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $description;
|
||||
/**
|
||||
* The description of this rule.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $description;
|
||||
|
||||
/**
|
||||
* The absolute path to the target extension.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $basedir;
|
||||
/**
|
||||
* The absolute path to the target extension.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $basedir;
|
||||
|
||||
/**
|
||||
* Optional rule parameters.
|
||||
*
|
||||
* @var object
|
||||
*/
|
||||
protected $params;
|
||||
/**
|
||||
* Optional rule parameters.
|
||||
*
|
||||
* @var object
|
||||
*/
|
||||
protected $params;
|
||||
|
||||
/**
|
||||
* The report summary
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $report;
|
||||
/**
|
||||
* 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);
|
||||
|
||||
/**
|
||||
* Constructor. Initialises variables.
|
||||
*
|
||||
* @param mixed $properties See JObject::__construct
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
||||
// Initialise vars
|
||||
if(empty($this->report)) {
|
||||
// Create a new report
|
||||
require_once (JPATH_COMPONENT_ADMINISTRATOR.'/models/report.php');
|
||||
$this->report = new JEDcheckerReport($properties);
|
||||
}
|
||||
/**
|
||||
* Performs the rule check. This method should be overloaded!
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function check()
|
||||
{
|
||||
// Overload this method
|
||||
}
|
||||
|
||||
// Try to load the params
|
||||
if(empty($this->params)) {
|
||||
$this->params = $this->loadParams();
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Attempts to load a .ini param file of this rule.
|
||||
*
|
||||
* @return JRegistry
|
||||
*/
|
||||
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';
|
||||
|
||||
$params = JRegistry::getInstance('jedchecker.rule.' . $file_name);
|
||||
|
||||
/**
|
||||
* Performs the rule check. This method should be overloaded!
|
||||
*
|
||||
*/
|
||||
public function check()
|
||||
{
|
||||
// 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);
|
||||
|
||||
/**
|
||||
* Attempts to load a .ini param file of this rule.
|
||||
*
|
||||
* @return JRegistry
|
||||
*/
|
||||
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';
|
||||
if (is_object($obj))
|
||||
{
|
||||
$params->loadObject($obj);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$params = JRegistry::getInstance('jedchecker.rule.'.$file_name);
|
||||
|
||||
// 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
|
||||
jimport('joomla.filesystem.file');
|
||||
$data = JFile::read($params_file);
|
||||
|
||||
if($data) {
|
||||
$obj = (object) parse_ini_string($data);
|
||||
|
||||
if(is_object($obj)) {
|
||||
$params->loadObject($obj);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $params;
|
||||
}
|
||||
return $params;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user