Welcome Guest, Not a member yet? Register   Sign In
Ajax star rating bar
#40

[eluser]debian4tw[/eluser]
Hi guys, sorry about the delay. some [email protected] are keeping me busy.

let's see if you can make it work with these modified/updated files, basically:

-you'll need jquery library.
-no need to use routes.
-no need to enable query strings, it uses uri segments.
-no need for ratings.js and behavior.js, just one simple 505 bytes jquery file that does the javascript part.
-with javascript disabled you should be redirected to the referer page. so you can delete the nojspage in config

here are the files:

rater.js
Code:
$(document).ready(function() {
        $("a[@href*=ratings_rpc]").bind("click", function(){
            
            par = this.href
            var params = par.split('/');
            params.reverse();
            var vote = params[4];
            var id_num = params[3];
            var ip_num = params[2];
            var units = params[1];    

            $(this).parent().parent().html('<div class="loading"><div>');
            $('#unit_long'+id_num.replace('idnum-','')).load('/ratings/ratings_rpc/index/'+vote+'/'+id_num+'/'+ip_num+'/'+units);
                
            return false;            
        });
});





modified index function on ratings_rpc controller
Code:
$url = $this->uri->uri_string();
    
        $nojs = false;
        // check if javascript is disabled
        if (strstr($url,'nojs-1')){
            
            $nojs = true;    
        }
        

        if(preg_match('/vote-(\d+)\/idnum-(\d+)\/ipnum-(.{1,16})\/units-(\d+)/', $url, $matches)){

            $vote_sent = $matches[1];
            $id_sent = $matches[2];    
            $ip_num = $matches[3];
            $units = $matches[4];
            $ip = $this->input->ip_address();
        }
        else{
            
            die("Sorry, vote appears to be invalid.");
        }
            


        // kill the script because normal users will never see this.
        if ($vote_sent > $units) die("Sorry, vote appears to be invalid.");

        //default values
        $checkIP = NULL;
        $count = 0;
        $current_rating = 0;
        $sum = 0;
        $tense = "votes"; // 0 votes

        //get the current values!
        if ($numbers = $this->ratings_model->findBy_id($id_sent))
        {
            // kill the script if vote limit is exceeded.
            if ($vote_sent > $numbers['vote_limit']) die("Sorry, your vote appears to be invalid.");

            $checkIP = unserialize($numbers['used_ips']);
            $count = $numbers['total_votes']; //how many votes total
            $current_rating = $numbers['total_value']; //total number of rating
            $sum = $vote_sent + $current_rating; // add together the current vote value and the total vote value
            $tense = ($count == 1) ? "vote" : "votes"; //plural form votes/vote
        }

        // checking to see if the first vote has been tallied or increment the current number of votes
        ($sum == 0 ? $added = 0 : $added = $count + 1);

        // if it is an array i.e. already has entries the push in another value
        (is_array($checkIP) ? array_push($checkIP, $ip_num) : $checkIP = array($ip_num));

        //if the user hasn't yet voted, then vote normally...
        if ($this->ratings_model->countBy_ip($ip, $id_sent) == 0)
        {

            //make sure vote is valid and IP matches - no monkey business!
            if ($vote_sent > 0 && $ip == $ip_num)
            {
                $this->ratings_model->updateBy_id($id_sent, array(
                'total_votes' => $added,
                'total_value' => $sum,
                'used_ips'    => serialize($checkIP),
                ));
            }
        }

        //get the new values!
        if ($numbers = $this->ratings_model->findBy_id($id_sent))
        {
            $checkIP = unserialize($numbers['used_ips']);
            $count = $numbers['total_votes']; //how many votes total
            $current_rating = $numbers['total_value']; //total number of rating
            $tense = ($count == 1) ? "vote" : "votes"; //plural form votes/vote
            $units = $numbers['vote_limit']; //get the vote limit
        }

        $data = array(
        'id_sent' => $id_sent,
        'current_rating' => $current_rating,
        'count' => $count,
        'sum'   => $sum,
        'added' => $added,
        'units' => $units,
        'tense' => $tense,
        'rating_unitwidth' => $this->config->item('rating_unitwidth'),
        );

        if($nojs) //javascript is disabled
        {

            // redirect() of url_helper adds site_url() :(
            header('Location: '.getenv('HTTP_REFERER'));

        }

        $this->load->view('newback_view', $data);


and...on dynamic_rating_view.php you need to change the href link to uri segments
Code:
// nojs-1 in url provides for javascript being disabled
echo '<li><a href="'.site_url().'/ratings_rpc/index/vote-'.$i.'/idnum-'.$id.'/ipnum-'.$ip.'/units-'.$units.'/nojs-1" title="'.$i.' out of '.$units.'" class="r'.$i.'-unit rater" rel="nofollow">'.$i.'</a></li>';


That should do it, if not letme know...
hope it helps


Messages In This Thread
Ajax star rating bar - by El Forum - 02-14-2008, 12:12 AM
Ajax star rating bar - by El Forum - 02-14-2008, 12:14 AM
Ajax star rating bar - by El Forum - 02-14-2008, 12:16 AM
Ajax star rating bar - by El Forum - 02-14-2008, 12:20 AM
Ajax star rating bar - by El Forum - 02-14-2008, 12:32 AM
Ajax star rating bar - by El Forum - 02-14-2008, 12:51 AM
Ajax star rating bar - by El Forum - 02-15-2008, 12:13 AM
Ajax star rating bar - by El Forum - 02-16-2008, 07:20 AM
Ajax star rating bar - by El Forum - 02-16-2008, 07:36 AM
Ajax star rating bar - by El Forum - 02-16-2008, 11:49 AM
Ajax star rating bar - by El Forum - 02-16-2008, 03:34 PM
Ajax star rating bar - by El Forum - 02-16-2008, 06:06 PM
Ajax star rating bar - by El Forum - 02-16-2008, 07:26 PM
Ajax star rating bar - by El Forum - 02-18-2008, 12:11 AM
Ajax star rating bar - by El Forum - 02-18-2008, 03:25 AM
Ajax star rating bar - by El Forum - 02-18-2008, 02:43 PM
Ajax star rating bar - by El Forum - 02-18-2008, 03:14 PM
Ajax star rating bar - by El Forum - 02-18-2008, 08:40 PM
Ajax star rating bar - by El Forum - 02-18-2008, 08:43 PM
Ajax star rating bar - by El Forum - 02-18-2008, 08:47 PM
Ajax star rating bar - by El Forum - 02-18-2008, 08:52 PM
Ajax star rating bar - by El Forum - 02-18-2008, 08:56 PM
Ajax star rating bar - by El Forum - 02-18-2008, 09:51 PM
Ajax star rating bar - by El Forum - 02-18-2008, 10:20 PM
Ajax star rating bar - by El Forum - 02-18-2008, 10:32 PM
Ajax star rating bar - by El Forum - 02-19-2008, 12:45 AM
Ajax star rating bar - by El Forum - 02-19-2008, 02:00 AM
Ajax star rating bar - by El Forum - 02-19-2008, 06:23 PM
Ajax star rating bar - by El Forum - 02-19-2008, 09:13 PM
Ajax star rating bar - by El Forum - 03-14-2008, 06:18 PM
Ajax star rating bar - by El Forum - 03-17-2008, 01:17 PM
Ajax star rating bar - by El Forum - 03-18-2008, 07:54 PM
Ajax star rating bar - by El Forum - 03-19-2008, 07:53 PM
Ajax star rating bar - by El Forum - 03-19-2008, 08:06 PM
Ajax star rating bar - by El Forum - 06-02-2008, 04:05 PM
Ajax star rating bar - by El Forum - 06-05-2008, 10:01 PM
Ajax star rating bar - by El Forum - 06-05-2008, 10:25 PM
Ajax star rating bar - by El Forum - 06-06-2008, 06:39 AM
Ajax star rating bar - by El Forum - 06-06-2008, 12:28 PM
Ajax star rating bar - by El Forum - 06-11-2008, 06:53 PM
Ajax star rating bar - by El Forum - 06-12-2008, 01:00 PM
Ajax star rating bar - by El Forum - 06-17-2008, 07:42 AM
Ajax star rating bar - by El Forum - 06-17-2008, 11:04 AM
Ajax star rating bar - by El Forum - 06-17-2008, 10:50 PM
Ajax star rating bar - by El Forum - 06-23-2008, 11:43 AM
Ajax star rating bar - by El Forum - 08-24-2008, 07:10 AM
Ajax star rating bar - by El Forum - 10-15-2008, 12:30 AM
Ajax star rating bar - by El Forum - 02-24-2009, 04:11 AM
Ajax star rating bar - by El Forum - 06-03-2009, 10:47 PM
Ajax star rating bar - by El Forum - 06-03-2009, 10:56 PM
Ajax star rating bar - by El Forum - 06-04-2009, 04:34 AM
Ajax star rating bar - by El Forum - 06-04-2009, 05:27 AM
Ajax star rating bar - by El Forum - 08-09-2009, 01:26 PM
Ajax star rating bar - by El Forum - 10-28-2009, 03:18 AM
Ajax star rating bar - by El Forum - 07-01-2010, 03:39 PM
Ajax star rating bar - by El Forum - 07-02-2010, 01:18 AM
Ajax star rating bar - by El Forum - 07-02-2010, 02:04 AM
Ajax star rating bar - by El Forum - 07-02-2010, 05:41 AM
Ajax star rating bar - by El Forum - 07-04-2010, 12:14 AM
Ajax star rating bar - by El Forum - 03-10-2011, 01:56 PM
Ajax star rating bar - by El Forum - 06-26-2011, 08:53 PM
Ajax star rating bar - by El Forum - 08-16-2011, 09:43 AM
Ajax star rating bar - by El Forum - 02-01-2012, 10:03 AM



Theme © iAndrew 2016 - Forum software by © MyBB