login
• July 27, 2017, 06:41:51 AM
• Welcome, Guest. Please login or register.
 
News: It's been a while since we started working on eFiction 5, there's been a lot of starting from scratch and half-scratch, but things are moving on.
Now we need you: please visit the eFicition 5 section of the forum and raise your voice, shape the new face of your favourite fanfiction management software.

Author Topic: [MOD] Likes Tally/Kudos Feature (work in progress)  (Read 71 times)

Ladama

  • Member
  • **
  • Posts: 38
  • Country: us
  • Thanked: 7 times
    • MoreThanThat
[MOD] Likes Tally/Kudos Feature (work in progress)
« on: June 22, 2017, 12:05:26 AM »
I'm not very satisfied with the Stars or the Like/Dislike ratings system on eFic (I detail a bit on why here) so I've been working on making it a little more like the Kudos system on Archive of our own (which... is basically a "Like" button :-D). I used this 2.0 mod as a jumping off point.

I'm still testing this out and hoping to get a some questions answered and figure out a couple more things before I actually add this mod to my live archive, so at this point I suggest to others interested in this mod to not put this in their live archives yet, but add it to your test site and report back with any problems or tweaks.

How Likes/Dislikes currently work: In the Like/Dislike system, when you "like" a story, you give it a rating of 1, if you dislike it you give a rating of 0. eFic averages this out and if the average is above half (0.5) it will display a thumbs up. If it's below 0.5, thumbs down. My issue with this: There's no displayed tally of how many "Likes" a story got, if it got 1 or 50 it will display the same thumbs up. Also, the thumbs down part of it I don't feel fosters the welcoming, encouraging environment I want our archive to have.

What this mod does: Rather than average the likes, it tallies up the number of "like" reviews a story has and displays them, like a social media "like" count. The "dislike" is taken out as an option, you either like the story or you select "None". If you are converting from the star ratings to "likes", this still works fine (provided your archive is like mine and very few people give low star reviews.). Warning: you will definitely not want to go back to the star rating system after initiating this mod, since giving a story a "like" = a value of 1, but in the star ratings that's a half star.

Before Modifying Any Code:
In your Efiction Admin Menu, select "Settings" then "Review Settings" then make sure it's set to "Rating System: Like/Dislike". (if you are converting from star ratings, it will basically convert every starred rating from 1-10 as a "like". If your users mostly give each other high ratings, then this shouldn't be a problem, Otherwise, you may want to do a few search/replaces" in the "Reviews" Table of your database.)

Up to you if you want to allow ratings only, that makes it a bit more like a "like" button system. If you don't, only when someone reviews can they leave a "like".

Next step, at least for me, it stops counting the number of "likes" at 127. There is probably a better, slicker way to do this but I just went into the phpadmin for my database and on the "stories", "chapters" and "series" tables, I select "Structure" and changed the Ratings settings from "tinyint(4)" to "int(11)"

So now that the rating system is set to "like/dislike" and the database has been modified to display larger numbers, here are the code modifications:

1. Change every instance of "SELECT AVG" to "SELECT COUNT"
You can find "SELECT AVG" in the following files:

admin/maintenance.php around lines 34 and 43
includes/corefunctions.php around line 173
includes/seriesreviews.php around lines 37 and 61
reviews.php around lines 74, 77, 145 and 149
update.php around 179 and 188
(also in install/upgrade11.php on lines 399 and 408 but you shouldn't have this folder unless you are upgrading)

Change them all to SELECT COUNT

2. In includes/corefunctions.php find (around line 467):
Code: [Select]
if($ratings == "2") {
if($rating >= 0.5)
$ratingpics = ($like ? $like : "<img src=\""._BASEDIR."images/like.gif\" alt=\""._LIKED."\">");
else if(($rating < 0.5) && ($rating > 0))
$ratingpics = ($dislike ? $dislike :"<img src=\""._BASEDIR."images/dislike.gif\" alt=\""._DISLIKED."\">");
else $ratingpics = "";
}

and replace with:
Code: [Select]
if($ratings == "2") {
if($rating >= 1)
$ratingpics = "<span title=\"number of likes\"><img src=\""._BASEDIR."images/like.gif\"><b>".$rating."</b></span>";
else $ratingpics = "";
}
Once the story gets some "likes", it will display the thumbs up and the number of "likes" next to it.

If you are adding this mod to an archive where people have left star ratings, you can go to the Admin menu in eFiction, select "Archive Maintenance" and then "Recalculate Reviews". Now it will convert any star ratings to a "like" and tally it up.

3. Remove the "dislike" option from the review form

in includes/reviewform.php find:
Code: [Select]
if($ratings == "2"){
$form .= "<div><label for=\"rating\">"._OPINION."</label> <select id=\"rating\" name=\"rating\" class=\"textbox\">
<option value=\"1\"".($review['rating'] == 1 ? " selected" : "").">"._LIKED."</option><option value=\"0\"".($review['reviewid'] && !$review['rating'] ? " selected" : "").">"._DISLIKED."</option><option value=\"-1\"".($review['rating'] == -1 || $action == "add" ? " selected" : "").">"._NONE."</option></select></div>";
}

replace with:
Code: [Select]
if($ratings == "2"){
$form .= "<div><label for=\"rating\">"._OPINION."</label> <select id=\"rating\" name=\"rating\" class=\"textbox\">
<option value=\"1\"".($review['rating'] == 1 ? " selected" : "").">"._LIKED."</option><option value=\"-1\"".($review['rating'] == -1 || $action == "add" ? " selected" : "").">"._NONE."</option></select></div>";
}
Now on the review form, it will only give the options of "Liked" and "None"

4. Modify the wording of the following lines in languages/en.php

Code: [Select]
define ("_REVIEWNOTE", "<span style=\"text-decoration: underline; font-weight: bold;\">Note:</span> You may submit either a rating or a review or both.");

define ("_LIKED", "Liked");

define ("_OPINION", "Opinion");

define ("_MISSINGINFO", "You must supply either a review or a rating.");

Here are some suggestions but change them to whatever fits your archive!

Code: [Select]
define ("_REVIEWNOTE", "<span style=\"text-decoration: underline; font-weight: bold;\">Note:</span> You may submit either a thumbs up or a review or both.");

define ("_LIKED", "Yes, add a thumbs up");

define ("_OPINION", "Add a thumbs up?");

define ("_MISSINGINFO", "You must supply either a thumbs up or a rating.");

Now you your have a "Like" system on your archive!

See next post for what I want to figure out, and maybe someone with some PHP knowledge can help me?
The following users thanked this post: SnoWhiteSally

Ladama

  • Member
  • **
  • Posts: 38
  • Country: us
  • Thanked: 7 times
    • MoreThanThat
Re: [MOD] Likes Tally/Kudos Feature (work in progress)
« Reply #1 on: June 22, 2017, 12:13:23 AM »
What I want to figure out:
As it is, there's nothing really stopping users from racking up the "like" count, especially if you allow ratings only, which I'm sure we all have members that would abuse that feature. I want to limit the "likes" somehow, either one per member per story, or one per member per chapter. I need to set up a query to check the database to see if the user has liked the story/chapter already, and either not record the "like" or throw them an error saying they already liked it.

Here's the code from the 2.0 mod I referenced earlier:

Code: [Select]
//prevents users from artificially inflating recommendations count
$count = mysql_query("SELECT count(rating) as ratingcount FROM ".$tableprefix."fanfiction_reviews WHERE rating = '1' AND psid = '$psid' and sid = '$sid' and member='$member'");
$ratingcheck = mysql_fetch_array($count);
if($ratingcheck[ratingcount] != 0){
$rating = "0";
}
//end prevention section

Of course this won't work in the current install. I tried in my limited knowledge to make it someone that I can paste into 3.5.5 code:
Code: [Select]
$count = dbquery("SELECT count(rating) as ratingcount FROM ".TABLEPREFIX."fanfiction_reviews WHERE rating = '1' AND chapid = '$chapid' and sid = '$item' and userid='$uid'");
$ratingcheck = fetch_array($count);
if($ratingcheck[ratingcount] != 0){
$rating = "-1";
}

I pasted this in reviews.php before this line, around ln 144
Code: [Select]
dbquery("INSERT INTO ".TABLEPREFIX."fanfiction_reviews (item, type, reviewer, review, rating, date, uid, chapid) VALUES ('$item', 'ST', '$reviewer', '$review', '$rating', now(), '".(USERUID && isNumber(USERUID) ? USERUID : 0)."', '$chapid')");

But I just get this error when trying to leave a rating or a review:
Quote
A fatal MySQL error was encountered.
Query: SELECT count(rating) as ratingcount FROM prefixfanfiction_reviews WHERE rating = '1' AND chapid = '14339' and sid = '5422' and userid='406'
Error: ()

ETA: I then tried this:
Code: [Select]
$ratecount = dbquery("select count(rating) as count FROM ".TABLEPREFIX."fanfiction_reviews WHERE item = '$item' AND chapid = '$chapid' AND uid = '$uid' AND rating != '-1'");
if($ratecount != 0) $output .= write_error(_MULTIPLERATINGS);

And the good news is it doesn't give me a MYSQL error but bad news is it logs the rating anyways.

Anyone have thoughts on preventing multiple ratings from one user?
« Last Edit: June 26, 2017, 09:05:07 AM by Ladama »

SnoWhiteSally

  • Member
  • **
  • Posts: 25
  • Country: gb
    • Kinnetik Dreams
Re: [MOD] Likes Tally/Kudos Feature (work in progress)
« Reply #2 on: July 25, 2017, 05:59:38 PM »
This is WAY above my skills, but I love the sound of this so much.

 

anything
anything