Update of /cvsroot/php-blog/serendipity/plugins/serendipity_event_karma
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv24806/plugins/serendipity_event_karma
Modified Files:
serendipity_event_karma.php
Log Message:
Merge from 'branch-smarty' to HEAD.
Index: serendipity_event_karma.php
===================================================================
RCS file: /cvsroot/php-blog/serendipity/plugins/serendipity_event_karma/serendipity_event_karma.php,v
retrieving revision 1.20
retrieving revision 1.21
diff -u -d -r1.20 -r1.21
--- serendipity_event_karma.php 29 Oct 2004 11:37:23 -0000 1.20
+++ serendipity_event_karma.php 19 Nov 2004 11:05:40 -0000 1.21
@@ -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');
@@ -52,7 +50,7 @@
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_BLAHBLAH', 'Let visitors rate the quality of your entries');
@define('PLUGIN_KARMA_VOTETEXT', 'Karma for this article: ');
@define('PLUGIN_KARMA_RATE', 'Rate this article: %s');
@define('PLUGIN_KARMA_VOTEPOINT_1', 'Very good!');
@@ -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');
@@ -108,7 +106,10 @@
$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, 'event_additional_statistics' => true));
+ $propbag->add('stackable', false);
+ $propbag->add('author', 'Garvin Hicking');
+ $propbag->add('version', '1.0');
+ $propbag->add('event_hooks', array('frontend_configure' => true, 'entry_display' => true, 'css' => true, 'event_additional_statistics' => true));
$propbag->add('scrambles_true_content', true);
$propbag->add('configuration', array('karma_active', 'visits_active', 'max_entrytime', 'max_votetime', 'extended_only', 'max_karmatime', 'logging'));
@@ -442,6 +443,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 +491,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 +506,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 +524,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']);
@@ -544,12 +567,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);
@@ -581,6 +605,10 @@
$points = (!empty($rows[$entryid]['points']) ? $rows[$entryid]['points'] : 0);
$visits = (!empty($rows[$entryid]['visits']) ? $rows[$entryid]['visits'] : 0);
+ if (!isset($eventData[$i]['add_footer'])) {
+ $eventData[$i]['add_footer'] = '';
+ }
+
if (isset($karma[$entryid])) {
$eventData[$i]['add_footer'] .= sprintf($karma_current, $karma[$entryid], $points, $votes, $visits, $url);
} elseif ($eventData[$i]['timestamp'] < ($now - $max_karmatime)) {
|