5 * Description: Addon for Friendika to include MathJax (LaTeX math syntax)
7 * Author: Tobias Diekershoff <https://f.diekershoff.de/profile/tobias>
8 * License: 3-clause BSD license
11 use Friendica\Core\Config;
12 use Friendica\Core\PConfig;
14 function mathjax_install() {
15 register_hook('page_header', 'addon/mathjax/mathjax.php', 'mathjax_page_header');
16 register_hook('plugin_settings', 'addon/mathjax/mathjax.php', 'mathjax_settings');
17 register_hook('plugin_settings_post', 'addon/mathjax/mathjax.php', 'mathjax_settings_post');
18 logger('installed js_math plugin');
20 function mathjax_uninstall() {
21 unregister_hook('page_header', 'addon/mathjax/mathjax.php', 'mathjax_page_header');
22 unregister_hook('plugin_settings', 'addon/mathjax/mathjax.php', 'mathjax_settings');
23 unregister_hook('plugin_settings_post', 'addon/mathjax/mathjax.php', 'mathjax_settings_post');
25 function mathjax_settings_post ($a, $post) {
28 // don't check statusnet settings if statusnet submit button is not clicked
29 if (!x($_POST,'mathjax-submit'))
31 PConfig::set(local_user(),'mathjax','use',intval($_POST['mathjax_use']));
33 function mathjax_settings (&$a, &$s) {
36 $use = PConfig::get(local_user(),'mathjax','use');
37 $usetext = (($use) ? ' checked="checked" ' : '');
38 $s .= '<span id="settings_mathjax_inflated" class="settings-block fakelink" style="display: block;" onclick="openClose(\'settings_mathjax_expanded\'); openClose(\'settings_mathjax_inflated\');">';
39 $s .= '<h3>MathJax '.t('Settings').'</h3>';
41 $s .= '<div id="settings_mathjax_expanded" class="settings-block" style="display: none;">';
42 $s .= '<span class="fakelink" onclick="openClose(\'settings_mathjax_expanded\'); openClose(\'settings_mathjax_inflated\');">';
43 $s .= '<h3>MathJax '.t('Settings').'</h3>';
45 $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>';
46 $s .= '<label id="mathjax_label" for="mathjax_use">'.t('Use the MathJax renderer').'</label>';
47 $s .= '<input id="mathjax_use" type="checkbox" name="mathjax_use" value="1"'. $usetext .' />';
48 $s .= '<div class="clear"></div>';
50 $s .= '<div class="settings-submit-wrapper" ><input type="submit" id="mathjax-submit" name="mathjax-submit" class="settings-submit" value="' . t('Save Settings') . '" /></div>';
53 /* we need to add one JavaScript include command to the html output
54 * note that you have to check the jsmath/easy/load.js too.
56 function mathjax_page_header($a, &$b) {
57 // if the visitor of the page is not a local_user, use MathJax
58 // otherwise check the users settings.
59 $url = Config::get ('mathjax','baseurl');
61 $url = 'http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML';
63 $b .= '<script type="text/javascript" src="'.$url.'"></script>';
65 $use = PConfig::get(local_user(),'mathjax','use');
67 $b .= '<script type="text/javascript" src="'.$url.'"></script>';
71 function mathjax_plugin_admin_post (&$a) {
72 $baseurl = ((x($_POST, 'baseurl')) ? trim($_POST['baseurl']) : 'http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML');
73 Config::set('mathjax','baseurl',$baseurl);
74 info( t('Settings updated.'). EOL);
76 function mathjax_plugin_admin (&$a, &$o) {
77 $t = get_markup_template( "admin.tpl", "addon/mathjax/" );
78 if (Config::get('mathjax','baseurl','') == '') {
79 Config::set('mathjax','baseurl','http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML');
82 $o = replace_macros( $t, array(
83 '$submit' => t('Save Settings'),
84 '$baseurl' => array('baseurl', t('MathJax Base URL'), Config::get('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.')),