1
deka87
User profile AJAX rating hack
  • 2011/10/16 12:01

  • deka87

  • Friend of XOOPS

  • Posts: 1125

  • Since: 2007/10/5


Hi,

I've recently had an urge to implement an ajax rating system to the profile module so users could rate each others' profiles to define reliable customers. So I came across an interesting AJAX solution I will share now. Here is what my profile page looks like now:

Resized Image


How to implement:

1. Donwload the file archive (15Kb) from here.

2. Import ratings.sql to your database. This will create a new table there.

3. Upload images/, js/ and css/ directories into your default theme directory.

4. Upload _config-rating.php, db.php, rpc.php and _drawrating.php into modules/profile/ directory. Edit _config-rating.php with your server info.

5. Edit your theme.html. Add
<script type="text/javascript" language="javascript" src="<{xoImgUrl}>js/behavior.js"></script>
<
script type="text/javascript" language="javascript" src="<{xoImgUrl}>js/rating.js"></script>
<
link rel="stylesheet" type="text/css" href="<{xoImgUrl}>css/rating.css" />

just before the closing </head> tag.

6. Edit userinfo.php. Add
require('_drawrating.php');
right before
$uid intval($_GET['uid']);
. Also add
//rating hack

if ( $xoopsUser ) {
$rate rating_bar($uid,'5');
$xoopsTpl->assign('rate'$rate);
} else {
$rate rating_bar($uid,'5','static');
$xoopsTpl->assign('rate'$rate); // we don't want anonymous users to vote so we give them a static picture
}

//end of hack

before
include $GLOBALS['xoops']->path('/include/comment_view.php')
.

7. Edit the profile_userinfo.html template and add
<{$rate}>
wherever you want your rating box to appear.

8. Clean your cache.

This is it. Enjoy your new AJAX rating system. This can be also easily implemented to any other module.
Mind anchors

2
trabis
Re: User profile AJAX rating hack
  • 2011/10/16 13:05

  • trabis

  • Core Developer

  • Posts: 2269

  • Since: 2006/9/1 1


Thanks for sharing!

It would be nice to have this as a module (like tag), using XOOPS API.

Observations:
The sql file does not account for uid (same user can vote several times as long his IP changes)
The IPs are saved in one db field (used_ips) using longtext. It would be better to save each vote individually, It would allow admin to delete votes and have the results synchronized.

If you want to work on it, you could look at the ratings table in publisher (it uses the same ajax rating script)

Thank you again.

3
JCash
Re: User profile AJAX rating hack
  • 2011/10/16 13:58

  • JCash

  • Just popping in

  • Posts: 66

  • Since: 2011/2/22


Thanks for sharing !

4
andrey3761
Re: User profile AJAX rating hack

trabis

I'm working on a rating module based on tags. I will publish it if it works.

5
trabis
Re: User profile AJAX rating hack
  • 2011/10/16 15:14

  • trabis

  • Core Developer

  • Posts: 2269

  • Since: 2006/9/1 1


Quote:

andrey3761 wrote:
trabis

I'm working on a rating module based on tags. I will publish it if it works.


Awesome, thanks!

6
easyb9
Re: User profile AJAX rating hack
  • 2012/5/25 23:45

  • easyb9

  • Just popping in

  • Posts: 41

  • Since: 2011/8/10


cannot download
Извините, Вы не имеете разрешения на доступ в эту зону.
Sorry, you do not have permission to access this area.

Login

Who's Online

104 user(s) are online (70 user(s) are browsing Support Forums)


Members: 0


Guests: 104


more...

Donat-O-Meter

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

Latest GitHub Commits