Quantcast

Jump to content

» «
Photo

Topic Rating Hack

14 replies to this topic
Azkoyen
  • Azkoyen

    Pixie Headed Freak

  • Members
  • Joined: 09 Nov 2001

#1

Posted 19 March 2005 - 11:43 PM Edited by Azkoyen, 20 March 2005 - 10:13 AM.

OMG! IT'S THE TOPIC RATING HACK!!!

What does it do?
It allows members to rate a topic.

Does it do anything else?
No.

Where can I see a working version
Right here, at the bottom of the page.

Does it have any 'uber-features'?
You can set it up so it allows a member to rate for the same topic more than once, depending on a preset timeout. Note: The GTAF installation does not allow members to rate twice. We're mean that way.

Is it wary of cheaters
Yes, it won't let you cheat, and it'll laugh at you if you try.[/b]

How do I install it?
[i]Like this...


Database Modifications:
Open the Admin console, go to 'SQL Toolbox' and paste each of these code blocks in there. And press the button of course.
CODE
CREATE TABLE `ibf_topic_ratings` (
 `uid` mediumint(8) NOT NULL default '0',
 `tid` int(10) NOT NULL default '0',
 `rtime` int(10) NOT NULL default '0',
 KEY `uid` (`uid`,`tid`)
) TYPE=MyISAM;

CODE
ALTER TABLE `ibf_topics` ADD `topic_rating` INT( 10 ) DEFAULT '500' NOT NULL;

CODE
ALTER TABLE `ibf_topics` ADD `total_raters` INT( 10 ) DEFAULT '10' NOT NULL;


Source File Modifications:
/conf_global.php

At the end of the file, before the line with '?>' on it, insert this:
CODE
$INFO['rating_timeout']   = '86400'; // timeout (in seconds) for topic ratings.  -1 means voting only ever allowed once.


86400 is the amount of seconds in 24 hrs.

/sources/Topics.php

Before the block that starts 'If this forum is a link, then...', insert this code:
CODE
//--------------------------------------------------------------------
// Are we rating a topic?
//--------------------------------------------------------------------

if(isset($ibforums->input['rating']))
{
if (! $ibforums->member['id'] )
 $print->redirect_screen( "but Guests can't rate topics!", "showtopic={$this->topic['tid']}&view=getnewpost" ); // if a guest tries to vote, set the straight.
if(preg_match("|[\D]|", $ibforums->input['rating']) || $ibforums->input['rating'] < 0 || $ibforums->input['rating'] > 100)
 $print->redirect_screen( "but the joke's on you!", "act=Login&CODE=03" ); // if they try to cheat, send them to the logout page, haha.
$result = $DB->query("select * from ibf_topic_ratings where uid = '{$ibforums->member['id']}' and tid = {$this->topic['tid']} order by rtime desc limit 1");
if($DB->get_num_rows($result))
{
 $record = mysql_fetch_assoc($result);
 if($ibforums->vars['rating_timeout'] != -1 && (time() > ($record['rtime'] + $ibforums->vars['rating_timeout'])))
 {
  $DB->query("update ibf_topics set topic_rating = topic_rating + {$ibforums->input['rating']}, total_raters = total_raters + 1 where tid = {$this->topic['tid']}");
  $DB->query("update ibf_topic_ratings set rtime = '".time()."' where uid = '{$ibforums->member['id']}' and tid = '{$this->topic['tid']}'");
  $print->redirect_screen( "your rating for this topic has been logged.", "showtopic={$this->topic['tid']}&view=getnewpost" );
 }
 else
 {
  $print->redirect_screen( "You have already rated this topic.", "showtopic={$this->topic['tid']}&view=getnewpost" ); // not cheating, maybe they pressed 'back'
 }
}
else
{ // log the rating
 $DB->query("update ibf_topics set topic_rating = topic_rating + {$ibforums->input['rating']}, total_raters = total_raters + 1 where tid = {$this->topic['tid']}");
 $DB->query("insert into ibf_topic_ratings (uid, tid, rtime) values('{$ibforums->member['id']}', '{$this->topic['tid']}', '".time()."')");
 $print->redirect_screen( "your rating for this topic has been logged.", "showtopic={$this->topic['tid']}&view=getnewpost" );
}
}


After this code:
CODE
$this->topic['REPLY_BUTTON']  = $this->reply_button();


Insert this code:
CODE
$this->topic['RATE_TOPIC']  = $this->rate_topic();


After the reply_button() function, insert this function:

CODE
//--------------------------------------------------------------
// Render the rate topic control
//--------------------------------------------------------------

function rate_topic()
{
global $ibforums, $DB;

$rating = "Topic Rating: ".round($this->topic['topic_rating'] / $this->topic['total_raters'])."%&nbsp;";

if (! $ibforums->member['id'] )
 return $rating;

$control = "<br/>Rate this topic as <a href=\"?act=ST&t={$this->topic['tid']}&rating=100\"><u>Good</u></a> or <a href=\"?act=ST&t={$this->topic['tid']}&rating=0\"><u>Bad</u></a>.&nbsp;";

$result = $DB->query("select * from ibf_topic_ratings where uid = '{$ibforums->member['id']}' and tid = {$this->topic['tid']} order by rtime desc limit 1");
if($DB->get_num_rows($result))
{
 $record = mysql_fetch_assoc($result);
 if($ibforums->vars['rating_timeout'] != -1 && (time() > ($record['rtime'] + $ibforums->vars['rating_timeout'])))
 {
  // display rating + control
  return $rating.$control;
 }
 return $rating;
}
else
{
 // display rating + control
 return $rating.$control;
}
}


/sources/Forums.php

Just before this code:
CODE
$topic['start_date'] = $std->get_date( $topic['start_date'], 'LONG' );


Insert this code:
CODE
$percentage = round($topic['topic_rating']/$topic['total_raters']);
if($percentage >= 70){
$topic['rating_icon'] = '<img src="layout/goodrating.gif">';
if($percentage >= 80){
 $topic['rating_icon'] .= '<img src="layout/goodrating.gif">';
 if($percentage >= 90){
  $topic['rating_icon'] .= '<img src="layout/goodrating.gif">';
 }
}
}
else if($percentage <= 30)
{
$topic['rating_icon'] = '<img src="layout/badrating.gif">';
if($percentage <= 20){
 $topic['rating_icon'] .= '<img src="layout/badrating.gif">';
 if($percentage <= 10){
  $topic['rating_icon'] .= '<img src="layout/badrating.gif">';
 }
}
}


/sources/lib/post_new_post.php

After the 'If we are still here, lets update the' comment, insert this code:

CODE
// Update the topic ratings table so the topic creator can't rate his own topic.
$DB->query("insert into ibf_topic_ratings (uid, tid) values('{$ibforums->member['id']}', '{$this->topic['tid']}')");



sources/lib/post_poll.php

After the 'If we are still here, lets update the' comment, insert this code:

CODE
// Update the topic ratings table so the topic creator can't rate his own topic.
$DB->query("insert into ibf_topic_ratings (uid, tid) values('{$ibforums->member['id']}', '{$this->topic['tid']}')");


Skin Edits:
In Forum Index Sections 'Normal Topic Entry' and 'Pinned Topic Entry'

Find '{$data[PAGES]}' and paste this code in just after it (put a space between them if you want)
CODE
{$data['rating_icon']}



In the Topic View Section 'Footer'
Add the tag below to the footer html somewhere.
CODE
{$data[TOPIC][RATE_TOPIC]}


Here's an example using GTAF's version of 'Invision Power Board Template Set':

CODE
     <!--IBF.TOPIC_ACTIVE-->
     <div class="activeuserstrip" align="center">&laquo; <a href='{ibf.script_url}showtopic={$data[TOPIC]['tid']}&amp;view=old'>{ibf.lang.t_old}</a> | <strong><a href='{ibf.script_url}showforum={$data['FORUM']['id']}'>{$data['FORUM']['name']}</a></strong> | <a href='{ibf.script_url}showtopic={$data[TOPIC]['tid']}&amp;view=new'>{ibf.lang.t_new}</a> &raquo;</div>
</div>

<br />
<table width="100%" cellpadding="0" cellspacing="0" border="0">
<tr>
<td align='left' width="20%" nowrap="nowrap"><!--IBF.TOPIC_OPTIONS_CLOSED-->{$data[TOPIC][SHOW_PAGES]}</td>
<td align='right' width="70%" nowrap="nowrap">{$data[TOPIC][RATE_TOPIC]}</td>
<td align='right' width="10%" nowrap="nowrap">{$data[TOPIC][REPLY_BUTTON]}<!--IBF.QUICK_REPLY_CLOSED--><a href='{ibf.script_url}act=Post&amp;CODE=00&amp;f={$data[FORUM]['id']}' title='{ibf.lang.start_new_topic}'><{A_POST}></a>{$data[TOPIC][POLL_BUTTON]}</td>
</tr>
</table>
<!--IBF.QUICK_REPLY_OPEN-->
<!--IBF.TOPIC_OPTIONS_OPEN-->
<br />
<!--IBF.MOD_PANEL-->
<div align='right'>{$data[FORUM]['JUMP']}</div>
<!--IBF.MULTIMOD-->
<br />


As you can see, the RATE_TOPIC section is squeezed in between the Options TD and the Topic Buttons TD.

Comments, criticisms, problems, bug reports and eLove welcome, as always...

edits:
1. Fixed bug where guests could rate topics.
2. Fixed bug where Bad votes were being ignored.
3. Fixed bug where you were being brought back to the first page of the topic you'd voted for. It now sends you to the last.
4. Modified the Database Table Defaults.

NOTE: If you installed this hack before 20 March 2005, you'll need to drop the database edits and re-create them. Just execute these commands, everything will be hunky dorey. I'd advise you to shut down the forums before you do it, so as people don't go ballistic when they can't post.
CODE
ALTER TABLE `ibf_topics` DROP `topic_rating`, DROP `total_raters`;

CODE
DROP TABLE `ibf_topic_ratings`

CODE
CREATE TABLE `ibf_topic_ratings` (
 `uid` mediumint(8) NOT NULL default '0',
 `tid` int(10) NOT NULL default '0',
 `rtime` int(10) NOT NULL default '0',
 KEY `uid` (`uid`,`tid`)
) TYPE=MyISAM;

CODE
ALTER TABLE `ibf_topics` ADD `topic_rating` INT( 10 ) DEFAULT '500' NOT NULL;

CODE
ALTER TABLE `ibf_topics` ADD `total_raters` INT( 10 ) DEFAULT '10' NOT NULL;

JSAN ANDREAS
  • JSAN ANDREAS

    Gangsta

  • Members
  • Joined: 04 Nov 2004

#2

Posted 19 March 2005 - 11:52 PM

Damn! I love these new features GTAF has! cookie.gif 's for them! Is it in all topics now? EDIT: Yes they are.

Chalkstar
  • Chalkstar

    QvsQ lab monkey

  • BUSTED!
  • Joined: 08 Nov 2004

#3

Posted 19 March 2005 - 11:53 PM

Good stuff. I like it. I also like that little searching thread feature part.

EDIT: It also is making those karma stars near threads with good ratings, no?

JSAN ANDREAS
  • JSAN ANDREAS

    Gangsta

  • Members
  • Joined: 04 Nov 2004

#4

Posted 19 March 2005 - 11:55 PM

QUOTE (Chalkstar2188 @ Mar 19 2005, 18:53)
Good stuff. I like it. I also like that little searching thread feature part.

Yup, that's another topic in this forum. Good job GTAF! Liking the new features! rah.gif

Chalkstar
  • Chalkstar

    QvsQ lab monkey

  • BUSTED!
  • Joined: 08 Nov 2004

#5

Posted 20 March 2005 - 12:29 AM

QUOTE (JSAN ANDREAS @ Mar 20 2005, 10:55)
QUOTE (Chalkstar2188 @ Mar 19 2005, 18:53)
Good stuff. I like it. I also like that little searching thread feature part.

Yup, that's another topic in this forum. Good job GTAF! Liking the new features! rah.gif

It works good except in the PGC people are overusing them too much.

JSAN ANDREAS
  • JSAN ANDREAS

    Gangsta

  • Members
  • Joined: 04 Nov 2004

#6

Posted 20 March 2005 - 12:31 AM

Yeah, biggrin.gif In the gang chat, I see a lot of red and yellow stars in the gang topics. Prolly ppl from other gangs are rating rival gang topics bad? I hope they don't do it to my gang. confused.gif

Azkoyen
  • Azkoyen

    Pixie Headed Freak

  • Members
  • Joined: 09 Nov 2001

#7

Posted 20 March 2005 - 12:48 AM

Enough discussion, this is a Web Development and Programming forum, not a 'I hope people are nice to me' forum.

And don't post to say sorry! Just, stop posting altogether, please.

PatrickW
  • PatrickW

    GTA Juggernaut

  • The Connection
  • Joined: 07 Jan 2004
  • Netherlands
  • Best Script 2013 [DYOM]
    Best Script 2012 [DYOM]

#8

Posted 20 March 2005 - 01:25 AM

Cool hack Az... cookie.gif cookie.gif

Some constructive comments:

* I was as a topic starter able to rate my own topic. This might be because it was already an old topic...

* Shouldn't the "rating stars" be displayed behind the topic-title on the topic-window. Now it's only displayed in the forum window.

* I think this thing will get overused very soon. Maybe there should be some more limitation on it, like every member can only hand out 1 "good" and 1 "bad" verdict per day. This should make people think at least a bit before handing them out.


And sorry, that I didn't stop posting altogether tounge.gif

Roald
  • Roald

    Hustler

  • Members
  • Joined: 30 Nov 2004

#9

Posted 20 March 2005 - 08:45 AM

QUOTE
Skin Edits:
In Forum Index Sections 'Normal Topic Entry' and 'Pinned Topic Entry'

Find '{$data[PAGES]}' and paste this code in just after it (put a space between them if you want)


What is the Forum Index Section?

Need some help finding this one as well:

QUOTE
In the Topic View Section 'Footer'
Add the tag below to the footer html somewhere.



Barbaneez
  • Barbaneez

    Boss

  • Members
  • Joined: 01 Jun 2003

#10

Posted 20 March 2005 - 08:54 AM

QUOTE (Roald @ Mar 20 2005, 03:45)
QUOTE
Skin Edits:
In Forum Index Sections 'Normal Topic Entry' and 'Pinned Topic Entry'

Find '{$data[PAGES]}' and paste this code in just after it (put a space between them if you want)


What is the Forum Index Section?

Need some help finding this one as well:

QUOTE
In the Topic View Section 'Footer'
Add the tag below to the footer html somewhere.



Admin CP > Skins & Templates > HTML Templates > (find the skin you want to edit this to and click on "Manage HTML") > Forum Index Sections (should be 6 table rows down) > then that will expand down and find "+-- Pinned Topic Entry" and click 'Edit Single' to the right of that and then find: {$data[PAGES]}' and after that add a space to that and insert: {$data['rating_icon']}
Now do the same what you did to "+-- Pinned Topic Entry" except do it to "+-- Normal Topic Entry"

and voila you're done with that part. smile.gif
Don't worry, it gets simple after a while.

Azkoyen
  • Azkoyen

    Pixie Headed Freak

  • Members
  • Joined: 09 Nov 2001

#11

Posted 20 March 2005 - 10:14 AM

I've made some pretty serious edits guys, please reapply the hack to your forums. Sorry about this sad.gif

YoYo-Pete
  • YoYo-Pete

    Stand Strong!

  • Members
  • Joined: 03 Nov 2004

#12

Posted 01 April 2005 - 07:48 PM

Is there anywhere to see the highest rated posts?

cmc_jacob
  • cmc_jacob

    qwerty

  • BUSTED!
  • Joined: 21 Oct 2004

#13

Posted 03 April 2005 - 07:09 PM

QUOTE (YoYo-Pete @ Apr 1 2005, 13:48)
Is there anywhere to see the highest rated posts?

This is a topic rater, not a post rater, in case you were confused.

Is there a way to increase how much the percent changes upon a rating? I don't like how small it increases/decreases the ratings.. smaller forums should have larger changes.

Roald
  • Roald

    Hustler

  • Members
  • Joined: 30 Nov 2004

#14

Posted 04 May 2005 - 06:42 PM

Pretty big bump, but I need help...where do you change the images that appear next to the topic?

PatrickW
  • PatrickW

    GTA Juggernaut

  • The Connection
  • Joined: 07 Jan 2004
  • Netherlands
  • Best Script 2013 [DYOM]
    Best Script 2012 [DYOM]

#15

Posted 04 May 2005 - 07:07 PM

In the code you added to:
/sources/Forums.php

Change the all the goodratings.gif and badrating.gif to the images you want there instead.




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users