Example #1
0
 /**
  *	Add a filter for a tag
  *
  *	@param $tag -- the tag string to filter on
  */
 public function add_tag_filter($tag)
 {
     if (!trim($tag)) {
         return;
     }
     global $vbphrase;
     require_once DIR . '/includes/class_taggablecontent.php';
     $tags = vB_Taggable_Content_Item::split_tag_list($tag);
     foreach ($tags as $key => $tag) {
         $tag = trim($tag);
         $verified_tag = datamanager_init('tag', $GLOBALS['vbulletin'], ERRTYPE_ARRAY);
         if (!$verified_tag->fetch_by_tagtext($tag)) {
             //$this->errors[] = 'invalid_tag_specified';
             $this->add_error('invalid_tag_specified');
             unset($tags[$key]);
         } else {
             //if this is a synonym search against the canonical tag.
             if ($verified_tag->is_synonym()) {
                 $synonym = $verified_tag;
                 $verified_tag = $verified_tag->fetch_canonical_tag();
                 $this->set_tag_display_string($verified_tag, $synonym);
             } else {
                 $this->set_tag_display_string($verified_tag);
             }
             $tags[$key] = $verified_tag->fetch_field("tagid");
         }
     }
     //for now, only allow one tag in a search.
     $this->add_filter('tag', vB_Search_Core::OP_EQ, $tags[0], true);
 }
Example #2
0
 /**
  *	Add a filter for a tag
  *
  *	@param string $tag - the tag string to filter on
  */
 public function add_tag_filter($tags)
 {
     require_once DIR . '/includes/class_taggablecontent.php';
     if (!is_array($tags)) {
         $tags = vB_Taggable_Content_Item::split_tag_list($tags);
     }
     $existing_tags = array();
     $query = vB::getDbAssertor()->assertQuery('vBForum:tag', array(vB_dB_Query::TYPE_KEY => vB_dB_Query::QUERY_SELECT, 'tagtext' => $tags));
     while ($query and $query->valid()) {
         $row = $query->current();
         $existing_tags[$row['tagtext']] = $row['tagid'];
         $index = array_search($row['tagtext'], $tags);
         if ($index !== false) {
             unset($tags[$index]);
         }
         $row = $query->next();
     }
     /** @todo rewrite this part */
     //		foreach ($tags as $key => $tag)
     //		{
     //			$tag = trim($tag);
     //
     //			$verified_tag = datamanager_init('tag', vB::getDatastore(), vB_DataManager_Constants::ERRTYPE_ARRAY);
     //			if (!$verified_tag->fetch_by_tagtext($tag))
     //			{
     //				//$this->errors[] = 'invalid_tag_specified';
     //				$this->add_error('invalid_tag_specified');
     //				unset($tags[$key]);
     //			}
     //			else
     //			{
     //				//if this is a synonym search against the canonical tag.
     //				if ($verified_tag->is_synonym())
     //				{
     //					$synonym = $verified_tag;
     //					$verified_tag = $verified_tag->fetch_canonical_tag();
     //					$this->set_tag_display_string($verified_tag, $synonym);
     //				}
     //				else
     //				{
     //					$this->set_tag_display_string($verified_tag);
     //				}
     //				$tags[$key] = $verified_tag->fetch_field("tagid");
     //			}
     //
     //		}
     $this->add_filter('tag', vB_Search_Core::OP_EQ, $existing_tags, true);
     if (!empty($tags)) {
         foreach ($tags as $tag) {
             $this->add_null_filter("Tag {$tag} does not exist.");
         }
     }
     return $existing_tags;
 }