PageRenderTime 61ms CodeModel.GetById 37ms RepoModel.GetById 1ms app.codeStats 0ms

/themesPlugin/web/themes/default/tinymce-3.4.7/jscripts/tiny_mce/plugins/spellchecker/rpc.php

https://github.com/juanda/symfonite
PHP | 111 lines | 66 code | 24 blank | 21 comment | 17 complexity | b3e206327510bd8ec63cb0157959cb91 MD5 | raw file
  1. <?php
  2. /**
  3. * $Id: rpc.php 822 2008-04-28 13:45:03Z spocke $
  4. *
  5. * @author Moxiecode
  6. * @copyright Copyright © 2004-2007, Moxiecode Systems AB, All rights reserved.
  7. */
  8. require_once("./includes/general.php");
  9. // Set RPC response headers
  10. header('Content-Type: text/plain');
  11. header('Content-Encoding: UTF-8');
  12. header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
  13. header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
  14. header("Cache-Control: no-store, no-cache, must-revalidate");
  15. header("Cache-Control: post-check=0, pre-check=0", false);
  16. header("Pragma: no-cache");
  17. $raw = "";
  18. // Try param
  19. if (isset($_POST["json_data"]))
  20. $raw = getRequestParam("json_data");
  21. // Try globals array
  22. if (!$raw && isset($_GLOBALS) && isset($_GLOBALS["HTTP_RAW_POST_DATA"]))
  23. $raw = $_GLOBALS["HTTP_RAW_POST_DATA"];
  24. // Try globals variable
  25. if (!$raw && isset($HTTP_RAW_POST_DATA))
  26. $raw = $HTTP_RAW_POST_DATA;
  27. // Try stream
  28. if (!$raw) {
  29. if (!function_exists('file_get_contents')) {
  30. $fp = fopen("php://input", "r");
  31. if ($fp) {
  32. $raw = "";
  33. while (!feof($fp))
  34. $raw = fread($fp, 1024);
  35. fclose($fp);
  36. }
  37. } else
  38. $raw = "" . file_get_contents("php://input");
  39. }
  40. // No input data
  41. if (!$raw)
  42. die('{"result":null,"id":null,"error":{"errstr":"Could not get raw post data.","errfile":"","errline":null,"errcontext":"","level":"FATAL"}}');
  43. // Passthrough request to remote server
  44. if (isset($config['general.remote_rpc_url'])) {
  45. $url = parse_url($config['general.remote_rpc_url']);
  46. // Setup request
  47. $req = "POST " . $url["path"] . " HTTP/1.0\r\n";
  48. $req .= "Connection: close\r\n";
  49. $req .= "Host: " . $url['host'] . "\r\n";
  50. $req .= "Content-Length: " . strlen($raw) . "\r\n";
  51. $req .= "\r\n" . $raw;
  52. if (!isset($url['port']) || !$url['port'])
  53. $url['port'] = 80;
  54. $errno = $errstr = "";
  55. $socket = fsockopen($url['host'], intval($url['port']), $errno, $errstr, 30);
  56. if ($socket) {
  57. // Send request headers
  58. fputs($socket, $req);
  59. // Read response headers and data
  60. $resp = "";
  61. while (!feof($socket))
  62. $resp .= fgets($socket, 4096);
  63. fclose($socket);
  64. // Split response header/data
  65. $resp = explode("\r\n\r\n", $resp);
  66. echo $resp[1]; // Output body
  67. }
  68. die();
  69. }
  70. // Get JSON data
  71. $json = new Moxiecode_JSON();
  72. $input = $json->decode($raw);
  73. // Execute RPC
  74. if (isset($config['general.engine'])) {
  75. $spellchecker = new $config['general.engine']($config);
  76. $result = call_user_func_array(array($spellchecker, $input['method']), $input['params']);
  77. } else
  78. die('{"result":null,"id":null,"error":{"errstr":"You must choose an spellchecker engine in the config.php file.","errfile":"","errline":null,"errcontext":"","level":"FATAL"}}');
  79. // Request and response id should always be the same
  80. $output = array(
  81. "id" => $input->id,
  82. "result" => $result,
  83. "error" => null
  84. );
  85. // Return JSON encoded string
  86. echo $json->encode($output);
  87. ?>