/** * Get the file component from the request * * @param HTTPRequest $request * @return string */ protected function parseFilename(HTTPRequest $request) { $filename = ''; $next = $request->param('Filename'); while ($next) { $filename = $filename ? File::join_paths($filename, $next) : $next; $next = $request->shift(); } if ($extension = $request->getExtension()) { $filename = $filename . "." . $extension; } return $filename; }
/** * @param HTTPRequest $request */ public function runTask($request) { $name = $request->param('TaskName'); $tasks = $this->getTasks(); $title = function ($content) { printf(Director::is_cli() ? "%s\n\n" : '<h1>%s</h1>', $content); }; $message = function ($content) { printf(Director::is_cli() ? "%s\n" : '<p>%s</p>', $content); }; foreach ($tasks as $task) { if ($task['segment'] == $name) { $inst = Injector::inst()->create($task['class']); $title(sprintf('Running Task %s', $inst->getTitle())); if (!$inst->isEnabled()) { $message('The task is disabled'); return; } $inst->run($request); return; } } $message(sprintf('The build task "%s" could not be found', Convert::raw2xml($name))); }
/** * Handle a field request. * Uses {@link Form->dataFieldByName()} to find a matching field, * and falls back to {@link FieldList->fieldByName()} to look * for tabs instead. This means that if you have a tab and a * formfield with the same name, this method gives priority * to the formfield. * * @param HTTPRequest $request * @return FormField */ public function handleField($request) { $field = $this->Fields()->dataFieldByName($request->param('FieldName')); if ($field) { return $field; } else { // falling back to fieldByName, e.g. for getting tabs return $this->Fields()->fieldByName($request->param('FieldName')); } }
public function runRegisteredController(HTTPRequest $request) { $controllerClass = null; $baseUrlPart = $request->param('Action'); $reg = Config::inst()->get(__CLASS__, 'registered_controllers'); if (isset($reg[$baseUrlPart])) { $controllerClass = $reg[$baseUrlPart]['controller']; } if ($controllerClass && class_exists($controllerClass)) { return $controllerClass::create(); } $msg = 'Error: no controller registered in ' . __CLASS__ . ' for: ' . $request->param('Action'); if (Director::is_cli()) { // in CLI we cant use httpError because of a bug with stuff being in the output already, see DevAdminControllerTest throw new Exception($msg); } else { $this->httpError(500, $msg); } }
/** * @param HTTPRequest $request * @return UploadField_ItemHandler */ public function handleItem(HTTPRequest $request) { return $this->getItemHandler($request->param('ID')); }
/** * @param HTTPRequest $request * @return HTTPResponse * @throws HTTPResponse_Exception */ public function show($request) { // TODO Necessary for TableListField URLs to work properly if ($request->param('ID')) { $this->setCurrentPageID($request->param('ID')); } return $this->getResponseNegotiator()->respond($request); }
/** * Show the "password sent" page, after a user has requested * to reset their password. * * @param HTTPRequest $request The HTTPRequest for this action. * @return string Returns the "password sent" page as HTML code. */ public function passwordsent($request) { $controller = $this->getResponseController(_t('Security.LOSTPASSWORDHEADER', 'Lost Password')); // if the controller calls Director::redirect(), this will break early if (($response = $controller->getResponse()) && $response->isFinished()) { return $response; } $email = Convert::raw2xml(rawurldecode($request->param('ID')) . '.' . $request->getExtension()); $customisedController = $controller->customise(array('Title' => _t('Security.PASSWORDSENTHEADER', "Password reset link sent to '{email}'", array('email' => $email)), 'Content' => "<p>" . _t('Security.PASSWORDSENTTEXT', "Thank you! A reset link has been sent to '{email}', provided an account exists for this email" . " address.", array('email' => $email)) . "</p>", 'Email' => $email)); //Controller::$currentController = $controller; return $customisedController->renderWith($this->getTemplatesFor('passwordsent')); }
/** * Url handler for edit form * * @param HTTPRequest $request * @return Form */ public function DetailEditForm($request) { // Get ID either from posted back value, or url parameter $id = $request->param('ID') ?: $request->postVar('ID'); return $this->getDetailEditForm($id); }
/** * Check if this action has a confirmation step * * @param HTTPRequest $request * @return HTTPResponse */ public function handleConfirmation($request) { // Find the action handler $action = $request->param('BatchAction'); $actionHandler = $this->actionByName($action); // Sanitise ID list and query the database for apges $csvIDs = $request->requestVar('csvIDs'); $ids = $this->cleanIDs($csvIDs); // Check dialog if ($actionHandler->hasMethod('confirmationDialog')) { $response = new HTTPResponse(json_encode($actionHandler->confirmationDialog($ids))); } else { $response = new HTTPResponse(json_encode(array('alert' => false))); } $response->addHeader("Content-type", "application/json"); return $response; }
/** * * @param GridField $gridField * @param HTTPRequest $request * @return GridFieldDetailForm_ItemRequest */ public function handleItem($gridField, $request) { // Our getController could either give us a true Controller, if this is the top-level GridField. // It could also give us a RequestHandler in the form of GridFieldDetailForm_ItemRequest if this is a // nested GridField. $requestHandler = $gridField->getForm()->getController(); /** @var DataObject $record */ if (is_numeric($request->param('ID'))) { $record = $gridField->getList()->byID($request->param("ID")); } else { $record = Object::create($gridField->getModelClass()); } $handler = $this->getItemRequestHandler($gridField, $record, $requestHandler); // if no validator has been set on the GridField and the record has a // CMS validator, use that. if (!$this->getValidator() && (method_exists($record, 'getCMSValidator') || $record instanceof Object && $record->hasMethod('getCMSValidator'))) { $this->setValidator($record->getCMSValidator()); } return $handler->handleRequest($request, DataModel::inst()); }
/** * Url handler for add to campaign form * * @param HTTPRequest $request * @return Form */ public function addToCampaignForm($request) { // Get ID either from posted back value, or url parameter $id = $request->param('ID') ?: $request->postVar('ID'); return $this->getAddToCampaignForm($id); }