PluginProbe
Insert PHP Code Snippet / trunk
Insert PHP Code Snippet vtrunk
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
← All changes | editor_plugin.js.php +68 -24 1.2trunk View file →
@@ -1,27 +1,71 @@
1 1 <?php
2 +if ( ! defined( 'ABSPATH' ) )
3 + exit;
4 +
2 5 header( 'Content-Type: text/javascript' );
3 - if ( ! is_user_logged_in() )
6 + if ( ! is_user_logged_in() || ! current_user_can( 'edit_posts' ) )
4 7 die('You must be logged in to access this script.');
5 8
6 - if(!isset($shortcodesXYZEP))
7 - $shortcodesXYZEP = new XYZ_Insert_Php_TinyMCESelector();
9 +/*if(!isset($shortcodesXYZEP))
10 + $shortcodesXYZEP = new XYZ_Insert_Php_TinyMCESelector();*/
8 11
9 - global $wpdb;
12 +global $wpdb;
13 +$buttonName = 'xyz_ips_snippet_selecter';
10 14
15 +$xyz_snippets_arr=$wpdb->get_results($wpdb->prepare( "SELECT id,title FROM ".$wpdb->prefix."xyz_ips_short_code WHERE status=%d and insertionMethod=%d ORDER BY id DESC",1,2),ARRAY_A );
11 16
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)
17 +if(empty($xyz_snippets_arr))//if(count($xyz_snippets_arr)==0)
15 18 die;
16 19
17 20 if(floatval(get_bloginfo('version'))>=3.9)
18 21 {
19 22 ?>
23 + (function() {
24 + /* Register the buttons */
25 + tinymce.create('tinymce.plugins.xyz_ips_snippet', {
26 + init : function(ed, url) {
27 + /**
28 + * Inserts shortcode content
29 + */
30 + ed.addButton( '<?php echo $buttonName;?>', {
31 + title: 'Insert PHP Code Snippet',
32 + type: 'menubutton',
33 + icon: 'icon xyz-ips-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-ips 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_ips_buttons', tinymce.plugins.xyz_ips_snippet );
58 +})();
59 +<?php
60 +}
61 +/*else if(floatval(get_bloginfo('version'))>=3.9)
62 +{
63 +?>
20 64 (function() {
21 65
22 - tinymce.PluginManager.add('<?php echo $shortcodesXYZEP->buttonName; ?>', function( editor, url ) {
23 - editor.addButton( '<?php echo $shortcodesXYZEP->buttonName; ?>', {
66 + tinymce.PluginManager.add('<?php echo $buttonName; ?>', function( editor, url ) {
67 + editor.addButton( '<?php echo $buttonName; ?>', {
24 68 title: 'Insert PHP Code Snippet',
25 69 type: 'menubutton',
26 70 icon: 'icon xyz-ips-own-icon',
27 71 menu: [
@@ -38,24 +82,24 @@
38 82 });
39 83 });
40 84
41 85 })();
42 -<?php } else {
86 +<?php }*/ else {
43 87
44 88 $xyz_snippets = array(
45 89 'title' =>'Insert PHP Code Snippet',
46 - 'url' => plugins_url('insert-php-code-snippet/images/logo.png'),
90 + 'url' => plugins_url('images/logo.png', XYZ_INSERT_PHP_PLUGIN_FILE),
47 91 'xyz_ips_snippets' => $xyz_snippets_arr
48 92 );
49 93 ?>
50 94
51 -var tinymce_<?php echo $shortcodesXYZEP->buttonName; ?> =<?php echo json_encode($xyz_snippets) ?>;
95 +var tinymce_<?php echo $buttonName; ?> =<?php echo json_encode($xyz_snippets) ?>;
52 96
53 97
54 98 (function() {
55 99 //******* Load plugin specific language pack
56 100
57 - tinymce.create('tinymce.plugins.<?php echo $shortcodesXYZEP->buttonName; ?>', {
101 + tinymce.create('tinymce.plugins.<?php echo $buttonName; ?>', {
58 102 /**
59 103 * Initializes the plugin, this will be executed after the plugin has been created.
60 104 * This call is done before the editor instance has finished it's initialization so use the onInit event
61 105 * of the editor instance to intercept that event.
@@ -64,11 +108,11 @@
64 108 * @param {string} url Absolute URL to where the plugin is located.
65 109 */
66 110 init : function(ed, url) {
67 111
68 - tinymce_<?php echo $shortcodesXYZEP->buttonName; ?>.insert = function(){
112 + tinymce_<?php echo $buttonName; ?>.insert = function(){
69 113 if(this.v && this.v != ''){
70 - tinymce.execCommand('mceInsertContent', false, '[xyz-ips snippet="'+tinymce_<?php echo $shortcodesXYZEP->buttonName; ?>.xyz_ips_snippets[this.v]['title']+'"]');
114 + tinymce.execCommand('mceInsertContent', false, '[xyz-ips snippet="'+tinymce_<?php echo $buttonName; ?>.xyz_ips_snippets[this.v]['title']+'"]');
71 115 }
72 116 };
73 117
74 118 },
@@ -83,13 +127,13 @@
83 127 * @param {tinymce.ControlManager} cm Control manager to use inorder to create new control.
84 128 * @return {tinymce.ui.Control} New control instance or null if no control was created.
85 129 */
86 130 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
131 + if(n=='<?php echo $buttonName; ?>'){
132 + var c = cm.createSplitButton('<?php echo $buttonName; ?>', {
133 + title : tinymce_<?php echo $buttonName; ?>.title,
134 + image : tinymce_<?php echo $buttonName; ?>.url,
135 + onclick : tinymce_<?php echo $buttonName; ?>.insert
92 136 });
93 137
94 138 // Add some values to the list box
95 139
@@ -94,13 +138,13 @@
94 138 // Add some values to the list box
95 139
96 140
97 141 c.onRenderMenu.add(function(c, m){
98 - for (var id in tinymce_<?php echo $shortcodesXYZEP->buttonName; ?>.xyz_ips_snippets){
142 + for (var id in tinymce_<?php echo $buttonName; ?>.xyz_ips_snippets){
99 143 m.add({
100 144 v : id,
101 - title : tinymce_<?php echo $shortcodesXYZEP->buttonName; ?>.xyz_ips_snippets[id]['title'],
102 - onclick : tinymce_<?php echo $shortcodesXYZEP->buttonName; ?>.insert
145 + title : tinymce_<?php echo $buttonName; ?>.xyz_ips_snippets[id]['title'],
146 + onclick : tinymce_<?php echo $buttonName; ?>.insert
103 147 });
104 148 }
105 149 });
106 150
@@ -115,8 +159,8 @@
115 159
116 160 });
117 161
118 162 // Register plugin
119 - tinymce.PluginManager.add('<?php echo $shortcodesXYZEP->buttonName; ?>', tinymce.plugins.<?php echo $shortcodesXYZEP->buttonName; ?>);
163 + tinymce.PluginManager.add('<?php echo $buttonName; ?>', tinymce.plugins.<?php echo $buttonName; ?>);
120 164 })();
121 165
122 166 <?php } ?>