mimemail.theme.inc 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. <?php
  2. /**
  3. * @file
  4. * The theme system, which controls the output of the messages.
  5. */
  6. function mimemail_theme_theme() {
  7. $path = drupal_get_path('module', 'mimemail') . '/theme';
  8. return array(
  9. 'mimemail_message' => array(
  10. 'variables' => array('module' => NULL, 'key' => NULL, 'recipient' => NULL, 'subject' => NULL, 'body' => NULL, 'message' => array()),
  11. 'template' => 'mimemail-message',
  12. 'pattern' => 'mimemail_message__',
  13. 'file' => 'mimemail.theme.inc',
  14. 'mail theme' => TRUE,
  15. 'path' => $path,
  16. )
  17. );
  18. }
  19. /**
  20. * A preprocess function for theme('mimemail_message').
  21. *
  22. * The $variables array initially contains the following arguments:
  23. * - $recipient: The recipient of the message
  24. * - $key: The mailkey associated with the message
  25. * - $subject: The message subject
  26. * - $body: The message body
  27. *
  28. * @see mimemail-message.tpl.php
  29. */
  30. function template_preprocess_mimemail_message(&$variables) {
  31. $theme = mailsystem_get_mail_theme();
  32. $themepath = drupal_get_path('theme', $theme);
  33. $sitestyle = variable_get('mimemail_sitestyle', 1);
  34. $mailstyles = file_scan_directory($themepath, '#^mail(-.+)?\.(c|le|sc|sa)ss$#');
  35. // Check recursively for the existence of a mail.css file in the theme folder.
  36. if (!empty($mailstyles)) {
  37. foreach ($mailstyles as $mailstyle) {
  38. $styles = $mailstyle->uri;
  39. }
  40. }
  41. // If no mail.css was found and the site style sheets including is enabled,
  42. // gather all style sheets and embed a version of all style definitions.
  43. elseif ($sitestyle) {
  44. // Grab local.css if it exists (support for Fusion based themes).
  45. $local = $themepath . '/css/local.css';
  46. if (@file_exists($local)) {
  47. $css_all = drupal_add_css($local, array('group' => CSS_THEME));
  48. }
  49. else {
  50. $css_all = drupal_add_css();
  51. }
  52. $css_files = array();
  53. foreach ($css_all as $key => $options) {
  54. if ($options['group'] == CSS_THEME && $options['type'] == 'file' &&
  55. ($options['media'] == 'all' || $options['media'] == 'screen')) {
  56. $css_files[$key] = $options;
  57. }
  58. }
  59. if (variable_get('preprocess_css', FALSE)) {
  60. $pattern = '|<link.*href="' . $GLOBALS['base_url'] . '/([^"?]*)[?"].*|';
  61. $replacement = '\1';
  62. }
  63. else {
  64. $pattern = array(
  65. '/<([^<>]*)>/', // Remove the style tag.
  66. '/@import\s+url\("([^"]+)"\);+/', // Remove the import directive.
  67. '|' . $GLOBALS['base_url'] . '/([^"?]*)[?"].*|' // Remove the base URL.
  68. );
  69. $replacement = array('', '\1', '\1');
  70. }
  71. $styles = preg_replace($pattern, $replacement, drupal_get_css($css_files));
  72. }
  73. $css = '';
  74. if (isset($styles)) {
  75. // Process each style sheet.
  76. foreach (explode("\n", $styles) as $style) {
  77. if (!empty($style)) {
  78. $css .= drupal_load_stylesheet($style, TRUE);
  79. }
  80. }
  81. // Wordwrap to adhere to RFC821
  82. $css = wordwrap($css, 700);
  83. }
  84. // Set styles for the message.
  85. $variables['css'] = $css;
  86. // Set template alternatives.
  87. $variables['theme_hook_suggestions'][] = 'mimemail_message__' . str_replace('-', '_', $variables['key']);
  88. // Process identifiers to be proper CSS classes.
  89. $variables['module'] = str_replace('_', '-', $variables['module']);
  90. $variables['key'] = str_replace('_', '-', $variables['key']);
  91. }