트랙백(trackback) Sample

<?php
/**
 * Trackback Class
 *
 * Created on 2011. 11. 16.
 * @author 불의회상 <hoksi2k@hanmail.net>
 * @package library
 * @subpackage controllers
 * @version 1.0
 */
class Trackback_lib extends CI_Controller {
	function __construct() {
		parent::__construct();

		$this->load->library('trackback');
		$this->load->database();
		$this->load->helper('url');
	}
	
	function index() 
	{
		$this->load->library('table');

		// 템플릿 일부 항목 변경
        $tmpl = array ( 'table_open'  => '<table class="tablesorter" border="0" cellpadding="0" cellspacing="1">' );
        $this->table->set_template($tmpl);
               
		$query = $this->db->query("SELECT * FROM trackbacks order by tb_id desc limit 20");
        $data['trackbacks'] = $this->table->generate($query);
        
		$this->load->view('trackback_lib_sample', $data);		
	}
	
	function receive() 
	{
		
		if ($this->uri->segment(3) == FALSE) {
		    $this->trackback->send_error("Unable to determine the entry ID");
		}
		
		if ( ! $this->trackback->receive())	{
		    $this->trackback->send_error("The Trackback did not contain valid data");
		}
		
		$data = array(
			'tb_id'      => '',
			'entry_id'   => $this->uri->segment(3),
			'url'        => $this->trackback->data('url'),
			'title'      => $this->trackback->data('title'),
			'excerpt'    => $this->trackback->data('excerpt'),
			'blog_name'  => $this->trackback->data('blog_name'),
			'tb_date'    => time(),
			'ip_address' => $this->input->ip_address()
		);
				
		$sql = $this->db->insert_string('trackbacks', $data);
		$this->db->query($sql);
		
		$this->trackback->send_success();		
	}
	
	function send()
	{
		$tb_data = array(
			'ping_url'  => 'http://' . $this->input->server('SERVER_NAME') . '/ci20/trackback_lib/receive/123',
			'url'       => 'http://www.my-example.com/blog/entry/'.time(),
			'title'     => date('[Y-m-d H:i:s]') . ' The Title of My Entry',
			'excerpt'   => 'The entry content.',
			'blog_name' => 'My Blog Name',
			'charset'   => 'utf-8'
		);
		
		if ( ! $this->trackback->send($tb_data)) {
			echo $this->trackback->display_errors();
		} else {
			redirect('trackback_lib');
		}
	}
	
	function del()
	{
		$this->db->query("DELETE FROM trackbacks");
		redirect('trackback_lib');
	}
}
<?php $this->load->view('inc/header')?>

<table class="tablesorter" border="0" cellpadding="0" cellspacing="1">
<thead>
<tr>
  <th style="text-align:center" colspan="2">Trackback</th>
</tr>
</thead>
<tr>
	<td  colspan="2">
		<input type="button" value="트랙백 보내기" onclick="document.location.replace('<?=site_url('trackback_lib/send')?>');" />
		<input type="button" value="트랙백  모두 삭제" onclick="document.location.replace('<?=site_url('trackback_lib/del')?>');" />
	</td>
</tr>
</table>
<?php echo $trackbacks?>

<?php $this->load->view('inc/footer')?>

© Copyright by hoksi(Page rendered in 0.0079 seconds)