Plugin Directory

Changeset 3412598


Ignore:
Timestamp:
12/05/2025 08:16:07 PM (3 months ago)
Author:
yhunter
Message:

plugin update

Location:
yamaps
Files:
7 edited
12 copied

Legend:

Unmodified
Added
Removed
  • yamaps/trunk/includes/admin.php

    r3235800 r3412598  
    44function yamap_plugin_scripts($plugin_array) {
    55    // Plugin localization
    6     wp_register_script('yamap_plugin', plugin_dir_url(__FILE__) . '../js/shortcode_parser.js?v=0.2');
     6    wp_register_script('yamap_plugin', plugin_dir_url(__FILE__) . '../js/shortcode_parser.js?v=0.3');
    77    wp_enqueue_script('yamap_plugin');
    88   
     
    3939        'MapContainerID' => __('Put in ID', 'yamaps'),
    4040        'MapContainerIDTip' => __('Do not create a block in the content. Use the existing block of the WP theme with the specified ID', 'yamaps'),
     41        'ClusterTab' => __('Clustering', 'yamaps'),
     42        'ClusterEnable' => __('Enable clustering', 'yamaps'),
     43        'ClusterGrid' => __('Cluster grid size (px)', 'yamaps'),
     44        'ClusterInfo' => __('Clustering groups nearby markers into clusters.<br>The grid size determines how close markers need to be to form a cluster.', 'yamaps'),
    4145        'Extra' => __('Extra', 'yamaps'),
    4246        'DeveloperInfoTab' => __('Design & Development', 'yamaps'),
     
    5256
    5357    //enqueue TinyMCE plugin script with its ID.
    54     $plugin_array["yamap_plugin"] =  plugin_dir_url(__FILE__) . "../js/btn.js?v=0.40";
     58    $plugin_array["yamap_plugin"] =  plugin_dir_url(__FILE__) . "../js/btn.js?v=0.5";
    5559
    5660    return $plugin_array;
  • yamaps/trunk/includes/init.php

    r3235800 r3412598  
    3434    'apikey_map_option'          => '',
    3535    'reset_maps_option'          => 'off',
     36    'cluster_map_option'         => 'off',      // Кластеризация по умолчанию
     37    'cluster_grid_option'        => '64',       // Размер ячейки кластеризации
    3638);
    3739
  • yamaps/trunk/includes/shortcodes.php

    r3235800 r3412598  
    7979   
    8080    $placearr = '';
     81   
     82    // Clustering is disabled by default
     83    // Works only when cluster="1" is explicitly specified in the shortcode
     84    // The option in options.php only affects the checkbox in the editor when creating a map
     85    $cluster_grid = isset($yamaps_defaults_front['cluster_grid_option']) ? $yamaps_defaults_front['cluster_grid_option'] : '64';
     86   
    8187    $atts = shortcode_atts( array(
    8288        'center' => esc_js($yamaps_defaults_front['center_map_option']),
     
    8894        'mobiledrag' => '1',
    8995        'container' => '',
     96        'cluster' => '0',           // Disabled by default, works only with cluster="1"
     97        'clustergrid' => $cluster_grid,
    9098    ), $atts );
    9199
     
    93101    $yacontrol_count = 0;
    94102    $yamap_onpage = true;
     103
     104    // Sanitize content: only allow [yaplacemark ...] shortcodes, remove everything else
     105    $safe_content = '';
     106    if ( ! empty( $content ) ) {
     107        // Match only [yaplacemark ...] shortcodes (self-closing or with closing tag)
     108        if ( preg_match_all( '/\[yaplacemark\s+[^\]]*\](?:\[\/yaplacemark\])?/i', $content, $matches ) ) {
     109            $safe_content = implode( '', $matches[0] );
     110        }
     111    }
    95112
    96113    $yamactrl = str_replace(';', '", "', esc_js($atts["controls"]));
     
    119136    }
    120137   
    121     $placemarkscode=str_replace("&nbsp;", "", strip_tags($content));
     138    $placemarkscode = $safe_content;
    122139
    123140    $atts["container"]=trim($atts["container"]);
     
    190207                                $placearr.='.add(myMap'.$current_map_index.'placemark'.$i.')';
    191208                            }
    192                             $yamap.='myMap'.$current_map_index.'.geoObjects'.$placearr.';';
     209                           
     210                            // If clustering is enabled
     211                            if ($atts["cluster"]=="1") {
     212                                $yamap.='
     213                                var yaClusterer'.$current_map_index.' = new ymaps.Clusterer({
     214                                    clusterIconLayout: "default#pieChart",
     215                                    clusterIconPieChartRadius: 25,
     216                                    clusterIconPieChartCoreRadius: 15,
     217                                    clusterIconPieChartStrokeWidth: 3,
     218                                    hasBalloon: false,
     219                                    gridSize: '.intval($atts["clustergrid"]).'
     220                                });
     221                                yaClusterer'.$current_map_index.'.add([';
     222                                for ($i = 1; $i <= $yaplacemark_count; $i++) {
     223                                    $yamap.='myMap'.$current_map_index.'placemark'.$i;
     224                                    if ($i < $yaplacemark_count) $yamap.=',';
     225                                }
     226                                $yamap.=']);
     227                                myMap'.$current_map_index.'.geoObjects.add(yaClusterer'.$current_map_index.');
     228                                ';
     229                            } else {
     230                                $yamap.='myMap'.$current_map_index.'.geoObjects'.$placearr.';';
     231                            }
     232                           
    193233                            if ($atts["scrollzoom"]=="0") $yamap.="myMap".$current_map_index.".behaviors.disable('scrollZoom');";
    194234                            // If map has mobiledrag=0, disable map dragging for the following platforms
  • yamaps/trunk/js/btn.js

    r3235714 r3412598  
    2020if (!editMapAction) { // Moved for correct operation in WP 5.6
    2121                           
    22     ym={map0: {center: coordaprox(yamap_defaults['center_map_option']), controls: yamap_defaults['controls_map_option'], height: yamap_defaults['height_map_option'], zoom: yamap_defaults['zoom_map_option'], maptype: yamap_defaults['type_map_option'], scrollzoom: optionCheck('wheelzoom_map_option'), mobiledrag: optionCheck('mobiledrag_map_option'), container: '', places: {}}};
     22    ym={map0: {center: coordaprox(yamap_defaults['center_map_option']), controls: yamap_defaults['controls_map_option'], height: yamap_defaults['height_map_option'], zoom: yamap_defaults['zoom_map_option'], maptype: yamap_defaults['type_map_option'], scrollzoom: optionCheck('wheelzoom_map_option'), mobiledrag: optionCheck('mobiledrag_map_option'), cluster: (yamap_defaults['cluster_map_option']==='on' ? '1' : '0'), clustergrid: yamap_defaults['cluster_grid_option'] || '64', container: '', places: {}}};
    2323
    2424
     
    2727function checkParam(param) {
    2828    var checker=true;
    29     if (ym.map0[param]==="0") {
    30         checker=false;
     29    if (param === 'cluster') {
     30        // For cluster: '1' means enabled, '0' means disabled
     31        checker = (ym.map0[param] === '1');
     32    } else {
     33        // For scrollzoom, mobiledrag: '0' means disabled, '' means enabled
     34        if (ym.map0[param]==="0") {
     35            checker=false;
     36        }
    3137    }
    3238    return checker;
     
    136142        setTimeout(checkcheckbox, 200, 'scrollzoom');
    137143        setTimeout(checkcheckbox, 200, 'mobiledrag');
     144        setTimeout(checkcheckbox, 200, 'cluster');  // Добавлено
     145       
     146        if(document.getElementById('clustergrid')) {
     147            ym[mapselector].clustergrid=jQuery("#clustergrid").val();
     148        }
    138149         
    139150        if(document.getElementById('mapcontainer')) {
     
    553564                            mapdatechange();
    554565                        });
     566                       
     567                        // Track cluster checkbox change
     568                        jQuery("#cluster").click(function() {
     569                            mapdatechange();
     570                        });
    555571
    556572                        // Track the change of icon fields 
     
    718734                                                    label: yamap_object.MapHeight,
    719735                                                    id: 'mapheight',
    720                                                     value: ym[mapselector].height, //yamap_defaults['height_map_option'],                                 
     736                                                    value: ym[mapselector].height,
    721737                                                    maxLength: '10',
    722738                                                    tooltip: 'rem, em, px, %',
     
    729745                                                    label: yamap_object.MapControls,
    730746                                                    id: 'mapcontrols',
    731                                                     value: ym[mapselector].controls, //yamap_defaults['controls_map_option'],   
     747                                                    value: ym[mapselector].controls,
    732748                                                    tooltip: yamap_object.MapControlsTip,
    733749                                                    onaction: mapdatechange(),
     
    769785                                                ]
    770786                                        },
    771 
    772 
    773                                      
    774 
    775 
    776787                                    ]
    777788
     789                                },
     790                                {
     791                                    type: 'panel',
     792                                    title: yamap_object.ClusterTab || 'Clustering',
     793                                    items: [
     794                                        {
     795                                            type: 'form',
     796                                            name: 'formCluster',
     797                                            minWidth : 598,
     798                                            items: [
     799                                                {
     800                                                    type: 'checkbox',
     801                                                    checked: checkParam('cluster'),
     802                                                    name: 'cluster',
     803                                                    label: yamap_object.ClusterEnable || 'Enable clustering',
     804                                                    id: 'cluster',
     805                                                    onaction: mapdatechange(),
     806                                                },
     807                                                {
     808                                                    type: 'textbox',
     809                                                    name: 'clustergrid',
     810                                                    label: yamap_object.ClusterGrid || 'Cluster grid size (px)',
     811                                                    id: 'clustergrid',
     812                                                    value: ym[mapselector].clustergrid || '64',
     813                                                    maxLength: '4',
     814                                                    tooltip: '2, 4, 8, 16, 32, 64, 128, 256',
     815                                                    onaction: mapdatechange(),
     816                                                },
     817                                                {
     818                                                    type   : 'container',
     819                                                    name   : 'clusterinfo',
     820                                                    minWidth : 598,   
     821                                                    html   : '<div style="padding: 10px 0; color: #666;">' + (yamap_object.ClusterInfo || 'Clustering groups nearby markers into clusters.<br>The grid size determines how close markers need to be to form a cluster.') + '</div>'
     822                                                },
     823                                            ]
     824                                        },
     825                                    ]
    778826                                },
    779827                                {
     
    783831                                        {
    784832                                            type: 'form',
    785                                             name: 'form2',
     833                                            name: 'form3',
    786834                                            minWidth : 598,
    787835
     
    797845                                                ]
    798846                                        },
    799 
    800 
    801                                      
    802 
    803 
    804847                                    ]
    805848
    806                                 }//,
    807                                 //{
    808                                 //    type: 'panel',
    809                                 //    title: '🦉\u00A0' + yamap_object.DeveloperInfoTab,
    810                                 //    items: [
    811                                 //        {
    812                                 //            type: 'form',
    813                                 //            name: 'form2',
    814                                 //            minWidth : 598,
    815 
    816                                 //            items: [
    817                                 //                {
    818                                 //                type   : 'container',
    819                                 //                name   : 'addcontrol',
    820                                                                        
    821                                 //                minWidth : 598,   
    822                                 //                html   : yamap_object.DeveloperInfo,
    823                                 //            },
    824                                                
    825                                 //                ]
    826                                 //        },
    827 
    828 
    829                                      
    830 
    831 
    832                                 //    ]
    833 
    834                                 //}
    835                                
     849                                }
    836850
    837851                            ]
     
    879893                            if (ym[mapselector].scrollzoom==="0") mapArgs.attrs.scrollzoom=ym[mapselector].scrollzoom;
    880894                            if (ym[mapselector].mobiledrag==="0") mapArgs.attrs.mobiledrag=ym[mapselector].mobiledrag;
     895                            if (ym[mapselector].cluster==="1") mapArgs.attrs.cluster=ym[mapselector].cluster;
     896                            if (ym[mapselector].cluster==="1" && ym[mapselector].clustergrid && ym[mapselector].clustergrid!=="64") mapArgs.attrs.clustergrid=ym[mapselector].clustergrid;
    881897                            if (ym[mapselector].controls!=="") mapArgs.attrs.controls=ym[yamapnumber].controls;
    882898                            ed.insertContent( wp.shortcode.string( mapArgs ) );
  • yamaps/trunk/js/shortcode_parser.js

    r3235714 r3412598  
    1 //Парсим шорткод меток внутри карты
     1// Parse placemark shortcodes inside the map
    22function findPlaceMarks(found) {
    33    if (typeof found !== 'string') return;
     
    99            ym['map0'].places['placemark'+j] = {};
    1010            for (var k = 0; k < foundplacemark.length; k++) {
    11                 foundplacemark[k] = foundplacemark[k].split("&amp;").join("&"); //Bugfix: Гутенберг меняет амперсанды на html тэги. Меняем обратно.
     11                // Bugfix: Gutenberg changes ampersands to HTML tags. Change back.
     12                foundplacemark[k] = foundplacemark[k].split("&amp;").join("&");
    1213
    1314                placeparams = foundplacemark[k].split("=");
    14                 if (placeparams.length > 2) { //Bugfix: Если строка в шорткоде содержит знак равества, не теряем ее продолжение при делении на ключ/значение
     15                // Bugfix: If the string in the shortcode contains an equals sign, don't lose its continuation when splitting into key/value
     16                if (placeparams.length > 2) {
    1517                    placeparams[1] = foundplacemark[k].replace(placeparams[0]+"=", "");
    1618                }
    1719                placeparams[1] = placeparams[1].replace(/\"|\'/g, '');
    1820
    19                 // Безопасная обработка URL и координат
     21                // Safe handling of URL and coordinates
    2022                if (placeparams[0] === 'coord') {
    21                     // Валидация координат
     23                    // Coordinate validation
    2224                    var coords = placeparams[1].split(',');
    2325                    if (coords.length === 2) {
     
    2729                            ym['map0'].places['placemark'+j][placeparams[0]] = lat + ',' + lng;
    2830                        } else {
    29                             ym['map0'].places['placemark'+j][placeparams[0]] = '55.7473,37.6247'; // Дефолтные координаты
     31                            ym['map0'].places['placemark'+j][placeparams[0]] = '55.7473,37.6247'; // Default coordinates
    3032                        }
    3133                    } else {
    32                         ym['map0'].places['placemark'+j][placeparams[0]] = '55.7473,37.6247'; // Дефолтные координаты
     34                        ym['map0'].places['placemark'+j][placeparams[0]] = '55.7473,37.6247'; // Default coordinates
    3335                    }
    3436                }
    3537                else if (placeparams[0] === 'url') {
    36                     // Безопасная обработка URL
     38                    // Safe URL handling
    3739                    try {
    3840                        var url = decodeURI(placeparams[1]);
    39                         // Проверяем, является ли значение числом (ID поста)
     41                        // Check if value is a number (post ID)
    4042                        if (!isNaN(url)) {
    4143                            ym['map0'].places['placemark'+j][placeparams[0]] = placeparams[1];
    4244                        } else {
    43                             // Если это URL, кодируем его
     45                            // If it's a URL, encode it
    4446                            ym['map0'].places['placemark'+j][placeparams[0]] = encodeURI(url);
    4547                        }
     
    7072            options.plugin = yamap_object.PluginTitle;
    7173            options.innercontent = this.shortcode.content;
    72             if (typeof ElementorConfig === 'undefined') { //код внутри функции блокирует вставку шорткода в Elementor. Нужно разобраться.
     74            // Code inside function blocks shortcode insertion in Elementor. Need to investigate.
     75            if (typeof ElementorConfig === 'undefined') {
    7376                return this.template(options);
    7477            }
  • yamaps/trunk/options.php

    r3235714 r3412598  
    245245    add_settings_field( 'mobiledrag_map_option', __( 'Mobile drag', 'yamaps' ), 'yamaps_option_display_settings', $yamaps_page, 'map_section', $yamaps_field_params );
    246246
     247    // Checkbox for clustering
     248    $yamaps_field_params = array(
     249        'type'      => 'checkbox',
     250        'id'        => 'cluster_map_option',
     251        'desc'      => __( 'Enable marker clustering by default', 'yamaps' )
     252    );
     253    add_settings_field( 'cluster_map_option', __( 'Clustering', 'yamaps' ), 'yamaps_option_display_settings', $yamaps_page, 'map_section', $yamaps_field_params );
     254
     255    // Cluster grid size field
     256    $yamaps_field_params = array(
     257        'type'      => 'text',
     258        'id'        => 'cluster_grid_option',
     259        'desc'      => __( 'Cluster grid size in pixels (2, 4, 8 ... 64, 128, 256)', 'yamaps' ),
     260        'label_for' => 'cluster_grid_option'
     261    );
     262    add_settings_field( 'cluster_grid_option', __( 'Cluster grid', 'yamaps' ), 'yamaps_option_display_settings', $yamaps_page, 'map_section', $yamaps_field_params );
     263
    247264    // Checkbox for opening a big map
    248265    $yamaps_field_params = array(
     
    328345
    329346    $o = get_option( $option_name );
     347   
     348    // Ensure $o is an array
     349    if ( ! is_array( $o ) ) {
     350        $o = array();
     351    }
    330352
    331353    foreach ($yamaps_defaults_front_bak as $key => $value) {
    332354        if (!isset($o[$key])) {
    333             if (($value=='off')or($value=='on')) {
    334                 $o[$key]=$yamaps_defaults_front_bak[$key];
    335             }
     355            // Set default value for missing keys
     356            $o[$key] = $yamaps_defaults_front_bak[$key];
    336357        }
    337 
    338     }
     358    }
     359
     360    // Ensure the current field exists in options
     361    if ( ! isset( $o[$id] ) ) {
     362        $o[$id] = isset( $yamaps_defaults_front_bak[$id] ) ? $yamaps_defaults_front_bak[$id] : '';
     363    }
     364
    339365    switch ( $type ) { 
    340366        case 'text': 
    341             $o[$id] = esc_attr( stripslashes($o[$id]) );
    342             echo "<input class='regular-text' type='text' id='$id' name='" . $option_name . "[$id]' value='$o[$id]' />"; 
    343             echo ($desc != '') ? "<br /><span class='description'>$desc</span>" : ""; 
     367            $o[$id] = esc_attr( stripslashes( (string) $o[$id] ) );
     368            echo "<input class='regular-text' type='text' id='" . esc_attr($id) . "' name='" . esc_attr($option_name) . "[" . esc_attr($id) . "]' value='" . esc_attr($o[$id]) . "' />"; 
     369            echo ($desc != '') ? "<br /><span class='description'>" . wp_kses_post($desc) . "</span>" : ""; 
    344370        break;
    345371        case 'textarea': 
    346             $o[$id] = esc_attr( stripslashes($o[$id]) );
    347             echo "<textarea class='code large-text' cols='50' rows='2' type='text' id='$id' name='" . $option_name . "[$id]'>$o[$id]</textarea>"; 
    348             echo ($desc != '') ? "<br /><span class='description'>$desc</span>" : ""; 
     372            $o[$id] = esc_attr( stripslashes( (string) $o[$id] ) );
     373            echo "<textarea class='code large-text' cols='50' rows='2' type='text' id='" . esc_attr($id) . "' name='" . esc_attr($option_name) . "[" . esc_attr($id) . "]'>" . esc_textarea($o[$id]) . "</textarea>"; 
     374            echo ($desc != '') ? "<br /><span class='description'>" . wp_kses_post($desc) . "</span>" : ""; 
    349375        break;
    350376        case 'checkbox':
    351             $checked = ($o[$id] == 'on') ? " checked='checked'" :  ''; 
    352             echo "<label><input type='checkbox' id='$id' name='" . $option_name . "[$id]' $checked /> "; 
    353             echo ($desc != '') ? $desc : "";
     377            $checked = ( isset($o[$id]) && $o[$id] == 'on' ) ? " checked='checked'" :  ''; 
     378            echo "<label><input type='checkbox' id='" . esc_attr($id) . "' name='" . esc_attr($option_name) . "[" . esc_attr($id) . "]' $checked /> "; 
     379            echo ($desc != '') ? wp_kses_post($desc) : "";
    354380            echo "</label>"; 
    355381        break;
    356382        case 'select':
    357             echo "<select id='$id' name='" . $option_name . "[$id]'>";
     383            echo "<select id='" . esc_attr($id) . "' name='" . esc_attr($option_name) . "[" . esc_attr($id) . "]'>";
    358384            foreach($vals as $v=>$l){
    359                 $selected = ($o[$id] == $v) ? "selected='selected'" : ''; 
    360                 echo "<option value='$v' $selected>$l</option>";
     385                $selected = ( isset($o[$id]) && $o[$id] == $v ) ? "selected='selected'" : ''; 
     386                echo "<option value='" . esc_attr($v) . "' $selected>" . esc_html($l) . "</option>";
    361387            }
    362             echo ($desc != '') ? $desc : "";
     388            echo ($desc != '') ? wp_kses_post($desc) : "";
    363389            echo "</select>"; 
    364390        break;
     
    366392            echo "<fieldset>";
    367393            foreach($vals as $v=>$l){
    368                 $checked = ($o[$id] == $v) ? "checked='checked'" : ''; 
    369                 echo "<label><input type='radio' name='" . $option_name . "[$id]' value='$v' $checked />$l</label><br />";
     394                $checked = ( isset($o[$id]) && $o[$id] == $v ) ? "checked='checked'" : ''; 
     395                echo "<label><input type='radio' name='" . esc_attr($option_name) . "[" . esc_attr($id) . "]' value='" . esc_attr($v) . "' $checked />" . esc_html($l) . "</label><br />";
    370396            }
    371397            echo "</fieldset>"; 
  • yamaps/trunk/yamap.php

    r3235800 r3412598  
    66 * Author URI:  www.yhunter.ru
    77 * Author:      Yuri Baranov
    8  * Version:     0.6.31
     8 * Version:     0.6.40
    99 *
    1010 *
Note: See TracChangeset for help on using the changeset viewer.