Advertisement
Guest User

Untitled

a guest
Apr 15th, 2018
312
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.45 KB | None | 0 0
  1. <?php
  2. header("Content-Type: application/json;charset=utf-8");
  3. if(isset($_POST['mensagem'])){
  4. include_once "../defines.php";
  5. require_once('../classes/BD.class.php');
  6. BD::conn();
  7.  
  8. $mensagens = array();
  9. $id_conversa = (int)$_POST['conversacom'];
  10. $online = (int)$_POST['online'];
  11.  
  12. $pegaConversas = BD::conn()->prepare("SELECT * FROM `mensagens` WHERE (`id_de` = ? AND `id_para` = ?) OR (`id_de` = ? AND `id_para` = ?) ORDER BY `id` DESC LIMIT 10");
  13. $pegaConversas->execute(array($online, $id_conversa, $id_conversa, $online));
  14.  
  15. while($row = $pegaConversas->fetch()){
  16. $fotoUser = '';
  17. if($online == $row['id_de']){
  18. $janela_de = $row['id_para'];
  19.  
  20. }elseif($online == $row['id_para']){
  21. $janela_de = $row['id_de'];
  22.  
  23. $pegaFoto = BD::conn()->prepare("SELECT `foto` FROM `usuarios` WHERE `id` = '".$row['id_de']."'");
  24. $pegaFoto->execute();
  25.  
  26. while ($usr = $pegaFoto->fetch()){
  27. $fotoUser = ($usr['foto'] == '') ? 'default.jpg' : $usr['foto'];
  28. }
  29. }
  30.  
  31. $emotions = array(':P', ':$', ':|', ':O', '<3', ';*', ':%', ':@', ':D', ';D', ':A', ':"(', ':(', ':Z');
  32. $imgs = array(
  33. '<img src="smiles/tongue.png" width="16" height="16" border="0"/>',
  34. '<img src="smiles/redface.png" width="16" height="16" border="0"/>',
  35. '<img src="smiles/nada.png" width="16" height="16" border="0"/>',
  36. '<img src="smiles/espanto.png" width="16" height="16" border="0"/>',
  37. '<img src="smiles/blowkiss.png" width="16" height="16" border="0"/>',
  38. '<img src="smiles/kiss.png" width="16" height="16" border="0"/>',
  39. '<img src="smiles/zangado.png" width="16" height="16" border="0"/>',
  40. '<img src="smiles/mad.png" width="16" height="16" border="0"/>',
  41. '<img src="smiles/rindo.png" width="16" height="16" border="0"/>',
  42. '<img src="smiles/rindo2.png" width="16" height="16" border="0"/>',
  43. '<img src="smiles/anjo.png" width="16" height="16" border="0"/>',
  44. '<img src="smiles/choro.png" width="16" height="16" border="0"/>',
  45. '<img src="smiles/triste.png" width="16" height="16" border="0"/>',
  46. '<img src="smiles/dormindo.png" width="16" height="16" border="0"/>'
  47. );
  48. $msg = str_replace($emotions, $imgs, $row['mensagem']);
  49. $mensagens[] = array(
  50. 'id' => $row['id'],
  51. 'mensagem' => utf8_encode($msg),
  52. 'fotoUser' => $fotoUser,
  53. 'id_de' => $row['id_de'],
  54. 'id_para' => $row['id_para'],
  55. 'janela_de' => $janela_de
  56. );
  57. }
  58. die(json_encode($mensagens));
  59. }
  60. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement