PluginProbe ʕ •ᴥ•ʔ
VK Blocks / 0.16.2
VK Blocks v0.16.2
1.123.0 1.122.0 1.121.0 1.120.0 1.119.2 1.119.1 1.119.0 1.118.7 1.82.0.0 1.82.0.1 1.83.0.0 1.83.0.1 1.84.0.0 1.84.0.1 1.85.0.2 1.85.0.3 1.85.1.0 1.85.1.1 1.86.0.0 1.86.0.1 1.86.1.0 1.87.0.0 1.87.0.1 1.88.0.1 1.88.0.2 1.89.0.0 1.9.2 1.90.0.0 1.90.0.1 1.90.1.1 1.91.0.0 1.91.1.1 1.92.0.0 1.92.0.1 1.92.1.0 1.92.1.1 1.93.0.0 trunk 1.93.0.1 0.1.1 1.93.1.0 0.10.3 1.93.1.1 0.11.0 1.94.0.0 0.12.6 1.94.0.1 0.15.1 1.94.1.0 0.16.2 1.94.2.1 0.17.6 1.94.2.2 0.2.2 1.95.0.3 0.22.4 1.95.0.4 0.26.7 1.96.2.0 0.3.2 1.96.2.1 0.31.0 1.97.0.1 0.35.5 1.97.0.2 0.37.5 1.99.0.0 0.38.8 1.99.0.1 0.39.4 0.4.7 0.41.0 0.42.0 0.44.13 0.45.2 0.46.1 0.47.0 0.48.0 0.49.8 0.5.2 0.50.3 0.51.0 0.52.2 0.53.2 0.54.0 0.55.0 0.56.2 0.56.3 0.57.6 0.58.10 0.59.0 0.6.0 0.60.1 0.61.2 0.7.1 0.8.2 1.0.16 1.10.0 1.100.0.0 1.100.0.1 1.102.0.0 1.102.0.1 1.103.0.0 1.104.0.0 1.104.0.1 1.105.1.0 1.105.1.1 1.106.0.0 1.106.0.1 1.107.0.0 1.107.0.1 1.107.0.2 1.108.0.0 1.108.0.1 1.109.0.0 1.109.0.1 1.11.4 1.110.0.0 1.110.0.1 1.111.0.0 1.111.0.1 1.111.0.2 1.112.0.0 1.112.0.1 1.113.0.0 1.113.0.1 1.114.0.0 1.114.0.1 1.114.2.0 1.114.2.1 1.115.0.0 1.115.0.1 1.115.1.0 1.115.1.1 1.115.2.0 1.115.2.1 1.116.0.0 1.116.0.1 1.116.1.0 1.116.1.1 1.116.2.0 1.117.0.0 1.117.0.1 1.117.1.0 1.118.2 1.118.5 1.12.0 1.13.2 1.14.1 1.15.1 1.16.11 1.17.0 1.18.6 1.19.0 1.19.1 1.2.3 1.20.7 1.21.0 1.22.4 1.23.0 1.24.5 1.25.1 1.26.2 1.27.7.2 1.28.0.1 1.29.2.0 1.3.9 1.30.0.1 1.31.0.1 1.32.0.2 1.33.2.1 1.36.1.5 1.37.0.0 1.39.2.1 1.4.6 1.40.0.1 1.40.1.0 1.40.1.1 1.41.0.0 1.41.0.1 1.41.2.2 1.41.2.3 1.43.0.0 1.43.0.1 1.43.0.2 1.44.0.0 1.44.0.1 1.45.0.0 1.45.0.1 1.46.0.0 1.46.0.1 1.47.0.0 1.47.0.1 1.47.1.0 1.48.0.0 1.48.0.1 1.48.0.2 1.48.1.0 1.48.1.1 1.5.0 1.50.0.0 1.50.0.1 1.51.0.0 1.51.0.1 1.52.0.0 1.52.0.1 1.53.0.0 1.53.0.1 1.54.0.0 1.54.0.1 1.55.0.0 1.55.0.1 1.56.0.0 1.56.0.1 1.57.0.0 1.57.0.2 1.57.0.3 1.57.0.4 1.57.0.5 1.57.1.0 1.57.1.1 1.57.1.2 1.58.0.0 1.58.0.1 1.59.0.0 1.59.0.1 1.6.0 1.60.0.0 1.60.0.1 1.63.0.0 1.63.0.1 1.64.0.0 1.64.0.1 1.64.1.0 1.64.1.2 1.67.0.0 1.67.0.1 1.68.0.0 1.68.0.1 1.69.0.0 1.69.0.1 1.69.1.1 1.69.1.2 1.7.1 1.70.0.0 1.70.0.1 1.71.0.0 1.71.0.1 1.72.0.0 1.72.1.0 1.72.1.1 1.73.0.0 1.73.0.1 1.74.0.0 1.74.0.1 1.75.0.0 1.75.1.0 1.75.1.1 1.76.0.0 1.76.0.1 1.76.1.0 1.76.1.1 1.76.2.0 1.76.2.1 1.77.0.0 1.77.0.1 1.78.0.0 1.78.0.1 1.79.0.0 1.79.0.1 1.79.0.2 1.79.0.3 1.79.1.0 1.79.1.1 1.8.2 1.80.1.0 1.80.1.1 1.80.1.2 1.81.0.1 1.81.0.2
vk-blocks / inc / vk-components / package / class-vk-component-posts.php
vk-blocks / inc / vk-components / package Last commit date
_scss 6 years ago class-vk-component-button.php 6 years ago class-vk-component-mini-contents.php 6 years ago class-vk-component-posts.php 6 years ago
class-vk-component-posts.php
422 lines
1 <?php
2 /*
3 The original of this file is located at:
4 https://github.com/vektor-inc/vektor-wp-libraries
5 If you want to change this file, please change the original file.
6 */
7
8 if ( ! class_exists( 'VK_Component_Posts' ) ) {
9
10 class VK_Component_Posts {
11
12 /*-------------------------------------------*/
13 /* Basic method
14 /*-------------------------------------------*/
15 /* Common Parts
16 /*-------------------------------------------*/
17 /* Layout patterns
18 /*-------------------------------------------*/
19 /* UI Helper method
20 /*-------------------------------------------*/
21
22 /*-------------------------------------------*/
23 /* Basic method
24 /*-------------------------------------------*/
25 static public function get_loop_post_view_options( $options ) {
26 global $vk_components_textdomain;
27 $default = array(
28 'layout' => 'card',
29 'display_image' => true,
30 'display_image_overlay_term' => true,
31 'display_excerpt' => false,
32 'display_date' => true,
33 'display_new' => true,
34 'display_btn' => false,
35 'image_default_url' => false,
36 'overlay' => false,
37 'btn_text' => __( 'Read more', $vk_components_textdomain ),
38 'btn_align' => 'text-right',
39 'new_text' => __( 'New!!', $vk_components_textdomain ),
40 'new_date' => 7,
41 'textlink' => true,
42 'class_outer' => '',
43 'class_title' => '',
44 'body_prepend' => '',
45 'body_append' => '',
46 );
47 $return = wp_parse_args( $options, $default );
48 return $return;
49 }
50
51 /**
52 * [public description]
53 * @var [type]
54 */
55 static public function get_view( $post, $options ) {
56
57 $options = self::get_loop_post_view_options( $options );
58
59 if ( $options['layout'] == 'card-horizontal' ) {
60 $html = self::get_view_type_card_horizontal( $post, $options );
61 } elseif ( $options['layout'] == 'media' ) {
62 $html = self::get_view_type_media( $post, $options );
63 } else {
64 $html = self::get_view_type_card( $post, $options );
65 }
66 return $html;
67 }
68
69 static public function the_view( $post, $options ) {
70 echo wp_kses_post( self::get_view( $post, $options ) );
71 }
72
73 /**
74 * [public description]
75 * @var [type]
76 */
77 static public function get_loop( $wp_query, $options, $options_loop = array() ) {
78
79 $options_loop_dafault = array(
80 'class_loop_outer' => '',
81 );
82 $options_loop = wp_parse_args( $options_loop, $options_loop_dafault );
83
84 $loop = '';
85 if ( $wp_query->have_posts() ) :
86
87 $outer_class = '';
88 if ( $options_loop['class_loop_outer'] ) {
89 $outer_class = ' ' . $options_loop['class_loop_outer'];
90 }
91
92 $loop .= '<div class="vk_posts' . $outer_class . '">';
93
94 while ( $wp_query->have_posts() ) {
95 $wp_query->the_post();
96 global $post;
97 $loop .= VK_Component_Posts::get_view( $post, $options );
98 } // while ( have_posts() ) {
99 endif;
100
101 $loop .= '</div>';
102
103 wp_reset_query();
104 wp_reset_postdata();
105 return $loop;
106 }
107
108 /**
109 * [public description]
110 * @var [type]
111 */
112 static public function the_loop( $wp_query, $options, $options_loop = array() ) {
113 echo self::get_loop( $wp_query, $options, $options_loop );
114 }
115
116 /*-------------------------------------------*/
117 /* Common Parts
118 /*-------------------------------------------*/
119 /**
120 * Common Part _ first DIV
121 * @var [type]
122 */
123 static public function get_view_first_div( $post, $options ) {
124 if ( $options['layout'] == 'card-horizontal' ) {
125 $class_outer = 'card card-post card-horizontal';
126 } elseif ( $options['layout'] == 'media' ) {
127 $class_outer = 'media';
128 } else {
129 $class_outer = 'card card-post';
130 }
131 if ( ! empty( $options['class_outer'] ) ) {
132 $class_outer .= ' ' . esc_attr( $options['class_outer'] );
133 }
134 if ( $options['display_btn'] ) {
135 $class_outer .= ' vk_post-btn-display';
136 }
137 $html = '<div id="post-' . esc_attr( $post->ID ) . '" class="vk_post ' . join( ' ', get_post_class( $class_outer ) ) . '">';
138 return $html;
139 }
140
141 /**
142 * Common Part _ post thumbnail
143 * @param [type] $post [description]
144 * @param [type] $options [description]
145 * @param string $class [description]
146 * @return [type] [description]
147 */
148 static public function get_thumbnail_image( $post, $options, $attr = array() ) {
149
150 $default = array(
151 'class_outer' => '',
152 'class_image' => '',
153 );
154 $classes = wp_parse_args( $attr, $default );
155
156 $html = '';
157 if ( $options['display_image'] ) {
158 if ( $classes['class_outer'] ) {
159 $classes['class_outer'] = ' ' . $classes['class_outer'];
160 }
161
162 $image_src = get_the_post_thumbnail_url( $post->ID, 'large' );
163 if ( ! $image_src && $options['image_default_url'] ) {
164 $image_src = esc_url( $options['image_default_url'] );
165 }
166 $style = ' style="background-image:url(' . $image_src . ')"';
167
168 $html .= '<div class="vk_post_imgOuter' . $classes['class_outer'] . '"' . $style . '>';
169 $html .= '<a href="' . get_the_permalink( $post->ID ) . '">';
170
171 if ( $options['overlay'] ) {
172 $html .= '<div class="card-img-overlay">';
173 $html .= $options['overlay'];
174 $html .= '</div>';
175 }
176
177 if ( $options['display_image_overlay_term'] ) {
178
179 $html .= '<div class="card-img-overlay">';
180 $term_args = array(
181 'class' => 'vk_post_imgOuter_singleTermLabel',
182 );
183 if ( method_exists( 'Vk_term_color', 'get_single_term_with_color' ) ) {
184 $html .= Vk_term_color::get_single_term_with_color( false, $term_args );
185 }
186 $html .= '</div>';
187
188 }
189 if ( $classes['class_image'] ) {
190 $image_class = 'vk_post_imgOuter_img ' . $classes['class_image'];
191 } else {
192 $image_class = 'vk_post_imgOuter_img';
193 }
194
195 $image_attr = array( 'class' => $image_class );
196 $img = get_the_post_thumbnail( $post->ID, 'medium', $image_attr );
197 if ( $img ) {
198 $html .= $img;
199 } elseif ( $options['image_default_url'] ) {
200 $html .= '<img src="' . esc_url( $options['image_default_url'] ) . '" alt="" class="' . $image_class . '" />';
201 }
202 $html .= '</a>';
203 $html .= '</div><!-- [ /.vk_post_imgOuter ] -->';
204 } // if ( $options['display_image'] ) {
205 return $html;
206 }
207
208 /**
209 * Common Part _ post body
210 * @var [type]
211 */
212 static public function get_view_body( $post, $options ) {
213 // $default = array(
214 // 'textlink' => false,
215 // );
216 // $attr = wp_parse_args( $attr, $default );
217
218 $layout_type = $options['layout'];
219 if ( $layout_type == 'card-horizontal' ) {
220 $layout_type = 'card';
221 }
222
223 $html = '';
224
225 $html .= '<div class="vk_post_body ' . $layout_type . '-body">';
226
227 if ( ! empty( $options['body_prepend'] ) ) {
228 $html .= $options['body_prepend'];
229 }
230
231 $html .= '<h5 class="vk_post_title ' . $layout_type . '-title">';
232
233 if ( $options['textlink'] ) {
234 $html .= '<a href="' . get_the_permalink( $post->ID ) . '">';
235 }
236
237 $html .= get_the_title( $post->ID );
238
239 if ( $options['display_new'] ) {
240 $today = date_i18n( 'U' );
241 $entry = get_the_time( 'U' );
242 $kiji = date( 'U', ( $today - $entry ) ) / 86400;
243 if ( $options['new_date'] > $kiji ) {
244 $html .= '<span class="vk_post_title_new">' . $options['new_text'] . '</span>';
245 }
246 }
247
248 if ( $options['textlink'] ) {
249 $html .= '</a>';
250 }
251
252 $html .= '</h5>';
253
254 if ( $options['display_date'] ) {
255 $html .= '<div class="vk_post_date ' . $layout_type . '-date published">';
256 $html .= esc_html( get_the_date( null, $post->ID ) );
257 $html .= '</div>';
258 }
259
260 if ( $options['display_excerpt'] ) {
261 $html .= '<p class="vk_post_excerpt ' . $layout_type . '-text">';
262 $html .= wp_kses_post( get_the_excerpt( $post->ID ) );
263 $html .= '</p>';
264 }
265
266 if ( $options['display_btn'] ) {
267 $button_options = array(
268 'outer_id' => '',
269 'outer_class' => '',
270 'btn_text' => $options['btn_text'],
271 'btn_url' => get_the_permalink( $post->ID ),
272 'btn_class' => 'btn btn-sm btn-primary vk_post_btn',
273 'btn_target' => '',
274 'btn_ghost' => false,
275 'btn_color_text' => '',
276 'btn_color_bg' => '',
277 'shadow_use' => false,
278 'shadow_color' => '',
279 );
280
281 // $text_align = '';
282 // if ( $options['btn_align'] == 'right' ) {
283 // $text_align = ' text-right';
284 // }
285 $html .= '<div class="vk_post_btnOuter ' . $options['btn_align'] . '">';
286 $html .= VK_Component_Button::get_view( $button_options );
287 $html .= '</div>';
288 }
289
290 if ( ! empty( $options['body_append'] ) ) {
291 $html .= $options['body_append'];
292 }
293
294 $html .= '</div><!-- [ /.' . $layout_type . '-body ] -->';
295
296 return $html;
297 }
298
299 /*-------------------------------------------*/
300 /* Layout patterns
301 /*-------------------------------------------*/
302 /**
303 * Card
304 * @var [type]
305 */
306 static public function get_view_type_card( $post, $options ) {
307 $html = '';
308 $html .= self::get_view_first_div( $post, $options );
309
310 $attr = array(
311 'class_outer' => '',
312 'class_image' => 'card-img-top',
313 );
314 $html .= self::get_thumbnail_image( $post, $options, $attr );
315
316 $html .= self::get_view_body( $post, $options );
317
318 $html .= '</div><!-- [ /.card ] -->';
319 return $html;
320 }
321
322 /**
323 * Card horizontal
324 * @var [type]
325 */
326 static public function get_view_type_card_horizontal( $post, $options ) {
327 $html = '';
328 $html .= self::get_view_first_div( $post, $options );
329 // $html .= '<a href="' . get_the_permalink( $post->ID ) . '" class="card-horizontal-inner">';
330 $html .= '<div class="row no-gutters card-horizontal-inner-row">';
331
332 // $image_src = '';
333 if ( $options['display_image'] ) {
334 $html .= '<div class="col-5 card-img-outer">';
335 $attr = array(
336 'class_outer' => '',
337 'class_image' => 'card-img card-img-use-bg',
338 );
339 $html .= self::get_thumbnail_image( $post, $options, $attr );
340 $html .= '</div><!-- /.col -->';
341 $html .= '<div class="col-7">';
342 }
343
344 $html .= self::get_view_body( $post, $options );
345
346 if ( $options['display_image'] ) {
347 $html .= '</div><!-- /.col -->';
348 }
349
350 $html .= '</div><!-- [ /.row ] -->';
351 // $html .= '</a>';
352 $html .= '</div><!-- [ /.card ] -->';
353 return $html;
354 }
355
356 /**
357 * Media
358 * @var [type]
359 */
360 static public function get_view_type_media( $post, $options ) {
361 $html = '';
362 $html .= self::get_view_first_div( $post, $options );
363 if ( $options['display_image'] ) {
364 // $html .= '<a href="' . get_the_permalink() . '" class="media-img">';
365 $attr = array(
366 'class_outer' => 'media-img',
367 'class_image' => '',
368 );
369 $html .= self::get_thumbnail_image( $post, $options, $attr );
370 // $html .= '</a>';
371 }
372
373 // $attr = array(
374 // 'textlink' => true,
375 // );
376 $html .= self::get_view_body( $post, $options );
377
378 $html .= '</div><!-- [ /.media ] -->';
379 return $html;
380 }
381
382 /*-------------------------------------------*/
383 /* UI Helper method
384 /*-------------------------------------------*/
385 /**
386 * Convert col-count from inputed column count.
387 * @param integer $input_col [description]
388 * @return [type] [description]
389 */
390 public static function get_col_converted_size( $input_col = 4 ) {
391 if ( $input_col == 1 ) {
392 $col = 12;
393 } elseif ( $input_col == 2 ) {
394 $col = 6;
395 } elseif ( $input_col == 3 ) {
396 $col = 4;
397 } elseif ( $input_col == 4 ) {
398 $col = 3;
399 }
400 return strval( $col );
401 }
402
403 /**
404 * Get all size col classes
405 * @param [type] $attributes inputed col numbers array
406 * @return [type] [description]
407 */
408 public static function get_col_size_classes( $attributes ) {
409 $col_class_array = array();
410 $sizes = array( 'xs', 'sm', 'md', 'lg', 'xl' );
411 foreach ( $sizes as $key => $size ) {
412 if ( ! empty( $attributes[ 'col_' . $size ] ) ) {
413 $col_class_array[] = 'vk_post-col-' . $size . '-' . self::get_col_converted_size( $attributes[ 'col_' . $size ] );
414 }
415 }
416 $col_class = implode( ' ', $col_class_array );
417 return $col_class;
418 }
419
420 }
421 }
422