Esempio n. 1
0
 /**
  * Function: __construct
  * See Also:
  *     <Model::grab>
  */
 public function __construct($extension_id, $options = array())
 {
     if (!isset($extension_id) and empty($options)) {
         return;
     }
     $options["left_join"][] = array("table" => "versions", "where" => "extension_id = extensions.id");
     $options["select"][] = "extensions.*";
     $options["select"][] = "MAX(versions.created_at) AS last_update";
     $options["group"][] = "id";
     $options["order"] = array("__last_update DESC", "extensions.id DESC");
     parent::grab($this, $extension_id, $options);
     if ($this->no_results) {
         return false;
     }
     $this->textID = $this->url;
     $this->filtered = !isset($options["filter"]) or $options["filter"];
     $trigger = Trigger::current();
     if ($this->filtered) {
         if (!$this->user->group->can("code_in_extensions")) {
             $this->name = fix($this->name);
         }
         $trigger->filter($this->name, array("markup_title", "markup_extension_title"), $this);
     }
     $trigger->filter($this, "extension");
 }
Esempio n. 2
0
 /**
  * Function: __construct
  * See Also:
  *     <Model::grab>
  */
 public function __construct($milestone_id, $options = array())
 {
     if (!isset($milestone_id) and empty($options)) {
         return;
     }
     $options["left_join"][] = array("table" => "tickets", "where" => "milestone_id = milestones.id");
     $options["select"][] = "milestones.*";
     $options["select"][] = "COUNT(tickets.id) AS ticket_count";
     $options["group"][] = "id";
     parent::grab($this, $milestone_id, $options);
     if ($this->no_results) {
         return false;
     }
     $this->filtered = !isset($options["filter"]) or $options["filter"];
     if ($this->ticket_count) {
         $this->percentage = round(100 - $this->open_tickets() / $this->ticket_count * 100);
     } else {
         $this->percentage = 0;
     }
     $trigger = Trigger::current();
     if ($this->filtered) {
         $trigger->filter($this->name, array("markup_title", "markup_milestone_name"), $this);
         $trigger->filter($this->description, array("markup_text", "markup_milestone_text"), $this);
     }
     $trigger->filter($this, "milestone");
 }
Esempio n. 3
0
 /**
  * Function: __construct
  * See Also:
  *     <Model::grab>
  */
 public function __construct($topic_id, $options = array())
 {
     if (!isset($topic_id) and empty($options)) {
         return;
     }
     $options["left_join"][] = array("table" => "messages", "where" => "topic_id = topics.id");
     $options["select"][] = "topics.*";
     $options["select"][] = "COUNT(messages.id) AS message_count";
     $options["select"][] = "MAX(messages.created_at) AS last_message";
     $options["select"][] = "MAX(messages.updated_at) AS last_update";
     fallback($options["order"], array("COALESCE(MAX(messages.created_at), topics.created_at) DESC", "id DESC"));
     $options["group"][] = "id";
     parent::grab($this, $topic_id, $options);
     if ($this->no_results) {
         return false;
     }
     $this->last_activity = max(strtotime($this->last_message), strtotime($this->last_update));
     $this->filtered = !isset($options["filter"]) or $options["filter"];
     $trigger = Trigger::current();
     if ($this->filtered) {
         if (!$this->user->group->can("code_in_topics")) {
             $this->title = strip_tags($this->title);
             $this->description = strip_tags($this->description);
         }
         $trigger->filter($this->title, array("markup_title", "markup_topic_title"), $this);
         $trigger->filter($this->description, array("markup_text", "markup_topic_text"), $this);
     }
     $trigger->filter($this, "topic");
 }
Esempio n. 4
0
 /**
  * Function: __construct
  * See Also:
  *     <Model::grab>
  */
 public function __construct($ticket_id, $options = array())
 {
     if (!isset($ticket_id) and empty($options)) {
         return;
     }
     $options["left_join"][] = array("table" => "revisions", "where" => "ticket_id = tickets.id");
     $options["select"][] = "tickets.*";
     $options["select"][] = "COUNT(revisions.id) AS revision_count";
     $options["select"][] = "MAX(revisions.created_at) AS last_revision";
     $options["select"][] = "MAX(revisions.updated_at) AS last_update";
     $options["group"][] = "id";
     parent::grab($this, $ticket_id, $options);
     if ($this->no_results) {
         return false;
     }
     $this->last_activity = max(array_map("strtotime", array($this->last_revision, $this->last_update, $this->created_at, $this->updated_at)));
     $this->done = in_array($this->state, array("resolved", "invalid", "declined"));
     $this->filtered = !isset($options["filter"]) or $options["filter"];
     $trigger = Trigger::current();
     if ($this->filtered) {
         if (!$this->user->group->can("code_in_revisions")) {
             $this->title = fix($this->title);
             $this->description = fix($this->description);
         }
         $trigger->filter($this->title, array("markup_title", "markup_ticket_title"), $this);
         $trigger->filter($this->description, array("markup_text", "markup_ticket_text"), $this);
     }
     $trigger->filter($this, "ticket");
 }
Esempio n. 5
0
 /**
  * Function: __construct
  * See Also:
  *     <Model::grab>
  */
 public function __construct($version_id, $options = array())
 {
     if (!isset($version_id) and empty($options)) {
         return;
     }
     $options["left_join"][] = array("table" => "notes", "where" => "version_id = versions.id");
     $options["select"][] = "versions.*";
     $options["select"][] = "COUNT(notes.id) AS note_count";
     $options["select"][] = "MAX(notes.created_at) AS last_note";
     $options["group"][] = "id";
     parent::grab($this, $version_id, $options);
     if ($this->no_results) {
         return false;
     }
     $this->compatible = array_map(array("Version", "numberfy"), (array) YAML::load($this->compatible));
     $this->tags = !empty($this->tags) ? YAML::load($this->tags) : array();
     $this->linked_tags = self::link_tags($this->tags);
     $this->filtered = !isset($options["filter"]) or $options["filter"];
     $trigger = Trigger::current();
     if ($this->filtered) {
         $this->description_unfiltered = $this->description;
         if (!$this->extension->user->group->can("code_in_extensions")) {
             $this->description = fix($this->description);
         }
         $trigger->filter($this->description, array("markup_text", "markup_version_text"), $this);
     }
     $trigger->filter($this, "version");
 }
Esempio n. 6
0
 public function __construct($attachment_id, $options = array())
 {
     parent::grab($this, $attachment_id, $options);
     if ($this->no_results) {
         return false;
     }
     $this->info = pathinfo($this->path);
 }
Esempio n. 7
0
 /**
  * Function: __construct
  * See Also:
  *     <Model::grab>
  */
 public function __construct($user_id, $options = array())
 {
     parent::grab($this, $user_id, $options);
     if ($this->no_results) {
         return false;
     }
     Trigger::current()->filter($this, "user");
 }
Esempio n. 8
0
 /**
  * Function: __construct
  * See Also:
  *     <Model::grab>
  */
 public function __construct($post_id = null, $options = array())
 {
     if (!isset($post_id) and empty($options)) {
         return;
     }
     if (isset($options["where"]) and !is_array($options["where"])) {
         $options["where"] = array($options["where"]);
     } elseif (!isset($options["where"])) {
         $options["where"] = array();
     }
     $has_status = false;
     foreach ($options["where"] as $key => $val) {
         if (is_int($key) and substr_count($val, "status") or $key == "status") {
             $has_status = true;
         }
     }
     if (!XML_RPC) {
         $options["where"][] = self::feathers();
         if (!$has_status) {
             $visitor = Visitor::current();
             $private = (isset($options["drafts"]) and $options["drafts"] and $visitor->group->can("view_draft")) ? self::statuses(array("draft")) : self::statuses();
             if (isset($options["drafts"]) and $options["drafts"] and $visitor->group->can("view_own_draft")) {
                 $private .= " OR (status = 'draft' AND user_id = :visitor_id)";
                 $options["params"][":visitor_id"] = $visitor->id;
             }
             $options["where"][] = $private;
         }
     }
     $options["left_join"][] = array("table" => "post_attributes", "where" => "post_id = posts.id");
     $options["select"] = array_merge(array("posts.*", "post_attributes.name AS attribute_names", "post_attributes.value AS attribute_values"), oneof(@$options["select"], array()));
     $options["ignore_dupes"] = array("attribute_names", "attribute_values");
     parent::grab($this, $post_id, $options);
     if ($this->no_results) {
         return false;
     }
     $this->attribute_values = (array) $this->attribute_values;
     $this->attribute_names = (array) $this->attribute_names;
     $this->attributes = $this->attribute_names ? array_combine($this->attribute_names, $this->attribute_values) : array();
     $this->filtered = (!isset($options["filter"]) or $options["filter"]) and !XML_RPC;
     $this->slug = $this->url;
     fallback($this->clean, $this->url);
     foreach ($this->attributes as $key => $val) {
         if (!empty($key)) {
             $keys = array("body", "caption", "description", "dialogue");
             if (in_array($key, $keys) and Config::current()->enable_emoji) {
                 $this->{$key} = emote($val);
             } else {
                 $this->{$key} = $val;
             }
         }
     }
     Trigger::current()->filter($this, "post");
     if ($this->filtered) {
         $this->filter();
     }
 }
Esempio n. 9
0
 /**
  * Function: __construct
  * See Also:
  *     <Model::grab>
  */
 public function __construct($group_id = null, $options = array())
 {
     $options["left_join"][] = array("table" => "permissions", "where" => "group_id = groups.id");
     $options["select"][] = "groups.*";
     $options["select"][] = "permissions.id AS permissions";
     parent::grab($this, $group_id, $options);
     $this->permissions = (array) oneof(@$this->permissions, array());
     if ($this->no_results) {
         return false;
     }
     Trigger::current()->filter($this, "group");
 }
Esempio n. 10
0
 /**
  * Function: __construct
  * See Also:
  *     <Model::grab>
  */
 public function __construct($comment_id, $options = array())
 {
     parent::grab($this, $comment_id, $options);
     if ($this->no_results) {
         return false;
     }
     $this->body_unfiltered = $this->body;
     $group = ($this->user_id and !$this->user->no_results) ? $this->user->group : new Group(Config::current()->guest_group);
     $this->filtered = !isset($options["filter"]) or $options["filter"];
     $trigger = Trigger::current();
     $trigger->filter($this, "comment");
     if ($this->filtered) {
         if ($this->status != "pingback" and !$this->status != "trackback" and !$group->can("code_in_comments")) {
             $this->body = strip_tags($this->body, "<" . join("><", Config::current()->allowed_comment_html) . ">");
         }
         $this->body_unfiltered = $this->body;
         $trigger->filter($this->body, array("markup_text", "markup_comment_text"));
         $trigger->filter($this, "filter_comment");
     }
 }
Esempio n. 11
0
 /**
  * Function: __construct
  * See Also:
  *     <Model::grab>
  */
 public function __construct($message_id, $options = array())
 {
     if (!isset($message_id) and empty($options)) {
         return;
     }
     fallback($options["order"], array("created_at ASC", "id ASC"));
     parent::grab($this, $message_id, $options);
     if ($this->no_results) {
         return false;
     }
     $this->filtered = !isset($options["filter"]) or $options["filter"];
     $trigger = Trigger::current();
     if ($this->filtered) {
         if (!$this->user->group->can("code_in_messages")) {
             $this->body = fix($this->body);
         }
         $trigger->filter($this->body, array("markup_text", "markup_message_text"), $this);
     }
     $trigger->filter($this, "message");
 }
Esempio n. 12
0
 /**
  * Function: __construct
  * See Also:
  *     <Model::grab>
  */
 public function __construct($page_id, $options = array())
 {
     if (!isset($page_id) and empty($options)) {
         return;
     }
     parent::grab($this, $page_id, $options);
     if ($this->no_results) {
         return false;
     }
     $this->slug = $this->url;
     $this->filtered = !isset($options["filter"]) or $options["filter"];
     $trigger = Trigger::current();
     $trigger->filter($this, "page");
     if ($this->filtered) {
         $this->title_unfiltered = $this->title;
         $this->body_unfiltered = $this->body;
         $trigger->filter($this->title, array("markup_title", "markup_page_title"), $this);
         $trigger->filter($this->body, array("markup_text", "markup_page_text"), $this);
         $trigger->filter($this, "filter_page");
     }
 }
Esempio n. 13
0
 /**
  * Function: __construct
  * See Also:
  *     <Model::grab>
  */
 public function __construct($revision_id, $options = array())
 {
     if (!isset($revision_id) and empty($options)) {
         return;
     }
     parent::grab($this, $revision_id, $options);
     $options["order"] = "created_at ASC, id ASC";
     if ($this->no_results) {
         return false;
     }
     $this->changes = YAML::load($this->changes);
     $this->filtered = !isset($options["filter"]) or $options["filter"];
     $trigger = Trigger::current();
     if ($this->filtered) {
         if (!$this->user->group->can("code_in_revisions")) {
             $this->body = fix($this->body);
         }
         $trigger->filter($this->body, array("markup_text", "markup_revision_text"), $this);
     }
     $trigger->filter($this, "revision");
 }
Esempio n. 14
0
 /**
  * Function: __construct
  * See Also:
  *     <Model::grab>
  */
 public function __construct($forum_id, $options = array())
 {
     if (!isset($forum_id) and empty($options)) {
         return;
     }
     $options["left_join"][] = array("table" => "topics", "where" => "forum_id = forums.id");
     $options["select"][] = "forums.*";
     $options["select"][] = "COUNT(topics.id) AS topic_count";
     $options["group"][] = "id";
     fallback($options["order"], array("order ASC", "id ASC"));
     parent::grab($this, $forum_id, $options);
     if ($this->no_results) {
         return false;
     }
     $this->filtered = !isset($options["filter"]) or $options["filter"];
     $trigger = Trigger::current();
     if ($this->filtered) {
         $trigger->filter($this->name, array("markup_title", "markup_forum_name"), $this);
         $trigger->filter($this->description, array("markup_text", "markup_forum_text"), $this);
     }
     $trigger->filter($this, "forum");
 }
Esempio n. 15
0
 /**
  * Function: __construct
  * See Also:
  *     <Model::grab>
  */
 public function __construct($type_id, $options = array())
 {
     if (!isset($type_id) and empty($options)) {
         return;
     }
     $options["left_join"][] = array("table" => "extensions", "where" => "type_id = extensions.id");
     $options["select"][] = "types.*";
     $options["select"][] = "COUNT(extensions.id) AS extension_count";
     $options["group"][] = "id";
     parent::grab($this, $type_id, $options);
     if ($this->no_results) {
         return false;
     }
     $this->textID = $this->url;
     # Useful for Twig
     $this->filtered = !isset($options["filter"]) or $options["filter"];
     $trigger = Trigger::current();
     if ($this->filtered) {
         $trigger->filter($this->name, array("markup_title", "markup_type_name"), $this);
         $trigger->filter($this->description, array("markup_text", "markup_type_text"), $this);
     }
     $trigger->filter($this, "type");
 }