1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45: 46: 47: 48: 49: 50: 51: 52: 53: 54: 55: 56: 57: 58: 59: 60: 61: 62: 63: 64: 65: 66: 67: 68: 69: 70: 71: 72: 73: 74: 75: 76: 77: 78: 79: 80: 81: 82: 83: 84: 85: 86: 87: 88: 89: 90: 91: 92: 93: 94: 95: 96: 97: 98: 99: 100: 101: 102: 103: 104: 105: 106: 107: 108: 109: 110: 111: 112: 113: 114: 115: 116: 117: 118: 119: 120: 121: 122: 123: 124: 125: 126: 127: 128: 129: 130: 131: 132: 133: 134: 135: 136: 137: 138: 139: 140: 141: 142: 143: 144: 145: 146: 147: 148: 149: 150: 151: 152: 153: 154: 155: 156: 157: 158: 159: 160: 161: 162: 163: 164: 165: 166: 167: 168: 169: 170: 171: 172: 173: 174: 175: 176: 177: 178: 179: 180: 181: 182: 183: 184: 185: 186: 187: 188: 189: 190: 191: 192: 193: 194: 195: 196: 197: 198: 199: 200: 201: 202: 203: 204: 205: 206: 207: 208: 209: 210: 211: 212: 213: 214: 215: 216: 217: 218: 219: 220: 221: 222: 223: 224: 225: 226: 227: 228: 229: 230: 231: 232: 233: 234: 235: 236: 237: 238: 239: 240: 241: 242: 243: 244: 245: 246: 247: 248: 249: 250: 251: 252: 253: 254: 255: 256: 257: 258: 259: 260: 261: 262: 263: 264: 265: 266: 267: 268: 269: 270: 271: 272: 273: 274: 275: 276: 277: 278: 279: 280: 281: 282: 283: 284: 285: 286: 287: 288: 289: 290: 291: 292: 293: 294: 295: 296: 297: 298: 299: 300: 301: 302: 303: 304: 305: 306: 307: 308: 309: 310: 311: 312: 313: 314: 315: 316: 317: 318: 319: 320: 321: 322: 323: 324: 325: 326: 327: 328: 329: 330: 331: 332: 333: 334: 335: 336: 337: 338: 339: 340: 341: 342: 343: 344: 345: 346: 347: 348: 349: 350: 351: 352: 353: 354: 355: 356: 357: 358: 359: 360: 361: 362: 363: 364: 365: 366: 367: 368: 369: 370: 371: 372: 373: 374: 375: 376: 377: 378: 379: 380: 381: 382: 383: 384: 385: 386: 387: 388: 389: 390: 391: 392: 393: 394: 395: 396: 397: 398: 399: 400: 401: 402: 403: 404: 405: 406: 407: 408: 409: 410: 411: 412: 413: 414: 415: 416: 417: 418: 419: 420: 421: 422: 423: 424: 425: 426: 427: 428: 429: 430: 431: 432: 433: 434:
<?php
if (!defined('OFFSET_PATH')) {
define('OFFSET_PATH', 3);
require_once(dirname(dirname(__FILE__)) . '/functions.php');
if (isset($_GET['action']) && $_GET['action'] == 'clear_rating') {
if (!zp_loggedin(ADMIN_RIGHTS)) {
redirectURL(FULLWEBPATH . '/' . ZENFOLDER . '/admin.php?from=' . currentRelativeURL());
}
require_once(dirname(dirname(__FILE__)) . '/admin-functions.php');
if (session_id() == '') {
if (secureServer()) {
$CookieInfo = session_get_cookie_params();
session_set_cookie_params($CookieInfo['lifetime'], $CookieInfo['path'], $CookieInfo['domain'], TRUE);
}
session_start();
}
XSRFdefender('clear_rating');
query('UPDATE ' . prefix('images') . ' SET total_value=0, total_votes=0, rating=0, used_ips="" ');
query('UPDATE ' . prefix('albums') . ' SET total_value=0, total_votes=0, rating=0, used_ips="" ');
query('UPDATE ' . prefix('news') . ' SET total_value=0, total_votes=0, rating=0, used_ips="" ');
query('UPDATE ' . prefix('pages') . ' SET total_value=0, total_votes=0, rating=0, used_ips="" ');
redirectURL(FULLWEBPATH . '/' . ZENFOLDER . '/admin.php?action=external&msg=' . gettext('All ratings have been set to <em>unrated</em>.'));
}
}
$plugin_is_filter = 5 | ADMIN_PLUGIN | THEME_PLUGIN;
$plugin_description = gettext("Adds several theme functions to enable images, album, news, or pages to be rated by users. ");
$plugin_author = "Stephen Billard (sbillard), Malte Müller (acrylian)";
$plugin_category = gettext('Statistics');
$option_interface = 'jquery_rating';
zp_register_filter('edit_album_utilities', 'jquery_rating::optionVoteStatus');
zp_register_filter('save_album_utilities_data', 'jquery_rating::optionVoteStatusSave');
zp_register_filter('admin_utilities_buttons', 'jquery_rating::rating_purgebutton');
if (getOption('rating_image_individual_control')) {
zp_register_filter('edit_image_utilities', 'jquery_rating::optionVoteStatus');
zp_register_filter('save_image_utilities_data', 'jquery_rating::optionVoteStatusSave');
}
if (in_context(ZP_INDEX)) {
zp_register_filter('theme_head', 'jquery_rating::ratingJS');
}
class jquery_rating {
var $ratingstate;
function __construct() {
setOptionDefault('rating_recast', 1);
setOptionDefault('rating_stars_count', 5);
setOptionDefault('rating_split_stars', 2);
setOptionDefault('rating_status', 3);
setOptionDefault('rating_image_individual_control', 0);
$this->ratingstate = array(gettext('open') => 3, gettext('members & guests') => 2, gettext('members only') => 1, gettext('closed') => 0);
}
function getOptionsSupported() {
$stars = ceil(getOption('rating_stars_count'));
return array(gettext('Voting state') => array(
'key' => 'rating_status',
'type' => OPTION_TYPE_RADIO,
'buttons' => $this->ratingstate,
'desc' => gettext('<em>Enable</em> state of voting.')),
gettext('Stars') => array(
'key' => 'rating_stars_count',
'type' => OPTION_TYPE_TEXTBOX,
'desc' => sprintf(ngettext('Rating will use %u star.', 'Rating will use %u stars.', $stars), $stars)),
gettext('Split stars') => array(
'key' => 'rating_split_stars',
'type' => OPTION_TYPE_RADIO,
'buttons' => array(
gettext('full') => 1,
gettext('half') => 2,
gettext('third') => 3),
'desc' => gettext('Show fractional stars based on rating. May cause performance problems for pages with large numbers of rating elements.')),
gettext('Individual image control') => array(
'key' => 'rating_image_individual_control',
'type' => OPTION_TYPE_CHECKBOX,
'desc' => gettext('Enable to allow voting status control on individual images.')),
gettext('Recast vote') => array(
'key' => 'rating_recast',
'type' => OPTION_TYPE_RADIO,
'buttons' => array(
gettext('No') => 0,
gettext('Show rating') => 1,
gettext('Show previous vote') => 2),
'desc' => gettext('Allow users to change their vote. If Show previous vote is chosen, the stars will reflect the last vote of the viewer. Otherwise they will reflect the current rating.')),
gettext('Disguise IP') => array(
'key' => 'rating_hash_ip',
'type' => OPTION_TYPE_CHECKBOX,
'desc' => gettext('Causes the stored IP addressed to be hashed so as to avoid privacy tracking issues. If not set the IP is anonymized as defined on the general Zenphoto option <em>Anonymize IP</em>.'))
);
}
function handleOption($option, $currentValue) {
}
static function ratingJS() {
$ME = substr(basename(__FILE__), 0, -4);
?>
<script type="text/javascript" src="<?php echo WEBPATH . '/' . ZENFOLDER . '/' . PLUGIN_FOLDER . '/' . $ME; ?>/jquery.MetaData.js"></script>
<script type="text/javascript" src="<?php echo WEBPATH . '/' . ZENFOLDER . '/' . PLUGIN_FOLDER . '/' . $ME; ?>/jquery.rating.js"></script>
<?php
$css = getPlugin('rating/jquery.rating.css', true, true);
?>
<link rel="stylesheet" href="<?php echo pathurlencode($css); ?>" type="text/css" />
<script type="text/javascript">
$.fn.rating.options = {cancel: '<?php echo gettext('retract'); ?>'};
</script>
<?php
}
static function optionVoteStatus($prior, $object, $prefix) {
$me = new jquery_rating();
$currentvalue = $object->get('rating_status');
$output = gettext('Vote Status:') . '<br />' . "\n";
foreach ($me->ratingstate as $text => $value) {
if ($value == $currentvalue) {
$checked = 'checked="checked"';
} else {
$checked = '';
}
$output .= "<label class='checkboxlabel'>\n<input type='radio' name='rating_status" . $prefix . "' id='rating_status" . $value . "-" . $prefix . "' value='" . ($value + 1) . "' " . $checked . "/> " . $text . "\n</label>" . "\n";
}
$output = $prior . "\n" . $output . '<br /clear="all">';
return $output;
}
static function optionVoteStatusSave($object, $prefix) {
if (isset($_POST['rating_status' . $prefix])) {
$object->set('rating_status', sanitize_numeric($_POST['rating_status' . $prefix]) - 1);
}
return $object;
}
static function rating_purgebutton($buttons) {
$buttons[] = array(
'category' => gettext('Database'),
'enable' => true,
'button_text' => gettext('Reset all ratings'),
'formname' => 'clearrating_button',
'action' => FULLWEBPATH .'/'. ZENFOLDER . '/' .PLUGIN_FOLDER . '/rating.php?action=clear_rating',
'icon' => FULLWEBPATH . '/' . ZENFOLDER . '/images/reset.png',
'title' => gettext('Sets all ratings to unrated.'),
'alt' => '',
'hidden' => '<input type="hidden" name="action" value="clear_rating" />',
'rights' => ADMIN_RIGHTS,
'XSRFTag' => 'clear_rating'
);
return $buttons;
}
static function getRatingByIP($ip, $usedips, $ratingAverage) {
global $_rating_current_IPlist;
$rating = 0;
if (empty($_rating_current_IPlist)) {
if (!empty($usedips)) {
$_rating_current_IPlist = getSerializedArray($usedips);
if (array_key_exists($ip, $_rating_current_IPlist)) {
return $_rating_current_IPlist[$ip];
}
}
}
return false;
}
static function getCurrentPageObject() {
global $_zp_gallery_page, $_zp_current_album, $_zp_current_image, $_zp_current_zenpage_news, $_zp_current_zenpage_page;
switch ($_zp_gallery_page) {
case 'album.php':
return $_zp_current_album;
case 'image.php':
return $_zp_current_image;
case 'news.php':
return $_zp_current_zenpage_news;
case 'pages.php':
return $_zp_current_zenpage_page;
default:
return NULL;
}
}
static function id() {
if (getOption('rating_hash_ip')) {
return sha1(getUserIP());
} else {
return getUserIP();
}
}
}
function printRating($vote = 3, $object = NULL, $text = true) {
global $_zp_gallery_page;
if (is_null($object)) {
$object = jquery_rating::getCurrentPageObject();
}
if (!is_object($object)) {
return;
}
$table = $object->table;
$vote = min($vote, getOption('rating_status'), $object->get('rating_status'));
switch ($vote) {
case 1:
if (!zp_loggedin()) {
$vote = 0;
}
break;
case 2:
switch ($_zp_gallery_page) {
case 'album.php':
$album = $object;
$hint = '';
if (!(zp_loggedin() || checkAlbumPassword($album->name))) {
$vote = 0;
}
break;
case 'pages.php':
case 'news.php':
if (!zp_loggedin()) {
$vote = 0;
}
break;
default:
$album = $object->getAlbum();
$hint = '';
if (!(zp_loggedin() || checkAlbumPassword($album->name))) {
$vote = 0;
}
break;
}
}
$stars = ceil(getOption('rating_stars_count'));
$recast = getOption('rating_recast');
$split_stars = max(1, getOption('rating_split_stars'));
$rating = $object->get('rating');
$votes = $object->get('total_votes');
$id = $object->getID();
$unique = '_' . $table . '_' . $id;
$ip = jquery_rating::id();
$oldrating = jquery_rating::getRatingByIP($ip, $object->get('used_ips'), $object->get('rating'));
if ($vote && $recast == 2 && $oldrating) {
$starselector = round($oldrating * $split_stars);
} else {
$starselector = round($rating * $split_stars);
}
$disable = !$vote || ($oldrating && !$recast);
if ($rating > 0) {
$msg = sprintf(ngettext('Rating %2$.1f (%1$u vote)', 'Rating %2$.1f (%1$u votes)', $votes), $votes, $rating);
} else {
$msg = gettext('Not yet rated');
}
if ($split_stars > 1) {
$step = $split_stars;
$split = " {split:$step}";
$step = 1 / $step;
} else {
$split = '';
$step = 1;
}
?>
<form name="star_rating<?php echo $unique; ?>" id="star_rating<?php echo $unique; ?>" action="submit">
<?php
$j = 0;
for ($i = $step; $i <= $stars; $i = $i + $step) {
$v = ceil($i);
$j++;
?>
<input type="radio" class="star<?php echo $split; ?>" name="star_rating-value<?php echo $unique; ?>" value="<?php echo $j; ?>" title="<?php printf(ngettext('%u star', '%u stars', $v), $v); ?>" />
<?php
}
if (!$disable) {
?>
<span id="submit_button<?php echo $unique; ?>">
<input type="button" class="button buttons" value="<?php echo gettext('Submit »'); ?>" onclick="cast<?php echo $unique; ?>();" />
</span>
<?php
}
?>
</form>
<span class="clearall" ></span>
<span class="vote" id="vote<?php echo $unique; ?>" <?php if (!$text) echo 'style="display:none;"'; ?>>
<?php echo $msg; ?>
</span>
<script type="text/javascript">
var recast<?php echo $unique; ?> = <?php printf('%u', $recast && $oldrating); ?>;
$(document).ready(function() {
$('#star_rating<?php echo $unique; ?> :radio.star').rating('select', '<?php echo $starselector; ?>');
<?php
if ($disable) {
?>
$('#star_rating<?php echo $unique; ?> :radio.star').rating('disable');
<?php
}
?>
});
function cast<?php echo $unique; ?>() {
var dataString = $('#star_rating<?php echo $unique; ?>').serialize();
if (dataString || recast<?php echo $unique; ?>) {
<?php
if ($recast) {
?>
if (!dataString) {
dataString = 'star_rating-value<?php echo $unique; ?>=0';
}
<?php
} else {
?>
$('#star_rating<?php echo $unique; ?> :radio.star').rating('disable');
$('#submit_button<?php echo $unique; ?>').hide();
<?php
}
?>
$.ajax({
type: 'POST',
cache: false,
url: '<?php echo WEBPATH . '/' . ZENFOLDER . '/' . PLUGIN_FOLDER . '/' . substr(basename(__FILE__), 0, -4); ?>/update.php',
data: dataString + '&id=<?php echo $id; ?>&table=<?php echo $table; ?>'
});
recast<?php echo $unique; ?> = <?php printf('%u', $recast); ?>;
$('#vote<?php echo $unique; ?>').html('<?php echo gettext('Vote Submitted'); ?>');
} else {
$('#vote<?php echo $unique; ?>').html('<?php echo gettext('nothing to submit'); ?>');
}
}
</script>
<?php
}
function getRating($object = NULL) {
if (is_null($object)) {
$object = jquery_rating::getCurrentPageObject();
if (!$object)
return NULL;
}
return $object->get('rating');
}
?>