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