/** * Getting the public responses to display * * @return void * @param unknown $inq_uuid (optional) */ public function search($inq_uuid = null) { $query_term = $this->input->get('q'); $resp_format = $this->input->get('t'); $api_key = $this->input->get('a'); if (!$resp_format) { $resp_format = 'JSON'; } // "view" only used for errors // otherwise proxy response sets its own headers // we do not have any HTML view, so if that is detected, // it was the default. override with our local response format detection. if ($this->airoutput->view == 'html') { $this->airoutput->view = strtolower($resp_format); $this->airoutput->format = $this->router->get_content_type_for_view($this->airoutput->view); } elseif (!$this->input->get('t')) { $resp_format = strtoupper($this->airoutput->view); } $api_key_rec = null; if (!strlen($api_key)) { $this->response(array('success' => false, 'error' => 'API Key Required'), 401); return; } else { $api_key_rec = APIKey::find('APIKey', $api_key); if (!$api_key_rec || !$api_key_rec->ak_approved) { $this->response(array('success' => false, 'error' => 'Invalid API Key'), 403); return; } // ok key. log it. $ip_address = $this->input->server('REMOTE_ADDR'); $api_stat = new APIStat(); $api_stat->APIKey = $api_key_rec; $api_stat->as_ip_addr = $ip_address; $api_stat->save(); } // validity checks if ($this->method != 'GET') { header('Allow: GET', true, 405); $this->response(array('success' => false), 405); return; } if (!strlen($query_term)) { $this->response(array('success' => false, 'error' => '"q" param required'), 400); return; } if ($inq_uuid) { $query_term = "(" . $query_term . ") AND inq_uuid={$inq_uuid}"; } $airuser = new AirUser(); $tkt = $airuser->get_tkt($api_key_rec->ak_email, 0); $tktname = null; $tktval = null; foreach ($tkt as $k => $v) { $tktname = $k; $tktval = $v; } $opts = array("url" => AIR2_SEARCH_URI . '/public-responses/search', "cookie_name" => $tktname, "params" => array('t' => $resp_format), "tkt" => $tktval, "query" => $query_term, "GET" => true); $search_proxy = new Search_Proxy($opts); $response = $search_proxy->response(); $body = $response['json']; $this->airoutput->format = $response['response']['content_type']; $this->airoutput->send_headers($response['response']['http_code']); // if JSONP requested, wrap response if ($this->input->get('callback')) { echo $this->input->get('callback') . '(' . $body . ');'; } else { echo $body; } }
/** * Save form information * * @param unknown $name * @param unknown $email */ protected function save($name, $email) { $ip_address = $this->input->server('REMOTE_ADDR'); $api_key = new APIKey(); $api_key->ak_contact = $name; $api_key->ak_email = $email; $api_key->ak_key = air2_generate_uuid(32); $api_key->save(); $api_stat = new APIStat(); $api_stat->APIKey = $api_key; $api_stat->as_ip_addr = $ip_address; $api_stat->save(); }