Source for file template.php

Documentation is available at template.php

  1. <?php
  2. /**
  3.  * @package     Joomla.Administrator
  4.  * @subpackage  com_templates
  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. JLoader::register('InstallerModelInstall'JPATH_ADMINISTRATOR '/components/com_installer/models/install.php');
  13.  
  14. /**
  15.  * Template style controller class.
  16.  *
  17.  * @package     Joomla.Administrator
  18.  * @subpackage  com_templates
  19.  * @since       1.6
  20.  */
  21. {
  22.     /**
  23.      * Constructor.
  24.      *
  25.      * @param   array  $config  An optional associative array of configuration settings.
  26.      *
  27.      * @see     JControllerLegacy
  28.      * @since   3.2
  29.      */
  30.     public function __construct($config array())
  31.     {
  32.         parent::__construct($config);
  33.  
  34.         // Apply, Save & New, and Save As copy should be standard on forms.
  35.         $this->registerTask('apply''save');
  36.     }
  37.  
  38.     /**
  39.      * Method for closing the template.
  40.      *
  41.      * @return  void. 
  42.      *
  43.      * @since   3.2
  44.      */
  45.     public function cancel()
  46.     {
  47.         $this->setRedirect(JRoute::_('index.php?option=com_templates&view=templates'false));
  48.     }
  49.  
  50.     /**
  51.      * Method for closing a file.
  52.      *
  53.      * @return  void. 
  54.      *
  55.      * @since   3.2
  56.      */
  57.     public function close()
  58.     {
  59.         $app  JFactory::getApplication();
  60.         $file base64_encode('home');
  61.         $id   $app->input->get('id');
  62.         $url  'index.php?option=com_templates&view=template&id=' $id '&file=' $file;
  63.         $this->setRedirect(JRoute::_($urlfalse));
  64.     }
  65.  
  66.     /**
  67.      * Method for copying the template.
  68.      *
  69.      * @return  boolean     true on success, false otherwise
  70.      *
  71.      * @since   3.2
  72.      */
  73.     public function copy()
  74.     {
  75.         // Check for request forgeries
  76.         JSession::checkToken(or jexit(JText::_('JINVALID_TOKEN'));
  77.  
  78.         $app JFactory::getApplication();
  79.         $this->input->set('installtype''folder');
  80.         $newName    $this->input->get('new_name');
  81.         $newNameRaw $this->input->get('new_name'null'string');
  82.         $templateID $this->input->getInt('id'0);
  83.         $file       $this->input->get('file');
  84.  
  85.         $this->setRedirect('index.php?option=com_templates&view=template&id=' $templateID '&file=' $file);
  86.         $model $this->getModel('Template''TemplatesModel');
  87.         $model->setState('new_name'$newName);
  88.         $model->setState('tmp_prefix'uniqid('template_copy_'));
  89.         $model->setState('to_path'JFactory::getConfig()->get('tmp_path''/' $model->getState('tmp_prefix'));
  90.  
  91.         // Process only if we have a new name entered
  92.         if (strlen($newName0)
  93.         {
  94.             if (!JFactory::getUser()->authorise('core.create''com_templates'))
  95.             {
  96.                 // User is not authorised to delete
  97.                 $app->enqueueMessage(JText::_('COM_TEMPLATES_ERROR_CREATE_NOT_PERMITTED')'error');
  98.  
  99.                 return false;
  100.             }
  101.  
  102.             // Set FTP credentials, if given
  103.             JClientHelper::setCredentialsFromRequest('ftp');
  104.  
  105.             // Check that new name is valid
  106.             if (($newNameRaw !== null&& ($newName !== $newNameRaw))
  107.             {
  108.                 $app->enqueueMessage(JText::_('COM_TEMPLATES_ERROR_INVALID_TEMPLATE_NAME')'error');
  109.  
  110.                 return false;
  111.             }
  112.  
  113.             // Check that new name doesn't already exist
  114.             if (!$model->checkNewName())
  115.             {
  116.                 $app->enqueueMessage(JText::_('COM_TEMPLATES_ERROR_DUPLICATE_TEMPLATE_NAME')'error');
  117.  
  118.                 return false;
  119.             }
  120.  
  121.             // Check that from name does exist and get the folder name
  122.             $fromName $model->getFromName();
  123.  
  124.             if (!$fromName)
  125.             {
  126.                 $app->enqueueMessage(JText::_('COM_TEMPLATES_ERROR_INVALID_FROM_NAME')'error');
  127.  
  128.                 return false;
  129.             }
  130.  
  131.             // Call model's copy method
  132.             if (!$model->copy())
  133.             {
  134.                 $app->enqueueMessage(JText::_('COM_TEMPLATES_ERROR_COULD_NOT_COPY')'error');
  135.  
  136.                 return false;
  137.             }
  138.  
  139.             // Call installation model
  140.             $this->input->set('install_directory'JFactory::getConfig()->get('tmp_path''/' $model->getState('tmp_prefix'));
  141.             $installModel $this->getModel('Install''InstallerModel');
  142.             JFactory::getLanguage()->load('com_installer');
  143.  
  144.             if (!$installModel->install())
  145.             {
  146.                 $app->enqueueMessage(JText::_('COM_TEMPLATES_ERROR_COULD_NOT_INSTALL')'error');
  147.  
  148.                 return false;
  149.             }
  150.  
  151.             $this->setMessage(JText::sprintf('COM_TEMPLATES_COPY_SUCCESS'$newName));
  152.             $model->cleanup();
  153.  
  154.             return true;
  155.         }
  156.     }
  157.  
  158.     /**
  159.      * Method to get a model object, loading it if required.
  160.      *
  161.      * @param   string  $name    The model name. Optional.
  162.      * @param   string  $prefix  The class prefix. Optional.
  163.      * @param   array   $config  Configuration array for model. Optional (note, the empty array is atypical compared to other models).
  164.      *
  165.      * @return  JModelLegacy  The model.
  166.      *
  167.      * @since   3.2
  168.      */
  169.     public function getModel($name 'Template'$prefix 'TemplatesModel'$config array())
  170.     {
  171.         $model parent::getModel($name$prefix$config);
  172.  
  173.         return $model;
  174.     }
  175.  
  176.     /**
  177.      * Method to check if you can add a new record.
  178.      *
  179.      * @return  boolean 
  180.      *
  181.      * @since   3.2
  182.      */
  183.     protected function allowEdit()
  184.     {
  185.         return JFactory::getUser()->authorise('core.edit''com_templates');
  186.     }
  187.  
  188.     /**
  189.      * Method to check if you can save a new or existing record.
  190.      *
  191.      * @return  boolean 
  192.      *
  193.      * @since   3.2
  194.      */
  195.     protected function allowSave()
  196.     {
  197.         return $this->allowEdit();
  198.     }
  199.  
  200.     /**
  201.      * Saves a template source file.
  202.      *
  203.      * @return  void 
  204.      *
  205.      * @since   3.2
  206.      */
  207.     public function save()
  208.     {
  209.         // Check for request forgeries.
  210.         JSession::checkToken(or jexit(JText::_('JINVALID_TOKEN'));
  211.  
  212.         $app          JFactory::getApplication();
  213.         $data         $this->input->post->get('jform'array()'array');
  214.         $task         $this->getTask();
  215.         $model        $this->getModel();
  216.         $fileName     $app->input->get('file');
  217.         $explodeArray explode(':'base64_decode($fileName));
  218.  
  219.         // Access check.
  220.         if (!$this->allowSave())
  221.         {
  222.             $app->enqueueMessage(JText::_('JERROR_SAVE_NOT_PERMITTED')'error');
  223.  
  224.             return false;
  225.         }
  226.  
  227.         // Match the stored id's with the submitted.
  228.         if (empty($data['extension_id']|| empty($data['filename']))
  229.         {
  230.             $app->enqueueMessage(JText::_('COM_TEMPLATES_ERROR_SOURCE_ID_FILENAME_MISMATCH')'error');
  231.  
  232.             return false;
  233.         }
  234.         elseif ($data['extension_id'!= $model->getState('extension.id'))
  235.         {
  236.             $app->enqueueMessage(JText::_('COM_TEMPLATES_ERROR_SOURCE_ID_FILENAME_MISMATCH')'error');
  237.  
  238.             return false;
  239.         }
  240.         elseif ($data['filename'!= end($explodeArray))
  241.         {
  242.             $app->enqueueMessage(JText::_('COM_TEMPLATES_ERROR_SOURCE_ID_FILENAME_MISMATCH')'error');
  243.  
  244.             return false;
  245.         }
  246.  
  247.         // Validate the posted data.
  248.         $form $model->getForm();
  249.  
  250.         if (!$form)
  251.         {
  252.             $app->enqueueMessage($model->getError()'error');
  253.  
  254.             return false;
  255.         }
  256.  
  257.         $data $model->validate($form$data);
  258.  
  259.         // Check for validation errors.
  260.         if ($data === false)
  261.         {
  262.             // Get the validation messages.
  263.             $errors    $model->getErrors();
  264.  
  265.             // Push up to three validation messages out to the user.
  266.             for ($i 0$n count($errors)$i $n && $i 3$i++)
  267.             {
  268.                 if ($errors[$iinstanceof Exception)
  269.                 {
  270.                     $app->enqueueMessage($errors[$i]->getMessage()'warning');
  271.                 }
  272.                 else
  273.                 {
  274.                     $app->enqueueMessage($errors[$i]'warning');
  275.                 }
  276.             }
  277.  
  278.             // Redirect back to the edit screen.
  279.             $url 'index.php?option=com_templates&view=template&id=' $model->getState('extension.id''&file=' $fileName;
  280.             $this->setRedirect(JRoute::_($urlfalse));
  281.  
  282.             return false;
  283.         }
  284.  
  285.         // Attempt to save the data.
  286.         if (!$model->save($data))
  287.         {
  288.             // Redirect back to the edit screen.
  289.             $this->setMessage(JText::sprintf('JERROR_SAVE_FAILED'$model->getError())'warning');
  290.             $url 'index.php?option=com_templates&view=template&id=' $model->getState('extension.id''&file=' $fileName;
  291.             $this->setRedirect(JRoute::_($urlfalse));
  292.  
  293.             return false;
  294.         }
  295.  
  296.         $this->setMessage(JText::_('COM_TEMPLATES_FILE_SAVE_SUCCESS'));
  297.  
  298.         // Redirect the user based on the chosen task.
  299.         switch ($task)
  300.         {
  301.         case 'apply':
  302.  
  303.             // Redirect back to the edit screen.
  304.             $url 'index.php?option=com_templates&view=template&id=' $model->getState('extension.id''&file=' $fileName;
  305.             $this->setRedirect(JRoute::_($urlfalse));
  306.             break;
  307.  
  308.         default:
  309.  
  310.             // Redirect to the list screen.
  311.             $this->setRedirect(JRoute::_('index.php?option=com_templates&view=templates'false));
  312.             break;
  313.         }
  314.     }
  315.  
  316.     /**
  317.      * Method for creating override.
  318.      *
  319.      * @return  void 
  320.      *
  321.      * @since   3.2
  322.      */
  323.     public function overrides()
  324.     {
  325.         $app      JFactory::getApplication();
  326.         $model    $this->getModel();
  327.         $file     $app->input->get('file');
  328.         $override base64_decode($app->input->get('folder'));
  329.         $id       $app->input->get('id');
  330.  
  331.         if ($model->createOverride($override))
  332.         {
  333.             $this->setMessage(JText::_('COM_TEMPLATES_OVERRIDE_SUCCESS'));
  334.         }
  335.  
  336.         // Redirect back to the edit screen.
  337.         $url 'index.php?option=com_templates&view=template&id=' $id '&file=' $file;
  338.         $this->setRedirect(JRoute::_($urlfalse));
  339.     }
  340.  
  341.     /**
  342.      * Method for compiling LESS.
  343.      *
  344.      * @return  void 
  345.      *
  346.      * @since   3.2
  347.      */
  348.     public function less()
  349.     {
  350.         $app   JFactory::getApplication();
  351.         $model $this->getModel();
  352.         $id    $app->input->get('id');
  353.         $file  $app->input->get('file');
  354.  
  355.         if ($model->compileLess($file))
  356.         {
  357.             $this->setMessage(JText::_('COM_TEMPLATES_COMPILE_SUCCESS'));
  358.         }
  359.         else
  360.         {
  361.             $app->enqueueMessage(JText::_('COM_TEMPLATES_COMPILE_ERROR')'error');
  362.         }
  363.  
  364.         $url 'index.php?option=com_templates&view=template&id=' $id '&file=' $file;
  365.         $this->setRedirect(JRoute::_($urlfalse));
  366.     }
  367.  
  368.     /**
  369.      * Method for deleting a file.
  370.      *
  371.      * @return  void 
  372.      *
  373.      * @since   3.2
  374.      */
  375.     public function delete()
  376.     {
  377.         $app   JFactory::getApplication();
  378.         $model $this->getModel();
  379.         $id    $app->input->get('id');
  380.         $file  $app->input->get('file');
  381.  
  382.         if (base64_decode(urldecode($file)) == 'index.php')
  383.         {
  384.             $app->enqueueMessage(JText::_('COM_TEMPLATES_ERROR_INDEX_DELETE')'warning');
  385.             $url 'index.php?option=com_templates&view=template&id=' $id '&file=' $file;
  386.             $this->setRedirect(JRoute::_($urlfalse));
  387.         }
  388.  
  389.         elseif ($model->deleteFile($file))
  390.         {
  391.             $this->setMessage(JText::_('COM_TEMPLATES_FILE_DELETE_SUCCESS'));
  392.             $file base64_encode('home');
  393.             $url 'index.php?option=com_templates&view=template&id=' $id '&file=' $file;
  394.             $this->setRedirect(JRoute::_($urlfalse));
  395.         }
  396.         else
  397.         {
  398.             $app->enqueueMessage(JText::_('COM_TEMPLATES_ERROR_FILE_DELETE')'error');
  399.             $url 'index.php?option=com_templates&view=template&id=' $id '&file=' $file;
  400.             $this->setRedirect(JRoute::_($urlfalse));
  401.         }
  402.     }
  403.  
  404.     /**
  405.      * Method for creating a new file.
  406.      *
  407.      * @return  void 
  408.      *
  409.      * @since   3.2
  410.      */
  411.     public function createFile()
  412.     {
  413.         $app      JFactory::getApplication();
  414.         $model    $this->getModel();
  415.         $id       $app->input->get('id');
  416.         $file     $app->input->get('file');
  417.         $name     $app->input->get('name');
  418.         $location base64_decode($app->input->get('address'));
  419.         $type     $app->input->get('type');
  420.  
  421.         if ($type == 'null')
  422.         {
  423.             $app->enqueueMessage(JText::_('COM_TEMPLATES_INVALID_FILE_TYPE')'error');
  424.             $url 'index.php?option=com_templates&view=template&id=' $id '&file=' $file;
  425.             $this->setRedirect(JRoute::_($urlfalse));
  426.         }
  427.         elseif (!preg_match('/^[a-zA-Z0-9-_]+$/'$name))
  428.         {
  429.             $app->enqueueMessage(JText::_('COM_TEMPLATES_INVALID_FILE_NAME')'error');
  430.             $url 'index.php?option=com_templates&view=template&id=' $id '&file=' $file;
  431.             $this->setRedirect(JRoute::_($urlfalse));
  432.         }
  433.         elseif ($model->createFile($name$type$location))
  434.         {
  435.             $this->setMessage(JText::_('COM_TEMPLATES_FILE_CREATE_SUCCESS'));
  436.             $file urlencode(base64_encode($location '/' $name '.' $type));
  437.             $url 'index.php?option=com_templates&view=template&id=' $id '&file=' $file;
  438.             $this->setRedirect(JRoute::_($urlfalse));
  439.         }
  440.         else
  441.         {
  442.             $app->enqueueMessage(JText::_('COM_TEMPLATES_ERROR_FILE_CREATE')'error');
  443.             $url 'index.php?option=com_templates&view=template&id=' $id '&file=' $file;
  444.             $this->setRedirect(JRoute::_($urlfalse));
  445.         }
  446.     }
  447.  
  448.     /**
  449.      * Method for uploading a file.
  450.      *
  451.      * @return  void 
  452.      *
  453.      * @since   3.2
  454.      */
  455.     public function uploadFile()
  456.     {
  457.         $app      JFactory::getApplication();
  458.         $model    $this->getModel();
  459.         $id       $app->input->get('id');
  460.         $file     $app->input->get('file');
  461.         $upload   $app->input->files->get('files');
  462.         $location base64_decode($app->input->get('address'));
  463.  
  464.         if ($return $model->uploadFile($upload$location))
  465.         {
  466.             $app->enqueueMessage(JText::_('COM_TEMPLATES_FILE_UPLOAD_SUCCESS'$upload['name']);
  467.             $redirect base64_encode($return);
  468.             $url 'index.php?option=com_templates&view=template&id=' $id '&file=' $redirect;
  469.             $this->setRedirect(JRoute::_($urlfalse));
  470.         }
  471.         else
  472.         {
  473.             $app->enqueueMessage(JText::_('COM_TEMPLATES_ERROR_FILE_UPLOAD')'error');
  474.             $url 'index.php?option=com_templates&view=template&id=' $id '&file=' $file;
  475.             $this->setRedirect(JRoute::_($urlfalse));
  476.         }
  477.     }
  478.  
  479.     /**
  480.      * Method for creating a new folder.
  481.      *
  482.      * @return  void 
  483.      *
  484.      * @since   3.2
  485.      */
  486.     public function createFolder()
  487.     {
  488.         $app      JFactory::getApplication();
  489.         $model    $this->getModel();
  490.         $id       $app->input->get('id');
  491.         $file     $app->input->get('file');
  492.         $name     $app->input->get('name');
  493.         $location base64_decode($app->input->get('address'));
  494.  
  495.         if (!preg_match('/^[a-zA-Z0-9-_.]+$/'$name))
  496.         {
  497.             $app->enqueueMessage(JText::_('COM_TEMPLATES_INVALID_FOLDER_NAME')'error');
  498.             $url 'index.php?option=com_templates&view=template&id=' $id '&file=' $file;
  499.             $this->setRedirect(JRoute::_($urlfalse));
  500.         }
  501.         elseif ($model->createFolder($name$location))
  502.         {
  503.             $this->setMessage(JText::_('COM_TEMPLATES_FOLDER_CREATE_SUCCESS'));
  504.             $url 'index.php?option=com_templates&view=template&id=' $id '&file=' $file;
  505.             $this->setRedirect(JRoute::_($urlfalse));
  506.         }
  507.         else
  508.         {
  509.             $app->enqueueMessage(JText::_('COM_TEMPLATES_ERROR_FOLDER_CREATE')'error');
  510.             $url 'index.php?option=com_templates&view=template&id=' $id '&file=' $file;
  511.             $this->setRedirect(JRoute::_($urlfalse));
  512.         }
  513.     }
  514.  
  515.     /**
  516.      * Method for deleting a folder.
  517.      *
  518.      * @return  void 
  519.      *
  520.      * @since   3.2
  521.      */
  522.     public function deleteFolder()
  523.     {
  524.         $app      JFactory::getApplication();
  525.         $model    $this->getModel();
  526.         $id       $app->input->get('id');
  527.         $file     $app->input->get('file');
  528.         $location base64_decode($app->input->get('address'));
  529.  
  530.         if (empty($location))
  531.         {
  532.             $app->enqueueMessage(JText::_('COM_TEMPLATES_ERROR_ROOT_DELETE')'warning');
  533.             $url 'index.php?option=com_templates&view=template&id=' $id '&file=' $file;
  534.             $this->setRedirect(JRoute::_($urlfalse));
  535.         }
  536.         elseif ($model->deleteFolder($location))
  537.         {
  538.             $this->setMessage(JText::_('COM_TEMPLATES_FOLDER_DELETE_SUCCESS'));
  539.  
  540.             if (stristr(base64_decode($file)$location!= false)
  541.             {
  542.                 $file base64_encode('home');
  543.             }
  544.  
  545.             $url 'index.php?option=com_templates&view=template&id=' $id '&file=' $file;
  546.             $this->setRedirect(JRoute::_($urlfalse));
  547.         }
  548.         else
  549.         {
  550.             $app->enqueueMessage(JText::_('COM_TEMPLATES_FOLDER_DELETE_ERROR')'error');
  551.             $url 'index.php?option=com_templates&view=template&id=' $id '&file=' $file;
  552.             $this->setRedirect(JRoute::_($urlfalse));
  553.         }
  554.     }
  555.  
  556.     /**
  557.      * Method for renaming a file.
  558.      *
  559.      * @return  void 
  560.      *
  561.      * @since   3.2
  562.      */
  563.     public function renameFile()
  564.     {
  565.         $app     JFactory::getApplication();
  566.         $model   $this->getModel();
  567.         $id      $app->input->get('id');
  568.         $file    $app->input->get('file');
  569.         $newName $app->input->get('new_name');
  570.  
  571.         if (base64_decode(urldecode($file)) == 'index.php')
  572.         {
  573.             $app->enqueueMessage(JText::_('COM_TEMPLATES_ERROR_RENAME_INDEX')'warning');
  574.             $url 'index.php?option=com_templates&view=template&id=' $id '&file=' $file;
  575.             $this->setRedirect(JRoute::_($urlfalse));
  576.         }
  577.         elseif (!preg_match('/^[a-zA-Z0-9-_]+$/'$newName))
  578.         {
  579.             $app->enqueueMessage(JText::_('COM_TEMPLATES_INVALID_FILE_NAME')'error');
  580.             $url 'index.php?option=com_templates&view=template&id=' $id '&file=' $file;
  581.             $this->setRedirect(JRoute::_($urlfalse));
  582.         }
  583.         elseif ($rename $model->renameFile($file$newName))
  584.         {
  585.             $this->setMessage(JText::_('COM_TEMPLATES_FILE_RENAME_SUCCESS'));
  586.             $url 'index.php?option=com_templates&view=template&id=' $id '&file=' $rename;
  587.             $this->setRedirect(JRoute::_($urlfalse));
  588.         }
  589.         else
  590.         {
  591.             $app->enqueueMessage(JText::_('COM_TEMPLATES_ERROR_FILE_RENAME')'error');
  592.             $url 'index.php?option=com_templates&view=template&id=' $id '&file=' $file;
  593.             $this->setRedirect(JRoute::_($urlfalse));
  594.         }
  595.     }
  596.  
  597.     /**
  598.      * Method for cropping an image.
  599.      *
  600.      * @return  void 
  601.      *
  602.      * @since   3.2
  603.      */
  604.     public function cropImage()
  605.     {
  606.         $app   JFactory::getApplication();
  607.         $id    $app->input->get('id');
  608.         $file  $app->input->get('file');
  609.         $x     $app->input->get('x');
  610.         $y     $app->input->get('y');
  611.         $w     $app->input->get('w');
  612.         $h     $app->input->get('h');
  613.         $model $this->getModel();
  614.  
  615.         if (empty($w&& empty($h&& empty($x&& empty($y))
  616.         {
  617.             $app->enqueueMessage(JText::_('COM_TEMPLATES_CROP_AREA_ERROR')'error');
  618.             $url 'index.php?option=com_templates&view=template&id=' $id '&file=' $file;
  619.             $this->setRedirect(JRoute::_($urlfalse));
  620.         }
  621.         elseif ($model->cropImage($file$w$h$x$y))
  622.         {
  623.             $app->enqueueMessage(JText::_('COM_TEMPLATES_FILE_CROP_SUCCESS'));
  624.             $url 'index.php?option=com_templates&view=template&id=' $id '&file=' $file;
  625.             $this->setRedirect(JRoute::_($urlfalse));
  626.         }
  627.         else
  628.         {
  629.             $app->enqueueMessage(JText::_('COM_TEMPLATES_FILE_CROP_ERROR')'error');
  630.             $url 'index.php?option=com_templates&view=template&id=' $id '&file=' $file;
  631.             $this->setRedirect(JRoute::_($urlfalse));
  632.         }
  633.     }
  634.  
  635.     /**
  636.      * Method for resizing an image.
  637.      *
  638.      * @return  void 
  639.      *
  640.      * @since   3.2
  641.      */
  642.     public function resizeImage()
  643.     {
  644.         $app    JFactory::getApplication();
  645.         $id     $app->input->get('id');
  646.         $file   $app->input->get('file');
  647.         $width  $app->input->get('width');
  648.         $height $app->input->get('height');
  649.         $model  $this->getModel();
  650.  
  651.         if ($model->resizeImage($file$width$height))
  652.         {
  653.             $app->enqueueMessage(JText::_('COM_TEMPLATES_FILE_RESIZE_SUCCESS'));
  654.             $url 'index.php?option=com_templates&view=template&id=' $id '&file=' $file;
  655.             $this->setRedirect(JRoute::_($urlfalse));
  656.         }
  657.         else
  658.         {
  659.             $app->enqueueMessage(JText::_('COM_TEMPLATES_FILE_RESIZE_ERROR')'error');
  660.             $url 'index.php?option=com_templates&view=template&id=' $id '&file=' $file;
  661.             $this->setRedirect(JRoute::_($urlfalse));
  662.         }
  663.     }
  664.  
  665.     /**
  666.      * Method for copying a file.
  667.      *
  668.      * @return  void 
  669.      *
  670.      * @since   3.2
  671.      */
  672.     public function copyFile()
  673.     {
  674.         $app      JFactory::getApplication();
  675.         $id       $app->input->get('id');
  676.         $file     $app->input->get('file');
  677.         $newName  $app->input->get('new_name');
  678.         $location base64_decode($app->input->get('address'));
  679.         $model    $this->getModel();
  680.  
  681.         if (!preg_match('/^[a-zA-Z0-9-_]+$/'$newName))
  682.         {
  683.             $app->enqueueMessage(JText::_('COM_TEMPLATES_INVALID_FILE_NAME')'error');
  684.             $url 'index.php?option=com_templates&view=template&id=' $id '&file=' $file;
  685.             $this->setRedirect(JRoute::_($urlfalse));
  686.         }
  687.         elseif ($model->copyFile($newName$location$file))
  688.         {
  689.             $url 'index.php?option=com_templates&view=template&id=' $id '&file=' $file;
  690.             $this->setRedirect(JRoute::_($urlfalse));
  691.         }
  692.         else
  693.         {
  694.             $app->enqueueMessage(JText::_('COM_TEMPLATES_FILE_COPY_FAIL')'error');
  695.             $url 'index.php?option=com_templates&view=template&id=' $id '&file=' $file;
  696.             $this->setRedirect(JRoute::_($urlfalse));
  697.         }
  698.     }
  699.  
  700.     /**
  701.      * Method for extracting an archive file.
  702.      *
  703.      * @return  void 
  704.      *
  705.      * @since   3.2
  706.      */
  707.     public function extractArchive()
  708.     {
  709.         $app   JFactory::getApplication();
  710.         $id    $app->input->get('id');
  711.         $file  $app->input->get('file');
  712.         $model $this->getModel();
  713.  
  714.         if ($model->extractArchive($file))
  715.         {
  716.             $app->enqueueMessage(JText::_('COM_TEMPLATES_FILE_ARCHIVE_EXTRACT_SUCCESS'));
  717.             $url 'index.php?option=com_templates&view=template&id=' $id '&file=' $file;
  718.             $this->setRedirect(JRoute::_($urlfalse));
  719.         }
  720.         else
  721.         {
  722.             $app->enqueueMessage(JText::_('COM_TEMPLATES_FILE_ARCHIVE_EXTRACT_FAIL')'error');
  723.             $url 'index.php?option=com_templates&view=template&id=' $id '&file=' $file;
  724.             $this->setRedirect(JRoute::_($urlfalse));
  725.         }
  726.     }
  727. }

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