From 307d187c6ca4fd31523ef9b9d0b483021126328c Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Fri, 23 Jan 2009 14:20:05 +0100 Subject: rework assigning articles to tags --- functions.php | 122 +++++++++++++++++++++++----------------------------------- 1 file changed, 49 insertions(+), 73 deletions(-) (limited to 'functions.php') diff --git a/functions.php b/functions.php index b4636927c..2b81a10c5 100644 --- a/functions.php +++ b/functions.php @@ -4533,54 +4533,15 @@ print "
" . $line["title"] . "$entry_author
"; } - $tags = get_article_tags($link, $id); - - $tags_str = ""; - $tags_nolinks_str = ""; - $f_tags_str = ""; - - $num_tags = 0; - - if ($_SESSION["theme"] == "3pane") { - $tag_limit = 3; - } else { - $tag_limit = 6; - } - - foreach ($tags as $tag) { - $num_tags++; - $tag_escaped = str_replace("'", "\\'", $tag); - - $tag_str = "$tag, "; - - if ($num_tags == $tag_limit) { - $tags_str .= "…"; - $tags_nolinks_str .= "…"; - - } else if ($num_tags < $tag_limit) { - $tags_str .= $tag_str; - $tags_nolinks_str .= "$tag, "; - } - $f_tags_str .= $tag_str; - } - - $tags_str = preg_replace("/, $/", "", $tags_str); - $tags_nolinks_str = preg_replace("/, $/", "", $tags_nolinks_str); - $f_tags_str = preg_replace("/, $/", "", $f_tags_str); - - $all_tags_div = "
All Tags: $f_tags_str
"; - $tags_str = preg_replace("/\.\.\.$/", "$all_tags_div", $tags_str); + $tags_str = format_tags_string(get_article_tags($link, $id), $id); if (!$entry_comments) $entry_comments = " "; # placeholder - if (!$tags_str) $tags_str = ''.__('no tags').''; - if (!$tags_nolinks_str) $tags_nolinks_str = ''.__('no tags').''; - print "
Tags"; if (!$zoom_mode) { - print "$tags_str + print "$tags_str (+)"; @@ -4597,8 +4558,6 @@ style=\"cursor : pointer\" style=\"cursor : pointer\" onclick=\"zoomToArticle($id)\" alt='Zoom' title='".__('Show article summary in new window')."'>"; - } else { - print "$tags_nolinks_str"; } print "
"; print "
$entry_comments
"; @@ -4609,8 +4568,6 @@ print "
"; - #print "
".__('Tags:')." $f_tags_str
"; - $article_content = sanitize_rss($link, $line["content"]); if (get_pref($link, 'OPEN_LINKS_IN_NEW_WINDOW')) { @@ -5253,38 +5210,15 @@ alt='Zoom' title='".__('Show article summary in new window')."'>"; - $tags = get_article_tags($link, $id); - - $tags_str = ""; - $full_tags_str = ""; - $num_tags = 0; - - foreach ($tags as $tag) { - $num_tags++; - $full_tags_str .= "$tag, "; - if ($num_tags < 5) { - $tags_str .= "$tag, "; - } else if ($num_tags == 5) { - $tags_str .= "…"; - } - } - - $tags_str = preg_replace("/, $/", "", $tags_str); - $full_tags_str = preg_replace("/, $/", "", $full_tags_str); - - $all_tags_div = "
All Tags: $full_tags_str
"; - - $tags_str = preg_replace("/\.\.\.$/", "$all_tags_div", $tags_str); - - - if ($tags_str == "") $tags_str = "no tags"; + $tags_str = format_tags_string(get_article_tags($link, $id), $id); // print ""; print " - Tags $tags_str (+)"; + Tags + $tags_str + (+)"; print ""; @@ -6011,4 +5945,46 @@ } } } + + function format_tags_string($tags, $id) { + + $tags_str = ""; + $tags_nolinks_str = ""; + + $num_tags = 0; + + if ($_SESSION["theme"] == "3pane") { + $tag_limit = 3; + } else { + $tag_limit = 6; + } + + $formatted_tags = array(); + + foreach ($tags as $tag) { + $num_tags++; + $tag_escaped = str_replace("'", "\\'", $tag); + + $tag_str = "$tag"; + + array_push($formatted_tags, $tag_str); + + if ($num_tags == $tag_limit) { + break; + } + } + + $tags_str = implode(", ", $formatted_tags); + + if ($num_tags < count($tags)) { + $tags_str .= ", …"; + } + + if ($num_tags == 0) { + $tags_str = __("no tags"); + } + + return $tags_str; + + } ?> -- cgit v1.2.3