PageRenderTime 50ms CodeModel.GetById 21ms RepoModel.GetById 1ms app.codeStats 0ms

/titania/includes/tools/email.php

http://github.com/phpbb/customisation-db
PHP | 155 lines | 107 code | 32 blank | 16 comment | 15 complexity | 9a47cc4a2e433a2614af58de2e45859a MD5 | raw file
Possible License(s): AGPL-1.0
  1. <?php
  2. /**
  3. *
  4. * @package Titania
  5. * @copyright (c) 2008 phpBB Customisation Database Team
  6. * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License, version 2
  7. *
  8. */
  9. /**
  10. * @ignore
  11. */
  12. if (!defined('IN_TITANIA'))
  13. {
  14. exit;
  15. }
  16. class titania_email
  17. {
  18. /**
  19. * Ignore this for now!
  20. * Moving it to the side for later...
  21. */
  22. public function email_friend()
  23. {
  24. phpbb::$user->add_lang('memberlist');
  25. if (!phpbb::$config['email_enable'])
  26. {
  27. titania::error_box('ERROR', 'EMAIL_DISABLED', TITANIA_ERROR, HEADER_SERVICE_UNAVAILABLE);
  28. return false;
  29. }
  30. if (!phpbb::$user->data['is_registered'] || phpbb::$user->data['is_bot'] || !phpbb::$auth->acl_get('u_sendemail'))
  31. {
  32. if (phpbb::$user->data['user_id'] == ANONYMOUS)
  33. {
  34. login_box(titania::$page, phpbb::$user->lang['ERROR_CONTRIB_EMAIL_FRIEND']);
  35. }
  36. titania::error_box('ERROR', 'ERROR_CONTRIB_EMAIL_FRIEND', TITANIA_ERROR, HEADER_FORBIDDEN);
  37. return false;
  38. }
  39. // Are we trying to abuse the facility?
  40. if (titania::$time - phpbb::$user->data['user_emailtime'] < phpbb::$config['flood_interval'])
  41. {
  42. trigger_error('FLOOD_EMAIL_LIMIT', E_USER_NOTICE);
  43. }
  44. $name = utf8_normalize_nfc(request_var('name', '', true));
  45. $email = request_var('email', '');
  46. $email_lang = request_var('lang', phpbb::$config['default_lang']);
  47. $message = utf8_normalize_nfc(request_var('message', '', true));
  48. $cc = (isset($_POST['cc_email'])) ? true : false;
  49. $submit = (isset($_POST['submit'])) ? true : false;
  50. add_form_key('contrib_email');
  51. phpbb::$template->assign_vars(array(
  52. 'S_LANG_OPTIONS' => language_select($email_lang),
  53. 'S_POST_ACTION' => phpbb::append_sid(titania::$page, array('id' => 'email', 'contrib_id' => $this->contrib_id)),
  54. ));
  55. $error = array();
  56. if ($submit)
  57. {
  58. if (!check_form_key('contrib_email'))
  59. {
  60. $error[] = 'FORM_INVALID';
  61. }
  62. if (!$email || !preg_match('/^' . get_preg_expression('email') . '$/i', $email))
  63. {
  64. $error[] = 'EMPTY_ADDRESS_EMAIL';
  65. }
  66. if (!$name)
  67. {
  68. $error[] = 'EMPTY_NAME_EMAIL';
  69. }
  70. if (!empty($error))
  71. {
  72. titania::error_box('ERROR', $error, TITANIA_ERROR);
  73. return false;
  74. }
  75. phpbb::_include('functions_messenger', false, 'messenger');
  76. $sql = 'UPDATE ' . USERS_TABLE . '
  77. SET user_emailtime = ' . titania::$time . '
  78. WHERE user_id = ' . (int) phpbb::$user->data['user_id'];
  79. $result = phpbb::$db->sql_query($sql);
  80. $mail_to_users = array();
  81. $mail_to_users[] = array(
  82. 'email_lang' => $email_lang,
  83. 'email' => $email,
  84. 'name' => $name,
  85. );
  86. // Ok, now the same email if CC specified, but without exposing the users email address
  87. if ($cc)
  88. {
  89. $mail_to_users[] = array(
  90. 'email_lang' => phpbb::$user->data['user_lang'],
  91. 'email' => phpbb::$user->data['user_email'],
  92. 'name' => phpbb::$user->data['username'],
  93. );
  94. }
  95. $lang_path = phpbb::$user->lang_path;
  96. phpbb::$user->set_custom_lang_path(titania::$config->language_path);
  97. $messenger = new messenger(false);
  98. foreach ($mail_to_users as $row)
  99. {
  100. $messenger->template('contrib_recommend', $row['email_lang']);
  101. $messenger->replyto(phpbb::$user->data['user_email']);
  102. $messenger->to($row['email'], $row['name']);
  103. $messenger->headers('X-AntiAbuse: Board servername - ' . phpbb::$config['server_name']);
  104. $messenger->headers('X-AntiAbuse: User_id - ' . (int) phpbb::$user->data['user_id']);
  105. $messenger->headers('X-AntiAbuse: Username - ' . phpbb::$user->data['username']);
  106. $messenger->headers('X-AntiAbuse: User IP - ' . phpbb::$user->ip);
  107. $messenger->assign_vars(array(
  108. 'BOARD_CONTACT' => phpbb::$config['board_contact'],
  109. 'TO_USERNAME' => htmlspecialchars_decode($name),
  110. 'FROM_USERNAME' => htmlspecialchars_decode(phpbb::$user->data['username']),
  111. 'MESSAGE' => htmlspecialchars_decode($message),
  112. 'CONTRIB_NAME' => htmlspecialchars_decode($this->contrib_name),
  113. 'U_CONTRIB' => phpbb::append_sid(titania::$page, array('contrib_id' => $this->contrib_id, 'id' => 'details'), true, ''),
  114. ));
  115. $messenger->send(NOTIFY_EMAIL);
  116. }
  117. phpbb::$user->set_custom_lang_path($lang_path);
  118. titania::error_box('SUCCESS', 'EMAIL_SENT', TITANIA_SUCCESS);
  119. return true;
  120. }
  121. return false;
  122. }
  123. }