Пример #1
0
 /**
  * @param $itemId
  * @return array|bool
  */
 function get_entry($itemId)
 {
     global $prefs;
     $arguments = array('content' => 'bib');
     if (!empty($prefs['zotero_style'])) {
         $arguments['style'] = $prefs['zotero_style'];
     }
     $oauthlib = TikiLib::lib('oauth');
     $response = $oauthlib->do_request('zotero', array('url' => "https://api.zotero.org/groups/{$prefs['zotero_group_id']}/items/" . urlencode($itemId), 'get' => $arguments));
     if ($response->isSuccessful()) {
         $entry = $response->getBody();
         $entry = str_replace('<entry ', '<feed xmlns="http://www.w3.org/2005/Atom"><entry ', $entry) . '</feed>';
         $feed = Zend\Feed\Reader\Reader::importString($entry);
         foreach ($feed as $entry) {
             return array('key' => basename($entry->getLink()), 'url' => $entry->getLink(), 'title' => $entry->getTitle(), 'content' => $entry->getDescription());
         }
     }
     return false;
 }
Пример #2
0
 /**
  * Get user's feeds
  * @param   int User ID
  * @param   int Limit of posts per feed
  * @return  string  HTML section with all feeds included
  * @author  Yannick Warnier
  * @since   Dokeos 1.8.6.1
  */
 public static function get_user_feeds($user, $limit = 5)
 {
     $feed = UserManager::get_extra_user_data_by_field($user, 'rssfeeds');
     if (empty($feed)) {
         return '';
     }
     $feeds = explode(';', $feed['rssfeeds']);
     if (count($feeds) == 0) {
         return '';
     }
     $res = '';
     foreach ($feeds as $url) {
         if (empty($url)) {
             continue;
         }
         $rss = Zend\Feed\Reader\Reader::import($url);
         $i = 1;
         if (!empty($rss)) {
             $icon_rss = '';
             if (!empty($feed)) {
                 $icon_rss = Display::url(Display::return_icon('rss.png', '', array(), 32), Security::remove_XSS($feed['rssfeeds']), array('target' => '_blank'));
             }
             $res .= '<h2>' . $rss->getTitle() . '' . $icon_rss . '</h2>';
             $res .= '<div class="social-rss-channel-items">';
             /** @var Zend\Feed\Reader\Extension\Atom\Entry $item */
             foreach ($rss as $item) {
                 if ($limit >= 0 and $i > $limit) {
                     break;
                 }
                 $res .= '<h3><a href="' . $item->getTitle() . '">' . $item->getTitle() . '</a></h3>';
                 $res .= '<div class="social-rss-item-date">' . $item->getDateCreated()->format('Y-m-d') . '</div>';
                 $res .= '<div class="social-rss-item-content">' . $item->getDescription() . '</div><br />';
                 $i++;
             }
             $res .= '</div>';
         }
     }
     return $res;
 }
Пример #3
0
 private function update_feed($rssId, $url, $actions)
 {
     global $tikilib;
     $filter = new DeclFilter();
     $filter->addStaticKeyFilters(array('url' => 'url', 'title' => 'striptags', 'author' => 'striptags', 'description' => 'striptags', 'content' => 'purifier'));
     $guidFilter = TikiFilter::get('url');
     try {
         $content = $tikilib->httprequest($url);
         $feed = Zend\Feed\Reader\Reader::importString($content);
     } catch (Zend\Feed\Exception\ExceptionInterface $e) {
         $this->modules->update(array('lastUpdated' => $tikilib->now, 'sitetitle' => 'N/A', 'siteurl' => '#'), array('rssId' => $rssId));
         return;
     }
     $siteTitle = TikiFilter::get('striptags')->filter($feed->getTitle());
     $siteUrl = TikiFilter::get('url')->filter($feed->getLink());
     $this->modules->update(array('lastUpdated' => $tikilib->now, 'sitetitle' => $siteTitle, 'siteurl' => $siteUrl), array('rssId' => $rssId));
     foreach ($feed as $entry) {
         // TODO: optimize. Atom entries have an 'updated' element which can be used to only update updated entries
         $guid = $guidFilter->filter($entry->getId());
         $authors = $entry->getAuthors();
         $categories = $entry->getCategories();
         $data = $filter->filter(array('title' => $entry->getTitle(), 'url' => $entry->getLink(), 'description' => $entry->getDescription(), 'content' => $entry->getContent(), 'author' => $authors ? implode(', ', $authors->getValues()) : '', 'categories' => $categories ? json_encode($categories->getValues()) : json_encode(array())));
         $data['guid'] = $guid;
         if (method_exists($entry, 'getDateCreated') && ($createdDate = $entry->getDateCreated())) {
             $data['publication_date'] = $createdDate->getTimestamp();
         } else {
             global $tikilib;
             $data['publication_date'] = $tikilib->now;
         }
         $count = $this->items->fetchCount(array('rssId' => $rssId, 'guid' => $guid));
         if (0 == $count) {
             $this->insert_item($rssId, $data, $actions);
         } else {
             $this->update_item($rssId, $data['guid'], $data);
         }
     }
 }