コード例 #1
0
 public function testCmsExceptionPhp()
 {
     $theme = Theme::load('test');
     $router = new Router($theme);
     $page = $router->findByUrl('/throw-php');
     $foreignException = new \Symfony\Component\Debug\Exception\FatalErrorException('This is a general error', 100, 1, 'test.php', 20);
     $this->setProtectedProperty($foreignException, 'file', "/modules/cms/classes/CodeParser.php(165) : eval()'d code line 7");
     $exception = new CmsException($page, 300);
     $exception->setMask($foreignException);
     $this->assertEquals($page->getFilePath(), $exception->getFile());
     $this->assertEquals('PHP Content', $exception->getErrorType());
     $this->assertEquals('This is a general error', $exception->getMessage());
 }
コード例 #2
0
 /**
  * Looks up an error page using the CMS route "/error". If the route does not
  * exist, this function will use the error view found in the Cms module.
  * @return mixed Error page contents.
  */
 public function handleCustomError()
 {
     if (Config::get('app.debug', false)) {
         return null;
     }
     $theme = Theme::getActiveTheme();
     // Use the default view if no "/error" URL is found.
     $router = new Router($theme);
     if (!$router->findByUrl('/error')) {
         return View::make('cms::error');
     }
     // Route to the CMS error page.
     $controller = new Controller($theme);
     return $controller->run('/error');
 }
コード例 #3
0
ファイル: ErrorHandler.php プロジェクト: GoldBest/october
 /**
  * Looks up an error page using the CMS route "/error". If the route does not
  * exist, this function will use the error view found in the Cms module.
  * @return mixed Error page contents.
  */
 public function handleCustomError()
 {
     if (Config::get('app.debug', false)) {
         return null;
     }
     $theme = Theme::getActiveTheme();
     // Use the default view if no "/error" URL is found.
     $router = new Router($theme);
     if (!$router->findByUrl('/error')) {
         return View::make('cms::error');
     }
     // Route to the CMS error page.
     $controller = new Controller($theme);
     $result = $controller->run('/error');
     // Extract content from response object
     if ($result instanceof \Symfony\Component\HttpFoundation\Response) {
         $result = $result->getContent();
     }
     return $result;
 }
コード例 #4
0
ファイル: Index.php プロジェクト: rafasashi/sd-laravel
 public function onSave()
 {
     $this->validateRequestTheme();
     $type = Request::input('templateType');
     $templatePath = trim(Request::input('templatePath'));
     $template = $templatePath ? $this->loadTemplate($type, $templatePath) : $this->createTemplate($type);
     $settings = Request::input('settings') ?: [];
     $settings = $this->upgradeSettings($settings);
     $templateData = [];
     if ($settings) {
         $templateData['settings'] = $settings;
     }
     $fields = ['markup', 'code', 'fileName', 'content'];
     foreach ($fields as $field) {
         if (array_key_exists($field, $_POST)) {
             $templateData[$field] = Request::input($field);
         }
     }
     if (!empty($templateData['markup']) && Config::get('cms.convertLineEndings', false) === true) {
         $templateData['markup'] = $this->convertLineEndings($templateData['markup']);
     }
     if (!Request::input('templateForceSave') && $template->mtime) {
         if (Request::input('templateMtime') != $template->mtime) {
             throw new ApplicationException('mtime-mismatch');
         }
     }
     $template->fill($templateData);
     $template->save();
     /*
      * Extensibility
      */
     Event::fire('cms.template.save', [$this, $template, $type]);
     $this->fireEvent('template.save', [$template, $type]);
     Flash::success(Lang::get('cms::lang.template.saved'));
     $result = ['templatePath' => $template->fileName, 'templateMtime' => $template->mtime, 'tabTitle' => $this->getTabTitle($type, $template)];
     if ($type == 'page') {
         $result['pageUrl'] = URL::to($template->url);
         $router = new Router($this->theme);
         $router->clearCache();
         CmsCompoundObject::clearCache($this->theme);
     }
     return $result;
 }
コード例 #5
0
ファイル: RouterTest.php プロジェクト: 360weboy/october
 public function testFindPageFromSubdirectory()
 {
     $router = new Router(self::$theme);
     $page = $router->findByUrl('/apage');
     $this->assertNotEmpty($page);
     $this->assertEquals('a/a-page.htm', $page->getFileName());
     $page = $router->findByUrl('/bpage');
     $this->assertNotEmpty($page);
     $this->assertEquals('b/b-page.htm', $page->getFileName());
 }
コード例 #6
0
 public function boot()
 {
     $backendUri = Config::get('cms.backendUri');
     $requestUrl = Request::url();
     $currentHostUrl = Request::getHost();
     /*
      * Get domain to theme bindings from cache, if it's not there, load them from database,
      * save to cache and use for theme selection.
      */
     $binds = Cache::rememberForever('julius_multidomain_settings', function () {
         try {
             $cacheableRecords = Setting::generateCacheableRecords();
         } catch (\Illuminate\Database\QueryException $e) {
             if (BackendAuth::check()) {
                 Flash::error(trans('julius.multidomain:lang.flash.db-error'));
             }
             return null;
         }
         return $cacheableRecords;
     });
     /*
      * Oooops something went wrong, abort.
      */
     if ($binds === null) {
         return;
     }
     /*
      * If current request is in backend scope, do not continue
      */
     if (preg_match('/\\' . $backendUri . '/', $requestUrl)) {
         return;
     }
     /*
      * Check if this request is in backend scope and is using domain,
      * that is protected from using backend
      */
     foreach ($binds as $domain => $bind) {
         if (preg_match('/\\' . $backendUri . '/', $requestUrl) && preg_match('/' . $currentHostUrl . '/i', $domain) && $bind['is_protected']) {
             return App::abort(401, 'Unauthorized.');
         }
     }
     /*
      * Overide the rainlab pages with custom domain ones
      *
      */
     $menuItemsToOveride = [];
     foreach ($binds as $domain => $value) {
         if (isset($value['page_url'])) {
             $menuItemsToOveride[] = ['domain' => $domain, 'url' => $value['page_url'], 'type' => $value['type']];
         }
     }
     Event::listen('cms.router.beforeRoute', function () use($menuItemsToOveride, $currentHostUrl, $requestUrl) {
         $url = null;
         $type = null;
         $domain = null;
         foreach ($menuItemsToOveride as $key => $value) {
             $configuredDomain = $value['domain'];
             $currentHostUrl = Request::url();
             if ($currentHostUrl === $configuredDomain) {
                 $url = $value['url'];
                 $domain = $value['domain'];
                 $type = $value['type'];
             }
         }
         if (!is_null($url)) {
             if ($type === 'pages_plugin') {
                 return Controller::instance()->initCmsPage($url);
             } elseif ($type === 'cms_pages') {
                 $theme = Theme::getEditTheme();
                 $router = new Router(Theme::getEditTheme());
                 for ($pass = 1; $pass <= 2; $pass++) {
                     $fileName = null;
                     $urlList = [];
                     /*
                      * Find the page by URL
                      */
                     if (!$fileName) {
                         if ($router->match($url)) {
                             $fileName = $router->matchedRoute();
                         }
                     }
                     /*
                      * Return the page
                      */
                     if ($fileName) {
                         if (($page = Page::loadCached($theme, $fileName)) === null) {
                             /*
                              * If the page was not found on the disk, clear the URL cache
                              * and repeat the routing process.
                              */
                             if ($pass == 1) {
                                 continue;
                             }
                             return null;
                         }
                         return $page;
                     }
                     return null;
                 }
             }
         }
     }, 1000);
 }