Skip to content

Commit

Permalink
Merge pull request #2673 from kprajapatii/master
Browse files Browse the repository at this point in the history
Add alt text to OSM marker icon if alt text saved in media - CHANGED
  • Loading branch information
kprajapatii authored Sep 4, 2024
2 parents ba9d254 + 70cc260 commit 1f1e75f
Show file tree
Hide file tree
Showing 11 changed files with 88 additions and 9 deletions.
4 changes: 4 additions & 0 deletions assets/aui/js/map.js
Original file line number Diff line number Diff line change
Expand Up @@ -609,6 +609,9 @@ function list_markers(json, map_canvas_var, animation) {
marker['icon'] = icon_url;
marker['w'] = icon['w'];
marker['h'] = icon['h'];
if ( icon['a'] ) {
marker['alt'] = icon['a'];
}
}
}
if (marker && !marker.animation && animation) {
Expand Down Expand Up @@ -1439,6 +1442,7 @@ function create_marker_osm(item, map_canvas) {
var marker = jQuery.goMap.createMarker({
id: marker_id,
title: title,
alt: item.alt ? geodir_htmlEscape(item.alt) : '',
position: coord,
visible: true,
clickable: true,
Expand Down
2 changes: 1 addition & 1 deletion assets/aui/js/map.min.js

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions assets/js/goMap.js
Original file line number Diff line number Diff line change
Expand Up @@ -559,6 +559,9 @@ function geodirGoMapInit() {
if (marker.title)
options.title = marker.title;

if (marker.alt)
options.alt = marker.alt;

if (marker.label)
options.label = marker.label;

Expand Down
2 changes: 1 addition & 1 deletion assets/js/goMap.min.js

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions assets/js/map.js
Original file line number Diff line number Diff line change
Expand Up @@ -568,6 +568,9 @@ function list_markers(json, map_canvas_var) {
marker['icon'] = icon_url;
marker['w'] = icon['w'];
marker['h'] = icon['h'];
if ( icon['a'] ) {
marker['alt'] = icon['a'];
}
}
}
if (map_options.map_type == 'post' && i == 0) {
Expand Down Expand Up @@ -1328,6 +1331,7 @@ function create_marker_osm(item, map_canvas) {
var marker = jQuery.goMap.createMarker({
id: marker_id,
title: title,
alt: item.alt ? geodir_htmlEscape(item.alt) : '',
position: coord,
visible: true,
clickable: true,
Expand Down
2 changes: 1 addition & 1 deletion assets/js/map.min.js

Large diffs are not rendered by default.

45 changes: 45 additions & 0 deletions includes/admin/class-geodir-admin-taxonomies.php
Original file line number Diff line number Diff line change
Expand Up @@ -1172,6 +1172,51 @@ public static function get_cat_icon( $term_id, $full_path = false, $default = fa
return apply_filters( 'geodir_get_cat_icon', $cat_icon, $term_id, $full_path, $default );
}

/**
* Get the category icon alt text.
*
* @since 2.3.76
*
* @param int $term_id Category ID.
* @param string|bool $default Default alt text. Default false.
* @return string Icon alt text.
*/
public static function get_cat_icon_alt( $term_id, $default = false ) {
global $geodir_cat_icon_alt;

if ( ! is_array( $geodir_cat_icon_alt ) ) {
$geodir_cat_icon_alt = array();
}

if ( isset( $geodir_cat_icon_alt[ $term_id ] ) ) {
return $geodir_cat_icon_alt[ $term_id ];
}

$alt = '';
$attachment_id = 0;

if ( ! empty( $term_id ) && $term_id != 'd' && $term_id > 0 ) {
$term_meta = get_term_meta( $term_id, 'ct_cat_icon', true );

$attachment_id = is_array( $term_meta ) && ! empty( $term_meta['id'] ) ? absint( $term_meta['id'] ) : 0;
$alt = $attachment_id > 0 ? get_post_meta( $attachment_id, '_wp_attachment_image_alt', true ) : '';

if ( $alt ) {
$alt = trim( strip_tags( $alt ) );
}
}

// Default alt text.
if ( $alt == '' && $default != false && is_scalar( $default ) ) {
$alt = $default;
}

$alt = apply_filters( 'geodir_get_cat_icon_alt', $alt, $term_id, $default, $attachment_id );

$geodir_cat_icon_alt[ $term_id ] = $alt;

return $alt;
}

/**
* Fires after a new term is created or term updated.
Expand Down
11 changes: 10 additions & 1 deletion includes/api/class-geodir-rest-markers-controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -399,11 +399,20 @@ public function prepare_item_for_response( $item, $request ) {
}
}

$geodir_rest_cache_icons[ $icon_id ] = array(
$_item = array(
'i' => $icon_url,
'w' => $icon_width,
'h' => $icon_height
);

// Icon alt text.
$alt = geodir_get_cat_icon_alt( $icon_id );

if ( $alt != '' ) {
$_item['a'] = $alt;
}

$geodir_rest_cache_icons[ $icon_id ] = $_item;
}
$response['i'] = $icon_id;

Expand Down
10 changes: 5 additions & 5 deletions includes/class-geodir-maps.php
Original file line number Diff line number Diff line change
Expand Up @@ -465,9 +465,10 @@ public static function get_categories_filter( $post_type, $cat_parent = 0, $hide
$term_check = '<input type="checkbox" ' . $checked . ' id="' .$map_canvas.'_tick_cat_'. $cat_term->term_id . '" class="group_selector ' . $main_list_class . '"';
$term_check .= ' name="' . $map_canvas . '_cat[]" ';
$term_check .= ' title="' . esc_attr(geodir_utf8_ucfirst($cat_term->name)) . '" value="' . $cat_term->term_id . '" onclick="javascript:build_map_ajax_search_param(\'' . $map_canvas . '\',false, this)">';
$icon_alt = geodir_get_cat_icon_alt( $cat_term->term_id, geodir_strtolower( $cat_term->name ) . '.' );

if($design_style){
$term_img = '<img class="w-auto mr-1 ml-n1 me-1 ms-n1 rounded-circle" style="height:22px;" alt="' . esc_attr( geodir_strtolower( $cat_term->name ) ) . '." src="' . $icon . '" title="' . geodir_utf8_ucfirst($cat_term->name) . '" loading=lazy />';
if ( $design_style ) {
$term_img = '<img class="w-auto mr-1 ml-n1 me-1 ms-n1 rounded-circle" style="height:22px;" alt="' . esc_attr( $icon_alt ) . '" src="' . $icon . '" title="' . geodir_utf8_ucfirst($cat_term->name) . '" loading=lazy />';
$term_html = '<li class="'.$li_class.'">' .aui()->input(
array(
'id' => "{$map_canvas}_tick_cat_{$cat_term->term_id}",
Expand All @@ -484,9 +485,8 @@ public static function get_categories_filter( $post_type, $cat_parent = 0, $hide
),
)
);

}else{
$term_img = '<img height="15" width="15" alt="' . $cat_term->taxonomy . '" src="' . $icon . '" title="' . geodir_utf8_ucfirst($cat_term->name) . '" loading=lazy />';
} else {
$term_img = '<img height="15" width="15" alt="' . esc_attr( $icon_alt ) . '" src="' . $icon . '" title="' . geodir_utf8_ucfirst($cat_term->name) . '" loading=lazy />';

$term_html = '<li class="'.$li_class.'">' . $term_check . '<label for="' . $map_canvas.'_tick_cat_'. $cat_term->term_id . '">' . $term_img . geodir_utf8_ucfirst($cat_term->name) . '</label><span class="gd-map-cat-toggle"><i class="fas fa-long-arrow-alt-down" aria-hidden="true" style="display:none"></i></span>';
}
Expand Down
13 changes: 13 additions & 0 deletions includes/taxonomy-functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -625,6 +625,19 @@ function geodir_get_cat_icon( $term_id, $full_path = false, $default = false ) {
return GeoDir_Admin_Taxonomies::get_cat_icon($term_id,$full_path ,$default);
}

/**
* Get the category icon alt text.
*
* @since 2.3.76
*
* @param int $term_id Category ID.
* @param string|bool $default Default alt text. Default false.
* @return string Alt text.
*/
function geodir_get_cat_icon_alt( $term_id, $default = false ) {
return GeoDir_Admin_Taxonomies::get_cat_icon_alt( $term_id, $default );
}

/**
* Get the category default image.
*
Expand Down
1 change: 1 addition & 0 deletions readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -321,6 +321,7 @@ __WARNING: GDv2 is a significant update over GDv1 and may require manual work, s

= GeoDirectory v2.3.76 - TBD =
* GD > Post Features shows error when tag does not exists - FIXED
* Add alt text to OSM marker icon if alt text saved in media - CHANGED

= GeoDirectory v2.3.75 - 2024-08-29 =
* In some cases SVG icon as map marker is not working on FireFox - FIXED
Expand Down

0 comments on commit 1f1e75f

Please sign in to comment.