예제 #1
0
 /**
  * @return \Symfony\Component\HttpFoundation\Response
  */
 public function generatePage()
 {
     // update scheduled versions
     PageVersionSchedule::checkPageVersionIds();
     $pageLoader = ['class' => PageLoader::class, 'args' => []];
     $pageBuilder = ['class' => PageBuilderInstance::class, 'args' => []];
     // try to load cms page for current request
     event(new InitializePageBuilder($pageLoader, $pageBuilder));
     PageBuilder::setClass($pageBuilder['class'], $pageBuilder['args'], $pageLoader['class'], $pageLoader['args']);
     try {
         // check for forced redirects
         $redirect = PageRedirect::uriHasRedirect();
         if (!empty($redirect) && $redirect->force == 1) {
             throw new CmsPageException('forced redirect', 0, null, redirect($redirect->to, $redirect->type));
         }
         // check for unforced redirects
         if (PageBuilder::getData('is404') && !empty($redirect)) {
             throw new CmsPageException('redirect', 0, null, redirect($redirect->to, $redirect->type));
         }
         // 404, no cms page for current request
         if (PageBuilder::getData('is404')) {
             throw new Exception('cms page not found', 404);
         }
         // 404, hidden page
         if (!PageBuilder::getData('previewVersion') && !PageBuilder::getData('isLive')) {
             throw new Exception('cms page not live', 404);
         }
         // check for form submissions
         if (!empty($_POST)) {
             $formData = PageBuilder::getData('externalTemplate') ? Request::input(config('coaster::frontend.external_form_input')) : Request::all();
             if (!empty($formData['block_id']) && empty($formData['coaster_check'])) {
                 // honeypot option
                 if (!($block = Block::find($formData['block_id']))) {
                     throw new Exception('no block handler for this form data', 500);
                 } else {
                     $pageId = !empty($formData['page_id']) ? $formData['page_id'] : 0;
                     unset($formData['_token']);
                     unset($formData['block_id']);
                     unset($formData['page_id']);
                     unset($formData['coaster_check']);
                     if ($formSubmitResponse = $block->setPageId($pageId)->setVersionId(PageBuilder::pageLiveVersionId())->getTypeObject()->submission($formData)) {
                         throw new CmsPageException('form submission response', 0, null, $formSubmitResponse);
                     }
                 }
             }
         }
         // load page with template
         $templatePath = PageBuilder::templatePath();
         event(new LoadPageTemplate($templatePath));
         if (View::exists($templatePath)) {
             $this->_setHeader('Content-Type', PageBuilder::getData('contentType'));
             $this->responseContent = View::make($templatePath)->render();
         } else {
             throw new Exception('cms page found with non existent template - ' . $templatePath, 500);
         }
         // if declared as a search page, must have search block
         if (Search::searchBlockRequired() && !Search::searchBlockExists()) {
             throw new Exception('cms page found without search function', 404);
         }
     } catch (CmsPageException $e) {
         $this->responseContent = $e->getAlternateResponse();
     } catch (Exception $e) {
         $this->_setErrorContent($e);
     }
     $response = $this->_createResponse();
     event(new LoadedPageResponse($response));
     // if response content is html, run modifications
     if (!empty($response->headers->get('content-type')) && stripos($response->headers->get('content-type'), 'html') !== false) {
         $domDocument = new DOMDocument();
         $domDocument->loadHTML($response->getContent());
         $domDocument->addMetaTag('generator', 'Coaster CMS ' . config('coaster::site.version'));
         if (config('coaster::frontend.strong_tags') == 1) {
             $keywords = explode(", ", str_replace(" and ", ", ", PageBuilder::block('meta_keywords')));
             $domDocument->addStrongTags($keywords);
         }
         // save page content
         if (PageBuilder::getData('externalTemplate')) {
             $domDocument->appendInputFieldNames(config('coaster::frontend.external_form_input'));
             $response->setContent($this->responseContent = $domDocument->saveBodyHMTL());
         } else {
             $response->setContent($domDocument->saveHTML($domDocument));
         }
     }
     return $response;
 }
예제 #2
0
 public static function processFiles(Theme $theme, $overwriteFile = true)
 {
     if (!empty($theme)) {
         $themePath = base_path('resources/views/themes/' . $theme->theme . '/templates');
         PageBuilder::setClass(ThemeBuilderInstance::class, [$overwriteFile], PageLoaderDummy::class, [$theme->theme]);
         if (is_dir($themePath)) {
             foreach (scandir($themePath) as $templateFile) {
                 if (($templateName = explode('.', $templateFile)[0]) && !is_dir($themePath . '/' . $templateFile)) {
                     PageBuilder::setData('template', $templateName);
                     View::make('themes.' . $theme->theme . '.templates.' . $templateName)->render();
                 }
             }
             if ($errors = PageBuilder::getData('errors')) {
                 echo 'Could not complete, errors found in theme:';
                 dd($errors);
             }
             self::$_selectBlocks = PageBuilder::getData('selectBlocks');
             self::$_formRules = PageBuilder::getData('formRules');
             self::$_repeaterBlocks = PageBuilder::getData('repeaterBlocks');
             self::$_blockSettings = PageBuilder::getData('blockSettings');
             self::$_fileTemplateBlocks = PageBuilder::getData('templateBlocks');
             self::$_coreTemplates = PageBuilder::getData('coreTemplates');
             self::_processDatabaseBlocks($theme->id);
             self::_processFileBlocks();
         }
     }
     if (empty(self::$_fileBlocks)) {
         throw new \Exception('no blocks found, theme or templates may not exist');
     }
 }