public function testGetURL() { $req = new SS_HTTPRequest('GET', '/'); $this->assertEquals('', $req->getURL()); $req = new SS_HTTPRequest('GET', '/assets/somefile.gif'); $this->assertEquals('assets/somefile.gif', $req->getURL()); $req = new SS_HTTPRequest('GET', '/home?test=1'); $this->assertEquals('home?test=1', $req->getURL(true)); $this->assertEquals('home', $req->getURL()); }
/** * Process all incoming requests passed to this controller, checking * that the file exists and passing the file through if possible. */ public function handleRequest(SS_HTTPRequest $request, DataModel $model) { $response = new SS_HTTPResponse(); $filename = $request->getURL(); if (strpos($filename, 'cdnassets') === 0) { $filename = 'assets/' . substr($filename, strlen('cdnassets/')); } $file = null; if (strpos($filename, '_resampled') !== false) { $file = ContentServiceAsset::get()->filter('Filename', $filename)->first(); } else { if (strpos($filename, '/_versions/') !== false) { $file = FileVersion::get()->filter('Filename', "/" . $filename)->first(); } else { $file = File::get()->filter('filename', $filename)->first(); } } if ($file && $file->canView()) { if (!$file->CDNFile && !$file->FilePointer) { return $this->httpError(404); } // Permission passed redirect to file $redirectLink = ''; if ($file->getViewType() != CDNFile::ANYONE_PERM) { if ($file->hasMethod('getSecureURL')) { $redirectLink = $file->getSecureURL(180); } if (!strlen($redirectLink)) { // can we stream it? return $this->sendFile($file); } } else { $redirectLink = $file->getURL(); } if ($redirectLink && trim($redirectLink, '/') != $request->getURL()) { $response->redirect($redirectLink); } else { return $this->httpError(404); } } else { if (class_exists('SecureFileController')) { $handoff = SecureFileController::create(); return $handoff->handleRequest($request, $model); } elseif ($file instanceof File) { // Permission failure Security::permissionFailure($this, 'You are not authorised to access this resource. Please log in.'); } else { // File doesn't exist $response = new SS_HTTPResponse('File Not Found', 404); } } return $response; }
/** * @uses ModelAsController::getNestedController() * @param SS_HTTPRequest $request * @param DataModel $model * @return SS_HTTPResponse */ public function handleRequest(SS_HTTPRequest $request, DataModel $model) { // Check Translatable dependency if (!class_exists('Translatable') || !SiteTree::has_extension('Translatable') && !SiteTree::has_extension('LanguagePrefixTranslatable')) { throw new Exception('Dependency error: the LanguagePrefix module expects the Translatable module.'); } $disablePrefixForDefaultLang = Config::inst()->get('prefixconfig', 'disable_prefix_for_default_lang'); $firstSegment = $request->param('URLSegment'); if ($firstSegment) { $prefixUsed = $this->setLocale($firstSegment); $defaultLocale = Translatable::default_locale(); $isDefaultLocale = $this->locale == $defaultLocale; if ($prefixUsed) { if ($isDefaultLocale && $disablePrefixForDefaultLang) { $url = substr($request->getURL(true), strlen($firstSegment)); return $this->redirect($url, 301); } else { $request->shiftAllParams(); $request->shift(1); } } else { /* * if no prefix is used but $disablePrefixForDefaultLang * is set, we go on like nothing happened. Otherwise a * 404 is generated. @todo: maybe we should redirect * pages that do actually exist, because this is a bit * harsh? */ //if (!$isDefaultLocale || !$disablePrefixForDefaultLang) { // return $this->showPageNotFound(); //} } } return parent::handleRequest($request, $model); }
public function placeOrder(SS_HTTPRequest $request) { $eventbrite_event_header = $request->getHeader('X-Eventbrite-Event'); if (!$eventbrite_event_header) { return $this->httpError(403); } if ($eventbrite_event_header !== 'order.placed') { return $this->httpError(403); } if (!$this->isJson()) { return $this->httpError(403); } $json_request = $this->getJsonRequest(); if (!isset($json_request['config']) || !isset($json_request['api_url'])) { return $this->httpError(403); } $config = $json_request['config']; if (!isset($config['action']) || $config['action'] !== 'order.placed') { return $this->httpError(403); } $current_local_url = Controller::join_links(Director::absoluteBaseURL(), $request->getURL()); if (!isset($config['endpoint_url']) || $config['endpoint_url'] !== $current_local_url) { return $this->httpError(403); } try { $this->manager->registerEvent('ORDER_PLACED', $json_request['api_url']); } catch (Exception $ex) { SS_Log::log($ex->getMessage(), SS_Log::ERR); return $this->httpError(500); } return true; }
public function postRequest(\SS_HTTPRequest $request, \SS_HTTPResponse $response, \DataModel $model) { if (defined('PROXY_CACHE_GENERATING') || isset($GLOBALS['__cache_publish']) || strpos($request->getURL(), 'admin/') !== false) { return; } $this->database = Db::getConn(); $queries = $this->database->queryRecord; $dupes = $this->database->getDuplicateQueries(); $str = "\n<!-- Total queries: " . count($queries) . "-->\n"; $str .= "\n<!-- Duplicate queries: " . count($dupes) . "-->\n"; $b = $response->getBody(); if (strpos($b, '</html>')) { if (count($queries) > $this->queryThreshold) { // add a floating div with info about the stuff $buildQueryList = function ($source, $class) { $html = ''; foreach ($source as $sql => $info) { $html .= "\n<p class='{$class}' style='display: none; border-top: 1px dashed #000;'>{$info->count} : {$info->query}</p>\n"; if ($info->source) { $html .= "\n<p class='{$class}' style='color: #a00; display: none; '>Last called from {$info->source}</p>\n"; } } return $html; }; $html = $buildQueryList($queries, 'debug-query'); $html .= $buildQueryList($dupes, 'debug-dupe-query'); $div = '<div id="query-stat-debugger" ' . 'style="position: fixed; bottom: 0; right: 0; border: 2px solid red; background: #fff; ' . 'font-size: 8px; font-family: sans-serif; width: 100px; z-index: 2000; padding: 1em;' . 'overflow: auto; max-height: 500px;">' . '<p id="debug-all-queries-list">Total of ' . count($queries) . ' queries</p>' . '<p id="debug-dupe-queries-list">Total of ' . count($dupes) . ' duplicates</p>' . $html . '<script>' . 'jQuery("#debug-all-queries-list").click(function () {' . 'var elems = jQuery(this).parent().find(".debug-query");' . 'jQuery(this).parent().css("width", "40%");' . 'elems.toggle();' . '}); ' . 'jQuery("#debug-dupe-queries-list").click(function () {' . 'var elems = jQuery(this).parent().find(".debug-dupe-query");' . 'jQuery(this).parent().css("width", "40%");' . 'elems.toggle();' . '}); ' . '' . '' . '</script>' . '</div>'; $b = str_replace('</body>', "{$div}</body>", $b); } $b = str_replace('</html>', "{$str}</html>", $b); $response->setBody($b); } }
/** * On every URL that generates a 404, we'll capture it here and see if we can * find an old URL that it should be redirecting to. * * @param SS_HTTPRequest $request The request object * @throws SS_HTTPResponse_Exception */ public function onBeforeHTTPError404($request) { // We need to get the URL ourselves because $request->allParams() only has a max of 4 params $params = preg_split('|/+|', $request->getURL()); $cleanURL = trim(Director::makeRelative($request->getURL(false), '/')); $getvars = $request->getVars(); unset($getvars['url']); $page = self::find_old_page($params); $cleanPage = trim(Director::makeRelative($page), '/'); if (!$cleanPage) { $cleanPage = Director::makeRelative(RootURLController::get_homepage_link()); } if ($page && $cleanPage != $cleanURL) { $res = new SS_HTTPResponse(); $res->redirect(Controller::join_links($page, $getvars ? '?' . http_build_query($getvars) : null), 301); throw new SS_HTTPResponse_Exception($res); } }
/** * Extract url, checks $_SERVER first to try and get raw url * * @param SS_HTTPRequest $request * @return string */ public function getUrl($request) { if (!empty($_SERVER['REQUEST_URI'])) { return $_SERVER['REQUEST_URI']; } elseif (!empty($_GET['url'])) { return $_GET['url']; } else { return $request->getURL(); } }
/** * @param \SS_HTTPRequest $request * @return \Heyday\Redirects\Redirect */ public function getRedirectForRequest(\SS_HTTPRequest $request) { $url = $request->getURL(); foreach ($this->dataSource->get() as $redirect) { if ($redirect->match($url)) { return $redirect; } } return false; }
/** * @param SS_HTTPRequest $request */ public static function UpdateContinentBasedOnURL(SS_HTTPRequest $request) { if ($strURL = $request->getURL(false)) { $arrParts = explode('/', $strURL); foreach (ContinentalContent::GetContinents() as $strContinent => $strCode) { if ($strCode === $arrParts[0]) { ContinentalContent::ForceUpdateContinent($strCode); } } } }
/** * On every URL that generates a 404, we'll capture it here and see if we can * find an old URL that it should be redirecting to. * * @param SS_HTTPRequest $request The request object * @throws SS_HTTPResponse_Exception */ public function onBeforeHTTPError404($request) { // We need to get the URL ourselves because $request->allParams() only has a max of 4 params $params = preg_split('|/+|', $request->getURL()); $getvars = $request->getVars(); unset($getvars['url']); $page = self::find_old_page($params); if ($page) { $res = new SS_HTTPResponse(); $res->redirect(Controller::join_links($page, $getvars ? '?' . http_build_query($getvars) : null), 301); throw new SS_HTTPResponse_Exception($res); } }
/** * @param \SS_HTTPRequest $request * @return \Heyday\Redirects\Redirect */ public function getRedirectForRequest(\SS_HTTPRequest $request) { // Format the URL as the key will have been formatted $url = Redirect::formatUrl($request->getURL()); $dataSource = $this->dataSource->get(); // Check if there's a key for the URL if (isset($dataSource[$url])) { $redirect = $dataSource[$url]; if ($redirect->match($url)) { return $redirect; } } return false; }
/** * Check if we're in a login request. If so, we're going to explicitly disable * restrictedobjects permission checks. This is poor, but dictated by the core * member login code performing writes prior to having a user context. * * @param \SS_HTTPRequest $request * @param \Session $session * @param \DataModel $model */ public function preRequest(\SS_HTTPRequest $request, \Session $session, \DataModel $model) { if (strtolower($request->httpMethod()) === 'post' && ($request->getURL() === 'Security/LoginForm' || $request->getURL() === 'Security/LostPasswordForm' || $request->getURL() === 'Security/ChangePasswordForm')) { Restrictable::set_enabled(false); } }
/** * Creates a failed spam attempt object witht the user's info * * @param SS_HTTPRequest * @return ContactFormSpamAttempt */ public function createSpamAttempt(SS_HTTPRequest $r) { $spam = ContactFormSpamAttempt::create(array('IPAddress' => $r->getIP(), 'URL' => $r->getURL(), 'Notes' => $this->class)); return $spam; }
/** * Action to show a product detail page. * Returns the rendered detail page. * * @param SS_HTTPRequest $request Request * * @return string * * @author Sebastian Diel <*****@*****.**> * @since 03.07.2013 */ public function detail(SS_HTTPRequest $request) { $params = $request->allParams(); $productID = $params['ID']; $product = SilvercartProduct::get()->byID($productID); $productLink = $product->Link(); $calledLink = $request->getURL(); if (strpos($calledLink, '/') != strpos($productLink, '/')) { if (strpos($productLink, '/') == 0) { $calledLink = '/' . $calledLink; } elseif (strpos($calledLink, '/') == 0) { $productLink = '/' . $productLink; } } if ($calledLink != $productLink) { SilvercartTools::redirectPermanentlyTo($productLink); } $this->setProduct($product); return $this->render(); }
/** * Attempt to redirect towards the highest priority link mapping that may have been defined. * * @URLparameter direct <{BYPASS_LINK_MAPPINGS}> boolean */ public function postRequest(SS_HTTPRequest $request, SS_HTTPResponse $response, DataModel $model) { // Bypass the request filter when requesting specific director rules such as "/admin" or "/dev". $requestURL = $request->getURL(); $configuration = Config::inst(); foreach ($configuration->get('Director', 'rules') as $segment => $controller) { // Retrieve the specific director rules. if (($position = strpos($segment, '$')) !== false) { $segment = rtrim(substr($segment, 0, $position), '/'); } // Determine if the current request matches a specific director rule. if ($segment && strpos($requestURL, $segment) === 0) { // Continue processing the response. return true; } } // Bypass the request filter when using the direct GET parameter. if ($request->getVar('direct')) { // Continue processing the response. return true; } // Determine the default automated URL handling response status. $status = $response->getStatusCode(); $success = $status >= 200 && $status < 300; $error = $status === 404; // Either hook into a page not found, or when enforced, replace the default automated URL handling. $enforce = $configuration->get('MisdirectionRequestFilter', 'enforce_misdirection'); $replace = $configuration->get('MisdirectionRequestFilter', 'replace_default'); if (($error || $enforce || $replace) && ($map = $this->service->getMappingByRequest($request))) { // Update the response code where appropriate. $responseCode = $map->ResponseCode; if ($responseCode == 0) { $responseCode = 303; } else { if ($responseCode == 301 && $map->ForwardPOSTRequest) { $responseCode = 308; } else { if ($responseCode == 303 && $map->ForwardPOSTRequest) { $responseCode = 307; } } } // Update the response using the link mapping redirection. $response->redirect($map->getLink(), $responseCode); } else { if ($error && ($fallback = $this->service->determineFallback($requestURL))) { // Update the response code where appropriate. $responseCode = $fallback['code']; if ($responseCode === 0) { $responseCode = 303; } // Update the response using the fallback, enforcing no further redirection. $response->redirect(HTTP::setGetVar('direct', true, Controller::join_links(Director::absoluteBaseURL(), $fallback['link'])), $responseCode); } else { if (!$error && !$success && $replace) { $response->setStatusCode(404); // Retrieve the appropriate page not found response. ClassInfo::exists('SiteTree') && ($page = ErrorPage::response_for(404)) ? $response->setBody($page->getBody()) : $response->setBody('No URL was matched!'); } } } // Continue processing the response. return true; }
/** * @param SS_HTTPRequest $request * @return string */ protected function getCacheKey(SS_HTTPRequest $request) { return $request->getURL(true); }
/** * Spits out an exported version of the selected WorkflowDefinition for download. * * @param \SS_HTTPRequest $request * @return \SS_HTTPResponse */ public function export(SS_HTTPRequest $request) { $url = explode('/', $request->getURL()); $definitionID = end($url); if ($definitionID && is_numeric($definitionID)) { $exporter = new WorkflowDefinitionExporter($definitionID); $exportFilename = WorkflowDefinitionExporter::$export_filename_prefix . '-' . $definitionID . '.yml'; $exportBody = $exporter->export(); $fileData = array('name' => $exportFilename, 'mime' => 'text/x-yaml', 'body' => $exportBody, 'size' => $exporter->getExportSize($exportBody)); return $exporter->sendFile($fileData); } }
/** * Construct the deployment form * * @param SS_HTTPRequest $request * @return Form */ public function getDeployForm(SS_HTTPRequest $request) { // Performs canView permission check by limiting visible projects $project = $this->getCurrentProject(); if (!$project) { return new SS_HTTPResponse("Project '" . Convert::raw2xml($request->latestParam('Project')) . "' not found.", 404); } // Performs canView permission check by limiting visible projects $environment = $this->getCurrentEnvironment($project); if (!$environment) { return new SS_HTTPResponse("Environment '" . Convert::raw2xml($request->latestParam('Environment')) . "' not found.", 404); } if (!$environment->canDeploy()) { return new SS_HTTPResponse("Not allowed to deploy", 401); } if (!$project->repoExists()) { $literalField = new LiteralField('noRepoWarning', '<strong>The GIT repository is for the time being not available.</strong>'); return Form::create($this, 'DeployForm', new FieldList($literalField), new FieldList()); } // Generate the form $form = new DeployForm($this, 'DeployForm', $environment, $project); // Tweak the action so it plays well with our fake URL structure. $form->setFormAction($request->getURL() . '/DeployForm'); return $form; }
/** * Construct the deployment form * * @param SS_HTTPRequest $request * @return Form */ public function getDeployForm(SS_HTTPRequest $request) { // Performs canView permission check by limiting visible projects $project = $this->getCurrentProject(); if (!$project) { return new SS_HTTPResponse("Project '" . Convert::raw2xml($request->latestParam('Project')) . "' not found.", 404); } // Performs canView permission check by limiting visible projects $environment = $this->getCurrentEnvironment($project); if (!$environment) { return new SS_HTTPResponse("Environment '" . Convert::raw2xml($request->latestParam('Environment')) . "' not found.", 404); } if (!$environment->canDeploy()) { return new SS_HTTPResponse("Not allowed to deploy", 401); } if (!$project->repoExists()) { $literalField = new LiteralField('noRepoWarning', '<strong>The GIT repository is for the time being not available.</strong>'); return Form::create($this, 'DeployForm', new FieldList($literalField), new FieldList()); } $branches = array(); foreach ($project->DNBranchList() as $branch) { $sha = $branch->SHA(); $name = $branch->Name(); $branches[$sha] = $name . ' (' . substr($sha, 0, 8) . ', ' . $branch->LastUpdated()->TimeDiff() . ' old)'; } $tags = array(); foreach ($project->DNTagList()->setLimit(null) as $tag) { $sha = $tag->SHA(); $name = $tag->Name(); $tags[$sha] = $name . ' (' . substr($sha, 0, 8) . ', ' . $tag->Created()->TimeDiff() . ' old)'; } $tags = array_reverse($tags); $redeploy = array(); foreach ($project->DNEnvironmentList() as $dnEnvironment) { $envName = $dnEnvironment->Name; foreach ($dnEnvironment->DeployHistory() as $deploy) { $sha = $deploy->SHA; if (!isset($redeploy[$envName])) { $redeploy[$envName] = array(); } if (!isset($redeploy[$envName][$sha])) { $redeploy[$envName][$sha] = substr($sha, 0, 8) . ' (deployed ' . $deploy->obj('LastEdited')->Ago() . ')'; } } } $releaseMethods = array(); if ($tags) { $releaseMethods[] = new SelectionGroup_Item('Tag', new DropdownField('Tag', '', $tags), 'Deploy a tagged release'); } if ($branches) { $releaseMethods[] = new SelectionGroup_Item('Branch', new DropdownField('Branch', '', $branches), 'Deploy the latest version of a branch'); } if ($redeploy) { $releaseMethods[] = new SelectionGroup_Item('Redeploy', new GroupedDropdownField('Redeploy', '', $redeploy), 'Redeploy a release that was previously deployed (to any environment)'); } $releaseMethods[] = new SelectionGroup_Item('SHA', new Textfield('SHA', 'Please specify the full SHA'), 'Deploy a specific SHA'); $field = new SelectionGroup('SelectRelease', $releaseMethods); $field->setValue('Tag'); $form = new Form($this, 'DeployForm', new FieldList($field), new FieldList($deployAction = new FormAction('doDeploy', "Deploy to " . $environment->Name))); $deployAction->addExtraClass('btn'); $form->disableSecurityToken(); // Tweak the action so it plays well with our fake URL structure. $form->setFormAction($request->getURL() . '/DeployForm'); return $form; }
/** * @param SS_HTTPRequest $request * @param string $template_class * @param string $ss_tpl_name * @return array */ private function buildList(SS_HTTPRequest $request, $template_class = 'SurveyTemplate', $ss_tpl_name = 'SurveyBuilderListSurveys') { Requirements::javascript('themes/openstack/javascript/querystring.jquery.js'); Requirements::javascript('survey_builder/js/survey.sangria.surveys.list.filter.js'); $query_templates = new QueryObject(new SurveyTemplate()); $query_templates->addAndCondition(QueryCriteria::equal('ClassName', $template_class)); list($templates, $count) = $this->survey_template_repository->getAll($query_templates, 0, PHP_INT_MAX); $page = intval($request->getVar('page')); $survey_template_id = intval($request->getVar('survey_template_id')); $question_id = intval($request->getVar('question_id')); $question_value = Convert::raw2sql($request->getVar('question_value')); $question_value2 = Convert::raw2sql($request->getVar('question_value2')); $question_value = !empty($question_value) ? $question_value : $question_value2; $order = Convert::raw2sql($request->getVar('order')); $order_dir = Convert::raw2sql($request->getVar('dir')); if ($page === 0) { $page = 1; } $offset = ($page - 1) * self::SurveysPageSize; $sort_fields = ['id' => 'ID', 'created' => 'Created', 'updated' => 'LastEdited']; $query_surveys = new QueryObject(new Survey()); $selected_template = $survey_template_id > 0 ? $this->survey_template_repository->getById($survey_template_id) : $templates[0]; if ($survey_template_id === 0) { Controller::curr()->redirect($request->getURL(true) . '?survey_template_id=' . $selected_template->ID); } $query_surveys->addAndCondition(QueryCriteria::id('Survey.TemplateID', $selected_template->getIdentifier()))->addAndCondition(QueryCriteria::id('Survey.IsTest', 0)); if ($question_id > 0 && !empty($question_value)) { // filter by question ... $query_surveys->addAlias(QueryAlias::create('Steps')->addAlias(QueryAlias::create('Answers')->addAlias(QueryAlias::create('Question')))); $query_surveys->addAndCondition(QueryCompoundCriteria::compoundAnd([QueryCriteria::id('SurveyQuestionTemplate.ID', $question_id), QueryCriteria::like('SurveyAnswer.Value', $question_value)])); } if (empty($order)) { $query_surveys->addOrder(QueryOrder::asc('ID')); } else { if ($order_dir === 'ASC') { $query_surveys->addOrder(QueryOrder::asc($sort_fields[$order])); } else { $query_surveys->addOrder(QueryOrder::desc($sort_fields[$order])); } } list($surveys, $count_surveys) = $this->survey_repository->getAll($query_surveys, $offset, self::SurveysPageSize); // build pager $pages = ''; $max_page = intval(ceil($count_surveys / self::SurveysPageSize)); for ($i = 1; $i < $max_page; $i++) { $pages .= sprintf("<li %s ><a href=\"%s?%s\">%s</a></li>", $page === $i ? "class=\"active\"" : "", $this->owner->Link($ss_tpl_name), $this->getPagerLink($i), $i); } $pager = <<<HTML <nav> <ul class="pagination pagination-sm"> {$pages} </ul> </nav> HTML; $result = ['Templates' => new ArrayList($templates), 'Surveys' => new ArrayList($surveys), 'Questions' => new ArrayList($selected_template->getAllFilterableQuestions()), 'Pager' => $pager]; return $result; }
/** * Render the KeywordInsertionPage page * * @param \SS_HTTPRequest $request * * @return string Rendered template */ public function renderInsertionPage(SS_HTTPRequest $request) { $sUrlSegment = $this->getUrlSegment($request->getURL()); $oPage = $this->pageObject($sUrlSegment); if (!$oPage) { $oErrorPage = DataObject::get_one('ErrorPage'); Director::direct($oErrorPage->Link(), 404); } $sKeyword = $this->paramKeyword(); $sContent = $oPage->renderContent($sKeyword); return $this->render(array('Content' => $sContent)); }
/** * Generates a fake request for the field * @param {SS_HTTPRequest} $request Source Request to base the fake request off of * @param {Widget} $sourceWidget Source widget * @param {string} $baseLink Base URL to be truncated off of the form * @return {SS_HTTPRequest} Fake HTTP Request used to fool the form field into thinking the request was made to it directly */ protected function getFakeRequest(SS_HTTPRequest $request, Widget $sourceWidget, $baseLink) { $fieldName = rawurldecode($request->param('FieldName')); $objID = preg_replace('/Widget\\[(.*?)\\]\\[(.*?)\\]\\[(.*?)\\]$/', '$2', $fieldName); $finalPostVars = array(); if ($request->isPOST()) { $postVars = $request->postVars(); //Pull the post data for the widget if (isset($postVars['Widget'][$this->getName()][$objID])) { $finalPostVars = $postVars['Widget'][$this->getName()][$objID]; } else { $finalPostVars = array(); } $finalPostVars = array_merge($finalPostVars, $postVars); unset($finalPostVars['Widget']); //Workaround for UploadField's and GridFields confusing the request $fields = $sourceWidget->getCMSFields(); $uploadFields = array(); $gridFields = array(); foreach ($fields as $field) { if ($field instanceof UploadField) { $uploadFields[] = $field->getName(); } else { if ($field instanceof GridField) { $gridFields[] = $field->getName(); } } } //Re-orgazine the upload field data if (count($uploadFields)) { foreach ($uploadFields as $field) { $formFieldName = 'Widget[' . $this->getName() . '][' . $objID . '][' . $field . ']'; $fieldData = array($formFieldName => array('name' => array('Uploads' => array()), 'type' => array('Uploads' => array()), 'tmp_name' => array('Uploads' => array()), 'error' => array('Uploads' => array()), 'size' => array('Uploads' => array()))); if (isset($postVars['Widget']['name'][$this->getName()][$objID][$field]['Uploads'])) { for ($i = 0; $i < count($postVars['Widget']['name'][$this->getName()][$objID][$field]['Uploads']); $i++) { $fieldData[$formFieldName]['name']['Uploads'][] = $postVars['Widget']['name'][$this->getName()][$objID][$field]['Uploads'][$i]; $fieldData[$formFieldName]['type']['Uploads'][] = $postVars['Widget']['type'][$this->getName()][$objID][$field]['Uploads'][$i]; $fieldData[$formFieldName]['tmp_name']['Uploads'][] = $postVars['Widget']['tmp_name'][$this->getName()][$objID][$field]['Uploads'][$i]; $fieldData[$formFieldName]['error']['Uploads'][] = $postVars['Widget']['error'][$this->getName()][$objID][$field]['Uploads'][$i]; $fieldData[$formFieldName]['size']['Uploads'][] = $postVars['Widget']['size'][$this->getName()][$objID][$field]['Uploads'][$i]; } } $finalPostVars = array_merge_recursive($finalPostVars, $fieldData); } } //Reorganize the gridfield data if (count($gridFields) && isset($postVars['Widget'][$this->getName()][$objID])) { foreach ($gridFields as $field) { $formFieldName = 'Widget[' . $this->getName() . '][' . $objID . '][' . $field . ']'; $fieldData = array($formFieldName => $postVars['Widget'][$this->getName()][$objID][$field]); } $finalPostVars = array_merge_recursive($finalPostVars, $fieldData); } } $headers = $request->getHeaders(); $request = new SS_HTTPRequest($_SERVER['REQUEST_METHOD'], str_replace(rtrim($baseLink, '/'), '', rtrim($request->getURL(), '/')) . '/', $request->getVars(), $finalPostVars, $request->getBody()); $request->match('$Action/$ID/$OtherID'); //Merge in the headers foreach ($headers as $header => $value) { $request->addHeader($header, $value); } return $request; }