/** * Opening hours shortcode handler * * @since 0.1 * * @param array $atts Array of shortcode parameters * * @param bool $show_schema choose to show schema.org HTMl or not * * @return string */ function wpseo_local_show_opening_hours($atts, $show_schema = true) { $atts = wpseo_check_falses(shortcode_atts(array('id' => '', 'hide_closed' => false, 'echo' => false, 'comment' => ''), $atts)); $options = get_option('wpseo_local'); if (isset($options['hide_opening_hours']) && $options['hide_opening_hours'] == 'on') { return false; } if (wpseo_has_multiple_locations()) { if (get_post_type() == 'wpseo_locations') { if (($atts['id'] == '' || $atts['id'] == 'current') && !is_post_type_archive()) { $atts['id'] = get_queried_object_id(); } if (is_post_type_archive() && ($atts['id'] == '' || $atts['id'] == 'current')) { return ''; } } } else { $atts['id'] = ''; } $options = get_option('wpseo_local'); $days = array('monday' => __('Monday', 'yoast-local-seo'), 'tuesday' => __('Tuesday', 'yoast-local-seo'), 'wednesday' => __('Wednesday', 'yoast-local-seo'), 'thursday' => __('Thursday', 'yoast-local-seo'), 'friday' => __('Friday', 'yoast-local-seo'), 'saturday' => __('Saturday', 'yoast-local-seo'), 'sunday' => __('Sunday', 'yoast-local-seo')); $output = '<table class="wpseo-opening-hours">'; foreach ($days as $key => $day) { $multiple_opening_hours = isset($options['multiple_opening_hours']) && $options['multiple_opening_hours'] == 'on'; $day_abbr = ucfirst(substr($key, 0, 2)); if (wpseo_has_multiple_locations()) { $field_name = '_wpseo_opening_hours_' . $key; $value_from = get_post_meta($atts['id'], $field_name . '_from', true); $value_to = get_post_meta($atts['id'], $field_name . '_to', true); $value_second_from = get_post_meta($atts['id'], $field_name . '_second_from', true); $value_second_to = get_post_meta($atts['id'], $field_name . '_second_to', true); $multiple_opening_hours = get_post_meta($atts['id'], '_wpseo_multiple_opening_hours', true); $multiple_opening_hours = !empty($multiple_opening_hours); } else { $field_name = 'opening_hours_' . $key; $value_from = isset($options[$field_name . '_from']) ? esc_attr($options[$field_name . '_from']) : ''; $value_to = isset($options[$field_name . '_to']) ? esc_attr($options[$field_name . '_to']) : ''; $value_second_from = isset($options[$field_name . '_second_from']) ? esc_attr($options[$field_name . '_second_from']) : ''; $value_second_to = isset($options[$field_name . '_second_to']) ? esc_attr($options[$field_name . '_second_to']) : ''; } if ($value_from == 'closed' && $atts['hide_closed']) { continue; } $value_from_formatted = $value_from; $value_to_formatted = $value_to; $value_second_from_formatted = $value_second_from; $value_second_to_formatted = $value_second_to; if (!isset($options['opening_hours_24h']) || $options['opening_hours_24h'] != 'on') { $value_from_formatted = date('g:i A', strtotime($value_from)); $value_to_formatted = date('g:i A', strtotime($value_to)); $value_second_from_formatted = date('g:i A', strtotime($value_second_from)); $value_second_to_formatted = date('g:i A', strtotime($value_second_to)); } $output .= '<tr>'; $output .= '<td class="day">' . $day . ' </td>'; $output .= '<td class="time">'; $output_time = ''; if ($value_from != 'closed' && $value_to != 'closed') { $output_time .= '<time ' . ($show_schema ? 'itemprop="openingHours"' : '') . ' content="' . $day_abbr . ' ' . $value_from . '-' . $value_to . '">' . $value_from_formatted . ' - ' . $value_to_formatted . '</time>'; } else { $output_time .= __('Closed', 'yoast-local-seo'); } if ($multiple_opening_hours) { if ($value_from != 'closed' && $value_to != 'closed' && $value_second_from != 'closed' && $value_second_to != 'closed') { $output_time .= '<span class="openingHoursAnd"> ' . __('and', 'yoast-local-seo') . ' </span> '; $output_time .= '<time ' . ($show_schema ? 'itemprop="openingHours"' : '') . ' content="' . $day_abbr . ' ' . $value_second_from . '-' . $value_second_to . '">' . $value_second_from_formatted . ' - ' . $value_second_to_formatted . '</time>'; } else { $output_time .= ''; } } $output_time = apply_filters('wpseo_opening_hours_time', $output_time, $day, $value_from, $value_to); $output .= $output_time; $output .= '</td>'; $output .= '</tr>'; } $output .= '</table>'; if ($atts['comment'] != '') { $output .= '<div class="wpseo-extra-comment">' . wpautop(html_entity_decode($atts['comment'])) . '</div>'; } if ($atts['echo']) { echo $output; } return $output; }
function show_storelocator($atts) { global $wpseo_enqueue_geocoder, $wpseo_sl_load_scripts; $wpseo_sl_load_scripts = true; $options = get_option('wpseo_local'); $atts = wpseo_check_falses(shortcode_atts(array('radius' => 10, 'show_radius' => false, 'show_nearest_suggestion' => true, 'show_map' => true, 'show_filter' => false, 'map_width' => '100%', 'scrollable' => true, 'show_country' => false, 'show_state' => false, 'show_phone' => false, 'show_phone_2' => false, 'show_fax' => false, 'show_email' => false, 'show_url' => false, 'map_style' => isset($options['map_view_style']) ? $options['map_view_style'] : 'ROADMAP', 'show_route_label' => isset($options['show_route_label']) && !empty($options['show_route_label']) ? $options['show_route_label'] : __('Show route', 'yoast-local-seo'), 'oneline' => false, 'show_opening_hours' => false, 'hide_closed' => false, 'from_widget' => false, 'widget_title' => '', 'before_title' => '', 'after_title' => '', 'echo' => false), $atts)); if ($atts['show_map']) { $wpseo_enqueue_geocoder = true; } ob_start(); ?> <form action="" method="post" id="wpseo-storelocator-form"> <fieldset> <?php $search_string = isset($_REQUEST['wpseo-sl-search']) ? esc_attr($_REQUEST['wpseo-sl-search']) : ''; $sl_category_term = !empty($_REQUEST['wpseo-sl-category']) ? $_REQUEST['wpseo-sl-category'] : ''; ?> <p> <label for="wpseo-sl-search"><?php _e('Enter your postal code or city', 'yoast-local-seo'); ?> </label> <input type="text" name="wpseo-sl-search" id="wpseo-sl-search" value="<?php echo $search_string; ?> "> <?php if ($atts['show_radius']) { ?> <?php _e('within', 'yoast-local-seo'); ?> <select name="wpseo-sl-radius" id="wpseo-sl-radius"> <?php $radius_array = array(1, 5, 10, 25, 50, 100, 250, 500, 1000); $selected_radius = !empty($_REQUEST['wpseo-sl-radius']) ? esc_attr($_REQUEST['wpseo-sl-radius']) : $atts['radius']; ?> <?php foreach ($radius_array as $radius) { echo '<option value="' . $radius . '" ' . selected($selected_radius, $radius, false) . '>' . $radius . ($this->options['unit_system'] == 'METRIC' ? 'km' : 'mi') . '</option>'; } ?> </select> <?php } else { ?> <input type="hidden" name="wpseo-sl-radius" id="wpseo-sl-radius-text" value="<?php echo esc_attr($atts['radius']); ?> "> <?php } ?> </p> <?php if ($atts['show_filter']) { ?> <?php $terms = get_terms('wpseo_locations_category'); ?> <?php if (count($terms) > 0) { ?> <p class="sl-filter"> <label for="wpseo-sl-category"><?php _e('Filter by category', 'yoast-local-seo'); ?> </label> <select name="wpseo-sl-category" id="wpseo-sl-category"> <option value=""></option> <?php foreach ($terms as $term) { echo '<option value="' . $term->term_id . '" ' . selected($sl_category_term, $term->term_id, false) . '>' . $term->name . '</option>'; } ?> </select> </p> <?php } ?> <?php } ?> <p class="sl-submit"> <input type="submit" value="<?php _e('Search', 'yoast-local-seo'); ?> "> </p> </fieldset> </form> <div id="wpseo-storelocator-results"> <?php if (false === empty($_POST)) { $results = $this->get_results(); } if ($atts['show_map']) { echo wpseo_local_show_map(array('id' => !empty($_POST) && !is_wp_error($results) ? implode(',', $results['locations']) : 'all', 'width' => $atts['map_width'], 'from_sl' => true, 'show_route' => true, 'scrollable' => $atts['scrollable'], 'map_style' => $atts['map_style'])); } if (false == empty($_POST)) { if (!is_wp_error($results)) { $show_suggestion = $results['in_radius'] <= 0 && true === $atts['show_nearest_suggestion'] && !empty($results['locations']); if ($results['in_radius'] > 0) { echo '<h2>' . sprintf(__('%s results have been found', 'yoast-local-seo'), count($results['locations'])) . '</h2>'; foreach ($results['locations'] as $distance => $location_id) { $this->get_location_details($location_id, $atts); } } else { echo '<h2>' . __('No results found', 'yoast-local-seo') . '</h2>'; if ($show_suggestion) { foreach ($results['locations'] as $distance => $location_id) { $text_mi = sprintf(__('The nearest location is %s miles away', 'yoast-local-seo'), $distance); $text_km = sprintf(__('The nearest location is %s kilometers away', 'yoast-local-seo'), $distance); echo '<p class="nearest_location">' . apply_filters('wpso_local_no_stores_in_radius', $this->options['unit_system'] == 'METRIC' ? $text_km : $text_mi) . '</p>'; $this->get_location_details($location_id, $atts); } } } } else { echo '<h2>' . __('No results found', 'yoast-local-seo') . '</h2>'; } } ?> </div> <?php $output = ob_get_contents(); ob_end_clean(); return $output; }