(.+)<\/code>/se", "/(.+)<\/pre>/se"),
array("''.fix('\\1').'
'", "''.fix('\\1').'
'"),
$info["description"]);
$info["author"]["link"] = !empty($info["author"]["url"]) ?
''.fix($info["author"]["name"]).'' :
$info["author"]["name"] ;
$category = (module_enabled($folder)) ? "enabled_modules" : "disabled_modules" ;
$this->context[$category][$folder] = array("name" => $info["name"],
"version" => $info["version"],
"url" => $info["url"],
"description" => $info["description"],
"author" => $info["author"],
"help" => $info["help"],
"classes" => $classes[$folder],
"dependencies_needed" => $dependencies_needed);
}
foreach ($this->context["enabled_modules"] as $module => &$attrs)
$attrs["classes"] = $classes[$module];
foreach ($this->context["disabled_modules"] as $module => &$attrs)
$attrs["classes"] = $classes[$module];
$this->display("modules");
}
/**
* Function: feathers
* Feather enabling/disabling.
*/
public function feathers() {
if (!Visitor::current()->group->can("toggle_extensions"))
show_403(__("Access Denied"), __("You do not have sufficient privileges to enable/disable feathers."));
$config = Config::current();
$this->context["enabled_feathers"] = $this->context["disabled_feathers"] = array();
if (!$open = @opendir(FEATHERS_DIR))
return Flash::warning(__("Could not read feathers directory."));
while (($folder = readdir($open)) !== false) {
if (!file_exists(FEATHERS_DIR."/".$folder."/".$folder.".php") or !file_exists(FEATHERS_DIR."/".$folder."/info.yaml")) continue;
if (file_exists(FEATHERS_DIR."/".$folder."/locale/".$config->locale.".mo"))
load_translator($folder, FEATHERS_DIR."/".$folder."/locale/".$config->locale.".mo");
$info = YAML::load(FEATHERS_DIR."/".$folder."/info.yaml");
fallback($info["name"], $folder);
fallback($info["version"], "0");
fallback($info["url"]);
fallback($info["description"]);
fallback($info["author"], array("name" => "", "url" => ""));
fallback($info["help"]);
$info["description"] = __($info["description"], $folder);
$info["description"] = preg_replace("/(.+)<\/code>/se", "''.fix('\\1').'
'", $info["description"]);
$info["description"] = preg_replace("/(.+)<\/pre>/se", "''.fix('\\1').'
'", $info["description"]);
$info["author"]["link"] = !empty($info["author"]["url"]) ?
''.fix($info["author"]["name"]).'' :
$info["author"]["name"] ;
$category = (feather_enabled($folder)) ? "enabled_feathers" : "disabled_feathers" ;
$this->context[$category][$folder] = array("name" => $info["name"],
"version" => $info["version"],
"url" => $info["url"],
"description" => $info["description"],
"author" => $info["author"],
"help" => $info["help"]);
}
$this->display("feathers");
}
/**
* Function: themes
* Theme switching/previewing.
*/
public function themes() {
$config = Config::current();
$this->context["preview"] = !empty($_SESSION['theme']) ? $_SESSION['theme'] : "" ;
$this->context["themes"] = array();
if (!$open = @opendir(THEMES_DIR))
return Flash::warning(__("Could not read themes directory."));
while (($folder = readdir($open)) !== false) {
if (!file_exists(THEMES_DIR."/".$folder."/info.yaml"))
continue;
if (file_exists(THEMES_DIR."/".$folder."/locale/".$config->locale.".mo"))
load_translator($folder, THEMES_DIR."/".$folder."/locale/".$config->locale.".mo");
$info = YAML::load(THEMES_DIR."/".$folder."/info.yaml");
fallback($info["name"], $folder);
fallback($info["version"], "0");
fallback($info["url"]);
fallback($info["description"]);
fallback($info["author"], array("name" => "", "url" => ""));
$info["author"]["link"] = !empty($info["author"]["url"]) ?
''.$info["author"]["name"].'' :
$info["author"]["name"] ;
$info["description"] = preg_replace("/(.+)<\/code>/se",
"''.fix('\\1').'
'",
$info["description"]);
$info["description"] = preg_replace("/(.+)<\/pre>/se",
"''.fix('\\1').'
'",
$info["description"]);
$this->context["themes"][] = array("name" => $folder,
"screenshot" => (file_exists(THEMES_DIR."/".$folder."/screenshot.png") ?
$config->chyrp_url."/themes/".$folder."/screenshot.png" :
""),
"info" => $info);
}
if (!$open = @opendir(ADMIN_THEMES_DIR))
return Flash::warning(__("Could not read themes directory."));
while (($folder = readdir($open)) !== false) {
if (!file_exists(ADMIN_THEMES_DIR."/".$folder."/info.yaml"))
continue;
if (file_exists(ADMIN_THEMES_DIR."/".$folder."/locale/".$config->locale.".mo"))
load_translator($folder, ADMIN_THEMES_DIR."/".$folder."/locale/".$config->locale.".mo");
$info = YAML::load(ADMIN_THEMES_DIR."/".$folder."/info.yaml");
fallback($info["name"], $folder);
fallback($info["version"], "0");
fallback($info["url"]);
fallback($info["description"]);
fallback($info["author"], array("name" => "", "url" => ""));
$info["author"]["link"] = !empty($info["author"]["url"]) ?
''.$info["author"]["name"].'' :
$info["author"]["name"] ;
$info["description"] = preg_replace("/(.+)<\/code>/se",
"''.fix('\\1').'
'",
$info["description"]);
$info["description"] = preg_replace("/(.+)<\/pre>/se",
"''.fix('\\1').'
'",
$info["description"]);
$this->context["admin_themes"][] = array("name" => $folder,
"screenshot" => (file_exists(ADMIN_THEMES_DIR."/".$folder."/screenshot.png") ?
$config->chyrp_url."/admin/themes/".$folder."/screenshot.png" :
""),
"info" => $info);
}
closedir($open);
$this->display("themes");
}
/**
* Function: enable
* Enables a module or feather.
*/
public function enable() {
$config = Config::current();
$visitor = Visitor::current();
$type = (isset($_GET['module'])) ? "module" : "feather" ;
if (!$visitor->group->can("toggle_extensions"))
if ($type == "module")
show_403(__("Access Denied"), __("You do not have sufficient privileges to enable/disable modules."));
else
show_403(__("Access Denied"), __("You do not have sufficient privileges to enable/disable feathers."));
if ($type == "module" and module_enabled($_GET[$type]))
Flash::warning(__("Module already enabled."), "/admin/?action=modules");
if ($type == "feather" and feather_enabled($_GET[$type]))
Flash::warning(__("Feather already enabled."), "/admin/?action=feathers");
$enabled_array = ($type == "module") ? "enabled_modules" : "enabled_feathers" ;
$folder = ($type == "module") ? MODULES_DIR : FEATHERS_DIR ;
require $folder."/".$_GET[$type]."/".$_GET[$type].".php";
$class_name = camelize($_GET[$type]);
if ($type == "module" and !is_subclass_of($class_name, "Modules"))
Flash::warning(__("Item is not a module."), "/admin/?action=modules");
if ($type == "feather" and !is_subclass_of($class_name, "Feathers"))
Flash::warning(__("Item is not a feather."), "/admin/?action=feathers");
if (method_exists($class_name, "__install"))
call_user_func(array($class_name, "__install"));
$new = $config->$enabled_array;
array_push($new, $_GET[$type]);
$config->set($enabled_array, $new);
if (file_exists($folder."/".$_GET[$type]."/locale/".$config->locale.".mo"))
load_translator($_GET[$type], $folder."/".$_GET[$type]."/locale/".$config->locale.".mo");
$info = YAML::load($folder."/".$_GET[$type]."/info.yaml");
fallback($info["uploader"], false);
fallback($info["notifications"], array());
foreach ($info["notifications"] as &$notification)
$notification = __($notification, $_GET[$type]);
if ($info["uploader"])
if (!file_exists(MAIN_DIR.$config->uploads_path))
$info["notifications"][] = _f("Please create the %s
directory at your Chyrp install's root and CHMOD it to 777.", array($config->uploads_path));
elseif (!is_writable(MAIN_DIR.$config->uploads_path))
$info["notifications"][] = _f("Please CHMOD %s
to 777.", array($config->uploads_path));
foreach ($info["notifications"] as $message)
Flash::message($message);
if ($type == "module")
Flash::notice(_f("“%s” module enabled.",
array($info["name"])),
"/admin/?action=".pluralize($type));
elseif ($type == "feather")
Flash::notice(_f("“%s” feather enabled.",
array($info["name"])),
"/admin/?action=".pluralize($type));
}
/**
* Function: disable
* Disables a module or feather.
*/
public function disable() {
$config = Config::current();
$visitor = Visitor::current();
$type = (isset($_GET['module'])) ? "module" : "feather" ;
if (!$visitor->group->can("toggle_extensions"))
if ($type == "module")
show_403(__("Access Denied"), __("You do not have sufficient privileges to enable/disable modules."));
else
show_403(__("Access Denied"), __("You do not have sufficient privileges to enable/disable feathers."));
if ($type == "module" and !module_enabled($_GET[$type]))
Flash::warning(__("Module already disabled."), "/admin/?action=modules");
if ($type == "feather" and !feather_enabled($_GET[$type]))
Flash::warning(__("Feather already disabled."), "/admin/?action=feathers");
$enabled_array = ($type == "module") ? "enabled_modules" : "enabled_feathers" ;
$folder = ($type == "module") ? MODULES_DIR : FEATHERS_DIR ;
$class_name = camelize($_GET[$type]);
if (method_exists($class_name, "__uninstall"))
call_user_func(array($class_name, "__uninstall"), false);
$config->set(($type == "module" ? "enabled_modules" : "enabled_feathers"),
array_diff($config->$enabled_array, array($_GET[$type])));
$info = YAML::load($folder."/".$_GET[$type]."/info.yaml");
if ($type == "module")
Flash::notice(_f("“%s” module disabled.",
array($info["name"])),
"/admin/?action=".pluralize($type));
elseif ($type == "feather")
Flash::notice(_f("“%s” feather disabled.",
array($info["name"])),
"/admin/?action=".pluralize($type));
}
/**
* Function: change_theme
* Changes the theme.
*/
public function change_theme() {
if (!Visitor::current()->group->can("change_settings"))
show_403(__("Access Denied"), __("You do not have sufficient privileges to change settings."));
if (empty($_GET['theme']))
error(__("No Theme Specified"), __("You did not specify a theme to switch to."));
$config = Config::current();
$config->set("theme", $_GET['theme']);
if (file_exists(THEMES_DIR."/".$_GET['theme']."/locale/".$config->locale.".mo"))
load_translator($_GET['theme'], THEMES_DIR."/".$_GET['theme']."/locale/".$config->locale.".mo");
$info = YAML::load(THEMES_DIR."/".$_GET['theme']."/info.yaml");
fallback($info["notifications"], array());
foreach ($info["notifications"] as &$notification)
$notification = __($notification, $_GET['theme']);
foreach ($info["notifications"] as $message)
Flash::message($message);
# Clear the caches made by the previous theme.
foreach ((array) glob(INCLUDES_DIR."/caches/*.cache") as $cache)
@unlink($cache);
Flash::notice(_f("Theme changed to “%s”.", array($info["name"])), "/admin/?action=themes");
}
/**
* Function: theme
* Changes the admin theme.
*/
public function change_admin_theme() {
if (empty($_GET['theme']))
error(__("No Theme Specified"), __("You did not specify a theme to switch to."));
$config = Config::current();
$_SESSION['admin_theme'] = $_GET['theme'];
if (file_exists(ADMIN_THEMES_DIR."/".$_GET['theme']."/locale/".$config->locale.".mo"))
load_translator($_GET['theme'], ADMIN_THEMES_DIR."/".$_GET['theme']."/locale/".$config->locale.".mo");
$info = YAML::load(ADMIN_THEMES_DIR."/".$_GET['theme']."/info.yaml");
fallback($info["notifications"], array());
foreach ($info["notifications"] as &$notification)
$notification = __($notification, $_GET['theme']);
foreach ($info["notifications"] as $message)
Flash::message($message);
# Clear the caches made by the previous theme.
foreach (glob(INCLUDES_DIR."/caches/*.cache") as $cache)
@unlink($cache);
Flash::notice(_f("Admin theme changed to “%s”.", array($info["name"])), "/admin/?action=themes");
}
/**
* Function: preview_theme
* Previews the theme.
*/
public function preview_theme() {
if (!Visitor::current()->group->can("change_settings"))
show_403(__("Access Denied"), __("You do not have sufficient privileges to preview themes."));
if (empty($_GET['theme']))
error(__("No Theme Specified"), __("You did not specify a theme to preview."));
$info = YAML::load(THEMES_DIR."/".$_GET['theme']."/info.yaml");
# Clear the caches made by the previous theme.
foreach (glob(INCLUDES_DIR."/caches/*.cache") as $cache)
@unlink($cache);
if (!empty($_SESSION['theme'])) {
unset($_SESSION['theme']);
Flash::notice(_f("Stopped previewing “%s”.", array($info["name"])), "/admin/?action=themes");
} else {
$_SESSION['theme'] = $_GET['theme'];
Flash::notice(_f("Previewing theme “%s”. Press the theme's “Preview” button again to stop previewing.", array($info["name"])), "/");
}
}
/**
* Function: general_settings
* General Settings page.
*/
public function general_settings() {
if (!Visitor::current()->group->can("change_settings"))
show_403(__("Access Denied"), __("You do not have sufficient privileges to change settings."));
$locales = array();
if ($open = opendir(INCLUDES_DIR."/locale/")) {
while (($folder = readdir($open)) !== false) {
$split = explode(".", $folder);
if (end($split) == "mo")
$locales[] = array("code" => $split[0], "name" => lang_code($split[0]));
}
closedir($open);
}
if (empty($_POST))
return $this->display("general_settings",
array("locales" => $locales,
"timezones" => timezones()));
if (!isset($_POST['hash']) or $_POST['hash'] != Config::current()->secure_hashkey)
show_403(__("Access Denied"), __("Invalid security key."));
$config = Config::current();
$set = array($config->set("name", $_POST['name']),
$config->set("description", $_POST['description']),
$config->set("chyrp_url", rtrim($_POST['chyrp_url'], "/")),
$config->set("url", rtrim(oneof($_POST['url'], $_POST['chyrp_url']), "/")),
$config->set("email", $_POST['email']),
$config->set("timezone", $_POST['timezone']),
$config->set("locale", $_POST['locale']));
if (!in_array(false, $set))
Flash::notice(__("Settings updated."), "/admin/?action=general_settings");
}
/**
* Function: user_settings
* User Settings page.
*/
public function user_settings() {
if (!Visitor::current()->group->can("change_settings"))
show_403(__("Access Denied"), __("You do not have sufficient privileges to change settings."));
if (empty($_POST))
return $this->display("user_settings", array("groups" => Group::find(array("order" => "id DESC"))));
if (!isset($_POST['hash']) or $_POST['hash'] != Config::current()->secure_hashkey)
show_403(__("Access Denied"), __("Invalid security key."));
$config = Config::current();
$set = array($config->set("can_register", !empty($_POST['can_register'])),
$config->set("default_group", $_POST['default_group']),
$config->set("guest_group", $_POST['guest_group']));
if (!in_array(false, $set))
Flash::notice(__("Settings updated."), "/admin/?action=user_settings");
}
/**
* Function: content_settings
* Content Settings page.
*/
public function content_settings() {
if (!Visitor::current()->group->can("change_settings"))
show_403(__("Access Denied"), __("You do not have sufficient privileges to change settings."));
if (empty($_POST))
return $this->display("content_settings");
if (!isset($_POST['hash']) or $_POST['hash'] != Config::current()->secure_hashkey)
show_403(__("Access Denied"), __("Invalid security key."));
$config = Config::current();
$set = array($config->set("posts_per_page", $_POST['posts_per_page']),
$config->set("feed_items", $_POST['feed_items']),
$config->set("feed_url", $_POST['feed_url']),
$config->set("uploads_path", $_POST['uploads_path']),
$config->set("enable_trackbacking", !empty($_POST['enable_trackbacking'])),
$config->set("send_pingbacks", !empty($_POST['send_pingbacks'])),
$config->set("enable_xmlrpc", !empty($_POST['enable_xmlrpc'])),
$config->set("enable_ajax", !empty($_POST['enable_ajax'])));
if (!in_array(false, $set))
Flash::notice(__("Settings updated."), "/admin/?action=content_settings");
}
/**
* Function: route_settings
* Route Settings page.
*/
public function route_settings() {
if (!Visitor::current()->group->can("change_settings"))
show_403(__("Access Denied"), __("You do not have sufficient privileges to change settings."));
if (empty($_POST))
return $this->display("route_settings");
if (!isset($_POST['hash']) or $_POST['hash'] != Config::current()->secure_hashkey)
show_403(__("Access Denied"), __("Invalid security key."));
$config = Config::current();
$set = array($config->set("clean_urls", !empty($_POST['clean_urls'])),
$config->set("post_url", $_POST['post_url']));
if (!in_array(false, $set))
Flash::notice(__("Settings updated."), "/admin/?action=route_settings");
}
/**
* Function: help
* Sets the $title and $body for various help IDs.
*/
public function help() {
list($title, $body) = Trigger::current()->call("help_".$_GET['id']);
switch($_GET['id']) {
case "filtering_results":
$title = __("Filtering Results");
$body = "".__("Use this to search for specific items. You can either enter plain text to match the item with, or use keywords:")."
";
$body.= "".__("Keywords")."
";
$body.= "".__("Usage").": attr:val
\n".__("Use this syntax to quickly match specific results. Keywords will modify the query to match items where attr
is equal to val
(case insensitive).");
break;
case "slugs":
$title = __("Post Slugs");
$body = __("Post slugs are strings to use for the URL of a post. They are directly respondible for the (url)
attribute in a post's clean URL, or the /?action=view&url=foo
in a post's dirty URL. A post slug should not contain any special characters other than hyphens.");
break;
case "trackbacks":
$title = __("Trackbacks");
$body = __("Trackbacks are special urls to posts from other blogs that your post is related to or references. The other blog will be notified of your post, and in some cases a comment will automatically be added to the post in question linking back to your post. It's basically a way to network between blogs via posts.");
break;
case "alternate_urls":
$title = __("Alternate URL");
$body = "".__("An alternate URL will allow you to keep Chyrp in its own directory, while having your site URLs point to someplace else. For example, you could have Chyrp in a /chyrp
directory, and have your site at /
. There are two requirements for this to work.")."
\n\n";
$body.= "\n\t- ".__("Create an
index.php
file in your destination directory with the following in it:")."\n\n";
$body.= "<?php
require \"path/to/chyrp/index.php\";
?>
";
$body.= " \n\t- ".__("Move the .htaccess file from the original Chyrp directory, and change the
RewriteBase
line to reflect the new website location.")." \n
";
}
require "help.php";
}
/**
* Function: subnav_context
* Generates the context variables for the subnav.
*/
public function subnav_context($action) {
$trigger = Trigger::current();
$visitor = Visitor::current();
$this->context["subnav"] = array();
$subnav =& $this->context["subnav"];
$subnav["write"] = array();
$pages = array("manage" => array());
foreach (Config::current()->enabled_feathers as $index => $feather) {
$info = YAML::load(FEATHERS_DIR."/".$feather."/info.yaml");
$subnav["write"]["write_post&feather=".$feather] = array("title" => __($info["name"], $feather),
"show" => $visitor->group->can("add_draft", "add_post"),
"attributes" => ' id="list_feathers['.$feather.']"',
"selected" => (isset($_GET['feather']) and $_GET['feather'] == $feather) or
(!isset($_GET['feather']) and $action == "write_post" and !$index));
}
# Write navs
$subnav["write"]["write_page"] = array("title" => __("Page"),
"show" => $visitor->group->can("add_page"));
$trigger->filter($subnav["write"], array("admin_write_nav", "write_nav"));
$pages["write"] = array_merge(array("write_post"), array_keys($subnav["write"]));;
# Manage navs
$subnav["manage"] = array("manage_posts" => array("title" => __("Posts"),
"show" => (Post::any_editable() or Post::any_deletable()),
"selected" => array("edit_post", "delete_post")),
"manage_pages" => array("title" => __("Pages"),
"show" => ($visitor->group->can("edit_page", "delete_page")),
"selected" => array("edit_page", "delete_page")),
"manage_users" => array("title" => __("Users"),
"show" => ($visitor->group->can("add_user",
"edit_user",
"delete_user")),
"selected" => array("edit_user", "delete_user", "new_user")),
"manage_groups" => array("title" => __("Groups"),
"show" => ($visitor->group->can("add_group",
"edit_group",
"delete_group")),
"selected" => array("edit_group", "delete_group", "new_group")));
$trigger->filter($subnav["manage"], "manage_nav");
$subnav["manage"]["import"] = array("title" => __("Import"),
"show" => ($visitor->group->can("add_post")));
$subnav["manage"]["export"] = array("title" => __("Export"),
"show" => ($visitor->group->can("add_post")));
$pages["manage"][] = "new_user";
$pages["manage"][] = "new_group";
foreach (array_keys($subnav["manage"]) as $manage)
$pages["manage"] = array_merge($pages["manage"], array($manage,
preg_replace("/manage_(.+)/e",
"'edit_'.depluralize('\\1')",
$manage),
preg_replace("/manage_(.+)/e",
"'delete_'.depluralize('\\1')",
$manage)));
# Settings navs
$subnav["settings"] = array("general_settings" => array("title" => __("General"),
"show" => $visitor->group->can("change_settings")),
"content_settings" => array("title" => __("Content"),
"show" => $visitor->group->can("change_settings")),
"user_settings" => array("title" => __("Users"),
"show" => $visitor->group->can("change_settings")),
"route_settings" => array("title" => __("Routes"),
"show" => $visitor->group->can("change_settings")));
$trigger->filter($subnav["settings"], "settings_nav");
$pages["settings"] = array_keys($subnav["settings"]);
# Extend navs
$subnav["extend"] = array("modules" => array("title" => __("Modules"),
"show" => $visitor->group->can("toggle_extensions")),
"feathers" => array("title" => __("Feathers"),
"show" => $visitor->group->can("toggle_extensions")),
"themes" => array("title" => __("Themes"),
"show" => $visitor->group->can("toggle_extensions")));
$trigger->filter($subnav["extend"], "extend_nav");
$pages["extend"] = array_keys($subnav["extend"]);
foreach (array_keys($subnav) as $main_nav)
foreach ($trigger->filter($pages[$main_nav], $main_nav."_nav_pages") as $extend)
$subnav[$extend] =& $subnav[$main_nav];
foreach ($subnav as $main_nav => &$sub_nav)
foreach ($sub_nav as &$nav)
$nav["show"] = (!isset($nav["show"]) or $nav["show"]);
$trigger->filter($subnav, "admin_subnav");
}
/**
* 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: %s
", 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: \\2
", $e->getMessage());
$trace = debug_backtrace();
$twig = array("file" => $e->filename, "line" => $e->lineno);
array_unshift($trace, $twig);
error(__("Error"), $prettify, $trace);
}
}
}
/**
* Function: current
* Returns a singleton reference to the current class.
*/
public static function & current() {
static $instance = null;
return $instance = (empty($instance)) ? new self() : $instance ;
}
}