2016-05-25 16:19:19 +00:00
|
|
|
<?php
|
|
|
|
/**
|
2019-03-09 19:44:14 +00:00
|
|
|
* @package Joomla.JEDChecker
|
2016-05-25 16:19:19 +00:00
|
|
|
*
|
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>
|
|
|
|
*
|
2019-03-09 19:44:14 +00:00
|
|
|
* @license GNU General Public License version 2 or later; see LICENSE.txt
|
2016-05-25 16:19:19 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
defined('_JEXEC') or die('Restricted access');
|
|
|
|
|
|
|
|
|
|
|
|
jimport('joomla.filesystem');
|
|
|
|
jimport('joomla.filesystem.folder');
|
|
|
|
jimport('joomla.filesystem.archive');
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Class jedcheckerControllerPolice
|
|
|
|
*
|
|
|
|
* @since 1.0
|
|
|
|
*/
|
|
|
|
class JedcheckerControllerPolice extends JControllerLegacy
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* Runs all the rules on the given directory
|
|
|
|
*
|
2021-04-04 10:25:35 +00:00
|
|
|
* @return boolean
|
2016-05-25 16:19:19 +00:00
|
|
|
*/
|
|
|
|
public function check()
|
|
|
|
{
|
2021-04-04 10:25:35 +00:00
|
|
|
$rule = JFactory::getApplication()->input->get('rule');
|
2016-05-25 16:19:19 +00:00
|
|
|
|
|
|
|
JLoader::discover('jedcheckerRules', JPATH_COMPONENT_ADMINISTRATOR . '/libraries/rules/');
|
|
|
|
|
|
|
|
$path = JFactory::getConfig()->get('tmp_path') . '/jed_checker/unzipped';
|
|
|
|
$class = 'jedcheckerRules' . ucfirst($rule);
|
|
|
|
|
|
|
|
// Stop if the class does not exist
|
|
|
|
if (!class_exists($class))
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Loop through each folder and police it
|
|
|
|
$folders = $this->getFolders();
|
|
|
|
|
|
|
|
foreach ($folders as $folder)
|
|
|
|
{
|
|
|
|
$this->police($class, $folder);
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Run each rule and echo the result
|
|
|
|
*
|
2021-04-04 10:25:35 +00:00
|
|
|
* @param string $class - the class name
|
2016-05-25 16:19:19 +00:00
|
|
|
* @param string $folder - the folder where the component is located
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
protected function police($class, $folder)
|
|
|
|
{
|
|
|
|
// Prepare rule properties
|
2021-02-15 20:22:23 +00:00
|
|
|
$properties = array('basedir' => JPath::clean($folder));
|
2016-05-25 16:19:19 +00:00
|
|
|
|
|
|
|
// Create instance of the rule
|
|
|
|
$police = new $class($properties);
|
|
|
|
|
|
|
|
// Perform check
|
|
|
|
$police->check();
|
|
|
|
|
|
|
|
// Get the report and then print it
|
|
|
|
$report = $police->get('report');
|
|
|
|
|
2021-02-23 20:03:19 +00:00
|
|
|
echo $report->getHTML();
|
2016-05-25 16:19:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the folders that should be checked
|
|
|
|
*
|
|
|
|
* @return array
|
|
|
|
*/
|
|
|
|
protected function getFolders()
|
|
|
|
{
|
|
|
|
$folders = array();
|
|
|
|
|
|
|
|
// Add the folders in the "jed_checked/unzipped" folder
|
|
|
|
$path = JFactory::getConfig()->get('tmp_path') . '/jed_checker/unzipped';
|
|
|
|
$tmp_folders = JFolder::folders($path);
|
|
|
|
|
|
|
|
if (!empty($tmp_folders))
|
|
|
|
{
|
|
|
|
foreach ($tmp_folders as $tmp_folder)
|
|
|
|
{
|
|
|
|
$folders[] = $path . '/' . $tmp_folder;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Parse the local.txt file and parse it
|
|
|
|
$local = JFactory::getConfig()->get('tmp_path') . '/jed_checker/local.txt';
|
|
|
|
|
|
|
|
if (JFile::exists($local))
|
|
|
|
{
|
2021-02-23 18:05:14 +00:00
|
|
|
$content = file_get_contents($local);
|
2016-05-25 16:19:19 +00:00
|
|
|
|
|
|
|
if (!empty($content))
|
|
|
|
{
|
|
|
|
$lines = explode("\n", $content);
|
|
|
|
|
|
|
|
if (!empty($lines))
|
|
|
|
{
|
|
|
|
foreach ($lines as $line)
|
|
|
|
{
|
|
|
|
$line = trim($line);
|
|
|
|
|
|
|
|
if (!empty($line))
|
|
|
|
{
|
|
|
|
if (JFolder::exists(JPATH_ROOT . '/' . $line))
|
|
|
|
{
|
|
|
|
$folders[] = JPATH_ROOT . '/' . $line;
|
|
|
|
}
|
|
|
|
elseif (JFolder::exists($line))
|
|
|
|
{
|
|
|
|
$folders[] = $line;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return $folders;
|
|
|
|
}
|
|
|
|
}
|