boards
[ class tree: boards ] [ index: boards ] [ all elements ]

Source for file boards_rss.php

Documentation is available at boards_rss.php

  1. <?php
  2. /**
  3.  * @version $Header$
  4.  * @package boards
  5.  * @subpackage functions
  6.  */
  7.  
  8. /**
  9.  * Initialization
  10.  */
  11. require_once( "../kernel/setup_inc.php" );
  12.  
  13. $gBitSystem->verifyPackage( 'boards' );
  14. $gBitSystem->verifyPackage( 'rss' );
  15.  
  16. require_once( RSS_PKG_PATH."rss_inc.php" );
  17.  
  18. // Load up the board or topic
  19. require_once( BOARDS_PKG_PATH.'lookup_inc.php' );
  20.  
  21. // access check
  22. if( !empty( $_REQUEST['t'] ) || !empty($_REQUEST['b'] ) ){
  23.     if( $gContent->isValid() ){
  24.         $gContent->load();
  25.     }
  26.     else{
  27.         $gBitSystem->fatalError(tra("Unknown discussion"), NULL, NULL, HttpStatusCodes::HTTP_GONE );
  28.     }
  29. }
  30. $gContent->verifyViewPermission();
  31.  
  32. // check if we want to use the cache file
  33. // HTTP_HOST is needed beacuse people subscribe to RSS via different URLs (docs.bw.o and www.bw.o for example)
  34. // cached versions of other URLs will double posts
  35. // $cacheFile = TEMP_PKG_PATH.RSS_PKG_NAME.'/'.BOARDS_PKG_NAME.'/'.$_SERVER['HTTP_HOST']."_".$cacheFileTail;
  36. $cacheFile = TEMP_PKG_PATH.RSS_PKG_NAME.'/'.BOARDS_PKG_NAME.'/'.$_SERVER['HTTP_HOST'];
  37. // BitTopic acts strange and does not set mContentTypeGuid
  38. switch( $gContent->getField('content_type_guid') ){
  39.     case 'bitcomment':
  40.         $cacheFile .= '_comment'.$_REQUEST['t'];
  41.         break;
  42.     case 'bitboard':
  43.         if( $gContent->isValid() ){
  44.             $cacheFile .= '_board'.$_REQUEST['b'];
  45.         }
  46.         break;
  47.     default:
  48.         break;
  49. }
  50. $cacheFile.="_".$cacheFileTail;
  51. $rss->useCached( $rss_version_name, $cacheFile, $gBitSystem->getConfig( 'rssfeed_cache_time' ));
  52.  
  53. $title = tra("Recent Discussions");
  54. $description = tra("All recent forum discussions on ".$gBitSystem->getConfig( 'site_title' ) );
  55. if( $gContent->isValid() ){
  56.     $gContent->parseData();
  57.     $title = $gContent->getField( 'title' )." Feed";
  58.     $description = $gContent->getField( 'parsed_data' );
  59. }
  60. $rss->title = $title;
  61. $rss->description = $description;
  62. $rss->link =  $gContent->getDisplayUri();
  63.  
  64.  
  65. // get all topics of a board or all recent topics in general
  66. switch( $gContent->getField('content_type_guid') ){
  67.     case 'bitcomment':
  68.         // need to use post class to get list of comments
  69.         $gComment = new BitBoardPost($_REQUEST['t']);
  70.         // pass in a reference to the root object so that we can do proper permissions checks
  71.         $gComment->mRootObj = $gContent;
  72.         $feeds = $gComment->getComments( $gContent->mContentId, $gBitSystem->getConfig( 'boards_rss_max_records', 10 ), 0, 'commentDate_desc', 'flat' );
  73.         break;
  74.     case 'bitboard':
  75.     default:
  76.         $topic = new BitBoardTopic();
  77.         $pParamHash = array();
  78.         if( !empty( $_REQUEST['b'] ) ) {
  79.             $pParamHash['b'] = $_REQUEST['b'];
  80.         }
  81.         $pParamHash['find'] ='';
  82.         $pParamHash['sort_mode'] = "llc_last_modified_desc";
  83.         $pParamHash['max_records'] = $gBitSystem->getConfig( 'boards_rss_max_records', 10 );
  84.         $pParamHash['offset'] = 0;
  85.         $feeds = $topic->getList( $pParamHash );
  86.         break;
  87. }
  88.  
  89. // get all the data ready for the feed creator
  90. foreach( $feeds as $feed ) {
  91.     /*
  92.     echo "<pre>";
  93.     var_dump($feed);
  94.     //*/
  95.     $item = new FeedItem();
  96.     $item->title = $feed['title'];
  97.     $item->source = 'http://'.$_SERVER['HTTP_HOST'].BIT_ROOT_URL;
  98.  
  99.     switch( $gContent->getField('content_type_guid') ){
  100.         case 'bitcomment':
  101.             // topic specific
  102.             $item->link = 'http://'.$_SERVER['HTTP_HOST'].BIT_ROOT_URL.'index.php?content_id='.$feed['content_id']; //comment paths are tricky, but work automagically through the front door
  103.             $item->description =  $feed['parsed_data'];
  104.             $item->date = ( int )$feed['last_modified'];
  105.             $user = new BitUser($feed['user_id']);
  106.             break;
  107.         case 'bitboard':
  108.         default:
  109.             // board specific
  110.             if ($gBitUser->isRegistered()) {
  111.                 if (!empty($feed['track']['on'])&&$feed['track']['mod']) {
  112.                     $item->title = "[NEW] " .$item->title;
  113.                 }
  114.             }
  115.             if( !empty( $feed['th_sticky'] ) ) {
  116.                 $item->title = "[!] " .$item->title;
  117.             }
  118.             if( !empty( $feed['th_locked'] ) ) {
  119.                 $item->title = "[#] " .$item->title;
  120.             }
  121.             $item->link = 'http://'.$_SERVER['HTTP_HOST'].$feed['url'];
  122.             $data = BitBoard::getBoard($feed['llc_content_id']);
  123.             $item->description =  $data['data'];
  124.             //TODO allow proper sort order
  125.             //$item->date = ( int )$feed['event_date'];
  126.             $item->date = ( int )$feed['llc_last_modified'];
  127.             $user = new BitUser($feed['llc_user_id']);
  128.             break;
  129.     }
  130.  
  131.     $user->load();
  132.     $item->author = $user->getDisplayName();//$gBitUser->getDisplayName( FALSE, array( 'user_id' => $feed['modifier_user_id'] ) );
  133.     $item->authorEmail = $user->mInfo['email'];
  134.     $item->descriptionTruncSize = $gBitSystem->getConfig( 'rssfeed_truncate', 1000 );
  135.     $item->descriptionHtmlSyndicated = FALSE;
  136.     /*
  137.     var_dump($item);
  138.     echo "</pre>";
  139.     die();
  140.     //*/
  141.     // pass the item on to the rss feed creator
  142.     $rss->addItem( $item );
  143. }
  144.  
  145. // finally we are ready to serve the data
  146. echo $rss->saveFeed( $rss_version_name, $cacheFile );
  147. ?>

Documentation generated on Wed, 29 Jul 2015 13:56:12 +0000 by phpDocumentor 1.5.0-lsces