Esempio n. 1
0
File: audio.php Progetto: eadz/chyrp
 public function swfupload($admin, $post = null)
 {
     if (isset($post) and $post->feather != "audio" or isset($_GET['feather']) and $_GET['feather'] != "audio") {
         return;
     }
     Trigger::current()->call("prepare_swfupload", "audio", "*.mp3");
 }
Esempio n. 2
0
 /**
  * Function: set
  * Adds or replaces a configuration setting with the given value.
  *
  * Parameters:
  *     $setting - The setting name.
  *     $value - The value.
  *     $overwrite - If the setting exists and is the same value, should it be overwritten?
  */
 public function set($setting, $value, $overwrite = true)
 {
     if (isset($this->{$setting}) and $this->{$setting} == $value and !$overwrite) {
         return false;
     }
     if (isset($this->file) and file_exists($this->file)) {
         $contents = str_replace("<?php header(\"Status: 403\"); exit(\"Access denied.\"); ?>\n", "", file_get_contents($this->file));
         $this->yaml = YAML::load($contents);
     }
     # Add the setting
     $this->yaml[$setting] = $this->{$setting} = $value;
     if (class_exists("Trigger")) {
         Trigger::current()->call("change_setting", $setting, $value, $overwrite);
     }
     # Add the PHP protection!
     $contents = "<?php header(\"Status: 403\"); exit(\"Access denied.\"); ?>\n";
     # Generate the new YAML settings
     $contents .= YAML::dump($this->yaml);
     if (!@file_put_contents(INCLUDES_DIR . "/config.yaml.php", $contents)) {
         Flash::warning(_f("Could not set \"<code>%s</code>\" configuration setting because <code>%s</code> is not writable.", array($setting, "/includes/config.yaml.php")));
         return false;
     } else {
         return true;
     }
 }
Esempio n. 3
0
 public function swfupload($admin, $post = null)
 {
     if (isset($post) and $post->feather != "photo" or isset($_GET['feather']) and $_GET['feather'] != "photo") {
         return;
     }
     Trigger::current()->call("prepare_swfupload", "photo", "*.jpg;*.jpeg;*.png;*.gif;*.bmp");
 }
Esempio n. 4
0
 public function prepare_cache_updaters()
 {
     $regenerate = array("add_post", "add_page", "update_post", "update_page", "delete_post", "delete_page", "change_setting");
     Trigger::current()->filter($regenerate, "cacher_regenerate_triggers");
     foreach ($regenerate as $action) {
         $this->addAlias($action, "regenerate");
     }
     $post_triggers = array();
     foreach (Trigger::current()->filter($post_triggers, "cacher_regenerate_posts_triggers") as $action) {
         $this->addAlias($action, "remove_post_cache");
     }
 }
Esempio n. 5
0
/**
 * This is called like an ordinary filter just with the name of the filter
 * as first argument.  Currently we just raise an exception here but it
 * would make sense in the future to allow dynamic filter lookup for plugins
 * or something like that.
 */
function twig_missing_filter($name)
{
    $args = func_get_args();
    array_shift($args);
    $text = $args[0];
    array_shift($args);
    array_unshift($args, $name);
    unretarded_array_unshift($args, $text);
    $trigger = Trigger::current();
    if ($trigger->exists($name)) {
        return call_user_func_array(array($trigger, "filter"), $args);
    }
    return $text;
}
Esempio n. 6
0
 public function update($filename = null, $path = null, $entity_type = null, $entity_id = null)
 {
     if ($this->no_results) {
         return false;
     }
     $sql = SQL::current();
     $trigger = Trigger::current();
     $old = clone $this;
     foreach (array("filename", "path", "entity_type", "entity_id") as $attr) {
         if ($attr == "updated_at" and $updated_at === null) {
             $this->updated_at = $updated_at = datetime();
         } else {
             $this->{$attr} = ${$attr} = ${$attr} === null ? $this->{$attr} : ${$attr};
         }
     }
     $sql->update("attachments", array("id" => $this->id), array("filename" => $filename, "path" => $path, "entity_type" => $entity_type, "entity_id" => $entity_id));
     $trigger->call("update_attachment", $this, $old);
 }
Esempio n. 7
0
 /**
  * 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);
     }
 }
Esempio n. 8
0
 /**
  * Function: addAlias
  * Allows a module to respond to a trigger with multiple functions and custom priorities.
  *
  * Parameters:
  *     $name - Name of the trigger to respond to.
  *     $function - Name of the class function to respond with.
  *     $priority - Priority of the response.
  */
 protected function addAlias($name, $function, $priority = 10)
 {
     Trigger::current()->priorities[$name][] = array("priority" => $priority, "function" => array($this, $function));
 }
Esempio n. 9
0
/**
 * Function: email
 * Send an email. Function arguments are exactly the same as the PHP mail() function.
 *
 * This is intended so that modules can provide an email method if the server cannot use mail().
 */
function email()
{
    $function = "mail";
    Trigger::current()->filter($function, "send_mail");
    $args = func_get_args();
    # Looks redundant, but it must be so in order to meet PHP's retardation requirements.
    return call_user_func_array($function, $args);
}
Esempio n. 10
0
 /**
  * Function: update
  * Updates the milestone.
  *
  * Parameters:
  *     $name - The new name.
  *     $description - The new description.
  */
 public function update($name = null, $description = null, $due = null)
 {
     if ($this->no_results) {
         return false;
     }
     $old = clone $this;
     $this->name = $name === null ? $this->name : $name;
     $this->description = $description === null ? $this->description : $description;
     $this->due = $due === null ? $this->due : $due;
     $sql = SQL::current();
     $sql->update("milestones", array("id" => $this->id), array("name" => $this->name, "description" => $this->description, "due" => $this->due));
     Trigger::current()->call("update_milestone", $this, $old);
     if (module_enabled("cacher")) {
         Modules::$instances["cacher"]->regenerate();
     }
 }
Esempio n. 11
0
 public function mt_setPostCategories($args)
 {
     $this->auth($args[1], $args[2], 'edit');
     global $user;
     $post = new Post($args[0], array('filter' => false));
     if ($post->no_results) {
         return new IXR_Error(500, __("Post not found."));
     } else {
         if (!$post->deletable($user)) {
             return new IXR_Error(500, __("You don't have permission to edit this post."));
         }
     }
     Trigger::current()->call('mt_setPostCategories', $args[3], $post);
     return true;
 }
Esempio n. 12
0
 /**
  * Function: from_url
  * Attempts to grab a post from its clean URL.
  */
 static function from_url($attrs = null, $options = array())
 {
     fallback($attrs, $_GET);
     $where = array();
     $times = array("year", "month", "day", "hour", "minute", "second");
     preg_match_all("/\\(([^\\)]+)\\)/", Config::current()->post_url, $matches);
     $params = array();
     foreach ($matches[1] as $attr) {
         if (in_array($attr, $times)) {
             $where[strtoupper($attr) . "(created_at)"] = $attrs[$attr];
         } elseif ($attr == "author") {
             $user = new User(array("login" => $attrs['author']));
             $where["user_id"] = $user->id;
         } elseif ($attr == "feathers") {
             $where["feather"] = depluralize($attrs['feathers']);
         } else {
             $tokens = array($where, $params, $attr);
             Trigger::current()->filter($tokens, "post_url_token");
             list($where, $params, $attr) = $tokens;
             if ($attr !== null) {
                 if (!isset($attrs[$attr])) {
                     continue;
                 }
                 $where[$attr] = $attrs[$attr];
             }
         }
     }
     return new self(null, array_merge($options, array("where" => $where, "params" => $params)));
 }
Esempio n. 13
0
 static function delete($comment_id)
 {
     $trigger = Trigger::current();
     if ($trigger->exists("delete_comment")) {
         $trigger->call("delete_comment", new self($comment_id));
     }
     SQL::current()->delete("comments", array("id" => $comment_id));
 }
Esempio n. 14
0
        $.post("<?php 
echo $config->chyrp_url;
?>
/includes/ajax.php", { action: "delete_comment", id: id }, function(response){
            $("#comment_"+id).loader(true)
            if (isError(response)) return

            if (Comment.delete_wrap != "")
                $("#comment_"+id).wrap(Comment.delete_wrap).parent().animate(Comment.delete_animations, function(){
                    $(this).remove()
                })
            else
                $("#comment_"+id).animate(Comment.delete_animations, function(){
                    $(this).remove()
                })

            if ($(".comment_count").size() && $(".comment_plural").size()) {
                var count = parseInt($(".comment_count:first").text())
                count--
                $(".comment_count").text(count)
                var plural = (count == 1) ? "" : "s"
                $(".comment_plural").text(plural)
            }
        }, "html")
    }
}
<?php 
Trigger::current()->call("comments_javascript");
?>
<!-- --></script>
Esempio n. 15
0
 /**
  * Function: update
  * Updates the extension.
  *
  * Parameters:
  *     $title - The new title.
  *     $description - The new description.
  */
 public function update($name = null, $clean = null, $url = null, $type = null, $user = null)
 {
     if ($this->no_results) {
         return false;
     }
     $sql = SQL::current();
     $trigger = Trigger::current();
     $old = clone $this;
     foreach (array("name", "clean", "url", "type_id", "user_id") as $attr) {
         if (substr($attr, -3) == "_id") {
             $arg = ${substr($attr, 0, -3)};
             $this->{$attr} = ${$attr} = oneof($arg instanceof Model ? $arg->id : $arg, $this->{$attr});
         } elseif ($attr == "updated_at" and ${$attr} === null) {
             $this->{$attr} = ${$attr} = datetime();
         } else {
             $this->{$attr} = ${$attr} = ${$attr} !== null ? ${$attr} : $this->{$attr};
         }
     }
     $sql->update("extensions", array("id" => $this->id), array("name" => $name, "clean" => $clean, "url" => $url, "type_id" => $type_id, "user_id" => $user_id));
     $trigger->call("update_extension", $this, $old);
     if (module_enabled("cacher")) {
         Modules::$instances["cacher"]->regenerate();
     }
 }
Esempio n. 16
0
 /**
  * Function: update
  * Updates the page.
  * 
  * Calls the @update_page@ trigger with the updated <Page> and the original <Page>.
  *
  * Parameters:
  *     $title - The new Title.
  *     $body - The new Body.
  *     $body - The <User> or <User.id> of the page's author.
  *     $parent_id - The new parent ID.
  *     $show_in_list - Whether or not to show it in the pages list.
  *     $clean - The page's clean URL.
  *     $url - The page's unique URL.
  *     $created_at - The page's "created" timestamp.
  *     $updated_at - The page's "last updated" timestamp.
  */
 public function update($title = null, $body = null, $user = null, $parent_id = null, $show_in_list = null, $list_order = null, $clean = null, $url = null, $created_at = null, $updated_at = null)
 {
     if ($this->no_results) {
         return false;
     }
     $user_id = $user instanceof User ? $user->id : $user;
     $sql = SQL::current();
     $trigger = Trigger::current();
     $old = clone $this;
     foreach (array("title", "body", "user_id", "parent_id", "show_in_list", "list_order", "clean", "url", "created_at", "updated_at") as $attr) {
         if ($attr == "updated_at" and ${$attr} === null) {
             $this->{$attr} = ${$attr} = datetime();
         } else {
             $this->{$attr} = ${$attr} = ${$attr} !== null ? ${$attr} : $this->{$attr};
         }
     }
     $new_values = array("title" => $title, "body" => $body, "user_id" => $user_id, "parent_id" => $parent_id, "show_in_list" => $show_in_list, "list_order" => $list_order, "clean" => $clean, "url" => $url, "created_at" => $created_at, "updated_at" => $updated_at);
     $trigger->filter($new_values, "before_update_page");
     $sql->update("pages", array("id" => $this->id), $new_values);
     $trigger->call("update_page", $this, $old);
 }
Esempio n. 17
0
 /**
  * Function: update
  * Updates the topic.
  *
  * Parameters:
  *     $title - The new title.
  *     $description - The new description.
  */
 public function update($title = null, $description = null, $forum = null, $user = null, $created_at = null, $updated_at = null)
 {
     if ($this->no_results) {
         return false;
     }
     $sql = SQL::current();
     $trigger = Trigger::current();
     $old = clone $this;
     foreach (array("title", "description", "forum_id", "user_id", "created_at", "updated_at") as $attr) {
         if (substr($attr, -3) == "_id") {
             $arg = ${substr($attr, 0, -3)};
             $this->{$attr} = ${$attr} = oneof($arg instanceof Model ? $arg->id : $arg, $this->{$attr});
         } elseif ($attr == "updated_at") {
             $this->{$attr} = ${$attr} = datetime();
         } else {
             $this->{$attr} = ${$attr} = ${$attr} === null ? $this->{$attr} : ${$attr};
         }
     }
     $sql->update("topics", array("id" => $this->id), array("title" => $title, "description" => $description, "forum_id" => $forum_id, "user_id" => $user_id, "created_at" => $created_at, "updated_at" => $updated_at));
     if (module_enabled("cacher")) {
         Modules::$instances["cacher"]->regenerate();
     }
     $trigger->call("update_topic", $this, $old);
 }
Esempio n. 18
0
 /**
  * Function: update
  * Updates the user with the given login, password, full name, e-mail, website, and <Group> ID.
  *
  * Passes all of the arguments to the update_user trigger.
  *
  * Parameters:
  *     $login - The new Login to set.
  *     $password - The new Password to set, already encoded.
  *     $full_name - The new Full Name to set.
  *     $email - The new E-Mail to set.
  *     $website - The new Website to set.
  *     $group_id - The new <Group> to set.
  *
  * See Also:
  *     <add>
  */
 public function update($login = null, $password = null, $email = null, $full_name = null, $website = null, $group_id = null, $joined_at = null)
 {
     if ($this->no_results) {
         return false;
     }
     $sql = SQL::current();
     $trigger = Trigger::current();
     $old = clone $this;
     foreach (array("login", "password", "email", "full_name", "website", "group_id", "joined_at") as $attr) {
         $this->{$attr} = ${$attr} = ${$attr} !== null ? ${$attr} : $this->{$attr};
     }
     $new_values = array("login" => strip_tags($login), "password" => $password, "email" => strip_tags($email), "full_name" => strip_tags($full_name), "website" => strip_tags($website), "group_id" => $group_id, "joined_at" => $joined_at);
     $trigger->filter($new_values, "before_update_user");
     $sql->update("users", array("id" => $this->id), $new_values);
     $trigger->call("update_user", $this, $old);
 }
Esempio n. 19
0
File: Theme.php Progetto: eadz/chyrp
 /**
  * Function: feeds
  * Outputs the Feed references.
  */
 public function feeds()
 {
     // Compute the URL of the per-page feed (if any):
     $config = Config::current();
     $request = $config->clean_urls ? rtrim(Route::current()->request, "/") : fix($_SERVER['REQUEST_URI']);
     $append = $config->clean_urls ? "/feed" : ((count($_GET) == 1 and Route::current()->action == "index") ? "/?feed" : "&amp;feed");
     $append .= $config->clean_urls ? "/" . urlencode($this->title) : "&amp;title=" . urlencode($this->title);
     # Create basic list of links (site and page Atom feeds):
     $feedurl = oneof(@$config->feed_url, url("feed"));
     $pagefeedurl = $config->url . $request . $append;
     $links = array(array("href" => $feedurl, "type" => "application/atom+xml", "title" => $config->name));
     if ($pagefeedurl != $feedurl) {
         $links[] = array("href" => $pagefeedurl, "type" => "application/atom+xml", "title" => "Current Page (if applicable)");
     }
     # Ask modules to pitch in by adding their own <link> tag items to $links.
     # Each item must be an array with "href" and "rel" properties (and optionally "title" and "type"):
     Trigger::current()->filter($links, "links");
     # Generate <link> tags:
     $tags = array();
     foreach ($links as $link) {
         $rel = oneof(@$link["rel"], "alternate");
         $href = $link["href"];
         $type = @$link["type"];
         $title = @$link["title"];
         $tag = '<link rel="' . $rel . '" href="' . $link["href"] . '"';
         if ($type) {
             $tag .= ' type="' . $type . '"';
         }
         if ($title) {
             $tag .= ' title="' . $title . '"';
         }
         $tags[] = $tag . ' />';
     }
     return implode("\n\t", $tags);
 }
Esempio n. 20
0
    static function ajax()
    {
        header("Content-Type: application/x-javascript", true);
        $config = Config::current();
        $sql = SQL::current();
        $trigger = Trigger::current();
        $visitor = Visitor::current();
        $theme = Theme::current();
        $main = MainController::current();
        switch ($_POST['action']) {
            case "reload_comments":
                $post = new Post($_POST['post_id']);
                if ($post->no_results) {
                    break;
                }
                if ($post->latest_comment > $_POST['last_comment']) {
                    $new_comments = $sql->select("comments", "id, created_at", array("post_id" => $_POST['post_id'], "created_at >" => $_POST['last_comment'], "status not" => "spam", "status != 'denied' OR (\n                                                                (\n                                                                    user_id != 0 AND\n                                                                    user_id = :visitor_id\n                                                                ) OR (\n                                                                    id IN " . self::visitor_comments() . "\n                                                                )\n                                                            )"), "created_at ASC", array(":visitor_id" => $visitor->id));
                    $ids = array();
                    $last_comment = "";
                    while ($the_comment = $new_comments->fetchObject()) {
                        $ids[] = $the_comment->id;
                        if (strtotime($last_comment) < strtotime($the_comment->created_at)) {
                            $last_comment = $the_comment->created_at;
                        }
                    }
                    ?>
{ comment_ids: [ <?php 
                    echo implode(", ", $ids);
                    ?>
 ], last_comment: "<?php 
                    echo $last_comment;
                    ?>
" }
<?php 
                }
                break;
            case "show_comment":
                $comment = new Comment($_POST['comment_id']);
                $trigger->call("show_comment", $comment);
                $main->display("content/comment", array("comment" => $comment));
                break;
            case "delete_comment":
                $comment = new Comment($_POST['id']);
                if (!$comment->deletable()) {
                    break;
                }
                Comment::delete($_POST['id']);
                break;
            case "edit_comment":
                $comment = new Comment($_POST['comment_id'], array("filter" => false));
                if (!$comment->editable()) {
                    break;
                }
                if ($theme->file_exists("forms/comment/edit")) {
                    $main->display("forms/comment/edit", array("comment" => $comment));
                } else {
                    require "edit_form.php";
                }
                break;
        }
    }
Esempio n. 21
0
 /**
  * Function: delete
  * Deletes a given object. Calls the @delete_(model)@ trigger with the objects ID.
  *
  * Parameters:
  *     $model - The model name.
  *     $id - The ID of the object to delete.
  */
 protected static function destroy($model, $id)
 {
     $model = strtolower($model);
     if (Trigger::current()->exists("delete_" . $model)) {
         Trigger::current()->call("delete_" . $model, new $model($id));
     }
     SQL::current()->delete(pluralize($model), array("id" => $id));
 }
Esempio n. 22
0
 /**
  * Function: warning
  * Add a warning (negative) message to the session.
  *
  * Parameters:
  *     $message - Message to display.
  *     $redirect_to - URL to redirect to after the message is stored.
  */
 static function warning($message, $redirect_to = null)
 {
     self::prepare("warnings");
     $_SESSION['warnings'][] = Trigger::current()->filter($message, "flash_warning_message", $redirect_to);
     if (TESTER) {
         exit("ERROR: " . $message);
     }
     if (isset($redirect_to)) {
         redirect($redirect_to);
     }
 }
Esempio n. 23
0
 /**
  * Function: update
  * Updates the version.
  *
  * Parameters:
  *     $title - The new title.
  *     $description - The new description.
  */
 public function update($number = null, $description = null, $compatible = null, $tags = null, $filename = null, $image = null, $loves = null, $downloads = null, $extension = null, $created_at = null, $updated_at = null)
 {
     if ($this->no_results) {
         return false;
     }
     $sql = SQL::current();
     $trigger = Trigger::current();
     $old = clone $this;
     if (is_array($tags)) {
         $tags = array_map("strip_tags", $tags);
         $compatible = array_map("strip_tags", $compatible);
         $tags = array_combine($tags, array_map("sanitize", $tags));
     }
     foreach (array("number", "description", "compatible", "tags", "filename", "image", "loves", "downloads", "extension_id", "created_at", "updated_at") as $attr) {
         if (substr($attr, -3) == "_id") {
             $arg = ${substr($attr, 0, -3)};
             $this->{$attr} = ${$attr} = oneof($arg instanceof Model ? $arg->id : $arg, $this->{$attr});
         } elseif ($attr == "updated_at") {
             if (${$attr} === null) {
                 $this->{$attr} = ${$attr} = datetime();
             } elseif (${$attr} === false) {
                 $this->{$attr} = ${$attr} = $this->{$attr};
             } else {
                 $this->{$attr} = ${$attr};
             }
         } else {
             $this->{$attr} = ${$attr} = ${$attr} !== null ? ${$attr} : $this->{$attr};
         }
     }
     $sql->update("versions", array("id" => $this->id), array("number" => $number, "description" => $description, "compatible" => is_array($compatible) ? YAML::dump($compatible) : $compatible, "tags" => is_array($tags) ? YAML::dump($tags) : $tags, "filename" => $filename, "image" => $image, "loves" => $loves, "downloads" => $downloads, "extension_id" => $extension_id, "created_at" => $created_at, "updated_at" => $updated_at));
     $trigger->call("update_version", $this, $old);
     if (module_enabled("cacher")) {
         Modules::$instances["cacher"]->regenerate();
     }
 }
Esempio n. 24
0
 /**
  * Function: url
  * Attempts to change the specified clean URL to a dirty URL if clean URLs is disabled.
  * Use this for linking to things. The applicable URL conversions are passed through the
  * parse_urls trigger.
  *
  * Parameters:
  *     $url - The clean URL.
  *     $use_chyrp_url - Use @Config.chyrp_url@ instead of @Config.url@, when the @$url@ begins with "/"?
  *
  * Returns:
  *     A clean or dirty URL, depending on @Config.clean_urls@.
  */
 public function url($url, $controller = null)
 {
     $config = Config::current();
     if ($url[0] == "/") {
         return ADMIN ? $config->chyrp_url . $url : $config->url . $url;
     } else {
         $url = substr($url, -1) == "/" ? $url : $url . "/";
     }
     fallback($controller, $this->controller);
     $base = !empty($controller->base) ? $config->url . "/" . $controller->base : $config->url;
     if ($config->clean_urls) {
         # If their post URL doesn't have a trailing slash, remove it from these as well.
         if (substr($url, 0, 5) == "page/") {
             # Different URL for viewing a page
             $url = substr($url, 5);
         }
         return (substr($config->post_url, -1) == "/" or $url == "search/") ? $base . "/" . $url : $base . "/" . rtrim($url, "/");
     }
     $urls = fallback($controller->urls, array());
     Trigger::current()->filter($urls, "parse_urls");
     foreach (array_diff_assoc($urls, $controller->urls) as $key => $value) {
         $urls[substr($key, 0, -1) . preg_quote("feed/", $key[0]) . $key[0]] = "/" . $value . "&amp;feed";
     }
     $urls["|/([^/]+)/\$|"] = "/?action=\$1";
     return $base . fix(preg_replace(array_keys($urls), array_values($urls), "/" . $url, 1));
 }
Esempio n. 25
0
File: Admin.php Progetto: 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);
         }
     }
 }
Esempio n. 26
0
                var postDom = $("#likes_post-"+post_id)
                postDom.children("span.text").html(response.likeText)
                var thumbImg = postDom.children("a.like").children("img")
                postDom.children("a.like").attr("title","").removeAttr("href").text("").addClass("liked").removeClass("like")
                thumbImg.appendTo(postDom.children("a.liked").eq(0))
                postDom.children("a.liked").fadeTo("500",.80)
                postDom.find(".like").hide("fast")
                //postDom.children("a.unlike").show("fast")
            }, false);
        }
        likes.unlike = function(post_id) {
            //likes.log("unlike click for post-"+post_id)
            $("#likes_post-"+post_id+" a.liked").fadeTo(500,.2)
            this.makeCall(post_id,function(response) {
                var postDom = $("#likes_post-"+post_id)
                postDom.children("span.text").html(response.likeText)
                var thumbImg = postDom.children("a.liked").children("img")
                postDom.children("a.liked").attr("href","javascript:likes.like("+post_id+")").text("").addClass("like").removeClass("liked").fadeTo("500",1)
                thumbImg.appendTo(postDom.children("a.like").eq(0))
                postDom.children("a.liked").hide("fast")
                postDom.find(".like").show("fast")
            }, true)
        }
        likes.log = function(obj){
            if(typeof console != "undefined")console.log(obj);
        }
<?php 
Trigger::current()->call("likes_javascript");
?>
<!-- --></script>
Esempio n. 27
0
<?php

$config = Config::current();
$trigger = Trigger::current();
$theme = Theme::current();
$title = !empty($_GET['title']) ? ": " . html_entity_decode($_GET['title']) : "";
echo "<" . '?xml version="1.0" encoding="utf-8"?' . ">\r";
?>
<feed xmlns="http://www.w3.org/2005/Atom">
    <title><?php 
echo $config->name . $title;
?>
</title>
<?php 
if (!empty($config->description)) {
    ?>
    <subtitle><?php 
    echo fix($config->description);
    ?>
</subtitle>
<?php 
}
?>
    <id><?php 
echo fix(self_url());
?>
</id>
    <updated><?php 
echo date("c", $latest_timestamp);
?>
</updated>
Esempio n. 28
0
         error(__("No ID Specified"), __("Please specify an ID of the post you would like to edit."));
     }
     $post = new Post($_POST['id'], array("filter" => false, "drafts" => true));
     if ($post->no_results) {
         header("HTTP/1.1 404 Not Found");
         $trigger->call("not_found");
         exit;
     }
     if (!$post->editable()) {
         show_403(__("Access Denied"), __("You do not have sufficient privileges to edit posts."));
     }
     $title = $post->title();
     $theme_file = THEME_DIR . "/forms/feathers/" . $post->feather . ".php";
     $default_file = FEATHERS_DIR . "/" . $post->feather . "/fields.php";
     $options = array();
     Trigger::current()->filter($options, array("edit_post_options", "post_options"), $post);
     $main->display("forms/post/edit", array("post" => $post, "feather" => Feathers::$instances[$post->feather], "options" => $options, "groups" => Group::find(array("order" => "id ASC"))));
     break;
 case "delete_post":
     $post = new Post($_POST['id'], array("drafts" => true));
     if ($post->no_results) {
         header("HTTP/1.1 404 Not Found");
         $trigger->call("not_found");
         exit;
     }
     if (!$post->deletable()) {
         show_403(__("Access Denied"), __("You do not have sufficient privileges to delete this post."));
     }
     Post::delete($_POST['id']);
     break;
 case "view_post":
Esempio n. 29
0
 /**
  * Function: respondTo
  * Allows a Feather to respond to a Trigger as a Module would.
  *
  * Parameters:
  *     $name - Name of the trigger to respond to.
  *     $function - Name of the class function to respond with.
  *     $priority - Priority of the response.
  *
  * See Also:
  *     <Trigger>
  */
 protected function respondTo($name, $function = null, $priority = 10)
 {
     fallback($function, $name);
     Trigger::current()->priorities[$name][] = array("priority" => $priority, "function" => array($this, $function));
 }
Esempio n. 30
0
 /**
  * Function: update
  * Updates the forum.
  *
  * Parameters:
  *     $name - The new name.
  *     $description - The new description.
  */
 public function update($name = null, $description = null, $order = null)
 {
     if ($this->no_results) {
         return false;
     }
     $old = clone $this;
     $this->name = fallback($name, $this->name);
     $this->description = fallback($description, $this->description);
     $this->order = fallback($order, $this->order);
     $sql = SQL::current();
     $sql->update("forums", array("id" => $this->id), array("name" => $this->name, "description" => $this->description, "order" => $this->order));
     if (module_enabled("cacher")) {
         Modules::$instances["cacher"]->regenerate();
     }
     Trigger::current()->call("update_forum", $this, $old);
 }