/
molpress.php
112 lines (86 loc) · 3.2 KB
/
molpress.php
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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
<?php
/**
* @package MolPress
* @version 0.1
*/
/*
Plugin Name: MolPress
Plugin URI: http://molmatinf.com
Description: Adds chemical structure datatypes to WordPress, starting with molecules.
Author: Alex M. Clark
Version: 0.1
Author URI: http://cheminf20.org
*/
$watermark = 0;
function molpress_shortcode_molecule($atts = [], $content = null, $tag = '')
{
global $watermark;
$watermark++;
$o = '';
$id = 'molecule' . $watermark;
$o .= '<span id="' . $id . '" style="display: none;">';
if (!is_null($content)) $o .= '<pre>' . $content . '</pre>';
$o .= '</span>';
$o .= '<script>var $; if (!$) $ = jQuery; $(document).ready(function($) {MolPress.RenderMolecule("' . $id . '",' . json_encode($atts) . ');});</script>';
return $o;
}
function molpress_shortcode_reaction($atts = [], $content = null, $tag = '')
{
global $watermark;
$watermark++;
$o = '';
$id = 'reaction' . $watermark;
$o .= '<span id="' . $id . '" style="display: none;">';
if (!is_null($content)) $o .= '<pre>' . $content . '</pre>';
$o .= '</span>';
$o .= '<script>var $; if (!$) $ = jQuery; $(document).ready(function($) {MolPress.RenderReaction("' . $id . '",' . json_encode($atts) . ');});</script>';
return $o;
}
function molpress_shortcode_collection($atts = [], $content = null, $tag = '')
{
global $watermark;
$watermark++;
$o = '';
$id = 'collection' . $watermark;
$o .= '<span id="' . $id . '" style="display: none;">';
if (!is_null($content)) $o .= '<script type="text/xml">' . $content . '</script>';
$o .= '</span>';
$o .= '<script>var $; if (!$) $ = jQuery; $(document).ready(function($) {MolPress.RenderCollection("' . $id . '",' . json_encode($atts) . ');});</script>';
return $o;
}
function molpress_init()
{
wp_enqueue_script('js_molpress', plugin_dir_url(__FILE__) . 'molpress.js?cachebuster=' . time());
//wp_enqueue_style('molpress_widgets', plugin_dir_url(__FILE__) . 'res/widgets.css', false, '1.0.0', 'all');
add_shortcode('molecule', 'molpress_shortcode_molecule');
add_shortcode('reaction', 'molpress_shortcode_reaction');
add_shortcode('collection', 'molpress_shortcode_collection');
if ((current_user_can('edit_posts') || current_user_can('edit_pages')) /*&& get_user_option('rich_editing') == 'true'*/)
{
add_filter('mce_external_plugins', 'molpress_add_plugin');
add_filter('mce_buttons', 'molpress_register_button');
}
}
function molpress_add_plugin($plugin_array)
{
$plugin_array['molpress_plugin'] = plugin_dir_url(__FILE__) . '/molpress_mce.js?cache=' . time();
return $plugin_array;
}
function molpress_register_button($buttons )
{
array_push($buttons, 'molpress_molecule_button');
array_push($buttons, 'molpress_reaction_button');
return $buttons;
}
function molpress_mime_types($mime_types)
{
$mime_types['svg'] = 'image/svg+xml';
$mime_types['el'] = 'chemical/x-sketchel';
$mime_types['mol'] = 'chemical/x-mdl-molfile';
$mime_types['ds'] = 'chemical/x-datasheet';
$mime_types['sdf'] = 'chemical/x-mdl-sdfile';
return $mime_types;
}
add_action('init', 'molpress_init');
add_filter('upload_mimes', 'molpress_mime_types', 1, 1);
?>