1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
|
<?php // Exit if accessed directly if ( ! defined( 'ABSPATH' ) ) { exit; }
if( ! class_exists( 'Pennew_Portfolio_Helper' ) ) { class Pennew_Portfolio_Helper{ public function __construct() { add_action( 'wp_ajax_nopriv_penci_ajax_portfolio', array( $this, 'ajax_callback' ) ); add_action( 'wp_ajax_penci_ajax_portfolio', array( $this, 'ajax_callback' ) ); }
public function ajax_callback() { $datafilter = isset( $_POST['datafilter'] ) ? $_POST['datafilter'] : ''; $atts = isset( $datafilter['atts'] ) ? $datafilter['atts'] : ''; $query = isset( $datafilter['query'] ) ? $datafilter['query'] : ''; $shown_ids = isset( $datafilter['pflShowIds'] ) ? $datafilter['pflShowIds'] : ''; $count = isset( $datafilter['count'] ) ? $datafilter['count'] : ''; $count_terms = isset( $datafilter['countByTerms'] ) ? $datafilter['countByTerms'] : ''; $currentTerm = isset( $datafilter['currentTerm'] ) ? $datafilter['currentTerm'] : ''; $currentTax = isset( $datafilter['currentTax'] ) ? $datafilter['currentTax'] : ''; $numbermore = isset( $atts['numbermore'] ) ? $atts['numbermore'] : ''; $style = isset( $atts['style'] ) ? $atts['style'] : ''; $image_type = isset( $atts['image_type'] ) ? $atts['image_type'] : '';
extract( $atts );
$image_thumb = Pennew_Portfolio_Helper::get_image_size( $style, $image_type );
$pre_query = array_merge( $query, array( 'ignore_sticky_posts' => true, 'post__not_in' => $shown_ids, 'paged' => 0, 'posts_per_page' => $numbermore, ) );
if ( $currentTerm && '*' != $currentTerm && $currentTax ) { $pre_query['tax_query'] = array( array( 'taxonomy' => $currentTax, 'field' => 'slug', 'terms' => $currentTerm ) ); }
$show_pag = false; $portfolio_query = new WP_Query( $pre_query ); ob_start(); if ( ! $portfolio_query->have_posts() ) { wp_send_json_success( array( 'items' => '', 'hasMore' => $show_pag ) ); } $portfolio_i = 0; while ( $portfolio_query->have_posts() ): $portfolio_query->the_post(); include PENCI_PORTFOLIO__DIR . "/template/content-portfolio.php";
$portfolio_i ++; endwhile; wp_reset_postdata();
$content_items = ob_get_clean();
$post_count = $portfolio_query->post_count;
if ( '*' == $currentTerm ) { $shown_items = count( (array)$shown_ids ) + $post_count; $show_pag = $shown_items < $count; } else { $query_current_term = array_merge( $pre_query, array( 'fields' => 'ids', 'posts_per_page' => - 1, 'post__not_in' => '' ) );
$get_category_ids = array_intersect( $shown_ids, get_posts( $query_current_term ) ); $shown_items = count( (array)$get_category_ids ) + $post_count; $post_count_Term = isset( $count_terms[$currentTerm] ) ? $count_terms[$currentTerm] : 0; $show_pag = $shown_items < $post_count_Term; }
wp_send_json_success( array( 'items' => $content_items, 'show_pag' => $show_pag ) ); }
public static function get_html_pagination( $custom_query = false, $atts = array(), $data_query = array() ) { $atts = wp_parse_args( $atts, array( 'style' => 'masonry', 'column' => '3', 'filter' => 'true', 'all_text' => __( 'All', 'pencidesign' ), 'style_pag' => '', 'numbermore' => 6, 'loadmore_text' => function_exists( 'penci_get_tran_setting' ) ? penci_get_tran_setting( 'penci_click_handle_text' ) : esc_html__( 'Load More', 'penci-framework' ), 'no_more_text' => function_exists( 'penci_get_tran_setting' ) ? penci_get_tran_setting( 'penci_content_no_more_post_text' ) : esc_html__( 'Sorry, No more', 'penci-framework' ), 'more_link' => '', 'pag_pos' => 'center', 'build_query' => '' ) );
$number = isset( $data_query['size'] ) ? intval( $data_query['size'] ) : '12';
if ( $number <= 0 ) { return; }
if ( in_array( $atts['style_pag'], array( 'load_more', 'infinite' ) ) ) { printf( '<div class="penci-pagination penci-ajax-more penci-pag-%s"> <a class="penci-portfolio-more-button button %s %s"> <span class="ajax-more-text">%s</span> <span class="penci-portfolio-ajaxdot penci-pfl-ajaxdot"> <span class="dot dot1"></span> <span class="dot dot2"></span> <span class="dot dot3"></span> <span class="dot dot4"></span> </span> <span class="ajax-more-finished">%s</span> </a> </div>', $atts['pag_pos'], $atts['style_pag'], 'penci-plf-loading-2', function_exists( 'penci_get_tran_setting' ) ? penci_get_tran_setting( 'penci_loadmore__text' ) : esc_html__( 'Load More', 'penci-framework' ), function_exists( 'penci_get_tran_setting' ) ? penci_get_tran_setting( 'penci_content_no_more_post_text' ) : esc_html__( 'Sorry, No more', 'penci-framework' ) ); } elseif( 'showmore' == $atts['style_pag'] ) { $more_link = vc_build_link( $atts['more_link'] ); $url = isset( $more_link['url'] ) ? $more_link['url'] : ''; $title = isset( $more_link['title'] ) ? $more_link['title'] : '';
if ( $url && $title ) { printf( '<div class="penci-pagination penci-ajax-more penci-pag-%s"> <a class="penci-portfolio-more-button button %s" href="%s" target="%s"> <span class="ajax-more-text">%s</span> </a> </div>', $atts['pag_pos'], $atts['style_pag'], esc_url( $url ), isset( $more_link['target'] ) ? $more_link['target'] : '', esc_html( $title ) ); } }elseif( 'numeric' == $atts['style_pag'] ) { echo '<div class="penci-pagenavi-shortcode">' . penci_pagination_numbers( $custom_query, $atts['pag_pos'] ) . '</div>'; } }
public static function is_use_option( $id = '' ) { if ( empty( $id ) ) { $id = get_the_ID(); }
return get_post_meta( $id, 'penci_pfl_use_opt_current_page', true ); }
public static function get_image_size ( $layout = '', $image_type = '' ) { $image_thumb = 'penci-thumb-480-320';
if ( empty( $layout ) ) { $layout = get_theme_mod( 'penci_portfolio_layout' ); $layout = $layout ? $layout : 'masonry'; }
if ( $layout == 'masonry' ) { $image_thumb = 'penci-masonry-thumb'; }
if ( function_exists( 'penci_get_archive_image_type' ) ) { $image_thumb = penci_get_archive_image_type( $image_thumb, $image_type ); }
return $image_thumb; }
public static function get_slug(){ return get_theme_mod( 'penci_pfl_custom_slug' ) ? get_theme_mod( 'penci_pfl_custom_slug' ) : 'portfolio'; }
public static function get_slug_tax(){ return get_theme_mod( 'penci_pfl_custom_catslug' ) ? get_theme_mod( 'penci_pfl_custom_catslug' ) : 'portfolio-category'; }
public static function pre_Ratio( $width, $height ) { return number_format( $height / $width * 100, 8 ); }
public static function get_image_ratio( $image, $style, $image_type, $echo = true , $disable_lazyload ) { $ratio = '0.666666667';
if ( false === strpos( $image, '<img' ) ) { return $image; } $src_img = ''; $pre_image = $image; if ( preg_match( '@src="([^"]+)"@', $pre_image, $match ) ) { $src_img = array_pop( $match ); }
if( 'grid' == $style ){ if( 'square' == $image_type ){ $ratio = 'padding-bottom: 100%'; }elseif( 'vertical' == $image_type ){ $ratio = 'padding-bottom: 125%'; }else{ $ratio = 'padding-bottom: 66.6666667%'; } } elseif ( preg_match_all( '#(width|height)=(\'|")?(?<dimensions>[0-9]+)(\'|")?#i', $image, $image_dis ) && 2 == count( (array)$image_dis['dimensions'] ) ) { $ratio = 'padding-bottom:' . self::pre_Ratio( $image_dis['dimensions'][0], $image_dis['dimensions'][1] ) . '%'; }
if( ! $disable_lazyload ) { if ( preg_match( '(class=(\'|")[^"]+)', $image, $class_el ) ) { $image = str_replace( $src_img, PENCI_PORTFOLIO__URL . 'images/penci-holder.png', $image ); $image = str_replace( $class_el[0], $class_el[0] . ' penci-pfl-lazy" data-src="' . $src_img, $image ); }
if ( preg_match( '@srcset="([^"]+)"@', $image, $match ) ) { $srcset_img = array_pop( $match ); $image = str_replace( $srcset_img, '', $image ); } }
$output = '<span class="penci-image-placeholder' . ( $disable_lazyload ? ' penci-lazyloaded' : '' ) . '" style="' . $ratio . '">' . $image . '</span>';
if ( ! $echo ) { return $output; }
echo $output; } } }
new Pennew_Portfolio_Helper;
|