public function extend_nav($navs) { if (Visitor::current()->group->can("toggle_extensions")) { $navs["extend_manager"] = array("title" => __("Extension Manager", "extension_manager")); } return $navs; }
static function settings_nav($navs) { if (Visitor::current()->group->can("change_settings")) { $navs["obscura_settings"] = array("title" => __("Obscura", "obscura")); } return $navs; }
static function settings_nav($navs) { if (Visitor::current()->group->can("change_settings")) { $navs["cascade_settings"] = array("title" => __("Cascade", "cascade")); } return $navs; }
/** * Function: submit * Submits a post to the blog owner. */ public function route_submit() { if (!Visitor::current()->group->can("submit_article")) { show_403(__("Access Denied"), __("You do not have sufficient privileges to submit articles.")); } if (!empty($_POST)) { if (!isset($_POST['hash']) or $_POST['hash'] != Config::current()->secure_hashkey) { show_403(__("Access Denied"), __("Invalid security key.")); } if (empty($_POST['body'])) { Flash::notice(__("Post body can't be empty!"), redirect("/")); } if (!isset($_POST['draft'])) { $_POST['draft'] = "true"; } $_POST['body'] = "{$_POST['body']}\n\n\n{$_POST['name']}\n{$_POST['email']}\n"; $post = Feathers::$instances[$_POST['feather']]->submit(); if (!in_array(false, $post)) { Flash::notice(__("Thank you for your submission. ", "submission"), "/"); } } if (Theme::current()->file_exists("forms/post/submit")) { MainController::current()->display("forms/post/submit", array("feather" => $feather), __("Submit a Text Post")); } else { require "pages/submit.php"; } }
public function settings_nav($navs) { if (Visitor::current()->group->can("change_settings")) { $navs["friendfeedr_settings"] = array("title" => __("FriendFeed", "friendfeedr")); } return $navs; }
static function settings_nav($navs) { if (Visitor::current()->group->can("change_settings")) { $navs["emailblog_settings"] = array("title" => __("EmailBlog", "emailblog")); } return $navs; }
/** * Function: write * Writes their session to the database, or updates it if it already exists. * * Parameters: * $id - Session ID. * $data - Data to write. */ static function write($id, $data) { if (empty($data) or $data == self::$data) { return; } $sql = SQL::current(); if ($sql->count("sessions", array("id" => $id))) { $sql->update("sessions", array("id" => $id), array("data" => $data, "user_id" => Visitor::current()->id, "updated_at" => datetime())); } else { $sql->insert("sessions", array("id" => $id, "data" => $data, "user_id" => Visitor::current()->id, "created_at" => datetime())); } }
/** * Function: __construct * See Also: * <Model::grab> */ public function __construct($req = null, $user_id = null) { $this->action = isset($req["action"]) ? $req["action"] == "unlike" ? "unlike" : "like" : null; # user info $this->user_id = isset($user_id) ? $user_id : Visitor::current()->id; $this->user_name = null; # post info $this->total_count = 0; $this->post_id = isset($req["post_id"]) ? (int) fix($req["post_id"]) : null; # inits $this->cookieInit(); }
/** * Function: add * Adds a page to the database. * * Calls the @add_page@ trigger with the new <Page>. * * Parameters: * $title - The Title for the new page. * $body - The Body for the new page. * $body - The <User> or <User.id> of the page's author. * $parent_id - The ID of the new page's parent page (0 for none). * $show_in_list - Whether or not to show it in the pages list. * $list_order - The order of the page in the list. * $clean - The clean URL. * $url - The unique URL. * $created_at - The new page's "created" timestamp. * $updated_at - The new page's "last updated" timestamp. * * Returns: * The newly created <Page>. * * See Also: * <update> */ static function add($title, $body, $user = null, $parent_id = 0, $show_in_list = true, $list_order = 0, $clean = "", $url = "", $created_at = null, $updated_at = "0000-00-00 00:00:00") { $user_id = $user instanceof User ? $user->id : $user; $sql = SQL::current(); $visitor = Visitor::current(); $trigger = Trigger::current(); $new_values = array("title" => $title, "body" => $body, "user_id" => oneof($user_id, $visitor->id), "parent_id" => oneof($parent_id, 0), "show_in_list" => oneof($show_in_list, true), "list_order" => oneof($list_order, 0), "clean" => oneof($clean, sanitize($title)), "url" => oneof($url, self::check_url($clean)), "created_at" => oneof($created_at, datetime()), "updated_at" => oneof($updated_at, "0000-00-00 00:00:00")); $trigger->filter($new_values, "before_add_page"); $sql->insert("pages", $new_values); $page = new self($sql->latest()); $trigger->call("add_page", $page); return $page; }
public function __construct($url, $config) { $this->user = logged_in() ? Visitor::current()->login : "******"; $this->path = INCLUDES_DIR . "/caches/" . sanitize($this->user); $this->caches = INCLUDES_DIR . "/caches"; $this->url = $url; $this->file = $this->path . "/" . md5($this->url) . ".html"; # If the cache directory is not writable, disable this module and cancel execution. if (!is_writable($this->caches)) { cancel_module("cacher"); } # Remove all expired files. $this->remove_expired(); }
public function __construct($url, $config) { $raw_hosts = (array) $config->cache_memcached_hosts; $this->user = logged_in() ? Visitor::current()->login : "******"; $this->memcache = new Memcache(); $this->url = $url; $this->config = $config; $disable_module = true; foreach ($raw_hosts as $raw) { $raw = trim($raw); if ($raw == '') { continue; } $stack = explode(':', $raw); $host = false; $port = 11211; if (count($stack) == 9 or count($stack) == 2) { # ipv6 with port is 9, ipv4 with port is 2 $port = array_pop($stack); } if (count($stack) == 1) { $host = $stack[0]; } if (count($stack) == 8) { # ipv6 is 8 entries $host = implode(':', $stack); } if ($host === false and count($stack) > 0) { # probably a uri for other transit $host = implode(':', $stack); $port = 0; # other transit requires a port of 0 } if ($host === false) { error_log("Memcached error: {$raw} is an invalid host address"); } else { $this->memcache->addServer($host, $port); $disable_module = false; } } //$disable_module = true; if ($disable_module) { cancel_module("cacher"); } }
public function admin_theme_editor($admin) { if (!Visitor::current()->group->can("change_settings")) { show_403(__("Access Denied"), __("You do not have sufficient privileges to change settings.")); } if (empty($_POST)) { return $admin->display("theme_editor", array("editor" => self::admin_context($admin->context)), __("Theme Editor", "theme_editor")); } if (!isset($_POST['hash']) or $_POST['hash'] != Config::current()->secure_hashkey) { show_403(__("Access Denied"), __("Invalid security key.")); } if (isset($_POST['file']) and isset($_POST['newcontent'])) { $done = file_put_contents($_POST['file'], $_POST['newcontent']); if (!empty($done)) { Flash::notice(__("File Updated"), "/admin/?action=theme_editor&file=" . $_POST['cur_file']); } } }
/** * 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); } }
/** * Function: keywords * Handle keyword-searching. * * Parameters: * $query - The query to parse. * $plain - WHERE syntax to search for non-keyword queries. * $table - If specified, the keywords will be checked against this table's columns for validity. * * Returns: * An array containing the "WHERE" queries and the corresponding parameters. */ function keywords($query, $plain, $table = null) { if (!trim($query)) { return array(array(), array()); } $search = array(); $matches = array(); $where = array(); $params = array(); if ($table) { $columns = SQL::current()->select($table)->fetch(); } $queries = explode(" ", $query); foreach ($queries as $query) { if (!preg_match("/([a-z0-9_]+):(.+)/", $query)) { $search[] = $query; } else { $matches[] = $query; } } $times = array("year", "month", "day", "hour", "minute", "second"); foreach ($matches as $match) { list($test, $equals, ) = explode(":", $match); if ($equals[0] == '"') { if (substr($equals, -1) != '"') { foreach ($search as $index => $part) { $equals .= " " . $part; unset($search[$index]); if (substr($part, -1) == '"') { break; } } } $equals = ltrim(trim($equals, '"'), '"'); } if (in_array($test, $times)) { if ($equals == "today") { $where["created_at like"] = date("%Y-m-d %"); } elseif ($equals == "yesterday") { $where["created_at like"] = date("%Y-m-d %", now("-1 day")); } elseif ($equals == "tomorrow") { error(__("Error"), "Unfortunately our flux capacitor is currently having issues. Try again yesterday."); } else { $where[strtoupper($test) . "(created_at)"] = $equals; } } elseif ($test == "author") { $user = new User(array("login" => $equals)); if ($user->no_results and $equals == "me") { $where["user_id"] = Visitor::current()->id; } else { $where["user_id"] = $user->id; } } elseif ($test == "group") { $group = new Group(array("name" => $equals)); $test = "group_id"; $equals = $group->no_results ? 0 : $group->id; } else { $where[$test] = $equals; } } if ($table) { foreach ($where as $col => $val) { if (!isset($columns[$col])) { if ($table == "posts") { $where["post_attributes.name"] = $col; $where["post_attributes.value like"] = "%" . $val . "%"; } unset($where[$col]); } } } if (!empty($search)) { $where[] = $plain; $params[":query"] = "%" . join(" ", $search) . "%"; } $keywords = array($where, $params); Trigger::current()->filter($keywords, "keyword_search", $query, $plain); return $keywords; }
public function admin_manage_tags($admin) { $sql = SQL::current(); $tags = array(); $names = array(); foreach ($sql->select("post_attributes", "*", array("name" => "tags"))->fetchAll() as $tag) { $post_tags = YAML::load($tag["value"]); $tags = array_merge($tags, $post_tags); foreach ($post_tags as $name => $clean) { $names[] = $name; } } $popularity = array_count_values($names); $cloud = array(); if (!empty($popularity)) { $max_qty = max($popularity); $min_qty = min($popularity); $spread = $max_qty - $min_qty; if ($spread == 0) { $spread = 1; } $step = 75 / $spread; foreach ($popularity as $tag => $count) { $cloud[] = array("size" => 100 + ($count - $min_qty) * $step, "popularity" => $count, "name" => $tag, "title" => sprintf(_p("%s post tagged with "%s"", "%s posts tagged with "%s"", $count, "tags"), $count, $tag), "clean" => $tags[$tag], "url" => url("tag/" . $tags[$tag])); } if (!Post::any_editable() and !Post::any_deletable()) { return $admin->display("manage_tags", array("tag_cloud" => $cloud)); } } fallback($_GET['query'], ""); list($where, $params) = keywords($_GET['query'], "post_attributes.value LIKE :query OR url LIKE :query"); $visitor = Visitor::current(); if (!$visitor->group->can("view_draft", "edit_draft", "edit_post", "delete_draft", "delete_post")) { $where["user_id"] = $visitor->id; } $results = Post::find(array("placeholders" => true, "where" => $where, "params" => $params)); $ids = array(); foreach ($results[0] as $result) { $ids[] = $result["id"]; } if (!empty($ids)) { $posts = new Paginator(Post::find(array("placeholders" => true, "drafts" => true, "where" => array("id" => $ids))), 25); } else { $posts = new Paginator(array()); } $admin->display("manage_tags", array("tag_cloud" => $cloud, "posts" => $posts)); }
public function admin_clear_cache() { if (!Visitor::current()->group->can("change_settings")) { show_403(__("Access Denied"), __("You do not have sufficient privileges to change settings.")); } $this->regenerate(); Flash::notice(__("Cache cleared.", "cacher"), "/admin/?action=cache_settings"); }
public function admin_destroy_aggregate($admin) { if (empty($_POST['id'])) { error(__("No ID Specified"), __("An ID is required to delete an aggregate.", "aggregator")); } if ($_POST['destroy'] == "bollocks") { redirect("/admin/?action=manage_aggregates"); } if (!isset($_POST['hash']) or $_POST['hash'] != Config::current()->secure_hashkey) { show_403(__("Access Denied"), __("Invalid security key.")); } if (!Visitor::current()->group->can("delete_aggregate")) { show_403(__("Access Denied"), __("You do not have sufficient privileges to delete this aggregate.", "aggregator")); } $name = $_POST['id']; if ($_POST["delete_posts"]) { $this->delete_posts($name); $notice = __("Aggregate and its posts deleted.", "aggregator"); } else { $notice = __("Aggregate deleted.", "aggregator"); } $config = Config::current(); unset($config->aggregates[$name]); $config->set("aggregates", $config->aggregates); Flash::notice($notice, "/admin/?action=manage_aggregates"); }
public function admin_delete_category($admin) { if (!Visitor::current()->group()->can("manage_categorize")) { show_403(__("Access Denied"), __("You do not have sufficient privileges to manage categories.", "categorize")); } Category::deleteCategory($_REQUEST['id']); Flash::notice(__("Category deleted.", "categorize"), "/admin/?action=manage_category"); }
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");
/** * Function: editable * Checks if the <User> can edit the topic. */ public function editable($user = null) { if ($this->no_results) { return false; } fallback($user, Visitor::current()); return $user->group->can("edit_topic") or $user->group->can("edit_own_topic") and $this->user_id == $user->id; }
static function user_can($post) { $visitor = Visitor::current(); if (!$visitor->group->can("add_comment")) { return false; } // assume allowed comments by default return empty($post->comment_status) or !($post->comment_status == "closed" or $post->comment_status == "registered_only" and !logged_in() or $post->comment_status == "private" and !$visitor->group->can("add_comment_private")); }
/** * Function: stylesheets * Outputs the default stylesheet links. */ public function stylesheets() { $visitor = Visitor::current(); $config = Config::current(); $trigger = Trigger::current(); $stylesheets = array(); Trigger::current()->filter($stylesheets, "stylesheets"); if (!empty($stylesheets)) { $stylesheets = '<link rel="stylesheet" href="' . implode('" type="text/css" media="screen" charset="utf-8" /' . "\n\t\t" . '<link rel="stylesheet" href="', $stylesheets) . '" type="text/css" media="screen" charset="utf-8" />'; } else { $stylesheets = ""; } if (file_exists(THEME_DIR . "/style.css")) { $stylesheets = '<link rel="stylesheet" href="' . THEME_URL . '/style.css" type="text/css" media="screen" charset="utf-8" />' . "\n\t\t"; } if (!file_exists(THEME_DIR . "/stylesheets/") and !file_exists(THEME_DIR . "/css/")) { return $stylesheets; } $long = (array) glob(THEME_DIR . "/stylesheets/*"); $short = (array) glob(THEME_DIR . "/css/*"); $total = array_merge($long, $short); foreach ($total as $file) { $path = preg_replace("/(.+)\\/themes\\/(.+)/", "/themes/\\2", $file); $file = basename($file); if (substr($file, -8) == ".inc.css" or substr($file, -4) != ".css" and substr($file, -4) != ".php") { continue; } if ($file == "ie.css") { $stylesheets .= "<!--[if IE]>"; } if (preg_match("/^ie([0-9\\.]+)\\.css/", $file, $matches)) { $stylesheets .= "<!--[if IE " . $matches[1] . "]>"; } elseif (preg_match("/(lte?|gte?)ie([0-9\\.]+)\\.css/", $file, $matches)) { $stylesheets .= "<!--[if " . $matches[1] . " IE " . $matches[2] . "]>"; } $stylesheets .= '<link rel="stylesheet" href="' . $config->chyrp_url . $path . '" type="text/css" media="' . ($file == "print.css" ? "print" : "screen") . '" charset="utf-8" />'; if ($file == "ie.css" or preg_match("/(lt|gt)?ie([0-9\\.]+)\\.css/", $file)) { $stylesheets .= "<![endif]-->"; } $stylesheets .= "\n\t\t"; } return $stylesheets; }
public function comments_get($options) { if (ADMIN) { return; } $options["where"]["status not"] = "spam"; $options["where"][] = "status != 'denied' OR (\n (\n user_id != 0 AND\n user_id = :visitor_id\n ) OR (\n id IN " . self::visitor_comments() . "\n )\n )"; $options["order"] = "created_at ASC"; $options["params"][":visitor_id"] = Visitor::current()->id; }
/** * Function: editable * Checks if the <User> can edit the post. */ public function editable($user = null) { if ($this->no_results) { return false; } $name = strtolower(get_class($this)); fallback($user, Visitor::current()); return $user->group->can("edit_" . $name); }
/** * Function: statuses * Returns a SQL query "chunk" for the "status" column permissions of the current user. * * Parameters: * $start - An array of additional statuses to allow; "registered_only" and "private" are added deterministically. */ static function statuses($start = array()) { $visitor = Visitor::current(); $statuses = array_merge(array("public"), $start); if (logged_in()) { $statuses[] = "registered_only"; } if ($visitor->group->can("view_private")) { $statuses[] = "private"; } return "(posts.status IN ('" . implode("', '", $statuses) . "') OR posts.status LIKE '%{" . $visitor->group->id . "}%') OR (posts.status LIKE '%{%' AND posts.user_id = " . $visitor->id . ")"; }
public function admin_add_milestone() { if (!Visitor::current()->group->can("add_milestone")) { show_403(__("Access Denied"), __("You do not have sufficient privileges to add milestones.", "progress")); } $due = empty($_POST['due']) ? "0000-00-00 00:00:00" : datetime($_POST['due']); Milestone::add($_POST['name'], $_POST['description'], $due); Flash::notice(__("Milestone added.", "progress"), "/admin/?action=manage_milestones"); }
/** * 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); } } }
public function admin_update_tag($admin) { if (!isset($_POST['hash']) or $_POST['hash'] != Config::current()->secure_hashkey) { show_403(__("Access Denied"), __("Invalid security key.")); } if (!Visitor::current()->group->can("edit_post")) { show_403(__("Access Denied"), __("You do not have sufficient privileges to edit tags.", "tags")); } $sql = SQL::current(); $tags = array(); $clean = array(); foreach ($sql->select("post_attributes", "*", array("name" => "tags", "value like" => "%\n" . $_POST['original'] . ": \"%"))->fetchAll() as $tag) { $tags = YAML::load($tag["value"]); unset($tags[$_POST['original']]); $tags[$_POST['name']] = sanitize($_POST['name']); $sql->update("post_attributes", array("name" => "tags", "post_id" => $tag["post_id"]), array("value" => YAML::dump($tags))); } Flash::notice(__("Tag renamed.", "tags"), "/admin/?action=manage_tags"); }
static function get_likes($post) { $config = Config::current(); $route = Route::current(); $visitor = Visitor::current(); $likeSetting = $config->module_like; if (!$visitor->group->can("like_post")) { return; } if ($likeSetting["showOnFront"] == false and $route->action == "index") { return; } $request["action"] = $route->action; $request["post_id"] = $post->id; $like = new Like($request, $visitor->id); $like->cookieInit(); $hasPersonLiked = false; if ($like->session_hash != null) { $people = $like->fetchPeople(); if (count($people) != 0) { foreach ($people as $person) { if ($person["session_hash"] == $like->session_hash) { $hasPersonLiked = true; break; } } } } else { $like->fetchCount(); } $returnStr = "<div class='likes' id='likes_post-{$post->id}'>"; if (!$hasPersonLiked) { $returnStr .= "<a class='like' href=\"javascript:likes.like({$post->id});\" title='" . ($like->total_count ? $likeSetting["likeText"][6] : "") . "' >"; $returnStr .= "<img src=\"" . $likeSetting["likeImage"] . "\" alt='Like Post-{$post->id}' />"; if ($likeSetting["likeWithText"]) { # $this->text_default[6] = "Like"; $returnStr .= "(" . $likeSetting["likeText"][6] . ") "; } $returnStr .= "</a><span class='text'>"; if ($like->total_count == 0) { # $this->text_default[3] = "Be the first to like."; $returnStr .= $like->getText($like->total_count, $likeSetting["likeText"][3]); } elseif ($like->total_count == 1) { # $this->text_default[4] = "1 person likes this post."; $returnStr = $returnStr . $like->getText($like->total_count, $likeSetting["likeText"][4]); } elseif ($like->total_count > 1) { # $this->text_default[5] = "%NUM% people like this post."; $returnStr .= $like->getText($like->total_count, $likeSetting["likeText"][5]); } $returnStr .= "</span>"; } else { # $this->text_default[7] = "Unlike"; if ($likeSetting["likeWithText"] and $visitor->group->can("unlike_post") and $hasPersonLiked) { $returnStr .= "<a class='liked' href=\"javascript:likes.unlike({$post->id});\"><img src=\"" . $likeSetting["likeImage"] . "\" alt='Like Post-{$post->id}' />(" . $likeSetting["likeText"][7] . ") </a><span class='text'>"; } else { $returnStr .= "<a class='liked'><img src=\"" . $likeSetting["likeImage"] . "\" alt='Like Post-{$post->id}' /></a><span class='text'>"; } if ($like->total_count == 1) { # $this->text_default[0] = "You like this post."; $returnStr .= $like->getText($like->total_count, $likeSetting["likeText"][0]); } elseif ($like->total_count == 2) { # $this->text_default[1] = "You and 1 person like this post."; $returnStr .= $like->getText(1, $likeSetting["likeText"][1]); } else { $like->total_count--; # $this->text_default[2] = "You and %NUM% people like this post."; $returnStr .= $like->getText($like->total_count, $likeSetting["likeText"][2]); } $returnStr .= "</span>"; } $returnStr .= "</div>"; return $post->get_likes = $returnStr; }
public function admin_add_type() { if (!Visitor::current()->group->can("add_type")) { show_403(__("Access Denied"), __("You do not have sufficient privileges to add types.", "extend")); } Type::add($_POST['name'], $_POST['description'], $_POST['color']); Flash::notice(__("Type added.", "extend"), "/admin/?action=manage_types"); }