Esempio n. 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;
 }
Esempio n. 2
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;
 }
Esempio n. 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;
 }
Esempio n. 4
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);
 }
 /**
  * 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;
 }