31
2
mirror of https://github.com/joomla-extensions/jedchecker.git synced 2024-06-26 08:02:35 +00:00

adding a new rule that will check the name, version and creationDate from a xml file

This commit is contained in:
Daniel Dimitrov 2012-12-13 11:33:17 +01:00
parent baf2248deb
commit 0a839fbe84
4 changed files with 172 additions and 10 deletions

View File

@ -0,0 +1,93 @@
<?php
/**
* @author eaxs
* @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
*/
defined('_JEXEC') or die('Restricted access');
// Include the rule base class
require_once(JPATH_COMPONENT_ADMINISTRATOR.'/models/rule.php');
/**
* This class searches all xml manifestes for a valid license.
*
*/
class jedcheckerRulesXMLinfo extends JEDcheckerRule
{
/**
* 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)
{
$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;
}
$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;
}
}

View File

@ -32,13 +32,13 @@ class JEDcheckerReport extends JObject
protected $basedir;
/**
* Constructor. Initialises variables.
*
* @param mixed $properties See JObject::__construct
*
* @return void
*/
/**
* Constructor. Initialises variables.
*
* @param mixed $properties See JObject::__construct
*
* @return \JEDcheckerReport
*/
public function __construct($properties = null)
{
// Construct JObject
@ -60,11 +60,13 @@ class JEDcheckerReport extends JObject
$this->data['errors'] = array();
$this->data['compat'] = array();
$this->data['info'] = array();
$this->data['count'] = new stdClass();
$this->data['count']->total = 0;
$this->data['count']->errors = 0;
$this->data['count']->compat = 0;
$this->data['count']->info = 0;
}
@ -74,7 +76,7 @@ class JEDcheckerReport extends JObject
* @param string $location The location of the error. Can be a path to a file or dir.
* @param string $text An optional description of the error.
* @param integer $line If $location is a file, you may specify the line where the
* error occured.
* error occurred.
*
* @return void
*/
@ -88,6 +90,26 @@ class JEDcheckerReport extends JObject
$this->addItem($item, 'errors');
}
/**
* Adds an error to the report.
*
* @param string $location The location of the error. Can be a path to a file or dir.
* @param string $text An optional description of the error.
* @param integer $line If $location is a file, you may specify the line where the
* error occurred.
*
* @return void
*/
public function addInfo($location, $text = NULL, $line = 0)
{
$item = new stdClass();
$item->location = $location;
$item->line = $line;
$item->text = (empty($text) ? '' : JText::_($text));
$this->addItem($item, 'info');
}
/**
* Adds a compatibility issue to the report.
@ -95,7 +117,7 @@ class JEDcheckerReport extends JObject
* @param string $location The location of the issue. Can be a path to a file or dir.
* @param string $text An optional description of the issue
* @param integer $line If $location is a file, you may specify the line where the
* issue occured.
* issue occurred.
*
* @return void
*/
@ -128,6 +150,7 @@ class JEDcheckerReport extends JObject
else {
$error_count = $this->data['count']->errors;
$compat_count = $this->data['count']->compat;
$info_count = $this->data['count']->info;
// Go through the error list
if($error_count > 0) {
@ -188,6 +211,37 @@ class JEDcheckerReport extends JObject
$html[] = '</ul>';
}
// Go through the compat list
if($info_count > 0) {
$html[] = '<strong>'.$info_count. ' '.JText::_('COM_JEDCHECKER_INFO').'</strong>';
$html[] = '<ul class="jedchecker-info-message">';
foreach($this->data['info'] AS $i => $item)
{
$num = $i + 1;
// Add the error count number
$html[] = '<li><p><strong>#'.str_pad($num, 3, '0', STR_PAD_LEFT).'</strong> ';
$html[] = $item->location;
// Add line information if given
if($item->line > 0) {
$html[] = ' '.JText::_('COM_JEDCHECKER_IN_LINE').': <strong>'.$item->line.'</strong>';
}
$html[] = '</p>';
// Add text if given
if(!empty($item->text)) {
$html[] = '<small>'.$item->text.'</small>';
}
$html[] = '</li>';
}
$html[] = '</ul>';
}
}

View File

@ -31,4 +31,10 @@ COM_JEDCHECKER_IN_LINE="in line"
COM_JEDCHECKER_ERROR_ENCODING="You've used encoding in this file? This is not an error, but an editor will have to review this file!"
COM_JEDCHECKER_RULE_ENCODING="Base64 or other type of encoding in the files"
COM_JEDCHECKER_RULE_ENCODING_DESC="As developers we are fully aware that the base64 and similar functions have a valid place in each extensions(like URL redirects or data storage). However if you use those to make it harder for users to read your code or to mask backlinks the JED might not accept your listing submission (this is not in the spirit of GPL anyway!). An editor will review your code and determine if the way you use the base64 matches the rules of the JED. This might slow your listing review time. So the rule of thumb is - don't do fishy stuff and avoid encoding your code if possible!"
COM_JEDCHECKER_LEAVE_A_REVIEW_JED="If you use this component, please post a rating and a review at the <a href='%s' title='JED' target='_blank'>Joomla! Extensions Directory</a>."
COM_JEDCHECKER_LEAVE_A_REVIEW_JED="If you use this component, please post a rating and a review at the <a href='%s' title='JED' target='_blank'>Joomla! Extensions Directory</a>."
COM_JEDCHECKER_INFO="Info"
COM_JEDCHECKER_INFO_XML="Just some info about the extension xml files"
COM_JEDCHECKER_INFO_XML_DESC="This is not a rule, just a convenience check. We go through the xml files and grab the value for the name tag. Useful information for the "filename and install as" fields in the jed submission form"
COM_JEDCHECKER_INFO_XML_NAME_XML="The name tag in this file is: %s"
COM_JEDCHECKER_INFO_XML_VERSION_XML="Version tag has the value: %s"
COM_JEDCHECKER_INFO_XML_CREATIONDATE_XML="The creationDate tag has the value: %s"

View File

@ -45,4 +45,13 @@
.success {
color: green;
font-weight: bold;
}
.jedchecker-info-message {
background-color: #D9EDF7;
border: 1px solid #BCE8F1;
color: #3A87AD;
margin: 5px;
padding: 5px;
list-style:none;
}