Пример #1
0
    /**
     * Returns printable array of property stats
     *
     *
     * @todo #property_stats is currently used in multiple instances when attribute list is displayed by groups.  Cannot remove to avoid breaking styles. - potanin@UD (11/5/2011)
     * @since 1.11
     * @args: exclude, return_blank, make_link
     */
    function draw_stats($args = false, $property = false)
    {
        global $wp_properties, $post;
        if (!$property) {
            $property = $post;
        }
        $property = prepare_property_for_display($property);
        if (is_array($property)) {
            $property = WPP_F::array_to_object($property);
        }
        $defaults = array('sort_by_groups' => 'false', 'display' => 'dl_list', 'show_true_as_image' => 'false', 'make_link' => 'true', 'hide_false' => 'false', 'first_alt' => 'false', 'return_blank' => 'false', 'include' => '', 'exclude' => '', 'include_clsf' => 'attribute', 'stats_prefix' => sanitize_key(WPP_F::property_label('singular')));
        if (!empty($wp_properties['configuration']['property_overview']['sort_stats_by_groups'])) {
            $defaults['sort_by_groups'] = $wp_properties['configuration']['property_overview']['sort_stats_by_groups'];
        }
        if (!empty($wp_properties['configuration']['property_overview']['show_true_as_image'])) {
            $defaults['show_true_as_image'] = $wp_properties['configuration']['property_overview']['show_true_as_image'];
        }
        extract($args = wp_parse_args($args, $defaults), EXTR_SKIP);
        $property_stats = array();
        $groups = isset($wp_properties['property_groups']) ? (array) $wp_properties['property_groups'] : array();
        /**
         * Determine if we should draw meta data.
         * The functionality below is related to WPP2.0
         * Now it just adds compatibility with new Denali versions
         */
        if ($include_clsf == 'detail') {
            $sort_by_groups = 'false';
            foreach ($wp_properties['property_meta'] as $k => $v) {
                if ($k == 'tagline') {
                    continue;
                }
                if (!empty($property->{$k})) {
                    $property_stats[$k] = array('label' => $v, 'value' => $property->{$k});
                }
            }
        } else {
            $property_stats = WPP_F::get_stat_values_and_labels($property, array('label_as_key' => 'false'));
        }
        /** Include only passed attributes */
        if (!empty($include)) {
            $include = !is_array($include) ? explode(',', $include) : $include;
            foreach ($property_stats as $k => $v) {
                if (!in_array($k, $include)) {
                    unset($property_stats[$k]);
                }
            }
        }
        /** Exclude specific attributes from list */
        if (!empty($exclude)) {
            $exclude = !is_array($exclude) ? explode(',', $exclude) : $exclude;
            foreach ($exclude as $k) {
                if (isset($property_stats[$k])) {
                    unset($property_stats[$k]);
                }
            }
        }
        if (empty($property_stats)) {
            return false;
        }
        //echo "<pre>"; print_r( $property_stats ); echo "</pre>"; die();
        //* Prepare values before display */
        $property_stats = apply_filters('wpp::draw_stats::attributes', $property_stats, $property);
        $stats = array();
        foreach ($property_stats as $tag => $data) {
            if (empty($data['value'])) {
                continue;
            }
            $value = $data['value'];
            $attribute_data = UsabilityDynamics\WPP\Attributes::get_attribute_data($tag);
            //** Do not show attributes that have value of 'value' if enabled */
            if ($hide_false == 'true' && $value == 'false') {
                continue;
            }
            //* Skip blank values (check after filters have been applied) */
            if ($return_blank == 'false' && empty($value)) {
                continue;
            }
            $value = html_entity_decode($value);
            //** Single "true" is converted to 1 by get_properties() we check 1 as well, as long as it isn't a numeric attribute */
            if (isset($attribute_data['data_input_type']) && $attribute_data['data_input_type'] == 'checkbox' && in_array(strtolower($value), array('true', '1', 'yes'))) {
                if ($show_true_as_image == 'true') {
                    $value = '<div class="true-checkbox-image"></div>';
                } else {
                    $value = __('Yes', ud_get_wp_property()->domain);
                }
            } else {
                if ($value == 'false') {
                    if ($show_true_as_image == 'true') {
                        continue;
                    }
                    $value = __('No', ud_get_wp_property()->domain);
                }
            }
            //* Make URLs into clickable links */
            if ($make_link == 'true' && WPP_F::isURL($value)) {
                $value = str_replace('&ndash;', '-', $value);
                $value = "<a href='{$value}' title='{$label}'>{$value}</a>";
            }
            //* Make emails into clickable links */
            if ($make_link == 'true' && WPP_F::is_email($value)) {
                $value = "<a href='mailto:{$value}'>{$value}</a>";
            }
            $data['value'] = $value;
            $stats[$tag] = $data;
        }
        if (empty($stats)) {
            return false;
        }
        if ($display == 'array') {
            if ($sort_by_groups == 'true' && is_array($groups)) {
                $stats = sort_stats_by_groups($stats);
            }
            return $stats;
        }
        $alt = $first_alt == 'true' ? "" : "alt";
        //** Disable regular list if groups are NOT enabled, or if groups is not an array */
        if ($sort_by_groups != 'true' || !is_array($groups)) {
            foreach ($stats as $tag => $data) {
                $label = $data['label'];
                $value = $data['value'];
                $alt = $alt == "alt" ? "" : "alt";
                switch ($display) {
                    case 'dl_list':
                        ?>
            <dt class="<?php 
                        echo $stats_prefix;
                        ?>
_<?php 
                        echo $tag;
                        ?>
 wpp_stat_dt_<?php 
                        echo $tag;
                        ?>
"><?php 
                        echo $label;
                        ?>
              <span class="wpp_colon">:</span></dt>
            <dd class="<?php 
                        echo $stats_prefix;
                        ?>
_<?php 
                        echo $tag;
                        ?>
 wpp_stat_dd_<?php 
                        echo $tag;
                        ?>
 <?php 
                        echo $alt;
                        ?>
"><?php 
                        echo $value;
                        ?>
              &nbsp;</dd>
            <?php 
                        break;
                    case 'list':
                        ?>
            <li class="<?php 
                        echo $stats_prefix;
                        ?>
_<?php 
                        echo $tag;
                        ?>
 wpp_stat_plain_list_<?php 
                        echo $tag;
                        ?>
 <?php 
                        echo $alt;
                        ?>
">
              <span class="attribute"><?php 
                        echo $label;
                        ?>
<span class="wpp_colon">:</span></span>
              <span class="value"><?php 
                        echo $value;
                        ?>
&nbsp;</span>
            </li>
            <?php 
                        break;
                    case 'plain_list':
                        ?>
            <span class="<?php 
                        echo $stats_prefix;
                        ?>
_<?php 
                        echo $tag;
                        ?>
 attribute"><?php 
                        echo $label;
                        ?>
:</span>
            <span class="<?php 
                        echo $stats_prefix;
                        ?>
_<?php 
                        echo $tag;
                        ?>
 value"><?php 
                        echo $value;
                        ?>
&nbsp;</span>
            <br/>
            <?php 
                        break;
                    case 'detail':
                        ?>
            <h4 class="wpp_attribute"><?php 
                        echo $label;
                        ?>
<span class="separator">:</span></h4>
            <p class="value"><?php 
                        echo $value;
                        ?>
&nbsp;</p>
            <?php 
                        break;
                }
            }
        } else {
            $stats_by_groups = sort_stats_by_groups($stats);
            $main_stats_group = $wp_properties['configuration']['main_stats_group'];
            foreach ($stats_by_groups as $gslug => $gstats) {
                ?>
        <div class="wpp_feature_list">
        <?php 
                if ($main_stats_group != $gslug || !@array_key_exists($gslug, $groups)) {
                    $group_name = @array_key_exists($gslug, $groups) ? $groups[$gslug]['name'] : __('Other', ud_get_wp_property()->domain);
                    ?>
          <h2 class="wpp_stats_group"><?php 
                    echo $group_name;
                    ?>
</h2>
        <?php 
                }
                switch ($display) {
                    case 'dl_list':
                        ?>
            <dl class="wpp_property_stats overview_stats">
            <?php 
                        foreach ($gstats as $tag => $data) {
                            ?>
              <?php 
                            $label = $data['label'];
                            $value = $data['value'];
                            ?>
              <?php 
                            $alt = $alt == "alt" ? "" : "alt";
                            ?>
              <dt class="<?php 
                            echo $stats_prefix;
                            ?>
_<?php 
                            echo $tag;
                            ?>
 wpp_stat_dt_<?php 
                            echo $tag;
                            ?>
"><?php 
                            echo $label;
                            ?>
</dt>
              <dd class="<?php 
                            echo $stats_prefix;
                            ?>
_<?php 
                            echo $tag;
                            ?>
 wpp_stat_dd_<?php 
                            echo $tag;
                            ?>
 <?php 
                            echo $alt;
                            ?>
"><?php 
                            echo $value;
                            ?>
                &nbsp;</dd>
            <?php 
                        }
                        ?>
            </dl>
            <?php 
                        break;
                    case 'list':
                        ?>
            <ul class="overview_stats wpp_property_stats list">
            <?php 
                        foreach ($gstats as $tag => $data) {
                            ?>
              <?php 
                            $label = $data['label'];
                            $value = $data['value'];
                            $alt = $alt == "alt" ? "" : "alt";
                            ?>
              <li class="<?php 
                            echo $stats_prefix;
                            ?>
_<?php 
                            echo $tag;
                            ?>
 wpp_stat_plain_list_<?php 
                            echo $tag;
                            ?>
 <?php 
                            echo $alt;
                            ?>
">
                <span class="attribute"><?php 
                            echo $label;
                            ?>
:</span>
                <span class="value"><?php 
                            echo $value;
                            ?>
&nbsp;</span>
              </li>
            <?php 
                        }
                        ?>
            </ul>
            <?php 
                        break;
                    case 'plain_list':
                        foreach ($gstats as $tag => $data) {
                            $label = $data['label'];
                            $value = $data['value'];
                            ?>
              <span class="<?php 
                            echo $stats_prefix;
                            ?>
_<?php 
                            echo $tag;
                            ?>
 attribute"><?php 
                            echo $label;
                            ?>
:</span>
              <span class="<?php 
                            echo $stats_prefix;
                            ?>
_<?php 
                            echo $tag;
                            ?>
 value"><?php 
                            echo $value;
                            ?>
&nbsp;</span>
              <br/>
            <?php 
                        }
                        break;
                }
                ?>
        </div>
      <?php 
            }
        }
    }
Пример #2
0
    /**
     * Returns a minified Google Maps Infobox
     *
     * Used in property map and supermap
     *
     * @filter wpp_google_maps_infobox
     * @version 1.11 - added return if $post or address attribute are not set to prevent fatal error
     * @since 1.081
     *
     */
    public static function google_maps_infobox($post, $args = false)
    {
        global $wp_properties;
        $map_image_type = $wp_properties['configuration']['single_property_view']['map_image_type'];
        $infobox_attributes = $wp_properties['configuration']['google_maps']['infobox_attributes'];
        $infobox_settings = $wp_properties['configuration']['google_maps']['infobox_settings'];
        if (empty($wp_properties['configuration']['address_attribute'])) {
            return;
        }
        if (empty($post)) {
            return;
        }
        if (is_array($post)) {
            $post = (object) $post;
        }
        $property = (array) prepare_property_for_display($post, array('load_gallery' => 'false', 'scope' => 'google_map_infobox'));
        //** Check if we have children */
        if (!empty($property['children']) && (!isset($wp_properties['configuration']['google_maps']['infobox_settings']['do_not_show_child_properties']) || $wp_properties['configuration']['google_maps']['infobox_settings']['do_not_show_child_properties'] != 'true')) {
            foreach ($property['children'] as $child_property) {
                $child_property = (array) $child_property;
                $html_child_properties[] = '<li class="infobox_child_property"><a href="' . $child_property['permalink'] . '">' . $child_property['post_title'] . '</a></li>';
            }
        }
        if (empty($infobox_attributes)) {
            $infobox_attributes = array('price', 'bedrooms', 'bathrooms');
        }
        if (empty($infobox_settings)) {
            $infobox_settings = array('show_direction_link' => true, 'show_property_title' => true);
        }
        $infobox_style = !empty($infobox_settings['minimum_box_width']) ? 'style="min-width: ' . $infobox_settings['minimum_box_width'] . 'px;"' : '';
        foreach ($infobox_attributes as $attribute) {
            if (!empty($wp_properties['property_stats'][$attribute])) {
                $property_stats[$attribute] = $wp_properties['property_stats'][$attribute];
            }
        }
        $property_stats = WPP_F::get_stat_values_and_labels($property, array('property_stats' => $property_stats));
        if (!empty($property['featured_image'])) {
            $image = wpp_get_image_link($property['featured_image'], $map_image_type, array('return' => 'array'));
            if (!empty($image) && is_array($image)) {
                $imageHTML = "<img width=\"{$image['width']}\" height=\"{$image['height']}\" src=\"{$image['link']}\" alt=\"" . addslashes($post->post_title) . "\" />";
                if (@$wp_properties['configuration']['property_overview']['fancybox_preview'] == 'true' && !empty($property['featured_image_url'])) {
                    $imageHTML = "<a href=\"{$property['featured_image_url']}\" class=\"fancybox_image thumbnail\">{$imageHTML}</a>";
                }
            }
        }
        ob_start();
        ?>

    <div id="infowindow" <?php 
        echo $infobox_style;
        ?>
>
      <?php 
        if ($infobox_settings['show_property_title'] == 'true') {
            ?>
        <div class="wpp_google_maps_attribute_row_property_title">
          <a href="<?php 
            echo get_permalink($property['ID']);
            ?>
"><?php 
            echo $property['post_title'];
            ?>
</a>
        </div>
      <?php 
        }
        ?>

      <table cellpadding="0" cellspacing="0" class="wpp_google_maps_infobox_table" style="">
        <tr>
          <?php 
        if (!empty($imageHTML)) {
            ?>
            <td class="wpp_google_maps_left_col" style=" width: <?php 
            echo $image['width'];
            ?>
px">
              <?php 
            echo $imageHTML;
            ?>
              <?php 
            if ($infobox_settings['show_direction_link'] == 'true' && !empty($property['latitude']) && !empty($property['longitude'])) {
                ?>
                <div class="wpp_google_maps_attribute_row wpp_google_maps_attribute_row_directions_link">
                  <a target="_blank"
                     href="http://maps.google.com/maps?gl=us&daddr=<?php 
                echo $property['latitude'];
                ?>
,<?php 
                echo $property['longitude'];
                ?>
"
                     class="btn btn-info"><?php 
                _e('Get Directions', ud_get_wp_property()->domain);
                ?>
</a>
                </div>
              <?php 
            }
            ?>
            </td>
          <?php 
        }
        ?>

          <td class="wpp_google_maps_right_col" vertical-align="top" style="vertical-align: top;">
            <?php 
        if (!empty($imageHTML) && $infobox_settings['show_direction_link'] == 'true' && !empty($property['latitude']) && !empty($property['longitude'])) {
            ?>
              <div class="wpp_google_maps_attribute_row wpp_google_maps_attribute_row_directions_link">
                <a target="_blank"
                   href="http://maps.google.com/maps?gl=us&daddr=<?php 
            echo $property['latitude'];
            ?>
,<?php 
            echo $property['longitude'];
            ?>
"
                   class="btn btn-info"><?php 
            _e('Get Directions', ud_get_wp_property()->domain);
            ?>
</a>
              </div>
            <?php 
        }
        $attributes = array();
        $labels_to_keys = array_flip($wp_properties['property_stats']);
        if (is_array($property_stats)) {
            foreach ($property_stats as $attribute_label => $value) {
                $attribute_slug = $labels_to_keys[$attribute_label];
                $attribute_data = UsabilityDynamics\WPP\Attributes::get_attribute_data($attribute_slug);
                if (empty($value)) {
                    continue;
                }
                if (!empty($attribute_data['data_input_type']) && $attribute_data['data_input_type'] == 'checkbox' && ($value == 'true' || $value == 1)) {
                    if ($wp_properties['configuration']['google_maps']['show_true_as_image'] == 'true') {
                        $value = '<div class="true-checkbox-image"></div>';
                    } else {
                        $value = __('Yes', ud_get_wp_property()->domain);
                    }
                } elseif ($value == 'false') {
                    continue;
                }
                $attributes[] = '<li class="wpp_google_maps_attribute_row wpp_google_maps_attribute_row_' . $attribute_slug . '">';
                $attributes[] = '<span class="attribute">' . $attribute_label . '</span>';
                $attributes[] = '<span class="value">' . $value . '</span>';
                $attributes[] = '</li>';
            }
        }
        if (count($attributes) > 0) {
            echo '<ul class="wpp_google_maps_infobox">' . implode('', $attributes) . '<li class="wpp_google_maps_attribute_row wpp_fillter_element">&nbsp;</li></ul>';
        }
        if (!empty($html_child_properties)) {
            echo '<ul class="infobox_child_property_list">' . implode('', $html_child_properties) . '<li class="infobox_child_property wpp_fillter_element">&nbsp;</li></ul>';
        }
        ?>

          </td>
        </tr>
      </table>

    </div>

    <?php 
        $data = ob_get_contents();
        $data = preg_replace(array('/[\\r\\n]+/'), array(""), $data);
        $data = addslashes($data);
        ob_end_clean();
        $data = apply_filters('wpp_google_maps_infobox', $data, $post);
        return $data;
    }