[pLog-svn] r2306 - in plog/trunk: class/action/admin class/controller class/view/admin templates/admin

oscar at devel.plogworld.net oscar at devel.plogworld.net
Tue Jul 12 21:15:13 GMT 2005


Author: oscar
Date: 2005-07-12 21:15:12 +0000 (Tue, 12 Jul 2005)
New Revision: 2306

Added:
   plog/trunk/class/action/admin/admindoregisterblogaction.class.php
   plog/trunk/class/action/admin/adminregisterblogaction.class.php
   plog/trunk/class/view/admin/adminregisterblogview.class.php
   plog/trunk/templates/admin/registerblog.template
Modified:
   plog/trunk/class/action/admin/adminaction.class.php
   plog/trunk/class/controller/admincontrollermap.properties.php
   plog/trunk/class/view/admin/admindashboardview.class.php
   plog/trunk/templates/admin/dashboard.template
   plog/trunk/templates/admin/globalsettings_summary.template
Log:
this implements feature request http://bugs.plogworld.net/view.php?id=494. It adds a new option to the dashboard called "create new blog" that allows for already registered users to create new blogs even if they do not have access to the "administration" section. I've also added a new configuration parameter called "num_blogs_per_user" that controls how many blogs a user can own... so that administrators can allow only 1, 2 or X blogs per user.

Modified: plog/trunk/class/action/admin/adminaction.class.php
===================================================================
--- plog/trunk/class/action/admin/adminaction.class.php	2005-07-12 21:08:45 UTC (rev 2305)
+++ plog/trunk/class/action/admin/adminaction.class.php	2005-07-12 21:15:12 UTC (rev 2306)
@@ -61,7 +61,9 @@
             // do the same with the information about the blog
             $this->_getBlogInfo();
             if( $this->_blogInfo == "" ) {
-            	if( $this->_actionInfo->getActionParamValue() != "blogSelect" ) {
+            	if( $this->_actionInfo->getActionParamValue() != "blogSelect" &&
+            	    $this->_actionInfo->getActionParamValue() != "registerBlog" &&
+            	    $this->_actionInfo->getActionParamValue() != "finishRegisterBlog" ) {
                 	header( "HTTP/1.0 403 Forbidden" );
                 	print($this->mustAuthenticatePage());
                     die();
@@ -140,7 +142,8 @@
         	$this->_view->setValue( "user", $this->_userInfo );
 			$this->_view->setUserInfo( $this->_userInfo );
             $this->_view->setValue( "blog", $this->_blogInfo );
-            $this->_view->setValue( "blogsettings", $this->_blogInfo->getSettings());
+            if( $this->_blogInfo )
+            	$this->_view->setValue( "blogsettings", $this->_blogInfo->getSettings());
             $this->_view->setValue( "op", $this->_actionInfo->_actionParamValue );
 			$this->_view->setValue( "locale", $this->_locale );
 			$this->_view->setValue( "config", $this->_config );

Added: plog/trunk/class/action/admin/admindoregisterblogaction.class.php
===================================================================
--- plog/trunk/class/action/admin/admindoregisterblogaction.class.php	2005-07-12 21:08:45 UTC (rev 2305)
+++ plog/trunk/class/action/admin/admindoregisterblogaction.class.php	2005-07-12 21:15:12 UTC (rev 2306)
@@ -0,0 +1,79 @@
+<?php
+
+	include_once( PLOG_CLASS_PATH."class/action/admin/adminaction.class.php" );
+	include_once( PLOG_CLASS_PATH."class/view/admin/adminregisterblogview.class.php" );
+	include_once( PLOG_CLASS_PATH."class/view/admin/admindashboardview.class.php" );	
+	include_once( PLOG_CLASS_PATH."class/data/validator/stringvalidator.class.php" );
+	include_once( PLOG_CLASS_PATH."class/dao/blogs.class.php" );
+	include_once( PLOG_CLASS_PATH."class/dao/users.class.php" );
+	include_once( PLOG_CLASS_PATH."class/dao/articles.class.php" );	
+	include_once( PLOG_CLASS_PATH."class/dao/articlecategories.class.php" );
+	include_once( PLOG_CLASS_PATH."class/data/timestamp.class.php" );
+	
+	class AdminDoRegisterBlogAction extends AdminAction
+	{
+	
+		function AdminDoRegisterBlogAction( $actionInfo, $request )
+		{
+			$this->AdminAction( $actionInfo, $request );
+			
+			$this->registerFieldValidator( "blogName", new StringValidator());
+			$this->registerFieldValidator( "blogLocale", new StringValidator());
+			$this->registerFieldValidator( "templateId", new StringValidator());
+			$this->setValidationErrorView( new AdminRegisterBlogView( $this->_userInfo ));
+		}
+		
+		function perform()
+		{
+			// if the validation of data went fine, then we can proceed and add the blog
+			$localeCode = $this->_request->getValue( "localeId" );
+			$template = $this->_request->getValue( "templateId" );
+			$name = $this->_request->getValue( "blogName" );
+			
+			// create the blog...
+			$blog = new BlogInfo( $name, $this->_userInfo->getId(),  // name
+			                      $this->_userInfo->getId(),  // owner id
+			                      '',  // about
+			                      '');  // settings
+			// set the template
+			$blog->setTemplate( $template );
+			// set the locale
+			$locale = Locales::getLocale( $localeCode );
+			$blog->setLocale( $locale );
+			// and set the status to ready
+			$blog->setStatus( BLOG_STATUS_ACTIVE );
+			
+			// and finally add everything to the db
+			$blogs = new Blogs();
+			if( !$blogs->addBlog( $blog )) {
+				$this->_view = new AdminRegisterBlogView( $this->_userInfo );
+				$this->setCommonData( true );
+			}
+			
+			$newBlogId = $blog->getId();
+            $articleCategories = new ArticleCategories();
+            $articleCategory = new ArticleCategory( "General", "", $newBlogId, true );
+            $catId = $articleCategories->addArticleCategory( $articleCategory );
+            $articleTopic = $locale->tr( "register_default_article_topic" );
+            $articleText  = $locale->tr( "register_default_article_text" );
+            $article = new Article( $articleTopic, 
+                                    $articleText, 
+                                    Array( $catId ), 
+                                    $this->_userInfo->getId(), 
+                                    $newBlogId, 
+                                    POST_STATUS_PUBLISHED, 
+                                    0, 
+                                    Array(), 
+                                    "welcome" );
+            $t = new Timestamp();
+            $article->setDateObject( $t );
+            $articles = new Articles();
+            $articles->addArticle( $article );	           
+						
+			// redirect process to the dashboard view
+			$users = new Users();
+			$usersBlogs = $users->getUsersBlogs( $this->_userInfo->getId(), BLOG_STATUS_ACTIVE );
+			$this->_view = new AdminDashboardView( $this->_userInfo, $usersBlogs ); 
+		}
+	}
+?>
\ No newline at end of file

Added: plog/trunk/class/action/admin/adminregisterblogaction.class.php
===================================================================
--- plog/trunk/class/action/admin/adminregisterblogaction.class.php	2005-07-12 21:08:45 UTC (rev 2305)
+++ plog/trunk/class/action/admin/adminregisterblogaction.class.php	2005-07-12 21:15:12 UTC (rev 2306)
@@ -0,0 +1,20 @@
+<?php
+
+	include_once( PLOG_CLASS_PATH."class/action/admin/adminaction.class.php" );
+	include_once( PLOG_CLASS_PATH."class/view/admin/adminregisterblogview.class.php" );
+	
+	class AdminRegisterBlogAction extends AdminAction
+	{
+	
+		function AdminRegisterBlogAction( $actionInfo, $request )
+		{
+			$this->AdminAction( $actionInfo, $request );
+		}
+		
+		function perform()
+		{
+			$this->_view = new AdminRegisterBlogView( $this->_userInfo );
+			$this->_view->setValue( "form", $this->_form );
+		}
+	}
+?>
\ No newline at end of file

Modified: plog/trunk/class/controller/admincontrollermap.properties.php
===================================================================
--- plog/trunk/class/controller/admincontrollermap.properties.php	2005-07-12 21:08:45 UTC (rev 2305)
+++ plog/trunk/class/controller/admincontrollermap.properties.php	2005-07-12 21:15:12 UTC (rev 2306)
@@ -252,4 +252,11 @@
     $actions["purgeUsers"] = "AdminPurgeUsersAction";	
 	// removes all blogs marked as deleted
 	$actions["purgeBlogs"] = "AdminPurgeBlogsAction";
+    // register a new blog
+    $actions["registerBlog"] = "AdminRegisterBlogAction";
+    $actions["finishRegisterBlog"] = "AdminDoRegisterBlogAction";    
+	// global blog categories
+	$actions["newBlogCategory"] = "AdminNewBlogCategoryAction";
+	$actions["addBlogCategory"] = "AdminAddBlogCategoryAction";	
+	$actions["editBlogCategories"] = "AdminBlogCategoriesAction";	
 ?>

Modified: plog/trunk/class/view/admin/admindashboardview.class.php
===================================================================
--- plog/trunk/class/view/admin/admindashboardview.class.php	2005-07-12 21:08:45 UTC (rev 2305)
+++ plog/trunk/class/view/admin/admindashboardview.class.php	2005-07-12 21:15:12 UTC (rev 2306)
@@ -6,12 +6,18 @@
 	include_once( PLOG_CLASS_PATH."class/dao/articles.class.php" );
 	include_once( PLOG_CLASS_PATH."class/dao/articlecomments.class.php" );
 	include_once( PLOG_CLASS_PATH."class/dao/trackbacks.class.php" );
+	include_once( PLOG_CLASS_PATH."class/config/config.class.php" );
 //	include_once( PLOG_CLASS_PATH."class/gallery/dao/galleryresources.class.php" );
 	
 	/**
 	 * maximum number of recent items that we will show in the statistics
 	 */
 	define( "DASHBOARD_MAX_RECENT_ITEMS", 5 );	
+	
+	/**
+	 * how many blogs a user can own, by default
+	 */
+	define( "DEFAULT_MAX_BLOGS_PER_USER", 1 ); 
 
     /**
      * \ingroup View
@@ -24,6 +30,7 @@
 	
 		var $_userInfo;
 		var $_userBlogs;
+		var $_config;
 
     	/**
          * This initializes the class, but normally we'll only have to initialize the parent
@@ -38,6 +45,7 @@
 			// keep the paramters for later use
 			$this->_userInfo = $userInfo;
 			$this->_userBlogs = $userBlogs;
+            $this->_config =& Config::getConfig();			
 			
 			$this->_loadViewData();
         }
@@ -61,6 +69,7 @@
 			$recentResources = Array();
 			
 			// load some statistics	for each one of the blogs
+			$numOwnedBlogs = 0;			
 			foreach( $this->_userBlogs as $userBlog ) {
 				$recentPosts[$userBlog->getId()] = $articles->getBlogArticles( $userBlog->getId(), 
 																			   -1, 
@@ -69,12 +78,28 @@
 																			   POST_STATUS_PUBLISHED );
 				$recentComments[$userBlog->getId()] = $comments->getBlogComments ( $userBlog->getId(), DASHBOARD_MAX_RECENT_ITEMS );
 				$recentTrackbacks[$userBlog->getId()] = $trackbacks->getBlogTrackbacks( $userBlog->getId(), DASHBOARD_MAX_RECENT_ITEMS );
+				
+				if( $userBlog->getOwner() == $this->_userInfo->getId())
+					$numOwnedBlogs++;
 			}
 		
 			$this->_params->setValue( "userblogs", $this->_userBlogs );
 			$this->_params->setValue( "recentposts", $recentPosts );
 			$this->_params->setValue( "recentcomments", $recentComments );
 			$this->_params->setValue( "recenttrackbacks", $recentTrackbacks );
+			
+			// check whether the user can create new blogs
+			$maxBlogsPerUser = $this->_config->getValue( "num_blogs_per_user" );
+			if( !is_numeric( $maxBlogsPerUser ))
+				$maxBlogsPerUser = DEFAULT_MAX_BLOGS_PER_USER;
+				
+			if( $maxBlogsPerUser == 0 )
+				$userCanCreateBlog = true;
+			else {
+				$userCanCreateBlog = ($numOwnedBlogs < $maxBlogsPerUser);
+			}
+			
+			$this->_params->setValue( "userCanCreateBlog", $userCanCreateBlog );
 		}
 
         /**
@@ -85,8 +110,7 @@
         function render()
         {
 			// set the view character set based on the default locale
-            $config =& Config::getConfig();
-            $locale =& Locales::getLocale( $config->getValue( "default_locale" ));			
+            $locale =& Locales::getLocale( $this->_config->getValue( "default_locale" ));			
 			$this->setCharset( $locale->getCharset());		
 		
 			parent::render();
@@ -101,5 +125,10 @@
             // and send the results
             print $template->fetch();
         }
+        
+        function setUserInfo()
+        {
+        	// ...
+        }
     }
-?>
+?>
\ No newline at end of file

Added: plog/trunk/class/view/admin/adminregisterblogview.class.php
===================================================================
--- plog/trunk/class/view/admin/adminregisterblogview.class.php	2005-07-12 21:08:45 UTC (rev 2305)
+++ plog/trunk/class/view/admin/adminregisterblogview.class.php	2005-07-12 21:15:12 UTC (rev 2306)
@@ -0,0 +1,48 @@
+<?php
+
+	include_once( PLOG_CLASS_PATH."class/view/view.class.php" );
+	include_once( PLOG_CLASS_PATH."class/config/config.class.php" );
+	include_once( PLOG_CLASS_PATH."class/locale/locales.class.php" );
+	include_once( PLOG_CLASS_PATH."class/template/templatesets/templatesets.class.php" );
+	
+	class AdminRegisterBlogView extends View
+	{
+		var $_userInfo;
+	
+		function AdminRegisterBlogView( $userInfo )
+		{
+			$this->View();
+			
+			$this->_userInfo = $userInfo;
+		}
+		
+		function setUserInfo( $user )
+		{
+			// whatever...
+		}
+		
+		function render()
+		{
+			// set the view character set based on the default locale
+            $config =& Config::getConfig();
+            $locale =& Locales::getLocale( $config->getValue( "default_locale" ));			
+			$this->setCharset( $locale->getCharset());		
+		
+			parent::render();
+			
+            $ts = new TemplateService();
+        	$template = $ts->AdminTemplate( "registerblog" );
+        	// assign a few values that have been loaded locally
+            $this->setValue( "locale", $locale );
+            $this->setValue( "user", $this->_userInfo );
+            $this->setValue( "locales", Locales::getLocales());
+            $ts = new TemplateSets();
+            $this->setValue( "templates", $ts->getGlobalTemplateSets());
+            // assign all the values
+            $template->assign( $this->_params->getAsArray());
+
+            // and send the results
+            print $template->fetch();		
+		}
+	}
+?>
\ No newline at end of file

Modified: plog/trunk/templates/admin/dashboard.template
===================================================================
--- plog/trunk/templates/admin/dashboard.template	2005-07-12 21:08:45 UTC (rev 2305)
+++ plog/trunk/templates/admin/dashboard.template	2005-07-12 21:15:12 UTC (rev 2306)
@@ -5,6 +5,7 @@
             <h2>{$locale->tr("dashboard")}</h2>
         </div>
         <div class="dashboard_logout_link">
+          {if $userCanCreateBlog}<a href="?op=registerBlog">{$locale->tr("create_blog")}</a>{/if}
           <a href="?op=blogSelect&amp;blogId={$userblogs[0]->getId()}&amp;action=Logout">{$locale->tr("logout")}</a>
         </div>
         <br style="clear:both;" />

Modified: plog/trunk/templates/admin/globalsettings_summary.template
===================================================================
--- plog/trunk/templates/admin/globalsettings_summary.template	2005-07-12 21:08:45 UTC (rev 2305)
+++ plog/trunk/templates/admin/globalsettings_summary.template	2005-07-12 21:15:12 UTC (rev 2306)
@@ -46,4 +46,10 @@
     <input class="radio" type="radio" id="config[need_email_confirm_registration]" name="config[need_email_confirm_registration]" value="1" {if $need_email_confirm_registration == 1 } checked="checked" {/if} />{$locale->tr("yes")}
     <input class="radio" type="radio" id="config[need_email_confirm_registration]" name="config[need_email_confirm_registration]" value="0" {if $need_email_confirm_registration == 0 } checked="checked" {/if} />{$locale->tr("no")}
   </div>
+   <!-- num_blogs_per_user -->
+   <div class="field">
+    <label for="config[num_blogs_per_user]">num_blogs_per_user</label>
+	<div class="formHelp">{$locale->tr("help_num_blogs_per_user")}</div> 
+    <input style="width:100%" type="text" id="config[num_blogs_per_user]" name="config[num_blogs_per_user]" value="{$num_blogs_per_user}"/>	
+  </div>  
  </div> 
\ No newline at end of file

Added: plog/trunk/templates/admin/registerblog.template
===================================================================
--- plog/trunk/templates/admin/registerblog.template	2005-07-12 21:08:45 UTC (rev 2305)
+++ plog/trunk/templates/admin/registerblog.template	2005-07-12 21:15:12 UTC (rev 2306)
@@ -0,0 +1,59 @@
+{include file="$admintemplatepath/simpleheader.template"}
+
+    <div id="nav_bar">
+        <div id="section_title">
+            <h2>{$locale->tr("register_blog")}</h2>
+        </div>
+        <br style="clear:both;" />
+    </div>
+    </div>
+    <div id="dashboard">
+ <form name="createBlog" action="admin.php" method="post">
+  <fieldset class="inputField">
+   <legend>{$locale->tr("step2")}</legend>
+   {include file="$admintemplatepath/errormessage.template" message=$locale->tr("error_adding_blog")}
+   <div class="field">
+     <label for="blogName">{$locale->tr("name")}</label>
+     <span class="required">*</span>
+     <div class="formHelp">{$locale->tr("register_blog_name_help")}</div>
+     <input type="text" name="blogName" value="{$blogName}" id="blogName" />
+     {include file="$admintemplatepath/validate.template" field=blogName message=$locale->tr("error_empty_name")}
+   </div>  
+   <div class="field">
+     <label for="blogLocale">{$locale->tr("language")}</label>
+     <span class="required">*</span>
+     <div class="formHelp">{$locale->tr("blog_language_help")}</div>
+     <select name="blogLocale" id="blogLocale">
+      {foreach from=$locales item=localeObject}
+        <option value="{$localeObject->getLocaleCode()}" {if $defaultLocale == $localeObject->getLocaleCode()}selected="selected"{/if}>{$localeObject->getDescription()}</option>
+      {/foreach}
+     </select>
+     {include file="$admintemplatepath/validate.template" field=blogLocale message=$locale->tr("error_empty_locale")}
+   </div>
+   <div class="field">
+	<label for="">{$locale->tr("select_template")}</label>
+	<div class="formHelp">{$locale->tr("register_step3_help")}</div>
+    {include file="$admintemplatepath/validate.template" field=templateId message=$locale->tr("error_must_choose_template")}	
+    {foreach from=$templates item=template}
+     {assign var=templateName value=$template->getName()}
+     <div class="templateScreen">
+     <a href="javascript:openWindow('{$template->getScreenshotUrl()}','Screenshot','scrollbars=yes,resizable=yes,width=400,height=300');"><img src="{$template->getScreenshotUrl()}" alt="{$templateName}" height="150" width="200" /></a><br/>
+     <input type="radio" class="checkbox" value="{$template->getName()}" name="templateId" id="templateId" {if $templateId==$template->getName()}checked="checked"{/if}/>
+     <label for="templateId"><strong>{$templateName}</strong></label>
+     <br/><br/>
+     </div>
+    {/foreach}
+   </div>   
+  </fieldset>
+  <div class="buttons">
+    <input type="button" onClick="javascript:window.location='admin.php?op=Dashboard'" value="&laquo; {$locale->tr("back")}" />
+    <input type="submit" name="{$locale->tr("register")}" value="{$locale->tr("register_blog")} &raquo;"/>
+    <input type="hidden" name="op" value="finishRegisterBlog" />
+    <input type="hidden" name="userName" value="{$userName}" />
+    <input type="hidden" name="userFullName" value="{$userFullName}" />
+    <input type="hidden" name="userPassword" value="{$userPassword}" />
+    <input type="hidden" name="userEmail" value="{$userEmail}" />
+  </div>  
+ </form>
+    </div>
+{include file="$admintemplatepath/footer.template"}




More information about the pLog-svn mailing list