Spacing out with TechnoTag

The other day I had made a tweak to the TechnoTag plugin for WordPress. As I am using the plugin heavily, I had found another feature that I needed. Any space and comma are treated as delimiters for a list of tags in the ttaglist custom field for each post. I wanted to add a phrase with spaces. The first thing that I tried was to put quotes around it, but it didn’t work.

I went into the plugin editor once more and made a tweak. Rather then splitting the tags by commas and spaces, I decided to match valid entries with a preference over quoted phrases. It took a little while to figure out the pattern that I needed, but in the end I got the results that I wanted.

/(”[^”]*?”|’[^’]*?’|[^”‘, ]+)/

For anyone who uses the plugin, you may find the following code useful:

1 function ttags($text) {
2 global $ttag_image, $ttag_link;
3 $ttaglist = get_post_custom_values(‘ttaglist’);
4 $ttagvals = get_post_custom_values(‘ttag’);
5 if(!empty($ttaglist)) {
6 preg_match_all(“/(\”[^\”]*?\”|’[^’]*?’|[^\”‘, ]+)/”, $ttaglist[0], $ttags);
7 $ttags = array_merge($ttags[0], $ttagvals);
8 } else {
9 $ttags = $ttagvals;
10 }
11 if(!empty($ttags)) {
12 $ttags_list = ‘<span class=”Tags” title=”Technorati Tags”>’;
13 $ttags_list .= ‘<a href=”http://www.technorati.com/help/tags.html”>’;
14 $ttags_list .= ‘<img src=”‘ . $ttag_image . ‘” alt=”Technorati Tags” style=”vertical-align:middle;padding-left:3px;padding-right:3px;” /></a> Tags: ‘;
15 foreach ($ttags as $ttag) {
16 $ttag = trim($ttag, “, \t\r\n\0\x0B’\”");
17 $ttags_list .= ‘<a href=”‘ . $ttag_link . urlencode($ttag) . ‘” rel=”tag”>’;
18 $ttags_list .= htmlentities($ttag).‘</a>, ‘;
19 }
20 $ttags_list = rtrim($ttags_list, ‘, ‘);
21 $ttags_list .= ‘</span>’;
22 $text .= $ttags_list;
23 }
24 return $text;
25 }

Leave a Reply