Completed
Push — master ( 77ce4a...d7b2b7 )
by Devin
39:25 queued 19:28
created

Google_Maps_Builder_Admin::admin_body_classes()   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 11
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 3
eloc 5
c 1
b 0
f 1
nc 2
nop 1
dl 0
loc 11
rs 9.4285
1
<?php
2
/**
3
 * Google Maps Admin
4
 *
5
 * The admin is considered the single post view where you build maps
6
 *
7
 * @package   Google_Maps_Builder_Admin
8
 * @author    Devin Walker <[email protected]>
9
 * @license   GPL-2.0+
10
 * @link      http://wordimpress.com
11
 * @copyright 2016 WordImpress, Devin Walker
12
 */
13
14
/**
15
 * Class Google_Maps_Builder_Admin
16
 */
17
class Google_Maps_Builder_Admin extends Google_Maps_Builder_Core_Admin {
18
19
	/**
20
	 * Instance of this class.
21
	 *
22
	 * @since    1.0.0
23
	 *
24
	 * @var      object
25
	 */
26
	protected static $instance = null;
27
28
	/**
29
	 * Initialize the plugin by loading admin scripts & styles and adding a
30
	 * settings page and menu.
31
	 *
32
	 * @since     1.0.0
33
	 */
34
	public function __construct() {
35
36
		parent::__construct();
37
38
		add_action( 'cmb2_render_google_maps_preview', array( $this, 'cmb2_render_google_maps_preview' ), 10, 2 );
39
		// Load admin style sheet and JavaScript.
40
		add_action( 'wp_ajax_hide_welcome', array( $this, 'hide_welcome_callback' ) );
41
42
		//Add links/information to plugin row meta
43
		add_filter( 'cmb2_get_metabox_form_format', array( $this, 'gmb_modify_cmb2_form_output' ), 10, 3 );
44
45
		//Widget upsell
46
		add_action( 'gmb_after_widget_form', array( $this, 'widget_upsell' ) );
47
48
		//Useful class for free-only styling
49
		add_filter( 'admin_body_class', array( $this, 'admin_body_classes' ) );
50
51
	}
52
53
	/**
54
	 *  Custom Google Geocoder field
55
	 *
56
	 * @since  1.0.0
57
	 */
58
	function cmb2_render_google_maps_preview( $field, $meta ) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
59
60
		/* @var $post */
61
		global $post;
0 ignored issues
show
Compatibility Best Practice introduced by
Use of global functionality is not recommended; it makes your code harder to test, and less reusable.

Instead of relying on global state, we recommend one of these alternatives:

1. Pass all data via parameters

function myFunction($a, $b) {
    // Do something
}

2. Create a class that maintains your state

class MyClass {
    private $a;
    private $b;

    public function __construct($a, $b) {
        $this->a = $a;
        $this->b = $b;
    }

    public function myFunction() {
        // Do something
    }
}
Loading history...
62
63
		$meta            = wp_parse_args( $meta, array() );
64
		$wh_value        = get_post_meta( $post->ID, 'gmb_width_height', true );
65
		$lat_lng         = get_post_meta( $post->ID, 'gmb_lat_lng', true );
66
		$default_options = $this->get_default_map_options();
67
68
		$output = '<div class="places-loading wpgp-loading">' . __( 'Loading Places', $this->plugin_slug ) . '</div><div id="google-map-wrap">';
69
		$output .= '<div id="map" style="height:600px; width:100%;"></div>';
70
71
		$output .= '<div class="map-modal-upsell"><p class="upsell-intro">' . __( 'Want more?', $this->plugin_slug ) . '</p><a href="https://wordimpress.com/plugins/maps-builder-pro?utm_source=MBF&utm_medium=BANNER&utm_content=MODAL&utm_campaign=MBF%20Modal" class="button button-small upsell-button" target="_blank">' . __( 'Go Pro!', $this->plugin_slug ) . '</a></div>';
72
73
		//Toolbar
74
		$output .= '<div id="map-toolbar">';
75
		$output .= '<button class="add-location button button-small gmb-magnific-inline" data-target="cmb2-id-gmb-geocoder" data-auto-focus="true"><span class="dashicons dashicons-pressthis"></span>' . __( 'Add Location', $this->plugin_slug ) . '</button>';
76
		$output .= '<button class="drop-marker button button-small"><span class="dashicons dashicons-location"></span>' . __( 'Drop a Marker', $this->plugin_slug ) . '</button>';
77
		$output .= '<button class="goto-location button button-small gmb-magnific-inline" data-target="map-autocomplete-wrap" data-auto-focus="true"><span class="dashicons dashicons-admin-site"></span>' . __( 'Goto Location', $this->plugin_slug ) . '</button>';
78
		$output .= '<button class="edit-title button  button-small gmb-magnific-inline" data-target="map-title-wrap" data-auto-focus="true"><span class="dashicons dashicons-edit"></span>' . __( 'Edit Map Title', $this->plugin_slug ) . '</button>';
79
80
		$output .= '<div class="live-lat-lng-wrap clearfix">';
81
		$output .= '<button disabled class="update-lat-lng button button-small">' . __( 'Set Lat/Lng', $this->plugin_slug ) . '</button>';
82
		$output .= '<div class="live-latitude-wrap"><span class="live-latitude-label">' . __( 'Lat:', $this->plugin_slug ) . '</span><span class="live-latitude">' . ( isset( $lat_lng['latitude'] ) ? $lat_lng['latitude'] : '' ) . '</span></div>';
83
		$output .= '<div class="live-longitude-wrap"><span class="live-longitude-label">' . __( 'Lng:', $this->plugin_slug ) . '</span><span class="live-longitude">' . ( isset( $lat_lng['longitude'] ) ? $lat_lng['longitude'] : '' ) . '</span></div>';
84
		$output .= '</div>'; //End .live-lat-lng-wrap
85
		$output .= '</div>'; //End #map-toolbar
86
		$output .= '</div>'; //End #map
87
88
89
		//@TODO: Obviously Need Wrapper function
90
		$output .= '<div class="white-popup mfp-hide map-title-wrap">';
91
		$output .= '<div class="inner-modal-wrap">';
92
		$output .= '<div class="inner-modal-container">';
93
		$output .= '<div class="inner-modal clearfix">';
94
		$output .= '<label for="post_title" class="map-title">' . __( 'Map Title', $this->plugin_slug ) . '</label>';
95
		$output .= '<p class="cmb2-metabox-description">' . __( 'Give your Map a descriptive title', $this->plugin_slug ) . '</p>';
96
		$output .= '<button type="button" class="gmb-modal-close">&times;</button><input type="text" name="model_post_title" size="30" value="' . get_the_title() . '" id="modal_title" spellcheck="true" autocomplete="off" placeholder="' . __( 'Enter map title', $this->plugin_slug ) . '">';
97
		$output .= '</div>';
98
		$output .= '</div>';
99
		$output .= '</div>';
100
		$output .= '</div>';
101
102
		$output .= '<div class="white-popup mfp-hide map-autocomplete-wrap">';
103
		$output .= '<div class="inner-modal-wrap">';
104
		$output .= '<div class="inner-modal-container">';
105
		$output .= '<div class="inner-modal clearfix">';
106
		$output .= '<label for="map-location-autocomplete" class="map-title">' . __( 'Enter a Location', $this->plugin_slug ) . '</label>';
107
		$output .= '<p class="cmb2-metabox-description">' . __( 'Type your point of interest below and the map will be re-centered over that location', $this->plugin_slug ) . '</p>';
108
		$output .= '<button type="button" class="gmb-modal-close">&times;</button>';
109
		$output .= '<input type="text" name="" size="30" id="map-location-autocomplete">';
110
		$output .= '</div>';
111
		$output .= '</div>';
112
		$output .= '</div>';
113
		$output .= '</div>';
114
115
		$output .= '<div class="warning-message wpgp-message"></div>';
116
117
		//Markers Modal
118
		gmb_include_view( 'admin/views/markers.php', false, $this->view_data() );
119
120
		echo apply_filters( 'google_maps_preview', $output );
121
122
	}
123
124
	/**
125
	 * Modify CMB2 Default Form Output
126
	 *
127
	 * @param string @args
128
	 *
129
	 * @since 2.0
130
	 *
131
	 * @param $form_format
132
	 * @param $object_id
133
	 * @param $cmb
134
	 *
135
	 * @return string
136
	 */
137
	function gmb_modify_cmb2_form_output( $form_format, $object_id, $cmb ) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
138
139
		//only modify the give settings form
140
		if ( 'gmb_settings' == $object_id && 'plugin_options' == $cmb->cmb_id ) {
141
142
			return '<form class="cmb-form" method="post" id="%1$s" enctype="multipart/form-data" encoding="multipart/form-data"><input type="hidden" name="object_id" value="%2$s">%3$s<div class="gmb-submit-wrap"><input type="submit" name="submit-cmb" value="' . __( 'Save Settings', 'give' ) . '" class="button-primary"></div></form>';
143
		}
144
145
		return $form_format;
146
147
	}
148
149
150
	/**
151
	 * Add upsell to the widget form
152
	 *
153
	 * @since 2.1.0
154
	 *
155
	 * @uses "gmb_after_widget_form" action
156
	 */
157
	public function widget_upsell() {
158
		?>
159
		<div class="gmb-widget-upgrade clear">
160
			<span class="powered-by"></span>
161
			<a href="https://wordimpress.com/plugins/maps-builder-pro?utm_source=MBF&utm_medium=BANNER&utm_content=WIDGET&utm_campaign=MBF%20Widgets" target="_blank" class="button button-small">
162
				<?php _e( 'Upgrade to Pro', $this->plugin_slug ); ?>
163
				<span class="new-window"></span>
164
			</a>
165
		</div>
166
		<?php
167
168
	}
169
170
171
	/**
172
	 * Adds a Free
173
	 *
174
	 * @param  String $classes Current body classes.
175
	 *
176
	 * @return String          Altered body classes.
177
	 */
178
	function admin_body_classes( $classes ) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
179
180
		global $post;
0 ignored issues
show
Compatibility Best Practice introduced by
Use of global functionality is not recommended; it makes your code harder to test, and less reusable.

Instead of relying on global state, we recommend one of these alternatives:

1. Pass all data via parameters

function myFunction($a, $b) {
    // Do something
}

2. Create a class that maintains your state

class MyClass {
    private $a;
    private $b;

    public function __construct($a, $b) {
        $this->a = $a;
        $this->b = $b;
    }

    public function myFunction() {
        // Do something
    }
}
Loading history...
181
182
		if ( isset( $post->post_type ) && $post->post_type == 'google_maps' ) {
183
			$classes .= 'maps-builder-free';
184
		}
185
186
		return $classes;
187
188
	}
189
190
191
} //end class
192