Your IP : 216.73.216.41


Current Path : /home/purehotels/public_html/components/com_easyfolderlistingpro/views/archive/
Upload File :
Current File : /home/purehotels/public_html/components/com_easyfolderlistingpro/views/archive/view.raw.php

<?php
/**
* @version		3.2.1
* @author		Michael A. Gilkes (michael@valorapps.com)
* @copyright	Michael Albert Gilkes
* @license		GNU/GPLv3

Easy Folder Listing Pro Component for Joomla!
Copyright (C) 2012-2016 Michael Albert Gilkes (Valor Apps)

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/

//no direct access
defined( '_JEXEC' ) or die( 'Restricted access' );

require_once(JPATH_SITE.'/components/com_easyfolderlistingpro/helpers/EFLPListing.Class.php');
require_once(JPATH_SITE.'/components/com_easyfolderlistingpro/helpers/MultiDownload.Class.php');
require_once(JPATH_ADMINISTRATOR.'/components/com_easyfolderlistingpro/helpers/eflphelper.php');
jimport('joomla.filesystem.file');


class EasyFolderListingProViewArchive extends JViewLegacy
{
	protected $filepath = '';
	protected $filename = '';
	protected $extension = '';
	
	/**
	 * Overwriting JView display method
	 */
	function display($tpl = null) 
	{
		//check for archiving. security check to see if download button was pressed.
		$archive_download = JFactory::getApplication()->input->get('archive_download', 0, 'int');
		
		//handle archive download request
		if ($archive_download === 1)
		{
			//load selected filedata from the request
			$files_data = JFactory::getApplication()->input->get('cid', array(), 'array');
		
			//if no data exists. log the error
			if (empty($files_data))
			{
				JLog::add(JText::sprintf('COM_EFLP_ARCHIVE_NOFILES_ERROR', ValorUtilities::getUserIP()), JLog::ALERT, 'com_easyfolderlistingpro');
			}
			else
			{
				//load archive data from the request
				$archive_data = JFactory::getApplication()->input->get('archive_data', '', 'raw');
				$archive_type = JFactory::getApplication()->input->get('archivetype', '', 'string');
		
				//if no data exists. log the error
				if (empty($archive_data) || empty($archive_type))
				{
					JLog::add(JText::sprintf('COM_EFLP_ARCHIVE_NODATA_ERROR', ValorUtilities::getUserIP()), JLog::ALERT, 'com_easyfolderlistingpro');
				}
				else
				{
					$process_errors = $this->processArchive($files_data, $archive_data, $archive_type);
					$model_errors = $this->get('Errors');
					$errors = array_merge($model_errors, $process_errors);
					if (count($errors)) 
					{
						EFLPHelper::logErrors($errors);
					}
				}
			}
		}
		
		parent::display($tpl);
	}
	
	/**
	 * Processes the requaest variables and creates the archive.
	 */
	protected function processArchive($files_data, $archive_data, $archive_type)
	{
		//decrypt the incoming data
		$archive_data = ValorUtilities::elucidate($archive_data);
		
		//make sure that the value of $archive_data['maxnumberfiles'] is an integer
		$archive_data['maxnumberfiles'] = (int)$archive_data['maxnumberfiles'];
		
		//check if the number of files is valid
		if ($archive_data['maxnumberfiles'] > 0)
		{
			if (count($files_data) > $archive_data['maxnumberfiles'])
			{
				$error_text = JText::sprintf('COM_EFLP_MAX_NUMBER_FILES_ERROR', $archive_data['maxnumberfiles']);
				$this->setError($error_text);
				return $this->getErrors();
			}
		}
		
		//get the IP
		$ip = ValorUtilities::getUserIP();
		
		//setup the correct rootpath
		$rootpath = ValorUtilities::compilePath($archive_data['folder'], $archive_data['userfolders'], $archive_data['guestfolder'], $archive_data['username']);
		
		//holds the file paths of each file
		$filepaths = array();
		$files_list = array();
		
		//test for total size permitted
		$total_size = 0.0;
		foreach ($files_data as $datum)
		{
			//decode the data
			$data = ValorUtilities::elucidate($datum);
			
			//add the full absolute path of the file
			$filepaths[] = ValorUtilities::changeSlashes($rootpath.$data['path']);
			
			//add the relative path of the file
			$files_list[] = ValorUtilities::changeSlashes(ltrim($data['path'], '/\\'));
			
			//calculate the total size
			$size = (int)$data['size'];
			$size = round($size / 1048576, 2);
			$total_size += $size;
		}
		
		//make sure that the value of $archive_data['maxsizefiles'] is an integer
		$archive_data['maxsizefiles'] = (int)$archive_data['maxsizefiles'];
		
		if ($archive_data['maxsizefiles'] > 0)
		{
			if ($total_size > $archive_data['maxsizefiles'])
			{
				$error_text = JText::sprintf('COM_EFLP_MAX_SIZE_FILES_ERROR', $archive_data['maxsizefiles']);
				$this->setError($error_text);
				return $this->getErrors();
			}
		}
		//get the model
		$model = $this->getModel();
		
		//log the download hits for the files we are going to archive
		$model->logDownloadHits($filepaths, $archive_data['userid'], $ip);
		
		//setup the properties and translation keys for the archiver
		$properties = array();
		$properties['source_path'] = $rootpath;
		$properties['source_files'] = $files_list;
		$trans_keys = array(
			'C0' => 'COM_EFLP_ARCHIVE_CREATION_FAILED_ERROR',
			'O1' => 'COM_EFLP_PHAR_CANT_OPEN_ERROR',
			'O2' => 'COM_EFLP_ZIP_CANT_OPEN_ERROR',
			'F0' => 'COM_EFLP_NO_VALID_FILES_ERROR',
			'F1' => 'COM_EFLP_NO_BZIP_ERROR',
			'F2' => 'COM_EFLP_NO_ZLIB_ERROR'
		);
		
		//create and save the archive
		$archiver = new MultiDownload($properties);
		
		//set the prefix to 'eflp'
		$archiver->set('prefix', 'eflp');
		
		//set the corect translation keys for the archiver object
		$archiver->setErrorCode($trans_keys);
		
		//createArchive returns the filename of the file that was created
		//but returns FALSE if not
		$this->filename = $archiver->createArchive($archive_type);
		if ($this->filename)
		{
			$this->filepath = $archiver->getArchivePath().DIRECTORY_SEPARATOR;
			$this->extension = $archive_type;
			
			//register the archive to be deleted later
			$model->registerNewArchive($this->filepath.$this->filename, $archive_data['archivelife']);
		}
		
		//return any errors
		return $archiver->getErrors();
	}
}