Example #1
0
 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');
 }
Example #2
0
 public function testCRUD()
 {
     $topic = $this->create_object('midcom_db_topic');
     midcom::get('auth')->request_sudo('net.nehmer.comments');
     $comment = new net_nehmer_comments_comment();
     $comment->objectguid = $topic->guid;
     $stat = $comment->create();
     $this->assertTrue($stat);
     $this->register_object($comment);
     $comment->refresh();
     $this->assertEquals($topic->guid, $comment->objectguid);
     $comment->title = 'TEST';
     $stat = $comment->update();
     $this->assertTrue($stat);
     $comment->refresh();
     $this->assertEquals('TEST', $comment->title);
     $stat = $comment->delete();
     $this->assertTrue($stat);
     midcom::get('auth')->drop_sudo();
 }
Example #3
0
 /**
  * DM2 creation callback, binds the new object directly to the _objectguid.
  */
 function &dm2_create_callback(&$controller)
 {
     $this->_new_comment = new net_nehmer_comments_comment();
     $this->_new_comment->objectguid = $this->_objectguid;
     //Proxy check
     if (!empty($_SERVER["HTTP_X_FORWARDED_FOR"])) {
         $this->_new_comment->ip = $_SERVER["HTTP_X_FORWARDED_FOR"];
     } else {
         $this->_new_comment->ip = $_SERVER['REMOTE_ADDR'];
     }
     if (midcom::get('auth')->user) {
         $this->_new_comment->status = net_nehmer_comments_comment::NEW_USER;
         $this->_new_comment->author = midcom::get('auth')->user->name;
     } else {
         $this->_new_comment->status = net_nehmer_comments_comment::NEW_ANONYMOUS;
     }
     if ($this->_config->get('enable_notify')) {
         $this->_new_comment->_send_notification = true;
     }
     if (!$this->_new_comment->create()) {
         debug_print_r('We operated on this object:', $this->_new_comment);
         throw new midcom_error('Failed to create a new comment, cannot continue. Last Midgard error was: ' . midcom_connection::get_error_string());
     }
     if (isset($_POST['subscribe']) && midcom::get('auth')->user) {
         // User wants to subscribe to receive notifications about this comments thread
         // Get the object we're commenting
         $parent = midcom::get('dbfactory')->get_object_by_guid($this->_objectguid);
         // Sudo so we can update the parent object
         if (midcom::get('auth')->request_sudo('net.nehmer.comments')) {
             // Save the subscription
             $parent->set_parameter('net.nehmer.comments:subscription', midcom::get('auth')->user->guid, time());
             // Return back from the sudo state
             midcom::get('auth')->drop_sudo();
         }
     }
     return $this->_new_comment;
 }
Example #4
0
 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');
 }
Example #5
0
    $comment->title = '';
}
if (isset($_POST['content'])) {
    $comment->content = $_POST['content'];
} else {
    $comment->content = '';
}
if (isset($_POST['subscribe'])) {
    $comment->subscribe = 1;
} else {
    $comment->subscribe = 0;
}
if (isset($_SERVER["HTTP_X_FORWARDED_FOR"]) && !empty($_SERVER["HTTP_X_FORWARDED_FOR"])) {
    $comment->ip = $_SERVER["HTTP_X_FORWARDED_FOR"];
} else {
    $comment->ip = $_SERVER['REMOTE_ADDR'];
}
$comment->status = 5;
$comment->author = $_MIDCOM->auth->user->name;
$status = $comment->create();
echo $comment->guid;
$todoitem = new fi_kilonkipinat_todos_todoitem_dba($_POST['todoitem_guid']);
$GLOBALS['fi.kilonkipinat.todos_commented'] = true;
$GLOBALS['fi.kilonkipinat.todos_update_message'] = '';
if ($_POST['title'] != '') {
    $GLOBALS['fi.kilonkipinat.todos_update_message'] = "\tOtsikko: " . $_POST['title'];
}
$GLOBALS['fi.kilonkipinat.todos_update_message'] .= "Kommentti:\n";
$GLOBALS['fi.kilonkipinat.todos_update_message'] .= $_POST['content'] . "\n\n";
$todoitem->_send_comment_notifications();
$_MIDCOM->relocate($_POST['return_url']);