[pLog-svn] r723 - plog/trunk

oscar at devel.plogworld.net oscar at devel.plogworld.net
Mon Jan 10 18:01:10 GMT 2005


Author: oscar
Date: 2005-01-10 18:01:10 +0000 (Mon, 10 Jan 2005)
New Revision: 723

Modified:
   plog/trunk/trackback.php
Log:
fixed a logging issue

Modified: plog/trunk/trackback.php
===================================================================
--- plog/trunk/trackback.php	2005-01-10 17:55:54 UTC (rev 722)
+++ plog/trunk/trackback.php	2005-01-10 18:01:10 UTC (rev 723)
@@ -9,7 +9,6 @@
     include_once( PLOG_CLASS_PATH."class/config/config.class.php" );
     include_once( PLOG_CLASS_PATH."class/data/textfilter.class.php" );
     include_once( PLOG_CLASS_PATH."class/net/http/httpvars.class.php" );
-    include_once( PLOG_CLASS_PATH."class/logger/logger.class.php" );
 	include_once( PLOG_CLASS_PATH."class/dao/articlenotifications.class.php" );
 	include_once( PLOG_CLASS_PATH."class/dao/articles.class.php" );
 	include_once( PLOG_CLASS_PATH."class/dao/blogs.class.php" );
@@ -21,6 +20,12 @@
     //
     define( "TRACKBACK_DEBUG_ENABLED", true );
 
+	/**
+	 * shorthand function for creating an error response to a client
+	 *
+	 * @param message the error message
+	 * @return returns the xml error message
+	 */
     function errorResponse( $message )
     {
         $result = '<?xml version="1.0" encoding="iso-8859-1"?>';
@@ -32,26 +37,56 @@
         return $result;
     }
 	
+	/**
+	 * dumps a whole request to the log file
+	 *
+	 * @param request
+	 * @return always true
+	 */
 	function dumpRequest( $request ) 
 	{
-		Logger::log( "-- dump of trackback request --" );
+
+		trackbackLog( "-- dump of trackback request --" );
 		$params = $request->getAsArray();
 		foreach( $params as $key => $value )
 		{
-			Logger::log( "  $key = $value" );
+			trackbackLog( "  $key = $value" );
 		}
-		Logger::log( "-- end of dump --" );
+		trackbackLog( "-- end of dump --" );
 		
 		return true;
 	}
+	
+	/**
+	 * shorthand function for getting a logger and sending a message to the log file
+	 *
+	 * @param message
+	 * @return always true
+	 * @see LoggerManager
+	 */
+	function trackbackLog( $message )
+	{
+		if( TRACKBACK_DEBUG_ENABLED ) {
+			$logger =& LoggerManager::getLogger( "trackback.php" );
+			$logger->debug( $message );
+		}
+		
+		return true;
+	}
+	
+	/**
+	 *
+	 * whoa believe it or not, in pLog you can also find php code that is not within a class! :-)
+	 *
+	 * perhaps the code below should be cleaned up and put into a TrackbackServer class or something
+	 * like that but since it works the way it is, we'll leave it like it is!
+	 *
+	 */
 
     // prepare everything...
     $config =& Config::getConfig();
-    Logger::setLogFilePath( $config->getValue( "temp_folder" ), "trackback.log" );
-	Logger::setEnabled( TRACKBACK_DEBUG_ENABLED );
-
     // get the post and get parameters
-    Logger::log( "** Request received" );
+    trackbackLog( "** Request received" );
     $params = new Properties( HttpVars::getRequest());
     dumpRequest( $params );
 
@@ -59,21 +94,21 @@
     if( $params->getValue("id") == "" || $params->getValue("id") <= 0 ) {
         $result = errorResponse( "Incorrect or missing id parameter." );
         print($result);
-        Logger::log( "Sending error response: $result" );
-        Logger::log( "** End" );
+        trackbackLog( "Sending error response: $result" );
+        trackbackLog( "** End" );
         die;
     }
 
     if( $params->getValue( "url" ) == "" ) {
         $result = errorResponse( "The url parameter must be present." );
         print($result);
-        Logger::log( "Sending error response: $result" );
-        Logger::log( "** End" );
+        trackbackLog( "Sending error response: $result" );
+        trackbackLog( "** End" );
         die;
     }
 
     if( !$config->getValue( "trackback_server_enabled" )) {
-		Logger::Log( "Trackback server disabled by administrator" );
+		trackbackLog( "Trackback server disabled by administrator" );
         $result = errorResponse( "Trackback feature has been disabled by the administrator." );
 		die( $result );	
 	}
@@ -90,7 +125,7 @@
 	$articles = new Articles();
 	$article = $articles->getBlogArticle( $articleId );
 	if( !$article ) {
-		Logger::Log( "ERROR: Incorrect error identifier" );
+		trackbackLog( "ERROR: Incorrect error identifier" );
 		$result = errorResponse( "Incorrect article identifier" );
 		die( $result );
 	}
@@ -104,7 +139,7 @@
 	// and now add it to our database
 	$result = $trackbacks->addTrackBack( $articleId, $url, $title, $blogName, $excerpt);
 	if( !$result ) {
-		Logger::Log( "There was an error saving the trackback!" );
+		trackbackLog( "There was an error saving the trackback!" );
 	}
 
 	// result
@@ -115,7 +150,7 @@
 
 	// notify the user that a new trackback has been received, if the article was
 	// configured to receive notifications
-	Logger::Log( "Notification sent!" );
+	trackbackLog( "Notification sent!" );
 	$notifier = new ArticleNotifications();
 	$notifier->notifyUsers( $article->getId(), $blogInfo);
 	
@@ -125,8 +160,8 @@
     // return the result
     print($result);
 
-    Logger::log( "Sending response: $result" );
-    Logger::log( "** End" );
+    trackbackLog( "Sending response: $result" );
+    trackbackLog( "** End" );
 	
 	die();
 ?>
\ No newline at end of file




More information about the pLog-svn mailing list