[ Index ]
 

Code source de LifeType 1.2.4

Accédez au Source d'autres logiciels libres

Classes | Fonctions | Variables | Constantes | Tables

title

Body

[fermer]

/class/action/ -> blogaction.class.php (source)

   1  <?php
   2  
   3      lt_include( PLOG_CLASS_PATH."class/action/action.class.php" );
   4      lt_include( PLOG_CLASS_PATH."class/config/config.class.php" );
   5      lt_include( PLOG_CLASS_PATH."class/data/validator/integervalidator.class.php" ); 
   6  
   7      /**
   8       * \ingroup Action
   9       *
  10       * Extends the BlogAction class so that some common operations for all the actions
  11       * can be done in one common place, for example to fetch the SessionInfo object
  12       * from the HTTP session.
  13       *
  14       * It is recommended that all the classes implementing actions for the public
  15       * side of the blog extend this one, and do not forget to call BlogView::setCommonData()
  16       * once done with the processing.
  17       */
  18      class BlogAction extends Action 
  19      {
  20  
  21          var $_session;
  22          var $_config;
  23          var $_blogInfo;
  24          var $_locale;
  25          var $_pm;
  26          var $_articles;
  27          var $_userInfo;
  28  
  29          /**
  30           * Constructor. Additionally, it fetches the SessionInfo object from
  31           * the session information
  32           *
  33           *
  34           */
  35          function BlogAction( $actionInfo, $request )
  36          {
  37              lt_include( PLOG_CLASS_PATH."class/plugin/pluginmanager.class.php" );
  38              lt_include( PLOG_CLASS_PATH."class/security/pipeline.class.php" );
  39              lt_include( PLOG_CLASS_PATH."class/net/http/httpvars.class.php" );
  40  
  41              $this->Action( $actionInfo, $request );
  42  
  43              // we use the HttpVars package since then we can access the session object
  44              // independently wether we're using php ver. < 4.1.0 or not
  45              $session = HttpVars::getSession();
  46              $this->_session = $session['SessionInfo'];
  47  
  48              $this->_config =& Config::getConfig();
  49              if( !$this->_getBlogInfo() ) {
  50                  lt_include( PLOG_CLASS_PATH."class/view/view.class.php" );
  51                  lt_include( PLOG_CLASS_PATH."class/view/redirectview.class.php" );
  52                  
  53                  $this->_session->setValue( 'blogId', null );
  54                  $blogDoesNotExistUrl = $this->_config->getValue( "blog_does_not_exist_url" );
  55                  if ( empty($blogDoesNotExistUrl) )
  56                      $blogDoesNotExistUrl = trim( $this->_config->getValue( "base_url" ) );
  57                  
  58                  $this->_view = new RedirectView( $blogDoesNotExistUrl );
  59                  $this->_view->render();
  60                  die();
  61              }
  62  
  63              // save the blogid in the session
  64              $this->_session->setValue( 'blogId', $this->_blogInfo->getId());
  65  
  66              // load userinfo data if any
  67              $this->_userInfo = SessionManager::getUserInfoFromSession();
  68              
  69              $this->checkDateParameter();
  70              
  71              // initialize the plugin manager
  72              $this->_pm =& PluginManager::getPluginManager();
  73              $this->_pm->setBlogInfo( $this->_blogInfo );
  74              $this->_pm->setUserInfo( $this->_userInfo );
  75              
  76              // locale
  77              $this->_locale = $this->_blogInfo->getBlogLocale();
  78  
  79              //
  80              // security stuff
  81              //
  82              $pipeline = new Pipeline( $request, $this->_blogInfo );
  83              $result = $pipeline->process();
  84              //
  85              // if the pipeline blocked the request, then we have
  86              // to let the user know
  87              if( !$result->isValid()) {
  88                  if( !$result->hasView()) {
  89                      // use the default view
  90                      lt_include( PLOG_CLASS_PATH."class/view/errorview.class.php" );
  91                      $message = $this->_locale->tr('error_you_have_been_blocked').'<br/><br/>';
  92                      $message .= $result->getErrorMessage();
  93                      $this->_view = new ErrorView( $this->_blogInfo, $message );
  94                  }
  95                  else {
  96                      // if the filter that forced the processing to stop provided
  97                      // its own view, then use it                
  98                      $this->_view = $result->getView();
  99                  }
 100                  $this->setCommonData();
 101                  $this->_view->render();
 102  
 103                  die();
 104              }
 105              
 106              // update the referrers, if needed
 107              $this->_updateReferrer();
 108              
 109              // get the "page" parameter from the request
 110              $this->_page = $this->_getPage();
 111          }
 112          
 113          /**
 114           * notifies of events using the plugin manager. It also adds a couple of useful parameters!
 115           *
 116           * @see PluginManager
 117           */
 118  		function notifyEvent( $eventType, $params = Array())
 119          {
 120              $params[ 'from' ] = $this->_actionInfo->getActionParamValue();
 121              $params[ 'request' ] = $this->_request;
 122                      
 123              return $this->_pm->notifyEvent( $eventType, $params );
 124          }
 125  
 126          /**
 127           * Saves the information from the session
 128           */
 129          function saveSession()
 130          {
 131              //$_SESSION['SessionInfo'] = $this->_session;
 132              $session = HttpVars::getSession();
 133              $session['SessionInfo'] = $this->_session;
 134              HttpVars::setSession( $session );
 135          }
 136  
 137          /**
 138           * Sets some common information (dirty dirty...)
 139           * @param copyFormValues Whether the values from fields that were registered via
 140           * Action::registerFieldValidator() and Action::registerField() should be passed back to the view
 141           * as variables or not. It defaults to 'false' but this parameter is useful in those cases
 142           * when we would like to force an error to happen (not a validation error) and still keep the
 143           * form values.
 144           * @see Action::setCommonData()
 145           */
 146          function setCommonData( $copyFormValues = false )
 147          {
 148              $this->_view->setValue( "Year", $this->_session->getValue( 'Year'));
 149              $this->_view->setValue( "Month", $this->_session->getValue( 'Month' ));
 150              $this->_view->setValue( "authuser", $this->_userInfo );
 151              $this->_view->setValue( "blog", $this->_blogInfo );
 152              $this->_view->setValue( "blogsettings", $this->_blogInfo->getSettings());            
 153              
 154              parent::setCommonData( $copyFormValues );
 155          }
 156  
 157          /**
 158           * Fetches the information for this blog from the database since we are going to need it
 159           * almost everywhere.
 160           */
 161          function _getBlogInfo()
 162          {    
 163              // see if we're using subdomains
 164              $config =& Config::getConfig();
 165              if( $config->getValue( "subdomains_enabled" )) {
 166                  lt_include( PLOG_CLASS_PATH."class/net/http/subdomains.class.php" );
 167  
 168                  $subdomainInfo = Subdomains::getSubdomainInfoFromRequest();
 169  
 170                  if( !empty($subdomainInfo["blogdomain"]) && $this->_request->getValue( 'blogDomain' ) == "" ) {
 171                      $this->_request->setValue( 'blogDomain', $subdomainInfo["blogdomain"] );
 172                  }
 173                  if( !empty($subdomainInfo["username"]) && $this->_request->getValue( 'blogUserName' ) == "" ) {
 174                      $this->_request->setValue( 'blogUserName', $subdomainInfo["username"] );
 175                  }
 176                  if( !empty($subdomainInfo["blogname"]) && $this->_request->getValue( 'blogName' ) == "" ) {
 177                      $this->_request->setValue( 'blogName', $subdomainInfo["blogname"] );
 178                  }
 179              }
 180  
 181              $blogId = $this->_request->getValue( 'blogId' );
 182              $blogName = $this->_request->getValue( 'blogName' );
 183              $userId = $this->_request->getValue( 'userId' );
 184              $userName = $this->_request->getValue( 'blogUserName' );
 185              $blogDomain = $this->_request->getValue( 'blogDomain' );
 186  
 187              // if there is a "blogId" parameter, it takes precedence over the
 188              // "user" parameter.
 189              if( !$blogId && !$blogName && !$blogDomain) {
 190                  // check if there was a user parameter
 191                  if( !empty($userName) ) {
 192                      lt_include( PLOG_CLASS_PATH."class/dao/users.class.php" );
 193                      // if so, check to which blogs the user belongs
 194                      $users = new Users();
 195                       $userInfo = $users->getUserInfoFromUsername( $userName );
 196                      // if the user exists and is valid...
 197                      if( $userInfo ) {
 198                          $userBlogs = $users->getUsersBlogs( $userInfo->getId(), BLOG_STATUS_ACTIVE );
 199                          // check all the blogs and pick the first one that is owned. If none is owned, then pick a random
 200                          // one (the last one that was processed)
 201                          if( !empty($userBlogs)) {
 202                              $i = 0;
 203                              $found = false;
 204                              while( $i < count($userBlogs) && !$found ) {
 205                                  $blog = $userBlogs[$i];
 206                                  if( $blog->getOwnerId() == $userInfo->getId()) $found = true;
 207                                  $i++;
 208                              }
 209                              $blogId = $blog->getId();
 210                          } 
 211                          else {
 212                              $blogId = $this->_config->getValue('default_blog_id');
 213                          }
 214                      } 
 215                      else {
 216                          $blogId = $this->_config->getValue('default_blog_id');
 217                      }
 218                  }
 219                  else {
 220                      // if there is no user parameter, we take the blogId from the session
 221                      if( $this->_session->getValue('blogId') != '' ) {
 222                          $blogId = $this->_session->getValue('blogId');
 223                      }
 224                      else {
 225                          // get the default blog id from the database
 226                          $blogId = $this->_config->getValue('default_blog_id');                        
 227                      }
 228                  }
 229              }
 230              
 231              // fetch the BlogInfo object
 232              lt_include( PLOG_CLASS_PATH."class/dao/blogs.class.php" );            
 233              $blogs = new Blogs();
 234              if( $blogId ) {
 235                  lt_include( PLOG_CLASS_PATH."class/dao/blogs.class.php" );            
 236                  $blogs = new Blogs();
 237                  $this->_blogInfo = $blogs->getBlogInfo( $blogId );
 238              }
 239              else if($blogName) {
 240                  lt_include( PLOG_CLASS_PATH."class/dao/blogs.class.php" );            
 241                  $blogs = new Blogs();
 242                  $this->_blogInfo = $blogs->getBlogInfoByName( $blogName );
 243              }
 244              else if($blogDomain) {
 245                  lt_include( PLOG_CLASS_PATH."class/dao/blogs.class.php" );
 246                  $blogs = new Blogs();
 247                  $this->_blogInfo = $blogs->getBlogInfoByDomain( $blogDomain );
 248              }
 249              else {
 250                  $this->_blogInfo = false;
 251              }
 252  
 253              $blogExists = true;
 254              
 255              // security checks...
 256              if( $this->_blogInfo == false ) {
 257                  $blogExists = false;
 258              } else {
 259                  // non-active blogs shouldn't be shown either!
 260                  if( $this->_blogInfo->getStatus() != BLOG_STATUS_ACTIVE )
 261                      $blogExists = false;
 262              }
 263              return $blogExists;
 264          }
 265  
 266          /**
 267           * Checks if there is at least a year and a month in the request
 268           */
 269          function checkDateParameter()
 270          {
 271              $date = $this->_request->getValue( 'Date' );
 272              $val = new IntegerValidator();
 273              if( $date && $val->validate( $date ) ) {
 274                  $year = substr( $date, 0, 4);
 275                  $month = substr( $date, 4,2 );
 276                  $day = substr( $date, 6, 2);
 277              }
 278              else {
 279                  // to much overhead for just getting the current date
 280                  // :TODO: but we might need to read the timezone to enter a valid date.. not sure ..
 281                  // $t = new Timestamp();
 282                  // $year = $t->getYear();
 283                  $year = date('Y');
 284                  // $month = $t->getMonth();
 285                  $month = date('m');
 286                  // $day = $t->getDay();
 287                  $day = date('d');
 288              }
 289  
 290              $this->_session->setValue( 'Year', $year );
 291              $this->_session->setValue( 'Month', $month );
 292              $this->_session->setValue( 'Day', $day );
 293          }
 294          
 295          /**
 296           * updates the referrers but only if there is no $articleId parameter in the request. If that's the case,
 297           * it will be left up to the correct action to take care of updating the referrers
 298           *
 299           * @private
 300           */
 301  		function _updateReferrer()
 302          {
 303              if( $this->_request->getValue( "articleId" ) != "" || 
 304                  $this->_request->getValue( "articleName" ) != "" ) 
 305                  return true;
 306                  
 307              // update the referer statistics
 308              lt_include( PLOG_CLASS_PATH."class/dao/referers.class.php" );
 309  
 310              if( $this->_config->getValue( "referer_tracker_enabled", true )) {
 311                  $referers = new Referers();
 312                  if (array_key_exists( 'HTTP_REFERER', $_SERVER ))
 313                      $referers->addReferer( $_SERVER['HTTP_REFERER'], 0, $this->_blogInfo->getId());
 314              }
 315              
 316              return true;
 317          }
 318  
 319          /**
 320           * @private
 321           * Caculate the correct article date period. All the action classes that can take dates in permalinks/links
 322           * need to call this method to calculate the right dates based on the URL and the current
 323           * time offset settings (such as ViewArticleAction or ViewArticleTrackbacksAction)
 324           */                
 325          function _getCorrectedDatePeriod( $inDate )
 326          {
 327              $blogSettings = $this->_blogInfo->getSettings();
 328              $serverTimeOffset = $blogSettings->getValue( "time_offset" );
 329              
 330              if( strlen($inDate) == 4 ) 
 331              {
 332                  $year = $inDate;
 333                  $outDate = Timestamp::getDateWithOffset( $year."0101000000", -$serverTimeOffset );
 334                  $maxDate = Timestamp::getDateWithOffset( $year."1231235959", -$serverTimeOffset );
 335              } 
 336              elseif ( strlen($inDate) == 6 )
 337              {
 338                  $year = substr( $inDate, 0, 4 );
 339                  $month = substr( $inDate, 4, 2 );
 340                  $dayOfMonth = Date_Calc::daysInMonth( $month, $year );
 341                  $outDate = Timestamp::getDateWithOffset( $year.$month."01000000", -$serverTimeOffset );
 342                  $maxDate = Timestamp::getDateWithOffset( $year.$month.$dayOfMonth."235959", -$serverTimeOffset );
 343              }
 344              elseif ( strlen($inDate) == 8 )
 345              {
 346                  $year = substr( $inDate, 0, 4 );
 347                  $month = substr( $inDate, 4, 2 );
 348                  $day = substr( $inDate, 6, 2 );
 349                  $outDate  = Timestamp::getDateWithOffset( $year.$month.$day."000000", -$serverTimeOffset );
 350                  //$maxDate = Timestamp::getDateWithOffset( $year.$month.$day."235959", -$serverTimeOffset );                                                             
 351                  //                                                                                               
 352                  // Fix for issue http://bugs.lifetype.net/view.php?id=1018
 353                  // Although I am not sure if this fix will have other consequences...
 354                  //
 355                  $maxDate = Timestamp::getDateWithOffset( $year.$month.$day."235959", 0 );
 356              }
 357              else
 358              {
 359                  $maxDate = -1;
 360                  $outDate = $inDate;
 361              }
 362              
 363              $result["inDate"] = $inDate;
 364              $result["maxDate"] = $maxDate;
 365              $result["adjustedDate"] = $outDate;
 366              
 367              return( $result );
 368          }        
 369          
 370          /**
 371           * @private
 372           */
 373  	    function _getPage()
 374          {
 375                  lt_include( PLOG_CLASS_PATH."class/data/validator/integervalidator.class.php");        
 376                  // get the value from the request
 377                  $page = HttpVars::getRequestValue( "page" );
 378                  // but first of all, validate it
 379                  $val = new IntegerValidator();
 380                  if( !$val->validate( $page ))
 381                      $page = 1;    
 382  
 383                  return $page;        
 384          }    
 385      }
 386  ?>


Généré le : Mon Nov 26 21:04:15 2007 par Balluche grâce à PHPXref 0.7
  Clicky Web Analytics