| [ Index ] |
PHP Cross Reference of Joomla 2.5.4 DE |
[Summary view] [Print] [Text view]
1 <?php 2 /** 3 * @package Joomla.Administrator 4 * @subpackage com_templates 5 * @copyright Copyright (C) 2005 - 2012 Open Source Matters, Inc. All rights reserved. 6 * @license GNU General Public License version 2 or later; see LICENSE.txt 7 */ 8 9 // No direct access. 10 defined('_JEXEC') or die; 11 12 jimport('joomla.application.component.model'); 13 14 /** 15 * @package Joomla.Administrator 16 * @subpackage com_templates 17 * @since 1.6 18 */ 19 class TemplatesModelTemplate extends JModel 20 { 21 protected $template = null; 22 23 /** 24 * Internal method to get file properties. 25 * 26 * @param string The base path. 27 * @param string The file name. 28 * @return object 29 * @since 1.6 30 */ 31 protected function getFile($path, $name) 32 { 33 $temp = new stdClass; 34 35 if ($template = $this->getTemplate()) { 36 $temp->name = $name; 37 $temp->exists = file_exists($path.$name); 38 $temp->id = urlencode(base64_encode($template->extension_id.':'.$name)); 39 return $temp; 40 } 41 } 42 43 /** 44 * Method to get a list of all the files to edit in a template. 45 * 46 * @return array A nested array of relevant files. 47 * @since 1.6 48 */ 49 public function getFiles() 50 { 51 // Initialise variables. 52 $result = array(); 53 54 if ($template = $this->getTemplate()) { 55 jimport('joomla.filesystem.folder'); 56 57 $client = JApplicationHelper::getClientInfo($template->client_id); 58 $path = JPath::clean($client->path.'/templates/'.$template->element.'/'); 59 $lang = JFactory::getLanguage(); 60 61 // Load the core and/or local language file(s). 62 $lang->load('tpl_'.$template->element, $client->path, null, false, false) 63 || $lang->load('tpl_'.$template->element, $client->path.'/templates/'.$template->element, null, false, false) 64 || $lang->load('tpl_'.$template->element, $client->path, $lang->getDefault(), false, false) 65 || $lang->load('tpl_'.$template->element, $client->path.'/templates/'.$template->element, $lang->getDefault(), false, false); 66 67 // Check if the template path exists. 68 69 if (is_dir($path)) { 70 $result['main'] = array(); 71 $result['css'] = array(); 72 $result['clo'] = array(); 73 $result['mlo'] = array(); 74 $result['html'] = array(); 75 76 // Handle the main PHP files. 77 $result['main']['index'] = $this->getFile($path, 'index.php'); 78 $result['main']['error'] = $this->getFile($path, 'error.php'); 79 $result['main']['print'] = $this->getFile($path, 'component.php'); 80 $result['main']['offline'] = $this->getFile($path, 'offline.php'); 81 82 // Handle the CSS files. 83 $files = JFolder::files($path.'/css', '\.css$', false, false); 84 85 foreach ($files as $file) { 86 $result['css'][] = $this->getFile($path.'/css/', 'css/'.$file); 87 } 88 } else { 89 $this->setError(JText::_('COM_TEMPLATES_ERROR_TEMPLATE_FOLDER_NOT_FOUND')); 90 return false; 91 } 92 } 93 94 return $result; 95 } 96 97 /** 98 * Method to auto-populate the model state. 99 * 100 * Note. Calling getState in this method will result in recursion. 101 * 102 * @since 1.6 103 */ 104 protected function populateState() 105 { 106 $app = JFactory::getApplication('administrator'); 107 108 // Load the User state. 109 $pk = (int) JRequest::getInt('id'); 110 $this->setState('extension.id', $pk); 111 112 // Load the parameters. 113 $params = JComponentHelper::getParams('com_templates'); 114 $this->setState('params', $params); 115 } 116 117 /** 118 * Method to get the template information. 119 * 120 * @return mixed Object if successful, false if not and internal error is set. 121 * @since 1.6 122 */ 123 public function &getTemplate() 124 { 125 if (empty($this->template)) { 126 // Initialise variables. 127 $pk = $this->getState('extension.id'); 128 $db = $this->getDbo(); 129 $result = false; 130 131 // Get the template information. 132 $db->setQuery( 133 'SELECT extension_id, client_id, element' . 134 ' FROM #__extensions' . 135 ' WHERE extension_id = '.(int) $pk. 136 ' AND type = '.$db->quote('template') 137 ); 138 139 $result = $db->loadObject(); 140 if (empty($result)) { 141 if ($error = $db->getErrorMsg()) { 142 $this->setError($error); 143 } else { 144 $this->setError(JText::_('COM_TEMPLATES_ERROR_EXTENSION_RECORD_NOT_FOUND')); 145 } 146 $this->template = false; 147 } else { 148 $this->template = $result; 149 } 150 } 151 152 return $this->template; 153 } 154 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
| Generated: Tue Apr 3 11:40:28 2012 | Cross-referenced by PHPXref 0.7.1 |