From d23f1300bbd63478ff7bf1768d95aca4917dea91 Mon Sep 17 00:00:00 2001 From: garvinhicking <garvinhicking> Date: Fri, 22 Apr 2005 13:41:03 +0000 Subject: [PATCH] karma plugin makes click tracking earlier, better interation with other plugins (cache, mainly) also fixes insertion of double entries. --- .../serendipity_event_karma.php | 34 ++++++++++++------- 1 file changed, 22 insertions(+), 12 deletions(-) diff --git a/plugins/serendipity_event_karma/serendipity_event_karma.php b/plugins/serendipity_event_karma/serendipity_event_karma.php index f761f45..08a9625 100644 --- a/plugins/serendipity_event_karma/serendipity_event_karma.php +++ b/plugins/serendipity_event_karma/serendipity_event_karma.php @@ -8,7 +8,7 @@ if (file_exists($probelang)) { switch ($serendipity['lang']) { case 'de': - @define('PLUGIN_KARMA_VERSION', '1.2'); + @define('PLUGIN_KARMA_VERSION', '1.3'); @define('PLUGIN_KARMA_NAME', 'Karma'); @define('PLUGIN_KARMA_BLAHBLAH', 'Abstimmung über die Einträge'); @define('PLUGIN_KARMA_VOTETEXT', 'Karma dieses Eintrags: '); @@ -54,7 +54,7 @@ switch ($serendipity['lang']) { case 'en': default: - @define('PLUGIN_KARMA_VERSION', '1.2'); + @define('PLUGIN_KARMA_VERSION', '1.3'); @define('PLUGIN_KARMA_NAME', 'Karma'); @define('PLUGIN_KARMA_BLAHBLAH', 'Let visitors rate the quality of your entries'); @define('PLUGIN_KARMA_VOTETEXT', 'Karma for this article: '); @@ -115,7 +115,7 @@ class serendipity_event_karma extends serendipity_event $propbag->add('description', PLUGIN_KARMA_BLAHBLAH); $propbag->add('stackable', false); $propbag->add('author', 'Garvin Hicking'); - $propbag->add('version', '1.01'); + $propbag->add('version', PLUGIN_KARMA_VERSION); $propbag->add('requirements', array( 'serendipity' => '0.8', 'smarty' => '2.6.7', @@ -253,6 +253,24 @@ class serendipity_event_karma extends serendipity_event serendipity_setCookie('karmaVote', serialize(array())); } + 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) { + $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; } @@ -297,8 +315,7 @@ class serendipity_event_karma extends serendipity_event } $now = time(); - - if ($row['votes'] > 0) { + if ($row['votes'] === '0' || $row['votes'] > 0) { // Votes for this entry already exist. Do some checking. $max_entrytime = $this->get_config('max_entrytime', 1440) * 60; $max_votetime = $this->get_config('max_votetime', 5) * 60; @@ -541,13 +558,6 @@ class serendipity_event_karma extends serendipity_event if ($addData['extended'] || $addData['preview']) { $entryid = (int)serendipity_db_escape_string($eventData[0]['id']); - if ($track_clicks && !$addData['preview']) { - $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)"); - } - } - $q = 'SELECT SUM(votes) AS votes, SUM(points) AS points, SUM(visits) AS visits FROM ' . $serendipity['dbPrefix'] . 'karma AS k WHERE k.entryid = ' . $entryid . ' GROUP BY k.entryid LIMIT 1'; -- 2.39.5