[ Index ]

PHP Cross Reference of Joomla 1.5.26 DE

title

Body

[close]

/administrator/components/com_media/controllers/ -> file.php (source)

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


Generated: Wed Mar 28 15:54:07 2012 Cross-referenced by PHPXref 0.7.1