Freetags with apostrophe

Found a bug? Tell us!!
Post Reply
mattsches
Regular
Posts: 440
Joined: Sat Nov 05, 2005 9:35 pm
Location: Wiesbaden, Germany
Contact:

Freetags with apostrophe

Post by mattsches »

I just updated to the latest freetag and tagcloud plugins. Problem is that I have some tags with apostrophes in them; an apostrophe does not seem to be escaped in the SQL query. Consequently, after clicking on one of these tags in the tag cloud, I get an SQL error:

Code: Select all

WHERE isdraft = 'false' AND e.timestamp <= '1131224625' AND entrytags.tag = 'fat freddy's drop'   AND
One little question (slightly OT): How can I prevent tags from being displayed in the tag cloud that exist only once ("orphaned tags")?
garvinhicking
Core Developer
Posts: 30022
Joined: Tue Sep 16, 2003 9:45 pm
Location: Cologne, Germany
Contact:

Re: Freetags with apostrophe

Post by garvinhicking »

Hi!

Thanks a lot for mentioning this. It can be fixed with this patch:

Code: Select all

Index: serendipity_event_freetag.php
===================================================================
RCS file: /cvsroot/php-blog/additional_plugins/serendipity_event_freetag/serendipity_event_freetag.php,v
retrieving revision 1.28
diff -u -r1.28 serendipity_event_freetag.php
--- serendipity_event_freetag.php       3 Nov 2005 12:13:47 -0000       1.28
+++ serendipity_event_freetag.php       6 Nov 2005 13:01:24 -0000
@@ -458,7 +458,7 @@
                 case 'frontend_fetchentries':
                 case 'frontend_fetchentry':
                     if (!empty($this->tags['show'])) {
-                        $showtag = $this->tags['show'];
+                        $showtag = serendipity_db_escape_string($this->tags['show']);
                     } else if (!empty($serendipity['GET']['tag'])) {
                         $showtag = serendipity_db_escape_string(strtolower(urldecode($serendipity['GET']['tag'])));
                     }
I also committed that, of course.

About your orphaned tags, I must admit I'm not much into the code and you might want to ask Jonathan Arkell about that. But in the place where I modified the code above you find this:

Code: Select all

if (!empty($showtag)) {
                   if (is_string($showtag)) {
                       $join = "LEFT JOIN {$serendipity['dbPrefix']}entrytags AS entrytags ON (e.id = entrytags.entryid) ";
                       $cond = "entrytags.tag = '$showtag' ";
                   }
If you put this into the if-structure:

Code: Select all

                       $eventData['having'] = " HAVING count(entrytags.tag) > 1";
This might(!) only show tags which have more than one relevance...

HTH,
Garvin
# Garvin Hicking (s9y Developer)
# Did I help you? Consider making me happy: http://wishes.garv.in/
# or use my PayPal account "paypal {at} supergarv (dot) de"
# My "other" hobby: http://flickr.garv.in/
mattsches
Regular
Posts: 440
Joined: Sat Nov 05, 2005 9:35 pm
Location: Wiesbaden, Germany
Contact:

Post by mattsches »

Thanks very much for fixing the bug, works like a charm now. :D

About the orphaned tags: No, your suggestion does not work. But now I've got an idea about where in the code to look for a solution. As soon as I find the time and changed it, I will post it here. Otherwise I'll have to ask Jonathan Arkell, but I'm pretty confident that I can figure it out myself. :wink: Thanks again.
garvinhicking
Core Developer
Posts: 30022
Joined: Tue Sep 16, 2003 9:45 pm
Location: Cologne, Germany
Contact:

Post by garvinhicking »

That would be great, of course. Good luck! :)

Regards,
Garvin
# Garvin Hicking (s9y Developer)
# Did I help you? Consider making me happy: http://wishes.garv.in/
# or use my PayPal account "paypal {at} supergarv (dot) de"
# My "other" hobby: http://flickr.garv.in/
mattsches
Regular
Posts: 440
Joined: Sat Nov 05, 2005 9:35 pm
Location: Wiesbaden, Germany
Contact:

Display only tags which have been used >1 times

Post by mattsches »

Well, I found a simple solution. Edited serendipity_plugin_freetag.php:

Code: Select all

87c87,89
<    $tags[$r['tag']] = $r['total']; 
---
>    if ($r['total'] > 1) {
>        $tags[$r['tag']] = $r['total']; 
>    }
I don't know if this is against all good practice, but it works for me :wink: Modifying the preceding query using a WHERE clause didn't work, though.
Post Reply