You are here

function nodeviewcount_node_view in Node view count 7

Same name and namespace in other branches
  1. 8 nodeviewcount.module \nodeviewcount_node_view()
  2. 7.3 nodeviewcount.module \nodeviewcount_node_view()
  3. 7.2 nodeviewcount.module \nodeviewcount_node_view()

Implements hook_node_view().

File

./nodeviewcount.module, line 74

Code

function nodeviewcount_node_view($node, $view_mode, $langcode) {
  if (!nodeviewcount_get_node_view_modes_count()) {

    // If nothing is checked then check the node view mode to the full mode.
    if ($view_mode != 'full') {
      return FALSE;
    }
  }
  elseif (!nodeviewcount_is_node_view_mode_count($view_mode)) {
    return FALSE;
  }
  if (!nodeviewcount_is_node_type_count($node)) {
    return FALSE;
  }
  global $user;
  if (!nodeviewcount_is_user_role_count($user)) {
    return FALSE;
  }
  $context = array(
    'node' => $node,
    'view_mode' => $view_mode,
    'langcode' => $langcode,
  );
  $result = module_invoke_all('nodeviewcount_insert', $context);
  if (in_array(FALSE, $result, TRUE)) {
    return FALSE;
  }
  $way_counting = variable_get('nodeviewcount_way_counting', NODEVIEWCOUNT_PHP_WAY_COUNT_VIEWS);
  if ($way_counting == NODEVIEWCOUNT_PHP_WAY_COUNT_VIEWS) {
    nodeviewcount_insert_node_view($node->nid, $user->uid);
  }
  else {
    $js_setting = array(
      'nodeviewcount' => array(
        'nodeviewcount_path' => 'nodeviewcount',
        'nodeviewcount_nid' => $node->nid,
        'nodeviewcount_uid' => $user->uid,
      ),
    );
    drupal_add_js($js_setting, 'setting');
    drupal_add_js(drupal_get_path('module', 'nodeviewcount') . '/theme/js/nodeviewcount.js');
  }
}