[ Index ]
 

Code source de Joomla 1.0.13

Accédez au Source d'autres logiciels libres

title

Body

[fermer]

/components/com_rss/ -> rss.php (source)

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


Généré le : Wed Nov 21 14:43:32 2007 par Balluche grâce à PHPXref 0.7
  Clicky Web Analytics