]> git.mxchange.org Git - friendica.git/blob - view/theme/frio/php/scheme.php
[frio] Prevent Enter from sending the form in ACL tags input in /compose
[friendica.git] / view / theme / frio / php / scheme.php
1 <?php
2
3 /**
4  * @brief: Get info header of the scheme
5  *
6  * This function parses the header of the schemename.php file for informations like
7  * Author, Description and Overwrites. Most of the code comes from the Addon::getInfo()
8  * function. We use this to get the variables which get overwritten through the scheme.
9  * All color variables which get overwritten through the theme have to be
10  * listed (comma separated) in the scheme header under Overwrites:
11  * This seems not to be the best solution. We need to investigate further.
12  *
13  * @param string $scheme Name of the scheme
14  * @return array With theme information
15  *    'author' => Author Name
16  *    'description' => Scheme description
17  *    'version' => Scheme version
18  *    'overwrites' => Variables which overwriting custom settings
19  */
20
21 use Friendica\Core\PConfig;
22 use Friendica\Util\Strings;
23
24 function get_scheme_info($scheme)
25 {
26         $theme = \get_app()->getCurrentTheme();
27         $themepath = 'view/theme/' . $theme . '/';
28         if (empty($scheme)) {
29                 $scheme = PConfig::get(local_user(), 'frio', 'scheme', PConfig::get(local_user(), 'frio', 'schema'));
30         }
31
32         $scheme = Strings::sanitizeFilePathItem($scheme);
33
34         $info = [
35                 'name' => $scheme,
36                 'description' => '',
37                 'author' => [],
38                 'version' => '',
39                 'overwrites' => []
40         ];
41
42         if (!is_file($themepath . 'scheme/' . $scheme . '.php')) return $info;
43
44         $f = file_get_contents($themepath . 'scheme/' . $scheme . '.php');
45
46         $r = preg_match('|/\*.*\*/|msU', $f, $m);
47
48         if ($r) {
49                 $ll = explode("\n", $m[0]);
50                 foreach ($ll as $l) {
51                         $l = trim($l, "\t\n\r */");
52                         if ($l != '') {
53                                 $values = array_map('trim', explode(':', $l, 2));
54                                 if (count($values) < 2) {
55                                         continue;
56                                 }
57                                 list($k, $v) = $values;
58                                 $k = strtolower($k);
59                                 if ($k == 'author') {
60                                         $r = preg_match('|([^<]+)<([^>]+)>|', $v, $m);
61                                         if ($r) {
62                                                 $info['author'][] = ['name' => $m[1], 'link' => $m[2]];
63                                         } else {
64                                                 $info['author'][] = ['name' => $v];
65                                         }
66                                 } elseif ($k == 'overwrites') {
67                                         $theme_settings = explode(',', str_replace(' ', '', $v));
68                                         foreach ($theme_settings as $key => $value) {
69                                                 $info['overwrites'][$value] = true;
70                                         }
71                                 } else {
72                                         if (array_key_exists($k, $info)) {
73                                                 $info[$k] = $v;
74                                         }
75                                 }
76                         }
77                 }
78         }
79
80         return $info;
81 }