You are here

function _uniqueness_content_nodetitle in Uniqueness 7

Same name and namespace in other branches
  1. 6 uniqueness.module \_uniqueness_content_nodetitle()

Searches for related content by comparing the node title with the title of existing nodes.

1 call to _uniqueness_content_nodetitle()
uniqueness_content in ./uniqueness.module
Perform lookup of related or similar content.

File

./uniqueness.module, line 401
uniqueness.module

Code

function _uniqueness_content_nodetitle($values) {
  if (empty($values['title'])) {
    return array();
  }

  // Query node table.
  $q = db_select('node', 'n')
    ->fields('n', array(
    'nid',
    'title',
    'status',
  ))
    ->condition('n.title', '%' . db_like($values['title']) . '%', 'LIKE');
  if (isset($values['type'])) {
    $q
      ->condition('n.type', $values['type']);
  }
  if (isset($values['nid']) && is_numeric($values['nid'])) {
    $q
      ->condition('n.nid', $values['nid'], '<>');
  }

  // If user is not allowed to bypass node access, restrict access to
  // unpublished content.
  if (!user_access('bypass node access')) {
    if (user_access('view own unpublished content')) {
      $q
        ->condition(db_or()
        ->condition('n.status', NODE_PUBLISHED)
        ->condition('n.uid', $GLOBALS['user']->uid));
    }
    else {
      $q
        ->condition('n.status', NODE_PUBLISHED);
    }
  }

  // Range is +1 for "... and more".
  $q
    ->range(0, variable_get('uniqueness_results_max', 10) + 1);

  // Respect node access.
  $q
    ->addTag('node_access');
  return $q
    ->execute()
    ->fetchAllAssoc('nid', PDO::FETCH_ASSOC);
}