PageRenderTime 71ms CodeModel.GetById 14ms RepoModel.GetById 0ms app.codeStats 0ms

/components/com_rss/rss.php

https://bitbucket.org/dgough/annamaria-daneswood-25102012
PHP | 307 lines | 219 code | 40 blank | 48 comment | 26 complexity | c45e84ca8c94df886a578585e3784253 MD5 | raw file
Possible License(s): GPL-2.0, LGPL-2.1
  1. <?php
  2. /**
  3. * @version $Id: rss.php 10002 2008-02-08 10:56:57Z willebil $
  4. * @package Joomla
  5. * @subpackage Syndicate
  6. * @copyright Copyright (C) 2005 Open Source Matters. All rights reserved.
  7. * @license http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL, see LICENSE.php
  8. * Joomla! is free software. This version may have been modified pursuant
  9. * to the GNU General Public License, and as distributed it includes or
  10. * is derivative of works licensed under the GNU General Public License or
  11. * other free or open source software licenses.
  12. * See COPYRIGHT.php for copyright notices and details.
  13. */
  14. // no direct access
  15. defined( '_VALID_MOS' ) or die( 'Restricted access' );
  16. // load feed creator class
  17. require_once( $mosConfig_absolute_path .'/includes/feedcreator.class.php' );
  18. $info = null;
  19. $rss = null;
  20. switch ( $task ) {
  21. case 'live_bookmark':
  22. feedFrontpage( false );
  23. break;
  24. default:
  25. feedFrontpage( true );
  26. break;
  27. }
  28. /*
  29. * Creates feed from Content Iems associated to teh frontpage component
  30. */
  31. function feedFrontpage( $showFeed ) {
  32. global $database, $mainframe;
  33. global $mosConfig_live_site, $mosConfig_cachepath;
  34. $nullDate = $database->getNullDate();
  35. // pull id of syndication component
  36. $query = "SELECT a.id"
  37. . "\n FROM #__components AS a"
  38. . "\n WHERE ( a.admin_menu_link = 'option=com_syndicate' OR a.admin_menu_link = 'option=com_syndicate&hidemainmenu=1' )"
  39. . "\n AND a.option = 'com_syndicate'"
  40. ;
  41. $database->setQuery( $query );
  42. $id = $database->loadResult();
  43. // load syndication parameters
  44. $component = new mosComponent( $database );
  45. $component->load( (int)$id );
  46. $params = new mosParameters( $component->params );
  47. // test if security check is enbled
  48. $check = $params->def( 'check', 1 );
  49. if($check) {
  50. // test if rssfeed module is published
  51. // if not disable access
  52. $query = "SELECT m.id"
  53. . "\n FROM #__modules AS m"
  54. . "\n WHERE m.module = 'mod_rssfeed'"
  55. . "\n AND m.published = 1"
  56. ;
  57. $database->setQuery( $query );
  58. $check = $database->loadResultArray();
  59. if(empty($check)) {
  60. mosNotAuth();
  61. return;
  62. }
  63. }
  64. $now = _CURRENT_SERVER_TIME;
  65. $iso = split( '=', _ISO );
  66. // parameter intilization
  67. $info[ 'date' ] = date( 'r' );
  68. $info[ 'year' ] = date( 'Y' );
  69. $info[ 'encoding' ] = $iso[1];
  70. $info[ 'link' ] = htmlspecialchars( $mosConfig_live_site );
  71. $info[ 'cache' ] = $params->def( 'cache', 1 );
  72. $info[ 'cache_time' ] = $params->def( 'cache_time', 3600 );
  73. $info[ 'count' ] = $params->def( 'count', 5 );
  74. $info[ 'orderby' ] = $params->def( 'orderby', '' );
  75. $info[ 'title' ] = $params->def( 'title', 'Joomla! powered Site' );
  76. $info[ 'description' ] = $params->def( 'description', 'Joomla! site syndication' );
  77. $info[ 'image_file' ] = $params->def( 'image_file', 'joomla_rss.png' );
  78. if ( $info[ 'image_file' ] == -1 ) {
  79. $info[ 'image' ] = NULL;
  80. } else{
  81. $info[ 'image' ] = $mosConfig_live_site .'/images/M_images/'. $info[ 'image_file' ];
  82. }
  83. $info[ 'image_alt' ] = $params->def( 'image_alt', 'Powered by Joomla!' );
  84. $info[ 'limit_text' ] = $params->def( 'limit_text', 0 );
  85. $info[ 'text_length' ] = $params->def( 'text_length', 20 );
  86. // get feed type from url
  87. $info[ 'feed' ] = strval( mosGetParam( $_GET, 'feed', 'RSS2.0' ) );
  88. // live bookmarks
  89. $info[ 'live_bookmark' ] = $params->def( 'live_bookmark', '' );
  90. $info[ 'bookmark_file' ] = $params->def( 'bookmark_file', '' );
  91. // set filename for live bookmarks feed
  92. if ( !$showFeed & $info[ 'live_bookmark' ] ) {
  93. if ( $info[ 'bookmark_file' ] ) {
  94. // custom bookmark filename
  95. $filename = $info[ 'bookmark_file' ];
  96. } else {
  97. // standard bookmark filename
  98. $filename = $info[ 'live_bookmark' ];
  99. }
  100. } else {
  101. // set filename for rss feeds
  102. $info[ 'file' ] = strtolower( str_replace( '.', '', $info[ 'feed' ] ) );
  103. // security check to limit arbitrary file creation.
  104. // and to allow disabling/enabling of selected feed types
  105. switch ( $info[ 'file' ] ) {
  106. case 'rss091':
  107. if ( !$params->get( 'rss091', 1 ) ) {
  108. echo _NOT_AUTH;
  109. return;
  110. }
  111. break;
  112. case 'rss10':
  113. if ( !$params->get( 'rss10', 1 ) ) {
  114. echo _NOT_AUTH;
  115. return;
  116. }
  117. break;
  118. case 'rss20':
  119. if ( !$params->get( 'rss20', 1 ) ) {
  120. echo _NOT_AUTH;
  121. return;
  122. }
  123. break;
  124. case 'atom03':
  125. if ( !$params->get( 'atom03', 1 ) ) {
  126. echo _NOT_AUTH;
  127. return;
  128. }
  129. break;
  130. case 'opml':
  131. if ( !$params->get( 'opml', 1 ) ) {
  132. echo _NOT_AUTH;
  133. return;
  134. }
  135. break;
  136. default:
  137. echo _NOT_AUTH;
  138. return;
  139. break;
  140. }
  141. }
  142. $filename = $info[ 'file' ] .'.xml';
  143. // security check to stop server path disclosure
  144. if ( strstr( $filename, '/' ) ) {
  145. echo _NOT_AUTH;
  146. return;
  147. }
  148. $info[ 'file' ] = $mosConfig_cachepath .'/'. $filename;
  149. // load feed creator class
  150. $rss = new UniversalFeedCreator();
  151. // load image creator class
  152. $image = new FeedImage();
  153. // loads cache file
  154. if ( $showFeed && $info[ 'cache' ] ) {
  155. $rss->useCached( $info[ 'feed' ], $info[ 'file' ], $info[ 'cache_time' ] );
  156. }
  157. $rss->title = $info[ 'title' ];
  158. $rss->description = $info[ 'description' ];
  159. $rss->link = $info[ 'link' ];
  160. $rss->syndicationURL = $info[ 'link' ];
  161. $rss->cssStyleSheet = NULL;
  162. $rss->encoding = $info[ 'encoding' ];
  163. if ( $info[ 'image' ] ) {
  164. $image->url = $info[ 'image' ];
  165. $image->link = $info[ 'link' ];
  166. $image->title = $info[ 'image_alt' ];
  167. $image->description = $info[ 'description' ];
  168. // loads image info into rss array
  169. $rss->image = $image;
  170. }
  171. // Determine ordering for sql
  172. switch ( strtolower( $info[ 'orderby' ] ) ) {
  173. case 'date':
  174. $orderby = 'a.created';
  175. break;
  176. case 'rdate':
  177. $orderby = 'a.created DESC';
  178. break;
  179. case 'alpha':
  180. $orderby = 'a.title';
  181. break;
  182. case 'ralpha':
  183. $orderby = 'a.title DESC';
  184. break;
  185. case 'hits':
  186. $orderby = 'a.hits DESC';
  187. break;
  188. case 'rhits':
  189. $orderby = 'a.hits ASC';
  190. break;
  191. case 'front':
  192. $orderby = 'f.ordering';
  193. break;
  194. default:
  195. $orderby = 'f.ordering';
  196. break;
  197. }
  198. // query of frontpage content items
  199. $query = "SELECT a.*, u.name AS author, u.usertype, UNIX_TIMESTAMP( a.created ) AS created_ts, cat.title AS cat_title, sec.title AS section_title"
  200. . "\n FROM #__content AS a"
  201. . "\n INNER JOIN #__content_frontpage AS f ON f.content_id = a.id"
  202. . "\n LEFT JOIN #__users AS u ON u.id = a.created_by"
  203. . "\n LEFT JOIN #__categories AS cat ON cat.id = a.catid"
  204. . "\n LEFT JOIN #__sections AS sec ON sec.id = a.sectionid"
  205. . "\n WHERE a.state = 1"
  206. . "\n AND cat.published = 1"
  207. . "\n AND sec.published = 1"
  208. . "\n AND a.access = 0"
  209. . "\n AND cat.access = 0"
  210. . "\n AND sec.access = 0"
  211. . "\n AND ( a.publish_up = " . $database->Quote( $nullDate ) . " OR a.publish_up <= " . $database->Quote( $now ) . " )"
  212. . "\n AND ( a.publish_down = " . $database->Quote( $nullDate ) . " OR a.publish_down >= " . $database->Quote( $now ) . " )"
  213. . "\n ORDER BY $orderby"
  214. ;
  215. $database->setQuery( $query, 0, $info[ 'count' ] );
  216. $rows = $database->loadObjectList();
  217. foreach ( $rows as $row ) {
  218. // title for particular item
  219. $item_title = htmlspecialchars( $row->title );
  220. $item_title = html_entity_decode( $item_title );
  221. // url link to article
  222. // & used instead of &amp; as this is converted by feed creator
  223. $_Itemid = '';
  224. $itemid = $mainframe->getItemid( $row->id );
  225. if ($itemid) {
  226. $_Itemid = '&Itemid='. $itemid;
  227. }
  228. $item_link = 'index.php?option=com_content&task=view&id='. $row->id . $_Itemid;
  229. $item_link = sefRelToAbs( $item_link );
  230. // removes all formating from the intro text for the description text
  231. $item_description = $row->introtext;
  232. $item_description = mosHTML::cleanText( $item_description );
  233. $item_description = html_entity_decode( $item_description );
  234. if ( $info[ 'limit_text' ] ) {
  235. if ( $info[ 'text_length' ] ) {
  236. // limits description text to x words
  237. $item_description_array = split( ' ', $item_description );
  238. $count = count( $item_description_array );
  239. if ( $count > $info[ 'text_length' ] ) {
  240. $item_description = '';
  241. for ( $a = 0; $a < $info[ 'text_length' ]; $a++ ) {
  242. $item_description .= $item_description_array[$a]. ' ';
  243. }
  244. $item_description = trim( $item_description );
  245. $item_description .= '...';
  246. }
  247. } else {
  248. // do not include description when text_length = 0
  249. $item_description = NULL;
  250. }
  251. }
  252. // load individual item creator class
  253. $item = new FeedItem();
  254. // item info
  255. $item->title = $item_title;
  256. $item->link = $item_link;
  257. $item->description = $item_description;
  258. $item->source = $info[ 'link' ];
  259. $item->date = date( 'r', $row->created_ts );
  260. $item->category = $row->section_title . ' - ' . $row->cat_title;
  261. // loads item info into rss array
  262. $rss->addItem( $item );
  263. }
  264. // save feed file
  265. $rss->saveFeed( $info[ 'feed' ], $info[ 'file' ], $showFeed );
  266. }
  267. ?>