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