Difference between revisions of "User:Crooked Shim"

From Second Life Wiki
Jump to navigation Jump to search
Line 50: Line 50:
$url = sprintf('http://world.secondlife.com/resident/%s', urlencode($user_key));
$url = sprintf('http://world.secondlife.com/resident/%s', urlencode($user_key));
$ch = curl_init();
$ch = curl_init();
curl_setopt_array($ch, array(CURLOPT_URL=>$url, CURLOPT_RETURNTRANSFER=>true, CURLOPT_CONNECTTIMEOUT=>5, CURLOPT_USERAGENT=>"Madgeek_K2DOB"));
curl_setopt_array($ch, array(CURLOPT_URL=>$url, CURLOPT_RETURNTRANSFER=>true, CURLOPT_CONNECTTIMEOUT=>5, CURLOPT_USERAGENT=>"Key2DOB"));
$output = curl_exec($ch);
$output = curl_exec($ch);
curl_close($ch);
curl_close($ch);

Revision as of 19:48, 6 May 2010

Useful PHP Functions

These may break at any time, depends on if LL changes SL search too much.

Name2Key

function get_key($user_name)
{
	$url = sprintf('http://search.secondlife.com/web/search/?q=%s', urlencode($user_name));
	$ch = curl_init();
	curl_setopt_array($ch, array(CURLOPT_URL=>$url, CURLOPT_RETURNTRANSFER=>true, CURLOPT_CONNECTTIMEOUT=>5, CURLOPT_USERAGENT=>"Name2Key"));
	$output = curl_exec($ch);
	curl_close($ch);
	$user_name = strtoupper($user_name);
	preg_match_all('%<a href="http://world\.secondlife\.com/resident/([0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12})">(?:<b>)?(.+?)(?:</b>)?</a>%', $output, $matches, PREG_SET_ORDER);
	foreach ($matches as $val)
	{
		if (strtoupper($val[2]) == $user_name)
		{
			return $val[1];
		}
	}
	return 'not_found';
}

Key2Name

function get_name($user_key)
{
	$url = sprintf('http://world.secondlife.com/resident/%s', urlencode($user_key));
	$ch = curl_init();
	curl_setopt_array($ch, array(CURLOPT_URL=>$url, CURLOPT_RETURNTRANSFER=>true, CURLOPT_CONNECTTIMEOUT=>5));
	$output = curl_exec($ch);
	curl_close($ch);
	preg_match('%<title>(.+?)</title>%', $output, $matches);
	if (!empty($matches[1])) return $matches[1];
	else return 'not_found';
}

Key2Birthday

function get_birthday($user_key)
{
	$url = sprintf('http://world.secondlife.com/resident/%s', urlencode($user_key));
	$ch = curl_init();
	curl_setopt_array($ch, array(CURLOPT_URL=>$url, CURLOPT_RETURNTRANSFER=>true, CURLOPT_CONNECTTIMEOUT=>5, CURLOPT_USERAGENT=>"Key2DOB"));
	$output = curl_exec($ch);
	curl_close($ch);
	
	if (strpos($output, 'AccessDenied') !== false) return 'not_found';
	
	if (preg_match('%<span class="syscat">Resident Since:</span>\s<!--googleon: index-->\s(\d+?)-(\d+?)-(\d+?)\s<!--googleoff: index-->%', $output, $matches)) return array_slice($matches, 1);
	else return 'not_found';
}