/**
  * Returns the list of objects in the specified theme.
  * This method is used internally by the system.
  * @param \Cms\Classes\Theme $theme Specifies a parent theme.
  * @param boolean $skipCache Indicates if objects should be reloaded from the disk bypassing the cache.
  * @return array Returns an array of CMS objects.
  */
 public static function listInTheme($theme, $skipCache = false)
 {
     if (!$theme) {
         throw new ApplicationException(Lang::get('cms::lang.theme.active.not_set'));
     }
     $dirPath = $theme->getPath() . '/' . static::getObjectTypeDirName();
     $result = [];
     if (!File::isDirectory($dirPath)) {
         return $result;
     }
     $it = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($dirPath));
     $it->setMaxDepth(1);
     // Support only a single level of subdirectories
     $it->rewind();
     while ($it->valid()) {
         if ($it->isFile() && in_array($it->getExtension(), static::$allowedExtensions)) {
             $filePath = $it->getBasename();
             if ($it->getDepth() > 0) {
                 $filePath = basename($it->getPath()) . '/' . $filePath;
             }
             $page = $skipCache ? static::load($theme, $filePath) : static::loadCached($theme, $filePath);
             $result[] = $page;
         }
         $it->next();
     }
     return $result;
 }
Exemplo n.º 2
0
 public function testCmsExceptionPhp()
 {
     $theme = new 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');
     $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->getFullPath(), $exception->getFile());
     $this->assertEquals('PHP Content', $exception->getErrorType());
     $this->assertEquals('This is a general error', $exception->getMessage());
 }
 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());
 }
Exemplo n.º 4
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();
 }
 /**
  * Returns all fields defined for this model, based on form field definitions.
  */
 public function getFormFields()
 {
     if (!($theme = CmsTheme::load($this->theme))) {
         throw new Exception(Lang::get('Unable to find theme with name :name', $this->theme));
     }
     return $theme->getConfigValue('form.fields', []) + $theme->getConfigValue('form.tabs.fields', []) + $theme->getConfigValue('form.secondaryTabs.fields', []);
 }
Exemplo n.º 7
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!');
 }
Exemplo n.º 8
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.º 9
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;
         }
     }
 }
Exemplo n.º 10
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'));
     }
 }
Exemplo n.º 11
0
 /**
  * Constructor.
  */
 public function __construct()
 {
     parent::__construct();
     BackendMenu::setContext('October.Cms', 'cms', true);
     try {
         if (!($theme = Theme::getEditTheme())) {
             throw new ApplicationException(Lang::get('cms::lang.theme.edit.not_found'));
         }
         $this->theme = $theme;
         new TemplateList($this, 'pageList', function () use($theme) {
             return Page::listInTheme($theme, true);
         });
         new TemplateList($this, 'partialList', function () use($theme) {
             return Partial::listInTheme($theme, true);
         });
         new TemplateList($this, 'layoutList', function () use($theme) {
             return Layout::listInTheme($theme, true);
         });
         new TemplateList($this, 'contentList', function () use($theme) {
             return Content::listInTheme($theme, true);
         });
         new ComponentList($this, 'componentList');
         new AssetList($this, 'assetList');
     } catch (Exception $ex) {
         $this->handleError($ex);
     }
 }
Exemplo n.º 12
0
 /**
  * Initialize.
  *
  * @return void
  * @throws \Krisawzm\DemoManager\Classes\DemoManagerException
  */
 protected function init()
 {
     $backendUser = BackendAuth::getUser();
     $baseTheme = $this->theme = Config::get('krisawzm.demomanager::base_theme', null);
     if ($backendUser) {
         if ($backendUser->login == Config::get('krisawzm.demomanager::admin.login', 'admin')) {
             $this->theme = $baseTheme;
         } else {
             $this->theme = $backendUser->login;
         }
     } else {
         if (UserCounter::instance()->limit()) {
             $action = Config::get('krisawzm.demomanager::limit_action', 'reset');
             if ($action == 'reset') {
                 DemoManager::instance()->resetEverything();
                 // @todo queue/async?
                 $this->theme = $this->newDemoUser()->login;
             } elseif ($action == 'maintenance') {
                 $theme = Theme::load($baseTheme);
                 Event::listen('cms.page.beforeDisplay', function ($controller, $url, $page) use($theme) {
                     return Page::loadCached($theme, 'maintenance');
                 });
             } elseif ($action == 'nothing') {
                 $this->theme = $baseTheme;
             } else {
                 throw new DemoManagerException('User limit is reached, but an invalid action is defined.');
             }
         } else {
             $this->theme = $this->newDemoUser()->login;
             // @todo Remember the username after signing out.
             //       Could prove useful as some plugins may
             //       have some different offline views.
         }
     }
 }
Exemplo n.º 13
0
 /**
  * Constructor.
  */
 public function __construct()
 {
     parent::__construct();
     BackendMenu::setContext('RainLab.Pages', 'pages', 'pages');
     try {
         if (!($this->theme = Theme::getEditTheme())) {
             throw new ApplicationException(Lang::get('cms::lang.theme.edit.not_found'));
         }
         new PageList($this, 'pageList');
         new MenuList($this, 'menuList');
         new SnippetList($this, 'snippetList');
         $theme = $this->theme;
         new TemplateList($this, 'contentList', function () use($theme) {
             return Content::listInTheme($theme, true);
         });
     } catch (Exception $ex) {
         $this->handleError($ex);
     }
     $this->addJs('/modules/backend/assets/js/october.treeview.js', 'core');
     $this->addJs('/plugins/rainlab/pages/assets/js/pages-page.js');
     $this->addJs('/plugins/rainlab/pages/assets/js/pages-snippets.js');
     $this->addCss('/plugins/rainlab/pages/assets/css/pages.css');
     // Preload the code editor class as it could be needed
     // before it loads dynamically.
     $this->addJs('/modules/backend/formwidgets/codeeditor/assets/js/codeeditor.js', 'core');
     $this->bodyClass = 'compact-container side-panel-not-fixed';
     $this->pageTitle = 'rainlab.pages::lang.plugin.name';
     $this->pageTitleTemplate = '%s Pages';
 }
Exemplo n.º 14
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;
 }
Exemplo n.º 15
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;
 }
 /**
  * Completely delete a theme from the system.
  * @param string $id Theme code/namespace
  * @return void
  */
 public function deleteTheme($theme)
 {
     if (!$theme) {
         return false;
     }
     if (is_string($theme)) {
         $theme = CmsTheme::load($theme);
     }
     if ($theme->isActiveTheme()) {
         throw new ApplicationException(trans('cms::lang.theme.delete_active_theme_failed'));
     }
     /*
      * Delete from file system
      */
     $themePath = $theme->getPath();
     if (File::isDirectory($themePath)) {
         File::deleteDirectory($themePath);
     }
     /*
      * Set uninstalled
      */
     if ($themeCode = $this->findByDirName($theme->getDirName())) {
         $this->setUninstalled($themeCode);
     }
 }
Exemplo n.º 17
0
 public function testHtmlContent()
 {
     $theme = Theme::load('test');
     $content = Content::load($theme, 'html-content.htm');
     $this->assertEquals('<a href="#">Stephen Saucier</a> changed his profile picture &mdash; <small>7 hrs ago</small></div>', $content->markup);
     $this->assertEquals('<a href="#">Stephen Saucier</a> changed his profile picture &mdash; <small>7 hrs ago</small></div>', $content->parsedMarkup);
 }
Exemplo n.º 18
0
 public function __construct($controller, $alias)
 {
     $this->alias = $alias;
     $this->theme = Theme::getEditTheme();
     $this->dataIdPrefix = 'page-' . $this->theme->getDirName();
     parent::__construct($controller, []);
     $this->bindToController();
 }
Exemplo n.º 19
0
 /**
  * Restore the CMS page found in the mapping array, or disable the
  * maintenance mode.
  * @return void
  */
 public function afterFetch()
 {
     if (($theme = Theme::getEditTheme()) && ($themeMap = array_get($this->attributes, 'theme_map')) && ($cmsPage = array_get($themeMap, $theme->getDirName()))) {
         $this->cms_page = $cmsPage;
     } else {
         $this->is_enabled = false;
     }
 }
Exemplo n.º 20
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');
 }
 public function __construct($controller, $alias)
 {
     $this->alias = $alias;
     $this->theme = Theme::getEditTheme();
     parent::__construct($controller, []);
     $this->bindToController();
     $this->checkUploadPostback();
 }
Exemplo n.º 22
0
 public function getThemeOptions($keyValue = null)
 {
     $all = Theme::all();
     $ret = [];
     foreach ($all as $theme) {
         $ret[$theme->getDirName()] = $theme->getConfigValue('name', $theme->getDirName());
     }
     return ['' => '-- none --'] + $ret;
 }
Exemplo n.º 23
0
 public function generateSitemap()
 {
     if (!$this->items) {
         return;
     }
     $currentUrl = Request::path();
     $theme = Theme::load($this->theme);
     /*
      * Cycle each page and add its URL
      */
     foreach ($this->items as $item) {
         /*
          * Explicit URL
          */
         if ($item->type == 'url') {
             $this->addItemToSet($item, URL::to($item->url));
         } else {
             $apiResult = Event::fire('pages.menuitem.resolveItem', [$item->type, $item, $currentUrl, $theme]);
             if (!is_array($apiResult)) {
                 continue;
             }
             foreach ($apiResult as $itemInfo) {
                 if (!is_array($itemInfo)) {
                     continue;
                 }
                 /*
                  * Single item
                  */
                 if (isset($itemInfo['url'])) {
                     $this->addItemToSet($item, $itemInfo['url'], array_get($itemInfo, 'mtime'));
                 }
                 /*
                  * Multiple items
                  */
                 if (isset($itemInfo['items'])) {
                     $parentItem = $item;
                     $itemIterator = function ($items) use(&$itemIterator, $parentItem) {
                         foreach ($items as $item) {
                             if (isset($item['url'])) {
                                 $this->addItemToSet($parentItem, $item['url'], array_get($item, 'mtime'));
                             }
                             if (isset($item['items'])) {
                                 $itemIterator($item['items']);
                             }
                         }
                     };
                     $itemIterator($itemInfo['items']);
                 }
             }
         }
     }
     $urlSet = $this->makeUrlSet();
     $xml = $this->makeXmlObject();
     $xml->appendChild($urlSet);
     return $xml->saveXML();
 }
Exemplo n.º 24
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());
 }
Exemplo n.º 25
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;
 }
Exemplo n.º 26
0
 private function spoofPageCode()
 {
     // Spoof all the objects we need to make a page object
     $theme = Theme::load('test');
     $page = Page::load($theme, 'index.htm');
     $layout = Layout::load($theme, 'content.htm');
     $controller = new Controller($theme);
     $parser = new CodeParser($page);
     $pageObj = $parser->source($page, $layout, $controller);
     return $pageObj;
 }
Exemplo n.º 27
0
 protected function getTemplateScriptPath()
 {
     $theme = Theme::getEditTheme();
     $assetPath = $theme->getPath() . '/assets';
     $fileName = $this->template->getBaseFileName();
     $jsPath = $assetPath . '/javascript';
     if (!File::isDirectory($jsPath)) {
         $jsPath = $assetPath . '/js';
     }
     return $jsPath . '/controllers/' . $fileName . '.js';
 }
Exemplo n.º 28
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);
 }
Exemplo n.º 29
0
 /**
  * Execute the console command.
  * @return void
  */
 public function fire()
 {
     $themeName = $this->argument('name');
     $argDirName = $this->argument('dirName');
     if ($argDirName && $themeName == $argDirName) {
         $argDirName = null;
     }
     if ($argDirName) {
         if (!preg_match('/^[a-z0-9\\_\\-]+$/i', $argDirName)) {
             return $this->error('Invalid destination directory name.');
         }
         if (Theme::exists($argDirName)) {
             return $this->error(sprintf('A theme named %s already exists.', $argDirName));
         }
     }
     try {
         $themeManager = ThemeManager::instance();
         $updateManager = UpdateManager::instance();
         $themeDetails = $updateManager->requestThemeDetails($themeName);
         if ($themeManager->isInstalled($themeDetails['code'])) {
             return $this->error(sprintf('The theme %s is already installed.', $themeDetails['code']));
         }
         if (Theme::exists($themeDetails['code'])) {
             return $this->error(sprintf('A theme named %s already exists.', $themeDetails['code']));
         }
         $fields = ['Name', 'Description', 'Author', 'URL', ''];
         $this->info(sprintf(implode(': %s' . PHP_EOL, $fields), $themeDetails['code'], $themeDetails['description'], $themeDetails['author'], $themeDetails['product_url']));
         if (!$this->confirm('Do you wish to continue? [Y|n]', true)) {
             return;
         }
         $this->info('Downloading theme...');
         $updateManager->downloadTheme($themeDetails['code'], $themeDetails['hash']);
         $this->info('Extracting theme...');
         $updateManager->extractTheme($themeDetails['code'], $themeDetails['hash']);
         $dirName = $this->themeCodeToDir($themeDetails['code']);
         if ($argDirName) {
             /*
              * Move downloaded theme to a new directory.
              * Basically we're renaming it.
              */
             File::move(themes_path() . '/' . $dirName, themes_path() . '/' . $argDirName);
             /*
              * Let's make sure to unflag the 'old' theme as
              * installed so it can be re-installed later.
              */
             $themeManager->setUninstalled($themeDetails['code']);
             $dirName = $argDirName;
         }
         $this->info(sprintf('The theme %s has been installed. (now %s)', $themeDetails['code'], $dirName));
     } catch (Exception $ex) {
         $this->error($ex->getMessage());
     }
 }
Exemplo n.º 30
0
 public function getPagesDropDown()
 {
     if (!$this->pages) {
         $theme = Theme::getEditTheme();
         $pages = Page::listInTheme($theme, true);
         $this->pages = [];
         foreach ($pages as $page) {
             $this->pages[$page->baseFileName] = $page->title . ' (' . $page->url . ')';
         }
     }
     return $this->pages;
 }