Randomizer?

Creating and modifying plugins.
Nintendo Gal
Regular
Posts: 44
Joined: Wed Oct 19, 2005 10:09 pm

Randomizer?

Post 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! :)
SirRobert
Regular
Posts: 38
Joined: Fri Oct 14, 2005 12:18 am

Post 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
carl_galloway
Regular
Posts: 1331
Joined: Sun Dec 04, 2005 5:43 pm
Location: Andalucia, Spain
Contact:

Post 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.
Nintendo Gal
Regular
Posts: 44
Joined: Wed Oct 19, 2005 10:09 pm

Post 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?
judebert
Regular
Posts: 2478
Joined: Sat Oct 15, 2005 6:57 am
Location: Orlando, FL
Contact:

Post 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.
Judebert
---
Website | Wishlist | PayPal
Nintendo Gal
Regular
Posts: 44
Joined: Wed Oct 19, 2005 10:09 pm

Post 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!
judebert
Regular
Posts: 2478
Joined: Sat Oct 15, 2005 6:57 am
Location: Orlando, FL
Contact:

Post 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.
Judebert
---
Website | Wishlist | PayPal
Nintendo Gal
Regular
Posts: 44
Joined: Wed Oct 19, 2005 10:09 pm

Post 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. :)
judebert
Regular
Posts: 2478
Joined: Sat Oct 15, 2005 6:57 am
Location: Orlando, FL
Contact:

Post 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.)
Last edited by judebert on Thu Nov 09, 2006 6:46 pm, edited 1 time in total.
Judebert
---
Website | Wishlist | PayPal
Nintendo Gal
Regular
Posts: 44
Joined: Wed Oct 19, 2005 10:09 pm

Post 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?
judebert
Regular
Posts: 2478
Joined: Sat Oct 15, 2005 6:57 am
Location: Orlando, FL
Contact:

Post 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
Judebert
---
Website | Wishlist | PayPal
Nintendo Gal
Regular
Posts: 44
Joined: Wed Oct 19, 2005 10:09 pm

Post 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. >.<;;
judebert
Regular
Posts: 2478
Joined: Sat Oct 15, 2005 6:57 am
Location: Orlando, FL
Contact:

Post 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.
Judebert
---
Website | Wishlist | PayPal
Nintendo Gal
Regular
Posts: 44
Joined: Wed Oct 19, 2005 10:09 pm

Post 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.
Nintendo Gal
Regular
Posts: 44
Joined: Wed Oct 19, 2005 10:09 pm

Post 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);
:)
Post Reply