Randomizer?
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.$numquotes = sizeof($quotes_array);
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);Code: Select all
$keys = array_rand($quotes_array, $numquotes);
if ($numquotes == "1") {
$keys = array(0 => $keys);
}Code: Select all
if ($numquotes > sizeof($quotes_array)) {
$numquotes = sizeof($quotes_array);
}Code: Select all
if ($numquotes > sizeof($quotes_array) || $numquotes == '0') {
$numquotes = sizeof($quotes_array);
}
Robert
-
Nintendo Gal
- Regular
- Posts: 44
- Joined: Wed Oct 19, 2005 10:09 pm
-
Nintendo Gal
- Regular
- Posts: 44
- Joined: Wed Oct 19, 2005 10:09 pm
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:
We could also use the "$quotes_array" in the foreach loop for printing instead of the $item array. This reduces double content of variables:
Best Regards,
Robert
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;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);
}Robert