############################################################################### # InstantMessage.pl # ############################################################################### # YaBB: Yet another Bulletin Board # # Open-Source Community Software for Webmasters # # Version: YaBB 2.4 # # Packaged: April 12, 2009 # # Distributed by: http://www.yabbforum.com # # =========================================================================== # # Copyright (c) 2000-2009 YaBB (www.yabbforum.com) - All Rights Reserved. # # Software by: The YaBB Development Team # # with assistance from the YaBB community. # # Sponsored by: Xnull Internet Media, Inc. - http://www.ximinc.com # # Your source for web hosting, web design, and domains. # ############################################################################### $instantmessageplver = 'YaBB 2.4 $Revision$'; if ($GLOBAL::ACTION eq 'detailedversion') { return 1; } ## create the send IM section of the screen #### # new format: for msg file: #messageid|(from)user|(touser(s))|(ccuser(s))|(bccuser(s))| # subject|date|message|(parentmid)|reply#|ip|messagestatus| # flags|storefolder|attachment # (optional) [placeholder] # for outbox: #messageid|(from)user|(touser(s))|(ccuser(s))|(bccuser(s))| # subject|date|message|(parentmid)|reply#|ip|messagestatus| # flags|storefolder|attachment ## messagestatus = c(onfidential)/h(igh importance)/s(tandard)/a(lert)/g(uest)/(b)roadcast/(n)otify of post ## flags = u(nread)/f(orward)/q(oute)/r(eply)/c(alled back) ## parentmid = stays same ## reply# = increments for replies, so we can build conversation threads ## storefolder = name of storage folder. Start with in & out for everyone. #1 $mnum = 3; #2 $imnewcount = 0; #3 $moutnum = 17; #4 $storenum = 0; #5 $draftnum = 0; #6 @folders (name1|name2|name3) # MF-B: new .ims file format # ### YaBB UserIMS ### # '${$username}{'PMmnum'}',"value" # '${$username}{'PMimnewcount'}',"value" # '${$username}{'PMmoutnum'}',"value" # '${$username}{'PMstorenum'}',"value" # '${$username}{'PMdraftnum'}',"value" # '${$username}{'PMfolders'}',"value" # '${$username}{'PMfoldersCount'}',"value" # @storecurrentin = qw/ /; # list of messages in .imstore from msg # @storecurrentout = qw/ /; # list of messages in .imstore from outbox sub buildIMsend { &LoadLanguage('InstantMessage'); &LoadLanguage('Post'); &LoadCensorList; if ($FORM{'previewim'}) { require "$sourcedir/Post.pl"; if (!$error){ &Preview; $subject = $csubject; } else { &Preview($error); } &FromHTML($message); &FromHTML($subject); } $mctitle = $inmes_txt{'775'}; ## check for a draft being opened if ($INFO{'caller'} == 4 && $INFO{'id'}) { my @draftPM = &read_DBorFILE(0,'',$memberdir,$username,'imdraft'); chomp(@draftPM); my $flagfound; foreach my $draftMess (@draftPM) { my ($checkId, undef) = split(/\|/, $draftMess, 2); if ($checkId eq $INFO{'id'}){ ($dmessageid, $dmusername, $userto, $usernamecc, $usernamebcc, $subject, $dmdate, $message, $dmpmessageid, $dmreplyno, $dmips, $dmessageStatus, $dmessageFlags, $dstoreFolder, $dmessageAttachment) = split(/\|/, $draftMess); $flagfound = 1; last; } } if (!$flagfound) { &fatal_error('cannot_find_draftmess'); } &FromHTML($message); &FromHTML($subject); } my $pmicon = 'standard'; $stselect = ''; $urselect = ''; $cnselect = ''; if ($FORM{'status'} || $INFO{'status'}) { $thestatus = $FORM{'status'} || $INFO{'status'}; } elsif ($dmessageStatus){ $thestatus = $dmessageStatus; } else { $thestatus = 's'; } if ($thestatus eq 's') { $stselect = qq~ selected="selected"~; } elsif ($thestatus eq 'u') { $urselect = qq~ selected="selected"~; } elsif ($thestatus eq 'c') { $cnselect = qq~ selected="selected"~; } elsif ($thestatus eq 'sb') { $stselect = qq~ selected="selected"~; $sendBMess = 1; } elsif ($thestatus eq 'ub') { $urselect = qq~ selected="selected"~; $sendBMess = 1; } elsif ($thestatus eq 'cb') { $cnselect = qq~ selected="selected"~; $sendBMess = 1; } $sendBMess = 0 unless $sendBMess == 1 && (($PMenableBm_level == 1 && $staff) || ($PMenableBm_level == 2 && ($iamadmin || $iamgmod)) || ($PMenableBm_level == 3 && $iamadmin)); ########## post code ######### if (!$staff && ${$uid.$username}{'postcount'} < $numposts) { &fatal_error('im_low_postcount'); } if (!$replyguest) { if ($is_preview) { $post_txt{'507'} = $post_txt{'771'}; } $normalquot = $post_txt{'599'}; $simpelquot = $post_txt{'601'}; $simpelcode = $post_txt{'602'}; $edittext = $post_txt{'603'}; if (!$fontsizemax) { $fontsizemax = 72; } if (!$fontsizemin) { $fontsizemin = 6; } # this defines what the top area of the post box will look like: ## if this is a reply , load the 'from' name off the message if ($INFO{'reply'} || $INFO{'quote'}) { $INFO{'to'} = $mfrom; } if (!$INFO{'to'} && $FORM{'to'} ne '') { $INFO{'to'} = $FORM{'to'}; } ## if cloaking is enabled, and 'to' is not a blank if ($do_scramble_id && $INFO{'to'} ne '') { &decloak($INFO{'to'}); } if (!$sendBMess) { &LoadUser($INFO{'to'}); } } $message =~ s~~\n~gi; $message =~ s/ / /g; &ToChars($message); $message = &Censor($message); &ToHTML($message); $message =~ s/      /\t/ig; if ($msubject) { $subject = $msubject; } &ToChars($subject); $subject = &Censor($subject); &ToHTML($subject); if ($action eq "modify" || $action eq "modify2") { $displayname = qq~$mename~; } else { $displayname = ${$uid.$username}{'realname'}; } require "$sourcedir/ContextHelp.pl"; &ContextScript("post"); $MCGlobalFormStart .= qq~ $ctmain ~; if ($prevmain && !$replyguest) { $imsend .= qq~ $prevmain ~; } if (((!$enable_PMcontrols && $enable_PMActprev) || ($enable_PMcontrols && ${$uid.$username}{'pmactprev'})) && !$replyguest) { $imsend .= qq~
$npf_txt{'01'} $npf_txt{'04'}
~; } if ($replyguest) { $imsend .= qq~ $guest_reply{'guesttext'} ~; } $imsend .= qq~ ~; if (!$replyguest && !$sendBMess && ($PMenable_cc || $PMenable_bcc)) { $yyjavascripttoform = qq~ ~; $imsend .= qq~$yyjavascripttoform ~; } $imsend .= qq~
\n~; # now uses a multi-line select &ProcIMrecs; $toname = $INFO{'forward'} ? '' : $INFO{'to'}; my $toUsersTitle = $inmes_txt{'torecepients'}; my ($onchangeText, $onchangeText2); if (((!$enable_PMcontrols && $enable_PMActprev) || ($enable_PMcontrols && ${$uid.$username}{'pmactprev'})) && !$replyguest) { $onchangeText = qq~ onkeyup="updatTopic();"~; $onchangeText2 = qq~ updatTopic();~; } if (!$replyguest) { if ($sendBMess) { $toUsersTitle = $inmes_txt{'togroups'}; } if ($PMenable_cc || $PMenable_bcc) { $us_winhight = 370; } else { $us_winhight = 345; } my $toIdtext = $sendBMess ? 'groups' : 'toshow'; $imsend .= qq~
$inmes_txt{'324'} $toUsersTitle: $inmes_txt{'clickto1'} $inmes_txt{'324'} $toUsersTitle $inmes_txt{'clickto2'}
~; $JSandInput = qq~ ~; $imsend .= qq~

$im_message_status{'$pmicon'}
~; } else { $imsend .= qq~ $inmes_txt{'324'} $toUsersTitle:   $post_txt{'69'}:   ~; } $subtitle = "$subject"; #this is the end of the upper area of the post page. # this declares the beginning of the UBBC section $JSandInput .= qq~ ~; $JSandInput .= qq~ ~; if ($FORM{'draftid'} || $INFO{'caller'} == 4) { $JSandInput .= qq~~; } $imsend .= qq~ $JSandInput
~; # this is for the ubbc buttons if (!$replyguest) { if ($enable_ubbc && $showyabbcbutt) { $imsend .= qq~$post_txt{'252'}:
                       
~; } } if ($replyguest) { $tmpmtext =qq~$post_txt{'72'}: ~; } # set size of messagebox and text if (!${$uid.$username}{'postlayout'}) { $pheight = 130; $pwidth = 425; $textsize = 10; } else { ($pheight, $pwidth, $textsize, $col_row) = split(/\|/, ${$uid.$username}{'postlayout'}); } if(!$textsize || $textsize < 6) { $textsize = 6; } if($textsize > 16) { $textsize = 16; } if($pheight > 400) { $pheight = 400; } if($pheight < 130) { $pheight = 130; } if($pwidth > 855) { $pwidth = 855; } if($pwidth < 425) { $pwidth = 425; } $mtextsize = $textsize . "pt"; $mheight = $pheight . "px"; $mwidth = $pwidth . "px"; $dheight = ($pheight + 12) . "px"; $dwidth = ($pwidth + 12) . "px"; $jsdragwpos = $pwidth - 425; $dragwpos = ($pwidth - 425) . "px"; $jsdraghpos = $pheight - 130; $draghpos = ($pheight - 130) . "px"; $imsend .= qq~
resize_wb
resize_hb
$npf_txt{'03'}
$post_txt{'textsize'} pt
~; if ($img_greybox) { $yyinlinestyle .= qq~\n~; $yyjavascript .= qq~ var GB_ROOT_DIR = "$yyhtml_root/greybox/"; // --> \n~; if (($showadded == 3 && $showsmdir != 2) || ($showsmdir == 3 && $showadded != 2)) { $imsend .= qq~ $post_smiltxt{'1'}~; } # SpellChecker start if ($enable_spell_check) { $yyinlinestyle .= qq~ ~; my $userdefaultlang = (split(/-/, $abbr_lang))[0]; $userdefaultlang ||= 'en'; $imsend .= qq~ ~; } # SpellChecker end $imsend .= qq~ ~; } $imsend .= qq~ ~; if ($INFO{'quote'} || $INFO{'reply'} || $FORM{'reply'}) { # if this is a reply, need to pass the reply # forward $imsend .= qq~ ~; } if (!$replyguest) { $imsend .= qq~
~; if ($FORM{'draftid'} || $INFO{'caller'} == 4) { $imsend .= qq~ $post_txt{'draftleave'}
~; } $imsend .= qq~
~; } $imsend .= qq~ ~; #these are the buttons to submit my $sendBMessFlag; if ($sendBMess || $isBMess) { $sendBMessFlag = qq~~; } $imsend .= qq~ $hidestatus $sendBMessFlag
~; if ($speedpostdetection) { $imsend .= qq~ ~; } my %accesskey; if (!$replyguest) { $imsend .= qq~      ~; $accesskey{'MSIE_Safari'} = $post_txt{'329b'}; $accesskey{'FireFox'} = $post_txt{'330b'}; $accesskey{'Browsers_on_Mac'} = $post_txt{'331b'}; if ((!$enable_PMcontrols && $enable_PMprev) || ($enable_PMcontrols && ${$uid.$username}{'pmmessprev'})) { $imsend .= qq~      ~; $accesskey{'MSIE_Safari'} = $post_txt{'329c'}; $accesskey{'FireFox'} = $post_txt{'330c'}; $accesskey{'Browsers_on_Mac'} = $post_txt{'331c'}; } } $smilie_url_array = ""; $smilie_code_array = ""; $i = 0; if ($showadded eq 2) { while ($SmilieURL[$i]) { if ($SmilieURL[$i] =~ /\//i) { $tmpurl = $SmilieURL[$i]; } else { $tmpurl = qq~$defaultimagesdir/$SmilieURL[$i]~; } $smilie_url_array .= qq~"$tmpurl", ~; $tmpcode = $SmilieCode[$i]; $tmpcode =~ s/\"/"+'"'+"/g; # "' &FromHTML($tmpcode); $tmpcode =~ s/$/\$/g; $tmpcode =~ s/@/\@/g; $smilie_code_array .= qq~" $tmpcode", ~; $i++; } } if ($showsmdir eq 2) { opendir(DIR, "$smiliesdir"); @contents = readdir(DIR); closedir(DIR); foreach $line (sort { uc($a) cmp uc($b) } @contents) { ($name, $extension) = split(/\./, $line); if ($extension =~ /gif/i || $extension =~ /jpg/i || $extension =~ /jpeg/i || $extension =~ /png/i) { if ($line !~ /banner/i) { $smilie_url_array .= qq~"$smiliesurl/$line", ~; $smilie_code_array .= qq~" [smiley=$line]", ~; $i++; } } } } $imsend .= qq~

\n~; require "$templatesdir/$usedisplay/Display.template"; foreach (@months) { $jsmonths .= qq~'$_',~; } $jsmonths =~ s~\,\Z~~; $jstimeselected = ${$uid.$username}{'timeselect'} || $timeselected; ########## end post code } ## process and send the IM to whomever sub IMsendMessage { # This is only for update, when comming from YaBB lower or equal version 2.2.3 # I think it can be deleted around version 2.4.0 without causing mayor issues (deti). if ($enable_notifications eq '') { $enable_notifications = $enable_notification ? 3 : 0; } # End update workaround &LoadLanguage('Post'); &LoadLanguage('InstantMessage'); ## load error strings &LoadLanguage('Error'); ## sorry - no guests if ($iamguest) { &fatal_error("im_members_only"); } my (@ignore, $igname, $messageid, $subject, $message, @recipient, $ignored); $isBMess = $FORM{'isBMess'}; # set size of messagebox and text ${$uid.$username}{'postlayout'} = qq~$FORM{'messageheight'}|$FORM{'messagewidth'}|$FORM{'txtsize'}|$FORM{'col_row'}~; # receipts for IM are now handled by "toshow" only, so we need to switch to the right # test for no recipient. also switch on flag to stop us going back to the form all the time # if there is only the one (intended) recipient, 'to' must contain the name if ((!$FORM{'toshow'} && !$INFO{'to'}) && !$FORM{'draft'}) { $error = $error_txt{'no_recipient'}; } $toshow = $FORM{'toshow'} || $INFO{'to'}; # if there are several intended - can be one of course ;) $subject = $FORM{'subject'}; $subject =~ s/^\s+|\s+$//g; $message = $FORM{'message'}; $message =~ s/^\s+|\s+$//g; # no subject/no message are bad! $error = $error_txt{'no_subject'} if !$subject; $error = $error_txt{'no_message'} if !$message; &FromChars($subject); &FromChars($message); &ToHTML($subject); &ToHTML($message); # manage line returns and tabs $subject =~ s/\s+/ /g; $message =~ s~\n~
~g; $message =~ s~\t~ \  \  \ ~g; # Check Length $convertstr = $subject; $convertcut = $set_subjectMaxLength + ($subject =~ /^Re: / ? 4 : 0); &CountChars; $subject = $convertstr; $convertstr = $message; $convertcut = $MaxMessLen; &CountChars; if ($cliped) { $error = "$inmes_txt{'536'} " . (length($message) - length($convertstr)) . " $inmes_txt{'537'}"; } $message = $convertstr; if ($FORM{'ns'} eq 'NS') { $message .= "#nosmileys"; } if ($error) { $IM_box = $inmes_txt{'148'}; $FORM{'previewim'} = 1; &IMPost; &buildIMsend; return; } &ProcIMrecs; # no need to check for spam if its a broadcast, as this only creates the one post if (!$iamadmin && !$isBMess && $imspam && @allto * 100 / $members_total > $imspam) { &fatal_error("im_spam_alert"); } # go through each member in list # add to each msg (inbox) but only one to outbox # Create unique Message ID $messageid = &getnewid; $actlang = $language; my $UserTo; if (!$FORM{'draft'} && !$isBMess && !$replyguest) { foreach $UserTo (@allto) { $addnr++; chomp $UserTo; my($status, $UserTo) = split(/:/, $UserTo); my $ignored = 0; $UserTo =~ s/\A\s+//; $UserTo =~ s/\s+\Z//; $UserTo =~ s/[^0-9A-Za-z#%+,-\.@^_]//g; # Check Ignore-List, unless sender is FA &LoadUser($UserTo); if (!$isBMess) { if (${$uid.$UserTo}{'im_ignorelist'} && !$iamadmin && !$iamgmod) { # Build Ignore-List @ignore = split(/\|/, ${$uid.$UserTo}{'im_ignorelist'}); # If User is on Recipient's Ignore-List, show Error Message foreach $igname (@ignore) { # adds ignored user's name to array which error list will be built from later chomp $igname; if ($igname eq $username) { push(@nouser, $UserTo); $ignored = 1; } if ($igname eq '*') { push(@nouser, "$inmes_txt{'761'} $UserTo $inmes_txt{'762'};"); $ignored = 1; } } } } ## check and see if 1) username is marked 'away' 2) they left a message 3) you haven't already had an auto-reply my $sendAutoReply = 1; if (${$uid.$UserTo}{'offlinestatus'} eq 'away' && ${$uid.$UserTo}{'awayreply'} ne '' && ${$uid.$UserTo}{'awaysubj'} ne '') { if (${$uid.$UserTo}{'awayreplysent'} eq '') { ${$uid.$UserTo}{'awayreplysent'} = $username; &UserAccount($UserTo, 'update'); } else { foreach my $replyListName (split(/,/ ,${$uid.$UserTo}{'awayreplysent'})) { if ($replyListName eq $username) { $sendAutoReply = 0; last; } } if ($sendAutoReply) { ${$uid.$UserTo}{'awayreplysent'} .= qq~,$username~; &UserAccount($UserTo, 'update'); } } } else { $sendAutoReply = 0; } if (!&checkfor_DBorFILE("$memberdir/$UserTo.vars")) { # adds invalid user's name to array which error list will be built from later push(@nouser, $UserTo); $ignored = 1; } if (!$ignored) { # Send message to user my @inmessages = &read_DBorFILE(0,'',$memberdir,$UserTo,'msg'); &write_DBorFILE(${$uid.$UserTo}{'mysql'},'',$memberdir,$UserTo,'msg',("$messageid|$username|$FORM{'toshow'}|$FORM{'toshowcc'}|$FORM{'toshowbcc'}|$subject|$date|$message|$messageid|0|$ENV{'REMOTE_ADDR'}|$FORM{'status'}|u||\n", @inmessages)); # we've added the msg to the inbox, now update the ims file &updateIMS($UserTo, $messageid, 'messagein'); ## if we need to drop the 'away' reply in.... if ($sendAutoReply) { my $rmessageid = &getnewid; @inmessages = &read_DBorFILE(0,'',$memberdir,$username,'msg'); &write_DBorFILE(${$uid.$username}{'mysql'},'',$memberdir,$username,'msg',("$rmessageid|$UserTo|$username|||${$uid.$UserTo}{'awaysubj'}|$date|${$uid.$UserTo}{'awayreply'}|$messageid|1|$ENV{'REMOTE_ADDR'}|s|u||\n", @inmessages)); } ## relocated sender's msg out of the loop # Send notification (Will only work if Admin has allowed the Email Notification) if (${$uid.$UserTo}{'notify_me'} > 1 && $enable_notifications > 1) { require "$sourcedir/Mailer.pl"; $language = ${$uid.$UserTo}{'language'}; &LoadLanguage('Email'); &LoadLanguage('Notify'); $useremail = ${$uid.$UserTo}{'email'}; $useremail =~ s/[\n\r]//g; if ($useremail ne '') { my $msubject = $subject ? $subject : $inmes_txt{'767'}; $fromname = ${$uid.$username}{'realname'}; &FromHTML($msubject); &ToChars($msubject); my $chmessage = $message; &FromHTML($chmessage); &ToChars($chmessage); $chmessage =~ s~~\n~gi; $chmessage =~ s~\[b\](.*?)\[/b\]~*$1*~isg; $chmessage =~ s~\[i\](.*?)\[/i\]~/$1/~isg; $chmessage =~ s~\[u\](.*?)\[/u\]~_$1_~isg; $chmessage =~ s~\[.*?\]~~g; &sendmail($useremail, $notify_txt{'145'}, &template_email($privatemessagenotificationemail, {'sender' => $fromname, 'subject' => $msubject, 'message' => $chmessage}), '', $emailcharset); } } } #end add PM to outbox } #end foreach loop if ($#allto == $#nouser) { my $badusers; foreach my $baduser (@nouser) { &LoadUser($baduser); $badusers .= qq~${$uid.$baduser}{'realname'}, ~; } $badusers =~ s/, \Z//; &fatal_error('im_bad_users', $badusers); } } ## moved sender's reply marker here, open the sender's inbox and mark 'replied' if (!$FORM{'draft'} && $isBMess) { &write_DBorFILE(0,'',$memberdir,'broadcast','messages',("$messageid|$username|$FORM{'toshow'}|||$subject|$date|$message|$messageid|0|$ENV{'REMOTE_ADDR'}|$FORM{'status'}b|u||\n",&read_DBorFILE(1,'',$memberdir,'broadcast','messages'))); } if ($FORM{'reply'} && $FORM{'info'}) { # mark msg replied &updateMessageFlag($username, $FORM{'info'}, 'msg', '', 'r'); } ## this now outside the foreach, to allow just one write in the outbox # Add message to outbox, read outbox my $savetofile = 'outbox'; if ($FORM{'draft'}) { $savetofile = 'imdraft'; } @outmessages = &read_DBorFILE(0,'',$memberdir,$username,$savetofile); # add the PM to the outbox # the sep users now live together my $messFlag = ''; if ($isBMess) { $messFlag = 'b'; } if ($replyguest) { $messFlag = 'gr'; $FORM{'toguest'} =~ s/ /%20/g; $FORM{'toshow'} = $FORM{'toguest'} . ' ' . $FORM{'guestemail'}; $FORM{'toshow'} =~ s/[\n\r]//g; $FORM{'guestemail'} =~ s/[\n\r]//g; $fromname = ${$uid.$username}{'realname'}; my $msubject = $subject; &FromHTML($msubject); &ToChars($msubject); $chmessage = $message; &FromHTML($chmessage); &ToChars($chmessage); $chmessage =~ s~~\n~gi; $chmessage =~ s~\[b\](.*?)\[/b\]~*$1*~isg; $chmessage =~ s~\[i\](.*?)\[/i\]~/$1/~isg; $chmessage =~ s~\[u\](.*?)\[/u\]~_$1_~isg; $chmessage =~ s~\[.*?\]~~g; $chmessage =~ s/\r(?=\n*)//g; require "$sourcedir/Mailer.pl"; &sendmail($FORM{'guestemail'}, $msubject, $chmessage, ${$uid.$username}{'email'}); } if (!$FORM{'dontstoreinoutbox'} || $FORM{'draft'}) { ## all but drafts being resaved just get added to their file if (!$FORM{'draft'} || ($FORM{'draft'} && !$FORM{'draftid'})) { &write_DBorFILE(${$uid.$username}{'mysql'},'',$memberdir,$username,$savetofile,("$messageid|$username|$FORM{'toshow'}|$FORM{'toshowcc'}|$FORM{'toshowbcc'}|$subject|$date|$message|$messageid|$FORM{'reply'}|$ENV{'REMOTE_ADDR'}|$FORM{'status'}$messFlag|||\n",@outmessages)); } elsif ($FORM{'draft'} && $FORM{'draftid'}) { ## resaving draft - find draft message id and amend the entry my @new_outmessages; foreach (@outmessages) { if ((split /\|/, $_, 2)[0] != $FORM{'draftid'}) { push(@new_outmessages, $_); } else { push(@new_outmessages, "$messageid|$username|$FORM{'toshow'}|$FORM{'toshowcc'}|$FORM{'toshowbcc'}|$subject|$date|$message|$messageid|$FORM{'reply'}|$ENV{'REMOTE_ADDR'}|$FORM{'status'}$messFlag|||\n"); } } &write_DBorFILE(${$uid.$username}{'mysql'},'',$memberdir,$username,$savetofile,@new_outmessages); } ## pdate ims for sent if (!$FORM{'draft'}) { &updateIMS($username, $messageid, 'messageout'); } elsif (!$FORM{'draftid'}) { &updateIMS($username, $messageid, 'draftadd'); } } ## if this is a draft being sent, remove it from the draft file if ($FORM{'draftid'} && $FORM{'draft'} ne $inmes_txt{'savedraft'}) { &updateIMS($username, $messageid, 'draftsend'); my @draftPM; foreach my $draftmess (&read_DBorFILE(0,'',$memberdir,$username,'imdraft')) { chomp $draftmess; if ((split /\|/, $draftmess)[0] != $FORM{'draftid'}) { push(@draftPM, "$draftmess\n"); } elsif ($FORM{'draftleave'}) { push(@draftPM, "$messageid|$username|$FORM{'toshow'}|$FORM{'toshowcc'}|$FORM{'toshowbcc'}|$subject|$date|$message|$messageid|$FORM{'reply'}|$ENV{'REMOTE_ADDR'}|$FORM{'status'}$messFlag|||\n"); } } &write_DBorFILE(${$uid.$username}{'mysql'},'',$memberdir,$username,'imdraft',@draftPM); } # invalid users #if there were invalid usernames in the recipient list, these names are listed after all valid users have been IMed if (!$FORM{'draft'}) { if (@nouser) { my $badusers; foreach my $baduser (@nouser) { &LoadUser($baduser); $badusers .= qq~${$uid.$baduser}{'realname'}, ~; } $badusers =~ s/, \Z//; &fatal_error('im_bad_users', $badusers); } } ## saving a draft doesn't count as sending if (!$FORM{'draft'}) { &UserAccount($username, 'update', 'lastim+lastonline'); } else { &UserAccount($username, 'update', 'lastonline'); } if ($FORM{'dontstoreinoutbox'}) { $yySetLocation = qq~$scripturl?action=im~; } elsif ($FORM{'draft'}) { $yySetLocation = qq~$scripturl?action=imdraft~; } else { $yySetLocation = qq~$scripturl?action=imoutbox~; } &redirectexit; } ## process the to/cc/bcc lists sub ProcIMrecs { $FORM{'toshow'} =~ s/ //g; if (!$isBMess) { my $multiUser; my $countMulti = 0; @multiple = split(/,/, $FORM{'toshow'}); if ($do_scramble_id) { foreach $multiUser (@multiple) { $multiple[$countMulti] = &decloak($multiUser); $countMulti++; } } push(@allto, split(/,/, ("to:" . join(',to:', @multiple)))); $FORM{'toshow'} = join(',', @multiple); $FORM{'toshowcc'} =~ s/ //g; $FORM{'toshowbcc'} =~ s/ //g; if ($FORM{'toshowcc'}) { @multiplecc = split(/,/, $FORM{'toshowcc'}); if ($do_scramble_id) { $countMulti = 0; foreach $multiUser (@multiplecc) { $multiplecc[$countMulti] = &decloak($multiUser); $countMulti++; } } push(@allto, split(/,/, ("cc:" . join(',cc:', @multiplecc)))); $FORM{'toshowcc'} = join(',', @multiplecc); } if ($FORM{'toshowbcc'}) { @multiplebcc = split(/,/, $FORM{'toshowbcc'}); if ($do_scramble_id) { $countMulti = 0; foreach $multiUser (@multiplebcc) { $multiplebcc[$countMulti] = &decloak($multiUser); $countMulti++; } } push(@allto, split(/,/, ("bcc:" . join(',bcc:', @multiplebcc)))); $FORM{'toshowbcc'} = join(',', @multiplebcc); } } } sub pageLinksList { # Build the page links list. $maxmessagedisplay ||= 10; my $userthreadpage = (split /\|/, ${$uid.$username}{'pageindex'})[3]; my ($pagetxtindex, $pagetextindex, $pagedropindex1, $pagedropindex2, $all, $allselected, $bmesslink); $postdisplaynum = 3; # max number of pages to display $dropdisplaynum = 10; $startpage = 0; if ($INFO{'viewfolder'} ne '') { $viewfolderinfo = qq~;viewfolder=$INFO{'viewfolder'}~; } if ($INFO{'focus'} eq 'bmess') { $bmesslink = qq~;focus=bmess~;} my @tempim = @dimmessages; if ($GLOBAL::ACTION eq 'imstorage') { my $i = 0; foreach (@dimmessages) { if ((split(/\|/, $_))[13] ne $INFO{'viewfolder'}) { splice(@tempim,$i,1); next; } $i++; } } $max = $#tempim + 1; if ($INFO{'start'} eq "all") { $maxmessagedisplay = $max; $all = 1; $allselected = qq~ selected="selected"~; $start = 0; } else { $start = $INFO{'start'} || 0; } $start = $start > $#tempim ? $#tempim : $start; $start = (int($start / $maxmessagedisplay)) * $maxmessagedisplay; $tmpa = 1; $pagenumb = int(($max - 1) / $maxmessagedisplay) + 1; if ($start >= (($postdisplaynum - 1) * $maxmessagedisplay)) { $startpage = $start - (($postdisplaynum - 1) * $maxmessagedisplay); $tmpa = int($startpage / $maxmessagedisplay) + 1; } if ($max >= $start + ($postdisplaynum * $maxmessagedisplay)) { $endpage = $start + ($postdisplaynum * $maxmessagedisplay); } else { $endpage = $max; } $lastpn = int($#tempim / $maxmessagedisplay) + 1; $lastptn = ($lastpn - 1) * $maxmessagedisplay; $pageindex1 = qq~$display_txt{'19'} $display_txt{'139'}: $pagenumb~; if ($pagenumb > 1 || $all) { if ($userthreadpage == 1 ) { $pagetxtindexst = qq~~; $pagetxtindexst .= qq~$display_txt{'19'} $display_txt{'139'}: ~; if ($startpage > 0) { $pagetxtindex = qq~1 ... ~; } if ($startpage == $maxmessagedisplay) { $pagetxtindex = qq~1 ~; } for ($counter = $startpage; $counter < $endpage; $counter += $maxmessagedisplay) { $pagetxtindex .= $start == $counter ? qq~$tmpa ~ : qq~$tmpa ~; $tmpa++; } if ($endpage < $max - ($maxmessagedisplay)) { $pageindexadd = qq~... ~; } if ($endpage != $max) { $pageindexadd .= qq~$lastpn~; } $pagetxtindex .= qq~$pageindexadd~; $pageindex1 = qq~$pagetxtindexst$pagetxtindex~; $pageindex2 = $pageindex1; } else { $pagedropindex1 = qq~~; $pagedropindex1 .= qq~$display_txt{'19'}~; $pagedropindex2 = $pagedropindex1; $tstart = $start; if (substr($INFO{'start'}, 0, 3) eq "all") { ($tstart, $start) = split(/\-/, $INFO{'start'}); } $d_indexpages = $pagenumb / $dropdisplaynum; $i_indexpages = int($pagenumb / $dropdisplaynum); if ($d_indexpages > $i_indexpages) { $indexpages = int($pagenumb / $dropdisplaynum) + 1; } else { $indexpages = int($pagenumb / $dropdisplaynum) } $selectedindex = int(($start / $maxmessagedisplay) / $dropdisplaynum); if ($pagenumb > $dropdisplaynum) { $pagedropindex1 .= qq~\n~; } for ($i = 0; $i < $indexpages; $i++) { $indexpage = ($i * $dropdisplaynum) * $maxmessagedisplay; $indexstart = ($i * $dropdisplaynum) + 1; $indexend = $indexstart + ($dropdisplaynum - 1); if ($indexend > $pagenumb) { $indexend = $pagenumb; } if ($indexstart == $indexend) { $indxoption = qq~$indexstart~; } else { $indxoption = qq~$indexstart-$indexend~; } $selected = ""; if ($i == $selectedindex) { $selected = qq~ selected="selected"~; $pagejsindex = qq~$indexstart|$indexend|$maxmessagedisplay|$indexpage~; } if ($pagenumb > $dropdisplaynum) { $pagedropindex1 .= qq~\n~; $pagedropindex2 .= qq~\n~; } } if ($pagenumb > $dropdisplaynum) { $pagedropindex1 .= qq~\n~; $pagedropindex2 .= qq~\n~; } $pagedropindex1 .= qq~~; $pagedropindex2 .= qq~~; $tmpmaxmessagedisplay = $maxmessagedisplay; if (substr($INFO{'start'}, 0, 3) eq "all") { $maxmessagedisplay = $maxmessagedisplay * $dropdisplaynum; } $prevpage = $start - $tmpmaxmessagedisplay; $nextpage = $start + $maxmessagedisplay; $pagedropindexpvbl = qq~~; $pagedropindexnxbl = qq~~; if ($start < $maxmessagedisplay) { $pagedropindexpv .= qq~~; } else { $pagedropindexpv .= qq~$pidtxt{'02'}~; } if ($nextpage > $lastptn) { $pagedropindexnx .= qq~~; } else { $pagedropindexnx .= qq~$pidtxt{'03'}~; } $pageindex1 = qq~$pagedropindex1~; $pageindexjs = qq~ ~; } } } ## output one or all IM - detailed view sub DoShowIM { $messfound = 0; if ($callerid < 5) { &updateIMS($username, $_[0], 'inread'); } my ($showIM, $fromTitle, $toTitle, $toTitleCC, $toTitleBCC, $usernamelinkfrom, $usernamelinkto, $usernamelinkcc, $usernamelinkbcc, $userOnline, $prevMessId, $nextMessid, $PMnav); $messcount = 0; foreach my $messagesim (@dimmessages) { $nextMessid = $messageid; ($messageid, $musername, $mtousers, $mccusers, $mbccusers, $msub, $mdate, $immessage, $mpmessageid, $mreplyno, $imip, $mstatus, $mflags, $mstorefolder, $mattach) = split(/\|/, $messagesim); $messcount++; if ($messageid == $_[0]) { $messfound = 1; last; } } if (!$messfound) { my $redirect; if ($INFO{'caller'} == 1) { $redirect = 'im'; } elsif ($INFO{'caller'} == 2) { $redirect = 'imoutbox'; } elsif ($INFO{'caller'} == 3) { $redirect = 'imstorage'; } elsif ($INFO{'caller'} == 4) { $redirect = 'imdraft'; } elsif ($INFO{'caller'} == 5) { $redirect = 'im;focus=bmess'; } $yySetLocation = qq~$scripturl?action=$redirect~; &redirectexit; } ## if not at the end of the list, catch the 'previoous' id if ($messcount <= $#dimmessages){ ($prevMessId, undef) = split(/\|/, $dimmessages[$messcount]); } ## wrap the URL in if ($INFO{'id'} ne 'all' && $prevMessId ne '') { $previd = qq~« $inmes_imtxt{'40'}~; } if ($INFO{'id'} ne 'all' && $nextMessid ne '') { $nextid = qq~$inmes_imtxt{'41'} »~; } if ($INFO{'id'} ne 'all' && $#dimmessages > 0) { $allid = qq~$inmes_txt{'190'}~; } my $mydate = &timeformat($mdate); if ($INFO{'caller'} == 1) { if ($mtousers) { foreach my $uname (split(/,/, $mtousers)) { &LoadValidUserDisplay($uname); $usernamelinkto .= (${$uid.$uname}{'realname'} ? &CreateUserDisplayLine($uname) : ($uname ? qq~$uname ($maintxt{'470a'})~ : $maintxt{'470a'})) . ', '; # 470a == Ex-Member } $usernamelinkto =~ s/, $//; $toTitle = qq~$inmes_txt{'324'}:~; } if ($mccusers) { foreach my $uname (split(/,/, $mccusers)) { &LoadValidUserDisplay($uname); $usernamelinkcc .= (${$uid.$uname}{'realname'} ? &CreateUserDisplayLine($uname) : ($uname ? qq~$uname ($maintxt{'470a'})~ : $maintxt{'470a'})) . ', '; } $usernamelinkcc =~ s/, $//; $toTitleCC = qq~$inmes_txt{'325'}:~; } if ($mbccusers) { foreach my $uname (split(/,/, $mbccusers)) { if ($uname eq $username) { &LoadValidUserDisplay($uname); $usernamelinkbcc = ${$uid.$uname}{'realname'} ? &CreateUserDisplayLine($uname) : ($uname ? qq~$uname ($maintxt{'470a'})~ : $maintxt{'470a'}); } } if ($usernamelinkbcc) { $toTitleBCC = qq~$inmes_txt{'326'}:~; } } if ($mstatus eq 'g') { my ($guestName, $guestEmail) = split(/ /, $musername); $guestName =~ s/%20/ /g; $usernamelinkfrom = qq~$guestName ($guestEmail)~; } else { &LoadValidUserDisplay($musername); $usernamelinkfrom = ${$uid.$musername}{'realname'} ? &CreateUserDisplayLine($musername) : ($musername ? qq~$musername ($maintxt{'470a'})~ : $maintxt{'470a'}); # 470a == Ex-Member } $fromTitle = qq~$inmes_txt{'318'}:~; } elsif ($INFO{'caller'} == 2) { &LoadValidUserDisplay($musername); $usernamelinkfrom = ${$uid.$musername}{'realname'} ? &CreateUserDisplayLine($musername) : ($musername ? qq~$musername ($maintxt{'470a'})~ : $maintxt{'470a'}); # 470a == Ex-Member $fromTitle = qq~$inmes_txt{'318'}:~; if ($mstatus !~ /b/) { if ($mstatus !~ /gr/) { foreach my $uname (split(/,/, $mtousers)) { &LoadValidUserDisplay($uname); $usernamelinkto .= (${$uid.$uname}{'realname'} ? &CreateUserDisplayLine($uname) : ($uname ? qq~$uname ($maintxt{'470a'})~ : $maintxt{'470a'})) . ', '; # 470a == Ex-Member } } else { my ($guestName, $guestEmail) = split(/ /, $mtousers); $guestName =~ s/%20/ /g; $usernamelinkto = qq~$guestName ($guestEmail)~; } $toTitle = qq~$inmes_txt{'324'}:~; } else { foreach my $uname (split(/,/, $mtousers)) { if ($uname eq 'all') { $usernamelinkto .= qq~$inmes_txt{'bmallmembers'}~ . ', '; } elsif ($uname eq 'mods') { $usernamelinkto .= qq~$inmes_txt{'bmmods'}~ . ', '; } elsif ($uname eq 'gmods') { $usernamelinkto .= qq~$inmes_txt{'bmgmods'}~ . ', '; } elsif ($uname eq 'admins') { $usernamelinkto .= qq~$inmes_txt{'bmadmins'}~ . ', '; } else { my ($title, undef) = split(/\|/, $NoPost{$uname}, 2); $usernamelinkto .= qq~$title~ . ', '; } } $toTitle = qq~$inmes_txt{'324'} $inmes_txt{'327'}:~; } $usernamelinkto =~ s/, $//; if ($mccusers) { foreach my $uname (split(/,/, $mccusers)) { &LoadValidUserDisplay($uname); $usernamelinkcc .= (${$uid.$uname}{'realname'} ? &CreateUserDisplayLine($uname) : ($uname ? qq~$uname ($maintxt{'470a'})~ : $maintxt{'470a'})) . ', '; # 470a == Ex-Member } $usernamelinkcc =~ s/, $//; $toTitleCC = qq~$inmes_txt{'325'}:~; } if ($mbccusers) { foreach my $uname (split(/,/, $mbccusers)) { &LoadValidUserDisplay($uname); $usernamelinkbcc .= (${$uid.$uname}{'realname'} ? &CreateUserDisplayLine($uname) : ($uname ? qq~$uname ($maintxt{'470a'})~ : $maintxt{'470a'})) . ', '; # 470a == Ex-Member } $usernamelinkbcc =~ s/, $//; $toTitleBCC = qq~$inmes_txt{'326'}:~; } } elsif ($INFO{'caller'} == 3) { if ($mstatus !~ /b/) { if ($mstatus !~ /gr/) { foreach my $uname (split(/,/, $mtousers)) { &LoadValidUserDisplay($uname); $usernamelinkto .= (${$uid.$uname}{'realname'} ? &CreateUserDisplayLine($uname) : ($uname ? qq~$uname ($maintxt{'470a'})~ : $maintxt{'470a'})) . ', '; # 470a == Ex-Member } } else { my ($guestName, $guestEmail) = split(/ /, $mtousers); $guestName =~ s/%20/ /g; $usernamelinkto = qq~$guestName ($guestEmail)~; } $toTitle = qq~$inmes_txt{'324'}:~; if ($mccusers && $musername eq $username) { foreach my $uname (split(/,/, $mccusers)) { &LoadValidUserDisplay($uname); $usernamelinkcc .= (${$uid.$uname}{'realname'} ? &CreateUserDisplayLine($uname) : ($uname ? qq~$uname ($maintxt{'470a'})~ : $maintxt{'470a'})) . ', '; # 470a == Ex-Member } $usernamelinkcc =~ s/, $//; $toTitleCC = qq~$inmes_txt{'325'}:~; } if ($mbccusers && $musername eq $username) { foreach my $uname (split(/,/, $mbccusers)) { &LoadValidUserDisplay($uname); $usernamelinkbcc .= (${$uid.$uname}{'realname'} ? &CreateUserDisplayLine($uname) : ($uname ? qq~$uname ($maintxt{'470a'})~ : $maintxt{'470a'})) . ', '; # 470a == Ex-Member } $usernamelinkbcc =~ s/, $//; $toTitleBCC = qq~$inmes_txt{'326'}:~; } } else { foreach my $uname (split(/,/, $mtousers)) { if ($uname eq 'all') { $usernamelinkto .= qq~$inmes_txt{'bmallmembers'}~ . ', '; } elsif ($uname eq 'mods') { $usernamelinkto .= qq~$inmes_txt{'bmmods'}~ . ', '; } elsif ($uname eq 'gmods') { $usernamelinkto .= qq~$inmes_txt{'bmgmods'}~ . ', '; } elsif ($uname eq 'admins') { $usernamelinkto .= qq~$inmes_txt{'bmadmins'}~ . ', '; } else { my ($title, undef) = split(/\|/, $NoPost{$uname}, 2); $usernamelinkto .= qq~$title~ . ', '; } } $toTitle = qq~$inmes_txt{'324'} $inmes_txt{'327'}:~; } $usernamelinkto =~ s/, $//; if ($mstatus eq 'g') { my ($guestName, $guestEmail) = split(/ /, $musername); $guestName =~ s/%20/ /g; $usernamelinkfrom = qq~$guestName ($guestEmail)~; } else { &LoadValidUserDisplay($musername); $usernamelinkfrom = ${$uid.$musername}{'realname'} ? &CreateUserDisplayLine($musername) : ($musername ? qq~$musername ($maintxt{'470a'})~ : $maintxt{'470a'}); # 470a == Ex-Member } $fromTitle = qq~$inmes_txt{'318'}:~; } elsif ($INFO{'caller'} == 5 && $mstatus eq 'g') { my ($guestName, $guestEmail) = split(/ /, $musername); $guestName =~ s/%20/ /g; $usernamelinkfrom = qq~$guestName ($guestEmail)~; $fromTitle = qq~$inmes_txt{'318'}:~; } elsif ($INFO{'caller'} == 5 && $mstatus =~ /b/) { if ($mtousers) { foreach my $uname (split(/,/, $mtousers)) { if ($uname eq 'all') { $usernamelinkto .= qq~$inmes_txt{'bmallmembers'}~ . ', '; } elsif ($uname eq 'mods') { $usernamelinkto .= qq~$inmes_txt{'bmmods'}~ . ', '; } elsif ($uname eq 'gmods') { $usernamelinkto .= qq~$inmes_txt{'bmgmods'}~ . ', '; } elsif ($uname eq 'admins') { $usernamelinkto .= qq~$inmes_txt{'bmadmins'}~ . ', '; } else { my ($title, undef) = split(/\|/, $NoPost{$uname}, 2); $usernamelinkto .= qq~$title~ . ', '; } } $usernamelinkto =~ s/, $//; $toTitle = qq~$inmes_txt{'324'} $inmes_txt{'327'}:~; } &LoadValidUserDisplay($musername); $usernamelinkfrom = ${$uid.$musername}{'realname'} ? &CreateUserDisplayLine($musername) : ($musername ? qq~$musername ($maintxt{'470a'})~ : $maintxt{'470a'}); # 470a == Ex-Member $fromTitle = qq~$inmes_txt{'318'}:~; } $PMnav = &buildPMNavigator; &ToChars($msub); $msub = &Censor($msub); $message = $immessage; &wrap; if ($enable_ubbc) { if (!$yyYaBBCloaded) { require "$sourcedir/YaBBC.pl"; } &DoUBBC; } &wrap2; &ToChars($message); $message = &Censor($message); $avstyle = ''; $showIM = qq~ ~; if ($signature) { $showIM .= qq~ ~; } if ($iamadmin || $iamgmod && $gmod_access2{'ipban2'} eq 'on') { $imip = $imip; } else { $imip = $inmes_txt{'511'}; } my $postMenuTemp = $sendEmail . $sendPM . $membAdInfo . " "; $postMenuTemp =~ s/\Q$menusep//i; $showIM .= qq~
~; if ($fromTitle) { $showIM .= qq~ $fromTitle $usernamelinkfrom
~; } if ($toTitle) { $showIM .= qq~ $toTitle $usernamelinkto
~; } if ($toTitleCC) { $showIM .= qq~ $toTitleCC $usernamelinkcc
~; } if ($toTitleBCC) { $showIM .= qq~ $toTitleBCC $usernamelinkbcc
~; } $showIM .= qq~
$inmes_txt{'70'}: $msub
$inmes_txt{'317'}: $mydate
$message
$signature
$imip
$postMenuTemp
~; $mreplyno++; if ($INFO{'caller'} == 1 || ($INFO{'caller'} == 3 && $musername ne '') || ($INFO{'caller'} == 5 && $musername ne '')) { ## inbox / stored inbox can reply/quote if ($mstatus eq 'g') { $showIM .= qq~$img{'reply_ims'}~; } else { $showIM .= qq~ $img{'quote'}$menusep $img{'reply_ims'}$menusep~; } } if ($INFO{'caller'} != 5) { $showIM .= qq~ $img{'forward'}$menusep~; } if ($INFO{'caller'} != 5 || ($INFO{'caller'} == 5 && ($iamadmin || $username eq $musername))) { $showIM .= qq~ $img{'im_remove'} ~; } my $notme = $musername eq $username ? $mtousers : $musername; $notme = ${$uid.$notme}{'realname'}; $showIM .= qq~
~ . ($notme ? qq~$inmes_imtxt{'42'} $notme~ : " ") . qq~
$PMnav
~; return $showIM; } ## build the links for single PM display sub buildPMNavigator { if ($previd ne '') { $PMnav = qq~$previd~; } if ($allid ne '' && $previd ne '') { $PMnav .= qq~ | $allid~; } elsif ($allid ne '') { $PMnav = qq~$allid~; } if ($nextid ne '' && $allid ne '') { $PMnav .= qq~ | $nextid~; } return $PMnav; } ## show original PM/BM or the PM/BM before Preview at the bottom of the massage field sub doshowims { my $tempdate; if ($INFO{'id'} && !$INFO{'replyguest'}) { my $messageCount = 0; my $messageFoundFlag = 0; foreach my $message (@messages) { my $tmnum = (split /\|/, $message)[0]; if ($tmnum == $INFO{'id'}) { $messageFoundFlag = 1; last; } else {$messageCount ++;} } ## as a backup, if its not found that way, revert to the list member if (!$messageFoundFlag) { $messageCount = $INFO{'num'}; } ($messageid, $musername, $mto, $mtocc, $mtobcc, $msub, $mdate, $message, $mparid, $mreplyno, $mip, $mstatus, $mflags, $mstore, $mattach) = split(/\|/, $messages[$messageCount]); $tempdate = &timeformat($mdate); } else { return; } &ToChars($msub); $msub = &Censor($msub); &wrap; if ($enable_ubbc) { if (!$yyYaBBCloaded) { require "$sourcedir/YaBBC.pl"; } &DoUBBC; } &wrap2; &ToChars($message); $message = &Censor($message); if (!${$uid.$musername}{'password'}) { &LoadUser($musername); } my $musernameRealName = ${$uid.$musername}{'realname'}; if(!$musernameRealName) { $musernameRealName = $musername; } $imsend .= qq~
$inmes_txt{'70'}: $msub
$inmes_txt{'318'}: $musernameRealName~ . (($INFO{'id'} && $INFO{'caller'} != 4) ? "$inmes_txt{'30'}: " : ($INFO{'id'} ? "$inmes_txt{'savedraft'} $inmes_txt{'30'}: " : "")) . qq~$tempdate
$message
\n ~; } 1;