function _on_execute() { if (!$this->_config->get('atom_comments_import_enable')) { debug_add('Import of Atom comment feeds disabled, aborting', MIDCOM_LOG_INFO); return; } if (!midcom::get('auth')->request_sudo('net.nehmer.comments')) { debug_add('Could not get sudo, aborting operation', MIDCOM_LOG_ERROR); return; } // Get 50 latest articles so we can look for those $qb = midcom_db_article::new_query_builder(); $qb->add_constraint('topic.guid', '=', $this->_config->get('atom_comments_topic')); $qb->add_order('metadata.published', 'DESC'); $qb->set_limit(50); $articles = $qb->execute(); foreach ($articles as $article) { $replies_url = $article->get_parameter('net.nemein.rss', 'replies_url'); if (empty($replies_url)) { // no replies-url for this article. skipping continue; } // fetch and parse Feed from URL $comments = net_nemein_rss_fetch::raw_fetch($replies_url)->items; foreach ($comments as $comment) { $qb = net_nehmer_comments_comment::new_query_builder(); $qb->add_constraint('remoteid', '=', $comment['guid']); $db_comments = $qb->execute(); if (count($db_comments) > 0) { $db_comment = $db_comments[0]; $db_comment->title = $comment['title']; $db_comment->content = $comment['description']; $db_comment->update(); } else { $author_info = net_nemein_rss_fetch::parse_item_author($comment); $db_comment = new net_nehmer_comments_comment(); $db_comment->objectguid = $article->guid; $db_comment->metadata->published = $comment['published']; $db_comment->author = isset($author_info['full_name']) ? $author_info['full_name'] : $author_info['username']; $db_comment->status = $this->_config->get('atom_comments_initial_status'); $db_comment->remoteid = $comment['guid']; $db_comment->title = $comment['title']; $db_comment->content = $comment['description']; $db_comment->create(); } } // <-- comments } // <-- articles midcom::get('auth')->drop_sudo(); debug_add('Done'); }
/** * Get latest 'n' comments that are posted to blogs * @param string GUID of the blog topic * @param integer the last 'n' number of comments to be fetched */ public function _get_last_dataset_comments($number = -1) { $_comments = array(); $qb = fi_opengov_datacatalog_dataset_dba::new_query_builder(); $_res = $qb->execute(); foreach ($_res as $dataset) { $qb2 = net_nehmer_comments_comment::new_query_builder(); $qb2->add_constraint('status', '>=', 4); $qb2->add_constraint('objectguid', '=', $dataset->guid); $_res2 = $qb2->execute(); if (count($_res2)) { foreach ($_res2 as $comment) { $_comments[$comment->metadata->created]['type'] = 'dataset'; $_comments[$comment->metadata->created]['object'] = $comment; } krsort($_comments); } } if (isset($number) && $number != -1 && count($_comments) > $number) { $_comments = array_splice($_comments, 0, $number); } return $_comments; }
function _on_execute() { debug_add('_on_execute called'); if (!$this->_config->get('qaiku_enable')) { debug_add('Qaiku import disabled, aborting', MIDCOM_LOG_INFO); return; } if (!midcom::get('auth')->request_sudo('net.nehmer.comments')) { debug_add('Could not get sudo, aborting operation', MIDCOM_LOG_ERROR); return; } // Get 50 latest articles so we can look for those $articles_by_url = array(); $qb = midcom_db_article::new_query_builder(); $qb->add_constraint('topic.guid', '=', $this->_config->get('qaiku_topic')); $qb->add_order('metadata.published', 'DESC'); $qb->set_limit(20); $articles = $qb->execute(); foreach ($articles as $article) { $articles_by_url[midcom::get('permalinks')->resolve_permalink($article->guid)] = $article; } unset($articles); foreach ($articles_by_url as $article_url => $article) { // Get the Qaiku JSON feed for article $url = "http://www.qaiku.com/api/statuses/replies/byurl.json?external_url=" . urlencode($article_url) . "&apikey=" . $this->_config->get('qaiku_apikey'); $json_file = @file_get_contents($url); if (!$json_file) { continue; } $comments = json_decode($json_file); if (empty($comments)) { continue; } foreach ($comments as $entry) { $article->set_parameter('net.nehmer.comments', 'qaiku_url', $entry->in_reply_to_status_url); $entry_published = strtotime($entry->created_at); // Check this comment isn't there yet $qb = net_nehmer_comments_comment::new_query_builder(); $qb->add_constraint('author', '=', (string) $entry->user->name); $qb->add_constraint('metadata.published', '=', gmstrftime('%Y-%m-%d %T', $entry_published)); $qb->add_constraint('objectguid', '=', $article->guid); $comments = $qb->execute(); if (count($comments) > 0) { // Update comment as needed $comment = $comments[0]; if ($comment->content != $entry->html) { // Entry has been updated $comment->content = (string) $entry->html; $comment->update(); } unset($comments); continue; } $comment = new net_nehmer_comments_comment(); $comment->objectguid = $article->guid; $comment->author = $entry->user->name; $comment->content = $entry->html; $comment->metadata->published = $entry_published; $comment->status = $this->_config->get('qaiku_initial_status'); $comment->create(); } } midcom::get('auth')->drop_sudo(); debug_add('Done'); }
/** * Returns the number of comments associated with a given object by actual registered users. * This is intended for outside usage to render stuff like "15 comments". The count is * executed unchecked. * * May be called statically. * * @return int Number of comments matching a given result. */ function count_by_objectguid_filter_anonymous($guid, $status = false) { $qb = net_nehmer_comments_comment::new_query_builder(); if (!is_array($status)) { $status = net_nehmer_comments_comment::get_default_status(); } $qb->add_constraint('status', 'IN', $status); $qb->add_constraint('objectguid', '=', $guid); $qb->add_constraint('author', '<>', ''); $qb->add_constraint('content', '<>', ''); return $qb->count_unchecked(); }
<?php midcom::get('auth')->require_admin_user(); $qb = net_nehmer_comments_comment::new_query_builder(); $qb->add_constraint('metadata.creator', '<>', ''); $qb->begin_group('OR'); $qb->add_constraint('metadata.authors', '=', ''); $qb->add_constraint('author', '=', ''); $qb->end_group(); $comments = $qb->execute(); foreach ($comments as $comment) { $author = midcom::get('auth')->get_user($comment->metadata->creator); if (!$author->guid) { continue; } $comment->metadata->authors = "|{$author->guid}|"; if ($author->name) { $comment->author = $author->name; } echo "Updating comment {$comment->guid} to author {$author->name} (#{$author->id})... "; $comment->update(); echo midcom_connection::get_error_string() . "<br />\n"; }