Пример #1
0
 /**
  * Upload a file
  *
  * @since 1.5
  */
 function upload()
 {
     // Initialise variables.
     $mainframe = JFactory::getApplication('administrator');
     // 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(JA_WORKING_DATA_FOLDER . '/' . $folder . '/' . strtolower($file['name']));
         if (!RepoHelper::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');
     }
 }
Пример #2
0
<?php

/**
 * @version		$Id: details_doc.php 17769 2010-06-20 01:50:48Z dextercowley $
 * @package		Joomla.Administrator
 * @subpackage	com_media
 * @copyright	Copyright (C) 2005 - 2010 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;
$RepoHelper = new RepoHelper();
?>

		<tr>
			<td><img src="<?php 
echo $this->_tmp_doc->icon_16;
?>
" width="16" height="16" border="0" alt="<?php 
echo $this->_tmp_doc->name;
?>
" />
			</td>
			<td class="description">
            <?php 
if ($this->_tmp_doc->ext == 'zip') {
    ?>

            <a class="download-item" href="index.php?option=com_jaextmanager&amp;view=file&amp;task=download&amp;tmpl=component&amp;<?php 
    echo JSession::getFormToken();
    ?>
Пример #3
0
echo $this->_tmp_doc->name;
?>
            <?php 
if ($this->_tmp_doc->ext == 'zip') {
    ?>
            </a>
            <?php 
}
?>
			</td>
			<td>&nbsp;

			</td>
			<td>
				<?php 
echo RepoHelper::parseSize($this->_tmp_doc->size);
?>
			</td>
			<td>
				<a class="delete-item" href="index.php?option=<?php 
echo JACOMPONENT;
?>
&amp;view=file&amp;task=delete&amp;tmpl=component&amp;<?php 
echo JUtility::getToken();
?>
=1&amp;folder=<?php 
echo $this->state->folder;
?>
&amp;rm[]=<?php 
echo $this->_tmp_doc->name;
?>
Пример #4
0
 /**
  * Build imagelist
  *
  * @param string $listFolder The image directory to display
  * @since 1.5
  */
 function getList()
 {
     static $list;
     $RepoHelper = new RepoHelper();
     // Only process the list once per request
     if (is_array($list)) {
         return $list;
     }
     // Get current path from request
     $current = $this->getState('folder');
     // If undefined, set to empty
     if ($current == 'undefined') {
         $current = '';
     }
     // Initialize variables
     if (strlen($current) > 0) {
         $basePath = JA_WORKING_DATA_FOLDER . '/' . $current;
     } else {
         $basePath = JA_WORKING_DATA_FOLDER;
     }
     $basePath = JPath::clean($basePath . '/');
     $mediaBase = str_replace(DS, '/', JA_WORKING_DATA_FOLDER);
     $images = array();
     $folders = array();
     $docs = array();
     if (JFolder::exists($basePath)) {
         // Get the list of files and folders from the given folder
         $fileList = JFolder::files($basePath);
         $folderList = JFolder::folders($basePath);
         $iconPath = JPATH_ADMINISTRATOR . "/components/com_jaextmanager/assets/images/icons/";
         // Iterate over the files if they exist
         if ($fileList !== false) {
             foreach ($fileList as $file) {
                 if (JFile::exists($basePath . '/' . $file) && substr($file, 0, 1) != '.' && strtolower($file) !== 'index.html') {
                     $tmp = new JObject();
                     $tmp->name = $file;
                     $tmp->path = str_replace(DS, '/', JPath::clean($basePath . '/' . $file));
                     $tmp->path_relative = str_replace($mediaBase, '', $tmp->path);
                     $tmp->size = filesize($tmp->path);
                     $ext = strtolower(JFile::getExt($file));
                     $tmp->ext = $ext;
                     switch ($ext) {
                         // Image
                         case 'jpg':
                         case 'png':
                         case 'gif':
                         case 'xcf':
                         case 'odg':
                         case 'bmp':
                         case 'jpeg':
                             $info = @getimagesize($tmp->path);
                             $tmp->width = @$info[0];
                             $tmp->height = @$info[1];
                             $tmp->type = @$info[2];
                             $tmp->mime = @$info['mime'];
                             $filesize = $RepoHelper->parseSize($tmp->size);
                             if ($info[0] > 60 || $info[1] > 60) {
                                 $dimensions = $RepoHelper->imageResize($info[0], $info[1], 60);
                                 $tmp->width_60 = $dimensions[0];
                                 $tmp->height_60 = $dimensions[1];
                             } else {
                                 $tmp->width_60 = $tmp->width;
                                 $tmp->height_60 = $tmp->height;
                             }
                             if ($info[0] > 16 || $info[1] > 16) {
                                 $dimensions = $RepoHelper->imageResize($info[0], $info[1], 16);
                                 $tmp->width_16 = $dimensions[0];
                                 $tmp->height_16 = $dimensions[1];
                             } else {
                                 $tmp->width_16 = $tmp->width;
                                 $tmp->height_16 = $tmp->height;
                             }
                             $iconfile_32 = $iconPath . "mime-icon-32/" . $ext . ".png";
                             if (file_exists($iconfile_32)) {
                                 $tmp->icon_32 = "components/com_jaextmanager/assets/images/icons/mime-icon-32/" . $ext . ".png";
                             } else {
                                 $tmp->icon_32 = "components/com_jaextmanager/assets/images/icons/con_info.png";
                             }
                             $iconfile_16 = $iconPath . "mime-icon-16/" . $ext . ".png";
                             if (file_exists($iconfile_16)) {
                                 $tmp->icon_16 = "components/com_jaextmanager/assets/images/icons/mime-icon-16/" . $ext . ".png";
                             } else {
                                 $tmp->icon_16 = "components/com_jaextmanager/assets/images/icons/con_info.png";
                             }
                             $images[] = $tmp;
                             break;
                             // Non-image document
                         // Non-image document
                         default:
                             $iconfile_32 = $iconPath . "mime-icon-32/" . $ext . ".png";
                             if (file_exists($iconfile_32)) {
                                 $tmp->icon_32 = "components/com_jaextmanager/assets/images/icons/mime-icon-32/" . $ext . ".png";
                             } else {
                                 $tmp->icon_32 = "components/com_jaextmanager/assets/images/icons/con_info.png";
                             }
                             $iconfile_16 = $iconPath . "/mime-icon-16/" . $ext . ".png";
                             if (file_exists($iconfile_16)) {
                                 $tmp->icon_16 = "components/com_jaextmanager/assets/images/icons/mime-icon-16/" . $ext . ".png";
                             } else {
                                 $tmp->icon_16 = "components/com_jaextmanager/assets/images/icons/con_info.png";
                             }
                             $docs[] = $tmp;
                             break;
                     }
                 }
             }
         }
         // Iterate over the folders if they exist
         if ($folderList !== false) {
             foreach ($folderList as $folder) {
                 $tmp = new JObject();
                 $tmp->name = basename($folder);
                 $tmp->path = str_replace(DS, '/', JPath::clean($basePath . '/' . $folder));
                 $tmp->path_relative = str_replace($mediaBase, '', $tmp->path);
                 $count = $RepoHelper->countFiles($tmp->path);
                 $tmp->files = $count[0];
                 $tmp->folders = $count[1];
                 $folders[] = $tmp;
             }
         }
     } else {
         JError::raiseWarning(100, JText::_("PATH_IS_NOT_A_FOLDER_OR_THIS_FOLDER_WAS_DELETED"));
     }
     $list = array('folders' => $folders, 'docs' => $docs, 'images' => $images);
     return $list;
 }