| 1 |
<?php
|
| 2 |
// $Id: searchquery.module,v 1.4 2009/01/26 19:14:02 goba Exp $
|
| 3 |
|
| 4 |
/**
|
| 5 |
* Implementation of hook_nodeapi().
|
| 6 |
*/
|
| 7 |
function searchquery_nodeapi(&$node, $op = 'view', $teaser = FALSE, $page = FALSE) {
|
| 8 |
if ($op == 'view' && $page) {
|
| 9 |
$extra = '';
|
| 10 |
switch ($node->nid) {
|
| 11 |
case 48380:
|
| 12 |
$extra = searchquery_list();
|
| 13 |
break;
|
| 14 |
}
|
| 15 |
$node->content['body']['#value'] .= $extra;
|
| 16 |
}
|
| 17 |
}
|
| 18 |
|
| 19 |
/**
|
| 20 |
* Load cached search query list or generate cache.
|
| 21 |
*/
|
| 22 |
function searchquery_list() {
|
| 23 |
if ($cache = cache_get('node_48380')) {
|
| 24 |
return $cache->data;
|
| 25 |
}
|
| 26 |
|
| 27 |
$output .= '<div class="column-left"><h2>Anonymous users</h2><ul>';
|
| 28 |
$result = db_query("SELECT message, COUNT(message) AS cnt FROM {watchdog}
|
| 29 |
WHERE type = 'search' AND uid = 0
|
| 30 |
GROUP BY message
|
| 31 |
ORDER BY cnt DESC
|
| 32 |
LIMIT 300");
|
| 33 |
|
| 34 |
while ($s = db_fetch_object($result)) {
|
| 35 |
preg_match('!<em>(.*?)</em>!', $s->message, $matches);
|
| 36 |
$output .= '<li>'. check_plain($matches[1]) .' ('. $s->cnt .')</li>';
|
| 37 |
}
|
| 38 |
$output .= '</ul></div>';
|
| 39 |
|
| 40 |
$output .= '<div class="column-right"><h2>Authenticated users</h2><ul>';
|
| 41 |
$result = db_query("SELECT message, COUNT(message) AS cnt FROM {watchdog}
|
| 42 |
WHERE type = 'search' AND uid != 0
|
| 43 |
GROUP BY message
|
| 44 |
ORDER BY cnt
|
| 45 |
DESC limit 300");
|
| 46 |
|
| 47 |
while ($s = db_fetch_object($result)) {
|
| 48 |
preg_match('!<em>(.*?)</em>!', $s->message, $matches);
|
| 49 |
$output .= '<li>'. check_plain($matches[1]) .' ('. $s->cnt .')</li>';
|
| 50 |
}
|
| 51 |
$output .= '</ul></div>';
|
| 52 |
|
| 53 |
cache_set('node_48380', $output, 'cache', 60*60);
|
| 54 |
|
| 55 |
return $output;
|
| 56 |
}
|