Textpattern Forum

You are not logged in. Register | Login | Help

#1 2011-09-05 20:00:36

testdeputy
Member
Registered: 2011-05-29
Posts: 15

escaping '

i would like to customize my sortorder: ordering without, for example, starting The, De, Die, Der, etc.
Analog this tip (maybe old but still relevant..) I tried
<txp:article sort="replace(Title,'The ',''),Title" />

However, the ‘ is replaced (by Txp doSlash = mysql_real_escape_string, which is perfectly safe!).
But, how do I escape this, while writing my tag?

[edit] textile formatting

Last edited by testdeputy (2011-09-06 13:50:03)

Offline

#2 2011-09-05 20:40:15

Els
Admin
From: The Netherlands
Registered: 2004-06-06
Posts: 7,374
Website

Re: escaping '

If you don’t mind using a plugin, soo_article_filter will do what you want.


<txp:Els /> ;)
Tag Reference | Unexpected behaviour? Check the tag trace | Still no clue? Check the names of your custom fields

Offline

#3 2011-09-06 11:19:15

testdeputy
Member
Registered: 2011-05-29
Posts: 15

Re: escaping '

Thanks for suggesting, but the plugin soo_article_filter will not suffice:
“main issue is that if the page context is search results (i.e., the q query parameter is set), the tag will simply parse its contents and return them as is”.
My goal is, amongst other, ordering a search. The plugin will do nothing when a search is performed.

[edit] tried this a bit, also needs an xtra custom field … bummer

Remains the question: how to escape ‘?
I guess the answer is: can’t be done.

Last edited by testdeputy (2011-09-06 13:51:13)

Offline

#4 2011-09-06 13:23:50

uli
Moderator
From: Cologne/Köln
Registered: 2006-08-15
Posts: 2,951

Re: escaping '

Your SQL probably worked if you’d use or a in your titles, which – on top – is typographically correct. Is that enticing enough?


In bad weather I never leave home without wet_plugout, smd_where_used and adi_form_links

Offline

#5 2011-09-06 13:47:08

testdeputy
Member
Registered: 2011-05-29
Posts: 15

Re: escaping '

My working sql looks like ORDER BY REPLACE(Title,'The ','') DESC or similar.
A single quote is used here?

Offline

#6 2011-09-06 14:03:38

uli
Moderator
From: Cologne/Köln
Registered: 2006-08-15
Posts: 2,951

Re: escaping '

testdeputy wrote:

or similar.

What exactly do you want sorted out, or am I missing something? I was referring to cases like D'Artagnan, where no straight quotes should be used.


In bad weather I never leave home without wet_plugout, smd_where_used and adi_form_links

Offline

#7 2011-09-06 14:28:03

testdeputy
Member
Registered: 2011-05-29
Posts: 15

Re: escaping '

the tag I would like to write looks similar to
<txp:article limit="5" sort="REPLACE(REPLACE(REPLACE(Title,'The ',''),'A ',''),'An ','') ASC,Title" />

Offline

#8 2011-09-06 14:53:10

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 5,714
Website

Re: escaping '

Don’t think there’s a way round it because doSlash() is immutable.

The only way I can find is to use smd_query because it trusts you to escape your own data or provide paranoia-fuelled filtering rules. It only escapes GET/POST data by default, not your own query attribute, since the plugin assumes you trust yourself :-)

The following approach works for me, but you’ll need to be creative with the WHERE clause and quotes if you want to pull stuff out from the current section only:

<txp:smd_query query="SELECT * FROM textpattern
    WHERE 1=1
    ORDER BY TRIM(LEADING 'The ' FROM TRIM(LEADING 'A ' FROM TRIM(LEADING 'An ' FROM Title))) ASC,Title"
    populate="article" limit="10">
   <txp:permlink><txp:title /></txp:permlink>
   <txp:excerpt />
</txp:smd_query>

You can also paginate the results if you wish.

Last edited by Bloke (2011-09-06 14:53:40)


The smd plugin menagerie — for when you need one more gribble of power from Textpattern.

Txp Builders – finely-crafted code, design and Txp

Online

#9 2011-09-06 18:46:20

testdeputy
Member
Registered: 2011-05-29
Posts: 15

Re: escaping '

For now, underlying case is a private website, I decided to hack publish.php and disabled the doSlash on the sort clause.
Maybe I trust myself, hahaha (already hacked that file anyway, to enable search in custom fields), or will learn the hard way.

The smd_query plugin looks very interesting for another project, bookmarked!

And thanx very mucho for your WAAAAAY better suggestion of handling starting The, A, etc. with TRIM(LEADING).

[edit] taking it up a notch..
ORDER BY TRIM(LEADING LOWER('The ') FROM TRIM(LEADING LOWER('A ') FROM TRIM(LEADING LOWER('An ') FROM LOWER(Title)))) ASC,Title
saves a bit when handling ‘the’ against ‘The’, ‘a’ against ‘A’, etc.
It’s a long way to perfectness, but a fine road to ride.

Last edited by testdeputy (2011-09-06 23:48:51)

Offline

#10 2011-09-06 19:34:15

Gocom
Developer
Registered: 2006-07-14
Posts: 4,405
Website

Re: escaping '

testdeputy wrote:

already hacked that file anyway, to enable search in custom fields

Textpattern has preference option for adding fields to the search, hacking the file isn’t needed if you are fine with the default matching method. See wet_haystack for automated index builder.


Rah-plugins | What? I’m a little confused… again :-) <txp:is_god />

Offline

Board footer

Powered by FluxBB