[pLog-svn] r4651 - in plog/branches/lifetype-1.2: class/action class/view templates/standard

oscar at devel.lifetype.net oscar at devel.lifetype.net
Thu Feb 1 09:06:13 EST 2007


Author: oscar
Date: 2007-02-01 09:06:13 -0500 (Thu, 01 Feb 2007)
New Revision: 4651

Modified:
   plog/branches/lifetype-1.2/class/action/viewalbumaction.class.php
   plog/branches/lifetype-1.2/class/action/viewarticleaction.class.php
   plog/branches/lifetype-1.2/class/action/viewresourceaction.class.php
   plog/branches/lifetype-1.2/class/view/blogview.class.php
   plog/branches/lifetype-1.2/class/view/defaultview.class.php
   plog/branches/lifetype-1.2/class/view/errorview.class.php
   plog/branches/lifetype-1.2/class/view/viewarticleview.class.php
   plog/branches/lifetype-1.2/templates/standard/albums.template
   plog/branches/lifetype-1.2/templates/standard/archives.template
   plog/branches/lifetype-1.2/templates/standard/header.template
   plog/branches/lifetype-1.2/templates/standard/links.template
Log:
implemented support for automatically generated page titles via the $pageTitle template variable. Currently titles have to be implemented on a per template basis while with this change, the core code (the View classes) can take care of generating a sensible title or whatever content they are tasked to display. Format of these titles is hardcoded in the code but they should be good enough for most people. If this is still not good enough for some users, they can still use the old approach and provide their own content fo the $pageTitle variable when the template is renderer.

Support in the code is provided via BlogView::setPageTitle() and BlogView::getPageTitle(). Those view classes extending BlogView can simply reimplement getPageTitle() while action classes that use a generic view like BlogTemplatedView can call setPageTitle() and provide their own title without the need to write their own specific view class. 

Thanks to user Rechosen and his article http://www.linuxtutorialblog.com/post/lifetype-search-engine-optimization-seo-tutorial for inspiration and ideas.


Modified: plog/branches/lifetype-1.2/class/action/viewalbumaction.class.php
===================================================================
--- plog/branches/lifetype-1.2/class/action/viewalbumaction.class.php	2007-02-01 12:44:16 UTC (rev 4650)
+++ plog/branches/lifetype-1.2/class/action/viewalbumaction.class.php	2007-02-01 14:06:13 UTC (rev 4651)
@@ -85,6 +85,7 @@
 				else {
 					$this->notifyEvent( EVENT_ALBUMS_LOADED, Array( "albums" => &$blogAlbums ));
 					$this->_view->setValue( "albums", $blogAlbums );
+					$this->_view->setPageTitle( $this->_blogInfo->getBlog()." | ".$this->_locale->tr("albums"));
 				}
             }
             else {
@@ -107,6 +108,8 @@
 				$this->notifyEvent( EVENT_ALBUM_LOADED, Array( "album" => &$blogAlbum ));				
                 // put the album to the template
                 $this->_view->setValue( "album", $album );
+				// and set a page title
+				$this->_view->setPageTitle( $this->_blogInfo->getBlog()." | ".$album->getName());
 				
 				// load the resources and build the pager
 				$resources = $galleryResources->getUserResources( $this->_blogInfo->getId(),

Modified: plog/branches/lifetype-1.2/class/action/viewarticleaction.class.php
===================================================================
--- plog/branches/lifetype-1.2/class/action/viewarticleaction.class.php	2007-02-01 12:44:16 UTC (rev 4650)
+++ plog/branches/lifetype-1.2/class/action/viewarticleaction.class.php	2007-02-01 14:06:13 UTC (rev 4651)
@@ -26,6 +26,7 @@
 		var $_userName;
 		var $_categoryId;
 		var $_categoryName;
+		var $_article;
 
 		function ViewArticleAction( $actionInfo, $request )
         {
@@ -130,7 +131,7 @@
 			
 			return( true );
 		}
-
+		
         function perform()
         {		
 	        lt_include( PLOG_CLASS_PATH."class/view/viewarticleview.class.php" );
@@ -227,6 +228,8 @@
                 $this->_setErrorView();
                 return false;
             }
+
+			$this->_article = $article;
 			
             // check if we have to update how many times an article has been read
             if( $this->_config->getValue( "update_article_reads" )) {

Modified: plog/branches/lifetype-1.2/class/action/viewresourceaction.class.php
===================================================================
--- plog/branches/lifetype-1.2/class/action/viewresourceaction.class.php	2007-02-01 12:44:16 UTC (rev 4650)
+++ plog/branches/lifetype-1.2/class/action/viewresourceaction.class.php	2007-02-01 14:06:13 UTC (rev 4651)
@@ -125,6 +125,10 @@
             $this->_view->setValue( "resource", $resource );
 			$this->_view->setValue( "prevresource", $prevResource );
 			$this->_view->setValue( "nextresource", $nextResource );
+			
+			// set the page title for the view
+			$this->_view->setPageTitle( $this->_blogInfo->getBlog()." | ".$resource->getFileName());
+			
             $this->setCommonData();
 
             // and return everything normal

Modified: plog/branches/lifetype-1.2/class/view/blogview.class.php
===================================================================
--- plog/branches/lifetype-1.2/class/view/blogview.class.php	2007-02-01 12:44:16 UTC (rev 4650)
+++ plog/branches/lifetype-1.2/class/view/blogview.class.php	2007-02-01 14:06:13 UTC (rev 4651)
@@ -19,6 +19,7 @@
 	{
 
         var $_pm;
+		var $_pageTitle;
 
 		/**
 		 * @see SmartyView
@@ -34,6 +35,9 @@
 			// set the character set in the request based on the blog locale
 			$locale = $this->_blogInfo->getLocale();
 			$this->setCharset( $locale->getCharset());			
+			
+			// set the initial page title
+			$this->_pageTitle = $blogInfo->getBlog();
         }
 
         /**
@@ -209,6 +213,29 @@
 		}		
 		
 		/**
+		 * This method must be implemented by child classes and it is meant
+		 * to return the title for the current page, to make it easier for template
+		 * designers to automatically provide meaningful page titles
+		 *
+		 * @return A string containing the appropriate page title
+		 */
+		function getPageTitle()
+		{
+			return( $this->_pageTitle );
+		}
+		
+		/**
+		 * This method sets the page title and can be called by action classes
+		 * instantiating this view to set a meaningful page title.
+		 *
+		 * @param title A string containing the appropriate page title
+		 */		
+		function setPageTitle( $title )
+		{
+			$this->_pageTitle = $title;
+		}
+		
+		/**
 		 * Sets some  in this case, we leave it all up to the child classes to reimplement
 		 * this and by default call View::render()
 		 *
@@ -236,6 +263,9 @@
 				$this->setValue( 'version', Version::getVersion());
 				$this->setValue( 'now', new Timestamp());
 				
+				// page title
+				$this->setValue( "pageTitle", $this->getPageTitle());
+				
 				// also, let's not forget about the plugins...
 				// put the plugins in the context
 				$plugins = $this->_pm->getPlugins();

Modified: plog/branches/lifetype-1.2/class/view/defaultview.class.php
===================================================================
--- plog/branches/lifetype-1.2/class/view/defaultview.class.php	2007-02-01 12:44:16 UTC (rev 4650)
+++ plog/branches/lifetype-1.2/class/view/defaultview.class.php	2007-02-01 14:06:13 UTC (rev 4651)
@@ -53,6 +53,26 @@
             $this->_params->setValue( 'posts', $modifPosts );
         }
 
+		/** 
+		 * Provides a meaningful page title. The format here will depend on whether we're browsing the main
+		 * blog page, or a page from the archives or a category page
+		 *
+		 * @return a page title
+		 */
+		function getPageTitle()
+		{
+			$title = $this->_blogInfo->getBlog(); 
+			if(($date = $this->getValue( "date" ))) {
+				$locale = $this->_blogInfo->getLocale();
+				$title .= " | ".$locale->formatDate( $date, "%B %Y" );
+			}
+			elseif(( $category = $this->getValue( "category" ))) {
+				$title .= " | ".$category->getName();
+			}
+			
+			return( $title );
+		}		
+
     	/**
 		 * This view shows a list of the posts for the blog.
          *

Modified: plog/branches/lifetype-1.2/class/view/errorview.class.php
===================================================================
--- plog/branches/lifetype-1.2/class/view/errorview.class.php	2007-02-01 12:44:16 UTC (rev 4650)
+++ plog/branches/lifetype-1.2/class/view/errorview.class.php	2007-02-01 14:06:13 UTC (rev 4651)
@@ -35,6 +35,15 @@
 			
 			return( parent::setErrorMessage( $message ));
 		}
+		
+		/**
+		 * Provides the page title
+		 */
+		function getPageTitle()
+		{
+			$locale = $this->_blogInfo->getLocale();
+			return( $this->_blogInfo->getBlog()." | ".$locale->tr("error"));
+		}		
 
         /** 
          * renders the error message

Modified: plog/branches/lifetype-1.2/class/view/viewarticleview.class.php
===================================================================
--- plog/branches/lifetype-1.2/class/view/viewarticleview.class.php	2007-02-01 12:44:16 UTC (rev 4650)
+++ plog/branches/lifetype-1.2/class/view/viewarticleview.class.php	2007-02-01 14:06:13 UTC (rev 4651)
@@ -36,6 +36,17 @@
 			return true;
 		}
 		
+		/** 
+		 * Provides a meaningful page title. The pre-defined format is "blog name | post title"
+		 *
+		 * @return a page title
+		 */
+		function getPageTitle()
+		{
+			$article = $this->getValue( "post" );
+			return( $this->_blogInfo->getBlog()." | ".$article->getTopic());
+		}		
+		
 		/**
 		 * renders this view
 		 *

Modified: plog/branches/lifetype-1.2/templates/standard/albums.template
===================================================================
--- plog/branches/lifetype-1.2/templates/standard/albums.template	2007-02-01 12:44:16 UTC (rev 4650)
+++ plog/branches/lifetype-1.2/templates/standard/albums.template	2007-02-01 14:06:13 UTC (rev 4651)
@@ -1,4 +1,4 @@
-		{include file="$blogtemplate/header.template"} 
+{include file="$blogtemplate/header.template"} 
 
 <h2>{$locale->tr("albums")}</h2>
 
@@ -11,18 +11,17 @@
 		{assign var="counter" value=0}
   		{foreach from=$albums item=album}
 	<div class="album">
-	<a href="{$url->albumLink($album)}"><img src="{$url->getTemplateFile("imgs/folder.gif")}" alt="{$album->getName()}" /></a>
+	<a href="{$url->albumLink($album)}"><img src="{$url->getTemplateFile("imgs/folder.gif")}" alt="{$album->getName()}" /></a>
   	<p>{$album->getName()} ({$album->getNumResources()})</p>
   		{assign var="counter" value="`$counter+1`"}
 		{if $counter%3 == 0}
 		{/if}
 	</div>
 		{/foreach}
-
+
 	<div class="clearer">&nbsp;</div>
 
 </div>
 
 <!-- end of the albums -->
-		
-		{include file="$blogtemplate/footer.template"} 
+{include file="$blogtemplate/footer.template"} 
\ No newline at end of file

Modified: plog/branches/lifetype-1.2/templates/standard/archives.template
===================================================================
--- plog/branches/lifetype-1.2/templates/standard/archives.template	2007-02-01 12:44:16 UTC (rev 4650)
+++ plog/branches/lifetype-1.2/templates/standard/archives.template	2007-02-01 14:06:13 UTC (rev 4651)
@@ -1,4 +1,5 @@
-		{include file="$blogtemplate/header.template"} 
+{assign var=title value=$locale->tr("archives")}
+{include file="$blogtemplate/header.template" pageTitle="$pageTitle | $title"} 
 <h2>{$locale->tr("archives")}</h2>
 
 <div id="Archives">

Modified: plog/branches/lifetype-1.2/templates/standard/header.template
===================================================================
--- plog/branches/lifetype-1.2/templates/standard/header.template	2007-02-01 12:44:16 UTC (rev 4650)
+++ plog/branches/lifetype-1.2/templates/standard/header.template	2007-02-01 14:06:13 UTC (rev 4651)
@@ -4,7 +4,7 @@
  <meta http-equiv="content-type" content="text/html; charset={$locale->getCharset()}" />
  <meta name="generator" content="{$version}" />
  <meta http-equiv="Content-Language" content="{$locale->getLanguageId()}" />
- <title>{$blog->getBlog()}{$postPageTitle}</title>
+ <title>{$pageTitle|escape:"html"}</title>
  <link rel="stylesheet" type="text/css" title="Style" href="{$url->getTemplateFile("style.css")}" />
  <!--[if IE ]>
 <link rel="stylesheet" type="text/css" title="Style" href="{$url->getTemplateFile("style-ie.css")}" />

Modified: plog/branches/lifetype-1.2/templates/standard/links.template
===================================================================
--- plog/branches/lifetype-1.2/templates/standard/links.template	2007-02-01 12:44:16 UTC (rev 4650)
+++ plog/branches/lifetype-1.2/templates/standard/links.template	2007-02-01 14:06:13 UTC (rev 4651)
@@ -1,5 +1,5 @@
-		{include file="$blogtemplate/header.template"} 
-  
+{assign var=title value=$locale->tr("links")}
+{include file="$blogtemplate/header.template" pageTitle="$pageTitle | $title"} 
 <div id="Links">
 	<h2>{$locale->tr("my_links")}</h2>
   		{foreach from=$mylinkscategories item=linkcategory}
@@ -12,6 +12,6 @@
     		{/foreach}
   	</ul>
   		{/foreach}
-  	</div>
+  	</div>
   
 		{include file="$blogtemplate/footer.template"} 
\ No newline at end of file



More information about the pLog-svn mailing list