PluginProbe
Insert Html Snippet / 1.2.5
Insert Html Snippet v1.2.5
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.2.5, at editor_plugin.js.php

126 lines 4.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
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 } ?>
126