summaryrefslogtreecommitdiffstats
path: root/server
diff options
context:
space:
mode:
authorKarl 'vollmerk' Vollmer <vollmer@ampache.org>2006-04-08 05:58:05 +0000
committerKarl 'vollmerk' Vollmer <vollmer@ampache.org>2006-04-08 05:58:05 +0000
commit2b55e30467f5ccdf9324b0377c419c5681f4c215 (patch)
tree16c2f63178ff762a673face6abb7fe584b680b36 /server
parent941afedab85ffd77a83188ca09a888e0603fae72 (diff)
downloadampache-2b55e30467f5ccdf9324b0377c419c5681f4c215.tar.gz
ampache-2b55e30467f5ccdf9324b0377c419c5681f4c215.tar.bz2
ampache-2b55e30467f5ccdf9324b0377c419c5681f4c215.zip
This update includes a full rewrite of the Localplay code, only update
to this version if you don't care about losing a lot of functionality while I am still finishing it up. Also the only working localplay method is currently MPD. UPDATE AT YOUR OWN RISK!
Diffstat (limited to 'server')
-rw-r--r--server/ajax.server.php220
1 files changed, 59 insertions, 161 deletions
diff --git a/server/ajax.server.php b/server/ajax.server.php
index b5b149b5..394d4ce4 100644
--- a/server/ajax.server.php
+++ b/server/ajax.server.php
@@ -1,172 +1,70 @@
<?php
-header('Content-Type: text/xml');
-header('Cache-control: no-cache');
-header('Pragma: no-cache');
-echo '<?xml version="1.0" encoding="UTF-8"?>';
-
-$no_session = true;
-include ('../modules/init.php');
-$myMpd = init_mpd();
-
-$action = $_GET['action'];
-$player = $_GET['player'];
-$result = '';
-
-
-function mpderr() { global $result, $myMpd;
- if ($GLOBALS['player'] == 'mpd')
- { $result = $result . '<error>'.$myMpd->errStr.'</error>'; } }
-function volume() { global $result, $myMpd;
- if ($GLOBALS['player'] == 'mpd')
- { $result = $result . '<volume>'. $myMpd->volume. '</volume>'; } }
-function state() { global $result, $myMpd;
- if ($GLOBALS['player'] == 'mpd')
- { $result = $result. '<state>'. $myMpd->state. '</state>'; } }
-
-function mpd_cur_track_pos () {
- global $result, $myMpd;
- if ($GLOBALS['player'] == 'mpd') {
- $result = $result . '<mpd_cur_track_pos>'.$myMpd->current_track_position.'</mpd_cur_track_pos>';
- }
-}
-
-function now_playing() {
-global $result, $myMpd;
- if ($GLOBALS['player'] == 'mpd') {
- if (!$myMpd->playlist[($myMpd->current_track_id)]['Title']) {
- list($tmp, $id, $tmp) = preg_split("/(song=|&)/", $myMpd->playlist[($myMpd->current_track_id)]['file']);
- $r = new Song($id);
- $myMpd->playlist[($myMpd->current_track_id)]['Title'] = $r->title;
- $myMpd->playlist[($myMpd->current_track_id)]['Artist'] = $r->get_artist_name();
- $myMpd->playlist[($myMpd->current_track_id)]['Album'] = $r->get_album_name();
- }
- $result = $result.'<now_playing>'.
- '<songid>'.$myMpd->current_track_id.'</songid>'.
- '<songtitle>'.htmlspecialchars($myMpd->playlist[$myMpd->current_track_id]['Title']).'</songtitle>'.
- '<songartist>'.htmlspecialchars($myMpd->playlist[$myMpd->current_track_id]['Artist']).'</songartist>'.
- '<songalbum>'.htmlspecialchars($myMpd->playlist[$myMpd->current_track_id]['Album']).'</songalbum>'.
- '<songlength>'.htmlspecialchars($myMpd->playlist[($myMpd->current_track_id)]['Time']).'</songlength>'.
- '</now_playing>';
- } //end if player == mpd
-now_playing_display();
-}
+/*
+ Copyright (c) 2001 - 2006 Ampache.org
+ All rights reserved.
-function now_playing_display() {
+ 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.
- global $result;
- $dbh = dbh();
- $results = get_now_playing();
- $result = $result.'<now_playing_display>';
-
- if (count($results)) {
-
- foreach($results as $item) {
-
- $song = $item['song'];
- $np_user = $item['user'];
-
- if (is_object($song)) {
-
- $result = $result.'<song>';
-
- if (!$np_user->fullname) { $np_user->fullname = "Unknown User"; }
-
- if (conf('use_auth')) {
- $result = $result.'<fullname>'.$np_user->fullname.'</fullname>';
- } else {
- $result = $result.'<fullname></fullname>';
- }
-
- $result = $result.'<songid>'.$song->id.'</songid>';
- $result = $result.'<albumid>'.$song->album.'</albumid>';
- $result = $result.'<artistid>'.$song->artist.'</artistid>';
- $result = $result.'<songtitle>'.htmlspecialchars($song->f_title).'</songtitle>';
- $result = $result.'<songartist>'.htmlspecialchars($song->f_artist).'</songartist>';
- $result = $result.'<songalbum>'.htmlspecialchars($song->f_album).'</songalbum>';
-
- $result = $result.'</song>';
-
- } // if it's a song
- } // foreach song
-
- } // if now playing
- $result = $result.'</now_playing_display>';
-
-}
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
-/**********************
-The below handles a request for action on the mpd player and/or the return of mpd
-player state information.
+*/
-It is grossly inefficient because everytime there is a request it loads init.php and does a full
-instantiation of myMpd. Would be much faster if it only loaded limited info to start, then
-just grabbed what it needed. (Prolly tougher to maintain abstraction.)
-**********************/
+/* Because this is accessed via Ajax we are going to allow the session_id
+ * as part of the get request
+ */
-/*if (!$user->has_access(25)) { echo '<error>Inadequate access privileges!</error>'; return; }*/
-
-switch ($action) {
-case 'getvol' :
- $result = '<volume>'. $myMpd->volume. '</volume>';
+$no_session = true;
+require_once('../modules/init.php');
+
+/* Verify the existance of the Session they passed in */
+if (!session_exists($_REQUEST['sessid'])) { exit(); }
+
+$GLOBALS['user'] = new User($_REQUEST['user_id']);
+$action = scrub_in($_REQUEST['action']);
+
+switch ($action) {
+ case 'localplay':
+ init_preferences();
+ $localplay = init_localplay();
+ $localplay->connect();
+ $function = scrub_in($_GET['cmd']);
+ $localplay->$function();
+ echo $function;
break;
-case 'setvol' :
- if ( is_null($myMpd->SetVolume($_GET['param1'])) ) $result = '<error>'.$myMpd->errStr.'</error>';
- $result = $result.'<volume>'. $myMpd->volume. '</volume>';
+ case 'change_play_type':
+ init_preferences();
+ session_id(scrub_in($_REQUEST['sessid']));
+ session_start();
+ $_SESSION['data']['old_play_type'] = conf('play_type');
+ $pref_id = get_preference_id('play_type');
+ $GLOBALS['user']->update_preference($pref_id,$_GET['type']);
+
+ /* Now Replace the text as you should */
+ $ajax_url = conf('web_path') . '/server/ajax.server.php';
+ $required_info = "&user_id=" . $GLOBALS['user']->id . "&sessid=" . session_id();
+ if ($_GET['type'] == 'localplay') { ?>
+ <span style="text-decoration:underline;cursor:pointer;" onclick="ajaxPut('<?php echo $ajax_url; ?>','action=change_play_type&type=<?php echo $_SESSION['data']['old_play_type'] . $required_info; ?>','play_type');return true;">
+ <?php echo ucfirst($_SESSION['data']['old_play_type']) . ' ' . _('Mode'); ?>
+ </span>
+ <?php } else { ?>
+ <span style="text-decoration:underline;cursor:pointer;" onclick="ajaxPut('<?php echo $ajax_url; ?>','action=change_play_type&type=localplay<?php echo $required_info; ?>','play_type');return true;">
+ <?php echo _('Localplay Mode'); ?>
+ </span>
+ <?php }
break;
-case 'adjvol' :
- if ( is_null($myMpd->AdjustVolume($_GET['param1'])) ) $result = '<error>'.$myMpd->errStr.'</error>';
- volume();
- break;
- case ' > ':
- case "play":
- if ( is_null($myMpd->Play()) ) $result = '<error>'.$myMpd->errStr.'</error>\n';
- mpd_cur_track_pos();
- state();
- now_playing();
- break;
- case "stop":
- case ' X ':
- if ( is_null($myMpd->Stop()) ) $result = '<error>'.$myMpd->errStr.'</error>\n';
- $result = $result.'<state>'. $myMpd->state. '</state>';
- now_playing();
- break;
- case ' | | ':
- case ' = ':
- case "pause":
- if ( is_null($myMpd->Pause()) ) echo "ERROR: " .$myMpd->errStr."\n";
- mpd_cur_track_pos();
- state();
- now_playing();
- break;
- case '|< ':
- case "Prev":
- if ( is_null($myMpd->Previous()) ) echo "ERROR: " . $myMpd->errStr."\n";
- mpd_cur_track_pos();
- state();
- now_playing();
- break;
- case ' >|';
- case "Next":
- if ( is_null($myMpd->Next()) ) echo "ERROR: " . $myMpd->errStr."\n";
- mpd_cur_track_pos();
- state();
- now_playing();
- break;
- case 'now_playing' :
- mpd_cur_track_pos();
- state();
- now_playing();
-// now_playing_display();
- break;
-
-
-} //end switch
-
-
-echo '<properties>' .
- '<action>' . $action .$player.'</action>' .
- $result .
-'</properties>';
+ default:
+ echo "Default Action";
+ break;
+} // end switch action
?>