From c15e4907624d4e7a300964ded3e22c1aa9fcad3f Mon Sep 17 00:00:00 2001 From: Tony Duckles Date: Mon, 16 Aug 2010 21:30:09 -0500 Subject: [PATCH] Initial commit --- README | 8 + delicious-dump/.gitignore | 1 + delicious-dump/delicious-dump-allposts.php | 42 ++ delicious-dump/delicious-dump-alltags.php | 42 ++ delicious-dump/php-delicious/cache.inc.php | 95 +++ .../examples/mysql-backup/backup-to-mysql.php | 54 ++ .../examples/mysql-backup/db-schema.sql | 19 + .../mysql-backup/restore-from-mysql.php | 40 ++ .../examples/simple-table/simple-table.php | 49 ++ .../php-delicious/php-delicious.inc.php | 539 ++++++++++++++++++ delicious-dump/php-delicious/readme.txt | 55 ++ .../php-delicious/xmlparser.inc.php | 72 +++ delicious-xml2rss/.gitignore | 1 + delicious-xml2rss/delicious-xml2rss.php | 59 ++ 14 files changed, 1076 insertions(+) create mode 100644 README create mode 100644 delicious-dump/.gitignore create mode 100644 delicious-dump/delicious-dump-allposts.php create mode 100644 delicious-dump/delicious-dump-alltags.php create mode 100644 delicious-dump/php-delicious/cache.inc.php create mode 100644 delicious-dump/php-delicious/examples/mysql-backup/backup-to-mysql.php create mode 100755 delicious-dump/php-delicious/examples/mysql-backup/db-schema.sql create mode 100644 delicious-dump/php-delicious/examples/mysql-backup/restore-from-mysql.php create mode 100644 delicious-dump/php-delicious/examples/simple-table/simple-table.php create mode 100644 delicious-dump/php-delicious/php-delicious.inc.php create mode 100644 delicious-dump/php-delicious/readme.txt create mode 100644 delicious-dump/php-delicious/xmlparser.inc.php create mode 100644 delicious-xml2rss/.gitignore create mode 100644 delicious-xml2rss/delicious-xml2rss.php diff --git a/README b/README new file mode 100644 index 0000000..6320c5f --- /dev/null +++ b/README @@ -0,0 +1,8 @@ +Utilities for backing-up and manipulating your Delicious.com data. + +delicious-dump: +delicious-dump/delicious-dump-allposts.php .... Get all bookmarks for a user. +delicious-dump/delicious-dump-alltags.php ..... Get all tags for a user. + +delicious-xml2rss: +delicious-xml2rss/delicious-xml2rss.php ....... Convert a "posts/all" XML file to an RSS feed. diff --git a/delicious-dump/.gitignore b/delicious-dump/.gitignore new file mode 100644 index 0000000..e83aa45 --- /dev/null +++ b/delicious-dump/.gitignore @@ -0,0 +1 @@ +auth_info.inc.php diff --git a/delicious-dump/delicious-dump-allposts.php b/delicious-dump/delicious-dump-allposts.php new file mode 100644 index 0000000..11be456 --- /dev/null +++ b/delicious-dump/delicious-dump-allposts.php @@ -0,0 +1,42 @@ + + + Uses the fantastic "php-delicious" library created by E.J. Eliot: + http://www.phpdelicious.com/ + + Usage: + 1) Create the "auth_info.inc.php" file, with your Delicious username and + password, e.g.: + + 2) Run this script and redirect the output as needed: + $ php delicious-dump-allposts.php > delicious-posts.xml +*/ + + // Load php-delicious library + require('php-delicious/php-delicious.inc.php'); + // Load the (private) "auth_info.inc.php" file + require('auth_info.inc.php'); + + $sCmd = PHP_DELICIOUS_BASE_URL.'posts/all'; + $oPhpDelicious = new PhpDelicious(AUTH_DELICIOUS_USERNAME, AUTH_DELICIOUS_PASSWORD); + if ($sXml = $oPhpDelicious->HttpRequest($sCmd)) { + if (strlen($sXml) > 0) { + // Strip last two lines off the file, because these contain a timestamp + $sXml = substr($sXml, 0, strrpos($sXml,"\n")); + $sXml = substr($sXml, 0, strrpos($sXml,"\n")); + + fwrite(STDOUT, $sXml); + } + } else { + fwrite(STDERR, "Error making HttpRequest(\"sCmd\"): LastErrorNo = ".$oPhpDelicious->LastErrorNo()."\n"); + } + +?> diff --git a/delicious-dump/delicious-dump-alltags.php b/delicious-dump/delicious-dump-alltags.php new file mode 100644 index 0000000..8cc422c --- /dev/null +++ b/delicious-dump/delicious-dump-alltags.php @@ -0,0 +1,42 @@ + + + Uses the fantastic "php-delicious" library created by E.J. Eliot: + http://www.phpdelicious.com/ + + Usage: + 1) Create the "auth_info.inc.php" file, with your Delicious username and + password, e.g.: + + 2) Run this script and redirect the output as needed: + $ php delicious-dump-alltags.php > delicious-tags.xml +*/ + + // Load php-delicious library + require('php-delicious/php-delicious.inc.php'); + // Load the (private) "auth_info.inc.php" file + require('auth_info.inc.php'); + + $sCmd = PHP_DELICIOUS_BASE_URL.'tags/get'; + $oPhpDelicious = new PhpDelicious(AUTH_DELICIOUS_USERNAME, AUTH_DELICIOUS_PASSWORD); + if ($sXml = $oPhpDelicious->HttpRequest($sCmd)) { + if (strlen($sXml) > 0) { + // Strip last two lines off the file, because these contain a timestamp + $sXml = substr($sXml, 0, strrpos($sXml,"\n")); + $sXml = substr($sXml, 0, strrpos($sXml,"\n")); + + fwrite(STDOUT, $sXml); + } + } else { + fwrite(STDERR, "Error making HttpRequest(\"sCmd\"): LastErrorNo = ".$oPhpDelicious->LastErrorNo()."\n"); + } + +?> diff --git a/delicious-dump/php-delicious/cache.inc.php b/delicious-dump/php-delicious/cache.inc.php new file mode 100644 index 0000000..c28fdc3 --- /dev/null +++ b/delicious-dump/php-delicious/cache.inc.php @@ -0,0 +1,95 @@ +sShortKey = $sPrefix.md5($sKey); + $this->sFile = "$sCachePath$this->sShortKey.txt"; + $this->sFileLock = "$this->sFile.lock"; + $this->iCacheTime = $iCacheTime; + } + + public function Check() { + if (array_key_exists($this->sShortKey, self::$aCache) || file_exists($this->sFileLock)) { + return true; + } + return (file_exists($this->sFile) && ($this->iCacheTime == -1 || time() - filemtime($this->sFile) <= $this->iCacheTime)); + } + + public function Exists() { + return (array_key_exists($this->sShortKey, self::$aCache)) || (file_exists($this->sFile) || file_exists($this->sFileLock)); + } + + public function Set($vContents) { + if (!file_exists($this->sFileLock)) { + if (file_exists($this->sFile)) { + copy($this->sFile, $this->sFileLock); + } + $oFile = fopen($this->sFile, 'w'); + fwrite($oFile, serialize($vContents)); + fclose($oFile); + if (file_exists($this->sFileLock)) { + unlink($this->sFileLock); + } + self::$aCache[$this->sShortKey] = $vContents; + return true; + } + return false; + } + + public function Get() { + if (array_key_exists($this->sShortKey, self::$aCache)) { + return self::$aCache[$this->sShortKey]; + } else if (file_exists($this->sFileLock)) { + self::$aCache[$this->sShortKey] = unserialize(file_get_contents($this->sFileLock)); + return self::$aCache[$this->sShortKey]; + } else { + self::$aCache[$this->sShortKey] = unserialize(file_get_contents($this->sFile)); + return self::$aCache[$this->sShortKey]; + } + } + + public function ReValidate() { + touch($this->sFile); + } + } +?> \ No newline at end of file diff --git a/delicious-dump/php-delicious/examples/mysql-backup/backup-to-mysql.php b/delicious-dump/php-delicious/examples/mysql-backup/backup-to-mysql.php new file mode 100644 index 0000000..7db0298 --- /dev/null +++ b/delicious-dump/php-delicious/examples/mysql-backup/backup-to-mysql.php @@ -0,0 +1,54 @@ +GetAllPosts()) { + if ($oDb = mysql_connect(MYSQL_SERVER, MYSQL_USER, MYSQL_PASS)) { + if (mysql_select_db(MYSQL_DB, $oDb)) { + mysql_query('delete from '.POSTS_TABLE, $oDb); + mysql_query('delete from '.TAGS_TABLE, $oDb); + $sInsertPosts = 'insert into '.POSTS_TABLE.' (url, description, notes, hash, updated) values'; + $sInsertTags = 'insert into '.TAGS_TABLE.' (hash, tag) values'; + foreach ($aPosts as $aPost) { + $sInsertPosts .= sprintf(" ('%s', '%s', '%s', '%s', '%s'),", + mysql_real_escape_string($aPost['url'], $oDb), + mysql_real_escape_string($aPost['desc'], $oDb), + mysql_real_escape_string($aPost['notes'], $oDb), + mysql_real_escape_string($aPost['hash'], $oDb), + mysql_real_escape_string($aPost['updated'], $oDb) + ); + foreach ($aPost['tags'] as $sTag) { + $sInsertTags .= sprintf(" ('%s', '%s'),", + mysql_real_escape_string($aPost['hash'], $oDb), + mysql_real_escape_string($sTag, $oDb) + ); + } + } + mysql_query(rtrim($sInsertPosts, ','), $oDb); + mysql_query(rtrim($sInsertTags, ','), $oDb); + } else { + echo mysql_error($oDb); + } + mysql_close($oDb); + } else { + echo "Could not connect to MySql server."; + } + } else { + echo $oDelicious->LastErrorString(); + } +?> \ No newline at end of file diff --git a/delicious-dump/php-delicious/examples/mysql-backup/db-schema.sql b/delicious-dump/php-delicious/examples/mysql-backup/db-schema.sql new file mode 100755 index 0000000..69c98f2 --- /dev/null +++ b/delicious-dump/php-delicious/examples/mysql-backup/db-schema.sql @@ -0,0 +1,19 @@ +create database if not exists delicious + default character set utf8 + default collate utf8_general_ci; + +use delicious; + +create table if not exists posts ( + url varchar(250), + description varchar(250), + notes text, + hash varchar(50), + updated datetime, + primary key(hash) +); + +create table if not exists tags ( + hash varchar(50), + tag varchar(50) +); \ No newline at end of file diff --git a/delicious-dump/php-delicious/examples/mysql-backup/restore-from-mysql.php b/delicious-dump/php-delicious/examples/mysql-backup/restore-from-mysql.php new file mode 100644 index 0000000..03c1538 --- /dev/null +++ b/delicious-dump/php-delicious/examples/mysql-backup/restore-from-mysql.php @@ -0,0 +1,40 @@ +AddPost($aPost['url'], $aPost['description'], $aPost['notes'], $aTags, $aPost['updated'], true); + } + } + } else { + echo mysql_error($oDb); + } + mysql_close($oDb); + } else { + echo "Could not connect to MySql server."; + } +?> \ No newline at end of file diff --git a/delicious-dump/php-delicious/examples/simple-table/simple-table.php b/delicious-dump/php-delicious/examples/simple-table/simple-table.php new file mode 100644 index 0000000..4794df5 --- /dev/null +++ b/delicious-dump/php-delicious/examples/simple-table/simple-table.php @@ -0,0 +1,49 @@ + + + + + + + Simple Table of All Posts + + + + +

Simple Table of All Posts

+ GetAllPosts()) { ?> +

posts in this account. Results cached for 10 seconds (by default).

+ + + + + + + + + + + + + +
DescriptionNotesLast Updated
+ LastErrorString(); + } + ?> + + + \ No newline at end of file diff --git a/delicious-dump/php-delicious/php-delicious.inc.php b/delicious-dump/php-delicious/php-delicious.inc.php new file mode 100644 index 0000000..5c37023 --- /dev/null +++ b/delicious-dump/php-delicious/php-delicious.inc.php @@ -0,0 +1,539 @@ +sUsername = urlencode($sUsername); + $this->sPassword = urlencode($sPassword); + $this->iCacheTime = $iCacheTime; + + // create instance of XML parser class + $this->oXmlParser = new XmlParser(); + } + + /************************ private methods ************************/ + + protected function FromDeliciousDate($sDate) { + return trim(str_replace(array('T', 'Z'), ' ', $sDate)); + } + + protected function ToDeliciousDate($sDate) { + return date('Y-m-d\TH:i:s\Z', strtotime($sDate)); + } + + protected function GetBoolReturn($sInput) { + return ($sInput == 'done' || $sInput == 'ok'); + } + + protected function Delay() { + // could use microtime but not supported on all systems + if (!is_null($this->iLastRequest) && time() - $this->iLastRequest < 1) { + sleep(1); + } else { + $this->iLastRequest = time(); + } + } + + public function HttpRequest($sCmd) { + // check for curl lib, use in preference to file_get_contents if available + if (function_exists('curl_init')) { + // initiate session + $oCurl = curl_init($sCmd); + // set options + curl_setopt_array($oCurl, array( + CURLOPT_RETURNTRANSFER => true, + CURLOPT_USERAGENT => PHP_DELICIOUS_USER_AGENT, + CURLOPT_CONNECTTIMEOUT => PHP_DELICIOUS_CONNECT_TIMEOUT, + CURLOPT_TIMEOUT => PHP_DELICIOUS_TRANSFER_TIMEOUT, + CURLOPT_DNS_CACHE_TIMEOUT => PHP_DELICIOUS_DNS_TIMEOUT, + CURLOPT_USERPWD => "$this->sUsername:$this->sPassword" + )); + // request URL + if ($sResult = curl_exec($oCurl)) { + switch (curl_getinfo($oCurl, CURLINFO_HTTP_CODE)) { + case 200: + return $sResult; + break; + case 503: + $this->iLastError = PHP_DELICIOUS_ERR_THROTTLED; + break; + case 401: + $this->iLastError = PHP_DELICIOUS_ERR_INCORRECT_LOGIN; + break; + default: + $this->iLastError = PHP_DELICIOUS_ERR_CONNECTION_FAILED; + } + } + // close session + curl_close($oCurl); + + return false; + } else { + // set user agent + ini_set('user_agent', PHP_DELICIOUS_USER_AGENT); + + // add basic auth details + $sCmd = str_replace('https://', "https://$this->sUsername:$this->sPassword@", $sCmd); + + // fopen_wrappers need to be enabled for this to work - see http://www.php.net/manual/en/function.file-get-contents.php + if ($sResult = @file_get_contents($sCmd)) { + if (strstr($http_response_header[0], '503')) { + $this->iLastError = PHP_DELICIOUS_ERR_THROTTLED; + } else { + if (strstr($http_response_header[0], '401')) { + $this->iLastError = PHP_DELICIOUS_ERR_INCORRECT_LOGIN; + } else { + return $sResult; + } + } + } else { + $this->iLastError = PHP_DELICIOUS_ERR_CONNECTION_FAILED; + } + } + return false; + } + + protected function DeliciousRequest($sCmd, $aParameters = array()) { + if ($this->LastError() >= 1 && $this->LastError() <= 3) { + return false; + } + + // reset the last error + $this->iLastError = 0; + + // construct URL - add username, password and command to run + $sCmd = PHP_DELICIOUS_BASE_URL.$sCmd; + + // check for parameters + if (count($aParameters) > 0) { + $sCmd .= '?'; + } + + // add parameters to command + $iCount = 0; + + foreach ($aParameters as $sKey => $sValue) { + if ($sValue != '') { + if ($iCount > 0) { + $sCmd .= '&'; + } + $sCmd .= "$sKey=".urlencode($sValue); + $iCount++; + } + } + + if ($sXml = $this->HttpRequest($sCmd)) { + // return result passed as array + if ($aXml = $this->oXmlParser->Parse($sXml)) { + return $aXml; + } else { + $this->iLastError = PHP_DELICIOUS_ERR_XML_PARSE; + } + } + return false; + } + + // generic function to get post listings + protected function GetList($sCmd, $sTag = '', $sDate = '', $sUrl = '', $iCount = -1) { + $oCache = new Cache($this->sUsername.$sCmd.$sTag.$sDate.$sUrl.$iCount, $this->iCacheTime); + + if (!$oCache->Check()) { + if ($sCmd == 'posts/all' && $oCache->Exists()) { + $sLastUpdate = $this->GetLastUpdate(); + + $aData = $oCache->Get(); + + if ($aData['last-update'] == $sLastUpdate) { + $oCache->Set($aData); + return $aData['items']; + } + } + + // initialise parameters array + $aParameters = array(); + + // check for optional parameters + if ($sTag != '') { + $aParameters['tag'] = $sTag; + } + if ($sDate != '') { + $aParameters['dt'] = $this->ToDeliciousDate($sDate); + } + if ($sUrl != '') { + $aParameters['url'] = $sUrl; + } + if ($iCount != -1) { + $aParameters['count'] = $iCount; + } + + // make request + if ($aResult = $this->DeliciousRequest($sCmd, $aParameters)) { + $aPosts = array(); + $aPosts['last-update'] = $this->FromDeliciousDate($aResult['attributes']['UPDATE']); + $aPosts['items'] = array(); + foreach ($aResult['items'] as $aCurPost) { + // check absence of tags for current URL + $aCurPost['attributes']['TAG'] != 'system:unfiled' ? $aTags = explode(' ', $aCurPost['attributes']['TAG']) : $aTags = array(); + + $aNewPost = array( + 'url' => $aCurPost['attributes']['HREF'], + 'desc' => $aCurPost['attributes']['DESCRIPTION'], + 'notes' => $aCurPost['attributes']['EXTENDED'], + 'hash' => $aCurPost['attributes']['HASH'], + 'tags' => $aTags, + 'updated' => $this->FromDeliciousDate($aCurPost['attributes']['TIME']) + ); + + if ($sCmd == 'posts/get') { + $aNewPost['count'] = $aCurPost['attributes']['OTHERS']; + } + + $aPosts['items'][] = $aNewPost; + } + $oCache->Set($aPosts); + } else { + $oCache->Set(false); + } + } + $aData = $oCache->Get(); + return $aData['items']; + } + + /************************ public methods ************************/ + + public function LastError() { // alias to LastErrorNo for backwards compatibility + return $this->LastErrorNo(); + } + + public function LastErrorNo() { + return $this->iLastError; + } + + public function LastErrorString() { + switch ($this->iLastError) { + case 1: + return 'Connection to del.icio.us failed.'; + case 2: + return 'Incorrect del.icio.us username or password.'; + case 3: + return 'Del.icio.us API access throttled.'; + case 4: + return 'XML parse error has occurred.'; + case 5: + return 'An unknown error has occurred.'; + default: + return ''; + } + } + + public function GetLastUpdate() { + // get last time the user updated their del.icio.us account + if ($aResult = $this->DeliciousRequest('posts/update')) { + return $this->FromDeliciousDate($aResult['attributes']['TIME']); + } + return false; + } + + public function GetAllTags() { + $oCache = new Cache($this->sUsername.'tags/get', $this->iCacheTime); + + if (!$oCache->Check()) { + if ($aResult = $this->DeliciousRequest('tags/get')) { + $aTags = array(); + foreach ($aResult['items'] as $aTag) { + $aTags[] = array( + 'tag' => $aTag['attributes']['TAG'], + 'count' => $aTag['attributes']['COUNT'] + ); + } + $oCache->Set($aTags); + } else { + $oCache->Set(false); + } + } + return $oCache->Get(); + } + + public function RenameTag($sOld, $sNew) { + $this->Delay(); + + if ($aResult = $this->DeliciousRequest('tags/rename', array('old' => $sOld, 'new' => $sNew))) { + if ($aResult['content'] == 'done') { + return true; + } + } + return false; + } + + public function GetPosts( + $sTag = '', // filter by tag + $sDate = '', // filter by date - format YYYY-MM-DD HH:MM:SS + $sUrl = '' // filter by URL + ) { + return $this->GetList('posts/get', $sTag, $sDate, $sUrl); + } + + public function GetRecentPosts( + $sTag = '', // filter by tag + $iCount = 15 // number of posts to retrieve, min 15, max 100 + ) { + return $this->GetList('posts/recent', $sTag, '', '', $iCount); + } + + public function GetAllPosts( + $sTag = '' // filter by tag + ) { + return $this->GetList('posts/all', $sTag, '', '', -1); + } + + public function GetDates( + $sTag = '' // filter by tag + ) { + // set up cache object + $oCache = new Cache($this->sUsername."posts/dates$sTag", $this->iCacheTime); + + // check for cached data + if (!$oCache->Check()) { + // return number of posts for each date + if ($aResult = $this->DeliciousRequest('posts/dates', array('tag' => $sTag))) { + $aDates = array(); + + foreach ($aResult['items'] as $aCurDate) { + $aDates[] = array( + 'date' => $this->FromDeliciousDate($aCurDate['attributes']['DATE']), + 'count' => $aCurDate['attributes']['COUNT'] + ); + } + $oCache->Set($aDates); + } else { + $oCache->Set(false); + } + } + // return data from cache + return $oCache->Get(); + } + + public function AddPost( + $sUrl, // URL of post + $sDescription, // description of post + $sNotes = '', // additional notes relating to post + $aTags = array(), // tags to assign to the post + $sDate = '', // date of the post, format YYYY-MM-DD HH:MM:SS - default is current date and time + $bReplace = true // if set, any existing post with the same URL will be replaced + ) { + $this->Delay(); + + $aParameters = array( + 'url' => $sUrl, + 'description' => $sDescription, + 'extended' => $sNotes, + 'tags' => implode(' ', $aTags) + ); + + if ($sDate != '') { + $aParameters['dt'] = $this->ToDeliciousDate($sDate); + } + if (!$bReplace) { + $aParameters['replace'] = 'no'; + } + + if ($aResult = $this->DeliciousRequest('posts/add', $aParameters)) { + return $this->GetBoolReturn($aResult['attributes']['CODE']); + } + + return false; + } + + public function DeletePost($sUrl) { + $this->Delay(); + + if ($aResult = $this->DeliciousRequest('posts/delete', array('url' => $sUrl))) { + return $this->GetBoolReturn($aResult['attributes']['CODE']); + } + return false; + } + + public function GetAllBundles() { + $oCache = new Cache($this->sUsername.'tags/bundles/all', $this->iCacheTime); + + if (!$oCache->Check()) { + if ($aResult = $this->DeliciousRequest('tags/bundles/all')) { + $aBundles = array(); + foreach ($aResult['items'] as $aCurBundle) { + $aBundles[] = array( + 'name' => $aCurBundle['attributes']['NAME'], + 'tags' => $aCurBundle['attributes']['TAGS'] + ); + } + $oCache->Set($aBundles); + } else { + $oCache->Set(false); + } + } + return $oCache->Get(); + } + + public function AddBundle($sName, $aTags) { + $this->Delay(); + + if ($aResult = $this->DeliciousRequest('tags/bundles/set', array('bundle' => $sName, 'tags' => implode(' ', $aTags)))) { + return $this->GetBoolReturn($aResult['content']); + } + return false; + } + + public function DeleteBundle($sName) { + $this->Delay(); + + if ($aResult = $this->DeliciousRequest('tags/bundles/delete', array('bundle' => $sName))) { + return $this->GetBoolReturn($aResult['content']); + } + return false; + } + + // the remaining methods call the JSON API + + public function GetUrlDetails( + $vUrls // this can take a single URL or an array of URLs (up to 15) + ) { + if (function_exists('json_decode')) { + $oCache = new Cache('url/data'.implode($vUrls), $this->iCacheTime); + + if (!$oCache->Check()) { + $sUrl = PHP_DELICIOUS_JSON_URL.'url/data?'; + + if (is_array($vUrls)) { + foreach ($vUrls as $sCurrentUrl) { + $sUrl .= 'hash='.md5($sCurrentUrl).'&'; + } + $sUrl .= rtrim($sUrl, '&'); + } else { + $sUrl .= 'hash='.md5($vUrls); + } + + if ($sJson = $this->HttpRequest($sUrl)) { + $oCache->Set(json_decode($sJson)); + } else { + $oCache->Set(false); + } + } + + return $oCache->Get(); + } + return false; + } + + public function GetNetwork($sUsername) { + if (function_exists('json_decode')) { + $oCache = new Cache("network/$sUsername", $this->iCacheTime); + + if (!$oCache->Check()) { + if ($sJson = $this->HttpRequest(PHP_DELICIOUS_JSON_URL."network/$sUsername")) { + $oCache->Set(json_decode($sJson)); + } else { + $oCache->Set(false); + } + } + + return $oCache->Get(); + } + return false; + } + + public function GetMyNetwork() { + return $this->GetNetwork($this->sUsername); + } + + public function GetFans($sUsername) { + if (function_exists('json_decode')) { + $oCache = new Cache("fans/$sUsername", $this->iCacheTime); + + if (!$oCache->Check()) { + if ($sJson = $this->HttpRequest(PHP_DELICIOUS_JSON_URL."fans/$sUsername")) { + $oCache->Set(json_decode($sJson)); + } else { + $oCache->Set(false); + } + } + + return $oCache->Get(); + } + return false; + } + + public function GetMyFans() { + return $this->GetFans($this->sUsername); + } + } +?> \ No newline at end of file diff --git a/delicious-dump/php-delicious/readme.txt b/delicious-dump/php-delicious/readme.txt new file mode 100644 index 0000000..c5fde70 --- /dev/null +++ b/delicious-dump/php-delicious/readme.txt @@ -0,0 +1,55 @@ +PhpDelicious v2 - a library for accessing the del.ico.us API +============================================================ + +Overview +-------- + +Support for: + +* PHP 5 (PHP 4 support dropped in the latest version) +* adding, updating, deleting posts +* viewing posts, post date statistics +* adding, deleting, renaming tags +* adding, updating, deleting bundles +* returning last update date +* retrieving URL details, network and fans +* returning error numbers and messages +* caching and automatic protection against throttling of API +* HTTP requests through CURL or fopen (automatic selection from supported methods) +* Backup and restore to/from MySql (implemented in example files) + +Site URL +-------- + +http://www.phpdelicious.com/ + +License +------- + +Software License Agreement (BSD License) + +Copyright (C) 2005-2008, Edward Eliot. +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: + +* Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. +* Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. +* Neither the name of Edward Eliot nor the names of its contributors + may be used to endorse or promote products derived from this software + without specific prior written permission of Edward Eliot. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER AND CONTRIBUTORS "AS IS" AND ANY +EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY +DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES +(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND +ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. \ No newline at end of file diff --git a/delicious-dump/php-delicious/xmlparser.inc.php b/delicious-dump/php-delicious/xmlparser.inc.php new file mode 100644 index 0000000..c05ec5e --- /dev/null +++ b/delicious-dump/php-delicious/xmlparser.inc.php @@ -0,0 +1,72 @@ +aXmlResult = array(); + $oParser = xml_parser_create(); + xml_set_object($oParser, $this); + xml_set_element_handler($oParser, "StartTag", "CloseTag"); + xml_set_character_data_handler($oParser, "TagContent"); + if (!xml_parse($oParser, $sXml)) { + return false; + } + xml_parser_free($oParser); + return $this->aXmlResult[0]; + } + + protected function StartTag($oParser, $sName, $sattributes) { + $sTag = array("name" => $sName, "attributes" => $sattributes); + array_push($this->aXmlResult, $sTag); + } + + protected function TagContent($oParser, $sTagData) { + if (trim($sTagData)) { + if (isset($this->aXmlResult[count($this->aXmlResult) - 1]['content'])) { + $this->aXmlResult[count($this->aXmlResult) - 1]['content'] .= $sTagData; + } else { + $this->aXmlResult[count($this->aXmlResult) - 1]['content'] = $sTagData; + } + } + } + + protected function CloseTag($parser, $name) { + $this->aXmlResult[count($this->aXmlResult) - 2]['items'][] = $this->aXmlResult[count($this->aXmlResult) - 1]; + array_pop($this->aXmlResult); + } + } +?> \ No newline at end of file diff --git a/delicious-xml2rss/.gitignore b/delicious-xml2rss/.gitignore new file mode 100644 index 0000000..3414e6a --- /dev/null +++ b/delicious-xml2rss/.gitignore @@ -0,0 +1 @@ +userinfo.inc.php diff --git a/delicious-xml2rss/delicious-xml2rss.php b/delicious-xml2rss/delicious-xml2rss.php new file mode 100644 index 0000000..29511bc --- /dev/null +++ b/delicious-xml2rss/delicious-xml2rss.php @@ -0,0 +1,59 @@ + + + Usage: + 1) Create the "userinfo.inc.php" file, with your Delicious username and + full-name, e.g.: + + 2) Run this script and redirect the output as needed: + $ php delicious-xml2rss.php < delicious-posts.xml > delicious-rss.xml +*/ + + // Load the (private) "auth_info.inc.php" file + require('userinfo.inc.php'); + if (!defined('DELICIOUS_USERNAME')) + define('DELICIOUS_USERNAME', 'username'); + + // Print the initial '' line using PHP code, so that the trailing + // "?"+">" doesn't confuse PHP and/or editor syntax-highlighting. + print ''."\n"; +?> + + + Delicious/<? print DELICIOUS_USERNAME; ?> + http://delicious.com/ + bookmarks posted by + + + $line) { + if ($line_num > 1) { + $pattern = '/ 0) { + echo ' '."\n"; + echo ' '.$matches[3].''."\n"; + echo ' '.date('r', strtotime(str_replace('T', ' ',$matches[5]))).''."\n"; + echo ' http://delicious.com/url/'.$matches[2].'#'.DELICIOUS_USERNAME.''."\n"; + echo ' '.$matches[1].''."\n"; + echo ' '."\n"; + echo ' http://delicious.com/url/'.$matches[2].''."\n"; + echo ' http://feeds.delicious.com/v2/rss/url/'.$matches[2].''."\n"; + echo ' '.DELICIOUS_USERNAME.'\'s bookmarks'."\n"; + $tags = explode(' ', $matches[4]); + foreach ($tags as $tag) { + echo ' '.$tag.''."\n"; + } + echo ' '."\n"; + } + } + } +?> + + -- 2.43.0