Support Joomla!

Joomla! 1.5 Documentation

Packages

Package: Joomla-Framework

Developer Network License

The Joomla! Developer Network content is © copyright 2006 by the individual contributors and can be used in accordance with the Creative Commons License, Attribution- NonCommercial- ShareAlike 2.5
Source code for file /joomla/document/html/html.php

Documentation is available at html.php

  1. <?php
  2. /**
  3. @version        $Id: html.php 6634 2007-02-15 18:27:18Z Jinx $
  4. @package        Joomla.Framework
  5. @subpackage    Document
  6. @copyright    Copyright (C) 2005 - 2007 Open Source Matters. All rights reserved.
  7. @license        GNU/GPL, see LICENSE.php
  8. *  Joomla! is free software. This version may have been modified pursuant
  9. *  to the GNU General Public License, and as distributed it includes or
  10. *  is derivative of works licensed under the GNU General Public License or
  11. *  other free or open source software licenses.
  12. *  See COPYRIGHT.php for copyright notices and details.
  13. */
  14.  
  15. // Check to ensure this file is within the rest of the framework
  16. defined('JPATH_BASE'or die();
  17.  
  18. jimport('joomla.application.module.helper');
  19.  
  20. /**
  21.  * DocumentHTML class, provides an easy interface to parse and display an html document
  22.  *
  23.  * @author        Johan Janssens <[email protected]>
  24.  * @package        Joomla.Framework
  25.  * @subpackage    Document
  26.  * @since        1.5
  27.  */
  28.  
  29. class JDocumentHTML extends JDocument
  30. {
  31.      /**
  32.      * Array of Header <link> tags
  33.      *
  34.      * @var     array 
  35.      * @access  private
  36.      */
  37.     var $_links array();
  38.  
  39.     /**
  40.      * Array of custom tags
  41.      *
  42.      * @var     string 
  43.      * @access  private
  44.      */
  45.     var $_custom array();
  46.  
  47.  
  48.     /**
  49.      * Class constructor
  50.      *
  51.      * @access protected
  52.      * @param    array    $options Associative array of options
  53.      */
  54.     function __construct($options array())
  55.     {
  56.         parent::__construct($options);
  57.  
  58.         //set document type
  59.         $this->_type 'html';
  60.  
  61.         //set mime type
  62.         $this->_mime 'text/html';
  63.  
  64.         //set default document metadata
  65.          $this->setMetaData('Content-Type'$this->_mime '; charset=' $this->_charset true );
  66.          $this->setMetaData('robots''index, follow' );
  67.     }
  68.  
  69.     /**
  70.      * Get the document head data
  71.      *
  72.      * @access    public
  73.      * @return    array    The document head data in array form
  74.      */
  75.     function getHeadData(
  76.     {
  77.         $data array();
  78.         $data['title']            $this->title;
  79.         $data['description']    $this->description;
  80.         $data['link']            $this->link;
  81.         $data['metaTags']        $this->_metaTags;
  82.         $data['links']            $this->_links;
  83.         $data['styleSheets']    $this->_styleSheets;
  84.         $data['style']            $this->_style;
  85.         $data['scripts']        $this->_scripts;
  86.         $data['script']            $this->_script;
  87.         $data['custom']            $this->_custom;
  88.         return $data;
  89.     }
  90.  
  91.     /**
  92.      * Set the document head data
  93.      *
  94.      * @access    public
  95.      * @param    array    $data    The document head data in array form
  96.      */
  97.     function setHeadData($data
  98.     {
  99.         $this->title        = (isset($data['title'])) $data['title'$this->title;
  100.         $this->description    = (isset($data['description'])) $data['description'$this->description;
  101.         $this->link            = (isset($data['link'])) $data['link'$this->link;
  102.         $this->_metaTags    (isset($data['metaTags'])) $data['metaTags'$this->_metaTags;
  103.         $this->_links        (isset($data['links'])) $data['links'$this->_links;
  104.         $this->_styleSheets    (isset($data['styleSheets'])) $data['styleSheets'$this->_styleSheets;
  105.         $this->_style        (isset($data['style'])) $data['style'$this->_style;
  106.         $this->_scripts        (isset($data['scripts'])) $data['scripts'$this->_scripts;
  107.         $this->_script        (isset($data['script'])) $data['script'$this->_script;
  108.         $this->_custom        (isset($data['custom'])) $data['custom'$this->_custom;
  109.     }
  110.  
  111.      /**
  112.      * Adds <link> tags to the head of the document
  113.      *
  114.      * <p>$relType defaults to 'rel' as it is the most common relation type used.
  115.      * ('rev' refers to reverse relation, 'rel' indicates normal, forward relation.)
  116.      * Typical tag: <link href="index.php" rel="Start"></p>
  117.      *
  118.      * @access   public
  119.      * @param    string  $href        The link that is being related.
  120.      * @param    string  $relation   Relation of link.
  121.      * @param    string  $relType    Relation type attribute.  Either rel or rev (default: 'rel').
  122.      * @param    array   $attributes Associative array of remaining attributes.
  123.      * @return   void 
  124.      */
  125.     function addHeadLink($href$relation$relType 'rel'$attribs array())
  126.     {
  127.         $attribs JDocumentHelper::implodeAttribs('='' '$attribs);
  128.         $generatedTag "<link href=\"$href\" $relType=\"$relation\" "$attribs;
  129.         $this->_links[$generatedTag;
  130.     }
  131.  
  132.      /**
  133.      * Adds a shortcut icon (favicon)
  134.      *
  135.      * <p>This adds a link to the icon shown in the favorites list or on
  136.      * the left of the url in the address bar. Some browsers display
  137.      * it on the tab, as well.</p>
  138.      *
  139.      * @param     string  $href        The link that is being related.
  140.      * @param     string  $type        File type
  141.      * @param     string  $relation    Relation of link
  142.      * @access    public
  143.      */
  144.     function addFavicon($href$type 'image/x-icon'$relation 'shortcut icon')
  145.     {
  146.         $href str_replace'\\''/'$href );
  147.         $this->_links['<link href="'.JURI::base().$href.'" rel="'.$relation.'" type="'.$type.'"';
  148.     }
  149.  
  150.     /**
  151.      * Adds a custom html string to the head block
  152.      *
  153.      * @param string The html to add to the head
  154.      * @access   public
  155.      * @return   void 
  156.      */
  157.  
  158.     function addCustomTag$html )
  159.     {
  160.         $this->_custom[trim$html );
  161.     }
  162.  
  163.     /**
  164.      * Get the contents of a document include
  165.      *
  166.      * @access public
  167.      * @param string     $type    The type of renderer
  168.      * @param string     $name     The name of the element to render
  169.      * @param array       $attribs Associative array of remaining attributes.
  170.      * @return     The output of the renderer
  171.      */
  172.     function getBuffer($type$name null$attribs array())
  173.     {
  174.         $result null;
  175.         if(isset($this->_buffer[$type][$name])) {
  176.             $result $this->_buffer[$type][$name];
  177.         }
  178.  
  179.         if($renderer $this->loadRenderer$type )) {
  180.             $result $renderer->render($name$attribs$result);
  181.         };
  182.  
  183.         return $result;
  184.  
  185.     }
  186.  
  187.     /**
  188.      * Set the contents a document include
  189.      *
  190.      * @access public
  191.      * @param string     $type        The type of renderer
  192.      * @param string     $name        oke The name of the element to render
  193.      * @param string     $content    The content to be set in the buffer
  194.      */
  195.     function setBuffer($contents$type$name null)
  196.     {
  197.         $this->_buffer[$type][$name$contents;
  198.     }
  199.  
  200.     /**
  201.      * Outputs the template to the browser.
  202.      *
  203.      * @access public
  204.      * @param boolean     $cache        If true, cache the output
  205.      * @param array        $params        Associative array of attributes
  206.      * @return     The rendered data
  207.      */
  208.     function render$caching false$params array())
  209.     {
  210.         // check
  211.         $directory    = isset($params['directory']$params['directory''templates';
  212.         $template    $params['template'];
  213.         $file        $params['file'];
  214.  
  215.         if !file_exists$directory.DS.$template.DS.$file) ) {
  216.             $template '_system';
  217.         }
  218.  
  219.         // Parse the template INI file if it exists for parameters and insert
  220.         // them into the template.
  221.         if (is_readable$directory.DS.$template.DS.'params.ini' ) )
  222.         {
  223.             $content file_get_contents($directory.DS.$template.DS.'params.ini');
  224.             $this->params new JParameter($content);
  225.         }
  226.  
  227.         $this->template =$template;
  228.  
  229.         // load
  230.         $data $this->_loadTemplate($directory.DS.$template$file);
  231.  
  232.         // parse
  233.         $data $this->_parseTemplate($data);
  234.  
  235.         //output
  236.         parent::render();
  237.         return $data;
  238.     }
  239.  
  240.     /**
  241.      * Count the modules based on the given condition
  242.      *
  243.      * @access public
  244.      * @param  string     $condition    The condition to use
  245.      * @return integer  Number of modules found
  246.      */
  247.     function countModules($condition)
  248.     {
  249.         $result '';
  250.  
  251.         $words explode(' '$condition);
  252.         for($i=0$i count($words)$i++)
  253.         {
  254.             if($i == 0)
  255.             {
  256.                 //odd parts (modules)
  257.                 $name strtolower($words[$i]);
  258.                 $words[$icount(JModuleHelper::getModules($name));
  259.             }
  260.         }
  261.  
  262.         $str 'return '.implode(' '$words).';';
  263.  
  264.         return eval($str);
  265.     }
  266.  
  267.     /**
  268.      * Load a template file
  269.      *
  270.      * @param string     $template    The name of the template
  271.      * @param string     $filename    The actual filename
  272.      * @return string The contents of the template
  273.      */
  274.     function _loadTemplate($directory$filename)
  275.     {
  276.         global $mainframe$option;
  277.  
  278.         if ($mainframe->getCfg('legacy'))
  279.         {
  280.             global $task$_VERSION$my$cur_template$database$acl$Itemid;
  281.  
  282.             //For backwards compatibility extract the config vars as globals
  283.             $registry =JFactory::getConfig();
  284.             foreach (get_object_vars($registry->toObject()) as $k => $v{
  285.                 $name 'mosConfig_'.$k;
  286.                 $$name $v;
  287.             }
  288.         }
  289.  
  290.         $contents '';
  291.  
  292.         //Check to see if we have a valid template file
  293.         if file_exists$directory.DS.$filename ) )
  294.         {
  295.             //store the file path
  296.             $this->_file $directory.DS.$filename;
  297.  
  298.             //get the file content
  299.             ob_start();
  300.             require_once($directory.DS.$filename );
  301.             $contents ob_get_contents();
  302.             ob_end_clean();
  303.         }
  304.  
  305.         // Try to find a favicon by checking the template and root folder
  306.         $path $directory DS;
  307.         $dirs array$pathJPATH_BASE DS );
  308.         foreach ($dirs as $dir )
  309.         {
  310.             $icon =   $dir 'favicon.ico';
  311.             if (file_exists$icon ))
  312.             {
  313.                 $path str_replaceJPATH_BASE DS''$dir );
  314.                 $path str_replace'\\''/'$path );
  315.                 $this->addFavicon$path 'favicon.ico' );
  316.                 break;
  317.             }
  318.         }
  319.  
  320.         return $contents;
  321.     }
  322.  
  323.     /**
  324.      * Parse a document template
  325.      *
  326.      * @access public
  327.      * @param string     $data        The data too parse
  328.      * @return The parsed contents of the template
  329.      */
  330.     function _parseTemplate($data)
  331.     {
  332.         $replace array();
  333.         $matches array();
  334.  
  335.         if(preg_match_all('#<jdoc:include\ type="([^"]+)" (.*)\/>#iU'$data$matches))
  336.         {
  337.             $matches[0array_reverse($matches[0]);
  338.             $matches[1array_reverse($matches[1]);
  339.             $matches[2array_reverse($matches[2]);
  340.  
  341.             $count count($matches[1]);
  342.  
  343.             for($i 0$i $count$i++)
  344.             {
  345.                 $attribs JUtility::parseAttributes$matches[2][$i);
  346.                 $type  $matches[1][$i];
  347.                 
  348.                 $name  = isset($attribs['name']$attribs['name'null;
  349.                 $replace[$i$this->getBuffer($type$name$attribs);
  350.             }
  351.  
  352.             $data str_replace($matches[0]$replace$data);
  353.         }
  354.  
  355.         return $data;
  356.     }
  357. }
  358. ?>

Documentation generated on Mon, 05 Mar 2007 21:07:00 +0000 by phpDocumentor 1.3.1