/** * Display method * * @access public */ public function display() { $application = \Skeleton\Core\Application::get(); $module_path = $application->module_path; $files = $this->recursive_scan($module_path); $modules = []; foreach ($files as $file) { require_once $file; $module_name = str_replace($module_path, '', $file); $module_name = str_replace('.php', '', $module_name); if ($module_name[0] == '/') { $module_name = substr($module_name, 1); } $module_name = str_replace('/', '_', $module_name); $classname = '\\Web_Module_' . $module_name; if (class_exists($classname)) { $module = new $classname(); if (is_a($module, '\\Skeleton\\Package\\Api\\Web\\Module\\Call')) { $modules[] = $module; } } } $template = \Skeleton\Core\Web\Template::get(); $template->assign('modules', $modules); }
/** * Can this handler run? * * @return bool */ public function can_run() { // This handler can only run when we have an application defined if (class_exists('\\Skeleton\\Core\\Application') === false) { return false; } try { \Skeleton\Core\Application::get(); return true; } catch (\Exception $e) { } return false; }
/** * Produce a subject based on the error * * @param \Exception $exception * @return string */ public static function get_subject(\Exception $exception) { $application = null; try { $application = \Skeleton\Core\Application::get(); } catch (\Exception $e) { } if ($application === null) { $hostname = 'unknown'; $name = 'unknown'; } else { $hostname = $application->hostname; $name = $application->name; } if ($exception instanceof \ErrorException) { $subject = get_class($exception) . ' (' . \Skeleton\Error\Util\Misc::translate_error_code($exception->getSeverity()) . ') on ' . $hostname . ' (' . $name . ')'; } else { $subject = get_class($exception) . ' on ' . $hostname . ' (' . $name . ')'; } return $subject; }
/** * Find out how we should refer to the current page * * @access private * @return string $uri */ private static function find_page_uri() { // We need to remove the base_uri from the link, because it will get // rewritten afterwards. If we leave it, it will be prepended again, // which makes the link invalid. if (class_exists('\\Skeleton\\Core\\Application')) { $application = \Skeleton\Core\Application::get(); } $request_uri = str_replace('?' . $_SERVER['QUERY_STRING'], '', $_SERVER['REQUEST_URI']); if (isset($application->config->base_uri) and strpos($request_uri, $application->config->base_uri) === 0) { $url = substr($request_uri, strlen($application->config->base_uri) - 1); } else { $url = $request_uri; } return $url; }
/** * Fetch the contents and mtime of a file * * @access private * @param string $type * @param string $path * @param string $extension * @return mixed $content Returns a string with the content, false if it * couldn't be found or null if it shouldn't be handled by us anyway */ private static function fetch($type, $path, $extension) { $packages = \Skeleton\Core\Package::get_all(); foreach (self::$filetypes as $filetype => $extensions) { $filepaths = [\Skeleton\Core\Config::$asset_dir . '/' . $path, Application::get()->media_path . '/' . $filetype . '/' . $path]; foreach ($packages as $package) { $path_parts = explode('/', $path); if (!isset($path_parts[0]) or $path_parts[0] != $package->name) { continue; } unset($path_parts[0]); $package_path = $package->asset_path . '/' . $filetype . '/' . implode('/', $path_parts); $filepaths[] = $package_path; } if (in_array($extension, $extensions)) { foreach ($filepaths as $filepath) { if (file_exists($filepath)) { if ($type == 'mtime') { return filemtime($filepath); } else { return file_get_contents($filepath); } } } return false; } } return null; }
/** * Get the requested module * * @param string Module name * @access public * @return Web_Module Requested module * @throws Exception */ public static function get($request_relative_uri) { $application = \Skeleton\Core\Application::get(); $relative_uri_parts = array_values(array_filter(explode('/', $request_relative_uri))); $filename = trim($request_relative_uri, '/'); if (file_exists($application->module_path . '/' . $filename . '.php')) { require $application->module_path . '/' . $filename . '.php'; $classname = 'Web_Module_' . implode('_', $relative_uri_parts); } elseif (file_exists($application->module_path . '/' . $filename . '/' . $application->config->module_default . '.php')) { require $application->module_path . '/' . $filename . '/' . $application->config->module_default . '.php'; if ($filename == '') { $classname = 'Web_Module_' . $application->config->module_default; } else { $classname = 'Web_Module_' . implode('_', $relative_uri_parts) . '_' . $application->config->module_default; } } elseif (file_exists($application->module_path . '/' . $application->config->module_404 . '.php')) { require $application->module_path . '/' . $application->config->module_404 . '.php'; $classname = 'Web_Module_' . $application->config->module_404; } else { throw new \Exception('Module not found'); } return new $classname(); }