private function buildLoginForm() { /* * Ajax, CLI or File content can't be requested by this controller. * This controller only provides an HTML form. */ if (Runtime::$SYSTEM["REQUEST_CONTENT"] == "page") { /* * Do not show a form if we are already logged-in */ if (!Auth::isLoggedIn()) { /* * Create a token for the form. * Not much protection, but we don't have to make it easy. */ Runtime::$SESSION["_im_login_token"] = Crypt::encode(Crypt::password()); /* * Assemble variables for our HTML form template */ $args = ["formRedirect" => Runtime::$SYSTEM["URI_LOCATION"] == "/login" ? Path::link("/?") : Path::link(), "formAction" => Path::link("/login?action=login"), "formJSAction" => Path::link('/login?action=login&$$=json'), "formToken" => Runtime::$SESSION["_im_login_token"], "pageTitle" => "Login", "pageHeadline" => "Authorization Required"]; /* * Load the form template */ $this->imLoadContent("view/loginForm.inc", $args); } else { /* * Already logged-in, send user away */ Router::request("/"); } } else { Router::request("ROUTER_404"); } }
/** * Load a content file to build html, css, javascript etc. * * This will load a content file and sent output to the client, * or return it if requested. This should always be used to load content, * mostly because it might provide additional features in the future. * * File path is resolved using `Path::toAbsolute`, which means that this method has all of the benefits * of that tool. * * If $__im_from is not defined, the location will be resolved relative to the location of * the extending from this. * * @param string $__im_path * A file path that can be resolved via `Path::toAbsolute` * * @param array $__im_values=null * An array of data where keys will be converted to variables * * @param string $__im_from=null * An optional path that $__im_path will be resolved relative to * * @param bool $__im_return=false * If true, output will be returned instead of sent to the client */ public function imLoadContent(string $__im_path, array $__im_values = null, string $__im_from = null, bool $__im_return = false) { if ($this->mImObjectInfo === null) { $__im_reflect = new ReflectionObject($this); $__im_object_file = $__im_reflect->getFileName(); if ($__im_object_file !== false) { $this->mImObjectInfo = ["DIRECTORY" => dirname($__im_object_file)]; } } ob_start(); $__im_path = Path::toAbsolute($__im_path, $__im_from ?? $this->mImObjectInfo["DIRECTORY"] ?? null); $this->mImLoadingValues[] = $__im_values; foreach ($this->mImLoadingValues as $__im_pos => &$__im_cache) { if ($__im_cache != null) { foreach ($__im_cache as $__im_key => &$__im_value) { ${$__im_key} =& $this->mImLoadingValues[$__im_pos][$__im_key]; } } } include $__im_path; array_pop($this->mImLoadingValues); if ($__im_return) { return ob_get_clean(); } else { ob_end_flush(); } return null; }
/** * Import a stack of files * * @api * * @param array $stack * Indexed array containing all files to be included * * @param string $parent=null * Optional path to be used when resolving relative paths * * @return int * The number of files that was included, already included files was skipped */ public static function importStack(array $stack, string $parent = null) : int { $offset = -1; $count = 0; foreach ($stack as $file) { $file = Path::toAbsolute($file, $parent); $type = substr($file, strrpos($file, ".") + 1); if ($type == "css") { $cache =& static::$mImportedStyle; } else { $cache =& static::$mImportedScript; } if (($pos = array_search($file, $cache)) !== false) { $offset = $pos + 1; } else { if ($offset >= 0) { array_splice($cache, $offset, 0, $file); $pos++; } else { array_unshift($cache, $file); $offset = 1; } $count++; } } return $count; }