Example #1
0
 /**
  * @param Net_HTTP_Request $r
  *
  * @return boolean
  */
 public function is_valid(Net_HTTP_Request $r)
 {
     $this->error = false;
     $response = $this->agent->send(Net_HTTP::Request(Service_Recaptcha::URL . '/verify')->method(Net_HTTP::POST)->parameters(array('privatekey' => $this->privkey, 'remoteip' => $r->meta['REMOTE_ADDR'], 'challenge' => $r['recaptcha_challenge_field'], 'response' => $r['recaptcha_response_field'])));
     if ($response->status->is_success) {
         $lines = explode("\n", $response->body);
         if (trim($lines[0]) == 'true') {
             return true;
         } else {
             $this->error = $lines[1];
             return false;
         }
     } else {
         $this->error = 'Unknown error';
         return false;
     }
 }
Example #2
0
 /**
  * @abstract
  */
 public function search()
 {
     $content = $this->client->agent->send(Net_HTTP::Request($this->url))->body;
     foreach (array(array('server' => 'openid2.provider', 'delegate' => 'openid2.local_id', 'version' => 2), array('server' => 'openid.server', 'delegate' => 'openid.delegate', 'version' => 1)) as $v) {
         $server = OpenId::parse_html($content, 'link', 'rel', $v['server'], 'href');
         $delegate = OpenId::parse_html($content, 'link', 'rel', $v['delegate'], 'href');
         if ($server) {
             $this->client->server = $server;
             if ($delegate) {
                 $this->client->identity = $delegate;
             }
             $this->client->version = Core::make('OpenId.Version' . $v['version']);
             return true;
         }
     }
     return false;
 }
Example #3
0
 protected function get_preview_src_from_youtube()
 {
     return Net_HTTP::Agent()->send(Net_HTTP::Request($this->get_youtube_preview_url()))->body;
 }
Example #4
0
File: WS.php Project: techart/tao
 /**
  * @return Net_HTTP_Request
  */
 public function make_request()
 {
     Core_Arrays::deep_merge_update_inplace($_POST, array_filter($this->current_uploads()));
     return Net_HTTP::Request((isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on' ? 'https://' : 'http://') . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'], array('REMOTE_ADDR' => $_SERVER['REMOTE_ADDR']))->method(isset($_POST['_method']) && $_POST['_method'] ? $_POST['_method'] : $_SERVER['REQUEST_METHOD'])->headers($this->headers());
 }
Example #5
0
File: VK.php Project: techart/tao
 /**
  * Публикация с изображением на стене пользователя
  *
  * @param  string $file  путь к изображению
  * @param  array  $parms массив параметров
  *
  * @return Net_HTTP_Response        ответ от сервера API vk.com
  */
 public function wall_post_img($file, $parms = array())
 {
     $data = json_decode($this->call('photos.getWallUploadServer')->body, true);
     $upload_url = $data['response']['upload_url'];
     $upload = Net_HTTP::Request($upload_url)->method('POST');
     $upload->body(array('photo' => '@' . $file));
     $photo = json_decode(Net_HTTP::Agent()->send($upload)->body);
     $d = json_decode($photo->photo);
     $attach = json_decode($this->call('photos.saveWallPhoto', 'GET', array('server' => $photo->server, 'photo' => $photo->photo, 'hash' => $photo->hash))->body, true);
     //can be uid gid
     $img_id = $attach['response'][0]['id'];
     $parms['attachments'] = $img_id;
     $res = $this->call('wall.post', 'POST', $parms);
     return $res;
 }
Example #6
0
 /**
  * @param string $url_name
  * @param array  $parameters
  * @param string $method
  *
  * @return array
  */
 protected function get_token($url_name, array $parameters = array(), $method = 'POST')
 {
     $this->send(Net_HTTP::Request($this->options[$url_name])->method($method), $parameters, $method == 'POST');
     $json = json_decode($this->last_response->body, true);
     return !empty($json) ? $json : ($this->token = Service_OAuth::parse_parameters($this->last_response->body));
 }
Example #7
0
File: RPC.php Project: techart/tao
 /**
  * @param array                        $requests
  * @param Service_OpenSocial_Container $container
  *
  * @return Net_HTTP_Request
  */
 protected function make_http_request(array $requests, Service_OpenSocial_Container $container)
 {
     $r = Net_HTTP::Request()->uri($container->rpc_endpoint)->method(Net_HTTP::POST)->content_type($this->format->content_type)->query_parameters(array('format' => $this->format->name))->body($this->format->encode($this->make_http_request_body($requests)));
     if ($container->use_method_override) {
         $r->header('X-HTTP-Method-Override', 'POST');
     }
     return $this->auth->authorize_request($r, $container);
 }
Example #8
0
File: Feed.php Project: techart/tao
 /**
  * Загружает документ ленты с указанного адреса и выполняет разбор
  *
  * @param string                  $url
  * @param Net_HTTP_AgentInterface $agent
  *
  * @return XML_Feed_Feed
  */
 public function fetch($url, Net_HTTP_AgentInterface $agent = null)
 {
     if (!isset($agent)) {
         $agent = Net_HTTP::Agent();
     }
     $r = $agent->send(Net_HTTP::Request($url));
     if ($r->status->is_success) {
         return $this->parse($r->body, $url);
     }
     throw new XML_Feed_BadURLException($url);
 }
Example #9
0
 protected function fetch_users()
 {
     $users = array();
     try {
         $agent = Net_HTTP::Agent();
         $res = $agent->send(Net_HTTP::Request($this->url));
         $users = json_decode($res->body);
     } catch (Exception $e) {
     }
     return $users;
 }
Example #10
0
 /**
  * @param string $url
  * @param string $method
  * @param array  $parameters
  *
  * @return array
  */
 public function call($url, $method = 'GET', $parameters = array(), $decode = true)
 {
     switch (true) {
         case $parameters instanceof Service_Twitter_Entity:
             $parameters = $parameters->as_array();
             break;
         default:
             $parameters = (array) $parameters;
             break;
     }
     try {
         $r = $this->client->send(Net_HTTP::Request(self::PREFIX . $url . '.json')->parameters($parameters)->method($method));
         if ($decode) {
             return new Service_Twitter_Entity((array) json_decode($r->body, true));
         } else {
             return $r;
         }
     } catch (SoapFault $e) {
         throw new Service_Twitter_Exception($e->getMessage());
     }
 }
Example #11
0
File: Auth.php Project: techart/tao
 /**
  * @param string           $email
  * @param string           $password
  * @param string           $service
  * @param string           $source
  * @param HOSTED_OR_GOOGLE $account_type
  *
  * @return boolean
  */
 public function login($email = null, $password = null)
 {
     foreach (array('email' => $email, 'password' => $password) as $k => $v) {
         if ($v) {
             $this->{$k}($v);
         }
     }
     $request = Net_HTTP::Request(Service_Google_Auth::CLIENTLOGIN_URI)->method(Net_HTTP::POST)->parameters($this->parameters);
     $response = $this->agent->send($request);
     if ($response->status->code !== 200) {
         $this->error = $this->get_value($response, 'Error');
     } else {
         $this->token = $this->get_value($response, 'Auth');
     }
     return $this;
 }
Example #12
0
File: HTTP.php Project: techart/tao
 /**
  * @param Net_HTTP_Request $request
  *
  * @return Net_HTTP_Response
  */
 public function send($request)
 {
     if (is_string($request)) {
         $url = $request;
         $request = Net_HTTP::Request($request);
     } else {
         $url = $request->url;
     }
     if (preg_match('{[а-яА-Я]+}u', $request->host) && function_exists('idn_to_ascii')) {
         $request->host = idn_to_ascii($request->host);
         $url = $request->url;
     }
     if ($this->act_as_browser) {
         $this->additional_headers($request);
     }
     $id = $this->make_curl($url);
     $headers = $request->headers->as_array(true);
     $headers[] = 'Expect:';
     // by default curl expect 100-continue
     $options = $this->to_file ? array(CURLOPT_CUSTOMREQUEST => strtoupper($request->method_name)) : array(CURLOPT_RETURNTRANSFER => 1, CURLOPT_CUSTOMREQUEST => strtoupper($request->method_name), CURLOPT_HEADER => 1, CURLOPT_NOBODY => !$this->with_body);
     switch ($request->method_code) {
         case Net_HTTP::GET:
         case Net_HTTP::HEAD:
             break;
         case Net_HTTP::POST:
         case Net_HTTP::PUT:
         case Net_HTTP::DELETE:
             $body = isset($request->body) ? is_array($request->body) ? $request->body : (string) $request->body : $request->post_data;
             if (is_string($body)) {
                 $headers[] = 'Content-Length: ' . strlen($body);
             }
             $options[CURLOPT_POSTFIELDS] = $body;
             break;
     }
     if ($headers) {
         $options[CURLOPT_HTTPHEADER] = $headers;
     }
     if ($this->inspect) {
         $this->inspect($id, $options);
     }
     $result = $this->execute($id, $options);
     $header_size = curl_getinfo($id, CURLINFO_HEADER_SIZE);
     $this->info = curl_getinfo($id);
     $this->error = curl_error($id);
     $this->errno = curl_errno($id);
     $effective_url = trim(curl_getinfo($id, CURLINFO_EFFECTIVE_URL));
     // memory duplicate
     // $this->last_result = &$result;
     curl_close($id);
     if ($this->to_file) {
         $this->to_file->close();
         return Net_HTTP::Response()->status($this->info['http_code']);
     }
     if ($result !== false) {
         $header = substr($result, 0, $header_size);
         $body = substr($result, $header_size);
         unset($result);
         //FIXME:
         $header = preg_replace('{[^\\r\\n]{0,5}Connection established[^\\r\\n]{0,5}\\r\\n\\r\\n}i', '', $header, 1);
         $response = Net_HTTP_Response::from_string($body, $header);
         unset($body);
         unset($header);
         $response->url = $url;
         if ($this->auto_redirect && $response->status->is_redirect) {
             return $this->redirect($response, $request, $effective_url);
         }
     } else {
         if (!empty($this->error)) {
             $response = Net_HTTP::Response();
             $response->status(0, $this->error);
         } else {
             return null;
         }
     }
     return $response;
 }
Example #13
0
 protected function load_user_data($env, $c)
 {
     $request = $env->request;
     if (isset($c['api_me_url'])) {
         $res = $c['client']->send(Net_HTTP::Request($c['api_me_url']));
         $data = json_decode($res->body);
         $data = isset($data->response) ? $data->response : $data;
         if (empty($data->id) && !empty($data->uid)) {
             $data->id = $data->uid;
         }
         if (empty($data->id) && !empty($data->user_id)) {
             $data->id = $data->user_id;
         }
         $env->oauth->{$c}['name']->user = $data;
     } else {
         $id = isset($request['user_id']) ? $request['user_id'] : $c['client']->token['user_id'];
         $name = isset($request['screen_name']) ? $request['screen_name'] : $c['client']->token['screen_name'];
         $env->oauth->{$c}['name']->user = (object) array('id' => $id, 'name' => $name);
     }
     $c['client']->flush_store();
     return $this;
 }
Example #14
0
 /**
  * @param string $property
  *
  * @return mixed
  */
 public function __get($property)
 {
     switch ($property) {
         case 'type':
         case 'data':
         case 'opts':
         case 'range':
         case 'encoder':
             return $this->{$property};
         case 'request':
             return Net_HTTP::Request(Service_Google_Chart::SERVER_URL)->parameters($this->as_array());
         default:
             throw new Core_MissingPropertyException($property);
     }
 }
Example #15
0
 public static function access($realm, $extra_auth_callback = null)
 {
     if (!$realm) {
         return array();
     }
     if (isset(self::$realms[$realm]) && self::$realms[$realm]) {
         return self::$realms[$realm];
     }
     $data = false;
     $cfg_name = "{$realm}_realm";
     $cfg = WS::env()->config;
     if (isset($cfg->{$cfg_name})) {
         $data = (array) $cfg->{$cfg_name};
     } elseif (isset(CMS::$restricted_realms[$realm])) {
         $data = CMS::$restricted_realms[$realm];
     } else {
         return self::$realms[$realm] = false;
     }
     if (!$data) {
         return self::$realms[$realm] = false;
     }
     if ($realm == CMS::$admin_realm) {
         CMS::$in_admin = true;
     }
     if (isset($data['page_404'])) {
         CMS::$page_404 = $data['page_404'];
     }
     if (isset($data['navigation_var'])) {
         Core::load(CMS::$nav_module);
         Core_Types::reflection_for(CMS::$nav_module)->setStaticPropertyValue('var', $data['navigation_var']);
     }
     $user = false;
     if (isset($data['auth_type']) && $data['auth_type'] == 'basic' || !isset($data['auth_type'])) {
         $user = WS::env()->admin_auth->user;
     }
     if ($user) {
         $client = false;
         $access = false;
         $mp = false;
         self::passwords($data, $user, $client, $access, $mp);
         Core::load('Net.HTTP.Session');
         $session = Net_HTTP_Session::Store();
         if (!$access && isset($session['auth_url_access']) && $session['auth_url_access']) {
             $access = true;
             $mp = $session['auth_url_parms'];
         }
         if (!$access && isset($data['auth_url'])) {
             Core::load('Net.Agents.HTTP');
             $url = $data['auth_url'];
             $agent = Net_HTTP::Agent();
             $res = $agent->with_credentials($user->login, $user->password)->send(Net_HTTP::Request($url));
             if ($res->status->code == '200') {
                 $r = trim($res->body);
                 if ($r == 'ok' || $r == 'ok:') {
                     $access = true;
                 } else {
                     if ($m = Core_Regexps::match_with_results('{^ok:(.+)$}', $r)) {
                         $access = true;
                         $mp = trim($m[1]);
                     }
                 }
             }
             if ($access) {
                 $session['auth_url_access'] = true;
                 $session['auth_url_parms'] = $mp;
             }
         }
         if (!$access) {
             $args = array($user->login, $user->password, $realm);
             if (Core_Types::is_callable($extra_auth_callback)) {
                 $extra_auth = Core::invoke($extra_auth_callback, $args);
             } else {
                 $extra_auth = self::extra_auth($args[0], $args[1], $args[2]);
             }
             if ($extra_auth || Core_Types::is_iterable($extra_auth)) {
                 $mp = $extra_auth;
                 $access = true;
             } else {
                 return self::$realms[$realm] = false;
             }
         }
         $auth_parms = self::auth_parms($mp, $client);
         $user->parms = $auth_parms;
         if ($access) {
             return self::$realms[$realm] = array('data' => $data, 'auth_parms' => $auth_parms);
         }
     } else {
         return self::$realms[$realm] = false;
     }
     return self::$realms[$realm] = false;
 }
Example #16
0
 protected function connect()
 {
     $o = $this->options;
     $auth_headers = array('Authorization' => "OAuth oauth_token=\"{$o['token']}\", oauth_client_id=\"{$o['application_id']}\", oauth_login=\"{$o['login']}\"");
     $this->base_request = Net_HTTP::Request()->headers($auth_headers);
 }