Update of /cvsroot/php-blog/serendipity/plugins/serendipity_event_karma
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv6749/serendipity_event_karma
Modified Files:
serendipity_event_karma.php
Log Message:
made karma plugin also log clicks.
add statistics hook to karma plugin
Index: serendipity_event_karma.php
===================================================================
RCS file: /cvsroot/php-blog/serendipity/plugins/serendipity_event_karma/serendipity_event_karma.php,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -d -r1.4 -r1.5
--- serendipity_event_karma.php 27 May 2004 16:51:08 -0000 1.4
+++ serendipity_event_karma.php 9 Jun 2004 11:49:23 -0000 1.5
@@ -4,6 +4,7 @@
switch ($serendipity['lang']) {
case 'de':
+ @define('PLUGIN_KARMA_VERSION', '1.2');
@define('PLUGIN_KARMA_NAME', 'Karma');
@define('PLUGIN_KARMA_BLAHBLAH', 'Abstimmung über die Eintrags');
@define('PLUGIN_KARMA_VOTETEXT', 'Karma dieses Eintrags: ');
@@ -18,28 +19,38 @@
@define('PLUGIN_KARMA_ALREADYVOTED', 'Bewertung bereits gespeichert.');
@define('PLUGIN_KARMA_NOCOOKIE', 'Der Browser muss Cookies unterstützen um eine Abstimmung zu ermöglichen.');
@define('PLUGIN_KARMA_CLOSED', 'Stimm ab für Artikel, die jünger als %s Tage sind!');
-
@define('PLUGIN_KARMA_ENTRYTIME', 'Abstimmungszeitraum nach Veröffentlichung eines Artikels');
@define('PLUGIN_KARMA_VOTINGTIME', 'Abstimmungszeitraum');
@define('PLUGIN_KARMA_ENTRYTIME_BLAHBLAH', 'Wie lang (in Minuten) kann nach der Veröffentlichung eines Artikels ein uneingeschränkter Abstimmungszeitraum durchgeführt werden? Standard sind 1440 Minuten (ein Tag).');
@define('PLUGIN_KARMA_VOTINGTIME_BLAHBLAH', 'Wartezeit (in Minuten), die nach einer Stimmabgabe vergehen muss bevor eine nächste Stimme angenommen wird. Diese Einschränkung gilt erst nach Überschreitung des obigen uneingeschränkten Abstimmungszeitraumes. Standard: 5 Minuten.');
@define('PLUGIN_KARMA_TIMEOUT', 'Wahlschutz: Ein anderer Besucher hat gerade abgestimmt. Bitte %s Minuten warten.');
-
@define('PLUGIN_KARMA_CURRENT', 'Derzeitiges Karma: %2$s, %3$s Stimme(n)');
-
@define('PLUGIN_KARMA_EXTENDEDONLY', 'Nur erweiterte Artikel');
@define('PLUGIN_KARMA_EXTENDEDONLY_BLAHBLAH', 'Karmavoting nur im erweiterten Artikel einblenden');
-
@define('PLUGIN_KARMA_MAXKARMA', 'Maximaler Abstimmungszeitraum');
@define('PLUGIN_KARMA_MAXKARMA_BLAHBLAH', 'Abstimmungen nur erlauben bis der Artikel X Tage alt ist (Standard: 7)');
-
@define('PLUGIN_KARMA_LOGGING', 'Protokollieren');
@define('PLUGIN_KARMA_LOGGING_BLAHBLAH', 'Sollen Logfiles der Votes angelegt werden?');
+ @define('PLUGIN_KARMA_ACTIVE', 'Karmavoting aktivieren?');
+ @define('PLUGIN_KARMA_ACTIVE_BLAHBLAH', 'Soll das Karmavoting verfügbar sein?');
+ @define('PLUGIN_KARMA_VISITS', 'Aufrufstatisik aktivieren?');
+ @define('PLUGIN_KARMA_VISITS_BLAHBLAH', 'Soll jeder Klick auf einen Artikel gezählt und dargestellt werden?');
+ @define('PLUGIN_KARMA_VISITSCOUNT', ', %4$s Klicks');
+ @define('PLUGIN_KARMA_STATISTICS_VISITS_TOP', 'Meistbesuchte Artikel');
+ @define('PLUGIN_KARMA_STATISTICS_VISITS_BOTTOM', 'Wenigstbesuchte Artikel');
+ @define('PLUGIN_KARMA_STATISTICS_VOTES_TOP', 'Meistbewertete Artikel');
+ @define('PLUGIN_KARMA_STATISTICS_VOTES_BOTTOM', 'Wenigstbewertete Artikel');
+ @define('PLUGIN_KARMA_STATISTICS_POINTS_TOP', 'Bestbewertete Artikel');
+ @define('PLUGIN_KARMA_STATISTICS_POINTS_BOTTOM', 'Schlechtstbewerte Artikel');
+ @define('PLUGIN_KARMA_STATISTICS_VISITS_NO', 'Besuche');
+ @define('PLUGIN_KARMA_STATISTICS_VOTES_NO', 'Stimmen');
+ @define('PLUGIN_KARMA_STATISTICS_POINTS_NO', 'Punkte');
break;
case 'en':
default:
+ @define('PLUGIN_KARMA_VERSION', '1.2');
@define('PLUGIN_KARMA_NAME', 'Karma');
@define('PLUGIN_KARMA_BLAHBLAH', 'Let people vote the quality of your entries');
@define('PLUGIN_KARMA_VOTETEXT', 'Karma for this article: ');
@@ -54,23 +65,32 @@
@define('PLUGIN_KARMA_ALREADYVOTED', 'Your rating was already stored.');
@define('PLUGIN_KARMA_NOCOOKIE', 'Your browser must support cookies to be able to vote.');
@define('PLUGIN_KARMA_CLOSED', 'Vote for articles fresher than %s days!');
-
@define('PLUGIN_KARMA_ENTRYTIME', 'Voting time after publishing');
@define('PLUGIN_KARMA_VOTINGTIME', 'Voting time');
@define('PLUGIN_KARMA_ENTRYTIME_BLAHBLAH', 'How long (in minutes) after your article has been published an unrestricted voting is allowed? Default: 1440 (one day)');
@define('PLUGIN_KARMA_VOTINGTIME_BLAHBLAH', 'Amount of time (in minutes) that needs to be passed from one vote to the other. Is only applied after the time above is expired. Default: 5');
@define('PLUGIN_KARMA_TIMEOUT', 'Flood protection: Another visitor has just recently voted. Please wait %s minutes.');
-
@define('PLUGIN_KARMA_CURRENT', 'Current karma: %2$s, %3$s vote(s)');
-
@define('PLUGIN_KARMA_EXTENDEDONLY', 'Only extended article');
@define('PLUGIN_KARMA_EXTENDEDONLY_BLAHBLAH', 'Only show karmavoting on extended article view');
-
@define('PLUGIN_KARMA_MAXKARMA', 'Karmavoting period');
@define('PLUGIN_KARMA_MAXKARMA_BLAHBLAH', 'Only allow karmavoting until the article is X days old (Default: 7)');
-
@define('PLUGIN_KARMA_LOGGING', 'Log votes?');
@define('PLUGIN_KARMA_LOGGING_BLAHBLAH', 'Should karma votes be logged?');
+ @define('PLUGIN_KARMA_ACTIVE', 'Enable karma voting?');
+ @define('PLUGIN_KARMA_ACTIVE_BLAHBLAH', 'Is karma voting turned on?');
+ @define('PLUGIN_KARMA_VISITS', 'Enable visit tracking?');
+ @define('PLUGIN_KARMA_VISITS_BLAHBLAH', 'Should every click to an extended article be counted and displayed?');
+ @define('PLUGIN_KARMA_VISITSCOUNT', ', %4$s hits');
+ @define('PLUGIN_KARMA_STATISTICS_VISITS_TOP', 'Top visited articles');
+ @define('PLUGIN_KARMA_STATISTICS_VISITS_BOTTOM', 'Worst visited articles');
+ @define('PLUGIN_KARMA_STATISTICS_VOTES_TOP', 'Top karma-voted articles');
+ @define('PLUGIN_KARMA_STATISTICS_VOTES_BOTTOM', 'Least karma-voted articles');
+ @define('PLUGIN_KARMA_STATISTICS_POINTS_TOP', 'Best karma-voted articles');
+ @define('PLUGIN_KARMA_STATISTICS_POINTS_BOTTOM', 'Worst karma-voted articles');
+ @define('PLUGIN_KARMA_STATISTICS_VISITS_NO', 'visits');
+ @define('PLUGIN_KARMA_STATISTICS_VOTES_NO', 'votes');
+ @define('PLUGIN_KARMA_STATISTICS_POINTS_NO', 'points');
break;
}
@@ -88,9 +108,9 @@
$propbag->add('name', PLUGIN_KARMA_NAME);
$propbag->add('description', PLUGIN_KARMA_BLAHBLAH);
- $propbag->add('event_hooks', array('frontend_configure' => true, 'entry_display' => true, 'css' => true));
+ $propbag->add('event_hooks', array('frontend_configure' => true, 'entry_display' => true, 'css' => true, 'event_additional_statistics' => true));
- $propbag->add('configuration', array('max_entrytime', 'max_votetime', 'extended_only', 'max_karmatime', 'logging'));
+ $propbag->add('configuration', array('karma_active', 'visits_active', 'max_entrytime', 'max_votetime', 'extended_only', 'max_karmatime', 'logging'));
}
function introspect_config_item($name, &$propbag)
@@ -114,6 +134,18 @@
$propbag->add('description', PLUGIN_KARMA_MAXKARMA_BLAHBLAH);
break;
+ case 'karma_active':
+ $propbag->add('type', 'boolean');
+ $propbag->add('name', PLUGIN_KARMA_ACTIVE);
+ $propbag->add('description', PLUGIN_KARMA_ACTIVE_BLAHBLAH);
+ break;
+
+ case 'visits_active':
+ $propbag->add('type', 'boolean');
+ $propbag->add('name', PLUGIN_KARMA_VISITS);
+ $propbag->add('description', PLUGIN_KARMA_VISITS_BLAHBLAH);
+ break;
+
case 'extended_only':
$propbag->add('type', 'boolean');
$propbag->add('name', PLUGIN_KARMA_EXTENDEDONLY);
@@ -136,7 +168,15 @@
global $serendipity;
$version = $this->get_config('version', '0.9');
- if ($version == '1.0') {
+
+ if ($version == '1.1') {
+ $q = "ALTER TABLE {$serendipity['dbPrefix']}karma ADD visits INT(11) default 0";
+ $sql = serendipity_db_schema_import($q);
+ $this->set_config('version', PLUGIN_KARMA_VERSION);
+ } elseif ($version == '1.0') {
+ $q = "ALTER TABLE {$serendipity['dbPrefix']}karma ADD visits INT(11) default 0";
+ $sql = serendipity_db_schema_import($q);
+
$q = "CREATE TABLE {$serendipity['dbPrefix']}karmalog (
entryid int(11) default null,
points int(4) default null,
@@ -145,13 +185,14 @@
votetime int(11) default null
)";
$sql = serendipity_db_schema_import($q);
- $this->set_config('version', '1.1');
- } elseif ($version != '1.1') {
+ $this->set_config('version', PLUGIN_KARMA_VERSION);
+ } elseif ($version != PLUGIN_KARMA_VERSION) {
$q = "CREATE TABLE {$serendipity['dbPrefix']}karma (
entryid int(11) default null,
points int(4) default null,
votes int(4) default null,
- lastvote int(10) {UNSIGNED} NULL
+ lastvote int(10) {UNSIGNED} NULL,
+ visits int(11) default null
)";
$sql = serendipity_db_schema_import($q);
@@ -168,20 +209,12 @@
$q = "CREATE INDEX kentryid ON {$serendipity['dbPrefix']}karma (entryid);";
$sql = serendipity_db_schema_import($q);
- $this->set_config('version', '1.1');
+ $this->set_config('version', PLUGIN_KARMA_VERSION);
}
return true;
}
- function register_dependencies($remove = false, $authorid = '0')
- {
- global $serendipity;
-
- if ($this->get_config('version') != '1.1') {
- }
- }
-
function generate_content(&$title)
{
$title = PLUGIN_KARMA_NAME;
@@ -236,12 +269,13 @@
return;
}
+ $now = time();
+
if ($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;
$max_karmatime = $this->get_config('max_karmatime', 7) * 24 * 60 * 60;
- $now = time();
if ($row['timestamp'] < ($now - $max_karmatime)) {
$this->karmaVote = 'timeout2';
@@ -277,15 +311,13 @@
$this->karmaId,
$this->karmaVoting,
1,
- time()
+ $now
);
$sql = serendipity_db_query($q);
}
if ($this->get_config('logging', false)) {
- $this->checkScheme();
-
$q = sprintf(
"INSERT INTO {$serendipity['dbPrefix']}karmalog
(entryid, points, ip, user_agent, votetime)
@@ -298,7 +330,7 @@
);
$sql = serendipity_db_query($q);
if (is_string($sql)) {
-
+ mail($serendipity['serendipityEmail'] , 'KARMA ERROR', $q . '<br />' . $sql . '<br />');
}
}
@@ -342,7 +374,52 @@
return true;
break;
+ case 'event_additional_statistics':
+ $sql = array();
+ $sql['visits_top'] = array('visits', 'DESC');
+ $sql['visits_bottom'] = array('visits', 'ASC');
+ $sql['votes_top'] = array('votes', 'DESC');
+ $sql['votes_bottom'] = array('votes', 'ASC');
+ $sql['points_top'] = array('points', 'DESC');
+ $sql['points_bottom'] = array('points', 'ASC');
+
+ foreach($sql AS $key => $rows) {
+ $q = "SELECT e.id,
+ e.title,
+ k.{$rows[0]} AS no
+ FROM {$serendipity['dbPrefix']}karma
+ AS k
+ JOIN {$serendipity['dbPrefix']}entries
+ AS e
+ ON k.entryid = e.id
+ ORDER BY k.{$rows[0]} {$rows[1]} LIMIT {$addData['maxitems']}";
+
+ $sql_rows = serendipity_db_query($q);
+?>
+ <dt><strong><?php echo constant('PLUGIN_KARMA_STATISTICS_' . strtoupper($key)); ?></strong></dt>
+ <dl>
+<?php
+ if (is_array($sql_rows)) {
+ foreach($sql_rows AS $id => $row) {
+ ?>
+ <dt><strong><a href="<?php echo serendipity_archiveURL($row['id'], $row['title'], 'serendipityHTTPPath'); ?>"><?php echo htmlspecialchars($row['title']); ?></a></strong></dt>
+ <dd><?php echo $row['no']; ?> <?php echo constant('PLUGIN_KARMA_STATISTICS_' . strtoupper($rows[0]) . '_NO'); ?></dd>
+ <?php
+ }
+ }
+?>
+ </dl>
+<?php
+ }
+
+ return true;
+ break;
+
case 'entry_display':
+ if ($this->get_config('version') != PLUGIN_KARMA_VERSION) {
+ $this->checkScheme();
+ }
+
switch($this->karmaVote) {
case 'nocookie':
// Users with no cookies won't be able to vote.
@@ -386,9 +463,14 @@
case 'voted':
default:
+ if ($this->get_config('karma_active', 'true') != 'true') {
+ return true;
+ }
+
$karmatime = $this->get_config('max_karmatime', 7);
$max_karmatime = $karmatime * 24 * 60 * 60;
$now = time();
+ $track_clicks = $this->get_config('visits_active', 'true');
$url = $_SERVER['REQUEST_URI'] . (stristr($_SERVER['REQUEST_URI'], '?') ? '&' : '?');
$karma = (isset($serendipity['COOKIE']['karmaVote']) ? unserialize($serendipity['COOKIE']['karmaVote']) : array());
@@ -402,23 +484,30 @@
$karma_voting = '
<br /><div class="serendipity_karmaVoting"><a id="karma_vote%1$s"></a>
' . PLUGIN_KARMA_VOTETEXT . ' ' . $link_1 . ' | ' . $link_2 . ' | ' . $link_3 . ' | ' . $link_4 . ' | ' . $link_5 . '<br />
- ' . PLUGIN_KARMA_CURRENT . '
+ ' . PLUGIN_KARMA_CURRENT . ($track_clicks == 'true' ? PLUGIN_KARMA_VISITSCOUNT : '') . '
</div>';
$karma_current = '
<br /><div class="serendipity_karmaVoting"><a id="karma_vote%1$s"></a>
<div class="serendipity_karmaSuccess">' . PLUGIN_KARMA_VOTED . '</div>
- ' . PLUGIN_KARMA_CURRENT . '
+ ' . PLUGIN_KARMA_CURRENT . ($track_clicks == 'true' ? PLUGIN_KARMA_VISITSCOUNT : '') . '
</div>';
$karma_timeout = '
<br /><div class="serendipity_karmaVoting"><a id="karma_vote%1$s"></a>
<div>' . sprintf(PLUGIN_KARMA_CLOSED, $karmatime) . '</div>
- ' . PLUGIN_KARMA_CURRENT . '
+ ' . PLUGIN_KARMA_CURRENT . ($track_clicks == 'true' ? PLUGIN_KARMA_VISITSCOUNT : '') . '
</div>';
if ($addData['extended']) {
- $entryid = $eventData[0]['id'];
+ $entryid = serendipity_db_escape_string($eventData[0]['id']);
+
+ 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 ($eventData[0]['timestamp'] < ($now - $max_karmatime)) {
return;
@@ -426,7 +515,7 @@
$q = 'SELECT *
FROM ' . $serendipity['dbPrefix'] . 'karma AS k
- WHERE k.entryid = ' . serendipity_db_escape_string($entryid) . ' LIMIT 1';
+ WHERE k.entryid = ' . $entryid . ' LIMIT 1';
$row = serendipity_db_query($q, true);
if (empty($row['votes'])) {
$row['votes'] = 0;
@@ -436,12 +525,16 @@
$row['points'] = 0;
}
+ if (empty($row['visits'])) {
+ $row['visits'] = 0;
+ }
+
if (isset($karma[$entryid])) {
- $eventData[0]['extended'] .= sprintf($karma_current, $karma[$entryid], $row['points'], $row['votes']);
+ $eventData[0]['extended'] .= sprintf($karma_current, $karma[$entryid], $row['points'], $row['votes'], $row['visits']);
} elseif ($eventData[0]['timestamp'] < ($now - $max_karmatime)) {
- $eventData[0]['extended'] .= sprintf($karma_timeout, $entryid, $row['points'], $row['votes']);
+ $eventData[0]['extended'] .= sprintf($karma_timeout, $entryid, $row['points'], $row['votes'], $row['visits']);
} else {
- $eventData[0]['extended'] .= sprintf($karma_voting, $entryid, $row['points'], $row['votes']);
+ $eventData[0]['extended'] .= sprintf($karma_voting, $entryid, $row['points'], $row['votes'], $row['visits']);
}
} elseif (!$this->get_config('extended_only', false)) {
$elements = count($eventData);
@@ -460,7 +553,7 @@
$rows = array();
if ($sql && is_array($sql)) {
foreach($sql AS $idx => $row) {
- $rows[$row['entryid']] = array('votes' => $row['votes'], 'points' => $row['points']);
+ $rows[$row['entryid']] = array('votes' => $row['votes'], 'points' => $row['points'], 'visits' => $row['visits']);
}
}
@@ -469,12 +562,14 @@
$entryid = $eventData[$i]['id'];
$votes = (!empty($rows[$entryid]['votes']) ? $rows[$entryid]['votes'] : 0);
$points = (!empty($rows[$entryid]['points']) ? $rows[$entryid]['points'] : 0);
+ $visits = (!empty($rows[$entryid]['visits']) ? $rows[$entryid]['visits'] : 0);
+
if (isset($karma[$entryid])) {
- $eventData[$i]['add_footer'] .= sprintf($karma_current, $karma[$entryid], $points, $votes);
+ $eventData[$i]['add_footer'] .= sprintf($karma_current, $karma[$entryid], $points, $votes, $visits);
} elseif ($eventData[$i]['timestamp'] < ($now - $max_karmatime)) {
- $eventData[$i]['add_footer'] .= sprintf($karma_timeout, $entryid, $points, $votes);
+ $eventData[$i]['add_footer'] .= sprintf($karma_timeout, $entryid, $points, $votes, $visits);
} else {
- $eventData[$i]['add_footer'] .= sprintf($karma_voting, $entryid, $points, $votes);
+ $eventData[$i]['add_footer'] .= sprintf($karma_voting, $entryid, $points, $votes, $visits);
}
}
}
|