- md5
- 474ac6667782b1c12e14fe83b546b625
- sha1
- a455bf5f77e871c9fcc5eb840c134c7d3eed6c71
- sha256
- 49f8557e67fc77dff2b850396747794eea22b9fecc910cb052c0b618c8a2d4ae
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214
<?php
/**
* @version $Id: file.php 21518 2011-06-10 21:38:12Z chdemko $
* @copyright Copyright (C) 2005 - 2011 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 JController
{
/**
* Upload a file
*
* @since 1.5
*/
function upload()
{
// Check for request forgeries
JRequest::checkToken('request') or jexit(JText::_('JINVALID_TOKEN'));
// Get the user
$user = JFactory::getUser();
// Get some data from the request
$file = JRequest::getVar('Filedata', '', 'files', 'array');
$folder = JRequest::getVar('folder', '', '', 'path');
$return = JRequest::getVar('return-url', null, 'post', 'base64');
// Set FTP credentials, if given
jimport('joomla.client.helper');
JClientHelper::setCredentialsFromRequest('ftp');
// Set the redirect
if ($return) {
$this->setRedirect(base64_decode($return).'&folder='.$folder);
}
// Make the filename safe
$file['name'] = JFile::makeSafe($file['name']);
if (isset($file['name']))
{
// The request is valid
$err = null;
if (!MediaHelper::canUpload($file, $err))
{
// The file can't be upload
JError::raiseNotice(100, JText::_($err));
return false;
}
$filepath = JPath::clean(COM_MEDIA_BASE . '/' . $folder . '/' . strtolower($file['name']));
// Trigger the onContentBeforeSave event.
JPluginHelper::importPlugin('content');
$dispatcher = JDispatcher::getInstance();
$object_file = new JObject($file);
$object_file->filepath = $filepath;
$result = $dispatcher->trigger('onContentBeforeSave', 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_SAVE', count($errors = $object_file->getErrors()), implode('<br />', $errors)));
return false;
}
$file = (array) $object_file;
if (JFile::exists($file['filepath']))
{
// File exists
JError::raiseWarning(100, JText::_('COM_MEDIA_ERROR_FILE_EXISTS'));
return false;
}
elseif (!$user->authorise('core.create', 'com_media'))
{
// File does not exist and user is not authorised to create
JError::raiseWarning(403, JText::_('COM_MEDIA_ERROR_CREATE_NOT_PERMITTED'));
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;
}
}
else
{
$this->setRedirect('index.php', JText::_('COM_MEDIA_INVALID_REQUEST'), 'error');
return false;
}
}
/**
* Deletes paths from the current path
*
* @param string $listFolder The image directory to delete a file from
* @since 1.5
*/
function delete()
{
JRequest::checkToken('request') or jexit(JText::_('JINVALID_TOKEN'));
$app = JFactory::getApplication();
$user = JFactory::getUser();
// Get some data from the request
$tmpl = JRequest::getCmd('tmpl');
$paths = JRequest::getVar('rm', array(), '', 'array');
$folder = JRequest::getVar('folder', '', '', 'path');
if ($tmpl == 'component') {
// We are inside the iframe
$this->setRedirect('index.php?option=com_media&view=mediaList&folder='.$folder.'&tmpl=component');
} else {
$this->setRedirect('index.php?option=com_media&folder='.$folder);
}
if (!$user->authorise('core.delete','com_media'))
{
// User is not authorised to delete
JError::raiseWarning(403, JText::_('JLIB_APPLICATION_ERROR_DELETE_NOT_PERMITTED'));
return false;
}
else
{
// Set FTP credentials, if given
jimport('joomla.client.helper');
JClientHelper::setCredentialsFromRequest('ftp');
// Initialise variables.
$ret = true;
if (count($paths))
{
JPluginHelper::importPlugin('content');
$dispatcher = JDispatcher::getInstance();
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(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))));
}
else if (is_dir($fullPath))
{
if (count(JFolder::files($fullPath, '.', true, false, array('.svn', 'CVS','.DS_Store','__MACOSX'), array('index.html', '^\..*','.*~'))) == 0)
{
// 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;
}
}
}
The same content is in 3 releases, Joomla 1.7.0 to 1.7.2. See them all, or every version of this file.