Beispiel #1
0
 /**
 		Process <F3:include> directives
 			@return string
 			@param $_file string
 			@param $_path string
 			@public
 	**/
 public static function embed($_file, $_path)
 {
     if (!$_file || !file_exists($_path . $_file)) {
         return '';
     }
     $_hash = 'tpl.' . self::hashCode($_file);
     $_cached = Cache::cached($_hash);
     if ($_cached && filemtime($_path . $_file) < $_cached['time']) {
         $_text = Cache::fetch($_hash);
         // Gather template file info for profiler
         F3::$global['PROFILE']['TEMPLATES']['cache'][$_file] = $_cached['size'];
     } else {
         $_text = file_get_contents($_path . $_file);
         Cache::store($_hash, $_text);
         // Gather template file info for profiler
         F3::$global['PROFILE']['TEMPLATES']['loaded'][$_file] = filesize($_path . $_file);
     }
     $_regex = '/<(?:F3:)?include\\h*href\\h*=\\h*"([^"]+)"\\h*\\/>/i';
     // Search/replace <F3:include> regex pattern
     if (!preg_match($_regex, $_text)) {
         return $_text;
     }
     // Call recursively if included file also has <F3:include>
     return preg_replace_callback($_regex, function ($_attr) use($_path) {
         // Load file
         return F3::embed(F3::resolve($_attr[1]), $_path);
     }, $_text);
 }