PageRenderTime 52ms CodeModel.GetById 24ms RepoModel.GetById 0ms app.codeStats 0ms

/components/com_newsfeeds/views/newsfeed/view.html.php

https://github.com/joebushi/joomla
PHP | 129 lines | 77 code | 22 blank | 30 comment | 11 complexity | 03462050e769372cae0978f27d6f5cc5 MD5 | raw file
Possible License(s): LGPL-2.1, Apache-2.0
  1. <?php
  2. /**
  3. * version $Id$
  4. * @package Joomla
  5. * @subpackage Newsfeeds
  6. * @copyright Copyright (C) 2005 - 2010 Open Source Matters, Inc. All rights reserved.
  7. * @license GNU General Public License version 2 or later; see LICENSE.txt
  8. *
  9. */
  10. // Check to ensure this file is included in Joomla!
  11. defined('_JEXEC') or die;
  12. jimport('joomla.application.component.view');
  13. /**
  14. * HTML View class for the Newsfeeds component
  15. *
  16. * @static
  17. * @package Joomla
  18. * @subpackage Newsfeeds
  19. * @since 1.0
  20. */
  21. class NewsfeedsViewNewsfeed extends JView
  22. {
  23. function display($tpl = null)
  24. {
  25. $app = JFactory::getApplication();
  26. // check if cache directory is writeable
  27. $cacheDir = JPATH_BASE.DS.'cache'.DS;
  28. if (!is_writable($cacheDir)) {
  29. echo JText::_('CACHE_DIRECTORY_UNWRITABLE');
  30. return;
  31. }
  32. // Get some objects from the JApplication
  33. $pathway = &$app->getPathway();
  34. $document = &JFactory::getDocument();
  35. // Get the current menu item
  36. $menus = &JSite::getMenu();
  37. $menu = $menus->getActive();
  38. $params = &$app->getParams();
  39. //get the newsfeed
  40. $newsfeed = &$this->get('data');
  41. // get RSS parsed object
  42. $options = array();
  43. $options['rssUrl'] = $newsfeed->link;
  44. $options['cache_time'] = $newsfeed->cache_time;
  45. $rssDoc = &JFactory::getXMLparser('RSS', $options);
  46. if ($rssDoc == false) {
  47. $msg = JText::_('Error: Feed not retrieved');
  48. $app->redirect('index.php?option=com_newsfeeds&view=category&id='. $newsfeed->catslug, $msg);
  49. return;
  50. }
  51. $lists = array();
  52. // channel header and link
  53. $newsfeed->channel['title'] = $rssDoc->get_title();
  54. $newsfeed->channel['link'] = $rssDoc->get_link();
  55. $newsfeed->channel['description'] = $rssDoc->get_description();
  56. $newsfeed->channel['language'] = $rssDoc->get_language();
  57. // channel image if exists
  58. $newsfeed->image['url'] = $rssDoc->get_image_url();
  59. $newsfeed->image['title'] = $rssDoc->get_image_title();
  60. $newsfeed->image['link'] = $rssDoc->get_image_link();
  61. $newsfeed->image['height'] = $rssDoc->get_image_height();
  62. $newsfeed->image['width'] = $rssDoc->get_image_width();
  63. // items
  64. $newsfeed->items = $rssDoc->get_items();
  65. // feed elements
  66. $newsfeed->items = array_slice($newsfeed->items, 0, $newsfeed->numarticles);
  67. // Set page title
  68. // because the application sets a default page title, we need to get it
  69. // right from the menu item itself
  70. if (is_object($menu)) {
  71. $menu_params = new JParameter($menu->params);
  72. if (!$menu_params->get('page_title')) {
  73. $params->set('page_title', $newsfeed->name);
  74. }
  75. } else {
  76. $params->set('page_title', $newsfeed->name);
  77. }
  78. $document->setTitle($params->get('page_title'));
  79. //set breadcrumbs
  80. $viewname = JRequest::getString('view');
  81. if ($viewname == 'categories') {
  82. $pathway->addItem($newsfeed->category, 'index.php?view=category&id='.$newsfeed->catslug);
  83. }
  84. $pathway->addItem($newsfeed->name, '');
  85. $this->assignRef('params' , $params );
  86. $this->assignRef('newsfeed', $newsfeed);
  87. parent::display($tpl);
  88. }
  89. function limitText($text, $wordcount)
  90. {
  91. if (!$wordcount) {
  92. return $text;
  93. }
  94. $texts = explode(' ', $text);
  95. $count = count($texts);
  96. if ($count > $wordcount)
  97. {
  98. $text = '';
  99. for ($i=0; $i < $wordcount; $i++) {
  100. $text .= ' '. $texts[$i];
  101. }
  102. $text .= '...';
  103. }
  104. return $text;
  105. }
  106. }
  107. ?>