Page 1 of 1

Pimp the karma Plugin with shiny AJAX

Posted: Sun Dec 10, 2006 7:08 pm
by pixelartist
Hello,

i was going to pimp the karma plugin for different reasons, main reason .. to make it more attractiv for users to vote and get a better overview. So i finally got a nice AJAX Snippet of a voting System from MatsugaDesign (http://www.masugadesign.com/the-lab/scr ... ating-bar/).
I really like it and was goin to implement the code into serendipity. With this script it is just necessary to update the ID for each article in the database.
Garvin already did this with the karma plugin .. is there any information/doc about it? It could not be very difficult to merge these two scripts into one (already done from b2evolution - (http://manual.b2evolution.net/Plugins/starrating_plugin)! And if Garvin read this .. is there a chance to "pimp" the karma script in stead of developing a second nearly equal one?
Perhaps a button "Activate Ajax" or something would do it :)

P.S. For the ones who wont get the code and do it yourself ... here is an example - TestLink

Posted: Mon Dec 11, 2006 6:07 am
by carl_galloway
If you manage to get this working, and if you read my request from last month where I asked for something similar you would be making a lot of people very happy. You could be in the running for some donations, but be sure to reply to the other thread as well so everyone knows what you've done.

Really looking forward to reading about your success with this. BTW, Garvin is on vacation at the moment so you might not get a reply from him for a few days.

Posted: Mon Dec 11, 2006 11:06 am
by pixelartist
and if you read my request from last month
That was the thread i was remembering as i tried to get through the code of the karma :lol:
Garvin did a hell of a job with this karma thing, it would be a lot easier if he just tuned his skript, instead of reinventing the whole thing again.
The script you can see at the example already do recognize different IPs and put them into the SQl Database, and already is able to run in serendipity with just a few modifications of the template and database.
I also sure i would be able to merge the karma Plugin and this one ... you just need to get the part of getting an unique ID for an article and create a new enty in the database .. also already done by Garvin .. but he is a pro and i am not :).
No need for an additional sql table or two very similar mods :)

Posted: Mon Dec 11, 2006 11:32 am
by garvinhicking
Hi!

Thanks for delving into code examples here.

Sadly my motivation for a karma-rating plugin is VERY VERY low. I am using it on my personal homepage and have found out that it's virtually useless and people just use it to degrade articles. So I currently have no belief that this plugin is helpful at all, which keeps me from working on nice and shiny Ajax approaches....

BUT this doesn't mean I wouldn't appreciate if someone took a stab at it. It's just that I see my free time currently better fit on other s9y tasks than this one. Hope this can be understood. :-) :-)

Maybe you, pixelartist, would want to have a go at it? The karma plugin might look obfuscated at first, but in reality it isn't. ;) I would of course answer to all questions you might face along the way. :-)

Best regards,
Garvin

Posted: Mon Dec 11, 2006 2:49 pm
by mattsches
I'd also like to see the AJAX features built into the the pollbox plugin. Though I've never used this particular plugin, I'm thinking about a couple of uses of a AJAX-driven poll right now. Shouldn't be too hard, right? If anyone looks into this, please let me/us know.

Posted: Mon Dec 11, 2006 7:23 pm
by pixelartist
Sadly my motivation for a karma-rating plugin is VERY VERY low.

:lol:
The karma plugin might look obfuscated at first, but in reality it isn't.
Hah .. got ya :). My problem is that alle my "skills" are self-educated - so i will try .. but i will need help. I think its just the ID we need to be generated .. so what about this?

Code: Select all


                    if (isset($serendipity['GET']['id'])) {
                        $entryid = (int)serendipity_db_escape_string($serendipity['GET']['id']);
                    } elseif (preg_match(PAT_COMMENTSUB, $_SERVER['REQUEST_URI'], $matches)) {
                        $entryid = (int)$matches[1];
                    } else {
                        $entryid = false;
                    }

                    if ($entryid && empty($serendipity['GET']['adminAction'])) {
                        $track_clicks  = serendipity_db_bool($this->get_config('visits_active', true));
                        if ($track_clicks) {
                            $sql = serendipity_db_query('UPDATE ' . $serendipity['dbPrefix'] . 'karma SET visits = visits + 1 WHERE entryid = ' . $entryid, true);
                            if (serendipity_db_affected_rows() < 1) {
                                serendipity_db_query("INSERT INTO {$serendipity['dbPrefix']}karma (entryid, points, votes, lastvote, visits) VALUES ('$entryid', 0, 0, 0, 1)");
                            }
                        }
                    }

                    if (!isset($serendipity['GET']['karmaId']) || !isset($serendipity['GET']['karmaVote'])) {
                        return;
                    }

                    $this->karmaId     = (int)$serendipity['GET']['karmaId'];
                    $this->karmaVoting = (int)$serendipity['GET']['karmaVote'];
IMHO is this the part in which the ID is generated. Do you attached every EntryID a KarmaID ? I took a look in the database but there is not for every entryID an entry - so you just build a karmaID if somebody has voted?

Posted: Tue Dec 12, 2006 10:59 am
by garvinhicking
Hi!

Thanks for having a stab at it :)
IMHO is this the part in which the ID is generated. Do you attached every EntryID a KarmaID ? I took a look in the database but there is not for every entryID an entry - so you just build a karmaID if somebody has voted?
This is actually the part where the Entry-ID is *fetched*. It is not generated, but the code above will check and return the current Entry-ID of an entry being displayed. The entry-id is used to associate a karma-rating to an entryid, as you have already figured out.

An entry into the karmatable will only be made after the first user casts a vote for an entry. That means you will only see karmaId entries for entries that have at least one vote.

KarmaId == EntryID!

HTH,
Garvin