PageRenderTime 63ms CodeModel.GetById 15ms RepoModel.GetById 1ms app.codeStats 0ms

/lib/outputlib.php

https://github.com/dongsheng/moodle
PHP | 2683 lines | 1433 code | 290 blank | 960 comment | 278 complexity | 2bb13ab4038a63c421e7ff25dcaa9425 MD5 | raw file
Possible License(s): BSD-3-Clause, MIT, GPL-3.0, Apache-2.0, LGPL-2.1

Large files files are truncated, but you can click here to view the full 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. * Functions for generating the HTML that Moodle should output.
  18. *
  19. * Please see http://docs.moodle.org/en/Developement:How_Moodle_outputs_HTML
  20. * for an overview.
  21. *
  22. * @copyright 2009 Tim Hunt
  23. * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  24. * @package core
  25. * @category output
  26. */
  27. defined('MOODLE_INTERNAL') || die();
  28. require_once($CFG->libdir.'/outputcomponents.php');
  29. require_once($CFG->libdir.'/outputactions.php');
  30. require_once($CFG->libdir.'/outputfactories.php');
  31. require_once($CFG->libdir.'/outputrenderers.php');
  32. require_once($CFG->libdir.'/outputrequirementslib.php');
  33. /**
  34. * Returns current theme revision number.
  35. *
  36. * @return int
  37. */
  38. function theme_get_revision() {
  39. global $CFG;
  40. if (empty($CFG->themedesignermode)) {
  41. if (empty($CFG->themerev)) {
  42. // This only happens during install. It doesn't matter what themerev we use as long as it's positive.
  43. return 1;
  44. } else {
  45. return $CFG->themerev;
  46. }
  47. } else {
  48. return -1;
  49. }
  50. }
  51. /**
  52. * Returns current theme sub revision number. This is the revision for
  53. * this theme exclusively, not the global theme revision.
  54. *
  55. * @param string $themename The non-frankenstyle name of the theme
  56. * @return int
  57. */
  58. function theme_get_sub_revision_for_theme($themename) {
  59. global $CFG;
  60. if (empty($CFG->themedesignermode)) {
  61. $pluginname = "theme_{$themename}";
  62. $revision = during_initial_install() ? null : get_config($pluginname, 'themerev');
  63. if (empty($revision)) {
  64. // This only happens during install. It doesn't matter what themerev we use as long as it's positive.
  65. return 1;
  66. } else {
  67. return $revision;
  68. }
  69. } else {
  70. return -1;
  71. }
  72. }
  73. /**
  74. * Calculates and returns the next theme revision number.
  75. *
  76. * @return int
  77. */
  78. function theme_get_next_revision() {
  79. global $CFG;
  80. $next = time();
  81. if (isset($CFG->themerev) and $next <= $CFG->themerev and $CFG->themerev - $next < 60*60) {
  82. // This resolves problems when reset is requested repeatedly within 1s,
  83. // the < 1h condition prevents accidental switching to future dates
  84. // because we might not recover from it.
  85. $next = $CFG->themerev+1;
  86. }
  87. return $next;
  88. }
  89. /**
  90. * Calculates and returns the next theme revision number.
  91. *
  92. * @param string $themename The non-frankenstyle name of the theme
  93. * @return int
  94. */
  95. function theme_get_next_sub_revision_for_theme($themename) {
  96. global $CFG;
  97. $next = time();
  98. $current = theme_get_sub_revision_for_theme($themename);
  99. if ($next <= $current and $current - $next < 60 * 60) {
  100. // This resolves problems when reset is requested repeatedly within 1s,
  101. // the < 1h condition prevents accidental switching to future dates
  102. // because we might not recover from it.
  103. $next = $current + 1;
  104. }
  105. return $next;
  106. }
  107. /**
  108. * Sets the current theme revision number.
  109. *
  110. * @param int $revision The new theme revision number
  111. */
  112. function theme_set_revision($revision) {
  113. set_config('themerev', $revision);
  114. }
  115. /**
  116. * Sets the current theme revision number for a specific theme.
  117. * This does not affect the global themerev value.
  118. *
  119. * @param string $themename The non-frankenstyle name of the theme
  120. * @param int $revision The new theme revision number
  121. */
  122. function theme_set_sub_revision_for_theme($themename, $revision) {
  123. set_config('themerev', $revision, "theme_{$themename}");
  124. }
  125. /**
  126. * Get the path to a theme config.php file.
  127. *
  128. * @param string $themename The non-frankenstyle name of the theme to check
  129. */
  130. function theme_get_config_file_path($themename) {
  131. global $CFG;
  132. if (file_exists("{$CFG->dirroot}/theme/{$themename}/config.php")) {
  133. return "{$CFG->dirroot}/theme/{$themename}/config.php";
  134. } else if (!empty($CFG->themedir) and file_exists("{$CFG->themedir}/{$themename}/config.php")) {
  135. return "{$CFG->themedir}/{$themename}/config.php";
  136. } else {
  137. return null;
  138. }
  139. }
  140. /**
  141. * Get the path to the local cached CSS file.
  142. *
  143. * @param string $themename The non-frankenstyle theme name.
  144. * @param int $globalrevision The global theme revision.
  145. * @param int $themerevision The theme specific revision.
  146. * @param string $direction Either 'ltr' or 'rtl' (case sensitive).
  147. */
  148. function theme_get_css_filename($themename, $globalrevision, $themerevision, $direction) {
  149. global $CFG;
  150. $path = "{$CFG->localcachedir}/theme/{$globalrevision}/{$themename}/css";
  151. $filename = $direction == 'rtl' ? "all-rtl_{$themerevision}" : "all_{$themerevision}";
  152. return "{$path}/{$filename}.css";
  153. }
  154. /**
  155. * Generates and saves the CSS files for the given theme configs.
  156. *
  157. * @param theme_config[] $themeconfigs An array of theme_config instances.
  158. * @param array $directions Must be a subset of ['rtl', 'ltr'].
  159. * @param bool $cache Should the generated files be stored in local cache.
  160. * @return array The built theme content in a multi-dimensional array of name => direction => content
  161. */
  162. function theme_build_css_for_themes($themeconfigs = [], $directions = ['rtl', 'ltr'],
  163. $cache = true, $mtraceprogress = false): array {
  164. global $CFG;
  165. if (empty($themeconfigs)) {
  166. return [];
  167. }
  168. require_once("{$CFG->libdir}/csslib.php");
  169. $themescss = [];
  170. $themerev = theme_get_revision();
  171. // Make sure the local cache directory exists.
  172. make_localcache_directory('theme');
  173. foreach ($themeconfigs as $themeconfig) {
  174. $themecss = [];
  175. $oldrevision = theme_get_sub_revision_for_theme($themeconfig->name);
  176. $newrevision = theme_get_next_sub_revision_for_theme($themeconfig->name);
  177. // First generate all the new css.
  178. foreach ($directions as $direction) {
  179. if ($mtraceprogress) {
  180. $timestart = microtime(true);
  181. mtrace('Building theme CSS for ' . $themeconfig->name . ' [' .
  182. $direction . '] ...', '');
  183. }
  184. // Lock it on. Technically we should build all themes for SVG and no SVG - but ie9 is out of support.
  185. $themeconfig->force_svg_use(true);
  186. $themeconfig->set_rtl_mode(($direction === 'rtl'));
  187. $themecss[$direction] = $themeconfig->get_css_content();
  188. if ($cache) {
  189. $themeconfig->set_css_content_cache($themecss[$direction]);
  190. $filename = theme_get_css_filename($themeconfig->name, $themerev, $newrevision, $direction);
  191. css_store_css($themeconfig, $filename, $themecss[$direction]);
  192. }
  193. if ($mtraceprogress) {
  194. mtrace(' done in ' . round(microtime(true) - $timestart, 2) . ' seconds.');
  195. }
  196. }
  197. $themescss[$themeconfig->name] = $themecss;
  198. if ($cache) {
  199. // Only update the theme revision after we've successfully created the
  200. // new CSS cache.
  201. theme_set_sub_revision_for_theme($themeconfig->name, $newrevision);
  202. // Now purge old files. We must purge all old files in the local cache
  203. // because we've incremented the theme sub revision. This will leave any
  204. // files with the old revision inaccessbile so we might as well removed
  205. // them from disk.
  206. foreach (['ltr', 'rtl'] as $direction) {
  207. $oldcss = theme_get_css_filename($themeconfig->name, $themerev, $oldrevision, $direction);
  208. if (file_exists($oldcss)) {
  209. unlink($oldcss);
  210. }
  211. }
  212. }
  213. }
  214. return $themescss;
  215. }
  216. /**
  217. * Invalidate all server and client side caches.
  218. *
  219. * This method deletes the physical directory that is used to cache the theme
  220. * files used for serving.
  221. * Because it deletes the main theme cache directory all themes are reset by
  222. * this function.
  223. */
  224. function theme_reset_all_caches() {
  225. global $CFG, $PAGE;
  226. require_once("{$CFG->libdir}/filelib.php");
  227. $next = theme_get_next_revision();
  228. theme_set_revision($next);
  229. if (!empty($CFG->themedesignermode)) {
  230. $cache = cache::make_from_params(cache_store::MODE_APPLICATION, 'core', 'themedesigner');
  231. $cache->purge();
  232. }
  233. // Purge compiled post processed css.
  234. cache::make('core', 'postprocessedcss')->purge();
  235. // Delete all old theme localcaches.
  236. $themecachedirs = glob("{$CFG->localcachedir}/theme/*", GLOB_ONLYDIR);
  237. foreach ($themecachedirs as $localcachedir) {
  238. fulldelete($localcachedir);
  239. }
  240. if ($PAGE) {
  241. $PAGE->reload_theme();
  242. }
  243. }
  244. /**
  245. * Reset static caches.
  246. *
  247. * This method indicates that all running cron processes should exit at the
  248. * next opportunity.
  249. */
  250. function theme_reset_static_caches() {
  251. \core\task\manager::clear_static_caches();
  252. }
  253. /**
  254. * Enable or disable theme designer mode.
  255. *
  256. * @param bool $state
  257. */
  258. function theme_set_designer_mod($state) {
  259. set_config('themedesignermode', (int)!empty($state));
  260. // Reset caches after switching mode so that any designer mode caches get purged too.
  261. theme_reset_all_caches();
  262. }
  263. /**
  264. * Checks if the given device has a theme defined in config.php.
  265. *
  266. * @return bool
  267. */
  268. function theme_is_device_locked($device) {
  269. global $CFG;
  270. $themeconfigname = core_useragent::get_device_type_cfg_var_name($device);
  271. return isset($CFG->config_php_settings[$themeconfigname]);
  272. }
  273. /**
  274. * Returns the theme named defined in config.php for the given device.
  275. *
  276. * @return string or null
  277. */
  278. function theme_get_locked_theme_for_device($device) {
  279. global $CFG;
  280. if (!theme_is_device_locked($device)) {
  281. return null;
  282. }
  283. $themeconfigname = core_useragent::get_device_type_cfg_var_name($device);
  284. return $CFG->config_php_settings[$themeconfigname];
  285. }
  286. /**
  287. * This class represents the configuration variables of a Moodle theme.
  288. *
  289. * All the variables with access: public below (with a few exceptions that are marked)
  290. * are the properties you can set in your themes config.php file.
  291. *
  292. * There are also some methods and protected variables that are part of the inner
  293. * workings of Moodle's themes system. If you are just editing a themes config.php
  294. * file, you can just ignore those, and the following information for developers.
  295. *
  296. * Normally, to create an instance of this class, you should use the
  297. * {@link theme_config::load()} factory method to load a themes config.php file.
  298. * However, normally you don't need to bother, because moodle_page (that is, $PAGE)
  299. * will create one for you, accessible as $PAGE->theme.
  300. *
  301. * @copyright 2009 Tim Hunt
  302. * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  303. * @since Moodle 2.0
  304. * @package core
  305. * @category output
  306. */
  307. class theme_config {
  308. /**
  309. * @var string Default theme, used when requested theme not found.
  310. */
  311. const DEFAULT_THEME = 'boost';
  312. /** The key under which the SCSS file is stored amongst the CSS files. */
  313. const SCSS_KEY = '__SCSS__';
  314. /**
  315. * @var array You can base your theme on other themes by linking to the other theme as
  316. * parents. This lets you use the CSS and layouts from the other themes
  317. * (see {@link theme_config::$layouts}).
  318. * That makes it easy to create a new theme that is similar to another one
  319. * but with a few changes. In this themes CSS you only need to override
  320. * those rules you want to change.
  321. */
  322. public $parents;
  323. /**
  324. * @var array The names of all the stylesheets from this theme that you would
  325. * like included, in order. Give the names of the files without .css.
  326. */
  327. public $sheets = array();
  328. /**
  329. * @var array The names of all the stylesheets from parents that should be excluded.
  330. * true value may be used to specify all parents or all themes from one parent.
  331. * If no value specified value from parent theme used.
  332. */
  333. public $parents_exclude_sheets = null;
  334. /**
  335. * @var array List of plugin sheets to be excluded.
  336. * If no value specified value from parent theme used.
  337. */
  338. public $plugins_exclude_sheets = null;
  339. /**
  340. * @var array List of style sheets that are included in the text editor bodies.
  341. * Sheets from parent themes are used automatically and can not be excluded.
  342. */
  343. public $editor_sheets = array();
  344. /**
  345. * @var bool Whether a fallback version of the stylesheet will be used
  346. * whilst the final version is generated.
  347. */
  348. public $usefallback = false;
  349. /**
  350. * @var array The names of all the javascript files this theme that you would
  351. * like included from head, in order. Give the names of the files without .js.
  352. */
  353. public $javascripts = array();
  354. /**
  355. * @var array The names of all the javascript files this theme that you would
  356. * like included from footer, in order. Give the names of the files without .js.
  357. */
  358. public $javascripts_footer = array();
  359. /**
  360. * @var array The names of all the javascript files from parents that should
  361. * be excluded. true value may be used to specify all parents or all themes
  362. * from one parent.
  363. * If no value specified value from parent theme used.
  364. */
  365. public $parents_exclude_javascripts = null;
  366. /**
  367. * @var array Which file to use for each page layout.
  368. *
  369. * This is an array of arrays. The keys of the outer array are the different layouts.
  370. * Pages in Moodle are using several different layouts like 'normal', 'course', 'home',
  371. * 'popup', 'form', .... The most reliable way to get a complete list is to look at
  372. * {@link http://cvs.moodle.org/moodle/theme/base/config.php?view=markup the base theme config.php file}.
  373. * That file also has a good example of how to set this setting.
  374. *
  375. * For each layout, the value in the outer array is an array that describes
  376. * how you want that type of page to look. For example
  377. * <pre>
  378. * $THEME->layouts = array(
  379. * // Most pages - if we encounter an unknown or a missing page type, this one is used.
  380. * 'standard' => array(
  381. * 'theme' = 'mytheme',
  382. * 'file' => 'normal.php',
  383. * 'regions' => array('side-pre', 'side-post'),
  384. * 'defaultregion' => 'side-post'
  385. * ),
  386. * // The site home page.
  387. * 'home' => array(
  388. * 'theme' = 'mytheme',
  389. * 'file' => 'home.php',
  390. * 'regions' => array('side-pre', 'side-post'),
  391. * 'defaultregion' => 'side-post'
  392. * ),
  393. * // ...
  394. * );
  395. * </pre>
  396. *
  397. * 'theme' name of the theme where is the layout located
  398. * 'file' is the layout file to use for this type of page.
  399. * layout files are stored in layout subfolder
  400. * 'regions' This lists the regions on the page where blocks may appear. For
  401. * each region you list here, your layout file must include a call to
  402. * <pre>
  403. * echo $OUTPUT->blocks_for_region($regionname);
  404. * </pre>
  405. * or equivalent so that the blocks are actually visible.
  406. *
  407. * 'defaultregion' If the list of regions is non-empty, then you must pick
  408. * one of the one of them as 'default'. This has two meanings. First, this is
  409. * where new blocks are added. Second, if there are any blocks associated with
  410. * the page, but in non-existent regions, they appear here. (Imaging, for example,
  411. * that someone added blocks using a different theme that used different region
  412. * names, and then switched to this theme.)
  413. */
  414. public $layouts = array();
  415. /**
  416. * @var string Name of the renderer factory class to use. Must implement the
  417. * {@link renderer_factory} interface.
  418. *
  419. * This is an advanced feature. Moodle output is generated by 'renderers',
  420. * you can customise the HTML that is output by writing custom renderers,
  421. * and then you need to specify 'renderer factory' so that Moodle can find
  422. * your renderers.
  423. *
  424. * There are some renderer factories supplied with Moodle. Please follow these
  425. * links to see what they do.
  426. * <ul>
  427. * <li>{@link standard_renderer_factory} - the default.</li>
  428. * <li>{@link theme_overridden_renderer_factory} - use this if you want to write
  429. * your own custom renderers in a lib.php file in this theme (or the parent theme).</li>
  430. * </ul>
  431. */
  432. public $rendererfactory = 'standard_renderer_factory';
  433. /**
  434. * @var string Function to do custom CSS post-processing.
  435. *
  436. * This is an advanced feature. If you want to do custom post-processing on the
  437. * CSS before it is output (for example, to replace certain variable names
  438. * with particular values) you can give the name of a function here.
  439. */
  440. public $csspostprocess = null;
  441. /**
  442. * @var string Function to do custom CSS post-processing on a parsed CSS tree.
  443. *
  444. * This is an advanced feature. If you want to do custom post-processing on the
  445. * CSS before it is output, you can provide the name of the function here. The
  446. * function will receive a CSS tree document as first parameter, and the theme_config
  447. * object as second parameter. A return value is not required, the tree can
  448. * be edited in place.
  449. */
  450. public $csstreepostprocessor = null;
  451. /**
  452. * @var string Accessibility: Right arrow-like character is
  453. * used in the breadcrumb trail, course navigation menu
  454. * (previous/next activity), calendar, and search forum block.
  455. * If the theme does not set characters, appropriate defaults
  456. * are set automatically. Please DO NOT
  457. * use &lt; &gt; &raquo; - these are confusing for blind users.
  458. */
  459. public $rarrow = null;
  460. /**
  461. * @var string Accessibility: Left arrow-like character is
  462. * used in the breadcrumb trail, course navigation menu
  463. * (previous/next activity), calendar, and search forum block.
  464. * If the theme does not set characters, appropriate defaults
  465. * are set automatically. Please DO NOT
  466. * use &lt; &gt; &raquo; - these are confusing for blind users.
  467. */
  468. public $larrow = null;
  469. /**
  470. * @var string Accessibility: Up arrow-like character is used in
  471. * the book heirarchical navigation.
  472. * If the theme does not set characters, appropriate defaults
  473. * are set automatically. Please DO NOT
  474. * use ^ - this is confusing for blind users.
  475. */
  476. public $uarrow = null;
  477. /**
  478. * @var string Accessibility: Down arrow-like character.
  479. * If the theme does not set characters, appropriate defaults
  480. * are set automatically.
  481. */
  482. public $darrow = null;
  483. /**
  484. * @var bool Some themes may want to disable ajax course editing.
  485. */
  486. public $enablecourseajax = true;
  487. /**
  488. * @var string Determines served document types
  489. * - 'html5' the only officially supported doctype in Moodle
  490. * - 'xhtml5' may be used in development for validation (not intended for production servers!)
  491. * - 'xhtml' XHTML 1.0 Strict for legacy themes only
  492. */
  493. public $doctype = 'html5';
  494. /**
  495. * @var string requiredblocks If set to a string, will list the block types that cannot be deleted. Defaults to
  496. * navigation and settings.
  497. */
  498. public $requiredblocks = false;
  499. //==Following properties are not configurable from theme config.php==
  500. /**
  501. * @var string The name of this theme. Set automatically when this theme is
  502. * loaded. This can not be set in theme config.php
  503. */
  504. public $name;
  505. /**
  506. * @var string The folder where this themes files are stored. This is set
  507. * automatically. This can not be set in theme config.php
  508. */
  509. public $dir;
  510. /**
  511. * @var stdClass Theme settings stored in config_plugins table.
  512. * This can not be set in theme config.php
  513. */
  514. public $settings = null;
  515. /**
  516. * @var bool If set to true and the theme enables the dock then blocks will be able
  517. * to be moved to the special dock
  518. */
  519. public $enable_dock = false;
  520. /**
  521. * @var bool If set to true then this theme will not be shown in the theme selector unless
  522. * theme designer mode is turned on.
  523. */
  524. public $hidefromselector = false;
  525. /**
  526. * @var array list of YUI CSS modules to be included on each page. This may be used
  527. * to remove cssreset and use cssnormalise module instead.
  528. */
  529. public $yuicssmodules = array('cssreset', 'cssfonts', 'cssgrids', 'cssbase');
  530. /**
  531. * An associative array of block manipulations that should be made if the user is using an rtl language.
  532. * The key is the original block region, and the value is the block region to change to.
  533. * This is used when displaying blocks for regions only.
  534. * @var array
  535. */
  536. public $blockrtlmanipulations = array();
  537. /**
  538. * @var renderer_factory Instance of the renderer_factory implementation
  539. * we are using. Implementation detail.
  540. */
  541. protected $rf = null;
  542. /**
  543. * @var array List of parent config objects.
  544. **/
  545. protected $parent_configs = array();
  546. /**
  547. * Used to determine whether we can serve SVG images or not.
  548. * @var bool
  549. */
  550. private $usesvg = null;
  551. /**
  552. * Whether in RTL mode or not.
  553. * @var bool
  554. */
  555. protected $rtlmode = false;
  556. /**
  557. * The SCSS file to compile (without .scss), located in the scss/ folder of the theme.
  558. * Or a Closure, which receives the theme_config as argument and must
  559. * return the SCSS content.
  560. * @var string|Closure
  561. */
  562. public $scss = false;
  563. /**
  564. * Local cache of the SCSS property.
  565. * @var false|array
  566. */
  567. protected $scsscache = null;
  568. /**
  569. * The name of the function to call to get the SCSS code to inject.
  570. * @var string
  571. */
  572. public $extrascsscallback = null;
  573. /**
  574. * The name of the function to call to get SCSS to prepend.
  575. * @var string
  576. */
  577. public $prescsscallback = null;
  578. /**
  579. * Sets the render method that should be used for rendering custom block regions by scripts such as my/index.php
  580. * Defaults to {@link core_renderer::blocks_for_region()}
  581. * @var string
  582. */
  583. public $blockrendermethod = null;
  584. /**
  585. * Remember the results of icon remapping for the current page.
  586. * @var array
  587. */
  588. public $remapiconcache = [];
  589. /**
  590. * The name of the function to call to get precompiled CSS.
  591. * @var string
  592. */
  593. public $precompiledcsscallback = null;
  594. /**
  595. * Whether the theme uses course index.
  596. * @var bool
  597. */
  598. public $usescourseindex = false;
  599. /**
  600. * Load the config.php file for a particular theme, and return an instance
  601. * of this class. (That is, this is a factory method.)
  602. *
  603. * @param string $themename the name of the theme.
  604. * @return theme_config an instance of this class.
  605. */
  606. public static function load($themename) {
  607. global $CFG;
  608. // load theme settings from db
  609. try {
  610. $settings = get_config('theme_'.$themename);
  611. } catch (dml_exception $e) {
  612. // most probably moodle tables not created yet
  613. $settings = new stdClass();
  614. }
  615. if ($config = theme_config::find_theme_config($themename, $settings)) {
  616. return new theme_config($config);
  617. } else if ($themename == theme_config::DEFAULT_THEME) {
  618. throw new coding_exception('Default theme '.theme_config::DEFAULT_THEME.' not available or broken!');
  619. } else if ($config = theme_config::find_theme_config($CFG->theme, $settings)) {
  620. debugging('This page should be using theme ' . $themename .
  621. ' which cannot be initialised. Falling back to the site theme ' . $CFG->theme, DEBUG_NORMAL);
  622. return new theme_config($config);
  623. } else {
  624. // bad luck, the requested theme has some problems - admin see details in theme config
  625. debugging('This page should be using theme ' . $themename .
  626. ' which cannot be initialised. Nor can the site theme ' . $CFG->theme .
  627. '. Falling back to ' . theme_config::DEFAULT_THEME, DEBUG_NORMAL);
  628. return new theme_config(theme_config::find_theme_config(theme_config::DEFAULT_THEME, $settings));
  629. }
  630. }
  631. /**
  632. * Theme diagnostic code. It is very problematic to send debug output
  633. * to the actual CSS file, instead this functions is supposed to
  634. * diagnose given theme and highlights all potential problems.
  635. * This information should be available from the theme selection page
  636. * or some other debug page for theme designers.
  637. *
  638. * @param string $themename
  639. * @return array description of problems
  640. */
  641. public static function diagnose($themename) {
  642. //TODO: MDL-21108
  643. return array();
  644. }
  645. /**
  646. * Private constructor, can be called only from the factory method.
  647. * @param stdClass $config
  648. */
  649. private function __construct($config) {
  650. global $CFG; //needed for included lib.php files
  651. $this->settings = $config->settings;
  652. $this->name = $config->name;
  653. $this->dir = $config->dir;
  654. if ($this->name != self::DEFAULT_THEME) {
  655. $baseconfig = self::find_theme_config(self::DEFAULT_THEME, $this->settings);
  656. } else {
  657. $baseconfig = $config;
  658. }
  659. $configurable = array(
  660. 'parents', 'sheets', 'parents_exclude_sheets', 'plugins_exclude_sheets', 'usefallback',
  661. 'javascripts', 'javascripts_footer', 'parents_exclude_javascripts',
  662. 'layouts', 'enablecourseajax', 'requiredblocks',
  663. 'rendererfactory', 'csspostprocess', 'editor_sheets', 'editor_scss', 'rarrow', 'larrow', 'uarrow', 'darrow',
  664. 'hidefromselector', 'doctype', 'yuicssmodules', 'blockrtlmanipulations', 'blockrendermethod',
  665. 'scss', 'extrascsscallback', 'prescsscallback', 'csstreepostprocessor', 'addblockposition',
  666. 'iconsystem', 'precompiledcsscallback', 'haseditswitch', 'usescourseindex');
  667. foreach ($config as $key=>$value) {
  668. if (in_array($key, $configurable)) {
  669. $this->$key = $value;
  670. }
  671. }
  672. // verify all parents and load configs and renderers
  673. foreach ($this->parents as $parent) {
  674. if (!$parent_config = theme_config::find_theme_config($parent, $this->settings)) {
  675. // this is not good - better exclude faulty parents
  676. continue;
  677. }
  678. $libfile = $parent_config->dir.'/lib.php';
  679. if (is_readable($libfile)) {
  680. // theme may store various function here
  681. include_once($libfile);
  682. }
  683. $renderersfile = $parent_config->dir.'/renderers.php';
  684. if (is_readable($renderersfile)) {
  685. // may contain core and plugin renderers and renderer factory
  686. include_once($renderersfile);
  687. }
  688. $this->parent_configs[$parent] = $parent_config;
  689. }
  690. $libfile = $this->dir.'/lib.php';
  691. if (is_readable($libfile)) {
  692. // theme may store various function here
  693. include_once($libfile);
  694. }
  695. $rendererfile = $this->dir.'/renderers.php';
  696. if (is_readable($rendererfile)) {
  697. // may contain core and plugin renderers and renderer factory
  698. include_once($rendererfile);
  699. } else {
  700. // check if renderers.php file is missnamed renderer.php
  701. if (is_readable($this->dir.'/renderer.php')) {
  702. debugging('Developer hint: '.$this->dir.'/renderer.php should be renamed to ' . $this->dir."/renderers.php.
  703. See: http://docs.moodle.org/dev/Output_renderers#Theme_renderers.", DEBUG_DEVELOPER);
  704. }
  705. }
  706. // cascade all layouts properly
  707. foreach ($baseconfig->layouts as $layout=>$value) {
  708. if (!isset($this->layouts[$layout])) {
  709. foreach ($this->parent_configs as $parent_config) {
  710. if (isset($parent_config->layouts[$layout])) {
  711. $this->layouts[$layout] = $parent_config->layouts[$layout];
  712. continue 2;
  713. }
  714. }
  715. $this->layouts[$layout] = $value;
  716. }
  717. }
  718. //fix arrows if needed
  719. $this->check_theme_arrows();
  720. }
  721. /**
  722. * Let the theme initialise the page object (usually $PAGE).
  723. *
  724. * This may be used for example to request jQuery in add-ons.
  725. *
  726. * @param moodle_page $page
  727. */
  728. public function init_page(moodle_page $page) {
  729. $themeinitfunction = 'theme_'.$this->name.'_page_init';
  730. if (function_exists($themeinitfunction)) {
  731. $themeinitfunction($page);
  732. }
  733. }
  734. /**
  735. * Checks if arrows $THEME->rarrow, $THEME->larrow, $THEME->uarrow, $THEME->darrow have been set (theme/-/config.php).
  736. * If not it applies sensible defaults.
  737. *
  738. * Accessibility: right and left arrow Unicode characters for breadcrumb, calendar,
  739. * search forum block, etc. Important: these are 'silent' in a screen-reader
  740. * (unlike &gt; &raquo;), and must be accompanied by text.
  741. */
  742. private function check_theme_arrows() {
  743. if (!isset($this->rarrow) and !isset($this->larrow)) {
  744. // Default, looks good in Win XP/IE 6, Win/Firefox 1.5, Win/Netscape 8...
  745. // Also OK in Win 9x/2K/IE 5.x
  746. $this->rarrow = '&#x25BA;';
  747. $this->larrow = '&#x25C4;';
  748. $this->uarrow = '&#x25B2;';
  749. $this->darrow = '&#x25BC;';
  750. if (empty($_SERVER['HTTP_USER_AGENT'])) {
  751. $uagent = '';
  752. } else {
  753. $uagent = $_SERVER['HTTP_USER_AGENT'];
  754. }
  755. if (false !== strpos($uagent, 'Opera')
  756. || false !== strpos($uagent, 'Mac')) {
  757. // Looks good in Win XP/Mac/Opera 8/9, Mac/Firefox 2, Camino, Safari.
  758. // Not broken in Mac/IE 5, Mac/Netscape 7 (?).
  759. $this->rarrow = '&#x25B6;&#xFE0E;';
  760. $this->larrow = '&#x25C0;&#xFE0E;';
  761. }
  762. elseif ((false !== strpos($uagent, 'Konqueror'))
  763. || (false !== strpos($uagent, 'Android'))) {
  764. // The fonts on Android don't include the characters required for this to work as expected.
  765. // So we use the same ones Konqueror uses.
  766. $this->rarrow = '&rarr;';
  767. $this->larrow = '&larr;';
  768. $this->uarrow = '&uarr;';
  769. $this->darrow = '&darr;';
  770. }
  771. elseif (isset($_SERVER['HTTP_ACCEPT_CHARSET'])
  772. && false === stripos($_SERVER['HTTP_ACCEPT_CHARSET'], 'utf-8')) {
  773. // (Win/IE 5 doesn't set ACCEPT_CHARSET, but handles Unicode.)
  774. // To be safe, non-Unicode browsers!
  775. $this->rarrow = '&gt;';
  776. $this->larrow = '&lt;';
  777. $this->uarrow = '^';
  778. $this->darrow = 'v';
  779. }
  780. // RTL support - in RTL languages, swap r and l arrows
  781. if (right_to_left()) {
  782. $t = $this->rarrow;
  783. $this->rarrow = $this->larrow;
  784. $this->larrow = $t;
  785. }
  786. }
  787. }
  788. /**
  789. * Returns output renderer prefixes, these are used when looking
  790. * for the overridden renderers in themes.
  791. *
  792. * @return array
  793. */
  794. public function renderer_prefixes() {
  795. global $CFG; // just in case the included files need it
  796. $prefixes = array('theme_'.$this->name);
  797. foreach ($this->parent_configs as $parent) {
  798. $prefixes[] = 'theme_'.$parent->name;
  799. }
  800. return $prefixes;
  801. }
  802. /**
  803. * Returns the stylesheet URL of this editor content
  804. *
  805. * @param bool $encoded false means use & and true use &amp; in URLs
  806. * @return moodle_url
  807. */
  808. public function editor_css_url($encoded=true) {
  809. global $CFG;
  810. $rev = theme_get_revision();
  811. if ($rev > -1) {
  812. $themesubrevision = theme_get_sub_revision_for_theme($this->name);
  813. // Provide the sub revision to allow us to invalidate cached theme CSS
  814. // on a per theme basis, rather than globally.
  815. if ($themesubrevision && $themesubrevision > 0) {
  816. $rev .= "_{$themesubrevision}";
  817. }
  818. $url = new moodle_url("/theme/styles.php");
  819. if (!empty($CFG->slasharguments)) {
  820. $url->set_slashargument('/'.$this->name.'/'.$rev.'/editor', 'noparam', true);
  821. } else {
  822. $url->params(array('theme'=>$this->name,'rev'=>$rev, 'type'=>'editor'));
  823. }
  824. } else {
  825. $params = array('theme'=>$this->name, 'type'=>'editor');
  826. $url = new moodle_url('/theme/styles_debug.php', $params);
  827. }
  828. return $url;
  829. }
  830. /**
  831. * Returns the content of the CSS to be used in editor content
  832. *
  833. * @return array
  834. */
  835. public function editor_css_files() {
  836. $files = array();
  837. // First editor plugins.
  838. $plugins = core_component::get_plugin_list('editor');
  839. foreach ($plugins as $plugin=>$fulldir) {
  840. $sheetfile = "$fulldir/editor_styles.css";
  841. if (is_readable($sheetfile)) {
  842. $files['plugin_'.$plugin] = $sheetfile;
  843. }
  844. }
  845. // Then parent themes - base first, the immediate parent last.
  846. foreach (array_reverse($this->parent_configs) as $parent_config) {
  847. if (empty($parent_config->editor_sheets)) {
  848. continue;
  849. }
  850. foreach ($parent_config->editor_sheets as $sheet) {
  851. $sheetfile = "$parent_config->dir/style/$sheet.css";
  852. if (is_readable($sheetfile)) {
  853. $files['parent_'.$parent_config->name.'_'.$sheet] = $sheetfile;
  854. }
  855. }
  856. }
  857. // Finally this theme.
  858. if (!empty($this->editor_sheets)) {
  859. foreach ($this->editor_sheets as $sheet) {
  860. $sheetfile = "$this->dir/style/$sheet.css";
  861. if (is_readable($sheetfile)) {
  862. $files['theme_'.$sheet] = $sheetfile;
  863. }
  864. }
  865. }
  866. return $files;
  867. }
  868. /**
  869. * Compiles and returns the content of the SCSS to be used in editor content
  870. *
  871. * @return string Compiled CSS from the editor SCSS
  872. */
  873. public function editor_scss_to_css() {
  874. $css = '';
  875. $dir = $this->dir;
  876. $filenames = [];
  877. // Use editor_scss file(s) provided by this theme if set.
  878. if (!empty($this->editor_scss)) {
  879. $filenames = $this->editor_scss;
  880. } else {
  881. // If no editor_scss set, move up theme hierarchy until one is found (if at all).
  882. // This is so child themes only need to set editor_scss if an override is required.
  883. foreach (array_reverse($this->parent_configs) as $parentconfig) {
  884. if (!empty($parentconfig->editor_scss)) {
  885. $dir = $parentconfig->dir;
  886. $filenames = $parentconfig->editor_scss;
  887. // Config found, stop looking.
  888. break;
  889. }
  890. }
  891. }
  892. if (!empty($filenames)) {
  893. $compiler = new core_scss();
  894. foreach ($filenames as $filename) {
  895. $compiler->set_file("{$dir}/scss/{$filename}.scss");
  896. try {
  897. $css .= $compiler->to_css();
  898. } catch (\Exception $e) {
  899. debugging('Error while compiling editor SCSS: ' . $e->getMessage(), DEBUG_DEVELOPER);
  900. }
  901. }
  902. }
  903. return $css;
  904. }
  905. /**
  906. * Get the stylesheet URL of this theme.
  907. *
  908. * @param moodle_page $page Not used... deprecated?
  909. * @return moodle_url[]
  910. */
  911. public function css_urls(moodle_page $page) {
  912. global $CFG;
  913. $rev = theme_get_revision();
  914. $urls = array();
  915. $svg = $this->use_svg_icons();
  916. $separate = (core_useragent::is_ie() && !core_useragent::check_ie_version('10'));
  917. if ($rev > -1) {
  918. $filename = right_to_left() ? 'all-rtl' : 'all';
  919. $url = new moodle_url("/theme/styles.php");
  920. $themesubrevision = theme_get_sub_revision_for_theme($this->name);
  921. // Provide the sub revision to allow us to invalidate cached theme CSS
  922. // on a per theme basis, rather than globally.
  923. if ($themesubrevision && $themesubrevision > 0) {
  924. $rev .= "_{$themesubrevision}";
  925. }
  926. if (!empty($CFG->slasharguments)) {
  927. $slashargs = '';
  928. if (!$svg) {
  929. // We add a simple /_s to the start of the path.
  930. // The underscore is used to ensure that it isn't a valid theme name.
  931. $slashargs .= '/_s'.$slashargs;
  932. }
  933. $slashargs .= '/'.$this->name.'/'.$rev.'/'.$filename;
  934. if ($separate) {
  935. $slashargs .= '/chunk0';
  936. }
  937. $url->set_slashargument($slashargs, 'noparam', true);
  938. } else {
  939. $params = array('theme' => $this->name, 'rev' => $rev, 'type' => $filename);
  940. if (!$svg) {
  941. // We add an SVG param so that we know not to serve SVG images.
  942. // We do this because all modern browsers support SVG and this param will one day be removed.
  943. $params['svg'] = '0';
  944. }
  945. if ($separate) {
  946. $params['chunk'] = '0';
  947. }
  948. $url->params($params);
  949. }
  950. $urls[] = $url;
  951. } else {
  952. $baseurl = new moodle_url('/theme/styles_debug.php');
  953. $css = $this->get_css_files(true);
  954. if (!$svg) {
  955. // We add an SVG param so that we know not to serve SVG images.
  956. // We do this because all modern browsers support SVG and this param will one day be removed.
  957. $baseurl->param('svg', '0');
  958. }
  959. if (right_to_left()) {
  960. $baseurl->param('rtl', 1);
  961. }
  962. if ($separate) {
  963. // We might need to chunk long files.
  964. $baseurl->param('chunk', '0');
  965. }
  966. if (core_useragent::is_ie()) {
  967. // Lalala, IE does not allow more than 31 linked CSS files from main document.
  968. $urls[] = new moodle_url($baseurl, array('theme'=>$this->name, 'type'=>'ie', 'subtype'=>'plugins'));
  969. foreach ($css['parents'] as $parent=>$sheets) {
  970. // We need to serve parents individually otherwise we may easily exceed the style limit IE imposes (4096).
  971. $urls[] = new moodle_url($baseurl, array('theme'=>$this->name,'type'=>'ie', 'subtype'=>'parents', 'sheet'=>$parent));
  972. }
  973. if ($this->get_scss_property()) {
  974. // No need to define the type as IE here.
  975. $urls[] = new moodle_url($baseurl, array('theme' => $this->name, 'type' => 'scss'));
  976. }
  977. $urls[] = new moodle_url($baseurl, array('theme'=>$this->name, 'type'=>'ie', 'subtype'=>'theme'));
  978. } else {
  979. foreach ($css['plugins'] as $plugin=>$unused) {
  980. $urls[] = new moodle_url($baseurl, array('theme'=>$this->name,'type'=>'plugin', 'subtype'=>$plugin));
  981. }
  982. foreach ($css['parents'] as $parent=>$sheets) {
  983. foreach ($sheets as $sheet=>$unused2) {
  984. $urls[] = new moodle_url($baseurl, array('theme'=>$this->name,'type'=>'parent', 'subtype'=>$parent, 'sheet'=>$sheet));
  985. }
  986. }
  987. foreach ($css['theme'] as $sheet => $filename) {
  988. if ($sheet === self::SCSS_KEY) {
  989. // This is the theme SCSS file.
  990. $urls[] = new moodle_url($baseurl, array('theme' => $this->name, 'type' => 'scss'));
  991. } else {
  992. // Sheet first in order to make long urls easier to read.
  993. $urls[] = new moodle_url($baseurl, array('sheet'=>$sheet, 'theme'=>$this->name, 'type'=>'theme'));
  994. }
  995. }
  996. }
  997. }
  998. // Allow themes to change the css url to something like theme/mytheme/mycss.php.
  999. component_callback('theme_' . $this->name, 'alter_css_urls', [&$urls]);
  1000. return $urls;
  1001. }
  1002. /**
  1003. * Get the whole css stylesheet for production mode.
  1004. *
  1005. * NOTE: this method is not expected to be used from any addons.
  1006. *
  1007. * @return string CSS markup compressed
  1008. */
  1009. public function get_css_content() {
  1010. $csscontent = '';
  1011. foreach ($this->get_css_files(false) as $type => $value) {
  1012. foreach ($value as $identifier => $val) {
  1013. if (is_array($val)) {
  1014. foreach ($val as $v) {
  1015. $csscontent .= file_get_contents($v) . "\n";
  1016. }
  1017. } else {
  1018. if ($type === 'theme' && $identifier === self::SCSS_KEY) {
  1019. // We need the content from SCSS because this is the SCSS file from the theme.
  1020. if ($compiled = $this->get_css_content_from_scss(false)) {
  1021. $csscontent .= $compiled;
  1022. } else {
  1023. // The compiler failed so default back to any precompiled css that might
  1024. // exist.
  1025. $csscontent .= $this->get_precompiled_css_content();
  1026. }
  1027. } else {
  1028. $csscontent .= file_get_contents($val) . "\n";
  1029. }
  1030. }
  1031. }
  1032. }
  1033. $csscontent = $this->post_process($csscontent);
  1034. $csscontent = core_minify::css($csscontent);
  1035. return $csscontent;
  1036. }
  1037. /**
  1038. * Set post processed CSS content cache.
  1039. *
  1040. * @param string $csscontent The post processed CSS content.
  1041. * @return bool True if the content was successfully cached.
  1042. */
  1043. public function set_css_content_cache($csscontent) {
  1044. $cache = cache::make('core', 'postprocessedcss');
  1045. $key = $this->get_css_cache_key();
  1046. return $cache->set($key, $csscontent);
  1047. }
  1048. /**
  1049. * Return whether the post processed CSS content has been cached.
  1050. *
  1051. * @return bool Whether the post-processed CSS is available in the cache.
  1052. */
  1053. public function has_css_cached_content() {
  1054. $key = $this->get_css_cache_key();
  1055. $cache = cache::make('core', 'postprocessedcss');
  1056. return $cache->has($key);
  1057. }
  1058. /**
  1059. * Return cached post processed CSS content.
  1060. *
  1061. * @return bool|string The cached css content or false if not found.
  1062. */
  1063. public function get_css_cached_content() {
  1064. $key = $this->get_css_cache_key();
  1065. $cache = cache::make('core', 'postprocessedcss');
  1066. return $cache->get($key);
  1067. }
  1068. /**
  1069. * Generate the css content cache key.
  1070. *
  1071. * @return string The post processed css cache key.
  1072. */
  1073. public function get_css_cache_key() {
  1074. $nosvg = (!$this->use_svg_icons()) ? 'nosvg_' : '';
  1075. $rtlmode = ($this->rtlmode == true) ? 'rtl' : 'ltr';
  1076. return $nosvg . $this->name . '_' . $rtlmode;
  1077. }
  1078. /**
  1079. * Get the theme designer css markup,
  1080. * the parameters are coming from css_urls().
  1081. *
  1082. * NOTE: this method is not expected to be used from any addons.
  1083. *
  1084. * @param string $type
  1085. * @param string $subtype
  1086. * @param string $sheet
  1087. * @return string CSS markup
  1088. */
  1089. public function get_css_content_debug($type, $subtype, $sheet) {
  1090. if ($type === 'scss') {
  1091. // The SCSS file of the theme is requested.
  1092. $csscontent = $this->get_css_content_from_scss(true);
  1093. if ($csscontent !== false) {
  1094. return $this->post_process($csscontent);
  1095. }
  1096. return '';
  1097. }
  1098. $cssfiles = array();
  1099. $css = $this->get_css_files(true);
  1100. if ($type === 'ie') {
  1101. // IE is a sloppy browser with weird limits, sorry.
  1102. if ($subtype === 'plugins') {
  1103. $cssfiles = $css['plugins'];
  1104. } else if ($subtype === 'parents') {
  1105. if (empty($sheet)) {
  1106. // Do not bother with the empty parent here.
  1107. } else {
  1108. // Build up the CSS for that parent so we can serve it as one file.
  1109. foreach ($css[$subtype][$sheet] as $parent => $css) {
  1110. $cssfiles[] = $css;
  1111. }
  1112. }
  1113. } else if ($subtype === 'theme') {
  1114. $cssfiles = $css['theme'];
  1115. foreach ($cssfiles as $key => $value) {
  1116. if (in_array($key, [self::SCSS_KEY])) {
  1117. // Remove the SCSS file from the theme CSS files.
  1118. // The SCSS files use the type 'scss', not 'ie'.
  1119. unset($cssfiles[$key]);
  1120. }
  1121. }
  1122. }
  1123. } else if ($type === 'plugin') {
  1124. if (isset($css['plugins'][$subtype])) {
  1125. $cssfiles[] = $css['plugins'][$subtype];
  1126. }
  1127. } else if ($type === 'parent') {
  1128. if (isset($css['parents'][$subtype][$sheet])) {
  1129. $cssfiles[] = $css['parents'][$subtype][$sheet];
  1130. }
  1131. } else if ($type === 'theme') {
  1132. if (isset($css['theme'][$sheet])) {
  1133. $cssfiles[] = $css['theme'][$sheet];
  1134. }
  1135. }
  1136. $csscontent = '';
  1137. foreach ($cssfiles as $file) {
  1138. $contents = file_get_contents($file);
  1139. $contents = $this->post_process($contents);
  1140. $comment = "/** Path: $type $subtype $sheet.' **/\n";
  1141. $stats = '';
  1142. $csscontent .= $comment.$stats.$contents."\n\n";
  1143. }
  1144. return $csscontent;
  1145. }
  1146. /**
  1147. * Get the whole css stylesheet for editor iframe.
  1148. *
  1149. * NOTE: this method is not expected to be used from any addons.
  1150. *
  1151. * @return string CSS markup
  1152. */
  1153. public function get_css_content_editor() {
  1154. $css = '';
  1155. $cssfiles = $this->editor_css_files();
  1156. // If editor has static CSS, include it.
  1157. foreach ($cssfiles as $file) {
  1158. $css .= file_get_contents($file)."\n";
  1159. }
  1160. // If editor has SCSS, compile and include it.
  1161. if (($convertedscss = $this->editor_scss_to_css())) {
  1162. $css .= $convertedscss;
  1163. }
  1164. $output = $this->post_process($css);
  1165. return $output;
  1166. }
  1167. /**
  1168. * Returns an array of organised CSS files required for this output.
  1169. *
  1170. * @param bool $themedesigner
  1171. * @return array nested array of file paths
  1172. */
  1173. protected function get_css_files($themedesigner) {
  1174. global $CFG;
  1175. $cache = null;
  1176. $cachekey = 'cssfiles';
  1177. if ($themedesigner) {
  1178. require_once($CFG->dirroot.'/lib/csslib.php');
  1179. // We need some kind of caching here because otherwise the page navigation becomes
  1180. // way too slow in theme designer mode. Feel free to create full cache definition later...
  1181. $cache = cache::make_from_params(cache_store::MODE_APPLICATION, 'core', 'themedesigner', array('theme' => $this->name));
  1182. if ($files = $cache->get($cachekey)) {
  1183. if ($files['created'] > time() - THEME_DESIGNER_CACHE_LIFETIME) {
  1184. unset($files['created']);
  1185. return $files;
  1186. }
  1187. }
  1188. }
  1189. $cssfiles = array('plugins'=>array(), 'parents'=>array(), 'theme'=>array());
  1190. // Get all plugin sheets.
  1191. $excludes = $this->resolve_excludes('plugins_exclude_sheets');
  1192. if ($excludes !== true) {
  1193. foreach (core_component::get_plugin_types() as $type=>$unused) {
  1194. if ($type === 'theme' || (!empty($excludes[$type]) and $excludes[$type] === true)) {
  1195. continue;
  1196. }
  1197. $plugins = core_component::get_plugin_list($type);
  1198. foreach ($plugins as $plugin=>$fulldir) {
  1199. if (!empty($excludes[$type]) and is_array($excludes[$type])
  1200. and in_array($plugin, $excludes[$type])) {
  1201. continue;
  1202. }
  1203. // Get the CSS from the plugin.

Large files files are truncated, but you can click here to view the full file