]> git.mxchange.org Git - friendica.git/blob - view/theme/frio/php/scheme.php
Merge pull request #8991 from MrPetovan/task/restore-autocomplete-comment
[friendica.git] / view / theme / frio / php / scheme.php
1 <?php
2 /**
3  * @copyright Copyright (C) 2020, Friendica
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\DI;
38 use Friendica\Util\Strings;
39
40 function get_scheme_info($scheme)
41 {
42         $theme = DI::app()->getCurrentTheme();
43         $themepath = 'view/theme/' . $theme . '/';
44         if (empty($scheme)) {
45                 $scheme = DI::pConfig()->get(local_user(), 'frio', 'scheme', DI::pConfig()->get(local_user(), 'frio', 'schema'));
46         }
47
48         $scheme = Strings::sanitizeFilePathItem($scheme);
49
50         $info = [
51                 'name' => $scheme,
52                 'description' => '',
53                 'author' => [],
54                 'version' => '',
55                 'overwrites' => []
56         ];
57
58         if (!is_file($themepath . 'scheme/' . $scheme . '.php')) return $info;
59
60         $f = file_get_contents($themepath . 'scheme/' . $scheme . '.php');
61
62         $r = preg_match('|/\*.*\*/|msU', $f, $m);
63
64         if ($r) {
65                 $ll = explode("\n", $m[0]);
66                 foreach ($ll as $l) {
67                         $l = trim($l, "\t\n\r */");
68                         if ($l != '') {
69                                 $values = array_map('trim', explode(':', $l, 2));
70                                 if (count($values) < 2) {
71                                         continue;
72                                 }
73                                 list($k, $v) = $values;
74                                 $k = strtolower($k);
75                                 if ($k == 'author') {
76                                         $r = preg_match('|([^<]+)<([^>]+)>|', $v, $m);
77                                         if ($r) {
78                                                 $info['author'][] = ['name' => $m[1], 'link' => $m[2]];
79                                         } else {
80                                                 $info['author'][] = ['name' => $v];
81                                         }
82                                 } elseif ($k == 'overwrites') {
83                                         $theme_settings = explode(',', str_replace(' ', '', $v));
84                                         foreach ($theme_settings as $key => $value) {
85                                                 $info['overwrites'][$value] = true;
86                                         }
87                                 } else {
88                                         if (array_key_exists($k, $info)) {
89                                                 $info[$k] = $v;
90                                         }
91                                 }
92                         }
93                 }
94         }
95
96         return $info;
97 }