PDA

View Full Version : [re-release vb2.0] Download PMs to file



bira
Thu 3rd May '01, 8:54am
Since I was asked to make this available, here's my hack for downloading Private Messages (as many as you select) at once into a local txt file.

This is helpful if you need to clear out your PM folder(s) due to quota limitation, but don't want to lose those messages.

In effect, it works like an e-mail RFC archive.

Installation Instructions:

1. Open private.php.

Find:



if ($delete!="") {
$what="delete";
}


Immediately AFTER it put:



if ($download!="") {
$what="download";
}


Find:



eval("standardredirect(\"".gettemplate("redirect_pmdelete")."\",\"private.php?s=$session[sessionhash]&folderid=$thisfolder\");");
}


Immediately AFTER it put:



if ($what=="download") {

if (is_array($privatemessage)) {
header("Content-disposition: filename=messages.txt");
header("Content-type: application/octetstream");
header("Pragma: no-cache");
header("Expires: 0");

while(list($key,$val)=each($privatemessage)) {
$downloads=$DB_site->query_first("SELECT touserid,fromuserid,dateline,title,message FROM privatemessage WHERE privatemessageid='$key' AND userid=$bbuserinfo[userid]");
$tousername=$DB_site->query_first("SELECT username FROM user WHERE userid='$downloads[touserid]'");
$fromusername=$DB_site->query_first("SELECT username FROM user WHERE userid='$downloads[fromuserid]'");
$msgdt = vbdate($dateformat,$downloads[dateline]);
$msgtm = vbdate($timeformat,$downloads[dateline]);
$wordwrap = wordwrap($downloads[message],75,"\r\n");

print("Date/Time Sent: $msgdt, $msgtm\r\n");
print("From: $fromusername[username]\r\n");
print("To: $tousername[username]\r\n");
print("Subject: $downloads[title]\r\n\r\n");
print("$wordwrap\r\n");
print("================================================== ========================\r\n\r\n\r\n");

} //end while

} else {
eval("standarderror(\"".gettemplate("error_pmnoselected")."\");");
exit;
}
}


Note for Foreign Users: replace the words 'Date/Time Sent', 'From', 'To', 'Subject' in the above code with whatever wording in your language that suits you.

Save file and upload.

2. Edit template privfolder.

Find:



$massforwardlink


Immediately after OR before it (it does not matter), put:



or <input type="submit" name="download" value="Download">


Note for Foreign Users: replace the word "or" and the value "Download" with whatever wording in your language that suits you.


That's it!

Usage: select one or more messages in one of your Private Messages folder and click on "Download". You will be prompted to save messages.txt on your hard drive (a Windows filename & folder selection dialogue will pop up).

Cheers,

Bira

bokhalifa
Thu 3rd May '01, 9:15am
good hack min;)

conan
Thu 3rd May '01, 2:12pm
Thanks a lot for the great hack!

poil11
Thu 3rd May '01, 3:08pm
Thanks for this great hack. i hope that you don't mind but i hacked it to work with wwwthreads. and i am going to use this in many many other things! good deal!

instead of it being message.txt i made that the subject of the post....

The_Sisko
Thu 3rd May '01, 7:43pm
This is what a lot of my Users asked for!!!
THANKS A LOT!

bira
Fri 4th May '01, 6:37am
thanks :D

Streicher
Fri 4th May '01, 10:23am
Very good hack. No problems to hack in vB.

smelialichu
Sat 12th May '01, 3:44pm
This is a great hack, just one problem though. When i click on download it displays the pm's in my browser and doesn't download it. i use IE 5.01 none of the other people on the board have reported the problem, ideas? I realise the problem is most likely at my end.

bira
Sat 12th May '01, 6:02pm
Originally posted by smelialichu
This is a great hack, just one problem though. When i click on download it displays the pm's in my browser and doesn't download it. i use IE 5.01 none of the other people on the board have reported the problem, ideas? I realise the problem is most likely at my end.

smelialichu, I'm not sure where to point you to, but it has to do with your system/browser setting. Instead of prompting you to choose between save file or open it, it goes right ahead and opens it without asking. I'm not sure how you solve that as I am not familiar with win32 registry stuff.

You might want to check in your security settings (Tool -> Internet Options) that Download is enabled (general download, that is). Not sure about anything else.

In any case, I'd recommend upgrading to IE 5.5, which is a much better, faster and less buggy browser.

Cheers,

bira

veedee
Mon 14th May '01, 8:29am
Great looking hack.

I run about 7 styles on my website, does this mean i have to hack the templates 7 times ?

~veedee

bira
Mon 14th May '01, 3:49pm
Originally posted by veedee
Great looking hack.

I run about 7 styles on my website, does this mean i have to hack the templates 7 times ?

~veedee

Do you actually have a different templateset for every style though?!?

Run a search in the Control Panel -> Templates for $massforwardlink. If you have more than one template with it, you can do a search/replace of



Search for: $massforwardlink
Replace with: $massforwardlinkor <input type="submit" name="download" value="Download">


At your peril though :)

veedee
Mon 14th May '01, 3:57pm
yeah different templates :)

will do what you told me, cheers me dear :)

smelialichu
Mon 14th May '01, 4:32pm
Abyone got any ideas on how to solve my prob? i got it so the filename includes the date. i can tell you how if anyone's interested, iy's fairly simple. In fact very simple

bira
Fri 18th May '01, 6:19pm
Actually, wordwrap() is a built-in function in PHP.

Perhaps, though, it's only in PHP4 or something.

slip
Sat 2nd Jun '01, 8:32pm
i installed everything exactly as it should be done, yet when i try to download some pm's, i just get a blank page (completely blank, no errors)

any help?

NORRITT
Mon 4th Jun '01, 1:46pm
Hi, if i click in the user cp on the link 'Private Messaging' I get just the following error messsage:

Parse error: parse error, expecting `T_STRING' or `T_VARIABLE' or `T_NUM_STRING' in e:\apache\apache\nsdocs\forum\private.php on line 695

Zarkov
Sat 9th Jun '01, 7:46am
restore private.php and see if that works then rehack.
You probably deleted a , or } or something. :)

See my hack based on this one to Email the selected PM's to the registered email address here
http://161.58.84.213/forum/showthread.php?s=&threadid=18991

NORRITT
Sat 9th Jun '01, 9:12am
I did it three times! :(

Zarkov
Sat 9th Jun '01, 9:46am
did it work OK when you re up the original file?

NORRITT
Sat 9th Jun '01, 12:13pm
yes

Zarkov
Sun 10th Jun '01, 6:56am
Then it must be something to do with the hack, either your doing something wrong or possibly your using PHP 3 and it maybe it doesnt work with 3 ( that is only a guess as i have never tried it on 3).

slip
Sun 10th Jun '01, 3:24pm
Originally posted by slip
i installed everything exactly as it should be done, yet when i try to download some pm's, i just get a blank page (completely blank, no errors)

any help?



can anyone help me?
I'm using PHP4 and I did everything like I should have..

Zarkov
Tue 12th Jun '01, 5:16am
What browser you using?

I found that the code in the hack worked in IE 5 but not 5.5, I had to do a little digging around,But i assume its to do with http versions, IE 5 being http 1.0 complient and 5.5 being http 1.1 compliant.

I did work out and get it to work in IE.5.5 and netscape 4.7, but at the moment im at work and dont have access to the code, but ill post the changes later for anyone to use.

Please note that from mmy playing you can have it work in IE 5 or 5.5 but not both

slip
Tue 12th Jun '01, 11:30am
yup, i'm running IE 5.5

those code modifications that you did would be GREATLY appreciated..

Zarkov
Tue 12th Jun '01, 7:09pm
OK look for this code in private.php


if (is_array($privatemessage)) {
header("Content-type: application/octet-stream");
header("Content-disposition: attachment; filename=messages.txt");
header("Pragma: no-cache");
header("Expires: 0");

and replace it with


if (is_array($privatemessage)) {
header("Content-disposition: attachment; filename=messages.txt");
header("Content-type: uknown/unknown");
header("Pragma: no-cache");
header("Expires: 0");


Dont forget to change the filename=messages.txt to what ever you want to call the downloaded file.

Axel Foley
Sat 16th Jun '01, 10:00pm
Bira, first of all GREAT HACK! ;)

For Zarkov & Norritt & Slip & Bira :rolleyes: :

I had the same error as Norritt (Parse error: parse error, expecting `T_STRING' or `T_VARIABLE' or `T_NUM_STRING' in e:\apache\apache\nsdocs\forum\private.php on line 695), and it wasn't my fault, after a while I found out the error. I had to modify the last EVAL() in this way:



// Original code by Bira
eval("standarderror(\"".gettemplate("error_pmnoselected")."");");
exit;
}

// My modification
eval("standarderror(\"".gettemplate("error_pmnoselected")."\");");
exit;
}


One other thing: I use IE 5.5 and the hack works greatly without applying Zarkov's modifications.