diff options
Diffstat (limited to 'modules')
-rw-r--r-- | modules/ampacheapi/AmpacheApi.lib.php | 670 | ||||
-rw-r--r-- | modules/httpq/httpqplayer.class.php | 638 | ||||
-rw-r--r-- | modules/localplay/httpq.controller.php | 546 | ||||
-rw-r--r-- | modules/localplay/mpd.controller.php | 848 | ||||
-rw-r--r-- | modules/localplay/vlc.controller.php | 12 | ||||
-rw-r--r-- | modules/mpd/mpd.class.php | 2 | ||||
-rw-r--r-- | modules/plugins/Lastfm.plugin.php | 422 | ||||
-rw-r--r-- | modules/plugins/Librefm.plugin.php | 420 | ||||
-rw-r--r-- | modules/plugins/MusicBrainz.plugin.php | 126 | ||||
-rw-r--r-- | modules/twitter/twitter_login.php | 58 | ||||
-rw-r--r-- | modules/twitter/twitter_update.php | 69 | ||||
-rw-r--r-- | modules/twitter/twitter_works.php | 205 | ||||
-rw-r--r-- | modules/vlc/vlcplayer.class.php | 17 |
13 files changed, 2017 insertions, 2016 deletions
diff --git a/modules/ampacheapi/AmpacheApi.lib.php b/modules/ampacheapi/AmpacheApi.lib.php index a8cb029d..97fe86d5 100644 --- a/modules/ampacheapi/AmpacheApi.lib.php +++ b/modules/ampacheapi/AmpacheApi.lib.php @@ -1,5 +1,5 @@ <?php -/* vim:set tabstop=8 softtabstop=8 shiftwidth=8 noexpandtab: */ +/* vim:set softtabstop=4 shiftwidth=4 expandtab: */ /** * * LICENSE: GNU General Public License, version 2 (GPLv2) @@ -22,353 +22,353 @@ class AmpacheApi { - // General Settings - private $server; - private $username; - private $password; - private $api_secure; - - // Handshake variables - private $handshake; - private $handshake_time; // Used to figure out how stale our data is - - // Response variables - private $api_session; - - // Constructed variables - private $api_url; - private $api_state='UNCONFIGURED'; - private $api_auth; - - // XML Parser variables - private $XML_currentTag; - private $XML_subTag; - private $XML_parser; - private $XML_results; - private $XML_position=0; - protected $XML_grabtags = array(); - protected $XML_skiptags = array('root'); - protected $XML_parenttags = array('artist','album','song','tag','video','playlist','result', - 'auth','version','update','add','clean','songs', - 'artists','albums','tags','videos','api','playlists','catalogs'); - - // Library static version information - protected $LIB_version = '350001'; - private $API_version = ''; - - private $DEBUG=false; - - /** - * Constructor - * This takes an array of input, if enough information is provided then it will - * attempt to connect to the API right away, otherwise it will simply return an - * object that can be later configured and then connected - */ - public function __construct($config=array()) { - - // See if we are setting debug first - if ($config['debug']) { - $this->debug($config['debug']); - } - - // If we got something, then configure! - if (is_array($config) AND count($config)) { - $this->configure($config); - } - - // If we've been READY'd then go ahead and attempt to connect - if ($this->state() == 'READY') { - $this->connect(); - } - - } // constructor - - /** - * connect - * This attempts to connect to the ampache instance, for now we assume the newer version - */ - public function connect() { - - if ($this->debug) { echo "CONNECT:: Using $this->username / $this->password\n"; } - - // Setup the handshake - $results = array(); - $timestamp = time(); - $key = hash('sha256',$this->password); - $passphrase = hash('sha256',$timestamp . $key); - - $options = array('timestamp'=>$timestamp,'auth'=>$passphrase,'version'=>$this->LIB_version,'user'=>$this->username); - - $response = $this->send_command('handshake',$options); - - $this->parse_response($response); - - // We want the first response - $data = $this->get_response(); - foreach ($data as $value) { - $results = array_merge($results,$value); - } - - if (!$results['auth']) { - $this->set_state('error'); - return false; - } - $this->api_auth = $results['auth']; - $this->set_state('connected'); - // Define when we pulled this, it is not wine, it does - // not get better with age - $this->handshake_time = time(); - $this->handshake = $results; - - } // connect - - /** - * configure - * This function takes an array of elements and configures the AmpaceApi object - * it doesn't really do much more, it is it's own function so we can call it - * from the constructor or directly, if we so desire. - */ - public function configure($config=array()) { - - if ($this->debug) { echo "CONFIGURE :: Checking Passed config options\n"; } - - if (!is_array($config)) { - trigger_error('AmpacheApi::configure received a non-array value'); - return false; - } - - if (isset($config['username'])) { - $this->username = htmlentities($config['username'],ENT_QUOTES,'UTF-8'); - } - if (isset($config['password'])) { - $this->password = htmlentities($config['password'],ENT_QUOTES,'UTF-8'); - } - if (isset($config['server'])) { - // Replace any http:// in the URL with '' - $config['server'] = str_replace('http://','',$config['server']); - $this->server = htmlentities($config['server'],ENT_QUOTES,'UTF-8'); - } - if (isset($config['api_secure'])) { - // This should be a boolean response - $this->api_secure = $config['api_secure'] ? true : false; - } - - // Once we've loaded the config variables we can build some of the final values - $this->api_url = ($this->api_secure ? 'https://' : 'http://') . $this->server . '/server/xml.server.php'; - - // See if we have enough to authenticate, if so change the state - if ($this->username AND $this->password AND $this->server) { - $this->set_state('ready'); - } - - return true; - - } // configure - - /** - * set_state - * This sets the current state of the API, it is used mostly internally but - * the state can be accessed externally so it could be used to check and see - * where the API is at, at this moment - */ - public function set_state($state) { - - // Very simple for now, maybe we'll do something more with this later - $this->api_state = strtoupper($state); - - } // set_state - - /** - * state - * This returns the state of the API - */ - public function state() { - - return $this->api_state; - - } // state - - /** - * info - * Returns the information gathered by the handshake - * not raw so we can formated it if we wanted? - */ - public function info() { - - if ($this->state() != 'CONNECTED') { - throw new Exception('AmpacheApi::info API in non-ready state, unable to return info'); - } - - return $this->handshake; - - } // info - - /** - * send_command - * This sends an API command, with options to the currently connected - * host, and returns a nice clean keyed array - */ - public function send_command($command,$options=array()) { - - if ($this->debug) { echo "SEND COMMAND:: $command"; print_r($options,1); echo "\n"; } - - if ($this->state() != 'READY' AND $this->state() != 'CONNECTED') { - throw new Exception('AmpacheApi::send_command API in non-ready state, unable to send'); - } - if (!trim($command)) { - throw new Exception('AmpacheApi::send_command no command specified'); - } - if (!$this->validate_command($command)) { - throw new Exception('AmpacheApi::send_command Invalid/Unknown command ' . $command . ' issued'); - } - - $url = $this->api_url . '?action=' . urlencode($command); - - foreach ($options as $key=>$value) { - if (!trim($key)) { - // Non fatal don't need to except it - trigger_error('AmpacheApi::send_command unable to append empty variable to command'); - continue; - } - $url .= '&' . urlencode($key) . '=' . urlencode($value); - } - - // IF Auth is set then we append it so you don't have to think about it, also do username - if ($this->api_auth) { - $url .= '&auth=' . urlencode($this->api_auth) . '&username=' . urlencode($this->username); - } - - $data = file_get_contents($url); - return $data; - - } // send_command - - /** - * validate_command - * This takes the specified command, and checks it against the known - * commands for the current version of Ampache. If no version is known yet - * This it will return FALSE for everything except ping and handshake. - */ - public function validate_command($command) { - - return true; - - } // validate_command - - /** - * parse_response - * This takes an XML document and dumps it into $this->results but before - * it does that it will clean up anything that was there before, so I hope - * you've saved! - */ - public function parse_response($response) { - - // Reset the results - $this->XML_results = array(); - $this->XML_position = 0; - - $this->XML_create_parser(); - - if (!xml_parse($this->XML_parser,$response)) { - throw new Exception('AmpacheApi::parse_response was unable to parse XML document'); - } - - xml_parser_free($this->XML_parser); - return true; - - } // parse_response - - /** - * get_response - * This returns the raw response from the last parsed response - */ - public function get_response() { - - return $this->XML_results; - - } // get_response - - /** - * debug - * set debug to true? - */ - private function debug($value) { - - $this->debug = intval($value); - - } // debug - - /////////////////////////// XML PARSER FUNCTIONS ///////////////////////////// - - /** - * XML_create_parser - * This creates the xml parser and sets the options - */ - public function XML_create_parser() { - - $this->XML_parser = xml_parser_create(); - xml_parser_set_option($this->XML_parser,XML_OPTION_CASE_FOLDING,false); - xml_set_object($this->XML_parser,$this); - xml_set_element_handler($this->XML_parser,'XML_start_element','XML_end_element'); - xml_set_character_data_handler($this->XML_parser,'XML_cdata'); - - } // XML_create_parser - - /** - * XML_cdata - * This is called for the content of the XML tag - */ - public function XML_cdata($parser,$cdata) { + // General Settings + private $server; + private $username; + private $password; + private $api_secure; + + // Handshake variables + private $handshake; + private $handshake_time; // Used to figure out how stale our data is + + // Response variables + private $api_session; + + // Constructed variables + private $api_url; + private $api_state='UNCONFIGURED'; + private $api_auth; + + // XML Parser variables + private $XML_currentTag; + private $XML_subTag; + private $XML_parser; + private $XML_results; + private $XML_position=0; + protected $XML_grabtags = array(); + protected $XML_skiptags = array('root'); + protected $XML_parenttags = array('artist','album','song','tag','video','playlist','result', + 'auth','version','update','add','clean','songs', + 'artists','albums','tags','videos','api','playlists','catalogs'); + + // Library static version information + protected $LIB_version = '350001'; + private $API_version = ''; + + private $DEBUG=false; + + /** + * Constructor + * This takes an array of input, if enough information is provided then it will + * attempt to connect to the API right away, otherwise it will simply return an + * object that can be later configured and then connected + */ + public function __construct($config=array()) { + + // See if we are setting debug first + if ($config['debug']) { + $this->debug($config['debug']); + } + + // If we got something, then configure! + if (is_array($config) AND count($config)) { + $this->configure($config); + } + + // If we've been READY'd then go ahead and attempt to connect + if ($this->state() == 'READY') { + $this->connect(); + } + + } // constructor + + /** + * connect + * This attempts to connect to the ampache instance, for now we assume the newer version + */ + public function connect() { + + if ($this->debug) { echo "CONNECT:: Using $this->username / $this->password\n"; } + + // Setup the handshake + $results = array(); + $timestamp = time(); + $key = hash('sha256',$this->password); + $passphrase = hash('sha256',$timestamp . $key); + + $options = array('timestamp'=>$timestamp,'auth'=>$passphrase,'version'=>$this->LIB_version,'user'=>$this->username); + + $response = $this->send_command('handshake',$options); + + $this->parse_response($response); + + // We want the first response + $data = $this->get_response(); + foreach ($data as $value) { + $results = array_merge($results,$value); + } + + if (!$results['auth']) { + $this->set_state('error'); + return false; + } + $this->api_auth = $results['auth']; + $this->set_state('connected'); + // Define when we pulled this, it is not wine, it does + // not get better with age + $this->handshake_time = time(); + $this->handshake = $results; + + } // connect + + /** + * configure + * This function takes an array of elements and configures the AmpaceApi object + * it doesn't really do much more, it is it's own function so we can call it + * from the constructor or directly, if we so desire. + */ + public function configure($config=array()) { + + if ($this->debug) { echo "CONFIGURE :: Checking Passed config options\n"; } + + if (!is_array($config)) { + trigger_error('AmpacheApi::configure received a non-array value'); + return false; + } + + if (isset($config['username'])) { + $this->username = htmlentities($config['username'],ENT_QUOTES,'UTF-8'); + } + if (isset($config['password'])) { + $this->password = htmlentities($config['password'],ENT_QUOTES,'UTF-8'); + } + if (isset($config['server'])) { + // Replace any http:// in the URL with '' + $config['server'] = str_replace('http://','',$config['server']); + $this->server = htmlentities($config['server'],ENT_QUOTES,'UTF-8'); + } + if (isset($config['api_secure'])) { + // This should be a boolean response + $this->api_secure = $config['api_secure'] ? true : false; + } + + // Once we've loaded the config variables we can build some of the final values + $this->api_url = ($this->api_secure ? 'https://' : 'http://') . $this->server . '/server/xml.server.php'; + + // See if we have enough to authenticate, if so change the state + if ($this->username AND $this->password AND $this->server) { + $this->set_state('ready'); + } + + return true; + + } // configure + + /** + * set_state + * This sets the current state of the API, it is used mostly internally but + * the state can be accessed externally so it could be used to check and see + * where the API is at, at this moment + */ + public function set_state($state) { + + // Very simple for now, maybe we'll do something more with this later + $this->api_state = strtoupper($state); + + } // set_state + + /** + * state + * This returns the state of the API + */ + public function state() { + + return $this->api_state; + + } // state + + /** + * info + * Returns the information gathered by the handshake + * not raw so we can formated it if we wanted? + */ + public function info() { + + if ($this->state() != 'CONNECTED') { + throw new Exception('AmpacheApi::info API in non-ready state, unable to return info'); + } + + return $this->handshake; + + } // info + + /** + * send_command + * This sends an API command, with options to the currently connected + * host, and returns a nice clean keyed array + */ + public function send_command($command,$options=array()) { + + if ($this->debug) { echo "SEND COMMAND:: $command"; print_r($options,1); echo "\n"; } + + if ($this->state() != 'READY' AND $this->state() != 'CONNECTED') { + throw new Exception('AmpacheApi::send_command API in non-ready state, unable to send'); + } + if (!trim($command)) { + throw new Exception('AmpacheApi::send_command no command specified'); + } + if (!$this->validate_command($command)) { + throw new Exception('AmpacheApi::send_command Invalid/Unknown command ' . $command . ' issued'); + } + + $url = $this->api_url . '?action=' . urlencode($command); + + foreach ($options as $key=>$value) { + if (!trim($key)) { + // Non fatal don't need to except it + trigger_error('AmpacheApi::send_command unable to append empty variable to command'); + continue; + } + $url .= '&' . urlencode($key) . '=' . urlencode($value); + } + + // IF Auth is set then we append it so you don't have to think about it, also do username + if ($this->api_auth) { + $url .= '&auth=' . urlencode($this->api_auth) . '&username=' . urlencode($this->username); + } + + $data = file_get_contents($url); + return $data; + + } // send_command + + /** + * validate_command + * This takes the specified command, and checks it against the known + * commands for the current version of Ampache. If no version is known yet + * This it will return FALSE for everything except ping and handshake. + */ + public function validate_command($command) { + + return true; + + } // validate_command + + /** + * parse_response + * This takes an XML document and dumps it into $this->results but before + * it does that it will clean up anything that was there before, so I hope + * you've saved! + */ + public function parse_response($response) { + + // Reset the results + $this->XML_results = array(); + $this->XML_position = 0; + + $this->XML_create_parser(); + + if (!xml_parse($this->XML_parser,$response)) { + throw new Exception('AmpacheApi::parse_response was unable to parse XML document'); + } + + xml_parser_free($this->XML_parser); + return true; + + } // parse_response + + /** + * get_response + * This returns the raw response from the last parsed response + */ + public function get_response() { + + return $this->XML_results; + + } // get_response + + /** + * debug + * set debug to true? + */ + private function debug($value) { + + $this->debug = intval($value); + + } // debug + + /////////////////////////// XML PARSER FUNCTIONS ///////////////////////////// + + /** + * XML_create_parser + * This creates the xml parser and sets the options + */ + public function XML_create_parser() { + + $this->XML_parser = xml_parser_create(); + xml_parser_set_option($this->XML_parser,XML_OPTION_CASE_FOLDING,false); + xml_set_object($this->XML_parser,$this); + xml_set_element_handler($this->XML_parser,'XML_start_element','XML_end_element'); + xml_set_character_data_handler($this->XML_parser,'XML_cdata'); + + } // XML_create_parser + + /** + * XML_cdata + * This is called for the content of the XML tag + */ + public function XML_cdata($parser,$cdata) { - $cdata = trim($cdata); + $cdata = trim($cdata); - if (!$this->XML_currentTag || !$cdata) { return false; } + if (!$this->XML_currentTag || !$cdata) { return false; } - if ($this->XML_subTag) { - $this->XML_results[$this->XML_position][$this->XML_currentTag][$this->XML_subTag] = $cdata; - } - else { - $this->XML_results[$this->XML_position][$this->XML_currentTag] = $cdata; - } + if ($this->XML_subTag) { + $this->XML_results[$this->XML_position][$this->XML_currentTag][$this->XML_subTag] = $cdata; + } + else { + $this->XML_results[$this->XML_position][$this->XML_currentTag] = $cdata; + } - } // XML_cdata + } // XML_cdata - public function XML_start_element($parser,$tag,$attributes) { + public function XML_start_element($parser,$tag,$attributes) { - // Skip it! - if (in_array($tag,$this->XML_skiptags)) { return false; } - - if (!in_array($tag,$this->XML_parenttags) OR $this->XML_currentTag) { - $this->XML_subTag = $tag; - } - else { - $this->XML_currentTag = $tag; - } + // Skip it! + if (in_array($tag,$this->XML_skiptags)) { return false; } + + if (!in_array($tag,$this->XML_parenttags) OR $this->XML_currentTag) { + $this->XML_subTag = $tag; + } + else { + $this->XML_currentTag = $tag; + } - if (count($attributes)) { - if (!$this->XML_subTag) { - $this->XML_results[$this->XML_position][$this->XML_currentTag]['self'] = $attributes; - } - else { - $this->XML_results[$this->XML_position][$this->XML_currentTag][$this->XML_subTag]['self'] = $attributes; - } - } + if (count($attributes)) { + if (!$this->XML_subTag) { + $this->XML_results[$this->XML_position][$this->XML_currentTag]['self'] = $attributes; + } + else { + $this->XML_results[$this->XML_position][$this->XML_currentTag][$this->XML_subTag]['self'] = $attributes; + } + } - } // start_element + } // start_element - public function XML_end_element($parser,$tag) { + public function XML_end_element($parser,$tag) { - if ($tag != $this->XML_currentTag) { - $this->XML_subTag = false; - } - else { - $this->XML_currentTag = false; - $this->XML_position++; - } + if ($tag != $this->XML_currentTag) { + $this->XML_subTag = false; + } + else { + $this->XML_currentTag = false; + $this->XML_position++; + } - } // end_element + } // end_element } // end AmpacheApi class ?> diff --git a/modules/httpq/httpqplayer.class.php b/modules/httpq/httpqplayer.class.php index 0251ee76..1f061f42 100644 --- a/modules/httpq/httpqplayer.class.php +++ b/modules/httpq/httpqplayer.class.php @@ -1,5 +1,5 @@ <?php -/* vim:set tabstop=8 softtabstop=8 shiftwidth=8 noexpandtab: */ +/* vim:set softtabstop=4 shiftwidth=4 expandtab: */ /** * * LICENSE: GNU General Public License, version 2 (GPLv2) @@ -28,410 +28,410 @@ */ class HttpQPlayer { - public $host; - public $port; - public $password; - - /** - * HttpQPlayer - * This is the constructor, it defaults to localhost - * with port 4800 - */ - public function HttpQPlayer($h = "localhost", $pw = "", $p = 4800) { - - $this->host = $h; - $this->port = $p; - $this->password = $pw; + public $host; + public $port; + public $password; + + /** + * HttpQPlayer + * This is the constructor, it defaults to localhost + * with port 4800 + */ + public function HttpQPlayer($h = "localhost", $pw = "", $p = 4800) { + + $this->host = $h; + $this->port = $p; + $this->password = $pw; - } // HttpQPlayer - - /** - * add - * append a song to the playlist - * $name Name to be shown in the playlist - * $url URL of the song - */ - public function add($name, $url) { - - $args['name'] = urlencode($name); - $args['url'] = urlencode($url); - - $results = $this->sendCommand('playurl', $args); - - if ($results == '0') { $results = null; } + } // HttpQPlayer + + /** + * add + * append a song to the playlist + * $name Name to be shown in the playlist + * $url URL of the song + */ + public function add($name, $url) { + + $args['name'] = urlencode($name); + $args['url'] = urlencode($url); + + $results = $this->sendCommand('playurl', $args); + + if ($results == '0') { $results = null; } - return $results; + return $results; - } // add - - /** - * version - * This gets the version of winamp currently - * running, use this to test for a valid connection - */ - public function version() { + } // add + + /** + * version + * This gets the version of winamp currently + * running, use this to test for a valid connection + */ + public function version() { - $args = array(); - $results = $this->sendCommand('getversion',$args); - - // a return of 0 is a bad value - if ($results == '0') { $results = null; } + $args = array(); + $results = $this->sendCommand('getversion',$args); + + // a return of 0 is a bad value + if ($results == '0') { $results = null; } - return $results; - - } // version + return $results; + + } // version - /** - * clear - * clear the playlist - */ - public function clear() { - $args = array(); - $results = $this->sendCommand("delete", $args); + /** + * clear + * clear the playlist + */ + public function clear() { + $args = array(); + $results = $this->sendCommand("delete", $args); - if ($results == '0') { $results = null; } + if ($results == '0') { $results = null; } - return $results; - - } // clear - - /** - * next - * go to next song - */ - public function next() { + return $results; + + } // clear + + /** + * next + * go to next song + */ + public function next() { - $args = array(); - $results = $this->sendCommand("next", $args); + $args = array(); + $results = $this->sendCommand("next", $args); - if ($results == '0') { return null; } + if ($results == '0') { return null; } - return true; + return true; - } // next + } // next - /** - * prev - * go to previous song - */ - public function prev() { + /** + * prev + * go to previous song + */ + public function prev() { - $args = array(); - $results = $this->sendCommand("prev", $args); + $args = array(); + $results = $this->sendCommand("prev", $args); - if ($results == '0') { return null; } - - return true; + if ($results == '0') { return null; } + + return true; - } // prev + } // prev - /** - * skip - * This skips to POS in the playlist - */ - public function skip($pos) { + /** + * skip + * This skips to POS in the playlist + */ + public function skip($pos) { - $args = array('index'=>$pos); - $results = $this->sendCommand('setplaylistpos',$args); + $args = array('index'=>$pos); + $results = $this->sendCommand('setplaylistpos',$args); - if ($results == '0') { return null; } + if ($results == '0') { return null; } - // Now stop start - $this->stop(); - $this->play(); + // Now stop start + $this->stop(); + $this->play(); - return true; + return true; - } // skip - - /** - * play - * play the current song - */ - public function play() { + } // skip + + /** + * play + * play the current song + */ + public function play() { - $args = array(); - $results = $this->sendCommand("play", $args); + $args = array(); + $results = $this->sendCommand("play", $args); - if ($results == '0') { $results = null; } + if ($results == '0') { $results = null; } - return $results; + return $results; - } // play - - /** - * pause - * toggle pause mode on current song - */ - public function pause() { + } // play + + /** + * pause + * toggle pause mode on current song + */ + public function pause() { - $args = array(); - $results = $this->sendCommand("pause", $args); + $args = array(); + $results = $this->sendCommand("pause", $args); - if ($results == '0') { $results = null; } + if ($results == '0') { $results = null; } - return $results; + return $results; - } // pause - - /** - * stop - * stops the current song amazing! - */ - public function stop() { + } // pause + + /** + * stop + * stops the current song amazing! + */ + public function stop() { - $args = array(); - $results = $this->sendCommand('stop', $args); + $args = array(); + $results = $this->sendCommand('stop', $args); - if ($results == '0') { $results = null; } + if ($results == '0') { $results = null; } - return $results; + return $results; - } // stop + } // stop - /** - * repeat - * This toggles the repeat state of HttpQ - */ - public function repeat($value) { - - $args = array('enable'=>$value); - $results = $this->sendCommand('repeat',$args); - - if ($results == '0') { $results = null; } + /** + * repeat + * This toggles the repeat state of HttpQ + */ + public function repeat($value) { + + $args = array('enable'=>$value); + $results = $this->sendCommand('repeat',$args); + + if ($results == '0') { $results = null; } - return $results; + return $results; - } // repeat + } // repeat - /** - * random - * this toggles the random state of HttpQ - */ - public function random($value) { + /** + * random + * this toggles the random state of HttpQ + */ + public function random($value) { - $args = array('enable'=>$value); - $results = $this->sendCommand('shuffle',$args); + $args = array('enable'=>$value); + $results = $this->sendCommand('shuffle',$args); - if ($results == '0') { $results = null; } + if ($results == '0') { $results = null; } - return $results; + return $results; - } // random + } // random - /** - * delete_pos - * This deletes a specific track - */ - public function delete_pos($track) { - - $args = array('index'=>$track); - $results = $this->sendCommand('deletepos',$args); - - if ($results == '0') { $results = null; } + /** + * delete_pos + * This deletes a specific track + */ + public function delete_pos($track) { + + $args = array('index'=>$track); + $results = $this->sendCommand('deletepos',$args); + + if ($results == '0') { $results = null; } - return $results; + return $results; - } // delete_pos + } // delete_pos - /** - * state - * This returns the current state of the httpQ player - */ - public function state() { + /** + * state + * This returns the current state of the httpQ player + */ + public function state() { - $args = array(); - $results = $this->sendCommand('isplaying',$args); + $args = array(); + $results = $this->sendCommand('isplaying',$args); - if ($results == '1') { $state = 'play'; } - if ($results == '0') { $state = 'stop'; } - if ($results == '3') { $state = 'pause'; } - - return $state; + if ($results == '1') { $state = 'play'; } + if ($results == '0') { $state = 'stop'; } + if ($results == '3') { $state = 'pause'; } + + return $state; - } // state + } // state - /** - * get_volume - * This returns the current volume - */ - public function get_volume() { + /** + * get_volume + * This returns the current volume + */ + public function get_volume() { - $args = array(); - $results = $this->sendCommand('getvolume',$args); + $args = array(); + $results = $this->sendCommand('getvolume',$args); - if ($results == '0') { $results = null; } - else { - /* Need to make this out of 100 */ - $results = round((($results / 255) * 100),2); - } + if ($results == '0') { $results = null; } + else { + /* Need to make this out of 100 */ + $results = round((($results / 255) * 100),2); + } - return $results; + return $results; - } // get_volume + } // get_volume - /** - * volume_up - * This increases the volume by Wimamp's defined amount - */ - public function volume_up() { + /** + * volume_up + * This increases the volume by Wimamp's defined amount + */ + public function volume_up() { - $args = array(); - $results = $this->sendCommand('volumeup',$args); - - if ($results == '0') { return null; } + $args = array(); + $results = $this->sendCommand('volumeup',$args); + + if ($results == '0') { return null; } - return true; + return true; - } // volume_up + } // volume_up - /** - * volume_down - * This decreases the volume by Winamp's defined amount - */ - public function volume_down() { + /** + * volume_down + * This decreases the volume by Winamp's defined amount + */ + public function volume_down() { - $args = array(); - $results = $this->sendCommand('volumedown',$args); - - if ($results == '0') { return null; } + $args = array(); + $results = $this->sendCommand('volumedown',$args); + + if ($results == '0') { return null; } - return true; + return true; - } // volume_down + } // volume_down - /** - * set_volume - * This sets the volume as best it can, we go from a resolution - * of 100 --> 255 so it's a little fuzzy - */ - public function set_volume($value) { + /** + * set_volume + * This sets the volume as best it can, we go from a resolution + * of 100 --> 255 so it's a little fuzzy + */ + public function set_volume($value) { - // Convert it to base 255 - $value = $value*2.55; - $args = array('level'=>$value); - $results = $this->sendCommand('setvolume',$args); + // Convert it to base 255 + $value = $value*2.55; + $args = array('level'=>$value); + $results = $this->sendCommand('setvolume',$args); - if ($results == '0') { return null; } + if ($results == '0') { return null; } - return true; + return true; - } // set_volume + } // set_volume - /** - * clear_playlist - * this flushes the playlist cache (I hope this means clear) - */ - public function clear_playlist() { + /** + * clear_playlist + * this flushes the playlist cache (I hope this means clear) + */ + public function clear_playlist() { - $args = array(); - $results = $this->sendcommand('flushplaylist',$args); - - if ($results == '0') { return null; } + $args = array(); + $results = $this->sendcommand('flushplaylist',$args); + + if ($results == '0') { return null; } - return true; + return true; - } // clear_playlist + } // clear_playlist - /** - * get_repeat - * This returns the current state of the repeat - */ - public function get_repeat() { + /** + * get_repeat + * This returns the current state of the repeat + */ + public function get_repeat() { - $args = array(); - $results = $this->sendCommand('repeat_status',$args); + $args = array(); + $results = $this->sendCommand('repeat_status',$args); - return $results; - - } // get_repeat + return $results; + + } // get_repeat - /** - * get_random - * This returns the current state of shuffle - */ - public function get_random() { - - $args = array(); - $results = $this->sendCommand('shuffle_status',$args); - - return $results; + /** + * get_random + * This returns the current state of shuffle + */ + public function get_random() { + + $args = array(); + $results = $this->sendCommand('shuffle_status',$args); + + return $results; - } // get_random + } // get_random - /** - * get_now_playing - * This returns the file information for the currently - * playing song - */ - public function get_now_playing() { + /** + * get_now_playing + * This returns the file information for the currently + * playing song + */ + public function get_now_playing() { - // First get the current POS - $pos = $this->sendCommand('getlistpos',array()); - - // Now get the filename - $file = $this->sendCommand('getplaylistfile',array('index'=>$pos)); - - return $file; + // First get the current POS + $pos = $this->sendCommand('getlistpos',array()); + + // Now get the filename + $file = $this->sendCommand('getplaylistfile',array('index'=>$pos)); + + return $file; - } // get_now_playing + } // get_now_playing - /** - * get_tracks - * This returns a delimiated string of all of the filenames - * current in your playlist - */ - public function get_tracks() { + /** + * get_tracks + * This returns a delimiated string of all of the filenames + * current in your playlist + */ + public function get_tracks() { - // Pull a delimited list of all tracks - $results = $this->sendCommand('getplaylistfile',array('delim'=>'::')); - - if ($results == '0') { $results = null; } - - return $results; + // Pull a delimited list of all tracks + $results = $this->sendCommand('getplaylistfile',array('delim'=>'::')); + + if ($results == '0') { $results = null; } + + return $results; - } // get_tracks - - /** - * sendCommand - * This is the core of this library it takes care of sending the HTTP - * request to the HttpQ server and getting the response - */ - private function sendCommand($cmd, $args) { - - $fp = fsockopen($this->host, $this->port, $errno, $errstr); - - if(!$fp) { - debug_event('httpq',"HttpQPlayer: $errstr ($errno)",'1'); - return null; - } + } // get_tracks + + /** + * sendCommand + * This is the core of this library it takes care of sending the HTTP + * request to the HttpQ server and getting the response + */ + private function sendCommand($cmd, $args) { + + $fp = fsockopen($this->host, $this->port, $errno, $errstr); + + if(!$fp) { + debug_event('httpq',"HttpQPlayer: $errstr ($errno)",'1'); + return null; + } - // Define the base message - $msg = "GET /$cmd?p=$this->password"; + // Define the base message + $msg = "GET /$cmd?p=$this->password"; - // Foreach our arguments - foreach ($args AS $key => $val) { - $msg = $msg . "&$key=$val"; - } + // Foreach our arguments + foreach ($args AS $key => $val) { + $msg = $msg . "&$key=$val"; + } - $msg = $msg . " HTTP/1.0\r\n\r\n"; - fputs($fp, $msg); - $data = ''; - - while(!feof($fp)) { - $data .= fgets($fp); - } - fclose($fp); - - // Explode the results by line break and take 4th line (results) - $data = explode("\n",$data); - - $result = $data['4']; - - return $result; - - } // sendCommand + $msg = $msg . " HTTP/1.0\r\n\r\n"; + fputs($fp, $msg); + $data = ''; + + while(!feof($fp)) { + $data .= fgets($fp); + } + fclose($fp); + + // Explode the results by line break and take 4th line (results) + $data = explode("\n",$data); + + $result = $data['4']; + + return $result; + + } // sendCommand } // End HttpQPlayer Class ?> diff --git a/modules/localplay/httpq.controller.php b/modules/localplay/httpq.controller.php index 6cad04c4..63d4e6de 100644 --- a/modules/localplay/httpq.controller.php +++ b/modules/localplay/httpq.controller.php @@ -1,5 +1,5 @@ <?php -/* vim:set tabstop=8 softtabstop=8 shiftwidth=8 noexpandtab: */ +/* vim:set softtabstop=4 shiftwidth=4 expandtab: */ /** * * LICENSE: GNU General Public License, version 2 (GPLv2) @@ -30,44 +30,44 @@ class AmpacheHttpq extends localplay_controller { - /* Variables */ - private $version = '000002'; - private $description = "Controls an httpQ instance, requires Ampache's httpQ version"; + /* Variables */ + private $version = '000002'; + private $description = "Controls an httpQ instance, requires Ampache's httpQ version"; - /* Constructed variables */ - private $_httpq; + /* Constructed variables */ + private $_httpq; - /** - * Constructor - * This returns the array map for the localplay object - * REQUIRED for Localplay - */ - public function __construct() { + /** + * Constructor + * This returns the array map for the localplay object + * REQUIRED for Localplay + */ + public function __construct() { - /* Do a Require Once On the needed Libraries */ - require_once Config::get('prefix') . '/modules/httpq/httpqplayer.class.php'; + /* Do a Require Once On the needed Libraries */ + require_once Config::get('prefix') . '/modules/httpq/httpqplayer.class.php'; - } // Constructor + } // Constructor - /** - * get_description - * This returns the description of this localplay method - */ - public function get_description() { + /** + * get_description + * This returns the description of this localplay method + */ + public function get_description() { - return $this->description; + return $this->description; - } // get_description + } // get_description - /** - * get_version - * This returns the current version - */ - public function get_version() { + /** + * get_version + * This returns the current version + */ + public function get_version() { - return $this->version; + return $this->version; - } // get_version + } // get_version /** * is_installed @@ -75,10 +75,10 @@ class AmpacheHttpq extends localplay_controller { */ public function is_installed() { - $sql = "DESCRIBE `localplay_httpq`"; - $db_results = Dba::read($sql); + $sql = "DESCRIBE `localplay_httpq`"; + $db_results = Dba::read($sql); - return Dba::num_rows($db_results); + return Dba::num_rows($db_results); } // is_installed @@ -89,21 +89,21 @@ class AmpacheHttpq extends localplay_controller { */ public function install() { - $sql = "CREATE TABLE `localplay_httpq` (`id` INT( 11 ) UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY , ". - "`name` VARCHAR( 128 ) COLLATE utf8_unicode_ci NOT NULL , " . - "`owner` INT( 11 ) NOT NULL, " . - "`host` VARCHAR( 255 ) COLLATE utf8_unicode_ci NOT NULL , " . - "`port` INT( 11 ) UNSIGNED NOT NULL , " . - "`password` VARCHAR( 255 ) COLLATE utf8_unicode_ci NOT NULL , " . - "`access` SMALLINT( 4 ) UNSIGNED NOT NULL DEFAULT '0'" . - ") ENGINE = MYISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci"; - $db_results = Dba::write($sql); + $sql = "CREATE TABLE `localplay_httpq` (`id` INT( 11 ) UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY , ". + "`name` VARCHAR( 128 ) COLLATE utf8_unicode_ci NOT NULL , " . + "`owner` INT( 11 ) NOT NULL, " . + "`host` VARCHAR( 255 ) COLLATE utf8_unicode_ci NOT NULL , " . + "`port` INT( 11 ) UNSIGNED NOT NULL , " . + "`password` VARCHAR( 255 ) COLLATE utf8_unicode_ci NOT NULL , " . + "`access` SMALLINT( 4 ) UNSIGNED NOT NULL DEFAULT '0'" . + ") ENGINE = MYISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci"; + $db_results = Dba::write($sql); - // Add an internal preference for the users current active instance - Preference::insert('httpq_active','HTTPQ Active Instance','0','25','integer','internal'); - User::rebuild_all_preferences(); + // Add an internal preference for the users current active instance + Preference::insert('httpq_active','HTTPQ Active Instance','0','25','integer','internal'); + User::rebuild_all_preferences(); - return true; + return true; } // install @@ -113,13 +113,13 @@ class AmpacheHttpq extends localplay_controller { */ public function uninstall() { - $sql = "DROP TABLE `localplay_httpq`"; - $db_results = Dba::write($sql); + $sql = "DROP TABLE `localplay_httpq`"; + $db_results = Dba::write($sql); - // Remove the pref we added for this - Preference::delete('httpq_active'); + // Remove the pref we added for this + Preference::delete('httpq_active'); - return true; + return true; } // uninstall @@ -129,18 +129,18 @@ class AmpacheHttpq extends localplay_controller { */ public function add_instance($data) { - $name = Dba::escape($data['name']); - $host = Dba::escape($data['host']); - $port = Dba::escape($data['port']); - $password = Dba::escape($data['password']); - $user_id = Dba::escape($GLOBALS['user']->id); + $name = Dba::escape($data['name']); + $host = Dba::escape($data['host']); + $port = Dba::escape($data['port']); + $password = Dba::escape($data['password']); + $user_id = Dba::escape($GLOBALS['user']->id); - $sql = "INSERT INTO `localplay_httpq` (`name`,`host`,`port`,`password`,`owner`) " . - "VALUES ('$name','$host','$port','$password','$user_id')"; - $db_results = Dba::write($sql); + $sql = "INSERT INTO `localplay_httpq` (`name`,`host`,`port`,`password`,`owner`) " . + "VALUES ('$name','$host','$port','$password','$user_id')"; + $db_results = Dba::write($sql); - return $db_results; + return $db_results; } // add_instance @@ -150,12 +150,12 @@ class AmpacheHttpq extends localplay_controller { */ public function delete_instance($uid) { - $uid = Dba::escape($uid); + $uid = Dba::escape($uid); - $sql = "DELETE FROM `localplay_httpq` WHERE `id`='$uid'"; - $db_results = Dba::write($sql); + $sql = "DELETE FROM `localplay_httpq` WHERE `id`='$uid'"; + $db_results = Dba::write($sql); - return true; + return true; } // delete_instance @@ -166,16 +166,16 @@ class AmpacheHttpq extends localplay_controller { */ public function get_instances() { - $sql = "SELECT * FROM `localplay_httpq` ORDER BY `name`"; - $db_results = Dba::read($sql); + $sql = "SELECT * FROM `localplay_httpq` ORDER BY `name`"; + $db_results = Dba::read($sql); - $results = array(); + $results = array(); - while ($row = Dba::fetch_assoc($db_results)) { - $results[$row['id']] = $row['name']; - } + while ($row = Dba::fetch_assoc($db_results)) { + $results[$row['id']] = $row['name']; + } - return $results; + return $results; } // get_instances @@ -185,16 +185,16 @@ class AmpacheHttpq extends localplay_controller { */ public function update_instance($uid, $data) { - $uid = Dba::escape($uid); - $port = Dba::escape($data['port']); - $host = Dba::escape($data['host']); - $name = Dba::escape($data['name']); - $pass = Dba::escape($data['password']); + $uid = Dba::escape($uid); + $port = Dba::escape($data['port']); + $host = Dba::escape($data['host']); + $name = Dba::escape($data['name']); + $pass = Dba::escape($data['password']); - $sql = "UPDATE `localplay_httpq` SET `host`='$host', `port`='$port', `name`='$name', `password`='$pass' WHERE `id`='$uid'"; - $db_results = Dba::write($sql); + $sql = "UPDATE `localplay_httpq` SET `host`='$host', `port`='$port', `name`='$name', `password`='$pass' WHERE `id`='$uid'"; + $db_results = Dba::write($sql); - return true; + return true; } // update_instance @@ -210,25 +210,25 @@ class AmpacheHttpq extends localplay_controller { $fields['port'] = array('description' => T_('Port'),'type'=>'textbox'); $fields['password'] = array('description' => T_('Password'),'type'=>'textbox'); - return $fields; + return $fields; - } // instance_fields + } // instance_fields - /** - * get_instance - * This returns a single instance and all its variables - */ - public function get_instance($instance='') { + /** + * get_instance + * This returns a single instance and all its variables + */ + public function get_instance($instance='') { - $instance = $instance ? $instance : Config::get('httpq_active'); - $instance = Dba::escape($instance); + $instance = $instance ? $instance : Config::get('httpq_active'); + $instance = Dba::escape($instance); - $sql = "SELECT * FROM `localplay_httpq` WHERE `id`='$instance'"; - $db_results = Dba::read($sql); + $sql = "SELECT * FROM `localplay_httpq` WHERE `id`='$instance'"; + $db_results = Dba::read($sql); - $row = Dba::fetch_assoc($db_results); + $row = Dba::fetch_assoc($db_results); - return $row; + return $row; } // get_instance @@ -238,17 +238,17 @@ class AmpacheHttpq extends localplay_controller { */ public function set_active_instance($uid,$user_id='') { - // Not an admin? bubkiss! - if (!$GLOBALS['user']->has_access('100')) { - $user_id = $GLOBALS['user']->id; - } + // Not an admin? bubkiss! + if (!$GLOBALS['user']->has_access('100')) { + $user_id = $GLOBALS['user']->id; + } - $user_id = $user_id ? $user_id : $GLOBALS['user']->id; + $user_id = $user_id ? $user_id : $GLOBALS['user']->id; - Preference::update('httpq_active',$user_id,intval($uid)); - Config::set('httpq_active', intval($uid), true); + Preference::update('httpq_active',$user_id,intval($uid)); + Config::set('httpq_active', intval($uid), true); - return true; + return true; } // set_active_instance @@ -262,147 +262,147 @@ class AmpacheHttpq extends localplay_controller { } // get_active_instance - /** - * add_url - * This is the new hotness - */ - public function add_url(Stream_URL $url) { - if (is_null($this->_httpq->add($url->title, $url->url))) { - debug_event('httpq', 'add_url failed to add ' . $url, 1); - return false; - } - - return true; - } + /** + * add_url + * This is the new hotness + */ + public function add_url(Stream_URL $url) { + if (is_null($this->_httpq->add($url->title, $url->url))) { + debug_event('httpq', 'add_url failed to add ' . $url, 1); + return false; + } + + return true; + } - /** - * delete_track - * This must take an ID (as returned by our get function) - * and delete it from httpQ - */ - public function delete_track($object_id) { + /** + * delete_track + * This must take an ID (as returned by our get function) + * and delete it from httpQ + */ + public function delete_track($object_id) { - if (is_null($this->_httpq->delete_pos($object_id))) { - debug_event('httpq', 'Unable to delete ' . $object_id . ' from httpQ', 1); - return false; - } + if (is_null($this->_httpq->delete_pos($object_id))) { + debug_event('httpq', 'Unable to delete ' . $object_id . ' from httpQ', 1); + return false; + } - return true; + return true; - } // delete_track + } // delete_track - /** - * clear_playlist - */ - public function clear_playlist() { + /** + * clear_playlist + */ + public function clear_playlist() { - if (is_null($this->_httpq->clear())) { return false; } + if (is_null($this->_httpq->clear())) { return false; } - // If the clear worked we should stop it! - $this->stop(); + // If the clear worked we should stop it! + $this->stop(); - return true; + return true; - } // clear_playlist + } // clear_playlist - /** - * play - * This just tells httpQ to start playing, it does not - * take any arguments - */ - public function play() { - // A play when it's already playing causes a track restart, - // so doublecheck its state - if ($this->_httpq->state() == 'play') { - return true; - } + /** + * play + * This just tells httpQ to start playing, it does not + * take any arguments + */ + public function play() { + // A play when it's already playing causes a track restart, + // so doublecheck its state + if ($this->_httpq->state() == 'play') { + return true; + } - if (is_null($this->_httpq->play())) { return false; } - return true; - } // play + if (is_null($this->_httpq->play())) { return false; } + return true; + } // play - /** - * stop - * This just tells httpQ to stop playing, it does not take - * any arguments - */ - public function stop() { + /** + * stop + * This just tells httpQ to stop playing, it does not take + * any arguments + */ + public function stop() { - if (is_null($this->_httpq->stop())) { return false; } - return true; + if (is_null($this->_httpq->stop())) { return false; } + return true; - } // stop + } // stop - /** - * skip - * This tells httpQ to skip to the specified song - */ - public function skip($song) { + /** + * skip + * This tells httpQ to skip to the specified song + */ + public function skip($song) { - if (is_null($this->_httpq->skip($song))) { return false; } - return true; + if (is_null($this->_httpq->skip($song))) { return false; } + return true; - } // skip + } // skip - /** - * This tells Httpq to increase the volume by WinAmps default amount - */ - public function volume_up() { + /** + * This tells Httpq to increase the volume by WinAmps default amount + */ + public function volume_up() { - if (is_null($this->_httpq->volume_up())) { return false; } - return true; + if (is_null($this->_httpq->volume_up())) { return false; } + return true; - } // volume_up + } // volume_up - /** - * This tells httpQ to decrease the volume by Winamp's default amount - */ - public function volume_down() { + /** + * This tells httpQ to decrease the volume by Winamp's default amount + */ + public function volume_down() { - if (is_null($this->_httpq->volume_down())) { return false; } - return true; + if (is_null($this->_httpq->volume_down())) { return false; } + return true; - } // volume_down + } // volume_down - /** - * next - * This just tells httpQ to skip to the next song - */ - public function next() { + /** + * next + * This just tells httpQ to skip to the next song + */ + public function next() { - if (is_null($this->_httpq->next())) { return false; } + if (is_null($this->_httpq->next())) { return false; } - return true; + return true; - } // next + } // next - /** - * prev - * This just tells httpQ to skip to the prev song - */ - public function prev() { + /** + * prev + * This just tells httpQ to skip to the prev song + */ + public function prev() { - if (is_null($this->_httpq->prev())) { return false; } + if (is_null($this->_httpq->prev())) { return false; } - return true; + return true; - } // prev + } // prev - /** - * pause - * This tells httpQ to pause the current song - */ - public function pause() { + /** + * pause + * This tells httpQ to pause the current song + */ + public function pause() { - if (is_null($this->_httpq->pause())) { return false; } - return true; + if (is_null($this->_httpq->pause())) { return false; } + return true; - } // pause + } // pause /** * volume * This tells httpQ to set the volume to the specified amount this - * is 0-100 + * is 0-100 */ public function volume($volume) { @@ -414,19 +414,19 @@ class AmpacheHttpq extends localplay_controller { /** * repeat * This tells httpQ to set the repeating the playlist (i.e. loop) to - * either on or off + * either on or off */ public function repeat($state) { - if (is_null($this->_httpq->repeat($state))) { return false; } - return true; + if (is_null($this->_httpq->repeat($state))) { return false; } + return true; } // repeat /** * random * This tells httpQ to turn on or off the playing of songs from the - * playlist in random order + * playlist in random order */ public function random($onoff) { @@ -435,29 +435,29 @@ class AmpacheHttpq extends localplay_controller { } // random - /** - * get - * This functions returns an array containing information about - * The songs that httpQ currently has in its playlist. This must be - * done in a standardized fashion - */ - public function get() { + /** + * get + * This functions returns an array containing information about + * The songs that httpQ currently has in its playlist. This must be + * done in a standardized fashion + */ + public function get() { - /* Get the Current Playlist */ - $list = $this->_httpq->get_tracks(); + /* Get the Current Playlist */ + $list = $this->_httpq->get_tracks(); - if (!$list) { return array(); } + if (!$list) { return array(); } - $songs = explode("::",$list); + $songs = explode("::",$list); - foreach ($songs as $key=>$entry) { - $data = array(); + foreach ($songs as $key=>$entry) { + $data = array(); - /* Required Elements */ - $data['id'] = $key; - $data['raw'] = $entry; + /* Required Elements */ + $data['id'] = $key; + $data['raw'] = $entry; - $url_data = $this->parse_url($entry); + $url_data = $this->parse_url($entry); switch ($url_data['primary_key']) { case 'oid': $song = new Song($url_data['oid']); @@ -470,10 +470,10 @@ class AmpacheHttpq extends localplay_controller { $data['name'] = T_('Democratic') . ' - ' . $democratic->name; $data['link'] = ''; break; - case 'random': - $data['name'] = T_('Random') . ' - ' . scrub_out(ucfirst($url_data['type'])); - $data['link'] = ''; - break; + case 'random': + $data['name'] = T_('Random') . ' - ' . scrub_out(ucfirst($url_data['type'])); + $data['link'] = ''; + break; default: /* If we don't know it, look up by filename */ $filename = Dba::escape($entry['file']); @@ -498,70 +498,70 @@ class AmpacheHttpq extends localplay_controller { break; } // end switch on type } // end if results - else { - $data['name'] = basename($data['raw']); - $data['link'] = basename($data['raw']); - } + else { + $data['name'] = basename($data['raw']); + $data['link'] = basename($data['raw']); + } break; } // end switch on primary key type - $data['track'] = $key+1; + $data['track'] = $key+1; - $results[] = $data; + $results[] = $data; - } // foreach playlist items + } // foreach playlist items - return $results; + return $results; - } // get + } // get - /** - * status - * This returns bool/int values for features, loop, repeat and any other features - * That this localplay method supports. required function - */ - public function status() { + /** + * status + * This returns bool/int values for features, loop, repeat and any other features + * That this localplay method supports. required function + */ + public function status() { - /* Construct the Array */ - $array['state'] = $this->_httpq->state(); - $array['volume'] = $this->_httpq->get_volume(); - $array['repeat'] = $this->_httpq->get_repeat(); - $array['random'] = $this->_httpq->get_random(); - $array['track'] = $this->_httpq->get_now_playing(); - $url_data = $this->parse_url($array['track']); + /* Construct the Array */ + $array['state'] = $this->_httpq->state(); + $array['volume'] = $this->_httpq->get_volume(); + $array['repeat'] = $this->_httpq->get_repeat(); + $array['random'] = $this->_httpq->get_random(); + $array['track'] = $this->_httpq->get_now_playing(); + $url_data = $this->parse_url($array['track']); - if (isset($url_data['oid'])) { - $song = new Song($url_data['oid']); - $array['track_title'] = $song->title; - $array['track_artist'] = $song->get_artist_name(); - $array['track_album'] = $song->get_album_name(); - } - else { - $array['track_title'] = basename($array['track']); - } + if (isset($url_data['oid'])) { + $song = new Song($url_data['oid']); + $array['track_title'] = $song->title; + $array['track_artist'] = $song->get_artist_name(); + $array['track_album'] = $song->get_album_name(); + } + else { + $array['track_title'] = basename($array['track']); + } - return $array; + return $array; - } // status + } // status - /** - * connect - * This functions creates the connection to httpQ and returns - * a boolean value for the status, to save time this handle - * is stored in this class - */ - public function connect() { + /** + * connect + * This functions creates the connection to httpQ and returns + * a boolean value for the status, to save time this handle + * is stored in this class + */ + public function connect() { - $options = self::get_instance(); - $this->_httpq = new HttpQPlayer($options['host'],$options['password'],$options['port']); + $options = self::get_instance(); + $this->_httpq = new HttpQPlayer($options['host'],$options['password'],$options['port']); - // Test our connection by retriving the version - if (!is_null($this->_httpq->version())) { return true; } + // Test our connection by retriving the version + if (!is_null($this->_httpq->version())) { return true; } - return false; + return false; - } // connect + } // connect } //end of AmpacheHttpq diff --git a/modules/localplay/mpd.controller.php b/modules/localplay/mpd.controller.php index 0fcacc60..3949697d 100644 --- a/modules/localplay/mpd.controller.php +++ b/modules/localplay/mpd.controller.php @@ -1,5 +1,5 @@ <?php -/* vim:set tabstop=8 softtabstop=8 shiftwidth=8 noexpandtab: */ +/* vim:set softtabstop=4 shiftwidth=4 expandtab: */ /** * * LICENSE: GNU General Public License, version 2 (GPLv2) @@ -29,65 +29,65 @@ */ class AmpacheMpd extends localplay_controller { - /* Variables */ - private $version = '000003'; - private $description = 'Controls an instance of MPD'; - - private $_add_count = 0; + /* Variables */ + private $version = '000003'; + private $description = 'Controls an instance of MPD'; + + private $_add_count = 0; - /* Constructed variables */ - private $_mpd; + /* Constructed variables */ + private $_mpd; - /** - * Constructor - * This returns the array map for the localplay object - * REQUIRED for Localplay - */ - public function __construct() { + /** + * Constructor + * This returns the array map for the localplay object + * REQUIRED for Localplay + */ + public function __construct() { - /* Do a Require Once On the needed Libraries */ - require_once Config::get('prefix') . '/modules/mpd/mpd.class.php'; + /* Do a Require Once On the needed Libraries */ + require_once Config::get('prefix') . '/modules/mpd/mpd.class.php'; - } // AmpacheMpd + } // AmpacheMpd - /** - * get_description - * Returns the description - */ - public function get_description() { + /** + * get_description + * Returns the description + */ + public function get_description() { - return $this->description; + return $this->description; - } // get_description + } // get_description - /** - * get_version - * This returns the version information - */ - public function get_version() { + /** + * get_version + * This returns the version information + */ + public function get_version() { - return $this->version; + return $this->version; - } // get_version + } // get_version - /** - * is_installed - * This returns true or false if MPD controller is installed - */ - public function is_installed() { + /** + * is_installed + * This returns true or false if MPD controller is installed + */ + public function is_installed() { $sql = "DESCRIBE `localplay_mpd`"; $db_results = Dba::read($sql); return Dba::num_rows($db_results); - } // is_installed + } // is_installed - /** - * install - * This function installs the MPD localplay controller - */ - public function install() { + /** + * install + * This function installs the MPD localplay controller + */ + public function install() { /* We need to create the MPD table */ $sql = "CREATE TABLE `localplay_mpd` ( `id` INT( 11 ) UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY , " . @@ -100,312 +100,312 @@ class AmpacheMpd extends localplay_controller { ") ENGINE = MYISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci"; $db_results = Dba::write($sql); - // Add an internal preference for the users current active instance - Preference::insert('mpd_active','MPD Active Instance','0','25','integer','internal'); - User::rebuild_all_preferences(); + // Add an internal preference for the users current active instance + Preference::insert('mpd_active','MPD Active Instance','0','25','integer','internal'); + User::rebuild_all_preferences(); return true; - } // install + } // install - /** - * uninstall - * This removes the localplay controller - */ - public function uninstall() { + /** + * uninstall + * This removes the localplay controller + */ + public function uninstall() { $sql = "DROP TABLE `localplay_mpd`"; $db_results = Dba::write($sql); - Preference::delete('mpd_active'); + Preference::delete('mpd_active'); return true; - } // uninstall + } // uninstall - /** - * add_instance - * This takes key'd data and inserts a new MPD instance - */ - public function add_instance($data) { + /** + * add_instance + * This takes key'd data and inserts a new MPD instance + */ + public function add_instance($data) { - foreach ($data as $key=>$value) { - switch ($key) { - case 'name': - case 'host': - case 'port': - case 'password': - ${$key} = Dba::escape($value); - break; - default: + foreach ($data as $key=>$value) { + switch ($key) { + case 'name': + case 'host': + case 'port': + case 'password': + ${$key} = Dba::escape($value); + break; + default: - break; - } // end switch - } // end foreach + break; + } // end switch + } // end foreach - $user_id = Dba::escape($GLOBALS['user']->id); + $user_id = Dba::escape($GLOBALS['user']->id); - $sql = "INSERT INTO `localplay_mpd` (`name`,`host`,`port`,`password`,`owner`) " . - "VALUES ('$name','$host','$port','$password','$user_id')"; - $db_results = Dba::write($sql); + $sql = "INSERT INTO `localplay_mpd` (`name`,`host`,`port`,`password`,`owner`) " . + "VALUES ('$name','$host','$port','$password','$user_id')"; + $db_results = Dba::write($sql); - return $db_results; + return $db_results; - } // add_instance + } // add_instance - /** - * delete_instance - * This takes a UID and deletes the instance in question - */ - public function delete_instance($uid) { + /** + * delete_instance + * This takes a UID and deletes the instance in question + */ + public function delete_instance($uid) { - $uid = Dba::escape($uid); + $uid = Dba::escape($uid); - // Go ahead and delete this mofo! - $sql = "DELETE FROM `localplay_mpd` WHERE `id`='$uid'"; - $db_results = Dba::write($sql); + // Go ahead and delete this mofo! + $sql = "DELETE FROM `localplay_mpd` WHERE `id`='$uid'"; + $db_results = Dba::write($sql); - return true; + return true; - } // delete_instance + } // delete_instance - /** - * get_instances - * This returns a key'd array of the instance information with - * [UID]=>[NAME] - */ - public function get_instances() { + /** + * get_instances + * This returns a key'd array of the instance information with + * [UID]=>[NAME] + */ + public function get_instances() { - $sql = "SELECT * FROM `localplay_mpd` ORDER BY `name`"; - $db_results = Dba::read($sql); + $sql = "SELECT * FROM `localplay_mpd` ORDER BY `name`"; + $db_results = Dba::read($sql); - $results = array(); + $results = array(); - while ($row = Dba::fetch_assoc($db_results)) { - $results[$row['id']] = $row['name']; - } + while ($row = Dba::fetch_assoc($db_results)) { + $results[$row['id']] = $row['name']; + } - return $results; + return $results; - } // get_instances + } // get_instances - /** - * get_instance - * This returns the specified instance and all it's pretty variables - * If no instance is passed current is used - */ - public function get_instance($instance='') { + /** + * get_instance + * This returns the specified instance and all it's pretty variables + * If no instance is passed current is used + */ + public function get_instance($instance='') { - $instance = $instance ? $instance : Config::get('mpd_active'); - $instance = Dba::escape($instance); + $instance = $instance ? $instance : Config::get('mpd_active'); + $instance = Dba::escape($instance); - $sql = "SELECT * FROM `localplay_mpd` WHERE `id`='$instance'"; - $db_results = Dba::read($sql); + $sql = "SELECT * FROM `localplay_mpd` WHERE `id`='$instance'"; + $db_results = Dba::read($sql); - $row = Dba::fetch_assoc($db_results); + $row = Dba::fetch_assoc($db_results); - return $row; + return $row; - } // get_instance + } // get_instance - /** - * update_instance - * This takes an ID and an array of data and updates the instance specified - */ - public function update_instance($uid,$data) { + /** + * update_instance + * This takes an ID and an array of data and updates the instance specified + */ + public function update_instance($uid,$data) { - $uid = Dba::escape($uid); - $host = $data['host'] ? Dba::escape($data['host']) : '127.0.0.1'; - $port = $data['port'] ? Dba::escape($data['port']) : '6600'; - $name = Dba::escape($data['name']); - $pass = Dba::escape($data['password']); - - $sql = "UPDATE `localplay_mpd` SET `host`='$host', `port`='$port', `name`='$name', `password`='$pass' WHERE `id`='$uid'"; - $db_results = Dba::write($sql); - - return true; - - } // update_instance - - /** - * instance_fields - * This returns a key'd array of [NAME]=>array([DESCRIPTION]=>VALUE,[TYPE]=>VALUE) for the - * fields so that we can on-the-fly generate a form - */ - public function instance_fields() { - - $fields['name'] = array('description' => T_('Instance Name'),'type'=>'textbox'); - $fields['host'] = array('description' => T_('Hostname'),'type'=>'textbox'); - $fields['port'] = array('description' => T_('Port'),'type'=>'textbox'); - $fields['password'] = array('description' => T_('Password'),'type'=>'textbox'); - - return $fields; - - } // instance_fields - - /** - * set_active_instance - * This sets the specified instance as the 'active' one - */ - public function set_active_instance($uid,$user_id='') { - - // Not an admin? bubkiss! - if (!$GLOBALS['user']->has_access('100')) { - $user_id = $GLOBALS['user']->id; - } - - $user_id = $user_id ? $user_id : $GLOBALS['user']->id; - - Preference::update('mpd_active',$user_id,intval($uid)); - Config::set('mpd_active', intval($uid), true); - - return true; - - } // set_active_instance - - /** - * get_active_instance - * This returns the UID of the current active instance - * false if none are active - */ - public function get_active_instance() { - - - } // get_active_instance - - /** - * add_url - * This is the new hotness - */ - public function add_url(Stream_URL $url) { - // If we haven't added anything then maybe we should clear the - // playlist. - if ($this->_add_count < 1) { - $this->_mpd->RefreshInfo(); - if ($this->_mpd->status['state'] == mpd::STATE_STOPPED) { - $this->clear_playlist(); - } - } - - if (!$this->_mpd->PlAdd($url->url)) { - debug_event('mpd', 'add_url failed to add: ' . json_encode($url), 1); - return false; - } - - $this->_add_count++; - return true; - } - - /** - * delete_track - * This must take a single ID (as returned by the get function) - * and delete it from the current playlist - */ - public function delete_track($object_id) { - return $this->_mpd->PLRemove($object_id); - } // delete_track - - /** - * clear_playlist - * This deletes the entire MPD playlist... nuff said - */ - public function clear_playlist() { - return $this->_mpd->PLClear(); - } // clear_playlist - - /** - * play - * This just tells MPD to start playing, it does not - * take any arguments - */ - public function play() { - return $this->_mpd->Play(); - } // play - - /** - * stop - * This just tells MPD to stop playing, it does not take - * any arguments - */ - public function stop() { - return $this->_mpd->Stop(); - } // stop - - /** - * skip - * This tells MPD to skip to the specified song - */ - public function skip($song) { - - if (!$this->_mpd->SkipTo($song)) { return false; } - sleep(2); - $this->stop(); - sleep(2); - $this->play(); - return true; - - } // skip - - /** - * This tells MPD to increase the volume by 5 - */ - public function volume_up() { - return $this->_mpd->AdjustVolume('5'); - } // volume_up - - /** - * This tells MPD to decrease the volume by 5 - */ - public function volume_down() { - return $this->_mpd->AdjustVolume('-5'); - } // volume_down - - /** - * next - * This just tells MPD to skip to the next song - */ - public function next() { - return $this->_mpd->Next(); - } // next - - /** - * prev - * This just tells MPD to skip to the prev song - */ - public function prev() { - return $this->_mpd->Previous(); - } // prev - - /** - * pause - * This tells MPD to pause the current song - */ - public function pause() { - return $this->_mpd->Pause(); - } // pause + $uid = Dba::escape($uid); + $host = $data['host'] ? Dba::escape($data['host']) : '127.0.0.1'; + $port = $data['port'] ? Dba::escape($data['port']) : '6600'; + $name = Dba::escape($data['name']); + $pass = Dba::escape($data['password']); + + $sql = "UPDATE `localplay_mpd` SET `host`='$host', `port`='$port', `name`='$name', `password`='$pass' WHERE `id`='$uid'"; + $db_results = Dba::write($sql); + + return true; + + } // update_instance + + /** + * instance_fields + * This returns a key'd array of [NAME]=>array([DESCRIPTION]=>VALUE,[TYPE]=>VALUE) for the + * fields so that we can on-the-fly generate a form + */ + public function instance_fields() { + + $fields['name'] = array('description' => T_('Instance Name'),'type'=>'textbox'); + $fields['host'] = array('description' => T_('Hostname'),'type'=>'textbox'); + $fields['port'] = array('description' => T_('Port'),'type'=>'textbox'); + $fields['password'] = array('description' => T_('Password'),'type'=>'textbox'); + + return $fields; + + } // instance_fields + + /** + * set_active_instance + * This sets the specified instance as the 'active' one + */ + public function set_active_instance($uid,$user_id='') { + + // Not an admin? bubkiss! + if (!$GLOBALS['user']->has_access('100')) { + $user_id = $GLOBALS['user']->id; + } + + $user_id = $user_id ? $user_id : $GLOBALS['user']->id; + + Preference::update('mpd_active',$user_id,intval($uid)); + Config::set('mpd_active', intval($uid), true); + + return true; + + } // set_active_instance + + /** + * get_active_instance + * This returns the UID of the current active instance + * false if none are active + */ + public function get_active_instance() { + + + } // get_active_instance + + /** + * add_url + * This is the new hotness + */ + public function add_url(Stream_URL $url) { + // If we haven't added anything then maybe we should clear the + // playlist. + if ($this->_add_count < 1) { + $this->_mpd->RefreshInfo(); + if ($this->_mpd->status['state'] == mpd::STATE_STOPPED) { + $this->clear_playlist(); + } + } + + if (!$this->_mpd->PlAdd($url->url)) { + debug_event('mpd', 'add_url failed to add: ' . json_encode($url), 1); + return false; + } + + $this->_add_count++; + return true; + } + + /** + * delete_track + * This must take a single ID (as returned by the get function) + * and delete it from the current playlist + */ + public function delete_track($object_id) { + return $this->_mpd->PLRemove($object_id); + } // delete_track + + /** + * clear_playlist + * This deletes the entire MPD playlist... nuff said + */ + public function clear_playlist() { + return $this->_mpd->PLClear(); + } // clear_playlist + + /** + * play + * This just tells MPD to start playing, it does not + * take any arguments + */ + public function play() { + return $this->_mpd->Play(); + } // play + + /** + * stop + * This just tells MPD to stop playing, it does not take + * any arguments + */ + public function stop() { + return $this->_mpd->Stop(); + } // stop + + /** + * skip + * This tells MPD to skip to the specified song + */ + public function skip($song) { + + if (!$this->_mpd->SkipTo($song)) { return false; } + sleep(2); + $this->stop(); + sleep(2); + $this->play(); + return true; + + } // skip + + /** + * This tells MPD to increase the volume by 5 + */ + public function volume_up() { + return $this->_mpd->AdjustVolume('5'); + } // volume_up + + /** + * This tells MPD to decrease the volume by 5 + */ + public function volume_down() { + return $this->_mpd->AdjustVolume('-5'); + } // volume_down + + /** + * next + * This just tells MPD to skip to the next song + */ + public function next() { + return $this->_mpd->Next(); + } // next + + /** + * prev + * This just tells MPD to skip to the prev song + */ + public function prev() { + return $this->_mpd->Previous(); + } // prev + + /** + * pause + * This tells MPD to pause the current song + */ + public function pause() { + return $this->_mpd->Pause(); + } // pause /** * volume * This tells MPD to set the volume to the parameter */ - public function volume($volume) { + public function volume($volume) { return $this->_mpd->SetVolume($volume); } // volume /** * repeat * This tells MPD to set the repeating the playlist (i.e. loop) to either - * on or off. + * on or off. */ - public function repeat($state) { - return $this->_mpd->SetRepeat($state); + public function repeat($state) { + return $this->_mpd->SetRepeat($state); } // repeat /** * random * This tells MPD to turn on or off the playing of songs from the - * playlist in random order. + * playlist in random order. */ public function random($onoff) { return $this->_mpd->SetRandom($onoff); @@ -416,137 +416,137 @@ class AmpacheMpd extends localplay_controller { * This tells MPD to move a song */ public function move($source, $destination) { - return $this->_mpd->PLMoveTrack($source, $destination); - } // move - - /** - * get_songs - * This functions returns an array containing information about - * the songs that MPD currently has in its playlist. This must be - * done in a standardized fashion - */ - public function get() { - // If we don't have the playlist yet, pull it - if (!isset($this->_mpd->playlist)) { - $this->_mpd->RefreshInfo(); - } - - /* Get the Current Playlist */ - $playlist = $this->_mpd->playlist; - - foreach ($playlist as $entry) { - $data = array(); - - /* Required Elements */ - $data['id'] = $entry['Pos']; - $data['raw'] = $entry['file']; - - $url_data = $this->parse_url($entry['file']); - - switch ($url_data['primary_key']) { - case 'oid': - $song = new Song($url_data['oid']); - $song->format(); - $data['name'] = $song->f_title . ' - ' . $song->f_album . ' - ' . $song->f_artist; - $data['link'] = $song->f_link; - break; - case 'demo_id': - $democratic = new Democratic($url_data['demo_id']); - $data['name'] = T_('Democratic') . ' - ' . $democratic->name; - $data['link'] = ''; - break; - case 'random': - $data['name'] = T_('Random') . ' - ' . scrub_out(ucfirst($url_data['type'])); - $data['link'] = ''; - break; - default: - - /* If we don't know it, look up by filename */ - $filename = Dba::escape($entry['file']); - $sql = "SELECT `id`,'song' AS `type` FROM `song` WHERE `file` LIKE '%$filename' " . - "UNION ALL " . - "SELECT `id`,'radio' AS `type` FROM `live_stream` WHERE `url`='$filename' "; - - $db_results = Dba::read($sql); - if ($row = Dba::fetch_assoc($db_results)) { - $media = new $row['type']($row['id']); - $media->format(); - switch ($row['type']) { - case 'song': - $data['name'] = $media->f_title . ' - ' . $media->f_album . ' - ' . $media->f_artist; - $data['link'] = $media->f_link; - break; - case 'radio': - $frequency = $media->frequency ? '[' . $media->frequency . ']' : ''; - $site_url = $media->site_url ? '(' . $media->site_url . ')' : ''; - $data['name'] = "$media->name $frequency $site_url"; - $data['link'] = $media->site_url; - break; - } // end switch on type - } // end if results - - else { - $data['name'] = T_('Unknown'); - $data['link'] = ''; - } - - break; - } // end switch on primary key type - - /* Optional Elements */ - $data['track'] = $entry['Pos']+1; - - $results[] = $data; - - } // foreach playlist items - - return $results; - - } // get - - /** - * get_status - * This returns bool/int values for features, loop, repeat and any other - * features that this localplay method supports. - */ - public function status() { - - $track = $this->_mpd->status['song']; - - /* Construct the Array */ - $array['state'] = $this->_mpd->status['state']; - $array['volume'] = $this->_mpd->status['volume']; - $array['repeat'] = $this->_mpd->status['repeat']; - $array['random'] = $this->_mpd->status['random']; - $array['track'] = $track+1; - - $url_data = $this->parse_url($this->_mpd->playlist[$track]['file']); - $song = new Song($url_data['oid']); - $array['track_title'] = $song->title; - $array['track_artist'] = $song->get_artist_name(); - $array['track_album'] = $song->get_album_name(); - - return $array; - - } // get_status - - /** - * connect - * This functions creates the connection to MPD and returns - * a boolean value for the status, to save time this handle - * is stored in this class - */ - public function connect() { - - // Look at the current instance and pull the options for said instance - $options = self::get_instance(); - $this->_mpd = new mpd($options['host'], $options['port'], $options['password'], 'debug_event'); - - if ($this->_mpd->connected) { return true; } - - return false; - - } // connect + return $this->_mpd->PLMoveTrack($source, $destination); + } // move + + /** + * get_songs + * This functions returns an array containing information about + * the songs that MPD currently has in its playlist. This must be + * done in a standardized fashion + */ + public function get() { + // If we don't have the playlist yet, pull it + if (!isset($this->_mpd->playlist)) { + $this->_mpd->RefreshInfo(); + } + + /* Get the Current Playlist */ + $playlist = $this->_mpd->playlist; + + foreach ($playlist as $entry) { + $data = array(); + + /* Required Elements */ + $data['id'] = $entry['Pos']; + $data['raw'] = $entry['file']; + + $url_data = $this->parse_url($entry['file']); + + switch ($url_data['primary_key']) { + case 'oid': + $song = new Song($url_data['oid']); + $song->format(); + $data['name'] = $song->f_title . ' - ' . $song->f_album . ' - ' . $song->f_artist; + $data['link'] = $song->f_link; + break; + case 'demo_id': + $democratic = new Democratic($url_data['demo_id']); + $data['name'] = T_('Democratic') . ' - ' . $democratic->name; + $data['link'] = ''; + break; + case 'random': + $data['name'] = T_('Random') . ' - ' . scrub_out(ucfirst($url_data['type'])); + $data['link'] = ''; + break; + default: + + /* If we don't know it, look up by filename */ + $filename = Dba::escape($entry['file']); + $sql = "SELECT `id`,'song' AS `type` FROM `song` WHERE `file` LIKE '%$filename' " . + "UNION ALL " . + "SELECT `id`,'radio' AS `type` FROM `live_stream` WHERE `url`='$filename' "; + + $db_results = Dba::read($sql); + if ($row = Dba::fetch_assoc($db_results)) { + $media = new $row['type']($row['id']); + $media->format(); + switch ($row['type']) { + case 'song': + $data['name'] = $media->f_title . ' - ' . $media->f_album . ' - ' . $media->f_artist; + $data['link'] = $media->f_link; + break; + case 'radio': + $frequency = $media->frequency ? '[' . $media->frequency . ']' : ''; + $site_url = $media->site_url ? '(' . $media->site_url . ')' : ''; + $data['name'] = "$media->name $frequency $site_url"; + $data['link'] = $media->site_url; + break; + } // end switch on type + } // end if results + + else { + $data['name'] = T_('Unknown'); + $data['link'] = ''; + } + + break; + } // end switch on primary key type + + /* Optional Elements */ + $data['track'] = $entry['Pos']+1; + + $results[] = $data; + + } // foreach playlist items + + return $results; + + } // get + + /** + * get_status + * This returns bool/int values for features, loop, repeat and any other + * features that this localplay method supports. + */ + public function status() { + + $track = $this->_mpd->status['song']; + + /* Construct the Array */ + $array['state'] = $this->_mpd->status['state']; + $array['volume'] = $this->_mpd->status['volume']; + $array['repeat'] = $this->_mpd->status['repeat']; + $array['random'] = $this->_mpd->status['random']; + $array['track'] = $track+1; + + $url_data = $this->parse_url($this->_mpd->playlist[$track]['file']); + $song = new Song($url_data['oid']); + $array['track_title'] = $song->title; + $array['track_artist'] = $song->get_artist_name(); + $array['track_album'] = $song->get_album_name(); + + return $array; + + } // get_status + + /** + * connect + * This functions creates the connection to MPD and returns + * a boolean value for the status, to save time this handle + * is stored in this class + */ + public function connect() { + + // Look at the current instance and pull the options for said instance + $options = self::get_instance(); + $this->_mpd = new mpd($options['host'], $options['port'], $options['password'], 'debug_event'); + + if ($this->_mpd->connected) { return true; } + + return false; + + } // connect } //end of AmpacheMpd diff --git a/modules/localplay/vlc.controller.php b/modules/localplay/vlc.controller.php index 0765a194..60ef68d0 100644 --- a/modules/localplay/vlc.controller.php +++ b/modules/localplay/vlc.controller.php @@ -1,5 +1,5 @@ <?php -/* vim:set tabstop=8 softtabstop=8 shiftwidth=8 noexpandtab: */ +/* vim:set softtabstop=4 shiftwidth=4 expandtab: */ /** * * LICENSE: GNU General Public License, version 2 (GPLv2) @@ -274,12 +274,12 @@ class AmpacheVlc extends localplay_controller { } // get_active_instance public function add_url(Stream_URL $url) { - if (is_null($this->_vlc->add($url->title, $url->url))) { - debug_event('vlc', 'add_url failed to add: ' . json_encode($url), 1); - return false; - } + if (is_null($this->_vlc->add($url->title, $url->url))) { + debug_event('vlc', 'add_url failed to add: ' . json_encode($url), 1); + return false; + } - return true; + return true; } /** diff --git a/modules/mpd/mpd.class.php b/modules/mpd/mpd.class.php index 5dacca64..ca9ca52c 100644 --- a/modules/mpd/mpd.class.php +++ b/modules/mpd/mpd.class.php @@ -1,5 +1,5 @@ <?php -/* vim:set tabstop=4 softtabstop=4 shiftwidth=4 expandtab: */ +/* vim:set softtabstop=4 shiftwidth=4 expandtab: */ /* * mpd.class.php - PHP Object Interface to the MPD Music Player Daemon * Version 1.3 diff --git a/modules/plugins/Lastfm.plugin.php b/modules/plugins/Lastfm.plugin.php index 4b6fe244..833feea1 100644 --- a/modules/plugins/Lastfm.plugin.php +++ b/modules/plugins/Lastfm.plugin.php @@ -1,5 +1,5 @@ <?php -/* vim:set tabstop=8 softtabstop=8 shiftwidth=8 noexpandtab: */ +/* vim:set softtabstop=4 shiftwidth=4 expandtab: */ /** * * LICENSE: GNU General Public License, version 2 (GPLv2) @@ -22,216 +22,216 @@ class AmpacheLastfm { - public $name ='Last.FM'; - public $description ='Records your played songs to your Last.FM Account'; - public $url =''; - public $version ='000004'; - public $min_ampache ='360003'; - public $max_ampache ='999999'; - - // These are internal settings used by this class, run this->load to - // fill them out - private $username; - private $password; - private $hostname; - private $port; - private $path; - private $challenge; - private $user_id; - - /** - * Constructor - * This function does nothing... - */ - public function __construct() { - - return true; - - } // constructor - - /** - * install - * This is a required plugin function. It inserts our preferences - * into Ampache - */ - public function install() { - - // Check and see if it's already installed (they've just hit refresh, those dorks) - if (Preference::exists('lastfm_user')) { return false; } - - Preference::insert('lastfm_user','Last.FM Username','','25','string','plugins'); - Preference::insert('lastfm_md5_pass','Last.FM Password','','25','string','plugins'); - Preference::insert('lastfm_port','Last.FM Submit Port','','25','string','internal'); - Preference::insert('lastfm_host','Last.FM Submit Host','','25','string','internal'); - Preference::insert('lastfm_url','Last.FM Submit URL','','25','string','internal'); - Preference::insert('lastfm_challenge','Last.FM Submit Challenge','','25','string','internal'); - - return true; - - } // install - - /** - * uninstall - * This is a required plugin function. It removes our preferences from - * the database returning it to its original form - */ - public function uninstall() { - - Preference::delete('lastfm_md5_pass'); - Preference::delete('lastfm_user'); - Preference::delete('lastfm_url'); - Preference::delete('lastfm_host'); - Preference::delete('lastfm_port'); - Preference::delete('lastfm_challenge'); - - } // uninstall - - /** - * upgrade - * This is a recommended plugin function - */ - public function upgrade() { - $from_version = Plugin::get_plugin_version($this->name); - if ($from_version < 4) { - Preference::rename('lastfm_pass', 'lastfm_md5_pass'); - } - return true; - } // upgrade - - /** - * save_songplay - * This takes care of queueing and then submitting the tracks. - */ - public function save_songplay($song) { - - // Let's pull the last song submitted by this user - $previous = Stats::get_last_song($this->user_id); - - $diff = time() - $previous['date']; - - // Make sure it wasn't within the last min - if ($diff < 60) { - debug_event($this->name,'Last song played within ' . $diff . ' seconds, not recording stats','3'); - return false; - } - - if ($song->time < 30) { - debug_event($this->name,'Song less then 30 seconds not queueing','3'); - return false; - } - - // Make sure there's actually a username and password before we keep going - if (!$this->username || !$this->password) { - debug_event($this->name,'Username or password missing','3'); - return false; - } - - // Create our scrobbler with everything this time and then queue it - $scrobbler = new scrobbler($this->username,$this->password,$this->hostname,$this->port,$this->path,$this->challenge); - - // Check to see if the scrobbling works - if (!$scrobbler->queue_track($song->f_artist_full,$song->f_album_full,$song->title,time(),$song->time,$song->track)) { - // Depending on the error we might need to do soemthing here - return false; - } - - // Go ahead and submit it now - if (!$scrobbler->submit_tracks()) { - debug_event($this->name,'Error Submit Failed: ' . $scrobbler->error_msg,'3'); - if ($scrobbler->reset_handshake) { - debug_event($this->name,'Re-running Handshake due to error','3'); - $this->set_handshake($this->user_id); - // Try try again - if ($scrobbler->submit_tracks()) { - debug_event($this->name,'Submission Successful','5'); - return true; - } - } - return false; - } - - debug_event($this->name,'Submission Successful','5'); - - return true; - - } // submit - - /** - * set_handshake - * This runs a handshake and properly updates the preferences as needed. - * It returns the data as an array so we don't have to requery the db. - * This requires a userid so it knows whose crap to update. - */ - public function set_handshake($user_id) { - - $scrobbler = new scrobbler($this->username,$this->password); - $data = $scrobbler->handshake(); - - if (!$data) { - debug_event($this->name,'Handshake Failed: ' . $scrobbler->error_msg,'3'); - return false; - } - - $this->hostname = $data['submit_host']; - $this->port = $data['submit_port']; - $this->path = $data['submit_url']; - $this->challenge = $data['challenge']; - - // Update the preferences - Preference::update('lastfm_port',$user_id,$data['submit_port']); - Preference::update('lastfm_host',$user_id,$data['submit_host']); - Preference::update('lastfm_url',$user_id,$data['submit_url']); - Preference::update('lastfm_challenge',$user_id,$data['challenge']); - - return true; - - } // set_handshake - - /** - * load - * This loads up the data we need into this object, this stuff comes - * from the preferences. - */ - public function load() { - - $GLOBALS['user']->set_preferences(); - $data = $GLOBALS['user']->prefs; - - if (strlen(trim($data['lastfm_user']))) { - $this->username = trim($data['lastfm_user']); - } - else { - debug_event($this->name,'No Username, not scrobbling','3'); - return false; - } - if (strlen(trim($data['lastfm_md5_pass']))) { - $this->password = trim($data['lastfm_md5_pass']); - } - else { - debug_event($this->name,'No Password, not scrobbling','3'); - return false; - } - - $this->user_id = $GLOBALS['user']->id; - - // If we don't have the other stuff try to get it before giving up - if (!$data['lastfm_host'] || !$data['lastfm_port'] || !$data['lastfm_url'] || !$data['lastfm_challenge']) { - debug_event($this->name,'Running Handshake, missing information','3'); - if (!$this->set_handshake($this->user_id)) { - debug_event($this->name,'Handshake failed, you lose','3'); - return false; - } - } - else { - $this->hostname = $data['lastfm_host']; - $this->port = $data['lastfm_port']; - $this->path = $data['lastfm_url']; - $this->challenge = $data['lastfm_challenge']; - } - - return true; - - } // load + public $name ='Last.FM'; + public $description ='Records your played songs to your Last.FM Account'; + public $url =''; + public $version ='000004'; + public $min_ampache ='360003'; + public $max_ampache ='999999'; + + // These are internal settings used by this class, run this->load to + // fill them out + private $username; + private $password; + private $hostname; + private $port; + private $path; + private $challenge; + private $user_id; + + /** + * Constructor + * This function does nothing... + */ + public function __construct() { + + return true; + + } // constructor + + /** + * install + * This is a required plugin function. It inserts our preferences + * into Ampache + */ + public function install() { + + // Check and see if it's already installed (they've just hit refresh, those dorks) + if (Preference::exists('lastfm_user')) { return false; } + + Preference::insert('lastfm_user','Last.FM Username','','25','string','plugins'); + Preference::insert('lastfm_md5_pass','Last.FM Password','','25','string','plugins'); + Preference::insert('lastfm_port','Last.FM Submit Port','','25','string','internal'); + Preference::insert('lastfm_host','Last.FM Submit Host','','25','string','internal'); + Preference::insert('lastfm_url','Last.FM Submit URL','','25','string','internal'); + Preference::insert('lastfm_challenge','Last.FM Submit Challenge','','25','string','internal'); + + return true; + + } // install + + /** + * uninstall + * This is a required plugin function. It removes our preferences from + * the database returning it to its original form + */ + public function uninstall() { + + Preference::delete('lastfm_md5_pass'); + Preference::delete('lastfm_user'); + Preference::delete('lastfm_url'); + Preference::delete('lastfm_host'); + Preference::delete('lastfm_port'); + Preference::delete('lastfm_challenge'); + + } // uninstall + + /** + * upgrade + * This is a recommended plugin function + */ + public function upgrade() { + $from_version = Plugin::get_plugin_version($this->name); + if ($from_version < 4) { + Preference::rename('lastfm_pass', 'lastfm_md5_pass'); + } + return true; + } // upgrade + + /** + * save_songplay + * This takes care of queueing and then submitting the tracks. + */ + public function save_songplay($song) { + + // Let's pull the last song submitted by this user + $previous = Stats::get_last_song($this->user_id); + + $diff = time() - $previous['date']; + + // Make sure it wasn't within the last min + if ($diff < 60) { + debug_event($this->name,'Last song played within ' . $diff . ' seconds, not recording stats','3'); + return false; + } + + if ($song->time < 30) { + debug_event($this->name,'Song less then 30 seconds not queueing','3'); + return false; + } + + // Make sure there's actually a username and password before we keep going + if (!$this->username || !$this->password) { + debug_event($this->name,'Username or password missing','3'); + return false; + } + + // Create our scrobbler with everything this time and then queue it + $scrobbler = new scrobbler($this->username,$this->password,$this->hostname,$this->port,$this->path,$this->challenge); + + // Check to see if the scrobbling works + if (!$scrobbler->queue_track($song->f_artist_full,$song->f_album_full,$song->title,time(),$song->time,$song->track)) { + // Depending on the error we might need to do soemthing here + return false; + } + + // Go ahead and submit it now + if (!$scrobbler->submit_tracks()) { + debug_event($this->name,'Error Submit Failed: ' . $scrobbler->error_msg,'3'); + if ($scrobbler->reset_handshake) { + debug_event($this->name,'Re-running Handshake due to error','3'); + $this->set_handshake($this->user_id); + // Try try again + if ($scrobbler->submit_tracks()) { + debug_event($this->name,'Submission Successful','5'); + return true; + } + } + return false; + } + + debug_event($this->name,'Submission Successful','5'); + + return true; + + } // submit + + /** + * set_handshake + * This runs a handshake and properly updates the preferences as needed. + * It returns the data as an array so we don't have to requery the db. + * This requires a userid so it knows whose crap to update. + */ + public function set_handshake($user_id) { + + $scrobbler = new scrobbler($this->username,$this->password); + $data = $scrobbler->handshake(); + + if (!$data) { + debug_event($this->name,'Handshake Failed: ' . $scrobbler->error_msg,'3'); + return false; + } + + $this->hostname = $data['submit_host']; + $this->port = $data['submit_port']; + $this->path = $data['submit_url']; + $this->challenge = $data['challenge']; + + // Update the preferences + Preference::update('lastfm_port',$user_id,$data['submit_port']); + Preference::update('lastfm_host',$user_id,$data['submit_host']); + Preference::update('lastfm_url',$user_id,$data['submit_url']); + Preference::update('lastfm_challenge',$user_id,$data['challenge']); + + return true; + + } // set_handshake + + /** + * load + * This loads up the data we need into this object, this stuff comes + * from the preferences. + */ + public function load() { + + $GLOBALS['user']->set_preferences(); + $data = $GLOBALS['user']->prefs; + + if (strlen(trim($data['lastfm_user']))) { + $this->username = trim($data['lastfm_user']); + } + else { + debug_event($this->name,'No Username, not scrobbling','3'); + return false; + } + if (strlen(trim($data['lastfm_md5_pass']))) { + $this->password = trim($data['lastfm_md5_pass']); + } + else { + debug_event($this->name,'No Password, not scrobbling','3'); + return false; + } + + $this->user_id = $GLOBALS['user']->id; + + // If we don't have the other stuff try to get it before giving up + if (!$data['lastfm_host'] || !$data['lastfm_port'] || !$data['lastfm_url'] || !$data['lastfm_challenge']) { + debug_event($this->name,'Running Handshake, missing information','3'); + if (!$this->set_handshake($this->user_id)) { + debug_event($this->name,'Handshake failed, you lose','3'); + return false; + } + } + else { + $this->hostname = $data['lastfm_host']; + $this->port = $data['lastfm_port']; + $this->path = $data['lastfm_url']; + $this->challenge = $data['lastfm_challenge']; + } + + return true; + + } // load } // end AmpacheLastfm ?> diff --git a/modules/plugins/Librefm.plugin.php b/modules/plugins/Librefm.plugin.php index 8489e7b6..fd2b8951 100644 --- a/modules/plugins/Librefm.plugin.php +++ b/modules/plugins/Librefm.plugin.php @@ -1,5 +1,5 @@ <?php -/* vim:set tabstop=8 softtabstop=8 shiftwidth=8 noexpandtab: */ +/* vim:set softtabstop=4 shiftwidth=4 expandtab: */ /** * * LICENSE: GNU General Public License, version 2 (GPLv2) @@ -22,215 +22,215 @@ class Ampachelibrefm { - public $name ='Libre.FM'; - public $description ='Records your played songs to your Libre.FM Account'; - public $url =''; - public $version ='000002'; - public $min_ampache ='360003'; - public $max_ampache ='999999'; - - // These are internal settings used by this class, run this->load to - // fill them out - private $username; - private $password; - private $hostname; - private $port; - private $path; - private $challenge; - private $user_id; - - /** - * Constructor - * This function does nothing... - */ - public function __construct() { - - return true; - - } // constructor - - /** - * install - * This is a required plugin function. It inserts our preferences - * into Ampache - */ - public function install() { - - // Check and see if it's already installed (they've just hit refresh, those dorks) - if (Preference::exists('librefm_user')) { return false; } - - Preference::insert('librefm_user','Libre.FM Username','','25','string','plugins'); - Preference::insert('librefm_md5_pass','Libre.FM Password','','25','string','plugins'); - Preference::insert('librefm_port','Libre.FM Submit Port','','25','string','internal'); - Preference::insert('librefm_host','Libre.FM Submit Host','','25','string','internal'); - Preference::insert('librefm_url','Libre.FM Submit URL','','25','string','internal'); - Preference::insert('librefm_challenge','Libre.FM Submit Challenge','','25','string','internal'); - - return true; - - } // install - - /** - * uninstall - * This is a required plugin function. It removes our preferences from - * the database returning it to its original form - */ - public function uninstall() { - - Preference::delete('librefm_md5_pass'); - Preference::delete('librefm_user'); - Preference::delete('librefm_url'); - Preference::delete('librefm_host'); - Preference::delete('librefm_port'); - Preference::delete('librefm_challenge'); - - } // uninstall - - /** - * upgrade - * This is a recommended plugin function - */ - public function upgrade() { - $from_version = Plugin::get_plugin_version($this->name); - if ($from_version < 2) { - Preference::rename('librefm_pass', 'librefm_md5_pass'); - } - return true; - } // upgrade - - /** - * save_songplay - * This takes care of queueing and then submitting the tracks. - */ - public function save_songplay($song) { - - // Before we start let's pull the last song submitted by this user - $previous = Stats::get_last_song($this->user_id); - - $diff = time() - $previous['date']; - - // Make sure it wasn't within the last min - if ($diff < 60) { - debug_event($this->name,'Last song played within ' . $diff . ' seconds, not recording stats','3'); - return false; - } - - if ($song->time < 30) { - debug_event($this->name,'Song less then 30 seconds not queueing','3'); - return false; - } - - // Make sure there's actually a username and password before we keep going - if (!$this->username || !$this->password) { - debug_event($this->name,'Username or password missing','3'); - return false; - } - - // Create our scrobbler with everything this time and then queue it - $scrobbler = new scrobbler($this->username,$this->password,$this->hostname,$this->port,$this->path,$this->challenge,'turtle.libre.fm'); - - // Check to see if the scrobbling works - if (!$scrobbler->queue_track($song->f_artist_full,$song->f_album_full,$song->title,time(),$song->time,$song->track)) { - // Depending on the error we might need to do soemthing here - return false; - } - - // Go ahead and submit it now - if (!$scrobbler->submit_tracks()) { - debug_event($this->name,'Error Submit Failed: ' . $scrobbler->error_msg,'3'); - if ($scrobbler->reset_handshake) { - debug_event($this->name,'Re-running Handshake due to error','3'); - $this->set_handshake($this->user_id); - // Try try again - if ($scrobbler->submit_tracks()) { - return true; - } - } - return false; - } - - debug_event($this->name,'Submission Successful','5'); - - return true; - - } // submit - - /** - * set_handshake - * This runs a handshake and properly updates the preferences as needed. - * It returns the data as an array so we don't have to requery the db. - * This requires a userid so it knows whose crap to update. - */ - public function set_handshake($user_id) { - - $scrobbler = new scrobbler($this->username,$this->password,'','','','','turtle.libre.fm'); - $data = $scrobbler->handshake(); - - if (!$data) { - debug_event($this->name,'Handshake Failed: ' . $scrobbler->error_msg,'3'); - return false; - } - - $this->hostname = $data['submit_host']; - $this->port = $data['submit_port']; - $this->path = $data['submit_url']; - $this->challenge = $data['challenge']; - - // Update the preferences - Preference::update('librefm_port',$user_id,$data['submit_port']); - Preference::update('librefm_host',$user_id,$data['submit_host']); - Preference::update('librefm_url',$user_id,$data['submit_url']); - Preference::update('librefm_challenge',$user_id,$data['challenge']); - - return true; - - } // set_handshake - - /** - * load - * This loads up the data we need into this object, this stuff comes - * from the preferences. - */ - public function load() { - - $GLOBALS['user']->set_preferences(); - $data = $GLOBALS['user']->prefs; - - if (strlen(trim($data['librefm_user']))) { - $this->username = trim($data['librefm_user']); - } - else { - debug_event($this->name,'No Username, not scrobbling','3'); - return false; - } - if (strlen(trim($data['librefm_md5_pass']))) { - $this->password = trim($data['librefm_md5_pass']); - } - else { - debug_event($this->name,'No Password, not scrobbling','3'); - return false; - } - - $this->user_id = $GLOBALS['user']->id; - - // If we don't have the other stuff try to get it before giving up - if (!$data['librefm_host'] || !$data['librefm_port'] || !$data['librefm_url'] || !$data['librefm_challenge']) { - debug_event($this->name,'Running Handshake, missing information','3'); - if (!$this->set_handshake($this->user_id)) { - debug_event($this->name,'Handshake failed, you lose','3'); - return false; - } - } - else { - $this->hostname = $data['librefm_host']; - $this->port = $data['librefm_port']; - $this->path = $data['librefm_url']; - $this->challenge = $data['librefm_challenge']; - } - - return true; - - } // load + public $name ='Libre.FM'; + public $description ='Records your played songs to your Libre.FM Account'; + public $url =''; + public $version ='000002'; + public $min_ampache ='360003'; + public $max_ampache ='999999'; + + // These are internal settings used by this class, run this->load to + // fill them out + private $username; + private $password; + private $hostname; + private $port; + private $path; + private $challenge; + private $user_id; + + /** + * Constructor + * This function does nothing... + */ + public function __construct() { + + return true; + + } // constructor + + /** + * install + * This is a required plugin function. It inserts our preferences + * into Ampache + */ + public function install() { + + // Check and see if it's already installed (they've just hit refresh, those dorks) + if (Preference::exists('librefm_user')) { return false; } + + Preference::insert('librefm_user','Libre.FM Username','','25','string','plugins'); + Preference::insert('librefm_md5_pass','Libre.FM Password','','25','string','plugins'); + Preference::insert('librefm_port','Libre.FM Submit Port','','25','string','internal'); + Preference::insert('librefm_host','Libre.FM Submit Host','','25','string','internal'); + Preference::insert('librefm_url','Libre.FM Submit URL','','25','string','internal'); + Preference::insert('librefm_challenge','Libre.FM Submit Challenge','','25','string','internal'); + + return true; + + } // install + + /** + * uninstall + * This is a required plugin function. It removes our preferences from + * the database returning it to its original form + */ + public function uninstall() { + + Preference::delete('librefm_md5_pass'); + Preference::delete('librefm_user'); + Preference::delete('librefm_url'); + Preference::delete('librefm_host'); + Preference::delete('librefm_port'); + Preference::delete('librefm_challenge'); + + } // uninstall + + /** + * upgrade + * This is a recommended plugin function + */ + public function upgrade() { + $from_version = Plugin::get_plugin_version($this->name); + if ($from_version < 2) { + Preference::rename('librefm_pass', 'librefm_md5_pass'); + } + return true; + } // upgrade + + /** + * save_songplay + * This takes care of queueing and then submitting the tracks. + */ + public function save_songplay($song) { + + // Before we start let's pull the last song submitted by this user + $previous = Stats::get_last_song($this->user_id); + + $diff = time() - $previous['date']; + + // Make sure it wasn't within the last min + if ($diff < 60) { + debug_event($this->name,'Last song played within ' . $diff . ' seconds, not recording stats','3'); + return false; + } + + if ($song->time < 30) { + debug_event($this->name,'Song less then 30 seconds not queueing','3'); + return false; + } + + // Make sure there's actually a username and password before we keep going + if (!$this->username || !$this->password) { + debug_event($this->name,'Username or password missing','3'); + return false; + } + + // Create our scrobbler with everything this time and then queue it + $scrobbler = new scrobbler($this->username,$this->password,$this->hostname,$this->port,$this->path,$this->challenge,'turtle.libre.fm'); + + // Check to see if the scrobbling works + if (!$scrobbler->queue_track($song->f_artist_full,$song->f_album_full,$song->title,time(),$song->time,$song->track)) { + // Depending on the error we might need to do soemthing here + return false; + } + + // Go ahead and submit it now + if (!$scrobbler->submit_tracks()) { + debug_event($this->name,'Error Submit Failed: ' . $scrobbler->error_msg,'3'); + if ($scrobbler->reset_handshake) { + debug_event($this->name,'Re-running Handshake due to error','3'); + $this->set_handshake($this->user_id); + // Try try again + if ($scrobbler->submit_tracks()) { + return true; + } + } + return false; + } + + debug_event($this->name,'Submission Successful','5'); + + return true; + + } // submit + + /** + * set_handshake + * This runs a handshake and properly updates the preferences as needed. + * It returns the data as an array so we don't have to requery the db. + * This requires a userid so it knows whose crap to update. + */ + public function set_handshake($user_id) { + + $scrobbler = new scrobbler($this->username,$this->password,'','','','','turtle.libre.fm'); + $data = $scrobbler->handshake(); + + if (!$data) { + debug_event($this->name,'Handshake Failed: ' . $scrobbler->error_msg,'3'); + return false; + } + + $this->hostname = $data['submit_host']; + $this->port = $data['submit_port']; + $this->path = $data['submit_url']; + $this->challenge = $data['challenge']; + + // Update the preferences + Preference::update('librefm_port',$user_id,$data['submit_port']); + Preference::update('librefm_host',$user_id,$data['submit_host']); + Preference::update('librefm_url',$user_id,$data['submit_url']); + Preference::update('librefm_challenge',$user_id,$data['challenge']); + + return true; + + } // set_handshake + + /** + * load + * This loads up the data we need into this object, this stuff comes + * from the preferences. + */ + public function load() { + + $GLOBALS['user']->set_preferences(); + $data = $GLOBALS['user']->prefs; + + if (strlen(trim($data['librefm_user']))) { + $this->username = trim($data['librefm_user']); + } + else { + debug_event($this->name,'No Username, not scrobbling','3'); + return false; + } + if (strlen(trim($data['librefm_md5_pass']))) { + $this->password = trim($data['librefm_md5_pass']); + } + else { + debug_event($this->name,'No Password, not scrobbling','3'); + return false; + } + + $this->user_id = $GLOBALS['user']->id; + + // If we don't have the other stuff try to get it before giving up + if (!$data['librefm_host'] || !$data['librefm_port'] || !$data['librefm_url'] || !$data['librefm_challenge']) { + debug_event($this->name,'Running Handshake, missing information','3'); + if (!$this->set_handshake($this->user_id)) { + debug_event($this->name,'Handshake failed, you lose','3'); + return false; + } + } + else { + $this->hostname = $data['librefm_host']; + $this->port = $data['librefm_port']; + $this->path = $data['librefm_url']; + $this->challenge = $data['librefm_challenge']; + } + + return true; + + } // load } // end Ampachelibrefm ?> diff --git a/modules/plugins/MusicBrainz.plugin.php b/modules/plugins/MusicBrainz.plugin.php index 86f3e7f4..672df7b5 100644 --- a/modules/plugins/MusicBrainz.plugin.php +++ b/modules/plugins/MusicBrainz.plugin.php @@ -1,5 +1,5 @@ <?php -/* vim:set tabstop=8 softtabstop=8 shiftwidth=8 noexpandtab: */ +/* vim:set softtabstop=4 shiftwidth=4 expandtab: */ /** * * LICENSE: GNU General Public License, version 2 (GPLv2) @@ -22,77 +22,77 @@ class AmpacheMusicBrainz { - public $name ='MusicBrainz'; - public $description ='MusicBrainz metadata integration'; - public $version ='000001'; - public $min_ampache ='360003'; - public $max_ampache ='999999'; + public $name ='MusicBrainz'; + public $description ='MusicBrainz metadata integration'; + public $version ='000001'; + public $min_ampache ='360003'; + public $max_ampache ='999999'; - /** - * Constructor - * This function does nothing - */ - public function __construct() { - return true; - } + /** + * Constructor + * This function does nothing + */ + public function __construct() { + return true; + } - /** - * install - * This is a required plugin function - */ - public function install() { - return true; - } // install + /** + * install + * This is a required plugin function + */ + public function install() { + return true; + } // install - /** - * uninstall - * This is a required plugin function - */ - public function uninstall() { - return true; - } // uninstall + /** + * uninstall + * This is a required plugin function + */ + public function uninstall() { + return true; + } // uninstall - /** - * load - * This is a required plugin function; here it populates the prefs we - * need for this object. - */ - public function load() { - return true; - } // load + /** + * load + * This is a required plugin function; here it populates the prefs we + * need for this object. + */ + public function load() { + return true; + } // load - /** - * get_metadata - * Returns song metadata for what we're passed in. - */ - public function get_metadata($song_info) { - if (!$mbid = $song_info['mb_trackid']) { - return null; - } + /** + * get_metadata + * Returns song metadata for what we're passed in. + */ + public function get_metadata($song_info) { + if (!$mbid = $song_info['mb_trackid']) { + return null; + } - $mbquery = new MusicBrainzQuery(); - $includes = new mbTrackIncludes(); - $includes = $includes->artist()->releases(); - try { - $track = $mbquery->getTrackById($mbid, $includes); - } - catch (Exception $e) { - return null; - } + $mbquery = new MusicBrainzQuery(); + $includes = new mbTrackIncludes(); + $includes = $includes->artist()->releases(); + try { + $track = $mbquery->getTrackById($mbid, $includes); + } + catch (Exception $e) { + return null; + } - $results = array(); + $results = array(); - $results['mb_artistid'] = $track->getArtist()->getId(); - $results['artist'] = $track->getArtist()->getName(); - $results['title'] = $track->getTitle(); - if ($track->getNumReleases() == 1) { - $release = $track->getReleases(); - $release = $release[0]; - $results['album'] = $release->getTitle(); - } + $results['mb_artistid'] = $track->getArtist()->getId(); + $results['artist'] = $track->getArtist()->getName(); + $results['title'] = $track->getTitle(); + if ($track->getNumReleases() == 1) { + $release = $track->getReleases(); + $release = $release[0]; + $results['album'] = $release->getTitle(); + } - return $results; - } // get_metadata + return $results; + } // get_metadata } // end AmpacheMusicBrainz ?> diff --git a/modules/twitter/twitter_login.php b/modules/twitter/twitter_login.php index 7e1b29e3..d929d1de 100644 --- a/modules/twitter/twitter_login.php +++ b/modules/twitter/twitter_login.php @@ -1,7 +1,8 @@ <?php +/* vim:set softtabstop=4 shiftwidth=4 expandtab: */ /** * Adapted for Ampache by Chris Slamar - * FIxME: Adapted from what? We shouldn't claim code that isn't ours + * FIXME: Adapted from what? We shouldn't claim code that isn't ours * * LICENSE: GNU General Public License, version 2 (GPLv2) * Copyright 2001 - 2013 Ampache.org @@ -21,36 +22,35 @@ * */ - require_once '../../lib/init.php'; - require_once( Config::get('prefix') . "/modules/twitter/twitteroauth/twitteroauth.php"); - session_start(); - - if( !isset($_SESSION['twitterCount'] )) { - $_SESSION['twitterCount'] = 0; - } - if( isset($_SESSION['twitterusername']) ) { +require_once '../../lib/init.php'; +require_once( Config::get('prefix') . "/modules/twitter/twitteroauth/twitteroauth.php"); +session_start(); - debug_event("Twitter", "User has logged in this session.", "5"); - header('Location: twitter_update.php'); - } else { - // The TwitterOAuth instance - $twitteroauth = new TwitterOAuth( Config::get('twitter_consumer_key') , Config::get('twitter_consumer_secret') ); +if( !isset($_SESSION['twitterCount'] )) { + $_SESSION['twitterCount'] = 0; +} +if( isset($_SESSION['twitterusername']) ) { + debug_event("Twitter", "User has logged in this session.", "5"); + header('Location: twitter_update.php'); +} else { + // The TwitterOAuth instance + $twitteroauth = new TwitterOAuth( Config::get('twitter_consumer_key') , Config::get('twitter_consumer_secret') ); - // Requesting authentication tokens, the parameter is the URL we will be redirected to - $request_token = $twitteroauth->getRequestToken( Config::get('web_path') . '/modules/twitter/twitter_works.php'); + // Requesting authentication tokens, the parameter is the URL we will be redirected to + $request_token = $twitteroauth->getRequestToken( Config::get('web_path') . '/modules/twitter/twitter_works.php'); - // Saving them into the session - $_SESSION['oauth_token'] = $request_token['oauth_token']; - $_SESSION['oauth_token_secret'] = $request_token['oauth_token_secret']; + // Saving them into the session + $_SESSION['oauth_token'] = $request_token['oauth_token']; + $_SESSION['oauth_token_secret'] = $request_token['oauth_token_secret']; - // If everything goes well.. - if( $twitteroauth->http_code == 200 ) { - // Let's generate the URL and redirect - $url = $twitteroauth->getAuthorizeURL($request_token['oauth_token']); - header('Location: '. $url); - } else { - debug_event("Twitter", "Could not generate the URL to continue. Going back.", "5"); - header('Location: ' . Config::get('web_path') ); - } - } + // If everything goes well.. + if( $twitteroauth->http_code == 200 ) { + // Let's generate the URL and redirect + $url = $twitteroauth->getAuthorizeURL($request_token['oauth_token']); + header('Location: '. $url); + } else { + debug_event("Twitter", "Could not generate the URL to continue. Going back.", "5"); + header('Location: ' . Config::get('web_path') ); + } +} ?> diff --git a/modules/twitter/twitter_update.php b/modules/twitter/twitter_update.php index 9fe779d6..04dbd878 100644 --- a/modules/twitter/twitter_update.php +++ b/modules/twitter/twitter_update.php @@ -1,4 +1,5 @@ <?php +/* vim:set softtabstop=4 shiftwidth=4 expandtab: */ /** * * Adapted for Ampache by Chris Slamar @@ -22,38 +23,38 @@ * */ - require_once '../../lib/init.php'; - require_once( Config::get('prefix') . "/modules/twitter/twitteroauth/twitteroauth.php"); - session_start(); - - - if(!empty($_SESSION['twitterusername'])) { - - $nowplayingQuery = "SELECT song.title,artist.name FROM song,now_playing,artist WHERE song.id = now_playing.object_id AND artist.id = song.artist"; - debug_event("Twitter", "Now Playing query: " . $nowplayingQuery, "6"); - - $nowplayingRun = Dba::read($nowplayingQuery); - $nowplayingResults = Dba::fetch_assoc($nowplayingRun); - - $return = $nowplayingResults['title'] . " by " . $nowplayingResults['name']; - debug_event("Twitter", "Song from DB is: " . $return, "5"); - - $selectquery = "SELECT * FROM twitter_users WHERE username = '" . $_SESSION['twitterusername'] . "' AND ampache_id = " . $_SESSION['userdata']['uid']; - debug_event("Twitter", "Select query: " . $selectquery, "6"); - - $selectrun = Dba::read($selectquery); - $result = Dba::fetch_assoc($selectrun); - - $twitteroauth = new TwitterOAuth( Config::get('twitter_consumer_key'), Config::get('twitter_consumer_secret'), $result['oauth_token'], $result['oauth_secret']); - $user_info = $twitteroauth->get('account/verify'); - if( $user_info->error == 'Not found' ) { - debug_event("Twitter", "Auth Successful! Posting Status", "5"); - $twitteroauth->post('statuses/update', array('status' => 'is rocking out to ' . $return)); - header('Location: ' . Config::get('web_path') ); - } - - } else { - debug_event("Twitter", "Auth Error going back to home.", "5"); - header('Location: ' . Config::get('web_path') ); - } +require_once '../../lib/init.php'; +require_once( Config::get('prefix') . "/modules/twitter/twitteroauth/twitteroauth.php"); + session_start(); + + +if(!empty($_SESSION['twitterusername'])) { + + $nowplayingQuery = "SELECT song.title,artist.name FROM song,now_playing,artist WHERE song.id = now_playing.object_id AND artist.id = song.artist"; + debug_event("Twitter", "Now Playing query: " . $nowplayingQuery, "6"); + + $nowplayingRun = Dba::read($nowplayingQuery); + $nowplayingResults = Dba::fetch_assoc($nowplayingRun); + + $return = $nowplayingResults['title'] . " by " . $nowplayingResults['name']; + debug_event("Twitter", "Song from DB is: " . $return, "5"); + + $selectquery = "SELECT * FROM twitter_users WHERE username = '" . $_SESSION['twitterusername'] . "' AND ampache_id = " . $_SESSION['userdata']['uid']; + debug_event("Twitter", "Select query: " . $selectquery, "6"); + + $selectrun = Dba::read($selectquery); + $result = Dba::fetch_assoc($selectrun); + + $twitteroauth = new TwitterOAuth( Config::get('twitter_consumer_key'), Config::get('twitter_consumer_secret'), $result['oauth_token'], $result['oauth_secret']); + $user_info = $twitteroauth->get('account/verify'); + if( $user_info->error == 'Not found' ) { + debug_event("Twitter", "Auth Successful! Posting Status", "5"); + $twitteroauth->post('statuses/update', array('status' => 'is rocking out to ' . $return)); + header('Location: ' . Config::get('web_path') ); + } + +} else { + debug_event("Twitter", "Auth Error going back to home.", "5"); + header('Location: ' . Config::get('web_path') ); +} ?> diff --git a/modules/twitter/twitter_works.php b/modules/twitter/twitter_works.php index 9d031f52..5bd0fca1 100644 --- a/modules/twitter/twitter_works.php +++ b/modules/twitter/twitter_works.php @@ -1,4 +1,5 @@ <?php +/* vim:set softtabstop=4 shiftwidth=4 expandtab: */ /** * * Adapted for Ampache by Chris Slamar @@ -22,105 +23,107 @@ * */ - require_once '../../lib/init.php'; - require_once( Config::get('prefix') . "/modules/twitter/twitteroauth/twitteroauth.php"); - - session_start(); - - if(!empty($_SESSION['twitterusername'])) { - header('Location: ' . Config::Get('web_path') . '/modules/twitter/twitter_update.php'); - debug_event("Twitter", "Twitter user has logged in this session.", "5"); - } - - if(!empty($_GET['oauth_verifier']) && !empty($_SESSION['oauth_token']) && !empty($_SESSION['oauth_token_secret'])){ - debug_event("Twitter", "Got all 3 pieces for auth", "5"); - } else { - if( $_SESSION['twitterCount'] < 4 ) { - debug_event("Twitter", "Didn't get all 3 auth pieces, going to try again. Try #" . $_SESSION['twitterCount'], "5"); - $_SESSION['twitterCount']++; - header('Location: ' . Config::Get('web_path') . '/modules/twitter/twitter_login.php'); - } else { - debug_event("Twitter", "Failed to auth too many times. Giving up.", "5"); - header('Location: ' . Config::Get('web_path') ); - } - } - - // TwitterOAuth instance, with two new parameters we got in twitter_login.php - $twitteroauth = new TwitterOAuth( Config::get('twitter_consumer_key'), Config::get('twitter_consumer_secret'), $_SESSION['oauth_token'], $_SESSION['oauth_token_secret']); - if( !isset($twitteroauth) ) { - debug_event("Twitter", "Couldn't create OAuth object.", "5"); - header('Location: ' . Config::get('web_path')); - } - // Let's request the access token - $access_token = $twitteroauth->getAccessToken($_GET['oauth_verifier']); - if( !isset($access_token) ) { - debug_event("Twitter", "Couldn't get access token", "5"); - header('Location: ' . Config::get('web_path')); - } - // Save it in a session var - $_SESSION['access_token'] = $access_token; - - - // Let's get the user's info - $user_info = $twitteroauth->get('account/verify_credentials'); - - debug_event("Twttier", "User ID:{$user_info->id}. ScreenName:{$user_info->screen_name}.", "5"); - debug_event("Twitter", "access token:" . $access_token['oauth_token'], "5"); - debug_event("Twitter", "access token secret:" . $access_token['oauth_token_secret'], "5"); - - if( isset($user_info->error)) { - debug_event("Twitter", "Error verifying credentials", "5"); - session_destroy(); - header('Location: ' . Config::get('web_path')); - } else { - - // Let's find the user by its twitterid and ampacheid - $idselectquery = "SELECT * FROM twitter_users WHERE oauth_provider = 'twitter' AND oauth_uid = ". $user_info->id . " AND ampache_id = " . $_SESSION['userdata']['uid']; - debug_event("Twitter", "Id query: " . $idselectquery, "6"); - - $idselectrun = Dba::read($idselectquery); - $result = Dba::fetch_assoc($idselectrun); - - debug_event("Twitter", "ampache_id: {$_SESSION['userdata']['uid']}", "5"); - debug_event("Twitter", "oauth_uid: {$user_info->id}", "5"); - debug_event("Twitter", "oauth_token: {$access_token['oauth_token']}", "5"); - debug_event("Twitter", "oauth_secret: {$access_token['oauth_token_secret']}", "5"); - debug_event("Twitter", "username: {$user_info->screen_name}", "5"); - - // If not, let's add it to the database - if(empty($result)){ - debug_event("Twitter", "First time user. Add them to the DB.", "5"); - $insert_query ="INSERT INTO twitter_users (ampache_id, oauth_provider, oauth_uid, oauth_token, oauth_secret, username) VALUES ( '{$_SESSION['userdata']['uid']}', 'twitter', '{$user_info->id}', '{$access_token['oauth_token']}', '{$access_token['oauth_token_secret']}', '{$user_info->screen_name}')"; - - debug_event("Twitter", "Insert query: " . $insert_query, "6"); - $insert_run = Dba::write($insert_query); - - $select_query = "SELECT * FROM twitter_users WHERE username = '" . $user_info->screen_name . "' AND ampache_id = " . $_SESSION['userdata']['uid']; - debug_event("Twitter", "Select query: {$query}", "6"); - $select_run = Dba::read( $select_query ); - $result = Dba::fetch_assoc($select_run); - } else { - debug_event("Twitter", "Update the DB to hold current tokens", "5"); - - $update_query = "UPDATE twitter_users SET oauth_token = '{$access_token['oauth_token']}', oauth_secret = '{$access_token['oauth_token_secret']}' WHERE oauth_provider = 'twitter' AND oauth_uid = {$user_info->id} AND ampache_id = {$_SESSION['userdata']['uid']}"; - debug_event("Twitter", "update query: " . $update_query, "6"); - - $update_run = Dba::write($update_query); - - $select_query = "SELECT * FROM twitter_users WHERE username = '" . $user_info->screen_name . "'"; - debug_event("Twitter", "select query: " . $select_query, "6"); - - $select_run = Dba::read($select_query); - $result = Dba::fetch_assoc($select_run); - } - - $_SESSION['id'] = $result['id']; - $_SESSION['twitterusername'] = $result['username']; - $_SESSION['oauth_uid'] = $result['oauth_uid']; - $_SESSION['oauth_provider'] = $result['oauth_provider']; - $_SESSION['oauth_token'] = $result['oauth_token']; - $_SESSION['oauth_secret'] = $result['oauth_secret']; - - header('Location: ' . Config::get('web_path') . '/modules/twitter/twitter_update.php'); - } +require_once '../../lib/init.php'; + require_once( Config::get('prefix') . "/modules/twitter/twitteroauth/twitteroauth.php"); + +session_start(); + +if(!empty($_SESSION['twitterusername'])) { + header('Location: ' . Config::Get('web_path') . '/modules/twitter/twitter_update.php'); + debug_event("Twitter", "Twitter user has logged in this session.", "5"); +} + +if(!empty($_GET['oauth_verifier']) && !empty($_SESSION['oauth_token']) && !empty($_SESSION['oauth_token_secret'])){ + debug_event("Twitter", "Got all 3 pieces for auth", "5"); +} else { + if( $_SESSION['twitterCount'] < 4 ) { + debug_event("Twitter", "Didn't get all 3 auth pieces, going to try again. Try #" . $_SESSION['twitterCount'], "5"); + $_SESSION['twitterCount']++; + header('Location: ' . Config::Get('web_path') . '/modules/twitter/twitter_login.php'); + } else { + debug_event("Twitter", "Failed to auth too many times. Giving up.", "5"); + header('Location: ' . Config::Get('web_path') ); + } +} + +// TwitterOAuth instance, with two new parameters we got in twitter_login.php +$twitteroauth = new TwitterOAuth( Config::get('twitter_consumer_key'), Config::get('twitter_consumer_secret'), $_SESSION['oauth_token'], $_SESSION['oauth_token_secret']); +if( !isset($twitteroauth) ) { + debug_event("Twitter", "Couldn't create OAuth object.", "5"); + header('Location: ' . Config::get('web_path')); +} +// Let's request the access token +$access_token = $twitteroauth->getAccessToken($_GET['oauth_verifier']); +if( !isset($access_token) ) { + debug_event("Twitter", "Couldn't get access token", "5"); + header('Location: ' . Config::get('web_path')); +} +// Save it in a session var +$_SESSION['access_token'] = $access_token; + + +// Let's get the user's info +$user_info = $twitteroauth->get('account/verify_credentials'); + +debug_event("Twttier", "User ID:{$user_info->id}. ScreenName:{$user_info->screen_name}.", "5"); +debug_event("Twitter", "access token:" . $access_token['oauth_token'], "5"); +debug_event("Twitter", "access token secret:" . $access_token['oauth_token_secret'], "5"); + +if( isset($user_info->error)) { + debug_event("Twitter", "Error verifying credentials", "5"); + session_destroy(); + header('Location: ' . Config::get('web_path')); +} +else { + + // Let's find the user by its twitterid and ampacheid + $idselectquery = "SELECT * FROM twitter_users WHERE oauth_provider = 'twitter' AND oauth_uid = ". $user_info->id . " AND ampache_id = " . $_SESSION['userdata']['uid']; + debug_event("Twitter", "Id query: " . $idselectquery, "6"); + + $idselectrun = Dba::read($idselectquery); + $result = Dba::fetch_assoc($idselectrun); + + debug_event("Twitter", "ampache_id: {$_SESSION['userdata']['uid']}", "5"); + debug_event("Twitter", "oauth_uid: {$user_info->id}", "5"); + debug_event("Twitter", "oauth_token: {$access_token['oauth_token']}", "5"); + debug_event("Twitter", "oauth_secret: {$access_token['oauth_token_secret']}", "5"); + debug_event("Twitter", "username: {$user_info->screen_name}", "5"); + + // If not, let's add it to the database + if(empty($result)){ + debug_event("Twitter", "First time user. Add them to the DB.", "5"); + $insert_query ="INSERT INTO twitter_users (ampache_id, oauth_provider, oauth_uid, oauth_token, oauth_secret, username) VALUES ( '{$_SESSION['userdata']['uid']}', 'twitter', '{$user_info->id}', '{$access_token['oauth_token']}', '{$access_token['oauth_token_secret']}', '{$user_info->screen_name}')"; + + debug_event("Twitter", "Insert query: " . $insert_query, "6"); + $insert_run = Dba::write($insert_query); + + $select_query = "SELECT * FROM twitter_users WHERE username = '" . $user_info->screen_name . "' AND ampache_id = " . $_SESSION['userdata']['uid']; + debug_event("Twitter", "Select query: {$query}", "6"); + $select_run = Dba::read( $select_query ); + $result = Dba::fetch_assoc($select_run); + } + else { + debug_event("Twitter", "Update the DB to hold current tokens", "5"); + + $update_query = "UPDATE twitter_users SET oauth_token = '{$access_token['oauth_token']}', oauth_secret = '{$access_token['oauth_token_secret']}' WHERE oauth_provider = 'twitter' AND oauth_uid = {$user_info->id} AND ampache_id = {$_SESSION['userdata']['uid']}"; + debug_event("Twitter", "update query: " . $update_query, "6"); + + $update_run = Dba::write($update_query); + + $select_query = "SELECT * FROM twitter_users WHERE username = '" . $user_info->screen_name . "'"; + debug_event("Twitter", "select query: " . $select_query, "6"); + + $select_run = Dba::read($select_query); + $result = Dba::fetch_assoc($select_run); + } + + $_SESSION['id'] = $result['id']; + $_SESSION['twitterusername'] = $result['username']; + $_SESSION['oauth_uid'] = $result['oauth_uid']; + $_SESSION['oauth_provider'] = $result['oauth_provider']; + $_SESSION['oauth_token'] = $result['oauth_token']; + $_SESSION['oauth_secret'] = $result['oauth_secret']; + + header('Location: ' . Config::get('web_path') . '/modules/twitter/twitter_update.php'); + } ?> diff --git a/modules/vlc/vlcplayer.class.php b/modules/vlc/vlcplayer.class.php index d124b1a4..04e7a0a6 100644 --- a/modules/vlc/vlcplayer.class.php +++ b/modules/vlc/vlcplayer.class.php @@ -1,5 +1,5 @@ <?php -/* vim:set tabstop=8 softtabstop=8 shiftwidth=8 noexpandtab: */ +/* vim:set softtabstop=4 shiftwidth=4 expandtab: */ /** * * LICENSE: GNU General Public License, version 2 (GPLv2) @@ -30,8 +30,8 @@ */ class VlcPlayer { - public $host; - public $port; + public $host; + public $port; public $password; /** @@ -54,19 +54,16 @@ class VlcPlayer { * $name Name to be shown in the playlist * $url URL of the song */ - public function add($name, $url) { - - - $aurl = urlencode($url); - $aurl .= "&"; - $aurl .= urlencode($name); + public function add($name, $url) { + $aurl = urlencode($url); + $aurl .= "&"; + $aurl .= urlencode($name); $args = array('command'=>'in_enqueue','&input'=>$aurl); $results = $this->sendCommand('status.xml?', $args); if (is_null($results)) { return null; } return true; - } // add /** |