Pastebin

newspostmail

von FuGu

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.  
  185.       // generate post text
  186.  
  187.       $message .= str_replace("<br />", "<br />\n", generate_text_for_display($data[message], $data[bbcode_uid], $data[bbcode_bitfield], $post_data[forum_desc_options]))."\n";
  188.  
  189.  
  190.  
  191.       // show attachments if not already shown in the post text
  192.  
  193.       if (!empty($data[attachment_data])) {
  194.         $message .= "<br />\n<dl class='attachbox'><dt>$phrase[attachments]:</dt><dd>\n";
  195.         foreach ($data[attachment_data] as $filename) {
  196.           $message .= print_r($filename, 1);
  197.         }
  198.         $message .= "</dl>\n";
  199.       }
  200.  
  201.  
  202.       // convert relative smily attachment to absolute url
  203.  
  204.       $message = str_replace("./download/file.php?id=", $board_url."download/file.php?id=", $message);
  205.  
  206.  
  207.       // 3rd party edit
  208.  
  209.       if ($post_data[post_edit_reason]) {
  210.         $post_EDITOR ? $edited_by = $post_EDITOR : $edited_by = $post_USERNAME;
  211.         $message .= "<div class='notice'>-&raquo; $phrase[edited_by] $edited_by, $phrase[edit_reason]: <em>$post_data[post_edit_reason]</em></div>\n";
  212.       }
  213.  
  214.  
  215.       // add signature
  216.  
  217.       if ($n2m_SHOW_SIG) {
  218.         if ($mode != "edit") {
  219.           if ( ($user->data[user_sig]) and ($data[enable_sig]) ) {
  220.             $message .= "<div class='signature'>";
  221.             $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";
  222.             $message .= "</div>\n";
  223.           }
  224.         } else {
  225.           if ( ($post_data[user_sig]) and ($post_data[enable_sig]) and ($n2m_SHOW_SIG)) {
  226.             $message .= "<div class='signature'>\n";
  227.             $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";
  228.             $message .= "</div>\n";
  229.           }
  230.         }
  231.       }
  232.  
  233.  
  234.       // convert relative smily url to absolute url
  235.  
  236.       $message = str_replace("./$config[smilies_path]", "$board_url$config[smilies_path]", $message);
  237.  
  238.       $message .= "</div></td></tr></table>\n";
  239.  
  240.  
  241.  
  242.       $message .= "</BODY></HTML>\n";
  243.  
  244.       $message = wordwrap($message, 256);
  245.  
  246.  
  247.       // encode subject
  248.  
  249.       $subject = mail_encode(html_entity_decode($n2m_SUBJECT));
  250.  
  251.  
  252.       // fix for phpBB 3.05 !
  253.       $subject = str_replace("\r", "", $subject);
  254.       $subject = str_replace("\n", "", $subject);
  255.  
  256.  
  257.  
  258.       // send email to board contact address?
  259.  
  260.       if ($n2m_MAILTO_BOARDCONTACT) $n2m_MAILTO[] = $config[board_contact];
  261.  
  262.  
  263.  
  264.       // send email to group?
  265.  
  266.       foreach ($n2m_MAILTO_GROUP as $group) {
  267.         $sql = $db->sql_build_query('SELECT', array('SELECT'  => 'u.user_email',
  268.                                                     'FROM'    => array(USERS_TABLE => 'u', GROUPS_TABLE => 'g', USER_GROUP_TABLE => 'ug'),
  269.                                                     '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) . '\''));
  270.         $result = $db->sql_query($sql);
  271.         while ($row = $db->sql_fetchrow($result)) $n2m_MAILTO[] = $row['user_email'];
  272.         $db->sql_freeresult($result);
  273.       }
  274.  
  275.  
  276.  
  277.       // add recipients by forum
  278.  
  279.       if (is_array($n2m_MONITOR_FORUM[$data[forum_id]])) $n2m_MAILTO = array_merge($n2m_MAILTO, $n2m_MONITOR_FORUM[$data[forum_id]]);
  280.  
  281.  
  282.  
  283.       // convert all addresses to lowercase and delete any empty addresses
  284.  
  285.       foreach ($n2m_MAILTO as $key => $value) {
  286.         if (is_null($value) or ($value == "")) {
  287.           unset($n2m_MAILTO[$key]);
  288.         } else {
  289.           $n2m_MAILTO[$key] = strtolower($n2m_MAILTO[$key]);
  290.         }
  291.       }
  292.  
  293.  
  294.  
  295.       // insure that every address is only used once
  296.  
  297.       $n2m_MAILTO = array_unique($n2m_MAILTO);
  298.  
  299.  
  300.       // Testversion, Mails an Author des Artikels verhindern
  301.       // unset($n2m_MAILTO[array_search($user->data['user_email'], $n2m_MAILTO)]);
  302.  
  303.  
  304.       // die($message); // for debugging purposes, mail will be shown in browser and not sent out if we uncomment this line
  305.  
  306.  
  307.  
  308.       // and finally send the mails
  309.  
  310.       foreach ($n2m_MAILTO as $mailto) {
  311.         if ($config['smtp_delivery']) { // SMTP?
  312.           $tempto[to][email] = $mailto;
  313.           $to[to] = $tempto;
  314.           $result = smtpmail($to, $subject, str_replace("\n.", "\n..", $message), $err_msg, $headers);
  315.           reset($to);
  316.           reset($tempto);
  317.         } else { // or PHP mail?
  318.           $result = $config['email_function_name']($mailto, $subject, $message, $headers);
  319.        }
  320.       }
  321.     }
  322.   }
  323.  
  324. ?>
  325.  

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.