referer module (#279)

git-svn-id: http://xe-core.googlecode.com/svn/sandbox@3106 201d5d3c-b55e-5fd7-737f-ddc643e51545
This commit is contained in:
haneul 2007-11-28 17:45:32 +00:00
parent 74ad4fc4a7
commit ae357bceb0
18 changed files with 384 additions and 0 deletions

View file

@ -0,0 +1,11 @@
<?xml version="1.0" encoding="utf-8"?>
<module version="0.1" category="accessory">
<title xml:lang="ko">리퍼러 통계</title>
<title xml:lang="en">Referer Statistics</title>
<author email_address="haneul0318@gmail.com" link="http://haneul.zetyx.net" date="2007. 11. 29">
<name xml:lang="ko">haneul</name>
<name xml:lang="en">haneul</name>
<description xml:lang="ko">기본 리퍼러 통계 프로그램입니다.</description>
<description xml:lang="en">Basic referer statistics program.</description>
</author>
</module>

View file

@ -0,0 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<module>
<grants />
<actions>
<action name="procRefererExecute" type="controller" standalone="true" />
<action name="dispRefererAdminIndex" type="view" standalone="true" admin_index="true" />
</actions>
</module>

View file

@ -0,0 +1,10 @@
<?php
/**
* @file module/referer/lang/ko.lang.php
* @author haneul <haneul0318@gmail.com>
* @brief English language pack
*/
$lang->referer = "Referer";
$lang->ranking = "Ranking";
?>

View file

@ -0,0 +1,10 @@
<?php
/**
* @file module/referer/lang/ko.lang.php
* @author haneul <haneul0318@gmail.com>
* @brief Korean language pack
*/
$lang->referer = "리퍼러";
$lang->ranking = "순위";
?>

View file

@ -0,0 +1,8 @@
<query id="deleteOlddatedLogs" action="delete">
<tables>
<table name="referer_log" />
</tables>
<conditions>
<condition operation="less" column="regdate" var="regdate" notnull="notnull" />
</conditions>
</query>

View file

@ -0,0 +1,11 @@
<query id="getHostStatus" action="select">
<tables>
<table name="referer_statistics" />
</tables>
<columns>
<column name="count(*)" alias="count"/>
</columns>
<conditions>
<condition operation="equal" column="host" var="host" notnull="notnull" />
</conditions>
</query>

View file

@ -0,0 +1,16 @@
<query id="getRefererLogList" action="select">
<tables>
<table name="referer_log" />
</tables>
<columns>
<column name="*" />
</columns>
<conditions>
</conditions>
<navigation>
<index var="sort_index" default="regdate" order="desc" />
<list_count var="list_count" default="20" />
<page_count var="page_count" default="10" />
<page var="page" default="1" />
</navigation>
</query>

View file

@ -0,0 +1,16 @@
<query id="getRefererStatistics" action="select">
<tables>
<table name="referer_statistics" />
</tables>
<columns>
<column name="*" />
</columns>
<conditions>
</conditions>
<navigation>
<index var="sort_index" default="count" order="desc" />
<list_count var="list_count" default="20" />
<page_count var="page_count" default="10" />
<page var="page" default="1" />
</navigation>
</query>

View file

@ -0,0 +1,10 @@
<query id="insertRefererLog" action="insert">
<tables>
<table name="referer_log" />
</tables>
<columns>
<column name="regdate" var="regdate" default="curdate()" notnull="notnull"/>
<column name="host" var="host" notnull="notnull" />
<column name="url" var="url" />
</columns>
</query>

View file

@ -0,0 +1,9 @@
<query id="insertRefererStatistics" action="insert">
<tables>
<table name="referer_statistics" />
</tables>
<columns>
<column name="host" var="host" notnull="notnull" />
<column name="count" var="count" default="1" />
</columns>
</query>

View file

@ -0,0 +1,11 @@
<query id="updateRefererStatistics" action="update">
<tables>
<table name="referer_statistics" />
</tables>
<columns>
<column name="count" var="count" default="plus(1)" />
</columns>
<conditions>
<condition operation="equal" column="host" var="host" notnull="notnull" />
</conditions>
</query>

View file

@ -0,0 +1,51 @@
<?php
/**
* @class refererAdminView
* @author haneul (haneul0318@gmail.com)
* @brief referer 모듈의 Admin view class
**/
class refererAdminView extends referer {
/**
* @brief 초기화
**/
function init() {
// 템플릿 경로 지정
$this->setTemplatePath($this->module_path.'tpl');
}
/**
* @brief 관리자 페이지 초기화면
**/
function dispRefererAdminIndex() {
$this->dispRefererAdminList();
}
function dispRefererAdminList() {
// 목록을 구하기 위한 옵션
$args->page = Context::get('page'); ///< 페이지
$args->sort_index = 'regdate'; ///< 소팅 값
$oRefererModel = &getModel('referer');
$output = $oRefererModel->getLogList($args);
Context::set('total_count', $output->total_count);
Context::set('total_page', $output->total_page);
Context::set('page', $output->page);
Context::set('referer_list', $output->data);
Context::set('page_navigation', $output->page_navigation);
$args2->sort_index = 'count';
$output2 = $oRefererModel->getRefererStatus($args2);
Context::set('referer_status', $output2->data);
// 템플릿 지정
$this->setTemplatePath($this->module_path.'tpl');
$this->setTemplateFile('referer_list');
}
}
?>

View file

@ -0,0 +1,41 @@
<?php
/**
* @class referer
* @author haneul (haneul0318@gmail.com)
* @brief referer module's class
**/
class referer extends ModuleObject {
/**
* @brief Install referer module
**/
function moduleInstall() {
// action forward에 등록 (관리자 모드에서 사용하기 위함)
$oModuleController = &getController('module');
$oModuleController->insertActionForward('referer', 'view', 'dispRefererAdminIndex');
return new Object();
}
/**
* @brief 설치가 이상이 없는지 체크하는 method
**/
function checkUpdate() {
return false;
}
/**
* @brief 업데이트 실행
**/
function moduleUpdate() {
return new Object();
}
/**
* @brief 캐시 파일 재생성
**/
function recompileCache() {
}
}
?>

View file

@ -0,0 +1,60 @@
<?php
/**
* @class refererController
* @author haneul (haneul0318@gmail.com)
* @brief referer 모듈의 controller class
**/
class refererController extends referer {
/**
* @brief initialization
**/
function init() {
}
function procRefererExecute() {
if(empty($_SERVER["HTTP_REFERER"])) return;
// Log only from different hosts
$referer = parse_url($_SERVER["HTTP_REFERER"]);
if($referer['host'] == $_SERVER['HTTP_HOST']) return;
$oDB = &DB::getInstance();
$oDB -> begin();
$this->insertRefererLog($referer['host'], $_SERVER["HTTP_REFERER"]);
$this->deleteOlddatedRefererLogs();
$this->updateRefererStatistics($referer['host']);
$oDB -> commit();
}
function updateRefererStatistics($host)
{
$oRefererModel = &getModel('referer');
$args->host = $host;
if($oRefererModel->isInsertedHost($host))
{
$output = executeQuery('referer.updateRefererStatistics', $args);
}
else
{
$output = executeQuery('referer.insertRefererStatistics', $args);
}
return $output;
}
function insertRefererLog($host, $url)
{
$args->regdate = date("YmdHis");
$args->host = $host;
$args->url = $url;
return executeQuery('referer.insertRefererLog', $args);
}
function deleteOlddatedRefererLogs()
{
$args->regdate = date("YmdHis", strtotime("-1 week"));
return executeQuery('referer.deleteOlddatedLogs', $args);
}
}
?>

View file

@ -0,0 +1,43 @@
<?php
/**
* @class refererModel
* @author haneul (haneul0318@gmail.com)
* @brief referer 모듈의 Model class
**/
class refererModel extends referer {
function init()
{
}
function isInsertedHost($host) {
$args->host = $host;
$output = executeQuery('referer.getHostStatus', $args);
return $output->data->count?true:false;
}
function getLogList($obj)
{
$query_id = 'referer.getRefererLogList';
$args->sort_index = 'regdate';
$args->page = $obj->page?$obj->page:1;
$args->list_count = $obj->list_count?$obj->list_count:20;
$args->page_count = $obj->page_count?$obj->page_count:10;
$output = executeQuery($query_id, $args);
// 결과가 없거나 오류 발생시 그냥 return
if(!$output->toBool()||!count($output->data)) return $output;
return $output;
}
function getRefererStatus()
{
$args->sort_index = 'count';
return executeQuery("referer.getRefererStatistics", $args);
}
}
?>

View file

@ -0,0 +1,5 @@
<table name="referer_log">
<column name="host" type="varchar" size="64" notnull="notnull" />
<column name="url" type="varchar" size="250" notnull="notnull" />
<column name="regdate" type="date" index="idx_referer_log" />
</table>

View file

@ -0,0 +1,4 @@
<table name="referer_statistics">
<column name="host" type="varchar" size="64" notnull="notnull" primary_key="primary_key" />
<column name="count" type="number" size="11" default="0" index="idx_referer_counter" />
</table>

View file

@ -0,0 +1,60 @@
<h3>{$lang->referer} <span class="gray">{$lang->cmd_management}</span></h3>
<div style="width: 250px; float:left; position:relative;">
<div class="tableSummaryType1" style="position:relative; top:10px;">
{$lang->ranking}
</div>
<div class="tableSummaryType1" style="position:relative; top:10px;">
<table cellspacing="0" class="adminTable refererStat">
<tbody>
<col width="50" />
<col width="150" />
<col width="50" />
<!--@foreach($referer_status as $no => $val)-->
<tr>
<td class="tahoma">{$no} </td>
<td class="tahoma">{$val->host}</td>
<td class="tahoma">{$val->count}</td>
</td>
<!--@end-->
</tbody>
</table>
</div>
</div>
<div style="float:left; position:relative; left:20px;">
<div class="tableSummaryType1" style="position:relative; top:10px;">
Total <strong>{number_format($total_count)}</strong>, Page <strong>{number_format($page)}</strong>/{number_format($total_page)}
</div>
<div style="position:relative; top:10px;">
<table cellspacing="0" class="adminTable referer">
<col width="80" />
<col width="150" />
<col width="350" />
<tbody>
<!--@foreach($referer_list as $no => $val)-->
<tr>
<td class="tahoma">{zdate($val->regdate,"Y-m-d")}</td>
<td class="tahoma">{$val->host}</td>
<td class="tahoma"><a href="{$val->url}">{$val->url}</a></td>
</tr>
<!--@end-->
</tbody>
</table>
<!-- 버튼 -->
</div>
<!-- 페이지 네비게이션 -->
<div class="pageNavigation" style="position:relative; top:10px;">
<a href="{getUrl('page','','module_srl','')}" class="goToFirst"><img src="../../admin/tpl/images/bottomGotoFirst.gif" alt="{$lang->first_page}" width="7" height="5" /></a>
<!--@while($page_no = $page_navigation->getNextPage())-->
<!--@if($page == $page_no)-->
<span class="current">{$page_no}</span>
<!--@else-->
<a href="{getUrl('page',$page_no,'module_srl','')}">{$page_no}</a>
<!--@end-->
<!--@end-->
<a href="{getUrl('page',$page_navigation->last_page,'module_srl','')}" class="goToLast"><img src="../../admin/tpl/images/bottomGotoLast.gif" alt="{$lang->last_page}" width="7" height="5" /></a>
</div>
</div>