Textpattern CMS support forum

You are not logged in. Register | Login | Help

#221 2010-03-24 11:20:10

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

Re: smd_query: Talk to the database directly via SQL

mlarino wrote:

what do you mean with anchor tags? the /?pg= is generated by smd_querys pagination…

Are you using that huge wodge of code I posted above? The ?pg= part is generated by that, not smd_query. As an example, the last part reads:

<txp:smd_query_if_next>
<a href="?pg={smd_nextpage}"><b>NEXT</b></a>
<txp:else />
NEXT
</txp:smd_query_if_prev>

I was just wondering if the browser or TXP was adding the slash automatically for some reason, so perhaps hardcoding the URL like this might fix it:

<txp:smd_query_if_next>
<a href="<txp:permlink />?pg={smd_nextpage}"><b>NEXT</b></a>
<txp:else />
NEXT
</txp:smd_query_if_prev>

?

Last edited by Bloke (2010-03-24 11:21:10)


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

#222 2010-03-24 11:20:55

mlarino
Member
Registered: 2007-06-29
Posts: 367

Re: smd_query: Talk to the database directly via SQL

Oh wait! :)

think I got what you meant.

<txp:smd_query_if_prev> <a href="<txp:permlink />?pg={smd_prevpage}"> Previous {smd_rows_prev}</a> </txp:smd_query_if_prev> <txp:smd_query_if_next> <a href="<txp:permlink />?pg={smd_nextpage}"> Next {smd_rows_next}</a> </txp:smd_query_if_next>

It works!

Offline

#223 2010-03-24 11:23:13

mlarino
Member
Registered: 2007-06-29
Posts: 367

Re: smd_query: Talk to the database directly via SQL

I was using this before:

Page {smd_thispage} of {smd_pages} | Showing records {smd_row_start} to {smd_row_end} of {smd_allrows} | <txp:older>Next {smd_rows_next}</txp:older> | <txp:newer>Previous {smd_rows_prev}</txp:newer>

that was giving me the / before ?pg=2

Offline

#224 2010-03-24 11:29:18

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

Re: smd_query: Talk to the database directly via SQL

mlarino wrote:

It works!

Great! I’ve no idea why the slash gets added in some circumstances. Probably something simple that I don’t understand about URIs. If anybody knows…


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

#225 2010-04-09 14:29:13

jens31
Plugin Author
From: munich / dtschermani
Registered: 2008-08-25
Posts: 183
Website

Re: smd_query: Talk to the database directly via SQL

hii

i have a small problem, and i dont know if this is solvable, or if i have to regret right now.
but i think its possible..

so
i have a multilingual website and its using one db with 2 txps, one for each language.
now my client wants to have one section where users can leave their comments.
and he wants them visible in both languages. so (i guess) there would be one way to hardcode the path to the specific db entry..(hopefully?? [never did that, yet])
or maybe this plugin can do the job..? is it possible to call another db / suffix via this tool..?

thanks for your help

best
jens

Offline

#226 2010-04-19 01:26:45

atbradley
Plugin Author
From: Rhode Island, US
Registered: 2007-02-15
Posts: 34
Website

Re: smd_query: Talk to the database directly via SQL

Bloke,

I made a minor change to my copy of smd_query—don’t know if you’d be interested.

Basically, I already had an article form when changing project requirements meant I needed more query power than article_custom could give me, so I hacked smd_query to let me use an article (or link or file) form with it. I added a new argument, “datatype”, which can be set to ‘file’, ‘link’, or ‘article’ to populate the appropriate global variable for each result row from your query.

This is the file.

And here’s a diff:

2a3
>     global $thisfile, $thislink;
33a35
>         'datatype' => '',
187a190,207
>
>                 if ( 'article' == $datatype ) {
>                     populateArticleData($row);
>                     $thisarticle['is_first'] = ($page_rowcnt == 1);
>                     $thisarticle['is_last'] = (($page_rowcnt + 1) == $pagerows);
>                 }
>                 if ( 'file' == $datatype ) { $thisfile = file_download_format_info($row); }
>                 if ( 'link' == $datatype ) {
>                     $thislink = array(
>                     'id'          => $row['id'],
>                     'linkname'    => $row['linkname'],
>                     'url'         => $row['url'],
>                     'description' => $row['description'],
>                     'date'        => $row['uDate'],
>                     'category'    => $row['category'],
>                 );
>                 }
>
301c321
< }?>
\ No newline at end of file
---
> }
\ No newline at end of file

Offline

#227 2010-04-19 08:10:33

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

Re: smd_query: Talk to the database directly via SQL

atbradley wrote:

I made a minor change to my copy of smd_query—don’t know if you’d be interested.

Yes, interested. Thanks for the idea. It does make things cleaner and also gives the ability to use either the replacement tags or standard TXP tags (or a mixture).

To do it fully is not quite as simple as your version unfortunately because we need to remember the previous state of the globals and reinstate them after smd_query has finished meddling, ortherwise it trashes your current article/file/link context. I’d also add in support for the new $thisimage context in the current SVN.

In fact I’d probably go so far as to auto-detect the datatype based on the current context — e.g. if $thisimage, $thisfile or $thislink are set, use that relevant context, else default to $thisarticle — but allow you to override it in case the plugin got it wrong (probably only if you were embedding images inside files inside links or something mad like that).

Let me look into this and make an official release based on your mod sometime this week. Thanks again.

jens31

Sorry for missing your question. The plugin just assumes you have a connection to a database already instated. If that database has more than one TXP install inside it, the plugin doesn’t care so you can — as you suggest — hard-code the prefix in your queries. Alternatively, set up a txp:variable to store your prefix (you can probably read the language from some place that indicates the current user language pref and make a decision based on that) and put that in your queries instead. Hope that helps.

Last edited by Bloke (2010-04-19 08:13:31)


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

#228 2010-04-19 13:04:54

atbradley
Plugin Author
From: Rhode Island, US
Registered: 2007-02-15
Posts: 34
Website

Re: smd_query: Talk to the database directly via SQL

Bloke wrote:

To do it fully is not quite as simple as your version unfortunately because we need to remember the previous state of the globals and reinstate them after smd_query has finished meddling, ortherwise it trashes your current article/file/link context. I’d also add in support for the new $thisimage context in the current SVN.

Right. I hadn’t thought about people using it within an existing article/whatever context. Is it adequate just to say

$thisarticle_orig = $thisarticle; $thisfileorig = $thisfile; $thislinkorig = $thislink;

at the top of smd_query() and then swap them back before the end?

In fact I’d probably go so far as to auto-detect the datatype based on the current context — e.g. if $thisimage, $thisfile or $thislink are set, use that relevant context, else default to $thisarticle — but allow you to override it in case the plugin got it wrong (probably only if you were embedding images inside files inside links or something mad like that).

I’m not clear how this works—wouldn’t you need to check for the existence of specific fields in the query result before feeding rows into $thiswhatever? I’m not using smd_query inside an existing article/file/link context, I’m using it to replace the built-in tags that can’t quite do what I need them to.

Offline

#229 2010-04-19 13:48:01

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

Re: smd_query: Talk to the database directly via SQL

atbradley wrote:

Is it adequate just to say $thisarticle_orig = $thisarticle; $thisfileorig = $thisfile; $thislinkorig = $thislink; at the top of smd_query() and then swap them back before the end?

Yup. That’s what I’d do!

I’m not clear how this works—wouldn’t you need to check for the existence of specific fields in the query result before feeding rows into $thiswhatever?

I’d just cheat and say something like this:

if (!$datatype) {
   $datatype = ($thisarticle) ? $thisarticle : NULL;
   $datatype = ($thislink) ? $thislink : $datatype;
   $datatype = ($thisimage) ? $thisimage : $datatype;
   $datatype = ($thisfile) ? $thisfile : $datatype;
}

At the end of that lot, your datatype will either be:

  1. your hard-coded plugin attribute
  2. NULL if you’re on a section/category/author/etc landing page — in which case you don’t have to bother saving anything
  3. one of the contexts based on whichever one currently has content in it

The thing I dislike about this approach is that the hierarchy is a bit hit-and-miss. I’ve assumed that article is the lowest common denominator and file context trumps everything. In reality I would probably opt for a system that allowed you to specify / override the order. But I’ve not really thought it through yet.

I suppose it’s not a massive headache whichever hierarchy is chosen, because if you’re using smd_query inside a file_download_list and still want to get at the article tags you can just specify datatype in the tag and it’ll do your bidding; the automatic selection is just there as a first stab so that in 95% of cases you can ignore the attribute!

If I (or anyone else) can come up with anything better I’ll put it in the plugin :-)


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

#230 2010-05-01 17:31:02

sereal
Member
From: Indonesia
Registered: 2010-02-18
Posts: 55

Re: smd_query: Talk to the database directly via SQL

hi Mr.Stef

one question..

how to limit Title’s characters from smd_query ?

<txp:permlink id=”{ID}”>{Title}</txp:permlink>

I use this @Gocom’s php to limit title in other section but I have no idea how to inject it into your smd_query

<txp:php> preg_match(‘/^(.{0,48})(.*)$/u’, title(array()), $match); echo $match1; if (strlen($match2)) echo ‘…’;
</txp:php>

please advise

thanks Mr.Stef

Last edited by sereal (2010-05-01 18:26:27)


$(mydocument).notyetready(function() {});
dowebsitesneedtolookexactlythesameineverybrowser ?

Offline

Board footer

Powered by FluxBB