Пример #1
0
    function draw_property_search_form($args = false)
    {
        global $wp_properties;
        WPP_F::force_script_inclusion('wpp-jquery-number-format');
        $args = wp_parse_args($args, array('search_attributes' => false, 'searchable_property_types' => false, 'use_pagination' => 'on', 'per_page' => '10', 'group_attributes' => false, 'strict_search' => false, 'instance_id' => false, 'sort_order' => false, 'cache' => true));
        if (empty($args['search_attributes']) && isset($args['searchable_attributes'])) {
            $args['search_attributes'] = $args['searchable_attributes'];
        }
        extract($args, EXTR_SKIP);
        $search_values = array();
        $property_type_flag = false;
        //** Bail if no search attributes passed */
        if (!is_array($args['search_attributes'])) {
            return;
        }
        $property_stats = $wp_properties['property_stats'];
        if (!isset($property_stats['property_type'])) {
            $property_stats['property_type'] = sprintf(__('%s Type', ud_get_wp_property()->domain), WPP_F::property_label());
        }
        //** Load search values for attributes (from cache, or generate) */
        if (!empty($search_attributes) && !empty($searchable_property_types)) {
            $search_values = WPP_F::get_search_values($search_attributes, $searchable_property_types, $args['cache'], $args['instance_id']);
        }
        //** This looks clumsy - potanin@UD */
        if (array_key_exists('property_type', array_fill_keys($search_attributes, 1)) && is_array($searchable_property_types) && count($searchable_property_types) > 1) {
            $spt = array_fill_keys($searchable_property_types, 1);
            if (!empty($wp_properties['property_types'])) {
                foreach ($wp_properties['property_types'] as $key => $value) {
                    if (array_key_exists($key, $spt)) {
                        $search_values['property_type'][$key] = $value;
                    }
                }
                if (isset($search_values['property_type']) && count($search_values['property_type']) <= 1) {
                    unset($search_values['property_type']);
                }
            }
        }
        ?>

    <form action="<?php 
        echo WPP_F::base_url($wp_properties['configuration']['base_slug']);
        ?>
" method="post" class="wpp_shortcode_search_form">
      <?php 
        do_action("draw_property_search_form", $args);
        ?>
      <?php 
        if ($sort_order) {
            ?>
        <input type="hidden" name="wpp_search[sort_order]" value="<?php 
            echo $sort_order;
            ?>
"/>
      <?php 
        }
        ?>
      <?php 
        if (!empty($sort_by)) {
            ?>
        <input type="hidden" name="wpp_search[sort_by]" value="<?php 
            echo $sort_by;
            ?>
"/>
      <?php 
        }
        ?>
      <?php 
        if (!empty($use_pagination)) {
            ?>
        <input type="hidden" name="wpp_search[pagination]" value="<?php 
            echo $use_pagination;
            ?>
"/>
      <?php 
        }
        ?>
      <?php 
        if (!empty($per_page)) {
            ?>
        <input type="hidden" name="wpp_search[per_page]" value="<?php 
            echo $per_page;
            ?>
"/>
      <?php 
        }
        ?>
      <?php 
        if (!empty($strict_search)) {
            ?>
        <input type="hidden" name="wpp_search[strict_search]" value="<?php 
            echo $strict_search;
            ?>
"/>
      <?php 
        }
        ?>
      <?php 
        //** If no property_type passed in search_attributes, we get defaults */
        if (is_array($searchable_property_types) && !array_key_exists('property_type', array_fill_keys($search_attributes, 1))) {
            echo '<input type="hidden" name="wpp_search[property_type]" value="' . implode(',', $searchable_property_types) . '" />';
        }
        ?>
      <ul class="wpp_search_elements">
    <?php 
        if (isset($group_attributes) && $group_attributes) {
            //** Get group data */
            $groups = $wp_properties['property_groups'];
            $_search_attributes = array();
            foreach ($search_attributes as $attr) {
                $_search_attributes[$attr] = $attr;
            }
            $search_groups = sort_stats_by_groups($_search_attributes);
            unset($_search_attributes);
        } else {
            //** Create an ad-hoc group */
            $search_groups['ungrouped'] = $search_attributes;
        }
        $main_stats_group = isset($wp_properties['configuration']['main_stats_group']) ? $wp_properties['configuration']['main_stats_group'] : false;
        $count = 0;
        foreach ($search_groups as $this_group => $search_attributes) {
            $count++;
            if ($this_group == 'ungrouped' || $this_group === 0 || $this_group == $main_stats_group) {
                $is_a_group = false;
                $this_group = 'not_a_group';
            } else {
                $is_a_group = true;
            }
            ?>
      <li class="wpp_search_group wpp_group_<?php 
            echo $this_group;
            ?>
">
      <?php 
            if ($is_a_group) {
                ?>
        <span class="wpp_search_group_title wpp_group_<?php 
                echo $this_group;
                ?>
_title"><?php 
                echo $groups[$this_group]['name'];
                ?>
</span>
      <?php 
            } elseif ($group_attributes && $count == count($search_groups)) {
                ?>
        <span class="wpp_search_group_title" style="height:1px;line-height:1px;">&nbsp;</span>
      <?php 
            }
            ?>
        <ul class="wpp_search_group wpp_group_<?php 
            echo $this_group;
            ?>
">
      <?php 
            //** Begin Group Attributes */
            foreach ($search_attributes as $attrib) {
                //** Override search values if they are set in the developer tab */
                if (!empty($wp_properties['predefined_search_values'][$attrib])) {
                    $maybe_search_values = explode(',', $wp_properties['predefined_search_values'][$attrib]);
                    if (is_array($maybe_search_values)) {
                        $using_predefined_values = true;
                        $search_values[$attrib] = $maybe_search_values;
                    } else {
                        $using_predefined_values = true;
                    }
                }
                //** Don't display search attributes that have no values */
                if (!apply_filters('wpp::show_search_field_with_no_values', isset($search_values[$attrib]), $attrib)) {
                    continue;
                }
                $label = apply_filters('wpp::search_attribute::label', empty($property_stats[$attrib]) ? WPP_F::de_slug($attrib) : $property_stats[$attrib], $attrib);
                ?>
        <li class="wpp_search_form_element seach_attribute_<?php 
                echo $attrib;
                ?>
  wpp_search_attribute_type_<?php 
                echo isset($wp_properties['searchable_attr_fields'][$attrib]) ? $wp_properties['searchable_attr_fields'][$attrib] : $attrib;
                ?>
 <?php 
                echo !empty($wp_properties['searchable_attr_fields'][$attrib]) && $wp_properties['searchable_attr_fields'][$attrib] == 'checkbox' ? 'wpp-checkbox-el' : '';
                echo !empty($wp_properties['searchable_attr_fields'][$attrib]) && ($wp_properties['searchable_attr_fields'][$attrib] == 'multi_checkbox' && count($search_values[$attrib]) == 1) || isset($wp_properties['searchable_attr_fields'][$attrib]) && $wp_properties['searchable_attr_fields'][$attrib] == 'checkbox' ? ' single_checkbox' : '';
                ?>
">
          <?php 
                $random_element_id = 'wpp_search_element_' . rand(1000, 9999);
                ?>

          <label for="<?php 
                echo $random_element_id;
                ?>
" class="wpp_search_label wpp_search_label_<?php 
                echo $attrib;
                ?>
"><?php 
                echo $label;
                ?>
<span class="wpp_search_post_label_colon">:</span></label>

          <div class="wpp_search_attribute_wrap">
            <?php 
                $value = isset($_REQUEST['wpp_search'][$attrib]) ? $_REQUEST['wpp_search'][$attrib] : '';
                ob_start();
                wpp_render_search_input(array('attrib' => $attrib, 'random_element_id' => $random_element_id, 'search_values' => $search_values, 'value' => $value));
                $this_field = ob_get_contents();
                ob_end_clean();
                echo apply_filters('wpp_search_form_field_' . $attrib, $this_field, $attrib, $label, $value, isset($wp_properties['searchable_attr_fields'][$attrib]) ? $wp_properties['searchable_attr_fields'][$attrib] : false, $random_element_id);
                ?>
          </div>
          <div class="clear"></div>
          </li>
      <?php 
            }
            //** End Group Attributes */
            ?>
      </ul>
      <div class="clear"></div>
      </li>
    <?php 
        }
        ?>
        <li class="wpp_search_form_element submit"><input type="submit" class="wpp_search_button submit btn btn-large" value="<?php 
        _e('Search', ud_get_wp_property()->domain);
        ?>
"/></li>
    </ul>
    </form>
  <?php 
    }
Пример #2
0
 /**
  * Fixed property pages being seen as 404 pages
  *
  * Ran on parse_request;
  *
  * WP handle_404() function decides if current request should be a 404 page
  * Marking the global variable $wp_query->is_search to true makes the function
  * assume that the request is a search.
  *
  * @param $query
  *
  * @since 0.5
  */
 function parse_request($query)
 {
     global $wp, $wp_query, $wp_properties, $wpdb;
     //** If we don't have permalinks, our base slug is always default */
     if (get_option('permalink_structure') == '') {
         $wp_properties['configuration']['base_slug'] = 'property';
     }
     //** If we are displaying search results, we can assume this is the default property page */
     if (isset($_REQUEST['wpp_search']) && is_array($_REQUEST['wpp_search'])) {
         if (isset($_POST['wpp_search'])) {
             $_query = '?' . http_build_query(array('wpp_search' => $_REQUEST['wpp_search']), '', '&');
             wp_redirect(WPP_F::base_url($wp_properties['configuration']['base_slug']) . $_query);
             die;
         }
         $wp_query->wpp_root_property_page = true;
         $wp_query->wpp_search_page = true;
     }
     //** Determine if this is the Default Property Page */
     if (isset($wp_properties['configuration']['base_slug']) && $wp->request == $wp_properties['configuration']['base_slug']) {
         $wp_query->wpp_root_property_page = true;
     }
     if (!empty($wp_properties['configuration']['base_slug']) && $wp->query_string == "p=" . $wp_properties['configuration']['base_slug']) {
         $wp_query->wpp_root_property_page = true;
     }
     if (isset($query->query_vars['name']) && $query->query_vars['name'] == $wp_properties['configuration']['base_slug']) {
         $wp_query->wpp_root_property_page = true;
     }
     if (isset($query->query_vars['pagename']) && $query->query_vars['pagename'] == $wp_properties['configuration']['base_slug']) {
         $wp_query->wpp_root_property_page = true;
     }
     if (isset($query->query_vars['category_name']) && $query->query_vars['category_name'] == $wp_properties['configuration']['base_slug']) {
         $wp_query->wpp_root_property_page = true;
     }
     //** If this is a the root property page, and the Dynamic Default Property page is used */
     if (isset($wp_query->wpp_root_property_page) && $wp_properties['configuration']['base_slug'] == 'property') {
         $wp_query->wpp_default_property_page = true;
         WPP_F::console_log('Overriding default 404 page status.');
         /** Set to override the 404 status */
         add_action('wp', create_function('', 'status_header( 200 );'));
         //** Prevent is_404() in template files from returning true */
         add_action('template_redirect', create_function('', ' global $wp_query; $wp_query->is_404 = false;'), 0, 10);
     }
     $wpp_pages = array();
     if (isset($wp_query->wpp_search_page)) {
         $wpp_pages[] = 'Search Page';
     }
     if (isset($wp_query->wpp_default_property_page)) {
         $wpp_pages[] = 'Default Property Page';
     }
     if (isset($wp_query->wpp_root_property_page)) {
         $wpp_pages[] = 'Root Property Page.';
     }
     if (!empty($wpp_pages)) {
         WPP_F::console_log('WPP_F::parse_request() ran, determined that request is for: ' . implode(', ', $wpp_pages));
     }
     if (!is_admin()) {
         /**
          * HACK.
          *
          * The issue:
          * When parent page is set as 'Default Properties Page',
          * child page will be rendered as 'property' page.
          * So Wordpress thinks that it's not a page and uses single template instead of page template.
          *
          * Tablet:
          * We determine if current post is 'page' but uses incorrect post_type 'property'
          * and fix it to valid post_type.
          *
          * @todo it's rough way to fix the problem, should be another one.
          * @see self::template_redirect(). hack is used there.
          * @author peshkov@UD
          */
         if (isset($query->query_vars['post_type']) && $query->query_vars['post_type'] == 'property' && isset($query->query_vars[$wp_properties['configuration']['base_slug']])) {
             $posts = get_posts(array('name' => $query->query_vars[$wp_properties['configuration']['base_slug']], 'post_type' => 'page'));
             if (!empty($posts) && count($posts) == 1) {
                 $query->query_vars['post_type'] = 'page';
                 $query->query_vars['_fix_to_page_template'] = true;
             }
         }
     }
     return $query;
 }
            wpp_css('property_overview::button', 'button wpp_edit');
            ?>
" href="<?php 
            echo class_wpp_feps::get_edit_feps_permalink($property['ID'], 'edit');
            ?>
"><?php 
            _e('Edit', ud_get_wp_property()->domain);
            ?>
</a>
              </li>
              <li>
                <a class="<?php 
            wpp_css('property_overview::button', 'button');
            ?>
" href="<?php 
            echo WPP_F::base_url(FEPS_VIEW_PAGE, array('feps' => $property['ID'], 'hash' => $property['wpp::feps::pending_hash'], 'action' => 'remove'));
            ?>
" onclick="return confirm('<?php 
            _e('Are you sure?', ud_get_wp_property()->domain);
            ?>
')"><?php 
            _e('Remove', ud_get_wp_property()->domain);
            ?>
</a>
              </li>
            </ul>
          </li>
          <?php 
        }
        ?>
        </ul>