Função PHP para enviar páginas para o Del.icio.us

LINKS PATROCINADOS

<?php
//1. $site must start with http://
//2. $tags must be separated with spaces, not commas
//3. $proxy_addy must start with http://
//4. $use_proxy must be passed in as TRUE if you want to use a proxy
//5. Make sure you have CURL installed.

function delicious_submit($user, $pass, $site, $note, $desc, $tags, $proxy_addy, $proxy_port, $use_proxy = FALSE)
{
// Set curl options.
$user_agent = “Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)”;
$ch = curl_init();
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
curl_setopt($ch, CURLOPT_USERAGENT, $user_agent);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_COOKIEJAR, dirname(__FILE__).’/cookie.txt’);
curl_setopt($ch, CURLOPT_COOKIEFILE, dirname(__FILE__).’/cookie.txt’);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
if($use_proxy){
curl_setopt($ch, CURLOPT_HTTPPROXYTUNNEL, 1);
curl_setopt($ch, CURLOPT_PROXY, $proxy_addy);
curl_setopt($ch, CURLOPT_PROXYPORT, $proxy_port);
}

// Visit login page.
$url = ‘https://secure.del.icio.us/login’;
$params = ”;
curl_setopt($ch, CURLOPT_POSTFIELDS, $params);
curl_setopt($ch, CURLOPT_URL, $url);
$result = curl_exec($ch);

//Grab unique token.
$piece = strstr($result, “inkey\””);
$piece = strstr($piece, “value=\””);
$token = substr($piece, 7, 32);

// Log in with token, user and pass.
$url = ‘https://secure.del.icio.us/login’;
$params = ‘inkey=’ . $token . ‘&user_name=’ . $user . ‘&password=’ . $pass . ‘&login=log%20in’;
curl_setopt($ch, CURLOPT_POSTFIELDS, $params);
curl_setopt($ch, CURLOPT_URL, $url);
$result = curl_exec($ch);

// Submit the url.
$url = ‘http://del.icio.us/’ . $user . ‘?url=’ . $site . ‘&submit=save&jump=no’;
curl_setopt($ch, CURLOPT_HTTPGET, 1);
curl_setopt($ch, CURLOPT_URL, $url);
$result = curl_exec($ch);

// Grab the new token.
$piece = strstr($result, “key\””);
$piece = strstr($piece, “value=\””);
$token = substr($piece, 7, 32);

// Grab the unique key code.
$piece = strstr($result, $user . “?”);
$piece = substr($piece, strlen($user));
$piece = strstr($piece, $user . “?”);
$quote = strpos($piece, “\””);
$len = strlen($user);
$code = substr($piece, $len + 1, $quote – $len – 1);

// Submit the url, description, notes, and tags along with the new token and key code.
$url = ‘http://del.icio.us/’ . $user . ‘?’ . $code;
$params = ‘url=’ . $site . ‘&oldurl=’ . $site . ‘&description=’ . $desc . ‘&notes=’ . $note . ‘&tags=’ . $tags . ‘&jump=no&key=’ . $token;
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $params);
curl_setopt($ch, CURL_OPT_URL, $url);
$result = curl_exec($ch);

curl_close($ch);
}
?>

LINKS PATROCINADOS
Veja uma seleção dos 10 melhores artigos que temos sobre este assunto:
Pesquisa personalizada

Deixe seus comentários