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