Nicer voting in cpg 1.x [Updated] Nicer voting in cpg 1.x [Updated]
 

News:

cpg1.5.48 Security release - upgrade mandatory!
The Coppermine development team is releasing a security update for Coppermine in order to counter a recently discovered vulnerability. It is important that all users who run version cpg1.5.46 or older update to this latest version as soon as possible.
[more]

Main Menu

Nicer voting in cpg 1.x [Updated]

Started by SaWey, January 31, 2007, 10:00:28 AM

Previous topic - Next topic

0 Members and 2 Guests are viewing this topic.

SaWey

I've been working on the voting of cpg,
I thought it could use some new voting pic.

Edit:
Before you read any further, this has still a giant bug in it.
In Firefox everything works fine, but IE won't let you vote for the moment.
This is caused by the referer in the code in "ratepic.php" at line 39.
If you comment this out, it will work in both IE and Firefox, but be carefull:
If the referer isn't checked, it is possible to vote from another website!

Solution to this ex-problem can be found at the bottom

To intall this, follow these steps:

First of all, copy the attached files in there corresponding folders:
rating.js -> scripts/rating
new.gif -> images
full.gif -> images
empty.gif -> images

Then in your "template.html" add the following above the </head> tag:


<script type="text/javascript" src="scripts/rating/rating.js"></script>



And as a last change, in your "theme.php" file add the following code before "?>"


//Rating change
$template_image_rating = <<<EOT
<table align="center" width="{WIDTH}" cellspacing="1" cellpadding="0" class="maintable">
        <tr>
                <td colspan="6" class="tableh2_compact"><b>{TITLE}</b> {VOTES}</td>
        </tr>
        <tr>
                <td class="tableb_compact">{RATESCRIPT}</td>
        </tr>
</table>
EOT;
function theme_html_rating_box()
{
    global $CONFIG, $CURRENT_PIC_DATA, $CURRENT_ALBUM_DATA, $THEME_DIR;
    global $template_image_rating, $lang_rate_pic;

    if (!(USER_CAN_RATE_PICTURES && $CURRENT_ALBUM_DATA['votes'] == 'YES')) return '';

    $votes = $CURRENT_PIC_DATA['votes'] ? sprintf($lang_rate_pic['rating'], round($CURRENT_PIC_DATA['pic_rating'] / 2000, 1), $CURRENT_PIC_DATA['votes']) : $lang_rate_pic['no_votes'];
    $pid = $CURRENT_PIC_DATA['pid'];

    if (defined('THEME_HAS_RATING_GRAPHICS')) {
        $location= $THEME_DIR;
    } else {
        $location= '';
    }

    $params = array('{TITLE}' => $lang_rate_pic['rate_this_pic'],

'{RATESCRIPT}' => '<script type="text/javascript" language="JavaScript">displayStars(' . round($CURRENT_PIC_DATA['pic_rating'] / 2000, 0) . ', ' . $pid . ', "");</script>',
        '{VOTES}' => $votes,
        '{WIDTH}' => $CONFIG['picture_table_width'],
        '{LOCATION}' => $location,        //theme dir or default images directory
        );

    return template_eval($template_image_rating, $params);
}


To escape the ex-problem in IE, just
Change the code in "ratepic.php" at line 39 to

// If referer is not displayimage.php we don't accept the vote
$referer = $_SERVER["HTTP_REFERER"];
if (!eregi("displayimage", $referer) & !($referer == "")){
    header('Location: displayimage.php?pos=' . (- $pic));
    exit;
}



Now it works.

Have fun.

alanuk

Hi

Thanks for this. It's really useful.

I've changed it for my site to allow me to use a 1 - 10 scale which was very easy to do.

Thanks again for making this available.

Alan
http://www.digital-imaging-associates.com   

SaWey


SaWey

I don't know if any moderator will see this, but if you do,
can't you place this topic in the mods-section (visuals or something)

Thanks

Joachim Müller

It is (coppermine-gallery.net > No Support > Modifications/Add-Ons/Hacks > Mods: Voting/Rating). Nibbler moved it here. Shouldn't have gone into the bugs board in the first place imo.

bitcloud

hey there..

ah what does this actually do?

SaWey

This replaces the standard voting pictures with only one picture and adds some rollover effects.

You should try it,
It's realy nice.

bitcloud

nice 1...

now we just need some kind of ajaxified voting and we're set! (so the page doesn't reload when you submit your vote)

zac

Hiya SaWey... another great mod... I had it working fine on my site and then with my endless theme tweaking I managed to screw it up... now it returns the dreaded "selected album/file does not exist" message whenever a vote is cast.  I noticed that it changes from mysite/displayimage.php?album=#&pos=-# to mysite/displayimage.php?pos=-# (no album is identified).  Is the fix in the ratepic.php ? 

Thanks for any help with this.

mywedding

Quote from: SaWey on January 31, 2007, 10:00:28 AM
And as a last change, in your "theme.php" file add the following code before "?>"


hi dears,

i did not change , rating , well, i have not "theme.php" like you , could you fix problem , many thx,

note: my "theme.php" is below



define('THEME_IS_XHTML10_TRANSITIONAL',1); // Remove this if you edit this template until
                                           // you have validated it. See docs/theme.htm.

// HTML template for template sys_menu spacer
$template_sys_menu_spacer ='<img src="themes/water_drop/images/orange_carret.gif" width="8" height="8" border="0" alt="" />';

?>

Dreams are free, so free your dreams, "Astrid Alauda"

Joachim Müller

If a function or var definition doesn't exist in your cutom theme, copy the corresponding section from the sample theme. In your case, paste//Rating change
$template_image_rating = <<<EOT
<table align="center" width="{WIDTH}" cellspacing="1" cellpadding="0" class="maintable">
        <tr>
                <td colspan="6" class="tableh2_compact"><b>{TITLE}</b> {VOTES}</td>
        </tr>
        <tr>
                <td class="tableb_compact">{RATESCRIPT}</td>
        </tr>
</table>
EOT;
function theme_html_rating_box()
{
    global $CONFIG, $CURRENT_PIC_DATA, $CURRENT_ALBUM_DATA, $THEME_DIR;
    global $template_image_rating, $lang_rate_pic;

    if (!(USER_CAN_RATE_PICTURES && $CURRENT_ALBUM_DATA['votes'] == 'YES')) return '';

    $votes = $CURRENT_PIC_DATA['votes'] ? sprintf($lang_rate_pic['rating'], round($CURRENT_PIC_DATA['pic_rating'] / 2000, 1), $CURRENT_PIC_DATA['votes']) : $lang_rate_pic['no_votes'];
    $pid = $CURRENT_PIC_DATA['pid'];

    if (defined('THEME_HAS_RATING_GRAPHICS')) {
        $location= $THEME_DIR;
    } else {
        $location= '';
    }

    $params = array('{TITLE}' => $lang_rate_pic['rate_this_pic'],

'{RATESCRIPT}' => '<script type="text/javascript" language="JavaScript">displayStars(' . round($CURRENT_PIC_DATA['pic_rating'] / 2000, 0) . ', ' . $pid . ', "");</script>',
        '{VOTES}' => $votes,
        '{WIDTH}' => $CONFIG['picture_table_width'],
        '{LOCATION}' => $location,        //theme dir or default images directory
        );

    return template_eval($template_image_rating, $params);
}
into a new line before?>

SaWey

Quote from: zac on July 16, 2007, 10:01:34 AM
Hiya SaWey... another great mod... I had it working fine on my site and then with my endless theme tweaking I managed to screw it up... now it returns the dreaded "selected album/file does not exist" message whenever a vote is cast.  I noticed that it changes from mysite/displayimage.php?album=#&pos=-# to mysite/displayimage.php?pos=-# (no album is identified).  Is the fix in the ratepic.php ? 

Thanks for any help with this.

You should check some things:
Open a voting page and look into the source, find "<SCRIPT language=JavaScript type=text/javascript>displayStars",
It should end with something like this: "displayStars(0, 217, "");</SCRIPT>" Where the 217 is the number of the picture.

If that isn't in there, no pic will be defined and the problem lies within your theme.php file.
If so, please post your theme.php source in this thread.

zac

Yea.. must be the theme... here it is, long one...  with your cool lightbox mod as well. 
i am having problems posting it because of the length, would you  mind looking at a zip?


SaWey


zac


SaWey

Is this the correct theme.php file?
Cause I can't seem to find anything related to the voting mod?
have you added the code as suggested at the top of this thread?

zac

ah. yea forgot to mention that.  i took out the mod when i was trying to troubleshoot.  It was just a unmodified copy of what you have in this thread.

anyways...  I guess the problem is totally unrelated to your mod and is rather some other problem in my voting system.  I should probably make a diff thread for this i guess.. sorry bout that.

Singular

Nice mod. It works great. I have a request if you are willing. Could you guide me in the process of how to change the rating system to 10 stars instead of 5?

all the best,
Joe

Joachim Müller

Quote from: Singular on August 23, 2007, 05:45:51 PMCould you guide me in the process of how to change the rating system to 10 stars instead of 5?
Not related to this mod. Ask that question in a new thread on the support board after having searched for instructions how to accomplish what you're up to - I'm pretty sure that this has already been explained. Please do not clutter mod announcement threads with unrelated stuff in the future.




I created a demo theme based on the classic theme that comes with coppermine and bundled it with this mod. The bundle contains everything you need but the changes in ratepic.php.
To make this an actual theme, I changed the location of the extra files and modified the js file a bit (should be self-explanatory).

To see what the mod does, take a look at http://coppermine-gallery.net/demo/cpg14x/index.php?theme=classic_rating and try voting for any file.
Download my modified version of the classic theme (named "classic_rating") that contains all needed files originally created by SaWey here: http://downloads.sourceforge.net/coppermine/cpg1.4.x_theme_classic_rating.zip

Singular

Thanks for your reply. i tried the link you provided and I was not able to rate an image. There was no option and no stars visible. I was logged in.

all the best,
Joe