]> git.mxchange.org Git - friendica.git/blob - view/theme/frio/php/scheme.php
Merge pull request #8055 from nupplaphil/task/remove_get_server
[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\DI;
23 use Friendica\Util\Strings;
24
25 function get_scheme_info($scheme)
26 {
27         $theme = DI::app()->getCurrentTheme();
28         $themepath = 'view/theme/' . $theme . '/';
29         if (empty($scheme)) {
30                 $scheme = PConfig::get(local_user(), 'frio', 'scheme', PConfig::get(local_user(), 'frio', 'schema'));
31         }
32
33         $scheme = Strings::sanitizeFilePathItem($scheme);
34
35         $info = [
36                 'name' => $scheme,
37                 'description' => '',
38                 'author' => [],
39                 'version' => '',
40                 'overwrites' => []
41         ];
42
43         if (!is_file($themepath . 'scheme/' . $scheme . '.php')) return $info;
44
45         $f = file_get_contents($themepath . 'scheme/' . $scheme . '.php');
46
47         $r = preg_match('|/\*.*\*/|msU', $f, $m);
48
49         if ($r) {
50                 $ll = explode("\n", $m[0]);
51                 foreach ($ll as $l) {
52                         $l = trim($l, "\t\n\r */");
53                         if ($l != '') {
54                                 $values = array_map('trim', explode(':', $l, 2));
55                                 if (count($values) < 2) {
56                                         continue;
57                                 }
58                                 list($k, $v) = $values;
59                                 $k = strtolower($k);
60                                 if ($k == 'author') {
61                                         $r = preg_match('|([^<]+)<([^>]+)>|', $v, $m);
62                                         if ($r) {
63                                                 $info['author'][] = ['name' => $m[1], 'link' => $m[2]];
64                                         } else {
65                                                 $info['author'][] = ['name' => $v];
66                                         }
67                                 } elseif ($k == 'overwrites') {
68                                         $theme_settings = explode(',', str_replace(' ', '', $v));
69                                         foreach ($theme_settings as $key => $value) {
70                                                 $info['overwrites'][$value] = true;
71                                         }
72                                 } else {
73                                         if (array_key_exists($k, $info)) {
74                                                 $info[$k] = $v;
75                                         }
76                                 }
77                         }
78                 }
79         }
80
81         return $info;
82 }