includes/stats.php
author Dan
Thu, 17 Jan 2008 02:03:33 -0500
changeset 349 fdaf9070566c
parent 322 5f1cd51bf1be
child 387 92664d2efab8
permissions -rw-r--r--
More progress on the installer. At this point it can install and import the language, but does not rename config files. Still much work to be done, most notably localization and creation of MySQL users and databases.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
     1
<?php
166
d53cc29308f4 Rebrand as 1.1.1; everything should now be bumped to "unstable" status
Dan
parents: 142
diff changeset
     2
1
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
     3
/*
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
     4
 * Enano - an open-source CMS capable of wiki functions, Drupal-like sidebar blocks, and everything in between
322
5f1cd51bf1be Many changes. Installer with PostgreSQL is broken badly and will be for some time.
Dan
parents: 166
diff changeset
     5
 * Version 1.0.3 (Dyrad)
1
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
     6
 * Copyright (C) 2006-2007 Dan Fuhry
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
     7
 * stats.php - handles statistics for pages (disablable in the admin CP)
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
     8
 *
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
     9
 *   ***** UNFINISHED ***** 
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
    10
 *
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
    11
 * This program is Free Software; you can redistribute and/or modify it under the terms of the GNU General Public License
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
    12
 * as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
    13
 *
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
    14
 * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
    15
 * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for details.
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
    16
 */
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
    17
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
    18
function doStats( $page_id = false, $namespace = false )
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
    19
{
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
    20
  global $db, $session, $paths, $template, $plugins; // Common objects
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
    21
  if(getConfig('log_hits') == '1')
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
    22
  {
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
    23
    if(!$page_id || !$namespace)
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
    24
    {
322
5f1cd51bf1be Many changes. Installer with PostgreSQL is broken badly and will be for some time.
Dan
parents: 166
diff changeset
    25
      $page_id = $paths->page_id;
1
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
    26
      $namespace = $paths->namespace;
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
    27
    }
61
e9708657875a I fixed the statistics!!! YAY!!
Dan
parents: 21
diff changeset
    28
    if($namespace == 'Special' || $namespace == 'Admin') 
e9708657875a I fixed the statistics!!! YAY!!
Dan
parents: 21
diff changeset
    29
    {
e9708657875a I fixed the statistics!!! YAY!!
Dan
parents: 21
diff changeset
    30
      return false;
e9708657875a I fixed the statistics!!! YAY!!
Dan
parents: 21
diff changeset
    31
    }
1
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
    32
    static $stats_done = false;
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
    33
    static $stats_data = Array();
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
    34
    if(!$stats_done)
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
    35
    {
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
    36
      $q = $db->sql_query('INSERT INTO '.table_prefix.'hits (username,time,page_id,namespace) VALUES(\''.$db->escape($session->username).'\', '.time().', \''.$db->escape($page_id).'\', \''.$db->escape($namespace).'\')');
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
    37
      if(!$q)
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
    38
      {
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
    39
        echo $db->get_error();
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
    40
        return false;
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
    41
      }
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
    42
      $db->free_result();
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
    43
      $stats_done = true;
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
    44
      return true;
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
    45
    }
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
    46
  }
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
    47
}
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
    48
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
    49
/**
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
    50
 * Fetch a list of the most-viewed pages
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
    51
 * @param int the number of pages to return, send -1 to get all pages (suicide for large sites)
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
    52
 * @return array key names are a string set to the page ID/namespace, and values are an int with the number of hits
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
    53
 */
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
    54
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
    55
function stats_top_pages($num = 5)
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
    56
{
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
    57
  global $db, $session, $paths, $template, $plugins; // Common objects
61
e9708657875a I fixed the statistics!!! YAY!!
Dan
parents: 21
diff changeset
    58
  if(!is_int($num)) 
1
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
    59
  {
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
    60
    return false;
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
    61
  }
61
e9708657875a I fixed the statistics!!! YAY!!
Dan
parents: 21
diff changeset
    62
  
e9708657875a I fixed the statistics!!! YAY!!
Dan
parents: 21
diff changeset
    63
  $data = array();
108
1c7f59df9474 Implemented some extra functionality for friends/foes in comments; fixed lack of table_prefix in stats.php line 63
Dan
parents: 73
diff changeset
    64
  $q = $db->sql_query('SELECT COUNT(hit_id) AS num_hits, page_id, namespace FROM '.table_prefix.'hits GROUP BY page_id, namespace ORDER BY num_hits DESC LIMIT ' . $num . ';');
61
e9708657875a I fixed the statistics!!! YAY!!
Dan
parents: 21
diff changeset
    65
  
1
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
    66
  while ( $row = $db->fetchrow() )
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
    67
  {
61
e9708657875a I fixed the statistics!!! YAY!!
Dan
parents: 21
diff changeset
    68
    if ( isset($paths->pages[ $paths->nslist[ $row['namespace'] ] . $row['page_id'] ]) )
e9708657875a I fixed the statistics!!! YAY!!
Dan
parents: 21
diff changeset
    69
    {
e9708657875a I fixed the statistics!!! YAY!!
Dan
parents: 21
diff changeset
    70
      $page_data =& $paths->pages[ $paths->nslist[ $row['namespace'] ] . $row['page_id'] ];
e9708657875a I fixed the statistics!!! YAY!!
Dan
parents: 21
diff changeset
    71
      $title = $page_data['name'];
e9708657875a I fixed the statistics!!! YAY!!
Dan
parents: 21
diff changeset
    72
      $page_id = $page_data['urlname'];
e9708657875a I fixed the statistics!!! YAY!!
Dan
parents: 21
diff changeset
    73
    }
e9708657875a I fixed the statistics!!! YAY!!
Dan
parents: 21
diff changeset
    74
    else if ( !isset($paths->nslist[$row['namespace']]) )
e9708657875a I fixed the statistics!!! YAY!!
Dan
parents: 21
diff changeset
    75
    {
e9708657875a I fixed the statistics!!! YAY!!
Dan
parents: 21
diff changeset
    76
      $title = $row['namespace'] . ':' . $row['page_id'];
e9708657875a I fixed the statistics!!! YAY!!
Dan
parents: 21
diff changeset
    77
      $page_id = sanitize_page_id($title);
e9708657875a I fixed the statistics!!! YAY!!
Dan
parents: 21
diff changeset
    78
    }
e9708657875a I fixed the statistics!!! YAY!!
Dan
parents: 21
diff changeset
    79
    else
e9708657875a I fixed the statistics!!! YAY!!
Dan
parents: 21
diff changeset
    80
    {
e9708657875a I fixed the statistics!!! YAY!!
Dan
parents: 21
diff changeset
    81
      $title = dirtify_page_id( $paths->nslist[$row['namespace']] . $row['page_id'] );
e9708657875a I fixed the statistics!!! YAY!!
Dan
parents: 21
diff changeset
    82
      $title = str_replace('_', ' ', $title);
e9708657875a I fixed the statistics!!! YAY!!
Dan
parents: 21
diff changeset
    83
      $page_id = sanitize_page_id($title);
e9708657875a I fixed the statistics!!! YAY!!
Dan
parents: 21
diff changeset
    84
    }
e9708657875a I fixed the statistics!!! YAY!!
Dan
parents: 21
diff changeset
    85
    $data[] = array(
e9708657875a I fixed the statistics!!! YAY!!
Dan
parents: 21
diff changeset
    86
        'page_urlname' => $page_id,
e9708657875a I fixed the statistics!!! YAY!!
Dan
parents: 21
diff changeset
    87
        'page_title' => $title,
e9708657875a I fixed the statistics!!! YAY!!
Dan
parents: 21
diff changeset
    88
        'num_hits' => $row['num_hits']
e9708657875a I fixed the statistics!!! YAY!!
Dan
parents: 21
diff changeset
    89
      );
1
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
    90
  }
61
e9708657875a I fixed the statistics!!! YAY!!
Dan
parents: 21
diff changeset
    91
  
e9708657875a I fixed the statistics!!! YAY!!
Dan
parents: 21
diff changeset
    92
  return $data;
1
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
    93
}
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
    94
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
    95
?>