Commit realizado el 12:13:52 08-04-2024

This commit is contained in:
Pagina Web Monito
2024-04-08 12:13:55 -04:00
commit 0c33094de9
7815 changed files with 1365694 additions and 0 deletions

View File

@@ -0,0 +1,122 @@
<?php
/**
* The Address shortcode Class.
*
* @since 1.0.1
* @package RankMath
* @subpackage RankMathPro
* @author Rank Math <support@rankmath.com>
*/
namespace RankMathPro\Local_Seo;
use RankMath\Helper;
defined( 'ABSPATH' ) || exit;
/**
* Address class.
*/
class Address {
/**
* Get Address Data.
*
* @param Location_Shortcode $shortcode Location_Shortcode Instance.
* @param array $schema Array of Schema data.
*
* @return string
*/
public function get_data( $shortcode, $schema ) {
$atts = $shortcode->atts;
$data = $this->get_address( $schema, $atts );
$schema = $schema['metadata'] + $schema;
$labels = [
'telephone' => [
'key' => 'telephone',
'label' => esc_html__( 'Phone', 'rank-math-pro' ),
],
'secondary_number' => [
'key' => 'secondary_number',
'label' => esc_html__( 'Secondary phone', 'rank-math-pro' ),
],
'fax' => [
'key' => 'faxNumber',
'label' => esc_html__( 'Fax', 'rank-math-pro' ),
],
'email' => [
'key' => 'email',
'label' => esc_html__( 'Email', 'rank-math-pro' ),
],
'url' => [
'key' => 'url',
'label' => esc_html__( 'URL', 'rank-math-pro' ),
],
'vat_id' => [
'key' => 'vatID',
'label' => esc_html__( 'VAT ID', 'rank-math-pro' ),
],
'tax_id' => [
'key' => 'taxID',
'label' => esc_html__( 'Tax ID', 'rank-math-pro' ),
],
'coc_id' => [
'key' => 'coc_id',
'label' => esc_html__( 'Chamber of Commerce ID', 'rank-math-pro' ),
],
'priceRange' => [
'key' => 'priceRange',
'label' => esc_html__( 'Price indication', 'rank-math-pro' ),
],
];
foreach ( $labels as $key => $label ) {
if ( empty( $atts[ "show_$key" ] ) || empty( $schema[ $label['key'] ] ) ) {
continue;
}
$value = esc_html( $schema[ $label['key'] ] );
if ( 'email' === $key ) {
$value = '<a href="mailto:' . $value . '">' . $value . '</a>';
}
if ( in_array( $key, [ 'telephone', 'secondary_number' ], true ) ) {
$value = '<a href="tel:' . $value . '">' . $value . '</a>';
}
$data .= '<div><strong>' . $label['label'] . '</strong>: ' . $value . '</div>';
}
return $data;
}
/**
* Get Address Data.
*
* @param array $schema Array of Schema data.
* @param array $atts Shortcode attributes.
*
* @return string
*/
public function get_address( $schema, $atts = [] ) {
$address = array_filter( $schema['address'] );
if ( false === $address || empty( $atts['show_company_address'] ) ) {
return '';
}
$hash = array_filter(
[
'streetAddress' => true,
'addressLocality' => true,
'addressRegion' => ! empty( $atts['show_state'] ),
'addressCountry' => ! empty( $atts['show_country'] ),
'postalCode' => true,
]
);
$glue = empty( $atts['show_on_one_line'] ) ? ',<br />' : ', ';
$data = implode( $glue, array_intersect_key( $address, $hash ) );
return '<h5>' . esc_html__( 'Address:', 'rank-math-pro' ) . '</h5><address>' . $data . '</address>';
}
}

View File

@@ -0,0 +1,119 @@
<?php
/**
* The Map shortcode Class.
*
* @since 1.0.1
* @package RankMath
* @subpackage RankMathPro
* @author Rank Math <support@rankmath.com>
*/
namespace RankMathPro\Local_Seo;
use RankMath\Schema\DB;
defined( 'ABSPATH' ) || exit;
/**
* Map class.
*/
class Map {
/**
* Shortcode Instance.
*
* @var Location_Shortcode
*/
public $shortcode;
/**
* Get Address Data.
*
* @param Location_Shortcode $shortcode Location_Shortcode Instance.
* @param array $locations Locations data.
* @return string
*/
public function get_data( $shortcode, $locations ) {
$this->shortcode = $shortcode;
$atts = $shortcode->atts;
$options = [
'map_style' => $atts['map_style'],
'allow_zoom' => $atts['allow_zoom'],
'zoom_level' => $atts['zoom_level'],
'allow_dragging' => $atts['allow_dragging'],
'show_clustering' => $atts['show_marker_clustering'],
'show_infowindow' => $atts['show_infowindow'],
];
$terms_data = [];
foreach ( $locations as $location ) {
$schema = DB::get_schemas( $location->ID );
if ( empty( $schema ) ) {
continue;
}
$schema = current( $shortcode->replace_variables( $schema ) );
if ( empty( $schema['geo']['latitude'] ) || empty( $schema['geo']['longitude'] ) ) {
continue;
}
$options['locations'][ $location->ID ] = [
'content' => $this->get_infobox_content( $location->ID, $schema ),
'lat' => $schema['geo']['latitude'],
'lng' => $schema['geo']['longitude'],
];
if ( ! empty( $atts['show_category_filter'] ) && 'map' === $atts['type'] ) {
$terms = get_the_terms( $location->ID, 'rank_math_location_category' );
if ( ! is_wp_error( $terms ) && ! empty( $terms ) ) {
$terms_data = array_merge( $terms_data, $terms );
$options['locations'][ $location->ID ]['terms'] = wp_list_pluck( $terms, 'term_id' );
}
}
}
if ( empty( $options['locations'] ) ) {
return;
}
wp_enqueue_script( 'rank-math-local' );
$width = ! empty( $atts['map_width'] ) ? $atts['map_width'] : '100%';
$height = ! empty( $atts['map_height'] ) ? $atts['map_height'] : '500px';
$style = sprintf( 'style="width: %s; height: %s"', $width, $height );
ob_start();
?>
<div class="rank-math-local-map-wrapper">
<div class="rank-math-local-map" data-map-options="<?php echo esc_attr( wp_json_encode( $options ) ); ?>" <?php printf( 'style="width: %s; height: %s"', esc_attr( $width ), esc_attr( $height ) ); ?>></div>
<?php
if ( ! empty( $terms_data ) ) {
echo '<select id="rank-math-select-category">';
echo '<option value="">' . esc_html__( 'Select Category', 'rank-math-pro' ) . '</option>';
foreach ( $terms_data as $term ) {
echo '<option value="' . esc_attr( $term->term_id ) . '">' . esc_html( $term->name ) . '</option>';
}
echo '</select>';
}
?>
</div>
<?php
return ob_get_clean();
}
/**
* Get Infobox Content.
*
* @param int $location_id The Location ID.
* @param array $schema Schema Data.
* @return string
*/
public function get_infobox_content( $location_id, $schema ) {
return '<div class="rank-math-infobox-wrapper">
<h5><a href="' . esc_url( get_the_permalink( $location_id ) ) . '">' . esc_html( get_the_title( $location_id ) ) . '</a></h5>
<p>' . $this->shortcode->address->get_data( $this->shortcode, $schema ) . '</p>
</div>';
}
}

View File

@@ -0,0 +1,158 @@
<?php
/**
* The Opening Hours shortcode Class.
*
* @since 1.0.1
* @package RankMath
* @subpackage RankMathPro
* @author Rank Math <support@rankmath.com>
*/
namespace RankMathPro\Local_Seo;
use RankMath\Helper;
defined( 'ABSPATH' ) || exit;
/**
* Opening_Hours class.
*/
class Opening_Hours {
/**
* Get Opening_Hours Data.
*
* @param Location_Shortcode $shortcode Location_Shortcode Instance.
* @param array $schema Schema data.
* @return string
*/
public function get_data( $shortcode, $schema ) {
if ( ! isset( $schema['openingHoursSpecification'] ) ) {
return '<p>' . esc_html__( 'Open 24/7', 'rank-math-pro' ) . '</p>';
}
if ( empty( $schema['openingHoursSpecification'] ) ) {
return false;
}
$days = $this->normalize_days( $schema, $shortcode );
ob_start();
?>
<h5><?php esc_html_e( 'Opening Hours:', 'rank-math-pro' ); ?></h5>
<div class="rank-math-business-opening-hours">
<?php
foreach ( $days as $day => $hours ) {
$time = ! empty( $hours['time'] ) ? implode( ' and ', $hours['time'] ) : esc_html__( 'Closed', 'rank-math-pro' );
$time = str_replace( '-', ' &ndash; ', $time );
printf(
'<div class="rank-math-opening-hours"><span class="rank-math-opening-days">%1$s</span> : <span class="rank-math-opening-time">%2$s</span> <span class="rank-math-business-open">%3$s</span></div>',
esc_html( $this->get_localized_day( $day ) ),
esc_html( $time ),
esc_html( $hours['isOpen'] )
);
}
?>
</div>
<?php
return ob_get_clean();
}
/**
* Get Local Time.
*
* @param Location_Shortcode $shortcode Location_Shortcode Instance.
* @param array $schema Schema data.
* @return string
*/
private function get_local_time( $shortcode, $schema ) {
if ( empty( $shortcode->atts['show_opening_now_label'] ) ) {
return false;
}
$timezone = ! empty( $schema['metadata']['timeZone'] ) ? $schema['metadata']['timeZone'] : wp_timezone_string();
$local_datetime = new \DateTime( 'now', new \DateTimeZone( $timezone ) );
return [
'day' => $local_datetime->format( 'l' ),
'time' => strtotime( $local_datetime->format( 'H:i' ) ),
];
}
/**
* Normalize Weekdays.
*
* @param array $schema Schema data.
* @param Location_Shortcode $shortcode Location_Shortcode Instance.
* @return array
*/
private function normalize_days( $schema, $shortcode ) {
$hours = $schema['openingHoursSpecification'];
$days = explode( ',', $shortcode->atts['show_days'] );
$format = ! isset( $schema['metadata']['use_24h_format'] ) ? Helper::get_settings( 'titles.opening_hours_format' ) : empty( $schema['metadata']['use_24h_format'] );
$data = [];
$local_time = $this->get_local_time( $shortcode, $schema );
foreach ( $days as $day ) {
$day = ucfirst( trim( $day ) );
$data[ $day ] = [
'isOpen' => '',
];
foreach ( $hours as $hour ) {
if ( ! in_array( $day, (array) $hour['dayOfWeek'], true ) ) {
continue;
}
$open = strtotime( $hour['opens'] );
$close = strtotime( $hour['closes'] );
$is_open = ! empty( $local_time ) &&
$day === $local_time['day'] &&
$local_time['time'] >= $open &&
$local_time['time'] <= $close;
$data[ $day ]['time'][] = $format ? date_i18n( 'g:i a', $open ) . ' - ' . date_i18n( 'g:i a', $close ) : $hour['opens'] . ' - ' . $hour['closes'];
$data[ $day ]['isOpen'] = $is_open ? $this->get_opening_hours_note( $shortcode ) : '';
}
if ( $shortcode->atts['hide_closed_days'] && empty( $data[ $day ]['time'] ) ) {
unset( $data[ $day ] );
}
}
return $data;
}
/**
* Get Opening Hours note.
*
* @param Location_Shortcode $shortcode Location_Shortcode Instance.
* @return string
*/
private function get_opening_hours_note( $shortcode ) {
return empty( $shortcode->atts['opening_hours_note'] ) ? esc_html__( 'Open now', 'rank-math-pro' ) : esc_html( $shortcode->atts['opening_hours_note'] );
}
/**
* Retrieve the full translated weekday word.
*
* @param string $day Day to translate.
*
* @return string
*/
private function get_localized_day( $day ) {
global $wp_locale;
$hash = [
'Sunday' => 0,
'Monday' => 1,
'Tuesday' => 2,
'Wednesday' => 3,
'Thursday' => 4,
'Friday' => 5,
'Saturday' => 6,
];
return ! isset( $hash[ $day ] ) ? $day : $wp_locale->get_weekday( $hash[ $day ] );
}
}

View File

@@ -0,0 +1,232 @@
<?php
/**
* The Store Locator shortcode Class.
*
* @since 1.0.1
* @package RankMath
* @subpackage RankMathPro
* @author Rank Math <support@rankmath.com>
*/
namespace RankMathPro\Local_Seo;
use RankMath\Helper;
use RankMath\Post;
use RankMath\Schema\DB;
use MyThemeShop\Helpers\Param;
defined( 'ABSPATH' ) || exit;
/**
* Store_Locator class.
*/
class Store_Locator {
/**
* Get Store_Locator Data.
*
* @param Location_Shortcode $shortcode Location_Shortcode Instance.
* @return string
*/
public function get_data( $shortcode ) {
$unit = 'miles' === Helper::get_settings( 'titles.map_unit', 'kilometers' ) ? 'mi' : 'km';
$radius = Param::post( 'rank-math-search-radius', 20 );
$address = Param::post( 'rank-math-search-address' );
$category = Param::post( 'rank-math-location-category' );
$terms = empty( $shortcode->atts['show_category_filter'] )
? []
: get_terms(
[
'taxonomy' => 'rank_math_location_category',
'fields' => 'id=>name',
]
);
wp_enqueue_script( 'rank-math-local' );
ob_start();
?>
<div class="rank-math-business-wrapper">
<form id="rank-math-local-store-locator" method="post" action="#rank-math-local-store-locator">
<?php if ( ! empty( $shortcode->atts['show_radius'] ) ) { ?>
<div class="rank-math-form-field">
<select name="rank-math-search-radius">
<?php
foreach ( [ 1, 5, 10, 20, 40, 50, 75, 100, 200, 300, 400, 500, 1000 ] as $value ) {
echo "<option value='{$value}' " . selected( $radius, $value, true ) . ">{$value}{$unit}</option>";
}
?>
</select>
</div>
<?php } ?>
<?php if ( ! empty( $terms ) ) { ?>
<div class="rank-math-form-field">
<select name="rank-math-location-category">
<option value=""><?php echo esc_html__( 'Select Category', 'rank-math-pro' ); ?></option>
<?php foreach ( $terms as $term_id => $term_name ) { ?>
<option value="<?php echo esc_attr( $term_id ); ?>" <?php selected( $category, $term_id ); ?>><?php echo esc_html( $term_name ); ?></option>
<?php } ?>
</select>
</div>
<?php } ?>
<div class="rank-math-form-field">
<input type="text" name="rank-math-search-address" id="rank-math-search-address" placeholder="<?php echo esc_html__( 'Address, Suburb, Region, Zip or Landmark', 'rank-math-pro' ); ?>" value="<?php echo esc_attr( $address ); ?>" />
<input type="hidden" name="lat" id="rank-math-lat" />
<input type="hidden" name="lng" id="rank-math-lng" />
</div>
<?php $this->detect_location(); ?>
<div class="rank-math-form-field">
<button type="submit" name="rank-math-submit" value="search"><?php echo esc_html__( 'Search', 'rank-math-pro' ); ?></button>
</div>
</form>
<?php
echo $this->get_results( $shortcode, $unit );
echo '</div>';
return ob_get_clean();
}
/**
* Add detect current location button.
*
* @return string
*/
private function detect_location() {
if ( ! Helper::get_settings( 'titles.enable_location_detection' ) ) {
return;
}
echo '<a href="#" id="rank-math-current-location">' . esc_html__( 'Detect Location', 'rank-math-pro' ) . '</a>';
}
/**
* Get Map Results.
*
* @param Location_Shortcode $shortcode Location_Shortcode Instance.
* @param string $unit Map measurement unit.
* @return string
*/
private function get_results( $shortcode, $unit ) {
if ( ! Param::post( 'rank-math-search-address' ) ) {
return false;
}
global $wpdb;
// Radius of the earth 3959 miles or 6371 kilometers.
$earth_radius = 'mi' === $unit ? 3959 : 6371;
$radius = ! empty( $shortcode->atts['show_radius'] ) ? Param::post( 'rank-math-search-radius', 20 ) : $shortcode->atts['search_radius'];
$latitude = Param::post( 'lat' );
$longitude = Param::post( 'lng' );
$category = Param::post( 'rank-math-location-category', 0, FILTER_VALIDATE_INT );
$inner_join = '';
if ( $category ) {
$inner_join .= $wpdb->prepare(
"INNER JOIN $wpdb->term_relationships AS tr ON p.ID = tr.object_id
INNER JOIN $wpdb->term_taxonomy AS tt ON tr.term_taxonomy_id = tt.term_taxonomy_id
AND tt.taxonomy = 'rank_math_location_category'
AND tt.term_id = %d",
$category
);
}
$nearby_locations = $wpdb->get_results(
$wpdb->prepare(
"SELECT DISTINCT
p.*,
map_lat.meta_value as locLat,
map_lng.meta_value as locLong,
( %d * acos(
cos( radians( %s ) )
* cos( radians( map_lat.meta_value ) )
* cos( radians( map_lng.meta_value ) - radians( %s ) )
+ sin( radians( %s ) )
* sin( radians( map_lat.meta_value ) )
) )
AS distance
FROM $wpdb->posts p
INNER JOIN $wpdb->postmeta map_lat ON p.ID = map_lat.post_id
INNER JOIN $wpdb->postmeta map_lng ON p.ID = map_lng.post_id
$inner_join
WHERE 1 = 1
AND p.post_type = 'rank_math_locations'
AND p.post_status = 'publish'
AND map_lat.meta_key = 'rank_math_local_business_latitide'
AND map_lng.meta_key = 'rank_math_local_business_longitude'
HAVING distance < %s
ORDER BY distance ASC",
$earth_radius,
$latitude,
$longitude,
$latitude,
$radius
)
);
//phpcs:enable
if ( empty( $nearby_locations ) ) {
return esc_html__( 'Sorry, no locations were found.', 'rank-math-pro' );
}
$data = ! empty( $shortcode->atts['show_map'] ) ? $shortcode->map->get_data( $shortcode, $nearby_locations ) : '';
foreach ( $nearby_locations as $location ) {
$schema = DB::get_schemas( $location->ID );
if ( empty( $schema ) ) {
continue;
}
$schema = current( $shortcode->replace_variables( $schema, $location ) );
$data .= $shortcode->get_title( $schema );
$data .= $shortcode->address->get_data( $shortcode, $schema );
$data .= ! empty( $shortcode->atts['show_opening_hours'] ) ? $shortcode->opening_hours->get_data( $shortcode, $schema ) : '';
$data .= $this->get_directions( $location, $shortcode );
}
return $data;
}
/**
* Get Map Results.
*
* @param Object $location Current Location Post.
* @param Location_Shortcode $shortcode Location_Shortcode Instance.
* @return string
*/
public function get_directions( $location, $shortcode ) {
if ( empty( $shortcode->atts['show_route_planner'] ) || empty( $shortcode->atts['show_map'] ) ) {
return '';
}
$lat = Post::get_meta( 'local_business_latitide', $location->ID );
$lng = Post::get_meta( 'local_business_longitude', $location->ID );
ob_start();
?>
<div class="rank-math-directions-wrapper">
<a href="#" class="rank-math-show-route" data-toggle-text="<?php echo esc_html__( 'Hide route', 'rank-math-pro' ); ?>">
<?php echo esc_html( $shortcode->atts['route_label'] ); ?>
</a>
<div class="rank-math-directions-result">
<h3><?php echo esc_html__( 'Route', 'rank-math-pro' ); ?></h3>
<div class="rank-math-directions-form">
<form method="post">
<div class="rank-math-form-field">
<label for="origin"><?php echo esc_html__( 'Your location:', 'rank-math-pro' ); ?></label>
<input type="text" name="origin" id="rank-math-origin" value="<?php echo esc_attr( Param::post( 'rank-math-search-address' ) ); ?>" />
<input type="submit" name="get-direction" value="<?php echo esc_html__( 'Show route', 'rank-math-pro' ); ?>" />
<input type="hidden" name="rank-math-lat" id="rank-math-lat" value="<?php echo esc_attr( $lat ); ?>" />
<input type="hidden" name="rank-math-lng" id="rank-math-lng" value="<?php echo esc_attr( $lng ); ?>" />
</div>
</form>
</div>
<div class="rank-math-directions"></div>
</div>
</div>
<?php
return ob_get_clean();
}
}