PageRenderTime 54ms CodeModel.GetById 7ms RepoModel.GetById 0ms app.codeStats 0ms

/4.6/components/com_content/content.feed.php

http://miacms.googlecode.com/
PHP | 379 lines | 273 code | 40 blank | 66 comment | 36 complexity | b3b4c530f0f25a0d87d222bc55793617 MD5 | raw file
Possible License(s): LGPL-2.1, GPL-2.0, LGPL-2.0
  1. <?php
  2. /**
  3. * @package MiaCMS
  4. * @subpackage Content
  5. * @author MiaCMS see README.php
  6. * @copyright see README.php
  7. * See COPYRIGHT.php for copyright notices and details.
  8. * @license GNU/GPL Version 2, see LICENSE.php
  9. * MiaCMS is free software; you can redistribute it and/or
  10. * modify it under the terms of the GNU General Public License
  11. * as published by the Free Software Foundation; version 2 of the License.
  12. */
  13. /** ensure this file is being included by a parent file */
  14. defined( '_VALID_MOS' ) or die( 'Direct Access to this location is not allowed.' );
  15. global $mosConfig_absolute_path;
  16. // load feed creator class
  17. require_once( $mosConfig_absolute_path .'/includes/feedcreator.class.php' );
  18. $contentfeed =& new ContentFeed();
  19. $contentfeed->show();
  20. /**
  21. * content Feed class for Mambo
  22. * @author Robert Deutz
  23. */
  24. class ContentFeed
  25. {
  26. /** hold the parameters **/
  27. var $params;
  28. /**
  29. * class constructor
  30. */
  31. function __construct()
  32. {
  33. $this->getParameters();
  34. }
  35. /**
  36. * php4 class constructor
  37. */
  38. function ContentFeed()
  39. {
  40. $this->__construct();
  41. }
  42. /**
  43. * Get the component parameters
  44. */
  45. function getParameters () {
  46. global $database,$mainframe,$mosConfig_offset, $mosConfig_live_site;
  47. // get id of the syndication component
  48. $query = "SELECT a.id"
  49. . "\n FROM #__components AS a"
  50. . "\n WHERE a.name = 'Syndicate'";
  51. $database->setQuery( $query );
  52. $id = $database->loadResult();
  53. // load the row from the database table
  54. $row = new mosComponent( $database );
  55. $row->load( $id );
  56. // get syndication param definitions
  57. $params =& new mosParameters( $row->params, $mainframe->getPath( 'com_xml', $row->option ), 'component' );
  58. if (method_exists($database,"getNullDate")) {
  59. $params->nullDate = $database->getNullDate();
  60. } else {
  61. $params->nullDate = '0000-00-00 00:00:00';
  62. }
  63. $params->now = date( 'Y-m-d H:i:s', time() + $mosConfig_offset * 60 * 60 );
  64. $iso = split( '=', _ISO );
  65. // parameter intilization
  66. $params->date = date( 'r' );
  67. $params->year = date( 'Y' );
  68. $params->encoding = $iso[1];
  69. $params->link = htmlspecialchars( $mosConfig_live_site );
  70. $params->cache = $params->def( 'cache', 1 );
  71. $params->cache_time = $params->def( 'cache_time', 3600 );
  72. $params->count = $params->def( 'count', 5 );
  73. $params->orderby = $params->def( 'orderby', '' );
  74. $params->title = $params->def( 'title', 'MiaCMS powered Site' );
  75. $params->description = $params->def( 'description', 'MiaCMS site syndication' );
  76. $params->image_file = $params->def( 'image_file', 'miacms_logo.png' );
  77. if ( $params->image_file == -1 ) {
  78. $params->image = NULL;
  79. } else{
  80. $params->image = $mosConfig_live_site .'/images/'. $params->image_file;
  81. }
  82. $params->image_alt = $params->def( 'image_alt', 'Powered by MiaCMS' );
  83. $params->limit_text = $params->def( 'limit_text', 1 );
  84. $params->text_length = $params->def( 'text_length', 20 );
  85. // get feed type from url
  86. $params->feed = mosGetParam( $_GET, 'feed', 'RSS2.0' );
  87. $params->option = mosGetParam ($_GET, 'option', 'com_content') ;
  88. $params->frontpage = $params->option == 'com_frontpage';
  89. $this->params=$params;
  90. return true;
  91. }
  92. /**
  93. * get the items for the feed
  94. */
  95. function getData ($section=0,$cat=0) {
  96. global $database;
  97. $params=$this->params;
  98. $this->rows=array();
  99. // Determine ordering for sql
  100. switch ( strtolower( $params->orderby ) ) {
  101. case 'date':
  102. $orderby = 'a.created';
  103. break;
  104. case 'rdate':
  105. $orderby = 'a.created DESC';
  106. break;
  107. case 'alpha':
  108. $orderby = 'a.title';
  109. break;
  110. case 'ralpha':
  111. $orderby = 'a.title DESC';
  112. break;
  113. case 'hits':
  114. $orderby = 'a.hits DESC';
  115. break;
  116. case 'rhits':
  117. $orderby = 'a.hits ASC';
  118. break;
  119. case 'front':
  120. if ($params->frontpage)
  121. {
  122. $orderby = 'f.ordering';
  123. } else {
  124. $orderby = 'a.created DESC';
  125. }
  126. break;
  127. default:
  128. if ($params->frontpage)
  129. {
  130. $orderby = 'f.ordering';
  131. } else {
  132. $orderby = 'a.created DESC';
  133. }
  134. break;
  135. }
  136. $nullDate = $params->nullDate;
  137. $now = $params->now;
  138. $and = '';
  139. $join = '';
  140. if ($params->frontpage)
  141. {
  142. $join = "\n ,#__content_frontpage AS f ";
  143. $and = "\n AND f.content_id = a.id";
  144. }
  145. else
  146. {
  147. if (is_array($section))
  148. {
  149. // we show a multi section rss feed
  150. $and = "\n AND a.sectionid in (".implode(',',$section).")";
  151. }
  152. else
  153. {
  154. if (is_array($cat))
  155. {
  156. // we show a multi category rss feed
  157. $and = "\n AND a.catid in (".implode(',',$cat).")";
  158. }
  159. else
  160. {
  161. if ($section == 0)
  162. {
  163. if ($cat == 0)
  164. {
  165. // error: all values 0, so we do not display anything
  166. }
  167. else
  168. {
  169. // we show a category
  170. $and = "\n AND a.catid = $cat";
  171. }
  172. }
  173. else
  174. {
  175. // we show a section
  176. $and = "\n AND a.sectionid = $section";
  177. }
  178. }
  179. }
  180. }
  181. // query of content items
  182. $query = "SELECT a.*, u.name AS author, u.usertype, UNIX_TIMESTAMP( a.created ) AS created_ts"
  183. . "\n FROM #__content AS a LEFT JOIN #__users AS u ON u.id = a.created_by"
  184. . $join
  185. . "\n WHERE a.state = 1"
  186. . $and
  187. . "\n AND a.access = 0"
  188. . "\n AND ( publish_up = '$nullDate' OR publish_up <= '$now' )"
  189. . "\n AND ( publish_down = '$nullDate' OR publish_down >= '$now' )"
  190. . "\n ORDER BY $orderby"
  191. . ( $params->count ? "\n LIMIT ". $params->count : '' )
  192. ;
  193. $database->setQuery( $query );
  194. //echo $database->getQuery( );
  195. $this->rows = $database->loadObjectList();
  196. return true;
  197. }
  198. function feed( $file ) {
  199. global $database, $mainframe, $Itemid;
  200. global $mosConfig_live_site, $mosConfig_offset, $mosConfig_absolute_path,$mosConfig_sef;
  201. $params = $this->params;
  202. // load feed creator class
  203. $rss = new UniversalFeedCreator();
  204. // load image creator class
  205. $image = new FeedImage();
  206. // loads cache file
  207. if ( $params->cache ) {
  208. //$rss->useCached( $params->feed, $file, $params->cache_time );
  209. }
  210. $rss->title = $params->title;
  211. $rss->description = $params->description;
  212. $rss->link = $params->link;
  213. $rss->syndicationURL = $params->link;
  214. $rss->cssStyleSheet = NULL;
  215. $rss->encoding = $params->encoding;
  216. if ( $params->image )
  217. {
  218. $image->url = $params->image;
  219. $image->link = $params->link;
  220. $image->title = $params->image_alt;
  221. $image->description = $params->description;
  222. // loads image info into rss array
  223. $rss->image = $image;
  224. }
  225. $rows =& $this->rows;
  226. $cr = count($rows);
  227. if ( $cr != 0 )
  228. {
  229. for ($i=0;$i < $cr ;$i++)
  230. {
  231. $row= $rows[$i];
  232. // title for particular item
  233. $item_title = htmlspecialchars( $row->title );
  234. $item_title = html_entity_decode( $item_title );
  235. $_Itemid = $mainframe->getItemid( $row->id );
  236. if ( $_Itemid == 0 )
  237. {
  238. $itemid = $Itemid;
  239. }
  240. else
  241. {
  242. $itemid = $_Itemid;
  243. }
  244. // url link to article (& used instead of &amp; as this is converted by feed creator)
  245. /* Build the $item_link a bit differently for SEF since sefRelToAbs doesn't convert the URL properly when
  246. passed $mosConfig_live_site. No SEF needs $mosConfig_live_site, else &amp; becomes an issue. */
  247. if ($mosConfig_sef > 0) {
  248. $item_link = htmlentities('index.php?option=com_content&task=view&id='. $row->id .'&Itemid='. $itemid);
  249. } else {
  250. $item_link = htmlentities($mosConfig_live_site .'/index.php?option=com_content&task=view&id='. $row->id .'&Itemid='. $itemid);
  251. }
  252. $item_link = sefRelToAbs( $item_link );
  253. // removes all formating from the intro text for the description text
  254. $item_description = $row->introtext;
  255. $item_description = mosHTML::cleanText( $item_description );
  256. $item_description = html_entity_decode( $item_description );
  257. if ( $params->limit_text ) {
  258. if ( $params->text_length ) {
  259. // limits description text to x words
  260. $item_description_array = split( ' ', $item_description );
  261. $count = count( $item_description_array );
  262. if ( $count > $params->text_length ) {
  263. $item_description = '';
  264. for ( $a = 0; $a < $params->text_length; $a++ ) {
  265. $item_description .= $item_description_array[$a]. ' ';
  266. }
  267. $item_description = trim( $item_description );
  268. $item_description .= '...';
  269. }
  270. } else {
  271. // do not include description when text_length = 0
  272. $item_description = NULL;
  273. }
  274. }
  275. // load individual item creator class
  276. $item = new FeedItem();
  277. // item info
  278. $item->title = $item_title;
  279. $item->link = $item_link;
  280. $item->description = $item_description;
  281. $item->source = $params->link;
  282. $item->date = date( 'r', $row->created_ts );
  283. // loads item info into rss array
  284. $rss->addItem( $item );
  285. }
  286. }
  287. //save feed file
  288. $rss->saveFeed( $params->feed, $file );
  289. }
  290. /**
  291. * generic show method
  292. */
  293. function show()
  294. {
  295. global $database, $mainframe, $Itemid,$mosConfig_absolute_path;
  296. // check the feed type
  297. $feed = strtolower(str_replace('.', '', $this->params->feed));
  298. $legal = array ('rss20', 'rss10', 'rss091', 'atom10', 'opml');
  299. $legalTasks = array ('section', 'blogsection', 'category', 'categorysection', 'frontpage');
  300. if (!in_array($feed, $legal))
  301. {
  302. echo "wrong feed type";
  303. mosNotAuth();
  304. return '';
  305. }
  306. if(isset($_GET['task']) AND in_array($_GET['task'], $legalTasks)){
  307. $mtype = mosGetParam ($_GET, 'task');
  308. } else {
  309. //revert to frontpage if theres no task
  310. $mtype = "frontpage";
  311. }
  312. $section=0;
  313. $cat=0;
  314. switch ($mtype)
  315. {
  316. case 'section':
  317. $section = mosGetParam ($_GET, 'id', 0) ;
  318. break;
  319. case 'blogsection':
  320. $section = mosGetParam ($_GET, 'id', 0) ;
  321. break;
  322. case 'category':
  323. $cat = mosGetParam ($_GET, 'id', 0) ;
  324. break;
  325. case 'categorysection':
  326. $cat = mosGetParam ($_GET, 'id', 0) ;
  327. break;
  328. default:
  329. //frontpage
  330. break;
  331. }
  332. // get the data for the feed
  333. $this->getData($section,$cat);
  334. $file = $mosConfig_absolute_path .'/cache/'. $Itemid .'_'.$feed . '.xml';
  335. $this->feed( $file );
  336. return true;
  337. }
  338. }
  339. ?>