Possible, but not a good idea (Features)

by Auge ⌂ @, Wednesday, August 15, 2012, 20:36 (2846 days ago) @ novacultura

Wow! That gives me hope.
I am talking of a quite small forum for a restricted community of translators, so I won't be afraid of being classified as spammer. Far away from that, I fear.

But may I ask how you implemented this option?
I have only rudimentary knowledge of php, unfortunately.

I implemented it in an easy way for mlf2 version 2.3. Every user, who has activated the user setting for being able to receive personal messages via the contact form will be notified about new entries in the forum. Otherwise the users will not informed about new entries.

1. Add the following function to includes/functions.inc.php

 * sends an e-mail notification to all users if a reply was
 * posted and a notification was requested
 * @param int $id : the id of the reply
 * @param bool $delayed : true adds a delayed message (when posting was activated manually)
function emailNotification2AllUsers($id, $delayed=false)
  global $settings, $db_settings, $lang, $connid;
  // check for 'notification for all registered users'-setting
  if ($settings['email_notification_2_all'] != 1) return false;
  // data of posting:
  $result = @mysql_query("SELECT pid, tid, name, user_name, ".$db_settings['forum_table'].".user_id, subject, text
                          FROM ".$db_settings['forum_table']."
                          LEFT JOIN ".$db_settings['userdata_table']." ON ".$db_settings['userdata_table'].".user_id=".$db_settings['forum_table'].".user_id
                          WHERE id = ".intval($id)." LIMIT 1", $connid);
  $data = mysql_fetch_array($result);
  // overwrite $data['name'] with $data['user_name'] if registered user:
    if(!$data['user_name']) $data['name'] = $lang['unknown_user'];
    else $data['name'] = $data['user_name'];
  // data of registered users, who wants to receive notifications
  $result = @mysql_query("SELECT user_name, user_email FROM ".$db_settings['userdata_table']." WHERE email_contact = 1", $connid);
  // return false in case of empty result
  if (mysql_num_rows($result) == 0) return false;
  // generate static content of the email
  $name = $data['name'];
  $subject = $data['subject'];
  $text = email_format($data['text']);
  // cut the email template at the point, where the parent posting should be encluded
  $emailbody = substr($lang['email_text'], 0, strrpos($lang['email_text'], '[posting_address]') + 17);
  $emailbody = str_replace("[name]", $name, $emailbody);
  $emailbody = str_replace("[subject]", $subject, $emailbody);
  $emailbody = str_replace("[text]", $text, $emailbody);
  $emailbody = str_replace("[posting_address]", $settings['forum_address']."index.php?id=".$id, $emailbody);
  $emailbody = str_replace("[forum_address]", $settings['forum_address'], $emailbody);
  if($delayed==true) $emailbody = $emailbody . "\n\n" . $lang['email_text_delayed_addition'];
  // get content of the parent posting
  if ($data['pid'] > 0)
    $parent_result = mysql_query("SELECT name, subject FROM ".$db_settings['forum_table']." WHERE id = ".intval($data['pid'])." LIMIT 1", $connid);
    $parent_data = mysql_fetch_assoc($parent_result);
    $emailbody = str_replace("[original_subject]", $parent_data['subject'], $emailbody);
    $emailbody = str_replace("[original_subject]", '---', $emailbody);
  while ($note = mysql_fetch_assoc($result))
    $dynamicbody = $emailbody;
    $dynamicbody = str_replace("[recipient]", $note['user_name'], $dynamicbody);
    $recipient = $note['user_email'];
    my_mail($recipient, $subject, $dynamicbody);

2. Use this funtion in posting.inc.php after lines 925 and 1527.

        // e-mail notification to admins and mods
        if($spam==0) emailNotification2ModsAndAdmins($new_data['id']);
        // e-mail notification to all users (the new lines)
        if($spam==0) emailNotification2AllUsers($new_data['id']);


        emailNotification2ParentAuthor($id, true);
        emailNotification2ModsAndAdmins($id, true);
        emailNotification2AllUsers($id, true); // the new line

3. Add a new setting via phpMyAdmin or a similar tool. Open the table mlf2_settings and insert a new row.

name: email_notification_2_all
value: 1

I tested the code in a test environment with only one user and it worked. Please test the code well in your own forum. Other functions are not affected.

Tschö, Auge

Trenne niemals Müll, denn er hat nur eine Silbe!

Complete thread:

 RSS Feed of thread

powered by my little forum