/** * The endpoint for file uploads. Hands off to Dropzone module * * @param SS_HTTPRequest $r * @return SS_HTTPResponse */ public function handleUpload(SS_HTTPRequest $r) { $r->setUrl('upload'); $folder = Folder::get()->byID($r->param('FolderID')); $uploader = FileAttachmentField::create('dummy'); if ($folder) { $uploader->setFolderName(self::remove_assets_dir($folder->Filename)); } else { $uploader->setFolderName('/'); } $httpResponse = $uploader->handleRequest($r, DataModel::inst()); if ($httpResponse->getStatusCode() !== 200) { return $httpResponse; } $ids = $httpResponse->getBody(); $files = File::get()->byIDs(explode(',', $ids)); $response = array(); foreach ($files as $f) { $response[] = $this->createFileJSON($f, $folder); } return (new SS_HTTPResponse(Convert::array2json($response)))->addHeader('Content-Type', 'application/json'); }
public function handleRequest(SS_HTTPRequest $request, DataModel $model = null) { self::$is_at_root = true; $this->setDataModel($model); $this->pushCurrent(); $this->init(); if ($language = $request->param('Language')) { if (Config::inst()->get('MultilingualRootURLController', 'UseLocaleURL')) { if (Config::inst()->get('MultilingualRootURLController', 'UseDashLocale')) { //Language is missing a dash 404 if (strpos($language, '-') === false) { //Locale not found 404 if ($response = ErrorPage::response_for(404)) { return $response; } else { $this->httpError(404, 'The requested page could not be found.'); } return $this->response; } $locale = explode('-', $language); $locale[1] = strtoupper($locale[1]); //Make sure that the language is all lowercase if ($language == implode('-', $locale)) { //Locale not found 404 if ($response = ErrorPage::response_for(404)) { return $response; } else { $this->httpError(404, 'The requested page could not be found.'); } return $this->response; } $locale = implode('_', $locale); } else { $locale = $language; } } else { if (strpos($request->param('Language'), '_') !== false) { //Locale not found 404 if ($response = ErrorPage::response_for(404)) { return $response; } else { $this->httpError(404, 'The requested page could not be found.'); } return $this->response; } else { $locale = i18n::get_locale_from_lang($language); } } if (in_array($locale, Translatable::get_allowed_locales())) { Cookie::set('language', $language); Translatable::set_current_locale($locale); i18n::set_locale($locale); if (!DB::isActive() || !ClassInfo::hasTable('SiteTree')) { $this->response = new SS_HTTPResponse(); $this->response->redirect(Director::absoluteBaseURL() . 'dev/build?returnURL=' . (isset($_GET['url']) ? urlencode($_GET['url']) : null)); return $this->response; } $request->setUrl($language . '/' . self::get_homepage_link() . '/'); $request->match('$Language/$URLSegment//$Action', true); $controller = new MultilingualModelAsController(); $result = $controller->handleRequest($request, $model); $this->popCurrent(); return $result; } else { //URL Param Locale is not allowed so redirect to default $this->redirect(Controller::join_links(Director::baseURL(), Config::inst()->get('MultilingualRootURLController', 'UseLocaleURL') ? Translatable::default_locale() : Translatable::default_lang()) . '/', 301); $this->popCurrent(); return $this->response; } } //No Locale Param so detect browser language and redirect if ($locale = self::detect_browser_locale()) { if (Config::inst()->get('MultilingualRootURLController', 'UseLocaleURL')) { if (Config::inst()->get('MultilingualRootURLController', 'UseDashLocale')) { $language = str_replace('_', '-', strtolower($locale)); } else { $language = $locale; } } else { $language = i18n::get_lang_from_locale($locale); } Cookie::set('language', $language); $this->redirect(Controller::join_links(Director::baseURL(), $language) . '/', 301); $this->popCurrent(); return $this->response; } if (Config::inst()->get('MultilingualRootURLController', 'UseLocaleURL')) { if (Config::inst()->get('MultilingualRootURLController', 'UseDashLocale')) { $language = str_replace('_', '-', strtolower(Translatable::default_locale())); } else { $language = Translatable::default_locale(); } } else { $language = Translatable::default_lang(); } $this->redirect(Controller::join_links(Director::baseURL(), $language . '/'), 301); $this->popCurrent(); return $this->response; }
/** * Hand off presentation CRUD to a sub controller. Ensure the user * can write to the presentation first * @param $r SS_HTTPRequest * @return RequestHandler */ public function handleManage(SS_HTTPRequest $r) { $summit = $this->Summit(); if (is_null($summit) || !$summit->exists() || !$this->presentation_manager->isPresentationEditionAllowed(Member::currentUser(), $summit)) { $r->setUrl($this->Link()); //clean up dir parts so we could redirect without 404 return $this->redirect($this->Link(), 301); } $presentation_id = Convert::raw2sql($r->param('PresentationID')); $presentation = $presentation_id === 'new' ? Presentation::create() : Presentation::get()->byID($presentation_id); if (!$presentation) { return $this->httpError(404); } if ($presentation->isInDB() && !$this->canEditPresentation($presentation->ID)) { return $this->httpError(403, "You can't edit this presentation"); } if (!$presentation->isInDB() && !$presentation->canCreate()) { return $this->httpError(403); } $request = PresentationPage_ManageRequest::create($presentation, $this); return $request->handleRequest($r, DataModel::inst()); }
/** * @param SS_HTTPRequest $request * @param DataModel|null $model * @return SS_HTTPResponse */ public function handleRequest(SS_HTTPRequest $request, DataModel $model = null) { self::$is_at_root = true; $this->setDataModel($model); $this->pushCurrent(); $this->init(); if (!DB::is_active() || !ClassInfo::hasTable('SiteTree')) { $this->response = new SS_HTTPResponse(); $this->response->redirect(Director::absoluteBaseURL() . 'dev/build?returnURL=' . (isset($_GET['url']) ? urlencode($_GET['url']) : null)); return $this->response; } $request->setUrl(self::get_homepage_link() . '/'); $request->match('$URLSegment//$Action', true); $controller = new ModelAsController(); $result = $controller->handleRequest($request, $model); $this->popCurrent(); return $result; }