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

[eluser]wiredesignz[/eluser]
Sorry for the late reply draude, I ported the star rating system to CI as an exercise, You're on your own when it comes to modifications. Thanks Wink
#32

[eluser]debian4tw[/eluser]
great stuff wiredesignz!
i'm going to be implementing this for sure, i'll let you know how that goes.
#33

[eluser]debian4tw[/eluser]
hey guys, this is strange
on an apache running on windows (wamp) everything works fine,
now on an apache running on a linux server i get :
The URI you submitted has disallowed characters.

any ideas?

thanks
#34

[eluser]taewoo[/eluser]
read this: http://ellislab.com/forums/viewthread/72933/
#35

[eluser]Silvrbak[/eluser]
I am having trouble with this. The loading clock just runs, the page does not refresh. If I refresh manually the vote has been cast. Any ideas?
#36

[eluser]debian4tw[/eluser]
Hi guys!

@Silvrbak

Looks to me that at somepoint javascript is getting problems, probably when showing the response once the vote has been comited, have you tried to check what happens if you disable javascript? or are you getting any javascript errors? firebug says something? let me know and maybe we can figure out togheter whats going on there.

anyway i slightly modified this library to work with query strings off and use uri segments, also i replaced the whole js work (behavior.js and rating.js ) with a few lines of jquery code. let me clean it up a little bit tomorrow and i'll post mi modifications here (if thats ok with wiredesignz) hopefully you'll have better luck with it, or someone will find it usefull Tongue

btw:
@wiredesignz
thank you very much sir =) this lib was very helpfull.
One thing that i've noticed is that you're making 2 queries. One to get the current rating and another to check if the user has voted or not(logically to allow the user or not to vote). the last one:
Code:
SELECT used_ips FROM ratings WHERE used_ips LIKE '#7.0.0.1%' AND id = '2'
Imho it's unnecesary to make that query if you call for a static rating from the view.
for instance in a blog, probably you'll want to show the static rating (no rating submit allowed ) when you list and paginate all the articles with the short description and the "read more link". And only let them vote when they are on the "full article" view.
So in the first case by just checking the current rating youre done, and you have 10 or 20 unnecesary queries that are trying to find an ip on a longtext field, i think that's not very cool.

i dont know if it is the best way to solve it, but i've fixed by modifying ratings_model.php, replace:
Code:
$voted = (bool)$this->countBy_ip($ip, $id);

with:
Code:
$voted = '';
if (!$static){
  $voted = (bool)$this->countBy_ip($ip, $id);
}

hope it helps
thanks again
#37

[eluser]wiredesignz[/eluser]
You're welcome debian4tw, feel free to create a wiki article for this library and modify as you wish.

Sorry I don't have time to support this any longer.
#38

[eluser]Isern Palaus[/eluser]
Hello,

I'm trying to use this script on my new project but seems that is not working fine. At first I've to say that I was having problems on the countBy_ip() function because I'm using a DB prefix. I solved with replacing the function with:

Code:
function countBy_ip($ip, $id)
    {
        $this->db->select('used_ips');
        $this->db->where('id','{'.$id.'}');
        $this->db->like('used_ips','{'.$ip.'}');
        $query = $this->db->get('ratings');
        return count($query->result());        
    }

Now this is working fine.

Whats more, I am trying to use it but seems that it's not working fine (well, it does not work at all). I've been trying first with the examples that wiredesignz provided and none of them works. Firebug is showing me this:

Quote:Params:
c; 5
j 3
q; 2id
t; 127.0.0.1

Headers:
Response Headers
Date Fri, 06 Jun 2008 21:28:52 GMT
Server Apache/2.2.4 (Win32)
Content-Length 228
Keep-Alive timeout=5, max=77
Connection Keep-Alive
Content-Type text/html; charset=iso-8859-1

Request Headers
Host localhost
User-Agent Mozilla/5.0 (Windows; U; Windows NT 5.1; es-ES; rv:1.8.1.14) Gecko/20080404 Firefox/2.0.0.14
Accept application/x-shockwave-flash,text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5
Accept-Language es-es,es;q=0.8,en-us;q=0.5,en;q=0.3
Accept-Encoding gzip,deflate
Accept-Charset ISO-8859-1,utf-8;q=0.7,*;q=0.7
Keep-Alive 300
Connection keep-alive
Referer http://localhost/dumbo/public_html/

Response:
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">

&lt;html&gt;&lt;head&gt;

&lt;title&gt;404 Not Found&lt;/title&gt;

&lt;/head&gt;&lt;body&gt;

<h1>Not Found</h1>

<p>The requested URL /dumbo/public_html/rpc.php was not found on this server.</p>

&lt;/body&gt;&lt;/html&gt;

Well the route hack ($route['rpc.php'] = ...) do not works and I don't know what more to do. I'm using a mod_rewrite to split up the index.php/.

Thank you in advance,
-- Isern Palaus
#39

[eluser]Silvrbak[/eluser]
That would be great if you could up the revised versions of the Jscripts. I hooked up Firebug and the error I am getting is this,

Code:
viewer has no properties
changeText(" unit_long66334", "unit_long66334")rating.js (line 94)
handleResponse()rating.js (line 79)
sndReq("3", "66334", "<IP ADDRESS>", "10")rating.js (line 67)
onclick()rating.js (line 120)
[Break on this error] viewer[removed] = text;

This is in the ratings.js script.


[quote author="debian4tw" date="1212742865"]Hi guys!

@Silvrbak

Looks to me that at somepoint javascript is getting problems, probably when showing the response once the vote has been comited, have you tried to check what happens if you disable javascript? or are you getting any javascript errors? firebug says something? let me know and maybe we can figure out togheter whats going on there.

anyway i slightly modified this library to work with query strings off and use uri segments, also i replaced the whole js work (behavior.js and rating.js ) with a few lines of jquery code. let me clean it up a little bit tomorrow and i'll post mi modifications here (if thats ok with wiredesignz) hopefully you'll have better luck with it, or someone will find it usefull Tongue

btw:
@wiredesignz
thank you very much sir =) this lib was very helpfull.
One thing that i've noticed is that you're making 2 queries. One to get the current rating and another to check if the user has voted or not(logically to allow the user or not to vote). the last one:
Code:
SELECT used_ips FROM ratings WHERE used_ips LIKE '#7.0.0.1%' AND id = '2'
Imho it's unnecesary to make that query if you call for a static rating from the view.
for instance in a blog, probably you'll want to show the static rating (no rating submit allowed ) when you list and paginate all the articles with the short description and the "read more link". And only let them vote when they are on the "full article" view.
So in the first case by just checking the current rating youre done, and you have 10 or 20 unnecesary queries that are trying to find an ip on a longtext field, i think that's not very cool.

i dont know if it is the best way to solve it, but i've fixed by modifying ratings_model.php, replace:
Code:
$voted = (bool)$this->countBy_ip($ip, $id);

with:
Code:
$voted = '';
if (!$static){
  $voted = (bool)$this->countBy_ip($ip, $id);
}

hope it helps
thanks again[/quote]
#40

[eluser]debian4tw[/eluser]
Hi guys, sorry about the delay. some exams@unviersity 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




Theme © iAndrew 2016 - Forum software by © MyBB