PageRenderTime 26ms CodeModel.GetById 17ms RepoModel.GetById 0ms app.codeStats 0ms

/modules/live/actions/getmessages.act.php

http://awarenet.googlecode.com/
PHP | 89 lines | 46 code | 16 blank | 27 comment | 23 complexity | e989147b4dc3278a7c9bdb7a409632f9 MD5 | raw file
Possible License(s): GPL-3.0
  1. <?
  2. require_once($kapenta->installPath . 'modules/live/models/mailbox.mod.php');
  3. //--------------------------------------------------------------------------------------------------
  4. //* get all messages belonging to a page
  5. //--------------------------------------------------------------------------------------------------
  6. //+ reference should be a page UID (ID of rendered page in the browser)
  7. //+
  8. //+ optional argument: chatsince [datetime] may be POSTed, any messages for the current user since
  9. //+ this time will be added to output
  10. //----------------------------------------------------------------------------------------------
  11. // check reference, arguments and user
  12. //----------------------------------------------------------------------------------------------
  13. if ('' == $req->ref) { echo "ERROR: no UID given\n"; die(); }
  14. $model = new Live_Mailbox($req->ref, true);
  15. if (false == $model->loaded) {
  16. //------------------------------------------------------------------------------------------
  17. // no such mailbox, create it
  18. //------------------------------------------------------------------------------------------
  19. $model->pageUID = $req->ref;
  20. $model->userUID = $user->UID;
  21. echo "NEW: creating mailbox ID " . $model->UID . " for page " . $req->ref . "\n";
  22. $model->save();
  23. }
  24. //----------------------------------------------------------------------------------------------
  25. // return any (block) messages
  26. //----------------------------------------------------------------------------------------------
  27. if ('' == $model->messages) {
  28. // empty mailbox
  29. echo "EMPTY: no messages\n";
  30. } else {
  31. echo $model->messages;
  32. $model->messages = '';
  33. }
  34. $model->lastChecked = $kapenta->time();
  35. $model->save();
  36. //----------------------------------------------------------------------------------------------
  37. // return any (chat) messages
  38. //----------------------------------------------------------------------------------------------
  39. if (true == array_key_exists('chatsince', $_POST)) {
  40. //------------------------------------------------------------------------------------------
  41. // check argument and user role
  42. //------------------------------------------------------------------------------------------
  43. if ('public' == $user->role) { $page->doXmlError('please log in.'); } // no public users
  44. if ('banned' == $user->role) { $page->doXmlError('banned.'); } // banhammered
  45. $uUID = $db->addMarkup($user->UID);
  46. $datetime = $_POST['chatsince'];
  47. if (('' == $datetime) || ('0' == $datetime) || ('undefined' == $datetime))
  48. { $datetime = $db->datetime(time() - 1000000); }
  49. //------------------------------------------------------------------------------------------
  50. // load any new messsages from the database
  51. //------------------------------------------------------------------------------------------
  52. $conditions = array();
  53. $conditions[] = "createdOn > cast('" . $db->addMarkup($datetime) . "' as datetime)";
  54. $conditions[] = "ownerUID='" . $uUID . "'";
  55. $conditions[] = "state='new'";
  56. $range = $db->loadRange('live_chat', '*', $conditions, 'createdOn ASC');
  57. if (0 == count($range)) {
  58. echo "NOCHAT: no new messages ($datetime)\n";
  59. } else {
  60. foreach($range as $row) {
  61. echo 'chat:'
  62. . base64_encode($row['UID']) . '|'
  63. . base64_encode($row['fromUID']) . '|'
  64. . base64_encode($row['toUID']) . '|'
  65. . base64_encode($row['msg']) . '|'
  66. . base64_encode($row['sent']) . '|'
  67. . base64_encode($row['state']) . "|"
  68. . base64_encode($row['createdOn']) . "\n";
  69. }
  70. }
  71. }
  72. //TODO: update UserLogin here
  73. ?>