Esempio n. 1
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());
     }
 }
Esempio n. 2
0
 /**
  * Create virtual array for theme change
  * @return array
  */
 public function themes()
 {
     $path = themes_path();
     $dir_arr = \File::directories($path);
     $themes = array();
     foreach ($dir_arr as $path) {
         $name_arr = explode('/', $path);
         $name = array_pop($name_arr);
         $theme_name = array_get(theme_settings($path), 'theme_name');
         $themes[$name] = $theme_name;
     }
     return $themes;
 }
Esempio n. 3
0
 /**
  * Execute the console command.
  */
 public function fire()
 {
     if (!$this->confirmToProceed('Are you sure?')) {
         return;
     }
     $demoThemePath = themes_path() . '/demo';
     if (File::exists($demoThemePath)) {
         Artisan::call('plugin:remove', ['name' => 'October.Demo', '--force' => true]);
         File::deleteDirectory($demoThemePath);
         $this->info('Demo has been removed! Enjoy a fresh start.');
     } else {
         $this->error('Demo theme is already removed.');
     }
 }
Esempio n. 4
0
 protected function getSystemWarnings()
 {
     $warnings = [];
     $writablePaths = [temp_path(), themes_path(), storage_path(), storage_path('app'), storage_path('logs'), storage_path('framework'), storage_path('cms'), storage_path('cms/cache'), storage_path('cms/twig'), storage_path('cms/combiner')];
     $requiredExtensions = ['GD' => extension_loaded('gd'), 'fileinfo' => extension_loaded('fileinfo'), 'Zip' => class_exists('ZipArchive'), 'cURL' => function_exists('curl_init') && defined('CURLOPT_FOLLOWLOCATION'), 'OpenSSL' => function_exists('openssl_random_pseudo_bytes')];
     foreach ($writablePaths as $path) {
         if (!is_writable($path)) {
             $warnings[] = Lang::get('backend::lang.warnings.permissions', ['name' => '<strong>' . $path . '</strong>']);
         }
     }
     foreach ($requiredExtensions as $extension => $installed) {
         if (!$installed) {
             $warnings[] = Lang::get('backend::lang.warnings.extension', ['name' => '<strong>' . $extension . '</strong>']);
         }
     }
     return $warnings;
 }
Esempio n. 5
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;
 }
Esempio n. 6
0
 /**
  * Converts supplied URL to a theme URL relative to the website root. If the URL provided is an
  * array then the files will be combined.
  * @param mixed $url Specifies the theme-relative URL. If null, the theme path is returned.
  * @return string
  */
 public function themeUrl($url = null)
 {
     $themeDir = $this->getTheme()->getDirName();
     if (is_array($url)) {
         $_url = URL::to(CombineAssets::combine($url, themes_path() . '/' . $themeDir));
     } else {
         $_url = Config::get('cms.themesPath', '/themes') . '/' . $themeDir;
         if ($url !== null) {
             $_url .= '/' . $url;
         }
         $_url = URL::asset($_url);
     }
     return $_url;
 }
Esempio n. 7
0
 /**
  * Returns a list of all themes.
  * @return array Returns an array of the Theme objects.
  */
 public static function all()
 {
     $it = new DirectoryIterator(themes_path());
     $it->rewind();
     $result = [];
     foreach ($it as $fileinfo) {
         if (!$fileinfo->isDir() || $fileinfo->isDot()) {
             continue;
         }
         $theme = static::load($fileinfo->getFilename());
         $result[] = $theme;
     }
     return $result;
 }
 /**
  * Returns the base for the file path to search the files in.
  * @return string
  * @throws \SystemException
  */
 protected function getPath()
 {
     return themes_path() . "/" . Theme::getActiveTheme()->getDirName() . "/";
 }
 /**
  * Remove old theme directories.
  *
  * @return bool
  * @throws \Krisawzm\DemoManager\Classes\DemoManagerException
  */
 protected function removeOldThemes()
 {
     $baseTheme = Config::get('krisawzm.demomanager::base_theme', null);
     if (!$baseTheme) {
         // Prevents the base theme from accidentally being deleted.
         throw new DemoManagerException('A base theme is not specified.');
     }
     $themesPath = themes_path();
     $baseThemePath = themes_path($baseTheme);
     foreach (File::directories($themesPath) as $themePath) {
         // Do not remove the base theme.
         if ($themePath == $baseThemePath) {
             continue;
         }
         if (!File::deleteDirectory($themePath)) {
             return false;
         }
     }
     return true;
 }
Esempio n. 10
0
 /**
  * Override configs with theme-specific settings.
  *
  * @return void
  */
 protected function applyThemeConfig()
 {
     $path = themes_path($this->theme . '/config');
     if (app('files')->exists($path)) {
         foreach (app('files')->allFiles($path) as $file) {
             $key = str_replace('.' . $file->getExtension(), '', $file->getFilename());
             app('config')->set($key, require $file->getPathname());
         }
     }
 }
Esempio n. 11
0
 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();
 }
Esempio n. 12
0
 /**
  * This command requires the git binary to be installed.
  */
 protected function utilGitPull()
 {
     foreach (File::directories(plugins_path()) as $authorDir) {
         foreach (File::directories($authorDir) as $pluginDir) {
             if (!File::isDirectory($pluginDir . '/.git')) {
                 continue;
             }
             $exec = 'cd ' . $pluginDir . ' && ';
             $exec .= 'git pull 2>&1';
             echo 'Updating plugin: ' . basename(dirname($pluginDir)) . '.' . basename($pluginDir) . PHP_EOL;
             echo shell_exec($exec);
         }
     }
     foreach (File::directories(themes_path()) as $themeDir) {
         if (!File::isDirectory($themeDir . '/.git')) {
             continue;
         }
         $exec = 'cd ' . $themeDir . ' && ';
         $exec .= 'git pull 2>&1';
         echo 'Updating theme: ' . basename($themeDir) . PHP_EOL;
         echo shell_exec($exec);
     }
 }
 /**
  * Returns the absolute theme path.
  * @param  string $dirName Optional theme directory. Defaults to $this->getDirName()
  * @return string
  */
 public function getPath($dirName = null)
 {
     if (!$dirName) {
         $dirName = $this->getDirName();
     }
     return themes_path() . '/' . $dirName;
 }
Esempio n. 14
0
 /**
  * Initialize.
  *
  * @return void
  */
 public function init()
 {
     if (!Cache::has($this->cacheKey)) {
         Cache::forever($this->cacheKey, count(File::directories(themes_path())) - 1);
     }
 }