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.

153 lines
7.6 KiB

  1. <?php
  2. use Friendica\App;
  3. use Friendica\Core\Config;
  4. use Friendica\Core\L10n;
  5. use Friendica\Core\PConfig;
  6. use Friendica\Core\Renderer;
  7. use Friendica\Core\System;
  8. require_once 'view/theme/frio/php/Image.php';
  9. function theme_post(App $a)
  10. {
  11. if (!local_user()) {
  12. return;
  13. }
  14. if (isset($_POST['frio-settings-submit'])) {
  15. PConfig::set(local_user(), 'frio', 'scheme', $_POST['frio_scheme'] ?? '');
  16. PConfig::set(local_user(), 'frio', 'nav_bg', $_POST['frio_nav_bg'] ?? '');
  17. PConfig::set(local_user(), 'frio', 'nav_icon_color', $_POST['frio_nav_icon_color'] ?? '');
  18. PConfig::set(local_user(), 'frio', 'link_color', $_POST['frio_link_color'] ?? '');
  19. PConfig::set(local_user(), 'frio', 'background_color', $_POST['frio_background_color'] ?? '');
  20. PConfig::set(local_user(), 'frio', 'contentbg_transp', $_POST['frio_contentbg_transp'] ?? '');
  21. PConfig::set(local_user(), 'frio', 'background_image', $_POST['frio_background_image'] ?? '');
  22. PConfig::set(local_user(), 'frio', 'bg_image_option', $_POST['frio_bg_image_option'] ?? '');
  23. PConfig::set(local_user(), 'frio', 'css_modified', time());
  24. PConfig::set(local_user(), 'frio', 'enable_compose', $_POST['frio_enable_compose'] ?? 0);
  25. }
  26. }
  27. function theme_admin_post(App $a)
  28. {
  29. if (!is_site_admin()) {
  30. return;
  31. }
  32. if (isset($_POST['frio-settings-submit'])) {
  33. Config::set('frio', 'scheme', $_POST['frio_scheme'] ?? '');
  34. Config::set('frio', 'nav_bg', $_POST['frio_nav_bg'] ?? '');
  35. Config::set('frio', 'nav_icon_color', $_POST['frio_nav_icon_color'] ?? '');
  36. Config::set('frio', 'link_color', $_POST['frio_link_color'] ?? '');
  37. Config::set('frio', 'background_color', $_POST['frio_background_color'] ?? '');
  38. Config::set('frio', 'contentbg_transp', $_POST['frio_contentbg_transp'] ?? '');
  39. Config::set('frio', 'background_image', $_POST['frio_background_image'] ?? '');
  40. Config::set('frio', 'bg_image_option', $_POST['frio_bg_image_option'] ?? '');
  41. Config::set('frio', 'login_bg_image', $_POST['frio_login_bg_image'] ?? '');
  42. Config::set('frio', 'login_bg_color', $_POST['frio_login_bg_color'] ?? '');
  43. Config::set('frio', 'css_modified', time());
  44. Config::set('frio', 'enable_compose', $_POST['frio_enable_compose'] ?? 0);
  45. }
  46. }
  47. function theme_content(App $a)
  48. {
  49. if (!local_user()) {
  50. return;
  51. }
  52. $arr = [];
  53. $node_scheme = Config::get('frio', 'scheme', Config::get('frio', 'scheme'));
  54. $arr['scheme'] = PConfig::get(local_user(), 'frio', 'scheme', PConfig::get(local_user(), 'frio', 'schema', $node_scheme));
  55. $arr['share_string'] = '';
  56. $arr['nav_bg'] = PConfig::get(local_user(), 'frio', 'nav_bg' , Config::get('frio', 'nav_bg'));
  57. $arr['nav_icon_color'] = PConfig::get(local_user(), 'frio', 'nav_icon_color' , Config::get('frio', 'nav_icon_color'));
  58. $arr['link_color'] = PConfig::get(local_user(), 'frio', 'link_color' , Config::get('frio', 'link_color'));
  59. $arr['background_color'] = PConfig::get(local_user(), 'frio', 'background_color', Config::get('frio', 'background_color'));
  60. $arr['contentbg_transp'] = PConfig::get(local_user(), 'frio', 'contentbg_transp', Config::get('frio', 'contentbg_transp'));
  61. $arr['background_image'] = PConfig::get(local_user(), 'frio', 'background_image', Config::get('frio', 'background_image'));
  62. $arr['bg_image_option'] = PConfig::get(local_user(), 'frio', 'bg_image_option' , Config::get('frio', 'bg_image_option'));
  63. $arr['enable_compose'] = PConfig::get(local_user(), 'frio', 'enable_compose' , Config::get('frio', 'enable_compose'));
  64. return frio_form($arr);
  65. }
  66. function theme_admin(App $a)
  67. {
  68. if (!local_user()) {
  69. return;
  70. }
  71. $arr = [];
  72. $arr['scheme'] = Config::get('frio', 'scheme', Config::get('frio', 'schema'));
  73. $arr['share_string'] = '';
  74. $arr['nav_bg'] = Config::get('frio', 'nav_bg');
  75. $arr['nav_icon_color'] = Config::get('frio', 'nav_icon_color');
  76. $arr['link_color'] = Config::get('frio', 'link_color');
  77. $arr['background_color'] = Config::get('frio', 'background_color');
  78. $arr['contentbg_transp'] = Config::get('frio', 'contentbg_transp');
  79. $arr['background_image'] = Config::get('frio', 'background_image');
  80. $arr['bg_image_option'] = Config::get('frio', 'bg_image_option');
  81. $arr['login_bg_image'] = Config::get('frio', 'login_bg_image');
  82. $arr['login_bg_color'] = Config::get('frio', 'login_bg_color');
  83. $arr['enable_compose'] = Config::get('frio', 'enable_compose');
  84. return frio_form($arr);
  85. }
  86. function frio_form($arr)
  87. {
  88. require_once 'view/theme/frio/php/scheme.php';
  89. $scheme_info = get_scheme_info($arr['scheme']);
  90. $disable = $scheme_info['overwrites'];
  91. if (!is_array($disable)) {
  92. $disable = [];
  93. }
  94. $scheme_choices = [];
  95. $scheme_choices['---'] = L10n::t('Custom');
  96. $files = glob('view/theme/frio/scheme/*.php');
  97. if ($files) {
  98. foreach ($files as $file) {
  99. $f = basename($file, '.php');
  100. if ($f != 'default') {
  101. $scheme_name = ucfirst($f);
  102. $scheme_choices[$f] = $scheme_name;
  103. }
  104. }
  105. }
  106. $background_image_help = '<strong>' . L10n::t('Note') . ': </strong>' . L10n::t('Check image permissions if all users are allowed to see the image');
  107. $t = Renderer::getMarkupTemplate('theme_settings.tpl');
  108. $ctx = [
  109. '$submit' => L10n::t('Submit'),
  110. '$title' => L10n::t('Theme settings'),
  111. '$scheme' => ['frio_scheme', L10n::t('Select color scheme'), $arr['scheme'], '', $scheme_choices],
  112. '$share_string' => ['frio_share_string', L10n::t('Copy or paste schemestring'), $arr['share_string'], L10n::t('You can copy this string to share your theme with others. Pasting here applies the schemestring'), false, false],
  113. '$nav_bg' => array_key_exists('nav_bg', $disable) ? '' : ['frio_nav_bg', L10n::t('Navigation bar background color'), $arr['nav_bg'], '', false],
  114. '$nav_icon_color' => array_key_exists('nav_icon_color', $disable) ? '' : ['frio_nav_icon_color', L10n::t('Navigation bar icon color '), $arr['nav_icon_color'], '', false],
  115. '$link_color' => array_key_exists('link_color', $disable) ? '' : ['frio_link_color', L10n::t('Link color'), $arr['link_color'], '', false],
  116. '$background_color' => array_key_exists('background_color', $disable) ? '' : ['frio_background_color', L10n::t('Set the background color'), $arr['background_color'], '', false],
  117. '$contentbg_transp' => array_key_exists('contentbg_transp', $disable) ? '' : ['frio_contentbg_transp', L10n::t('Content background opacity'), ($arr['contentbg_transp'] ?? 0) ?: 100, ''],
  118. '$background_image' => array_key_exists('background_image', $disable) ? '' : ['frio_background_image', L10n::t('Set the background image'), $arr['background_image'], $background_image_help, false],
  119. '$bg_image_options_title' => L10n::t('Background image style'),
  120. '$bg_image_options' => Image::get_options($arr),
  121. '$enable_compose' => ['frio_enable_compose', L10n::t('Enable Compose page'), $arr['enable_compose'], L10n::t('This replaces the jot modal window for writing new posts with a link to <a href="compose">the new Compose page</a>.')],
  122. ];
  123. if (array_key_exists('login_bg_image', $arr) && !array_key_exists('login_bg_image', $disable)) {
  124. $ctx['$login_bg_image'] = ['frio_login_bg_image', L10n::t('Login page background image'), $arr['login_bg_image'], $background_image_help, false];
  125. }
  126. if (array_key_exists('login_bg_color', $arr) && !array_key_exists('login_bg_color', $disable)) {
  127. $ctx['$login_bg_color'] = ['frio_login_bg_color', L10n::t('Login page background color'), $arr['login_bg_color'], L10n::t('Leave background image and color empty for theme defaults'), false];
  128. }
  129. $o = Renderer::replaceMacros($t, $ctx);
  130. return $o;
  131. }