PluginProbe
Meow Gallery / trunk
Meow Gallery vtrunk
5.5.4 5.5.3 5.5.2 5.5.1 5.5.0 5.4.9 5.4.8 5.4.7 4.1.5 4.1.6 4.1.7 4.1.8 4.1.9 4.2.0 4.2.1 4.2.2 4.2.3 4.2.4 4.2.5 4.2.6 4.2.7 4.2.8 4.2.9 4.3.0 4.3.1 All 156 releases
meow-gallery / classes / orderby.php

orderby.php in Meow Gallery trunk, at classes/orderby.php

72 lines 1.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 class Meow_MGL_OrderBy {
4
5 public $admin = null;
6
7 static function run( $images, $orderby = null, $order = 'asc' ) {
8 $sqlOrderBy = '';
9 $order = strtolower( $order );
10
11 // Check params
12 switch ( $orderby ) {
13 case 'ids':
14 $order === 'asc' ? sort( $images ) : rsort( $images );
15 break;
16
17 case 'random':
18 shuffle( $images );
19 return $images;
20 break;
21
22 case 'date':
23 $sqlOrderBy = $order === 'asc'
24 ? ' ORDER BY p.post_date ASC'
25 : ' ORDER BY p.post_date DESC';
26 break;
27
28 case 'modified':
29 $sqlOrderBy = $order === 'asc'
30 ? ' ORDER BY p.post_modified ASC'
31 : ' ORDER BY p.post_modified DESC';
32 break;
33
34 case 'filename':
35 case 'title':
36 $sqlOrderBy = $order === 'asc'
37 ? ' ORDER BY p.post_title ASC'
38 : ' ORDER BY p.post_title DESC';
39 break;
40
41 case 'menu':
42 $sqlOrderBy = $order === 'asc'
43 ? ' ORDER BY p.menu_order ASC'
44 : ' ORDER BY p.menu_order DESC';
45 break;
46
47 case 'none':
48 return $images;
49
50 default:
51 // no ordering
52 break;
53 }
54
55 // Apply sort
56 if ( !empty( $sqlOrderBy ) ) {
57 global $wpdb;
58 $wpIdsPlaceHolders = array_fill( 0, count( $images ), '%d' );
59 $wpIdsPlaceHolders = implode( ', ', $wpIdsPlaceHolders );
60 $query = $wpdb->prepare( "SELECT p.ID
61 FROM $wpdb->posts p
62 WHERE p.ID IN ($wpIdsPlaceHolders)" . $sqlOrderBy, $images );
63 $images = $wpdb->get_col( $query );
64
65 }
66 return $images;
67 }
68
69 }
70
71 ?>
72