/** @see WP_Widget::widget */
 function widget($args, $instance)
 {
     global $wpseo_local_core;
     $title = apply_filters('widget_title', $instance['title']);
     $location_id = !empty($instance['location_id']) ? $instance['location_id'] : '';
     $comment = !empty($instance['comment']) ? esc_attr($instance['comment']) : '';
     if ($location_id == '' && wpseo_has_multiple_locations() || $location_id == 'current' && !is_singular('wpseo_locations')) {
         return '';
     }
     $shortcode_args = array('id' => $location_id, 'comment' => $comment, 'from_widget' => true, 'widget_title' => $title, 'before_title' => $args['before_title'], 'after_title' => $args['after_title'], 'hide_closed' => $instance['hide_closed'] ? 1 : 0);
     $location_data = $wpseo_local_core->get_location_data($location_id);
     $location_data = !empty($location_data['businesses']) ? $location_data['businesses'][0] : null;
     if (null == $location_data) {
         return '';
     }
     if (isset($args['before_widget'])) {
         echo $args['before_widget'];
     }
     if (!empty($title)) {
         echo $args['before_title'] . $title . $args['after_title'];
     }
     if (!isset($instance['hide_closed'])) {
         $instance['hide_closed'] = 0;
     }
     // Displaying location data as <meta> tags, so the schema.org validation will be positive
     echo '<div itemscope itemtype="http://schema.org/' . esc_attr($location_data['business_type']) . '">';
     echo '<meta itemprop="name" content="' . esc_attr($location_data['business_name']) . '">';
     echo wpseo_local_show_opening_hours($shortcode_args);
     echo '</div>';
     if (isset($args['after_widget'])) {
         echo $args['after_widget'];
     }
     return true;
 }
/**
 * Address shortcode handler
 *
 * @since 0.1
 *
 * @param array $atts Array of shortcode parameters
 *
 * @return string
 */
function wpseo_local_show_address($atts)
{
    $atts = wpseo_check_falses(shortcode_atts(array('id' => '', 'hide_name' => false, 'show_state' => true, 'show_country' => true, 'show_phone' => true, 'show_phone_2' => true, 'show_fax' => true, 'show_email' => true, 'show_url' => false, 'show_vat' => false, 'show_tax' => false, 'show_coc' => false, 'show_opening_hours' => false, 'hide_closed' => false, 'oneline' => false, 'comment' => '', 'from_sl' => false, 'from_widget' => false, 'widget_title' => '', 'before_title' => '', 'after_title' => '', 'echo' => false), $atts));
    $options = get_option('wpseo_local');
    if (isset($options['hide_opening_hours']) && $options['hide_opening_hours'] == 'on') {
        $atts['show_opening_hours'] = false;
    }
    $is_postal_address = 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 {
            if ($atts['id'] == '') {
                return is_singular() ? __('Please provide a post ID if you want to show an address outside a Locations singular page', 'yoast-local-seo') : '';
            }
        }
        // Get the location data if its already been entered
        $business_name = get_the_title($atts['id']);
        $business_type = get_post_meta($atts['id'], '_wpseo_business_type', true);
        $business_address = get_post_meta($atts['id'], '_wpseo_business_address', true);
        $business_city = get_post_meta($atts['id'], '_wpseo_business_city', true);
        $business_state = get_post_meta($atts['id'], '_wpseo_business_state', true);
        $business_zipcode = get_post_meta($atts['id'], '_wpseo_business_zipcode', true);
        $business_country = get_post_meta($atts['id'], '_wpseo_business_country', true);
        $business_phone = get_post_meta($atts['id'], '_wpseo_business_phone', true);
        $business_phone_2nd = get_post_meta($atts['id'], '_wpseo_business_phone_2nd', true);
        $business_fax = get_post_meta($atts['id'], '_wpseo_business_fax', true);
        $business_email = get_post_meta($atts['id'], '_wpseo_business_email', true);
        $business_url = get_post_meta($atts['id'], '_wpseo_business_url', true);
        $business_vat = get_post_meta($atts['id'], '_wpseo_business_vat_id', true);
        $business_tax = get_post_meta($atts['id'], '_wpseo_business_tax_id', true);
        $business_coc = get_post_meta($atts['id'], '_wpseo_business_coc_id', true);
        $is_postal_address = get_post_meta($atts['id'], '_wpseo_is_postal_address', true);
        $is_postal_address = $is_postal_address == '1';
        if (empty($business_url)) {
            $business_url = get_permalink($atts['id']);
        }
    } else {
        $business_name = isset($options['location_name']) ? $options['location_name'] : '';
        $business_type = isset($options['business_type']) ? $options['business_type'] : '';
        $business_address = isset($options['location_address']) ? $options['location_address'] : '';
        $business_city = isset($options['location_city']) ? $options['location_city'] : '';
        $business_state = isset($options['location_state']) ? $options['location_state'] : '';
        $business_zipcode = isset($options['location_zipcode']) ? $options['location_zipcode'] : '';
        $business_country = isset($options['location_country']) ? $options['location_country'] : '';
        $business_phone = isset($options['location_phone']) ? $options['location_phone'] : '';
        $business_phone_2nd = isset($options['location_phone_2nd']) ? $options['location_phone_2nd'] : '';
        $business_fax = isset($options['location_fax']) ? $options['location_fax'] : '';
        $business_email = isset($options['location_email']) ? $options['location_email'] : '';
        $business_url = !empty($options['location_url']) ? $options['location_url'] : wpseo_xml_sitemaps_base_url('');
        $business_vat = isset($options['location_vat_id']) ? $options['location_vat_id'] : '';
        $business_tax = isset($options['location_tax_id']) ? $options['location_tax_id'] : '';
        $business_coc = isset($options['location_coc_id']) ? $options['location_coc_id'] : '';
    }
    /*
     * This array can be used in a filter to change the order and the labels of contact details
     */
    $business_contact_details = array(array('key' => 'phone', 'label' => __('Phone', 'yoast-local-seo')), array('key' => 'phone_2', 'label' => __('Secondary phone', 'yoast-local-seo')), array('key' => 'fax', 'label' => __('Fax', 'yoast-local-seo')), array('key' => 'email', 'label' => __('Email', 'yoast-local-seo')), array('key' => 'url', 'label' => __('URL', 'yoast-local-seo')), array('key' => 'vat', 'label' => __('VAT ID', 'yoast-local-seo')), array('key' => 'tax', 'label' => __('Tax ID', 'yoast-local-seo')), array('key' => 'coc', 'label' => __('Chamber of Commerce ID', 'yoast-local-seo')));
    $business_contact_details = apply_filters('wpseo_local_contact_details', $business_contact_details);
    $tag_title_open = '';
    $tag_title_close = '';
    if (!$atts['oneline']) {
        if (!$atts['from_widget']) {
            $tag_name = apply_filters('wpseo_local_location_title_tag_name', 'h3');
            $tag_title_open = '<' . esc_html($tag_name) . '>';
            $tag_title_close = '</' . esc_html($tag_name) . '>';
        } else {
            if ($atts['from_widget'] && $atts['widget_title'] == '') {
                $tag_title_open = $atts['before_title'];
                $tag_title_close = $atts['after_title'];
            }
        }
    }
    $output = '<div id="wpseo_location-' . $atts['id'] . '" class="wpseo-location" itemscope itemtype="http://schema.org/' . ($is_postal_address ? 'PostalAddress' : $business_type) . '">';
    if (false == $atts['hide_name']) {
        $output .= $tag_title_open . ($atts['from_sl'] ? '<a href="' . $business_url . '">' : '') . '<span class="wpseo-business-name" itemprop="name">' . $business_name . '</span>' . ($atts['from_sl'] ? '</a>' : '') . $tag_title_close . ($atts['oneline'] ? ', ' : '');
    }
    $output .= '<' . ($atts['oneline'] ? 'span' : 'div') . ' ' . ($is_postal_address ? '' : 'itemprop="address" itemscope itemtype="http://schema.org/PostalAddress"') . ' class="wpseo-address-wrapper">';
    // Output city/state/zipcode in right format
    $output .= wpseo_local_get_address_format($business_address, $atts['oneline'], $business_zipcode, $business_city, $business_state, $atts['show_state']);
    if ($atts['show_country'] && !empty($business_country)) {
        $output .= $atts['oneline'] ? ', ' : ' ';
    }
    if ($atts['show_country'] && !empty($business_country)) {
        $output .= '<' . ($atts['oneline'] ? 'span' : 'div') . '  class="country-name" itemprop="addressCountry">' . WPSEO_Local_Frontend::get_country($business_country) . '</' . ($atts['oneline'] ? 'span' : 'div') . '>';
    }
    $output .= '</' . ($atts['oneline'] ? 'span' : 'div') . '>';
    $details_output = '';
    foreach ($business_contact_details as $order => $details) {
        if ('phone' == $details['key'] && $atts['show_phone'] && !empty($business_phone)) {
            $details_output .= sprintf('<span class="wpseo-phone">%s: <a href="tel:' . preg_replace('/[^0-9+]/', '', $business_phone) . '" class="tel"><span itemprop="telephone">' . $business_phone . '</span></a></span>' . ($atts['oneline'] ? ' ' : '<br/>'), $details['label']);
        }
        if ('phone_2' == $details['key'] && $atts['show_phone_2'] && !empty($business_phone_2nd)) {
            $details_output .= sprintf('<span class="wpseo-phone2nd">%s: <a href="tel:' . preg_replace('/[^0-9+]/', '', $business_phone_2nd) . '" class="tel">' . $business_phone_2nd . '</a></span>' . ($atts['oneline'] ? ' ' : '<br/>'), $details['label']);
        }
        if ('fax' == $details['key'] && $atts['show_fax'] && !empty($business_fax)) {
            $details_output .= sprintf('<span class="wpseo-fax">%s: <span class="tel" itemprop="faxNumber">' . $business_fax . '</span></span>' . ($atts['oneline'] ? ' ' : '<br/>'), $details['label']);
        }
        if ('email' == $details['key'] && $atts['show_email'] && !empty($business_email)) {
            $details_output .= sprintf('<span class="wpseo-email">%s: <a href="mailto:' . $business_email . '" itemprop="email">' . $business_email . '</a></span>' . ($atts['oneline'] ? ' ' : '<br/>'), $details['label']);
        }
        if ('url' == $details['key'] && $atts['show_url']) {
            $details_output .= sprintf('<span class="wpseo-url">%s: <a href="' . $business_url . '" itemprop="url">' . $business_url . '</a></span>' . ($atts['oneline'] ? ' ' : '<br/>'), $details['label']);
        }
        if ('vat' == $details['key'] && $atts['show_vat'] && !empty($business_vat)) {
            $details_output .= sprintf('<span class="wpseo-vat">%s: <span itemprop="vatID">' . $business_vat . '</span></span>' . ($atts['oneline'] ? ' ' : '<br/>'), $details['label']);
        }
        if ('tax' == $details['key'] && $atts['show_tax'] && !empty($business_tax)) {
            $details_output .= sprintf('<span class="wpseo-tax">%s: <span itemprop="taxID">' . $business_tax . '</span></span>' . ($atts['oneline'] ? ' ' : '<br/>'), $details['label']);
        }
        if ('coc' == $details['key'] && $atts['show_coc'] && !empty($business_coc)) {
            $details_output .= sprintf('<span class="wpseo-vat">%s: ' . $business_coc . '</span>' . ($atts['oneline'] ? ' ' : '<br/>'), $details['label']);
        }
    }
    if ('' != $details_output && true == $atts['oneline']) {
        $output .= ' - ';
    }
    $output .= $details_output;
    if ($atts['show_opening_hours']) {
        $args = array('id' => wpseo_has_multiple_locations() ? $atts['id'] : '', 'hide_closed' => $atts['hide_closed']);
        $output .= '<br/>' . wpseo_local_show_opening_hours($args, true) . '<br/>';
    }
    $output .= '</div>';
    if ($atts['comment'] != '') {
        $output .= '<div class="wpseo-extra-comment">' . wpautop(html_entity_decode($atts['comment'])) . '</div>';
    }
    if ($atts['echo']) {
        echo $output;
    }
    return $output;
}