Google_Maps_Builder_Core_Shortcode_Generator

GMB_Shortcode_Generator class.

Defined (1)

The class is defined in the following location(s).

/vendor/wordimpress/maps-builder-core/includes/admin/class-gmc-shortcode-generator.php  
  1. abstract class Google_Maps_Builder_Core_Shortcode_Generator { 
  2.  
  3. /** 
  4. * Constructor 
  5. */ 
  6. public function __construct() { 
  7.  
  8. add_action( 'admin_head', array( $this, 'add_shortcode_button' ), 20 ); 
  9. add_filter( 'tiny_mce_version', array( $this, 'refresh_mce' ), 20 ); 
  10. add_filter( 'mce_external_languages', array( $this, 'add_tinymce_lang' ), 20, 1 ); 
  11.  
  12. // Tiny MCE button icon 
  13. add_action( 'admin_head', array( $this, 'set_tinymce_button_icon' ) ); 
  14. add_action( 'wp_ajax_gmb_shortcode_iframe', array( $this, 'gmb_shortcode_iframe' ), 9 ); 
  15.  
  16. /** 
  17. * Add a button for the GPR shortcode to the WP editor. 
  18. */ 
  19. public function add_shortcode_button() { 
  20. global $post, $pagenow; 
  21.  
  22. if ( ! current_user_can( 'edit_posts' ) && ! current_user_can( 'edit_pages' ) ) { 
  23. return; 
  24. //Be sure to not allow on out post type 
  25. if ( ! isset( $post->post_type ) || $post->post_type === 'google_maps' ) { 
  26. return; 
  27.  
  28. if ( ! in_array( $pagenow, array( 'post.php', 'post-new.php' ) ) ) { 
  29. return; 
  30.  
  31. // check if WYSIWYG is enabled 
  32. if ( get_user_option( 'rich_editing' ) == 'true' ) { 
  33. add_filter( 'mce_external_plugins', array( $this, 'add_shortcode_tinymce_plugin' ), 10 ); 
  34. add_filter( 'mce_buttons', array( $this, 'register_shortcode_button' ), 10 ); 
  35.  
  36. /** 
  37. * Add TinyMCE language function. 
  38. * @param array $arr 
  39. * @return array 
  40. */ 
  41. public function add_tinymce_lang( $arr ) { 
  42. $arr['gmb_shortcode_button'] = GMB_CORE_PATH . '/includes/admin/shortcode-generator-i18n.php'; 
  43.  
  44. return $arr; 
  45.  
  46. /** 
  47. * Register the shortcode button. 
  48. * @param array $buttons 
  49. * @return array 
  50. */ 
  51. public function register_shortcode_button( $buttons ) { 
  52.  
  53. array_push( $buttons, '|', 'gmb_shortcode_button' ); 
  54.  
  55. return $buttons; 
  56.  
  57. /** 
  58. * Add the shortcode button to TinyMCE 
  59. * @param array $plugin_array 
  60. * @return array 
  61. */ 
  62. public function add_shortcode_tinymce_plugin( $plugin_array ) { 
  63.  
  64. $plugin_array['gmb_shortcode_button'] = GMB_CORE_URL . '/assets/js/admin/admin-shortcode.js'; 
  65.  
  66. return $plugin_array; 
  67.  
  68. /** 
  69. * Force TinyMCE to refresh. 
  70. * @param int $ver 
  71. * @return int 
  72. */ 
  73. public function refresh_mce( $ver ) { 
  74. $ver += 3; 
  75.  
  76. return $ver; 
  77.  
  78. /** 
  79. * Adds admin styles for setting the tinymce button icon 
  80. */ 
  81. public static function set_tinymce_button_icon() { 
  82. ?> 
  83. <style> 
  84. i.mce-i-gmb { 
  85. font: 400 20px/1 dashicons; 
  86.  
  87. padding: 0; 
  88. vertical-align: top; 
  89. speak: none; 
  90. -webkit-font-smoothing: antialiased; 
  91. -moz-osx-font-smoothing: grayscale; 
  92. margin-left: -2px; 
  93. padding-right: 2px 
  94.  
  95. #gmb_shortcode_dialog-body { 
  96. background: #F1F1F1; 
  97.  
  98. .gmb-shortcode-submit { 
  99. margin: 0 -15px; 
  100. position: fixed; 
  101. bottom: 0; 
  102. background: #FFF; 
  103. width: 100%; 
  104. padding: 15px; 
  105. border-top: 1px solid #DDD; 
  106.  
  107. div.place-id-set { 
  108. clear: both; 
  109. float: left; 
  110. width: 100%; 
  111.  
  112. </style> 
  113. <?php 
  114.  
  115. /** 
  116. * Display the contents of the iframe used when the GPR Shortcode Generator is clicked 
  117. * TinyMCE button is clicked. 
  118. * @param int $ver 
  119. * @return int 
  120. */ 
  121. public static function gmb_shortcode_iframe() { 
  122. set_current_screen( 'google-maps-builder' ); 
  123. $suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min'; 
  124.  
  125. //Shortcode Generator Specific JS 
  126. wp_register_script( 'gmb-shortcode-generator', GMB_CORE_URL . '/assets/js/admin/shortcode-iframe' . $suffix . '.js', array( 'jquery' ) ); 
  127. wp_enqueue_script( 'gmb-shortcode-generator' ); 
  128.  
  129. iframe_header(); ?> 
  130.  
  131. <style> 
  132. #gmb-wrap { 
  133. margin: 0 1em; 
  134. overflow: hidden; 
  135. padding-bottom: 75px; 
  136.  
  137. /* iFrame Styles */ 
  138. #gmb_settings label { 
  139. margin-bottom: 3px; 
  140. display: block; 
  141.  
  142. div.gmb-shortcode-hidden-fields-wrap { 
  143. display: none; 
  144.  
  145. .gmb-place-search-wrap > div.gmb-map-select { 
  146. width: 65%; 
  147. margin-right: 2%; 
  148. float: left; 
  149.  
  150. div.updated { 
  151. width: 100%; 
  152. float: left; 
  153. box-sizing: border-box; 
  154.  
  155. div.gmb-edit-shortcode { 
  156. border-color: orange; 
  157.  
  158. <?php 
  159. /** 
  160. * Add styles to the shortcode iFrame 
  161. * Runs inside of the style tag 
  162. * @since 2.1.0 
  163. */ 
  164. do_action( 'gmb_shortcode_iframe_style' ); 
  165.  
  166. ?> 
  167. </style> 
  168. <div class="wrap" id="gmb-wrap"> 
  169. <form id="gmb_settings" style="float: left; width: 100%;"> 
  170. <?php do_action( 'gmb_shortcode_iframe_before' ); ?> 
  171. <fieldset id="gmb_location_lookup_fields" class="gmb-place-search-wrap clear" style="margin:1em 0;"> 
  172. <div class="gmb-map-select"> 
  173. <label for="gmb_location_lookup"><strong><?php _e( 'Choose a Map', 'google-maps-builder' ); ?></strong></label> 
  174. <?php echo Google_Maps_Builder()->html->maps_dropdown(); ?> 
  175. </div> 
  176. </fieldset> 
  177.  
  178. <div class="updated new-shortcode"> 
  179. <p><?php _e( '<strong>Insert Shortcode</strong>: Select your desired map from the dropdown above then click create shortcode below.', 'google-maps-builder' ); ?></p> 
  180. </div> 
  181.  
  182. <div class="updated gmb-edit-shortcode" style="display: none;"> 
  183. <p><?php _e( '<strong>Edit Active Shortcode:</strong> Customize the map for this shortcode by modifying the map selection above.', 'google-maps-builder' ); ?></p> 
  184. </div> 
  185.  
  186. <?php do_action( 'gmb_shortcode_iframe_after' ); ?> 
  187.  
  188. <fieldset class="gmb-shortcode-submit"> 
  189. <input id="gmb_submit" type="submit" class="button-small button-primary" value="<?php _e( 'Create Shortcode', 'google-maps-builder' ); ?>" /> 
  190. <input id="gmb_cancel" type="button" class="button-small button-secondary" value="<?php _e( 'Cancel', 'google-maps-builder' ); ?>" /> 
  191. </fieldset> 
  192.  
  193. </form> 
  194. <?php 
  195. /** 
  196. * Runs after shortcode form in iFrame 
  197. * @since 2.1.0 
  198. */ 
  199. do_action( 'gmb_after_shortcode_form' ); 
  200. ?> 
  201. </div> 
  202.  
  203.  
  204. <?php iframe_footer(); 
  205. exit(); 
  206.