1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69
|
<?php
/**
* $Horde: kronolith/imple.php,v 1.1.2.3 2008/04/25 03:50:58 chuck Exp $
*
* Copyright 2005-2008 The Horde Project (http://www.horde.org/)
*
* See the enclosed file COPYING for license information (GPL). If you
* did not receive this file, see http://www.fsf.org/copyleft/gpl.html.
*
* @author Michael Slusarz <slusarz@horde.org>
*/
@define('KRONOLITH_BASE', dirname(__FILE__));
require_once KRONOLITH_BASE . '/lib/base.php';
require_once KRONOLITH_BASE . '/lib/Imple.php';
$path = Util::getFormData('imple');
if (!$path) {
exit;
}
if ($path[0] == '/') {
$path = substr($path, 1);
}
$path = explode('/', $path);
$impleName = array_shift($path);
$imple = Imple::factory($impleName);
if (!$imple) {
exit;
}
$args = array();
foreach ($path as $pair) {
if (strpos($pair, '=') === false) {
$args[$pair] = true;
} else {
list($name, $val) = explode('=', $pair);
$args[$name] = $val;
}
}
$result = $imple->handle($args);
if (!empty($_SERVER['Content-Type'])) {
$ct = $_SERVER['Content-Type'];
} else {
$ct = is_string($result) ? 'plain' : 'json';
}
switch ($ct) {
case 'json':
header('Content-Type: text/x-json');
require_once KRONOLITH_BASE . '/lib/JSON.php';
echo Kronolith_Serialize_JSON::encode(String::convertCharset($result, NLS::getCharset(), 'utf-8'));
break;
case 'plain':
header('Content-Type: text/plain');
echo $result;
break;
case 'html':
header('Content-Type: text/html');
echo $result;
break;
default:
echo $result;
}
|