/** Grab file contents @return mixed @param $file string @public **/ function grab($file) { $file = F3::resolve($file); if (!ini_get('short_open_tag')) { $text = preg_replace_callback('/<\\?(?:\\s|\\s*(=))(.+?)\\?>/s', function ($tag) { return '<?php ' . ($tag[1] ? 'echo ' : '') . trim($tag[2]) . ' ?>'; }, $orig = self::getfile($file)); if (ini_get('allow_url_fopen') && ini_get('allow_url_include')) { // Stream wrap $file = 'data:text/plain,' . urlencode($text); } elseif ($text != $orig) { // Save re-tagged file in temporary folder if (!is_dir($ref = F3::ref('TEMP'))) { F3::mkdir($ref); } $temp = $ref . $_SERVER['SERVER_NAME'] . '.tpl.' . F3::hash($file); if (!is_file($temp)) { self::mutex(function () use($temp, $text) { file_put_contents($temp, $text); }); } $file = $temp; } } ob_start(); // Render $this->sandbox($file); return ob_get_clean(); }
/** Grab file contents @return mixed @param $file string @public **/ function grab($file) { $file = F3::resolve($file); ob_start(); if (!ini_get('short_open_tag')) { $text = preg_replace_callback('/<\\?(?:\\s|\\s*(=))(.+?)\\?>/s', function ($tag) { return '<?php ' . ($tag[1] ? 'echo ' : '') . trim($tag[2]) . ' ?>'; }, $orig = file_get_contents($file)); if (ini_get('allow_url_fopen') && ini_get('allow_url_include')) { // Stream wrap $file = 'data:text/plain,' . urlencode($text); } elseif ($text != $orig) { // Save re-tagged file in temporary folder if (!is_dir($ref = F3::ref('TEMP'))) { F3::mkdir($ref); } $temp = $ref . $_SERVER['SERVER_NAME'] . '.tpl.' . F3::hash($file); if (!is_file($temp)) { // Create semaphore $hash = 'sem.' . F3::hash($file); $cached = Cache::cached($hash); while ($cached) { // Locked by another process usleep(mt_rand(0, 1000)); } Cache::set($hash, TRUE); file_put_contents($temp, $text, LOCK_EX); // Remove semaphore Cache::clear($hash); } $file = $temp; } } // Render $this->sandbox($file); return ob_get_clean(); }