Update of /cvsroot/php-blog/serendipity/plugins/serendipity_event_karma
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv6468/plugins/serendipity_event_karma
Modified Files:
Tag: branch-smarty
serendipity_event_karma.php
Log Message:
Karma plugin works with enabled entryproperties plugin and can
be configured to only show Hit-statistics for an entry without
the voting ability
Index: serendipity_event_karma.php
===================================================================
RCS file: /cvsroot/php-blog/serendipity/plugins/serendipity_event_karma/serendipity_event_karma.php,v
retrieving revision 1.14.2.5
retrieving revision 1.14.2.6
diff -u -d -r1.14.2.5 -r1.14.2.6
--- serendipity_event_karma.php 27 Oct 2004 11:04:56 -0000 1.14.2.5
+++ serendipity_event_karma.php 27 Oct 2004 14:11:16 -0000 1.14.2.6
@@ -1,7 +1,5 @@
<?php # $Id$
-/* Contributed by Matthias Lange (http://blog.dinnri.de/ml/) */
-
switch ($serendipity['lang']) {
case 'de':
@define('PLUGIN_KARMA_VERSION', '1.2');
@@ -35,7 +33,7 @@
@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_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');
@@ -81,7 +79,7 @@
@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_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');
@@ -442,6 +440,25 @@
$this->checkScheme();
}
+ // Check whether the cache plugin is used. If so, we need to append our karma-voting output
+ // to the cached version, since that one is used instead of the 'extended' key later on.
+ if (is_array($eventData) && isset($eventData[0])) {
+ if (!empty($eventData[0]['properties']['ep_cache_body'])) {
+
+ // It may happen that there is no extended entry to concatenate to. In that case,
+ // create a dummy extended entry.
+ if (!isset($eventData[0]['properties']['ep_cache_extended'])) {
+ $eventData[0]['properties']['ep_cache_extended'] = '';
+ }
+
+ $extended_key = &$eventData[0]['properties']['ep_cache_extended'];
+ } else {
+ $extended_key = &$eventData[0]['extended'];
+ }
+ } else {
+ $extended_key = '';
+ }
+
switch($this->karmaVote) {
case 'nocookie':
// Users with no cookies won't be able to vote.
@@ -471,7 +488,8 @@
/* OUTPUT MESSAGE */
if ($addData['extended']) {
- $eventData[0]['extended'] .= $msg;
+ $eventData[0]['exflag'] = 1;
+ $extended_keys .= $msg;
} else {
$elements = count($eventData);
// Find the right container to store our message in.
@@ -485,16 +503,14 @@
case 'voted':
default:
- if ($this->get_config('karma_active', 'true') != 'true') {
- return true;
- }
+ $track_clicks = serendipity_db_bool($this->get_config('visits_active', true));
+ $karma_active = serendipity_db_bool($this->get_config('karma_active', true));
if (!is_array($eventData)) return;
$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());
@@ -505,17 +521,21 @@
$link_4 = '<a class="serendipity_karmaVoting_link4" href="#" onclick="javascript:location.href=\'%5$sserendipity[karmaVote]=-1&serendipity[karmaId]=%1$s#karma_vote%1$s\';" title="' . sprintf(PLUGIN_KARMA_RATE, PLUGIN_KARMA_VOTEPOINT_4) . '">-</a>';
$link_5 = '<a class="serendipity_karmaVoting_link5" href="#" onclick="javascript:location.href=\'%5$sserendipity[karmaVote]=-2&serendipity[karmaId]=%1$s#karma_vote%1$s\';" title="' . sprintf(PLUGIN_KARMA_RATE, PLUGIN_KARMA_VOTEPOINT_5) . '">--</a>';
+ if ($addData['extended'] && $eventData[0]['timestamp'] < ($now - $max_karmatime)) {
+ $karma_active = false;
+ }
+
$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 . ($track_clicks == 'true' ? PLUGIN_KARMA_VISITSCOUNT : '') . '</div>';
+ . ($karma_active ? PLUGIN_KARMA_VOTETEXT . ' ' . $link_1 . ' | ' . $link_2 . ' | ' . $link_3 . ' | ' . $link_4 . ' | ' . $link_5 . '<br />'
+ . PLUGIN_KARMA_CURRENT : '') . ($track_clicks ? 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 . ($track_clicks == 'true' ? PLUGIN_KARMA_VISITSCOUNT : '') . '</div>';
+ . ($karma_active ? '<div class="serendipity_karmaSuccess">' . PLUGIN_KARMA_VOTED . '</div>'
+ . PLUGIN_KARMA_CURRENT : '') . ($track_clicks ? 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 . ($track_clicks == 'true' ? PLUGIN_KARMA_VISITSCOUNT : '') . '</div>';
+ . ($karma_active ? '<div>' . sprintf(PLUGIN_KARMA_CLOSED, $karmatime) . '</div>'
+ . PLUGIN_KARMA_CURRENT : '') . ($track_clicks ? PLUGIN_KARMA_VISITSCOUNT : '') . '</div>';
if ($addData['extended']) {
$entryid = (int)serendipity_db_escape_string($eventData[0]['id']);
@@ -527,10 +547,6 @@
}
}
- if ($eventData[0]['timestamp'] < ($now - $max_karmatime)) {
- return;
- }
-
$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';
@@ -548,12 +564,13 @@
$row['visits'] = 0;
}
+ $eventData[0]['exflag'] = 1;
if (isset($karma[$entryid])) {
- $eventData[0]['extended'] .= sprintf($karma_current, $karma[$entryid], $row['points'], $row['votes'], $row['visits'], $url);
+ $extended_key .= sprintf($karma_current, $karma[$entryid], $row['points'], $row['votes'], $row['visits'], $url);
} elseif ($eventData[0]['timestamp'] < ($now - $max_karmatime)) {
- $eventData[0]['extended'] .= sprintf($karma_timeout, $entryid, $row['points'], $row['votes'], $row['visits'], $url);
+ $extended_key .= sprintf($karma_timeout, $entryid, $row['points'], $row['votes'], $row['visits'], $url);
} else {
- $eventData[0]['extended'] .= sprintf($karma_voting, $entryid, $row['points'], $row['votes'], $row['visits'], $url);
+ $extended_key .= sprintf($karma_voting, $entryid, $row['points'], $row['votes'], $row['visits'], $url);
}
} elseif (!serendipity_db_bool($this->get_config('extended_only', false))) {
$elements = count($eventData);
@@ -608,4 +625,4 @@
}
/* vim: set sts=4 ts=4 expandtab : */
-?>
+?>
\ No newline at end of file
|