Index: trunk/wp-content/plugins/xpressme/include/custom_functions.php
===================================================================
--- trunk/wp-content/plugins/xpressme/include/custom_functions.php	(revision 49)
+++ trunk/wp-content/plugins/xpressme/include/custom_functions.php	(revision 51)
@@ -80,5 +80,5 @@
 		return $ret;
 	else
-		echo $ret;	
+		echo $ret;
 }
 
@@ -133,4 +133,10 @@
 		echo $ret;	
 }
+
+function xpress_is_author_view_count(){
+	$config = new XPressME_Class();
+	return $config->is_author_view_count;
+}
+
 function xpress_substr($str, $start, $length, $trimmarker = '...')
 {
@@ -208,3 +214,85 @@
 }
 
+// views count
+// Set and retrieves post views given a post ID or post object. 
+// Retrieves post views given a post ID or post object. 
+function xpress_post_views_count($post_id=0,$format= '',$show = true) {
+	global $table_prefix;
+
+	static $post_cache_views;
+
+	if ( empty($post_id) ) {
+		if ( isset($GLOBALS['post']) )
+			$post_id = $GLOBALS['post']->ID;
+	}
+
+	$post_id = intval($post_id);
+	if($post_id==0) return null;
+	if(!isset($post_cache_views[$post_id])){
+        $sql = "SELECT post_views FROM " . $table_prefix . "views" . " WHERE post_id=$post_id";
+        if (!$result = $GLOBALS["xoopsDB"]->query($sql)) {
+	        $post_cache_views[$post_id] = 0;
+        }else{
+	        $row = $GLOBALS["xoopsDB"]->fetchArray($result);
+	        $post_cache_views[$post_id] = $row["post_views"];
+        }
+	}
+	$v_count = intval($post_cache_views[$post_id]);
+	
+	if (empty($format)) $format = __('views :%d','xpressme');
+	
+	$ret = sprintf($format,$v_count);
+
+	if ($show) echo $ret; else return $ret;
+}
+
+function set_post_views_count(&$content) {
+	if ( empty($_GET["feed"]) &&  empty($GLOBALS["feed"]) && empty($GLOBALS["doing_trackback"]) && empty($GLOBALS["doing_rss"]) && empty($_POST) && is_single() ){
+		post_views_counting();
+	}
+	return $content;
+}
+
+// Set post views given a post ID or post object. 
+function post_views_counting($post_id = 0) {
+	global $table_prefix;
+	static $views;
+	
+	$post_id = intval($post_id);
+	if ( empty($post_id) && isset($GLOBALS['post']) ){
+		$post_id = $GLOBALS['post']->ID;
+	}
+
+
+	$views_db = $table_prefix . "views";
+
+	if($post_id==0 || !empty($views[$post_id])) return null;
+	
+	if(!xpress_is_author_view_count()){
+		$current_user_id = $GLOBALS['current_user']->ID;
+		$post_author_id = $GLOBALS['post']->post_author;
+		if ($current_user_id ==$post_author_id) return null;
+	}
+
+    $sql = "SELECT post_views FROM " . $views_db . " WHERE post_id=$post_id";
+    $exist = false;
+    if ($result = $GLOBALS["xoopsDB"]->query($sql)) {
+        while($row = $GLOBALS["xoopsDB"]->fetchArray($result)){
+        	$exist = true;
+	        break;
+    	}
+	}
+	if($exist){
+        $sql = "UPDATE " . $views_db . " SET post_views=post_views+1 WHERE post_id=$post_id";
+    }else{
+        $sql = "INSERT INTO " . $views_db . " (post_id, post_views) VALUES ($post_id, 1)";
+    }
+    if ($result = $GLOBALS["xoopsDB"]->queryF($sql)) {
+    	$views[$post_id] = 1;
+    }
+    
+	return true;
+}
+
+
 ?>
