author | Dan |
Sat, 08 Sep 2007 22:58:38 -0400 | |
changeset 128 | 01955bf53f96 |
parent 108 | 1c7f59df9474 |
child 142 | ca9118d9c0f2 |
permissions | -rw-r--r-- |
1 | 1 |
<?php |
2 |
/* |
|
3 |
* Enano - an open-source CMS capable of wiki functions, Drupal-like sidebar blocks, and everything in between |
|
73
0a74676a2f2f
Made the move to Loch Ness, and got some basic page grouping functionality working. TODO: fix some UI issues in Javascript ACL editor and change non-JS ACL editor to work with page groups too
Dan
parents:
61
diff
changeset
|
4 |
* Version 1.0.1 (Loch Ness) |
1 | 5 |
* Copyright (C) 2006-2007 Dan Fuhry |
6 |
* stats.php - handles statistics for pages (disablable in the admin CP) |
|
7 |
* |
|
8 |
* ***** UNFINISHED ***** |
|
9 |
* |
|
10 |
* This program is Free Software; you can redistribute and/or modify it under the terms of the GNU General Public License |
|
11 |
* as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. |
|
12 |
* |
|
13 |
* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied |
|
14 |
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for details. |
|
15 |
*/ |
|
16 |
||
17 |
function doStats( $page_id = false, $namespace = false ) |
|
18 |
{ |
|
19 |
global $db, $session, $paths, $template, $plugins; // Common objects |
|
20 |
if(getConfig('log_hits') == '1') |
|
21 |
{ |
|
22 |
if(!$page_id || !$namespace) |
|
23 |
{ |
|
24 |
$page_id = $paths->cpage['urlname_nons']; |
|
25 |
$namespace = $paths->namespace; |
|
26 |
} |
|
61 | 27 |
if($namespace == 'Special' || $namespace == 'Admin') |
28 |
{ |
|
29 |
return false; |
|
30 |
} |
|
1 | 31 |
static $stats_done = false; |
32 |
static $stats_data = Array(); |
|
33 |
if(!$stats_done) |
|
34 |
{ |
|
35 |
$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).'\')'); |
|
36 |
if(!$q) |
|
37 |
{ |
|
38 |
echo $db->get_error(); |
|
39 |
return false; |
|
40 |
} |
|
41 |
$db->free_result(); |
|
42 |
$stats_done = true; |
|
43 |
return true; |
|
44 |
} |
|
45 |
} |
|
46 |
} |
|
47 |
||
48 |
/** |
|
49 |
* Fetch a list of the most-viewed pages |
|
50 |
* @param int the number of pages to return, send -1 to get all pages (suicide for large sites) |
|
51 |
* @return array key names are a string set to the page ID/namespace, and values are an int with the number of hits |
|
52 |
*/ |
|
53 |
||
54 |
function stats_top_pages($num = 5) |
|
55 |
{ |
|
56 |
global $db, $session, $paths, $template, $plugins; // Common objects |
|
61 | 57 |
if(!is_int($num)) |
1 | 58 |
{ |
59 |
return false; |
|
60 |
} |
|
61 | 61 |
|
62 |
$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
|
63 |
$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 | 64 |
|
1 | 65 |
while ( $row = $db->fetchrow() ) |
66 |
{ |
|
61 | 67 |
if ( isset($paths->pages[ $paths->nslist[ $row['namespace'] ] . $row['page_id'] ]) ) |
68 |
{ |
|
69 |
$page_data =& $paths->pages[ $paths->nslist[ $row['namespace'] ] . $row['page_id'] ]; |
|
70 |
$title = $page_data['name']; |
|
71 |
$page_id = $page_data['urlname']; |
|
72 |
} |
|
73 |
else if ( !isset($paths->nslist[$row['namespace']]) ) |
|
74 |
{ |
|
75 |
$title = $row['namespace'] . ':' . $row['page_id']; |
|
76 |
$page_id = sanitize_page_id($title); |
|
77 |
} |
|
78 |
else |
|
79 |
{ |
|
80 |
$title = dirtify_page_id( $paths->nslist[$row['namespace']] . $row['page_id'] ); |
|
81 |
$title = str_replace('_', ' ', $title); |
|
82 |
$page_id = sanitize_page_id($title); |
|
83 |
} |
|
84 |
$data[] = array( |
|
85 |
'page_urlname' => $page_id, |
|
86 |
'page_title' => $title, |
|
87 |
'num_hits' => $row['num_hits'] |
|
88 |
); |
|
1 | 89 |
} |
61 | 90 |
|
91 |
return $data; |
|
1 | 92 |
} |
93 |
||
94 |
?> |