b2evolution

Multilingual multiuser multiblog engine

b2evolution Technical Documentation (0.9.x) [ class tree: admin ] [ index: admin ] [ all elements ]

Source for file b2stats.php

Documentation is available at b2stats.php

  1. <?php
  2. /**
  3.  * This displays the stats.
  4.  *
  5.  * b2evolution - {@link http://b2evolution.net/}
  6.  * Released under GNU GPL License - {@link http://b2evolution.net/about/license.html}
  7.  * @copyright (c)2003-2005 by Francois PLANQUE - {@link http://fplanque.net/}
  8.  *
  9.  * @package admin
  10.  */
  11.  
  12. /**
  13.  * Includes:
  14.  */
  15. require_oncedirname(__FILE__).'/_header.php' );
  16. $admin_tab 'stats';
  17. $admin_pagetitle T_('View Stats for Blog:');
  18.  
  19. param'action''string' );
  20. param'show''string''referers' );
  21.  
  22. require(dirname(__FILE__'/_menutop.php');
  23. ?>
  24. <a href="b2stats.php?show=<?php echo $show ?>&amp;blog=0" class="<?php echo == $blog 'CurrentBlog' 'OtherBlog' ?>"><?php echo T_('None'?></a>
  25. <?php
  26. for$curr_blog_ID=blog_list_start('stub');
  27.             $curr_blog_ID!=false;
  28.              $curr_blog_ID=blog_list_next('stub') )
  29.     {
  30.         ?>
  31.         <a href="b2stats.php?show=<?php echo $show ?>&amp;blog=<?php echo $curr_blog_ID ?>" class="<?php echo $curr_blog_ID == $blog 'CurrentBlog' 'OtherBlog' ?>"><?php blog_list_iteminfo('shortname'?></a>
  32.     <?php
  33. }
  34. requiredirname(__FILE__'/_menutop_end.php' );
  35.  
  36. // Check permission:
  37. $current_User->check_perm'stats''view'true );
  38.  
  39. switch$action )
  40. {
  41.     case 'changetype':
  42.         // Change the type of a hit:
  43.  
  44.         // Check permission:
  45.         $current_User->check_perm'stats''edit'true );
  46.  
  47.         param'hit_ID''integer'true );    // Required!
  48.         param'hit_type''string'true );    // Required!
  49.         ?>
  50.         <div class="panelinfo">
  51.             <p><?php printfT_('Changing hit #%d type to: %s')$hit_ID$hit_type?></p>
  52.             <?php
  53.             hit_change_type$hit_ID$hit_type );
  54.             ?>
  55.         </div>
  56.         <?php
  57.         break;
  58.  
  59.     case 'delete':
  60.         // DELETE A HIT:
  61.  
  62.         // Check permission:
  63.         $current_User->check_perm'stats''edit'true );
  64.  
  65.         param'hit_ID''integer'true );    // Required!
  66.         ?>
  67.         <div class="panelinfo">
  68.             <p><?php printfT_('Deleting hit #%d...')$hit_ID )?></p>
  69.             <?php
  70.             hit_delete$hit_ID );
  71.             ?>
  72.         </div>
  73.         <?php
  74.         break;
  75.  
  76.     case 'prune':
  77.         // PRUNE hits for a certain date
  78.  
  79.         // Check permission:
  80.         $current_User->check_perm'stats''edit'true );
  81.  
  82.         param'date''integer'true );    // Required!
  83.         ?>
  84.         <div class="panelinfo">
  85.             <p><?php printfT_('Pruning hits for %s...')datelocale_datefmt()$date) ) ?></p>
  86.             <?php
  87.             hit_prune$date );
  88.             ?>
  89.         </div>
  90.         <?php
  91.         break;
  92. }
  93. ?>
  94.  
  95. <ul class="hack">
  96.     <li><!-- Yes, this empty UL is needed! It's a DOUBLE hack for correct CSS display --></li>
  97. </ul>
  98. <div class="pt">
  99.     <div class="panelblocktabs">
  100.         <ul class="tabs">
  101.         <?php
  102.         if$show == 'summary' )
  103.                 echo '<li class="current">';
  104.             else
  105.                 echo '<li>';
  106.         echo '<a href="b2stats.php?show=summary&amp;blog='$blog'">'T_('Summary')'</a></li>';
  107.  
  108.         if$show == 'referers' )
  109.             echo '<li class="current">';
  110.         else
  111.             echo '<li>';
  112.         echo '<a href="b2stats.php?show=referers&amp;blog='$blog'">'T_('Referers')'</a></li>';
  113.  
  114.         if$show == 'refsearches' )
  115.             echo '<li class="current">';
  116.         else
  117.             echo '<li>';
  118.         echo '<a href="b2stats.php?show=refsearches&amp;blog='$blog'">'T_('Refering Searches')'</a></li>';
  119.  
  120.         if$show == 'syndication' )
  121.             echo '<li class="current">';
  122.         else
  123.             echo '<li>';
  124.         echo '<a href="b2stats.php?show=syndication&amp;blog='$blog'">'T_('Syndication')'</a></li>';
  125.  
  126.         if$show == 'useragents' )
  127.             echo '<li class="current">';
  128.         else
  129.             echo '<li>';
  130.         echo '<a href="b2stats.php?show=useragents&amp;blog='$blog'">'T_('User Agents')'</a></li>';
  131.  
  132.         if$show == 'other' )
  133.             echo '<li class="current">';
  134.         else
  135.             echo '<li>';
  136.         echo '<a href="b2stats.php?show=other&amp;blog='$blog'">'T_('Direct Accesses')'</a></li>';
  137.  
  138.         ?>
  139.         </ul>
  140.     </div>
  141. </div>
  142. <div class="tabbedpanelblock">
  143. <?php
  144. switch$show )
  145. {
  146.     case 'summary':
  147.         ?>
  148.         <h2><?php echo T_('Summary'?>:</h2>
  149.         <?php
  150.         $sql "SELECT COUNT(*)AS hits, hit_ignore, YEAR(visitTime) AS year, MONTH(visitTime) AS month,
  151.                                         DAYOFMONTH(visitTime) AS day
  152.                             FROM $tablehitlog ";
  153.         if$blog )
  154.         {
  155.             $sql .= " WHERE hit_blog_ID = $blog ";
  156.         }
  157.         $sql .= 'GROUP BY YEAR(visitTime), MONTH(visitTime),  DAYOFMONTH(visitTime), hit_ignore
  158.                          ORDER BY YEAR(visitTime) DESC, MONTH(visitTime) DESC, DAYOFMONTH(visitTime) DESC';
  159.         $res_hits $DB->get_results$sqlARRAY_A );
  160.         
  161.         $hits array();
  162.         $hits['no'0;
  163.         $hits['invalid'0;
  164.         // $hits['badchar'] = 0;            // Not used any longer
  165.         // $hits['blacklist'] = 0;            // Not used any longer
  166.         $hits['rss'0;
  167.         $hits['robot'0;
  168.         $hits['search'0;
  169.         $last_date 0;
  170.     ifcount($res_hits) )
  171.   {    ?>
  172.     <table class="grouped" cellspacing="0">
  173.     <tr>
  174.           <th class="firstcol"><?php echo T_('Date'?></th>
  175.           <th><?php echo T_('Referers'// 'no' ?></th>
  176.           <th><?php echo T_('Refering Searches'?></th>
  177.           <th><?php echo T_('Indexing Robots'?></th>
  178.           <th><?php echo T_('Syndication'?></th>
  179.           <th><?php echo T_('Direct Accesses'?></th>
  180.           <th><?php echo T_('Total'?></th>
  181.     </tr>
  182.         <?php
  183.         $count 0;
  184.         foreach$res_hits as $row_stats )
  185.         {
  186.             $this_date mktime000$row_stats['month']$row_stats['day']$row_stats['year');
  187.             if$last_date == $last_date $this_date;    // that'll be the first one
  188.             if$last_date != $this_date )
  189.             {    // We just hit a new day, let's display the previous one:
  190.                 ?>
  191.                 <tr <?php if$count%== echo 'class="odd"'?>>
  192.                     <td class="firstcol"><?php if$current_User->check_perm'spamblacklist''edit' ) )
  193.                         ?>
  194.                             <a href="b2stats.php?action=prune&amp;date=<?php echo $last_date ?>&amp;show=summary&amp;blog=<?php echo $blog ?>" title="<?php echo T_('Prune this date!'?>"><img src="img/xross.gif" width="13" height="13" class="middle" alt="<?php echo /* TRANS: Abbrev. for Prune (stats) */ T_('Prune'?>"  title="<?php echo T_('Prune hits for this date!'?>" /></a>
  195.                         <?php
  196.                         }
  197.                         echo datelocale_datefmt()$last_date ?>
  198.                     </td>
  199.                     <td class="right"><?php echo $hits['no'?></td>
  200.                     <td class="right"><?php echo $hits['search'?></td>
  201.                     <td class="right"><?php echo $hits['robot'?></td>
  202.                     <td class="right"><?php echo $hits['rss'?></td>
  203.                     <td class="right"><?php echo $hits['invalid'?></td>
  204.                     <td class="right"><?php echo array_sum($hits?></td>
  205.                 </tr>
  206.                 <?php
  207.                     $hits['no'0;
  208.                     $hits['invalid'0;
  209.                     $hits['rss'0;
  210.                     $hits['robot'0;
  211.                     $hits['search'0;
  212.                     $last_date $this_date;    // that'll be the next one
  213.                     $count ++;
  214.             }
  215.             $hits[$row_stats['hit_ignore']] $row_stats['hits'];
  216.         }
  217.  
  218.         if$last_date != )
  219.         {    // We had a day pending:
  220.             ?>
  221.             <tr <?php if$count%== echo 'class="odd"'?>>
  222.                 <td class="firstcol"><?php if$current_User->check_perm'stats''edit' ) )
  223.                     ?>
  224.                     <a href="b2stats.php?action=prune&amp;date=<?php echo $this_date ?>&amp;show=summary&amp;blog=<?php echo $blog ?>" title="<?php echo T_('Prune hits for this date!'?>"><img src="img/xross.gif" width="13" height="13" class="middle" alt="<?php echo /* TRANS: Abbrev. for Prune (stats) */ T_('Prune'?>"  title="<?php echo T_('Prune hits for this date!'?>" /></a>
  225.                     <?php
  226.                     }
  227.                     echo datelocale_datefmt()$this_date ?>
  228.                 </td>
  229.                 <td class="right"><?php echo $hits['no'?></td>
  230.                 <td class="right"><?php echo $hits['search'?></td>
  231.                 <td class="right"><?php echo $hits['robot'?></td>
  232.                 <td class="right"><?php echo $hits['rss'?></td>
  233.                 <td class="right"><?php echo $hits['invalid'?></td>
  234.                 <td class="right"><?php echo array_sum($hits?></td>
  235.             </tr>
  236.         <?php ?>
  237.         </table>
  238.     <?php
  239.     }
  240.         break;
  241.  
  242.         case 'referers':
  243.         ?>
  244.     <h2><?php echo T_('Last referers'?>:</h2>
  245.     <p><?php echo T_('These are hits from external web pages refering to this blog'?>.</p>
  246.     <?php refererList(40,'global',1,1,'no','',$blog);
  247.   ifcount$res_stats ) )
  248.   ?>
  249.     <table class="grouped" cellspacing="0">
  250.         <?php
  251.         $count 0;
  252.         foreach$res_stats as $row_stats ?>
  253.         <tr <?php if$count%== echo 'class="odd"'?>>
  254.             <td class="firstcol"><?php stats_time(?></td>
  255.             <td>
  256.                 <?php if$current_User->check_perm'stats''edit' ) )
  257.                     ?>
  258.                     <a href="b2stats.php?action=delete&amp;hit_ID=<?php stats_hit_ID(?>&amp;show=referers&amp;blog=<?php echo $blog ?>" title="<?php echo T_('Delete this hit!'?>"><img src="img/xross.gif" width="13" height="13" class="middle" alt="<?php echo /* TRANS: Abbrev. for Delete (stats) */ T_('Del'?>" title="<?php echo T_('Delete this hit!'?>" /></a>
  259.                 <a href="b2stats.php?action=changetype&amp;hit_type=search&amp;hit_ID=<?php stats_hit_ID(?>&amp;show=referers&amp;blog=<?php echo $blog ?>" title="<?php echo T_('Log as a search instead'?>"><img src="img/magnifier.png" width="14" height="13" class="middle" alt="<?php echo /* TRANS: Abbrev. for "move to searches" (stats) */ T_('-&gt;S'?>" title="<?php echo T_('Log as a search instead'?>" /></a>
  260.                 <?php ?>
  261.                 <a href="<?php stats_referer(?>"><?php stats_basedomain(?></a>
  262.             </td>
  263.             <?php if$current_User->check_perm'spamblacklist''edit' ) )
  264.             ?>
  265.             <td><a href="b2antispam.php?action=ban&amp;keyword=<?php echo urlencodestats_basedomain(false) ) ?>" title="<?php echo T_('Ban this domain!'?>"><img src="img/noicon.gif" class="middle" alt="<?php echo /* TRANS: Abbrev. */ T_('Ban'?>" title="<?php echo T_('Ban this domain!'?>" /></a></td>
  266.             <?php ?>
  267.             <td><?php stats_blog_name(?></td>
  268.             <td><a href="<?php stats_req_URI(?>"><?php stats_req_URI(?></a></td>
  269.         </tr>
  270.         <?php
  271.         $count++;
  272.         // End stat loop ?>
  273.     </table>
  274.   <?php ?>
  275.  
  276.     <h3><?php echo T_('Top referers'?>:</h3>
  277.     <?php refererList(30,'global',0,0,"'no'",'baseDomain',$blog,true);
  278.   ifcount$res_stats ) )
  279.   ?>
  280.     <table class="grouped" cellspacing="0">
  281.         <?php
  282.             $count 0;
  283.             foreach$res_stats as $row_stats ?>
  284.             <tr <?php if$count%== echo 'class="odd"'?>>
  285.                 <td class="firstcol"><a href="<?php stats_referer(?>"><?php stats_basedomain(?></a></td>
  286.                 <?php if$current_User->check_perm'spamblacklist''edit' ) )
  287.                 ?>
  288.                 <td><a href="b2antispam.php?action=ban&amp;keyword=<?php echo urlencodestats_basedomain(false) ) ?>" title="<?php echo T_('Ban this domain!'?>"><img src="img/noicon.gif" class="middle" alt="<?php echo /* TRANS: Abbrev. */ T_('Ban'?>" title="<?php echo T_('Ban this domain!'?>" /></a></td>
  289.                 <?php ?>
  290.                 <td class="right"><?php stats_hit_count(?></td>
  291.                 <td class="right"><?php stats_hit_percent(?></td>
  292.             </tr>
  293.         <?php
  294.         $count++;
  295.         // End stat loop ?>
  296.     </table>
  297.   <?php ?>
  298.     <p><?php echo T_('Total referers'?><?php stats_total_hit_count(?></p>
  299.  
  300.   <?php
  301.         break;
  302.  
  303.         case 'refsearches':
  304.             ?>
  305.     <h2><?php echo T_('Last refering searches'?>:</h2>
  306.     <p><?php echo T_('These are hits from people who came to this blog system through a search engine. (Search engines must be listed in /conf/_stats.php)'?></p>
  307.     <?php refererList(20,'global',1,1,"'search'",'',$blog);
  308.   ifcount$res_stats ) )
  309.   ?>
  310.     <table class="grouped" cellspacing="0">
  311.         <?php
  312.         $count 0;
  313.         foreach$res_stats as $row_stats ?>
  314.         <tr <?php if$count%== echo 'class="odd"'?>>
  315.             <td class="firstcol"><?php stats_time(?></td>
  316.             <td>
  317.                 <?php if$current_User->check_perm'stats''edit' ) )
  318.                 ?>
  319.                 <a href="b2stats.php?action=delete&amp;hit_ID=<?php stats_hit_ID(?>&amp;show=refsearches&amp;blog=<?php echo $blog ?>" title="<?php echo T_('Delete this hit!'?>"><img src="img/xross.gif" width="13" height="13" class="middle" alt="<?php echo /* TRANS: Abbrev. for Delete (stats) */ T_('Del'?>" /></a>
  320.                 <?php
  321.                 }
  322.                 stats_basedomain(?></td>
  323.             <td><a href="<?php stats_referer(?>"><?php stats_search_keywords(?></a></td>
  324.             <td><?php stats_blog_name(?></td>
  325.             <td><a href="<?php stats_req_URI(?>"><?php stats_req_URI(?></a></td>
  326.         </tr>
  327.         <?php
  328.         $count++;
  329.         // End stat loop ?>
  330.     </table>
  331.   <?php ?>
  332.  
  333.     <h3><?php echo T_('Top refering search engines'?>:</h3>
  334.     <?php refererList(20,'global',0,0,"'search'",'baseDomain',$blog,true);
  335.   ifcount$res_stats ) )
  336.   ?>
  337.     <table class="grouped" cellspacing="0">
  338.         <?php
  339.         $count 0;
  340.         foreach$res_stats as $row_stats ?>
  341.             <tr <?php if$count%== echo 'class="odd"'?>>
  342.                 <td class="firstcol"><a href="<?php stats_referer(?>"><?php stats_basedomain(?></a></td>
  343.                 <td class="right"><?php stats_hit_count(?></td>
  344.                 <td class="right"><?php stats_hit_percent(?></td>
  345.             </tr>
  346.         <?php
  347.         $count++;
  348.         // End stat loop ?>
  349.     </table>
  350.   <?php ?>
  351.  
  352.     <h3><?php echo T_('Top Indexing Robots'?>:</h3>
  353.     <p><?php echo T_('These are hits from automated robots like search engines\' indexing robots. (Robots must be listed in /conf/_stats.php)'?></p>
  354.     <?php refererList(20,'global',0,0,"'robot'",'hit_user_agent',$blog,true,true);
  355.   ifcount$res_stats ) )
  356.   ?>
  357.     <table class="grouped" cellspacing="0">
  358.         <?php
  359.         $count 0;
  360.         foreach$res_stats as $row_stats ?>
  361.             <tr>
  362.                 <td class="firstcol"><?php stats_referer('<a href="''">'?><?php stats_user_agenttrue ?><?php stats_referer('''</a>'false?></td>
  363.                 <td class="right"><?php stats_hit_count(?></td>
  364.                 <td class="right"><?php stats_hit_percent(?></td>
  365.             </tr>
  366.         <?php
  367.         $count++;
  368.         // End stat loop ?>
  369.     </table>
  370.   <?php
  371.   }
  372.         break;
  373.  
  374.         case 'syndication':
  375.             ?>
  376.     <h2><?php echo T_('Top Aggregators'?>:</h2>
  377.     <p><?php echo T_('These are hits from RSS news aggregators. (Aggregators must be listed in /conf/_stats.php)'?></p>
  378.     <?php refererList(40'global'00"'rss'"'hit_user_agent'$blogtruetrue);
  379.   ifcount$res_stats ) )
  380.   ?>
  381.     <table class="grouped" cellspacing="0">
  382.         <?php
  383.             $count 0;
  384.             foreach$res_stats as $row_stats ?>
  385.             <tr <?php if$count%== echo 'class="odd"'?>>
  386.                 <td class="firstcol"><?php stats_user_agenttrue ?></td>
  387.                 <td class="right"><?php stats_hit_count(?></td>
  388.                 <td class="right"><?php stats_hit_percent(?></td>
  389.             </tr>
  390.         <?php
  391.         $count++;
  392.         // End stat loop ?>
  393.     </table>
  394.   <?php ?>
  395.     <p><?php echo T_('Total RSS hits'?><?php stats_total_hit_count(?></p>
  396.  
  397.   <?php
  398.         break;
  399.  
  400.         case 'other':
  401.         ?>
  402.     <h2><?php echo T_('Last direct accesses'?>:</h2>
  403.     <p><?php echo T_('These are hits from people who came to this blog system by direct access (either by typing the URL directly, or using a bookmark. Invalid (too short) referers are also listed here.)'?></p>
  404.     <?php refererList(10,'global',1,1,"'invalid'",'',$blog);
  405.   ifcount$res_stats ) )
  406.   ?>
  407.     <table class="grouped" cellspacing="0">
  408.         <?php
  409.         $count 0;
  410.         foreach$res_stats as $row_stats ?>
  411.         <tr <?php if$count%== echo 'class="odd"'?>>
  412.             <td class="firstcol"><?php stats_time(?></td>
  413.             <?php if$current_User->check_perm'stats''edit' ) )
  414.             ?>
  415.             <td>
  416.                 <a href="b2stats.php?action=delete&amp;hit_ID=<?php stats_hit_ID(?>&amp;show=other&amp;blog=<?php echo $blog ?>" title="<?php echo T_('Delete this hit!'?>"><img src="img/xross.gif" width="13" height="13" class="middle" alt="<?php echo /* TRANS: Abbrev. for Delete (stats) */ T_('Del'?>" /></a>
  417.             </td>
  418.             <?php ?>
  419.             <td><?php stats_blog_name(?></td>
  420.             <td><a href="<?php stats_req_URI(?>"><?php stats_req_URI(?></a></td>
  421.         </tr>
  422.         <?php
  423.         $count++;
  424.         // End stat loop ?>
  425.     </table>
  426.   <?php
  427.   }
  428.         break;
  429.  
  430.         case 'useragents':
  431.             ?>
  432.     <h2><?php echo T_('Top User Agents'?>:</h2>
  433.     <?php refererList(50,'global',0,0,"'no','invalid','badchar','blacklist','search'",'hit_user_agent',$blog,true,true);
  434.   ifcount$res_stats ) )
  435.   ?>
  436.     <table class="grouped" cellspacing="0">
  437.         <?php
  438.             $count 0;
  439.             foreach$res_stats as $row_stats ?>
  440.             <tr <?php if$count%== echo 'class="odd"'?>>
  441.                 <td class="firstcol"><?php stats_user_agentfalse ?></td>
  442.                 <td class="right"><?php stats_hit_count(?></td>
  443.                 <td class="right"><?php stats_hit_percent(?></td>
  444.             </tr>
  445.         <?php
  446.         $count++;
  447.         // End stat loop ?>
  448.     </table>
  449.   <?php
  450.   }
  451.         break;
  452. }
  453. ?>
  454. </div>
  455. <?php
  456. requiredirname(__FILE__).'/_footer.php' );
  457. ?>

Documentation generated on Tue, 20 May 2008 01:51:26 +0200 by phpDocumentor 1.4.2