]> git.mxchange.org Git - friendica.git/blob - style.php
README: Add link to commit history
[friendica.git] / style.php
1 <?php
2 require_once('view/theme/frio/php/PHPColors/Color.php');
3
4
5 if(! $a->install) {
6         // Get the UID of the channel owner
7         $uid = get_theme_uid();
8         if($uid) {
9                 load_pconfig($uid,'frio');
10         }
11         // Load the owners pconfig
12         $schema         = get_pconfig($uid, "frio", "schema");
13         $nav_bg         = get_pconfig($uid, "frio", "nav_bg");
14         $nav_icon_color = get_pconfig($uid, "frio", "nav_icon_color");
15         $link_color     = get_pconfig($uid, "frio", "link_color");
16         $bgcolor        = get_pconfig($uid, "frio", "background_color");
17         $contentbg_transp = get_pconfig($uid, "frio", "contentbg_transp");
18         $background_image = get_pconfig($uid, "frio", "background_image");
19         $bg_image_option = get_pconfig($uid, "frio", "bg_image_option");
20 }
21
22 // Now load the scheme.  If a value is changed above, we'll keep the settings
23 // If not, we'll keep those defined by the schema
24 // Setting $schema to '' wasn't working for some reason, so we'll check it's
25 // not --- like the mobile theme does instead.
26 // Allow layouts to over-ride the schema
27 if($_REQUEST['schema']) {
28         $schema = $_REQUEST['schema'];
29 }
30 if (($schema) && ($schema != '---')) {
31         // Check it exists, because this setting gets distributed to clones
32         if(file_exists('view/theme/frio/schema/' . $schema . '.php')) {
33                 $schemefile = 'view/theme/frio/schema/' . $schema . '.php';
34                 require_once ($schemefile);
35         }
36         if(file_exists('view/theme/frio/schema/' . $schema . '.css')) {
37                 $schemecss = file_get_contents('view/theme/frio/schema/' . $schema . '.css');
38         }
39 }
40
41 // If we haven't got a schema, load the default.  We shouldn't touch this - we
42 // should leave it for admins to define for themselves.
43 // default.php and default.css MUST be symlinks to existing schema files.
44 if (! $schema) {
45         if(file_exists('view/theme/frio/schema/default.php')) {
46                 $schemefile = 'view/theme/frio/schema/default.php';
47                 require_once ($schemefile);
48         }
49         if(file_exists('view/theme/frio/schema/default.css')) {
50                 $schemecss = file_get_contents('view/theme/frio/schema/default.css');
51         }
52 }
53
54 //Set some defaults - we have to do this after pulling owner settings, and we have to check for each setting
55 //individually.  If we don't, we'll have problems if a user has set one, but not all options.
56 if(! $nav_bg)
57         $nav_bg = "#708fa0";
58 if(! $nav_icon_color)
59         $nav_icon_color = "#fff";
60 if(! $link_color)
61         $link_color = "#6fdbe8";
62 if(! $bgcolor)
63         $bgcolor = "#ededed";
64 if(! $contentbg_transp)
65         $contentbg_transp = 100;
66 if(! $background_image)
67         $background_image ='';
68
69 // Calculate some colors in dependance of existing colors
70 // Some colors are calculated to don't have too many selection
71 // fields in the theme settings
72 if(! $menu_background_hover_color) {
73         $mbhc = new Color($nav_bg);
74         $mcolor = $mbhc->getHex();
75
76         if($mbhc->isLight($mcolor, 75)) {
77                 $menu_is = 'light';
78                 $menu_background_hover_color = '#' . $mbhc->darken(5);
79         } else {
80                 $menu_is = 'dark';
81                 $menu_background_hover_color = '#' . $mbhc->lighten(5);
82         //$menu_background_hover_color = "#628394";
83         }
84 }
85 if(! $nav_icon_hover_color) {
86         $nihc = new Color($nav_bg);
87
88         if($nihc->isLight())
89                 $nav_icon_hover_color = '#' . $nihc->darken(10);
90         else
91                 $nav_icon_hover_color = '#' . $nihc->lighten(10);
92 }
93 if(! $link_hover_color) {
94         $lhc = new Color($link_color);
95         $lcolor = $lhc->getHex();
96
97         if($lhc->isLight($lcolor, 75)) {
98                 $link_hover_color = '#' . $lhc->darken(5);
99         } else {
100                 $link_hover_color = '#' . $lhc->lighten(5);
101         }
102
103 }
104
105 // Convert $bg_image_options into css
106 switch ($bg_image_option) {
107         case "stretch":
108                 $background_size_img = "100%";
109                 break;
110         case "cover":
111                 $background_size_img ="cover";
112                 break;
113         case "repeat":
114                 $background_size_img = "auto";
115                 break;
116         case "contain":
117                 $background_size_img = "contain";
118                 break;
119
120         default:
121                 $background_size_img = "auto";
122                 break;
123 }
124
125 // Convert transparency level from percentage to opacity value
126 $contentbg_transp = $contentbg_transp / 100;
127
128
129 // Apply the settings
130 if(file_exists('view/theme/frio/css/style.css')) {
131         $x = file_get_contents('view/theme/frio/css/style.css');
132
133         $options = array (
134                 '$nav_bg'                       => $nav_bg,
135                 '$nav_icon_color'               => $nav_icon_color,
136                 '$nav_icon_hover_color'         => $nav_icon_hover_color,
137                 '$link_color'                   => $link_color,
138                 '$link_hover_color'             => $link_hover_color,
139                 '$menu_background_hover_color'  => $menu_background_hover_color,
140                 '$btn_primary_color'            => $nav_icon_color,
141                 '$btn_primary_hover_color'      => $menu_background_hover_color,
142                 '$bgcolor'                      => $bgcolor,
143                 '$contentbg_transp'             => $contentbg_transp,
144                 '$background_image'             => $background_image,
145                 '$background_size_img'          => $background_size_img,
146         );
147
148         echo str_replace(array_keys($options), array_values($options), $x);
149 }
150
151 if($schemecss) {
152         echo $schemecss;
153 }