You are here

public function nexcloud::search in filedepot 7

Same name and namespace in other branches
  1. 6 nexcloud.class.php \nexcloud::search()

File

./nexcloud.class.php, line 493
nexcloud.class.php Tag Cloud class for the filedepot module

Class

nexcloud
@file nexcloud.class.php Tag Cloud class for the filedepot module

Code

public function search($query) {
  $query = addslashes($query);
  $itemids = array();

  // Get a list of Tag ID's for the tag words in the query
  $sql = "SELECT id,tagword FROM {nextag_words} ";
  $asearchtags = explode(',', stripslashes($query));
  if (count($asearchtags) > 1) {
    $sql .= "WHERE ";
    $i = 1;
    foreach ($asearchtags as $tag) {
      $tag = addslashes($tag);
      if ($i > 1) {
        $sql .= "OR tagword = '{$tag}' ";
      }
      else {
        $sql .= "tagword = '{$tag}' ";
      }
      $i++;
    }
  }
  else {
    $sql .= "WHERE tagword = '{$query}' ";
  }
  $query = db_query($sql);
  $tagids = array();
  $sql = "SELECT itemid FROM {nextag_items} WHERE type='{$this->_type}' AND ";
  $i = 1;
  while ($A = $query
    ->fetchAssoc()) {
    $tagids[] = $A['id'];

    // REGEX - search for id that is the first id or has a leading comma must then have a trailing , or be the end of the field
    if ($i > 1) {
      $sql .= "AND (tags LIKE '{$A['id']},%' OR tags LIKE '%,{$A['id']}' OR tags LIKE '%,{$A['id']},%' OR tags = '{$A['id']}')";

      //"AND tags REGEXP '(^|,){$A['id']}(,|$)' ";
    }
    else {
      $sql .= "(tags LIKE '{$A['id']},%' OR tags LIKE '%,{$A['id']}' OR tags LIKE '%,{$A['id']},%' OR tags = '{$A['id']}')";

      //"tags REGEXP '(^|,){$A['id']}(,|$)' ";
    }
    $i++;
  }
  if (count($tagids) > 0) {
    $this->_activetags = implode(',', $tagids);
    $query = db_query($sql);
    while ($A = $query
      ->fetchAssoc()) {
      $itemids[] = $A['itemid'];
    }
    if (count($itemids) > 0) {
      return $itemids;
    }
    else {
      return FALSE;
    }
  }
  else {
    return FALSE;
  }
}