dev.stuconnolly.com / svn / sites

  1. <?php
  2.  
  3. /*
  4.  *  $Id: s.php 132 2011-09-28 16:06:09Z stuart $
  5.  *  
  6.  *  spbug.com
  7.  *  Sequel Pro URL Shortening Service
  8.  *
  9.  *  Copyright (c) 2010 Stuart Connolly. All rights reserved.
  10.  *
  11.  *  This program is free software: you can redistribute it and/or modify
  12.  *  it under the terms of the GNU General Public License as published by
  13.  *  the Free Software Foundation, either version 3 of the License, or
  14.  *  (at your option) any later version.
  15.  *
  16.  *  This program is distributed in the hope that it will be useful,
  17.  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
  18.  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  19.  *  GNU General Public License for more details.
  20.  *
  21.  *  You should have received a copy of the GNU General Public License
  22.  *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
  23.  */
  24.  
  25. $title = 'Stats';
  26.  
  27. // General
  28. $total  = DB::get_var('SELECT COUNT(1) FROM redirect_log');
  29. $year   = DB::get_var('SELECT COUNT(1) FROM redirect_log WHERE YEAR(redirect_date) = YEAR(CURRENT_DATE())');
  30. $month  = DB::get_var('SELECT COUNT(1) FROM redirect_log WHERE MONTH(redirect_date) = MONTH(CURRENT_DATE())');
  31. $day    = DB::get_var('SELECT COUNT(1) FROM redirect_log WHERE DATE(redirect_date) = CURRENT_DATE()');
  32. $hour   = DB::get_var("SELECT COUNT(1) FROM redirect_log WHERE redirect_date >= DATE_SUB(UTC_TIMESTAMP(), INTERVAL 1 HOUR)");
  33.  
  34. // Rule based
  35. $rule_stats = DB::get_results(
  36.     "SELECT u.url_name, COUNT(1) AS 'hit_count'
  37.      FROM   redirect_log l, redirect_urls u
  38.      WHERE  l.redirect_url_id = u.url_id
  39.      GROUP BY u.url_name"
  40. );
  41.  
  42. // Build array of stats
  43. $stats = array((object)array('name' => 'Total Redirects',      'hits' => $total),
  44.                (object)array('name' => 'Redirects This Year',  'hits' => $year),
  45.                (object)array('name' => 'Redirects This Month', 'hits' => $month),
  46.                (object)array('name' => 'Redirects Today',      'hits' => $day),
  47.                (object)array('name' => 'Redirects This Hour',  'hits' => $hour));
  48.  
  49. require_once('header.php'); ?>
  50.  
  51.     <h1><?php echo $_SERVER['HTTP_HOST']; ?> Stats</h1>
  52.    
  53.     <p>URL redirect statistics.</p>
  54.    
  55.     <h2>General Stats</h2>
  56.    
  57.     <table class="stattable">
  58.         <thead>
  59.             <tr>
  60.                 <th>Stat</th>
  61.                 <th class="center">Hits</th>
  62.             </tr>
  63.         </thead>
  64.        
  65.         <tbody>
  66.             <?php foreach ($stats as $stat) : ?>
  67.            
  68.             <tr>
  69.                 <td><?php echo $stat->name; ?></td>
  70.                 <td class="center"><?php echo $stat->hits; ?></td>
  71.             </tr>
  72.            
  73.             <?php endforeach; ?>
  74.         </tbody>
  75.     </table>
  76.    
  77.     <h2>Rule-Based Stats</h2>
  78.    
  79.     <?php if (count($rule_stats)) : ?>
  80.    
  81.     <table class="stattable">
  82.         <thead>
  83.             <tr>
  84.                 <th>Redirect Rule</th>
  85.                 <th class="center">Hits</th>
  86.             </tr>
  87.         </thead>
  88.        
  89.         <tbody>
  90.             <?php foreach ($rule_stats as $rule) : ?>
  91.            
  92.             <tr>
  93.                 <td><?php echo $rule->url_name; ?></td>
  94.                 <td class="center"><?php echo $rule->hit_count; ?></td>
  95.             </tr>
  96.            
  97.             <?php endforeach; ?>
  98.         </tbody>
  99.     </table>
  100.    
  101.     <?php else : ?>
  102.         <p><em>No rule-based statistics to display.</em></p>
  103.     <?php endif; ?>
  104.    
  105. <?php require_once('footer.php'); ?>