php-es.org


Welcome! Here you can paste sources and general debugging text, You can even set yourself a password if you want to keep it just for yourself.

Posted by OSPHPChat on March Sat 19th 2:56 AM - Never Expires
Download | New paste

  1. <?php
  2.         /**
  3.         /*           OSPHPChat Alpha 1 - 2011
  4.         /*
  5.         /*           File: /modules/chat/ajax.php
  6.         /*
  7.         /*           Website: www.OSPHPChat.com
  8.         /*
  9.         /*           Author: Daniel Hood <danny@osphpchat.com>
  10.         /*
  11.         /*
  12.         /*
  13.         **/
  14.  
  15.         if ($mode == 'send')
  16.         {
  17.                 $message = $OSPHPChat->Purify->get('message', 'POST', 'string');
  18.                 if (isset($message) && !empty($message))
  19.                 {
  20.                         $data = array(
  21.                                 'user_id' => $OSPHPChat->User->user_info['id'],
  22.                                 'to' => 'room:' . $OSPHPChat->Messages->room . ';',
  23.                                 'message' => $message,
  24.                                 'date' => $OSPHPChat->data,
  25.                                 'time' => $OSPHPChat->time,
  26.                                 'color' => $OSPHPChat->User->user_info['message_color'],
  27.                                 'user_color' => $OSPHPChat->User->user_info['user_color'],
  28.                                 'username' => $OSPHPChat->User->user_info['username']
  29.                         );
  30.                         $OSPHPChat->Messages->send_message($data);
  31.                 }
  32.                 else
  33.                 {
  34.                         $OSPHPChat->Errors->error('You cannot send blank messages.');
  35.                 }
  36.         }
  37.         elseif ($mode == 'load')
  38.         {
  39.                 $OSPHPChat->Messages->starting_id = $_SESSION['last_message'];
  40.                 $OSPHPChat->Messages->get_messages();
  41.                 $Messages = array();
  42.                 foreach ($OSPHPChat->Messages->get_messages() as $message)
  43.                 {
  44.                         // Establishes User Color \\
  45.                         if (isset($message['user_color']))
  46.                         {
  47.                                 $message['sender'] = "<a href='#' style='color:#" . $message['user_color'] . ";'>" . $message['username'] . "</a>";
  48.                         }
  49.                         else
  50.                         {
  51.                                 $message['sender'] = "<a href='#'>" . $message['username'] . "</a>";
  52.                         }
  53.  
  54.                         // Establishes Message Color \\
  55.                         if (isset($message['color']))
  56.                         {
  57.                                 $message['text'] = "<span style='color:#" . $message['color'] . ";'>" . $message['message'] . "</span>";
  58.                         }
  59.                         else
  60.                         {
  61.                                 $message['text'] = "<span>" . $message['message'] . "</span>";
  62.                         }
  63.                         $_SESSION['last_message'] = $message['id'];
  64.                         $Smarty->assign('message', $message);
  65.                         $Messages[] = $Smarty->fetch('_message.tpl');
  66.                 }
  67.                 echo json_encode($Messages);
  68.         }
  69.         elseif ($mode == 'users')
  70.         {
  71.                 $offline_time = time() - 15;
  72.                 // Getting [new] online users \\
  73.                 $online_users = $OSPHPChat->db->Execute("SELECT * FROM `" . $OSPHPChat->config['database']['tables']['users'] . "` WHERE `online_time`> '" . $offline_time . "'");
  74.                 while ($online_user = $online_users->FetchRow())
  75.                 {
  76.                         $All_users[$online_user['id']] = $online_user;
  77.                         if (!isset($_SESSION['online_users'][$online_user['id']]))
  78.                         {
  79.                                 $Users[online][$online_user['id']] = $online_user;
  80.                         }
  81.                         $Userids_online[$online_user['id']] = $online_user['username'];
  82.                 }
  83.                 // Removing offline users \\
  84.                 if (is_array($_SESSION['online_users']))
  85.                 {
  86.                         foreach ($_SESSION['online_users'] as $online_user)
  87.                         {
  88.                                 if (!isset($Userids_online[$online_user['id']]))
  89.                                 {
  90.                                         $Users['offline'][] = $online_user;
  91.                                 }
  92.                         }
  93.                 }
  94.                 $_SESSION['online_users'] = $All_users;
  95.                 echo json_encode($Users);
  96.         }
  97. ?>
Language:
To highlight particular lines, prefix each line with @@





© 2012 - Powered by PASTE 1.0