by visiblesoul
tested with version 1.2.10
This is a little hack to send notifications of all new topics and new posts to main Admin. You can use the new topic or new post notification features separately if you like. What the hack actually does is to automatically subscribe you to all new topics and to existing topics when there is a new reply.
Do not use this hack if you have an a large active board. Your email server will have to work way too hard. The hack is suitable for boards with a few new posts per day.
IMPORTANT! You must change 2 instances of "$adsubid = 193;" in the hack code to relect your actual admin user id number.
----------------------------------------------------------------------
To receive notification of all new replies use this code...
FIND:
// Count number of replies in the topicADD ABOVE:
//begin admin notification hack by visiblesoul
//add this section of code to receive notification of all replies (1 of 1 edit)
$adsubid = 193; //Admin user id
$result = $db->query('SELECT 1 FROM '.$db->prefix.'subscriptions WHERE user_id='.$adsubid.' AND topic_id='.$tid) or error('Unable to fetch subscription info', __FILE__, __LINE__, $db->error());
if (!$db->num_rows($result))
$db->query('INSERT INTO '.$db->prefix.'subscriptions (user_id, topic_id) VALUES('.$adsubid.' ,'.$tid.')') or error('Unable to add subscription', __FILE__, __LINE__, $db->error());
//end admin notification hack
----------------------------------------------------------------------To receive notification of all new topics use this code...
FIND:
update_search_index('post', $new_pid, $message, $subject);
update_forum($fid);
ADD ABOVE: //begin admin notification hack by visiblesoul
//add this section of code to receive notification of all new topics (1 of 2 edits)
$adsubid = 193; //Admin user id
$db->query('INSERT INTO '.$db->prefix.'subscriptions (user_id, topic_id) VALUES('.$adsubid.' ,'.$new_tid.')') or error('Unable to add subscription', __FILE__, __LINE__, $db->error());
//end admin hack
FIND: update_search_index('post', $new_pid, $message, $subject);
update_forum($fid);
ADD BELOW: //begin admin notification hack by visiblesoul
//add this section of code to receive notification of all new topics (2 of 2 edits)
$result = $db->query('SELECT u.id, u.email, u.notify_with_post, u.language FROM '.$db->prefix.'users AS u INNER JOIN '.$db->prefix.'subscriptions AS s ON u.id=s.user_id LEFT JOIN '.$db->prefix.'online AS o ON u.id=o.user_id WHERE s.topic_id='.$new_tid.' AND u.id='.$adsubid.'') or error('Unable to fetch subscription info', __FILE__, __LINE__, $db->error());
if ($pun_user['id'] != $adsubid)
{
if ($db->num_rows($result))
{
require_once PUN_ROOT.'include/email.php';
$notification_emails = array();
// Loop through subscribed users and send e-mails
while ($cur_subscriber = $db->fetch_assoc($result))
{
// Is the subscription e-mail for $cur_subscriber['language'] cached or not?
if (!isset($notification_emails[$cur_subscriber['language']]))
{
if (file_exists(PUN_ROOT.'lang/'.$cur_subscriber['language'].'/mail_templates/new_reply.tpl'))
{
// Load the "new reply" template
$mail_tpl = trim(file_get_contents(PUN_ROOT.'lang/'.$cur_subscriber['language'].'/mail_templates/new_reply.tpl'));
// Load the "new reply full" template (with post included)
$mail_tpl_full = trim(file_get_contents(PUN_ROOT.'lang/'.$cur_subscriber['language'].'/mail_templates/new_reply_full.tpl'));
// The first row contains the subject (it also starts with "Subject:")
$first_crlf = strpos($mail_tpl, "n");
$mail_subject = trim(substr($mail_tpl, 8, $first_crlf-8));
$mail_message = trim(substr($mail_tpl, $first_crlf));
$first_crlf = strpos($mail_tpl_full, "n");
$mail_subject_full = trim(substr($mail_tpl_full, 8, $first_crlf-8));
$mail_message_full = trim(substr($mail_tpl_full, $first_crlf));
$mail_subject = str_replace('<topic_subject>', '''.$subject.''', $mail_subject);
$mail_message = str_replace('<topic_subject>', '''.$subject.''', $mail_message);
$mail_message = str_replace('<replier>', $username, $mail_message);
$mail_message = str_replace('<post_url>', $pun_config['o_base_url'].'/viewtopic.php?pid='.$new_pid.'#p'.$new_pid, $mail_message);
$mail_message = str_replace('<unsubscribe_url>', $pun_config['o_base_url'].'/misc.php?unsubscribe='.$new_tid, $mail_message);
$mail_message = str_replace('<board_mailer>', $pun_config['o_board_title'].' '.$lang_common['Mailer'], $mail_message);
$mail_subject_full = str_replace('<topic_subject>', '''.$subject.''', $mail_subject_full);
$mail_message_full = str_replace('<topic_subject>', '''.$subject.''', $mail_message_full);
$mail_message_full = str_replace('<replier>', $username, $mail_message_full);
$mail_message_full = str_replace('<message>', $message, $mail_message_full);
$mail_message_full = str_replace('<post_url>', $pun_config['o_base_url'].'/viewtopic.php?pid='.$new_pid.'#p'.$new_pid, $mail_message_full);
$mail_message_full = str_replace('<unsubscribe_url>', $pun_config['o_base_url'].'/misc.php?unsubscribe='.$new_tid, $mail_message_full);
$mail_message_full = str_replace('<board_mailer>', $pun_config['o_board_title'].' '.$lang_common['Mailer'], $mail_message_full);
$notification_emails[$cur_subscriber['language']][0] = $mail_subject;
$notification_emails[$cur_subscriber['language']][1] = $mail_message;
$notification_emails[$cur_subscriber['language']][2] = $mail_subject_full;
$notification_emails[$cur_subscriber['language']][3] = $mail_message_full;
$mail_subject = $mail_message = $mail_subject_full = $mail_message_full = null;
}
}
// We have to double check here because the templates could be missing
if (isset($notification_emails[$cur_subscriber['language']]))
{
if ($cur_subscriber['notify_with_post'] == '0')
pun_mail($cur_subscriber['email'], $notification_emails[$cur_subscriber['language']][0], $notification_emails[$cur_subscriber['language']][1]);
else
pun_mail($cur_subscriber['email'], $notification_emails[$cur_subscriber['language']][2], $notification_emails[$cur_subscriber['language']][3]);
}
}
}
}
//end admin notification hack
-=DKC=-














