Plugin Directory

Changeset 2959850


Ignore:
Timestamp:
08/29/2023 11:52:48 AM (2 years ago)
Author:
markomaksym
Message:

Google Maps API integrated.

Location:
many-points-on-the-map
Files:
58 added
2 deleted
14 edited

Legend:

Unmodified
Added
Removed
  • many-points-on-the-map/trunk/includes/admin/assets/js/script.js

    r2097177 r2959850  
    206206        $( this ).parent().remove();
    207207
    208     } );   
     208    } );
     209
     210    /***************
     211    * Settings page
     212    */
     213    $( '#mxmpotm_settings' ).on( 'submit', function(e) {
     214
     215        e.preventDefault();
     216
     217        const api_key = $( '#mx_google_map_api_key' ).val();
     218
     219        if(api_key === '') {
     220            alert('Enter a Google Map API Key!');
     221            return;
     222        }
     223
     224        var nonce = $(this).find( '#mxmpotm_wpnonce' ).val();
     225
     226        const data = {
     227            action: 'mxmpotm_update_map_settings',
     228            nonce: nonce,
     229            api_key: api_key
     230        };
     231
     232
     233        jQuery.post( ajaxurl, data, function( response ) {
     234
     235            if(response === 'success') {
     236                alert('Saved');
     237            } else {
     238                alert('Something went wrong. Make sure you have changed the API key.');
     239            }
     240
     241        } );
     242
     243    } );
    209244
    210245} );
     
    250285
    251286        filter_regions = 1;
     287
     288    }
     289
     290    var filter_points       = 0;
     291
     292    if( $( '#mx_show_points_filter' ).prop( 'checked' ) ) {
     293
     294        filter_points = 1;
    252295
    253296    }
     
    342385            'map_width'         :   map_width,
    343386            'map_height'        :   map_height,
    344             'filter_regions'    :   filter_regions
     387            'filter_regions'    :   filter_regions,
     388            'filter_points'     :   filter_points
    345389
    346390        };
  • many-points-on-the-map/trunk/includes/admin/class-admin-main.php

    r2097798 r2959850  
    22
    33// Exit if accessed directly
    4 if ( ! defined( 'ABSPATH' ) ) exit;
     4if (!defined('ABSPATH')) exit;
    55
    66class MXMPOTMAdminMain
     
    1818
    1919        $this->mxmpotm_include();
    20 
    2120    }
    2221
     
    2928        // require database-talk class
    3029        require_once MXMPOTM_PLUGIN_ABS_PATH . 'includes/admin/class-database-talk.php';
    31 
    3230    }
    3331
     
    3937
    4038        // register scripts and styles
    41         add_action( 'admin_enqueue_scripts', array( $this, 'mxmpotm_enqueue' ) );
     39        add_action('admin_enqueue_scripts', array($this, 'mxmpotm_enqueue'));
    4240
    4341        // register admin menu
    44         add_action( 'admin_menu', array( $this, 'add_admin_pages' ) );
     42        add_action('admin_menu', array($this, 'add_admin_pages'));
    4543
    4644        // add link Settings under the name of the plugin
    47         add_filter( "plugin_action_links_$this->plugin_name", array( $this, 'settings_link' ) );
    48 
    49     }
    50 
    51         public function mxmpotm_enqueue()
    52         {
    53 
    54             // include custom file
    55             wp_enqueue_script( 'mxmpotm_admin_script_custom', MXMPOTM_PLUGIN_URL . 'includes/admin/assets/js/custom.js', array( 'jquery' ), MXMPOTM_PLUGIN_VERSION, true );
    56 
    57             // localize object
    58             wp_localize_script( 'mxmpotm_admin_script_custom', 'mxmpotm_localize_script_custom_obj', array(
    59 
    60                 'mxmpotm_nonce'         => wp_create_nonce( 'mxmpotm_admin_nonce' )
    61 
    62             ) );   
    63 
    64             if( ! isset( $_GET['page'] ) ) return;
    65 
    66             // include bootstrap 4.1.1
    67             if(
    68                 $_GET['page'] == 'mxmpotm-many-points-on-the-map' ||
    69                 $_GET['page'] == 'mxmpotm-many-points-on-the-map-add' ||
    70                 $_GET['page'] == 'mxmpotm-many-points-on-the-map-edit'
    71             ) {
    72 
    73                 wp_enqueue_style( 'mxmpotm_bootstrap_4_1_1', MXMPOTM_PLUGIN_URL . 'includes/admin/assets/bootstrap-4.1.1/css/bootstrap.min.css' );
    74 
    75             }
    76 
    77             // include font-awesome
    78             wp_enqueue_style( 'mxmpotm_font_awesome', MXMPOTM_PLUGIN_URL . 'assets/font-awesome-4.6.3/css/font-awesome.min.css' );
    79 
    80             // include admin_style file
    81             wp_enqueue_style( 'mxmpotm_admin_style', MXMPOTM_PLUGIN_URL . 'includes/admin/assets/css/style.css', array( 'mxmpotm_font_awesome' ), MXMPOTM_PLUGIN_VERSION, 'all' );
    82 
    83             wp_enqueue_media();
    84 
    85             // include admin_script file
    86             wp_enqueue_script( 'mxmpotm_admin_script', MXMPOTM_PLUGIN_URL . 'includes/admin/assets/js/script.js', array( 'jquery' ), MXMPOTM_PLUGIN_VERSION, true );           
    87 
    88             // localize object
    89             wp_localize_script( 'jquery', 'mxmpotm_localize_script_obj', array(
    90 
    91                 'default_marker_src'    => MXMPOTM_PLUGIN_URL . '/includes/admin/assets/img/default_icon.png',
    92 
    93                 'mxmpotm_nonce'         => wp_create_nonce( 'mxmpotm_admin_nonce' )
    94 
    95             ) );   
    96 
     45        add_filter("plugin_action_links_$this->plugin_name", array($this, 'settings_link'));
     46    }
     47
     48    public function mxmpotm_enqueue()
     49    {
     50
     51        // include custom file
     52        wp_enqueue_script('mxmpotm_admin_script_custom', MXMPOTM_PLUGIN_URL . 'includes/admin/assets/js/custom.js', array('jquery'), MXMPOTM_PLUGIN_VERSION, true);
     53
     54        // localize object
     55        wp_localize_script('mxmpotm_admin_script_custom', 'mxmpotm_localize_script_custom_obj', array(
     56
     57            'mxmpotm_nonce'         => wp_create_nonce('mxmpotm_admin_nonce')
     58
     59        ));
     60
     61        if (!isset($_GET['page'])) return;
     62
     63        // include bootstrap 4.1.1
     64        if (
     65            $_GET['page'] == 'mxmpotm-many-points-on-the-map' ||
     66            $_GET['page'] == 'mxmpotm-many-points-on-the-map-add' ||
     67            $_GET['page'] == 'mxmpotm-many-points-on-the-map-edit' ||
     68            $_GET['page'] == 'mxmpotm-many-points-on-the-map-settings'
     69        ) {
     70
     71            wp_enqueue_style('mxmpotm_bootstrap_4_1_1', MXMPOTM_PLUGIN_URL . 'includes/admin/assets/bootstrap-4.1.1/css/bootstrap.min.css');
    9772        }
    9873
    99         // register admin menu
    100         public function add_admin_pages()
    101         {
    102 
    103             add_menu_page( __( 'List of the maps', 'mxmpotm-map' ), __( 'Many points', 'mxmpotm-map' ), 'manage_options', 'mxmpotm-many-points-on-the-map', array( $this, 'admin_index' ), 'dashicons-image-filter', 111 ); // icons https://developer.wordpress.org/resource/dashicons/#id
    104 
    105             // add map
    106             add_submenu_page( 'mxmpotm-many-points-on-the-map', __( 'Create a new map', 'mxmpotm-map' ), __( 'Create a new map', 'mxmpotm-map' ), 'manage_options', 'mxmpotm-many-points-on-the-map-add', array( $this, 'add_map' ) );
    107 
    108             // edit map
    109             add_submenu_page( 'NULL', __( 'Edit Map', 'mxmpotm-map' ), __( 'Edit Map', 'mxmpotm-map' ), 'manage_options', 'mxmpotm-many-points-on-the-map-edit', array( $this, 'edit_map' ) );
    110 
    111         }
    112 
    113             public function admin_index()
    114             {
    115 
    116                 // require index page
    117                 mxmpotm_require_template_admin( 'index.php' );
    118 
    119             }
    120 
    121             public function edit_map()
    122             {
    123 
    124                 // require one_map page
    125                 mxmpotm_require_template_admin( 'edit_map.php' );
    126 
    127             }
    128 
    129             public function add_map()
    130             {
    131                
    132                 // require add_new_map page
    133                 mxmpotm_require_template_admin( 'add_new_map.php' );
    134 
    135             }
    136 
    137         // add settings link
    138         public function settings_link( $links )
    139         {
    140 
    141             $settings_link = '<a href="' . get_admin_url() . 'admin.php?page=mxmpotm-many-points-on-the-map">' . __( 'Settings', 'mxmpotm-map' ) . '</a>'; // options-general.php
    142 
    143             array_push( $links, $settings_link );
    144 
    145             return $links;
    146 
    147         }
     74        // include font-awesome
     75        wp_enqueue_style('mxmpotm_font_awesome', MXMPOTM_PLUGIN_URL . 'assets/font-awesome-4.6.3/css/font-awesome.min.css');
     76
     77        // include admin_style file
     78        wp_enqueue_style('mxmpotm_admin_style', MXMPOTM_PLUGIN_URL . 'includes/admin/assets/css/style.css', array('mxmpotm_font_awesome'), MXMPOTM_PLUGIN_VERSION, 'all');
     79
     80        wp_enqueue_media();
     81
     82        // include admin_script file
     83        wp_enqueue_script('mxmpotm_admin_script', MXMPOTM_PLUGIN_URL . 'includes/admin/assets/js/script.js', array('jquery'), MXMPOTM_PLUGIN_VERSION, true);
     84
     85        // localize object
     86        wp_localize_script('jquery', 'mxmpotm_localize_script_obj', array(
     87
     88            'default_marker_src'    => MXMPOTM_PLUGIN_URL . '/includes/admin/assets/img/default_icon.png',
     89
     90            'mxmpotm_nonce'         => wp_create_nonce('mxmpotm_admin_nonce')
     91
     92        ));
     93    }
     94
     95    // register admin menu
     96    public function add_admin_pages()
     97    {
     98
     99        add_menu_page(__('List of the maps', 'mxmpotm-map'), __('Many points', 'mxmpotm-map'), 'manage_options', 'mxmpotm-many-points-on-the-map', array($this, 'admin_index'), 'dashicons-image-filter', 111); // icons https://developer.wordpress.org/resource/dashicons/#id
     100
     101        // add map
     102        add_submenu_page('mxmpotm-many-points-on-the-map', __('Create a new map', 'mxmpotm-map'), __('Create a new map', 'mxmpotm-map'), 'manage_options', 'mxmpotm-many-points-on-the-map-add', array($this, 'add_map'));
     103
     104        // edit map
     105        add_submenu_page('NULL', __('Edit Map', 'mxmpotm-map'), __('Edit Map', 'mxmpotm-map'), 'manage_options', 'mxmpotm-many-points-on-the-map-edit', array($this, 'edit_map'));
     106
     107        // Settings page
     108        add_submenu_page('mxmpotm-many-points-on-the-map', __('Settings', 'mxmpotm-map'), __('Settings', 'mxmpotm-map'), 'manage_options', 'mxmpotm-many-points-on-the-map-settings', array($this, 'settings'));
     109
     110    }
     111
     112    public function admin_index()
     113    {
     114
     115        // require index page
     116        mxmpotm_require_template_admin('index.php');
     117    }
     118
     119    public function edit_map()
     120    {
     121
     122        // require one_map page
     123        mxmpotm_require_template_admin('edit_map.php');
     124    }
     125
     126    public function add_map()
     127    {
     128
     129        // require add_new_map page
     130        mxmpotm_require_template_admin('add_new_map.php');
     131    }
     132
     133    public function settings()
     134    {
     135   
     136        // require settings page
     137        mxmpotm_require_template_admin('settings.php');
     138    }
     139
     140    // add settings link
     141    public function settings_link($links)
     142    {
     143
     144        $settings_link = '<a href="' . get_admin_url() . 'admin.php?page=mxmpotm-many-points-on-the-map">' . __('Settings', 'mxmpotm-map') . '</a>'; // options-general.php
     145
     146        array_push($links, $settings_link);
     147
     148        return $links;
     149    }
    148150
    149151    // notifications
     
    152154
    153155        // marker notice
    154         if( is_admin() && get_option( '_mxmpotm_custom_markup_notice' ) !== 'was_seen' ) {
    155            
    156             add_action( 'admin_notices', array( $this, 'mxmpotm_custom_markup_notice' ) );
     156        if (is_admin() && get_option('_mxmpotm_custom_markup_notice') !== 'was_seen') {
     157
     158            add_action('admin_notices', array($this, 'mxmpotm_custom_markup_notice'));
    157159        }
    158160
    159161        // alphabet order notice
    160         if( is_admin() && get_option( '_mxmpotm_alphabet_order_notice' ) !== 'was_seen' ) {
    161            
    162             add_action( 'admin_notices', array( $this, 'mxmpotm_alphabet_order_notice' ) );
     162        if (is_admin() && get_option('_mxmpotm_alphabet_order_notice') !== 'was_seen') {
     163
     164            add_action('admin_notices', array($this, 'mxmpotm_alphabet_order_notice'));
    163165        }
    164 
    165     }
    166 
    167         // marker notification
    168         public function mxmpotm_custom_markup_notice()
    169         {
    170 
    171             ?>
    172             <div class="notice notice-success mxmpotm_notification_marker">
    173                 <h5><b>"Many points on the map" plugin:</b></h5>
    174                 <p><?php echo __( 'Now you can set up your own custom marker for any point.', 'mxmpotm-map' ); ?></p>
    175 
    176                 <p>
    177                     <a href="<?php get_admin_url(); ?>admin.php?page=mxmpotm-many-points-on-the-map"><?php echo __( 'Go to the map list', 'mxmpotm-map' ); ?></a>
    178                 </p>
    179 
    180                 <p>
    181                     <button class="button button-primary button-large">OK!</button>
    182                 </p>
    183             </div>
    184             <?php
    185 
    186         }
    187 
    188         // alphabet order notice
    189         public function mxmpotm_alphabet_order_notice()
    190         {
    191 
    192             ?>
    193             <div class="notice notice-success mxmpotm_notification_alphabet_order">
    194                 <h5><b>"Many points on the map" plugin:</b></h5>
    195                 <p><?php echo __( 'Now the plugin has the ability to sort points and regions alphabetically.', 'mxmpotm-map' ); ?></p>
    196 
    197                 <p>
    198                     <a href="<?php get_admin_url(); ?>admin.php?page=mxmpotm-many-points-on-the-map"><?php echo __( 'Go to the map list', 'mxmpotm-map' ); ?></a>
    199                 </p>
    200 
    201                 <p>
    202                     <button class="button button-primary button-large">OK!</button>
    203                 </p>
    204             </div>
    205             <?php
    206 
    207         }
    208 
     166    }
     167
     168    // marker notification
     169    public function mxmpotm_custom_markup_notice()
     170    {
     171
     172?>
     173        <div class="notice notice-success mxmpotm_notification_marker">
     174            <h5><b>"Many points on the map" plugin:</b></h5>
     175            <p><?php echo __('Now you can set up your own custom marker for any point.', 'mxmpotm-map'); ?></p>
     176
     177            <p>
     178                <a href="<?php get_admin_url(); ?>admin.php?page=mxmpotm-many-points-on-the-map"><?php echo __('Go to the map list', 'mxmpotm-map'); ?></a>
     179            </p>
     180
     181            <p>
     182                <button class="button button-primary button-large">OK!</button>
     183            </p>
     184        </div>
     185    <?php
     186
     187    }
     188
     189    // alphabet order notice
     190    public function mxmpotm_alphabet_order_notice()
     191    {
     192
     193    ?>
     194        <div class="notice notice-success mxmpotm_notification_alphabet_order">
     195            <h5><b>"Many points on the map" plugin:</b></h5>
     196            <p><?php echo __('Now the plugin has the ability to sort points and regions alphabetically.', 'mxmpotm-map'); ?></p>
     197
     198            <p>
     199                <a href="<?php get_admin_url(); ?>admin.php?page=mxmpotm-many-points-on-the-map"><?php echo __('Go to the map list', 'mxmpotm-map'); ?></a>
     200            </p>
     201
     202            <p>
     203                <button class="button button-primary button-large">OK!</button>
     204            </p>
     205        </div>
     206<?php
     207
     208    }
    209209}
    210210
     
    216216
    217217// apply notifications
    218 $initialize_class->mxmpotm_notifications();
     218// $initialize_class->mxmpotm_notifications();
  • many-points-on-the-map/trunk/includes/admin/class-database-talk.php

    r2097774 r2959850  
    3838        add_action( 'wp_ajax_mxmpotm_alphabet_order', array( $this, 'mxmpotm_alphabet_order' ) );
    3939
     40        // map settings
     41        add_action( 'wp_ajax_mxmpotm_update_map_settings', array( $this, 'update_settings' ) );
     42
     43    }
     44
     45    /*
     46    * Update Settings
     47    */
     48    public function update_settings()
     49    {
     50
     51        // Checked POST nonce is not empty
     52        if( empty( $_POST['nonce'] ) ) wp_die( '0' );
     53
     54        // Checked or nonce match
     55        if( wp_verify_nonce( $_POST['nonce'], 'mxmpotm_nonce_request' ) ) {
     56
     57            if($_POST['api_key'] == '') return;
     58
     59            $api_key = sanitize_text_field($_POST['api_key']);
     60
     61            $option = update_option('mx_google_map_api_key', $api_key);
     62
     63            if($option) {
     64                echo 'success';
     65            } else {
     66                echo 'failed';
     67            }
     68
     69        }
     70
     71        wp_die();
     72
    4073    }
    4174
     
    5386
    5487            // Add map
    55             $this->add_new_map( $_POST['mapName'], $_POST['mapDesc'], $_POST['obj_points'], $_POST['latitude_center'], $_POST['longitude_center'], $_POST['zoom_map_center'], $_POST['zoom_map_to_point'], $_POST['map_width'], $_POST['map_height'] );
     88            $new_map = $this->add_new_map( $_POST['mapName'], $_POST['mapDesc'], $_POST['obj_points'], $_POST['latitude_center'], $_POST['longitude_center'], $_POST['zoom_map_center'], $_POST['zoom_map_to_point'], $_POST['map_width'], $_POST['map_height'], $_POST['filter_regions'], $_POST['filter_points'] );
    5689
    5790        }
     
    6295
    6396        // Add data
    64         public function add_new_map( $map_name, $map_desc, $obj_points, $latitude_center, $longitude_center, $zoom_map_center, $zoom_map_to_point, $map_width, $map_height )
     97        public function add_new_map( $map_name, $map_desc, $obj_points, $latitude_center, $longitude_center, $zoom_map_center, $zoom_map_to_point, $map_width, $map_height, $filter_regions, $filter_points )
    6598        {
    6699
     
    131164                $tmp_all_areas = array();
    132165
    133                 foreach ( $value['areas'] as $key => $_value ) {
    134                    
    135                     // point_desc
    136                     $area = sanitize_text_field( $_value );
    137 
    138                         $push_area = array_push( $tmp_all_areas, $area );
    139 
     166                if(isset($value['areas'])) {
     167                    foreach ( $value['areas'] as $key => $_value ) {
     168                       
     169                        // point_desc
     170                        $area = sanitize_text_field( $_value );
     171
     172                            array_push( $tmp_all_areas, $area );
     173
     174                    }
    140175                }
    141176
     
    143178
    144179                // push to main array
    145                 $push_to_main_array = array_push( $sanitize_points, $tmp_array );
     180                array_push( $sanitize_points, $tmp_array );
    146181
    147182            }
    148183
    149             $obj_points = serialize( $sanitize_points );
     184            $obj_points = serialize( $sanitize_points );           
    150185
    151186            // latitude of the map
     
    166201            $map_height = sanitize_text_field( $map_height );
    167202
     203            // filters
     204            $filter_points = intval($filter_points);
     205            $filter_regions = intval($filter_regions);
     206
    168207            global $wpdb;
    169208
    170209            $table_name = $wpdb->prefix . MXMPOTM_TABLE_SLUG;
    171210
    172             $wpdb->insert(
     211            $map = $wpdb->insert(
    173212                $table_name,
    174213                array(
     
    181220                    'zoom_to_point'         => $zoom_map_to_point,
    182221                    'map_width'             => $map_width,
    183                     'map_height'            => $map_height
     222                    'map_height'            => $map_height,
     223                    'filter_points'         => $filter_points,
     224                    'filter_regions'        => $filter_regions
    184225                ),
    185226                array(
     
    192233                    '%d',
    193234                    '%s',
    194                     '%s'
     235                    '%s',
     236                    '%d',
     237                    '%d'
    195238                )
    196239            );
    197240
     241            return $map;
     242
    198243        }
    199244
     
    211256
    212257            // Update map
    213             $this->update_map( $_POST['id_map'], $_POST['mapName'], $_POST['mapDesc'], $_POST['obj_points'], $_POST['latitude_center'], $_POST['longitude_center'], $_POST['zoom_map_center'], $_POST['zoom_map_to_point'], $_POST['map_width'], $_POST['map_height'], $_POST['filter_regions'] );
     258            $this->update_map( $_POST['id_map'], $_POST['mapName'], $_POST['mapDesc'], $_POST['obj_points'], $_POST['latitude_center'], $_POST['longitude_center'], $_POST['zoom_map_center'], $_POST['zoom_map_to_point'], $_POST['map_width'], $_POST['map_height'], $_POST['filter_regions'], $_POST['filter_points'] );
    214259
    215260        }
     
    220265
    221266        // Update map
    222         public function update_map( $id_map, $map_name, $map_desc, $obj_points, $latitude_center, $longitude_center, $zoom_map_center, $zoom_map_to_point, $map_width, $map_height, $filter_regions )
     267        public function update_map( $id_map, $map_name, $map_desc, $obj_points, $latitude_center, $longitude_center, $zoom_map_center, $zoom_map_to_point, $map_width, $map_height, $filter_regions, $filter_points )
    223268        {
    224269
     
    289334                $tmp_all_areas = array();
    290335
    291                 foreach ( $value['areas'] as $key => $_value ) {
    292                    
    293                     // point_desc
    294                     $area = sanitize_text_field( $_value );
    295 
    296                         $push_area = array_push( $tmp_all_areas, $area );
     336                if( isset($value['areas']) ) {
     337
     338                    foreach ( $value['areas'] as $key => $_value ) {
     339                       
     340                        // point_desc
     341                        $area = sanitize_text_field( $_value );
     342
     343                            $push_area = array_push( $tmp_all_areas, $area );
     344
     345                    }
    297346
    298347                }
     
    323372
    324373            $map_height = sanitize_text_field( $map_height );
     374
     375            // filters
     376            $filter_points = intval($filter_points);
     377            $filter_regions = intval($filter_regions);
    325378
    326379            global $wpdb;
     
    340393                    'map_width'             => $map_width,
    341394                    'map_height'            => $map_height,
     395                    'filter_points'         => $filter_points,
    342396                    'filter_regions'        => $filter_regions
    343397                ),
     
    353407                    '%s',
    354408                    '%s',
     409                    '%d',
    355410                    '%d'
    356411                )
  • many-points-on-the-map/trunk/includes/admin/templates/add_new_map.php

    r1914879 r2959850  
    110110    <div class="mx-block_wrap">
    111111
     112        <h5><?php echo __( 'Search points', 'mxmpotm-map' ); ?></h5>
     113
     114        <div class="form-group">
     115
     116            <label for="mx_show_points_filter"><?php echo __( 'Show points filter:', 'mxmpotm-map' ); ?></label>
     117
     118            <input type="checkbox" name="mx_show_points_filter" class="form-control" id="mx_show_points_filter" value="0" />
     119
     120        </div> 
     121
     122    </div>
     123
     124    <!-- <div class="mx-block_wrap">
     125
    112126        <h5><?php echo __( 'Filters', 'mxmpotm-map' ); ?></h5>
    113127
     
    120134        </div> 
    121135
    122     </div>
     136    </div> -->
    123137
    124138    <!-- area of creating a new points  -->
  • many-points-on-the-map/trunk/includes/admin/templates/edit_map.php

    r2097177 r2959850  
    140140        <div class="form-group">
    141141
     142            <label for="mx_show_points_filter"><?php echo __( 'Show points filter:', 'mxmpotm-map' ); ?></label>
     143
     144            <input type="checkbox" name="mx_show_points_filter" class="form-control" id="mx_show_points_filter" value="<?php echo $map_rows->filter_points; ?>" <?php if( $map_rows->filter_points == 1 ) echo 'checked'; ?> />
     145
     146        </div>
     147
     148    </div>
     149
     150    <!-- <div class="mx-block_wrap">
     151
     152        <h5><?php echo __( 'Filters', 'mxmpotm-map' ); ?></h5>
     153
     154        <div class="form-group">
     155
    142156            <label for="mx_show_region_filter"><?php echo __( 'Show region filter:', 'mxmpotm-map' ); ?></label>
    143157
     
    146160        </div> 
    147161
    148     </div>
     162    </div> -->
    149163
    150164    <!-- area of creating a new points  -->
  • many-points-on-the-map/trunk/includes/class-basis-plugin-class.php

    r2019341 r2959850  
    3232                `map_width` varchar(6) DEFAULT '100%' NOT NULL,
    3333                `map_height` varchar(6) DEFAULT '500px' NOT NULL,
    34                 `latitude_map_center` varchar(15) NOT NULL,
    35                 `longitude_map_center` varchar(15) NOT NULL,
     34                `latitude_map_center` varchar(20) NOT NULL,
     35                `longitude_map_center` varchar(20) NOT NULL,
    3636                `zoom_map_center` int(3) DEFAULT 10 NOT NULL,
    3737                `zoom_to_point` int(2) DEFAULT 12 NOT NULL,
    3838                `filter_regions` int(1) DEFAULT 1 NOT NULL,
     39                `filter_points` int(1) DEFAULT 1 NOT NULL,
    3940                PRIMARY KEY (`id`)
    4041            ) ENGINE=MyISAM DEFAULT CHARSET=$wpdb->charset AUTO_INCREMENT=1;";
  • many-points-on-the-map/trunk/includes/class-final-main-class.php

    r2097798 r2959850  
    3131
    3232        // version
    33         $this->mxmpotm_define( 'MXMPOTM_PLUGIN_VERSION', '1.3.1' );// '1.3'
     33        $this->mxmpotm_define( 'MXMPOTM_PLUGIN_VERSION', '1.4' );// '1.3'
    3434
    3535    }
  • many-points-on-the-map/trunk/includes/core/helpers.php

    r2097774 r2959850  
    22
    33// Exit if accessed directly
    4 if ( ! defined( 'ABSPATH' ) ) exit;
     4if (!defined('ABSPATH')) exit;
    55
    66/*
    77* Require template for admin panel
    88*/
    9 function mxmpotm_require_template_admin( $file ) {
     9function mxmpotm_require_template_admin($file)
     10{
    1011
    1112    require_once MXMPOTM_PLUGIN_ABS_PATH . 'includes/admin/templates/' . $file;
    12 
    1313}
    1414
     
    1717*/
    1818// select row by id
    19 function mxmpotm_select_row( $id ) {
     19function mxmpotm_select_row($id)
     20{
    2021
    2122    global $wpdb;
     
    2324    $table_name = $wpdb->prefix . MXMPOTM_TABLE_SLUG;
    2425
    25     $get_row_map = $wpdb->get_row( "SELECT map_name, map_desc, points, latitude_map_center, longitude_map_center, zoom_map_center, zoom_to_point, map_width, map_height, filter_regions FROM $table_name WHERE id = $id" );
     26    $get_row_map = $wpdb->get_row("SELECT map_name, map_desc, points, latitude_map_center, longitude_map_center, zoom_map_center, zoom_to_point, map_width, map_height, filter_regions, filter_points FROM $table_name WHERE id = $id");
    2627
    2728    return $get_row_map;
    28 
    2929}
    3030
    3131// select rows
    32 function mxmpotm_select_rows() {
     32function mxmpotm_select_rows()
     33{
    3334
    3435    global $wpdb;
     
    3637    $table_name = $wpdb->prefix . MXMPOTM_TABLE_SLUG;
    3738
    38     $get_all_rows_map = $wpdb->get_results( "SELECT id, map_name, map_desc, points FROM $table_name ORDER BY id DESC" );
     39    $get_all_rows_map = $wpdb->get_results("SELECT id, map_name, map_desc, points FROM $table_name ORDER BY id DESC");
    3940
    4041    return $get_all_rows_map;
    41 
    4242}
    4343
     
    4545* Shortcodes
    4646*/
    47 function mxmpotm_show_many_points_map( $args ) {
     47function mxmpotm_show_many_points_map($args)
     48{
     49
     50    ob_start();
    4851
    4952    // if isset id of the map
    50     if( ! isset( $args['id'] ) ) return '<strong>Error in shortcode!</strong>';
     53    if (!isset($args['id'])) return '<strong>Error in shortcode!</strong>';
    5154
    5255    // save this id
    53     $id_map = intval( $args['id'] );
    54    
     56    $id_map = intval($args['id']);
     57
    5558    // get result by id
    56     $result_map = mxmpotm_select_row( $id_map );
     59    $result_map = mxmpotm_select_row($id_map);
    5760
    5861    // check if the map exists
    59     if( $result_map == NULL ) return '<strong>Error in shortcode!</strong>';
     62    if ($result_map == NULL) return '<strong>Error in shortcode!</strong>';
    6063
    6164    // unserialize points
    62     $unserialize_points = maybe_unserialize( $result_map->points );
     65    $unserialize_points = maybe_unserialize($result_map->points);
    6366
    6467    // sortable
    65     $array_result = mxmpotm_sort_array_by_alphabet_order( $unserialize_points );
    66 
    67     // create js object for display data
    68     return mxmpotm_create_object_points( $result_map, $array_result );
    69 
    70 }
    71 
    72 add_shortcode( 'many_points_map', 'mxmpotm_show_many_points_map' );
     68    $array_result = mxmpotm_sort_array_by_alphabet_order($unserialize_points);
     69
     70    // $result_map, $array_result
     71
     72    $points = maybe_unserialize($result_map->points);
     73
     74    $map_id = get_the_ID();
     75
     76    // var_dump(json_encode($result_map));
     77?>
     78
     79    <div class="mx-map_wrapper">
     80
     81        <div class="mx-map_desc">
     82            <h3><?php echo $result_map->map_name; ?></h3>
     83
     84            <?php if ($result_map->filter_points == '1') : ?>
     85
     86                <div class="mx-map_filter">
     87                    <label for="mxmpotm_map_search_point"><?php echo __('Search points:', 'mxmpotm-map'); ?></label>
     88                    <select id="mx-map-select" name="mxmpotm_map_search_point">
     89                        <option value="">All</option>
     90                        <?php foreach ($points as $point) : ?>
     91                            <option value="<?php echo $point['point_latitude']; ?>,<?php echo $point['point_longitude']; ?>"><?php echo $point['point_name']; ?></option>
     92                        <?php endforeach; ?>
     93                    </select>
     94                </div>
     95
     96            <?php endif; ?>
     97
     98            <p><?php echo $result_map->map_desc; ?></p>
     99        </div>
     100
     101        <div id="mxmpotm_map" style="width: <?php echo $result_map->map_width; ?>; height:<?php echo $result_map->map_height; ?>" data-mx-map='<?php echo mx_map_data_to_json($result_map); ?>' data-map_id="<?php echo $map_id; ?>"></div>
     102
     103    </div>
     104
     105<?php return ob_get_clean();
     106}
     107
     108add_shortcode('many_points_map', 'mxmpotm_show_many_points_map');
    73109
    74110/*
    75111* components of map
    76112*/
    77     // create js object
    78     function mxmpotm_create_object_points( $map, $points ) {
    79 
    80         // create html
    81         $html = '<div class="mx-map_desc">';
    82 
    83         $html .= '<h3>' . $map->map_name . '</h3>';
    84 
    85         $html .= '<p>' . $map->map_desc . '</p>';
    86 
    87         $html .= '</div>';
    88 
    89         $html .= '<script src="https://api-maps.yandex.ru/2.1/?lang=ru_RU" type="text/javascript"></script>';
    90 
    91         // get filter
    92         $html .= mxmpotm_filter_map( $map, $points  );
    93 
    94         $html .= '<div id="mxmpotm_map" style="width: ' . $map->map_width . '; height: ' . $map->map_height . '"></div>';
    95 
    96         $html .= '<script> var points = [';
    97 
    98                 foreach ( $points as $key => $value ) :
    99                
    100                     $html .= '{"type": "Feature","id": ' . $value['point_id'] . ',';
    101                    
    102                     $html .= '"geometry": {"type": "Point","coordinates": [';
    103 
    104                     $html .= $value['point_latitude'] . ', ' . $value['point_longitude'] . '] },';
    105 
    106                     $html .= '"mx_object": {"areas": ["' . implode( "\",\"", $value['areas'] ) . '"]},';
    107 
    108                     $html .= '"options": {';
    109 
    110                         $html .= 'iconLayout: "default#image",';
    111 
    112                         if( strlen( $value['point_custom_marker'] ) > 4 ) {
    113 
    114                             $html .= 'iconImageHref: "' . $value['point_custom_marker'] . '",';
    115 
    116                             $html .= 'iconImageSize: [42, 42]';
    117                        
    118                         }                       
    119 
    120                     $html .= '},';
    121 
    122                     $html .= '"properties": {"balloonContent": `' . mxmpotm_show_content( $value['point_id'], $value['point_name'], $value['point_address'], $value['phone'], $value['web_site'], $value['areas'], $value['point_desc'], $value['point_additional'] ) . '`}},';
    123 
    124                 endforeach;
    125 
    126             $html .= ']; </script>';
    127 
    128         $html .= mxmpotm_vars_for_translate( $map );
    129 
    130         // script for map
    131         $html .= '<script src="' . MXMPOTM_PLUGIN_URL . 'includes/frontend/assets/js/yandex-map-customize.js?v=' . MXMPOTM_PLUGIN_VERSION . '"></script>';
    132 
    133         return $html;
    134 
    135     }
    136    
    137     // create array of areas
    138     function mxmpotm_create_array_areas( $areasArray ) {
    139 
    140         $stringAreas = '';
    141 
    142         for( $i = 0; $i < count( $areasArray ); $i++ ) {
    143 
    144             if( $i == count( $areasArray ) - 1 ) {
    145 
    146                 $stringAreas .= '"' . $areasArray[$i] . '"';
    147 
    148             } else {
    149 
    150                 $stringAreas .= '"' . $areasArray[$i] . '",';
    151 
     113
     114// data to json
     115function mx_map_data_to_json($data)
     116{
     117
     118    $prepared_data = [];
     119
     120    foreach ($data as $key => $value) {
     121
     122        if ($key !== 'points') {
     123            $prepared_data[$key] = $value;
     124        } else {
     125            $prepared_data[$key] = maybe_unserialize($value);
     126        }
     127    }
     128
     129    return json_encode($prepared_data);
     130}
     131
     132//
     133function mxmpotm_sort_array_by_alphabet_order($_array)
     134{
     135
     136    $new_array_of_names = array();
     137
     138    foreach ($_array as $key => $value) {
     139
     140        array_push($new_array_of_names, $value["point_name"]);
     141    }
     142
     143    // get names by alphabet order
     144    $array_of_names_sorted = mxmpotm_sort_array_by_alphabet_order_recursion($new_array_of_names, array());
     145
     146    // create sortable array
     147    $sortable_array = mxmpotm_crate_sortable_array($_array, $array_of_names_sorted);
     148
     149    return $sortable_array;
     150}
     151
     152// sort name value
     153function mxmpotm_sort_array_by_alphabet_order_recursion($new_array_of_names, $new_array_of_names_sorted)
     154{
     155
     156    $new_array_of_names = $new_array_of_names;
     157
     158    $new_array_of_names_sorted = $new_array_of_names_sorted;
     159
     160    if (count($new_array_of_names) > 0) {
     161
     162        // find minimal value
     163        $min_value = min($new_array_of_names);
     164
     165        array_push($new_array_of_names_sorted, $min_value);
     166
     167        // remove minimal value from main array
     168        foreach ($new_array_of_names as $key => $value) {
     169
     170            if ($key = array_search($min_value, $new_array_of_names)) {
     171
     172                unset($new_array_of_names[$key]);
     173
     174                $new_array_of_names_sorted = mxmpotm_sort_array_by_alphabet_order_recursion($new_array_of_names, $new_array_of_names_sorted);
    152175            }
    153 
    154176        }
    155 
    156         return $stringAreas;
    157 
    158     }
    159 
    160     // show modal window on the map
    161     function mxmpotm_show_content( $id, $name, $adress, $phone, $website, $areas, $point_desc, $point_additional ) {
    162 
    163         $html = '<div id="mxmpotmModal' . $id .'">';
    164 
    165             $html .= '<h4>' . $name . '</h4>';
    166 
    167             if( $point_desc !== '' ) {
    168 
    169                 $html .= '<p class="mxmpotm-point_desc">'. $point_desc . '</p>';
    170 
    171             }           
    172 
    173             $html .= '<p class="mxmpotm-point_adress"><strong>' . __( 'Address:', 'mxmpotm-map' ) . '</strong> ' . $adress . '</p>';
    174 
    175             if( $website !== '' ) {
    176 
    177                 $html .= '<p class="mxmpotm-point_website"><strong>' . __( 'Web-site:', 'mxmpotm-map' ) . '</strong> <a href="' . $website . '" target="_blank">' . $website . '</a></p>';
    178 
     177    }
     178
     179    return $new_array_of_names_sorted;
     180}
     181
     182// crate sortable array
     183function mxmpotm_crate_sortable_array($full_array, $name_ordered_array)
     184{
     185
     186    $sortable_array = array();
     187
     188    foreach ($name_ordered_array as $key => $value) {
     189
     190        foreach ($full_array as $_key => $_value) {
     191
     192            if ($value == $_value["point_name"]) {
     193
     194                array_push($sortable_array, $full_array[$_key]);
    179195            }
    180 
    181             if( $phone !== '' ) {
    182 
    183                 $html .= '<p class="mxmpotm-point_phone"><strong>' . __( 'Phone:', 'mxmpotm-map' ) . '</strong> ' . $phone . '</p>';
    184 
    185             }           
    186 
    187             if( $point_additional !== '' ) {
    188 
    189                 $html .= '<p class="mxmpotm-point_phone"><strong>' . __( 'Additional:', 'mxmpotm-map' ) . '</strong> ' . $point_additional . '</p>';
    190 
    191             }           
    192 
    193             if( count( $areas ) !== 0 ) {
    194 
    195                 $html .= '<div class="mxmpotm-areas_wrap">';
    196 
    197                     $html .= '<strong>' . __( 'Regions:', 'mxmpotm-map' ) . '</strong>';
    198 
    199                         for( $i = 0; $i < count( $areas ); $i++ ) {
    200                            
    201                             $html .= '<p>' . $areas[$i] . '</p>';
    202 
    203                         }
    204 
    205                 $html .= '</div>';
    206 
    207             }           
    208 
    209         $html .= '</div>';
    210 
    211         return $html;
    212 
    213     }
    214 
    215     // fister
    216     function mxmpotm_filter_map( $map, $points  ) {     
    217 
    218         $html = '<div class="mxmpotm_map_filter_wrap">';
    219 
    220             // show filter by region
    221             if( $map->filter_regions == 1 ) {
    222 
    223                 $html .= '<div class="mxmpotm_map_filter_type_select">';
    224 
    225                     $html .= '<div class="mxmpotm_map_filter_type_select_point">';
    226 
    227                         $html .= '<label for="mxmpotm_type_filter_point">' . __( 'All points:', 'mxmpotm-map' ) . '</label>';
    228 
    229                         $html .= '<input type="radio" name="mxmpotm_type_filter" id="mxmpotm_type_filter_point" value="point" checked />';
    230 
    231                     $html .= '</div>';
    232 
    233                     $html .= '<div class="mxmpotm_map_filter_type_select_area">';
    234                    
    235                         $html .= '<label for="mxmpotm_type_filter_area">' . __( 'Regions:', 'mxmpotm-map' ) . '</label>';
    236 
    237                         $html .= '<input type="radio" name="mxmpotm_type_filter" id="mxmpotm_type_filter_area" value="area" />';
    238 
    239                     $html .= '</div>';                     
    240 
    241                 $html .= '</div>';
    242 
    243             }
    244 
    245             $html .= '<div class="mx-clearfix"></div>';
    246            
    247             $html .= '<div class="mxmpotm_map_filter_search_point">';
    248                
    249                 $html .= '<label for="mxmpotm_map_search_point">' . __( 'Search points:', 'mxmpotm-map' ) . '</label>';
    250 
    251                 $html .= '<select name="mxmpotm_map_search_point" id="mxmpotm_map_search_point">';
    252 
    253                     $html .= '<option value="0" data-lat="' . $map->latitude_map_center . '" data-lng="' . $map->longitude_map_center . '" >' . __( 'All points', 'mxmpotm-map' ) . '</option>';
    254                    
    255                     foreach ( $points as $k => $v ) {
    256 
    257                         $html .= '<option value="' . $v['point_id'] . '" data-lng="' . $v['point_longitude'] . '" data-lat="' . $v['point_latitude'] . '">' . $v['point_name'] . '</option>';
    258 
    259                     }
    260 
    261                 $html .= '</select>';
    262 
    263             $html .= '</div>';
    264 
    265             // show filter by region
    266             if( $map->filter_regions == 1 ) {
    267 
    268                 $html .= '<div class="mxmpotm_map_filter_search_area" style="display: none">';
    269 
    270                     $html .= '<label for="mxmpotm_map_search_area">' . __( 'Search region:', 'mxmpotm-map' ) . '</label>';
    271 
    272                     $html .= '<select id="mxmpotm_map_search_area"></select>';
    273 
    274                 $html .= '</div>';
    275 
    276             }           
    277            
    278         $html .= '</div>';
    279 
    280         return $html;
    281 
    282     }
    283 
    284     // vars for translate
    285     function mxmpotm_vars_for_translate( $map ) {
    286 
    287         $html = '<script>';
    288 
    289             $html .= 'var allAreasText = "' . __( 'All regions', 'mxmpotm-map' ) . '";';
    290 
    291             $html .= 'var centerMapLatDefault = parseFloat( ' . $map->latitude_map_center . ' );';
    292 
    293             $html .= 'var centerMapLngDefault = parseFloat( ' . $map->longitude_map_center . ' );';
    294 
    295             $html .= 'var zoomMapDefault = parseInt( ' . $map->zoom_map_center . ' );';
    296 
    297             $html .= 'var zoomToPointDefault = parseInt( ' . $map->zoom_to_point . ' );';
    298 
    299         $html .= '</script>';
    300 
    301         return $html;
    302 
    303     }
    304 
    305 //
    306 function mxmpotm_sort_array_by_alphabet_order( $_array ) {
    307 
    308     $new_array_of_names = array();
    309 
    310     foreach ( $_array as $key => $value ) {
    311 
    312         array_push( $new_array_of_names, $value["point_name"] );
    313 
    314     }
    315 
    316     // get names by alphabet order
    317     $array_of_names_sorted = mxmpotm_sort_array_by_alphabet_order_recursion( $new_array_of_names, array() );
    318 
    319     // create sortable array
    320     $sortable_array = mxmpotm_crate_sortable_array( $_array, $array_of_names_sorted );
     196        }
     197    }
     198
    321199
    322200    return $sortable_array;
    323 
    324 }
    325    
    326     // sort name value
    327     function mxmpotm_sort_array_by_alphabet_order_recursion( $new_array_of_names, $new_array_of_names_sorted ) {
    328 
    329         $new_array_of_names = $new_array_of_names;
    330 
    331         $new_array_of_names_sorted = $new_array_of_names_sorted;       
    332 
    333         if( count( $new_array_of_names ) > 0 ) {
    334 
    335             // find minimal value
    336             $min_value = min( $new_array_of_names );
    337 
    338             array_push( $new_array_of_names_sorted, $min_value );
    339 
    340             // remove minimal value from main array
    341             foreach ( $new_array_of_names as $key => $value ) {
    342                
    343                 if( $key = array_search( $min_value, $new_array_of_names ) ) {
    344 
    345                     unset( $new_array_of_names[$key] );
    346 
    347                     $new_array_of_names_sorted = mxmpotm_sort_array_by_alphabet_order_recursion( $new_array_of_names, $new_array_of_names_sorted );
    348 
    349                 }
    350 
    351             }           
    352 
    353         }       
    354 
    355         return $new_array_of_names_sorted;
    356 
    357     }
    358 
    359     // crate sortable array
    360     function mxmpotm_crate_sortable_array( $full_array, $name_ordered_array ) {
    361 
    362         $sortable_array = array();
    363 
    364         foreach ( $name_ordered_array as $key => $value ) {
    365            
    366             foreach ( $full_array as $_key => $_value ) {
    367            
    368                 if( $value == $_value["point_name"] ) {
    369 
    370                     array_push( $sortable_array, $full_array[$_key] );
    371 
    372                 }
    373            
    374             }
    375 
    376         }
    377 
    378 
    379         return $sortable_array;
    380 
    381     }
     201}
  • many-points-on-the-map/trunk/includes/frontend/assets/css/style.css

    r1914879 r2959850  
    4444    clear: both;
    4545}
     46.mx-toolbar {
     47    max-width: 350px;
     48}
     49.mx-toolbar h5 {
     50    padding: 0;
     51    margin: 7px 0;
     52}
     53.mx-toolbar > div {
     54    margin-bottom: 5px;
     55}
  • many-points-on-the-map/trunk/includes/frontend/assets/js/script.js

    r1914879 r2959850  
    1 jQuery( document ).ready( function( $ ){
    2 
    3     // JS script ...
    4 
    5 } );
     1(function ($) {
     2    $(function () {
     3
     4        function isJSON(str) {
     5            try {
     6                JSON.parse(str);
     7            } catch (e) {
     8                return false;
     9            }
     10            return true;
     11        }
     12
     13        window.mxmpotm_map_generator = window.mxmpotm_map_generator || {
     14
     15            container: 'mxmpotm_map',
     16            filter_container: 'mx-map-select',
     17            map_data: {},
     18
     19            init_filter: function (map, container) {
     20
     21                const _this = this;
     22
     23                container.addEventListener('change', function (e) {
     24
     25                    const coordinates = this.value.split(',');
     26
     27                    let lat = Number(_this.map_data.latitude_map_center);
     28                    let lng = Number(_this.map_data.longitude_map_center);
     29                    let zoom = parseInt(_this.map_data.zoom_map_center)
     30
     31                    if (coordinates[0] !== '') {
     32
     33                        lat = coordinates[0];
     34                        lng = coordinates[1];
     35                        zoom = parseInt(_this.map_data.zoom_to_point)
     36
     37                    }
     38
     39                    var panPoint = new google.maps.LatLng(Number(lat), Number(lng));
     40                    map.zoom = zoom;
     41                    map.panTo(panPoint);
     42                });
     43
     44            },
     45
     46            setMarker: function (marker, defaultMarker) {
     47                if (marker === '0') {
     48                    return defaultMarker.element
     49                } else {
     50                    const content = document.createElement("div");
     51                    content.innerHTML = `
     52                <img src="${marker}" width="35px" height="35px" />
     53            `;
     54                    return content;
     55                }
     56            },
     57
     58            init_map: async function (container) {
     59
     60                const _this = this;
     61
     62                const data = container.getAttribute('data-mx-map');
     63
     64                const map_id = container.getAttribute('data-map_id');
     65
     66                if (isJSON(data)) {
     67
     68                    const map_data = JSON.parse(data);
     69
     70                    _this.map_data = map_data;
     71
     72                    const {
     73                        Map,
     74                        InfoWindow
     75                    } = await google.maps.importLibrary("maps");
     76
     77                    const {
     78                        AdvancedMarkerElement,
     79                        PinElement
     80                    } = await google.maps.importLibrary("marker");
     81
     82                    const map = new Map(container, {
     83                        zoom: parseInt(map_data.zoom_map_center),
     84                        center: {
     85                            lat: Number(map_data.latitude_map_center),
     86                            lng: Number(map_data.longitude_map_center)
     87                        },
     88                        mapId: map_id
     89                    });
     90
     91                    let tourStops = []
     92
     93                    map_data.points.forEach(element => {
     94
     95                        let tmp = {
     96                            position: {},
     97                            title: `<div class="mx-toolbar"></div>`,
     98                            pointMarker: '0'
     99                        };
     100
     101                        for (const property in element) {
     102                            if (property === 'point_latitude') {
     103                                tmp.position.lat = Number(element[property])
     104                            }
     105                            if (property === 'point_longitude') {
     106                                tmp.position.lng = Number(element[property])
     107                            }
     108
     109                            tmp.title = `<div class="mx-toolbar">
     110                               
     111                                <h5>${element['point_name']}</h5>
     112
     113                                <div class="mx-desc">${element['point_desc']}</div>
     114
     115                                <div class="mx-address">${element['point_address']}</div>
     116
     117                                <div class="mx-additional">${element['point_additional']}</div>
     118
     119                                <div class="mx-phone">${element['phone']}</div>
     120
     121                                <div class="mx-web_site"><a href="${element['web_site']}" target="_blank">${element['web_site']}</a></div>
     122
     123                                <div class="mx-areas">${element['areas'].join(', ')}</div>
     124                           
     125                            </div>`;
     126
     127                            tmp.pointMarker = element['point_custom_marker'];
     128
     129                        }
     130
     131                        tourStops.push(tmp);
     132
     133                    });
     134
     135                    const infoWindow = new InfoWindow();
     136
     137                    tourStops.forEach(({
     138                        position,
     139                        title,
     140                        pointMarker
     141                    }, i) => {
     142                        const pin = new PinElement();
     143
     144                        const marker = new AdvancedMarkerElement({
     145                            position,
     146                            map,
     147                            title: title,
     148                            content: _this.setMarker(pointMarker, pin)
     149                        });
     150
     151                        marker.addListener("click", ({
     152                            domEvent,
     153                            latLng
     154                        }) => {
     155                            const {
     156                                target
     157                            } = domEvent;
     158                            infoWindow.close();
     159                            infoWindow.setContent(marker.title);
     160                            infoWindow.open(marker.map, marker);
     161                        });
     162                    });
     163
     164                    // filter
     165                    const select = document.getElementById(_this.filter_container);
     166
     167                    if (select !== null) {
     168
     169                        _this.init_filter(map, select);
     170
     171                    }
     172
     173                }
     174
     175
     176            },
     177
     178            prepare_map: function () {
     179
     180                const container = document.getElementById(this.container);
     181
     182                if (typeof container !== 'undefined') {
     183
     184                    this.init_map(container);
     185
     186                }
     187
     188            },
     189
     190            init: function () {
     191
     192                this.prepare_map();
     193
     194            }
     195
     196        };
     197
     198        mxmpotm_map_generator.init();
     199
     200    });
     201
     202})(jQuery);
  • many-points-on-the-map/trunk/includes/frontend/class-frontend-main.php

    r1914879 r2959850  
    22
    33// Exit if accessed directly
    4 if ( ! defined( 'ABSPATH' ) ) exit;
     4if (!defined('ABSPATH')) exit;
    55
    66class MXMPOTMFrontEndMain
     
    1313    {
    1414
    15         add_action( 'wp_enqueue_scripts', array( $this, 'enqueue' ) );
    16 
     15        add_action('wp_enqueue_scripts', array($this, 'enqueue'));
    1716    }
    1817
    19         public function enqueue()
    20         {
     18    public function enqueue()
     19    {
    2120
    22             wp_enqueue_style( 'mxmpotm_font_awesome', MXMPOTM_PLUGIN_URL . 'assets/font-awesome-4.6.3/css/font-awesome.min.css' );
     21        wp_enqueue_style('mxmpotm_font_awesome', MXMPOTM_PLUGIN_URL . 'assets/font-awesome-4.6.3/css/font-awesome.min.css');
    2322
    24             wp_enqueue_style( 'mxmpotm_style', MXMPOTM_PLUGIN_URL . 'includes/frontend/assets/css/style.css', array( 'mxmpotm_font_awesome' ), MXMPOTM_PLUGIN_VERSION, 'all' );
     23        wp_enqueue_style('mxmpotm_style', MXMPOTM_PLUGIN_URL . 'includes/frontend/assets/css/style.css', array('mxmpotm_font_awesome'), MXMPOTM_PLUGIN_VERSION, 'all');
    2524
    26             wp_enqueue_script( 'mxmpotm_script', MXMPOTM_PLUGIN_URL . 'includes/frontend/assets/js/script.js', array( 'jquery' ), MXMPOTM_PLUGIN_VERSION, false );
     25        $api_key = get_option('mx_google_map_api_key');
    2726
     27        if ($api_key && $api_key !== '') {
     28
     29            wp_enqueue_script('mxmpotm_google_maps_script', 'https://maps.googleapis.com/maps/api/js?key='.$api_key, array(), MXMPOTM_PLUGIN_VERSION, true);
     30
     31            wp_enqueue_script('mxmpotm_script', MXMPOTM_PLUGIN_URL . 'includes/frontend/assets/js/script.js', array('mxmpotm_google_maps_script'), MXMPOTM_PLUGIN_VERSION, true);
    2832        }
    29 
     33    }
    3034}
    3135
  • many-points-on-the-map/trunk/many-points-on-the-map.php

    r2097798 r2959850  
    44Plugin URI: https://github.com/Maxim-us/many-points-on-the-map
    55Description: The plugin helps you set points on the map and filter them in the future.
    6 Author: Marko Maksym
    7 Version: 1.3.1
     6Author: Maksym Marko
     7Version: 1.4
    88Author URI: https://github.com/Maxim-us
    99*/
  • many-points-on-the-map/trunk/readme.txt

    r2097798 r2959850  
    11=== Many points on the map ===
    22Contributors: markomaksym
    3 Tags: yandex maps, map
     3Tags: google maps, map
    44Requires at least: 4.7
    5 Tested up to: 5.2
    6 Stable tag: 1.3.1
     5Tested up to: 6.3
     6Stable tag: 1.4
    77License: GPLv2 or later
    88License URI: https://www.gnu.org/licenses/gpl-2.0.html
     
    1313
    1414The plugin helps you set points on the map and filter them in the future.
    15 The plugin is based on the Yandex.Maps API.
     15The plugin is based on the Google Maps API.
    1616You can put a map on your website using a shortcode.
    1717
     
    38384. Copy the longitude to the point
    39395. The shortcode of the map
    40 6. Appearance of the map
    41 7. Point information
    4240
    4341== Changelog ==
     42
     43= 1.4 =
     44* Google Maps API integrated.
    4445
    4546= 1.3.1 =
  • many-points-on-the-map/trunk/uninstall.php

    r1914879 r2959850  
    33// uninstall
    44if ( ! defined( 'WP_UNINSTALL_PLUGIN' ) ) die();
    5            
    6 global $wpdb;
    7 
    8 // table name
    9 $table_names = array();
    10 
    11 $table_names[] = $wpdb->prefix . 'mxmpotm_table_slug';
    12 
    13 // drop table(s);
    14 foreach( $table_names as $table_name ){
    15 
    16     $sql = 'DROP TABLE IF EXISTS ' . $table_name . ';';
    17 
    18     $wpdb->query( $sql );
    19 
    20 }
    21 
    22 // Delete posts CPT
    23 $posts = get_posts( array( 'post_type' => 'mxmpotm_book', 'numberposts' => -1 ) );
    24 
    25 foreach( $posts as $post ){
    26 
    27     wp_delete_post( $post->ID, true );
    28 
    29 }
    30 
    31 //delete_option( 'some_option' );
Note: See TracChangeset for help on using the changeset viewer.