예제 #1
0
파일: AjaxUpload.php 프로젝트: techart/tao
 public function action($name, $data, $action, $item = false)
 {
     $c = CMS::$current_controller;
     $item_id = $item ? $item->id() : 0;
     if (isset($_GET['filename'])) {
         $filename = $_GET['filename'];
         $filename = str_replace('..', '', $filename);
         $path = CMS::temp_dir() . '/' . $filename;
     }
     if ($action == 'temp') {
         if (!IO_FS::exists($path)) {
             return false;
         }
         Core::load('Net.HTTP');
         return Net_HTTP::Download($path, false);
     }
     if ($action == 'delete') {
         if (IO_FS::exists($path)) {
             IO_FS::rm($path);
         }
         return 'ok';
     }
     if ($action == 'info') {
         if ($filename == 'none') {
             return 'ok';
         }
         return $this->render($name, $data, 'info-ajax.phtml', array('file_path' => $path, 'file_url' => $c->field_action_url($name, 'temp', $item, array('filename' => str_replace('/', '', $filename))), 'name' => $name));
     }
     if ($action == 'upload') {
         return $this->action_upload($name, $data, $action, $item);
     }
     return false;
 }
예제 #2
0
파일: OpenSocial.php 프로젝트: techart/tao
 /**
  */
 public function authenticate()
 {
     if ($user = $this->env->auth->module->authenticate_remote_user($this->env)) {
         $this->save_user($user);
         return Net_HTTP::redirect_to(Core::if_not_set($this->env->request, 'url', '/'));
     }
     return $this->index();
 }
예제 #3
0
파일: Forms.php 프로젝트: techart/tao
 /**
  * Формирует HTML-форму с помощью объекта формы $form
  * 
  * @param Templates_HTML_Template $t
  * @param Forms_Form $form
  * @param array $attributes
  */
 public function begin_form(Templates_HTML_Template $t, $form, array $attrs = array())
 {
     $this->form = $form;
     $method = Net_HTTP::method_name_for($form->options['method']);
     $result = $t->tag('form', array_merge(array('action' => $form->action, 'method' => $method == 'post' || $method == 'get' ? $method : 'post', 'id' => "{$form->name}_form", 'enctype' => $form->options['enctype']), $attrs), false) . $this->begin_fieldset($t, Core_Arrays::pick($attrs, 'fieldset', array()));
     if ($method == 'put' || $method == 'delete') {
         $result .= $t->tag('input', array('type' => 'hidden', 'name' => '_method', 'value' => $method));
     }
     return $result;
 }
예제 #4
0
파일: Upload.php 프로젝트: techart/tao
 public function action($name, $data, $action, $item)
 {
     $file = $this->uploaded_path($item[$name]);
     if ($action == 'delete') {
         @IO_FS::rm($file);
         $item[$name] = '';
         CMS::$current_controller->field_callback_update_item($item);
         return 'ok';
     }
     if ($action == 'download') {
         $path = $this->uploaded_path($file);
         return Net_HTTP::Download($path);
     }
     return false;
 }
예제 #5
0
파일: Recaptcha.php 프로젝트: techart/tao
 /**
  * @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;
     }
 }
예제 #6
0
 public function action($name, $data, $action, $item = false, $fields = array())
 {
     $args = func_get_args();
     $res = Net_HTTP::Response();
     $res->content_type('application/json');
     $query = WS::env()->request['query'];
     $ents = CMS::items_for_select(Core::invoke($data['search'], array($query)));
     $values = array();
     $empty = $this->get_empty($data);
     if ($empty && empty($query)) {
         $values[] = $empty;
     }
     foreach ($ents as $k => $e) {
         $values[] = array('id' => (int) $k, 'title' => (string) $e);
     }
     $res->body(json_encode(array('data' => $values)));
     return $res;
 }
예제 #7
0
파일: PDF.php 프로젝트: techart/tao
 /**
  * Выполняет обработку запроса
  *
  * @param WS_Environment $env
  *
  * @return mixed
  */
 public function run(WS_Environment $env)
 {
     $m = false;
     foreach ($this->patterns as $p => $r) {
         $pattern_match = preg_match($p, $env->request->urn);
         if ($pattern_match) {
             $m = true;
             if ($this->clear_url) {
                 $env->request->uri(preg_replace($p, $r, $env->request->urn));
             }
         }
     }
     $env->pdf = (object) array('active' => $m);
     $r = $this->application->run($env);
     if ($env->pdf->active) {
         $response = Net_HTTP::merge_response($r, $env->{$response});
         if (!$response->status->is_success) {
             return $r;
         }
         if (isset($env->config) && isset($env->config->pdf)) {
             foreach ($env->config->pdf as $option => $v) {
                 if (isset($this->{$option})) {
                     $this->{$option} = $v;
                 }
             }
         }
         if (!class_exists('mPDF')) {
             include $this->mpdf_dir;
         }
         $mpdf = new mPDF();
         foreach ($this->options as $name => $v) {
             $mpdf->{$name} = $v;
         }
         if (is_callable($env->pdf->callback)) {
             $env->response = $response;
             return call_user_func($env->pdf->callback, $mpdf, $env);
         } else {
             $mpdf->WriteHTML((string) $response->body);
             $mpdf->Output(!empty($env->pdf->title) ? $env->pdf->title : $this->title, 'D');
         }
     } else {
         return $r;
     }
 }
예제 #8
0
파일: Basic.php 프로젝트: techart/tao
 /**
  * @param WS_Environment $env
  *
  * @return mixed
  */
 public function run(WS_Environment $env)
 {
     $name = $this->options['env_name'];
     if (!isset($env->{$name})) {
         $env->{$name} = Core::object(array('user' => null, 'module' => $this->auth_module));
     }
     if (isset($env->request->headers['Authorization'])) {
         list($login, $password) = $this->parse_credentials($env->request->headers['Authorization']);
         $env->{$name}->user = $this->auth_module->authenticate($login, $password);
     }
     try {
         $response = $this->application->run($env);
     } catch (WS_Auth_UnauthenticatedException $e) {
         $response = Net_HTTP::Response(Net_HTTP::UNAUTHORIZED)->header('WWW-Authenticate', 'Basic realm="' . $e->realm . '"');
     } catch (WS_Auth_ForbiddenException $e) {
         $response = Net_HTTP::Response(Net_HTTP::FORBIDDEN);
     }
     return $response;
 }
예제 #9
0
파일: Status.php 프로젝트: techart/tao
 /**
  * @param WS_Environment $env
  *
  * @return Net_HTTP_Response
  */
 public function run(WS_Environment $env)
 {
     //if ($this->disabled) return $this->application->run($env);
     $error = null;
     try {
         $body = $this->application->run($env);
         $response = Net_HTTP::merge_response($body, $env->response);
     } catch (Exception $e) {
         $error = $e;
         if ($this->disabled) {
             throw $e;
         }
         $response = Net_HTTP::Response(Net_HTTP::INTERNAL_SERVER_ERROR);
     }
     if (!$response->body && ($template = $this->find_template_name_for($response->status))) {
         if (isset($env->not_found->static_file)) {
             $response->body(IO_FS::File($env->not_found->static_file));
         } else {
             $layout = isset($env->not_found->layout) ? $env->not_found->layout : 'work';
             $view = Templates::HTML($template);
             if ($layout) {
                 $view->within_layout($layout);
             }
             $view->root->with(array('env' => $env, 'response' => $response, 'error' => $error));
             if ($view->exists()) {
                 $response->body($view);
             } else {
                 if (IO_FS::exists($static_name = $template . '.html')) {
                     $response->body(IO_FS::File($static_name));
                 }
             }
         }
     }
     Events::call('ws.status', $response);
     return $response;
 }
예제 #10
0
파일: DSL.php 프로젝트: techart/tao
 /**
  * @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());
     }
 }
예제 #11
0
파일: RPC.php 프로젝트: 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);
 }
예제 #12
0
파일: Feed.php 프로젝트: 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);
 }
예제 #13
0
파일: Fields.php 프로젝트: techart/tao
 public function action($name, $data, $action, $item = false, $fields = array())
 {
     if (!$this->access($name, $data, 'action', $action, $item, $fields)) {
         return Net_HTTP::forbidden();
     }
     if (method_exists($this, $m = 'action_' . $action)) {
         return $this->{$m}($name, $data, $action, $item, $fields);
     }
     return false;
 }
예제 #14
0
파일: OpenId.php 프로젝트: techart/tao
 /**
  * @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;
 }
예제 #15
0
파일: VK.php 프로젝트: 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;
 }
예제 #16
0
파일: Gallery.php 프로젝트: techart/tao
 public function action_left($name, $data, $action, $item = false, $fields = array())
 {
     $filename = $this->dir_path($item, false, $name, $data) . '/' . $this->request('filename');
     $file = IO_FS::File($filename);
     if (!$file->exists()) {
         Net_HTTP::not_found();
     }
     Core::load('CMS.Images');
     $method = 'turn_' . $action;
     CMS_Images::Image($file->path)->{$method}()->save($file->path);
     $file->set_permission();
     Events::call('admin.change');
     return 'ok';
 }
예제 #17
0
파일: WS.php 프로젝트: techart/tao
 /**
  * Запускает приложение
  *
  * @param WS_ServiceInterface $app
  *
  * @return WS_Runner
  */
 public function run(WS_ServiceInterface $app)
 {
     $environment = WS::env();
     $environment->request = $this->adapter->make_request();
     $rc = Events::call('ws.run');
     if (!is_null($rc)) {
         return $rc;
     }
     $environment->response = Net_HTTP::Response();
     $body = $app->run($environment);
     $response = Net_HTTP::merge_response($body, $environment->response);
     return $this->adapter->process_response($response);
 }
예제 #18
0
파일: Twitter.php 프로젝트: techart/tao
 /**
  * @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());
     }
 }
예제 #19
0
파일: Session.php 프로젝트: techart/tao
 /**
  * @return Net_HTTP_Response
  */
 public function delete()
 {
     $this->env->auth->user = null;
     unset($this->env->request->session['user_id']);
     return Net_HTTP::redirect_to(Core::if_not_set($this->env->request, 'url', '/'));
 }
예제 #20
0
파일: Auth.php 프로젝트: 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;
 }
예제 #21
0
파일: ExtJSTable.php 프로젝트: techart/tao
 protected function tree_json()
 {
     $res = Net_HTTP::Response()->content_type('application/json');
     $root = WS::env()->request['node'];
     // $this->page = (int) isset($this->request['page']) ? $this->request['page'] : 1;
     $data = $this->tree_data($root, json_decode(WS::env()->request['sort'], true));
     $result = array('total' => $this->get_tree_count($root), 'children' => $data, 'success' => true);
     return $res->body(json_encode($result));
 }
예제 #22
0
파일: SlickTable.php 프로젝트: techart/tao
 protected function tree_update()
 {
     $data = json_decode($this->env->request->content, true);
     if (isset($data['id'])) {
         $data = array($data);
     }
     try {
         foreach ($data as $row) {
             if (!empty($row['id'])) {
                 $entity = $this->load($row['id']);
                 if ($entity->id()) {
                     foreach ($row as $k => $v) {
                         $entity[$k] = $v;
                     }
                     // Log::logger()->debug('item', $entity->attrs);
                     $entity->update();
                 }
             }
             $this->save_reorder($parent_id);
         }
         return Net_HTTP::Response()->content_type('application/json')->body(json_encode(array('success' => true, 'message' => 'OK')));
     } catch (Exception $e) {
         return Net_HTTP::Response()->content_type('application/json')->body(json_encode(array('success' => false, 'message' => $e->getMessage())));
     }
 }
예제 #23
0
파일: OAuth.php 프로젝트: techart/tao
 /**
  * @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));
 }
예제 #24
0
 public static function download($file, $cache = false)
 {
     return Net_HTTP::Download($file, $cache);
 }
예제 #25
0
파일: HTTP.php 프로젝트: techart/tao
 /**
  * Устанавливает статус отклика
  *
  * @param Net_HTTP_Status $status
  *
  * @return Net_HTTP_Response
  */
 public function status($code, $message = null)
 {
     $this->status = $code instanceof Net_HTTP_Status ? $code : Net_HTTP::Status($code, $message);
     return $this;
 }
예제 #26
0
파일: HTTP.php 프로젝트: 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;
 }
예제 #27
0
파일: Youtube.php 프로젝트: techart/tao
 protected function get_preview_src_from_youtube()
 {
     return Net_HTTP::Agent()->send(Net_HTTP::Request($this->get_youtube_preview_url()))->body;
 }
예제 #28
0
파일: Stockroom.php 프로젝트: techart/tao
 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}";
     }
 }
예제 #29
0
파일: Attaches.php 프로젝트: techart/tao
 public function action($name, $data, $action, $item = false)
 {
     $code = $this->request('code');
     $dir = $this->dir_path($item, $code, $name, $data);
     if ($action == 'delete') {
         return $this->action_delete($name, $data, $action, $item);
     }
     if ($action == 'download') {
         $file = $this->request('file');
         $path = "{$dir}/{$file}";
         if (!IO_FS::exists($path)) {
             return false;
         }
         Core::load('Net.HTTP');
         return Net_HTTP::Download($path, false);
     }
     if ($action == 'reload') {
         $t = $this->create_template($name, $data, 'files');
         return $t->with(array('type_object' => $this, 'c' => CMS::$current_controller, 'name' => $name, 'data' => $data, 'item' => $item))->render();
     }
     if ($action == 'upload') {
         return $this->action_upload($name, $data, $action, $item);
     }
     return false;
 }
예제 #30
0
파일: Apache.php 프로젝트: techart/tao
 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;
 }