• Avail guidance to develop Drupal modules & Drupal themes
  • Share and get review of your code
  • Get Access to free CodeBooks and ThemeBooks
  • Drupal 5, 6 and 7 covered

About bhavinhjoshi

Node Visitors

Printer-friendly versionSend to a DeveloperPDF version
2
0

This CodeLet adds a local task on node page which lists all the unique visitors of the node. You can configure the profile fields to be shown list.

<?php
//$Id$

/**
* @file
*
* Retrive and Display user visits of a node
*
* @author Drupal Developer
*/


/**
* Implemntation of hook_menu
*
* @return $item
* @author Drupal Developer
*/
function track_user_menu() {
   
$item = array();
   
$item['node/%node/node-track'] = array(
     
'type' => MENU_LOCAL_TASK,
     
'weight' => 0,
     
'title' => 'Who visited this node',
     
'title callback' => 't',
     
'page callback' => 'get_node_visitor',
     
'page arguments' => array(1),
     
'access callback' => 'validate_node_visitor',
    );


    return
$item;
}



/**
* validate_node_visitor
*
* Validates the access to the user visits to the node
*
* @return unknown_type
* @author Drupal Developer
*/
function validate_node_visitor() {
    global
$user;
    if (
in_array('admin', $user->roles) || $user->uid == 1) {
        return
TRUE;
    }
    else {
        return
FALSE;
    }
}


/**
* get_node_visitor
*
* @param $node
* @return unknown_type
* @author Drupal Developer
*/
function get_node_visitor($node) {
    if (
$node->nid) {
   
$am__field_ttile = array(t("User"));
       
$r__result = db_query("SELECT DISTINCT uid FROM {accesslog}
          WHERE PATH = '%s' AND uid <> 0"
, "node/". $node->nid);
        while (
$om__user = db_fetch_object($r__result)) {
     
$ss__username = db_result(db_query("SELECT name FROM {users} WHERE uid = %d", $om__user->uid));
         
$row[] = array(l($ss__username, "user/". $om__user->uid));
          unset(
$om__user);
        }
        return
theme('table', $am__field_title, $row);
    }
}
?>

Syndicate content

Sitestats

Recent comments

rss-top-right.png
toolbar powered by www.iconcy.com