summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/album.lib.php8
-rw-r--r--lib/class/playlist.class.php100
-rw-r--r--lib/class/update.class.php58
-rw-r--r--lib/install.php2
-rw-r--r--lib/preferences.php2
5 files changed, 107 insertions, 63 deletions
diff --git a/lib/album.lib.php b/lib/album.lib.php
index 8812cb4c..e04d494c 100644
--- a/lib/album.lib.php
+++ b/lib/album.lib.php
@@ -90,6 +90,14 @@ function get_image_from_source($data) {
* this is used by the index to return some 'potential' albums to play
*/
function get_random_albums($count=6) {
+
+ // Make sure that we have anything to pick from
+ $sql = "SELECT `id` FROM `album` LIMIT 7";
+ $db_results = Dba::query($sql);
+
+ $rows = Dba::num_rows($db_results);
+ if ($rows < 7) { return false; }
+
// There's a slight chance with this logic that the number of albums
// returned will be less than the number requested if the id's for the
// albums have signifigant gaps, but the speed increase is probably
diff --git a/lib/class/playlist.class.php b/lib/class/playlist.class.php
index 863a28a5..493e335a 100644
--- a/lib/class/playlist.class.php
+++ b/lib/class/playlist.class.php
@@ -30,6 +30,7 @@ class Playlist {
public $name;
public $user;
public $type;
+ public $genre;
public $date;
/* Generated Elements */
@@ -74,7 +75,12 @@ class Playlist {
*/
public function format() {
- $this->f_link = '<a href="' . Config::get('web_path') . '/playlist.php?action=show_playlist&amp;playlist_id=' . $this->id . '">' . $this->name . '</a>';
+ $this->f_name = truncate_with_ellipsis($this->name,Config::get('ellipse_threshold_title'));
+ $this->f_link = '<a href="' . Config::get('web_path') . '/playlist.php?action=show_playlist&amp;playlist_id=' . $this->id . '">' . $this->f_name . '</a>';
+
+ $client = new User($this->user);
+
+ $this->f_user = $client->fullname;
} // format
@@ -102,12 +108,16 @@ class Playlist {
$results = array();
- $sql = "SELECT * FROM `playlist_data` WHERE `playlist`='" . Dba::escape($this->id) . "' ORDER BY `track`";
+ $sql = "SELECT `object_id`,`object_type`,`dynamic_song` FROM `playlist_data` WHERE `playlist`='" . Dba::escape($this->id) . "' ORDER BY `track`";
$db_results = Dba::query($sql);
while ($row = Dba::fetch_assoc($db_results)) {
- $key = $row['id'];
- $results[$key] = $row['song'];
+
+ if (strlen($row['dynamic_song'])) {
+ // Do something here FIXME!
+ }
+
+ $results[] = array('type'=>$row['object_type'],'object_id'=>$row['object_id']);
} // end while
return $results;
@@ -115,85 +125,56 @@ class Playlist {
} // get_items
/**
- * get_songs
- * This returns an array of song_ids accounting for any dyn_song entries this playlist
- * may have. This is what should be called when trying to generate a m3u or other playlist
+ * get_random_items
+ * This is the same as before but we randomize the buggers!
*/
- function get_songs($array=array()) {
-
- $results = array();
-
- /* If we've passed in some songs */
- if (count($array)) {
-
- foreach ($array as $data) {
-
- $sql = "SELECT song,dyn_song FROM playlist_data WHERE id='" . sql_escape($data) . "' ORDER BY track";
- $db_results = mysql_query($sql, dbh());
+ public function get_random_items() {
- $r = mysql_fetch_assoc($db_results);
- if ($r['dyn_song']) {
- $array = $this->get_dyn_songs($r['dyn_song']);
- $results = array_merge($array,$results);
- }
- else {
- $results[] = $r['song'];
- }
-
- } // end foreach songs
-
- return $results;
+ $results = array();
- } // end if we were passed some data
+ $sql = "SELECT `object_id`,`object_type`,`dynamic_song` FROM `playlist_data` " .
+ "WHERE `playlist`='" . Dba::escape($this->id) . "' ORDER BY RAND()";
+ $db_results = Dba::query($sql);
- $sql = "SELECT * FROM playlist_data WHERE playlist='" . sql_escape($this->id) . "' ORDER BY track";
- $db_results = mysql_query($sql, dbh());
+ while ($row = Dba::fetch_assoc($db_results)) {
- while ($r = mysql_fetch_assoc($db_results)) {
- if ($r['dyn_song']) {
- $array = $this->get_dyn_songs($r['dyn_song']);
- $results = array_merge($array,$results);
- }
- else {
- $results[] = $r['song'];
+ if (strlen($row['dynamic_song'])) {
+ // Do something here FIXME!!!
}
- } // end while
+ $results[] = array('type'=>$row['object_type'],'object_id'=>$row['object_id']);
+ } // end while
- return $results;
+ return $results;
- } // get_songs
+ } // get_random_items
/**
- * get_random_songs
- * This returns all of the songs in a random order, except those
- * pulled from dyn_songs, takes an optional limit
+ * get_songs
+ * This is called by the batch script, because we can't pass in Dynamic objects they pulled once and then their
+ * target song.id is pushed into the array
*/
- function get_random_songs($limit='') {
-
- if ($limit) {
- $limit_sql = "LIMIT " . intval($limit);
- }
-
- $sql = "SELECT * FROM playlist_data WHERE playlist='" . sql_escape($this->id) . "'" .
- " ORDER BY RAND() $limit_sql";
- $db_results = mysql_query($sql, dbh());
+ function get_songs() {
$results = array();
- while ($r = mysql_fetch_assoc($db_results)) {
+ $sql = "SELECT * FROM `playlist_data` WHERE `playlist`='" . Dba::escape($this->id) . "' ORDER BY `track`";
+ $db_results = Dba::query($sql);
+
+ while ($r = Dba::fetch_assoc($db_results)) {
if ($r['dyn_song']) {
$array = $this->get_dyn_songs($r['dyn_song']);
$results = array_merge($array,$results);
}
else {
- $results[] = $r['song'];
- }
+ $results[] = $r['object_id'];
+ }
+
} // end while
return $results;
- } // get_random_songs
+ } // get_songs
/**
* get_dyn_songs
@@ -298,7 +279,6 @@ class Playlist {
/**
* update_track_numbers
-
* This function takes an array of $array['song_id'] $array['track'] where song_id is really the
* playlist_data.id and updates them
*/
diff --git a/lib/class/update.class.php b/lib/class/update.class.php
index 2af04264..2c5f5694 100644
--- a/lib/class/update.class.php
+++ b/lib/class/update.class.php
@@ -220,6 +220,13 @@ class Update {
$version[] = array('version' => '340007','description' => $update_string);
+ $update_string = '- Modified Playlist_Data table to account for multiple object types.<br />' .
+ '- Verified previous updates, adjusting as needed.<br />' .
+ '- Dropped Allow Downsampling pref, configured in cfg file.<br />' .
+ '- Renamed Downsample Rate --> Transcode Rate to reflect new terminiology.<br />';
+
+ $version[] = array('version' => '340008','description' => $update_string);
+
return $version;
} // populate_version
@@ -309,7 +316,7 @@ class Update {
* This updates the 'update_info' which is used by the updater
* and plugins
*/
- private function set_version($key,$value) {
+ private static function set_version($key,$value) {
$sql = "UPDATE update_info SET value='$value' WHERE `key`='$key'";
$db_results = Dba::query($sql);
@@ -848,5 +855,54 @@ class Update {
} // update_340007
+ /**
+ * update_340008
+ * This modifies the playlist table to handle the different types of objects that it needs to be able to
+ * store, and tweaks how dynamic playlist stuff works
+ */
+ public static function update_340008() {
+
+ $sql = "ALTER TABLE `playlist_data` CHANGE `song` `object_id` INT( 11 ) UNSIGNED NULL DEFAULT NULL";
+ $db_results = Dba::query($sql);
+
+ $sql = "ALTER TABLE `playlist_data` CHANGE `dyn_song` `dynamic_song` TEXT CHARACTER SET utf8 COLLATE utf8_unicode_ci NULL";
+ $db_results = Dba::query($sql);
+
+ $sql = "ALTER TABLE `playlist_data` ADD `object_type` VARCHAR( 32 ) NOT NULL DEFAULT 'song' AFTER `object_id`";
+ $db_results = Dba::query($sql);
+
+ $sql = "ALTER TABLE `playlist` ADD `genre` INT( 11 ) UNSIGNED NOT NULL AFTER `type`";
+ $db_results = Dba::query($sql);
+
+ $sql = "DELETE FROM `preference` WHERE `name`='allow_downsample_playback'";
+ $db_results = Dba::query($sql);
+
+ $sql = "UPDATE `preference` SET `description`='Transcode Bitrate' WHERE `name`='sample_rate'";
+ $db_results = Dba::query($sql);
+
+ // Check for old tables and drop if found, seems like there was a glitch that caused them
+ // not to get droped.. *shrug*
+ $sql = "DROP TABLE IF EXISTS `preferences`";
+ $db_results = Dba::query($sql);
+
+ $sql = "DROP TABLE IF EXISTS `song_ext_data`";
+ $db_results = Dba::query($sql);
+
+ $sql = "DROP TABLE IF EXISTS `ratings`";
+ $db_results = Dba::query($sql);
+
+ $sql = "SELECT `id` FROM `user`";
+ $db_results = Dba::query($sql);
+
+ User::fix_preferences('-1');
+
+ while ($r = Dba::fetch_assoc($db_results)) {
+ User::fix_preferences($r['id']);
+ }
+
+ self::set_version('db_version','340008');
+
+ } // update_340008
+
} // end update class
?>
diff --git a/lib/install.php b/lib/install.php
index ede48a17..d9636f3a 100644
--- a/lib/install.php
+++ b/lib/install.php
@@ -120,7 +120,7 @@ function install_insert_db($username,$password,$hostname,$database) {
$db_selected = @mysql_select_db($database, $dbh);
if ($db_selected && !$_POST['overwrite_db']) {
- Error::add('general','Error: Database Already exists and Overwrite no checked');
+ Error::add('general','Error: Database Already exists and Overwrite not checked');
return false;
}
if (!$db_selected) {
diff --git a/lib/preferences.php b/lib/preferences.php
index a2dc0afe..e956cef5 100644
--- a/lib/preferences.php
+++ b/lib/preferences.php
@@ -231,7 +231,6 @@ function create_preference_input($name,$value) {
case 'use_auth':
case 'access_control':
case 'allow_stream_playback':
- case 'allow_downsample_playback':
case 'allow_democratic_playback':
case 'allow_localplay_playback':
case 'demo_mode':
@@ -348,6 +347,7 @@ function create_preference_input($name,$value) {
case 'transcode':
${$value} = ' selected="selected"';
echo "<select name=\"$name\">\n";
+ echo "\t<option value=\"never\"$never>" . _('Never') . "</option>\n";
echo "\t<option value=\"default\"$default>" . _('Default') . "</option>\n";
echo "\t<option value=\"always\"$always>" . _('Always') . "</option>\n";
echo "</select>\n";