[ Index ] |
|
Code source de LifeType 1.2.4 |
1 <?php 2 3 lt_include( PLOG_CLASS_PATH."class/action/admin/adminaction.class.php" ); 4 lt_include( PLOG_CLASS_PATH."class/view/admin/adminregisterblogview.class.php" ); 5 lt_include( PLOG_CLASS_PATH."class/view/admin/admindashboardview.class.php" ); 6 lt_include( PLOG_CLASS_PATH."class/data/validator/stringvalidator.class.php" ); 7 lt_include( PLOG_CLASS_PATH."class/data/validator/blognamevalidator.class.php" ); 8 lt_include( PLOG_CLASS_PATH."class/data/validator/integervalidator.class.php" ); 9 lt_include( PLOG_CLASS_PATH."class/data/validator/domainvalidator.class.php" ); 10 lt_include( PLOG_CLASS_PATH."class/dao/blogs.class.php" ); 11 lt_include( PLOG_CLASS_PATH."class/dao/users.class.php" ); 12 lt_include( PLOG_CLASS_PATH."class/dao/articles.class.php" ); 13 lt_include( PLOG_CLASS_PATH."class/dao/articlecategories.class.php" ); 14 lt_include( PLOG_CLASS_PATH."class/data/timestamp.class.php" ); 15 lt_include( PLOG_CLASS_PATH."class/net/http/subdomains.class.php" ); 16 lt_include( PLOG_CLASS_PATH."class/gallery/dao/galleryalbums.class.php" ); 17 lt_include( PLOG_CLASS_PATH."class/dao/mylinkscategories.class.php" ); 18 19 class AdminDoRegisterBlogAction extends AdminAction 20 { 21 22 function AdminDoRegisterBlogAction( $actionInfo, $request ) 23 { 24 $this->AdminAction( $actionInfo, $request ); 25 26 $this->registerFieldValidator( "blogName", new BlogNameValidator()); 27 $this->registerFieldValidator( "blogSubDomain", new DomainValidator(), true ); 28 $this->registerFieldValidator( "blogMainDomain", new DomainValidator(), true ); 29 $this->registerFieldValidator( "blogLocale", new StringValidator()); 30 $this->registerFieldValidator( "templateId", new StringValidator()); 31 $this->registerFieldValidator( "blogCategory", new IntegerValidator()); 32 $this->setValidationErrorView( new AdminRegisterBlogView( $this->_userInfo )); 33 } 34 35 function validate() 36 { 37 if( !parent::validate()) 38 return false; 39 40 $maxBlogsPerUser = $this->_config->getValue( "num_blogs_per_user" ); 41 if( !is_numeric( $maxBlogsPerUser )) 42 $maxBlogsPerUser = DEFAULT_MAX_BLOGS_PER_USER; 43 $numOfUserBlogs = count( $this->_userInfo->getOwnBlogs() ); 44 45 if( $numOfUserBlogs >= $maxBlogsPerUser ) { 46 $this->_view = new AdminRegisterBlogView( $this->_blogInfo, $this->_userInfo ); 47 $this->_view->setErrorMessage( $this->_locale->tr("error_already_over_blog_creation_limition") ); 48 $this->setCommonData(); 49 50 return false; 51 } 52 53 return true; 54 } 55 56 function perform() 57 { 58 // if the validation of data went fine, then we can proceed and add the blog 59 $localeCode = $this->_request->getValue( "blogLocale" ); 60 $template = $this->_request->getValue( "templateId" ); 61 $name = $this->_request->getValue( "blogName" ); 62 $blogCategory = $this->_request->getValue( "blogCategory" ); 63 64 // create the blog... 65 $blog = new BlogInfo( $name, $this->_userInfo->getId(), // owner id 66 '', // about 67 ''); // settings 68 69 // check to see whether we are going to save subdomain information 70 if( Subdomains::getSubdomainsEnabled()) { 71 // Translate a few characters to valid names, and remove the rest 72 $mainDomain = Textfilter::domainize($this->_request->getValue( "blogMainDomain" )); 73 if(!$mainDomain) 74 $mainDomain = "?"; 75 $subDomain = Textfilter::domainize($this->_request->getValue( "blogSubDomain" )); 76 77 if(!Subdomains::isDomainAvailable($mainDomain)){ 78 $this->_view = new AdminRegisterBlogView( $this->_userInfo ); 79 $this->_view->setErrorMessage( $this->_locale->tr("error_updating_blog_subdomain")); 80 $this->setCommonData(); 81 return false; 82 } 83 84 if(!Subdomains::isValidDomainName($subDomain)){ 85 $this->_view = new AdminRegisterBlogView( $this->_userInfo ); 86 $this->_view->setErrorMessage( $this->_locale->tr("error_updating_blog_subdomain")); 87 $this->setCommonData(); 88 return false; 89 } 90 91 if($mainDomain == "?"){ 92 $blog_domain = $subDomain; 93 } 94 else{ 95 $blog_domain = $subDomain . "." . $mainDomain; 96 } 97 98 $blog->setCustomDomain( $blog_domain ); 99 } 100 101 // set the template 102 $blog->setTemplate( $template ); 103 // set the locale 104 $locale =& Locales::getLocale( $localeCode ); 105 $blog->setLocale( $locale ); 106 // and set the status to ready 107 $blog->setStatus( BLOG_STATUS_ACTIVE ); 108 // set the blog category 109 $blog->setBlogCategoryId( $blogCategory ); 110 111 // and finally add everything to the db 112 $blogs = new Blogs(); 113 if( !$blogs->addBlog( $blog )) { 114 $this->_view = new AdminRegisterBlogView( $this->_userInfo ); 115 $this->setCommonData( true ); 116 } 117 118 $newBlogId = $blog->getId(); 119 $articleCategories = new ArticleCategories(); 120 $articleCategory = new ArticleCategory( $locale->tr("register_default_category"), "", $newBlogId, true ); 121 $catId = $articleCategories->addArticleCategory( $articleCategory ); 122 $articleTopic = $locale->tr( "register_default_article_topic" ); 123 $articleText = $locale->tr( "register_default_article_text" ); 124 $article = new Article( $articleTopic, 125 $articleText, 126 Array( $catId ), 127 $this->_userInfo->getId(), 128 $newBlogId, 129 POST_STATUS_PUBLISHED, 130 0, 131 Array(), 132 "welcome" ); 133 $t = new Timestamp(); 134 $article->setDateObject( $t ); 135 $articles = new Articles(); 136 $articles->addArticle( $article ); 137 138 // create a new link category and album 139 $t = new Timestamp(); 140 $album = new GalleryAlbum( $newBlogId, // blog id 141 $locale->tr( "register_default_album_name" ), // album name 142 $locale->tr( "register_default_album_description" ), // album description 143 GALLERY_RESOURCE_PREVIEW_AVAILABLE, // flags 144 0, // no parent id 145 $t->getTimestamp(), // current date 146 Array(), // no properties 147 true ); // show the album in the interface 148 $albums = new GalleryAlbums(); 149 $albums->addAlbum( $album ); 150 151 // add a new default mylinkscategory 152 lt_include( PLOG_CLASS_PATH."class/dao/mylinkscategories.class.php" ); 153 $linksCategory = new MyLinksCategory( $locale->tr("register_default_category" ), $newBlogId ); 154 $linksCategories = new MyLinksCategories(); 155 $linksCategories->addMyLinksCategory( $linksCategory ); 156 157 // after we update everything, we need to get the userInfo from db and set to session again. 158 lt_include( PLOG_CLASS_PATH."class/dao/users.class.php" ); 159 $users = new Users(); 160 $this->_userInfo = $users->getUserInfoFromId( $this->_userInfo->getId() ); 161 $this->_session->setValue( "userInfo", $this->_userInfo ); 162 $this->saveSession(); 163 164 // redirect process to the dashboard view 165 $usersBlogs = $users->getUsersBlogs( $this->_userInfo->getId(), BLOG_STATUS_ACTIVE ); 166 $this->_view = new AdminDashboardView( $this->_userInfo, $usersBlogs ); 167 } 168 } 169 ?>
titre
Description
Corps
titre
Description
Corps
titre
Description
Corps
titre
Corps
Généré le : Mon Nov 26 21:04:15 2007 | par Balluche grâce à PHPXref 0.7 |
![]() |