| [ 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/admincreateblogview.class.php" ); 5 lt_include( PLOG_CLASS_PATH."class/view/admin/adminsiteblogslistview.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/users.class.php" ); 11 lt_include( PLOG_CLASS_PATH."class/dao/articlecategories.class.php" ); 12 lt_include( PLOG_CLASS_PATH."class/dao/articles.class.php" ); 13 14 /** 15 * \ingroup Action 16 * @private 17 * 18 * Adds a new user to the database. 19 */ 20 class AdminAddBlogAction extends AdminAction 21 { 22 23 var $_blogName; 24 var $_ownerId; 25 var $_blogProperties; 26 27 function AdminAddBlogAction( $actionInfo, $request ) 28 { 29 $this->AdminAction( $actionInfo, $request ); 30 31 // data validation 32 $this->registerFieldValidator( "blogName", new BlogNameValidator()); 33 $this->registerFieldValidator( "userId", new IntegerValidator()); 34 if( Subdomains::getSubdomainsEnabled()) { 35 $this->registerFieldValidator( "blogSubDomain", new DomainValidator()); 36 $this->registerFieldValidator( "blogMainDomain", new DomainValidator()); 37 } 38 39 $this->registerField( "userName" ); 40 $view = new AdminCreateBlogView( $this->_blogInfo ); 41 $view->setErrorMessage( $this->_locale->tr( "error_adding_blog" )); 42 $this->setValidationErrorView( $view ); 43 44 $this->requireAdminPermission( "add_site_blog" ); 45 } 46 47 function perform() 48 { 49 // fetch the validated data 50 $this->_blogName = Textfilter::filterAllHTML($this->_request->getValue( "blogName" )); 51 $this->_ownerId = $this->_request->getValue( "userId" ); 52 $this->_blogProperties = $this->_request->getValue( "properties" ); 53 54 // check that the user really exists 55 $users = new Users(); 56 $userInfo = $users->getUserInfoFromId( $this->_ownerId ); 57 if( !$userInfo ) { 58 $this->_view = new AdminCreateBlogView( $this->_blogInfo ); 59 $this->_form->setFieldValidationStatus( "blogOwner", false ); 60 $this->setCommonData( true ); 61 return false; 62 } 63 64 // now that we have validated the data, we can proceed to create the user, making 65 // sure that it doesn't already exists 66 $blogs = new Blogs(); 67 $blog = new BlogInfo( $this->_blogName, $this->_ownerId, "", "" ); 68 $blog->setProperties( $this->_blogProperties ); 69 70 // check to see whether we are going to save subdomain information 71 if( Subdomains::getSubdomainsEnabled()) { 72 73 // Translate a few characters to valid names, and remove the rest 74 $mainDomain = Textfilter::domainize($this->_request->getValue( "blogMainDomain" )); 75 if(!$mainDomain) 76 $mainDomain = "?"; 77 $subDomain = Textfilter::domainize($this->_request->getValue( "blogSubDomain" )); 78 79 if( !Subdomains::isDomainAvailable( $mainDomain )) { 80 $this->_view = new AdminCreateBlogView( $this->_blogInfo ); 81 $this->_view->setErrorMessage( $this->_locale->tr("error_updating_blog_subdomain")); 82 $this->_form->setFieldValidationStatus( "blogMainDomain", false ); 83 $this->setCommonData(); 84 return false; 85 } 86 87 if( !Subdomains::isValidDomainName( $subDomain )) { 88 $this->_view = new AdminCreateBlogView( $this->_blogInfo ); 89 $this->_view->setErrorMessage( $this->_locale->tr("error_updating_blog_subdomain")); 90 $this->_form->setFieldValidationStatus( "blogSubDomain", false ); 91 $this->setCommonData(); 92 return false; 93 } 94 95 if($mainDomain == "?"){ 96 $blog_domain = $subDomain; 97 } 98 else{ 99 $blog_domain = $subDomain . "." . $mainDomain; 100 } 101 102 $blog->setCustomDomain( $blog_domain ); 103 } 104 105 // save the blog 106 $this->notifyEvent( EVENT_PRE_BLOG_ADD, Array( "blog" => &$blog )); 107 $newBlogId = $blogs->addBlog( $blog ); 108 if( !$newBlogId) { 109 $this->_view = new AdminCreateBlogView( $this->_blogInfo ); 110 $this->_form->setFieldValidationStatus( "blogName", false ); 111 $this->setCommonData(); 112 113 return false; 114 } 115 116 // get the default global article category id 117 lt_include( PLOG_CLASS_PATH."class/dao/globalarticlecategories.class.php" ); 118 $globalArticleCategories = new GlobalArticleCategories(); 119 $globalArticleCategoryId = $this->_config->getValue("default_global_article_category_id"); 120 if( !empty( $globalArticleCategoryId ) ) { 121 $globalArticleCategory = $globalArticleCategories->getGlobalArticleCategory( $globalArticleCategoryId ); 122 if( empty( $globalArticleCategory ) ) 123 $globalArticleCategoryId = 0; 124 } 125 else { 126 $globalArticleCategoryId = 0; 127 } 128 129 // Get the defaul locale object 130 $config =& Config::getConfig(); 131 $locale =& Locales::getLocale( $config->getValue( "default_locale" )); 132 133 // add a default category and a default post 134 $articleCategories = new ArticleCategories(); 135 $articleCategory = new ArticleCategory( $locale->tr( "register_default_category" ), "", $newBlogId, true ); 136 $catId = $articleCategories->addArticleCategory( $articleCategory ); 137 $articleTopic = $locale->tr( "register_default_article_topic" ); 138 $articleText = $locale->tr( "register_default_article_text" ); 139 $article = new Article( $articleTopic, 140 $articleText, 141 Array( $catId ), 142 $this->_ownerId, 143 $newBlogId, 144 POST_STATUS_PUBLISHED, 145 0, 146 Array(), 147 "welcome" ); 148 $article->setGlobalCategoryId( $globalArticleCategoryId ); // set the default ArticleGlobalCategory id to article 149 $t = new Timestamp(); 150 $article->setDateObject( $t ); 151 $article->setInSummary( false ); 152 $articles = new Articles(); 153 $articles->addArticle( $article ); 154 155 // add a new first album so that users can start uploading stuff right away 156 lt_include( PLOG_CLASS_PATH."class/gallery/dao/galleryalbums.class.php" ); 157 lt_include( PLOG_CLASS_PATH."class/gallery/dao/galleryalbum.class.php" ); 158 $album = new GalleryAlbum( $newBlogId, // blog id 159 $locale->tr( "register_default_album_name" ), // album name 160 $locale->tr( "register_default_album_description" ), // album description 161 GALLERY_RESOURCE_PREVIEW_AVAILABLE, // flags 162 0, // no parent id 163 $t->getTimestamp(), // current date 164 Array(), // no properties 165 true ); // show the album in the interface 166 $albums = new GalleryAlbums(); 167 $albums->addAlbum( $album ); 168 169 // add a new default mylinkscategory 170 lt_include( PLOG_CLASS_PATH."class/dao/mylinkscategories.class.php" ); 171 $linksCategory = new MyLinksCategory( $locale->tr("register_default_category" ), $newBlogId ); 172 $linksCategories = new MyLinksCategories(); 173 $linksCategories->addMyLinksCategory( $linksCategory ); 174 175 // and inform everyone that everything went ok 176 $this->notifyEvent( EVENT_POST_BLOG_ADD, Array( "blog" => &$blog )); 177 if( $this->userHasPermission( "view_site_blogs", ADMIN_PERMISSION )) 178 $this->_view = new AdminSiteBlogsListView( $this->_blogInfo ); 179 else 180 $this->_view = new AdminCreateBlogView( $this->_blogInfo ); 181 182 $this->_view->setSuccessMessage($this->_locale->pr("blog_added_ok", $blog->getBlog())); 183 $this->setCommonData(); 184 185 return true; 186 } 187 } 188 ?>
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 |
|