/** * Output the Atom entry for a specific slug * * @param string $slug The slug to get the entry for */ public function get_entry($slug) { $params['slug'] = $slug; $params['status'] = $this->is_auth() ? 'any' : Post::status('published'); if ($post = Post::get($params)) { // Assign alternate link. $alternate = URL::get('display_entry', $post, false); $self = URL::get('atom_entry', $post, false); $id = isset($params['slug']) ? $params['slug'] : 'atom_entry'; $user = User::get_by_id($post->user_id); $title = $this->is_auth() ? $post->title : $post->title_atom; $content = $this->is_auth() ? Utils::htmlspecialchars($post->content, ENT_COMPAT, 'UTF-8', false) : Utils::htmlspecialchars($post->content_atom, ENT_COMPAT, 'UTF-8', false); // Build the namespaces, plugins can alter it to override or insert their own. $namespaces = array('default' => 'http://www.w3.org/2005/Atom'); $namespaces = Plugins::filter('atom_get_entry_namespaces', $namespaces); $namespaces = array_map(function ($value, $key) { return ($key == "default" ? "xmlns" : "xmlns:" . $key) . "=\"" . $value . "\""; }, $namespaces, array_keys($namespaces)); $namespaces = implode(' ', $namespaces); $xml = new SimpleXMLElement('<entry ' . $namespaces . '></entry>'); $entry = $xml; $entry_title = $entry->title = $title; $entry_author = $entry->addChild('author'); $author_name = $entry_author->addChild('name', $user->displayname); $entry_link = $xml->addChild('link'); $entry_link->addAttribute('rel', 'alternate'); $entry_link->addAttribute('href', $post->permalink); $entry_link = $entry->addChild('link'); $entry_link->addAttribute('rel', 'edit'); $entry_link->addAttribute('href', URL::get('atom_entry', "slug={$post->slug}")); $entry_id = $entry->addChild('id', $post->guid); $entry_updated = $entry->addChild('updated', $post->updated->get('c')); $entry_edited = $entry->addChild('app:edited', $post->modified->get('c'), 'http://www.w3.org/2007/app'); $entry_published = $entry->addChild('published', $post->pubdate->get('c')); foreach ($post->tags as $tag) { $entry_category = $entry->addChild('category'); $entry_category->addAttribute('term', $tag->term); } $entry_content = $entry->addChild('content', $content); $entry_content->addAttribute('type', 'html'); Plugins::act('atom_get_entry', $xml, $post, $this->handler_vars); $xml = $xml->asXML(); ob_clean(); header('Content-Type: application/atom+xml'); print $this->tidy_xml($xml); } }
/** * Scan a comment with defensio and set it's status. * @param Comment $comment The comment object to scan */ private function audit_comment(Comment $comment) { $user = User::identify(); $params = array('user-ip' => long2ip($comment->ip), 'article-date' => $comment->post->pubdate->format('Y/m/d'), 'comment-author' => $comment->name, 'comment-type' => strtolower($comment->typename), 'comment-content' => $comment->content_out, 'comment-author-email' => $comment->email ? $comment->email : NULL, 'comment-author-url' => $comment->url ? $comment->url : NULL, 'permalink' => $comment->post->permalink, 'referrer' => isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : NULL); if ($user instanceof User) { $params['user-logged-in'] = $user->loggedin; // @todo test for administrator, editor, etc. as well $params['trusted-user'] = $user->loggedin; if ($user->info->openid_url) { $params['openid'] = $user->info->openid_url; } } if (self::TEST_FORCE != FALSE) { $params['test-force'] = self::TEST_FORCE; } $result = $this->defensio->audit_comment($params); // see if it's spamm or the spaminess is greater than min allowed spaminess $min_spaminess = Options::get(self::OPTION_FLAG_SPAMINESS); if ($result->spam == true && $result->spaminess >= (int) $min_spaminess / 100) { $comment->status = 'spam'; // this array nonsense is dumb $comment->info->spamcheck = array_unique(array_merge((array) $comment->info->spamcheck, array(_t('Flagged as Spam by Defensio', 'defensio')))); } else { // it's not spam so if auto_approve is set, approve it if (Options::get(self::OPTION_AUTO_APPROVE) == 'yes') { $comment->status = 'approved'; } else { $comment->status = 'unapproved'; } } $comment->info->defensio_signature = $result->signature; $comment->info->defensio_spaminess = $result->spaminess; }