PluginProbe
GamiPress – Gamification plugin to reward points, badges & ranks in WordPress, now with AI / 7.9.9
GamiPress – Gamification plugin to reward points, badges & ranks in WordPress, now with AI v7.9.9
8.0.5 8.0.4 8.0.3 8.0.1 8.0.2 8.0.0 7.9.9.7 7.9.9.6 7.9.9.5 7.9.9.4 7.9.9.3 7.9.9.2 7.9.9.1 7.9.9 7.9.8 7.9.7 7.9.6 7.9.5 7.9.4 7.9.3 7.9.2 7.9.1 7.9.0 7.8.9 7.8.8 All 47 releases
gamipress / includes / compatibility / 1.4.7.php

1.4.7.php in GamiPress – Gamification plugin to reward points, badges & ranks in WordPress, now with AI 7.9.9, at includes/compatibility/1.4.7.php

208 lines 6.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * GamiPress 1.4.7 compatibility functions
4 *
5 * @package GamiPress\1.4.7
6 * @author GamiPress <[email protected]>, Ruben Garcia <[email protected]>
7 * @since 1.4.7
8 */
9 // Exit if accessed directly
10 if( !defined( 'ABSPATH' ) ) exit;
11
12 /**
13 * Get an array of post IDs for achievements that are marked as "hidden"
14 *
15 * @deprecated
16 *
17 * @see gamipress_is_achievement_hidden()
18 *
19 * @since 1.0.0
20 *
21 * @param integer $achievement_id Limit the array to a specific id of achievement
22 *
23 * @return array An array of hidden achievement post IDs
24 */
25
26 function gamipress_get_hidden_achievement_by_id( $achievement_id ) {
27
28 // Grab our hidden achievements
29 global $wpdb;
30
31 $posts = GamiPress()->db->posts;
32 $postmeta = GamiPress()->db->postmeta;
33
34 //Get hidden achievement posts.
35 $hidden_achievements = $wpdb->get_results( $wpdb->prepare(
36 "
37 SELECT *
38 FROM {$posts} AS p
39 JOIN {$postmeta} AS pm
40 ON p.ID = pm.post_id
41 WHERE p.ID = %d
42 AND pm.meta_key = '_gamipress_hidden'
43 AND pm.meta_value = 'hidden'
44 ",
45 $achievement_id));
46
47 // Return our results
48 return $hidden_achievements;
49 }
50
51 /**
52 * Posts a log entry when a user unlocks any achievement post
53 *
54 * @since 1.0.0
55 * @updated 1.2.8 Added $type
56 *
57 * @param string $type The log type
58 * @param int $user_id The user ID
59 * @param string $access Access to this log ( public|private )
60 * @param array $log_meta Log meta data
61 *
62 * @return integer The log ID of the newly created log entry
63 */
64 function gamipress_insert_log_old_147( $type = '', $user_id = 0, $access = 'public', $log_meta = array() ) {
65
66 // If not properly upgrade to required version fallback to compatibility function
67 if( ! is_gamipress_upgraded_to( '1.2.8' ) ) {
68
69 $log_meta['type'] = $type;
70
71 return gamipress_insert_log_old( $user_id, $access, $log_meta );
72 }
73
74 // Setup table
75 ct_setup_table( 'gamipress_logs' );
76
77 // Post data
78 $log_data = array(
79 'title' => '',
80 'description' => '',
81 'type' => $type,
82 'access' => $access,
83 'user_id' => $user_id === 0 ? get_current_user_id() : absint( $user_id ),
84 'date' => date( 'Y-m-d H:i:s', current_time( 'timestamp' ) ),
85 );
86
87 // Auto-generated post title
88 $log_data['title'] = gamipress_parse_log_pattern( $log_meta['pattern'], $log_data, $log_meta );
89
90 // Store log entry
91 $log_id = ct_insert_object( $log_data );
92
93 // Store log meta data
94 if ( $log_id && ! empty( $log_meta ) ) {
95
96 foreach ( (array) $log_meta as $key => $meta ) {
97
98 ct_update_object_meta( $log_id, '_gamipress_' . sanitize_key( $key ), $meta );
99
100 }
101
102 }
103
104 // Hook to add custom data
105 do_action( 'gamipress_insert_log', $log_id, $log_data, $log_meta, $user_id );
106
107 ct_reset_setup_table();
108
109 return $log_id;
110
111 }
112
113 /**
114 * Get the count for the number of times is logged a user has triggered a particular trigger
115 *
116 * @since 1.0.0
117 *
118 * @param integer $user_id The given user's ID
119 * @param string $trigger The given trigger we're checking
120 * @param integer $since The since timestamp where retrieve the logs
121 * @param integer $site_id The desired Site ID to check
122 * @param array $args The triggered args or requirement object
123 *
124 * @return integer The total number of times a user has triggered the trigger
125 */
126 function gamipress_get_user_trigger_count_old_147( $user_id, $trigger, $since = 0, $site_id = 0, $args = array() ) {
127
128 // If not properly upgrade to required version fallback to compatibility function
129 if( ! is_gamipress_upgraded_to( '1.2.8' ) ) {
130 return gamipress_get_user_trigger_count_old( $user_id, $trigger, $since, $site_id, $args );
131 }
132
133 global $wpdb;
134
135 $logs = GamiPress()->db->logs;
136 $logs_meta = GamiPress()->db->logs_meta;
137
138 // Set to current site id
139 if ( ! $site_id )
140 $site_id = get_current_blog_id();
141
142 // Setup date conditional
143 $date = '';
144
145 if( $since !== 0 ) {
146 $since = date( 'Y-m-d H:i:s', $since );
147
148 $date = "AND l.date >= '$since'";
149 }
150
151 // If is specific trigger then try to get the attached id
152 if( in_array( $trigger, array_keys( gamipress_get_specific_activity_triggers() ) ) ) {
153
154 $specific_id = 0;
155
156 // if isset this key it means $args is a requirement object
157 if( isset( $args['achievement_post'] ) ) {
158 $specific_id = absint( $args['achievement_post'] );
159 } else if( ! empty( $args ) ) {
160 $specific_id = gamipress_specific_trigger_get_id( $trigger, $args );
161 }
162
163 // If there is a specific id, then try to find the count
164 if( $specific_id !== 0 ) {
165 $user_triggers = $wpdb->get_var( $wpdb->prepare(
166 "SELECT COUNT(*)
167 FROM {$logs} AS l
168 INNER JOIN {$logs_meta} AS lm1 ON ( l.log_id = lm1.log_id )
169 INNER JOIN {$logs_meta} AS lm2 ON ( l.log_id = lm2.log_id )
170 WHERE l.user_id = %d
171 AND l.type = %s
172 {$date}
173 AND (
174 ( lm1.meta_key = %s AND lm1.meta_value = %s )
175 AND ( lm2.meta_key = %s AND lm2.meta_value = %s )
176 )
177 ",
178 absint( $user_id ),
179 'event_trigger',
180 '_gamipress_trigger_type', $trigger,
181 '_gamipress_achievement_post', $specific_id
182 ) );
183 } else {
184 return 0;
185 }
186 } else {
187 // Single trigger count
188 $user_triggers = $wpdb->get_var( $wpdb->prepare(
189 "SELECT COUNT(*)
190 FROM {$logs} AS l
191 INNER JOIN {$logs_meta} AS lm ON ( l.log_id = lm.log_id )
192 WHERE l.user_id = %d
193 AND l.type = %s
194 {$date}
195 AND (
196 lm.meta_key = %s AND lm.meta_value = %s
197 )
198 ",
199 absint( $user_id ),
200 'event_trigger',
201 '_gamipress_trigger_type', $trigger
202 ) );
203 }
204
205 // If we have any triggers, return the current count for the given trigger
206 return absint( $user_triggers );
207
208 }