Elgg  Version master
CssCompiler.php
Go to the documentation of this file.
1 <?php
2 
3 namespace Elgg\Assets;
4 
6 use Elgg\Includer;
8 
14 class CssCompiler {
15 
16  protected ?array $css_variables = null;
17 
23  public function __construct(protected EventsService $events) {
24  }
25 
33  public function getCssVars(bool $load_config_vars = true): array {
34  if (!isset($this->css_variables)) {
35  $this->css_variables = Includer::includeFile(Paths::elgg() . 'engine/theme.php');
36  $this->loadPluginVars();
37  }
38 
40 
41  if (!$load_config_vars) {
42  return $results;
43  }
44 
45  $custom_vars = (array) elgg_get_config('custom_theme_vars', []);
46  if (empty($custom_vars)) {
47  return $results;
48  }
49 
50  $first_element = $custom_vars[array_key_first($custom_vars)];
51  if (!is_array($first_element)) {
52  // assume site config only has default color scheme variables (pre 7.0)
53  $custom_vars = ['default' => $custom_vars];
54  }
55 
56  foreach ($custom_vars as $color_scheme => $variables) {
57  $results[$color_scheme] = array_merge(elgg_extract($color_scheme, $results), $variables);
58  }
59 
60  return $results;
61  }
62 
68  protected function loadPluginVars(): void {
69  $plugins = elgg_get_plugins('active');
70  foreach ($plugins as $plugin) {
71  $plugin_vars = $plugin->getStaticConfig('theme', []);
72  if (empty($plugin_vars)) {
73  continue;
74  }
75 
76  $first_item = $plugin_vars[array_key_first($plugin_vars)];
77  if (!is_array($first_item)) {
78  // assume plugin config only has default color scheme variables
79  $plugin_vars = ['default' => $plugin_vars];
80  }
81 
82  foreach ($plugin_vars as $color_scheme => $variables) {
83  $merged_variables = array_merge(elgg_extract($color_scheme, $this->css_variables), $variables);
84  $this->css_variables[$color_scheme] = $merged_variables;
85  }
86  }
87  }
88 }
Gives access to CSS variables in the system.
Definition: CssCompiler.php:14
loadPluginVars()
Loads the plugin theme variables.
Definition: CssCompiler.php:68
getCssVars(bool $load_config_vars=true)
Fetches a combined set of CSS variables and their value.
Definition: CssCompiler.php:33
__construct(protected EventsService $events)
Constructor.
Definition: CssCompiler.php:23
Events service.
Allow executing scripts without $this context or local vars.
Definition: Includer.php:10
static includeFile($file)
Include a file with as little context as possible.
Definition: Includer.php:18
Find Elgg and project paths.
Definition: Paths.php:8
static elgg()
Get the Elgg codebase path with "/".
Definition: Paths.php:44
elgg_get_config(string $name, $default=null)
Get an Elgg configuration value.
elgg_extract($key, $array, $default=null, bool $strict=true)
Checks for $array[$key] and returns its value if it exists, else returns $default.
Definition: elgglib.php:246
elgg_get_plugins(string $status='active')
Returns an ordered list of plugins.
Definition: plugins.php:39
if(parse_url(elgg_get_site_url(), PHP_URL_PATH) !=='/') if(file_exists(elgg_get_root_path() . 'robots.txt'))
Set robots.txt.
Definition: robots.php:10
$plugin
$variables
Generic form template for install forms.
Definition: template.php:9
$results
Definition: content.php:22