예제 #1
0
 public 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;
     }
     try {
         $feed = new JFeedFactory();
         $rssDoc = $feed->getFeed($rssurl);
     } catch (InvalidArgumentException $e) {
         $msg = JText::_('MOD_NEWSFEEDS_ERRORS_FEED_NOT_RETRIEVED');
     } catch (RunTimeException $e) {
         $msg = JText::_('MOD_FEED_ERR_FEED_NOT_RETRIEVED');
     }
     if (empty($rssDoc)) {
         $msg = JText::_('MOD_FEED_ERR_FEED_NOT_RETRIEVED');
         return $msg;
     }
     if ($rssDoc) {
         return $rssDoc;
     }
 }
예제 #2
0
 /**
  * Method to load a feed.
  *
  * @param   JRegisty  $params  The parameters object.
  *
  * @return  JFeedReader|string  Return a JFeedReader object or a string message if error.
  *
  * @since   1.5
  */
 public static function getFeed($params)
 {
     // Module params
     $rssurl = $params->get('rssurl', '');
     // Get RSS parsed object
     try {
         jimport('joomla.feed.factory');
         $feed = new JFeedFactory();
         $rssDoc = $feed->getFeed($rssurl);
     } catch (Exception $e) {
         return JText::_('MOD_FEED_ERR_FEED_NOT_RETRIEVED');
     }
     if (empty($rssDoc)) {
         return JText::_('MOD_FEED_ERR_FEED_NOT_RETRIEVED');
     }
     return $rssDoc;
 }
예제 #3
0
파일: helper.php 프로젝트: Tommar/vino2
 public static function getFeed($params)
 {
     // module params
     $rssurl = $params->get('rssurl', '');
     // get RSS parsed object
     try {
         $feed = new JFeedFactory();
         $rssDoc = $feed->getFeed($rssurl);
     } catch (InvalidArgumentException $e) {
         return JText::_('MOD_FEED_ERR_FEED_NOT_RETRIEVED');
     } catch (RunTimeException $e) {
         return JText::_('MOD_FEED_ERR_FEED_NOT_RETRIEVED');
     } catch (LogicException $e) {
         return JText::_('MOD_FEED_ERR_FEED_NOT_RETRIEVED');
     }
     if (empty($rssDoc)) {
         return JText::_('MOD_FEED_ERR_FEED_NOT_RETRIEVED');
     }
     if ($rssDoc) {
         return $rssDoc;
     }
 }
예제 #4
0
파일: metacafe.php 프로젝트: JozefAB/neoacu
 public function isValid()
 {
     // Connect and get the remote video
     if (!parent::isValid()) {
         return false;
     }
     if (class_exists('JFeedFactory')) {
         $feed = new JFeedFactory();
         $rssDoc = $feed->getFeed($this->getFeedUrl());
         $this->title = $rssDoc[0]->title;
         $this->data = $rssDoc[0]->content;
     } else {
         $rssDoc = JFactory::getFeedParser($this->getFeedUrl(), 0);
         foreach ($rssDoc->get_items() as $item) {
             $enclosures = $item->get_enclosures();
             $this->duration = $enclosures[0]->get_duration();
             $this->title = $item->get_title();
             $this->data = $item->get_description();
         }
     }
     return true;
 }
예제 #5
0
 function renderJEventsNewsCached()
 {
     $output = '';
     //  get RSS parsed object
     try {
         $feed = new JFeedFactory();
         $rssDoc = $feed->getFeed('https://www.jevents.net/jevnews?format=feed&type=rss');
     } catch (InvalidArgumentException $e) {
         return JText::_('MOD_FEED_ERR_FEED_NOT_RETRIEVED');
     } catch (RunTimeException $e) {
         return JText::_('MOD_FEED_ERR_FEED_NOT_RETRIEVED');
     } catch (LogicException $e) {
         return JText::_('MOD_FEED_ERR_FEED_NOT_RETRIEVED');
     }
     if (empty($rssDoc)) {
         return JText::_('MOD_FEED_ERR_FEED_NOT_RETRIEVED');
     } else {
         // channel header and link
         $title = str_replace(" ", "_", $rssDoc->title);
         $link = $rssDoc->uri;
         $output = '<table class="adminlist   table table-striped">';
         $output .= '<tr><th><a href="' . $link . '" target="_blank">' . JText::_($title) . '</th></tr>';
         $items = $rssDoc;
         $numItems = 3;
         if ($numItems == 0) {
             $output .= '<tr><th>' . JText::_('JEV_No_news') . '</th></tr>';
         } else {
             $k = 0;
             for ($j = 0; $j < $numItems; $j++) {
                 if (!isset($items[$j])) {
                     break;
                 }
                 $item = @$items[$j];
                 $output .= '<tr><td class="row' . $k . '">';
                 $output .= '<a href="' . $item->uri . '" target="_blank">' . $item->title . '</a>';
                 if ($item->content) {
                     $description = $this->limitText($item->content, 50);
                     $output .= '<br />' . $description;
                 }
                 $output .= '</td></tr>';
                 $k = 1 - $k;
             }
         }
         $output .= '</table>';
     }
     // do not return the output because of differences between J15 and J17
     echo $output;
 }
예제 #6
0
 /**
  * Execute and display a template script.
  *
  * @param   string  $tpl  The name of the template file to parse; automatically searches through the template paths.
  *
  * @return  mixed  A string if successful, otherwise an Error object.
  *
  * @since   1.6
  */
 public function display($tpl = null)
 {
     $app = JFactory::getApplication();
     $user = JFactory::getUser();
     // Get view related request variables.
     $print = $app->input->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');
         // @TODO: $items is not used. Remove this line?
         $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;
     // 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);
         }
     }
     // 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)) {
         $app->enqueueMessage(JText::_('JERROR_ALERTNOAUTHOR'), 'error');
         $app->setHeader('status', 403, true);
         return;
     }
     // Get the current menu item
     $params = $app->getParams();
     // Get the newsfeed
     $newsfeed = $item;
     $temp = new Registry($item->params);
     $params->merge($temp);
     try {
         $feed = new JFeedFactory();
         $this->rssDoc = $feed->getFeed($newsfeed->link);
     } catch (InvalidArgumentException $e) {
         $msg = JText::_('COM_NEWSFEEDS_ERRORS_FEED_NOT_RETRIEVED');
     } catch (RunTimeException $e) {
         $msg = JText::_('COM_NEWSFEEDS_ERRORS_FEED_NOT_RETRIEVED');
     }
     if (empty($this->rssDoc)) {
         $msg = JText::_('COM_NEWSFEEDS_ERRORS_FEED_NOT_RETRIEVED');
     }
     $feed_display_order = $params->get('feed_display_order', 'des');
     if ($feed_display_order == 'asc') {
         $this->rssDoc->reverseItems();
     }
     // Escape strings for HTML output
     $this->pageclass_sfx = htmlspecialchars($params->get('pageclass_sfx'));
     $this->params = $params;
     $this->newsfeed = $newsfeed;
     $this->state = $state;
     $this->item = $item;
     $this->user = $user;
     if (!empty($msg)) {
         $this->msg = $msg;
     }
     $this->print = $print;
     $item->tags = new JHelperTags();
     $item->tags->getItemTags('com_newsfeeds.newsfeed', $item->id);
     // Increment the hit counter of the newsfeed.
     $model = $this->getModel();
     $model->hit();
     $this->_prepareDocument();
     return parent::display($tpl);
 }
 /**
  * Tests JFeedFactory::registerParser()
  *
  * @return  void
  *
  * @expectedException  InvalidArgumentException
  * @since              12.3
  */
 public function testRegisterParserWithInvalidTag()
 {
     TestReflection::setValue($this->_instance, 'parsers', array());
     $this->_instance->registerParser('42tag', 'JFeedParserMock');
     $this->assertNotEmpty(TestReflection::getValue($this->_instance, 'parsers'));
 }
예제 #8
0
    /**
     * Renders a feed
     *
     * @param   string  $url  - the feed url
     *
     * @return void
     */
    public static function renderFeed($url)
    {
        $rssitems = 5;
        $rssitemdesc = 1;
        // Aaach, Joomla 2.5 please die faster...
        if (JVERSION < '3') {
            jimport('simplepie.simplepie');
            $cache = JFactory::getCache('feed_parser', 'callback');
            $cache->setLifeTime(600);
            $simplepie = new SimplePie(null, null, 0);
            $simplepie->enable_cache(false);
            $simplepie->set_feed_url($url);
            $simplepie->force_feed(true);
            $contents = $cache->get(array($simplepie, 'init'), null, false, false);
            if ($contents) {
                $rssDoc = $simplepie;
            } else {
                return JText::_('LIB_COMPOJOOM_FEED_COULDNT_BE_FETCHED');
            }
        } else {
            // Get RSS parsed object
            try {
                jimport('joomla.feed.factory');
                $feed = new JFeedFactory();
                $rssDoc = $feed->getFeed($url);
            } catch (Exception $e) {
                return JText::_('LIB_COMPOJOOM_FEED_COULDNT_BE_FETCHED');
            }
        }
        $feed = $rssDoc;
        if (JVERSION < 3) {
            if ($rssDoc != false) {
                $filter = JFilterInput::getInstance();
                // Channel header and link
                $channel['title'] = $filter->clean($rssDoc->get_title());
                $channel['link'] = $filter->clean($rssDoc->get_link());
                $channel['description'] = $filter->clean($rssDoc->get_description());
                // Items
                $items = $rssDoc->get_items();
                // Feed elements
                $items = array_slice($items, 0, $rssitems);
                ?>
				<div class="newsfeed">
					<?php 
                if (!is_null($channel['title'])) {
                    ?>
						<h2>
							<a href="<?php 
                    echo htmlspecialchars(str_replace('&', '&amp;', $channel['link']));
                    ?>
" target="_blank">
								<?php 
                    echo htmlspecialchars($channel['title']);
                    ?>
</a>
						</h2>
					<?php 
                }
                ?>

					<?php 
                echo $channel['description'];
                ?>

					<?php 
                $actualItems = count($items);
                $setItems = $rssitems;
                if ($setItems > $actualItems) {
                    $totalItems = $actualItems;
                } else {
                    $totalItems = $setItems;
                }
                ?>

						<ul class="newsfeed">
							<?php 
                for ($j = 0; $j < $totalItems; $j++) {
                    $currItem = $items[$j];
                    ?>
								<li>
									<?php 
                    if (!is_null($currItem->get_link())) {
                        ?>
										<a href="<?php 
                        echo htmlspecialchars($currItem->get_link());
                        ?>
" target="_child">
											<?php 
                        echo htmlspecialchars($currItem->get_title());
                        ?>
</a>
									<?php 
                    }
                    ?>

									<?php 
                    // Item description
                    if ($rssitemdesc) {
                        // Item description
                        $text = $filter->clean(html_entity_decode($currItem->get_description(), ENT_COMPAT, 'UTF-8'));
                        $text = str_replace('&apos;', "'", $text);
                        ?>
										<div>
											<?php 
                        echo CompojoomHtmlString::truncateComplex($text, 200);
                        ?>
										</div>
									<?php 
                    }
                    ?>
								</li>
							<?php 
                }
                ?>
						</ul>
					</div>
			<?php 
            }
        } else {
            if ($rssDoc != false) {
                ?>
				<div class="feed">
					<?php 
                if (!is_null($feed->title)) {
                    ?>
						<h2>
							<a href="<?php 
                    echo str_replace('&', '&amp;', $url);
                    ?>
" target="_blank">
								<?php 
                    echo $feed->title;
                    ?>
</a>
						</h2>
					<?php 
                }
                ?>

					<?php 
                echo $feed->description;
                ?>


					<ul class="newsfeed">
						<?php 
                for ($i = 0; $i < $rssitems; $i++) {
                    if (!$feed->offsetExists($i)) {
                        break;
                    }
                    ?>
							<?php 
                    $uri = !empty($feed[$i]->uri) || !is_null($feed[$i]->uri) ? $feed[$i]->uri : $feed[$i]->guid;
                    $text = !empty($feed[$i]->content) || !is_null($feed[$i]->content) ? $feed[$i]->content : $feed[$i]->description;
                    ?>
							<li>
								<?php 
                    if (!empty($uri)) {
                        ?>
									<h5 class="feed-link">
										<a href="<?php 
                        echo $uri;
                        ?>
" target="_blank">
											<?php 
                        echo $feed[$i]->title;
                        ?>
</a></h5>
								<?php 
                    } else {
                        ?>
									<h5 class="feed-link"><?php 
                        echo $feed[$i]->title;
                        ?>
</h5>
								<?php 
                    }
                    ?>

								<?php 
                    if ($rssitemdesc && !empty($text)) {
                        ?>
									<div class="feed-item-description">
										<?php 
                        // Strip the images.
                        $text = JFilterOutput::stripImages($text);
                        $text = CompojoomHtmlString::truncateComplex($text, 200);
                        echo str_replace('&apos;', "'", $text);
                        ?>
									</div>
								<?php 
                    }
                    ?>
							</li>
						<?php 
                }
                ?>
					</ul>
				</div>
			<?php 
            }
        }
    }
예제 #9
0
 public static function getRssFeed($rssURL, $max)
 {
     $jversion = new JVersion();
     $joomla_version_dest = $jversion->getShortVersion();
     if (version_compare($joomla_version_dest, 3, '<')) {
         return self::getRssFeedJ25($rssURL, $max);
     }
     $feed = new JFeedFactory();
     $rssDoc = $feed->getFeed($rssURL);
     if (empty($rssDoc)) {
         return false;
     }
     for ($i = 0; $i < $max; $i++) {
         if (!$rssDoc->offsetExists($i)) {
             break;
         }
         $item = $rssDoc[$i];
         $temp = new StdClass();
         $temp->link = $item->__get('uri');
         $temp->title = $item->__get('title');
         $temp->title = trim(str_ireplace('addon', '', $temp->title));
         $temp->description = $item->__get('content');
         $feeds[] = $temp;
     }
     return $feeds;
 }
예제 #10
0
 public function getRssFeed($url, $id)
 {
     $response = new JAXResponse();
     $version = new JVersion();
     $joomla_ver = $version->getHelpVersion();
     $rss = array();
     if ($joomla_ver <= '0.30') {
         $rssData = $this->getRSS($url, $id);
         foreach ($rssData->items as $item) {
             $data = new stdClass();
             preg_match_all('#(<[/]?img.*>)#U', $item->get_content(), $matches);
             $imgSrc = '';
             if (isset($matches[0][0])) {
                 $imgSrc = explode('src="', $matches[0][0]);
                 $imgSrc = explode('" ', $imgSrc[1]);
                 $imgSrc = $imgSrc[0];
             }
             $data->title = $item->get_title();
             $data->url = $item->get_link();
             $data->img = $imgSrc;
             $data->published = strtolower($item->get_date('l , d F Y'));
             $data->content = strip_tags(JFilterOutput::stripImages($item->get_description()));
             $rss[] = $data;
         }
     } else {
         try {
             $feed = new JFeedFactory();
             $rssDoc = $feed->getFeed($url);
         } catch (InvalidArgumentException $e) {
             return JText::_('MOD_FEED_ERR_FEED_NOT_RETRIEVED');
         } catch (RunTimeException $e) {
             return JText::_('MOD_FEED_ERR_FEED_NOT_RETRIEVED');
         } catch (LogicException $e) {
             return JText::_('MOD_FEED_ERR_FEED_NOT_RETRIEVED');
         }
         if (empty($rssDoc)) {
             return JText::_('MOD_FEED_ERR_FEED_NOT_RETRIEVED');
         }
         if ($rssDoc) {
             for ($i = 0; $i < 5; $i++) {
                 $date = $rssDoc[$i]->publishedDate;
                 $data = new stdClass();
                 preg_match_all('#(<[/]?img.*>)#U', $rssDoc[$i]->content, $matches);
                 $imgSrc = '';
                 if (isset($matches[0][0])) {
                     $imgSrc = explode('src="', $matches[0][0]);
                     $imgSrc = explode('" ', $imgSrc[1]);
                     $imgSrc = $imgSrc[0];
                 }
                 $data->title = $rssDoc[$i]->title;
                 $data->url = $rssDoc[$i]->uri;
                 $data->img = $imgSrc;
                 $data->published = strtolower($date->format('l , d F Y'));
                 $data->content = strip_tags(JFilterOutput::stripImages($rssDoc[$i]->content));
                 $rss[] = $data;
             }
         }
     }
     $html = '';
     foreach ($rss as $data) {
         //var_dump($data->img);
         $html .= '<div class="media clearfix">';
         $html .= '<div class="media-body">';
         $html .= '<h4 class="media-heading reset-gap"><a href="' . $data->url . '" target="_blank">' . $data->title . '</a></h4>';
         $html .= '<p class="orange">' . $data->published . '</p>';
         if ($data->img) {
             $html .= '<a class="pull-left thumbnail" href="' . $data->url . '" target="_blank">';
             $html .= '<img class="media-object" src="' . $data->img . '" width="100px"  />';
             $html .= '</a>';
         }
         $html .= JHTML::_('string.truncate', $data->content, 200);
         $html .= '</div>';
         $html .= '</div>';
     }
     $response->addScriptCall('joms.jQuery("#' . $id . '").html', $html);
     return $response->sendResponse();
 }
예제 #11
0
 /**
  * Returns all downloadable extensions developed by JoomGallery::ProjectTeam
  * with some additional information like the current version number or a
  * short description of the extension
  *
  * @return  array Two-dimensional array with extension information
  * @since   1.5.0
  */
 public static function getAvailableExtensions()
 {
     static $extensions;
     if (isset($extensions)) {
         return $extensions;
     }
     // Check whether the german or the english RSS file should be loaded
     $subdomain = '';
     $language = JFactory::getLanguage();
     if (strpos($language->getTag(), 'de-') === false) {
         $subdomain = 'en.';
     }
     $site = 'http://www.' . $subdomain . 'joomgallery.net';
     $site2 = 'http://' . $subdomain . 'joomgallery.net';
     $rssurl = $site . '/components/com_newversion/rss/extensions3.rss';
     // Get RSS parsed object
     $rssDoc = false;
     try {
         $feed = new JFeedFactory();
         $rssDoc = $feed->getFeed($rssurl);
     } catch (InvalidArgumentException $e) {
     } catch (RunTimeException $e) {
     }
     $extensions = array();
     if ($rssDoc != false) {
         for ($i = 0; isset($rssDoc[$i]); $i++) {
             $item = $rssDoc[$i];
             $name = $item->title;
             // The data type is delivered as the name of the first category
             $categories = $item->categories;
             $type = key($categories);
             switch ($type) {
                 case 'general':
                     $description = $item->content;
                     $link = $item->uri;
                     if (!is_null($description) && $description != '') {
                         $extensions[$name]['description'] = $description;
                     }
                     if (!is_null($link) && $link != $site && $link != $site2) {
                         $extensions[$name]['downloadlink'] = $link;
                     }
                     break;
                 case 'version':
                     $version = $item->content;
                     $link = $item->uri;
                     if (!is_null($version) && $version != '') {
                         $extensions[$name]['version'] = $version;
                     }
                     if (!is_null($link) && $link != $site && $link != $site2) {
                         $extensions[$name]['releaselink'] = $link;
                     }
                     break;
                 case 'autoupdate':
                     $xml = $item->content;
                     $link = $item->uri;
                     if (!is_null($xml) && $xml != '') {
                         $extensions[$name]['xml'] = $xml;
                     }
                     if (!is_null($link) && $link != $site && $link != $site2) {
                         $extensions[$name]['updatelink'] = $link;
                     }
                     break;
                 default:
                     break;
             }
         }
         // Sort the extensions in alphabetical order
         ksort($extensions);
     }
     return $extensions;
 }
예제 #12
0
	/**
	 * @param $rssURL
	 * @param $max
	 * @return array|bool
	 */
	static public function getRssFeed($rssURL, $max) {

		if (JVM_VERSION < 3){
			jimport('simplepie.simplepie');
			$rssFeed = new SimplePie($rssURL);

			$feeds = array();
			$count = $rssFeed->get_item_quantity();
			$limit=min($max,$count);
			for ($i = 0; $i < $limit; $i++) {
				$feed = new StdClass();
				$item = $rssFeed->get_item($i);
				$feed->link = $item->get_link();
				$feed->title = $item->get_title();
				$feed->description = $item->get_description();
				$feeds[] = $feed;
			}
			return $feeds;

		} else {
			jimport('joomla.feed.factory');
			$feed = new JFeedFactory;
			$rssFeed = $feed->getFeed($rssURL);

			if (empty($rssFeed) or !is_object($rssFeed)) return false;

			for ($i = 0; $i < $max; $i++) {
				if (!$rssFeed->offsetExists($i)) {
					break;
				}
				$feed = new StdClass();
				$uri = (!empty($rssFeed[$i]->uri) || !is_null($rssFeed[$i]->uri)) ? $rssFeed[$i]->uri : $rssFeed[$i]->guid;
				$text = !empty($rssFeed[$i]->content) || !is_null($rssFeed[$i]->content) ? $rssFeed[$i]->content : $rssFeed[$i]->description;
				$feed->link = $uri;
				$feed->title = $rssFeed[$i]->title;
				$feed->description = $text;
				$feeds[] = $feed;
			}
			return $feeds;
		}

	}