Esempio n. 1
0
 /**
  * Fetches subscribed feeds and imports them
  */
 public function _on_execute()
 {
     debug_add('_on_execute called');
     if (!midcom::get('auth')->request_sudo('net.nemein.rss')) {
         $msg = "Could not get sudo, aborting operation, see error log for details";
         $this->print_error($msg);
         debug_add($msg, MIDCOM_LOG_ERROR);
         return;
     }
     midcom::get()->disable_limits();
     $qb = net_nemein_rss_feed_dba::new_query_builder();
     // Process lang0 subscriptions first
     $qb->add_order('itemlang', 'ASC');
     $feeds = $qb->execute();
     foreach ($feeds as $feed) {
         try {
             $node = new midcom_db_topic($feed->node);
         } catch (midcom_error $e) {
             debug_add("Node #{$feed->node} does not exist, skipping feed #{$feed->id}", MIDCOM_LOG_ERROR);
             continue;
         }
         debug_add("Fetching {$feed->url}...", MIDCOM_LOG_INFO);
         $fetcher = new net_nemein_rss_fetch($feed);
         $items = $fetcher->import();
         debug_add("Imported " . count($items) . " items, set feed refresh time to " . strftime('%x %X', $feed->latestfetch), MIDCOM_LOG_INFO);
     }
     midcom::get('auth')->drop_sudo();
     debug_add('Done');
     return;
 }
Esempio n. 2
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');
 }
Esempio n. 3
0
 private function _fetch_georss_position($url)
 {
     $rss_content = net_nemein_rss_fetch::raw_fetch($url);
     if (isset($rss_content->items)) {
         foreach ($rss_content->items as $item) {
             $latitude = null;
             $longitude = null;
             if (array_key_exists('georss', $item) && array_key_exists('point', $item['georss'])) {
                 // GeoRSS Simple format
                 $geo_point = explode(' ', $item['georss']['point']);
                 if (count($geo_point) != 2) {
                     // Somehow broken point
                     continue;
                 }
                 $latitude = (double) $geo_point[0];
                 $longitude = (double) $geo_point[1];
             }
             if (array_key_exists('geo', $item) && array_key_exists('lat', $item['geo']) && array_key_exists('lon', $item['geo'])) {
                 // W3C geo format
                 $latitude = (double) $item['geo']['lat'];
                 $longitude = (double) $item['geo']['lon'];
             }
             if (!is_null($latitude) && !is_null($longitude)) {
                 if ($latitude > 90 || $latitude < -90) {
                     // This is no earth coordinate, my friend
                     $this->error = 'POSITIONING_GEORSS_INCORRECT_LATITUDE';
                     // Skip to next
                     continue;
                 }
                 if ($longitude > 180 || $longitude < -180) {
                     // This is no earth coordinate, my friend
                     $this->error = 'POSITIONING_GEORSS_INCORRECT_LONGITUDE';
                     // Skip to next
                     continue;
                 }
                 if (!isset($item['date_timestamp'])) {
                     $item['date_timestamp'] = time();
                 }
                 $position = array('latitude' => $latitude, 'longitude' => $longitude, 'time' => $item['date_timestamp']);
                 // We're happy with the first proper match
                 return $position;
             }
         }
     }
     $this->error = 'POSITIONING_GEORSS_CONNECTION_NORESULTS';
     return null;
 }
Esempio n. 4
0
 /**
  * @param mixed $handler_id The ID of the handler.
  * @param Array $args The argument list.
  * @param Array &$data The local request data.
  */
 public function _handler_fetch($handler_id, array $args, array &$data)
 {
     $this->_topic->require_do('midgard:create');
     midcom::get('cache')->content->enable_live_mode();
     //Disable limits
     @ini_set('memory_limit', $GLOBALS['midcom_config']['midcom_max_memory']);
     @ini_set('max_execution_time', 0);
     if ($handler_id == 'feeds_fetch') {
         $data['feed'] = new net_nemein_rss_feed_dba($args[0]);
         $fetcher = new net_nemein_rss_fetch($data['feed']);
         $data['items'] = $fetcher->import();
         midcom::get('metadata')->set_request_metadata($data['feed']->metadata->revised, $data['feed']->guid);
         $this->bind_view_to_object($data['feed']);
     } else {
         $data['items'] = array();
         $qb = net_nemein_rss_feed_dba::new_query_builder();
         $qb->add_order('title');
         $qb->add_constraint('node', '=', $this->_topic->id);
         $data['feeds'] = $qb->execute();
         foreach ($data['feeds'] as $feed) {
             $fetcher = new net_nemein_rss_fetch($feed);
             $items = $fetcher->import();
             $data['items'] = array_merge($data['items'], $items);
         }
     }
     $this->_update_breadcrumb_line($handler_id);
 }
Esempio n. 5
0
 private function _get_data_from_url($url)
 {
     //We have to hang on to the hKit object, because its configuration is done by require_once
     //and will thus only work for the first instantiation...
     static $hkit;
     if (is_null($hkit)) {
         require_once MIDCOM_ROOT . '/external/hkit.php';
         $hkit = new hKit();
     }
     $data = array();
     // TODO: Error handling
     $client = new org_openpsa_httplib();
     $html = $client->get($url);
     // Check for ICBM coordinate information
     $icbm = org_openpsa_httplib_helpers::get_meta_value($html, 'icbm');
     if ($icbm) {
         $data['icbm'] = $icbm;
     }
     // Check for RSS feed
     $rss_url = org_openpsa_httplib_helpers::get_link_values($html, 'alternate');
     if ($rss_url && count($rss_url) > 0) {
         $data['rss_url'] = $rss_url[0]['href'];
         // We have a feed URL, but we should check if it is GeoRSS as well
         midcom::get('componentloader')->load_library('net.nemein.rss');
         $rss_content = net_nemein_rss_fetch::raw_fetch($data['rss_url']);
         if (isset($rss_content->items) && count($rss_content->items) > 0) {
             if (array_key_exists('georss', $rss_content->items[0]) || array_key_exists('geo', $rss_content->items[0])) {
                 // This is a GeoRSS feed
                 $data['georss_url'] = $data['rss_url'];
             }
         }
     }
     $hcards = @$hkit->getByURL('hcard', $url);
     if (is_array($hcards) && count($hcards) > 0) {
         // We have found hCard data here
         $data['hcards'] = $hcards;
     }
     return $data;
 }