Rating Hack Tutorial:
1. Obtain zip file copied from original funbox.ro archive (which is no longer there, which is why I zipped the files up and supplied them
here.)
a. Read through the readme file included with the original archive. This is the original readme from the funbox.ro site.
2. Expand zip file to a temporary directory.
3. Edit the _config_rating.php file with your DB parameters to connect to your zenphoto DB
4. About line 38 in the _drawrating.php file, you'll want to edit the path to be the absolute path to your zenphoto installation.
5. Add these lines to your image.php file:
HEAD Section
<?php require('_drawrating.php'); ?>
<!-- Rating System -->
<script type="text/javascript" language="javascript" src="<?= $_zp_themeroot ?>/js/rating.js"></script>
<link rel="stylesheet" type="text/css" href="<?= $_zp_themeroot ?>/css/rating.css" />
BODY Section
<?php $id=$_zp_current_image->id; rating_bar($id,5); ?>
6. Copy the contents of the temporary directory (NOTE: with the exception of the index.php file) you created to your theme folder, and make sure the directories (images/css/js) stay intact. If you already have these folders, that's ok.
7. You will have to add some custom stuff to your DB:
CREATE TABLE 'ratings' (
'id' varchar(11) NOT NULL,
'total_votes' int(11) NOT NULL default '0',
'total_value' int(11) NOT NULL default '0',
'used_ips' longtext,
PRIMARY KEY ('id')
) TYPE=MyISAM AUTO_INCREMENT=3 ;
Note that I was able to successfully put this information in my Images table as well with no issues. Just make sure in the config file (_config_rating.php) that the table is pointing to the correct one.
After this, it should work properly. I will not be providing any official support for this "hack" as it isn't mine to begin with, but I'll be happy to answer questions on the forum to the best of my abilities (and as time permits.) Everything you need should be here to make it work.
Comments
1. mySQl gave errors so I had to run this query instead of yours:
CREATE TABLE `ratings` (
`id` INT( 11 ) NOT NULL AUTO_INCREMENT PRIMARY KEY ,
`total_value` INT( 11 ) NOT NULL DEFAULT '0',
`total_votes` INT( 11 ) NOT NULL DEFAULT '0',
`used_ips` LONGTEXT NOT NULL
) ENGINE = MYISAM ;
2. Everything else was setup as you said except in image.php I had to specify the path of
<?absolute path here/_drawrating.php'); ?> as the original README suggests.
3. I can see the stars and clicking on them reloads, no errors occur but the vote does not register.
since it was a hack made by a zenphoto poster whose site was down for others, and I grabbed it, i figured i'd post it. but i can't guarantee it works in everyone's implementation, since I haven't tested it at all on anyone's install.
everyone else is welcome to post here and help us work out the bugs, as I'm sure there are some.
You may try initializing the SQL table with some data first, before voting. It does mention something about that in the readme file.
'CREATE TABLE `ratings` (
`id` VARCHAR( 11 ) NOT NULL ,
`total_value` INT( 11 ) NOT NULL DEFAULT '0',
`total_votes` INT( 11 ) NOT NULL DEFAULT '0',
`used_ips` LONGTEXT NULL ,
PRIMARY KEY ( `id` )
) ENGINE = MYISAM AUTO_INCREMENT =3;'
This ran and then I initialized by running.
'INSERT INTO `clientz_ratings` ( `id` , `total_value` , `total_votes` , `used_ips` )
VALUES (
'1', '0', '0', NULL
), (
'2', '0', '0', NULL
);'
The paths seem ok to me. Everything runs fine (i.e. no errors) except the vote does not register!!
I did away with the INSERT statement, because someone could get the db.php href and alter that (though not the rating or the IP) to add a new line into your db. I couldn't figure out a decent way to check that. So, at least for now, any new raters placed on a page have to be entered in your db manually, before votes can be registered to that id.
Is this the source of my troubles?
After the line:
$query=mysql_query("SELECT total_votes, total_value, used_ips FROM $tableName WHERE id='$id' ")or die(" Error: ".mysql_error());
Add:
if (mysql_num_rows($query) == 0) {
$sql = "INSERT INTO $tableName (`id`,
`total_votes`, `total_value`, `used_ips`)
VALUES ('$id', '0', '0', '')";
$result = mysql_query($sql);
}
And it works.
Of course, on this forum I can never get code to show up accurately so I don't know but believe me this works. Of course I wonder if the original reason for avoiding the INSERT command in favor of manual insert is still valid. Any thoughts anybody?
Comment number 12. WaxOr is what helped.
Others have done things like most popular etc.
did you do line #4 on my tutorial? I noted that in the drawrating file, I had to COMPLETELY hardcode the URL to get it to work:
`&q=<?php echo $id ?>&t=<?php echo $ip ?>&c=<?php echo $units ?>" title="<?php echo $ncount ?> out of <?php echo $units ?>" class="r<?php echo $ncount ?>-unit rater"><?php echo $ncount ?>`
Thus, http://www.thinkdreams.com/zenphoto/themes/thinkdreams_photoblog would be what I would use in my case. That might be causing your issue.
Now for some cool icons...I think the stars (starrating.gif) are much nicer but they come with a rectangular white background block that does not take kindly to transparency. On the masugadesign.com page they tell you how to design custom icons.
@subjunk, is there anything possibly different about your install that you could share that might help jayray out?
and mod_rewrite is off right now on yours jayray right?
Try it without mod_rewrite just for kicks. The problem is that the db.php call in the drawrating file is coded for a specific url and parameters, and it will get messed around with mod_rewrite. There may be a way to fix it in the mod_rewrite statements but I'm not sure how to go about that.
if (mysql_num_rows($query) == 0) {
$sql = "INSERT INTO $tableName (id,
total_votes, total_value, used_ips)
VALUES ('$id', '0', '0', '')";
$result = mysql_query($sql);
}
After the line:
$query=mysql_query("SELECT total_votes, total_value, used_ips FROM $tableName WHERE id='$id' ")or die(" Error: ".mysql_error());
Sorry I'll check back on this thread more often and try to help. I do have another worthwhile change to make though, for those of you who want valid code:
In _drawrating.php, change:
<?php echo $ncount ?>&q=<?php echo $id ?>&t=<?php echo $ip ?>&c=<?php echo $units ?>" title="<?php echo $ncount ?> out of <?php echo $units ?>" class="r<?php echo $ncount ?>-unit rater"><?php echo $ncount ?>
To:
<?php echo $ncount ?>&q=<?php echo $id ?>&t=<?php echo $ip ?>&c=<?php echo $units ?>" title="<?php echo $ncount ?> out of <?php echo $units ?>" class="r<?php echo $ncount ?>-unit rater"><?php echo $ncount ?>
It just escapes the ampersands, just that little change got rid of 18 perceived W3C errors for me.
Replace all the ampersands (&) with:
& amp; (remove the space between & and a)
`/js/behavior.js">`
Then another error occurs when a star (or whatever image you use for rating) is clicked, the error is:
`Line 60, character 2: Null is null or an invalid object'`
No filename is given in the error but I expect it is in rating.js
On line 63 of rating.js there is:
`xmlhttp.send(null);`
Anyone have any ideas of how to fix this error?