Example #1
0
 public function loadEntries($feed)
 {
     $entries = array();
     foreach ($feed->get_items() as $item) {
         $title = html_only_entity_decode(strip_tags($item->get_title()));
         $author = $item->get_author();
         $link = $item->get_permalink();
         $date = @strtotime($item->get_date());
         // gestion des tags (catégorie == tag)
         $tags_tmp = $item->get_categories();
         $tags = array();
         if ($tags_tmp !== null) {
             foreach ($tags_tmp as $tag) {
                 $tags[] = html_only_entity_decode($tag->get_label());
             }
         }
         $content = html_only_entity_decode($item->get_content());
         $elinks = array();
         foreach ($item->get_enclosures() as $enclosure) {
             $elink = $enclosure->get_link();
             if (empty($elinks[$elink])) {
                 $elinks[$elink] = '1';
                 $mime = strtolower($enclosure->get_type());
                 if (strpos($mime, 'image/') === 0) {
                     $content .= '<br /><img lazyload="" postpone="" src="' . $elink . '" alt="" />';
                 } elseif (strpos($mime, 'audio/') === 0) {
                     $content .= '<br /><audio lazyload="" postpone="" preload="none" src="' . $elink . '" controls="controls" />';
                 } elseif (strpos($mime, 'video/') === 0) {
                     $content .= '<br /><video lazyload="" postpone="" preload="none" src="' . $elink . '" controls="controls" />';
                 } else {
                     unset($elinks[$elink]);
                 }
             }
         }
         $entry = new FreshRSS_Entry($this->id(), $item->get_id(), $title === null ? '' : $title, $author === null ? '' : html_only_entity_decode($author->name), $content === null ? '' : $content, $link === null ? '' : $link, $date ? $date : time());
         $entry->_tags($tags);
         // permet de récupérer le contenu des flux tronqués
         $entry->loadCompleteContent($this->pathEntries());
         $entries[] = $entry;
         unset($item);
     }
     $this->entries = $entries;
 }
Example #2
0
 public static function daoToEntry($listDAO)
 {
     $list = array();
     if (!is_array($listDAO)) {
         $listDAO = array($listDAO);
     }
     foreach ($listDAO as $key => $dao) {
         $entry = new FreshRSS_Entry($dao['id_feed'], $dao['guid'], $dao['title'], $dao['author'], $dao['content'], $dao['link'], $dao['date'], $dao['is_read'], $dao['is_favorite'], $dao['tags']);
         if (isset($dao['id'])) {
             $entry->_id($dao['id']);
         }
         $list[] = $entry;
     }
     unset($listDAO);
     return $list;
 }
 /**
  * This method import a JSON-based file (Google Reader format).
  *
  * @param string $article_file the JSON file content.
  * @param boolean $starred true if articles from the file must be starred.
  * @return boolean true if an error occured, false else.
  */
 private function importJson($article_file, $starred = false)
 {
     $article_object = json_decode($article_file, true);
     if (is_null($article_object)) {
         Minz_Log::warning('Try to import a non-JSON file');
         return true;
     }
     $is_read = FreshRSS_Context::$user_conf->mark_when['reception'] ? 1 : 0;
     $google_compliant = strpos($article_object['id'], 'com.google') !== false;
     $error = false;
     $article_to_feed = array();
     $nb_feeds = count($this->feedDAO->listFeeds());
     $limits = FreshRSS_Context::$system_conf->limits;
     // First, we check feeds of articles are in DB (and add them if needed).
     foreach ($article_object['items'] as $item) {
         $key = $google_compliant ? 'htmlUrl' : 'feedUrl';
         $feed = new FreshRSS_Feed($item['origin'][$key]);
         $feed = $this->feedDAO->searchByUrl($feed->url());
         if (is_null($feed)) {
             // Feed does not exist in DB,we should to try to add it.
             if ($nb_feeds >= $limits['max_feeds']) {
                 // Oops, no more place!
                 Minz_Log::warning(_t('feedback.sub.feed.over_max', $limits['max_feeds']));
             } else {
                 $feed = $this->addFeedJson($item['origin'], $google_compliant);
             }
             if (is_null($feed)) {
                 // Still null? It means something went wrong.
                 $error = true;
             } else {
                 // Nice! Increase the counter.
                 $nb_feeds += 1;
             }
         }
         if (!is_null($feed)) {
             $article_to_feed[$item['id']] = $feed->id();
         }
     }
     // Then, articles are imported.
     $prepared_statement = $this->entryDAO->addEntryPrepare();
     $this->entryDAO->beginTransaction();
     foreach ($article_object['items'] as $item) {
         if (!isset($article_to_feed[$item['id']])) {
             // Related feed does not exist for this entry, do nothing.
             continue;
         }
         $feed_id = $article_to_feed[$item['id']];
         $author = isset($item['author']) ? $item['author'] : '';
         $key_content = $google_compliant && !isset($item['content']) ? 'summary' : 'content';
         $tags = $item['categories'];
         if ($google_compliant) {
             // Remove tags containing "/state/com.google" which are useless.
             $tags = array_filter($tags, function ($var) {
                 return strpos($var, '/state/com.google') === false;
             });
         }
         $entry = new FreshRSS_Entry($feed_id, $item['id'], $item['title'], $author, $item[$key_content]['content'], $item['alternate'][0]['href'], $item['published'], $is_read, $starred);
         $entry->_id(min(time(), $entry->date(true)) . uSecString());
         $entry->_tags($tags);
         $entry = Minz_ExtensionManager::callHook('entry_before_insert', $entry);
         if (is_null($entry)) {
             // An extension has returned a null value, there is nothing to insert.
             continue;
         }
         $values = $entry->toArray();
         $id = $this->entryDAO->addEntry($values, $prepared_statement);
         if (!$error && $id === false) {
             $error = true;
         }
     }
     $this->entryDAO->commit();
     return $error;
 }