_config["security_key"], 'security' ); /** * Fetch posts as per search filter */ $_res_total = $this->getSqlResult( 0, 0, 1 ); return $_res_total[0]->total_val; } /** * Render templates for posts lists * * @access public * @since 1.0 * * @param array $params Shortcode configuration options from admin settings * @return string Render templates accordion to request */ public function ajaxPostLoadmore( $params = array() ) { $params = is_array( $params ) ? $params : array(); $previous_config = $this->_config; $ajaxpostloadmore_id = ! empty( $params['id'] ) ? absint( $params['id'] ) : 0; $aplm_shortcode = array(); if ( $ajaxpostloadmore_id > 0 ) { $aplm_shortcode = get_post_meta( $ajaxpostloadmore_id ); foreach ( $aplm_shortcode as $sc_key => $sc_val ) { $aplm_shortcode[ $sc_key ] = isset( $sc_val[0] ) ? $sc_val[0] : ''; } } $aplm_shortcode = wp_parse_args( $params, $aplm_shortcode ); unset( $aplm_shortcode['id'] ); if ( 0 === $ajaxpostloadmore_id && empty( $aplm_shortcode ) ) { return ''; } $this->_config = shortcode_atts( $this->_config, $aplm_shortcode ); $this->_config['vcode'] = 'uid_' . md5( md5( wp_json_encode( $this->_config ) ) . $this->getUCode() ); $template = sanitize_key( $this->_config['template'] ); if ( ! in_array( $template, array( 'pane_style_1', 'pane_style_2', 'pane_style_3' ), true ) ) { $template = 'pane_style_1'; } ob_start(); require( $this->getajaxPostLoadmoreTemplate( 'template_' . $template . '.php' ) ); $output = ob_get_clean(); $this->_config = $previous_config; return $output; } /** * Load more post via ajax request * * @access public * @since 1.0 * * @return void Displays searched posts HTML to load more pagination */ public function getMorePosts() { global $wpdb, $wp_query; /** * Check security token from ajax request */ check_ajax_referer($this->_config["security_key"], 'security' ); $_total = ( isset( $_REQUEST["total"] )?esc_attr( $_REQUEST["total"] ):0 ); $_limit_start = ( isset( $_REQUEST["limit_start"])?esc_attr( $_REQUEST["limit_start"] ):0 ); $_limit_end = max( 1, absint( isset( $_REQUEST["number_of_post_display"] ) ? $_REQUEST["number_of_post_display"] : aplm_number_of_post_display ) ); /** * Fetch posts as per search filter */ $_result_items = $this->getSqlResult( $_limit_start, $_limit_end ); require( $this->getajaxPostLoadmoreTemplate( 'ajax_load_more_posts.php' ) ); wp_die(); } /** * Load more posts via ajax request * * @access public * @since 1.0 * * @return object Displays searched posts HTML */ public function getPosts() { global $wpdb; /** * Check security token from ajax request */ check_ajax_referer( $this->_config["security_key"], 'security' ); require( $this->getajaxPostLoadmoreTemplate( 'ajax_load_posts.php' ) ); wp_die(); } /** * Get post list with specified limit * * @access public * @since 1.0 * * @param int $_limit_end Limit to fetch post ending to given position * @return object Set of searched post data */ public function getPostList( $_limit_end ) { /** * Check security token from ajax request */ check_ajax_referer( $this->_config["security_key"], 'security' ); /** * Fetch data from database */ return $this->getSqlResult( 0, $_limit_end ); } } } new ajaxPostLoadmoreWidget();