31
2
mirror of https://github.com/joomla-extensions/jedchecker.git synced 2024-05-29 03:40:47 +00:00

added warning handling for error reporting

This commit is contained in:
Daniel Dimitrov 2013-11-05 21:04:03 +01:00
parent dac3bf2429
commit 84fae50f99
4 changed files with 146 additions and 72 deletions

View File

@ -1,96 +1,102 @@
<?php
/**
* @author Denis Dulici
* @date 18/08/2013
* @author Denis Dulici <denis@mijosoft.com>
* @date 18.08.2013
* @copyright Copyright (C) 2008 - 2013 mijosoft.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');
require_once JPATH_COMPONENT_ADMINISTRATOR . '/models/rule.php';
/**
* This class searches all files for the _JEXEC check
* which prevents direct file access.
* JedcheckerRulesErrorreporting
*
* This class searches all files for the php error_reporting function
* Developers are discouraged to use this in their joomla extensions
* as users are able to set the error reporting in the global config
*
* @since 1.5
*/
class jedcheckerRulesErrorreporting extends JEDcheckerRule
class JedcheckerRulesErrorreporting extends JEDcheckerRule
{
/**
* The formal ID of this rule. For example: SE1.
*
* @var string
*/
protected $id = 'errorreporting';
/**
* The formal ID of this rule. For example: SE1.
*
* @var string
*/
protected $id = 'errorreporting';
/**
* The title or caption of this rule.
*
* @var string
*/
protected $title = 'COM_JEDCHECKER_RULE_ERRORREPORTING';
/**
* The title or caption of this rule.
*
* @var string
*/
protected $title = 'COM_JEDCHECKER_RULE_ERRORREPORTING';
/**
* The description of this rule.
*
* @var string
*/
protected $description = 'COM_JEDCHECKER_RULE_ERRORREPORTING_DESC';
/**
* The description of this rule.
*
* @var string
*/
protected $description = 'COM_JEDCHECKER_RULE_ERRORREPORTING_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_ERRORREPORTING'));
}
}
}
// 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->addWarning($file, JText::_('COM_JEDCHECKER_ERROR_ERRORREPORTING'));
}
}
}
/**
* 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);
/**
* 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('errorreportings'));
// Get the functions to look for
$encodings = explode(',', $this->params->get('errorreportings'));
foreach ($encodings as $encoding)
{
$encoding = trim($encoding);
foreach($encodings as $encoding) {
$encoding = trim($encoding);
foreach ($content AS $line)
{
// Search for "base64"
$pos_1 = stripos($line, $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;
}
}

View File

@ -69,6 +69,7 @@ class JEDcheckerReport extends JObject
$this->data['count']->total = 0;
$this->data['count']->errors = 0;
$this->data['count']->compat = 0;
$this->data['count']->warning = 0;
$this->data['count']->info = 0;
}
@ -132,6 +133,26 @@ class JEDcheckerReport extends JObject
$this->addItem($item, 'compat');
}
/**
* Adds a warning issue to the report.
*
* @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 occurred.
*
* @return void
*/
public function addWarning($location, $text = null, $line = 0)
{
$item = new stdClass;
$item->location = $location;
$item->line = $line;
$item->text = $text;
$this->addItem($item, 'warning');
}
/**
* Formats the existing report data into HTML and returns it.
*
@ -153,6 +174,7 @@ class JEDcheckerReport extends JObject
$error_count = $this->data['count']->errors;
$compat_count = $this->data['count']->compat;
$info_count = $this->data['count']->info;
$warning_count = $this->data['count']->warning;
// Go through the error list
if ($error_count > 0)
@ -253,6 +275,40 @@ class JEDcheckerReport extends JObject
$html[] = '</ul>';
}
// Go through the warning list
if ($warning_count > 0)
{
$html[] = '<strong>' . $warning_count . ' ' . JText::_('COM_JEDCHECKER_WARNING') . '</strong>';
$html[] = '<ul class="jedchecker-warning-message">';
foreach ($this->data['warning'] AS $i => $item)
{
$num = $i + 1;
// Add the warning 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>';
}
}
return implode('', $html);

View File

@ -31,7 +31,7 @@ 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_ERROR_ERRORREPORTING="You've used error_reporting(0) in this file."
COM_JEDCHECKER_RULE_ERRORREPORTING="error_reporting(0) in the files"
COM_JEDCHECKER_RULE_ERRORREPORTING_DESC="error_reporting(0) is not allowed by JED as there is already such an option into the Joomla Global Configuration."
COM_JEDCHECKER_RULE_ERRORREPORTING_DESC="Using error_reporting(0) is discouraged as Joomla provides an error_reporting option in the Global Configuration. Currently your extensions will be published on the JED if you have this in your files, but this might change in the future! So better don't use this to disable the error reporting."
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"
@ -43,4 +43,5 @@ COM_JEDCHECKER_RULE_PH1="PHP Headers missing GPL License Notice"
COM_JEDCHECKER_RULE_PH1_DESC="A notice is required on each PHP file stating that the file is licensed GPL (or other compatible accepted license). More info <a href='http://extensions.joomla.org/index.php?option=com_content&id=50' target='_blank'>here</a>."
COM_JEDCHECKER_ERROR_GPL_NOT_FOUND="GPL or compatible license was not found"
COM_JEDCHECKER_PH1_LICENSE_FOUND="GPL license was found"
COM_JEDCHECKER_GPL_COMPATIBLE_LICENSE_WAS_FOUND="GPL compatible license was found"
COM_JEDCHECKER_GPL_COMPATIBLE_LICENSE_WAS_FOUND="GPL compatible license was found"
COM_JEDCHECKER_WARNING="Warning"

View File

@ -54,4 +54,15 @@
margin: 5px;
padding: 5px;
list-style:none;
}
.jedchecker-warning-message {
background-color: #FCF8E3;
border: 1px solid #FBEED5;
border-radius: 4px;
color: #C09853;
margin: 5px;
padding: 5px;
text-shadow: 0 1px 0 rgba(255, 255, 255, 0.5);
list-style:none;
}