News:

SMF 2.1.4 has been released! Take it for a spin! Read more.

Main Menu

Merge Post Notification by PM

Started by floydpink, October 23, 2010, 04:01:29 AM

Previous topic - Next topic

floydpink

This code allows the administrator to send a PM to a user when their post is merged into another one.
It is based on the excellent Move Topic Notification mod, but is a bit more complex as there are two messages being processed that are automatically ordered by date so the admin needs an option to choose which is the post that was selected to be merged and therefore which user should be sent the notification message.

SMF 1.1.11
./Sources/SplitTopics.php
Find                'link' => empty($row['ID_MEMBER_STARTED']) ? $row['name_started'] : '<a href="' . $scripturl . '?action=profile;u=' . $row['ID_MEMBER_STARTED'] . '">' . $row['name_started'] . '</a>'

Add After                // FloydPink INSERT - Merge Post notification
                ,'id' => empty($row['ID_MEMBER_STARTED']) ? '' : $row['ID_MEMBER_STARTED'],
                'name' => empty($row['name_started']) ? '' : $row['name_started']

Find    sendNotifications($ID_TOPIC, 'merge');

Add After    // FloydPink INSERT - Merge Topic Notification
    if (isset($_POST['postNotify']))
    {
        $PostSelectedForMerge = $_POST['TopicSelectedForMerge'];
        $PostSelectedForMergeMemberID=$topic_data[$PostSelectedForMerge]['started']['id'];
        $PostSelectedForMergeSubject = $topic_data[$PostSelectedForMerge]['subject'];
        // Get Merged Into id
        foreach ($topic_data as $topic)
            if ($topic['id'] != $PostSelectedForMerge)
                $PostSelectedForMergeInto = $topic['id'];
        $PostSelectedForMergeIntoSubject = $topic_data[$PostSelectedForMergeInto]['subject'];
        $mergedIntoId = $ID_TOPIC;
        $mergedInto_subject = $target_subject;
       
        // If you want to Temporarily BCC all PMs to admin to check its working then
        // place the admins memberid in the bcc line below e.g. 'bcc' => array(<memberid of admin>),
        $pmto = array(
            'to' => array($PostSelectedForMergeMemberID),
            'bcc' => array(),
        );

        $pm_subject = 'Merged Post: ' . $PostSelectedForMergeSubject;
        $pm_subject = un_htmlspecialchars($pm_subject);
        $pm_subject = preg_replace("/'/",'&#039;',$pm_subject);

        $pm_words = array('{merged_subject}','{merged_into_subject}','{merged_topic}');       

        $pm_move_topic_body = str_replace($pm_words,array(
            $PostSelectedForMergeSubject,
            $PostSelectedForMergeIntoSubject,
            '[url=http://' . $scripturl . '?topic=' . $mergedIntoId . '.0]' . $mergedInto_subject . '[/url]',
        ),
        $_POST['notify']
            );
        sendpm($pmto,$pm_subject,$pm_move_topic_body);
    }

Note: For clarity the various variables used are created at the start of the above code, but they could be merged into the bottom bit if preferred.
.Themes/Default/SplitTopics.template.php
Find                                <td class="windowbg2" valign="middle">
                                    <input type="checkbox" class="check" name="notifications[]" value="' . $topic['id'] . '" checked="checked" />
                                </td>
                            </tr>';
    echo '
                        </table>
                        <br />
                        <br />';

Replace with                                <td class="windowbg2" valign="middle">
                                    <input type="checkbox" class="check" name="notifications[]" value="' . $topic['id'] . '" checked="checked" />
                                </td>
                            </tr>';
    echo '
                        </table>
<!-- FloydPink DELETE to save white space - Merge Post Notification                        <br /> -->
                        <br />';

Find', /* REMEMBER TO RE-ADD CODE HERE 2309478 */'
                    </table></td>
                </tr>';
    }

Add After    // FloydPink INSERT - Merge Topic Notification
        echo '
                <tr>
                    <td class="windowbg" align=center>
                    <label for="postNotify"><input type="checkbox" name="postNotify" id="postNotify" checked="checked"/> ', $txt['mergeTopicPM'], '</label>';
        echo '
                    <select name="TopicSelectedForMerge">';
        foreach ($context['topics'] as $topic)
            echo '
                        <option value="', $topic['id'], '"  selected="selected">', $topic['started']['name'], '</option>';
        echo '
                    </select>
                    <div id="notifyArea" style="margin: 0;">
                        <textarea name="notify" rows="4" cols="120">', $txt['mergetopic_notify_default'], '</textarea>
                    </div>
                    </td>
                </tr>';     // Merge Topic Notification End

.Themes/Default/languages/Modifications.english.php
Find?>
Add Before// FloydPink INSERT - Merge Topic Notification
$txt['mergeTopicPM'] = 'Send PM notification of merge to';
$txt['mergetopic_notify_default'] = 'Hi there,' . "\n" . 'Just to let you know that your recent post \'{merged_subject}\' has been merged with the \'{merged_into_subject}\' post as the contents of the posts are directly related. The newly merged post is {merged_topic}.' . "\n" . 'Hope that\'s OK.' . "\n";

HunterP


THANKS!

Really appreciate this modification! Had to hack it a bit to get it working (made it a real zipped mod file), but it works like a charm now.

Thanks again!

HunterP


Did anyone got this working for 2.0 (especially RC5) ??


HunterP

Quote from: HunterP on March 28, 2011, 10:08:18 AM
Did anyone got this working for 2.0 (especially RC5) ??

Ok, I'm trying to port it myself. The template seems ok, but I'm getting this error :

Database error, given array of integer values is empty. (to_members)

I'm adding this in SplitTopics.php :

   if (isset($_POST['postNotify']))
   {
      $PostSelectedForMerge = $_POST['TopicSelectedForMerge'];
      $PostSelectedForMergeMemberID=$topic_data[$PostSelectedForMerge]['started']['id'];
      $PostSelectedForMergeSubject = $topic_data[$PostSelectedForMerge]['subject'];

      // Get Merged Into id
      foreach ($topic_data as $topic)
         if ($topic['id'] != $PostSelectedForMerge)
            $PostSelectedForMergeInto = $topic['id'];
      $PostSelectedForMergeIntoSubject = $topic_data[$PostSelectedForMergeInto]['subject'];
      $mergedIntoId = $id_topic;
      $mergedInto_subject = $target_subject;

      // If you want to Temporarily BCC all PMs to admin to check its working then
      // place the admins memberid in the bcc line below e.g. 'bcc' => array(<memberid of admin>),
      $pmto = array(
         'to' => array($PostSelectedForMergeMemberID),
         'bcc' => array(),
      );

      $pm_subject = $txt['mergetopic_notify_subject'] . $PostSelectedForMergeSubject;
      $pm_subject = un_htmlspecialchars($pm_subject);
      $pm_subject = preg_replace("/'/",'&#039;',$pm_subject);

      $pm_words = array('{merged_subject}','{merged_into_subject}','{merged_topic}');       

      $pm_merge_topic_body = str_replace($pm_words,array(
         $PostSelectedForMergeSubject,
         $PostSelectedForMergeIntoSubject,
         '' . $mergedInto_subject . '',
         ), $_POST['notify']
      );

      sendpm($pmto,$pm_subject,$pm_merge_topic_body);
   }

And that comes before :

   // Notify people that these topics have been merged?
   sendNotifications($id_topic, 'merge');




Any ideas?

HunterP


I was very patient with bumping, no-one??

Advertisement: