plug_mail.php 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. <?php
  2. if (!class_exists("plug_mail")) {
  3. class plug_mail {
  4. function __construct($ns) {
  5. $this->title = __("mail", "dagsopt");
  6. $this->pluginname = $ns->pluginname;
  7. $this->file = $ns->file;
  8. $this->ns = $ns;
  9. }
  10. function start() {
  11. $this->logfile = fopen(ABSPATH . "/wp-content/uploads/maillog.log", 'a');
  12. add_filter('wp_mail', array(&$this, 'mail_logger'), 10, 1);
  13. add_filter('wp_mail_from_name', array(&$this, 'sender_name'));
  14. add_filter('wp_mail_from', array(&$this, 'sender_email'));
  15. //add_filter("wp_footer", array(&$this, 'tester'));
  16. }
  17. function sender_email($original_email_address) {
  18. $g = stripcslashes(get_option($this->pluginname . "_mail_emailsettings"));
  19. $arr = json_decode($g, true);
  20. if (isset($arr[$_SERVER['HTTP_HOST']])) {
  21. $darr = $arr[$_SERVER['HTTP_HOST']];
  22. } else {
  23. $dom = explode(".", $_SERVER['HTTP_HOST']);
  24. $topdom = implode(".", array_slice($dom, -2));
  25. if (isset($arr[$topdom])) {
  26. $darr = $arr[$topdom];
  27. }
  28. }
  29. if (isset($darr)) {
  30. return $darr[1];
  31. } else {
  32. return $original_email_address;
  33. }
  34. }
  35. function sender_name($original_email_from) {
  36. $g = stripcslashes(get_option($this->pluginname . "_mail_emailsettings"));
  37. $arr = json_decode($g, true);
  38. if (isset($arr[$_SERVER['HTTP_HOST']])) {
  39. $darr = $arr[$_SERVER['HTTP_HOST']];
  40. } else {
  41. $dom = explode(".", $_SERVER['HTTP_HOST']);
  42. $topdom = implode(".", array_slice($dom, -2));
  43. if (isset($arr[$topdom])) {
  44. $darr = $arr[$topdom];
  45. }
  46. }
  47. if (isset($darr)) {
  48. return $darr[0];
  49. } else {
  50. return $original_email_from;
  51. }
  52. }
  53. function tester() {
  54. $g = stripcslashes(get_option($this->pluginname . "_mail_emailsettings"));
  55. $arr = json_decode($g, true);
  56. if (isset($arr[$_SERVER['HTTP_HOST']])) {
  57. $darr = $arr[$_SERVER['HTTP_HOST']];
  58. } else {
  59. $dom = explode(".", $_SERVER['HTTP_HOST']);
  60. $topdom = implode(".", array_slice($dom, -2));
  61. if (isset($arr[$topdom])) {
  62. $darr = $arr[$topdom];
  63. }
  64. }
  65. if (isset($darr)) {
  66. print_r($darr);
  67. }
  68. }
  69. function mail_logger($args) {
  70. $str = date("Y-m-d");
  71. $str .= " | " . date("H:i:s");
  72. $str .= " | " . $args['to'];
  73. $str .= " | " . $args['subject'];
  74. fwrite($this->logfile, $str . "\n");
  75. return $args;
  76. }
  77. function help() {
  78. ?>
  79. <?php echo (__("Adds mail log functions", "dagsopt")) ?>
  80. <?php echo (__("Adds mail settings", "dagsopt")) ?>
  81. <?php
  82. }
  83. function Option($pre) {
  84. update_option($pre . '_emailsettings', $_POST[$pre . '_emailsettings']);
  85. }
  86. function fullscreen() {
  87. ?>
  88. <?php
  89. $data = file_get_contents(ABSPATH . "/wp-content/uploads/maillog.log");
  90. ?>
  91. <table class="form-table">
  92. <tr><td style="width: 100px;">Email log</td>
  93. <td>
  94. <textarea class="" rows="40" style="width: 100%; font-size: 11px;"><?php echo ($data) ?></textarea>
  95. </td></tr>
  96. </table>
  97. <?php
  98. }
  99. function admin_line($pre) {
  100. ?>
  101. <?php echo (__("Emailsettings:", "dagsopt")) ?><br><textarea style="width: 100%; height: 150px;" name="<?php echo ($pre . '_emailsettings'); ?>"><?php echo (stripcslashes(get_option($pre . "_emailsettings"))); ?></textarea>
  102. <hr>
  103. <?php echo ($pre . "_emailsettings"); ?>
  104. <?php
  105. $g = stripcslashes(get_option($pre . "_emailsettings"));
  106. $arr = json_decode($g, true);
  107. ?>
  108. <hr>
  109. <a href="/wp-admin/admin.php?page=dagsopt-options-mail">Se log</a>
  110. <?php
  111. }
  112. }
  113. global $plug_mail;
  114. $plug_mail = new plug_mail($this);
  115. $this->dagsopt['plug_mail'] = $plug_mail;
  116. }