/** * {@inheritdoc} */ public function perform_auth_login() { if (!$this->service_provider instanceof \OAuth\OAuth2\Service\Facebook) { throw new exception('AUTH_PROVIDER_OAUTH_ERROR_INVALID_SERVICE_TYPE'); } // This was a callback request, get the token $this->service_provider->requestAccessToken($this->request->variable('code', '')); // Send a request with it $result = json_decode($this->service_provider->request('/me'), true); // Return the unique identifier return $result['id']; }
/** * {@inheritdoc} */ public function perform_auth_login() { if (!$this->service_provider instanceof \OAuth\OAuth2\Service\Bitly) { throw new \src\auth\provider\oauth\service\exception('AUTH_PROVIDER_OAUTH_ERROR_INVALID_SERVICE_TYPE'); } // This was a callback request from bitly, get the token $this->service_provider->requestAccessToken($this->request->variable('code', '')); // Send a request with it $result = json_decode($this->service_provider->request('user/info'), true); // Return the unique identifier returned from bitly return $result['data']['login']; }
/** * Checks whether the chunk we are about to deal with was actually uploaded * by PHP and actually exists, if not, it generates an error * * @param string $form_name The name of the file in the form data * * @return null */ protected function integrate_uploaded_file($form_name, $chunk, $file_path) { $is_multipart = $this->is_multipart(); $upload = $this->request->file($form_name); if ($is_multipart && (!isset($upload['tmp_name']) || !is_uploaded_file($upload['tmp_name']))) { $this->emit_error(103, 'PLUPLOAD_ERR_MOVE_UPLOADED'); } $tmp_file = $this->temporary_filepath($upload['tmp_name']); if (!src_is_writable($this->temporary_directory) || !move_uploaded_file($upload['tmp_name'], $tmp_file)) { $this->emit_error(103, 'PLUPLOAD_ERR_MOVE_UPLOADED'); } $out = fopen("{$file_path}.part", $chunk == 0 ? 'wb' : 'ab'); if (!$out) { $this->emit_error(102, 'PLUPLOAD_ERR_OUTPUT'); } $in = fopen($is_multipart ? $tmp_file : 'php://input', 'rb'); if (!$in) { $this->emit_error(101, 'PLUPLOAD_ERR_INPUT'); } while ($buf = fread($in, 4096)) { fwrite($out, $buf); } fclose($in); fclose($out); if ($is_multipart) { unlink($tmp_file); } }
/** * Constructor * * @param \src\request\request_interface $src_request */ public function __construct(\src\request\request_interface $src_request) { $get_parameters = $src_request->get_super_global(\src\request\request_interface::GET); $post_parameters = $src_request->get_super_global(\src\request\request_interface::POST); $server_parameters = $src_request->get_super_global(\src\request\request_interface::SERVER); $files_parameters = $src_request->get_super_global(\src\request\request_interface::FILES); $cookie_parameters = $src_request->get_super_global(\src\request\request_interface::COOKIE); parent::__construct($get_parameters, $post_parameters, array(), $cookie_parameters, $files_parameters, $server_parameters); }
/** * Get list of items from posted data * * @param string $name Variable name * @param string|int $default Default value for array * @param bool $error If true, error will be triggered if list is empty * @return array Items */ protected function request_vars($name, $default, $error = false) { $item = $this->request->variable($name, $default); $items = $this->request->variable($name . 's', array($default)); if (count($items) == 1 && $items[0] == $default) { $items = array(); } if ($item != $default && !count($items)) { $items[] = $item; } if ($error && !count($items)) { trigger_error($this->user->lang['NO_MATCHING_STYLES_FOUND'] . adm_back_link($this->u_action), E_USER_WARNING); } return $items; }
/** * Performs the account linking for auth_link * * @param array $link_data The same variable given to {@see \src\auth\provider\provider_interface::link_account} * @param string $service_name The name of the service being used in * linking. * @return string|null Returns a language constant (string) if an error is * encountered, or null on success. */ protected function link_account_auth_link(array $link_data, $service_name) { $storage = new \src\auth\provider\oauth\token_storage($this->db, $this->user, $this->auth_provider_oauth_token_storage_table); $query = 'i=ucp_auth_link&mode=auth_link&link=1&oauth_service=' . strtolower($link_data['oauth_service']); $service_credentials = $this->service_providers[$service_name]->get_service_credentials(); $scopes = $this->service_providers[$service_name]->get_auth_scope(); $service = $this->get_service(strtolower($link_data['oauth_service']), $storage, $service_credentials, $query, $scopes); if ($this->request->is_set('code', \src\request\request_interface::GET)) { $this->service_providers[$service_name]->set_external_service_provider($service); $unique_id = $this->service_providers[$service_name]->perform_auth_login(); // Insert into table, they will be able to log in after this $data = array('user_id' => $this->user->data['user_id'], 'provider' => strtolower($link_data['oauth_service']), 'oauth_provider_id' => $unique_id); $this->link_account_perform_link($data); } else { $url = $service->getAuthorizationUri(); header('Location: ' . $url); } }
/** * Check and display the SQL report if requested. * * @param \src\request\request_interface $request Request object * @param \src\auth\auth $auth Auth object * @param \src\db\driver\driver_interface $db Database connection */ function src_check_and_display_sql_report(\src\request\request_interface $request, \src\auth\auth $auth, \src\db\driver\driver_interface $db) { if ($request->variable('explain', false) && $auth->acl_get('a_') && defined('DEBUG')) { $db->sql_report('display'); } }
/** * Bind the values of the request to the form * * @param \src\request\request_interface $request * @return null */ public function bind(\src\request\request_interface $request) { $this->cc_sender = $request->is_set_post('cc_sender'); $this->body = $request->variable('message', '', true); }
/** * Get a relative root path from the current URL * * @return string */ public function get_web_root_path() { if ($this->symfony_request === null) { return $this->src_root_path; } if (null !== $this->web_root_path) { return $this->web_root_path; } // We do not need to escape $path_info, $request_uri and $script_name because we can not find their content in the result. // Path info (e.g. /foo/bar) $path_info = $this->filesystem->clean_path($this->symfony_request->getPathInfo()); // Full request URI (e.g. src/app.php/foo/bar) $request_uri = $this->symfony_request->getRequestUri(); // Script name URI (e.g. src/app.php) $script_name = $this->symfony_request->getScriptName(); /* * If the path info is empty but we're using app.php, then we * might be using an empty route like app.php/ which is * supported by symfony's routing */ if ($path_info === '/' && preg_match('/app\\.' . $this->php_ext . '\\/$/', $request_uri)) { return $this->web_root_path = $this->filesystem->clean_path('./../' . $this->src_root_path); } /* * If the path info is empty (single /), then we're not using * a route like app.php/foo/bar */ if ($path_info === '/') { return $this->web_root_path = $this->src_root_path; } /* * Check AJAX request: * If the current request is a AJAX we need to fix the paths. * We need to get the root path based on the Referer, so we can use * the generated URLs in the template of the Referer. If we do not * generate the relative path based on the Referer, but based on the * currently requested URL, the generated URLs will not point to the * intended locations: * Referer desired URL desired relative root path * memberlist.php faq.php ./ * memberlist.php app.php/foo/bar ./ * app.php/foo memberlist.php ../ * app.php/foo app.php/fox ../ * app.php/foo/bar memberlist.php ../../ * ../page.php memberlist.php ./src/ * ../sub/page.php memberlist.php ./../src/ * * The referer must be specified as a parameter in the query. */ if ($this->request->is_ajax() && $this->symfony_request->get('_referer')) { // We need to escape $absolute_srcrd_url because it can be partially concatenated to the result. $absolute_srcrd_url = $this->request->escape($this->symfony_request->getSchemeAndHttpHost() . $this->symfony_request->getBasePath(), true); $referer_web_root_path = $this->get_web_root_path_from_ajax_referer($this->symfony_request->get('_referer'), $absolute_srcrd_url); return $this->web_root_path = $this->src_root_path . $referer_web_root_path; } // How many corrections might we need? $corrections = substr_count($path_info, '/'); /* * If the script name (e.g. src/app.php) does not exists in the * requestUri (e.g. src/app.php/foo/template), then we are rewriting * the URL. So we must reduce the slash count by 1. */ if (strpos($request_uri, $script_name) !== 0) { $corrections--; } // Prepend ../ to the src_root_path as many times as / exists in path_info $this->web_root_path = $this->filesystem->clean_path('./' . str_repeat('../', $corrections) . $this->src_root_path); return $this->web_root_path; }
/** * Parses parameters found in $request, which is an instance of * \src\request\request_interface. * * It is expected to have a key f whose value is id of the forum to be pruned. * * @param \src\request\request_interface $request Request object. * * @return null */ public function parse_parameters(\src\request\request_interface $request) { $this->forum_data = null; if ($request->is_set('f')) { $forum_id = $request->variable('f', 0); $sql = 'SELECT forum_id, prune_next, enable_prune, prune_days, prune_viewed, forum_flags, prune_freq FROM ' . FORUMS_TABLE . "\n\t\t\t\tWHERE forum_id = {$forum_id}"; $result = $this->db->sql_query($sql); $row = $this->db->sql_fetchrow($result); $this->db->sql_freeresult($result); if ($row) { $this->forum_data = $row; } } }