Page 1 of 2

Randomizer?

Posted: Wed Nov 08, 2006 12:04 pm
by Nintendo Gal
I'm looking for something like this:

http://linux.linux.dk/projects/randomize/

Basically it allows you to randomize things on your page. I'm looking to randomize links on my sidebar (reason is self-exclamatory I'd think).

I'm not certain on how to convert this for s9y usage so I figured I'd ask if there is something already in place.

Thanks again! :)

Posted: Wed Nov 08, 2006 9:43 pm
by SirRobert
Hi,

there is a comfortable plugin for Serendipity called "Random Quotes". It allows you to enter a few quotes that appear in the sidebar and change on each refresh of the site.

You can modify this plugin in a way that it also interpretes HTML code. You just need to strip off the "htmlspecialchars()" in line 96 of the .php file and it should work fine.

Download here:
http://spartacus.s9y.org/cvs/additional ... quotes.zip

or simply via Spartacus.

Best Regards, Robert

Posted: Thu Nov 09, 2006 2:53 am
by carl_galloway
I've actually used the random quote plugin to include html and images without editing any of the php files. Admittedly this was back when I was using Serendipity 0.82 and then 0.91, but I don't think the plugin has changed much since then so try it without altering any of the code. It might work for you as is.

Posted: Thu Nov 09, 2006 10:25 am
by Nintendo Gal
Hmm the problem with this one is, is that it only displays one quote (or in my case link) at a time. I'm looking to have a list of links that are randomized.

Is there a way to make this so it can display a list and have that list be completely random?

Posted: Thu Nov 09, 2006 4:09 pm
by judebert
Well, there's always modifying the code. :wink:

Beyond that, you could do the same thing they do on 'random' amusement park rides, like the Tower of Terror: come up with a bunch of blocks and choose one of them randomly.

Posted: Thu Nov 09, 2006 4:33 pm
by Nintendo Gal
Yeah I figured it'd come down to editing code. I was hoping it wasn't, but I think I got time to hammer this out. :(

Thanks for the suggestions!

Posted: Thu Nov 09, 2006 4:54 pm
by judebert
Sorry. But look what you'll be contributing back to the community!

I'm imagining an option in the plugin configuration: "Number of Quotes to Display". Then just wrap a for-loop around the bit that does the random choosing.

Posted: Thu Nov 09, 2006 5:19 pm
by Nintendo Gal
I'll be happy to contribute it as soon as I figure out how to make an actual plug-in and not have it just be hacked for my own purposes. I think I'll start reading now. :)

Posted: Thu Nov 09, 2006 5:35 pm
by judebert
I found that there's a beautiful array_rand function for this in PHP. Download the new serendipity_plugin_randomquote.php from my site at http://www.judebert.com/wasted_youth/me ... quotes.php and tell me if it works. If so, I'll update CVS later tonight, after I pull out the language constants.

(You'll need to use "Save link as", or you'll wind up on my site.)

Posted: Thu Nov 09, 2006 5:42 pm
by Nintendo Gal
This link didn't actually download the plug-in, instead it seemed to grab your entire site. Unless that was your intent?

Posted: Thu Nov 09, 2006 6:45 pm
by judebert
I'm not that clever. I assume you used "Save link as", so it's probably a problem with the server recognizing .php files as executable. I zipped it up and we can try again:
http://www.judebert.com/wasted_youth/me ... quotes.zip

Posted: Thu Nov 09, 2006 6:50 pm
by Nintendo Gal
Yeah umm.. you may need to pull the file from an FTP client as you just pulled and zipped your site again. >.<;;

Posted: Thu Nov 09, 2006 8:17 pm
by judebert
Oh, blush.

So sorry. An idiotic mistake on my part. It's fixed now, at least for the zip file.

I should've known that this plugin didn't need to be 45K.

Posted: Thu Nov 09, 2006 8:39 pm
by Nintendo Gal
All is forgiven, but there are some errors unfortunately. :(

Code: Select all

Warning: array_rand() [function.array-rand]: Second argument has to be between 1 and the number of elements in the array in /home/nintendo/public_html/plugins/serendipity_plugin_randomquotes/serendipity_plugin_randomquotes.php on line 116

Warning: Invalid argument supplied for foreach() in /home/nintendo/public_html/plugins/serendipity_plugin_randomquotes/serendipity_plugin_randomquotes.php on line 117
I'm trying to figure it out now.

Posted: Thu Nov 09, 2006 9:17 pm
by Nintendo Gal
Thanks to a friend/forum user of mine, it now works like a charm! :D

What you had:
if ($numquotes > sizeof($quotes_array)) {
$numquotes = sizeof($quotes_array);
}
Changes:
$numquotes = sizeof($quotes_array);
:)