PluginProbe
Insert PHP Code Snippet / 1.1
Insert PHP Code Snippet v1.1
1.4.7 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 1.4.4 1.4.5 1.4.6 trunk 1.0 1.1 1.2 1.2.1 1.2.2 1.2.3 1.2.4 1.2.5 1.2.6 1.3 All 27 releases
insert-php-code-snippet / editor_plugin.js.php

editor_plugin.js.php in Insert PHP Code Snippet 1.1, at editor_plugin.js.php

123 lines 4.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 if ( ! is_user_logged_in() )
4 die('You must be logged in to access this script.');
5
6 if(!isset($shortcodesXYZEP))
7 $shortcodesXYZEP = new XYZ_Insert_Php_TinyMCESelector();
8
9 global $wpdb;
10
11
12 $xyz_snippets_arr=$wpdb->get_results($wpdb->prepare( "SELECT id,title FROM ".$wpdb->prefix."xyz_ips_short_code WHERE status=%d ORDER BY id DESC",1),ARRAY_A );
13 // print_r($xyz_snippets_arr);
14 if(count($xyz_snippets_arr)==0)
15 die;
16
17 if(floatval(get_bloginfo('version'))>=3.9)
18 {
19 ?>
20 (function() {
21
22 tinymce.PluginManager.add('<?php echo $shortcodesXYZEP->buttonName; ?>', function( editor, url ) {
23 editor.addButton( '<?php echo $shortcodesXYZEP->buttonName; ?>', {
24 title: 'Insert PHP Code Snippet',
25 type: 'menubutton',
26 icon: 'icon xyz-ips-own-icon',
27 menu: [
28 <?php foreach ($xyz_snippets_arr as $key=>$val) { ?>
29 {
30 text: '<?php echo addslashes($val['title']); ?>',
31 value: '[xyz-ips snippet="<?php echo addslashes($val['title']); ?>"]',
32 onclick: function() {
33 editor.insertContent(this.value());
34 }
35 },
36 <?php } ?>
37 ]
38 });
39 });
40
41 })();
42 <?php } else {
43
44 $xyz_snippets = array(
45 'title' =>'Insert PHP Code Snippet',
46 'url' => plugins_url('insert-php-code-snippet/images/logo.png'),
47 'xyz_ips_snippets' => $xyz_snippets_arr
48 );
49 ?>
50
51 var tinymce_<?php echo $shortcodesXYZEP->buttonName; ?> =<?php echo json_encode($xyz_snippets) ?>;
52
53
54 (function() {
55 //******* Load plugin specific language pack
56
57 tinymce.create('tinymce.plugins.<?php echo $shortcodesXYZEP->buttonName; ?>', {
58 /**
59 * Initializes the plugin, this will be executed after the plugin has been created.
60 * This call is done before the editor instance has finished it's initialization so use the onInit event
61 * of the editor instance to intercept that event.
62 *
63 * @param {tinymce.Editor} ed Editor instance that the plugin is initialized in.
64 * @param {string} url Absolute URL to where the plugin is located.
65 */
66 init : function(ed, url) {
67
68 tinymce_<?php echo $shortcodesXYZEP->buttonName; ?>.insert = function(){
69 if(this.v && this.v != ''){
70 tinymce.execCommand('mceInsertContent', false, '[xyz-ips snippet="'+tinymce_<?php echo $shortcodesXYZEP->buttonName; ?>.xyz_ips_snippets[this.v]['title']+'"]');
71 }
72 };
73
74 },
75
76 /**
77 * Creates control instances based in the incomming name. This method is normally not
78 * needed since the addButton method of the tinymce.Editor class is a more easy way of adding buttons
79 * but you sometimes need to create more complex controls like listboxes, split buttons etc then this
80 * method can be used to create those.
81 *
82 * @param {String} n Name of the control to create.
83 * @param {tinymce.ControlManager} cm Control manager to use inorder to create new control.
84 * @return {tinymce.ui.Control} New control instance or null if no control was created.
85 */
86 createControl : function(n, cm) {
87 if(n=='<?php echo $shortcodesXYZEP->buttonName; ?>'){
88 var c = cm.createSplitButton('<?php echo $shortcodesXYZEP->buttonName; ?>', {
89 title : tinymce_<?php echo $shortcodesXYZEP->buttonName; ?>.title,
90 image : tinymce_<?php echo $shortcodesXYZEP->buttonName; ?>.url,
91 onclick : tinymce_<?php echo $shortcodesXYZEP->buttonName; ?>.insert
92 });
93
94 // Add some values to the list box
95
96
97 c.onRenderMenu.add(function(c, m){
98 for (var id in tinymce_<?php echo $shortcodesXYZEP->buttonName; ?>.xyz_ips_snippets){
99 m.add({
100 v : id,
101 title : tinymce_<?php echo $shortcodesXYZEP->buttonName; ?>.xyz_ips_snippets[id]['title'],
102 onclick : tinymce_<?php echo $shortcodesXYZEP->buttonName; ?>.insert
103 });
104 }
105 });
106
107
108 // Return the new listbox instance
109 return c;
110 }
111
112 return null;
113 },
114
115
116 });
117
118 // Register plugin
119 tinymce.PluginManager.add('<?php echo $shortcodesXYZEP->buttonName; ?>', tinymce.plugins.<?php echo $shortcodesXYZEP->buttonName; ?>);
120 })();
121
122 <?php } ?>
123