home/wwgoat/public_html/blog/wp-content/themes/foxiz/templates/ajax.php000064400000011774147207176310022427 0ustar00validate( $_GET['data'] ); $settings['no_found_rows'] = false; $paged = 2; if ( isset( $settings['page_next'] ) ) { $paged = absint( $settings['page_next'] ); } if ( ! empty( $settings['is_related_query'] ) ) { $_query = foxiz_query_related( $settings, $paged ); } else { $_query = foxiz_query( $settings, $paged ); } $response = array(); if ( $_query->have_posts() ) { if ( ! empty( $_query->paged ) ) { $response['paged'] = $_query->paged; } else { $response['paged'] = $paged; } if ( $response['paged'] >= $settings['page_max'] ) { $response['notice'] = $this->end_list_info(); } $response['content'] = $this->render( $settings, $_query ); wp_reset_postdata(); } else { $response['paged'] = $settings['page_max'] + 99; $response['content'] = $this->end_list_info(); } wp_send_json( $response, null ); } /** * @param $settings * * @return array|mixed|string * validate input */ function validate( $settings ) { if ( is_array( $settings ) ) { foreach ( $settings as $key => $val ) { $key = sanitize_text_field( $key ); if ( ! is_array( $settings[ $key ] ) ) { $settings[ $key ] = sanitize_text_field( $val ); } } } elseif ( is_string( $settings ) ) { $settings = sanitize_text_field( $settings ); } else { $settings = ''; } return $settings; } /** * @param $settings * @param $_query * * @return false|string * render */ function render( $settings, $_query ) { ob_start(); $func = 'foxiz_loop_' . trim( $settings['name'] ); if ( function_exists( $func ) ) { call_user_func_array( $func, array( $settings, $_query ) ); } return ob_get_clean(); } /** * @return string * end list info */ function end_list_info() { $output = '
'; $output .= foxiz_html__( 'You\'ve reached the end of the list!', 'foxiz' ); $output .= '
'; return $output; } /** get embed iframe */ public function embed() { if ( empty( $_POST['data'] ) || empty( $_POST['data']['url'] ) ) { die( '-1' ); } wp_send_json( wp_oembed_get( esc_url( $_POST['data']['url'] ), array( 'height' => 450, 'width' => 800 ) ), null ); } function load_next_redirect() { global $wp_query; if ( empty( $wp_query->query_vars['rbsnp'] ) || ! is_singular( 'post' ) ) { return; } $file = '/templates/single/next-posts.php'; $template = locate_template( $file ); if ( $template ) { include( $template ); } exit; } function live_search() { if ( empty( $_GET['s'] ) ) { wp_send_json( '', null ); } $input = sanitize_text_field( $_GET['s'] ); $_query = new WP_Query( array( 's' => $input, 'posts_per_page' => 4, 'post_type' => 'post', 'post_status' => 'publish' ) ); $response = '
'; if ( $_query->have_posts() ) { ob_start(); while ( $_query->have_posts() ) : $_query->the_post(); foxiz_list_small_2( array( 'featured_position' => 'left', 'middle_mode' => '1' ) ); endwhile; $response .= ob_get_clean(); $response .= ''; } else { $response .= '

' . foxiz_html__( 'Sorry, but nothing matched your search terms. Please try again with some different keywords.', 'foxiz' ) . '

'; } $response .= '
'; wp_send_json( $response, null ); } } }