Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#61 2012-09-23 21:52:13

maniqui
Member
From: Buenos Aires, Argentina
Registered: 2004-10-10
Posts: 3,070
Website

Re: rah_function // Every PHP function is a tag

Hi Jukka.
Not sure what I’m doing wrong here.
With rah_function v0.6, I’m trying this:

<txp:rah_function call="parse_url" url="http://www.example.com/test/abc" _intcomponent="PHP_URL_PATH" />

I get just http in the output

While this equivalent:

<txp:php>
  echo parse_url("http://www.example.com/test/abc", PHP_URL_PATH);
</txp:php>

correctly outputs /test/abc.

I’ve skimmed over plugin help docs, but couldn’t find a clue. Enlighten me. Thanks. :)


La música ideas portará y siempre continuará

TXP Builders – finely-crafted code, design and txp

Offline

#62 2012-09-24 03:18:46

Gocom
Developer Emeritus
From: Helsinki, Finland
Registered: 2006-07-14
Posts: 4,533
Website

Re: rah_function // Every PHP function is a tag

PHP_URL_PATH is a constant. In the PHP snippet you are using it as such, but in the tag markup it’s considered as a string. In other words, you are passing a literal string of PHP_URL_PATH to the the function instead of the constant’s value. When converted to an integer by the _int prefix, it is passed on as a 0.

Instead of the string and constants name, you could use the constant’s returned value. Which for PHP_URL_PATH is 5. E.g.

<txp:rah_function
	call="parse_url"
	url="http://www.example.com/test/abc"
	component="5"
/>

Adding constant support could be beneficial indeed. So, commit 47d05e3 introduces a _constant prefix and makes using an constant as an attribute possible:

<txp:rah_function _constantAttr="I_LIKE_CHEESE" />

Last edited by Gocom (2012-09-24 03:32:50)

Offline

#63 2012-09-24 04:23:43

maniqui
Member
From: Buenos Aires, Argentina
Registered: 2004-10-10
Posts: 3,070
Website

Re: rah_function // Every PHP function is a tag

PHP docs on parse_url don’t show the returned values for constants. I may have figured it out if docs would have show them :)
Thanks, Jukka.


La música ideas portará y siempre continuará

TXP Builders – finely-crafted code, design and txp

Offline

#64 2013-04-25 09:35:49

Gocom
Developer Emeritus
From: Helsinki, Finland
Registered: 2006-07-14
Posts: 4,533
Website

Re: rah_function // Every PHP function is a tag

v0.7.0 released. Changes:

  • Added: _constant attribute prefix.
  • Added: _assign attribute.
  • Changed to semantic versioning.
  • Released as a composer package.

More info and downloads

Offline

#65 2021-03-09 17:20:35

TheMakmal
New Member
From: KL-MY
Registered: 2021-03-09
Posts: 4
Website

Re: rah_function // Every PHP function is a tag

Hi guys,

Any idea how I could use this to display Tomorrow’s date?
It’s for a food delivery website. Just want to keep showing the date of the next day.

(I used to do this via <txp:php /> but for some reason I can’t seem to save my page/forms with certain inline php/js scripts. I suspect my hosting made some security changes. So am just wondering if I could use this plugin instead since it seem this is a better approach. Also, am a designer here. Can’t really code much beyond front-end things :)

Offline

#66 2021-03-09 19:28:53

etc
Developer
Registered: 2010-11-11
Posts: 5,278
Website GitHub

Re: rah_function // Every PHP function is a tag

Hi,

welcome (back?) to the forum. You could try php date() and strtotime() functions:

<txp:rah_function call="date" format="Y-m-d" thing="here">
    <txp:rah_function call="strtotime" time="tomorrow" />
</txp:rah_function>

In recent (4.7+?) txp versions you can also register these functions and call

<txp:evaluate query="date('Y-m-d', strtotime('tomorrow')" />

Hope that helps.

Offline

#67 2021-03-10 04:13:26

TheMakmal
New Member
From: KL-MY
Registered: 2021-03-09
Posts: 4
Website

Re: rah_function // Every PHP function is a tag

etc wrote #329184:

Hi,

welcome (back?) to the forum. You could try php date() and strtotime() functions:

<txp:rah_function call="date" format="Y-m-d" thing="here">...

In recent (4.7+?) txp versions you can also register these functions and call

<txp:evaluate query="date('Y-m-d', strtotime('tomorrow')" />...

Hope that helps.

This is perfect. Thanks!
(Yes back, thanks also for the welcoming note. Been a loyal TXP user since the mid-00s. Just can’t rmbr my u/p from the old forum. You guys make TXP the best community! :)

Offline

#68 2021-03-10 04:32:05

TheMakmal
New Member
From: KL-MY
Registered: 2021-03-09
Posts: 4
Website

Re: rah_function // Every PHP function is a tag

etc wrote #329184:

<txp:rah_function call="date" format="Y-m-d" thing="here">...

Opps, one more question. How do I change the timezone to GMT+08:00 Asia/Kuala Lumpur?
Thanks again for the help on this. Much appreciated.

Last edited by TheMakmal (2021-03-10 04:33:07)

Offline

#69 2021-03-10 06:51:59

colak
Admin
From: Cyprus
Registered: 2004-11-20
Posts: 9,120
Website GitHub Mastodon Twitter

Re: rah_function // Every PHP function is a tag

TheMakmal wrote #329187:

Opps, one more question. How do I change the timezone to GMT+08:00 Asia/Kuala Lumpur?
Thanks again for the help on this. Much appreciated.

Would setting the time zone in Admin>preferences>site solve this?


Yiannis
——————————
NeMe | hblack.art | EMAP | A Sea change | Toolkit of Care
I do my best editing after I click on the submit button.

Offline

#70 2021-03-10 06:55:00

TheMakmal
New Member
From: KL-MY
Registered: 2021-03-09
Posts: 4
Website

Re: rah_function // Every PHP function is a tag

colak wrote #329188:

Would setting the time zone in Admin>preferences>site solve this?

Didn’t work. I’ve set that to my timezone. Could it be because I’m using a US based web hosting (dreamhost)?

Offline

#71 2021-03-10 07:37:03

etc
Developer
Registered: 2010-11-11
Posts: 5,278
Website GitHub

Re: rah_function // Every PHP function is a tag

You can try to replace strtotime with txp own safe_strtotime function, but I’m not sure. Timezones are always a headache.

Offline

#72 2021-03-10 09:03:01

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 11,506
Website GitHub

Re: rah_function // Every PHP function is a tag

etc wrote #329190:

Timezones are always a headache.

An understatement.


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

Board footer

Powered by FluxBB