<?
	require_once (dirname(__FILE__).'/../OpenID/AX.php');

	function getAliases()
	{
		return array(	'fullname' => 'http://axschema.org/namePerson',
			  'email' => 'http://axschema.org/contact/email',
			  'country' => 'http://axschema.org/contact/country/home',
			 // 'nickname' => 'http://axschema.org/namePerson/friendly',
			 // так сделано пока гугл не образумится
			  'nickname' => 'http://axschema.org/namePerson/first',
			  'language' => 'http://axschema.org/pref/language',
			  'dob' => 'http://axschema.org/birthDate',
			  'gender' => 'http://axschema.org/person/gender',
			  'postcode' => 'http://axschema.org/contact/postalCode/home',
			  'timezone' => 'http://axschema.org/pref/timezone');
		
	}

	function Auth_OpenID_AXmake($required=false, $optional=false)
	{
		$aliases=getAliases();
		$ax = new Auth_OpenID_AX_FetchRequest;

		if ($required)
		{
			foreach($required as $item)
			{
				// Usage: make($type_uri, $count=1, $required=false, $alias=null)
				$ax->add(Auth_OpenID_AX_AttrInfo::make($aliases[$item] ,1 ,true , $item));
			}
			
		}

		if ($optional)
		{
			foreach($optional as $item)
			{
				$ax->add(Auth_OpenID_AX_AttrInfo::make($aliases[$item],1 ,false , $item));
			}
		}
		return $ax;
	}
	
	function Auth_OpenID_AXResponse($response)
	{
		$aliases=getAliases();
		$ax = new Auth_OpenID_AX_FetchResponse();
		$obj = $ax->fromSuccessResponse($response);
		$items=array_keys($obj->data);
		if ($items)
		{
			foreach($items as $item)
			{
				if (in_array($item, $aliases))
				{
					$data[array_search($item, $aliases)]=$obj->data[$item][0];
				}
			}
		}
		return $data;
	}