1<?php
2/* Ace editor plugin for Dokuwiki
3 * Copyright © 2011, 2012 Institut Obert de Catalunya
4 *
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License
7 * as published by the Free Software Foundation; either version 2
8 * of the License, or (at your option) any later version.
9 *
10 * Ths program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
18 */
19
20ini_set('display_errors', 0);
21
22if(!defined('DOKU_INC')) define('DOKU_INC',dirname(__FILE__).'/../../../');
23
24require_once DOKU_INC . 'inc/init.php';
25require_once DOKU_INC . 'inc/parser/xhtml.php';
26
27header('Content-Type', 'text/plain');
28
29$renderer = new Doku_Renderer_xhtml();
30$xhtml = $renderer->render($_GET['text']);
31
32if (preg_match('/<img src="(.*?\?media=(.*?))"/', $xhtml, $matches)) {
33    $url = $matches[1];
34    $path = mediaFN($matches[2]);
35} else {
36    $url = DOKU_BASE . "lib/plugins/latex/images/renderfail.png";
37    $path = DOKU_INC . "lib/plugins/latex/images/renderfail.png";
38}
39
40$size = getimagesize($path);
41$data = array(
42    'url' => $url,
43    'width' => $size[0],
44    'height' => $size[1],
45);
46echo json_encode($data);
47