]> CyberLeo.Net >> Repos - SourceForge/phpwiki.git/blob - lib/plugin/AsciiMath.php
include [all] Include and file path should be devided with single space. File path...
[SourceForge/phpwiki.git] / lib / plugin / AsciiMath.php
1 <?php // -*-php-*-
2 /*
3  * Copyright 2005 $ThePhpWikiProgrammingTeam
4  * Copyright 2009 Marc-Etienne Vargenau, Alcatel-Lucent
5  *
6  * This file is part of PhpWiki.
7  *
8  * PhpWiki is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; either version 2 of the License, or
11  * (at your option) any later version.
12  *
13  * PhpWiki is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License along
19  * with PhpWiki; if not, write to the Free Software Foundation, Inc.,
20  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21  */
22
23 if (phpversion() >= '5') {
24     require_once 'lib/ASCIIMathPHP/ASCIIMathPHP-2.0.class.php';
25 } else {
26     require_once 'lib/ASCIIMathPHP/ASCIIMathPHP.class.php';
27 }
28
29 /**
30  * Render ASCII math as MathML
31  * Requires ENABLE_XHTML_XML = true
32  * See http://www.jcphysics.com/ASCIIMath/
33  * Syntax: http://www1.chapman.edu/~jipsen/mathml/asciimathsyntax.xml
34  * Example: "int_-1^1 sqrt(1-x^2)dx = pi/2"
35  * => <math xmlns="http://www.w3.org/1998/Math/MathML">
36         <mrow><msubsup><mo>&#8747;</mo><mn>-1</mn><mn>1</mn></msubsup></mrow>
37         <msqrt><mrow><mn>1</mn><mo>-</mo><msup><mi>x</mi><mn>2</mn></msup></mrow></msqrt>
38         <mi>d</mi>
39         <mi>x</mi>
40         <mo>=</mo>
41         <mfrac><mi>&#960;</mi><mo>2</mo></mfrac>
42       </math>
43  */
44 class WikiPlugin_AsciiMath
45 extends WikiPlugin
46 {
47     function getName() {
48         return _("AsciiMath");
49     }
50
51     function getDescription() {
52         return _("Render ASCII Math as MathML");
53     }
54
55     function getDefaultArguments() {
56         return array();
57     }
58     function handle_plugin_args_cruft(&$argstr, &$args) {
59         $this->source = $argstr;
60     }
61
62     function run($dbi, $argstr, &$request, $basepage) {
63         $args = $this->getArgs($argstr, $request);
64         if (empty($this->source)) {
65             return HTML::div(array('class' => "error"), "Please provide a formula to AsciiMath plugin");
66         }
67
68         if (phpversion() >= '5') {
69             include 'lib/ASCIIMathPHP/ASCIIMathPHP-2.0.cfg.php';
70         } else {
71             include 'lib/ASCIIMathPHP/ASCIIMathPHP.cfg.php';
72         }
73         $ascii_math = new ASCIIMathPHP($symbol_arr, $this->source);
74         $ascii_math->genMathML();
75         return HTML::raw($ascii_math->getMathML());
76     }
77 };
78
79 // Local Variables:
80 // mode: php
81 // tab-width: 8
82 // c-basic-offset: 4
83 // c-hanging-comment-ender-p: nil
84 // indent-tabs-mode: nil
85 // End: