Hello
I have installed a vote_up_down.module to use for rating posts on nodes and comments by giving them positive (up) and negative (down) points, much like it reddit.com has.
The module is apparently meant to work with the vote_storylink.module as the primary goal seems to be to clone the reddit.com and even digg.com experience. However, I am not planning to do that and I would just like to use it for simple rating of articles, forum posts and blog entries. The module package includes the vote_storylink.module as well as an example template.php and node-storylink.tpl.php where the voting (up and down) widget is already enabled. The help, however, says that I can include the widget through a template for other content types and modules by following a vote-storylink.tpl.php example.
From what I've seen, the example uses this to call and display the widget:
print $vote_up_down_widget
But that doesn't work. Nothing happens and nothing is displayed, even when I turn off the built in display of the widget (for the template switch not to contradict it) from the admin area. And yes, I have copied the context of template.php that was provided. I merged the phptemplate_variables function that is there with the one that already existed in my own, so it ultimately looks like this:
function _phptemplate_variables($hook, $vars) {
static $is_forum;
$variables = array();
if (!isset($is_forum)) {
if (arg(0) == 'node' && is_numeric(arg(1)) && arg(2) == '') {
$nid = arg(1);
}
if (arg(0) == 'comment' && arg(1) == 'reply' && is_numeric(arg(2))) {
$nid = arg(2);
}
if ($nid) {
$node = node_load(array('nid' => $nid));
}
$is_forum = ($node && $node->type == 'forum');
_is_forum($is_forum);
}
if ($is_forum) {
switch ($hook) {
case 'comment' :
$variables['template_file'] = 'node-forum';
$variables['row_class'] = _row_class();
$variables['name'] = $vars['author'];
$variables['userid'] = $vars['comment']->uid;
$joined = module_invoke('flatforum', 'get_created', $vars['comment']->uid);
$variables['joined'] = $joined ? format_date($joined, 'custom', 'Y-m-d') : '';
$posts = module_invoke('flatforum', 'get', $vars['comment']->uid);
$variables['posts'] = $posts ? $posts : 0;
$variables['submitted'] = format_date($vars['comment']->timestamp);
$subject = $vars['comment']->subject;
$variables['title'] = empty($subject) ? ' ' : $subject;
$variables['content'] = $vars['comment']->comment;
$variables['links'] = empty($vars['links']) ? ' ' : $vars['links'];
break;
case 'node' :
$variables['row_class'] = _row_class();
$variables['userid']=$vars['node']->uid;
$joined = module_invoke('flatforum', 'get_created', $vars['node']->uid);
$variables['joined'] = $joined ? format_date($joined, 'custom', 'Y-m-d') : '';
$posts = module_invoke('flatforum', 'get', $vars['node']->uid);
$variables['posts'] = $posts ? $posts : 0;
$variables['title'] = empty($vars['title']) ? ' ' : $vars['title'];
$variables['content'] = $vars['node']->body;
$variables['links'] = empty($vars['links']) ? ' ' : $vars['links'];
$vars['storylink_url'] = check_url($vars['node']->vote_storylink_url);
if (arg(1) != 'add' && arg(1) != 'edit') {
$vars['vote_up_down_widget'] = theme('vote_up_down_widget', $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 $variables;
}
Now, since that didn't work and there was one overridable function in the vote_up_down.module, the function theme_vote_up_down_widget which displays the widget I decided to simply print that function into a template. That actually does it, but not without shouting and screaming. The widget displays, but with an error and a bit screwed up look on all, but the first instance of the widget appearing on a page.
The function above is this:
function phptemplate_vote_up_down_widget($cid, $type) {
global $user;
if (user_access('view up-down vote')) {
$output = '<div class="vote-up-down-widget">';
if (user_access('use up-down vote') && $user->uid) {
$user_vote = votingapi_get_user_votes($type, $cid);
if ($user_vote[0]->value > 0) {
$class = 'vote-up-act';
$class2 = 'vote-down-inact';
}
else if ($user_vote[0]->value < 0) {
$class = 'vote-up-inact';
$class2 = 'vote-down-act';
}
else {
$class = 'vote-up-inact';
$class2 = 'vote-down-inact';
}
$output .= '<span id="vote_up_'. $cid .'" class="'. $class .'" title="'. url("ajax_vote_up_down/$type/$cid/1") .'">'. l('', "vote_up_down/$type/$cid/1", array('class' => $class, 'title' => t('Vote up')), drupal_get_destination(), NULL, FALSE, TRUE) .'</span>';
$output .= '<span id="vote_down_'. $cid .'" class="'. $class2 .'" title="'. url("ajax_vote_up_down/$type/$cid/0") .'">'. l('', "vote_up_down/$type/$cid/0", array('class' => $class2, 'title' => t('Vote down')), drupal_get_destination(), NULL, FALSE, TRUE) .'</span>';
}
else {
$output .= '<span class="up-inact" title="'. t('You must login to vote.') .'"></span>';
$output .= '<span class="down-inact" title="'. t('You must login to vote.') .'"></span>';
}
$output .= '</div>';
return $output;
}
}
I called it from a template like this:
print phptemplate_vote_up_down_widget()
and the warnings I get for it are these:
# warning: Missing argument 1 for phptemplate_vote_up_down_widget() in /home2/nuxorg/public_html/themes/bluetango/template.php on line 222.
# warning: Missing argument 2 for phptemplate_vote_up_down_widget() in /home2/nuxorg/public_html/themes/bluetango/template.php on line 222.
(Note that I've included a function in template.php which is why the above path is like it is, to my themes template.php. I get the same result if I don't override anything as well).
The above two warnings repeat for 10 times.
I really think that calling a function that displays html output should work as I've seen them succesfully used before. So there must be a glitch of some kind or I am just plain missing something.
The reason why I am doing this is that I want the widget to display on a different place than it is now because as it is now it is within the content div which can be annoying to some users (the widget actually appears as if it is within their actual post). I want it moved to the links div instead.
I would appreciate any help on this.
Thank you
Daniel
Comments
I notice you have the
I notice you have the relevant code in template.php inside a if ($is_forum) statement. That means it will only be executed if the node is a forum. Maybe that is part of the problem?
The solution should be this simple. Put this in your template.php file
and insert the widget in your theme like this.
Thank you, I might try that
Thank you, I might try that and let you know if it worked.
I haven't actually resolved the problem, but have settled with simply moving the widget to the right instead on the left via the CSS file. On forums it is on the right and on nodes it is on the left as it is per default.
Oops, that should be... and
Oops, that should be...
and insert the widget in your theme like this.