Pastebin

newspost2mail.php

von FuGu (16.06.2024 15:44)

Dein Code:
  1. <?php
  2.  
  3.  
  4.   // newpost2mail beta 21 for phpBB3 by Stefan Hendricks
  5.   // See http://henmedia.de for latest version
  6.   //
  7.   // Do not wonder if this code is formatted strange
  8.   // in your editor as I always use a tabsize of 2 :)
  9.  
  10.  
  11.   // only allow access from "posting.php"
  12.  
  13.   // if (!is_array($_SERVER)) { // phpBB3 >= v3.1.x
  14.  
  15.  
  16.   if (version_compare(PHPBB_VERSION, "3.1.0", ">=")) { // phpBB3 >= v3.1.0
  17.  
  18.     $my_script_name = $request->server("SCRIPT_NAME");
  19.     $my_script_uri  = $request->server("SCRIPT_URI");
  20.  
  21.   } else { // phpBB3 < v3.1.0
  22.  
  23.     $my_script_name = $_SERVER["SCRIPT_NAME"];
  24.     $my_script_uri  = $_SERVER["SCRIPT_URI"];
  25.  
  26.   }
  27.  
  28.   if ((substr($my_script_name, -11) != "posting.php") AND (substr($my_script_uri, -11) != "posting.php")) die("ACCESS DENIED");
  29.  
  30.  
  31.   newpost2mail($data);
  32.  
  33.   function newpost2mail($data) {
  34.  
  35.     global $config, $mode, $user, $post_data, $phpEx, $phpbb_root_path, $db;
  36.  
  37.     $version = "beta 21";
  38.  
  39.  
  40.     // variables that can be used in newpost2mail.config.php to build an individial subject line
  41.  
  42.     $post_SITENAME    = $config['sitename'];
  43.     $post_FORUMNAME   = $data['forum_name'];
  44.     $post_MODE        = $mode;
  45.     $post_TOPICTITLE  = $data['topic_title'];
  46.     $post_SUBJECT     = $post_data['post_subject'];
  47.     $post_USERNAME    = $user->data['username'];
  48.     $post_IP          = $data['poster_ip'];
  49.     $post_HOST        = @gethostbyaddr($post_IP);
  50.  
  51.  
  52.  
  53.     // 3rd party edit?
  54.  
  55.     if ( ($mode == "edit" ) AND ($post_data['username'] != $user->data['username']) ) {
  56.       $post_EDITOR    = $user->data['username'];
  57.       $post_USERNAME  = $post_data['username'];
  58.     }
  59.  
  60.  
  61.  
  62.     // get forum parents
  63.  
  64.     foreach (get_forum_parents($post_data) as $temp) {
  65.       $post_FORUMPARENTS       .= $temp["0"]. " / ";
  66.       $post_FORUMPARENTS_laquo .= $temp["0"]. " &laquo; ";
  67.     }
  68.  
  69.  
  70.  
  71.     // read configuration
  72.  
  73.     include($phpbb_root_path . 'newpost2mail.config.php');
  74.  
  75.  
  76.  
  77.     // check if the actual mode is set for sending mails
  78.  
  79.     if ($n2m_MAIL_ON[$mode]) {
  80.  
  81.       // if there is a language set in newpost2mail.config.php then use that setting.
  82.       // Otherwise read default language from board config and use that.
  83.  
  84.       $n2m_LANG ? $lang = $n2m_LANG : $lang = $config['default_lang'];
  85.  
  86.  
  87.  
  88.  
  89.       // get (translated) phrases and convert them to UTF8
  90.  
  91.       foreach ($n2m_TEXT['en'] as $key=>$value) {
  92.         if ($n2m_TEXT[$lang][$key]) {
  93.           $phrase[$key] = utf8_encode($n2m_TEXT[$lang][$key]);
  94.         } else {
  95.           $phrase[$key] = utf8_encode($n2m_TEXT[en][$key]);
  96.         }
  97.       }
  98.  
  99.  
  100.  
  101.  
  102.       // set variables for later use
  103.  
  104.       $board_url      = generate_board_url();
  105.       if (substr($board_url, -1) != "/") $board_url .= "/";
  106.  
  107.       $forum_url      = $board_url . "viewforum.php?f=$data[forum_id]";
  108.       $thread_url     = $board_url . "viewtopic.php?f=$data[forum_id]&t=$data[topic_id]";
  109.       $post_url       = $board_url . "viewtopic.php?f=$data[forum_id]&t=$data[topic_id]&p=$data[post_id]#p$data[post_id]";
  110.       $u_profile_url  = $board_url . "memberlist.php?mode=viewprofile&u=$post_data[poster_id]";
  111.       $e_profile_url  = $board_url . "memberlist.php?mode=viewprofile&u=$post_data[post_edit_user]";
  112.       $reply_url      = $board_url . "posting.php?mode=reply&f=$data[forum_id]&t=$data[topic_id]";
  113.       $edit_url       = $board_url . "posting.php?mode=edit&f=$data[forum_id]&p=$data[post_id]";
  114.       $quote_url      = $board_url . "posting.php?mode=quote&f=$data[forum_id]&p=$data[post_id]";
  115.       $delete_url     = $board_url . "posting.php?mode=delete&f=$data[forum_id]&p=$data[post_id]";
  116.       $info_url       = $board_url . "mcp.php?i=main&mode=post_details&f=$data[forum_id]&p=$data[post_id]";
  117.       $pm_url         = $board_url . "ucp.php?i=pm&mode=compose&action=quotepost&p=$data[post_id]";
  118.       $email_url      = $board_url . "memberlist.php?mode=email&u=$post_data[poster_id]";
  119.  
  120.  
  121.  
  122.       // build the email header
  123.  
  124.       include_once($phpbb_root_path . 'includes/functions_messenger.' . $phpEx);
  125.  
  126.       $headers .= "Date: ".date("D, j M Y H:i:s O")."\n";
  127.       $headers .= "From: \"".mail_encode(html_entity_decode($config['sitename']))."\" <$config[board_email]>\n";
  128.       $headers .= "X-Mailer: newpost2mail $version for phpBB3\n";
  129.       $headers .= "MIME-Version: 1.0\n";
  130.       $headers .= "Content-type: text/html; charset=UTF-8\n";
  131.  
  132.  
  133.  
  134.       // build the email body
  135.  
  136.       $message .= "<HTML>\n";
  137.       $message .= "<HEAD>\n";
  138.       $message .= "<base href='$board_url'>\n";
  139.       $message .= "<META http-equiv='content-type' content='text/html; charset=UTF-8'>\n";
  140.  
  141.  
  142.  
  143.       // insert style definitions from newpost2mail.css
  144.  
  145.       $message .= "<style type='text/css' media='screen'>\n";
  146.       $message .= file_get_contents($phpbb_root_path."newpost2mail.css");
  147.       $message .= "\n</style>\n";
  148.  
  149.       $message .= "</HEAD>\n";
  150.       $message .= "<BODY>\n";
  151.  
  152.  
  153.  
  154.       // build the informational table
  155.  
  156.       $message .= "<table class='table_info'>\n";
  157.       $message .= "<tr><td>$phrase[user]</td><td>: <a href='$u_profile_url'><b>$post_USERNAME</b></a>";
  158.       if ($post_EDITOR) $message .= "&nbsp;&nbsp;-&raquo; $phrase[edited_by] <a href='$e_profile_url'><b>$post_EDITOR</b></a>";
  159.       if (($user->data['user_allow_viewemail']) or ($n2m_ALWAYS_SHOW_EMAIL)) $message .= " (<a href='mailto:". $user->data['user_email'] . "'>". $user->data['user_email'] ."</a>)";
  160.       $message .= "</td>\n</tr>\n";
  161.       $message .= "<tr><td>$phrase[subject]</td><td>: <a href='$post_url'><b>$post_SUBJECT</b></a></td></tr>\n";
  162.       $message .= "<tr><td>$phrase[thread]</td><td>: <a href='$thread_url'>$post_TOPICTITLE</a></td></tr>\n";
  163.       $message .= "<tr><td>$phrase[forum]</td><td>: <a href='$forum_url'>$post_FORUMPARENTS_laquo$post_FORUMNAME</a></td></tr>\n";
  164.       $message .= "<tr><td>$phrase[mode]</td><td>: $mode</td></tr>\n";
  165.  
  166.       if ($post_HOST == $post_IP) $post_HOST = $phrase['host_na'];
  167.       $message .= "<tr><td>$phrase[ip_hostname]</td><td>: $post_IP / $post_HOST</td></tr>\n";
  168.       $message .= "<tr><td>$phrase[actions]</td><td>: [<a href='$reply_url'>$phrase[reply]</a>] [<a href='$quote_url'>$phrase[quote]</a>] [<a href='$edit_url'>$phrase[edit]</a>] [<a href='$delete_url'>$phrase[delete]</a>] [<a href='$info_url'>$phrase[info]</a>] [<a href='$pm_url'>$phrase[pm]</a>] [<a href='$email_url'>$phrase[email]</a>]</td></tr>\n";
  169.       $message .= "</table>\n";
  170.  
  171.  
  172.  
  173.       // build the post text table
  174.  
  175.       $message .= "<table class='table_post' width='$n2m_WIDTH'>\n";
  176.       $message .= "<tr><td><div class='content'>\n";
  177.  
  178.  
  179.  
  180.       // search for inline attachments to show them in the post text
  181.  
  182.       if (!empty($data['attachment_data'])) parse_attachments($data['forum_id'], $data['message'], $data['attachment_data'], $dummy, true);
  183.  
  184.       // generate post text
  185.  
  186.       $message .= str_replace("<br />", "<br />\n", generate_text_for_display($data['message'], $data['bbcode_uid'], $data['bbcode_bitfield'], $post_data['forum_desc_options']))."\n";
  187.  
  188.  
  189.  
  190.       // show attachments if not already shown in the post text
  191.  
  192.       if (!empty($data['attachment_data'])) {
  193.         $message .= "<br />\n<dl class='attachbox'><dt>$phrase[attachments]:</dt><dd>\n";
  194.         foreach ($data['attachment_data'] as $filename) {
  195.           $message .= print_r($filename, 1);
  196.         }
  197.         $message .= "</dl>\n";
  198.       }
  199.  
  200.  
  201.       // convert relative smily attachment to absolute url
  202.  
  203.       $message = str_replace("./download/file.php?id=", $board_url."download/file.php?id=", $message);
  204.  
  205.  
  206.       // 3rd party edit
  207.  
  208.       if ($post_data['post_edit_reason']) {
  209.         $post_EDITOR ? $edited_by = $post_EDITOR : $edited_by = $post_USERNAME;
  210.         $message .= "<div class='notice'>-&raquo; $phrase[edited_by] $edited_by, $phrase[edit_reason]: <em>$post_data[post_edit_reason]</em></div>\n";
  211.       }
  212.  
  213.  
  214.       // add signature
  215.  
  216.       if ($n2m_SHOW_SIG) {
  217.         if ($mode != "edit") {
  218.           if ( ($user->data[user_sig]) and ($data[enable_sig]) ) {
  219.             $message .= "<div class='signature'>";
  220.             $message .= generate_text_for_display($user->data[user_sig], $user->data[user_sig_bbcode_uid], $user->data[user_sig_bbcode_bitfield], $post_data[forum_desc_options])."\n";
  221.             $message .= "</div>\n";
  222.           }
  223.         } else {
  224.           if ( ($post_data[user_sig]) and ($post_data[enable_sig]) and ($n2m_SHOW_SIG)) {
  225.             $message .= "<div class='signature'>\n";
  226.             $message .= generate_text_for_display($post_data[user_sig], $post_data[user_sig_bbcode_uid], $post_data[user_sig_bbcode_bitfield], $post_data[forum_desc_options])."\n";
  227.             $message .= "</div>\n";
  228.           }
  229.         }
  230.       }
  231.  
  232.  
  233.       // convert relative smily url to absolute url
  234.  
  235.       $message = str_replace("./$config[smilies_path]", "$board_url$config[smilies_path]", $message);
  236.  
  237.       $message .= "</div></td></tr></table>\n";
  238.  
  239.  
  240.  
  241.       $message .= "</BODY></HTML>\n";
  242.  
  243.       $message = wordwrap($message, 256);
  244.  
  245.  
  246.       // encode subject
  247.  
  248.       $subject = mail_encode(html_entity_decode($n2m_SUBJECT));
  249.  
  250.  
  251.       // fix for phpBB 3.05 !
  252.       $subject = str_replace("\r", "", $subject);
  253.       $subject = str_replace("\n", "", $subject);
  254.  
  255.  
  256.  
  257.       // send email to board contact address?
  258.  
  259.       if ($n2m_MAILTO_BOARDCONTACT) $n2m_MAILTO[] = $config[board_contact];
  260.  
  261.  
  262.  
  263.       // send email to group?
  264.  
  265.       foreach ($n2m_MAILTO_GROUP as $group) {
  266.         $sql = $db->sql_build_query('SELECT', array('SELECT'  => 'u.user_email',
  267.                                                     'FROM'    => array(USERS_TABLE => 'u', GROUPS_TABLE => 'g', USER_GROUP_TABLE => 'ug'),
  268.                                                     'WHERE'   => 'ug.group_id = g.group_id AND ug.user_id = u.user_id AND u.user_email != \'\' AND lower(g.group_name) = \'' . strtolower($group) . '\''));
  269.         $result = $db->sql_query($sql);
  270.         while ($row = $db->sql_fetchrow($result)) $n2m_MAILTO[] = $row['user_email'];
  271.         $db->sql_freeresult($result);
  272.       }
  273.  
  274.  
  275.  
  276.       // add recipients by forum
  277.  
  278.       if (is_array($n2m_MONITOR_FORUM[$data['forum_id']])) $n2m_MAILTO = array_merge($n2m_MAILTO, $n2m_MONITOR_FORUM[$data[forum_id]]);
  279.  
  280.  
  281.  
  282.       // convert all addresses to lowercase and delete any empty addresses
  283.  
  284.       foreach ($n2m_MAILTO as $key => $value) {
  285.         if (is_null($value) or ($value == "")) {
  286.           unset($n2m_MAILTO[$key]);
  287.         } else {
  288.           $n2m_MAILTO[$key] = strtolower($n2m_MAILTO[$key]);
  289.         }
  290.       }
  291.  
  292.  
  293.  
  294.       // insure that every address is only used once
  295.  
  296.       $n2m_MAILTO = array_unique($n2m_MAILTO);
  297.  
  298.  
  299.       // Testversion, Mails an Author des Artikels verhindern
  300.       // unset($n2m_MAILTO[array_search($user->data['user_email'], $n2m_MAILTO)]);
  301.  
  302.  
  303.       // die($message); // for debugging purposes, mail will be shown in browser and not sent out if we uncomment this line
  304.  
  305.  
  306.  
  307.       // and finally send the mails
  308.  
  309.       foreach ($n2m_MAILTO as $mailto) {
  310.         if ($config['smtp_delivery']) { // SMTP?
  311.           $tempto['to']['email'] = $mailto;
  312.           $to['to'] = $tempto;
  313.           $result = smtpmail($to, $subject, str_replace("\n.", "\n..", $message), $err_msg, $headers);
  314.           reset($to);
  315.           reset($tempto);
  316.         } else { // or PHP mail?
  317.           $result = $config['email_function_name']($mailto, $subject, $message, $headers);
  318.        }
  319.       }
  320.     }
  321.   }
  322.  
  323. ?>
  324.  

Quellcode

Hier kannst du den Code kopieren und ihn in deinen bevorzugten Editor einfügen. Alternativ kannst du den gesamten Eintrag auch als Datei herunterladen.