nyan_cat.engine 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. <?php
  2. /**
  3. * @file
  4. * Handles integration of Nyan cat templates because we love kittens.
  5. */
  6. /**
  7. * Includes .theme file from themes.
  8. */
  9. function nyan_cat_init($template) {
  10. $file = dirname($template->filename) . '/template.theme';
  11. if (file_exists($file)) {
  12. include_once DRUPAL_ROOT . '/' . $file;
  13. }
  14. }
  15. /**
  16. * Implements hook_theme().
  17. */
  18. function nyan_cat_theme($existing, $type, $theme, $path) {
  19. $templates = drupal_find_theme_functions($existing, array($theme));
  20. $templates += drupal_find_theme_templates($existing, '.nyan-cat.html', $path);
  21. return $templates;
  22. }
  23. /**
  24. * Implements hook_extension().
  25. */
  26. function nyan_cat_extension() {
  27. return '.nyan-cat.html';
  28. }
  29. /**
  30. * Implements hook_render_template().
  31. *
  32. * @param string $template_file
  33. * The filename of the template to render.
  34. * @param mixed[] $variables
  35. * A keyed array of variables that will appear in the output.
  36. *
  37. * @return string
  38. * The output generated by the template.
  39. */
  40. function nyan_cat_render_template($template_file, $variables) {
  41. $output = str_replace('div', 'nyancat', file_get_contents(DRUPAL_ROOT . '/' . $template_file));
  42. foreach ($variables as $key => $variable) {
  43. if (strpos($output, '9' . $key) !== FALSE) {
  44. $output = str_replace('9' . $key, $variable, $output);
  45. }
  46. }
  47. return $output;
  48. }