1 | <?php |
||
2 | /** |
||
3 | * Do an XML lookup from MusicBrainz. |
||
4 | * |
||
5 | * This example shows how to make a simple REST-style request against a remote |
||
6 | * server. (For a more advanced example of HTML requests, see {@link sparql.php}) |
||
7 | * |
||
8 | * This does two HTTP requests -- one to get information about a band, and another |
||
9 | * to get a list of albums put out by that band. |
||
10 | * |
||
11 | * TODO: Fix the output. |
||
12 | * |
||
13 | * |
||
14 | * @author M Butcher <[email protected]> |
||
15 | * @license LGPL The GNU Lesser GPL (LGPL) or an MIT-like license. |
||
16 | * @see http://musicbrainz.org |
||
17 | */ |
||
18 | require_once '../src/QueryPath/QueryPath.php'; |
||
19 | |||
20 | $artist_url = 'http://musicbrainz.org/ws/1/artist/?type=xml&name=u2'; |
||
21 | $album_url = 'http://musicbrainz.org/ws/1/release/?type=xml&artistid='; |
||
22 | try { |
||
23 | $artist = qp($artist_url, 'artist:first'); |
||
24 | if ($artist->size() > 0) { |
||
0 ignored issues
–
show
|
|||
25 | $id = $artist->attr('id'); |
||
26 | print '<p>The best match we found was for ' . $artist->children('name')->text() . PHP_EOL; |
||
27 | print '</p><p>Artist ID: ' . $id . PHP_EOL; |
||
28 | print '</p><p>Albums for this artist' . PHP_EOL; |
||
29 | print '</p><p><a href="'.$album_url . urlencode($id).'">'.$album_url.'</a></p>'; |
||
30 | $albums = qp($album_url . urlencode($id))->writeXML(); |
||
31 | |||
32 | foreach ($albums as $album) { |
||
33 | print $album->find('title')->text() . PHP_EOL; |
||
34 | // Fixme: Label is broken. See Drupal QueryPath module. |
||
35 | print '(' . $album->next('label')->text() . ')' .PHP_EOL; |
||
36 | } |
||
37 | } |
||
38 | } |
||
39 | catch (Exception $e) { |
||
40 | print $e->getMessage(); |
||
41 | } |
||
42 |
This function has been deprecated. The supplier of the function has supplied an explanatory message.
The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.