Phantom Designs Banner

By donating you support Phantom Designs. Cash for ads are also a form of donation.

  Add ReplyNew TopicNew Poll

 Reputation Modification
slayer766
Posted: Jul 1 2009, 05:48 PM
Quote Post


PD-Rising Member
*

Group: Member
Posts: 964
Member No.: 331
Joined: 18-December 05



Hello everyone, recently I've been checking the IF Support boards and I noticed that a handful of people request for a Rep mod of some sort. So I got to thinking and then starting writing this for ZetaBoards. This is something basic, and will not eat ANY of your ad credits(If you have any), the loading speeds are fast(Determined by your hosts server mainly). The only downside to this is that it only works 100% in FireFox. Google Chrome doesn't show the Rep but the Plus/Subtract functions work.


PREVIEW: http://s1.zetaboards.com/ZBReputation/index/


So here is the info on what needs to be done:


First you will need to get yourself a host! I use, for a free host, http://ulmb.com Seems to work fine.
Your host will need to PHP & MySQL. You will need at least 1 MySQL database.

Setting up your MySQL database & table
First you will need to create your database. After you have created that, you will need to set up your mysql table.

Open up your phpMyAdmin for your database you have created. Click on the "SQL" tab and run this query:
CODE
CREATE TABLE IF NOT EXISTS `ZBRepTable` (
 `username` varchar(100) NOT NULL,
 `user_id` int(8) NOT NULL,
 `date_reg` varchar(125) NOT NULL,
 `reputation` int(4) NOT NULL,
 `last_rep` varchar(125) NOT NULL,
 PRIMARY KEY  (`user_id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1;


After that has been run, you will see your table on the left hand side. This is to store info for your Rep Mod. smile.png

Ok, create a new directory on your hosts file manager, name it "ZBRep", save and upload the following files:

Save this file as database.php
CODE
<?php
$db_user = ""; //The username
$db_pass = ""; //Database password
$db_database = ""; //The database name
$db_host = "mysql"; //Database server name
$db_connect = mysql_connect($db_host, $db_user, $db_pass) or trigger_error ("There has been an error querying the database. Please contact the administrator.");
$db_select = mysql_select_db($db_database) or trigger_error ("There has been an error querying the database. Please contact the administrator.");
?>


Save this file as REPUserReg.php
CODE
<?php
require("database.php");

//User Register
$username = mysql_real_escape_string($_GET['u']);
$idz = mysql_real_escape_string($_GET['id']);
$date = date("F j, Y, g:i a",time());
$yesterday = mktime(0,0,0,date("m"),date("d")-1,date("Y"));
$_date = date("F j, Y, g:i a",$yesterday);
$r = mysql_query("SELECT * FROM `ZBRepTable` WHERE username = '$username' AND user_id = '$idz'") or trigger_error("There has been an error querying the database. Please contact the administrator.");

if(mysql_num_rows($r) == 0){
mysql_query("INSERT INTO ZBRepTable(username,user_id,date_reg,last_rep) VALUES('$username','$idz','$date','$_date')") or trigger_error("There has been an error querying the database. Please contact the administrator.");
}
else{
exit;
}
?>


Save this file as REPTopicRes.php
CODE
<?php
require("database.php");

//ZB Topic Result
$id = mysql_real_escape_string($_GET['getid']);
$num = mysql_real_escape_string($_GET['num']);

$query = mysql_query("SELECT * FROM `ZBRepTable` WHERE user_id = '$id'") or trigger_error("There has been an error querying the database. Please contact the administrator.");
if(mysql_num_rows($query) == 0){
?>
$("#ZBreputation<?php echo $num; ?>").text("0");
<?php
exit;
}
$query2 = mysql_query("SELECT reputation FROM `ZBRepTable` WHERE user_id = '$id'") or trigger_error("There has been an error querying the database. Please contact the administrator.");
$result = mysql_fetch_array($query2);
?>
$("#ZBreputation<?php echo $num; ?>").text("<?php echo number_format($result['reputation']); ?>");


Save this file as ZBUpdateRep.php
Change http://slayer766.ulmb.com near the end of the file to your host name.
CODE
<?php
require("database.php");

//ZB Reputation Add/Sub
$to_user = mysql_real_escape_string($_GET['toid']);
$from_user = mysql_real_escape_string($_GET['fromid']);
$type = mysql_real_escape_string($_GET['type']);
$num = mysql_real_escape_string($_GET['num']);
$date = date("F j, Y, g:i a",time());
$tomorrow = mktime(0,0,0,date("m"),date("d")+1,date("Y"));
$_date = date("F j, Y, g:i a",$tomorrow);

$query = mysql_query("SELECT * FROM `ZBRepTable` WHERE user_id = '$from_user' AND last_rep = '$_date'") or trigger_error("There has been an error querying the database. Please contact the administrator.");
$check = mysql_num_rows($query);
if($check == 1){
?>
alert("You have already repped today!\nYou must wait 24 hours.");
<?php
exit;
}
if($type == 0){
mysql_query("UPDATE `ZBRepTable` SET reputation = reputation - 1 WHERE user_id = '$to_user'") or trigger_error("There has been an error querying the database. Please contact the administrator.");
}
if($type == 1){
mysql_query("UPDATE `ZBRepTable` SET reputation = reputation + 1 WHERE user_id = '$to_user'") or trigger_error("There has been an error querying the database. Please contact the administrator.");
}
mysql_query("UPDATE `ZBRepTable` SET last_rep = '$_date' WHERE user_id = '$from_user'") or trigger_error("There has been an error querying the database. Please contact the administrator.");
?>
if(location.href.match(/profile/i)){
query("http://slayer766.ulmb.com/ZBRep/REPTopicRes.php?getid=<?php echo $to_user; ?>&id=<?php echo $from_user; ?>");
}
if(location.href.match(/topic/i)){
query("http://slayer766.ulmb.com/ZBRep/REPTopicRes.php?getid=<?php echo $to_user; ?>&num=<?php echo $num; ?>");
}


Save this file as REPTopicView.js
(Change any occurrence of http://slayer766.ulmb.com to your host name.)
CODE
var num = 0;
var the_id = "";
var id = $("#top_info strong a").attr("href").split("profile/")[1].split("/")[0];
$("dl.user_info").each(function(){
num++;
the_id = $(this).parent().parent().prev().html().split('profile/')[1].split('/')[0];
query("http://slayer766.ulmb.com/ZBRep/REPTopicRes.php?getid="+the_id+"&num="+num);
$(this).find("dd:eq(0)").after("<dt>Rep:</dt><dd><a href='javascript:void(0);' onclick='Reputation("+the_id+","+num+",0)'><img src='http://209.85.62.26/12704/23/upload/p1496490.gif'></a> <span id='ZBreputation"+num+"'><img src='http://209.85.62.24/365/0/0/p177230/ajax_loader.gif' alt='Loading'></span> <a href='javascript:void(0);' onclick='Reputation("+the_id+","+num+",1)'><img src='http://209.85.62.26/12704/23/upload/p1496493.gif'></a></dd>");
});

function Reputation(to,num,type){
if(to == id){
alert("You cannot rep yourself!");
return;
}
query("http://slayer766.ulmb.com/ZBRep/ZBUpdateRep.php?toid="+to+"&fromid="+id+"&type="+type+"&num="+num);
}


Save this file as REPProfileView.js
(Change any occurrence of http://slayer766.ulmb.com to your host name.)
CODE
var the_id = location.href.split('profile/')[1].split('/')[0];
var id_from = $("#top_info strong a").attr("href").split("profile/")[1].split("/")[0];
query("http://slayer766.ulmb.com/ZBRep/ZBProfileRes.php?getid="+the_id+"&id="+id_from);
$("dl.user_info").find("dd:eq(0)").after("<dt>Rep:</dt><dd><a href='javascript:void(0);' onclick='Reputation(0)'><img src='http://209.85.62.26/12704/23/upload/p1496490.gif'></a> <span id='ZBreputation'><img src='http://209.85.62.24/365/0/0/p177230/ajax_loader.gif' alt='Loading'></span> <a href='javascript:void(0);' onclick='Reputation(1)'><img src='http://209.85.62.26/12704/23/upload/p1496493.gif'></a></dd>");

function Reputation(type){
if(the_id == id_from){
alert("You cannot rep yourself!");
return false;
}
query("http://slayer766.ulmb.com/ZBRep/ZBUpdateRep.php?toid="+the_id+"&fromid="+id_from+"&type="+type);
}


Save this file as ZBProfileRes.php
CODE
<?php
require("database.php");

//ZB Reputation Profile
$id = mysql_real_escape_string($_GET['getid']);
$id_2 = mysql_real_escape_string($_GET['id']);
$query = mysql_query("SELECT * FROM `ZBRepTable` WHERE user_id = '$id'") or trigger_error("There has been an error querying the database. Please contact the administrator.");
$check = mysql_num_rows($query);
if($check == 0){
?>
$("#ZBreputation").text("0");
<?php
exit;
}
$query2 = mysql_query("SELECT * FROM `ZBRepTable` WHERE user_id = '$id'") or trigger_error("There has been an error querying the database. Please contact the administrator.");
$result = mysql_fetch_array($query2);
?>
$("#ZBreputation").text("<?php echo number_format($result['reputation']); ?>");



Finally, add this code to your Board Template > Below the board:
(Change any occurrence of http://slayer766.ulmb.com to your host name.)
CODE
<script type='text/javascript'>
/******************************************
* ZetaBoards Reputation Modification      *
* Written By slayer766                    *
* ======================================= *
* Version:  1.0                           *
* Exclusivity:  http://zbcode.com         *
******************************************/

if(!$("div#top_info:contains('Guest')").html()){
document.write("<div id='loader'></div>");
var user = $("#top_info strong").text();
var id = $("#top_info strong a").attr("href").split("profile/")[1].split("/")[0];
query("http://slayer766.ulmb.com/ZBRep/REPUserReg.php?u="+user+"&id="+id);
if(location.href.match(/topic/i)){
query("http://slayer766.ulmb.com/ZBRep/REPTopicView.js");
}
if(location.href.match(/profile/i)){
query("http://slayer766.ulmb.com/ZBRep/REPProfileView.js");
}
}

function query(url){
var l=document.getElementById('loader');
var s=document.createElement('script');
s.src=url;
s.type='text/javascript';
l.appendChild(s);
}
</script>


Everything should be set! If you have any problems just let me know. Feedback and suggestions are most welcome.

This post has been edited by slayer766 on Jul 2 2009, 01:27 AM
Top
Michael
Posted: Jul 1 2009, 05:57 PM
Quote Post


www.imged.net
Group Icon

Group: Community Manager
Posts: 7.723
Member No.: 47
Joined: 11-October 05



Looking good slayer, I had already tested it on the other board.

But I do suggest you putting these file in a rar, it's easier to upload then rather create all files.

EDIT: I'm not sure if this is the right way to use trigger_error, I believe it has something to do with E_ERROR? I would rather use die and dispaly the mysql_error.

This post has been edited by Michael on Jul 1 2009, 06:00 PM


--------------------
user posted image
user posted image
Windows 7 Ultimate RC - AMD Athlon 64 X2 6000+ 3.22Ghz(overclocked) - ATI Radeon HD4850 512MB
[x] - [x] - [x] - [x] - [x] - [x] - [x] - [x] - [x] - [x] - [x] - [x] - [x] - [x]
Fast Image Hosting - Need proxy?
Top
Eureka
Posted: Jul 1 2009, 09:17 PM
Quote Post


Error: Invalid Characters
Group Icon

Group: Eureka
Posts: 1.309
Member No.: 8.197
Joined: 18-December 07



The error type in trigger_error function is optional. It defaults to E_USER_WARNING or 512 IIRC.

Michael, die is horrible. It should never be used for any debugging purposes. trigger_error() is much better. It gives you better control on the error type. Ever had die just print out your connection information? Would you really want people seeing that?

slayer: awesome job with the script man. The only suggestions I'll be making are of coding specs. $idz or any numeric number for that matter should be secured via casting or using the intval() function to make it an int. mysql_real_escape_string() function should not be used on strings. As the function name says, it escape strings. So instead of mysql_real_escape_string($_GET['id']), I would suggest one of the following -
CODE
$id = (int) $_GET['id'];

CODE
$id = intval($_GET['id']);


Or if you want to be more sophisticated -
CODE

$id = $_GET['id'];
if (!preg_match('#^\d+$#', $id)) exit;


Also, integer values don't need quotes around them when you INSERT them or UPDATE using them.
CODE
INSERT INTO table (num) VALUES (4);

That works just fine. You don't need to do -
CODE
INSERT INTO table (num) VALUES ('4');
As long as the data type for that field is int, MySQL will do the right thing. smile.png Same case for SELECT, UPDATE, DELETE, etc SQLs that uses numbers.

A MySQL date field should not be varchar. I would advice either TIMESTAMP, DATE, or DATETIME. You can also have MySQL set the date_reg field to have a default value so you don't have to populate it. That's provided you have it in date format and not varchar. Like such -
CODE
`date_reg` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP


For yesterday's date, you can use MySQL to do date math, and IMO, it's very efficient at doing it. Like such -
CODE
INSERT INTO table (yesterday_date) VALUES (DATE_SUB(NOW(), INTERVAL 1 DAY));


Lastly, I don't find myself using mysql_num_rows() all that often. It's much more efficient to use MySQL COUNT() aggregate function instead. Like such -
CODE

$sql = "SELECT COUNT(*) cnt FROM `ZBRepTable` WHERE username = '$username' AND user_id = $idz";
$result = mysql_query($sql) or trigger_error('SQL failed', E_USER_ERROR);
if ($result['cnt'] == 0) { /* do something */ }


That's about it. Great job on it though.


--------------------
DO NOT PM ME FOR HELP, SUPPORT OR REQUESTS!
CLICK HERE FOR THE RECOMMENDED ENTERTAINMENT TOPIC!

user posted image
^ Thanks to Slasher for the sig. ^

QUOTE (First Bad Habit)
I'm a part of you, you're a part of me
And I know it's wrong but I can't get free
You're like my first bad habit
How am I gonna give you up?
~ Vanessa Hudgens
Top
slayer766
Posted: Jul 2 2009, 01:25 AM
Quote Post


PD-Rising Member
*

Group: Member
Posts: 964
Member No.: 331
Joined: 18-December 05



Thanks a bunch for the feedback you guys, and yeah Michael - Eureka said exactly what I would for the use of trigger_error instead of die. wink.png I could have put all the files into a .rar but I never even thought about that, I'll do that sometime. xD.png


Ken, thanks for the tips man, appreciate that. smile.png
Top
Eureka
Posted: Jul 2 2009, 05:41 AM
Quote Post


Error: Invalid Characters
Group Icon

Group: Eureka
Posts: 1.309
Member No.: 8.197
Joined: 18-December 07



One more thing I should have said but didn't. Most of the time, when your site is up and running with many people viewing it, you don't actually want errors displayed. That's just bad. Members do not want to see this. It scares them to think the site is going down. With trigger_error(), you can create your own function that writes error messages to some log file. die() simply can't do that. It can't do anything but die so I wish die to die already! Does everyone understand my last 2 sentences?


--------------------
DO NOT PM ME FOR HELP, SUPPORT OR REQUESTS!
CLICK HERE FOR THE RECOMMENDED ENTERTAINMENT TOPIC!

user posted image
^ Thanks to Slasher for the sig. ^

QUOTE (First Bad Habit)
I'm a part of you, you're a part of me
And I know it's wrong but I can't get free
You're like my first bad habit
How am I gonna give you up?
~ Vanessa Hudgens
Top
Michael
Posted: Jul 2 2009, 09:00 AM
Quote Post


www.imged.net
Group Icon

Group: Community Manager
Posts: 7.723
Member No.: 47
Joined: 11-October 05



Oh wait, trigger_error writes to the error_log? If so, it rocks tounge.png


--------------------
user posted image
user posted image
Windows 7 Ultimate RC - AMD Athlon 64 X2 6000+ 3.22Ghz(overclocked) - ATI Radeon HD4850 512MB
[x] - [x] - [x] - [x] - [x] - [x] - [x] - [x] - [x] - [x] - [x] - [x] - [x] - [x]
Fast Image Hosting - Need proxy?
Top
Eureka
Posted: Jul 2 2009, 09:39 AM
Quote Post


Error: Invalid Characters
Group Icon

Group: Eureka
Posts: 1.309
Member No.: 8.197
Joined: 18-December 07



By default, no. You can use set_error_handler function to define your own PHP function that writes it to a log. smile.png


--------------------
DO NOT PM ME FOR HELP, SUPPORT OR REQUESTS!
CLICK HERE FOR THE RECOMMENDED ENTERTAINMENT TOPIC!

user posted image
^ Thanks to Slasher for the sig. ^

QUOTE (First Bad Habit)
I'm a part of you, you're a part of me
And I know it's wrong but I can't get free
You're like my first bad habit
How am I gonna give you up?
~ Vanessa Hudgens
Top
justin186
Posted: Jul 5 2009, 06:20 AM
Quote Post


Interested Member
*

Group: Member
Posts: 85
Member No.: 15.128
Joined: 18-May 08



looking good man smile.png didnt realise that people were still making codes.. i havnt made one in ages...... im like dead out of ideas tounge.png


--------------------
user posted image
Top
0 User(s) are reading this topic (0 Guests and 0 Anonymous Users)
0 Members:


Topic Options Add ReplyNew TopicNew Poll



Hosted for free by InvisionFree (Terms of Use: Updated 7/7/05) | Powered by Invision Power Board v1.3 Final © 2003 IPS, Inc.
Archive