All Good Things Must Come To An End

As you all know, I have been doing WordPress plugins and supporting it for the past 6 years. These 6 years of my life, I have been through my polytechnic education, my national service as well as my university education.

I just graduated from university in December 2009 and have been looking for full-time jobs. I am offered a full-time job and will be starting work on 1st February 2010.

I regret to say that I am NOT ABLE to provide support for my plugins anymore due to my full-time job commitment. I will leave this forum open and let the community help one another.

However, I WILL still update my plugins whenever I can and you still can report bugs to me via email and I will try to fix it.

Author Topic: Thumbs / Plus-minus / Nero rating  (Read 3417 times)

0 Members and 1 Guest are viewing this topic.

Offline Dont

  • Newbie
  • *
  • Posts: 1
    • View Profile
  • WordPress Version: WordPress 3.0.x
  • Theme Name: Sandbox
Thumbs / Plus-minus / Nero rating
« on: 02 January 2011, 23:47 »
I spent a great deal of time figuring these out, so I thought I'd share these.

Number of thumbs up / down:

1. Make a copy of wp-postratings.php in case something goes wrong.
2. Open wp-postratings.php with your editor of your choice.
3. Search $value = str_replace("%RATINGS_USERS%"
4. Insert the following below that line:
Code: [Select]
$value = str_replace("%RATINGS_UP%", ($post_ratings_users + $post_ratings_score) / 2, $value);
$value = str_replace("%RATINGS_DOWN%", ($post_ratings_users - $post_ratings_score) / 2, $value);
5. Save your changes and upload the file.

Now you can use %RATINGS_UP% and %RATINGS_DOWN% at the templates to display the number of ups and downs.

Note that you must have two choices, with values set for +1 and -1 (or vice versa) for this to work, otherwise it might produce funny numbers.

Number of ups and downs between the voting icons:

1. Do the steps written above
2. Search for function get_ratings_images_vote
3. Insert the following above it (separated from both that and the code above):
Code: [Select]
function get_ratings_images_vote_thumbs($post_id, $ratings_custom, $ratings_max, $post_rating, $ratings_image, $image_alt, $insert_half, $ratings_texts) {
global $text_direction;
$ratings_images = '';
if('rtl' == $text_direction && file_exists(WP_PLUGIN_DIR.'/wp-postratings/images/'.$ratings_image.'/rating_start-rtl.'.RATINGS_IMG_EXT)) {
$ratings_images .= '<img src="'.plugins_url('/wp-postratings/images/'.$ratings_image.'/rating_start-rtl.'.RATINGS_IMG_EXT).'" alt="" class="post-ratings-image" />';
} elseif(file_exists(WP_PLUGIN_DIR.'/wp-postratings/images/'.$ratings_image.'/rating_start.'.RATINGS_IMG_EXT)) {
$ratings_images .= '<img src="'.plugins_url('/wp-postratings/images/'.$ratings_image.'/rating_start.'.RATINGS_IMG_EXT).'" alt="" class="post-ratings-image" />';
}
if($ratings_custom) {
for($i=1; $i <= $ratings_max; $i++) {
if ('rtl' == $text_direction && file_exists(WP_PLUGIN_DIR.'/wp-postratings/images/'.$ratings_image.'/rating_'.$i.'half-rtl.'.RATINGS_IMG_EXT)) {
$use_half_rtl = 1;
} else {
$use_half_rtl = 0;
}
$ratings_text = stripslashes($ratings_texts[$i-1]);
if($i <= $post_rating) {
$ratings_images .= '<img id="rating_'.$post_id.'_'.$i.'" src="'.plugins_url('/wp-postratings/images/'.$ratings_image.'/rating_'.$i.'_on.'.RATINGS_IMG_EXT).'" alt="'.$ratings_text.'" title="'.$ratings_text.'" onmouseover="current_rating('.$post_id.', '.$i.', \''.$ratings_text.'\');" onmouseout="ratings_off('.$post_rating.', '.$insert_half.', '.$use_half_rtl.');" onclick="rate_post();" onkeypress="rate_post();" style="cursor: pointer; border: 0px;" />';   
} elseif($i == $insert_half) {
if ($use_half_rtl) {
$ratings_images .= '<img id="rating_'.$post_id.'_'.$i.'" src="'.plugins_url('/wp-postratings/images/'.$ratings_image.'/rating_'.$i.'_half-rtl.'.RATINGS_IMG_EXT).'" alt="'.$ratings_text.'" title="'.$ratings_text.'" onmouseover="current_rating('.$post_id.', '.$i.', \''.$ratings_text.'\');" onmouseout="ratings_off('.$post_rating.', '.$insert_half.', '.$use_half_rtl.');" onclick="rate_post();" onkeypress="rate_post();" style="cursor: pointer; border: 0px;" />';
} else {
$ratings_images .= '<img id="rating_'.$post_id.'_'.$i.'" src="'.plugins_url('/wp-postratings/images/'.$ratings_image.'/rating_'.$i.'_half.'.RATINGS_IMG_EXT).'" alt="'.$ratings_text.'" title="'.$ratings_text.'" onmouseover="current_rating('.$post_id.', '.$i.', \''.$ratings_text.'\');" onmouseout="ratings_off('.$post_rating.', '.$insert_half.', '.$use_half_rtl.');" onclick="rate_post();" onkeypress="rate_post();" style="cursor: pointer; border: 0px;" />';
}
} else {
$ratings_images .= '<img id="rating_'.$post_id.'_'.$i.'" src="'.plugins_url('/wp-postratings/images/'.$ratings_image.'/rating_'.$i.'_off.'.RATINGS_IMG_EXT).'" alt="'.$ratings_text.'" title="'.$ratings_text.'" onmouseover="current_rating('.$post_id.', '.$i.', \''.$ratings_text.'\');" onmouseout="ratings_off('.$post_rating.', '.$insert_half.', '.$use_half_rtl.');" onclick="rate_post();" onkeypress="rate_post();" style="cursor: pointer; border: 0px;" />';
}
if ($i == 1) {
$ratings_images .= '%RATINGS_DOWN%';
} else {
$ratings_images .= '%RATINGS_UP%';
}
}
} else {
if ('rtl' == $text_direction && file_exists(WP_PLUGIN_DIR.'/wp-postratings/images/'.$ratings_image.'/rating_half-rtl.'.RATINGS_IMG_EXT)) {
$use_half_rtl = 1;
} else {
$use_half_rtl = 0;
}
for($i=1; $i <= $ratings_max; $i++) {
$ratings_text = stripslashes($ratings_texts[$i-1]);
if($i <= $post_rating) {
$ratings_images .= '<img id="rating_'.$post_id.'_'.$i.'" src="'.plugins_url('/wp-postratings/images/'.$ratings_image.'/rating_on.'.RATINGS_IMG_EXT).'" alt="'.$ratings_text.'" title="'.$ratings_text.'" onmouseover="current_rating('.$post_id.', '.$i.', \''.$ratings_text.'\');" onmouseout="ratings_off('.$post_rating.', '.$insert_half.', '.$use_half_rtl.');" onclick="rate_post();" onkeypress="rate_post();" style="cursor: pointer; border: 0px;" />';   
} elseif($i == $insert_half) {
if ($use_half_rtl) {
$ratings_images .= '<img id="rating_'.$post_id.'_'.$i.'" src="'.plugins_url('/wp-postratings/images/'.$ratings_image.'/rating_half-rtl.'.RATINGS_IMG_EXT).'" alt="'.$ratings_text.'" title="'.$ratings_text.'" onmouseover="current_rating('.$post_id.', '.$i.', \''.$ratings_text.'\');" onmouseout="ratings_off('.$post_rating.', '.$insert_half.', '.$use_half_rtl.');" onclick="rate_post();" onkeypress="rate_post();" style="cursor: pointer; border: 0px;" />';
} else {
$ratings_images .= '<img id="rating_'.$post_id.'_'.$i.'" src="'.plugins_url('/wp-postratings/images/'.$ratings_image.'/rating_half.'.RATINGS_IMG_EXT).'" alt="'.$ratings_text.'" title="'.$ratings_text.'" onmouseover="current_rating('.$post_id.', '.$i.', \''.$ratings_text.'\');" onmouseout="ratings_off('.$post_rating.', '.$insert_half.', '.$use_half_rtl.');" onclick="rate_post();" onkeypress="rate_post();" style="cursor: pointer; border: 0px;" />';
}
} else {
$ratings_images .= '<img id="rating_'.$post_id.'_'.$i.'" src="'.plugins_url('/wp-postratings/images/'.$ratings_image.'/rating_off.'.RATINGS_IMG_EXT).'" alt="'.$ratings_text.'" title="'.$ratings_text.'" onmouseover="current_rating('.$post_id.', '.$i.', \''.$ratings_text.'\');" onmouseout="ratings_off('.$post_rating.', '.$insert_half.', '.$use_half_rtl.');" onclick="rate_post();" onkeypress="rate_post();" style="cursor: pointer; border: 0px;" />';
}
}
}
if('rtl' == $text_direction && file_exists(WP_PLUGIN_DIR.'/wp-postratings/images/'.$ratings_image.'/rating_end-rtl.'.RATINGS_IMG_EXT)) {
$ratings_images .= '<img src="'.plugins_url('/wp-postratings/images/'.$ratings_image.'/rating_end-rtl.'.RATINGS_IMG_EXT).'" alt="" class="post-ratings-image" />';
} elseif(file_exists(WP_PLUGIN_DIR.'/wp-postratings/images/'.$ratings_image.'/rating_end.'.RATINGS_IMG_EXT)) {
$ratings_images .= '<img src="'.plugins_url('/wp-postratings/images/'.$ratings_image.'/rating_end.'.RATINGS_IMG_EXT).'" alt="" class="post-ratings-image" />';
}
return $ratings_images;
}

(In other words, I copied the get_ratings_images_vote function, renamed it to get_ratings_images_vote_thumbs and added
Code: [Select]
if ($i == 1) {
$ratings_images .= '%RATINGS_DOWN%';
} else {
$ratings_images .= '%RATINGS_UP%';
}
before the end of the first 'for' loop where $ratings_custom is true.)

4. Search for $value = str_replace("%RATINGS_ALT_TEXT%"
5. Insert the following code above that line:
Code: [Select]
if (strpos($template, '%RATINGS_IMAGES_VOTE_THUMBS%') !== false) {
$ratings_texts = get_option('postratings_ratingstext');
$post_ratings_images = get_ratings_images_vote_thumbs($post_id, $ratings_custom, $ratings_max, $post_ratings, $ratings_image, $post_ratings_alt_text, $insert_half, $ratings_texts);
$value = str_replace("%RATINGS_IMAGES_VOTE_THUMBS%", $post_ratings_images, $value);
}
6. Save your changes and upload the file.

Now you can use %RATINGS_IMAGES_VOTE_THUMBS% to display Vote down iconnumber of downsvote up iconnumber of ups. To display the number of ups first, search for if ($i == 1) { and replace %RATINGS_DOWN% with %RATINGS_UP% below and vice versa.

Note that you must have two choices (with values set for +1 and -1 (or vice versa)) for this to work, otherwise it might have funny outcomes.

Hope I could help, have a nice day!

Offline AdamCapriola

  • Newbie
  • *
  • Posts: 7
    • View Profile
  • WordPress Version: WordPress 3.0.x
  • Theme Name: Atahualpa
Re: Thumbs / Plus-minus / Nero rating
« Reply #1 on: 07 January 2011, 01:10 »
This looks pretty incredible, thanks for sharing!!

I wanted to show the number of ups and downs for a while then just went without it when I heard it wasn't possible.  I don't know if I have any real NEED to show them, but it's awesome that you've shared the code to git er done.  Thanks!

Offline AdamCapriola

  • Newbie
  • *
  • Posts: 7
    • View Profile
  • WordPress Version: WordPress 3.0.x
  • Theme Name: Atahualpa
Re: Thumbs / Plus-minus / Nero rating
« Reply #2 on: 07 January 2011, 07:05 »
Ok I looked at your code a little more and what you did with the first part if pretty simple yet ingenious... I just turned it into functions you could use anywhere:

// Show WP-PostRatings Likes For A Post
function post_rating_likes() {
   global $post;
   $post_ratings_data = get_post_custom(get_the_id());
    $post_ratings_users = intval($post_ratings_data['ratings_users'][0]);
    $post_ratings_score = intval($post_ratings_data['ratings_score'][0]);
   
    $post_likes = ($post_ratings_users + $post_ratings_score) / 2;
   
    echo $post_likes;
}

// Show WP-PostRatings Dislikes For A Post
function post_rating_dislikes() {
   global $post;
   $post_ratings_data = get_post_custom(get_the_id());
    $post_ratings_users = intval($post_ratings_data['ratings_users'][0]);
    $post_ratings_score = intval($post_ratings_data['ratings_score'][0]);
   
    $post_likes = ($post_ratings_users - $post_ratings_score) / 2;
   
    echo $post_dislikes;
}

I use Likes and Dislikes as the terminology on my site (seems be be pretty common with Facebook and YouTube using that too).

I'm not totally sure what you did for the second part (Number of ups and downs between the voting icons).  I'd have to see it on your site to tell if it's something I'd actually use.

Offline whaaa

  • Newbie
  • *
  • Posts: 3
    • View Profile
  • WordPress Version: WordPress 3.1.x
  • Theme Name: caw
Re: Thumbs / Plus-minus / Nero rating
« Reply #3 on: 07 February 2011, 01:27 »
This has helped me so much, thanks!

I'd love to see your website too

Offline c1nko

  • Newbie
  • *
  • Posts: 3
    • View Profile
  • WordPress Version: WordPress 3.0.x
  • Theme Name: Atahulapa
Re: Thumbs / Plus-minus / Nero rating
« Reply #4 on: 01 June 2011, 13:28 »
Great. Works perfect.

And if I want to change the icons with text. What should I do?
And to put the numbers in parentheses ()?

Thanks.