Friendica Communications Platform (please note that this is a clone of the repository at github, issues are handled there) https://friendi.ca
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

214 lines
7.3 KiB

  1. <?php
  2. /**
  3. * @file view/theme/frio/style.php
  4. */
  5. use Friendica\Core\Config;
  6. use Friendica\DI;
  7. use Friendica\Util\Strings;
  8. require_once 'view/theme/frio/php/PHPColors/Color.php';
  9. $scheme = '';
  10. $schemecss = '';
  11. $schemecssfile = false;
  12. $scheme_modified = 0;
  13. Config::load('frio');
  14. // Default to hard-coded values for empty settings
  15. $scheme = Config::get('frio', 'scheme', Config::get('frio', 'schema'));
  16. $nav_bg = Config::get('frio', 'nav_bg') ?: '#708fa0';
  17. $nav_icon_color = Config::get('frio', 'nav_icon_color') ?: '#ffffff';
  18. $link_color = Config::get('frio', 'link_color') ?: '#6fdbe8';
  19. $background_color = Config::get('frio', 'background_color') ?: '#ededed';
  20. $contentbg_transp = Config::get('frio', 'contentbg_transp') ?: '';
  21. $background_image = Config::get('frio', 'background_image') ?: 'img/none.png';
  22. $bg_image_option = Config::get('frio', 'bg_image_option') ?: '';
  23. $login_bg_image = Config::get('frio', 'login_bg_image') ?: '';
  24. $login_bg_color = Config::get('frio', 'login_bg_color') ?: '';
  25. $modified = Config::get('frio', 'css_modified') ?: time();
  26. if (!$login_bg_image && !$login_bg_color) {
  27. $login_bg_image = 'img/login_bg.jpg';
  28. }
  29. $login_bg_color = $login_bg_color ?: '#ededed';
  30. // Get the UID of the profile owner.
  31. $uid = $_REQUEST['puid'] ?? 0;
  32. if ($uid) {
  33. DI::pConfig()->load($uid, 'frio');
  34. // Only override display settings that have actually been set
  35. $scheme = DI::pConfig()->get($uid, 'frio', 'scheme', DI::pConfig()->get($uid, 'frio', 'schema')) ?: $scheme;
  36. $nav_bg = DI::pConfig()->get($uid, 'frio', 'nav_bg') ?: $nav_bg;
  37. $nav_icon_color = DI::pConfig()->get($uid, 'frio', 'nav_icon_color') ?: $nav_icon_color;
  38. $link_color = DI::pConfig()->get($uid, 'frio', 'link_color') ?: $link_color;
  39. $background_color = DI::pConfig()->get($uid, 'frio', 'background_color') ?: $background_color;
  40. $contentbg_transp = DI::pConfig()->get($uid, 'frio', 'contentbg_transp') ?: $contentbg_transp;
  41. $background_image = DI::pConfig()->get($uid, 'frio', 'background_image') ?: $background_image;
  42. $bg_image_option = DI::pConfig()->get($uid, 'frio', 'bg_image_option') ?: $bg_image_option;
  43. $modified = DI::pConfig()->get($uid, 'frio', 'css_modified') ?: $modified;
  44. }
  45. // Now load the scheme. If a value is changed above, we'll keep the settings
  46. // If not, we'll keep those defined by the scheme
  47. // Setting $scheme to '' wasn't working for some reason, so we'll check it's
  48. // not --- like the mobile theme does instead.
  49. // Allow layouts to over-ride the scheme.
  50. if (!empty($_REQUEST['scheme'])) {
  51. $scheme = $_REQUEST['scheme'];
  52. }
  53. $scheme = Strings::sanitizeFilePathItem($scheme);
  54. if (($scheme) && ($scheme != '---')) {
  55. if (file_exists('view/theme/frio/scheme/' . $scheme . '.php')) {
  56. $schemefile = 'view/theme/frio/scheme/' . $scheme . '.php';
  57. require_once $schemefile;
  58. }
  59. if (file_exists('view/theme/frio/scheme/' . $scheme . '.css')) {
  60. $schemecssfile = 'view/theme/frio/scheme/' . $scheme . '.css';
  61. }
  62. }
  63. // If we haven't got a scheme, load the default. We shouldn't touch this - we
  64. // should leave it for admins to define for themselves.
  65. // default.php and default.css MUST be symlinks to existing scheme files.
  66. if (!$scheme) {
  67. if (file_exists('view/theme/frio/scheme/default.php')) {
  68. $schemefile = 'view/theme/frio/scheme/default.php';
  69. require_once $schemefile;
  70. }
  71. if (file_exists('view/theme/frio/scheme/default.css')) {
  72. $schemecssfile = 'view/theme/frio/scheme/default.css';
  73. }
  74. }
  75. $contentbg_transp = ((isset($contentbg_transp) && $contentbg_transp != '') ? $contentbg_transp : 100);
  76. // Calculate some colors in dependance of existing colors.
  77. // Some colors are calculated to don't have too many selection
  78. // fields in the theme settings.
  79. if (!isset($menu_background_hover_color)) {
  80. $mbhc = new Color($nav_bg);
  81. $mcolor = $mbhc->getHex();
  82. if ($mbhc->isLight($mcolor, 75)) {
  83. $menu_is = 'light';
  84. $menu_background_hover_color = '#' . $mbhc->darken(5);
  85. } else {
  86. $menu_is = 'dark';
  87. $menu_background_hover_color = '#' . $mbhc->lighten(5);
  88. }
  89. }
  90. if (!isset($nav_icon_hover_color)) {
  91. $nihc = new Color($nav_bg);
  92. if ($nihc->isLight()) {
  93. $nav_icon_hover_color = '#' . $nihc->darken(10);
  94. } else {
  95. $nav_icon_hover_color = '#' . $nihc->lighten(10);
  96. }
  97. }
  98. if (!isset($link_hover_color)) {
  99. $lhc = new Color($link_color);
  100. $lcolor = $lhc->getHex();
  101. if ($lhc->isLight($lcolor, 75)) {
  102. $link_hover_color = '#' . $lhc->darken(5);
  103. } else {
  104. $link_hover_color = '#' . $lhc->lighten(5);
  105. }
  106. }
  107. // Convert $bg_image_options into css.
  108. if (!isset($bg_image_option)) {
  109. $bg_image_option = null;
  110. }
  111. switch ($bg_image_option) {
  112. case 'stretch':
  113. $background_size_img = '100%';
  114. $background_repeat = 'no-repeat';
  115. break;
  116. case 'cover':
  117. $background_size_img = 'cover';
  118. $background_repeat = 'no-repeat';
  119. break;
  120. case 'repeat':
  121. $background_size_img = 'auto';
  122. $background_repeat = 'repeat';
  123. break;
  124. case 'contain':
  125. $background_size_img = 'contain';
  126. $background_repeat = 'repeat';
  127. break;
  128. default:
  129. $background_size_img = 'auto';
  130. $background_repeat = 'no-repeat';
  131. break;
  132. }
  133. // Convert transparency level from percentage to opacity value.
  134. $contentbg_transp = $contentbg_transp / 100;
  135. $options = [
  136. '$nav_bg' => $nav_bg,
  137. '$nav_icon_color' => $nav_icon_color,
  138. '$nav_icon_hover_color' => $nav_icon_hover_color,
  139. '$link_color' => $link_color,
  140. '$link_hover_color' => $link_hover_color,
  141. '$menu_background_hover_color' => $menu_background_hover_color,
  142. '$btn_primary_color' => $nav_icon_color,
  143. '$btn_primary_hover_color' => $menu_background_hover_color,
  144. '$background_color' => $background_color,
  145. '$contentbg_transp' => $contentbg_transp,
  146. '$background_image' => $background_image,
  147. '$background_size_img' => $background_size_img,
  148. '$background_repeat' => $background_repeat,
  149. '$login_bg_image' => $login_bg_image,
  150. '$login_bg_color' => $login_bg_color
  151. ];
  152. $css_tpl = file_get_contents('view/theme/frio/css/style.css');
  153. // Get the content of the scheme css file and the time of the last file change.
  154. if ($schemecssfile) {
  155. $css_tpl .= file_get_contents($schemecssfile);
  156. $scheme_modified = filemtime($schemecssfile);
  157. }
  158. // We need to check which is the most recent css data.
  159. // We will use this time later to decide if we load the cached or fresh css data.
  160. if ($scheme_modified > $modified) {
  161. $modified = $scheme_modified;
  162. }
  163. // Apply the settings to the css template.
  164. $css = str_replace(array_keys($options), array_values($options), $css_tpl);
  165. $modified = gmdate('r', $modified);
  166. $etag = md5($css);
  167. // Set a header for caching.
  168. header('Cache-Control: public');
  169. header('ETag: "' . $etag . '"');
  170. header('Last-Modified: ' . $modified);
  171. // Only send the CSS file if it was changed.
  172. /// @todo Check if this works at all (possibly clients are sending only the one or the other header) - compare with mod/photo.php
  173. if (isset($_SERVER['HTTP_IF_MODIFIED_SINCE']) && isset($_SERVER['HTTP_IF_NONE_MATCH'])) {
  174. $cached_modified = gmdate('r', strtotime($_SERVER['HTTP_IF_MODIFIED_SINCE']));
  175. $cached_etag = str_replace(['"', '-gzip'], ['', ''],
  176. stripslashes($_SERVER['HTTP_IF_NONE_MATCH']));
  177. if (($cached_modified == $modified) && ($cached_etag == $etag)) {
  178. header('HTTP/1.1 304 Not Modified');
  179. exit();
  180. }
  181. }
  182. echo $css;