-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathreference-footnotes.php
More file actions
202 lines (161 loc) · 7.03 KB
/
reference-footnotes.php
File metadata and controls
202 lines (161 loc) · 7.03 KB
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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
<?php
/**
* Plugin Name: Reference Footnotes Editor Button
* Description: Add Reference Footnotes to the toolbar of TinyMCE Editor for automatically insert Reference Footnotes shortcode: ```[ref]...[/ref]```
* Version: 1.0.3
* Author: ODC: Huy Eng
* License: CC0
* Text Domain: reference-footnotes
* Domain Path: languages/
* Note: Based on Simple Footnotes Editor Button
*/
if ( !class_exists( 'reference_footnotes_TinyMCE' ) ) {
class reference_footnotes_TinyMCE
{
function __construct()
{
add_action( 'wp_enqueue_scripts', array( &$this, 'add_script' ), 11 );
add_action( 'init', array( &$this, 'init' ) );
add_shortcode( 'ref', array( &$this, 'shortcode' ) );
add_filter( 'img_caption_shortcode', array( &$this, 'nested_img_caption_shortcode' ), 1, 3 );
add_filter( 'the_content', array( &$this, 'the_content' ), 12 );
}
function init()
{
add_filter( 'mce_external_plugins', array( $this, 'add_buttons_reference_footnotes' ) );
add_filter( 'mce_buttons', array( $this, 'register_buttons_reference_footnotes' ) );
load_plugin_textdomain( 'reference-footnotes', false, dirname( plugin_basename( __FILE__ ) ) . '/i18n' );
if ( ( current_user_can( 'edit_posts' ) || current_user_can( 'edit_pages' ) ) && 'true' == get_user_option( 'rich_editing' ) ) {
wp_enqueue_script( array( 'wpdialogs' ) );
wp_enqueue_style( 'wp-jquery-ui-dialog' );
add_action( 'admin_footer', array( $this, 'builder_reference_footnotes' ) );
}
}
public function add_script()
{
wp_enqueue_style( "reference_footnotes_css", plugins_url( "rfootnotes.css", __FILE__ ) );
if ( get_post_type() == 'profiles' ) {
wp_enqueue_script( 'reference_footnotes_script', plugins_url( 'rfootnotes.js', __FILE__ ) );
}
}
/**
* Add Reference Footnotes button to TinyMCE Editor
*
* @param [type] $plugins
* @return void
*/
function add_buttons_reference_footnotes( $plugins )
{
$plugins['referencefootnote'] = plugins_url( '/js/tinymce.js', __FILE__ );
return $plugins;
}
/**
* Register Reference Footnotes button to TinyMCE Editor
*
* @param [type] $buttons
* @return void
*/
function register_buttons_reference_footnotes( $buttons )
{
$buttons[] = 'referencefootnote';
return $buttons;
}
/**
* Render Reference Footnotes Form Builder on modal panel
*
* @return void
*/
function builder_reference_footnotes()
{ ?>
<div style="display:none;">
<form id="reference-footnotes" tabindex="-1">
<div style="margin: 1em">
<p class="howto"><?php _e( 'Enter the content of the reference footnote', 'reference-footnotes' ); ?></p>
<textarea id="reference-footnotes-content" rows="4" style="width: 95%; margin-bottom: 1em"></textarea>
<div class="submitbox" style="margin-bottom: 1em">
<div id="reference-footnotes-insert" class="alignright">
<input type="submit" value="<?php esc_attr_e( 'Insert', 'reference-footnotes' ); ?>" class="button-primary">
</div>
<div id="reference-footnotes-cancel">
<a class="submitdelete deletion" href="#"><?php _e( 'Cancel', 'reference-footnotes' ); ?></a>
</div>
</div>
</div>
</form>
</div>
<?php
}
function reference_footnotes( $content )
{
global $id;
if ( empty( $this->reference_footnotes[$id] ) )
return $content;
$content .= '<div class="reference-footnote">';
$content .= '<h4 id="reference-notes">' . __( 'References', 'reference-footnotes' ) . '</h4>';
$content .= '<ol id="reference-list">';
foreach ( array_filter( $this->reference_footnotes[$id] ) as $num => $note ) {
$content .= '<li id="ref-' . $id . '-' . $num . '"><a href="#return-note-' . $id . '-' . $num . '">' . sprintf( _n( '%s', '%s', $num, 'tereference-footnotesst' ), $num ) . '</a>. ' . do_shortcode( $note ) . '</li>';
}
$content .= '</ol></div>';
return $content;
}
/**
* Render Note Number
*
* @param array $atts
* @param string $content
* @return string
*/
public function shortcode( $atts, $content = null )
{
global $id;
$note_number = '';
if ( null === $content )
return $note_number;
if ( !isset( $this->reference_footnotes[$id] ) )
$this->reference_footnotes[$id] = array( 0 => false );
$this->reference_footnotes[$id][] = $content;
$note = count( $this->reference_footnotes[$id] ) - 1;
$note_number = '<sup><a class="reference_footnote" title="' . esc_attr( wp_strip_all_tags( $content ) ) . '" id="return-note-' . $id . '-' . $note . '" href="#ref-' . $id . '-' . $note . '">' . $note . '</a></sup>';
return $note_number;
}
/**
* Overwrite default the_content() function to include Reference List section
*
* @param string $content
* @return string
*/
public function the_content( $content )
{
if ( isset( $GLOBALS['multipage'] ) && !$GLOBALS['multipage'] )
return $this->reference_footnotes( $content );
return $content;
}
public function nested_img_caption_shortcode( $empty, $attr, $content = null )
{
extract(
shortcode_atts(
array(
'id' => '',
'align' => 'alignnone',
'width' => '',
'caption' => ''
),
$attr,
'caption'
)
);
$caption = do_shortcode( $caption );
if ( 1 > ( int ) $width || empty( $caption ) ):
return $content;
endif;
if ( $id ):
$id = 'id="' . esc_attr( $id ) . '" ';
endif;
return '<div ' . $id . 'class="wp-caption ' . esc_attr( $align ) . '" style="width: ' . ( 10 + ( int ) $width ) . 'px">' . do_shortcode( $content ) . '<p class="wp-caption-text">' . $caption . '</p></div>';
}
}
}
if ( class_exists( 'reference_footnotes_TinyMCE' ) ) {
$reference_footnotes_TinyMCE = new reference_footnotes_TinyMCE();
}