tag functions in a tag class
This commit is contained in:
parent
820f60d5e8
commit
df594aee6d
@ -260,38 +260,6 @@ class Image {
|
||||
}
|
||||
}
|
||||
|
||||
public function resolve_alias($tag) {
|
||||
assert(is_string($tag));
|
||||
$newtag = $this->database->db->GetOne("SELECT newtag FROM aliases WHERE oldtag=?", array($tag));
|
||||
if(!empty($newtag)) {
|
||||
return $newtag;
|
||||
} else {
|
||||
return $tag;
|
||||
}
|
||||
}
|
||||
|
||||
public function resolve_wildcard($tag) {
|
||||
if(strpos($tag, "%") === false && strpos($tag, "_") === false) {
|
||||
return array($tag);
|
||||
}
|
||||
else {
|
||||
$newtags = $this->database->db->GetCol("SELECT tag FROM tags WHERE tag LIKE ?", array($tag));
|
||||
if(count($newtags) > 0) {
|
||||
$resolved = $newtags;
|
||||
} else {
|
||||
$resolved = array($tag);
|
||||
}
|
||||
return $resolved;
|
||||
}
|
||||
}
|
||||
|
||||
public function sanitise($tag) {
|
||||
assert(is_string($tag));
|
||||
$tag = preg_replace("/[\s?*]/", "", $tag);
|
||||
$tag = preg_replace("/\.+/", ".", $tag);
|
||||
$tag = preg_replace("/^(\.+[\/\\\\])+/", "", $tag);
|
||||
return $tag;
|
||||
}
|
||||
|
||||
/*
|
||||
* Other actions
|
||||
@ -355,7 +323,7 @@ class Image {
|
||||
$term = substr($term, 1);
|
||||
}
|
||||
|
||||
$term = $database->resolve_alias($term);
|
||||
$term = Tag::resolve_alias($term);
|
||||
|
||||
$stpe = new SearchTermParseEvent($term, $terms);
|
||||
send_event($stpe);
|
||||
@ -368,7 +336,7 @@ class Image {
|
||||
$term = str_replace("*", "%", $term);
|
||||
$term = str_replace("?", "_", $term);
|
||||
if(!preg_match("/^[%_]+$/", $term)) {
|
||||
$expansions = $database->resolve_wildcard($term);
|
||||
$expansions = Tag::resolve_wildcard($term);
|
||||
if($positive) $positive_tag_count++;
|
||||
foreach($expansions as $term) {
|
||||
$tag_querylets[] = new TagQuerylet($term, $positive);
|
||||
@ -485,6 +453,44 @@ class Image {
|
||||
}
|
||||
}
|
||||
|
||||
class Tag {
|
||||
public static function sanitise($tag) {
|
||||
assert(is_string($tag));
|
||||
$tag = preg_replace("/[\s?*]/", "", $tag);
|
||||
$tag = preg_replace("/\.+/", ".", $tag);
|
||||
$tag = preg_replace("/^(\.+[\/\\\\])+/", "", $tag);
|
||||
return $tag;
|
||||
}
|
||||
|
||||
public static function resolve_alias($tag) {
|
||||
assert(is_string($tag));
|
||||
|
||||
global $database;
|
||||
$newtag = $database->db->GetOne("SELECT newtag FROM aliases WHERE oldtag=?", array($tag));
|
||||
if(!empty($newtag)) {
|
||||
return $newtag;
|
||||
} else {
|
||||
return $tag;
|
||||
}
|
||||
}
|
||||
|
||||
public static function resolve_wildcard($tag) {
|
||||
if(strpos($tag, "%") === false && strpos($tag, "_") === false) {
|
||||
return array($tag);
|
||||
}
|
||||
else {
|
||||
global $database;
|
||||
$newtags = $database->db->GetCol("SELECT tag FROM tags WHERE tag LIKE ?", array($tag));
|
||||
if(count($newtags) > 0) {
|
||||
$resolved = $newtags;
|
||||
} else {
|
||||
$resolved = array($tag);
|
||||
}
|
||||
return $resolved;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *\
|
||||
* Debugging functions *
|
||||
|
Loading…
x
Reference in New Issue
Block a user