mirror of
https://github.com/joomla-extensions/jedchecker.git
synced 2025-01-22 21:28:24 +00:00
Phpcs
This commit is contained in:
parent
05130c32a2
commit
8bd73e2e81
@ -1,15 +1,19 @@
|
||||
<?php
|
||||
/**
|
||||
* @author Daniel Dimitrov - compojoom.com
|
||||
* @date: 02.06.12
|
||||
*
|
||||
* @copyright Copyright (C) 2008 - 2012 compojoom.com . All rights reserved.
|
||||
* @license GNU General Public License version 2 or later; see LICENSE
|
||||
*/
|
||||
|
||||
defined( '_JEXEC' ) or die ( 'Restricted access' );
|
||||
|
||||
class jedcheckerController extends JControllerlegacy
|
||||
{
|
||||
|
||||
}
|
||||
<?php
|
||||
/**
|
||||
* @author Daniel Dimitrov <daniel@compojoom.com>
|
||||
* @date 26.10.15
|
||||
*
|
||||
* @copyright Copyright (C) 2008 - 2015 compojoom.com . All rights reserved.
|
||||
* @license GNU General Public License version 2 or later; see LICENSE
|
||||
*/
|
||||
|
||||
defined('_JEXEC') or die ('Restricted access');
|
||||
|
||||
/**
|
||||
* Class JedcheckerController
|
||||
*
|
||||
* @since 1.0
|
||||
*/
|
||||
class JedcheckerController extends JControllerlegacy
|
||||
{
|
||||
}
|
||||
|
@ -1,103 +1,143 @@
|
||||
<?php
|
||||
/**
|
||||
* @author Daniel Dimitrov - compojoom.com
|
||||
* @date: 02.06.12
|
||||
*
|
||||
* @copyright Copyright (C) 2008 - 2012 compojoom.com . All rights reserved.
|
||||
* @license GNU General Public License version 2 or later; see LICENSE
|
||||
*/
|
||||
|
||||
defined('_JEXEC') or die('Restricted access');
|
||||
|
||||
|
||||
jimport('joomla.filesystem');
|
||||
jimport('joomla.filesystem.folder');
|
||||
jimport('joomla.filesystem.archive');
|
||||
|
||||
|
||||
class jedcheckerControllerPolice extends JControllerlegacy
|
||||
{
|
||||
public function check()
|
||||
{
|
||||
$rule = JRequest::getString('rule');
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
protected function police($class, $folder)
|
||||
{
|
||||
// Prepare rule properties
|
||||
$properties = array('basedir' => $folder);
|
||||
|
||||
// Create instance of the rule
|
||||
$police = new $class($properties);
|
||||
|
||||
// Perform check
|
||||
$police->check();
|
||||
|
||||
// Get the report and then print it
|
||||
$report = $police->get('report');
|
||||
|
||||
echo '<span class="rule">'
|
||||
. JText::_('COM_JEDCHECKER_RULE') .' ' . JText::_($police->get('id'))
|
||||
. ' - '. JText::_($police->get('title'))
|
||||
. '</span><br/>'
|
||||
. $report->getHTML();
|
||||
|
||||
flush();
|
||||
ob_flush();
|
||||
}
|
||||
|
||||
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)) {
|
||||
$content = JFile::read($local);
|
||||
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;
|
||||
}
|
||||
}
|
||||
<?php
|
||||
/**
|
||||
* @author Daniel Dimitrov <daniel@compojoom.com>
|
||||
* @date 26.10.15
|
||||
*
|
||||
* @copyright Copyright (C) 2008 - 2015 compojoom.com . All rights reserved.
|
||||
* @license GNU General Public License version 2 or later; see LICENSE
|
||||
*/
|
||||
|
||||
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
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function check()
|
||||
{
|
||||
$rule = JRequest::getString('rule');
|
||||
|
||||
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
|
||||
*
|
||||
* @param string $class - the class anme
|
||||
* @param string $folder - the folder where the component is located
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function police($class, $folder)
|
||||
{
|
||||
// Prepare rule properties
|
||||
$properties = array('basedir' => $folder);
|
||||
|
||||
// Create instance of the rule
|
||||
$police = new $class($properties);
|
||||
|
||||
// Perform check
|
||||
$police->check();
|
||||
|
||||
// Get the report and then print it
|
||||
$report = $police->get('report');
|
||||
|
||||
echo '<span class="rule">'
|
||||
. JText::_('COM_JEDCHECKER_RULE') . ' ' . JText::_($police->get('id'))
|
||||
. ' - ' . JText::_($police->get('title'))
|
||||
. '</span><br/>'
|
||||
. $report->getHTML();
|
||||
|
||||
flush();
|
||||
ob_flush();
|
||||
}
|
||||
|
||||
/**
|
||||
* 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))
|
||||
{
|
||||
$content = JFile::read($local);
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
@ -1,9 +1,9 @@
|
||||
<?php
|
||||
/**
|
||||
* @author Daniel Dimitrov - compojoom.com
|
||||
* @date: 02.06.12
|
||||
* @author Daniel Dimitrov <daniel@compojoom.com>
|
||||
* @date 26.10.15
|
||||
*
|
||||
* @copyright Copyright (C) 2008 - 2012 compojoom.com . All rights reserved.
|
||||
* @copyright Copyright (C) 2008 - 2015 compojoom.com . All rights reserved.
|
||||
* @license GNU General Public License version 2 or later; see LICENSE
|
||||
*/
|
||||
|
||||
@ -13,122 +13,164 @@ jimport('joomla.filesystem');
|
||||
jimport('joomla.filesystem.folder');
|
||||
jimport('joomla.filesystem.archive');
|
||||
|
||||
class jedcheckerControllerUploads extends JControllerlegacy
|
||||
/**
|
||||
* Class JedcheckerControllerUploads
|
||||
*
|
||||
* @since 1.0
|
||||
*/
|
||||
class JedcheckerControllerUploads extends JControllerlegacy
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
$this->path = JFactory::getConfig()->get('tmp_path') . '/jed_checker';
|
||||
$this->pathArchive = $this->path . '/archives';
|
||||
$this->pathUnzipped = $this->path . '/unzipped';
|
||||
parent::__construct();
|
||||
}
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
$this->path = JFactory::getConfig()->get('tmp_path') . '/jed_checker';
|
||||
$this->pathArchive = $this->path . '/archives';
|
||||
$this->pathUnzipped = $this->path . '/unzipped';
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
/**
|
||||
* basic upload
|
||||
* @return bool
|
||||
*/
|
||||
public function upload()
|
||||
{
|
||||
JRequest::checkToken() or die( 'Invalid Token' );
|
||||
$appl = JFactory::getApplication();
|
||||
$file = JRequest::getVar('extension', '', 'files', 'array');
|
||||
if ($file['tmp_name']) {
|
||||
$path = $this->pathArchive;
|
||||
// if the archive folder doesn't exist - create it!
|
||||
if(!JFolder::exists($path)) {
|
||||
JFolder::create($path);
|
||||
} else {
|
||||
// let us remove all previous uploads
|
||||
$archiveFiles = JFolder::files($path);
|
||||
/**
|
||||
* basic upload
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function upload()
|
||||
{
|
||||
JRequest::checkToken() or die('Invalid Token');
|
||||
$appl = JFactory::getApplication();
|
||||
$file = JRequest::getVar('extension', '', 'files', 'array');
|
||||
|
||||
foreach ($archiveFiles as $archive) {
|
||||
if (!JFile::delete($this->pathArchive . '/'.$archive)) {
|
||||
echo 'could not delete' . $archive;
|
||||
}
|
||||
}
|
||||
}
|
||||
$filepath = $path .'/'. strtolower($file['name']);
|
||||
if ($file['tmp_name'])
|
||||
{
|
||||
$path = $this->pathArchive;
|
||||
|
||||
// If the archive folder doesn't exist - create it!
|
||||
if (!JFolder::exists($path))
|
||||
{
|
||||
JFolder::create($path);
|
||||
}
|
||||
else
|
||||
{
|
||||
// Let us remove all previous uploads
|
||||
$archiveFiles = JFolder::files($path);
|
||||
|
||||
foreach ($archiveFiles as $archive)
|
||||
{
|
||||
if (!JFile::delete($this->pathArchive . '/' . $archive))
|
||||
{
|
||||
echo 'could not delete' . $archive;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$filepath = $path . '/' . strtolower($file['name']);
|
||||
|
||||
|
||||
$object_file = new JObject($file);
|
||||
$object_file->filepath = $filepath;
|
||||
$file = (array)$object_file;
|
||||
$object_file = new JObject($file);
|
||||
$object_file->filepath = $filepath;
|
||||
$file = (array) $object_file;
|
||||
|
||||
// let us try to upload
|
||||
if (!JFile::upload($file['tmp_name'], $file['filepath'], false, true)) {
|
||||
// Error in upload
|
||||
JError::raiseWarning(100, JText::_('COM_JEDCHECKER_ERROR_UNABLE_TO_UPLOAD_FILE'));
|
||||
return false;
|
||||
}
|
||||
$appl->redirect('index.php?option=com_jedchecker&view=uploads', JText::_('COM_JEDCHECKER_UPLOAD_WAS_SUCCESSFUL'));
|
||||
return true;
|
||||
}
|
||||
// Let us try to upload
|
||||
if (!JFile::upload($file['tmp_name'], $file['filepath'], false, true))
|
||||
{
|
||||
// Error in upload
|
||||
JError::raiseWarning(100, JText::_('COM_JEDCHECKER_ERROR_UNABLE_TO_UPLOAD_FILE'));
|
||||
|
||||
return false;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* unzip the file
|
||||
* @return bool
|
||||
*/
|
||||
public function unzip()
|
||||
{
|
||||
JRequest::checkToken() or die( 'Invalid Token' );
|
||||
$appl = JFactory::getApplication();
|
||||
// if folder doesn't exist - create it!
|
||||
if(!JFolder::exists($this->pathUnzipped)) {
|
||||
JFolder::create($this->pathUnzipped);
|
||||
} else {
|
||||
// let us remove all previous unzipped files
|
||||
$folders = JFolder::folders($this->pathUnzipped);
|
||||
foreach ($folders as $folder) {
|
||||
JFolder::delete($this->pathUnzipped .'/'. $folder);
|
||||
}
|
||||
}
|
||||
$appl->redirect('index.php?option=com_jedchecker&view=uploads', JText::_('COM_JEDCHECKER_UPLOAD_WAS_SUCCESSFUL'));
|
||||
|
||||
$file = JFolder::files($this->pathArchive);
|
||||
$result = JArchive::extract($this->pathArchive .'/'. $file[0], $this->pathUnzipped .'/'. $file[0]);
|
||||
return true;
|
||||
}
|
||||
|
||||
if ($result) {
|
||||
// scan unzipped folders if we find zip file -> unzip them as well
|
||||
$this->unzipAll($this->pathUnzipped .'/'. $file[0]);
|
||||
$message = 'COM_JEDCHECKER_UNZIP_SUCCESS';
|
||||
} else {
|
||||
$message = 'COM_JEDCHECKER_UNZIP_FAILED';
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
$appl->redirect('index.php?option=com_jedchecker&view=uploads', JText::_($message));
|
||||
/**
|
||||
* unzip the file
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function unzip()
|
||||
{
|
||||
JRequest::checkToken() or die('Invalid Token');
|
||||
$appl = JFactory::getApplication();
|
||||
|
||||
return $result;
|
||||
}
|
||||
// If folder doesn't exist - create it!
|
||||
if (!JFolder::exists($this->pathUnzipped))
|
||||
{
|
||||
JFolder::create($this->pathUnzipped);
|
||||
}
|
||||
else
|
||||
{
|
||||
// Let us remove all previous unzipped files
|
||||
$folders = JFolder::folders($this->pathUnzipped);
|
||||
|
||||
/**
|
||||
* Recursively go through each folder and extract the archives
|
||||
*
|
||||
* @param $start
|
||||
*/
|
||||
public function unzipAll($start)
|
||||
{
|
||||
$iterator = new RecursiveDirectoryIterator($start);
|
||||
foreach ($folders as $folder)
|
||||
{
|
||||
JFolder::delete($this->pathUnzipped . '/' . $folder);
|
||||
}
|
||||
}
|
||||
|
||||
foreach ($iterator as $file) {
|
||||
if ($file->isFile()) {
|
||||
$extension = pathinfo($file->getFilename(), PATHINFO_EXTENSION);;
|
||||
if ($extension == 'zip') {
|
||||
$unzip = $file->getPath() . '/' . $file->getBasename('.' . $extension);
|
||||
$result = JArchive::extract($file->getPathname(), $unzip);
|
||||
// delete the archive once we extract it
|
||||
if ($result) {
|
||||
JFile::delete($file->getPathname());
|
||||
$file = JFolder::files($this->pathArchive);
|
||||
$result = JArchive::extract($this->pathArchive . '/' . $file[0], $this->pathUnzipped . '/' . $file[0]);
|
||||
|
||||
// now check the new extracted folder for archive files
|
||||
$this->unzipAll($unzip);
|
||||
}
|
||||
}
|
||||
} else if (!$iterator->isDot()) {
|
||||
$this->unzipAll($file->getPathname());
|
||||
if ($result)
|
||||
{
|
||||
// Scan unzipped folders if we find zip file -> unzip them as well
|
||||
$this->unzipAll($this->pathUnzipped . '/' . $file[0]);
|
||||
$message = 'COM_JEDCHECKER_UNZIP_SUCCESS';
|
||||
}
|
||||
else
|
||||
{
|
||||
$message = 'COM_JEDCHECKER_UNZIP_FAILED';
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
$appl->redirect('index.php?option=com_jedchecker&view=uploads', JText::_($message));
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Recursively go through each folder and extract the archives
|
||||
*
|
||||
* @param string $start - the directory where we start the unzipping from
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function unzipAll($start)
|
||||
{
|
||||
$iterator = new RecursiveDirectoryIterator($start);
|
||||
|
||||
foreach ($iterator as $file)
|
||||
{
|
||||
if ($file->isFile())
|
||||
{
|
||||
$extension = pathinfo($file->getFilename(), PATHINFO_EXTENSION);
|
||||
|
||||
if ($extension == 'zip')
|
||||
{
|
||||
$unzip = $file->getPath() . '/' . $file->getBasename('.' . $extension);
|
||||
$result = JArchive::extract($file->getPathname(), $unzip);
|
||||
|
||||
// Delete the archive once we extract it
|
||||
if ($result)
|
||||
{
|
||||
JFile::delete($file->getPathname());
|
||||
|
||||
// Now check the new extracted folder for archive files
|
||||
$this->unzipAll($unzip);
|
||||
}
|
||||
}
|
||||
}
|
||||
elseif (!$iterator->isDot())
|
||||
{
|
||||
$this->unzipAll($file->getPathname());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,27 +1,27 @@
|
||||
<?php
|
||||
/**
|
||||
* @author Daniel Dimitrov - compojoom.com
|
||||
* @date : 02.06.12
|
||||
*
|
||||
* @copyright Copyright (C) 2008 - 2012 compojoom.com . All rights reserved.
|
||||
* @license GNU General Public License version 2 or later; see LICENSE
|
||||
*/
|
||||
|
||||
defined('_JEXEC') or die('Restricted access');
|
||||
jimport('joomla.application.component.controllerlegacy');
|
||||
|
||||
// We'll need jfile and JFolder all through the compoenent so let us load them here
|
||||
jimport('joomla.filesystem.folder');
|
||||
jimport('joomla.filesystem.file');
|
||||
|
||||
$input = JFactory::getApplication()->input;
|
||||
$view = $input->getCmd('view', '');
|
||||
|
||||
if ($view == '' && $input->getCmd('task', '') == '')
|
||||
{
|
||||
$input->set('view', 'uploads');
|
||||
}
|
||||
|
||||
$controller = JControllerLegacy::getInstance('jedchecker');
|
||||
$controller->execute($input->getCmd('task', ''));
|
||||
$controller->redirect();
|
||||
<?php
|
||||
/**
|
||||
* @author Daniel Dimitrov - compojoom.com
|
||||
* @date : 02.06.12
|
||||
*
|
||||
* @copyright Copyright (C) 2008 - 2012 compojoom.com . All rights reserved.
|
||||
* @license GNU General Public License version 2 or later; see LICENSE
|
||||
*/
|
||||
|
||||
defined('_JEXEC') or die('Restricted access');
|
||||
jimport('joomla.application.component.controllerlegacy');
|
||||
|
||||
// We'll need jfile and JFolder all through the compoenent so let us load them here
|
||||
jimport('joomla.filesystem.folder');
|
||||
jimport('joomla.filesystem.file');
|
||||
|
||||
$input = JFactory::getApplication()->input;
|
||||
$view = $input->getCmd('view', '');
|
||||
|
||||
if ($view == '' && $input->getCmd('task', '') == '')
|
||||
{
|
||||
$input->set('view', 'uploads');
|
||||
}
|
||||
|
||||
$controller = JControllerLegacy::getInstance('jedchecker');
|
||||
$controller->execute($input->getCmd('task', ''));
|
||||
$controller->redirect();
|
||||
|
Loading…
x
Reference in New Issue
Block a user