/** * 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(); } }
/** * 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 = Config::current()->enable_emoji ? emote($this->body) : $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"); } }