Support Joomla!

Joomla! 1.5 Documentation

Packages

Package: patTemplate

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 /pattemplate/patTemplate/Reader/IT.php

Documentation is available at IT.php

  1. <?PHP
  2. /**
  3.  * patTemplate reader that reads HTML_Template_IT files
  4.  *
  5.  * $Id: IT.php 413 2005-08-05 13:51:01Z schst $
  6.  *
  7.  * @package        patTemplate
  8.  * @subpackage    Readers
  9.  * @author        Stephan Schmidt <[email protected]>
  10.  */
  11.  
  12. // Check to ensure this file is within the rest of the framework
  13. defined('JPATH_BASE'or die();
  14.  
  15. /**
  16.  * patTemplate reader that reads HTML_Template_IT files
  17.  *
  18.  * @package        patTemplate
  19.  * @subpackage    Readers
  20.  * @author        Stephan Schmidt <[email protected]>
  21.  */
  22. {
  23.    /**
  24.     * reader name
  25.     * @access    private
  26.     * @var        string 
  27.     */
  28.     var    $_name    =    'IT';
  29.  
  30.    /**
  31.     * files that have been used
  32.     * @access    private
  33.     * @var        array 
  34.     */
  35.     var    $_files    =    array();
  36.  
  37.    /**
  38.     * parse templates from string
  39.     *
  40.     * @access    private
  41.     * @param    string        string to parse
  42.     * @return    array        templates
  43.     */
  44.     function parseString$string )
  45.     {
  46.         /**
  47.          * apply input filter before parsing
  48.          */
  49.         $string $this->_tmpl->applyInputFilters$string );
  50.  
  51.         $this->_inheritAtts    =    array();
  52.         $this->_elStack        =    array();
  53.         $this->_data        =    array'' );
  54.         $this->_tmplStack    =    array();
  55.         $this->_depth        =    0;
  56.         $this->_templates    =    array();
  57.         $this->_path        =    array();
  58.         $this->_processedData    =    '';
  59.  
  60.         $this->_defaultAtts    =    $this->_tmpl->getDefaultAttributes();
  61.  
  62.         if!isset$this->_defaultAtts['autoload') )
  63.             $this->_defaultAtts['autoload']    =    'on';
  64.  
  65.         /**
  66.          * create a special root template
  67.          */
  68.         $attributes        $this->_rootAtts;
  69.         $attributes['name']    '__global';
  70.  
  71.         $rootTemplate    $this->_initTemplate$attributes );
  72.  
  73.         array_push$this->_tmplStack$rootTemplate );
  74.  
  75.         /**
  76.          *start parsing
  77.          */
  78.         $patNamespace    =    strtolower$this->_tmpl->getNamespace() );
  79.  
  80.         $regexp    =    '/(<!-- (BEGIN|END) ([a-zA-Z]+) -->)/m';
  81.  
  82.         $tokens    =    preg_split$regexp$string-1PREG_SPLIT_DELIM_CAPTURE );
  83.  
  84.         /**
  85.          * the first token is always character data
  86.          * Though it could just be empty
  87.          */
  88.         if$tokens[0!= '' )
  89.             $this->_characterData$tokens[0);
  90.  
  91.         $cnt    =    count$tokens );
  92.         $i        =    1;
  93.         // process all tokens
  94.         while$i $cnt )
  95.         {
  96.             $fullTag    =    $tokens[$i++];
  97.             $closing    =    strtoupper$tokens[$i++== 'END' true false;
  98.             $tmplName    =    $tokens[$i++];
  99.             $namespace  =   $patNamespace;
  100.             $tagname    =    'tmpl';
  101.             $data        =    $tokens[$i++];
  102.  
  103.             /**
  104.              * is it a closing tag?
  105.              */
  106.             if$closing === true )
  107.             {
  108.                 $result    =    $this->_endElement$namespace$tagname );
  109.                 ifpatErrorManager::isError$result ) )
  110.                 {
  111.                     return    $result;
  112.                 }
  113.                 $this->_characterData$data );
  114.                 continue;
  115.             }
  116.  
  117.             $attributes    =    array'name' => $tmplName );
  118.             $result     =    $this->_startElement$namespace$tagname$attributes );
  119.             ifpatErrorManager::isError$result ) )
  120.             {
  121.                 return    $result;
  122.             }
  123.  
  124.             $this->_characterData$data );
  125.         }
  126.  
  127.         $rootTemplate array_pop$this->_tmplStack );
  128.  
  129.         $this->_closeTemplate$rootTemplate$this->_data[0);
  130.  
  131.         /**
  132.          * check for tags that are still open
  133.          */
  134.         if$this->_depth )
  135.         {
  136.             $el    =    array_pop$this->_elStack );
  137.             return patErrorManager::raiseError(
  138.                 PATTEMPLATE_READER_ERROR_NO_CLOSING_TAG,
  139.                 $this->_createErrorMessage"No closing tag for {$el['ns']}:{$el['name']} found)
  140.             );
  141.         }
  142.  
  143.         return    $this->_templates;
  144.     }
  145.  
  146.    /**
  147.     * read templates from any input
  148.     *
  149.     * @final
  150.     * @access    public
  151.     * @param    string    file to parse
  152.     * @return    array    templates
  153.     */
  154.     function readTemplates$input )
  155.     {
  156.         $this->_currentInput $input;
  157.         $fullPath    =    $this->_resolveFullPath$input );
  158.         ifpatErrorManager::isError$fullPath ) )
  159.             return $fullPath;
  160.         $content    =    $this->_getFileContents$fullPath );
  161.         ifpatErrorManager::isError$content ) )
  162.             return $content;
  163.  
  164.         $templates    =    $this->parseString$content );
  165.  
  166.         return    $templates;
  167.     }
  168.  
  169.    /**
  170.     * load template from any input
  171.     *
  172.     * If the a template is loaded, the content will not get
  173.     * analyzed but the whole content is returned as a string.
  174.     *
  175.     * @abstract    must be implemented in the template readers
  176.     * @param    mixed    input to load from.
  177.     *                     This can be a string, a filename, a resource or whatever the derived class needs to read from
  178.     * @return    string  template content
  179.     */
  180.     function loadTemplate$input )
  181.     {
  182.         $fullPath    =    $this->_resolveFullPath$input );
  183.         ifpatErrorManager::isError$fullPath ) )
  184.             return $fullPath;
  185.         return $this->_getFileContents$fullPath );
  186.     }
  187.  
  188.    /**
  189.     * resolve path for a template
  190.     *
  191.     * @access    private
  192.     * @param    string        filename
  193.     * @return    string        full path
  194.     */
  195.     function _resolveFullPath$filename )
  196.     {
  197.         $baseDir  $this->getTemplateRoot();
  198.         $fullPath $baseDir '/' $filename;
  199.         return    $fullPath;
  200.     }
  201.  
  202.    /**
  203.     * get the contents of a file
  204.     *
  205.     * @access    private
  206.     * @param    string        filename
  207.     * @return    string        file contents
  208.     */
  209.     function _getFileContents$file )
  210.     {
  211.         if!file_exists$file || !is_readable$file ) )
  212.         {
  213.             return patErrorManager::raiseError(
  214.                                         PATTEMPLATE_READER_ERROR_NO_INPUT,
  215.                                         "Could not load templates from $file."
  216.                                         );
  217.         }
  218.  
  219.         iffunction_exists'file_get_contents' ) )
  220.             $content    =    @file_get_contents$file );
  221.         else
  222.             $content    =    implode''file$file ) );
  223.  
  224.         /**
  225.          * store the file name
  226.          */
  227.         array_push$this->_files$file );
  228.  
  229.         return    $content;
  230.     }
  231. }
  232. ?>

Documentation generated on Mon, 05 Mar 2007 21:08:53 +0000 by phpDocumentor 1.3.1