Google Maps CP - Version 1.0.21

Version Description

  • Modifies the integration with the Gutenberg editor, loading the maps directly in the editor.
Download this release

Release Info

Developer codepeople
Plugin Icon 128x128 Google Maps CP
Version 1.0.21
Comparing to
See all releases

Code changes from version 1.0.20 to 1.0.21

codepeople-post-map.php CHANGED
@@ -2,7 +2,7 @@
2
  /*
3
  Plugin Name: Google Maps CP
4
  Text Domain: codepeople-post-map
5
- Version: 1.0.20
6
  Author: CodePeople
7
  Author URI: http://wordpress.dwbooster.com/content-tools/codepeople-post-map
8
  Plugin URI: http://wordpress.dwbooster.com/content-tools/codepeople-post-map
@@ -80,6 +80,8 @@ function cpm_init(){
80
  add_action( 'loop_end', 'cpm_loop_end' );
81
 
82
  add_filter('widget_text', 'do_shortcode');
 
 
83
  }
84
  }
85
 
2
  /*
3
  Plugin Name: Google Maps CP
4
  Text Domain: codepeople-post-map
5
+ Version: 1.0.21
6
  Author: CodePeople
7
  Author URI: http://wordpress.dwbooster.com/content-tools/codepeople-post-map
8
  Plugin URI: http://wordpress.dwbooster.com/content-tools/codepeople-post-map
80
  add_action( 'loop_end', 'cpm_loop_end' );
81
 
82
  add_filter('widget_text', 'do_shortcode');
83
+
84
+ $cpm_master_obj->preview();
85
  }
86
  }
87
 
include/functions.php CHANGED
@@ -816,7 +816,16 @@ class CPM {
816
  * Loads the scripts required to integrate the plugin with the Gutenberg Editor.
817
  */
818
  function load_gutenberg_code(){
819
- wp_enqueue_script('corner-ad-gutenberg-editor', CPM_PLUGIN_URL.'/js/gutenberg.js');
 
 
 
 
 
 
 
 
 
820
  } // End load_gutenberg_code
821
 
822
  /**
@@ -1168,6 +1177,64 @@ class CPM {
1168
  return $output;
1169
  } // End replace_shortcode
1170
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1171
  /*
1172
  * Generates the DIV tag where the map will be loaded
1173
  */
816
  * Loads the scripts required to integrate the plugin with the Gutenberg Editor.
817
  */
818
  function load_gutenberg_code(){
819
+ global $post;
820
+ wp_enqueue_style('cpm-admin-gutenberg-editor-css', CPM_PLUGIN_URL.'/styles/cpm-gutenberg.css');
821
+
822
+ if(!empty($post)) $url = get_preview_post_link($post->ID);
823
+ else $url = rtrim( get_home_url( get_current_blog_id() ), "/" ).( ( strpos( get_current_blog_id(), '?' ) === false ) ? "/" : "" );
824
+
825
+ $url .= ((strpos($url, '?') === false) ? '?' : '&').'cpm-preview=';
826
+ $config = array('url' => $url);
827
+ wp_enqueue_script('cpm-gutenberg-editor', CPM_PLUGIN_URL.'/js/gutenberg.js');
828
+ wp_localize_script('cpm-gutenberg-editor', 'cpm_ge_config', $config);
829
  } // End load_gutenberg_code
830
 
831
  /**
1177
  return $output;
1178
  } // End replace_shortcode
1179
 
1180
+ function preview()
1181
+ {
1182
+ $user = wp_get_current_user();
1183
+ $allowed_roles = array('editor', 'administrator', 'author');
1184
+
1185
+ if(array_intersect($allowed_roles, $user->roles ))
1186
+ {
1187
+ if(
1188
+ !empty($_REQUEST['cpm-preview']) &&
1189
+ !empty($_REQUEST['post-id']) &&
1190
+ ($post_id = @intval($_REQUEST['post-id'])) !== 0
1191
+ )
1192
+ {
1193
+ // Sanitizing variable
1194
+ $preview = stripcslashes($_REQUEST['cpm-preview']);
1195
+ $preview = strip_tags($preview);
1196
+
1197
+ // Remove every shortcode that is not in the music store list
1198
+ remove_all_shortcodes();
1199
+ add_shortcode('codepeople-post-map', array(&$this, 'replace_shortcode'));
1200
+ get_post($post_id);
1201
+
1202
+ if(has_shortcode($preview, 'codepeople-post-map'))
1203
+ {
1204
+ // To indicate in the replace_shortcode that should be used the particular settings.
1205
+ global $id, $cpm_in_loop;
1206
+ $id = $post_id;
1207
+ $cpm_in_loop = true;
1208
+
1209
+ // Includes the print attribute in the shortcode
1210
+ $preview = preg_replace('/(\[codepeople\-post\-map)/i', '$1 print="1" ', $preview);
1211
+ wp_head();
1212
+ print '<div class="cpm-preview-container">'.do_shortcode($preview).'</div>';
1213
+
1214
+ if(
1215
+ function_exists('wp_print_styles') &&
1216
+ function_exists('wp_print_scripts')
1217
+ )
1218
+ {
1219
+ wp_print_styles();
1220
+ wp_print_scripts();
1221
+ }
1222
+ else
1223
+ {
1224
+ wp_footer();
1225
+ }
1226
+ print'<script type="text/javascript">jQuery(window).on("load", function(){
1227
+ var frameEl = window.frameElement,
1228
+ cpm = jQuery(".cpm-map:visible");
1229
+ if(frameEl)
1230
+ frameEl.height = cpm.outerHeight(true)+5;
1231
+ });</script>';
1232
+ exit;
1233
+ }
1234
+ }
1235
+ }
1236
+ } // End preview
1237
+
1238
  /*
1239
  * Generates the DIV tag where the map will be loaded
1240
  */
js/gutenberg.js CHANGED
@@ -29,7 +29,9 @@ jQuery(function(){
29
  }
30
  },
31
 
32
- edit: function( props ) {
 
 
33
  function onChangeMap(evt)
34
  {
35
  props.setAttributes({shortcode: evt.target.value});
@@ -40,15 +42,30 @@ jQuery(function(){
40
  props.attributes.shortcode = cpm_generate_shortcode();
41
  }
42
 
43
- return el(
44
- 'textarea',
 
 
 
 
 
 
 
 
 
 
 
 
45
  {
46
- key : 'cpgm-shortcode',
47
- onChange: onChangeMap,
48
- value : props.attributes.shortcode,
49
- style : {width:"100%", resize: "vertical"}
 
50
  }
51
- );
 
 
52
  },
53
 
54
  save: function( props ) {
@@ -59,4 +76,39 @@ jQuery(function(){
59
  window.wp.blocks,
60
  window.wp.element
61
  );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
62
  });
29
  }
30
  },
31
 
32
+ edit: function( props )
33
+ {
34
+ var children = [], postID = wp.data.select("core/editor").getCurrentPostId();
35
  function onChangeMap(evt)
36
  {
37
  props.setAttributes({shortcode: evt.target.value});
42
  props.attributes.shortcode = cpm_generate_shortcode();
43
  }
44
 
45
+ return [
46
+ el(
47
+ 'textarea',
48
+ {
49
+ key : 'cpgm-shortcode',
50
+ onChange: onChangeMap,
51
+ value : props.attributes.shortcode,
52
+ style : {width:"100%", resize: "vertical"}
53
+ }
54
+ ),
55
+ el(
56
+ 'div', {className: 'cpm-iframe-container'},
57
+ el('div', {className: 'cpm-iframe-overlay'}),
58
+ el('iframe',
59
  {
60
+ key: 'cpm_store_iframe',
61
+ src: cpm_ge_config.url+encodeURIComponent(props.attributes.shortcode)+'&post-id='+encodeURIComponent(postID),
62
+ height: 0,
63
+ width: 500,
64
+ scrolling: 'no'
65
  }
66
+ )
67
+ )
68
+ ];
69
  },
70
 
71
  save: function( props ) {
76
  window.wp.blocks,
77
  window.wp.element
78
  );
79
+
80
+ // Autoupdate
81
+ var reloading_iframes;
82
+ function autoupdate()
83
+ {
84
+ var save_draft = jQuery('.editor-post-save-draft');
85
+ if(save_draft.length) save_draft.click();
86
+ else
87
+ {
88
+ var update_btn = jQuery('.editor-post-publish-button');
89
+ if(update_btn.length) update_btn.click();
90
+ else
91
+ {
92
+ try{ wp.heartbeat.connectNow(); } catch(err){}
93
+ }
94
+ }
95
+ if('number' === typeof reloading_iframes)
96
+ {
97
+ clearTimeout(reloading_iframes);
98
+ delete reloading_iframes;
99
+ }
100
+ reloading_iframes = setTimeout(function(){
101
+ jQuery('.cpm-iframe-container iframe').each(function(){
102
+ this.contentWindow.location.reload();
103
+ });
104
+ }, 4000);
105
+ };
106
+
107
+ jQuery(document).on('change click', '#codepeople_post_map_form :input, [id*="cpm_point"]',
108
+ function(evt)
109
+ {
110
+ var t = jQuery(evt.target);
111
+ if(evt.type == 'click' && t.is('input[type="button"]') || evt.type == 'change') autoupdate();
112
+ }
113
+ );
114
  });
readme.txt CHANGED
@@ -517,6 +517,10 @@ Now the most important part create the shape's area. To create the shape's area
517
 
518
  == Changelog ==
519
 
 
 
 
 
520
  = 1.0.20 =
521
 
522
  * Implements the integration with the latest version of the Gutenberg editor.
517
 
518
  == Changelog ==
519
 
520
+ = 1.0.21 =
521
+
522
+ * Modifies the integration with the Gutenberg editor, loading the maps directly in the editor.
523
+
524
  = 1.0.20 =
525
 
526
  * Implements the integration with the latest version of the Gutenberg editor.
styles/cpm-gutenberg.css ADDED
@@ -0,0 +1,7 @@
 
 
 
 
 
 
 
1
+ .cpm-iframe-container {
2
+ position: relative;
3
+ }
4
+ .cpm-iframe-overlay {
5
+ position: absolute;
6
+ top: 0; right: 0; bottom: 0; left: 0;
7
+ }