PluginProbe
Insert Html Snippet / 1.3
Insert Html Snippet v1.3
1.4.6 trunk 1.0 1.0.1 1.1 1.1.1 1.2 1.2.1 1.2.2 1.2.3 1.2.4 1.2.5 1.3 1.3.1 1.3.2 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 All 27 releases
insert-html-snippet / editor_plugin.js.php

editor_plugin.js.php in Insert Html Snippet 1.3, at editor_plugin.js.php

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