*/
class Andreadb_Google_Maps_Admin {
/**
* The ID of this plugin.
*
* @since 1.0.0
* @access private
* @var string $plugin_name The ID of this plugin.
*/
private $plugin_name;
/**
* The version of this plugin.
*
* @since 1.0.0
* @access private
* @var string $version The current version of this plugin.
*/
private $version;
/**
* Initialize the class and set its properties.
*
* @since 1.0.0
* @param string $plugin_name The name of this plugin.
* @param string $version The version of this plugin.
*/
public function __construct($plugin_name, $version) {
$this->plugin_name = $plugin_name;
$this->version = $version;
}
/**
* Register the stylesheets for the admin area.
*
* @since 1.0.0
*/
public function dba_google_maps_enqueue_styles() {
/**
* This function is provided for demonstration purposes only.
*
* An instance of this class should be passed to the run() function
* defined in Andreadb_Google_Maps_Loader as all of the hooks are defined
* in that particular class.
*
* The Andreadb_Google_Maps_Loader will then create the relationship
* between the defined hooks and the functions defined in this
* class.
*/
wp_enqueue_style($this->plugin_name, plugin_dir_url(__FILE__) . 'css/andreadb-google-maps-admin.css', array(), null, 'all');
}
/**
* Register the JavaScript for the admin area.
*
* @since 1.0.0
*/
public function dba_google_maps_enqueue_scripts() {
/**
* This function is provided for demonstration purposes only.
*
* An instance of this class should be passed to the run() function
* defined in Andreadb_Google_Maps_Loader as all of the hooks are defined
* in that particular class.
*
* The Andreadb_Google_Maps_Loader will then create the relationship
* between the defined hooks and the functions defined in this
* class.
*/
wp_enqueue_media();
wp_enqueue_script($this->plugin_name, plugin_dir_url(__FILE__) . 'js/andreadb-google-maps-admin.js', array('jquery'), null, false);
wp_localize_script($this->plugin_name, 'andreadb_google_maps', array(
'url' => __('URL', 'andreadb-google-maps'),
'confirm' => __('Are you sure?', 'andreadb-google-maps'),
'ajaxurl' => admin_url('admin-ajax.php'),
'addmarker_nonce' => wp_create_nonce('dba_google_maps_addmarker'),
'iframeurl' => admin_url('admin-ajax.php?action=dba_google_maps_preview')
)
);
}
/**
* Register dba_google_maps post type.
*
* @since 1.0.0
* @access public
* @uses register_post_type()
*/
public static function register_dba_google_maps_post_type() {
$labels = array(
'name' => __('Google Maps', 'andreadb-google-maps'),
'singular_name' => __('Google Maps', 'andreadb-google-maps'),
'menu_name' => _x('Google Maps', 'Admin menu name', 'andreadb-google-maps'),
'name_admin_bar' => _x('Google Maps', 'add new on admin bar', 'andreadb-google-maps'),
'add_new' => __('Add Google Maps', 'andreadb-google-maps'),
'add_new_item' => __('Add New Google Maps', 'andreadb-google-maps'),
'new_item' => __('New Google Maps', 'andreadb-google-maps'),
'edit_item' => __('Edit Google Maps', 'andreadb-google-maps'),
'view_item' => __('View Google Maps', 'andreadb-google-maps'),
'all_items' => __('Google Maps', 'andreadb-google-maps'),
'search_items' => __('Search Google Maps', 'andreadb-google-maps'),
'not_found' => __('No Google Maps found', 'andreadb-google-maps'),
'not_found_in_trash' => __('No Google Maps found in trash', 'andreadb-google-maps')
);
$args = array(
'labels' => $labels,
'description' => __('Description.', 'andreadb-google-maps'),
'public' => true,
'publicly_queryable' => false,
'show_ui' => true,
'show_in_menu' => true,
'query_var' => false,
'rewrite' => false,
'exclude_from_search' => true,
'menu_position' => 100,
'menu_icon' => 'dashicons-location',
'supports' => array(
'title',
'thumbnail'
),
);
register_post_type('dba_google_maps', $args);
}
/**
* Add columns in dba_google_maps.
*
* @since 1.0.0
* @param mixed $columns
* @return array
*/
public function dba_google_maps_columns($columns) {
unset($columns['title'], $columns['date']);
$columns['dba-google-maps-id'] = __('ID', 'andreadb-google-maps');
$columns['title'] = __('Title', 'andreadb-google-maps');
$columns['dba-google-maps-address'] = __('Address', 'andreadb-google-maps');
$columns['dba-google-maps-shortcode'] = __('Shortcode', 'andreadb-google-maps');
$columns['date'] = __('Date', 'andreadb-google-maps');
return $columns;
}
/**
* Column value added to dba_google_maps.
*
* @since 1.0.0
* @param string $column
*/
public function dba_google_maps_column($column) {
global $post;
$post_id = $post->ID;
$google_maps_markers = get_post_meta($post_id, 'dba_google_maps_markers', true);
switch ($column) {
case 'dba-google-maps-id' :
echo $post_id;
break;
case 'dba-google-maps-address' :
foreach ($google_maps_markers as $marker) {
echo "
" . $marker["address"] . "
";
}
break;
case 'dba-google-maps-shortcode' :
echo '';
break;
}
}
/**
* Add preview action row.
*
* @since 1.0.0
* @param $actions $post
*/
public function dba_google_maps_action_row($actions, $post) {
if ($post->post_type == "dba_google_maps") {
$preview_button = __('Preview', 'andreadb-google-maps');
array_splice($actions, 2, 0, '' . $preview_button . '');
}
return $actions;
}
/**
* Add metaboxes Google Maps.
*
* @since 1.0.0
* @access public
*/
public function add_meta_boxes_dba_google_maps() {
// add_meta_box( $id, $title, $callback, $screen, $context, $priority, $callback_args );
add_meta_box(
'dba_google_maps_general', __('General', 'andreadb-google-maps'), array($this, 'render_dba_google_maps_general'), 'dba_google_maps', 'normal', 'high'
);
add_meta_box(
'dba_google_maps_markers', __('Markers', 'andreadb-google-maps'), array($this, 'render_dba_google_maps_markers'), 'dba_google_maps', 'normal', 'default'
);
add_meta_box(
'dba_google_maps_controls', __('Controls', 'andreadb-google-maps'), array($this, 'render_dba_google_maps_controls'), 'dba_google_maps', 'normal', 'default'
);
add_meta_box(
'dba_google_maps_shortcodes', __('Shortcodes', 'andreadb-google-maps'), array($this, 'render_dba_google_maps_shortcodes'), 'dba_google_maps', 'side', 'low'
);
remove_meta_box('postimagediv', 'dba_google_maps', 'side');
}
/**
* Render google maps shortcodes
*
* @since 1.0.0
* @access public
* @param $post
*/
public function render_dba_google_maps_shortcodes($post) {
$status = get_post_status($post->ID);
$shortcode = $shortcodephp = '';
if ($status == 'publish') {
$shortcode = '[andreadb_google_maps id="' . $post->ID . '"]';
$shortcodephp = '<?php
echo do_shortcode("[andreadb_google_maps id="' . $post->ID . '"]");
?>';
}
include( plugin_dir_path(__FILE__) . 'display/' . $this->plugin_name . '-admin-shortcodes.php' );
}
/**
* Render google maps general
*
* @since 1.0.0
* @access public
* @param $post
*/
public function render_dba_google_maps_general($post) {
wp_nonce_field('dba_google_maps_nonce', 'meta_box_nonce');
$default = $this->dba_google_maps_general_defaults();
$stored = $this->dba_google_maps_general($post);
$data = array();
$data['width'] = ($stored['width'] ? $stored['width'] : $default['width']);
$data['widthm'] = ($stored['widthm'] ? $stored['widthm'] : $default['widthm']);
$data['height'] = ($stored['height'] ? $stored['height'] : $default['height']);
$data['zoom'] = ($stored['zoom'] ? $stored['zoom'] : $default['zoom']);
$data['type'] = ($stored['type'] ? $stored['type'] : $default['type']);
$data['imagery'] = ($stored['imagery'] ? $stored['imagery'] : $default['imagery']);
include( plugin_dir_path(__FILE__) . 'display/' . $this->plugin_name . '-admin-general.php' );
}
/**
* Gets the Google Maps default general.
*
* @since 1.0.0
* @access public
* @return array The array of Google Maps defaults
*/
public function dba_google_maps_general_defaults() {
return array(
'width' => '100',
'widthm' => '%',
'height' => '400',
'zoom' => '8',
'type' => 'roadmap',
'imagery' => 'false'
);
}
/**
* Gets the Google Maps general.
*
* @since 1.0.0
* @access public
* @param $post
* @return array The array of Google Maps general
*/
public function dba_google_maps_general($post) {
$post_id = $post->ID;
$general = get_post_meta($post_id, 'dba_google_maps_general', true);
if (empty($general)) {
$this->dba_google_maps_general_defaults();
} else {
return $general;
}
}
/**
* Render google maps markers
*
* @since 1.0.0
* @access public
* @param $post
*/
public function render_dba_google_maps_markers($post) {
wp_nonce_field('dba_google_maps_nonce', 'meta_box_nonce');
$icon_deafult = plugin_dir_url(__FILE__) . 'images/marker.png';
include( plugin_dir_path(__FILE__) . 'display/' . $this->plugin_name . '-admin-markers.php' );
}
/**
* Gets the Google Maps markers.
*
* @since 1.0.0
* @access public
* @param $post_id
* @return array The array of Google Maps markers
*/
public function dba_google_maps_markers($post_id) {
$markers = get_post_meta($post_id, 'dba_google_maps_markers', true);
if (empty($markers)) {
return array(
'0' => array(
'address' => 'Colosseo, Roma, RM, Italia',
'latitude' => '41.890210',
'longitude' => '12.492231',
'icon' => '',
'animation' => 'DROP',
'info_window' => '',
'info_window_open' => 'Onclick',
'info_window_width' => ''
),
);
} else {
return $markers;
}
}
/**
* Add a new marker tab.
*
* @since 1.0.0
* @access public
*/
public function ajax_add_dba_google_maps_marker_tab() {
// security check
if (!wp_verify_nonce($_REQUEST['_wpnonce'], 'dba_google_maps_addmarker')) {
_e("Security check failed. Refresh page and try again.", $this->plugin_name);
wp_die();
}
$element = $_POST['element'];
?>