summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rwxr-xr-xdocs/CHANGELOG6
-rw-r--r--lib/class/democratic.class.php97
-rw-r--r--lib/class/tmpplaylist.class.php12
-rw-r--r--lib/ui.lib.php13
-rw-r--r--play/index.php6
-rw-r--r--register.php32
-rw-r--r--templates/install.css11
-rw-r--r--templates/rightbar.inc.php12
-rw-r--r--templates/show_user_registration.inc.php215
9 files changed, 209 insertions, 195 deletions
diff --git a/docs/CHANGELOG b/docs/CHANGELOG
index 557d81ae..51a02275 100755
--- a/docs/CHANGELOG
+++ b/docs/CHANGELOG
@@ -4,6 +4,12 @@
--------------------------------------------------------------------------
v.3.4-Alpha4
+ - Limited Rightbar to only 100 items, adds last row indicating any
+ additional items on playlist. Prevents Firefox crash if you
+ add many thousands of items to a single active playlist
+ - Corrected Sorting of Democratic Play votes, sort order is now
+ # of votes then oldest vote first so new votes sort to
+ the bottom
- Fixed sending URLs directly to MPD
- Fixed a problem with automatic downsampling which was referencing
a now non-existant function
diff --git a/lib/class/democratic.class.php b/lib/class/democratic.class.php
index 5b477f80..bc9429fb 100644
--- a/lib/class/democratic.class.php
+++ b/lib/class/democratic.class.php
@@ -75,27 +75,64 @@ class Democratic extends tmpPlaylist {
* This returns an array of all object_ids currently in this tmpPlaylist. This
* has gotten a little more complicated because of type, the values are an array
* 0 being ID 1 being TYPE
+ * FIXME: This is too complex, it makes my brain hurt
+ * [VOTE COUNT]
+ * [DATE OF NEWEST VOTE]
+ * [ROW ID]
+ * [OBJECT_ID]
+ * [OBJECT_TYPE]
+ *
+ * Sorting does the following
+ * sort largest VOTE COUNT to top
+ * sort smallest DATE OF NEWEST VOTE]
*/
public function get_items() {
- $order = "GROUP BY tmp_playlist_data.id ORDER BY `count` DESC, user_vote.date ASC";
- $vote_select = ", COUNT(user_vote.user) AS `count`";
- $vote_join = "INNER JOIN user_vote ON user_vote.object_id=tmp_playlist_data.id";
+ $order = "ORDER BY `user_vote`.`date` ASC";
+ $vote_join = "INNER JOIN `user_vote` ON `user_vote`.`object_id`=`tmp_playlist_data`.`id`";
/* Select all objects from this playlist */
- $sql = "SELECT tmp_playlist_data.object_type, tmp_playlist_data.id, tmp_playlist_data.object_id $vote_select " .
- "FROM tmp_playlist_data $vote_join " .
- "WHERE tmp_playlist_data.tmp_playlist='" . Dba::escape($this->id) . "' $order";
+ $sql = "SELECT `tmp_playlist_data`.`id`,`tmp_playlist_data`.`object_type`, `user_vote`.`date`, `tmp_playlist_data`.`object_id` " .
+ "FROM `tmp_playlist_data` $vote_join " .
+ "WHERE `tmp_playlist_data`.`tmp_playlist`='" . Dba::escape($this->id) . "' $order";
$db_results = Dba::query($sql);
/* Define the array */
$items = array();
+ $votes = array();
+ // Itterate and build the sortable array
while ($results = Dba::fetch_assoc($db_results)) {
- $key = $results['id'];
- $items[$key] = array($results['object_id'],$results['object_type']);
+
+ // First build a variable that holds the number of votes for an object
+ $name = 'vc_' . $results['object_id'];
+
+ // Check if the vote is older then our current vote for this object
+ if ($votes[$results['object_id']] < $results['date'] OR !isset($votes[$results['object_id']])) {
+ $votes[$results['object_id']] = $results['date'];
+ }
+
+
+ // Append oen to the vote
+ ${$name}++;
+ $primary_key = ${$name};
+ $secondary_key = $votes[$results['object_id']];
+ $items[$primary_key][$secondary_key][$results['id']] = array($results['object_id'],$results['object_type'],$results['id']);
}
- return $items;
+ // Sort highest voted stuff to the top
+ krsort($items);
+
+ // re-collapse the array
+ foreach ($items as $vote_count=>$date_array) {
+ ksort($date_array);
+ foreach ($date_array as $object_array) {
+ foreach ($object_array as $key=>$sorted_array) {
+ $sorted_items[$key] = $sorted_array;
+ }
+ }
+ }
+
+ return $sorted_items;
} // get_items
@@ -119,27 +156,22 @@ class Democratic extends tmpPlaylist {
*/
public function get_next_object($offset='') {
- $tmp_id = Dba::escape($this->id);
-
- // Format the limit statement
- $limit_sql = $offset ? intval($offset) . ',1' : '1';
-
- /* Add conditions for voting */
- $vote_select = ", COUNT(user_vote.user) AS `count`";
- $order = " GROUP BY tmp_playlist_data.id ORDER BY `count` DESC, user_vote.date ASC";
- $vote_join = "INNER JOIN user_vote ON user_vote.object_id=tmp_playlist_data.id";
+ $offset = $offset ? intval($offset) : '0';
- $sql = "SELECT tmp_playlist_data.object_id $vote_select FROM tmp_playlist_data $vote_join " .
- "WHERE tmp_playlist_data.tmp_playlist = '$tmp_id' $order LIMIT $limit_sql";
- $db_results = Dba::query($sql);
+ // We have to get all because of the pysco sorting
+ $items = self::get_items();
- $results = Dba::fetch_assoc($db_results);
+ if (count($items)) {
+ $array = array_slice($items,$offset,1);
+ $item = array_shift($array);
+ $results['object_id'] = $item['0'];
+ }
/* If nothing was found and this is a voting playlist then get from base_playlist */
- if (!$results) {
+ if (!$results['object_id']) {
/* Check for a playlist */
- if ($this->base_playlist != '0') {
+ if ($this->base_playlist) {
/* We need to pull a random one from the base_playlist */
$base_playlist = new Playlist($this->base_playlist);
$data = $base_playlist->get_random_items(1);
@@ -296,6 +328,23 @@ class Democratic extends tmpPlaylist {
} // delete_votes
+ /**
+ * prune_tracks
+ * This replaces the normal prune tracks and correctly removes the votes
+ * as well
+ */
+ public static function prune_tracks() {
+
+ // This deletes data without votes, if it's a voting democratic playlist
+ $sql = "DELETE FROM tmp_playlist_data USING tmp_playlist_data " .
+ "LEFT JOIN user_vote ON tmp_playlist_data.id=user_vote.object_id " .
+ "LEFT JOIN tmp_playlist ON tmp_playlist.id=tmp_playlist.tmp_playlist " .
+ "WHERE user_vote.object_id IS NULL AND tmp_playlist.type = 'vote'";
+ $db_results = Dba::query($sql);
+
+ return true;
+
+ } // prune_tracks
} // Democratic class
?>
diff --git a/lib/class/tmpplaylist.class.php b/lib/class/tmpplaylist.class.php
index 9e0c5a3a..ec3a9962 100644
--- a/lib/class/tmpplaylist.class.php
+++ b/lib/class/tmpplaylist.class.php
@@ -288,18 +288,6 @@ class tmpPlaylist {
"WHERE tmp_playlist.id IS NULL";
$db_results = Dba::query($sql);
- // If we don't allow it, don't waste the time
- if (!Config::get('allow_democratic_playback')) { return true; }
-
- // This deletes data without votes, if it's a voting democratic playlist
- $sql = "DELETE FROM tmp_playlist_data USING tmp_playlist_data " .
- "LEFT JOIN user_vote ON tmp_playlist_data.id=user_vote.object_id " .
- "LEFT JOIN tmp_playlist ON tmp_playlist.id=tmp_playlist.tmp_playlist " .
- "WHERE user_vote.object_id IS NULL AND tmp_playlist.type = 'vote'";
- $db_results = Dba::query($sql);
-
- return true;
-
} // prune_tracks
/**
diff --git a/lib/ui.lib.php b/lib/ui.lib.php
index f8696655..2f50256b 100644
--- a/lib/ui.lib.php
+++ b/lib/ui.lib.php
@@ -225,19 +225,6 @@ function show_footer() {
} // show_footer
/**
- * show_user_registration
- * this function is called for a new user
- * registration
- * @author Terry
- * @todo Fix so that it recieves an array of values for the user reg rather than seperate
- */
-function show_user_registration ($values=array()) {
-
- require (conf('prefix') . "/templates/show_user_registration.inc.php");
-
-} // show_user_registration
-
-/**
* show_play_selected
* this shows the playselected/add to playlist
* box, which includes a little javascript
diff --git a/play/index.php b/play/index.php
index 2030c3ff..f97c1e07 100644
--- a/play/index.php
+++ b/play/index.php
@@ -298,8 +298,10 @@ if ($bytesStreamed > $minBytesStreamed) {
/* If this is a voting tmp playlist remove the entry */
if ($demo_id) {
$row_id = $democratic->get_uid_from_object_id($song_id,'song');
- debug_event('Democratic','Removing Song Entry from Democratic Playlist','1');
- $democratic->delete_votes($row_id);
+ if ($row_id) {
+ debug_event('Democratic','Removing ' . $song->title . ' from Democratic Playlist','1');
+ $democratic->delete_votes($row_id);
+ }
} // if tmp_playlist
/* Set the Song as Played if it isn't already */
diff --git a/register.php b/register.php
index e40da39b..8b19e686 100644
--- a/register.php
+++ b/register.php
@@ -1,7 +1,7 @@
<?php
/*
- Copyright (c) 2001 - 2006 Ampache.org
+ Copyright (c) 2001 - 2007 Ampache.org
All rights reserved.
This program is free software; you can redistribute it and/or
@@ -19,38 +19,27 @@
*/
-/*!
- @header User Registration page
- @discussion this page handles new user
- registration, this is by default disabled
- (it allows public reg)
-
-*/
-
define('NO_SESSION','1');
-require_once ('lib/init.php');
-
-/* Load the preferences */
-init_preferences();
-
-$web_path = conf('web_path');
+require_once 'lib/init.php';
/* Check Perms */
-if (!conf('allow_public_registration') || conf('demo_mode')) {
+if (!Config::get('allow_public_registration') || Config::get('demo_mode')) {
+ debug_event('DENIED','Error Attempted registration','1');
access_denied();
+ exit();
}
/**
* These are only needed for this page so they aren't included in init.php
* this is for email validation and the cool little graphic
*/
-require_once (conf('prefix') . '/modules/validatemail/validateEmailFormat.php');
-require_once (conf('prefix') . '/modules/validatemail/validateEmail.php');
+require_once Config::get('prefix') . '/modules/validatemail/validateEmailFormat.php';
+require_once Config::get('prefix') . '/modules/validatemail/validateEmail.php';
/* Don't even include it if we aren't going to use it */
-if (conf('captcha_public_reg')) {
+if (Config::get('captcha_public_reg')) {
define ("CAPTCHA_INVERSE", 1);
- require_once (conf('prefix') . '/modules/captcha/captcha.php');
+ require_once Config::get('prefix') . '/modules/captcha/captcha.php';
}
@@ -175,8 +164,7 @@ switch ($action) {
break;
case 'show_add_user':
default:
- $values = array('type'=>"new_user");
- show_user_registration($values);
+ require_once Config::get('prefix') . '/templates/show_user_registration.inc.php';
break;
} // end switch on action
?>
diff --git a/templates/install.css b/templates/install.css
index c9944ef4..9ee3ab13 100644
--- a/templates/install.css
+++ b/templates/install.css
@@ -7,6 +7,13 @@ body {
background: #FFFFFF url(../images/top_bg.jpg) repeat-x top left;
}
+h3 {
+ text-align:left;
+ border-bottom: 1px dotted #cccccc;
+ padding-left: 10px;
+}
+
+
/* Header */
#header {
width: 90%;
@@ -103,8 +110,8 @@ margin:10px 10 10px 10px;
/* Bottom */
#bottom {
- border-top: 1px dotted #cccccc;
- margin-top: 10px;
+ border-top: 1px dotted #cccccc;
+ margin-top: 10px;
margin-bottom: 10px;
padding:5px;
}
diff --git a/templates/rightbar.inc.php b/templates/rightbar.inc.php
index 85d935c5..bf1322e1 100644
--- a/templates/rightbar.inc.php
+++ b/templates/rightbar.inc.php
@@ -75,6 +75,13 @@
<?php
//FIXME :: this feels kludgy
$objects = $GLOBALS['user']->playlist->get_items();
+
+ // Limit the number of objects we show here
+ if (count($objects) > 100) {
+ $truncated = (count($objects) - 100);
+ $objects = array_slice($objects,0,100);
+ }
+
foreach ($objects as $uid=>$object_data) {
if ($object_data['1'] == 'radio' || $object_data['1'] == 'song') {
$object = new $object_data['1']($object_data['0']);
@@ -92,6 +99,11 @@
<?php } if (!count($objects)) { ?>
<li class="error"><?php echo _('Not Enough Data'); ?></li>
<?php } ?>
+<?php if ($truncated) { ?>
+ <li class="<?php echo flip_class(); ?>">
+ <?php echo $truncated . ' ' . _('More'); ?>...
+ </li>
+<?php } ?>
</ul>
diff --git a/templates/show_user_registration.inc.php b/templates/show_user_registration.inc.php
index d150c2da..29cf8f9f 100644
--- a/templates/show_user_registration.inc.php
+++ b/templates/show_user_registration.inc.php
@@ -1,13 +1,13 @@
<?php
/*
- Copyright (c) 2001 - 2006 Ampache.org
+ Copyright (c) 2001 - 2007 Ampache.org
All rights reserved.
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
- as published by the Free Software Foundation; either version 2
- of the License, or (at your option) any later version.
+ as published by the Free Software Foundation; version 2
+ of the License.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
@@ -19,30 +19,29 @@
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
-$htmllang = str_replace("_","-",conf('lang'));
+$htmllang = str_replace("_","-",Config::get('lang'));
+$web_path = Config::get('web_path');
?>
-
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="<?php echo $htmllang; ?>" lang="<?php echo $htmllang; ?>">
<head>
-<link rel="shortcut icon" href="<?php echo conf('web_path'); ?>/favicon.ico" />
-<meta http-equiv="Content-Type" content="text/html; charset=<?php echo conf('site_charset'); ?>" />
-<link rel="stylesheet" href="<?php echo conf('web_path'); ?><?php echo conf('theme_path'); ?>/templates/default.css" type="text/css" />
-<title><?php echo conf('site_title'); ?> - <?php echo $location['title']; ?></title>
+<meta http-equiv="Content-Type" content="text/html; charset=<?php echo Config::get('site_charset'); ?>" />
+<title><?php echo Config::get('site_title'); ?> - <?php echo _('Registration'); ?></title>
+</head>
+<body bgcolor="#f0f0f0">
+<link rel="stylesheet" href="<?php echo Config::get('web_path'); ?>/templates/install.css" type="text/css" media="screen" />
+<link rel="shortcut icon" href="<?php echo Config::get('web_path'); ?>/favicon.ico" />
+<div id="header">
+<h1><?php echo Config::get('site_title'); ?></h1>
+<?php echo _('Registration'); ?>...
+</div>
</head>
<body>
-<script src="<?php echo conf('web_path'); ?>/lib/javascript-base.js" language="javascript" type="text/javascript"></script>
+<script src="<?php echo $web_path; ?>/lib/javascript-base.js" language="javascript" type="text/javascript"></script>
+<script src="<?php echo $web_path; ?>/modules/kajax/ajax.js" language="javascript" type="text/javascript"></script>
+<script src="<?php echo $web_path; ?>/modules/prototype/prototype.js" language="javascript" type="text/javascript"></script>
<div id="maincontainer">
-<!-- This is the topbar row -->
-<div id="topbar">
- <div align="center">
- <a href="http://www.ampache.org/">
- <img src="<?php echo conf('web_path'); ?><?php echo conf('theme_path'); ?>/images/ampache.gif" title="Ampache: For the love of music" alt="Ampache: For the love of music" />
- </a>
- </div>
-</div>
-<br /><br />
<?php
$action = scrub_in($_REQUEST['action']);
@@ -50,119 +49,95 @@ $fullname = scrub_in($_REQUEST['fullname']);
$username = scrub_in($_REQUEST['username']);
$email = scrub_in($_REQUEST['email']);
?>
-<div align="center">
-<?php show_box_top(_('Ampache New User Registration')); ?>
-<form name="update_user" method="post" action="<?php echo conf('web_path'); ?>/register.php" enctype="multipart/form-data">
-<table width='700px' cellpadding='0' cellspacing='0'>
+<form name="update_user" method="post" action="<?php echo $web_path; ?>/register.php" enctype="multipart/form-data">
<?php
/* If we should show the user agreement */
-if(conf('user_agreement')){ ?>
- <tr>
- <td height="15px">
- </td>
- </tr>
+if (Config::get('user_agreement')) { ?>
+<h3><?php echo _('User Agreement'); ?></h3>
+<table cellpadding="2" cellspacing="0">
+<tr>
+ <td>
+ <?php show_registration_agreement(); ?>
+ </td>
+</tr>
+<tr>
+ <td>
+ <input type='checkbox' name='accept_agreement'> <?php echo _('I Accept'); ?>
+ <?php $GLOBALS['error']->print_error('user_agreement'); ?>
+ </td>
+</tr>
+</table>
+<?php } // end if(conf('user_agreement')) ?>
+<h3><?php echo _('User Information'); ?></h3>
+<table cellpadding="0" cellspacing="0">
+<tr>
+ <td align='right'>
+ <?php echo _('Username'); ?>:
+ </td>
+ <td>
+ <font color='red'>*</font> <input type='text' name='username' id='username' value='<?php echo scrub_out($username); ?>' />
+ <?php Error::display('username'); ?>
+ <?php Error::display('duplicate_user'); ?>
+ </td>
+</tr>
+<tr>
+ <td align='right'>
+ <?php echo _('Full Name'); ?>:
+ </td>
+ <td>
+ <font color='red'>*</font> <input type='text' name='fullname' id='fullname' value='<?php echo scrub_out($fullname); ?>' />
+ <?php Error::display('fullname'); ?>
+ </td>
+</tr>
+<tr>
+ <td align='right'>
+ <?php echo _('E-mail'); ?>:
+ </td>
+ <td>
+ <font color='red'>*</font> <input type='text' name='email' id='email' value='<?php echo scrub_out($email); ?>' />
+ <?php Error::display('email'); ?>
+ </td>
+</tr>
+<tr>
+ <td align='right'>
+ <?php echo _('Password'); ?>:
+ </td>
+ <td>
+ <font color='red'>*</font> <input type='password' name='password_1' id='password_1' />
+ <?php Error::display('password'); ?>
+ </td>
+</tr>
+<tr>
+ <td align='right'>
+ <?php echo _('Confirm Password'); ?>:
+ </td>
+ <td>
+ <font color='red'>*</font> <input type='password' name='password_2' id='password_2' />
+ </td>
+</tr>
+<?php if (Config::get('captcha_public_reg')) { ?>
<tr>
- <td>
- <table cellpadding="2" cellspacing="0">
- <tr>
- <td>
- <span class="box-title"><?php echo _('User Agreement'); ?></span>
- </td>
- </tr>
- <tr>
- <td>
- <?php show_registration_agreement(); ?>
- </td>
- </tr>
- <tr>
- <td>
- <input type='checkbox' name='accept_agreement'> <?php echo _('I Accept'); ?>
- <?php $GLOBALS['error']->print_error('user_agreement'); ?>
- </td>
- </tr>
- </table>
- </td>
+ <?php echo captcha::form(); ?>
+ <?php Error::display('captcha'); ?>
</tr>
-<?php } // end if(conf('user_agreement')) ?>
+<?php } ?>
<tr>
- <td height='15'>
+ <td colspan='2' align='center' height='20'>
+ <span style="color:red;">* Required fields</span>
</td>
</tr>
<tr>
- <td valign="top">
- <p class="box-title"><?php echo _('User Information'); ?></p>
-
- <table width='99%' cellpadding='0' cellspacing='0'>
- <tr>
- <td align='right'>
- <?php echo _('Username'); ?>:
- </td>
- <td>
- <font color='red'>*</font> <input type='text' name='username' id='username' value='<?php echo scrub_out($username); ?>' />
- <?php $GLOBALS['error']->print_error('username'); ?>
- <?php $GLOBALS['error']->print_error('duplicate_user'); ?>
- </td>
- </tr>
- <tr>
- <td align='right'>
- <?php echo _('Full Name'); ?>:
- </td>
- <td>
- <font color='red'>*</font> <input type='text' name='fullname' id='fullname' value='<?php echo scrub_out($fullname); ?>' />
- <?php $GLOBALS['error']->print_error('fullname'); ?>
- </td>
- </tr>
- <tr>
- <td align='right'>
- <?php echo _('E-mail'); ?>:
- </td>
- <td>
- <font color='red'>*</font> <input type='text' name='email' id='email' value='<?php echo scrub_out($email); ?>' />
- <?php $GLOBALS['error']->print_error('email'); ?>
- </td>
- </tr>
- <tr>
- <td align='right'>
- <?php echo _('Password'); ?>:
- </td>
- <td>
- <font color='red'>*</font> <input type='password' name='password_1' id='password_1' />
- <?php $GLOBALS['error']->print_error('password'); ?>
- </td>
- </tr>
- <tr>
- <td align='right'>
- <?php echo _('Confirm Password'); ?>:
- </td>
- <td>
- <font color='red'>*</font> <input type='password' name='password_2' id='password_2' />
- </td>
- </tr>
- <?php if (conf('captcha_public_reg')) { ?>
- <tr>
- <?php echo captcha::form(); ?>
- <?php $GLOBALS['error']->print_error('captcha'); ?>
- </tr>
- <?php } ?>
- <tr>
- <td colspan='2' align='center' height='20'>
- <font color='red'>*</font>Required fields
- </td>
- </tr>
- <tr>
- <td colspan='2' align='center' height='50'>
- <input type="hidden" name="action" value="add_user" />
- <input type='reset' name='clear_info' id='clear_info' value='<?php echo _('Clear Info'); ?>' />
- <input type='submit' name='submit_registration' id='submit_registration' value='<?php echo _('Register User'); ?>' />
- </td>
- </tr>
- </table>
+ <td colspan='2' align='center' height='50'>
+ <input type="hidden" name="action" value="add_user" />
+ <input type='submit' name='submit_registration' id='submit_registration' value='<?php echo _('Register User'); ?>' />
</td>
</tr>
</table>
</form>
-<?php show_box_bottom(); ?>
-</div>
</div><!--end <div>id="maincontainer-->
+<div id="bottom">
+<p><b>Ampache</b><br />
+Pour l'Amour de la Musique.</p>
+</div>
</body>
</html>