PluginProbe
WP Ultimate Post Grid / 1.6
WP Ultimate Post Grid v1.6
4.1.1 trunk 1.5 1.6 1.7 1.7.1 1.7.2 1.8 1.9 2.0 2.1 2.2 2.3 2.4.0 2.5.0 2.6.0 2.7.0 2.8.0 2.8.2 3.0.0 3.3.0 3.4.0 3.5.0 3.6.0 3.7.0 All 32 releases
← All changes | helpers/models/grid.php +24 -207 2.2 → 1.6 View file →
@@ -5,37 +5,22 @@
5 5 private $post;
6 6 private $meta;
7 7 private $fields = array(
8 8 'wpupg_centered',
9 - 'wpupg_empty_message',
10 9 'wpupg_images_only',
11 - 'wpupg_filter_count',
12 - 'wpupg_filter_inverse',
13 - 'wpupg_filter_limit',
14 - 'wpupg_filter_limit_exclude',
15 10 'wpupg_filter_match_parents',
16 11 'wpupg_filter_multiselect',
17 12 'wpupg_filter_multiselect_type',
18 - 'wpupg_filter_show_empty',
19 13 'wpupg_filter_type',
20 14 'wpupg_pagination_type',
21 15 'wpupg_post_types',
22 16 'wpupg_layout_mode',
23 17 'wpupg_limit_posts',
24 - 'wpupg_limit_posts_number',
25 18 'wpupg_link_target',
26 19 'wpupg_link_type',
27 20 'wpupg_order_by',
28 21 'wpupg_order',
29 - 'wpupg_order_custom_key',
30 - 'wpupg_order_custom_key_numeric',
31 - 'wpupg_taxonomies',
32 22 'wpupg_template',
33 - 'wpupg_terms_hide_empty',
34 - 'wpupg_terms_images_only',
35 - 'wpupg_terms_order_by',
36 - 'wpupg_terms_order',
37 - 'wpupg_type',
38 23 );
39 24
40 25 // Pagination fields with defaults
41 26 private $pagination_fields = array(
@@ -41,20 +26,13 @@
41 26 private $pagination_fields = array(
42 27 'pages' => array(
43 28 'posts_per_page' => 20,
44 29 ),
45 - 'infinite_load' => array(
46 - 'initial_posts' => 20,
47 - 'posts_on_scroll' => 20,
48 - ),
49 30 'load_more' => array(
50 31 'initial_posts' => 20,
51 32 'posts_on_click' => 20,
52 33 'button_text' => 'Load More',
53 34 ),
54 - 'load_filter' => array(
55 - 'initial_posts' => 20,
56 - ),
57 35 );
58 36
59 37 private $pagination_style_fields = array(
60 38 'background_color' => '#2E5077',
@@ -160,13 +138,8 @@
160 138 {
161 139 return $this->meta( 'wpupg_centered' );
162 140 }
163 141
164 - public function empty_message()
165 - {
166 - return $this->meta( 'wpupg_empty_message' );
167 - }
168 -
169 142 public function filter()
170 143 {
171 144 return $this->meta( 'wpupg_filter' );
172 145 }
@@ -172,15 +145,17 @@
172 145 }
173 146
174 147 public function filter_taxonomies()
175 148 {
176 - $filter_taxonomies = maybe_unserialize( $this->meta( 'wpupg_filter_taxonomies' ) );
149 + $filter_taxonomies = $this->meta( 'wpupg_filter_taxonomies' );
150 + $filter_taxonomies = is_null( $filter_taxonomies ) ? null : unserialize( $filter_taxonomies );
177 151 return is_array( $filter_taxonomies ) ? $filter_taxonomies : array();
178 152 }
179 153
180 154 public function filter_style()
181 155 {
182 - $filter_style = maybe_unserialize( $this->meta( 'wpupg_filter_style' ) );
156 + $filter_style = $this->meta( 'wpupg_filter_style' );
157 + $filter_style = is_null( $filter_style ) ? null : unserialize( $filter_style );
183 158 $filter_style = is_array( $filter_style ) ? $filter_style : array();
184 159
185 160 // Set defaults
186 161 foreach( $this->filter_style_fields() as $type => $defaults ) {
@@ -189,44 +164,8 @@
189 164
190 165 return $filter_style;
191 166 }
192 167
193 - public function filter_dropdown_labels()
194 - {
195 - $dropdown_labels = maybe_unserialize( $this->meta( 'wpupg_filter_dropdown_labels' ) );
196 - return is_array( $dropdown_labels ) ? $dropdown_labels : array();
197 - }
198 -
199 - public function filter_count()
200 - {
201 - if( WPUltimatePostGrid::is_premium_active() ) {
202 - return $this->meta( 'wpupg_filter_count' );
203 - } else {
204 - return false;
205 - }
206 - }
207 -
208 - public function filter_inverse()
209 - {
210 - return $this->meta( 'wpupg_filter_inverse' );
211 - }
212 -
213 - public function filter_limit()
214 - {
215 - return $this->meta( 'wpupg_filter_limit' );
216 - }
217 -
218 - public function filter_limit_exclude()
219 - {
220 - return $this->meta( 'wpupg_filter_limit_exclude' );
221 - }
222 -
223 - public function filter_limit_terms()
224 - {
225 - $limit_terms = maybe_unserialize( $this->meta( 'wpupg_filter_limit_terms' ) );
226 - return is_array( $limit_terms ) ? $limit_terms : array();
227 - }
228 -
229 168 public function filter_match_parents()
230 169 {
231 170 return $this->meta( 'wpupg_filter_match_parents' );
232 171 }
@@ -244,13 +183,8 @@
244 183 {
245 184 return $this->meta( 'wpupg_filter_multiselect_type' );
246 185 }
247 186
248 - public function filter_show_empty()
249 - {
250 - return $this->meta( 'wpupg_filter_show_empty' );
251 - }
252 -
253 187 public function filter_type()
254 188 {
255 189 return $this->meta( 'wpupg_filter_type' );
256 190 }
@@ -275,17 +209,12 @@
275 209 {
276 210 return $this->meta( 'wpupg_limit_posts' );
277 211 }
278 212
279 - public function limit_posts_number()
280 - {
281 - $limit = intval( $this->meta( 'wpupg_limit_posts_number' ) );
282 - return $limit > 0 ? $limit : '';
283 - }
284 -
285 213 public function limit_rules()
286 214 {
287 - $limit_rules = maybe_unserialize( $this->meta( 'wpupg_limit_rules' ) );
215 + $limit_rules = $this->meta( 'wpupg_limit_rules' );
216 + $limit_rules = is_null( $limit_rules ) ? null : unserialize( $limit_rules );
288 217 return is_array( $limit_rules ) ? $limit_rules : array();
289 218 }
290 219
291 220 public function link_target()
@@ -309,21 +238,12 @@
309 238 {
310 239 return $this->meta( 'wpupg_order_by' );
311 240 }
312 241
313 - public function order_custom_key()
314 - {
315 - return $this->meta( 'wpupg_order_custom_key' );
316 - }
317 -
318 - public function order_custom_key_numeric()
319 - {
320 - return $this->meta( 'wpupg_order_custom_key_numeric' );
321 - }
322 -
323 242 public function pagination()
324 243 {
325 - $pagination = maybe_unserialize( $this->meta( 'wpupg_pagination' ) );
244 + $pagination = $this->meta( 'wpupg_pagination' );
245 + $pagination = is_null( $pagination ) ? null : unserialize( $pagination );
326 246 $pagination = is_array( $pagination ) ? $pagination : array();
327 247
328 248 // Set defaults
329 249 foreach( $this->pagination_fields() as $type => $defaults ) {
@@ -334,9 +254,10 @@
334 254 }
335 255
336 256 public function pagination_style()
337 257 {
338 - $pagination_style = maybe_unserialize( $this->meta( 'wpupg_pagination_style' ) );
258 + $pagination_style = $this->meta( 'wpupg_pagination_style' );
259 + $pagination_style = is_null( $pagination_style ) ? null : unserialize( $pagination_style );
339 260 $pagination_style = is_array( $pagination_style ) ? $pagination_style : array();
340 261
341 262 // Set defaults
342 263 $pagination_style = $pagination_style + $this->pagination_style_fields();
@@ -350,9 +271,10 @@
350 271 }
351 272
352 273 public function posts()
353 274 {
354 - $posts = maybe_unserialize( $this->meta( 'wpupg_posts' ) );
275 + $posts = $this->meta( 'wpupg_posts' );
276 + $posts = is_null( $posts ) ? null : unserialize( $posts );
355 277 return is_array( $posts ) ? $posts : array();
356 278 }
357 279
358 280 public function post()
@@ -359,16 +281,17 @@
359 281 {
360 282 return $this->post;
361 283 }
362 284
363 - public function post_status()
285 + public function post_status() // TODO
364 286 {
365 - return in_array( 'attachment', $this->post_types() ) ? array( 'publish', 'inherit' ) : 'publish';
287 + return 'publish';
366 288 }
367 289
368 290 public function post_types()
369 291 {
370 - $post_types = maybe_unserialize( $this->meta( 'wpupg_post_types' ) );
292 + $post_types = $this->meta( 'wpupg_post_types' );
293 + $post_types = is_null( $post_types ) ? null : unserialize( $post_types );
371 294 return is_array( $post_types ) ? $post_types : array();
372 295 }
373 296
374 297 public function slug()
@@ -375,14 +298,8 @@
375 298 {
376 299 return $this->post->post_name;
377 300 }
378 301
379 - public function taxonomies()
380 - {
381 - $taxonomies = maybe_unserialize( $this->meta( 'wpupg_taxonomies' ) );
382 - return is_array( $taxonomies ) ? $taxonomies : array();
383 - }
384 -
385 302 public function template()
386 303 {
387 304 return WPUltimatePostGrid::addon( 'custom-templates' )->get_template( $this->template_id() );
388 305 }
@@ -391,39 +308,13 @@
391 308 {
392 309 return $this->meta( 'wpupg_template' );
393 310 }
394 311
395 - public function terms_hide_empty()
396 - {
397 - return $this->meta( 'wpupg_terms_hide_empty' );
398 - }
399 -
400 - public function terms_images_only()
401 - {
402 - return $this->meta( 'wpupg_terms_images_only' );
403 - }
404 -
405 - public function terms_order()
406 - {
407 - return $this->meta( 'wpupg_terms_order' );
408 - }
409 -
410 - public function terms_order_by()
411 - {
412 - return $this->meta( 'wpupg_terms_order_by' );
413 - }
414 -
415 312 public function title()
416 313 {
417 314 return $this->post->post_title;
418 315 }
419 316
420 - public function type()
421 - {
422 - $type = $this->meta( 'wpupg_type' );
423 - return $type ? $type : 'posts';
424 - }
425 -
426 317 /**
427 318 * Helper functions
428 319 */
429 320
@@ -431,9 +322,10 @@
431 322 {
432 323 if( WPUltimatePostGrid::is_premium_active() ) {
433 324 $this->meta['wpupg_limit_posts'][0] = 'on';
434 325
435 - $limit_rules = maybe_unserialize( $this->meta( 'wpupg_limit_rules' ) );
326 + $limit_rules = $this->meta( 'wpupg_limit_rules' );
327 + $limit_rules = is_null( $limit_rules ) ? null : unserialize( $limit_rules );
436 328 $limit_rules = is_array( $limit_rules ) ? $limit_rules : array();
437 329
438 330 $new_rules = array_merge( $limit_rules, $dynamic_rules );
439 331 $this->meta['wpupg_limit_rules'][0] = serialize( $new_rules );
@@ -444,12 +336,12 @@
444 336 $this->meta['wpupg_filter'][0] = $generated['filter'];
445 337 }
446 338 }
447 339
448 - public function get_posts( $page = 0, $post_ids = null )
340 + public function get_posts( $page = 0 )
449 341 {
450 342 $grid_posts = $this->posts();
451 - $post_ids = is_null( $post_ids ) ? $grid_posts['all'] : array_intersect( $post_ids, $grid_posts['all'] );
343 + $post_ids = $grid_posts['all'];
452 344
453 345 if( count( $post_ids ) == 0 ) return array();
454 346
455 347 $posts_per_page = -1;
@@ -464,10 +356,10 @@
464 356 $offset = $page * $posts_per_page;
465 357 }
466 358
467 359 $args = array(
468 - 'post_type' => $this->post_types(), // "any" doesn't work for private post types.
469 - 'post_status' => 'any',
360 + 'post_type' => 'any',
361 + 'orderby' => $this->order_by(),
470 362 'order' => $this->order(),
471 363 'posts_per_page' => $posts_per_page,
472 364 'offset' => $offset,
473 365 'post__in' => $post_ids,
@@ -473,15 +365,8 @@
473 365 'post__in' => $post_ids,
474 366 'ignore_sticky_posts' => true,
475 367 );
476 368
477 - if( $this->order_by() == 'custom' ) {
478 - $args['meta_key'] = $this->order_custom_key();
479 - $args['orderby'] = $this->order_custom_key_numeric() ? 'meta_value_num' : 'meta_value';
480 - } else {
481 - $args['orderby'] = $this->order_by();
482 - }
483 -
484 369 $args = apply_filters( 'wpupg_get_posts_args', $args, $page, $this );
485 370
486 371 if( $args['posts_per_page'] == -1 ) {
487 372 $args['nopaging'] = true;
@@ -492,18 +377,13 @@
492 377
493 378 return $posts;
494 379 }
495 380
496 - public function draw_posts( $page = 0, $post_ids = null )
381 + public function draw_posts( $page = 0 )
497 382 {
498 - if( $this->type() == 'terms' ) {
499 - return $this->draw_terms();
500 - }
501 -
502 - // Draw Posts
503 383 $output = '';
504 384 $grid_posts = $this->posts();
505 - $posts = $this->get_posts( $page, $post_ids );
385 + $posts = $this->get_posts( $page );
506 386
507 387 foreach( $posts as $post ) {
508 388 $post_id = $post->ID;
509 389
@@ -520,71 +400,8 @@
520 400 $classes[] = 'wpupg-tax-' . $taxonomy . '-' . $term;
521 401 }
522 402 }
523 403 }
524 -
525 - $classes = apply_filters( 'wpupg_output_grid_classes', $classes, $this );
526 - $template = apply_filters( 'wpupg_output_grid_template', $this->template(), $this );
527 - $post = apply_filters( 'wpupg_output_grid_post', $post, $this );
528 -
529 - $output .= apply_filters( 'wpupg_output_grid_html', $template->output_string( $post, $classes ), $template, $post, $classes );
530 - }
531 -
532 - return $output;
533 - }
534 -
535 - public function draw_terms()
536 - {
537 - $output = '';
538 -
539 - $args = array(
540 - 'orderby' => $this->terms_order_by(),
541 - 'order' => $this->terms_order(),
542 - 'hide_empty' => $this->terms_hide_empty(),
543 - );
544 -
545 - if( $this->terms_images_only() ) {
546 - $args['meta_query'] = array(
547 - array(
548 - 'key' => 'wpupg_custom_image',
549 - 'compare' => '!=',
550 - 'value' => '',
551 - )
552 - );
553 - }
554 -
555 - $terms = get_terms( $this->taxonomies(), $args );
556 -
557 - foreach( $terms as $term ) {
558 - // Emulate post object
559 - $post = (object) array(
560 - 'term' => true,
561 - 'ID' => $term->term_id,
562 - 'post_author' => '',
563 - 'post_name' => $term->slug,
564 - 'post_type' => $term->taxonomy,
565 - 'post_title' => $term->name,
566 - 'post_date' => '0000-00-00 00:00:00',
567 - 'post_date_gmt' => '0000-00-00 00:00:00',
568 - 'post_content' => $term->description,
569 - 'post_excerpt' => $term->description,
570 - 'post_status' => 'publish',
571 - 'comment_status' => 'open',
572 - 'ping_status' => 'open',
573 - 'post_password' => '',
574 - 'post_parent' => $term->parent,
575 - 'post_modified' => '0000-00-00 00:00:00',
576 - 'post_modified_gmt' => '0000-00-00 00:00:00',
577 - 'comment_count' => '0',
578 - 'menu_order' => '0',
579 - );
580 -
581 - $classes = array(
582 - 'wpupg-item',
583 - 'wpupg-page-0',
584 - 'wpupg-post-' . $post->ID,
585 - 'wpupg-type-' . $post->post_type,
586 - );
587 404
588 405 $classes = apply_filters( 'wpupg_output_grid_classes', $classes, $this );
589 406 $template = apply_filters( 'wpupg_output_grid_template', $this->template(), $this );
590 407 $post = apply_filters( 'wpupg_output_grid_post', $post, $this );