PageRenderTime 48ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 0ms

/administrator/modules/mod_feed/helper.php

https://github.com/joebushi/joomla
PHP | 166 lines | 129 code | 14 blank | 23 comment | 14 complexity | 011b1ee08fc2ac52583c5b99dac229c9 MD5 | raw file
Possible License(s): LGPL-2.1, Apache-2.0
  1. <?php
  2. /**
  3. * @version $Id$
  4. * @copyright Copyright (C) 2005 - 2010 Open Source Matters, Inc. All rights reserved.
  5. * @license GNU General Public License version 2 or later; see LICENSE.txt
  6. */
  7. // No direct access.
  8. defined('_JEXEC') or die;
  9. /**
  10. * @package Joomla.Administrator
  11. * @subpackage mod_feed
  12. */
  13. abstract class modFeedHelper
  14. {
  15. public static function render($params)
  16. {
  17. // module params
  18. $rssurl = $params->get('rssurl', '');
  19. $rssitems = $params->get('rssitems', 5);
  20. $rssdesc = $params->get('rssdesc', 1);
  21. $rssimage = $params->get('rssimage', 1);
  22. $rssitemdesc = $params->get('rssitemdesc', 1);
  23. $words = $params->def('word_count', 0);
  24. $rsstitle = $params->get('rsstitle', 1);
  25. $rssrtl = $params->get('rssrtl', 0);
  26. $moduleclass_sfx = $params->get('moduleclass_sfx', '');
  27. // get RSS parsed object
  28. $options = array();
  29. $options['rssUrl'] = $rssurl;
  30. if ($params->get('cache')) {
  31. $options['cache_time'] = $params->get('cache_time', 15) ;
  32. $options['cache_time'] *= 60;
  33. } else {
  34. $options['cache_time'] = null;
  35. }
  36. $rssDoc = &JFactory::getXMLparser('RSS', $options);
  37. if ($rssDoc != false)
  38. {
  39. // channel header and link
  40. $channel['title'] = $rssDoc->get_title();
  41. $channel['link'] = $rssDoc->get_link();
  42. $channel['description'] = $rssDoc->get_description();
  43. // channel image if exists
  44. $image['url'] = $rssDoc->get_image_url();
  45. $image['title'] = $rssDoc->get_image_title();
  46. //image handling
  47. $iUrl = isset($image['url']) ? $image['url'] : null;
  48. $iTitle = isset($image['title']) ? $image['title'] : null;
  49. // items
  50. $items = $rssDoc->get_items();
  51. // feed elements
  52. $items = array_slice($items, 0, $rssitems);
  53. ?>
  54. <table cellpadding="0" cellspacing="0" class="moduletable<?php echo $params->get('moduleclass_sfx'); ?>">
  55. <?php
  56. // feed description
  57. if (!is_null($channel['title']) && $rsstitle) {
  58. ?>
  59. <tr>
  60. <td>
  61. <strong>
  62. <a href="<?php echo str_replace('&', '&amp;', $channel['link']); ?>" target="_blank">
  63. <?php echo $channel['title']; ?></a>
  64. </strong>
  65. </td>
  66. </tr>
  67. <?php
  68. }
  69. // feed description
  70. if ($rssdesc) {
  71. ?>
  72. <tr>
  73. <td>
  74. <?php echo $channel['description']; ?>
  75. </td>
  76. </tr>
  77. <?php
  78. }
  79. // feed image
  80. if ($rssimage && $iUrl) {
  81. ?>
  82. <tr>
  83. <td align="center">
  84. <img src="<?php echo $iUrl; ?>" alt="<?php echo @$iTitle; ?>"/>
  85. </td>
  86. </tr>
  87. <?php
  88. }
  89. $actualItems = count($items);
  90. $setItems = $rssitems;
  91. if ($setItems > $actualItems) {
  92. $totalItems = $actualItems;
  93. } else {
  94. $totalItems = $setItems;
  95. }
  96. ?>
  97. <tr>
  98. <td>
  99. <ul class="newsfeed<?php echo $moduleclass_sfx; ?>" >
  100. <?php
  101. for ($j = 0; $j < $totalItems; $j ++)
  102. {
  103. $currItem = & $items[$j];
  104. // item title
  105. ?>
  106. <li>
  107. <?php
  108. if (!is_null($currItem->get_link())) {
  109. ?>
  110. <a href="<?php echo $currItem->get_link(); ?>" target="_child">
  111. <?php echo $currItem->get_title(); ?></a>
  112. <?php
  113. }
  114. // item description
  115. if ($rssitemdesc)
  116. {
  117. // item description
  118. $text = html_entity_decode($currItem->get_description());
  119. $text = str_replace('&apos;', "'", $text);
  120. // word limit check
  121. if ($words) {
  122. $texts = explode(' ', $text);
  123. $count = count($texts);
  124. if ($count > $words) {
  125. $text = '';
  126. for ($i = 0; $i < $words; $i ++)
  127. {
  128. $text .= ' '.$texts[$i];
  129. }
  130. $text .= '...';
  131. }
  132. }
  133. ?>
  134. <div style="text-align: <?php echo $rssrtl ? 'right': 'left'; ?> !important">
  135. <?php echo $text; ?>
  136. </div>
  137. <?php
  138. }
  139. ?>
  140. </li>
  141. <?php
  142. }
  143. ?>
  144. </ul>
  145. </td>
  146. </tr>
  147. </table>
  148. <?php
  149. }
  150. }
  151. }