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

Documentation is available at File.php

  1. <?PHP
  2. /**
  3.  * patTemplate Reader that reads from a file
  4.  *
  5.  * $Id: File.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 from a file
  17.  *
  18.  * $Id: File.php 413 2005-08-05 13:51:01Z schst $
  19.  *
  20.  * @package        patTemplate
  21.  * @subpackage    Readers
  22.  * @author        Stephan Schmidt <[email protected]>
  23.  */
  24. {
  25.    /**
  26.     * reader name
  27.     * @access    private
  28.     * @var        string 
  29.     */
  30.     var    $_name    =    'File';
  31.  
  32.    /**
  33.     * flag to indicate, that current file is remote
  34.     *
  35.     * @access    private
  36.     * @var        boolean 
  37.     */
  38.     var $_isRemote false;
  39.  
  40.    /**
  41.     * all files, that have been opened
  42.     *
  43.     * @access    private
  44.     * @var        array 
  45.     */
  46.     var $_files array();
  47.  
  48.    /**
  49.     * read templates from any input
  50.     *
  51.     * @final
  52.     * @access    public
  53.     * @param    string    file to parse
  54.     * @return    array    templates
  55.     */
  56.     function readTemplates$input )
  57.     {
  58.         if (isset($this->_rootAtts['relative'])) {
  59.             $relative $this->_rootAtts['relative'];
  60.         else {
  61.             $relative false;
  62.         }
  63.         if ($relative === false{
  64.                $this->_currentInput $input;
  65.         else {
  66.             $this->_currentInput dirname($relativeDIRECTORY_SEPARATOR $input;
  67.         }
  68.  
  69.         $fullPath $this->_resolveFullPath($input$relative);
  70.         if (patErrorManager::isError($fullPath)) {
  71.             return $fullPath;
  72.         }
  73.         $content $this->_getFileContents($fullPath);
  74.         if (patErrorManager::isError($content)) {
  75.             return $content;
  76.         }
  77.  
  78.         $templates $this->parseString($content);
  79.  
  80.         return    $templates;
  81.     }
  82.  
  83.    /**
  84.     * load template from any input
  85.     *
  86.     * If the a template is loaded, the content will not get
  87.     * analyzed but the whole content is returned as a string.
  88.     *
  89.     * @abstract    must be implemented in the template readers
  90.     * @param    mixed    input to load from.
  91.     *                     This can be a string, a filename, a resource or whatever the derived class needs to read from
  92.     * @return    string  template content
  93.     */
  94.     function loadTemplate$input )
  95.     {
  96.         if (isset($this->_rootAtts['relative'])) {
  97.             $relative $this->_rootAtts['relative'];
  98.         else {
  99.             $relative false;
  100.         }
  101.         $fullPath    =    $this->_resolveFullPath$input$relative );
  102.         ifpatErrorManager::isError$fullPath ) )
  103.             return $fullPath;
  104.         return $this->_getFileContents$fullPath );
  105.     }
  106.  
  107.    /**
  108.     * resolve path for a template
  109.     *
  110.     * @access    private
  111.     * @param    string            filename
  112.     * @param    boolean|string filename for relative path calculation
  113.     * @return    string            full path
  114.     */
  115.     function _resolveFullPath$filename$relativeTo false )
  116.     {
  117.         if (preg_match'/^[a-z]+:\/\//'$filename )) {
  118.             $this->_isRemote true;
  119.             return $filename;
  120.         else {
  121.             $rootFolders $this->getTemplateRoot();
  122.             if (!is_array($rootFolders)) {
  123.                 $rootFolders array($rootFolders);
  124.             }
  125.             foreach ($rootFolders as $root{
  126.                 if ($relativeTo === false{
  127.                     $baseDir $root;
  128.                 else {
  129.                     $baseDir $root DIRECTORY_SEPARATOR dirname($relativeTo);
  130.                 }
  131.                 $fullPath $baseDir DIRECTORY_SEPARATOR $filename;
  132.                 if (file_exists($fullPath)) {
  133.                     return $fullPath;
  134.                 }
  135.             }
  136.         }
  137.         return patErrorManager::raiseError(
  138.                                     PATTEMPLATE_READER_ERROR_NO_INPUT,
  139.                                     "Could not load templates from $filename."
  140.                                     );
  141.     }
  142.  
  143.    /**
  144.     * get the contents of a file
  145.     *
  146.     * @access    private
  147.     * @param    string        filename
  148.     * @return    string        file contents
  149.     */
  150.     function _getFileContents$file )
  151.     {
  152.         if (!$this->_isRemote && (!file_exists($file|| !is_readable($file))) {
  153.             return patErrorManager::raiseError(
  154.                                         PATTEMPLATE_READER_ERROR_NO_INPUT,
  155.                                         "Could not load templates from $file."
  156.                                         );
  157.         }
  158.  
  159.         if (function_exists('file_get_contents')) {
  160.             $content @file_get_contents$file );
  161.         else {
  162.             $content implode(''file($file));
  163.         }
  164.  
  165.         /**
  166.          * store the file name
  167.          */
  168.         array_push($this->_files$file);
  169.  
  170.         return $content;
  171.     }
  172. }
  173. ?>

Documentation generated on Mon, 05 Mar 2007 20:58:35 +0000 by phpDocumentor 1.3.1