diff --git a/MAINTAINERS.txt b/MAINTAINERS.txt index a4c8a80..da16732 100644 --- a/MAINTAINERS.txt +++ b/MAINTAINERS.txt @@ -241,9 +241,6 @@ Simpletest module - Jimmy Berry 'boombatower' - Károly Négyesi 'chx' -Statistics module -- Dave Reid 'davereid' - Syslog module - Khalid Baheyeldin 'kbahey' diff --git a/includes/common.inc b/includes/common.inc index 1ef681f..41675c1 100644 --- a/includes/common.inc +++ b/includes/common.inc @@ -5377,13 +5377,6 @@ function drupal_pre_render_link($element) { * // passing in to theme_links(). * ), * ), - * 'statistics' => array( - * '#theme' => 'links__node__statistics', - * '#links' => array( - * // An array of links associated with node statistics, suitable for - * // passing in to theme_links(). - * ), - * ), * 'translation' => array( * '#theme' => 'links__node__translation', * '#links' => array( @@ -5412,9 +5405,9 @@ function drupal_pre_render_link($element) { * print render($content['links']); * @endcode * - * In the above example, this will result in the statistics and translation - * links being rendered together in a single list (but not the comment links, - * which were rendered previously on their own). + * In the above example, this will result in the translation links being + * rendered together in a single list (but not the comment links, which were + * rendered previously on their own). * * Because of the way this function works, the individual properties of each * group (for example, a group-specific #theme property such as diff --git a/modules/statistics/statistics.admin.inc b/modules/statistics/statistics.admin.inc deleted file mode 100644 index 6606b8b..0000000 --- a/modules/statistics/statistics.admin.inc +++ /dev/null @@ -1,274 +0,0 @@ - t('Timestamp'), 'field' => 'a.timestamp', 'sort' => 'desc'), - array('data' => t('Page'), 'field' => 'a.path'), - array('data' => t('User'), 'field' => 'u.name'), - array('data' => t('Operations')) - ); - - $query = db_select('accesslog', 'a', array('target' => 'slave'))->extend('PagerDefault')->extend('TableSort'); - $query->join('users', 'u', 'a.uid = u.uid'); - $query - ->fields('a', array('aid', 'timestamp', 'path', 'title', 'uid')) - ->fields('u', array('name')) - ->limit(30) - ->orderByHeader($header); - - $result = $query->execute(); - $rows = array(); - foreach ($result as $log) { - $rows[] = array( - array('data' => format_date($log->timestamp, 'short'), 'class' => array('nowrap')), - _statistics_format_item($log->title, $log->path), - theme('username', array('account' => $log)), - l(t('details'), "admin/reports/access/$log->aid")); - } - - $build['statistics_table'] = array( - '#theme' => 'table', - '#header' => $header, - '#rows' => $rows, - '#empty' => t('No statistics available.'), - ); - $build['statistics_pager'] = array('#theme' => 'pager'); - return $build; -} - -/** - * Menu callback; presents the "top pages" page. - */ -function statistics_top_pages() { - $header = array( - array('data' => t('Hits'), 'field' => 'hits', 'sort' => 'desc'), - array('data' => t('Page'), 'field' => 'path'), - array('data' => t('Average page generation time'), 'field' => 'average_time'), - array('data' => t('Total page generation time'), 'field' => 'total_time') - ); - - $query = db_select('accesslog', 'a', array('target' => 'slave'))->extend('PagerDefault')->extend('TableSort'); - $query->addExpression('COUNT(path)', 'hits'); - // MAX(title) avoids having empty node titles which otherwise causes duplicates in the top pages list - $query->addExpression('MAX(title)', 'title'); - $query->addExpression('AVG(timer)', 'average_time'); - $query->addExpression('SUM(timer)', 'total_time'); - - $query - ->fields('a', array('path')) - ->groupBy('path') - ->limit(30) - ->orderByHeader($header); - - $count_query = db_select('accesslog', 'a', array('target' => 'slave')); - $count_query->addExpression('COUNT(DISTINCT path)'); - $query->setCountQuery($count_query); - - $result = $query->execute(); - $rows = array(); - foreach ($result as $page) { - $rows[] = array($page->hits, _statistics_format_item($page->title, $page->path), t('%time ms', array('%time' => round($page->average_time))), format_interval(round($page->total_time / 1000))); - } - - drupal_set_title(t('Top pages in the past %interval', array('%interval' => format_interval(variable_get('statistics_flush_accesslog_timer', 259200)))), PASS_THROUGH); - $build['statistics_top_pages_table'] = array( - '#theme' => 'table', - '#header' => $header, - '#rows' => $rows, - '#empty' => t('No statistics available.'), - ); - $build['statistics_top_pages_pager'] = array('#theme' => 'pager'); - return $build; -} - -/** - * Menu callback; presents the "top visitors" page. - */ -function statistics_top_visitors() { - - $header = array( - array('data' => t('Hits'), 'field' => 'hits', 'sort' => 'desc'), - array('data' => t('Visitor'), 'field' => 'u.name'), - array('data' => t('Total page generation time'), 'field' => 'total'), - array('data' => user_access('block IP addresses') ? t('Operations') : '', 'colspan' => 2), - ); - $query = db_select('accesslog', 'a', array('target' => 'slave'))->extend('PagerDefault')->extend('TableSort'); - $query->leftJoin('blocked_ips', 'bl', 'a.hostname = bl.ip'); - $query->leftJoin('users', 'u', 'a.uid = u.uid'); - - $query->addExpression('COUNT(a.uid)', 'hits'); - $query->addExpression('SUM(a.timer)', 'total'); - $query - ->fields('a', array('uid', 'hostname')) - ->fields('u', array('name')) - ->fields('bl', array('iid')) - ->groupBy('a.hostname') - ->groupBy('a.uid') - ->groupBy('u.name') - ->groupBy('bl.iid') - ->limit(30) - ->orderByHeader($header); - - $uniques_query = db_select('accesslog')->distinct(); - $uniques_query->fields('accesslog', array('uid', 'hostname')); - $count_query = db_select($uniques_query); - $count_query->addExpression('COUNT(*)'); - $query->setCountQuery($count_query); - - $result = $query->execute(); - $rows = array(); - $destination = drupal_get_destination(); - foreach ($result as $account) { - $ban_link = $account->iid ? l(t('unblock IP address'), "admin/config/people/ip-blocking/delete/$account->iid", array('query' => $destination)) : l(t('block IP address'), "admin/config/people/ip-blocking/$account->hostname", array('query' => $destination)); - $rows[] = array($account->hits, ($account->uid ? theme('username', array('account' => $account)) : $account->hostname), format_interval(round($account->total / 1000)), (user_access('block IP addresses') && !$account->uid) ? $ban_link : ''); - } - - drupal_set_title(t('Top visitors in the past %interval', array('%interval' => format_interval(variable_get('statistics_flush_accesslog_timer', 259200)))), PASS_THROUGH); - $build['statistics_top_visitors_table'] = array( - '#theme' => 'table', - '#header' => $header, - '#rows' => $rows, - '#empty' => t('No statistics available.'), - ); - $build['statistics_top_visitors_pager'] = array('#theme' => 'pager'); - return $build; -} - -/** - * Menu callback; presents the "referrer" page. - */ -function statistics_top_referrers() { - drupal_set_title(t('Top referrers in the past %interval', array('%interval' => format_interval(variable_get('statistics_flush_accesslog_timer', 259200)))), PASS_THROUGH); - - $header = array( - array('data' => t('Hits'), 'field' => 'hits', 'sort' => 'desc'), - array('data' => t('Url'), 'field' => 'url'), - array('data' => t('Last visit'), 'field' => 'last'), - ); - $query = db_select('accesslog', 'a')->extend('PagerDefault')->extend('TableSort'); - - $query->addExpression('COUNT(url)', 'hits'); - $query->addExpression('MAX(timestamp)', 'last'); - $query - ->fields('a', array('url')) - ->condition('url', '%' . $_SERVER['HTTP_HOST'] . '%', 'NOT LIKE') - ->condition('url', '', '<>') - ->groupBy('url') - ->limit(30) - ->orderByHeader($header); - - $count_query = db_select('accesslog', 'a', array('target' => 'slave')); - $count_query->addExpression('COUNT(DISTINCT url)'); - $count_query - ->condition('url', '%' . $_SERVER['HTTP_HOST'] . '%', 'NOT LIKE') - ->condition('url', '', '<>'); - $query->setCountQuery($count_query); - - $result = $query->execute(); - $rows = array(); - foreach ($result as $referrer) { - $rows[] = array($referrer->hits, _statistics_link($referrer->url), t('@time ago', array('@time' => format_interval(REQUEST_TIME - $referrer->last)))); - } - - $build['statistics_top_referrers_table'] = array( - '#theme' => 'table', - '#header' => $header, - '#rows' => $rows, - '#empty' => t('No statistics available.'), - ); - $build['statistics_top_referrers_pager'] = array('#theme' => 'pager'); - return $build; -} - -/** - * Menu callback; Displays recent page accesses. - */ -function statistics_access_log($aid) { - $access = db_query('SELECT a.*, u.name FROM {accesslog} a LEFT JOIN {users} u ON a.uid = u.uid WHERE aid = :aid', array(':aid' => $aid))->fetch(); - if ($access) { - $rows[] = array( - array('data' => t('URL'), 'header' => TRUE), - l(url($access->path, array('absolute' => TRUE)), $access->path) - ); - // It is safe to avoid filtering $access->title through check_plain because - // it comes from drupal_get_title(). - $rows[] = array( - array('data' => t('Title'), 'header' => TRUE), - $access->title - ); - $rows[] = array( - array('data' => t('Referrer'), 'header' => TRUE), - ($access->url ? l($access->url, $access->url) : '') - ); - $rows[] = array( - array('data' => t('Date'), 'header' => TRUE), - format_date($access->timestamp, 'long') - ); - $rows[] = array( - array('data' => t('User'), 'header' => TRUE), - theme('username', array('account' => $access)) - ); - $rows[] = array( - array('data' => t('Hostname'), 'header' => TRUE), - check_plain($access->hostname) - ); - - $build['statistics_table'] = array( - '#theme' => 'table', - '#rows' => $rows, - ); - return $build; - } - else { - drupal_not_found(); - } -} - -/** - * Form builder; Configure access logging. - * - * @ingroup forms - * @see system_settings_form() - */ -function statistics_settings_form() { - // Access log settings. - $form['access'] = array( - '#type' => 'fieldset', - '#title' => t('Access log settings'), - ); - $form['access']['statistics_enable_access_log'] = array( - '#type' => 'checkbox', - '#title' => t('Enable access log'), - '#default_value' => variable_get('statistics_enable_access_log', 0), - '#description' => t('Log each page access. Required for referrer statistics.'), - ); - $form['access']['statistics_flush_accesslog_timer'] = array( - '#type' => 'select', - '#title' => t('Discard access logs older than'), - '#default_value' => variable_get('statistics_flush_accesslog_timer', 259200), - '#options' => array(0 => t('Never')) + drupal_map_assoc(array(3600, 10800, 21600, 32400, 43200, 86400, 172800, 259200, 604800, 1209600, 2419200, 4838400, 9676800), 'format_interval'), - '#description' => t('Older access log entries (including referrer statistics) will be automatically discarded. (Requires a correctly configured cron maintenance task.)', array('@cron' => url('admin/reports/status'))), - ); - - // Content counter settings. - $form['content'] = array( - '#type' => 'fieldset', - '#title' => t('Content viewing counter settings'), - ); - $form['content']['statistics_count_content_views'] = array( - '#type' => 'checkbox', - '#title' => t('Count content views'), - '#default_value' => variable_get('statistics_count_content_views', 0), - '#description' => t('Increment a counter each time content is viewed.'), - ); - - return system_settings_form($form); -} diff --git a/modules/statistics/statistics.info b/modules/statistics/statistics.info deleted file mode 100644 index e7add60..0000000 --- a/modules/statistics/statistics.info +++ /dev/null @@ -1,7 +0,0 @@ -name = Statistics -description = Logs access statistics for your site. -package = Core -version = VERSION -core = 8.x -files[] = statistics.test -configure = admin/config/system/statistics diff --git a/modules/statistics/statistics.install b/modules/statistics/statistics.install deleted file mode 100644 index a5dc7f8..0000000 --- a/modules/statistics/statistics.install +++ /dev/null @@ -1,136 +0,0 @@ - 'Stores site access information for statistics.', - 'fields' => array( - 'aid' => array( - 'type' => 'serial', - 'not null' => TRUE, - 'description' => 'Primary Key: Unique accesslog ID.', - ), - 'sid' => array( - 'type' => 'varchar', - 'length' => 128, - 'not null' => TRUE, - 'default' => '', - 'description' => 'Browser session ID of user that visited page.', - ), - 'title' => array( - 'type' => 'varchar', - 'length' => 255, - 'not null' => FALSE, - 'description' => 'Title of page visited.', - ), - 'path' => array( - 'type' => 'varchar', - 'length' => 255, - 'not null' => FALSE, - 'description' => 'Internal path to page visited (relative to Drupal root.)', - ), - 'url' => array( - 'type' => 'text', - 'not null' => FALSE, - 'description' => 'Referrer URI.', - ), - 'hostname' => array( - 'type' => 'varchar', - 'length' => 128, - 'not null' => FALSE, - 'description' => 'Hostname of user that visited the page.', - ), - 'uid' => array( - 'type' => 'int', - 'unsigned' => TRUE, - 'not null' => FALSE, - 'default' => 0, - 'description' => 'User {users}.uid that visited the page.', - ), - 'timer' => array( - 'type' => 'int', - 'unsigned' => TRUE, - 'not null' => TRUE, - 'default' => 0, - 'description' => 'Time in milliseconds that the page took to load.', - ), - 'timestamp' => array( - 'type' => 'int', - 'unsigned' => TRUE, - 'not null' => TRUE, - 'default' => 0, - 'description' => 'Timestamp of when the page was visited.', - ), - ), - 'indexes' => array( - 'accesslog_timestamp' => array('timestamp'), - 'uid' => array('uid'), - ), - 'primary key' => array('aid'), - 'foreign keys' => array( - 'visitor' => array( - 'table' => 'users', - 'columns' => array('uid' => 'uid'), - ), - ), - ); - - $schema['node_counter'] = array( - 'description' => 'Access statistics for {node}s.', - 'fields' => array( - 'nid' => array( - 'description' => 'The {node}.nid for these statistics.', - 'type' => 'int', - 'not null' => TRUE, - 'default' => 0, - ), - 'totalcount' => array( - 'description' => 'The total number of times the {node} has been viewed.', - 'type' => 'int', - 'unsigned' => TRUE, - 'not null' => TRUE, - 'default' => 0, - 'size' => 'big', - ), - 'daycount' => array( - 'description' => 'The total number of times the {node} has been viewed today.', - 'type' => 'int', - 'unsigned' => TRUE, - 'not null' => TRUE, - 'default' => 0, - 'size' => 'medium', - ), - 'timestamp' => array( - 'description' => 'The most recent time the {node} has been viewed.', - 'type' => 'int', - 'unsigned' => TRUE, - 'not null' => TRUE, - 'default' => 0, - ), - ), - 'primary key' => array('nid'), - ); - - return $schema; -} diff --git a/modules/statistics/statistics.module b/modules/statistics/statistics.module deleted file mode 100644 index 69e06f3..0000000 --- a/modules/statistics/statistics.module +++ /dev/null @@ -1,427 +0,0 @@ -' . t('About') . ''; - $output .= '

' . t('The Statistics module shows you how often a given page is viewed, who viewed it, the previous page the user visited (referrer URL), and when it was viewed. These statistics are useful in determining how users are visiting and navigating your site. For more information, see the online handbook entry for the Statistics module.', array('@statistics' => url('http://drupal.org/handbook/modules/statistics/'))) . '

'; - $output .= '

' . t('Uses') . '

'; - $output .= '
'; - $output .= '
' . t('Managing logs') . '
'; - $output .= '
' . t('To enable collection of statistics, the Enable access log checkbox on the Statistics settings page must be checked. The Discard access logs older than setting on the settings page specifies the length of time entries are kept in the log before they are deleted. This setting requires a correctly configured cron maintenance task to run.', array('@statistics-settings' => url('admin/config/system/statistics'), '@cron' => 'http://drupal.org/cron')) . '
'; - $output .= '
' . t('Viewing site usage') . '
'; - $output .= '
' . t('The Statistics module can help you break down details about your users and how they are using the site. The module offers four reports:'); - $output .= '
  • ' . t('Recent hits displays information about the latest activity on your site, including the URL and title of the page that was accessed, the user name (if available) and the IP address of the viewer.', array('@recent-hits' => url('admin/reports/hits'))) . '
  • '; - $output .= '
  • ' . t('Top referrers displays where visitors came from (referrer URL).', array('@top-referrers' => url('admin/reports/referrers'))) . '
  • '; - $output .= '
  • ' . t('Top pages displays a list of pages ordered by how often they were viewed.', array('@top-pages' => url('admin/reports/pages'))) . '
  • '; - $output .= '
  • ' . t('Top visitors shows you the most active visitors for your site and allows you to ban abusive visitors.', array('@top-visitors' => url('admin/reports/visitors'))) . '
'; - $output .= '
' . t('Displaying popular content') . '
'; - $output .= '
' . t('The module includes a Popular content block that displays the most viewed pages today and for all time, and the last content viewed. To use the block, enable Count content views on the statistics settings page, and then you can enable and configure the block on the blocks administration page.', array('@statistics-settings' => url('admin/config/system/statistics'), '@blocks' => url('admin/structure/block'))) . '
'; - $output .= '
' . t('Page view counter') . '
'; - $output .= '
' . t('The Statistics module includes a counter for each page that increases whenever the page is viewed. To use the counter, enable Count content views on the statistics settings page, and set the necessary permissions (View content hits) so that the counter is visible to the users.', array('@statistics-settings' => url('admin/config/system/statistics'), '@permissions' => url('admin/people/permissions', array('fragment' => 'module-statistics')))) . '
'; - $output .= '
'; - return $output; - case 'admin/config/system/statistics': - return '

' . t('Settings for the statistical information that Drupal will keep about the site. See site statistics for the actual information.', array('@statistics' => url('admin/reports/hits'))) . '

'; - case 'admin/reports/hits': - return '

' . t("This page displays the site's most recent hits.") . '

'; - case 'admin/reports/referrers': - return '

' . t('This page displays all external referrers, or external references to your website.') . '

'; - case 'admin/reports/visitors': - return '

' . t("When you ban a visitor, you prevent the visitor's IP address from accessing your site. Unlike blocking a user, banning a visitor works even for anonymous users. This is most commonly used to block resource-intensive bots or web crawlers.") . '

'; - } -} - - -/** - * Implements hook_exit(). - * - * This is where statistics are gathered on page accesses. - */ -function statistics_exit() { - global $user; - - // When serving cached pages with the 'page_cache_without_database' - // configuration, system variables need to be loaded. This is a major - // performance decrease for non-database page caches, but with Statistics - // module, it is likely to also have 'statistics_enable_access_log' enabled, - // in which case we need to bootstrap to the session phase anyway. - drupal_bootstrap(DRUPAL_BOOTSTRAP_VARIABLES); - - if (variable_get('statistics_count_content_views', 0)) { - // We are counting content views. - if (arg(0) == 'node' && is_numeric(arg(1)) && arg(2) == NULL) { - // A node has been viewed, so update the node's counters. - db_merge('node_counter') - ->key(array('nid' => arg(1))) - ->fields(array( - 'daycount' => 1, - 'totalcount' => 1, - 'timestamp' => REQUEST_TIME, - )) - ->expression('daycount', 'daycount + 1') - ->expression('totalcount', 'totalcount + 1') - ->execute(); - } - } - if (variable_get('statistics_enable_access_log', 0)) { - drupal_bootstrap(DRUPAL_BOOTSTRAP_SESSION); - // Log this page access. - db_insert('accesslog') - ->fields(array( - 'title' => strip_tags(drupal_get_title()), - 'path' => $_GET['q'], - 'url' => isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : '', - 'hostname' => ip_address(), - 'uid' => $user->uid, - 'sid' => session_id(), - 'timer' => (int) timer_read('page'), - 'timestamp' => REQUEST_TIME, - )) - ->execute(); - } -} - -/** - * Implements hook_permission(). - */ -function statistics_permission() { - return array( - 'administer statistics' => array( - 'title' => t('Administer statistics'), - ), - 'access statistics' => array( - 'title' => t('View content access statistics'), - ), - 'view post access counter' => array( - 'title' => t('View content hits'), - ), - ); -} - -/** - * Implements hook_node_view(). - */ -function statistics_node_view($node, $view_mode) { - if ($view_mode != 'rss') { - if (user_access('view post access counter')) { - $statistics = statistics_get($node->nid); - if ($statistics) { - $links['statistics_counter']['title'] = format_plural($statistics['totalcount'], '1 read', '@count reads'); - $node->content['links']['statistics'] = array( - '#theme' => 'links__node__statistics', - '#links' => $links, - '#attributes' => array('class' => array('links', 'inline')), - ); - } - } - } -} - -/** - * Implements hook_menu(). - */ -function statistics_menu() { - $items['admin/reports/hits'] = array( - 'title' => 'Recent hits', - 'description' => 'View pages that have recently been visited.', - 'page callback' => 'statistics_recent_hits', - 'access arguments' => array('access statistics'), - 'file' => 'statistics.admin.inc', - ); - $items['admin/reports/pages'] = array( - 'title' => 'Top pages', - 'description' => 'View pages that have been hit frequently.', - 'page callback' => 'statistics_top_pages', - 'access arguments' => array('access statistics'), - 'weight' => 1, - 'file' => 'statistics.admin.inc', - ); - $items['admin/reports/visitors'] = array( - 'title' => 'Top visitors', - 'description' => 'View visitors that hit many pages.', - 'page callback' => 'statistics_top_visitors', - 'access arguments' => array('access statistics'), - 'weight' => 2, - 'file' => 'statistics.admin.inc', - ); - $items['admin/reports/referrers'] = array( - 'title' => 'Top referrers', - 'description' => 'View top referrers.', - 'page callback' => 'statistics_top_referrers', - 'access arguments' => array('access statistics'), - 'file' => 'statistics.admin.inc', - ); - $items['admin/reports/access/%'] = array( - 'title' => 'Details', - 'description' => 'View access log.', - 'page callback' => 'statistics_access_log', - 'page arguments' => array(3), - 'access arguments' => array('access statistics'), - 'file' => 'statistics.admin.inc', - ); - $items['admin/config/system/statistics'] = array( - 'title' => 'Statistics', - 'description' => 'Control details about what and how your site logs access statistics.', - 'page callback' => 'drupal_get_form', - 'page arguments' => array('statistics_settings_form'), - 'access arguments' => array('administer statistics'), - 'file' => 'statistics.admin.inc', - 'weight' => -15, - ); - $items['user/%user/track/navigation'] = array( - 'title' => 'Track page visits', - 'page callback' => 'statistics_user_tracker', - 'access callback' => 'user_access', - 'access arguments' => array('access statistics'), - 'type' => MENU_LOCAL_TASK, - 'weight' => 2, - 'file' => 'statistics.pages.inc', - ); - $items['node/%node/track'] = array( - 'title' => 'Track', - 'page callback' => 'statistics_node_tracker', - 'access callback' => 'user_access', - 'access arguments' => array('access statistics'), - 'type' => MENU_LOCAL_TASK, - 'weight' => 2, - 'file' => 'statistics.pages.inc', - ); - - return $items; -} - -/** - * Implements hook_user_cancel(). - */ -function statistics_user_cancel($edit, $account, $method) { - switch ($method) { - case 'user_cancel_reassign': - db_update('accesslog') - ->fields(array('uid' => 0)) - ->condition('uid', $account->uid) - ->execute(); - break; - } -} - -/** - * Implements hook_user_delete(). - */ -function statistics_user_delete($account) { - db_delete('accesslog') - ->condition('uid', $account->uid) - ->execute(); -} - -/** - * Implements hook_cron(). - */ -function statistics_cron() { - $statistics_timestamp = variable_get('statistics_day_timestamp', ''); - - if ((REQUEST_TIME - $statistics_timestamp) >= 86400) { - // Reset day counts. - db_update('node_counter') - ->fields(array('daycount' => 0)) - ->execute(); - variable_set('statistics_day_timestamp', REQUEST_TIME); - } - - // Clean up expired access logs (if applicable). - if (variable_get('statistics_flush_accesslog_timer', 259200) > 0) { - db_delete('accesslog') - ->condition('timestamp', REQUEST_TIME - variable_get('statistics_flush_accesslog_timer', 259200), '<') - ->execute(); - } -} - -/** - * Returns all time or today top or last viewed node(s). - * - * @param $dbfield - * one of - * - 'totalcount': top viewed content of all time. - * - 'daycount': top viewed content for today. - * - 'timestamp': last viewed node. - * - * @param $dbrows - * number of rows to be returned. - * - * @return - * A query result containing n.nid, n.title, u.uid, u.name of the selected node(s) - * or FALSE if the query could not be executed correctly. - */ -function statistics_title_list($dbfield, $dbrows) { - if (in_array($dbfield, array('totalcount', 'daycount', 'timestamp'))) { - $query = db_select('node', 'n'); - $query->addTag('node_access'); - $query->join('node_counter', 's', 'n.nid = s.nid'); - $query->join('users', 'u', 'n.uid = u.uid'); - - return $query - ->fields('n', array('nid', 'title')) - ->fields('u', array('uid', 'name')) - ->condition($dbfield, 0, '<>') - ->condition('n.status', 1) - ->orderBy($dbfield, 'DESC') - ->range(0, $dbrows) - ->execute(); - } - return FALSE; -} - - -/** - * Retrieves a node's "view statistics". - * - * @param $nid - * node ID - * - * @return - * An array with three entries: [0]=totalcount, [1]=daycount, [2]=timestamp - * - totalcount: count of the total number of times that node has been viewed. - * - daycount: count of the total number of times that node has been viewed "today". - * For the daycount to be reset, cron must be enabled. - * - timestamp: timestamp of when that node was last viewed. - */ -function statistics_get($nid) { - - if ($nid > 0) { - // Retrieve an array with both totalcount and daycount. - return db_query('SELECT totalcount, daycount, timestamp FROM {node_counter} WHERE nid = :nid', array(':nid' => $nid), array('target' => 'slave'))->fetchAssoc(); - } -} - -/** - * Implements hook_block_info(). - */ -function statistics_block_info() { - $blocks = array(); - - if (variable_get('statistics_count_content_views', 0)) { - $blocks['popular']['info'] = t('Popular content'); - // Too dynamic to cache. - $blocks['popular']['cache'] = DRUPAL_NO_CACHE; - } - return $blocks; -} - -/** - * Implements hook_block_configure(). - */ -function statistics_block_configure($delta = '') { - // Popular content block settings - $numbers = array('0' => t('Disabled')) + drupal_map_assoc(array(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 15, 20, 25, 30, 40)); - $form['statistics_block_top_day_num'] = array('#type' => 'select', '#title' => t("Number of day's top views to display"), '#default_value' => variable_get('statistics_block_top_day_num', 0), '#options' => $numbers, '#description' => t('How many content items to display in "day" list.')); - $form['statistics_block_top_all_num'] = array('#type' => 'select', '#title' => t('Number of all time views to display'), '#default_value' => variable_get('statistics_block_top_all_num', 0), '#options' => $numbers, '#description' => t('How many content items to display in "all time" list.')); - $form['statistics_block_top_last_num'] = array('#type' => 'select', '#title' => t('Number of most recent views to display'), '#default_value' => variable_get('statistics_block_top_last_num', 0), '#options' => $numbers, '#description' => t('How many content items to display in "recently viewed" list.')); - return $form; -} - -/** - * Implements hook_block_save(). - */ -function statistics_block_save($delta = '', $edit = array()) { - variable_set('statistics_block_top_day_num', $edit['statistics_block_top_day_num']); - variable_set('statistics_block_top_all_num', $edit['statistics_block_top_all_num']); - variable_set('statistics_block_top_last_num', $edit['statistics_block_top_last_num']); -} - -/** - * Implements hook_block_view(). - */ -function statistics_block_view($delta = '') { - if (user_access('access content')) { - $content = array(); - - $daytop = variable_get('statistics_block_top_day_num', 0); - if ($daytop && ($result = statistics_title_list('daycount', $daytop)) && ($node_title_list = node_title_list($result, t("Today's:")))) { - $content['top_day'] = $node_title_list; - $content['top_day']['#suffix'] = '
'; - } - - $alltimetop = variable_get('statistics_block_top_all_num', 0); - if ($alltimetop && ($result = statistics_title_list('totalcount', $alltimetop)) && ($node_title_list = node_title_list($result, t('All time:')))) { - $content['top_all'] = $node_title_list; - $content['top_all']['#suffix'] = '
'; - } - - $lasttop = variable_get('statistics_block_top_last_num', 0); - if ($lasttop && ($result = statistics_title_list('timestamp', $lasttop)) && ($node_title_list = node_title_list($result, t('Last viewed:')))) { - $content['top_last'] = $node_title_list; - $content['top_last']['#suffix'] = '
'; - } - - if (count($content)) { - $block['content'] = $content; - $block['subject'] = t('Popular content'); - return $block; - } - } -} - -/** - * It is possible to adjust the width of columns generated by the - * statistics module. - */ -function _statistics_link($path, $width = 35) { - $title = drupal_get_path_alias($path); - $title = truncate_utf8($title, $width, FALSE, TRUE); - return l($title, $path); -} - -function _statistics_format_item($title, $path) { - $path = ($path ? $path : '/'); - $output = ($title ? "$title
" : ''); - $output .= _statistics_link($path); - return $output; -} - -/** - * Implements hook_node_delete(). - */ -function statistics_node_delete($node) { - // clean up statistics table when node is deleted - db_delete('node_counter') - ->condition('nid', $node->nid) - ->execute(); -} - -/** - * Implements hook_ranking(). - */ -function statistics_ranking() { - if (variable_get('statistics_count_content_views', 0)) { - return array( - 'views' => array( - 'title' => t('Number of views'), - 'join' => array( - 'type' => 'LEFT', - 'table' => 'node_counter', - 'alias' => 'node_counter', - 'on' => 'node_counter.nid = i.sid', - ), - // Inverse law that maps the highest view count on the site to 1 and 0 to 0. - 'score' => '2.0 - 2.0 / (1.0 + node_counter.totalcount * CAST(:scale AS DECIMAL))', - 'arguments' => array(':scale' => variable_get('node_cron_views_scale', 0)), - ), - ); - } -} - -/** - * Implements hook_update_index(). - */ -function statistics_update_index() { - variable_set('node_cron_views_scale', 1.0 / max(1, db_query('SELECT MAX(totalcount) FROM {node_counter}')->fetchField())); -} diff --git a/modules/statistics/statistics.pages.inc b/modules/statistics/statistics.pages.inc deleted file mode 100644 index bb31f98..0000000 --- a/modules/statistics/statistics.pages.inc +++ /dev/null @@ -1,91 +0,0 @@ - t('Time'), 'field' => 'a.timestamp', 'sort' => 'desc'), - array('data' => t('Referrer'), 'field' => 'a.url'), - array('data' => t('User'), 'field' => 'u.name'), - array('data' => t('Operations'))); - - $query = db_select('accesslog', 'a', array('target' => 'slave'))->extend('PagerDefault')->extend('TableSort'); - $query->join('users', 'u', 'a.uid = u.uid'); - - $query - ->fields('a', array('aid', 'timestamp', 'url', 'uid')) - ->fields('u', array('name')) - ->condition(db_or() - ->condition('a.path', 'node/' . $node->nid) - ->condition('a.path', 'node/' . $node->nid . '/%', 'LIKE')) - ->limit(30) - ->orderByHeader($header); - - $result = $query->execute(); - $rows = array(); - foreach ($result as $log) { - $rows[] = array( - array('data' => format_date($log->timestamp, 'short'), 'class' => array('nowrap')), - _statistics_link($log->url), - theme('username', array('account' => $log)), - l(t('details'), "admin/reports/access/$log->aid"), - ); - } - - drupal_set_title($node->title); - $build['statistics_table'] = array( - '#theme' => 'table', - '#header' => $header, - '#rows' => $rows, - '#empty' => t('No statistics available.'), - ); - $build['statistics_pager'] = array('#theme' => 'pager'); - return $build; - } - else { - drupal_not_found(); - } -} - -function statistics_user_tracker() { - if ($account = user_load(arg(1))) { - - $header = array( - array('data' => t('Timestamp'), 'field' => 'timestamp', 'sort' => 'desc'), - array('data' => t('Page'), 'field' => 'path'), - array('data' => t('Operations'))); - $query = db_select('accesslog', 'a', array('target' => 'slave'))->extend('PagerDefault')->extend('TableSort'); - $query - ->fields('a', array('aid', 'timestamp', 'path', 'title')) - ->condition('uid', $account->uid) - ->limit(30) - ->orderByHeader($header); - - $result = $query->execute(); - $rows = array(); - foreach ($result as $log) { - $rows[] = array( - array('data' => format_date($log->timestamp, 'short'), 'class' => array('nowrap')), - _statistics_format_item($log->title, $log->path), - l(t('details'), "admin/reports/access/$log->aid")); - } - - drupal_set_title(format_username($account)); - $build['statistics_table'] = array( - '#theme' => 'table', - '#header' => $header, - '#rows' => $rows, - '#empty' => t('No statistics available.'), - ); - $build['statistics_pager'] = array('#theme' => 'pager'); - return $build; - } - else { - drupal_not_found(); - } -} diff --git a/modules/statistics/statistics.test b/modules/statistics/statistics.test deleted file mode 100644 index 126828f..0000000 --- a/modules/statistics/statistics.test +++ /dev/null @@ -1,444 +0,0 @@ -blocking_user = $this->drupalCreateUser(array( - 'access administration pages', - 'access site reports', - 'access statistics', - 'block IP addresses', - 'administer blocks', - 'administer statistics', - 'administer users', - )); - $this->drupalLogin($this->blocking_user); - - // Enable access logging. - variable_set('statistics_enable_access_log', 1); - variable_set('statistics_count_content_views', 1); - - // Insert dummy access by anonymous user into access log. - db_insert('accesslog') - ->fields(array( - 'title' => 'test', - 'path' => 'node/1', - 'url' => 'http://example.com', - 'hostname' => '192.168.1.1', - 'uid' => 0, - 'sid' => 10, - 'timer' => 10, - 'timestamp' => REQUEST_TIME, - )) - ->execute(); - } -} - -/** - * Tests that logging via statistics_exit() works for cached and uncached pages. - * - * Subclass DrupalWebTestCase rather than StatisticsTestCase, because we want - * to test requests from an anonymous user. - */ -class StatisticsLoggingTestCase extends DrupalWebTestCase { - public static function getInfo() { - return array( - 'name' => 'Statistics logging tests', - 'description' => 'Tests request logging for cached and uncached pages.', - 'group' => 'Statistics' - ); - } - - function setUp() { - parent::setUp('statistics'); - - // Ensure we have a node page to access. - $this->node = $this->drupalCreateNode(); - $this->auth_user = $this->drupalCreateUser(); - - // Enable page caching. - variable_set('cache', TRUE); - - // Enable access logging. - variable_set('statistics_enable_access_log', 1); - variable_set('statistics_count_content_views', 1); - - // Clear the logs. - db_truncate('accesslog'); - db_truncate('node_counter'); - } - - /** - * Verifies request logging for cached and uncached pages. - */ - function testLogging() { - $path = 'node/' . $this->node->nid; - $expected = array( - 'title' => $this->node->title, - 'path' => $path, - ); - - // Verify logging of an uncached page. - $this->drupalGet($path); - $this->assertIdentical($this->drupalGetHeader('X-Drupal-Cache'), 'MISS', t('Testing an uncached page.')); - $log = db_query('SELECT * FROM {accesslog}')->fetchAll(PDO::FETCH_ASSOC); - $this->assertTrue(is_array($log) && count($log) == 1, t('Page request was logged.')); - $this->assertEqual(array_intersect_key($log[0], $expected), $expected); - $node_counter = statistics_get($this->node->nid); - $this->assertIdentical($node_counter['totalcount'], '1'); - - // Verify logging of a cached page. - $this->drupalGet($path); - $this->assertIdentical($this->drupalGetHeader('X-Drupal-Cache'), 'HIT', t('Testing a cached page.')); - $log = db_query('SELECT * FROM {accesslog}')->fetchAll(PDO::FETCH_ASSOC); - $this->assertTrue(is_array($log) && count($log) == 2, t('Page request was logged.')); - $this->assertEqual(array_intersect_key($log[1], $expected), $expected); - $node_counter = statistics_get($this->node->nid); - $this->assertIdentical($node_counter['totalcount'], '2'); - - // Test logging from authenticated users - $this->drupalLogin($this->auth_user); - $this->drupalGet($path); - $log = db_query('SELECT * FROM {accesslog}')->fetchAll(PDO::FETCH_ASSOC); - // Check the 6th item since login and account pages are also logged - $this->assertTrue(is_array($log) && count($log) == 6, t('Page request was logged.')); - $this->assertEqual(array_intersect_key($log[5], $expected), $expected); - $node_counter = statistics_get($this->node->nid); - $this->assertIdentical($node_counter['totalcount'], '3'); - } -} - -/** - * Tests that report pages render properly, and that access logging works. - */ -class StatisticsReportsTestCase extends StatisticsTestCase { - public static function getInfo() { - return array( - 'name' => 'Statistics reports tests', - 'description' => 'Tests display of statistics report pages and access logging.', - 'group' => 'Statistics' - ); - } - - /** - * Verifies that 'Recent hits' renders properly and displays the added hit. - */ - function testRecentHits() { - $this->drupalGet('admin/reports/hits'); - $this->assertText('test', t('Hit title found.')); - $this->assertText('node/1', t('Hit URL found.')); - $this->assertText('Anonymous', t('Hit user found.')); - } - - /** - * Verifies that 'Top pages' renders properly and displays the added hit. - */ - function testTopPages() { - $this->drupalGet('admin/reports/pages'); - $this->assertText('test', t('Hit title found.')); - $this->assertText('node/1', t('Hit URL found.')); - } - - /** - * Verifies that 'Top referrers' renders properly and displays the added hit. - */ - function testTopReferrers() { - $this->drupalGet('admin/reports/referrers'); - $this->assertText('http://example.com', t('Hit referrer found.')); - } - - /** - * Verifies that 'Details' page renders properly and displays the added hit. - */ - function testDetails() { - $this->drupalGet('admin/reports/access/1'); - $this->assertText('test', t('Hit title found.')); - $this->assertText('node/1', t('Hit URL found.')); - $this->assertText('Anonymous', t('Hit user found.')); - } - - /** - * Verifies that access logging is working and is reported correctly. - */ - function testAccessLogging() { - $this->drupalGet('admin/reports/referrers'); - $this->drupalGet('admin/reports/hits'); - $this->assertText('Top referrers in the past 3 days', t('Hit title found.')); - $this->assertText('admin/reports/referrers', t('Hit URL found.')); - } - - /** - * Tests the "popular content" block. - */ - function testPopularContentBlock() { - // Visit a node to have something show up in the block. - $node = $this->drupalCreateNode(array('type' => 'page', 'uid' => $this->blocking_user->uid)); - $this->drupalGet('node/' . $node->nid); - - // Configure and save the block. - $block = block_load('statistics', 'popular'); - $block->theme = variable_get('theme_default', 'bartik'); - $block->status = 1; - $block->pages = ''; - $block->region = 'sidebar_first'; - $block->cache = -1; - $block->visibility = 0; - $edit = array('statistics_block_top_day_num' => 3, 'statistics_block_top_all_num' => 3, 'statistics_block_top_last_num' => 3); - module_invoke('statistics', 'block_save', 'popular', $edit); - drupal_write_record('block', $block); - - // Get some page and check if the block is displayed. - $this->drupalGet('user'); - $this->assertText('Popular content', t('Found the popular content block.')); - $this->assertText("Today's", t('Found today\'s popular content.')); - $this->assertText('All time', t('Found the alll time popular content.')); - $this->assertText('Last viewed', t('Found the last viewed popular content.')); - - $this->assertRaw(l($node->title, 'node/' . $node->nid), t('Found link to visited node.')); - } -} - -/** - * Tests that the visitor blocking functionality works. - */ -class StatisticsBlockVisitorsTestCase extends StatisticsTestCase { - public static function getInfo() { - return array( - 'name' => 'Top visitor blocking', - 'description' => 'Tests blocking of IP addresses via the top visitors report.', - 'group' => 'Statistics' - ); - } - - /** - * Blocks an IP address via the top visitors report and then unblocks it. - */ - function testIPAddressBlocking() { - // IP address for testing. - $test_ip_address = '192.168.1.1'; - - // Verify the IP address from accesslog appears on the top visitors page - // and that a 'block IP address' link is displayed. - $this->drupalLogin($this->blocking_user); - $this->drupalGet('admin/reports/visitors'); - $this->assertText($test_ip_address, t('IP address found.')); - $this->assertText(t('block IP address'), t('Block IP link displayed')); - - // Block the IP address. - $this->clickLink('block IP address'); - $this->assertText(t('IP address blocking'), t('IP blocking page displayed.')); - $edit = array(); - $edit['ip'] = $test_ip_address; - $this->drupalPost('admin/config/people/ip-blocking', $edit, t('Add')); - $ip = db_query("SELECT iid from {blocked_ips} WHERE ip = :ip", array(':ip' => $edit['ip']))->fetchField(); - $this->assertNotEqual($ip, FALSE, t('IP address found in database')); - $this->assertRaw(t('The IP address %ip has been blocked.', array('%ip' => $edit['ip'])), t('IP address was blocked.')); - - // Verify that the block/unblock link on the top visitors page has been - // altered. - $this->drupalGet('admin/reports/visitors'); - $this->assertText(t('unblock IP address'), t('Unblock IP address link displayed')); - - // Unblock the IP address. - $this->clickLink('unblock IP address'); - $this->assertRaw(t('Are you sure you want to delete %ip?', array('%ip' => $test_ip_address)), t('IP address deletion confirmation found.')); - $edit = array(); - $this->drupalPost('admin/config/people/ip-blocking/delete/1', NULL, t('Delete')); - $this->assertRaw(t('The IP address %ip was deleted.', array('%ip' => $test_ip_address)), t('IP address deleted.')); - } -} - -/** - * Test statistics administration screen. - */ -class StatisticsAdminTestCase extends DrupalWebTestCase { - protected $privileged_user; - protected $test_node; - - public static function getInfo() { - return array( - 'name' => 'Test statistics admin.', - 'description' => 'Tests the statistics admin.', - 'group' => 'Statistics' - ); - } - - function setUp() { - parent::setUp('statistics'); - $this->privileged_user = $this->drupalCreateUser(array('access statistics', 'administer statistics', 'view post access counter', 'create page content')); - $this->drupalLogin($this->privileged_user); - $this->test_node = $this->drupalCreateNode(array('type' => 'page', 'uid' => $this->privileged_user->uid)); - } - - /** - * Verifies that the statistics settings page works. - */ - function testStatisticsSettings() { - $this->assertFalse(variable_get('statistics_enable_access_log', 0), t('Access log is disabled by default.')); - $this->assertFalse(variable_get('statistics_count_content_views', 0), t('Count content view log is disabled by default.')); - - $this->drupalGet('admin/reports/pages'); - $this->assertRaw(t('No statistics available.'), t('Verifying text shown when no statistics is available.')); - - // Enable access log and counter on content view. - $edit['statistics_enable_access_log'] = 1; - $edit['statistics_count_content_views'] = 1; - $this->drupalPost('admin/config/system/statistics', $edit, t('Save configuration')); - $this->assertTrue(variable_get('statistics_enable_access_log'), t('Access log is enabled.')); - $this->assertTrue(variable_get('statistics_count_content_views'), t('Count content view log is enabled.')); - - // Hit the node. - $this->drupalGet('node/' . $this->test_node->nid); - - $this->drupalGet('admin/reports/pages'); - $this->assertText('node/1', t('Test node found.')); - - // Hit the node again (the counter is incremented after the hit, so - // "1 read" will actually be shown when the node is hit the second time). - $this->drupalGet('node/' . $this->test_node->nid); - $this->assertText('1 read', t('Node is read once.')); - - $this->drupalGet('node/' . $this->test_node->nid); - $this->assertText('2 reads', t('Node is read 2 times.')); - } - - /** - * Tests that when a node is deleted, the node counter is deleted too. - */ - function testDeleteNode() { - variable_set('statistics_count_content_views', 1); - - $this->drupalGet('node/' . $this->test_node->nid); - - $result = db_select('node_counter', 'n') - ->fields('n', array('nid')) - ->condition('n.nid', $this->test_node->nid) - ->execute() - ->fetchAssoc(); - $this->assertEqual($result['nid'], $this->test_node->nid, 'Verifying that the node counter is incremented.'); - - node_delete($this->test_node->nid); - - $result = db_select('node_counter', 'n') - ->fields('n', array('nid')) - ->condition('n.nid', $this->test_node->nid) - ->execute() - ->fetchAssoc(); - $this->assertFalse($result, 'Verifying that the node counter is deleted.'); - } - - /** - * Tests that accesslog reflects when a user is deleted. - */ - function testDeleteUser() { - variable_set('statistics_enable_access_log', 1); - - variable_set('user_cancel_method', 'user_cancel_delete'); - $this->drupalLogout($this->privileged_user); - $account = $this->drupalCreateUser(array('access content', 'cancel account')); - $this->drupalLogin($account); - $this->drupalGet('node/' . $this->test_node->nid); - - $account = user_load($account->uid, TRUE); - - $this->drupalGet('user/' . $account->uid . '/edit'); - $this->drupalPost(NULL, NULL, t('Cancel account')); - - $timestamp = time(); - $this->drupalPost(NULL, NULL, t('Cancel account')); - // Confirm account cancellation request. - $this->drupalGet("user/$account->uid/cancel/confirm/$timestamp/" . user_pass_rehash($account->pass, $timestamp, $account->login)); - $this->assertFalse(user_load($account->uid, TRUE), t('User is not found in the database.')); - - $this->drupalGet('admin/reports/visitors'); - $this->assertNoText($account->name, t('Did not find user in visitor statistics.')); - } - - /** - * Tests that cron clears day counts and expired access logs. - */ - function testExpiredLogs() { - variable_set('statistics_enable_access_log', 1); - variable_set('statistics_count_content_views', 1); - variable_set('statistics_day_timestamp', 8640000); - variable_set('statistics_flush_accesslog_timer', 1); - - $this->drupalGet('node/' . $this->test_node->nid); - $this->drupalGet('node/' . $this->test_node->nid); - $this->assertText('1 read', t('Node is read once.')); - - $this->drupalGet('admin/reports/pages'); - $this->assertText('node/' . $this->test_node->nid, t('Hit URL found.')); - - // statistics_cron will subtract the statistics_flush_accesslog_timer - // variable from REQUEST_TIME in the delete query, so wait two secs here to - // make sure the access log will be flushed for the node just hit. - sleep(2); - $this->cronRun(); - - $this->drupalGet('admin/reports/pages'); - $this->assertNoText('node/' . $this->test_node->nid, t('No hit URL found.')); - - $result = db_select('node_counter', 'nc') - ->fields('nc', array('daycount')) - ->condition('nid', $this->test_node->nid, '=') - ->execute() - ->fetchField(); - $this->assertFalse($result, t('Daycounter is zero.')); - } -} - -/** - * Test statistics token replacement in strings. - */ -class StatisticsTokenReplaceTestCase extends StatisticsTestCase { - public static function getInfo() { - return array( - 'name' => 'Statistics token replacement', - 'description' => 'Generates text using placeholders for dummy content to check statistics token replacement.', - 'group' => 'Statistics', - ); - } - - /** - * Creates a node, then tests the statistics tokens generated from it. - */ - function testStatisticsTokenReplacement() { - global $language; - - // Create user and node. - $user = $this->drupalCreateUser(array('create page content')); - $this->drupalLogin($user); - $node = $this->drupalCreateNode(array('type' => 'page', 'uid' => $user->uid)); - - // Hit the node. - $this->drupalGet('node/' . $node->nid); - $statistics = statistics_get($node->nid); - - // Generate and test tokens. - $tests = array(); - $tests['[node:total-count]'] = 1; - $tests['[node:day-count]'] = 1; - $tests['[node:last-view]'] = format_date($statistics['timestamp']); - $tests['[node:last-view:short]'] = format_date($statistics['timestamp'], 'short'); - - // Test to make sure that we generated something for each token. - $this->assertFalse(in_array(0, array_map('strlen', $tests)), t('No empty tokens generated.')); - - foreach ($tests as $input => $expected) { - $output = token_replace($input, array('node' => $node), array('language' => $language)); - $this->assertEqual($output, $expected, t('Statistics token %token replaced.', array('%token' => $input))); - } - } -} diff --git a/modules/statistics/statistics.tokens.inc b/modules/statistics/statistics.tokens.inc deleted file mode 100644 index c2c8fc3..0000000 --- a/modules/statistics/statistics.tokens.inc +++ /dev/null @@ -1,63 +0,0 @@ - t("Number of views"), - 'description' => t("The number of visitors who have read the node."), - ); - $node['day-count'] = array( - 'name' => t("Views today"), - 'description' => t("The number of visitors who have read the node today."), - ); - $node['last-view'] = array( - 'name' => t("Last view"), - 'description' => t("The date on which a visitor last read the node."), - 'type' => 'date', - ); - - return array( - 'tokens' => array('node' => $node), - ); -} - -/** - * Implements hook_tokens(). - */ -function statistics_tokens($type, $tokens, array $data = array(), array $options = array()) { - $url_options = array('absolute' => TRUE); - $replacements = array(); - - if ($type == 'node' & !empty($data['node'])) { - $node = $data['node']; - - foreach ($tokens as $name => $original) { - if ($name == 'total-count') { - $statistics = statistics_get($node->nid); - $replacements[$original] = $statistics['totalcount']; - } - elseif ($name == 'day-count') { - $statistics = statistics_get($node->nid); - $replacements[$original] = $statistics['daycount']; - } - elseif ($name == 'last-view') { - $statistics = statistics_get($node->nid); - $replacements[$original] = format_date($statistics['timestamp']); - } - } - - if ($created_tokens = token_find_with_prefix($tokens, 'last-view')) { - $statistics = statistics_get($node->nid); - $replacements += token_generate('date', $created_tokens, array('date' => $statistics['timestamp']), $options); - } - } - - return $replacements; -}