blogger_entries.php

Go to the documentation of this file.
00001 <?PHP
00002 class blogger_entries
00003 {
00004         var $entries;                     
00005         var $users;                       
00006         var $categories;                  
00007         var $edit = false;                
00008         var $limit = 10;                  
00009         var $limitTiny = null;            
00010         
00011         // users == null -> all users
00012         // categories == null -> everything
00013         function blogger_entries( $users = null, $categories = null )
00014         {
00015                 if( is_array( $users ) )
00016                         $tempUsers = $users;
00017                 else
00018                         $tempUsers = allUsersArray();
00019                 foreach( $tempUsers as $key => $value )
00020                         $this->users[$value] = $key;
00021                 
00022                 $this->categories = $categories;
00023                 
00024                 $this->load();
00025         }
00026         
00027         function load()
00028         {
00029                 // (re)initialise instances of all users
00030                 $instances = array();
00031                 foreach( $this->users as $key => $value )
00032                         $instances[$key] = new blogger_user( &$this, $key );
00033                 $this->users = $instances;
00034                 
00035                 // Get references to entries out of all users and put them into $this->entries["timestamp/username"]
00036                 $this->entries = array();
00037                 foreach( $this->users as $key => $value )
00038                 {
00039                         foreach( $this->users[$key]->entries as $key2 => $value2 )
00040                         {
00041                                 $entryKey = $value2->timestamp . "/" . $key;
00042                                 $this->entries[$entryKey] = &$this->users[$key]->entries[$key2];
00043                         }
00044                 }
00045                 krsort($this->entries);
00046         }
00047         
00055         function renderFeed( $type = null )
00056         {
00057                 global $page_title;
00058                 $title = $page_title;
00059                 
00060                 $link = thisPageURL();
00061                 
00062                 if( count( $this->users ) == count( allUsersArray() ) )
00063                         $theUsers = i18n("all users, ");
00064                 else
00065                 {
00066                         foreach( $this->users as $key => $value )
00067                                 $theUsers .= $value->username . ", ";
00068                 }
00069                 
00070                 if( $this->categories == null )
00071                         $theUsers = i18n("all categories, ");
00072                 else
00073                 {
00074                         foreach( $this->categories as $key => $value )
00075                                 $theCategories .= "$value, ";
00076                 }
00077                 
00078                 $description = i18n("A syndication of the entries by ##0##in the category or categories ##1##on ##2##", array( $theUsers, $theCategories, $title ) );
00079                 
00080                 $feed = new Feed( $title, $link, $description, time() );
00081                 
00082                 $i = 0;
00083                 foreach( $this->entries as $key => $entry )
00084                 {
00085                         $feed->addItem( $entry->getFeedItem() );
00086                         if( $i++ > $this->limit )
00087                                 break;
00088                 }
00089                 
00090                 return $feed->render( $type );
00091         }
00092         
00101         function render( $username = null, $timestamp = null )
00102         {
00103                 $renderedData = "";
00104                 if( $username != null )
00105                 {
00106                         // No need to check for null here as that is also what's checked the other end
00107                         $renderedData = $this->users[$username]->render($timestamp);
00108                 }
00109                 else
00110                 {
00111                         if( count( $this->entries ) > 0 )
00112                         {
00113                                 $entryCount = 0;
00114                                 $shownEntry = 0;
00115                                 $currentPage = array_key_exists( "currentpage", $_REQUEST) ? $_REQUEST["currentpage"] : 0;
00116                                 $lowerBound = $currentPage * $this->limit;
00117                                 $upperBound = $lowerBound + $this->limit;
00118                                 // Loop through all entries...
00119                                 foreach( $this->entries as $key => $value )
00120                                 {
00121                                         if( $value->published )
00122                                         {
00123                                                 if( $lowerBound <= $entryCount && $entryCount < $upperBound )
00124                                                 {
00125                                                         $shownEntry++;
00126                                                         if( $this->limitTiny !== null && $shownEntry < $this->limitTiny )
00127                                                                 $renderedData .= $value->renderTiny();
00128                                                         else
00129                                                                 $renderedData .= $value->renderBlock();
00130                                                 }
00131                                                 $entryCount++;
00132                                         }
00133                                 }
00134                         }
00135                         if( $renderedData == "" )
00136                                 $renderedData = renderInformationBox( i18n("No entries"), i18n("There are no published blog entries available.") );
00137                         else
00138                                 $renderedData = renderNavigator($entryCount, $currentPage, $lowerBound, $upperBound, $this->limit) . $renderedData;
00139                 }
00140                 return $renderedData;
00141         }
00142 }
00143 ?>

Generated on Sun Oct 26 20:33:12 2008 for The Travelsized Content Management System by  doxygen 1.5.5