From 14716f3b126b045a77f68559724d80c2f9b454ef Mon Sep 17 00:00:00 2001 From: Tobias Diekershoff Date: Sun, 15 Apr 2012 22:25:23 +0200 Subject: [PATCH] MathJax: added the MathJax addon to the repository --- mathjax/README | 31 +++++++++++++++++++ mathjax/admin.tpl | 2 ++ mathjax/mathjax.php | 74 +++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 107 insertions(+) create mode 100644 mathjax/README create mode 100644 mathjax/admin.tpl create mode 100644 mathjax/mathjax.php diff --git a/mathjax/README b/mathjax/README new file mode 100644 index 00000000..023e1c89 --- /dev/null +++ b/mathjax/README @@ -0,0 +1,31 @@ +Addon for Friendika to include MathJax (LaTeX math syntax) + +This addon lets your users use LaTeX to type mathematical formulas +within their posts. MathJax takes care about the best method for the +browser to display the formula and provides compatibility to 99% +of the modern browsers. + +You can either use the MathJax CDN online, thus loading the required javascript +libraries from the MathJax cloud, or use a local installation of MathJax. +Please see the plugin settings in the admin panel for configuration possibles. +If you don't set up a local MathJax instance, leave the configuration untouched +it will fall back to the MathJax cloud as default value. + +If you don't use the admin panel add mathjax to the list of active addons + +$a->config['system']['addon'] = [..., mathjax, ...] + +To select the source of the included javascript libraries add a line + +$a->config['mathjax']['baseurl'] = 'the URL to your MathJax installation'; + +to your .htconfig.php file. If this line is not there, the addon assumes that +you want to use the MathJax cloud (CDN). + +Please note that your usage of the CDN is governed by the "MathJax CDN Terms of +Service" see http://www.mathjax.org/download/mathjax-cdn-terms-of-service/ + +Author: Tobias Diekershoff + http://diekershoff.homeunix.net/friendika/profile/tobias + email: tobias.diekershoff@gmx.net + diff --git a/mathjax/admin.tpl b/mathjax/admin.tpl new file mode 100644 index 00000000..1c723cdd --- /dev/null +++ b/mathjax/admin.tpl @@ -0,0 +1,2 @@ +{{ inc field_input.tpl with $field=$baseurl }}{{endinc }} +
diff --git a/mathjax/mathjax.php b/mathjax/mathjax.php new file mode 100644 index 00000000..69df4225 --- /dev/null +++ b/mathjax/mathjax.php @@ -0,0 +1,74 @@ + + * License: 3-clause BSD license + */ + +function mathjax_install() { + register_hook('page_header', 'addon/mathjax/mathjax.php', 'mathjax_page_header'); + register_hook('plugin_settings', 'addon/mathjax/mathjax.php', 'mathjax_settings'); + register_hook('plugin_settings_post', 'addon/mathjax/mathjax.php', 'mathjax_settings_post'); + logger('installed js_math plugin'); +} +function mathjax_uninstall() { + unregister_hook('page_header', 'addon/mathjax/mathjax.php', 'mathjax_page_header'); + unregister_hook('plugin_settings', 'addon/mathjax/mathjax.php', 'mathjax_settings'); + unregister_hook('plugin_settings_post', 'addon/mathjax/mathjax.php', 'mathjax_settings_post'); +} +function mathjax_settings_post ($a, $post) { + if (! local_user()) + return; + // don't check statusnet settings if statusnet submit button is not clicked + if (!x($_POST,'mathjax-submit')) + return; + set_pconfig(local_user(),'mathjax','use',intval($_POST['mathjax_use'])); +} +function mathjax_settings (&$a, &$s) { + if (! local_user()) + return; + $use = get_pconfig(local_user(),'mathjax','use'); + $usetext = (($use) ? ' checked="checked" ' : ''); + $s .= '
'; + $s .= '

MathJax '.t('Settings').'

'; + $s .= '

'.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.').'

'; + $s .= ''; + $s .= ''; + $s .= '
'; + + $s .= '
'; + $s .= '
'; +} +/* we need to add one JavaScript include command to the html output + * note that you have to check the jsmath/easy/load.js too. + */ +function mathjax_page_header($a, &$b) { + // if the visitor of the page is not a local_user, use MathJax + // otherwise check the users settings. + $url = get_config ('mathjax','baseurl','http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML'); + if (! local_user()) { + $b .= ''; + } else { + $use = get_pconfig(local_user(),'mathjax','use'); + if ($use) { + $b .= ''; + } + } +} +function mathjax_plugin_admin_post (&$a) { + $baseurl = ((x($_POST, 'baseurl')) ? trim($_POST['baseurl']) : 'http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML'); + set_config('mathjax','baseurl',$baseurl); + info( t('Settings updated.'). EOL); +} +function mathjax_plugin_admin (&$a, &$o) { + $t = file_get_contents( dirname(__file__)."/admin.tpl"); + if (get_config('mathjax','baseurl','') == '') { + set_config('mathjax','baseurl','http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML'); + } + $o = replace_macros( $t, array( + '$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.')), + )); +} -- 2.39.5