2012-07-06 23:45:06 +00:00
|
|
|
<?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
|
2012-07-06 23:45:06 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
defined('_JEXEC') or die('Restricted access');
|
|
|
|
|
|
|
|
/**
|
2013-11-05 19:52:37 +00:00
|
|
|
* Class JEDcheckerReport
|
|
|
|
*
|
2012-07-06 23:45:06 +00:00
|
|
|
* This class is meant to be used by JED rules to
|
|
|
|
* create a report.
|
|
|
|
*
|
2013-11-05 19:52:37 +00:00
|
|
|
* @since 1.0
|
2012-07-06 23:45:06 +00:00
|
|
|
*/
|
|
|
|
class JEDcheckerReport extends JObject
|
|
|
|
{
|
2013-11-05 19:52:37 +00:00
|
|
|
/**
|
|
|
|
* Contains the report data.
|
|
|
|
*
|
|
|
|
* @var array
|
2021-04-04 10:25:35 +00:00
|
|
|
* @see reset
|
2013-11-05 19:52:37 +00:00
|
|
|
*/
|
|
|
|
protected $data;
|
2012-07-06 23:45:06 +00:00
|
|
|
|
2013-11-05 19:52:37 +00:00
|
|
|
/**
|
|
|
|
* The absolute path to the target extension.
|
|
|
|
*
|
|
|
|
* @var string
|
|
|
|
*/
|
|
|
|
protected $basedir;
|
2012-07-06 23:45:06 +00:00
|
|
|
|
2012-12-13 10:33:17 +00:00
|
|
|
/**
|
|
|
|
* Constructor. Initialises variables.
|
|
|
|
*
|
2013-11-05 19:52:37 +00:00
|
|
|
* @param mixed $properties Either and associative array or another
|
|
|
|
* object to set the initial properties of the object.
|
|
|
|
*/
|
|
|
|
public function __construct($properties = null)
|
|
|
|
{
|
|
|
|
// Construct JObject
|
|
|
|
parent::__construct($properties);
|
|
|
|
|
|
|
|
// Initialise vars
|
|
|
|
if (empty($this->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['info'] = array();
|
2019-05-15 19:02:36 +00:00
|
|
|
$this->data['warning'] = array();
|
2013-11-05 19:52:37 +00:00
|
|
|
|
|
|
|
$this->data['count'] = new stdClass;
|
|
|
|
$this->data['count']->total = 0;
|
|
|
|
$this->data['count']->errors = 0;
|
|
|
|
$this->data['count']->compat = 0;
|
2013-11-05 20:04:03 +00:00
|
|
|
$this->data['count']->warning = 0;
|
2013-11-05 19:52:37 +00:00
|
|
|
$this->data['count']->info = 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 occurred.
|
2021-02-23 19:38:42 +00:00
|
|
|
* @param string $code - Code at that location (to be displayed below the description)
|
2012-12-13 10:33:17 +00:00
|
|
|
*
|
2013-11-05 19:52:37 +00:00
|
|
|
* @return void
|
2012-12-13 10:33:17 +00:00
|
|
|
*/
|
2021-02-23 19:38:42 +00:00
|
|
|
public function addError($location, $text = null, $line = 0, $code = null)
|
2013-11-05 19:52:37 +00:00
|
|
|
{
|
|
|
|
$item = new stdClass;
|
|
|
|
$item->location = $location;
|
|
|
|
$item->line = $line;
|
|
|
|
$item->text = $text;
|
2021-02-23 19:38:42 +00:00
|
|
|
$item->code = $code;
|
2013-11-05 19:52:37 +00:00
|
|
|
|
|
|
|
$this->addItem($item, 'errors');
|
|
|
|
}
|
2012-07-06 23:45:06 +00:00
|
|
|
|
2012-12-13 10:33:17 +00:00
|
|
|
/**
|
|
|
|
* Adds an error to the report.
|
|
|
|
*
|
2013-11-05 19:52:37 +00:00
|
|
|
* @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
|
2012-12-13 10:33:17 +00:00
|
|
|
* error occurred.
|
2021-02-23 19:38:42 +00:00
|
|
|
* @param string $code - Code at that location (to be displayed below the description)
|
2012-12-13 10:33:17 +00:00
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2021-02-23 19:38:42 +00:00
|
|
|
public function addInfo($location, $text = null, $line = 0, $code = null)
|
2012-12-13 10:33:17 +00:00
|
|
|
{
|
2013-11-05 19:52:37 +00:00
|
|
|
$item = new stdClass;
|
2012-12-13 10:33:17 +00:00
|
|
|
$item->location = $location;
|
2013-11-05 19:52:37 +00:00
|
|
|
$item->line = $line;
|
|
|
|
$item->text = $text;
|
2021-02-23 19:38:42 +00:00
|
|
|
$item->code = $code;
|
2012-12-13 10:33:17 +00:00
|
|
|
|
|
|
|
$this->addItem($item, 'info');
|
|
|
|
}
|
|
|
|
|
2013-11-05 19:52:37 +00:00
|
|
|
/**
|
|
|
|
* 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 occurred.
|
2021-02-23 19:38:42 +00:00
|
|
|
* @param string $code - Code at that location (to be displayed below the description)
|
2013-11-05 19:52:37 +00:00
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2021-02-23 19:38:42 +00:00
|
|
|
public function addCompat($location, $text = null, $line = 0, $code = null)
|
2013-11-05 19:52:37 +00:00
|
|
|
{
|
|
|
|
$item = new stdClass;
|
|
|
|
$item->location = $location;
|
|
|
|
$item->line = $line;
|
|
|
|
$item->text = $text;
|
2021-02-23 19:38:42 +00:00
|
|
|
$item->code = $code;
|
2012-07-06 23:45:06 +00:00
|
|
|
|
2013-11-05 19:52:37 +00:00
|
|
|
$this->addItem($item, 'compat');
|
|
|
|
}
|
|
|
|
|
2013-11-05 20:04:03 +00:00
|
|
|
/**
|
|
|
|
* 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.
|
2021-02-23 19:38:42 +00:00
|
|
|
* @param string $code - Code at that location (to be displayed below the description)
|
2013-11-05 20:04:03 +00:00
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2021-02-23 19:38:42 +00:00
|
|
|
public function addWarning($location, $text = null, $line = 0, $code = null)
|
2013-11-05 20:04:03 +00:00
|
|
|
{
|
|
|
|
$item = new stdClass;
|
|
|
|
$item->location = $location;
|
|
|
|
$item->line = $line;
|
|
|
|
$item->text = $text;
|
2021-02-23 19:38:42 +00:00
|
|
|
$item->code = $code;
|
2013-11-05 20:04:03 +00:00
|
|
|
|
|
|
|
$this->addItem($item, 'warning');
|
|
|
|
}
|
|
|
|
|
2013-11-05 19:52:37 +00:00
|
|
|
/**
|
|
|
|
* Formats the existing report data into HTML and returns it.
|
|
|
|
*
|
|
|
|
* @return string The HTML report data
|
|
|
|
*/
|
|
|
|
public function getHTML()
|
|
|
|
{
|
|
|
|
$html = array();
|
2019-03-09 19:44:14 +00:00
|
|
|
|
2013-11-05 19:52:37 +00:00
|
|
|
if ($this->data['count']->total == 0)
|
|
|
|
{
|
|
|
|
// No errors or compatibility issues found
|
2016-03-11 23:46:16 +00:00
|
|
|
$html[] = '<div class="alert alert-success">';
|
2013-11-05 19:52:37 +00:00
|
|
|
$html[] = JText::_('COM_JEDCHECKER_EVERYTHING_SEEMS_TO_BE_FINE_WITH_THAT_RULE');
|
2016-03-11 23:46:16 +00:00
|
|
|
$html[] = '</div>';
|
2013-11-05 19:52:37 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$error_count = $this->data['count']->errors;
|
|
|
|
$compat_count = $this->data['count']->compat;
|
|
|
|
$info_count = $this->data['count']->info;
|
2013-11-05 20:04:03 +00:00
|
|
|
$warning_count = $this->data['count']->warning;
|
2013-11-05 19:52:37 +00:00
|
|
|
|
|
|
|
// Go through the error list
|
|
|
|
if ($error_count > 0)
|
|
|
|
{
|
2017-01-06 16:53:31 +00:00
|
|
|
$collapseID = uniqid('error_');
|
2019-03-09 19:44:14 +00:00
|
|
|
|
2021-02-03 15:31:53 +00:00
|
|
|
$html[] = '<div class="alert alert-danger" data-toggle="collapse" data-target="#' . $collapseID . '"><strong>' . $error_count . ' ' . JText::_('COM_JEDCHECKER_ERRORS') . '</strong> - ' . JText::_('COM_JEDCHECKER_CLICK_TO_VIEW_DETAILS') . '</div>';
|
2017-01-06 16:53:31 +00:00
|
|
|
$html[] = '<div id="' . $collapseID . '" class="collapse"><ul class="alert alert-danger">';
|
2013-11-05 19:52:37 +00:00
|
|
|
|
2021-02-23 19:33:32 +00:00
|
|
|
$html[] = $this->formatItems($this->data['errors']);
|
2013-11-05 19:52:37 +00:00
|
|
|
|
2017-01-06 16:53:31 +00:00
|
|
|
$html[] = '</ul></div>';
|
2013-11-05 19:52:37 +00:00
|
|
|
}
|
2012-12-13 10:33:17 +00:00
|
|
|
|
|
|
|
// Go through the compat list
|
2013-11-05 19:52:37 +00:00
|
|
|
if ($compat_count > 0)
|
|
|
|
{
|
2019-03-09 19:44:14 +00:00
|
|
|
|
2019-05-15 19:09:22 +00:00
|
|
|
$collapseID = uniqid('compat_');
|
2019-03-09 19:44:14 +00:00
|
|
|
|
2021-02-03 15:31:53 +00:00
|
|
|
$html[] = '<div class="alert alert-warning" data-toggle="collapse" data-target="#' . $collapseID . '"><strong>' . $compat_count . ' ' . JText::_('COM_JEDCHECKER_COMPAT_ISSUES') . '</strong> - ' . JText::_('COM_JEDCHECKER_CLICK_TO_VIEW_DETAILS') . '</div>';
|
2017-01-06 16:53:31 +00:00
|
|
|
$html[] = '<div id="' . $collapseID . '" class="collapse"><ul class="alert alert-warning">';
|
2019-03-09 19:44:14 +00:00
|
|
|
|
2021-02-23 19:33:32 +00:00
|
|
|
$html[] = $this->formatItems($this->data['compat']);
|
2012-12-13 10:33:17 +00:00
|
|
|
|
2017-01-06 16:53:31 +00:00
|
|
|
$html[] = '</ul></div>';
|
2012-12-13 10:33:17 +00:00
|
|
|
}
|
2012-07-06 23:45:06 +00:00
|
|
|
|
2013-11-05 19:52:37 +00:00
|
|
|
// Go through the compat list
|
|
|
|
if ($info_count > 0)
|
|
|
|
{
|
2019-03-09 19:44:14 +00:00
|
|
|
|
2017-01-06 16:53:31 +00:00
|
|
|
$collapseID = uniqid('info_');
|
2019-03-09 19:44:14 +00:00
|
|
|
|
2021-02-03 15:31:53 +00:00
|
|
|
$html[] = '<div class="alert alert-info" data-toggle="collapse" data-target="#' . $collapseID . '"><strong>' . $info_count . ' ' . JText::_('COM_JEDCHECKER_INFO') . '</strong> - ' . JText::_('COM_JEDCHECKER_CLICK_TO_VIEW_DETAILS') . '</div>';
|
2017-01-06 16:53:31 +00:00
|
|
|
$html[] = '<div id="' . $collapseID . '" class="collapse"><ul class="alert alert-info">';
|
2019-03-09 19:44:14 +00:00
|
|
|
|
2021-02-23 19:33:32 +00:00
|
|
|
$html[] = $this->formatItems($this->data['info']);
|
2013-11-05 20:04:03 +00:00
|
|
|
|
2017-01-06 16:53:31 +00:00
|
|
|
$html[] = '</ul></div>';
|
2013-11-05 20:04:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Go through the warning list
|
|
|
|
if ($warning_count > 0)
|
|
|
|
{
|
2017-01-06 16:53:31 +00:00
|
|
|
$collapseID = uniqid('warning_');
|
2019-03-09 19:44:14 +00:00
|
|
|
|
2021-02-03 15:31:53 +00:00
|
|
|
$html[] = '<div class="alert alert-warning" data-toggle="collapse" data-target="#' . $collapseID . '"><strong>' . $warning_count . ' ' . JText::_('COM_JEDCHECKER_WARNING') . '</strong> - ' . JText::_('COM_JEDCHECKER_CLICK_TO_VIEW_DETAILS') . '</div>';
|
2017-01-06 16:53:31 +00:00
|
|
|
$html[] = '<div id="' . $collapseID . '" class="collapse"><ul class="alert alert-warning">';
|
2019-03-09 19:44:14 +00:00
|
|
|
|
2021-02-23 19:33:32 +00:00
|
|
|
$html[] = $this->formatItems($this->data['warning']);
|
2013-11-05 19:52:37 +00:00
|
|
|
|
2017-01-06 16:53:31 +00:00
|
|
|
$html[] = '</ul></div>';
|
2013-11-05 19:52:37 +00:00
|
|
|
}
|
|
|
|
}
|
2012-07-06 23:45:06 +00:00
|
|
|
|
2013-11-05 19:52:37 +00:00
|
|
|
return implode('', $html);
|
|
|
|
}
|
2012-07-06 23:45:06 +00:00
|
|
|
|
2013-11-05 19:52:37 +00:00
|
|
|
/**
|
|
|
|
* 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);
|
|
|
|
|
2021-04-04 10:25:35 +00:00
|
|
|
if ($item->location === '')
|
2013-11-05 19:52:37 +00:00
|
|
|
{
|
|
|
|
$item->location = '/';
|
|
|
|
}
|
|
|
|
}
|
2012-07-06 23:45:06 +00:00
|
|
|
|
2013-11-05 19:52:37 +00:00
|
|
|
// Add the item to the report data
|
|
|
|
$this->data[$type][] = $item;
|
|
|
|
|
|
|
|
$this->data['count']->total++;
|
|
|
|
$this->data['count']->$type++;
|
|
|
|
}
|
2021-02-23 19:33:32 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Converts an item to the string representation
|
|
|
|
*
|
|
|
|
* @param array $items List or reports
|
|
|
|
*
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
protected function formatItems($items)
|
|
|
|
{
|
|
|
|
$html = array();
|
|
|
|
|
|
|
|
foreach ($items as $i => $item)
|
|
|
|
{
|
|
|
|
$num = $i + 1;
|
|
|
|
|
|
|
|
// Add count number
|
|
|
|
$html[] = '<li><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[] = '<br />';
|
|
|
|
|
|
|
|
// Add text if given
|
|
|
|
if (!empty($item->text))
|
|
|
|
{
|
2021-02-23 19:38:42 +00:00
|
|
|
$html[] = '<small>' . $item->text;
|
|
|
|
|
|
|
|
// Add code if given
|
|
|
|
if (!empty($item->code))
|
|
|
|
{
|
|
|
|
$html[] = '<pre>' . htmlspecialchars(rtrim($item->code)) . '</pre>';
|
|
|
|
}
|
|
|
|
|
|
|
|
$html[] = '</small>';
|
2021-02-23 19:33:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
$html[] = '</li>';
|
|
|
|
}
|
|
|
|
|
|
|
|
return implode('', $html);
|
|
|
|
}
|
2012-07-06 23:45:06 +00:00
|
|
|
}
|