Files
@ c7d7e38b2269
Branch filter:
Location: hot67beta/administrator/components/com_media/controllers/file.php
c7d7e38b2269
5.3 KiB
text/x-php
Initial import of the site.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 | <?php
/**
* @version $Id: file.php 10381 2008-06-01 03:35:53Z pasamio $
* @package Joomla
* @subpackage Content
* @copyright Copyright (C) 2005 - 2008 Open Source Matters. All rights reserved.
* @license GNU/GPL, see LICENSE.php
* Joomla! is free software. This version may have been modified pursuant to the
* GNU General Public License, and as distributed it includes or is derivative
* of works licensed under the GNU General Public License or other free or open
* source software licenses. See COPYRIGHT.php for copyright notices and
* details.
*/
// Check to ensure this file is included in Joomla!
defined('_JEXEC') or die( 'Restricted access' );
jimport('joomla.filesystem.file');
jimport('joomla.filesystem.folder');
/**
* Weblinks Weblink Controller
*
* @package Joomla
* @subpackage Weblinks
* @since 1.5
*/
class MediaControllerFile extends MediaController
{
/**
* Upload a file
*
* @since 1.5
*/
function upload()
{
global $mainframe;
// Check for request forgeries
JRequest::checkToken( 'request' ) or jexit( 'Invalid Token' );
$file = JRequest::getVar( 'Filedata', '', 'files', 'array' );
$folder = JRequest::getVar( 'folder', '', '', 'path' );
$format = JRequest::getVar( 'format', 'html', '', 'cmd');
$return = JRequest::getVar( 'return-url', null, 'post', 'base64' );
$err = null;
// Set FTP credentials, if given
jimport('joomla.client.helper');
JClientHelper::setCredentialsFromRequest('ftp');
// Make the filename safe
jimport('joomla.filesystem.file');
$file['name'] = JFile::makeSafe($file['name']);
if (isset($file['name'])) {
$filepath = JPath::clean(COM_MEDIA_BASE.DS.$folder.DS.strtolower($file['name']));
if (!MediaHelper::canUpload( $file, $err )) {
if ($format == 'json') {
jimport('joomla.error.log');
$log = &JLog::getInstance('upload.error.php');
$log->addEntry(array('comment' => 'Invalid: '.$filepath.': '.$err));
header('HTTP/1.0 415 Unsupported Media Type');
jexit('Error. Unsupported Media Type!');
} else {
JError::raiseNotice(100, JText::_($err));
// REDIRECT
if ($return) {
$mainframe->redirect(base64_decode($return).'&folder='.$folder);
}
return;
}
}
if (JFile::exists($filepath)) {
if ($format == 'json') {
jimport('joomla.error.log');
$log = &JLog::getInstance('upload.error.php');
$log->addEntry(array('comment' => 'File already exists: '.$filepath));
header('HTTP/1.0 409 Conflict');
jexit('Error. File already exists');
} else {
JError::raiseNotice(100, JText::_('Error. File already exists'));
// REDIRECT
if ($return) {
$mainframe->redirect(base64_decode($return).'&folder='.$folder);
}
return;
}
}
if (!JFile::upload($file['tmp_name'], $filepath)) {
if ($format == 'json') {
jimport('joomla.error.log');
$log = &JLog::getInstance('upload.error.php');
$log->addEntry(array('comment' => 'Cannot upload: '.$filepath));
header('HTTP/1.0 400 Bad Request');
jexit('Error. Unable to upload file');
} else {
JError::raiseWarning(100, JText::_('Error. Unable to upload file'));
// REDIRECT
if ($return) {
$mainframe->redirect(base64_decode($return).'&folder='.$folder);
}
return;
}
} else {
if ($format == 'json') {
jimport('joomla.error.log');
$log = &JLog::getInstance();
$log->addEntry(array('comment' => $folder));
jexit('Upload complete');
} else {
$mainframe->enqueueMessage(JText::_('Upload complete'));
// REDIRECT
if ($return) {
$mainframe->redirect(base64_decode($return).'&folder='.$folder);
}
return;
}
}
} else {
$mainframe->redirect('index.php', 'Invalid Request', 'error');
}
}
/**
* Deletes paths from the current path
*
* @param string $listFolder The image directory to delete a file from
* @since 1.5
*/
function delete()
{
global $mainframe;
// Set FTP credentials, if given
jimport('joomla.client.helper');
JClientHelper::setCredentialsFromRequest('ftp');
// Get some data from the request
$tmpl = JRequest::getCmd( 'tmpl' );
$paths = JRequest::getVar( 'rm', array(), '', 'array' );
$folder = JRequest::getVar( 'folder', '', '', 'path');
// Initialize variables
$msg = array();
$ret = true;
if (count($paths)) {
foreach ($paths as $path)
{
if ($path !== JFile::makeSafe($path)) {
JError::raiseWarning(100, JText::_('Unable to delete:').htmlspecialchars($path, ENT_COMPAT, 'UTF-8').' '.JText::_('WARNFILENAME'));
continue;
}
$fullPath = JPath::clean(COM_MEDIA_BASE.DS.$folder.DS.$path);
if (is_file($fullPath)) {
$ret |= !JFile::delete($fullPath);
} else if (is_dir($fullPath)) {
$files = JFolder::files($fullPath, '.', true);
$canDelete = true;
foreach ($files as $file) {
if ($file != 'index.html') {
$canDelete = false;
}
}
if ($canDelete) {
$ret |= !JFolder::delete($fullPath);
} else {
JError::raiseWarning(100, JText::_('Unable to delete:').$fullPath.' '.JText::_('Not Empty!'));
}
}
}
}
if ($tmpl == 'component') {
// We are inside the iframe
$mainframe->redirect('index.php?option=com_media&view=mediaList&folder='.$folder.'&tmpl=component');
} else {
$mainframe->redirect('index.php?option=com_media&folder='.$folder);
}
}
}
|