1. 8.3.x core/includes/theme.inc
  2. 8.0.x core/includes/theme.inc
  3. 8.1.x core/includes/theme.inc
  4. 8.2.x core/includes/theme.inc
  5. 8.4.x core/includes/theme.inc
  6. 4.6.x includes/theme.inc
  7. 4.7.x includes/theme.inc
  8. 5.x includes/theme.inc
  9. 6.x includes/theme.inc
  10. 7.x includes/theme.inc

The theme system, which controls the output of Drupal.

The theme system allows for nearly all output of the Drupal system to be customized by user themes.

File

includes/theme.inc
View source
  1. <?php
  2. /**
  3. * @file
  4. * The theme system, which controls the output of Drupal.
  5. *
  6. * The theme system allows for nearly all output of the Drupal system to be
  7. * customized by user themes.
  8. *
  9. * @ingroup themeable
  10. */
  11. /**
  12. * @defgroup content_flags Content markers
  13. * @{
  14. * Markers used by theme_mark() and node_mark() to designate content.
  15. * @see theme_mark(), node_mark()
  16. */
  17. /**
  18. * Mark content as read.
  19. */
  20. define('MARK_READ', 0);
  21. /**
  22. * Mark content as being new.
  23. */
  24. define('MARK_NEW', 1);
  25. /**
  26. * Mark content as being updated.
  27. */
  28. define('MARK_UPDATED', 2);
  29. /**
  30. * @} End of "Content markers".
  31. */
  32. /**
  33. * Initialize the theme system by loading the theme.
  34. */
  35. function init_theme() {
  36. global $theme, $user, $custom_theme, $theme_key;
  37. // If $theme is already set, assume the others are set, too, and do nothing
  38. if (isset($theme)) {
  39. return;
  40. }
  41. drupal_bootstrap(DRUPAL_BOOTSTRAP_DATABASE);
  42. $themes = list_themes();
  43. // Only select the user selected theme if it is available in the
  44. // list of enabled themes.
  45. $theme = !empty($user->theme) && !empty($themes[$user->theme]->status) ? $user->theme : variable_get('theme_default', 'garland');
  46. // Allow modules to override the present theme... only select custom theme
  47. // if it is available in the list of installed themes.
  48. $theme = $custom_theme && $themes[$custom_theme] ? $custom_theme : $theme;
  49. // Store the identifier for retrieving theme settings with.
  50. $theme_key = $theme;
  51. // Find all our ancestor themes and put them in an array.
  52. $base_theme = array();
  53. $ancestor = $theme;
  54. while ($ancestor && isset($themes[$ancestor]->base_theme)) {
  55. $base_theme[] = $new_base_theme = $themes[$themes[$ancestor]->base_theme];
  56. $ancestor = $themes[$ancestor]->base_theme;
  57. }
  58. _init_theme($themes[$theme], array_reverse($base_theme));
  59. }
  60. /**
  61. * Initialize the theme system given already loaded information. This
  62. * function is useful to initialize a theme when no database is present.
  63. *
  64. * @param $theme
  65. * An object with the following information:
  66. * filename
  67. * The .info file for this theme. The 'path' to
  68. * the theme will be in this file's directory. (Required)
  69. * owner
  70. * The path to the .theme file or the .engine file to load for
  71. * the theme. (Required)
  72. * stylesheet
  73. * The primary stylesheet for the theme. (Optional)
  74. * engine
  75. * The name of theme engine to use. (Optional)
  76. * @param $base_theme
  77. * An optional array of objects that represent the 'base theme' if the
  78. * theme is meant to be derivative of another theme. It requires
  79. * the same information as the $theme object. It should be in
  80. * 'oldest first' order, meaning the top level of the chain will
  81. * be first.
  82. * @param $registry_callback
  83. * The callback to invoke to set the theme registry.
  84. */
  85. function _init_theme($theme, $base_theme = array(), $registry_callback = '_theme_load_registry') {
  86. global $theme_info, $base_theme_info, $theme_engine, $theme_path;
  87. $theme_info = $theme;
  88. $base_theme_info = $base_theme;
  89. $theme_path = dirname($theme->filename);
  90. // Prepare stylesheets from this theme as well as all ancestor themes.
  91. // We work it this way so that we can have child themes override parent
  92. // theme stylesheets easily.
  93. $final_stylesheets = array();
  94. // Grab stylesheets from base theme
  95. foreach ($base_theme as $base) {
  96. if (!empty($base->stylesheets)) {
  97. foreach ($base->stylesheets as $media => $stylesheets) {
  98. foreach ($stylesheets as $name => $stylesheet) {
  99. $final_stylesheets[$media][$name] = $stylesheet;
  100. }
  101. }
  102. }
  103. }
  104. // Add stylesheets used by this theme.
  105. if (!empty($theme->stylesheets)) {
  106. foreach ($theme->stylesheets as $media => $stylesheets) {
  107. foreach ($stylesheets as $name => $stylesheet) {
  108. $final_stylesheets[$media][$name] = $stylesheet;
  109. }
  110. }
  111. }
  112. // And now add the stylesheets properly
  113. foreach ($final_stylesheets as $media => $stylesheets) {
  114. foreach ($stylesheets as $stylesheet) {
  115. drupal_add_css($stylesheet, 'theme', $media);
  116. }
  117. }
  118. // Do basically the same as the above for scripts
  119. $final_scripts = array();
  120. // Grab scripts from base theme
  121. foreach ($base_theme as $base) {
  122. if (!empty($base->scripts)) {
  123. foreach ($base->scripts as $name => $script) {
  124. $final_scripts[$name] = $script;
  125. }
  126. }
  127. }
  128. // Add scripts used by this theme.
  129. if (!empty($theme->scripts)) {
  130. foreach ($theme->scripts as $name => $script) {
  131. $final_scripts[$name] = $script;
  132. }
  133. }
  134. // Add scripts used by this theme.
  135. foreach ($final_scripts as $script) {
  136. drupal_add_js($script, 'theme');
  137. }
  138. $theme_engine = NULL;
  139. // Initialize the theme.
  140. if (isset($theme->engine)) {
  141. // Include the engine.
  142. include_once './'. $theme->owner;
  143. $theme_engine = $theme->engine;
  144. if (function_exists($theme_engine .'_init')) {
  145. foreach ($base_theme as $base) {
  146. call_user_func($theme_engine .'_init', $base);
  147. }
  148. call_user_func($theme_engine .'_init', $theme);
  149. }
  150. }
  151. else {
  152. // include non-engine theme files
  153. foreach ($base_theme as $base) {
  154. // Include the theme file or the engine.
  155. if (!empty($base->owner)) {
  156. include_once './'. $base->owner;
  157. }
  158. }
  159. // and our theme gets one too.
  160. if (!empty($theme->owner)) {
  161. include_once './'. $theme->owner;
  162. }
  163. }
  164. $registry_callback($theme, $base_theme, $theme_engine);
  165. }
  166. /**
  167. * Retrieve the stored theme registry. If the theme registry is already
  168. * in memory it will be returned; otherwise it will attempt to load the
  169. * registry from cache. If this fails, it will construct the registry and
  170. * cache it.
  171. */
  172. function theme_get_registry($registry = NULL) {
  173. static $theme_registry = NULL;
  174. if (isset($registry)) {
  175. $theme_registry = $registry;
  176. }
  177. return $theme_registry;
  178. }
  179. /**
  180. * Store the theme registry in memory.
  181. */
  182. function _theme_set_registry($registry) {
  183. // Pass through for setting of static variable.
  184. return theme_get_registry($registry);
  185. }
  186. /**
  187. * Get the theme_registry cache from the database; if it doesn't exist, build
  188. * it.
  189. *
  190. * @param $theme
  191. * The loaded $theme object.
  192. * @param $base_theme
  193. * An array of loaded $theme objects representing the ancestor themes in
  194. * oldest first order.
  195. * @param theme_engine
  196. * The name of the theme engine.
  197. */
  198. function _theme_load_registry($theme, $base_theme = NULL, $theme_engine = NULL) {
  199. // Check the theme registry cache; if it exists, use it.
  200. $cache = cache_get("theme_registry:$theme->name", 'cache');
  201. if (isset($cache->data)) {
  202. $registry = $cache->data;
  203. }
  204. else {
  205. // If not, build one and cache it.
  206. $registry = _theme_build_registry($theme, $base_theme, $theme_engine);
  207. _theme_save_registry($theme, $registry);
  208. }
  209. _theme_set_registry($registry);
  210. }
  211. /**
  212. * Write the theme_registry cache into the database.
  213. */
  214. function _theme_save_registry($theme, $registry) {
  215. cache_set("theme_registry:$theme->name", $registry);
  216. }
  217. /**
  218. * Force the system to rebuild the theme registry; this should be called
  219. * when modules are added to the system, or when a dynamic system needs
  220. * to add more theme hooks.
  221. */
  222. function drupal_rebuild_theme_registry() {
  223. cache_clear_all('theme_registry', 'cache', TRUE);
  224. }
  225. /**
  226. * Process a single invocation of the theme hook. $type will be one
  227. * of 'module', 'theme_engine', 'base_theme_engine', 'theme', or 'base_theme'
  228. * and it tells us some important information.
  229. *
  230. * Because $cache is a reference, the cache will be continually
  231. * expanded upon; new entries will replace old entries in the
  232. * array_merge, but we are careful to ensure some data is carried
  233. * forward, such as the arguments a theme hook needs.
  234. *
  235. * An override flag can be set for preprocess functions. When detected the
  236. * cached preprocessors for the hook will not be merged with the newly set.
  237. * This can be useful to themes and theme engines by giving them more control
  238. * over how and when the preprocess functions are run.
  239. */
  240. function _theme_process_registry(&$cache, $name, $type, $theme, $path) {
  241. $result = array();
  242. $function = $name .'_theme';
  243. if (function_exists($function)) {
  244. $result = $function($cache, $type, $theme, $path);
  245. foreach ($result as $hook => $info) {
  246. $result[$hook]['type'] = $type;
  247. $result[$hook]['theme path'] = $path;
  248. // if function and file are left out, default to standard naming
  249. // conventions.
  250. if (!isset($info['template']) && !isset($info['function'])) {
  251. $result[$hook]['function'] = ($type == 'module' ? 'theme_' : $name .'_') . $hook;
  252. }
  253. // Make sure include files is set so we don't generate notices later.
  254. if (!isset($info['include files'])) {
  255. $result[$hook]['include files'] = array();
  256. }
  257. // If a path is set in the info, use what was set. Otherwise use the
  258. // default path. This is mostly so system.module can declare theme
  259. // functions on behalf of core .include files.
  260. // All files are included to be safe. Conditionally included
  261. // files can prevent them from getting registered.
  262. if (isset($info['file']) && !isset($info['path'])) {
  263. // First, check to see if the fully qualified file exists.
  264. $filename = './'. $path .'/'. $info['file'];
  265. if (file_exists($filename)) {
  266. require_once $filename;
  267. $result[$hook]['include files'][] = $filename;
  268. }
  269. else {
  270. $filename = './'. $info['file'];
  271. if (file_exists($filename)) {
  272. require_once $filename;
  273. $result[$hook]['include files'][] = $filename;
  274. }
  275. }
  276. }
  277. elseif (isset($info['file']) && isset($info['path'])) {
  278. $filename = './'. $info['path'] .'/'. $info['file'];
  279. if (file_exists($filename)) {
  280. require_once $filename;
  281. $result[$hook]['include files'][] = $filename;
  282. }
  283. }
  284. if (isset($info['template']) && !isset($info['path'])) {
  285. $result[$hook]['template'] = $path .'/'. $info['template'];
  286. }
  287. // If 'arguments' have been defined previously, carry them forward.
  288. // This should happen if a theme overrides a Drupal defined theme
  289. // function, for example.
  290. if (!isset($info['arguments']) && isset($cache[$hook])) {
  291. $result[$hook]['arguments'] = $cache[$hook]['arguments'];
  292. }
  293. // Likewise with theme paths. These are used for template naming suggestions.
  294. // Theme implementations can occur in multiple paths. Suggestions should follow.
  295. if (!isset($info['theme paths']) && isset($cache[$hook])) {
  296. $result[$hook]['theme paths'] = $cache[$hook]['theme paths'];
  297. }
  298. // Check for sub-directories.
  299. $result[$hook]['theme paths'][] = isset($info['path']) ? $info['path'] : $path;
  300. // Check for default _preprocess_ functions. Ensure arrayness.
  301. if (!isset($info['preprocess functions']) || !is_array($info['preprocess functions'])) {
  302. $info['preprocess functions'] = array();
  303. $prefixes = array();
  304. if ($type == 'module') {
  305. // Default preprocessor prefix.
  306. $prefixes[] = 'template';
  307. // Add all modules so they can intervene with their own preprocessors. This allows them
  308. // to provide preprocess functions even if they are not the owner of the current hook.
  309. $prefixes += module_list();
  310. }
  311. elseif ($type == 'theme_engine' || $type == 'base_theme_engine') {
  312. // Theme engines get an extra set that come before the normally named preprocessors.
  313. $prefixes[] = $name .'_engine';
  314. // The theme engine also registers on behalf of the theme. The theme or engine name can be used.
  315. $prefixes[] = $name;
  316. $prefixes[] = $theme;
  317. }
  318. else {
  319. // This applies when the theme manually registers their own preprocessors.
  320. $prefixes[] = $name;
  321. }
  322. foreach ($prefixes as $prefix) {
  323. if (function_exists($prefix .'_preprocess')) {
  324. $info['preprocess functions'][] = $prefix .'_preprocess';
  325. }
  326. if (function_exists($prefix .'_preprocess_'. $hook)) {
  327. $info['preprocess functions'][] = $prefix .'_preprocess_'. $hook;
  328. }
  329. if (!empty($info['original hook']) && function_exists($prefix .'_preprocess_'. $info['original hook'])) {
  330. $info['preprocess functions'][] = $prefix .'_preprocess_'. $info['original hook'];
  331. }
  332. }
  333. }
  334. // Check for the override flag and prevent the cached preprocess functions from being used.
  335. // This allows themes or theme engines to remove preprocessors set earlier in the registry build.
  336. if (!empty($info['override preprocess functions'])) {
  337. // Flag not needed inside the registry.
  338. unset($result[$hook]['override preprocess functions']);
  339. }
  340. elseif (isset($cache[$hook]['preprocess functions']) && is_array($cache[$hook]['preprocess functions'])) {
  341. $info['preprocess functions'] = array_merge($cache[$hook]['preprocess functions'], $info['preprocess functions']);
  342. }
  343. elseif (isset($info['original hook']) && isset($cache[$info['original hook']]['preprocess functions']) && is_array($cache[$info['original hook']]['preprocess functions'])) {
  344. $info['preprocess functions'] = array_merge($cache[$info['original hook']]['preprocess functions'], $info['preprocess functions']);
  345. }
  346. $result[$hook]['preprocess functions'] = $info['preprocess functions'];
  347. }
  348. // Merge the newly created theme hooks into the existing cache.
  349. $cache = array_merge($cache, $result);
  350. }
  351. // Let themes have preprocess functions even if they didn't register a template.
  352. if ($type == 'theme' || $type == 'base_theme') {
  353. foreach ($cache as $hook => $info) {
  354. // Check only if it's a template and not registered by the theme or engine.
  355. if (!empty($info['template']) && empty($result[$hook])) {
  356. if (!isset($info['preprocess functions'])) {
  357. $cache[$hook]['preprocess functions'] = array();
  358. }
  359. if (function_exists($name .'_preprocess')) {
  360. $cache[$hook]['preprocess functions'][] = $name .'_preprocess';
  361. }
  362. if (function_exists($name .'_preprocess_'. $hook)) {
  363. $cache[$hook]['preprocess functions'][] = $name .'_preprocess_'. $hook;
  364. }
  365. // Ensure uniqueness.
  366. $cache[$hook]['preprocess functions'] = array_unique($cache[$hook]['preprocess functions']);
  367. }
  368. }
  369. }
  370. }
  371. /**
  372. * Rebuild the hook theme_registry cache.
  373. *
  374. * @param $theme
  375. * The loaded $theme object.
  376. * @param $base_theme
  377. * An array of loaded $theme objects representing the ancestor themes in
  378. * oldest first order.
  379. * @param theme_engine
  380. * The name of the theme engine.
  381. */
  382. function _theme_build_registry($theme, $base_theme, $theme_engine) {
  383. $cache = array();
  384. // First, process the theme hooks advertised by modules. This will
  385. // serve as the basic registry.
  386. foreach (module_implements('theme') as $module) {
  387. _theme_process_registry($cache, $module, 'module', $module, drupal_get_path('module', $module));
  388. }
  389. // Process each base theme.
  390. foreach ($base_theme as $base) {
  391. // If the base theme uses a theme engine, process its hooks.
  392. $base_path = dirname($base->filename);
  393. if ($theme_engine) {
  394. _theme_process_registry($cache, $theme_engine, 'base_theme_engine', $base->name, $base_path);
  395. }
  396. _theme_process_registry($cache, $base->name, 'base_theme', $base->name, $base_path);
  397. }
  398. // And then the same thing, but for the theme.
  399. if ($theme_engine) {
  400. _theme_process_registry($cache, $theme_engine, 'theme_engine', $theme->name, dirname($theme->filename));
  401. }
  402. // Finally, hooks provided by the theme itself.
  403. _theme_process_registry($cache, $theme->name, 'theme', $theme->name, dirname($theme->filename));
  404. // Let modules alter the registry
  405. drupal_alter('theme_registry', $cache);
  406. return $cache;
  407. }
  408. /**
  409. * Provides a list of currently available themes.
  410. *
  411. * If the database is active then it will be retrieved from the database.
  412. * Otherwise it will retrieve a new list.
  413. *
  414. * @param $refresh
  415. * Whether to reload the list of themes from the database.
  416. * @return
  417. * An array of the currently available themes.
  418. */
  419. function list_themes($refresh = FALSE) {
  420. static $list = array();
  421. if ($refresh) {
  422. $list = array();
  423. }
  424. if (empty($list)) {
  425. $list = array();
  426. $themes = array();
  427. // Extract from the database only when it is available.
  428. // Also check that the site is not in the middle of an install or update.
  429. if (db_is_active() && !defined('MAINTENANCE_MODE')) {
  430. $result = db_query("SELECT * FROM {system} WHERE type = '%s'", 'theme');
  431. while ($theme = db_fetch_object($result)) {
  432. if (file_exists($theme->filename)) {
  433. $theme->info = unserialize($theme->info);
  434. $themes[] = $theme;
  435. }
  436. }
  437. }
  438. else {
  439. // Scan the installation when the database should not be read.
  440. $themes = _system_theme_data();
  441. }
  442. foreach ($themes as $theme) {
  443. foreach ($theme->info['stylesheets'] as $media => $stylesheets) {
  444. foreach ($stylesheets as $stylesheet => $path) {
  445. $theme->stylesheets[$media][$stylesheet] = $path;
  446. }
  447. }
  448. foreach ($theme->info['scripts'] as $script => $path) {
  449. if (file_exists($path)) {
  450. $theme->scripts[$script] = $path;
  451. }
  452. }
  453. if (isset($theme->info['engine'])) {
  454. $theme->engine = $theme->info['engine'];
  455. }
  456. if (isset($theme->info['base theme'])) {
  457. $theme->base_theme = $theme->info['base theme'];
  458. }
  459. // Status is normally retrieved from the database. Add zero values when
  460. // read from the installation directory to prevent notices.
  461. if (!isset($theme->status)) {
  462. $theme->status = 0;
  463. }
  464. $list[$theme->name] = $theme;
  465. }
  466. }
  467. return $list;
  468. }
  469. /**
  470. * Generates the themed output.
  471. *
  472. * All requests for theme hooks must go through this function. It examines
  473. * the request and routes it to the appropriate theme function. The theme
  474. * registry is checked to determine which implementation to use, which may
  475. * be a function or a template.
  476. *
  477. * If the implementation is a function, it is executed and its return value
  478. * passed along.
  479. *
  480. * If the implementation is a template, the arguments are converted to a
  481. * $variables array. This array is then modified by the module implementing
  482. * the hook, theme engine (if applicable) and the theme. The following
  483. * functions may be used to modify the $variables array. They are processed in
  484. * this order when available:
  485. *
  486. * - template_preprocess(&$variables, $hook)
  487. * This sets a default set of variables for all template implementations.
  488. *
  489. * - template_preprocess_HOOK(&$variables)
  490. * This is the first preprocessor called specific to the hook; it should be
  491. * implemented by the module that registers it.
  492. *
  493. * - MODULE_preprocess(&$variables, $hook)
  494. * This will be called for all templates; it should only be used if there
  495. * is a real need. It's purpose is similar to template_preprocess().
  496. *
  497. * - MODULE_preprocess_HOOK(&$variables)
  498. * This is for modules that want to alter or provide extra variables for
  499. * theming hooks not registered to itself. For example, if a module named
  500. * "foo" wanted to alter the $submitted variable for the hook "node" a
  501. * preprocess function of foo_preprocess_node() can be created to intercept
  502. * and alter the variable.
  503. *
  504. * - ENGINE_engine_preprocess(&$variables, $hook)
  505. * This function should only be implemented by theme engines and exists
  506. * so that it can set necessary variables for all hooks.
  507. *
  508. * - ENGINE_engine_preprocess_HOOK(&$variables)
  509. * This is the same as the previous function, but it is called for a single
  510. * theming hook.
  511. *
  512. * - ENGINE_preprocess(&$variables, $hook)
  513. * This is meant to be used by themes that utilize a theme engine. It is
  514. * provided so that the preprocessor is not locked into a specific theme.
  515. * This makes it easy to share and transport code but theme authors must be
  516. * careful to prevent fatal re-declaration errors when using sub-themes that
  517. * have their own preprocessor named exactly the same as its base theme. In
  518. * the default theme engine (PHPTemplate), sub-themes will load their own
  519. * template.php file in addition to the one used for its parent theme. This
  520. * increases the risk for these errors. A good practice is to use the engine
  521. * name for the base theme and the theme name for the sub-themes to minimize
  522. * this possibility.
  523. *
  524. * - ENGINE_preprocess_HOOK(&$variables)
  525. * The same applies from the previous function, but it is called for a
  526. * specific hook.
  527. *
  528. * - THEME_preprocess(&$variables, $hook)
  529. * These functions are based upon the raw theme; they should primarily be
  530. * used by themes that do not use an engine or by sub-themes. It serves the
  531. * same purpose as ENGINE_preprocess().
  532. *
  533. * - THEME_preprocess_HOOK(&$variables)
  534. * The same applies from the previous function, but it is called for a
  535. * specific hook.
  536. *
  537. * There are two special variables that these hooks can set:
  538. * 'template_file' and 'template_files'. These will be merged together
  539. * to form a list of 'suggested' alternate template files to use, in
  540. * reverse order of priority. template_file will always be a higher
  541. * priority than items in template_files. theme() will then look for these
  542. * files, one at a time, and use the first one
  543. * that exists.
  544. * @param $hook
  545. * The name of the theme function to call. May be an array, in which
  546. * case the first hook that actually has an implementation registered
  547. * will be used. This can be used to choose 'fallback' theme implementations,
  548. * so that if the specific theme hook isn't implemented anywhere, a more
  549. * generic one will be used. This can allow themes to create specific theme
  550. * implementations for named objects.
  551. * @param ...
  552. * Additional arguments to pass along to the theme function.
  553. *
  554. * @return
  555. * An HTML string that generates the themed output.
  556. */
  557. function theme() {
  558. $args = func_get_args();
  559. $hook = array_shift($args);
  560. static $hooks = NULL;
  561. if (!isset($hooks)) {
  562. init_theme();
  563. $hooks = theme_get_registry();
  564. }
  565. if (is_array($hook)) {
  566. foreach ($hook as $candidate) {
  567. if (isset($hooks[$candidate])) {
  568. break;
  569. }
  570. }
  571. $hook = $candidate;
  572. }
  573. if (!isset($hooks[$hook])) {
  574. return;
  575. }
  576. $info = $hooks[$hook];
  577. global $theme_path;
  578. $temp = $theme_path;
  579. // point path_to_theme() to the currently used theme path:
  580. $theme_path = $hooks[$hook]['theme path'];
  581. // Include a file if the theme function or preprocess function is held elsewhere.
  582. if (!empty($info['include files'])) {
  583. foreach ($info['include files'] as $include_file) {
  584. include_once($include_file);
  585. }
  586. }
  587. // Handle compatibility with theme_registry_alters to prevent failures.
  588. if (!empty($info['file'])) {
  589. static $included_files = array();
  590. $include_file = $info['file'];
  591. if (!empty($info['path'])) {
  592. $include_file = $info['path'] .'/'. $include_file;
  593. }
  594. if (empty($included_files[$include_file])) {
  595. // Statically cache files we've already tried to include so we don't
  596. // run unnecessary file_exists calls.
  597. $included_files[$include_file] = TRUE;
  598. if (file_exists('./'. $include_file)) {
  599. include_once('./'. $include_file);
  600. }
  601. }
  602. }
  603. if (isset($info['function'])) {
  604. // The theme call is a function.
  605. $output = call_user_func_array($info['function'], $args);
  606. }
  607. else {
  608. // The theme call is a template.
  609. $variables = array(
  610. 'template_files' => array()
  611. );
  612. if (!empty($info['arguments'])) {
  613. $count = 0;
  614. foreach ($info['arguments'] as $name => $default) {
  615. $variables[$name] = isset($args[$count]) ? $args[$count] : $default;
  616. $count++;
  617. }
  618. }
  619. // default render function and extension.
  620. $render_function = 'theme_render_template';
  621. $extension = '.tpl.php';
  622. // Run through the theme engine variables, if necessary
  623. global $theme_engine;
  624. if (isset($theme_engine)) {
  625. // If theme or theme engine is implementing this, it may have
  626. // a different extension and a different renderer.
  627. if ($hooks[$hook]['type'] != 'module') {
  628. if (function_exists($theme_engine .'_render_template')) {
  629. $render_function = $theme_engine .'_render_template';
  630. }
  631. $extension_function = $theme_engine .'_extension';
  632. if (function_exists($extension_function)) {
  633. $extension = $extension_function();
  634. }
  635. }
  636. }
  637. if (isset($info['preprocess functions']) && is_array($info['preprocess functions'])) {
  638. // This construct ensures that we can keep a reference through
  639. // call_user_func_array.
  640. $args = array(&$variables, $hook);
  641. foreach ($info['preprocess functions'] as $preprocess_function) {
  642. if (function_exists($preprocess_function)) {
  643. call_user_func_array($preprocess_function, $args);
  644. }
  645. }
  646. }
  647. // Get suggestions for alternate templates out of the variables
  648. // that were set. This lets us dynamically choose a template
  649. // from a list. The order is FILO, so this array is ordered from
  650. // least appropriate first to most appropriate last.
  651. $suggestions = array();
  652. if (isset($variables['template_files'])) {
  653. $suggestions = $variables['template_files'];
  654. }
  655. if (isset($variables['template_file'])) {
  656. $suggestions[] = $variables['template_file'];
  657. }
  658. if ($suggestions) {
  659. $template_file = drupal_discover_template($info['theme paths'], $suggestions, $extension);
  660. }
  661. if (empty($template_file)) {
  662. $template_file = $hooks[$hook]['template'] . $extension;
  663. if (isset($hooks[$hook]['path'])) {
  664. $template_file = $hooks[$hook]['path'] .'/'. $template_file;
  665. }
  666. }
  667. $output = $render_function($template_file, $variables);
  668. }
  669. // restore path_to_theme()
  670. $theme_path = $temp;
  671. // Add final markup to the full page.
  672. if ($hook == 'page' || $hook == 'book_export_html') {
  673. $output = drupal_final_markup($output);
  674. }
  675. return $output;
  676. }
  677. /**
  678. * Choose which template file to actually render. These are all suggested
  679. * templates from themes and modules. Theming implementations can occur on
  680. * multiple levels. All paths are checked to account for this.
  681. */
  682. function drupal_discover_template($paths, $suggestions, $extension = '.tpl.php') {
  683. global $theme_engine;
  684. // Remove slashes or null to prevent files from being included from
  685. // an unexpected location (especially on Windows servers).
  686. $extension = str_replace(array("/", "\\", "\0"), '', $extension);
  687. // Loop through all paths and suggestions in FIFO order.
  688. $suggestions = array_reverse($suggestions);
  689. $paths = array_reverse($paths);
  690. foreach ($suggestions as $suggestion) {
  691. if (!empty($suggestion)) {
  692. $suggestion = str_replace(array("/", "\\", "\0"), '', $suggestion);
  693. foreach ($paths as $path) {
  694. if (file_exists($file = $path .'/'. $suggestion . $extension)) {
  695. return $file;
  696. }
  697. }
  698. }
  699. }
  700. }
  701. /**
  702. * Return the path to the current themed element.
  703. *
  704. * It can point to the active theme or the module handling a themed implementation.
  705. * For example, when invoked within the scope of a theming call it will depend
  706. * on where the theming function is handled. If implemented from a module, it
  707. * will point to the module. If implemented from the active theme, it will point
  708. * to the active theme. When called outside the scope of a theming call, it will
  709. * always point to the active theme.
  710. */
  711. function path_to_theme() {
  712. global $theme_path;
  713. if (!isset($theme_path)) {
  714. init_theme();
  715. }
  716. return $theme_path;
  717. }
  718. /**
  719. * Find overridden theme functions. Called by themes and/or theme engines to
  720. * easily discover theme functions.
  721. *
  722. * @param $cache
  723. * The existing cache of theme hooks to test against.
  724. * @param $prefixes
  725. * An array of prefixes to test, in reverse order of importance.
  726. *
  727. * @return $templates
  728. * The functions found, suitable for returning from hook_theme;
  729. */
  730. function drupal_find_theme_functions($cache, $prefixes) {
  731. $templates = array();
  732. $functions = get_defined_functions();
  733. foreach ($cache as $hook => $info) {
  734. foreach ($prefixes as $prefix) {
  735. if (!empty($info['pattern'])) {
  736. $matches = preg_grep('/^'. $prefix .'_'. $info['pattern'] .'/', $functions['user']);
  737. if ($matches) {
  738. foreach ($matches as $match) {
  739. $new_hook = str_replace($prefix .'_', '', $match);
  740. $templates[$new_hook] = array(
  741. 'function' => $match,
  742. 'arguments' => $info['arguments'],
  743. 'original hook' => $hook,
  744. 'include files' => $info['include files'],
  745. );
  746. }
  747. }
  748. }
  749. if (function_exists($prefix .'_'. $hook)) {
  750. $templates[$hook] = array(
  751. 'function' => $prefix .'_'. $hook,
  752. 'include files' => $info['include files'],
  753. );
  754. // Ensure that the pattern is maintained from base themes to its sub-themes.
  755. // Each sub-theme will have their functions scanned so the pattern must be
  756. // held for subsequent runs.
  757. if (isset($info['pattern'])) {
  758. $templates[$hook]['pattern'] = $info['pattern'];
  759. }
  760. // Also ensure that the 'file' property is maintained, because it probably
  761. // contains the preprocess.
  762. }
  763. }
  764. }
  765. return $templates;
  766. }
  767. /**
  768. * Find overridden theme templates. Called by themes and/or theme engines to
  769. * easily discover templates.
  770. *
  771. * @param $cache
  772. * The existing cache of theme hooks to test against.
  773. * @param $extension
  774. * The extension that these templates will have.
  775. * @param $path
  776. * The path to search.
  777. */
  778. function drupal_find_theme_templates($cache, $extension, $path) {
  779. $templates = array();
  780. // Collect paths to all sub-themes grouped by base themes. These will be
  781. // used for filtering. This allows base themes to have sub-themes in its
  782. // folder hierarchy without affecting the base themes template discovery.
  783. $theme_paths = array();
  784. foreach (list_themes() as $theme_info) {
  785. if (!empty($theme_info->base_theme)) {
  786. $theme_paths[$theme_info->base_theme][$theme_info->name] = dirname($theme_info->filename);
  787. }
  788. }
  789. foreach ($theme_paths as $basetheme => $subthemes) {
  790. foreach ($subthemes as $subtheme => $subtheme_path) {
  791. if (isset($theme_paths[$subtheme])) {
  792. $theme_paths[$basetheme] = array_merge($theme_paths[$basetheme], $theme_paths[$subtheme]);
  793. }
  794. }
  795. }
  796. global $theme;
  797. $subtheme_paths = isset($theme_paths[$theme]) ? $theme_paths[$theme] : array();
  798. // Escape the periods in the extension.
  799. $regex = str_replace('.', '\.', $extension) .'$';
  800. // Because drupal_system_listing works the way it does, we check for real
  801. // templates separately from checking for patterns.
  802. $files = drupal_system_listing($regex, $path, 'name', 0);
  803. foreach ($files as $template => $file) {
  804. // Ignore sub-theme templates for the current theme.
  805. if (strpos($file->filename, str_replace($subtheme_paths, '', $file->filename)) !== 0) {
  806. continue;
  807. }
  808. // Chop off the remaining extensions if there are any. $template already
  809. // has the rightmost extension removed, but there might still be more,
  810. // such as with .tpl.php, which still has .tpl in $template at this point.
  811. if (($pos = strpos($template, '.')) !== FALSE) {
  812. $template = substr($template, 0, $pos);
  813. }
  814. // Transform - in filenames to _ to match function naming scheme
  815. // for the purposes of searching.
  816. $hook = strtr($template, '-', '_');
  817. if (isset($cache[$hook])) {
  818. $templates[$hook] = array(
  819. 'template' => $template,
  820. 'path' => dirname($file->filename),
  821. 'include files' => $cache[$hook]['include files'],
  822. );
  823. }
  824. // Ensure that the pattern is maintained from base themes to its sub-themes.
  825. // Each sub-theme will have their templates scanned so the pattern must be
  826. // held for subsequent runs.
  827. if (isset($cache[$hook]['pattern'])) {
  828. $templates[$hook]['pattern'] = $cache[$hook]['pattern'];
  829. }
  830. }
  831. $patterns = array_keys($files);
  832. foreach ($cache as $hook => $info) {
  833. if (!empty($info['pattern'])) {
  834. // Transform _ in pattern to - to match file naming scheme
  835. // for the purposes of searching.
  836. $pattern = strtr($info['pattern'], '_', '-');
  837. $matches = preg_grep('/^'. $pattern .'/', $patterns);
  838. if ($matches) {
  839. foreach ($matches as $match) {
  840. $file = substr($match, 0, strpos($match, '.'));
  841. // Put the underscores back in for the hook name and register this pattern.
  842. $templates[strtr($file, '-', '_')] = array(
  843. 'template' => $file,
  844. 'path' => dirname($files[$match]->filename),
  845. 'arguments' => $info['arguments'],
  846. 'original hook' => $hook,
  847. 'include files' => $info['include files'],
  848. );
  849. }
  850. }
  851. }
  852. }
  853. return $templates;
  854. }
  855. /**
  856. * Retrieve an associative array containing the settings for a theme.
  857. *
  858. * The final settings are arrived at by merging the default settings,
  859. * the site-wide settings, and the settings defined for the specific theme.
  860. * If no $key was specified, only the site-wide theme defaults are retrieved.
  861. *
  862. * The default values for each of settings are also defined in this function.
  863. * To add new settings, add their default values here, and then add form elements
  864. * to system_theme_settings() in system.module.
  865. *
  866. * @param $key
  867. * The template/style value for a given theme.
  868. *
  869. * @return
  870. * An associative array containing theme settings.
  871. */
  872. function theme_get_settings($key = NULL) {
  873. $defaults = array(
  874. 'mission' => '',
  875. 'default_logo' => 1,
  876. 'logo_path' => '',
  877. 'default_favicon' => 1,
  878. 'favicon_path' => '',
  879. 'primary_links' => 1,
  880. 'secondary_links' => 1,
  881. 'toggle_logo' => 1,
  882. 'toggle_favicon' => 1,
  883. 'toggle_name' => 1,
  884. 'toggle_search' => 1,
  885. 'toggle_slogan' => 0,
  886. 'toggle_mission' => 1,
  887. 'toggle_node_user_picture' => 0,
  888. 'toggle_comment_user_picture' => 0,
  889. 'toggle_primary_links' => 1,
  890. 'toggle_secondary_links' => 1,
  891. );
  892. if (module_exists('node')) {
  893. foreach (node_get_types() as $type => $name) {
  894. $defaults['toggle_node_info_'. $type] = 1;
  895. }
  896. }
  897. $settings = array_merge($defaults, variable_get('theme_settings', array()));
  898. if ($key) {
  899. $settings = array_merge($settings, variable_get(str_replace('/', '_', 'theme_'. $key .'_settings'), array()));
  900. }
  901. // Only offer search box if search.module is enabled.
  902. if (!module_exists('search') || !user_access('search content')) {
  903. $settings['toggle_search'] = 0;
  904. }
  905. return $settings;
  906. }
  907. /**
  908. * Retrieve a setting for the current theme.
  909. * This function is designed for use from within themes & engines
  910. * to determine theme settings made in the admin interface.
  911. *
  912. * Caches values for speed (use $refresh = TRUE to refresh cache)
  913. *
  914. * @param $setting_name
  915. * The name of the setting to be retrieved.
  916. *
  917. * @param $refresh
  918. * Whether to reload the cache of settings.
  919. *
  920. * @return
  921. * The value of the requested setting, NULL if the setting does not exist.
  922. */
  923. function theme_get_setting($setting_name, $refresh = FALSE) {
  924. global $theme_key;
  925. static $settings;
  926. if (empty($settings) || $refresh) {
  927. $settings = theme_get_settings($theme_key);
  928. $themes = list_themes();
  929. $theme_object = $themes[$theme_key];
  930. if ($settings['mission'] == '') {
  931. $settings['mission'] = variable_get('site_mission', '');
  932. }
  933. if (!$settings['toggle_mission']) {
  934. $settings['mission'] = '';
  935. }
  936. if ($settings['toggle_logo']) {
  937. if ($settings['default_logo']) {
  938. $settings['logo'] = base_path() . dirname($theme_object->filename) .'/logo.png';
  939. }
  940. elseif ($settings['logo_path']) {
  941. $settings['logo'] = base_path() . $settings['logo_path'];
  942. }
  943. }
  944. if ($settings['toggle_favicon']) {
  945. if ($settings['default_favicon']) {
  946. if (file_exists($favicon = dirname($theme_object->filename) .'/favicon.ico')) {
  947. $settings['favicon'] = base_path() . $favicon;
  948. }
  949. else {
  950. $settings['favicon'] = base_path() .'misc/favicon.ico';
  951. }
  952. }
  953. elseif ($settings['favicon_path']) {
  954. $settings['favicon'] = base_path() . $settings['favicon_path'];
  955. }
  956. else {
  957. $settings['toggle_favicon'] = FALSE;
  958. }
  959. }
  960. }
  961. return isset($settings[$setting_name]) ? $settings[$setting_name] : NULL;
  962. }
  963. /**
  964. * Render a system default template, which is essentially a PHP template.
  965. *
  966. * @param $template_file
  967. * The filename of the template to render. Note that this will overwrite
  968. * anything stored in $variables['template_file'] if using a preprocess hook.
  969. * @param $variables
  970. * A keyed array of variables that will appear in the output.
  971. *
  972. * @return
  973. * The output generated by the template.
  974. */
  975. function theme_render_template($template_file, $variables) {
  976. extract($variables, EXTR_SKIP); // Extract the variables to a local namespace
  977. ob_start(); // Start output buffering
  978. include "./$template_file"; // Include the template file
  979. $contents = ob_get_contents(); // Get the contents of the buffer
  980. ob_end_clean(); // End buffering and discard
  981. return $contents; // Return the contents
  982. }
  983. /**
  984. * @defgroup themeable Default theme implementations
  985. * @{
  986. * Functions and templates that present output to the user, and can be
  987. * implemented by themes.
  988. *
  989. * Drupal's presentation layer is a pluggable system known as the theme
  990. * layer. Each theme can take control over most of Drupal's output, and
  991. * has complete control over the CSS.
  992. *
  993. * Inside Drupal, the theme layer is utilized by the use of the theme()
  994. * function, which is passed the name of a component (the theme hook)
  995. * and several arguments. For example, theme('table', $header, $rows);
  996. * Additionally, the theme() function can take an array of theme
  997. * hooks, which can be used to provide 'fallback' implementations to
  998. * allow for more specific control of output. For example, the function:
  999. * theme(array('table__foo', 'table'), $header, $rows) would look to see if
  1000. * 'table__foo' is registered anywhere; if it is not, it would 'fall back'
  1001. * to the generic 'table' implementation. This can be used to attach specific
  1002. * theme functions to named objects, allowing the themer more control over
  1003. * specific types of output.
  1004. *
  1005. * As of Drupal 6, every theme hook is required to be registered by the
  1006. * module that owns it, so that Drupal can tell what to do with it and
  1007. * to make it simple for themes to identify and override the behavior
  1008. * for these calls.
  1009. *
  1010. * The theme hooks are registered via hook_theme(), which returns an
  1011. * array of arrays with information about the hook. It describes the
  1012. * arguments the function or template will need, and provides
  1013. * defaults for the template in case they are not filled in. If the default
  1014. * implementation is a function, by convention it is named theme_HOOK().
  1015. *
  1016. * Each module should provide a default implementation for theme_hooks that
  1017. * it registers. This implementation may be either a function or a template;
  1018. * if it is a function it must be specified via hook_theme(). By convention,
  1019. * default implementations of theme hooks are named theme_HOOK. Default
  1020. * template implementations are stored in the module directory.
  1021. *
  1022. * Drupal's default template renderer is a simple PHP parsing engine that
  1023. * includes the template and stores the output. Drupal's theme engines
  1024. * can provide alternate template engines, such as XTemplate, Smarty and
  1025. * PHPTal. The most common template engine is PHPTemplate (included with
  1026. * Drupal and implemented in phptemplate.engine, which uses Drupal's default
  1027. * template renderer.
  1028. *
  1029. * In order to create theme-specific implementations of these hooks,
  1030. * themes can implement their own version of theme hooks, either as functions
  1031. * or templates. These implementations will be used instead of the default
  1032. * implementation. If using a pure .theme without an engine, the .theme is
  1033. * required to implement its own version of hook_theme() to tell Drupal what
  1034. * it is implementing; themes utilizing an engine will have their well-named
  1035. * theming functions automatically registered for them. While this can vary
  1036. * based upon the theme engine, the standard set by phptemplate is that theme
  1037. * functions should be named either phptemplate_HOOK or THEMENAME_HOOK. For
  1038. * example, for Drupal's default theme (Garland) to implement the 'table' hook,
  1039. * the phptemplate.engine would find phptemplate_table() or garland_table().
  1040. * The ENGINE_HOOK() syntax is preferred, as this can be used by sub-themes
  1041. * (which are themes that share code but use different stylesheets).
  1042. *
  1043. * The theme system is described and defined in theme.inc.
  1044. *
  1045. * @see theme()
  1046. * @see hook_theme()
  1047. */
  1048. /**
  1049. * Formats text for emphasized display in a placeholder inside a sentence.
  1050. * Used automatically by t().
  1051. *
  1052. * @param $text
  1053. * The text to format (plain-text).
  1054. * @return
  1055. * The formatted text (html).
  1056. */
  1057. function theme_placeholder($text) {
  1058. return '<em>'. check_plain($text) .'</em>';
  1059. }
  1060. /**
  1061. * Return a themed set of status and/or error messages. The messages are grouped
  1062. * by type.
  1063. *
  1064. * @param $display
  1065. * (optional) Set to 'status' or 'error' to display only messages of that type.
  1066. *
  1067. * @return
  1068. * A string containing the messages.
  1069. */
  1070. function theme_status_messages($display = NULL) {
  1071. $output = '';
  1072. foreach (drupal_get_messages($display) as $type => $messages) {
  1073. $output .= "<div class=\"messages $type\">\n";
  1074. if (count($messages) > 1) {
  1075. $output .= " <ul>\n";
  1076. foreach ($messages as $message) {
  1077. $output .= ' <li>'. $message ."</li>\n";
  1078. }
  1079. $output .= " </ul>\n";
  1080. }
  1081. else {
  1082. $output .= $messages[0];
  1083. }
  1084. $output .= "</div>\n";
  1085. }
  1086. return $output;
  1087. }
  1088. /**
  1089. * Returns HTML for a set of links.
  1090. *
  1091. * @param $links
  1092. * An associative array of links to be themed. The key for each link
  1093. * is used as its CSS class. Each link should be itself an array, with the
  1094. * following elements:
  1095. * - title: The link text.
  1096. * - href: The link URL. If omitted, the 'title' is shown as a plain text
  1097. * item in the links list.
  1098. * - html: (optional) Whether or not 'title' is HTML. If set, the title
  1099. * will not be passed through check_plain().
  1100. * - attributes: (optional) Attributes for the anchor, or for the <span> tag
  1101. * used in its place if no 'href' is supplied.
  1102. * If the 'href' element is supplied, the entire link array is passed to l()
  1103. * as its $options parameter.
  1104. * @param $attributes
  1105. * An associative array of attributes for the UL containing the list of links.
  1106. *
  1107. * @return
  1108. * A string containing an unordered list of links.
  1109. */
  1110. function theme_links($links, $attributes = array('class' => 'links')) {
  1111. global $language;
  1112. $output = '';
  1113. if (count($links) > 0) {
  1114. $output = '<ul'. drupal_attributes($attributes) .'>';
  1115. $num_links = count($links);
  1116. $i = 1;
  1117. foreach ($links as $key => $link) {
  1118. $class = $key;
  1119. // Add first, last and active classes to the list of links to help out themers.
  1120. if ($i == 1) {
  1121. $class .= ' first';
  1122. }
  1123. if ($i == $num_links) {
  1124. $class .= ' last';
  1125. }
  1126. if (isset($link['href']) && ($link['href'] == $_GET['q'] || ($link['href'] == '<front>' && drupal_is_front_page()))
  1127. && (empty($link['language']) || $link['language']->language == $language->language)) {
  1128. $class .= ' active';
  1129. }
  1130. $output .= '<li'. drupal_attributes(array('class' => $class)) .'>';
  1131. if (isset($link['href'])) {
  1132. // Pass in $link as $options, they share the same keys.
  1133. $output .= l($link['title'], $link['href'], $link);
  1134. }
  1135. else if (!empty($link['title'])) {
  1136. // Some links are actually not links, but we wrap these in <span> for adding title and class attributes
  1137. if (empty($link['html'])) {
  1138. $link['title'] = check_plain($link['title']);
  1139. }
  1140. $span_attributes = '';
  1141. if (isset($link['attributes'])) {
  1142. $span_attributes = drupal_attributes($link['attributes']);
  1143. }
  1144. $output .= '<span'. $span_attributes .'>'. $link['title'] .'</span>';
  1145. }
  1146. $i++;
  1147. $output .= "</li>\n";
  1148. }
  1149. $output .= '</ul>';
  1150. }
  1151. return $output;
  1152. }
  1153. /**
  1154. * Return a themed image.
  1155. *
  1156. * @param $path
  1157. * Either the path of the image file (relative to base_path()) or a full URL.
  1158. * If this is a full URL, $getsize must be set to FALSE or nothing will be returned.
  1159. * @param $alt
  1160. * The alternative text for text-based browsers.
  1161. * @param $title
  1162. * The title text is displayed when the image is hovered in some popular browsers.
  1163. * @param $attributes
  1164. * Associative array of attributes to be placed in the img tag.
  1165. * @param $getsize
  1166. * If set to TRUE, the image's dimension are fetched and added as width/height attributes.
  1167. * Defaults to TRUE. Must be set to FALSE if $path is a full URL.
  1168. *
  1169. * @return
  1170. * A string containing the image tag.
  1171. */
  1172. function theme_image($path, $alt = '', $title = '', $attributes = NULL, $getsize = TRUE) {
  1173. if (!$getsize || (is_file($path) && (list($width, $height, $type, $image_attributes) = @getimagesize($path)))) {
  1174. $attributes = drupal_attributes($attributes);
  1175. $url = (url($path) == $path) ? $path : (base_path() . $path);
  1176. return '<img src="'. check_url($url) .'" alt="'. check_plain($alt) .'" title="'. check_plain($title) .'" '. (isset($image_attributes) ? $image_attributes : '') . $attributes .' />';
  1177. }
  1178. }
  1179. /**
  1180. * Return a themed breadcrumb trail.
  1181. *
  1182. * @param $breadcrumb
  1183. * An array containing the breadcrumb links.
  1184. * @return a string containing the breadcrumb output.
  1185. */
  1186. function theme_breadcrumb($breadcrumb) {
  1187. if (!empty($breadcrumb)) {
  1188. return '<div class="breadcrumb">'. implode(' » ', $breadcrumb) .'</div>';
  1189. }
  1190. }
  1191. /**
  1192. * Return a themed help message.
  1193. *
  1194. * @return a string containing the helptext for the current page.
  1195. */
  1196. function theme_help() {
  1197. if ($help = menu_get_active_help()) {
  1198. return '<div class="help">'. $help .'</div>';
  1199. }
  1200. }
  1201. /**
  1202. * Return a themed submenu, typically displayed under the tabs.
  1203. *
  1204. * @param $links
  1205. * An array of links.
  1206. */
  1207. function theme_submenu($links) {
  1208. return '<div class="submenu">'. implode(' | ', $links) .'</div>';
  1209. }
  1210. /**
  1211. * Return a themed table.
  1212. *
  1213. * @param $header
  1214. * An array containing the table headers. Each element of the array can be
  1215. * either a localized string or an associative array with the following keys:
  1216. * - "data": The localized title of the table column.
  1217. * - "field": The database field represented in the table column (required if
  1218. * user is to be able to sort on this column).
  1219. * - "sort": A default sort order for this column ("asc" or "desc").
  1220. * - Any HTML attributes, such as "colspan", to apply to the column header cell.
  1221. * @param $rows
  1222. * An array of table rows. Every row is an array of cells, or an associative
  1223. * array with the following keys:
  1224. * - "data": an array of cells
  1225. * - Any HTML attributes, such as "class", to apply to the table row.
  1226. *
  1227. * Each cell can be either a string or an associative array with the following keys:
  1228. * - "data": The string to display in the table cell.
  1229. * - "header": Indicates this cell is a header.
  1230. * - Any HTML attributes, such as "colspan", to apply to the table cell.
  1231. *
  1232. * Here's an example for $rows:
  1233. * @code
  1234. * $rows = array(
  1235. * // Simple row
  1236. * array(
  1237. * 'Cell 1', 'Cell 2', 'Cell 3'
  1238. * ),
  1239. * // Row with attributes on the row and some of its cells.
  1240. * array(
  1241. * 'data' => array('Cell 1', array('data' => 'Cell 2', 'colspan' => 2)), 'class' => 'funky'
  1242. * )
  1243. * );
  1244. * @endcode
  1245. *
  1246. * @param $attributes
  1247. * An array of HTML attributes to apply to the table tag.
  1248. * @param $caption
  1249. * A localized string to use for the <caption> tag.
  1250. * @return
  1251. * An HTML string representing the table.
  1252. */
  1253. function theme_table($header, $rows, $attributes = array(), $caption = NULL) {
  1254. // Add sticky headers, if applicable.
  1255. if (count($header)) {
  1256. drupal_add_js('misc/tableheader.js');
  1257. // Add 'sticky-enabled' class to the table to identify it for JS.
  1258. // This is needed to target tables constructed by this function.
  1259. $attributes['class'] = empty($attributes['class']) ? 'sticky-enabled' : ($attributes['class'] .' sticky-enabled');
  1260. }
  1261. $output = '<table'. drupal_attributes($attributes) .">\n";
  1262. if (isset($caption)) {
  1263. $output .= '<caption>'. $caption ."</caption>\n";
  1264. }
  1265. // Format the table header:
  1266. if (count($header)) {
  1267. $ts = tablesort_init($header);
  1268. // HTML requires that the thead tag has tr tags in it followed by tbody
  1269. // tags. Using ternary operator to check and see if we have any rows.
  1270. $output .= (count($rows) ? ' <thead><tr>' : ' <tr>');
  1271. foreach ($header as $cell) {
  1272. $cell = tablesort_header($cell, $header, $ts);
  1273. $output .= _theme_table_cell($cell, TRUE);
  1274. }
  1275. // Using ternary operator to close the tags based on whether or not there are rows
  1276. $output .= (count($rows) ? " </tr></thead>\n" : "</tr>\n");
  1277. }
  1278. else {
  1279. $ts = array();
  1280. }
  1281. // Format the table rows:
  1282. if (count($rows)) {
  1283. $output .= "<tbody>\n";
  1284. $flip = array('even' => 'odd', 'odd' => 'even');
  1285. $class = 'even';
  1286. foreach ($rows as $number => $row) {
  1287. $attributes = array();
  1288. // Check if we're dealing with a simple or complex row
  1289. if (isset($row['data'])) {
  1290. foreach ($row as $key => $value) {
  1291. if ($key == 'data') {
  1292. $cells = $value;
  1293. }
  1294. else {
  1295. $attributes[$key] = $value;
  1296. }
  1297. }
  1298. }
  1299. else {
  1300. $cells = $row;
  1301. }
  1302. if (count($cells)) {
  1303. // Add odd/even class
  1304. $class = $flip[$class];
  1305. if (isset($attributes['class'])) {
  1306. $attributes['class'] .= ' '. $class;
  1307. }
  1308. else {
  1309. $attributes['class'] = $class;
  1310. }
  1311. // Build row
  1312. $output .= ' <tr'. drupal_attributes($attributes) .'>';
  1313. $i = 0;
  1314. foreach ($cells as $cell) {
  1315. $cell = tablesort_cell($cell, $header, $ts, $i++);
  1316. $output .= _theme_table_cell($cell);
  1317. }
  1318. $output .= " </tr>\n";
  1319. }
  1320. }
  1321. $output .= "</tbody>\n";
  1322. }
  1323. $output .= "</table>\n";
  1324. return $output;
  1325. }
  1326. /**
  1327. * Returns a header cell for tables that have a select all functionality.
  1328. */
  1329. function theme_table_select_header_cell() {
  1330. drupal_add_js('misc/tableselect.js');
  1331. return array('class' => 'select-all');
  1332. }
  1333. /**
  1334. * Return a themed sort icon.
  1335. *
  1336. * @param $style
  1337. * Set to either asc or desc. This sets which icon to show.
  1338. * @return
  1339. * A themed sort icon.
  1340. */
  1341. function theme_tablesort_indicator($style) {
  1342. if ($style == "asc") {
  1343. return theme('image', 'misc/arrow-asc.png', t('sort icon'), t('sort ascending'));
  1344. }
  1345. else {
  1346. return theme('image', 'misc/arrow-desc.png', t('sort icon'), t('sort descending'));
  1347. }
  1348. }
  1349. /**
  1350. * Return a themed box.
  1351. *
  1352. * @param $title
  1353. * The subject of the box.
  1354. * @param $content
  1355. * The content of the box.
  1356. * @param $region
  1357. * The region in which the box is displayed.
  1358. * @return
  1359. * A string containing the box output.
  1360. */
  1361. function theme_box($title, $content, $region = 'main') {
  1362. $output = '<h2 class="title">'. $title .'</h2><div>'. $content .'</div>';
  1363. return $output;
  1364. }
  1365. /**
  1366. * Return a themed marker, useful for marking new or updated
  1367. * content.
  1368. *
  1369. * @param $type
  1370. * Number representing the marker type to display
  1371. * @see MARK_NEW, MARK_UPDATED, MARK_READ
  1372. * @return
  1373. * A string containing the marker.
  1374. */
  1375. function theme_mark($type = MARK_NEW) {
  1376. global $user;
  1377. if ($user->uid) {
  1378. if ($type == MARK_NEW) {
  1379. return ' <span class="marker">'. t('new') .'</span>';
  1380. }
  1381. else if ($type == MARK_UPDATED) {
  1382. return ' <span class="marker">'. t('updated') .'</span>';
  1383. }
  1384. }
  1385. }
  1386. /**
  1387. * Return a themed list of items.
  1388. *
  1389. * @param $items
  1390. * An array of items to be displayed in the list. If an item is a string,
  1391. * then it is used as is. If an item is an array, then the "data" element of
  1392. * the array is used as the contents of the list item. If an item is an array
  1393. * with a "children" element, those children are displayed in a nested list.
  1394. * All other elements are treated as attributes of the list item element.
  1395. * @param $title
  1396. * The title of the list.
  1397. * @param $type
  1398. * The type of list to return (e.g. "ul", "ol")
  1399. * @param $attributes
  1400. * The attributes applied to the list element.
  1401. * @return
  1402. * A string containing the list output.
  1403. */
  1404. function theme_item_list($items = array(), $title = NULL, $type = 'ul', $attributes = NULL) {
  1405. $output = '<div class="item-list">';
  1406. if (isset($title)) {
  1407. $output .= '<h3>'. $title .'</h3>';
  1408. }
  1409. if (!empty($items)) {
  1410. $output .= "<$type". drupal_attributes($attributes) .'>';
  1411. $num_items = count($items);
  1412. foreach ($items as $i => $item) {
  1413. $attributes = array();
  1414. $children = array();
  1415. if (is_array($item)) {
  1416. foreach ($item as $key => $value) {
  1417. if ($key == 'data') {
  1418. $data = $value;
  1419. }
  1420. elseif ($key == 'children') {
  1421. $children = $value;
  1422. }
  1423. else {
  1424. $attributes[$key] = $value;
  1425. }
  1426. }
  1427. }
  1428. else {
  1429. $data = $item;
  1430. }
  1431. if (count($children) > 0) {
  1432. $data .= theme_item_list($children, NULL, $type, $attributes); // Render nested list
  1433. }
  1434. if ($i == 0) {
  1435. $attributes['class'] = empty($attributes['class']) ? 'first' : ($attributes['class'] .' first');
  1436. }
  1437. if ($i == $num_items - 1) {
  1438. $attributes['class'] = empty($attributes['class']) ? 'last' : ($attributes['class'] .' last');
  1439. }
  1440. $output .= '<li'. drupal_attributes($attributes) .'>'. $data ."</li>\n";
  1441. }
  1442. $output .= "</$type>";
  1443. }
  1444. $output .= '</div>';
  1445. return $output;
  1446. }
  1447. /**
  1448. * Returns code that emits the 'more help'-link.
  1449. */
  1450. function theme_more_help_link($url) {
  1451. return '<div class="more-help-link">'. t('[<a href="@link">more help...</a>]', array('@link' => check_url($url))) .'</div>';
  1452. }
  1453. /**
  1454. * Return code that emits an XML icon.
  1455. *
  1456. * For most use cases, this function has been superseded by theme_feed_icon().
  1457. *
  1458. * @see theme_feed_icon()
  1459. * @param $url
  1460. * The URL of the feed.
  1461. */
  1462. function theme_xml_icon($url) {
  1463. if ($image = theme('image', 'misc/xml.png', t('XML feed'), t('XML feed'))) {
  1464. return '<a href="'. check_url($url) .'" class="xml-icon">'. $image .'</a>';
  1465. }
  1466. }
  1467. /**
  1468. * Return code that emits an feed icon.
  1469. *
  1470. * @param $url
  1471. * The URL of the feed.
  1472. * @param $title
  1473. * A descriptive title of the feed.
  1474. */
  1475. function theme_feed_icon($url, $title) {
  1476. if ($image = theme('image', 'misc/feed.png', t('Syndicate content'), $title)) {
  1477. return '<a href="'. check_url($url) .'" class="feed-icon">'. $image .'</a>';
  1478. }
  1479. }
  1480. /**
  1481. * Returns code that emits the 'more' link used on blocks.
  1482. *
  1483. * @param $url
  1484. * The URL of the main page
  1485. * @param $title
  1486. * A descriptive verb for the link, like 'Read more'
  1487. */
  1488. function theme_more_link($url, $title) {
  1489. return '<div class="more-link">'. t('<a href="@link" title="@title">more</a>', array('@link' => check_url($url), '@title' => $title)) .'</div>';
  1490. }
  1491. /**
  1492. * Execute hook_footer() which is run at the end of the page right before the
  1493. * close of the body tag.
  1494. *
  1495. * @param $main (optional)
  1496. * Whether the current page is the front page of the site.
  1497. * @return
  1498. * A string containing the results of the hook_footer() calls.
  1499. */
  1500. function theme_closure($main = 0) {
  1501. $footer = module_invoke_all('footer', $main);
  1502. return implode("\n", $footer) . drupal_get_js('footer');
  1503. }
  1504. /**
  1505. * Return a set of blocks available for the current user.
  1506. *
  1507. * @param $region
  1508. * Which set of blocks to retrieve.
  1509. * @return
  1510. * A string containing the themed blocks for this region.
  1511. */
  1512. function theme_blocks($region) {
  1513. $output = '';
  1514. if ($list = block_list($region)) {
  1515. foreach ($list as $key => $block) {
  1516. // $key == <i>module</i>_<i>delta</i>
  1517. $output .= theme('block', $block);
  1518. }
  1519. }
  1520. // Add any content assigned to this region through drupal_set_content() calls.
  1521. $output .= drupal_get_content($region);
  1522. return $output;
  1523. }
  1524. /**
  1525. * Format a username.
  1526. *
  1527. * @param $object
  1528. * The user object to format, usually returned from user_load().
  1529. * @return
  1530. * A string containing an HTML link to the user's page if the passed object
  1531. * suggests that this is a site user. Otherwise, only the username is returned.
  1532. */
  1533. function theme_username($object) {
  1534. if ($object->uid && $object->name) {
  1535. // Shorten the name when it is too long or it will break many tables.
  1536. if (drupal_strlen($object->name) > 20) {
  1537. $name = drupal_substr($object->name, 0, 15) .'...';
  1538. }
  1539. else {
  1540. $name = $object->name;
  1541. }
  1542. if (user_access('access user profiles')) {
  1543. $output = l($name, 'user/'. $object->uid, array('attributes' => array('title' => t('View user profile.'))));
  1544. }
  1545. else {
  1546. $output = check_plain($name);
  1547. }
  1548. }
  1549. else if ($object->name) {
  1550. // Sometimes modules display content composed by people who are
  1551. // not registered members of the site (e.g. mailing list or news
  1552. // aggregator modules). This clause enables modules to display
  1553. // the true author of the content.
  1554. if (!empty($object->homepage)) {
  1555. $output = l($object->name, $object->homepage, array('attributes' => array('rel' => 'nofollow')));
  1556. }
  1557. else {
  1558. $output = check_plain($object->name);
  1559. }
  1560. $output .= ' ('. t('not verified') .')';
  1561. }
  1562. else {
  1563. $output = check_plain(variable_get('anonymous', t('Anonymous')));
  1564. }
  1565. return $output;
  1566. }
  1567. /**
  1568. * Return a themed progress bar.
  1569. *
  1570. * @param $percent
  1571. * The percentage of the progress.
  1572. * @param $message
  1573. * A string containing information to be displayed.
  1574. * @return
  1575. * A themed HTML string representing the progress bar.
  1576. */
  1577. function theme_progress_bar($percent, $message) {
  1578. $output = '<div id="progress" class="progress">';
  1579. $output .= '<div class="bar"><div class="filled" style="width: '. $percent .'%"></div></div>';
  1580. $output .= '<div class="percentage">'. $percent .'%</div>';
  1581. $output .= '<div class="message">'. $message .'</div>';
  1582. $output .= '</div>';
  1583. return $output;
  1584. }
  1585. /**
  1586. * Create a standard indentation div. Used for drag and drop tables.
  1587. *
  1588. * @param $size
  1589. * Optional. The number of indentations to create.
  1590. * @return
  1591. * A string containing indentations.
  1592. */
  1593. function theme_indentation($size = 1) {
  1594. $output = '';
  1595. for ($n = 0; $n < $size; $n++) {
  1596. $output .= '<div class="indentation">&nbsp;</div>';
  1597. }
  1598. return $output;
  1599. }
  1600. /**
  1601. * @} End of "defgroup themeable".
  1602. */
  1603. function _theme_table_cell($cell, $header = FALSE) {
  1604. $attributes = '';
  1605. if (is_array($cell)) {
  1606. $data = isset($cell['data']) ? $cell['data'] : '';
  1607. $header |= isset($cell['header']);
  1608. unset($cell['data']);
  1609. unset($cell['header']);
  1610. $attributes = drupal_attributes($cell);
  1611. }
  1612. else {
  1613. $data = $cell;
  1614. }
  1615. if ($header) {
  1616. $output = "<th$attributes>$data</th>";
  1617. }
  1618. else {
  1619. $output = "<td$attributes>$data</td>";
  1620. }
  1621. return $output;
  1622. }
  1623. /**
  1624. * Adds a default set of helper variables for preprocess functions and
  1625. * templates. This comes in before any other preprocess function which makes
  1626. * it possible to be used in default theme implementations (non-overriden
  1627. * theme functions).
  1628. */
  1629. function template_preprocess(&$variables, $hook) {
  1630. global $user;
  1631. static $count = array();
  1632. // Track run count for each hook to provide zebra striping.
  1633. // See "template_preprocess_block()" which provides the same feature specific to blocks.
  1634. $count[$hook] = isset($count[$hook]) && is_int($count[$hook]) ? $count[$hook] : 1;
  1635. $variables['zebra'] = ($count[$hook] % 2) ? 'odd' : 'even';
  1636. $variables['id'] = $count[$hook]++;
  1637. // Tell all templates where they are located.
  1638. $variables['directory'] = path_to_theme();
  1639. // Set default variables that depend on the database.
  1640. $variables['is_admin'] = FALSE;
  1641. $variables['is_front'] = FALSE;
  1642. $variables['logged_in'] = FALSE;
  1643. if ($variables['db_is_active'] = db_is_active() && !defined('MAINTENANCE_MODE')) {
  1644. // Check for administrators.
  1645. if (user_access('access administration pages')) {
  1646. $variables['is_admin'] = TRUE;
  1647. }
  1648. // Flag front page status.
  1649. $variables['is_front'] = drupal_is_front_page();
  1650. // Tell all templates by which kind of user they're viewed.
  1651. $variables['logged_in'] = ($user->uid > 0);
  1652. // Provide user object to all templates
  1653. $variables['user'] = $user;
  1654. }
  1655. }
  1656. /**
  1657. * Process variables for page.tpl.php
  1658. *
  1659. * Most themes utilize their own copy of page.tpl.php. The default is located
  1660. * inside "modules/system/page.tpl.php". Look in there for the full list of
  1661. * variables.
  1662. *
  1663. * Uses the arg() function to generate a series of page template suggestions
  1664. * based on the current path.
  1665. *
  1666. * Any changes to variables in this preprocessor should also be changed inside
  1667. * template_preprocess_maintenance_page() to keep all them consistent.
  1668. *
  1669. * The $variables array contains the following arguments:
  1670. * - $content
  1671. * - $show_blocks
  1672. *
  1673. * @see page.tpl.php
  1674. */
  1675. function template_preprocess_page(&$variables) {
  1676. // Add favicon
  1677. if (theme_get_setting('toggle_favicon')) {
  1678. drupal_set_html_head('<link rel="shortcut icon" href="'. check_url(theme_get_setting('favicon')) .'" type="image/x-icon" />');
  1679. }
  1680. global $theme;
  1681. // Populate all block regions.
  1682. $regions = system_region_list($theme);
  1683. // Load all region content assigned via blocks.
  1684. foreach (array_keys($regions) as $region) {
  1685. // Prevent left and right regions from rendering blocks when 'show_blocks' == FALSE.
  1686. if (!(!$variables['show_blocks'] && ($region == 'left' || $region == 'right'))) {
  1687. $blocks = theme('blocks', $region);
  1688. }
  1689. else {
  1690. $blocks = '';
  1691. }
  1692. // Assign region to a region variable.
  1693. isset($variables[$region]) ? $variables[$region] .= $blocks : $variables[$region] = $blocks;
  1694. }
  1695. // Set up layout variable.
  1696. $variables['layout'] = 'none';
  1697. if (!empty($variables['left'])) {
  1698. $variables['layout'] = 'left';
  1699. }
  1700. if (!empty($variables['right'])) {
  1701. $variables['layout'] = ($variables['layout'] == 'left') ? 'both' : 'right';
  1702. }
  1703. // Set mission when viewing the frontpage.
  1704. if (drupal_is_front_page()) {
  1705. $mission = filter_xss_admin(theme_get_setting('mission'));
  1706. }
  1707. // Construct page title
  1708. if (drupal_get_title()) {
  1709. $head_title = array(strip_tags(drupal_get_title()), variable_get('site_name', 'Drupal'));
  1710. }
  1711. else {
  1712. $head_title = array(variable_get('site_name', 'Drupal'));
  1713. if (variable_get('site_slogan', '')) {
  1714. $head_title[] = variable_get('site_slogan', '');
  1715. }
  1716. }
  1717. $variables['head_title'] = implode(' | ', $head_title);
  1718. $variables['base_path'] = base_path();
  1719. $variables['front_page'] = url();
  1720. $variables['breadcrumb'] = theme('breadcrumb', drupal_get_breadcrumb());
  1721. $variables['feed_icons'] = drupal_get_feeds();
  1722. $variables['footer_message'] = filter_xss_admin(variable_get('site_footer', FALSE));
  1723. $variables['head'] = drupal_get_html_head();
  1724. $variables['help'] = theme('help');
  1725. $variables['language'] = $GLOBALS['language'];
  1726. $variables['language']->dir = $GLOBALS['language']->direction ? 'rtl' : 'ltr';
  1727. $variables['logo'] = theme_get_setting('logo');
  1728. $variables['messages'] = $variables['show_messages'] ? theme('status_messages') : '';
  1729. $variables['mission'] = isset($mission) ? $mission : '';
  1730. $variables['primary_links'] = theme_get_setting('toggle_primary_links') ? menu_primary_links() : array();
  1731. $variables['secondary_links'] = theme_get_setting('toggle_secondary_links') ? menu_secondary_links() : array();
  1732. $variables['search_box'] = (theme_get_setting('toggle_search') ? drupal_get_form('search_theme_form') : '');
  1733. $variables['site_name'] = (theme_get_setting('toggle_name') ? filter_xss_admin(variable_get('site_name', 'Drupal')) : '');
  1734. $variables['site_slogan'] = (theme_get_setting('toggle_slogan') ? filter_xss_admin(variable_get('site_slogan', '')) : '');
  1735. $variables['css'] = drupal_add_css();
  1736. $variables['styles'] = drupal_get_css();
  1737. $variables['scripts'] = drupal_get_js();
  1738. $variables['tabs'] = theme('menu_local_tasks');
  1739. $variables['title'] = drupal_get_title();
  1740. // Closure should be filled last.
  1741. $variables['closure'] = theme('closure');
  1742. if ($node = menu_get_object()) {
  1743. $variables['node'] = $node;
  1744. }
  1745. // Compile a list of classes that are going to be applied to the body element.
  1746. // This allows advanced theming based on context (home page, node of certain type, etc.).
  1747. $body_classes = array();
  1748. // Add a class that tells us whether we're on the front page or not.
  1749. $body_classes[] = $variables['is_front'] ? 'front' : 'not-front';
  1750. // Add a class that tells us whether the page is viewed by an authenticated user or not.
  1751. $body_classes[] = $variables['logged_in'] ? 'logged-in' : 'not-logged-in';
  1752. // Add arg(0) to make it possible to theme the page depending on the current page
  1753. // type (e.g. node, admin, user, etc.). To avoid illegal characters in the class,
  1754. // we're removing everything disallowed. We are not using 'a-z' as that might leave
  1755. // in certain international characters (e.g. German umlauts).
  1756. $body_classes[] = preg_replace('![^abcdefghijklmnopqrstuvwxyz0-9-_]+!s', '', 'page-'. form_clean_id(drupal_strtolower(arg(0))));
  1757. // If on an individual node page, add the node type.
  1758. if (isset($variables['node']) && $variables['node']->type) {
  1759. $body_classes[] = 'node-type-'. form_clean_id($variables['node']->type);
  1760. }
  1761. // Add information about the number of sidebars.
  1762. if ($variables['layout'] == 'both') {
  1763. $body_classes[] = 'two-sidebars';
  1764. }
  1765. elseif ($variables['layout'] == 'none') {
  1766. $body_classes[] = 'no-sidebars';
  1767. }
  1768. else {
  1769. $body_classes[] = 'one-sidebar sidebar-'. $variables['layout'];
  1770. }
  1771. // Implode with spaces.
  1772. $variables['body_classes'] = implode(' ', $body_classes);
  1773. // Build a list of suggested template files in order of specificity. One
  1774. // suggestion is made for every element of the current path, though
  1775. // numeric elements are not carried to subsequent suggestions. For example,
  1776. // http://www.example.com/node/1/edit would result in the following
  1777. // suggestions:
  1778. //
  1779. // page-node-edit.tpl.php
  1780. // page-node-1.tpl.php
  1781. // page-node.tpl.php
  1782. // page.tpl.php
  1783. $i = 0;
  1784. $suggestion = 'page';
  1785. $suggestions = array();
  1786. while ($arg = arg($i++)) {
  1787. $arg = str_replace(array("/", "\\", "\0"), '', $arg);
  1788. $suggestions[] = $suggestion .'-'. $arg;
  1789. if (!is_numeric($arg)) {
  1790. $suggestion .= '-'. $arg;
  1791. }
  1792. }
  1793. if (drupal_is_front_page()) {
  1794. $suggestions[] = 'page-front';
  1795. }
  1796. if ($suggestions) {
  1797. $variables['template_files'] = $suggestions;
  1798. }
  1799. }
  1800. /**
  1801. * Process variables for node.tpl.php
  1802. *
  1803. * Most themes utilize their own copy of node.tpl.php. The default is located
  1804. * inside "modules/node/node.tpl.php". Look in there for the full list of
  1805. * variables.
  1806. *
  1807. * The $variables array contains the following arguments:
  1808. * - $node
  1809. * - $teaser
  1810. * - $page
  1811. *
  1812. * @see node.tpl.php
  1813. */
  1814. function template_preprocess_node(&$variables) {
  1815. $node = $variables['node'];
  1816. if (module_exists('taxonomy')) {
  1817. $variables['taxonomy'] = taxonomy_link('taxonomy terms', $node);
  1818. }
  1819. else {
  1820. $variables['taxonomy'] = array();
  1821. }
  1822. if ($variables['teaser'] && $node->teaser) {
  1823. $variables['content'] = $node->teaser;
  1824. }
  1825. elseif (isset($node->body)) {
  1826. $variables['content'] = $node->body;
  1827. }
  1828. else {
  1829. $variables['content'] = '';
  1830. }
  1831. $variables['date'] = format_date($node->created);
  1832. $variables['links'] = !empty($node->links) ? theme('links', $node->links, array('class' => 'links inline')) : '';
  1833. $variables['name'] = theme('username', $node);
  1834. $variables['node_url'] = url('node/'. $node->nid);
  1835. $variables['terms'] = theme('links', $variables['taxonomy'], array('class' => 'links inline'));
  1836. $variables['title'] = check_plain($node->title);
  1837. // Flatten the node object's member fields.
  1838. $variables = array_merge((array)$node, $variables);
  1839. // Display info only on certain node types.
  1840. if (theme_get_setting('toggle_node_info_'. $node->type)) {
  1841. $variables['submitted'] = theme('node_submitted', $node);
  1842. $variables['picture'] = theme_get_setting('toggle_node_user_picture') ? theme('user_picture', $node) : '';
  1843. }
  1844. else {
  1845. $variables['submitted'] = '';
  1846. $variables['picture'] = '';
  1847. }
  1848. // Clean up name so there are no underscores.
  1849. $variables['template_files'][] = 'node-'. $node->type;
  1850. }
  1851. /**
  1852. * Process variables for block.tpl.php
  1853. *
  1854. * Prepare the values passed to the theme_block function to be passed
  1855. * into a pluggable template engine. Uses block properties to generate a
  1856. * series of template file suggestions. If none are found, the default
  1857. * block.tpl.php is used.
  1858. *
  1859. * Most themes utilize their own copy of block.tpl.php. The default is located
  1860. * inside "modules/system/block.tpl.php". Look in there for the full list of
  1861. * variables.
  1862. *
  1863. * The $variables array contains the following arguments:
  1864. * - $block
  1865. *
  1866. * @see block.tpl.php
  1867. */
  1868. function template_preprocess_block(&$variables) {
  1869. static $block_counter = array();
  1870. // All blocks get an independent counter for each region.
  1871. if (!isset($block_counter[$variables['block']->region])) {
  1872. $block_counter[$variables['block']->region] = 1;
  1873. }
  1874. // Same with zebra striping.
  1875. $variables['block_zebra'] = ($block_counter[$variables['block']->region] % 2) ? 'odd' : 'even';
  1876. $variables['block_id'] = $block_counter[$variables['block']->region]++;
  1877. $variables['template_files'][] = 'block-'. $variables['block']->region;
  1878. $variables['template_files'][] = 'block-'. $variables['block']->module;
  1879. $variables['template_files'][] = 'block-'. $variables['block']->module .'-'. $variables['block']->delta;
  1880. }

Related topics

Functions

Namesort descending Description
drupal_discover_template Choose which template file to actually render. These are all suggested templates from themes and modules. Theming implementations can occur on multiple levels. All paths are checked to account for this.
drupal_find_theme_functions Find overridden theme functions. Called by themes and/or theme engines to easily discover theme functions.
drupal_find_theme_templates Find overridden theme templates. Called by themes and/or theme engines to easily discover templates.
drupal_rebuild_theme_registry Force the system to rebuild the theme registry; this should be called when modules are added to the system, or when a dynamic system needs to add more theme hooks.
init_theme Initialize the theme system by loading the theme.
list_themes Provides a list of currently available themes.
path_to_theme Return the path to the current themed element.
template_preprocess Adds a default set of helper variables for preprocess functions and templates. This comes in before any other preprocess function which makes it possible to be used in default theme implementations (non-overriden theme functions).
template_preprocess_block Process variables for block.tpl.php
template_preprocess_node Process variables for node.tpl.php
template_preprocess_page Process variables for page.tpl.php
theme Generates the themed output.
theme_blocks Return a set of blocks available for the current user.
theme_box Return a themed box.
theme_breadcrumb Return a themed breadcrumb trail.
theme_closure Execute hook_footer() which is run at the end of the page right before the close of the body tag.
theme_feed_icon Return code that emits an feed icon.
theme_get_registry Retrieve the stored theme registry. If the theme registry is already in memory it will be returned; otherwise it will attempt to load the registry from cache. If this fails, it will construct the registry and cache it.
theme_get_setting Retrieve a setting for the current theme. This function is designed for use from within themes & engines to determine theme settings made in the admin interface.
theme_get_settings Retrieve an associative array containing the settings for a theme.
theme_help Return a themed help message.
theme_image Return a themed image.
theme_indentation Create a standard indentation div. Used for drag and drop tables.
theme_item_list Return a themed list of items.
theme_links Returns HTML for a set of links.
theme_mark Return a themed marker, useful for marking new or updated content.
theme_more_help_link Returns code that emits the 'more help'-link.
theme_more_link Returns code that emits the 'more' link used on blocks.
theme_placeholder Formats text for emphasized display in a placeholder inside a sentence. Used automatically by t().
theme_progress_bar Return a themed progress bar.
theme_render_template Render a system default template, which is essentially a PHP template.
theme_status_messages Return a themed set of status and/or error messages. The messages are grouped by type.
theme_submenu Return a themed submenu, typically displayed under the tabs.
theme_table Return a themed table.
theme_tablesort_indicator Return a themed sort icon.
theme_table_select_header_cell Returns a header cell for tables that have a select all functionality.
theme_username Format a username.
theme_xml_icon Return code that emits an XML icon.
_init_theme Initialize the theme system given already loaded information. This function is useful to initialize a theme when no database is present.
_theme_build_registry Rebuild the hook theme_registry cache.
_theme_load_registry Get the theme_registry cache from the database; if it doesn't exist, build it.
_theme_process_registry Process a single invocation of the theme hook. $type will be one of 'module', 'theme_engine', 'base_theme_engine', 'theme', or 'base_theme' and it tells us some important information.
_theme_save_registry Write the theme_registry cache into the database.
_theme_set_registry Store the theme registry in memory.
_theme_table_cell

Constants

Namesort descending Description
MARK_NEW Mark content as being new.
MARK_READ Mark content as read.
MARK_UPDATED Mark content as being updated.