PageRenderTime 33ms CodeModel.GetById 33ms RepoModel.GetById 0ms app.codeStats 1ms

/includes/theme.inc

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