示例#1
0
文件: common.php 项目: prych/prych
session();
# Set the locale for gettext.
set_locale($config->locale);
# Load the translation engine.
load_translator("chyrp", INCLUDES_DIR . "/locale/" . $config->locale . ".mo");
# Constant: PREVIEWING
# Is the user previewing a theme?
define('PREVIEWING', !ADMIN and !empty($_SESSION['theme']));
# Constant: THEME_DIR
# Absolute path to /themes/(current/previewed theme)
define('THEME_DIR', MAIN_DIR . "/themes/" . (PREVIEWING ? $_SESSION['theme'] : $config->theme));
# Constant: THEME_URL
# URL to /themes/(current/previewed theme)
define('THEME_URL', $config->chyrp_url . "/themes/" . (PREVIEWING ? $_SESSION['theme'] : $config->theme));
# Initialize the theme.
$theme = Theme::current();
# Load the Visitor.
$visitor = Visitor::current();
# Prepare the notifier.
$flash = Flash::current();
# Initiate the extensions.
init_extensions();
# Prepare the trigger class
$trigger = Trigger::current();
# Filter the visitor immediately after the Modules are initialized.
# Example usage scenario: custom auth systems (e.g. OpenID)
$trigger->filter($visitor, "visitor");
# First general-purpose trigger. There are many cases you may want to use @route_init@ instead of this, however.
$trigger->call("runtime");
# Set the content-type to the theme's "type" setting, or "text/html".
header("Content-type: " . (INDEX ? fallback($theme->type, "text/html") : "text/html") . "; charset=UTF-8");
示例#2
0
文件: Admin.php 项目: eadz/chyrp
 /**
  * Function: display
  * Renders the page.
  *
  * Parameters:
  *     $action - The template file to display, in (theme dir)/pages.
  *     $context - Context for the template.
  *     $title - The title for the page. Defaults to a camlelization of the action, e.g. foo_bar -> Foo Bar.
  */
 public function display($action, $context = array(), $title = "")
 {
     $this->displayed = true;
     fallback($title, camelize($action, true));
     $this->context = array_merge($context, $this->context);
     $trigger = Trigger::current();
     $trigger->filter($this->context, array("admin_context", "admin_context_" . str_replace("/", "_", $action)));
     # Are there any extension-added pages?
     foreach (array("write" => array(), "manage" => array("import", "export"), "settings" => array(), "extend" => array("modules", "feathers", "themes")) as $main_nav => $val) {
         ${$main_nav} = $val;
         $trigger->filter(${$main_nav}, $main_nav . "_pages");
     }
     $visitor = Visitor::current();
     $route = Route::current();
     $this->context["theme"] = Theme::current();
     $this->context["flash"] = Flash::current();
     $this->context["trigger"] = $trigger;
     $this->context["title"] = $title;
     $this->context["site"] = Config::current();
     $this->context["visitor"] = $visitor;
     $this->context["logged_in"] = logged_in();
     $this->context["route"] = $route;
     $this->context["hide_admin"] = isset($_SESSION["hide_admin"]);
     $this->context["now"] = time();
     $this->context["version"] = CHYRP_VERSION;
     $this->context["debug"] = DEBUG;
     $this->context["feathers"] = Feathers::$instances;
     $this->context["modules"] = Modules::$instances;
     $this->context["admin_theme"] = $this->admin_theme;
     $this->context["theme_url"] = Config::current()->chyrp_url . "/admin/themes/" . $this->admin_theme;
     $this->context["POST"] = $_POST;
     $this->context["GET"] = $_GET;
     $this->context["navigation"] = array();
     $show = array("write" => array($visitor->group->can("add_draft", "add_post", "add_page")), "manage" => array($visitor->group->can("view_own_draft", "view_draft", "edit_own_draft", "edit_own_post", "edit_post", "delete_own_draft", "delete_own_post", "delete_post", "add_page", "edit_page", "delete_page", "add_user", "edit_user", "delete_user", "add_group", "edit_group", "delete_group")), "settings" => array($visitor->group->can("change_settings")), "extend" => array($visitor->group->can("toggle_extensions")));
     foreach ($show as $name => &$arr) {
         $trigger->filter($arr, $name . "_nav_show");
     }
     $this->context["navigation"]["write"] = array("title" => __("Write"), "show" => in_array(true, $show["write"]), "selected" => in_array($action, $write) or match("/^write_/", $action));
     $this->context["navigation"]["manage"] = array("title" => __("Manage"), "show" => in_array(true, $show["manage"]), "selected" => in_array($action, $manage) or match(array("/^manage_/", "/^edit_/", "/^delete_/", "/^new_/"), $action));
     $this->context["navigation"]["settings"] = array("title" => __("Settings"), "show" => in_array(true, $show["settings"]), "selected" => in_array($action, $settings) or match("/_settings\$/", $action));
     $this->context["navigation"]["extend"] = array("title" => __("Extend"), "show" => in_array(true, $show["extend"]), "selected" => in_array($action, $extend));
     $this->subnav_context($route->action);
     $trigger->filter($this->context["selected"], "nav_selected");
     $this->context["sql_debug"] = SQL::current()->debug;
     $file = MAIN_DIR . "/admin/themes/%s/pages/" . $action . ".twig";
     $template = file_exists(sprintf($file, $this->admin_theme)) ? sprintf($file, $this->admin_theme) : sprintf($file, "default");
     $config = Config::current();
     if (!file_exists($template)) {
         foreach (array(MODULES_DIR => $config->enabled_modules, FEATHERS_DIR => $config->enabled_feathers) as $path => $try) {
             foreach ($try as $extension) {
                 if (file_exists($path . "/" . $extension . "/pages/admin/" . $action . ".twig")) {
                     $template = $path . "/" . $extension . "/pages/admin/" . $action . ".twig";
                 }
             }
         }
         if (!file_exists($template)) {
             error(__("Template Missing"), _f("Couldn't load template: <code>%s</code>", array($template)));
         }
     }
     # Try the theme first
     try {
         $this->theme->getTemplate($template)->display($this->context);
     } catch (Exception $t) {
         # Fallback to the default
         try {
             $this->default->getTemplate($template)->display($this->context);
         } catch (Exception $e) {
             $prettify = preg_replace("/([^:]+): (.+)/", "\\1: <code>\\2</code>", $e->getMessage());
             $trace = debug_backtrace();
             $twig = array("file" => $e->filename, "line" => $e->lineno);
             array_unshift($trace, $twig);
             error(__("Error"), $prettify, $trace);
         }
     }
 }
示例#3
0
文件: Main.php 项目: vito/chyrp-site
 /**
  * Function: display
  * Display the page.
  *
  * If "posts" is in the context and the visitor requested a feed, they will be served.
  *
  * Parameters:
  *     $file - The theme file to display.
  *     $context - The context for the file.
  *     $title - The title for the page.
  */
 public function display($file, $context = array(), $title = "")
 {
     if (is_array($file)) {
         for ($i = 0; $i < count($file); $i++) {
             $check = ($file[$i][0] == "/" or preg_match("/[a-zA-Z]:\\\\/", $file[$i])) ? $file[$i] : THEME_DIR . "/" . $file[$i];
             if (file_exists($check . ".twig") or $i + 1 == count($file)) {
                 return $this->display($file[$i], $context, $title);
             }
         }
     }
     $this->displayed = true;
     $route = Route::current();
     $trigger = Trigger::current();
     # Serve feeds.
     if ($this->feed) {
         if ($trigger->exists($route->action . "_feed")) {
             return $trigger->call($route->action . "_feed", $context);
         }
         if (isset($context["posts"])) {
             return $this->feed($context["posts"]);
         }
     }
     $this->context = array_merge($context, $this->context);
     $visitor = Visitor::current();
     $config = Config::current();
     $theme = Theme::current();
     $theme->title = $title;
     $this->context["theme"] = $theme;
     $this->context["flash"] = Flash::current();
     $this->context["trigger"] = $trigger;
     $this->context["modules"] = Modules::$instances;
     $this->context["feathers"] = Feathers::$instances;
     $this->context["title"] = $title;
     $this->context["site"] = $config;
     $this->context["visitor"] = $visitor;
     $this->context["route"] = Route::current();
     $this->context["hide_admin"] = isset($_COOKIE["hide_admin"]);
     $this->context["version"] = CHYRP_VERSION;
     $this->context["now"] = time();
     $this->context["debug"] = DEBUG;
     $this->context["POST"] = $_POST;
     $this->context["GET"] = $_GET;
     $this->context["sql_queries"] =& SQL::current()->queries;
     $this->context["visitor"]->logged_in = logged_in();
     $this->context["enabled_modules"] = array();
     foreach ($config->enabled_modules as $module) {
         $this->context["enabled_modules"][$module] = true;
     }
     $context["enabled_feathers"] = array();
     foreach ($config->enabled_feathers as $feather) {
         $this->context["enabled_feathers"][$feather] = true;
     }
     $this->context["sql_debug"] =& SQL::current()->debug;
     $trigger->filter($this->context, array("main_context", "main_context_" . str_replace("/", "_", $file)));
     $file = ($file[0] == "/" or preg_match("/[a-zA-Z]:\\\\/", $file)) ? $file : THEME_DIR . "/" . $file;
     if (!file_exists($file . ".twig")) {
         error(__("Template Missing"), _f("Couldn't load template: <code>%s</code>", array($file . ".twig")));
     }
     try {
         return $this->twig->getTemplate($file . ".twig")->display($this->context);
     } catch (Exception $e) {
         $prettify = preg_replace("/([^:]+): (.+)/", "\\1: <code>\\2</code>", $e->getMessage());
         $trace = debug_backtrace();
         $twig = array("file" => $e->filename, "line" => $e->lineno);
         array_unshift($trace, $twig);
         error(__("Error"), $prettify, $trace);
     }
 }