PluginProbe
Insert Html Snippet / trunk
Insert Html Snippet vtrunk
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
← All changes | editor_plugin.js.php +167 -125 1.2.3trunk View file →
@@ -1,125 +1,167 @@
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 -
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)
21 -{
22 -?>
23 -(function() {
24 -
25 - tinymce.PluginManager.add('<?php echo $shortcodesXYZEH->buttonName; ?>', function( editor, url ) {
26 - editor.addButton( '<?php echo $shortcodesXYZEH->buttonName; ?>', {
27 - title: 'Insert HTML Snippet',
28 - type: 'menubutton',
29 - icon: 'icon xyz-ihs-own-icon',
30 - menu: [
31 -<?php foreach ($xyz_snippets_arr as $key=>$val) { ?>
32 - {
33 - text: '<?php echo addslashes($val['title']); ?>',
34 - value: '[xyz-ihs snippet="<?php echo addslashes($val['title']); ?>"]',
35 - onclick: function() {
36 - editor.insertContent(this.value());
37 - }
38 - },
39 -<?php } ?>
40 - ]
41 - });
42 - });
43 -
44 -})();
45 -<?php } else {
46 -
47 - $xyz_snippets = array(
48 - 'title' =>'Insert HTML Snippet',
49 - 'url' => plugins_url('images/logo.png',XYZ_INSERT_HTML_PLUGIN_FILE),
50 - 'xyz_ihs_snippets' => $xyz_snippets_arr
51 - );
52 - ?>
53 -
54 -var tinymce_<?php echo $shortcodesXYZEH->buttonName; ?> =<?php echo json_encode($xyz_snippets) ?>;
55 -
56 -
57 -(function() {
58 - //******* Load plugin specific language pack
59 -
60 - tinymce.create('tinymce.plugins.<?php echo $shortcodesXYZEH->buttonName; ?>', {
61 - /**
62 - * Initializes the plugin, this will be executed after the plugin has been created.
63 - * This call is done before the editor instance has finished it's initialization so use the onInit event
64 - * of the editor instance to intercept that event.
65 - *
66 - * @param {tinymce.Editor} ed Editor instance that the plugin is initialized in.
67 - * @param {string} url Absolute URL to where the plugin is located.
68 - */
69 - init : function(ed, url) {
70 -
71 - tinymce_<?php echo $shortcodesXYZEH->buttonName; ?>.insert = function(){
72 - if(this.v && this.v != ''){
73 - tinymce.execCommand('mceInsertContent', false, '[xyz-ihs snippet="'+tinymce_<?php echo $shortcodesXYZEH->buttonName; ?>.xyz_ihs_snippets[this.v]['title']+'"]');
74 - }
75 - };
76 -
77 - },
78 -
79 - /**
80 - * Creates control instances based in the incomming name. This method is normally not
81 - * needed since the addButton method of the tinymce.Editor class is a more easy way of adding buttons
82 - * but you sometimes need to create more complex controls like listboxes, split buttons etc then this
83 - * method can be used to create those.
84 - *
85 - * @param {String} n Name of the control to create.
86 - * @param {tinymce.ControlManager} cm Control manager to use inorder to create new control.
87 - * @return {tinymce.ui.Control} New control instance or null if no control was created.
88 - */
89 - createControl : function(n, cm) {
90 - if(n=='<?php echo $shortcodesXYZEH->buttonName; ?>'){
91 - var c = cm.createSplitButton('<?php echo $shortcodesXYZEH->buttonName; ?>', {
92 - title : tinymce_<?php echo $shortcodesXYZEH->buttonName; ?>.title,
93 - image : tinymce_<?php echo $shortcodesXYZEH->buttonName; ?>.url,
94 - onclick : tinymce_<?php echo $shortcodesXYZEH->buttonName; ?>.insert
95 - });
96 -
97 - // Add some values to the list box
98 -
99 -
100 - c.onRenderMenu.add(function(c, m){
101 - for (var id in tinymce_<?php echo $shortcodesXYZEH->buttonName; ?>.xyz_ihs_snippets){
102 - m.add({
103 - v : id,
104 - title : tinymce_<?php echo $shortcodesXYZEH->buttonName; ?>.xyz_ihs_snippets[id]['title'],
105 - onclick : tinymce_<?php echo $shortcodesXYZEH->buttonName; ?>.insert
106 - });
107 - }
108 - });
109 -
110 -
111 - // Return the new listbox instance
112 - return c;
113 - }
114 -
115 - return null;
116 - },
117 -
118 -
119 - });
120 -
121 - // Register plugin
122 - tinymce.PluginManager.add('<?php echo $shortcodesXYZEH->buttonName; ?>', tinymce.plugins.<?php echo $shortcodesXYZEH->buttonName; ?>);
123 -})();
124 -
125 -<?php } ?>
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 and insertionMethod=%d ORDER BY id DESC",1,2),ARRAY_A );
16 +// print_r($xyz_snippets_arr);
17 +if(empty($xyz_snippets_arr))//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 } ?>