summaryrefslogtreecommitdiff
path: root/themes/engines/phptemplate/phptemplate.engine
blob: 007c7a73504bef9c8b4ca32ce15d69925f0229a1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
<?php
// $Id$

/**
 * @file
 * Handles integration of templates written in pure php with the Drupal theme system.
 */

function phptemplate_init($template) {
  $file = dirname($template->filename) . '/template.php';
  if (file_exists($file)) {
    include_once "./$file";
  }
}

/**
 * Implementation of hook_theme to tell Drupal what templates the engine
 * and the current theme use. The $existing argument will contain hooks
 * pre-defined by Drupal so that we can use that information if
 * we need to.
 */
function phptemplate_theme($existing, $type, $theme, $path) {
  $templates = drupal_find_theme_functions($existing, array('phptemplate', $theme));
  $templates += drupal_find_theme_templates($existing, '.tpl.php', $path);
  return $templates;
}

/**
 * Adds additional helper variables to all templates.
 *
 * Counts how many times certain hooks have been called. Sidebar left / right are special cases.
 *
 * @param $variables
 *   A series of key-value value pairs.
 * @param $hook
 *   The name of the theme function being executed.
 */
function phptemplate_engine_preprocess(&$variables, $hook) {
  global $user;
  static $count = array();

  // Create variables so anything which is themed can be zebra striped automatically.
  $count[$hook] = isset($count[$hook]) && is_int($count[$hook]) ? $count[$hook] : 1;
  $variables['zebra'] = ($count[$hook] % 2) ? 'odd' : 'even';
  $variables['id'] = $count[$hook]++;

  // Tell all templates where they are located.
  $variables['directory'] = path_to_theme();
  $variables['is_front'] = drupal_is_front_page();
  // Tell all templates by which kind of user they're viewed.
  $variables['logged_in'] = ($user->uid > 0);
  $variables['is_admin'] = user_access('access administration pages');
}