Advertisement
Corey

Untitled

Mar 19th, 2011
246
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 4.26 KB | None | 0 0
  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.             if ($OSPHPChat->User->auth->check_auth('main_talk'))
  21.             {
  22.                 if ($message{0} == '/')
  23.                 {
  24.                     $message = substr($message, 1);
  25.                     $cmd = explode(' ', $message, 2);
  26.                     if (file_exists('modules/chat/commands/' . $cmd[0] . '.php'))
  27.                     {
  28.                         include('commands/' . $cmd[0] . '.php');
  29.                         $command = $cmd[0];
  30.                         $command = new $command(&$OSPHPChat, $message);
  31.                         if ($command->allowed())
  32.                         {
  33.                             if (stristr($message, '-help'))
  34.                             {
  35.                                 $data = array(
  36.                                     'user_id' => $OSPHPChat->User->user_info['id'],
  37.                                     'to' => 'room:' . $OSPHPChat->Messages->room . ';',
  38.                                     'message' => $command->help(),
  39.                                     'date' => $OSPHPChat->data,
  40.                                     'time' => $OSPHPChat->time,
  41.                                     'color' => $OSPHPChat->User->user_info['message_color'],
  42.                                     'user_color' => $OSPHPChat->User->user_info['user_color'],
  43.                                     'username' => $OSPHPChat->User->user_info['username']
  44.                                 );
  45.                                 $OSPHPChat->Messages->send_message($data);
  46.                             }
  47.                             else
  48.                             {
  49.                                 $command->execute();
  50.                             }
  51.                         }
  52.                         else
  53.                         {
  54.                             $error = "You are not permitted to use this command.";
  55.                         }
  56.                     }
  57.                 }
  58.                 else
  59.                 {
  60.                     $data = array(
  61.                         'user_id' => $OSPHPChat->User->user_info['id'],
  62.                         'to' => 'room:' . $OSPHPChat->Messages->room . ';',
  63.                         'message' => $message,
  64.                         'date' => $OSPHPChat->data,
  65.                         'time' => $OSPHPChat->time,
  66.                         'color' => $OSPHPChat->User->user_info['message_color'],
  67.                         'user_color' => $OSPHPChat->User->user_info['user_color'],
  68.                         'username' => $OSPHPChat->User->user_info['username']
  69.                     );
  70.                     $OSPHPChat->Messages->send_message($data);
  71.                 }
  72.             }
  73.             else
  74.             {
  75.                 $error = "You are not permitted to talk.";
  76.             }
  77.         }
  78.         else
  79.         {
  80.             $error = "You cannot send blank messages.";
  81.         }
  82.         if ($error)
  83.         {
  84.             echo json_encode($error);
  85.         }
  86.     }
  87.     elseif ($mode == 'load')
  88.     {
  89.         $OSPHPChat->Messages->starting_id = $_SESSION['last_message'];
  90.         $OSPHPChat->Messages->get_messages();
  91.         $Messages = array();
  92.         foreach ($OSPHPChat->Messages->get_messages() as $message)
  93.         {
  94.             // Establishes User Color \\
  95.             if (isset($message['user_color']))
  96.             {
  97.                 $message['sender'] = "<a href='#' style='color:#" . $message['user_color'] . ";'>" . $message['username'] . "</a>";
  98.             }
  99.             else
  100.             {
  101.                 $message['sender'] = "<a href='#'>" . $message['username'] . "</a>";
  102.             }
  103.  
  104.             // Establishes Message Color \\
  105.             if (isset($message['color']))
  106.             {
  107.                 $message['text'] = "<span style='color:#" . $message['color'] . ";'>" . $message['message'] . "</span>";
  108.             }
  109.             else
  110.             {
  111.                 $message['text'] = "<span>" . $message['message'] . "</span>";
  112.             }
  113.  
  114.             $_SESSION['last_message'] = $message['id'];
  115.             $Smarty->assign('message', $message);
  116.             $Messages[] = $Smarty->fetch('_message.tpl');
  117.         }
  118.         echo json_encode($Messages);
  119.     }
  120.     elseif ($mode == 'users')
  121.     {
  122.         $offline_time = time() - 15;
  123.         // Getting [new] online users \\
  124.         $online_users = $OSPHPChat->db->Execute("SELECT * FROM `" . $OSPHPChat->config['database']['tables']['users'] . "` WHERE `online_time`> '" . $offline_time . "'");
  125.         while ($online_user = $online_users->FetchRow())
  126.         {
  127.             $All_users[$online_user['id']] = array(
  128.                 'id' => $online_user['id'],
  129.                 'username' => $online_user['username']
  130.             );
  131.             if (!isset($_SESSION['online_users'][$online_user['id']]))
  132.             {
  133.                 $Smarty->assign('user', $online_user);
  134.                 $Users[online][$online_user['id']] = array(
  135.                     'html' => $Smarty->fetch('_user_list.tpl'),
  136.                     'id' => $online_user['id']
  137.                 );
  138.             }
  139.             $Userids_online[$online_user['id']] = $online_user['username'];
  140.         }
  141.         // Removing offline users \\
  142.         if (is_array($_SESSION['online_users']))
  143.         {
  144.             foreach ($_SESSION['online_users'] as $online_user)
  145.             {
  146.                 if (!isset($Userids_online[$online_user['id']]))
  147.                 {
  148.                     $Users['offline'][] = $online_user;
  149.                 }
  150.             }
  151.         }
  152.         $_SESSION['online_users'] = $All_users;
  153.         echo json_encode($Users);
  154.     }
  155. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement