[pLog-svn] r4931 - in plugins/branches/lifetype-1.2/unported/blogstatistics: . class class/dao

jondaley at devel.lifetype.net jondaley at devel.lifetype.net
Fri Mar 2 12:57:55 EST 2007


Author: jondaley
Date: 2007-03-02 12:57:55 -0500 (Fri, 02 Mar 2007)
New Revision: 4931

Added:
   plugins/branches/lifetype-1.2/unported/blogstatistics/class/
   plugins/branches/lifetype-1.2/unported/blogstatistics/class/dao/
   plugins/branches/lifetype-1.2/unported/blogstatistics/class/dao/blogstatistics.class.php
Modified:
   plugins/branches/lifetype-1.2/unported/blogstatistics/pluginblogstatistics.class.php
Log:
still not ported, but closer.  The main problem is the {dynamic} thing.  I thought it was working better than it is

Added: plugins/branches/lifetype-1.2/unported/blogstatistics/class/dao/blogstatistics.class.php
===================================================================
--- plugins/branches/lifetype-1.2/unported/blogstatistics/class/dao/blogstatistics.class.php	                        (rev 0)
+++ plugins/branches/lifetype-1.2/unported/blogstatistics/class/dao/blogstatistics.class.php	2007-03-02 17:57:55 UTC (rev 4931)
@@ -0,0 +1,57 @@
+<?php
+//
+// blogstatistics - LifeType Blog Statistics and Traffic Statistics
+//
+// Copyright 2004 by Minstrel Chiu. All rights reserved.
+//
+// Licensed under the GNU GPL License, Version 2.0 (the "License");
+// Everyone is permitted to copy and distribute verbatim copies
+// of this license document, but changing it is not allowed.
+// You may obtain a copy of the License at
+//
+//   http://www.fsf.org/copyleft/gpl.html
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+
+	lt_include( PLOG_CLASS_PATH."class/dao/model.class.php" );
+
+	class BlogStatistics extends Model
+    {
+        function BlogStatistics(){
+			$this->Model();
+		}
+
+		function checkTable($db, $table, $field){
+			$dbPrefix = $this->getPrefix();
+			$tableName = $dbPrefix.$table;
+
+			// create the data dictionary and create the table if necessary
+			$dict = NewPDbDataDictionary( $db );
+			$sqlArray = $dict->ChangeTableSQL( $tableName, $field );
+			$result = $dict->ExecuteSQLArray( $sqlArray );
+
+			if( $result == 0 )
+				$this->_desc = "There was an error initializing the tables.";
+		}
+
+		function createTable($db){
+			$table = "statistics";
+			$field = "blog_id I(10) NOT NULL default '-1',
+				article_id I(10) NOT NULL default '-1',
+				time timestamp(14),
+				ip varchar(15) default '0.0.0.0',
+				refer text NOT NULL,
+				agent text NOT NULL";
+
+			$this->checkTable($db, $table, $field);
+
+			return true;
+		}
+	}
+
+?>

Modified: plugins/branches/lifetype-1.2/unported/blogstatistics/pluginblogstatistics.class.php
===================================================================
--- plugins/branches/lifetype-1.2/unported/blogstatistics/pluginblogstatistics.class.php	2007-03-02 17:20:04 UTC (rev 4930)
+++ plugins/branches/lifetype-1.2/unported/blogstatistics/pluginblogstatistics.class.php	2007-03-02 17:57:55 UTC (rev 4931)
@@ -19,7 +19,6 @@
 //
 
 	lt_include( PLOG_CLASS_PATH."class/plugin/pluginbase.class.php" );
-	lt_include( PLOG_CLASS_PATH."class/dao/model.class.php" );
 	lt_include( PLOG_CLASS_PATH."class/data/Date.class.php" );
 //	lt_include( PLOG_CLASS_PATH."class/data/timestamp.class.php" );
 
@@ -85,8 +84,8 @@
 			</p>";
 
 
-			$config =& Config::getConfig();
-			$this->_prefix = $config->getValue('db_prefix');
+            $this->_prefix = Db::getPrefix();
+            $this->_db =& Db::getDb();
 
 			$this->_now = new Date();
 
@@ -111,33 +110,39 @@
 		}
 
 		function register(){
-		    $this->db =& Db::getDb();
+            lt_include( PLOG_CLASS_PATH."plugins/blogstatistics/class/dao/blogstatistics.class.php" );
             $stat = new BlogStatistics();
-            $stat->createTable();
+            $stat->createTable($this->_db);
 		}
 
 		function logStatistics(){
             lt_include( PLOG_CLASS_PATH."class/net/url.class.php" );
+            lt_include( PLOG_CLASS_PATH."class/data/validator/rules/urlformatrule.class.php" );
             lt_include( PLOG_CLASS_PATH."class/net/client.class.php" );
 
 			$blog = $this->blogInfo->getId();
 			$timestamp = $this->_now->getDate(DATE_FORMAT_TIMESTAMP);
 			$clientip = Client::getIp();
-			$refer = $_SERVER["HTTP_REFERER"];
-			$ourHost = $_SERVER["HTTP_HOST"];
-			$agent = $_SERVER["HTTP_USER_AGENT"];
+            $ourHost = $_SERVER["HTTP_HOST"];
 
-			$refererUrl = new Url( $refer );
+                // TODO: better validation
+            $agent = $_SERVER["HTTP_USER_AGENT"];
+            if(preg_match("/[^A-Za-z0-9.\/ ;\-:]/", $agent))
+                $agent = "Invalid";
 
-			if( $refererUrl->getHost() == $ourHost || $refererUrl->getHost() == "" )
-			{
+			$refer = $_SERVER["HTTP_REFERER"];
+            $ufr = new UrlFormatRule();
+            if(!$ufr->validate($refer))
+                $refer = "";
+            
+			$refererUrl = new Url( $refer );
+			if($refererUrl->getHost() == $ourHost || $refererUrl->getHost() == "")
 				$refer = "";
-			}
 
 			$params = HttpVars::getRequest();
 			$articleId = $params["articleId"];
 
-            if((preg_match("/[^0-9]/", $articleId) != 0) || $articleId == "")
+            if(preg_match("/[^0-9]/", $articleId) || $articleId == "")
 				$articleId = 0;
 
 			$this->injectSql("(`blog_id`, `article_id`, `time`, `ip`,  `refer`, `agent`) VALUES ('$blog', '$articleId', '$timestamp', '$clientip', '$refer', '$agent');");
@@ -146,9 +151,11 @@
 		function injectSql($dbqry)
 		{
 			$query = "INSERT INTO ".$this->_prefix."statistics $dbqry";
-			$result = $this->db->Execute( $query );
+			$result = $this->_db->Execute( $query );
 		}
 
+
+        
 		////////////////////////////////////////////////////////////////////////////////////////////
 		//
 		//
@@ -166,7 +173,7 @@
 
 			$query .= ";";
 
-			$result = $this->db->Execute( $query );
+			$result = $this->_db->Execute( $query );
 
 			if( $result )
 				$count = $result->RecordCount();
@@ -183,7 +190,7 @@
 
 			$query .= ";";
 
-			$result = $this->db->Execute( $query );
+			$result = $this->_db->Execute( $query );
 
 			if( $result )
 				$count = $result->RecordCount();
@@ -200,7 +207,7 @@
 
 			$query .= ";";
 
-			$result = $this->db->Execute( $query );
+			$result = $this->_db->Execute( $query );
 
 			if( !$result )
 				return false;
@@ -218,7 +225,7 @@
 
 			$query .= ";";
 
-			$result = $this->db->Execute( $query );
+			$result = $this->_db->Execute( $query );
 
 			if( $result )
 				$count = $result->RecordCount();
@@ -235,7 +242,7 @@
 
 			$query .= ";";
 
-			$result = $this->db->Execute( $query );
+			$result = $this->_db->Execute( $query );
 
 			if( $result )
 				$count = $result->RecordCount();
@@ -260,7 +267,7 @@
 
 			$query .= ";";
 
-			$result = $this->db->Execute( $query );
+			$result = $this->_db->Execute( $query );
 
 			if( $result )
 				$count = $result->RecordCount();
@@ -277,7 +284,7 @@
 
 			$query .= ";";
 
-			$result = $this->db->Execute( $query );
+			$result = $this->_db->Execute( $query );
 
 			if( $result )
 				$count = $result->RecordCount();
@@ -294,7 +301,7 @@
 
 			$query .= ";";
 
-			$result = $this->db->Execute( $query );
+			$result = $this->_db->Execute( $query );
 
 			if( $result )
 				$count = $result->RecordCount();
@@ -311,7 +318,7 @@
 
 			$query .= ";";
 
-			$result = $this->db->Execute( $query );
+			$result = $this->_db->Execute( $query );
 
 			if( $result )
 				$count = $result->RecordCount();
@@ -328,7 +335,7 @@
 
 			$query .= ";";
 
-			$result = $this->db->Execute( $query );
+			$result = $this->_db->Execute( $query );
 
 			if( $result )
 				$count = $result->RecordCount();
@@ -344,7 +351,7 @@
 
 			$query .= ";";
 
-			$result = $this->db->Execute( $query );
+			$result = $this->_db->Execute( $query );
 
 			if( $result )
 				$count = $result->RecordCount();
@@ -361,7 +368,7 @@
 
 			$query .= ";";
 
-			$result = $this->db->Execute( $query );
+			$result = $this->_db->Execute( $query );
 
 			if( $result )
 				$count = $result->RecordCount();
@@ -378,7 +385,7 @@
 
 			$query .= ";";
 
-			$result = $this->db->Execute( $query );
+			$result = $this->_db->Execute( $query );
 
 			if( $result )
 				$count = $result->RecordCount();
@@ -395,7 +402,7 @@
 
 			$query .= ";";
 
-			$result = $this->db->Execute( $query );
+			$result = $this->_db->Execute( $query );
 
 			if( $result )
 				$count = $result->RecordCount();
@@ -412,7 +419,7 @@
 
 			$query .= ";";
 
-			$result = $this->db->Execute( $query );
+			$result = $this->_db->Execute( $query );
 
 			if( $result )
 				$count = $result->RecordCount();
@@ -429,7 +436,7 @@
 
 			$query .= ";";
 
-			$result = $this->db->Execute( $query );
+			$result = $this->_db->Execute( $query );
 
 			if( $result )
 				$count = $result->RecordCount();
@@ -437,42 +444,4 @@
 			return $count;
 		}
 	}
-
-	class BlogStatistics extends Model
-	{
-		function BlogStatistics()
-		{
-			$this->Model();
-		}
-
-		function checkTable($table, $field)
-		{
-			$dbPrefix = $this->getPrefix();
-			$tableName = $dbPrefix.$table;
-
-			// create the data dictionary and create the table if necessary
-			$dict = NewDataDictionary( $this->_db );
-			$sqlArray = $dict->ChangeTableSQL( $tableName, $field );
-			$result = $dict->ExecuteSQLArray( $sqlArray );
-
-			if( $result == 0 )
-				$this->_desc = "There was an error initializing the tables.";
-		}
-
-		function createTable()
-		{
-			$table = "statistics";
-			$field = "blog_id I(10) NOT NULL default '-1',
-				article_id I(10) NOT NULL default '-1',
-				time timestamp(14),
-				ip varchar(15) default '0.0.0.0',
-				refer text NOT NULL,
-				agent text NOT NULL";
-
-			$this->checkTable( $table, $field );
-
-			return true;
-		}
-	}
-
 ?>



More information about the pLog-svn mailing list