[pLog-svn] r3952 - in plog/trunk: class/action class/dao class/net/http/session install locale templates/admin templates/standard

oscar at devel.lifetype.net oscar at devel.lifetype.net
Sun Sep 10 13:13:57 GMT 2006


Author: oscar
Date: 2006-09-10 13:13:56 +0000 (Sun, 10 Sep 2006)
New Revision: 3952

Modified:
   plog/trunk/class/action/addcommentaction.class.php
   plog/trunk/class/action/blogaction.class.php
   plog/trunk/class/action/viewarticleaction.class.php
   plog/trunk/class/dao/commentscommon.class.php
   plog/trunk/class/dao/usercomment.class.php
   plog/trunk/class/net/http/session/sessionmanager.class.php
   plog/trunk/install/dbschemas.properties.php
   plog/trunk/locale/locale_en_UK.php
   plog/trunk/templates/admin/editcomments.template
   plog/trunk/templates/standard/header.template
   plog/trunk/templates/standard/postandcomments.template
Log:
First feature for LifeType 1.2 implemented: support for user-authenticated comments. Now if a user is logged in and attempts to post a comment, its user will be recognized and user information will be stored in the comment. I've also modified the standard template to show the user picture for those comments that were posted by an authenticated user.

This has been implemented by passing an object called $authuser to the template, based on the contents of the session. If this object is available, the page is being browsed by an authenticated user. Then, the {dynamic} tag is used to get a dynamically generated comment form (which is all we need anyway), and it seems to work well. 

If interested in testing this, plase use the updatedbschema.php script to get your db schema updated to support this feature (there is one new field in the articles_comments table)


Modified: plog/trunk/class/action/addcommentaction.class.php
===================================================================
--- plog/trunk/class/action/addcommentaction.class.php	2006-09-09 12:46:27 UTC (rev 3951)
+++ plog/trunk/class/action/addcommentaction.class.php	2006-09-10 13:13:56 UTC (rev 3952)
@@ -34,7 +34,6 @@
         var $_commentTopic;
         var $_parentId;
 
-
     	/**
          * Constructor
          */
@@ -177,6 +176,12 @@
 			                            $this->_userEmail, 
 			                            $this->_userUrl,
 									    $clientIp );			
+									
+			// check if the comment was being posted by an authenticated user...
+			if( $this->_userInfo ) {
+				// ...and if so, save the user data in the UserComment object
+				$comment->setUser( $this->_userInfo );
+			}
 
 			// fire an event
 			$this->notifyEvent( EVENT_PRE_COMMENT_ADD, Array( "comment" => &$comment ));

Modified: plog/trunk/class/action/blogaction.class.php
===================================================================
--- plog/trunk/class/action/blogaction.class.php	2006-09-09 12:46:27 UTC (rev 3951)
+++ plog/trunk/class/action/blogaction.class.php	2006-09-10 13:13:56 UTC (rev 3952)
@@ -24,6 +24,7 @@
         var $_locale;
         var $_pm;
         var $_articles;
+		var $_userInfo;
 
         /**
          * Constructor. Additionally, it fetches the SessionInfo object from
@@ -62,6 +63,14 @@
             // save the blogid in the session
             $this->_session->setValue( 'blogId', $this->_blogInfo->getId());
 
+			// load userinfo data if any
+			$this->_userInfo = SessionManager::getUserInfoFromSession();
+			
+			if( $this->_userInfo )
+				print( "Logged in user: ".$this->_userInfo->getUsername());
+			else
+				print("NO LOGGED IN USER!" );
+
             $this->checkDateParameter();
 			
             // initialize the plugin manager
@@ -143,6 +152,7 @@
         {
             $this->_view->setValue( "Year", $this->_session->getValue( 'Year'));
             $this->_view->setValue( "Month", $this->_session->getValue( 'Month' ));
+			$this->_view->setValue( "authuser", $this->_userInfo );
             
             parent::setCommonData( $copyFormValues );
         }
@@ -343,7 +353,6 @@
             
             return( $result );
         }		
-
         
 	    /**
 	     * @private

Modified: plog/trunk/class/action/viewarticleaction.class.php
===================================================================
--- plog/trunk/class/action/viewarticleaction.class.php	2006-09-09 12:46:27 UTC (rev 3951)
+++ plog/trunk/class/action/viewarticleaction.class.php	2006-09-10 13:13:56 UTC (rev 3952)
@@ -154,6 +154,7 @@
                     }
 				}
 				
+				$this->setCommonData();
 				return true;
 			}			
 			

Modified: plog/trunk/class/dao/commentscommon.class.php
===================================================================
--- plog/trunk/class/dao/commentscommon.class.php	2006-09-09 12:46:27 UTC (rev 3951)
+++ plog/trunk/class/dao/commentscommon.class.php	2006-09-10 13:13:56 UTC (rev 3952)
@@ -118,10 +118,10 @@
 			                            $order,
 										"",
 			                            $page,
-			                            $itemsPerPage );			                           
-			                            
+			                            $itemsPerPage );
+						                            
 			$result = Array();
-		
+			
 			if( $comments ) {
 				// load the post to get the blog in order to get the time difference
 				$articles = new Articles();
@@ -539,6 +539,7 @@
 			$comment->setNormalizedText( $row['normalized_text'] );
 			$comment->setNormalizedTopic( $row['normalized_topic'] );
 			$comment->setType( $row['type'] );
+			$comment->setUserId( $row['user_id'] );
 
             return $comment;
 		}

Modified: plog/trunk/class/dao/usercomment.class.php
===================================================================
--- plog/trunk/class/dao/usercomment.class.php	2006-09-09 12:46:27 UTC (rev 3951)
+++ plog/trunk/class/dao/usercomment.class.php	2006-09-10 13:13:56 UTC (rev 3952)
@@ -33,6 +33,8 @@
 		var $_normalizedText;
 		var $_normalizedTopic;
 		var $_article;
+		var $_userId;
+		var $_user;
 
         /**
          * Creates a new user comment.
@@ -92,7 +94,8 @@
 			   "spam_rate" => "getSpamRate",
 			   "type" => "getType",
 			   "normalized_text" => "getNormalizedText",
-			   "normalized_topic" => "getNormalizedTopic"
+			   "normalized_topic" => "getNormalizedTopic",
+			   "user_id" => "getUserId"
 			);
 		}
 
@@ -535,5 +538,77 @@
 			
 			return( $this->_normalizedTopic );
 		}
+		
+		/**
+		 * Returns true if this comment was posted by an authenticated user
+		 * 
+		 * @return True if poster was authenticated or false otherwise
+		 */
+		function IsPosterAuthenticated()
+		{
+			return( $this->getUser() != false );
+		}
+		
+		/**
+		 * Returns the UserInfo object of the user who posted this comment or false if the comment
+		 * wasn't posted by an authenticated user or if the user does not exist anymore
+		 *
+		 * @return An UserInfo object or false if the user doesn't exist anymore or poster was not
+		 * authenticated when posting the comment 
+		 */
+		function getUser()
+		{
+			if( $this->_userId != 0 ) {
+				include_once( PLOG_CLASS_PATH."class/dao/users.class.php" );
+				$users = new Users();
+				$this->_user = $users->getUserInfoFromId( $this->_userId );
+			}
+			
+			return( $this->_user );
+		}
+		
+		/** 
+		 * Returns the id of the user who posted this comment, or '0' if the comment was
+		 * posted by a non-authenticated user
+		 *
+		 * @return Id of the user who posted this comment, '0' if the comment was posted
+		 * by a non-authenticated user
+		 */
+		function getUserId()
+		{
+			return( $this->_userId );
+		}
+		
+		/**
+		 * Sets the user id of the user who posted this comment
+		 *
+		 * @param id The user id of the poster, or 0 if the comment was posted by 
+		 * a non-authenticated user
+		 */
+		function setUserId( $id )
+		{
+			$this->_userId = $id;
+		}
+		
+		/**
+		 * Sets the UserInfo object containing information about the user who posted this
+		 * comment.
+		 *
+		 * @param userInfo A UserInfo object
+		 */
+		function setUser( $userInfo )
+		{
+			$this->_user = $userInfo;
+			$this->_userId = $userInfo->getId();
+		}
+		
+		/**
+		 * @private
+		 */
+		function __sleep()
+		{
+			$this->_userInfo = null;
+			return( parent::__sleep());			
+		}
 	}
 ?>
\ No newline at end of file

Modified: plog/trunk/class/net/http/session/sessionmanager.class.php
===================================================================
--- plog/trunk/class/net/http/session/sessionmanager.class.php	2006-09-09 12:46:27 UTC (rev 3951)
+++ plog/trunk/class/net/http/session/sessionmanager.class.php	2006-09-10 13:13:56 UTC (rev 3952)
@@ -202,5 +202,21 @@
 		    
 		    return true;
 		}
+
+		/**
+		 * Retrieve the UserInfo object from the session, if any
+		 *
+		 * @return A UserInfo object if found, or false otherwise
+		 */
+		function getUserInfoFromSession()
+		{
+	        $session = HttpVars::getSession();
+	        $sessionInfo = $session["SessionInfo"];
+	        $userInfo = $sessionInfo->getValue("userInfo");
+			if( !is_object( $userInfo ))
+				return false;
+			
+			return( $userInfo );
+		}
 	}
 ?>
\ No newline at end of file

Modified: plog/trunk/install/dbschemas.properties.php
===================================================================
--- plog/trunk/install/dbschemas.properties.php	2006-09-09 12:46:27 UTC (rev 3951)
+++ plog/trunk/install/dbschemas.properties.php	2006-09-10 13:13:56 UTC (rev 3952)
@@ -52,6 +52,7 @@
   topic TEXT NOTNULL,
   text X,
   date T(14) NOTNULL,
+  user_id I(10) DEFAULT '0',
   user_email C(255) DEFAULT '',
   user_url C(255) DEFAULT '',
   user_name C(255) NOTNULL DEFAULT Anonymous,
@@ -63,7 +64,7 @@
   properties TEXT NOTNULL DEFAULT '',
   normalized_text TEXT NOTNULL DEFAULT '',
   normalized_topic TEXT NOTNULL DEFAULT '',
-  type I(3) NOTNULL DEFAULT '1',  
+  type I(3) NOTNULL DEFAULT '1', 
   INDEX parent_id (parent_id),
   INDEX article_id_blog_id(article_id,blog_id),
   INDEX article_id_type(article_id,type),  
@@ -165,6 +166,7 @@
   status I(4) NOTNULL DEFAULT 1,
   resource_picture_id I(10) NOTNULL DEFAULT 0,
   site_admin I(10) NOTNULL DEFAULT '0',
+  last_login T(14),
   UNIQUE user (user)
 ";
 $Tables["users"]["options"] = "TYPE=MyISAM";

Modified: plog/trunk/locale/locale_en_UK.php
===================================================================
--- plog/trunk/locale/locale_en_UK.php	2006-09-09 12:46:27 UTC (rev 3951)
+++ plog/trunk/locale/locale_en_UK.php	2006-09-10 13:13:56 UTC (rev 3952)
@@ -1077,4 +1077,10 @@
 $messages['global_article_category_help'] = 'Site wide category for this post';
 
 $messages['password_reset_subject'] = 'LifeType Password Request';
+
+//
+// new strings for LifeType 1.2
+//
+$messages['auth'] = 'Auth';
+$messages['authenticated'] = 'Authenticated';
 ?>
\ No newline at end of file

Modified: plog/trunk/templates/admin/editcomments.template
===================================================================
--- plog/trunk/templates/admin/editcomments.template	2006-09-09 12:46:27 UTC (rev 3951)
+++ plog/trunk/templates/admin/editcomments.template	2006-09-10 13:13:56 UTC (rev 3952)
@@ -52,13 +52,14 @@
                 <thead>
                     <tr>					
                         <th style="width:10px;"><input class="checkbox" type="checkbox" name="all" id="all" value="1" onclick="toggleAllChecks('postCommentsList');" /></th>
-                        <th style="width:85px;">{$locale->tr("topic")}</th>						
+                        <th style="width:75px;">{$locale->tr("topic")}</th>						
                         <th style="width:360px;">{$locale->tr("text")}</th>
-                        <th style="width:70px;">{$locale->tr("author")}</th>
+                        <th style="width:60px;">{$locale->tr("author")}</th>
 						<th style="width:60px;">{$locale->tr("date")}</th>
                         <th style="width:60px;">{$locale->tr("status")}</th>
+						<th style="width:60px;">{$locale->tr("auth")}</th>
                         <th style="width:45px;">IP</th>
-                        <th style="width:95px;">{$locale->tr("actions")}</th>
+                        <th style="width:55px;">{$locale->tr("actions")}</th>
                     </tr>
                 </thead>
                 <tbody>
@@ -87,6 +88,9 @@
                            {if $comment->getStatus() == $status}{$locale->tr($name)}{/if}
                           {/foreach}
                         </td>
+						<td style="text-align: center;">
+							{if $comment->isPosterAuthenticated()}{$locale->tr("yes")}{else}{$locale->tr("no")}{/if}
+						</td>
                         <td style="text-align: center;">
 						  {$comment->getClientIp()}
                         </td>						

Modified: plog/trunk/templates/standard/header.template
===================================================================
--- plog/trunk/templates/standard/header.template	2006-09-09 12:46:27 UTC (rev 3951)
+++ plog/trunk/templates/standard/header.template	2006-09-10 13:13:56 UTC (rev 3952)
@@ -16,7 +16,7 @@
  <link rel="shortcut icon" type="image/x-icon" href="{$url->getTemplateFile("favicon.ico")}" />
  </head>
   <body> 
-
+<!-- Cached content created: {"0"|date_format:"%D %H:%M:%S"} -->
 <div id="Container">
   
 <div id="Title"><h1><a href="{$url->blogLink()}">{$blog->getBlog()}</a></h1></div>

Modified: plog/trunk/templates/standard/postandcomments.template
===================================================================
--- plog/trunk/templates/standard/postandcomments.template	2006-09-09 12:46:27 UTC (rev 3951)
+++ plog/trunk/templates/standard/postandcomments.template	2006-09-10 13:13:56 UTC (rev 3952)
@@ -22,13 +22,58 @@
 </p>
 
 <div class="commenttext">
+{if $comment->IsPosterAuthenticated()}
+ {assign var=poster value=$comment->getUser()}
+ {if $poster->hasPicture()}
+   {assign var=posterimg value=$poster->getPicture()}
+   <img src="{$posterimg->getPreviewLink()}" alt="{$comment->getUser()}" />
+  {/if}
+{/if}
 {$comment->getText()}
 </div>
 </div>
-  		{/foreach}
+  		{/foreach}	
 
 		{if $blogsettings->getValue("comments_enabled") && $post->getCommentsEnabled()==1}
-		{include file="$blogtemplate/commentform.template"}
+
+		<div id="CommentForm">
+
+		<form id="NewComment" action="{$url->getIndexUrl()}" method="post">
+		<fieldset>
+		<legend>{$locale->tr("add_comment")}</legend>
+		
+		{dynamic}
+		<!-- Dynamic content created: {"0"|date_format:"%D %H:%M:%S"} -->
+
+		<div><label for="commentTopic">{$locale->pr("comment_topic")}</label><input type="text" name="commentTopic" id="commentTopic" value="{$topic}" /></div>
+		<div><label for="commentText">{$locale->pr("comment_text")}</label><textarea rows="10" cols="30" name="commentText" id="commentText"></textarea></div>
+		<div><label for="userName">{$locale->pr("comment_username")}</label>
+ 			{if $authuser}
+			{$authuser->getUsername()} (<b>Authenticated</b>)<br />
+			<input type="hidden" name="userName" id="userName" value="{if $authuser}{$authuser->getUsername()}{/if}" /></div>
+			{else}
+			<input type="text" name="userName" id="userName" value="" /></div>
+			{/if}
+		<div><label for="userEmail">Email</label><input type="text" name="userEmail" id="userEmail" value="" /></div>
+		<div><label for="userUrl">Web</label><input type="text" name="userUrl" id="userUrl" value="" /></div>
+		{/dynamic}
+		
+		{if $authimage}{if $authimage->isEnabled()}
+		<div><label for="authImage">Please type the 6-digit code you can see here:</label><br/>
+		<input type="text" name="authImage" id="authImage" value="" />&nbsp;{$authimage->show()}</div>
+		{/if}{/if}
+
+		<div id="Submit"><input id="Add" type="submit" value="{$locale->pr("comment_send")}" name="Add" />
+		<input type="hidden" name="op" value="AddComment" />
+		<input type="hidden" name="articleId" value="{$post->getId()}" />
+		<input type="hidden" name="blogId" value="{$blog->getId()}" />
+		<input type="hidden" name="parentId" value="{$parentId}" /></div>
+		</fieldset>
+		</form>
+
+		</div>
+
+
 		{/if}
 			
 		{include file="$blogtemplate/footer.template"} 



More information about the pLog-svn mailing list