Version Description
Bug fixes and BuddyPress 2.3+ comp.
=
Download this release
Release Info
Developer | designbymerovingi |
Plugin | myCRED |
Version | 1.6.5 |
Comparing to | |
See all releases |
Code changes from version 1.6.4 to 1.6.5
- abstracts/mycred-abstract-hook.php +122 -50
- abstracts/mycred-abstract-module.php +134 -37
- addons/badges/includes/mycred-badge-shortcodes.php +3 -2
- addons/badges/myCRED-addon-badges.php +1 -1
- addons/buy-creds/gateways/paypal-standard.php +2 -2
- addons/buy-creds/myCRED-addon-buy-creds.php +2 -2
- addons/coupons/myCRED-addon-coupons.php +1 -1
- addons/email-notices/myCRED-addon-email-notices.php +1 -1
- addons/notifications/myCRED-addon-notifications.php +1 -1
- addons/ranks/includes/mycred-rank-shortcodes.php +58 -50
- addons/ranks/myCRED-addon-ranks.php +1 -1
- addons/sell-content/myCRED-addon-sell-content.php +1 -1
- addons/transfer/myCRED-addon-transfer.php +1 -1
- assets/js/send.js +12 -5
- includes/mycred-shortcodes.php +27 -11
- lang/mycred-ja_JP.mo +0 -0
- lang/mycred-ja_JP.po +0 -0
- modules/mycred-module-buddypress.php +1 -1
- modules/mycred-module-hooks.php +12 -5
- mycred.php +3 -3
- plugins/mycred-hook-buddypress.php +966 -915
- plugins/mycred-hook-wp-postratings.php +2 -2
- readme.txt +45 -23
abstracts/mycred-abstract-hook.php
CHANGED
@@ -5,9 +5,9 @@ if ( ! defined( 'myCRED_VERSION' ) ) exit;
|
|
5 |
* myCRED_Hook class
|
6 |
* @see http://codex.mycred.me/classes/mycred_hook/
|
7 |
* @since 0.1
|
8 |
-
* @version 1.3
|
9 |
*/
|
10 |
-
if ( ! class_exists( 'myCRED_Hook' ) )
|
11 |
abstract class myCRED_Hook {
|
12 |
|
13 |
// Hook ID
|
@@ -30,6 +30,7 @@ if ( ! class_exists( 'myCRED_Hook' ) ) {
|
|
30 |
* Construct
|
31 |
*/
|
32 |
function __construct( $args = array(), $hook_prefs = NULL, $type = 'mycred_default' ) {
|
|
|
33 |
if ( ! empty( $args ) ) {
|
34 |
foreach ( $args as $key => $value ) {
|
35 |
$this->$key = $value;
|
@@ -50,6 +51,7 @@ if ( ! class_exists( 'myCRED_Hook' ) ) {
|
|
50 |
|
51 |
// Grab settings
|
52 |
if ( $hook_prefs !== NULL ) {
|
|
|
53 |
// Assign prefs if set
|
54 |
if ( isset( $hook_prefs[ $this->id ] ) )
|
55 |
$this->prefs = $hook_prefs[ $this->id ];
|
@@ -57,11 +59,13 @@ if ( ! class_exists( 'myCRED_Hook' ) ) {
|
|
57 |
// Defaults must be set
|
58 |
if ( ! isset( $this->defaults ) )
|
59 |
$this->defaults = array();
|
|
|
60 |
}
|
61 |
|
62 |
// Apply default settings if needed
|
63 |
if ( ! empty( $this->defaults ) )
|
64 |
$this->prefs = mycred_apply_defaults( $this->defaults, $this->prefs );
|
|
|
65 |
}
|
66 |
|
67 |
/**
|
@@ -71,7 +75,9 @@ if ( ! class_exists( 'myCRED_Hook' ) ) {
|
|
71 |
* @version 1.0
|
72 |
*/
|
73 |
function run() {
|
|
|
74 |
wp_die( 'function myCRED_Hook::run() must be over-ridden in a sub-class.' );
|
|
|
75 |
}
|
76 |
|
77 |
/**
|
@@ -80,7 +86,9 @@ if ( ! class_exists( 'myCRED_Hook' ) ) {
|
|
80 |
* @version 1.0
|
81 |
*/
|
82 |
function preferences() {
|
|
|
83 |
echo '<p>' . __( 'This Hook has no settings', 'mycred' ) . '</p>';
|
|
|
84 |
}
|
85 |
|
86 |
/**
|
@@ -89,7 +97,9 @@ if ( ! class_exists( 'myCRED_Hook' ) ) {
|
|
89 |
* @version 1.0
|
90 |
*/
|
91 |
function sanitise_preferences( $data ) {
|
|
|
92 |
return $data;
|
|
|
93 |
}
|
94 |
|
95 |
/**
|
@@ -99,26 +109,34 @@ if ( ! class_exists( 'myCRED_Hook' ) ) {
|
|
99 |
* @version 1.1
|
100 |
*/
|
101 |
function field_name( $field = '' ) {
|
|
|
102 |
if ( is_array( $field ) ) {
|
|
|
103 |
$array = array();
|
104 |
foreach ( $field as $parent => $child ) {
|
|
|
105 |
if ( ! is_numeric( $parent ) )
|
106 |
$array[] = $parent;
|
107 |
|
108 |
if ( ! empty( $child ) && ! is_array( $child ) )
|
109 |
$array[] = $child;
|
|
|
110 |
}
|
111 |
$field = '[' . implode( '][', $array ) . ']';
|
|
|
112 |
}
|
113 |
else {
|
|
|
114 |
$field = '[' . $field . ']';
|
|
|
115 |
}
|
116 |
-
|
117 |
$option_id = 'mycred_pref_hooks';
|
118 |
if ( ! $this->is_main_type )
|
119 |
$option_id = $option_id . '_' . $this->mycred_type;
|
120 |
|
121 |
return $option_id . '[hook_prefs][' . $this->id . ']' . $field;
|
|
|
122 |
}
|
123 |
|
124 |
/**
|
@@ -128,19 +146,26 @@ if ( ! class_exists( 'myCRED_Hook' ) ) {
|
|
128 |
* @version 1.1
|
129 |
*/
|
130 |
function field_id( $field = '' ) {
|
|
|
131 |
if ( is_array( $field ) ) {
|
|
|
132 |
$array = array();
|
133 |
foreach ( $field as $parent => $child ) {
|
|
|
134 |
if ( ! is_numeric( $parent ) )
|
135 |
$array[] = str_replace( '_', '-', $parent );
|
136 |
|
137 |
if ( ! empty( $child ) && ! is_array( $child ) )
|
138 |
$array[] = str_replace( '_', '-', $child );
|
|
|
139 |
}
|
140 |
$field = implode( '-', $array );
|
|
|
141 |
}
|
142 |
else {
|
|
|
143 |
$field = str_replace( '_', '-', $field );
|
|
|
144 |
}
|
145 |
|
146 |
$option_id = 'mycred_pref_hooks';
|
@@ -148,30 +173,35 @@ if ( ! class_exists( 'myCRED_Hook' ) ) {
|
|
148 |
$option_id = $option_id . '_' . $this->mycred_type;
|
149 |
|
150 |
$option_id = str_replace( '_', '-', $option_id );
|
|
|
151 |
return $option_id . '-' . str_replace( '_', '-', $this->id ) . '-' . $field;
|
|
|
152 |
}
|
153 |
|
154 |
/**
|
155 |
* Check Limit
|
156 |
* @since 1.6
|
157 |
-
* @version 1.
|
158 |
*/
|
159 |
-
function over_hook_limit( $instance = '', $reference = '', $user_id = NULL ) {
|
160 |
|
|
|
161 |
if ( ! isset( $this->prefs[ $instance ] ) && $instance != '' )
|
162 |
return true;
|
163 |
|
|
|
|
|
|
|
|
|
|
|
|
|
164 |
// If hook uses multiple instances
|
165 |
-
if ( isset( $this->prefs[ $instance ]['limit'] ) )
|
166 |
-
if ( $this->prefs[ $instance ]['limit'] == '0/x' ) return false;
|
167 |
$prefs = $this->prefs[ $instance ]['limit'];
|
168 |
-
}
|
169 |
|
170 |
// Else if hook uses single instance
|
171 |
-
elseif ( isset( $this->prefs['limit'] ) )
|
172 |
-
if ( $this->prefs['limit'] == '0/x' ) return false;
|
173 |
$prefs = $this->prefs['limit'];
|
174 |
-
}
|
175 |
|
176 |
// no support for limits
|
177 |
else {
|
@@ -182,36 +212,60 @@ if ( ! class_exists( 'myCRED_Hook' ) ) {
|
|
182 |
if ( $user_id === NULL )
|
183 |
$user_id = get_current_user_id();
|
184 |
|
|
|
|
|
|
|
|
|
|
|
|
|
185 |
list ( $amount, $period ) = explode( '/', $prefs );
|
186 |
$amount = (int) $amount;
|
187 |
|
188 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
189 |
|
190 |
-
|
191 |
-
|
192 |
-
if ( $period == 'd' )
|
193 |
-
$from = $wpdb->prepare( "AND time BETWEEN %d AND %d", mktime( 0, 0, 0, date( 'n', $until ), date( 'j', $until ), date( 'Y', $until ) ), $until );
|
194 |
|
195 |
-
|
196 |
-
|
|
|
197 |
|
198 |
-
|
199 |
-
|
|
|
200 |
|
201 |
-
|
202 |
-
|
203 |
-
|
204 |
-
WHERE user_id = %d
|
205 |
-
AND ref = %s
|
206 |
-
AND ctype = %s {$from};", $user_id, $reference, $this->mycred_type ) );
|
207 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
208 |
if ( $count === NULL ) $count = 0;
|
209 |
|
210 |
-
$
|
211 |
-
|
212 |
-
|
|
|
|
|
213 |
|
214 |
-
|
|
|
|
|
|
|
|
|
215 |
|
216 |
}
|
217 |
|
@@ -245,8 +299,10 @@ if ( ! class_exists( 'myCRED_Hook' ) ) {
|
|
245 |
|
246 |
if ( $count == 0 || ( $count == 1 && $check[0] == 0 ) )
|
247 |
$selected = array( 0, 'x' );
|
|
|
248 |
elseif ( $count == 1 && $check[0] != '' && is_numeric( $check[0] ) )
|
249 |
$selected = array( (int) $check[0], 'd' );
|
|
|
250 |
else
|
251 |
$selected = $check;
|
252 |
|
@@ -279,6 +335,7 @@ if ( ! class_exists( 'myCRED_Hook' ) ) {
|
|
279 |
$output .= '>' . $label . '</option>';
|
280 |
}
|
281 |
$output .= '</select></div>';
|
|
|
282 |
return $output;
|
283 |
|
284 |
}
|
@@ -289,6 +346,7 @@ if ( ! class_exists( 'myCRED_Hook' ) ) {
|
|
289 |
* @version 1.3
|
290 |
*/
|
291 |
function impose_limits_dropdown( $pref_id = '', $use_select = true ) {
|
|
|
292 |
$limits = array(
|
293 |
'' => __( 'No limit', 'mycred' ),
|
294 |
'twentyfour' => __( 'Once every 24 hours', 'mycred' ),
|
@@ -304,12 +362,16 @@ if ( ! class_exists( 'myCRED_Hook' ) ) {
|
|
304 |
|
305 |
$settings = '';
|
306 |
if ( is_array( $pref_id ) ) {
|
|
|
307 |
reset( $pref_id );
|
308 |
$key = key( $pref_id );
|
309 |
$settings = $this->prefs[ $key ][ $pref_id[ $key ] ];
|
|
|
310 |
}
|
311 |
elseif ( isset( $this->prefs[ $pref_id ] ) ) {
|
|
|
312 |
$settings = $this->prefs[ $pref_id ];
|
|
|
313 |
}
|
314 |
|
315 |
foreach ( $limits as $value => $description ) {
|
@@ -318,6 +380,7 @@ if ( ! class_exists( 'myCRED_Hook' ) ) {
|
|
318 |
echo '>' . $description . '</option>';
|
319 |
}
|
320 |
echo '</select>';
|
|
|
321 |
}
|
322 |
|
323 |
/**
|
@@ -327,10 +390,12 @@ if ( ! class_exists( 'myCRED_Hook' ) ) {
|
|
327 |
* @version 1.3
|
328 |
*/
|
329 |
function has_entry( $action = '', $ref_id = '', $user_id = '', $data = '', $type = '' ) {
|
|
|
330 |
if ( $type == '' )
|
331 |
$type = $this->mycred_type;
|
332 |
|
333 |
return $this->core->has_entry( $action, $ref_id, $user_id, $data, $type );
|
|
|
334 |
}
|
335 |
|
336 |
/**
|
@@ -339,31 +404,31 @@ if ( ! class_exists( 'myCRED_Hook' ) ) {
|
|
339 |
* @version 1.0
|
340 |
*/
|
341 |
function available_template_tags( $available = array(), $custom = '' ) {
|
|
|
342 |
return $this->core->available_template_tags( $available, $custom );
|
|
|
343 |
}
|
344 |
|
345 |
/**
|
346 |
* Over Daily Limit
|
347 |
* @since 1.0
|
348 |
-
* @version 1.
|
349 |
*/
|
350 |
public function is_over_daily_limit( $ref = '', $user_id = 0, $max = 0, $ref_id = NULL ) {
|
|
|
351 |
global $wpdb;
|
352 |
|
353 |
// Prep
|
354 |
$reply = true;
|
355 |
|
356 |
-
// Times
|
357 |
-
$start = date_i18n( 'U', strtotime( 'today midnight' ) );
|
358 |
-
$end = date_i18n( 'U' );
|
359 |
-
|
360 |
// DB Query
|
361 |
-
$total = $this->limit_query( $ref, $user_id, $
|
362 |
|
363 |
-
if ( $total
|
364 |
$reply = false;
|
365 |
|
366 |
return apply_filters( 'mycred_hook_over_daily_limit', $reply, $ref, $user_id, $max );
|
|
|
367 |
}
|
368 |
|
369 |
/**
|
@@ -377,31 +442,38 @@ if ( ! class_exists( 'myCRED_Hook' ) ) {
|
|
377 |
* @param $ref_id (int) optional reference id to include in search
|
378 |
* @returns number of entries found (int) or NULL if required params are missing
|
379 |
* @since 1.4
|
380 |
-
* @version 1.
|
381 |
*/
|
382 |
public function limit_query( $ref = '', $user_id = 0, $start = 0, $end = 0, $ref_id = NULL ) {
|
|
|
|
|
|
|
|
|
|
|
383 |
global $wpdb;
|
384 |
|
385 |
// Prep
|
386 |
-
$reply
|
|
|
387 |
|
388 |
-
|
389 |
-
|
|
|
390 |
|
391 |
-
$ref = '';
|
392 |
if ( $ref_id !== NULL )
|
393 |
-
$
|
|
|
|
|
394 |
|
395 |
// DB Query
|
396 |
-
$total = $wpdb->get_var( $
|
397 |
-
|
398 |
-
FROM {$this->core->log_table}
|
399 |
-
WHERE ref = %s {$ref}
|
400 |
-
AND user_id = %d
|
401 |
-
AND time BETWEEN %d AND %d;", $ref, $user_id, $start, $end ) );
|
402 |
|
403 |
return apply_filters( 'mycred_hook_limit_query', $total, $ref, $user_id, $ref_id, $start, $end );
|
|
|
404 |
}
|
|
|
405 |
}
|
406 |
-
|
|
|
407 |
?>
|
5 |
* myCRED_Hook class
|
6 |
* @see http://codex.mycred.me/classes/mycred_hook/
|
7 |
* @since 0.1
|
8 |
+
* @version 1.3.1
|
9 |
*/
|
10 |
+
if ( ! class_exists( 'myCRED_Hook' ) ) :
|
11 |
abstract class myCRED_Hook {
|
12 |
|
13 |
// Hook ID
|
30 |
* Construct
|
31 |
*/
|
32 |
function __construct( $args = array(), $hook_prefs = NULL, $type = 'mycred_default' ) {
|
33 |
+
|
34 |
if ( ! empty( $args ) ) {
|
35 |
foreach ( $args as $key => $value ) {
|
36 |
$this->$key = $value;
|
51 |
|
52 |
// Grab settings
|
53 |
if ( $hook_prefs !== NULL ) {
|
54 |
+
|
55 |
// Assign prefs if set
|
56 |
if ( isset( $hook_prefs[ $this->id ] ) )
|
57 |
$this->prefs = $hook_prefs[ $this->id ];
|
59 |
// Defaults must be set
|
60 |
if ( ! isset( $this->defaults ) )
|
61 |
$this->defaults = array();
|
62 |
+
|
63 |
}
|
64 |
|
65 |
// Apply default settings if needed
|
66 |
if ( ! empty( $this->defaults ) )
|
67 |
$this->prefs = mycred_apply_defaults( $this->defaults, $this->prefs );
|
68 |
+
|
69 |
}
|
70 |
|
71 |
/**
|
75 |
* @version 1.0
|
76 |
*/
|
77 |
function run() {
|
78 |
+
|
79 |
wp_die( 'function myCRED_Hook::run() must be over-ridden in a sub-class.' );
|
80 |
+
|
81 |
}
|
82 |
|
83 |
/**
|
86 |
* @version 1.0
|
87 |
*/
|
88 |
function preferences() {
|
89 |
+
|
90 |
echo '<p>' . __( 'This Hook has no settings', 'mycred' ) . '</p>';
|
91 |
+
|
92 |
}
|
93 |
|
94 |
/**
|
97 |
* @version 1.0
|
98 |
*/
|
99 |
function sanitise_preferences( $data ) {
|
100 |
+
|
101 |
return $data;
|
102 |
+
|
103 |
}
|
104 |
|
105 |
/**
|
109 |
* @version 1.1
|
110 |
*/
|
111 |
function field_name( $field = '' ) {
|
112 |
+
|
113 |
if ( is_array( $field ) ) {
|
114 |
+
|
115 |
$array = array();
|
116 |
foreach ( $field as $parent => $child ) {
|
117 |
+
|
118 |
if ( ! is_numeric( $parent ) )
|
119 |
$array[] = $parent;
|
120 |
|
121 |
if ( ! empty( $child ) && ! is_array( $child ) )
|
122 |
$array[] = $child;
|
123 |
+
|
124 |
}
|
125 |
$field = '[' . implode( '][', $array ) . ']';
|
126 |
+
|
127 |
}
|
128 |
else {
|
129 |
+
|
130 |
$field = '[' . $field . ']';
|
131 |
+
|
132 |
}
|
133 |
+
|
134 |
$option_id = 'mycred_pref_hooks';
|
135 |
if ( ! $this->is_main_type )
|
136 |
$option_id = $option_id . '_' . $this->mycred_type;
|
137 |
|
138 |
return $option_id . '[hook_prefs][' . $this->id . ']' . $field;
|
139 |
+
|
140 |
}
|
141 |
|
142 |
/**
|
146 |
* @version 1.1
|
147 |
*/
|
148 |
function field_id( $field = '' ) {
|
149 |
+
|
150 |
if ( is_array( $field ) ) {
|
151 |
+
|
152 |
$array = array();
|
153 |
foreach ( $field as $parent => $child ) {
|
154 |
+
|
155 |
if ( ! is_numeric( $parent ) )
|
156 |
$array[] = str_replace( '_', '-', $parent );
|
157 |
|
158 |
if ( ! empty( $child ) && ! is_array( $child ) )
|
159 |
$array[] = str_replace( '_', '-', $child );
|
160 |
+
|
161 |
}
|
162 |
$field = implode( '-', $array );
|
163 |
+
|
164 |
}
|
165 |
else {
|
166 |
+
|
167 |
$field = str_replace( '_', '-', $field );
|
168 |
+
|
169 |
}
|
170 |
|
171 |
$option_id = 'mycred_pref_hooks';
|
173 |
$option_id = $option_id . '_' . $this->mycred_type;
|
174 |
|
175 |
$option_id = str_replace( '_', '-', $option_id );
|
176 |
+
|
177 |
return $option_id . '-' . str_replace( '_', '-', $this->id ) . '-' . $field;
|
178 |
+
|
179 |
}
|
180 |
|
181 |
/**
|
182 |
* Check Limit
|
183 |
* @since 1.6
|
184 |
+
* @version 1.1
|
185 |
*/
|
186 |
+
function over_hook_limit( $instance = '', $reference = '', $user_id = NULL, $ref_id = NULL ) {
|
187 |
|
188 |
+
// Enforce limit if this function is used incorrectly
|
189 |
if ( ! isset( $this->prefs[ $instance ] ) && $instance != '' )
|
190 |
return true;
|
191 |
|
192 |
+
global $wpdb;
|
193 |
+
|
194 |
+
// Prep
|
195 |
+
$wheres = array();
|
196 |
+
$now = current_time( 'timestamp' );
|
197 |
+
|
198 |
// If hook uses multiple instances
|
199 |
+
if ( isset( $this->prefs[ $instance ]['limit'] ) )
|
|
|
200 |
$prefs = $this->prefs[ $instance ]['limit'];
|
|
|
201 |
|
202 |
// Else if hook uses single instance
|
203 |
+
elseif ( isset( $this->prefs['limit'] ) )
|
|
|
204 |
$prefs = $this->prefs['limit'];
|
|
|
205 |
|
206 |
// no support for limits
|
207 |
else {
|
212 |
if ( $user_id === NULL )
|
213 |
$user_id = get_current_user_id();
|
214 |
|
215 |
+
// If this an existance check or just a regular limit check?
|
216 |
+
$exists_check = false;
|
217 |
+
if ( $ref_id !== NULL && strlen( $ref_id ) > 0 )
|
218 |
+
$exists_check = true;
|
219 |
+
|
220 |
+
// Prep settings
|
221 |
list ( $amount, $period ) = explode( '/', $prefs );
|
222 |
$amount = (int) $amount;
|
223 |
|
224 |
+
// We start constructing the query.
|
225 |
+
$wheres[] = $wpdb->prepare( "user_id = %d", $user_id );
|
226 |
+
$wheres[] = $wpdb->prepare( "ref = %s", $reference );
|
227 |
+
$wheres[] = $wpdb->prepare( "ctype = %s", $this->mycred_type );
|
228 |
+
|
229 |
+
if ( $exists_check )
|
230 |
+
$wheres[] = $wpdb->prepare( "ref_id = %d", $ref_id );
|
231 |
|
232 |
+
// If check is based on time
|
233 |
+
if ( ! in_array( $period, array( 't', 'x' ) ) ) {
|
|
|
|
|
234 |
|
235 |
+
// Per day
|
236 |
+
if ( $period == 'd' )
|
237 |
+
$from = mktime( 0, 0, 0, date( 'n', $now ), date( 'j', $now ), date( 'Y', $now ) );
|
238 |
|
239 |
+
// Per week
|
240 |
+
elseif ( $period == 'w' )
|
241 |
+
$from = mktime( 0, 0, 0, date( "n", $now ), date( "j", $now ) - date( "N", $now ) + 1 );
|
242 |
|
243 |
+
// Per Month
|
244 |
+
elseif ( $period == 'm' )
|
245 |
+
$from = mktime( 0, 0, 0, date( "n", $now ), 1, date( 'Y', $now ) );
|
|
|
|
|
|
|
246 |
|
247 |
+
$wheres[] = $wpdb->prepare( "time BETWEEN %d AND %d", $from, $now );
|
248 |
+
|
249 |
+
}
|
250 |
+
|
251 |
+
// Put all wheres together into one string
|
252 |
+
$wheres = implode( " AND ", $wheres );
|
253 |
+
|
254 |
+
// Count
|
255 |
+
$count = $wpdb->get_var( "SELECT COUNT(*) FROM {$this->core->log_table} WHERE {$wheres};" );
|
256 |
if ( $count === NULL ) $count = 0;
|
257 |
|
258 |
+
$over_limit = false;
|
259 |
+
|
260 |
+
// Existence check has first priority
|
261 |
+
if ( $count > 0 && $exists_check )
|
262 |
+
$over_limit = true;
|
263 |
|
264 |
+
// Limit check is second priority
|
265 |
+
elseif ( $period != 'x' && $count >= $amount )
|
266 |
+
$over_limit = true;
|
267 |
+
|
268 |
+
return $over_limit;
|
269 |
|
270 |
}
|
271 |
|
299 |
|
300 |
if ( $count == 0 || ( $count == 1 && $check[0] == 0 ) )
|
301 |
$selected = array( 0, 'x' );
|
302 |
+
|
303 |
elseif ( $count == 1 && $check[0] != '' && is_numeric( $check[0] ) )
|
304 |
$selected = array( (int) $check[0], 'd' );
|
305 |
+
|
306 |
else
|
307 |
$selected = $check;
|
308 |
|
335 |
$output .= '>' . $label . '</option>';
|
336 |
}
|
337 |
$output .= '</select></div>';
|
338 |
+
|
339 |
return $output;
|
340 |
|
341 |
}
|
346 |
* @version 1.3
|
347 |
*/
|
348 |
function impose_limits_dropdown( $pref_id = '', $use_select = true ) {
|
349 |
+
|
350 |
$limits = array(
|
351 |
'' => __( 'No limit', 'mycred' ),
|
352 |
'twentyfour' => __( 'Once every 24 hours', 'mycred' ),
|
362 |
|
363 |
$settings = '';
|
364 |
if ( is_array( $pref_id ) ) {
|
365 |
+
|
366 |
reset( $pref_id );
|
367 |
$key = key( $pref_id );
|
368 |
$settings = $this->prefs[ $key ][ $pref_id[ $key ] ];
|
369 |
+
|
370 |
}
|
371 |
elseif ( isset( $this->prefs[ $pref_id ] ) ) {
|
372 |
+
|
373 |
$settings = $this->prefs[ $pref_id ];
|
374 |
+
|
375 |
}
|
376 |
|
377 |
foreach ( $limits as $value => $description ) {
|
380 |
echo '>' . $description . '</option>';
|
381 |
}
|
382 |
echo '</select>';
|
383 |
+
|
384 |
}
|
385 |
|
386 |
/**
|
390 |
* @version 1.3
|
391 |
*/
|
392 |
function has_entry( $action = '', $ref_id = '', $user_id = '', $data = '', $type = '' ) {
|
393 |
+
|
394 |
if ( $type == '' )
|
395 |
$type = $this->mycred_type;
|
396 |
|
397 |
return $this->core->has_entry( $action, $ref_id, $user_id, $data, $type );
|
398 |
+
|
399 |
}
|
400 |
|
401 |
/**
|
404 |
* @version 1.0
|
405 |
*/
|
406 |
function available_template_tags( $available = array(), $custom = '' ) {
|
407 |
+
|
408 |
return $this->core->available_template_tags( $available, $custom );
|
409 |
+
|
410 |
}
|
411 |
|
412 |
/**
|
413 |
* Over Daily Limit
|
414 |
* @since 1.0
|
415 |
+
* @version 1.1
|
416 |
*/
|
417 |
public function is_over_daily_limit( $ref = '', $user_id = 0, $max = 0, $ref_id = NULL ) {
|
418 |
+
|
419 |
global $wpdb;
|
420 |
|
421 |
// Prep
|
422 |
$reply = true;
|
423 |
|
|
|
|
|
|
|
|
|
424 |
// DB Query
|
425 |
+
$total = $this->limit_query( $ref, $user_id, strtotime( 'today midnight', $this->now ), $this->now, $ref_id );
|
426 |
|
427 |
+
if ( $total < $max )
|
428 |
$reply = false;
|
429 |
|
430 |
return apply_filters( 'mycred_hook_over_daily_limit', $reply, $ref, $user_id, $max );
|
431 |
+
|
432 |
}
|
433 |
|
434 |
/**
|
442 |
* @param $ref_id (int) optional reference id to include in search
|
443 |
* @returns number of entries found (int) or NULL if required params are missing
|
444 |
* @since 1.4
|
445 |
+
* @version 1.1
|
446 |
*/
|
447 |
public function limit_query( $ref = '', $user_id = 0, $start = 0, $end = 0, $ref_id = NULL ) {
|
448 |
+
|
449 |
+
// Minimum requirements
|
450 |
+
if ( empty( $ref ) || $user_id == 0 || $start == 0 || $end == 0 )
|
451 |
+
return NULL;
|
452 |
+
|
453 |
global $wpdb;
|
454 |
|
455 |
// Prep
|
456 |
+
$reply = true;
|
457 |
+
$wheres = array();
|
458 |
|
459 |
+
$wheres[] = $wpdb->prepare( "ref = %s", $ref );
|
460 |
+
$wheres[] = $wpdb->prepare( "user_id = %d", $user_id );
|
461 |
+
$wheres[] = $wpdb->prepare( "time BETWEEN %d AND %d", $start, $end );
|
462 |
|
|
|
463 |
if ( $ref_id !== NULL )
|
464 |
+
$wheres[] = $wpdb->prepare( "ref_id = %d", $ref_id );
|
465 |
+
|
466 |
+
$wheres = implode( " AND ", $wheres );
|
467 |
|
468 |
// DB Query
|
469 |
+
$total = $wpdb->get_var( "SELECT COUNT(*) FROM {$this->core->log_table} WHERE {$wheres};" );
|
470 |
+
if ( $total === NULL ) $total = 0;
|
|
|
|
|
|
|
|
|
471 |
|
472 |
return apply_filters( 'mycred_hook_limit_query', $total, $ref, $user_id, $ref_id, $start, $end );
|
473 |
+
|
474 |
}
|
475 |
+
|
476 |
}
|
477 |
+
endif;
|
478 |
+
|
479 |
?>
|
abstracts/mycred-abstract-module.php
CHANGED
@@ -5,9 +5,9 @@ if ( ! defined( 'myCRED_VERSION' ) ) exit;
|
|
5 |
* myCRED_Module class
|
6 |
* @see http://codex.mycred.me/classes/mycred_module/
|
7 |
* @since 0.1
|
8 |
-
* @version 1.3.
|
9 |
*/
|
10 |
-
if ( ! class_exists( 'myCRED_Module' ) )
|
11 |
abstract class myCRED_Module {
|
12 |
|
13 |
// Module ID (unique)
|
@@ -34,35 +34,44 @@ if ( ! class_exists( 'myCRED_Module' ) ) {
|
|
34 |
// Menu Position (int)
|
35 |
public $menu_pos;
|
36 |
|
|
|
|
|
|
|
37 |
// Is Main Cred Type
|
38 |
public $is_main_type = true;
|
39 |
|
40 |
-
|
41 |
-
|
42 |
public $mycred_type;
|
43 |
|
|
|
44 |
public $point_types;
|
45 |
|
|
|
46 |
public $current_user_id;
|
47 |
|
|
|
|
|
|
|
|
|
48 |
public $pages = array();
|
49 |
|
50 |
/**
|
51 |
* Construct
|
52 |
*/
|
53 |
function __construct( $module_id = '', $args = array(), $type = 'mycred_default' ) {
|
|
|
54 |
// Module ID is required
|
55 |
if ( empty( $module_id ) )
|
56 |
-
wp_die(
|
57 |
|
58 |
$this->module_id = $module_id;
|
59 |
-
$this->core
|
60 |
|
61 |
if ( ! empty( $type ) ) {
|
62 |
$this->core->cred_id = sanitize_text_field( $type );
|
63 |
-
$this->mycred_type
|
64 |
}
|
65 |
-
|
66 |
if ( $this->mycred_type != 'mycred_default' )
|
67 |
$this->is_main_type = false;
|
68 |
|
@@ -86,33 +95,35 @@ if ( ! class_exists( 'myCRED_Module' ) ) {
|
|
86 |
);
|
87 |
$args = wp_parse_args( $args, $defaults );
|
88 |
|
89 |
-
$this->module_name
|
90 |
-
$this->option_id
|
91 |
-
|
92 |
if ( ! $this->is_main_type )
|
93 |
$this->option_id .= '_' . $this->mycred_type;
|
94 |
-
|
95 |
$this->settings_name = 'myCRED-' . $this->module_name;
|
96 |
if ( ! $this->is_main_type )
|
97 |
$this->settings_name .= '-' . $this->mycred_type;
|
98 |
-
|
99 |
-
$this->labels
|
100 |
-
$this->register
|
101 |
-
$this->screen_id
|
102 |
|
103 |
if ( ! $this->is_main_type && ! empty( $this->screen_id ) )
|
104 |
$this->screen_id = 'myCRED_' . $this->mycred_type . substr( $this->screen_id, 6 );
|
105 |
|
106 |
-
$this->add_to_core
|
107 |
-
$this->accordion
|
108 |
-
$this->cap
|
109 |
-
$this->menu_pos
|
|
|
|
|
110 |
|
111 |
-
$this->default_prefs = $args['defaults'];
|
112 |
-
$this->set_settings();
|
113 |
$this->current_user_id = get_current_user_id();
|
|
|
|
|
|
|
114 |
|
115 |
-
$args = NULL;
|
116 |
}
|
117 |
|
118 |
/**
|
@@ -121,13 +132,16 @@ if ( ! class_exists( 'myCRED_Module' ) ) {
|
|
121 |
* @version 1.2
|
122 |
*/
|
123 |
function set_settings() {
|
|
|
124 |
$module = $this->module_name;
|
125 |
|
126 |
// Reqest not to register any settings
|
127 |
if ( $this->register === false ) {
|
|
|
128 |
// If settings does not exist apply defaults
|
129 |
if ( ! isset( $this->core->$module ) )
|
130 |
$this->$module = $this->default_prefs;
|
|
|
131 |
// Else append settings
|
132 |
else
|
133 |
$this->$module = $this->core->$module;
|
@@ -135,14 +149,18 @@ if ( ! class_exists( 'myCRED_Module' ) ) {
|
|
135 |
// Apply defaults in case new settings have been applied
|
136 |
if ( ! empty( $defaults ) )
|
137 |
$this->$module = mycred_apply_defaults( $this->default_prefs, $this->$module );
|
|
|
138 |
}
|
139 |
|
140 |
// Request to register settings
|
141 |
else {
|
|
|
142 |
// Option IDs must be provided
|
143 |
if ( ! empty( $this->option_id ) ) {
|
|
|
144 |
// Array = more then one
|
145 |
if ( is_array( $this->option_id ) ) {
|
|
|
146 |
// General settings needs not to be loaded
|
147 |
$pattern = 'mycred_pref_core';
|
148 |
//$matches = array_filter( $this->option_id, function( $a ) use ( $pattern ) { return preg_grep( $a, $pattern ); } );
|
@@ -151,6 +169,7 @@ if ( ! class_exists( 'myCRED_Module' ) ) {
|
|
151 |
|
152 |
// Loop and grab
|
153 |
foreach ( $this->option_id as $option_id => $option_name ) {
|
|
|
154 |
$settings = mycred_get_option( $option_name, false );
|
155 |
|
156 |
if ( $settings === false && array_key_exists( $option_id, $defaults ) )
|
@@ -161,17 +180,21 @@ if ( ! class_exists( 'myCRED_Module' ) ) {
|
|
161 |
// Apply defaults in case new settings have been applied
|
162 |
if ( array_key_exists( $option_id, $defaults ) )
|
163 |
$this->$module[ $option_name ] = mycred_apply_defaults( $this->default_prefs[ $option_id ], $this->$module[ $option_name ] );
|
|
|
164 |
}
|
|
|
165 |
}
|
166 |
|
167 |
// String = one
|
168 |
else {
|
|
|
169 |
// General settings needs not to be loaded
|
170 |
if ( str_replace( 'mycred_pref_core', '', $this->option_id ) == '' )
|
171 |
$this->$module = $this->core;
|
172 |
|
173 |
// Grab the requested option
|
174 |
else {
|
|
|
175 |
$this->$module = mycred_get_option( $this->option_id, false );
|
176 |
|
177 |
if ( $this->$module === false && ! empty( $this->default_prefs ) )
|
@@ -180,16 +203,23 @@ if ( ! class_exists( 'myCRED_Module' ) ) {
|
|
180 |
// Apply defaults in case new settings have been applied
|
181 |
if ( ! empty( $this->default_prefs ) )
|
182 |
$this->$module = mycred_apply_defaults( $this->default_prefs, $this->$module );
|
|
|
183 |
}
|
|
|
184 |
}
|
185 |
|
186 |
if ( is_array( $this->$module ) ) {
|
|
|
187 |
foreach ( $this->$module as $key => $value ) {
|
188 |
$this->$key = $value;
|
189 |
}
|
|
|
190 |
}
|
|
|
191 |
}
|
|
|
192 |
}
|
|
|
193 |
}
|
194 |
|
195 |
/**
|
@@ -198,6 +228,7 @@ if ( ! class_exists( 'myCRED_Module' ) ) {
|
|
198 |
* @version 1.0
|
199 |
*/
|
200 |
function load() {
|
|
|
201 |
if ( ! empty( $this->screen_id ) && ! empty( $this->labels['menu'] ) ) {
|
202 |
add_action( 'mycred_add_menu', array( $this, 'add_menu' ), $this->menu_pos );
|
203 |
add_action( 'admin_init', array( $this, 'set_entries_per_page' ) );
|
@@ -216,6 +247,7 @@ if ( ! class_exists( 'myCRED_Module' ) ) {
|
|
216 |
add_action( 'mycred_init', array( $this, 'module_init' ) );
|
217 |
add_action( 'mycred_admin_init', array( $this, 'module_admin_init' ) );
|
218 |
add_action( 'mycred_widgets_init', array( $this, 'module_widgets_init' ) );
|
|
|
219 |
}
|
220 |
|
221 |
/**
|
@@ -269,27 +301,35 @@ if ( ! class_exists( 'myCRED_Module' ) ) {
|
|
269 |
* @version 1.0.1
|
270 |
*/
|
271 |
function call( $call, $callback, $return = NULL ) {
|
|
|
272 |
// Class
|
273 |
if ( is_array( $callback ) && class_exists( $callback[0] ) ) {
|
274 |
-
|
|
|
275 |
$methods = get_class_methods( $class );
|
276 |
if ( in_array( $call, $methods ) ) {
|
277 |
$new = new $class( $this );
|
278 |
return $new->$call( $return );
|
279 |
}
|
|
|
280 |
}
|
281 |
|
282 |
// Function
|
283 |
elseif ( ! is_array( $callback ) ) {
|
|
|
284 |
if ( function_exists( $callback ) ) {
|
|
|
285 |
if ( $return !== NULL )
|
286 |
return call_user_func( $callback, $return, $this );
|
287 |
else
|
288 |
return call_user_func( $callback, $this );
|
|
|
289 |
}
|
|
|
290 |
}
|
291 |
|
292 |
return array();
|
|
|
293 |
}
|
294 |
|
295 |
/**
|
@@ -301,9 +341,11 @@ if ( ! class_exists( 'myCRED_Module' ) ) {
|
|
301 |
* @version 1.0
|
302 |
*/
|
303 |
function is_installed() {
|
|
|
304 |
$module_name = $this->module_name;
|
305 |
if ( $this->$module_name === false ) return false;
|
306 |
return true;
|
|
|
307 |
}
|
308 |
|
309 |
/**
|
@@ -314,20 +356,28 @@ if ( ! class_exists( 'myCRED_Module' ) ) {
|
|
314 |
* @version 1.0
|
315 |
*/
|
316 |
function is_active( $key = '' ) {
|
|
|
317 |
$module = $this->module_name;
|
|
|
318 |
if ( ! isset( $this->active ) && ! empty( $key ) ) {
|
|
|
319 |
if ( isset( $this->$module['active'] ) )
|
320 |
$active = $this->$module['active'];
|
321 |
else
|
322 |
return false;
|
323 |
|
324 |
if ( in_array( $key, $active ) ) return true;
|
|
|
325 |
}
|
|
|
326 |
elseif ( isset( $this->active ) && ! empty( $key ) ) {
|
|
|
327 |
if ( in_array( $key, $this->active ) ) return true;
|
|
|
328 |
}
|
329 |
|
330 |
return false;
|
|
|
331 |
}
|
332 |
|
333 |
/**
|
@@ -336,10 +386,12 @@ if ( ! class_exists( 'myCRED_Module' ) ) {
|
|
336 |
* @version 1.2.1
|
337 |
*/
|
338 |
function add_menu() {
|
|
|
339 |
// Network Setting for Multisites
|
340 |
if ( mycred_override_settings() && $GLOBALS['blog_id'] > 1 && substr( $this->screen_id, 0, 6 ) == 'myCRED' && strlen( $this->screen_id ) > 6 ) return;
|
341 |
|
342 |
if ( ! empty( $this->labels ) && ! empty( $this->screen_id ) ) {
|
|
|
343 |
// Menu Slug
|
344 |
$menu_slug = 'myCRED';
|
345 |
if ( ! $this->is_main_type )
|
@@ -348,21 +400,26 @@ if ( ! class_exists( 'myCRED_Module' ) ) {
|
|
348 |
// Menu Label
|
349 |
if ( ! isset( $this->labels['page_title'] ) && ! isset( $this->labels['menu'] ) )
|
350 |
$label_menu = __( 'Surprise', 'mycred' );
|
|
|
351 |
elseif ( isset( $this->labels['menu'] ) )
|
352 |
$label_menu = $this->labels['menu'];
|
|
|
353 |
else
|
354 |
$label_menu = $this->labels['page_title'];
|
355 |
|
356 |
// Page Title
|
357 |
if ( ! isset( $this->labels['page_title'] ) && ! isset( $this->labels['menu'] ) )
|
358 |
$label_title = __( 'Surprise', 'mycred' );
|
|
|
359 |
elseif ( isset( $this->labels['page_title'] ) )
|
360 |
$label_title = $this->labels['page_title'];
|
|
|
361 |
else
|
362 |
$label_title = $this->labels['menu'];
|
363 |
|
364 |
if ( $this->cap != 'plugin' )
|
365 |
$cap = $this->core->edit_creds_cap();
|
|
|
366 |
else
|
367 |
$cap = $this->core->edit_plugin_cap();
|
368 |
|
@@ -378,7 +435,9 @@ if ( ! class_exists( 'myCRED_Module' ) ) {
|
|
378 |
|
379 |
add_action( 'admin_print_styles-' . $page, array( $this, 'settings_page_enqueue' ) );
|
380 |
add_action( 'load-' . $page, array( $this, 'screen_options' ) );
|
|
|
381 |
}
|
|
|
382 |
}
|
383 |
|
384 |
/**
|
@@ -387,8 +446,9 @@ if ( ! class_exists( 'myCRED_Module' ) ) {
|
|
387 |
* @version 1.0
|
388 |
*/
|
389 |
function set_entries_per_page() {
|
|
|
390 |
if ( ! isset( $_REQUEST['wp_screen_options']['option'] ) || ! isset( $_REQUEST['wp_screen_options']['value'] ) ) return;
|
391 |
-
|
392 |
$settings_key = 'mycred_epp_' . $_GET['page'];
|
393 |
if ( ! $this->is_main_type )
|
394 |
$settings_key .= '_' . $this->mycred_type;
|
@@ -397,6 +457,7 @@ if ( ! class_exists( 'myCRED_Module' ) ) {
|
|
397 |
$value = absint( $_REQUEST['wp_screen_options']['value'] );
|
398 |
mycred_update_user_meta( get_current_user_id(), $settings_key, '', $value );
|
399 |
}
|
|
|
400 |
}
|
401 |
|
402 |
/**
|
@@ -405,9 +466,11 @@ if ( ! class_exists( 'myCRED_Module' ) ) {
|
|
405 |
* @version 1.1
|
406 |
*/
|
407 |
function register_settings() {
|
|
|
408 |
if ( empty( $this->option_id ) || $this->register === false ) return;
|
409 |
|
410 |
register_setting( $this->settings_name, $this->option_id, array( $this, 'sanitize_settings' ) );
|
|
|
411 |
}
|
412 |
|
413 |
/**
|
@@ -416,7 +479,9 @@ if ( ! class_exists( 'myCRED_Module' ) ) {
|
|
416 |
* @version 1.0
|
417 |
*/
|
418 |
function screen_options() {
|
|
|
419 |
$this->set_entries_per_page();
|
|
|
420 |
}
|
421 |
|
422 |
/**
|
@@ -426,19 +491,22 @@ if ( ! class_exists( 'myCRED_Module' ) ) {
|
|
426 |
* @version 1.0
|
427 |
*/
|
428 |
function settings_page_enqueue() {
|
|
|
429 |
wp_dequeue_script( 'bpge_admin_js_acc' );
|
430 |
|
431 |
// Load Accordion
|
432 |
if ( $this->accordion ) {
|
|
|
433 |
wp_enqueue_script( 'mycred-admin' );
|
434 |
wp_enqueue_style( 'mycred-admin' );
|
435 |
-
|
436 |
-
$open = '-1';
|
437 |
if ( isset( $_GET['open-tab'] ) && is_numeric( $_GET['open-tab'] ) )
|
438 |
$open = absint( $_GET['open-tab'] );
|
439 |
|
440 |
-
wp_localize_script( 'mycred-admin', 'myCRED', apply_filters( 'mycred_localize_admin', array( 'active' => $open ) ) );
|
441 |
|
|
|
442 |
<!-- myCRED Accordion Styling -->
|
443 |
<style type="text/css">
|
444 |
h4:before { float:right; padding-right: 12px; font-size: 14px; font-weight: normal; color: silver; }
|
@@ -446,9 +514,11 @@ h4.ui-accordion-header.ui-state-active:before { content: "<?php _e( 'click to cl
|
|
446 |
h4.ui-accordion-header:before { content: "<?php _e( 'click to open', 'mycred' ); ?>"; }
|
447 |
</style>
|
448 |
<?php
|
|
|
449 |
}
|
450 |
|
451 |
$this->settings_header();
|
|
|
452 |
}
|
453 |
|
454 |
/**
|
@@ -457,9 +527,7 @@ h4.ui-accordion-header:before { content: "<?php _e( 'click to open', 'mycred' );
|
|
457 |
* @since 0.1
|
458 |
* @version 1.2
|
459 |
*/
|
460 |
-
function settings_header() {
|
461 |
-
|
462 |
-
}
|
463 |
|
464 |
/**
|
465 |
* Admin Page
|
@@ -474,12 +542,13 @@ h4.ui-accordion-header:before { content: "<?php _e( 'click to open', 'mycred' );
|
|
474 |
* @version 1.0
|
475 |
*/
|
476 |
function update_notice( $get = 'settings-updated', $class = 'updated', $message = '' ) {
|
477 |
-
|
478 |
if ( empty( $message ) )
|
479 |
$message = __( 'Settings Updated', 'mycred' );
|
480 |
-
|
481 |
if ( isset( $_GET[ $get ] ) )
|
482 |
echo '<div class="' . $class . '"><p>' . $message . '</p></div>';
|
|
|
483 |
}
|
484 |
|
485 |
/**
|
@@ -488,7 +557,9 @@ h4.ui-accordion-header:before { content: "<?php _e( 'click to open', 'mycred' );
|
|
488 |
* @version 1.0
|
489 |
*/
|
490 |
function sanitize_settings( $post ) {
|
|
|
491 |
return $post;
|
|
|
492 |
}
|
493 |
|
494 |
/**
|
@@ -496,7 +567,7 @@ h4.ui-accordion-header:before { content: "<?php _e( 'click to open', 'mycred' );
|
|
496 |
* @since 0.1
|
497 |
* @version 1.0
|
498 |
*/
|
499 |
-
function after_general_settings(
|
500 |
|
501 |
/**
|
502 |
* Sanitize Core Settings
|
@@ -504,7 +575,9 @@ h4.ui-accordion-header:before { content: "<?php _e( 'click to open', 'mycred' );
|
|
504 |
* @version 1.0
|
505 |
*/
|
506 |
function sanitize_extra_settings( $new_data, $data, $core ) {
|
|
|
507 |
return $new_data;
|
|
|
508 |
}
|
509 |
|
510 |
/**
|
@@ -513,19 +586,26 @@ h4.ui-accordion-header:before { content: "<?php _e( 'click to open', 'mycred' );
|
|
513 |
* @version 1.0
|
514 |
*/
|
515 |
function field_name( $name = '' ) {
|
|
|
516 |
if ( is_array( $name ) ) {
|
|
|
517 |
$array = array();
|
518 |
foreach ( $name as $parent => $child ) {
|
|
|
519 |
if ( ! is_numeric( $parent ) )
|
520 |
$array[] = $parent;
|
521 |
|
522 |
if ( ! empty( $child ) && ! is_array( $child ) )
|
523 |
$array[] = $child;
|
|
|
524 |
}
|
525 |
$name = '[' . implode( '][', $array ) . ']';
|
|
|
526 |
}
|
527 |
else {
|
|
|
528 |
$name = '[' . $name . ']';
|
|
|
529 |
}
|
530 |
|
531 |
if ( $this->add_to_core === true )
|
@@ -535,6 +615,7 @@ h4.ui-accordion-header:before { content: "<?php _e( 'click to open', 'mycred' );
|
|
535 |
return $this->option_id . $name;
|
536 |
else
|
537 |
return 'mycred_pref_core' . $name;
|
|
|
538 |
}
|
539 |
|
540 |
/**
|
@@ -543,25 +624,33 @@ h4.ui-accordion-header:before { content: "<?php _e( 'click to open', 'mycred' );
|
|
543 |
* @version 1.0
|
544 |
*/
|
545 |
function field_id( $id = '' ) {
|
|
|
546 |
if ( is_array( $id ) ) {
|
|
|
547 |
$array = array();
|
548 |
foreach ( $id as $parent => $child ) {
|
|
|
549 |
if ( ! is_numeric( $parent ) )
|
550 |
$array[] = str_replace( '_', '-', $parent );
|
551 |
|
552 |
if ( ! empty( $child ) && ! is_array( $child ) )
|
553 |
$array[] = str_replace( '_', '-', $child );
|
|
|
554 |
}
|
555 |
$id = implode( '-', $array );
|
|
|
556 |
}
|
557 |
else {
|
|
|
558 |
$id = str_replace( '_', '-', $id );
|
|
|
559 |
}
|
560 |
|
561 |
if ( $this->add_to_core === true )
|
562 |
$id = $this->module_name . '-' . $id;
|
563 |
|
564 |
return str_replace( '_', '-', $this->module_id ) . '-' . $id;
|
|
|
565 |
}
|
566 |
|
567 |
/**
|
@@ -570,7 +659,9 @@ h4.ui-accordion-header:before { content: "<?php _e( 'click to open', 'mycred' );
|
|
570 |
* @version 1.0
|
571 |
*/
|
572 |
function available_template_tags( $available = array() ) {
|
|
|
573 |
return $this->core->available_template_tags( $available );
|
|
|
574 |
}
|
575 |
|
576 |
/**
|
@@ -579,12 +670,15 @@ h4.ui-accordion-header:before { content: "<?php _e( 'click to open', 'mycred' );
|
|
579 |
* @version 1.0.1
|
580 |
*/
|
581 |
function get_settings_url( $module = '' ) {
|
|
|
582 |
$variables = array( 'page' => 'myCRED_page_settings' );
|
583 |
if ( ! empty( $module ) )
|
584 |
$variables['open-tab'] = $module;
|
585 |
|
586 |
$url = add_query_arg( $variables, admin_url( 'admin.php' ) );
|
|
|
587 |
return esc_url( $url );
|
|
|
588 |
}
|
589 |
|
590 |
/**
|
@@ -592,7 +686,9 @@ h4.ui-accordion-header:before { content: "<?php _e( 'click to open', 'mycred' );
|
|
592 |
* @since 1.6
|
593 |
* @version 1.0
|
594 |
*/
|
595 |
-
public function request_to_entry( $request ) {
|
|
|
|
|
596 |
|
597 |
$entry = new stdClass();
|
598 |
|
@@ -600,7 +696,7 @@ h4.ui-accordion-header:before { content: "<?php _e( 'click to open', 'mycred' );
|
|
600 |
$entry->ref = $request['ref'];
|
601 |
$entry->ref_id = $request['ref_id'];
|
602 |
$entry->user_id = $request['user_id'];
|
603 |
-
$entry->time =
|
604 |
$entry->entry = $request['entry'];
|
605 |
$entry->data = $request['data'];
|
606 |
$entry->ctype = $request['type'];
|
@@ -610,5 +706,6 @@ h4.ui-accordion-header:before { content: "<?php _e( 'click to open', 'mycred' );
|
|
610 |
}
|
611 |
|
612 |
}
|
613 |
-
|
|
|
614 |
?>
|
5 |
* myCRED_Module class
|
6 |
* @see http://codex.mycred.me/classes/mycred_module/
|
7 |
* @since 0.1
|
8 |
+
* @version 1.3.3
|
9 |
*/
|
10 |
+
if ( ! class_exists( 'myCRED_Module' ) ) :
|
11 |
abstract class myCRED_Module {
|
12 |
|
13 |
// Module ID (unique)
|
34 |
// Menu Position (int)
|
35 |
public $menu_pos;
|
36 |
|
37 |
+
// Default preferences
|
38 |
+
public $default_prefs = array();
|
39 |
+
|
40 |
// Is Main Cred Type
|
41 |
public $is_main_type = true;
|
42 |
|
43 |
+
// myCRED Type used
|
|
|
44 |
public $mycred_type;
|
45 |
|
46 |
+
// All registered point types
|
47 |
public $point_types;
|
48 |
|
49 |
+
// Current users ID
|
50 |
public $current_user_id;
|
51 |
|
52 |
+
// Current time
|
53 |
+
public $now;
|
54 |
+
|
55 |
+
// Pages
|
56 |
public $pages = array();
|
57 |
|
58 |
/**
|
59 |
* Construct
|
60 |
*/
|
61 |
function __construct( $module_id = '', $args = array(), $type = 'mycred_default' ) {
|
62 |
+
|
63 |
// Module ID is required
|
64 |
if ( empty( $module_id ) )
|
65 |
+
wp_die( 'myCRED_Module() Error. A Module ID is required!' );
|
66 |
|
67 |
$this->module_id = $module_id;
|
68 |
+
$this->core = mycred( $type );
|
69 |
|
70 |
if ( ! empty( $type ) ) {
|
71 |
$this->core->cred_id = sanitize_text_field( $type );
|
72 |
+
$this->mycred_type = $this->core->cred_id;
|
73 |
}
|
74 |
+
|
75 |
if ( $this->mycred_type != 'mycred_default' )
|
76 |
$this->is_main_type = false;
|
77 |
|
95 |
);
|
96 |
$args = wp_parse_args( $args, $defaults );
|
97 |
|
98 |
+
$this->module_name = $args['module_name'];
|
99 |
+
$this->option_id = $args['option_id'];
|
100 |
+
|
101 |
if ( ! $this->is_main_type )
|
102 |
$this->option_id .= '_' . $this->mycred_type;
|
103 |
+
|
104 |
$this->settings_name = 'myCRED-' . $this->module_name;
|
105 |
if ( ! $this->is_main_type )
|
106 |
$this->settings_name .= '-' . $this->mycred_type;
|
107 |
+
|
108 |
+
$this->labels = $args['labels'];
|
109 |
+
$this->register = $args['register'];
|
110 |
+
$this->screen_id = $args['screen_id'];
|
111 |
|
112 |
if ( ! $this->is_main_type && ! empty( $this->screen_id ) )
|
113 |
$this->screen_id = 'myCRED_' . $this->mycred_type . substr( $this->screen_id, 6 );
|
114 |
|
115 |
+
$this->add_to_core = $args['add_to_core'];
|
116 |
+
$this->accordion = $args['accordion'];
|
117 |
+
$this->cap = $args['cap'];
|
118 |
+
$this->menu_pos = $args['menu_pos'];
|
119 |
+
|
120 |
+
$this->default_prefs = $args['defaults'];
|
121 |
|
|
|
|
|
122 |
$this->current_user_id = get_current_user_id();
|
123 |
+
$this->now = current_time( 'timestamp' );
|
124 |
+
|
125 |
+
$this->set_settings();
|
126 |
|
|
|
127 |
}
|
128 |
|
129 |
/**
|
132 |
* @version 1.2
|
133 |
*/
|
134 |
function set_settings() {
|
135 |
+
|
136 |
$module = $this->module_name;
|
137 |
|
138 |
// Reqest not to register any settings
|
139 |
if ( $this->register === false ) {
|
140 |
+
|
141 |
// If settings does not exist apply defaults
|
142 |
if ( ! isset( $this->core->$module ) )
|
143 |
$this->$module = $this->default_prefs;
|
144 |
+
|
145 |
// Else append settings
|
146 |
else
|
147 |
$this->$module = $this->core->$module;
|
149 |
// Apply defaults in case new settings have been applied
|
150 |
if ( ! empty( $defaults ) )
|
151 |
$this->$module = mycred_apply_defaults( $this->default_prefs, $this->$module );
|
152 |
+
|
153 |
}
|
154 |
|
155 |
// Request to register settings
|
156 |
else {
|
157 |
+
|
158 |
// Option IDs must be provided
|
159 |
if ( ! empty( $this->option_id ) ) {
|
160 |
+
|
161 |
// Array = more then one
|
162 |
if ( is_array( $this->option_id ) ) {
|
163 |
+
|
164 |
// General settings needs not to be loaded
|
165 |
$pattern = 'mycred_pref_core';
|
166 |
//$matches = array_filter( $this->option_id, function( $a ) use ( $pattern ) { return preg_grep( $a, $pattern ); } );
|
169 |
|
170 |
// Loop and grab
|
171 |
foreach ( $this->option_id as $option_id => $option_name ) {
|
172 |
+
|
173 |
$settings = mycred_get_option( $option_name, false );
|
174 |
|
175 |
if ( $settings === false && array_key_exists( $option_id, $defaults ) )
|
180 |
// Apply defaults in case new settings have been applied
|
181 |
if ( array_key_exists( $option_id, $defaults ) )
|
182 |
$this->$module[ $option_name ] = mycred_apply_defaults( $this->default_prefs[ $option_id ], $this->$module[ $option_name ] );
|
183 |
+
|
184 |
}
|
185 |
+
|
186 |
}
|
187 |
|
188 |
// String = one
|
189 |
else {
|
190 |
+
|
191 |
// General settings needs not to be loaded
|
192 |
if ( str_replace( 'mycred_pref_core', '', $this->option_id ) == '' )
|
193 |
$this->$module = $this->core;
|
194 |
|
195 |
// Grab the requested option
|
196 |
else {
|
197 |
+
|
198 |
$this->$module = mycred_get_option( $this->option_id, false );
|
199 |
|
200 |
if ( $this->$module === false && ! empty( $this->default_prefs ) )
|
203 |
// Apply defaults in case new settings have been applied
|
204 |
if ( ! empty( $this->default_prefs ) )
|
205 |
$this->$module = mycred_apply_defaults( $this->default_prefs, $this->$module );
|
206 |
+
|
207 |
}
|
208 |
+
|
209 |
}
|
210 |
|
211 |
if ( is_array( $this->$module ) ) {
|
212 |
+
|
213 |
foreach ( $this->$module as $key => $value ) {
|
214 |
$this->$key = $value;
|
215 |
}
|
216 |
+
|
217 |
}
|
218 |
+
|
219 |
}
|
220 |
+
|
221 |
}
|
222 |
+
|
223 |
}
|
224 |
|
225 |
/**
|
228 |
* @version 1.0
|
229 |
*/
|
230 |
function load() {
|
231 |
+
|
232 |
if ( ! empty( $this->screen_id ) && ! empty( $this->labels['menu'] ) ) {
|
233 |
add_action( 'mycred_add_menu', array( $this, 'add_menu' ), $this->menu_pos );
|
234 |
add_action( 'admin_init', array( $this, 'set_entries_per_page' ) );
|
247 |
add_action( 'mycred_init', array( $this, 'module_init' ) );
|
248 |
add_action( 'mycred_admin_init', array( $this, 'module_admin_init' ) );
|
249 |
add_action( 'mycred_widgets_init', array( $this, 'module_widgets_init' ) );
|
250 |
+
|
251 |
}
|
252 |
|
253 |
/**
|
301 |
* @version 1.0.1
|
302 |
*/
|
303 |
function call( $call, $callback, $return = NULL ) {
|
304 |
+
|
305 |
// Class
|
306 |
if ( is_array( $callback ) && class_exists( $callback[0] ) ) {
|
307 |
+
|
308 |
+
$class = $callback[0];
|
309 |
$methods = get_class_methods( $class );
|
310 |
if ( in_array( $call, $methods ) ) {
|
311 |
$new = new $class( $this );
|
312 |
return $new->$call( $return );
|
313 |
}
|
314 |
+
|
315 |
}
|
316 |
|
317 |
// Function
|
318 |
elseif ( ! is_array( $callback ) ) {
|
319 |
+
|
320 |
if ( function_exists( $callback ) ) {
|
321 |
+
|
322 |
if ( $return !== NULL )
|
323 |
return call_user_func( $callback, $return, $this );
|
324 |
else
|
325 |
return call_user_func( $callback, $this );
|
326 |
+
|
327 |
}
|
328 |
+
|
329 |
}
|
330 |
|
331 |
return array();
|
332 |
+
|
333 |
}
|
334 |
|
335 |
/**
|
341 |
* @version 1.0
|
342 |
*/
|
343 |
function is_installed() {
|
344 |
+
|
345 |
$module_name = $this->module_name;
|
346 |
if ( $this->$module_name === false ) return false;
|
347 |
return true;
|
348 |
+
|
349 |
}
|
350 |
|
351 |
/**
|
356 |
* @version 1.0
|
357 |
*/
|
358 |
function is_active( $key = '' ) {
|
359 |
+
|
360 |
$module = $this->module_name;
|
361 |
+
|
362 |
if ( ! isset( $this->active ) && ! empty( $key ) ) {
|
363 |
+
|
364 |
if ( isset( $this->$module['active'] ) )
|
365 |
$active = $this->$module['active'];
|
366 |
else
|
367 |
return false;
|
368 |
|
369 |
if ( in_array( $key, $active ) ) return true;
|
370 |
+
|
371 |
}
|
372 |
+
|
373 |
elseif ( isset( $this->active ) && ! empty( $key ) ) {
|
374 |
+
|
375 |
if ( in_array( $key, $this->active ) ) return true;
|
376 |
+
|
377 |
}
|
378 |
|
379 |
return false;
|
380 |
+
|
381 |
}
|
382 |
|
383 |
/**
|
386 |
* @version 1.2.1
|
387 |
*/
|
388 |
function add_menu() {
|
389 |
+
|
390 |
// Network Setting for Multisites
|
391 |
if ( mycred_override_settings() && $GLOBALS['blog_id'] > 1 && substr( $this->screen_id, 0, 6 ) == 'myCRED' && strlen( $this->screen_id ) > 6 ) return;
|
392 |
|
393 |
if ( ! empty( $this->labels ) && ! empty( $this->screen_id ) ) {
|
394 |
+
|
395 |
// Menu Slug
|
396 |
$menu_slug = 'myCRED';
|
397 |
if ( ! $this->is_main_type )
|
400 |
// Menu Label
|
401 |
if ( ! isset( $this->labels['page_title'] ) && ! isset( $this->labels['menu'] ) )
|
402 |
$label_menu = __( 'Surprise', 'mycred' );
|
403 |
+
|
404 |
elseif ( isset( $this->labels['menu'] ) )
|
405 |
$label_menu = $this->labels['menu'];
|
406 |
+
|
407 |
else
|
408 |
$label_menu = $this->labels['page_title'];
|
409 |
|
410 |
// Page Title
|
411 |
if ( ! isset( $this->labels['page_title'] ) && ! isset( $this->labels['menu'] ) )
|
412 |
$label_title = __( 'Surprise', 'mycred' );
|
413 |
+
|
414 |
elseif ( isset( $this->labels['page_title'] ) )
|
415 |
$label_title = $this->labels['page_title'];
|
416 |
+
|
417 |
else
|
418 |
$label_title = $this->labels['menu'];
|
419 |
|
420 |
if ( $this->cap != 'plugin' )
|
421 |
$cap = $this->core->edit_creds_cap();
|
422 |
+
|
423 |
else
|
424 |
$cap = $this->core->edit_plugin_cap();
|
425 |
|
435 |
|
436 |
add_action( 'admin_print_styles-' . $page, array( $this, 'settings_page_enqueue' ) );
|
437 |
add_action( 'load-' . $page, array( $this, 'screen_options' ) );
|
438 |
+
|
439 |
}
|
440 |
+
|
441 |
}
|
442 |
|
443 |
/**
|
446 |
* @version 1.0
|
447 |
*/
|
448 |
function set_entries_per_page() {
|
449 |
+
|
450 |
if ( ! isset( $_REQUEST['wp_screen_options']['option'] ) || ! isset( $_REQUEST['wp_screen_options']['value'] ) ) return;
|
451 |
+
|
452 |
$settings_key = 'mycred_epp_' . $_GET['page'];
|
453 |
if ( ! $this->is_main_type )
|
454 |
$settings_key .= '_' . $this->mycred_type;
|
457 |
$value = absint( $_REQUEST['wp_screen_options']['value'] );
|
458 |
mycred_update_user_meta( get_current_user_id(), $settings_key, '', $value );
|
459 |
}
|
460 |
+
|
461 |
}
|
462 |
|
463 |
/**
|
466 |
* @version 1.1
|
467 |
*/
|
468 |
function register_settings() {
|
469 |
+
|
470 |
if ( empty( $this->option_id ) || $this->register === false ) return;
|
471 |
|
472 |
register_setting( $this->settings_name, $this->option_id, array( $this, 'sanitize_settings' ) );
|
473 |
+
|
474 |
}
|
475 |
|
476 |
/**
|
479 |
* @version 1.0
|
480 |
*/
|
481 |
function screen_options() {
|
482 |
+
|
483 |
$this->set_entries_per_page();
|
484 |
+
|
485 |
}
|
486 |
|
487 |
/**
|
491 |
* @version 1.0
|
492 |
*/
|
493 |
function settings_page_enqueue() {
|
494 |
+
|
495 |
wp_dequeue_script( 'bpge_admin_js_acc' );
|
496 |
|
497 |
// Load Accordion
|
498 |
if ( $this->accordion ) {
|
499 |
+
|
500 |
wp_enqueue_script( 'mycred-admin' );
|
501 |
wp_enqueue_style( 'mycred-admin' );
|
502 |
+
|
503 |
+
$open = '-1';
|
504 |
if ( isset( $_GET['open-tab'] ) && is_numeric( $_GET['open-tab'] ) )
|
505 |
$open = absint( $_GET['open-tab'] );
|
506 |
|
507 |
+
wp_localize_script( 'mycred-admin', 'myCRED', apply_filters( 'mycred_localize_admin', array( 'active' => $open ) ) );
|
508 |
|
509 |
+
?>
|
510 |
<!-- myCRED Accordion Styling -->
|
511 |
<style type="text/css">
|
512 |
h4:before { float:right; padding-right: 12px; font-size: 14px; font-weight: normal; color: silver; }
|
514 |
h4.ui-accordion-header:before { content: "<?php _e( 'click to open', 'mycred' ); ?>"; }
|
515 |
</style>
|
516 |
<?php
|
517 |
+
|
518 |
}
|
519 |
|
520 |
$this->settings_header();
|
521 |
+
|
522 |
}
|
523 |
|
524 |
/**
|
527 |
* @since 0.1
|
528 |
* @version 1.2
|
529 |
*/
|
530 |
+
function settings_header() { }
|
|
|
|
|
531 |
|
532 |
/**
|
533 |
* Admin Page
|
542 |
* @version 1.0
|
543 |
*/
|
544 |
function update_notice( $get = 'settings-updated', $class = 'updated', $message = '' ) {
|
545 |
+
|
546 |
if ( empty( $message ) )
|
547 |
$message = __( 'Settings Updated', 'mycred' );
|
548 |
+
|
549 |
if ( isset( $_GET[ $get ] ) )
|
550 |
echo '<div class="' . $class . '"><p>' . $message . '</p></div>';
|
551 |
+
|
552 |
}
|
553 |
|
554 |
/**
|
557 |
* @version 1.0
|
558 |
*/
|
559 |
function sanitize_settings( $post ) {
|
560 |
+
|
561 |
return $post;
|
562 |
+
|
563 |
}
|
564 |
|
565 |
/**
|
567 |
* @since 0.1
|
568 |
* @version 1.0
|
569 |
*/
|
570 |
+
function after_general_settings() { }
|
571 |
|
572 |
/**
|
573 |
* Sanitize Core Settings
|
575 |
* @version 1.0
|
576 |
*/
|
577 |
function sanitize_extra_settings( $new_data, $data, $core ) {
|
578 |
+
|
579 |
return $new_data;
|
580 |
+
|
581 |
}
|
582 |
|
583 |
/**
|
586 |
* @version 1.0
|
587 |
*/
|
588 |
function field_name( $name = '' ) {
|
589 |
+
|
590 |
if ( is_array( $name ) ) {
|
591 |
+
|
592 |
$array = array();
|
593 |
foreach ( $name as $parent => $child ) {
|
594 |
+
|
595 |
if ( ! is_numeric( $parent ) )
|
596 |
$array[] = $parent;
|
597 |
|
598 |
if ( ! empty( $child ) && ! is_array( $child ) )
|
599 |
$array[] = $child;
|
600 |
+
|
601 |
}
|
602 |
$name = '[' . implode( '][', $array ) . ']';
|
603 |
+
|
604 |
}
|
605 |
else {
|
606 |
+
|
607 |
$name = '[' . $name . ']';
|
608 |
+
|
609 |
}
|
610 |
|
611 |
if ( $this->add_to_core === true )
|
615 |
return $this->option_id . $name;
|
616 |
else
|
617 |
return 'mycred_pref_core' . $name;
|
618 |
+
|
619 |
}
|
620 |
|
621 |
/**
|
624 |
* @version 1.0
|
625 |
*/
|
626 |
function field_id( $id = '' ) {
|
627 |
+
|
628 |
if ( is_array( $id ) ) {
|
629 |
+
|
630 |
$array = array();
|
631 |
foreach ( $id as $parent => $child ) {
|
632 |
+
|
633 |
if ( ! is_numeric( $parent ) )
|
634 |
$array[] = str_replace( '_', '-', $parent );
|
635 |
|
636 |
if ( ! empty( $child ) && ! is_array( $child ) )
|
637 |
$array[] = str_replace( '_', '-', $child );
|
638 |
+
|
639 |
}
|
640 |
$id = implode( '-', $array );
|
641 |
+
|
642 |
}
|
643 |
else {
|
644 |
+
|
645 |
$id = str_replace( '_', '-', $id );
|
646 |
+
|
647 |
}
|
648 |
|
649 |
if ( $this->add_to_core === true )
|
650 |
$id = $this->module_name . '-' . $id;
|
651 |
|
652 |
return str_replace( '_', '-', $this->module_id ) . '-' . $id;
|
653 |
+
|
654 |
}
|
655 |
|
656 |
/**
|
659 |
* @version 1.0
|
660 |
*/
|
661 |
function available_template_tags( $available = array() ) {
|
662 |
+
|
663 |
return $this->core->available_template_tags( $available );
|
664 |
+
|
665 |
}
|
666 |
|
667 |
/**
|
670 |
* @version 1.0.1
|
671 |
*/
|
672 |
function get_settings_url( $module = '' ) {
|
673 |
+
|
674 |
$variables = array( 'page' => 'myCRED_page_settings' );
|
675 |
if ( ! empty( $module ) )
|
676 |
$variables['open-tab'] = $module;
|
677 |
|
678 |
$url = add_query_arg( $variables, admin_url( 'admin.php' ) );
|
679 |
+
|
680 |
return esc_url( $url );
|
681 |
+
|
682 |
}
|
683 |
|
684 |
/**
|
686 |
* @since 1.6
|
687 |
* @version 1.0
|
688 |
*/
|
689 |
+
public function request_to_entry( $request = array() ) {
|
690 |
+
|
691 |
+
if ( empty( $request ) ) return false;
|
692 |
|
693 |
$entry = new stdClass();
|
694 |
|
696 |
$entry->ref = $request['ref'];
|
697 |
$entry->ref_id = $request['ref_id'];
|
698 |
$entry->user_id = $request['user_id'];
|
699 |
+
$entry->time = $this->now;
|
700 |
$entry->entry = $request['entry'];
|
701 |
$entry->data = $request['data'];
|
702 |
$entry->ctype = $request['type'];
|
706 |
}
|
707 |
|
708 |
}
|
709 |
+
endif;
|
710 |
+
|
711 |
?>
|
addons/badges/includes/mycred-badge-shortcodes.php
CHANGED
@@ -5,7 +5,7 @@ if ( ! defined( 'myCRED_VERSION' ) ) exit;
|
|
5 |
* Shortcode: mycred_my_badges
|
6 |
* Allows you to show the current users earned badges.
|
7 |
* @since 1.5
|
8 |
-
* @version 1.1.
|
9 |
*/
|
10 |
if ( ! function_exists( 'mycred_render_my_badges' ) ) :
|
11 |
function mycred_render_my_badges( $atts, $content = '' )
|
@@ -45,7 +45,8 @@ if ( ! function_exists( 'mycred_render_my_badges' ) ) :
|
|
45 |
if ( $level_image == '' )
|
46 |
$level_image = get_post_meta( $badge_id, 'main_image', true );
|
47 |
|
48 |
-
|
|
|
49 |
|
50 |
}
|
51 |
|
5 |
* Shortcode: mycred_my_badges
|
6 |
* Allows you to show the current users earned badges.
|
7 |
* @since 1.5
|
8 |
+
* @version 1.1.2
|
9 |
*/
|
10 |
if ( ! function_exists( 'mycred_render_my_badges' ) ) :
|
11 |
function mycred_render_my_badges( $atts, $content = '' )
|
45 |
if ( $level_image == '' )
|
46 |
$level_image = get_post_meta( $badge_id, 'main_image', true );
|
47 |
|
48 |
+
$badge_title = get_the_title( $badge_id );
|
49 |
+
echo apply_filters( 'mycred_my_badge', '<img src="' . $level_image . '"' . $width . $height . ' class="mycred-badge earned" alt="' . esc_attr( $badge_title ) . '" title="' . esc_attr( $badge_title ) . '" />', $badge_id, $level, $user_id, $atts );
|
50 |
|
51 |
}
|
52 |
|
addons/badges/myCRED-addon-badges.php
CHANGED
@@ -943,7 +943,7 @@ jQuery(function($) {
|
|
943 |
* Add to General Settings
|
944 |
* @version 1.0.1
|
945 |
*/
|
946 |
-
public function after_general_settings(
|
947 |
$settings = $this->badges;
|
948 |
|
949 |
$buddypress = false;
|
943 |
* Add to General Settings
|
944 |
* @version 1.0.1
|
945 |
*/
|
946 |
+
public function after_general_settings() {
|
947 |
$settings = $this->badges;
|
948 |
|
949 |
$buddypress = false;
|
addons/buy-creds/gateways/paypal-standard.php
CHANGED
@@ -39,7 +39,7 @@ if ( ! class_exists( 'myCRED_PayPal_Standard' ) ) :
|
|
39 |
* IPN - Is Valid Call
|
40 |
* Replaces the default check
|
41 |
* @since 1.4
|
42 |
-
* @version 1.0
|
43 |
*/
|
44 |
public function IPN_is_valid_call() {
|
45 |
|
@@ -83,7 +83,7 @@ if ( ! class_exists( 'myCRED_PayPal_Standard' ) ) :
|
|
83 |
curl_setopt( $call, CURLOPT_SSL_VERIFYHOST, 2 );
|
84 |
curl_setopt( $call, CURLOPT_FRESH_CONNECT, 1 );
|
85 |
curl_setopt( $call, CURLOPT_FORBID_REUSE, 1 );
|
86 |
-
curl_setopt( $call, CURLOPT_HTTPHEADER, array( 'Connection: Close' ) );
|
87 |
$result = curl_exec( $call );
|
88 |
|
89 |
// End on success
|
39 |
* IPN - Is Valid Call
|
40 |
* Replaces the default check
|
41 |
* @since 1.4
|
42 |
+
* @version 1.0.1
|
43 |
*/
|
44 |
public function IPN_is_valid_call() {
|
45 |
|
83 |
curl_setopt( $call, CURLOPT_SSL_VERIFYHOST, 2 );
|
84 |
curl_setopt( $call, CURLOPT_FRESH_CONNECT, 1 );
|
85 |
curl_setopt( $call, CURLOPT_FORBID_REUSE, 1 );
|
86 |
+
curl_setopt( $call, CURLOPT_HTTPHEADER, array( 'Connection: Close', 'User-Agent: myCRED' ) );
|
87 |
$result = curl_exec( $call );
|
88 |
|
89 |
// End on success
|
addons/buy-creds/myCRED-addon-buy-creds.php
CHANGED
@@ -115,7 +115,7 @@ if ( ! class_exists( 'myCRED_buyCRED_Module' ) ) :
|
|
115 |
* Process
|
116 |
* Processes Gateway returns and IPN calls
|
117 |
* @since 0.1
|
118 |
-
* @version 1.
|
119 |
*/
|
120 |
public function module_init() {
|
121 |
|
@@ -602,7 +602,7 @@ if ( ! class_exists( 'myCRED_buyCRED_Module' ) ) :
|
|
602 |
* @since 0.1
|
603 |
* @version 1.1
|
604 |
*/
|
605 |
-
public function after_general_settings(
|
606 |
|
607 |
// Since we are both registering our own settings and want to hook into
|
608 |
// the core settings, we need to define our "defaults" here.
|
115 |
* Process
|
116 |
* Processes Gateway returns and IPN calls
|
117 |
* @since 0.1
|
118 |
+
* @version 1.3
|
119 |
*/
|
120 |
public function module_init() {
|
121 |
|
602 |
* @since 0.1
|
603 |
* @version 1.1
|
604 |
*/
|
605 |
+
public function after_general_settings() {
|
606 |
|
607 |
// Since we are both registering our own settings and want to hook into
|
608 |
// the core settings, we need to define our "defaults" here.
|
addons/coupons/myCRED-addon-coupons.php
CHANGED
@@ -491,7 +491,7 @@ table td textarea { width: 95%; }
|
|
491 |
* @since 1.4
|
492 |
* @version 1.0
|
493 |
*/
|
494 |
-
public function after_general_settings(
|
495 |
if ( ! isset( $this->coupons ) )
|
496 |
$prefs = $this->default_prefs;
|
497 |
else
|
491 |
* @since 1.4
|
492 |
* @version 1.0
|
493 |
*/
|
494 |
+
public function after_general_settings() {
|
495 |
if ( ! isset( $this->coupons ) )
|
496 |
$prefs = $this->default_prefs;
|
497 |
else
|
addons/email-notices/myCRED-addon-email-notices.php
CHANGED
@@ -276,7 +276,7 @@ if ( ! class_exists( 'myCRED_Email_Notice_Module' ) ) {
|
|
276 |
* @since 1.1
|
277 |
* @version 1.1
|
278 |
*/
|
279 |
-
public function after_general_settings(
|
280 |
|
281 |
$this->emailnotices = mycred_apply_defaults( $this->default_prefs, $this->emailnotices ); ?>
|
282 |
|
276 |
* @since 1.1
|
277 |
* @version 1.1
|
278 |
*/
|
279 |
+
public function after_general_settings() {
|
280 |
|
281 |
$this->emailnotices = mycred_apply_defaults( $this->default_prefs, $this->emailnotices ); ?>
|
282 |
|
addons/notifications/myCRED-addon-notifications.php
CHANGED
@@ -186,7 +186,7 @@ if ( ! class_exists( 'myCRED_Notifications_Module' ) ) {
|
|
186 |
* @since 1.2.3
|
187 |
* @version 1.1
|
188 |
*/
|
189 |
-
public function after_general_settings(
|
190 |
|
191 |
$prefs = $this->notifications; ?>
|
192 |
|
186 |
* @since 1.2.3
|
187 |
* @version 1.1
|
188 |
*/
|
189 |
+
public function after_general_settings() {
|
190 |
|
191 |
$prefs = $this->notifications; ?>
|
192 |
|
addons/ranks/includes/mycred-rank-shortcodes.php
CHANGED
@@ -101,11 +101,11 @@ endif;
|
|
101 |
* Returns all users who have the given rank with the option to show the rank logo and optional content.
|
102 |
* @see http://mycred.me/shortcodes/mycred_users_of_rank/
|
103 |
* @since 1.1
|
104 |
-
* @version 1.1
|
105 |
*/
|
106 |
if ( ! function_exists( 'mycred_render_users_of_rank' ) ) :
|
107 |
-
function mycred_render_users_of_rank( $atts, $row_template = NULL )
|
108 |
-
|
109 |
extract( shortcode_atts( array(
|
110 |
'rank_id' => NULL,
|
111 |
'login' => '',
|
@@ -113,72 +113,80 @@ if ( ! function_exists( 'mycred_render_users_of_rank' ) ) :
|
|
113 |
'wrap' => 'div',
|
114 |
'col' => 1,
|
115 |
'nothing' => __( 'No users found with this rank', 'mycred' ),
|
116 |
-
'ctype' =>
|
117 |
'order' => 'DESC'
|
118 |
), $atts ) );
|
119 |
-
|
120 |
// Rank ID required
|
121 |
if ( $rank_id === NULL )
|
122 |
-
return '<strong>
|
|
|
|
|
|
|
123 |
|
124 |
-
$mycred = mycred(
|
125 |
|
126 |
// User is not logged in
|
127 |
if ( ! is_user_logged_in() && $login != '' )
|
128 |
return $mycred->template_tags_general( $login );
|
129 |
-
|
130 |
-
//
|
131 |
if ( ! is_numeric( $rank_id ) )
|
132 |
-
$
|
133 |
|
134 |
-
|
135 |
-
|
136 |
-
|
137 |
-
$ctype = $type;
|
138 |
-
}
|
139 |
|
140 |
$output = '';
|
141 |
-
|
142 |
// Make sure rank exist
|
143 |
-
if ( $rank
|
144 |
-
|
145 |
-
|
146 |
-
|
147 |
-
|
148 |
-
|
149 |
-
|
150 |
-
|
151 |
-
|
152 |
-
|
153 |
-
|
154 |
-
|
155 |
-
|
156 |
-
|
157 |
-
|
158 |
-
|
159 |
-
|
160 |
-
|
161 |
-
|
162 |
-
|
163 |
-
|
164 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
165 |
}
|
166 |
-
|
167 |
else {
|
168 |
-
|
169 |
-
|
170 |
-
$output .= '<tr><td';
|
171 |
-
if ( $col > 1 ) $output .= ' colspan="' . $col . '"';
|
172 |
-
$output .= '>' . $nothing . '</td></tr>';
|
173 |
-
}
|
174 |
-
else {
|
175 |
-
if ( empty( $wrap ) ) $wrap = 'p';
|
176 |
-
$output .= '<' . $wrap . '>' . $nothing . '</' . $wrap . '>' . "\n";
|
177 |
-
}
|
178 |
}
|
|
|
179 |
}
|
180 |
-
|
181 |
return do_shortcode( $output );
|
|
|
182 |
}
|
183 |
endif;
|
184 |
|
101 |
* Returns all users who have the given rank with the option to show the rank logo and optional content.
|
102 |
* @see http://mycred.me/shortcodes/mycred_users_of_rank/
|
103 |
* @since 1.1
|
104 |
+
* @version 1.1.1
|
105 |
*/
|
106 |
if ( ! function_exists( 'mycred_render_users_of_rank' ) ) :
|
107 |
+
function mycred_render_users_of_rank( $atts, $row_template = NULL ) {
|
108 |
+
|
109 |
extract( shortcode_atts( array(
|
110 |
'rank_id' => NULL,
|
111 |
'login' => '',
|
113 |
'wrap' => 'div',
|
114 |
'col' => 1,
|
115 |
'nothing' => __( 'No users found with this rank', 'mycred' ),
|
116 |
+
'ctype' => 'mycred_default',
|
117 |
'order' => 'DESC'
|
118 |
), $atts ) );
|
119 |
+
|
120 |
// Rank ID required
|
121 |
if ( $rank_id === NULL )
|
122 |
+
return '<strong>ERROR</strong> ' . __( 'Rank ID is required!', 'mycred' );
|
123 |
+
|
124 |
+
if ( $ctype == '' )
|
125 |
+
$ctype = 'mycred_default';
|
126 |
|
127 |
+
$mycred = mycred( $ctype );
|
128 |
|
129 |
// User is not logged in
|
130 |
if ( ! is_user_logged_in() && $login != '' )
|
131 |
return $mycred->template_tags_general( $login );
|
132 |
+
|
133 |
+
// Get rank by title
|
134 |
if ( ! is_numeric( $rank_id ) )
|
135 |
+
$rank = get_page_by_title( $rank_id, OBJECT, 'mycred_rank' );
|
136 |
|
137 |
+
// Else get rank by post ID
|
138 |
+
else
|
139 |
+
$rank = get_post( $rank_id );
|
|
|
|
|
140 |
|
141 |
$output = '';
|
142 |
+
|
143 |
// Make sure rank exist
|
144 |
+
if ( ! isset( $rank->ID ) )
|
145 |
+
return '<strong>ERROR</strong> ' . __( 'Rank not found. Please check the id and try again.', 'mycred' );
|
146 |
+
|
147 |
+
if ( $row_template === NULL || empty( $row_template ) )
|
148 |
+
$row_template = '<p class="user-row">%user_profile_link% with %balance% %_plural%</p>';
|
149 |
+
|
150 |
+
// Let others play
|
151 |
+
$row_template = apply_filters( 'mycred_users_of_rank', $row_template, $atts, $mycred );
|
152 |
+
|
153 |
+
// Get users of this rank if there are any
|
154 |
+
$users = mycred_get_users_of_rank( $rank_id, $number, $order, $ctype );
|
155 |
+
if ( ! empty( $users ) ) {
|
156 |
+
|
157 |
+
// Add support for table
|
158 |
+
if ( $wrap != 'table' && ! empty( $wrap ) )
|
159 |
+
$output .= '<' . $wrap . ' class="mycred-users-of-rank-wrapper">';
|
160 |
+
|
161 |
+
// Loop
|
162 |
+
foreach ( $users as $user )
|
163 |
+
$output .= $mycred->template_tags_user( $row_template, $user['user_id'] );
|
164 |
+
|
165 |
+
// Add support for table
|
166 |
+
if ( $wrap != 'table' && ! empty( $wrap ) )
|
167 |
+
$output .= '</' . $wrap . '>' . "\n";
|
168 |
+
|
169 |
+
}
|
170 |
+
|
171 |
+
// No users found
|
172 |
+
else {
|
173 |
+
|
174 |
+
// Add support for table
|
175 |
+
if ( $wrap == 'table' ) {
|
176 |
+
$output .= '<tr><td';
|
177 |
+
if ( $col > 1 ) $output .= ' colspan="' . $col . '"';
|
178 |
+
$output .= '>' . $nothing . '</td></tr>';
|
179 |
}
|
180 |
+
|
181 |
else {
|
182 |
+
if ( empty( $wrap ) ) $wrap = 'p';
|
183 |
+
$output .= '<' . $wrap . '>' . $nothing . '</' . $wrap . '>' . "\n";
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
184 |
}
|
185 |
+
|
186 |
}
|
187 |
+
|
188 |
return do_shortcode( $output );
|
189 |
+
|
190 |
}
|
191 |
endif;
|
192 |
|
addons/ranks/myCRED-addon-ranks.php
CHANGED
@@ -1286,7 +1286,7 @@ if ( ! class_exists( 'myCRED_Ranks_Module' ) ) :
|
|
1286 |
* @since 1.1
|
1287 |
* @version 1.3
|
1288 |
*/
|
1289 |
-
public function after_general_settings(
|
1290 |
|
1291 |
$prefs = $this->rank;
|
1292 |
$this->add_to_core = true;
|
1286 |
* @since 1.1
|
1287 |
* @version 1.3
|
1288 |
*/
|
1289 |
+
public function after_general_settings() {
|
1290 |
|
1291 |
$prefs = $this->rank;
|
1292 |
$this->add_to_core = true;
|
addons/sell-content/myCRED-addon-sell-content.php
CHANGED
@@ -382,7 +382,7 @@ if ( ! class_exists( 'myCRED_Sell_Content_Module' ) ) {
|
|
382 |
* @since 0.1
|
383 |
* @version 1.3
|
384 |
*/
|
385 |
-
public function after_general_settings(
|
386 |
$sell_content = $this->sell_content;
|
387 |
if ( ! isset( $sell_content['defaults']['expire'] ) )
|
388 |
$sell_content['defaults']['expire'] = 0;
|
382 |
* @since 0.1
|
383 |
* @version 1.3
|
384 |
*/
|
385 |
+
public function after_general_settings() {
|
386 |
$sell_content = $this->sell_content;
|
387 |
if ( ! isset( $sell_content['defaults']['expire'] ) )
|
388 |
$sell_content['defaults']['expire'] = 0;
|
addons/transfer/myCRED-addon-transfer.php
CHANGED
@@ -175,7 +175,7 @@ if ( ! class_exists( 'myCRED_Transfer_Module' ) ) :
|
|
175 |
* @since 0.1
|
176 |
* @version 1.3
|
177 |
*/
|
178 |
-
public function after_general_settings(
|
179 |
|
180 |
// Settings
|
181 |
$settings = $this->transfers;
|
175 |
* @since 0.1
|
176 |
* @version 1.3
|
177 |
*/
|
178 |
+
public function after_general_settings() {
|
179 |
|
180 |
// Settings
|
181 |
$settings = $this->transfers;
|
assets/js/send.js
CHANGED
@@ -1,10 +1,12 @@
|
|
1 |
/**
|
2 |
* myCRED Points for Link Clicks jQuery Scripts
|
3 |
* @since 0.1
|
4 |
-
* @version 1.
|
5 |
*/
|
6 |
jQuery(function($) {
|
|
|
7 |
var mycred_send = function( button, label ) {
|
|
|
8 |
$.ajax({
|
9 |
type : "POST",
|
10 |
data : {
|
@@ -30,12 +32,13 @@ jQuery(function($) {
|
|
30 |
button.attr( 'value', myCREDsend.done );
|
31 |
setTimeout( function(){
|
32 |
button.attr( 'value', label );
|
33 |
-
button.removeAttr( 'disabled' );
|
|
|
34 |
}
|
35 |
// Transfer complete but now account has reached zero
|
36 |
else if ( data == 'zero' ) {
|
37 |
// Loop though each button disable and hide
|
38 |
-
$('.mycred-send-points-button').each(function(){
|
39 |
$(this).attr( 'disabled', 'disabled' );
|
40 |
$(this).hide();
|
41 |
});
|
@@ -43,7 +46,7 @@ jQuery(function($) {
|
|
43 |
// Transfer complete but this amount can not be sent again
|
44 |
else if ( data == 'minus' ) {
|
45 |
// Loop though each button
|
46 |
-
$('.mycred-send-points-button').each(function(){
|
47 |
// If amount is larger or equal to this buttons amount disable and hide
|
48 |
if ( $(this).attr( 'data-amount' ) && $(this).attr( 'data-amount' ) >= button.attr( 'data-amount' ) ) {
|
49 |
$(this).attr( 'disabled', 'disabled' );
|
@@ -53,9 +56,13 @@ jQuery(function($) {
|
|
53 |
}
|
54 |
}
|
55 |
});
|
|
|
56 |
};
|
57 |
|
58 |
-
$('.mycred-send-points-button').click(function(){
|
|
|
59 |
mycred_send( $(this), $(this).attr( 'value' ) );
|
|
|
60 |
});
|
|
|
61 |
});
|
1 |
/**
|
2 |
* myCRED Points for Link Clicks jQuery Scripts
|
3 |
* @since 0.1
|
4 |
+
* @version 1.2
|
5 |
*/
|
6 |
jQuery(function($) {
|
7 |
+
|
8 |
var mycred_send = function( button, label ) {
|
9 |
+
|
10 |
$.ajax({
|
11 |
type : "POST",
|
12 |
data : {
|
32 |
button.attr( 'value', myCREDsend.done );
|
33 |
setTimeout( function(){
|
34 |
button.attr( 'value', label );
|
35 |
+
button.removeAttr( 'disabled' );
|
36 |
+
}, 2000 );
|
37 |
}
|
38 |
// Transfer complete but now account has reached zero
|
39 |
else if ( data == 'zero' ) {
|
40 |
// Loop though each button disable and hide
|
41 |
+
$( 'button.mycred-send-points-button' ).each(function(){
|
42 |
$(this).attr( 'disabled', 'disabled' );
|
43 |
$(this).hide();
|
44 |
});
|
46 |
// Transfer complete but this amount can not be sent again
|
47 |
else if ( data == 'minus' ) {
|
48 |
// Loop though each button
|
49 |
+
$( 'button.mycred-send-points-button' ).each(function(){
|
50 |
// If amount is larger or equal to this buttons amount disable and hide
|
51 |
if ( $(this).attr( 'data-amount' ) && $(this).attr( 'data-amount' ) >= button.attr( 'data-amount' ) ) {
|
52 |
$(this).attr( 'disabled', 'disabled' );
|
56 |
}
|
57 |
}
|
58 |
});
|
59 |
+
|
60 |
};
|
61 |
|
62 |
+
$( 'button.mycred-send-points-button' ).click(function(){
|
63 |
+
|
64 |
mycred_send( $(this), $(this).attr( 'value' ) );
|
65 |
+
|
66 |
});
|
67 |
+
|
68 |
});
|
includes/mycred-shortcodes.php
CHANGED
@@ -564,7 +564,7 @@ endif;
|
|
564 |
* to a pre-set user. A simpler version of the mycred_transfer shortcode.
|
565 |
* @see http://codex.mycred.me/shortcodes/mycred_send/
|
566 |
* @since 1.1
|
567 |
-
* @version 1.
|
568 |
*/
|
569 |
if ( ! function_exists( 'mycred_render_shortcode_send' ) ) :
|
570 |
function mycred_render_shortcode_send( $atts, $content = '' ) {
|
@@ -576,7 +576,8 @@ if ( ! function_exists( 'mycred_render_shortcode_send' ) ) :
|
|
576 |
'to' => '',
|
577 |
'log' => '',
|
578 |
'ref' => 'gift',
|
579 |
-
'type' => 'mycred_default'
|
|
|
580 |
), $atts ) );
|
581 |
|
582 |
if ( $to == 'author' ) {
|
@@ -609,7 +610,10 @@ if ( ! function_exists( 'mycred_render_shortcode_send' ) ) :
|
|
609 |
// We are ready!
|
610 |
$mycred_sending_points = true;
|
611 |
|
612 |
-
|
|
|
|
|
|
|
613 |
return apply_filters( 'mycred_send', $render, $atts, $content );
|
614 |
|
615 |
}
|
@@ -739,27 +743,39 @@ endif;
|
|
739 |
* for watchinga YouTube video.
|
740 |
* @see http://codex.mycred.me/shortcodes/mycred_video/
|
741 |
* @since 1.2
|
742 |
-
* @version 1.2.
|
743 |
*/
|
744 |
if ( ! function_exists( 'mycred_render_shortcode_video' ) ) :
|
745 |
function mycred_render_shortcode_video( $atts ) {
|
746 |
|
747 |
global $mycred_video_points;
|
748 |
|
749 |
-
$hooks = mycred_get_option( 'mycred_pref_hooks', false );
|
750 |
-
if ( $hooks === false ) return;
|
751 |
-
$prefs = $hooks['hook_prefs']['video_view'];
|
752 |
-
|
753 |
extract( shortcode_atts( array(
|
754 |
'id' => NULL,
|
755 |
'width' => 560,
|
756 |
'height' => 315,
|
757 |
-
'amount' =>
|
758 |
-
'logic' =>
|
759 |
-
'interval' =>
|
760 |
'ctype' => 'mycred_default'
|
761 |
), $atts ) );
|
762 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
763 |
// ID is required
|
764 |
if ( $id === NULL || empty( $id ) ) return __( 'A video ID is required for this shortcode', 'mycred' );
|
765 |
|
564 |
* to a pre-set user. A simpler version of the mycred_transfer shortcode.
|
565 |
* @see http://codex.mycred.me/shortcodes/mycred_send/
|
566 |
* @since 1.1
|
567 |
+
* @version 1.2
|
568 |
*/
|
569 |
if ( ! function_exists( 'mycred_render_shortcode_send' ) ) :
|
570 |
function mycred_render_shortcode_send( $atts, $content = '' ) {
|
576 |
'to' => '',
|
577 |
'log' => '',
|
578 |
'ref' => 'gift',
|
579 |
+
'type' => 'mycred_default',
|
580 |
+
'class' => ''
|
581 |
), $atts ) );
|
582 |
|
583 |
if ( $to == 'author' ) {
|
610 |
// We are ready!
|
611 |
$mycred_sending_points = true;
|
612 |
|
613 |
+
if ( $class != '' )
|
614 |
+
$class = ' ' . sanitize_text_field( $class );
|
615 |
+
|
616 |
+
$render = '<button type="button" class="mycred-send-points-button button button-primary btn btn-primary' . $class . '" data-to="' . $to . '" data-ref="' . $ref . '" data-log="' . $log . '" data-amount="' . $amount . '" data-type="' . $type . '">' . $mycred->template_tags_general( $content ) . '</button>';
|
617 |
return apply_filters( 'mycred_send', $render, $atts, $content );
|
618 |
|
619 |
}
|
743 |
* for watchinga YouTube video.
|
744 |
* @see http://codex.mycred.me/shortcodes/mycred_video/
|
745 |
* @since 1.2
|
746 |
+
* @version 1.2.2
|
747 |
*/
|
748 |
if ( ! function_exists( 'mycred_render_shortcode_video' ) ) :
|
749 |
function mycred_render_shortcode_video( $atts ) {
|
750 |
|
751 |
global $mycred_video_points;
|
752 |
|
|
|
|
|
|
|
|
|
753 |
extract( shortcode_atts( array(
|
754 |
'id' => NULL,
|
755 |
'width' => 560,
|
756 |
'height' => 315,
|
757 |
+
'amount' => NULL,
|
758 |
+
'logic' => NULL,
|
759 |
+
'interval' => NULL,
|
760 |
'ctype' => 'mycred_default'
|
761 |
), $atts ) );
|
762 |
|
763 |
+
$hooks = get_option( 'mycred_pref_hooks', false );
|
764 |
+
if ( $ctype != 'mycred_default' )
|
765 |
+
$hooks = get_option( 'mycred_pref_hooks_' . sanitize_key( $ctype ), false );
|
766 |
+
|
767 |
+
if ( $hooks === false ) return;
|
768 |
+
$prefs = $hooks['hook_prefs']['video_view'];
|
769 |
+
|
770 |
+
if ( $amount === NULL )
|
771 |
+
$amount = $prefs['creds'];
|
772 |
+
|
773 |
+
if ( $logic === NULL )
|
774 |
+
$logic = $prefs['logic'];
|
775 |
+
|
776 |
+
if ( $interval === NULL )
|
777 |
+
$interval = $prefs['interval'];
|
778 |
+
|
779 |
// ID is required
|
780 |
if ( $id === NULL || empty( $id ) ) return __( 'A video ID is required for this shortcode', 'mycred' );
|
781 |
|
lang/mycred-ja_JP.mo
CHANGED
File without changes
|
lang/mycred-ja_JP.po
CHANGED
File without changes
|
modules/mycred-module-buddypress.php
CHANGED
@@ -406,7 +406,7 @@ if ( ! class_exists( 'myCRED_BuddyPress_Module' ) ) :
|
|
406 |
* @since 0.1
|
407 |
* @version 1.3
|
408 |
*/
|
409 |
-
public function after_general_settings(
|
410 |
|
411 |
// Settings
|
412 |
global $bp;
|
406 |
* @since 0.1
|
407 |
* @version 1.3
|
408 |
*/
|
409 |
+
public function after_general_settings() {
|
410 |
|
411 |
// Settings
|
412 |
global $bp;
|
modules/mycred-module-hooks.php
CHANGED
@@ -593,7 +593,7 @@ if ( ! class_exists( 'myCRED_Hook_View_Contents' ) ) :
|
|
593 |
/**
|
594 |
* Content Loaded
|
595 |
* @since 1.5.1
|
596 |
-
* @version 1.1.
|
597 |
*/
|
598 |
public function content_loaded( $content ) {
|
599 |
|
@@ -602,7 +602,8 @@ if ( ! class_exists( 'myCRED_Hook_View_Contents' ) ) :
|
|
602 |
|
603 |
global $post;
|
604 |
|
605 |
-
$user_id
|
|
|
606 |
if ( $post->post_author == $user_id ) return $content;
|
607 |
|
608 |
// Make sure this post type award points. Any amount but zero.
|
@@ -612,7 +613,8 @@ if ( ! class_exists( 'myCRED_Hook_View_Contents' ) ) :
|
|
612 |
if ( ! $this->core->exclude_user( $user_id ) ) {
|
613 |
|
614 |
// Limit
|
615 |
-
if ( ! $this->over_hook_limit( $post->post_type, 'view_content', $user_id ) )
|
|
|
616 |
$this->core->add_creds(
|
617 |
'view_content',
|
618 |
$user_id,
|
@@ -623,12 +625,17 @@ if ( ! class_exists( 'myCRED_Hook_View_Contents' ) ) :
|
|
623 |
$this->mycred_type
|
624 |
);
|
625 |
|
|
|
|
|
|
|
|
|
|
|
626 |
}
|
627 |
|
628 |
}
|
629 |
|
630 |
// Make sure this post type award points to the author. Any amount but zero.
|
631 |
-
if ( isset( $this->prefs[ $post->post_type ]['acreds'] ) && $this->prefs[ $post->post_type ]['acreds'] != 0 && apply_filters( 'mycred_view_content_author',
|
632 |
|
633 |
// No payout for viewing our own content
|
634 |
if ( ! $this->core->exclude_user( $post->post_author ) ) {
|
@@ -2173,7 +2180,7 @@ if ( ! class_exists( 'myCRED_Hook_Video_Views' ) ) :
|
|
2173 |
// Decode the key giving us the video shortcode setup
|
2174 |
// This will prevent users from manipulating the shortcode output
|
2175 |
$setup = mycred_verify_token( $_POST['setup'], 5 );
|
2176 |
-
if ( $setup === false ) die;
|
2177 |
|
2178 |
list ( $source, $video_id, $amount, $logic, $interval ) = $setup;
|
2179 |
|
593 |
/**
|
594 |
* Content Loaded
|
595 |
* @since 1.5.1
|
596 |
+
* @version 1.1.2
|
597 |
*/
|
598 |
public function content_loaded( $content ) {
|
599 |
|
602 |
|
603 |
global $post;
|
604 |
|
605 |
+
$user_id = get_current_user_id();
|
606 |
+
$pay_author = true;
|
607 |
if ( $post->post_author == $user_id ) return $content;
|
608 |
|
609 |
// Make sure this post type award points. Any amount but zero.
|
613 |
if ( ! $this->core->exclude_user( $user_id ) ) {
|
614 |
|
615 |
// Limit
|
616 |
+
if ( ! $this->over_hook_limit( $post->post_type, 'view_content', $user_id, $post->ID ) ) {
|
617 |
+
|
618 |
$this->core->add_creds(
|
619 |
'view_content',
|
620 |
$user_id,
|
625 |
$this->mycred_type
|
626 |
);
|
627 |
|
628 |
+
}
|
629 |
+
|
630 |
+
// If the visitor does not get points, neither does the author
|
631 |
+
else $pay_author = false;
|
632 |
+
|
633 |
}
|
634 |
|
635 |
}
|
636 |
|
637 |
// Make sure this post type award points to the author. Any amount but zero.
|
638 |
+
if ( isset( $this->prefs[ $post->post_type ]['acreds'] ) && $this->prefs[ $post->post_type ]['acreds'] != 0 && apply_filters( 'mycred_view_content_author', $pay_author, $this ) === true ) {
|
639 |
|
640 |
// No payout for viewing our own content
|
641 |
if ( ! $this->core->exclude_user( $post->post_author ) ) {
|
2180 |
// Decode the key giving us the video shortcode setup
|
2181 |
// This will prevent users from manipulating the shortcode output
|
2182 |
$setup = mycred_verify_token( $_POST['setup'], 5 );
|
2183 |
+
if ( $setup === false ) die( 0 );
|
2184 |
|
2185 |
list ( $source, $video_id, $amount, $logic, $interval ) = $setup;
|
2186 |
|
mycred.php
CHANGED
@@ -3,13 +3,13 @@
|
|
3 |
* Plugin Name: myCRED
|
4 |
* Plugin URI: http://mycred.me
|
5 |
* Description: <strong>my</strong>CRED is an adaptive points management system for WordPress powered websites, giving you full control on how points are gained, used, traded, managed, logged or presented.
|
6 |
-
* Version: 1.6.
|
7 |
* Tags: points, tokens, credit, management, reward, charge, buddypress, bbpress, jetpack, woocommerce, marketpress, wp e-commerce, gravity forms, simplepress
|
8 |
* Author: Gabriel S Merovingi
|
9 |
* Author URI: http://www.merovingi.com
|
10 |
* Author Email: support@mycred.me
|
11 |
* Requires at least: WP 3.8
|
12 |
-
* Tested up to: WP 4.3
|
13 |
* Text Domain: mycred
|
14 |
* Domain Path: /lang
|
15 |
* License: GPLv2 or later
|
@@ -20,7 +20,7 @@
|
|
20 |
* BuddyPress Compatible: yes
|
21 |
* Forum URI: http://mycred.me/support/forums/
|
22 |
*/
|
23 |
-
define( 'myCRED_VERSION', '1.6.
|
24 |
define( 'myCRED_SLUG', 'mycred' );
|
25 |
define( 'myCRED_NAME', '<strong>my</strong>CRED' );
|
26 |
|
3 |
* Plugin Name: myCRED
|
4 |
* Plugin URI: http://mycred.me
|
5 |
* Description: <strong>my</strong>CRED is an adaptive points management system for WordPress powered websites, giving you full control on how points are gained, used, traded, managed, logged or presented.
|
6 |
+
* Version: 1.6.5
|
7 |
* Tags: points, tokens, credit, management, reward, charge, buddypress, bbpress, jetpack, woocommerce, marketpress, wp e-commerce, gravity forms, simplepress
|
8 |
* Author: Gabriel S Merovingi
|
9 |
* Author URI: http://www.merovingi.com
|
10 |
* Author Email: support@mycred.me
|
11 |
* Requires at least: WP 3.8
|
12 |
+
* Tested up to: WP 4.3.1
|
13 |
* Text Domain: mycred
|
14 |
* Domain Path: /lang
|
15 |
* License: GPLv2 or later
|
20 |
* BuddyPress Compatible: yes
|
21 |
* Forum URI: http://mycred.me/support/forums/
|
22 |
*/
|
23 |
+
define( 'myCRED_VERSION', '1.6.5' );
|
24 |
define( 'myCRED_SLUG', 'mycred' );
|
25 |
define( 'myCRED_NAME', '<strong>my</strong>CRED' );
|
26 |
|
plugins/mycred-hook-buddypress.php
CHANGED
@@ -1,240 +1,275 @@
|
|
1 |
<?php
|
|
|
2 |
|
3 |
/**
|
4 |
-
*
|
5 |
* @since 0.1
|
6 |
-
* @version 1.
|
7 |
*/
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
if ( bp_is_active( 'xprofile' ) ) {
|
19 |
-
$installed['hook_bp_profile'] = array(
|
20 |
-
'title' => __( 'BuddyPress: Members', 'mycred' ),
|
21 |
-
'description' => __( 'Awards %_plural% for profile related actions.', 'mycred' ),
|
22 |
-
'callback' => array( 'myCRED_BuddyPress_Profile' )
|
23 |
-
);
|
24 |
-
}
|
25 |
-
|
26 |
-
if ( bp_is_active( 'groups' ) ) {
|
27 |
-
$installed['hook_bp_groups'] = array(
|
28 |
-
'title' => __( 'BuddyPress: Groups', 'mycred' ),
|
29 |
-
'description' => __( 'Awards %_plural% for group related actions. Use minus to deduct %_plural% or zero to disable a specific hook.', 'mycred' ),
|
30 |
-
'callback' => array( 'myCRED_BuddyPress_Groups' )
|
31 |
-
);
|
32 |
-
}
|
33 |
|
34 |
-
|
|
|
|
|
|
|
|
|
|
|
35 |
}
|
36 |
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
'
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
'
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
'
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
'
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
'
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
'
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
-
|
94 |
-
'
|
95 |
-
|
96 |
-
|
97 |
-
|
98 |
-
|
|
|
|
|
|
|
99 |
)
|
100 |
-
)
|
101 |
-
|
102 |
|
103 |
-
|
104 |
-
* Run
|
105 |
-
* @since 0.1
|
106 |
-
* @version 1.0
|
107 |
-
*/
|
108 |
-
public function run() {
|
109 |
-
if ( $this->prefs['update']['creds'] != 0 )
|
110 |
-
add_action( 'bp_activity_posted_update', array( $this, 'new_update' ), 20, 3 );
|
111 |
|
112 |
-
|
113 |
-
|
|
|
|
|
|
|
|
|
114 |
|
115 |
-
|
116 |
-
|
117 |
|
118 |
-
|
119 |
-
|
120 |
-
add_filter( 'bp_get_add_friend_button', array( $this, 'disable_friendship' ) );
|
121 |
-
}
|
122 |
|
123 |
-
|
124 |
-
|
125 |
|
126 |
-
|
127 |
-
|
|
|
|
|
128 |
|
129 |
-
|
130 |
-
|
131 |
|
132 |
-
|
133 |
-
|
134 |
|
135 |
-
|
136 |
-
|
137 |
|
138 |
-
|
139 |
-
|
140 |
-
}
|
141 |
|
142 |
-
|
143 |
-
|
144 |
-
* @since 0.1
|
145 |
-
* @version 1.2
|
146 |
-
*/
|
147 |
-
public function new_update( $content, $user_id, $activity_id ) {
|
148 |
-
// Check if user is excluded
|
149 |
-
if ( $this->core->exclude_user( $user_id ) ) return;
|
150 |
|
151 |
-
|
152 |
-
|
153 |
|
154 |
-
|
155 |
-
if ( $this->core->has_entry( 'new_profile_update', $activity_id, $user_id ) ) return;
|
156 |
|
157 |
-
|
158 |
-
|
159 |
-
|
160 |
-
|
161 |
-
|
162 |
-
|
163 |
-
|
164 |
-
|
165 |
-
|
166 |
-
|
167 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
168 |
|
169 |
-
|
170 |
-
* Removing Profile Update
|
171 |
-
* @since 1.6
|
172 |
-
* @version 1.0
|
173 |
-
*/
|
174 |
-
public function remove_update( $args ) {
|
175 |
|
176 |
-
|
|
|
|
|
|
|
|
|
|
|
177 |
|
178 |
-
|
179 |
|
180 |
-
|
181 |
-
if ( $this->core->exclude_user( $user_id ) ) return;
|
182 |
|
183 |
-
|
184 |
-
|
185 |
|
186 |
-
|
187 |
-
|
188 |
-
'deleted_profile_update',
|
189 |
-
$user_id,
|
190 |
-
$this->prefs['removed_update']['creds'],
|
191 |
-
$this->prefs['removed_update']['log'],
|
192 |
-
0,
|
193 |
-
$args,
|
194 |
-
$this->mycred_type
|
195 |
-
);
|
196 |
-
}
|
197 |
|
198 |
-
|
199 |
-
|
200 |
-
|
201 |
-
|
202 |
-
|
203 |
-
|
204 |
-
|
|
|
|
|
|
|
205 |
|
206 |
-
|
207 |
-
if ( $this->core->exclude_user( $bp->loggedin_user->id ) ) return;
|
208 |
|
209 |
-
|
210 |
-
|
211 |
-
|
212 |
-
|
213 |
-
|
214 |
-
|
215 |
-
|
216 |
-
|
217 |
-
|
218 |
-
|
219 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
220 |
}
|
221 |
|
222 |
-
|
223 |
-
|
224 |
-
|
225 |
-
|
226 |
-
|
227 |
-
|
228 |
-
|
229 |
-
|
230 |
-
|
231 |
-
|
232 |
-
|
|
|
|
|
233 |
|
234 |
$user_id = bp_loggedin_user_id();
|
235 |
$balance = $this->core->get_users_balance( $user_id, $this->mycred_type );
|
236 |
-
|
237 |
-
$cost = abs( $this->prefs['new_friend']['creds'] );
|
238 |
|
239 |
// Take into account any existing requests which will be charged when the new
|
240 |
// friend approves it. Prevents users from requesting more then they can afford.
|
@@ -242,242 +277,225 @@ if ( defined( 'myCRED_VERSION' ) ) {
|
|
242 |
if ( $pending_requests > 0 )
|
243 |
$cost = $cost + ( $cost * $pending_requests );
|
244 |
|
245 |
-
|
246 |
-
|
247 |
-
echo apply_filters( 'mycred_bp_declined_addfriend', __( 'Insufficient Funds', 'mycred' ), $this );
|
248 |
-
exit;
|
249 |
-
}
|
250 |
-
|
251 |
-
return;
|
252 |
-
}
|
253 |
|
254 |
-
/**
|
255 |
-
* Disable Friendship
|
256 |
-
* If we deduct points from a user for new friendships
|
257 |
-
* we disable the friendship button if the user ca not afford it.
|
258 |
-
* @since 1.5.4
|
259 |
-
* @version 1.0
|
260 |
-
*/
|
261 |
-
public function disable_friendship( $button ) {
|
262 |
-
// Only applicable for Add Friend button
|
263 |
-
if ( $button['id'] == 'not_friends' ) {
|
264 |
-
$user_id = bp_loggedin_user_id();
|
265 |
-
$balance = $this->core->get_users_balance( $user_id, $this->mycred_type );
|
266 |
-
|
267 |
-
$cost = abs( $this->prefs['new_friend']['creds'] );
|
268 |
-
|
269 |
-
// Take into account any existing requests which will be charged when the new
|
270 |
-
// friend approves it. Prevents users from requesting more then they can afford.
|
271 |
-
$pending_requests = $this->count_pending_requests( $user_id );
|
272 |
-
if ( $pending_requests > 0 )
|
273 |
-
$cost = $cost + ( $cost * $pending_requests );
|
274 |
-
|
275 |
-
if ( $balance < $cost )
|
276 |
-
return array();
|
277 |
-
}
|
278 |
-
|
279 |
-
return $button;
|
280 |
}
|
281 |
|
282 |
-
|
283 |
-
* Count Pending Friendship Requests
|
284 |
-
* Counts the given users pending friendship requests sent to
|
285 |
-
* other users.
|
286 |
-
* @since 1.5.4
|
287 |
-
* @version 1.0
|
288 |
-
*/
|
289 |
-
protected function count_pending_requests( $user_id ) {
|
290 |
-
global $wpdb, $bp;
|
291 |
-
|
292 |
-
return $wpdb->get_var( $wpdb->prepare( "
|
293 |
-
SELECT COUNT(*)
|
294 |
-
FROM {$bp->friends->table_name}
|
295 |
-
WHERE initiator_user_id = %d
|
296 |
-
AND is_confirmed = 0;", $user_id ) );
|
297 |
|
298 |
-
|
299 |
|
300 |
-
|
301 |
-
|
302 |
-
|
303 |
-
|
304 |
-
|
305 |
-
|
|
|
|
|
306 |
|
307 |
-
|
308 |
-
if ( ! $this->core->exclude_user( $initiator_user_id ) && ! $this->core->has_entry( 'new_friendship', $friend_user_id, $initiator_user_id ) && ! $this->over_hook_limit( 'new_friend', 'new_friendship', $initiator_user_id ) )
|
309 |
-
$this->core->add_creds(
|
310 |
-
'new_friendship',
|
311 |
-
$initiator_user_id,
|
312 |
-
$this->prefs['new_friend']['creds'],
|
313 |
-
$this->prefs['new_friend']['log'],
|
314 |
-
$friend_user_id,
|
315 |
-
array( 'ref_type' => 'user' ),
|
316 |
-
$this->mycred_type
|
317 |
-
);
|
318 |
|
319 |
-
|
320 |
-
|
321 |
-
|
322 |
-
|
323 |
-
|
324 |
-
$this->prefs['new_friend']['creds'],
|
325 |
-
$this->prefs['new_friend']['log'],
|
326 |
-
$initiator_user_id,
|
327 |
-
array( 'ref_type' => 'user' )
|
328 |
-
);
|
329 |
-
}
|
330 |
|
331 |
-
|
332 |
-
* Ending Friendship
|
333 |
-
* @since 0.1
|
334 |
-
* @version 1.2
|
335 |
-
*/
|
336 |
-
public function friendship_leave( $friendship_id, $initiator_user_id, $friend_user_id ) {
|
337 |
|
338 |
-
|
339 |
-
|
340 |
-
|
341 |
-
|
342 |
-
|
343 |
-
|
344 |
-
$friend_user_id,
|
345 |
-
array( 'ref_type' => 'user' ),
|
346 |
-
$this->mycred_type
|
347 |
-
);
|
348 |
-
|
349 |
-
if ( ! $this->core->exclude_user( $friend_user_id ) )
|
350 |
-
$this->core->add_creds(
|
351 |
-
'ended_friendship',
|
352 |
-
$friend_user_id,
|
353 |
-
$this->prefs['leave_friend']['creds'],
|
354 |
-
$this->prefs['leave_friend']['log'],
|
355 |
-
$initiator_user_id,
|
356 |
-
array( 'ref_type' => 'user' ),
|
357 |
-
$this->mycred_type
|
358 |
-
);
|
359 |
-
}
|
360 |
|
361 |
-
|
362 |
-
|
363 |
-
|
364 |
-
|
365 |
-
|
366 |
-
|
367 |
-
|
|
|
|
|
|
|
|
|
368 |
|
369 |
-
|
370 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
371 |
|
372 |
-
|
373 |
-
if ( $this->over_hook_limit( 'new_comment', 'new_comment' ) ) return;
|
374 |
|
375 |
-
|
376 |
-
|
|
|
|
|
|
|
|
|
377 |
|
378 |
-
|
379 |
$this->core->add_creds(
|
380 |
-
'
|
381 |
-
$
|
382 |
-
$this->prefs['
|
383 |
-
$this->prefs['
|
384 |
-
$
|
385 |
-
'
|
386 |
$this->mycred_type
|
387 |
);
|
388 |
-
}
|
389 |
|
390 |
-
|
391 |
-
* Comment Deletion
|
392 |
-
* @since 0.1
|
393 |
-
* @version 1.0
|
394 |
-
*/
|
395 |
-
public function delete_comment( $activity_id, $user_id ) {
|
396 |
-
// Check if user is excluded
|
397 |
-
if ( $this->core->exclude_user( $user_id ) ) return;
|
398 |
-
|
399 |
-
// Make sure this is unique event
|
400 |
-
if ( $this->core->has_entry( 'comment_deletion', $activity_id ) ) return;
|
401 |
-
|
402 |
-
// Execute
|
403 |
$this->core->add_creds(
|
404 |
-
'
|
405 |
-
$
|
406 |
-
$this->prefs['
|
407 |
-
$this->prefs['
|
408 |
-
$
|
409 |
-
'
|
410 |
$this->mycred_type
|
411 |
);
|
412 |
-
}
|
413 |
|
414 |
-
|
415 |
-
|
416 |
-
|
417 |
-
|
418 |
-
|
419 |
-
|
420 |
-
|
421 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
422 |
|
423 |
-
|
424 |
-
|
|
|
|
|
|
|
|
|
425 |
|
426 |
-
|
427 |
-
|
428 |
|
429 |
-
|
|
|
|
|
|
|
|
|
430 |
$this->core->add_creds(
|
431 |
-
'
|
432 |
-
$
|
433 |
-
$this->prefs['
|
434 |
-
$this->prefs['
|
435 |
-
$
|
436 |
-
'
|
437 |
$this->mycred_type
|
438 |
);
|
439 |
-
}
|
440 |
-
|
441 |
-
/**
|
442 |
-
* Send Gift
|
443 |
-
* @since 0.1
|
444 |
-
* @version 1.1
|
445 |
-
*/
|
446 |
-
public function send_gifts( $to_user_id, $from_user_id ) {
|
447 |
-
// Check if sender is excluded
|
448 |
-
if ( $this->core->exclude_user( $from_user_id ) ) return;
|
449 |
|
450 |
-
|
451 |
-
if ( $this->core->exclude_user( $to_user_id ) ) return;
|
452 |
-
|
453 |
-
// Limit
|
454 |
-
if ( ! $this->over_hook_limit( 'send_gift', 'sending_gift', $from_user_id ) )
|
455 |
-
$this->core->add_creds(
|
456 |
-
'sending_gift',
|
457 |
-
$from_user_id,
|
458 |
-
$this->prefs['send_gift']['creds'],
|
459 |
-
$this->prefs['send_gift']['log'],
|
460 |
-
$to_user_id,
|
461 |
-
'bp_gifts',
|
462 |
-
$this->mycred_type
|
463 |
-
);
|
464 |
-
}
|
465 |
|
466 |
-
|
467 |
-
|
468 |
-
|
469 |
-
|
470 |
-
|
471 |
-
|
472 |
|
473 |
-
|
474 |
|
475 |
-
|
476 |
-
|
477 |
|
478 |
-
|
479 |
-
|
480 |
-
|
481 |
|
482 |
?>
|
483 |
<!-- Creds for Profile Update -->
|
@@ -629,527 +647,559 @@ if ( defined( 'myCRED_VERSION' ) ) {
|
|
629 |
</li>
|
630 |
</ol>
|
631 |
<?php
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
632 |
}
|
633 |
-
|
634 |
-
/**
|
635 |
-
* Sanitise Preferences
|
636 |
-
* @since 1.6
|
637 |
-
* @version 1.0
|
638 |
-
*/
|
639 |
-
function sanitise_preferences( $data ) {
|
640 |
-
|
641 |
-
if ( isset( $data['update']['limit'] ) && isset( $data['update']['limit_by'] ) ) {
|
642 |
-
$limit = sanitize_text_field( $data['update']['limit'] );
|
643 |
-
if ( $limit == '' ) $limit = 0;
|
644 |
-
$data['update']['limit'] = $limit . '/' . $data['update']['limit_by'];
|
645 |
-
unset( $data['update']['limit_by'] );
|
646 |
-
}
|
647 |
-
|
648 |
-
if ( isset( $data['removed_update']['limit'] ) && isset( $data['removed_update']['limit_by'] ) ) {
|
649 |
-
$limit = sanitize_text_field( $data['removed_update']['limit'] );
|
650 |
-
if ( $limit == '' ) $limit = 0;
|
651 |
-
$data['removed_update']['limit'] = $limit . '/' . $data['removed_update']['limit_by'];
|
652 |
-
unset( $data['removed_update']['limit_by'] );
|
653 |
-
}
|
654 |
-
|
655 |
-
if ( isset( $data['avatar']['limit'] ) && isset( $data['avatar']['limit_by'] ) ) {
|
656 |
-
$limit = sanitize_text_field( $data['avatar']['limit'] );
|
657 |
-
if ( $limit == '' ) $limit = 0;
|
658 |
-
$data['avatar']['limit'] = $limit . '/' . $data['avatar']['limit_by'];
|
659 |
-
unset( $data['avatar']['limit_by'] );
|
660 |
-
}
|
661 |
-
|
662 |
-
if ( isset( $data['new_friend']['limit'] ) && isset( $data['new_friend']['limit_by'] ) ) {
|
663 |
-
$limit = sanitize_text_field( $data['new_friend']['limit'] );
|
664 |
-
if ( $limit == '' ) $limit = 0;
|
665 |
-
$data['new_friend']['limit'] = $limit . '/' . $data['new_friend']['limit_by'];
|
666 |
-
unset( $data['new_friend']['limit_by'] );
|
667 |
-
}
|
668 |
-
|
669 |
-
$data['new_friend']['block'] = ( isset( $data['new_friend']['block'] ) ) ? absint( $data['new_friend']['block'] ) : 0;
|
670 |
-
|
671 |
-
if ( isset( $data['new_comment']['limit'] ) && isset( $data['new_comment']['limit_by'] ) ) {
|
672 |
-
$limit = sanitize_text_field( $data['new_comment']['limit'] );
|
673 |
-
if ( $limit == '' ) $limit = 0;
|
674 |
-
$data['new_comment']['limit'] = $limit . '/' . $data['new_comment']['limit_by'];
|
675 |
-
unset( $data['new_comment']['limit_by'] );
|
676 |
-
}
|
677 |
-
|
678 |
-
if ( isset( $data['message']['limit'] ) && isset( $data['message']['limit_by'] ) ) {
|
679 |
-
$limit = sanitize_text_field( $data['message']['limit'] );
|
680 |
-
if ( $limit == '' ) $limit = 0;
|
681 |
-
$data['message']['limit'] = $limit . '/' . $data['message']['limit_by'];
|
682 |
-
unset( $data['message']['limit_by'] );
|
683 |
-
}
|
684 |
-
|
685 |
-
if ( isset( $data['send_gift']['limit'] ) && isset( $data['send_gift']['limit_by'] ) ) {
|
686 |
-
$limit = sanitize_text_field( $data['send_gift']['limit'] );
|
687 |
-
if ( $limit == '' ) $limit = 0;
|
688 |
-
$data['send_gift']['limit'] = $limit . '/' . $data['send_gift']['limit_by'];
|
689 |
-
unset( $data['send_gift']['limit_by'] );
|
690 |
-
}
|
691 |
-
|
692 |
-
return $data;
|
693 |
|
|
|
|
|
|
|
|
|
|
|
694 |
}
|
695 |
-
}
|
696 |
-
}
|
697 |
|
698 |
-
|
699 |
-
|
700 |
-
|
701 |
-
|
702 |
-
|
703 |
-
* @version 1.1
|
704 |
-
*/
|
705 |
-
if ( ! class_exists( 'myCRED_BuddyPress_Groups' ) && class_exists( 'myCRED_Hook' ) ) {
|
706 |
-
class myCRED_BuddyPress_Groups extends myCRED_Hook {
|
707 |
-
|
708 |
-
/**
|
709 |
-
* Construct
|
710 |
-
*/
|
711 |
-
function __construct( $hook_prefs, $type = 'mycred_default' ) {
|
712 |
-
parent::__construct( array(
|
713 |
-
'id' => 'hook_bp_groups',
|
714 |
-
'defaults' => array(
|
715 |
-
'create' => array(
|
716 |
-
'creds' => 10,
|
717 |
-
'log' => '%plural% for creating a new group',
|
718 |
-
'min' => 0
|
719 |
-
),
|
720 |
-
'delete' => array(
|
721 |
-
'creds' => '-10',
|
722 |
-
'log' => '%singular% deduction for deleting a group'
|
723 |
-
),
|
724 |
-
'new_topic' => array(
|
725 |
-
'creds' => 1,
|
726 |
-
'log' => '%plural% for new group topic',
|
727 |
-
'limit' => '0/x'
|
728 |
-
),
|
729 |
-
'edit_topic' => array(
|
730 |
-
'creds' => 1,
|
731 |
-
'log' => '%plural% for updating group topic',
|
732 |
-
'limit' => '0/x'
|
733 |
-
),
|
734 |
-
'new_post' => array(
|
735 |
-
'creds' => 1,
|
736 |
-
'log' => '%plural% for new group post',
|
737 |
-
'limit' => '0/x'
|
738 |
-
),
|
739 |
-
'edit_post' => array(
|
740 |
-
'creds' => 1,
|
741 |
-
'log' => '%plural% for updating group post',
|
742 |
-
'limit' => '0/x'
|
743 |
-
),
|
744 |
-
'join' => array(
|
745 |
-
'creds' => 1,
|
746 |
-
'log' => '%plural% for joining new group',
|
747 |
-
'limit' => '0/x'
|
748 |
-
),
|
749 |
-
'leave' => array(
|
750 |
-
'creds' => '-5',
|
751 |
-
'log' => '%singular% deduction for leaving group'
|
752 |
-
),
|
753 |
-
'avatar' => array(
|
754 |
-
'creds' => 1,
|
755 |
-
'log' => '%plural% for new group avatar',
|
756 |
-
'limit' => '0/x'
|
757 |
-
),
|
758 |
-
'comments' => array(
|
759 |
-
'creds' => 1,
|
760 |
-
'log' => '%plural% for new group comment',
|
761 |
-
'limit' => '0/x'
|
762 |
-
)
|
763 |
-
)
|
764 |
-
), $hook_prefs, $type );
|
765 |
}
|
766 |
|
767 |
-
|
768 |
-
|
769 |
-
|
770 |
-
|
771 |
-
|
772 |
-
|
773 |
-
if ( $this->prefs['create']['creds'] != 0 && $this->prefs['create']['min'] == 0 )
|
774 |
-
add_action( 'groups_group_create_complete', array( $this, 'create_group' ) );
|
775 |
|
776 |
-
|
777 |
-
add_filter( 'bp_user_can_create_groups', array( $this, 'restrict_group_creation' ), 99, 2 );
|
778 |
|
779 |
-
|
780 |
-
|
|
|
|
|
|
|
|
|
781 |
|
782 |
-
|
783 |
-
|
|
|
|
|
|
|
|
|
784 |
|
785 |
-
|
786 |
-
|
|
|
|
|
|
|
|
|
787 |
|
788 |
-
|
789 |
-
add_action( 'bp_forums_new_post', array( $this, 'new_post' ) );
|
790 |
|
791 |
-
|
792 |
-
add_action( 'groups_edit_forum_post', array( $this, 'edit_post' ) );
|
793 |
|
794 |
-
|
795 |
-
|
796 |
-
|
797 |
-
if ( $this->prefs['join']['creds'] < 0 )
|
798 |
-
add_filter( 'bp_get_group_join_button', array( $this, 'restrict_joining_group' ) );
|
799 |
|
800 |
-
|
801 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
802 |
|
803 |
-
|
804 |
-
add_action( 'groups_screen_group_admin_avatar', array( $this, 'avatar_upload_group' ) );
|
805 |
|
806 |
-
|
807 |
-
|
808 |
-
|
|
|
|
|
|
|
809 |
|
810 |
-
|
811 |
-
|
812 |
-
* @since 0.1
|
813 |
-
* @version 1.0
|
814 |
-
*/
|
815 |
-
public function create_group( $group_id ) {
|
816 |
-
global $bp;
|
817 |
|
818 |
-
|
819 |
-
|
820 |
|
821 |
-
|
822 |
-
$this
|
823 |
-
'creation_of_new_group',
|
824 |
-
$bp->loggedin_user->id,
|
825 |
-
$this->prefs['create']['creds'],
|
826 |
-
$this->prefs['create']['log'],
|
827 |
-
$group_id,
|
828 |
-
'bp_group',
|
829 |
-
$this->mycred_type
|
830 |
-
);
|
831 |
-
}
|
832 |
|
833 |
-
|
834 |
-
|
835 |
-
* If creating a group costs and the user does not have enough points, we restrict creations.
|
836 |
-
* @since 0.1
|
837 |
-
* @version 1.0
|
838 |
-
*/
|
839 |
-
public function restrict_group_creation( $can_create, $restricted ) {
|
840 |
-
global $bp;
|
841 |
|
842 |
-
|
843 |
-
|
844 |
|
845 |
-
|
846 |
-
|
847 |
-
$balance = $this->core->get_users_cred( $bp->loggedin_user->id, $this->mycred_type );
|
848 |
-
if ( $cost > $balance ) return false;
|
849 |
|
850 |
-
|
851 |
-
|
852 |
|
853 |
-
|
854 |
-
|
855 |
-
* If joining a group costs and the user does not have enough points, we restrict joining of groups.
|
856 |
-
* @since 0.1
|
857 |
-
* @version 1.0
|
858 |
-
*/
|
859 |
-
public function restrict_joining_group( $button ) {
|
860 |
-
global $bp;
|
861 |
|
862 |
-
|
863 |
-
|
864 |
|
865 |
-
|
866 |
-
|
867 |
-
$balance = $this->core->get_users_cred( $bp->loggedin_user->id, $this->mycred_type );
|
868 |
-
if ( $cost > $balance ) return false;
|
869 |
|
870 |
-
|
871 |
-
|
872 |
|
873 |
-
|
874 |
-
|
875 |
-
* @since 0.1
|
876 |
-
* @version 1.0
|
877 |
-
*/
|
878 |
-
public function delete_group( $group_id ) {
|
879 |
-
global $bp;
|
880 |
|
881 |
-
|
882 |
-
if ( $bp->loggedin_user->is_super_admin )
|
883 |
-
$user_id = $bp->groups->current_group->creator_id;
|
884 |
|
885 |
-
|
886 |
-
|
887 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
888 |
|
889 |
-
|
890 |
-
else
|
891 |
-
$user_id = $bp->loggedin_user->id;
|
892 |
|
893 |
-
|
894 |
-
|
|
|
|
|
|
|
|
|
|
|
895 |
|
896 |
-
|
897 |
-
$this->core->add_creds(
|
898 |
-
'deletion_of_group',
|
899 |
-
$user_id,
|
900 |
-
$this->prefs['delete']['creds'],
|
901 |
-
$this->prefs['delete']['log'],
|
902 |
-
$group_id,
|
903 |
-
'bp_group',
|
904 |
-
$this->mycred_type
|
905 |
-
);
|
906 |
-
}
|
907 |
|
908 |
-
|
909 |
-
|
910 |
-
* @since 0.1
|
911 |
-
* @version 1.1
|
912 |
-
*/
|
913 |
-
public function new_topic( $topic_id ) {
|
914 |
-
global $bp;
|
915 |
|
916 |
-
|
917 |
-
|
|
|
|
|
918 |
|
919 |
-
|
920 |
-
if ( $this->over_hook_limit( 'new_topic', 'new_group_forum_topic' ) ) return;
|
921 |
|
922 |
-
|
923 |
-
if ( $this->core->has_entry( 'new_group_forum_topic', $topic_id, $bp->loggedin_user->id ) ) return;
|
924 |
|
925 |
-
|
926 |
-
|
927 |
-
|
928 |
-
|
929 |
-
|
930 |
-
|
931 |
-
|
932 |
-
'bp_ftopic',
|
933 |
-
$this->mycred_type
|
934 |
-
);
|
935 |
-
}
|
936 |
|
937 |
-
|
938 |
-
* Edit Group Forum Topic
|
939 |
-
* @since 0.1
|
940 |
-
* @version 1.0
|
941 |
-
*/
|
942 |
-
public function edit_topic( $topic_id ) {
|
943 |
-
global $bp;
|
944 |
|
945 |
-
|
946 |
-
|
947 |
|
948 |
-
|
949 |
-
|
|
|
|
|
950 |
|
951 |
-
|
952 |
-
$this->core->add_creds(
|
953 |
-
'edit_group_forum_topic',
|
954 |
-
$bp->loggedin_user->id,
|
955 |
-
$this->prefs['edit_topic']['creds'],
|
956 |
-
$this->prefs['edit_topic']['log'],
|
957 |
-
$topic_id,
|
958 |
-
'bp_ftopic',
|
959 |
-
$this->mycred_type
|
960 |
-
);
|
961 |
-
}
|
962 |
|
963 |
-
|
964 |
-
* New Group Forum Post
|
965 |
-
* @since 0.1
|
966 |
-
* @version 1.1
|
967 |
-
*/
|
968 |
-
public function new_post( $post_id ) {
|
969 |
-
global $bp;
|
970 |
|
971 |
-
|
972 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
973 |
|
974 |
-
|
975 |
-
if ( $this->over_hook_limit( 'new_post', 'new_group_forum_post' ) ) return;
|
976 |
|
977 |
-
|
978 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
979 |
|
980 |
-
|
981 |
-
$this->core->add_creds(
|
982 |
-
'new_group_forum_post',
|
983 |
-
$bp->loggedin_user->id,
|
984 |
-
$this->prefs['new_post']['creds'],
|
985 |
-
$this->prefs['new_post']['log'],
|
986 |
-
$post_id,
|
987 |
-
'bp_fpost',
|
988 |
-
$this->mycred_type
|
989 |
-
);
|
990 |
-
}
|
991 |
|
992 |
-
|
993 |
-
|
994 |
-
|
995 |
-
|
996 |
-
|
997 |
-
|
998 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
999 |
|
1000 |
-
|
1001 |
-
if ( $this->core->exclude_user( $bp->loggedin_user->id ) ) return;
|
1002 |
|
1003 |
-
|
1004 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1005 |
|
1006 |
-
|
1007 |
-
$this->core->add_creds(
|
1008 |
-
'edit_group_forum_post',
|
1009 |
-
$bp->loggedin_user->id,
|
1010 |
-
$this->prefs['edit_post']['creds'],
|
1011 |
-
$this->prefs['edit_post']['log'],
|
1012 |
-
$post_id,
|
1013 |
-
'bp_fpost',
|
1014 |
-
$this->mycred_type
|
1015 |
-
);
|
1016 |
-
}
|
1017 |
|
1018 |
-
|
1019 |
-
|
1020 |
-
|
1021 |
-
|
1022 |
-
|
1023 |
-
|
1024 |
-
|
1025 |
-
|
1026 |
-
|
1027 |
-
|
1028 |
-
|
1029 |
-
|
1030 |
-
|
1031 |
-
|
1032 |
-
|
1033 |
-
|
1034 |
-
|
1035 |
-
|
1036 |
-
|
1037 |
-
|
1038 |
-
|
1039 |
-
|
1040 |
-
|
1041 |
-
|
1042 |
-
|
1043 |
-
|
1044 |
-
// Check if user should be excluded
|
1045 |
-
if ( $this->core->exclude_user( $user_id ) ) return;
|
1046 |
-
|
1047 |
-
// Limit
|
1048 |
-
if ( $this->over_hook_limit( 'join', 'joining_group' ) ) return;
|
1049 |
-
|
1050 |
-
// Make sure this is unique event
|
1051 |
-
if ( $this->core->has_entry( 'joining_group', $group_id, $user_id ) ) return;
|
1052 |
-
|
1053 |
-
// Execute
|
1054 |
-
$this->core->add_creds(
|
1055 |
-
'joining_group',
|
1056 |
-
$user_id,
|
1057 |
-
$this->prefs['join']['creds'],
|
1058 |
-
$this->prefs['join']['log'],
|
1059 |
-
$group_id,
|
1060 |
-
'bp_group',
|
1061 |
-
$this->mycred_type
|
1062 |
-
);
|
1063 |
-
}
|
1064 |
|
1065 |
-
|
1066 |
-
* Leaving Group
|
1067 |
-
* @since 0.1
|
1068 |
-
* @version 1.0
|
1069 |
-
*/
|
1070 |
-
public function leave_group( $group_id, $user_id ) {
|
1071 |
-
// Check if user should be excluded
|
1072 |
-
if ( $this->core->exclude_user( $user_id ) ) return;
|
1073 |
|
1074 |
-
|
1075 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1076 |
|
1077 |
-
// Execute
|
1078 |
-
$this->core->add_creds(
|
1079 |
-
'leaving_group',
|
1080 |
-
$user_id,
|
1081 |
-
$this->prefs['leave']['creds'],
|
1082 |
-
$this->prefs['leave']['log'],
|
1083 |
-
$group_id,
|
1084 |
-
'bp_group',
|
1085 |
-
$this->mycred_type
|
1086 |
-
);
|
1087 |
}
|
1088 |
|
1089 |
-
|
1090 |
-
|
1091 |
-
* @since 0.1
|
1092 |
-
* @version 1.1
|
1093 |
-
*/
|
1094 |
-
public function avatar_upload_group( $group_id ) {
|
1095 |
-
global $bp;
|
1096 |
|
1097 |
-
|
1098 |
-
|
1099 |
|
1100 |
-
|
1101 |
-
|
1102 |
|
1103 |
-
|
1104 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1105 |
|
1106 |
-
|
1107 |
-
|
1108 |
-
|
1109 |
-
|
1110 |
-
|
1111 |
-
|
1112 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1113 |
'bp_group',
|
1114 |
-
|
1115 |
-
|
1116 |
-
}
|
1117 |
|
1118 |
-
|
1119 |
-
* New Group Comment
|
1120 |
-
* @since 0.1
|
1121 |
-
* @version 1.1
|
1122 |
-
*/
|
1123 |
-
public function new_group_comment( $content, $user_id, $group_id, $activity_id ) {
|
1124 |
-
// Check if user should be excluded
|
1125 |
-
if ( $this->core->exclude_user( $user_id ) ) return;
|
1126 |
|
1127 |
-
|
1128 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1129 |
|
1130 |
-
|
1131 |
-
if ( $this->core->has_entry( 'new_group_comment', $activity_id, $user_id ) ) return;
|
1132 |
|
1133 |
-
|
1134 |
-
|
1135 |
-
|
1136 |
-
|
1137 |
-
|
1138 |
-
|
1139 |
-
|
1140 |
-
|
1141 |
-
|
1142 |
-
|
1143 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1144 |
|
1145 |
-
|
1146 |
-
* Preferences
|
1147 |
-
* @since 0.1
|
1148 |
-
* @version 1.2
|
1149 |
-
*/
|
1150 |
-
public function preferences() {
|
1151 |
-
$prefs = $this->prefs; ?>
|
1152 |
|
|
|
1153 |
<!-- Creds for New Group -->
|
1154 |
<label for="<?php echo $this->field_id( array( 'create', 'creds' ) ); ?>" class="subheader"><?php echo $this->core->template_tags_general( __( '%plural% for Creating Groups', 'mycred' ) ); ?></label>
|
1155 |
<ol>
|
@@ -1317,69 +1367,70 @@ if ( defined( 'myCRED_VERSION' ) ) {
|
|
1317 |
</li>
|
1318 |
</ol>
|
1319 |
<?php
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1320 |
}
|
1321 |
-
|
1322 |
-
/**
|
1323 |
-
* Sanitise Preferences
|
1324 |
-
* @since 1.6
|
1325 |
-
* @version 1.0
|
1326 |
-
*/
|
1327 |
-
function sanitise_preferences( $data ) {
|
1328 |
-
|
1329 |
-
if ( isset( $data['new_topic']['limit'] ) && isset( $data['new_topic']['limit_by'] ) ) {
|
1330 |
-
$limit = sanitize_text_field( $data['new_topic']['limit'] );
|
1331 |
-
if ( $limit == '' ) $limit = 0;
|
1332 |
-
$data['new_topic']['limit'] = $limit . '/' . $data['new_topic']['limit_by'];
|
1333 |
-
unset( $data['new_topic']['limit_by'] );
|
1334 |
-
}
|
1335 |
-
|
1336 |
-
if ( isset( $data['edit_topic']['limit'] ) && isset( $data['edit_topic']['limit_by'] ) ) {
|
1337 |
-
$limit = sanitize_text_field( $data['edit_topic']['limit'] );
|
1338 |
-
if ( $limit == '' ) $limit = 0;
|
1339 |
-
$data['edit_topic']['limit'] = $limit . '/' . $data['edit_topic']['limit_by'];
|
1340 |
-
unset( $data['edit_topic']['limit_by'] );
|
1341 |
-
}
|
1342 |
-
|
1343 |
-
if ( isset( $data['new_post']['limit'] ) && isset( $data['new_post']['limit_by'] ) ) {
|
1344 |
-
$limit = sanitize_text_field( $data['new_post']['limit'] );
|
1345 |
-
if ( $limit == '' ) $limit = 0;
|
1346 |
-
$data['new_post']['limit'] = $limit . '/' . $data['new_post']['limit_by'];
|
1347 |
-
unset( $data['new_post']['limit_by'] );
|
1348 |
-
}
|
1349 |
-
|
1350 |
-
if ( isset( $data['edit_post']['limit'] ) && isset( $data['edit_post']['limit_by'] ) ) {
|
1351 |
-
$limit = sanitize_text_field( $data['edit_post']['limit'] );
|
1352 |
-
if ( $limit == '' ) $limit = 0;
|
1353 |
-
$data['edit_post']['limit'] = $limit . '/' . $data['edit_post']['limit_by'];
|
1354 |
-
unset( $data['edit_post']['limit_by'] );
|
1355 |
-
}
|
1356 |
-
|
1357 |
-
if ( isset( $data['join']['limit'] ) && isset( $data['join']['limit_by'] ) ) {
|
1358 |
-
$limit = sanitize_text_field( $data['join']['limit'] );
|
1359 |
-
if ( $limit == '' ) $limit = 0;
|
1360 |
-
$data['join']['limit'] = $limit . '/' . $data['join']['limit_by'];
|
1361 |
-
unset( $data['join']['limit_by'] );
|
1362 |
-
}
|
1363 |
-
|
1364 |
-
if ( isset( $data['avatar']['limit'] ) && isset( $data['avatar']['limit_by'] ) ) {
|
1365 |
-
$limit = sanitize_text_field( $data['avatar']['limit'] );
|
1366 |
-
if ( $limit == '' ) $limit = 0;
|
1367 |
-
$data['avatar']['limit'] = $limit . '/' . $data['avatar']['limit_by'];
|
1368 |
-
unset( $data['avatar']['limit_by'] );
|
1369 |
-
}
|
1370 |
-
|
1371 |
-
if ( isset( $data['comments']['limit'] ) && isset( $data['comments']['limit_by'] ) ) {
|
1372 |
-
$limit = sanitize_text_field( $data['comments']['limit'] );
|
1373 |
-
if ( $limit == '' ) $limit = 0;
|
1374 |
-
$data['comments']['limit'] = $limit . '/' . $data['comments']['limit_by'];
|
1375 |
-
unset( $data['comments']['limit_by'] );
|
1376 |
-
}
|
1377 |
-
|
1378 |
-
return $data;
|
1379 |
|
|
|
|
|
|
|
|
|
|
|
1380 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1381 |
}
|
|
|
1382 |
}
|
|
|
1383 |
|
1384 |
-
}
|
1385 |
?>
|
1 |
<?php
|
2 |
+
if ( ! defined( 'myCRED_VERSION' ) ) exit;
|
3 |
|
4 |
/**
|
5 |
+
* Register Hook
|
6 |
* @since 0.1
|
7 |
+
* @version 1.0
|
8 |
*/
|
9 |
+
add_filter( 'mycred_setup_hooks', 'BuddyPress_myCRED_Hook' );
|
10 |
+
function BuddyPress_myCRED_Hook( $installed ) {
|
11 |
+
|
12 |
+
if ( bp_is_active( 'xprofile' ) ) {
|
13 |
+
$installed['hook_bp_profile'] = array(
|
14 |
+
'title' => __( 'BuddyPress: Members', 'mycred' ),
|
15 |
+
'description' => __( 'Awards %_plural% for profile related actions.', 'mycred' ),
|
16 |
+
'callback' => array( 'myCRED_BuddyPress_Profile' )
|
17 |
+
);
|
18 |
+
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
19 |
|
20 |
+
if ( bp_is_active( 'groups' ) ) {
|
21 |
+
$installed['hook_bp_groups'] = array(
|
22 |
+
'title' => __( 'BuddyPress: Groups', 'mycred' ),
|
23 |
+
'description' => __( 'Awards %_plural% for group related actions. Use minus to deduct %_plural% or zero to disable a specific hook.', 'mycred' ),
|
24 |
+
'callback' => array( 'myCRED_BuddyPress_Groups' )
|
25 |
+
);
|
26 |
}
|
27 |
|
28 |
+
return $installed;
|
29 |
+
|
30 |
+
}
|
31 |
+
|
32 |
+
/**
|
33 |
+
* myCRED_BuddyPress_Profile class
|
34 |
+
* Creds for profile updates
|
35 |
+
* @since 0.1
|
36 |
+
* @version 1.2
|
37 |
+
*/
|
38 |
+
if ( ! class_exists( 'myCRED_BuddyPress_Profile' ) && class_exists( 'myCRED_Hook' ) ) :
|
39 |
+
class myCRED_BuddyPress_Profile extends myCRED_Hook {
|
40 |
+
|
41 |
+
/**
|
42 |
+
* Construct
|
43 |
+
*/
|
44 |
+
function __construct( $hook_prefs, $type = 'mycred_default' ) {
|
45 |
+
|
46 |
+
parent::__construct( array(
|
47 |
+
'id' => 'hook_bp_profile',
|
48 |
+
'defaults' => array(
|
49 |
+
'update' => array(
|
50 |
+
'creds' => 1,
|
51 |
+
'log' => '%plural% for updating profile',
|
52 |
+
'limit' => '0/x'
|
53 |
+
),
|
54 |
+
'removed_update' => array(
|
55 |
+
'creds' => 1,
|
56 |
+
'log' => '%plural% for removing profile update',
|
57 |
+
'limit' => '0/x'
|
58 |
+
),
|
59 |
+
'avatar' => array(
|
60 |
+
'creds' => 1,
|
61 |
+
'log' => '%plural% for new avatar',
|
62 |
+
'limit' => '0/x'
|
63 |
+
),
|
64 |
+
'new_friend' => array(
|
65 |
+
'creds' => 1,
|
66 |
+
'log' => '%plural% for new friendship',
|
67 |
+
'block' => 0,
|
68 |
+
'limit' => '0/x'
|
69 |
+
),
|
70 |
+
'leave_friend' => array(
|
71 |
+
'creds' => '-1',
|
72 |
+
'log' => '%singular% deduction for loosing a friend',
|
73 |
+
'limit' => '0/x'
|
74 |
+
),
|
75 |
+
'new_comment' => array(
|
76 |
+
'creds' => 1,
|
77 |
+
'log' => '%plural% for new comment',
|
78 |
+
'limit' => '0/x'
|
79 |
+
),
|
80 |
+
'delete_comment' => array(
|
81 |
+
'creds' => '-1',
|
82 |
+
'log' => '%singular% deduction for comment removal'
|
83 |
+
),
|
84 |
+
'message' => array(
|
85 |
+
'creds' => 1,
|
86 |
+
'log' => '%plural% for sending a message',
|
87 |
+
'limit' => '0/x'
|
88 |
+
),
|
89 |
+
'send_gift' => array(
|
90 |
+
'creds' => 1,
|
91 |
+
'log' => '%plural% for sending a gift',
|
92 |
+
'limit' => '0/x'
|
93 |
)
|
94 |
+
)
|
95 |
+
), $hook_prefs, $type );
|
96 |
|
97 |
+
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
98 |
|
99 |
+
/**
|
100 |
+
* Run
|
101 |
+
* @since 0.1
|
102 |
+
* @version 1.0
|
103 |
+
*/
|
104 |
+
public function run() {
|
105 |
|
106 |
+
if ( $this->prefs['update']['creds'] != 0 )
|
107 |
+
add_action( 'bp_activity_posted_update', array( $this, 'new_update' ), 10, 3 );
|
108 |
|
109 |
+
if ( $this->prefs['removed_update']['creds'] != 0 )
|
110 |
+
add_action( 'bp_activity_delete', array( $this, 'remove_update' ), 10, 3 );
|
|
|
|
|
111 |
|
112 |
+
if ( $this->prefs['avatar']['creds'] != 0 )
|
113 |
+
add_action( 'xprofile_avatar_uploaded', array( $this, 'avatar_upload' ) );
|
114 |
|
115 |
+
if ( $this->prefs['new_friend']['creds'] < 0 && isset( $this->prefs['new_friend']['block'] ) && $this->prefs['new_friend']['block'] == 1 ) {
|
116 |
+
add_action( 'wp_ajax_addremove_friend', array( $this, 'ajax_addremove_friend' ), 0 );
|
117 |
+
add_filter( 'bp_get_add_friend_button', array( $this, 'disable_friendship' ) );
|
118 |
+
}
|
119 |
|
120 |
+
if ( $this->prefs['new_friend']['creds'] != 0 )
|
121 |
+
add_action( 'friends_friendship_accepted', array( $this, 'friendship_join' ), 10, 3 );
|
122 |
|
123 |
+
if ( $this->prefs['leave_friend']['creds'] != 0 )
|
124 |
+
add_action( 'friends_friendship_deleted', array( $this, 'friendship_leave' ), 10, 3 );
|
125 |
|
126 |
+
if ( $this->prefs['new_comment']['creds'] != 0 )
|
127 |
+
add_action( 'bp_activity_comment_posted', array( $this, 'new_comment' ), 10, 2 );
|
128 |
|
129 |
+
if ( $this->prefs['delete_comment']['creds'] != 0 )
|
130 |
+
add_action( 'bp_activity_action_delete_activity', array( $this, 'delete_comment' ), 10, 2 );
|
|
|
131 |
|
132 |
+
if ( $this->prefs['message']['creds'] != 0 )
|
133 |
+
add_action( 'messages_message_sent', array( $this, 'messages' ) );
|
|
|
|
|
|
|
|
|
|
|
|
|
134 |
|
135 |
+
if ( $this->prefs['send_gift']['creds'] != 0 )
|
136 |
+
add_action( 'bp_gifts_send_gifts', array( $this, 'send_gifts' ), 10, 2 );
|
137 |
|
138 |
+
}
|
|
|
139 |
|
140 |
+
/**
|
141 |
+
* New Profile Update
|
142 |
+
* @since 0.1
|
143 |
+
* @version 1.2
|
144 |
+
*/
|
145 |
+
public function new_update( $content, $user_id, $activity_id ) {
|
146 |
+
|
147 |
+
// Check if user is excluded
|
148 |
+
if ( $this->core->exclude_user( $user_id ) ) return;
|
149 |
+
|
150 |
+
// Limit
|
151 |
+
if ( $this->over_hook_limit( 'update', 'new_profile_update', $user_id ) ) return;
|
152 |
+
|
153 |
+
// Make sure this is unique event
|
154 |
+
if ( $this->core->has_entry( 'new_profile_update', $activity_id, $user_id ) ) return;
|
155 |
+
|
156 |
+
// Execute
|
157 |
+
$this->core->add_creds(
|
158 |
+
'new_profile_update',
|
159 |
+
$user_id,
|
160 |
+
$this->prefs['update']['creds'],
|
161 |
+
$this->prefs['update']['log'],
|
162 |
+
$activity_id,
|
163 |
+
'bp_activity',
|
164 |
+
$this->mycred_type
|
165 |
+
);
|
166 |
|
167 |
+
}
|
|
|
|
|
|
|
|
|
|
|
168 |
|
169 |
+
/**
|
170 |
+
* Removing Profile Update
|
171 |
+
* @since 1.6
|
172 |
+
* @version 1.0
|
173 |
+
*/
|
174 |
+
public function remove_update( $args ) {
|
175 |
|
176 |
+
if ( ! isset( $args['user_id'] ) || $args['user_id'] === false ) return;
|
177 |
|
178 |
+
$user_id = absint( $args['user_id'] );
|
|
|
179 |
|
180 |
+
// Check if user is excluded
|
181 |
+
if ( $this->core->exclude_user( $user_id ) ) return;
|
182 |
|
183 |
+
// Limit
|
184 |
+
if ( $this->over_hook_limit( 'removed_update', 'deleted_profile_update', $user_id ) ) return;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
185 |
|
186 |
+
// Execute
|
187 |
+
$this->core->add_creds(
|
188 |
+
'deleted_profile_update',
|
189 |
+
$user_id,
|
190 |
+
$this->prefs['removed_update']['creds'],
|
191 |
+
$this->prefs['removed_update']['log'],
|
192 |
+
0,
|
193 |
+
$args,
|
194 |
+
$this->mycred_type
|
195 |
+
);
|
196 |
|
197 |
+
}
|
|
|
198 |
|
199 |
+
/**
|
200 |
+
* Avatar Upload
|
201 |
+
* @since 0.1
|
202 |
+
* @version 1.2
|
203 |
+
*/
|
204 |
+
public function avatar_upload() {
|
205 |
+
|
206 |
+
$user_id = apply_filters( 'bp_xprofile_new_avatar_user_id', bp_displayed_user_id() );
|
207 |
+
|
208 |
+
// Check if user is excluded
|
209 |
+
if ( $this->core->exclude_user( $user_id ) ) return;
|
210 |
+
|
211 |
+
// Limit
|
212 |
+
if ( $this->over_hook_limit( 'avatar', 'upload_avatar', $user_id ) ) return;
|
213 |
+
|
214 |
+
// Execute
|
215 |
+
$this->core->add_creds(
|
216 |
+
'upload_avatar',
|
217 |
+
$user_id,
|
218 |
+
$this->prefs['avatar']['creds'],
|
219 |
+
$this->prefs['avatar']['log'],
|
220 |
+
0,
|
221 |
+
'',
|
222 |
+
$this->mycred_type
|
223 |
+
);
|
224 |
+
|
225 |
+
}
|
226 |
+
|
227 |
+
/**
|
228 |
+
* AJAX: Add/Remove Friend
|
229 |
+
* Intercept addremovefriend ajax call and block
|
230 |
+
* action if the user can not afford new friendship.
|
231 |
+
* @since 1.5.4
|
232 |
+
* @version 1.0
|
233 |
+
*/
|
234 |
+
public function ajax_addremove_friend() {
|
235 |
+
|
236 |
+
// Bail if not a POST action
|
237 |
+
if ( 'POST' !== strtoupper( $_SERVER['REQUEST_METHOD'] ) )
|
238 |
+
return;
|
239 |
+
|
240 |
+
$user_id = bp_loggedin_user_id();
|
241 |
+
$balance = $this->core->get_users_balance( $user_id, $this->mycred_type );
|
242 |
+
$cost = abs( $this->prefs['new_friend']['creds'] );
|
243 |
+
|
244 |
+
// Take into account any existing requests which will be charged when the new
|
245 |
+
// friend approves it. Prevents users from requesting more then they can afford.
|
246 |
+
$pending_requests = $this->count_pending_requests( $user_id );
|
247 |
+
if ( $pending_requests > 0 )
|
248 |
+
$cost = $cost + ( $cost * $pending_requests );
|
249 |
+
|
250 |
+
// Prevent BP from running this ajax call
|
251 |
+
if ( $balance < $cost ) {
|
252 |
+
echo apply_filters( 'mycred_bp_declined_addfriend', __( 'Insufficient Funds', 'mycred' ), $this );
|
253 |
+
exit;
|
254 |
}
|
255 |
|
256 |
+
}
|
257 |
+
|
258 |
+
/**
|
259 |
+
* Disable Friendship
|
260 |
+
* If we deduct points from a user for new friendships
|
261 |
+
* we disable the friendship button if the user ca not afford it.
|
262 |
+
* @since 1.5.4
|
263 |
+
* @version 1.0
|
264 |
+
*/
|
265 |
+
public function disable_friendship( $button ) {
|
266 |
+
|
267 |
+
// Only applicable for Add Friend button
|
268 |
+
if ( $button['id'] == 'not_friends' ) {
|
269 |
|
270 |
$user_id = bp_loggedin_user_id();
|
271 |
$balance = $this->core->get_users_balance( $user_id, $this->mycred_type );
|
272 |
+
$cost = abs( $this->prefs['new_friend']['creds'] );
|
|
|
273 |
|
274 |
// Take into account any existing requests which will be charged when the new
|
275 |
// friend approves it. Prevents users from requesting more then they can afford.
|
277 |
if ( $pending_requests > 0 )
|
278 |
$cost = $cost + ( $cost * $pending_requests );
|
279 |
|
280 |
+
if ( $balance < $cost )
|
281 |
+
return array();
|
|
|
|
|
|
|
|
|
|
|
|
|
282 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
283 |
}
|
284 |
|
285 |
+
return $button;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
286 |
|
287 |
+
}
|
288 |
|
289 |
+
/**
|
290 |
+
* Count Pending Friendship Requests
|
291 |
+
* Counts the given users pending friendship requests sent to
|
292 |
+
* other users.
|
293 |
+
* @since 1.5.4
|
294 |
+
* @version 1.0
|
295 |
+
*/
|
296 |
+
protected function count_pending_requests( $user_id ) {
|
297 |
|
298 |
+
global $wpdb, $bp;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
299 |
|
300 |
+
return $wpdb->get_var( $wpdb->prepare( "
|
301 |
+
SELECT COUNT(*)
|
302 |
+
FROM {$bp->friends->table_name}
|
303 |
+
WHERE initiator_user_id = %d
|
304 |
+
AND is_confirmed = 0;", $user_id ) );
|
|
|
|
|
|
|
|
|
|
|
|
|
305 |
|
306 |
+
}
|
|
|
|
|
|
|
|
|
|
|
307 |
|
308 |
+
/**
|
309 |
+
* New Friendship
|
310 |
+
* @since 0.1
|
311 |
+
* @version 1.3
|
312 |
+
*/
|
313 |
+
public function friendship_join( $friendship_id, $initiator_user_id, $friend_user_id ) {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
314 |
|
315 |
+
// Make sure this is unique event
|
316 |
+
if ( ! $this->core->exclude_user( $initiator_user_id ) && ! $this->core->has_entry( 'new_friendship', $friend_user_id, $initiator_user_id ) && ! $this->over_hook_limit( 'new_friend', 'new_friendship', $initiator_user_id ) )
|
317 |
+
$this->core->add_creds(
|
318 |
+
'new_friendship',
|
319 |
+
$initiator_user_id,
|
320 |
+
$this->prefs['new_friend']['creds'],
|
321 |
+
$this->prefs['new_friend']['log'],
|
322 |
+
$friend_user_id,
|
323 |
+
array( 'ref_type' => 'user' ),
|
324 |
+
$this->mycred_type
|
325 |
+
);
|
326 |
|
327 |
+
// Points to friend (ignored if we are deducting points for new friendships)
|
328 |
+
if ( $this->prefs['new_friend']['creds'] > 0 && ! $this->core->exclude_user( $friend_user_id ) && ! $this->over_hook_limit( 'new_friend', 'new_friendship', $friend_user_id ) )
|
329 |
+
$this->core->add_creds(
|
330 |
+
'new_friendship',
|
331 |
+
$friend_user_id,
|
332 |
+
$this->prefs['new_friend']['creds'],
|
333 |
+
$this->prefs['new_friend']['log'],
|
334 |
+
$initiator_user_id,
|
335 |
+
array( 'ref_type' => 'user' )
|
336 |
+
);
|
337 |
|
338 |
+
}
|
|
|
339 |
|
340 |
+
/**
|
341 |
+
* Ending Friendship
|
342 |
+
* @since 0.1
|
343 |
+
* @version 1.2
|
344 |
+
*/
|
345 |
+
public function friendship_leave( $friendship_id, $initiator_user_id, $friend_user_id ) {
|
346 |
|
347 |
+
if ( ! $this->core->exclude_user( $initiator_user_id ) && ! $this->core->has_entry( 'ended_friendship', $friend_user_id, $initiator_user_id ) )
|
348 |
$this->core->add_creds(
|
349 |
+
'ended_friendship',
|
350 |
+
$initiator_user_id,
|
351 |
+
$this->prefs['leave_friend']['creds'],
|
352 |
+
$this->prefs['leave_friend']['log'],
|
353 |
+
$friend_user_id,
|
354 |
+
array( 'ref_type' => 'user' ),
|
355 |
$this->mycred_type
|
356 |
);
|
|
|
357 |
|
358 |
+
if ( ! $this->core->exclude_user( $friend_user_id ) )
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
359 |
$this->core->add_creds(
|
360 |
+
'ended_friendship',
|
361 |
+
$friend_user_id,
|
362 |
+
$this->prefs['leave_friend']['creds'],
|
363 |
+
$this->prefs['leave_friend']['log'],
|
364 |
+
$initiator_user_id,
|
365 |
+
array( 'ref_type' => 'user' ),
|
366 |
$this->mycred_type
|
367 |
);
|
|
|
368 |
|
369 |
+
}
|
370 |
+
|
371 |
+
/**
|
372 |
+
* New Comment
|
373 |
+
* @since 0.1
|
374 |
+
* @version 1.2
|
375 |
+
*/
|
376 |
+
public function new_comment( $comment_id, $params ) {
|
377 |
+
|
378 |
+
$user_id = bp_loggedin_user_id();
|
379 |
+
|
380 |
+
// Check if user is excluded
|
381 |
+
if ( $this->core->exclude_user( $user_id ) ) return;
|
382 |
+
|
383 |
+
// Limit
|
384 |
+
if ( $this->over_hook_limit( 'new_comment', 'new_comment' ) ) return;
|
385 |
+
|
386 |
+
// Make sure this is unique event
|
387 |
+
if ( $this->core->has_entry( 'new_comment', $comment_id ) ) return;
|
388 |
+
|
389 |
+
// Execute
|
390 |
+
$this->core->add_creds(
|
391 |
+
'new_comment',
|
392 |
+
$user_id,
|
393 |
+
$this->prefs['new_comment']['creds'],
|
394 |
+
$this->prefs['new_comment']['log'],
|
395 |
+
$comment_id,
|
396 |
+
'bp_comment',
|
397 |
+
$this->mycred_type
|
398 |
+
);
|
399 |
+
|
400 |
+
}
|
401 |
+
|
402 |
+
/**
|
403 |
+
* Comment Deletion
|
404 |
+
* @since 0.1
|
405 |
+
* @version 1.0
|
406 |
+
*/
|
407 |
+
public function delete_comment( $activity_id, $user_id ) {
|
408 |
+
|
409 |
+
// Check if user is excluded
|
410 |
+
if ( $this->core->exclude_user( $user_id ) ) return;
|
411 |
+
|
412 |
+
// Make sure this is unique event
|
413 |
+
if ( $this->core->has_entry( 'comment_deletion', $activity_id ) ) return;
|
414 |
+
|
415 |
+
// Execute
|
416 |
+
$this->core->add_creds(
|
417 |
+
'comment_deletion',
|
418 |
+
$user_id,
|
419 |
+
$this->prefs['delete_comment']['creds'],
|
420 |
+
$this->prefs['delete_comment']['log'],
|
421 |
+
$activity_id,
|
422 |
+
'bp_comment',
|
423 |
+
$this->mycred_type
|
424 |
+
);
|
425 |
+
|
426 |
+
}
|
427 |
+
|
428 |
+
/**
|
429 |
+
* New Message
|
430 |
+
* @since 0.1
|
431 |
+
* @version 1.1
|
432 |
+
*/
|
433 |
+
public function messages( $message ) {
|
434 |
+
|
435 |
+
// Check if user is excluded
|
436 |
+
if ( $this->core->exclude_user( $message->sender_id ) ) return;
|
437 |
+
|
438 |
+
// Limit
|
439 |
+
if ( $this->over_hook_limit( 'message', 'new_message', $message->sender_id ) ) return;
|
440 |
+
|
441 |
+
// Make sure this is unique event
|
442 |
+
if ( $this->core->has_entry( 'new_message', $message->thread_id ) ) return;
|
443 |
+
|
444 |
+
// Execute
|
445 |
+
$this->core->add_creds(
|
446 |
+
'new_message',
|
447 |
+
$message->sender_id,
|
448 |
+
$this->prefs['message']['creds'],
|
449 |
+
$this->prefs['message']['log'],
|
450 |
+
$message->thread_id,
|
451 |
+
'bp_message',
|
452 |
+
$this->mycred_type
|
453 |
+
);
|
454 |
+
|
455 |
+
}
|
456 |
|
457 |
+
/**
|
458 |
+
* Send Gift
|
459 |
+
* @since 0.1
|
460 |
+
* @version 1.1
|
461 |
+
*/
|
462 |
+
public function send_gifts( $to_user_id, $from_user_id ) {
|
463 |
|
464 |
+
// Check if sender is excluded
|
465 |
+
if ( $this->core->exclude_user( $from_user_id ) ) return;
|
466 |
|
467 |
+
// Check if recipient is excluded
|
468 |
+
if ( $this->core->exclude_user( $to_user_id ) ) return;
|
469 |
+
|
470 |
+
// Limit
|
471 |
+
if ( ! $this->over_hook_limit( 'send_gift', 'sending_gift', $from_user_id ) )
|
472 |
$this->core->add_creds(
|
473 |
+
'sending_gift',
|
474 |
+
$from_user_id,
|
475 |
+
$this->prefs['send_gift']['creds'],
|
476 |
+
$this->prefs['send_gift']['log'],
|
477 |
+
$to_user_id,
|
478 |
+
'bp_gifts',
|
479 |
$this->mycred_type
|
480 |
);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
481 |
|
482 |
+
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
483 |
|
484 |
+
/**
|
485 |
+
* Preferences
|
486 |
+
* @since 0.1
|
487 |
+
* @version 1.1
|
488 |
+
*/
|
489 |
+
public function preferences() {
|
490 |
|
491 |
+
$prefs = $this->prefs;
|
492 |
|
493 |
+
if ( ! isset( $prefs['removed_update'] ) )
|
494 |
+
$prefs['removed_update'] = array( 'creds' => 0, 'limit' => '0/x', 'log' => '%plural% deduction for removing profile update' );
|
495 |
|
496 |
+
$friend_block = 0;
|
497 |
+
if ( isset( $prefs['new_friend']['block'] ) )
|
498 |
+
$friend_block = $prefs['new_friend']['block'];
|
499 |
|
500 |
?>
|
501 |
<!-- Creds for Profile Update -->
|
647 |
</li>
|
648 |
</ol>
|
649 |
<?php
|
650 |
+
|
651 |
+
}
|
652 |
+
|
653 |
+
/**
|
654 |
+
* Sanitise Preferences
|
655 |
+
* @since 1.6
|
656 |
+
* @version 1.0
|
657 |
+
*/
|
658 |
+
function sanitise_preferences( $data ) {
|
659 |
+
|
660 |
+
if ( isset( $data['update']['limit'] ) && isset( $data['update']['limit_by'] ) ) {
|
661 |
+
$limit = sanitize_text_field( $data['update']['limit'] );
|
662 |
+
if ( $limit == '' ) $limit = 0;
|
663 |
+
$data['update']['limit'] = $limit . '/' . $data['update']['limit_by'];
|
664 |
+
unset( $data['update']['limit_by'] );
|
665 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
666 |
|
667 |
+
if ( isset( $data['removed_update']['limit'] ) && isset( $data['removed_update']['limit_by'] ) ) {
|
668 |
+
$limit = sanitize_text_field( $data['removed_update']['limit'] );
|
669 |
+
if ( $limit == '' ) $limit = 0;
|
670 |
+
$data['removed_update']['limit'] = $limit . '/' . $data['removed_update']['limit_by'];
|
671 |
+
unset( $data['removed_update']['limit_by'] );
|
672 |
}
|
|
|
|
|
673 |
|
674 |
+
if ( isset( $data['avatar']['limit'] ) && isset( $data['avatar']['limit_by'] ) ) {
|
675 |
+
$limit = sanitize_text_field( $data['avatar']['limit'] );
|
676 |
+
if ( $limit == '' ) $limit = 0;
|
677 |
+
$data['avatar']['limit'] = $limit . '/' . $data['avatar']['limit_by'];
|
678 |
+
unset( $data['avatar']['limit_by'] );
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
679 |
}
|
680 |
|
681 |
+
if ( isset( $data['new_friend']['limit'] ) && isset( $data['new_friend']['limit_by'] ) ) {
|
682 |
+
$limit = sanitize_text_field( $data['new_friend']['limit'] );
|
683 |
+
if ( $limit == '' ) $limit = 0;
|
684 |
+
$data['new_friend']['limit'] = $limit . '/' . $data['new_friend']['limit_by'];
|
685 |
+
unset( $data['new_friend']['limit_by'] );
|
686 |
+
}
|
|
|
|
|
687 |
|
688 |
+
$data['new_friend']['block'] = ( isset( $data['new_friend']['block'] ) ) ? absint( $data['new_friend']['block'] ) : 0;
|
|
|
689 |
|
690 |
+
if ( isset( $data['new_comment']['limit'] ) && isset( $data['new_comment']['limit_by'] ) ) {
|
691 |
+
$limit = sanitize_text_field( $data['new_comment']['limit'] );
|
692 |
+
if ( $limit == '' ) $limit = 0;
|
693 |
+
$data['new_comment']['limit'] = $limit . '/' . $data['new_comment']['limit_by'];
|
694 |
+
unset( $data['new_comment']['limit_by'] );
|
695 |
+
}
|
696 |
|
697 |
+
if ( isset( $data['message']['limit'] ) && isset( $data['message']['limit_by'] ) ) {
|
698 |
+
$limit = sanitize_text_field( $data['message']['limit'] );
|
699 |
+
if ( $limit == '' ) $limit = 0;
|
700 |
+
$data['message']['limit'] = $limit . '/' . $data['message']['limit_by'];
|
701 |
+
unset( $data['message']['limit_by'] );
|
702 |
+
}
|
703 |
|
704 |
+
if ( isset( $data['send_gift']['limit'] ) && isset( $data['send_gift']['limit_by'] ) ) {
|
705 |
+
$limit = sanitize_text_field( $data['send_gift']['limit'] );
|
706 |
+
if ( $limit == '' ) $limit = 0;
|
707 |
+
$data['send_gift']['limit'] = $limit . '/' . $data['send_gift']['limit_by'];
|
708 |
+
unset( $data['send_gift']['limit_by'] );
|
709 |
+
}
|
710 |
|
711 |
+
return $data;
|
|
|
712 |
|
713 |
+
}
|
|
|
714 |
|
715 |
+
}
|
716 |
+
endif;
|
|
|
|
|
|
|
717 |
|
718 |
+
/**
|
719 |
+
* myCRED_BuddyPress_Groups class
|
720 |
+
* Creds for groups actions such as joining / leaving, creating / deleting, new topics / edit topics or new posts / edit posts
|
721 |
+
* @since 0.1
|
722 |
+
* @version 1.1
|
723 |
+
*/
|
724 |
+
if ( ! class_exists( 'myCRED_BuddyPress_Groups' ) && class_exists( 'myCRED_Hook' ) ) :
|
725 |
+
class myCRED_BuddyPress_Groups extends myCRED_Hook {
|
726 |
+
|
727 |
+
/**
|
728 |
+
* Construct
|
729 |
+
*/
|
730 |
+
function __construct( $hook_prefs, $type = 'mycred_default' ) {
|
731 |
+
|
732 |
+
parent::__construct( array(
|
733 |
+
'id' => 'hook_bp_groups',
|
734 |
+
'defaults' => array(
|
735 |
+
'create' => array(
|
736 |
+
'creds' => 10,
|
737 |
+
'log' => '%plural% for creating a new group',
|
738 |
+
'min' => 0
|
739 |
+
),
|
740 |
+
'delete' => array(
|
741 |
+
'creds' => '-10',
|
742 |
+
'log' => '%singular% deduction for deleting a group'
|
743 |
+
),
|
744 |
+
'new_topic' => array(
|
745 |
+
'creds' => 1,
|
746 |
+
'log' => '%plural% for new group topic',
|
747 |
+
'limit' => '0/x'
|
748 |
+
),
|
749 |
+
'edit_topic' => array(
|
750 |
+
'creds' => 1,
|
751 |
+
'log' => '%plural% for updating group topic',
|
752 |
+
'limit' => '0/x'
|
753 |
+
),
|
754 |
+
'new_post' => array(
|
755 |
+
'creds' => 1,
|
756 |
+
'log' => '%plural% for new group post',
|
757 |
+
'limit' => '0/x'
|
758 |
+
),
|
759 |
+
'edit_post' => array(
|
760 |
+
'creds' => 1,
|
761 |
+
'log' => '%plural% for updating group post',
|
762 |
+
'limit' => '0/x'
|
763 |
+
),
|
764 |
+
'join' => array(
|
765 |
+
'creds' => 1,
|
766 |
+
'log' => '%plural% for joining new group',
|
767 |
+
'limit' => '0/x'
|
768 |
+
),
|
769 |
+
'leave' => array(
|
770 |
+
'creds' => '-5',
|
771 |
+
'log' => '%singular% deduction for leaving group'
|
772 |
+
),
|
773 |
+
'avatar' => array(
|
774 |
+
'creds' => 1,
|
775 |
+
'log' => '%plural% for new group avatar',
|
776 |
+
'limit' => '0/x'
|
777 |
+
),
|
778 |
+
'comments' => array(
|
779 |
+
'creds' => 1,
|
780 |
+
'log' => '%plural% for new group comment',
|
781 |
+
'limit' => '0/x'
|
782 |
+
)
|
783 |
+
)
|
784 |
+
), $hook_prefs, $type );
|
785 |
|
786 |
+
}
|
|
|
787 |
|
788 |
+
/**
|
789 |
+
* Run
|
790 |
+
* @since 0.1
|
791 |
+
* @version 1.0
|
792 |
+
*/
|
793 |
+
public function run() {
|
794 |
|
795 |
+
if ( $this->prefs['create']['creds'] != 0 && $this->prefs['create']['min'] == 0 )
|
796 |
+
add_action( 'groups_group_create_complete', array( $this, 'create_group' ) );
|
|
|
|
|
|
|
|
|
|
|
797 |
|
798 |
+
if ( $this->prefs['create']['creds'] < 0 )
|
799 |
+
add_filter( 'bp_user_can_create_groups', array( $this, 'restrict_group_creation' ), 99, 2 );
|
800 |
|
801 |
+
if ( $this->prefs['delete']['creds'] != 0 )
|
802 |
+
add_action( 'groups_group_deleted', array( $this, 'delete_group' ) );
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
803 |
|
804 |
+
if ( $this->prefs['new_topic']['creds'] != 0 )
|
805 |
+
add_action( 'bp_forums_new_topic', array( $this, 'new_topic' ) );
|
|
|
|
|
|
|
|
|
|
|
|
|
806 |
|
807 |
+
if ( $this->prefs['edit_topic']['creds'] != 0 )
|
808 |
+
add_action( 'groups_edit_forum_topic', array( $this, 'edit_topic' ) );
|
809 |
|
810 |
+
if ( $this->prefs['new_post']['creds'] != 0 )
|
811 |
+
add_action( 'bp_forums_new_post', array( $this, 'new_post' ) );
|
|
|
|
|
812 |
|
813 |
+
if ( $this->prefs['edit_post']['creds'] != 0 )
|
814 |
+
add_action( 'groups_edit_forum_post', array( $this, 'edit_post' ) );
|
815 |
|
816 |
+
if ( $this->prefs['join']['creds'] != 0 || ( $this->prefs['create']['creds'] != 0 && $this->prefs['create']['min'] != 0 ) )
|
817 |
+
add_action( 'groups_join_group', array( $this, 'join_group' ), 20, 2 );
|
|
|
|
|
|
|
|
|
|
|
|
|
818 |
|
819 |
+
if ( $this->prefs['join']['creds'] < 0 )
|
820 |
+
add_filter( 'bp_get_group_join_button', array( $this, 'restrict_joining_group' ) );
|
821 |
|
822 |
+
if ( $this->prefs['leave']['creds'] != 0 )
|
823 |
+
add_action( 'groups_leave_group', array( $this, 'leave_group' ), 20, 2 );
|
|
|
|
|
824 |
|
825 |
+
if ( $this->prefs['avatar']['creds'] != 0 )
|
826 |
+
add_action( 'groups_screen_group_admin_avatar', array( $this, 'avatar_upload_group' ) );
|
827 |
|
828 |
+
if ( $this->prefs['comments']['creds'] != 0 )
|
829 |
+
add_action( 'bp_groups_posted_update', array( $this, 'new_group_comment' ), 20, 4 );
|
|
|
|
|
|
|
|
|
|
|
830 |
|
831 |
+
}
|
|
|
|
|
832 |
|
833 |
+
/**
|
834 |
+
* Creating Group
|
835 |
+
* @since 0.1
|
836 |
+
* @version 1.0
|
837 |
+
*/
|
838 |
+
public function create_group( $group_id ) {
|
839 |
+
|
840 |
+
global $bp;
|
841 |
+
|
842 |
+
// Check if user should be excluded
|
843 |
+
if ( $this->core->exclude_user( $bp->loggedin_user->id ) ) return;
|
844 |
+
|
845 |
+
// Execute
|
846 |
+
$this->core->add_creds(
|
847 |
+
'creation_of_new_group',
|
848 |
+
$bp->loggedin_user->id,
|
849 |
+
$this->prefs['create']['creds'],
|
850 |
+
$this->prefs['create']['log'],
|
851 |
+
$group_id,
|
852 |
+
'bp_group',
|
853 |
+
$this->mycred_type
|
854 |
+
);
|
855 |
|
856 |
+
}
|
|
|
|
|
857 |
|
858 |
+
/**
|
859 |
+
* Restrict Group Creation
|
860 |
+
* If creating a group costs and the user does not have enough points, we restrict creations.
|
861 |
+
* @since 0.1
|
862 |
+
* @version 1.0
|
863 |
+
*/
|
864 |
+
public function restrict_group_creation( $can_create, $restricted ) {
|
865 |
|
866 |
+
global $bp;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
867 |
|
868 |
+
// Check if user should be excluded
|
869 |
+
if ( $this->core->exclude_user( $bp->loggedin_user->id ) ) return $can_create;
|
|
|
|
|
|
|
|
|
|
|
870 |
|
871 |
+
// Check if user has enough to create a group
|
872 |
+
$cost = abs( $this->prefs['create']['creds'] );
|
873 |
+
$balance = $this->core->get_users_cred( $bp->loggedin_user->id, $this->mycred_type );
|
874 |
+
if ( $cost > $balance ) return false;
|
875 |
|
876 |
+
return $can_create;
|
|
|
877 |
|
878 |
+
}
|
|
|
879 |
|
880 |
+
/**
|
881 |
+
* Restrict Group Join
|
882 |
+
* If joining a group costs and the user does not have enough points, we restrict joining of groups.
|
883 |
+
* @since 0.1
|
884 |
+
* @version 1.0
|
885 |
+
*/
|
886 |
+
public function restrict_joining_group( $button ) {
|
|
|
|
|
|
|
|
|
887 |
|
888 |
+
global $bp;
|
|
|
|
|
|
|
|
|
|
|
|
|
889 |
|
890 |
+
// Check if user should be excluded
|
891 |
+
if ( $this->core->exclude_user( $bp->loggedin_user->id ) ) return $button;
|
892 |
|
893 |
+
// Check if user has enough to join group
|
894 |
+
$cost = abs( $this->prefs['join']['creds'] );
|
895 |
+
$balance = $this->core->get_users_cred( $bp->loggedin_user->id, $this->mycred_type );
|
896 |
+
if ( $cost > $balance ) return false;
|
897 |
|
898 |
+
return $button;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
899 |
|
900 |
+
}
|
|
|
|
|
|
|
|
|
|
|
|
|
901 |
|
902 |
+
/**
|
903 |
+
* Deleting Group
|
904 |
+
* @since 0.1
|
905 |
+
* @version 1.0
|
906 |
+
*/
|
907 |
+
public function delete_group( $group_id ) {
|
908 |
+
|
909 |
+
global $bp;
|
910 |
+
|
911 |
+
// If admin is removing deduct from creator
|
912 |
+
if ( $bp->loggedin_user->is_super_admin )
|
913 |
+
$user_id = $bp->groups->current_group->creator_id;
|
914 |
+
|
915 |
+
// Else if admin but not the creator is removing
|
916 |
+
elseif ( $bp->loggedin_user->id != $bp->groups->current_group->creator_id )
|
917 |
+
$user_id = $bp->groups->current_group->creator_id;
|
918 |
+
|
919 |
+
// Else deduct from current user
|
920 |
+
else
|
921 |
+
$user_id = $bp->loggedin_user->id;
|
922 |
+
|
923 |
+
// Check if user should be excluded
|
924 |
+
if ( $this->core->exclude_user( $user_id ) ) return;
|
925 |
+
|
926 |
+
// Execute
|
927 |
+
$this->core->add_creds(
|
928 |
+
'deletion_of_group',
|
929 |
+
$user_id,
|
930 |
+
$this->prefs['delete']['creds'],
|
931 |
+
$this->prefs['delete']['log'],
|
932 |
+
$group_id,
|
933 |
+
'bp_group',
|
934 |
+
$this->mycred_type
|
935 |
+
);
|
936 |
|
937 |
+
}
|
|
|
938 |
|
939 |
+
/**
|
940 |
+
* New Group Forum Topic
|
941 |
+
* @since 0.1
|
942 |
+
* @version 1.1
|
943 |
+
*/
|
944 |
+
public function new_topic( $topic_id ) {
|
945 |
+
|
946 |
+
global $bp;
|
947 |
+
|
948 |
+
// Check if user should be excluded
|
949 |
+
if ( $this->core->exclude_user( $bp->loggedin_user->id ) ) return;
|
950 |
+
|
951 |
+
// Limit
|
952 |
+
if ( $this->over_hook_limit( 'new_topic', 'new_group_forum_topic' ) ) return;
|
953 |
+
|
954 |
+
// Make sure this is unique event
|
955 |
+
if ( $this->core->has_entry( 'new_group_forum_topic', $topic_id, $bp->loggedin_user->id ) ) return;
|
956 |
+
|
957 |
+
// Execute
|
958 |
+
$this->core->add_creds(
|
959 |
+
'new_group_forum_topic',
|
960 |
+
$bp->loggedin_user->id,
|
961 |
+
$this->prefs['new_topic']['creds'],
|
962 |
+
$this->prefs['new_topic']['log'],
|
963 |
+
$topic_id,
|
964 |
+
'bp_ftopic',
|
965 |
+
$this->mycred_type
|
966 |
+
);
|
967 |
|
968 |
+
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
969 |
|
970 |
+
/**
|
971 |
+
* Edit Group Forum Topic
|
972 |
+
* @since 0.1
|
973 |
+
* @version 1.0
|
974 |
+
*/
|
975 |
+
public function edit_topic( $topic_id ) {
|
976 |
+
|
977 |
+
global $bp;
|
978 |
+
|
979 |
+
// Check if user should be excluded
|
980 |
+
if ( $this->core->exclude_user( $bp->loggedin_user->id ) ) return;
|
981 |
+
|
982 |
+
// Limit
|
983 |
+
if ( $this->over_hook_limit( 'edit_topic', 'edit_group_forum_topic' ) ) return;
|
984 |
+
|
985 |
+
// Execute
|
986 |
+
$this->core->add_creds(
|
987 |
+
'edit_group_forum_topic',
|
988 |
+
$bp->loggedin_user->id,
|
989 |
+
$this->prefs['edit_topic']['creds'],
|
990 |
+
$this->prefs['edit_topic']['log'],
|
991 |
+
$topic_id,
|
992 |
+
'bp_ftopic',
|
993 |
+
$this->mycred_type
|
994 |
+
);
|
995 |
|
996 |
+
}
|
|
|
997 |
|
998 |
+
/**
|
999 |
+
* New Group Forum Post
|
1000 |
+
* @since 0.1
|
1001 |
+
* @version 1.1
|
1002 |
+
*/
|
1003 |
+
public function new_post( $post_id ) {
|
1004 |
+
|
1005 |
+
global $bp;
|
1006 |
+
|
1007 |
+
// Check if user should be excluded
|
1008 |
+
if ( $this->core->exclude_user( $bp->loggedin_user->id ) ) return;
|
1009 |
+
|
1010 |
+
// Limit
|
1011 |
+
if ( $this->over_hook_limit( 'new_post', 'new_group_forum_post' ) ) return;
|
1012 |
+
|
1013 |
+
// Make sure this is unique event
|
1014 |
+
if ( $this->core->has_entry( 'new_group_forum_post', $post_id, $bp->loggedin_user->id ) ) return;
|
1015 |
+
|
1016 |
+
// Execute
|
1017 |
+
$this->core->add_creds(
|
1018 |
+
'new_group_forum_post',
|
1019 |
+
$bp->loggedin_user->id,
|
1020 |
+
$this->prefs['new_post']['creds'],
|
1021 |
+
$this->prefs['new_post']['log'],
|
1022 |
+
$post_id,
|
1023 |
+
'bp_fpost',
|
1024 |
+
$this->mycred_type
|
1025 |
+
);
|
1026 |
|
1027 |
+
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1028 |
|
1029 |
+
/**
|
1030 |
+
* Edit Group Forum Post
|
1031 |
+
* @since 0.1
|
1032 |
+
* @version 1.0
|
1033 |
+
*/
|
1034 |
+
public function edit_post( $post_id ) {
|
1035 |
+
|
1036 |
+
global $bp;
|
1037 |
+
|
1038 |
+
// Check if user should be excluded
|
1039 |
+
if ( $this->core->exclude_user( $bp->loggedin_user->id ) ) return;
|
1040 |
+
|
1041 |
+
// Limit
|
1042 |
+
if ( $this->over_hook_limit( 'edit_post', 'edit_group_forum_post' ) ) return;
|
1043 |
+
|
1044 |
+
// Execute
|
1045 |
+
$this->core->add_creds(
|
1046 |
+
'edit_group_forum_post',
|
1047 |
+
$bp->loggedin_user->id,
|
1048 |
+
$this->prefs['edit_post']['creds'],
|
1049 |
+
$this->prefs['edit_post']['log'],
|
1050 |
+
$post_id,
|
1051 |
+
'bp_fpost',
|
1052 |
+
$this->mycred_type
|
1053 |
+
);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1054 |
|
1055 |
+
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1056 |
|
1057 |
+
/**
|
1058 |
+
* Joining Group
|
1059 |
+
* @since 0.1
|
1060 |
+
* @version 1.1
|
1061 |
+
*/
|
1062 |
+
public function join_group( $group_id, $user_id ) {
|
1063 |
+
|
1064 |
+
// Minimum members limit
|
1065 |
+
if ( $this->prefs['create']['min'] != 0 ) {
|
1066 |
+
$group = groups_get_group( array( 'group_id' => $group_id ) );
|
1067 |
+
|
1068 |
+
// Award creator if we have reached the minimum number of members and we have not yet been awarded
|
1069 |
+
if ( $group->total_member_count >= (int) $this->prefs['create']['min'] && ! $this->core->has_entry( 'creation_of_new_group', $group_id, $group->creator_id ) )
|
1070 |
+
$this->core->add_creds(
|
1071 |
+
'creation_of_new_group',
|
1072 |
+
$group->creator_id,
|
1073 |
+
$this->prefs['create']['creds'],
|
1074 |
+
$this->prefs['create']['log'],
|
1075 |
+
$group_id,
|
1076 |
+
'bp_group',
|
1077 |
+
$this->mycred_type
|
1078 |
+
);
|
1079 |
+
|
1080 |
+
// Clean up
|
1081 |
+
unset( $group );
|
1082 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1083 |
}
|
1084 |
|
1085 |
+
// Check if user should be excluded
|
1086 |
+
if ( $this->core->exclude_user( $user_id ) ) return;
|
|
|
|
|
|
|
|
|
|
|
1087 |
|
1088 |
+
// Limit
|
1089 |
+
if ( $this->over_hook_limit( 'join', 'joining_group' ) ) return;
|
1090 |
|
1091 |
+
// Make sure this is unique event
|
1092 |
+
if ( $this->core->has_entry( 'joining_group', $group_id, $user_id ) ) return;
|
1093 |
|
1094 |
+
// Execute
|
1095 |
+
$this->core->add_creds(
|
1096 |
+
'joining_group',
|
1097 |
+
$user_id,
|
1098 |
+
$this->prefs['join']['creds'],
|
1099 |
+
$this->prefs['join']['log'],
|
1100 |
+
$group_id,
|
1101 |
+
'bp_group',
|
1102 |
+
$this->mycred_type
|
1103 |
+
);
|
1104 |
|
1105 |
+
}
|
1106 |
+
|
1107 |
+
/**
|
1108 |
+
* Leaving Group
|
1109 |
+
* @since 0.1
|
1110 |
+
* @version 1.0
|
1111 |
+
*/
|
1112 |
+
public function leave_group( $group_id, $user_id ) {
|
1113 |
+
|
1114 |
+
// Check if user should be excluded
|
1115 |
+
if ( $this->core->exclude_user( $user_id ) ) return;
|
1116 |
+
|
1117 |
+
// Make sure this is unique event
|
1118 |
+
if ( $this->core->has_entry( 'leaving_group', $group_id, $user_id ) ) return;
|
1119 |
+
|
1120 |
+
// Execute
|
1121 |
+
$this->core->add_creds(
|
1122 |
+
'leaving_group',
|
1123 |
+
$user_id,
|
1124 |
+
$this->prefs['leave']['creds'],
|
1125 |
+
$this->prefs['leave']['log'],
|
1126 |
+
$group_id,
|
1127 |
'bp_group',
|
1128 |
+
$this->mycred_type
|
1129 |
+
);
|
|
|
1130 |
|
1131 |
+
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1132 |
|
1133 |
+
/**
|
1134 |
+
* Avatar Upload for Group
|
1135 |
+
* @since 0.1
|
1136 |
+
* @version 1.1
|
1137 |
+
*/
|
1138 |
+
public function avatar_upload_group( $group_id ) {
|
1139 |
+
|
1140 |
+
global $bp;
|
1141 |
+
|
1142 |
+
// Check if user should be excluded
|
1143 |
+
if ( $this->core->exclude_user( $bp->loggedin_user->id ) ) return;
|
1144 |
+
|
1145 |
+
// Limit
|
1146 |
+
if ( $this->over_hook_limit( 'avatar', 'upload_group_avatar' ) ) return;
|
1147 |
+
|
1148 |
+
// Make sure this is unique event
|
1149 |
+
if ( $this->core->has_entry( 'upload_group_avatar', $group_id ) ) return;
|
1150 |
+
|
1151 |
+
// Execute
|
1152 |
+
$this->core->add_creds(
|
1153 |
+
'upload_group_avatar',
|
1154 |
+
$bp->loggedin_user->id,
|
1155 |
+
$this->prefs['avatar']['creds'],
|
1156 |
+
$this->prefs['avatar']['log'],
|
1157 |
+
$group_id,
|
1158 |
+
'bp_group',
|
1159 |
+
$this->mycred_type
|
1160 |
+
);
|
1161 |
|
1162 |
+
}
|
|
|
1163 |
|
1164 |
+
/**
|
1165 |
+
* New Group Comment
|
1166 |
+
* @since 0.1
|
1167 |
+
* @version 1.1
|
1168 |
+
*/
|
1169 |
+
public function new_group_comment( $content, $user_id, $group_id, $activity_id ) {
|
1170 |
+
|
1171 |
+
// Check if user should be excluded
|
1172 |
+
if ( $this->core->exclude_user( $user_id ) ) return;
|
1173 |
+
|
1174 |
+
// Limit
|
1175 |
+
if ( $this->over_hook_limit( 'comments', 'new_group_comment', $user_id ) ) return;
|
1176 |
+
|
1177 |
+
// Make sure this is unique event
|
1178 |
+
if ( $this->core->has_entry( 'new_group_comment', $activity_id, $user_id ) ) return;
|
1179 |
+
|
1180 |
+
// Execute
|
1181 |
+
$this->core->add_creds(
|
1182 |
+
'new_group_comment',
|
1183 |
+
$user_id,
|
1184 |
+
$this->prefs['comments']['creds'],
|
1185 |
+
$this->prefs['comments']['log'],
|
1186 |
+
$activity_id,
|
1187 |
+
'bp_activity',
|
1188 |
+
$this->mycred_type
|
1189 |
+
);
|
1190 |
+
|
1191 |
+
}
|
1192 |
+
|
1193 |
+
/**
|
1194 |
+
* Preferences
|
1195 |
+
* @since 0.1
|
1196 |
+
* @version 1.2
|
1197 |
+
*/
|
1198 |
+
public function preferences() {
|
1199 |
|
1200 |
+
$prefs = $this->prefs;
|
|
|
|
|
|
|
|
|
|
|
|
|
1201 |
|
1202 |
+
?>
|
1203 |
<!-- Creds for New Group -->
|
1204 |
<label for="<?php echo $this->field_id( array( 'create', 'creds' ) ); ?>" class="subheader"><?php echo $this->core->template_tags_general( __( '%plural% for Creating Groups', 'mycred' ) ); ?></label>
|
1205 |
<ol>
|
1367 |
</li>
|
1368 |
</ol>
|
1369 |
<?php
|
1370 |
+
|
1371 |
+
}
|
1372 |
+
|
1373 |
+
/**
|
1374 |
+
* Sanitise Preferences
|
1375 |
+
* @since 1.6
|
1376 |
+
* @version 1.0
|
1377 |
+
*/
|
1378 |
+
function sanitise_preferences( $data ) {
|
1379 |
+
|
1380 |
+
if ( isset( $data['new_topic']['limit'] ) && isset( $data['new_topic']['limit_by'] ) ) {
|
1381 |
+
$limit = sanitize_text_field( $data['new_topic']['limit'] );
|
1382 |
+
if ( $limit == '' ) $limit = 0;
|
1383 |
+
$data['new_topic']['limit'] = $limit . '/' . $data['new_topic']['limit_by'];
|
1384 |
+
unset( $data['new_topic']['limit_by'] );
|
1385 |
+
}
|
1386 |
+
|
1387 |
+
if ( isset( $data['edit_topic']['limit'] ) && isset( $data['edit_topic']['limit_by'] ) ) {
|
1388 |
+
$limit = sanitize_text_field( $data['edit_topic']['limit'] );
|
1389 |
+
if ( $limit == '' ) $limit = 0;
|
1390 |
+
$data['edit_topic']['limit'] = $limit . '/' . $data['edit_topic']['limit_by'];
|
1391 |
+
unset( $data['edit_topic']['limit_by'] );
|
1392 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1393 |
|
1394 |
+
if ( isset( $data['new_post']['limit'] ) && isset( $data['new_post']['limit_by'] ) ) {
|
1395 |
+
$limit = sanitize_text_field( $data['new_post']['limit'] );
|
1396 |
+
if ( $limit == '' ) $limit = 0;
|
1397 |
+
$data['new_post']['limit'] = $limit . '/' . $data['new_post']['limit_by'];
|
1398 |
+
unset( $data['new_post']['limit_by'] );
|
1399 |
}
|
1400 |
+
|
1401 |
+
if ( isset( $data['edit_post']['limit'] ) && isset( $data['edit_post']['limit_by'] ) ) {
|
1402 |
+
$limit = sanitize_text_field( $data['edit_post']['limit'] );
|
1403 |
+
if ( $limit == '' ) $limit = 0;
|
1404 |
+
$data['edit_post']['limit'] = $limit . '/' . $data['edit_post']['limit_by'];
|
1405 |
+
unset( $data['edit_post']['limit_by'] );
|
1406 |
+
}
|
1407 |
+
|
1408 |
+
if ( isset( $data['join']['limit'] ) && isset( $data['join']['limit_by'] ) ) {
|
1409 |
+
$limit = sanitize_text_field( $data['join']['limit'] );
|
1410 |
+
if ( $limit == '' ) $limit = 0;
|
1411 |
+
$data['join']['limit'] = $limit . '/' . $data['join']['limit_by'];
|
1412 |
+
unset( $data['join']['limit_by'] );
|
1413 |
+
}
|
1414 |
+
|
1415 |
+
if ( isset( $data['avatar']['limit'] ) && isset( $data['avatar']['limit_by'] ) ) {
|
1416 |
+
$limit = sanitize_text_field( $data['avatar']['limit'] );
|
1417 |
+
if ( $limit == '' ) $limit = 0;
|
1418 |
+
$data['avatar']['limit'] = $limit . '/' . $data['avatar']['limit_by'];
|
1419 |
+
unset( $data['avatar']['limit_by'] );
|
1420 |
+
}
|
1421 |
+
|
1422 |
+
if ( isset( $data['comments']['limit'] ) && isset( $data['comments']['limit_by'] ) ) {
|
1423 |
+
$limit = sanitize_text_field( $data['comments']['limit'] );
|
1424 |
+
if ( $limit == '' ) $limit = 0;
|
1425 |
+
$data['comments']['limit'] = $limit . '/' . $data['comments']['limit_by'];
|
1426 |
+
unset( $data['comments']['limit_by'] );
|
1427 |
+
}
|
1428 |
+
|
1429 |
+
return $data;
|
1430 |
+
|
1431 |
}
|
1432 |
+
|
1433 |
}
|
1434 |
+
endif;
|
1435 |
|
|
|
1436 |
?>
|
plugins/mycred-hook-wp-postratings.php
CHANGED
@@ -141,7 +141,7 @@ if ( defined( 'myCRED_VERSION' ) ) {
|
|
141 |
/**
|
142 |
* Preferences for WP Postratings Hook
|
143 |
* @since 1.6
|
144 |
-
* @version 1.0
|
145 |
*/
|
146 |
public function preferences() {
|
147 |
$prefs = $this->prefs;
|
@@ -157,7 +157,7 @@ if ( defined( 'myCRED_VERSION' ) ) {
|
|
157 |
<?php echo $this->hook_limit_setting( $this->field_name( array( 'rating', 'limit' ) ), $this->field_id( array( 'rating', 'limit' ) ), $prefs['rating']['limit'] ); ?>
|
158 |
</li>
|
159 |
<li>
|
160 |
-
<label for="<?php echo $this->field_id( array( 'rating', 'value' ) ); ?>"><input type="checkbox" name="<?php echo $this->field_name( array( '
|
161 |
</li>
|
162 |
<li class="empty"> </li>
|
163 |
<li>
|
141 |
/**
|
142 |
* Preferences for WP Postratings Hook
|
143 |
* @since 1.6
|
144 |
+
* @version 1.0.1
|
145 |
*/
|
146 |
public function preferences() {
|
147 |
$prefs = $this->prefs;
|
157 |
<?php echo $this->hook_limit_setting( $this->field_name( array( 'rating', 'limit' ) ), $this->field_id( array( 'rating', 'limit' ) ), $prefs['rating']['limit'] ); ?>
|
158 |
</li>
|
159 |
<li>
|
160 |
+
<label for="<?php echo $this->field_id( array( 'rating', 'value' ) ); ?>"><input type="checkbox" name="<?php echo $this->field_name( array( 'rating', 'value' ) ); ?>" id="<?php echo $this->field_id( array( 'rating', 'value' ) ); ?>" <?php checked( $prefs['rating']['value'], 1 ); ?> value="1" /> <?php _e( 'Use the Rating Value instead of the amount set here.', 'mycred' ); ?></label>
|
161 |
</li>
|
162 |
<li class="empty"> </li>
|
163 |
<li>
|
readme.txt
CHANGED
@@ -3,7 +3,7 @@ Contributors: designbymerovingi
|
|
3 |
Tags:points, tokens, credit, management, reward, charge, community, contest, buddypress, jetpack, bbpress, simple press, woocommerce, marketpress, wp e-commerce, gravity forms, share-this
|
4 |
Requires at least: 3.8
|
5 |
Tested up to: 4.3.1
|
6 |
-
Stable tag: 1.6.
|
7 |
License: GPLv2 or later
|
8 |
License URI: http://www.gnu.org/licenses/gpl-2.0.html
|
9 |
|
@@ -11,40 +11,55 @@ myCRED is an adaptive points management system that lets you award / charge your
|
|
11 |
|
12 |
== Description ==
|
13 |
|
14 |
-
> #### Read before updating to 1.6
|
15 |
-
> Version 1.6 brings some major core changes for your point type settings and hooks. Please read [this guide](http://codex.mycred.me/updating-to-mycred-1-6/) before updating!
|
16 |
-
|
17 |
> #### Plugin Support
|
18 |
-
> Free support is offered
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
19 |
|
20 |
-
|
21 |
|
22 |
-
So I built an adaptive plugin which gives it’s users full control on how points are awarded, used, traded, managed, logged and presented. Built on the "opt-in" principle, it is up to you what features you want to use and how. If your WordPress installation does not support a feature it is hidden from you to keep things clean and simple.
|
23 |
|
24 |
-
**my**CRED comes packed with features along with built-in support for some of the most popular [WordPress plugins](http://mycred.me/about/supported-plugins/) out there. But of course **my**CRED does not support everything out of the box so I have documented as much as possible in the **my**CRED [codex](http://codex.mycred.me) and you can find several [tutorials](http://mycred.me/support/tutorials/) that can help you better acquaint yourself with **my**CRED.
|
25 |
|
26 |
-
|
27 |
|
28 |
-
|
29 |
|
30 |
-
**About Hooks**
|
31 |
|
32 |
-
**my**CRED hooks are instances where you award or deduct points from a user. By default you can award point for: registrations, logins, content publishing, commenting, clicking on links and viewing YouTube videos. You can find more information on built-in hooks [here](http://mycred.me/about/hooks/).
|
33 |
|
|
|
34 |
|
35 |
-
|
36 |
|
37 |
-
**my**CRED add-ons allows you to enable more complex features that is not just about awarding / deducting points. Features include: [Sell Content](http://mycred.me/add-ons/sell-content/) with points, [Buy points](http://mycred.me/add-ons/buycred/) for real money, [Transfer](http://mycred.me/add-ons/transfer/) points between users, award [ranks](http://mycred.me/add-ons/ranks/) according to points balances. You can find a complete list of [built-in](http://mycred.me/add-on-types/built-in/) and [premium](http://mycred.me/add-on-types/premium/) add-ons [here](http://mycred.me/add-ons/).
|
38 |
|
39 |
|
40 |
-
**
|
41 |
|
42 |
-
|
43 |
|
|
|
44 |
|
45 |
-
**Contact**
|
46 |
|
47 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
48 |
|
49 |
|
50 |
== Installation ==
|
@@ -106,8 +121,8 @@ myCRED supports importing, exporting, inline editing and manual deletion of log
|
|
106 |
|
107 |
== Upgrade Notice ==
|
108 |
|
109 |
-
= 1.6.
|
110 |
-
|
111 |
|
112 |
|
113 |
== Other Notes ==
|
@@ -131,10 +146,17 @@ WP 4.3 compatibility update, clean up of code and Japanese language support.
|
|
131 |
|
132 |
== Changelog ==
|
133 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
134 |
= 1.6.4 =
|
135 |
-
|
136 |
-
UPDATE - Adjusted widget constructors for 4.3 compatibility.
|
137 |
-
NEW - Added Japanese translation.
|
138 |
|
139 |
= 1.6.3 =
|
140 |
http://mycred.me/support/changelog/
|
3 |
Tags:points, tokens, credit, management, reward, charge, community, contest, buddypress, jetpack, bbpress, simple press, woocommerce, marketpress, wp e-commerce, gravity forms, share-this
|
4 |
Requires at least: 3.8
|
5 |
Tested up to: 4.3.1
|
6 |
+
Stable tag: 1.6.5
|
7 |
License: GPLv2 or later
|
8 |
License URI: http://www.gnu.org/licenses/gpl-2.0.html
|
9 |
|
11 |
|
12 |
== Description ==
|
13 |
|
|
|
|
|
|
|
14 |
> #### Plugin Support
|
15 |
+
> Free support is offered via the [myCRED support forum](http://mycred.me/support/forums/). No support is provided here on the wordpress.org support forum.
|
16 |
+
|
17 |
+
myCRED is a adaptive points management tool to help you build reward programs, monetize your website or just reward users with points for posting comments or publishing content.
|
18 |
+
|
19 |
+
Packed with features, myCRED also supports some of the most popular WordPress plugins like WooCommerce, BuddyPress, Jetpack, Contact Form 7 and [more](http://mycred.me/about/supported-plugins/).
|
20 |
+
|
21 |
+
|
22 |
+
**Points**
|
23 |
+
|
24 |
+
Each user on your WordPress websites gets their own point balance which you can manually [adjust](http://mycred.me/about/features/easy-manual-adjustments/) at any time. As of version 1.4, myCRED also supports multiple point types for those who need more then one type of points on their website.
|
25 |
+
|
26 |
+
|
27 |
+
|
28 |
+
**Log**
|
29 |
|
30 |
+
Each time myCRED adds or deducts points from a user, the adjustment is [logged](http://mycred.me/about/features/the-log/) in a dedicated log, allowing your users to browse their history. The log is also used to provide you with statistics or enforce limits you set.
|
31 |
|
|
|
32 |
|
|
|
33 |
|
34 |
+
**Awarding or Deducting Points Automatically**
|
35 |
|
36 |
+
myCRED supports a vast set of ways you can automatically give / take points from a user. Everything from new comments to store purchases. These automatic adjustments are managed by “Hooks” which you can setup in your admin area.
|
37 |
|
|
|
38 |
|
|
|
39 |
|
40 |
+
**Third-party plugin Support**
|
41 |
|
42 |
+
myCRED supports some of the most [popular plugins](http://mycred.me/about/supported-plugins/) for WordPress like BuddyPress, WooCommerce, Jetpack, Contact Form 7 etc. To prevent to much cluttering in the admin area with settings, myCRED will automatically hide settings for plugins that you are not using.
|
43 |
|
|
|
44 |
|
45 |
|
46 |
+
**Add-ons**
|
47 |
|
48 |
+
There is so much more to myCRED then just adjusting balances. The plugin comes with several [built-in add-ons](http://mycred.me/add-ons/) which enabled more complex features such as allowing point transfers, buying points for real money, allow payments in stores etc.
|
49 |
|
50 |
+
To help fund development of myCRED, I also provide an ever growing set of [premium add-ons](http://mycred.me/store/) that brings you even more features or add support for more payment gateways.
|
51 |
|
|
|
52 |
|
53 |
+
|
54 |
+
**Documentation**
|
55 |
+
|
56 |
+
The myCRED [Codex](http://codex.mycred.me/) provides a large amount of documentation for users and developers. You can also find installation guides on each add-ons page on the myCRED.me website.
|
57 |
+
|
58 |
+
|
59 |
+
|
60 |
+
**Support**
|
61 |
+
|
62 |
+
I provide free technical support via the [myCRED website](http://mycred.me/support/forums/). Support is **NOT** provided here on the wordpress.org support forum. This also means I do not provide support for forks or clones of this plugin.
|
63 |
|
64 |
|
65 |
== Installation ==
|
121 |
|
122 |
== Upgrade Notice ==
|
123 |
|
124 |
+
= 1.6.5 =
|
125 |
+
Bug fixes and BuddyPress 2.3+ comp.
|
126 |
|
127 |
|
128 |
== Other Notes ==
|
146 |
|
147 |
== Changelog ==
|
148 |
|
149 |
+
= 1.6.5 =
|
150 |
+
FIX - mycred_video shortcode is not applying the correct point type default setup when having more then one point type.
|
151 |
+
FIX - BuddyPress 2.3+ compatibility.
|
152 |
+
FIX - Adjusted the mycred_users_of_rank shortcode to prevent the wrap attribute from being empty.
|
153 |
+
FIX - WP Postratings plugin settings were not properly saved due to misspelled instance id.
|
154 |
+
TWEAK - The View Content hook now only awards points once per unique content no matter what limit is set.
|
155 |
+
TWEAK - Re-wrote the daily hook limit query.
|
156 |
+
TWEAK - Cleaned up abstract class files and added some inline documentation.
|
157 |
+
|
158 |
= 1.6.4 =
|
159 |
+
http://mycred.me/support/changelog/
|
|
|
|
|
160 |
|
161 |
= 1.6.3 =
|
162 |
http://mycred.me/support/changelog/
|