/**
  * 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);
     }
 }
 /**
  * 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', []);
 }
 /**
  * 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.
         }
     }
 }
 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);
 }
Exemple #5
0
 /**
  * Set the theme to a specific one.
  * @return self
  */
 public function inTheme($theme)
 {
     if (is_string($theme)) {
         $theme = Theme::load($theme);
     }
     $this->theme = $theme;
     return $this;
 }
Exemple #6
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();
 }
 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;
 }
Exemple #8
0
 public function testListPages()
 {
     $theme = Theme::load('test');
     $pages = $theme->listPages();
     $this->assertInternalType('array', $pages);
     $expectedPageNum = $this->countThemePages(base_path() . '/tests/fixtures/themes/test/pages');
     $this->assertEquals($expectedPageNum, count($pages));
     $this->assertInstanceOf('\\Cms\\Classes\\Page', $pages[0]);
     $this->assertNotEmpty($pages[0]->url);
     $this->assertInstanceOf('\\Cms\\Classes\\Page', $pages[1]);
     $this->assertNotEmpty($pages[1]->url);
 }
 public function testCmsExceptionPhp()
 {
     $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', 100, 1, 'test.php', 20);
     $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->getFilePath(), $exception->getFile());
     $this->assertEquals('PHP Content', $exception->getErrorType());
     $this->assertEquals('This is a general error', $exception->getMessage());
 }
Exemple #10
0
 /**
  * Add form fields defined in theme.yaml
  */
 protected function formExtendFields($form)
 {
     $model = $form->model;
     if (!($theme = CmsTheme::load($model->theme))) {
         throw new Exception(Lang::get('Unable to find theme with name :name', $this->theme));
     }
     if ($fields = $theme->getConfigValue('form.fields')) {
         $form->addFields($fields);
     }
     if ($fields = $theme->getConfigValue('form.tabs.fields')) {
         $form->addTabFields($fields);
     }
     if ($fields = $theme->getConfigValue('form.secondaryTabs.fields')) {
         $form->addSecondaryTabFields($fields);
     }
 }
Exemple #11
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);
 }
Exemple #12
0
 /**
  * Update action. Add the theme object to the page vars.
  */
 public function update($recordId = null, $context = null)
 {
     $this->bodyClass = 'compact-container';
     try {
         if (!($editTheme = Theme::getEditTheme())) {
             throw new ApplicationException('Unable to find the active theme.');
         }
         $result = $this->asExtension('FormController')->update($recordId, $context);
         $model = $this->formGetModel();
         $theme = Theme::load($model->theme);
         /*
          * Not editing the active sitemap definition
          */
         if ($editTheme->getDirName() != $theme->getDirName()) {
             return $this->redirectToThemeSitemap($editTheme);
         }
         $this->vars['theme'] = $theme;
         $this->vars['themeName'] = $theme->getConfigValue('name', $theme->getDirName());
         $this->vars['sitemapUrl'] = URL::to('/sitemap.xml');
         return $result;
     } catch (Exception $ex) {
         $this->handleError($ex);
     }
 }
 public function testGetViewBagEmpty()
 {
     $theme = Theme::load('test');
     $obj = TestParsedCmsCompoundObject::load($theme, 'compound.htm');
     $viewBag = $obj->getViewBag();
     $this->assertInstanceOf('Cms\\Classes\\ViewBag', $viewBag);
     $properties = $viewBag->getProperties();
     $this->assertEmpty($properties);
     $this->assertEquals($obj->viewBag, $properties);
 }
 public function testSaveNewDir()
 {
     $theme = Theme::load('apitest');
     $destFilePath = $theme->getPath() . '/testobjects/testsubdir/mytestobj.htm';
     if (file_exists($destFilePath)) {
         unlink($destFilePath);
     }
     $destDirPath = dirname($destFilePath);
     if (file_exists($destDirPath) && is_dir($destDirPath)) {
         rmdir($destDirPath);
     }
     $this->assertFileNotExists($destFilePath);
     $this->assertFileNotExists($destDirPath);
     $testContents = 'mytestcontent';
     $obj = new TestCmsObject($theme);
     $obj->fill(['fileName' => 'testsubdir/mytestobj.htm', 'content' => $testContents]);
     $obj->save();
     $this->assertFileExists($destFilePath);
     $this->assertEquals($testContents, file_get_contents($destFilePath));
 }
Exemple #15
0
 /**
  * Returns all fields defined for this model, based on form field definitions.
  * @return array
  */
 public function getFormFields()
 {
     if (!($theme = CmsTheme::load($this->theme))) {
         throw new Exception(Lang::get('Unable to find theme with name :name', $this->theme));
     }
     $config = $theme->getConfigArray('form');
     return array_get($config, 'fields', []) + array_get($config, 'tabs.fields', []) + array_get($config, 'secondaryTabs.fields', []);
 }
Exemple #16
0
 /**
  * Returns the CMS theme this object belongs to.
  * @return \Cms\Classes\Theme
  */
 public function getThemeAttribute()
 {
     if ($this->themeCache !== null) {
         return $this->themeCache;
     }
     $themeName = $this->getDatasourceName() ?: static::getDatasourceResolver()->getDefaultDatasource();
     return $this->themeCache = Theme::load($themeName);
 }
Exemple #17
0
 public function testCombinerNotFound()
 {
     $this->markTestIncomplete('Unfinished.');
     $theme = new Theme();
     $theme->load('test');
     $controller = new Controller($theme);
     $response = $controller->run('/combine/xxxxxxxxx');
     $this->assertEquals("The combiner file 'xxx' is not found.", $response->getOriginalContent());
 }
 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']);
 }
    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);
    }
 public function testNamespaces()
 {
     $theme = Theme::load('test');
     $page = Page::load($theme, 'code-namespaces.htm');
     $this->assertNotEmpty($page);
     $parser = new CodeParser($page);
     $info = $parser->parse();
     $this->assertInternalType('array', $info);
     $this->assertArrayHasKey('filePath', $info);
     $this->assertArrayHasKey('className', $info);
     $this->assertArrayHasKey('source', $info);
     $this->assertFileExists($info['filePath']);
     $controller = new Controller($theme);
     $obj = $parser->source($page, null, $controller);
     $this->assertInstanceOf('\\Cms\\Classes\\PageCode', $obj);
     $referenceFilePath = base_path() . '/tests/fixtures/cms/reference/namespaces.php';
     $this->assertFileExists($referenceFilePath);
     $referenceContents = $this->getContents($referenceFilePath);
     $referenceContents = str_replace('{className}', $info['className'], $referenceContents);
     $this->assertEquals($referenceContents, $this->getContents($info['filePath']));
 }
Exemple #21
0
 public function setUp()
 {
     parent::setUp();
     self::$theme = Theme::load('test');
 }
Exemple #22
0
 /**
  * Prepares the theme datasource for the model.
  * @param \Cms\Classes\Theme $theme Specifies a parent theme.
  * @return $this
  */
 public static function inTheme($theme)
 {
     if (is_string($theme)) {
         $theme = Theme::load($theme);
     }
     return new static($theme);
 }
Exemple #23
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);
 }
Exemple #24
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);
 }
Exemple #25
0
 protected function findThemeObject($name = null)
 {
     if ($name === null) {
         $name = post('theme');
     }
     if (!$name || !($theme = CmsTheme::load($name))) {
         throw new ApplicationException(trans('cms::lang.theme.not_found_name', ['name' => $name]));
     }
     return $theme;
 }
 public function index_onDuplicateTheme()
 {
     $theme = $this->findThemeObject();
     $newDirName = trim(post('new_dir_name'));
     $sourcePath = $theme->getPath();
     $destinationPath = themes_path() . '/' . $newDirName;
     if (!preg_match('/^[a-z0-9\\_\\-]+$/i', $newDirName)) {
         throw new ValidationException(['new_dir_name' => trans('cms::lang.theme.dir_name_invalid')]);
     }
     if (File::isDirectory($destinationPath)) {
         throw new ValidationException(['new_dir_name' => trans('cms::lang.theme.dir_name_taken')]);
     }
     File::copyDirectory($sourcePath, $destinationPath);
     $newTheme = CmsTheme::load($newDirName);
     $newName = $newTheme->getConfigValue('name') . ' - Copy';
     $newTheme->writeConfig(['name' => $newName]);
     Flash::success(trans('cms::lang.theme.duplicate_theme_success'));
     return Redirect::refresh();
 }
 public function testSaveFull()
 {
     $theme = Theme::load('apitest');
     $destFilePath = $theme->getPath() . '/testobjects/compound.htm';
     if (file_exists($destFilePath)) {
         unlink($destFilePath);
     }
     $this->assertFileNotExists($destFilePath);
     $obj = new TestCmsCompoundObject($theme);
     $obj->fill(['fileName' => 'compound', 'settings' => ['var' => 'value'], 'code' => 'function a() {return true;}', 'markup' => '<p>Hello, world!</p>']);
     $obj->save();
     $referenceFilePath = base_path() . '/tests/fixtures/cms/reference/compound-full.htm';
     $this->assertFileExists($referenceFilePath);
     $this->assertFileExists($destFilePath);
     $this->assertFileEqualsNormalized($referenceFilePath, $destFilePath);
 }
Exemple #28
0
 public static function setUpBeforeClass()
 {
     self::$theme = Theme::load('test');
 }