4 * Description: Addon for Friendica to include MathJax (LaTeX math syntax)
6 * Author: Tobias Diekershoff <https://social.diekershoff.de/profile/tobias>
7 * Author: Hypolite Petovan <https://friendica.mrpetovan.com/profile/hypolite>
8 * License: 3-clause BSD license
12 use Friendica\Core\Addon;
13 use Friendica\Core\L10n;
14 use Friendica\Core\PConfig;
16 function mathjax_install()
18 Addon::registerHook('footer' , __FILE__, 'mathjax_footer');
19 Addon::registerHook('addon_settings' , __FILE__, 'mathjax_settings');
20 Addon::registerHook('addon_settings_post', __FILE__, 'mathjax_settings_post');
23 function mathjax_uninstall()
25 Addon::unregisterHook('footer' , __FILE__, 'mathjax_footer');
26 Addon::unregisterHook('addon_settings' , __FILE__, 'mathjax_settings');
27 Addon::unregisterHook('addon_settings_post', __FILE__, 'mathjax_settings_post');
30 Addon::unregisterHook('load_config' , __FILE__, 'mathjax_load_config');
31 Addon::unregisterHook('page_header' , __FILE__, 'mathjax_page_header');
32 Addon::unregisterHook('template_vars' , __FILE__, 'mathjax_template_vars');
35 function mathjax_settings_post($a)
37 if (!local_user() || empty($_POST['mathjax-submit'])) {
41 PConfig::set(local_user(), 'mathjax', 'use', intval($_POST['mathjax_use']));
44 function mathjax_settings(App $a, &$s)
50 $use = PConfig::get(local_user(), 'mathjax', 'use', false);
52 $tpl = get_markup_template('settings.tpl', __DIR__);
53 $s .= replace_macros($tpl, [
54 '$title' => 'MathJax',
55 '$description' => L10n::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.'),
56 '$mathjax_use' => ['mathjax_use', L10n::t('Use the MathJax renderer'), $use, ''],
57 '$savesettings' => L10n::t('Save Settings'),
61 function mathjax_footer(App $a, &$b)
63 // if the visitor of the page is not a local_user, use MathJax
64 // otherwise check the users settings.
65 if (!local_user() || PConfig::get(local_user(), 'mathjax', 'use', false)) {
66 $a->registerFooterScript(__DIR__ . '/asset/MathJax.js?config=TeX-MML-AM_CHTML');
67 $a->registerFooterScript(__DIR__ . '/mathjax.js');