I just wanna clarify some features are possible in five
star and voting api module.

Enabling the five star rating to a content type, results in showing the five
star rating to all the nodes created in that content type.

1.on visiting the seperate node we can see the star rating and the text below
the stars as "Your rating:3
(3 votes)" and it shows the 3 stars as red in color(whatever v have given the
rating it may 4 or 5 or 2 ....).

I bring all the nodes in a page through view ,in that page, if we clicked on
the stars it shows the Your rating as 3(for example) and the stars are in red
in color. If we refresh the page the stars are not in red color but the text
below the stars shows "Your rating:3" .
My question is , is it possible to bring the stars in red color after
refreshing the page? or is this the feature existing with these mdule?

2.The authenticated and admin users doesn't have this problem.As voting as an
anonymous user from an IP address (for example giving star rating as 5),the
text below the star rating as "Your rating:5" and after refreshing the page
in shows "your rating:None" but it counts the vote from this IP and anonymous
User.Is this the nature of these module or can we bring out this rating as
"Your rating:5" for anonymous user after refreshing ?

If these are possible means, please help me to do this.

Comments

Aamuktha’s picture

Hi all,

Finally the second issue is fixed,

In the drupal module file I made some changes ,

if ($uid) {
    $user_vote = votingapi_select_votes($criteria += array('uid' => $uid));
    if ($user_vote) {
   
      $votes['user'] = $user_vote[0];
      $votes['user']['function'] = 'user';
     }
  }
  else {

      $result = array();
      $user_vote = votingapi_select_votes($criteria += array('uid' => $uid));

      $ip_address = $_SERVER['REMOTE_ADDR'];
      for($i=0;$i<count($user_vote);$i++){
         $select_vote = db_query("SELECT * FROM votingapi_vote WHERE vote_source = '".$ip_address."' and content_id = '".$cid."' order by vote_id desc limit 0,1");
         $result_vote = db_fetch_array($select_vote);
         $result[0] = $result_vote;
      }
     
         if ($result) {
          $votes['user'] = $result[0];
          $votes['user']['function'] = 'user';
        }
     
        // If the user is anonymous, we never bother loading their existing votes.
        // Not only would it be hit-or-miss, it would break page caching. Safer to always
        // show the 'fresh' version to anon users.
        //$votes['user'] = array('value' => 0);
  }

  return $votes;
}  
 

Instead of the following code,

if ($uid) {
    $user_vote = votingapi_select_votes($criteria += array('uid' => $uid));
    if ($user_vote) {
      $votes['user'] = $user_vote[0];
      $votes['user']['function'] = 'user';
    }
  }
  else {
    // If the user is anonymous, we never bother loading their existing votes.
    // Not only would it be hit-or-miss, it would break page caching. Safer to always
    // show the 'fresh' version to anon users.
    $votes['user'] = array('value' => 0);
  }

  return $votes;
}

Now the anonymous user can also view their rating from which IP they voted.

floydm’s picture

Thank you for posting this fix (#1). One issue I ran into with it though. You have:

      $ip_address = $_SERVER['REMOTE_ADDR'];

In order to work on sites that are running reverse proxies or load balancers it needs to be:

       $ip_address = ip_address();

Once I made that change it worked perfectly for me.

-Floyd

whiteph’s picture

Issue summary: View changes
Status: Active » Closed (won't fix)

Sorry, Drupal 6 is end of life, and is no longer supported.