function mostpopular_drupal_mostpopular_service in Drupal Most Popular 6
Implements hook_mostpopular_service().
See also
File
- modules/
mostpopular_drupal/ mostpopular_drupal.module, line 24 - This module uses the Drupal statistics module to provide Most Popular data.
Code
function mostpopular_drupal_mostpopular_service($op, $delta = 0, $options = array()) {
switch ($op) {
case 'list':
return array(
'viewed' => array(
'name' => t('Drupal Most Viewed'),
'title' => t('Viewed'),
),
'commented' => array(
'name' => t('Drupal Most Commented Pages'),
'title' => t('Commented'),
),
);
break;
case 'refresh':
switch ($delta) {
case 'viewed':
// This query is borrowed from the Hall of Fame module.
// However, it does not fetch any nodes which were published a while ago
// and are only now becoming popular. Use the Google Analytics plugin
// instead for better results.
$sql = "\n SELECT DISTINCT n.nid, n.title, c.totalcount\n FROM {node} n left join {node_counter} c on n.nid = c.nid\n WHERE n.status = 1 and n.moderate = 0 and n.created >= %d\n AND c.totalcount >= 1 and title not like '%page not found%'\n ORDER BY c.totalcount desc, n.created desc";
$out = array();
$result = db_query($sql, $options['ts'], 0);
while ($row = db_fetch_object($result)) {
$node = mostpopular_match_result_nodes(url("node/{$row->nid}"), $row->totalcount);
if (isset($node)) {
$out[] = $node;
if (count($out) >= $options['max']) {
break;
}
}
}
return $out;
case 'commented':
$sql = "\n SELECT DISTINCT n.nid, n.title, count(c.cid) as totalcount\n FROM {node} n INNER JOIN {comments} c on n.nid = c.nid\n WHERE n.status = 1 and n.moderate = 0 AND c.timestamp >= %d\n GROUP BY n.nid\n ORDER BY totalcount desc, n.created desc";
$out = array();
$result = db_query($sql, $options['ts']);
while ($row = db_fetch_object($result)) {
$node = mostpopular_match_result_nodes(url("node/{$row->nid}"), $row->totalcount);
if (isset($node)) {
$out[] = $node;
if (count($out) >= $options['max']) {
break;
}
}
}
return $out;
}
return FALSE;
}
}