Textpattern Forum

You are not logged in. Register | Login | Help

#11 2009-04-11 08:17:24

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

Re: smd_random_text: Pull random items from the TXP environment

Slight update to add trim and escape attributes. Download


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

Txp Builders – finely-crafted code, design and Txp

Offline

#12 2009-05-04 20:05:20

the_ghost
Plugin Author
From: Minsk, The Republic of Belarus
Registered: 2007-07-26
Posts: 907
Website

Re: smd_random_text: Pull random items from the TXP environment

Have good idea. I want to use this plugin to output different “read more” texts: “read more about this article”, “try to get this”, “some facts about”.. and so on..

But bad thing is that every time page loads this text will change. And i want to make this random text to be stable :) So, i offer to add some attr, named, for example, unqizer :) And the example of using:

<txp:smd_random_text uniqizer='<txp:article_id' />
In this case, every article will have uniq and stable random text :)

How to make this? May be you can get md5() of uniqizer and then convert it in number of strings to offset in array of random strings.


Providing help in hacking ATM! Come to courses and don’t forget to bring us notebook and hammer! What for notebook? What a kind of hacker you are without notebok?

Offline

#13 2009-05-05 06:52:08

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

Re: smd_random_text: Pull random items from the TXP environment

the_ghost wrote:

And i want to make this random text to be stable :)

Bizarrely I had a similar requirement recently and had to “fix” it with some PHP. If you look at my contact page the “Favourite question” at the bottom is chosen using smd_random_text. The problem I had was that if you submit a “bad” form (i.e. one that showed a zemError) then it would generate a new ‘favourite’ each time. I circumvented this with a SESSION variable and ‘forced’ the random item by setting a txp:variable in advance of the smd_random_text call.

I like your idea of fixed randomness though. It may be that I can address both your needs and mine with a new attribute and some cunning. Leave it with me and I’ll look into it.


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

Txp Builders – finely-crafted code, design and Txp

Offline

#14 2009-07-26 17:20:30

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

Re: smd_random_text: Pull random items from the TXP environment

Minor update to add a couple of attributes and a new replacement tag. The first is to ‘fix’ the randomness which is mighty handy if you want to link some disparate but related sources of info together. Not quite what the_ghost was after but it might be able to be abused for this purpose. If not I can have a go at adding what you wanted at a later date.

The second attribute allows a subsequent bout of randomness to be introduced if you need it.

Download v0.12


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

Txp Builders – finely-crafted code, design and Txp

Offline

#15 2010-07-10 08:43:08

dandul
Member
From: Brisbane, Australia
Registered: 2010-01-31
Posts: 33

Re: smd_random_text: Pull random items from the TXP environment

Hiya

I’m trying to set up a random quote using a text file as the source.

The code is:
<div id="quote"> <h3>Dharma quote</h3> <txp:smd_random_text type="file" source="files/VGKG-quotes-pick.txt" form="330_quote" limit="1" /> </div>

And the “330_quote” looks like this:
{smd_rnd_txt}

The h3 heading appears but no quote. The text file is located in the “files” folder and I’m running txp 4.2. Any suggestions?


Stop wishing things were different to the way they are. Accept it, deal with it, move on.

Offline

#16 2010-07-10 20:02:52

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

Re: smd_random_text: Pull random items from the TXP environment

dandul wrote:

The text file is located in the “files” folder

A few things you could try/check:

  1. Try it with a / before your files directory name — it might just not be finding the file path correctly
  2. Is your site in a subdirectory?
  3. Are your random quotes in the text file delimited by a newline?
  4. Are your newlines “real” newlines or Windoze-style (or Mac-style) newlines?
  5. Add debug="1" (or maybe 2 as well) and see if that gives you any clues. If not, you can always post the relevant stuff here and I’ll see if I can figure it out

If (3) or (4) are the cause you might be able to alter the file_delim attribute to make it work properly. I’ve not tried it with non-UNIX line endings. You could always smoosh them all onto one line and use a different delimiter if it’s not working right — depending on how many quotes you have in total.


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

Txp Builders – finely-crafted code, design and Txp

Offline

#17 2010-07-10 20:37:45

the_ghost
Plugin Author
From: Minsk, The Republic of Belarus
Registered: 2007-07-26
Posts: 907
Website

Re: smd_random_text: Pull random items from the TXP environment

dandul wrote:

The h3 heading appears but no quote. The text file is located in the “files” folder and I’m running txp 4.2. Any suggestions?

Try to check the url – try absolute url instead of relative – /files/... instead of files/...


Providing help in hacking ATM! Come to courses and don’t forget to bring us notebook and hammer! What for notebook? What a kind of hacker you are without notebok?

Offline

#18 2010-07-11 11:46:26

dandul
Member
From: Brisbane, Australia
Registered: 2010-01-31
Posts: 33

Re: smd_random_text: Pull random items from the TXP environment

Doh! I forgot to mention i was testing on my laptop. i uploaded it to a live site and it works fine. Should have tried that before posting. Ah well, it works, thanks everyone


Stop wishing things were different to the way they are. Accept it, deal with it, move on.

Offline

#19 2010-07-16 07:27:00

otti
Member
From: Australia
Registered: 2008-04-16
Posts: 75
Website

Re: smd_random_text: Pull random items from the TXP environment

I have implemented smd_random_text successfully on my website. It pulls random quotes from a database, but not without a problem. Once a page gets refreshed (reloaded), the previous randomly selected quote stays as is and no new quote gets selected. Has this something to do with the cache in the browser? As soon as I clear the cache in the browser and refresh the page, a new quote gets displayed. A page refresh only reloads possibly one new quote and then gets stuck with it.
Many thanks for any help.
otti

Offline

#20 2010-07-16 08:08:18

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

Re: smd_random_text: Pull random items from the TXP environment

otti wrote:

Has this something to do with the cache in the browser?

Yes. Try visiting Admin->Advanced Prefs and setting Send “last modified” header to No.

I could probably implement a feature that added a random class or something to the quote (if you used wraptag) to try and defeat the cacheing. But in theory the fact that the quote is changing each time should be enough to trigger ‘different from last time’ behaviour. I don’t know why it doesn’t do this; I’ve noticed it myself sometimes.


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

Txp Builders – finely-crafted code, design and Txp

Offline

Board footer

Powered by FluxBB