[ PHPXref.com ] [ Generated: Sun Jul 20 20:54:51 2008 ] [ Vice Stats 1.0.1 ]
[ Index ]     [ Variables ]     [ Functions ]     [ Classes ]     [ Constants ]     [ Statistics ]

title

Body

[close]

/ -> vs_search.php (source)

   1  <?
   2  /*

   3  Vice Stats - Web site statistics gathering suite.

   4  Copyright (C) 2005 Anthony Lieuallen

   5  

   6  This program is free software; you can redistribute it and/or modify

   7  it under the terms of the GNU General Public License as published by

   8  the Free Software Foundation; either version 2 of the License, or

   9  (at your option) any later version.

  10  

  11  This program is distributed in the hope that it will be useful,

  12  but WITHOUT ANY WARRANTY; without even the implied warranty of

  13  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the

  14  GNU General Public License for more details.

  15  

  16  You should have received a copy of the GNU General Public License

  17  along with this program; if not, write to the Free Software

  18  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA

  19  */
  20  
  21  include('vs_config.php');
  22  include ('vs_funcs.php');
  23  include ('vs_display.php');
  24  
  25  ob_start(); //along with the ob_flush() calls down below, this makes 

  26              //incremental loading cleaner

  27  vs_dbConnect();
  28  vs_checkLogin();
  29  
  30  function showSearchForm() {
  31      $s='';
  32      if (isset($_GET['s'])) $s=$_GET['s'];
  33      ?>
  34      <form method='get' action='vs_resource.php'>
  35      <p>Enter any part of the URL to locate a resource that matches:</p>
  36      <input type='text' name='s' value='<?=$s?>' size='50'>
  37      <input type='submit' value=' Go '>
  38      </form>
  39      </body></html>
  40      <?
  41  }
  42  
  43  vs_header();
  44  ?>
  45  <h1>
  46      <div class='tabs'>
  47          <a href='vs_search.php?engine'>Engines</a>
  48          <a href='vs_search.php?spider'>Spiders</a>
  49      </div>
  50      Searches
  51  </h1>
  52  
  53  <?
  54  if (empty($_GET)) {
  55      print "<p>Error</p>";
  56      exit;
  57  } else if (isset($_GET['engine']) && empty($_GET['engine'])) {
  58      $sql="SELECT COUNT(0) AS hits, e.name, e.ID as engineID 
  59          FROM {$vs_dbPrefix}hit h
  60          JOIN {$vs_dbPrefix}resource r ON (h.referralID=r.ID)
  61          JOIN {$vs_dbPrefix}searchEngine e ON (r.searchEngineID=e.ID)
  62          WHERE h.userID={$vs_user}
  63          GROUP BY e.ID
  64          ORDER BY hits DESC";
  65      $result=mysql_query($sql);
  66  
  67      if (mysql_num_rows($result)>0) {
  68          print "<table>";
  69          print "<tr><th>Engine</th><th>Referrals</th></tr>";
  70          while ($row=mysql_fetch_assoc($result)) {
  71              $row['dispURL']=wrapURL($row['URL']);
  72              print '<tr>';
  73              print "<td><a href='vs_search.php?engine={$row['engineID']}'>{$row['name']}</a></td>";
  74              print "<td>{$row['hits']}</td>";
  75              print '</tr>';
  76          }
  77      }
  78  } else if (isset($_GET['engine']) && !empty($_GET['engine'])) {
  79      $engine=mysql_real_escape_string($_GET['engine']);
  80      $sql="SELECT name FROM {$vs_dbPrefix}searchEngine WHERE ID='{$engine}'";
  81      $result=mysql_query($sql);
  82      $engineName=mysql_result($result, 0, 0);
  83  
  84      $start=0;
  85      if (isset($_GET['start'])) $start=mysql_real_escape_string($_GET['start']);
  86      $sql="SELECT SQL_CALC_FOUND_ROWS COUNT(0) AS hits, p.phrase
  87          FROM {$vs_dbPrefix}hit h
  88          JOIN {$vs_dbPrefix}resource r ON (h.referralID=r.ID)
  89          JOIN {$vs_dbPrefix}searchPhrase p ON (r.searchPhraseID=p.ID)
  90          WHERE r.searchEngineID={$engine} AND h.userID={$vs_user}
  91          GROUP BY p.ID
  92          ORDER BY hits DESC
  93          LIMIT {$start}, {$vs_maxRows}";
  94      $result=mysql_query($sql);
  95  
  96      if (mysql_num_rows($result)>0) {
  97          print "<p>Search phrases for engine: {$engineName}</p>";
  98          multiPageLinks($start, $vs_maxRows, 'vs_search.php?engine='.urlencode($engine).'&amp;start=%d');
  99          print "<table>";
 100          print "<tr><th>Phrase</th><th>Referrals</th></tr>";
 101          while ($row=mysql_fetch_assoc($result)) {
 102              print '<tr>';
 103              print "<td>{$row['phrase']}</td>";
 104              print "<td>{$row['hits']}</td>";
 105              print '</tr>';
 106          }
 107          print "</table>";
 108      }
 109  } else if (isset($_GET['spider']) && empty($_GET['spider'])) {
 110      $sql="SELECT COUNT(0) AS hits, b.ua, b.ID as browserID
 111          FROM {$vs_dbPrefix}hit h
 112          JOIN {$vs_dbPrefix}browser b ON (h.browserID=b.ID)
 113          WHERE b.spider=1 AND h.userID={$vs_user}
 114          GROUP BY b.ua
 115          ORDER BY hits DESC";
 116      $result=mysql_query($sql);
 117  
 118      if (mysql_num_rows($result)>0) {
 119          print "<table>";
 120          print "<tr><th>Spider</th><th>Hits</th></tr>";
 121          while ($row=mysql_fetch_assoc($result)) {
 122              $row['dispURL']=wrapURL($row['URL']);
 123              print '<tr>';
 124              print "<td><a href='vs_search.php?spider={$row['browserID']}'>{$row['ua']}</a></td>";
 125              print "<td>{$row['hits']}</td>";
 126              print '</tr>';
 127          }
 128          print "</table>";
 129      }
 130  } else if (isset($_GET['spider']) && !empty($_GET['spider'])) {
 131      $spider=mysql_real_escape_string($_GET['spider']);
 132      $sql="SELECT ua FROM {$vs_dbPrefix}browser WHERE ID={$spider}";
 133      $result=mysql_query($sql);
 134      $spiderName=mysql_result($result, 0, 0);
 135  
 136      $start=0;
 137      if (isset($_GET['start'])) $start=mysql_real_escape_string($_GET['start']);
 138      $sql="SELECT SQL_CALC_FOUND_ROWS COUNT(0) AS hits, 
 139              CONCAT(r.path, IF(r.query IS NULL, '', r.query)) AS res
 140          FROM {$vs_dbPrefix}hit h
 141          JOIN {$vs_dbPrefix}resource r ON (h.resourceID=r.ID)
 142          WHERE h.browserID='{$spider}' AND h.userID={$vs_user}
 143          GROUP BY h.resourceID
 144          ORDER BY hits DESC
 145          LIMIT {$start}, {$vs_maxRows}";
 146      $result=mysql_query($sql);
 147  
 148      if (mysql_num_rows($result)>0) {
 149          print "<p>Hits for spider: {$spiderName}</p>";
 150          multiPageLinks($start, $vs_maxRows, 'vs_search.php?engine='.urlencode($spider).'&amp;start=%d');
 151          print "<table>";
 152          print "<tr><th>Phrase</th><th>Referrals</th></tr>";
 153          while ($row=mysql_fetch_assoc($result)) {
 154              print '<tr>';
 155              print "<td>{$row['res']}</td>";
 156              print "<td>{$row['hits']}</td>";
 157              print '</tr>';
 158          }
 159          print "</table>";
 160      }
 161  }
 162  ?>
 163  
 164  </body>
 165  </html>


[ Powered by PHPXref - Served by Debian GNU/Linux ]