xoops forums

deka87

Friend of XOOPS
Posted on: 2011/10/16 12:01
deka87
deka87 (Show more)
Friend of XOOPS
Posts: 1124
Since: 2007/10/5
#1

User profile AJAX rating hack

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

trabis

Core Developer
Posted on: 2011/10/16 13:05
trabis
trabis (Show more)
Core Developer
Posts: 2268
Since: 2006/9/1 1
#2

Re: User profile AJAX rating hack

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.

JCash

Just popping in
Posted on: 2011/10/16 13:58
JCash
JCash (Show more)
Just popping in
Posts: 66
Since: 2011/2/22
#3

Re: User profile AJAX rating hack

Thanks for sharing !

andrey3761

XOOPS Translator
Posted on: 2011/10/16 14:24
andrey3761
andrey3761 (Show more)
XOOPS Translator
Posts: 234
Since: 2008/8/21
#4

Re: User profile AJAX rating hack

trabis

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

trabis

Core Developer
Posted on: 2011/10/16 15:14
trabis
trabis (Show more)
Core Developer
Posts: 2268
Since: 2006/9/1 1
#5

Re: User profile AJAX rating hack

Quote:

andrey3761 wrote:
trabis

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


Awesome, thanks!

easyb9

Just popping in
Posted on: 2012/5/25 23:45
easyb9
easyb9 (Show more)
Just popping in
Posts: 41
Since: 2011/8/10
#6

Re: User profile AJAX rating hack

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