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