Hello frjo,

I'm trying to put your widget in my custom theme, though it does not work.
I'm using
<?php print $vote_up_down_widget ?> in my custom node tpl file.
I have also copy pasted your code (which was in the example template.php) into my template.php in my theme folder.
I'm pretty sure everything I did is correct. That's why I believe your module contains a bug, somehow.
Please let me know what I am doing wrong? Or else, it must be a bug, right?

I hope you can help me, thanks in advance.

-Laurent

Comments

Laurentvw’s picture

Priority: Normal » Critical
Status: Active » Needs work

Okay so I found your lame bug. Let me paste your template.php code:

<?php
// $Id: template.php,v 1.5 2006/11/24 13:18:35 frjo Exp $

function _phptemplate_variables($hook, $vars) {
  switch($hook) {
    case 'node':
      $vars['storylink_url'] = check_url($vars['node']->vote_storylink_url);
      if (arg(1) != 'add' && arg(2) != 'edit') {
        $style = variable_get('vote_up_down_widget_style_node', 0) == 1 ? '_alt' : '';
        $vars['vote_up_down_widget'] = theme("vote_up_down_widget$style", $vars['node']->nid, 'node');
        $vars['vote_up_down_points'] = theme("vote_up_down_points$style", $vars['node']->nid, 'node');
      }
      $vars['vote_storylink_via'] = theme('vote_storylink_via', $vars['node']->vote_storylink_url);
      if (arg(1) == 'top') {
        static $count;
        $count = is_array($count) ? $count : array();
        $count[$hook] = is_int($count[$hook]) ? $count[$hook] : 1;
        $vars['seqid'] = $count[$hook]++;
      }
      break;
  }
  return $vars;
}
?>

As you can see, the widget will only get outputted when 'node' (case) is true. I assume you are checking if the url is indeed a node. But what if someone uses url aliases, thus, no 'node' will be included in the url, which will result in a "FALSE", and consequently the widget will not get displayed.

So, how to make it work? Here's how:

<?php
function _phptemplate_variables($hook, $vars) {

      $vars['storylink_url'] = check_url($vars['node']->vote_storylink_url);
      if (arg(1) != 'add' && arg(2) != 'edit') {
        $style = variable_get('vote_up_down_widget_style_node', 0) == 1 ? '_alt' : '';
        $vars['vote_up_down_widget'] = theme("vote_up_down_widget$style", $vars['node']->nid, 'node');
        $vars['vote_up_down_points'] = theme("vote_up_down_points$style", $vars['node']->nid, 'node');
      }
      $vars['vote_storylink_via'] = theme('vote_storylink_via', $vars['node']->vote_storylink_url);
      if (arg(1) == 'top') {
        static $count;
        $count = is_array($count) ? $count : array();
        $count[$hook] = is_int($count[$hook]) ? $count[$hook] : 1;
        $vars['seqid'] = $count[$hook]++;
      }
      

  return $vars;
}
?>

It simply doesn't check if the current page is a node or not.

-Laurent

Laurentvw’s picture

u kick ass laurent (im so awesome I KNOW laurent :)

prameya’s picture

woo.. .now i am awesome^200 i got to use laurent's account :) please kick my ass laurent.. make me that lucky...!!

prameya’s picture

i guess that looks kinda gay... but your still the man!

oh.. and you suck ass for that stupid bug... i'd say it was okay if it was a mammal... but bug.. not acceptable... but still kudos for the code...!

frjo’s picture

Category: bug » support
Priority: Critical » Normal
Status: Needs work » Closed (fixed)