PageRenderTime 31ms CodeModel.GetById 22ms RepoModel.GetById 0ms app.codeStats 0ms

/theme/formal_white/lib.php

https://github.com/jamiepratt/moodle
PHP | 368 lines | 216 code | 54 blank | 98 comment | 28 complexity | dc5df39d87dd7736e6148ea19f1c4ece MD5 | raw file
  1. <?php
  2. // This file is part of Moodle - http://moodle.org/
  3. //
  4. // Moodle is free software: you can redistribute it and/or modify
  5. // it under the terms of the GNU General Public License as published by
  6. // the Free Software Foundation, either version 3 of the License, or
  7. // (at your option) any later version.
  8. //
  9. // Moodle is distributed in the hope that it will be useful,
  10. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. // GNU General Public License for more details.
  13. //
  14. // You should have received a copy of the GNU General Public License
  15. // along with Moodle. If not, see <http://www.gnu.org/licenses/>.
  16. /**
  17. * Moodle's formal_white theme
  18. *
  19. * DO NOT MODIFY THIS THEME!
  20. * COPY IT FIRST, THEN RENAME THE COPY AND MODIFY IT INSTEAD.
  21. *
  22. * For full information about creating Moodle themes, see:
  23. * http://docs.moodle.org/dev/Themes_2.0
  24. *
  25. * @package theme_formal_white
  26. * @copyright 2013 Mediatouch 2000, mediatouch.it
  27. * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  28. */
  29. defined('MOODLE_INTERNAL') || die();
  30. /**
  31. * Makes our changes to the CSS
  32. *
  33. * @param string $css
  34. * @param theme_config $theme
  35. * @return string
  36. */
  37. function formal_white_user_settings($css, $theme) {
  38. // Set the font reference size
  39. if (empty($theme->settings->fontsizereference)) {
  40. $fontsizereference = '13'; // default
  41. } else {
  42. $fontsizereference = $theme->settings->fontsizereference;
  43. }
  44. $css = formal_white_set_fontsizereference($css, $fontsizereference);
  45. // Set the frame margin
  46. if (!isset($theme->settings->framemargin)) {
  47. $framemargin = 15; // default
  48. } else {
  49. $framemargin = $theme->settings->framemargin;
  50. }
  51. $css = formal_white_set_framemargin($css, $framemargin);
  52. // Set the images according to color trend
  53. if (!isset($theme->settings->trendcolor)) {
  54. $trendcolor = 'mink'; // default
  55. } else {
  56. $trendcolor = $theme->settings->trendcolor;
  57. }
  58. $css = formal_white_set_trendcolor($css, $trendcolor);
  59. // Set the page header background color
  60. if (empty($theme->settings->headerbgc)) {
  61. $headerbgc = '#E3DFD4'; // default
  62. } else {
  63. $headerbgc = $theme->settings->headerbgc;
  64. }
  65. $css = formal_white_set_headerbgc($css, $headerbgc);
  66. // Set the block content background color
  67. if (empty($theme->settings->blockcontentbgc)) {
  68. $blockcontentbgc = '#F6F6F6'; // default
  69. } else {
  70. $blockcontentbgc = $theme->settings->blockcontentbgc;
  71. }
  72. $css = formal_white_set_blockcontentbgc($css, $blockcontentbgc);
  73. // Set the left block column background color
  74. if (empty($theme->settings->lblockcolumnbgc)) {
  75. $lblockcolumnbgc = '#E3DFD4'; // default
  76. } else {
  77. $lblockcolumnbgc = $theme->settings->lblockcolumnbgc;
  78. }
  79. $css = formal_white_set_lblockcolumnbgc($css, $lblockcolumnbgc);
  80. // Set the right block column background color
  81. if (empty($theme->settings->rblockcolumnbgc)) {
  82. $rblockcolumnbgc = $lblockcolumnbgc; // default
  83. } else {
  84. $rblockcolumnbgc = $theme->settings->rblockcolumnbgc;
  85. }
  86. $css = formal_white_set_rblockcolumnbgc($css, $rblockcolumnbgc);
  87. // set the width of the two blocks columns
  88. if (!empty($theme->settings->blockcolumnwidth)) {
  89. $blockcolumnwidth = $theme->settings->blockcolumnwidth;
  90. } else {
  91. $blockcolumnwidth = '200'; // default
  92. }
  93. $css = formal_white_set_blockcolumnwidth($css, $blockcolumnwidth);
  94. // set blocks margin
  95. if (!empty($theme->settings->blockpadding)) {
  96. $blockpadding = $theme->settings->blockpadding;
  97. } else {
  98. $blockpadding = '8'; // default
  99. }
  100. $css = formal_white_set_blockpadding($css, $blockcolumnwidth, $blockpadding);
  101. // set the customcss
  102. if (!empty($theme->settings->customcss)) {
  103. $customcss = $theme->settings->customcss;
  104. } else {
  105. $customcss = null;
  106. }
  107. $css = formal_white_set_customcss($css, $customcss);
  108. return $css;
  109. }
  110. /**
  111. * Sets the link color variable in CSS
  112. *
  113. */
  114. function formal_white_set_fontsizereference($css, $fontsizereference) {
  115. $tag = '[[setting:fontsizereference]]';
  116. $css = str_replace($tag, $fontsizereference.'px', $css);
  117. return $css;
  118. }
  119. function formal_white_set_framemargin($css, $framemargin) {
  120. $tag = '[[setting:framemargin]]';
  121. $css = str_replace($tag, $framemargin.'px', $css);
  122. // Set .headermenu margin
  123. $calculated = $framemargin + 22; // 17px is the width of the frame; 5px to avoid to have all stuck
  124. $tag = '[[calculated:headermenumargin]]';
  125. $css = str_replace($tag, $calculated.'px', $css);
  126. return $css;
  127. }
  128. function formal_white_set_trendcolor($css, $trendcolor) {
  129. // __setting_trendcolor__ is part of URLS so it is already between double square bracket.
  130. // I can not enclose it between double square bracket once again otherwise images path parser get confused.
  131. $tag = urlencode('__setting_trendcolor__'); // urlencode is useless but it is correct to put it here
  132. $css = str_replace($tag, $trendcolor, $css);
  133. // of the basis of the general choosed trend, I need some colour definition.
  134. switch ($trendcolor) {
  135. case 'blueberry':
  136. // .courses .coursebox
  137. $tag = '[[setting:hovercolor]]';
  138. $css = str_replace($tag, '#CEE5FD', $css);
  139. // page background
  140. $tag = '[[setting:pagebackground]]';
  141. $css = str_replace($tag, '#DAF1FF', $css);
  142. // block header background
  143. $tag = '[[setting:blockheaderbackground]]';
  144. $css = str_replace($tag, '#CDE2F3', $css);
  145. break;
  146. case 'lemon':
  147. // .courses .coursebox
  148. $tag = '[[setting:hovercolor]]';
  149. $css = str_replace($tag, '#FFEA68', $css);
  150. // page background
  151. $tag = '[[setting:pagebackground]]';
  152. $css = str_replace($tag, '#FFEB9A', $css);
  153. // block header background
  154. $tag = '[[setting:blockheaderbackground]]';
  155. $css = str_replace($tag, '#F7DA41', $css);
  156. break;
  157. case 'lime':
  158. // .courses .coursebox
  159. $tag = '[[setting:hovercolor]]';
  160. $css = str_replace($tag, '#EBEDB1', $css);
  161. // page background
  162. $tag = '[[setting:pagebackground]]';
  163. $css = str_replace($tag, '#F0F5BB', $css);
  164. // block header background
  165. $tag = '[[setting:blockheaderbackground]]';
  166. $css = str_replace($tag, '#E2E499', $css);
  167. break;
  168. case 'mink':
  169. // .courses .coursebox
  170. $tag = '[[setting:hovercolor]]';
  171. $css = str_replace($tag, '#E3DFD4', $css);
  172. // page background
  173. $tag = '[[setting:pagebackground]]';
  174. $css = str_replace($tag, '#EFEFEF', $css);
  175. // block header background
  176. $tag = '[[setting:blockheaderbackground]]';
  177. $css = str_replace($tag, '#E3DFD4', $css);
  178. break;
  179. case 'orange':
  180. // .courses .coursebox
  181. $tag = '[[setting:hovercolor]]';
  182. $css = str_replace($tag, '#FFCF88', $css);
  183. // page background
  184. $tag = '[[setting:pagebackground]]';
  185. $css = str_replace($tag, '#FFD46C', $css);
  186. // block header background
  187. $tag = '[[setting:blockheaderbackground]]';
  188. $css = str_replace($tag, '#FDC06D', $css);
  189. break;
  190. case 'peach':
  191. // .courses .coursebox
  192. $tag = '[[setting:hovercolor]]';
  193. $css = str_replace($tag, '#FFCEB8', $css);
  194. // page background
  195. $tag = '[[setting:pagebackground]]';
  196. $css = str_replace($tag, '#FCD3BC', $css);
  197. // block header background
  198. $tag = '[[setting:blockheaderbackground]]';
  199. $css = str_replace($tag, '#F7C099', $css);
  200. break;
  201. case 'silver':
  202. // .courses .coursebox
  203. $tag = '[[setting:hovercolor]]';
  204. $css = str_replace($tag, '#E0DFDD', $css);
  205. // page background
  206. $tag = '[[setting:pagebackground]]';
  207. $css = str_replace($tag, '#EFF0F2', $css);
  208. // block header background
  209. $tag = '[[setting:blockheaderbackground]]';
  210. $css = str_replace($tag, '#E0DFDD', $css);
  211. break;
  212. default:
  213. debugging('It seems a colour has been added to the formal_white trend colours folder but was not fully managed. The code must be updated by a developer.');
  214. }
  215. return $css;
  216. }
  217. function formal_white_set_headerbgc($css, $headerbgc) {
  218. $tag = '[[setting:headerbgc]]';
  219. $css = str_replace($tag, $headerbgc, $css);
  220. return $css;
  221. }
  222. function formal_white_set_blockcontentbgc($css, $blockcontentbgc) {
  223. $tag = '[[setting:blockcontentbgc]]';
  224. $css = str_replace($tag, $blockcontentbgc, $css);
  225. return $css;
  226. }
  227. function formal_white_set_lblockcolumnbgc($css, $lblockcolumnbgc) {
  228. $tag = '[[setting:lblockcolumnbgc]]';
  229. $css = str_replace($tag, $lblockcolumnbgc, $css);
  230. return $css;
  231. }
  232. function formal_white_set_rblockcolumnbgc($css, $rblockcolumnbgc) {
  233. $tag = '[[setting:rblockcolumnbgc]]';
  234. $css = str_replace($tag, $rblockcolumnbgc, $css);
  235. return $css;
  236. }
  237. function formal_white_set_blockcolumnwidth($css, $blockcolumnwidth) {
  238. $tag = '[[setting:blockcolumnwidth]]';
  239. $css = str_replace($tag, $blockcolumnwidth.'px', $css);
  240. $calculated = -2*$blockcolumnwidth;
  241. $tag = '[[calculated:minusdoubleblockcolumnwidth]]';
  242. $css = str_replace($tag, $calculated.'px', $css);
  243. $calculated = 2*$blockcolumnwidth;
  244. $tag = '[[calculated:doubleblockcolumnwidth]]';
  245. $css = str_replace($tag, $calculated.'px', $css);
  246. // set the min-width of the page to provide: content region min-width = block region width
  247. // I do not care $framemargin because the min-width applies to #frametop that is free from $framemargin
  248. // I need to add twice the width of the frame because it is inside #frametop
  249. // (this code here because it HAS TO come later than $blockcolumnwidth definition)
  250. $calculated = 3*$blockcolumnwidth + 34; // 34 = 2*17 (17px is the width of the frame)
  251. $tag = '[[calculated:minwidth]]';
  252. $css = str_replace($tag, $calculated.'px', $css);
  253. return $css;
  254. }
  255. function formal_white_set_blockpadding($css, $blockcolumnwidth, $blockpadding) {
  256. $tag = '[[setting:blockpadding]]';
  257. $css = str_replace($tag, $blockpadding.'px', $css);
  258. // I need to know the field width in pixel because width:100%; and width:auto; don't work as expected
  259. // once $blockcolumnwidth and $blockpadding are known, $lb_fieldswidth can be applied
  260. // the process has not been optimized at all but it is executed only once
  261. $lb_fieldswidth = $blockcolumnwidth;
  262. // #page-content .region-content {padding:[[setting:blockpadding]] [[setting:blockpadding]] 0 [[setting:blockpadding]];} in pagelayout.css
  263. $lb_fieldswidth -= 2*$blockpadding;
  264. // .block {border:[[static:lb_blockborderwidth]] solid #C6BDA8; [...] }
  265. $lb_fieldsborderwidth = 1;
  266. $tag = '[[static:lb_blockborderwidth]]'; // It is static, it is not a setting. I just hardcoded its definition here.
  267. $css = str_replace($tag, $lb_fieldsborderwidth.'px', $css);
  268. $lb_fieldswidth -= 2*$lb_fieldsborderwidth;
  269. // .block_login .content {padding:[[static:lb_contentpadding]];}
  270. $lb_fieldspadding = 4;
  271. $tag = '[[static:lb_contentpadding]]'; // It is static, it is not a setting. I just hardcoded its definition here.
  272. $css = str_replace($tag, $lb_fieldspadding.'px', $css);
  273. $lb_fieldswidth -= 2*$lb_fieldspadding;
  274. // .block_login #login_username, .block_login #login_password {margin:4px 0 4px [[static:lb_fieldsmargin]];}
  275. $lb_fieldsmargin = 14;
  276. $tag = '[[static:lb_fieldsmargin]]'; // It is static, it is not a setting. I just hardcoded its definition here.
  277. $css = str_replace($tag, $lb_fieldsmargin.'px', $css);
  278. $lb_fieldswidth -= $lb_fieldsmargin; // without 2* because it is only left margin
  279. // fields default factory border: 3px
  280. $lb_fieldswidth -= 2*3;
  281. // leave few pixel on the right reducing once again the field length
  282. $lb_fieldswidth -= 12;
  283. $tag = '[[static:lb_fieldswidth]]';
  284. $css = str_replace($tag, $lb_fieldswidth.'px', $css);
  285. return $css;
  286. }
  287. function formal_white_set_customcss($css, $customcss) {
  288. $tag = '[[setting:customcss]]';
  289. $css = str_replace($tag, $customcss, $css);
  290. return $css;
  291. }
  292. /**
  293. * Serves formal white files.
  294. *
  295. * @param stdClass $course
  296. * @param stdClass $cm
  297. * @param context $context
  298. * @param string $filearea
  299. * @param type $args
  300. * @param array $forcedownload
  301. * @param array $options
  302. * @return bool
  303. */
  304. function theme_formal_white_pluginfile($course, $cm, $context, $filearea, $args, $forcedownload, array $options = array()) {
  305. if ($context->contextlevel == CONTEXT_SYSTEM and $filearea === 'customlogourl') {
  306. $theme = theme_config::load('formal_white');
  307. return $theme->setting_file_serve('customlogourl', $args, $forcedownload, $options);
  308. } else if ($context->contextlevel == CONTEXT_SYSTEM and $filearea === 'frontpagelogourl') {
  309. $theme = theme_config::load('formal_white');
  310. return $theme->setting_file_serve('frontpagelogourl', $args, $forcedownload, $options);
  311. } else {
  312. send_file_not_found();
  313. }
  314. }