PageRenderTime 544ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 0ms

/modules/shoutbox/shoutqueries.php

http://lansuite.googlecode.com/
PHP | 139 lines | 58 code | 80 blank | 1 comment | 8 complexity | e41a684ea748e1fe5fa6d23e7c0952db MD5 | raw file
Possible License(s): LGPL-3.0, AGPL-1.0, LGPL-2.1
  1. <?php
  2. $framework->set_modus('ajax');
  3. switch($_GET['shout']) {
  4. case 'add':
  5. if($_POST['captchaInputSend'] == $_SESSION['captcha'] and $_POST['captchaInputSend'] != "")
  6. $captchaCheck = true;
  7. else
  8. $captchaCheck = false;
  9. if(!$auth['login'] or !$captchaCheck)
  10. {
  11. // No Login -> Captcha
  12. include_once('ext_scripts/ascii_captcha.class.php');
  13. $captcha = new ASCII_Captcha();
  14. $cap = $captcha->create($text);
  15. $_SESSION['captcha'] = $text;
  16. $data['response'] = 'captcha';
  17. $data['code'] = $text;
  18. $data['captcha'] = $cap;
  19. }
  20. if(($_POST['message'] and $auth['login']) or ($_POST['message'] and $captchaCheck))
  21. {
  22. if($auth['type']>=1)
  23. $_POST['nickname'] = $auth['username'];
  24. $result = $db->qry("INSERT INTO %prefix%shoutbox (userid, ip, name, message) VALUES (%int%,%string%,%string%,%string%)",$auth['userid'],$auth['ip'],$_POST["nickname"],$_POST["message"]);
  25. $resp = $db->qry_first("SELECT id, created FROM %prefix%shoutbox WHERE id = %int%",$db->insert_id());
  26. $data['response'] = 'Good work';
  27. $data['nickname'] = $_POST['nickname'];
  28. $data['message'] = $_POST['message'];
  29. $data['time'] = strtotime($resp['created']);
  30. $data['id'] = $resp['id'];
  31. }
  32. break;
  33. case 'view':
  34. $data = array();
  35. if(!$_GET['lastid'])
  36. $_GET['lastid'] = 0;
  37. $qry = $db->qry('SELECT * FROM %prefix%shoutbox WHERE id > %int% ORDER BY ID DESC LIMIT %int%',$_GET['lastid'],$cfg['shout_entries']);
  38. while ($row = $db->fetch_array($qry)) {
  39. $data[] = array(
  40. "message"=>$row['message'],
  41. "nickname"=>$row['name'],
  42. "time"=>strtotime($row['created']),
  43. "id"=>$row['id']
  44. );
  45. }
  46. $data = array_reverse($data);
  47. $db->free_result($qry);
  48. break;
  49. }
  50. require_once('ext_scripts/json/json.php');
  51. $json = new Services_JSON();
  52. header("Content-Type: application/json; charset=utf-8");
  53. header("Last-Modified: ".gmdate("D, d M Y H:i:s")." GMT");
  54. header("Cache-Control: no-store, no-cache, must-revalidate");
  55. header("Cache-Control: post-check=0, pre-check=0", false);
  56. header("Pragma: no-cache");
  57. $out = $json->encode($data);
  58. print $out;
  59. ?>