/** */ public function __construct(array $parameters = array()) { if ($parameters) { $this->parameters($parameters); } $this->agent = Net_HTTP::Agent(); }
/** * @param Net_HTTP_Request|null $request * @param mixed $agent */ public function __construct($request = null, $agent = null) { if ($request instanceof Net_HTTP_Request) { $this->request($request)->option('return_url', $request->scheme . '://' . $request->host); } $this->agent = $agent instanceof Net_HTTP_AgentInterface ? $agent : Net_HTTP::Agent(); $this->params['ax'] = new OpenId_AxParams(); $this->params['sreg'] = new OpenId_SregParams(); }
protected function get_preview_src_from_youtube() { return Net_HTTP::Agent()->send(Net_HTTP::Request($this->get_youtube_preview_url()))->body; }
/** * Публикация с изображением на стене пользователя * * @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; }
/** * @param Net_HTTP_Request $request * @param array $parameters * @param boolean $to_headers * * @return Net_HTTP_Response */ public function send(Net_HTTP_Request $request, array $parameters = array(), $to_headers = false) { $agent = Net_HTTP::Agent(); if (count($this->proxy) > 0) { $agent->using_proxy($this->proxy[0], $this->proxy[1], $this->proxy[2]); } $this->last_response = Net_HTTP::Agent()->send($this->build_request($request, array_merge($this->parameters, $parameters), $to_headers)); if ($this->last_response->status->is_server_error) { throw new Service_OAuth_Exception($this->last_response); } else { return $this->last_response; } }
/** * @return Service_OpenSocial_Protocol */ protected function make_protocol() { if ($this->protocol[0] instanceof Service_OpenSocial_Protocol) { return $this->protocol[0]; } else { Core::load($m = 'Service.OpenSocial.Protocols.' . $this->protocol[0]); return Core::make("{$m}.Protocol", $this->make_auth(), $this->make_format(), $this->agent ? $this->agent : Net_HTTP::Agent()); } }
/** * Загружает документ ленты с указанного адреса и выполняет разбор * * @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); }
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; }
protected function get_install_pack($item) { $tdir = $item->install_temp_dir(); if (IO_FS::exists($tdir)) { CMS::rmdir($tdir); } CMS::mkdirs($tdir); $zip = "{$tdir}/install.zip"; $agent = Net_HTTP::Agent(CMS_Stockroom::$curl_options)->act_as_browser(); $res = $agent->send($item['download']); if ($res->status->code == 200) { $unknown = 'Некорректный инсталляционный пакет!'; if (isset($res->headers['Content-Type'])) { if (Core_Regexps::match('{^application/zip}', $res->headers['Content-Type'])) { file_put_contents($zip, $res->body); CMS::chmod_file($zip); Core::load('IO.Arc'); IO_Arc::ZIP($zip)->extract_to($tdir); unlink($zip); return $this->hash_dir($tdir, '', $item); } else { return $unknown; } } else { return $unknown; } } else { return "Error {$res->status->code} {$res->status->message}"; } }
/** * @param string $path * * @return boolean */ public function save_as($path) { return IO_FS::File($path)->update(Net_HTTP::Agent()->send($this->request->method(Net_HTTP::POST))->body); }
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; }
/** * @param string $pubkey * @param string $privkey * @param Net_HTTP_AgentInterface $agent */ public function __construct($pubkey, $privkey, $agent = null) { $this->pubkey = $pubkey; $this->privkey = $privkey; $this->agent($agent ? $agent : Net_HTTP::Agent()); }