/4.6/components/com_content/content.feed.php
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
- <?php
- /**
- * @package MiaCMS
- * @subpackage Content
- * @author MiaCMS see README.php
- * @copyright see README.php
- * See COPYRIGHT.php for copyright notices and details.
- * @license GNU/GPL Version 2, see LICENSE.php
- * MiaCMS is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; version 2 of the License.
- */
- /** ensure this file is being included by a parent file */
- defined( '_VALID_MOS' ) or die( 'Direct Access to this location is not allowed.' );
- global $mosConfig_absolute_path;
- // load feed creator class
- require_once( $mosConfig_absolute_path .'/includes/feedcreator.class.php' );
- $contentfeed =& new ContentFeed();
- $contentfeed->show();
- /**
- * content Feed class for Mambo
- * @author Robert Deutz
- */
- class ContentFeed
- {
- /** hold the parameters **/
- var $params;
-
- /**
- * class constructor
- */
- function __construct()
- {
- $this->getParameters();
- }
- /**
- * php4 class constructor
- */
- function ContentFeed()
- {
- $this->__construct();
- }
- /**
- * Get the component parameters
- */
- function getParameters () {
- global $database,$mainframe,$mosConfig_offset, $mosConfig_live_site;
- // get id of the syndication component
- $query = "SELECT a.id"
- . "\n FROM #__components AS a"
- . "\n WHERE a.name = 'Syndicate'";
- $database->setQuery( $query );
- $id = $database->loadResult();
- // load the row from the database table
- $row = new mosComponent( $database );
- $row->load( $id );
- // get syndication param definitions
- $params =& new mosParameters( $row->params, $mainframe->getPath( 'com_xml', $row->option ), 'component' );
- if (method_exists($database,"getNullDate")) {
- $params->nullDate = $database->getNullDate();
- } else {
- $params->nullDate = '0000-00-00 00:00:00';
- }
- $params->now = date( 'Y-m-d H:i:s', time() + $mosConfig_offset * 60 * 60 );
- $iso = split( '=', _ISO );
- // parameter intilization
- $params->date = date( 'r' );
- $params->year = date( 'Y' );
- $params->encoding = $iso[1];
- $params->link = htmlspecialchars( $mosConfig_live_site );
- $params->cache = $params->def( 'cache', 1 );
- $params->cache_time = $params->def( 'cache_time', 3600 );
- $params->count = $params->def( 'count', 5 );
- $params->orderby = $params->def( 'orderby', '' );
- $params->title = $params->def( 'title', 'MiaCMS powered Site' );
- $params->description = $params->def( 'description', 'MiaCMS site syndication' );
- $params->image_file = $params->def( 'image_file', 'miacms_logo.png' );
- if ( $params->image_file == -1 ) {
- $params->image = NULL;
- } else{
- $params->image = $mosConfig_live_site .'/images/'. $params->image_file;
- }
- $params->image_alt = $params->def( 'image_alt', 'Powered by MiaCMS' );
- $params->limit_text = $params->def( 'limit_text', 1 );
- $params->text_length = $params->def( 'text_length', 20 );
- // get feed type from url
- $params->feed = mosGetParam( $_GET, 'feed', 'RSS2.0' );
- $params->option = mosGetParam ($_GET, 'option', 'com_content') ;
- $params->frontpage = $params->option == 'com_frontpage';
-
- $this->params=$params;
- return true;
- }
-
- /**
- * get the items for the feed
- */
- function getData ($section=0,$cat=0) {
- global $database;
- $params=$this->params;
- $this->rows=array();
- // Determine ordering for sql
- switch ( strtolower( $params->orderby ) ) {
- case 'date':
- $orderby = 'a.created';
- break;
- case 'rdate':
- $orderby = 'a.created DESC';
- break;
- case 'alpha':
- $orderby = 'a.title';
- break;
- case 'ralpha':
- $orderby = 'a.title DESC';
- break;
- case 'hits':
- $orderby = 'a.hits DESC';
- break;
- case 'rhits':
- $orderby = 'a.hits ASC';
- break;
- case 'front':
- if ($params->frontpage)
- {
- $orderby = 'f.ordering';
- } else {
- $orderby = 'a.created DESC';
- }
- break;
- default:
- if ($params->frontpage)
- {
- $orderby = 'f.ordering';
- } else {
- $orderby = 'a.created DESC';
- }
- break;
- }
- $nullDate = $params->nullDate;
- $now = $params->now;
- $and = '';
- $join = '';
- if ($params->frontpage)
- {
- $join = "\n ,#__content_frontpage AS f ";
- $and = "\n AND f.content_id = a.id";
- }
- else
- {
- if (is_array($section))
- {
- // we show a multi section rss feed
- $and = "\n AND a.sectionid in (".implode(',',$section).")";
- }
- else
- {
- if (is_array($cat))
- {
- // we show a multi category rss feed
- $and = "\n AND a.catid in (".implode(',',$cat).")";
- }
- else
- {
- if ($section == 0)
- {
- if ($cat == 0)
- {
- // error: all values 0, so we do not display anything
- }
- else
- {
- // we show a category
- $and = "\n AND a.catid = $cat";
- }
- }
- else
- {
- // we show a section
- $and = "\n AND a.sectionid = $section";
- }
- }
- }
- }
- // query of content items
- $query = "SELECT a.*, u.name AS author, u.usertype, UNIX_TIMESTAMP( a.created ) AS created_ts"
- . "\n FROM #__content AS a LEFT JOIN #__users AS u ON u.id = a.created_by"
- . $join
- . "\n WHERE a.state = 1"
- . $and
- . "\n AND a.access = 0"
- . "\n AND ( publish_up = '$nullDate' OR publish_up <= '$now' )"
- . "\n AND ( publish_down = '$nullDate' OR publish_down >= '$now' )"
- . "\n ORDER BY $orderby"
- . ( $params->count ? "\n LIMIT ". $params->count : '' )
- ;
- $database->setQuery( $query );
- //echo $database->getQuery( );
- $this->rows = $database->loadObjectList();
- return true;
- }
- function feed( $file ) {
- global $database, $mainframe, $Itemid;
- global $mosConfig_live_site, $mosConfig_offset, $mosConfig_absolute_path,$mosConfig_sef;
- $params = $this->params;
-
- // load feed creator class
- $rss = new UniversalFeedCreator();
- // load image creator class
- $image = new FeedImage();
- // loads cache file
- if ( $params->cache ) {
- //$rss->useCached( $params->feed, $file, $params->cache_time );
- }
- $rss->title = $params->title;
- $rss->description = $params->description;
- $rss->link = $params->link;
- $rss->syndicationURL = $params->link;
- $rss->cssStyleSheet = NULL;
- $rss->encoding = $params->encoding;
- if ( $params->image )
- {
- $image->url = $params->image;
- $image->link = $params->link;
- $image->title = $params->image_alt;
- $image->description = $params->description;
- // loads image info into rss array
- $rss->image = $image;
- }
-
- $rows =& $this->rows;
- $cr = count($rows);
- if ( $cr != 0 )
- {
- for ($i=0;$i < $cr ;$i++)
- {
- $row= $rows[$i];
- // title for particular item
- $item_title = htmlspecialchars( $row->title );
- $item_title = html_entity_decode( $item_title );
- $_Itemid = $mainframe->getItemid( $row->id );
- if ( $_Itemid == 0 )
- {
- $itemid = $Itemid;
- }
- else
- {
- $itemid = $_Itemid;
- }
- // url link to article (& used instead of & as this is converted by feed creator)
- /* Build the $item_link a bit differently for SEF since sefRelToAbs doesn't convert the URL properly when
- passed $mosConfig_live_site. No SEF needs $mosConfig_live_site, else & becomes an issue. */
- if ($mosConfig_sef > 0) {
- $item_link = htmlentities('index.php?option=com_content&task=view&id='. $row->id .'&Itemid='. $itemid);
- } else {
- $item_link = htmlentities($mosConfig_live_site .'/index.php?option=com_content&task=view&id='. $row->id .'&Itemid='. $itemid);
- }
- $item_link = sefRelToAbs( $item_link );
- // removes all formating from the intro text for the description text
- $item_description = $row->introtext;
- $item_description = mosHTML::cleanText( $item_description );
- $item_description = html_entity_decode( $item_description );
- if ( $params->limit_text ) {
- if ( $params->text_length ) {
- // limits description text to x words
- $item_description_array = split( ' ', $item_description );
- $count = count( $item_description_array );
- if ( $count > $params->text_length ) {
- $item_description = '';
- for ( $a = 0; $a < $params->text_length; $a++ ) {
- $item_description .= $item_description_array[$a]. ' ';
- }
- $item_description = trim( $item_description );
- $item_description .= '...';
- }
- } else {
- // do not include description when text_length = 0
- $item_description = NULL;
- }
- }
- // load individual item creator class
- $item = new FeedItem();
- // item info
- $item->title = $item_title;
- $item->link = $item_link;
- $item->description = $item_description;
- $item->source = $params->link;
- $item->date = date( 'r', $row->created_ts );
- // loads item info into rss array
- $rss->addItem( $item );
- }
- }
-
- //save feed file
- $rss->saveFeed( $params->feed, $file );
- }
-
- /**
- * generic show method
- */
- function show()
- {
- global $database, $mainframe, $Itemid,$mosConfig_absolute_path;
- // check the feed type
- $feed = strtolower(str_replace('.', '', $this->params->feed));
- $legal = array ('rss20', 'rss10', 'rss091', 'atom10', 'opml');
- $legalTasks = array ('section', 'blogsection', 'category', 'categorysection', 'frontpage');
- if (!in_array($feed, $legal))
- {
- echo "wrong feed type";
- mosNotAuth();
- return '';
- }
- if(isset($_GET['task']) AND in_array($_GET['task'], $legalTasks)){
- $mtype = mosGetParam ($_GET, 'task');
- } else {
- //revert to frontpage if theres no task
- $mtype = "frontpage";
- }
- $section=0;
- $cat=0;
- switch ($mtype)
- {
- case 'section':
- $section = mosGetParam ($_GET, 'id', 0) ;
- break;
- case 'blogsection':
- $section = mosGetParam ($_GET, 'id', 0) ;
- break;
- case 'category':
- $cat = mosGetParam ($_GET, 'id', 0) ;
- break;
- case 'categorysection':
- $cat = mosGetParam ($_GET, 'id', 0) ;
- break;
- default:
- //frontpage
- break;
- }
- // get the data for the feed
- $this->getData($section,$cat);
- $file = $mosConfig_absolute_path .'/cache/'. $Itemid .'_'.$feed . '.xml';
- $this->feed( $file );
- return true;
- }
- }
- ?>