I am using the mediafield_display module, but this question would apply if I wasn't.

I have a theme variable $zebracount that increments in my _phptemplate_variables() method in my theme (in Drupal 4.7 with the audio module this method would be phptemplate_audio_mp3_player() ). The theme that I have created styles nodes differently depending on a modulo number (aka my zebracount variable). The trouble is when the call is made to my function mythemename_mediafield_display_1pixelout() theme function, the template variable is no longer accessible.

I am trying to do something like:

/**
* Theme a 1pixelout audio file.
*/
function KimmyZen_mediafield_display_1pixelout($file, $item, $field) {
  global $base_url;

  //$options = array();
  //$options['soundFile'] = check_url($base_url .'/'. $file['filepath']);
 
  if ($zebracount == 1) {
  $options = array(
    'soundFile' => check_url($base_url .'/'. $file['filepath']),
    'bg' => '0xFFFFCD',
    'leftbg' => '0xb5bb7d',
    'rightbg' => '0xb5bb7d',
    'rightbghover' => '0xE5EFF5',
    'lefticon' => '0xffffcd',
    'righticon' => '0xffffcd',
    'righticonhover' => '0xE99030',
    'text' => '0x537e53',
    'slider' => '0xb5bb7d',
    'loader' => '0xfac46c',
    'track' => '0xFFFFFF',
    'border' => '0x537e53',
  );
  } else {
   // different colors here
   $options = array(
    'soundFile' => check_url($base_url .'/'. $file['filepath']),
    'bg' => '0xFFFFCD',
    'leftbg' => '0xb5bb7d',
    'rightbg' => '0xb5bb7d',
    'rightbghover' => '0xE5EFF5',
    'lefticon' => '0xffffcd',
    'righticon' => '0xffffcd',
    'righticonhover' => '0xE99030',
    'text' => '0x537e53',
    'slider' => '0xb5bb7d',
    'loader' => '0xfac46c',
    'track' => '0xFFFFFF',
    'border' => '0x537e53',
    );
  }

  $url = $base_url .'/'. drupal_get_path('module', 'mediafield_display') .'/players/1pixelout.swf';

  $flashvars = array();
  foreach ($options as $key => $val) {
    $flashvars[] = rawurlencode($key) .'='. rawurlencode($val);
  }
  $flashvars = implode('&', $flashvars);

$output = <<<EOT
<object type="application/x-shockwave-flash" data="$url" width="290" height="24" >
  <param name="movie" value="$url" />
  <param name="wmode" value="transparent" />
  <param name="menu" value="false" />
  <param name="quality" value="high" />
  <param name="FlashVars" value="$flashvars" />
</object>
EOT;

  return $output;
}

Can anyone help me with how to have my zebracount variable available in the ..._mediafield_display_1pixelout() function()?

Thanks

Rich

Comments

coreyp_1’s picture

Just add: global $zebracount; at the beginning of each function that uses the variable.

It's not the cleanest method, but it will get the job done...

- Corey

rl’s picture

I tried that, but the issue was that the variable was not updated or created yet when my function was called.

I ended up doing this in the theme file

     <?php
      	if ($zebracount == 1) {
	  $onepixeloutstyle = '&bg=0xFFFFCD&leftbg=0xfac46c&rightbg=0xfac46c&rightbghover=0xffffcd&lefticon=0xffffcd&righticon=0xffffcd&righticonhover=0xE99030&text=0x537e53&slider=0xb5bb7d&loader=0xfac46c&track=0xFFFFFF&border=0x537e53';
	} else {
     	  $onepixeloutstyle = '&bg=0xFFFFCD&leftbg=0xb5bb7d&rightbg=0xb5bb7d&rightbghover=0xffffcd&lefticon=0xffffcd&righticon=0xffffcd&righticonhover=0xE99030&text=0x537e53&slider=0xb5bb7d&loader=0xfac46c&track=0xFFFFFF&border=0x537e53';
	}
	
     	$pattern = '/(soundFile=.*)"/';
	$replacement = '$1' . $onepixeloutstyle . '"';
	$newcontent = preg_replace($pattern, $replacement, $content);
	?>
      <?php print $newcontent; ?>

I spent several evenings trying to do it with JQuery, but in the end I needed to get this done, so I did it brute force. Thanks for responding.

Rich