phpBB2Refugees.com Logo
Not affiliated with or endorsed by the phpBB Group

Register •  Login 

Continue the legacy...

Welcome to all phpBB2 Refugees!Wave Smilie

This site is intended to continue support for the legacy 2.x line of the phpBB2 bulletin board package. If you are a fan of phpBB2, please, by all means register, post, and help us out by offering your suggestions. We are primarily a community and support network. Our secondary goal is to provide a phpBB2 MOD Author and Styles area.

[RELEASED] Track PMs for phpBB2

Goto page 1, 2  Next
 
Search this topic... | Search MOD Development... | Search Box
Register or Login to Post    Index » MOD Development  Previous TopicPrint TopicNext Topic
Author Message
vlad77
Board Member



Joined: 31 May 2015

Posts: 74


flag
PostPosted: Sun Jun 17, 2018 7:45 am 
Post subject: Track PMs for phpBB2

Title: Track PMs for phpBB2
Author: Manipe, vlad77
Description: Mod like phpBB3 - in personal messages displays the correspondence history. Further development of fashion by Manipe. Functionality brought to the level of phpBB3
Version: 2.0.6
Note: If you are upgrading from mod by Manipe it is recommended that you delete and recreate the database column 'privmsgs_track_id'.



track_pms_2.0.6.zip
 Description:

Download
 Filename:  track_pms_2.0.6.zip
 Filesize:  5.77 KB
 Downloaded:  123 Time(s)


Attachment_for_Track_PMs.txt
 Description:
Addon for track_pms
This mod adds an attachment to the history of private messages.

Download
 Filename:  Attachment_for_Track_PMs.txt
 Filesize:  4.8 KB
 Downloaded:  121 Time(s)


track_pms_2.0.5.zip
 Description:

Download
 Filename:  track_pms_2.0.5.zip
 Filesize:  5.49 KB
 Downloaded:  250 Time(s)

Back to top
Vendethiel
Board Member



Joined: 26 Oct 2014

Posts: 153



PostPosted: Tue Jun 19, 2018 9:17 am 
Post subject: Re: Track PMs for phpBB2

That seems really good.

I want to install this mod, but I have a security concern: since you accept the $_POST var "id_for_pm_track", a user could fake that ID to track someone else's message, and thus see someone else's private message.
It's probably not an actual security issue in practice, since the function pm_track only selects PMs from a certain user, but still, I would be wary of inserting tampered data.

Great job!

_________________
Developer on EzArena, the ADR premod.
Developer on Icy Phoenix, the phpBB hybrid cms.
Developer on IntegraMOD, the full-featured premod.
Help me archive premods on github! (fixed for recent PHPs).
Back to top
vlad77
Board Member



Joined: 31 May 2015

Posts: 74


flag
PostPosted: Tue Jun 19, 2018 7:23 pm 
Post subject: Re: Track PMs for phpBB2

Hello Vendethiel,
This sql request prevents access to other people's private messages
Code:
      $sql = "SELECT pm.privmsgs_id, pm.privmsgs_type, pm.privmsgs_subject, pm.privmsgs_date, pm.privmsgs_enable_html, pm.privmsgs_enable_smilies, pmt.privmsgs_bbcode_uid, pmt.privmsgs_text, u.username AS username_1, u.user_id AS user_id_1, u2.username AS username_2, u2.user_id AS user_id_2, u.user_avatar, u.user_avatar_type, u.user_allowavatar
         FROM " . PRIVMSGS_TABLE . " pm, " . PRIVMSGS_TEXT_TABLE . " pmt, " . USERS_TABLE . " u, " . USERS_TABLE . " u2
         WHERE pmt.privmsgs_text_id = pm.privmsgs_id
            AND pm.privmsgs_track_id = " . $pm_track_id . "
            AND u.user_id = pm.privmsgs_from_userid
            AND u2.user_id = pm.privmsgs_to_userid
            AND ( ( pm.privmsgs_to_userid = " . $userdata['user_id'] . "
               AND ( pm.privmsgs_type = " . PRIVMSGS_SAVED_IN_MAIL . "
                  OR pm.privmsgs_type = " . PRIVMSGS_READ_MAIL . "
                  OR pm.privmsgs_type = " . PRIVMSGS_NEW_MAIL . "
                  OR pm.privmsgs_type = " . PRIVMSGS_UNREAD_MAIL . "  ) )
            OR ( pm.privmsgs_from_userid =  " . $userdata['user_id'] . "
               AND ( pm.privmsgs_type = " . PRIVMSGS_NEW_MAIL . "
                  OR pm.privmsgs_type = " . PRIVMSGS_UNREAD_MAIL . "
                  OR pm.privmsgs_type = " . PRIVMSGS_SENT_MAIL . "
                  OR pm.privmsgs_type = " . PRIVMSGS_SAVED_OUT_MAIL . " ) )
            )
         ORDER BY privmsgs_date DESC
         LIMIT 0," . $pm_track_limiter;
AND ( ( pm.privmsgs_to_userid = " . $userdata['user_id'] . "
OR ( pm.privmsgs_from_userid = " . $userdata['user_id'] . "
Back to top
Vendethiel
Board Member



Joined: 26 Oct 2014

Posts: 153



PostPosted: Wed Jun 20, 2018 11:59 am 
Post subject: Re: Track PMs for phpBB2

Yes, this is what I mentioned in the second part.
I still prefer not to insert wrong data in the first place. But I think yours is safe.

_________________
Developer on EzArena, the ADR premod.
Developer on Icy Phoenix, the phpBB hybrid cms.
Developer on IntegraMOD, the full-featured premod.
Help me archive premods on github! (fixed for recent PHPs).
Back to top
vlad77
Board Member



Joined: 31 May 2015

Posts: 74


flag
PostPosted: Wed Jun 20, 2018 4:35 pm 
Post subject: Re: Track PMs for phpBB2

If you want, try to replace the "$pm_track_id = $id_for_pm_track;" to "return $id_for_pm_track;" But for safety it is unnecessary.
Line "$pm_track_id = $id_for_pm_track;" will be used when viewing automatically generated private messages, if "$pm_track_id = pm_track($id_for_pm_track, 1);" replaced by "$pm_track_id = pm_track($id_for_pm_track);"
Back to top
Vendethiel
Board Member



Joined: 26 Oct 2014

Posts: 153



PostPosted: Wed Jan 16, 2019 2:29 pm 
Post subject: Re: Track PMs for phpBB2

There is a very minor bug. If you send a PM to yourself, in the review, you will have both the Sentbox PM and the Inbox PM. Doesn't really matter...



Then, I changed something else: right now the $pass parameter is buggy. So I changed it to $ignore_pm_id. Now, in the view, it shows which PM of the chain the user is reading:

Image link

So you know where you're at while reviewing the PM history.

I can send you my changes if you care about it.


Also, I need to add some more code to make it work with attachments.

_________________
Developer on EzArena, the ADR premod.
Developer on Icy Phoenix, the phpBB hybrid cms.
Developer on IntegraMOD, the full-featured premod.
Help me archive premods on github! (fixed for recent PHPs).
Back to top
vlad77
Board Member



Joined: 31 May 2015

Posts: 74


flag
PostPosted: Tue Jan 22, 2019 5:48 pm 
Post subject: Re: Track PMs for phpBB2

Send your changes. Addon to work with attachments would be useful.
Back to top
Vendethiel
Board Member



Joined: 26 Oct 2014

Posts: 153



PostPosted: Wed Jan 23, 2019 6:21 pm 
Post subject: Re: Track PMs for phpBB2

Here's my pm_track_id function:
Code:
// View PM while replying MOD, By Manipe
function pm_track_id($id_for_pm_track, $pm_pass_id = 0)
// ^^^^ I changed this
{
// Specifies the number of messages that change if you want to reduce server load
   $pm_track_limiter = 200;

   global $template, $userdata, $lang, $db, $board_config, $images, $theme, $phpEx;

   $sql = "SELECT privmsgs_track_id
      FROM " . PRIVMSGS_TABLE . "
      WHERE privmsgs_id = " . $id_for_pm_track;
   if ( !($result = $db->sql_query($sql)) )
   {
      message_die(GENERAL_ERROR, 'Could not obtain private message for track id', '', __LINE__, __FILE__, $sql);
   }

   if ( !($row = $db->sql_fetchrow($result)) )
   {
      $pm_track_id = $id_for_pm_track;
   }
   else
   {
      $pm_track_id = $row['privmsgs_track_id'];
   }
   if ( $pm_track_id != 0 )
   {
      $template->set_filenames(array(
         'pm_tracker' => 'posting_pm_tracker.tpl')
      );
      $template->assign_vars(array(
         'L_PM_TRACKER' => $lang['Private_Message_tracker'],
         'L_FROM' => $lang['From'],
         'L_TO' => $lang['To'],
         'L_FOLDER' => $lang['Folder'],
         'L_PRIVATE_MESSAGE' => $lang['Private_Message'],
         'L_SENT' => $lang['Sent'],
         'L_MINI_POST_ALT' => $lang['Message'],
         'L_SUBJECT' => $lang['Subject'],

         'MINI_POST_IMG' => $images['icon_minipost'])
      );

      $list_row = array();

      $sql = "SELECT pm.privmsgs_id, pm.privmsgs_type, pm.privmsgs_subject, pm.privmsgs_date, pm.privmsgs_enable_html, pm.privmsgs_enable_smilies, pmt.privmsgs_bbcode_uid, pmt.privmsgs_text, u.username AS username_1, u.user_id AS user_id_1, u2.username AS username_2, u2.user_id AS user_id_2, u.user_avatar, u.user_avatar_type, u.user_allowavatar
         FROM " . PRIVMSGS_TABLE . " pm, " . PRIVMSGS_TEXT_TABLE . " pmt, " . USERS_TABLE . " u, " . USERS_TABLE . " u2
         WHERE pmt.privmsgs_text_id = pm.privmsgs_id
            AND pm.privmsgs_track_id = " . $pm_track_id . "
            AND u.user_id = pm.privmsgs_from_userid
            AND u2.user_id = pm.privmsgs_to_userid
            AND ( ( pm.privmsgs_to_userid = " . $userdata['user_id'] . "
               AND ( pm.privmsgs_type = " . PRIVMSGS_SAVED_IN_MAIL . "
                  OR pm.privmsgs_type = " . PRIVMSGS_READ_MAIL . "
                  OR pm.privmsgs_type = " . PRIVMSGS_NEW_MAIL . "
                  OR pm.privmsgs_type = " . PRIVMSGS_UNREAD_MAIL . "  ) )
            OR ( pm.privmsgs_from_userid =  " . $userdata['user_id'] . "
               AND ( pm.privmsgs_type = " . PRIVMSGS_NEW_MAIL . "
                  OR pm.privmsgs_type = " . PRIVMSGS_UNREAD_MAIL . "
                  OR pm.privmsgs_type = " . PRIVMSGS_SENT_MAIL . "
                  OR pm.privmsgs_type = " . PRIVMSGS_SAVED_OUT_MAIL . " ) )
            )
         ORDER BY privmsgs_date DESC
         LIMIT 0," . $pm_track_limiter;
      if ( !($result = $db->sql_query($sql)) )
      {
         message_die(GENERAL_ERROR, 'Could not obtain private message for tracking', '', __LINE__, __FILE__, $sql);
      }

      while ( $row = $db->sql_fetchrow($result) )
      {
         if ($row['privmsgs_to_userid'] == $row['privmsgs_from_userid']
            && ($row['privmsgs_type'] == PRIVMSGS_SENT_MAIL || $row['privmsgs_type'] == PRIVMSGS_SAVED_OUT_MAIL))
         { // V: if we're sending PMs to ourselves, skip it all
            continue;
         }
// ^^^^ I added this if

         $list_row[] = $row;
      }

      $counter_list_row = count($list_row);

      if ( ( $counter_list_row > 0 ) && ( $pm_track_id != 0 ) )
// ^^^^ I changed this
      {
         for ($i = 0; $i < $counter_list_row; $i++)
         {
            $is_current = ($list_row[$i]['privmsgs_id'] == $pm_pass_id);
// ^^^^ I added this

            $privmsg_bbcode_uid = $list_row[$i]['privmsgs_bbcode_uid'];

            $reply_message = $list_row[$i]['privmsgs_text'];
            $reply_subject = $list_row[$i]['privmsgs_subject'];

            if ( !$board_config['allow_html'] || !$userdata['user_allowhtml'])
            {
               if ( $list_row[$i]['privmsgs_enable_html'] )
               {
                  $reply_message = preg_replace('#(<)([\/]?.*?)(>)#is', "&lt;\\2&gt;", $reply_message);
               }
            }

            if ( $privmsg_bbcode_uid != '' )
            {
               $reply_message = ( $board_config['allow_bbcode'] ) ? bbencode_second_pass($reply_message, $privmsg_bbcode_uid) : preg_replace('/\:[0-9a-z\:]+\]/si', ']', $reply_message);
            }

//             $reply_message = make_clickable($reply_message);

            $orig_word = array();
            $replacement_word = array();
            obtain_word_list($orig_word, $replacement_word);

            if ( count($orig_word) )
            {
               $reply_subject = preg_replace($orig_word, $replacement_word, $reply_subject);
               $reply_message = preg_replace($orig_word, $replacement_word, $reply_message);
            }

            $reply_message = make_clickable($reply_message);

            if ( $board_config['allow_smilies'] && $list_row[$i]['privmsgs_enable_smilies'] )
            {
               $reply_message = smilies_pass($reply_message);
            }

            $reply_message = str_replace("\n", '<br />', $reply_message);

            $row_color = ( $row_color == $theme['td_color1'] ) ? $theme['td_color2'] : $theme['td_color1'];
            $row_class = ( $row_class == $theme['td_class1'] ) ? $theme['td_class2'] : $theme['td_class1'];

            $folder_pm_track = 'outbox';
            $folder_pm_track = ( $list_row[$i]['user_id_1'] != $userdata['user_id'] ) && ( ( $list_row[$i]['privmsgs_type'] == PRIVMSGS_NEW_MAIL ) || ( $list_row[$i]['privmsgs_type'] == PRIVMSGS_UNREAD_MAIL ) ) ? 'inbox' : $folder_pm_track;
            $folder_pm_track = $list_row[$i]['privmsgs_type'] == PRIVMSGS_READ_MAIL ? 'inbox' : $folder_pm_track;
            $folder_pm_track = $list_row[$i]['privmsgs_type'] == PRIVMSGS_SENT_MAIL ? 'sentbox' : $folder_pm_track;
            $folder_pm_track = ( $list_row[$i]['privmsgs_type'] == PRIVMSGS_SAVED_IN_MAIL ) || ( $list_row[$i]['privmsgs_type'] == PRIVMSGS_SAVED_OUT_MAIL ) ? 'savebox' : $folder_pm_track;

            switch ($folder_pm_track)
            {
               case 'inbox':
                  $l_box_name_pm_track = $lang['Inbox'];
                  break;
               case 'outbox':
                  $l_box_name_pm_track = $lang['Outbox'];
                  break;
               case 'savebox':
                  $l_box_name_pm_track = $lang['Savebox'];
                  break;
               case 'sentbox':
                  $l_box_name_pm_track = $lang['Sentbox'];
                  break;
               default:
                  $l_box_name_pm_track = $lang['No_such_folder'];
                  break;
            }

            $avatar_img = '';
            if ( $list_row[$i]['user_avatar_type'] && $list_row[$i]['user_allowavatar'] )

            {
               switch( $list_row[$i]['user_avatar_type'] )
               {
                  case USER_AVATAR_UPLOAD:
                     $avatar_img = ( $board_config['allow_avatar_upload'] ) ? '<a target="_blank" href="' . append_sid("profile.$phpEx?mode=viewprofile&amp;" . POST_USERS_URL . '=' . $list_row[$i]['user_id_1']) . '"><img src="' . $board_config['avatar_path'] . '/' . $list_row[$i]['user_avatar'] . '" alt="" border="0" /></a>' : '';
                     break;
                  case USER_AVATAR_REMOTE:
                     $avatar_img = ( $board_config['allow_avatar_remote'] ) ? '<a target="_blank" href="' . append_sid("profile.$phpEx?mode=viewprofile&amp;" . POST_USERS_URL . '=' . $list_row[$i]['user_id_1']) . '"><img src="' . $list_row[$i]['user_avatar'] . '" alt="" border="0" /></a>' : '';
                     break;
                  case USER_AVATAR_GALLERY:
                     $avatar_img = ( $board_config['allow_avatar_local'] ) ? '<a target="_blank" href="' . append_sid("profile.$phpEx?mode=viewprofile&amp;" . POST_USERS_URL . '=' . $list_row[$i]['user_id_1']) . '"><img src="' . $board_config['avatar_gallery_path'] . '/' . $list_row[$i]['user_avatar'] . '" alt="" border="0" /></a>' : '';
                     break;
               }
            }

            $template->assign_block_vars('postrow', array(
               'ROW_COLOR' => '#' . $row_color,
               'ROW_CLASS' => $row_class,

               'BOX_NAME' => $l_box_name_pm_track,
               'PRIVMSGS_LINK' => '<a target="_blank" href="'  .append_sid("privmsg.$phpEx?folder=$folder_pm_track&amp;mode=read&amp;" . POST_POST_URL . '=' . $list_row[$i]['privmsgs_id']) . '"><u>' . $lang['Jump_to_Private_Message'] . '</u></a>',
               'POSTER_NAME' => '<a target="_blank" href="'  .append_sid("profile.$phpEx?mode=viewprofile&amp;" . POST_USERS_URL . '=' . $list_row[$i]['user_id_1']) . '">' . $list_row[$i]['username_1'] . '</a>',
               'ADDRESSEE_NAME' => '<a target="_blank" href="'  .append_sid("profile.$phpEx?mode=viewprofile&amp;" . POST_USERS_URL . '=' . $list_row[$i]['user_id_2']) . '">' . $list_row[$i]['username_2'] . '</a>',
               'AVATAR_IMG' => $avatar_img,
               'PM_DATE' => create_date($board_config['default_dateformat'], $list_row[$i]['privmsgs_date'], $board_config['board_timezone']),
               'PM_SUBJECT' => $reply_subject,
               'MESSAGE' => $reply_message,
               'IS_CURRENT' => $is_current,
// ^^^^ I added this
               )
            );
         }
      }
   }
   if ( ( $counter_list_row > 0 ) && ( $pm_track_id != 0 ) )
// ^^^^ I changed this
   {
      $template->assign_var_from_handle('TOPIC_REVIEW_BOX', 'pm_tracker');
   }

   return $pm_track_id;
}
// View PM while replying MOD, By Manipe
Sorry, this is the whole function. All my changes are annotated with "// ^^^^".

This is my addition to the template:
Code:

   <!-- BEGIN postrow -->
   <tr>
      <td width="22%" align="left" valign="top" class="{postrow.ROW_CLASS}">
      <span class="name"><b>{postrow.POSTER_NAME}</b><br /><br /></span>{postrow.AVATAR_IMG}<br /><br /></td>
      <!-- IF postrow.IS_CURRENT -->
      <td class="{postrow.ROW_CLASS}">
         {L_PM_CURRENTLY_VIEWING}
      </td>
      <!-- ELSE -->
      <td class="{postrow.ROW_CLASS}" height="28" valign="top"><table width="100%" border="0" cellspacing="0" cellpadding="0">
         <tr>
            <td width="100%"><img src="{MINI_POST_IMG}" width="12" height="9" alt="{L_MINI_POST_ALT}" title="{L_MINI_POST_ALT}" border="0" /><span class="postdetails">{L_SENT}: {postrow.PM_DATE}&nbsp;&nbsp;&nbsp;{L_TO}: <b>{postrow.ADDRESSEE_NAME}</b>&nbsp;&nbsp;&nbsp;{L_SUBJECT}: {postrow.PM_SUBJECT}&nbsp;&nbsp;&nbsp;{L_FOLDER}: <b>{postrow.BOX_NAME}</b></span></td>
         </tr>
         <tr>
            <td colspan="2"><hr /></td>
         </tr>
         <tr>
            <td colspan="2"><span class="postbody">{postrow.MESSAGE}</span></td>
         </tr>

         <tr>
            <td colspan="2"><br /><span class="genmed">&nbsp;{postrow.PRIVMSGS_LINK}</span></td>
         </tr>

      </table>
      <!-- ENDIF -->
      </td>
   </tr>
   <tr>
      <td colspan="2" height="1" class="spaceRow"><img src="images/spacer.gif" alt="" width="1" height="1" /></td>
   </tr>
    <!-- END postrow -->
Once again, sorry, I'm not posting a diff, because I reformated the HTML, the diff would look messy. But I added the IF / ELSE / ENDIF.


I have not yet done attachments. I will soon.

_________________
Developer on EzArena, the ADR premod.
Developer on Icy Phoenix, the phpBB hybrid cms.
Developer on IntegraMOD, the full-featured premod.
Help me archive premods on github! (fixed for recent PHPs).
Back to top
vlad77
Board Member



Joined: 31 May 2015

Posts: 74


flag
PostPosted: Sat Jan 26, 2019 12:51 pm 
Post subject: Re: Track PMs for phpBB2

Interested addon for attachments.
I study your code.
The $pass variable is needed to control the display of the correspondence history, show the history when there are different quantity PMs in this history for various function calls.
Your code, showing which PM the user has opened, requires the installed "eXtreme Styles mod 2", i can add it to my mod like addon is another file posting_pm_tracker.tpl
Back to top
Vendethiel
Board Member



Joined: 26 Oct 2014

Posts: 153



PostPosted: Sat Jan 26, 2019 2:14 pm 
Post subject: Re: Track PMs for phpBB2

You are right that, as of right now, this mod requires XS for IF ELSE END. But it can easily be rewritten in two sub-blocks:
BEGIN postrow.is_current

And replace the else with
BEGIN postrow.is_not_current



I don’t think $pass is important.
The only use it had that I saw, was not displaying the latest PM in the history block.
But it’s not necessary anymore.

_________________
Developer on EzArena, the ADR premod.
Developer on Icy Phoenix, the phpBB hybrid cms.
Developer on IntegraMOD, the full-featured premod.
Help me archive premods on github! (fixed for recent PHPs).
Back to top
vlad77
Board Member



Joined: 31 May 2015

Posts: 74


flag
PostPosted: Sat Jan 26, 2019 2:30 pm 
Post subject: Re: Track PMs for phpBB2

variable $pm_pass_id is better defined
Code:
$pm_pass_id = (isset($_GET[POST_POST_URL])) ? trim($_GET[POST_POST_URL]) : ((isset($_POST[POST_POST_URL])) ? trim($_POST[POST_POST_URL]) : 0);


"This is the PM you're currently viewing" is still better to do as the second posting_pm_tracker.tpl, so that admins can customize as they like.
Back to top
vlad77
Board Member



Joined: 31 May 2015

Posts: 74


flag
PostPosted: Sat Jan 26, 2019 2:47 pm 
Post subject: Re: Track PMs for phpBB2

That's what happened pm_track function:
Code:
// View PM while replying MOD, By Manipe
function pm_track($id_for_pm_track, $pass = 0)
{

// Specifies the number of messages that change if you want to reduce server load
// Определяет количество показываемых сообщений, поменяйте если надо снизить нагрузку на сервер
   $pm_track_limiter = 200;

   global $template, $userdata, $lang, $db, $board_config, $images, $theme, $phpEx;
   $pm_pass_id = (isset($_GET[POST_POST_URL])) ? trim($_GET[POST_POST_URL]) : ((isset($_POST[POST_POST_URL])) ? trim($_POST[POST_POST_URL]) : 0);

   $sql = "SELECT privmsgs_track_id
      FROM " . PRIVMSGS_TABLE . "
      WHERE privmsgs_id = " . $id_for_pm_track;
   if ( !($result = $db->sql_query($sql)) )
   {
      message_die(GENERAL_ERROR, 'Could not obtain private message for track id', '', __LINE__, __FILE__, $sql);
   }

   if ( !($row = $db->sql_fetchrow($result)) )
   {
      $pm_track_id = $id_for_pm_track;
   }
   else
   {
      $pm_track_id = $row['privmsgs_track_id'];
   }
   if ( $pm_track_id != 0 )
   {
      $template->set_filenames(array(
         'pm_tracker' => 'posting_pm_tracker.tpl')
      );
      $template->assign_vars(array(
         'L_PM_TRACKER' => $lang['Private_Message_tracker'],
         'L_FROM' => $lang['From'],
         'L_TO' => $lang['To'],
         'L_FOLDER' => $lang['Folder'],
         'L_PRIVATE_MESSAGE' => $lang['Private_Message'],
         'L_SENT' => $lang['Sent'],
         'L_MINI_POST_ALT' => $lang['Message'],
         'L_SUBJECT' => $lang['Subject'],

         'MINI_POST_IMG' => $images['icon_minipost'])
      );

      $list_row = array();

      $sql = "SELECT pm.privmsgs_id, pm.privmsgs_type, pm.privmsgs_subject, pm.privmsgs_date, pm.privmsgs_enable_html, pm.privmsgs_enable_smilies, pmt.privmsgs_bbcode_uid, pmt.privmsgs_text, u.username AS username_1, u.user_id AS user_id_1, u2.username AS username_2, u2.user_id AS user_id_2, u.user_avatar, u.user_avatar_type, u.user_allowavatar
         FROM " . PRIVMSGS_TABLE . " pm, " . PRIVMSGS_TEXT_TABLE . " pmt, " . USERS_TABLE . " u, " . USERS_TABLE . " u2
         WHERE pmt.privmsgs_text_id = pm.privmsgs_id
            AND pm.privmsgs_track_id = " . $pm_track_id . "
            AND u.user_id = pm.privmsgs_from_userid
            AND u2.user_id = pm.privmsgs_to_userid
            AND ( ( pm.privmsgs_to_userid = " . $userdata['user_id'] . "
               AND ( pm.privmsgs_type = " . PRIVMSGS_SAVED_IN_MAIL . "
                  OR pm.privmsgs_type = " . PRIVMSGS_READ_MAIL . "
                  OR pm.privmsgs_type = " . PRIVMSGS_NEW_MAIL . "
                  OR pm.privmsgs_type = " . PRIVMSGS_UNREAD_MAIL . "  ) )
            OR ( pm.privmsgs_from_userid =  " . $userdata['user_id'] . "
               AND ( pm.privmsgs_type = " . PRIVMSGS_NEW_MAIL . "
                  OR pm.privmsgs_type = " . PRIVMSGS_UNREAD_MAIL . "
                  OR pm.privmsgs_type = " . PRIVMSGS_SENT_MAIL . "
                  OR pm.privmsgs_type = " . PRIVMSGS_SAVED_OUT_MAIL . " ) )
            )
         ORDER BY privmsgs_date DESC
         LIMIT 0," . $pm_track_limiter;
      if ( !($result = $db->sql_query($sql)) )
      {
         message_die(GENERAL_ERROR, 'Could not obtain private message for tracking', '', __LINE__, __FILE__, $sql);
      }

      while ( $row = $db->sql_fetchrow($result) )
      {
         if ($row['privmsgs_to_userid'] == $row['privmsgs_from_userid'] && ($row['privmsgs_type'] == PRIVMSGS_SENT_MAIL || $row['privmsgs_type'] == PRIVMSGS_SAVED_OUT_MAIL))
         { // V: if we're sending PMs to ourselves, skip it all
            continue;
         }
         $list_row[] = $row;
      }

      $counter_list_row = count($list_row);

      if ( ( $counter_list_row > $pass ) && ( $pm_track_id != 0 ) )
      {
         for ($i = 0; $i < $counter_list_row; $i++)
         {
            $is_current = ($list_row[$i]['privmsgs_id'] == $pm_pass_id);

            $privmsg_bbcode_uid = $list_row[$i]['privmsgs_bbcode_uid'];

            $reply_message = $list_row[$i]['privmsgs_text'];
            $reply_subject = $list_row[$i]['privmsgs_subject'];

            if ( !$board_config['allow_html'] || !$userdata['user_allowhtml'])
            {
               if ( $list_row[$i]['privmsgs_enable_html'] )
               {
                  $reply_message = preg_replace('#(<)([\/]?.*?)(>)#is', "&lt;\\2&gt;", $reply_message);
               }
            }

            if ( $privmsg_bbcode_uid != '' )
            {
               $reply_message = ( $board_config['allow_bbcode'] ) ? bbencode_second_pass($reply_message, $privmsg_bbcode_uid) : preg_replace('/\:[0-9a-z\:]+\]/si', ']', $reply_message);
            }

//             $reply_message = make_clickable($reply_message);

            $orig_word = array();
            $replacement_word = array();
            obtain_word_list($orig_word, $replacement_word);

            if ( count($orig_word) )
            {
               $reply_subject = preg_replace($orig_word, $replacement_word, $reply_subject);
               $reply_message = preg_replace($orig_word, $replacement_word, $reply_message);
            }

            $reply_message = make_clickable($reply_message);

            if ( $board_config['allow_smilies'] && $list_row[$i]['privmsgs_enable_smilies'] )
            {
               $reply_message = smilies_pass($reply_message);
            }

            $reply_message = str_replace("\n", '<br />', $reply_message);

            $row_color = ( $row_color == $theme['td_color1'] ) ? $theme['td_color2'] : $theme['td_color1'];
            $row_class = ( $row_class == $theme['td_class1'] ) ? $theme['td_class2'] : $theme['td_class1'];

            $folder_pm_track = 'outbox';
            $folder_pm_track = ( $list_row[$i]['user_id_1'] != $userdata['user_id'] ) && ( ( $list_row[$i]['privmsgs_type'] == PRIVMSGS_NEW_MAIL ) || ( $list_row[$i]['privmsgs_type'] == PRIVMSGS_UNREAD_MAIL ) ) ? 'inbox' : $folder_pm_track;
            $folder_pm_track = $list_row[$i]['privmsgs_type'] == PRIVMSGS_READ_MAIL ? 'inbox' : $folder_pm_track;
            $folder_pm_track = $list_row[$i]['privmsgs_type'] == PRIVMSGS_SENT_MAIL ? 'sentbox' : $folder_pm_track;
            $folder_pm_track = ( $list_row[$i]['privmsgs_type'] == PRIVMSGS_SAVED_IN_MAIL ) || ( $list_row[$i]['privmsgs_type'] == PRIVMSGS_SAVED_OUT_MAIL ) ? 'savebox' : $folder_pm_track;

            switch ($folder_pm_track)
            {
               case 'inbox':
                  $l_box_name_pm_track = $lang['Inbox'];
                  break;
               case 'outbox':
                  $l_box_name_pm_track = $lang['Outbox'];
                  break;
               case 'savebox':
                  $l_box_name_pm_track = $lang['Savebox'];
                  break;
               case 'sentbox':
                  $l_box_name_pm_track = $lang['Sentbox'];
                  break;
               default:
                  $l_box_name_pm_track = $lang['No_such_folder'];
                  break;
            }

            $avatar_img = '';
            if ( $list_row[$i]['user_avatar_type'] && $list_row[$i]['user_allowavatar'] )

            {
               switch( $list_row[$i]['user_avatar_type'] )
               {
                  case USER_AVATAR_UPLOAD:
                     $avatar_img = ( $board_config['allow_avatar_upload'] ) ? '<a target="_blank" href="' . append_sid("profile.$phpEx?mode=viewprofile&amp;" . POST_USERS_URL . '=' . $list_row[$i]['user_id_1']) . '"><img src="' . $board_config['avatar_path'] . '/' . $list_row[$i]['user_avatar'] . '" alt="" border="0" /></a>' : '';
                     break;
                  case USER_AVATAR_REMOTE:
                     $avatar_img = ( $board_config['allow_avatar_remote'] ) ? '<a target="_blank" href="' . append_sid("profile.$phpEx?mode=viewprofile&amp;" . POST_USERS_URL . '=' . $list_row[$i]['user_id_1']) . '"><img src="' . $list_row[$i]['user_avatar'] . '" alt="" border="0" /></a>' : '';
                     break;
                  case USER_AVATAR_GALLERY:
                     $avatar_img = ( $board_config['allow_avatar_local'] ) ? '<a target="_blank" href="' . append_sid("profile.$phpEx?mode=viewprofile&amp;" . POST_USERS_URL . '=' . $list_row[$i]['user_id_1']) . '"><img src="' . $board_config['avatar_gallery_path'] . '/' . $list_row[$i]['user_avatar'] . '" alt="" border="0" /></a>' : '';
                     break;
               }
            }

            $template->assign_block_vars('postrow', array(
               'ROW_COLOR' => '#' . $row_color,
               'ROW_CLASS' => $row_class,

               'BOX_NAME' => $l_box_name_pm_track,
               'PRIVMSGS_LINK' => '<a target="_blank" href="'  .append_sid("privmsg.$phpEx?folder=$folder_pm_track&amp;mode=read&amp;" . POST_POST_URL . '=' . $list_row[$i]['privmsgs_id']) . '"><u>' . $lang['Jump_to_Private_Message'] . '</u></a>',
               'POSTER_NAME' => '<a target="_blank" href="'  .append_sid("profile.$phpEx?mode=viewprofile&amp;" . POST_USERS_URL . '=' . $list_row[$i]['user_id_1']) . '">' . $list_row[$i]['username_1'] . '</a>',
               'ADDRESSEE_NAME' => '<a target="_blank" href="'  .append_sid("profile.$phpEx?mode=viewprofile&amp;" . POST_USERS_URL . '=' . $list_row[$i]['user_id_2']) . '">' . $list_row[$i]['username_2'] . '</a>',
               'AVATAR_IMG' => $avatar_img,
               'PM_DATE' => create_date($board_config['default_dateformat'], $list_row[$i]['privmsgs_date'], $board_config['board_timezone']),
               'PM_SUBJECT' => $reply_subject,
               'MESSAGE' => $reply_message,
               'IS_CURRENT' => $is_current)
            );
         }
      }
   }
   if ( ( $counter_list_row > $pass ) && ( $pm_track_id != 0 ) )
   {
      $template->assign_var_from_handle('TOPIC_REVIEW_BOX', 'pm_tracker');
   }

   return $pm_track_id;
}
// View PM while replying MOD, By Manipe


I am waiting for addon for attachments
Back to top
Vendethiel
Board Member



Joined: 26 Oct 2014

Posts: 153



PostPosted: Sat Jan 26, 2019 4:10 pm 
Post subject: Re: Track PMs for phpBB2

Ah. I understand now why you need $pass: to not display the review box if there is only a PM. I get it now.

I will integrate your version.

_________________
Developer on EzArena, the ADR premod.
Developer on Icy Phoenix, the phpBB hybrid cms.
Developer on IntegraMOD, the full-featured premod.
Help me archive premods on github! (fixed for recent PHPs).
Back to top
vlad77
Board Member



Joined: 31 May 2015

Posts: 74


flag
PostPosted: Sun Jan 27, 2019 10:27 am 
Post subject: Re: Track PMs for phpBB2

Added by
Code:
$pm_pass_id = ($mode == 'read') ? $pm_pass_id : 0;
what would you reply a user saw a the message which answers.

From the code
Code:
         if ($row['privmsgs_to_userid'] == $row['privmsgs_from_userid'] && ($row['privmsgs_type'] == PRIVMSGS_SENT_MAIL || $row['privmsgs_type'] == PRIVMSGS_SAVED_OUT_MAIL))
         { // V: if we're sending PMs to ourselves, skip it all
            continue;
         }
had to be abandoned because $row['privmsgs_to_userid'] are always NULL and spoil private message chains. What would this code worked, it is necessary to redo the sql query, which in my opinion unnecessarily laborious.
In attachment upload mod version 2.0.6. See how done. Later, upload it in the first post of the topic.

----------------

Attachment deleted because you watched it.
Back to top
Vendethiel
Board Member



Joined: 26 Oct 2014

Posts: 153



PostPosted: Sun Jan 27, 2019 4:50 pm 
Post subject: Re: Track PMs for phpBB2

Quote:
had to be abandoned because $row['privmsgs_to_userid'] are always NULL and spoil private message chains. What would this code worked, it is necessary to redo the sql query, which in my opinion unnecessarily laborious.
Oh, too bad. In which case is the to_userid NULL? I have changed the code, to use privmsgs_date + text as a differentiator:

Code:

      $last_privmsg = null;
      while ( $row = $db->sql_fetchrow($result) )
      {
         if ($last_privmsg
            && $last_privmsg['privmsgs_date'] == $row['privmsgs_date']
            && $last_privmsg['privmsgs_text'] == $row['privmsgs_text']
            // check if they're in a diff folder (savebox <=> inbox or outbox <=> inbox)
            && $last_privmsg['privmsgs_type'] != $row['privmsgs_type']
         ) {
            continue;
         }
         $last_privmsg = $row;



I got the attachments mod working with pm_tracker:
Image link

The code is very messy. I will test more to make sure everything works fine.

_________________
Developer on EzArena, the ADR premod.
Developer on Icy Phoenix, the phpBB hybrid cms.
Developer on IntegraMOD, the full-featured premod.
Help me archive premods on github! (fixed for recent PHPs).
Back to top
Display posts from previous:   
Register or Login to Post    Index » MOD Development  Previous TopicPrint TopicNext Topic
Page 1 of 2 All times are GMT
Goto page 1, 2  Next
 
Jump to:  

Index • About • FAQ • Rules • Privacy • Search •  Register •  Login 
Not affiliated with or endorsed by the phpBB Group
Powered by phpBB2 © phpBB Group
Generated in 0.1053 seconds using 17 queries. (SQL 0.0064 Parse 0.0625 Other 0.0364)
phpBB Customizations by the phpBBDoctor.com
Template Design by DeLFlo and MomentsOfLight.com Moments of Light Logo