From 3cbb7d7b0a3b61c98c7a7bca817cbb6626380ae6 Mon Sep 17 00:00:00 2001
From: eaxs #'.str_pad($num, 3, '0', STR_PAD_LEFT).' ';
+ $html[] = $item->location;
+
+ // Add line information if given
+ if($item->line > 0) {
+ $html[] = ' '.JText::_('COM_JEDCHECKER_IN_LINE').': '.$item->line.'';
+ }
+
+ $html[] = '
-
-
-
+
+ get('id').' - '.JText::_($rule->get('title'));?>
+
+ get('description')); ?>
'
+ . $report->getHTML();
}
-}
\ No newline at end of file
+}
diff --git a/source/administrator/components/com_jedchecker/libraries/rules/htmlindexes.ini b/source/administrator/components/com_jedchecker/libraries/rules/htmlindexes.ini
new file mode 100644
index 0000000..c675602
--- /dev/null
+++ b/source/administrator/components/com_jedchecker/libraries/rules/htmlindexes.ini
@@ -0,0 +1,10 @@
+; This is the configuration file of the HTLM indexes rule.
+;
+; @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
+
+
+; Joomla system directories
+sysfolders = "administrator, components, language, language/.*, media, modules, plugins, plugins/content, plugins/editors, plugins/editors-xtd, plugins/finder, plugins/search, plugins/system, plugins/user"
diff --git a/source/administrator/components/com_jedchecker/libraries/rules/htmlindexes.php b/source/administrator/components/com_jedchecker/libraries/rules/htmlindexes.php
index 7f2ac54..9480c41 100644
--- a/source/administrator/components/com_jedchecker/libraries/rules/htmlindexes.php
+++ b/source/administrator/components/com_jedchecker/libraries/rules/htmlindexes.php
@@ -1,7 +1,7 @@
findHtml($startFolder, 1);
+ $this->findHtml($this->basedir, 1);
/**
* let us "merge" the 2 arrays
@@ -23,18 +49,14 @@ class jedcheckerRulesHtmlindexes {
*/
$indexes = array_replace($this->folders, $this->indexes);
- echo ''.JText::_('COM_JEDCHECKER_RULE_SE1') . '
';
if(count($indexes) && in_array(false, $indexes)) {
- foreach($indexes as $key => $index) {
+ foreach($indexes as $key => $index)
+ {
if(!$index) {
- echo $key . '
';
+ $this->report->addError($key, 'COM_JEDCHECKER_ERROR_HTML_INDEX_NOT_FOUND');
}
}
- } else {
- echo ''.JText::_('COM_JEDCHECKER_EVERYTHING_SEEMS_TO_BE_FINE_WITH_THAT_RULE').'';
}
-
-
}
/**
@@ -45,25 +67,12 @@ class jedcheckerRulesHtmlindexes {
*/
public function findHtml($start, $root = 0)
{
-
// array of system folders (regex)
// will match paths ending with these folders
- $system_folders = array(
- 'administrator',
- 'components',
- 'language',
- 'language/.*',
- 'media',
- 'modules',
- 'plugins',
- 'plugins/content',
- 'plugins/editors',
- 'plugins/editors-xtd',
- 'plugins/finder',
- 'plugins/search',
- 'plugins/system',
- 'plugins/user'
- );
+ $system_folders = explode(',', $this->params->get('sysfolders'));
+
+ // Make sure there are no spaces
+ array_walk($system_folders, create_function('&$v', '$v = trim($v);'));
$iterator = new DirectoryIterator($start);
diff --git a/source/administrator/components/com_jedchecker/libraries/rules/jexec.ini b/source/administrator/components/com_jedchecker/libraries/rules/jexec.ini
new file mode 100644
index 0000000..0b2d6eb
--- /dev/null
+++ b/source/administrator/components/com_jedchecker/libraries/rules/jexec.ini
@@ -0,0 +1,10 @@
+; This is the configuration file of the JEXEC rule.
+;
+; @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
+
+
+; The valid constants to search for
+constants ="_JEXEC, JPATH_PLATFORM, JPATH_BASE, AKEEBAENGINE, WF_EDITOR"
diff --git a/source/administrator/components/com_jedchecker/libraries/rules/jexec.php b/source/administrator/components/com_jedchecker/libraries/rules/jexec.php
index aab0779..09a8028 100644
--- a/source/administrator/components/com_jedchecker/libraries/rules/jexec.php
+++ b/source/administrator/components/com_jedchecker/libraries/rules/jexec.php
@@ -1,7 +1,7 @@
missing = array();
- $files = JFolder::files($basedir, '.php', true, true);
+ // Find all php files of the extension
+ $files = JFolder::files($this->basedir, '.php$', true, true);
- // Iterate through all files in the package
+ // Iterate through all files
foreach($files as $file)
{
// Try to find the _JEXEC check in the file
- if(!$this->findJExec($file)) {
- $this->missing[] = $file;
+ if(!$this->find($file)) {
+ // Add as error to the report if it was not found
+ $this->report->addError($file, 'COM_JEDCHECKER_ERROR_JEXEC_NOT_FOUND');
}
}
-
-
- echo ''.JText::_('COM_JEDCHECKER_RULE_PH2') .'
';
- if(count($this->missing)) {
- // Echo all files which don't have the _JEXEC check
- foreach($this->missing AS $file)
- {
- echo $file.'
';
- }
- } else {
- echo ''.JText::_('COM_JEDCHECKER_EVERYTHING_SEEMS_TO_BE_FINE_WITH_THAT_RULE').'';
- }
-
}
@@ -64,36 +70,36 @@ class jedcheckerRulesJexec
* @param string $file The path to the file
* @return boolean True if the statement was found, otherwise False.
*/
- protected function findJexec($file)
+ protected function find($file)
{
$content = (array) file($file);
- $defines = array(
- '_JEXEC',
- 'JPATH_PLATFORM',
- 'JPATH_BASE',
- 'AKEEBAENGINE',
- 'WF_EDITOR'
- );
+ // Get the constants to look for
+ $defines = $this->params->get('constants');
+ $defines = explode(',', $defines);
- foreach($content AS $line)
+ foreach ($content AS $line)
{
+ // Search for "defined"
+ $pos_1 = stripos($line, 'defined');
+
+ // Skip the line if "defined" is not found
+ if ($pos_1 === false) {
+ continue;
+ }
+
+ // Search for "die".
+ // "or" may not be present depending on syntax
+ $pos_3 = stripos($line, 'die');
+ // Skip the line if "die" is not found
+ if ($pos_3 === false) {
+ continue;
+ }
+
+ // Search for the constant name
foreach ($defines AS $define)
{
- // Search for "defined"
- $pos_1 = stripos($line, 'defined');
- // Skip the line if "defined" is not found
- if ($pos_1 === false) {
- continue;
- }
-
- // Search for "die".
- // "or" may not be present depending on syntax
- $pos_3 = stripos($line, 'die');
- // Skip the line if "die" is not found
- if ($pos_3 === false) {
- continue;
- }
+ $define = trim($define);
// Search for the define
$pos_2 = strpos($line, $define);
diff --git a/source/administrator/components/com_jedchecker/libraries/rules/xmllicense.php b/source/administrator/components/com_jedchecker/libraries/rules/xmllicense.php
index 9287dbb..7636695 100644
--- a/source/administrator/components/com_jedchecker/libraries/rules/xmllicense.php
+++ b/source/administrator/components/com_jedchecker/libraries/rules/xmllicense.php
@@ -1,7 +1,7 @@
missing = array();
- $files = JFolder::files($basedir, '.xml$', true, true);
+ // Find all XML files of the extension
+ $files = JFolder::files($this->basedir, '.xml$', true, true);
- // Iterate through all files in the package
+ // Iterate through all the xml files
foreach ($files as $file)
{
- // Try to find the license in the file
- if (!$this->find($file)) {
- $this->missing[] = $file;
- }
+ // Try to find the license
+ $this->find($file);
}
-
-
- echo ''.JText::_('COM_JEDCHECKER_RULE_PH3') .'
';
-
- // Echo all files which failed the check
- if (count($this->missing)) {
- foreach ($this->missing AS $file)
- {
- echo $file.'
';
- }
- }
- else {
- echo ''.JText::_('COM_JEDCHECKER_EVERYTHING_SEEMS_TO_BE_FINE_WITH_THAT_RULE').'';
- }
-
}
@@ -81,12 +82,16 @@ class jedcheckerRulesXMLlicense
}
// Check if there's a license tag
- if (!isset($xml->license)) return false;
+ if (!isset($xml->license)) {
+ $this->report->addError($file, 'COM_JEDCHECKER_ERROR_XML_LICENSE_NOT_FOUND');
+ return false;
+ }
// Check if the license is gpl
if (stripos($xml->license, 'gpl') === false &&
stripos($xml->license, 'general public license') === false)
{
+ $this->report->addCompat($file, 'COM_JEDCHECKER_ERROR_XML_LICENSE_NOT_GPL');
return false;
}
diff --git a/source/administrator/components/com_jedchecker/models/index.html b/source/administrator/components/com_jedchecker/models/index.html
new file mode 100644
index 0000000..fa6d84e
--- /dev/null
+++ b/source/administrator/components/com_jedchecker/models/index.html
@@ -0,0 +1 @@
+
\ No newline at end of file
diff --git a/source/administrator/components/com_jedchecker/models/report.php b/source/administrator/components/com_jedchecker/models/report.php
new file mode 100644
index 0000000..ccd9dbd
--- /dev/null
+++ b/source/administrator/components/com_jedchecker/models/report.php
@@ -0,0 +1,222 @@
+data)) $this->reset();
+ }
+
+
+ /**
+ * Resets the report data.
+ *
+ * @return void
+ */
+ public function reset()
+ {
+ $this->data = array();
+
+ $this->data['errors'] = array();
+ $this->data['compat'] = array();
+
+ $this->data['count'] = new stdClass();
+ $this->data['count']->total = 0;
+ $this->data['count']->errors = 0;
+ $this->data['count']->compat = 0;
+ }
+
+
+ /**
+ * 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 occured.
+ *
+ * @return void
+ */
+ public function addError($location, $text = NULL, $line = 0)
+ {
+ $item = new stdClass();
+ $item->location = $location;
+ $item->line = $line;
+ $item->text = (empty($text) ? '' : JText::_($text));
+
+ $this->addItem($item, 'errors');
+ }
+
+
+ /**
+ * Adds a compatibility 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 occured.
+ *
+ * @return void
+ */
+ public function addCompat($location, $text = NULL, $line = 0)
+ {
+ $item = new stdClass();
+ $item->location = $location;
+ $item->line = $line;
+ $item->text = empty($text) ? NULL : JText::_($text);
+
+ $this->addItem($item, 'compat');
+ }
+
+
+ /**
+ * Formats the existing report data into HTML and returns it.
+ *
+ * @return string The HTML report data
+ */
+ public function getHTML()
+ {
+ $html = array();
+
+ if($this->data['count']->total == 0) {
+ // No errors or compatibility issues found
+ $html[] = '';
+ $html[] = JText::_('COM_JEDCHECKER_EVERYTHING_SEEMS_TO_BE_FINE_WITH_THAT_RULE');
+ $html[] = '';
+ }
+ else {
+ $error_count = $this->data['count']->errors;
+ $compat_count = $this->data['count']->compat;
+
+ // Go through the error list
+ if($error_count > 0) {
+ $html[] = ''.$error_count. ' '.JText::_('COM_JEDCHECKER_ERRORS').'';
+ $html[] = '';
+
+ foreach($this->data['errors'] AS $i => $item)
+ {
+ $num = $i + 1;
+
+ // Add the error count number
+ $html[] = '
';
+ }
+
+ // Go through the compat list
+ if($compat_count > 0) {
+ $html[] = ''.$error_count. ' '.JText::_('COM_JEDCHECKER_COMPAT_ISSUES').'';
+ $html[] = '
'.$item->text.'';
+ }
+
+ $html[] = '';
+
+ foreach($this->data['compat'] AS $i => $item)
+ {
+ $num = $i + 1;
+
+ // Add the error count number
+ $html[] = '
';
+ }
+ }
+
+
+ return implode('', $html);
+ }
+
+
+ /**
+ * Adds an item to the report data
+ *
+ * @param object $item The item to add.
+ * @param string $type Optional item type. Can be 'errors' or 'compat'.
+ * Defaults to 'errors'.
+ *
+ * @return void
+ */
+ protected function addItem($item, $type = 'errors')
+ {
+ // Remove the base dir from the location
+ if(!empty($this->basedir)) {
+ $item->location = str_replace($this->basedir, '', $item->location);
+
+ if($item->location == '') $item->location = '/';
+ }
+
+ // Add the item to the report data
+ $this->data[$type][] = $item;
+
+ $this->data['count']->total++;
+ $this->data['count']->$type++;
+ }
+}
diff --git a/source/administrator/components/com_jedchecker/models/rule.php b/source/administrator/components/com_jedchecker/models/rule.php
new file mode 100644
index 0000000..9cab670
--- /dev/null
+++ b/source/administrator/components/com_jedchecker/models/rule.php
@@ -0,0 +1,131 @@
+report)) {
+ // Create a new report
+ require_once (JPATH_COMPONENT_ADMINISTRATOR.'/models/report.php');
+ $this->report = new JEDcheckerReport($properties);
+ }
+
+ // Try to load the params
+ if(empty($this->params)) {
+ $this->params = $this->loadParams();
+ }
+ }
+
+
+ /**
+ * Performs the rule check. This method should be overloaded!
+ *
+ */
+ public function check()
+ {
+
+ }
+
+
+ /**
+ * Attempts to load a .ini param file of this rule.
+ *
+ * @return JRegistry
+ */
+ protected function loadParams()
+ {
+ // Try to determine the name and location of the params file
+ $file_name = str_replace('jedcheckerrules', '', strtolower(get_class($this)));
+ $params_file = JPATH_COMPONENT_ADMINISTRATOR.'/libraries/rules/'.$file_name.'.ini';
+
+ $params = JRegistry::getInstance('jedchecker.rule.'.$file_name);
+
+ // Load the params from the ini file
+ if (file_exists($params_file)) {
+ // Due to a bug in Joomla 2.5.6, this method cannot be used
+ //$params->loadFile($params_file, 'INI');
+
+ // Get the contents of the file
+ jimport('joomla.filesystem.file');
+ $data = JFile::read($params_file);
+
+ if($data) {
+ $obj = (object) parse_ini_string($data);
+
+ if(is_object($obj)) {
+ $params->loadObject($obj);
+ }
+ }
+ }
+
+ return $params;
+ }
+}
diff --git a/source/administrator/components/com_jedchecker/views/uploads/tmpl/default.php b/source/administrator/components/com_jedchecker/views/uploads/tmpl/default.php
index d130d42..805ff5f 100644
--- a/source/administrator/components/com_jedchecker/views/uploads/tmpl/default.php
+++ b/source/administrator/components/com_jedchecker/views/uploads/tmpl/default.php
@@ -77,26 +77,25 @@ JHtml::script('media/com_jedchecker/js/police.js');
-
-
-
-
+ jsOptions['rules'] AS $rule)
+ {
+ $class = 'jedcheckerRules'.ucfirst($rule);
-
-
-
-