Source for file folder.php

Documentation is available at folder.php

  1. <?php
  2. /**
  3.  * @package     Joomla.Administrator
  4.  * @subpackage  com_media
  5.  *
  6.  * @copyright   Copyright (C) 2005 - 2013 Open Source Matters, Inc. All rights reserved.
  7.  * @license     GNU General Public License version 2 or later; see LICENSE.txt
  8.  */
  9.  
  10. defined('_JEXEC'or die;
  11.  
  12. jimport('joomla.filesystem.file');
  13. jimport('joomla.filesystem.folder');
  14.  
  15. /**
  16.  * Folder Media Controller
  17.  *
  18.  * @package     Joomla.Administrator
  19.  * @subpackage  com_media
  20.  * @since       1.5
  21.  */
  22. {
  23.     /**
  24.      * Deletes paths from the current path
  25.      *
  26.      * @return  boolean 
  27.      *
  28.      * @since   1.5
  29.      */
  30.     public function delete()
  31.     {
  32.         JSession::checkToken('request'or jexit(JText::_('JINVALID_TOKEN'));
  33.  
  34.         $user    JFactory::getUser();
  35.  
  36.         // Get some data from the request
  37.         $tmpl   $this->input->get('tmpl');
  38.         $paths  $this->input->get('rm'array()'array');
  39.         $folder $this->input->get('folder''''path');
  40.  
  41.         $redirect 'index.php?option=com_media&folder=' $folder;
  42.  
  43.         if ($tmpl == 'component')
  44.         {
  45.             // We are inside the iframe
  46.             $redirect .= '&view=mediaList&tmpl=component';
  47.         }
  48.  
  49.         $this->setRedirect($redirect);
  50.  
  51.         // Just return if there's nothing to do
  52.         if (empty($paths))
  53.         {
  54.             return true;
  55.         }
  56.  
  57.         if (!$user->authorise('core.delete''com_media'))
  58.         {
  59.             // User is not authorised to delete
  60.             JError::raiseWarning(403JText::_('JLIB_APPLICATION_ERROR_DELETE_NOT_PERMITTED'));
  61.  
  62.             return false;
  63.         }
  64.  
  65.         // Set FTP credentials, if given
  66.         JClientHelper::setCredentialsFromRequest('ftp');
  67.  
  68.         $ret true;
  69.  
  70.         JPluginHelper::importPlugin('content');
  71.         $dispatcher    JEventDispatcher::getInstance();
  72.  
  73.         if (count($paths))
  74.         {
  75.             foreach ($paths as $path)
  76.             {
  77.                 if ($path !== JFile::makeSafe($path))
  78.                 {
  79.                     $dirname htmlspecialchars($pathENT_COMPAT'UTF-8');
  80.                     JError::raiseWarning(100JText::sprintf('COM_MEDIA_ERROR_UNABLE_TO_DELETE_FOLDER_WARNDIRNAME'substr($dirnamestrlen(COM_MEDIA_BASE))));
  81.                     continue;
  82.                 }
  83.  
  84.                 $fullPath JPath::clean(implode(DIRECTORY_SEPARATORarray(COM_MEDIA_BASE$folder$path)));
  85.                 $object_file new JObject(array('filepath' => $fullPath));
  86.  
  87.                 if (is_file($object_file->filepath))
  88.                 {
  89.                     // Trigger the onContentBeforeDelete event.
  90.                     $result $dispatcher->trigger('onContentBeforeDelete'array('com_media.file'&$object_file));
  91.  
  92.                     if (in_array(false$resulttrue))
  93.                     {
  94.                         // There are some errors in the plugins
  95.                         JError::raiseWarning(100JText::plural('COM_MEDIA_ERROR_BEFORE_DELETE'count($errors $object_file->getErrors())implode('<br />'$errors)));
  96.                         continue;
  97.                     }
  98.  
  99.                     $ret &= JFile::delete($object_file->filepath);
  100.  
  101.                     // Trigger the onContentAfterDelete event.
  102.                     $dispatcher->trigger('onContentAfterDelete'array('com_media.file'&$object_file));
  103.                     $this->setMessage(JText::sprintf('COM_MEDIA_DELETE_COMPLETE'substr($object_file->filepathstrlen(COM_MEDIA_BASE))));
  104.                 }
  105.                 elseif (is_dir($object_file->filepath))
  106.                 {
  107.                     $contents JFolder::files($object_file->filepath'.'truefalsearray('.svn''CVS''.DS_Store''__MACOSX''index.html'));
  108.  
  109.                     if (empty($contents))
  110.                     {
  111.                         // Trigger the onContentBeforeDelete event.
  112.                         $result $dispatcher->trigger('onContentBeforeDelete'array('com_media.folder'&$object_file));
  113.  
  114.                         if (in_array(false$resulttrue))
  115.                         {
  116.                             // There are some errors in the plugins
  117.                             JError::raiseWarning(100JText::plural('COM_MEDIA_ERROR_BEFORE_DELETE'count($errors $object_file->getErrors())implode('<br />'$errors)));
  118.                             continue;
  119.                         }
  120.  
  121.                         $ret &= !JFolder::delete($object_file->filepath);
  122.  
  123.                         // Trigger the onContentAfterDelete event.
  124.                         $dispatcher->trigger('onContentAfterDelete'array('com_media.folder'&$object_file));
  125.                         $this->setMessage(JText::sprintf('COM_MEDIA_DELETE_COMPLETE'substr($object_file->filepathstrlen(COM_MEDIA_BASE))));
  126.                     }
  127.                     else
  128.                     {
  129.                         // This makes no sense...
  130.                         JError::raiseWarning(100JText::sprintf('COM_MEDIA_ERROR_UNABLE_TO_DELETE_FOLDER_NOT_EMPTY'substr($object_file->filepathstrlen(COM_MEDIA_BASE))));
  131.                     }
  132.                 }
  133.             }
  134.         }
  135.  
  136.         return $ret;
  137.     }
  138.  
  139.     /**
  140.      * Create a folder
  141.      *
  142.      * @return  boolean 
  143.      *
  144.      * @since   1.5
  145.      */
  146.     public function create()
  147.     {
  148.         // Check for request forgeries
  149.         JSession::checkToken(or jexit(JText::_('JINVALID_TOKEN'));
  150.  
  151.         $user  JFactory::getUser();
  152.  
  153.         $folder      $this->input->get('foldername''');
  154.         $folderCheck = (string) $this->input->get('foldername'null'raw');
  155.         $parent      $this->input->get('folderbase''''path');
  156.  
  157.         $this->setRedirect('index.php?option=com_media&folder=' $parent '&tmpl=' $this->input->get('tmpl''index'));
  158.  
  159.         if (strlen($folder0)
  160.         {
  161.             if (!$user->authorise('core.create''com_media'))
  162.             {
  163.                 // User is not authorised to create
  164.                 JError::raiseWarning(403JText::_('JLIB_APPLICATION_ERROR_CREATE_NOT_PERMITTED'));
  165.  
  166.                 return false;
  167.             }
  168.  
  169.             // Set FTP credentials, if given
  170.             JClientHelper::setCredentialsFromRequest('ftp');
  171.  
  172.             $this->input->set('folder'$parent);
  173.  
  174.             if (($folderCheck !== null&& ($folder !== $folderCheck))
  175.             {
  176.                 $this->setMessage(JText::_('COM_MEDIA_ERROR_UNABLE_TO_CREATE_FOLDER_WARNDIRNAME'));
  177.  
  178.                 return false;
  179.             }
  180.  
  181.             $path JPath::clean(COM_MEDIA_BASE '/' $parent '/' $folder);
  182.  
  183.             if (!is_dir($path&& !is_file($path))
  184.             {
  185.                 // Trigger the onContentBeforeSave event.
  186.                 $object_file new JObject(array('filepath' => $path));
  187.                 JPluginHelper::importPlugin('content');
  188.                 $dispatcher    JEventDispatcher::getInstance();
  189.                 $result $dispatcher->trigger('onContentBeforeSave'array('com_media.folder'&$object_filetrue));
  190.  
  191.                 if (in_array(false$resulttrue))
  192.                 {
  193.                     // There are some errors in the plugins
  194.                     JError::raiseWarning(100JText::plural('COM_MEDIA_ERROR_BEFORE_SAVE'count($errors $object_file->getErrors())implode('<br />'$errors)));
  195.  
  196.                     return false;
  197.                 }
  198.  
  199.                 if (JFolder::create($object_file->filepath))
  200.                 {
  201.                     $data "<html>\n<body bgcolor=\"#FFFFFF\">\n</body>\n</html>";
  202.                     JFile::write($object_file->filepath "/index.html"$data);
  203.  
  204.                     // Trigger the onContentAfterSave event.
  205.                     $dispatcher->trigger('onContentAfterSave'array('com_media.folder'&$object_filetrue));
  206.                     $this->setMessage(JText::sprintf('COM_MEDIA_CREATE_COMPLETE'substr($object_file->filepathstrlen(COM_MEDIA_BASE))));
  207.                 }
  208.             }
  209.  
  210.             $this->input->set('folder'($parent$parent '/' $folder $folder);
  211.         }
  212.         else
  213.         {
  214.             // File name is of zero length (null).
  215.             JError::raiseWarning(100JText::_('COM_MEDIA_ERROR_UNABLE_TO_CREATE_FOLDER_WARNDIRNAME'));
  216.  
  217.             return false;
  218.         }
  219.  
  220.         return true;
  221.     }
  222. }

Documentation generated on Tue, 19 Nov 2013 15:03:28 +0100 by phpDocumentor 1.4.3