]> git.mxchange.org Git - friendica-addons.git/blob - mathjax/mathjax.php
Merge remote branch 'upstream/master'
[friendica-addons.git] / mathjax / mathjax.php
1 <?php
2
3 /**
4  * Name: MathJax
5  * Description: Addon for Friendika to include MathJax (LaTeX math syntax)
6  * Version: 1.0
7  * Author: Tobias Diekershoff <http://diekershoff.homeunix.net/friendika/profile/tobias>
8  * License: 3-clause BSD license
9  */
10
11 function mathjax_install() {
12     register_hook('page_header', 'addon/mathjax/mathjax.php', 'mathjax_page_header');
13     register_hook('plugin_settings', 'addon/mathjax/mathjax.php', 'mathjax_settings'); 
14     register_hook('plugin_settings_post', 'addon/mathjax/mathjax.php', 'mathjax_settings_post');
15     logger('installed js_math plugin');
16 }
17 function mathjax_uninstall() {
18     unregister_hook('page_header', 'addon/mathjax/mathjax.php', 'mathjax_page_header');
19     unregister_hook('plugin_settings', 'addon/mathjax/mathjax.php', 'mathjax_settings'); 
20     unregister_hook('plugin_settings_post', 'addon/mathjax/mathjax.php', 'mathjax_settings_post');
21 }
22 function mathjax_settings_post ($a, $post) {
23     if (! local_user())
24         return;
25     // don't check statusnet settings if statusnet submit button is not clicked
26     if (!x($_POST,'mathjax-submit'))
27         return;
28     set_pconfig(local_user(),'mathjax','use',intval($_POST['mathjax_use']));
29 }
30 function mathjax_settings (&$a, &$s) {
31     if (! local_user())
32         return;
33     $use = get_pconfig(local_user(),'mathjax','use');
34     $usetext = (($use) ? ' checked="checked" ' : '');
35     $s .= '<div class="settings-block">';
36     $s .= '<h3>MathJax '.t('Settings').'</h3>';
37     $s .= '<p>'.t('The MathJax addon renders mathematical formulae written using the LaTeX syntax surrounded by the usual $$ or an eqnarray block in the postings of your wall,network tab and private mail.').'</p>';
38     $s .= '<label id="mathjax_label" for="mathjax_use">'.t('Use the MathJax renderer').'</label>';
39     $s .= '<input id="mathjax_use" type="checkbox" name="mathjax_use" value="1"'. $usetext .' />';
40     $s .= '<div class="clear"></div>';
41
42     $s .= '<div class="settings-submit-wrapper" ><input type="submit" id="mathjax-submit" name="mathjax-submit" class="settings-submit" value="' . t('Submit') . '" /></div>';
43     $s .= '</div>';
44 }
45 /*  we need to add one JavaScript include command to the html output
46  *  note that you have to check the jsmath/easy/load.js too.
47  */
48 function mathjax_page_header($a, &$b) {
49     //  if the visitor of the page is not a local_user, use MathJax
50     //  otherwise check the users settings.
51     $url = get_config ('mathjax','baseurl');
52         if(! $url)
53                 $url = 'http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML';
54     if (! local_user()) {
55         $b .= '<script type="text/javascript" src="'.$url.'"></script>';
56     } else {
57         $use = get_pconfig(local_user(),'mathjax','use');
58         if ($use) { 
59             $b .= '<script type="text/javascript" src="'.$url.'"></script>';
60         }
61     }
62 }
63 function mathjax_plugin_admin_post (&$a) {
64     $baseurl = ((x($_POST, 'baseurl')) ? trim($_POST['baseurl']) : 'http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML');
65     set_config('mathjax','baseurl',$baseurl);
66     info( t('Settings updated.'). EOL);
67 }
68 function mathjax_plugin_admin (&$a, &$o) {
69         $t = file_get_contents( dirname(__file__)."/admin.tpl");
70         if (get_config('mathjax','baseurl','') == '') {
71             set_config('mathjax','baseurl','http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML');
72         }
73         $o = replace_macros( $t, array(
74                 '$baseurl' => array('baseurl', t('MathJax Base URL'), get_config('mathjax','baseurl' ), t('The URL for the javascript file that should be included to use MathJax. Can be either the MathJax CDN or another installation of MathJax.')),
75             ));
76 }