Notifica e-mail su modifica Post

Aperto da ibernet, Venerdì - 16 Ottobre 2015 - 16:07

0 Utenti e 1 Visitatore stanno visualizzando questa discussione.

ibernet

Buondì a tutti, dato che non esistono mod mi son messo a sfrazzare un po' sul codice cercando di far si che quanto un utente attiva le notifiche parta l'email anche quando viene modificato un post contenuto nel topic in cui la notifica è attiva.

Ho trovato il pezzo di codice che rileva il flag della notifica ed invia una mail quando sente una nuova reply

// Notify members that something has happened to a topic they marked!
function sendNotifications($topics, $type, $exclude = array(), $members_only = array())
{
global $txt, $scripturl, $language, $user_info;
global $modSettings, $sourcedir, $context, $smcFunc;

// Can't do it if there's no topics.
if (empty($topics))
return;
// It must be an array - it must!
if (!is_array($topics))
$topics = array($topics);

// Get the subject and body...
$result = $smcFunc['db_query']('', '
SELECT mf.subject, ml.body, ml.id_member, t.id_last_msg, t.id_topic,
IFNULL(mem.real_name, ml.poster_name) AS poster_name
FROM {db_prefix}topics AS t
INNER JOIN {db_prefix}messages AS mf ON (mf.id_msg = t.id_first_msg)
INNER JOIN {db_prefix}messages AS ml ON (ml.id_msg = t.id_last_msg)
LEFT JOIN {db_prefix}members AS mem ON (mem.id_member = ml.id_member)
WHERE t.id_topic IN ({array_int:topic_list})
LIMIT 1',
array(
'topic_list' => $topics,
)
);
$topicData = array();
while ($row = $smcFunc['db_fetch_assoc']($result))
{
// Clean it up.
censorText($row['subject']);
censorText($row['body']);
$row['subject'] = un_htmlspecialchars($row['subject']);
$row['body'] = trim(un_htmlspecialchars(strip_tags(strtr(parse_bbc($row['body'], false, $row['id_last_msg']), array('<br />' => "\n", '</div>' => "\n", '</li>' => "\n", '[' => '[', ']' => ']')))));

$topicData[$row['id_topic']] = array(
'subject' => $row['subject'],
'body' => $row['body'],
'last_id' => $row['id_last_msg'],
'topic' => $row['id_topic'],
'name' => $user_info['name'],
'exclude' => '',
);
}
$smcFunc['db_free_result']($result);

// Work out any exclusions...
foreach ($topics as $key => $id)
if (isset($topicData[$id]) && !empty($exclude[$key]))
$topicData[$id]['exclude'] = (int) $exclude[$key];

// Nada?
if (empty($topicData))
trigger_error('sendNotifications(): topics not found', E_USER_NOTICE);

$topics = array_keys($topicData);
// Just in case they've gone walkies.
if (empty($topics))
return;

// Insert all of these items into the digest log for those who want notifications later.
$digest_insert = array();
foreach ($topicData as $id => $data)
$digest_insert[] = array($data['topic'], $data['last_id'], $type, (int) $data['exclude']);
$smcFunc['db_insert']('',
'{db_prefix}log_digest',
array(
'id_topic' => 'int', 'id_msg' => 'int', 'note_type' => 'string', 'exclude' => 'int',
),
$digest_insert,
array()
);

// Find the members with notification on for this topic.
$members = $smcFunc['db_query']('', '
SELECT
mem.id_member, mem.email_address, mem.notify_regularity, mem.notify_types, mem.notify_send_body, mem.lngfile,
ln.sent, mem.id_group, mem.additional_groups, b.member_groups, mem.id_post_group, t.id_member_started,
ln.id_topic
FROM {db_prefix}log_notify AS ln
INNER JOIN {db_prefix}members AS mem ON (mem.id_member = ln.id_member)
INNER JOIN {db_prefix}topics AS t ON (t.id_topic = ln.id_topic)
INNER JOIN {db_prefix}boards AS b ON (b.id_board = t.id_board)
WHERE ln.id_topic IN ({array_int:topic_list})
AND mem.notify_types < {int:notify_types}
AND mem.notify_regularity < {int:notify_regularity}
AND mem.is_activated = {int:is_activated}
AND ln.id_member != {int:current_member}' .
(empty($members_only) ? '' : ' AND ln.id_member IN ({array_int:members_only})') . '
ORDER BY mem.lngfile',
array(
'current_member' => $user_info['id'],
'topic_list' => $topics,
'notify_types' => $type == 'reply' ? '4' : '3',
'notify_regularity' => 2,
'is_activated' => 1,
'members_only' => is_array($members_only) ? $members_only : array($members_only),
)
);
$sent = 0;
while ($row = $smcFunc['db_fetch_assoc']($members))
{
// Don't do the excluded...
if ($topicData[$row['id_topic']]['exclude'] == $row['id_member'])
continue;

// Easier to check this here... if they aren't the topic poster do they really want to know?
if ($type != 'reply' && $row['notify_types'] == 2 && $row['id_member'] != $row['id_member_started'])
continue;

if ($row['id_group'] != 1)
{
$allowed = explode(',', $row['member_groups']);
$row['additional_groups'] = explode(',', $row['additional_groups']);
$row['additional_groups'][] = $row['id_group'];
$row['additional_groups'][] = $row['id_post_group'];

if (count(array_intersect($allowed, $row['additional_groups'])) == 0)
continue;
}

$needed_language = empty($row['lngfile']) || empty($modSettings['userLanguage']) ? $language : $row['lngfile'];
if (empty($current_language) || $current_language != $needed_language)
$current_language = loadLanguage('Post', $needed_language, false);

$message_type = 'notification_' . $type;
$replacements = array(
'TOPICSUBJECT' => $topicData[$row['id_topic']]['subject'],
'POSTERNAME' => un_htmlspecialchars($topicData[$row['id_topic']]['name']),
'TOPICLINK' => $scripturl . '?topic=' . $row['id_topic'] . '.new;topicseen#new',
'UNSUBSCRIBELINK' => $scripturl . '?action=notify;topic=' . $row['id_topic'] . '.0',
);

if ($type == 'remove')
unset($replacements['TOPICLINK'], $replacements['UNSUBSCRIBELINK']);
// Do they want the body of the message sent too?
if (!empty($row['notify_send_body']) && $type == 'reply' && empty($modSettings['disallow_sendBody']))
{
$message_type .= '_body';
$replacements['MESSAGE'] = $topicData[$row['id_topic']]['body'];
}
if (!empty($row['notify_regularity']) && $type == 'reply')
$message_type .= '_once';

// Send only if once is off or it's on and it hasn't been sent.
if ($type != 'reply' || empty($row['notify_regularity']) || empty($row['sent']))
{
$emaildata = loadEmailTemplate($message_type, $replacements, $needed_language);
sendmail($row['email_address'], $emaildata['subject'], $emaildata['body'], null, 'm' . $topicData[$row['id_topic']]['last_id']);
$sent++;
}
}
$smcFunc['db_free_result']($members);

if (isset($current_language) && $current_language != $user_info['language'])
loadLanguage('Post');

// Sent!
if ($type == 'reply' && !empty($sent))
$smcFunc['db_query']('', '
UPDATE {db_prefix}log_notify
SET sent = {int:is_sent}
WHERE id_topic IN ({array_int:topic_list})
AND id_member != {int:current_member}',
array(
'current_member' => $user_info['id'],
'topic_list' => $topics,
'is_sent' => 1,
)
);

// For approvals we need to unsend the exclusions (This *is* the quickest way!)
if (!empty($sent) && !empty($exclude))
{
foreach ($topicData as $id => $data)
if ($data['exclude'])
$smcFunc['db_query']('', '
UPDATE {db_prefix}log_notify
SET sent = {int:not_sent}
WHERE id_topic = {int:id_topic}
AND id_member = {int:id_member}',
array(
'not_sent' => 0,
'id_topic' => $id,
'id_member' => $data['exclude'],
)
);
}
}


Sto provando da un po' ma senza risultati..
C'è qualcuno che riesce a modificarlo affinchè funzioni?

Edit: dimenticato il file è Subs-Post.php

Edit2: ho trovato anche questo => http://support.simplemachines.org/function_db/index.php?action=view_function;id=320

emanuele

Sorry per il ritardo...
Così a naso, senza andare a leggere proprio tutto il codice, il sistema di notifiche di SMF si basa fortemente sull'ultimo messaggio letto, quindi andare a modificare quella funzione per infilarci notifiche a messaggi esisteni sarebbe probabilmente non semplice...

Discussioni simili (3)