@@ -20,21 +20,21 @@ |
||
| 20 | 20 | $artist_url = 'http://musicbrainz.org/ws/1/artist/?type=xml&name=u2'; |
| 21 | 21 | $album_url = 'http://musicbrainz.org/ws/1/release/?type=xml&artistid='; |
| 22 | 22 | try { |
| 23 | - $artist = qp($artist_url, 'artist:first'); |
|
| 24 | - if ($artist->size() > 0) { |
|
| 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(); |
|
| 23 | + $artist = qp($artist_url, 'artist:first'); |
|
| 24 | + if ($artist->size() > 0) { |
|
| 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 | 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 | - } |
|
| 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 | 38 | } catch (Exception $e) { |
| 39 | - print $e->getMessage(); |
|
| 39 | + print $e->getMessage(); |
|
| 40 | 40 | } |
@@ -32,10 +32,10 @@ |
||
| 32 | 32 | </svg>'; |
| 33 | 33 | |
| 34 | 34 | qp($svg_stub) |
| 35 | - ->attr(['width' => 800, 'height' => 600]) |
|
| 36 | - ->append('<rect id="first"/><rect id="second"/>') |
|
| 37 | - ->find('#second') |
|
| 38 | - ->attr(['x' => 15, 'y' => 4, 'width' => 40, 'height' => 60, 'fill' => 'red']) |
|
| 39 | - ->prev() |
|
| 40 | - ->attr(['x' => 2, 'y' => 2, 'width' => 40, 'height' => 60, 'fill' => 'navy']) |
|
| 41 | - ->writeXML(); |
|
| 35 | + ->attr(['width' => 800, 'height' => 600]) |
|
| 36 | + ->append('<rect id="first"/><rect id="second"/>') |
|
| 37 | + ->find('#second') |
|
| 38 | + ->attr(['x' => 15, 'y' => 4, 'width' => 40, 'height' => 60, 'fill' => 'red']) |
|
| 39 | + ->prev() |
|
| 40 | + ->attr(['x' => 2, 'y' => 2, 'width' => 40, 'height' => 60, 'fill' => 'navy']) |
|
| 41 | + ->writeXML(); |
|
@@ -33,19 +33,19 @@ discard block |
||
| 33 | 33 | //$url = 'http://dbpedia.org/data/The_Lord_of_the_Rings.rdf'; |
| 34 | 34 | // HTTP headers: |
| 35 | 35 | $headers = [ |
| 36 | - 'Accept: application/rdf,application/rdf+xml;q=0.9,*/*;q=0.8', |
|
| 37 | - 'Accept-Language: en-us,en', |
|
| 38 | - 'Accept-Charset: ISO-8859-1,utf-8', |
|
| 39 | - 'User-Agent: QueryPath/1.2', |
|
| 36 | + 'Accept: application/rdf,application/rdf+xml;q=0.9,*/*;q=0.8', |
|
| 37 | + 'Accept-Language: en-us,en', |
|
| 38 | + 'Accept-Charset: ISO-8859-1,utf-8', |
|
| 39 | + 'User-Agent: QueryPath/1.2', |
|
| 40 | 40 | ]; |
| 41 | 41 | |
| 42 | 42 | // The context options: |
| 43 | 43 | $options = [ |
| 44 | - 'http' => [ |
|
| 45 | - 'method' => 'GET', |
|
| 46 | - 'protocol_version' => 1.1, |
|
| 47 | - 'header' => implode("\r\n", $headers), |
|
| 48 | - ], |
|
| 44 | + 'http' => [ |
|
| 45 | + 'method' => 'GET', |
|
| 46 | + 'protocol_version' => 1.1, |
|
| 47 | + 'header' => implode("\r\n", $headers), |
|
| 48 | + ], |
|
| 49 | 49 | ]; |
| 50 | 50 | |
| 51 | 51 | // Create a stream context that will tell QueryPath how to |
@@ -78,21 +78,21 @@ discard block |
||
| 78 | 78 | |
| 79 | 79 | print "\nImages:\n"; |
| 80 | 80 | foreach ($qp->branch()->find('foaf|img') as $img) { |
| 81 | - // Note that when we use attr() we are using the XML name, NOT |
|
| 82 | - // the CSS 3 name. So it is rdf:resource, not rdf|resource. |
|
| 83 | - // The same goes for the tag() function -- it will return |
|
| 84 | - // the full element name (e.g. rdf:Description). |
|
| 85 | - print $img->attr('rdf:resource') . PHP_EOL; |
|
| 81 | + // Note that when we use attr() we are using the XML name, NOT |
|
| 82 | + // the CSS 3 name. So it is rdf:resource, not rdf|resource. |
|
| 83 | + // The same goes for the tag() function -- it will return |
|
| 84 | + // the full element name (e.g. rdf:Description). |
|
| 85 | + print $img->attr('rdf:resource') . PHP_EOL; |
|
| 86 | 86 | } |
| 87 | 87 | |
| 88 | 88 | print "\nImages Galleries:\n"; |
| 89 | 89 | foreach ($qp->branch()->find('dbpprop|hasPhotoCollection') as $img) { |
| 90 | - print $img->attr('rdf:resource') . PHP_EOL; |
|
| 90 | + print $img->attr('rdf:resource') . PHP_EOL; |
|
| 91 | 91 | } |
| 92 | 92 | |
| 93 | 93 | print "\nOther Sites:\n"; |
| 94 | 94 | foreach ($qp->branch()->find('foaf|page') as $img) { |
| 95 | - print $img->attr('rdf:resource') . PHP_EOL; |
|
| 95 | + print $img->attr('rdf:resource') . PHP_EOL; |
|
| 96 | 96 | } |
| 97 | 97 | |
| 98 | 98 | //$qp->writeXML(); |
@@ -42,8 +42,8 @@ discard block |
||
| 42 | 42 | |
| 43 | 43 | // We first set up the parameters that will be sent. |
| 44 | 44 | $params = [ |
| 45 | - 'query' => $sparql, |
|
| 46 | - 'format' => 'application/sparql-results+xml', |
|
| 45 | + 'query' => $sparql, |
|
| 46 | + 'format' => 'application/sparql-results+xml', |
|
| 47 | 47 | ]; |
| 48 | 48 | |
| 49 | 49 | // DB Pedia wants a GET query, so we create one. |
@@ -56,27 +56,27 @@ discard block |
||
| 56 | 56 | // Get the headers from the resulting XML. |
| 57 | 57 | $headers = []; |
| 58 | 58 | foreach ($qp->children('variable') as $col) { |
| 59 | - $headers[] = $col->attr('name'); |
|
| 59 | + $headers[] = $col->attr('name'); |
|
| 60 | 60 | } |
| 61 | 61 | |
| 62 | 62 | // Get rows of data from result. |
| 63 | 63 | $rows = []; |
| 64 | 64 | $col_count = count($headers); |
| 65 | 65 | foreach ($qp->top()->find('results>result') as $row) { |
| 66 | - $cols = []; |
|
| 67 | - $row->children(); |
|
| 68 | - for ($i = 0; $i < $col_count; ++$i) { |
|
| 69 | - $cols[$i] = $row->branch()->eq($i)->text(); |
|
| 70 | - } |
|
| 71 | - $rows[] = $cols; |
|
| 66 | + $cols = []; |
|
| 67 | + $row->children(); |
|
| 68 | + for ($i = 0; $i < $col_count; ++$i) { |
|
| 69 | + $cols[$i] = $row->branch()->eq($i)->text(); |
|
| 70 | + } |
|
| 71 | + $rows[] = $cols; |
|
| 72 | 72 | } |
| 73 | 73 | |
| 74 | 74 | // Turn data into table. |
| 75 | 75 | $table = '<table><tr><th>' . implode('</th><th>', $headers) . '</th></tr>'; |
| 76 | 76 | foreach ($rows as $row) { |
| 77 | - $table .= '<tr><td>'; |
|
| 78 | - $table .= implode('</td><td>', $row); |
|
| 79 | - $table .= '</td></tr>'; |
|
| 77 | + $table .= '<tr><td>'; |
|
| 78 | + $table .= implode('</td><td>', $row); |
|
| 79 | + $table .= '</td></tr>'; |
|
| 80 | 80 | } |
| 81 | 81 | $table .= '</table>'; |
| 82 | 82 | |
@@ -48,7 +48,7 @@ |
||
| 48 | 48 | |
| 49 | 49 | // DB Pedia wants a GET query, so we create one. |
| 50 | 50 | $data = http_build_query($params); |
| 51 | -$url .= '?' . $data; |
|
| 51 | +$url .= '?' . $data; |
|
| 52 | 52 | |
| 53 | 53 | // Next, we simply retrieve, parse, and output the contents. |
| 54 | 54 | $qp = qp($url, 'head'); |
@@ -31,9 +31,9 @@ discard block |
||
| 31 | 31 | */ |
| 32 | 32 | function exampleCallback($index, $item) |
| 33 | 33 | { |
| 34 | - $text = qp($item)->text(); |
|
| 34 | + $text = qp($item)->text(); |
|
| 35 | 35 | |
| 36 | - return strpos($text, 'Release') !== false; |
|
| 36 | + return strpos($text, 'Release') !== false; |
|
| 37 | 37 | } |
| 38 | 38 | |
| 39 | 39 | /* |
@@ -47,5 +47,5 @@ discard block |
||
| 47 | 47 | * into a stand-alone function. |
| 48 | 48 | */ |
| 49 | 49 | print htmlqp('http://php.net/', 'h1.summary a') |
| 50 | - ->filterCallback('exampleCallback') |
|
| 51 | - ->textImplode(PHP_EOL); |
|
| 50 | + ->filterCallback('exampleCallback') |
|
| 51 | + ->textImplode(PHP_EOL); |
|