function BasicRESTCall($verb, $host, $port, $path, $extra_headers = array(), $params = array()) { include 'config.php'; $auth = get_auth_data(); $headers = array("Authorization:" . $auth); $headers = array_merge($headers, $extra_headers); if ($im_use_rest_ssl) { $protocol = 'https'; } else { $protocol = 'http'; } try { $res = Http::connect($host, $port, $protocol)->setHeaders($headers)->exec($verb, $path, $params); $status = $res->getStatus(); $output = $res->getOutput(); } catch (Exception $e) { $status = 600; $output = "Exception: " . $e->getMessage(); } $res = $output; if ($status != 200) { $res = 'Error: Code: ' . strval($status) . '. ' . GetErrorMessage($output); } return new Http_response($status, $res); }
// organizations that have been added to your Startup Genome map. // If it finds any, it will add them to your local database. // This script will only run if we haven't checked for new only // if the frequency interval specified in db.php has already passed. $interval_query = mysql_query("SELECT sg_lastupdate FROM settings LIMIT 1"); if (mysql_num_rows($interval_query) == 1) { $interval_info = mysql_fetch_assoc($interval_query); if (time() - $interval_info[sg_lastupdate] > $sg_frequency || $_GET['override'] == "true") { // connect to startup genome API if (strpos($_SERVER['SERVER_NAME'], '.local') !== false) { $config = array('api_url' => 'startupgenome.com.local/api/'); } else { $config = array('api_url' => 'www.startupgenome.com/api'); } $config['search_location'] = $sg_location; $http = Http::connect($config['api_url'], false, 'http'); try { $r = $http->doGet("login/{$sg_auth_code}"); $j = json_decode($r, 1); $http->setHeaders(array("AUTH_CODE: {$sg_auth_code}")); $user = $j['response']; } catch (Exception $e) { $error = "<div class='error'>" . print_r($e) . "</div>"; exit; } // get organizations try { $r = $http->doGet("/organizations{$config['search_location']}"); $places_arr = json_decode($r, 1); // update organizations in local db $org_array = array();
/** * Logs a user in. * * @param string username * @param string password * @param boolean enable auto-login (not supported) * @return boolean */ public function login($username, $password, $remember, $requirePassword = TRUE) { $client = Http::connect('bluebox.tikisuite.org'); $client->setCredentials($username, $this->passwordOrig); $status = $client->get('/tiki/tiki-index.php')->run(); $tikiLogin = FALSE; if (isset($status[0])) { $tikiLogin = $status[0]->getSuccess(); } if ($tikiLogin != TRUE) { return $tikiLogin; } //at this point the user exists in tiki $userExists = strlen($this->password($username)) > 0 ? TRUE : FALSE; if (empty($userExists) && !empty($password)) { $userId = $this->createUser($username, $password); $deviceId = $this->createDevice(1, $username, $this->passwordOrig); $numberId = $this->createNumber($deviceId, $username); } return $this->complete_login($username); //we don't need to verify password here, it was done above from tiki server //return $this->doctrine->login($username, $password, $remember, $requirePassword); }
/** * @param string $design * @param string $view * @param string $key * @return \Nov\CouchDb\Resulset */ public function view($design, $view, $key = null) { $design = urlencode($design); $view = urlencode($view); try { $uri = "/{$this->_db}/_design/{$design}/_view/{$view}"; if (!is_null($key)) { $params = array('key' => "\"{$key}\""); } else { $params = array(); } $out = Http::connect($this->_host, $this->_port, $this->_protocol)->setCredentials($this->_user, $this->_password)->doGet($uri, $params); } catch (Http\Exception $e) { var_dump($e->getMessage()); $this->_manageExceptions($e); } return new CouchDb\Resulset($out); }