本文整理汇总了PHP中JFactory::getFeedParser方法的典型用法代码示例。如果您正苦于以下问题:PHP JFactory::getFeedParser方法的具体用法?PHP JFactory::getFeedParser怎么用?PHP JFactory::getFeedParser使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类JFactory
的用法示例。
在下文中一共展示了JFactory::getFeedParser方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: display
/**
* Displays the application output in the canvas.
*
* @since 1.0
* @access public
* @param int The user id that is currently being viewed.
*/
public function display($groupId = null, $docType = null)
{
$group = FD::group($groupId);
// Render the rss model
$model = FD::model('RSS');
$result = $model->getItems($group->id, SOCIAL_TYPE_GROUP);
// If there are tasks, we need to bind them with the table.
$feeds = array();
if ($result) {
foreach ($result as $row) {
// Bind the result back to the note object.
$rss = FD::table('Rss');
$rss->bind($row);
// Initialize the parser.
$parser = @JFactory::getFeedParser($rss->url);
$rss->parser = $parser;
$rss->total = @$parser->get_item_quantity();
$rss->items = @$parser->get_items();
$feeds[] = $rss;
}
}
// Get the app params
$params = $this->app->getParams();
$limit = $params->get('total', 5);
$this->set('totalDisplayed', $limit);
$this->set('appId', $this->app->id);
$this->set('group', $group);
$this->set('feeds', $feeds);
echo parent::display('views/default');
}
示例2: getFeed
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 = JFactory::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;
}
示例3: getFeed
function getFeed()
{
$sefConfig =& SEFConfig::getConfig();
if (!$sefConfig->artioFeedDisplay) {
return '';
}
$rssDoc = JFactory::getFeedParser($sefConfig->artioFeedUrl);
if ($rssDoc === false) {
return JText::_('COM_SEF_ERROR_CONNECTING_TO_RSS_FEED');
}
$items = $rssDoc->get_items();
if (count($items) == 0) {
return JText::_('COM_SEF_NO_ITEMS_TO_DISPLAY');
}
$txt = '';
for ($i = 0, $n = count($items); $i < $n; $i++) {
$item =& $items[$i];
$title = $item->get_title();
$link = $item->get_link();
$desc = $item->get_description();
$date = $item->get_date('j. F Y');
$author = $item->get_author();
$txt .= '<div class="feed-item">';
$txt .= '<div class="feed-title"><a href="' . $link . '" target="_blank">' . $title . '</a></div>';
$txt .= '<div class="feed-text">' . $desc . '</div>';
$txt .= '</div>';
}
return $txt;
}
示例4: fetchFeeds
public function fetchFeeds($url = '', $max = 3)
{
if (method_exists('JFactory', 'getFeedParser')) {
$rss = JFactory::getFeedParser($url);
} else {
$rss = JFactory::getXMLParser('rss', array('rssUrl' => $url));
}
if ($rss == null) {
return false;
}
$result = $rss->get_items();
$feeds = array();
$i = 0;
foreach ($result as $r) {
if ($i == $max) {
break;
}
$feed = array();
$feed['link'] = $r->get_link();
$feed['title'] = $r->get_title();
$feed['description'] = preg_replace('/<img([^>]+)>/', '', $r->get_description());
$feeds[] = $feed;
$i++;
}
return $feeds;
}
示例5: isValid
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;
}
示例6: getFeed
static function getFeed($params)
{
// module params
$rssurl = $params->get('rssurl', '');
// get RSS parsed object
$cache_time = 0;
if ($params->get('cache')) {
/*
* The cache_time will get fed into JCache to initiate the feed_parser cache group and eventually
* JCacheStorage will multiply the value by 60 and use that for its lifetime. The only way to sync
* the feed_parser cache (which caches with an empty dataset anyway) with the module cache is to
* first divide the module's cache time by 60 then inject that forward, which once stored into the
* JCacheStorage object, will be the correct value in minutes.
*/
$cache_time = $params->get('cache_time', 15) / 60;
}
$rssDoc = JFactory::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 = new stdClass();
$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;
}
示例7: render
public static function render($params)
{
// module params
$rssurl = $params->get('feedurl', '');
$rssitems = $params->get('feeditems', 5);
$rssdesc = $params->get('rssdesc', 1);
$rssimage = $params->get('rssimage', 1);
$rssitemdesc = $params->get('rssitemdesc', 1);
$words = $params->get('word_count', 40);
$rsstitle = $params->get('rsstitle', 1);
$rssrtl = $params->get('rssrtl', 0);
$moduleclass_sfx = $params->get('moduleclass_sfx', '');
$filter = JFilterInput::getInstance();
// get RSS parsed object
$rssDoc = JFactory::getFeedParser($rssurl);
// var_dump($rssDoc);
// echo "feed " + $rssurl;
if ($rssDoc != false) {
// 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());
// channel image if exists
$image['url'] = $rssDoc->get_image_url();
$image['title'] = $rssDoc->get_image_title();
//image handling
$iUrl = isset($image['url']) ? $image['url'] : null;
$iTitle = isset($image['title']) ? $image['title'] : null;
// items
$items = $rssDoc->get_items();
// feed elements
$items = array_slice($items, 0, $rssitems);
?>
<table cellpadding="0" cellspacing="0" class="moduletable<?php
echo htmlspecialchars($params->get('moduleclass_sfx'));
?>
">
<?php
// feed description
if (!is_null($channel['title']) && $rsstitle) {
?>
<tr>
<td>
<strong>
<a href="<?php
echo htmlspecialchars(str_replace('&', '&', $channel['link']));
?>
" target="_blank">
<?php
echo htmlspecialchars($channel['title']);
?>
</a>
</strong>
</td>
</tr>
<?php
}
// feed description
if ($rssdesc) {
?>
<tr>
<td>
<?php
echo $channel['description'];
?>
</td>
</tr>
<?php
}
// feed image
if ($rssimage && $iUrl) {
?>
<tr>
<td align="center">
<img src="<?php
echo htmlspecialchars($iUrl);
?>
" alt="<?php
echo htmlspecialchars(@$iTitle);
?>
"/>
</td>
</tr>
<?php
}
$actualItems = count($items);
$setItems = $rssitems;
if ($setItems > $actualItems) {
$totalItems = $actualItems;
} else {
$totalItems = $setItems;
}
?>
<tr>
<td>
<ul class="newsfeed<?php
echo htmlspecialchars($moduleclass_sfx);
?>
" >
<?php
//.........这里部分代码省略.........
示例8: getXMLParser
/**
* Get an XML document
*
* @param string The type of xml parser needed 'DOM', 'RSS' or 'Simple'
* @param array:
* string ['rssUrl'] the rss url to parse when using "RSS"
* string ['cache_time'] with 'RSS' - feed cache time. If not defined defaults to 3600 sec
* @return object Parsed XML document object
* @deprecated
*/
public static function getXMLParser($type = '', $options = array())
{
$doc = null;
switch (strtolower($type)) {
case 'rss':
case 'atom':
$cache_time = isset($options['cache_time']) ? $options['cache_time'] : 0;
$doc = JFactory::getFeedParser($options['rssUrl'], $cache_time);
break;
case 'simple':
// JError::raiseWarning('SOME_ERROR_CODE', 'JSimpleXML is deprecated. Use JFactory::getXML instead');
jimport('joomla.utilities.simplexml');
$doc = new JSimpleXML();
break;
case 'dom':
JError::raiseWarning('SOME_ERROR_CODE', 'DommitDocument is deprecated. Use DomDocument instead');
$doc = null;
break;
throw new JException('DommitDocument is deprecated. Use DomDocument instead');
default:
$doc = null;
}
return $doc;
}
示例9: renderFeed
/**
* 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') {
$rssDoc = JFactory::getFeedParser($url, 900);
if (!$rssDoc) {
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('&', '&', $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(''', "'", $text);
$texts = explode(' ', $text);
//.........这里部分代码省略.........
示例10: render
public static function render($params)
{
// module params
$rssurl = $params->get('rssurl', '');
$rssitems = $params->get('rssitems', 5);
$rssdesc = $params->get('rssdesc', 1);
$rssimage = $params->get('rssimage', 1);
$rssitemdesc = $params->get('rssitemdesc', 1);
$words = $params->def('word_count', 0);
$rsstitle = $params->get('rsstitle', 1);
$rssrtl = $params->get('rssrtl', 0);
$moduleclass_sfx = $params->get('moduleclass_sfx', '');
$filter = JFilterInput::getInstance();
// get RSS parsed object
$cache_time = 0;
if ($params->get('cache')) {
/*
* The cache_time will get fed into JCache to initiate the feed_parser cache group and eventually
* JCacheStorage will multiply the value by 60 and use that for its lifetime. The only way to sync
* the feed_parser cache (which caches with an empty dataset anyway) with the module cache is to
* first divide the module's cache time by 60 then inject that forward, which once stored into the
* JCacheStorage object, will be the correct value in minutes.
*/
$cache_time = $params->get('cache_time', 15) / 60;
}
$rssDoc = JFactory::getFeedParser($rssurl, $cache_time);
if ($rssDoc != false) {
// 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());
// channel image if exists
$image['url'] = $rssDoc->get_image_url();
$image['title'] = $rssDoc->get_image_title();
//image handling
$iUrl = isset($image['url']) ? $image['url'] : null;
$iTitle = isset($image['title']) ? $image['title'] : null;
// items
$items = $rssDoc->get_items();
// feed elements
$items = array_slice($items, 0, $rssitems);
?>
<table cellpadding="0" cellspacing="0" class="moduletable<?php
echo htmlspecialchars($params->get('moduleclass_sfx'));
?>
">
<?php
// feed description
if (!is_null($channel['title']) && $rsstitle) {
?>
<tr>
<td>
<strong>
<a href="<?php
echo htmlspecialchars(str_replace('&', '&', $channel['link']));
?>
" target="_blank">
<?php
echo htmlspecialchars($channel['title']);
?>
</a>
</strong>
</td>
</tr>
<?php
}
// feed description
if ($rssdesc) {
?>
<tr>
<td>
<?php
echo $channel['description'];
?>
</td>
</tr>
<?php
}
// feed image
if ($rssimage && $iUrl) {
?>
<tr>
<td align="center">
<img src="<?php
echo htmlspecialchars($iUrl);
?>
" alt="<?php
echo htmlspecialchars(@$iTitle);
?>
"/>
</td>
</tr>
<?php
}
$actualItems = count($items);
$setItems = $rssitems;
if ($setItems > $actualItems) {
$totalItems = $actualItems;
} else {
$totalItems = $setItems;
//.........这里部分代码省略.........
示例11: renderJEventsNewsCached25
function renderJEventsNewsCached25()
{
$output = '';
// get RSS parsed object
$options = array();
$options['rssUrl'] = 'https://www.jevents.net/jevnews?format=feed&type=rss';
$options['cache_time'] = 0;
error_reporting(0);
ini_set('display_errors', 0);
$rssDoc = JFactory::getFeedParser($options['rssUrl'], $options['cache_time']);
//$rssDoc = JFactory::getXMLparser('RSS', $options);
if ($rssDoc == false) {
$output = JText::_('Error: Feed not retrieved');
} else {
// channel header and link
$title = str_replace(" ", "_", $rssDoc->get_title());
$link = $rssDoc->get_link();
$output = '<table class="adminlist table table-striped">';
$output .= '<tr><th><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::_('JEV_No_news') . '</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>';
if ($item->get_description()) {
$description = $this->limitText($item->get_description(), 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;
}
示例12: getFeedParser
public static function getFeedParser($url)
{
return JFactory::getFeedParser($url);
}
示例13: dataFromRSS
/**
* get list of items from rss list and process caching.
*
* @param JParameter $params.
* @return array list of articles
*/
public static function dataFromRSS($params)
{
$data = array();
if (trim($params->get('rss_link')) == '') {
return $data;
}
$rssUrl = $params->get('rss_link');
// get RSS parsed object
$options = array();
$options['rssUrl'] = $rssUrl;
if ($params->get('enable_cache')) {
$options['cache_time'] = $params->get('cache_time', '30');
$options['cache_time'] *= 60;
} else {
$options['cache_time'] = null;
}
if (version_compare(JVERSION, '3.0', 'ge')) {
$rssDoc = JFactory::getFeedParser($rssUrl, $options['cache_time']);
} else {
if (version_compare(JVERSION, '2.5', 'ge')) {
$rssDoc = JFactory::getXMLparser('RSS', $options);
} else {
$rssDoc = JFactory::getXMLparser('RSS', $options);
}
}
if ($rssDoc != false) {
$items = $rssDoc->get_items();
if ($items != null) {
$tmp = array();
foreach ($items as $item) {
$obj = new stdClass();
$obj->title = $item->get_title();
$obj->link = $item->get_link();
$obj->introtext = $item->get_description();
$tmp[] = $obj;
}
$data = $tmp;
}
}
return $data;
}
示例14: display
public function display()
{
$this->feed = JFactory::getFeedParser($this->module->params->get('rssurl'), $this->module->params->get('cache_time', 15) * 60);
return parent::display();
}
示例15: display
/**
* @since 1.6
*/
function display($tpl = null)
{
// Initialise variables.
$app = JFactory::getApplication();
$user = JFactory::getUser();
$dispatcher = JDispatcher::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 = JModel::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);
// get RSS parsed object
$rssDoc = JFactory::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();
//.........这里部分代码省略.........