• This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn more.
[TH] Email Reports

[TH] Email Reports 1.1.2

No permission to download

Nudaii

Well-known member
#1

ManOnDaMoon

Well-known member
#2
Hi and thanks for this useful addon.

I was just wondering where to edit the email's phrases or the email template. Is this possible or planned?
 

ManOnDaMoon

Well-known member
#3
Solution for future reference : follow the tutorial by RobDog mentioned in the resource description, and customize the email template.
Sadly, I guess email templates cannot be edited from installation unless in debug mode.
 

Ingenious

Well-known member
#4
I've installed this and all of my accounts which are Admin get the email when something is reported. But my super moderators do not.

My admin accounts are a mix of primary usergroup = Admin, or, a secondary group = Admin (with primary group being registered in that case) and they get the emails. My super mods are primary group registered with secondary group as super mod.

Any ideas where I should start to troubleshoot this or any info you need? Would the actions of this plugin be logged anywhere?
 

Ingenious

Well-known member
#5
Both of my super moderators have confirmed they are getting other forum emails (new PMs, watched threads etc) but not the report ones. Can you confirm, these are intended to go to any user who is a super moderator as a secondary usergroup? Or have I not read it right? In report.php does this line of code check for a user belonging to the supermod group?

Code:
$users = $this->fetchAllKeyed('SELECT * FROM xf_user WHERE is_admin = 1', 'user_id');
 

ManOnDaMoon

Well-known member
#6
The line you quote does grab the users which the email will be sent to. However, it will not check group belonging, but admin permissions. It was a shortcut robdog used for its tutorial:
In step 3, you will see the actual SQL statement where it grabs the users to send. I my implementation, it will grab all the ADMIN users and loop through them to send the reported item.
 

Ingenious

Well-known member
#8
That's what I thought, but the description of this plugin by the author does state:

Admins and Supermods Receive Email notices on reports
Perhaps that needs changing then to state that just admins get an email. Or, if anyone can suggest a change to that line of code to include members in the supermods group (as an additional usergroup) then I can modify it :)
 

Nudaii

Well-known member
#9
At the forum i installed this on both admin and the super/global mods get the reports, uncertain why you aren't getting that

as for email template yes sadly once installed you do it via the debug mode
 

Ingenious

Well-known member
#10
Richard my super mods definitely do not get emails, and the query I highlighted above would suggest it only looks for users matching admin="1" anyway. Maybe the supermods on your forum are also in the admin usergroup?

Perhaps if/when more people install this we'll get a better idea of what it's doing.

Is this something you are going to be looking into, no probs if not, in that case I'll ask for help in changing the query to also pick out those in the supermod group.

(Edit, another workaround for me would be to have it send the report just to one specified email address which I can hard code into the script, and use forwarders to send that on to mods).
 

Nudaii

Well-known member
#11
Feel free to ask for help with the query, i imagine jake bounce would know it, he is a master at sql queries, currently i'm bogged down with other work and still learning the xenforo system (having been a vb fanboy sicne 2005)
 

Ingenious

Well-known member
#12
Does anyone know how the code above can be changed so the email contains more information, for example, what post is reported and the report reason? The reason why this is useful is because if someone just reports a duplicate post, we don't all need to rush into the forum. Whereas if it is libel, we need to drop everything and act :) It will help prioritise our response, thanks.
 

ManOnDaMoon

Well-known member
#13
Does anyone know how the code above can be changed so the email contains more information, for example, what post is reported and the report reason? The reason why this is useful is because if someone just reports a duplicate post, we don't all need to rush into the forum. Whereas if it is libel, we need to drop everything and act :) It will help prioritise our response, thanks.
Here is my custom code, with comments on what information is fetched:
PHP:
class MODM_Model_Report extends XenForo_Model_Report
{
    public function reportContent($contentType, array $content, $message, array $viewingUser = null)
    {
        $reportId = parent::reportContent($contentType, $content, $message, $viewingUser);
        if ($reportId == 0)
        {
            return false;
        }
        $users = $this->fetchAllKeyed('SELECT * FROM xf_user WHERE is_admin = 1', 'user_id');
        $report = $this->getReportById($reportId);
        $userModel = $this->getModelFromCache('XenForo_Model_User');
 
        // Fetching the owner of reported content
        $reportedUser = $userModel->getUserById($report['content_user_id']);
 
        foreach ($users as $user)
        {
            $params = array(
        // User whose email will be sent
                'user' => $user['username'],
 
        // User who reported the content
                'reportingUser' => $report['last_modified_username'],
                'reportId' => $report['report_id'],
 
        // The message of the report - very useful indeed ;)
                'reportMessage' => $message,
 
        // Username of the content owner
                'reportedUser' => $reportedUser['username']
            );
         
            $mail = new XenForo_Mail('MODM_new_item_reported', $params, $user['language_id']);
            $mail->send($user['email'], $user['username']);
        }
    }
}
With the following email template "MODM_new_item_reported" (I used phrases in my own version, useful if you want multiple languages support) :
Hi {$user},
A new content has been reported by {$reportingUser}.
More info:
Reported content owner: {$reportedUser}
Comment: {$reportMessage}
To access the report, follow this link: {$xenOptions.boardUrl}/reports/{$reportId}/


The moderation team.
This code is freely usable as a starting point for someone willing to create an advanced addon.
 

Ingenious

Well-known member
#14
I don't follow the bit about a new email template. In the original it uses new_item_reported but I can't find any template or phrase with that title - so how can I edit this to change it? I tried creating a new template as you suggest above, but I then don't get any email at all. I must be missing something simple, but I cannot even find where the email template for the original plugin is (new_item_reported)?
 

Ingenious

Well-known member
#15
Don't Panic! I have found using the forum search that email templates can only be accessed in debug mode. Done, and fixed, have cobbled together my own version of this with thanks to ManOnDaMoon's help :) Thank you guys.
 

Nudaii

Well-known member
#17

Ingenious

Well-known member
#18
Richard can I suggest a different way of doing this (and it is how I changed the mod to suit my needs)? Why not have an option where instead of doing this by usergroup, you do it by user id? So the admin will set in the options, which users should get the reports. In that way, you can have total flexibility, you can have the reports sent to any or all of the mods and admins. You can also take mods/admin out of the emails (say, when they are on holiday) without changing their usergroups etc. In my amended add-on I hard coded this into the script which is obviously then not fit for distribution, but if that was a core part of the add-on it would be brilliant.

If you haven't already done it with this update, having the report reason (what the user filled in when reporting the post) is also really handy - because in the case of simple "Duplicate post, please remove" requests, mods know they don't have to drop everything and go into the forum quickly.

Just some suggestions, feel free to ignore, as we all have slightly different requirements!
 

ManOnDaMoon

Well-known member
#19
Upon request of my moderators, I updated the email content with the reported content type, the node title, the thread subject when relevant... Here is my code (I am maintaining my own addon based on this one).
PHP:
    public function reportContent($contentType, array $content, $message, array $viewingUser = null)
    {
        $reportId = parent::reportContent($contentType, $content, $message, $viewingUser);
        if ($reportId == 0)
        {
            return false;
        }
        $users = $this->fetchAllKeyed('SELECT email, username, language_id FROM xf_user WHERE is_admin = 1 OR is_moderator = 1', 'user_id');
        $report = $this->getReportById($reportId);
        $userModel = $this->getModelFromCache('XenForo_Model_USer');
        $reportedUser = $userModel->getUserById($report['content_user_id']);
 
        $reportHandler = $this->getReportHandler($contentType);
        list($contentId, $contentUserId, $contentInfo) = $reportHandler->getReportDetailsFromContent($content);
        switch ($contentType)
        {
            case "post":
                $mailTemplate = 'MODM_Phidippides_new_post_reported';
                $params = array(
                        'user' => "",
                        'reportingUser' => $report['last_modified_username'],
                        'reportId' => $report['report_id'],
                        'reportMessage' => $message,
                        'reportedUser' => $contentInfo['username'],
                        'reportedThread' => $contentInfo['thread_title'],
                        'reportedNode' => $contentInfo['node_title'],
                        'reportedContent' => $contentInfo['message']);
                break;
            case "profile_post":
            case "conversation_message":
            default:
                $mailTemplate = 'MODM_Phidippides_new_item_reported';
            $params = array(
                        'user' => "",
                        'reportingUser' => $report['last_modified_username'],
                        'reportId' => $report['report_id'],
                        'reportMessage' => $message,
                        'reportedUser' => $reportedUser['username']);
        }
     
        foreach ($users as $user)
        {
            XenForo_Error::debug("Mail report sent to " . $user['email']);
            $params['user'] = $user['username'];
            $mail = new XenForo_Mail($mailTemplate, $params, $user['language_id']);
            $mail->send($user['email'], $user['username']);
        }
    }
This requires new email templates based on content type. This is a copy/paste from my addon XML file. I only used a specific template for thread posts, letting the "Item report" template take care of the rest:
HTML:
 <email_templates>
    <template title="MODM_Phidippides_new_item_reported">
      <subject><![CDATA[{xen:phrase MODM_Phidippides_content_reported}]]></subject>
      <body_text><![CDATA[{xen:phrase MODM_Phidippides_hi} {$user},
 
{xen:phrase MODM_Phidippides_a_new_content_has_been_reported_by} {$reportingUser}.
 
{xen:phrase MODM_Phidippides_more_info}:
{xen:phrase MODM_Phidippides_reported_user}: {$reportedUser}
{xen:phrase MODM_Phidippides_report_comment}:
{$reportMessage}
 
{xen:phrase MODM_Phidippides_to_view_the_report_click_on_the_following_link}:
{$xenOptions.boardUrl}/reports/{$reportId}/
 
{xen:phrase MODM_Phidippides_signature}]]></body_text>
      <body_html><![CDATA[<p>{xen:phrase MODM_Phidippides_hi} {$user},</p>
 
<p>{xen:phrase MODM_Phidippides_a_new_content_has_been_reported_by} {$reportingUser}.</p>
 
<p><b>{xen:phrase MODM_Phidippides_more_info}:</b><br/>
{xen:phrase MODM_Phidippides_reported_user}: {$reportedUser}<br/>
{xen:phrase MODM_Phidippides_report_comment}:<br/>
<i>{$reportMessage}</i>
</p>
 
<p>{xen:phrase MODM_Phidippides_to_view_the_report_click_on_the_following_link}:<br/>
{$xenOptions.boardUrl}/reports/{$reportId}/</p>
 
<p>{xen:phrase MODM_Phidippides_signature}</p>]]></body_html>
    </template>
    <template title="MODM_Phidippides_new_post_reported">
      <subject><![CDATA[{xen:phrase MODM_Phidippides_post_reported}]]></subject>
      <body_text><![CDATA[{xen:phrase MODM_Phidippides_hi} {$user},
 
{xen:phrase MODM_Phidippides_a_new_post_has_been_reported_by} {$reportingUser}.
 
{xen:phrase MODM_Phidippides_more_info}:
{xen:phrase MODM_Phidippides_reported_node}: {$reportedNode}
{xen:phrase MODM_Phidippides_reported_thread}: {$reportedThread}
{xen:phrase MODM_Phidippides_reported_user}: {$reportedUser}
{xen:phrase MODM_Phidippides_report_comment}:
{$reportMessage}
 
{xen:phrase MODM_Phidippides_to_view_the_report_click_on_the_following_link}:
{$xenOptions.boardUrl}/reports/{$reportId}/
 
{xen:phrase MODM_Phidippides_signature}]]></body_text>
      <body_html><![CDATA[<p>{xen:phrase MODM_Phidippides_hi} {$user},</p>
 
<p>{xen:phrase MODM_Phidippides_a_new_post_has_been_reported_by} {$reportingUser}.</p>
 
<p><b>{xen:phrase MODM_Phidippides_more_info}:</b><br/>
{xen:phrase MODM_Phidippides_reported_node}: {$reportedNode}<br/>
{xen:phrase MODM_Phidippides_reported_thread}: {$reportedThread}<br/>
{xen:phrase MODM_Phidippides_reported_user}: {$reportedUser}<br/>
{xen:phrase MODM_Phidippides_report_comment}:<br/>
<i>{$reportMessage}</i>
</p>
 
<p>{xen:phrase MODM_Phidippides_to_view_the_report_click_on_the_following_link}:<br/>
{$xenOptions.boardUrl}/reports/{$reportId}/</p>
 
<p>{xen:phrase MODM_Phidippides_signature}</p>]]></body_html>
    </template>
  </email_templates>