0byt3m1n1-V2
Path:
/
home
/
a
/
c
/
a
/
academiac
/
www
/
[
Home
]
File: file.php.tar
home/academiac/www/administrator/components/com_virtuemart_allinone/classes/storage/file.php 0000604 00000002114 15137225337 0026730 0 ustar 00 <?php /** * @package LiveUpdate * @copyright Copyright ©2011 Nicholas K. Dionysopoulos / AkeebaBackup.com * @license GNU LGPLv3 or later <http://www.gnu.org/copyleft/lesser.html> */ defined('_JEXEC') or die(); /** * Live Update File Storage Class * Allows to store the update data to files on disk. Its configuration options are: * path string The absolute path to the directory where the update data will be stored as INI files * */ class LiveUpdateStorageFile extends LiveUpdateStorage { private static $filename = null; public function load($config) { $path = $config['path']; $extname = $config['extensionName']; $filename = "$path/$extname.updates.ini"; self::$filename = $filename; jimport('joomla.registry.registry'); self::$registry = new JRegistry('update'); jimport('joomla.filesystem.file'); if(JFile::exists(self::$filename)) { self::$registry->loadFile(self::$filename, 'INI'); } } public function save() { jimport('joomla.filesystem.file'); $data = self::$registry->toString('INI'); JFile::write(self::$filename, $data); } } home/academiac/www/administrator/components/com_virtuemart/liveupdate/classes/storage/file.php 0000604 00000002114 15137247356 0027216 0 ustar 00 <?php /** * @package LiveUpdate * @copyright Copyright ©2011 Nicholas K. Dionysopoulos / AkeebaBackup.com * @license GNU LGPLv3 or later <http://www.gnu.org/copyleft/lesser.html> */ defined('_JEXEC') or die(); /** * Live Update File Storage Class * Allows to store the update data to files on disk. Its configuration options are: * path string The absolute path to the directory where the update data will be stored as INI files * */ class LiveUpdateStorageFile extends LiveUpdateStorage { private static $filename = null; public function load($config) { $path = $config['path']; $extname = $config['extensionName']; $filename = "$path/$extname.updates.ini"; self::$filename = $filename; jimport('joomla.registry.registry'); self::$registry = new JRegistry('update'); jimport('joomla.filesystem.file'); if(JFile::exists(self::$filename)) { self::$registry->loadFile(self::$filename, 'INI'); } } public function save() { jimport('joomla.filesystem.file'); $data = self::$registry->toString('INI'); JFile::write(self::$filename, $data); } } home/academiac/www/libraries/joomla/cache/storage/file.php 0000644 00000036770 15137267410 0017626 0 ustar 00 <?php /** * @package Joomla.Platform * @subpackage Cache * * @copyright Copyright (C) 2005 - 2014 Open Source Matters, Inc. All rights reserved. * @license GNU General Public License version 2 or later; see LICENSE */ defined('JPATH_PLATFORM') or die; jimport('joomla.filesystem.file'); /** * File cache storage handler * * @package Joomla.Platform * @subpackage Cache * @since 11.1 */ class JCacheStorageFile extends JCacheStorage { /** * @var string * @since 11.1 */ protected $_root; /** * Constructor * * @param array $options Optional parameters * * @since 11.1 */ public function __construct($options = array()) { parent::__construct($options); $this->_root = $options['cachebase']; } // NOTE: raw php calls are up to 100 times faster than JFile or JFolder /** * Get cached data from a file by id and group * * @param string $id The cache data id * @param string $group The cache data group * @param boolean $checkTime True to verify cache time expiration threshold * * @return mixed Boolean false on failure or a cached data string * * @since 11.1 */ public function get($id, $group, $checkTime = true) { $data = false; $path = $this->_getFilePath($id, $group); if ($checkTime == false || ($checkTime == true && $this->_checkExpire($id, $group) === true)) { if (file_exists($path)) { $data = file_get_contents($path); if ($data) { // Remove the initial die() statement $data = str_replace('<?php die("Access Denied"); ?>#x#', '', $data); } } return $data; } else { return false; } } /** * Get all cached data * * @return array The cached data * * @since 11.1 */ public function getAll() { parent::getAll(); $path = $this->_root; $folders = $this->_folders($path); $data = array(); foreach ($folders as $folder) { $files = array(); $files = $this->_filesInFolder($path . '/' . $folder); $item = new JCacheStorageHelper($folder); foreach ($files as $file) { $item->updateSize(filesize($path . '/' . $folder . '/' . $file) / 1024); } $data[$folder] = $item; } return $data; } /** * Store the data to a file by id and group * * @param string $id The cache data id * @param string $group The cache data group * @param string $data The data to store in cache * * @return boolean True on success, false otherwise * * @since 11.1 */ public function store($id, $group, $data) { $written = false; $path = $this->_getFilePath($id, $group); $die = '<?php die("Access Denied"); ?>#x#'; // Prepend a die string $data = $die . $data; $_fileopen = @fopen($path, "wb"); if ($_fileopen) { $len = strlen($data); @fwrite($_fileopen, $data, $len); $written = true; } // Data integrity check if ($written && ($data == file_get_contents($path))) { return true; } else { return false; } } /** * Remove a cached data file by id and group * * @param string $id The cache data id * @param string $group The cache data group * * @return boolean True on success, false otherwise * * @since 11.1 */ public function remove($id, $group) { $path = $this->_getFilePath($id, $group); if (!@unlink($path)) { return false; } return true; } /** * Clean cache for a group given a mode. * * @param string $group The cache data group * @param string $mode The mode for cleaning cache [group|notgroup] * group mode : cleans all cache in the group * notgroup mode : cleans all cache not in the group * * @return boolean True on success, false otherwise * * @since 11.1 */ public function clean($group, $mode = null) { $return = true; $folder = $group; if (trim($folder) == '') { $mode = 'notgroup'; } switch ($mode) { case 'notgroup': $folders = $this->_folders($this->_root); for ($i = 0, $n = count($folders); $i < $n; $i++) { if ($folders[$i] != $folder) { $return |= $this->_deleteFolder($this->_root . '/' . $folders[$i]); } } break; case 'group': default: if (is_dir($this->_root . '/' . $folder)) { $return = $this->_deleteFolder($this->_root . '/' . $folder); } break; } return $return; } /** * Garbage collect expired cache data * * @return boolean True on success, false otherwise. * * @since 11.1 */ public function gc() { $result = true; // files older than lifeTime get deleted from cache $files = $this->_filesInFolder($this->_root, '', true, true, array('.svn', 'CVS', '.DS_Store', '__MACOSX', 'index.html')); foreach ($files as $file) { $time = @filemtime($file); if (($time + $this->_lifetime) < $this->_now || empty($time)) { $result |= @unlink($file); } } return $result; } /** * Test to see if the cache storage is available. * * @return boolean True on success, false otherwise. * * @since 11.1 */ public static function test() { $conf = JFactory::getConfig(); return is_writable($conf->get('cache_path', JPATH_CACHE)); } /** * Lock cached item * * @param string $id The cache data id * @param string $group The cache data group * @param integer $locktime Cached item max lock time * * @return boolean True on success, false otherwise. * * @since 11.1 */ public function lock($id, $group, $locktime) { $returning = new stdClass; $returning->locklooped = false; $looptime = $locktime * 10; $path = $this->_getFilePath($id, $group); $_fileopen = @fopen($path, "r+b"); if ($_fileopen) { $data_lock = @flock($_fileopen, LOCK_EX); } else { $data_lock = false; } if ($data_lock === false) { $lock_counter = 0; // loop until you find that the lock has been released. that implies that data get from other thread has finished while ($data_lock === false) { if ($lock_counter > $looptime) { $returning->locked = false; $returning->locklooped = true; break; } usleep(100); $data_lock = @flock($_fileopen, LOCK_EX); $lock_counter++; } } $returning->locked = $data_lock; return $returning; } /** * Unlock cached item * * @param string $id The cache data id * @param string $group The cache data group * * @return boolean True on success, false otherwise. * * @since 11.1 */ public function unlock($id, $group = null) { $path = $this->_getFilePath($id, $group); $_fileopen = @fopen($path, "r+b"); if ($_fileopen) { $ret = @flock($_fileopen, LOCK_UN); @fclose($_fileopen); } return $ret; } /** * Check to make sure cache is still valid, if not, delete it. * * @param string $id Cache key to expire. * @param string $group The cache data group. * * @return boolean False if not valid * * @since 11.1 */ protected function _checkExpire($id, $group) { $path = $this->_getFilePath($id, $group); // check prune period if (file_exists($path)) { $time = @filemtime($path); if (($time + $this->_lifetime) < $this->_now || empty($time)) { @unlink($path); return false; } return true; } return false; } /** * Get a cache file path from an id/group pair * * @param string $id The cache data id * @param string $group The cache data group * * @return string The cache file path * * @since 11.1 */ protected function _getFilePath($id, $group) { $name = $this->_getCacheId($id, $group); $dir = $this->_root . '/' . $group; // If the folder doesn't exist try to create it if (!is_dir($dir)) { // Make sure the index file is there $indexFile = $dir . '/index.html'; @ mkdir($dir) && file_put_contents($indexFile, '<!DOCTYPE html><title></title>'); } // Make sure the folder exists if (!is_dir($dir)) { return false; } return $dir . '/' . $name . '.php'; } /** * Quickly delete a folder of files * * @param string $path The path to the folder to delete. * * @return boolean True on success. * * @since 11.1 */ protected function _deleteFolder($path) { // Sanity check if (!$path || !is_dir($path) || empty($this->_root)) { // Bad programmer! Bad Bad programmer! JError::raiseWarning(500, 'JCacheStorageFile::_deleteFolder ' . JText::_('JLIB_FILESYSTEM_ERROR_DELETE_BASE_DIRECTORY')); return false; } $path = $this->_cleanPath($path); // Check to make sure path is inside cache folder, we do not want to delete Joomla root! $pos = strpos($path, $this->_cleanPath($this->_root)); if ($pos === false || $pos > 0) { JError::raiseWarning(500, 'JCacheStorageFile::_deleteFolder' . JText::sprintf('JLIB_FILESYSTEM_ERROR_PATH_IS_NOT_A_FOLDER', $path)); return false; } // Remove all the files in folder if they exist; disable all filtering $files = $this->_filesInFolder($path, '.', false, true, array(), array()); if (!empty($files) && !is_array($files)) { if (@unlink($files) !== true) { return false; } } elseif (!empty($files) && is_array($files)) { foreach ($files as $file) { $file = $this->_cleanPath($file); // In case of restricted permissions we zap it one way or the other // as long as the owner is either the webserver or the ftp if (@unlink($file)) { // Do nothing } else { $filename = basename($file); JError::raiseWarning('SOME_ERROR_CODE', 'JCacheStorageFile::_deleteFolder' . JText::sprintf('JLIB_FILESYSTEM_DELETE_FAILED', $filename)); return false; } } } // Remove sub-folders of folder; disable all filtering $folders = $this->_folders($path, '.', false, true, array(), array()); foreach ($folders as $folder) { if (is_link($folder)) { // Don't descend into linked directories, just delete the link. if (@unlink($folder) !== true) { return false; } } elseif ($this->_deleteFolder($folder) !== true) { return false; } } // In case of restricted permissions we zap it one way or the other // as long as the owner is either the webserver or the ftp if (@rmdir($path)) { $ret = true; } else { JError::raiseWarning('SOME_ERROR_CODE', 'JCacheStorageFile::_deleteFolder' . JText::sprintf('JLIB_FILESYSTEM_ERROR_FOLDER_DELETE', $path)); $ret = false; } return $ret; } /** * Function to strip additional / or \ in a path name * * @param string $path The path to clean * @param string $ds Directory separator (optional) * * @return string The cleaned path * * @since 11.1 */ protected function _cleanPath($path, $ds = DIRECTORY_SEPARATOR) { $path = trim($path); if (empty($path)) { $path = $this->_root; } else { // Remove double slashes and backslahses and convert all slashes and backslashes to DIRECTORY_SEPARATOR $path = preg_replace('#[/\\\\]+#', $ds, $path); } return $path; } /** * Utility function to quickly read the files in a folder. * * @param string $path The path of the folder to read. * @param string $filter A filter for file names. * @param mixed $recurse True to recursively search into sub-folders, or an * integer to specify the maximum depth. * @param boolean $fullpath True to return the full path to the file. * @param array $exclude Array with names of files which should not be shown in * the result. * @param array $excludefilter Array of folder names to exclude * * @return array Files in the given folder. * * @since 11.1 */ protected function _filesInFolder($path, $filter = '.', $recurse = false, $fullpath = false , $exclude = array('.svn', 'CVS', '.DS_Store', '__MACOSX'), $excludefilter = array('^\..*', '.*~')) { // Initialise variables. $arr = array(); // Check to make sure the path valid and clean $path = $this->_cleanPath($path); // Is the path a folder? if (!is_dir($path)) { JError::raiseWarning(21, 'JCacheStorageFile::_filesInFolder' . JText::sprintf('JLIB_FILESYSTEM_ERROR_PATH_IS_NOT_A_FOLDER', $path)); return false; } // Read the source directory. if (!($handle = @opendir($path))) { return $arr; } if (count($excludefilter)) { $excludefilter = '/(' . implode('|', $excludefilter) . ')/'; } else { $excludefilter = ''; } while (($file = readdir($handle)) !== false) { if (($file != '.') && ($file != '..') && (!in_array($file, $exclude)) && (!$excludefilter || !preg_match($excludefilter, $file))) { $dir = $path . '/' . $file; $isDir = is_dir($dir); if ($isDir) { if ($recurse) { if (is_integer($recurse)) { $arr2 = $this->_filesInFolder($dir, $filter, $recurse - 1, $fullpath); } else { $arr2 = $this->_filesInFolder($dir, $filter, $recurse, $fullpath); } $arr = array_merge($arr, $arr2); } } else { if (preg_match("/$filter/", $file)) { if ($fullpath) { $arr[] = $path . '/' . $file; } else { $arr[] = $file; } } } } } closedir($handle); return $arr; } /** * Utility function to read the folders in a folder. * * @param string $path The path of the folder to read. * @param string $filter A filter for folder names. * @param mixed $recurse True to recursively search into sub-folders, or an integer to specify the maximum depth. * @param boolean $fullpath True to return the full path to the folders. * @param array $exclude Array with names of folders which should not be shown in the result. * @param array $excludefilter Array with regular expressions matching folders which should not be shown in the result. * * @return array Folders in the given folder. * * @since 11.1 */ protected function _folders($path, $filter = '.', $recurse = false, $fullpath = false , $exclude = array('.svn', 'CVS', '.DS_Store', '__MACOSX'), $excludefilter = array('^\..*')) { // Initialise variables. $arr = array(); // Check to make sure the path valid and clean $path = $this->_cleanPath($path); // Is the path a folder? if (!is_dir($path)) { JError::raiseWarning(21, 'JCacheStorageFile::_folders' . JText::sprintf('JLIB_FILESYSTEM_ERROR_PATH_IS_NOT_A_FOLDER', $path)); return false; } // read the source directory if (!($handle = @opendir($path))) { return $arr; } if (count($excludefilter)) { $excludefilter_string = '/(' . implode('|', $excludefilter) . ')/'; } else { $excludefilter_string = ''; } while (($file = readdir($handle)) !== false) { if (($file != '.') && ($file != '..') && (!in_array($file, $exclude)) && (empty($excludefilter_string) || !preg_match($excludefilter_string, $file))) { $dir = $path . '/' . $file; $isDir = is_dir($dir); if ($isDir) { // Removes filtered directories if (preg_match("/$filter/", $file)) { if ($fullpath) { $arr[] = $dir; } else { $arr[] = $file; } } if ($recurse) { if (is_integer($recurse)) { $arr2 = $this->_folders($dir, $filter, $recurse - 1, $fullpath, $exclude, $excludefilter); } else { $arr2 = $this->_folders($dir, $filter, $recurse, $fullpath, $exclude, $excludefilter); } $arr = array_merge($arr, $arr2); } } } } closedir($handle); return $arr; } } home/academiac/www/libraries/joomla/installer/adapters/file.php 0000644 00000046525 15137270412 0020712 0 ustar 00 <?php /** * @package Joomla.Platform * @subpackage Installer * * @copyright Copyright (C) 2005 - 2014 Open Source Matters, Inc. All rights reserved. * @license GNU General Public License version 2 or later; see LICENSE */ defined('JPATH_PLATFORM') or die; jimport('joomla.installer.filemanifest'); jimport('joomla.base.adapterinstance'); /** * File installer * * @package Joomla.Platform * @subpackage Installer * @since 11.1 */ class JInstallerFile extends JAdapterInstance { protected $route = 'install'; /** * Custom loadLanguage method * * @param string $path The path on which to find language files. * * @return void * * @since 11.1 */ public function loadLanguage($path) { $this->manifest = $this->parent->getManifest(); $extension = 'files_' . str_replace('files_', '', strtolower(JFilterInput::getInstance()->clean((string) $this->manifest->name, 'cmd'))); $lang = JFactory::getLanguage(); $source = $path; $lang->load($extension . '.sys', $source, null, false, true) || $lang->load($extension . '.sys', JPATH_SITE, null, false, true); } /** * Custom install method * * @return boolean True on success * * @since 11.1 */ public function install() { // Get the extension manifest object $this->manifest = $this->parent->getManifest(); // Manifest Document Setup Section // Set the extension's name $name = JFilterInput::getInstance()->clean((string) $this->manifest->name, 'string'); $this->set('name', $name); // Set element $manifestPath = JPath::clean($this->parent->getPath('manifest')); $element = preg_replace('/\.xml/', '', basename($manifestPath)); $this->set('element', $element); // Get the component description $description = (string) $this->manifest->description; if ($description) { $this->parent->set('message', JText::_($description)); } else { $this->parent->set('message', ''); } //Check if the extension by the same name is already installed if ($this->extensionExistsInSystem($element)) { // Package with same name already exists if (!$this->parent->isOverwrite()) { // we're not overwriting so abort $this->parent->abort(JText::_('JLIB_INSTALLER_ABORT_FILE_SAME_NAME')); return false; } else { // swap to the update route $this->route = 'update'; } } // Set the file root path $this->parent->setPath('extension_root', JPATH_ROOT); /** * --------------------------------------------------------------------------------------------- * Installer Trigger Loading * --------------------------------------------------------------------------------------------- */ // If there is an manifest class file, lets load it; we'll copy it later (don't have dest yet) $this->scriptElement = $this->manifest->scriptfile; $manifestScript = (string) $this->manifest->scriptfile; if ($manifestScript) { $manifestScriptFile = $this->parent->getPath('source') . '/' . $manifestScript; if (is_file($manifestScriptFile)) { // load the file include_once $manifestScriptFile; } // Set the class name $classname = $element . 'InstallerScript'; if (class_exists($classname)) { // create a new instance $this->parent->manifestClass = new $classname($this); // and set this so we can copy it later $this->set('manifest_script', $manifestScript); // Note: if we don't find the class, don't bother to copy the file } } // run preflight if possible (since we know we're not an update) ob_start(); ob_implicit_flush(false); if ($this->parent->manifestClass && method_exists($this->parent->manifestClass, 'preflight')) { if ($this->parent->manifestClass->preflight($this->route, $this) === false) { // Install failed, rollback changes $this->parent->abort(JText::_('JLIB_INSTALLER_ABORT_FILE_INSTALL_CUSTOM_INSTALL_FAILURE')); return false; } } $msg = ob_get_contents(); // create msg object; first use here ob_end_clean(); // Populate File and Folder List to copy $this->populateFilesAndFolderList(); // Filesystem Processing Section // Now that we have folder list, lets start creating them foreach ($this->folderList as $folder) { if (!JFolder::exists($folder)) { if (!$created = JFolder::create($folder)) { JError::raiseWarning(1, JText::sprintf('JLIB_INSTALLER_ABORT_FILE_INSTALL_FAIL_SOURCE_DIRECTORY', $folder)); // If installation fails, rollback $this->parent->abort(); return false; } // Since we created a directory and will want to remove it if we have to roll back. // the installation due to some errors, let's add it to the installation step stack. if ($created) { $this->parent->pushStep(array('type' => 'folder', 'path' => $folder)); } } } // Now that we have file list, let's start copying them $this->parent->copyFiles($this->fileList); // Parse optional tags $this->parent->parseLanguages($this->manifest->languages); // Finalization and Cleanup Section // Get a database connector object $db = $this->parent->getDbo(); // Check to see if a module by the same name is already installed // If it is, then update the table because if the files aren't there // we can assume that it was (badly) uninstalled // If it isn't, add an entry to extensions $query = $db->getQuery(true); $query->select($query->qn('extension_id')) ->from($query->qn('#__extensions')); $query->where($query->qn('type') . ' = ' . $query->q('file')) ->where($query->qn('element') . ' = ' . $query->q($element)); $db->setQuery($query); try { $db->execute(); } catch (JException $e) { // Install failed, roll back changes $this->parent->abort( JText::sprintf('JLIB_INSTALLER_ABORT_FILE_ROLLBACK', JText::_('JLIB_INSTALLER_' . $this->route), $db->stderr(true)) ); return false; } $id = $db->loadResult(); $row = JTable::getInstance('extension'); if ($id) { // Load the entry and update the manifest_cache $row->load($id); // Update name $row->set('name', $this->get('name')); // Update manifest $row->manifest_cache = $this->parent->generateManifestCache(); if (!$row->store()) { // Install failed, roll back changes $this->parent->abort( JText::sprintf('JLIB_INSTALLER_ABORT_FILE_ROLLBACK', JText::_('JLIB_INSTALLER_' . $this->route), $db->stderr(true)) ); return false; } } else { // Add an entry to the extension table with a whole heap of defaults $row->set('name', $this->get('name')); $row->set('type', 'file'); $row->set('element', $this->get('element')); // There is no folder for files so leave it blank $row->set('folder', ''); $row->set('enabled', 1); $row->set('protected', 0); $row->set('access', 0); $row->set('client_id', 0); $row->set('params', ''); $row->set('system_data', ''); $row->set('manifest_cache', $this->parent->generateManifestCache()); if (!$row->store()) { // Install failed, roll back changes $this->parent->abort(JText::sprintf('JLIB_INSTALLER_ABORT_FILE_INSTALL_ROLLBACK', $db->stderr(true))); return false; } // Set the insert id $row->set('extension_id', $db->insertid()); // Since we have created a module item, we add it to the installation step stack // so that if we have to rollback the changes we can undo it. $this->parent->pushStep(array('type' => 'extension', 'extension_id' => $row->extension_id)); } /* * Let's run the queries for the file */ // second argument is the utf compatible version attribute if (strtolower($this->route) == 'install') { $utfresult = $this->parent->parseSQLFiles($this->manifest->install->sql); if ($utfresult === false) { // Install failed, rollback changes $this->parent->abort( JText::sprintf('JLIB_INSTALLER_ABORT_FILE_INSTALL_SQL_ERROR', JText::_('JLIB_INSTALLER_' . $this->route), $db->stderr(true)) ); return false; } // Set the schema version to be the latest update version if ($this->manifest->update) { $this->parent->setSchemaVersion($this->manifest->update->schemas, $row->extension_id); } } elseif (strtolower($this->route) == 'update') { if ($this->manifest->update) { $result = $this->parent->parseSchemaUpdates($this->manifest->update->schemas, $row->extension_id); if ($result === false) { // Install failed, rollback changes $this->parent->abort(JText::sprintf('JLIB_INSTALLER_ABORT_FILE_UPDATE_SQL_ERROR', $db->stderr(true))); return false; } } } // Start Joomla! 1.6 ob_start(); ob_implicit_flush(false); if ($this->parent->manifestClass && method_exists($this->parent->manifestClass, $this->route)) { if ($this->parent->manifestClass->{$this->route}($this) === false) { // Install failed, rollback changes $this->parent->abort(JText::_('JLIB_INSTALLER_ABORT_FILE_INSTALL_CUSTOM_INSTALL_FAILURE')); return false; } } $msg .= ob_get_contents(); // append messages ob_end_clean(); // Lastly, we will copy the manifest file to its appropriate place. $manifest = array(); $manifest['src'] = $this->parent->getPath('manifest'); $manifest['dest'] = JPATH_MANIFESTS . '/files/' . basename($this->parent->getPath('manifest')); if (!$this->parent->copyFiles(array($manifest), true)) { // Install failed, rollback changes $this->parent->abort(JText::_('JLIB_INSTALLER_ABORT_FILE_INSTALL_COPY_SETUP')); return false; } // Clobber any possible pending updates $update = JTable::getInstance('update'); $uid = $update->find( array('element' => $this->get('element'), 'type' => 'file', 'client_id' => '', 'folder' => '') ); if ($uid) { $update->delete($uid); } // And now we run the postflight ob_start(); ob_implicit_flush(false); if ($this->parent->manifestClass && method_exists($this->parent->manifestClass, 'postflight')) { $this->parent->manifestClass->postflight($this->route, $this); } $msg .= ob_get_contents(); // append messages ob_end_clean(); if ($msg != '') { $this->parent->set('extension_message', $msg); } return $row->get('extension_id'); } /** * Custom update method * * @return boolean True on success * * @since 11.1 */ public function update() { // Set the overwrite setting $this->parent->setOverwrite(true); $this->parent->setUpgrade(true); $this->route = 'update'; // ...and adds new files return $this->install(); } /** * Custom uninstall method * * @param string $id The id of the file to uninstall * * @return boolean True on success * * @since 11.1 */ public function uninstall($id) { // Initialise variables. $row = JTable::getInstance('extension'); if (!$row->load($id)) { JError::raiseWarning(100, JText::_('JLIB_INSTALLER_ERROR_FILE_UNINSTALL_LOAD_ENTRY')); return false; } if ($row->protected) { JError::raiseWarning(100, JText::_('JLIB_INSTALLER_ERROR_FILE_UNINSTALL_WARNCOREFILE')); return false; } $retval = true; $manifestFile = JPATH_MANIFESTS . '/files/' . $row->element . '.xml'; // Because files may not have their own folders we cannot use the standard method of finding an installation manifest if (file_exists($manifestFile)) { // Set the plugin root path $this->parent->setPath('extension_root', JPATH_ROOT); // . '/files/' . $manifest->filename); $xml = JFactory::getXML($manifestFile); // If we cannot load the XML file return null if (!$xml) { JError::raiseWarning(100, JText::_('JLIB_INSTALLER_ERROR_FILE_UNINSTALL_LOAD_MANIFEST')); return false; } /* * Check for a valid XML root tag. */ if ($xml->getName() != 'extension') { JError::raiseWarning(100, JText::_('JLIB_INSTALLER_ERROR_FILE_UNINSTALL_INVALID_MANIFEST')); return false; } $this->manifest = $xml; // If there is an manifest class file, let's load it $this->scriptElement = $this->manifest->scriptfile; $manifestScript = (string) $this->manifest->scriptfile; if ($manifestScript) { $manifestScriptFile = $this->parent->getPath('extension_root') . '/' . $manifestScript; if (is_file($manifestScriptFile)) { // Load the file include_once $manifestScriptFile; } // Set the class name $classname = $row->element . 'InstallerScript'; if (class_exists($classname)) { // Create a new instance $this->parent->manifestClass = new $classname($this); // And set this so we can copy it later $this->set('manifest_script', $manifestScript); // Note: if we don't find the class, don't bother to copy the file } } ob_start(); ob_implicit_flush(false); // Run uninstall if possible if ($this->parent->manifestClass && method_exists($this->parent->manifestClass, 'uninstall')) { $this->parent->manifestClass->uninstall($this); } $msg = ob_get_contents(); ob_end_clean(); /* * Let's run the uninstall queries for the component * If Joomla 1.5 compatible, with discreet sql files - execute appropriate * file for utf-8 support or non-utf support */ // Try for Joomla 1.5 type queries // Second argument is the utf compatible version attribute $utfresult = $this->parent->parseSQLFiles($this->manifest->uninstall->sql); $db = JFactory::getDbo(); if ($utfresult === false) { // Install failed, rollback changes JError::raiseWarning(100, JText::sprintf('JLIB_INSTALLER_ERROR_FILE_UNINSTALL_SQL_ERROR', $db->stderr(true))); $retval = false; } // Remove the schema version $query = $db->getQuery(true); $query->delete() ->from('#__schemas') ->where('extension_id = ' . $row->extension_id); $db->setQuery($query); $db->execute(); // Set root folder names $packagePath = $this->parent->getPath('source'); $jRootPath = JPath::clean(JPATH_ROOT); // Loop through all elements and get list of files and folders foreach ($xml->fileset->files as $eFiles) { $folder = (string) $eFiles->attributes()->folder; $target = (string) $eFiles->attributes()->target; // Create folder path if (empty($target)) { $targetFolder = JPATH_ROOT; } else { $targetFolder = JPATH_ROOT . '/' . $target; } $folderList = array(); // Check if all children exists if (count($eFiles->children()) > 0) { // Loop through all filenames elements foreach ($eFiles->children() as $eFileName) { if ($eFileName->getName() == 'folder') { $folderList[] = $targetFolder . '/' . $eFileName; } else { $fileName = $targetFolder . '/' . $eFileName; JFile::delete($fileName); } } } // Delete any folders that don't have any content in them. foreach ($folderList as $folder) { $files = JFolder::files($folder); if (!count($files)) { JFolder::delete($folder); } } } JFile::delete($manifestFile); } else { JError::raiseWarning(100, JText::_('JLIB_INSTALLER_ERROR_FILE_UNINSTALL_INVALID_NOTFOUND_MANIFEST')); // Delete the row because its broken $row->delete(); return false; } $this->parent->removeFiles($xml->languages); $row->delete(); return $retval; } /** * Function used to check if extension is already installed * * @param string $extension The element name of the extension to install * * @return boolean True if extension exists * * @since 11.1 */ protected function extensionExistsInSystem($extension = null) { // Get a database connector object $db = $this->parent->getDBO(); $query = $db->getQuery(true); $query->select($query->qn('extension_id')) ->from($query->qn('#__extensions')); $query->where($query->qn('type') . ' = ' . $query->q('file')) ->where($query->qn('element') . ' = ' . $query->q($extension)); $db->setQuery($query); try { $db->execute(); } catch (JException $e) { // Install failed, roll back changes $this->parent->abort(JText::sprintf('JLIB_INSTALLER_ABORT_FILE_ROLLBACK', $db->stderr(true))); return false; } $id = $db->loadResult(); if (empty($id)) { return false; } return true; } /** * Function used to populate files and folder list * * @return boolean none * * @since 11.1 */ protected function populateFilesAndFolderList() { // Initialise variable $this->folderList = array(); $this->fileList = array(); // Get fileset $eFileset = $this->manifest->fileset->files; // Set root folder names $packagePath = $this->parent->getPath('source'); $jRootPath = JPath::clean(JPATH_ROOT); // Loop through all elements and get list of files and folders foreach ($this->manifest->fileset->files as $eFiles) { // Check if the element is files element $folder = (string) $eFiles->attributes()->folder; $target = (string) $eFiles->attributes()->target; //Split folder names into array to get folder names. This will // help in creating folders $arrList = preg_split("#/|\\/#", $target); $folderName = $jRootPath; foreach ($arrList as $dir) { if (empty($dir)) { continue; } $folderName .= '/' . $dir; // Check if folder exists, if not then add to the array for folder creation if (!JFolder::exists($folderName)) { array_push($this->folderList, $folderName); } } // Create folder path $sourceFolder = empty($folder) ? $packagePath : $packagePath . '/' . $folder; $targetFolder = empty($target) ? $jRootPath : $jRootPath . '/' . $target; // Check if source folder exists if (!JFolder::exists($sourceFolder)) { JError::raiseWarning(1, JText::sprintf('JLIB_INSTALLER_ABORT_FILE_INSTALL_FAIL_SOURCE_DIRECTORY', $sourceFolder)); // If installation fails, rollback $this->parent->abort(); return false; } // Check if all children exists if (count($eFiles->children())) { // Loop through all filenames elements foreach ($eFiles->children() as $eFileName) { $path['src'] = $sourceFolder . '/' . $eFileName; $path['dest'] = $targetFolder . '/' . $eFileName; $path['type'] = 'file'; if ($eFileName->getName() == 'folder') { $folderName = $targetFolder . '/' . $eFileName; array_push($this->folderList, $folderName); $path['type'] = 'folder'; } array_push($this->fileList, $path); } } else { $files = JFolder::files($sourceFolder); foreach ($files as $file) { $path['src'] = $sourceFolder . '/' . $file; $path['dest'] = $targetFolder . '/' . $file; array_push($this->fileList, $path); } } } } /** * Refreshes the extension table cache * * @return boolean result of operation, true if updated, false on failure * * @since 11.1 */ public function refreshManifestCache() { // Need to find to find where the XML file is since we don't store this normally $manifestPath = JPATH_MANIFESTS . '/files/' . $this->parent->extension->element . '.xml'; $this->parent->manifest = $this->parent->isManifest($manifestPath); $this->parent->setPath('manifest', $manifestPath); $manifest_details = JApplicationHelper::parseXMLInstallFile($this->parent->getPath('manifest')); $this->parent->extension->manifest_cache = json_encode($manifest_details); $this->parent->extension->name = $manifest_details['name']; try { return $this->parent->extension->store(); } catch (JException $e) { JError::raiseWarning(101, JText::_('JLIB_INSTALLER_ERROR_PACK_REFRESH_MANIFEST_CACHE')); return false; } } } home/academiac/www/administrator/components/com_media/controllers/file.php 0000644 00000021447 15137374436 0023214 0 ustar 00 <?php /** * @copyright Copyright (C) 2005 - 2014 Open Source Matters, Inc. All rights reserved. * @license GNU General Public License version 2 or later; see LICENSE.txt */ // No direct access defined('_JEXEC') or die; jimport('joomla.filesystem.file'); jimport('joomla.filesystem.folder'); /** * Media File Controller * * @package Joomla.Administrator * @subpackage com_media * @since 1.5 */ class MediaControllerFile extends JControllerLegacy { /* * The folder we are uploading into */ protected $folder = ''; /** * Upload one or more files * * @since 1.5 */ public function upload() { // Check for request forgeries JSession::checkToken('request') or jexit(JText::_('JINVALID_TOKEN')); $params = JComponentHelper::getParams('com_media'); // Get some data from the request $files = JRequest::getVar('Filedata', '', 'files', 'array'); $return = JRequest::getVar('return-url', null, 'post', 'base64'); $this->folder = JRequest::getVar('folder', '', '', 'path'); // Set the redirect if ($return) { $this->setRedirect(base64_decode($return) . '&folder=' . $this->folder); } // Authorize the user if (!$this->authoriseUser('create')) { return false; } if ( $_SERVER['CONTENT_LENGTH']>($params->get('upload_maxsize', 0) * 1024 * 1024) || $_SERVER['CONTENT_LENGTH']>(int)(ini_get('upload_max_filesize'))* 1024 * 1024 || $_SERVER['CONTENT_LENGTH']>(int)(ini_get('post_max_size'))* 1024 * 1024 || (($_SERVER['CONTENT_LENGTH'] > (int) (ini_get('memory_limit')) * 1024 * 1024) && ((int) (ini_get('memory_limit')) != -1)) ) { JError::raiseWarning(100, JText::_('COM_MEDIA_ERROR_WARNFILETOOLARGE')); return false; } // Input is in the form of an associative array containing numerically indexed arrays // We want a numerically indexed array containing associative arrays // Cast each item as array in case the Filedata parameter was not sent as such $files = array_map( array($this, 'reformatFilesArray'), (array) $files['name'], (array) $files['type'], (array) $files['tmp_name'], (array) $files['error'], (array) $files['size'] ); // Perform basic checks on file info before attempting anything foreach ($files as &$file) { if ($file['error']==1) { JError::raiseWarning(100, JText::_('COM_MEDIA_ERROR_WARNFILETOOLARGE')); return false; } if ($file['size']>($params->get('upload_maxsize', 0) * 1024 * 1024)) { JError::raiseNotice(100, JText::_('COM_MEDIA_ERROR_WARNFILETOOLARGE')); return false; } if (JFile::exists($file['filepath'])) { // A file with this name already exists JError::raiseWarning(100, JText::_('COM_MEDIA_ERROR_FILE_EXISTS')); return false; } if (!isset($file['name'])) { // No filename (after the name was cleaned by JFile::makeSafe) $this->setRedirect('index.php', JText::_('COM_MEDIA_INVALID_REQUEST'), 'error'); return false; } } // Set FTP credentials, if given JClientHelper::setCredentialsFromRequest('ftp'); JPluginHelper::importPlugin('content'); $dispatcher = JDispatcher::getInstance(); foreach ($files as &$file) { // The request is valid $err = null; if (!MediaHelper::canUpload($file, $err)) { // The file can't be upload JError::raiseNotice(100, JText::_($err)); return false; } // Trigger the onContentBeforeSave event. $object_file = new JObject($file); $result = $dispatcher->trigger('onContentBeforeSave', array('com_media.file', &$object_file, true)); if (in_array(false, $result, true)) { // There are some errors in the plugins JError::raiseWarning(100, JText::plural('COM_MEDIA_ERROR_BEFORE_SAVE', count($errors = $object_file->getErrors()), implode('<br />', $errors))); return false; } if (!JFile::upload($file['tmp_name'], $file['filepath'])) { // Error in upload JError::raiseWarning(100, JText::_('COM_MEDIA_ERROR_UNABLE_TO_UPLOAD_FILE')); return false; } else { // Trigger the onContentAfterSave event. $dispatcher->trigger('onContentAfterSave', array('com_media.file', &$object_file, true)); $this->setMessage(JText::sprintf('COM_MEDIA_UPLOAD_COMPLETE', substr($file['filepath'], strlen(COM_MEDIA_BASE)))); } } return true; } /** * Used as a callback for array_map, turns the multi-file input array into a sensible array of files * Also, removes illegal characters from the 'name' and sets a 'filepath' as the final destination of the file * * @param string - file name ($files['name']) * @param string - file type ($files['type']) * @param string - temporary name ($files['tmp_name']) * @param string - error info ($files['error']) * @param string - file size ($files['size']) * * @return array * @access protected */ protected function reformatFilesArray($name, $type, $tmp_name, $error, $size) { $name = JFile::makeSafe($name); return array( 'name' => $name, 'type' => $type, 'tmp_name' => $tmp_name, 'error' => $error, 'size' => $size, 'filepath' => JPath::clean(implode(DIRECTORY_SEPARATOR, array(COM_MEDIA_BASE, $this->folder, $name))) ); } /** * Check that the user is authorized to perform this action * * @param string $action - the action to be peformed (create or delete) * * @return boolean * @access protected */ protected function authoriseUser($action) { if (!JFactory::getUser()->authorise('core.' . strtolower($action), 'com_media')) { // User is not authorised JError::raiseWarning(403, JText::_('JLIB_APPLICATION_ERROR_' . strtoupper($action) . '_NOT_PERMITTED')); return false; } return true; } /** * Deletes paths from the current path * * @since 1.5 */ public function delete() { JSession::checkToken('request') or jexit(JText::_('JINVALID_TOKEN')); // Get some data from the request $tmpl = JRequest::getCmd('tmpl'); $paths = JRequest::getVar('rm', array(), '', 'array'); $folder = JRequest::getVar('folder', '', '', 'path'); $redirect = 'index.php?option=com_media&folder=' . $folder; if ($tmpl == 'component') { // We are inside the iframe $redirect .= '&view=mediaList&tmpl=component'; } $this->setRedirect($redirect); // Nothing to delete if (empty($paths)) { return true; } // Authorize the user if (!$this->authoriseUser('delete')) { return false; } // Set FTP credentials, if given JClientHelper::setCredentialsFromRequest('ftp'); JPluginHelper::importPlugin('content'); $dispatcher = JDispatcher::getInstance(); // Initialise variables. $ret = true; foreach ($paths as $path) { if ($path !== JFile::makeSafe($path)) { // filename is not safe $filename = htmlspecialchars($path, ENT_COMPAT, 'UTF-8'); JError::raiseWarning(100, JText::sprintf('COM_MEDIA_ERROR_UNABLE_TO_DELETE_FILE_WARNFILENAME', substr($filename, strlen(COM_MEDIA_BASE)))); continue; } $fullPath = JPath::clean(implode(DIRECTORY_SEPARATOR, array(COM_MEDIA_BASE, $folder, $path))); $object_file = new JObject(array('filepath' => $fullPath)); if (is_file($fullPath)) { // Trigger the onContentBeforeDelete event. $result = $dispatcher->trigger('onContentBeforeDelete', array('com_media.file', &$object_file)); if (in_array(false, $result, true)) { // There are some errors in the plugins JError::raiseWarning(100, JText::plural('COM_MEDIA_ERROR_BEFORE_DELETE', count($errors = $object_file->getErrors()), implode('<br />', $errors))); continue; } $ret &= JFile::delete($fullPath); // Trigger the onContentAfterDelete event. $dispatcher->trigger('onContentAfterDelete', array('com_media.file', &$object_file)); $this->setMessage(JText::sprintf('COM_MEDIA_DELETE_COMPLETE', substr($fullPath, strlen(COM_MEDIA_BASE)))); } elseif (is_dir($fullPath)) { $contents = JFolder::files($fullPath, '.', true, false, array('.svn', 'CVS', '.DS_Store', '__MACOSX', 'index.html')); if (empty($contents)) { // Trigger the onContentBeforeDelete event. $result = $dispatcher->trigger('onContentBeforeDelete', array('com_media.folder', &$object_file)); if (in_array(false, $result, true)) { // There are some errors in the plugins JError::raiseWarning(100, JText::plural('COM_MEDIA_ERROR_BEFORE_DELETE', count($errors = $object_file->getErrors()), implode('<br />', $errors))); continue; } $ret &= JFolder::delete($fullPath); // Trigger the onContentAfterDelete event. $dispatcher->trigger('onContentAfterDelete', array('com_media.folder', &$object_file)); $this->setMessage(JText::sprintf('COM_MEDIA_DELETE_COMPLETE', substr($fullPath, strlen(COM_MEDIA_BASE)))); } else { // This makes no sense... JError::raiseWarning(100, JText::sprintf('COM_MEDIA_ERROR_UNABLE_TO_DELETE_FOLDER_NOT_EMPTY', substr($fullPath, strlen(COM_MEDIA_BASE)))); } } } return $ret; } } home/academiac/www/libraries/joomla/form/fields/file.php 0000644 00000003345 15137515214 0017316 0 ustar 00 <?php /** * @package Joomla.Platform * @subpackage Form * * @copyright Copyright (C) 2005 - 2014 Open Source Matters, Inc. All rights reserved. * @license GNU General Public License version 2 or later; see LICENSE */ defined('JPATH_PLATFORM') or die; /** * Form Field class for the Joomla Platform. * Provides an input field for files * * @package Joomla.Platform * @subpackage Form * @link http://www.w3.org/TR/html-markup/input.file.html#input.file * @since 11.1 */ class JFormFieldFile extends JFormField { /** * The form field type. * * @var string * @since 11.1 */ public $type = 'File'; /** * Method to get the field input markup for the file field. * Field attributes allow specification of a maximum file size and a string * of accepted file extensions. * * @return string The field input markup. * * @since 11.1 * * @note The field does not include an upload mechanism. * @see JFormFieldMedia */ protected function getInput() { // Initialize some field attributes. $accept = $this->element['accept'] ? ' accept="' . (string) $this->element['accept'] . '"' : ''; $size = $this->element['size'] ? ' size="' . (int) $this->element['size'] . '"' : ''; $class = $this->element['class'] ? ' class="' . (string) $this->element['class'] . '"' : ''; $disabled = ((string) $this->element['disabled'] == 'true') ? ' disabled="disabled"' : ''; // Initialize JavaScript field attributes. $onchange = $this->element['onchange'] ? ' onchange="' . (string) $this->element['onchange'] . '"' : ''; return '<input type="file" name="' . $this->name . '" id="' . $this->id . '"' . ' value=""' . $accept . $disabled . $class . $size . $onchange . ' />'; } } home/academiac/www/administrator/components/com_csvi/helpers/file.php 0000604 00000040004 15140023445 0022140 0 ustar 00 <?php /** * Main file processor class * * @package CSVI * @author Roland Dalmulder * @link http://www.csvimproved.com * @copyright Copyright (C) 2006 - 2013 RolandD Cyber Produksi. All rights reserved. * @license GNU/GPLv3 http://www.gnu.org/licenses/gpl-3.0.html * @version $Id: file.php 2275 2013-01-03 21:08:43Z RolandD $ */ defined( '_JEXEC' ) or die( 'Direct Access to this location is not allowed.' ); /** * CsviFile class * * The CsviFile class handles all file operations * * @package CSVI */ abstract class CsviFile { /** @var array Contains the list of available fields in the target table */ protected $_supported_fields = array(); /** @var array Contains allowed extensions for uploaded files */ public $suffixes = array(); /** @var array Contains allowed mimetypes for uploaded files */ public $mimetypes = array(); /** @var array Contains allowed archivetypes for uploaded files */ public $archives = array(); /** @var string Contains the name of the uploaded file */ public $filename = ''; /** @var string Contains the extension of the uploaded file */ public $extension = ''; /** @var bool Contains the value whether or not the file uses * an extension that is allowed. * * @see $suffixes */ public $valid_extension = false; /** @var bool Filepointer used when opening files */ public $fp = false; /** @var integer Internal line pointer */ public $linepointer = 1; /** @var array Contains the data that is read from file */ public $data = null; /** @var string Path for unpacking files */ protected $_unpackpath = null; /** @var bool Sets to true if a file has been uploaded */ private $_uploaded = false; /** @var bool Sets to true if a file has been closed */ private $_closed = false; /** * Construct the class and its settings * * @copyright * @author RolandD * @todo * @see * @access public * @param * @return * @since 3.0 */ public function __construct() { $jinput = JFactory::getApplication()->input; // Load the necessary libraries jimport('joomla.filesystem.file'); jimport('joomla.filesystem.folder'); jimport('joomla.filesystem.archive'); $this->_unpackpath = CSVIPATH_TMP; $this->_supported_fields = $jinput->get('avfields', array(), null); // Load some basic settings $this->_fileSettings(); } /** * Set up the basic settings * * @copyright * @author RolandD * @todo * @see $suffixes * @see $mimetypes * @see $data * @access private * @param * @return * @since 3.0 */ private function _fileSettings() { $this->suffixes = array('txt','csv','xls','xml','ods'); $this->mimetypes = array('text/html', 'text/plain', 'text/csv', 'application/octet-stream', 'application/x-octet-stream', 'application/vnd.ms-excel', 'application/excel', 'application/ms-excel', 'application/x-excel', 'application/x-msexcel', 'application/force-download', 'text/comma-separated-values', 'text/x-csv', 'text/x-comma-separated-values', 'application/vnd.oasis.opendocument.spreadsheet'); $this->archives = array('zip', 'tgz'); $this->data->sheets[0] = array(); } /** * Process the file to import * * @copyright * @author RolandD * @todo * @see * @access public * @param * @return * @since 3.0 */ abstract public function processFile(); /** * Validate the file * * Validate the file is of the supported type * Types supported are csv, txt, xls, ods, xml * * @copyright * @author RolandD * @todo See if this code can be optimized * @see * @access public * @param * @return bool true if all OK | false if not OK * @since 3.0 */ public function validateFile() { $jinput = JFactory::getApplication()->input; $csvilog = $jinput->get('csvilog', null, null); $template = $jinput->get('template', null, null); // Workaround as it is always true //if ($jinput->get('filepos', 0, 'int') >= 0) { // $csv_file = $template->get('local_csv_file', 'general', false); // if (!$csv_file) { // $csv_file = urldecode($jinput->get('csv_file')); // $jinput->set('local_csv_file', $csv_file); // } // $this->folder = dirname($csv_file); // $jinput->set('csv_file', $csv_file); //} $loadfrom = $template->get('source', 'general'); switch (strtolower($loadfrom)) { // Uploaded file case 'fromupload': $upload['name'] = $_FILES['jform']['name']['general']['import_file']; $upload['type'] = $_FILES['jform']['type']['general']['import_file']; $upload['tmp_name'] = $_FILES['jform']['tmp_name']['general']['import_file']; $upload['error'] = $_FILES['jform']['error']['general']['import_file']; // Check if the file upload has an error if (empty($upload)) { $csvilog->AddStats('incorrect', JText::_('COM_CSVI_NO_UPLOADED_FILE_PROVIDED')); return false; } else if ($upload['error'] == 0) { if (is_uploaded_file($upload['tmp_name'])) { // Get some basic info $folder = $this->_unpackpath.'/'.time(); $upload_parts = pathinfo($upload['name']); // Create the temp folder if (JFolder::create($folder)) { $this->folder = $folder; // Move the uploaded file to its temp location if (JFile::upload($upload['tmp_name'], $folder.'/'.$upload['name'])) { $this->_uploaded = true; // Let's see if the uploaded file is an archive if (in_array($upload_parts['extension'], $this->archives)) { // It is an archive, unpack first if (JArchive::extract($folder.'/'.$upload['name'], $folder)) { // File is unpacked, let's get the filename $foundfiles = scandir($folder); foreach ($foundfiles as $ffkey => $filename) { $ff_parts = pathinfo($filename); if (in_array(strtolower($ff_parts['extension']), $this->suffixes)) { $jinput->set('csv_file', $folder.'/'.$filename); $jinput->set('upload_file_error', false); $this->extension = strtolower($ff_parts["extension"]); end($foundfiles); } else $found = false; } if (!$found) $jinput->set('upload_file_error', true); } else { $csvilog->AddStats('incorrect', JText::_('COM_CSVI_CANNOT_UNPACK_UPLOADED_FILE')); return false; } } // Just a regular file else { $jinput->set('csv_file', $folder.'/'.$upload['name']); $this->extension = strtolower($upload_parts['extension']); } } } else { $csvilog->AddStats('incorrect', JText::sprintf('COM_CSVI_CANNOT_CREATE_UNPACK_FOLDER', $folder)); return false; } } // Error warning cannot save uploaded file else { $csvilog->AddStats('incorrect', JText::sprintf('COM_CSVI_NO_UPLOADED_FILE_PROVIDED', $upload['tmp_name'])); return false; } } else { // There was a problem uploading the file switch($upload['error']) { case '1': $csvilog->AddStats('incorrect', JText::_('COM_CSVI_THE_UPLOADED_FILE_EXCEEDS_THE_MAXIMUM_UPLOADED_FILE_SIZE')); break; case '2': $csvilog->AddStats('incorrect', JText::_('COM_CSVI_THE_UPLOADED_FILE_EXCEEDS_THE_MAXIMUM_UPLOADED_FILE_SIZE')); break; case '3': $csvilog->AddStats('incorrect', JText::_('COM_CSVI_THE_UPLOADED_FILE_WAS_ONLY_PARTIALLY_UPLOADED')); break; case '4': $csvilog->AddStats('incorrect', JText::_('COM_CSVI_NO_FILE_WAS_UPLOADED')); break; case '6': $csvilog->AddStats('incorrect', JText::_('COM_CSVI_MISSING_A_TEMPORARY_FOLDER')); break; case '7': $csvilog->AddStats('incorrect', JText::_('COM_CSVI_FAILED_TO_WRITE_FILE_TO_DISK')); break; case '8': $csvilog->AddStats('incorrect', JText::_('COM_CSVI_FILE_UPLOAD_STOPPED_BY_EXTENSION')); break; default: $csvilog->AddStats('incorrect', JText::_('COM_CSVI_THERE_WAS_A_PROBLEM_UPLOADING_THE_FILE')); break; } return false; } break; // Local file case 'fromserver': $csv_file = JPath::clean($template->get('local_csv_file', 'general'), '/'); // Set the file name to use $jinput->set('csv_file', $csv_file); if (!JFile::exists($csv_file)) { $csvilog->addDebug('[VALIDATEFILE] '.JText::sprintf('COM_CSVI_LOCAL_FILE_DOESNT_EXIST', $csv_file)); $csvilog->AddStats('incorrect', JText::sprintf('COM_CSVI_LOCAL_FILE_DOESNT_EXIST', $csv_file)); return false; } else $jinput->set('upload_file_error', false); $fileinfo = pathinfo($csv_file); if (isset($fileinfo["extension"])) { $this->extension = strtolower($fileinfo["extension"]); if ($this->extension == 'txt') $this->extension = 'csv'; } break; case 'fromurl': // The temporary folder $folder = $this->_unpackpath.'/'.time(); $urlfile = $template->get('urlfile', 'general', false); $tempfile = basename($urlfile); // Check if the remote file exists if ($urlfile) { if (CsviHelper::fileExistsRemote($urlfile)) { // Copy the remote file to a local location if (JFolder::create($folder)) { if (touch($folder.'/'.$tempfile)) { if (JFile::write($folder.'/'.$tempfile, JFile::read($urlfile))) { $csvilog->addDebug(JText::sprintf('COM_CSVI_RETRIEVE_FROM_URL', $urlfile)); $jinput->set('csv_file', $folder.'/'.$tempfile); $jinput->set('upload_file_error', false); $this->extension = JFile::getExt($tempfile); } else { $csvilog->AddStats('incorrect', JText::_('COM_CSVI_CANNOT_READ_FROM_URL')); return false; } } else { $csvilog->AddStats('incorrect', JText::sprintf('COM_CSVI_CANNOT_CREATE_TEMP_FILE', $folder.'/'.$tempfile)); return false; } } else { $csvilog->AddStats('incorrect', JText::sprintf('COM_CSVI_CANNOT_CREATE_TEMP_FOLDER', $folder)); return false; } } else { $csvilog->AddStats('incorrect', JText::_('COM_CSVI_CANNOT_READ_FROM_URL')); return false; } } else { $csvilog->AddStats('incorrect', JText::_('COM_CSVI_NO_FILENAME_GIVEN')); return false; } break; case 'fromftp': // The temporary folder $folder = $this->_unpackpath.'/'.time(); $ftpfile = $template->get('ftpfile', 'general', false); if ($ftpfile) { // Create the output file if (JFolder::create($folder)) { if (touch($folder.'/'.$ftpfile)) { // Start the FTP jimport('joomla.client.ftp'); $ftp = JFTP::getInstance($template->get('ftphost', 'general'), $template->get('ftpport', 'general'), null, $template->get('ftpusername', 'general'), $template->get('ftppass', 'general')); if ($ftp->get($folder.'/'.$ftpfile, $template->get('ftproot', 'general', '/').$ftpfile)) { $csvilog->addDebug(JText::sprintf('COM_CSVI_RETRIEVE_FROM_FTP', $template->get('ftproot', 'general', '/').$ftpfile)); $jinput->set('csv_file', $folder.'/'.$ftpfile); $jinput->set('upload_file_error', false); $this->extension = JFile::getExt($ftpfile); } else { $csvilog->AddStats('incorrect', JText::_('COM_CSVI_CANNOT_READ_FROM_FTP')); return false; } $ftp->quit(); } else { $csvilog->AddStats('incorrect', JText::sprintf('COM_CSVI_CANNOT_CREATE_TEMP_FILE', $folder.'/'.$ftpfile)); return false; } } else { $csvilog->AddStats('incorrect', JText::sprintf('COM_CSVI_CANNOT_CREATE_TEMP_FOLDER', $folder)); return false; } } else { $csvilog->AddStats('incorrect', JText::_('COM_CSVI_NO_FILENAME_GIVEN')); return false; } break; // No file given default: $csvilog->AddStats('incorrect', JText::_('COM_CSVI_NO_FILE_PROVIDED')); return false; break; } // Make sure txt files are not ignored if ($this->extension == 'txt') $this->extension = 'csv'; // Set the filename $csv_file = $jinput->get('csv_file', '', 'string'); if (JFile::exists($csv_file)) { $this->filename = JPath::clean($csv_file, '/'); // Store the users filename for display purposes $csvilog->setFilename(basename($this->filename)); } else { $csvilog->addDebug(JText::sprintf('COM_CSVI_LOCAL_FILE_DOESNT_EXIST', $jinput->get('csv_file'))); return false; } if (in_array($this->extension, $this->suffixes)) $this->valid_extension = true; else { // Test the mime type if (!in_array($this->extension, $this->mimetypes) ) { $csvilog->AddStats('information', JText::sprintf('COM_CSVI_EXTENSION_NOT_ACCEPTED', $this->extension)); return false; } } // Debug message to know what filetype the user is uploading $csvilog->addDebug(JText::sprintf('COM_CSVI_IMPORT_FILETYPE', $this->extension)); // All is fine return true; } /** * Read the next line in the file * * @copyright * @author RolandD * @todo * @see * @access public * @param * @return array with the line of data read | false if data cannot be read * @since 3.0 */ abstract public function ReadNextLine(); /** * Close the file * * @copyright * @author RolandD * @todo * @see processFile() * @access * @param * @return * @since */ public function closeFile($removefolder=true) { // Delete the uploaded folder if ($removefolder) $this->removeFolder(); } /** * Remove the temporary folder * * @copyright * @author RolandD * @todo * @see * @access protected * @param * @return * @since 3.0 */ protected function removeFolder() { $jinput = JFactory::getApplication()->input; if (!$jinput->get('cron', false, 'bool')) { $folder = JPath::clean(dirname($this->filename), '/'); $pos = strpos($folder, CSVIPATH_TMP); if ($pos !== false) if (JFolder::exists($folder)) JFolder::delete($folder); } } /** * Get the file position * * @copyright * @author RolandD * @todo * @see * @access public * @param * @return int current position in the file * @since 3.0 */ abstract public function getFilePos(); /** * Set the current position in the file * * @copyright * @author RolandD * @todo * @see * @access public * @param int $pos the position to move to * @return * @since 3.0 */ abstract public function setFilePos($pos); /** * Get the size of the file * * @copyright * @author RolandD * @todo * @see * @access public * @param * @return int the size of the file being read * @since 3.0 */ public function getFileSize() { return filesize($this->filename); } /** * Load the column headers from a file * * @copyright * @author RolandD * @todo * @see * @access public * @param * @return bool true * @since 3.0 */ abstract public function loadColumnHeaders(); /** * Advances the file pointer 1 forward * * @copyright * @author RolandD * @todo * @see * @access public * @param bool $preview True if called from the preview * @return * @since 3.0 */ public function next($preview=false) { $discard = $this->readNextLine(); } /** * Sets the file pointer back to the beginning of the file * * @copyright * @author RolandD * @todo * @see * @access public * @param * @return * @since 3.0 */ abstract function rewind(); /** * Empties the data * * @copyright * @author RolandD * @todo * @see * @access public * @param * @return bool true * @since 3.0 */ public function clearData() { $this->data = null; return true; } } ?>