Location: PHPKode > scripts > Universal comment module > universal-comment-module/Comment.class.php
<?php
/*
	Main Comment class.
	by ivi.
	www: newsroot.net
	E-mail: hide@address.com
	ICQ# 4405730
*/


	require_once("conf.php");
	require_once("func.php");
	
	
	require_once("API.class.php");
	require_once("template.php");
	
	
	
	class Comment
	{
		var $table = "";
		var $api = NULL;
		var $id = NULL;
		
		
		function Comment($id)
		{
			$this->__construct($id);
		}
		
		function __construct($id)
		{
			$this->api =  new C_API();
			$this->id = $id;
		}
		
		
		function getComments()
		{
			$direct  =  "";
			if(_MESSAGES_DERECTION == 1)
				$direct ="DESC";
			else 
				$direct ="ASC";
			$sql  = "select * from `"._COMMENT_TABLE."` where `id`= '$this->id' order BY `_id` $direct";
			$arr  = $this->api->db_getAll($sql);
			if(testArray($arr))
			{
				foreach ($arr as $key=>$val)
				{
					$arr[$key]['ldate'] =  $this->getDate($val['dtime']);
					$arr[$key]['username'] =  $this->api->getUserName($val['userid']);
					
				}
			}
			$str  =   getTPLComments($arr,$this->id,$this->api->getUserId());
			return $str;
//			dump($sql);
//			dump($arr);
		}
		
		function addComment($msg,$id,$userid)
		{ 
			$msg = escape(strip_tags(trim($msg)));
			$id  =  escape(trim($id));
			$userid  =  intval($userid);
			if($userid <=0)
				exit;
			$sql  =  "insert into `"._COMMENT_TABLE."` (`id`,`userid`,`msg`,`dtime`) values ('".$id."','$userid','$msg',now());";
			$this->api->db_query($sql);
			$msgid  = $this->api->getLastId();
			$sql  =  "select * from `"._COMMENT_TABLE."` where `id`= '$this->id' AND `_id`='$msgid'";
			$arr  = $this->api->db_getOne($sql);
			if(testArray($arr))
			{
				$arr['ldate'] =  $this->getDate($arr['dtime']);
				$arr['username'] =  $this->api->getUserName($arr['userid']);
			}
			else 
				exit;
			$div  =  getTplROW($arr);
			echo $div;
//			dump($arr);
		}
		
		
		function getDate($date)
		{
			$time  =  strtotime($date);
			return date(_DATE_FORMAT,$time);
		}
		
			
	}
?>
Return current item: Universal comment module