@@ -47,13 +47,39 @@ class AmpacheApi
4747 private $ XML_subTag ;
4848 private $ XML_parser ;
4949 private $ XML_results ;
50- private $ XML_position = 0 ;
51- protected $ XML_grabtags = array ();
52- protected $ XML_skiptags = array ('root ' );
53- protected $ XML_parenttags = array ('artist ' ,'album ' ,'song ' ,'tag ' ,'video ' ,'playlist ' ,'result ' ,
54- 'auth ' ,'version ' ,'update ' ,'add ' ,'clean ' ,'songs ' ,'artists ' ,'albums ' ,
55- 'tags ' ,'videos ' ,'api ' ,'playlists ' ,'catalogs ' , 'user ' , 'users ' ,
56- 'shouts ' , 'timeline ' );
50+ private $ XML_position = 0 ;
51+
52+ protected $ XML_grabtags = array ();
53+ protected $ XML_skiptags = array (
54+ 'root '
55+ );
56+
57+ protected $ XML_parenttags = array (
58+ 'artist ' ,
59+ 'album ' ,
60+ 'song ' ,
61+ 'tag ' ,
62+ 'video ' ,
63+ 'playlist ' ,
64+ 'result ' ,
65+ 'auth ' ,
66+ 'version ' ,
67+ 'update ' ,
68+ 'add ' ,
69+ 'clean ' ,
70+ 'songs ' ,
71+ 'artists ' ,
72+ 'albums ' ,
73+ 'tags ' ,
74+ 'videos ' ,
75+ 'api ' ,
76+ 'playlists ' ,
77+ 'catalogs ' ,
78+ 'user ' ,
79+ 'users ' ,
80+ 'shouts ' ,
81+ 'timeline '
82+ );
5783
5884 // Library static version information
5985 protected static $ LIB_version = '350001 ' ;
@@ -117,10 +143,10 @@ public function connect()
117143 $ this ->_debug ('CONNECT ' , "Using $ this ->username / $ this ->password " );
118144
119145 // Set up the handshake
120- $ results = array ();
121- $ timestamp = time ();
146+ $ results = array ();
147+ $ timestamp = time ();
122148
123- $ key = hash ('sha256 ' , $ this ->password );
149+ $ key = hash ('sha256 ' , $ this ->password );
124150 $ passphrase = hash ('sha256 ' , $ timestamp . $ key );
125151
126152 $ options = array (
@@ -138,6 +164,7 @@ public function connect()
138164
139165 if (!$ results ['auth ' ]) {
140166 $ this ->set_state ('error ' );
167+
141168 return false ;
142169 }
143170 $ this ->api_auth = $ results ['auth ' ];
@@ -146,6 +173,8 @@ public function connect()
146173 // not get better with age
147174 $ this ->handshake_time = time ();
148175 $ this ->handshake = $ results ;
176+
177+ return true ;
149178 }
150179
151180 /**
@@ -161,6 +190,7 @@ public function configure($config = array())
161190
162191 if (!is_array ($ config )) {
163192 trigger_error ('AmpacheApi::configure received a non-array value ' );
193+
164194 return false ;
165195 }
166196
@@ -243,7 +273,7 @@ public function send_command($command, $options = array())
243273 {
244274 $ this ->_debug ('SEND COMMAND ' , $ command . ' ' . json_encode ($ options ));
245275
246- if ($ this ->state () != 'READY ' AND $ this ->state () != 'CONNECTED ' ) {
276+ if ($ this ->state () != 'READY ' && $ this ->state () != 'CONNECTED ' ) {
247277 throw new \Exception ('AmpacheApi::send_command API in non-ready state, unable to send ' );
248278 }
249279 $ command = trim ($ command );
@@ -276,6 +306,7 @@ public function send_command($command, $options = array())
276306 $ data = file_get_contents ($ url );
277307 $ this ->raw_response = $ data ;
278308 $ this ->parse_response ($ data );
309+
279310 return $ this ->get_response ();
280311 }
281312
@@ -314,6 +345,7 @@ public function parse_response($response)
314345
315346 xml_parser_free ($ this ->XML_parser );
316347 $ this ->_debug ('PARSE RESPONSE ' , json_encode ($ this ->XML_results ));
348+
317349 return true ;
318350 }
319351
@@ -337,17 +369,17 @@ public function get_response()
337369 public function XML_create_parser ()
338370 {
339371 $ this ->XML_parser = xml_parser_create ();
340- xml_parser_set_option ($ this ->XML_parser ,XML_OPTION_CASE_FOLDING ,false );
341- xml_set_object ($ this ->XML_parser ,$ this );
342- xml_set_element_handler ($ this ->XML_parser ,'XML_start_element ' ,'XML_end_element ' );
343- xml_set_character_data_handler ($ this ->XML_parser ,'XML_cdata ' );
372+ xml_parser_set_option ($ this ->XML_parser , XML_OPTION_CASE_FOLDING , false );
373+ xml_set_object ($ this ->XML_parser , $ this );
374+ xml_set_element_handler ($ this ->XML_parser , 'XML_start_element ' , 'XML_end_element ' );
375+ xml_set_character_data_handler ($ this ->XML_parser , 'XML_cdata ' );
344376 } // XML_create_parser
345377
346378 /**
347379 * XML_cdata
348380 * This is called for the content of the XML tag
349381 */
350- public function XML_cdata ($ parser ,$ cdata )
382+ public function XML_cdata ($ parser , $ cdata )
351383 {
352384 $ cdata = trim ($ cdata );
353385
@@ -360,16 +392,18 @@ public function XML_cdata($parser,$cdata)
360392 } else {
361393 $ this ->XML_results [$ this ->XML_position ][$ this ->XML_currentTag ] = $ cdata ;
362394 }
395+
396+ return true ;
363397 } // XML_cdata
364398
365- public function XML_start_element ($ parser ,$ tag ,$ attributes )
399+ public function XML_start_element ($ parser , $ tag , $ attributes )
366400 {
367401 // Skip it!
368- if (in_array ($ tag ,$ this ->XML_skiptags )) {
402+ if (in_array ($ tag , $ this ->XML_skiptags )) {
369403 return false ;
370404 }
371405
372- if (!in_array ($ tag ,$ this ->XML_parenttags ) OR $ this ->XML_currentTag ) {
406+ if (!in_array ($ tag , $ this ->XML_parenttags ) || $ this ->XML_currentTag ) {
373407 $ this ->XML_subTag = $ tag ;
374408 } else {
375409 $ this ->XML_currentTag = $ tag ;
@@ -384,9 +418,11 @@ public function XML_start_element($parser,$tag,$attributes)
384418 }
385419 }
386420 }
421+
422+ return true ;
387423 } // start_element
388424
389- public function XML_end_element ($ parser ,$ tag )
425+ public function XML_end_element ($ parser , $ tag )
390426 {
391427 if ($ tag != $ this ->XML_currentTag ) {
392428 $ this ->XML_subTag = false ;
0 commit comments