b2evolution PHP Cross Reference Blogging Systems

Source: /inc/messaging/views/_message_list.view.php - 455 lines - 16674 bytes - Summary - Text - Print

Description: This file is part of b2evolution - {@link http://b2evolution.net/} See also {@link http://sourceforge.net/projects/evocms/}.

   1  <?php
   2  /**
   3   * This file is part of b2evolution - {@link http://b2evolution.net/}
   4   * See also {@link http://sourceforge.net/projects/evocms/}.
   5   *
   6   * @copyright (c)2009-2014 by Francois PLANQUE - {@link http://fplanque.net/}
   7   * Parts of this file are copyright (c)2009 by The Evo Factory - {@link http://www.evofactory.com/}.
   8   *
   9   * Released under GNU GPL License - {@link http://b2evolution.net/about/license.html}
  10   *
  11   * {@internal Open Source relicensing agreement:
  12   * The Evo Factory grants Francois PLANQUE the right to license
  13   * The Evo Factory's contributions to this file and the b2evolution project
  14   * under any OSI approved OSS license (http://www.opensource.org/licenses/).
  15   * }}
  16   *
  17   * @package messaging
  18   *
  19   * {@internal Below is a list of authors who have contributed to design/coding of this file: }}
  20   * @author efy-maxim: Evo Factory / Maxim.
  21   * @author fplanque: Francois Planque.
  22   *
  23   * @version $Id: _message_list.view.php 6136 2014-03-08 07:59:48Z manuel $
  24   */
  25  if( !defined('EVO_MAIN_INIT') ) die( 'Please, do not access this page directly.' );
  26  
  27  global $dispatcher, $action, $current_User, $Blog, $perm_abuse_management;
  28  
  29  // in front office there is no function call, $edited_Thread is available
  30  if( !isset( $edited_Thread ) )
  31  { // $edited thread is global in back office, but we are inside of disp_view function call
  32      global $edited_Thread;
  33  
  34      if( !isset( $edited_Thread ) )
  35      {
  36          debug_die( "Missing thread!");
  37      }
  38  }
  39  
  40  global $read_status_list, $leave_status_list;
  41  
  42  $creating = is_create_action( $action );
  43  
  44  if( !isset( $display_params ) )
  45  {
  46      $display_params = array();
  47  }
  48  
  49  if( !isset( $params ) )
  50  {
  51      $params = array();
  52  }
  53  $params = array_merge( array(
  54      'form_class' => 'fform',
  55      'form_action' => NULL,
  56      'form_name' => 'messages_checkchanges',
  57      'form_layout' => 'compact',
  58      'redirect_to' => regenerate_url( 'action', '', '', '&' ),
  59      'cols' => 80,
  60      'skin_form_params' => array(),
  61      'display_navigation' => false,
  62      'display_title' => false,
  63      'messages_list_start' => '',
  64      'messages_list_end' => '',
  65      'messages_list_title' => $edited_Thread->title,
  66      ), $params );
  67  
  68  echo $params['messages_list_start'];
  69  
  70  if( $params['display_navigation'] )
  71  {    // Display navigation
  72      echo '<div class="messages_navigation">'
  73          .'<div class="floatleft">'
  74              .'<a href="'.get_dispctrl_url( 'threads' ).'">&laquo; '.T_('Back to list').'</a>'
  75          .'</div>'
  76          .get_thread_prevnext_links( $edited_Thread->ID )
  77          .'<div class="clear"></div>'
  78      .'</div>';
  79  }
  80  
  81  if( $params['display_title'] )
  82  {    // Display title
  83      echo '<h2>'.$edited_Thread->title.'</h2>';
  84  }
  85  
  86  // load Thread recipients
  87  $recipient_list = $edited_Thread->load_recipients();
  88  // load Thread recipient users into the UserCache
  89  $UserCache = & get_UserCache();
  90  $UserCache->load_list( $recipient_list );
  91  
  92  // Select all recipients with their statuses
  93  $recipients_status_SQL = new SQL();
  94  
  95  $recipients_status_SQL->SELECT( 'tsta_user_ID as user_ID, tsta_first_unread_msg_ID, tsta_thread_leave_msg_ID' );
  96  
  97  $recipients_status_SQL->FROM( 'T_messaging__threadstatus' );
  98  
  99  $recipients_status_SQL->WHERE( 'tsta_thread_ID = '.$edited_Thread->ID );
 100  
 101  $recipient_status_list = $DB->get_results( $recipients_status_SQL->get() );
 102  $read_status_list = array();
 103  $leave_status_list = array();
 104  foreach( $recipient_status_list as $row )
 105  {
 106      $read_status_list[ $row->user_ID ] = $row->tsta_first_unread_msg_ID;
 107      $leave_status_list[ $row->user_ID ] = $row->tsta_thread_leave_msg_ID;
 108  }
 109  $is_recipient = $edited_Thread->check_thread_recipient( $current_User->ID );
 110  $leave_msg_ID = ( $is_recipient ? $leave_status_list[ $current_User->ID ] : NULL );
 111  
 112  // Create SELECT query:
 113  $select_SQL = new SQL();
 114  
 115  $select_SQL->SELECT( 'mm.msg_ID, mm.msg_author_user_ID, mm.msg_thread_ID, mm.msg_datetime,
 116                          u.user_ID AS msg_user_ID, u.user_login AS msg_author,
 117                          u.user_firstname AS msg_firstname, u.user_lastname AS msg_lastname,
 118                          u.user_avatar_file_ID AS msg_user_avatar_ID,
 119                          mm.msg_text, '.$DB->quote( $edited_Thread->title ).' AS thread_title' );
 120  
 121  $select_SQL->FROM( 'T_messaging__message mm
 122                          LEFT OUTER JOIN T_users u ON u.user_ID = mm.msg_author_user_ID' );
 123  
 124  $select_SQL->WHERE( 'mm.msg_thread_ID = '.$edited_Thread->ID );
 125  if( !empty( $leave_msg_ID ) && ( !$perm_abuse_management ) )
 126  {
 127      $select_SQL->WHERE_and( 'mm.msg_ID <= '.$leave_msg_ID );
 128  }
 129  
 130  $select_SQL->ORDER_BY( 'mm.msg_datetime DESC' );
 131  
 132  // Create COUNT query
 133  
 134  $count_SQL = new SQL();
 135  $count_SQL->SELECT( 'COUNT(*)' );
 136  
 137  // Get params from request
 138  $s = param( 's', 'string', '', true );
 139  
 140  if( !empty( $s ) )
 141  {
 142      $select_SQL->WHERE_and( 'CONCAT_WS( " ", u.user_login, u.user_firstname, u.user_lastname, u.user_nickname, msg_text ) LIKE "%'.$DB->escape($s).'%"' );
 143  
 144      $count_SQL->FROM( 'T_messaging__message mm LEFT OUTER JOIN T_users u ON u.user_ID = mm.msg_author_user_ID' );
 145      $count_SQL->WHERE( 'mm.msg_thread_ID = '.$edited_Thread->ID );
 146      $count_SQL->WHERE_and( 'CONCAT_WS( " ", u.user_login, u.user_firstname, u.user_lastname, u.user_nickname, msg_text ) LIKE "%'.$DB->escape($s).'%"' );
 147  }
 148  else
 149  {
 150      $count_SQL->FROM( 'T_messaging__message' );
 151      $count_SQL->WHERE( 'msg_thread_ID = '.$edited_Thread->ID );
 152  }
 153  
 154  // Create result set:
 155  
 156  $Results = new Results( $select_SQL->get(), 'msg_', '', 0, $count_SQL->get() );
 157  
 158  $Results->Cache = & get_MessageCache();
 159  
 160  $Results->title = $params['messages_list_title'];
 161  
 162  if( is_admin_page() )
 163  {
 164      $Results->global_icon( T_('Cancel!'), 'close', '?ctrl=threads' );
 165  }
 166  
 167  /**
 168   * Callback to add filters on top of the result set
 169   *
 170   * @param Form
 171   */
 172  function filter_messages( & $Form )
 173  {
 174      $Form->text( 's', get_param('s'), 30, T_('Search'), '', 255 );
 175  }
 176  
 177  $Results->filter_area = array(
 178      'submit_title' => T_('Filter messages'),
 179      'callback' => 'filter_messages',
 180      'presets' => array(
 181          'all' => array( T_('All'), get_dispctrl_url( 'messages', 'thrd_ID='.$edited_Thread->ID ) ),
 182          )
 183      );
 184  
 185  /*
 186   * Author col:
 187   */
 188  
 189  /**
 190   * Create author cell for message list table
 191   *
 192   * @param integer user ID
 193   * @param string login
 194   * @param string first name
 195   * @param string last name
 196   * @param integer avatar ID
 197   * @param string datetime
 198   */
 199  function author( $user_ID, $datetime)
 200  {
 201      $author = get_user_avatar_styled( $user_ID, array( 'size' => 'crop-top-80x80' ) );
 202      return $author.'<div class="note black">'.mysql2date( locale_datefmt().'<\b\r />'.str_replace( ':s', '', locale_timefmt() ), $datetime ).'</div>';
 203  }
 204  $Results->cols[] = array(
 205          'th' => T_('Author'),
 206          'th_class' => 'shrinkwrap',
 207          'td_class' => 'center top',
 208          'td' => '%author( #msg_user_ID#, #msg_datetime#)%'
 209      );
 210  
 211  function format_msg_text( $msg_text, $thread_title )
 212  {
 213      global $evo_charset;
 214      
 215      if( empty( $msg_text ) )
 216      {
 217          return format_to_output( $thread_title, 'htmlspecialchars' );
 218      }
 219  
 220      // WARNING: the messages may contain MALICIOUS HTML and javascript snippets. They must ALWAYS be ESCAPED prior to display!
 221      $msg_text = htmlentities( $msg_text, ENT_COMPAT, $evo_charset );
 222  
 223      $msg_text = make_clickable( $msg_text );
 224      $msg_text = preg_replace( '#<a #i', '<a rel="nofollow" target="_blank"', $msg_text );
 225      $msg_text = nl2br( $msg_text );
 226  
 227      return $msg_text;
 228  }
 229  /*
 230   * Message col
 231   */
 232  $Results->cols[] = array(
 233          'th' => T_('Message'),
 234          'td_class' => 'left top message_text',
 235          'td' => '%format_msg_text( #msg_text#, #thread_title# )%',
 236      );
 237  
 238  function get_read_by( $message_ID )
 239  {
 240      global $read_status_list, $leave_status_list, $Blog, $current_User, $perm_abuse_management;
 241  
 242      $UserCache = & get_UserCache();
 243  
 244      if( empty( $Blog ) )
 245      {    // Set avatar size for a case when blog is not defined
 246          $avatar_size = 'crop-top-32x32';
 247      }
 248      else
 249      {    // Get avatar size from blog settings
 250          $avatar_size = $Blog->get_setting('image_size_messaging');
 251      }
 252  
 253      $read_recipients = array();
 254      $unread_recipients = array();
 255      foreach( $read_status_list as $user_ID => $first_unread_msg_ID )
 256      {
 257          if( $user_ID == $current_User->ID )
 258          { // Current user status: current user should not be displayed except in case of abuse management
 259              if( $perm_abuse_management )
 260              { // current user has seen all received messages for sure, set first unread msg to NULL
 261                  $first_unread_msg_ID = NULL;
 262              }
 263              else
 264              { // not abuse management
 265                  continue;
 266              }
 267          }
 268  
 269          $recipient_User = $UserCache->get_by_ID( $user_ID, false );
 270          if( !$recipient_User )
 271          { // user not exists
 272              continue;
 273          }
 274  
 275          $leave_msg_ID = $leave_status_list[ $user_ID ];
 276          if( !empty( $leave_msg_ID ) && ( $leave_msg_ID < $message_ID ) )
 277          { // user has left the conversation and didn't receive this message
 278              $left_recipients[] = $recipient_User->login;
 279          }
 280          elseif( empty( $first_unread_msg_ID ) || ( $first_unread_msg_ID > $message_ID ) )
 281          { // user has read all message from this thread or at least this message
 282              // user didn't leave the conversation before this message
 283              $read_recipients[] = $recipient_User->login;
 284          }
 285          else
 286          { // User didn't read this message, but didn't leave the conversation either
 287              $unread_recipients[] = $recipient_User->login;
 288          }
 289      }
 290  
 291      $read_by = '';
 292      if( !empty( $read_recipients ) )
 293      { // There are users who have read this message
 294          asort( $read_recipients );
 295          $read_by .= '<div>'.get_avatar_imgtags( $read_recipients, true, false, $avatar_size, '', '', true, false );
 296          if( !empty ( $unread_recipients ) )
 297          {
 298              $read_by .= '<br />';
 299          }
 300          $read_by .= '</div>';
 301      }
 302  
 303      if( !empty ( $unread_recipients ) )
 304      { // There are users who didn't read this message
 305          asort( $unread_recipients );
 306          $read_by .= '<div>'.get_avatar_imgtags( $unread_recipients, true, false, $avatar_size, '', '', false, false ).'</div>';
 307      }
 308  
 309      if( !empty ( $left_recipients ) )
 310      { // There are users who left the conversation before this message
 311          asort( $left_recipients );
 312          $read_by .= '<div>'.get_avatar_imgtags( $left_recipients, true, false, $avatar_size, '', '', 'left_message', false ).'</div>';
 313      }
 314      return $read_by;
 315  }
 316  
 317  $Results->cols[] = array(
 318                      'th' => T_('Read?'),
 319                      'th_class' => 'shrinkwrap',
 320                      'td_class' => 'top',
 321                      'td' => '%get_read_by( #msg_ID# )%',
 322                      );
 323  
 324  function delete_action( $thrd_ID, $msg_ID )
 325  {
 326      global $Blog, $samedomain_htsrv_url, $perm_abuse_management;
 327      if( is_admin_page() )
 328      {
 329          $tab = '';
 330          if( $perm_abuse_management )
 331          {    // We are in Abuse Management
 332              $tab = '&tab=abuse';
 333          }
 334          return action_icon( T_( 'Delete'), 'delete', regenerate_url( 'action', 'thrd_ID='.$thrd_ID.'&msg_ID='.$msg_ID.'&action=delete'.$tab.'&'.url_crumb( 'messaging_messages' ) ) );
 335      }
 336      else
 337      {
 338          $redirect_to = url_add_param( $Blog->gen_blogurl(), 'disp=messages&thrd_ID='.$thrd_ID );
 339          $action_url = $samedomain_htsrv_url.'action.php?mname=messaging&disp=messages&thrd_ID='.$thrd_ID.'&msg_ID='.$msg_ID.'&action=delete';
 340          $action_url = url_add_param( $action_url, 'redirect_to='.rawurlencode( $redirect_to ), '&' );
 341          return action_icon( T_( 'Delete'), 'delete', $action_url.'&'.url_crumb( 'messaging_messages' ) );
 342      }
 343  }
 344  
 345  if( $current_User->check_perm( 'perm_messaging', 'delete' ) && $Results->total_rows > 1 )
 346  {    // We have permission to modify and there are more than 1 message (otherwise it's better to delete the whole thread):
 347      $Results->cols[] = array(
 348                              'th' => T_('Del'),
 349                              'th_class' => 'shrinkwrap',
 350                              'td_class' => 'shrinkwrap',
 351                              'td' => '%delete_action( #msg_thread_ID#, #msg_ID#)%',
 352                          );
 353  }
 354  
 355  if( $is_recipient )
 356  { // Current user is involved in this thread, only involved users can send a message
 357      // we had to check this because admin user can see all messages in 'Abuse management', but should not be able to reply
 358      // get all available recipient in this thread
 359      $available_recipients = array();
 360      foreach( $recipient_list as $recipient_ID )
 361      {
 362          $recipient_User = & $UserCache->get_by_ID( $recipient_ID, false );
 363          if( ( $recipient_ID != $current_User->ID ) && $recipient_User && !$recipient_User->check_status( 'is_closed' ) && empty( $leave_status_list[ $recipient_ID ] ) )
 364          {
 365              $available_recipients[ $recipient_ID ] = $recipient_User->login;
 366          }
 367      }
 368      if( empty( $available_recipients ) )
 369      { // There are no other existing and not closed users who are still part of this conversation
 370          echo '<span class="error">'.T_( 'You cannot reply because this conversation was closed.' ).'</span>';
 371      }
 372      elseif( !empty( $leave_msg_ID ) )
 373      { // Current user has already left this conversation
 374          echo '<span class="error">'.T_( 'You cannot reply because you have already left this conversation.' ).'</span>';
 375      }
 376      else
 377      { // Current user is still part of this conversation, should be able to reply
 378          $Form = new Form( $params[ 'form_action' ], $params[ 'form_name' ], 'post', $params[ 'form_layout' ] );
 379  
 380          $Form->switch_template_parts( $params['skin_form_params'] );
 381  
 382          $Form->begin_form( $params['form_class'], '' );
 383  
 384              $Form->add_crumb( 'messaging_messages' );
 385              if( $perm_abuse_management )
 386              {    // To back in the abuse management
 387                  memorize_param( 'tab', 'string', 'abuse' );
 388              }
 389              $Form->hiddens_by_key( get_memorized( 'action'.( $creating ? ',msg_ID' : '' ) ) ); // (this allows to come back to the right list order & page)
 390              $Form->hidden( 'redirect_to', $params[ 'redirect_to' ] );
 391  
 392              $Form->info_field(T_('Reply to'), get_avatar_imgtags( $available_recipients, true, true, 'crop-top-15x15', 'avatar_before_login mb1' ), array('required'=>true));
 393  
 394              if( !empty( $closed_recipients ) )
 395              {
 396                  $Form->info_field( '', T_( 'The other users involved in this conversation have closed their account.' ) );
 397              }
 398  
 399              $Form->textarea('msg_text', '', 10, T_('Message'), '', $params[ 'cols' ], '', true);
 400  
 401          $Form->end_form( array( array( 'submit', 'actionArray[create]', T_('Send message'), 'SaveButton' ) ) );
 402      }
 403  }
 404  
 405  // Display Leave or Close conversation action if they are available
 406  if( $is_recipient && empty( $leave_msg_ID ) && ( count( $available_recipients ) > 0 ) )
 407  { // user is recipient and didn't leave this conversation yet and this conversation is not closed
 408      echo '<div class="fieldset messages_list_actions">';
 409      if( count( $available_recipients ) > 1 )
 410      { // there are more then one recipients
 411          $leave_text = T_( 'I want to leave this conversation now!' );
 412          $confirm_leave_text = TS_( 'If you leave this conversation,\\nother users can still continue the conversation\\nbut you will not receive their future replies.\\nAre you sure?' );
 413          $leave_action = 'leave';
 414      }
 415      else
 416      { // only one recipient exists if the user leave the conversation then it will be closed.
 417          $recipient_ID = key( $available_recipients );
 418          $recipient_login = $available_recipients[$recipient_ID];
 419          $leave_text = get_icon( 'stop', 'imgtag', array( 'style' => 'margin-right:5px' ) ).T_( 'I want to end this conversation now!' );
 420          $block_text = get_icon( 'ban', 'imgtag', array( 'style' => 'margin:0 7px 2px 1px;vertical-align:middle;' ) ).sprintf( T_( 'I want to block %s from sending me any more messages!' ), $recipient_login );
 421          $confirm_leave_text = T_( 'Are you sure you want to close this conversation?' );
 422          $confirm_block_text = sprintf( TS_( 'This action will close this conversion\\nand will block %s from starting any new\\nconversation with you.\\n(You can see blocked users in your contacts list)\\nAre you sure you want to close and block?' ), $recipient_login );
 423          $leave_action = 'close';
 424      }
 425      if( is_admin_page() )
 426      { // backoffice
 427          $leave_url = '?ctrl=threads&thrd_ID='.$edited_Thread->ID.'&action='.$leave_action.'&'.url_crumb( 'messaging_threads' );
 428          $close_and_block_url = '?ctrl=threads&thrd_ID='.$edited_Thread->ID.'&action=close_and_block&block_ID='.$recipient_ID.'&'.url_crumb( 'messaging_threads' );
 429      }
 430      else
 431      { // frontoffice
 432          $leave_url = url_add_param( $params[ 'form_action' ], 'disp=threads&thrd_ID='.$edited_Thread->ID.'&action='.$leave_action.'&redirect_to='.rawurlencode( url_add_param( $Blog->gen_blogurl(), 'disp=threads', '&' ) ).'&'.url_crumb( 'messaging_threads' ) );
 433          $close_and_block_url = url_add_param( $params[ 'form_action' ], 'disp=threads&thrd_ID='.$edited_Thread->ID.'&action=close_and_block&block_ID='.$recipient_ID.'&redirect_to='.rawurlencode( url_add_param( $Blog->gen_blogurl(), 'disp=threads', '&' ) ).'&'.url_crumb( 'messaging_threads' ) );
 434      }
 435      echo '<p>';
 436      echo '<a href="'.$leave_url.'" onclick="return confirm( \''.$confirm_leave_text.'\' );">'.$leave_text.'</a>';
 437      if( $leave_action == 'close' )
 438      { // user want's to close this conversation ( there is only one recipient )
 439          echo '<br />';
 440          echo '<a href="'.$close_and_block_url.'" onclick="return confirm( \''.$confirm_block_text.'\' );">'.$block_text.'</a>';
 441      }
 442      echo '</p>';
 443      echo '</div>';
 444  }
 445  
 446  // Disable rollover effect on table rows
 447  $Results->display_init( $display_params );
 448  $display_params['list_start'] = str_replace( 'class="grouped', 'class="grouped nohover', $Results->params['list_start'] );
 449  
 450  // Dispaly message list
 451  $Results->display( $display_params );
 452  
 453  echo $params['messages_list_end'];
 454  
 455  ?>

title

Description

title

Description

title

Description

title

title

Body