示例#1
0
 static function getFeed($params)
 {
     // module params
     $rssurl = $params->get('rssurl', '');
     // get RSS parsed object
     $cache_time = 0;
     if ($params->get('cache')) {
         $cache_time = $params->get('cache_time', 15) * 60;
     }
     $rssDoc = JSimplepieFactory::getFeedParser($rssurl, $cache_time);
     $feed = new stdclass();
     if ($rssDoc != false) {
         // channel header and link
         $feed->title = $rssDoc->get_title();
         $feed->link = $rssDoc->get_link();
         $feed->description = $rssDoc->get_description();
         // channel image if exists
         $feed->image->url = $rssDoc->get_image_url();
         $feed->image->title = $rssDoc->get_image_title();
         // items
         $items = $rssDoc->get_items();
         // feed elements
         $feed->items = array_slice($items, 0, $params->get('rssitems', 5));
     } else {
         $feed = false;
     }
     return $feed;
 }
示例#2
0
 /**
  * Get RSS News feed
  *
  * @return string
  */
 public function getRSSFeed()
 {
     // Get RSS parsed object
     $rssDoc = JSimplepieFactory::getFeedParser('http://feeds.feedburner.com/fabrik', 86400);
     if ($rssDoc == false) {
         $output = JText::_('Error: Feed not retrieved');
     } else {
         // Channel header and link
         $title = $rssDoc->get_title();
         $link = $rssDoc->get_link();
         $output = '<table class="adminlist">';
         $output .= '<tr><th colspan="3"><a href="' . $link . '" target="_blank">' . JText::_($title) . '</th></tr>';
         $items = array_slice($rssDoc->get_items(), 0, 3);
         $numItems = count($items);
         if ($numItems == 0) {
             $output .= '<tr><th>' . JText::_('No news items found') . '</th></tr>';
         } else {
             $k = 0;
             for ($j = 0; $j < $numItems; $j++) {
                 $item = $items[$j];
                 $output .= '<tr><td class="row' . $k . '">';
                 $output .= '<a href="' . $item->get_link() . '" target="_blank">' . $item->get_title() . '</a>';
                 $output .= '<br />' . $item->get_date('Y-m-d');
                 if ($item->get_description()) {
                     $description = $this->_truncateText($item->get_description(), 50);
                     $output .= '<br />' . $description;
                 }
                 $output .= '</td></tr>';
             }
         }
         $k = 1 - $k;
         $output .= '</table>';
     }
     return $output;
 }
示例#3
0
文件: home.php 项目: glauberm/cinevi
 /**
  * Get fabrikar.com rss feed
  *
  * @return string
  */
 public function getRSSFeed()
 {
     //  Get RSS parsed object - Turn off error reporting as SimplePie creates strict error notices.
     $origError = error_reporting();
     error_reporting(0);
     $version = new JVersion();
     if ($version->RELEASE == 2.5) {
         //  get RSS parsed object
         $options = array();
         $options['rssUrl'] = 'http://feeds.feedburner.com/fabrik';
         $options['cache_time'] = 86400;
         $rssDoc = JFactory::getXMLparser('RSS', $options);
     } else {
         $rssDoc = JSimplepieFactory::getFeedParser('http://feeds.feedburner.com/fabrik', 86400);
     }
     if ($rssDoc == false) {
         $output = FText::_('Error: Feed not retrieved');
     } else {
         // Channel header and link
         $title = $rssDoc->get_title();
         $link = $rssDoc->get_link();
         $output = '<table class="adminlist">';
         $output .= '<tr><th colspan="3"><a href="' . $link . '" target="_blank">' . FText::_($title) . '</th></tr>';
         $items = array_slice($rssDoc->get_items(), 0, 3);
         $numItems = count($items);
         if ($numItems == 0) {
             $output .= '<tr><th>' . FText::_('No news items found') . '</th></tr>';
         } else {
             $k = 0;
             for ($j = 0; $j < $numItems; $j++) {
                 $item = $items[$j];
                 $output .= '<tr><td class="row' . $k . '">';
                 $output .= '<a href="' . $item->get_link() . '" target="_blank">' . $item->get_title() . '</a>';
                 $output .= '<br />' . $item->get_date('Y-m-d');
                 if ($item->get_description()) {
                     $description = FabrikString::truncate($item->get_description(), array('wordcount' => 50));
                     $output .= '<br />' . $description;
                 }
                 $output .= '</td></tr>';
                 $k = 1 - $k;
             }
         }
         $output .= '</table>';
     }
     error_reporting($origError);
     return $output;
 }
示例#4
0
 /**
  * Get a parsed XML Feed Source
  *
  * @param string  $url        Url for feed source.
  * @param integer $cache_time Time to cache feed for (using internal cache mechanism).
  *
  * @return mixed SimplePie parsed object on success, false on failure.
  *
  * @since   11.1
  * @deprecated  13.3  Use JSimplepieFactory::getFeedParser() instead.
  */
 public static function getFeedParser($url, $cache_time = 0)
 {
     if (!class_exists('JSimplepieFactory')) {
         throw new BadMethodCallException('JSimplepieFactory not found');
     }
     JLog::add(__METHOD__ . ' is deprecated.   Use JSimplepieFactory::getFeedParser() instead.', JLog::WARNING, 'deprecated');
     return JSimplepieFactory::getFeedParser($url, $cache_time);
 }
示例#5
0
 /**
  * @since	1.6
  */
 function display($tpl = null)
 {
     // Initialise variables.
     $app = JFactory::getApplication();
     $user = JFactory::getUser();
     $dispatcher = JEventDispatcher::getInstance();
     // Get view related request variables.
     $print = JRequest::getBool('print');
     // Get model data.
     $state = $this->get('State');
     $item = $this->get('Item');
     if ($item) {
         // Get Category Model data
         $categoryModel = JModelLegacy::getInstance('Category', 'NewsfeedsModel', array('ignore_request' => true));
         $categoryModel->setState('category.id', $item->catid);
         $categoryModel->setState('list.ordering', 'a.name');
         $categoryModel->setState('list.direction', 'asc');
         $items = $categoryModel->getItems();
     }
     // Check for errors.
     // @TODO Maybe this could go into JComponentHelper::raiseErrors($this->get('Errors'))
     if (count($errors = $this->get('Errors'))) {
         JError::raiseWarning(500, implode("\n", $errors));
         return false;
     }
     // Add router helpers.
     $item->slug = $item->alias ? $item->id . ':' . $item->alias : $item->id;
     $item->catslug = $item->category_alias ? $item->catid . ':' . $item->category_alias : $item->catid;
     $item->parent_slug = $item->category_alias ? $item->parent_id . ':' . $item->parent_alias : $item->parent_id;
     // check if cache directory is writeable
     $cacheDir = JPATH_CACHE . '/';
     if (!is_writable($cacheDir)) {
         JError::raiseNotice('0', JText::_('COM_NEWSFEEDS_CACHE_DIRECTORY_UNWRITABLE'));
         return;
     }
     // Merge newsfeed params. If this is single-newsfeed view, menu params override newsfeed params
     // Otherwise, newsfeed params override menu item params
     $params = $state->get('params');
     $newsfeed_params = clone $item->params;
     $active = $app->getMenu()->getActive();
     $temp = clone $params;
     // Check to see which parameters should take priority
     if ($active) {
         $currentLink = $active->link;
         // If the current view is the active item and an newsfeed view for this feed, then the menu item params take priority
         if (strpos($currentLink, 'view=newsfeed') && strpos($currentLink, '&id=' . (string) $item->id)) {
             // $item->params are the newsfeed params, $temp are the menu item params
             // Merge so that the menu item params take priority
             $newsfeed_params->merge($temp);
             $item->params = $newsfeed_params;
             // Load layout from active query (in case it is an alternative menu item)
             if (isset($active->query['layout'])) {
                 $this->setLayout($active->query['layout']);
             }
         } else {
             // Current view is not a single newsfeed, so the newsfeed params take priority here
             // Merge the menu item params with the newsfeed params so that the newsfeed params take priority
             $temp->merge($newsfeed_params);
             $item->params = $temp;
             // Check for alternative layouts (since we are not in a single-newsfeed menu item)
             if ($layout = $item->params->get('newsfeed_layout')) {
                 $this->setLayout($layout);
             }
         }
     } else {
         // Merge so that newsfeed params take priority
         $temp->merge($newsfeed_params);
         $item->params = $temp;
         // Check for alternative layouts (since we are not in a single-newsfeed menu item)
         if ($layout = $item->params->get('newsfeed_layout')) {
             $this->setLayout($layout);
         }
     }
     $offset = $state->get('list.offset');
     // Check the access to the newsfeed
     $levels = $user->getAuthorisedViewLevels();
     if (!in_array($item->access, $levels) or in_array($item->access, $levels) and !in_array($item->category_access, $levels)) {
         JError::raiseWarning(403, JText::_('JERROR_ALERTNOAUTHOR'));
         return;
     }
     // Get the current menu item
     $menus = $app->getMenu();
     $menu = $menus->getActive();
     $params = $app->getParams();
     // Get the newsfeed
     $newsfeed = $item;
     $temp = new JRegistry();
     $temp->loadString($item->params);
     $params->merge($temp);
     $rssDoc = JSimplepieFactory::getFeedParser($newsfeed->link, $newsfeed->cache_time);
     if ($rssDoc == false) {
         $msg = JText::_('COM_NEWSFEEDS_ERRORS_FEED_NOT_RETRIEVED');
         $app->redirect(NewsFeedsHelperRoute::getCategoryRoute($newsfeed->catslug), $msg);
         return;
     }
     $lists = array();
     // channel header and link
     $newsfeed->channel['title'] = $rssDoc->get_title();
     $newsfeed->channel['link'] = $rssDoc->get_link();
     $newsfeed->channel['description'] = $rssDoc->get_description();
     $newsfeed->channel['language'] = $rssDoc->get_language();
     // channel image if exists
     $newsfeed->image['url'] = $rssDoc->get_image_url();
     $newsfeed->image['title'] = $rssDoc->get_image_title();
     $newsfeed->image['link'] = $rssDoc->get_image_link();
     $newsfeed->image['height'] = $rssDoc->get_image_height();
     $newsfeed->image['width'] = $rssDoc->get_image_width();
     // items
     $newsfeed->items = $rssDoc->get_items();
     // feed elements
     $newsfeed->items = array_slice($newsfeed->items, 0, $newsfeed->numarticles);
     // feed display order
     $feed_display_order = $params->get('feed_display_order', 'des');
     if ($feed_display_order == 'asc') {
         $newsfeed->items = array_reverse($newsfeed->items);
     }
     //Escape strings for HTML output
     $this->pageclass_sfx = htmlspecialchars($params->get('pageclass_sfx'));
     $this->assignRef('params', $params);
     $this->assignRef('newsfeed', $newsfeed);
     $this->assignRef('state', $state);
     $this->assignRef('item', $item);
     $this->assignRef('user', $user);
     $this->print = $print;
     $this->_prepareDocument();
     parent::display($tpl);
 }