<?php
/* 
 * $Id: plugin.inc.php,v 1.3 2004/09/23 09:31:33 youka Exp $
 */



class Plugin_trackback extends Plugin
{
	function do_inline($pagename, $param1, $param2)
	{
		$num = TrackBack::getinstance($pagename)->countreceived();
		$path = SCRIPTPATH;
		$page = rawurlencode($pagename);
		return "<a href=\"{$path}?plugin=trackback&amp;page={$page}\">TrackBack({$num})</a>";
	}
	
	
	function do_url()
	{
		$get = KinoWiki::getinstance()->getGET();
		if(!isset($get['page'])){
			throw new PluginException('パラメータが足りません。');
		}
		$pagename = trim($get['page']);
		
		$db = DataBase::getinstance();
		$_pagename = $db->escape($pagename);
		$query  = "SELECT num, title, excerpt, url, blog_name, timestamp FROM trackback";
		$query .= " WHERE pagename = '$_pagename'";
		$query .= " ORDER BY timestamp DESC";
		$result = $db->query($query);
		
		$smarty = new PluginSmarty('trackback');
		$html = array();
		while($row = $db->fetch($result)){
			$smarty->append('trackback', $row);
		}
		
		$smarty->assign('pagename', $pagename);
		$smarty->assign('pingurl', TrackBack::getinstance($pagename)->getpingurl());
		$ret['title'] = htmlspecialchars("{$pagename} へのTrackBack");
		$ret['body'] = $smarty->fetch('trackback.tpl.htm');
		return $ret;
	}
}

?>