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/libraries/rules/xmlinfo.php

122 lines
2.9 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');
// Include the rule base class
2013-11-05 20:17:39 +00:00
require_once JPATH_COMPONENT_ADMINISTRATOR . '/models/rule.php';
/**
2013-11-05 20:17:39 +00:00
* class JedcheckerRulesXMLinfo
*
2013-11-05 20:17:39 +00:00
* This class searches all xml manifestes for specific tags
*
* @since 1.0
*/
2013-11-05 20:17:39 +00:00
class JedcheckerRulesXMLinfo extends JEDcheckerRule
{
2013-11-05 20:17:39 +00:00
/**
* 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 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);
// 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)
{
2016-05-25 16:19:19 +00:00
$xml = JFactory::getXml($file);
2013-11-05 20:17:39 +00:00
2019-03-09 19:44:14 +00:00
// Get all the info about the file
$folder_info = pathinfo($file);
// Get the folder path
$folder_path = $folder_info['dirname'];
// Get the folder name
$folder_name = $folder_info['dirname'];
$folder_name_exploded = explode(DIRECTORY_SEPARATOR,$folder_name);
if ( is_array($folder_name_exploded) ) {
$folder_name = end($folder_name_exploded);
}
// Load the language of the extension (if any)
$lang = JFactory::getLanguage();
$lang->load($folder_name,$folder_path);
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;
}
2013-11-05 20:17:39 +00:00
// Check if this is an extension manifest
// 1.5 uses 'install', 1.6 uses 'extension'
if ($xml->getName() != 'install' && $xml->getName() != 'extension')
{
return true;
}
2019-03-09 19:44:14 +00:00
// Get the real extension's name now that the language has been loaded
(string) $extension_name = $lang->_($xml->name);
$info[] = JText::sprintf('COM_JEDCHECKER_INFO_XML_NAME_XML', $extension_name);
2013-11-05 20:17:39 +00:00
$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));
2013-11-05 20:17:39 +00:00
// All checks passed. Return true
return true;
}
}