Ejemplo n.º 1
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');
 }
Ejemplo n.º 2
0
 public function __construct($cmsPage = null)
 {
     if (!$cmsPage) {
         // Retrieve page instance from controller
         $cmsPage = \Cms\Classes\Controller::getController()->getPage();
     }
     $this->haircutTiles = $cmsPage->settings['haircut_tiles'];
     $this->productTiles = $cmsPage->settings['product_tiles'];
 }
Ejemplo n.º 3
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);
     $result = $controller->run('/error');
     // Extract content from response object
     if ($result instanceof \Symfony\Component\HttpFoundation\Response) {
         $result = $result->getContent();
     }
     return $result;
 }
Ejemplo n.º 4
0
 protected function playerPartialExists($name)
 {
     if (array_key_exists($name, $this->playerPartialFlags)) {
         return $this->playerPartialFlags[$name];
     }
     $controller = Controller::getController();
     if (!$controller) {
         throw new ApplicationException('Media tags can only be processed for front-end requests.');
     }
     $partial = Partial::loadCached($controller->getTheme(), $name);
     return $this->playerPartialFlags[$name] = !!$partial;
 }
Ejemplo n.º 5
0
 public function launchGreenhouse()
 {
     $controller = Controller::getController() ?: new Controller();
     if (isset($_POST['lti_message_type'])) {
         $this['messageType'] = $_POST['lti_message_type'];
         switch ($this['messageType']) {
             case "ContentItemSelectionRequest":
                 //Present text editor dialog to select a component
                 $this['return_url'] = $_POST["content_item_return_url"];
                 break;
             case "basic-lti-launch-request":
                 //load requested component
                 $this->loadComponents();
                 break;
         }
     } else {
         //return xml configuration file for LTI tool
         $this->returnXML($controller);
     }
 }
Ejemplo n.º 6
0
 /**
  * Outputs custom markup in place of the default URL. If not specified,
  * URL is output.
  *
  * @param  MenuItem $item
  *
  * @return string
  */
 public function onRender(MenuItem $item, Controller $controller, array $settings, $depth = 0, $url, $child_count = 0)
 {
     $theme = Theme::getEditTheme();
     return $controller->renderPartial($item->master_object_id, ['item' => $item, 'settings' => $settings, 'depth' => $depth, 'url' => $url, 'child_count' => $child_count, 'before_item' => sprintf($settings['before_item'], $item->id, $item->id_attrib, $item->getClassAttrib($settings, $depth), $item->title_attrib), 'after_item' => sprintf($settings['after_item'], $item->id, $item->id_attrib, $item->getClassAttrib($settings, $depth), $item->title_attrib)]);
 }
Ejemplo n.º 7
0
 public function boot()
 {
     Event::listen('cms.router.beforeRoute', function ($url) {
         return Controller::instance()->initCmsPage($url);
     });
     Event::listen('cms.page.beforeRenderPage', function ($controller, $page) {
         /*
          * Before twig renders
          */
         $twig = $controller->getTwig();
         $loader = $controller->getLoader();
         Controller::instance()->injectPageTwig($page, $loader, $twig);
         /*
          * Get rendered content
          */
         $contents = Controller::instance()->getPageContents($page);
         if (strlen($contents)) {
             return $contents;
         }
     });
     Event::listen('cms.page.initComponents', function ($controller, $page) {
         Controller::instance()->initPageComponents($controller, $page);
     });
     Event::listen('cms.block.render', function ($blockName, $blockContents) {
         $page = CmsController::getController()->getPage();
         if (!isset($page->apiBag['staticPage'])) {
             return;
         }
         $contents = Controller::instance()->getPlaceholderContents($page, $blockName, $blockContents);
         if (strlen($contents)) {
             return $contents;
         }
     });
     Event::listen('pages.menuitem.listTypes', function () {
         return ['static-page' => 'rainlab.pages::lang.menuitem.static_page', 'all-static-pages' => 'rainlab.pages::lang.menuitem.all_static_pages'];
     });
     Event::listen('pages.menuitem.getTypeInfo', function ($type) {
         if ($type == 'url') {
             return [];
         }
         if ($type == 'static-page' || $type == 'all-static-pages') {
             return StaticPage::getMenuTypeInfo($type);
         }
     });
     Event::listen('pages.menuitem.resolveItem', function ($type, $item, $url, $theme) {
         if ($type == 'static-page' || $type == 'all-static-pages') {
             return StaticPage::resolveMenuItem($item, $url, $theme);
         }
     });
     Event::listen('backend.form.extendFieldsBefore', function ($formWidget) {
         if ($formWidget->model instanceof \Cms\Classes\Partial) {
             Snippet::extendPartialForm($formWidget);
         }
     });
     Event::listen('cms.template.save', function ($controller, $template, $type) {
         Plugin::clearCache();
     });
     Event::listen('cms.template.processSettingsBeforeSave', function ($controller, $dataHolder) {
         $dataHolder->settings = Snippet::processTemplateSettingsArray($dataHolder->settings);
     });
     Event::listen('cms.template.processSettingsAfterLoad', function ($controller, $template) {
         Snippet::processTemplateSettings($template);
     });
     Event::listen('cms.template.processTwigContent', function ($template, $dataHolder) {
         if ($template instanceof \Cms\Classes\Layout) {
             $dataHolder->content = Controller::instance()->parseSyntaxFields($dataHolder->content);
         }
     });
     Event::listen('backend.richeditor.listTypes', function () {
         return ['static-page' => 'rainlab.pages::lang.menuitem.static_page'];
     });
     Event::listen('backend.richeditor.getTypeInfo', function ($type) {
         if ($type === 'static-page') {
             return StaticPage::getRichEditorTypeInfo($type);
         }
     });
 }
Ejemplo n.º 8
0
 protected function makeUrl()
 {
     $controller = Controller::getController() ?: new Controller();
     return $controller->pageUrl($this->getUrlPageName(), $this->getUrlParams());
 }
Ejemplo n.º 9
0
    public function testComponentWithOnRender()
    {
        $theme = Theme::load('test');
        $controller = new Controller($theme);
        $response = $controller->run('/component-custom-render')->getContent();
        $content = <<<ESC
Pass
Custom output: Would you look over Picasso's shoulder
Custom output: And tell him about his brush strokes?
ESC;
        $this->assertEquals($content, $response);
    }
Ejemplo n.º 10
0
 /**
  * Parses the static page markup and renders snippets defined on the page.
  * @param string $pageName Specifies the static page file name (the name of the corresponding content block file).
  * @param \Cms\Classes\Theme $theme Specifies a parent theme.
  * @param string $markup Specifies the markup string to process.
  * @return string Returns the processed string.
  */
 public static function processPageMarkup($pageName, $theme, $markup)
 {
     $map = self::extractSnippetsFromMarkupCached($theme, $pageName, $markup);
     $controller = CmsController::getController();
     $partialSnippetMap = SnippetManager::instance()->getPartialSnippetMap($theme);
     $controller = CmsController::getController();
     foreach ($map as $snippetDeclaration => $snippetInfo) {
         $snippetCode = $snippetInfo['code'];
         if (!isset($snippetInfo['component'])) {
             if (!array_key_exists($snippetCode, $partialSnippetMap)) {
                 throw new ApplicationException(sprintf('Partial for the snippet %s is not found', $snippetCode));
             }
             $partialName = $partialSnippetMap[$snippetCode];
             $generatedMarkup = $controller->renderPartial($partialName, $snippetInfo['properties']);
         } else {
             $generatedMarkup = $controller->renderComponent($snippetCode);
         }
         $pattern = preg_quote($snippetDeclaration);
         $markup = mb_ereg_replace($pattern, $generatedMarkup, $markup);
     }
     return $markup;
 }
Ejemplo n.º 11
0
 public function testThemeUrl()
 {
     $theme = Theme::load('test');
     $controller = new Controller($theme);
     $url = $controller->themeUrl();
     $this->assertEquals('http://localhost/themes/test', $url);
     $url = $controller->themeUrl('foo/bar.css');
     $this->assertEquals('http://localhost/themes/test/foo/bar.css', $url);
     //
     // These tests seem to bear different results
     //
     // $url = $controller->themeUrl(['assets/css/style1.css', 'assets/css/style2.css']);
     // $url = substr($url, 0, strpos($url, '-'));
     // $this->assertEquals('/combine/88634b8fa6f4f6442ce830d38296640a', $url);
     // $url = $controller->themeUrl(['assets/js/script1.js', 'assets/js/script2.js']);
     // $url = substr($url, 0, strpos($url, '-'));
     // $this->assertEquals('/combine/860afc990164a60a8e90682d04da27ee', $url);
 }
Ejemplo n.º 12
0
 /**
  * {@inheritDoc}
  */
 public function getReceiptUrl()
 {
     if ($this->return_page) {
         $controller = Controller::getController() ?: new Controller();
         return $controller->pageUrl($this->return_page, $this->getUrlParams());
     }
     return $this->getUrlAttribute();
 }
Ejemplo n.º 13
0
 /**
  * Set current object url.
  *
  * @param  string      $pageName
  * @param  Controller  $controller
  * @param  array       $query
  * @return  string
  */
 public function setUrl($pageName, Controller $controller, $query = null)
 {
     $params = ['topic_id' => $this->id . '-' . Str::slug($this->name)];
     $this->url = $controller->pageUrl($pageName, $params, false);
     if ($query) {
         $this->url .= '?' . http_build_query($query);
     }
     return $this->url;
 }
Ejemplo n.º 14
0
 protected function getPageContent($page)
 {
     $theme = Theme::getEditTheme();
     $result = CmsController::render($page, ['code' => LARAVEL_START], $theme);
     return $result;
 }
Ejemplo n.º 15
0
 /**
  * Set current object url.
  *
  * @param  string      $pageName
  * @param  Controller  $controller
  */
 public function setUrl($pageName, Controller $controller)
 {
     $params = ['event_id' => $this->id . '-' . Str::slug($this->name)];
     return $this->url = $controller->pageUrl($pageName, $params);
 }
Ejemplo n.º 16
0
 /**
  * Helper that makes a URL for a page in the active theme.
  * @return string
  */
 public static function url($page, $params = [], $absolute = true)
 {
     $controller = new Controller();
     return $controller->pageUrl($page, $params, true, $absolute);
 }
Ejemplo n.º 17
0
 public function testThemeUrl()
 {
     $theme = new Theme();
     $theme->load('test');
     $controller = new Controller($theme);
     $url = $controller->themeUrl();
     $this->assertEquals('/tests/fixtures/cms/themes/test', $url);
     $url = $controller->themeUrl('foo/bar.css');
     $this->assertEquals('/tests/fixtures/cms/themes/test/foo/bar.css', $url);
     $url = $controller->themeUrl(['assets/css/style1.css', 'assets/css/style2.css']);
     $url = substr($url, 0, strpos($url, '-'));
     $this->assertEquals('/combine/88634b8fa6f4f6442ce830d38296640a', $url);
     $url = $controller->themeUrl(['assets/js/script1.js', 'assets/js/script2.js']);
     $url = substr($url, 0, strpos($url, '-'));
     $this->assertEquals('/combine/860afc990164a60a8e90682d04da27ee', $url);
 }
Ejemplo n.º 18
0
 public function testComponentAjax()
 {
     App::instance('request', $this->configAjaxRequestMock('testArchive::onTestAjax', 'ajax-result'));
     $theme = new Theme();
     $theme->load('test');
     $controller = new Controller($theme);
     $response = $controller->run('/with-component');
     $this->assertInstanceOf('Symfony\\Component\\HttpFoundation\\Response', $response);
     $content = $response->getOriginalContent();
     $this->assertInternalType('array', $content);
     $this->assertEquals(200, $response->getStatusCode());
     $this->assertCount(1, $content);
     $this->assertArrayHasKey('ajax-result', $content);
     $this->assertEquals('page', $content['ajax-result']);
 }
Ejemplo n.º 19
0
 /**
  * @param RedirectRule $rule
  * @return string
  */
 private function redirectToCmsPage(RedirectRule $rule)
 {
     $controller = new Controller(Theme::getActiveTheme());
     $parameters = [];
     // Strip curly braces from keys
     foreach ($rule->getPlaceholderMatches() as $placeholder => $value) {
         $parameters[str_replace(['{', '}'], '', $placeholder)] = $value;
     }
     return $controller->pageUrl($rule->getCmsPage(), $parameters);
 }
Ejemplo n.º 20
0
 /**
  * Helper that makes a URL for a page in the active theme.
  * @param mixed $page Specifies the Cms Page file name.
  * @return string
  */
 public static function url($page, $params = [], $absolute = true)
 {
     /*
      * Reuse existing controller or create a new one,
      * assuming that the method is called not during the front-end
      * request processing.
      */
     $controller = Controller::getController();
     if (!$controller) {
         $controller = new Controller();
     }
     return $controller->pageUrl($page, $params, true, $absolute);
 }
Ejemplo n.º 21
0
 /**
  * Helper that makes a URL for a page in the active theme.
  * @return string
  */
 public static function url($page, $params = [])
 {
     $controller = new Controller();
     return $controller->pageUrl($page, $params);
 }
Ejemplo n.º 22
0
 /**
  * Handler for the pages.menuitem.resolveItem event.
  * Returns information about a menu item. The result is an array
  * with the following keys:
  * - url - the menu item URL. Not required for menu item types that return all available records.
  *   The URL should be returned relative to the website root and include the subdirectory, if any.
  *   Use the URL::to() helper to generate the URLs.
  * - isActive - determines whether the menu item is active. Not required for menu item types that 
  *   return all available records.
  * - items - an array of arrays with the same keys (url, isActive, items) + the title key. 
  *   The items array should be added only if the $item's $nesting property value is TRUE.
  * @param \RainLab\Pages\Classes\MenuItem $item Specifies the menu item.
  * @param \Cms\Classes\Theme $theme Specifies the current theme.
  * @param string $url Specifies the current page URL, normalized, in lower case
  * The URL is specified relative to the website root, it includes the subdirectory name, if any.
  * @return mixed Returns an array. Returns null if the item cannot be resolved.
  */
 public static function resolveMenuItem($item, $url, $theme)
 {
     $result = null;
     if ($item->type == 'cms-page') {
         if (!$item->reference) {
             return;
         }
         $page = self::loadCached($theme, $item->reference);
         $controller = Controller::getController() ?: new Controller();
         $pageUrl = $controller->pageUrl($item->reference, [], false);
         $result = [];
         $result['url'] = $pageUrl;
         $result['isActive'] = $pageUrl == $url;
         $result['mtime'] = $page ? $page->mtime : null;
     }
     return $result;
 }
Ejemplo n.º 23
0
 /**
  * Helper that makes a URL for a page in the active theme.
  * @param mixed $page Specifies the Cms Page file name.
  * @param array $params Route parameters to consider in the URL.
  * @return string
  */
 public static function url($page, $params = [], $absolute = true)
 {
     /* @deprecated remove if year >= 2016 -- remove 3rd argument */
     if ($absolute !== true) {
         traceLog('Deprecated warning: Third argument of Page::url() has no affect, consider removing it.');
     }
     /*
      * Reuse existing controller or create a new one,
      * assuming that the method is called not during the front-end
      * request processing.
      */
     $controller = Controller::getController();
     if (!$controller) {
         $controller = new Controller();
     }
     return $controller->pageUrl($page, $params, true);
 }