b2evolution

Multilingual multiuser multiblog engine

b2evolution Technical Documentation (CVS HEAD) [ class tree: main ] [ index: main ] [ all elements ]

Source for file threads.ctrl.php

Documentation is available at threads.ctrl.php

  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. $current_User->check_perm'perm_messaging''write'true );
  16.  
  17. // Set options path:
  18. $AdminUI->set_path'messaging''messages' );
  19.  
  20. // Get action parameter from request:
  21.  
  22. ifparam'thrd_ID''integer'''true) )
  23. {// Load thread from cache:
  24.     $ThreadCache get_ThreadCache();
  25.     if( ($edited_Thread $ThreadCache->get_by_ID$thrd_IDfalse )) === false )
  26.     {    unset$edited_Thread );
  27.         forget_param'thrd_ID' );
  28.         $Messages->addsprintfT_('Requested &laquo;%s&raquo; object does not exist any longer.')T_('Thread') )'error' );
  29.         $action 'nil';
  30.     }
  31. }
  32.  
  33. ifparam'msg_ID''integer'''true) )
  34. {// Load message from cache:
  35.     $MessageCache get_MessageCache();
  36.     if( ($edited_Message $MessageCache->get_by_ID$msg_IDfalse )) === false )
  37.     {    unset$edited_Message );
  38.         forget_param'msg_ID' );
  39.         $Messages->addsprintfT_('Requested &laquo;%s&raquo; object does not exist any longer.')T_('Message') )'error' );
  40.         $action 'nil';
  41.     }
  42. }
  43.  
  44. // Preload users to show theirs avatars
  45.  
  46. load_messaging_threads_recipients$current_User->ID );
  47.  
  48. switch$action )
  49. {
  50.     case 'new':
  51.         // Check permission:
  52.         $current_User->check_perm'perm_messaging''write'true );
  53.  
  54.         ifisset($edited_Message) )
  55.         {    // We don't have a model to use, start with blank object:
  56.             $edited_Thread new Thread();
  57.             $edited_Message new Message();
  58.         }
  59.         else
  60.         {    // Duplicate object in order no to mess with the cache:
  61.             $edited_Thread duplicate$edited_Message->Thread )// PHP4/5 abstraction
  62.             $edited_Message duplicate$edited_Message )// PHP4/5 abstraction
  63.             $edited_Message->ID 0;
  64.         }
  65.         $edited_Message->Thread $edited_Thread;
  66.  
  67.         break;
  68.  
  69.     case 'create'// Record new thread
  70.         // Check that this action request is not a CSRF hacked request:
  71.         $Session->assert_received_crumb'thread' );
  72.         
  73.         // Insert new thread:
  74.         $edited_Thread new Thread();
  75.         $edited_Message new Message();
  76.         $edited_Message->Thread $edited_Thread;
  77.  
  78.         // Check permission:
  79.         $current_User->check_perm'perm_messaging''write'true );
  80.  
  81.         param'thrd_recipients''string' );
  82.  
  83.         // Load data from request
  84.         if$edited_Message->load_from_Request() )
  85.         {    // We could load data from form without errors:
  86.  
  87.             if$current_User->check_perm'perm_messaging''reply' ) )
  88.             {
  89.                 $blocked_contacts check_blocked_contacts$edited_Thread->recipients_list );
  90.                 if!empty$blocked_contacts ) )
  91.                 {
  92.                     param_error'thrd_recipients'T_'You don\'t have permission to initiate conversations with the following users: ' )implode', '$blocked_contacts ) );
  93.                 }
  94.             }
  95.  
  96.             ifparam_errors_detected() )
  97.             {
  98.                 // Insert in DB:
  99.                 ifparam'thrdtype''string''discussion' == 'discussion' )
  100.                 {
  101.                     $edited_Message->dbinsert_discussion();
  102.                 }
  103.                 else
  104.                 {
  105.                     $edited_Message->dbinsert_individual();
  106.                 }
  107.  
  108.                 $Messages->addT_('New thread created.')'success' );
  109.  
  110.                 // What next?
  111.                 switch$action )
  112.                 {
  113.                     case 'create':
  114.                         // Redirect so that a reload doesn't write to the DB twice:
  115.                         header_redirect'?ctrl=threads'303 )// Will EXIT
  116.                         // We have EXITed already at this point!!
  117.                         break;
  118.                 }
  119.             }
  120.         }
  121.         break;
  122.  
  123.     case 'delete':
  124.         // Delete thread:
  125.         // Check that this action request is not a CSRF hacked request:
  126.         $Session->assert_received_crumb'thread' );
  127.  
  128.         // Check permission:
  129.         $current_User->check_perm'perm_messaging''delete'true );
  130.  
  131.         // Make sure we got an thrd_ID:
  132.         param'thrd_ID''integer'true );
  133.  
  134.         ifparam'confirm''integer') )
  135.         // confirmed, Delete from DB:
  136.             $msg sprintfT_('Thread &laquo;%s&raquo; deleted.')$edited_Thread->dget('title') );
  137.             $edited_Thread->dbdeletetrue );
  138.             unset$edited_Thread );
  139.             unset$edited_Message );
  140.             forget_param'thrd_ID' );
  141.             forget_param'msg_ID' );
  142.             $Messages->add$msg'success' );
  143.             // Redirect so that a reload doesn't write to the DB twice:
  144.             header_redirect'?ctrl=threads'303 )// Will EXIT
  145.             // We have EXITed already at this point!!
  146.         }
  147.         else
  148.         {    // not confirmed, Check for restrictions:
  149.             if$edited_Thread->check_deletesprintfT_('Cannot delete thread &laquo;%s&raquo;')$edited_Thread->dget('title') ) ) )
  150.             {    // There are restrictions:
  151.                 $action 'view';
  152.             }
  153.         }
  154.         break;
  155.  
  156. }
  157.  
  158. $AdminUI->breadcrumbpath_initfalse );  // fp> I'm playing with the idea of keeping the current blog in the path here...
  159. $AdminUI->breadcrumbpath_addT_('Messages')'?ctrl=threads' );
  160. $AdminUI->breadcrumbpath_addT_('Conversations')'?ctrl=threads' );
  161.  
  162. // Display <html><head>...</head> section! (Note: should be done early if actions do not redirect)
  163. $AdminUI->disp_html_head();
  164.  
  165. // Display title, menu, messages, etc. (Note: messages MUST be displayed AFTER the actions)
  166. $AdminUI->disp_body_top();
  167.  
  168. $AdminUI->disp_payload_begin();
  169.  
  170. /**
  171.  * Display payload:
  172.  */
  173. switch$action )
  174. {
  175.     case 'nil':
  176.         // Do nothing
  177.         break;
  178.  
  179.     case 'delete':
  180.         // We need to ask for confirmation:
  181.         $edited_Thread->confirm_delete(
  182.                 sprintfT_('Delete thread &laquo;%s&raquo;?')$edited_Thread->dget('title') ),
  183.                 'thread'$actionget_memorized'action' ) );
  184.         $AdminUI->disp_view'messaging/views/_thread_list.view.php' );
  185.         break;
  186.  
  187.     case 'new':
  188.     case 'create':
  189.         $AdminUI->disp_view'messaging/views/_thread.form.php' );
  190.         break;
  191.  
  192.     default:
  193.         // No specific request, list all threads:
  194.         // Cleanup context:
  195.         forget_param'thrd_ID' );
  196.         forget_param'msg_ID' );
  197.         // Display threads list:
  198.         $AdminUI->disp_view'messaging/views/_thread_list.view.php' );
  199.         break;
  200. }
  201.  
  202. $AdminUI->disp_payload_end();
  203.  
  204. // Display body bottom, debug info and close </html>:
  205. $AdminUI->disp_global_footer();
  206.  
  207. /*
  208.  * $Log: threads.ctrl.php,v $
  209.  * Revision 1.16  2010/01/30 18:55:32  blueyed
  210.  * Fix "Assigning the return value of new by reference is deprecated" (PHP 5.3)
  211.  *
  212.  * Revision 1.15  2010/01/15 16:57:38  efy-yury
  213.  * update messaging: crumbs
  214.  *
  215.  * Revision 1.14  2010/01/03 12:03:17  fplanque
  216.  * More crumbs...
  217.  *
  218.  * Revision 1.13  2009/12/06 22:55:20  fplanque
  219.  * Started breadcrumbs feature in admin.
  220.  * Work in progress. Help welcome ;)
  221.  * Also move file settings to Files tab and made FM always enabled
  222.  *
  223.  * Revision 1.12  2009/10/08 20:05:52  efy-maxim
  224.  * Modular/Pluggable Permissions
  225.  *
  226.  * Revision 1.11  2009/09/26 12:00:43  tblue246
  227.  * Minor/coding style
  228.  *
  229.  * Revision 1.10  2009/09/25 07:32:52  efy-cantor
  230.  * replace get_cache to get_*cache
  231.  *
  232.  * Revision 1.9  2009/09/19 20:31:38  efy-maxim
  233.  * 'Reply' permission : SQL queries to check permission ; Block/Unblock functionality; Error messages on insert thread/message
  234.  *
  235.  * Revision 1.8  2009/09/19 11:29:05  efy-maxim
  236.  * Refactoring
  237.  *
  238.  * Revision 1.7  2009/09/18 16:16:50  efy-maxim
  239.  * comments tab in messaging module
  240.  *
  241.  * Revision 1.6  2009/09/18 10:38:31  efy-maxim
  242.  * 15x15 icons next to login in messagin module
  243.  *
  244.  * Revision 1.5  2009/09/16 22:03:40  fplanque
  245.  * doc
  246.  *
  247.  */
  248. ?>

Documentation generated on Sat, 06 Mar 2010 03:58:18 +0100 by phpDocumentor 1.4.2. This site is hosted and maintained by Daniel HAHLER (Contact).