티스토리 뷰

xe 위젯 개념은 살펴봤으니 실제 xe 코어 다운로드 받으면 기본적으로 들어 있는 xe 카운터 위젯을 뜯어보겠다.


xe 코어 다운시 들어 있는 위젯중에 가장 심플한거라 선택해봤다.


먼저 info.xml 이 있으나 정보 부분이라 넘어가고.. 단 info.xml 에는 아래와 같은 description이 있다.


    <description xml:lang="ko">

        기본 카운터를 이용하여 전체, 어제, 오늘의 접속현황을 표시합니다.

        counter 모듈이 설치되어 있어야 하고 counter 애드온이 켜져 있어야 합니다.

    </description>


counter_status.class.php 를 열어보면

<?php

/* Copyright (C) NAVER <http://www.navercorp.com> */

/**

 * @class counter_status

 * @author NAVER (developers@xpressengine.com)

 * @version 0.1

 * @brief Display counter status by using data in the counter module

 */

class counter_status extends WidgetHandler

{

/**

* @brief Widget execution

* Get extra_vars declared in ./widgets/widget/conf/info.xml as arguments

* After generating the result, do not print but return it.

*/

function proc($args)

{

// Get status of the accumulated, yesterday's, today's counts

$oCounterModel = getModel('counter');


$site_module_info = Context::get('site_module_info');

$output = $oCounterModel->getStatus(array('00000000', date('Ymd', $_SERVER['REQUEST_TIME']-60*60*24), date('Ymd')), $site_module_info->site_srl);

if(count($output))

{

foreach($output as $key => $val) 

{

if(!$key) Context::set('total_counter', $val);

elseif($key == date("Ymd")) Context::set('today_counter', $val);

else Context::set('yesterday_counter', $val);

}

}

// Set a path of the template skin (values of skin, colorset settings)

$tpl_path = sprintf('%sskins/%s', $this->widget_path, $args->skin);

Context::set('colorset', $args->colorset);

// Specify a template file

$tpl_file = 'counter_status';

// Compile a template

$oTemplate = &TemplateHandler::getInstance();

return $oTemplate->compile($tpl_path, $tpl_file);

}

}

/* End of file counter_status.class.php */

/* Location: ./widgets/counter_status/counter_status.class.php */



주석이 영어로 되어 있어 다소 복잡해 보일 수도 있지만 시간을 가지고 천천히 보면 간단하다.

여기서 Context::set 해서 세팅한 데이터를 html파일에서 사용한다. 


counter_status.html

<load target="./css/widget.css" />
<div class="widgetContainer<!--@if($colorset=="black")--> black<!--@end-->">
    <dl class="widgetCounter">
        <dt>{$lang->today}:</dt>
        <dd>{number_format($today_counter->unique_visitor)}</dd>
        <dt>{$lang->yesterday}:</dt>
        <dd>{number_format($yesterday_counter->unique_visitor)}</dd>
        <dt>{$lang->total}:</dt>
        <dd>{number_format($total_counter->unique_visitor)}</dd>
    </dl>
</div>


즉 counter_status.class.php 에서 Context::set('total_counter', $val); 이렇게 세팅하면 counter_status.html 파일에서 $today_counter->unique_visitor 이런식으로 사용이 가능하다. 


이렇게 위젯을 만들고 결과를 보면 아래와 같다.


오늘:
1
어제:
0
전체:
1


댓글
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
«   2024/05   »
1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30 31
글 보관함