]> git.mxchange.org Git - friendica.git/blob - view/theme/frio/php/scheme.php
old boot.php functions replaced in various places
[friendica.git] / view / theme / frio / php / scheme.php
1 <?php
2 /**
3  * @copyright Copyright (C) 2010-2022, the Friendica project
4  *
5  * @license GNU AGPL version 3 or any later version
6  *
7  * This program is free software: you can redistribute it and/or modify
8  * it under the terms of the GNU Affero General Public License as
9  * published by the Free Software Foundation, either version 3 of the
10  * License, or (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  * GNU Affero General Public License for more details.
16  *
17  * You should have received a copy of the GNU Affero General Public License
18  * along with this program.  If not, see <https://www.gnu.org/licenses/>.
19  *
20  * Get info header of the scheme
21  *
22  * This function parses the header of the schemename.php file for informations like
23  * Author, Description and Overwrites. Most of the code comes from the Addon::getInfo()
24  * function. We use this to get the variables which get overwritten through the scheme.
25  * All color variables which get overwritten through the theme have to be
26  * listed (comma separated) in the scheme header under Overwrites:
27  * This seems not to be the best solution. We need to investigate further.
28  *
29  * @param string $scheme Name of the scheme
30  * @return array With theme information
31  *    'author' => Author Name
32  *    'description' => Scheme description
33  *    'version' => Scheme version
34  *    'overwrites' => Variables which overwriting custom settings
35  */
36
37 use Friendica\Core\Session;
38 use Friendica\DI;
39 use Friendica\Util\Strings;
40
41 function get_scheme_info($scheme)
42 {
43         $theme = DI::app()->getCurrentTheme();
44         $themepath = 'view/theme/' . $theme . '/';
45         if (empty($scheme)) {
46                 $scheme = DI::pConfig()->get(Session::getLocalUser(), 'frio', 'scheme', DI::pConfig()->get(Session::getLocalUser(), 'frio', 'schema', '---'));
47         }
48
49         $scheme = Strings::sanitizeFilePathItem($scheme);
50
51         $info = [
52                 'name' => $scheme,
53                 'description' => '',
54                 'author' => [],
55                 'version' => '',
56                 'overwrites' => [],
57                 'accented' => false,
58         ];
59
60         if (!is_file($themepath . 'scheme/' . $scheme . '.php')) {
61                 return $info;
62         }
63
64         $f = file_get_contents($themepath . 'scheme/' . $scheme . '.php');
65
66         $r = preg_match('|/\*.*\*/|msU', $f, $m);
67
68         if ($r) {
69                 $ll = explode("\n", $m[0]);
70                 foreach ($ll as $l) {
71                         $l = trim($l, "\t\n\r */");
72                         if ($l != '') {
73                                 $values = array_map('trim', explode(':', $l, 2));
74                                 if (count($values) < 2) {
75                                         continue;
76                                 }
77                                 list($k, $v) = $values;
78                                 $k = strtolower($k);
79                                 if ($k == 'author') {
80                                         $r = preg_match('|([^<]+)<([^>]+)>|', $v, $m);
81                                         if ($r) {
82                                                 $info['author'][] = ['name' => $m[1], 'link' => $m[2]];
83                                         } else {
84                                                 $info['author'][] = ['name' => $v];
85                                         }
86                                 } elseif ($k == 'overwrites') {
87                                         $theme_settings = explode(',', str_replace(' ', '', $v));
88                                         foreach ($theme_settings as $key => $value) {
89                                                 $info['overwrites'][$value] = true;
90                                         }
91                                 } elseif ($k == 'accented') {
92                                         $info['accented'] = $v && $v != 'false' && $v != 'no';
93                                 } else {
94                                         if (array_key_exists($k, $info)) {
95                                                 $info[$k] = $v;
96                                         }
97                                 }
98                         }
99                 }
100         }
101
102         return $info;
103 }