mirror of
https://github.com/Lastorder-DC/rhymix.git
synced 2026-01-08 19:21:40 +09:00
제로보드XE의 기본 카운터의 그래프 표시 위젯 추가
git-svn-id: http://xe-core.googlecode.com/svn/sandbox@2411 201d5d3c-b55e-5fd7-737f-ddc643e51545
This commit is contained in:
parent
dd804f33f0
commit
75d594fbe0
3 changed files with 249 additions and 0 deletions
84
widgets/image_counter/conf/info.xml
Normal file
84
widgets/image_counter/conf/info.xml
Normal file
|
|
@ -0,0 +1,84 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<widget version="0.1">
|
||||
<title xml:lang="ko">이미지 카운터 위젯</title>
|
||||
<author email_address="zero@zeroboard.com" link="http://www.zeroboard.com" date="2007. 8. 27">
|
||||
<name xml:lang="ko">제로</name>
|
||||
<description xml:lang="ko">
|
||||
제로보드XE의 기본 카운터를 블로그나 사이트에 달 수 있는 작은 그래프로 표시를 합니다.
|
||||
크기, 배경색등의 조건을 설정하지 않으시면 기본 설정으로 사용됩니다.
|
||||
그래프를 그리기 위해서 GD 라이브러리가 설치되어 있어야 합니다.
|
||||
</description>
|
||||
</author>
|
||||
<extra_vars>
|
||||
<var id="graph_width">
|
||||
<name xml:lang="ko">가로 크기</name>
|
||||
<type>text</type>
|
||||
<description xml:lang="ko">
|
||||
그래프 이미지의 가로크기를 지정하실 수 있습니다.
|
||||
지정하지 않으시면 150px로 지정되며 숫자로 입력을 해주세요.
|
||||
코드 생성 페이지의 하단에 있는 가로크기와 다르게 적용됩니다.
|
||||
</description>
|
||||
</var>
|
||||
<var id="graph_height">
|
||||
<name xml:lang="ko">세로 크기</name>
|
||||
<type>text</type>
|
||||
<description xml:lang="ko">
|
||||
그래프 이미지의 세로 크기를 지정하실 수 있습니다.
|
||||
지정하지 않으시면 100px로 지정되며 숫자로 입력을 해주세요.
|
||||
</description>
|
||||
</var>
|
||||
<var id="day_range">
|
||||
<name xml:lang="ko">출력 기간</name>
|
||||
<type>text</type>
|
||||
<description xml:lang="ko">
|
||||
오늘부터 지정하신 출력기간 만큼의 데이터를 그래프로 출력합니다.
|
||||
숫자를 입력해주세요. (기본 지난 7일)
|
||||
</description>
|
||||
</var>
|
||||
<var id="bg_color">
|
||||
<name xml:lang="ko">배경색</name>
|
||||
<type>text</type>
|
||||
<description xml:lang="ko">
|
||||
지정하신 색상 코드로 배경을 그립니다.
|
||||
기본 : #FFFFFF
|
||||
#과 6자리의 색상코드 입력해주세요
|
||||
</description>
|
||||
</var>
|
||||
<var id="check_bg_color">
|
||||
<name xml:lang="ko">체크 무늬 배경색</name>
|
||||
<type>text</type>
|
||||
<description xml:lang="ko"><![CDATA[지정하신 색상 코드로 체크 무늬 배경을 그립니다.
|
||||
기본 : <span style="color:#F9F9F9">#F9F9F9</span>
|
||||
#과 6자리의 색상코드 입력해주세요]]></description>
|
||||
</description>
|
||||
</var>
|
||||
<var id="grid_color">
|
||||
<name xml:lang="ko">격자 선 색</name>
|
||||
<type>text</type>
|
||||
<description xml:lang="ko"><![CDATA[지정하신 색상 코드로 xy 격자를 그립니다.
|
||||
기본 : <span style="color:#9d9d9d">#9d9d9d</span>
|
||||
#과 6자리의 색상코드 입력해주세요]]></description>
|
||||
</var>
|
||||
<var id="unique_line_color">
|
||||
<name xml:lang="ko">그래프 선색</name>
|
||||
<type>text</type>
|
||||
<description xml:lang="ko"><![CDATA[지정하신 색상 코드로 방문자 그래프 선을 그립니다.
|
||||
기본 : <span style="color:#BBBBBB">#BBBBBB</span>
|
||||
#과 6자리의 색상코드 입력해주세요]]></description>
|
||||
</var>
|
||||
<var id="unique_text_color">
|
||||
<name xml:lang="ko">방문자 수 글자색</name>
|
||||
<type>text</type>
|
||||
<description xml:lang="ko"><![CDATA[지정하신 색상 코드로 방문자 수 글자를 표시합니다.
|
||||
기본 : <span style="color:#666666">#666666</span>
|
||||
#과 6자리의 색상코드 입력해주세요]]></description>
|
||||
</var>
|
||||
<var id="point_color">
|
||||
<name xml:lang="ko">포인트 점 색</name>
|
||||
<type>text</type>
|
||||
<description xml:lang="ko"><![CDATA[그래프의 꺽인 포인트 부분의 점 색을 지정할 수 있습니다.
|
||||
기본 : <span style="color:#ed3027">#ed3027</span>
|
||||
#과 6자리의 색상코드 입력해주세요]]></description>
|
||||
</var>
|
||||
</extra_vars>
|
||||
</widget>
|
||||
153
widgets/image_counter/image_counter.class.php
Normal file
153
widgets/image_counter/image_counter.class.php
Normal file
|
|
@ -0,0 +1,153 @@
|
|||
<?php
|
||||
/**
|
||||
* @class image_counter
|
||||
* @author zero (zero@nzeo.com)
|
||||
* @version 0.1
|
||||
* @brief counter 모듈의 데이터를 이용하여 counter 현황을 출력
|
||||
**/
|
||||
|
||||
class image_counter extends WidgetHandler {
|
||||
|
||||
/**
|
||||
* @brief 위젯의 실행 부분
|
||||
* ./widgets/위젯/conf/info.xml에 선언한 extra_vars를 args로 받는다
|
||||
* 결과를 만든후 print가 아니라 return 해주어야 한다
|
||||
**/
|
||||
function proc($args) {
|
||||
// 인자 값 정리
|
||||
$graph_width = (int)$args->graph_width?$args->graph_width:150;
|
||||
$graph_height = (int)$args->graph_height?$args->graph_height:100;
|
||||
$day_range = (int)$args->day_range?$args->day_range:7;
|
||||
if($day_range < 7) $day_range = 7;
|
||||
|
||||
$bg_color = hexrgb($args->bg_color?$args->bg_color:'#FFFFFF');
|
||||
$check_bg_color = hexrgb($args->check_bg_color?$args->check_bg_color:'#F9F9F9');
|
||||
$grid_color = hexrgb($args->grid_color?$args->grid_color:'#dbdbdb');
|
||||
$unique_line_color = hexrgb($args->unique_line_color?$args->unique_line_color:'#BBBBBB');
|
||||
$unique_text_color = hexrgb($args->unique_text_color?$args->unique_text_color:'#666666');
|
||||
$point_color = hexrgb($args->point_color?$args->point_color:'#ed3027');
|
||||
|
||||
// 시작일 부터 오늘까지 일단 배열 만들어 놓기
|
||||
$start_time = ztime(date("YmdHis"))-$day_range*60*60*24;
|
||||
$end_time = time();
|
||||
$day_check_falg = 0;
|
||||
for($i=$start_time;$i<$end_time;$i+= 60*60*24) {
|
||||
$data[date("Ymd", $i+60*60*24)] = 0;
|
||||
$day_check_falg++;
|
||||
if($day_check_falg>$day_range) break;
|
||||
}
|
||||
unset($obj);
|
||||
|
||||
// 현재부터 지난 $day_range동안의 카운터 로그를 가져옴
|
||||
$obj->e_regdate = date("Ymd");
|
||||
$obj->s_regdate = date("Ymd", ztime(date("YmdHis"))-$day_range*60*60*24+1);
|
||||
$output = executeQuery('widgets.image_counter.getCounterStatus', $obj);
|
||||
|
||||
// 결과가 있다면 loop를 돌면서 최고/최저값을 구하고 그래프를 그릴 준비
|
||||
$max_unique_visitor = 0;
|
||||
$min_unique_visitor = 99999999999;
|
||||
if(count($output->data)) {
|
||||
foreach($output->data as $key => $val) {
|
||||
if($max_unique_visitor < $val->unique_visitor) $max_unique_visitor = $val->unique_visitor;
|
||||
if($min_unique_visitor > $val->unique_visitor) $min_unique_visitor = $val->unique_visitor;
|
||||
$data[$val->regdate] = $val;
|
||||
}
|
||||
}
|
||||
|
||||
// 이미지를 그림 (이미지 위치는 ./files/cache/widget_cache/couter_graph.gif로 고정)
|
||||
$image_src = "files/cache/widget_cache/couter_graph.gif";
|
||||
|
||||
// 이미지 생성
|
||||
$image = imagecreate($graph_width, $graph_height);
|
||||
|
||||
// 각 종류의 색상을 지정
|
||||
$gridLine = imagecolorallocate($image, $grid_color['red'], $grid_color['green'], $grid_color['blue']);
|
||||
$fillBack = imagecolorallocate($image, $bg_color['red'], $bg_color['green'], $bg_color['blue']);
|
||||
$checkFillBack = imagecolorallocate($image, $check_bg_color['red'], $check_bg_color['green'], $check_bg_color['blue']);
|
||||
$visitorLine = imagecolorallocate($image, $unique_line_color['red'], $unique_line_color['green'], $unique_line_color['blue']);
|
||||
$visitorText = imagecolorallocate($image, $unique_text_color['red'], $unique_text_color['green'], $unique_text_color['blue']);
|
||||
$pointColor = imagecolorallocate($image, $point_color['red'], $point_color['green'], $point_color['blue']);
|
||||
|
||||
// 배경선 채우기
|
||||
imagefilledrectangle($image, 0, 0, $graph_width-1, $graph_height-1, $fillBack);
|
||||
|
||||
// 가로선 그리기
|
||||
$y_gap = ($graph_height - 32) /3;
|
||||
for($i=0;$i<4;$i++) {
|
||||
imageline($image, 5, 5+($i*$y_gap), $graph_width-5, 5+($i*$y_gap), $gridLine);
|
||||
}
|
||||
|
||||
// 세로선 그리기
|
||||
$x_gap = ($graph_width - 30) / ($day_range-1);
|
||||
for($i=0;$i<$day_range;$i++) {
|
||||
imageline($image, 15+($i*$x_gap), 5, 15+($i*$x_gap), $graph_height - 27, $gridLine);
|
||||
}
|
||||
|
||||
// 체크 무늬 배경 칠하기
|
||||
for($j=0;$j<$day_range-1;$j++) {
|
||||
for($i=0;$i<3;$i++) {
|
||||
if( ($j+$i)%2==1) continue;
|
||||
imagefilledrectangle($image, 15+($j*$x_gap)+1, 5+($i*$y_gap)+1, 15+($j*$x_gap)+$x_gap-1, 5+($i*$y_gap)+$y_gap-1, $checkFillBack);
|
||||
}
|
||||
}
|
||||
|
||||
// 그래프 그리기
|
||||
$prev_x = $prev_y = 0;
|
||||
$step = 0;
|
||||
|
||||
// 선 그림
|
||||
foreach($data as $date => $val) {
|
||||
// 그래프를 그리기 위한 좌표 구함
|
||||
$unique_visitor = $val->unique_visitor;
|
||||
if($max_unique_visitor == 0) $per = 0;
|
||||
else $per = ($val->unique_visitor-$min_unique_visitor) / ($max_unique_visitor-$min_unique_visitor);
|
||||
|
||||
// x,y 좌표 구함
|
||||
$cur_x = (int)($step * $x_gap);
|
||||
$cur_y = (int)( ($graph_height-55) - ($graph_height-55)*$per);
|
||||
|
||||
imageline($image, $prev_x+15, $prev_y+15, $cur_x+15, $cur_y+15, $visitorLine);
|
||||
|
||||
$prev_x = $cur_x;
|
||||
$prev_y = $cur_y;
|
||||
|
||||
$step ++;
|
||||
}
|
||||
|
||||
// 포인트 + 숫자 표시
|
||||
$prev_x = $prev_y = 0;
|
||||
$step = 0;
|
||||
foreach($data as $date => $val) {
|
||||
// 그래프를 그리기 위한 좌표 구함
|
||||
$unique_visitor = $val->unique_visitor;
|
||||
if($max_unique_visitor == 0) $per = 0;
|
||||
else $per = ($val->unique_visitor-$min_unique_visitor) / ($max_unique_visitor-$min_unique_visitor);
|
||||
|
||||
// x,y 좌표 구함
|
||||
$cur_x = (int)($step * $x_gap);
|
||||
$cur_y = (int)( ($graph_height-55) - ($graph_height-55)*$per);
|
||||
|
||||
imagefilledrectangle($image, $cur_x+15-1, $cur_y+15-1, $cur_x+15+1, $cur_y+15+1, $pointColor);
|
||||
|
||||
for($j=0;$j<strlen($unique_visitor);$j++) {
|
||||
imageString($image, 1, $cur_x+6+$j*4, $cur_y+5 + ($step%2-1)*13+13, substr($unique_visitor,$j,1), $visitorText);
|
||||
}
|
||||
|
||||
$prev_x = $cur_x;
|
||||
$prev_y = $cur_y;
|
||||
|
||||
imageString($image, 1, $cur_x+15-1, $graph_height - 25, substr($date,6,2), $gridLine);
|
||||
|
||||
$step ++;
|
||||
}
|
||||
|
||||
imageString($image, 1, $graph_width - 100, $graph_height - 15, date("Y-m-d H:i:s"), $gridLine);
|
||||
|
||||
// 이미지 저장
|
||||
@imagegif($image, $image_src, 100);
|
||||
|
||||
// graph의 img 태그 값을 return
|
||||
return sprintf('<img src="%s%s" border="0" alt="counter" />', Context::getRequestUri(), $image_src);
|
||||
}
|
||||
}
|
||||
?>
|
||||
12
widgets/image_counter/queries/getCounterStatus.xml
Normal file
12
widgets/image_counter/queries/getCounterStatus.xml
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
<query id="getCounterStatus" action="select">
|
||||
<tables>
|
||||
<table name="counter_status" />
|
||||
</tables>
|
||||
<columns>
|
||||
<column name="*" />
|
||||
</columns>
|
||||
<conditions>
|
||||
<condition operation="excess" column="regdate" var="s_regdate" notnull="notnull" />
|
||||
<condition operation="less" column="regdate" var="e_regdate" notnull="notnull" pipe="and" />
|
||||
</conditions>
|
||||
</query>
|
||||
Loading…
Add table
Add a link
Reference in a new issue