Private Messages in stats
#1
Hello,
i'd love to see a plugin which includes the number of PMs sent (average per day / in total / past 24hrs) in stats.php
Reply
#2
* bump *

...or might this be something to be considered as a standard feature in future versions?
Reply
#3
I think it's unethical. PM, and stats about PM, are private. And must stay private.
[MyBB 1.8 mods] - Offer me a coffee
Do not ask me help through PM
Reply
#4
I don't see this getting added to MyBB anytime soon... Certainly wouldn't be hard to do though.

Edit: Here you go. Quickly done this:

<?php

// Disallow direct access to this file for security reasons
if(!defined("IN_MYBB"))
{
	die("Direct initialization of this file is not allowed.");
}


$plugins->add_hook("stats_start", "pmstats_calculate");

function pmstats_info()
{
	return array(
        "name"  => "Private Message Stats",
        "description"=> "Calculates and outputs statistics regarding private messaging.",
        "website"        => "https://oseax.com",
        "author"        => "Wires <i>(AndreRl)</i>",
        "authorsite"    => "https://oseax.com",
        "version"        => "1.0",
        "guid"             => "",
        "compatibility" => "18*"
	);
}

function pmstats_install()
{
global $db, $mybb;

$setting_group = array(
    'name' => 'pmstats',
    'title' => 'Private Messaging Statistics',
    'description' => 'Displays stats about PMs on the Statistics page.',
    'disporder' => 5, 
    'isdefault' => 0
);

$gid = $db->insert_query("settinggroups", $setting_group);

$setting_array = array(

    'pmstats_enable' => array(
        'title' => 'Enable Statistics',
        'description' => 'Show PM statistics on stats page',
        'optionscode' => 'yesno',
        'value' => 1, 
        'disporder' => 1
    ),

    'pmstats_total' => array(
        'title' => 'Total PMs Stat',
        'description' => 'Toggle the total amount',
        'optionscode' => "yesno",
        'value' => 1,
        'disporder' => 2
    ),

    'pmstats_average' => array(
        'title' => 'Average PMs Stat',
        'description' => 'Toggle average amount of PMs sent per day',
        'optionscode' => 'yesno',
        'value' => 1,
        'disporder' => 3
    ),
	
    'pmstats_day' => array(
        'title' => 'Past 24hrs PMs Stat',
        'description' => 'Toggle amount of PMs sent in 24 hours',
        'optionscode' => 'yesno',
        'value' => 1,
        'disporder' => 3
    ),
);

foreach($setting_array as $name => $setting)
{
    $setting['name'] = $name;
    $setting['gid'] = $gid;

    $db->insert_query('settings', $setting);
}

// Don't forget this!
rebuild_settings();
}

function pmstats_is_installed()
{
 global $mybb;
    if($mybb->settings['pmstats_enable'])
    {
        return true;
    }
    return false;
}

function pmstats_uninstall()
{
global $db;

$db->delete_query('settings', "name IN ('pmstats_enable','pmstats_total','pmstats_average', 'pmstats_day')");
$db->delete_query('settinggroups', "name = 'pmstats'");

rebuild_settings();
}

function pmstats_activate()
{
global $db;

$templates = array();
$templates[] = array(
// Total Stats template
	"title" => "pmstats_total",
	"template" => 'Private Messages: <b>{$total_pmstats}</b>'
	);
$templates[] = array(
// Average Stats template
	"title" => "pmstats_average",
	"template" => 'Private Messages per day: <b>{$average_pmstats}'
);
$templates[] = array(
// 24hrs Stats template
	"title" => "pmstats_day",
	"template" => 'Amount of PMs sent in last 24 hrs: <b>{$day_pmstats}</b>'
);
    foreach($templates as $template)
    {
        $insert = array(
            "title" => $db->escape_string($template['title']),
            "template" => $db->escape_string($template['template']),
            "sid" => "-1",
            "version" => "",
            "dateline" => time()
        );
        $db->insert_query("templates", $insert);
    }

}

function pmstats_deactivate()
{
global $db;

$db->delete_query('templates', "title IN ('pmstats_total','pmstats_average', 'pmstats_day')");
}

function pmstats_calculate()
{
global $db, $mybb, $templates, $pmstatstotal, $pmstatsaverage, $pmstatsday, $cache;


if($mybb->settings['pmstats_enable'] != 1)
{
	return;
}

// Lets start off with total...
if($mybb->settings['pmstats_total'] == 1)
{
$query = $db->simple_select("privatemessages", "COUNT(pmid) as pms");
$total_pmstats = (int)$db->fetch_field($query, "pms");

eval("\$pmstatstotal = \"".$templates->get("pmstats_total")."\";");
}

// Now onto average...
if($mybb->settings['pmstats_average'] == 1)
{

$query = $db->simple_select("users", "regdate", "", array('order_by' => 'regdate', 'limit' => 1));
$result = $db->fetch_array($query);
$days = (TIME_NOW - $result['regdate']) / 86400;
	if($days < 1)
	{
		$days = 1;
	}

	if($mybb->settings['pmstats_total'] == 1)
	{
		$average_pmstats = my_number_format(round(($total_pmstats / $days)));
	} else {
		$query = $db->simple_select("privatemessages", "COUNT(pmid) as pms");
		$total_pmstats = (int)$db->fetch_field($query, "pms");
		$average_pmstats = my_number_format(round(($total_pmstats / $days)));
	}

eval("\$pmstatsaverage = \"".$templates->get("pmstats_average")."\";");
	
}

// Finally, last 24hrs...
if($mybb->settings['pmstats_day'] == 1)
{

$timecut = TIME_NOW - 86400;
$query = $db->simple_select("privatemessages", "COUNT(pmid) as pms", "dateline > $timecut");
$day_pmstats = (int)$db->fetch_field($query, "pms");

eval("\$pmstatsday = \"".$templates->get("pmstats_day")."\";");	
}

}

Add the following to your stats page wherever necessary:
{$pmstatstotal}
{$pmstatsaverage}
{$pmstatsday}
Plugin Count: I lost count.
Public Plugins are available here.
Official GitHub.
Please do not PM me for support unless asked to.
Reply
#5
(2018-06-27, 10:31 PM)Crazycat Wrote: I think it's unethical. PM, and stats about PM, are private. And must stay private.

The number of total PMs sent on a site, not broken down by user, how is that private?

(2018-06-27, 10:32 PM)Wires Wrote: I don't see this getting added to MyBB anytime soon... Certainly wouldn't be hard to do though.

Edit: Here you go. Quickly done this:

Nice! Thank you, Wires Smile

I found one bug:


// Average Stats template
	"title" => "pmstats_average",
	"template" => 'Private Messages per day: <b>{$average_pmstats}'
);

The closing </b> tag is missing.


edit: I also added my_number_format(...) for the total
$total_pmstats = my_number_format((int)$db->fetch_field($query, "pms"));


See it (translated) in action here: https://www.linguisten.de/stats.php


Most of the words used should be available in the standard language files already. I think I'll play around with that and see how far I can get. Otherwise, I'll gladly translate a language file and add it here if you like.
Reply
#6
(2018-06-28, 12:19 AM)linguist Wrote:
(2018-06-27, 10:31 PM)Crazycat Wrote: I think it's unethical. PM, and stats about PM, are private. And must stay private.

The number of total PMs sent on a site, not broken down by user, how is that private?

Sorry, I didn't realize you were speaking about the total (didn't see "stats page").

But I think these stats are irrelevant:
- users can delete their received MP,
- the query can count the double of MP (sent + received)
- the query count the MP which are in the trash folder,
- it also count the automatic messages (subscribtion to a forum / thread)
- ...
[MyBB 1.8 mods] - Offer me a coffee
Do not ask me help through PM
Reply
#7
In some communities, these numbers are taken as another indicator of how active the community is.

But yes... It is a niche thing and I'm happy to have it. ;-)
Reply
#8
(2018-06-28, 12:19 AM)linguist Wrote:
(2018-06-27, 10:31 PM)Crazycat Wrote: I think it's unethical. PM, and stats about PM, are private. And must stay private.

The number of total PMs sent on a site, not broken down by user, how is that private?

(2018-06-27, 10:32 PM)Wires Wrote: I don't see this getting added to MyBB anytime soon... Certainly wouldn't be hard to do though.

Edit: Here you go. Quickly done this:

Nice! Thank you, Wires Smile

I found one bug:


// Average Stats template
	"title" => "pmstats_average",
	"template" => 'Private Messages per day: <b>{$average_pmstats}'
);

The closing </b> tag is missing.


edit: I also added my_number_format(...) for the total
$total_pmstats = my_number_format((int)$db->fetch_field($query, "pms"));


See it (translated) in action here: https://www.linguisten.de/stats.php


Most of the words used should be available in the standard language files already. I think I'll play around with that and see how far I can get. Otherwise, I'll gladly translate a language file and add it here if you like.

Was actually going to add a language for it, but I couldn't see this being used by a lot of people (haven't seen any requests for it) at all. More than welcome to post a language file for it Smile
Plugin Count: I lost count.
Public Plugins are available here.
Official GitHub.
Please do not PM me for support unless asked to.
Reply
#9
<?php
/**
 * pmstats language file by linguist
 * https://community.mybb.com/user-13949.html 
 * Language: en
 */
 
/* front end */
$l['pms_pms'] = "Private Messages";
$l['pms_total'] = "Total Private Messages";
$l['pms_perday'] = "Private Messages per day";
$l['pms_today'] = "Private messages in the past 24 hours";

/* admin */
$l['pms_name'] = "Private Message Stats";
$l['pms_desc'] = "Calculates and outputs statistics regarding private messaging.";
$l['pms_title'] = "Private Messaging Statistics";
$l['pms_settings'] = "Displays stats about PMs on the Statistics page.";
$l['pms_main'] = "Enable Statistics";
$l['pms_maind'] = "Show PM statistics on stats page";
$l['pms_set1'] = "Total PMs Stat";
$l['pms_set1d'] = "Toggle the total amount";
$l['pms_set2'] = "Average PMs Stat";
$l['pms_set2d'] = "Toggle average amount of PMs sent per day";
$l['pms_set3'] = "Past 24hrs PMs Stat";
$l['pms_set3d'] = "Toggle amount of PMs sent in 24 hours";
?>


<?php
/**
 * pmstats language file by linguist
 * https://community.mybb.com/user-13949.html 
 * Language: de
 */
 
/* front end */
$l['pms_pms'] = "Private Nachrichten";
$l['pms_total'] = "Private Nachrichten insgesamt";
$l['pms_perday'] = "Private Nachrichten pro Tag";
$l['pms_today'] = "Private Nachrichten heute";

/* admin */
$l['pms_name'] = "Private Message Stats";
$l['pms_desc'] = "Erweitert die Statistik-Seite um Daten zu Privaten Nachrichten";
$l['pms_title'] = "PN Statistik";
$l['pms_settings'] = "Zeigt PN-Statistiken auf der Statistikseite an";
$l['pms_main'] = "PN-Statistiken einschalten";
$l['pms_maind'] = "sollen PN-Statistiken angezeigt werden?";
$l['pms_set1'] = "Gesamtzahl";
$l['pms_set1d'] = "Gesamtsumme aller PN anzeigen?";
$l['pms_set2'] = "PN Durchschnitt";
$l['pms_set2d'] = "Durchschnitt PN pro Tag anzeigen?";
$l['pms_set3'] = "PN heute";
$l['pms_set3d'] = "PN der letzten 24 Stunden anzeigen?";
?>
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)