- md5
- 9fe8e436db50082234af9d02ac4e208e
- sha1
- 4d3a256d14e65c068bf6d83a84c8d31037dc2992
- sha256
- 4097b00e534ad28e06bd137d736b918776178b4f7fc0a3f971cc722eb0141df7
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
<?php
/**
* @package Joomla.Administrator
* @subpackage com_templates
* @copyright Copyright (C) 2005 - 2012 Open Source Matters, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
// No direct access.
defined('_JEXEC') or die;
jimport('joomla.application.component.model');
/**
* @package Joomla.Administrator
* @subpackage com_templates
* @since 1.6
*/
class TemplatesModelTemplate extends JModel
{
protected $template = null;
/**
* Internal method to get file properties.
*
* @param string The base path.
* @param string The file name.
* @return object
* @since 1.6
*/
protected function getFile($path, $name)
{
$temp = new stdClass;
if ($template = $this->getTemplate()) {
$temp->name = $name;
$temp->exists = file_exists($path.$name);
$temp->id = urlencode(base64_encode($template->extension_id.':'.$name));
return $temp;
}
}
/**
* Method to get a list of all the files to edit in a template.
*
* @return array A nested array of relevant files.
* @since 1.6
*/
public function getFiles()
{
// Initialise variables.
$result = array();
if ($template = $this->getTemplate()) {
jimport('joomla.filesystem.folder');
$client = JApplicationHelper::getClientInfo($template->client_id);
$path = JPath::clean($client->path.'/templates/'.$template->element.'/');
$lang = JFactory::getLanguage();
// Load the core and/or local language file(s).
$lang->load('tpl_'.$template->element, $client->path, null, false, false)
|| $lang->load('tpl_'.$template->element, $client->path.'/templates/'.$template->element, null, false, false)
|| $lang->load('tpl_'.$template->element, $client->path, $lang->getDefault(), false, false)
|| $lang->load('tpl_'.$template->element, $client->path.'/templates/'.$template->element, $lang->getDefault(), false, false);
// Check if the template path exists.
if (is_dir($path)) {
$result['main'] = array();
$result['css'] = array();
$result['clo'] = array();
$result['mlo'] = array();
$result['html'] = array();
// Handle the main PHP files.
$result['main']['index'] = $this->getFile($path, 'index.php');
$result['main']['error'] = $this->getFile($path, 'error.php');
$result['main']['print'] = $this->getFile($path, 'component.php');
$result['main']['offline'] = $this->getFile($path, 'offline.php');
// Handle the CSS files.
$files = JFolder::files($path.'/css', '\.css$', false, false);
foreach ($files as $file) {
$result['css'][] = $this->getFile($path.'/css/', 'css/'.$file);
}
} else {
$this->setError(JText::_('COM_TEMPLATES_ERROR_TEMPLATE_FOLDER_NOT_FOUND'));
return false;
}
}
return $result;
}
/**
* Method to auto-populate the model state.
*
* Note. Calling getState in this method will result in recursion.
*
* @since 1.6
*/
protected function populateState()
{
$app = JFactory::getApplication('administrator');
// Load the User state.
$pk = (int) JRequest::getInt('id');
$this->setState('extension.id', $pk);
// Load the parameters.
$params = JComponentHelper::getParams('com_templates');
$this->setState('params', $params);
}
/**
* Method to get the template information.
*
* @return mixed Object if successful, false if not and internal error is set.
* @since 1.6
*/
public function &getTemplate()
{
if (empty($this->template)) {
// Initialise variables.
$pk = $this->getState('extension.id');
$db = $this->getDbo();
$result = false;
// Get the template information.
$db->setQuery(
'SELECT extension_id, client_id, element' .
' FROM #__extensions' .
' WHERE extension_id = '.(int) $pk.
' AND type = '.$db->quote('template')
);
$result = $db->loadObject();
if (empty($result)) {
if ($error = $db->getErrorMsg()) {
$this->setError($error);
} else {
$this->setError(JText::_('COM_TEMPLATES_ERROR_EXTENSION_RECORD_NOT_FOUND'));
}
$this->template = false;
} else {
$this->template = $result;
}
}
return $this->template;
}
}
The same content is in 5 releases, Joomla 2.5.0 to 2.5.4. See them all, or every version of this file.