NewsFeaturesDownloadsDevelopmentSupportAbout Us

lifetype/branches/lifetype-1.0.6/class/action/blogaction.class.php

Go to the documentation of this file.
00001 <?php
00002 
00003         include_once( PLOG_CLASS_PATH."class/action/action.class.php" );
00004     include_once( PLOG_CLASS_PATH."class/config/config.class.php" );
00005     include_once( PLOG_CLASS_PATH."class/dao/blogs.class.php" );
00006     include_once( PLOG_CLASS_PATH."class/plugin/pluginmanager.class.php" );
00007     include_once( PLOG_CLASS_PATH."class/net/http/httpvars.class.php" );
00008     include_once( PLOG_CLASS_PATH."class/security/pipeline.class.php" );
00009         include_once( PLOG_CLASS_PATH."class/net/http/subdomains.class.php" );
00010         include_once( PLOG_CLASS_PATH."class/dao/referers.class.php" );
00011     include_once( PLOG_CLASS_PATH."class/dao/articles.class.php" );
00012     include_once( PLOG_CLASS_PATH."class/data/validator/integervalidator.class.php" );
00013 
00025         class BlogAction extends Action 
00026         {
00027 
00028         var $_session;
00029         var $_config;
00030         var $_blogInfo;
00031         var $_locale;
00032         var $_pm;
00033         var $_articles;
00034 
00041                 function BlogAction( $actionInfo, $request )
00042         {
00043                 $this->Action( $actionInfo, $request );
00044 
00045             // we use the HttpVars package since then we can access the session object
00046             // independently wether we're using php ver. < 4.1.0 or not
00047             $session = HttpVars::getSession();
00048                 $this->_session = $session['SessionInfo'];
00049 
00050             $this->_config =& Config::getConfig();
00051 
00052             $this->_getBlogInfo();
00053 
00054             // save the blogid in the session
00055             $this->_session->setValue( 'blogId', $this->_blogInfo->getId());
00056 
00057             $this->checkDateParameter();
00058                         
00059             // initialize the plugin manager
00060             $this->_pm =& PluginManager::getPluginManager();
00061             $this->_pm->setBlogInfo( $this->_blogInfo );
00062             $this->_pm->setUserInfo( $this->_userInfo );
00063             
00064             // locale
00065             $this->_locale = $this->_blogInfo->getLocale();
00066 
00067             //
00068             // security stuff
00069             //
00070             $pipeline = new Pipeline( $request, $this->_blogInfo );
00071             $result = $pipeline->process();
00072             //
00073             // if the pipeline blocked the request, then we have
00074             // to let the user know
00075             if( !$result->isValid()) {
00076                                 $message = $this->_locale->tr('error_you_have_been_blocked').'<br/><br/>';
00077                                 $message .= $result->getErrorMessage();
00078                 $this->_view = new ErrorView( $this->_blogInfo, $message );
00079                 $this->setCommonData();
00080                 $this->_view->render();
00081 
00082                 die();
00083             }
00084                         
00085                         // update the referrers, if needed
00086                         $this->_updateReferrer();
00087                         
00088                         $this->articles = new Articles();       
00089         }
00090                 
00096                 function notifyEvent( $eventType, $params = Array())
00097                 {
00098                         $params[ 'from' ] = $this->_actionInfo->getActionParamValue();
00099                         $params[ 'request' ] = $this->_request;
00100                                         
00101                         return $this->_pm->notifyEvent( $eventType, $params );
00102                 }
00103 
00107         function saveSession()
00108         {
00109                 //$_SESSION['SessionInfo'] = $this->_session;
00110             $session = HttpVars::getSession();
00111             $session['SessionInfo'] = $this->_session;
00112             HttpVars::setSession( $session );
00113         }
00114 
00124         function setCommonData( $copyFormValues = false )
00125         {
00126             $this->_view->setValue( "Year", $this->_session->getValue( 'Year'));
00127             $this->_view->setValue( "Month", $this->_session->getValue( 'Month' ));
00128             
00129             parent::setCommonData( $copyFormValues );
00130         }
00131 
00136         function _getBlogInfo()
00137         {       
00138                         // see if we're using subdomains
00139                         $config =& Config::getConfig();
00140                         if( $config->getValue( "subdomains_enabled" )) {
00141                                 $subdomainInfo = Subdomains::getSubdomainInfoFromRequest();
00142 
00143                                 if( $subdomainInfo["username"] != "" && $this->_request->getValue( 'blogUserName' ) == "" )
00144                                         $this->_request->setValue( 'blogUserName', $subdomainInfo["username"] );
00145                                 if( $subdomainInfo["blogname"] != "" && $this->_request->getValue( 'blogName' ) == "" ) 
00146                                         $this->_request->setValue( 'blogName', $subdomainInfo["blogname"] );                            
00147                         }
00148 
00149                 $blogId = $this->_request->getValue( 'blogId' );
00150                 $blogName = $this->_request->getValue( 'blogName' );
00151                 $userId = $this->_request->getValue( 'userId' );
00152                 $userName = $this->_request->getValue( 'blogUserName' );
00153                         
00154             // if there is a "blogId" parameter, it takes precedence over the
00155             // "user" parameter.
00156             if( !$blogId && !$blogName ) {
00157                 // check if there was a user parameter
00158                 if( !empty($userName) ) {
00159                         // if so, check to which blogs the user belongs
00160                         $users = new Users();
00161                         $userInfo = $users->getUserInfoFromUsername( $userName );
00162                     // if the user exists and is valid...
00163                         if( $userInfo ) {
00164                         $userBlogs = $users->getUsersBlogs( $userInfo->getId(), BLOG_STATUS_ACTIVE );
00165                         // check if he or she belogs to any blog. If he or she does, simply
00166                         // get the first one (any better rule for this?)
00167                         if( !empty($userBlogs)) {                                               
00168                                         $blogId = $userBlogs[0]->getId();
00169                         } else {
00170                                 $blogId = $this->_config->getValue('default_blog_id');
00171                         }
00172                     } else {
00173                         $blogId = $this->_config->getValue('default_blog_id');
00174                     }
00175                 }
00176                 else {
00177                     // if there is no user parameter, we take the blogId from the session
00178                     if( $this->_session->getValue('blogId') != '' ) {
00179                         $blogId = $this->_session->getValue('blogId');
00180                     }
00181                     else {
00182                         // get the default blog id from the database
00183                         $blogId = $this->_config->getValue('default_blog_id');                        
00184                     }
00185                 }
00186             }
00187                         
00188             // fetch the BlogInfo object
00189             $blogs = new Blogs();
00190             if( $blogId )
00191                 $this->_blogInfo = $blogs->getBlogInfo( $blogId );
00192             else
00193                 $this->_blogInfo = $blogs->getBlogInfoByName( $blogName );
00194 
00195             // security checks...
00196             if( $this->_blogInfo == false ) {
00197                 print( 'ERROR: The blog does not exist.' );
00198                 die;
00199             }
00200             
00201             // non-active blogs shoulnd't be shown either!
00202             if( $this->_blogInfo->getStatus() != BLOG_STATUS_ACTIVE ) {
00203                 print( 'ERROR: The blog does not exist.' );
00204                 die;                
00205             }
00206         }
00207 
00211         function checkDateParameter()
00212         {
00213                 $date = $this->_request->getValue( 'Date' );
00214                 $val = new IntegerValidator();
00215                 if( $date && $val->validate( $date ) ) {
00216                 $year = substr( $date, 0, 4);
00217                 $month = substr( $date, 4,2 );
00218                 $day = substr( $date, 6, 2);
00219             }
00220             else {
00221                 $year = date('Y');
00222                 // $month = $t->getMonth();
00223                 $month = date('m');
00224                 // $day = $t->getDay();
00225                 $day = date('d');
00226             }
00227 
00228             $this->_session->setValue( 'Year', $year );
00229             $this->_session->setValue( 'Month', $month );
00230             $this->_session->setValue( 'Day', $day );
00231         }
00232                 
00239                 function _updateReferrer()
00240                 {
00241                         if( $this->_request->getValue( "articleId" ) != "" || $this->_request->getValue( "articleName" ) != "" ) 
00242                                 return true;
00243                                 
00244                 // update the referer statistics
00245             $referers = new Referers();
00246             if (array_key_exists( 'HTTP_REFERER', $_SERVER ))
00247                 $referers->addReferer( $_SERVER['HTTP_REFERER'], 0, $this->_blogInfo->getId());
00248                         
00249                         return true;
00250                 }
00251                 
00252 
00259         function _getCorrectedDatePeriod( $inDate )
00260         {
00261             $blogSettings = $this->_blogInfo->getSettings();
00262             $serverTimeOffset = $blogSettings->getValue( "time_offset" );
00263             
00264             if( $serverTimeOffset == 0)
00265             {
00266                 $maxDate = -1;
00267                 $outDate = $inDate;
00268             }
00269             else
00270             {
00271                     if( strlen($inDate) == 4 ) 
00272                         {
00273                                 $year = $inDate;
00274                                 $outDate = Timestamp::getDateWithOffset( $year."0101000000", -$serverTimeOffset );
00275                                 $maxDate = Timestamp::getDateWithOffset( $year."1231235959", -$serverTimeOffset );
00276                         } 
00277                         elseif ( strlen($inDate) == 6 )
00278                         {
00279                         $year = substr( $inDate, 0, 4 );
00280                         $month = substr( $inDate, 4, 2 );
00281                         $dayOfMonth = Date_Calc::daysInMonth( $month, $year );
00282                                 $outDate = Timestamp::getDateWithOffset( $year.$month."01000000", -$serverTimeOffset );
00283                                 $maxDate = Timestamp::getDateWithOffset( $year.$month.$dayOfMonth."235959", -$serverTimeOffset );
00284                         }
00285                         elseif ( strlen($inDate) == 8 )
00286                         {
00287                                 $year = substr( $inDate, 0, 4 );
00288                         $month = substr( $inDate, 4, 2 );
00289                         $day = substr( $inDate, 6, 2 );
00290                                 $outDate  = Timestamp::getDateWithOffset( $year.$month.$day."000000", -$serverTimeOffset );
00291                                 $maxDate = Timestamp::getDateWithOffset( $year.$month.$day."235959", -$serverTimeOffset );
00292                         }
00293                         else
00294                         {
00295                                 $maxDate = -1;
00296                                 $outDate = $inDate;
00297                         }
00298             }
00299             
00300             $result["inDate"] = $inDate;
00301             $result["maxDate"] = $maxDate;
00302             $result["adjustedDate"] = $outDate;
00303             
00304             return( $result );
00305         }               
00306     }
00307 ?>