Exemple #1
0
 /**
  * @return array
  */
 public static function getThemes()
 {
     $gantry = Gantry::instance();
     /** @var UniformResourceLocator $locator */
     $locator = $gantry['locator'];
     $files = Folder::all('gantry-themes://', ['recursive' => false]);
     /** @var array|ThemeDetails[] $list */
     $list = [];
     ksort($files);
     foreach ($files as $theme) {
         if (!is_dir($theme)) {
             continue;
         }
         if ($locator('gantry-themes://' . $theme . '/gantry/theme.yaml')) {
             $details = new ThemeDetails($theme);
             // Stream needs to be valid URL.
             $streamName = 'gantry-themes-' . preg_replace('|[^a-z\\d+.-]|ui', '-', $theme);
             if (!$locator->schemeExists($streamName)) {
                 $locator->addPath($streamName, '', $details->getPaths());
             }
             $details['name'] = $theme;
             $details['title'] = $details['details.name'];
             $details['preview_url'] = $locator('gantry-themes://' . $theme);
             // FIXME:
             $details['admin_url'] = 'FIXME';
             $details['params'] = [];
             $list[$details->name] = $details;
         }
     }
     // Add Thumbnails links after adding all the paths to the locator.
     foreach ($list as $details) {
         $details['thumbnail'] = $details->getUrl("details.images.thumbnail");
     }
     return $list;
 }
Exemple #2
0
 public function index()
 {
     /** @var UniformResourceLocator $locator */
     $locator = $this->container['locator'];
     Folder::delete($locator('gantry-cache://'), false);
     return new JsonResponse(['html' => 'Cache was successfully cleared', 'title' => 'Cache Cleared']);
 }
Exemple #3
0
 /**
  * @return array
  */
 public static function getStyles()
 {
     $gantry = Gantry::instance();
     /** @var UniformResourceLocator $locator */
     $locator = $gantry['locator'];
     $files = Folder::all('gantry-themes://', ['recursive' => false]);
     $list = array();
     foreach ($files as $theme) {
         if (file_exists($locator('gantry-themes://' . $theme . '/default/gantry/theme.yaml'))) {
             $details = new ThemeDetails($theme);
             if (!$locator->schemeExists('gantry-theme-' . $theme)) {
                 $locator->addPath('gantry-themes-' . $theme, '', $details->getPaths());
             }
             $details['name'] = $theme;
             $details['title'] = ucfirst($theme);
             $details['preview_url'] = '/' . $theme;
             $details['admin_url'] = '/' . $theme . '/admin';
             $details['params'] = [];
             $list[$details->name] = $details;
         }
     }
     // Add Thumbnails links.
     foreach ($list as $details) {
         $details['thumbnail'] = self::getImage($locator, $details, 'thumbnail');
     }
     return $list;
 }
Exemple #4
0
 /**
  * @see AbstractTheme::init()
  */
 protected function init()
 {
     $gantry = static::gantry();
     // Add particles, styles and defaults into DI.
     $gantry['particles'] = function ($c) {
         return new Particles($c);
     };
     $gantry['styles'] = function ($c) {
         return new Styles($c);
     };
     $gantry['defaults'] = function ($c) {
         /** @var UniformResourceLocator $locator */
         $locator = $c['locator'];
         $cache = $locator->findResource('gantry-cache://theme/compiled/config', true, true);
         $paths = $locator->findResources('gantry-config://default');
         $files = (new ConfigFileFinder())->locateFiles($paths);
         $config = new CompiledConfig($cache, $files, function () use($c) {
             return $c['blueprints'];
         });
         return $config->load(true);
     };
     // Initialize admin streams.
     /** @var Platform $patform */
     $patform = $gantry['platform'];
     /** @var UniformResourceLocator $locator */
     $locator = $gantry['locator'];
     $nucleus = $patform->getEnginePaths('nucleus')[''];
     $relpath = Folder::getRelativePath($this->path);
     $patform->set('streams.gantry-admin.prefixes', ['' => ['gantry-theme://admin', $relpath, $relpath . '/common', 'gantry-engine://admin'], 'assets/' => array_merge([$relpath, $relpath . '/common'], $nucleus, ['gantry-assets://'])]);
     // Add admin paths.
     foreach ($patform->get('streams.gantry-admin.prefixes') as $prefix => $paths) {
         $locator->addPath('gantry-admin', $prefix, $paths);
     }
 }
Exemple #5
0
 public function __construct($path, $name = '')
 {
     $gantry = \Gantry\Framework\Gantry::instance();
     $relpath = Folder::getRelativePath($path);
     // Initialize admin streams.
     /** @var Platform $patform */
     $patform = $gantry['platform'];
     $nucleus = $patform->getEnginePaths('nucleus')[''];
     $patform->set('streams.gantry-admin.prefixes', ['' => ['gantry-theme://admin', $relpath, $relpath . '/common', 'gantry-engine://admin'], 'assets/' => array_merge([$relpath, $relpath . '/common'], $nucleus, ['gantry-assets://'])]);
     $gantry['particles'] = function ($c) {
         return new Particles($c);
     };
     $gantry['styles'] = function ($c) {
         return new Styles($c);
     };
     $gantry['defaults'] = function ($c) {
         /** @var UniformResourceLocator $locator */
         $locator = $c['locator'];
         $cache = $locator->findResource('gantry-cache://theme/compiled/config', true, true);
         $paths = $locator->findResources('gantry-config://default');
         $files = (new ConfigFileFinder())->locateFiles($paths);
         $config = new CompiledConfig($cache, $files, function () use($c) {
             return $c['blueprints'];
         });
         return $config->load(true);
     };
     parent::__construct($path, $name);
     $this->boot();
 }
Exemple #6
0
 /**
  * Update all CSS files in the theme.
  *
  * @param array $configurations
  * @return array List of CSS warnings.
  */
 public function updateCss(array $configurations = null)
 {
     $gantry = static::gantry();
     $compiler = $this->compiler();
     if (is_null($configurations)) {
         /** @var UniformResourceLocator $locator */
         $locator = $gantry['locator'];
         $path = $locator->findResource($compiler->getTarget(), true, true);
         // Make sure that all the CSS files get deleted.
         if (is_dir($path)) {
             Folder::delete($path, false);
         }
         $configurations = $gantry['configurations'];
     }
     // Make sure that PHP has the latest data of the files.
     clearstatcache();
     $warnings = [];
     foreach ($configurations as $configuration => $title) {
         $config = ConfigServiceProvider::load($gantry, $configuration);
         $compiler->reset()->setConfiguration($configuration)->setVariables($config->flatten('styles', '-'));
         $results = $compiler->compileAll()->getWarnings();
         if ($results) {
             $warnings[$configuration] = $results;
         }
     }
     return $warnings;
 }
Exemple #7
0
 /**
  * @return array
  */
 public static function getThemes()
 {
     $gantry = Gantry::instance();
     /** @var UniformResourceLocator $locator */
     $locator = $gantry['locator'];
     $files = Folder::all('gantry-themes://', ['recursive' => false]);
     /** @var array|ThemeDetails[] $list */
     $list = [];
     ksort($files);
     foreach ($files as $theme) {
         if (file_exists(PRIME_ROOT . '/themes/' . $theme . '/gantry/theme.yaml')) {
             $details = new ThemeDetails($theme);
             if (!$locator->schemeExists('gantry-theme-' . $theme)) {
                 $locator->addPath('gantry-themes-' . $theme, '', $details->getPaths());
             }
             $details['name'] = $theme;
             $details['title'] = $details['details.name'];
             $details['preview_url'] = rtrim(PRIME_URI, '/') . '/' . $theme;
             $details['admin_url'] = rtrim(PRIME_URI, '/') . '/' . $theme . '/admin/configurations/styles';
             $details['params'] = [];
             $list[$details->name] = $details;
         }
     }
     // Add Thumbnails links after adding all the paths to the locator.
     foreach ($list as $details) {
         $details['thumbnail'] = $details->getUrl("details.images.thumbnail");
     }
     return $list;
 }
Exemple #8
0
 public function __construct(Container $container)
 {
     $this->container = $container;
     //Make sure that cache folder exists, otherwise it will be removed from the lookup.
     $cachePath = $this->getCachePath();
     Folder::create($cachePath);
     $this->items = ['streams' => ['gantry-cache' => ['type' => 'Stream', 'force' => true, 'prefixes' => ['' => [$cachePath]]], 'gantry-themes' => ['type' => 'ReadOnlyStream', 'prefixes' => $this->getThemesPaths()], 'gantry-theme' => ['type' => 'ReadOnlyStream', 'prefixes' => $this->getThemePaths()], 'gantry-assets' => ['type' => 'ReadOnlyStream', 'prefixes' => $this->getAssetsPaths()], 'gantry-media' => ['type' => 'ReadOnlyStream', 'prefixes' => $this->getMediaPaths()], 'gantry-engines' => ['type' => 'ReadOnlyStream', 'prefixes' => $this->getEnginesPaths()], 'gantry-engine' => ['type' => 'ReadOnlyStream', 'prefixes' => $this->getEnginePaths()], 'gantry-layouts' => ['type' => 'ReadOnlyStream', 'prefixes' => ['' => ['gantry-theme://layouts', 'gantry-engine://layouts']]], 'gantry-particles' => ['type' => 'ReadOnlyStream', 'prefixes' => ['' => ['gantry-theme://particles', 'gantry-engine://particles']]], 'gantry-admin' => ['type' => 'ReadOnlyStream', 'prefixes' => []], 'gantry-blueprints' => ['type' => 'ReadOnlyStream', 'prefixes' => ['' => ['gantry-theme://blueprints', 'gantry-engine://blueprints'], 'particles' => ['gantry-particles://']]], 'gantry-config' => ['type' => 'ReadOnlyStream', 'prefixes' => ['' => ['gantry-theme://config']]]]];
 }
Exemple #9
0
 protected function boot()
 {
     $gantry = \Gantry\Framework\Gantry::instance();
     $relpath = Folder::getRelativePath($this->path);
     /** @var Streams $streams */
     $streams = $gantry['streams'];
     $streams->add(['gantry-admin' => ['prefixes' => ['' => ['gantry-theme://admin', $relpath, $relpath . '/common'], 'assets/' => ['gantry-theme://admin', $relpath, $relpath . '/common']]]]);
     $streams->register();
 }
Exemple #10
0
 public function __construct(Container $container)
 {
     parent::__construct($container);
     Folder::create(GANTRY5_ROOT . '/custom');
     // Initialize custom streams for Prime.
     $this->items['streams'] += ['gantry-prime' => ['type' => 'ReadOnlyStream', 'prefixes' => ['' => ['']]], 'gantry-custom' => ['type' => 'ReadOnlyStream', 'prefixes' => ['' => []]], 'gantry-pages' => ['type' => 'ReadOnlyStream', 'prefixes' => ['' => ['gantry-theme://overrides/pages', 'pages']]], 'gantry-positions' => ['type' => 'ReadOnlyStream', 'prefixes' => ['' => ['gantry-theme://overrides/positions', 'positions']]]];
     $this->items['streams']['gantry-layouts']['prefixes'][''][] = 'gantry-prime://layouts';
     $this->items['streams']['gantry-config']['prefixes'][''][] = 'gantry-prime://config';
 }
Exemple #11
0
 public static function delete($id)
 {
     $gantry = Gantry::instance();
     /** @var UniformResourceLocator $locator */
     $locator = $gantry['locator'];
     $path = $locator->findResource('gantry-config://' . $id, true, true);
     if (is_dir($path)) {
         Folder::delete($path, true);
     }
 }
Exemple #12
0
 public function index()
 {
     /** @var UniformResourceLocator $locator */
     $locator = $this->container['locator'];
     Folder::delete($locator('gantry-cache://theme'), false);
     Folder::delete($locator('gantry-cache://admin'), false);
     // Make sure that PHP has the latest data of the files.
     clearstatcache();
     return new JsonResponse(['html' => 'Cache was successfully cleared', 'title' => 'Cache Cleared']);
 }
Exemple #13
0
 public function __construct($path, $name = '')
 {
     $gantry = \Gantry\Framework\Gantry::instance();
     $relpath = Folder::getRelativePath($path);
     // Initialize admin streams.
     $gantry['platform']->set('streams.gantry-admin.prefixes', ['' => [$relpath, $relpath . '/common'], 'assets/' => [$relpath, $relpath . '/common']]);
     parent::__construct($path, $name);
     // FIXME:
     $this->url = '/templates/' . $this->name;
     $this->boot();
 }
Exemple #14
0
 public static function copy($style, $old, $new)
 {
     $gantry = Gantry::instance();
     /** @var UniformResourceLocator $locator */
     $locator = $gantry['locator'];
     $oldPath = $locator->findResource('gantry-config://' . $old, true, true);
     $newPath = $locator->findResource('gantry-config://' . $new, true, true);
     if (file_exists($oldPath)) {
         Folder::copy($oldPath, $newPath);
     }
     $installer = new TemplateInstaller($style->extension_id);
     $installer->updateStyle($new, ['configuration' => $new]);
 }
Exemple #15
0
 public function index()
 {
     throw new \Exception('Deprecated');
     $options = ['compare' => 'Filename', 'pattern' => '|\\.json|', 'filters' => ['key' => '|\\.json|'], 'key' => 'SubPathname', 'value' => 'Pathname'];
     /** @var UniformResourceLocator $locator */
     $locator = $this->container['locator'];
     $files = Folder::all($locator->findResource('gantry-theme://layouts/presets'), $options);
     $response = ['layouts'];
     foreach ($files as $name => $structure) {
         $content = JsonFile::instance($structure)->content();
         $response['layouts'][$name] = $content;
     }
     $response['html'] = $this->container['admin.theme']->render('@gantry-admin/layouts/picker.html.twig', ['presets' => $response]);
     return new JsonResponse($response);
 }
Exemple #16
0
 /**
  * Update all CSS files in the theme.
  */
 public function updateCss()
 {
     $gantry = static::gantry();
     $compiler = $this->compiler();
     /** @var UniformResourceLocator $locator */
     $locator = $gantry['locator'];
     $path = $locator->findResource($compiler->getTarget(), true, true);
     // Make sure that all the CSS files get deleted.
     if (is_dir($path)) {
         Folder::delete($path, false);
     }
     /** @var Configurations $configurations */
     $configurations = $gantry['configurations'];
     foreach ($configurations as $configuration => $title) {
         $config = ConfigServiceProvider::load($gantry, $configuration);
         $compiler->reset()->setConfiguration($configuration)->setVariables($config->flatten('styles', '-'));
         $compiler->compileAll();
     }
 }
Exemple #17
0
 public function libUrl(array $args, Compiler $compiler)
 {
     // Function has a single parameter.
     $parsed = reset($args);
     if (!$parsed) {
         $this->throwError('url() is missing parameter');
     }
     // Compile parsed value to string.
     $url = trim($compiler->compileValue($parsed), '\'"');
     // Handle ../ inside CSS files (points to current theme).
     $uri = strpos($url, '../') === 0 ? 'gantry-theme://' . substr($url, 3) : $url;
     // Generate URL, failed streams will be kept as they are to allow users to find issues.
     $url = Document::url($uri) ?: $url;
     // Changes absolute URIs to relative to make the path to work even if the site gets moved.
     if ($url[0] == '/' && $this->basePath) {
         $url = Folder::getRelativePathDotDot($url, $this->basePath);
     }
     // Return valid CSS.
     return "url('{$url}')";
 }
Exemple #18
0
 public function getThemesPaths()
 {
     return ['' => Folder::getRelativePath(get_theme_root())];
 }
Exemple #19
0
use Gantry\Component\Filesystem\Folder;
define('PRIME_ROOT', dirname($_SERVER['SCRIPT_FILENAME']));
define('PRIME_URI', dirname($_SERVER['SCRIPT_NAME']));
date_default_timezone_set('UTC');
// Bootstrap Gantry framework or fail gracefully (inside included file).
$gantry = (include_once PRIME_ROOT . '/includes/gantry.php');
// Get current theme and path.
$path = isset($_SERVER['PATH_INFO']) ? $_SERVER['PATH_INFO'] : Folder::getRelativePath($_SERVER['REQUEST_URI'], PRIME_URI);
$path = explode('?', $path, 2);
$path = reset($path);
$extension = strrchr(basename($path), '.');
if ($extension) {
    $path = substr($path, 0, -strlen($extension));
}
$theme = strpos($path, 'admin') !== 0 ? Folder::shift($path) : null;
define('THEME', $theme);
define('PAGE_PATH', $path ?: ($theme ? 'home' : ''));
define('PAGE_EXTENSION', trim($extension, '.') ?: 'html');
// Bootstrap selected theme.
$include = PRIME_ROOT . "/themes/{$theme}/includes/gantry.php";
if (is_file($include)) {
    include $include;
}
// Enter to administration if we are in /ROOT/theme/admin. Also display installed themes if no theme has been selected.
if (!isset($gantry['theme']) || strpos($path, 'admin') === 0) {
    require_once PRIME_ROOT . '/admin/admin.php';
    exit;
}
// Boot the service.
/** @var Gantry\Framework\Theme $theme */
Exemple #20
0
 /**
  * @param string $id
  * @throws \RuntimeException
  */
 public function delete($id)
 {
     if (!$this->canDelete($id)) {
         throw new \RuntimeException("Outline '{$id}' cannot be deleted", 400);
     }
     $gantry = $this->container;
     /** @var UniformResourceLocator $locator */
     $locator = $gantry['locator'];
     $path = $locator->findResource("{$this->path}/{$id}", true, true);
     if (!is_dir($path)) {
         throw new \RuntimeException('Outline not found', 404);
     }
     if (file_exists($path)) {
         Folder::delete($path);
     }
 }
Exemple #21
0
 public function delete($id)
 {
     $model = StyleHelper::loadModel();
     $item = $model->getTable();
     $item->load($id);
     if (!$item->id) {
         throw new \RuntimeException('Outline not found', 404);
     }
     try {
         if (!$model->delete($id)) {
             $error = $model->getError();
             // Well, Joomla can always send enqueue message instead!
             if (!$error) {
                 $messages = \JFactory::getApplication()->getMessageQueue();
                 $message = reset($messages);
                 $error = $message ? $message['message'] : 'Unknown error';
             }
             throw new \RuntimeException($error);
         }
     } catch (\Exception $e) {
         throw new \RuntimeException('Deleting outline failed: ' . $e->getMessage(), 400, $e);
     }
     // Remove configuration directory.
     $gantry = $this->container;
     /** @var UniformResourceLocator $locator */
     $locator = $gantry['locator'];
     $path = $locator->findResource("{$this->path}/{$item->id}", true, true);
     if ($path) {
         if (file_exists($path)) {
             Folder::delete($path);
         }
     }
 }
Exemple #22
0
 /**
  * Initialize theme.
  */
 protected function init()
 {
     $gantry = static::gantry();
     $gantry['streams']->register();
     // Only add error service if development or debug mode has been enabled or user is admin.
     if (!$gantry['global']->get('production', 0) || $gantry->debug() || $gantry->admin()) {
         $gantry->register(new ErrorServiceProvider());
     }
     // Initialize theme cache stream.
     $cachePath = $this->getCachePath();
     Folder::create($cachePath);
     /** @var UniformResourceLocator $locator */
     $locator = $gantry['locator'];
     $locator->addPath('gantry-cache', 'theme', [$cachePath], true, true);
     $gantry['file.yaml.cache.path'] = $locator->findResource('gantry-cache://theme/compiled/yaml', true, true);
 }
 /**
  * Detects all plugins with a configuration file and returns them with last modification time.
  *
  * @param  string $folder   Location to look up from.
  * @param  string $pattern  Pattern to match the file. Pattern will also be removed from the key.
  * @param  int    $levels   Maximum number of recursive directories.
  * @return array
  * @internal
  */
 protected function detectAll($folder, $pattern, $levels)
 {
     $path = trim(Folder::getRelativePath($folder), '/');
     if (is_dir($folder)) {
         // Find all system and user configuration files.
         $options = ['levels' => $levels, 'compare' => 'Filename', 'pattern' => $pattern, 'filters' => ['pre-key' => $this->base, 'key' => $pattern, 'value' => function (\RecursiveDirectoryIterator $file) use($path) {
             return ["{$path}/{$file->getSubPathname()}" => $file->getMTime()];
         }], 'key' => 'SubPathname'];
         $list = Folder::all($folder, $options);
         ksort($list);
     } else {
         $list = [];
     }
     return $list;
 }
Exemple #24
0
 public function upload()
 {
     /** @var UniformResourceLocator $locator */
     $locator = $this->container['locator'];
     $path = implode('/', func_get_args());
     if (base64_decode($path, true) !== false) {
         $path = base64_decode($path);
     }
     $stream = explode('://', $path);
     $scheme = $stream[0];
     $isStream = $locator->schemeExists($scheme);
     if ($isStream) {
         $targetPath = dirname($locator->findResource($path, true, true));
     } else {
         $targetPath = dirname(GANTRY5_ROOT . '/' . $path);
     }
     if (!isset($_FILES['file']['error']) || is_array($_FILES['file']['error'])) {
         throw new \RuntimeException('No file sent', 400);
     }
     // Check $_FILES['file']['error'] value.
     switch ($_FILES['file']['error']) {
         case UPLOAD_ERR_OK:
             break;
         case UPLOAD_ERR_NO_FILE:
             throw new \RuntimeException('No file sent', 400);
         case UPLOAD_ERR_INI_SIZE:
         case UPLOAD_ERR_FORM_SIZE:
             throw new \RuntimeException('Exceeded filesize limit.', 400);
         default:
             throw new \RuntimeException('Unkown errors', 400);
     }
     $maxSize = $this->returnBytes(min(ini_get('post_max_size'), ini_get('upload_max_filesize')));
     if ($_FILES['file']['size'] > $maxSize) {
         throw new \RuntimeException('Exceeded filesize limit. File is ' . $_FILES['file']['size'] . ', maximum allowed is ' . $maxSize, 400);
     }
     // Check extension
     $fileParts = pathinfo($_FILES['file']['name']);
     $fileExt = strtolower($fileParts['extension']);
     // TODO: check if download is of supported type.
     // Upload it
     $destination = sprintf('%s/%s', $targetPath, $_FILES['file']['name']);
     $destination = preg_replace('#//#', '/', $destination);
     Folder::create($targetPath);
     if (!move_uploaded_file($_FILES['file']['tmp_name'], $destination)) {
         throw new \RuntimeException('Failed to move uploaded file.', 500);
     }
     $finfo = new \stdClass();
     $this->attachData($finfo, new \SplFileInfo($destination));
     return new JsonResponse(['success' => 'File uploaded successfully', 'finfo' => $finfo, 'url' => $path]);
 }
Exemple #25
0
 public function index()
 {
     /** @var UniformResourceLocator $locator */
     $locator = $this->container['locator'];
     $base = $locator->base;
     $bookmarks = [];
     $drives = [DS];
     $subfolder = false;
     $filter = false;
     if (isset($_POST)) {
         $drives = isset($_POST['root']) ? $_POST['root'] != 'false' ? $_POST['root'] : [DS] : [DS];
         $subfolder = isset($_POST['subfolder']) ? true : false;
         $filter = isset($_POST['filter']) ? $_POST['filter'] != 'false' ? $_POST['filter'] : false : false;
     }
     if (!is_array($drives)) {
         $drives = [$drives];
     }
     foreach ($drives as $drive) {
         // cleanup of the path so it's chrooted.
         $drive = str_replace('..', '', $drive);
         $stream = explode('://', $drive);
         $scheme = $stream[0];
         $isStream = $locator->schemeExists($scheme);
         $path = rtrim($base, DS) . DS . ltrim($scheme, DS);
         // It's a stream but the scheme doesn't exist. we skip it.
         if (!$isStream && (count($stream) == 2 || !file_exists($path))) {
             continue;
         }
         if ($isStream && !count($resources = $locator->findResources($drive, false))) {
             continue;
         }
         $key = $isStream ? $drive : preg_replace('#' . DS . '{2,}+#', DS, $drive);
         if (!array_key_exists($key, $bookmarks)) {
             $bookmarks[$key] = $isStream ? $resources : [rtrim(Folder::getRelativePath($path), DS) . DS];
         }
     }
     if (!count($bookmarks)) {
         throw new \RuntimeException((count($drives) > 1 ? 'directories' : 'directory') . ' "' . implode('", "', $drives) . '" not found', 404);
     }
     $files = new \ArrayObject();
     $folders = [];
     $active = [];
     $index = 0;
     // iterating the folder and collecting subfolders and files
     foreach ($bookmarks as $key => $bookmark) {
         $folders[$key] = [];
         if (!$index) {
             $active[] = $key;
         }
         foreach ($bookmark as $folder) {
             $folders[$key][$folder] = new \ArrayObject();
             if (!$index) {
                 $active[] = $folder;
             }
             /** @var \SplFileInfo $info */
             foreach (new \DirectoryIterator($base . DS . ltrim($folder, DS)) as $info) {
                 // no dot files nor files beginning with dot
                 if ($info->isDot() || substr($info->getFilename(), 0, 1) == '.') {
                     continue;
                 }
                 $file = new \stdClass();
                 foreach (['getFilename', 'getExtension', 'getPerms', 'getMTime', 'getBasename', 'getPathname', 'getSize', 'getType', 'isReadable', 'isWritable', 'isDir', 'isFile'] as $method) {
                     $keyMethod = strtolower(preg_replace("/^(is|get)/", '', $method));
                     $file->{$keyMethod} = $info->{$method}();
                     if ($method == 'getPathname') {
                         $file->{$keyMethod} = Folder::getRelativePath($file->{$keyMethod});
                     } else {
                         if ($method == 'getExtension') {
                             $file->isImage = in_array($file->{$keyMethod}, ['jpg', 'jpeg', 'png', 'gif', 'ico', 'svg', 'bmp']);
                         }
                     }
                 }
                 if ($file->dir) {
                     $folders[$key][$folder]->append($file);
                 } else {
                     if ($filter && !preg_match("/" . $filter . "/i", $file->filename)) {
                         continue;
                     }
                     if (!$index) {
                         $files->append($file);
                     }
                 }
             }
             $index++;
         }
     }
     $response = [];
     if (!$subfolder) {
         $response['html'] = $this->container['admin.theme']->render('@gantry-admin/ajax/filepicker.html.twig', ['active' => $active, 'base' => $base, 'bookmarks' => $bookmarks, 'folders' => $folders, 'files' => $files]);
     } else {
         $response['subfolder'] = !$folders[$key][$folder]->count() ? false : $this->container['admin.theme']->render('@gantry-admin/ajax/filepicker/subfolders.html.twig', ['folder' => $folders[$key][$folder]]);
         $response['files'] = !$files->count() ? false : $this->container['admin.theme']->render('@gantry-admin/ajax/filepicker/files.html.twig', ['files' => $files]);
     }
     return new JsonResponse($response);
 }
 public function cleanup()
 {
     $name = $this->extension->name;
     $path = JPATH_SITE . '/templates/' . $name;
     // Remove compiled CSS files if they exist.
     $cssPath = $path . '/custom/css-compiled';
     if (is_dir($cssPath)) {
         \JFolder::delete($cssPath);
     } elseif (is_file($cssPath)) {
         \JFile::delete($cssPath);
     }
     // Remove wrongly named file if it exists.
     $md5path = $path . '/MD5SUM';
     if (is_file($md5path)) {
         \JFile::delete($md5path);
     }
     // Restart Gantry and initialize it.
     $gantry = Gantry::restart();
     $gantry['theme.name'] = $name;
     $gantry['streams']->register();
     // Only add error service if debug mode has been enabled.
     if ($gantry->debug()) {
         $gantry->register(new ErrorServiceProvider());
     }
     /** @var Platform $patform */
     $patform = $gantry['platform'];
     /** @var UniformResourceLocator $locator */
     $locator = $gantry['locator'];
     // Initialize theme stream.
     $details = new ThemeDetails($name);
     $locator->addPath('gantry-theme', '', $details->getPaths(), false, true);
     // Initialize theme cache stream and clear theme cache.
     $cachePath = $patform->getCachePath() . '/' . $name;
     if (is_dir($cachePath)) {
         Folder::delete($cachePath);
     }
     Folder::create($cachePath);
     $locator->addPath('gantry-cache', 'theme', [$cachePath], true, true);
     $gantry['file.yaml.cache.path'] = $locator->findResource('gantry-cache://theme/compiled/yaml', true, true);
     /** @var Outlines $outlines */
     $outlines = $gantry['configurations'];
     // Update positions in manifest file.
     $positions = $outlines->positions();
     $manifest = new Manifest($name);
     $manifest->setPositions(array_keys($positions));
     $manifest->save();
 }
Exemple #27
0
 /**
  * @return string
  */
 public function getCachePath()
 {
     return Folder::getRelativePath(\Mage::getBaseDir('cache')) . '/gantry5';
 }