]> Tony Duckles's Git Repositories (git.nynim.org) - delicious-utils.git/blob - delicious-dump/delicious-dump-alltags.php
delicious-dump: Handle changed XML output format
[delicious-utils.git] / delicious-dump / delicious-dump-alltags.php
1 <?php
2 /*
3 Name: delicious-dump-alltags.php
4 Description: Makes a "tags/all" Delicious API call and writes the output to
5 stdout. If there's any problems, error-messages are written to stderr.
6 Author: Tony Duckles <tony@nynim.org>
7
8 Uses the fantastic "php-delicious" library created by E.J. Eliot:
9 http://www.phpdelicious.com/
10
11 Usage:
12 1) Create the "auth_info.inc.php" file, with your Delicious username and
13 password, e.g.:
14 <?php
15 // Private username+password info
16 define('AUTH_DELICIOUS_USERNAME', 'username');
17 define('AUTH_DELICIOUS_PASSWORD', 'password');
18 ?>
19 2) Run this script and redirect the output as needed:
20 $ php delicious-dump-alltags.php > delicious-tags.xml
21 */
22
23 // Load php-delicious library
24 require('php-delicious/php-delicious.inc.php');
25 // Load the (private) "auth_info.inc.php" file
26 require('auth_info.inc.php');
27
28 $sCmd = PHP_DELICIOUS_BASE_URL.'tags/get';
29 $oPhpDelicious = new PhpDelicious(AUTH_DELICIOUS_USERNAME, AUTH_DELICIOUS_PASSWORD);
30 if ($sXml = $oPhpDelicious->HttpRequest($sCmd)) {
31 if (strlen($sXml) > 0) {
32 //// Strip last two lines off the file, because these contain a timestamp
33 //$sXml = substr($sXml, 0, strrpos($sXml,"\n"));
34 //$sXml = substr($sXml, 0, strrpos($sXml,"\n"));
35
36 // If $sXml contains no line-breaks, pretty-ify the XML
37 if (strpos($sXml, "\n") !== true) {
38 $sXml = str_replace("?><tags ","?>\n<tags ", $sXml);
39 $sXml = str_replace("><tag ",">\n <tag ", $sXml);
40 $sXml = str_replace("></tags>",">\n</tags>", $sXml);
41 }
42
43 fwrite(STDOUT, $sXml);
44 }
45 } else {
46 fwrite(STDERR, "Error making HttpRequest(\"sCmd\"): LastErrorNo = ".$oPhpDelicious->LastErrorNo()."\n");
47 }
48
49 ?>