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/document.php

Documentation is available at document.php

  1. <?php
  2. /**
  3. @version        $Id: document.php 6684 2007-02-19 18:53:46Z louis $
  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. /**
  19.  * Document class, provides an easy interface to parse and display a document
  20.  *
  21.  * @abstract
  22.  * @author        Johan Janssens <[email protected]>
  23.  * @package        Joomla.Framework
  24.  * @subpackage    Document
  25.  * @since        1.5
  26.  */
  27. class JDocument extends JObject
  28. {
  29.     /**
  30.      * Document title
  31.      *
  32.      * @var     string 
  33.      * @access  public
  34.      */
  35.     var $title = '';
  36.  
  37.     /**
  38.      * Document description
  39.      *
  40.      * @var     string 
  41.      * @access  public
  42.      */
  43.     var $description = '';
  44.  
  45.     /**
  46.      * Document base URL
  47.      *
  48.      * @var     string 
  49.      * @access  public
  50.      */
  51.     var $link = '';
  52.  
  53.      /**
  54.      * Contains the document language setting
  55.      *
  56.      * @var     string 
  57.      * @access  public
  58.      */
  59.     var $language = 'en';
  60.  
  61.     /**
  62.      * Contains the document direction setting
  63.      *
  64.      * @var     string 
  65.      * @access  public
  66.      */
  67.     var $direction = 'ltr';
  68.  
  69.     /**
  70.      * Document generator
  71.      *
  72.      * @var        string 
  73.      * @access    public
  74.      */
  75.      var $_generator = 'Joomla! 1.5 - Open Source Content Management';
  76.  
  77.     /**
  78.      * Document modified date
  79.      *
  80.      * @var        string 
  81.      * @access   private
  82.      */
  83.     var $_mdate '';
  84.  
  85.     /**
  86.      * Tab string
  87.      *
  88.      * @var        string 
  89.      * @access    private
  90.      */
  91.     var $_tab "\11";
  92.  
  93.     /**
  94.      * Contains the line end string
  95.      *
  96.      * @var        string 
  97.      * @access    private
  98.      */
  99.     var $_lineEnd "\12";
  100.  
  101.     /**
  102.      * Contains the character encoding string
  103.      *
  104.      * @var     string 
  105.      * @access  private
  106.      */
  107.     var $_charset 'utf-8';
  108.  
  109.     /**
  110.      * Document mime type
  111.      *
  112.      * @var        string 
  113.      * @access    private
  114.      */
  115.     var $_mime '';
  116.  
  117.     /**
  118.      * Document namespace
  119.      *
  120.      * @var        string 
  121.      * @access   private
  122.      */
  123.     var $_namespace '';
  124.  
  125.     /**
  126.      * Document profile
  127.      *
  128.      * @var        string 
  129.      * @access   private
  130.      */
  131.     var $_profile '';
  132.  
  133.     /**
  134.      * Array of linked scripts
  135.      *
  136.      * @var        array 
  137.      * @access   private
  138.      */
  139.     var $_scripts array();
  140.  
  141.     /**
  142.      * Array of scripts placed in the header
  143.      *
  144.      * @var  array 
  145.      * @access   private
  146.      */
  147.     var $_script array();
  148.  
  149.      /**
  150.      * Array of linked style sheets
  151.      *
  152.      * @var     array 
  153.      * @access  private
  154.      */
  155.     var $_styleSheets array();
  156.  
  157.     /**
  158.      * Array of included style declarations
  159.      *
  160.      * @var     array 
  161.      * @access  private
  162.      */
  163.     var $_style array();
  164.  
  165.     /**
  166.      * Array of meta tags
  167.      *
  168.      * @var     array 
  169.      * @access  private
  170.      */
  171.     var $_metaTags array();
  172.  
  173.     /**
  174.      * The rendering engine
  175.      *
  176.      * @var     object 
  177.      * @access  private
  178.      */
  179.     var $_engine null;
  180.  
  181.     /**
  182.      * The document type
  183.      *
  184.      * @var     string 
  185.      * @access  private
  186.      */
  187.     var $_type null;
  188.  
  189.     /**
  190.      * Array of buffered output
  191.      *
  192.      * @var        mixed (depends on the renderer)
  193.      * @access    private
  194.      */
  195.     var $_buffer null;
  196.  
  197.  
  198.     /**
  199.     * Class constructor
  200.     *
  201.     * @access protected
  202.     * @param    array    $options Associative array of options
  203.     */
  204.     function __construct$options array())
  205.     {
  206.         parent::__construct();
  207.  
  208.         if (isset($options['lineend'])) {
  209.             $this->setLineEnd($options['lineend']);
  210.         }
  211.  
  212.         if (isset($options['charset'])) {
  213.             $this->setCharset($options['charset']);
  214.         }
  215.  
  216.         if (isset($options['language'])) {
  217.             $this->setLanguage($options['language']);
  218.         }
  219.  
  220.          if (isset($options['direction'])) {
  221.             $this->setDirection($options['direction']);
  222.         }
  223.  
  224.         if (isset($options['tab'])) {
  225.             $this->setTab($options['tab']);
  226.         }
  227.  
  228.         if (isset($options['link'])) {
  229.             $this->setLink($options['link']);
  230.         }
  231.     }
  232.  
  233.     /**
  234.      * Returns a reference to the global JDocument object, only creating it
  235.      * if it doesn't already exist.
  236.      *
  237.      * This method must be invoked as:
  238.      *         <pre>  $document = &JDocument::getInstance();</pre>
  239.      *
  240.      * @access public
  241.      * @param type $type The document type to instantiate
  242.      * @return object  The document object.
  243.      */
  244.     function &getInstance($type 'html'$attributes array())
  245.     {
  246.         static $instances;
  247.  
  248.         if (!isset$instances )) {
  249.             $instances array();
  250.         }
  251.  
  252.         $signature serialize(array($type$attributes));
  253.  
  254.         if (empty($instances[$signature])) {
  255.             jimport('joomla.document.'.$type.'.'.$type);
  256.             $class 'JDocument'.$type;
  257.             $instances[$signaturenew $class($attributes);
  258.         }
  259.  
  260.         return $instances[$signature];
  261.     }
  262.  
  263.      /**
  264.      * Returns the document type
  265.      *
  266.      * @access    public
  267.      * @return    string 
  268.      */
  269.     function getType({
  270.         return $this->_type;
  271.     }
  272.  
  273.     /**
  274.      * Get the document head data
  275.      *
  276.      * @access    public
  277.      * @return    array    The document head data in array form
  278.      */
  279.     function getHeadData({
  280.         // Impelemented in child classes
  281.     }
  282.  
  283.     /**
  284.      * Set the document head data
  285.      *
  286.      * @access    public
  287.      * @param    array    $data    The document head data in array form
  288.      */
  289.     function setHeadData($data{
  290.         // Impelemented in child classes
  291.     }
  292.  
  293.     /**
  294.      * Get the contents of the document buffer
  295.      *
  296.      * @access public
  297.      * @return     The contents of the document buffer
  298.      */
  299.     function getBuffer({
  300.         return $this->_buffer;
  301.     }
  302.  
  303.     /**
  304.      * Set the contents of the document buffer
  305.      *
  306.      * @access public
  307.      * @param string     $content    The content to be set in the buffer
  308.      */
  309.     function setBuffer($content{
  310.         $this->_buffer $content;
  311.     }
  312.  
  313.     /**
  314.      * Gets a meta tag.
  315.      *
  316.      * @param    string    $name            Value of name or http-equiv tag
  317.      * @param    bool    $http_equiv     META type "http-equiv" defaults to null
  318.      * @return    string 
  319.      * @access    public
  320.      */
  321.     function getMetaData($name$http_equiv false)
  322.     {
  323.         $result '';
  324.         if ($http_equiv == true{
  325.             $result @$this->_metaTags['http-equiv'][$name];
  326.         else {
  327.             $result @$this->_metaTags['standard'][$name];
  328.         }
  329.         return $result;
  330.     }
  331.  
  332.     /**
  333.      * Sets or alters a meta tag.
  334.      *
  335.      * @param string  $name            Value of name or http-equiv tag
  336.      * @param string  $content        Value of the content tag
  337.      * @param bool    $http_equiv     META type "http-equiv" defaults to null
  338.      * @return void 
  339.      * @access public
  340.      */
  341.     function setMetaData($name$content$http_equiv false)
  342.     {
  343.          if ($http_equiv == true{
  344.             $this->_metaTags['http-equiv'][$name$content;
  345.         else {
  346.             $this->_metaTags['standard'][$name$content;
  347.         }
  348.     }
  349.  
  350.      /**
  351.      * Adds a linked script to the page
  352.      *
  353.      * @param    string  $url        URL to the linked script
  354.      * @param    string  $type        Type of script. Defaults to 'text/javascript'
  355.      * @access   public
  356.      */
  357.     function addScript($url$type="text/javascript"{
  358.         $this->_scripts[$url$type;
  359.     }
  360.  
  361.     /**
  362.      * Adds a script to the page
  363.      *
  364.      * @access   public
  365.      * @param    string  $content   Script
  366.      * @param    string  $type        Scripting mime (defaults to 'text/javascript')
  367.      * @return   void 
  368.      */
  369.     function addScriptDeclaration($content$type 'text/javascript'{
  370.         $this->_script[][strtolower($type)=$content;
  371.     }
  372.  
  373.     /**
  374.      * Adds a linked stylesheet to the page
  375.      *
  376.      * @param    string  $url    URL to the linked style sheet
  377.      * @param    string  $type   Mime encoding type
  378.      * @param    string  $media  Media type that this stylesheet applies to
  379.      * @access   public
  380.      */
  381.     function addStyleSheet($url$type 'text/css'$media null$attribs array())
  382.     {
  383.         $this->_styleSheets[$url]['mime']        $type;
  384.         $this->_styleSheets[$url]['media']        $media;
  385.         $this->_styleSheets[$url]['attribs']    $attribs;
  386.     }
  387.  
  388.      /**
  389.      * Adds a stylesheet declaration to the page
  390.      *
  391.      * @param    string  $content   Style declarations
  392.      * @param    string  $type        Type of stylesheet (defaults to 'text/css')
  393.      * @access   public
  394.      * @return   void 
  395.      */
  396.     function addStyleDeclaration($content$type 'text/css'{
  397.         $this->_style[][strtolower($type)$content;
  398.     }
  399.  
  400.      /**
  401.      * Sets the document charset
  402.      *
  403.      * @param   string   $type  Charset encoding string
  404.      * @access  public
  405.      * @return  void 
  406.      */
  407.     function setCharset($type 'utf-8'{
  408.         $this->_charset $type;
  409.     }
  410.  
  411.     /**
  412.      * Returns the document charset encoding.
  413.      *
  414.      * @access public
  415.      * @return string 
  416.      */
  417.     function getCharset({
  418.         return $this->_charset;
  419.     }
  420.  
  421.     /**
  422.      * Sets the global document language declaration. Default is English (en).
  423.      *
  424.      * @access public
  425.      * @param   string   $lang 
  426.      */
  427.     function setLanguage($lang "en"{
  428.         $this->language = strtolower($lang);
  429.     }
  430.  
  431.     /**
  432.      * Returns the document language.
  433.      *
  434.      * @return string 
  435.      * @access public
  436.      */
  437.     function getLanguage({
  438.         return $this->language;
  439.     }
  440.  
  441.     /**
  442.      * Sets the global document direction declaration. Default is left-to-right (ltr).
  443.      *
  444.      * @access public
  445.      * @param   string   $lang 
  446.      */
  447.     function setDirection($dir "ltr"{
  448.         $this->direction = strtolower($dir);
  449.     }
  450.  
  451.     /**
  452.      * Returns the document language.
  453.      *
  454.      * @return string 
  455.      * @access public
  456.      */
  457.     function getDirection({
  458.         return $this->direction;
  459.     }
  460.  
  461.     /**
  462.      * Sets the title of the document
  463.      *
  464.      * @param    string    $title 
  465.      * @access   public
  466.      */
  467.     function setTitle($title{
  468.         $this->title = $title;
  469.     }
  470.  
  471.     /**
  472.      * Return the title of the document.
  473.      *
  474.      * @return   string 
  475.      * @access   public
  476.      */
  477.     function getTitle({
  478.         return $this->title;
  479.     }
  480.  
  481.     /**
  482.      * Sets the description of the document
  483.      *
  484.      * @param    string    $title 
  485.      * @access   public
  486.      */
  487.     function setDescription($description{
  488.         $this->description = $description;
  489.     }
  490.  
  491.     /**
  492.      * Return the title of the page.
  493.      *
  494.      * @return   string 
  495.      * @access   public
  496.      */
  497.     function getDescription({
  498.         return $this->description;
  499.     }
  500.  
  501.      /**
  502.      * Sets the document link
  503.      *
  504.      * @param   string   $url  A url
  505.      * @access  public
  506.      * @return  void 
  507.      */
  508.     function setLink($url{
  509.         $this->link = $url;
  510.     }
  511.  
  512.     /**
  513.      * Returns the document base url
  514.      *
  515.      * @access public
  516.      * @return string 
  517.      */
  518.     function getLink({
  519.         return $this->link;
  520.     }
  521.  
  522.      /**
  523.      * Sets the document generator
  524.      *
  525.      * @param   string 
  526.      * @access  public
  527.      * @return  void 
  528.      */
  529.     function setGenerator($generator{
  530.         $this->_generator = $generator;
  531.     }
  532.  
  533.     /**
  534.      * Returns the document generator
  535.      *
  536.      * @access public
  537.      * @return string 
  538.      */
  539.     function getGenerator({
  540.         return $this->_generator;
  541.     }
  542.  
  543.      /**
  544.      * Sets the document modified date
  545.      *
  546.      * @param   string 
  547.      * @access  public
  548.      * @return  void 
  549.      */
  550.     function setModifiedDate($date{
  551.         $this->_mdate $date;
  552.     }
  553.  
  554.     /**
  555.      * Returns the document modified date
  556.      *
  557.      * @access public
  558.      * @return string 
  559.      */
  560.     function getModifiedDate({
  561.         return $this->_mdate;
  562.     }
  563.  
  564.      /**
  565.      * Sets the document MIME encoding that is sent to the browser.
  566.      *
  567.      * <p>This usually will be text/html because most browsers cannot yet
  568.      * accept the proper mime settings for XHTML: application/xhtml+xml
  569.      * and to a lesser extent application/xml and text/xml. See the W3C note
  570.      * ({@link http://www.w3.org/TR/xhtml-media-types/}
  571.      * http://www.w3.org/TR/xhtml-media-types/}) for more details.</p>
  572.      *
  573.      * @param    string    $type 
  574.      * @access   public
  575.      * @return   void 
  576.      */
  577.     function setMimeEncoding($type 'text/html'{
  578.         $this->_mime strtolower($type);
  579.     }
  580.  
  581.      /**
  582.      * Sets the line end style to Windows, Mac, Unix or a custom string.
  583.      *
  584.      * @param   string  $style  "win", "mac", "unix" or custom string.
  585.      * @access  public
  586.      * @return  void 
  587.      */
  588.     function setLineEnd($style)
  589.     {
  590.         switch ($style{
  591.             case 'win':
  592.                 $this->_lineEnd "\15\12";
  593.                 break;
  594.             case 'unix':
  595.                 $this->_lineEnd "\12";
  596.                 break;
  597.             case 'mac':
  598.                 $this->_lineEnd "\15";
  599.                 break;
  600.             default:
  601.                 $this->_lineEnd $style;
  602.         }
  603.     }
  604.  
  605.     /**
  606.      * Returns the lineEnd
  607.      *
  608.      * @access    private
  609.      * @return    string 
  610.      */
  611.     function _getLineEnd({
  612.         return $this->_lineEnd;
  613.     }
  614.  
  615.     /**
  616.      * Sets the string used to indent HTML
  617.      *
  618.      * @param     string    $string     String used to indent ("\11", "\t", '  ', etc.).
  619.      * @access    public
  620.      * @return    void 
  621.      */
  622.     function setTab($string{
  623.         $this->_tab $string;
  624.     }
  625.  
  626.      /**
  627.      * Returns a string containing the unit for indenting HTML
  628.      *
  629.      * @access    private
  630.      * @return    string 
  631.      */
  632.     function _getTab({
  633.         return $this->_tab;
  634.     }
  635.  
  636.     /**
  637.     * Load a renderer
  638.     *
  639.     * @access    public
  640.     * @param    string    The renderer type
  641.     * @return    object 
  642.     * @since 1.5
  643.     */
  644.     function loadRenderer$type )
  645.     {
  646.         if!class_exists'JDocumentRenderer' ) ) {
  647.             jimport('joomla.document.renderer');
  648.         }
  649.  
  650.         $class    =    'JDocumentRenderer_' $type;
  651.  
  652.         if!class_exists$class ) )
  653.         {
  654.             if(!file_exists(dirname(__FILE__).DS.$this->_type.DS.'renderer'.DS.$type.'.php')) {
  655.                 return null;
  656.             }
  657.             //import renderer
  658.             jimport('joomla.document.'.$this->_type.'.renderer.'.$type);
  659.         }
  660.  
  661.         if!class_exists$class ) ) {
  662.             return null;
  663.         }
  664.  
  665.         $instance new $class($this);
  666.  
  667.         return $instance;
  668.     }
  669.  
  670.     /**
  671.      * Outputs the document
  672.      *
  673.      * @access public
  674.      * @param boolean     $cache        If true, cache the output
  675.      * @param boolean     $compress    If true, compress the output
  676.      * @param array        $params        Associative array of attributes
  677.      * @return     The rendered data
  678.      */
  679.     function render$cache false$params array())
  680.     {
  681.         JResponse::setHeader'Expires'gmdate'D, d M Y H:i:s'time(900 ' GMT' );
  682.         if ($mdate $this->getModifiedDate()) {
  683.             JResponse::setHeader'Last-Modified'$mdate /* gmdate( 'D, d M Y H:i:s', time() + 900 ) . ' GMT' */ );
  684.         }
  685.         JResponse::setHeader'Cache-Control''no-store, no-cache, must-revalidate' );
  686.         JResponse::setHeader'Cache-Control''post-check=0, pre-check=0'false );    // HTTP/1.1
  687.         JResponse::setHeader'Pragma''no-cache' );                                    // HTTP/1.0
  688.         JResponse::setHeader'Content-Type'$this->_mime .  '; charset=' $this->_charset);
  689.     }
  690. }
  691.  
  692. /**
  693.  * Document helper functions
  694.  *
  695.  * @static
  696.  * @author        Johan Janssens <[email protected]>
  697.  * @package        Joomla.Framework
  698.  * @subpackage    Document
  699.  * @since        1.5
  700.  */
  701.  {
  702.     function implodeAttribs($inner_glue "="$outer_glue "\n"$array null$keepOuterKey false)
  703.     {
  704.         $output array();
  705.  
  706.         foreach($array as $key => $item)
  707.         if (is_array ($item)) {
  708.             if ($keepOuterKey)
  709.                 $output[$key;
  710.             // This is value is an array, go and do it again!
  711.             $output[JDocumentHelper::implodeAttribs($inner_glue$outer_glue$item$keepOuterKey);
  712.         else
  713.             $output[$key $inner_glue '"'.$item.'"';
  714.  
  715.         return implode($outer_glue$output);
  716.     }
  717.  }
  718. ?>

Documentation generated on Mon, 05 Mar 2007 20:56:47 +0000 by phpDocumentor 1.3.1