Пример #1
0
 /** @see WP_Widget::widget */
 function widget($args, $instance)
 {
     $title = apply_filters('widget_title', isset($instance['title']) ? $instance['title'] : '');
     $location_id = !empty($instance['location_id']) ? $instance['location_id'] : '';
     $show_all_locations = !empty($instance['show_all_locations']) && $instance['show_all_locations'] == '1';
     $width = !empty($instance['width']) ? $instance['width'] : 200;
     $height = !empty($instance['height']) ? $instance['height'] : 150;
     $zoom = !empty($instance['zoom']) ? $instance['zoom'] : 10;
     $show_route = !empty($instance['show_route']) && $instance['show_route'] == '1';
     $show_state = !empty($instance['show_state']) && $instance['show_state'] == '1';
     $show_country = !empty($instance['show_country']) && $instance['show_country'] == '1';
     $show_url = !empty($instance['show_url']) && $instance['show_url'] == '1';
     if ($location_id == '' && wpseo_has_multiple_locations() || $location_id == 'current' && !is_singular('wpseo_locations')) {
         return '';
     }
     if (isset($args['before_widget'])) {
         echo $args['before_widget'];
     }
     if (!empty($title)) {
         echo $args['before_title'] . $title . $args['after_title'];
     }
     $map_args = array('width' => $width, 'height' => $height, 'zoom' => $zoom, 'id' => $show_all_locations ? 'all' : $location_id, 'show_route' => $show_route, 'show_state' => $show_state, 'show_country' => $show_country, 'show_url' => $show_url);
     echo wpseo_local_show_map($map_args);
     if (isset($args['after_widget'])) {
         echo $args['after_widget'];
     }
     return true;
 }
Пример #2
0
 /**
  * Builds the metabox for editing screen of the wpseo_locations Custom Post Type
  */
 function metabox_locations()
 {
     /** @var WPSEO_Local_Core */
     global $wpseo_local_core;
     $post_id = get_the_ID();
     echo '<div style="overflow: hidden;" id="wpseo-local-metabox">';
     // Noncename needed to verify where the data originated
     echo '<input type="hidden" name="locationsmeta_noncename" id="locationsmeta_noncename" value="' . wp_create_nonce(plugin_basename(__FILE__)) . '" />';
     // Copy from other locations field
     $locations = get_posts(array('post_type' => 'wpseo_locations', 'posts_per_page' => -1, 'orderby' => 'title', 'order' => 'ASC', 'fields' => 'ids', 'exclude' => $post_id));
     if (count($locations) > 0) {
         echo '<p>';
         echo '<label class="textinput">' . __('Copy data from another location', 'yoast-local-seo') . ':</label>';
         echo '<select class="chzn-select" name="_wpseo_copy_from_location" id="wpseo_copy_from_location" style="width: 400px;" data-placeholder="' . __('Choose your location', 'yoast-local-seo') . '">';
         echo '<option value=""></option>';
         foreach ($locations as $location_id) {
             echo '<option value="' . $location_id . '">' . get_the_title($location_id) . '</option>';
         }
         echo '</select>';
         echo '</p>';
         echo '<p style="clear:both; margin-left: 150px;"><em><strong>' . __('Note', 'yoast-local-seo') . ':</strong> ' . __('selecting a location will overwrite all data below. If you accidently selected a location, just refresh the page and make sure you don\'t save it.', 'yoast-local-seo') . '</em></p><br>';
         wp_reset_postdata();
     }
     // Get the location data if its already been entered
     $business_type = get_post_meta($post_id, '_wpseo_business_type', true);
     $business_address = get_post_meta($post_id, '_wpseo_business_address', true);
     $business_city = get_post_meta($post_id, '_wpseo_business_city', true);
     $business_state = get_post_meta($post_id, '_wpseo_business_state', true);
     $business_zipcode = get_post_meta($post_id, '_wpseo_business_zipcode', true);
     $business_country = get_post_meta($post_id, '_wpseo_business_country', true);
     $business_phone = get_post_meta($post_id, '_wpseo_business_phone', true);
     $business_phone_2nd = get_post_meta($post_id, '_wpseo_business_phone_2nd', true);
     $business_fax = get_post_meta($post_id, '_wpseo_business_fax', true);
     $business_email = get_post_meta($post_id, '_wpseo_business_email', true);
     $notes_1 = get_post_meta($post_id, '_wpseo_business_notes_1', true);
     $notes_2 = get_post_meta($post_id, '_wpseo_business_notes_2', true);
     $notes_3 = get_post_meta($post_id, '_wpseo_business_notes_3', true);
     $business_url = get_post_meta($post_id, '_wpseo_business_url', true);
     $business_vat_id = get_post_meta($post_id, '_wpseo_business_vat_id', true);
     $business_tax_id = get_post_meta($post_id, '_wpseo_business_tax_id', true);
     $business_coc_id = get_post_meta($post_id, '_wpseo_business_coc_id', true);
     $coordinates_lat = get_post_meta($post_id, '_wpseo_coordinates_lat', true);
     $coordinates_long = get_post_meta($post_id, '_wpseo_coordinates_long', true);
     $is_postal_address = get_post_meta($post_id, '_wpseo_is_postal_address', true);
     $multiple_opening_hours = get_post_meta($post_id, '_wpseo_multiple_opening_hours', true);
     $multiple_opening_hours = $multiple_opening_hours == 'on';
     // Echo out the field
     echo '<p><label class="textinput" for="wpseo_business_type">Business type:</label>';
     echo '<select class="chzn-select" name="_wpseo_business_type" id="wpseo_business_type" style="width: 200px;" data-placeholder="' . __('Choose your business type', 'yoast-local-seo') . '">';
     echo '<option></option>';
     foreach ($wpseo_local_core->get_local_business_types() as $bt_option => $bt_label) {
         echo '<option ' . selected($business_type, $bt_option, false) . ' value="' . $bt_option . '">' . $bt_label . '</option>';
     }
     echo '</select></p>';
     echo '<p class="desc label">' . sprintf(__('If your business type is not listed, please read %sthe FAQ entry%s.', 'yoast-local-seo'), '<a href="http://kb.yoast.com/article/49-my-business-is-not-listed-can-you-add-it" target="_blank">', '</a>') . '</p><br class="clear">';
     echo '<p><label class="textinput" for="wpseo_business_address">' . __('Business address:', 'yoast-local-seo') . '</label>';
     echo '<input type="text" name="_wpseo_business_address" id="wpseo_business_address" value="' . $business_address . '" /></p>';
     echo '<p><label class="textinput" for="wpseo_business_city">' . __('Business city', 'yoast-local-seo') . ':</label>';
     echo '<input type="text" name="_wpseo_business_city" id="wpseo_business_city" value="' . $business_city . '" /></p>';
     echo '<p><label class="textinput" for="wpseo_business_state">' . __('Business state', 'yoast-local-seo') . ':</label>';
     echo '<input type="text" name="_wpseo_business_state" id="wpseo_business_state" value="' . $business_state . '" /></p>';
     echo '<p><label class="textinput" for="wpseo_business_zipcode">' . __('Business zipcode', 'yoast-local-seo') . ':</label>';
     echo '<input type="text" name="_wpseo_business_zipcode" id="wpseo_business_zipcode" value="' . $business_zipcode . '" /></p>';
     echo '<p><label class="textinput" for="wpseo_business_country">' . __('Business country', 'yoast-local-seo') . ':</label>';
     echo '<select class="chzn-select" name="_wpseo_business_country" id="wpseo_business_country" style="width: 200px; margin-top: 8px;" data-placeholder="' . __('Choose your country', 'yoast-local-seo') . '">';
     echo '<option></option>';
     $countries = WPSEO_Local_Frontend::get_country_array();
     foreach ($countries as $key => $val) {
         echo '<option value="' . $key . '"' . ($business_country == $key ? ' selected="selected"' : '') . '>' . $countries[$key] . '</option>';
     }
     echo '</select></p>';
     echo '<p><label class="textinput" for="wpseo_business_phone">' . __('Main phone number', 'yoast-local-seo') . ':</label>';
     echo '<input type="text" name="_wpseo_business_phone" id="wpseo_business_phone" value="' . $business_phone . '" /></p>';
     echo '<p><label class="textinput" for="wpseo_business_phone_2nd">' . __('Second phone number', 'yoast-local-seo') . ':</label>';
     echo '<input type="text" name="_wpseo_business_phone_2nd" id="wpseo_business_phone_2nd" value="' . $business_phone_2nd . '" /></p>';
     echo '<p><label class="textinput" for="wpseo_business_fax">' . __('Fax number', 'yoast-local-seo') . ':</label>';
     echo '<input type="text" name="_wpseo_business_fax" id="wpseo_business_fax" value="' . $business_fax . '" /></p>';
     echo '<p><label class="textinput" for="wpseo_business_email">' . __('Email address', 'yoast-local-seo') . ':</label>';
     echo '<input type="text" name="_wpseo_business_email" id="wpseo_business_email" value="' . $business_email . '" /></p>';
     echo '<p><label class="textinput" for="wpseo_business_url">' . __('URL', 'yoast-local-seo') . ':</label>';
     echo '<input type="text" name="_wpseo_business_url" id="wpseo_business_url" value="' . $business_url . '" /></p>';
     echo '<p><label class="textinput" for="wpseo_business_vat_id">' . __('VAT ID', 'yoast-local-seo') . ':</label>';
     echo '<input type="text" name="_wpseo_business_vat_id" id="wpseo_business_vat_id" value="' . $business_vat_id . '" /></p>';
     echo '<p><label class="textinput" for="wpseo_business_tax_id">' . __('Tax ID', 'yoast-local-seo') . ':</label>';
     echo '<input type="text" name="_wpseo_business_tax_id" id="wpseo_business_tax_id" value="' . $business_tax_id . '" /></p>';
     echo '<p><label class="textinput" for="wpseo_business_coc_id">' . __('Chamber of Commerce ID', 'yoast-local-seo') . ':</label>';
     echo '<input type="text" name="_wpseo_business_coc_id" id="wpseo_business_coc_id" value="' . $business_coc_id . '" /></p>';
     echo '<p><label class="textinput" for="wpseo_custom_notes_1">' . __('Notes', 'yoast-local-seo') . ':</label>';
     echo '<textarea name="_wpseo_business_notes_1" id="wpseo_business_notes_1" >' . $notes_1 . '</textarea></p>';
     echo '<p><label class="textinput" for="wpseo_business_notes_2">' . __('Notes', 'yoast-local-seo') . ':</label>';
     echo '<textarea name="_wpseo_business_notes_2" id="wpseo_business_notes_2" >' . $notes_2 . '</textarea></p>';
     echo '<p><label class="textinput" for="wpseo_business_notes_3">' . __('Notes', 'yoast-local-seo') . ':</label>';
     echo '<textarea name="_wpseo_business_notes_3" id="wpseo_business_notes_3" >' . $notes_3 . '</textarea></p>';
     echo '<p>' . __('You can enter the lat/long coordinates yourself. If you leave them empty they will be calculated automatically. If you want to re-calculate these fields, please make them blank before saving this location.', 'yoast-local-seo') . '</p>';
     echo '<p><label class="textinput" for="wpseo_coordinates_lat">' . __('Latitude', 'yoast-local-seo') . ':</label>';
     echo '<input type="text" name="_wpseo_coordinates_lat" id="wpseo_coordinates_lat" value="' . $coordinates_lat . '" /></p>';
     echo '<p><label class="textinput" for="wpseo_coordinates_long">' . __('Longitude', 'yoast-local-seo') . ':</label>';
     echo '<input type="text" name="_wpseo_coordinates_long" id="wpseo_coordinates_long" value="' . $coordinates_long . '" /></p>';
     echo '<p>' . __('If the marker is not in the right location for your store, you can drag the pin to the location where you want it.', 'yoast-local-seo') . '</p>';
     wpseo_local_show_map(array('id' => $post_id, 'echo' => true, 'show_route' => false, 'map_style' => 'roadmap', 'draggable' => true));
     echo '<p>';
     echo '<label class="textinput" for="wpseo_is_postal_address">' . __('This address is a postal address (not a physical location)', 'yoast-local-seo') . ':</label>';
     echo '<input type="checkbox" class="checkbox" name="_wpseo_is_postal_address" id="wpseo_is_postal_address" value="1" ' . checked($is_postal_address, 1, false) . ' />';
     echo '</p>';
     $hide_opening_hours = isset($this->options['hide_opening_hours']) && $this->options['hide_opening_hours'] == 'on';
     // Opening hours
     echo '<br class="clear">';
     echo '<div id="hide-opening-hours" style="display: ' . ($hide_opening_hours ? 'none' : 'block') . ';">';
     echo '<h4>' . __('Opening hours', 'yoast-local-seo') . '</h4>';
     echo '<div id="opening-hours-multiple">';
     echo '<label for="wpseo_multiple_opening_hours" class="textinput">' . __('I have two sets of opening hours per day', 'yoast-local-seo') . ':</label>';
     echo '<input class="checkbox" id="wpseo_multiple_opening_hours" type="checkbox" name="_wpseo_multiple_opening_hours" value="on" ' . checked(true, $multiple_opening_hours, false) . '> ';
     echo '</div>';
     echo '<br class="clear">';
     foreach ($wpseo_local_core->days as $key => $day) {
         $field_name = '_wpseo_opening_hours_' . $key;
         $value_from = get_post_meta($post_id, $field_name . '_from', true);
         if (!$value_from) {
             $value_from = '09:00';
         }
         $value_to = get_post_meta($post_id, $field_name . '_to', true);
         if (!$value_to) {
             $value_to = '17:00';
         }
         $value_second_from = get_post_meta($post_id, $field_name . '_second_from', true);
         if (!$value_second_from) {
             $value_second_from = '09:00';
         }
         $value_second_to = get_post_meta($post_id, $field_name . '_second_to', true);
         if (!$value_second_to) {
             $value_second_to = '17:00';
         }
         echo '<div class="clear opening-hours">';
         if (!isset($this->options['opening_hours_24h'])) {
             $this->options['opening_hours_24h'] = false;
         }
         echo '<label class="textinput">' . $day . ':</label>';
         echo '<select class="openinghours_from" style="width: 100px;" id="' . $field_name . '_from" name="' . $field_name . '_from">';
         echo wpseo_show_hour_options($this->options['opening_hours_24h'], $value_from);
         echo '</select><span id="' . $field_name . '_to_wrapper"> - ';
         echo '<select class="openinghours_to" style="width: 100px;" id="' . $field_name . '_to" name="' . $field_name . '_to">';
         echo wpseo_show_hour_options($this->options['opening_hours_24h'], $value_to);
         echo '</select></span>';
         echo '<div class="clear opening-hour-second ' . (!$multiple_opening_hours ? 'hidden' : '') . '">';
         echo '<div id="' . $field_name . '_second">';
         echo '<label class="textinput">&nbsp;</label>';
         echo '<select class="openinghours_from_second" style="width: 100px;" id="' . $field_name . '_second_from" name="' . $field_name . '_second_from">';
         echo wpseo_show_hour_options($this->options['opening_hours_24h'], $value_second_from);
         echo '</select><span id="' . $field_name . '_second_to_wrapper"> - ';
         echo '<select class="openinghours_to_second" style="width: 100px;" id="' . $field_name . '_second_to" name="' . $field_name . '_second_to">';
         echo wpseo_show_hour_options($this->options['opening_hours_24h'], $value_second_to);
         echo '</select></span>';
         echo '</div>';
         echo '</div>';
         echo '</div>';
     }
     echo '</div><!-- #hide-opening-hours -->';
     echo '<br class="clear" />';
     echo '</div>';
 }
Пример #3
0
        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;
        }