PageRenderTime 54ms CodeModel.GetById 11ms RepoModel.GetById 0ms app.codeStats 0ms

/includes/theme.inc

https://github.com/mikl/drupal
Pascal | 2561 lines | 1535 code | 113 blank | 913 comment | 197 complexity | 79051068abfd31784658b77ec048b858 MD5 | raw file

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

  1. <?php
  2. // $Id: theme.inc,v 1.605 2010-08-08 19:35:48 dries Exp $
  3. /**
  4. * @file
  5. * The theme system, which controls the output of Drupal.
  6. *
  7. * The theme system allows for nearly all output of the Drupal system to be
  8. * customized by user themes.
  9. */
  10. /**
  11. * @name Content markers
  12. * @{
  13. * Markers used by theme_mark() and node_mark() to designate content.
  14. * @see theme_mark(), node_mark()
  15. */
  16. /**
  17. * Mark content as read.
  18. */
  19. define('MARK_READ', 0);
  20. /**
  21. * Mark content as being new.
  22. */
  23. define('MARK_NEW', 1);
  24. /**
  25. * Mark content as being updated.
  26. */
  27. define('MARK_UPDATED', 2);
  28. /**
  29. * @} End of "Content markers".
  30. */
  31. /**
  32. * Determines if a theme is available to use.
  33. *
  34. * @param $theme
  35. * Either the name of a theme or a full theme object.
  36. *
  37. * @return
  38. * Boolean TRUE if the theme is enabled or is the site administration theme;
  39. * FALSE otherwise.
  40. */
  41. function drupal_theme_access($theme) {
  42. if (is_object($theme)) {
  43. return _drupal_theme_access($theme);
  44. }
  45. else {
  46. $themes = list_themes();
  47. return isset($themes[$theme]) && _drupal_theme_access($themes[$theme]);
  48. }
  49. }
  50. /**
  51. * Helper function for determining access to a theme.
  52. *
  53. * @see drupal_theme_access()
  54. */
  55. function _drupal_theme_access($theme) {
  56. $admin_theme = variable_get('admin_theme');
  57. return !empty($theme->status) || ($admin_theme && $theme->name == $admin_theme);
  58. }
  59. /**
  60. * Initialize the theme system by loading the theme.
  61. */
  62. function drupal_theme_initialize() {
  63. global $theme, $user, $theme_key;
  64. // If $theme is already set, assume the others are set, too, and do nothing
  65. if (isset($theme)) {
  66. return;
  67. }
  68. drupal_bootstrap(DRUPAL_BOOTSTRAP_DATABASE);
  69. $themes = list_themes();
  70. // Only select the user selected theme if it is available in the
  71. // list of themes that can be accessed.
  72. $theme = !empty($user->theme) && drupal_theme_access($user->theme) ? $user->theme : variable_get('theme_default', 'bartik');
  73. // Allow modules to override the theme. Validation has already been performed
  74. // inside menu_get_custom_theme(), so we do not need to check it again here.
  75. $custom_theme = menu_get_custom_theme();
  76. $theme = !empty($custom_theme) ? $custom_theme : $theme;
  77. // Store the identifier for retrieving theme settings with.
  78. $theme_key = $theme;
  79. // Find all our ancestor themes and put them in an array.
  80. $base_theme = array();
  81. $ancestor = $theme;
  82. while ($ancestor && isset($themes[$ancestor]->base_theme)) {
  83. $base_theme[] = $new_base_theme = $themes[$themes[$ancestor]->base_theme];
  84. $ancestor = $themes[$ancestor]->base_theme;
  85. }
  86. _drupal_theme_initialize($themes[$theme], array_reverse($base_theme));
  87. // Themes can have alter functions, so reset the drupal_alter() cache.
  88. drupal_static_reset('drupal_alter');
  89. }
  90. /**
  91. * Initialize the theme system given already loaded information. This
  92. * function is useful to initialize a theme when no database is present.
  93. *
  94. * @param $theme
  95. * An object with the following information:
  96. * filename
  97. * The .info file for this theme. The 'path' to
  98. * the theme will be in this file's directory. (Required)
  99. * owner
  100. * The path to the .theme file or the .engine file to load for
  101. * the theme. (Required)
  102. * stylesheet
  103. * The primary stylesheet for the theme. (Optional)
  104. * engine
  105. * The name of theme engine to use. (Optional)
  106. * @param $base_theme
  107. * An optional array of objects that represent the 'base theme' if the
  108. * theme is meant to be derivative of another theme. It requires
  109. * the same information as the $theme object. It should be in
  110. * 'oldest first' order, meaning the top level of the chain will
  111. * be first.
  112. * @param $registry_callback
  113. * The callback to invoke to set the theme registry.
  114. */
  115. function _drupal_theme_initialize($theme, $base_theme = array(), $registry_callback = '_theme_load_registry') {
  116. global $theme_info, $base_theme_info, $theme_engine, $theme_path;
  117. $theme_info = $theme;
  118. $base_theme_info = $base_theme;
  119. $theme_path = dirname($theme->filename);
  120. // Prepare stylesheets from this theme as well as all ancestor themes.
  121. // We work it this way so that we can have child themes override parent
  122. // theme stylesheets easily.
  123. $final_stylesheets = array();
  124. // Grab stylesheets from base theme
  125. foreach ($base_theme as $base) {
  126. if (!empty($base->stylesheets)) {
  127. foreach ($base->stylesheets as $media => $stylesheets) {
  128. foreach ($stylesheets as $name => $stylesheet) {
  129. $final_stylesheets[$media][$name] = $stylesheet;
  130. }
  131. }
  132. }
  133. }
  134. // Add stylesheets used by this theme.
  135. if (!empty($theme->stylesheets)) {
  136. foreach ($theme->stylesheets as $media => $stylesheets) {
  137. foreach ($stylesheets as $name => $stylesheet) {
  138. $final_stylesheets[$media][$name] = $stylesheet;
  139. }
  140. }
  141. }
  142. // And now add the stylesheets properly
  143. foreach ($final_stylesheets as $media => $stylesheets) {
  144. foreach ($stylesheets as $stylesheet) {
  145. drupal_add_css($stylesheet, array('weight' => CSS_THEME, 'media' => $media, 'preprocess' => TRUE));
  146. }
  147. }
  148. // Do basically the same as the above for scripts
  149. $final_scripts = array();
  150. // Grab scripts from base theme
  151. foreach ($base_theme as $base) {
  152. if (!empty($base->scripts)) {
  153. foreach ($base->scripts as $name => $script) {
  154. $final_scripts[$name] = $script;
  155. }
  156. }
  157. }
  158. // Add scripts used by this theme.
  159. if (!empty($theme->scripts)) {
  160. foreach ($theme->scripts as $name => $script) {
  161. $final_scripts[$name] = $script;
  162. }
  163. }
  164. // Add scripts used by this theme.
  165. foreach ($final_scripts as $script) {
  166. drupal_add_js($script, array('weight' => JS_THEME, 'preprocess' => TRUE));
  167. }
  168. $theme_engine = NULL;
  169. // Initialize the theme.
  170. if (isset($theme->engine)) {
  171. // Include the engine.
  172. include_once DRUPAL_ROOT . '/' . $theme->owner;
  173. $theme_engine = $theme->engine;
  174. if (function_exists($theme_engine . '_init')) {
  175. foreach ($base_theme as $base) {
  176. call_user_func($theme_engine . '_init', $base);
  177. }
  178. call_user_func($theme_engine . '_init', $theme);
  179. }
  180. }
  181. else {
  182. // include non-engine theme files
  183. foreach ($base_theme as $base) {
  184. // Include the theme file or the engine.
  185. if (!empty($base->owner)) {
  186. include_once DRUPAL_ROOT . '/' . $base->owner;
  187. }
  188. }
  189. // and our theme gets one too.
  190. if (!empty($theme->owner)) {
  191. include_once DRUPAL_ROOT . '/' . $theme->owner;
  192. }
  193. }
  194. if (function_exists($registry_callback)) {
  195. $registry_callback($theme, $base_theme, $theme_engine);
  196. }
  197. }
  198. /**
  199. * Get the theme registry.
  200. *
  201. * @return
  202. * The theme registry array if it has been stored in memory, NULL otherwise.
  203. */
  204. function theme_get_registry() {
  205. return _theme_set_registry();
  206. }
  207. /**
  208. * Store the theme registry in memory.
  209. *
  210. * @param $registry
  211. * A registry array as returned by _theme_build_registry()
  212. *
  213. * @return
  214. * The theme registry array stored in memory
  215. */
  216. function _theme_set_registry($registry = NULL) {
  217. static $theme_registry = NULL;
  218. if (isset($registry)) {
  219. $theme_registry = $registry;
  220. }
  221. return $theme_registry;
  222. }
  223. /**
  224. * Get the theme_registry cache from the database; if it doesn't exist, build it.
  225. *
  226. * @param $theme
  227. * The loaded $theme object as returned by list_themes().
  228. * @param $base_theme
  229. * An array of loaded $theme objects representing the ancestor themes in
  230. * oldest first order.
  231. * @param theme_engine
  232. * The name of the theme engine.
  233. */
  234. function _theme_load_registry($theme, $base_theme = NULL, $theme_engine = NULL) {
  235. // Check the theme registry cache; if it exists, use it.
  236. $cache = cache_get("theme_registry:$theme->name", 'cache');
  237. if (isset($cache->data)) {
  238. $registry = $cache->data;
  239. _theme_set_registry($registry);
  240. }
  241. else {
  242. // If not, build one and cache it.
  243. $registry = _theme_build_registry($theme, $base_theme, $theme_engine);
  244. // Only persist this registry if all modules are loaded. This assures a
  245. // complete set of theme hooks.
  246. if (module_load_all(NULL)) {
  247. _theme_save_registry($theme, $registry);
  248. _theme_set_registry($registry);
  249. }
  250. }
  251. }
  252. /**
  253. * Write the theme_registry cache into the database.
  254. */
  255. function _theme_save_registry($theme, $registry) {
  256. cache_set("theme_registry:$theme->name", $registry);
  257. }
  258. /**
  259. * Force the system to rebuild the theme registry; this should be called
  260. * when modules are added to the system, or when a dynamic system needs
  261. * to add more theme hooks.
  262. */
  263. function drupal_theme_rebuild() {
  264. cache_clear_all('theme_registry', 'cache', TRUE);
  265. }
  266. /**
  267. * Process a single implementation of hook_theme().
  268. *
  269. * @param $cache
  270. * The theme registry that will eventually be cached; It is an associative
  271. * array keyed by theme hooks, whose values are associative arrays describing
  272. * the hook:
  273. * - 'type': The passed in $type.
  274. * - 'theme path': The passed in $path.
  275. * - 'function': The name of the function generating output for this theme
  276. * hook. Either defined explicitly in hook_theme() or, if neither 'function'
  277. * nor 'template' is defined, then the default theme function name is used.
  278. * The default theme function name is the theme hook prefixed by either
  279. * 'theme_' for modules or '$name_' for everything else. If 'function' is
  280. * defined, 'template' is not used.
  281. * - 'template': The filename of the template generating output for this
  282. * theme hook. The template is in the directory defined by the 'path' key of
  283. * hook_theme() or defaults to $path.
  284. * - 'variables': The variables for this theme hook as defined in
  285. * hook_theme(). If there is more than one implementation and 'variables' is
  286. * not specified in a later one, then the previous definition is kept.
  287. * - 'render element': The renderable element for this theme hook as defined
  288. * in hook_theme(). If there is more than one implementation and
  289. * 'render element' is not specified in a later one, then the previous
  290. * definition is kept.
  291. * - 'preprocess functions': See theme() for detailed documentation.
  292. * - 'process functions': See theme() for detailed documentation.
  293. * @param $name
  294. * The name of the module, theme engine, base theme engine, theme or base
  295. * theme implementing hook_theme().
  296. * @param $type
  297. * One of 'module', 'theme_engine', 'base_theme_engine', 'theme', or
  298. * 'base_theme'. Unlike regular hooks that can only be implemented by modules,
  299. * each of these can implement hook_theme(). _theme_process_registry() is
  300. * called in aforementioned order and new entries override older ones. For
  301. * example, if a theme hook is both defined by a module and a theme, then the
  302. * definition in the theme will be used.
  303. * @param $theme
  304. * The loaded $theme object as returned from list_themes().
  305. * @param $path
  306. * The directory where $name is. For example, modules/system or
  307. * themes/bartik.
  308. *
  309. * @see theme()
  310. * @see _theme_process_registry()
  311. * @see hook_theme()
  312. * @see list_themes()
  313. */
  314. function _theme_process_registry(&$cache, $name, $type, $theme, $path) {
  315. $result = array();
  316. $function = $name . '_theme';
  317. // Processor functions work in two distinct phases with the process
  318. // functions always being executed after the preprocess functions.
  319. $variable_process_phases = array(
  320. 'preprocess functions' => 'preprocess',
  321. 'process functions' => 'process',
  322. );
  323. if (function_exists($function)) {
  324. $result = $function($cache, $type, $theme, $path);
  325. foreach ($result as $hook => $info) {
  326. $result[$hook]['type'] = $type;
  327. $result[$hook]['theme path'] = $path;
  328. // if function and file are left out, default to standard naming
  329. // conventions.
  330. if (!isset($info['template']) && !isset($info['function'])) {
  331. $result[$hook]['function'] = ($type == 'module' ? 'theme_' : $name . '_') . $hook;
  332. }
  333. // If a path is set in the info, use what was set. Otherwise use the
  334. // default path. This is mostly so system.module can declare theme
  335. // functions on behalf of core .include files.
  336. // All files are included to be safe. Conditionally included
  337. // files can prevent them from getting registered.
  338. if (isset($cache[$hook]['includes'])) {
  339. $result[$hook]['includes'] = $cache[$hook]['includes'];
  340. }
  341. if (isset($info['file'])) {
  342. $include_file = isset($info['path']) ? $info['path'] : $path;
  343. $include_file .= '/' . $info['file'];
  344. include_once DRUPAL_ROOT . '/' . $include_file;
  345. $result[$hook]['includes'][] = $include_file;
  346. }
  347. // If these keys are left unspecified within overridden entries returned
  348. // by hook_theme(), carry them forward from the prior entry. This is so
  349. // that themes don't need to specify this information, since the module
  350. // that registered the theme hook already has.
  351. foreach (array('variables', 'render element', 'pattern', 'base hook') as $key) {
  352. if (!array_key_exists($key, $info) && isset($cache[$hook][$key])) {
  353. $result[$hook][$key] = $cache[$hook][$key];
  354. }
  355. }
  356. // The following apply only to theming hooks implemented as templates.
  357. if (isset($info['template'])) {
  358. // Prepend the current theming path when none is set.
  359. if (!isset($info['path'])) {
  360. $result[$hook]['template'] = $path . '/' . $info['template'];
  361. }
  362. }
  363. // Allow variable processors for all theming hooks, whether the hook is
  364. // implemented as a template or as a function.
  365. foreach ($variable_process_phases as $phase_key => $phase) {
  366. // Check for existing variable processors. Ensure arrayness.
  367. if (!isset($info[$phase_key]) || !is_array($info[$phase_key])) {
  368. $info[$phase_key] = array();
  369. $prefixes = array();
  370. if ($type == 'module') {
  371. // Default variable processor prefix.
  372. $prefixes[] = 'template';
  373. // Add all modules so they can intervene with their own variable
  374. // processors. This allows them to provide variable processors even
  375. // if they are not the owner of the current hook.
  376. $prefixes += module_list();
  377. }
  378. elseif ($type == 'theme_engine' || $type == 'base_theme_engine') {
  379. // Theme engines get an extra set that come before the normally
  380. // named variable processors.
  381. $prefixes[] = $name . '_engine';
  382. // The theme engine registers on behalf of the theme using the
  383. // theme's name.
  384. $prefixes[] = $theme;
  385. }
  386. else {
  387. // This applies when the theme manually registers their own variable
  388. // processors.
  389. $prefixes[] = $name;
  390. }
  391. foreach ($prefixes as $prefix) {
  392. // Only use non-hook-specific variable processors for theming hooks
  393. // implemented as templates. See theme().
  394. if (isset($info['template']) && function_exists($prefix . '_' . $phase)) {
  395. $info[$phase_key][] = $prefix . '_' . $phase;
  396. }
  397. if (function_exists($prefix . '_' . $phase . '_' . $hook)) {
  398. $info[$phase_key][] = $prefix . '_' . $phase . '_' . $hook;
  399. }
  400. }
  401. }
  402. // Check for the override flag and prevent the cached variable
  403. // processors from being used. This allows themes or theme engines to
  404. // remove variable processors set earlier in the registry build.
  405. if (!empty($info['override ' . $phase_key])) {
  406. // Flag not needed inside the registry.
  407. unset($result[$hook]['override ' . $phase_key]);
  408. }
  409. elseif (isset($cache[$hook][$phase_key]) && is_array($cache[$hook][$phase_key])) {
  410. $info[$phase_key] = array_merge($cache[$hook][$phase_key], $info[$phase_key]);
  411. }
  412. $result[$hook][$phase_key] = $info[$phase_key];
  413. }
  414. }
  415. // Merge the newly created theme hooks into the existing cache.
  416. $cache = array_merge($cache, $result);
  417. }
  418. // Let themes have variable processors even if they didn't register a template.
  419. if ($type == 'theme' || $type == 'base_theme') {
  420. foreach ($cache as $hook => $info) {
  421. // Check only if not registered by the theme or engine.
  422. if (empty($result[$hook])) {
  423. foreach ($variable_process_phases as $phase_key => $phase) {
  424. if (!isset($info[$phase_key])) {
  425. $cache[$hook][$phase_key] = array();
  426. }
  427. // Only use non-hook-specific variable processors for theming hooks
  428. // implemented as templates. See theme().
  429. if (isset($info['template']) && function_exists($name . '_' . $phase)) {
  430. $cache[$hook][$phase_key][] = $name . '_' . $phase;
  431. }
  432. if (function_exists($name . '_' . $phase . '_' . $hook)) {
  433. $cache[$hook][$phase_key][] = $name . '_' . $phase . '_' . $hook;
  434. $cache[$hook]['theme path'] = $path;
  435. }
  436. // Ensure uniqueness.
  437. $cache[$hook][$phase_key] = array_unique($cache[$hook][$phase_key]);
  438. }
  439. }
  440. }
  441. }
  442. }
  443. /**
  444. * Rebuild the theme registry cache.
  445. *
  446. * @param $theme
  447. * The loaded $theme object as returned by list_themes().
  448. * @param $base_theme
  449. * An array of loaded $theme objects representing the ancestor themes in
  450. * oldest first order.
  451. * @param theme_engine
  452. * The name of the theme engine.
  453. */
  454. function _theme_build_registry($theme, $base_theme, $theme_engine) {
  455. $cache = array();
  456. // First, process the theme hooks advertised by modules. This will
  457. // serve as the basic registry.
  458. foreach (module_implements('theme') as $module) {
  459. _theme_process_registry($cache, $module, 'module', $module, drupal_get_path('module', $module));
  460. }
  461. // Process each base theme.
  462. foreach ($base_theme as $base) {
  463. // If the base theme uses a theme engine, process its hooks.
  464. $base_path = dirname($base->filename);
  465. if ($theme_engine) {
  466. _theme_process_registry($cache, $theme_engine, 'base_theme_engine', $base->name, $base_path);
  467. }
  468. _theme_process_registry($cache, $base->name, 'base_theme', $base->name, $base_path);
  469. }
  470. // And then the same thing, but for the theme.
  471. if ($theme_engine) {
  472. _theme_process_registry($cache, $theme_engine, 'theme_engine', $theme->name, dirname($theme->filename));
  473. }
  474. // Finally, hooks provided by the theme itself.
  475. _theme_process_registry($cache, $theme->name, 'theme', $theme->name, dirname($theme->filename));
  476. // Let modules alter the registry.
  477. drupal_alter('theme_registry', $cache);
  478. // Optimize the registry to not have empty arrays for functions.
  479. foreach ($cache as $hook => $info) {
  480. foreach (array('preprocess functions', 'process functions') as $phase) {
  481. if (empty($info[$phase])) {
  482. unset($cache[$hook][$phase]);
  483. }
  484. }
  485. }
  486. return $cache;
  487. }
  488. /**
  489. * Return a list of all currently available themes.
  490. *
  491. * Retrieved from the database, if available and the site is not in maintenance
  492. * mode; otherwise compiled freshly from the filesystem.
  493. *
  494. * @param $refresh
  495. * Whether to reload the list of themes from the database. Defaults to FALSE.
  496. *
  497. * @return
  498. * An associative array of the currently available themes. The keys are the
  499. * names of the themes and the values are objects having the following
  500. * properties:
  501. * - 'filename': The name of the .info file.
  502. * - 'name': The name of the theme.
  503. * - 'status': 1 for enabled, 0 for disabled themes.
  504. * - 'info': The contents of the .info file.
  505. * - 'stylesheets': A two dimensional array, using the first key for the
  506. * 'media' attribute (e.g. 'all'), the second for the name of the file
  507. * (e.g. style.css). The value is a complete filepath
  508. * (e.g. themes/bartik/style.css).
  509. * - 'scripts': An associative array of JavaScripts, using the filename as key
  510. * and the complete filepath as value.
  511. * - 'engine': The name of the theme engine.
  512. * - 'base theme': The name of the base theme.
  513. */
  514. function list_themes($refresh = FALSE) {
  515. $list = &drupal_static(__FUNCTION__, array());
  516. if ($refresh) {
  517. $list = array();
  518. system_list_reset();
  519. }
  520. if (empty($list)) {
  521. $list = array();
  522. $themes = array();
  523. // Extract from the database only when it is available.
  524. // Also check that the site is not in the middle of an install or update.
  525. if (!defined('MAINTENANCE_MODE')) {
  526. try {
  527. foreach (system_list('theme') as $theme) {
  528. if (file_exists($theme->filename)) {
  529. $theme->info = unserialize($theme->info);
  530. $themes[] = $theme;
  531. }
  532. }
  533. }
  534. catch (Exception $e) {
  535. // If the database is not available, rebuild the theme data.
  536. $themes = _system_rebuild_theme_data();
  537. }
  538. }
  539. else {
  540. // Scan the installation when the database should not be read.
  541. $themes = _system_rebuild_theme_data();
  542. }
  543. foreach ($themes as $theme) {
  544. foreach ($theme->info['stylesheets'] as $media => $stylesheets) {
  545. foreach ($stylesheets as $stylesheet => $path) {
  546. $theme->stylesheets[$media][$stylesheet] = $path;
  547. }
  548. }
  549. foreach ($theme->info['scripts'] as $script => $path) {
  550. if (file_exists($path)) {
  551. $theme->scripts[$script] = $path;
  552. }
  553. }
  554. if (isset($theme->info['engine'])) {
  555. $theme->engine = $theme->info['engine'];
  556. }
  557. if (isset($theme->info['base theme'])) {
  558. $theme->base_theme = $theme->info['base theme'];
  559. }
  560. // Status is normally retrieved from the database. Add zero values when
  561. // read from the installation directory to prevent notices.
  562. if (!isset($theme->status)) {
  563. $theme->status = 0;
  564. }
  565. $list[$theme->name] = $theme;
  566. }
  567. }
  568. return $list;
  569. }
  570. /**
  571. * Generates themed output.
  572. *
  573. * All requests for themed output must go through this function. It examines
  574. * the request and routes it to the appropriate theme function or template, by
  575. * checking the theme registry.
  576. *
  577. * The first argument to this function is the name of the theme hook. For
  578. * instance, to theme a table, the theme hook name is 'table'. By default, this
  579. * theme hook could be implemented by a function called 'theme_table' or a
  580. * template file called 'table.tpl.php', but hook_theme() can override the
  581. * default function or template name.
  582. *
  583. * If the implementation is a template file, several functions are called
  584. * before the template file is invoked, to modify the $variables array. These
  585. * fall into the "preprocessing" phase and the "processing" phase, and are
  586. * executed (if they exist), in the following order (note that in the following
  587. * list, HOOK indicates the theme hook name, MODULE indicates a module name,
  588. * THEME indicates a theme name, and ENGINE indicates a theme engine name):
  589. * - template_preprocess(&$variables, $hook): Creates a default set of variables
  590. * for all theme hooks.
  591. * - template_preprocess_HOOK(&$variables): Should be implemented by
  592. * the module that registers the theme hook, to set up default variables.
  593. * - MODULE_preprocess(&$variables, $hook): hook_preprocess() is invoked on all
  594. * implementing modules.
  595. * - MODULE_preprocess_HOOK(&$variables): hook_preprocess_HOOK() is invoked on
  596. * all implementing modules, so that modules that didn't define the theme hook
  597. * can alter the variables.
  598. * - ENGINE_engine_preprocess(&$variables, $hook): Allows the theme engine to
  599. * set necessary variables for all theme hooks.
  600. * - ENGINE_engine_preprocess_HOOK(&$variables): Allows the theme engine to set
  601. * necessary variables for the particular theme hook.
  602. * - THEME_preprocess(&$variables, $hook): Allows the theme to set necessary
  603. * variables for all theme hooks.
  604. * - THEME_preprocess_HOOK(&$variables): Allows the theme to set necessary
  605. * variables specific to the particular theme hook.
  606. * - template_process(&$variables, $hook): Creates a default set of variables
  607. * for all theme hooks.
  608. * - template_process_HOOK(&$variables): This is the first processor specific
  609. * to the theme hook; it should be implemented by the module that registers
  610. * it.
  611. * - MODULE_process(&$variables, $hook): hook_process() is invoked on all
  612. * implementing modules.
  613. * - MODULE_process_HOOK(&$variables): hook_process_HOOK() is invoked on
  614. * on all implementing modules, so that modules that didn't define the theme
  615. * hook can alter the variables.
  616. * - ENGINE_engine_process(&$variables, $hook): Allows the theme engine to set
  617. * necessary variables for all theme hooks.
  618. * - ENGINE_engine_process_HOOK(&$variables): Allows the theme engine to set
  619. * necessary variables for the particular theme hook.
  620. * - ENGINE_process(&$variables, $hook): Allows the theme engine to process the
  621. * variables.
  622. * - ENGINE_process_HOOK(&$variables): Allows the theme engine to process the
  623. * variables specific to the theme hook.
  624. * - THEME_process(&$variables, $hook): Allows the theme to process the
  625. * variables.
  626. * - THEME_process_HOOK(&$variables): Allows the theme to process the
  627. * variables specific to the theme hook.
  628. *
  629. * If the implementation is a function, only the theme-hook-specific preprocess
  630. * and process functions (the ones ending in _HOOK) are called from the
  631. * list above. This is because theme hooks with function implementations
  632. * need to be fast, and calling the non-theme-hook-specific preprocess and
  633. * process functions for them would incur a noticeable performance penalty.
  634. *
  635. * There are two special variables that these preprocess and process functions
  636. * can set: 'theme_hook_suggestion' and 'theme_hook_suggestions'. These will be
  637. * merged together to form a list of 'suggested' alternate theme hooks to use,
  638. * in reverse order of priority. theme_hook_suggestion will always be a higher
  639. * priority than items in theme_hook_suggestions. theme() will use the
  640. * highest priority implementation that exists. If none exists, theme() will
  641. * use the implementation for the theme hook it was called with. These
  642. * suggestions are similar to and are used for similar reasons as calling
  643. * theme() with an array as the $hook parameter (see below). The difference
  644. * is whether the suggestions are determined by the code that calls theme() or
  645. * by a preprocess or process function.
  646. *
  647. * @param $hook
  648. * The name of the theme hook to call. If the name contains a
  649. * double-underscore ('__') and there isn't an implementation for the full
  650. * name, the part before the '__' is checked. This allows a fallback to a more
  651. * generic implementation. For example, if theme('links__node', ...) is
  652. * called, but there is no implementation of that theme hook, then the 'links'
  653. * implementation is used. This process is iterative, so if
  654. * theme('links__contextual__node', ...) is called, theme() checks for the
  655. * following implementations, and uses the first one that exists:
  656. * - links__contextual__node
  657. * - links__contextual
  658. * - links
  659. * This allows themes to create specific theme implementations for named
  660. * objects and contexts of otherwise generic theme hooks. The $hook parameter
  661. * may also be an array, in which case the first theme hook that has an
  662. * implementation is used. This allows for the code that calls theme() to
  663. * explicitly specify the fallback order in a situation where using the '__'
  664. * convention is not desired or is insufficient.
  665. * @param $variables
  666. * An associative array of variables to merge with defaults from the theme
  667. * registry, pass to preprocess and process functions for modification, and
  668. * finally, pass to the function or template implementing the theme hook.
  669. * Alternatively, this can be a renderable array, in which case, its
  670. * properties are mapped to variables expected by the theme hook
  671. * implementations.
  672. *
  673. * @return
  674. * An HTML string representing the themed output.
  675. */
  676. function theme($hook, $variables = array()) {
  677. static $hooks = NULL;
  678. // If called before all modules are loaded, we do not necessarily have a full
  679. // theme registry to work with, and therefore cannot process the theme
  680. // request properly. See also _theme_load_registry().
  681. if (!module_load_all(NULL) && !defined('MAINTENANCE_MODE')) {
  682. throw new Exception(t('theme() may not be called until all modules are loaded.'));
  683. }
  684. if (!isset($hooks)) {
  685. drupal_theme_initialize();
  686. $hooks = theme_get_registry();
  687. }
  688. // If an array of hook candidates were passed, use the first one that has an
  689. // implementation.
  690. if (is_array($hook)) {
  691. foreach ($hook as $candidate) {
  692. if (isset($hooks[$candidate])) {
  693. break;
  694. }
  695. }
  696. $hook = $candidate;
  697. }
  698. // If there's no implementation, check for more generic fallbacks. If there's
  699. // still no implementation, log an error and return an empty string.
  700. if (!isset($hooks[$hook])) {
  701. // Iteratively strip everything after the last '__' delimiter, until an
  702. // implementation is found.
  703. while ($pos = strrpos($hook, '__')) {
  704. $hook = substr($hook, 0, $pos);
  705. if (isset($hooks[$hook])) {
  706. break;
  707. }
  708. }
  709. if (!isset($hooks[$hook])) {
  710. watchdog('theme', 'Theme key "@key" not found.', array('@key' => $hook), WATCHDOG_WARNING);
  711. return '';
  712. }
  713. }
  714. $info = $hooks[$hook];
  715. global $theme_path;
  716. $temp = $theme_path;
  717. // point path_to_theme() to the currently used theme path:
  718. $theme_path = $info['theme path'];
  719. // Include a file if the theme function or variable processor is held elsewhere.
  720. if (!empty($info['includes'])) {
  721. foreach ($info['includes'] as $include_file) {
  722. include_once DRUPAL_ROOT . '/' . $include_file;
  723. }
  724. }
  725. // If a renderable array is passed as $variables, then set $variables to
  726. // the arguments expected by the theme function.
  727. if (isset($variables['#theme']) || isset($variables['#theme_wrappers'])) {
  728. $element = $variables;
  729. $variables = array();
  730. if (isset($info['variables'])) {
  731. foreach (array_keys($info['variables']) as $name) {
  732. if (isset($element["#$name"])) {
  733. $variables[$name] = $element["#$name"];
  734. }
  735. }
  736. }
  737. else {
  738. $variables[$info['render element']] = $element;
  739. }
  740. }
  741. // Merge in argument defaults.
  742. if (!empty($info['variables'])) {
  743. $variables += $info['variables'];
  744. }
  745. elseif (!empty($info['render element'])) {
  746. $variables += array($info['render element'] => array());
  747. }
  748. // Invoke the variable processors, if any. The processors may specify
  749. // alternate suggestions for which hook's template/function to use. If the
  750. // hook is a suggestion of a base hook, invoke the variable processors of
  751. // the base hook, but retain the suggestion as a high priority suggestion to
  752. // be used unless overridden by a variable processor function.
  753. if (isset($info['base hook'])) {
  754. $base_hook = $info['base hook'];
  755. $base_hook_info = $hooks[$base_hook];
  756. if (isset($base_hook_info['preprocess functions']) || isset($base_hook_info['process functions'])) {
  757. $variables['theme_hook_suggestion'] = $hook;
  758. $hook = $base_hook;
  759. $info = $base_hook_info;
  760. }
  761. }
  762. if (isset($info['preprocess functions']) || isset($info['process functions'])) {
  763. $variables['theme_hook_suggestions'] = array();
  764. foreach (array('preprocess functions', 'process functions') as $phase) {
  765. if (!empty($info[$phase])) {
  766. foreach ($info[$phase] as $processor_function) {
  767. if (function_exists($processor_function)) {
  768. // We don't want a poorly behaved process function changing $hook.
  769. $hook_clone = $hook;
  770. $processor_function($variables, $hook_clone);
  771. }
  772. }
  773. }
  774. }
  775. // If the preprocess/process functions specified hook suggestions, and the
  776. // suggestion exists in the theme registry, use it instead of the hook that
  777. // theme() was called with. This allows the preprocess/process step to
  778. // route to a more specific theme hook. For example, a function may call
  779. // theme('node', ...), but a preprocess function can add 'node__article' as
  780. // a suggestion, enabling a theme to have an alternate template file for
  781. // article nodes. Suggestions are checked in the following order:
  782. // - The 'theme_hook_suggestion' variable is checked first. It overrides
  783. // all others.
  784. // - The 'theme_hook_suggestions' variable is checked in FILO order, so the
  785. // last suggestion added to the array takes precedence over suggestions
  786. // added earlier.
  787. $suggestions = array();
  788. if (!empty($variables['theme_hook_suggestions'])) {
  789. $suggestions = $variables['theme_hook_suggestions'];
  790. }
  791. if (!empty($variables['theme_hook_suggestion'])) {
  792. $suggestions[] = $variables['theme_hook_suggestion'];
  793. }
  794. foreach (array_reverse($suggestions) as $suggestion) {
  795. if (isset($hooks[$suggestion])) {
  796. $info = $hooks[$suggestion];
  797. break;
  798. }
  799. }
  800. }
  801. // Generate the output using either a function or a template.
  802. if (isset($info['function'])) {
  803. if (function_exists($info['function'])) {
  804. $output = $info['function']($variables);
  805. }
  806. }
  807. else {
  808. // Default render function and extension.
  809. $render_function = 'theme_render_template';
  810. $extension = '.tpl.php';
  811. // The theme engine may use a different extension and a different renderer.
  812. global $theme_engine;
  813. if (isset($theme_engine)) {
  814. if ($info['type'] != 'module') {
  815. if (function_exists($theme_engine . '_render_template')) {
  816. $render_function = $theme_engine . '_render_template';
  817. }
  818. $extension_function = $theme_engine . '_extension';
  819. if (function_exists($extension_function)) {
  820. $extension = $extension_function();
  821. }
  822. }
  823. }
  824. // In some cases, a template implementation may not have had
  825. // template_preprocess() run (for example, if the default implementation is
  826. // a function, but a template overrides that default implementation). In
  827. // these cases, a template should still be able to expect to have access to
  828. // the variables provided by template_preprocess(), so we add them here if
  829. // they don't already exist. We don't want to run template_preprocess()
  830. // twice (it would be inefficient and mess up zebra striping), so we use the
  831. // 'directory' variable to determine if it has already run, which while not
  832. // completely intuitive, is reasonably safe, and allows us to save on the
  833. // overhead of adding some new variable to track that.
  834. if (!isset($variables['directory'])) {
  835. $default_template_variables = array();
  836. template_preprocess($default_template_variables, $hook);
  837. $variables += $default_template_variables;
  838. }
  839. // Render the output using the template file.
  840. $template_file = $info['template'] . $extension;
  841. if (isset($info['path'])) {
  842. $template_file = $info['path'] . '/' . $template_file;
  843. }
  844. $output = $render_function($template_file, $variables);
  845. }
  846. // restore path_to_theme()
  847. $theme_path = $temp;
  848. return $output;
  849. }
  850. /**
  851. * Return the path to the current themed element.
  852. *
  853. * It can point to the active theme or the module handling a themed implementation.
  854. * For example, when invoked within the scope of a theming call it will depend
  855. * on where the theming function is handled. If implemented from a module, it
  856. * will point to the module. If implemented from the active theme, it will point
  857. * to the active theme. When called outside the scope of a theming call, it will
  858. * always point to the active theme.
  859. */
  860. function path_to_theme() {
  861. global $theme_path;
  862. if (!isset($theme_path)) {
  863. drupal_theme_initialize();
  864. }
  865. return $theme_path;
  866. }
  867. /**
  868. * Allow themes and/or theme engines to easily discover overridden theme functions.
  869. *
  870. * @param $cache
  871. * The existing cache of theme hooks to test against.
  872. * @param $prefixes
  873. * An array of prefixes to test, in reverse order of importance.
  874. *
  875. * @return $implementations
  876. * The functions found, suitable for returning from hook_theme;
  877. */
  878. function drupal_find_theme_functions($cache, $prefixes) {
  879. $implementations = array();
  880. $functions = get_defined_functions();
  881. foreach ($cache as $hook => $info) {
  882. foreach ($prefixes as $prefix) {
  883. // Find theme functions that implement possible "suggestion" variants of
  884. // registered theme hooks and add those as new registered theme hooks.
  885. // The 'pattern' key defines a common prefix that all suggestions must
  886. // start with. The default is the name of the hook followed by '__'. An
  887. // 'base hook' key is added to each entry made for a found suggestion,
  888. // so that common functionality can be implemented for all suggestions of
  889. // the same base hook. To keep things simple, deep heirarchy of
  890. // suggestions is not supported: each suggestion's 'base hook' key
  891. // refers to a base hook, not to another suggestion, and all suggestions
  892. // are found using the base hook's pattern, not a pattern from an
  893. // intermediary suggestion.
  894. $pattern = isset($info['pattern']) ? $info['pattern'] : ($hook . '__');
  895. if (!isset($info['base hook']) && !empty($pattern)) {
  896. $matches = preg_grep('/^' . $prefix . '_' . $pattern . '/', $functions['user']);
  897. if ($matches) {
  898. foreach ($matches as $match) {
  899. $new_hook = str_replace($prefix . '_', '', $match);
  900. $arg_name = isset($info['variables']) ? 'variables' : 'render element';
  901. $implementations[$new_hook] = array(
  902. 'function' => $match,
  903. $arg_name => $info[$arg_name],
  904. 'base hook' => $hook,
  905. );
  906. }
  907. }
  908. }
  909. // Find theme functions that implement registered theme hooks and include
  910. // that in what is returned so that the registry knows that the theme has
  911. // this implementation.
  912. if (function_exists($prefix . '_' . $hook)) {
  913. $implementations[$hook] = array(
  914. 'function' => $prefix . '_' . $hook,
  915. );
  916. }
  917. }
  918. }
  919. return $implementations;
  920. }
  921. /**
  922. * Allow themes and/or theme engines to easily discover overridden templates.
  923. *
  924. * @param $cache
  925. * The existing cache of theme hooks to test against.
  926. * @param $extension
  927. * The extension that these templates will have.
  928. * @param $path
  929. * The path to search.
  930. */
  931. function drupal_find_theme_templates($cache, $extension, $path) {
  932. $implementations = array();
  933. // Collect paths to all sub-themes grouped by base themes. These will be
  934. // used for filtering. This allows base themes to have sub-themes in its
  935. // folder hierarchy without affecting the base themes template discovery.
  936. $theme_paths = array();
  937. foreach (list_themes() as $theme_info) {
  938. if (!empty($theme_info->base_theme)) {
  939. $theme_paths[$theme_info->base_theme][$theme_info->name] = dirname($theme_info->filename);
  940. }
  941. }
  942. foreach ($theme_paths as $basetheme => $subthemes) {
  943. foreach ($subthemes as $subtheme => $subtheme_path) {
  944. if (isset($theme_paths[$subtheme])) {
  945. $theme_paths[$basetheme] = array_merge($theme_paths[$basetheme], $theme_paths[$subtheme]);
  946. }
  947. }
  948. }
  949. global $theme;
  950. $subtheme_paths = isset($theme_paths[$theme]) ? $theme_paths[$theme] : array();
  951. // Escape the periods in the extension.
  952. $regex = '/' . str_replace('.', '\.', $extension) . '$/';
  953. // Get a listing of all template files in the path to search.
  954. $files = drupal_system_listing($regex, $path, 'name', 0);
  955. // Find templates that implement registered theme hooks and include that in
  956. // what is returned so that the registry knows that the theme has this
  957. // implementation.
  958. foreach ($files as $template => $file) {
  959. // Ignore sub-theme templates for the current theme.
  960. if (strpos($file->uri, str_replace($subtheme_paths, '', $file->uri)) !== 0) {
  961. continue;
  962. }
  963. // Chop off the remaining extensions if there are any. $template already
  964. // has the rightmost extension removed, but there might still be more,
  965. // such as with .tpl.php, which still has .tpl in $template at this point.
  966. if (($pos = strpos($template, '.')) !== FALSE) {
  967. $template = substr($template, 0, $pos);
  968. }
  969. // Transform - in filenames to _ to match function naming scheme
  970. // for the purposes of searching.
  971. $hook = strtr($template, '-', '_');
  972. if (isset($cache[$hook])) {
  973. $implementations[$hook] = array(
  974. 'template' => $template,
  975. 'path' => dirname($file->uri),
  976. );
  977. }
  978. }
  979. // Find templates that implement possible "suggestion" variants of registered
  980. // theme hooks and add those as new registered theme hooks. See
  981. // drupal_find_theme_functions() for more information about suggestions and
  982. // the use of 'pattern' and 'base hook'.
  983. $patterns = array_keys($files);
  984. foreach ($cache as $hook => $info) {
  985. $pattern = isset($info['pattern']) ? $info['pattern'] : ($hook . '__');
  986. if (!isset($info['base hook']) && !empty($pattern)) {
  987. // Transform _ in pattern to - to match file naming scheme
  988. // for the purposes of searching.
  989. $pattern = strtr($pattern, '_', '-');
  990. $matches = preg_grep('/^' . $pattern . '/', $patterns);
  991. if ($matches) {
  992. foreach ($matches as $match) {
  993. $file = substr($match, 0, strpos($match, '.'));
  994. // Put the underscores back in for the hook name and register this pattern.
  995. $arg_name = isset($info['variables']) ? 'variables' : 'render element';
  996. $implementations[strtr($file, '-', '_')] = array(
  997. 'template' => $file,
  998. 'path' => dirname($files[$match]->uri),
  999. $arg_name => $info[$arg_name],
  1000. 'base hook' => $hook,
  1001. );
  1002. }
  1003. }
  1004. }
  1005. }
  1006. return $implementations;
  1007. }
  1008. /**
  1009. * Retrieve a setting for the current theme or for a given theme.
  1010. *
  1011. * The final setting is obtained from the last value found in the following
  1012. * sources:
  1013. * - the default global settings specified in this function
  1014. * - the default theme-specific settings defined in any base theme's .info file
  1015. * - the default theme-specific settings defined in the theme's .info file
  1016. * - the saved values from the global theme settings form
  1017. * - the saved values from the theme's settings form
  1018. * To only retrieve the default global theme setting, an empty string should be
  1019. * given for $theme.
  1020. *
  1021. * @param $setting_name
  1022. * The name of the setting to be retrieved.
  1023. * @param $theme
  1024. * The name of a given theme; defaults to the current theme.
  1025. *
  1026. * @return
  1027. * The value of the requested setting, NULL if the setting does not exist.
  1028. */
  1029. function theme_get_setting($setting_name, $theme = NULL) {
  1030. $cache = &drupal_static(__FUNCTION__, array());
  1031. // If no key is given, use the current theme if we can determine it.
  1032. if (is_null($theme)) {
  1033. $theme = !empty($GLOBALS['theme_key']) ? $GLOBALS['theme_key'] : '';
  1034. }
  1035. if (empty($cache[$theme])) {
  1036. // Set the default values for each global setting.
  1037. // To add new global settings, add their default values below, and then
  1038. // add form elements to system_theme_settings() in system.admin.inc.
  1039. $cache[$theme] = array(
  1040. 'default_logo' => 1,
  1041. 'logo_path' => '',
  1042. 'default_favicon' => 1,
  1043. 'favicon_path' => '',
  1044. // Use the IANA-registered MIME type for ICO files as default.
  1045. 'favicon_mimetype' => 'image/vnd.microsoft.icon',
  1046. );
  1047. // Turn on all default features.
  1048. $features = _system_default_theme_features();
  1049. foreach ($features as $feature) {
  1050. $cache[$theme]['toggle_' . $feature] = 1;
  1051. }
  1052. // Get the values for the theme-specific settings from the .info files of
  1053. // the theme and all its base themes.
  1054. if ($theme) {
  1055. $themes = list_themes();
  1056. $theme_object = $themes[$theme];
  1057. // Create a list which includes the current theme and all its base themes.
  1058. if (isset($theme_object->base_themes)) {
  1059. $theme_keys = array_keys($theme_object->base_themes);
  1060. $theme_keys[] = $theme;
  1061. }
  1062. else {
  1063. $theme_keys = array($theme);
  1064. }
  1065. foreach ($theme_keys as $theme_key) {
  1066. if (!empty($themes[$theme_key]->info['settings'])) {
  1067. $cache[$theme] = array_merge($cache[$theme], $themes[$theme_key]->info['settings']);
  1068. }
  1069. }
  1070. }
  1071. // Get the saved global settings from the database.
  1072. $cache[$theme] = array_merge($cache[$theme], variable_get('theme_settings', array()));
  1073. if ($theme) {
  1074. // Get the saved theme-specific settings from the database.
  1075. $cache[$theme] = array_merge($cache[$theme], variable_get('theme_' . $theme . '_settings', array()));
  1076. // If the theme does not support a particular feature, override the global
  1077. // setting and set the value to NULL.
  1078. if (!empty($theme_object->info['features'])) {
  1079. foreach ($features as $feature) {
  1080. if (!in_array($feature, $theme_object->info['features'])) {
  1081. $cache[$theme]['toggle_' . $feature] = NULL;
  1082. }
  1083. }
  1084. }
  1085. // Generate the path to the logo image.
  1086. if ($cache[$theme]['toggle_logo']) {
  1087. if ($cache[$theme]['default_logo']) {
  1088. $cache[$theme]['logo'] = file_create_url(dirname($theme_object->filename) . '/logo.png');
  1089. }
  1090. elseif ($cache[$theme]['logo_path']) {
  1091. $cache[$theme]['logo'] = file_create_url($cache[$theme]['logo_path']);
  1092. }
  1093. }
  1094. // Generate the path to the favicon.
  1095. if ($cache[$theme]['toggle_favicon']) {
  1096. if ($cache[$theme]['default_favicon']) {
  1097. if (file_exists($favicon = dirname($theme_object->filename) . '/favicon.ico')) {
  1098. $cache[$theme]['favicon'] = file_create_url($favicon);
  1099. }
  1100. else {
  1101. $cache[$theme]['favicon'] = file_create_url('misc/favicon.ico');
  1102. }
  1103. }
  1104. elseif ($cache[$theme]['favicon_path']) {
  1105. $cache[$theme]['favicon'] = file_create_url($cache[$theme]['favicon_path']);
  1106. }
  1107. else {
  1108. $cache[$theme]['toggle_favicon'] = FALSE;
  1109. }
  1110. }
  1111. }
  1112. }
  1113. return isset($cache[$theme][$setting_name]) ? $cache[$theme][$setting_name] : NULL;
  1114. }
  1115. /**
  1116. * Render a system default template, which is essentially a PHP template.
  1117. *
  1118. * @param $template_file
  1119. * The filename of the template to render.
  1120. * @param $variables
  1121. * A keyed array of variables that will appear in the output.
  1122. *
  1123. * @return
  1124. * The output generated by the template.
  1125. */
  1126. function theme_render_template($template_file, $variables) {
  1127. extract($variables, EXTR_SKIP); // Extract the variables to a local namespace
  1128. ob_start(); // Start output buffering
  1129. include DRUPAL_ROOT . '/' . $template_file; // Include the template file
  1130. return ob_get_clean(); // End buffering and return its contents
  1131. }
  1132. /**
  1133. * Enable a given list of themes.
  1134. *
  1135. * @param $theme_list
  1136. * An array of theme names.
  1137. */
  1138. function theme_enable($theme_list) {
  1139. drupal_clear_css_cache();
  1140. foreach ($theme_list as $key) {
  1141. db_update('system')
  1142. ->fields(array('status' => 1))
  1143. ->condition('type', 'theme')
  1144. ->condition('name', $key)
  1145. ->execute();
  1146. }
  1147. list_themes(TRUE);
  1148. menu_rebuild();
  1149. drupal_theme_rebuild();
  1150. // Notify locale module about new themes being enabled, so translations can
  1151. // be imported. This might start a batch, and only return to the redirect
  1152. // path after that.
  1153. module_invoke('locale', 'system_update', $theme_list);
  1154. // Invoke hook_themes_enabled after the themes have been enabled.
  1155. module_invoke_all('themes_enabled', $theme_list);
  1156. return;
  1157. }
  1158. /**
  1159. * Disable a given list of themes.
  1160. *
  1161. * @param $theme_list
  1162. * An array of theme names.
  1163. */
  1164. function theme_disable($theme_list) {
  1165. // Don't disable the default theme.
  1166. if ($pos = array_search(variable_get('theme_default', 'bartik'), $theme_list) !== FALSE) {
  1167. unset($theme_list[$pos]);
  1168. if (empty($theme_list)) {
  1169. return;
  1170. }
  1171. }
  1172. drupal_clear_css_cache();
  1173. foreach ($theme_list as $key) {
  1174. db_update('system')
  1175. ->fields(array('status' => 0))
  1176. ->condition('type', 'theme')
  1177. ->condition('name', $key)
  1178. ->execute();
  1179. }
  1180. list_themes(TRUE);
  1181. menu_rebuild();
  1182. drupal_theme_rebuild();
  1183. // Invoke hook_themes_enabled after the themes have been enabled.
  1184. module_invoke_all('themes_disabled', $theme_list);
  1185. return;
  1186. }
  1187. /**
  1188. * @ingroup themeable
  1189. * @{
  1190. */
  1191. /**
  1192. * Returns HTML for status and/or error messages, grouped by type.
  1193. *
  1194. * An invisible heading identifies the messages for assistive technology.
  1195. * Sighted users see a colored box. See http://www.w3.org/TR/WCAG-TECHS/H69.html
  1196. * for info.
  1197. *
  1198. * @param $variables
  1199. * An associative array containing:
  1200. * - display: (optional) Set to 'status' or 'error' to display only messages
  1201. * of that type.
  1202. */
  1203. function theme_status_messages($variables) {
  1204. $display = $variables['display'];
  1205. $output = '';
  1206. $status_heading = array(
  1207. 'status' => t('Status message'),
  1208. 'error' => t('Error message'),
  1209. 'warning' => t('Warning message'),
  1210. );
  1211. foreach (drupal_get_messages($display) as $type => $messages) {
  1212. $output .= "<div class=\"messages $type\">\n";
  1213. if (!empty($status_heading[$type])) {
  1214. $output .= '<h2 class="element-invisible">' . $status_heading[$type] . "</h2>\n";
  1215. }
  1216. if (count($messages) > 1) {
  1217. $output .= " <ul>\n";
  1218. foreach ($messages as $message) {
  1219. $output .= ' <li>' . $message . "</li>\n";
  1220. }
  1221. $output .= " </ul>\n";
  1222. }
  1223. else {
  1224. $output .= $messages[0];
  1225. }
  1226. $output .= "</div>\n";
  1227. }
  1228. return $output;
  1229. }
  1230. /**
  1231. * Return…

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