| 
									
										
										
										
											2015-10-24 05:02:24 +02:00
										 |  |  | <?php | 
					
						
							|  |  |  | /** | 
					
						
							|  |  |  |  * Smarty read include path plugin | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * @package    Smarty | 
					
						
							|  |  |  |  * @subpackage PluginsInternal | 
					
						
							|  |  |  |  * @author     Monte Ohrt | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /** | 
					
						
							|  |  |  |  * Smarty Internal Read Include Path Class | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * @package    Smarty | 
					
						
							|  |  |  |  * @subpackage PluginsInternal | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | class Smarty_Internal_Runtime_GetIncludePath | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     /** | 
					
						
							|  |  |  |      * include path cache | 
					
						
							|  |  |  |      * | 
					
						
							|  |  |  |      * @var string | 
					
						
							|  |  |  |      */ | 
					
						
							|  |  |  |     public $_include_path = ''; | 
					
						
							| 
									
										
										
										
											2018-08-31 16:45:09 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-10-24 05:02:24 +02:00
										 |  |  |     /** | 
					
						
							|  |  |  |      * include path directory cache | 
					
						
							|  |  |  |      * | 
					
						
							|  |  |  |      * @var array | 
					
						
							|  |  |  |      */ | 
					
						
							|  |  |  |     public $_include_dirs = array(); | 
					
						
							| 
									
										
										
										
											2018-08-31 16:45:09 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-10-24 05:02:24 +02:00
										 |  |  |     /** | 
					
						
							|  |  |  |      * include path directory cache | 
					
						
							|  |  |  |      * | 
					
						
							|  |  |  |      * @var array | 
					
						
							|  |  |  |      */ | 
					
						
							|  |  |  |     public $_user_dirs = array(); | 
					
						
							| 
									
										
										
										
											2018-08-31 16:45:09 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-10-24 05:02:24 +02:00
										 |  |  |     /** | 
					
						
							|  |  |  |      * stream cache | 
					
						
							|  |  |  |      * | 
					
						
							| 
									
										
										
										
											2017-10-26 10:25:41 +02:00
										 |  |  |      * @var string[][] | 
					
						
							| 
									
										
										
										
											2015-10-24 05:02:24 +02:00
										 |  |  |      */ | 
					
						
							|  |  |  |     public $isFile = array(); | 
					
						
							| 
									
										
										
										
											2018-08-31 16:45:09 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-10-24 05:02:24 +02:00
										 |  |  |     /** | 
					
						
							|  |  |  |      * stream cache | 
					
						
							|  |  |  |      * | 
					
						
							|  |  |  |      * @var string[] | 
					
						
							|  |  |  |      */ | 
					
						
							|  |  |  |     public $isPath = array(); | 
					
						
							| 
									
										
										
										
											2018-08-31 16:45:09 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-10-24 05:02:24 +02:00
										 |  |  |     /** | 
					
						
							|  |  |  |      * stream cache | 
					
						
							|  |  |  |      * | 
					
						
							|  |  |  |      * @var int[] | 
					
						
							|  |  |  |      */ | 
					
						
							|  |  |  |     public $number = array(); | 
					
						
							| 
									
										
										
										
											2018-08-31 16:45:09 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-10-24 05:02:24 +02:00
										 |  |  |     /** | 
					
						
							|  |  |  |      * status cache | 
					
						
							|  |  |  |      * | 
					
						
							|  |  |  |      * @var bool | 
					
						
							|  |  |  |      */ | 
					
						
							|  |  |  |     public $_has_stream_include = null; | 
					
						
							| 
									
										
										
										
											2018-08-31 16:45:09 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-10-24 05:02:24 +02:00
										 |  |  |     /** | 
					
						
							|  |  |  |      * Number for array index | 
					
						
							|  |  |  |      * | 
					
						
							|  |  |  |      * @var int | 
					
						
							|  |  |  |      */ | 
					
						
							|  |  |  |     public $counter = 0; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     /** | 
					
						
							|  |  |  |      * Check if include path was updated | 
					
						
							|  |  |  |      * | 
					
						
							|  |  |  |      * @param \Smarty $smarty | 
					
						
							|  |  |  |      * | 
					
						
							|  |  |  |      * @return bool | 
					
						
							|  |  |  |      */ | 
					
						
							|  |  |  |     public function isNewIncludePath(Smarty $smarty) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         $_i_path = get_include_path(); | 
					
						
							| 
									
										
										
										
											2017-10-26 05:27:25 +02:00
										 |  |  |         if ($this->_include_path !== $_i_path) { | 
					
						
							| 
									
										
										
										
											2015-10-24 05:02:24 +02:00
										 |  |  |             $this->_include_dirs = array(); | 
					
						
							|  |  |  |             $this->_include_path = $_i_path; | 
					
						
							| 
									
										
										
										
											2017-10-26 05:27:25 +02:00
										 |  |  |             $_dirs = (array)explode(PATH_SEPARATOR, $_i_path); | 
					
						
							| 
									
										
										
										
											2015-10-24 05:02:24 +02:00
										 |  |  |             foreach ($_dirs as $_path) { | 
					
						
							|  |  |  |                 if (is_dir($_path)) { | 
					
						
							| 
									
										
										
										
											2017-10-26 05:27:25 +02:00
										 |  |  |                     $this->_include_dirs[] = $smarty->_realpath($_path . DIRECTORY_SEPARATOR, true); | 
					
						
							| 
									
										
										
										
											2015-10-24 05:02:24 +02:00
										 |  |  |                 } | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |             return true; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |         return false; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     /** | 
					
						
							|  |  |  |      * return array with include path directories | 
					
						
							|  |  |  |      * | 
					
						
							|  |  |  |      * @param \Smarty $smarty | 
					
						
							|  |  |  |      * | 
					
						
							|  |  |  |      * @return array | 
					
						
							|  |  |  |      */ | 
					
						
							|  |  |  |     public function getIncludePathDirs(Smarty $smarty) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         $this->isNewIncludePath($smarty); | 
					
						
							|  |  |  |         return $this->_include_dirs; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     /** | 
					
						
							|  |  |  |      * Return full file path from PHP include_path | 
					
						
							|  |  |  |      * | 
					
						
							| 
									
										
										
										
											2018-06-12 09:58:15 +02:00
										 |  |  |      * @param string[] $dirs | 
					
						
							|  |  |  |      * @param string   $file | 
					
						
							|  |  |  |      * @param \Smarty  $smarty | 
					
						
							| 
									
										
										
										
											2015-10-24 05:02:24 +02:00
										 |  |  |      * | 
					
						
							|  |  |  |      * @return bool|string full filepath or false | 
					
						
							|  |  |  |      */ | 
					
						
							|  |  |  |     public function getIncludePath($dirs, $file, Smarty $smarty) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         //if (!(isset($this->_has_stream_include) ? $this->_has_stream_include : $this->_has_stream_include = false)) {
 | 
					
						
							| 
									
										
										
										
											2018-08-31 16:45:09 +02:00
										 |  |  |         if (!(isset($this->_has_stream_include) ? $this->_has_stream_include : | 
					
						
							|  |  |  |             $this->_has_stream_include = function_exists('stream_resolve_include_path')) | 
					
						
							| 
									
										
										
										
											2016-02-09 01:27:15 +01:00
										 |  |  |         ) { | 
					
						
							|  |  |  |             $this->isNewIncludePath($smarty); | 
					
						
							| 
									
										
										
										
											2015-10-24 05:02:24 +02:00
										 |  |  |         } | 
					
						
							|  |  |  |         // try PHP include_path
 | 
					
						
							|  |  |  |         foreach ($dirs as $dir) { | 
					
						
							| 
									
										
										
										
											2017-10-26 05:27:25 +02:00
										 |  |  |             $dir_n = isset($this->number[ $dir ]) ? $this->number[ $dir ] : $this->number[ $dir ] = $this->counter++; | 
					
						
							| 
									
										
										
										
											2016-02-09 01:27:15 +01:00
										 |  |  |             if (isset($this->isFile[ $dir_n ][ $file ])) { | 
					
						
							|  |  |  |                 if ($this->isFile[ $dir_n ][ $file ]) { | 
					
						
							|  |  |  |                     return $this->isFile[ $dir_n ][ $file ]; | 
					
						
							| 
									
										
										
										
											2015-10-24 05:02:24 +02:00
										 |  |  |                 } else { | 
					
						
							|  |  |  |                     continue; | 
					
						
							|  |  |  |                 } | 
					
						
							|  |  |  |             } | 
					
						
							| 
									
										
										
										
											2016-02-09 01:27:15 +01:00
										 |  |  |             if (isset($this->_user_dirs[ $dir_n ])) { | 
					
						
							|  |  |  |                 if (false === $this->_user_dirs[ $dir_n ]) { | 
					
						
							| 
									
										
										
										
											2015-10-24 05:02:24 +02:00
										 |  |  |                     continue; | 
					
						
							|  |  |  |                 } else { | 
					
						
							| 
									
										
										
										
											2016-02-09 01:27:15 +01:00
										 |  |  |                     $dir = $this->_user_dirs[ $dir_n ]; | 
					
						
							| 
									
										
										
										
											2015-10-24 05:02:24 +02:00
										 |  |  |                 } | 
					
						
							|  |  |  |             } else { | 
					
						
							| 
									
										
										
										
											2017-10-26 05:27:25 +02:00
										 |  |  |                 if ($dir[ 0 ] === '/' || $dir[ 1 ] === ':') { | 
					
						
							| 
									
										
										
										
											2015-10-24 05:02:24 +02:00
										 |  |  |                     $dir = str_ireplace(getcwd(), '.', $dir); | 
					
						
							| 
									
										
										
										
											2017-10-26 05:27:25 +02:00
										 |  |  |                     if ($dir[ 0 ] === '/' || $dir[ 1 ] === ':') { | 
					
						
							| 
									
										
										
										
											2016-02-09 01:27:15 +01:00
										 |  |  |                         $this->_user_dirs[ $dir_n ] = false; | 
					
						
							| 
									
										
										
										
											2015-10-24 05:02:24 +02:00
										 |  |  |                         continue; | 
					
						
							|  |  |  |                     } | 
					
						
							|  |  |  |                 } | 
					
						
							|  |  |  |                 $dir = substr($dir, 2); | 
					
						
							| 
									
										
										
										
											2016-02-09 01:27:15 +01:00
										 |  |  |                 $this->_user_dirs[ $dir_n ] = $dir; | 
					
						
							| 
									
										
										
										
											2015-10-24 05:02:24 +02:00
										 |  |  |             } | 
					
						
							|  |  |  |             if ($this->_has_stream_include) { | 
					
						
							|  |  |  |                 $path = stream_resolve_include_path($dir . (isset($file) ? $file : '')); | 
					
						
							|  |  |  |                 if ($path) { | 
					
						
							| 
									
										
										
										
											2016-02-09 01:27:15 +01:00
										 |  |  |                     return $this->isFile[ $dir_n ][ $file ] = $path; | 
					
						
							| 
									
										
										
										
											2015-10-24 05:02:24 +02:00
										 |  |  |                 } | 
					
						
							|  |  |  |             } else { | 
					
						
							|  |  |  |                 foreach ($this->_include_dirs as $key => $_i_path) { | 
					
						
							| 
									
										
										
										
											2016-02-09 01:27:15 +01:00
										 |  |  |                     $path = isset($this->isPath[ $key ][ $dir_n ]) ? $this->isPath[ $key ][ $dir_n ] : | 
					
						
							|  |  |  |                         $this->isPath[ $key ][ $dir_n ] = is_dir($_dir_path = $_i_path . $dir) ? $_dir_path : false; | 
					
						
							| 
									
										
										
										
											2015-10-24 05:02:24 +02:00
										 |  |  |                     if ($path === false) { | 
					
						
							|  |  |  |                         continue; | 
					
						
							|  |  |  |                     } | 
					
						
							|  |  |  |                     if (isset($file)) { | 
					
						
							| 
									
										
										
										
											2016-02-09 01:27:15 +01:00
										 |  |  |                         $_file = $this->isFile[ $dir_n ][ $file ] = (is_file($path . $file)) ? $path . $file : false; | 
					
						
							| 
									
										
										
										
											2015-10-24 05:02:24 +02:00
										 |  |  |                         if ($_file) { | 
					
						
							|  |  |  |                             return $_file; | 
					
						
							|  |  |  |                         } | 
					
						
							|  |  |  |                     } else { | 
					
						
							|  |  |  |                         // no file was given return directory path
 | 
					
						
							|  |  |  |                         return $path; | 
					
						
							|  |  |  |                     } | 
					
						
							|  |  |  |                 } | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |         return false; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | } |