Randomizer?

Creating and modifying plugins.
SirRobert
Regular
Posts: 38
Joined: Fri Oct 14, 2005 12:18 am

Post by SirRobert »

edit* sorry double posting.
Last edited by SirRobert on Thu Nov 09, 2006 9:26 pm, edited 1 time in total.
SirRobert
Regular
Posts: 38
Joined: Fri Oct 14, 2005 12:18 am

Post by SirRobert »

$numquotes = sizeof($quotes_array);
This would mean that the plugin always displays all quotes you added in the backoffice and ignores the option to configure the number of quotes.

I think the problem is, that the function array_rand() returns an integer instead of an array when "$numquotes" is set to "1". A possible way (maybe not the cleanest?) to solve this would be to replace this line:

Code: Select all

$keys = array_rand($quotes_array, $numquotes);
with this piece of code:

Code: Select all

$keys = array_rand($quotes_array, $numquotes);

if ($numquotes == "1") {
	$keys = array(0 => $keys);
}
It would also be useful to display all entered quotes when "$numquotes" is set to "0". For this litte feature, you could change this:

Code: Select all

if ($numquotes > sizeof($quotes_array)) { 
          $numquotes = sizeof($quotes_array); 
}
to this:

Code: Select all

if ($numquotes > sizeof($quotes_array) || $numquotes == '0') { 
            $numquotes = sizeof($quotes_array); 
       }
Hope it works.

Robert
Nintendo Gal
Regular
Posts: 44
Joined: Wed Oct 19, 2005 10:09 pm

Post by Nintendo Gal »

But that's ok for all of them to be displayed because that's what I've been wanting. This is for all my links on the side, not for quotes. :)
judebert
Regular
Posts: 2478
Joined: Sat Oct 15, 2005 6:57 am
Location: Orlando, FL
Contact:

Post by judebert »

Well, yes, but we'd like it to work for other people, too.

SirRobert, I like your updates. I didn't realize it was returning a single integer. I'll make the final updates and commit it tonight.
Judebert
---
Website | Wishlist | PayPal
judebert
Regular
Posts: 2478
Joined: Sat Oct 15, 2005 6:57 am
Location: Orlando, FL
Contact:

Post by judebert »

And finally, it's commited. Version 1.04 of serendipity_plugin_randomquotes, supporting a random subset of quotes from the list of quotes, will be available through SPARTACUS within 24 hours.
Judebert
---
Website | Wishlist | PayPal
Nintendo Gal
Regular
Posts: 44
Joined: Wed Oct 19, 2005 10:09 pm

Post by Nintendo Gal »

Oh I understand making it work for other people completely, I was simply explaining my own personal needs. ;)

As a side note, I noticed in the plug-in area there are two areas to input data and if you do not input data in both areas it goes a little squirrelly.
SirRobert
Regular
Posts: 38
Joined: Fri Oct 14, 2005 12:18 am

Post by SirRobert »

Hello Judebert,

thank you for adding the little suggestions! :)

The text-input field indeed appears twice. You just forgot a litte "break" after the switch-fields:

Code: Select all

case 'numquotes':
                $propbag->add('type',           'string');
                $propbag->add('name',           'Number of Quotes to Display');
                $propbag->add('description',    'The number of quote to choose and display in one sidebar');
                $propbag->add('default',        '1');
			break;
We could also use the "$quotes_array" in the foreach loop for printing instead of the $item array. This reduces double content of variables:

Code: Select all

foreach ($keys as $key) {
            if (trim($quotes_array[$key]['link']) == '') {
                if (trim($url) != '') {
                    $quotes_array[$key]['author'] = '<a href="'.str_replace('%QUERY%', urlencode($quotes_array[$key]['author']), $url).'"'.$onclick.'>'. htmlspecialchars($quotes_array[$key]['author']).'</a>'."\n"; 
                }
            } elseif (trim($quotes_array[$key]['link']) != 'none') {
                $quotes_array[$key]['author'] = '<a href="'.$quotes_array[$key]['link'].'"'.$onclick.'>'. htmlspecialchars($quotes_array[$key]['author']) .'</a>'."\n"; 
            } else {
                $quotes_array[$key]['author'] = htmlspecialchars($quotes_array[$key]['author']);
            }
            echo str_replace(array('%QUOTE%', '%AUTHOR%'), array($quotes_array[$key]['quote'], $quotes_array[$key]['author']), $formatstring);
        }
Best Regards,

Robert
judebert
Regular
Posts: 2478
Joined: Sat Oct 15, 2005 6:57 am
Location: Orlando, FL
Contact:

Post by judebert »

Thanks! Already taken care of in the CVS version.

I didn't update the $item thing. If it's seriously a performance problem, I will. Otherwise, it's just more readable as it stands.
Judebert
---
Website | Wishlist | PayPal
SirRobert
Regular
Posts: 38
Joined: Fri Oct 14, 2005 12:18 am

Post by SirRobert »

Hi Judebert,

it's fine with the $item - thanks for the update!

Robert
Post Reply