Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#13 2004-09-01 19:27:47

kennethlove666
Member
From: arkansas
Registered: 2004-04-27
Posts: 107
Website

Re: [plugin] [ORPHAN] dru_random_text

sophia – if you’re on a *nix computer, “tar xzf filename.tgz” at the commandline should work for you. if you’re on an older mac, stuffit can open the file. if you’re on a windows computer, i do believe winRAR or winACE can open it.


Listen to Kenneth

Offline

#14 2004-09-02 11:32:30

Martagnan
Member
From: Humberside - uk
Registered: 2004-06-21
Posts: 90
Website

Re: [plugin] [ORPHAN] dru_random_text

TIME SENSITIVE RANDOM TEXT!

Someone else might find this useful. I dont know PHP but I have cobbled this together with help from friends…

Copy and paste the following in place of the plugin code… ALWAYS BACKUP THE ORIGINAL FIRST!!!

@
function dru_random_text($atts) // by mr drew mclellan // allinthehead.com { global $txpcfg; if (is_array($atts)) extract($atts); $source = empty($source) ? ‘file’ : $source;

if ($source == ‘database’){ if (empty($table) || empty($column)) return ‘’; $sql = “select $column from $table order by rand() limit 1”; $rs = getRow($sql); if($rs) return $rs0; return ‘’; } if ($source == ‘file’){ if( date(“H”) > 6 && date(“H”) < 11) { $path = “morning.txt”; } else if (date(“H”) > 11 && date(“H”) < 18) { $path = “afternoon.txt”; } else if (date(“H”) > 18 && date(“H”) < 23) { $path = “evening.txt”; } else { $path = “smallhours.txt”; } $path = empty($path) ? $txpcfg[‘doc_root’].$filename : $path; $delimiter = empty($delimiter) ? “\n” : $delimiter; $fp = fopen($path, “r”); $contents = fread($fp, filesize($path)); $elements = explode($delimiter,$contents); fclose($fp); srand((double)microtime()*1000000); $text_index = (rand(1, sizeof($elements)) – 1); return $elements[$text_index]; } return ‘’; }

@

Now its possible to serve up random(ish) text appropriate to the time of day!

If anyone could suggest a more elegant way i’d appreciate it.

Can someone tell me how to get code to display properly on this forum :(

Last edited by Martagnan (2004-09-02 15:50:11)

Offline

#15 2004-09-02 13:21:42

els
Moderator
From: The Netherlands
Registered: 2004-06-06
Posts: 7,458

Re: [plugin] [ORPHAN] dru_random_text

I tried this in my form:

<txp:permlink><txp:dru_random_text source="database" table="textpattern" column="Title" /></txp:permlink>

but then nothing is displayed. Without the permlink tags it displays a random title, but I don’t see much use in that without the permlink.
Is it possible to add the permlink, and how?

Martagnan: put the code between -s.

Last edited by doggiez (2004-09-02 13:22:27)

Offline

#16 2004-09-02 15:49:11

Martagnan
Member
From: Humberside - uk
Registered: 2004-06-21
Posts: 90
Website

Re: [plugin] [ORPHAN] dru_random_text

I put the code between @s as you can see… no difference?

Offline

#17 2004-09-02 20:21:40

els
Moderator
From: The Netherlands
Registered: 2004-06-06
Posts: 7,458

Re: [plugin] [ORPHAN] dru_random_text

And this?

< code >your code< /code >

<del>Edit: can’t seem to get this right :-( I’ll just keep trying until it shows what I want. (why doesn’t this thing have a preview button?)</del>

Edit nr. 387: at last! (just leave out the spaces of course)

Last edited by doggiez (2004-09-02 20:38:09)

Offline

#18 2005-11-23 14:09:33

EddieG5
Member
From: Georgia
Registered: 2004-03-03
Posts: 96

Re: [plugin] [ORPHAN] dru_random_text

Has anyone tried this plugin with the latest version of Txp? I’ve got it running on a RC2 install that I’m about to upgrade … does anyone know of any issues I should be aware of or if there is an updated version of the plugin?

Offline

#19 2005-11-23 14:38:16

els
Moderator
From: The Netherlands
Registered: 2004-06-06
Posts: 7,458

Re: [plugin] [ORPHAN] dru_random_text

I have been using it without problems in 4.0.1, stopped using it recently because I found that the same can be achieved with articles and sortby=“rand()”.

Offline

#20 2005-11-23 15:03:37

reid
Member
From: Atlanta, Ga.
Registered: 2004-04-04
Posts: 224
Website

Re: [plugin] [ORPHAN] dru_random_text

I’m using it with 4.0.2 with no issues.


TextPattern user since 04/04/04

Offline

#21 2005-11-23 16:25:10

EddieG5
Member
From: Georgia
Registered: 2004-03-03
Posts: 96

Re: [plugin] [ORPHAN] dru_random_text

Excellent … thanks!

Offline

#22 2006-04-04 22:14:13

marios
Archived Plugin Author
Registered: 2005-03-12
Posts: 1,253

Re: [plugin] [ORPHAN] dru_random_text

Does it work with 4.03 ?

regards


⌃ ⇧ < ⌃ ⇧ >

Offline

#23 2006-04-04 23:18:50

RenJonsin
Member
From: Tarpon Springs, FL USA
Registered: 2005-02-06
Posts: 103
Website

Re: [plugin] [ORPHAN] dru_random_text

Yes it does!

Ren

Offline

Board footer

Powered by FluxBB