move tag functions into the tag class

This commit is contained in:
Shish 2009-01-24 03:32:48 -08:00
parent a77feff4af
commit 394cff1909

View file

@ -241,11 +241,7 @@ class Image {
} }
public function set_tags($tags) { public function set_tags($tags) {
$tags = tag_explode($tags); $tags = Tag::resolve_list($tags);
$tags = array_map(array('Tag', 'resolve_alias'), $tags);
$tags = array_map(array('Tag', 'sanitise'), $tags);
$tags = array_iunique($tags); // remove any duplicate tags
assert(is_array($tags)); assert(is_array($tags));
assert(count($tags) > 0); assert(count($tags) > 0);
@ -485,6 +481,33 @@ class Tag {
return $tag; return $tag;
} }
public static function explode($tags) {
if(is_string($tags)) {
$tags = explode(' ', $tags);
}
else if(is_array($tags)) {
// do nothing
}
else {
die("tag_explode only takes strings or arrays");
}
$tags = array_map("trim", $tags);
$tag_array = array();
foreach($tags as $tag) {
if(is_string($tag) && strlen($tag) > 0) {
$tag_array[] = $tag;
}
}
if(count($tag_array) == 0) {
$tag_array = array("tagme");
}
return $tag_array;
}
public static function resolve_alias($tag) { public static function resolve_alias($tag) {
assert(is_string($tag)); assert(is_string($tag));
@ -512,6 +535,20 @@ class Tag {
return $resolved; return $resolved;
} }
} }
public static function resolve_list($tags) {
$tags = Tag::explode($tags);
$new = array();
foreach($tags as $tag) {
$new_set = explode(' ', Tag::resolve_alias($tag));
foreach($new_set as $new_one) {
$new[] = $new_one;
}
}
$new = array_map(array('Tag', 'sanitise'), $new);
$new = array_iunique($new); // remove any duplicate tags
return $new;
}
} }
@ -623,31 +660,4 @@ function get_thumbnail_size($orig_width, $orig_height) {
} }
} }
function tag_explode($tags) {
if(is_string($tags)) {
$tags = explode(' ', $tags);
}
else if(is_array($tags)) {
// do nothing
}
else {
die("tag_explode only takes strings or arrays");
}
$tags = array_map("trim", $tags);
$tag_array = array();
foreach($tags as $tag) {
if(is_string($tag) && strlen($tag) > 0) {
$tag_array[] = $tag;
}
}
if(count($tag_array) == 0) {
$tag_array = array("tagme");
}
return $tag_array;
}
?> ?>