- md5
- 2210ce3f87919a28df79d65a470cf8e9
- sha1
- 64749f34876cbf5dd859daf062eefdeb9e03bd6d
- sha256
- 2a0131db4178825e855b79002b0f1503770019b721494f1d06646983451deb9d
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
<?php
/**
* @copyright Copyright (C) 2005 - 2013 Open Source Matters, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
defined('_JEXEC') or die;
JLoader::register('InstallerModelInstall', JPATH_ADMINISTRATOR . '/components/com_installer/models/install.php');
/**
* Template style controller class.
*
* @package Joomla.Administrator
* @subpackage com_templates
* @since 1.6
*/
class TemplatesControllerTemplate extends JControllerLegacy
{
/**
*/
public function cancel()
{
$this->setRedirect('index.php?option=com_templates&view=templates');
}
public function copy()
{
// Check for request forgeries
JSession::checkToken() or jexit(JText::_('JINVALID_TOKEN'));
$app = JFactory::getApplication();
JRequest::setVar('installtype', 'folder');
$newName = JRequest::getCmd('new_name');
$newNameRaw = JRequest::getVar('new_name', null, '', 'string');
$templateID = JRequest::getInt('id', 0);
$this->setRedirect('index.php?option=com_templates&view=template&id=' . $templateID);
$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
if (strlen($newName) > 0)
{
if (!JFactory::getUser()->authorise('core.create', 'com_templates'))
{
// User is not authorised to delete
JError::raiseWarning(403, JText::_('COM_TEMPLATES_ERROR_CREATE_NOT_PERMITTED'));
return false;
}
// Set FTP credentials, if given
JClientHelper::setCredentialsFromRequest('ftp');
// Check that new name is valid
if (($newNameRaw !== null) && ($newName !== $newNameRaw)) {
JError::raiseWarning(403, JText::_('COM_TEMPLATES_ERROR_INVALID_TEMPLATE_NAME'));
return false;
}
// Check that new name doesn't already exist
if (!$model->checkNewName())
{
JError::raiseWarning(403, JText::_('COM_TEMPLATES_ERROR_DUPLICATE_TEMPLATE_NAME'));
return false;
}
// Check that from name does exist and get the folder name
$fromName = $model->getFromName();
if (!$fromName)
{
JError::raiseWarning(403, JText::_('COM_TEMPLATES_ERROR_INVALID_FROM_NAME'));
return false;
}
// Call model's copy method
if (!$model->copy())
{
JError::raiseWarning(403, JText::_('COM_TEMPLATES_ERROR_COULD_NOT_COPY'));
return false;
}
// Call installation model
JRequest::setVar('install_directory', JFactory::getConfig()->get('tmp_path') . '/' . $model->getState('tmp_prefix'));
$installModel = $this->getModel('Install', 'InstallerModel');
JFactory::getLanguage()->load('com_installer');
if (!$installModel->install())
{
JError::raiseWarning(403, JText::_('COM_TEMPLATES_ERROR_COULD_NOT_INSTALL'));
return false;
}
$this->setMessage(JText::sprintf('COM_TEMPLATES_COPY_SUCCESS', $newName));
$model->cleanup();
return true;
}
}
}
The same content is in 8 releases, Joomla 2.5.9 to 2.5.17. See them all, or every version of this file.