[pLog-svn] r1095 - in plog/trunk/class/view: . admin

oscar at devel.plogworld.net oscar at devel.plogworld.net
Tue Feb 15 18:18:56 GMT 2005


Author: oscar
Date: 2005-02-15 18:18:55 +0000 (Tue, 15 Feb 2005)
New Revision: 1095

Modified:
   plog/trunk/class/view/admin/admindashboardview.class.php
   plog/trunk/class/view/admin/admindefaultview.class.php
   plog/trunk/class/view/admin/adminsimpleerrorview.class.php
   plog/trunk/class/view/admin/adminsimplemessageview.class.php
   plog/trunk/class/view/admin/adminview.class.php
   plog/trunk/class/view/blogview.class.php
   plog/trunk/class/view/view.class.php
Log:
Solved issue 244 (http://bugs.plogworld.net/view.php?id=244) I have added a method called View::setCharset($charset) that should be used by child classes to set the right character set that will be sent in the headers, along the content type. If none is set, it defaults to iso-8859-1.

I have modified all the child classes that inherit from View and that have a reference to a BlogInfo object (BlogView and AdminView) so that they set the correct character set based on what the blog locale settings are. 

Other views that inherit from View directly (AdminSimple[Error|Message]View, AdminDefaultView, AdminDashboardView)  will set the character set based on the default locale setttings for the site.

Modified: plog/trunk/class/view/admin/admindashboardview.class.php
===================================================================
--- plog/trunk/class/view/admin/admindashboardview.class.php	2005-02-15 18:13:57 UTC (rev 1094)
+++ plog/trunk/class/view/admin/admindashboardview.class.php	2005-02-15 18:18:55 UTC (rev 1095)
@@ -83,14 +83,16 @@
          */
         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();
 		
         	// to find the template we need, we can use the TemplateService
             $ts = new TemplateService();
         	$template = $ts->AdminTemplate( "dashboard" );
-            // load the default locale
-            $config =& Config::getConfig();
-            $locale =& Locales::getLocale( $config->getValue( "default_locale" ));
             $this->setValue( "locale", $locale );
             // assign all the values
             $template->assign( $this->_params->getAsArray());

Modified: plog/trunk/class/view/admin/admindefaultview.class.php
===================================================================
--- plog/trunk/class/view/admin/admindefaultview.class.php	2005-02-15 18:13:57 UTC (rev 1094)
+++ plog/trunk/class/view/admin/admindefaultview.class.php	2005-02-15 18:18:55 UTC (rev 1095)
@@ -33,14 +33,16 @@
          */
         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();
 					
         	// to find the template we need, we can use the TemplateService
             $ts = new TemplateService();
         	$template = $ts->Template( DEFAULTADMIN_TEMPLATE, "admin" );
-            // load the default locale
-            $config =& Config::getConfig();
-            $locale =& Locales::getLocale( $config->getValue( "default_locale" ));
             $this->setValue( "locale", $locale );
             // assign all the values
             $template->assign( $this->_params->getAsArray());

Modified: plog/trunk/class/view/admin/adminsimpleerrorview.class.php
===================================================================
--- plog/trunk/class/view/admin/adminsimpleerrorview.class.php	2005-02-15 18:13:57 UTC (rev 1094)
+++ plog/trunk/class/view/admin/adminsimpleerrorview.class.php	2005-02-15 18:18:55 UTC (rev 1095)
@@ -13,7 +13,8 @@
     /**
      * The ErrorView class takes care of showing error messages
      */
-    class AdminSimpleErrorView extends View {
+    class AdminSimpleErrorView extends View 
+	{
 
 		function AdminSimpleErrorView()
         {
@@ -22,14 +23,16 @@
 
         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();		
 		
             // load the contents into the template context
             $ts = new TemplateService();
             $template = $ts->Template( ADMINSIMPLEERROR_TEMPLATE, "admin" );
-            // load the default locale
-            $config =& Config::getConfig();
-            $locale =& Locales::getLocale( $config->getValue( "default_locale" ));
             $this->setValue( "locale", $locale );
             // finally pass the values to the templates            
             $template->assign( $this->_params->getAsArray());

Modified: plog/trunk/class/view/admin/adminsimplemessageview.class.php
===================================================================
--- plog/trunk/class/view/admin/adminsimplemessageview.class.php	2005-02-15 18:13:57 UTC (rev 1094)
+++ plog/trunk/class/view/admin/adminsimplemessageview.class.php	2005-02-15 18:18:55 UTC (rev 1095)
@@ -14,7 +14,8 @@
      * The SimpleMessageView class shows messages, but the template does not
      * include the header or the footer.
      */
-    class AdminSimpleMessageView extends View {
+    class AdminSimpleMessageView extends View 
+	{
 
 		function AdminSimpleErrorView()
         {
@@ -22,16 +23,20 @@
         }
 
         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();
 		
             // load the contents into the template context
             $ts = new TemplateService();
             $template = $ts->Template( ADMINSIMPLEMESSAGE_TEMPLATE, "admin" );
-            // load the default locale
-            $config =& Config::getConfig();
-            $locale =& Locales::getLocale( $config->getValue( "default_locale" ));
             $this->setValue( "locale", $locale );
+
+			
             // and pass the values to the template
             $template->assign( $this->_params->getAsArray());
 			

Modified: plog/trunk/class/view/admin/adminview.class.php
===================================================================
--- plog/trunk/class/view/admin/adminview.class.php	2005-02-15 18:13:57 UTC (rev 1094)
+++ plog/trunk/class/view/admin/adminview.class.php	2005-02-15 18:18:55 UTC (rev 1095)
@@ -40,6 +40,10 @@
 			// initialize the plugin manager, so that we can throw events from views too!
 			$this->_pm =& PluginManager::getPluginManager();
 			$this->_pm->setBlogInfo( $this->_blogInfo );			
+			
+			// set the character set in the request based on the blog locale
+			$locale = $this->_blogInfo->getLocale();
+			$this->setCharset( $locale->getCharset());			
         }
         
         /**

Modified: plog/trunk/class/view/blogview.class.php
===================================================================
--- plog/trunk/class/view/blogview.class.php	2005-02-15 18:13:57 UTC (rev 1094)
+++ plog/trunk/class/view/blogview.class.php	2005-02-15 18:18:55 UTC (rev 1095)
@@ -16,7 +16,7 @@
     include_once( PLOG_CLASS_PATH.'class/misc/version.class.php' );
     include_once( PLOG_CLASS_PATH.'class/dao/mylinkscategories.class.php' ); 
     include_once( PLOG_CLASS_PATH.'class/plugin/pluginmanager.class.php' );
-    include_once( PLOG_CLASS_PATH."class/xml/rssparser/rssparser.class.php" );    
+    include_once( PLOG_CLASS_PATH.'class/xml/rssparser/rssparser.class.php' );    
 
     /**
      * Extends the original 'View' class to provide support for common operations, for example
@@ -40,6 +40,10 @@
 			
 			$this->_pm =& PluginManager::getPluginManager();
 			$this->_pm->setBlogInfo( $this->_blogInfo );
+			
+			// set the character set in the request based on the blog locale
+			$locale = $this->_blogInfo->getLocale();
+			$this->setCharset( $locale->getCharset());			
         }
 
         /**
@@ -177,7 +181,7 @@
 		 * @returns always true
 		 */
 		function render()
-		{
+		{		
 			if( !$this->isCached()) {
 				$this->log->debug("generating contents!");
 				// and then add our stuff to the view...

Modified: plog/trunk/class/view/view.class.php
===================================================================
--- plog/trunk/class/view/view.class.php	2005-02-15 18:13:57 UTC (rev 1094)
+++ plog/trunk/class/view/view.class.php	2005-02-15 18:18:55 UTC (rev 1095)
@@ -17,6 +17,11 @@
 	define( "TEXT_XML_CONTENT_TYPE", "text/xml" );
 	
 	/**
+	 * default content-type that is going to be sent in HTTP headers
+	 */
+	define( "DEFAULT_VIEW_CHARSET", "iso-8859-1" );
+	
+	/**
 	 * default page where we should start if the "page" parameter is not
 	 * available
 	 */
@@ -37,6 +42,7 @@
 		var $_params;
 		var $_contentType;
 		var $_headers;
+		var $_charset;
 
         /**
          * Constructor. By default, does nothing
@@ -46,7 +52,10 @@
 			$this->Object();
 
             $this->_params = new Properties();
-			$this->_contentType = null;
+			
+			// set a default content type and character set for responses
+			$this->_contentType = TEXT_HTML_CONTENT_TYPE;
+			$this->_charset = DEFAULT_VIEW_CHARSET;
 			$this->_headers = Array();
 			
 			// no form has caused any error when we initialize the view!
@@ -88,6 +97,16 @@
 		}
 		
 		/**
+		 * sets the character set
+		 *
+		 * @param charset the character set
+		 */
+		function setCharset( $charset )
+		{
+			$this->_charset = $charset;
+		}
+		
+		/**
 		 * Adds a new header string to the current list of headers
 		 *
 		 * @param headerString the new header string
@@ -122,8 +141,9 @@
 		 */
 		function sendContentType()
 		{
-			if( $this->_contentType != null ) 
-				header( "Content-Type: ".$this->_contentType );
+			// build up the header and send it
+			$header = "Content-Type: ".$this->_contentType.";charset=".$this->_charset;
+			header( $header );
 				
 			return true;
 		}




More information about the pLog-svn mailing list