/** * Get the runtime site configuration variable named {@code $key}. * @throws ConfigException if config has not been initialised or there is no valid key (and no default has been provided) */ static function get($key, $default = null) { if (isset(Config::$values[$key])) { return Config::$values[$key]; } else { if (Config::isEmpty()) { throw new ConfigException("Site configuration has not been initialised for '{$key}'"); } else { if ($default !== null) { return $default; } else { throw new ConfigException("No site configuration value found for '{$key}'"); } } } }
/** * @param string $path * @param string $filter * @param int $media * @return string */ protected function applyFilter($path, $filter, $media) { if ($media == 1) { $path = 'media/' . $path; } if ($this->config->isEmpty("plugins.config.imagine.filter_sets.{$filter}")) { return $path; } // return original path if file not exists if (!is_file($path)) { return $path; } $filterConfig = $this->config->get("plugins.config.imagine.filter_sets.{$filter}"); $cachePath = $this->resolveCachePath($path, $filter); if (!empty($filterConfig['test'])) { if (is_file($cachePath)) { unlink($cachePath); } } if (is_file($cachePath)) { return $cachePath; } $imagine = new Imagine(); $image = $imagine->open($path); foreach ($filterConfig['filters'] as $key => $value) { $methodName = sprintf('apply%sFilter', ucfirst($key)); if (method_exists($this, $methodName)) { $image = $this->{$methodName}($image, $value); } } $options = []; if (isset($filterConfig['quality'])) { $options['quality'] = $filterConfig['quality']; } $cacheDir = dirname($cachePath); if (!is_dir($cacheDir)) { mkdir($cacheDir, 0755, true); } $image->save($cachePath, $options); return $cachePath; }
/** * @return Twig_Loader_Filesystem */ private function getTwigFilesystemLoader() { $paths = []; if ($this->config->isEmpty('theme')) { $paths[] = $this->config->get('layouts.path'); } elseif ($this->config->get('theme') == 'default') { $paths[] = $this->config->get('layouts.path') . '/default'; } else { $paths[] = $this->config->get('layouts.path') . '/' . $this->config->get('theme'); $paths[] = $this->config->get('layouts.path') . '/default'; } $loader = new Twig_Loader_Filesystem($paths); // namespaces $namespaces = ['plugin' => $this->config->get('plugins.path'), 'page' => $this->config->get('pages.path'), 'post' => $this->config->get('posts.path'), 'site' => $this->config->get('site.path'), 'widget' => __DIR__ . '/widgets']; foreach ($namespaces as $namespace => $path) { if (is_readable($path)) { $loader->addPath($path, $namespace); } } return $loader; }