-
Notifications
You must be signed in to change notification settings - Fork 0
/
button.js.php
82 lines (72 loc) · 1.88 KB
/
button.js.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
<?php
$absolute_path = explode('wp-content', $_SERVER['SCRIPT_FILENAME']);
$wp_load = $absolute_path[0] . 'wp-load.php';
require_once($wp_load);
header('Content-Type: application/x-javascript');
header('Cache-control: must-revalidate');
$q = instructables::instructables_get_feeds();
?>
(function() {
// Register buttons
tinymce.create('tinymce.plugins.MyButtons', {
init: function( editor, url ) {
// Add button that inserts shortcode into the current position of the editor
editor.addButton( 'instruct_button', {
title: 'Instructables Feeds',
icon: false,
onclick: function() {
// Open a TinyMCE modal
editor.windowManager.open({
title: 'Instructables Feeds',
width: 450,
height: 100,
body: [{
type: 'listbox',
name: 'feedlist',
label: 'Select a feed: ',
values: [
{ text: 'Choose a feed', value: 'default' },
<?php
if($q->have_posts())
{
$i = 0;
$len = wp_count_posts( 'instructables_sc' )->publish;
while( $q->have_posts() ) : $q->the_post();
?>
{ text: '<?php echo get_the_title(); ?>', value: '<?php echo the_ID(); ?>' }
<?php
if ($i != $len - 1)
{
echo ',' . PHP_EOL;
}
else
{
echo PHP_EOL;
}
$i++;
endwhile;
wp_reset_postdata();
}
else
{
//need to define feeds
}
?>
],
value: 'default' //Default
}
],
onsubmit: function( e ) {
editor.insertContent( '[instructables id="' + e.data.feedlist + '" ]' );
}
});
}
});
},
createControl: function( n, cm ) {
return null;
}
});
// Add buttons
tinymce.PluginManager.add( 'instruct_button_script', tinymce.plugins.MyButtons );
})();