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 +117 -25 1.0.1trunk View file →
@@ -1,23 +1,106 @@
1 1 <?php
2 +if ( ! defined( 'ABSPATH' ) )
3 + exit;
2 4
5 +header( 'Content-Type: text/javascript' );
3 6 if ( ! is_user_logged_in() )
4 7 die('You must be logged in to access this script.');
5 8
6 - if(!isset($shortcodesXYZEH))
7 - $shortcodesXYZEH = new XYZ_Insert_Html_TinyMCESelector();
9 +/*if(!isset($shortcodesXYZEH))
10 + $shortcodesXYZEH = new XYZ_Insert_Html_TinyMCESelector();*/
8 11
9 - global $wpdb;
10 -// $ordered_sct = array_keys($shortcode_tags);
11 -// sort($ordered_sct);
12 +global $wpdb;
13 +$buttonName = 'xyz_ihs_snippet_selector';
12 14
13 - $ordered_sct = $wpdb->get_results( "SELECT * FROM ".$wpdb->prefix."xyz_ihs_short_code WHERE status='1' ORDER BY id DESC" );
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 +{
14 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() {
15 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 +
16 99 (function() {
17 100 //******* Load plugin specific language pack
18 101
19 - tinymce.create('tinymce.plugins.<?php echo $shortcodesXYZEH->buttonName; ?>', {
102 + tinymce.create('tinymce.plugins.<?php echo $buttonName; ?>', {
20 103 /**
21 104 * Initializes the plugin, this will be executed after the plugin has been created.
22 105 * This call is done before the editor instance has finished it's initialization so use the onInit event
23 106 * of the editor instance to intercept that event.
@@ -25,8 +108,14 @@
25 108 * @param {tinymce.Editor} ed Editor instance that the plugin is initialized in.
26 109 * @param {string} url Absolute URL to where the plugin is located.
27 110 */
28 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 + };
29 118
30 119 },
31 120
32 121 /**
@@ -39,30 +128,31 @@
39 128 * @param {tinymce.ControlManager} cm Control manager to use inorder to create new control.
40 129 * @return {tinymce.ui.Control} New control instance or null if no control was created.
41 130 */
42 131 createControl : function(n, cm) {
43 - if(n=='<?php echo $shortcodesXYZEH->buttonName; ?>'){
44 - var mlb = cm.createListBox('<?php echo $shortcodesXYZEH->buttonName; ?>List', {
45 - title : 'HTML Snippets',
46 - onselect : function(v) { //Option value as parameter
47 - if(v != ''){
48 - if(tinyMCE.activeEditor.selection.getContent() != ''){
49 - tinyMCE.activeEditor.selection.setContent('[' + v + ']' + tinyMCE.activeEditor.selection.getContent() + '[/' + v + ']');
50 - }
51 - else{
52 - tinyMCE.activeEditor.selection.setContent('[' + v + ']');
53 - }
54 - }
55 - }
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
56 137 });
57 138
58 139 // Add some values to the list box
59 - <?php foreach($ordered_sct as $sct):?>
60 - mlb.add('<?php echo $sct->title;?>', '<?php echo 'xyz-ihs snippet="'.$sct->title.'"';?>');
61 - <?php endforeach;?>
140 +
62 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 +
63 153 // Return the new listbox instance
64 - return mlb;
154 + return c;
65 155 }
66 156
67 157 return null;
68 158 },
@@ -70,6 +160,8 @@
70 160
71 161 });
72 162
73 163 // Register plugin
74 - tinymce.PluginManager.add('<?php echo $shortcodesXYZEH->buttonName; ?>', tinymce.plugins.<?php echo $shortcodesXYZEH->buttonName; ?>);
164 + tinymce.PluginManager.add('<?php echo $buttonName; ?>', tinymce.plugins.<?php echo $buttonName; ?>);
75 165 })();
166 +
167 +<?php } ?>