示例#1
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;
 }
 /**
  * @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]);
         }
     }
 }
示例#3
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();
 }
示例#4
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);
 }