コード例 #1
0
	/**
	* @method OC_Shorty_Backend::registerUrl_tinyurl
	* @brief Registers a given local relay url at the tinyURL shortening service
	* @param string id
	* @param url relay
	* @return Registered and validated relay url
	* @access public
	* @author Chrisian Reiner
	*/
	static function registerUrl_tinyurl ( $id, $relay )
	{
		$curl = curl_init ( );
		curl_setopt ( $curl, CURLOPT_URL, sprintf('http://tinyurl.com/api-create.php?url=%s', urlencode(trim($relay))) );
		curl_setopt ( $curl, CURLOPT_RETURNTRANSFER, TRUE );
		if (  (FALSE===($reply=curl_exec($curl)))
			||( ! preg_match( '/^(.+)$/', $reply, $match )) )
		{
			throw new OC_Shorty_Exception ( "Failed to register url at backend 'tinyUrl'. \nError %s: %s",
				array(curl_errno($curl),curl_error($curl))  );
		}
		curl_close ( $curl );
		return OC_Shorty_Type::validate ( $match[1], OC_Shorty_Type::URL );
	} // OC_Shorty_Backend::registerUrl_tinyurl