1
0

IEMailTemplate.php 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. <?php
  2. declare(strict_types=1);
  3. /**
  4. * SPDX-FileCopyrightText: 2017 Nextcloud GmbH and Nextcloud contributors
  5. * SPDX-License-Identifier: AGPL-3.0-or-later
  6. */
  7. namespace OCP\Mail;
  8. /**
  9. * Interface IEMailTemplate
  10. *
  11. * Interface to a class that allows to build HTML emails
  12. *
  13. * Example:
  14. *
  15. * <?php
  16. *
  17. * $emailTemplate = new EMailTemplate($this->defaults, $this->urlGenerator, $this->l10n);
  18. *
  19. * $emailTemplate->addHeader();
  20. * $emailTemplate->addHeading('Welcome aboard');
  21. * $emailTemplate->addBodyText('Welcome to your Nextcloud account, you can add, protect, and share your data.');
  22. *
  23. * $emailTemplate->addBodyButtonGroup(
  24. * 'Set your password', 'https://example.org/resetPassword/q1234567890qwertz',
  25. * 'Install Client', 'https://nextcloud.com/install/#install-clients'
  26. * );
  27. *
  28. * $emailTemplate->addFooter('Optional footer text');
  29. *
  30. * $htmlContent = $emailTemplate->renderHtml();
  31. * $plainContent = $emailTemplate->renderText();
  32. *
  33. * @since 12.0.0
  34. */
  35. interface IEMailTemplate {
  36. /**
  37. * Sets the subject of the email
  38. *
  39. * @param string $subject
  40. *
  41. * @since 13.0.0
  42. */
  43. public function setSubject(string $subject);
  44. /**
  45. * Adds a header to the email
  46. *
  47. * @since 12.0.0
  48. */
  49. public function addHeader();
  50. /**
  51. * Adds a heading to the email
  52. *
  53. * @param string $title
  54. * @param string|bool $plainTitle Title that is used in the plain text email
  55. * if empty the $title is used, if false none will be used
  56. *
  57. * @since 12.0.0
  58. */
  59. public function addHeading(string $title, $plainTitle = '');
  60. /**
  61. * Adds a paragraph to the body of the email
  62. *
  63. * @param string $text; Note: When $plainText falls back to this, HTML is automatically escaped in the HTML email
  64. * @param string|bool $plainText Text that is used in the plain text email
  65. * if empty the $text is used, if false none will be used
  66. *
  67. * @since 12.0.0
  68. */
  69. public function addBodyText(string $text, $plainText = '');
  70. /**
  71. * Adds a list item to the body of the email
  72. *
  73. * @param string $text; Note: When $plainText falls back to this, HTML is automatically escaped in the HTML email
  74. * @param string $metaInfo; Note: When $plainMetaInfo falls back to this, HTML is automatically escaped in the HTML email
  75. * @param string $icon Absolute path, must be 16*16 pixels
  76. * @param string|bool $plainText Text that is used in the plain text email
  77. * if empty the $text is used, if false none will be used
  78. * @param string|bool $plainMetaInfo Meta info that is used in the plain text email
  79. * if empty the $metaInfo is used, if false none will be used
  80. * @param integer plainIndent If > 0, Indent plainText by this amount.
  81. * @since 12.0.0
  82. */
  83. public function addBodyListItem(string $text, string $metaInfo = '', string $icon = '', $plainText = '', $plainMetaInfo = '', $plainIndent = 0);
  84. /**
  85. * Adds a button group of two buttons to the body of the email
  86. *
  87. * @param string $textLeft Text of left button; Note: When $plainTextLeft falls back to this, HTML is automatically escaped in the HTML email
  88. * @param string $urlLeft URL of left button
  89. * @param string $textRight Text of right button; Note: When $plainTextRight falls back to this, HTML is automatically escaped in the HTML email
  90. * @param string $urlRight URL of right button
  91. * @param string $plainTextLeft Text of left button that is used in the plain text version - if empty the $textLeft is used
  92. * @param string $plainTextRight Text of right button that is used in the plain text version - if empty the $textRight is used
  93. *
  94. * @since 12.0.0
  95. */
  96. public function addBodyButtonGroup(string $textLeft, string $urlLeft, string $textRight, string $urlRight, string $plainTextLeft = '', string $plainTextRight = '');
  97. /**
  98. * Adds a button to the body of the email
  99. *
  100. * @param string $text Text of button; Note: When $plainText falls back to this, HTML is automatically escaped in the HTML email
  101. * @param string $url URL of button
  102. * @param string|false $plainText Text of button in plain text version
  103. * if empty the $text is used, if false none will be used
  104. *
  105. * @since 12.0.0
  106. */
  107. public function addBodyButton(string $text, string $url, $plainText = '');
  108. /**
  109. * Adds a logo and a text to the footer. <br> in the text will be replaced by new lines in the plain text email
  110. *
  111. * @param string $text If the text is empty the default "Name - Slogan<br>This is an automatically sent email" will be used
  112. * @param string $lang Optional language to set the default footer in
  113. *
  114. * @since 12.0.0
  115. */
  116. public function addFooter(string $text = '', ?string $lang = null);
  117. /**
  118. * Returns the rendered email subject as string
  119. *
  120. * @return string
  121. *
  122. * @since 13.0.0
  123. */
  124. public function renderSubject(): string;
  125. /**
  126. * Returns the rendered HTML email as string
  127. *
  128. * @return string
  129. *
  130. * @since 12.0.0
  131. */
  132. public function renderHtml(): string;
  133. /**
  134. * Returns the rendered plain text email as string
  135. *
  136. * @return string
  137. *
  138. * @since 12.0.0
  139. */
  140. public function renderText(): string;
  141. }