<?php 
/*#################################################################*\
|# Licence Number 0H6R-0808-0UVQ-0111
|# -------------------------------------------------------------   #|
|# Copyright (c)2012 PHP Link Directory.                           #|
|# http://www.phplinkdirectory.com                                 #|
\*#################################################################*/
	 
	
/**
 # ################################################################################
 # Project:   PHP Link Directory
 #
 # **********************************************************************
 # Copyright (C) 2004-2012 NetCreated, Inc. (http://www.netcreated.com/)
 #
 # This software is for use only to those who have purchased a license.
 # A license must be purchased for EACH installation of the software.
 #
 # By using the software you agree to the terms:
 #
 #    - You may not redistribute, sell or otherwise share this software
 #      in whole or in part without the consent of the the ownership
 #      of PHP Link Directory. Please contact david@david-duval.com
 #      if you need more information.
 #
 #    - You agree to retain a link back to http://www.phplinkdirectory.com/
 #      on all pages of your directory if you purchased any of our "link back" 
 #      versions of the software.
 #
 #
 # In some cases, license holders may be required to agree to changes
 # in the software license before receiving updates to the software.
 # **********************************************************************
 #
 # For questions, help, comments, discussion, etc., please join the
 # PHP Link Directory Forum http://www.phplinkdirectory.com/forum/
 #
 # @link           http://www.phplinkdirectory.com/
 # @copyright      2004-2012 NetCreated, Inc. (http://www.netcreated.com/)
 # @projectManager David DuVal <david@david-duval.com>
 # @package        PHPLinkDirectory
 # @version        4.2.1
 # ################################################################################
 */
 
class LatestLinkComments extends Widget {
	var $name;
	var $type;
	var $tpl;
	
	function LatestLinkComments($name='', $type='', $tpl='') {
		$this->name = $name;
		$this->type = $type;
		$this->tpl = get_widget_tpl($name);
		$this->tpl->assign('date_format', '%D %H:%M:%S');
	}
	
	function getContent() {
		global $db;
		global $tables;
	    
		$set = $this->getFrontSettings();
	    
		if (intval($set['NO_OF_COMMENTS']) > 0) {
			$limit = intval($set['NO_OF_COMMENTS']);
		} else {
			$limit = 10;
		}
		
		$qry = "SELECT lc.*, l.`TITLE`, DATE_FORMAT(lc.DATE_ADDED, '%b %d') AS `DAT` 
								FROM `{$tables['comment']['name']}` lc LEFT JOIN `{$tables['link']['name']}` l
								ON (lc.`ITEM_ID` = l.`ID`) 
								WHERE (lc.`STATUS` = '2' AND lc.`TYPE` = '1')
								ORDER BY lc.`DATE_ADDED` DESC LIMIT 0, ".$limit;
		if ($set['CACHE_RESULTS'] == "Yes") {
			$latest_com = $db->CacheGetAll($qry);
		} else {
			$latest_com = $db->CacheGetAll($qry);
		}
		
		foreach($latest_com as $k => $v) {
        	$latest_com[$k]['SEO_URL'] = seo_url($v['ARTICLE_ID'], $v['TITLE'], REWRITE_TYPE, REWRITE_EXT, 2);
    	}
    	$this->tpl->assign('latest_com', $latest_com);
    	
    	if ($set['DISPLAY_IN_BOX'] == "No") {
			$this->tpl->assign('show_title', 1);
		}
		$this->tpl->assign("TITLE", $set['TITLE']);
    	
		return $this->tpl->fetch('content.tpl');
	}
}

?>