/**
 * Intercept template variables.
 *
 * This mimics how themes work in Drupal 6. Instead of using switch cases,
 * separated functions are called to alter the variables per hook. This is
 * easier to maintain. Each preprocess function passes $vars by reference.
 *
 * This function should not be modified directly.
 */
function _phptemplate_variables($hook, $vars = array()) {  
  global $theme, $theme_engine;
  $preprocess_functions = array(
    $theme_engine .'_preprocess',
    $theme_engine .'_preprocess_'. $hook,
    $theme .'_preprocess',
    $theme .'_preprocess_'. $hook,
  );
  // This construct ensures that we can keep a reference through
  // call_user_func_array.
  $args = array(&$vars, $hook);
  foreach ($preprocess_functions as $preprocess_function) {
    if (function_exists($preprocess_function)) {
      call_user_func_array($preprocess_function, $args);
    }
  }
  return $vars;
}