5 * Description: Addon for Friendika to include MathJax (LaTeX math syntax)
7 * Author: Tobias Diekershoff <http://diekershoff.homeunix.net/friendika/profile/tobias>
8 * License: 3-clause BSD license
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');
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');
22 function mathjax_settings_post ($a, $post) {
25 // don't check statusnet settings if statusnet submit button is not clicked
26 if (!x($_POST,'mathjax-submit'))
28 set_pconfig(local_user(),'mathjax','use',intval($_POST['mathjax_use']));
30 function mathjax_settings (&$a, &$s) {
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>';
42 $s .= '<div class="settings-submit-wrapper" ><input type="submit" id="mathjax-submit" name="mathjax-submit" class="settings-submit" value="' . t('Submit') . '" /></div>';
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.
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');
53 $url = 'http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML';
55 $b .= '<script type="text/javascript" src="'.$url.'"></script>';
57 $use = get_pconfig(local_user(),'mathjax','use');
59 $b .= '<script type="text/javascript" src="'.$url.'"></script>';
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);
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');
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.')),