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