Random logos with frequency set fails to display logo
| Project: | Logo Tool |
| Version: | 6.x-1.x-dev |
| Component: | Code |
| Category: | bug report |
| Priority: | normal |
| Assigned: | Unassigned |
| Status: | needs review |
Jump to:
Under 6.13, when I set "Display mode: Random logos" and the Random frequency to something other than every page refresh ie using a time interval the random logo only works once at the start of each interval.
What happens is the logotool code sets the logo in $variables the first time in the time interval and the logo displays. The next time a page is requested within the interval the logo is not set (it thinks it doesn't have to) and no logo displays, or the site/theme logo displays if it is set in the theme or site settings.
The reason for this is that the includes/theme.inc sets the logo variable in $variables to the site default and logotools doesn't override this within the interval (only the first time).
The problem is in this bit of the code:
case '1':
if ($time || !variable_get('logotool_frequency', 0)) {
$logos = logotool_scan_dir(variable_get('logotool_folder', LT_CWD));
if ($time) {
variable_set('logotool_timestamp', time());
}
$variables['logo'] = sprintf("/%s", array_rand($logos));
}
break;so if we're within the interval and we don't need to set the next timestamp $variables['logo'] is never set and the theme value is retained.
I'd fix it if I knew how to set a variable that persists but I'm unsure how to do that in the Drupal setting.

#1
I've cobbled together a fix for this:
Around line 385 of logotool.module:
case '1':if ($time || !variable_get('logotool_frequency', 0)) {
$logos = logotool_scan_dir(variable_get('logotool_folder', LT_CWD));
if ($time) {
variable_set('logotool_timestamp', time());
}
$last_logo = sprintf("/%s", array_rand($logos));
variable_set('logotool_last_logo', $last_logo);
}
$variables['logo'] = variable_get('logotool_last_logo',0);
break;
This uses a persistent variable to save the random logo for use in subsequent page refreshes. I'm no drupal programmer but this certainly seems to work for me.
#2
Thanks, I'll look into this. TBH the reason the 6.x release is still in dev is because I haven't had time to test it at all outside of what I need it to do myself.
Pobster
#3
Thanks pobster - I'm happy to test any tweaks you make as yours is the only solution I can find for random but time based logos.
For now I'm ok with the fix I made. Thanks for the module.