PageRenderTime 41ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 0ms

/joomla/components/com_config/view/cms/html.php

https://gitlab.com/ricardosanchez/prueba
PHP | 224 lines | 103 code | 31 blank | 90 comment | 12 complexity | 0a1da859a5de1d851559b13e96cc1604 MD5 | raw file
  1. <?php
  2. /**
  3. * @package Joomla.Site
  4. * @subpackage com_config
  5. *
  6. * @copyright Copyright (C) 2005 - 2015 Open Source Matters, Inc. All rights reserved.
  7. * @license GNU General Public License version 2 or later; see LICENSE.txt
  8. */
  9. defined('_JEXEC') or die;
  10. /**
  11. * Prototype admin view.
  12. *
  13. * @since 3.2
  14. */
  15. abstract class ConfigViewCmsHtml extends JViewHtml
  16. {
  17. /**
  18. * The output of the template script.
  19. *
  20. * @var string
  21. * @since 3.2
  22. */
  23. protected $_output = null;
  24. /**
  25. * The name of the default template source file.
  26. *
  27. * @var string
  28. * @since 3.2
  29. */
  30. protected $_template = null;
  31. /**
  32. * The set of search directories for resources (templates)
  33. *
  34. * @var array
  35. * @since 3.2
  36. */
  37. protected $_path = array('template' => array(), 'helper' => array());
  38. /**
  39. * Layout extension
  40. *
  41. * @var string
  42. * @since 3.2
  43. */
  44. protected $_layoutExt = 'php';
  45. /**
  46. * Method to instantiate the view.
  47. *
  48. * @param JModel $model The model object.
  49. * @param SplPriorityQueue $paths The paths queue.
  50. *
  51. * @since 3.2
  52. */
  53. public function __construct(JModel $model, SplPriorityQueue $paths = null)
  54. {
  55. $app = JFactory::getApplication();
  56. $component = JApplicationHelper::getComponentName();
  57. $component = preg_replace('/[^A-Z0-9_\.-]/i', '', $component);
  58. if (isset($paths))
  59. {
  60. $paths->insert(JPATH_THEMES . '/' . $app->getTemplate() . '/html/' . $component . '/' . $this->getName(), 2);
  61. }
  62. parent::__construct($model, $paths);
  63. }
  64. /**
  65. * Load a template file -- first look in the templates folder for an override
  66. *
  67. * @param string $tpl The name of the template source file; automatically searches the template paths and compiles as needed.
  68. *
  69. * @return string The output of the the template script.
  70. *
  71. * @since 3.2
  72. * @throws Exception
  73. */
  74. public function loadTemplate($tpl = null)
  75. {
  76. // Clear prior output
  77. $this->_output = null;
  78. $template = JFactory::getApplication()->getTemplate();
  79. $layout = $this->getLayout();
  80. // Create the template file name based on the layout
  81. $file = isset($tpl) ? $layout . '_' . $tpl : $layout;
  82. // Clean the file name
  83. $file = preg_replace('/[^A-Z0-9_\.-]/i', '', $file);
  84. $tpl = isset($tpl) ? preg_replace('/[^A-Z0-9_\.-]/i', '', $tpl) : $tpl;
  85. // Load the language file for the template
  86. $lang = JFactory::getLanguage();
  87. $lang->load('tpl_' . $template, JPATH_BASE, null, false, true)
  88. || $lang->load('tpl_' . $template, JPATH_THEMES . "/$template", null, false, true);
  89. // Prevents adding path twise
  90. if (empty($this->_path['template']))
  91. {
  92. // Adding template paths
  93. $this->paths->top();
  94. $defaultPath = $this->paths->current();
  95. $this->paths->next();
  96. $templatePath = $this->paths->current();
  97. $this->_path['template'] = array($defaultPath, $templatePath);
  98. }
  99. // Load the template script
  100. jimport('joomla.filesystem.path');
  101. $filetofind = $this->_createFileName('template', array('name' => $file));
  102. $this->_template = JPath::find($this->_path['template'], $filetofind);
  103. // If alternate layout can't be found, fall back to default layout
  104. if ($this->_template == false)
  105. {
  106. $filetofind = $this->_createFileName('', array('name' => 'default' . (isset($tpl) ? '_' . $tpl : $tpl)));
  107. $this->_template = JPath::find($this->_path['template'], $filetofind);
  108. }
  109. if ($this->_template != false)
  110. {
  111. // Unset so as not to introduce into template scope
  112. unset($tpl);
  113. unset($file);
  114. // Never allow a 'this' property
  115. if (isset($this->this))
  116. {
  117. unset($this->this);
  118. }
  119. // Start capturing output into a buffer
  120. ob_start();
  121. // Include the requested template filename in the local scope
  122. // (this will execute the view logic).
  123. include $this->_template;
  124. // Done with the requested template; get the buffer and
  125. // clear it.
  126. $this->_output = ob_get_contents();
  127. ob_end_clean();
  128. return $this->_output;
  129. }
  130. else
  131. {
  132. throw new Exception(JText::sprintf('JLIB_APPLICATION_ERROR_LAYOUTFILE_NOT_FOUND', $file), 500);
  133. }
  134. }
  135. /**
  136. * Create the filename for a resource
  137. *
  138. * @param string $type The resource type to create the filename for
  139. * @param array $parts An associative array of filename information
  140. *
  141. * @return string The filename
  142. *
  143. * @since 3.2
  144. */
  145. protected function _createFileName($type, $parts = array())
  146. {
  147. $filename = '';
  148. switch ($type)
  149. {
  150. case 'template':
  151. $filename = strtolower($parts['name']) . '.' . $this->_layoutExt;
  152. break;
  153. default:
  154. $filename = strtolower($parts['name']) . '.php';
  155. break;
  156. }
  157. return $filename;
  158. }
  159. /**
  160. * Method to get the view name
  161. *
  162. * The model name by default parsed using the classname, or it can be set
  163. * by passing a $config['name'] in the class constructor
  164. *
  165. * @return string The name of the model
  166. *
  167. * @since 3.2
  168. * @throws Exception
  169. */
  170. public function getName()
  171. {
  172. if (empty($this->_name))
  173. {
  174. $classname = get_class($this);
  175. $viewpos = strpos($classname, 'View');
  176. if ($viewpos === false)
  177. {
  178. throw new Exception(JText::_('JLIB_APPLICATION_ERROR_VIEW_GET_NAME'), 500);
  179. }
  180. $lastPart = substr($classname, $viewpos + 4);
  181. $pathParts = explode(' ', JStringNormalise::fromCamelCase($lastPart));
  182. if (!empty($pathParts[1]))
  183. {
  184. $this->_name = strtolower($pathParts[0]);
  185. }
  186. else
  187. {
  188. $this->_name = strtolower($lastPart);
  189. }
  190. }
  191. return $this->_name;
  192. }
  193. }