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']]]]]; }
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'; }
/** * Initialize theme. */ public function init() { $gantry = static::gantry(); $gantry['streams']->register(); $gantry->register(new ErrorServiceProvider()); /** @var Platform $patform */ $patform = $gantry['platform']; // Initialize theme cache stream. $cachePath = $patform->getCachePath() . '/' . $this->name; 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); }
/** * Initialize theme. */ public 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()); } /** @var Platform $patform */ $patform = $gantry['platform']; // Initialize theme cache stream. $cachePath = $patform->getCachePath() . '/' . $this->name; 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); }
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]); }
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(); }