forked from backdrop-contrib/mathjax
-
Notifications
You must be signed in to change notification settings - Fork 0
/
mathjax.install
90 lines (84 loc) · 2.31 KB
/
mathjax.install
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
<?php
/**
* @file
* MathJax module install.
*/
/**
* Implements hook_uninstall().
*/
function mathjax_uninstall() {
variable_del('mathjax_config_type');
variable_del('mathjax_config_string');
variable_del('mathjax_use_cdn');
variable_del('mathjax_cdn_url');
cache_clear_all('variables', 'cache_bootstrap');
}
/**
* Implements hook_requirements().
*/
function mathjax_requirements($phase) {
$requirements = array();
$t = get_t();
if ($phase == 'runtime') {
if (!variable_get('mathjax_use_cdn', TRUE)) {
if (!_mathjax_library_present()) {
$requirements['mathjax_local_libraries'] = array(
'title' => $t('MathJax'),
'value' => $t('Missing JavaScript libraries'),
'description' => $t("MathJax is configured to use local library files but they could not be found. See the README."),
'severity' => REQUIREMENT_ERROR,
);
}
if (!function_exists('libraries_get_path')) {
$requirements['mathjax_libraries_dependency'] = array(
'title' => $t('MathJax'),
'value' => $t('Missing libraries module'),
'description' => $t("MathJax is configured to use local library files but the libraries module is not enabled. See the README."),
'severity' => REQUIREMENT_ERROR,
);
}
}
}
return $requirements;
}
/**
* Determines whether the MathJax sources are present.
*
* @return bool
* True if MathJax is installed
*/
function _mathjax_library_present() {
if (function_exists('libraries_get_path')) {
$mathjax_path = libraries_get_path('mathjax');
$jspath = $mathjax_path . '/MathJax.js';
$jsp = file_exists($jspath);
return $jsp;
}
return FALSE;
}
/**
* Implements hook_update_N().
*
* Removes deprecated configuration variables.
*/
function mathjax_update_7001() {
variable_del('mathjax_enabled');
variable_del('mathjax_pages');
variable_del('mathjax_active_type');
variable_set('mathjax_config_type', 1);
if (!variable_get('mathjax_config_string')) {
$str = <<<EOD
MathJax.Hub.Config({
extensions: ['tex2jax.js'],
jax: ['input/TeX','output/HTML-CSS'],
tex2jax: {
inlineMath: [ ['$','$'], ['\\\\(','\\\\)'] ],
processEscapes: true
},
showProcessingMessages: false,
messageStyle: 'none'
});
EOD;
variable_set('mathjax_config_string', $str);
}
}