/** * Examine the URL, optionally looking for a specific service. If no * service selection is done, all the services that the URL publishes * will be returned. * * @param string $url The URL to explore * @param string $service The service to look for * @return array An array of the exposed services at the URL */ function discover($url, $services = null) { // Perform the query $ret = new HttpRequest($url); // Grab the data $status = $ret->status(); $content = $ret->responseText(); $headers = $ret->headers(); $results = array(); // Enumerate the explorers $explorers = config::get(Discovery::KEY_EXPLORERS, array()); foreach ($explorers as $explorer) { // Discover the service and merge the results $instance = new $explorer($url, $headers, $content); $instance->discover(); if ($services) { foreach ($instance->getAllServices() as $stype => $sdata) { // Return the service if it matches the type. if ($stype == $service) { return $sdata; } } } else { // Merge the resultset otherwise $results = array_merge($results, $instance->getAllServices()); } } // Return null if we were looking for a specific service if ($services) { return null; } return $results; }
function translate($string) { switch ($this->apiversion) { case 1: $langs = join('|', array($this->fromlang, $this->tolang)); $translation = array(); $url = 'http://ajax.googleapis.com/ajax/services/language/translate'; $r = new HttpRequest($url, array('parameters' => array('v' => '1.0', 'q' => $string, 'langpair' => $langs))); $rd = json_decode($r->responseText(), true); $rstr = $rd['responseData']['translatedText']; break; case 2: default: throw new BaseException("GoogleTranslate API Version 2 not implemented"); $rstr = $string; break; } return $rstr; }
/** * Call a method on the server. The result is returned decoded as * native PHP data. * * @param string $method The method to call * @param any $data The data * @return any The result data */ function call($method, $args = null) { logger::debug("Sending XmlrpcRequest to %s ...", $method); $req = xmlrpc_encode_request($method, $args); logger::debug('%s', $req); $opts = array('method' => 'post', 'parameters' => $req, 'content-type' => 'text/xml'); if ($this->username) { $opts['username'] = $this->username; $opts['password'] = $this->password; } $opts = array_merge($opts, $this->httpopts); $ret = new HttpRequest($this->url, $opts); logger::debug('Response: %s', $ret->responseText()); $mtd = null; $dec = xmlrpc_decode_request($ret->responseText(), $mtd); /* if ($dec && arr::hasKey($dec,'faultCode')) { printf("Fault\n"); } */ return $dec; /* // Encode the request $xml = xmlrpc_encode_request( $method, $args ); // Send it to the server $sparams = array('http' => array( 'method' => 'POST', 'content' => $xml, 'header' => array( 'content-type' => 'text/xml' ) )); $ctx = stream_context_create($params); $fp = @fopen($this->url, 'rb', false, $ctx); if (!$fp) { throw new Exception("Problem with $this->url, $php_errormsg"); } $response = @stream_get_contents($fp); if ($response === false) { throw new Exception("Problem reading data from $url, $php_errormsg"); } // Parse the output $ret = xmlrpc_decode_request($response,$mtd); return $ret; */ }
/** * @brief Constructor for Password Authentication * * @param string $username The username for which to validate the token * @param string $password The user's password. */ public function __construct() { $token = request::get('token')->toString(); $apikey = config::get('lepton.user.engage.apikey'); $ret = new HttpRequest('https://rpxnow.com/api/v2/auth_info', array('method' => 'post', 'parameters' => array('apiKey' => $apikey, 'token' => $token, 'format' => 'xml'))); $dom = DOMDocument::loadXml($ret->responseText()); $domx = new DOMXPath($dom); // Get the status $status = $domx->query('/rsp')->item(0)->getAttribute('stat'); if ($status == 'ok') { // Call on the successful callback method event::invoke(EngageEvents::EVENT_SUCCESSFUL_CALLBACK, array('profile' => $dom, 'profiletext' => $ret->responseText())); // Extract the values $identifier = $domx->query('/rsp/profile/identifier')->item(0)->nodeValue; $displayname = $domx->query('/rsp/profile/displayName')->item(0)->nodeValue; $provider = $domx->query('/rsp/profile/providerName')->item(0)->nodeValue; $firstname = $domx->query('/rsp/profile/name/givenName')->item(0)->nodeValue; $lastname = $domx->query('/rsp/profile/name/familyName')->item(0)->nodeValue; $preferredusername = $domx->query('/rsp/profile/preferredUsername')->item(0)->nodeValue; $email = $domx->query('/rsp/profile/email')->item(0)->nodeValue; // Sign in $db = new DatabaseConnection(); $idrs = $db->getSingleRow("SELECT * FROM userengage WHERE identifier=%s", $identifier); if ($idrs) { $cu = $idrs['userid']; $db->updateRow("UPDATE userengage SET lastseen=NOW(), lastip=%s WHERE id=%d", request::getRemoteIp(), $idrs['id']); } else { if (!user::isAuthenticated()) { if (!config::get(EngageAuthentication::KEY_ALLOW_CREATION, false)) { throw new SecurityException("User creation is disabled for EngageAuthentication"); } // Check username, add random numbers if not available $username = $preferredusername; $retrycount = 0; while (!user::checkUsername($username)) { $username = substr($preferredusername, 0, 6) . rand(1000, 9999); $retrycount = $retrycount + 1; if ($retrycount > 10) { throw new UserException("Bad username"); } } // Generate a new password $password = substr(md5(uniqid()), 0, 6); // And create the userrecord $u = new UserRecord(); $u->username = $username; $u->password = $password; $u->flags = config::get(EngageAuthentication::KEY_DEFAULT_FLAGS, EngageAuthentication::DEFAULT_FLAGS); $u->displayname = $displayname; $u->firstname = $firstname; $u->lastname = $lastname; $u->email = $email; $cu = user::create($u); session::set(self::SESSIONKEY_USER_CREATED, true); } else { $cu = user::getActiveUser(); } // Add identifier to user $db->updateRow("INSERT INTO userengage (userid,identifier,provider,lastseen,lastip) VALUES (%d,%s,%s,NOW(),%s)", $cu, $identifier, $provider, request::getRemoteIp()); } $this->userid = $cu; } else { $this->userid = null; } }