1
0

IEMailTemplate.php 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  1. <?php
  2. /**
  3. * @copyright 2017, Morris Jobke <hey@morrisjobke.de>
  4. *
  5. * @author Joas Schilling <coding@schilljs.com>
  6. * @author Leon Klingele <leon@struktur.de>
  7. * @author Lukas Reschke <lukas@statuscode.ch>
  8. * @author Morris Jobke <hey@morrisjobke.de>
  9. *
  10. * @license GNU AGPL version 3 or any later version
  11. *
  12. * This program is free software: you can redistribute it and/or modify
  13. * it under the terms of the GNU Affero General Public License as
  14. * published by the Free Software Foundation, either version 3 of the
  15. * License, or (at your option) any later version.
  16. *
  17. * This program is distributed in the hope that it will be useful,
  18. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  19. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  20. * GNU Affero General Public License for more details.
  21. *
  22. * You should have received a copy of the GNU Affero General Public License
  23. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  24. *
  25. */
  26. namespace OCP\Mail;
  27. /**
  28. * Interface IEMailTemplate
  29. *
  30. * Interface to a class that allows to build HTML emails
  31. *
  32. * Example:
  33. *
  34. * <?php
  35. *
  36. * $emailTemplate = new EMailTemplate($this->defaults, $this->urlGenerator, $this->l10n);
  37. *
  38. * $emailTemplate->addHeader();
  39. * $emailTemplate->addHeading('Welcome aboard');
  40. * $emailTemplate->addBodyText('Welcome to your Nextcloud account, you can add, protect, and share your data.');
  41. *
  42. * $emailTemplate->addBodyButtonGroup(
  43. * 'Set your password', 'https://example.org/resetPassword/q1234567890qwertz',
  44. * 'Install Client', 'https://nextcloud.com/install/#install-clients'
  45. * );
  46. *
  47. * $emailTemplate->addFooter('Optional footer text');
  48. *
  49. * $htmlContent = $emailTemplate->renderHtml();
  50. * $plainContent = $emailTemplate->renderText();
  51. *
  52. * @since 12.0.0
  53. */
  54. interface IEMailTemplate {
  55. /**
  56. * Sets the subject of the email
  57. *
  58. * @param string $subject
  59. *
  60. * @since 13.0.0
  61. */
  62. public function setSubject($subject);
  63. /**
  64. * Adds a header to the email
  65. *
  66. * @since 12.0.0
  67. */
  68. public function addHeader();
  69. /**
  70. * Adds a heading to the email
  71. *
  72. * @param string $title
  73. * @param string|bool $plainTitle Title that is used in the plain text email
  74. * if empty the $title is used, if false none will be used
  75. *
  76. * @since 12.0.0
  77. */
  78. public function addHeading($title, $plainTitle = '');
  79. /**
  80. * Adds a paragraph to the body of the email
  81. *
  82. * @param string $text
  83. * @param string|bool $plainText Text that is used in the plain text email
  84. * if empty the $text is used, if false none will be used
  85. *
  86. * @since 12.0.0
  87. */
  88. public function addBodyText($text, $plainText = '');
  89. /**
  90. * Adds a list item to the body of the email
  91. *
  92. * @param string $text
  93. * @param string $metaInfo
  94. * @param string $icon Absolute path, must be 16*16 pixels
  95. * @param string $plainText Text that is used in the plain text email
  96. * if empty the $text is used, if false none will be used
  97. * @param string $plainMetaInfo Meta info that is used in the plain text email
  98. * if empty the $metaInfo is used, if false none will be used
  99. * @since 12.0.0
  100. */
  101. public function addBodyListItem($text, $metaInfo = '', $icon = '', $plainText = '', $plainMetaInfo = '');
  102. /**
  103. * Adds a button group of two buttons to the body of the email
  104. *
  105. * @param string $textLeft Text of left button
  106. * @param string $urlLeft URL of left button
  107. * @param string $textRight Text of right button
  108. * @param string $urlRight URL of right button
  109. * @param string $plainTextLeft Text of left button that is used in the plain text version - if empty the $textLeft is used
  110. * @param string $plainTextRight Text of right button that is used in the plain text version - if empty the $textRight is used
  111. *
  112. * @since 12.0.0
  113. */
  114. public function addBodyButtonGroup($textLeft, $urlLeft, $textRight, $urlRight, $plainTextLeft = '', $plainTextRight = '');
  115. /**
  116. * Adds a button to the body of the email
  117. *
  118. * @param string $text Text of button
  119. * @param string $url URL of button
  120. * @param string $plainText Text of button in plain text version
  121. * if empty the $text is used, if false none will be used
  122. *
  123. * @since 12.0.0
  124. */
  125. public function addBodyButton($text, $url, $plainText = '');
  126. /**
  127. * Adds a logo and a text to the footer. <br> in the text will be replaced by new lines in the plain text email
  128. *
  129. * @param string $text If the text is empty the default "Name - Slogan<br>This is an automatically sent email" will be used
  130. *
  131. * @since 12.0.0
  132. */
  133. public function addFooter($text = '');
  134. /**
  135. * Returns the rendered email subject as string
  136. *
  137. * @return string
  138. *
  139. * @since 13.0.0
  140. */
  141. public function renderSubject();
  142. /**
  143. * Returns the rendered HTML email as string
  144. *
  145. * @return string
  146. *
  147. * @since 12.0.0
  148. */
  149. public function renderHtml();
  150. /**
  151. * Returns the rendered plain text email as string
  152. *
  153. * @return string
  154. *
  155. * @since 12.0.0
  156. */
  157. public function renderText();
  158. }