1
0

improved karma plugin

This commit is contained in:
Garvin Hicking
2012-02-08 15:14:58 +01:00
parent a490e1e7a5
commit f16854859a
21 changed files with 381 additions and 258 deletions

View File

@ -6,6 +6,9 @@ Version 1.7 ()
* fixed draft & future entries preview link in backend * fixed draft & future entries preview link in backend
* Improved karmarating plugin to be able to use AJAX calls
(gregman)
* Allow Smarty to fetch .tpl files from all directories so that * Allow Smarty to fetch .tpl files from all directories so that
s9y plugin can use the fetch() call for their .tpl files no s9y plugin can use the fetch() call for their .tpl files no
matter which (symlinked) directory the plugin resides in. matter which (symlinked) directory the plugin resides in.
@ -16,6 +19,7 @@ Version 1.7 ()
add that to .tpl files. add that to .tpl files.
(garvinhicking) (garvinhicking)
* Patch by Markus Brükner: Properly handle files that have no * Patch by Markus Brükner: Properly handle files that have no
extension in media database extension in media database

View File

@ -1,7 +1,7 @@
<?php # $Id$ <?php # $Id: lang_bg.inc.php 2114 2008-02-11 12:25:31Z jwalker $
/** /**
* @version $Revision$ * @version $Revision: 2114 $
* @author Ivan Cenov jwalker@hotmail.bg * @author Ivan Cenov jwalker@hotmail.bg
* EN-revision: 1475 * EN-revision: 1475
*/ */

View File

@ -1,13 +1,11 @@
<?php # lang_de.inc.php 1.1 2011-11-22 10:01:55 VladaAjgl $ <?php # lang_de.inc.php 1.0 2009-06-03 09:51:33 VladaAjgl $
/** /**
* @version 1.1 * @version 1.0
* @author Grischa Brockhaus <http://blog.brockha.us> * @author Grischa Brockhaus <http://blog.brockha.us>
* DE-Revision: Revision of lang_de.inc.php * DE-Revision: Revision of lang_de.inc.php
* @author Konrad Bauckmeier <kontakt@dd4kids.de> * @author Konrad Bauckmeier <kontakt@dd4kids.de>
* @translated 2009/06/03 * @translated 2009/06/03
* @author Konrad Bauckmeier <yourmail@example.com>
* @revisionDate 2011/11/22
*/ */
@define('PLUGIN_KARMA_NAME', 'Karma'); @define('PLUGIN_KARMA_NAME', 'Karma');
@ -46,7 +44,7 @@
@define('PLUGIN_KARMA_VOTETEXT_1', '-2'); @define('PLUGIN_KARMA_VOTETEXT_1', '-2');
@define('PLUGIN_KARMA_VOTETEXT_1_NAME', 'Benennung: Schlechtes Ergebnis'); @define('PLUGIN_KARMA_VOTETEXT_1_NAME', 'Benennung: Schlechtes Ergebnis');
@define('PLUGIN_KARMA_VOTETEXT_1_BLAHBLAH', 'Text, der dargestellt wird, wenn der Benutzer für "schlecht" im Textmode stimmen möchte. (Standard: ' . PLUGIN_KARMA_VOTETEXT_1 . ')'); @define('PLUGIN_KARMA_VOTETEXT_1_BLAHBLAH', 'Text, der dargestellt wird, wenn der Benutzer für "schlecht" im Textmode stimmen möchte. (Standard: ' . PLUGIN_KARMA_VOTETEXT_1 . ')');
@define('PLUGIN_KARMA_VOTED', 'Punktzahl "%s" gespeichert.'); @define('PLUGIN_KARMA_VOTED', 'Bewertung "%s" gespeichert.');
@define('PLUGIN_KARMA_VOTES', '%3$s Stimme(n)'); @define('PLUGIN_KARMA_VOTES', '%3$s Stimme(n)');
@define('PLUGIN_KARMA_INVALID', 'Bewertung ungültig oder manipuliert!'); @define('PLUGIN_KARMA_INVALID', 'Bewertung ungültig oder manipuliert!');
@define('PLUGIN_KARMA_ALREADYVOTED', 'Bewertung bereits gespeichert.'); @define('PLUGIN_KARMA_ALREADYVOTED', 'Bewertung bereits gespeichert.');
@ -73,7 +71,6 @@
//--JAM:@define('PLUGIN_KARMA_ALIGNMENT', 'Voting Bar Alignment'); //--JAM:@define('PLUGIN_KARMA_ALIGNMENT', 'Voting Bar Alignment');
//--JAM:@define('PLUGIN_KARMA_ALIGNMENT_BLAHBLAH', 'Alignment of voting bar in the entry footer. Templates can override this setting with !important (Default: right)'); //--JAM:@define('PLUGIN_KARMA_ALIGNMENT_BLAHBLAH', 'Alignment of voting bar in the entry footer. Templates can override this setting with !important (Default: right)');
//--JAM: @define('PLUGIN_KARMA_ALIGNMENT_DETECT', 'from style'); //--JAM: @define('PLUGIN_KARMA_ALIGNMENT_DETECT', 'from style');
@define('PLUGIN_KARMA_VISITS', 'Aufrufstatisik aktivieren?'); @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_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');
@ -124,5 +121,8 @@
@define('PLUGIN_KARMA_DELETE_VOTES', 'Lösche ausgewählte Stimmen'); @define('PLUGIN_KARMA_DELETE_VOTES', 'Lösche ausgewählte Stimmen');
@define('PLUGIN_KARMA_APPROVE_VOTES', 'Bestätige ausgewählte Stimmen'); @define('PLUGIN_KARMA_APPROVE_VOTES', 'Bestätige ausgewählte Stimmen');
// Next lines were translated on 2011/11/22 //New on ajax feature
@define('PLUGIN_KARMA_ACTIVE_REGISTERED', 'Nur eingeloggte Authoren können abstimmen'); @define('PLUGIN_KARMA_AJAX', 'AJAX Funktionalität');
@define('PLUGIN_KARMA_AJAX_BLAHBLAH', 'Soll die Stimmabgabe mittels asynchronem Javascript erfolgen? Wenn ja, wird die Bewertung im Hintergrund an den Server gesendet und das Ergebnis dargestellt, ohne dass die Seite neu geladen werden muss.');
@define('PLUGIN_KARMA_ALIGNMENT', 'Ausrichtung des Plugins');
@define('PLUGIN_KARMA_ALIGNMENT_BLAHBLAH', 'Soll das Plugin links, mittig oder rechts angezeigt werden?');

View File

@ -1,6 +1,6 @@
<?php # $Id$ <?php # $Id: lang_es.inc.php 2110 2008-02-11 02:12:07Z slothman $
/** /**
* @version $Revision$ * @version $Revision: 2110 $
* @author Rodrigo Lazo Paz <rlazo.paz@gmail.com> * @author Rodrigo Lazo Paz <rlazo.paz@gmail.com>
* EN-Revision: 690 * EN-Revision: 690
*/ */

View File

@ -1,4 +1,4 @@
<?php # $Id$ <?php # $Id: lang_fr.inc.php 2110 2008-02-11 02:12:07Z slothman $
########################################################################## ##########################################################################
# serendipity - another blogger... # # serendipity - another blogger... #

View File

@ -1,7 +1,7 @@
<?php # $Id$ <?php # $Id: lang_ja.inc.php 2110 2008-02-11 02:12:07Z slothman $
/** /**
* @version $Revision$ * @version $Revision: 2110 $
* @author Tadashi Jokagi <elf2000@users.sourceforge.net> * @author Tadashi Jokagi <elf2000@users.sourceforge.net>
* EN-Revision: 690 * EN-Revision: 690
*/ */

View File

@ -1,4 +1,4 @@
<?php # $Id$ <?php # $Id: lang_ko.inc.php 2110 2008-02-11 02:12:07Z slothman $
# Translated by: Wesley Hwang-Chung <wesley96@gmail.com> # Translated by: Wesley Hwang-Chung <wesley96@gmail.com>
# (c) 2005 http://www.tool-box.info/ # (c) 2005 http://www.tool-box.info/

View File

@ -1,7 +1,7 @@
<?php # $Id$ <?php # $Id: lang_pl.inc.php 2110 2008-02-11 02:12:07Z slothman $
/** /**
* @version $Revision$ * @version $Revision: 2110 $
* @author Kostas CoSTa Brzezinski <costa@kofeina.net> * @author Kostas CoSTa Brzezinski <costa@kofeina.net>
* EN-Revision: Revision of lang_en.inc.php * EN-Revision: Revision of lang_en.inc.php
*/ */

View File

@ -1,4 +1,4 @@
<?php # $Id$ <?php # $Id: lang_tn.inc.php 2110 2008-02-11 02:12:07Z slothman $
########################################################################## ##########################################################################
# Copyright (c) 2003-2005, Jannis Hermanns (on behalf the Serendipity # # Copyright (c) 2003-2005, Jannis Hermanns (on behalf the Serendipity #
# Developer Team) All rights reserved. See LICENSE file for licensing # # Developer Team) All rights reserved. See LICENSE file for licensing #

View File

@ -1,4 +1,4 @@
<?php # $Id$ <?php # $Id: lang_zh.inc.php 2110 2008-02-11 02:12:07Z slothman $
########################################################################## ##########################################################################
# Copyright (c) 2003-2005, Jannis Hermanns (on behalf the Serendipity # # Copyright (c) 2003-2005, Jannis Hermanns (on behalf the Serendipity #
# Developer Team) All rights reserved. See LICENSE file for licensing # # Developer Team) All rights reserved. See LICENSE file for licensing #

View File

@ -1,7 +1,7 @@
<?php # $Id$ <?php # $Id: lang_bg.inc.php 2114 2008-02-11 12:25:31Z jwalker $
/** /**
* @version $Revision$ * @version $Revision: 2114 $
* @author Ivan Cenov jwalker@hotmail.bg * @author Ivan Cenov jwalker@hotmail.bg
*/ */

View File

@ -1,13 +1,11 @@
<?php # lang_de.inc.php 1.1 2011-11-22 10:01:55 VladaAjgl $ <?php # lang_de.inc.php 1.0 2009-06-03 09:51:33 VladaAjgl $
/** /**
* @version 1.1 * @version 1.0
* @author Grischa Brockhaus <http://blog.brockha.us> * @author Grischa Brockhaus <http://blog.brockha.us>
* DE-Revision: Revision of lang_de.inc.php * DE-Revision: Revision of lang_de.inc.php
* @author Konrad Bauckmeier <kontakt@dd4kids.de> * @author Konrad Bauckmeier <kontakt@dd4kids.de>
* @translated 2009/06/03 * @translated 2009/06/03
* @author Konrad Bauckmeier <yourmail@example.com>
* @revisionDate 2011/11/22
*/ */
@define('PLUGIN_KARMA_NAME', 'Karma'); @define('PLUGIN_KARMA_NAME', 'Karma');
@ -46,7 +44,7 @@
@define('PLUGIN_KARMA_VOTETEXT_1', '-2'); @define('PLUGIN_KARMA_VOTETEXT_1', '-2');
@define('PLUGIN_KARMA_VOTETEXT_1_NAME', 'Benennung: Schlechtes Ergebnis'); @define('PLUGIN_KARMA_VOTETEXT_1_NAME', 'Benennung: Schlechtes Ergebnis');
@define('PLUGIN_KARMA_VOTETEXT_1_BLAHBLAH', 'Text, der dargestellt wird, wenn der Benutzer f<>r "schlecht" im Textmode stimmen m<>chte. (Standard: ' . PLUGIN_KARMA_VOTETEXT_1 . ')'); @define('PLUGIN_KARMA_VOTETEXT_1_BLAHBLAH', 'Text, der dargestellt wird, wenn der Benutzer f<>r "schlecht" im Textmode stimmen m<>chte. (Standard: ' . PLUGIN_KARMA_VOTETEXT_1 . ')');
@define('PLUGIN_KARMA_VOTED', 'Punktzahl "%s" gespeichert.'); @define('PLUGIN_KARMA_VOTED', 'Bewertung "%s" gespeichert.');
@define('PLUGIN_KARMA_VOTES', '%3$s Stimme(n)'); @define('PLUGIN_KARMA_VOTES', '%3$s Stimme(n)');
@define('PLUGIN_KARMA_INVALID', 'Bewertung ung<6E>ltig oder manipuliert!'); @define('PLUGIN_KARMA_INVALID', 'Bewertung ung<6E>ltig oder manipuliert!');
@define('PLUGIN_KARMA_ALREADYVOTED', 'Bewertung bereits gespeichert.'); @define('PLUGIN_KARMA_ALREADYVOTED', 'Bewertung bereits gespeichert.');
@ -73,7 +71,6 @@
//--JAM:@define('PLUGIN_KARMA_ALIGNMENT', 'Voting Bar Alignment'); //--JAM:@define('PLUGIN_KARMA_ALIGNMENT', 'Voting Bar Alignment');
//--JAM:@define('PLUGIN_KARMA_ALIGNMENT_BLAHBLAH', 'Alignment of voting bar in the entry footer. Templates can override this setting with !important (Default: right)'); //--JAM:@define('PLUGIN_KARMA_ALIGNMENT_BLAHBLAH', 'Alignment of voting bar in the entry footer. Templates can override this setting with !important (Default: right)');
//--JAM: @define('PLUGIN_KARMA_ALIGNMENT_DETECT', 'from style'); //--JAM: @define('PLUGIN_KARMA_ALIGNMENT_DETECT', 'from style');
@define('PLUGIN_KARMA_VISITS', 'Aufrufstatisik aktivieren?'); @define('PLUGIN_KARMA_VISITS', 'Aufrufstatisik aktivieren?');
@define('PLUGIN_KARMA_VISITS_BLAHBLAH', 'Soll jeder Klick auf einen Artikel gez<65>hlt und dargestellt werden?'); @define('PLUGIN_KARMA_VISITS_BLAHBLAH', 'Soll jeder Klick auf einen Artikel gez<65>hlt und dargestellt werden?');
@define('PLUGIN_KARMA_VISITSCOUNT', ' %4$s Klicks'); @define('PLUGIN_KARMA_VISITSCOUNT', ' %4$s Klicks');
@ -124,5 +121,8 @@
@define('PLUGIN_KARMA_DELETE_VOTES', 'L<>sche ausgew<65>hlte Stimmen'); @define('PLUGIN_KARMA_DELETE_VOTES', 'L<>sche ausgew<65>hlte Stimmen');
@define('PLUGIN_KARMA_APPROVE_VOTES', 'Best<73>tige ausgew<65>hlte Stimmen'); @define('PLUGIN_KARMA_APPROVE_VOTES', 'Best<73>tige ausgew<65>hlte Stimmen');
// Next lines were translated on 2011/11/22 //New on ajax feature
@define('PLUGIN_KARMA_ACTIVE_REGISTERED', 'Nur eingeloggte Authoren k<>nnen abstimmen'); @define('PLUGIN_KARMA_AJAX', 'AJAX Funktionalit<69>t');
@define('PLUGIN_KARMA_AJAX_BLAHBLAH', 'Soll die Stimmabgabe mittels asynchronem Javascript erfolgen? Wenn ja, wird die Bewertung im Hintergrund an den Server gesendet und das Ergebnis dargestellt, ohne dass die Seite neu geladen werden muss.');
@define('PLUGIN_KARMA_ALIGNMENT', 'Ausrichtung des Plugins');
@define('PLUGIN_KARMA_ALIGNMENT_BLAHBLAH', 'Soll das Plugin links, mittig oder rechts angezeigt werden?');

View File

@ -1,7 +1,7 @@
<?php # $Id$ <?php # $Id: lang_en.inc.php 2738 2011-03-09 11:11:14Z garvinhicking $
/** /**
* @version $Revision$ * @version $Revision: 2738 $
* @author Translator Name <yourmail@example.com> * @author Translator Name <yourmail@example.com>
* EN-Revision: Revision of lang_en.inc.php * EN-Revision: Revision of lang_en.inc.php
*/ */
@ -117,3 +117,9 @@
@define('PLUGIN_KARMA_DELETE_VOTES', 'Delete selected votes'); @define('PLUGIN_KARMA_DELETE_VOTES', 'Delete selected votes');
@define('PLUGIN_KARMA_APPROVE_VOTES', 'Approve selected votes'); @define('PLUGIN_KARMA_APPROVE_VOTES', 'Approve selected votes');
@define('PLUGIN_KARMA_ACTIVE_REGISTERED', 'Only logged-in authors can vote'); @define('PLUGIN_KARMA_ACTIVE_REGISTERED', 'Only logged-in authors can vote');
//New on ajax feature
@define('PLUGIN_KARMA_AJAX', 'AJAX funcionality');
@define('PLUGIN_KARMA_AJAX_BLAHBLAH', 'Shall rating be performed by asynchronous javascript? If set to "yes", your rating will be send to the server in the background and the result will be displayed without refreshing the website.');
@define('PLUGIN_KARMA_ALIGNMENT', 'Alignmnet of the plugin');
@define('PLUGIN_KARMA_ALIGNMENT_BLAHBLAH', 'Shall the plugin be displayed left, center or right');

View File

@ -1,6 +1,6 @@
<?php # $Id$ <?php # $Id: lang_es.inc.php 1381 2006-08-15 10:14:56Z elf2000 $
/** /**
* @version $Revision$ * @version $Revision: 1381 $
* @author Rodrigo Lazo Paz <rlazo.paz@gmail.com> * @author Rodrigo Lazo Paz <rlazo.paz@gmail.com>
* EN-Revision: 690 * EN-Revision: 690
*/ */

View File

@ -1,7 +1,7 @@
<?php # $Id$ <?php # $Id: lang_fa.inc.php 1381 2006-08-15 10:14:56Z elf2000 $
/** /**
* @version $Revision$ * @version $Revision: 1381 $
* @author Omid Mottaghi <webmaster@oxygenws.com> * @author Omid Mottaghi <webmaster@oxygenws.com>
* EN-Revision: Revision of lang_fa.inc.php * EN-Revision: Revision of lang_fa.inc.php
*/ */

View File

@ -1,4 +1,4 @@
<?php # $Id$ <?php # $Id: lang_fr.inc.php 1381 2006-08-15 10:14:56Z elf2000 $
########################################################################## ##########################################################################
# serendipity - another blogger... # # serendipity - another blogger... #

View File

@ -1,7 +1,7 @@
<?php # $Id$ <?php # $Id: lang_ja.inc.php 1381 2006-08-15 10:14:56Z elf2000 $
/** /**
* @version $Revision$ * @version $Revision: 1381 $
* @author Tadashi Jokagi <elf2000@users.sourceforge.net> * @author Tadashi Jokagi <elf2000@users.sourceforge.net>
* EN-Revision: 690 * EN-Revision: 690
*/ */

View File

@ -1,4 +1,4 @@
<?php # $Id$ <?php # $Id: lang_ko.inc.php 1381 2006-08-15 10:14:56Z elf2000 $
# Translated by: Wesley Hwang-Chung <wesley96@gmail.com> # Translated by: Wesley Hwang-Chung <wesley96@gmail.com>
# (c) 2005 http://www.tool-box.info/ # (c) 2005 http://www.tool-box.info/

View File

@ -1,7 +1,7 @@
<?php # $Id$ <?php # $Id: lang_pl.inc.php 1548 2006-12-20 18:26:17Z garvinhicking $
/** /**
* @version $Revision$ * @version $Revision: 1548 $
* @author Kostas CoSTa Brzezinski <costa@kofeina.net> * @author Kostas CoSTa Brzezinski <costa@kofeina.net>
* EN-Revision: Revision of lang_en.inc.php * EN-Revision: Revision of lang_en.inc.php
*/ */

View File

@ -1,4 +1,4 @@
<?php # $Id$ <?php # $Id: lang_tn.inc.php 1381 2006-08-15 10:14:56Z elf2000 $
########################################################################## ##########################################################################
# Copyright (c) 2003-2005, Jannis Hermanns (on behalf the Serendipity # # Copyright (c) 2003-2005, Jannis Hermanns (on behalf the Serendipity #
# Developer Team) All rights reserved. See LICENSE file for licensing # # Developer Team) All rights reserved. See LICENSE file for licensing #

View File

@ -1,4 +1,4 @@
<?php # $Id$ <?php # $Id: serendipity_event_karma.php 2778 2011-09-23 12:32:28Z garvinhicking $
@serendipity_plugin_api::load_language(dirname(__FILE__)); @serendipity_plugin_api::load_language(dirname(__FILE__));
@ -42,14 +42,16 @@ class serendipity_event_karma extends serendipity_event
$propbag->add('name', PLUGIN_KARMA_NAME); $propbag->add('name', PLUGIN_KARMA_NAME);
$propbag->add('description', PLUGIN_KARMA_BLAHBLAH); $propbag->add('description', PLUGIN_KARMA_BLAHBLAH);
$propbag->add('stackable', false); $propbag->add('stackable', false);
$propbag->add('author', 'Garvin Hicking, Grischa Brockhaus, Gregor V<EFBFBD>ltz, Judebert'); $propbag->add('author', 'Garvin Hicking, Grischa Brockhaus, Judebert, Gregor Voeltz');
$propbag->add('version', '2.6'); $propbag->add('version', '2.7');
$propbag->add('requirements', array( $propbag->add('requirements', array(
'serendipity' => '0.8', 'serendipity' => '0.8',
'smarty' => '2.6.7', 'smarty' => '2.6.7',
'php' => '4.1.0' 'php' => '4.1.0'
)); ));
$propbag->add('event_hooks', array( $propbag->add('event_hooks', array(
'external_plugin' => true,
'frontend_footer' => true,
'frontend_configure' => true, 'frontend_configure' => true,
'entry_display' => true, 'entry_display' => true,
'css' => true, 'css' => true,
@ -74,9 +76,10 @@ class serendipity_event_karma extends serendipity_event
'min_disp_visits', 'min_disp_visits',
'exits_active', 'exits_active',
'logging', 'logging',
'ajax',
// Appearance options // Appearance options
'appearance_tab', 'appearance_tab',
//--JAM:'alignment', 'alignment',
'rate_with_words', 'rate_with_words',
'textual_msg', 'textual_msg',
'textual_current', 'textual_current',
@ -238,11 +241,17 @@ class serendipity_event_karma extends serendipity_event
$propbag->add('default', 'false'); $propbag->add('default', 'false');
break; break;
/*--JAM: // Log karma votes?
case 'ajax':
$propbag->add('type', 'boolean');
$propbag->add('name', PLUGIN_KARMA_AJAX);
$propbag->add('description', PLUGIN_KARMA_AJAX_BLAHBLAH);
$propbag->add('default', 'false');
break;
// Alignment to use for rating bars // Alignment to use for rating bars
case 'alignment': case 'alignment':
$select = array( $select = array(
//--JAM: 'detect' => PLUGIN_KARMA_ALIGNMENT_DETECT,
'left' => LEFT, 'left' => LEFT,
'center' => CENTER, 'center' => CENTER,
'right' => RIGHT); 'right' => RIGHT);
@ -252,7 +261,7 @@ class serendipity_event_karma extends serendipity_event
$propbag->add('select_values', $select); $propbag->add('select_values', $select);
$propbag->add('default', 'right'); $propbag->add('default', 'right');
break; break;
*/
// Use words for ratings? // Use words for ratings?
case 'rate_with_words': case 'rate_with_words':
$propbag->add('type', 'boolean'); $propbag->add('type', 'boolean');
@ -489,48 +498,29 @@ class serendipity_event_karma extends serendipity_event
return sprintf($karma_exits, $points); return sprintf($karma_exits, $points);
} }
function event_hook($event, &$bag, &$eventData, $addData = null) { function performkarmaVote() {
global $serendipity; global $serendipity;
$hooks = &$bag->get('event_hooks');
if (isset($hooks[$event])) {
// Moved from above: only get image data if we're actually going to do something
$this->set_valid_image_data();
// Get dimensions of image, only if not text-only
if ($this->image_name) {
// Is this a single-image bar, or a single segment?
$ratio = $this->image_width / $this->image_height;
if ($ratio < $max_segment_ratio) {
// This is probably a single segment. Square segments
// will have a ratio of 0.3; long, flat segments won't
// get up to 1.0 unless they're 3 times as wide as they
// are tall; full-bar images with square segments will
// be 1.666; and full-bar images with tall, narrow
// segments will be greater than 1.0 unless they're
// nearly twice as high as they are wide.
$this->image_width = $this->image_width * 5;
}
}
switch($event) {
// Early hook, before any page is displayed
case 'frontend_configure':
// Make sure the karmaVote cookie is set, even if empty <a name="#1" /> // Make sure the karmaVote cookie is set, even if empty <a name="#1" />
if (!isset($serendipity['COOKIE']['karmaVote'])) { if (!isset($serendipity['COOKIE']['karmaVote'])) {
serendipity_setCookie('karmaVote', serialize(array())); serendipity_setCookie('karmaVote', serialize(array()));
} }
// If user didn't vote, we're done. // If user didn't vote, we're done.
// Do we realy need this?
if (!isset($_POST['karmaId'])) {
if (!isset($serendipity['GET']['karmaId']) || !isset($serendipity['GET']['karmaVote'])) { if (!isset($serendipity['GET']['karmaId']) || !isset($serendipity['GET']['karmaVote'])) {
return; return;
} }
}
// Get URL vote data // Get URL vote data
if (isset($_POST['karmaId'])) {
$this->karmaId = (int)$_POST['karmaId'];
$this->karmaVoting = (int)$_POST['karmaVote'];
} else {
$this->karmaId = (int)$serendipity['GET']['karmaId']; $this->karmaId = (int)$serendipity['GET']['karmaId'];
$this->karmaVoting = (int)$serendipity['GET']['karmaVote']; $this->karmaVoting = (int)$serendipity['GET']['karmaVote'];
}
// karmaVote cookie was just set (see name="#1"); this boils down to // karmaVote cookie was just set (see name="#1"); this boils down to
// "if check cookie isn't 1, there's no real cookie". // "if check cookie isn't 1, there's no real cookie".
@ -666,6 +656,157 @@ class serendipity_event_karma extends serendipity_event
$karma[$this->karmaId] = $this->karmaVoting; $karma[$this->karmaId] = $this->karmaVoting;
$this->karmaVote = 'voted'; $this->karmaVote = 'voted';
serendipity_setCookie('karmaVote', serialize($karma)); serendipity_setCookie('karmaVote', serialize($karma));
}
function karmaVoted($myvote,$points,$votes) {
$msg = '<div class="serendipity_karmaSuccess">' . PLUGIN_KARMA_VOTED . '</div>';
if ($this->get_config('rate_with_words', false)) {
$myvote = $this->wordRating($myvote, 1);
}
elseif ($this->image_name != '0') {
$myvote = $this->imageRating($myvote, 1);
}
// Just a current rating bar, if any
$bar = $this->createRatingBar(null, $points, $votes);
return array("myvote" => $myvote, "msg" => $msg, "bar" => $bar);
}
function createkarmaBlock($entryid, $textual_msg, $msg, $bar, $enough_votes, $textual_current, $enough_visits, $textual_visits, $points, $votes) {
$image_class = '';
if ($this->image_name != '0') {
$image_class = ' serendipity_karmaVoting_images';
}
$karma_block = "<div class='serendipity_karmaVoting$image_class'><a id='karma_vote$entryid'></a>";
if ($textual_msg) {
$karma_block .= $msg;
}
$karma_block .= $bar;
if ($enough_votes && $textual_current) {
$curr_msg = $this->get_config('curr_msg', PLUGIN_KARMA_CURRENT);
$karma_block .= '<span class="serendipity_karmaVoting_current">' . $curr_msg . '</span>';
}
if ($enough_visits && $textual_visits) {
$karma_block .= '<span class="serendipity_karmaVoting_visits">' . PLUGIN_KARMA_VISITSCOUNT . '</span>';
}
$karma_block .= "\n</div>\n";
// Adjust rating points
if ($this->get_config('rate_with_words', false)) {
$points = $this->wordRating($points, $votes);
}
elseif ($this->image_name != '0') {
$points = $this->imageRating($points, $votes);
}
return array("karma_block" => $karma_block, "points" => $points);
}
function event_hook($event, &$bag, &$eventData, $addData = null) {
global $serendipity;
$hooks = &$bag->get('event_hooks');
if (isset($hooks[$event])) {
// Moved from above: only get image data if we're actually going to do something
$this->set_valid_image_data();
// Get dimensions of image, only if not text-only
if ($this->image_name) {
// Is this a single-image bar, or a single segment?
$ratio = $this->image_width / $this->image_height;
if ($ratio < $max_segment_ratio) {
// This is probably a single segment. Square segments
// will have a ratio of 0.3; long, flat segments won't
// get up to 1.0 unless they're 3 times as wide as they
// are tall; full-bar images with square segments will
// be 1.666; and full-bar images with tall, narrow
// segments will be greater than 1.0 unless they're
// nearly twice as high as they are wide.
$this->image_width = $this->image_width * 5;
}
}
switch($event) {
//Javascript for ajax functionality
case 'frontend_footer':
if ($this->get_config('ajax') == true) {
?>
<script type="text/javascript">
/*<![CDATA[ */
ajaxloader = new Image();
ajaxloader.src = "<?php echo $serendipity['baseURL']; ?>plugins/serendipity_event_karma/img/ajax-loader.gif";
for (i=1;i<6;i++) {
jQuery('.serendipity_karmaVoting_link'+i).click(function(event) {
event.preventDefault();
karmaId = jQuery(this).attr('href').match(/\[karmaId\]=([0-9]+)/);
vote(jQuery(this).html(),karmaId[1]);
});
}
function vote(karmaVote,karmaId) {
// Send the data using post and put the results in place
jQuery('#karma_vote'+karmaId).parent().children('.serendipity_karmaVoting_links').replaceWith('<div class="serendipity_karmaVoting_links ajaxloader"><img src="<?php echo $serendipity['baseURL']; ?>plugins/serendipity_event_karma/img/ajax-loader.gif" border="0" alt="ajax-loader" /></div>');
jQuery.post("<?php echo $serendipity['baseURL']. $serendipity['permalinkPluginPath'] ?>/karma-ajaxquery", { karmaVote: karmaVote, karmaId: karmaId }, function(data) {
jQuery('#karma_vote'+karmaId).parent().replaceWith(data);
});
}
/* ]]>*/
</script>
<?php
}
// Hook for ajax calls
case 'external_plugin':
$uri_parts = explode('?', str_replace('&amp;', '&', $eventData));
// Try to get request parameters from eventData name
if (!empty($uri_parts[1])) {
$reqs = explode('&', $uri_parts[1]);
foreach($reqs AS $id => $req) {
$val = explode('=', $req);
if (empty($_REQUEST[$val[0]])) {
$_REQUEST[$val[0]] = $val[1];
}
}
}
$parts = explode('_', $uri_parts[0]);
switch($parts[0]) {
case 'karma-ajaxquery':
$this->performkarmaVote();
$q = "SELECT SUM(votes) AS votes, SUM(points) AS points, SUM(visits) AS visits
FROM " . $serendipity['dbPrefix'] . "karma
WHERE entryid = '" . (int)$_POST['karmaId'] . "';";
$sql = serendipity_db_query($q);
$track_clicks = serendipity_db_bool($this->get_config('visits_active', true));
$track_karma = serendipity_db_bool($this->get_config('karma_active', true));
$enough_votes = $track_karma && ($sql[0]['votes'] >= $this->get_config('min_disp_votes', 0));
$enough_visits = $track_clicks && ($sql[0]['visits'] >= $this->get_config('min_disp_visits', 0));
$textual_msg = true;
$textual_current = true;
$textual_visits = true;
if ($this->image_name != '0') {
$textual_msg = $this->get_config('textual_msg', 'true');
$textual_current = $this->get_config('textual_current', 'true');
$textual_visits = $this->get_config('textual_visits', 'true');
}
$temp = $this->karmaVoted((int)$_POST['karmaVote'],$sql[0]['points'],$sql[0]['votes']);
$myvote = $temp['myvote'];
$msg = $temp['msg'];
$bar = $temp['bar'];
$temp = $this->createkarmaBlock((int)$_POST['karmaId'], $textual_msg, $msg, $bar, $enough_votes, $textual_current, $enough_visits, $textual_visits, $sql[0]['points'], $sql[0]['votes']);
$karma_block = $temp['karma_block'];
$points = $temp['points'];
echo sprintf($karma_block, $myvote, $points, $sql[0]['votes'], $sql[0]['visits'], '');
break;
}
return true;
break;
// Early hook, before any page is displayed
case 'frontend_configure':
$this->performkarmaVote();
return true; return true;
break; break;
@ -737,7 +878,7 @@ class serendipity_event_karma extends serendipity_event
} }
if ($align == 'detect') { if ($align == 'detect') {
*/ */
$align = $this->get_config('alignment', 'center'); $align = $this->get_config('alignment');
// Try to let the template take care of it // Try to let the template take care of it
if ($this->image_name == '0') { if ($this->image_name == '0') {
// Text-only rating bar is used // Text-only rating bar is used
@ -842,6 +983,9 @@ EOS;
background: url($img) left; background: url($img) left;
font-size: 0; font-size: 0;
} }
.ajaxloader {
background-image: none;
}
.serendipity_karmaVoting_links { .serendipity_karmaVoting_links {
position: relative; position: relative;
width: {$w}px; width: {$w}px;
@ -1210,17 +1354,10 @@ END_IMG_CSS;
if ($track_karma) { if ($track_karma) {
if (isset($karma[$entryid])) { if (isset($karma[$entryid])) {
// We already voted for this one // We already voted for this one
$msg = $temp = $this->karmaVoted($karma[$entryid],$points,$votes);
'<div class="serendipity_karmaSuccess">' . PLUGIN_KARMA_VOTED . '</div>'; $myvote = $temp['myvote'];
$myvote = $karma[$entryid]; $msg = $temp['msg'];
if ($this->get_config('rate_with_words', false)) { $bar = $temp['bar'];
$myvote = $this->wordRating($myvote, 1);
}
elseif ($this->image_name != '0') {
$myvote = $this->imageRating($myvote, 1);
}
// Just a current rating bar, if any
$bar = $this->createRatingBar(null, $points, $votes);
} elseif ($eventData[$i]['timestamp'] < ($now - $max_karmatime)) { } elseif ($eventData[$i]['timestamp'] < ($now - $max_karmatime)) {
// Too late to vote for this one // Too late to vote for this one
$msg = $msg =
@ -1237,36 +1374,9 @@ END_IMG_CSS;
} }
} }
// Create the karma block // Create the karma block
$image_class = ''; $temp = $this->createkarmaBlock($entryid, $textual_msg, $msg, $bar, $enough_votes, $textual_current, $enough_visits, $textual_visits, $points, $votes);
if ($this->image_name != '0') { $karma_block = $temp['karma_block'];
$image_class = ' serendipity_karmaVoting_images'; $points = $temp['points'];
}
$karma_block =
"<div class='serendipity_karmaVoting$image_class'><a id='karma_vote$entryid'></a>";
if ($textual_msg) {
$karma_block .=
$msg;
}
$karma_block .=
$bar;
if ($enough_votes && $textual_current) {
$curr_msg = $this->get_config('curr_msg', PLUGIN_KARMA_CURRENT);
$karma_block .=
'<span class="serendipity_karmaVoting_current">' . $curr_msg . '</span>';
}
if ($enough_visits && $textual_visits) {
$karma_block .=
'<span class="serendipity_karmaVoting_visits">' . PLUGIN_KARMA_VISITSCOUNT . '</span>';
}
$karma_block .=
"\n</div>\n";
// Adjust rating points
if ($this->get_config('rate_with_words', false)) {
$points = $this->wordRating($points, $votes);
}
elseif ($this->image_name != '0') {
$points = $this->imageRating($points, $votes);
}
/* /*
print("<h3>--DEBUG: Karma block code:</h3>\n<pre>\n"); print("<h3>--DEBUG: Karma block code:</h3>\n<pre>\n");
@ -1281,6 +1391,7 @@ END_IMG_CSS;
$eventData[$i]['properties']['visits'] = $visits; $eventData[$i]['properties']['visits'] = $visits;
$footer .= sprintf($karma_block, $myvote, $points, $votes, $visits, $url); $footer .= sprintf($karma_block, $myvote, $points, $votes, $visits, $url);
} // foreach key in entries } // foreach key in entries
}// End switch on karma voting status }// End switch on karma voting status
return true; return true;
@ -1783,6 +1894,7 @@ function invertSelection() {
$images = array(); $images = array();
$folder = opendir($path); $folder = opendir($path);
while (false !== ($filename = readdir($folder))) { while (false !== ($filename = readdir($folder))) {
if ($filename != "ajax-loader.gif") {
$parts = serendipity_parseFileName($filename); $parts = serendipity_parseFileName($filename);
$img_data = serendipity_getimagesize($path . '/' . $filename); $img_data = serendipity_getimagesize($path . '/' . $filename);
if (!isset($img_data['noimage'])) { if (!isset($img_data['noimage'])) {
@ -1790,6 +1902,7 @@ function invertSelection() {
$images{$filename} = array('fname'=>$filename, 'width'=>$img_data[0], 'height'=>$img_data[1]); $images{$filename} = array('fname'=>$filename, 'width'=>$img_data[0], 'height'=>$img_data[1]);
} }
} }
}
closedir($folder); closedir($folder);
ksort($images); ksort($images);
return $images; return $images;
@ -1988,16 +2101,16 @@ function invertSelection() {
$rating = ((float)$points) / ((float)$votes); $rating = ((float)$points) / ((float)$votes);
// Put it into the language-specific string format, rounding up // Put it into the language-specific string format, rounding up
// I'm mapping invalid cases (rating > 5 and rating < -2) to the extremes // I'm mapping invalid cases (rating > 5 and rating < -2) to the extremes
if ($rating <= -1.5) { if ($rating < -1.5) {
$rating = PLUGIN_KARMA_VOTEPOINT_1; $rating = $this->get_config('rate_vile', PLUGIN_KARMA_VOTEPOINT_1);
} elseif ($rating <= -0.5) { } elseif ($rating < -0.5) {
$rating = PLUGIN_KARMA_VOTEPOINT_2; $rating = $this->get_config('rate_poor', PLUGIN_KARMA_VOTEPOINT_2);
} elseif ($rating <= 0.5) { } elseif ($rating < 0.5) {
$rating = PLUGIN_KARMA_VOTEPOINT_3; $rating = $this->get_config('rate_okay', PLUGIN_KARMA_VOTEPOINT_3);
} elseif ($rating <= 1.5) { } elseif ($rating < 1.5) {
$rating = PLUGIN_KARMA_VOTEPOINT_4; $rating = $this->get_config('rate_good', PLUGIN_KARMA_VOTEPOINT_4);
} else { } else {
$rating = PLUGIN_KARMA_VOTEPOINT_5; $rating = $this->get_config('rate_best', PLUGIN_KARMA_VOTEPOINT_5);
} }
} }
return $rating; return $rating;