blogger_entry.php

Go to the documentation of this file.
00001 <?PHP
00021 class blogger_entry extends lockableClass
00022 {
00023         var $username;
00024         var $timestamp;
00025         var $filename;
00026         
00027         var $title;
00028         var $content;
00029         var $categories;
00030         var $published;
00031         
00032         var $personal;
00033         var $viewLevel;
00034         var $commentLevel;
00035         var $comments;
00036         
00037         var $parentUser;               
00038         var $edit = false;
00039         
00047         function blogger_entry( $parentUser, $timestamp = null )
00048         {
00049                 global $userinfo_folder;
00050                 $this->parentUser = &$parentUser;
00051                 $this->username = $parentUser->username;
00052                 $this->timestamp = $timestamp == null ? time() : $timestamp;
00053                 $this->createFilename();
00054                 
00055                 // We should only attempt to load if we were given a timestamp to load...
00056                 if( $timestamp != null )
00057                         $this->load();
00058         }
00059         
00060         function createFilename()
00061         {
00062                 global $userinfo_folder;
00063                 $this->filename = $userinfo_folder . "/" . $this->parentUser->username . "/blogger/" . $this->timestamp . ".php";
00064                 $this->lockfile = $this->filename . ".lock";
00065         }
00066         
00067         function load()
00068         {
00069                 if( file_exists( $this->filename ) )
00070                         include( $this->filename );
00071                 
00072                 $this->title = $entry["title"];
00073                 $this->content = $entry["content"];
00074                 $this->categories = $entry["categories"];
00075                 $this->personal = $entry["personal"];
00076                 $this->viewLevel = $entry["viewLevel"];
00077                 $this->commentLevel = $entry["commentLevel"];
00078                 $this->comments = $entry["comments"];
00079                 $this->published = $entry["published"];
00080         }
00081         
00082         function save()
00083         {
00084                 if( file_exists( $this->filename ) )
00085                         unlink( $this->filename );
00086                 
00087                 $entry["title"] = $this->title;
00088                 $entry["content"] = $this->content;
00089                 $entry["categories"] = $this->categories;
00090                 $entry["personal"] = $this->personal;
00091                 $entry["viewLevel"] = $this->viewLevel;
00092                 $entry["commentLevel"] = $this->commentLevel;
00093                 $entry["comments"] = $this->comments;
00094                 $entry["published"] = $this->published;
00095                 
00096                 file_put_contents( $this->filename, array_export( $entry, "entry" ) );
00097         }
00098         
00099         function getGlobalID( $aswhat = "view" )
00100         {
00101                 if( $aswhat == "view" )
00102                         $aswhat = "";
00103                 else
00104                         $aswhat = "/" . $aswhat;
00105                 
00106                 return "user/" . $this->username . "/blogger" . $aswhat . "/entry/" . $this->timestamp;
00107         }
00108         
00109         function getFeedItem()
00110         {
00111                 $title = $this->title;
00112                 $link = globalIDToURL( $this->getGlobalID() );
00113                 
00114                 $splithere = strpos( $this->content, "---" );
00115                 if( $splithere > 0 )
00116                         $description = substr( $this->content, 0, $splithere );
00117                 else
00118                         $description = $this->content;
00119                 
00120                 $pubDate = $this->timestamp;
00121                 
00122                 return new FeedItem( $title, $link, $description, $pubDate, $link );
00123         }
00124         
00132         function userCanView( $username )
00133         {
00134                 if( $this->personal )
00135                         return userAllows( $username, $this->parentUser->getParam( $allowsViewPersonal ) );
00136                 else
00137                         return userAllows( $username, $this->viewLevel );
00138         }
00139         
00140         function renderEditor()
00141         {
00142                 global $globalID;
00143                 $splitID = explode("/", $globalID);
00144                 
00145                 switch( $splitID[3] )
00146                 {
00147                 //  action: publish (toggle publish status)
00148                 case "publish":
00149                         if( $this->lock() )
00150                         {
00151                                 $this->load();
00152                                 $this->published = !$this->published;
00153                                 $this->save();
00154                                 $this->unlock();
00155                                 header( "Location: " . globalIDtoURL( $this->parentUser->getGlobalID("edit") ) );
00156                         }
00157                         else
00158                                 $renderedContent = renderWarningBox( i18n("Could not lock"), i18n("The entry could not be locked! Please use your browser's back button and try again.") );
00159                         break;
00160                 //  action: delete
00161                 case "delete":
00162                         $dialog = new confirmDeleteDialog( $this->title, strtok( $this->content, "\n---\n" ), $this->getGlobalID("view") );
00163                         
00164                         if( $dialog->submitted )
00165                         {
00166                                 if( $dialog->confirmed )
00167                                         unlink($this->filename);
00168                                 header( "Location: " . globalIDtoURL( $this->parentUser->getGlobalID("edit") ) );
00169                         }
00170                         
00171                         $renderedContent = $dialog->render();
00172                         break;
00173                 //  action: none (edit entry)
00174                 case "edit":
00175                 default:
00176                         $editor = new blogger_entryEditor( &$this );
00177                         $renderedContent = "<form method=\"POST\" action=\"" . thisPageURL() . "\">" . $editor->render() . "</form>";
00178                         break;
00179                 }
00180                 return $renderedContent;
00181         }
00182         
00188         function renderControls()
00189         {
00190                 $view = drawCommand( i18n("View ##0##", array( "&raquo;" ) ), i18n("View the entry"), globalIDtoURL( $this->getGlobalID("view") ) );
00191                 
00192                 $commentHandler = new commentHandler( array(), 0, 0, 0 );
00193                 
00194                 $comments = i18n("Comments: ##0##", array( $commentHandler->countComments( $this->comments ) ) );
00195                 
00196                 if( $this->parentUser->parentEntries->edit )
00197                 {
00198                         $publishTitle = $this->published ? i18n("Unpublish") : i18n("Publish");
00199                         $publishTip = $this->published ? i18n("Unpublish this entry") : i18n("Publish this entry");
00200                         $publish = drawCommand( $publishTitle, $publishTip, globalIDtoURL( $this->getGlobalID("publish") ) );
00201                         
00202                         $edit = drawCommand( i18n("Edit ##0##", array( "&raquo;" ) ), i18n("Edit the entry"), globalIDtoURL( $this->getGlobalID("edit") ) );
00203                         $delete = drawCommand( i18n("Delete ##0##", array( "&raquo;" ) ), i18n("Delete the entry"), globalIDtoURL( $this->getGlobalID("delete") ) );
00204                 }
00205                 
00206                 $controls = "<div class=\"blogger-commands\">" . $comments . " " . $view . $publish . $edit . $delete . "</div>";
00207                 
00208                 return $controls;
00209         }
00210         
00211         function renderFull()
00212         {
00213                 $date = "<div class=\"blogger-date\">" . formatTime( $this->timestamp ) . "</div>";
00214                 $title = "<div class=\"blogger-title\">" . $this->title . "</div>";
00215                 $content = "<div class=\"blogger-content\">" . parse_page_data( $this->content ) . "</div>";
00216                 
00217                 $commentHandler = new CommentHandler( $this->comments, $this->username, $this->commentLevel, 4 );
00218                 
00219                 $renderedContent = "<div class=\"blogger blogger-full\">" . $date . $title . $content . $commentHandler->renderComments() . $commentHandler->renderCommentsAdder() . "</div>";
00220                 
00221                 if( $commentHandler->commentsChanged )
00222                 {
00223                         if( $this->lock() )
00224                         {
00225                                 $this->load();
00226                                 $this->comments = $commentHandler->comments;
00227                                 $this->save();
00228                                 $this->unlock();
00229                         }
00230                         
00231                 }
00232                 
00233                 return $renderedContent;
00234         }
00235         
00236         function renderBlock()
00237         {
00238                 $date = "<div class=\"blogger-date\">" . formatTime( $this->timestamp ) . "</div>";
00239                 $title = "<div class=\"blogger-title\">" . $this->title . "</div>";
00240                 
00241                 $splithere = strpos( $this->content, "---" );
00242                 if( $splithere > 0 )
00243                         $content = substr( $this->content, 0, $splithere );
00244                 else
00245                         $content = $this->content;
00246                 $content = "<div class=\"blogger-content\">" . parse_page_data( $content ) . "</div>";
00247                 
00248                 $controls = $this->renderControls();
00249                 
00250                 $renderedContent = "<div class=\"blogger blogger-block\">" . $date . $title . $content . $controls . "</div>";
00251                 
00252                 return $renderedContent;
00253         }
00254         
00255         function renderTiny()
00256         {
00257                 $date = "<div class=\"blogger-date\">" . formatTime( $this->timestamp ) . "</div>";
00258                 $title = "<div class=\"blogger-title\">" . $this->title . "</div>";
00259                 $controls = $this->renderControls();
00260                 
00261                 $renderedContent = "<div class=\"blogger-tiny\">" . $date . $title . $controls . "</div>";
00262                 return $renderedContent;
00263         }
00264         
00273         function render( $block = false, $tiny = false )
00274         {
00275                 $renderedData = "";
00276                 if( $this->edit )
00277                         $renderedData = $this->renderEditor();
00278                 else if( $tiny )
00279                         $renderedData = $this->renderTiny();
00280                 else if( $block )
00281                         $renderedData = $this->renderBlock();
00282                 else
00283                         $renderedData = $this->renderFull();
00284                 
00285                 return $renderedData;
00286         }
00287 }
00288 ?>

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