UBB.Dev
Posted By: Medar Final-[6.5] Private Message Enhancement 1.0 - 09/24/2004 10:12 PM
Mod Name / Version: Private Message Enhancement 1.0

Description: This modification will allow all users to save selected private messages, and allow them to view statistics on their private messages (ie, #saved, #received, #sent, #total in box). It also shows the total allowed number of private messages set by the forum admistrators in the 6.5 control panel, and the user's percent usage of their PM Box.


Working Under: UBB.Threads 6.5

Mod Status: Beta

Any pre-requisites: none

Author(s): Medar

Date: 09/24/04

Credits:

Files Altered: delete.php, mess_handler.php, mess_reply.php, viewmessages.php, viewmessages.tmpl, viewmessage.tmpl, and the generic, viewmessage, and viewmessages language files.

New Files: none

Database Altered: No.

Info/Instructions: Yes, I know this could be considered a cheesy knock-off of other similar systems, but as a Threads admin, I have always wanted to be able to save a few Private Messages here and there.

Plus with the 6.5 Admin ability to set a PM limit, this allows users to view their status as well.

To play with this first (if you like), head to http://www.bladekeep.com/forums/

Login: threadsdev
pass: threadsdev

Send as many PMs to yourself as you like!

Disclaimer: Please backup every file that you intend to modify. If the modification modifies the database, it's a good idea to backup your database before doing so. I am not a php coder, I figure this stuff out by pure accident at times! Test and install at your own risk (but it seems to work for me).

Note: If you modify your UBB.Threads code, you may be giving up your right for "official" support from Infopop. If you need official support, you'll need to restore unmodified files.


Attached File
120365-pme.zip  (274 downloads)
Posted By: Medar Re: Beta-[6.5] Private Message Enhancement 1.0 - 09/24/2004 10:13 PM
FYI I hacked this out last night, and it was rather late. So if there are any small bugs, definitely let me know, as I will continue to use this, my forum members already love it.

Here is an example image:

Attached picture 120366-pme_examp.png
Nice, adding this to my list.
I added it. Took about 30 minutes to install. The directions were perfect. This is certainly one of the top mods Ive seen and used

Thanks for this mod Medar!
Posted By: Anno Re: Beta-[6.5] Private Message Enhancement 1.0 - 09/25/2004 10:49 AM
What is the purpose of Saved messages?
Posted By: Medar Re: Beta-[6.5] Private Message Enhancement 1.0 - 09/26/2004 7:29 PM
Anno - sometimes you have a message you want to hold onto for a few days, or separate from the mess of other messages, or various reasons.

I didn't say it would be useful for a lot of people, it was just something I wanted, so I figured I would share!
Giving it a try, I notice...

a) I see a limit on the PMs being displayed; but there isn't anything that actually limits the users number of PM's, right?
b) No instructions to add the $config['tital_pm'] variable to the config file.
c) There are three $i = 1;'s in viewmessages.php (only one would be needed, I would think)
d) The group of excessive SELECT fields seems unnecessary when all you are doing is a numrows.
Posted By: Medar Re: Beta-[6.5] Private Message Enhancement 1.0 - 09/27/2004 7:45 PM
Thanks for the heads up on some of this...but one or two questions.

a) No, there is nothing in here that limits the users number of Private Messages. This basically filters any PMs marked as "S" or "Y" (Saved or Saved/Replied) to a separate view.

b) $config['total_pm'] is part of 6.5 and is set in the control panel...I didn't add that, just used it.

c) Correct, the $i=1; were not needed, I removed them and updated. Thanks!

d) I have no idea how to query the filtered totals I am looking to grab by using just a Numrows, would I still not need to query each using a separate WHERE statement like I did? Would love to make this more efficient if possible, I just didn't know any other way.
Maybe 6.5 has a limit on the number of PMs; okay, I modded this down to my 6.4. The queries in (d) are okay by themselves although you don't need to select all those fields if you arent going to use them (might speed up the query?).
Posted By: Medar Re: Beta-[6.5] Private Message Enhancement 1.0 - 09/27/2004 10:43 PM
Good point on the fields - really I just need to select one or two for a proper count. Will fix that when I get home.

I meant to do that when I copied/pasted that original query, and then just forgot to be rid of the extraneous data.

Thanks!
In the box that has "Private message details", where would I go to add, "send a pm" so users dont have to go back to the main index to send a pm.
Posted By: Medar Re: Beta-[6.5] Private Message Enhancement 1.0 - 09/28/2004 3:54 PM
You could add that in your viewmessages.tmpl file.

And that is a good idea, I will probably replace the "total PMs" piece of that with a Send PM link, at least on my local version.

Thanks!
Word of warning, on larger sites the queries that count the number of messages will dramatically slow down the page and since they don't use the do_query function, they weren't being timed or counted:

Generated in 8.893 seconds in which 8.884 seconds were spent on a total of 11 queries.

There are three numrow calls to count messages; the second of which appears to be a near duplicate of the $pmsaved query; not sure but maybe this can be done only once. All three are near duplicates in themselves, only checking for different status codes.
Posted By: Medar Re: Beta-[6.5] Private Message Enhancement 1.0 - 10/28/2004 7:04 PM
I have never had a php class and do not write code for a living, so any suggestions on making this "better" or "correct" are greatly appreciated...so thanks for the heads up PhotoPost.

I have changed the three queries you are talking about to read as follows - they 'work' on my forums and are now counted and timed. Is there any better optimization that can be done on the below queries?

[]// ------------------------------
// Private Message Enhancement Start

// ---------------------------
// Grab total private messages
$query = "
SELECT COUNT(*)
FROM {$config['tbprefix']}Messages AS t1,
{$config['tbprefix']}Users AS t2
WHERE t1.M_Uid = '{$user['U_Number']}'
AND t1.M_Sender = t2.U_Number
";
$sth = $dbh -> do_query($query,__LINE__,__FILE__);
list($pmtotal) = $dbh -> fetch_array($sth);

// ---------------------------------
// Grab total saved private messages
$query = "
SELECT COUNT(*)
FROM {$config['tbprefix']}Messages AS t1,
{$config['tbprefix']}Users AS t2
WHERE t1.M_Uid = '{$user['U_Number']}'
AND t1.M_Sender = t2.U_Number
AND t1.M_Status IN ('S', 'Y')
";
$sth = $dbh -> do_query($query,__LINE__,__FILE__);
list($pmsaved) = $dbh -> fetch_array($sth);

// ---------------------------------
// Grab total sent private messages
$query = "
SELECT COUNT(*)
FROM {$config['tbprefix']}Messages AS t1,
{$config['tbprefix']}Users AS t2
WHERE t1.M_Uid = '{$user['U_Number']}'
AND t1.M_Sender = t2.U_Number
AND t1.M_Status = 'X'
";
$sth = $dbh -> do_query($query,__LINE__,__FILE__);
list($pmsent) = $dbh -> fetch_array($sth);

$pmrec = $pmtotal - $pmsaved - $pmsent;
$max_pm = $config['total_pm'];
$p_pm = (($pmtotal/$config['total_pm']) * 100);

// ----------------------------
// Private Message Enhancement End[/]
Any way you could test this again to see if it fixes the query timing issue? My forums only have 700+ members and do not get regularly hammered...
It has as much to do with the number of PMs as it does users. I had 4,000+ messages between the Saved, Received and Sent folders and got those horrible delays. When I just deleted all but a couple hundred, the speed was back to normal.

I have one user with 9,000 messages between the folders - his page has to be really slow.

If I get some time, I'll play around with it; but even one query instead of the three is going to have the same delay because its the first query that took 96% of the time.
Posted By: Medar Re: Beta-[6.5] Private Message Enhancement 1.0 - 10/28/2004 9:27 PM
That makes sense now, I guess in my limited use on larger boards I never dreamt of anyone having 9000+ PMs, or even 3 or 4k!

What I changed will mesh better with the threads code (ie its more compliant), but you are right, it won't make it any faster per se. The way Threads typically gets around this issue would be to add a couple of fields to the Users table that track the PM numbers.

The downside is that these would need to be constantly updated due to deletions and additions, but storing a hard number is really the only way around huge PM users having a delay.
Would it be possible to use this mod only for selected user groups?
Posted By: AKD96 Re: Beta-[6.5] Private Message Enhancement 1.0 - 11/08/2004 2:01 PM
Very
I've tried installing this on my 6.5.1 test site, and am having one problem with it. When I'm viewing a message, I can save it, and it'll be marked as saved properly. However, viewing things from viewmessages.php, if I check messages and then use the "Save Checked" button, the page just refreshes and clears the check marks, but doesn't actually save the message(s).
Posted By: Medar Re: Beta-[6.5] Private Message Enhancement 1.0 - 02/22/2005 10:34 PM
I have not installed 6.5.1 yet, and am not near ready to do so. It is still too buggy for my taste, and my 6.5 is actually working somewhat properly.

Will work on this as soon as I get a fixed 6.5.1 uploaded.
© UBB.Developers