Beispiel #1
0
<?php

/*
 *	Typographie, v1.2.2
 *	(c) 2014–2015 Artyom "Sleepwalker" Fedosov <*****@*****.**>
 *	https://github.com/asleepwalker/typographie
 */
if (!(isset($_POST['raw']) && isset($_POST['actions']) && isset($_POST['in']) && isset($_POST['out']) && isset($_POST['highlight']))) {
    echo json_encode(array('error' => '1'));
    exit;
}
require_once 'typographie.class.php';
require_once 'converter.class.php';
$engine = new TypographieModes($_POST['actions']);
$engine->mode($_POST['in'], $_POST['out']);
$result = $engine->process($_POST['raw']);
if ($_POST['highlight'] == 'enabled') {
    require_once 'finediff.class.php';
    $opcodes = FineDiff::getDiffOpcodes($_POST['raw'], $result);
    $result = '';
    FineDiff::renderFromOpcodes($_POST['raw'], $opcodes, function ($opcode, $from, $from_offset, $from_len) use(&$result) {
        if ($opcode === 'c') {
            $result .= htmlspecialchars(mb_substr($from, $from_offset, $from_len));
        } else {
            if ($opcode === 'i') {
                $result .= '<span class="fix">' . htmlspecialchars(mb_substr($from, $from_offset, $from_len), ENT_QUOTES) . '</span>';
            }
        }
    });
} else {
    $result = htmlspecialchars($result, ENT_QUOTES, 'UTF-8');
Beispiel #2
0
}
$in = 'plain';
if (isset($_POST['in'])) {
    $in = $_POST['in'];
}
$out = 'plain';
if (isset($_POST['out'])) {
    $out = $_POST['out'];
}
$actions = implode(',', $rules['actions']);
if (isset($_POST['actions'])) {
    $actions = $_POST['actions'];
}
if ($in == 'plain' && $out == 'plain') {
    $engine = new Typographie($actions);
} else {
    require_once '../engine/converter.class.php';
    $engine = new TypographieModes($actions);
    $engine->mode($in, $out);
}
$result = $engine->process($_POST['raw']);
returnResult($result);
function returnResult($text)
{
    $result = array('version' => $GLOBALS['rules']['version'], 'result' => $text);
    echo json_encode($result);
}
function returnError($code)
{
    die(json_encode(array('error' => $GLOBALS['rules']['errors'][$code])));
}