Source for file html.php

Documentation is available at html.php

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

Documentation generated on Tue, 19 Nov 2013 15:04:48 +0100 by phpDocumentor 1.4.3