Rotate captions along with the logo?

lambert - June 12, 2007 - 13:43
Project:Logo Tool
Version:5.x-2.3
Component:Code
Category:feature request
Priority:normal
Assigned:Unassigned
Status:closed
Description

I'd like to be able to rotate captions for the logos along with the logos. I've tried using the $logo filename in logo.php as a key to an associative array of captions, but the caption and the logo still get out of synch.

Not always, but sometimes.

This happens whether I pass the filename key in $_SESSION, via set_variable, or even in $_GET.

What gives? It sounds like caching behavior. Can I detect when art is being pulled from the cache and when it isn't, and adjust the caption accordingly?

#1

pobster - June 12, 2007 - 13:53

Sorry but I have absolutely no idea of what you're asking...? I think you're saying that you've altered your theme to show your logos with a title attribute like... <img title="something" src="... (or whatever) and you want to have control over that title attribute? Is this correct? Sorry but the information you've given me just isn't enough for me to determine *exactly* what you're trying to do...

Pobster

--------------------------------------------
http://www.justgiving.com/paulmaddern
--------------------------------------------

#2

lambert - June 12, 2007 - 15:37

This is in page.php.tpl:

<?php
function get_logo_caption() {
     
// associative array of file names to captions
     
include "captions.inc";
   
//  $logo = variable_get('logotool_logo','');
    //  $logo = isset($_GET['logo']) ? $_GET['logo'] : variable_get('logotool_logo','');
    //  $logo = $_GET['logo'];
      
$logo = variable_get('logotool_captionlogo','');

   
$logo = basename($logo);

   if ((
$logo != '') && (array_key_exists($logo,$logo_to_caption))) {
    
$result = $logo_to_caption[$logo];
   }
   else {
      
$result = '[default caption]';
   }
   return
$result;
}
?>

And this is further down in page.php.tpl:
<div class='site-caption'><?php print get_logo_caption() ?></div>

And here the filename is stored in logos.php:
variable_set('logotool_captionlogo',$logo);
 
// Return image information ...

I'm calling get_logo_caption() after logo.php, and so I thought I would get the caption keyed to the file name of the image , in synch. But instead I get the caption of the previosly displayed image. So I must be missing something really obvious....

#3

pobster - June 12, 2007 - 16:33

Wow! That seems to me to be a really roundabout way of achieving what you want! Here's what I think I'd do...

Ignore logo.php - it's just a file server it's not where the logo variable is set, you can't really rely on this remaining constant for all sorts of reasons...

Go straight to logotool.module function _init and right at the end add something in there;

<?php
//....blah blah
       
}
      }
      break;
  }
// end switch
// new bit below
 
$caption = logotool_match_logo_to_caption(variable_get('logotool_logo', ''));
 
variable_set('logotool_caption', $caption);
}
// logotool_init

function logotool_match_logo_to_caption($logo) {
 
// do that matchy thing you did
 
return $caption;
}

// rest of module code...
?>

Then just return the caption using its variable in page.tpl.php - much less fuss!

Pobster

--------------------------------------------
http://www.justgiving.com/paulmaddern
--------------------------------------------

#4

lambert - June 12, 2007 - 17:43

Thanks, using hook_init is less roundabout, but it doesn't solve the problem.

The captions still aren't in synch with the pictures. Sometimes they are, sometimes they aren't.

And it's not the Drupal cache, I don't think, because the behavior persists when I turn caching off (I have normal cache on.) And it's not the browser's cache, because when I empty that the behavior persists.

Even more interesting: When I log out, the picture still rotates when I click on the logo. But the caption does not. Here is the template:

// $logotool_logo prints nothing
<div class='site-caption'><?php print variable_get('logotool_caption','[default caption]'); ?></div>

And the code you suggested to add:
  $caption = logotool_match_logo_to_caption(variable_get('logotool_logo','[default caption]'));
  variable_set('logotool_caption',$caption);
  
} // logotool_init
 
function logotool_match_logo_to_caption($logo) {
  include "captions.inc";
  $logo = basename($logo);
  if (($logo != '') && array_key_exists($logo,$logo_to_caption)) {
    $result = $logo_to_caption[$logo];
  }
  else {
    $result = 'View from the Fellows Lounge of the Mighty Corrente Building.';
  }  
  return $result;
}

Thanks. People love the rotating logo, but I really need the captions too...

#5

pobster - June 12, 2007 - 18:59

Hiya! Sorry only just read your reply, but something does jump out at me with your code...

This line;   if (($logo != '') && array_key_exists($logo,$logo_to_caption)) {

$logo_to_caption isn't defined anywhere? So... That "if" statement can never be executed? I can't understand how it ever works at all??? In fact I'm surprised your php doesn't crap out with an error telling you that $logo_to_caption isn't an array? What's in this mysterious "captions.inc" file?? ;o)

Pobster

--------------------------------------------
http://www.justgiving.com/paulmaddern
--------------------------------------------

#6

lambert - June 12, 2007 - 21:50

The captions.inc file is where that array lives. I'm getting stuff out of the array, believe me. It's just not in sync with the pictures (all the time).

#7

pobster - June 12, 2007 - 22:04

Hmmm... Just thought - what mode are you using? And are you using the 'time delay' for random logos? If so... Perhaps rather than have;

  $caption = logotool_match_logo_to_caption(variable_get('logotool_logo','[default caption]'));
  variable_set('logotool_caption',$caption);

At the end of hook_init, perhaps try setting it after the mode has set the logotool_logo variable instead. Reason for thinking this is that the logo isn't always set when _init is called, yet having that call at the end means caption is being called every time. Try it and see;

eg.

    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());
        variable_set('logotool_logo', substr(array_rand($logos), strlen(variable_get('logotool_folder', LT_CWD))));
        variable_set('logotool_caption', logotool_match_logo_to_caption(variable_get('logotool_logo','[default caption]')));
      }
      break;

Pobster

--------------------------------------------
http://www.justgiving.com/paulmaddern
--------------------------------------------

#8

lambert - June 13, 2007 - 03:05

I'll try that. For some reason, I got pages that didn't build all the way with logotool_match_logo_to_caption outside the switch statement. (And thanks for doing this. I was so desperate to get the thing going I didn't stop to get above the problem and see what that case statement was doing.)

Incidentally, I bet I'm not the only person who would like this feature. There's also a use case, for example, where the logo images need to have rights statements along with them, and the rights statements would would have to rotate with the logos. Same deal with credits and cutlines.)

#9

lambert - June 14, 2007 - 10:15

No, that didn't do it:

<?php
   
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());
       
variable_set('logotool_logo', substr(array_rand($logos), strlen(variable_get('logotool_folder', LT_CWD))));
       
variable_set('logotool_caption',logotool_match_logo_to_caption(variable_get('logotool_logo','[default caption]')));
      }
      break;
?>

Starts out fine, then gets out of synch. So in page.tpl.php, I did this:
<div class='site-caption'><?php print variable_get('logotool_logo','[default caption]') ?></div>

to print out $logotool_logo instead of the caption it's the key for, and in page.tpl.php, $logotool_logo gives a different filename from the filename of the image that is actually displayed. (Also, I had my settings for a random logo on every page display, so getting the variable at the end of the switch should have worked to, since I am getting a new image every time. )

My cache setting is normal, not off. But I turned off Drupal caching, truncated all of the cache tables in the database, and emptied my brower's cache. Still no joy.

P.S. Two more use cases: (1) Captions for cartoons. (I'm reluctant to make the caption part of the image because I don't get the t() function then.) (2) Advertising where the text needs to vary separately from the image. (The rotation is really eyecatching, and I can see why an advertiser would want to leverage it.)

#10

lambert - June 14, 2007 - 10:59

More:

1. Checked my logs, and saw that a space before the <?php was throwing an error. I removed it, but still no joy.

2. Tried changing "include 'captions.inc'" to "include_once 'captions.inc'" in logotool_match_logo_to_caption function, but still no joy. If anything, it made things more out of synch than before.

(Trying with Drupal caching on and off, and emptying the database cache, for each of these.)

#11

pobster - June 14, 2007 - 11:52

Wouldn't it be better to use say, the banner module to do what you want to do? (or maybe a custom snippet?) I mean, yes logotool *does* rotate logos, but I can't imagine many people will want actual 'content' as their logo. I should imagine you're quite a minority with what you're attempting to do - sacrificing your own sites logo to provide *something* eg. a cartoon strip (as you suggested). I can't think of a situation where I myself would want to do this, plus there's no way even if you do get this to work that I'm going to commit it to the module - it involves making changes to your theme, most people are not going to want to do this...

Surely it's better to use the banner module, it'll allow you so much more freedom than a site logo fileserver? I mean it's not like Drupal out of the box gives you the option to add a caption to your sites logo, it's just not necessary?

Pobster

--------------------------------------------
http://www.justgiving.com/paulmaddern
--------------------------------------------

#12

pobster - August 6, 2007 - 16:17
Status:active» closed
 
 

Drupal is a registered trademark of Dries Buytaert.