MathJax: added the MathJax addon to the repository
This commit is contained in:
parent
27134d4b57
commit
14716f3b12
3 changed files with 107 additions and 0 deletions
31
mathjax/README
Normal file
31
mathjax/README
Normal file
|
@ -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
|
||||
|
2
mathjax/admin.tpl
Normal file
2
mathjax/admin.tpl
Normal file
|
@ -0,0 +1,2 @@
|
|||
{{ inc field_input.tpl with $field=$baseurl }}{{endinc }}
|
||||
<div class="submit"><input type="submit" name="page_site" value="$submit" /></div>
|
74
mathjax/mathjax.php
Normal file
74
mathjax/mathjax.php
Normal file
|
@ -0,0 +1,74 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* Name: MathJax
|
||||
* Description: Addon for Friendika to include MathJax (LaTeX math syntax)
|
||||
* Version: 1.0
|
||||
* Author: Tobias Diekershoff <http://diekershoff.homeunix.net/friendika/profile/tobias>
|
||||
* 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 .= '<div class="settings-block">';
|
||||
$s .= '<h3>MathJax '.t('Settings').'</h3>';
|
||||
$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>';
|
||||
$s .= '<label id="mathjax_label" for="mathjax_use">'.t('Use the MathJax renderer').'</label>';
|
||||
$s .= '<input id="mathjax_use" type="checkbox" name="mathjax_use" value="1"'. $usetext .' />';
|
||||
$s .= '<div class="clear"></div>';
|
||||
|
||||
$s .= '<div class="settings-submit-wrapper" ><input type="submit" id="mathjax-submit" name="mathjax-submit" class="settings-submit" value="' . t('Submit') . '" /></div>';
|
||||
$s .= '</div>';
|
||||
}
|
||||
/* 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 .= '<script type="text/javascript" src="'.$url.'"></script>';
|
||||
} else {
|
||||
$use = get_pconfig(local_user(),'mathjax','use');
|
||||
if ($use) {
|
||||
$b .= '<script type="text/javascript" src="'.$url.'"></script>';
|
||||
}
|
||||
}
|
||||
}
|
||||
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.')),
|
||||
));
|
||||
}
|
Loading…
Reference in a new issue