]> CyberLeo.Net >> Repos - SourceForge/phpwiki.git/blob - lib/plugin/AsciiMath.php
Replace tabs by spaces; remove EOL spaces
[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 getVersion() {
57         return preg_replace("/[Revision: $]/", '',
58                             "\$Revision$");
59     }
60
61     function getDefaultArguments() {
62         return array();
63     }
64     function handle_plugin_args_cruft(&$argstr, &$args) {
65         $this->source = $argstr;
66     }
67
68     function run($dbi, $argstr, &$request, $basepage) {
69         $args = $this->getArgs($argstr, $request);
70         if (empty($this->source)) {
71             return HTML::div(array('class' => "error"), "Please provide a formula to AsciiMath plugin");
72         }
73
74         if (phpversion() >= '5') {
75             include("lib/ASCIIMathPHP/ASCIIMathPHP-2.0.cfg.php");
76         } else {
77             include("lib/ASCIIMathPHP/ASCIIMathPHP.cfg.php");
78         }
79         $ascii_math = new ASCIIMathPHP($symbol_arr, $this->source);
80         $ascii_math->genMathML();
81         return HTML::raw($ascii_math->getMathML());
82     }
83 };
84
85 // Local Variables:
86 // mode: php
87 // tab-width: 8
88 // c-basic-offset: 4
89 // c-hanging-comment-ender-p: nil
90 // indent-tabs-mode: nil
91 // End:
92 ?>