Advertisement
Guest User

front-map.php

a guest
Jun 18th, 2018
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 40.33 KB | None | 0 0
  1. <?php
  2. /*
  3. *FRONTPAGE - MAP WIDGET
  4. */
  5. add_action( 'widgets_init', 'optimizer_register_front_map' );
  6.  
  7. /*
  8. * Register widget.
  9. */
  10. function optimizer_register_front_map() {
  11. register_widget( 'optimizer_front_map' );
  12. }
  13.  
  14.  
  15. /*
  16. * Widget class.
  17. */
  18. class optimizer_front_Map extends WP_Widget {
  19.  
  20. /* ---------------------------- */
  21. /* -------- Widget setup -------- */
  22. /* ---------------------------- */
  23.  
  24.  
  25. function __construct() {
  26. if(is_customize_preview()){$widgetname = __( 'Contact', 'optimizer' ); }else{ $widgetname = __( '&diams; Contact Widget', 'optimizer' ); }
  27.  
  28. parent::__construct( 'optimizer_front_map', $widgetname, array(
  29. 'classname' => 'optimizer_front_map mapblock',
  30. 'description' => __( 'Optimizer Frontpage Contact lets you display Conact Form and Live Map.', 'optimizer' ),
  31. 'customize_selective_refresh' => true,
  32. ) );
  33. $this->alt_option_name = 'optimizer_front_map';
  34. add_action('wp_enqueue_scripts', array(&$this, 'optimizer_map_styles'));
  35. add_action('wp_enqueue_scripts', array(&$this, 'front_map_enqueue_css'));
  36. add_action('wp_footer', array(&$this, 'optimizer_map_run'), 100);
  37. }
  38.  
  39. /* ---------------------------- */
  40. /* ------- Display Widget -------- */
  41. /* ---------------------------- */
  42.  
  43. function widget( $args, $instance ) {
  44.  
  45.  
  46. extract( $args );
  47. /* Our variables from the widget settings. */
  48. $title = isset( $instance['title'] ) ? $instance['title']: __('GET IN TOUCH','optimizer');
  49. $subtitle = isset( $instance['subtitle'] ) ? apply_filters( 'wp_editor_widget_content', $instance['subtitle'] ) : __('Come have a cup of coffee with us','optimizer');
  50. $contactform = isset( $instance['contactform'] ) ? $instance['contactform'] : '';
  51. $contactfield1 = isset( $instance['contactfield1'] ) ? $instance['contactfield1'] : '';
  52. $contactstyle = isset( $instance['contactstyle'] ) ? $instance['contactstyle'] : 'style1';
  53. $contactalign = isset( $instance['contactalign'] ) ? $instance['contactalign'] : 'right';
  54.  
  55. $gdpr_policy_field = isset( $instance['gdpr_policy'] ) ? $instance['gdpr_policy'] : 'I agree with this Site\'s Privacy Policy';
  56.  
  57. $locations = isset( $instance['locations'] ) ? $instance['locations'] : array( );
  58. $height = isset( $instance['height'] ) ? apply_filters('widget_title', $instance['height']) : '500px';
  59. $divider = isset( $instance['divider'] ) ? apply_filters('widget_title', $instance['divider']) : 'fa-stop';
  60. $title_color = isset( $instance['title_color'] ) ? $instance['title_color'] : '';
  61. $content_bg = isset( $instance['content_bg'] ) ? $instance['content_bg'] : '';
  62. $content_bgimg = isset( $instance['content_bgimg'] ) ? esc_url($instance['content_bgimg']) : '';
  63. $style = isset( $instance['style'] ) ? apply_filters('widget_title', $instance['style']) : 'map_default';
  64. $zoom = isset( $instance['zoom'] ) ? absint($instance['zoom']) : '';
  65.  
  66. /* Before widget (defined by themes). */
  67. echo $before_widget;
  68.  
  69. //Sitegorigin Builder FIX
  70. echo '<span class="so_widget_id" data-panel-id="'.$this->id.'"></span>';
  71. if(is_customize_preview()) echo '<span class="widgetname">'.$this->name.'</span>';
  72. ?>
  73. <?php
  74.  
  75. //WIDGET EDIT BUTTON(Customizer)
  76. if(is_customize_preview()){ echo '<a class="edit_widget" title="'.__('Edit ','optimizer').$this->id.'"><i class="fa fa-pencil"></i></a>'; }
  77.  
  78. if(!empty($contactalign)) $contactalign ='form_'.$contactalign;
  79.  
  80. $var = $this->id;
  81. echo '<div class="centerfix"><div class="ast_map '.(empty($locations) && !empty($contactform) ?'no_map': 'has_map').' '.$contactstyle.' '.$contactalign.'">';
  82.  
  83. if ( !empty($title) || !empty($subtitle)){
  84. echo '<div class="homeposts_title title_'.str_replace('fa-','dvd_',$divider).'">';
  85. if ( $title || is_customize_preview() ){
  86. echo '<h2 class="home_title"><span>'.do_shortcode($title).'</span></h2>';
  87. }
  88. if ( $subtitle || is_customize_preview() ){
  89. echo '<div class="home_subtitle">'.do_shortcode($subtitle).'</div>';
  90. }
  91.  
  92. if ( $divider ){
  93. if( $divider !== 'no_divider'){
  94. if($divider == 'underline'){ $underline= 'title_underline';}else{$underline='';}
  95. echo '<div class="optimizer_divider '.$underline.' divider_style_'.str_replace('fa-','dvd_',$divider).'"><span class="div_left"></span><span class="div_middle"><i class="fa '.$divider.'"></i></span><span class="div_right"></span></div>';
  96. }
  97. }
  98. echo '</div>';
  99. }
  100.  
  101.  
  102. echo '<div class="contact_map_wrap">';
  103. if ( !empty($contactform) ){
  104.  
  105. if (isset($_POST['contact_name'])){ $contact_name = esc_attr($_POST['contact_name']); }else{ $contact_name = ''; }
  106. if (isset($_POST['contact_email'])){ $contact_email = esc_attr($_POST['contact_email']); }else { $contact_email = ''; }
  107. if (isset($_POST['contact_subject'])){ $contact_subject = esc_attr($_POST['contact_subject']); }else{ $contact_subject = ''; }
  108. if (isset($_POST['contact_message'])){ $contact_message = esc_textarea($_POST['contact_message']); }else{ $contact_message = ''; }
  109. if (isset($_POST['contact_extra'])){ $contact_field1 = esc_attr($_POST['contact_extra']); }else{ $contact_field1 = ''; }
  110. if (isset($_POST['gdpr_policy'])){ $gdpr_policy = esc_attr($_POST['gdpr_policy']); }else{ $gdpr_policy = ''; }
  111.  
  112. if ( !empty($contactfield1) ){$has_extra_field = 'has_extra_field';}else{$has_extra_field = '';}
  113. echo '<div class="contact_form_wrap '.$has_extra_field.'"><form id="'.$this->id.'_form">';
  114.  
  115. echo '<p><input placeholder="'.__('Name*', 'optimizer').'" type="text" name="contact_name" class="contact_input contact_name" value="'.$contact_name.'"></label></p>';
  116. echo '<p><input placeholder="'. __('Email*', 'optimizer').'" type="text" name="contact_email" class="contact_input contact_email" value="'.$contact_email.'"></label></p>';
  117. if ( !empty($contactfield1) ){
  118. echo '<p><input placeholder="'.sprintf( __( '%1$s', 'optimizer' ), $contactfield1 ).'" type="text" name="contactfield1" class="contact_input contact_extra" value="'.$contact_field1.'"></p>';
  119. }
  120. echo '<p><input placeholder="'. __('Subject*', 'optimizer').'" type="text" name="contact_subject" class="contact_input contact_subject" value="'.$contact_subject.'"></p>';
  121. echo '<p><textarea placeholder="'. __('Your Message', "optimizer").'" class="contact_message" name="contact_message">'.$contact_message.'</textarea></p>';
  122.  
  123. if ( !empty($gdpr_policy_field) ){
  124. echo '<p class="contact_widget_gdpr_policy"><input type="checkbox" name="gdpr_policy" class="contact_cgdpr" id="'.$this->id.'_gdpr_policy" ><label for="'.$this->id.'_gdpr_policy">'.do_shortcode($gdpr_policy_field).'</label></p>';
  125. }else{
  126. echo '<p class="contact_widget_gdpr_policy" style="display:none"><input type="checkbox" name="gdpr_policy" class="contact_cgdpr" id="'.$this->id.'_gdpr_policy" checked><label for="'.$this->id.'_gdpr_policy">'.do_shortcode($gdpr_policy_field).'</label></p>';
  127. }
  128. echo '<p><input id="'.$this->id.'_submit" onclick="optimizerContact(this.id)" type="button" class="contact_button" name ="send" value ="'.__('Send', 'optimizer').'"></p>';
  129.  
  130. echo '</form></div>';
  131.  
  132. }
  133.  
  134. if ( !empty($contactform) ){
  135. $minheight = 'min-height:500px;';
  136. }else{$minheight = '';}
  137. if ( $locations ){
  138. if ( $locations ){$height = 'height:'.$height.';'; }else{ $height =''; }
  139. echo '<div id="asthemap-'.$var.'" style="'.$height. $minheight.'" class="asthemap"></div>';
  140. }
  141.  
  142. echo '</div>'; //contact_map_wrap ENDS
  143.  
  144. echo '</div></div>';
  145.  
  146. ?>
  147.  
  148.  
  149. <?php if (!empty ($locations) && is_customize_preview() ){ ?>
  150. <script>
  151. if (document.getElementById("asthemap-<?php echo $var; ?>")) {
  152. <?php $vars = str_replace('-','_',$var); ?>
  153.  
  154. function initialize_<?php echo $vars; ?>() {
  155.  
  156. var locations_<?php echo $vars; ?> = [
  157. <?php foreach ((array)$locations as $location){ ?>
  158. ['<?php $description = preg_replace("/\r\n|\r|\n/",'<br/>',$location['description']); $description = addslashes($description); echo do_shortcode($description); ?>', <?php echo $location['latlong']; ?>],
  159. <?php } ?>
  160. ];
  161.  
  162.  
  163. window.map_<?php echo $vars; ?> = new google.maps.Map(document.getElementById("asthemap-<?php echo $var; ?>"), {
  164. mapTypeId: google.maps.MapTypeId.ROADMAP,
  165. scrollwheel: false,
  166. <?php if($style !== 'map_default') { ?>
  167. styles: <?php echo $style; ?>
  168. <?php } ?>
  169. });
  170.  
  171. var infowindow = new google.maps.InfoWindow();
  172.  
  173. var bounds = new google.maps.LatLngBounds();
  174.  
  175. for (i = 0; i < locations_<?php echo $vars; ?>.length; i++) {
  176. marker = new google.maps.Marker({
  177. position: new google.maps.LatLng(locations_<?php echo $vars; ?>[i][1], locations_<?php echo $vars; ?>[i][2]),
  178. map: map_<?php echo $vars; ?>
  179. });
  180.  
  181. bounds.extend(marker.position);
  182.  
  183. google.maps.event.addListener(marker, 'click', (function (marker, i) {
  184. return function () {
  185. infowindow.setContent(locations_<?php echo $vars; ?>[i][0]);
  186. infowindow.open(map_<?php echo $vars; ?>, marker);
  187. }
  188. })(marker, i));
  189. }
  190.  
  191. map_<?php echo $vars; ?>.fitBounds(bounds);
  192.  
  193. var listener = google.maps.event.addListener(map_<?php echo $vars; ?>, "idle", function () {
  194. map_<?php echo $vars; ?>.setZoom(<?php echo $zoom; ?>);
  195. google.maps.event.removeListener(listener);
  196. });
  197. }
  198.  
  199. google.maps.event.addDomListener(window, 'load', initialize_<?php echo $vars; ?>);
  200. jQuery(document).ajaxStop(initialize_<?php echo $vars; ?>)
  201. }
  202. </script>
  203. <?php } ?>
  204.  
  205. <?php
  206.  
  207. //Stylesheet-loaded in Customizer Only.
  208. if(is_customize_preview()){
  209. $id= $this->id;
  210. $content_bg = 'background-color:#ffffff;';
  211. $title_color = '#333333;';
  212.  
  213. $marginTop =''; $marginBottom =''; $marginLeft =''; $marginRight ='';$calcWidth ='';
  214. $paddingTop =''; $paddingBottom =''; $paddingLeft =''; $paddingRight =''; $boxSizing='';
  215.  
  216. //Margin
  217. if ( ! empty( $instance['margin'] ) ) {
  218. if(!empty($instance['margin'][0])){ $marginTop ='margin-top:'.$instance['margin'][0].';';}
  219. if(!empty($instance['margin'][1])){ $marginBottom ='margin-bottom:'.$instance['margin'][1].';';}
  220. if(!empty($instance['margin'][2])){ $marginLeft ='margin-left:'.$instance['margin'][2].';';}
  221. if(!empty($instance['margin'][3])){ $marginRight ='margin-right:'.$instance['margin'][3].';';}
  222.  
  223. //Width
  224. $thewidth ='100';
  225. $leftrightmargin ='0px';
  226.  
  227. if ( ! empty( $instance['width']) ) {
  228. if($instance['width'] == 2){ $thewidth = '50';} if($instance['width'] == 3){ $thewidth = '33.33';} if($instance['width'] == 4){ $thewidth = '66.67';}
  229. if($instance['width'] == 5){ $thewidth = '25';} if($instance['width'] == 6){ $thewidth = '75';}
  230. }
  231. if ( ! empty( $instance['width']) && !empty($instance['margin'][2] ) ) { $leftrightmargin = $instance['margin'][2]; }
  232. if ( ! empty( $instance['width']) && !empty($instance['margin'][3] ) ) { $leftrightmargin = $instance['margin'][3]; }
  233.  
  234. if ( ! empty( $instance['width']) ) {
  235. if(!empty($instance['margin'][2]) && !empty($instance['margin'][3]) ){
  236. $leftrightmargin = '('.$instance['margin'][2].' + '.$instance['margin'][3].')';
  237. }
  238. }
  239. $calcWidth ='width: calc('.$thewidth.'% - '.$leftrightmargin.')!important;';
  240.  
  241. }
  242.  
  243. //Padding
  244. if ( ! empty( $instance['padding'] ) ) {
  245. if(!empty($instance['padding'][0])){ $paddingTop ='padding-top:'.$instance['padding'][0].';';}
  246. if(!empty($instance['padding'][1])){ $paddingBottom ='padding-bottom:'.$instance['padding'][1].';';}
  247. if(!empty($instance['padding'][2])){ $paddingLeft ='padding-left:'.$instance['padding'][2].';';}
  248. if(!empty($instance['padding'][3])){ $paddingRight ='padding-right:'.$instance['padding'][3].';';}
  249.  
  250. $boxSizing='box-sizing:border-box;';
  251.  
  252. }
  253.  
  254. if ( ! empty( $instance['content_bg'] ) ) { $content_bg = 'background-color: ' . $instance['content_bg'] . '; ';}
  255. if ( ! empty( $instance['content_bgimg'] ) ) { $content_bgimg = 'background-image: url(' . $instance['content_bgimg'] . ')!important; '; }
  256. if ( ! empty( $instance['title_color'] ) ) { $title_color = $instance['title_color'] . '; ';}
  257.  
  258. echo '<style>#'.$id.'{ ' . $content_bg . ''.$content_bgimg.'}#'.$id.' .home_title, #'.$id.' .home_subtitle, #'.$id.' span.div_middle{ color:' . $title_color . '}#'.$id.' span.div_left, #'.$id.' span.div_right{background-color:' . $title_color . '} @media screen and (min-width: 480px){#'.$id.' {'.$marginTop.$marginBottom.$marginLeft.$marginRight.$calcWidth. $paddingTop.$paddingBottom.$paddingLeft.$paddingRight. $boxSizing.'} }</style>';
  259.  
  260. }
  261.  
  262. /* After widget (defined by themes). */
  263. echo $after_widget;
  264.  
  265. }
  266.  
  267.  
  268. /* ---------------------------- */
  269. /* ------- Update Widget -------- */
  270. /* ---------------------------- */
  271.  
  272. function update( $new_instance, $old_instance ) {
  273. $instance = $old_instance;
  274.  
  275. /* Strip tags for title and name to remove HTML (important for text inputs). */
  276. $instance['title'] = strip_tags( $new_instance['title'] );
  277.  
  278. /* No need to strip tags */
  279. $instance['subtitle'] = wp_kses_post( $new_instance['subtitle']);
  280. $instance['contactform'] = strip_tags( $new_instance['contactform']);
  281. $instance['contactfield1'] = strip_tags( $new_instance['contactfield1']);
  282. $instance['contactstyle'] = strip_tags( $new_instance['contactstyle']);
  283. $instance['contactalign'] = strip_tags( $new_instance['contactalign']);
  284. $instance['gdpr_policy'] = $new_instance['gdpr_policy'];
  285. $instance['height'] = strip_tags( $new_instance['height']);
  286. $instance['divider'] = strip_tags($new_instance['divider']);
  287. $instance['title_color'] = optimizer_sanitize_hex($new_instance['title_color']);
  288. $instance['content_bg'] = optimizer_sanitize_hex($new_instance['content_bg']);
  289. $instance['content_bgimg'] = esc_url_raw($new_instance['content_bgimg']);
  290. $instance['style'] = strip_tags( $new_instance['style']);
  291. $instance['zoom'] = absint( $new_instance['zoom']);
  292.  
  293. $instance['locations'] = array();
  294.  
  295. if ( isset( $new_instance['locations'] ) )
  296. {
  297. foreach ( $new_instance['locations'] as $location )
  298. {
  299. if ( '' !== trim( $location['latlong'] ) )
  300. $instance['locations'][] = $location;
  301. }
  302. }
  303.  
  304. return $instance;
  305. }
  306.  
  307. /* ---------------------------- */
  308. /* ------- Widget Settings ------- */
  309. /* ---------------------------- */
  310.  
  311. /**
  312. * Displays the widget settings controls on the widget panel.
  313. * Make use of the get_field_id() and get_field_name() function
  314. * when creating your form elements. This handles the confusing stuff.
  315. */
  316.  
  317. function form( $instance ) {
  318.  
  319. /* Set up some default widget settings. */
  320. $defaults = array(
  321. 'title' => __('OUR LOCATION','optimizer'),
  322. 'subtitle' => __('Come Have coffee with us','optimizer'),
  323. 'contactform' => '',
  324. 'contactfield1' => '',
  325. 'contactstyle' => 'style1',
  326. 'contactalign' => 'right',
  327. 'gdpr_policy' => __('I agree with this Site\'s Privacy Policy','optimizer'),
  328. 'locations' => array(),
  329. 'height' => '500px',
  330. 'divider' => 'fa-stop',
  331. 'title_color' => '#333333',
  332. 'content_bg' => '#ffffff',
  333. 'content_bgimg' => '',
  334. 'style' => 'map_default',
  335. 'zoom' => '2',
  336. );
  337. $instance = wp_parse_args( (array) $instance, $defaults ); ?>
  338.  
  339.  
  340. <!-- MAP TITLE Field -->
  341. <p>
  342. <label for="<?php echo $this->get_field_id( 'title' ); ?>"><?php _e('Title:', 'optimizer') ?></label>
  343. <input class="widefat" id="<?php echo $this->get_field_id( 'title' ); ?>" name="<?php echo $this->get_field_name( 'title' ); ?>" value="<?php echo htmlspecialchars($instance['title'], ENT_QUOTES, "UTF-8"); ?>" type="text" />
  344. </p>
  345.  
  346. <!-- MAP Subtitle Field -->
  347. <p>
  348. <label for="<?php echo $this->get_field_id( 'subtitle' ); ?>"><?php _e('Subtitle:', 'optimizer') ?></label>
  349. <input class="widefat" id="<?php echo $this->get_field_id( 'subtitle' ); ?>" name="<?php echo $this->get_field_name( 'subtitle' ); ?>" value="<?php echo esc_attr($instance['subtitle']); ?>" type="hidden" />
  350. <a href="javascript:WPEditorWidget.showEditor('<?php echo $this->get_field_id( 'subtitle' ); ?>');" class="button edit-content-button"><?php _e( 'Edit content', 'optimizer' ) ?></a>
  351. </p>
  352.  
  353.  
  354.  
  355. <!-- MAP TITLE DIVIDER Field -->
  356. <p>
  357. <label for="<?php echo $this->get_field_id( 'divider' ); ?>"><?php _e('Title Divider:', 'optimizer') ?></label>
  358. <select id="<?php echo $this->get_field_id( 'divider' ); ?>" name="<?php echo $this->get_field_name( 'divider' ); ?>" class="widefat">
  359. <option value="underline" <?php if ( 'underline' == $instance['divider'] ) echo 'selected="selected"'; ?>><?php _e('Underline', 'optimizer') ?></option>
  360. <option value="border-center" <?php if ( 'border-center' == $instance['divider'] ) echo 'selected="selected"'; ?>><?php _e('Bordered (Center)', 'optimizer') ?></option>
  361. <option value="border-left" <?php if ( 'border-left' == $instance['divider'] ) echo 'selected="selected"'; ?>><?php _e('Bordered (Left)', 'optimizer') ?></option>
  362. <option value="border-right" <?php if ( 'border-right' == $instance['divider'] ) echo 'selected="selected"'; ?>><?php _e('Bordered (Right)', 'optimizer') ?></option>
  363. <option value="fa-stop" <?php if ( 'fa-stop' == $instance['divider'] ) echo 'selected="selected"'; ?>><?php _e('Rhombus', 'optimizer') ?></option>
  364. <option value="fa-star" <?php if ( 'fa-star' == $instance['divider'] ) echo 'selected="selected"'; ?>><?php _e('Star', 'optimizer') ?></option>
  365. <option value="fa-times" <?php if ( 'fa-times' == $instance['divider'] ) echo 'selected="selected"'; ?>><?php _e('Cross', 'optimizer') ?></option>
  366. <option value="fa-bolt" <?php if ( 'fa-bolt' == $instance['divider'] ) echo 'selected="selected"'; ?>><?php _e('Bolt', 'optimizer') ?></option>
  367. <option value="fa-asterisk" <?php if ( 'fa-asterisk' == $instance['divider'] ) echo 'selected="selected"'; ?>><?php _e('Asterisk', 'optimizer') ?></option>
  368. <option value="fa-chevron-down" <?php if ( 'fa-chevron-down' == $instance['divider'] ) echo 'selected="selected"'; ?>><?php _e('Chevron', 'optimizer') ?></option>
  369. <option value="fa-heart" <?php if ( 'fa-heart' == $instance['divider'] ) echo 'selected="selected"'; ?>><?php _e('Heart', 'optimizer') ?></option>
  370. <option value="fa-plus" <?php if ( 'fa-plus' == $instance['divider'] ) echo 'selected="selected"'; ?>><?php _e('Plus', 'optimizer') ?></option>
  371. <option value="fa-bookmark" <?php if ( 'fa-bookmark' == $instance['divider'] ) echo 'selected="selected"'; ?>><?php _e('Bookmark', 'optimizer') ?></option>
  372. <option value="fa-circle-o" <?php if ( 'fa-circle-o' == $instance['divider'] ) echo 'selected="selected"'; ?>><?php _e('Circle', 'optimizer') ?></option>
  373. <option value="fa-th-large" <?php if ( 'fa-th-large' == $instance['divider'] ) echo 'selected="selected"'; ?>><?php _e('Blocks', 'optimizer') ?></option>
  374. <option value="fa-minus" <?php if ( 'fa-minus' == $instance['divider'] ) echo 'selected="selected"'; ?>><?php _e('Sides', 'optimizer') ?></option>
  375. <option value="fa-cog" <?php if ( 'fa-cog' == $instance['divider'] ) echo 'selected="selected"'; ?>><?php _e('Cog', 'optimizer') ?></option>
  376. <option value="fa-reorder" <?php if ( 'fa-reorder' == $instance['divider'] ) echo 'selected="selected"'; ?>><?php _e('Blinds', 'optimizer') ?></option>
  377. <option value="fa-diamond" <?php if ( 'fa-diamond' == $instance['divider'] ) echo 'selected="selected"'; ?>><?php _e('Diamond', 'optimizer') ?></option>
  378. <option value="fa-gg" <?php if ( 'fa-gg' == $instance['divider'] ) echo 'selected="selected"'; ?>><?php _e('Tetris', 'optimizer') ?></option>
  379. <option value="fa-houzz" <?php if ( 'fa-houzz' == $instance['divider'] ) echo 'selected="selected"'; ?>><?php _e('Digital', 'optimizer') ?></option>
  380. <option value="fa-rocket" <?php if ( 'fa-rocket' == $instance['divider'] ) echo 'selected="selected"'; ?>><?php _e('Rocket', 'optimizer') ?></option>
  381. <option value="no_divider" <?php if ( 'no_divider' == $instance['divider'] ) echo 'selected="selected"'; ?>><?php _e('Hide Divider', 'optimizer') ?></option>
  382. </select>
  383. </p>
  384.  
  385.  
  386. <a class="widget_contact_title widget_active_contact"><?php _e('Contact Form', 'optimizer') ?></a> <a class="widget_map_title"><?php _e('Map', 'optimizer') ?></a>
  387. <!-- Contact Form Field -->
  388. <p class="widget_contact_fields">
  389. <label for="<?php echo $this->get_field_id( 'contactform' ); ?>"><?php _e('Display Contact Form', 'optimizer') ?>
  390. </label>
  391. <input class="widefat" id="<?php echo $this->get_field_id( 'contactform' ); ?>" name="<?php echo $this->get_field_name( 'contactform' ); ?>" value="1" type="checkbox" <?php if ( '1' == $instance['contactform'] ) echo 'checked'; ?> /><br>
  392. <small><?php _e('Emails will be sent to your WordPress Admin Email Address.', 'optimizer') ?></small>
  393. </p>
  394.  
  395. <!-- Contact Form Additional Field -->
  396. <p class="widget_contact_fields">
  397. <label for="<?php echo $this->get_field_id( 'contactfield1' ); ?>"><?php _e('Contact Form Additional Field', 'optimizer') ?></label>
  398. <input class="widefat" id="<?php echo $this->get_field_id( 'contactfield1' ); ?>" name="<?php echo $this->get_field_name( 'contactfield1' ); ?>" value="<?php echo htmlspecialchars($instance['contactfield1'], ENT_QUOTES, "UTF-8"); ?>" type="text" placeholder="<?php _e('Field Name (e.g: Phone Number)','optimizer');?>" />
  399. </p>
  400.  
  401. <!-- Contact Form Style -->
  402. <p class="widget_contact_fields">
  403. <label for="<?php echo $this->get_field_id( 'contactstyle' ); ?>"><?php _e('Contact Form Style:', 'optimizer') ?></label>
  404. <select id="<?php echo $this->get_field_id( 'contactstyle' ); ?>" name="<?php echo $this->get_field_name( 'contactstyle' ); ?>" class="widefat">
  405. <option value="style1" <?php if ( 'style1' == $instance['contactstyle'] ) echo 'selected="selected"'; ?>><?php _e('Style 1', 'optimizer') ?></option>
  406. <option value="style2" <?php if ( 'style2' == $instance['contactstyle'] ) echo 'selected="selected"'; ?>><?php _e('Style 2', 'optimizer') ?></option>
  407. <option value="style3" <?php if ( 'style3' == $instance['contactstyle'] ) echo 'selected="selected"'; ?>><?php _e('Style 3', 'optimizer') ?></option>
  408. <option value="style4" <?php if ( 'style4' == $instance['contactstyle'] ) echo 'selected="selected"'; ?>><?php _e('Style 4', 'optimizer') ?></option>
  409. <option value="style5" <?php if ( 'style5' == $instance['contactstyle'] ) echo 'selected="selected"'; ?>><?php _e('Style 5', 'optimizer') ?></option>
  410.  
  411. </select>
  412. </p>
  413.  
  414.  
  415. <!-- Contact Form Style -->
  416. <p class="widget_contact_fields">
  417. <label for="<?php echo $this->get_field_id( 'contactalign' ); ?>"><?php _e('Contact Form Alignment:', 'optimizer') ?></label>
  418. <select id="<?php echo $this->get_field_id( 'contactalign' ); ?>" name="<?php echo $this->get_field_name( 'contactalign' ); ?>" class="widefat">
  419. <option value="left" <?php if ( 'left' == $instance['contactalign'] ) echo 'selected="selected"'; ?>><?php _e('Left', 'optimizer') ?></option>
  420. <option value="center" <?php if ( 'center' == $instance['contactalign']) echo 'selected="selected"'; ?>><?php _e('Center', 'optimizer') ?></option>
  421. <option value="right" <?php if ( 'right' == $instance['contactalign'] ) echo 'selected="selected"'; ?>><?php _e('Right', 'optimizer') ?></option>
  422. </select>
  423. </p>
  424.  
  425. <!-- Contact Form GDPR -->
  426. <p class="widget_contact_fields">
  427. <label for="<?php echo $this->get_field_id( 'gdpr_policy' ); ?>"><?php _e('GDPR Consent Checkbox', 'optimizer') ?></label>
  428. <input class="widefat" id="<?php echo $this->get_field_id( 'gdpr_policy' ); ?>" name="<?php echo $this->get_field_name( 'gdpr_policy' ); ?>" value="<?php echo htmlspecialchars($instance['gdpr_policy'], ENT_QUOTES, "UTF-8"); ?>" type="text" placeholder="<?php _e('I agree with this Site\'s Privacy Policy','optimizer');?>" /><br>
  429. <small><?php _e('Clear the field to hide the checkbox in the Contact Form', 'optimizer') ?></small>
  430. </p>
  431.  
  432. <!-- MAP Location Field -->
  433. <div class="widget_repeater widget_map_fields" data-widget-id="<?php echo $this->get_field_id( 'locations' ); ?>" data-widget-name="<?php echo $this->get_field_name( 'locations' ); ?>">
  434. <?php
  435. $locations = isset( $instance['locations'] ) ? $instance['locations'] : array();
  436. $location_num = count($locations);
  437. $locations[$location_num+1] = '';
  438. $locations_html = array();
  439. $location_counter = 0;
  440.  
  441. foreach ( $locations as $location )
  442. {
  443. if ( isset($location['title']) && isset($location['latlong']) )
  444. {
  445. $locations_html[] = sprintf(
  446. '<div class="widget_input_wrap"><span id="%9$s%2$s" class="repeat_handle" onclick="repeatOpen(this.id)">%3$s</span><input type="text" name="%1$s[%2$s][title]" value="%3$s" class="widefat sourc%2$s" placeholder="%6$s"><input type="text" name="%1$s[%2$s][latlong]" value="%4$s" class="widefat sourc%2$s" placeholder="%7$s"><textarea name="%1$s[%2$s][description]" class="widefat sourc%2$s" placeholder="%8$s">%5$s</textarea><span class="remove-field button button-primary button-large">Remove</span></div>',
  447. $this->get_field_name( 'locations' ),
  448. $location_counter,
  449. esc_attr( $location['title'] ),
  450. esc_attr( $location['latlong'] ),
  451. esc_attr( $location['description'] ),
  452. __('Location Title (Required)','optimizer'),
  453. __('Latitude , Longitude (Required)','optimizer'),
  454. __('Location Description','optimizer'),
  455. $this->get_field_id('add_field').'-repeat'
  456. );
  457. }
  458.  
  459. $location_counter += 1;
  460. }
  461.  
  462. echo '<h4>'.__('Locations','optimizer').'</h4>' . join( $locations_html );
  463.  
  464. ?>
  465.  
  466. <script type="text/javascript">
  467. var fieldnum = <?php echo json_encode( $location_counter-1 ) ?>;
  468. var count = fieldnum;
  469. function mapclickFunction(buttondid){
  470. //var count = fieldnum;
  471. var fieldname = jQuery('#'+buttondid).data('widget-fieldname');
  472. var fieldid = jQuery('#'+buttondid).data('widget-fieldid');
  473.  
  474. jQuery('#'+buttondid).prev().append("<div class='widget_input_wrap'><span id='"+buttondid+"-repeat"+(count+1)+"' class='repeat_handle' onclick='repeatOpen(this.id)'></span><input type='text' name='"+fieldname+"["+(count+1)+"][title]' value='<?php _e( 'Location Name (Required)', 'optimizer' ); ?>' class='widefat' placeholder='<?php _e( 'Location Title (Required)', 'optimizer' ); ?>'><input type='text' name='"+fieldname+"["+(count+1)+"][latlong]' value='53.359286 , -2.040904' class='widefat sourc"+(count+1)+"' placeholder='<?php _e( 'Latitude , Longitude (Required)', 'optimizer' ); ?>'><textarea name='"+fieldname+"["+(count+1)+"][description] class='widefat sourc"+(count+1)+"' placeholder='<?php _e( 'Location Description', 'optimizer' ); ?>'></textarea><span class='remove-field button button-primary button-large'>Remove</span></div>");
  475. count++;
  476.  
  477. }
  478.  
  479.  
  480. jQuery( document ).on( 'ready widget-added widget-updated', function () {
  481.  
  482. jQuery(document).on("click", ".remove-field", function(e) {
  483. jQuery(this).parent().remove();
  484. });
  485. });
  486.  
  487. </script>
  488.  
  489. <span id="<?php echo $this->get_field_id( 'field_clone' );?>" class="repeat_clone_field" data-empty-content="<?php _e('No Map Location Added', 'optimizer') ?>"></span>
  490.  
  491. <?php echo '<input onclick="mapclickFunction(this.id)" class="button button-primary button-large" type="button" value="' . __( '+ Add New', 'optimizer' ) . '" id="'.$this->get_field_id('add_field').'" data-widget-fieldname="'.$this->get_field_name('locations').'" data-widget-fieldid="'.$this->get_field_id('locations').'" />';?>
  492. </div>
  493.  
  494.  
  495. <!-- MAP Height Field -->
  496. <p class="widget_map_fields">
  497. <?php _e('If your Maps are not working you will have to <a href="https://optimizerwp.com/documentation/get-google-map-api-key/" target="_blank">Get a Map Api Key</a> and then insert the key in Customize > Miscellaneous > Other > Google Map Api Key.','optimizer');?>
  498. </p>
  499.  
  500. <!-- MAP Height Field -->
  501. <p class="widget_map_fields">
  502. <label for="<?php echo $this->get_field_id( 'height' ); ?>"><?php _e('Map Height:', 'optimizer') ?></label>
  503. <input class="widefat" id="<?php echo $this->get_field_id( 'height' ); ?>" name="<?php echo $this->get_field_name( 'height' ); ?>" value="<?php echo $instance['height']; ?>" type="text" />
  504. </p>
  505.  
  506.  
  507. <!-- MAP Content STYLE Field -->
  508. <p class="widget_map_fields">
  509. <label for="<?php echo $this->get_field_id( 'style' ); ?>"><?php _e('Map Style:', 'optimizer') ?></label>
  510. <select id="<?php echo $this->get_field_id( 'style' ); ?>" name="<?php echo $this->get_field_name( 'style' ); ?>" class="widefat">
  511. <option value="map_default" <?php if ( 'map_default' == $instance['style'] ) echo 'selected="selected"'; ?>><?php _e('Default', 'optimizer') ?></option>
  512. <option value="map_bluish" <?php if ( 'map_bluish' == $instance['style'] ) echo 'selected="selected"'; ?>><?php _e('Bluish', 'optimizer') ?></option>
  513. <option value="map_angel" <?php if ( 'map_angel' == $instance['style'] ) echo 'selected="selected"'; ?>><?php _e('Angel', 'optimizer') ?></option>
  514. <option value="map_pale" <?php if ( 'map_pale' == $instance['style'] ) echo 'selected="selected"'; ?>><?php _e('Pale', 'optimizer') ?></option>
  515. <option value="map_gowalla" <?php if ( 'map_gowalla' == $instance['style'] ) echo 'selected="selected"'; ?>><?php _e('Gowalla', 'optimizer') ?></option>
  516. <option value="map_pastel" <?php if ( 'map_pastel' == $instance['style'] ) echo 'selected="selected"'; ?>><?php _e('Pastel', 'optimizer') ?></option>
  517. <option value="map_old" <?php if ( 'map_old' == $instance['style'] ) echo 'selected="selected"'; ?>><?php _e('Old', 'optimizer') ?></option>
  518. <option value="map_light" <?php if ( 'map_light' == $instance['style'] ) echo 'selected="selected"'; ?>><?php _e('Light', 'optimizer') ?></option>
  519. <option value="map_dark" <?php if ( 'map_dark' == $instance['style'] ) echo 'selected="selected"'; ?>><?php _e('Dark', 'optimizer') ?></option>
  520. <option value="map_greyscale" <?php if ( 'map_greyscale' == $instance['style'] ) echo 'selected="selected"'; ?>><?php _e('Greyscale', 'optimizer') ?></option>
  521.  
  522. </select>
  523. </p>
  524.  
  525. <!-- Map Zoom Field -->
  526. <p class="widget_map_fields">
  527. <label for="<?php echo $this->get_field_id( 'zoom' ); ?>"><?php _e('Map Zoom', 'optimizer') ?></label>
  528. <input class="widefat" id="<?php echo $this->get_field_id( 'zoom' ); ?>" name="<?php echo $this->get_field_name( 'zoom' ); ?>" value="<?php echo $instance['zoom']; ?>" type="range" min="2" max="20" />
  529. </p>
  530.  
  531. <hr style="margin: 30px 0;">
  532.  
  533. <!-- Map Title Color Field -->
  534. <p>
  535. <label for="<?php echo $this->get_field_id( 'title_color' ); ?>"><?php _e('Title &amp; Subtitle Color', 'optimizer') ?></label>
  536. <input class="widefat color-picker" id="<?php echo $this->get_field_id( 'title_color' ); ?>" name="<?php echo $this->get_field_name( 'title_color' ); ?>" value="<?php echo $instance['title_color']; ?>" type="text" />
  537. </p>
  538.  
  539.  
  540. <!-- Map Background Color Field -->
  541. <p>
  542. <label for="<?php echo $this->get_field_id( 'content_bg' ); ?>"><?php _e('Background Color', 'optimizer') ?></label>
  543. <input class="widefat color-picker" id="<?php echo $this->get_field_id( 'content_bg' ); ?>" name="<?php echo $this->get_field_name( 'content_bg' ); ?>" value="<?php echo $instance['content_bg']; ?>" type="text" />
  544. </p>
  545.  
  546. <!-- MAP Background Image Field -->
  547. <p>
  548. <label for="<?php echo $this->get_field_id( 'content_bgimg' ); ?>"><?php _e('Background Image', 'optimizer') ?></label>
  549. <div class="media-picker-wrap">
  550. <?php if(!empty($instance['content_bgimg'])) { ?>
  551. <img style="max-width:100%; height:auto;" class="media-picker-preview" src="<?php echo esc_url($instance['content_bgimg']); ?>" />
  552. <i class="fa fa-times media-picker-remove"></i>
  553. <?php } ?>
  554. <input class="widefat media-picker" id="<?php echo $this->get_field_id( 'content_bgimg' ); ?>" name="<?php echo $this->get_field_name( 'content_bgimg' ); ?>" value="<?php echo esc_url($instance['content_bgimg']); ?>" type="hidden" />
  555. <a class="media-picker-button button" onclick="mediaPicker(this.id)" id="<?php echo $this->get_field_id( 'content_bgimg' ).'mpick'; ?>"><?php _e('Select Image', 'optimizer') ?></a>
  556. </div>
  557. </p>
  558.  
  559. <?php
  560. }
  561.  
  562. //Load the Map Styles
  563. function optimizer_map_styles() {
  564. $settings = $this->get_settings();
  565.  
  566. if ( empty( $settings ) ) {
  567. return;
  568. }
  569.  
  570. foreach ( $settings as $instance_id => $instance ) {
  571. $id = $this->id_base . '-' . $instance_id;
  572. if(!is_customize_preview()){
  573. if ( ! is_active_widget( false, $id, $this->id_base ) ) {
  574. continue;
  575. }
  576. if ( ! empty( $instance['locations'] ) ) {
  577. global $optimizer;
  578. if(!empty($optimizer['map_api'])){ $mapkey = 'https://maps.googleapis.com/maps/api/js?key='.$optimizer['map_api'].''; }else{ $mapkey = 'https://maps.googleapis.com/maps/api/js?sensor=false';}
  579. wp_enqueue_script('optimizer_map',get_template_directory_uri().'/assets/js/map-styles.js', array('jquery'),'1.0', true);
  580. wp_enqueue_script('optimizer_googlemaps', $mapkey, array('jquery'),'1.0', true);
  581. }
  582.  
  583. }
  584. }
  585. }
  586.  
  587.  
  588.  
  589.  
  590. function optimizer_map_run(){
  591. $settings = get_option($this->option_name);
  592. if(!is_customize_preview()){
  593. if ( empty( $settings ) ) {
  594. return;
  595. }
  596.  
  597.  
  598. foreach ( $settings as $instance_id => $instance ) {
  599. $id = $this->id_base . '-' . $instance_id;
  600.  
  601. if ( ! is_active_widget( false, $id, $this->id_base ) ) {
  602. continue;
  603. }
  604. $idbase = str_replace('-','_',$id);
  605. if ( ! empty( $instance['locations'] ) ) {$locations = $instance['locations']; }else{$locations = '';}
  606. if ( ! empty( $instance['style'] ) ) {$style = $instance['style']; }else{$style = '';}
  607. if ( ! empty( $instance['zoom'] ) ) {$zoom = $instance['zoom']; }else{$zoom = '';}
  608. $var = $id;
  609.  
  610. if (!empty ($locations)){ ?>
  611. <script>
  612. if (document.getElementById("asthemap-<?php echo $var; ?>")) {
  613. <?php $vars = str_replace('-','_',$var); ?>
  614.  
  615. function initialize_<?php echo $vars; ?>() {
  616.  
  617. var locations_<?php echo $vars; ?> = [
  618. <?php foreach ((array)$locations as $location){ ?>
  619. ['<?php $description = preg_replace("/\r\n|\r|\n/",'<br/>',$location['description']); $description = addslashes($description); echo do_shortcode($description); ?>', <?php echo $location['latlong']; ?>],
  620. <?php } ?>
  621. ];
  622.  
  623.  
  624. window.map_<?php echo $vars; ?> = new google.maps.Map(document.getElementById("asthemap-<?php echo $var; ?>"), {
  625. mapTypeId: google.maps.MapTypeId.ROADMAP,
  626. scrollwheel: false,
  627. <?php if($style !== 'map_default') { ?>
  628. styles: <?php echo $style; ?>
  629. <?php } ?>
  630. });
  631.  
  632. var infowindow = new google.maps.InfoWindow();
  633.  
  634. var bounds = new google.maps.LatLngBounds();
  635.  
  636. for (i = 0; i < locations_<?php echo $vars; ?>.length; i++) {
  637. marker = new google.maps.Marker({
  638. position: new google.maps.LatLng(locations_<?php echo $vars; ?>[i][1], locations_<?php echo $vars; ?>[i][2]),
  639. map: map_<?php echo $vars; ?>
  640. });
  641.  
  642. bounds.extend(marker.position);
  643.  
  644. google.maps.event.addListener(marker, 'click', (function (marker, i) {
  645. return function () {
  646. infowindow.setContent(locations_<?php echo $vars; ?>[i][0]);
  647. infowindow.open(map_<?php echo $vars; ?>, marker);
  648. }
  649. })(marker, i));
  650. }
  651.  
  652. var center;
  653. function calculateCenter() {
  654. center = map_<?php echo $vars; ?>.getCenter();
  655. }
  656.  
  657. map_<?php echo $vars; ?>.fitBounds(bounds);
  658.  
  659. var listener = google.maps.event.addListener(map_<?php echo $vars; ?>, "idle", function () {
  660. map_<?php echo $vars; ?>.setZoom(<?php echo $zoom; ?>);
  661. google.maps.event.removeListener(listener);
  662. calculateCenter();
  663. });
  664.  
  665. google.maps.event.addDomListener(window, 'resize', function() {
  666. map_<?php echo $vars; ?>.setCenter(center);
  667. });
  668. }
  669.  
  670.  
  671. google.maps.event.addDomListener(window, 'load', initialize_<?php echo $vars; ?>);
  672. jQuery(document).ajaxStop(initialize_<?php echo $vars; ?>)
  673. }
  674. </script>
  675. <?php }
  676. }
  677. }
  678. }
  679.  
  680.  
  681. //ENQUEUE CSS
  682. function front_map_enqueue_css() {
  683. $settings = $this->get_settings();
  684.  
  685. if ( empty( $settings ) ) {
  686. return;
  687. }
  688.  
  689. foreach ( $settings as $instance_id => $instance ) {
  690. $id = $this->id_base . '-' . $instance_id;
  691. if(!is_customize_preview()){
  692. if ( ! is_active_widget( false, $id, $this->id_base ) ) {
  693. continue;
  694. }
  695.  
  696. $content_bg = 'background-color:#ffffff;';
  697. $title_color = '#333333;';
  698. $content_bgimg = '';
  699. $marginTop =''; $marginBottom =''; $marginLeft =''; $marginRight ='';$calcWidth ='';
  700. $paddingTop =''; $paddingBottom =''; $paddingLeft =''; $paddingRight =''; $boxSizing='';
  701.  
  702. //Margin
  703. if ( ! empty( $instance['margin'] ) ) {
  704. if(!empty($instance['margin'][0])){ $marginTop ='margin-top:'.$instance['margin'][0].';';}
  705. if(!empty($instance['margin'][1])){ $marginBottom ='margin-bottom:'.$instance['margin'][1].';';}
  706. if(!empty($instance['margin'][2])){ $marginLeft ='margin-left:'.$instance['margin'][2].';';}
  707. if(!empty($instance['margin'][3])){ $marginRight ='margin-right:'.$instance['margin'][3].';';}
  708.  
  709. //Width
  710. $thewidth ='100';
  711. $leftrightmargin ='0px';
  712.  
  713. if ( ! empty( $instance['width']) ) {
  714. if($instance['width'] == 2){ $thewidth = '50';} if($instance['width'] == 3){ $thewidth = '33.33';} if($instance['width'] == 4){ $thewidth = '66.67';}
  715. if($instance['width'] == 5){ $thewidth = '25';} if($instance['width'] == 6){ $thewidth = '75';}
  716. }
  717. if ( ! empty( $instance['width']) && !empty($instance['margin'][2] ) ) { $leftrightmargin = $instance['margin'][2]; }
  718. if ( ! empty( $instance['width']) && !empty($instance['margin'][3] ) ) { $leftrightmargin = $instance['margin'][3]; }
  719.  
  720. if ( ! empty( $instance['width']) ) {
  721. if(!empty($instance['margin'][2]) && !empty($instance['margin'][3]) ){
  722. $leftrightmargin = '('.$instance['margin'][2].' + '.$instance['margin'][3].')';
  723. }
  724. }
  725. $calcWidth ='width: calc('.$thewidth.'% - '.$leftrightmargin.')!important;';
  726.  
  727. }
  728.  
  729. //Padding
  730. if ( ! empty( $instance['padding'] ) ) {
  731. if(!empty($instance['padding'][0])){ $paddingTop ='padding-top:'.$instance['padding'][0].';';}
  732. if(!empty($instance['padding'][1])){ $paddingBottom ='padding-bottom:'.$instance['padding'][1].';';}
  733. if(!empty($instance['padding'][2])){ $paddingLeft ='padding-left:'.$instance['padding'][2].';';}
  734. if(!empty($instance['padding'][3])){ $paddingRight ='padding-right:'.$instance['padding'][3].';';}
  735.  
  736. $boxSizing='box-sizing:border-box;';
  737.  
  738. }
  739.  
  740.  
  741. if ( ! empty( $instance['content_bg'] ) ) { $content_bg = 'background-color: ' . $instance['content_bg'] . '; ';}
  742. if ( ! empty( $instance['content_bgimg'] ) ) { $content_bgimg = 'background-image: url(' . $instance['content_bgimg'] . ')!important; '; }
  743. if ( ! empty( $instance['title_color'] ) ) { $title_color = $instance['title_color'] . '; ';}
  744.  
  745. $widget_style = '#'.$id.'{ ' . $content_bg . ''.$content_bgimg.'}#'.$id.' .home_title, #'.$id.' .home_subtitle, #'.$id.' span.div_middle{ color:' . $title_color . '}#'.$id.' span.div_left, #'.$id.' span.div_right{background-color:' . $title_color . '} @media screen and (min-width: 480px){#'.$id.' {'.$marginTop.$marginBottom.$marginLeft.$marginRight.$calcWidth. $paddingTop.$paddingBottom.$paddingLeft.$paddingRight. $boxSizing.'} }';
  746. wp_add_inline_style( 'optimizer-style', $widget_style );
  747.  
  748. }
  749. }
  750. }
  751. }
  752. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement