33
2
mirror of https://github.com/joomla-extensions/jedchecker.git synced 2024-11-16 18:15:18 +00:00
jedchecker/administrator/components/com_jedchecker/libraries/rules/xmllicense.php

119 lines
2.5 KiB
PHP
Raw Permalink Normal View History

2012-06-26 10:37:12 +00:00
<?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
2012-06-26 10:37:12 +00:00
*/
defined('_JEXEC') or die('Restricted access');
use Joomla\CMS\Language\Text;
// Include the rule base class
2013-11-05 20:17:39 +00:00
require_once JPATH_COMPONENT_ADMINISTRATOR . '/models/rule.php';
// Include the helper class
require_once JPATH_COMPONENT_ADMINISTRATOR . '/libraries/helper.php';
2012-06-26 10:37:12 +00:00
/**
2013-11-05 20:17:39 +00:00
* class JedcheckerRulesXMLlicense
*
2023-08-22 11:01:53 +00:00
* This class searches all xml manifests for a valid license.
2012-06-26 10:37:12 +00:00
*
2013-11-05 20:17:39 +00:00
* @since 1.0
2012-06-26 10:37:12 +00:00
*/
2013-11-05 20:17:39 +00:00
class JedcheckerRulesXMLlicense extends JEDcheckerRule
2012-06-26 10:37:12 +00:00
{
2013-11-05 20:17:39 +00:00
/**
* 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 description of this rule.
*
* @var string
*/
protected $description = 'COM_JEDCHECKER_RULE_PH3_DESC';
/**
* The ordering value to sort rules in the menu.
*
* @var integer
*/
public static $ordering = 100;
2013-11-05 20:17:39 +00:00
/**
* Initiates the search and check
*
* @return void
*/
public function check()
{
2021-09-09 07:32:52 +00:00
$this->report->setDefaultSubtype($this->id);
2013-11-05 20:17:39 +00:00
// Find all XML files of the extension
$files = JEDCheckerHelper::findManifests($this->basedir);
2013-11-05 20:17:39 +00:00
// 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)
{
2021-02-13 20:01:07 +00:00
$xml = simplexml_load_file($file);
2013-11-05 20:17:39 +00:00
// Failed to parse the xml file.
// Assume that this is not a extension manifest
if (!$xml)
{
return true;
}
2012-06-26 10:37:12 +00:00
2013-11-05 20:17:39 +00:00
// Check if there's a license tag
if (!isset($xml->license))
{
$this->report->addError($file, Text::_('COM_JEDCHECKER_ERROR_XML_LICENSE_NOT_FOUND'));
2012-06-26 10:37:12 +00:00
2013-11-05 20:17:39 +00:00
return false;
}
2012-06-26 10:37:12 +00:00
2013-11-05 20:17:39 +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, Text::_('COM_JEDCHECKER_ERROR_XML_LICENSE_NOT_GPL'));
2013-11-05 20:17:39 +00:00
return false;
}
2012-06-26 10:37:12 +00:00
2013-11-05 20:17:39 +00:00
// All checks passed. Return true
return true;
}
2012-06-26 10:37:12 +00:00
}