Author: Alexey Bobkov, Samuel Georges
Inheritance: extends Cms\Classes\Content
 /**
  * Get all pages with matching title or content.
  *
  * @return Collection
  */
 protected function pages()
 {
     $pages = Page::all()->filter(function ($page) {
         return $this->containsQuery($page->parsedMarkup) || $this->viewBagContainsQuery($page->viewBag);
     });
     return $pages;
 }
Exemplo n.º 2
0
 public function onRun()
 {
     $url = $this->getRouter()->getUrl();
     if (!strlen($url)) {
         $url = '/';
     }
     $theme = Theme::getActiveTheme();
     $router = new Router($theme);
     $page = $router->findByUrl($url);
     if ($page) {
         $tree = StaticPageClass::buildMenuTree($theme);
         $code = $startCode = $page->getBaseFileName();
         $breadcrumbs = [];
         while ($code) {
             if (!isset($tree[$code])) {
                 continue;
             }
             $pageInfo = $tree[$code];
             if ($pageInfo['navigation_hidden']) {
                 $code = $pageInfo['parent'];
                 continue;
             }
             $reference = new MenuItemReference();
             $reference->title = $pageInfo['title'];
             $reference->url = URL::to($pageInfo['url']);
             $reference->isActive = $code == $startCode;
             $breadcrumbs[] = $reference;
             $code = $pageInfo['parent'];
         }
         $breadcrumbs = array_reverse($breadcrumbs);
         $this->breadcrumbs = $this->page['breadcrumbs'] = $breadcrumbs;
     }
 }
Exemplo n.º 3
0
 public function onRun()
 {
     if ($this->property('page')) {
         //attempt to load the named static page's children
         $this->pages = Page::find($this->property('page'))->getChildren();
     } else {
         //attempt to load the current page's children
         if (isset($this->page->page->apiBag['staticPage']) && $this->page->page->apiBag['staticPage'] instanceof Page) {
             $this->pages = $this->page->page->apiBag['staticPage']->getChildren();
         } else {
             throw new \Exception('Subpages component used on non-Static Pages page without page name');
         }
     }
 }
Exemplo n.º 4
0
 /**
  * Get all Static Pages as an option array
  *
  * @return array
  */
 public static function getStaticPageOptions()
 {
     $hasPagesPlugin = PluginManager::instance()->hasPlugin('RainLab.Pages');
     if (!$hasPagesPlugin) {
         return [];
     }
     $pages = \RainLab\Pages\Classes\Page::listInTheme(Theme::getActiveTheme());
     $options = [];
     /** @var \RainLab\Pages\Classes\Page $page */
     foreach ($pages as $page) {
         if (array_key_exists('title', $page->viewBag)) {
             $options[$page->getFileName()] = $page->viewBag['title'];
         }
     }
     return $options;
 }
Exemplo n.º 5
0
 public function getPageUrlOptions()
 {
     $currentTheme = Theme::getEditTheme();
     $allThemePages = Page::listInTheme($currentTheme, true);
     $options = [];
     foreach ($allThemePages as $p) {
         $options['url=' . $p->url . '&type=cms_pages'] = $p->title;
     }
     $tree = StaticPageClass::buildMenuTree($currentTheme);
     foreach ($tree as $key => $page) {
         if (isset($page['title']) && isset($page['url'])) {
             $options['url=' . $page['url'] . '&type=pages_plugin'] = $page['title'];
         }
     }
     return $options;
 }
Exemplo n.º 6
0
 /**
  * Finds a static page by its URL.
  * @param string $url The requested URL string.
  * @return \RainLab\Pages\Classes\Page Returns \RainLab\Pages\Classes\Page object or null if the page cannot be found.
  */
 public function findByUrl($url)
 {
     $url = Str::lower(RouterHelper::normalizeUrl($url));
     if (array_key_exists($url, self::$cache)) {
         return self::$cache[$url];
     }
     $urlMap = $this->getUrlMap();
     $urlMap = array_key_exists('urls', $urlMap) ? $urlMap['urls'] : [];
     if (!array_key_exists($url, $urlMap)) {
         return null;
     }
     $fileName = $urlMap[$url];
     if (($page = Page::loadCached($this->theme, $fileName)) === null) {
         /*
          * If the page was not found on the disk, clear the URL cache
          * and try again.
          */
         $this->clearCache();
         return self::$cache[$url] = Page::loadCached($this->theme, $fileName);
     }
     return self::$cache[$url] = $page;
 }
Exemplo n.º 7
0
 public function fixValidations()
 {
     CmsPage::extend(function ($page) {
         $page->rules['url'] = ['required', 'regex:/^\\/[۰-۹آا-یa-z0-9\\/\\:_\\-\\*\\[\\]\\+\\?\\|\\.\\^\\\\$]*$/iu'];
     });
     //edit blog url validation rule
     if (PluginManager::instance()->exists('rainlab.blog')) {
         \RainLab\Blog\Models\Post::extend(function ($post) {
             $post->rules['slug'] = ['required', 'regex:/^[۰-۹آا-یa-z0-9\\/\\:_\\-\\*\\[\\]\\+\\?\\|]*$/iu', 'unique:rainlab_blog_posts'];
         });
     }
     //extending rainlab.pages
     if (PluginManager::instance()->exists('rainlab.pages')) {
         //edit rainlab page url validation rule
         \RainLab\Pages\Classes\Page::extend(function ($page) {
             $page->rules['url'] = ['required', 'regex:/^\\/[۰-۹آا-یa-z0-9\\/_\\-]*$/iu', 'uniqueUrl'];
         });
         //edit rainlab page filename in crating
         \RainLab\Pages\Classes\Page::creating(function ($page) {
             $page->fileName = \Str::ascii($page->fileName);
         }, -1);
     }
 }
 /**
  * @param null|callable $map
  * The unique param it receives id an array with page informations
  *
  * @throws \ApplicationException
  * @throws \SystemException
  */
 public function map($map = null)
 {
     $theme = \Cms\Classes\Theme::getActiveTheme();
     $pages = \Cms\Classes\Page::listInTheme($theme, true);
     if (class_exists('\\RainLab\\Pages\\Classes\\Controller')) {
         // hack RainlabPage's Controller to avoid class name collision
         $classPath = \App::pluginsPath() . '/rainlab/pages/classes/Controller.php';
         file_put_contents($classPath, str_replace('use Cms\\Classes\\Page;', 'use Cms\\Classes\\Page as BasePage;', file_get_contents($classPath)));
         file_put_contents($classPath, str_replace('new Page(', 'new BasePage(', file_get_contents($classPath)));
         // end of hack
         $pages = array_merge($pages, \RainLab\Pages\Classes\Page::listInTheme($theme, true));
     }
     foreach ($pages as $i => $page) {
         if (!isset($this->pageInfos[$page->url])) {
             $this->pageInfos[$page->url] = ['url' => $page->url, 'content' => function () use($page) {
                 return $this->getPageContents($page->url);
             }, 'pageType' => $this->getPageTypeByUrl($page->url), 'urlParameters' => $this->getDynamicParameters($page->url)];
         }
         if (is_callable($map)) {
             $map($this->pageInfos[$page->url]);
         }
     }
 }
Exemplo n.º 9
0
 /**
  * Validates the object properties.
  * Throws a ValidationException in case of an error.
  */
 protected function validate()
 {
     $pages = Page::listInTheme($this->theme, true);
     Validator::extend('uniqueUrl', function ($attribute, $value, $parameters) use($pages) {
         $value = trim(strtolower($value));
         foreach ($pages as $existingPage) {
             if ($existingPage->getBaseFileName() !== $this->getBaseFileName() && strtolower($existingPage->getViewBag()->property('url')) == $value) {
                 return false;
             }
         }
         return true;
     });
     parent::validate();
 }
Exemplo n.º 10
0
 public function onCreateObject()
 {
     $this->validateRequestTheme();
     $type = Request::input('type');
     $object = $this->createObject($type);
     $parent = Request::input('parent');
     $parentPage = null;
     if ($type == 'page' && strlen($parent)) {
         $parentPage = StaticPage::load($this->theme, $parent);
     }
     $widget = $this->makeObjectFormWidget($type, $object);
     $this->vars['objectPath'] = '';
     $result = ['tabTitle' => $this->getTabTitle($type, $object), 'tab' => $this->makePartial('form_page', ['form' => $widget, 'objectType' => $type, 'objectTheme' => $this->theme->getDirName(), 'objectMtime' => null, 'objectParent' => $parent, 'parentPage' => $parentPage])];
     return $result;
 }
Exemplo n.º 11
0
 public static function clearCache()
 {
     $theme = Theme::getEditTheme();
     $router = new Router($theme);
     $router->clearCache();
     StaticPage::clearMenuCache($theme);
     SnippetManager::clearCache($theme);
 }
Exemplo n.º 12
0
 /**
  * Returns a list of static pages in the specified theme.
  * This method is used internally by the system.
  * @param boolean $skipCache Indicates if objects should be reloaded from the disk bypassing the cache.
  * @return array Returns an array of static pages.
  */
 public function listPages($skipCache = false)
 {
     return Page::listInTheme($this->theme, $skipCache);
 }
Exemplo n.º 13
0
 /**
  * @param RedirectRule $rule
  * @return string|bool
  */
 private function redirectToStaticPage(RedirectRule $rule)
 {
     if (class_exists('\\RainLab\\Pages\\Classes\\Page')) {
         return \RainLab\Pages\Classes\Page::url($rule->getStaticPage());
     }
     return false;
 }