Beispiel #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');
 }
Beispiel #2
0
 /**
  * The delete handler will drop all entries associated with any deleted object
  * so that our DB is clean.
  *
  * Uses SUDO to ensure privileges.
  */
 function _on_watched_dba_delete($object)
 {
     $sudo = midcom::get('auth')->request_sudo();
     $result = net_nehmer_comments_comment::list_by_objectguid($object->guid);
     foreach ($result as $comment) {
         $comment->delete();
     }
     if ($sudo) {
         midcom::get('auth')->drop_sudo();
     }
 }
Beispiel #3
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();
 }
Beispiel #4
0
 /**
  * Checks if a new post has been submitted.
  */
 function _process_post()
 {
     if (!midcom::get('auth')->user && !midcom::get('auth')->request_sudo('net.nehmer.comments')) {
         throw new midcom_error('We were anonymous but could not acquire SUDO privileges, aborting');
     }
     switch ($this->_post_controller->process_form()) {
         case 'save':
             // Check against comment spam
             $this->_new_comment->check_spam($this->_config);
             midcom::get('cache')->invalidate($this->_objectguid);
             // Fall-through intentional
         // Fall-through intentional
         case 'cancel':
             if (!midcom::get('auth')->user) {
                 midcom::get('auth')->drop_sudo();
             }
             $this->_relocate_to_self();
             // This will exit();
     }
 }
Beispiel #5
0
 /**
  * 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;
 }
Beispiel #6
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');
 }
Beispiel #7
0
            continue;
        }
        $author = new midcom_db_person($author_guid);
        if ($author->id == 1) {
            continue;
        }
        $author_string = '<a href="http://news.meego.com/users/' . $author->userid . '">' . $author->name . '</a>';
    }
}
if (empty($author_string)) {
    $published = sprintf($data['l10n']->get('posted on %s.'), "<abbr title=\"" . strftime('%Y-%m-%dT%H:%M:%S%z', $data['article']->metadata->published) . "\">" . gmdate('Y-m-d H:i e', $data['article']->metadata->published) . "</abbr>");
} else {
    $published = sprintf($data['l10n']->get('posted on %s by %s.'), "<abbr title=\"" . strftime('%Y-%m-%dT%H:%M:%S%z', $data['article']->metadata->published) . "\">" . gmdate('Y-m-d H:i e', $data['article']->metadata->published) . "</abbr>", $author_string);
}
if (array_key_exists('comments_enable', $data)) {
    $published .= " <a href=\"{$data['view_url']}#net_nehmer_comments_{$data['article']->guid}\">" . sprintf($data['l10n']->get('%s comments'), net_nehmer_comments_comment::count_by_objectguid($data['article']->guid)) . "</a>.";
}
?>

<div class="hentry counter_&(view_counter); &(class_str);">
    <?php 
$media_params = $data['article']->list_parameters('net.nemein.rss:media');
if (isset($media_params['thumbnail@url'])) {
    echo "<a href=\"{$data['view_url']}\"><img src=\"{$media_params['thumbnail@url']}\" class=\"thumbnail\" /></a>\n";
}
?>
    <h2 class="entry-title"><a href="&(data['view_url']);" rel="bookmark"><?php 
echo $data['article']->title;
?>
</a> </h2>
Beispiel #8
0
<?php

if (!$_MIDGARD['user']) {
    die('No User, exiting!');
}
if (!isset($_POST) || !is_array($_POST) || !isset($_POST['todoitem_guid'])) {
    die('No Post or guid, exiting!');
}
$comment = new net_nehmer_comments_comment();
$comment->objectguid = $_POST['todoitem_guid'];
if (isset($_POST['title'])) {
    $comment->title = $_POST['title'];
} else {
    $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;
Beispiel #9
0
 /**
  * Checks if a button of the admin toolbar was pressed. Detected by looking for the
  * net_nehmer_comment_adminsubmit value in the Request.
  *
  * As of this point, this tool assumes at least owner level privileges for all
  */
 function _process_admintoolbar()
 {
     if (!array_key_exists('net_nehmer_comment_adminsubmit', $_REQUEST)) {
         // Nothing to do.
         return;
     }
     if (array_key_exists('action_delete', $_REQUEST)) {
         $comment = new net_nehmer_comments_comment($_REQUEST['guid']);
         if (!$comment->delete()) {
             throw new midcom_error("Failed to delete comment GUID '{$_REQUEST['guid']}': " . midcom_connection::get_error_string());
         }
         midcom::get('cache')->invalidate($comment->objectguid);
         $this->_relocate_to_self();
     }
 }
Beispiel #10
0
<?php

// This is a style element so the XML output can easily be modified to whatever is needed: DOAP, ...
$mapper = new midcom_helper_xml_objectmapper();
$label = $data['datamanager']->schema->name;
if ($label == 'default') {
    $label = 'product';
}
$extradata = array();
if (midcom::get('componentloader')->is_installed('net.nehmer.comments')) {
    $comments_db = net_nehmer_comments_comment::list_by_objectguid_filter_anonymous($data['product']->guid);
    foreach ($comments_db as $i => $comment) {
        $extradata['comments'][] = array('guid' => $comment->guid, 'author' => $comment->author, 'title' => $comment->title, 'content' => $comment->content, 'published' => $comment->metadata->published, 'rating' => $comment->rating);
    }
}
echo $mapper->dm2data($data['datamanager'], $label, $extradata);
Beispiel #11
0
 /**
  * Update possible ratings cache as requested in configuration
  */
 private function _cache_ratings()
 {
     $config = midcom_baseclasses_components_configuration::get('net.nehmer.comments', 'config');
     if ($config->get('ratings_enable') && ($config->get('ratings_cache_to_object') || $config->get('comment_count_cache_to_object'))) {
         // Handle ratings
         $comments = net_nehmer_comments_comment::list_by_objectguid($this->objectguid);
         $ratings_total = 0;
         $rating_comments = 0;
         $value = 0;
         foreach ($comments as $comment) {
             if (!empty($comment->rating)) {
                 $rating_comments++;
                 $ratings_total += $comment->rating;
             }
         }
         // Get parent object
         $parent_property = $config->get('ratings_cache_to_object_property');
         midcom::get('auth')->request_sudo('net.nehmer.comments');
         if ($config->get('ratings_cache_total')) {
             $value = $ratings_total;
         } else {
             if ($rating_comments != 0) {
                 $value = $ratings_total / $rating_comments;
             }
         }
         if ($config->get('ratings_cache_to_object_property_metadata')) {
             $metadata = midcom_helper_metadata::retrieve($this->objectguid);
             $metadata->set($parent_property, round($value));
         } else {
             $parent_object = midcom::get('dbfactory')->get_object_by_guid($this->objectguid);
             // TODO: Figure out whether to round
             if (!$config->get('ratings_cache_to_object_use_rcs')) {
                 $parent_object->_use_rcs = false;
             }
             $parent_object->{$parent_property} = $value;
             $parent_object->update();
             if (!$config->get('ratings_cache_to_object_use_rcs')) {
                 $parent_object->_use_rcs = true;
             }
         }
         // Get parent object
         $parent_property = $config->get('comment_count_cache_to_object_property');
         if ($config->get('comment_count_cache_to_object_property_metadata')) {
             $metadata = midcom_helper_metadata::retrieve($this->objectguid);
             $metadata->set($parent_property, count($comments));
         } else {
             $parent_object = midcom::get('dbfactory')->get_object_by_guid($this->objectguid);
             if (!$config->get('comment_count_cache_to_object_use_rcs')) {
                 $parent_object->_use_rcs = false;
             }
             $parent_object->{$parent_property} = count($comments);
             $parent_object->update();
             if (!$config->get('comment_count_cache_to_object_use_rcs')) {
                 $parent_object->_use_rcs = true;
             }
         }
         midcom::get('auth')->drop_sudo();
     }
 }
Beispiel #12
0
<?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";
}