[ 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/admin/ -> adminupdateblogsettingsaction.class.php (source)

   1  <?php
   2  
   3      lt_include( PLOG_CLASS_PATH."class/action/admin/adminaction.class.php" );
   4      lt_include( PLOG_CLASS_PATH."class/dao/blogs.class.php" );
   5      lt_include( PLOG_CLASS_PATH."class/data/validator/stringvalidator.class.php" );
   6      lt_include( PLOG_CLASS_PATH."class/data/validator/blognamevalidator.class.php" );
   7      lt_include( PLOG_CLASS_PATH."class/data/validator/integervalidator.class.php" );
   8      lt_include( PLOG_CLASS_PATH."class/data/textfilter.class.php" );
   9      lt_include( PLOG_CLASS_PATH."class/view/admin/adminblogsettingsview.class.php" );
  10      lt_include( PLOG_CLASS_PATH."class/data/validator/domainvalidator.class.php" );    
  11      lt_include( PLOG_CLASS_PATH."class/data/validator/rules/intrangerule.class.php" );
  12      lt_include( PLOG_CLASS_PATH."class/net/http/subdomains.class.php" );
  13  
  14  
  15      /**
  16       * \ingroup Action
  17       * @private
  18       *
  19       * Action that shows a form to change the settings of the current blog.
  20       */
  21      class AdminUpdateBlogSettingsAction extends AdminAction
  22      {
  23          /**
  24           * Constructor. If nothing else, it also has to call the constructor of the parent
  25           * class, BlogAction with the same parameters
  26           */
  27          function AdminUpdateBlogSettingsAction( $actionInfo, $request )
  28          {
  29              $this->AdminAction( $actionInfo, $request );
  30              
  31              // specific validator that does not allow an integer below 1
  32              $val = new IntegerValidator();
  33              $val->addRule( new IntRangeRule( 1, 99999999 ));
  34              $this->registerFieldValidator( "blogMaxMainPageItems", $val );            
  35              // the rest of validators, as normal...
  36              $this->registerFieldValidator( "blogMaxRecentItems", new IntegerValidator());
  37              $this->registerFieldValidator( "blogName",  new BlogNameValidator());
  38              $this->registerFieldValidator( "blogLocale", new StringValidator());
  39              $this->registerFieldValidator( "blogTemplate", new StringValidator());
  40              $this->registerFieldValidator( "blogCategory", new IntegerValidator());
  41              $this->registerFieldValidator( "blogNumCommentsPerPage", $val );
  42              $this->registerFieldValidator( "blogArticlesOrder", new IntegerValidator());
  43              $this->registerField( "blogAbout" );
  44              $this->registerField( "blogShowMoreEnabled" );
  45              $this->registerField( "blogEnableHtmlarea" );
  46              $this->registerField( "blogEnablePullDownMenu" );
  47              $this->registerField( "blogCommentsEnabled" );
  48              $this->registerField( "blogCommentsOrder" );
  49              $this->registerField( "blogShowFuturePosts" );
  50              $this->registerField( "blogFirstDayOfWeek" );
  51              $this->registerField( "blogTimeOffset" );
  52              $this->registerField( "properties" );
  53              $this->registerField( "blogCategoriesOrder" );
  54              $this->registerField( "blogLinkCategoriesOrder" );
  55              $this->registerField( "blogEnableAutosaveDrafts" );
  56              $this->registerField( "blogShowInSummary" );
  57              $this->registerField( "blogSendNotification" );
  58              $this->registerField( "blogCommentOnlyRegisteredUsers" );
  59              $this->registerField( "blogSubDomain" );
  60              $this->registerField( "blogMainDomain" );
  61              // set the view that we're going to use
  62              $view = new AdminBlogSettingsView( $this->_blogInfo );
  63              $view->setErrorMessage( $this->_locale->tr("error_updating_settings"));
  64              $this->setValidationErrorView( $view );
  65              
  66              $this->requirePermission( "update_blog" );
  67          }
  68          
  69  		function validate()
  70          {
  71              $valid = parent::validate();
  72              
  73              // check to see whether we are going to save subdomain information
  74              if( Subdomains::getSubdomainsEnabled()) {
  75  
  76                  // Translate a few characters to valid names, and remove the rest
  77                  $mainDomain = Textfilter::domainize($this->_request->getValue( "blogMainDomain" ));
  78                  if(!$mainDomain)
  79                      $mainDomain = "?";
  80                  $subDomain = Textfilter::domainize($this->_request->getValue( "blogSubDomain" ));
  81  
  82                  // get list of allowed domains
  83                  $available_domains = Subdomains::getAvailableDomains();
  84                  
  85                  if($mainDomain == "?")
  86                      $this->blogDomain = $subDomain;
  87                  else {
  88                      $this->blogDomain = $subDomain . "." . $mainDomain;
  89                  }                            
  90  
  91                  // make sure the mainDomain parameter is one of the blogAvailableDomains and if not, 
  92                  // force a validation error
  93                  if( !Subdomains::isDomainAvailable( $mainDomain ) || !Subdomains::isValidDomainName( $subDomain )) {
  94                      $valid = false;
  95                      $this->_form->setFieldValidationStatus( "blogSubDomain", false );                    
  96                      $this->validationErrorProcessing();                    
  97                  }
  98                  if( Subdomains::domainNameExists( $this->blogDomain, $this->_blogInfo->getId() )) {
  99                      $valid = false;
 100                      $this->_form->setFieldValidationStatus( "blogSubDomain", false );                    
 101                      $this->validationErrorProcessing();                    
 102                  }                
 103              }
 104  
 105              return( $valid );            
 106          }
 107  
 108          /**
 109           * Carries out the specified action
 110           */
 111          function perform()
 112          {
 113              $config =& Config::getConfig();    
 114      
 115              // fetch the settings from the db and update them accordingly
 116              $blogs = new Blogs();
 117              $blogSettings = $this->_blogInfo->getSettings();
 118              $blogSettings->setValue( "locale", $this->_request->getValue( "blogLocale" ));
 119              $blogSettings->setValue( "show_posts_max", $this->_request->getValue( "blogMaxMainPageItems" ));
 120              $blogSettings->setValue( "recent_posts_max", $this->_request->getValue( "blogMaxRecentItems" ));
 121              $blogSettings->setValue( "time_offset", $this->_request->getValue( "blogTimeOffset" ));
 122              $blogSettings->setValue( "categories_order", $this->_request->getValue( "blogCategoriesOrder" ));
 123              $blogSettings->setValue( "link_categories_order", $this->_request->getValue( "blogLinkCategoriesOrder" ));
 124                 $blogSettings->setValue( "show_more_enabled",  Textfilter::checkboxToBoolean($this->_request->getValue( "blogShowMoreEnabled" )));
 125                 $blogSettings->setValue( "htmlarea_enabled", Textfilter::checkboxToBoolean($this->_request->getValue( "blogEnableHtmlarea" )));
 126                 $blogSettings->setValue( "pull_down_menu_enabled", Textfilter::checkboxToBoolean($this->_request->getValue( "blogEnablePullDownMenu" )));
 127                 $blogSettings->setValue( "comments_enabled", Textfilter::checkboxToBoolean($this->_request->getValue( "blogCommentsEnabled" )));
 128                 $blogSettings->setValue( "show_future_posts_in_calendar",  Textfilter::checkboxToBoolean($this->_request->getValue( "blogShowFuturePosts" )));
 129                 $blogSettings->setValue( "first_day_of_week",  $this->_request->getValue( "blogFirstDayOfWeek" ));
 130                 $blogSettings->setValue( "new_drafts_autosave_enabled", Textfilter::checkboxToBoolean($this->_request->getValue( "blogEnableAutosaveDrafts" )));
 131                 $blogSettings->setValue( "show_comments_max", $this->_request->getValue( "blogNumCommentsPerPage" ));
 132              //$blogSettings->setValue( "comment_only_auth_users", Textfilter::checkboxToBoolean($this->_request->getValue( "blogCommentOnlyRegisteredUsers" )));
 133              $blogSettings->setValue( "comments_order", $this->_request->getValue( "blogCommentsOrder" ));
 134              $blogSettings->setValue( "articles_order", $this->_request->getValue( "blogArticlesOrder" ));
 135              $blogSettings->setValue( "default_send_notification", $this->_request->getValue( "blogSendNotification" ));
 136              $this->_blogInfo->setAbout( Textfilter::filterAllHTML($this->_request->getValue( "blogAbout" )));
 137              $this->_blogInfo->setBlog( Textfilter::filterAllHTML($this->_request->getValue( "blogName" )));
 138              $this->_blogInfo->setSettings( $blogSettings );
 139              $this->_blogInfo->setTemplate( $this->_request->getValue( "blogTemplate" ));
 140              $this->_blogInfo->setProperties( $this->_request->getValue( "properties" ));
 141              $this->_blogInfo->setBlogCategoryId( $this->_request->getValue( "blogCategory" ));
 142              $this->_blogInfo->setMangledBlogName( $this->_blogInfo->getBlog(), true );
 143              $this->_blogInfo->setShowInSummary( Textfilter::checkboxToBoolean( $this->_request->getValue( "blogShowInSummary" )));
 144              
 145              // check to see whether we are going to save subdomain information            
 146              if( Subdomains::getSubdomainsEnabled()) {
 147      
 148                  // Translate a few characters to valid names, and remove the rest
 149                  $mainDomain = Textfilter::domainize($this->_request->getValue( "blogMainDomain" ));
 150                  if(!$mainDomain)
 151                      $mainDomain = "?";
 152                  $subDomain = Textfilter::domainize($this->_request->getValue( "blogSubDomain" ));
 153                  if( !Subdomains::isDomainAvailable( $mainDomain )) {
 154                      $this->_view = new AdminBlogSettingsView( $this->_blogInfo );
 155                      $this->_view->setErrorMessage( $this->_locale->tr("error_updating_blog_domain"));
 156                      $this->_form->setFieldValidationStatus( "blogMainDomain", false );
 157                      $this->setCommonData();
 158                      return false;
 159                  }
 160  
 161                  if( !Subdomains::isValidDomainName( $subDomain )) {
 162                      $this->_view = new AdminBlogSettingsView( $this->_blogInfo );
 163                      $this->_view->setErrorMessage( $this->_locale->tr("error_updating_blog_subdomain"));
 164                      $this->_form->setFieldValidationStatus( "blogSubDomain", false );    
 165                      $this->setCommonData();
 166                      return false;
 167                  }
 168  
 169                  if($mainDomain == "?"){
 170                      $blog_domain = $subDomain;
 171                  }
 172                  else{
 173                      $blog_domain = $subDomain . "." . $mainDomain;
 174                  }
 175  
 176                  $this->_blogInfo->setCustomDomain( $blog_domain );
 177              }            
 178  
 179              // and now update the settings in the database
 180              $blogs = new Blogs();
 181  
 182              // and now we can proceed...
 183              $this->notifyEvent( EVENT_PRE_BLOG_UPDATE, Array( "blog" => &$this->_blogInfo ));
 184              $blogs = new Blogs();
 185              if( !$blogs->updateBlog( $this->_blogInfo )) {
 186                  $this->_view = new AdminBlogSettingsView( $this->_blogInfo );
 187                  $this->_view->setErrorMessage( $this->_locale->tr("error_updating_settings"));
 188                     $this->setCommonData();
 189  
 190                  return false;
 191              }
 192  
 193              $this->_session->setValue( "blogInfo", $this->_blogInfo );
 194              $this->saveSession();
 195  
 196              $this->notifyEvent( EVENT_POST_BLOG_UPDATE, Array( "blog" => &$this->_blogInfo ));
 197              $this->_view = new AdminBlogSettingsView( $this->_blogInfo );
 198              $this->_locale =& Locales::getLocale( $blogSettings->getValue( "locale" ));
 199              $this->_view->setSuccessMessage( $this->_locale->pr("blog_settings_updated_ok", $this->_blogInfo->getBlog()));
 200              $this->setCommonData();
 201  
 202              // clear the cache
 203              CacheControl::resetBlogCache( $this->_blogInfo->getId());
 204  
 205              // better to return true if everything fine
 206              return true;
 207          }
 208      }
 209  ?>


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