chat.ajax.php 940 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * Responses to AJAX calls
  5. */
  6. require_once '../global.inc.php';
  7. require_once api_get_path(LIBRARY_PATH).'chat.lib.php';
  8. $action = isset($_REQUEST['action']) ? $_REQUEST['action'] : null;
  9. if (api_is_anonymous()) {
  10. exit;
  11. }
  12. if (api_get_setting('allow_global_chat') == 'false') {
  13. exit;
  14. }
  15. $to_user_id = intval($_REQUEST['to']);
  16. $message = $_REQUEST['message'];
  17. if (!isset($_SESSION['chatHistory'])) {
  18. $_SESSION['chatHistory'] = array();
  19. }
  20. if (!isset($_SESSION['openChatBoxes'])) {
  21. $_SESSION['openChatBoxes'] = array();
  22. }
  23. $chat = new Chat();
  24. switch ($action) {
  25. case 'chatheartbeat':
  26. $chat->heartbeat();
  27. break;
  28. case 'closechat':
  29. $chat->close();
  30. break;
  31. case 'sendchat':
  32. $chat->send(api_get_user_id(), $_POST['to'], $_POST['message']);
  33. break;
  34. case 'startchatsession':
  35. $chat->start_session();
  36. break;
  37. default:
  38. echo '';
  39. }
  40. exit;