1 | diff -crB ori/bp-activity/bp-activity-classes.php mod/bp-activity/bp-activity-classes.php |
---|
2 | *** ori/bp-activity/bp-activity-classes.php 2011-06-10 11:41:33.951771397 +0200 |
---|
3 | --- mod/bp-activity/bp-activity-classes.php 2011-05-27 02:15:59.000000000 +0200 |
---|
4 | *************** |
---|
5 | *** 86,92 **** |
---|
6 | |
---|
7 | /* Static Functions */ |
---|
8 | |
---|
9 | ! function get( $max = false, $page = 1, $per_page = 25, $sort = 'DESC', $search_terms = false, $filter = false, $display_comments = false, $show_hidden = false ) { |
---|
10 | global $wpdb, $bp; |
---|
11 | |
---|
12 | /* Select conditions */ |
---|
13 | --- 86,92 ---- |
---|
14 | |
---|
15 | /* Static Functions */ |
---|
16 | |
---|
17 | ! function get( $max = false, $page = 1, $per_page = 25, $sort = 'DESC', $search_terms = false, $filter = false, $display_comments = false, $show_hidden = false, $order = false) { |
---|
18 | global $wpdb, $bp; |
---|
19 | |
---|
20 | /* Select conditions */ |
---|
21 | *************** |
---|
22 | *** 110,115 **** |
---|
23 | --- 110,133 ---- |
---|
24 | /* Sorting */ |
---|
25 | if ( $sort != 'ASC' && $sort != 'DESC' ) |
---|
26 | $sort = 'DESC'; |
---|
27 | + |
---|
28 | + /* Ordering */ //added by Federico Rampazzo 27/05/2011 |
---|
29 | + switch ( $order ){ |
---|
30 | + case 'comments': |
---|
31 | + $select_sql .= ", (SELECT COUNT(id) |
---|
32 | + FROM {$bp->activity->table_name} |
---|
33 | + WHERE item_id=a.id) AS comments"; |
---|
34 | + break; |
---|
35 | + case 'favourites': |
---|
36 | + $select_sql .= ", (SELECT meta_value |
---|
37 | + FROM {$bp->activity->table_name_meta} |
---|
38 | + WHERE activity_id=a.id |
---|
39 | + AND meta_key='favorite_count') AS favourites"; |
---|
40 | + break; |
---|
41 | + default: |
---|
42 | + $order = 'a.date_recorded'; |
---|
43 | + break; |
---|
44 | + } |
---|
45 | |
---|
46 | /* Hide Hidden Items? */ |
---|
47 | if ( !$show_hidden ) |
---|
48 | *************** |
---|
49 | *** 124,132 **** |
---|
50 | |
---|
51 | if ( $per_page && $page ) { |
---|
52 | $pag_sql = $wpdb->prepare( "LIMIT %d, %d", intval( ( $page - 1 ) * $per_page ), intval( $per_page ) ); |
---|
53 | ! $activities = $wpdb->get_results( $wpdb->prepare( "{$select_sql} {$from_sql} {$where_sql} ORDER BY a.date_recorded {$sort} {$pag_sql}" ) ); |
---|
54 | } else |
---|
55 | ! $activities = $wpdb->get_results( $wpdb->prepare( "{$select_sql} {$from_sql} {$where_sql} ORDER BY a.date_recorded {$sort} {$pag_sql}" ) ); |
---|
56 | |
---|
57 | $total_activities = $wpdb->get_var( $wpdb->prepare( "SELECT count(a.id) FROM {$bp->activity->table_name} a {$where_sql} ORDER BY a.date_recorded {$sort}" ) ); |
---|
58 | |
---|
59 | --- 142,150 ---- |
---|
60 | |
---|
61 | if ( $per_page && $page ) { |
---|
62 | $pag_sql = $wpdb->prepare( "LIMIT %d, %d", intval( ( $page - 1 ) * $per_page ), intval( $per_page ) ); |
---|
63 | ! $activities = $wpdb->get_results( $wpdb->prepare( "{$select_sql} {$from_sql} {$where_sql} ORDER BY {$order} {$sort} {$pag_sql}" ) ); |
---|
64 | } else |
---|
65 | ! $activities = $wpdb->get_results( $wpdb->prepare( "{$select_sql} {$from_sql} {$where_sql} ORDER BY {$order} {$sort} {$pag_sql}" ) ); |
---|
66 | |
---|
67 | $total_activities = $wpdb->get_var( $wpdb->prepare( "SELECT count(a.id) FROM {$bp->activity->table_name} a {$where_sql} ORDER BY a.date_recorded {$sort}" ) ); |
---|
68 | |
---|
69 | *************** |
---|
70 | *** 166,173 **** |
---|
71 | return array( 'activities' => $activities, 'total' => (int)$total_activities ); |
---|
72 | } |
---|
73 | |
---|
74 | ! function get_specific( $activity_ids, $max = false, $page = 1, $per_page = 25, $sort = 'DESC', $display_comments = false ) { |
---|
75 | global $wpdb, $bp; |
---|
76 | |
---|
77 | if ( is_array( $activity_ids ) ) |
---|
78 | $activity_ids = implode( ',', $activity_ids ); |
---|
79 | --- 184,193 ---- |
---|
80 | return array( 'activities' => $activities, 'total' => (int)$total_activities ); |
---|
81 | } |
---|
82 | |
---|
83 | ! function get_specific( $activity_ids, $max = false, $page = 1, $per_page = 25, $sort = 'DESC', $display_comments = false, $order = false ) { |
---|
84 | global $wpdb, $bp; |
---|
85 | + |
---|
86 | + $select_sql = 'SELECT *'; |
---|
87 | |
---|
88 | if ( is_array( $activity_ids ) ) |
---|
89 | $activity_ids = implode( ',', $activity_ids ); |
---|
90 | *************** |
---|
91 | *** 182,189 **** |
---|
92 | |
---|
93 | if ( $sort != 'ASC' && $sort != 'DESC' ) |
---|
94 | $sort = 'DESC'; |
---|
95 | |
---|
96 | ! $activities = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM {$bp->activity->table_name} WHERE id IN ({$activity_ids}) ORDER BY date_recorded {$sort} $pag_sql" ) ); |
---|
97 | $total_activities = $wpdb->get_var( $wpdb->prepare( "SELECT count(id) FROM {$bp->activity->table_name} WHERE id IN ({$activity_ids})" ) ); |
---|
98 | |
---|
99 | if ( $display_comments ) |
---|
100 | --- 202,227 ---- |
---|
101 | |
---|
102 | if ( $sort != 'ASC' && $sort != 'DESC' ) |
---|
103 | $sort = 'DESC'; |
---|
104 | + |
---|
105 | + /* Ordering */ //added by Federico Rampazzo 27/05/2011 |
---|
106 | + switch ( $order ){ |
---|
107 | + case 'comments': |
---|
108 | + $select_sql .= ", (SELECT COUNT(id) |
---|
109 | + FROM {$bp->activity->table_name} |
---|
110 | + WHERE item_id=a.id) AS comments"; |
---|
111 | + break; |
---|
112 | + case 'favourites': |
---|
113 | + $select_sql .= ", (SELECT meta_value |
---|
114 | + FROM {$bp->activity->table_name_meta} |
---|
115 | + WHERE activity_id=a.id |
---|
116 | + AND meta_key='favorite_count') AS favourites"; |
---|
117 | + break; |
---|
118 | + default: |
---|
119 | + $order = 'a.date_recorded'; |
---|
120 | + break; |
---|
121 | + } |
---|
122 | |
---|
123 | ! $activities = $wpdb->get_results( $wpdb->prepare( "{$select_sql} FROM {$bp->activity->table_name} AS a WHERE id IN ({$activity_ids}) ORDER BY {$order} {$sort} $pag_sql" ) ); |
---|
124 | $total_activities = $wpdb->get_var( $wpdb->prepare( "SELECT count(id) FROM {$bp->activity->table_name} WHERE id IN ({$activity_ids})" ) ); |
---|
125 | |
---|
126 | if ( $display_comments ) |
---|
127 | diff -crB ori/bp-activity.php mod/bp-activity.php |
---|
128 | *** ori/bp-activity.php 2011-06-10 11:42:03.747398901 +0200 |
---|
129 | --- mod/bp-activity.php 2011-05-27 02:01:00.000000000 +0200 |
---|
130 | *************** |
---|
131 | *** 595,609 **** |
---|
132 | |
---|
133 | $r = wp_parse_args( $args, $defaults ); |
---|
134 | extract( $r, EXTR_SKIP ); |
---|
135 | |
---|
136 | /* Attempt to return a cached copy of the first page of sitewide activity. */ |
---|
137 | if ( 1 == (int)$page && empty( $max ) && empty( $search_terms ) && empty( $filter ) && 'DESC' == $sort ) { |
---|
138 | if ( !$activity = wp_cache_get( 'bp_activity_sitewide_front', 'bp' ) ) { |
---|
139 | ! $activity = BP_Activity_Activity::get( $max, $page, $per_page, $sort, $search_terms, $filter, $display_comments, $show_hidden ); |
---|
140 | wp_cache_set( 'bp_activity_sitewide_front', $activity, 'bp' ); |
---|
141 | } |
---|
142 | } else |
---|
143 | ! $activity = BP_Activity_Activity::get( $max, $page, $per_page, $sort, $search_terms, $filter, $display_comments, $show_hidden ); |
---|
144 | |
---|
145 | return apply_filters( 'bp_activity_get', $activity, &$r ); |
---|
146 | } |
---|
147 | --- 595,612 ---- |
---|
148 | |
---|
149 | $r = wp_parse_args( $args, $defaults ); |
---|
150 | extract( $r, EXTR_SKIP ); |
---|
151 | + |
---|
152 | + $order = (isset($_COOKIE['order']) ? $_COOKIE['order'] : false); |
---|
153 | + $sort = (isset($_COOKIE['sort']) ? $_COOKIE['sort'] : 'DESC'); |
---|
154 | |
---|
155 | /* Attempt to return a cached copy of the first page of sitewide activity. */ |
---|
156 | if ( 1 == (int)$page && empty( $max ) && empty( $search_terms ) && empty( $filter ) && 'DESC' == $sort ) { |
---|
157 | if ( !$activity = wp_cache_get( 'bp_activity_sitewide_front', 'bp' ) ) { |
---|
158 | ! $activity = BP_Activity_Activity::get( $max, $page, $per_page, $sort, $search_terms, $filter, $display_comments, $show_hidden, $order); |
---|
159 | wp_cache_set( 'bp_activity_sitewide_front', $activity, 'bp' ); |
---|
160 | } |
---|
161 | } else |
---|
162 | ! $activity = BP_Activity_Activity::get( $max, $page, $per_page, $sort, $search_terms, $filter, $display_comments, $show_hidden, $order); |
---|
163 | |
---|
164 | return apply_filters( 'bp_activity_get', $activity, &$r ); |
---|
165 | } |
---|