/** Initiate OpenID authentication sequence @return bool @public **/ function auth() { $root = self::$vars['PROTOCOL'] . '://' . $_SERVER['SERVER_NAME']; if (!isset($this->trust_root)) { $this->trust_root = $root . (self::$vars['BASE'] ?: '/'); } if (!isset($this->return_to)) { $this->return_to = $root . $_SERVER['REQUEST_URI']; } $this->mode = 'checkid_setup'; if (isset($this->provider)) { // OpenID 2.0 $op = $this->provider; if (!isset($this->claimed_id)) { $this->claimed_id = $this->identity; } } elseif (isset($this->server)) { // OpenID 1.1 $op = $this->server; } else { return FALSE; } $var = array(); foreach ($this->args as $key => $val) { $var['openid.' . $key] = $val; } $fw = new F3instance(); $fw->reroute($op . '?' . http_build_query($var)); }
/** Retrieve contents of flat-file @return mixed @param $file string @public **/ function read($file) { if (!is_file($this->path . $file)) { return array(); } if ($this->format == self::FORMAT_Plain) { $instance = new F3instance(); return $instance->sandbox($this->path . $file); } else { $contents = file_get_contents($this->path . $file); if ($this->format == self::FORMAT_Serialized) { return unserialize($contents); } else { return json_decode($contents, TRUE); } } }
/** Render template @return string @param $file string @param $mime string @param $globals boolean @public **/ static function serve($file, $mime = 'text/html', $globals = TRUE) { $file = self::resolve($file); $found = FALSE; foreach (preg_split('/[\\|;,]/', self::$vars['GUI'], 0, PREG_SPLIT_NO_EMPTY) as $gui) { if (is_file($view = self::fixslashes($gui . $file))) { $found = TRUE; break; } } if (!$found) { trigger_error(sprintf(self::TEXT_Render, $file)); return ''; } if (PHP_SAPI != 'cli' && !headers_sent()) { // Send HTTP header with appropriate character set header(self::HTTP_Content . ': ' . $mime . '; ' . 'charset=' . self::$vars['ENCODING']); } $hash = 'tpl.' . self::hash($view); $cached = Cache::cached($hash); if ($cached && filemtime($view) < $cached) { if (self::$vars['CACHE']) { // Retrieve PHP-compiled template from cache $text = Cache::get($hash); } } else { // Parse raw template $doc = new F3markup($mime, $globals); $text = $doc->load(self::getfile($view)); if (self::$vars['CACHE'] && $doc->cache) { // Save PHP-compiled template to cache Cache::set($hash, $text); } } // Render in a sandbox $instance = new F3instance(); ob_start(); if (ini_get('allow_url_fopen') && ini_get('allow_url_include')) { // Stream wrap $instance->sandbox('data:text/plain,' . urlencode($text)); } else { // Save PHP-equivalent file in temporary folder if (!is_dir(self::$vars['TEMP'])) { self::mkdir(self::$vars['TEMP']); } $temp = self::$vars['TEMP'] . $_SERVER['SERVER_NAME'] . '.' . $hash; if (!$cached || !is_file($temp) || filemtime($temp) < Cache::cached($view)) { // Create semaphore $hash = 'sem.' . self::hash($view); $cached = Cache::cached($hash); while ($cached) { // Locked by another process usleep(mt_rand(0, 100)); } Cache::set($hash, TRUE); self::putfile($temp, $text); // Remove semaphore Cache::clear($hash); } $instance->sandbox($temp); } $out = ob_get_clean(); unset($instance); return self::$vars['TIDY'] ? self::tidy($out) : $out; }
/** Retrieve contents of flat-file @return mixed @param $file string @public **/ function read($file) { $file = $this->path . $file; if (!is_file($file)) { return array(); } $text = self::getfile($file); $out = ''; switch ($this->format) { case self::FORMAT_GZip: $text = gzinflate($text); case self::FORMAT_Plain: if (ini_get('allow_url_fopen') && ini_get('allow_url_include')) { // Stream wrap $file = 'data:text/plain,' . urlencode($text); } else { $file = self::$vars['TEMP'] . $_SERVER['SERVER_NAME'] . '.' . 'php.' . self::hash($file); self::putfile($file, $text); } $instance = new F3instance(); $out = $instance->sandbox($file); break; case self::FORMAT_Serialized: $out = unserialize($text); break; case self::FORMAT_JSON: $out = json_decode($text, TRUE); } return $out; }
/** Intercept instantiation of objects in undefined classes @param $class string @public **/ static function autoload($class) { foreach (self::split(self::$vars['PLUGINS'] . ';' . self::$vars['AUTOLOAD']) as $auto) { $ns = ''; $iter = ltrim($class, '\\'); for (;;) { if ($glob = glob($auto . self::fixslashes($ns) . '*')) { $grep = preg_grep('/^' . preg_quote($auto, '/') . implode('[\\/\\.]', explode('\\', $ns . $iter)) . '(?:\\.class)?\\.php/i', $glob); if ($file = current($grep)) { unset($grep); $instance = new F3instance(); $instance->sandbox($file); // Verify that the class was loaded if (class_exists($class, FALSE)) { // Run onLoad event handler if defined self::loadstatic($class); return; } elseif (interface_exists($class, FALSE)) { return; } } $parts = explode('\\', $iter, 2); if (count($parts) > 1) { $iter = $parts[1]; $grep = preg_grep('/^' . preg_quote($auto . self::fixslashes($ns) . $parts[0], '/') . '$/i', $glob); if ($file = current($grep)) { $ns = str_replace('/', '\\', preg_replace('/^' . preg_quote($auto, '/') . '/', '', $file)) . '\\'; continue; } $ns .= $parts[0] . '\\'; } } break; } } if (count(spl_autoload_functions()) == 1) { // No other registered autoload functions exist trigger_error(sprintf(self::TEXT_Class, $class)); } }
/** Intercept instantiation of objects in undefined classes @param $class string @public **/ static function autoload($class) { $list = array_map('self::fixslashes', get_included_files()); // Support both namespace mapping styles: NS_class and NS/class foreach (array(str_replace('\\', '_', $class), $class) as $style) { // Prioritize plugins foreach (self::split(self::$vars['PLUGINS'] . ';' . self::$vars['AUTOLOAD']) as $auto) { $path = self::fixslashes(realpath($auto)); if (!$path) { continue; } $file = self::fixslashes($style) . '.php'; if (is_int(strpos($file, '/'))) { $ok = FALSE; // Case-insensitive check for folders foreach (explode('/', self::fixslashes(dirname($file))) as $dir) { foreach (glob($path . '/*') as $found) { $found = self::fixslashes($found); if (strtolower($path . '/' . $dir) == strtolower($found)) { $path = $found; $ok = TRUE; } } } if (!$ok) { continue; } $file = basename($file); } $glob = glob($path . '/*.php', GLOB_NOSORT); if ($glob) { $glob = array_map('self::fixslashes', $glob); // Case-insensitive check for file presence $fkey = array_search(strtolower($path . '/' . $file), array_map('strtolower', $glob)); if (is_int($fkey) && !in_array($glob[$fkey], $list)) { $instance = new F3instance(); $instance->sandbox($glob[$fkey]); // Verify that the class was loaded if (class_exists($class, FALSE)) { // Run onLoad event handler if defined self::loadstatic($class); return; } } } } } if (count(spl_autoload_functions()) == 1) { // No other registered autoload functions exist trigger_error(sprintf(self::TEXT_Class, $class)); } }