Inheritance: extends ArrayObject
示例#1
0
 /**
  * Output an Atom collection of comments based on the supplied parameters.
  *
  * @param array $params An array of parameters passed to Comments::get() to retrieve comments
  */
 function get_comments($params = array())
 {
     $comments = null;
     $comments_count = null;
     // Assign self link.
     $self = '';
     // Assign alternate link.
     $alternate = '';
     $updated = DateTime::create();
     // Check if this is a feed for a single post
     if (isset($params['slug']) || isset($params['id'])) {
         if (isset($params['slug'])) {
             $post = Post::get(array('slug' => $params['slug']));
         } elseif (isset($params['id'])) {
             $post = Post::get(array('id' => $params['id']));
         }
         // If the post doesn't exist, send a 404
         if (!$post instanceof Post) {
             header('HTTP/1.1 404 Not Found', true, 404);
             die('The post could not be found');
         }
         $comments = $post->comments->approved;
         $comments_count = count($comments);
         $content_type = Post::type_name($post->content_type);
         $self = URL::get("atom_feed_{$content_type}_comments", $post, false);
         $alternate = URL::get("display_{$content_type}", $post, false);
         if ($comments_count) {
             $updated = $comments[$comments_count - 1]->date;
         }
     } else {
         $self = URL::get('atom_feed_comments');
         $alternate = URL::get('display_home');
         $params['status'] = 'approved';
         $comments = Comments::get($params);
         $comments_count = Comments::count_total(Comment::status('approved'));
         if ($comments_count) {
             $updated = $comments[0]->date;
         }
     }
     $id = isset($params['slug']) ? $params['slug'] : 'atom_comments';
     $xml = $this->create_atom_wrapper($alternate, $self, $id, $updated);
     $xml = $this->add_pagination_links($xml, $comments_count);
     $xml = $this->add_comments($xml, $comments);
     Plugins::act('atom_get_comments', $xml, $params, $this->handler_vars);
     $xml = $xml->asXML();
     ob_clean();
     header('Content-Type: application/atom+xml');
     print $xml;
 }
 /**
  * try to scan for MAX_RETRIES
  */
 public function filter_defensio_queue($result = true)
 {
     $comments = Comments::get(array('status' => self::COMMENT_STATUS_QUEUED));
     if (count($comments) > 0) {
         $try_again = FALSE;
         foreach ($comments as $comment) {
             // Have we tried yet
             if (!$comment->info->defensio_retries) {
                 $comment->info->defensio_retries = 1;
             }
             try {
                 $this->audit_comment($comment);
                 $comment->update();
                 EventLog::log(_t('Defensio scanning, retry %d, for comment %s succeded', array($comment->info->defensio_retries, $comment->ip), 'defensio'), 'notice', 'comment', 'Defensio');
             } catch (Exception $e) {
                 if ($comment->info->defensio_retries >= self::MAX_RETRIES) {
                     EventLog::log(_t('Defensio scanning failed for comment %s. Could not connect to server. Marking unapproved.', array($comment->ip), 'defensio'), 'notice', 'comment', 'Defensio');
                     $comment->status = 'unapproved';
                     $comment->update();
                 } else {
                     EventLog::log(_t('Defensio scanning, retry %d, for comment %s failed', array($comment->info->defensio_retries, $comment->ip), 'defensio'), 'notice', 'comment', 'Defensio');
                     // increment retries and set try_again
                     $comment->info->defensio_retries = $comment->info->defensio_retries + 1;
                     $comment->update();
                     $try_again = TRUE;
                 }
             }
         }
         // try again in RETRY_INTERVAL seconds if not scanned yet
         if ($try_again) {
             $this->_add_cron(self::RETRY_INTERVAL);
         }
     }
     return true;
 }