1
0
Fork 0
mirror of https://github.com/Yetangitu/ampache synced 2025-10-06 03:49:56 +02:00

new rating hotness, has some bugs will continue to hash them out

This commit is contained in:
Karl 'vollmerk' Vollmer 2006-10-12 01:34:18 +00:00
parent 80d226853c
commit 2a8cbedade
9 changed files with 79 additions and 32 deletions

View file

@ -4,6 +4,8 @@
-------------------------------------------------------------------------- --------------------------------------------------------------------------
v.3.3.3-Alpha1 v.3.3.3-Alpha1
- Added ajax support to ratings, no longer requires a refresh,
hello instant gratification.
- Tweaked Kajax, now accepts an array of elements to replace - Tweaked Kajax, now accepts an array of elements to replace
from a passed xml document. allows for multiple targets from a passed xml document. allows for multiple targets
on a single ajax request on a single ajax request

View file

@ -44,12 +44,7 @@ if (conf('refresh_limit') > 5) {
require_once(conf('prefix') . '/templates/javascript_refresh.inc.php'); require_once(conf('prefix') . '/templates/javascript_refresh.inc.php');
} }
?> ?>
<script language="javascript" type="text/javascript"> <?php show_ajax_js('np_refresh',array('np_data')); ?>
<!--
var np_refresh = new Array(1);
np_refresh[0] = "np_data";
-->
</script>
<div id="np_data"> <div id="np_data">
<?php show_now_playing(); ?> <?php show_now_playing(); ?>
</div> <!-- Close Now Playing Div --> </div> <!-- Close Now Playing Div -->

View file

@ -255,6 +255,13 @@ else {
$user = new user(); $user = new user();
} }
/* Add in some variables for ajax done here because we need the user */
$ajax_info['ajax_url'] = $results['web_path'] . '/server/ajax.server.php';
$ajax_info['ajax_info'] = '&user_id=' . $user->id . '&sessid=' . session_id();
conf($ajax_info);
unset($ajax_info);
// Load gettext mojo // Load gettext mojo
load_gettext(); load_gettext();

View file

@ -1353,6 +1353,23 @@ function xml_from_array($array) {
} // xml_from_array } // xml_from_array
/**
* show_ajax_js
* This displays the javascript array definition needed
* For ajax to know what it should be replacing
*/
function show_ajax_js($name,$array) {
$elements = count($array);
echo "<script type=\"text/javascript\" language=\"javascript\">\n";
echo "<!--\n";
echo "var $name = new Array($elements);\n";
foreach ($array as $key=>$value) {
echo $name . "[$key] = \"$value\";\n";
}
echo "-->\n</script>\n";
} // show_ajax_js
?> ?>

View file

@ -97,6 +97,17 @@ switch ($action) {
$xml_doc = xml_from_array($results); $xml_doc = xml_from_array($results);
echo $xml_doc; echo $xml_doc;
break; break;
case 'set_rating':
ob_start();
$rating = new Rating($_REQUEST['object_id'],$_REQUEST['rating_type']);
$rating->set_rating($_REQUEST['rating']);
show_rating($_REQUEST['object_id'],$_REQUEST['rating_type']);
$key = "rating_" . $_REQUEST['object_id'] . "_" . $_REQUEST['rating_type'];
$results[$key] = ob_get_contents();
ob_end_clean();
$xml_doc = xml_from_array($results);
echo $xml_doc;
break;
default: default:
echo "Default Action"; echo "Default Action";
break; break;

View file

@ -445,7 +445,7 @@ margin-right:5em;
margin:0px; margin:0px;
float: right; float: right;
} }
.star-rating li a{ .star-rating li span{
display:block; display:block;
width:16px; width:16px;
height: 15px; height: 15px;
@ -455,51 +455,51 @@ margin-right:5em;
position: absolute; position: absolute;
padding: 0px; padding: 0px;
} }
.star-rating li a:hover{ .star-rating li span:hover{
background: url(../images/ratings/star_rating.gif) left center; background: url(../images/ratings/star_rating.gif) left center;
z-index: 2; z-index: 2;
left: 0px; left: 0px;
} }
li.zero-stars a:hover { li.zero-stars span:hover {
background: url(../images/ratings/x.gif); background: url(../images/ratings/x.gif);
height: 15px; height: 15px;
left: 80px; left: 80px;
display: block; display: block;
} }
a.zero-stars { span.zero-stars {
background: url(../images/ratings/x_off.gif); background: url(../images/ratings/x_off.gif);
height: 15px; height: 15px;
left: 80px; left: 80px;
display: block; display: block;
} }
a.one-stars{ span.one-stars{
left: 0px; left: 0px;
} }
a.one-stars:hover{ span.one-stars:hover{
width:16px; width:16px;
} }
a.two-stars{ span.two-stars{
left:16px; left:16px;
} }
a.two-stars:hover{ span.two-stars:hover{
width: 32px; width: 32px;
} }
a.three-stars{ span.three-stars{
left: 32px; left: 32px;
} }
a.three-stars:hover{ span.three-stars:hover{
width: 48px; width: 48px;
} }
a.four-stars{ span.four-stars{
left: 48px; left: 48px;
} }
a.four-stars:hover{ span.four-stars:hover{
width: 64px; width: 64px;
} }
a.five-stars{ span.five-stars{
left: 64px; left: 64px;
} }
a.five-stars:hover{ span.five-stars:hover{
width: 80px; width: 80px;
} }
li.current-rating{ li.current-rating{

View file

@ -27,7 +27,6 @@ $web_path = conf('web_path');
// Build array of the table classes we are using // Build array of the table classes we are using
$row_classes = array('even','odd'); $row_classes = array('even','odd');
// Generate variables for the flash ratings
//FIXME: //FIXME:
$album_id = $album->id; $album_id = $album->id;
$artist_id = $album->artist_id; $artist_id = $album->artist_id;
@ -47,7 +46,11 @@ $title = scrub_out($album->name) . ' -- ' . $album->f_artist;
</div> </div>
<div style="display:table-cell;vertical-align:top;"> <div style="display:table-cell;vertical-align:top;">
<?php <?php
if (conf('ratings')) { show_rating($album->id, 'album');} // end if ratings if (conf('ratings')) {
show_ajax_js("r_" . $album->id . "_album",array("rating_" . $album->id . "_album"));
echo "<span style=\"display:inline;\" id=\"rating_" . $album->id . "_album\">";
show_rating($album->id, 'album');} // end if ratings
echo "</span>";
echo "<br />\n"; echo "<br />\n";
?> ?>
<strong><?php echo _('Actions'); ?>:</strong><br /> <strong><?php echo _('Actions'); ?>:</strong><br />

View file

@ -21,17 +21,18 @@
/* Create some variables we are going to need */ /* Create some variables we are going to need */
$web_path = conf('web_path'); $web_path = conf('web_path');
$base_url = $web_path . '/ratings.php?action=set_rating&amp;mode=' . conf('flash') . '&amp;rating_type=' . $rating->type . '&amp;object_id=' . $rating->id . '&amp;username=' . $GLOBALS['user']->username; $base_url = conf('ajax_url') . '?action=set_rating&rating_type=' . $rating->type . '&object_id=' . $rating->id . conf('ajax_info');
//set the background to no stars //set the background to no stars
echo "<ul class=\"star-rating\">\n"; echo "<ul class=\"star-rating\">\n";
/* Handle the "Not rated" possibility */ /* Handle the "Not rated" possibility */
if ($rating->rating == '-1') { if ($rating->rating == '-1') {
echo "<li class=\"zero-stars\"><a href=\"" . $base_url . "&amp;rating=-1\" title=\"don't play\" class=\"zero-stars\">-1</a></li>\n"; echo "<li class=\"zero-stars\"><span onclick=\"ajaxPut('" . $base_url . "&rating=-1',r_" . $rating->id . "_" . $rating->type . ");return true;\" title=\"don't play\" class=\"zero-stars\"></span></li>\n";
} }
else { else {
echo "<li class=\"zero-stars\"><a href=\"" . $base_url . "&amp;rating=-1\" title=\"remove rating\" class=\"zero-stars\">-1</a></li>\n"; echo "<li class=\"zero-stars\"><span onclick=\"ajaxPut('" . $base_url . "&rating=-1',r_" . $rating->id . "_" . $rating->type . ");return true;\" title=\"remove rating\" class=\"zero-stars\"></span></li>\n";
} }
// decide width of rating. image is 16 px wide // decide width of rating. image is 16 px wide
$width = $rating->rating*16; $width = $rating->rating*16;
@ -45,11 +46,21 @@ if ($rating->rating <= 0) {
else echo "$rating->rating of 5</li>\n"; else echo "$rating->rating of 5</li>\n";
//it did not like my "1-star", "2-star" ... css styles, and I changed it to this after I realized star1... would have worked :\ //it did not like my "1-star", "2-star" ... css styles, and I changed it to this after I realized star1... would have worked :\
echo "<li> <a href=\"" . $base_url . "&amp;rating=1\" class=\"one-stars\" title=\"1 out of 5\">$score</a></li>\n";
echo "<li> <a href=\"" . $base_url . "&amp;rating=2\" class=\"two-stars\" title=\"2 out of 5\">$score</a></li>\n";
echo "<li> <a href=\"" . $base_url . "&amp;rating=3\" class=\"three-stars\" title=\"3 out of 5\">$score</a></li>\n";
echo "<li> <a href=\"" . $base_url . "&amp;rating=4\" class=\"four-stars\" title=\"4 out of 5\">$score</a></li>\n";
echo "<li> <a href=\"" . $base_url . "&amp;rating=5\" class=\"five-stars\" title=\"5 out of 5\">$score</a></li>\n";
echo "</ul>";
?> ?>
<li>
<span onclick="ajaxPut('<?php echo $base_url; ?>&rating=1',r_<?php echo $rating->id; ?>_<?php echo $rating->type; ?>);return true;" class="one-stars" title="1 <?php echo _('out of'); ?> 5"></span>
</li>
<li>
<span onclick="ajaxPut('<?php echo $base_url; ?>&rating=2',r_<?php echo $rating->id; ?>_<?php echo $rating->type; ?>);return true;" class="two-stars" title="2 <?php echo _('out of'); ?> 5"></span>
</li>
<li>
<span onclick="ajaxPut('<?php echo $base_url; ?>&rating=3',r_<?php echo $rating->id; ?>_<?php echo $rating->type; ?>);return true;" class="three-stars" title="3 <?php echo _('out of'); ?> 5"></span>
</li>
<li>
<span onclick="ajaxPut('<?php echo $base_url; ?>&rating=4',r_<?php echo $rating->id; ?>_<?php echo $rating->type; ?>);return true;" class="four-stars" title="4 <?php echo _('out of'); ?> 5"></span>
</li>
<li>
<span onclick="ajaxPut('<?php echo $base_url; ?>&rating=5',r_<?php echo $rating->id; ?>_<?php echo $rating->type; ?>);return true;" class="five-stars" title="5 <?php echo _('out of'); ?> 5"></span>
</li>
</ul>

View file

@ -145,7 +145,8 @@ foreach ($song_ids as $song_id) {
<?php } ?> <?php } ?>
</td> </td>
<?php if(conf('ratings')) { ?> <?php if(conf('ratings')) { ?>
<td> <td id="rating_<?php echo $song->id; ?>_song">
<?php show_ajax_js("r_" . $song->id . "_song",array("rating_" . $song->id . "_song")); ?>
<?php show_rating($song->id,'song'); ?> <?php show_rating($song->id,'song'); ?>
</td> </td>
<?php } ?> <?php } ?>