2016-04-29 01:49:09 +02:00
|
|
|
<?php
|
|
|
|
/**
|
2020-02-09 16:34:23 +01:00
|
|
|
* @copyright Copyright (C) 2020, Friendica
|
|
|
|
*
|
|
|
|
* @license GNU AGPL version 3 or any later version
|
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU Affero General Public License as
|
|
|
|
* published by the Free Software Foundation, either version 3 of the
|
|
|
|
* License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU Affero General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Affero General Public License
|
|
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
|
|
*
|
2020-01-19 21:44:01 +01:00
|
|
|
* Get info header of the scheme
|
2018-01-15 14:05:12 +01:00
|
|
|
*
|
2018-04-25 02:26:14 +02:00
|
|
|
* This function parses the header of the schemename.php file for informations like
|
2018-01-17 19:42:40 +01:00
|
|
|
* Author, Description and Overwrites. Most of the code comes from the Addon::getInfo()
|
2018-04-25 02:26:14 +02:00
|
|
|
* function. We use this to get the variables which get overwritten through the scheme.
|
2016-04-29 01:49:09 +02:00
|
|
|
* All color variables which get overwritten through the theme have to be
|
2018-04-25 02:26:14 +02:00
|
|
|
* listed (comma separated) in the scheme header under Overwrites:
|
|
|
|
* This seems not to be the best solution. We need to investigate further.
|
2018-01-15 14:05:12 +01:00
|
|
|
*
|
2018-04-25 02:26:14 +02:00
|
|
|
* @param string $scheme Name of the scheme
|
2016-04-29 01:49:09 +02:00
|
|
|
* @return array With theme information
|
|
|
|
* 'author' => Author Name
|
2018-04-25 02:26:14 +02:00
|
|
|
* 'description' => Scheme description
|
|
|
|
* 'version' => Scheme version
|
2016-04-29 01:49:09 +02:00
|
|
|
* 'overwrites' => Variables which overwriting custom settings
|
|
|
|
*/
|
2019-02-24 15:40:05 +01:00
|
|
|
|
2020-01-04 23:42:01 +01:00
|
|
|
use Friendica\DI;
|
2019-04-01 03:50:00 +02:00
|
|
|
use Friendica\Util\Strings;
|
2017-11-07 03:22:52 +01:00
|
|
|
|
2018-04-25 02:26:14 +02:00
|
|
|
function get_scheme_info($scheme)
|
2018-04-25 02:05:20 +02:00
|
|
|
{
|
2020-01-04 23:42:01 +01:00
|
|
|
$theme = DI::app()->getCurrentTheme();
|
2018-04-25 02:12:43 +02:00
|
|
|
$themepath = 'view/theme/' . $theme . '/';
|
2019-02-24 15:48:30 +01:00
|
|
|
if (empty($scheme)) {
|
2020-01-18 16:50:57 +01:00
|
|
|
$scheme = DI::pConfig()->get(local_user(), 'frio', 'scheme', DI::pConfig()->get(local_user(), 'frio', 'schema'));
|
2019-02-24 15:40:05 +01:00
|
|
|
}
|
2016-04-29 01:49:09 +02:00
|
|
|
|
2019-04-01 03:50:00 +02:00
|
|
|
$scheme = Strings::sanitizeFilePathItem($scheme);
|
|
|
|
|
2018-04-25 02:05:20 +02:00
|
|
|
$info = [
|
2018-04-25 02:26:14 +02:00
|
|
|
'name' => $scheme,
|
2018-04-25 02:12:43 +02:00
|
|
|
'description' => '',
|
2018-01-15 14:05:12 +01:00
|
|
|
'author' => [],
|
2018-04-25 02:12:43 +02:00
|
|
|
'version' => '',
|
2020-08-20 04:58:00 +02:00
|
|
|
'overwrites' => [],
|
|
|
|
'accented' => false,
|
2018-01-15 14:05:12 +01:00
|
|
|
];
|
2016-04-29 01:49:09 +02:00
|
|
|
|
2018-04-25 02:26:14 +02:00
|
|
|
if (!is_file($themepath . 'scheme/' . $scheme . '.php')) return $info;
|
2016-04-29 01:49:09 +02:00
|
|
|
|
2018-04-25 02:26:14 +02:00
|
|
|
$f = file_get_contents($themepath . 'scheme/' . $scheme . '.php');
|
2016-04-29 01:49:09 +02:00
|
|
|
|
2018-04-25 02:12:43 +02:00
|
|
|
$r = preg_match('|/\*.*\*/|msU', $f, $m);
|
2016-04-29 01:49:09 +02:00
|
|
|
|
2018-04-25 02:05:20 +02:00
|
|
|
if ($r) {
|
2016-04-29 01:49:09 +02:00
|
|
|
$ll = explode("\n", $m[0]);
|
2018-04-25 02:05:20 +02:00
|
|
|
foreach ($ll as $l) {
|
|
|
|
$l = trim($l, "\t\n\r */");
|
2018-04-25 02:12:43 +02:00
|
|
|
if ($l != '') {
|
2018-08-14 21:37:44 +02:00
|
|
|
$values = array_map('trim', explode(':', $l, 2));
|
|
|
|
if (count($values) < 2) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
list($k, $v) = $values;
|
2018-04-25 02:05:20 +02:00
|
|
|
$k = strtolower($k);
|
2018-04-25 02:12:43 +02:00
|
|
|
if ($k == 'author') {
|
|
|
|
$r = preg_match('|([^<]+)<([^>]+)>|', $v, $m);
|
2016-04-29 01:49:09 +02:00
|
|
|
if ($r) {
|
2018-04-25 02:05:20 +02:00
|
|
|
$info['author'][] = ['name' => $m[1], 'link' => $m[2]];
|
2016-04-29 01:49:09 +02:00
|
|
|
} else {
|
2018-04-25 02:05:20 +02:00
|
|
|
$info['author'][] = ['name' => $v];
|
2016-04-29 01:49:09 +02:00
|
|
|
}
|
2018-04-25 02:12:43 +02:00
|
|
|
} elseif ($k == 'overwrites') {
|
2018-04-25 02:05:20 +02:00
|
|
|
$theme_settings = explode(',', str_replace(' ', '', $v));
|
2016-04-29 01:49:09 +02:00
|
|
|
foreach ($theme_settings as $key => $value) {
|
2018-04-25 02:12:43 +02:00
|
|
|
$info['overwrites'][$value] = true;
|
2016-04-29 01:49:09 +02:00
|
|
|
}
|
2020-08-20 04:58:00 +02:00
|
|
|
} elseif ($k == 'accented') {
|
|
|
|
$info['accented'] = $v && $v != 'false' && $v != 'no';
|
2016-04-29 01:49:09 +02:00
|
|
|
} else {
|
2018-04-25 02:05:20 +02:00
|
|
|
if (array_key_exists($k, $info)) {
|
|
|
|
$info[$k] = $v;
|
2016-04-29 01:49:09 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2018-04-25 02:05:20 +02:00
|
|
|
|
2016-04-29 01:49:09 +02:00
|
|
|
return $info;
|
|
|
|
}
|