[pLog-svn] r1945 - in plog/branches/plog-1.0.1: . class/summary/action class/summary/view

oscar at devel.plogworld.net oscar at devel.plogworld.net
Thu May 5 19:39:50 GMT 2005


Author: oscar
Date: 2005-05-05 19:39:50 +0000 (Thu, 05 May 2005)
New Revision: 1945

Modified:
   plog/branches/plog-1.0.1/class/summary/action/activeaccountaction.class.php
   plog/branches/plog-1.0.1/class/summary/action/blogprofileaction.class.php
   plog/branches/plog-1.0.1/class/summary/action/dofinishregister.class.php
   plog/branches/plog-1.0.1/class/summary/action/doreadagreement.class.php
   plog/branches/plog-1.0.1/class/summary/action/dousercreation.class.php
   plog/branches/plog-1.0.1/class/summary/action/registeraction.class.php
   plog/branches/plog-1.0.1/class/summary/action/summaryaction.class.php
   plog/branches/plog-1.0.1/class/summary/action/summarydefaultaction.class.php
   plog/branches/plog-1.0.1/class/summary/action/summaryrssaction.class.php
   plog/branches/plog-1.0.1/class/summary/action/summarysearchaction.class.php
   plog/branches/plog-1.0.1/class/summary/action/summarysendresetemail.class.php
   plog/branches/plog-1.0.1/class/summary/action/userprofileaction.class.php
   plog/branches/plog-1.0.1/class/summary/view/summarybloglistview.class.php
   plog/branches/plog-1.0.1/class/summary/view/summarycachedview.class.php
   plog/branches/plog-1.0.1/class/summary/view/summaryview.class.php
   plog/branches/plog-1.0.1/summary.php
Log:
fixed issue 462, based on the idea from a post in the forums. The guy already implemented this in his own way, but I thought that this feature might be wort having. Basically now it is possible choose in which language we'd like to see the summary, by using the "lang" parameter in the request as in:

http://yourhost/plog/summary.php?lang=en_UK

The language identifier should be one of the available locales in the system. If the identifier is not correct, the value set as default_locale will be used.

Whenever a choice is made, it is saved in the session for future use. The parameter in request always has the highest priority, then the data session and finally default_locale will be used.

The summary templates have not been modified to reflect this change and I think we should leave it up to site owners whether to publicize this feature or not. 

I've also cleaned up the code a bit for this change, since Locales::getLocale() was called in waaaay too many places in the code. Now it's only called once for all actions and views, so this should also help to save some memory... Let me know if there is any issue with this. 

Modified: plog/branches/plog-1.0.1/class/summary/action/activeaccountaction.class.php
===================================================================
--- plog/branches/plog-1.0.1/class/summary/action/activeaccountaction.class.php	2005-05-05 19:26:13 UTC (rev 1944)
+++ plog/branches/plog-1.0.1/class/summary/action/activeaccountaction.class.php	2005-05-05 19:39:50 UTC (rev 1945)
@@ -1,27 +1,24 @@
 <?php
 
-include_once(PLOG_CLASS_PATH.'class/action/action.class.php');
+include_once(PLOG_CLASS_PATH.'class/summary/action/summaryaction.class.php');
 include_once(PLOG_CLASS_PATH.'class/data/validator/stringvalidator.class.php');
 include_once(PLOG_CLASS_PATH.'class/dao/users.class.php');
 include_once(PLOG_CLASS_PATH.'class/dao/blogs.class.php');
 include_once(PLOG_CLASS_PATH.'class/summary/view/summarymessageview.class.php');
-
 include_once(PLOG_CLASS_PATH.'class/logger/LogUtil.php');
 
-class ActiveAccountAction extends Action {
+class ActiveAccountAction extends SummaryAction 
+{
 
     var $username;
     var $activeCode;
 
-    var $_locale;
+    function ActiveAccountAction($actionInfo,$httpRequest)
+    {
+        $this->SummaryAction($actionInfo,$httpRequest);
 
-    function ActiveAccountAction($actionInfo,$httpRequest){
-        $this->Action($actionInfo,$httpRequest);
-
         $this->registerFieldValidator("username",new StringValidator());
         $this->registerFieldValidator("activeCode",new StringValidator());
-
-        $this->_locale = & Locales::getLocale();
     }
 
     function perform(){

Modified: plog/branches/plog-1.0.1/class/summary/action/blogprofileaction.class.php
===================================================================
--- plog/branches/plog-1.0.1/class/summary/action/blogprofileaction.class.php	2005-05-05 19:26:13 UTC (rev 1944)
+++ plog/branches/plog-1.0.1/class/summary/action/blogprofileaction.class.php	2005-05-05 19:39:50 UTC (rev 1945)
@@ -67,8 +67,9 @@
 												 
 			
 			$this->_view->setValue( "blog", $blogInfo );
-			$this->_view->setValue( "locale", $this->_locale );
 			$this->_view->setValue( "blogposts", $posts );
+			
+			$this->setCommonData();			
 		
             return true;
         }

Modified: plog/branches/plog-1.0.1/class/summary/action/dofinishregister.class.php
===================================================================
--- plog/branches/plog-1.0.1/class/summary/action/dofinishregister.class.php	2005-05-05 19:26:13 UTC (rev 1944)
+++ plog/branches/plog-1.0.1/class/summary/action/dofinishregister.class.php	2005-05-05 19:39:50 UTC (rev 1945)
@@ -11,7 +11,7 @@
      * @package summary
      * @subpackage action
      */
-    class doFinishRegister extends registerAction 
+    class doFinishRegister extends RegisterAction 
 	{
         var $need_confirm;
 

Modified: plog/branches/plog-1.0.1/class/summary/action/doreadagreement.class.php
===================================================================
--- plog/branches/plog-1.0.1/class/summary/action/doreadagreement.class.php	2005-05-05 19:26:13 UTC (rev 1944)
+++ plog/branches/plog-1.0.1/class/summary/action/doreadagreement.class.php	2005-05-05 19:39:50 UTC (rev 1945)
@@ -1,22 +1,20 @@
 <?php
 
-	include_once( PLOG_CLASS_PATH."class/summary/action/summaryaction.class.php" );
+	include_once( PLOG_CLASS_PATH."class/summary/action/registeraction.class.php" );
 	include_once( PLOG_CLASS_PATH."class/config/config.class.php" );
 
 	/**
 	 * shows a form so that users can register
 	 */
-    class doReadAgreement extends SummaryAction 
+    class doReadAgreement extends RegisterAction 
 	{
         function perform()
         {
+    		if( $this->_config->getValue( "summary_show_agreement" ))
+    		    $this->_view = new SummaryView( "registerstep0" );
+	    	else
+		    	$this->_view = new SummaryView( "registerstep1" );
 
-		$config =& Config::getConfig();
-		if( $config->getValue( "summary_show_agreement" ))
-            		$this->_view = new SummaryView( "registerstep0" );
-		else
-			$this->_view = new SummaryView( "registerstep1" );
-
             $this->setCommonData();
         }
     }	 

Modified: plog/branches/plog-1.0.1/class/summary/action/dousercreation.class.php
===================================================================
--- plog/branches/plog-1.0.1/class/summary/action/dousercreation.class.php	2005-05-05 19:26:13 UTC (rev 1944)
+++ plog/branches/plog-1.0.1/class/summary/action/dousercreation.class.php	2005-05-05 19:39:50 UTC (rev 1945)
@@ -51,8 +51,7 @@
 
             // check if this email account has registered and quit if so, but only if the configuration
 		// says that we should only allow one blog per email account
-		$config =& Config::getConfig();
-		if( $config->getValue( "force_one_blog_per_email_account" )) {
+		if( $this->_config->getValue( "force_one_blog_per_email_account" )) {
             if( $users->emailExists($this->userEmail)) {
 				$this->_view = new SummaryView( "registerstep1" );
 				//$this->_form->hasRun( true );

Modified: plog/branches/plog-1.0.1/class/summary/action/registeraction.class.php
===================================================================
--- plog/branches/plog-1.0.1/class/summary/action/registeraction.class.php	2005-05-05 19:26:13 UTC (rev 1944)
+++ plog/branches/plog-1.0.1/class/summary/action/registeraction.class.php	2005-05-05 19:39:50 UTC (rev 1945)
@@ -1,8 +1,7 @@
 <?php
 
-include_once( PLOG_CLASS_PATH."class/action/action.class.php" );
+include_once( PLOG_CLASS_PATH."class/summary/action/summaryaction.class.php" );
 include_once( PLOG_CLASS_PATH."class/data/textfilter.class.php" );
-include_once( PLOG_CLASS_PATH."class/summary/view/summaryview.class.php" );
 include_once( PLOG_CLASS_PATH."class/summary/view/summarycachedview.class.php" );
 
 /**
@@ -10,7 +9,7 @@
  * @package summary
  * @subpackage action
  */
-class RegisterAction extends Action
+class RegisterAction extends SummaryAction
 {
     //{{{ member variables
     var $userName;
@@ -25,17 +24,15 @@
     //{{{function RegisterAction( $actionInfo, $request )
     function RegisterAction( $actionInfo, $request )
     {
-        $this->Action( $actionInfo, $request );
-        $this->_config   = &Config::getConfig();
-        $this->_locale   = &Locales::getLocale( $this->_config->getValue("default_locale" ));			
+        $this->SummaryAction( $actionInfo, $request );
 		
-			$tf = new Textfilter();
-            $this->blogName = $tf->filterAllHTML( $this->_request->getValue( "blogName" ));
-            $this->blogLocale = $this->_request->getValue( "blogLocale" );
-            $this->userName = $tf->filterAllHTML($this->_request->getValue( "userName" ));
-            $this->userPassword = $tf->filterAllHTML($this->_request->getValue( "userPassword" ));
-            $this->userEmail = $tf->filterAllHTML($this->_request->getValue( "userEmail" ));
-			$this->userFullName = $tf->filterAllHTML($this->_request->getValue( "userFullName" ));
+		$tf = new Textfilter();
+        $this->blogName = $tf->filterAllHTML( $this->_request->getValue( "blogName" ));
+        $this->blogLocale = $this->_request->getValue( "blogLocale" );
+        $this->userName = $tf->filterAllHTML($this->_request->getValue( "userName" ));
+        $this->userPassword = $tf->filterAllHTML($this->_request->getValue( "userPassword" ));
+        $this->userEmail = $tf->filterAllHTML($this->_request->getValue( "userEmail" ));
+		$this->userFullName = $tf->filterAllHTML($this->_request->getValue( "userFullName" ));
 		
     }
     //}}}

Modified: plog/branches/plog-1.0.1/class/summary/action/summaryaction.class.php
===================================================================
--- plog/branches/plog-1.0.1/class/summary/action/summaryaction.class.php	2005-05-05 19:26:13 UTC (rev 1944)
+++ plog/branches/plog-1.0.1/class/summary/action/summaryaction.class.php	2005-05-05 19:39:50 UTC (rev 1945)
@@ -3,6 +3,7 @@
 	include_once( PLOG_CLASS_PATH."class/action/action.class.php" );
 	include_once( PLOG_CLASS_PATH."class/summary/view/summaryview.class.php" );
 	include_once( PLOG_CLASS_PATH."class/summary/view/summarycachedview.class.php" );	
+	include_once( PLOG_CLASS_PATH."class/net/http/httpvars.class.php" );
 
 	/**
 	 * Base action that all summary actions should extend
@@ -12,9 +13,63 @@
 		function SummaryAction( $actionInfo, $request )
 		{
 			$this->Action( $actionInfo, $request );
-			$this->_config   = Config::getConfig();
-            $this->_locale   = Locales::getLocale( $this->_config->getValue("default_locale" ));			
+			$this->_config   =& Config::getConfig();
+            $this->_locale   =& $this->_loadLocale();
 		}
+		
+		/**
+		 * Loads the current locale. It works so that it tries to fetch the parameter "lang" from the
+		 * request. If it's not available, then it will try to look for it in the session. If it is not
+		 * there either, it will use whatever the value of "default_locale" is and load the
+		 * most suitable Locale object
+		 *
+		 * @private
+		 * @return Returns a reference to a Locale object
+		 */
+		function &_loadLocale()
+		{
+		    $requestLocale = $this->_request->getValue( "lang" );
+		    
+		    $localeCode = "";
+		    
+		    // check if there's something in the request... 
+		    // if not, check the session and as a valid resort, use the default one
+		    if( $requestLocale ) {
+		        // check if it's a valid one
+		        if( Locales::isValidLocale( $requestLocale )) {
+		            $localeCode = $requestLocale;
+		        }
+		    }
+		    else {
+		        $sessionLocale = SessionManager::getSessionValue( "summaryLang" );
+		        if( $sessionLocale ) {		            
+		            $localeCode = $sessionLocale;
+		        }
+		    }
+		    
+		    // check if the locale code is correct
+		    if( !Locales::isValidLocale( $localeCode )) {
+		        $localeCode = $this->_config->getValue( "default_locale" );
+		    }
+		    
+		    // now put whatever locale value back to the session
+		    SessionManager::setSessionValue( "summaryLang", $localeCode );
+		    
+		    // load the correct locale
+		    $locale =& Locales::getLocale( $localeCode );		    
+		    
+		    return( $locale );
+		}
+		
+		/**
+		 * Common things that should be performed by all SummaryAction classes
+		 */
+		function setCommonData( $copyFormValues = false )
+		{
+		    parent::setCommonData( $copyFormValues );
+		    
+		    $this->_view->setValue( "locale", $this->_locale );
+		}
 	}
 	
 ?>
\ No newline at end of file

Modified: plog/branches/plog-1.0.1/class/summary/action/summarydefaultaction.class.php
===================================================================
--- plog/branches/plog-1.0.1/class/summary/action/summarydefaultaction.class.php	2005-05-05 19:26:13 UTC (rev 1944)
+++ plog/branches/plog-1.0.1/class/summary/action/summarydefaultaction.class.php	2005-05-05 19:39:50 UTC (rev 1945)
@@ -57,7 +57,6 @@
 			$this->_view->setValue( "commentedPosts", $commentedPosts );
 			$this->_view->setValue( "readestBlogs", $readestBlogs );
 			$this->_view->setValue( "blogs", $siteBlogs );
-            $this->_view->setValue( "locale", $this->_locale );
 		
 			//
 			// :KLUDGE:
@@ -66,6 +65,8 @@
 			$randomBlog = array_pop($siteBlogs);
 			$url = $randomBlog->getBlogRequestGenerator();
 			$this->_view->setValue( "url", $url );
+			
+			$this->setCommonData();
 
             return true;
         }

Modified: plog/branches/plog-1.0.1/class/summary/action/summaryrssaction.class.php
===================================================================
--- plog/branches/plog-1.0.1/class/summary/action/summaryrssaction.class.php	2005-05-05 19:26:13 UTC (rev 1944)
+++ plog/branches/plog-1.0.1/class/summary/action/summaryrssaction.class.php	2005-05-05 19:39:50 UTC (rev 1945)
@@ -76,8 +76,9 @@
             }
 
 			$this->_view->setValue( "posts", $posts );
-            $this->_view->setValue( "locale", $this->_locale );
 			$this->_view->setValue( "summary", true );
+			
+			$this->setCommonData();			
 
             return true;
         }

Modified: plog/branches/plog-1.0.1/class/summary/action/summarysearchaction.class.php
===================================================================
--- plog/branches/plog-1.0.1/class/summary/action/summarysearchaction.class.php	2005-05-05 19:26:13 UTC (rev 1944)
+++ plog/branches/plog-1.0.1/class/summary/action/summarysearchaction.class.php	2005-05-05 19:39:50 UTC (rev 1945)
@@ -48,6 +48,8 @@
 			$this->_view = new SummaryView( "searchresults" );
 			$this->_view->setValue( "searchresults", $results );
 			
+			$this->setCommonData();			
+			
 			return true;
         }
      }

Modified: plog/branches/plog-1.0.1/class/summary/action/summarysendresetemail.class.php
===================================================================
--- plog/branches/plog-1.0.1/class/summary/action/summarysendresetemail.class.php	2005-05-05 19:26:13 UTC (rev 1944)
+++ plog/branches/plog-1.0.1/class/summary/action/summarysendresetemail.class.php	2005-05-05 19:39:50 UTC (rev 1945)
@@ -65,6 +65,8 @@
 			SummaryTools::sendResetEmail( $userInfo, $resetUrl );
 			
 			$this->_view = new SummaryMessageView( $this->_locale->tr( "password_reset_message_sent_ok" ));
+			
+			$this->setCommonData();			
 	
 			return true;
 		}

Modified: plog/branches/plog-1.0.1/class/summary/action/userprofileaction.class.php
===================================================================
--- plog/branches/plog-1.0.1/class/summary/action/userprofileaction.class.php	2005-05-05 19:26:13 UTC (rev 1944)
+++ plog/branches/plog-1.0.1/class/summary/action/userprofileaction.class.php	2005-05-05 19:39:50 UTC (rev 1945)
@@ -46,7 +46,8 @@
 			}
 			
 			$this->_view->setValue( "user", $userInfo );
-			$this->_view->setValue( "locale", $this->_locale );
+
+			$this->setCommonData();
 		
             return true;
         }

Modified: plog/branches/plog-1.0.1/class/summary/view/summarybloglistview.class.php
===================================================================
--- plog/branches/plog-1.0.1/class/summary/view/summarybloglistview.class.php	2005-05-05 19:26:13 UTC (rev 1944)
+++ plog/branches/plog-1.0.1/class/summary/view/summarybloglistview.class.php	2005-05-05 19:39:50 UTC (rev 1945)
@@ -35,11 +35,6 @@
 				return true;
 			}
 
-			// set the view character set based on the default locale
-            $config =& Config::getConfig();
-            $locale =& Locales::getLocale( $config->getValue( "default_locale" ));			
-			$this->setCharset( $locale->getCharset());			
-			
 			// get the data itself
 			$blogs = new Blogs();
             $siteBlogs = $blogs->getAllBlogs( BLOG_STATUS_ACTIVE, $this->_page, $this->_numBlogsPerPage );

Modified: plog/branches/plog-1.0.1/class/summary/view/summarycachedview.class.php
===================================================================
--- plog/branches/plog-1.0.1/class/summary/view/summarycachedview.class.php	2005-05-05 19:26:13 UTC (rev 1944)
+++ plog/branches/plog-1.0.1/class/summary/view/summarycachedview.class.php	2005-05-05 19:39:50 UTC (rev 1945)
@@ -61,12 +61,29 @@
 			return $isCached;
 		}
 		
+		/**
+		 * @private
+		 */
+		function _getLocale()
+		{
+		    // load the Locale object from the view context or initialize it now
+		    if( $this->_params->keyExists( "locale" )) {
+		        print("getting locale from context<br/>");
+		        $this->_locale = $this->_params->getValue( "locale" );
+		    }
+		    else {
+		        print("loading default locale<br/>");		        
+		        $config =& Config::getConfig();
+		        $this->_locale =& Locales::getLocale( $config->getValue("default_locale" ));		        
+		    }
+		    
+		    print("locale code = ".$this->_locale->getLocaleCode());
+		}
+		
 		function sendUncachedOutput()
 		{
-		    $config =& Config::getConfig();
-			$this->_locale =& Locales::getLocale( $config->getValue("default_locale" ));
 			$this->_params->setValue( "version", new Version());
-			$this->_params->setValue( "locale", $this->_locale );
+			$this->_params->setValue( "locale", $this->_locale);
 			$this->_template->assign( $this->_params->getAsArray());
 			print $this->_template->fetch( $this->_viewId );		
 		}
@@ -75,13 +92,13 @@
         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());
+			$this->_getLocale();
+			$this->setCharset( $this->_locale->getCharset());
 			
 			$sendOutput = true;
 			
 			// check if support for conditional HTTP requests is enabled
+			$config =& Config::getConfig();
 			if( $config->getValue( "template_http_cache_enabled" )) {
 				// some debug information
 				$timestamp = $this->_template->getCreationTimestamp();

Modified: plog/branches/plog-1.0.1/class/summary/view/summaryview.class.php
===================================================================
--- plog/branches/plog-1.0.1/class/summary/view/summaryview.class.php	2005-05-05 19:26:13 UTC (rev 1944)
+++ plog/branches/plog-1.0.1/class/summary/view/summaryview.class.php	2005-05-05 19:39:50 UTC (rev 1945)
@@ -13,23 +13,36 @@
         function SummaryView( $templateName )
         {
             $this->View();
-            $this->_templateName = $templateName;
+            $this->_templateName = $templateName;            
         }
+        
+        /**
+         * @private
+         */
+        function _getLocale()
+        {
+            // load the Locale object from the view context or initialize it now            
+            if( $this->_params->keyExists( "locale" )) {
+                $this->_locale = $this->_params->getValue( "locale" );
+            }
+            else {	        
+                $config =& Config::getConfig();
+                $this->_locale =& Locales::getLocale( $config->getValue("default_locale" ));		        
+            }
+        }        
 
         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());
+			// load the locale
+			$this->_getLocale();
+			// set the view character set based on the locale			
+			$this->setCharset( $this->_locale->getCharset());
 
 			parent::render();
 		
             $templateService = new TemplateService();
             $template = $templateService->customTemplate( $this->_templateName, "summary" );
 
-            $config =& Config::getConfig();
-            $this->_locale =& Locales::getLocale( $config->getValue("default_locale" ));
             $this->_params->setValue( "version", new Version());
             $this->_params->setValue( "locale", $this->_locale );
             $template->assign( $this->_params->getAsArray());

Modified: plog/branches/plog-1.0.1/summary.php
===================================================================
--- plog/branches/plog-1.0.1/summary.php	2005-05-05 19:26:13 UTC (rev 1944)
+++ plog/branches/plog-1.0.1/summary.php	2005-05-05 19:39:50 UTC (rev 1945)
@@ -8,12 +8,13 @@
      * Script that shows a summary page with the 'n' most recent additions
      * of all blogs in one page. Therefore, it is called a "Summary" :)
      */
-
+     
     include_once( PLOG_CLASS_PATH."class/controller/controller.class.php" );
     include_once( PLOG_CLASS_PATH."class/net/http/httpvars.class.php" );
     include_once( PLOG_CLASS_PATH."class/misc/version.class.php" );
     include_once( PLOG_CLASS_PATH."class/data/validator/usernamevalidator.class.php" );
 	include_once( PLOG_CLASS_PATH."class/net/http/subdomains.class.php" );
+	include_once( PLOG_CLASS_PATH."class/net/http/session/sessionmanager.class.php" );	
 
 	define( "SUMMARY_DEFAULT_BLOGS_PER_PAGE", 25 );
 	
@@ -38,6 +39,9 @@
 			$this->setActionFolderPath( PLOG_CLASS_PATH."class/summary/action/" );
 		}
 	}
+	
+	// start the session handling stuff
+	SessionManager::init();	
 
     //// map to associate actions with classes ////
     $_actionMap["Default"]       = "SummaryDefaultAction";




More information about the pLog-svn mailing list