33
2
mirror of https://github.com/joomla-extensions/jedchecker.git synced 2024-11-17 02:25:10 +00:00
jedchecker/source/administrator/components/com_jedchecker/libraries/rules/xmllicense.php

103 lines
2.5 KiB
PHP
Raw Normal View History

2012-06-26 10:37:12 +00:00
<?php
/**
* @author eaxs
* @date 07/06/2012
2012-06-26 10:37:12 +00:00
* @copyright Copyright (C) 2008 - 2012 compojoom.com . All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE
*/
defined('_JEXEC') or die('Restricted access');
// Include the rule base class
require_once(JPATH_COMPONENT_ADMINISTRATOR.'/models/rule.php');
2012-06-26 10:37:12 +00:00
/**
* This class searches all xml manifestes for a valid license.
*
*/
class jedcheckerRulesXMLlicense extends JEDcheckerRule
2012-06-26 10:37:12 +00:00
{
/**
* The formal ID of this rule. For example: SE1.
*
* @var string
2012-06-26 10:37:12 +00:00
*/
protected $id = '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';
2012-06-26 10:37:12 +00:00
/**
* Initiates the search and check
*
* @return void
*/
public function check()
2012-06-26 10:37:12 +00:00
{
// Find all XML files of the extension
$files = JFolder::files($this->basedir, '.xml$', true, true);
2012-06-26 10:37:12 +00:00
// Iterate through all the xml files
2012-06-26 10:37:12 +00:00
foreach ($files as $file)
{
// Try to find the license
$this->find($file);
2012-06-26 10:37:12 +00:00
}
}
/**
* 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'
if ($xml->getName() != 'install' && $xml->getName() != 'extension')
{
return true;
}
// Check if there's a license tag
if (!isset($xml->license)) {
$this->report->addError($file, 'COM_JEDCHECKER_ERROR_XML_LICENSE_NOT_FOUND');
return false;
}
2012-06-26 10:37:12 +00:00
// Check if the license is gpl
if (stripos($xml->license, 'gpl') === false &&
stripos($xml->license, 'general public license') === false)
{
$this->report->addCompat($file, 'COM_JEDCHECKER_ERROR_XML_LICENSE_NOT_GPL');
2012-06-26 10:37:12 +00:00
return false;
}
// All checks passed. Return true
return true;
}
}