<?php
// Created by Chris S. / FluidMarkup.com / chris@fluidmarkup.com
// Aug. 2008 / Delicious v2 / API v1
// Remember to change $username and $password below
// Modify/redistribute the script as you see fit, but please leave this header intact

$username "delicious_user";
$password "delicious_pass";

// Initiate the cURL session
$ch curl_init("https://api.del.icio.us/v1/posts/all");

// Set up some cURL options
curl_setopt($chCURLOPT_RETURNTRANSFERtrue);
curl_setopt($chCURLOPT_HEADER0);
curl_setopt($chCURLOPT_HEADER0);
curl_setopt($chCURLOPT_USERPWD"$username:$password");

// Execute the cURL command
$data curl_exec($ch);

// Check to see if the response is OK
if(curl_getinfo($chCURLINFO_HTTP_CODE) != 200){ 
    die(
"<b>ERROR:</b> Could not connect to Del.icio.us. Maybe the server is throttled? Wait a few moments and try again.");
}

// Close cURL
curl_close($ch);

// Use SimpleXML to parse the returned data
$doc = new SimpleXmlElement($dataLIBXML_NOCDATA);

// Used for counting errors in the foreach() loop
$errors 0;

echo(
"<b>STARTING</b> with ".$doc['total']." bookmarks.<br><br>");

// For each <post> in the XML
foreach($doc->post as $post){
    
// Encode the URL string so we don't get errors
    
$url2delete urlencode($post['href']);
    
    
// Initiate another cURL session to do the delete
    
$chdel curl_init("https://api.del.icio.us/v1/posts/delete?url=$url2delete");

    
// Set up options for the second cURL session
    
curl_setopt($chdelCURLOPT_RETURNTRANSFERtrue);
    
curl_setopt($chdelCURLOPT_HEADER0);
    
curl_setopt($chdelCURLOPT_HEADER0);
    
curl_setopt($chdelCURLOPT_USERPWD"$username:$password");
    
    
// Run and close the cURL command
    
$datadel curl_exec($chdel);
    
    if(
curl_getinfo($chdelCURLINFO_HTTP_CODE) != 200){ 
        
$statusecho "<font color=\"red\">[ THROTTLED ]</font>";
        
$errors++;
    } else {
        
// Get the status from the delete operation
        
$status = new SimpleXmlElement($datadelLIBXML_NOCDATA);
        
        if(
$status['code'] == "done") { // Success
            
$statusecho "<font color=\"green\">[ OKAY ]</font>"
        } else { 
// Error
            
$statusecho "<font color=\"red\">[ ERROR ]</font>"
            
$errors++;
        }
    }
    
    
curl_close($chdel);
    
    echo(
$post['href']." <b>$statusecho</b><br>");
    
    
// Sleep for 2 seconds so the API doesn't throttle us
    
sleep(2);
}

echo(
"<br><b>DONE</b> with $errors errors.");

?>