글검색결과 [방문자] : 1

  1. 2007/03/22 방문자 기록 > 시간별 방문자 수 추가...





적용 버전 : Tattertools 1.1.2.X : Animato


1. "시간별 방문자 수" 테이블 생성

CREATE TABLE `tt_TimeStatistics` (
  `owner` int(11) NOT NULL default '0',
  `datetime` int(10) NOT NULL default '0',
  `visits` int(11) NOT NULL default '0',
  PRIMARY KEY  (`owner`,`datetime`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;



2. 함수(getTimeStatistics) 추가

수정 대상 파일 : tt\components\Tattertools.Model.Statistics.php


######Line 25    아래 함수 추가

 function getTimeStatistics($period) {
  global $database, $owner;
  return DBQuery::queryAll("SELECT datetime, visits FROM {$database['prefix']}TimeStatistics WHERE owner = $owner AND LEFT(datetime, 8) = $period ORDER BY datetime DESC");
 }



3. 해당 파일에 코드 추가

  - 코드 추가 예제
     예제 수정 대상 파일 : tt\blog\index.php


######Line 1155   updateVisitorStatistics 함수 내에 코드 추가

function updateVisitorStatistics($owner){
 global $database,$blogURL;
    ..................................................................
    ..................................................................
    ..................................................................
  $period=Timestamp::getDate();
  DBQuery::query("update {$database['prefix']}DailyStatistics set visits = visits + 1 where owner = $owner and `date` = $period");
  if(mysql_affected_rows()==0){
   if(!DBQuery::query("insert into {$database['prefix']}DailyStatistics values($owner, $period, 1)")||(mysql_affected_rows()==0))
    DBQuery::query("update {$database['prefix']}DailyStatistics set visits = visits + 1 where owner = $owner and `date` = $period");
  }
  $period2=date('YmdH');
  DBQuery::query("update tt_TimeStatistics set visits = visits + 1 where owner = $owner and `datetime` = $period2");
  if(mysql_affected_rows()==0){
   if(!DBQuery::query("insert into tt_TimeStatistics values($owner, $period2, 1)")||(mysql_affected_rows()==0))
    DBQuery::query("update tt_TimeStatistics set visits = visits + 1 where owner = $owner and `datetime` = $period2");
  }

  if(!empty($_SERVER['HTTP_REFERER'])){
   $referer=parse_url($_SERVER['HTTP_REFERER']);
    ..................................................................
    ..................................................................
    ..................................................................
}

※ 태터툴즈 기본팩 및 확장팩 사용자
해당 파일(17개)의 updateVisitorStatistics 함수 내에 위와 같이 코드 추가

tt\blog\archive\index.php
tt\blog\archive\item.php
tt\blog\category\index.php
tt\blog\entry\index.php
tt\blog\guestbook\index.php
tt\blog\index.php
tt\blog\item.php
tt\blog\keylog\index.php
tt\blog\location\index.php
tt\blog\notice\index.php
tt\blog\notice\item.php
tt\blog\owner\entry\preview\item.php
tt\blog\owner\skin\preview\index.php
tt\blog\page\index.php
tt\blog\page\item.php
tt\blog\search\index.php
tt\blog\tag\index.php

※ 태터툴즈 소스 사용자
tt\lib\model\blog.statistics.php




4. "관리자 메뉴 > 플러그인 > 방문자 기록" 페이지 수정

수정 대상 파일 : tt\plugins\PN_Visitor_Default\index.php

######Line 28     $pluginURL 추가
 global $owner, $pluginMenuURL, $pluginAccessURL, $pluginHandlerURL, $pluginURL;


######Line 125 ~ 140    이하 코드로 수정

if (strlen($date) == 8) {
   if ($date == date('Ymd', strtotime("now"))) $date2 = date('Ym', strtotime("now"));
   else $date2 = substr($date, 0, 6);
}
else $date2 = $date;
if (isset($date2)) {
  $temp = Statistics::getDailyStatistics($date2);
  for ($i=0; $i<sizeof($temp); $i++) {
    $record = $temp[$i];
   
    $className = ($i % 2) == 1 ? 'even-line' : 'odd-line';
    $className .= ($i == sizeof($temp) - 1) ? ' last-line' : '';
    if (strlen($date) == 6) if ($record['date'] == $date.date("t", mktime(1,1,1,substr($date,4,2),1,substr($date,0,4)))) $sum2 = $record['visits'];
    if (strlen($date) == 8) if ($record['date'] == $date) $sum2 = $record['visits'];
    if ($i == 0) $firstday = $record['date'];
?>
                    <tr class="<?php echo $className;?> inactive-class" onmouseover="rolloverClass(this, 'over')" onmouseout="rolloverClass(this, 'out')" onclick="window.location.href='<?php echo $pluginMenuURL;?>&amp;date=<?php echo $record['date'];?>'">
                      <td class="date"><a href="<?php echo $pluginMenuURL;?>&amp;date=<?php echo $record['date'];?>"><?php echo Timestamp::formatDate(misc::getTimeFromPeriod($record['date']));?></a></td>
                      <td class="count"><?php echo $record['visits'];?></td>
                    </tr>
<?php
  }
}
?>
                  </tbody>
                </table>
               
                <hr class="hidden" />
<?php
unset($strtoday);
if (strlen($date) == 6) {
  if($date != date('Ym', strtotime("now"))) $strtoday = "&nbsp;&nbsp;[".Timestamp::formatDate(misc::getTimeFromPeriod($date.date("t", mktime(1,1,1,substr($date,4,2),1,substr($date,0,4)))))."]";
  if ($firstday != date('Ymd', strtotime("now")))  $strtoday = "&nbsp;&nbsp;[".Timestamp::formatDate(misc::getTimeFromPeriod($firstday))."]";
}
if(strlen($date) == 8 && $date != date('Ymd', strtotime("now"))) $strtoday = "&nbsp;&nbsp;[".Timestamp::formatDate(misc::getTimeFromPeriod($date))."]";
?>
                <table id="statistics-day-inbox" class="data-inbox" cellspacing="0" cellpadding="0">
                  <thead>
                    <tr>
                      <th colspan="2"><span class="text">시간별 방문자 수<?php echo $strtoday;?></span>
                      </th>
                    </tr>
                  </thead>
                  <tbody>
<?php
if (strlen($date) == 6) {
  if ($date == date('Ym', strtotime("now"))) {
      if ($firstday == date('Ymd', strtotime("now"))) $date2 = date('Ymd', strtotime("now"));
      else  $date2 = $firstday;
  }
  else $date2 = $date.date("t", mktime(1,1,1,substr($date,4,2),1,substr($date,0,4)));
}
else $date2 = $date;
$sum = 0; $avg = 0;
$barimg = $pluginURL."/images/bar.gif";
if (isset($date2)) {
  $temp = Statistics::getTimeStatistics($date2);
  for ($i=0; $i<sizeof($temp); $i++) {
    $record = $temp[$i];
   
    $className = ($i % 2) == 1 ? 'even-line' : 'odd-line';
    $className .= ($i == sizeof($temp) - 1) ? ' last-line' : '';

    $sum = $sum + $record['visits'];
    // 시간당 방문자수가 100 이상일 경우 아래 숫자를 적절히 수정 (예. 100 -> 500)
    $width = ((int)$record['visits']/100) * 100;
?>
                    <tr class="<?php echo $className;?> inactive-class">
                      <td class="date"><?php echo sprintf("%02d", substr($record['datetime'], 8, 2));?></td>
                      <td class="count">
                        <img src='<?php echo $barimg;?>' height='10' width='<?=$width?>'>
                        <?php echo $record['visits'];?>
                        </td>
                    </tr>
<?php
  }
  $avg = (int)($sum/$i);
  if (!$avg) $avg = (int)($sum2/24);
}
?>
                    <tr class="even-line last-line inactive-class">
                      <td class="date">평균</td>
                      <td class="count">
                        <img src='http://kkal3.net/image/grp1.gif' height='10' width='<?=$avg?>'>
                        <?php echo $avg;?>
                        </td>
                    </tr>




5. 그래프용 이미지 파일 복사

그래프용 이미지 파일 : bar.gif        <- 다른 이름으로 저장, 파일 이름 bar.gif로 저장
이미지 파일 저장 디렉토리 (images 디렉토리 추가 생성) : tt/plugins/PN_Visitor_Default/images/




크리에이티브 커먼즈 라이센스
Creative Commons License
이올린에 북마크하기(0) 이올린에 추천하기(0)
2007/03/22 23:38 2007/03/22 23:38
[로그인][오픈아이디란?]
 이전  1   다음