Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#201 2014-01-14 08:36:38

etc
Developer
Registered: 2010-11-11
Posts: 3,780
Website

Re: etc_query: all things Textpattern

photonomad wrote #278126:

Might there be a way/shortcut to get etc_query to automatically store each node from items in a JSON document as a textpattern variables when using etc_query as a container tag?

No, mainly because nodes (e.g. {//a}) are generally lists, so storing them in txp variables (that are strings) is problematic.

I have couple of date/timestamps that need formatting and other nodes that need to have the html escaped, etc. My programming knowledge is limited to where I can’t figure out how to wrap a {node?} in an smd_wrap tag or other plugin tags without first defining the nodes as txp:variables and this seems to slow the whole thing down a bit.

You can do most of formatting with etc_query itself, using php or txp functions. For example, to transform a {timestamp?} into year, call {$strftime(%Y|{timestamp?})}, to escape it call {$txpspecialchars({timestamp?})}, and so on. If you need to inject {node?} as attribute of some <txp:tag />, that’s a mere <txp:tag attr="{node?}" />, or <txp:tag attr="{$txpspecialchars({node?})}" />.

If your treatment is really complex, you can (at least in theory) save the imported JSON object with save attribute of etc_query and reuse it later, without etc_query parsing the object again. An example of what you are doing would help me.

Offline

#202 2014-01-14 09:17:36

photonomad
Member
Registered: 2005-09-10
Posts: 287
Website

Re: etc_query: all things Textpattern

Oleg, Thank you for your reply! I see what you mean by the list/string difference. Makes sense. And, thank you so much for the helpful formatting/function examples!

I am working on a community calendar that consists of multiple Google calendars.* I created a Yahoo Pipe that grabs all the feeds and combines them into a json document. A static public example of the output is here: http://www.outcentral.org/comcaltestfeed.json

The pipe itself takes a while to run. My etc_query code runs slowly because I’ve got a ton of variables and lots of if/else tests for the output. I am using aks_cache (60 minutes) to try to help improve load time. I have to get some sleep right now, but will work on improving my code tomorrow with the tips you provided.

And, here is a link to a test/preview of the end result:
http://www.outcentral.org/comcal-test

  • I imagine there may be a way to combine, loop and sort data from multiple feeds with etc_query, but the solution is most definitely currently over my head. I also realize that there is probably a way to do most of this with the Google Calendar API. Once again: beyond my current Google API knowledge.

Last edited by photonomad (2014-01-14 15:35:24)

Offline

#203 2014-01-14 09:24:18

etc
Developer
Registered: 2010-11-11
Posts: 3,780
Website

Re: etc_query: all things Textpattern

Challenging, I like it. Good night, and see you tomorrow, I’ll take a look at it meanwhile.

Offline

#204 2014-01-15 04:56:40

photonomad
Member
Registered: 2005-09-10
Posts: 287
Website

Re: etc_query: all things Textpattern

Thank you so much for your help, Oleg.

One thing that I’m stuck on at the moment is whether it is possible to use {$?(if|then|else} or another method to test if the start time minutes = 00. If {$?(if|then|else} is only used to check for emptiness, should I just define a <txp:variable name=“startminutes” value=”{$date(i,{start?})}” /> and then use <txp:if_variable name=“startminutes” value=“00”> to test?

etc_query is so powerful and you make it seem so easy! I wish I could fully understand all of the shortcuts and possibilities.

Last edited by photonomad (2014-01-15 05:47:02)

Offline

#205 2014-01-15 09:30:59

etc
Developer
Registered: 2010-11-11
Posts: 3,780
Website

Re: etc_query: all things Textpattern

Glad you like it, Stacey, thanks.

photonomad wrote #278144:

One thing that I’m stuck on at the moment is whether it is possible to use {$?(if|then|else} or another method to test if the start time minutes = 00. If {$?(if|then|else} is only used to check for emptiness, should I just define a <txp:variable name=“startminutes” value=”{$date(i,{start?})}” /> and then use <txp:if_variable name=“startminutes” value=“00”> to test?

You can chain it with another etc_query function: =

{$date(i,{start?}).=00.?(then,else)}

etc_query is so powerful and you make it seem so easy! I wish I could fully understand all of the shortcuts and possibilities.

Thank you again, but, frankly speaking, if my code contained many {$...} or <txp:tag> blocks, I would consider switching to <txp:php>. Here is why: User Defined Functions in PHP are slow, and every {$...} pattern (as well as <txp:tag>) calls few UDFs. That’s ok on small datasets, but when your array contains ~300 rows, the difference starts to be noticeable (I’ve measured ~0.05s). In fact, these {$...} were never intended as replacement for <txp:php>. Bu I hope things can be sped up, so stay with etc_query.

Offline

#206 2014-02-10 13:13:06

johnno
Member
Registered: 2007-06-14
Posts: 27

Re: etc_query: all things Textpattern

Is it possible to inject a txp variable into the url attribute?
Thanks for the plugin btw!

Offline

#207 2014-02-10 13:39:08

etc
Developer
Registered: 2010-11-11
Posts: 3,780
Website

Re: etc_query: all things Textpattern

johnno wrote #278750:

Is it possible to inject a txp variable into the url attribute?

Certainly, as with any txp tag:

<txp:etc_query url='http://<txp:variable name="url" />/something/else' />

Offline

#208 2014-02-10 14:03:44

etc
Developer
Registered: 2010-11-11
Posts: 3,780
Website

Re: etc_query: all things Textpattern

etc wrote #278148:

if my code contained many {$...} or <txp:tag> blocks, I would consider switching to <txp:php>.

BTW, I’ve done some testing here, that might interest every txp tags aficionado.

Offline

#209 2014-02-10 14:25:25

johnno
Member
Registered: 2007-06-14
Posts: 27

Re: etc_query: all things Textpattern

etc wrote #278752:

Certainly, as with any txp tag:

<txp:etc_query url='http://<txp:variable name="url" />/something/else' />...

I assumed it should work – and it does; thanks for confirming so quickly.

It’s my ill-disciplined syntax which was causing the problem :(

<txp:etc_query url="http://<txp:variable name='url' />/something/else" />

Offline

#210 2014-03-22 10:33:10

nardo
Member
From: tuvalahiti
Registered: 2004-04-22
Posts: 741

Re: etc_query: all things Textpattern

Oleg, this plugin is fantastic. Thank you again.

A question about extracting a random set of nodes. I’m getting a response from the Flickr API describing 200 photos. I’d like to choose 12 of the nodes at random to display, but I want to avoid the same node being picked twice.

Can it be done in etc_query? Or do I need to first come up with my values, and then populate the query?

query="//photos/photo[33] | //photos/photo[143] | -etc- "

Offline

Board footer

Powered by FluxBB