From 394cff19093e9a3efa45f5ea426c864104724b4e Mon Sep 17 00:00:00 2001 From: Shish Date: Sat, 24 Jan 2009 03:32:48 -0800 Subject: [PATCH] move tag functions into the tag class --- core/imageboard.pack.php | 74 +++++++++++++++++++++++----------------- 1 file changed, 42 insertions(+), 32 deletions(-) diff --git a/core/imageboard.pack.php b/core/imageboard.pack.php index b0d04bfe..371380a6 100644 --- a/core/imageboard.pack.php +++ b/core/imageboard.pack.php @@ -241,11 +241,7 @@ class Image { } public function set_tags($tags) { - $tags = tag_explode($tags); - - $tags = array_map(array('Tag', 'resolve_alias'), $tags); - $tags = array_map(array('Tag', 'sanitise'), $tags); - $tags = array_iunique($tags); // remove any duplicate tags + $tags = Tag::resolve_list($tags); assert(is_array($tags)); assert(count($tags) > 0); @@ -485,6 +481,33 @@ class 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) { assert(is_string($tag)); @@ -512,6 +535,20 @@ class Tag { 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; -} - ?>