Support from Acquia helps fund testing for Drupal Acquia logo

Comments

realityloop’s picture

I'm not sure how to make $vote_count accesible from vud_comment.module, how would I pass the variable which is abailable in vud.theme.inc to vud_comment.module?

marvil07’s picture

There is a $points variable inside the widget template(retrieved on vud_widget_proxy()), which is calculated using:

  $result_criteria = array(
    'content_type' => $type,
    'content_id' => $content_id,
    'value_type' => 'points',
    'tag' => $tag,
    'function' => 'sum'
  );
  $vote_result = (int) votingapi_select_single_result_value($result_criteria);

So, what we need to do is set a class on comment depending on vote_result value.

realityloop’s picture

FileSize
2.97 KB

I'm almost done at the moment getting static hides in place, I aim to make the cutoff point configurable once this issue is sorted.

I just need help with making $vote_count variable available in vud_comment.module. see TODO comment at line 75

realityloop’s picture

FileSize
3.55 KB

Patch attached with settings for Trigger point for dimmed comments.

I still need help with making $vote_count variable available in vud_comment.module though. see TODO comment at line 81 of vud_comment.module after applying patch.

greggles’s picture

Status: Active » Needs work
FileSize
4.27 KB

Here's an updated patch (untested) but I think it should work.

realityloop’s picture

Status: Needs work » Needs review
FileSize
11.52 KB

Thanks greggles that didn't work here, but led me to a working solution.

Working patch attached, also did some cleanup of other files as recommended by Coder.

jcisio’s picture

Status: Needs review » Needs work

I think there is a solution better than override the comment theme (there are themes with customized comment.tpl.php already). The collapsed part is great. Why just make the comment $content collapsible? It's even better if there is a text "click here to show the comment", when clicking on it, the text will be replaced with the content. But I don't know if something like that is available, or is it easy to implement with jQuery.

There are also some debug code in the last patch: ($comment->cid > 89654 && strpos($base_url, 'groups')) || ($comment->cid > 1266382)

greggles’s picture

That's not debug code, it's for the drupal.org theme. realityloop is working on this in part for groups.drupal.org (which is awesome of him) so his code may include some site specific things which should not be committed to the main project directly.

realityloop’s picture

Status: Needs work » Needs review

As per greggles comment marking this as needs review again so marvil07 or lut4rp will review

marvil07’s picture

Status: Needs review » Needs work

Thanks for the work here.

It would be great if you split the patch in two: one in this issue for the relevant code, and other in #786902: Review code with coder about code standards.

The patch works only if I use the proposed comment template in my theme(garland by default overwrite comment.tpl.php). It seems like the only way to accomplish that because there is not a $classes variable inside the comment. I'm not really convinced about that solution.

Other alternatives(making the decision in the theme preprocess function instead of inside the comment template) could be:

- define a theme variable for comment.tpl.php template, and let the user put that variable in his template.
- hack the $status variable to include the relevant class.

But those are neither "good" solutions, so I'm open for suggestions.

About css it seems to the only way to get cross-browser opacity now, so great.

Naturally, please do not include g.d.o custom code in the patch.

I suppose I need more feedback about the right way to "dim" irrelevant comments, so opacity is a good option, but auto-collapse could be another one(kind of what slashdot use). So if someone has more options about that, please join the discussion :-)

jcisio’s picture

I think the easiest way, and suitable for most themes, is something like this in the preprocess:

if ($need_deem_it) {
  $content = "<a id='show-comment-12345'>Click here to show hidden comment</a><div id='wrapper-comment-12345' class='comment-hidden'>". $content ."</div>";
}

And some jQuery script to remove/switch class on a click over ^show-comment

My €.02

realityloop’s picture

I'm planning to investigate collapsing eventually, look at http://groups.drupal.org/node/65763

Re-rolled patch with Coder review stripped out and comment.tpl.php based on default from /modules/comment is attached.

realityloop’s picture

Status: Needs work » Needs review

status

marvil07’s picture

Status: Needs review » Needs work

Thanks for the quick response :-)

Some suggestions:

- Insert the logic about marking as dimmed in the preprocess function(vud_comment_preprocess_comment())
- use vud-comment-dimmed as the class to identify it.
- IMHO this hunk is not necessary:

@@ -226,7 +228,10 @@ function vud_votes_proxy($content_id, $t
   }
   else {
     $variables['points'] = $vote_result;
-    if ($vote_result < 0) {
+    if ($vote_result < variable_get('vud_comment_dimmed', array())) {
+      $variables['class'] = 'negative-dimmed';
+    }
+      elseif ($vote_result < 0) {
       $variables['class'] = 'negative';
     }
     else {

.. since the real use of the class is by printing on comment.tpl.php
- vud.module is not modified, avoid that hunk too
- make dim feature optional, by setting a flag in vud_comment configuration page.

realityloop’s picture

Status: Needs work » Needs review
FileSize
6.99 KB

Added instructions to INSTALL.txt for adding required code to any theme's comment.tpl.php

Note: I posted this before previous comment was visible.. working on it..

realityloop’s picture

Trying to get preprocess suggestion implemented but not sure I'm doing it right, could you give me some assistance?

<?php
function vud_comment_preprocess_comment(&$variables) {
  if (isset($comment->vud_sum) && ($comment->vud_sum <= $comment->vud_dim)) {
    $vud_comment_dimmed = 'vud-comment-dimmed';
  }
  // set status to a string representation of comment->status.
  if (isset($comment->preview)) {
    $variables['status']  = 'comment-preview' . $vud_comment_dimmed ;
  }
  else {
    $variables['status']  = ($comment->status == COMMENT_NOT_PUBLISHED) ? 'comment-unpublished' . $vud_comment_dimmed : 'comment-published' . $vud_comment_dimmed;
  }
}
?>
realityloop’s picture

-Dimming now optional by leaving field blank or setting to 0
-Improved settings form description
-Redundant code removed
-Class name changed.

I still need assistance with implementing 'vud_comment_preprocess_comment()' though, see vud_comment.module line 107 after applying this patch.

realityloop’s picture

Bump

realityloop’s picture

-implemented 'vud_comment_preprocess_comment()' as requested in #14
-removed need to edit comment.tpl.php
-updated INSTALL.txt due to removal of comment.tpl.php

*thanks davereid for setting me on the right path*

gausarts’s picture

Subscribing. Thanks

realityloop’s picture

Hi Gaus,

Could you perhaps test the patch and mark it RTBC if you think it works fine?

Cheers,
Brian

gausarts’s picture

Hi,
I love fun stuff, so I played around with it happily, and here is the results in my test bed:

1. I wanted to have great control on placing the widget, so I simply disable "Node type" selection and put the widget anywhere in the comment.tpl. This prevents double widgets. Setting -1 to trigger dimmed comment. And it FAILS to work.

2. I tried to go the regular placement by enabling one of the node types, it indeed WORKS.

So my expectation for improvement, can you possibly make the dim independent from "node type" selection, so it can also work when the widget is pulled apart from $comment object? The reason is the widget is working outside the $comment, so the dim hopefully can also work outside $comment object.

Thanks for a very sweet additional feature.

realityloop’s picture

#22

I don't quite follow what your describing, could you try describing it another way please?

lut4rp’s picture

I have exams right now, but I'll take some time out today (hopefully) and do a review.

gausarts’s picture

Ok, sorry for not being clear.

I have two ways to display the vud widget, and notice that dim only works with way #2:

1. Anywhere. I can only do this if I DISABLE "node type" option at admin/settings/voteupdown/comment. This is to prevent the appearance of two widgets within comment.tpl (one default widget contained by $comment and another by my custom placement).

2. Default. As is contained by $comment, and I have to enable "node type" option at admin/settings/voteupdown/comment

So this dim functionality will be great if only works with way #1 as well.

Thanks.

gausarts’s picture

I know this is not the right solution, since this is hard-coded to my specific need, but works when my widget is placed anywhere outside $comment:

<?php
$tag = isset($variables['tag']) ? $variables['tag'] : variable_get('vote_up_down_tag', 'userpoints_karma');
    $criteria = array(
    'content_type' => 'comment',
    'content_id' => $comment->cid,
    'value_type' => 'points',
    'tag' => $tag,
    'function' => 'sum'
    );
   $vote_result = (int)votingapi_select_single_result_value($criteria);
   if ($vote_result <= -1) {
     $vud_comment_dimmed = ' vud-comment-dimmed';
   }
?>

So I'll wait for your patches to get into the module.

Thanks

marvil07’s picture

Re #25: "two widgets displayed" seems to be unrelated, please take a look at How to display voting widget by API? (I think the error is just because you are disabling votes for that type).

Thanks for the changes realityloop!

Finally I going to review this today in some hours :-p at a local user meeting! .. sorry for the delay but, like Pratul, I have one exam today.

In the other hand, make this generic to other entities(nodes and terms) sounds pretty good, but not sure how to do that, so let's see what I can do in the afternoon.

realityloop’s picture

thanks,good luck with your exams!

marvil07’s picture

FileSize
4.1 KB

Ok, finally I could review this :-)

I've seen some notices in various places and I decided to use dependent from ctools ;-) (BTW ctools is great!)

So, I have a new patch that:

  • change the default behaviour to not use dim comments, so I also removed the INSTALL.txt
  • load dim css only on comments(vud_widget_proxy is for all types)
  • use two variables instead of one for dim configuration(active/inactive and dim threshold)
  • validate the input at configuration
  • move the dim logic from comment view to comment preprocess(IMHO is clearer there), also remove some unnecessary logic in that code portion.
  • remove spaces at css

In the other hand, I think dim really applies naturally only for comments, so that's the reason I did not try a more general approach.

about using collapsible divs, IMO it would be great to have that, but I think it should be in another issue, so feel free to create it

Please take a look at this patch, I hope we can commit this soon ;-)

realityloop’s picture

Status: Needs review » Reviewed & tested by the community

#29 works fine here

gausarts’s picture

#29 works like a charm with custom widget placement, and plus +1 for cTools. Thanks

UPDATE: I should rephrase it correctly, since cTools is already in 6.2*, that additional cTools setting is a real plus. I am learning much :)

greggles’s picture

I think this issue should really focus on comments only. If people want to add it to nodes or other objects (I can see cases where it makes sense) then that could be another issue.

Once we get this committed the question becomes, when can we roll out 6.x-2.x-dev to groups.drupal.org :)

marvil07’s picture

Status: Reviewed & tested by the community » Fixed

committed.

About g.d.o, mayb eis better to wait until a beta since I marked some issues as release blockers today :-p (aka finally I could read the whole queue)

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.