NewsFeaturesDownloadsDevelopmentSupportAbout Us

lifetype-1.1.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/data/validator/integervalidator.class.php" ); 
00006 
00018         class BlogAction extends Action 
00019         {
00020 
00021         var $_session;
00022         var $_config;
00023         var $_blogInfo;
00024         var $_locale;
00025         var $_pm;
00026         var $_articles;
00027 
00034         function BlogAction( $actionInfo, $request )
00035         {
00036             include_once( PLOG_CLASS_PATH."class/plugin/pluginmanager.class.php" );
00037             include_once( PLOG_CLASS_PATH."class/security/pipeline.class.php" );
00038             include_once( PLOG_CLASS_PATH."class/net/http/httpvars.class.php" );
00039 
00040             $this->Action( $actionInfo, $request );
00041 
00042             // we use the HttpVars package since then we can access the session object
00043             // independently wether we're using php ver. < 4.1.0 or not
00044             $session = HttpVars::getSession();
00045             $this->_session = $session['SessionInfo'];
00046 
00047             $this->_config =& Config::getConfig();
00048             if( !$this->_getBlogInfo() ) {
00049                     include_once( PLOG_CLASS_PATH."class/view/view.class.php" );
00050                     include_once( PLOG_CLASS_PATH."class/view/redirectview.class.php" );
00051                     
00052                     $this->_session->setValue( 'blogId', null );
00053                     $blogDoesNotExistUrl = $this->_config->getValue( "blog_does_not_exist_url" );
00054                     if ( empty($blogDoesNotExistUrl) )
00055                         $blogDoesNotExistUrl = trim( $this->_config->getValue( "base_url" ) );
00056                     
00057                                 $this->_view = new RedirectView( $blogDoesNotExistUrl );
00058                                 $this->_view->render();
00059                 die();
00060                         }
00061 
00062             // save the blogid in the session
00063             $this->_session->setValue( 'blogId', $this->_blogInfo->getId());
00064 
00065             $this->checkDateParameter();
00066                         
00067             // initialize the plugin manager
00068             $this->_pm =& PluginManager::getPluginManager();
00069             $this->_pm->setBlogInfo( $this->_blogInfo );
00070             $this->_pm->setUserInfo( $this->_userInfo );
00071             
00072             // locale
00073             $this->_locale = $this->_blogInfo->getLocale();
00074 
00075             //
00076             // security stuff
00077             //
00078             $pipeline = new Pipeline( $request, $this->_blogInfo );
00079             $result = $pipeline->process();
00080             //
00081             // if the pipeline blocked the request, then we have
00082             // to let the user know
00083             if( !$result->isValid()) {
00084                                 if( !$result->hasView()) {
00085                                         // use the default view
00086                                         include_once( PLOG_CLASS_PATH."class/view/errorview.class.php" );
00087                                         $message = $this->_locale->tr('error_you_have_been_blocked').'<br/><br/>';
00088                                         $message .= $result->getErrorMessage();
00089                                         $this->_view = new ErrorView( $this->_blogInfo, $message );
00090                                 }
00091                                 else {
00092                                         // if the filter that forced the processing to stop provided
00093                                         // its own view, then use it                            
00094                                         $this->_view = $result->getView();
00095                                 }
00096                 $this->setCommonData();
00097                 $this->_view->render();
00098 
00099                 die();
00100             }
00101                         
00102                         // update the referrers, if needed
00103                         $this->_updateReferrer();
00104                         
00105                         // get the "page" parameter from the request
00106                         $this->_page = $this->_getPage();
00107         }
00108                 
00114                 function notifyEvent( $eventType, $params = Array())
00115                 {
00116                         $params[ 'from' ] = $this->_actionInfo->getActionParamValue();
00117                         $params[ 'request' ] = $this->_request;
00118                                         
00119                         return $this->_pm->notifyEvent( $eventType, $params );
00120                 }
00121 
00125         function saveSession()
00126         {
00127                 //$_SESSION['SessionInfo'] = $this->_session;
00128             $session = HttpVars::getSession();
00129             $session['SessionInfo'] = $this->_session;
00130             HttpVars::setSession( $session );
00131         }
00132 
00142         function setCommonData( $copyFormValues = false )
00143         {
00144             $this->_view->setValue( "Year", $this->_session->getValue( 'Year'));
00145             $this->_view->setValue( "Month", $this->_session->getValue( 'Month' ));
00146             
00147             parent::setCommonData( $copyFormValues );
00148         }
00149 
00154         function _getBlogInfo()
00155         {       
00156             // see if we're using subdomains
00157             $config =& Config::getConfig();
00158             if( $config->getValue( "subdomains_enabled" )) {
00159                 include_once( PLOG_CLASS_PATH."class/net/http/subdomains.class.php" );
00160 
00161                 $subdomainInfo = Subdomains::getSubdomainInfoFromRequest();
00162 
00163                 if( !empty($subdomainInfo["blogdomain"]) && $this->_request->getValue( 'blogDomain' ) == "" ) {
00164                     $this->_request->setValue( 'blogDomain', $subdomainInfo["blogdomain"] );
00165                 }
00166                 if( !empty($subdomainInfo["username"]) && $this->_request->getValue( 'blogUserName' ) == "" ) {
00167                     $this->_request->setValue( 'blogUserName', $subdomainInfo["username"] );
00168                 }
00169                 if( !empty($subdomainInfo["blogname"]) && $this->_request->getValue( 'blogName' ) == "" ) {
00170                     $this->_request->setValue( 'blogName', $subdomainInfo["blogname"] );
00171                 }
00172             }
00173 
00174                 $blogId = $this->_request->getValue( 'blogId' );
00175                 $blogName = $this->_request->getValue( 'blogName' );
00176                 $userId = $this->_request->getValue( 'userId' );
00177                 $userName = $this->_request->getValue( 'blogUserName' );
00178             $blogDomain = $this->_request->getValue( 'blogDomain' );
00179 
00180             // if there is a "blogId" parameter, it takes precedence over the
00181             // "user" parameter.
00182             if( !$blogId && !$blogName && !$blogDomain) {
00183                 // check if there was a user parameter
00184                 if( !empty($userName) ) {
00185                     include_once( PLOG_CLASS_PATH."class/dao/users.class.php" );
00186                         // if so, check to which blogs the user belongs
00187                         $users = new Users();
00188                         $userInfo = $users->getUserInfoFromUsername( $userName );
00189                     // if the user exists and is valid...
00190                         if( $userInfo ) {
00191                         $userBlogs = $users->getUsersBlogs( $userInfo->getId(), BLOG_STATUS_ACTIVE );
00192                                                 // check all the blogs and pick the first one that is owned. If none is owned, then pick a random
00193                                                 // one (the last one that was processed)
00194                         if( !empty($userBlogs)) {
00195                                                         $i = 0;
00196                                                         $found = false;
00197                                                         while( $i < count($userBlogs) && !$found ) {
00198                                                                 $blog = $userBlogs[$i];
00199                                                                 if( $blog->getOwnerId() == $userInfo->getId()) $found = true;
00200                                                                 $i++;
00201                                                         }
00202                                                         $blogId = $blog->getId();
00203                         } 
00204                                                 else {
00205                                 $blogId = $this->_config->getValue('default_blog_id');
00206                         }
00207                     } 
00208                                         else {
00209                         $blogId = $this->_config->getValue('default_blog_id');
00210                     }
00211                 }
00212                 else {
00213                     // if there is no user parameter, we take the blogId from the session
00214                     if( $this->_session->getValue('blogId') != '' ) {
00215                         $blogId = $this->_session->getValue('blogId');
00216                     }
00217                     else {
00218                         // get the default blog id from the database
00219                         $blogId = $this->_config->getValue('default_blog_id');                        
00220                     }
00221                 }
00222             }
00223                         
00224             // fetch the BlogInfo object
00225             include_once( PLOG_CLASS_PATH."class/dao/blogs.class.php" );                        
00226             $blogs = new Blogs();
00227             if( $blogId ) {
00228                 $this->_blogInfo = $blogs->getBlogInfo( $blogId );
00229             }
00230             else if($blogName){
00231                 $this->_blogInfo = $blogs->getBlogInfoByName( $blogName );
00232             }
00233             else if($blogDomain){
00234                 $this->_blogInfo = $blogs->getBlogInfoByDomain( $blogDomain );
00235             }
00236             else{
00237                 $this->_blogInfo = false;
00238             }
00239 
00240             $blogExists = true;
00241             
00242             // security checks...
00243             if( $this->_blogInfo == false ) {
00244                                 $blogExists = false;
00245             } else {
00246                     // non-active blogs shouldn't be shown either!
00247                     if( $this->_blogInfo->getStatus() != BLOG_STATUS_ACTIVE )
00248                         $blogExists = false;
00249             }
00250             return $blogExists;
00251         }
00252 
00256         function checkDateParameter()
00257         {
00258                 $date = $this->_request->getValue( 'Date' );
00259                 $val = new IntegerValidator();
00260                 if( $date && $val->validate( $date ) ) {
00261                 $year = substr( $date, 0, 4);
00262                 $month = substr( $date, 4,2 );
00263                 $day = substr( $date, 6, 2);
00264             }
00265             else {
00266                 // to much overhead for just getting the current date
00267                 // :TODO: but we might need to read the timezone to enter a valid date.. not sure ..
00268                 // $t = new Timestamp();
00269                 // $year = $t->getYear();
00270                 $year = date('Y');
00271                 // $month = $t->getMonth();
00272                 $month = date('m');
00273                 // $day = $t->getDay();
00274                 $day = date('d');
00275             }
00276 
00277             $this->_session->setValue( 'Year', $year );
00278             $this->_session->setValue( 'Month', $month );
00279             $this->_session->setValue( 'Day', $day );
00280         }
00281                 
00288                 function _updateReferrer()
00289                 {
00290                         if( $this->_request->getValue( "articleId" ) != "" || 
00291                 $this->_request->getValue( "articleName" ) != "" ) 
00292                                 return true;
00293                                 
00294                 // update the referer statistics
00295             include_once( PLOG_CLASS_PATH."class/dao/referers.class.php" );
00296 
00297             $referers = new Referers();
00298             if (array_key_exists( 'HTTP_REFERER', $_SERVER ))
00299                 $referers->addReferer( $_SERVER['HTTP_REFERER'], 0, $this->_blogInfo->getId());
00300                         
00301                         return true;
00302                 }
00303 
00310         function _getCorrectedDatePeriod( $inDate )
00311         {
00312             $blogSettings = $this->_blogInfo->getSettings();
00313             $serverTimeOffset = $blogSettings->getValue( "time_offset" );
00314             
00315             if( strlen($inDate) == 4 ) 
00316                 {
00317                         $year = $inDate;
00318                         $outDate = Timestamp::getDateWithOffset( $year."0101000000", -$serverTimeOffset );
00319                         $maxDate = Timestamp::getDateWithOffset( $year."1231235959", -$serverTimeOffset );
00320                 } 
00321                 elseif ( strlen($inDate) == 6 )
00322                 {
00323                 $year = substr( $inDate, 0, 4 );
00324                 $month = substr( $inDate, 4, 2 );
00325                 $dayOfMonth = Date_Calc::daysInMonth( $month, $year );
00326                         $outDate = Timestamp::getDateWithOffset( $year.$month."01000000", -$serverTimeOffset );
00327                         $maxDate = Timestamp::getDateWithOffset( $year.$month.$dayOfMonth."235959", -$serverTimeOffset );
00328                 }
00329                 elseif ( strlen($inDate) == 8 )
00330                 {
00331                         $year = substr( $inDate, 0, 4 );
00332                 $month = substr( $inDate, 4, 2 );
00333                 $day = substr( $inDate, 6, 2 );
00334                         $outDate  = Timestamp::getDateWithOffset( $year.$month.$day."000000", -$serverTimeOffset );
00335                 //$maxDate = Timestamp::getDateWithOffset( $year.$month.$day."235959", -$serverTimeOffset );                                                             
00336                 //                                                                                               
00337                 // Fix for issue http://bugs.lifetype.net/view.php?id=1018
00338                 // Although I am not sure if this fix will have other consequences...
00339                                 //
00340                 $maxDate = Timestamp::getDateWithOffset( $year.$month.$day."235959", 0 );
00341                 }
00342                 else
00343                 {
00344                         $maxDate = -1;
00345                         $outDate = $inDate;
00346                 }
00347             
00348             $result["inDate"] = $inDate;
00349             $result["maxDate"] = $maxDate;
00350             $result["adjustedDate"] = $outDate;
00351             
00352             return( $result );
00353         }               
00354 
00355         
00359             function _getPage()
00360             {
00361                     include_once( PLOG_CLASS_PATH."class/data/validator/integervalidator.class.php");           
00362                                 // get the value from the request
00363                                 $page = HttpVars::getRequestValue( "page" );
00364                                 // but first of all, validate it
00365                                 $val = new IntegerValidator();
00366                                 if( !$val->validate( $page ))
00367                                         $page = 1;      
00368 
00369                                 return $page;       
00370             }           
00371     }
00372 ?>