2012-06-02 21:18:29 +00:00
|
|
|
<?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');
|
2012-12-13 10:08:35 +00:00
|
|
|
jimport('joomla.filesystem.folder');
|
2012-06-02 21:18:29 +00:00
|
|
|
jimport('joomla.filesystem.archive');
|
|
|
|
|
2012-12-13 10:08:35 +00:00
|
|
|
class jedcheckerControllerUploads extends JControllerlegacy
|
2012-06-02 21:18:29 +00:00
|
|
|
{
|
2012-06-03 19:00:14 +00:00
|
|
|
public function __construct()
|
|
|
|
{
|
2012-06-09 12:51:17 +00:00
|
|
|
$this->path = JFactory::getConfig()->get('tmp_path') . '/jed_checker';
|
2012-06-24 07:50:50 +00:00
|
|
|
$this->pathArchive = $this->path . '/archives';
|
2012-06-09 12:51:17 +00:00
|
|
|
$this->pathUnzipped = $this->path . '/unzipped';
|
2012-06-02 21:18:29 +00:00
|
|
|
parent::__construct();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* basic upload
|
|
|
|
* @return bool
|
|
|
|
*/
|
2012-06-03 19:00:14 +00:00
|
|
|
public function upload()
|
|
|
|
{
|
2012-06-29 14:37:05 +00:00
|
|
|
JRequest::checkToken() or die( 'Invalid Token' );
|
2012-06-09 12:51:17 +00:00
|
|
|
$appl = JFactory::getApplication();
|
2012-06-02 21:18:29 +00:00
|
|
|
$file = JRequest::getVar('extension', '', 'files', 'array');
|
2012-06-03 19:00:14 +00:00
|
|
|
if ($file['tmp_name']) {
|
|
|
|
$path = $this->pathArchive;
|
2012-06-09 12:51:17 +00:00
|
|
|
// 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);
|
2012-06-03 19:00:14 +00:00
|
|
|
|
2012-06-09 12:51:17 +00:00
|
|
|
foreach ($archiveFiles as $archive) {
|
|
|
|
if (!JFile::delete($this->pathArchive . '/'.$archive)) {
|
|
|
|
echo 'could not delete' . $archive;
|
|
|
|
}
|
2012-06-03 19:00:14 +00:00
|
|
|
}
|
2012-06-02 21:18:29 +00:00
|
|
|
}
|
2012-06-09 12:51:17 +00:00
|
|
|
$filepath = $path .'/'. strtolower($file['name']);
|
|
|
|
|
2012-06-02 21:18:29 +00:00
|
|
|
|
|
|
|
$object_file = new JObject($file);
|
|
|
|
$object_file->filepath = $filepath;
|
2012-06-03 19:00:14 +00:00
|
|
|
$file = (array)$object_file;
|
2012-06-02 21:18:29 +00:00
|
|
|
|
|
|
|
// let us try to upload
|
2015-10-25 19:59:01 +00:00
|
|
|
if (!JFile::upload($file['tmp_name'], $file['filepath'], false, true)) {
|
2012-06-02 21:18:29 +00:00
|
|
|
// Error in upload
|
|
|
|
JError::raiseWarning(100, JText::_('COM_JEDCHECKER_ERROR_UNABLE_TO_UPLOAD_FILE'));
|
|
|
|
return false;
|
|
|
|
}
|
2012-06-09 12:51:17 +00:00
|
|
|
$appl->redirect('index.php?option=com_jedchecker&view=uploads', JText::_('COM_JEDCHECKER_UPLOAD_WAS_SUCCESSFUL'));
|
2012-06-02 21:18:29 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* unzip the file
|
|
|
|
* @return bool
|
|
|
|
*/
|
2012-06-03 19:00:14 +00:00
|
|
|
public function unzip()
|
|
|
|
{
|
2012-06-29 14:37:05 +00:00
|
|
|
JRequest::checkToken() or die( 'Invalid Token' );
|
2012-06-09 12:51:17 +00:00
|
|
|
$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);
|
|
|
|
}
|
2012-06-03 19:00:14 +00:00
|
|
|
}
|
2012-06-02 21:18:29 +00:00
|
|
|
|
2012-06-03 19:00:14 +00:00
|
|
|
$file = JFolder::files($this->pathArchive);
|
2012-06-09 12:51:17 +00:00
|
|
|
$result = JArchive::extract($this->pathArchive .'/'. $file[0], $this->pathUnzipped .'/'. $file[0]);
|
2012-06-03 19:00:14 +00:00
|
|
|
|
|
|
|
if ($result) {
|
|
|
|
// scan unzipped folders if we find zip file -> unzip them as well
|
2012-06-09 12:51:17 +00:00
|
|
|
$this->unzipAll($this->pathUnzipped .'/'. $file[0]);
|
|
|
|
$message = 'COM_JEDCHECKER_UNZIP_SUCCESS';
|
|
|
|
} else {
|
|
|
|
$message = 'COM_JEDCHECKER_UNZIP_FAILED';
|
2012-06-03 19:00:14 +00:00
|
|
|
}
|
2012-06-02 21:18:29 +00:00
|
|
|
|
2012-06-09 12:51:17 +00:00
|
|
|
$appl->redirect('index.php?option=com_jedchecker&view=uploads', JText::_($message));
|
|
|
|
|
2012-06-02 21:18:29 +00:00
|
|
|
return $result;
|
|
|
|
}
|
2012-06-03 19:00:14 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Recursively go through each folder and extract the archives
|
|
|
|
*
|
|
|
|
* @param $start
|
|
|
|
*/
|
|
|
|
public function unzipAll($start)
|
|
|
|
{
|
|
|
|
$iterator = new RecursiveDirectoryIterator($start);
|
|
|
|
|
|
|
|
foreach ($iterator as $file) {
|
|
|
|
if ($file->isFile()) {
|
2013-01-01 10:44:05 +00:00
|
|
|
$extension = pathinfo($file->getFilename(), PATHINFO_EXTENSION);;
|
2012-06-03 19:00:14 +00:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|
2012-06-28 06:57:05 +00:00
|
|
|
} else if (!$iterator->isDot()) {
|
2012-06-03 19:00:14 +00:00
|
|
|
$this->unzipAll($file->getPathname());
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2012-06-02 21:18:29 +00:00
|
|
|
}
|