friendica-github/view/theme/frio/php/scheme.php

82 lines
2.2 KiB
PHP
Raw Normal View History

<?php
/**
2020-01-19 20:44:01 +00:00
* Get info header of the scheme
*
2018-04-25 00:26:14 +00:00
* This function parses the header of the schemename.php file for informations like
* Author, Description and Overwrites. Most of the code comes from the Addon::getInfo()
2018-04-25 00:26:14 +00:00
* function. We use this to get the variables which get overwritten through the scheme.
* All color variables which get overwritten through the theme have to be
2018-04-25 00:26:14 +00:00
* listed (comma separated) in the scheme header under Overwrites:
* This seems not to be the best solution. We need to investigate further.
*
2018-04-25 00:26:14 +00:00
* @param string $scheme Name of the scheme
* @return array With theme information
* 'author' => Author Name
2018-04-25 00:26:14 +00:00
* 'description' => Scheme description
* 'version' => Scheme version
* 'overwrites' => Variables which overwriting custom settings
*/
2019-02-24 14:40:05 +00:00
2020-01-04 22:42:01 +00:00
use Friendica\DI;
use Friendica\Util\Strings;
2018-04-25 00:26:14 +00:00
function get_scheme_info($scheme)
2018-04-25 00:05:20 +00:00
{
2020-01-04 22:42:01 +00:00
$theme = DI::app()->getCurrentTheme();
$themepath = 'view/theme/' . $theme . '/';
2019-02-24 14:48:30 +00:00
if (empty($scheme)) {
$scheme = DI::pConfig()->get(local_user(), 'frio', 'scheme', DI::pConfig()->get(local_user(), 'frio', 'schema'));
2019-02-24 14:40:05 +00:00
}
$scheme = Strings::sanitizeFilePathItem($scheme);
2018-04-25 00:05:20 +00:00
$info = [
2018-04-25 00:26:14 +00:00
'name' => $scheme,
'description' => '',
'author' => [],
'version' => '',
'overwrites' => []
];
2018-04-25 00:26:14 +00:00
if (!is_file($themepath . 'scheme/' . $scheme . '.php')) return $info;
2018-04-25 00:26:14 +00:00
$f = file_get_contents($themepath . 'scheme/' . $scheme . '.php');
$r = preg_match('|/\*.*\*/|msU', $f, $m);
2018-04-25 00:05:20 +00:00
if ($r) {
$ll = explode("\n", $m[0]);
2018-04-25 00:05:20 +00:00
foreach ($ll as $l) {
$l = trim($l, "\t\n\r */");
if ($l != '') {
$values = array_map('trim', explode(':', $l, 2));
if (count($values) < 2) {
continue;
}
list($k, $v) = $values;
2018-04-25 00:05:20 +00:00
$k = strtolower($k);
if ($k == 'author') {
$r = preg_match('|([^<]+)<([^>]+)>|', $v, $m);
if ($r) {
2018-04-25 00:05:20 +00:00
$info['author'][] = ['name' => $m[1], 'link' => $m[2]];
} else {
2018-04-25 00:05:20 +00:00
$info['author'][] = ['name' => $v];
}
} elseif ($k == 'overwrites') {
2018-04-25 00:05:20 +00:00
$theme_settings = explode(',', str_replace(' ', '', $v));
foreach ($theme_settings as $key => $value) {
$info['overwrites'][$value] = true;
}
} else {
2018-04-25 00:05:20 +00:00
if (array_key_exists($k, $info)) {
$info[$k] = $v;
}
}
}
}
}
2018-04-25 00:05:20 +00:00
return $info;
}