Source for file template.php
Documentation is available at template.php
* @package Joomla.Administrator
* @subpackage com_templates
* @copyright Copyright (C) 2005 - 2013 Open Source Matters, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE.txt
* Template style controller class.
* @package Joomla.Administrator
* @subpackage com_templates
* @param array $config An optional associative array of configuration settings.
// Apply, Save & New, and Save As copy should be standard on forms.
* Method for closing the template.
* Method for closing a file.
$id =
$app->input->get('id');
$url =
'index.php?option=com_templates&view=template&id=' .
$id .
'&file=' .
$file;
* Method for copying the template.
* @return boolean true on success, false otherwise
// Check for request forgeries
$this->input->set('installtype', 'folder');
$newName =
$this->input->get('new_name');
$newNameRaw =
$this->input->get('new_name', null, 'string');
$templateID =
$this->input->getInt('id', 0);
$file =
$this->input->get('file');
$this->setRedirect('index.php?option=com_templates&view=template&id=' .
$templateID .
'&file=' .
$file);
$model =
$this->getModel('Template', 'TemplatesModel');
$model->setState('new_name', $newName);
$model->setState('tmp_prefix', uniqid('template_copy_'));
$model->setState('to_path', JFactory::getConfig()->get('tmp_path') .
'/' .
$model->getState('tmp_prefix'));
// Process only if we have a new name entered
// User is not authorised to delete
$app->enqueueMessage(JText::_('COM_TEMPLATES_ERROR_CREATE_NOT_PERMITTED'), 'error');
// Set FTP credentials, if given
// Check that new name is valid
if (($newNameRaw !==
null) &&
($newName !==
$newNameRaw))
$app->enqueueMessage(JText::_('COM_TEMPLATES_ERROR_INVALID_TEMPLATE_NAME'), 'error');
// Check that new name doesn't already exist
if (!$model->checkNewName())
$app->enqueueMessage(JText::_('COM_TEMPLATES_ERROR_DUPLICATE_TEMPLATE_NAME'), 'error');
// Check that from name does exist and get the folder name
$fromName =
$model->getFromName();
$app->enqueueMessage(JText::_('COM_TEMPLATES_ERROR_INVALID_FROM_NAME'), 'error');
// Call model's copy method
$app->enqueueMessage(JText::_('COM_TEMPLATES_ERROR_COULD_NOT_COPY'), 'error');
// Call installation model
$this->input->set('install_directory', JFactory::getConfig()->get('tmp_path') .
'/' .
$model->getState('tmp_prefix'));
$installModel =
$this->getModel('Install', 'InstallerModel');
if (!$installModel->install())
$app->enqueueMessage(JText::_('COM_TEMPLATES_ERROR_COULD_NOT_INSTALL'), 'error');
* Method to get a model object, loading it if required.
* @param string $name The model name. Optional.
* @param string $prefix The class prefix. Optional.
* @param array $config Configuration array for model. Optional (note, the empty array is atypical compared to other models).
* @return JModelLegacy The model.
public function getModel($name =
'Template', $prefix =
'TemplatesModel', $config =
array())
$model =
parent::getModel($name, $prefix, $config);
* Method to check if you can add a new record.
* Method to check if you can save a new or existing record.
* Saves a template source file.
// Check for request forgeries.
$data =
$this->input->post->get('jform', array(), 'array');
$fileName =
$app->input->get('file');
$app->enqueueMessage(JText::_('JERROR_SAVE_NOT_PERMITTED'), 'error');
// Match the stored id's with the submitted.
if (empty($data['extension_id']) ||
empty($data['filename']))
$app->enqueueMessage(JText::_('COM_TEMPLATES_ERROR_SOURCE_ID_FILENAME_MISMATCH'), 'error');
elseif ($data['extension_id'] !=
$model->getState('extension.id'))
$app->enqueueMessage(JText::_('COM_TEMPLATES_ERROR_SOURCE_ID_FILENAME_MISMATCH'), 'error');
elseif ($data['filename'] !=
end($explodeArray))
$app->enqueueMessage(JText::_('COM_TEMPLATES_ERROR_SOURCE_ID_FILENAME_MISMATCH'), 'error');
// Validate the posted data.
$form =
$model->getForm();
$app->enqueueMessage($model->getError(), 'error');
$data =
$model->validate($form, $data);
// Check for validation errors.
// Get the validation messages.
$errors =
$model->getErrors();
// Push up to three validation messages out to the user.
for ($i =
0, $n =
count($errors); $i <
$n &&
$i <
3; $i++
)
if ($errors[$i] instanceof
Exception)
$app->enqueueMessage($errors[$i]->getMessage(), 'warning');
$app->enqueueMessage($errors[$i], 'warning');
// Redirect back to the edit screen.
$url =
'index.php?option=com_templates&view=template&id=' .
$model->getState('extension.id') .
'&file=' .
$fileName;
// Attempt to save the data.
if (!$model->save($data))
// Redirect back to the edit screen.
$url =
'index.php?option=com_templates&view=template&id=' .
$model->getState('extension.id') .
'&file=' .
$fileName;
// Redirect the user based on the chosen task.
// Redirect back to the edit screen.
$url =
'index.php?option=com_templates&view=template&id=' .
$model->getState('extension.id') .
'&file=' .
$fileName;
// Redirect to the list screen.
* Method for creating override.
$file =
$app->input->get('file');
$id =
$app->input->get('id');
if ($model->createOverride($override))
// Redirect back to the edit screen.
$url =
'index.php?option=com_templates&view=template&id=' .
$id .
'&file=' .
$file;
* Method for compiling LESS.
$id =
$app->input->get('id');
$file =
$app->input->get('file');
if ($model->compileLess($file))
$app->enqueueMessage(JText::_('COM_TEMPLATES_COMPILE_ERROR'), 'error');
$url =
'index.php?option=com_templates&view=template&id=' .
$id .
'&file=' .
$file;
* Method for deleting a file.
$id =
$app->input->get('id');
$file =
$app->input->get('file');
$app->enqueueMessage(JText::_('COM_TEMPLATES_ERROR_INDEX_DELETE'), 'warning');
$url =
'index.php?option=com_templates&view=template&id=' .
$id .
'&file=' .
$file;
elseif ($model->deleteFile($file))
$url =
'index.php?option=com_templates&view=template&id=' .
$id .
'&file=' .
$file;
$app->enqueueMessage(JText::_('COM_TEMPLATES_ERROR_FILE_DELETE'), 'error');
$url =
'index.php?option=com_templates&view=template&id=' .
$id .
'&file=' .
$file;
* Method for creating a new file.
$id =
$app->input->get('id');
$file =
$app->input->get('file');
$name =
$app->input->get('name');
$type =
$app->input->get('type');
$app->enqueueMessage(JText::_('COM_TEMPLATES_INVALID_FILE_TYPE'), 'error');
$url =
'index.php?option=com_templates&view=template&id=' .
$id .
'&file=' .
$file;
$app->enqueueMessage(JText::_('COM_TEMPLATES_INVALID_FILE_NAME'), 'error');
$url =
'index.php?option=com_templates&view=template&id=' .
$id .
'&file=' .
$file;
elseif ($model->createFile($name, $type, $location))
$url =
'index.php?option=com_templates&view=template&id=' .
$id .
'&file=' .
$file;
$app->enqueueMessage(JText::_('COM_TEMPLATES_ERROR_FILE_CREATE'), 'error');
$url =
'index.php?option=com_templates&view=template&id=' .
$id .
'&file=' .
$file;
* Method for uploading a file.
$id =
$app->input->get('id');
$file =
$app->input->get('file');
$upload =
$app->input->files->get('files');
if ($return =
$model->uploadFile($upload, $location))
$app->enqueueMessage(JText::_('COM_TEMPLATES_FILE_UPLOAD_SUCCESS') .
$upload['name']);
$url =
'index.php?option=com_templates&view=template&id=' .
$id .
'&file=' .
$redirect;
$app->enqueueMessage(JText::_('COM_TEMPLATES_ERROR_FILE_UPLOAD'), 'error');
$url =
'index.php?option=com_templates&view=template&id=' .
$id .
'&file=' .
$file;
* Method for creating a new folder.
$id =
$app->input->get('id');
$file =
$app->input->get('file');
$name =
$app->input->get('name');
$app->enqueueMessage(JText::_('COM_TEMPLATES_INVALID_FOLDER_NAME'), 'error');
$url =
'index.php?option=com_templates&view=template&id=' .
$id .
'&file=' .
$file;
elseif ($model->createFolder($name, $location))
$url =
'index.php?option=com_templates&view=template&id=' .
$id .
'&file=' .
$file;
$app->enqueueMessage(JText::_('COM_TEMPLATES_ERROR_FOLDER_CREATE'), 'error');
$url =
'index.php?option=com_templates&view=template&id=' .
$id .
'&file=' .
$file;
* Method for deleting a folder.
$id =
$app->input->get('id');
$file =
$app->input->get('file');
$app->enqueueMessage(JText::_('COM_TEMPLATES_ERROR_ROOT_DELETE'), 'warning');
$url =
'index.php?option=com_templates&view=template&id=' .
$id .
'&file=' .
$file;
elseif ($model->deleteFolder($location))
$url =
'index.php?option=com_templates&view=template&id=' .
$id .
'&file=' .
$file;
$app->enqueueMessage(JText::_('COM_TEMPLATES_FOLDER_DELETE_ERROR'), 'error');
$url =
'index.php?option=com_templates&view=template&id=' .
$id .
'&file=' .
$file;
* Method for renaming a file.
$id =
$app->input->get('id');
$file =
$app->input->get('file');
$newName =
$app->input->get('new_name');
$app->enqueueMessage(JText::_('COM_TEMPLATES_ERROR_RENAME_INDEX'), 'warning');
$url =
'index.php?option=com_templates&view=template&id=' .
$id .
'&file=' .
$file;
elseif (!preg_match('/^[a-zA-Z0-9-_]+$/', $newName))
$app->enqueueMessage(JText::_('COM_TEMPLATES_INVALID_FILE_NAME'), 'error');
$url =
'index.php?option=com_templates&view=template&id=' .
$id .
'&file=' .
$file;
elseif ($rename =
$model->renameFile($file, $newName))
$url =
'index.php?option=com_templates&view=template&id=' .
$id .
'&file=' .
$rename;
$app->enqueueMessage(JText::_('COM_TEMPLATES_ERROR_FILE_RENAME'), 'error');
$url =
'index.php?option=com_templates&view=template&id=' .
$id .
'&file=' .
$file;
* Method for cropping an image.
$id =
$app->input->get('id');
$file =
$app->input->get('file');
$x =
$app->input->get('x');
$y =
$app->input->get('y');
$w =
$app->input->get('w');
$h =
$app->input->get('h');
if (empty($w) &&
empty($h) &&
empty($x) &&
empty($y))
$app->enqueueMessage(JText::_('COM_TEMPLATES_CROP_AREA_ERROR'), 'error');
$url =
'index.php?option=com_templates&view=template&id=' .
$id .
'&file=' .
$file;
elseif ($model->cropImage($file, $w, $h, $x, $y))
$app->enqueueMessage(JText::_('COM_TEMPLATES_FILE_CROP_SUCCESS'));
$url =
'index.php?option=com_templates&view=template&id=' .
$id .
'&file=' .
$file;
$app->enqueueMessage(JText::_('COM_TEMPLATES_FILE_CROP_ERROR'), 'error');
$url =
'index.php?option=com_templates&view=template&id=' .
$id .
'&file=' .
$file;
* Method for resizing an image.
$id =
$app->input->get('id');
$file =
$app->input->get('file');
$width =
$app->input->get('width');
$height =
$app->input->get('height');
if ($model->resizeImage($file, $width, $height))
$app->enqueueMessage(JText::_('COM_TEMPLATES_FILE_RESIZE_SUCCESS'));
$url =
'index.php?option=com_templates&view=template&id=' .
$id .
'&file=' .
$file;
$app->enqueueMessage(JText::_('COM_TEMPLATES_FILE_RESIZE_ERROR'), 'error');
$url =
'index.php?option=com_templates&view=template&id=' .
$id .
'&file=' .
$file;
* Method for copying a file.
$id =
$app->input->get('id');
$file =
$app->input->get('file');
$newName =
$app->input->get('new_name');
$app->enqueueMessage(JText::_('COM_TEMPLATES_INVALID_FILE_NAME'), 'error');
$url =
'index.php?option=com_templates&view=template&id=' .
$id .
'&file=' .
$file;
elseif ($model->copyFile($newName, $location, $file))
$url =
'index.php?option=com_templates&view=template&id=' .
$id .
'&file=' .
$file;
$app->enqueueMessage(JText::_('COM_TEMPLATES_FILE_COPY_FAIL'), 'error');
$url =
'index.php?option=com_templates&view=template&id=' .
$id .
'&file=' .
$file;
* Method for extracting an archive file.
$id =
$app->input->get('id');
$file =
$app->input->get('file');
if ($model->extractArchive($file))
$app->enqueueMessage(JText::_('COM_TEMPLATES_FILE_ARCHIVE_EXTRACT_SUCCESS'));
$url =
'index.php?option=com_templates&view=template&id=' .
$id .
'&file=' .
$file;
$app->enqueueMessage(JText::_('COM_TEMPLATES_FILE_ARCHIVE_EXTRACT_FAIL'), 'error');
$url =
'index.php?option=com_templates&view=template&id=' .
$id .
'&file=' .
$file;
Documentation generated on Tue, 19 Nov 2013 15:15:34 +0100 by phpDocumentor 1.4.3