/** * Figures out if current page is the property overview page * * This function could be called multiple times for the same shortcode, and numerous times on the page. * therefore, all JS in here has to take that into account and not perform same function twice. * * @since 1.10 * */ function wpp_draw_pagination($settings = '') { global $wpp_query, $wp_properties; $settings = wp_parse_args($settings, array('javascript' => true, 'return' => true, 'class' => '', 'sorter_type' => 'none', 'hide_count' => false, 'sort_by_text' => isset($wpp_query['sort_by_text']) ? $wpp_query['sort_by_text'] : '')); $settings = apply_filters('wpp:draw_pagination:settings', $settings, $wpp_query, $wp_properties); //** Do not show pagination on ajax requests */ if ($wpp_query['ajax_call']) { return null; } if (is_array($wpp_query) || is_object($wpp_query)) { extract($wpp_query); } if ($pagination == 'off' && $hide_count) { return null; } /** Maybe use custom pagination/sorter instead of default one */ $custom = apply_filters('wpp:property_overview:custom_pagination', false, $settings, $wpp_query, $wp_properties); if (!empty($custom)) { if ($settings['return'] == 'true') { return $custom; } else { echo $custom; return null; } } if (is_array($wpp_query) || is_object($wpp_query)) { extract($wpp_query); } if ($properties['total'] > $per_page && $pagination != 'off') { $use_pagination = true; } if ($properties['total'] < 2 || $sorter_type == 'none') { $sortable_attrs = false; } //** */ if ($settings['javascript']) { ob_start(); ?> <script type="text/javascript"> /* * The functionality below is used for pagination and sorting the list of properties * It can be many times (on multiple shortcodes) * So the current javascript functionality should not to be initialized twice. */ /* * Init global WPP_QUERY variable which will contain all query objects */ if ( typeof wpp_query == 'undefined' ) { var wpp_query = []; } /* * */ if ( typeof document_ready == 'undefined' ) { var document_ready = false; } /* * Initialize shortcode's wpp_query object */ if ( typeof wpp_query_<?php echo $unique_hash; ?> == 'undefined' ) { var wpp_query_<?php echo $unique_hash; ?> = <?php echo json_encode($wpp_query); ?> ; /* Default values for ajax query. It's used when we go to base URL using back button */ wpp_query_<?php echo $unique_hash; ?> ['default_query'] = wpp_query_<?php echo $unique_hash; ?> .query; /* Push query objects to global wpp_query variable */ wpp_query.push( wpp_query_<?php echo $unique_hash; ?> ); } /* * Init variable only at once */ if ( typeof wpp_pagination_history_ran == 'undefined' ) { var wpp_pagination_history_ran = false; } /* Init variable only at once */ if ( typeof wpp_pagination_<?php echo $unique_hash; ?> == 'undefined' ) { var wpp_pagination_<?php echo $unique_hash; ?> = false; } if ( typeof first_load == 'undefined' ) { var first_load = true; } /* Watch for address URL for back buttons support */ if ( !wpp_pagination_history_ran ) { wpp_pagination_history_ran = true; /* * On change location (address) Event. * * Also used as Back button functionality. * * Attention! This event is unique (binds at once) and is used for any (multiple) shortcode */ jQuery( document ).ready( function () { if ( !jQuery.isFunction( jQuery.fn.slider ) ) { return; } jQuery.address.change( function ( event ) { callPagination( event ); } ); } ); /* * Parse location (address) hash, * Setup shortcode params by hash params * Calls ajax pagination */ function callPagination ( event ) { /* * We have to be sure that DOM is ready * if it's not, wait 0.1 sec and call function again */ if ( !document_ready ) { window.setTimeout( function () { callPagination( event ); }, 100 ); return false; } var history = {}; /* Parse hash value (params) */ var hashes = event.value.replace( /^\//, '' ); /* Determine if we have hash params */ if ( hashes ) { hashes = hashes.split( '&' ); for ( var i in hashes ) { if ( typeof hashes[i] != 'function' ) { hash = hashes[i].split( '=' ); history[hash[0]] = hash[1]; } } if ( history.i ) { /* get current shortcode's object */ var index = parseInt( history.i ) - 1; if ( index >= 0 ) { var q = wpp_query[index]; } if ( typeof q == 'undefined' || q.length == 0 ) { //ERROR return false; } if ( history.sort_by && history.sort_by != '' ) { q.sort_by = history.sort_by; } if ( history.sort_order && history.sort_order != '' ) { q.sort_order = history.sort_order; } /* 'Select/Unselect' sortable buttons */ var sortable_links = jQuery( '#wpp_shortcode_' + q.unique_hash + ' .wpp_sortable_link' ); if ( sortable_links.length > 0 ) { sortable_links.each( function ( i, e ) { jQuery( e ).removeClass( "wpp_sorted_element" ); if ( jQuery( e ).attr( 'sort_slug' ) == q.sort_by ) { jQuery( e ).addClass( "wpp_sorted_element" ); } } ); } if ( history.requested_page && history.requested_page != '' ) { eval( 'wpp_do_ajax_pagination_' + q.unique_hash + '(' + history.requested_page + ')' ); } else { eval( 'wpp_do_ajax_pagination_' + q.unique_hash + '(1)' ); } } else { return false; } } else { /* Looks like it's base url * Determine if this first load, we do nothing * If not, - we use 'back button' functionality. */ if ( first_load ) { first_load = false; } else { /* * Set default pagination values for all shortcodes */ for ( var i in wpp_query ) { wpp_query[i].sort_by = wpp_query[i].default_query.sort_by; wpp_query[i].sort_order = wpp_query[i].default_query.sort_order; /* 'Select/Unselect' sortable buttons */ var sortable_links = jQuery( '#wpp_shortcode_' + wpp_query[i].unique_hash + ' .wpp_sortable_link' ); if ( sortable_links.length > 0 ) { sortable_links.each( function ( ie, e ) { jQuery( e ).removeClass( "wpp_sorted_element" ); if ( jQuery( e ).attr( 'sort_slug' ) == wpp_query[i].sort_by ) { jQuery( e ).addClass( "wpp_sorted_element" ); } } ); } eval( 'wpp_do_ajax_pagination_' + wpp_query[i].unique_hash + '(1, false)' ); } } } } } /* * Changes location (address) hash based on pagination * * We use this function extend of wpp_do_ajax_pagination() * because wpp_do_ajax_pagination() is called on change Address Value's event * * @param int this_page Page which will be loaded * @param object data WPP_QUERY object * @return object data Returns updated WPP_QUERY object */ if ( typeof changeAddressValue == 'undefined' ) { function changeAddressValue ( this_page, data ) { var q = window.wpp_query; /* Get the current shortcode's index */ var index = 0; for ( var i in q ) { if ( q[i].unique_hash == data.unique_hash ) { index = (++i); break; } } /* Set data query which will be used in history hash below */ var q = { requested_page: this_page, sort_order: data.sort_order, sort_by: data.sort_by, i: index }; /* Update WPP_QUERY query */ data.query.requested_page = this_page; data.query.sort_order = data.sort_order; data.query.sort_by = data.sort_by; /* * Update page URL for back-button support (needs to do sort order and direction) * jQuery.address.value() and jQuery.address.path() double binds jQuery.change() event, some way * so for now, we use window.location */ var history = jQuery.param( q ); window.location.hash = '/' + history; return data; } } function wpp_do_ajax_pagination_<?php echo $unique_hash; ?> ( this_page, scroll_to ) { if ( typeof this_page == 'undefined' ) { this_page = 1; } if ( typeof scroll_to == 'undefined' ) { scroll_to = true; } data = wpp_query_<?php echo $unique_hash; ?> ; /* Update page counter */ jQuery( "#wpp_shortcode_<?php echo $unique_hash; ?> .wpp_current_page_count" ).text( this_page ); jQuery( "#wpp_shortcode_<?php echo $unique_hash; ?> .wpp_pagination_slider .slider_page_info .val" ).text( this_page ); /* Update sliders */ jQuery( "#wpp_shortcode_<?php echo $unique_hash; ?> .wpp_pagination_slider" ).slider( "value", this_page ); jQuery( '#wpp_shortcode_<?php echo $unique_hash; ?> .ajax_loader' ).show(); /* Scroll page to the top of the current shortcode */ if ( scroll_to ) { jQuery( document ).trigger( 'wpp_pagination_change', {'overview_id': <?php echo $unique_hash; ?> } ); } data.ajax_call = 'true'; data.requested_page = this_page; jQuery.post( '<?php echo admin_url('admin-ajax.php'); ?> ', { action: 'wpp_property_overview_pagination', wpp_ajax_query: data }, function ( result_data ) { jQuery( '#wpp_shortcode_<?php echo $unique_hash; ?> .ajax_loader' ).hide(); var p_list = jQuery( '.wpp_property_view_result', result_data.display ); //* Determine if p_list is empty try previous version's selector */ if ( p_list.length == 0 ) { p_list = jQuery( '.wpp_row_view', result_data.display ); } var content = ( p_list.length > 0 ) ? p_list.html() : result_data.display; var p_wrapper = jQuery( '#wpp_shortcode_<?php echo $unique_hash; ?> .wpp_property_view_result' ); //* Determine if p_wrapper is empty try previous version's selector */ if ( p_wrapper.length == 0 ) { p_wrapper = jQuery( '#wpp_shortcode_<?php echo $unique_hash; ?> .wpp_row_view' ) } p_wrapper.html( content ); /* Total properties count may change depending on sorting (if sorted by an attribute that all properties do not have) */ /* It seems issue mentioned above are fexed so nex line unneeded, commented odokienko@UD */ // jQuery("#wpp_shortcode_<?php echo $unique_hash; ?> .wpp_property_results").text(result_data.wpp_query.properties?result_data.wpp_query.properties.total:0); <?php if (isset($use_pagination) && $use_pagination) { ?> /* Update max page in slider and in display */ jQuery( "#wpp_shortcode_<?php echo $unique_hash; ?> .wpp_pagination_slider" ).slider( "option", "max", result_data.wpp_query.pages ); jQuery( "#wpp_shortcode_<?php echo $unique_hash; ?> .wpp_total_page_count" ).text( result_data.wpp_query.pages ); max_slider_pos_<?php echo $unique_hash; ?> = result_data.wpp_query.pages; if ( max_slider_pos_<?php echo $unique_hash; ?> == 0 ) jQuery( "#wpp_shortcode_<?php echo $unique_hash; ?> .wpp_current_page_count" ).text( 0 ); <?php } ?> jQuery( "#wpp_shortcode_<?php echo $unique_hash; ?> a.fancybox_image" ).fancybox( { 'transitionIn': 'elastic', 'transitionOut': 'elastic', 'speedIn': 600, 'speedOut': 200, 'overlayShow': false } ); jQuery( document ).trigger( 'wpp_pagination_change_complete', {'overview_id': <?php echo $unique_hash; ?> } ); }, "json" ); } jQuery( document ).ready( function () { if ( !jQuery.isFunction( jQuery.fn.slider ) || !jQuery.isFunction( jQuery.fn.slider ) ) { jQuery( ".wpp_pagination_slider_wrapper" ).hide(); return null; } document_ready = true; max_slider_pos_<?php echo $unique_hash; ?> = <?php echo !empty($pages) ? $pages : 'null'; ?> ; //** Do not assign click event again */ if ( !jQuery( '#wpp_shortcode_<?php echo $unique_hash; ?> .wpp_pagination_back' ).data( 'events' ) ) { jQuery( '#wpp_shortcode_<?php echo $unique_hash; ?> .wpp_pagination_back' ).click( function () { var current_value = jQuery( "#wpp_shortcode_<?php echo $unique_hash; ?> .wpp_pagination_slider" ).slider( "value" ); if ( current_value == 1 ) { return; } var new_value = current_value - 1; jQuery( "#wpp_shortcode_<?php echo $unique_hash; ?> .wpp_pagination_slider" ).slider( "value", new_value ); wpp_query_<?php echo $unique_hash; ?> = changeAddressValue( new_value, wpp_query_<?php echo $unique_hash; ?> ); } ); } if ( !jQuery( '#wpp_shortcode_<?php echo $unique_hash; ?> .wpp_pagination_forward' ).data( 'events' ) ) { jQuery( '#wpp_shortcode_<?php echo $unique_hash; ?> .wpp_pagination_forward' ).click( function () { var current_value = jQuery( "#wpp_shortcode_<?php echo $unique_hash; ?> .wpp_pagination_slider" ).slider( "value" ); if ( max_slider_pos_<?php echo $unique_hash; ?> && (current_value == max_slider_pos_<?php echo $unique_hash; ?> || max_slider_pos_<?php echo $unique_hash; ?> < 1 ) ) { return; } var new_value = current_value + 1; jQuery( "#wpp_shortcode_<?php echo $unique_hash; ?> .wpp_pagination_slider" ).slider( "value", new_value ); wpp_query_<?php echo $unique_hash; ?> = changeAddressValue( new_value, wpp_query_<?php echo $unique_hash; ?> ); } ); } if ( !jQuery( '#wpp_shortcode_<?php echo $unique_hash; ?> .wpp_sortable_link' ).data( 'events' ) ) { jQuery( '#wpp_shortcode_<?php echo $unique_hash; ?> .wpp_sortable_link' ).click( function () { var attribute = jQuery( this ).attr( 'sort_slug' ); var sort_order = jQuery( this ).attr( 'sort_order' ); var this_attribute = jQuery( "#wpp_shortcode_<?php echo $unique_hash; ?> .wpp_sortable_link[sort_slug=" + attribute + "]" ); if ( jQuery( this ).is( ".wpp_sorted_element" ) ) { var currently_sorted = true; /* If this attribute is already sorted, we switch sort order */ if ( sort_order == "ASC" ) { sort_order = "DESC"; } else if ( sort_order == "DESC" ) { sort_order = "ASC"; } } jQuery( "#wpp_shortcode_<?php echo $unique_hash; ?> .wpp_sortable_link" ).removeClass( "wpp_sorted_element" ); wpp_query_<?php echo $unique_hash; ?> .sort_by = attribute; wpp_query_<?php echo $unique_hash; ?> .sort_order = sort_order; jQuery( this_attribute ).addClass( "wpp_sorted_element" ); jQuery( this_attribute ).attr( "sort_order", sort_order ); /* Get ajax results and reset to first page */ wpp_query_<?php echo $unique_hash; ?> = changeAddressValue( 1, wpp_query_<?php echo $unique_hash; ?> ); } ); } if ( !jQuery( '#wpp_shortcode_<?php echo $unique_hash; ?> .wpp_sortable_dropdown' ).data( 'events' ) ) { jQuery( '#wpp_shortcode_<?php echo $unique_hash; ?> .wpp_sortable_dropdown' ).change( function () { var parent = jQuery( this ).parents( '.wpp_sorter_options' ); var attribute = jQuery( ":selected", this ).attr( 'sort_slug' ); var sort_element = jQuery( ".sort_order", parent ); var sort_order = jQuery( sort_element ).attr( 'sort_order' ); wpp_query_<?php echo $unique_hash; ?> .sort_by = attribute; wpp_query_<?php echo $unique_hash; ?> .sort_order = sort_order; /* Get ajax results and reset to first page */ wpp_query_<?php echo $unique_hash; ?> = changeAddressValue( 1, wpp_query_<?php echo $unique_hash; ?> ); } ); } if ( !jQuery( '#wpp_shortcode_<?php echo $unique_hash; ?> .wpp_overview_sorter' ).data( 'events' ) ) { jQuery( '#wpp_shortcode_<?php echo $unique_hash; ?> .wpp_overview_sorter' ).click( function () { var parent = jQuery( this ).parents( '.wpp_sorter_options' ); var sort_element = this; var dropdown_element = jQuery( ".wpp_sortable_dropdown", parent ); var attribute = jQuery( ":selected", dropdown_element ).attr( 'sort_slug' ); var sort_order = jQuery( sort_element ).attr( 'sort_order' ); jQuery( sort_element ).removeClass( sort_order ); /* If this attribute is already sorted, we switch sort order */ if ( sort_order == "ASC" ) { sort_order = "DESC"; } else if ( sort_order == "DESC" ) { sort_order = "ASC"; } wpp_query_<?php echo $unique_hash; ?> .sort_by = attribute; wpp_query_<?php echo $unique_hash; ?> .sort_order = sort_order; jQuery( sort_element ).attr( "sort_order", sort_order ); jQuery( sort_element ).addClass( sort_order ); /* Get ajax results and reset to first page */ wpp_query_<?php echo $unique_hash; ?> = changeAddressValue( 1, wpp_query_<?php echo $unique_hash; ?> ); } ); } <?php if (isset($use_pagination) && $use_pagination) { ?> jQuery( "#wpp_shortcode_<?php echo $unique_hash; ?> .wpp_pagination_slider_wrapper" ).each( function () { var this_parent = this; /* Slider */ jQuery( '.wpp_pagination_slider', this ).slider( { value: 1, min: 1, max: <?php echo $pages; ?> , step: 1, slide: function ( event, ui ) { /* Update page counter - we do it here because we want it to be instant */ jQuery( "#wpp_shortcode_<?php echo $unique_hash; ?> .wpp_current_page_count" ).text( ui.value ); jQuery( "#wpp_shortcode_<?php echo $unique_hash; ?> .wpp_pagination_slider .slider_page_info .val" ).text( ui.value ); }, stop: function ( event, ui ) { wpp_query_<?php echo $unique_hash; ?> = changeAddressValue( ui.value, wpp_query_<?php echo $unique_hash; ?> ); } } ); /* Fix slider width based on button width */ var slider_width = (jQuery( this_parent ).width() - jQuery( ".wpp_pagination_back", this_parent ).outerWidth() - jQuery( ".wpp_pagination_forward", this_parent ).outerWidth() - 30); jQuery( ".wpp_pagination_slider", this_parent ).css( 'width', slider_width ); jQuery( '.wpp_pagination_slider .ui-slider-handle', this ).append( '<div class="slider_page_info"><div class="val">1</div><div class="arrow"></div></div>' ); } ); <?php } ?> } ); </script> <?php $js_result = ob_get_contents(); ob_end_clean(); } ob_start(); ?> <div class="properties_pagination <?php echo $settings['class']; ?> wpp_slider_pagination" id="properties_pagination_<?php echo $unique_hash; ?> "> <div class="wpp_pagination_slider_status"> <span class="wpp_property_results_options"> <?php if ($hide_count != 'true') { $wpp_property_results = '<span class="wpp_property_results">'; $wpp_property_results .= $properties['total'] > 0 ? WPP_F::format_numeric($properties['total']) : __('None', ud_get_wp_property()->domain); $wpp_property_results .= __(' found.', ud_get_wp_property()->domain); echo apply_filters('wpp::wpp_draw_pagination::wpp_property_results', $wpp_property_results, array('properties' => $properties, 'settings' => $settings)); ?> <?php } ?> <?php if (!empty($use_pagination)) { ?> <?php _e('Viewing page', ud_get_wp_property()->domain); ?> <span class="wpp_current_page_count">1</span> <?php _e('of', ud_get_wp_property()->domain); ?> <span class="wpp_total_page_count"><?php echo $pages; ?> </span>. <?php } ?> </span> <?php if ($sortable_attrs) { ?> <span class="wpp_sorter_options"><span class="wpp_sort_by_text"><?php echo $settings['sort_by_text']; ?> </span> <?php if ($settings['sorter_type'] == 'buttons') { ?> <?php foreach ($sortable_attrs as $slug => $label) { ?> <span class="wpp_sortable_link <?php echo $sort_by == $slug ? 'wpp_sorted_element' : ''; ?> label label-info" sort_order="<?php echo $sort_order; ?> " sort_slug="<?php echo $slug; ?> "><?php echo $label; ?> </span> <?php } } elseif ($settings['sorter_type'] == 'dropdown') { ?> <select class="wpp_sortable_dropdown sort_by label-info" name="sort_by"> <?php foreach ($sortable_attrs as $slug => $label) { ?> <option <?php echo $sort_by == $slug ? 'class="wpp_sorted_element" selected="true"' : ''; ?> sort_slug="<?php echo $slug; ?> " value="<?php echo $slug; ?> "><?php echo $label; ?> </option> <?php } ?> </select> <?php /* <span class="wpp_overview_sorter sort_order <?php echo $sort_order ?> label label-info" sort_order="<?php echo $sort_order ?>"></span> */ ?> <?php } else { do_action('wpp_custom_sorter', array('settings' => $settings, 'wpp_query' => $wpp_query, 'sorter_type' => $settings['sorter_type'])); } ?> </span> <?php } ?> <div class="clear"></div> </div> <?php if (!empty($use_pagination)) { ?> <div class="wpp_pagination_slider_wrapper"> <div class="wpp_pagination_back wpp_pagination_button"><?php _e('Prev', ud_get_wp_property()->domain); ?> </div> <div class="wpp_pagination_forward wpp_pagination_button"><?php _e('Next', ud_get_wp_property()->domain); ?> </div> <div class="wpp_pagination_slider"></div> </div> <?php } ?> </div> <div class="ajax_loader"></div> <?php $result = ob_get_contents(); ob_end_clean(); //** Combine JS (after minification) with HTML results */ if ($settings['javascript'] && isset($js_result)) { $js_result = WPP_F::minify_js($js_result); $result = $js_result . $result; } if ($settings['return'] == 'true') { return $result; } echo $result; }
/** * Demonstrates how to add dollar signs before all prices and deposits * * @since 1.15.3 * @uses WPP_F::get_coordinates() Creates an array from string $args. * * @param string $listing_id Listing ID must be passed */ function add_dollar_sign($content) { global $wp_properties; $currency_symbol = !empty($wp_properties['configuration']['currency_symbol']) ? $wp_properties['configuration']['currency_symbol'] : "\$"; $currency_symbol_placement = !empty($wp_properties['configuration']['currency_symbol_placement']) ? $wp_properties['configuration']['currency_symbol_placement'] : "before"; $content = trim(str_replace(array("\$", ","), "", $content)); if (!is_numeric($content)) { return preg_replace_callback('/(\\d+)/', create_function('$matches', 'return add_dollar_sign( $matches[0] );'), $content); } else { return ($currency_symbol_placement == 'before' ? $currency_symbol : '') . WPP_F::format_numeric($content) . ($currency_symbol_placement == 'after' ? $currency_symbol : ''); } }
/** * Returns the list of property statuses. * * @return array */ public function get_post_statuses() { $all = 0; $_attrs = \WPP_F::get_all_attribute_values('post_status'); $attrs = array(); if (is_array($_attrs)) { foreach ($_attrs as $attr) { $count = \WPP_F::get_properties_quantity(array($attr)); switch ($attr) { case 'publish': $label = __('Published', $this->get('domain')); $all += $count; break; case 'pending': $label = __('Pending', $this->get('domain')); $all += $count; break; case 'trash': $label = __('Trashed', $this->get('domain')); break; case 'auto-draft': $label = __('Auto-Draft', $this->get('domain')); break; default: $label = strtoupper(substr($attr, 0, 1)) . substr($attr, 1, strlen($attr)); $all += $count; } $attrs[$attr] = $label . ' (' . \WPP_F::format_numeric($count) . ')'; } } else { return array(); } $attrs['any'] = __('Any', $this->get('domain')) . ' (' . \WPP_F::format_numeric($all) . ')'; ksort($attrs); return $attrs; }
*/ ?> <div class="properties_pagination <?php echo $settings['class']; ?> wpp_slider_pagination type-<?php echo $settings['type']; ?> "> <div class="wpp_pagination_slider_status"> <span class="wpp_property_results_options"> <?php if ($hide_count != 'true') { $wpp_property_results = '<span class="wpp_property_results">'; $wpp_property_results .= $properties['total'] > 0 ? \WPP_F::format_numeric($properties['total']) : __('None', ud_get_wp_property()->domain); $wpp_property_results .= __(' found.', ud_get_wp_property()->domain); echo apply_filters('wpp::wpp_draw_pagination::wpp_property_results', $wpp_property_results, array('properties' => $properties, 'settings' => $settings)); } ?> <?php if (!empty($use_pagination)) { ?> <?php _e('Viewing page', ud_get_wp_property()->domain); ?> <span class="wpp_current_page_count">1</span> <?php _e('of', ud_get_wp_property()->domain); ?> <span class="wpp_total_page_count"><?php echo $pages;