public function configurations() { $type = \Request::query('type', 'frontend'); $theme = \Request::query('theme', 'default'); //exit('themes/'.$type.'/'.$theme.'/config'); return $this->theme->view('theme.configurations', ['configurations' => $this->configrationRepository->lists('themes/' . $type . '/' . $theme . '/config'), 'configurationRepository' => $this->configrationRepository])->render(); }
public function paginatedCollection(Paginator $paginator, $transformer = null, $resourceKey = null) { $paginator->appends(\Request::query()); $resource = new Collection($paginator->getCollection(), $this->getTransformer($transformer), $resourceKey); $resource->setPaginator(new IlluminatePaginatorAdapter($paginator)); return $this->manager->createData($resource)->toArray(); }
/** * Sends the HTTP message [Request] to a remote server and processes * the response. * * @param Request $request request to send * @param Response $request response to send * @return Response */ public function _send_message(Request $request, Response $response) { $http_method_mapping = array(HTTP_Request::GET => HTTPRequest::METH_GET, HTTP_Request::HEAD => HTTPRequest::METH_HEAD, HTTP_Request::POST => HTTPRequest::METH_POST, HTTP_Request::PUT => HTTPRequest::METH_PUT, HTTP_Request::DELETE => HTTPRequest::METH_DELETE, HTTP_Request::OPTIONS => HTTPRequest::METH_OPTIONS, HTTP_Request::TRACE => HTTPRequest::METH_TRACE, HTTP_Request::CONNECT => HTTPRequest::METH_CONNECT); // Create an http request object $http_request = new HTTPRequest($request->uri(), $http_method_mapping[$request->method()]); if ($this->_options) { // Set custom options $http_request->setOptions($this->_options); } // Set headers $http_request->setHeaders($request->headers()->getArrayCopy()); // Set cookies $http_request->setCookies($request->cookie()); // Set query data (?foo=bar&bar=foo) $http_request->setQueryData($request->query()); // Set the body if ($request->method() == HTTP_Request::PUT) { $http_request->addPutData($request->body()); } else { $http_request->setBody($request->body()); } try { $http_request->send(); } catch (HTTPRequestException $e) { throw new Request_Exception($e->getMessage()); } catch (HTTPMalformedHeaderException $e) { throw new Request_Exception($e->getMessage()); } catch (HTTPEncodingException $e) { throw new Request_Exception($e->getMessage()); } // Build the response $response->status($http_request->getResponseCode())->headers($http_request->getResponseHeader())->cookie($http_request->getResponseCookies())->body($http_request->getResponseBody()); return $response; }
public function getInvitee($username) { $lender = LenderQuery::create()->useUserQuery()->filterByUsername($username)->endUse()->findOne(); $lenderInviteVisit = InviteVisitQuery::create()->findOneById(Session::get('lenderInviteVisitId')); if (!$lender) { return Redirect::route('/'); } $ycAccountCredit = TransactionQuery::create()->filterByUserId(Setting::get('site.YCAccountId'))->getTotalBalance(); if ($ycAccountCredit->getAmount() < 5000) { return View::make('lender.invite-inactive'); } if (!Auth::check()) { $lenderInvite = $shareType = null; if (Request::query('h')) { $lenderInvite = InviteQuery::create()->filterByLender($lender)->findOneByHash(Request::query('h')); $shareType = $lenderInvite ? 1 : null; } else { $shareType = Request::query('s') ?: 0; } $isNewVisit = !$lenderInviteVisit || $lenderInviteVisit->getLenderId() != $lender->getId(); if ($isNewVisit && $shareType !== null) { $lenderInviteVisit = $this->lenderService->addLenderInviteVisit($lender, $shareType, $lenderInvite); Session::put('lenderInviteVisitId', $lenderInviteVisit->getId()); return Redirect::route('lender:invitee', ['username' => $lender->getUser()->getUsername()]); } } return View::make('lender.invitee', compact('lender')); }
function sort_table_by($sortBy, $text, $url = null) { $currentDirection = Request::get('sort_direction'); $currentSortBy = Request::get('sort_by'); $iconDirection = "fa-sort"; $sortDirection = $currentDirection == 'asc' ? 'desc' : 'asc'; // changes the little icon for us if ($currentSortBy == $sortBy) { $iconDirection = $currentDirection == 'asc' ? "fa-sort-up" : "fa-sort-down"; } $url = $url ?: Request::url() . "?sort_direction={$sortDirection}&sort_by={$sortBy}"; // we want to keep additional query parameters on the string // so we loop through and build query below foreach (Request::query() as $queryName => $queryValue) { if (!in_array($queryName, array('sort_by', 'sort_direction'))) { if (is_array($queryValue)) { foreach ($queryValue as $value) { $url .= "&{$queryName}[]={$value}"; } } else { $url .= "&{$queryName}={$queryValue}"; } } } return "\n <a class=\"table-sorter-link {$sortBy}\" href=\"{$url}\">\n {$text}\n <i class=\"fa {$iconDirection} pull-right\"></i>\n </a>"; }
/** * Basic cache key generator that hashes the entire request and returns * it. This is fine for static content, or dynamic content where user * specific information is encoded into the request. * * // Generate cache key * $cache_key = HTTP_Cache::basic_cache_key_generator($request); * * @param Request $request * @return string */ public static function basic_cache_key_generator(Request $request) { $uri = $request->uri(); $query = $request->query(); $headers = $request->headers()->getArrayCopy(); $body = $request->body(); return sha1($uri . '?' . http_build_query($query, NULL, '&') . '~' . implode('~', $headers) . '~' . $body); }
/** * @param $data * @param null $view * @return mixed */ function pagination_links($data, $view = null) { if ($query = Request::query()) { $request = array_except($query, 'page'); return $data->appends($request)->render($view); } return $data->render($view); }
public function getIndex() { $page = Request::query('page') ?: 1; $paginator = BorrowerQuery::create()->filterByVerified(true)->filterPendingActivation()->orderByCreatedAt()->joinWith('Profile')->paginate($page, 50); $paginator->populateRelation('Contact'); $paginator->populateRelation('User'); $paginator->populateRelation('Country'); return View::make('admin.borrower-activation.index', compact('paginator')); }
public static function query(Request $request, array $query = array()) { $p = $request->query(self::QUERY_PARAM); if (!empty($p)) { return array_merge($query, array(self::QUERY_PARAM => $p)); } else { return $query; } }
/** * GET List Resources */ public function index() { $pageNum = Request::query('page'); $page = is_null($pageNum) ? 1 : (int) $pageNum; $data = $this->resource->fetch($page); $totalRows = $this->resource->getTotalRows(); $extras = array('totalrows' => (int) $totalRows); return $this->responseMessage($data, 'successful', 200, $extras); }
/** * Sends the HTTP message [Request] to a remote server and processes * the response. * * @param Request request to send * @return Response */ public function _send_message(Request $request) { // Response headers $response_headers = array(); // Set the request method $options[CURLOPT_CUSTOMREQUEST] = $request->method(); // Set the request body. This is perfectly legal in CURL even // if using a request other than POST. PUT does support this method // and DOES NOT require writing data to disk before putting it, if // reading the PHP docs you may have got that impression. SdF $options[CURLOPT_POSTFIELDS] = $request->body(); // Process headers if ($headers = $request->headers()) { $http_headers = array(); foreach ($headers as $key => $value) { $http_headers[] = $key . ': ' . $value; } $options[CURLOPT_HTTPHEADER] = $http_headers; } // Process cookies if ($cookies = $request->cookie()) { $options[CURLOPT_COOKIE] = http_build_query($cookies, NULL, '; '); } // Create response $response = $request->create_response(); $response_header = $response->headers(); // Implement the standard parsing parameters $options[CURLOPT_HEADERFUNCTION] = array($response_header, 'parse_header_string'); $this->_options[CURLOPT_RETURNTRANSFER] = TRUE; $this->_options[CURLOPT_HEADER] = FALSE; // Apply any additional options set to $options += $this->_options; $uri = $request->uri(); if ($query = $request->query()) { $uri .= '?' . http_build_query($query, NULL, '&'); } // Open a new remote connection $curl = curl_init($uri); // Set connection options if (!curl_setopt_array($curl, $options)) { throw new Request_Exception('Failed to set CURL options, check CURL documentation: :url', array(':url' => 'http://php.net/curl_setopt_array')); } // Get the response body $body = curl_exec($curl); // Get the response information $code = curl_getinfo($curl, CURLINFO_HTTP_CODE); if ($body === FALSE) { $error = curl_error($curl); } // Close the connection curl_close($curl); if (isset($error)) { throw new Request_Exception('Error fetching remote :url [ status :code ] :error', array(':url' => $request->url(), ':code' => $code, ':error' => $error)); } $response->status($code)->body($body); return $response; }
/** * Displays a grid of titles with pagination. * * @return View */ public function index() { $q = Request::query(); //make index page crawlable by google if (isset($q['_escaped_fragment_'])) { $series = Title::where('type', 'series')->paginate(16); return View::make('Titles.CrawlableIndex')->with('movies', $series)->with('type', 'series'); } return View::make('Titles.Index')->withType('series'); }
/** * Split the URL for the current request. * */ public function splitUrl() { $url = $this->request->query("url"); if (!empty($url)) { $url = explode('/', filter_var(trim($url, '/'), FILTER_SANITIZE_URL)); $this->controller = !empty($url[0]) ? ucwords($url[0]) . 'Controller' : null; $this->method = !empty($url[1]) ? $url[1] : null; unset($url[0], $url[1]); $this->args = !empty($url) ? array_values($url) : []; } }
static function retrieve() { $array_query = explode('/', $_SERVER['REQUEST_URI']); if ($array_query[0] == APP_W) { array_shift($array_query); } if (end($array_query) == "") { array_pop($array_query); } self::$query = $array_query; //var_dump($array_query); }
/** * Bootstrap any application services. * * @return void */ public function boot() { if (config('app.debug')) { \DB::enableQueryLog(); } \View::composer('widgets.categories', function ($view) { $view->with('categories', \App\Category::ordered()->get()); }); \View::composer(['widgets.categories', 'articles.index'], function ($view) { $view->with('QUERY', \Request::query()); }); }
/** * Calculate the signature of a request. * Should be called just before the request is sent. * * @param Request $request * @param $private_key * @return string Calculated HMAC */ public static function calculate_hmac(Request $request, $private_key) { // Consolidate data that's not in the main route (params) $query = array_change_key_case($request->query()); $post = array_change_key_case($request->post()); // Sort alphabetically ksort($query); ksort($post); $data_to_sign = ['method' => $request->method(), 'uri' => $request->uri(), 'post' => $post, 'query' => $query]; // Calculate the signature return hash_hmac('sha256', json_encode($data_to_sign), $private_key); }
/** * Displays the error * * @param array $options Options from config * @return void */ protected function _action_display(array $options = array()) { if (((Kohana::$environment > Kohana::STAGING) and ($this->request_initial->query('show_error') == 'true')) or ($this->request_initial->query('display_token') == $this->config('display_token', false))) { Kohana_Exception::handler($this->exception); exit(1); } $view = Arr::get($options, 'view', 'errors/_default'); $this->display = $this->render($view); echo $this->display; }
/** * Display a listing of the resource. * * @return \Illuminate\Http\Response */ public function index() { $perPage = 20; $currentPage = Input::get('page', 1); $users = User::all(); $users = $users->sortByDesc(function ($item) { return [$item->getAcceptCount(), -$item->getSubmitCount()]; })->values(); $total = $users->count(); $users = $users->forPage($currentPage, $perPage); $rankNumber = ($currentPage - 1) * $perPage + 1; $paginator = new LengthAwarePaginator($users, $total, $perPage, $currentPage, ['path' => \Request::url(), 'query' => \Request::query()]); return view('rank.index', compact('users', 'rankNumber', 'paginator')); }
public function getTransactionHistory() { $currentBalance = $this->transactionQuery->filterByUserId(Auth::getUser()->getId())->getTotalAmount(); $page = Request::query('page') ?: 1; $currentBalancePageObj = DB::select('SELECT SUM(amount) AS total FROM transactions WHERE id IN (SELECT id FROM transactions WHERE user_id = ? ORDER BY transaction_date DESC, transactions.id DESC OFFSET ?)', array(Auth::getUser()->getId(), ($page - 1) * 50)); $currentBalancePage = Money::create($currentBalancePageObj[0]->total); $paginator = $this->transactionQuery->create()->orderByTransactionDate('desc')->orderById('desc')->filterByUserId(Auth::getUser()->getId())->paginate($page, 50); return View::make('lender.history', compact('paginator', 'currentBalance', 'currentBalancePage')); }
/** * Method that fires after before a super group displays a super group comonent * * @return void */ public function onBeforeRenderSuperGroupComponent() { // get request options $option = Request::getCmd('option', ''); // make sure we in groups if ($option != 'com_groups') { return; } $cn = Request::getVar('cn', ''); $active = Request::getVar('active', ''); // load group object $group = \Hubzero\User\Group::getInstance($cn); // make sure we have all the needed stuff if (is_object($group) && $group->isSuperGroup() && isset($cn) && isset($active)) { // get com_groups params to get upload path $uploadPath = $this->filespace($group); $componentPath = $uploadPath . DS . 'components'; $componentRouter = $componentPath . DS . 'com_' . $active . DS . 'router.php'; // if we have a router if (file_exists($componentRouter)) { // include router require_once $componentRouter; // build function name $parseRouteFunction = ucfirst($active) . 'ParseRoute'; $parseRouteFunction = str_replace(array('-', '.'), '', $parseRouteFunction); // if we have a build route functions, run it if (function_exists($parseRouteFunction)) { // get current route and remove prefix $currentRoute = rtrim(Request::path(), '/'); $currentRoute = trim(str_replace('groups/' . $group->get('cn') . '/' . $active, '', $currentRoute), '/'); // split route into segements $segments = explode('/', $currentRoute); // run segments through parser $vars = $parseRouteFunction($segments); // set each var foreach ($vars as $key => $var) { Request::setVar($key, $var); } } } // remove "sg_" prefix for super group query params foreach (Request::query() as $k => $v) { if (strpos($k, 'sg_') !== false) { Request::setVar(str_replace('sg_', '', $k), $v); } } } }
static function retrieve() { $array_query = explode('/', $_SERVER['REQUEST_URI']); //Coder::code_var($array_query); array_shift($array_query); //Coder::code_var($array_query); if ($array_query[0] == APP_W || substr_count(APP_W, $array_query[0]) > 0) { array_shift($array_query); } //cal estudiar que passa amb l'últim element si aquest és "" if (end($array_query) == "") { array_pop($array_query); } self::$query = $array_query; //Coder::code_var($array_query); }
static function retrieve() { $array_query = explode('/', $_SERVER['REQUEST_URI']); //quitamos la raiz array_shift($array_query); //si no está en la raiz... if ($array_query[0] == APP_W) { array_shift($array_query); } //si al final tiene una / if (end($array_query) == "") { array_pop($array_query); } self::$query = $array_query; //var_dump($array_query); }
/** * Sends the HTTP message [Request] to a remote server and processes * the response. * * @param Request request to send * @return Response * @uses [PHP cURL](http://php.net/manual/en/book.curl.php) */ public function _send_message(Request $request) { // Calculate stream mode $mode = $request->method() === HTTP_Request::GET ? 'r' : 'r+'; // Process cookies if ($cookies = $request->cookie()) { $request->headers('cookie', http_build_query($cookies, NULL, '; ')); } // Get the message body $body = $request->body(); if (is_resource($body)) { $body = stream_get_contents($body); } // Set the content length $request->headers('content-length', (string) strlen($body)); list($protocol) = explode('/', $request->protocol()); // Create the context $options = array(strtolower($protocol) => array('method' => $request->method(), 'header' => (string) $request->headers(), 'content' => $body)); // Create the context stream $context = stream_context_create($options); stream_context_set_option($context, $this->_options); $uri = $request->uri(); if ($query = $request->query()) { $uri .= '?' . http_build_query($query, NULL, '&'); } $stream = fopen($uri, $mode, FALSE, $context); $meta_data = stream_get_meta_data($stream); // Get the HTTP response code $http_response = array_shift($meta_data['wrapper_data']); if (preg_match_all('/(\\w+\\/\\d\\.\\d) (\\d{3})/', $http_response, $matches) !== FALSE) { $protocol = $matches[1][0]; $status = (int) $matches[2][0]; } else { $protocol = NULL; $status = NULL; } // Create a response $response = $request->create_response(); $response_header = $response->headers(); // Process headers array_map(array($response_header, 'parse_header_string'), array(), $meta_data['wrapper_data']); $response->status($status)->protocol($protocol)->body(stream_get_contents($stream)); // Close the stream after use fclose($stream); return $response; }
public function testPostJson() { $r = new Request(['url' => 'api/tasks/12.json', 'filter' => 'all'], ['HTTP_ACCEPT' => 'application/json;q=0.8', 'REQUEST_URI' => '/api/tasks/12.json?filter=all', 'REQUEST_METHOD' => 'POST'], ['url' => 'api/tasks/12.json', 'filter' => 'all'], ['title' => 'New Title']); $this->assertTrue($r instanceof Request); $this->assertEquals(Request::POST, $r->method()); $this->assertEquals('api/tasks/12.json', $r->url()); $this->assertEquals('json', $r->type()); $this->assertEquals('all', $r->param('filter')); $route = $r->route(); $this->assertTrue($route instanceof Route); $result = $r->response(); $this->assertTrue($result instanceof Response); $this->assertEquals("New Title", $r->param('title')); $expected = ['filter' => 'all']; $result = $r->query(); $this->assertEquals($expected, $result); }
static function retrieve() { $array_query = explode('/', $_SERVER['REQUEST_URI']); //extract the first "/" array_shift($array_query); // if we publish in root if (!is_base()) { array_shift($array_query); } //deleting blanks at the end if (end($array_query) == "") { array_pop($array_query); } //return value to static $query self::$query = $array_query; //var_dump($array_query); }
/** * URL::query() replacement for Pagination use only * * @param array $params Parameters to override * * @return string */ public function query(array $params = null) { if ($params === null) { // Use only the current parameters $params = $this->_request->query(); } else { // Merge the current and new parameters $params = array_merge($this->_request->query(), $params); } if (empty($params)) { // No query parameters return ''; } // Note: http_build_query returns an empty string for a params array with only null values $query = http_build_query($params, '', '&'); // Don't prepend '?' to an empty string return $query === '' ? '' : '?' . $query; }
static function retrieve() { $array_query = explode('/', $_SERVER['REQUEST_URI']); array_shift($array_query); //quita un elemento por delante, que en nuestro caso es el primer espacio en blanco //array_pop($array_query);//quita un elemento por detras //var_dump($array_query); //if we publish in root if ($array_query[0] == APP_W) { array_shift($array_query); } //deleting blanks at the end if (end($array_query) == "") { array_pop($array_query); } //return value to starti $query self::$query = $array_query; }
public function getIndex($stage = null, $category = null, $country = null) { // for categories $loanCategories = $this->loanCategoryQuery->orderByRank()->find(); //for countries $countries = $this->countryQuery->orderByName()->find(); //for loans $conditions = []; $loanCategoryName = $category; $stageName = $stage; $selectedLoanCategory = $this->loanCategoryQuery->findOneBySlug($loanCategoryName); $routeParams = ['category' => 'all', 'stage' => 'fund-raising', 'country' => 'everywhere']; if ($stageName == 'completed') { $routeParams['stage'] = 'completed'; $conditions['status'] = [Loan::DEFAULTED, Loan::REPAID]; } elseif ($stageName == 'active') { $routeParams['stage'] = 'active'; $conditions['status'] = [Loan::ACTIVE, Loan::FUNDED]; } else { $routeParams['stage'] = 'fund-raising'; $conditions['status'] = Loan::OPEN; } if ($selectedLoanCategory) { $conditions['categoryId'] = $selectedLoanCategory->getId(); $routeParams['category'] = $selectedLoanCategory->getSlug(); } $countryName = $country; $selectedCountry = $this->countryQuery->findOneBySlug($countryName); if ($selectedCountry) { $conditions['countryId'] = $selectedCountry->getId(); $routeParams['country'] = $selectedCountry->getSlug(); } $searchRouteParams = $routeParams; $searchQuery = Request::query('search'); if ($searchQuery) { $conditions['search'] = $searchQuery; $routeParams['search'] = $searchQuery; } $page = Request::query('page') ?: 1; $paginator = $this->loanService->searchLoans($conditions, $page); return View::make('pages.lend', compact('countries', 'selectedCountry', 'loanCategories', 'selectedLoanCategory', 'paginator', 'routeParams', 'searchQuery', 'searchRouteParams')); }
/** * @test * @group pmc */ public function testQueryParams() { $body = <<<RESPONSE Server: Make-Believe Content-Type: text/plain Blade RESPONSE; $curl = $this->_mockCurl(); $curl->expects($this->once())->method('init')->with('http://google.com?q=this&q2=that'); $curl->expects($this->exactly(2))->method('setopt')->withConsecutive(array($this->equalTo(CURLOPT_RETURNTRANSFER), $this->equalTo(true)), array($this->equalTo(CURLOPT_HEADER), $this->equalTo(true))); $curl->expects($this->once())->method('exec')->will($this->returnValue($body)); $curl->expects($this->once())->method('errno')->will($this->returnValue(0)); $curl->expects($this->once())->method('getinfo')->will($this->returnValue(array('header_size' => 45, 'http_code' => 200))); $request = new Request('GET', 'http://google.com', new \Bronto\DataObject(), $curl); $response = $request->query("q", "this")->query("q2", "that")->respond(); $this->assertEquals(200, $response->code()); $this->assertEquals("Blade", $response->body()); $this->assertEquals("Make-Believe", $response->header('Server')); $this->assertEquals("text/plain", $response->header('Content-Type')); }
/** * Tests that query parameters are parsed correctly * * @dataProvider provider_query_parameter_parsing * * @param Request request * @param array query * @param array expected * @return void */ public function test_query_parameter_parsing(Request $request, $query, $expected) { foreach ($query as $key => $value) { $request->query($key, $value); } $this->assertSame($expected, $request->query()); }