Пример #1
0
 public function onRun()
 {
     $theme = Theme::getActiveTheme();
     $page = Page::load($theme, $this->page->baseFileName);
     $this->page["hasBlog"] = false;
     if (!$page->hasComponent("blogPost")) {
         $this->seo_title = $this->page["seo_title"] = empty($this->page->meta_title) ? $this->page->title : $this->page->meta_title;
         $this->seo_description = $this->page["seo_description"] = $this->page->meta_description;
         $this->seo_keywords = $this->page["seo_keywords"] = $this->page->seo_keywords;
         $this->canonical_url = $this->page["canonical_url"] = $this->page->canonical_url;
         $this->redirect_url = $this->page["redirect_url"] = $this->page->redirect_url;
         $this->robot_follow = $this->page["robot_follow"] = $this->page->robot_follow;
         $this->robot_index = $this->page["robot_index"] = $this->page->robot_index;
         $settings = Settings::instance();
         if ($settings->enable_og_tags) {
             $this->ogTitle = empty($this->page->meta_title) ? $this->page->title : $this->page->meta_title;
             $this->ogDescription = $this->page->meta_description;
             $this->ogUrl = empty($this->page->canonical_url) ? Request::url() : $this->page->canonical_url;
             $this->ogSiteName = $settings->og_sitename;
             $this->ogFbAppId = $settings->og_fb_appid;
         }
     } else {
         $this->hasBlog = $this->page["hasBlog"] = true;
     }
 }
 protected function getThemeDir()
 {
     if (is_null(self::$theme)) {
         self::$theme = Theme::getActiveTheme();
     }
     return ltrim(Config::get('cms.themesPath'), '/') . '/' . self::$theme->getDirName();
 }
 public function boot()
 {
     $this->manager = PluginManager::instance();
     // Get paths we need
     $theme = Theme::getActiveTheme();
     $themePath = $theme->getPath();
     $pluginPath = dirname(__FILE__);
     $providerPath = $themePath . '/Plugin.php';
     // Load your theme's Theme.php file as a service provider
     if (File::exists($providerPath)) {
         // Use reflection to find out info about Plugin.php
         $info = new Classes\ClassInfo($providerPath);
         if (ltrim($info->extends, '\\') == "NSRosenqvist\\ThemesPlus\\Classes\\ThemesPlusBase") {
             // Activate the theme plugin
             $plugin = $this->manager->loadPlugin($info->namespace, $themePath);
             $identifier = $this->manager->getIdentifier($plugin);
             $definitionsFile = $pluginPath . '/composer/definitions.php';
             $this->manager->registerPlugin($plugin);
             $this->manager->bootPlugin($plugin);
             // See if we need to generate a new composer psr-4 definitions file
             if (Settings::get('definitions_generated_for') != $identifier || !File::exists($definitionsFile)) {
                 File::put($definitionsFile, $this->makeDefinitionFile($info->namespace, $themePath));
                 Settings::set('definitions_generated_for', $identifier);
             }
             // Add theme to autoload through our definitions file
             ComposerManager::instance()->autoload($pluginPath);
         }
     }
     // dd(\Composer\Autoload\ClassLoader::findFile('MyCompany\\MyTheme\\Classes\\Radical'));
     // dd(ComposerManager::instance());
 }
Пример #4
0
 /**
  * Handler for the pages.menuitem.getTypeInfo event.
  * Returns a menu item type information. The type information is returned as array
  * with the following elements:
  * - references - a list of the item type reference options. The options are returned in the
  *   ["key"] => "title" format for options that don't have sub-options, and in the format
  *   ["key"] => ["title"=>"Option title", "items"=>[...]] for options that have sub-options. Optional,
  *   required only if the menu item type requires references.
  * - nesting - Boolean value indicating whether the item type supports nested items. Optional,
  *   false if omitted.
  * - dynamicItems - Boolean value indicating whether the item type could generate new menu items.
  *   Optional, false if omitted.
  * - cmsPages - a list of CMS pages (objects of the Cms\Classes\Page class), if the item type requires a CMS page reference to 
  *   resolve the item URL.
  * @param string $type Specifies the menu item type
  * @return array Returns an array
  */
 public static function getMenuTypeInfo($type)
 {
     $result = [];
     if ($type == 'blog-category') {
         $references = [];
         $categories = self::orderBy('name')->get();
         foreach ($categories as $category) {
             $references[$category->id] = $category->name;
         }
         $result = ['references' => $references, 'nesting' => false, 'dynamicItems' => false];
     }
     if ($type == 'all-blog-categories') {
         $result = ['dynamicItems' => true];
     }
     if ($result) {
         $theme = Theme::getActiveTheme();
         $pages = CmsPage::listInTheme($theme, true);
         $cmsPages = [];
         foreach ($pages as $page) {
             if (!$page->hasComponent('blogPosts')) {
                 continue;
             }
             $properties = $page->getComponentProperties('blogPosts');
             if (!isset($properties['categoryFilter']) || substr($properties['categoryFilter'], 0, 1) !== ':') {
                 continue;
             }
             $cmsPages[] = $page;
         }
         $result['cmsPages'] = $cmsPages;
     }
     return $result;
 }
Пример #5
0
 public function onRun()
 {
     $url = Request::path();
     if (!strlen($url)) {
         $url = '/';
     }
     $router = new Router(Theme::getActiveTheme());
     $this->page = $this->page['page'] = $router->findByUrl($url);
     if ($this->page) {
         $this->seo_title = $this->page['seo_title'] = $this->page->getViewBag()->property('seo_title');
         $this->title = $this->page['title'] = $this->page->getViewBag()->property('title');
         $this->seo_description = $this->page['seo_description'] = $this->page->getViewBag()->property('seo_description');
         $this->seo_keywords = $this->page['seo_keywords'] = $this->page->getViewBag()->property('seo_keywords');
         $this->canonical_url = $this->page['canonical_url'] = $this->page->getViewBag()->property('canonical_url');
         $this->redirect_url = $this->page['redirect_url'] = $this->page->getViewBag()->property('redirect_url');
         $this->robot_index = $this->page['robot_index'] = $this->page->getViewBag()->property('robot_index');
         $this->robot_follow = $this->page['robot_follow'] = $this->page->getViewBag()->property('robot_follow');
         $settings = Settings::instance();
         if ($settings->enable_og_tags) {
             $this->ogTitle = empty($this->page->meta_title) ? $this->page->title : $this->page->meta_title;
             $this->ogDescription = $this->page->meta_description;
             $this->ogUrl = empty($this->page->canonical_url) ? Request::url() : $this->page->canonical_url;
             $this->ogSiteName = $settings->og_sitename;
             $this->ogFbAppId = $settings->og_fb_appid;
         }
     }
 }
Пример #6
0
 /**
  * Execute the console command.
  * @return void
  */
 public function fire()
 {
     $this->info('Initializing npm, bower and some boilerplates');
     // copiar templates
     $path_source = plugins_path('genius/elixir/assets/template/');
     $path_destination = base_path('/');
     $vars = ['{{theme}}' => Theme::getActiveTheme()->getDirName(), '{{project}}' => str_slug(BrandSettings::get('app_name'))];
     $fileSystem = new Filesystem();
     foreach ($fileSystem->allFiles($path_source) as $file) {
         if (!$fileSystem->isDirectory($path_destination . $file->getRelativePath())) {
             $fileSystem->makeDirectory($path_destination . $file->getRelativePath(), 0777, true);
         }
         $fileSystem->put($path_destination . $file->getRelativePathname(), str_replace(array_keys($vars), array_values($vars), $fileSystem->get($path_source . $file->getRelativePathname())));
     }
     $this->info('... initial setup is ok!');
     $this->info('Installing npm... this can take several minutes!');
     // instalar NPM
     system("cd '{$path_destination}' && npm install");
     $this->info('... node components is ok!');
     $this->info('Installing bower... this will no longer take as!');
     // instalar NPM
     system("cd '{$path_destination}' && bower install");
     $this->info('... bower components is ok!');
     $this->info('Now... edit the /gulpfile.js as you wish and edit your assets at/ resources directory... that\'s is!');
 }
Пример #7
0
 /**
  * Handler for the pages.menuitem.getTypeInfo event.
  * Returns a menu item type information. The type information is returned as array
  * with the following elements:
  * - references - a list of the item type reference options. The options are returned in the
  *   ["key"] => "title" format for options that don't have sub-options, and in the format
  *   ["key"] => ["title"=>"Option title", "items"=>[...]] for options that have sub-options. Optional,
  *   required only if the menu item type requires references.
  * - nesting - Boolean value indicating whether the item type supports nested items. Optional,
  *   false if omitted.
  * - dynamicItems - Boolean value indicating whether the item type could generate new menu items.
  *   Optional, false if omitted.
  * - cmsPages - a list of CMS pages (objects of the Cms\Classes\Page class), if the item type requires a CMS page reference to 
  *   resolve the item URL.
  * @param string $type Specifies the menu item type
  * @return array Returns an array
  */
 public static function getMenuTypeInfo($type)
 {
     $result = [];
     if ($type == 'blog-category') {
         $result = ['references' => self::listSubCategoryOptions(), 'nesting' => true, 'dynamicItems' => true];
     }
     if ($type == 'all-blog-categories') {
         $result = ['dynamicItems' => true];
     }
     if ($result) {
         $theme = Theme::getActiveTheme();
         $pages = CmsPage::listInTheme($theme, true);
         $cmsPages = [];
         foreach ($pages as $page) {
             if (!$page->hasComponent('blogPosts')) {
                 continue;
             }
             /*
              * Component must use a category filter with a routing parameter
              * eg: categoryFilter = "{{ :somevalue }}"
              */
             $properties = $page->getComponentProperties('blogPosts');
             if (!isset($properties['categoryFilter']) || !preg_match('/{{\\s*:/', $properties['categoryFilter'])) {
                 continue;
             }
             $cmsPages[] = $page;
         }
         $result['cmsPages'] = $cmsPages;
     }
     return $result;
 }
Пример #8
0
 /**
  * Initialize this singleton.
  */
 protected function init()
 {
     $this->theme = Theme::getActiveTheme();
     if (!$this->theme) {
         throw new CmsException(Lang::get('cms::lang.theme.active.not_found'));
     }
 }
Пример #9
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;
     }
 }
Пример #10
0
 protected function loadData()
 {
     if (!($theme = Theme::getActiveTheme())) {
         throw new ApplicationException(Lang::get('cms::lang.theme.not_found_name', ['name' => Theme::getActiveThemeCode()]));
     }
     $this->vars['theme'] = $theme;
     $this->vars['inMaintenance'] = MaintenanceSetting::get('is_enabled');
 }
Пример #11
0
 public function testApiTheme()
 {
     Event::flush('cms.activeTheme');
     Event::listen('cms.activeTheme', function () {
         return 'apitest';
     });
     $activeTheme = Theme::getActiveTheme();
     $this->assertNotNull($activeTheme);
     $this->assertEquals('apitest', $activeTheme->getDirName());
 }
Пример #12
0
 /**
  *
  * Returns an array of info about menu item type
  *
  * @param string $type item name
  * @return array
  */
 public static function getMenuTypeInfo($type)
 {
     $result = [];
     if ($type != 'all-archive-years') {
         return $result;
     }
     $result['dynamicItems'] = true;
     $theme = Theme::getActiveTheme();
     $result['cmsPages'] = CmsPage::listInTheme($theme, true);
     return $result;
 }
Пример #13
0
 /**
  * Checks for broken links in selected database fields and/or all CMS files
  * @return void
  */
 public static function processLinks()
 {
     # Let's start by truncating the BrokenLinks table
     BrokenLink::truncate();
     $brokenLinks = [];
     $settings = Settings::instance();
     foreach ($settings->modelators as $el) {
         list($modelName, $field) = explode('::', $el['modelator']);
         $models = $modelName::whereNotNull($field)->get();
         foreach ($models as $model) {
             $urls = Helper::scanForUrls($model->{$field});
             $modelParts = explode('\\', $modelName);
             foreach ($urls as $url) {
                 $status = BrokenLink::isBrokenLink($url);
                 if ($status) {
                     $brokenLinks[] = ['status' => $status, 'plugin' => $modelParts[1] . '.' . $modelParts[2], 'model' => array_pop($modelParts), 'model_id' => $model->id, 'field' => $field, 'url' => $model->{$field}];
                 }
             }
         }
     }
     /**
      * Go process the current theme
      */
     $theme = Theme::getActiveTheme();
     $theme->getPath();
     /**
      * Should we process theme pages?
      */
     if ($settings['checkCMS'] == '1') {
         foreach (File::directories($theme->getPath()) as $themeSubDir) {
             # Skip the assets folder
             if (basename($themeSubDir) == 'assets') {
                 continue;
             }
             foreach (File::allFiles($themeSubDir) as $filePath) {
                 $urls = Helper::scanForUrls(file_get_contents($filePath));
                 foreach ($urls as $url) {
                     $status = BrokenLink::isBrokenLink($url);
                     if ($status) {
                         $brokenLinks[] = ['status' => $status, 'plugin' => 'CMS', 'model' => str_replace($theme->getPath() . DIRECTORY_SEPARATOR, '', $filePath), 'url' => $url];
                     }
                 }
             }
         }
     }
     /**
      * Lets seed the BrokenLink table with any and all found links.
      */
     foreach ($brokenLinks as $brokenLink) {
         BrokenLink::create($brokenLink);
     }
     return count($brokenLinks);
 }
Пример #14
0
 public function onRun()
 {
     $url = Request::path();
     if (!strlen($url)) {
         $url = '/';
     }
     $router = new Router(Theme::getActiveTheme());
     $this->pageObject = $this->page['page'] = $router->findByUrl($url);
     if ($this->pageObject) {
         $this->title = $this->page['title'] = $this->pageObject->getViewBag()->property('title');
         $this->extraData = $this->page['extraData'] = $this->defineExtraData();
     }
 }
Пример #15
0
 public function onRun()
 {
     $url = $this->getRouter()->getUrl();
     if (!strlen($url)) {
         $url = '/';
     }
     $router = new Router(Theme::getActiveTheme());
     $this->pageObject = $this->page['page'] = $router->findByUrl($url);
     if ($this->pageObject) {
         $this->title = $this->page['title'] = array_get($this->pageObject->viewBag, 'title');
         $this->extraData = $this->page['extraData'] = $this->defineExtraData();
     }
 }
Пример #16
0
 public function registerMarkupTags()
 {
     return ['filters' => ['hash' => function ($url) {
         $file = Theme::getActiveTheme()->getPath() . '/' . $url;
         if (is_file($file)) {
             return $url . '?' . filemtime(Theme::getActiveTheme()->getPath() . '/' . $url);
         } else {
             return $url;
         }
     }], 'functions' => ['lang' => function () {
         return \RainLab\Translate\Classes\Translator::instance()->getLocale();
     }]];
 }
Пример #17
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');
 }
Пример #18
0
 public function menuItems()
 {
     if ($this->menuItems !== null) {
         return $this->menuItems;
     }
     if (!strlen($this->property('code'))) {
         return;
     }
     $theme = Theme::getActiveTheme();
     $menu = PagesMenu::loadCached($theme, $this->property('code'));
     if ($menu) {
         $this->menuItems = $menu->generateReferences($this->page);
     }
     return $this->menuItems;
 }
Пример #19
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;
 }
 public function register()
 {
     // Add gallery css to backend forms
     Event::listen('backend.form.extendFields', function ($widget) {
         $pages = ['RainLab\\Blog\\Models\\Post'];
         if (in_array(get_class($widget->model), $pages)) {
             // Add our gallery styles
             $widget->getController()->addCss('/plugins/nsrosenqvist/baguettegallery/assets/css/gallery_layouts.css');
             $theme = Theme::getActiveTheme();
             // Check if the theme has a css file that needs to be included too
             if (Filesystem::isFile($theme->getPath() . '/partials/baguetteGallery/galleries.css')) {
                 $themeDir = '/' . ltrim(Config::get('cms.themesPath'), '/') . '/' . $theme->getDirName();
                 $widget->getController()->addCss($themeDir . '/partials/baguetteGallery/galleries.css');
             }
         }
     });
 }
Пример #21
0
 /**
  * Scans the theme configuration for defined messages
  * @return void
  */
 public function scanThemeConfigForMessages()
 {
     $theme = Theme::getActiveTheme();
     $config = $theme->getConfigArray('translate');
     if (!count($config)) {
         return;
     }
     $translator = Translator::instance();
     $keys = [];
     foreach ($config as $locale => $messages) {
         $keys = array_merge($keys, array_keys($messages));
     }
     Message::importMessages($keys);
     foreach ($config as $locale => $messages) {
         Message::importMessageCodes($messages, $locale);
     }
 }
Пример #22
0
 /**
  * Execute the console command.
  * @return void
  */
 public function fire()
 {
     if (!$this->confirmToProceed('Do you really want to change the active theme?')) {
         return;
     }
     $newThemeName = $this->argument('name');
     $newTheme = Theme::load($newThemeName);
     if (!$newTheme->exists($newThemeName)) {
         return $this->error(sprintf('The theme %s does not exist.', $newThemeName));
     }
     if ($newTheme->isActiveTheme()) {
         return $this->error(sprintf('%s is already the active theme.', $newTheme->getId()));
     }
     $activeTheme = Theme::getActiveTheme();
     $from = $activeTheme ? $activeTheme->getId() : 'nothing';
     $this->info(sprintf('Switching theme from %s to %s', $from, $newTheme->getId()));
     Theme::setActiveTheme($newThemeName);
 }
Пример #23
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;
 }
Пример #24
0
 /**
  * @return bool|string
  * @throws \SystemException
  */
 public function getContent()
 {
     switch ($this->popup->content_type) {
         case 'imageUrl':
             return "<img src='{$this->popup->content_image_url}'>";
             break;
         case 'imageUpload':
             return '<img src="' . MediaLibrary::instance()->getPathUrl($this->popup->content_image_upload) . '">';
             break;
         case 'page':
             /** @var Page $page */
             $page = Page::load(Theme::getActiveTheme(), $this->popup->content_page);
             $cms = new CmsController();
             return $cms->run($page->url)->getContent();
             break;
         case 'markdown':
             return \Markdown::parse($this->popup->content_markdown);
             break;
     }
 }
Пример #25
0
 public function testTargetCmsPageRedirect()
 {
     $page = Page::load(Theme::getActiveTheme(), 'adrenth-redirect-testpage');
     if ($page === null) {
         $page = new Page();
         $page->title = 'Testpage';
         $page->url = '/adrenth/redirect/testpage';
         $page->setFileNameAttribute('adrenth-redirect-testpage');
         $page->save();
     }
     $redirect = new Redirect(['match_type' => Redirect::TYPE_EXACT, 'target_type' => Redirect::TARGET_TYPE_CMS_PAGE, 'from_url' => '/this-should-be-source', 'cms_page' => 'adrenth-redirect-testpage', 'requirements' => null, 'status_code' => 302, 'from_date' => Carbon::now(), 'to_date' => Carbon::now()->addWeek()]);
     self::assertTrue($redirect->save());
     $rule = RedirectRule::createWithModel($redirect);
     self::assertInstanceOf(RedirectRule::class, $rule);
     $manager = RedirectManager::createWithRule($rule);
     self::assertInstanceOf(RedirectManager::class, $manager);
     $result = $manager->match('/this-should-be-source');
     self::assertInstanceOf(RedirectRule::class, $result);
     self::assertEquals('http://localhost/adrenth/redirect/testpage', $manager->getLocation($result));
     self::assertTrue($page->delete());
 }
Пример #26
0
 /**
  * @param $path
  * @return string
  */
 public static function flipCss($path, $useTheme = false)
 {
     if ($path == '/modules/backend/formwidgets/richeditor/assets/css/richeditor.css') {
         return $path;
     }
     $theme_name = Theme::getActiveTheme()->getDirName();
     $customPath = $useTheme ? themes_path($theme_name . '/' . dirname($path) . '/' . File::name($path) . '.rtl.' . File::extension($path)) : static::getCustomPath($path);
     $orginalFile = $useTheme ? themes_path($theme_name . '/' . $path) : base_path($path);
     $replacePath = $useTheme ? themes_path($theme_name) : base_path();
     if (File::exists($orginalFile)) {
         if (File::exists($customPath) && File::lastModified($orginalFile) < File::lastModified($customPath)) {
             return str_replace($replacePath, '', $customPath);
         }
         File::makeDirectory(dirname($customPath), 0777, true, true);
         $flipped_css = CSSJanus::transform(File::get($orginalFile), true, true);
         //change url
         if ($useTheme === false) {
             $flipped_css = preg_replace_callback('/url\\s*\\(\\s*[\'|\\"]?([A-Za-z0-9\\.\\/\\-\\?=#_&]+)[\'|\\"]?\\)/i', function ($url) use($path) {
                 $u = str_replace('\'', '', $url[1]);
                 $u = str_replace('"', '', $u);
                 $p = dirname($path) . '/' . $u;
                 if (substr($p, 0, 1) != '/') {
                     $p = '/' . $p;
                 }
                 return 'url(\'' . $p . '\')';
             }, $flipped_css);
         }
         preg_replace_callback('/@import\\s*"([A-Za-z0-9\\.\\/\\-\\?=#_&]+)"\\s*;/i', function ($import) use($path, $useTheme) {
             $importPath = $import[1];
             if (substr($importPath, 0, 1) != '/') {
                 $importPath = dirname($path) . '/' . $importPath;
             }
             return static::flipCss($importPath, $useTheme);
         }, $flipped_css);
         File::put($customPath, $flipped_css);
         return str_replace($replacePath, '', $customPath);
     }
     return $path;
 }
Пример #27
0
 /**
  * @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]);
         }
     }
 }
Пример #28
0
 /**
  * Handler for the pages.menuitem.getTypeInfo event.
  * Returns a menu item type information. The type information is returned as array
  * with the following elements:
  * - references - a list of the item type reference options. The options are returned in the
  *   ["key"] => "title" format for options that don't have sub-options, and in the format
  *   ["key"] => ["title"=>"Option title", "items"=>[...]] for options that have sub-options. Optional,
  *   required only if the menu item type requires references.
  * - nesting - Boolean value indicating whether the item type supports nested items. Optional,
  *   false if omitted.
  * - dynamicItems - Boolean value indicating whether the item type could generate new menu items.
  *   Optional, false if omitted.
  * - cmsPages - a list of CMS pages (objects of the Cms\Classes\Page class), if the item type requires
  *   a CMS page reference to resolve the item URL.
  * @param string $type Specifies the menu item type
  * @return array Returns an array
  */
 public static function getMenuTypeInfo($type)
 {
     $result = [];
     if ($type == 'cms-page') {
         $theme = Theme::getActiveTheme();
         $pages = self::listInTheme($theme, true);
         foreach ($pages as $page) {
             $references[$page->getBaseFileName()] = $page->title . ' [' . $page->getBaseFileName() . ']';
         }
         $result = ['references' => $references, 'nesting' => false, 'dynamicItems' => false];
     }
     return $result;
 }
Пример #29
0
 /**
  * Renders a page in its entirety, including component initialization.
  * AJAX will be disabled for this process.
  * @param string $pageFile Specifies the CMS page file name to run.
  * @param array  $parameters  Routing parameters.
  * @param \Cms\Classes\Theme  $theme  Theme object
  */
 public static function render($pageFile, $parameters = [], $theme = null)
 {
     if (!$theme && !($theme = Theme::getActiveTheme())) {
         throw new CmsException(Lang::get('cms::lang.theme.active.not_found'));
     }
     $controller = new static($theme);
     $controller->getRouter()->setParameters($parameters);
     if (($page = Page::load($theme, $pageFile)) === null) {
         throw new CmsException(Lang::get('cms::lang.page.not_found_name', ['name' => $pageFile]));
     }
     return $controller->runPage($page, false);
 }
Пример #30
0
 /**
  * Get the path to the theme's partials
  *
  * @return string $path
  */
 protected static function getThemePartialsDir()
 {
     $theme = Theme::getActiveTheme();
     return $theme->getPath() . '/partials/';
 }