/administrator/modules/mod_feed/helper.php
PHP | 166 lines | 129 code | 14 blank | 23 comment | 14 complexity | 011b1ee08fc2ac52583c5b99dac229c9 MD5 | raw file
Possible License(s): LGPL-2.1, Apache-2.0
- <?php
- /**
- * @version $Id$
- * @copyright Copyright (C) 2005 - 2010 Open Source Matters, Inc. All rights reserved.
- * @license GNU General Public License version 2 or later; see LICENSE.txt
- */
- // No direct access.
- defined('_JEXEC') or die;
- /**
- * @package Joomla.Administrator
- * @subpackage mod_feed
- */
- abstract class modFeedHelper
- {
- 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', '');
- // get RSS parsed object
- $options = array();
- $options['rssUrl'] = $rssurl;
- if ($params->get('cache')) {
- $options['cache_time'] = $params->get('cache_time', 15) ;
- $options['cache_time'] *= 60;
- } else {
- $options['cache_time'] = null;
- }
- $rssDoc = &JFactory::getXMLparser('RSS', $options);
- if ($rssDoc != false)
- {
- // channel header and link
- $channel['title'] = $rssDoc->get_title();
- $channel['link'] = $rssDoc->get_link();
- $channel['description'] = $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 $params->get('moduleclass_sfx'); ?>">
- <?php
- // feed description
- if (!is_null($channel['title']) && $rsstitle) {
- ?>
- <tr>
- <td>
- <strong>
- <a href="<?php echo str_replace('&', '&', $channel['link']); ?>" target="_blank">
- <?php echo $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 $iUrl; ?>" alt="<?php echo @$iTitle; ?>"/>
- </td>
- </tr>
- <?php
- }
- $actualItems = count($items);
- $setItems = $rssitems;
- if ($setItems > $actualItems) {
- $totalItems = $actualItems;
- } else {
- $totalItems = $setItems;
- }
- ?>
- <tr>
- <td>
- <ul class="newsfeed<?php echo $moduleclass_sfx; ?>" >
- <?php
- for ($j = 0; $j < $totalItems; $j ++)
- {
- $currItem = & $items[$j];
- // item title
- ?>
- <li>
- <?php
- if (!is_null($currItem->get_link())) {
- ?>
- <a href="<?php echo $currItem->get_link(); ?>" target="_child">
- <?php echo $currItem->get_title(); ?></a>
- <?php
- }
- // item description
- if ($rssitemdesc)
- {
- // item description
- $text = html_entity_decode($currItem->get_description());
- $text = str_replace(''', "'", $text);
- // word limit check
- if ($words) {
- $texts = explode(' ', $text);
- $count = count($texts);
- if ($count > $words) {
- $text = '';
- for ($i = 0; $i < $words; $i ++)
- {
- $text .= ' '.$texts[$i];
- }
- $text .= '...';
- }
- }
- ?>
- <div style="text-align: <?php echo $rssrtl ? 'right': 'left'; ?> !important">
- <?php echo $text; ?>
- </div>
- <?php
- }
- ?>
- </li>
- <?php
- }
- ?>
- </ul>
- </td>
- </tr>
- </table>
- <?php
- }
- }
- }