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