mirror of
https://github.com/joomla-extensions/jedchecker.git
synced 2024-12-18 00:24:24 +00:00
added warning handling for error reporting
This commit is contained in:
parent
dac3bf2429
commit
84fae50f99
@ -1,24 +1,26 @@
|
|||||||
<?php
|
<?php
|
||||||
/**
|
/**
|
||||||
* @author Denis Dulici
|
* @author Denis Dulici <denis@mijosoft.com>
|
||||||
* @date 18/08/2013
|
* @date 18.08.2013
|
||||||
* @copyright Copyright (C) 2008 - 2013 mijosoft.com . All rights reserved.
|
* @copyright Copyright (C) 2008 - 2013 mijosoft.com . All rights reserved.
|
||||||
* @license GNU General Public License version 2 or later; see LICENSE
|
* @license GNU General Public License version 2 or later; see LICENSE
|
||||||
*/
|
*/
|
||||||
|
|
||||||
defined('_JEXEC') or die('Restricted access');
|
defined('_JEXEC') or die('Restricted access');
|
||||||
|
|
||||||
|
|
||||||
// Include the rule base class
|
// 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
|
* JedcheckerRulesErrorreporting
|
||||||
* which prevents direct file access.
|
|
||||||
*
|
*
|
||||||
|
* 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.
|
* The formal ID of this rule. For example: SE1.
|
||||||
@ -56,19 +58,20 @@ class jedcheckerRulesErrorreporting extends JEDcheckerRule
|
|||||||
foreach ($files as $file)
|
foreach ($files as $file)
|
||||||
{
|
{
|
||||||
// Try to find the base64 use in the file
|
// Try to find the base64 use in the file
|
||||||
if($this->find($file)) {
|
if ($this->find($file))
|
||||||
|
{
|
||||||
// Add as error to the report if it was not found
|
// Add as error to the report if it was not found
|
||||||
$this->report->addError($file, JText::_('COM_JEDCHECKER_ERROR_ERRORREPORTING'));
|
$this->report->addWarning($file, JText::_('COM_JEDCHECKER_ERROR_ERRORREPORTING'));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Reads a file and searches for any encoding function defined in the params
|
* 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
|
* Not a very clever way of doing this, but it should be fine for now
|
||||||
*
|
*
|
||||||
* @param string $file The path to the file
|
* @param string $file - The path to the file
|
||||||
|
*
|
||||||
* @return boolean True if the statement was found, otherwise False.
|
* @return boolean True if the statement was found, otherwise False.
|
||||||
*/
|
*/
|
||||||
protected function find($file)
|
protected function find($file)
|
||||||
@ -78,14 +81,17 @@ class jedcheckerRulesErrorreporting extends JEDcheckerRule
|
|||||||
// Get the functions to look for
|
// Get the functions to look for
|
||||||
$encodings = explode(',', $this->params->get('errorreportings'));
|
$encodings = explode(',', $this->params->get('errorreportings'));
|
||||||
|
|
||||||
foreach($encodings as $encoding) {
|
foreach ($encodings as $encoding)
|
||||||
|
{
|
||||||
$encoding = trim($encoding);
|
$encoding = trim($encoding);
|
||||||
|
|
||||||
foreach ($content AS $line)
|
foreach ($content AS $line)
|
||||||
{
|
{
|
||||||
// Search for "base64"
|
// Search for "base64"
|
||||||
$pos_1 = stripos($line, $encoding);
|
$pos_1 = stripos($line, $encoding);
|
||||||
|
|
||||||
if ($pos_1 !== false) {
|
if ($pos_1 !== false)
|
||||||
|
{
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -69,6 +69,7 @@ class JEDcheckerReport extends JObject
|
|||||||
$this->data['count']->total = 0;
|
$this->data['count']->total = 0;
|
||||||
$this->data['count']->errors = 0;
|
$this->data['count']->errors = 0;
|
||||||
$this->data['count']->compat = 0;
|
$this->data['count']->compat = 0;
|
||||||
|
$this->data['count']->warning = 0;
|
||||||
$this->data['count']->info = 0;
|
$this->data['count']->info = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -132,6 +133,26 @@ class JEDcheckerReport extends JObject
|
|||||||
$this->addItem($item, 'compat');
|
$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.
|
* Formats the existing report data into HTML and returns it.
|
||||||
*
|
*
|
||||||
@ -153,6 +174,7 @@ class JEDcheckerReport extends JObject
|
|||||||
$error_count = $this->data['count']->errors;
|
$error_count = $this->data['count']->errors;
|
||||||
$compat_count = $this->data['count']->compat;
|
$compat_count = $this->data['count']->compat;
|
||||||
$info_count = $this->data['count']->info;
|
$info_count = $this->data['count']->info;
|
||||||
|
$warning_count = $this->data['count']->warning;
|
||||||
|
|
||||||
// Go through the error list
|
// Go through the error list
|
||||||
if ($error_count > 0)
|
if ($error_count > 0)
|
||||||
@ -253,6 +275,40 @@ class JEDcheckerReport extends JObject
|
|||||||
|
|
||||||
$html[] = '</ul>';
|
$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);
|
return implode('', $html);
|
||||||
|
@ -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_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_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="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_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="Info"
|
||||||
COM_JEDCHECKER_INFO_XML="Just some info about the extension xml files"
|
COM_JEDCHECKER_INFO_XML="Just some info about the extension xml files"
|
||||||
@ -44,3 +44,4 @@ COM_JEDCHECKER_RULE_PH1_DESC="A notice is required on each PHP file stating that
|
|||||||
COM_JEDCHECKER_ERROR_GPL_NOT_FOUND="GPL or compatible license was not found"
|
COM_JEDCHECKER_ERROR_GPL_NOT_FOUND="GPL or compatible license was not found"
|
||||||
COM_JEDCHECKER_PH1_LICENSE_FOUND="GPL license was 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"
|
@ -55,3 +55,14 @@
|
|||||||
padding: 5px;
|
padding: 5px;
|
||||||
list-style:none;
|
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;
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user