• [MOD] Ajax Star Rating. Rate images without page reload, like on youtube etc. 4 0 5 1
Currently:  

Author Topic: [MOD] Ajax Star Rating. Rate images without page reload, like on youtube etc.  (Read 129371 times)

0 Members and 1 Guest are viewing this topic.

Offline MrAndrew

  • Sr. Member
  • ****
  • Posts: 302
    • View Profile
    • Aviation PhotoBase
Due to some MOD restrictions, you will be able to show only one result using stars images! (See attachments for DEMO!!!)

However, you able to show extremely results in ratung values (not in images)!

Let`s go!

0. STEP. Make a backup all files will be changed!!!

1. Step
Correct 4images_voted table. Set new options on "vote" Type: decimal Length/value 4,2 As defined  0.00

2. Step
Add to the 4images_voted table new field "vote_time" int(11) No 0
3. Step
Open /includes/page_header.php and delete:
Code: [Select]
 if ($user_info['user_level'] != GUEST) {
    $sql = "SELECT user_id, image_id, vote
            FROM ".VOTED_TABLE."
            WHERE image_id = ".$id." AND user_id = ".$user_info['user_id'];
    $rated = $site_db->query_firstrow($sql);
    $rating = ($rated['vote']) ? $rated['vote'] : $rating;
  }else{
    $rated = FALSE;
  }
3.1 Step
At the very end Locate:
Code: [Select]
?>Add:
Code: [Select]
//-----------------------------------------------------
//--- LATEST VOTES ------------------------------------
//-----------------------------------------------------
$lastvoted = "";

        
        $sql = "SELECT v.user_id, v.image_id, v.vote, v.vote_time, u.user_id, u.user_name, i.image_id, i.image_name
        FROM ".VOTED_TABLE." v, ".USERS_TABLE." u, ".IMAGES_TABLE." i
        WHERE v.user_id = u.user_id AND v.image_id = i.image_id
        ORDER BY v.vote_time DESC
        LIMIT 1";


$result = $site_db->query($sql);  
   while ($row = $site_db->fetch_array($result)) {
  
$lastv = '<div id="star"><br style="clear: both;" /><ul id="star0" class="star"><li id="starCur0" class="curr" title="'.$row['vote'].'" style="width: 0px;"></li></ul></div>';
  
$lastvoted .= "<tr>";
$lastvoted .= "<td align=\"left\" width=\"4\"></td>";
$lastvoted .= "<td align=\"left\">";
$lastvoted .= '<a href ="'.ROOT_PATH.'search.php?search_user='.$row['user_name'].'"><b>'.$row['user_name'].'</b></a>';
$lastvoted .= "</td>";
$lastvoted .= "<td width=\"50\" align=\"right\">";
$lastvoted .= ''.$lastv.''.$row['image_name'].'';
$lastvoted .= "</td>";
$lastvoted .= "</tr>";
}

$site_template->register_vars(array(
"lastvoted" => $lastvoted,
));
unset($lastvoted);
//-----------------------------------------------------

4. Step

Open /ajaxrating.php and find:
Code: [Select]
 if ($action == "rateimage" && $id) {
Add below:
Code: [Select]
 if ($user_info['user_level'] != GUEST) {
    $sql = "SELECT user_id, image_id, vote
            FROM ".VOTED_TABLE."
            WHERE image_id = ".$id." AND user_id = ".$user_info['user_id'];
    $rated = $site_db->query_firstrow($sql);
    $rating = ($rated['vote']) ? $rated['vote'] : $rating;
  }else{
    $rated = FALSE;
  }

4.1 Step
Find:
Code: [Select]
if (!in_array($id, $split_list) && !in_array($id, $cookie_rated)) {Replace:
Code: [Select]
if (!in_array($id, $split_list) && !in_array($id, $cookie_rated) && !$rated) {
5 Step
Open /includes/functions.php:
Find:
Code: [Select]
function update_image_rating($image_id, $rating) {
  global $site_db, $user_info;
Add below:
Code: [Select]
$current_time = time();
5.1 Step
Find:
Code: [Select]
       $sql = "INSERT INTO ".VOTED_TABLE."
                (user_id, image_id, vote)
                VALUES
                (".$user_info['user_id'].", ".$image_id.", ".$rating.")";
        $site_db->query($sql);
Replace:
Code: [Select]
       $sql = "INSERT INTO ".VOTED_TABLE."
                (user_id, image_id, vote, vote_time)
                VALUES
                (".$user_info['user_id'].", ".$image_id.", ".$rating.", ".$current_time.")";
        $site_db->query($sql);

6. Step:
Open templates/details.html
Find and delete:
Code: [Select]
<!-- ----------------------------------------------- -->
<!-- [MOD] Ajax Star Rating -------------- by Bash-T -->
<!-- START ----------------------------------------- -->
<script type="text/javascript">
YAHOO.namespace('rating');
YAHOO.rating.star={
display_percentage : false, //set to true if a percentaged value shall be shown beneath the stars.
display_lables: true, //set to true if a ranking label shall be displayed beneath the stars at mouseover.
//do not modify the properties below!
num : 0,
successfully_voted : false,
labels : [ '{ajax_rating_labels_0}' , '{ajax_rating_labels_1}', '{ajax_rating_labels_2}', '{ajax_rating_labels_3}', '{ajax_rating_labels_4}', '{ajax_rating_labels_5}'],
msgs : [ '{ajax_rating_messages_0}' , '{ajax_rating_messages_1}', '{ajax_rating_messages_2}']
};
</script>
<script type="text/javascript" src="scripts/ajaxrating.js"></script>
<!-- ----------------------------------------------- -->
<!-- [MOD] Ajax Star Rating -------------- by Bash-T -->
<!-- END ----------------------------------------- -->

6.1 Step:
Open templates/header.html
Find:
Code: [Select]
<!-- ----------------------------------------------- -->
<!-- [MOD] Ajax Star Rating -------------- by Bash-T -->
<!-- START ----------------------------------------- -->
<script type="text/javascript" src="scripts/yui/2.7.0/build/yahoo-dom-event/yahoo-dom-event.js"></script>
<script type="text/javascript" src="scripts/yui/2.7.0/build/json/json-min.js"></script>
<script type="text/javascript" src="scripts/yui/2.7.0/build/connection/connection-min.js"></script>
<!-- ----------------------------------------------- -->
<!-- [MOD] Ajax Star Rating -------------- by Bash-T -->
And replace:
Code: [Select]
<!-- ----------------------------------------------- -->
<!-- [MOD] Ajax Star Rating -------------- by Bash-T -->
<!-- START ----------------------------------------- -->
<script type="text/javascript" src="scripts/yui/2.7.0/build/yahoo-dom-event/yahoo-dom-event.js"></script>
<script type="text/javascript" src="scripts/yui/2.7.0/build/json/json-min.js"></script>
<script type="text/javascript" src="scripts/yui/2.7.0/build/connection/connection-min.js"></script>

<script type="text/javascript">
YAHOO.namespace('rating');
YAHOO.rating.star={
display_percentage : false, //set to true if a percentaged value shall be shown beneath the stars.
display_lables: true, //set to true if a ranking label shall be displayed beneath the stars at mouseover.
//do not modify the properties below!
num : 0,
successfully_voted : false,
labels : [ '{ajax_rating_labels_0}' , '{ajax_rating_labels_1}', '{ajax_rating_labels_2}', '{ajax_rating_labels_3}', '{ajax_rating_labels_4}', '{ajax_rating_labels_5}'],
msgs : [ '{ajax_rating_messages_0}' , '{ajax_rating_messages_1}', '{ajax_rating_messages_2}']
};
</script>
<script type="text/javascript" src="scripts/ajaxrating.js"></script>
<!-- ----------------------------------------------- -->
<!-- [MOD] Ajax Star Rating -------------- by Bash-T -->
<!-- END ----------------------------------------- -->

7. Step
Open templates/home.html
And locate this, where you want:
Code: [Select]
             <TABLE border="0" cellpadding="5" cellspacing="0" width="400" class="tablehead">
                <tr>
                  <TD class="tdhead">Last vote</TD>
                </tr>
                <TR>
                  <TD>Recent voted photo</TD>
                </TR>
                {lastvoted}
              </TABLE>

In case you want to show rating values:

In step: 3.1 find:
Code: [Select]
//-----------------------------------------------------
//--- LATEST VOTES ------------------------------------
//-----------------------------------------------------
$lastvoted = "";

        
        $sql = "SELECT v.user_id, v.image_id, v.vote, v.vote_time, u.user_id, u.user_name, i.image_id, i.image_name
        FROM ".VOTED_TABLE." v, ".USERS_TABLE." u, ".IMAGES_TABLE." i
        WHERE v.user_id = u.user_id AND v.image_id = i.image_id
        ORDER BY v.vote_time DESC
        LIMIT 1";


$result = $site_db->query($sql);  
   while ($row = $site_db->fetch_array($result)) {
  
$lastv = '<div id="star"><br style="clear: both;" /><ul id="star0" class="star"><li id="starCur0" class="curr" title="'.$row['vote'].'" style="width: 0px;"></li></ul></div>';
  
$lastvoted .= "<tr>";
$lastvoted .= "<td align=\"left\" width=\"4\"></td>";
$lastvoted .= "<td align=\"left\">";
$lastvoted .= '<a href ="'.ROOT_PATH.'search.php?search_user='.$row['user_name'].'"><b>'.$row['user_name'].'</b></a>';
$lastvoted .= "</td>";
$lastvoted .= "<td width=\"50\" align=\"right\">";
$lastvoted .= ''.$lastv.''.$row['image_name'].'';
$lastvoted .= "</td>";
$lastvoted .= "</tr>";
}

$site_template->register_vars(array(
"lastvoted" => $lastvoted,
));
unset($lastvoted);
//-----------------------------------------------------
Replace:
Code: [Select]
//-----------------------------------------------------
//--- LATEST VOTES ------------------------------------
//-----------------------------------------------------
$lastvoted = "";

        
        $sql = "SELECT v.user_id, v.image_id, v.vote, v.vote_time, u.user_id, u.user_name, i.image_id, i.image_name
        FROM ".VOTED_TABLE." v, ".USERS_TABLE." u, ".IMAGES_TABLE." i
        WHERE v.user_id = u.user_id AND v.image_id = i.image_id
        ORDER BY v.vote_time DESC
        LIMIT 3";


$result = $site_db->query($sql);  
   while ($row = $site_db->fetch_array($result)) {
  
$lastv = ''.$row['vote'].'';
  
$lastvoted .= "<tr>";
$lastvoted .= "<td align=\"left\" width=\"4\"></td>";
$lastvoted .= "<td align=\"left\">";
$lastvoted .= '<a href ="'.ROOT_PATH.'search.php?search_user='.$row['user_name'].'"><b>'.$row['user_name'].'</b></a>';
$lastvoted .= "</td>";
$lastvoted .= "<td width=\"50\" align=\"right\">";
$lastvoted .= ''.$lastv.'';
$lastvoted .= "</td>";
$lastvoted .= "<td width=\"50\" align=\"right\">";
$lastvoted .= ''.$row['image_name'].'';
$lastvoted .= "</td>";
$lastvoted .= "</tr>";
}

$site_template->register_vars(array(
"lastvoted" => $lastvoted,
));
unset($lastvoted);
//-----------------------------------------------------


Additional info:
LIMIT 3 you may change as you need...
« Last Edit: April 12, 2013, 07:33:13 PM by MrAndrew »

Offline CodeMan

  • Newbie
  • *
  • Posts: 32
    • View Profile
    • ArabGlobe.com
MrAndrew,

the AJAX Star rating stopped working after installing this MOD.
Rating is not possible anymore and also no mouse-over-effect.

Furhtermore, in step 4 you mentioned:

4. Step

Open /ajaxrating.php and find:
Code: [Select]
 $rating = intval($HTTP_POST_VARS['rating']);
Add below:
Code: [Select]
 if ($user_info['user_level'] != GUEST) {
    $sql = "SELECT user_id, image_id, vote
            FROM ".VOTED_TABLE."
            WHERE image_id = ".$id." AND user_id = ".$user_info['user_id'];
    $rated = $site_db->query_firstrow($sql);
    $rating = ($rated['vote']) ? $rated['vote'] : $rating;
  }else{
    $rated = FALSE;
  }


In my ajaxrating.php it says $rating = floatval($HTTP_POST_VARS['rating']); and not  $rating = intval($HTTP_POST_VARS['rating']);
I tried both, but not working.

In the attachment I added my 4images tables from phpMyAdmin so you can look at the structure.

Why did the AJAX Star rating stop working?
« Last Edit: April 12, 2013, 07:46:09 PM by CodeMan »

Offline MrAndrew

  • Sr. Member
  • ****
  • Posts: 302
    • View Profile
    • Aviation PhotoBase
Sorry! I missed!

Find:
Code: [Select]
if ($action == "rateimage" && $id) {add below:
Code: [Select]
  if ($user_info['user_level'] != GUEST) {
    $sql = "SELECT user_id, image_id, vote
            FROM ".VOTED_TABLE."
            WHERE image_id = ".$id." AND user_id = ".$user_info['user_id'];
    $rated = $site_db->query_firstrow($sql);
    $rating = ($rated['vote']) ? $rated['vote'] : $rating;
  }else{
    $rated = FALSE;
  }

-------------------

Code: [Select]
$rating = floatval($HTTP_POST_VARS['rating']);
Must be under the code!

Offline CodeMan

  • Newbie
  • *
  • Posts: 32
    • View Profile
    • ArabGlobe.com
No, still not working.
The whole rating sytem is not working anymore.

Bytheway, I hope you understood my explanation about showing the voted image on the home page.
I meant for each image_id, not just one voted image.

But anyway, still not working...

Offline MrAndrew

  • Sr. Member
  • ****
  • Posts: 302
    • View Profile
    • Aviation PhotoBase
Please, post your ajaxrating.php code here

Offline CodeMan

  • Newbie
  • *
  • Posts: 32
    • View Profile
    • ArabGlobe.com
Oke, see the attachment:

Offline MrAndrew

  • Sr. Member
  • ****
  • Posts: 302
    • View Profile
    • Aviation PhotoBase
May i see the site for more information? Send me link via PM

Offline Sunny C.

  • Addicted member
  • ******
  • Posts: 1.808
  • I ♥ 4I
    • View Profile
Dont work with jquery ;(