Textpattern CMS support forum

You are not logged in. Register | Login | Help

#11 2017-12-13 11:37:43

uli
Moderator
From: Cologne
Registered: 2006-08-15
Posts: 4,152

Re: Poll: useful 'escape' transforms

Now that we’ll be able to even rtrim and ltrim white space, wouldn’t it be desirable to have the variable tag calculate in order to do some simple, user defined maths?

E.g.
var “current iteration-no.” plus 1
var “current iteration-no.” < n
var “image width” minus 90px
etc.


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

Offline

#12 2017-12-13 11:55:24

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 8,458
Website

Re: Poll: useful 'escape' transforms

uli wrote #308288:

Now that we’ll be able to even rtrim and ltrim white space, wouldn’t it be desirable to have the variable tag calculate in order to do some simple, user defined maths?

We do. :-) See example 1, for instance.


The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.

Txp Builders – finely-crafted code, design and Txp

Offline

#13 2017-12-13 12:30:03

etc
Developer
Registered: 2010-11-11
Posts: 2,949
Website

Re: Poll: useful 'escape' transforms

Speaking of <txp:evaluate />, we can extend the list of XPath 1.0 functions to any PHP string function judged safe to use, like str_replace. In this case using arguments would be straightforward:

<txp:evaluate query='str_replace("from", "to", <txp:body escape="quote" />)' />

Howzat?


etc_[ query | search | pagination | date | tree | cache ]

Offline

#14 2017-12-13 12:34:01

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 8,458
Website

Re: Poll: useful 'escape' transforms

etc wrote #308290:

Howzat?

Magic!

EDIT: escape="quote" isn’t in your list in the OP. Can it be added, as it has value?

Last edited by Bloke (2017-12-13 12:36:52)


The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.

Txp Builders – finely-crafted code, design and Txp

Offline

#15 2017-12-13 14:21:31

etc
Developer
Registered: 2010-11-11
Posts: 2,949
Website

Re: Poll: useful 'escape' transforms

Bloke wrote #308291:

escape="quote" isn’t in your list in the OP. Can it be added, as it has value?

Yes, but I’m not sure for the name. What it currently does is transform a string in a XPath-readable format:

Hello, world! => 'Hello, world!' // ok, but
Hi, "m'dam"! => concat('Hi, "m', "'", 'dam"!')

I doubt it could be useful elsewhere than <txp:evaluate /> and have not found a more robust solution to escape quotes in XPath functions without transforming them into HTML entities (which we don’t want). Still investigating.

And while we are here, which functions to add to the pool?


etc_[ query | search | pagination | date | tree | cache ]

Offline

#16 2017-12-13 15:22:36

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 8,458
Website

Re: Poll: useful 'escape' transforms

etc wrote #308295:

Yes, but I’m not sure for the name.

I was wondering that too. Tricky. ‘quote’ is the most logical choice, I suppose.

have not found a more robust solution to escape quotes in XPath functions

Can our txpspecialchars() help? That handles both double-quotes and apostrophes, but I dunno how clever it is if the string contains both.

which functions to add to the pool?

Can’t think of any others that don’t require parameters. Possibly some way to remove newlines but preserve spaces? Is that helpful, as distinct from trim? Probably not…

EDIT: or do you mean functions for use in <txp:evaluate>?

Last edited by Bloke (2017-12-13 15:23:49)


The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.

Txp Builders – finely-crafted code, design and Txp

Offline

#17 2017-12-13 15:53:42

etc
Developer
Registered: 2010-11-11
Posts: 2,949
Website

Re: Poll: useful 'escape' transforms

Bloke wrote #308299:

Can our txpspecialchars() help? That handles both double-quotes and apostrophes, but I dunno how clever it is if the string contains both.

No, it just replaces them with &#039; and &quot;, but this is not always desired. And escape="html" is already alias of txpspecialchars($thing).

do you mean functions for use in <txp:evaluate>?

Yes. We could even make it a user pref (and caveat utilitor), but then code copy-pasting would not always work (though I don’t care).


etc_[ query | search | pagination | date | tree | cache ]

Offline

#18 2017-12-13 16:36:59

uli
Moderator
From: Cologne
Registered: 2006-08-15
Posts: 4,152

Re: Poll: useful 'escape' transforms

Bloke wrote #308289:

We do. :-)

Sigh! :]


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

Offline

#19 2017-12-14 00:42:34

phiw13
Plugin Author
From: Japan
Registered: 2004-02-27
Posts: 1,546
Website

Re: Poll: useful 'escape' transforms

escape="textile"

Do I understand correctly?

I have this in the caption field of an image: a _test_ image - something *bold*.

In the form used to insert images in the body of an article, I have this:

<figcaption itemprop="caption"><txp:image_info type="caption" escape="textile" /></figcaption>

but no transform happens, the string is outputted verbatim, with underscores and asterisks.

Edit: simple example, inserted in a page template:

<txp:images …… >
  <figure>
    <a href="<txp:image_url />" class="image-gallery-link">
      <txp:image />
    </a>
    <txp:image_info type="caption" escape="textile" wraptag="figcaption" />
  </figure>
</txp:images>

Last edited by phiw13 (2017-12-14 05:00:02)

Offline

#20 2017-12-14 09:17:28

etc
Developer
Registered: 2010-11-11
Posts: 2,949
Website

Re: Poll: useful 'escape' transforms

phiw13 wrote #308304:

escape="textile"

Do I understand correctly?

Short answer: tags like <txp:image_info /> that already had escape attribute are not affected by the global escape, to avoid escaping twice. They must be modified individually to comply with globals.

Longer answer: I did modify some tags, but not this one, since it escapes only some parts of its output, unlike the global escape applied to the whole output, including the eventual wrap tag. But it shouldn’t be difficult to plug the global escape in, leave it with me. And thanks for testing! :-)


etc_[ query | search | pagination | date | tree | cache ]

Offline

Board footer

Powered by FluxBB