You are here

function reviews_user_reviewed_load in Reviews 7

Menu callback. Returns the argument passed form the URL if content type allows reviews and reviews are enabled globally and the current user has not already reviewed the node.

1 call to reviews_user_reviewed_load()
reviews_node_view in ./reviews.module
Implements hook_node_view().

File

./reviews.module, line 215
This file defines all the necessary hooks and functions to create a system for enabling and authoring content reviews on a per content type basis.

Code

function reviews_user_reviewed_load($arg) {
  global $user;

  // Check if reviews are enabled, if not return FALSE immediately.
  if (!reviews_reviews_enabled()) {
    return FALSE;
  }

  // Load the node to find it's type.
  $node = node_load($arg);
  $node_type = $node->type;

  // Get the Array containing which content types are allowed reviews.
  $reviewable_ctypes = variable_get('reviews_enabled_content_types', array());

  // Check if reviews are allowed for the node type, if not return FALSE.
  if (isset($reviewable_ctypes[$node_type]) && $reviewable_ctypes[$node_type] === 0) {
    return FALSE;
  }

  // Now check to see if the user has already reviewed this node, if they have
  // return FALSE.
  $user_reviewed = reviews_check_user_review($node->nid, $user->uid);
  if ($user_reviewed) {
    return FALSE;
  }

  // If all aobve checks are OK we return TRUE and present the user with the
  // review option.
  return $arg;
}