1
daviddu54
Adding users vote + user visit counter in your member's profils
  • 2006/8/10 11:25

  • daviddu54

  • Just popping in

  • Posts: 22

  • Since: 2006/8/1 2


Hello every body

Today i will explain how to hack your members profil for add user vote and user hits (visit counter)

Ok c'est partie !!!

1 - Copy all windows code contents

<?php
//-------------------------------------------------------------------------- //
//  Users vrate Version 1.0 user_rate.php                                           //
//                                                                             //
//    Author: David Auguste DeMâcon                                                 //
//    Mail:    daviddu54@allsecrets.net                                                 //
//    Homepage: http://www.rencontre.allsecrets.net&n ... nbsp;   //
//                                                                             //
//    for XOOPS                                                                //
// ------------------------------------------------------------------------- //
//  This program is free software; you can redistribute it and/or modify     //
//  it under the terms of the GNU General Public License as published by     //
//  the Free Software Foundation; either version 2 of the License, or        //
//  (at your option) any later version.                                      //
//                                                                           //
//  This program is distributed in the hope that it will be useful,          //
//  but WITHOUT ANY WARRANTY; without even the implied warranty of           //
//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the            //
//  GNU General Public License for more details.                             //
//                                                                           //
//  You should have received a copy of the GNU General Public License        //
//  along with this program; if not, write to the Free Software              //
//  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA //
// ------------------------------------------------------------------------- //

include("mainfile.php");
include_once 
XOOPS_ROOT_PATH."/class/module.textsanitizer.php";
include_once 
XOOPS_ROOT_PATH."/class/module.errorhandler.php";
include(
XOOPS_ROOT_PATH."/language/".$xoopsConfig['language']."/user.php");

$myts =& MyTextSanitizer::getInstance(); // MyTextSanitizer object
if($HTTP_POST_VARS['submit']) {
    
$eh = new ErrorHandler//ErrorHandler object
    
if(!$xoopsUser){
        
$ratinguser 0;
    }else{
        
$ratinguser $xoopsUser->uid();
    }
    
//Make sure only 1 anonymous from an IP in a single day.
    
$anonwaitdays 1;
    
$ip getenv("REMOTE_ADDR");
    
$uid $HTTP_POST_VARS['uid'];
    
$rating $HTTP_POST_VARS['rating'];
       
// Check if Rating is Null
       
if ($rating=="--") {
           
redirect_header("user_rate.php?uid=".$uid."",4,_US_NORATING);
    exit();
       }

    
// Check if REG user is trying to vote twice.
    
$result=$xoopsDB->query("SELECT ratinguser FROM ".$xoopsDB->prefix("users_votedata")." WHERE uid=$uid");
    while(list(
$ratinguserDB)=$xoopsDB->fetchRow($result)) {
        if (
$ratinguserDB==$ratinguser) {
            
redirect_header("userinfo.php?uid=$uid",4,_US_VOTEONCE);
            exit();
        }
    }

    
// Check if ANONYMOUS user is trying to vote more than once per day.
    
if ($ratinguser==0){
        
$yesterday = (time()-(86400 $anonwaitdays));
        
$result=$xoopsDB->query("SELECT COUNT(*) FROM ".$xoopsDB->prefix("users_votedata")." WHERE uid=$uid AND ratinguser=0 AND ratinghostname = '$ip'  AND ratingtimestamp > $yesterday");
        list(
$anonvotecount) = $xoopsDB->fetchRow($result);
        if (
$anonvotecount >= 1) {
            
redirect_header("userinfo.php?uid=$uid",4,_US_VOTEONCE);
            exit();
        }
    }

    
//All is well.  Add to Line Item Rate to DB.
    
$newid $xoopsDB->genId("users_votedata_ratingid_seq");
    
$datetime time();
    
$xoopsDB->query("INSERT INTO ".$xoopsDB->prefix("users_votedata")." (ratingid, uid, ratinguser, rating, ratinghostname, ratingtimestamp) VALUES ($newid$uid$ratinguser$rating, '$ip', $datetime)") or $eh("0013");
    
//All is well.  Calculate Score & Add to Summary (for quick retrieval & sorting) to DB.

    //updates rating data in itemtable for a given item
    
$query "select rating FROM ".$xoopsDB->prefix("users_votedata")." WHERE uid = $uid";
    
$voteresult $xoopsDB->query($query);
       
$votesDB $xoopsDB->getRowsNum($voteresult);
    
$totalrating 0;
    while(list(
$rating)=$xoopsDB->fetchRow($voteresult)){
        
$totalrating += $rating;
    }
    
$finalrating $totalrating/$votesDB;
    
$finalrating number_format($finalrating4);
    
$query =  "UPDATE ".$xoopsDB->prefix("users")." SET rating=$finalrating, votes=$votesDB WHERE uid = $uid";
       
$xoopsDB->query($query);
    
$ratemessage _US_VOTEAPPRE."<br>".sprintf(_US_THANKYOU,$xoopsConfig[sitename]);
    
redirect_header("userinfo.php?uid=$uid",4,$ratemessage);
    exit();
} else {
    include(
XOOPS_ROOT_PATH."/header.php");
    
OpenTable();
    
$result=$xoopsDB->query("SELECT uname FROM ".$xoopsDB->prefix("users")." WHERE uid=$uid");
    list(
$uname) = $xoopsDB->fetchRow($result);
    
$uname $myts->makeTboxData4Show($uname);
    echo 
"
        
        <table border=0 cellpadding=1 cellspacing=0 width="
80%"><tr><td>
    
        <center><h4>
$uname</h4></center>
        <UL>
         <LI>"
._US_VOTEONCE."
         <LI>"
._US_RATINGSCALE."
         <LI>"
._US_BEOBJECTIVE."
         <LI>"
._US_DONOTVOTE."";
        echo 
"
         </UL>
         </td></tr>
         <tr><td align="
center">
         <form method="
POST" action="user_rate.php">
         <input type="
hidden" name="uid" value="$uid">
         <select name="
rating">
        <option>--</option>"
;
         for(
$i=10;$i>0;$i--){
            echo 
"<option value="".$i."">".$i."</option>n";
        }
         echo 
"</select><br><br><input type="submit" name="submit" value=""._US_RATEIT.""n>";
        echo 
"&nbsp;<input type="button" value=""._US_CANCEL."" onclick="javascript:history.go(-1)">n";
        echo 
"</form></td></tr></table>";
        
CloseTable();
}
    include 
XOOPS_ROOT_PATH."/footer.php";
?>

Create a newfiletexte ,paste all contents ,and rename it "user_rate.php" and send it in XOOPS racine (where is userinfo.php"

2 - Open userinfo.php and add this line just before "$gperm_handler"
//hack compteur de visite du profil
    
$page = !empty($HTTP_GET_VARS['page']) ? trim($HTTP_GET_VARS['page']) : '';
    if (
$page != '') {
        
$page $HTTP_GET_VARS['page'];
    } else {
        
$xoopsDB->queryF("update ".$xoopsDB->prefix("users")." set hits=hits+1 where uid=$uid ");
    }
//fin du hack


Add this both line after this line :$xoopsTpl->assign('lang_avatar', _US_AVATAR);
$xoopsTpl->assign('lang_ratethisuser'_US_RATETHISUSER);
$xoopsTpl->assign('lang_votes'_US_VOTES);
$xoopsTpl->assign('user_votes'$thisUser->getVar('votes'));
$xoopsTpl->assign('lang_hits'_US_HITSC);
$xoopsTpl->assign('user_hits'$thisUser->getVar('hits'));
$rating $thisUser->getVar("rating");
if (!empty(
$rating)) {
    
$xoopsTpl->assign('user_rating'number_format($rating2));
}
$xoopsTpl->assign('lang_ratingc'_US_RATINGC);


3 - Open kernel\user.php and add this 3 lines 108
$this->initVar('votes'XOBJ_DTYPE_OTHERnullfalse);
$this->initVar('hits'XOBJ_DTYPE_OTHERnullfalse);
$this->initVar('rating'XOBJ_DTYPE_OTHERnullfalse);


4 - Open language\english\user.php and add this lines at end
define("_US_VOTEAPPRE","Votre vote est appr&eacute;ci&eacute;.");
define("_US_THANKYOU","Merci de prendre le temps pour votez pour un membre ici sur %s"); // %s is your site name
define("_US_VOTEONCE","Merci de ne pas voter pour le m&ecirc;me membre plus d'une fois.");
define("_US_RATINGSCALE","L'&eacute;chelle est 1 - 10, avec 1 &eacute;tant faible et 10 &eacute;tant excellent.");
define("_US_BEOBJECTIVE","Merci d'&ecirc;tre objectif, si tous re&ccedil;oivent un 1 ou un 10, les notations ne sont pas tr&egrave;s utiles.");
define("_US_DONOTVOTE","Ne votez pas pour vous memes.");
define("_US_RATEIT","Votez pour ce membre !");
define("_US_CANCEL","Annuler !");
define("_US_NORATING","Vous avez annuler le vote!");

define in your language ,look in module mydownloads what is writting for example

5 - Open modules\system\template\system_userinfo.html and add this lines where you want

this is vote button ,the best place is at beginning
<input type="button" value="<{$lang_ratethisuser}>" onclick="location='<{$xoops_url}>/user_rate.php?uid=<{$user_uid}>'" />


Remplace your table "statistics" by this table ,they will display usr visit statistics and user votes statistics now
<table class="outer" cellpadding="4" cellspacing="1" width="100%">
        <
tr valign="top">
          <
th colspan="2" align="center"><{$lang_statistics}></th>
        </
tr>
        <
tr valign="top">
          <
td class="head" width="50%"><{$lang_membersince}></td>
          <
td align="center" class="even"><{$user_joindate}></td>
        </
tr>
        <
tr valign="top">
          <
td class="head" width="50%"><{$lang_rank}></td>
          <
td align="center" class="odd"><{$user_rankimage}><br /><{$user_ranktitle}></td>
        </
tr>
        <
tr valign="top">
          <
td class="head" width="50%"><{$lang_posts}></td>
          <
td align="center" class="even"><{$user_posts}></td>
        </
tr>
          <
tr valign="top">
          <
td class="head" width="50%"><{$lang_hits}></td>
          <
td align="center" class="odd"><{$user_hits}></td>
        </
tr>              
          <
tr valign="top">
          <
td class="head" width="50%"><{$lang_votes}></td>
          <
td align="center" class="odd"><{$user_votes}></td>
        </
tr>        
          <
tr valign="top">
          <
td class="head" width="50%"><{$lang_ratingc}></td>
          <
td align="center" class="odd"><{$user_rating}></td>
        </
tr>        
          <
tr valign="top">
          <
td class="head" width="50%"><{$lang_lastlogin}></td>
          <
td align="center" class="odd"><{$user_lastlogin}></td>
        </
tr>
      </
table>



6 - The last operation ,before to beginning save your database
ok go in your MySQL database ,click on "sql" and past this folder lines,and click on execute

ALTER TABLE `xoops_users`
ADD `hitsint(11NOT NULL default '0',
ADD `ratingdouble(6,4NOT NULL default '0.0000',
ADD `votesint(5unsigned NOT NULL default '0',

-- 
-- 
Structure de la table `xoops_users_votedata`
-- 

CREATE TABLE `xoops_users_votedata` (
  `
ratingidint(11unsigned NOT NULL auto_increment,
  `
uidint(11unsigned NOT NULL default '0',
  `
ratinguserint(11NOT NULL default '0',
  `
ratingtinyint(3unsigned NOT NULL default '0',
  `
ratinghostnamevarchar(60NOT NULL default '',
  `
ratingtimestampint(10NOT NULL default '0',
  
PRIMARY KEY  (`ratingid`),
  
KEY `ratinguser` (`ratinguser`),
  
KEY `ratinghostname` (`ratinghostname`),
  
KEY `pid` (`uid`)
ENGINE=MyISAM ;

Don't forget to change prefix if your prefixe is not "xoops"


that's all,normally your hack work as well now

best regards

2
daviddu54
Re: Adding users vote + user visit counter in your member's profils
  • 2006/8/11 16:50

  • daviddu54

  • Just popping in

  • Posts: 22

  • Since: 2006/8/1 2


Nobody have trying this method?

3
trabis
Re: Adding users vote + user visit counter in your member's profils
  • 2006/9/8 11:57

  • trabis

  • Core Developer

  • Posts: 2269

  • Since: 2006/9/1 1


I´m using MySQL client version: 4.1.21

I had this error:

#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'CREATE TABLE `trb_users_votedata` (
`ratingid` int(11) unsigned NOT NULL auto' at line 7

Can you help me on this?

4
trabis
Re: Adding users vote + user visit counter in your member's profils
  • 2006/9/8 21:44

  • trabis

  • Core Developer

  • Posts: 2269

  • Since: 2006/9/1 1


"
ALTER TABLE `xoops_users`
ADD `hits` int(11) NOT NULL default '0',
ADD `rating` double(6,4) NOT NULL default '0.0000',
ADD `votes` int(5) unsigned NOT NULL default '0',
"

OK... I took off the last comma and it went fine!

But now I get this error when trying to vote:


"Notice: Undefined index: submit in file /user_rate.php line 32"

I clear my templates and updated the system module and I can't see no extra tables on the profile. The button to vote has nothing wrote inside.

It seems there is some "define" missing.
For example:

_US_RATETHISUSER


Have you forgot something???

5
daviddu54
Re: Adding users vote + user visit counter in your member's profils
  • 2006/9/13 21:10

  • daviddu54

  • Just popping in

  • Posts: 22

  • Since: 2006/8/1 2


hi

yes i think i have mistake here

ADD `votes` int(5) unsigned NOT NULL default '0',

try to remplace virgule (,) by point virgule (;)

and for this error ,i have forget to define in language file ,also add this line in your language\english\user.php file

define("_US_RATETHISUSER","Rate this user ");

6
jordi_rc
Re: Adding users vote + user visit counter in your member's profils
  • 2006/10/20 18:49

  • jordi_rc

  • Not too shy to talk

  • Posts: 114

  • Since: 2006/8/21


Hello XOOPS friends.

I have implemented the hack for user ratings, seems great.

But I have a problem. Me, as administrator, can vote and all is ok.

If any other member tries to rate an user, I get a fatal error in line 75 of user_rate.php.

Please help me to fix this!

Jordi
"Battles are fought by those with the courage to believe. They are won by those who find the heart to share." -MANOWAR

7
m0nty
Re: Adding users vote + user visit counter in your members profils
  • 2006/10/20 19:15

  • m0nty

  • XOOPS is my life!

  • Posts: 3337

  • Since: 2003/10/24


also you might want to change all the HTTP vars in the above code.

you should use $_GET, $_POST, $_SERVER, $_FILES instead of the longer $HTTP_GET_VARS, $HTTP_POST_VARS and so on..

8
jordi_rc
Re: Adding users vote + user visit counter in your members profils
  • 2006/10/20 19:51

  • jordi_rc

  • Not too shy to talk

  • Posts: 114

  • Since: 2006/8/21


Thanks m0nty for the advice but it doesn't solves the problem.

The error is:

function name must be a string in user_rate.php line 75


I think it has to deal with syntax or maybe something that happens with admin user (1) and not with the others.

Do you have any ideas?

Jordi
"Battles are fought by those with the courage to believe. They are won by those who find the heart to share." -MANOWAR

9
m0nty
Re: Adding users vote + user visit counter in your members profils
  • 2006/10/20 20:09

  • m0nty

  • XOOPS is my life!

  • Posts: 3337

  • Since: 2003/10/24


mail me your user_rate.php to vaughan.montgomery[at]gmail[dot]com

10
jordi_rc
Re: Adding users vote + user visit counter in your members profils
  • 2006/10/20 21:01

  • jordi_rc

  • Not too shy to talk

  • Posts: 114

  • Since: 2006/8/21


OK and thanks very much for spending your time with me on this, m0nty.

If I could help you on something, just ask, I will try.

I also post here the line that throws the problem:

Quote:

$xoopsDB->query("INSERT INTO ".$xoopsDB->prefix("users_votedata")." (ratingid, uid, ratinguser, rating, ratinghostname, ratingtimestamp) VALUES ($newid, $uid, $ratinguser, $rating, '$ip', $datetime)") or $eh("0013");



Jordi.
"Battles are fought by those with the courage to believe. They are won by those who find the heart to share." -MANOWAR

Login

Who's Online

60 user(s) are online (35 user(s) are browsing Support Forums)


Members: 0


Guests: 60


more...

Donat-O-Meter

Stats
Goal: $100.00
Due Date: Aug 31
Gross Amount: $0.00
Net Balance: $0.00
Left to go: $100.00
Make donations with PayPal!

Latest GitHub Commits