summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKarl 'vollmerk' Vollmer <vollmer@ampache.org>2005-07-13 04:43:46 +0000
committerKarl 'vollmerk' Vollmer <vollmer@ampache.org>2005-07-13 04:43:46 +0000
commit5bc35124a7077fc318ecfe0771b3cb591bdf6ef1 (patch)
tree2f040154ec747927581086bcac352dd7d395d81f
parentc837dd5752ec436333fe246ce88a90ccfe6eae93 (diff)
downloadampache-5bc35124a7077fc318ecfe0771b3cb591bdf6ef1.tar.gz
ampache-5bc35124a7077fc318ecfe0771b3cb591bdf6ef1.tar.bz2
ampache-5bc35124a7077fc318ecfe0771b3cb591bdf6ef1.zip
fixed now playing, and added mpd file method to now playing
-rw-r--r--amp-mpd.php5
-rwxr-xr-xdocs/CHANGELOG5
-rw-r--r--index.php14
-rw-r--r--lib/general.lib.php29
-rw-r--r--lib/mpd.php46
-rw-r--r--lib/ui.lib.php25
-rw-r--r--play/index.php2
7 files changed, 92 insertions, 34 deletions
diff --git a/amp-mpd.php b/amp-mpd.php
index 2c564a66..f86950d8 100644
--- a/amp-mpd.php
+++ b/amp-mpd.php
@@ -24,6 +24,9 @@
require_once("modules/init.php");
+/* We need to create a MPD object here */
+$myMpd = init_mpd();
+
function mpd_redirect() {
if (conf('localplay_menu')) {
header ("Location: " . conf('web_path') . "/mpd.php");
@@ -33,7 +36,7 @@ function mpd_redirect() {
}
}
-if (!init_mpd()) {
+if (is_object($myMpd)) {
switch ($_REQUEST['action']) {
case "add":
if (!$user->has_access(25)) { break; }
diff --git a/docs/CHANGELOG b/docs/CHANGELOG
index d12d9c32..92fa5783 100755
--- a/docs/CHANGELOG
+++ b/docs/CHANGELOG
@@ -8,6 +8,11 @@
(Thx Sigger, Trey)
- Added Simplified Chinese (Thx Hongyi Gao)
- Fixed XMLRPC session checking
+ - Fixed up the init_mpd() function to prevent errors on local play
+ page
+ - Updated Now Playing to account for new db structure
+ - Fixed Now Playing so that songs played by the MPD file method
+ actually show up (Thx sigger)
--------------------------------------------------------------------------
diff --git a/index.php b/index.php
index 8cb25c76..abf7d4fb 100644
--- a/index.php
+++ b/index.php
@@ -26,7 +26,12 @@
*/
require_once("modules/init.php");
-init_mpd();
+
+/* We need to attempt to init the mpd object */
+if (conf('mpd_method') == 'file') {
+ $myMpd = init_mpd();
+}
+
show_template('header');
show_menu_items('Home');
show_clear();
@@ -70,7 +75,12 @@ if (conf('refresh_limit') > 0) { show_template('javascript_refresh'); }
</tr>
<tr><td colspan="2">&nbsp;</td></tr>
<tr>
- <?php if ($user->prefs['play_type'] == 'mpd') { show_mpd_pl(); } ?>
+ <?php
+ if ($user->prefs['play_type'] == 'mpd') {
+ show_mpd_pl();
+ $myMpd = init_mpd();
+ }
+ ?>
</tr>
<tr><td colspan="2">&nbsp;</td></tr>
<tr>
diff --git a/lib/general.lib.php b/lib/general.lib.php
index 73467efc..d5a0c330 100644
--- a/lib/general.lib.php
+++ b/lib/general.lib.php
@@ -740,33 +740,6 @@ function tbl_name($table) {
/* For now we just return the table name */
return $table;
-} // table
-
-/**
- * Init MPD - This is originally from /amp-mpd.php
- * This initializes MPD if it is the playback method.
- * Returns 1 if error, 0 if all good
- * @package
- * @catagory
- */
-
-function init_mpd () {
-
-global $myMpd;
-
-if (!class_exists('mpd')) { require_once(conf('prefix')."/modules/mpd/mpd.class.php"); }
-if (!is_object($myMpd)) { $myMpd = new mpd(conf('mpd_host'),conf('mpd_port')); }
-if (!$myMpd->connected)
- {
- echo "<font class=\"error\">" . _("Error Connecting") . ": " . $myMpd->errStr . "</font><br />\n";
- log_event ($_SESSION['userdata']['username'],' connection_failed ',"Error: unable to connect to MPD, ".$myMpd->errStr);
- return 1;
- }
-
-return 0;
-
-} // function init_mpd ()
-
-
+} // tbl_name
?>
diff --git a/lib/mpd.php b/lib/mpd.php
index 895b40ac..45b958dd 100644
--- a/lib/mpd.php
+++ b/lib/mpd.php
@@ -72,8 +72,54 @@ function show_mpd_control() {
} // show_mpd_control
+/**
+ * show_mpd_pl
+ * Shows the MPD playlist
+ * @package Local Play
+ * @cataogyr MPD
+ */
function show_mpd_pl() {
require (conf('prefix').'/templates/show_mpdpl.inc');
} // show_mpd_pl
+/**
+ * mpd_redirect
+ * Redriect mojo
+ * @package Local Play
+ * @catagory MPD
+ */
+function mpd_redirect() {
+ if (conf('localplay_menu')) {
+ header ("Location: " . conf('web_path') . "/mpd.php");
+ }
+ else {
+ header ("Location: " . conf('web_path'));
+ }
+} // mpd_redirect
+
+
+/**
+ * Init MPD - This is originally from /amp-mpd.php
+ * This initializes MPD if it is the playback method.
+ * It checks to see if a global variable called myMpd is an object
+ * if it's not then it attempt to create one and return it
+ * @package Local Play
+ * @catagory MPD
+ */
+function init_mpd() {
+
+ if (!class_exists('mpd')) { require_once(conf('prefix')."/modules/mpd/mpd.class.php"); }
+ if (!is_object($GLOBALS['myMpd'])) {
+ $myMpd = new mpd(conf('mpd_host'),conf('mpd_port'));
+ }
+
+ if (!$myMpd->connected) {
+ if (conf('debug')) { log_event ($_SESSION['userdata']['username'],' connection_failed ',"Error: unable to connect to MPD, ".$myMpd->errStr); }
+ return false;
+ }
+
+ return $myMpd;
+
+} // function init_mpd()
+
?>
diff --git a/lib/ui.lib.php b/lib/ui.lib.php
index 715f82ea..b7e63fed 100644
--- a/lib/ui.lib.php
+++ b/lib/ui.lib.php
@@ -452,14 +452,35 @@ function show_play_selected() {
*/
function get_now_playing() {
- $sql = "SELECT song_id,user_id FROM now_playing ORDER BY start_time DESC";
+ $sql = "SELECT song_id,user FROM now_playing ORDER BY start_time DESC";
$db_results = mysql_query($sql, dbh());
while ($r = mysql_fetch_assoc($db_results)) {
$song = new Song($r['song_id']);
$song->format_song();
- $np_user = new User($r['user_id']);
+ $np_user = new User($r['user']);
$results[] = array('song'=>$song,'user'=>$np_user);
} // end while
+
+ if (is_object($GLOBALS['myMpd']) AND conf('mpd_method') == 'file') {
+ $sql = "SELECT song.id FROM song WHERE file = \"". conf('mpd_dir') . "/" .
+ $myMpd->playlist[$myMpd->current_track_id]['file']. "\"";
+
+ $db_results = @mysql_query($sql,dbh());
+
+ while ($r = mysql_fetch_assoc($db_results)) {
+
+ $song = new Song($r['id']);
+ $song->format_song();
+ $np_user = new User(0);
+ $np_user->fullname = 'MPD User';
+ $np_user->username = 'mpd_user';
+ $results[] = array('song'=>$song,'user'=>$np_user);
+
+ } // end while
+
+ } // end if we have a MPD object
+
+
return $results;
} // get_now_playing
diff --git a/play/index.php b/play/index.php
index 3ab7239b..c3870e4f 100644
--- a/play/index.php
+++ b/play/index.php
@@ -167,7 +167,7 @@ else {
// Put this song in the now_playing table
$end_time = time() - $song->time;
- $sql = "INSERT INTO now_playing (`song_id`, `user_id`, `start_time`)" .
+ $sql = "INSERT INTO now_playing (`song_id`, `user`, `start_time`)" .
" VALUES ('$song_id', '$uid', '$end_time')";
$db_result = mysql_query($sql, $dbh);
$lastid = mysql_insert_id($dbh);