[ 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/summary/action/ -> dofinishregister.class.php (source)

   1  <?php
   2  
   3      lt_include( PLOG_CLASS_PATH."class/summary/action/registeraction.class.php" );
   4      lt_include( PLOG_CLASS_PATH."class/template/cachecontrol.class.php" );    
   5      lt_include( PLOG_CLASS_PATH."class/dao/articlecategories.class.php" );
   6      lt_include( PLOG_CLASS_PATH."class/dao/users.class.php" );
   7      lt_include( PLOG_CLASS_PATH."class/dao/blogs.class.php" );
   8      lt_include( PLOG_CLASS_PATH."class/dao/bloginfo.class.php" );
   9      lt_include( PLOG_CLASS_PATH."class/dao/userinfo.class.php" );
  10      lt_include( PLOG_CLASS_PATH."class/dao/article.class.php" );
  11      lt_include( PLOG_CLASS_PATH."class/dao/articles.class.php" );
  12      lt_include( PLOG_CLASS_PATH."class/summary/mail/summarymailer.class.php" );
  13      lt_include( PLOG_CLASS_PATH."class/summary/view/blogtemplatechooserview.class.php" );
  14      lt_include( PLOG_CLASS_PATH."class/data/validator/stringvalidator.class.php" );    
  15      lt_include( PLOG_CLASS_PATH."class/net/http/subdomains.class.php" );
  16      lt_include( PLOG_CLASS_PATH."class/dao/permissions.class.php" );
  17      lt_include( PLOG_CLASS_PATH."class/dao/userpermissions.class.php" );    
  18  
  19      /**
  20       * Finish the user and blog registration process.
  21        *
  22        * In case you need to blog creation process, take a look at the methods
  23       * preBlogCreatHook, postBlogCreateHook, preUserCreateHook and postUserCreateHook. Unfortunately
  24       * plugins are not supported in summary.php/register.php so implementing your custom
  25       * code in this methods will be considered the cleanest way to customize this process for the
  26       * time being.
  27       *
  28       * @package summary
  29       * @subpackage action
  30       */
  31      class doFinishRegister extends RegisterAction 
  32      {
  33          var $need_confirm;
  34  
  35          /**
  36           * constructor
  37           */
  38          function doFinishRegister( $actionInfo, $request )
  39          {
  40              $this->RegisterAction( $actionInfo, $request );
  41              
  42              $this->registerFieldValidator( "templateId", new StringValidator());
  43              $this->setValidationErrorView( new BlogTemplateChooserView());                        
  44          }   
  45  
  46          /**
  47           * perform
  48            * 
  49           * @private
  50           */
  51          function perform()
  52          {
  53              $this->_view = new SummaryView( "registererror" );
  54              $this->need_confirm = $this->_config->getValue("need_email_confirm_registration");            
  55              
  56              $userId = $this->createUser();
  57              if( !$userId )
  58                  return false;
  59                  
  60              $blogId = $this->createBlog($userId);
  61              if( !$blogId )
  62                  return false;
  63  
  64              // let's assume that everything went fine at this point...
  65              $this->doneRegister();
  66              
  67              // reset the summary cache, since there's new information to show
  68              CacheControl::resetSummaryCache(); 
  69  
  70             return( true );
  71          }
  72  
  73          /**
  74           * create the user
  75           *
  76           * @private
  77           */
  78          function createUser()
  79          {
  80              // all data is already correct
  81              $this->userName = SessionManager::getSessionValue("userName");
  82              $this->userFullName = SessionManager::getSessionValue("userFullName");
  83              $this->userPassword = SessionManager::getSessionValue("userPassword");
  84              $this->userEmail = SessionManager::getSessionValue("userEmail");
  85  
  86              $users = new Users();
  87              $user = new UserInfo( $this->userName, 
  88                          $this->userPassword, 
  89                          $this->userEmail, 
  90                          "", // about myself
  91                          $this->userFullName );
  92  
  93              // if user registration need email confirm, that is
  94              // user must active his account 
  95              if($this->need_confirm == true){
  96                  $user->setStatus(USER_STATUS_UNCONFIRMED);
  97              } else {
  98                  $user->setStatus(USER_STATUS_ACTIVE);
  99              }
 100  
 101              // pre-user create hook
 102              $this->preUserCreateHook( $user );
 103  
 104              $userId = $users->addUser( $user );
 105              if( !$userId ) {
 106                  $this->_view = new SummaryView( "registererror" );
 107                  $this->_view->setErrorMessage( $this->_locale->tr("error_adding_user" ));
 108                  $this->setCommonData( true );
 109                  return false;
 110              }
 111  
 112              // assign the login_perm permission so that the user can log in
 113              $perms = new Permissions();
 114              $loginPerm = $perms->getPermissionByName( "login_perm" );
 115              $userPerms = new UserPermissions();
 116              $userPerm = new UserPermission( $userId, 0, $loginPerm->getId());
 117              $userPerms->grantPermission( $userPerm );
 118  
 119              // post-user create hook
 120              $this->postUserCreateHook( $user );
 121  
 122              return $userId;
 123          }
 124  
 125          /**
 126           * create the blog
 127           *
 128           * @private
 129           */
 130          function createBlog($userId)
 131          {
 132              $this->blogName = stripslashes(SessionManager::getSessionValue("blogName"));
 133              $this->blogDomain = stripslashes(SessionManager::getSessionValue("blogDomain"));
 134              $this->blogCategoryId = SessionManager::getSessionValue("blogCategoryId");
 135              $this->blogLocale = SessionManager::getSessionValue("blogLocale");
 136              $this->templateId = $this->_request->getValue("templateId");
 137          
 138              // get the default locale configured for the site
 139              $blogs = new Blogs();
 140              $blogInfo = new BlogInfo( $this->blogName, $userId, "", "" );
 141  
 142              if($this->need_confirm == 1){
 143                  $blogInfo->setStatus( BLOG_STATUS_UNCONFIRMED );
 144              } else {
 145                  $blogInfo->setStatus( BLOG_STATUS_ACTIVE );
 146              }
 147  
 148              $locale = Locales::getLocale( $this->blogLocale );
 149              $blogInfo->setLocale( $locale );
 150              $blogInfo->setTemplate( $this->templateId );
 151              $blogInfo->setBlogCategoryId( $this->blogCategoryId );
 152  
 153              if( Subdomains::getSubdomainsEnabled()) {
 154                  $blogDomain = SessionManager::getSessionValue( "blogDomain" );
 155                  $blogInfo->setCustomDomain( $blogDomain );
 156              }            
 157  
 158              // pre-blog create hook
 159              $this->preBlogCreateHook( $blogInfo );
 160  
 161              $newblogId = $blogs->addBlog( $blogInfo );
 162  
 163              if( !$newblogId ) {
 164                  $this->_view = new SummaryView( "registererror" );
 165                  $this->_view->setErrorMessage( $this->_locale->tr("error_creating_blog"));
 166                  return false;
 167              }
 168  
 169              // get info about the blog
 170              $blogInfo = $blogs->getBlogInfo( $newblogId );
 171              
 172              $this->_blogInfo = $blogInfo;
 173  
 174              // get the default global article category id
 175              lt_include( PLOG_CLASS_PATH."class/dao/globalarticlecategories.class.php" );
 176              $globalArticleCategories = new GlobalArticleCategories();
 177              $globalArticleCategoryId = $this->_config->getValue("default_global_article_category_id");
 178              if( !empty( $globalArticleCategoryId ) ) {
 179                  $globalArticleCategory = $globalArticleCategories->getGlobalArticleCategory( $globalArticleCategoryId );
 180                  if( empty( $globalArticleCategory ) )
 181                      $globalArticleCategoryId = 0;
 182              }    
 183              else {
 184                  $globalArticleCategoryId = 0;
 185              }
 186                          
 187              // if the blog was created, we can add some basic information
 188              // add a category
 189              $articleCategories = new ArticleCategories();
 190              $articleCategory = new ArticleCategory( $locale->tr("register_default_category" ), "", $newblogId, true );
 191              $catId = $articleCategories->addArticleCategory( $articleCategory );
 192  
 193              // add an article based on that category
 194              $articleTopic = $locale->tr( "register_default_article_topic" );
 195              $articleText  = $locale->tr("register_default_article_text" );
 196              $article = new Article( $articleTopic, 
 197                                      $articleText, 
 198                                      Array( $catId ), 
 199                                      $userId, 
 200                                      $newblogId, 
 201                                      POST_STATUS_PUBLISHED, 
 202                                      0, 
 203                                      Array(), 
 204                                      "welcome" );
 205              $article->setGlobalCategoryId( $globalArticleCategoryId );  // set the default ArticleGlobalCategory id to article
 206              $article->setDateObject( new Timestamp());  // set it to the current date
 207              $article->setCommentsEnabled( true ); // enable comments
 208              $article->setInSummary( false );    // no need to see these in the summary!
 209              $articles = new Articles();
 210              $articles->addArticle( $article );
 211              // add a new first album so that users can start uploading stuff right away
 212              lt_include( PLOG_CLASS_PATH."class/gallery/dao/galleryalbums.class.php" );
 213              lt_include( PLOG_CLASS_PATH."class/gallery/dao/galleryalbum.class.php" );            
 214              $t = new Timestamp();
 215              $album = new GalleryAlbum( $this->_blogInfo->getId(),   // blog id
 216                                         $locale->tr( "register_default_album_name" ), // album name
 217                                         $locale->tr( "register_default_album_description" ), // album description
 218                                         GALLERY_RESOURCE_PREVIEW_AVAILABLE,   // flags
 219                                         0,   // no parent id
 220                                         $t->getTimestamp(),   // current date
 221                                         Array(),   // no properties
 222                                         true );  // show the album in the interface
 223              $albums = new GalleryAlbums();
 224              $albums->addAlbum( $album );
 225              
 226              // add a new default mylinkscategory
 227              lt_include( PLOG_CLASS_PATH."class/dao/mylinkscategories.class.php" );
 228              $linksCategory = new MyLinksCategory( $locale->tr("register_default_category" ), $this->_blogInfo->getId() );
 229              $linksCategories = new MyLinksCategories();
 230              $linksCategories->addMyLinksCategory( $linksCategory ); 
 231  
 232              // post-blog create hook
 233              $this->postBlogCreateHook( $blogInfo );
 234  
 235              return true;
 236          }
 237  
 238          /**
 239           * finished registaration
 240           *
 241           * @private
 242           */
 243          function doneRegister()
 244          {
 245              $this->_view = new SummaryView("registerstep5");
 246              
 247              if($this->need_confirm == 1){
 248                  $this->_view->setValue("need_email_confirm",1);
 249                  SummaryMailer::sendConfirmationEmail( $this->userName );
 250              }
 251              else {
 252                  // add the blog object to the template
 253                  $this->_view->setValue( "blog", $this->_blogInfo );
 254              }
 255  
 256              $this->setCommonData();
 257              return true;
 258          }
 259  
 260          /**
 261           * This method will be called prior to saving the new user to the database. Please
 262           * place here your custom code if needed.
 263           *
 264           * @param user By reference, the UserInfo object with information about the user who we are
 265           * going to create
 266           * @return Always true
 267           */
 268  		function preUserCreateHook( &$user )
 269          {
 270              // please implement here your custom code if needed
 271          }
 272  
 273          /**
 274           * This method will be called after to saving the new user to the database. Please
 275           * place here your custom code if needed.
 276           *
 277           * @param user By reference, the UserInfo object with information about the user who was
 278           * just saved to the database
 279           * @return Always true
 280           */        
 281  		function postUserCreateHook( &$user )
 282          {
 283              // please implement here your custom code if needed
 284          }
 285  
 286          /**
 287           * This method will be called prior to saving the new blog to the database. Please
 288           * place here your custom code if needed.
 289           *
 290           * @param blog By reference, the BlogInfo object with information about the blog that we are
 291           * going to create
 292           * @return Always true
 293           */        
 294  		function preBlogCreateHook( &$blog )
 295          {
 296              // please implement here your custom code if needed
 297          }
 298  
 299          /**
 300           * At this point the blog has already been created, as well as the default albums, link categories,
 301           * and so on. This method could be used to create some new custom fields, activate some plugins
 302           * by default, etc.
 303           *
 304           * @param blog By reference, the BlogInfo object with information about the blog that was just
 305           * created to the database
 306           * @return Always true
 307           */        
 308  		function postBlogCreateHook( &$blog )
 309          {
 310              // please implement here your custom code if needed
 311          }        
 312      }
 313  ?>


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