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.
 
 
 
 
 

184 lines
5.2 KiB

  1. <?php
  2. /**
  3. * DokuWiki Bootstrap3 Template: CSS Asset Dispatcher
  4. *
  5. * @link http://dokuwiki.org/template:bootstrap3
  6. * @author Giuseppe Di Terlizzi <giuseppe.diterlizzi@gmail.com>
  7. * @license GPL 2 (http://www.gnu.org/licenses/gpl.html)
  8. */
  9. # NOTE Some Linux distributon change the location of DokuWiki core libraries (DOKU_INC)
  10. #
  11. # Bitnami (Docker) /opt/bitnami/dokuwiki
  12. # LinuxServer.io (Docker) /app/dokuwiki
  13. # Arch Linux /usr/share/webapps/dokuwiki
  14. # Debian/Ubuntu /usr/share/dokuwiki
  15. #
  16. # NOTE If DokuWiki core libraries (DOKU_INC) is in another location you can
  17. # create a PHP file in bootstrap3 root directory called "doku_inc.php" with
  18. # this content:
  19. #
  20. # <?php define('DOKU_INC', '/path/dokuwiki/');
  21. #
  22. # (!) This file will be deleted on every upgrade of template
  23. $doku_inc_dirs = array(
  24. '/opt/bitnami/dokuwiki', # Bitnami (Docker)
  25. '/usr/share/webapps/dokuwiki', # Arch Linux
  26. '/usr/share/dokuwiki', # Debian/Ubuntu
  27. '/app/dokuwiki', # LinuxServer.io (Docker),
  28. realpath(dirname(__FILE__) . '/../../../'), # Default DokuWiki path
  29. );
  30. # Load doku_inc.php file
  31. #
  32. if (file_exists(dirname(__FILE__) . '/doku_inc.php')) {
  33. require_once dirname(__FILE__) . '/doku_inc.php';
  34. }
  35. if (! defined('DOKU_INC')) {
  36. foreach ($doku_inc_dirs as $dir) {
  37. if (! defined('DOKU_INC') && @file_exists("$dir/inc/init.php")) {
  38. define('DOKU_INC', "$dir/");
  39. }
  40. }
  41. }
  42. // we do not use a session or authentication here (better caching)
  43. if (!defined('NOSESSION')) {
  44. define('NOSESSION', true);
  45. }
  46. if (!defined('NL')) {
  47. define('NL', "\n");
  48. }
  49. // we gzip ourself here
  50. if (!defined('DOKU_DISABLE_GZIP_OUTPUT')) {
  51. define('DOKU_DISABLE_GZIP_OUTPUT', 1);
  52. }
  53. function css_error($error)
  54. {
  55. echo "html:before {
  56. content: '$error';
  57. background-color: red;
  58. display: block;
  59. background-color: #fcc;
  60. border-color: #ebb;
  61. color: #000;
  62. padding: 0.5em;
  63. }";
  64. }
  65. // TODO remove this cache-control in future
  66. header("Cache-Control: no-store, no-cache, must-revalidate, max-age=0");
  67. header("Cache-Control: post-check=0, pre-check=0", false);
  68. header("Pragma: no-cache");
  69. header('Content-Type: text/css; charset=utf-8');
  70. if (!file_exists(DOKU_INC)) {
  71. $error = 'Problem with DOKU_INC directory. Please check your DokuWiki installation directory!';
  72. css_error($error);
  73. die;
  74. }
  75. require_once DOKU_INC . 'inc/init.php';
  76. global $INPUT;
  77. global $conf;
  78. global $ID;
  79. $ID = cleanID($INPUT->str('id', null));
  80. $bootstrap_theme = tpl_getConf('bootstrapTheme');
  81. $bootswatch_theme = tpl_getConf('bootswatchTheme');
  82. $custom_theme = tpl_getConf('customTheme');
  83. $theme_by_namespace = tpl_getConf('themeByNamespace');
  84. $tpl_basedir = tpl_basedir();
  85. $tpl_incdir = tpl_incdir();
  86. $themes_filename = DOKU_CONF . 'bootstrap3.themes.conf';
  87. $stylesheets = array();
  88. $bootswatch_themes = array('cerulean', 'cosmo', 'cyborg', 'darkly', 'flatly', 'journal', 'lumen', 'paper', 'readable', 'sandstone', 'simplex', 'solar', 'slate', 'spacelab', 'superhero', 'united', 'yeti');
  89. # Check Theme Switcher
  90. if (tpl_getConf('showThemeSwitcher')) {
  91. if (get_doku_pref('bootswatchTheme', null) !== null && get_doku_pref('bootswatchTheme', null) !== '') {
  92. $bootswatch_theme = get_doku_pref('bootswatchTheme', null);
  93. }
  94. if (!in_array($bootswatch_theme, $bootswatch_themes)) {
  95. $bootswatch_theme = 'default';
  96. }
  97. }
  98. # Check Theme by Namespace
  99. if ($theme_by_namespace && file_exists($themes_filename)) {
  100. $config = confToHash($themes_filename);
  101. krsort($config);
  102. $theme_found = false;
  103. foreach ($config as $page => $theme) {
  104. if (preg_match("/^$page/", "$ID")) {
  105. list($bootstrap_theme, $bootswatch_theme) = explode('/', $theme);
  106. if ($bootstrap_theme && in_array($bootstrap_theme, array('default', 'optional', 'custom'))) {
  107. $theme_found = true;
  108. break;
  109. }
  110. if ($bootstrap_theme == 'bootswatch' && in_array($bootswatch_theme, $bootswatch_themes)) {
  111. $theme_found = true;
  112. break;
  113. }
  114. }
  115. }
  116. }
  117. # Check $ID and unload the template
  118. if ($theme_by_namespace && file_exists($themes_filename) && !$ID) {
  119. $bootstrap_theme = 'none';
  120. }
  121. switch ($bootstrap_theme) {
  122. case 'optional':
  123. $stylesheets[] = 'assets/bootstrap/default/bootstrap.min.css';
  124. $stylesheets[] = 'assets/bootstrap/default/bootstrap-theme.min.css';
  125. break;
  126. case 'custom':
  127. $stylesheets[] = $custom_theme;
  128. break;
  129. case 'bootswatch':
  130. $bootswatch_url = 'assets/bootstrap';
  131. if (file_exists($tpl_incdir . "assets/fonts/$bootswatch_theme.fonts.css")) {
  132. $stylesheets[] = "assets/fonts/$bootswatch_theme.fonts.css";
  133. }
  134. $stylesheets[] = "$bootswatch_url/$bootswatch_theme/bootstrap.min.css";
  135. break;
  136. case 'none':
  137. break;
  138. case 'default':
  139. default:
  140. $stylesheets[] = 'assets/bootstrap/default/bootstrap.min.css';
  141. break;
  142. }
  143. $content = '';
  144. foreach ($stylesheets as $style) {
  145. $content .= "@import url($style);" . NL;
  146. }
  147. print $content;