PluginProbe
Insert PHP Code Snippet / trunk
Insert PHP Code Snippet vtrunk
1.4.7 1.3.3 1.3.4 1.3.5 1.3.6 1.3.7 1.3.8 1.4 1.4.1 1.4.2 1.4.3 1.4.4 1.4.5 1.4.6 trunk 1.0 1.1 1.2 1.2.1 1.2.2 1.2.3 1.2.4 1.2.5 1.2.6 1.3 All 27 releases
insert-php-code-snippet / editor_plugin.js.php

editor_plugin.js.php in Insert PHP Code Snippet trunk, at editor_plugin.js.php

167 lines 5.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 if ( ! defined( 'ABSPATH' ) )
3 exit;
4
5 header( 'Content-Type: text/javascript' );
6 if ( ! is_user_logged_in() || ! current_user_can( 'edit_posts' ) )
7 die('You must be logged in to access this script.');
8
9 /*if(!isset($shortcodesXYZEP))
10 $shortcodesXYZEP = new XYZ_Insert_Php_TinyMCESelector();*/
11
12 global $wpdb;
13 $buttonName = 'xyz_ips_snippet_selecter';
14
15 $xyz_snippets_arr=$wpdb->get_results($wpdb->prepare( "SELECT id,title FROM ".$wpdb->prefix."xyz_ips_short_code WHERE status=%d and insertionMethod=%d ORDER BY id DESC",1,2),ARRAY_A );
16
17 if(empty($xyz_snippets_arr))//if(count($xyz_snippets_arr)==0)
18 die;
19
20 if(floatval(get_bloginfo('version'))>=3.9)
21 {
22 ?>
23 (function() {
24 /* Register the buttons */
25 tinymce.create('tinymce.plugins.xyz_ips_snippet', {
26 init : function(ed, url) {
27 /**
28 * Inserts shortcode content
29 */
30 ed.addButton( '<?php echo $buttonName;?>', {
31 title: 'Insert PHP Code Snippet',
32 type: 'menubutton',
33 icon: 'icon xyz-ips-own-icon',
34 menu: [
35
36 <?php foreach ($xyz_snippets_arr as $key=>$val) { ?>
37 {
38 text: '<?php echo addslashes($val['title']); ?>',
39 value: '[xyz-ips snippet="<?php echo addslashes($val['title']); ?>"]',
40 onclick: function() {
41 ed.selection.setContent(this.value());
42 }
43 },
44 <?php } ?>
45
46 ]
47
48 });
49
50
51 },
52 createControl : function(n, cm) {
53 return null;
54 },
55 });
56 /* Start the buttons */
57 tinymce.PluginManager.add( 'xyz_ips_buttons', tinymce.plugins.xyz_ips_snippet );
58 })();
59 <?php
60 }
61 /*else if(floatval(get_bloginfo('version'))>=3.9)
62 {
63 ?>
64 (function() {
65
66 tinymce.PluginManager.add('<?php echo $buttonName; ?>', function( editor, url ) {
67 editor.addButton( '<?php echo $buttonName; ?>', {
68 title: 'Insert PHP Code Snippet',
69 type: 'menubutton',
70 icon: 'icon xyz-ips-own-icon',
71 menu: [
72 <?php foreach ($xyz_snippets_arr as $key=>$val) { ?>
73 {
74 text: '<?php echo addslashes($val['title']); ?>',
75 value: '[xyz-ips snippet="<?php echo addslashes($val['title']); ?>"]',
76 onclick: function() {
77 editor.insertContent(this.value());
78 }
79 },
80 <?php } ?>
81 ]
82 });
83 });
84
85 })();
86 <?php }*/ else {
87
88 $xyz_snippets = array(
89 'title' =>'Insert PHP Code Snippet',
90 'url' => plugins_url('images/logo.png', XYZ_INSERT_PHP_PLUGIN_FILE),
91 'xyz_ips_snippets' => $xyz_snippets_arr
92 );
93 ?>
94
95 var tinymce_<?php echo $buttonName; ?> =<?php echo json_encode($xyz_snippets) ?>;
96
97
98 (function() {
99 //******* Load plugin specific language pack
100
101 tinymce.create('tinymce.plugins.<?php echo $buttonName; ?>', {
102 /**
103 * Initializes the plugin, this will be executed after the plugin has been created.
104 * This call is done before the editor instance has finished it's initialization so use the onInit event
105 * of the editor instance to intercept that event.
106 *
107 * @param {tinymce.Editor} ed Editor instance that the plugin is initialized in.
108 * @param {string} url Absolute URL to where the plugin is located.
109 */
110 init : function(ed, url) {
111
112 tinymce_<?php echo $buttonName; ?>.insert = function(){
113 if(this.v && this.v != ''){
114 tinymce.execCommand('mceInsertContent', false, '[xyz-ips snippet="'+tinymce_<?php echo $buttonName; ?>.xyz_ips_snippets[this.v]['title']+'"]');
115 }
116 };
117
118 },
119
120 /**
121 * Creates control instances based in the incomming name. This method is normally not
122 * needed since the addButton method of the tinymce.Editor class is a more easy way of adding buttons
123 * but you sometimes need to create more complex controls like listboxes, split buttons etc then this
124 * method can be used to create those.
125 *
126 * @param {String} n Name of the control to create.
127 * @param {tinymce.ControlManager} cm Control manager to use inorder to create new control.
128 * @return {tinymce.ui.Control} New control instance or null if no control was created.
129 */
130 createControl : function(n, cm) {
131 if(n=='<?php echo $buttonName; ?>'){
132 var c = cm.createSplitButton('<?php echo $buttonName; ?>', {
133 title : tinymce_<?php echo $buttonName; ?>.title,
134 image : tinymce_<?php echo $buttonName; ?>.url,
135 onclick : tinymce_<?php echo $buttonName; ?>.insert
136 });
137
138 // Add some values to the list box
139
140
141 c.onRenderMenu.add(function(c, m){
142 for (var id in tinymce_<?php echo $buttonName; ?>.xyz_ips_snippets){
143 m.add({
144 v : id,
145 title : tinymce_<?php echo $buttonName; ?>.xyz_ips_snippets[id]['title'],
146 onclick : tinymce_<?php echo $buttonName; ?>.insert
147 });
148 }
149 });
150
151
152 // Return the new listbox instance
153 return c;
154 }
155
156 return null;
157 },
158
159
160 });
161
162 // Register plugin
163 tinymce.PluginManager.add('<?php echo $buttonName; ?>', tinymce.plugins.<?php echo $buttonName; ?>);
164 })();
165
166 <?php } ?>
167