Page 2 of 2

Posted: Thu Nov 09, 2006 9:24 pm
by SirRobert
edit* sorry double posting.

Posted: Thu Nov 09, 2006 9:25 pm
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

Posted: Thu Nov 09, 2006 9:28 pm
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. :)

Posted: Fri Nov 10, 2006 3:40 am
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.

Posted: Fri Nov 10, 2006 4:26 am
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.

Posted: Fri Nov 10, 2006 4:51 am
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.

Posted: Fri Nov 10, 2006 9:58 am
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

Posted: Fri Nov 10, 2006 7:49 pm
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.

Posted: Fri Nov 10, 2006 8:20 pm
by SirRobert
Hi Judebert,

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

Robert