Пример #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 
            }
        }
    }
 /**
  * Returns property
  *
  * @since 1.11
  * @todo Code pertaining to displaying data should be migrated to prepare_property_for_display() like :$real_value = nl2br($real_value);
  * @todo Fix the long dashes - when in latitude or longitude it breaks it when using static map
  *
  */
 public static function get($id, $args = false)
 {
     global $wp_properties;
     if (is_object($id) && isset($id->ID)) {
         $id = $id->ID;
     }
     $id = trim($id);
     extract($args = wp_parse_args($args, array('get_children' => 'true', 'return_object' => 'false', 'load_gallery' => 'true', 'load_thumbnail' => 'true', 'load_parent' => 'true', 'cache' => 'true')), EXTR_SKIP);
     $get_children = isset($get_children) && $get_children === 'true' ? true : false;
     $return_object = isset($return_object) && $return_object === 'true' ? true : false;
     $load_gallery = isset($load_gallery) && $load_gallery === 'true' ? true : false;
     $load_thumbnail = isset($load_thumbnail) && $load_thumbnail === 'true' ? true : false;
     $load_parent = isset($load_parent) && $load_parent === 'true' ? true : false;
     $cache = isset($cache) && $cache === 'true' ? true : false;
     if ($cache && ($property = wp_cache_get($id))) {
         // Do nothing here since we already have data from cache!
     } else {
         $property = array();
         $post = get_post($id, ARRAY_A);
         if ($post['post_type'] != 'property') {
             return false;
         }
         //** Figure out what all the editable attributes are, and get their keys */
         $editable_keys = array_keys(array_merge((array) $wp_properties['property_meta'], (array) $wp_properties['property_stats']));
         //** Load all meta keys for this object */
         if ($keys = get_post_custom($id)) {
             foreach ($keys as $key => $value) {
                 $attribute = Attributes::get_attribute_data($key);
                 if (!$attribute['multiple']) {
                     $value = $value[0];
                 }
                 $keyt = trim($key);
                 //** If has _ prefix it's a built-in WP key */
                 if ('_' == $keyt[0]) {
                     continue;
                 }
                 // Fix for boolean values
                 switch ($value) {
                     case 'true':
                         $real_value = true;
                         //** Converts all "true" to 1 */
                         break;
                     case 'false':
                         $real_value = false;
                         break;
                     default:
                         $real_value = $value;
                         break;
                 }
                 // Handle keys with multiple values
                 if (count($value) > 1) {
                     $property[$key] = $value;
                 } else {
                     $property[$key] = $real_value;
                 }
             }
         }
         $property = array_merge($property, $post);
         //** Make sure certain keys were not messed up by custom attributes */
         $property['system'] = array();
         $property['gallery'] = array();
         $property['wpp_gpid'] = \WPP_F::maybe_set_gpid($id);
         $property['permalink'] = get_permalink($id);
         //** Make sure property_type stays as slug, or it will break many things:  (widgets, class names, etc)  */
         if (!empty($property['property_type'])) {
             $property['property_type_label'] = get_property_type($id);
         }
         //** If phone number is not set but set globally, we load it into property array here */
         if (empty($property['phone_number']) && !empty($wp_properties['configuration']['phone_number'])) {
             $property['phone_number'] = $wp_properties['configuration']['phone_number'];
         }
         //* Get rid of all empty values */
         foreach ($property as $key => $item) {
             //** Don't blank keys starting w/ post_  - this should be converted to use get_attribute_data() to check where data is stored for better check - potanin@UD */
             if (strpos($key, 'post_') === 0) {
                 continue;
             }
             if (empty($item)) {
                 unset($property[$key]);
             }
         }
         wp_cache_add($id, $property);
     }
     /*
      * Load parent if exists and inherit Parent's atttributes.
      */
     if ($load_parent) {
         $property = self::extend_property_with_parent($property, $cache);
     }
     /*
      * Load Children and their attributes
      */
     if ($get_children) {
         $property = self::extend_property_with_children($property, $cache);
     }
     /*
      * Figure out what the thumbnail is, and load all sizes
      */
     if ($load_thumbnail) {
         $property = array_merge($property, self::get_thumbnail($id, $cache));
     }
     /*
      * Load all attached images and their sizes
      */
     if ($load_gallery) {
         $gallery = self::get_images($id, $cache);
         $property['gallery'] = !empty($gallery) ? $gallery : false;
     }
     if (is_array($property)) {
         ksort($property);
     }
     $property = apply_filters('wpp_get_property', $property, $args);
     //** Convert to object */
     if ($return_object) {
         $property = \WPP_F::array_to_object($property);
     }
     return $property;
 }