b2evolution PHP Cross Reference Blogging Systems

Source: /inc/messaging/threads.ctrl.php - 201 lines - 6069 bytes - Text - Print

   1  <?php
   2  
   3  if( !defined('EVO_MAIN_INIT') ) die( 'Please, do not access this page directly.' );
   4  
   5  // Load classes
   6  load_class( 'messaging/model/_thread.class.php', 'Thread' );
   7  load_class( 'messaging/model/_message.class.php', 'Message' );
   8  
   9  /**
  10   * @var User
  11   */
  12  global $current_User;
  13  
  14  // Check minimum permission:
  15  if( !$current_User->check_perm( 'perm_messaging', 'reply' ) )
  16  {
  17      $Messages->add( 'Sorry, you are not allowed to view threads!' );
  18      header_redirect( $admin_url );
  19  }
  20  
  21  // Set options path:
  22  $AdminUI->set_path( 'messaging', 'threads' );
  23  
  24  // Get action parameter from request:
  25  param_action();
  26  
  27  if( param( 'thrd_ID', 'integer', '', true) )
  28  {// Load thread from cache:
  29      $ThreadCache = & get_ThreadCache();
  30      if( ($edited_Thread = & $ThreadCache->get_by_ID( $thrd_ID, false )) === false )
  31      {    unset( $edited_Thread );
  32          forget_param( 'thrd_ID' );
  33          $Messages->add( sprintf( T_('Requested &laquo;%s&raquo; object does not exist any longer.'), T_('Thread') ), 'error' );
  34          $action = 'nil';
  35      }
  36  }
  37  
  38  // check params
  39  switch( $action )
  40  {
  41      case 'create':
  42          // Check that this action request is not a CSRF hacked request:
  43          $Session->assert_received_crumb( 'messaging_threads' );
  44          break;
  45      case 'delete':
  46      case 'leave':
  47      case 'close':
  48      case 'close_and_block':
  49          // Check that this action request is not a CSRF hacked request:
  50          $Session->assert_received_crumb( 'messaging_threads' );
  51  
  52          // Make sure we got a thrd_ID:
  53          param( 'thrd_ID', 'integer', true );
  54          break;
  55  }
  56  
  57  // handle action
  58  switch( $action )
  59  {
  60      case 'new':
  61          if( check_create_thread_limit( true ) )
  62          { // user has already reached his limit, don't allow to create new thread
  63              $action = '';
  64              break;
  65          }
  66  
  67          if( ! isset($edited_Message) )
  68          {    // We don't have a model to use, start with blank object:
  69              $edited_Thread = new Thread();
  70              $edited_Message = new Message();
  71          }
  72          else
  73          {    // Duplicate object in order no to mess with the cache:
  74              $edited_Thread = duplicate( $edited_Message->Thread ); // PHP4/5 abstraction
  75              $edited_Message = duplicate( $edited_Message ); // PHP4/5 abstraction
  76              $edited_Message->ID = 0;
  77          }
  78          $edited_Message->Thread = & $edited_Thread;
  79  
  80          init_tokeninput_js();
  81  
  82          break;
  83  
  84      case 'create': // Record new thread
  85          if( check_create_thread_limit() )
  86          { // max new threads limit reached, don't allow to create new thread
  87              debug_die( 'Invalid request, new conversation limit already reached!' );
  88          }
  89  
  90          // the create_new_thread() funciton will create required Thread and Message objects
  91          if( create_new_thread() )
  92          { // new thread has been created successful
  93              // Redirect so that a reload doesn't write to the DB twice:
  94              header_redirect( '?ctrl=threads', 303 ); // Will EXIT
  95              // We have EXITed already at this point!!
  96          }
  97  
  98          init_tokeninput_js();
  99  
 100          break;
 101  
 102      case 'delete': // Delete thread:
 103          // Check permission:
 104          $current_User->check_perm( 'perm_messaging', 'delete', true );
 105  
 106          if( param( 'confirm', 'integer', 0 ) )
 107          { // confirmed, Delete from DB:
 108              $msg = sprintf( T_('Thread &laquo;%s&raquo; deleted.'), $edited_Thread->dget('title') );
 109              $edited_Thread->dbdelete( true );
 110              unset( $edited_Thread );
 111              unset( $edited_Message );
 112              forget_param( 'thrd_ID' );
 113              forget_param( 'msg_ID' );
 114              $Messages->add( $msg, 'success' );
 115              // Redirect so that a reload doesn't write to the DB twice:
 116              $redirect_to = param( 'redirect_to', 'url', '?ctrl=threads' );
 117              header_redirect( $redirect_to, 303 ); // Will EXIT
 118              // We have EXITed already at this point!!
 119          }
 120          else
 121          { // not confirmed, Check for restrictions:
 122              if( ! $edited_Thread->check_delete( sprintf( T_('Cannot delete thread &laquo;%s&raquo;'), $edited_Thread->dget('title') ) ) )
 123              { // There are restrictions:
 124                  $action = 'view';
 125              }
 126          }
 127          break;
 128  
 129      case 'leave': // Leave thread:
 130          leave_thread( $edited_Thread->ID, $current_User->ID, false );
 131  
 132          $Messages->add( sprintf( T_( 'You have successfuly left the &laquo;%s&raquo; conversation!' ), $edited_Thread->get( 'title' ) ), 'success' );
 133          break;
 134  
 135      case 'close': // Close thread:
 136      case 'close_and_block': // Close thread and block contact:
 137          leave_thread( $edited_Thread->ID, $current_User->ID, true );
 138  
 139          $Messages->add( sprintf( T_( 'You have successfuly closed the &laquo;%s&raquo; conversation!' ), $edited_Thread->get( 'title' ) ), 'success' );
 140          if( $action == 'close_and_block' )
 141          { // also block the given contact
 142              $block_user_ID = param( 'block_ID', 'integer', true );
 143              $UserCache = & get_UserCache();
 144              $blocked_User = $UserCache->get_by_ID( $block_user_ID );
 145  
 146              set_contact_blocked( $block_user_ID, true );
 147              $Messages->add( sprintf( T_( '&laquo;%s&raquo; was blocked.' ), $blocked_User->get( 'login' ) ), 'success' );
 148          }
 149          break;
 150  }
 151  
 152  $AdminUI->breadcrumbpath_init( false );  // fp> I'm playing with the idea of keeping the current blog in the path here...
 153  $AdminUI->breadcrumbpath_add( T_('Messages'), '?ctrl=threads' );
 154  $AdminUI->breadcrumbpath_add( T_('Conversations'), '?ctrl=threads' );
 155  
 156  // Display <html><head>...</head> section! (Note: should be done early if actions do not redirect)
 157  $AdminUI->disp_html_head();
 158  
 159  // Display title, menu, messages, etc. (Note: messages MUST be displayed AFTER the actions)
 160  $AdminUI->disp_body_top();
 161  
 162  $AdminUI->disp_payload_begin();
 163  
 164  /**
 165   * Display payload:
 166   */
 167  switch( $action )
 168  {
 169      case 'nil':
 170          // Do nothing
 171          break;
 172  
 173      case 'delete':
 174          // We need to ask for confirmation:
 175          $edited_Thread->confirm_delete(
 176                  sprintf( T_('Delete thread &laquo;%s&raquo;?'), $edited_Thread->dget('title') ),
 177                  'messaging_threads', $action, get_memorized( 'action' ) );
 178          $AdminUI->disp_view( 'messaging/views/_thread_list.view.php' );
 179          break;
 180  
 181      case 'new':
 182      case 'create':
 183          $AdminUI->disp_view( 'messaging/views/_thread.form.php' );
 184          break;
 185  
 186      default:
 187          // No specific request, list all threads:
 188          // Cleanup context:
 189          forget_param( 'thrd_ID' );
 190          forget_param( 'msg_ID' );
 191          // Display threads list:
 192          $AdminUI->disp_view( 'messaging/views/_thread_list.view.php' );
 193          break;
 194  }
 195  
 196  $AdminUI->disp_payload_end();
 197  
 198  // Display body bottom, debug info and close </html>:
 199  $AdminUI->disp_global_footer();
 200  
 201  ?>

title

Description

title

Description

title

Description

title

title

Body