myCRED - Version 1.2

Version Description

See http://mycred.me/download/changelog/

Download this release

Release Info

Developer designbymerovingi
Plugin Icon 128x128 myCRED
Version 1.2
Comparing to
See all releases

Code changes from version 1.1.2 to 1.2

Files changed (43) hide show
  1. abstracts/mycred-abstract-hook.php +16 -41
  2. abstracts/mycred-abstract-module.php +1 -1
  3. addons/banking/abstracts/index.php +3 -0
  4. addons/banking/abstracts/mycred-abstract-service.php +291 -0
  5. addons/banking/index.php +3 -0
  6. addons/banking/myCRED-addon-banking.php +234 -0
  7. addons/banking/services/index.php +3 -0
  8. addons/banking/services/mycred-bank-service-interest.php +265 -0
  9. addons/banking/services/mycred-bank-service-payouts.php +248 -0
  10. addons/buddypress/hooks/bp-galleries.php +1 -1
  11. addons/buddypress/hooks/bp-groups.php +7 -7
  12. addons/buddypress/hooks/bp-links.php +4 -4
  13. addons/buddypress/hooks/bp-profile.php +32 -12
  14. addons/buddypress/myCRED-addon-buddypress.php +50 -20
  15. addons/email-notices/myCRED-addon-email-notices.php +9 -3
  16. addons/gateway/carts/mycred-marketpress.php +163 -87
  17. addons/gateway/event-booking/mycred-eventespresso3.php +513 -0
  18. addons/gateway/event-booking/mycred-eventsmanager.php +639 -0
  19. addons/gateway/myCRED-addon-gateway.php +11 -2
  20. addons/ranks/includes/mycred-rank-functions.php +6 -5
  21. addons/ranks/myCRED-addon-ranks.php +207 -68
  22. addons/transfer/myCRED-addon-transfer.php +7 -4
  23. assets/css/inline-edit.css +25 -0
  24. assets/images/cred-icon16.png +0 -0
  25. assets/images/cred-icon32.png +0 -0
  26. assets/images/logo-menu.png +0 -0
  27. assets/js/inline-edit.js +124 -0
  28. assets/js/links.js +5 -6
  29. assets/js/video.js +205 -0
  30. includes/mycred-admin.php +135 -10
  31. includes/mycred-functions.php +129 -24
  32. includes/mycred-install.php +5 -1
  33. includes/mycred-shortcodes.php +77 -0
  34. includes/mycred-widgets.php +1 -1
  35. modules/mycred-module-addons.php +2 -2
  36. modules/mycred-module-general.php +2 -2
  37. modules/mycred-module-help.php +3 -4
  38. modules/mycred-module-hooks.php +338 -10
  39. modules/mycred-module-log.php +114 -80
  40. modules/mycred-module-plugins.php +323 -28
  41. modules/mycred-module-subscriptions.php +7 -7
  42. mycred.php +33 -5
  43. readme.txt +40 -3
abstracts/mycred-abstract-hook.php CHANGED
@@ -63,7 +63,7 @@ if ( !class_exists( 'myCRED_Hook' ) ) {
63
  * @version 1.0
64
  */
65
  function preferences() {
66
- echo '<p>' . __( 'This Hook does no settings' ) . '</p>';
67
  }
68
 
69
  /**
@@ -126,7 +126,7 @@ if ( !class_exists( 'myCRED_Hook' ) ) {
126
  /**
127
  * Impose Limits Dropdown
128
  * @since 0.1
129
- * @version 1.1
130
  */
131
  function impose_limits_dropdown( $pref_id = '', $use_select = true ) {
132
  $limits = array(
@@ -143,9 +143,19 @@ if ( !class_exists( 'myCRED_Hook' ) ) {
143
  if ( $use_select )
144
  echo '<option value="">' . __( 'Select', 'mycred' ) . '</option>';
145
 
 
 
 
 
 
 
 
 
 
 
146
  foreach ( $limits as $value => $description ) {
147
  echo '<option value="' . $value . '"';
148
- if ( $this->prefs[$pref_id] == $value ) echo ' selected="selected"';
149
  echo '>' . $description . '</option>';
150
  }
151
  echo '</select>';
@@ -153,47 +163,12 @@ if ( !class_exists( 'myCRED_Hook' ) ) {
153
 
154
  /**
155
  * Has Entry
156
- * Checks to see if a given action with reference ID and user ID exists in the log database.
157
- * @param $action (string) required reference
158
- * @param $ref_id (int) optional reference id
159
- * @param $user_id (int) optional user id
160
- * @param $data (array|string) option data to search
161
  * @since 0.1
162
- * @version 1.1
163
  */
164
  function has_entry( $action = '', $ref_id = '', $user_id = '', $data = '' ) {
165
- global $wpdb;
166
-
167
- $where = $prep = array();
168
- if ( !empty( $action ) ) {
169
- $where[] = 'ref = %s';
170
- $prep[] = $action;
171
- }
172
-
173
- if ( !empty( $ref_id ) ) {
174
- $where[] = 'ref_id = %d';
175
- $prep[] = $ref_id;
176
- }
177
-
178
- if ( !empty( $user_id ) ) {
179
- $where[] = 'user_id = %d';
180
- $prep[] = abs( $user_id );
181
- }
182
-
183
- if ( !empty( $data ) ) {
184
- $where[] = 'data = %s';
185
- $prep[] = maybe_serialize( $data );
186
- }
187
-
188
- $where = implode( ' AND ', $where );
189
-
190
- if ( !empty( $where ) ) {
191
- $sql = "SELECT * FROM " . $wpdb->prefix . 'myCRED_log' . " WHERE $where";
192
- $wpdb->get_results( $wpdb->prepare( $sql, $prep ) );
193
- if ( $wpdb->num_rows > 0 ) return true;
194
- }
195
-
196
- return false;
197
  }
198
  }
199
  }
63
  * @version 1.0
64
  */
65
  function preferences() {
66
+ echo '<p>' . __( 'This Hook has no settings', 'mycred' ) . '</p>';
67
  }
68
 
69
  /**
126
  /**
127
  * Impose Limits Dropdown
128
  * @since 0.1
129
+ * @version 1.2
130
  */
131
  function impose_limits_dropdown( $pref_id = '', $use_select = true ) {
132
  $limits = array(
143
  if ( $use_select )
144
  echo '<option value="">' . __( 'Select', 'mycred' ) . '</option>';
145
 
146
+ $settings = '';
147
+ if ( is_array( $pref_id ) ) {
148
+ reset( $pref_id );
149
+ $key = key( $pref_id );
150
+ $settings = $this->prefs[ $key ][ $pref_id[ $key ] ];
151
+ }
152
+ elseif ( isset( $this->prefs[ $pref_id ] ) ) {
153
+ $settings = $this->prefs[ $pref_id ];
154
+ }
155
+
156
  foreach ( $limits as $value => $description ) {
157
  echo '<option value="' . $value . '"';
158
+ if ( $settings == $value ) echo ' selected="selected"';
159
  echo '>' . $description . '</option>';
160
  }
161
  echo '</select>';
163
 
164
  /**
165
  * Has Entry
166
+ * Moved to myCRED_Settings
 
 
 
 
167
  * @since 0.1
168
+ * @version 1.2
169
  */
170
  function has_entry( $action = '', $ref_id = '', $user_id = '', $data = '' ) {
171
+ return $this->core->has_entry( $action, $ref_id, $user_id, $data );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
172
  }
173
  }
174
  }
abstracts/mycred-abstract-module.php CHANGED
@@ -39,7 +39,7 @@ if ( !class_exists( 'myCRED_Module' ) ) {
39
  function __construct( $module_id = '', $args = array() ) {
40
  // Module ID is required
41
  if ( empty( $module_id ) )
42
- wp_die( __( 'myCRED_Module() Error. A Module ID is required!', 'mycred' ) );
43
 
44
  $this->module_id = $module_id;
45
  $this->core = mycred_get_settings();
39
  function __construct( $module_id = '', $args = array() ) {
40
  // Module ID is required
41
  if ( empty( $module_id ) )
42
+ wp_die( 'myCRED_Module() Error. A Module ID is required!' );
43
 
44
  $this->module_id = $module_id;
45
  $this->core = mycred_get_settings();
addons/banking/abstracts/index.php ADDED
@@ -0,0 +1,3 @@
 
 
 
1
+ <?php
2
+ // Silence is golden.
3
+ ?>
addons/banking/abstracts/mycred-abstract-service.php ADDED
@@ -0,0 +1,291 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ if ( !defined( 'myCRED_VERSION' ) ) exit;
3
+ /**
4
+ * myCRED_Service class
5
+ * @see http://mycred.me/classes/mycred_service/
6
+ * @since 1.2
7
+ * @version 1.0
8
+ */
9
+ if ( !class_exists( 'myCRED_Service' ) ) {
10
+ abstract class myCRED_Service {
11
+
12
+ // Service ID
13
+ public $id;
14
+
15
+ // myCRED_Settings Class
16
+ public $core;
17
+
18
+ // Service Prefs
19
+ public $prefs = false;
20
+
21
+ /**
22
+ * Construct
23
+ */
24
+ function __construct( $args = array(), $service_prefs = NULL ) {
25
+ if ( !empty( $args ) ) {
26
+ foreach ( $args as $key => $value ) {
27
+ $this->$key = $value;
28
+ }
29
+ }
30
+
31
+ // Grab myCRED Settings
32
+ $this->core = mycred_get_settings();
33
+
34
+ // Grab settings
35
+ if ( $service_prefs !== NULL ) {
36
+ // Assign prefs if set
37
+ if ( isset( $service_prefs[$this->id] ) )
38
+ $this->prefs = $service_prefs[$this->id];
39
+
40
+ // Defaults must be set
41
+ if ( !isset( $this->defaults ) || empty( $this->defaults ) )
42
+ $this->defaults = array();
43
+ }
44
+
45
+ // Apply default settings if needed
46
+ if ( !empty( $this->defaults ) )
47
+ $this->prefs = wp_parse_args( $this->prefs, $this->defaults );
48
+ }
49
+
50
+ /**
51
+ * Run
52
+ * Must be over-ridden by sub-class!
53
+ * @since 1.2
54
+ * @version 1.0
55
+ */
56
+ function run() {
57
+ wp_die( 'function myCRED_Service::run() must be over-ridden in a sub-class.' );
58
+ }
59
+
60
+ /**
61
+ * Preferences
62
+ * @since 0.1
63
+ * @version 1.0
64
+ */
65
+ function preferences() {
66
+ echo '<p>' . __( 'This Service has no settings', 'mycred' ) . '</p>';
67
+ }
68
+
69
+ /**
70
+ * Sanitise Preference
71
+ * @since 1.2
72
+ * @version 1.0
73
+ */
74
+ function sanitise_preferences( $post ) {
75
+ return $post;
76
+ }
77
+
78
+ /**
79
+ * Deactivate
80
+ * @since 1.2
81
+ * @version 1.0
82
+ */
83
+ function deactivate() {
84
+
85
+ }
86
+
87
+ /**
88
+ * Get Field Name
89
+ * Returns the field name for the current service
90
+ * @since 1.2
91
+ * @version 1.0
92
+ */
93
+ function field_name( $field = '' ) {
94
+ if ( is_array( $field ) ) {
95
+ $array = array();
96
+ foreach ( $field as $parent => $child ) {
97
+ if ( !is_numeric( $parent ) )
98
+ $array[] = $parent;
99
+
100
+ if ( !empty( $child ) && !is_array( $child ) )
101
+ $array[] = $child;
102
+ }
103
+ $field = '[' . implode( '][', $array ) . ']';
104
+ }
105
+ else {
106
+ $field = '[' . $field . ']';
107
+ }
108
+ return 'mycred_pref_bank[service_prefs][' . $this->id . ']' . $field;
109
+ }
110
+
111
+ /**
112
+ * Get Field ID
113
+ * Returns the field id for the current service
114
+ * @since 1.2
115
+ * @version 1.0
116
+ */
117
+ function field_id( $field = '' ) {
118
+ if ( is_array( $field ) ) {
119
+ $array = array();
120
+ foreach ( $field as $parent => $child ) {
121
+ if ( !is_numeric( $parent ) )
122
+ $array[] = str_replace( '_', '-', $parent );
123
+
124
+ if ( !empty( $child ) && !is_array( $child ) )
125
+ $array[] = str_replace( '_', '-', $child );
126
+ }
127
+ $field = implode( '-', $array );
128
+ }
129
+ else {
130
+ $field = str_replace( '_', '-', $field );
131
+ }
132
+ return 'mycred-bank-service-prefs-' . str_replace( '_', '-', $this->id ) . '-' . $field;
133
+ }
134
+
135
+ /**
136
+ * Get Timeframes
137
+ * @since 1.2
138
+ * @version 1.0
139
+ */
140
+ function get_timeframes() {
141
+ $timeframes = array(
142
+ 'hourly' => array(
143
+ 'label' => __( 'Hourly', 'mycred' ),
144
+ 'date_format' => 'G'
145
+ ),
146
+ 'daily' => array(
147
+ 'label' => __( 'Daily', 'mycred' ),
148
+ 'date_format' => 'z'
149
+ ),
150
+ 'weekly' => array(
151
+ 'label' => __( 'Weekly', 'mycred' ),
152
+ 'date_format' => 'W'
153
+ ),
154
+ 'monthly' => array(
155
+ 'label' => __( 'Monthly', 'mycred' ),
156
+ 'date_format' => 'M'
157
+ ),
158
+ 'quarterly' => array(
159
+ 'label' => __( 'Quarterly', 'mycred' ),
160
+ 'date_format' => 'Y'
161
+ ),
162
+ 'semiannually' => array(
163
+ 'label' => __( 'Semiannually', 'mycred' ),
164
+ 'date_format' => 'Y'
165
+ ),
166
+ 'annually' => array(
167
+ 'label' => __( 'Annually', 'mycred' ),
168
+ 'date_format' => 'Y'
169
+ )
170
+ );
171
+ return apply_filters( 'mycred_banking_timeframes', $timeframes );
172
+ }
173
+
174
+ /**
175
+ * Get Now
176
+ * @since 1.2
177
+ * @version 1.0
178
+ */
179
+ public function get_now( $rate = '' ) {
180
+ $timeframes = $this->get_timeframes();
181
+ if ( array_key_exists( $rate, $timeframes ) ) {
182
+ // Quarterly
183
+ if ( $rate == 'quarterly' ) {
184
+ $month = date_i18n( 'n' );
185
+ return 'Q' . ceil( $month/3 );
186
+ }
187
+ elseif ( $rate == 'semiannually' ) {
188
+ $month = date_i18n( 'n' );
189
+ return ( $month <= 6 ) ? 'first' : 'second';
190
+ }
191
+ else {
192
+ return date_i18n( $timeframes[ $rate ]['date_format'] );
193
+ }
194
+ }
195
+ else
196
+ return false;
197
+ }
198
+
199
+ /**
200
+ * Last Run
201
+ * @since 1.2
202
+ * @version 1.0
203
+ */
204
+ public function get_last_run( $timestamp, $rate ) {
205
+ $timeframes = $this->get_timeframes();
206
+ if ( array_key_exists( $rate, $timeframes ) ) {
207
+ // Quarterly
208
+ if ( $rate == 'quarterly' ) {
209
+ $month = date_i18n( 'n', $timestamp );
210
+ return 'Q' . ceil( $month/3 );
211
+ }
212
+ elseif ( $rate == 'semiannually' ) {
213
+ $month = date_i18n( 'm', $timestamp );
214
+ return ( $month <= 5 ) ? 'first' : 'second';
215
+ }
216
+ else {
217
+ return date_i18n( $timeframes[ $rate ]['date_format'], $timestamp );
218
+ }
219
+ }
220
+ else
221
+ return false;
222
+ }
223
+
224
+ /**
225
+ * Get User IDs
226
+ * Returns all registered members user id with optional excludes.
227
+ * @since 1.2
228
+ * @version 1.0
229
+ */
230
+ public function get_user_ids( $exclude = '' ) {
231
+ $args = array();
232
+ $args['fields'] = 'ID';
233
+
234
+ $excludes = $this->core->exclude['list'];
235
+ if ( !empty( $exclude ) )
236
+ $excludes .= $exclude;
237
+
238
+ if ( !empty( $excludes ) )
239
+ $args['exclude'] = explode( ',', $excludes );
240
+
241
+ return get_users( $args );
242
+ }
243
+
244
+ /**
245
+ * Get Days in Year
246
+ * @since 1.2
247
+ * @version 1.0
248
+ */
249
+ public function get_days_in_year() {
250
+ if ( date_i18n( 'L' ) )
251
+ return 366;
252
+ else
253
+ return 365;
254
+ }
255
+
256
+ /**
257
+ * Timeframe Dropdown
258
+ * @since 1.2
259
+ * @version 1.0
260
+ */
261
+ function timeframe_dropdown( $pref_id = '', $use_select = true, $hourly = true ) {
262
+
263
+ $timeframes = $this->get_timeframes();
264
+ if ( !$hourly )
265
+ unset( $timeframes['hourly'] );
266
+
267
+ echo '<select name="' . $this->field_name( $pref_id ) . '" id="' . $this->field_id( $pref_id ) . '">';
268
+
269
+ if ( $use_select )
270
+ echo '<option value="">' . __( 'Select', 'mycred' ) . '</option>';
271
+
272
+ $settings = '';
273
+ if ( is_array( $pref_id ) ) {
274
+ reset( $pref_id );
275
+ $key = key( $pref_id );
276
+ $settings = $this->prefs[ $key ][ $pref_id[ $key ] ];
277
+ }
278
+ elseif ( isset( $this->prefs[ $pref_id ] ) ) {
279
+ $settings = $this->prefs[ $pref_id ];
280
+ }
281
+
282
+ foreach ( $timeframes as $value => $details ) {
283
+ echo '<option value="' . $value . '"';
284
+ if ( $settings == $value ) echo ' selected="selected"';
285
+ echo '>' . $details['label'] . '</option>';
286
+ }
287
+ echo '</select>';
288
+ }
289
+ }
290
+ }
291
+ ?>
addons/banking/index.php ADDED
@@ -0,0 +1,3 @@
 
 
 
1
+ <?php
2
+ // Silence is golden.
3
+ ?>
addons/banking/myCRED-addon-banking.php ADDED
@@ -0,0 +1,234 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Addon: Banking
4
+ * Addon URI: http://mycred.me/add-ons/banking/
5
+ * Version: 1.0
6
+ * Description: This add-on allows you to offer interest on your users %_plural% balances or setup recurring payouts.
7
+ * Author: Gabriel S Merovingi
8
+ * Author URI: http://www.merovingi.com
9
+ */
10
+ if ( !defined( 'myCRED_VERSION' ) ) exit;
11
+ define( 'myCRED_BANK', __FILE__ );
12
+ define( 'myCRED_BANK_DIR', myCRED_ADDONS_DIR . 'banking/' );
13
+ define( 'myCRED_BANK_ABSTRACT_DIR', myCRED_BANK_DIR . 'abstracts/' );
14
+ define( 'myCRED_BANK_SERVICES_DIR', myCRED_BANK_DIR . 'services/' );
15
+
16
+ require_once( myCRED_BANK_ABSTRACT_DIR . 'mycred-abstract-service.php' );
17
+ require_once( myCRED_BANK_SERVICES_DIR . 'mycred-bank-service-interest.php' );
18
+ require_once( myCRED_BANK_SERVICES_DIR . 'mycred-bank-service-payouts.php' );
19
+
20
+ /**
21
+ * myCRED_Banking class
22
+ *
23
+ * @since 0.1
24
+ * @version 1.0
25
+ */
26
+ if ( !class_exists( 'myCRED_Banking' ) ) {
27
+ class myCRED_Banking extends myCRED_Module {
28
+
29
+ /**
30
+ * Constructor
31
+ */
32
+ public function __construct() {
33
+ parent::__construct( 'myCRED_Banking', array(
34
+ 'module_name' => 'banking',
35
+ 'option_id' => 'mycred_pref_bank',
36
+ 'defaults' => array(
37
+ 'active' => array(),
38
+ 'services' => array(),
39
+ 'service_prefs' => array()
40
+ ),
41
+ 'labels' => array(
42
+ 'menu' => __( 'Banking', 'mycred' ),
43
+ 'page_title' => __( 'Banking', 'mycred' ),
44
+ 'page_header' => __( 'Banking', 'mycred' )
45
+ ),
46
+ 'screen_id' => 'myCRED_page_banking',
47
+ 'accordion' => true,
48
+ 'menu_pos' => 30
49
+ ) );
50
+ }
51
+
52
+ /**
53
+ * Load Services
54
+ * @since 1.2
55
+ * @version 1.0
56
+ */
57
+ public function module_init() {
58
+ if ( !empty( $this->services ) ) {
59
+ foreach ( $this->services as $key => $gdata ) {
60
+ if ( $this->is_active( $key ) && isset( $gdata['callback'] ) ) {
61
+ $this->call( 'run', $gdata['callback'] );
62
+ }
63
+ }
64
+ }
65
+ }
66
+
67
+ /**
68
+ * Call
69
+ * Either runs a given class method or function.
70
+ * @since 1.2
71
+ * @version 1.1
72
+ */
73
+ public function call( $call, $callback, $return = NULL ) {
74
+ // Class
75
+ if ( is_array( $callback ) && class_exists( $callback[0] ) ) {
76
+ $class = $callback[0];
77
+ $methods = get_class_methods( $class );
78
+ if ( in_array( $call, $methods ) ) {
79
+ $new = new $class( ( isset( $this->service_prefs ) ) ? $this->service_prefs : array() );
80
+ return $new->$call( $return );
81
+ }
82
+ }
83
+
84
+ // Function
85
+ if ( !is_array( $callback ) ) {
86
+ if ( function_exists( $callback ) ) {
87
+ if ( $return !== NULL )
88
+ return call_user_func( $callback, $return, $this );
89
+ else
90
+ return call_user_func( $callback, $this );
91
+ }
92
+ }
93
+ }
94
+
95
+ /**
96
+ * Get Bank Services
97
+ * @since 1.2
98
+ * @version 1.0
99
+ */
100
+ public function get( $save = false ) {
101
+ // Savings
102
+ $services['interest'] = array(
103
+ 'title' => __( 'Compound Interest', 'mycred' ),
104
+ 'description' => __( 'Apply an interest rate on your users %_plural% balances. Interest rate is annual and is compounded daily as long as this service is enabled. Positive interest rate leads to users gaining %_plural% while a negative interest rate will to users loosing %_plural%.', 'mycred' ),
105
+ 'callback' => array( 'myCRED_Banking_Service_Interest' )
106
+ );
107
+
108
+ // Inflation
109
+ $services['payouts'] = array(
110
+ 'title' => __( 'Recurring Payouts', 'mycred' ),
111
+ 'description' => __( 'Give your users %_plural% on a regular basis with the option to set the number of times you want this payout to run (cycles).', 'mycred' ),
112
+ 'callback' => array( 'myCRED_Banking_Service_Payouts' )
113
+ );
114
+
115
+ $services = apply_filters( 'mycred_setup_banking', $services );
116
+
117
+ if ( $save === true && $this->core->can_edit_plugin() ) {
118
+ update_option( 'mycred_pref_bank', array(
119
+ 'active' => $this->active,
120
+ 'services' => $services,
121
+ 'service_prefs' => $this->service_prefs
122
+ ) );
123
+ }
124
+
125
+ $this->services = $services;
126
+ return $services;
127
+ }
128
+
129
+ /**
130
+ * Admin Page
131
+ * @since 0.1
132
+ * @version 1.0
133
+ */
134
+ public function admin_page() {
135
+ // Security
136
+ if ( !$this->core->can_edit_plugin( get_current_user_id() ) ) wp_die( __( 'Access Denied' ) );
137
+
138
+ // Get installed
139
+ $installed = $this->get( true );
140
+
141
+ // Message
142
+ if ( isset( $_GET['settings-updated'] ) && $_GET['settings-updated'] == true ) {
143
+ echo '<div class="updated settings-error"><p>' . __( 'Settings Updated', 'mycred' ) . '</p></div>';
144
+ } ?>
145
+
146
+ <div class="wrap" id="myCRED-wrap">
147
+ <div id="icon-myCRED" class="icon32"><br /></div>
148
+ <h2><?php echo apply_filters( 'mycred_label', myCRED_NAME ) . ' ' . __( 'Banking', 'mycred' ); ?></h2>
149
+ <p><?php echo $this->core->template_tags_general( __( 'This add-on allows you to setup transaction fees for %_plural% transfers, purchases or payments using the Gateway add-on, along with offering interest on %_plural% balances.', 'mycred' ) ); ?></p>
150
+ <form method="post" action="options.php">
151
+ <?php settings_fields( 'myCRED-banking' ); ?>
152
+
153
+ <!-- Loop though Services -->
154
+ <div class="list-items expandable-li" id="accordion">
155
+ <?php if ( !empty( $installed ) ) {
156
+ foreach ( $installed as $key => $data ) { ?>
157
+
158
+ <h4 class="<?php if ( $this->is_active( $key ) ) echo 'active'; else echo 'inactive'; ?>"><label><?php echo $this->core->template_tags_general( $data['title'] ); ?></label></h4>
159
+ <div class="body" style="display:none;">
160
+ <p><?php echo nl2br( $this->core->template_tags_general( $data['description'] ) ); ?></p>
161
+ <label class="subheader"><?php _e( 'Enable', 'mycred' ); ?></label>
162
+ <ol>
163
+ <li>
164
+ <input type="checkbox" name="mycred_pref_bank[active][]" id="mycred-bank-service-<?php echo $key; ?>" value="<?php echo $key; ?>"<?php if ( $this->is_active( $key ) ) echo ' checked="checked"'; ?> />
165
+ </li>
166
+ </ol>
167
+ <?php echo $this->call( 'preferences', $data['callback'] ); ?>
168
+
169
+ </div>
170
+ <?php }
171
+ } ?>
172
+
173
+ </div>
174
+ <?php submit_button( __( 'Update Changes', 'mycred' ), 'primary large' ); ?>
175
+
176
+ </form>
177
+ </div>
178
+ <?php unset( $installed );
179
+ unset( $this );
180
+ }
181
+
182
+ /**
183
+ * Sanititze Settings
184
+ * @since 1.2
185
+ * @version 1.0
186
+ */
187
+ public function sanitize_settings( $post ) {
188
+ // Loop though all installed hooks
189
+ $installed = $this->get();
190
+
191
+ // Construct new settings
192
+ $new_post['services'] = $installed;
193
+ if ( empty( $post['active'] ) || !isset( $post['active'] ) ) $post['active'] = array();
194
+ $new_post['active'] = $post['active'];
195
+
196
+ if ( !empty( $installed ) ) {
197
+ // Loop though all installed
198
+ foreach ( $installed as $key => $data ) {
199
+ // Callback and settings are required
200
+ if ( isset( $data['callback'] ) && isset( $post['service_prefs'][$key] ) ) {
201
+ // Old settings
202
+ $old_settings = $post['service_prefs'][$key];
203
+
204
+ // New settings
205
+ $new_settings = $this->call( 'sanitise_preferences', $data['callback'], $old_settings );
206
+
207
+ // If something went wrong use the old settings
208
+ if ( empty( $new_settings ) || $new_settings === NULL || !is_array( $new_settings ) )
209
+ $new_post['service_prefs'][$key] = $old_settings;
210
+ // Else we got ourselves new settings
211
+ else
212
+ $new_post['service_prefs'][$key] = $new_settings;
213
+
214
+ // Handle de-activation
215
+ if ( isset( $this->active ) && !empty( $this->active ) ) {
216
+ foreach ( $this->active as $id ) {
217
+ // If a previously active id is no longer in the new active array call deactivate
218
+ if ( !in_array( $id, $new_post['active'] ) ) {
219
+ $this->call( 'deactivate', $data['callback'] );
220
+ }
221
+ }
222
+ }
223
+ // Next item
224
+ }
225
+ }
226
+ }
227
+
228
+ return $new_post;
229
+ }
230
+ }
231
+ $bank = new myCRED_Banking();
232
+ $bank->load();
233
+ }
234
+ ?>
addons/banking/services/index.php ADDED
@@ -0,0 +1,3 @@
 
 
 
1
+ <?php
2
+ // Silence is golden.
3
+ ?>
addons/banking/services/mycred-bank-service-interest.php ADDED
@@ -0,0 +1,265 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * myCRED Bank Service - Interest
4
+ * @since 1.2
5
+ * @version 1.0
6
+ */
7
+ if ( !defined( 'myCRED_VERSION' ) ) exit;
8
+
9
+ if ( !class_exists( 'myCRED_Banking_Service_Interest' ) ) {
10
+ class myCRED_Banking_Service_Interest extends myCRED_Service {
11
+
12
+ /**
13
+ * Construct
14
+ */
15
+ function __construct( $service_prefs ) {
16
+ parent::__construct( array(
17
+ 'id' => 'interest',
18
+ 'defaults' => array(
19
+ 'rate' => array(
20
+ 'amount' => 2,
21
+ 'period' => 1,
22
+ 'pay_out' => 'monthly'
23
+ ),
24
+ 'last_payout' => '',
25
+ 'log' => __( '%plural% interest rate payment', 'mycred' ),
26
+ 'min_balance' => 1
27
+ )
28
+ ), $service_prefs );
29
+ }
30
+
31
+ /**
32
+ * Run
33
+ * @since 1.2
34
+ * @version 1.0
35
+ */
36
+ public function run() {
37
+ add_action( 'wp_loaded', array( $this, 'process' ) );
38
+ add_action( 'mycred_banking_interest_compound', array( $this, 'do_compound' ) );
39
+ add_action( 'mycred_banking_interest_payout', array( $this, 'do_payouts' ) );
40
+ }
41
+
42
+ /**
43
+ * Deactivation
44
+ * @since 1.2
45
+ * @version 1.0
46
+ */
47
+ public function deactivate() {
48
+ // Unschedule compounding
49
+ $timestamp = wp_next_scheduled( 'mycred_banking_interest_compound' );
50
+ if ( $timestamp !== false )
51
+ wp_clear_scheduled_hook( 'mycred_banking_interest_compound' );
52
+
53
+ // Unschedule payouts
54
+ $timestamp = wp_next_scheduled( 'mycred_banking_interest_payout' );
55
+ if ( $timestamp !== false )
56
+ wp_clear_scheduled_hook( 'mycred_banking_interest_payout' );
57
+ }
58
+
59
+ /**
60
+ * Process
61
+ * @since 1.2
62
+ * @version 1.0
63
+ */
64
+ public function process() {
65
+ // Unschedule if amount is set to zero
66
+ if ( $this->prefs['rate']['amount'] == $this->core->format_number( 0 ) ) {
67
+ if ( wp_next_scheduled( 'mycred_banking_interest_compound' ) )
68
+ wp_clear_scheduled_hook( 'mycred_banking_interest_compound' );
69
+ }
70
+
71
+ // Schedule if none exist
72
+ if ( ! wp_next_scheduled( 'mycred_banking_interest_compound' ) ) {
73
+ wp_schedule_event( time(), 'daily', 'mycred_banking_interest_compound' );
74
+ }
75
+
76
+ $unow = date_i18n( 'U' );
77
+ // Cant pay interest on zero
78
+ if ( $this->prefs['rate']['amount'] == $this->core->format_number( 0 ) ) return;
79
+
80
+ // Should we payout
81
+ $payout_now = $this->get_now( $this->prefs['rate']['pay_out'] );
82
+ if ( empty( $this->prefs['last_payout'] ) || $this->prefs['last_payout'] === NULL ) {
83
+ $last_payout = $this->get_last_run( $unow, $this->prefs['rate']['pay_out'] );
84
+ $this->save( 'last_payout', $unow );
85
+ }
86
+ else {
87
+ $last_payout = $this->get_last_run( $this->prefs['last_payout'], $this->prefs['rate']['pay_out'] );
88
+ }
89
+ if ( $payout_now === false || $last_payout === false ) return;
90
+
91
+ if ( $last_payout != $payout_now ) {
92
+ $this->save( 'last_payout', $unow );
93
+ if ( wp_next_scheduled( 'mycred_banking_interest_payout' ) === false )
94
+ wp_schedule_single_event( time(), 'mycred_banking_interest_payout' );
95
+ }
96
+ }
97
+
98
+ /**
99
+ * Do Compound
100
+ * Runs though all user balances and compounds interest. Will un-schedule it self
101
+ * once completed.
102
+ * @since 1.2
103
+ * @version 1.0
104
+ */
105
+ public function do_compound() {
106
+ if ( $this->prefs['rate']['amount'] == $this->core->format_number( 0 ) ) return;
107
+ // Get users
108
+ $users = $this->get_user_ids();
109
+ if ( !empty( $users ) ) {
110
+ foreach ( $users as $user_id ) {
111
+ // Current balance
112
+ $balance = $this->core->get_users_cred( $user_id );
113
+ if ( $balance == 0 ) continue;
114
+
115
+ // Get past interest
116
+ $past_interest = get_user_meta( $user_id, $this->core->get_cred_id() . '_comp', true );
117
+ if ( empty( $past_interest ) ) $past_interest = 0;
118
+
119
+ // Min Balance Limit
120
+ if ( $balance < $this->core->number( $this->prefs['min_balance'] ) ) continue;
121
+
122
+ // Let others play
123
+ $this->prefs = apply_filters( 'mycred_banking_do_compound', $this->prefs, $user_id );
124
+
125
+ // Convert rate
126
+ $rate = $this->prefs['rate']['amount']/100;
127
+
128
+ // Period
129
+ $period = $this->prefs['rate']['period']/$this->get_days_in_year();
130
+
131
+ // Compound
132
+ $interest = ( $balance + $past_interest ) * $rate * $period;
133
+ $interest = round( $interest, 2 );
134
+
135
+ // Save interest
136
+ update_user_meta( $user_id, $this->core->get_cred_id() . '_comp', $interest );
137
+ }
138
+ }
139
+ }
140
+
141
+ /**
142
+ * Do Payout
143
+ * Runs though all user compounded interest and pays. Will un-schedule it self
144
+ * once completed.
145
+ * @since 1.2
146
+ * @version 1.0
147
+ */
148
+ public function do_payouts() {
149
+ // Get users
150
+ $users = $this->get_user_ids();
151
+ if ( !empty( $users ) ) {
152
+ $users = array_unique( $users );
153
+ foreach ( $users as $user_id ) {
154
+ // Get past interest
155
+ $past_interest = get_user_meta( $user_id, $this->core->get_cred_id() . '_comp', true );
156
+ if ( empty( $past_interest ) || $past_interest == 0 ) continue;
157
+
158
+ // Pay / Charge
159
+ $this->core->add_creds(
160
+ 'payout',
161
+ $user_id,
162
+ $past_interest,
163
+ $this->prefs['log']
164
+ );
165
+
166
+ // Reset past interest
167
+ update_user_meta( $user_id, $this->core->get_cred_id() . '_comp', 0 );
168
+
169
+ // Let others play
170
+ do_action( 'mycred_banking_do_payout', $this->id, $user_id, $this->prefs, $past_interest );
171
+ }
172
+ }
173
+ // Make sure to clear any stray schedules to prevent duplicates
174
+ wp_clear_scheduled_hook( 'mycred_banking_interest_payout' );
175
+ }
176
+
177
+ /**
178
+ * Save
179
+ * Saves the given preference id for rates.
180
+ * from the active list.
181
+ * @since 1.2
182
+ * @version 1.0
183
+ */
184
+ public function save( $id, $now ) {
185
+ if ( !isset( $this->prefs[ $id ] ) ) return;
186
+ $this->prefs[ $id ] = $now;
187
+
188
+ // Get Bank settings
189
+ $bank = get_option( 'mycred_pref_bank' );
190
+
191
+ // Update settings
192
+ $bank['service_prefs'][$this->id] = $this->prefs;
193
+
194
+ // Save new settings
195
+ update_option( 'mycred_pref_bank', $bank );
196
+ }
197
+
198
+ /**
199
+ * Preference for Savings
200
+ * @since 1.2
201
+ * @version 1.0
202
+ */
203
+ public function preferences() {
204
+ $prefs = $this->prefs; ?>
205
+
206
+ <label class="subheader"><?php _e( 'Interest Rate', 'mycred' ); ?></label>
207
+ <ol class="inline">
208
+ <li>
209
+ <label>&nbsp;</label>
210
+ <div class="h2"><input type="text" name="<?php echo $this->field_name( array( 'rate' => 'amount' ) ); ?>" id="<?php echo $this->field_id( array( 'rate' => 'amount' ) ); ?>" value="<?php echo $this->core->format_number( $prefs['rate']['amount'] ); ?>" size="4" /> %</div>
211
+ </li>
212
+ <li>
213
+ <label for="<?php echo $this->field_id( array( 'rate' => 'pay_out' ) ); ?>"><?php _e( 'Payed / Charged', 'mycred' ); ?></label><br />
214
+ <?php $this->timeframe_dropdown( array( 'rate' => 'pay_out' ), false, false ); ?>
215
+
216
+ </li>
217
+ <li class="block">
218
+ <input type="hidden" name="<?php echo $this->field_name( 'last_payout' ); ?>" value="<?php echo $prefs['last_payout']; ?>" />
219
+ <span class="description"><?php _e( 'The interest rate can be either positive or negative and is compounded daily.', 'mycred' ); ?></span>
220
+ </li>
221
+ </ol>
222
+ <label class="subheader"><?php _e( 'Minimum Balance', 'mycred' ); ?></label>
223
+ <ol>
224
+ <li>
225
+ <div class="h2"><?php if ( !empty( $this->core->before ) ) echo $this->core->before . ' '; ?><input type="text" name="<?php echo $this->field_name( 'min_balance' ); ?>" id="<?php echo $this->field_id( 'min_balance' ); ?>" value="<?php echo $this->core->format_number( $prefs['min_balance'] ); ?>" size="8" /><?php if ( !empty( $this->core->after ) ) echo ' ' . $this->core->after; ?></div>
226
+ <span class="description"><?php _e( 'The minimum requires balance for interest to apply.', 'mycred' ); ?></span>
227
+ </li>
228
+ </ol>
229
+ <label class="subheader"><?php _e( 'Log Template', 'mycred' ); ?></label>
230
+ <ol>
231
+ <li>
232
+ <div class="h2"><input type="text" name="<?php echo $this->field_name( 'log' ); ?>" id="<?php echo $this->field_id( 'log' ); ?>" value="<?php echo $prefs['log']; ?>" style="width: 65%;" /></div>
233
+ <span class="description"><?php _e( 'Available template tags: General, %timeframe%, %rate%, %base%', 'mycred' ); ?></span>
234
+ </li>
235
+ </ol>
236
+ <?php do_action( 'mycred_banking_compound_interest', $this->prefs ); ?>
237
+ <?php
238
+ }
239
+
240
+ /**
241
+ * Sanitise Preferences
242
+ * @since 1.2
243
+ * @version 1.0
244
+ */
245
+ function sanitise_preferences( $post ) {
246
+ $new_settings = $post;
247
+
248
+ $new_settings['rate']['amount'] = str_replace( ',', '.', trim( $post['rate']['amount'] ) );
249
+
250
+ $new_settings['rate']['period'] = $this->get_days_in_year();
251
+
252
+ $new_settings['rate']['pay_out'] = sanitize_text_field( $post['rate']['pay_out'] );
253
+
254
+ $new_settings['min_balance'] = str_replace( ',', '.', trim( $post['min_balance'] ) );
255
+
256
+ $new_settings['last_payout'] = trim( $post['last_payout'] );
257
+
258
+ $new_settings['log'] = trim( $post['log'] );
259
+
260
+ return apply_filters( 'mycred_banking_save_interest', $new_settings, $this->prefs );
261
+ }
262
+ }
263
+ }
264
+
265
+ ?>
addons/banking/services/mycred-bank-service-payouts.php ADDED
@@ -0,0 +1,248 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * myCRED Bank Service - Recurring Payouts
4
+ * @since 1.2
5
+ * @version 1.0
6
+ */
7
+ if ( !defined( 'myCRED_VERSION' ) ) exit;
8
+
9
+ if ( !class_exists( 'myCRED_Banking_Service_Payouts' ) ) {
10
+ class myCRED_Banking_Service_Payouts extends myCRED_Service {
11
+
12
+ /**
13
+ * Construct
14
+ */
15
+ function __construct( $service_prefs ) {
16
+ parent::__construct( array(
17
+ 'id' => 'payouts',
18
+ 'defaults' => array(
19
+ 'amount' => 10,
20
+ 'rate' => 'daily',
21
+ 'log' => __( 'Daily %_plural%', 'mycred' ),
22
+ 'excludes' => '',
23
+ 'cycles' => 0,
24
+ 'last_run' => ''
25
+ )
26
+ ), $service_prefs );
27
+ }
28
+
29
+ /**
30
+ * Run
31
+ * @since 1.2
32
+ * @version 1.0
33
+ */
34
+ public function run() {
35
+ add_action( 'wp_loaded', array( $this, 'process' ) );
36
+ add_action( 'mycred_banking_recurring_payout', array( $this, 'do_payouts' ) );
37
+ }
38
+
39
+ /**
40
+ * Deactivation
41
+ * @since 1.2
42
+ * @version 1.0
43
+ */
44
+ public function deactivate() {
45
+ // Unschedule payouts
46
+ wp_clear_scheduled_hook( 'mycred_banking_recurring_payout' );
47
+ }
48
+
49
+ /**
50
+ * Process
51
+ * @since 1.2
52
+ * @version 1.0
53
+ */
54
+ public function process() {
55
+ // Get cycles
56
+ $cycles = (int) $this->prefs['cycles'];
57
+ // Zero cycles left, bail
58
+ if ( $cycles == 0 ) return;
59
+
60
+ // No amount = no payout
61
+ if ( !isset( $this->prefs['amount'] ) || $this->prefs['amount'] == 0 ) return;
62
+
63
+ $unow = date_i18n( 'U' );
64
+ $now = $this->get_now( $this->prefs['rate'] );
65
+ // No last run, save now as last run
66
+ if ( empty( $this->prefs['last_run'] ) || $this->prefs['last_run'] === NULL ) {
67
+ $last_run = $this->get_last_run( $unow, $this->prefs['rate'] );
68
+ $this->save( $unow, $cycles );
69
+ }
70
+ // Last run
71
+ else {
72
+ $last_run = $this->get_last_run( $this->prefs['last_run'], $this->prefs['rate'] );
73
+ }
74
+ // If now or last run returns false bail
75
+ if ( $now === false || $last_run === false ) return;
76
+
77
+ // Mismatch means new run
78
+ if ( $last_run != $now ) {
79
+ // Cycles (-1 means no limit)
80
+ if ( $cycles > 0-1 ) {
81
+ $cycles = $cycles-1;
82
+ }
83
+ // Save
84
+ $this->save( $unow, $cycles );
85
+
86
+ // Schedule payouts
87
+ if ( ! wp_next_scheduled( 'mycred_banking_recurring_payout' ) )
88
+ wp_schedule_single_event( time(), 'mycred_banking_recurring_payout' );
89
+ }
90
+ }
91
+
92
+ /**
93
+ * Payout
94
+ * Gathers all eligeble users and award / deducts the amount given.
95
+ * @since 1.2
96
+ * @version 1.0
97
+ */
98
+ public function do_payouts() {
99
+ // Query
100
+ $users = $this->get_user_ids( $this->prefs['excludes'] );
101
+ $now = $this->get_now( $this->prefs['rate'] );
102
+ $last_run = $this->get_last_run( $this->prefs['last_run'], $this->prefs['rate'] );
103
+ if ( !empty( $users ) ) {
104
+ $users = array_unique( $users );
105
+ foreach( $users as $user_id ) {
106
+ // Add / Deduct points
107
+ $this->core->add_creds(
108
+ 'payout',
109
+ $user_id,
110
+ $this->prefs['amount'],
111
+ $this->prefs['log']
112
+ );
113
+
114
+ // Let others play
115
+ do_action( 'mycred_banking_do_payout', $this->id, $user_id, $this->prefs );
116
+ }
117
+ }
118
+ // Make sure to clear any stray schedules to prevent duplicates
119
+ wp_clear_scheduled_hook( 'mycred_banking_recurring_payout' );
120
+ }
121
+
122
+ /**
123
+ * Save
124
+ * Saves the last run and the number of cycles run.
125
+ * If this is the last cycle, this method will remove this service
126
+ * from the active list.
127
+ * @since 1.2
128
+ * @version 1.0
129
+ */
130
+ public function save( $now = 0, $cycles = 0 ) {
131
+ // Update last run
132
+ $this->prefs['last_run'] = $now;
133
+ // Update cycles count
134
+ $this->prefs['cycles'] = $cycles;
135
+
136
+ // Get Bank settings
137
+ $bank = get_option( 'mycred_pref_bank' );
138
+
139
+ // Update settings
140
+ $bank['service_prefs'][ $this->id ] = $this->prefs;
141
+
142
+ // Deactivate this service if this is the last run
143
+ if ( $cycles == 0 ) {
144
+ // Should return the service id as a key for us to unset
145
+ if ( ( $key = array_search( $this->id, $bank['active'] ) ) !== false ) {
146
+ unset( $bank['active'][ $key ] );
147
+ }
148
+ }
149
+
150
+ // Save new settings
151
+ update_option( 'mycred_pref_bank', $bank );
152
+ }
153
+
154
+ /**
155
+ * Preference for Savings
156
+ * @since 1.2
157
+ * @version 1.0
158
+ */
159
+ public function preferences() {
160
+ $prefs = $this->prefs;
161
+
162
+ // Last run
163
+ $last_run = $prefs['last_run'];
164
+ if ( empty( $last_run ) )
165
+ $last_run = __( 'Not yet run', 'mycred' );
166
+ else
167
+ $last_run = date_i18n( get_option( 'date_format' ) . ' : ' . get_option( 'time_format' ), $last_run ); ?>
168
+
169
+
170
+ <label class="subheader"><?php _e( 'Pay Users', 'mycred' ); ?></label>
171
+ <ol class="inline">
172
+ <li>
173
+ <label><?php _e( 'Amount', 'mycred' ); ?></label>
174
+ <div class="h2"><?php if ( !empty( $this->core->before ) ) echo $this->core->before . ' '; ?><input type="text" name="<?php echo $this->field_name( 'amount' ); ?>" id="<?php echo $this->field_id( 'amount' ); ?>" value="<?php echo $this->core->format_number( $prefs['amount'] ); ?>" size="8" /><?php if ( !empty( $this->core->after ) ) echo ' ' . $this->core->after; ?></div>
175
+ <span class="description"><?php _e( 'Can not be zero.', 'mycred' ); ?></span>
176
+ <input type="hidden" name="<?php echo $this->field_name( 'last_run' ); ?>" value="<?php echo $prefs['last_run']; ?>" />
177
+ </li>
178
+ <li>
179
+ <label for="<?php echo $this->field_id( 'rate' ); ?>"><?php _e( 'Interval', 'mycred' ); ?></label><br />
180
+ <?php $this->timeframe_dropdown( 'rate', false ); ?>
181
+
182
+ </li>
183
+ <li>
184
+ <label><?php _e( 'Cycles', 'mycred' ); ?></label>
185
+ <div class="h2"><input type="text" name="<?php echo $this->field_name( 'cycles' ); ?>" id="<?php echo $this->field_id( 'cycles' ); ?>" value="<?php echo $prefs['cycles']; ?>" size="8" /></div>
186
+ <span class="description"><?php _e( 'Set to -1 for unlimited', 'mycred' ); ?></span>
187
+ </li>
188
+ <li>
189
+ <label><?php _e( 'Last Run / Activated', 'mycred' ); ?></label><br />
190
+ <div class="h2"><?php echo $last_run; ?></div>
191
+ </li>
192
+ <li class="block"><strong><?php _e( 'Interval', 'mycred' ); ?></strong><br /><?php echo $this->core->template_tags_general( __( 'Select how often you want to award %_plural%. Note that when this service is enabled, the first payout will be in the beginning of the next period. So with a "Daily" interval, the first payout will occur first thing in the morning.', 'mycred' ) ); ?></li>
193
+ <li class="block"><strong><?php _e( 'Cycles', 'mycred' ); ?></strong><br /><?php _e( 'Cycles let you choose how many intervals this service should run. Each time a cycle runs, the value will decrease until it hits zero, in which case this service will deactivate itself. Use -1 to run unlimited times.', 'mycred' ); ?></li>
194
+ <li class="block"><strong><?php _e( 'Important', 'mycred' ); ?></strong><br /><?php _e( 'You can always stop payouts by deactivating this service. Just remember that if you deactivate while there are cycles left, this service will continue on when it gets re-activated. Set cycles to zero to reset.', 'mycred' ); ?></li>
195
+ </ol>
196
+ <label class="subheader" for="<?php echo $this->field_id( 'excludes' ); ?>"><?php _e( 'Excludes', 'mycred' ); ?></label>
197
+ <ol>
198
+ <li>
199
+ <div class="h2"><input type="text" name="<?php echo $this->field_name( 'excludes' ); ?>" id="<?php echo $this->field_id( 'excludes' ); ?>" value="<?php echo $prefs['excludes']; ?>" style="width: 65%;" /></div>
200
+ <span class="description"><?php _e( 'Comma separated list of user IDs to exclude from this service. No spaces allowed!', 'mycred' ); ?></span>
201
+ </li>
202
+ </ol>
203
+ <label class="subheader" for="<?php echo $this->field_id( 'log' ); ?>"><?php _e( 'Log Template', 'mycred' ); ?></label>
204
+ <ol>
205
+ <li>
206
+ <div class="h2"><input type="text" name="<?php echo $this->field_name( 'log' ); ?>" id="<?php echo $this->field_id( 'log' ); ?>" value="<?php echo $prefs['log']; ?>" style="width: 65%;" /></div>
207
+ <span class="description"><?php _e( 'Available template tags: General', 'mycred' ); ?></span>
208
+ </li>
209
+ </ol>
210
+ <?php do_action( 'mycred_banking_recurring_payouts', $this->prefs ); ?>
211
+ <?php
212
+ }
213
+
214
+ /**
215
+ * Sanitise Preferences
216
+ * @since 1.2
217
+ * @version 1.0
218
+ */
219
+ function sanitise_preferences( $post ) {
220
+ // Amount
221
+ $new_settings['amount'] = trim( $post['amount'] );
222
+
223
+ // Rate
224
+ $new_settings['rate'] = sanitize_text_field( $post['rate'] );
225
+
226
+ // Cycles
227
+ $new_settings['cycles'] = sanitize_text_field( $post['cycles'] );
228
+
229
+ // Last Run
230
+ $new_settings['last_run'] = $post['last_run'];
231
+ $current_cycles = $this->prefs['cycles'];
232
+ // Moving from -1 or 0 to any higher number indicates a new start. In these cases, we will
233
+ // reset the last run timestamp to prevent this service from running right away.
234
+ if ( ( $current_cycles == 0 || $current_cycles == 0-1 ) && $new_settings['cycles'] > 0 )
235
+ $new_settings['last_run'] = '';
236
+
237
+ // Excludes
238
+ $excludes = str_replace( ' ', '', $post['excludes'] );
239
+ $new_settings['excludes'] = sanitize_text_field( $excludes );
240
+
241
+ // Log
242
+ $new_settings['log'] = trim( $post['log'] );
243
+
244
+ return apply_filters( 'mycred_banking_save_recurring', $new_settings, $this->prefs );
245
+ }
246
+ }
247
+ }
248
+ ?>
addons/buddypress/hooks/bp-galleries.php CHANGED
@@ -47,7 +47,7 @@ if ( !class_exists( 'myCRED_BuddyPress_Gallery' ) ) {
47
  if ( $this->core->exclude_user( $gallery->owner_id ) ) return;
48
 
49
  // Make sure this is unique event
50
- if ( $this->has_entry( 'new_buddypress_gallery', $gallery->id ) ) return;
51
 
52
  // Execute
53
  $this->core->add_creds(
47
  if ( $this->core->exclude_user( $gallery->owner_id ) ) return;
48
 
49
  // Make sure this is unique event
50
+ if ( $this->core->has_entry( 'new_buddypress_gallery', $gallery->id ) ) return;
51
 
52
  // Execute
53
  $this->core->add_creds(
addons/buddypress/hooks/bp-groups.php CHANGED
@@ -216,7 +216,7 @@ if ( !class_exists( 'myCRED_BuddyPress_Groups' ) ) {
216
  if ( $this->core->exclude_user( $bp->loggedin_user->id ) ) return;
217
 
218
  // Make sure this is unique event
219
- if ( $this->has_entry( 'new_group_forum_topic', $topic_id, $bp->loggedin_user->id ) ) return;
220
 
221
  // Execute
222
  $this->core->add_creds(
@@ -263,7 +263,7 @@ if ( !class_exists( 'myCRED_BuddyPress_Groups' ) ) {
263
  if ( $this->core->exclude_user( $bp->loggedin_user->id ) ) return;
264
 
265
  // Make sure this is unique event
266
- if ( $this->has_entry( 'new_group_forum_post', $post_id, $bp->loggedin_user->id ) ) return;
267
 
268
  // Execute
269
  $this->core->add_creds(
@@ -311,7 +311,7 @@ if ( !class_exists( 'myCRED_BuddyPress_Groups' ) ) {
311
  $creator = $group->creator_id;
312
 
313
  // Award creator if we have reached the minimum number of members and we have not yet been awarded
314
- if ( $count == $this->prefs['create']['min'] && !$this->has_entry( 'creation_of_new_group', $group_id, $creator ) ) {
315
  $this->core->add_creds( 'creation_of_new_group', $creator, $this->prefs['create']['creds'], $this->prefs['create']['log'], $group_id, 'bp_group' );
316
  }
317
 
@@ -323,7 +323,7 @@ if ( !class_exists( 'myCRED_BuddyPress_Groups' ) ) {
323
  if ( $this->core->exclude_user( $user_id ) ) return;
324
 
325
  // Make sure this is unique event
326
- if ( $this->has_entry( 'joining_group', $group_id, $user_id ) ) return;
327
 
328
  // Execute
329
  $this->core->add_creds(
@@ -346,7 +346,7 @@ if ( !class_exists( 'myCRED_BuddyPress_Groups' ) ) {
346
  if ( $this->core->exclude_user( $user_id ) ) return;
347
 
348
  // Make sure this is unique event
349
- if ( $this->has_entry( 'leaving_group', $group_id, $user_id ) ) return;
350
 
351
  // Execute
352
  $this->core->add_creds(
@@ -371,7 +371,7 @@ if ( !class_exists( 'myCRED_BuddyPress_Groups' ) ) {
371
  if ( $this->core->exclude_user( $bp->loggedin_user->id ) ) return;
372
 
373
  // Make sure this is unique event
374
- if ( $this->has_entry( 'upload_group_avatar', $group_id ) ) return;
375
 
376
  // Execute
377
  $this->core->add_creds(
@@ -394,7 +394,7 @@ if ( !class_exists( 'myCRED_BuddyPress_Groups' ) ) {
394
  if ( $this->core->exclude_user( $user_id ) ) return;
395
 
396
  // Make sure this is unique event
397
- if ( $this->has_entry( 'new_group_comment', $activity_id, $user_id ) ) return;
398
 
399
  // Execute
400
  $this->core->add_creds(
216
  if ( $this->core->exclude_user( $bp->loggedin_user->id ) ) return;
217
 
218
  // Make sure this is unique event
219
+ if ( $this->core->has_entry( 'new_group_forum_topic', $topic_id, $bp->loggedin_user->id ) ) return;
220
 
221
  // Execute
222
  $this->core->add_creds(
263
  if ( $this->core->exclude_user( $bp->loggedin_user->id ) ) return;
264
 
265
  // Make sure this is unique event
266
+ if ( $this->core->has_entry( 'new_group_forum_post', $post_id, $bp->loggedin_user->id ) ) return;
267
 
268
  // Execute
269
  $this->core->add_creds(
311
  $creator = $group->creator_id;
312
 
313
  // Award creator if we have reached the minimum number of members and we have not yet been awarded
314
+ if ( $count == $this->prefs['create']['min'] && !$this->core->has_entry( 'creation_of_new_group', $group_id, $creator ) ) {
315
  $this->core->add_creds( 'creation_of_new_group', $creator, $this->prefs['create']['creds'], $this->prefs['create']['log'], $group_id, 'bp_group' );
316
  }
317
 
323
  if ( $this->core->exclude_user( $user_id ) ) return;
324
 
325
  // Make sure this is unique event
326
+ if ( $this->core->has_entry( 'joining_group', $group_id, $user_id ) ) return;
327
 
328
  // Execute
329
  $this->core->add_creds(
346
  if ( $this->core->exclude_user( $user_id ) ) return;
347
 
348
  // Make sure this is unique event
349
+ if ( $this->core->has_entry( 'leaving_group', $group_id, $user_id ) ) return;
350
 
351
  // Execute
352
  $this->core->add_creds(
371
  if ( $this->core->exclude_user( $bp->loggedin_user->id ) ) return;
372
 
373
  // Make sure this is unique event
374
+ if ( $this->core->has_entry( 'upload_group_avatar', $group_id ) ) return;
375
 
376
  // Execute
377
  $this->core->add_creds(
394
  if ( $this->core->exclude_user( $user_id ) ) return;
395
 
396
  // Make sure this is unique event
397
+ if ( $this->core->has_entry( 'new_group_comment', $activity_id, $user_id ) ) return;
398
 
399
  // Execute
400
  $this->core->add_creds(
addons/buddypress/hooks/bp-links.php CHANGED
@@ -68,7 +68,7 @@ if ( !class_exists( 'myCRED_BuddyPress_Links' ) ) {
68
  if ( $this->core->exclude_user( $bp->loggedin_user->id ) ) return;
69
 
70
  // Make sure this is unique event
71
- if ( $this->has_entry( 'new_link', $link_id, $bp->loggedin_user->id ) ) return;
72
 
73
  // Execute
74
  $this->core->add_creds(
@@ -93,7 +93,7 @@ if ( !class_exists( 'myCRED_BuddyPress_Links' ) ) {
93
  if ( $this->core->exclude_user( $bp->loggedin_user->id ) ) return;
94
 
95
  // Make sure this is unique event
96
- if ( $this->has_entry( 'link_voting', $link_id, $bp->loggedin_user->id ) ) return;
97
 
98
  // Execute
99
  $this->core->add_creds(
@@ -116,7 +116,7 @@ if ( !class_exists( 'myCRED_BuddyPress_Links' ) ) {
116
  if ( $this->core->exclude_user( $user_id ) ) return;
117
 
118
  // Make sure this is unique event
119
- if ( $this->has_entry( 'update_link', $activity_id, $user_id ) ) return;
120
 
121
  // Execute
122
  $this->core->add_creds(
@@ -141,7 +141,7 @@ if ( !class_exists( 'myCRED_BuddyPress_Links' ) ) {
141
  if ( $this->core->exclude_user( $bp->loggedin_user->id ) ) return;
142
 
143
  // Make sure this is unique event
144
- if ( $this->has_entry( 'link_deletion', $link_id, $bp->loggedin_user->id ) ) return;
145
 
146
  // Execute
147
  $this->core->add_creds(
68
  if ( $this->core->exclude_user( $bp->loggedin_user->id ) ) return;
69
 
70
  // Make sure this is unique event
71
+ if ( $this->core->has_entry( 'new_link', $link_id, $bp->loggedin_user->id ) ) return;
72
 
73
  // Execute
74
  $this->core->add_creds(
93
  if ( $this->core->exclude_user( $bp->loggedin_user->id ) ) return;
94
 
95
  // Make sure this is unique event
96
+ if ( $this->core->has_entry( 'link_voting', $link_id, $bp->loggedin_user->id ) ) return;
97
 
98
  // Execute
99
  $this->core->add_creds(
116
  if ( $this->core->exclude_user( $user_id ) ) return;
117
 
118
  // Make sure this is unique event
119
+ if ( $this->core->has_entry( 'update_link', $activity_id, $user_id ) ) return;
120
 
121
  // Execute
122
  $this->core->add_creds(
141
  if ( $this->core->exclude_user( $bp->loggedin_user->id ) ) return;
142
 
143
  // Make sure this is unique event
144
+ if ( $this->core->has_entry( 'link_deletion', $link_id, $bp->loggedin_user->id ) ) return;
145
 
146
  // Execute
147
  $this->core->add_creds(
addons/buddypress/hooks/bp-profile.php CHANGED
@@ -94,7 +94,7 @@ if ( !class_exists( 'myCRED_BuddyPress_Profile' ) ) {
94
  if ( $this->core->exclude_user( $user_id ) ) return;
95
 
96
  // Make sure this is unique event
97
- if ( $this->has_entry( 'new_profile_update', $activity_id, $user_id ) ) return;
98
 
99
  // Execute
100
  $this->core->add_creds(
@@ -119,7 +119,7 @@ if ( !class_exists( 'myCRED_BuddyPress_Profile' ) ) {
119
  if ( $this->core->exclude_user( $bp->loggedin_user->id ) ) return;
120
 
121
  // Make sure this is unique event
122
- if ( $this->has_entry( 'upload_avatar', $bp->loggedin_user->id ) ) return;
123
 
124
  // Execute
125
  $this->core->add_creds(
@@ -133,7 +133,7 @@ if ( !class_exists( 'myCRED_BuddyPress_Profile' ) ) {
133
  /**
134
  * New Friendship
135
  * @since 0.1
136
- * @version 1.0
137
  */
138
  public function friendship_join( $friendship_id, $initiator_user_id, $friend_user_id ) {
139
  // Check if user is excluded
@@ -143,9 +143,9 @@ if ( !class_exists( 'myCRED_BuddyPress_Profile' ) ) {
143
  if ( $this->core->exclude_user( $friend_user_id ) ) return;
144
 
145
  // Make sure this is unique event
146
- if ( $this->has_entry( 'new_friendship', $friend_user_id, $initiator_user_id ) ) return;
147
 
148
- // Execute
149
  $this->core->add_creds(
150
  'new_friendship',
151
  $initiator_user_id,
@@ -154,12 +154,22 @@ if ( !class_exists( 'myCRED_BuddyPress_Profile' ) ) {
154
  $friend_user_id,
155
  array( 'ref_type' => 'user' )
156
  );
 
 
 
 
 
 
 
 
 
 
157
  }
158
 
159
  /**
160
  * Ending Friendship
161
  * @since 0.1
162
- * @version 1.0
163
  */
164
  public function friendship_leave( $friendship_id, $initiator_user_id, $friend_user_id ) {
165
  // Check if user is excluded
@@ -169,9 +179,9 @@ if ( !class_exists( 'myCRED_BuddyPress_Profile' ) ) {
169
  if ( $this->core->exclude_user( $friend_user_id ) ) return;
170
 
171
  // Make sure this is unique event
172
- if ( $this->has_entry( 'ended_friendship', $friend_user_id, $initiator_user_id ) ) return;
173
 
174
- // Execute
175
  $this->core->add_creds(
176
  'ended_friendship',
177
  $initiator_user_id,
@@ -180,6 +190,16 @@ if ( !class_exists( 'myCRED_BuddyPress_Profile' ) ) {
180
  $friend_user_id,
181
  array( 'ref_type' => 'user' )
182
  );
 
 
 
 
 
 
 
 
 
 
183
  }
184
 
185
  /**
@@ -194,7 +214,7 @@ if ( !class_exists( 'myCRED_BuddyPress_Profile' ) ) {
194
  if ( $this->core->exclude_user( $bp->loggedin_user->id ) ) return;
195
 
196
  // Make sure this is unique event
197
- if ( $this->has_entry( 'new_comment', $comment_id ) ) return;
198
 
199
  // Execute
200
  $this->core->add_creds(
@@ -217,7 +237,7 @@ if ( !class_exists( 'myCRED_BuddyPress_Profile' ) ) {
217
  if ( $this->core->exclude_user( $user_id ) ) return;
218
 
219
  // Make sure this is unique event
220
- if ( $this->has_entry( 'comment_deletion', $activity_id ) ) return;
221
 
222
  // Execute
223
  $this->core->add_creds(
@@ -240,7 +260,7 @@ if ( !class_exists( 'myCRED_BuddyPress_Profile' ) ) {
240
  if ( $this->core->exclude_user( $message->sender_id ) ) return;
241
 
242
  // Make sure this is unique event
243
- if ( $this->has_entry( 'new_message', $message->thread_id ) ) return;
244
 
245
  // Execute
246
  $this->core->add_creds(
@@ -266,7 +286,7 @@ if ( !class_exists( 'myCRED_BuddyPress_Profile' ) ) {
266
  if ( $this->core->exclude_user( $to_user_id ) ) return;
267
 
268
  // Make sure this is unique event
269
- if ( $this->has_entry( 'sending_gift', $to_user_id ) ) return;
270
 
271
  // Exclude
272
  $this->core->add_creds(
94
  if ( $this->core->exclude_user( $user_id ) ) return;
95
 
96
  // Make sure this is unique event
97
+ if ( $this->core->has_entry( 'new_profile_update', $activity_id, $user_id ) ) return;
98
 
99
  // Execute
100
  $this->core->add_creds(
119
  if ( $this->core->exclude_user( $bp->loggedin_user->id ) ) return;
120
 
121
  // Make sure this is unique event
122
+ if ( $this->core->has_entry( 'upload_avatar', $bp->loggedin_user->id ) ) return;
123
 
124
  // Execute
125
  $this->core->add_creds(
133
  /**
134
  * New Friendship
135
  * @since 0.1
136
+ * @version 1.1
137
  */
138
  public function friendship_join( $friendship_id, $initiator_user_id, $friend_user_id ) {
139
  // Check if user is excluded
143
  if ( $this->core->exclude_user( $friend_user_id ) ) return;
144
 
145
  // Make sure this is unique event
146
+ if ( $this->core->has_entry( 'new_friendship', $friend_user_id, $initiator_user_id ) ) return;
147
 
148
+ // Points to initiator
149
  $this->core->add_creds(
150
  'new_friendship',
151
  $initiator_user_id,
154
  $friend_user_id,
155
  array( 'ref_type' => 'user' )
156
  );
157
+
158
+ // Points to friend
159
+ $this->core->add_creds(
160
+ 'new_friendship',
161
+ $friend_user_id,
162
+ $this->prefs['new_friend']['creds'],
163
+ $this->prefs['new_friend']['log'],
164
+ $initiator_user_id,
165
+ array( 'ref_type' => 'user' )
166
+ );
167
  }
168
 
169
  /**
170
  * Ending Friendship
171
  * @since 0.1
172
+ * @version 1.1
173
  */
174
  public function friendship_leave( $friendship_id, $initiator_user_id, $friend_user_id ) {
175
  // Check if user is excluded
179
  if ( $this->core->exclude_user( $friend_user_id ) ) return;
180
 
181
  // Make sure this is unique event
182
+ if ( $this->core->has_entry( 'ended_friendship', $friend_user_id, $initiator_user_id ) ) return;
183
 
184
+ // Deduction to initiator
185
  $this->core->add_creds(
186
  'ended_friendship',
187
  $initiator_user_id,
190
  $friend_user_id,
191
  array( 'ref_type' => 'user' )
192
  );
193
+
194
+ // Deduction to friend
195
+ $this->core->add_creds(
196
+ 'ended_friendship',
197
+ $friend_user_id,
198
+ $this->prefs['leave_friend']['creds'],
199
+ $this->prefs['leave_friend']['log'],
200
+ $initiator_user_id,
201
+ array( 'ref_type' => 'user' )
202
+ );
203
  }
204
 
205
  /**
214
  if ( $this->core->exclude_user( $bp->loggedin_user->id ) ) return;
215
 
216
  // Make sure this is unique event
217
+ if ( $this->core->has_entry( 'new_comment', $comment_id ) ) return;
218
 
219
  // Execute
220
  $this->core->add_creds(
237
  if ( $this->core->exclude_user( $user_id ) ) return;
238
 
239
  // Make sure this is unique event
240
+ if ( $this->core->has_entry( 'comment_deletion', $activity_id ) ) return;
241
 
242
  // Execute
243
  $this->core->add_creds(
260
  if ( $this->core->exclude_user( $message->sender_id ) ) return;
261
 
262
  // Make sure this is unique event
263
+ if ( $this->core->has_entry( 'new_message', $message->thread_id ) ) return;
264
 
265
  // Execute
266
  $this->core->add_creds(
286
  if ( $this->core->exclude_user( $to_user_id ) ) return;
287
 
288
  // Make sure this is unique event
289
+ if ( $this->core->has_entry( 'sending_gift', $to_user_id ) ) return;
290
 
291
  // Exclude
292
  $this->core->add_creds(
addons/buddypress/myCRED-addon-buddypress.php CHANGED
@@ -49,7 +49,9 @@ if ( !class_exists( 'myCRED_BuddyPress' ) ) {
49
  'me' => __( "My History", 'mycred' ),
50
  'others' => __( "%s's History", 'mycred' )
51
  ),
52
- 'history_menu_pos' => 99
 
 
53
  ),
54
  'register' => false,
55
  'add_to_core' => true
@@ -77,7 +79,7 @@ if ( !class_exists( 'myCRED_BuddyPress' ) ) {
77
  /**
78
  * Adjust Admin Bar
79
  * @since 0.1
80
- * @version 1.0
81
  */
82
  public function adjust_admin_bar() {
83
  // Bail if this is an ajax request
@@ -93,7 +95,7 @@ if ( !class_exists( 'myCRED_BuddyPress' ) ) {
93
  'parent' => 'my-account-xprofile',
94
  'id' => 'user-admin-mycred',
95
  'title' => $this->buddypress['history_menu_title']['me'],
96
- 'href' => bp_loggedin_user_domain() . 'mycred-history/'
97
  ) );
98
  }
99
  }
@@ -133,7 +135,7 @@ if ( !class_exists( 'myCRED_BuddyPress' ) ) {
133
  /**
134
  * Show Balance in Header
135
  * @since 0.1
136
- * @version 1.1
137
  */
138
  public function show_balance( $table_row = false ) {
139
  if ( bp_is_my_profile() || ( !bp_is_my_profile() && $this->buddypress['visibility']['balance'] ) || mycred_is_admin() ) {
@@ -152,7 +154,7 @@ if ( !class_exists( 'myCRED_BuddyPress' ) ) {
152
  $template = str_replace( '%ranking%', mycred_rankings_position( $user_id ), $template );
153
  }
154
  else {
155
- $template = str_replace( '%rank%', mycred_rankings_position( $user_id ), $template );
156
  }
157
 
158
  echo '<div id="mycred-my-balance">' . $this->core->template_tags_general( $template ) . '</div>';
@@ -162,18 +164,28 @@ if ( !class_exists( 'myCRED_BuddyPress' ) ) {
162
  /**
163
  * Setup Navigation
164
  * @since 0.1
165
- * @version 1.0
166
  */
167
  public function setup_nav() {
168
  if ( !is_user_logged_in() ) return;
169
  global $bp;
170
 
171
  $user_id = bp_displayed_user_id();
 
 
 
172
  if ( $this->core->exclude_user( $user_id ) ) return;
173
 
174
- $current = get_current_user_id();
175
- if ( !$this->buddypress['visibility']['history'] && !$this->core->can_edit_plugin() && $user_id != $current ) return;
 
 
 
 
 
 
176
 
 
177
  if ( $this->buddypress['visibility']['history'] || $this->core->can_edit_plugin() )
178
  $show_for_displayed_user = true;
179
  else
@@ -183,9 +195,9 @@ if ( !class_exists( 'myCRED_BuddyPress' ) ) {
183
  $top_name = bp_word_or_name( $this->buddypress['history_menu_title']['me'], $this->buddypress['history_menu_title']['others'], false, false );
184
  bp_core_new_nav_item( array(
185
  'name' => $this->core->template_tags_general( $top_name ),
186
- 'slug' => 'mycred-history',
187
  'parent_url' => $bp->displayed_user->domain,
188
- 'default_subnav_slug' => 'mycred-history',
189
  'screen_function' => array( $this, 'my_history' ),
190
  'show_for_displayed_user' => $show_for_displayed_user,
191
  'position' => $this->buddypress['history_menu_pos']
@@ -202,9 +214,9 @@ if ( !class_exists( 'myCRED_BuddyPress' ) ) {
202
  // "All" is default
203
  bp_core_new_subnav_item( array(
204
  'name' => 'All',
205
- 'slug' => 'mycred-history',
206
- 'parent_url' => $bp->displayed_user->domain . 'mycred-history/',
207
- 'parent_slug' => 'mycred-history',
208
  'screen_function' => array( $this, 'my_history' ),
209
  'show_for_displayed_user' => $show_for_displayed_user
210
  ) );
@@ -216,8 +228,8 @@ if ( !class_exists( 'myCRED_BuddyPress' ) ) {
216
  bp_core_new_subnav_item( array(
217
  'name' => $sorting_name,
218
  'slug' => $sorting_id,
219
- 'parent_url' => $bp->displayed_user->domain . 'mycred-history/',
220
- 'parent_slug' => 'mycred-history',
221
  'screen_function' => array( $this, 'my_history' ),
222
  'show_for_displayed_user' => $show_for_displayed_user
223
  ) );
@@ -260,17 +272,17 @@ if ( !class_exists( 'myCRED_BuddyPress' ) ) {
260
  /**
261
  * My History Content
262
  * @since 0.1
263
- * @version 1.0
264
  */
265
  public function my_history_screen() {
266
  global $bp;
267
 
268
  $args = array(
269
  'user_id' => bp_displayed_user_id(),
270
- 'number' => 10
271
  );
272
 
273
- if ( isset( $bp->canonical_stack['action'] ) && $bp->canonical_stack['action'] != 'mycred-history' )
274
  $args['time'] = $bp->canonical_stack['action'];
275
 
276
  $log = new myCRED_Query_Log( $args );
@@ -325,7 +337,7 @@ if ( !class_exists( 'myCRED_BuddyPress' ) ) {
325
  /**
326
  * After General Settings
327
  * @since 0.1
328
- * @version 1.0
329
  */
330
  public function after_general_settings() {
331
  // Settings
@@ -421,6 +433,19 @@ if ( !class_exists( 'myCRED_BuddyPress' ) ) {
421
  <span class="description"><?php echo __( 'Current menu positions:', 'mycred' ) . ' ' . implode( ', ', $bp_nav_positions ); ?></span>
422
  </li>
423
  </ol>
 
 
 
 
 
 
 
 
 
 
 
 
 
424
  </div>
425
  <?php
426
  }
@@ -428,7 +453,7 @@ if ( !class_exists( 'myCRED_BuddyPress' ) ) {
428
  /**
429
  * Sanitize Core Settings
430
  * @since 0.1
431
- * @version 1.0
432
  */
433
  public function sanitize_extra_settings( $new_data, $data, $core ) {
434
 
@@ -441,6 +466,11 @@ if ( !class_exists( 'myCRED_BuddyPress' ) ) {
441
  $new_data['buddypress']['history_menu_title']['me'] = sanitize_text_field( $data['buddypress']['history_menu_title']['me'] );
442
  $new_data['buddypress']['history_menu_title']['others'] = sanitize_text_field( $data['buddypress']['history_menu_title']['others'] );
443
  $new_data['buddypress']['history_menu_pos'] = abs( $data['buddypress']['history_menu_pos'] );
 
 
 
 
 
444
  $new_data['buddypress']['visibility']['history'] = ( isset( $data['buddypress']['visibility']['history'] ) ) ? true : false;
445
 
446
  return $new_data;
49
  'me' => __( "My History", 'mycred' ),
50
  'others' => __( "%s's History", 'mycred' )
51
  ),
52
+ 'history_menu_pos' => 99,
53
+ 'history_url' => 'mycred-history',
54
+ 'history_num' => 10
55
  ),
56
  'register' => false,
57
  'add_to_core' => true
79
  /**
80
  * Adjust Admin Bar
81
  * @since 0.1
82
+ * @version 1.1
83
  */
84
  public function adjust_admin_bar() {
85
  // Bail if this is an ajax request
95
  'parent' => 'my-account-xprofile',
96
  'id' => 'user-admin-mycred',
97
  'title' => $this->buddypress['history_menu_title']['me'],
98
+ 'href' => bp_loggedin_user_domain() . $this->buddypress['history_url'] . '/'
99
  ) );
100
  }
101
  }
135
  /**
136
  * Show Balance in Header
137
  * @since 0.1
138
+ * @version 1.2
139
  */
140
  public function show_balance( $table_row = false ) {
141
  if ( bp_is_my_profile() || ( !bp_is_my_profile() && $this->buddypress['visibility']['balance'] ) || mycred_is_admin() ) {
154
  $template = str_replace( '%ranking%', mycred_rankings_position( $user_id ), $template );
155
  }
156
  else {
157
+ $template = str_replace( array( '%ranking%', '%rank%' ), mycred_rankings_position( $user_id ), $template );
158
  }
159
 
160
  echo '<div id="mycred-my-balance">' . $this->core->template_tags_general( $template ) . '</div>';
164
  /**
165
  * Setup Navigation
166
  * @since 0.1
167
+ * @version 1.1
168
  */
169
  public function setup_nav() {
170
  if ( !is_user_logged_in() ) return;
171
  global $bp;
172
 
173
  $user_id = bp_displayed_user_id();
174
+ $current = get_current_user_id();
175
+
176
+ // User is excluded
177
  if ( $this->core->exclude_user( $user_id ) ) return;
178
 
179
+ // Admins alway see points history
180
+ if ( !$this->core->can_edit_plugin() ) {
181
+ // If history is not shown in profile
182
+ if ( $this->buddypress['history_location'] != 'top' ) return;
183
+
184
+ // Allow users to see each others history?
185
+ if ( !$this->buddypress['visibility']['history'] && $user_id != $current ) return;
186
+ }
187
 
188
+ // Settings for bp menu
189
  if ( $this->buddypress['visibility']['history'] || $this->core->can_edit_plugin() )
190
  $show_for_displayed_user = true;
191
  else
195
  $top_name = bp_word_or_name( $this->buddypress['history_menu_title']['me'], $this->buddypress['history_menu_title']['others'], false, false );
196
  bp_core_new_nav_item( array(
197
  'name' => $this->core->template_tags_general( $top_name ),
198
+ 'slug' => $this->buddypress['history_url'],
199
  'parent_url' => $bp->displayed_user->domain,
200
+ 'default_subnav_slug' => $this->buddypress['history_url'],
201
  'screen_function' => array( $this, 'my_history' ),
202
  'show_for_displayed_user' => $show_for_displayed_user,
203
  'position' => $this->buddypress['history_menu_pos']
214
  // "All" is default
215
  bp_core_new_subnav_item( array(
216
  'name' => 'All',
217
+ 'slug' => $this->buddypress['history_url'],
218
+ 'parent_url' => $bp->displayed_user->domain . $this->buddypress['history_url'] . '/',
219
+ 'parent_slug' => $this->buddypress['history_url'],
220
  'screen_function' => array( $this, 'my_history' ),
221
  'show_for_displayed_user' => $show_for_displayed_user
222
  ) );
228
  bp_core_new_subnav_item( array(
229
  'name' => $sorting_name,
230
  'slug' => $sorting_id,
231
+ 'parent_url' => $bp->displayed_user->domain . $this->buddypress['history_url'] . '/',
232
+ 'parent_slug' => $this->buddypress['history_url'],
233
  'screen_function' => array( $this, 'my_history' ),
234
  'show_for_displayed_user' => $show_for_displayed_user
235
  ) );
272
  /**
273
  * My History Content
274
  * @since 0.1
275
+ * @version 1.1
276
  */
277
  public function my_history_screen() {
278
  global $bp;
279
 
280
  $args = array(
281
  'user_id' => bp_displayed_user_id(),
282
+ 'number' => apply_filters( 'mycred_bp_history_num_to_show', $this->buddypress['history_num'] )
283
  );
284
 
285
+ if ( isset( $bp->canonical_stack['action'] ) && $bp->canonical_stack['action'] != $this->buddypress['history_url'] )
286
  $args['time'] = $bp->canonical_stack['action'];
287
 
288
  $log = new myCRED_Query_Log( $args );
337
  /**
338
  * After General Settings
339
  * @since 0.1
340
+ * @version 1.1
341
  */
342
  public function after_general_settings() {
343
  // Settings
433
  <span class="description"><?php echo __( 'Current menu positions:', 'mycred' ) . ' ' . implode( ', ', $bp_nav_positions ); ?></span>
434
  </li>
435
  </ol>
436
+ <ol>
437
+ <li>
438
+ <label for="<?php echo $this->field_id( 'history_url' ); ?>"><?php _e( 'History URL slug', 'mycred' ); ?></label>
439
+ <div class="h2">/ <input type="text" name="<?php echo $this->field_name( 'history_url' ); ?>" id="<?php echo $this->field_id( 'history_url' ); ?>" value="<?php echo $settings['history_url']; ?>" class="medium" />/</div>
440
+ <span class="description"><?php echo __( 'Do not use empty spaces!', 'mycred' ); ?></span>
441
+ </li>
442
+ </ol>
443
+ <ol>
444
+ <li>
445
+ <label for="<?php echo $this->field_id( 'history_num' ); ?>"><?php _e( 'Number of history entries to show', 'mycred' ); ?></label>
446
+ <div class="h2"><input type="text" name="<?php echo $this->field_name( 'history_num' ); ?>" id="<?php echo $this->field_id( 'history_num' ); ?>" value="<?php echo $settings['history_num']; ?>" class="short" /></div>
447
+ </li>
448
+ </ol>
449
  </div>
450
  <?php
451
  }
453
  /**
454
  * Sanitize Core Settings
455
  * @since 0.1
456
+ * @version 1.1
457
  */
458
  public function sanitize_extra_settings( $new_data, $data, $core ) {
459
 
466
  $new_data['buddypress']['history_menu_title']['me'] = sanitize_text_field( $data['buddypress']['history_menu_title']['me'] );
467
  $new_data['buddypress']['history_menu_title']['others'] = sanitize_text_field( $data['buddypress']['history_menu_title']['others'] );
468
  $new_data['buddypress']['history_menu_pos'] = abs( $data['buddypress']['history_menu_pos'] );
469
+
470
+ $url = sanitize_text_field( $data['buddypress']['history_url'] );
471
+ $new_data['buddypress']['history_url'] = urlencode( $url );
472
+ $new_data['buddypress']['history_num'] = abs( $data['buddypress']['history_num'] );
473
+
474
  $new_data['buddypress']['visibility']['history'] = ( isset( $data['buddypress']['visibility']['history'] ) ) ? true : false;
475
 
476
  return $new_data;
addons/email-notices/myCRED-addon-email-notices.php CHANGED
@@ -457,7 +457,7 @@ if ( !class_exists( 'myCRED_Email_Notices' ) ) {
457
  /**
458
  * WP Mail
459
  * @since 1.1
460
- * @version 1.0
461
  */
462
  public function wp_mail( $to, $subject, $message, $headers, $attachments, $request, $email_id ) {
463
  // Let others play before we do our thing
@@ -474,12 +474,18 @@ if ( !class_exists( 'myCRED_Email_Notices' ) ) {
474
  // Parse Subject Template Tags
475
  $subject = $this->core->template_tags_general( $filtered['subject'] );
476
  $subject = $this->core->template_tags_amount( $subject, $filtered['request']['amount'] );
477
- $subject = $this->core->template_tags_user( $subject, $filtered['request']['user_id'] );
 
 
 
478
 
479
  // Parse Message Template Tags
480
  $message = $this->core->template_tags_general( $filtered['message'] );
481
  $message = $this->core->template_tags_amount( $message, $filtered['request']['amount'] );
482
- $message = $this->core->template_tags_user( $message, $filtered['request']['user_id'] );
 
 
 
483
  $message = $this->template_tags_request( $message, $filtered['request'] );
484
 
485
  // Construct HTML Content
457
  /**
458
  * WP Mail
459
  * @since 1.1
460
+ * @version 1.1
461
  */
462
  public function wp_mail( $to, $subject, $message, $headers, $attachments, $request, $email_id ) {
463
  // Let others play before we do our thing
474
  // Parse Subject Template Tags
475
  $subject = $this->core->template_tags_general( $filtered['subject'] );
476
  $subject = $this->core->template_tags_amount( $subject, $filtered['request']['amount'] );
477
+ if ( $filtered['request']['user_id'] == get_current_user_id() )
478
+ $subject = $this->core->template_tags_user( $subject, false, wp_get_current_user() );
479
+ else
480
+ $subject = $this->core->template_tags_user( $subject, $filtered['request']['user_id'] );
481
 
482
  // Parse Message Template Tags
483
  $message = $this->core->template_tags_general( $filtered['message'] );
484
  $message = $this->core->template_tags_amount( $message, $filtered['request']['amount'] );
485
+ if ( $filtered['request']['user_id'] == get_current_user_id() )
486
+ $message = $this->core->template_tags_user( $message, false, wp_get_current_user() );
487
+ else
488
+ $message = $this->core->template_tags_user( $message, $filtered['request']['user_id'] );
489
  $message = $this->template_tags_request( $message, $filtered['request'] );
490
 
491
  // Construct HTML Content
addons/gateway/carts/mycred-marketpress.php CHANGED
@@ -50,6 +50,7 @@ if ( !class_exists( 'MP_Gateway_myCRED' ) ) {
50
  $this->public_name = ( !empty( $settings['gateways']['mycred']['name'] ) ) ? $settings['gateways']['mycred']['name'] : apply_filters( 'mycred_label', myCRED_NAME );
51
  $this->method_img_url = plugins_url( 'assets/images/cred-icon32.png', myCRED_THIS );
52
  $this->method_button_img_url = $settings['gateways']['mycred']['name'];
 
53
  }
54
 
55
  /**
@@ -66,20 +67,97 @@ if ( !class_exists( 'MP_Gateway_myCRED' ) ) {
66
  return true;
67
  }
68
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
69
  /**
70
  * Return fields you need to add to the payment screen, like your credit card info fields
71
  *
72
  * @param array $cart. Contains the cart contents for the current blog, global cart if $mp->global_cart is true
73
  * @param array $shipping_info. Contains shipping info and email in case you need it
74
  * @since 1.1
75
- * @version 1.0
76
  */
77
  function payment_form( $cart, $shipping_info ) {
78
  global $mp;
79
 
80
  $settings = get_option( 'mp_settings' );
81
- $mycred = mycred_get_settings();
82
- return '<div id="mp-mycred-balance">' . $mycred->template_tags_general( $settings['gateways']['mycred']['name'] ) . '</div>';
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
83
  }
84
 
85
  /**
@@ -89,15 +167,25 @@ if ( !class_exists( 'MP_Gateway_myCRED' ) ) {
89
  * @param array $cart. Contains the cart contents for the current blog, global cart if $mp->global_cart is true
90
  * @param array $shipping_info. Contains shipping info and email in case you need it
91
  * @since 1.1
92
- * @version 1.0
93
  */
94
  function confirm_payment_form( $cart, $shipping_info ) {
95
  global $mp;
96
 
97
  $settings = get_option( 'mp_settings' );
98
- $mycred = mycred_get_settings();
99
  $user_id = get_current_user_id();
100
- return '<div id="mp-mycred-balance">' . $mycred->template_tags_user( $settings['gateways']['mycred']['instructions'], $user_id ) . '</div>';
 
 
 
 
 
 
 
 
 
 
 
101
  }
102
 
103
  function process_payment_form( $cart, $shipping_info ) { }
@@ -112,95 +200,62 @@ if ( !class_exists( 'MP_Gateway_myCRED' ) ) {
112
  * @param array $cart. Contains the cart contents for the current blog, global cart if $mp->global_cart is true
113
  * @param array $shipping_info. Contains shipping info and email in case you need it
114
  * @since 1.1
115
- * @version 1.0
116
  */
117
  function process_payment( $cart, $shipping_info ) {
118
  global $mp;
119
 
120
  $settings = get_option('mp_settings');
 
 
121
  $timestamp = time();
122
 
123
  // This gateway requires buyer to be logged in
124
- if ( !is_user_logged_in() )
125
- $mp->cart_checkout_error(
126
- sprintf(
127
- __( 'Sorry, but you must be logged in to use this gateway. Please <a href="%s">Login</a> or <a href="%s">select a different payment method</a>.', 'mycred' ),
128
- wp_login_url( mp_checkout_step_url( 'checkout' ) ),
129
- mp_checkout_step_url( 'checkout' )
130
- )
131
- );
132
-
133
- $mycred = mycred_get_settings();
134
- $user_id = get_current_user_id();
135
-
136
  // Make sure current user is not excluded from using myCRED
137
- if ( $mycred->exclude_user( $user_id ) )
138
  $mp->cart_checkout_error(
139
  sprintf( __( 'Sorry, but you can not use this gateway as your account is excluded. Please <a href="%s">select a different payment method</a>.', 'mycred' ), mp_checkout_step_url( 'checkout' ) )
140
  );
141
 
142
- // Get total
143
- $totals = array();
144
- foreach ( $cart as $product_id => $variations ) {
145
- foreach ( $variations as $data ) {
146
- $totals[] = $mp->before_tax_price( $data['price'], $product_id ) * $data['quantity'];
147
- }
148
- }
149
- $total = array_sum( $totals );
150
-
151
- // Apply Coupons
152
- if ( $coupon = $mp->coupon_value( $mp->get_coupon_code(), $total ) ) {
153
- $total = $coupon['new_total'];
154
- }
155
-
156
- // Shipping Cost
157
- if ( ( $shipping_price = $mp->shipping_price() ) !== false ) {
158
- $total = $total + $shipping_price;
159
- }
160
-
161
- // Tax
162
- if ( ( $tax_price = $mp->tax_price() ) !== false ) {
163
- $total = $total + $tax_price;
164
- }
165
-
166
- $balance = $mycred->get_users_cred( $user_id );
167
- if ( $this->use_exchange() )
168
- $balance = $mycred->apply_exchange_rate( $mycred->number( $total ), $settings['gateways']['mycred']['exchange'] );
169
 
170
- // Check if there is enough to fund this
171
- if ( $balance >= $total ) {
172
- // Create MarketPress order
173
- $order_id = $mp->generate_order_id();
174
- $payment_info['gateway_public_name'] = $this->public_name;
175
- $payment_info['gateway_private_name'] = $this->admin_name;
176
- $payment_info['status'][$timestamp] = __( 'Paid', 'mycred' );
177
- $payment_info['total'] = $total;
178
- $payment_info['currency'] = $settings['currency'];
179
- $payment_info['method'] = __( 'myCRED', 'mycred' );
180
- $payment_info['transaction_id'] = $order_id;
181
- $paid = true;
182
- $result = $mp->create_order( $order_id, $cart, $shipping_info, $payment_info, $paid );
183
-
184
- $order = get_page_by_title( $result, 'OBJECT', 'mp_order' );
185
- // Deduct cost
186
- $mycred->add_creds(
187
- 'marketpress_payment',
188
- $user_id,
189
- 0-$total,
190
- $settings['gateways']['mycred']['log_template'],
191
- $order->ID,
192
- array( 'ref_type' => 'post' )
193
- );
194
-
195
-
196
-
197
- }
198
- // Insuffient Funds
199
- else {
200
  $mp->cart_checkout_error(
201
- sprintf( __( 'Insufficient Funds Please select a different payment method. <a href="%s">Go Back</a>', 'mycred' ), mp_checkout_step_url( 'checkout' ) )
202
  );
 
203
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
204
  }
205
 
206
  function order_confirmation( $order ) { }
@@ -227,7 +282,7 @@ if ( !class_exists( 'MP_Gateway_myCRED' ) ) {
227
  * Return any html you want to show on the confirmation screen after checkout. This
228
  * should be a payment details box and message.
229
  * @since 1.1
230
- * @version 1.0
231
  */
232
  function order_confirmation_msg( $content, $order ) {
233
  global $mp;
@@ -239,14 +294,14 @@ if ( !class_exists( 'MP_Gateway_myCRED' ) ) {
239
  return $content . str_replace(
240
  'TOTAL',
241
  $mp->format_currency( $order->mp_payment_info['currency'], $order->mp_payment_info['total'] ),
242
- $mycred->template_tags_user( $settings['gateways']['mycred']['confirmation'], $user_id )
243
  );
244
  }
245
 
246
  /**
247
  * myCRED Gateway Settings
248
  * @since 1.1
249
- * @version 1.0
250
  */
251
  function gateway_settings_box( $settings ) {
252
  global $mp;
@@ -272,6 +327,12 @@ if ( !class_exists( 'MP_Gateway_myCRED' ) ) {
272
 
273
  if ( !isset( $settings['gateways']['mycred']['confirmation'] ) )
274
  $settings['gateways']['mycred']['confirmation'] = 'TOTAL amount has been deducted from your account. Your current balance is: %balance_f%';
 
 
 
 
 
 
275
 
276
  if ( !isset( $settings['gateways']['mycred']['email'] ) )
277
  $settings['gateways']['mycred']['email'] = $settings['email']['new_order_txt']; ?>
@@ -317,6 +378,22 @@ if ( !class_exists( 'MP_Gateway_myCRED' ) ) {
317
  </tr>
318
  <?php endif; ?>
319
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
320
  <tr>
321
  <th scope="row"><label for="mycred-instructions"><?php _e( 'User Instructions', 'mycred' ); ?></label></th>
322
  <td>
@@ -350,7 +427,7 @@ if ( !class_exists( 'MP_Gateway_myCRED' ) ) {
350
  /**
351
  * Filter Gateway Settings
352
  * @since 1.1
353
- * @version 1.0
354
  */
355
  function process_gateway_settings( $settings ) {
356
  // Name (no html)
@@ -372,11 +449,10 @@ if ( !class_exists( 'MP_Gateway_myCRED' ) ) {
372
  else
373
  $settings['gateways']['mycred']['exchange'] = 1;
374
 
375
- // Filter Instruction & Confirmation (if needed)
376
- if ( !current_user_can( 'unfiltered_html' ) ) {
377
- $settings['gateways']['mycred']['instructions'] = wp_filter_post_kses( $settings['gateways']['mycred']['instructions'] );
378
- $settings['gateways']['mycred']['confirmation'] = wp_filter_post_kses( $settings['gateways']['mycred']['confirmation'] );
379
- }
380
 
381
  // Email (no html)
382
  $settings['gateways']['mycred']['email'] = stripslashes( wp_filter_nohtml_kses( $settings['gateways']['mycred']['email'] ) );
50
  $this->public_name = ( !empty( $settings['gateways']['mycred']['name'] ) ) ? $settings['gateways']['mycred']['name'] : apply_filters( 'mycred_label', myCRED_NAME );
51
  $this->method_img_url = plugins_url( 'assets/images/cred-icon32.png', myCRED_THIS );
52
  $this->method_button_img_url = $settings['gateways']['mycred']['name'];
53
+ $this->mycred = mycred_get_settings();
54
  }
55
 
56
  /**
67
  return true;
68
  }
69
 
70
+ /**
71
+ * Returns the current carts total.
72
+ * @since 1.2
73
+ * @version 1.0
74
+ */
75
+ function get_cart_total( $cart = NULL ) {
76
+ global $mp;
77
+
78
+ // Get total
79
+ $totals = array();
80
+ foreach ( $cart as $product_id => $variations ) {
81
+ foreach ( $variations as $data ) {
82
+ $totals[] = $mp->before_tax_price( $data['price'], $product_id ) * $data['quantity'];
83
+ }
84
+ }
85
+ $total = array_sum( $totals );
86
+
87
+ // Apply Coupons
88
+ if ( $coupon = $mp->coupon_value( $mp->get_coupon_code(), $total ) ) {
89
+ $total = $coupon['new_total'];
90
+ }
91
+
92
+ // Shipping Cost
93
+ if ( ( $shipping_price = $mp->shipping_price() ) !== false ) {
94
+ $total = $total + $shipping_price;
95
+ }
96
+
97
+ // Tax
98
+ if ( ( $tax_price = $mp->tax_price() ) !== false ) {
99
+ $total = $total + $tax_price;
100
+ }
101
+
102
+ $settings = get_option( 'mp_settings' );
103
+ if ( $this->use_exchange() )
104
+ return $this->mycred->apply_exchange_rate( $total, $settings['gateways']['mycred']['exchange'] );
105
+ else
106
+ return $this->mycred->number( $total );
107
+ }
108
+
109
  /**
110
  * Return fields you need to add to the payment screen, like your credit card info fields
111
  *
112
  * @param array $cart. Contains the cart contents for the current blog, global cart if $mp->global_cart is true
113
  * @param array $shipping_info. Contains shipping info and email in case you need it
114
  * @since 1.1
115
+ * @version 1.1
116
  */
117
  function payment_form( $cart, $shipping_info ) {
118
  global $mp;
119
 
120
  $settings = get_option( 'mp_settings' );
121
+
122
+ if ( !is_user_logged_in() ) {
123
+ $message = str_replace( '%login_url_here%', wp_login_url( mp_checkout_step_url( 'checkout' ) ), $settings['gateways']['mycred']['visitors'] );
124
+ $message = $this->mycred->template_tags_general( $message );
125
+ return '<div id="mp-mycred-balance">' . $message . '</div>';
126
+ }
127
+
128
+ $balance = $this->mycred->get_users_cred( get_current_user_id() );
129
+ $total = $this->get_cart_total( $cart );
130
+
131
+ // Low balance
132
+ if ( $balance-$total < 0 ) {
133
+ $message = $this->mycred->template_tags_user( $settings['gateways']['mycred']['lowfunds'], false, wp_get_current_user() );
134
+ $instructions = '<div id="mp-mycred-balance">' . $message . '</div>';
135
+ $red = ' style="color: red;"';
136
+ }
137
+ else {
138
+ $instructions = $this->mycred->template_tags_general( $settings['gateways']['mycred']['instructions'] );
139
+ $red = '';
140
+ }
141
+
142
+ // Return Cost
143
+ return '
144
+ <div id="mp-mycred-balance">' . $instructions . '</div>
145
+ <div id="mp-mycred-cost">
146
+ <table style="width:100%;">
147
+ <tr>
148
+ <td class="info">' . __( 'Current Balance', 'mycred' ) . '</td>
149
+ <td class="amount">' . $this->mycred->format_creds( $balance ) . '</td>
150
+ </tr>
151
+ <tr>
152
+ <td class="info">' . __( 'Total Cost', 'mycred' ) . '</td>
153
+ <td class="amount">' . $this->mycred->format_creds( $total ) . '</td>
154
+ </tr>
155
+ <tr>
156
+ <td class="info">' . __( 'Balance After Purchase', 'mycred' ) . '</td>
157
+ <td class="amount"' . $red . '>' . $this->mycred->format_creds( $balance-$total ) . '</td>
158
+ </tr>
159
+ </table>
160
+ </div>';
161
  }
162
 
163
  /**
167
  * @param array $cart. Contains the cart contents for the current blog, global cart if $mp->global_cart is true
168
  * @param array $shipping_info. Contains shipping info and email in case you need it
169
  * @since 1.1
170
+ * @version 1.1
171
  */
172
  function confirm_payment_form( $cart, $shipping_info ) {
173
  global $mp;
174
 
175
  $settings = get_option( 'mp_settings' );
 
176
  $user_id = get_current_user_id();
177
+ $balance = $this->mycred->get_users_cred( get_current_user_id() );
178
+ $total = $this->get_cart_total( $cart );
179
+
180
+ $table = '<table class="mycred-cart-cost"><thead><tr><th>' . __( 'Payment', 'mycred' ) . '</th></tr></thead>';
181
+ if ( $balance-$total < 0 ) {
182
+ $message = $this->mycred->template_tags_user( $settings['gateways']['mycred']['lowfunds'], false, wp_get_current_user() );
183
+ $table .= '<tr><td id="mp-mycred-cost" style="color: red; font-weight: bold;"><p>' . $message . ' ' . sprintf( __( '<a href="%s">Go Back</a>', 'mycred' ), mp_checkout_step_url( 'checkout' ) ) . '</td></tr>';
184
+ }
185
+ else
186
+ $table .= '<tr><td id="mp-mycred-cost" class="mycred-ok">' . $this->mycred->format_creds( $total ) . ' ' . __( 'will be deducted from your account.', 'mycred' ) . '</td></tr>';
187
+
188
+ return $table . '</table>';
189
  }
190
 
191
  function process_payment_form( $cart, $shipping_info ) { }
200
  * @param array $cart. Contains the cart contents for the current blog, global cart if $mp->global_cart is true
201
  * @param array $shipping_info. Contains shipping info and email in case you need it
202
  * @since 1.1
203
+ * @version 1.2
204
  */
205
  function process_payment( $cart, $shipping_info ) {
206
  global $mp;
207
 
208
  $settings = get_option('mp_settings');
209
+ $user_id = get_current_user_id();
210
+ $insolvent = $this->mycred->template_tags_user( $settings['gateways']['mycred']['lowfunds'], false, wp_get_current_user() );
211
  $timestamp = time();
212
 
213
  // This gateway requires buyer to be logged in
214
+ if ( !is_user_logged_in() ) {
215
+ $message = str_replace( '%login_url_here%', wp_login_url( mp_checkout_step_url( 'checkout' ) ), $settings['gateways']['mycred']['visitors'] );
216
+ $mp->cart_checkout_error( $this->mycred->template_tags_general( $message ) );
217
+ }
218
+
 
 
 
 
 
 
 
219
  // Make sure current user is not excluded from using myCRED
220
+ if ( $this->mycred->exclude_user( $user_id ) )
221
  $mp->cart_checkout_error(
222
  sprintf( __( 'Sorry, but you can not use this gateway as your account is excluded. Please <a href="%s">select a different payment method</a>.', 'mycred' ), mp_checkout_step_url( 'checkout' ) )
223
  );
224
 
225
+ // Get users balance
226
+ $balance = $this->mycred->get_users_cred( $user_id );
227
+ $total = $this->get_cart_total( $cart );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
228
 
229
+ // Low balance or Insolvent
230
+ if ( $balance <= 0 || $balance-$total < 0 ) {
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
231
  $mp->cart_checkout_error(
232
+ $insolvent . ' ' . sprintf( __( '<a href="%s">Go Back</a>', 'mycred' ), mp_checkout_step_url( 'checkout' ) )
233
  );
234
+ return;
235
  }
236
+
237
+ // Create MarketPress order
238
+ $order_id = $mp->generate_order_id();
239
+ $payment_info['gateway_public_name'] = $this->public_name;
240
+ $payment_info['gateway_private_name'] = $this->admin_name;
241
+ $payment_info['status'][$timestamp] = __( 'Paid', 'mycred' );
242
+ $payment_info['total'] = $total;
243
+ $payment_info['currency'] = $settings['currency'];
244
+ $payment_info['method'] = __( 'myCRED', 'mycred' );
245
+ $payment_info['transaction_id'] = $order_id;
246
+ $paid = true;
247
+ $result = $mp->create_order( $order_id, $cart, $shipping_info, $payment_info, $paid );
248
+
249
+ $order = get_page_by_title( $result, 'OBJECT', 'mp_order' );
250
+ // Deduct cost
251
+ $this->mycred->add_creds(
252
+ 'marketpress_payment',
253
+ $user_id,
254
+ 0-$total,
255
+ $settings['gateways']['mycred']['log_template'],
256
+ $order->ID,
257
+ array( 'ref_type' => 'post' )
258
+ );
259
  }
260
 
261
  function order_confirmation( $order ) { }
282
  * Return any html you want to show on the confirmation screen after checkout. This
283
  * should be a payment details box and message.
284
  * @since 1.1
285
+ * @version 1.1
286
  */
287
  function order_confirmation_msg( $content, $order ) {
288
  global $mp;
294
  return $content . str_replace(
295
  'TOTAL',
296
  $mp->format_currency( $order->mp_payment_info['currency'], $order->mp_payment_info['total'] ),
297
+ $mycred->template_tags_user( $settings['gateways']['mycred']['confirmation'], false, wp_get_current_user() )
298
  );
299
  }
300
 
301
  /**
302
  * myCRED Gateway Settings
303
  * @since 1.1
304
+ * @version 1.1
305
  */
306
  function gateway_settings_box( $settings ) {
307
  global $mp;
327
 
328
  if ( !isset( $settings['gateways']['mycred']['confirmation'] ) )
329
  $settings['gateways']['mycred']['confirmation'] = 'TOTAL amount has been deducted from your account. Your current balance is: %balance_f%';
330
+
331
+ if ( !isset( $settings['gateways']['mycred']['lowfunds'] ) )
332
+ $settings['gateways']['mycred']['lowfunds'] = 'Insufficient funds. Please select another form of payment. Your current balance is: %balance_f%';
333
+
334
+ if ( !isset( $settings['gateways']['mycred']['visitors'] ) )
335
+ $settings['gateways']['mycred']['visitors'] = 'You must be logged in to pay with %_plural%. Please <a href="%login_url_here%">login</a>.';
336
 
337
  if ( !isset( $settings['gateways']['mycred']['email'] ) )
338
  $settings['gateways']['mycred']['email'] = $settings['email']['new_order_txt']; ?>
378
  </tr>
379
  <?php endif; ?>
380
 
381
+ <tr>
382
+ <th scope="row"><label for="mycred-lowfunds"><?php _e( 'Insufficient Funds', 'mycred' ); ?></label></th>
383
+ <td>
384
+ <span class="description"><?php _e( 'Message to show when the user can not use this gateway.', 'mycred' ); ?></span>
385
+ <p><input type="text" name="mp[gateways][mycred][lowfunds]" id="mycred-lowfunds" style="width: 100%;" value="<?php echo esc_attr( $settings['gateways']['mycred']['lowfunds'] ); ?>"><br />
386
+ <span class="description"><?php _e( 'Available template tags are: General.', 'mycred' ); ?></span></p>
387
+ </td>
388
+ </tr>
389
+ <tr>
390
+ <th scope="row"><label for="mycred-visitors"><?php _e( 'Visitors', 'mycred' ); ?></label></th>
391
+ <td>
392
+ <span class="description"><?php _e( 'Message to show to buyers that are not logged in.', 'mycred' ); ?></span>
393
+ <p><input type="text" name="mp[gateways][mycred][visitors]" id="mycred-visitors" style="width: 100%;" value="<?php echo esc_attr( $settings['gateways']['mycred']['visitors'] ); ?>"><br />
394
+ <span class="description"><?php _e( 'Available template tags are: General.', 'mycred' ); ?></span></p>
395
+ </td>
396
+ </tr>
397
  <tr>
398
  <th scope="row"><label for="mycred-instructions"><?php _e( 'User Instructions', 'mycred' ); ?></label></th>
399
  <td>
427
  /**
428
  * Filter Gateway Settings
429
  * @since 1.1
430
+ * @version 1.1
431
  */
432
  function process_gateway_settings( $settings ) {
433
  // Name (no html)
449
  else
450
  $settings['gateways']['mycred']['exchange'] = 1;
451
 
452
+ $settings['gateways']['mycred']['lowfunds'] = stripslashes( wp_filter_post_kses( $settings['gateways']['mycred']['lowfunds'] ) );
453
+ $settings['gateways']['mycred']['visitors'] = stripslashes( wp_filter_post_kses( $settings['gateways']['mycred']['visitors'] ) );
454
+ $settings['gateways']['mycred']['instructions'] = stripslashes( wp_filter_post_kses( $settings['gateways']['mycred']['instructions'] ) );
455
+ $settings['gateways']['mycred']['confirmation'] = stripslashes( wp_filter_post_kses( $settings['gateways']['mycred']['confirmation'] ) );
 
456
 
457
  // Email (no html)
458
  $settings['gateways']['mycred']['email'] = stripslashes( wp_filter_nohtml_kses( $settings['gateways']['mycred']['email'] ) );
addons/gateway/event-booking/mycred-eventespresso3.php ADDED
@@ -0,0 +1,513 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ if ( !defined( 'myCRED_VERSION' ) ) exit;
3
+ /**
4
+ * Event Espresso Payment Gateway
5
+ * @since 1.2
6
+ * @version 1.0
7
+ */
8
+ if ( !class_exists( 'myCRED_Espresso_Gateway' ) ) {
9
+ class myCRED_Espresso_Gateway {
10
+
11
+ public $label = '';
12
+ public $core = NULL;
13
+ public $prefs = array();
14
+ public $update = false;
15
+
16
+ /**
17
+ * Construct
18
+ */
19
+ function __construct() {
20
+ // Default settings
21
+ $defaults = array(
22
+ 'labels' => array(
23
+ 'gateway' => $this->label,
24
+ 'payment' => $this->label . ' ' . __( 'Payments', 'mycred' ),
25
+ 'button' => __( 'Pay Now', 'mycred' )
26
+ ),
27
+ 'rate' => 100,
28
+ 'log' => __( 'Payment for Event Registration', 'mycred' ),
29
+ 'messages' => array(
30
+ 'solvent' => 'Click "Pay Now" to pay using your %plural%.',
31
+ 'insolvent' => 'Unfortunately you do not have enough %plural% to pay for this event.',
32
+ 'visitors' => 'Payments using %_plural% is only available for registered members.'
33
+ )
34
+ );
35
+
36
+ // Settings
37
+ $settings = get_option( 'mycred_espresso_gateway_prefs' );
38
+ $this->prefs = mycred_apply_defaults( $defaults, $settings );
39
+
40
+ // Load myCRED
41
+ $this->core = mycred_get_settings();
42
+ }
43
+
44
+ /**
45
+ * Load Gateway
46
+ * Hook in on init and setup our gateway.
47
+ * @since 1.2
48
+ * @version 1.0
49
+ */
50
+ public function load() {
51
+ add_action( 'init', array( $this, 'gateway_setup' ) );
52
+
53
+ }
54
+
55
+ /**
56
+ * Gateway Active
57
+ * Checks to see if a given gateway is active.
58
+ * @since 1.2
59
+ * @version 1.0
60
+ */
61
+ public function gateway_active( $id = 'mycred' ) {
62
+ global $active_gateways;
63
+
64
+ if ( !isset( $active_gateways ) || !is_array( $active_gateways ) )
65
+ $active_gateways = get_option( 'event_espresso_active_gateways', array() );
66
+
67
+ if ( array_key_exists( $id, $active_gateways ) ) return true;
68
+ return false;
69
+ }
70
+
71
+ /**
72
+ * Gateway Setup
73
+ * @since 1.2
74
+ * @version 1.0
75
+ */
76
+ public function gateway_setup() {
77
+ // Capture Settings Update
78
+ if ( isset( $_REQUEST['mycred-gateway-action'] ) && isset( $_REQUEST['mycred-gateway-token'] ) ) {
79
+ $this->update_settings();
80
+ }
81
+
82
+ add_filter( 'action_hook_espresso_gateway_formal_name', array( $this, 'formal_name' ) );
83
+ add_filter( 'action_hook_espresso_gateway_payment_type', array( $this, 'paymenttype_name' ) );
84
+ add_action( 'action_hook_espresso_display_gateway_settings', array( $this, 'gateway_settings_page' ), 11 );
85
+
86
+ // Make sure gateway is enabled
87
+ if ( $this->gateway_active() ) {
88
+ // Hook into Payment Page
89
+ add_action( 'action_hook_espresso_display_onsite_payment_gateway', array( $this, 'payment_page' ) );
90
+
91
+ // Capture myCRED Payment Requests
92
+ if ( $this->is_payment() ) {
93
+ add_filter( 'filter_hook_espresso_transactions_get_attendee_id', array( $this, 'set_attendee_id' ) );
94
+ add_filter( 'filter_hook_espresso_thank_you_get_payment_data', array( $this, 'process_payment' ) );
95
+ }
96
+
97
+ add_action( 'action_hook_espresso_display_onsite_payment_header', 'espresso_display_onsite_payment_header' );
98
+ add_action( 'action_hook_espresso_display_onsite_payment_footer', 'espresso_display_onsite_payment_footer' );
99
+ }
100
+ }
101
+
102
+ /**
103
+ * Is Payment Request?
104
+ * @since 1.2
105
+ * @version 1.0
106
+ */
107
+ public function is_payment() {
108
+ if (
109
+ ( isset( $_REQUEST['payment_type'] ) && $_REQUEST['payment_type'] == 'mycred' ) &&
110
+ ( isset( $_REQUEST['token'] ) && wp_verify_nonce( $_REQUEST['token'], 'pay-with-mycred' ) ) ) return true;
111
+
112
+ return false;
113
+ }
114
+
115
+ /**
116
+ * Formal Name
117
+ * @since 1.2
118
+ * @version 1.0
119
+ */
120
+ public function formal_name( $gateway_formal_names ) {
121
+ $gateway_formal_names['mycred'] = $this->prefs['labels']['gateway'];
122
+ return $gateway_formal_names;
123
+ }
124
+
125
+ /**
126
+ * Payment Type
127
+ * @since 1.2
128
+ * @version 1.0
129
+ */
130
+ public function paymenttype_name( $gateway_payment_types ) {
131
+ $gateway_payment_types['mycred'] = $this->prefs['labels']['payment'];
132
+ return $gateway_payment_types;
133
+ }
134
+
135
+ /**
136
+ * Set Attendee ID
137
+ * @since 1.2
138
+ * @version 1.0
139
+ */
140
+ public function set_attendee_id( $attendee_id ) {
141
+ if ( isset( $_REQUEST['id'] ) )
142
+ $attendee_id = $_REQUEST['id'];
143
+
144
+ return $attendee_id;
145
+ }
146
+
147
+ /**
148
+ * Process Payment
149
+ * @since 1.2
150
+ * @version 1.0
151
+ */
152
+ public function process_payment( $payment_data ) {
153
+ if ( !is_user_logged_in() ) return $payment_data;
154
+
155
+ // Security
156
+ if ( !isset( $_REQUEST['token'] ) || !wp_verify_nonce( $_REQUEST['token'], 'pay-with-mycred' ) ) return $payment_data;
157
+
158
+ // Let others play
159
+ do_action( 'mycred_espresso_process', $payment_data, $this->prefs, $this->core );
160
+
161
+ // Check if this event does not accept myCRED payments
162
+ if ( isset( $event_meta['mycred_no_sale'] ) ) return;
163
+
164
+ $user_id = get_current_user_id();
165
+
166
+ // Make sure this is unique
167
+ if ( $this->core->has_entry( 'event_payment', $payment_data['event_id'], $user_id, $payment_data['registration_id'] ) ) return $payment_data;
168
+
169
+ $balance = $this->core->get_users_cred( $user_id );
170
+ $event_cost = $this->prefs['rate']*$payment_data['total_cost'];
171
+ $after_purchase = $balance-$event_cost;
172
+
173
+ // This should never happen
174
+ if ( $after_purchase < 0 ) return $payment_data;
175
+
176
+ $entry = $this->prefs['log'];
177
+
178
+ // Deduct
179
+ $this->core->add_creds(
180
+ 'event_payment',
181
+ $user_id,
182
+ 0-$event_cost,
183
+ $entry,
184
+ $payment_data['event_id'],
185
+ $payment_data['registration_id']
186
+ );
187
+
188
+ // Update Payment Data
189
+ $payment_data['payment_status'] = 'Completed';
190
+ $payment_data['txn_type'] = $this->prefs['labels']['payment'];
191
+ $payment_data['txn_id'] = $payment_data['attendee_session'];
192
+ $payment_data['txn_details'] = $this->core->template_tags_general( $entry );
193
+
194
+ // Let others play
195
+ do_action( 'mycred_espresso_processed', $payment_data, $this->prefs, $this->core );
196
+
197
+ return $payment_data;
198
+ }
199
+
200
+ /**
201
+ * Payment Page
202
+ * @since 1.2
203
+ * @version 1.0
204
+ */
205
+ public function payment_page( $payment_data ) {
206
+ extract( $payment_data );
207
+
208
+ // Check if this event does not accept myCRED payments
209
+ if ( isset( $event_meta['mycred_no_sale'] ) ) return;
210
+
211
+ global $org_options;
212
+
213
+ $member = $solvent = $user_id = false;
214
+ if ( is_user_logged_in() ) {
215
+ $member = true;
216
+ $user_id = get_current_user_id();
217
+ $balance = $this->core->get_users_cred( $user_id );
218
+
219
+ // Calculate Cost
220
+ $event_cost = $this->prefs['rate']*$event_cost;
221
+ $after_purchase = $balance-$event_cost;
222
+
223
+ if ( $after_purchase >= 0 )
224
+ $solvent = true;
225
+
226
+ $args = array(
227
+ 'page_id' => $org_options['return_url'],
228
+ 'r_id' => $registration_id,
229
+ 'id' => $attendee_id,
230
+ 'payment_type' => 'mycred',
231
+ 'token' => wp_create_nonce( 'pay-with-mycred' )
232
+ );
233
+ $finalize_link = add_query_arg( $args, home_url() );
234
+ } ?>
235
+
236
+ <div id="mycred-payment-option-dv" class="payment-option-dv">
237
+ <a id="mycred-payment-option-lnk" class="payment-option-lnk algn-vrt display-the-hidden" rel="mycred-payment-option-form" style="display: table-cell">
238
+ <div class="vrt-cell">
239
+ <div><?php echo $this->prefs['labels']['gateway']; ?></div>
240
+ </div>
241
+ </a><br/>
242
+ <div id="mycred-payment-option-form-dv" class="hide-if-js">
243
+ <?php if ( $member && $solvent ) : ?>
244
+ <?php if ( trim( $this->prefs['messages']['solvent'] ) != '' ) : ?>
245
+
246
+ <p><?php echo $this->core->template_tags_general( $this->prefs['messages']['solvent'] ); ?></p>
247
+ <?php endif; ?>
248
+
249
+ <div class="event-display-boxes">
250
+ <pre><?php print_r( get_option( 'mycred_espresso_test' ) ); ?></pre>
251
+ <h4 id="mycred_title" class="payment_type_title section-heading"><?php echo $this->prefs['labels']['payment']; ?></h4>
252
+ <table style="width:100%;">
253
+ <tr>
254
+ <td class="info"><?php _e( 'Current Balance', 'mycred' ); ?></td>
255
+ <td class="amount"><?php echo $this->core->format_creds( $balance ); ?></td>
256
+ </tr>
257
+ <tr>
258
+ <td class="info"><?php _e( 'Total Cost', 'mycred' ); ?></td>
259
+ <td class="amount"><?php echo $this->core->format_creds( $event_cost ); ?></td>
260
+ </tr>
261
+ <tr>
262
+ <td class="info"><?php _e( 'Balance After Purchase', 'mycred' ); ?></td>
263
+ <td class="amount"><?php echo $this->core->format_creds( $after_purchase ); ?></td>
264
+ </tr>
265
+ </table>
266
+ <p><a href="<?php echo $finalize_link; ?>" class="button button-large button-primary" style="float:right;"><?php echo $this->prefs['labels']['button']; ?></a></p>
267
+ </div>
268
+ <?php elseif ( $member && !$solvent ) : ?>
269
+
270
+ <div class="event_espresso_attention event-messages ui-state-highlight">
271
+ <span class="ui-icon ui-icon-alert"></span>
272
+ <p><?php echo $this->core->template_tags_general( $this->prefs['messages']['insolvent'] ); ?></p>
273
+ </div>
274
+ <div class="event-display-boxes">
275
+ <h4 id="mycred_title" class="payment_type_title section-heading"><?php echo $this->prefs['labels']['payment']; ?></h4>
276
+ <table style="width:100%;">
277
+ <tr class="current">
278
+ <td class="info"><?php _e( 'Current Balance', 'mycred' ); ?></td>
279
+ <td class="amount"><?php echo $this->core->format_creds( $balance ); ?></td>
280
+ </tr>
281
+ <tr class="cost">
282
+ <td class="info"><?php _e( 'Total Cost', 'mycred' ); ?></td>
283
+ <td class="amount"><?php echo $this->core->format_creds( $event_cost ); ?></td>
284
+ </tr>
285
+ <tr class="after-purchase">
286
+ <td class="info"><?php _e( 'Balance After Purchase', 'mycred' ); ?></td>
287
+ <td class="amount" style="color:red;"><?php echo $this->core->format_creds( $after_purchase ); ?></td>
288
+ </tr>
289
+ </table>
290
+ </div>
291
+ <?php else : ?>
292
+
293
+ <div class="event_espresso_attention event-messages ui-state-highlight">
294
+ <span class="ui-icon ui-icon-alert"></span>
295
+ <p><?php echo $this->core->template_tags_general( $this->prefs['messages']['visitors'] ); ?></p>
296
+ </div>
297
+ <?php endif; ?>
298
+
299
+ </div>
300
+ </div>
301
+ <?php
302
+ }
303
+
304
+ /**
305
+ * Gateway Settings Page
306
+ * @since 1.2
307
+ * @version 1.0
308
+ */
309
+ public function gateway_settings_page( ) {
310
+ global $espresso_premium, $active_gateways, $org_options;
311
+ if ( !$espresso_premium )
312
+ return;
313
+
314
+ // activate
315
+ if ( !empty( $_REQUEST['activate_mycred_payment'] ) ) {
316
+ $active_gateways['mycred'] = myCRED_GATE_CART_DIR . 'mycred-eventespresso3.php';
317
+ update_option( 'event_espresso_active_gateways', $active_gateways );
318
+ }
319
+ $activate_url = admin_url( 'admin.php?page=payment_gateways&activate_mycred_payment=true' );
320
+ $activate_text = sprintf( __( 'Activate %s', 'mycred' ), $this->label );
321
+
322
+ // deactivate
323
+ if ( !empty( $_REQUEST['deactivate_check_payment'] ) ) {
324
+ unset( $active_gateways['mycred'] );
325
+ update_option( 'event_espresso_active_gateways', $active_gateways );
326
+ }
327
+ $deactivate_url = admin_url( 'admin.php?page=payment_gateways&deactivate_mycred_payment=true' );
328
+ $deactivate_text = sprintf( __( 'Deactivate %s', 'mycred' ), $this->label );
329
+
330
+ //Open or close the postbox div
331
+ if ( empty( $_REQUEST['deactivate_mycred_payment'] )
332
+ && ( !empty( $_REQUEST['deactivate_mycred_payment'] )
333
+ || array_key_exists( 'mycred', $active_gateways ) ) ) {
334
+ $postbox_style = '';
335
+ } else {
336
+ $postbox_style = 'closed';
337
+ } ?>
338
+
339
+ <p id="mycred-gate">&nbsp;</p>
340
+ <div class="metabox-holder">
341
+ <div class="postbox <?php echo $postbox_style; ?>" style="background-image: url(http://mycred.me/wp-content/uploads/login-bg.png); background-position: center bottom; background-repeat: no-repeat; background-size: contain;">
342
+ <div title="Click to toggle" class="handlediv"><br /></div>
343
+ <h3 class="hndle">
344
+ <?php echo $this->label . ' ' . __( 'Gateway Settings', 'mycred' ); ?>
345
+ </h3>
346
+ <div class="inside">
347
+ <div class="padding">
348
+ <ul>
349
+ <?php if ( array_key_exists( 'mycred', $active_gateways ) ) {
350
+ echo '<li id="deactivate_check" style="width:30%;" onclick="location.href=\'' . $deactivate_url . '\';" class="red_alert pointer"><strong>' . $deactivate_text . '</strong></li>';
351
+
352
+ $this->gateway_settings();
353
+ }
354
+ else {
355
+ echo '<li id="activate_check" style="width:30%;" onclick="location.href=\'' . $activate_url . '\';" class="green_alert pointer"><strong>' . $activate_text . '</strong></li>';
356
+ }
357
+ echo '</ul>'; ?>
358
+
359
+ </div>
360
+ </div>
361
+ </div>
362
+ </div>
363
+ <?php
364
+ }
365
+
366
+ /**
367
+ * Gateway Settings
368
+ * Included first when the gateway is activated.
369
+ * @since 1.2
370
+ * @version 1.0
371
+ */
372
+ public function gateway_settings() {
373
+ global $org_options;
374
+
375
+ $exchange_message = sprintf(
376
+ __( 'How many %s is 1 %s worth?', 'mycred' ),
377
+ $this->core->plural(),
378
+ $org_options['currency_symbol']
379
+ ); ?>
380
+
381
+ <?php if ( $this->update ) : ?>
382
+ <h2 style="color: green;"><?php _e( 'Gateways Settings Successfully Updated', 'mycred' ); ?></h2>
383
+ <?php endif; ?>
384
+ <form method="post" action="<?php echo $_SERVER['REQUEST_URI'] ?>#mycred-gate">
385
+ <?php do_action( 'mycred_espresso_before_prefs' ); ?>
386
+
387
+ <table width="99%" border="0" cellspacing="5" cellpadding="5">
388
+ <tr>
389
+ <td valign="top">
390
+ <h4><?php _e( 'Labels', 'mycred' ); ?></h4>
391
+ <ul>
392
+ <li>
393
+ <label for="mycred-prefs-gateway-labels"><?php _e( 'Gateway Title', 'mycred' ); ?></label>
394
+ <input type="text" name="mycred_prefs[labels][gateway]" id="mycred-prefs-gateway-labels" size="30" value="<?php echo $this->prefs['labels']['gateway']; ?>" /><br />
395
+ <span class="description"><?php _e( 'Title to show on Payment page', 'mycred' ); ?>.</span>
396
+ </li>
397
+ <li>
398
+ <label for="mycred-prefs-payment-labels"><?php _e( 'Payment Type', 'mycred' ); ?></label>
399
+ <input type="text" name="mycred_prefs[labels][payment]" id="mycred-prefs-payment-labels" size="30" value="<?php echo $this->prefs['labels']['payment']; ?>" /><br />
400
+ <span class="description"><?php _e( 'Title to show on receipts and logs', 'mycred' ); ?>.</span>
401
+ </li>
402
+ <li>
403
+ <label for="mycred-prefs-button-labels"><?php _e( 'Button Label', 'mycred' ); ?></label>
404
+ <input type="text" name="mycred_prefs[labels][button]" id="mycred-prefs-button-labels" size="30" value="<?php echo $this->prefs['labels']['button']; ?>" /><br />
405
+ <span class="description"><?php _e( 'Pay Button', 'mycred' ); ?></span>
406
+ </li>
407
+ </ul>
408
+ <h4><?php _e( 'Price', 'mycred' ); ?></h4>
409
+ <ul>
410
+ <li id="mycred-event-exchange-box">
411
+ <label for="mycred-prefs-price-x-rate"><?php _e( 'Exchange Rate', 'mycred' ); ?></label>
412
+ <input type="text" name="mycred_prefs[rate]" id="mycred-prefs-price-x-rate" size="30" value="<?php echo $this->prefs['rate']; ?>" /><br />
413
+ <span class="description"><?php echo $exchange_message; ?></span>
414
+ </li>
415
+ <li>
416
+ <p><strong><?php _e( 'Important!', 'mycred' ); ?></strong></p>
417
+ <ol>
418
+ <li><?php _e( 'You can disable purchases using this gateway by adding a custom Event Meta: <code>mycred_no_sale</code>', 'mycred' ); ?></li>
419
+ <li><?php _e( 'Users must be logged in to use this gateway!', 'mycred' ); ?></li>
420
+ </ol>
421
+ </li>
422
+ </ul>
423
+ <h4><?php _e( 'Log', 'mycred' ); ?></h4>
424
+ <ul>
425
+ <li>
426
+ <label for="mycred-prefs-log"><?php _e( 'Log Entry', 'mycred' ); ?></label>
427
+ <input type="text" name="mycred_prefs[log]" id="mycred-prefs-log" size="30" value="<?php echo $this->prefs['log']; ?>" /><br />
428
+ <span class="description"><?php _e( 'Available template tags: General', 'mycred' ); ?></span>
429
+ </li>
430
+ </ul>
431
+ </td>
432
+ <td valign="top">
433
+ <h4><?php _e( 'Templates', 'mycred' ); ?></h4>
434
+ <ul>
435
+ <li>
436
+ <label for="mycred-prefs-message-solvent"><?php _e( 'Solvent users', 'mycred' ); ?></label>
437
+ <textarea name="mycred_prefs[messages][solvent]" id="mycred-prefs-message-solvent" style="width: 90%; max-width: 90%; min-height: 90px;"><?php echo stripslashes( $this->prefs['messages']['solvent'] ); ?></textarea><br />
438
+ <span class="description"><?php _e( 'Message to show users on the payment page before they are charged. Leave empty to hide.<br />Available template tags: General', 'mycred' ); ?></span>
439
+ </li>
440
+ <li>
441
+ <label for="mycred-prefs-message-insolvent"><?php _e( 'Insolvent users', 'mycred' ); ?></label>
442
+ <textarea name="mycred_prefs[messages][insolvent]" id="mycred-prefs-message-solvent" style="width: 90%; max-width: 90%; min-height: 90px;"><?php echo stripslashes( $this->prefs['messages']['insolvent'] ); ?></textarea><br />
443
+ <span class="description"><?php _e( 'Message to show users who do not have enough points to pay.<br />Available template tags: General', 'mycred' ); ?></span>
444
+ </li>
445
+ <li>
446
+ <label for="mycred-prefs-message-insolvent"><?php _e( 'Visitors', 'mycred' ); ?></label>
447
+ <textarea name="mycred_prefs[messages][visitors]" id="mycred-prefs-message-visitors" style="width: 90%; max-width: 90%; min-height: 90px;"><?php echo stripslashes( $this->prefs['messages']['visitors'] ); ?></textarea><br />
448
+ <span class="description"><?php _e( 'Message to show visitors (users not logged in) on the payment page.<br />Available template tags: General', 'mycred' ); ?></span>
449
+ </li>
450
+ </ul>
451
+ </td>
452
+ </tr>
453
+ </table>
454
+ <?php do_action( 'mycred_espresso_after_prefs' ); ?>
455
+
456
+ <input type="hidden" name="mycred-gateway-action" value="update-settings" />
457
+ <input type="hidden" name="mycred-gateway-token" value="<?php echo wp_create_nonce( 'mycred-espresso-update' ); ?>" />
458
+ <p><input class="button-primary" type="submit" name="Submit" value="<?php _e( 'Update Settings', 'mycred' ); ?>" /></p>
459
+ </form>
460
+ <?php
461
+ }
462
+
463
+ /**
464
+ * Update Settings
465
+ * @since 1.2
466
+ * @version 1.0
467
+ */
468
+ public function update_settings() {
469
+ // Apply Whitelabeling
470
+ $this->label = apply_filters( 'mycred_label', myCRED_NAME );
471
+
472
+ // Security
473
+ if ( !wp_verify_nonce( $_REQUEST['mycred-gateway-token'], 'mycred-espresso-update' ) ) return;
474
+ if ( !$this->core->can_edit_plugin() ) return;
475
+
476
+ // Prep
477
+ $new_settings = array();
478
+ $post = $_POST['mycred_prefs'];
479
+ if ( !is_array( $post ) || empty( $post ) ) return;
480
+
481
+ // Labels
482
+ $new_settings['labels']['gateway'] = strip_tags( $post['labels']['gateway'], '<strong><em><span>' );
483
+ $new_settings['labels']['payment'] = strip_tags( $post['labels']['payment'], '<strong><em><span>' );
484
+ $new_settings['labels']['button'] = sanitize_text_field( $post['labels']['button'] );
485
+
486
+ // Exchange Rate
487
+ $new_settings['rate'] = sanitize_text_field( $post['rate'] );
488
+
489
+ // Log
490
+ $new_settings['log'] = sanitize_text_field( $post['log'] );
491
+
492
+ // Messages
493
+ $new_settings['messages']['solvent'] = sanitize_text_field( stripslashes( $post['messages']['solvent'] ) );
494
+ $new_settings['messages']['insolvent'] = sanitize_text_field( stripslashes( $post['messages']['insolvent'] ) );
495
+ $new_settings['messages']['visitors'] = sanitize_text_field( stripslashes( $post['messages']['visitors'] ) );
496
+
497
+ // Let others play
498
+ $new_settings = apply_filters( 'mycred_espresso_save_pref', $new_settings );
499
+
500
+ // Save new settings
501
+ $current = $this->prefs;
502
+ $this->prefs = mycred_apply_defaults( $current, $new_settings );
503
+ update_option( 'mycred_espresso_gateway_prefs', $this->prefs );
504
+
505
+ // Flag update
506
+ $this->update = true;
507
+ }
508
+ }
509
+
510
+ $gateway = new myCRED_Espresso_Gateway();
511
+ $gateway->load();
512
+ }
513
+ ?>
addons/gateway/event-booking/mycred-eventsmanager.php ADDED
@@ -0,0 +1,639 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ if ( !defined( 'myCRED_VERSION' ) ) exit;
3
+ /**
4
+ * Events Manager
5
+ * @since 1.2
6
+ * @version 1.0
7
+ */
8
+ if ( !class_exists( 'myCRED_Events_Manager_Gateway' ) && defined( 'EM_VERSION' ) ) {
9
+ class myCRED_Events_Manager_Gateway {
10
+
11
+ public $label = '';
12
+ public $prefs;
13
+ public $core;
14
+ public $booking_cols = 0;
15
+
16
+ /**
17
+ * Construct
18
+ */
19
+ function __construct() {
20
+ // Default settings
21
+ $defaults = array(
22
+ 'setup' => 'off',
23
+ 'rate' => 100,
24
+ 'log' => array(
25
+ 'purchase' => __( 'Payment for tickets to %link_with_title%', 'mycred' ),
26
+ 'refund' => __( 'Ticket refund for %link_with_title%', 'mycred' )
27
+ ),
28
+ 'refund' => 0,
29
+ 'labels' => array(
30
+ 'header' => __( 'Pay using your %_plural% balance', 'mycred' ),
31
+ 'button' => __( 'Pay Now', 'mycred' ),
32
+ 'link' => __( 'Pay', 'mycred' )
33
+ ),
34
+ 'messages' => array(
35
+ 'success' => __( 'Thank you for your payment!', 'mycred' ),
36
+ 'error' => __( "I'm sorry but you can not pay for these tickets using %_plural%", 'mycred' )
37
+ )
38
+ );
39
+
40
+ // Settings
41
+ $settings = get_option( 'mycred_eventsmanager_gateway_prefs' );
42
+ $this->prefs = mycred_apply_defaults( $defaults, $settings );
43
+
44
+ // Load myCRED
45
+ $this->core = mycred_get_settings();
46
+
47
+ // Apply Whitelabeling
48
+ $this->label = apply_filters( 'mycred_label', myCRED_NAME );
49
+ }
50
+
51
+ /**
52
+ * Load Gateway
53
+ * @since 1.2
54
+ * @version 1.0
55
+ */
56
+ public function load() {
57
+ // Settings
58
+ add_action( 'em_options_page_footer_bookings', array( $this, 'settings_page' ) );
59
+ add_action( 'em_options_save', array( $this, 'save_settings' ) );
60
+
61
+ // In case gateway has not yet been enabled bail here.
62
+ if ( !$this->use_gateway() ) return;
63
+
64
+ // Currency
65
+ add_filter( 'em_get_currencies', array( $this, 'add_currency' ) );
66
+ if ( $this->single_currency() )
67
+ add_filter( 'em_get_currency_formatted', array( $this, 'format_price' ), 10, 4 );
68
+
69
+ // Adjust Ticket Columns
70
+ add_filter( 'em_booking_form_tickets_cols', array( $this, 'ticket_columns' ), 10, 2 );
71
+ add_action( 'em_booking_form_tickets_col_mycred', array( $this, 'ticket_col' ), 10, 2 );
72
+
73
+ // Add Pay Button
74
+ add_filter( 'em_my_bookings_booking_actions', array( $this, 'add_pay_button' ), 10, 2 );
75
+ add_action( 'em_my_bookings_booking_loop', array( $this, 'payment_box' ) );
76
+ add_action( 'em_template_my_bookings_footer', array( $this, 'insert_scripting' ) );
77
+
78
+ // Ajax Payments
79
+ add_action( 'wp_ajax_mycred-pay-em-booking', array( $this, 'process_payment' ) );
80
+ if ( $this->prefs['refund'] != 0 )
81
+ add_filter( 'em_booking_set_status', array( $this, 'refunds' ), 10, 2 );
82
+ }
83
+
84
+ /**
85
+ * Add Currency
86
+ * Adds "Points" as a form of currency
87
+ * @since 1.2
88
+ * @version 1.0
89
+ */
90
+ public function add_currency( $currencies ) {
91
+ $currencies->names['XMY'] = $this->core->plural();
92
+ if ( empty( $this->core->before ) && !empty( $this->core->after ) ) {
93
+ $currencies->symbols['XMY'] = $this->core->after;
94
+ $currencies->symbols['XMY'] = $this->core->after;
95
+ }
96
+ elseif ( !empty( $this->core->before ) && empty( $this->core->after ) ) {
97
+ $currencies->true_symbols['XMY'] = $this->core->before;
98
+ $currencies->true_symbols['XMY'] = $this->core->after;
99
+ }
100
+
101
+ return $currencies;
102
+ }
103
+
104
+ /**
105
+ * Format Price
106
+ * @since 1.2
107
+ * @version 1.0
108
+ */
109
+ public function format_price( $formatted_price, $price, $currency, $format ) {
110
+ return $this->core->format_creds( $price );
111
+ }
112
+
113
+ /**
114
+ * Use Gateway
115
+ * Checks if this gateway has been enabled.
116
+ * @since 1.2
117
+ * @version 1.0
118
+ */
119
+ public function use_gateway() {
120
+ if ( $this->prefs['setup'] == 'off' ) return false;
121
+ return true;
122
+ }
123
+
124
+ /**
125
+ * Check if using Single Currency
126
+ * @since 1.2
127
+ * @version 1.0
128
+ */
129
+ public function single_currency() {
130
+ if ( $this->prefs['setup'] == 'single' ) return true;
131
+ return false;
132
+ }
133
+
134
+ /**
135
+ * Can Pay Check
136
+ * Checks if the user can pay for their booking.
137
+ * @since 1.2
138
+ * @version 1.0
139
+ */
140
+ public function can_pay( $EM_Booking ) {
141
+ $EM_Event = $EM_Booking->get_event();
142
+ // You cant pay for free events
143
+ if ( $EM_Event->is_free() ) return false;
144
+
145
+ // Only pending events can be paid for
146
+ if ( $EM_Booking->booking_status == 0 && get_option( 'dbem_bookings_user_cancellation' ) && $EM_Event->get_bookings()->has_open_time() ) {
147
+ $balance = $this->core->get_users_cred( $EM_Booking->person->ID );
148
+ if ( $balance <= 0 ) return false;
149
+
150
+ $price = $this->core->number( $EM_Booking->booking_price );
151
+ if ( $price == 0 ) return true;
152
+ if ( !$this->single_currency() ) {
153
+ $exchange_rate = $this->prefs['rate'];
154
+ $price = $this->core->number( $exchange_rate*$price );
155
+ }
156
+
157
+ if ( $balance-$price < 0 ) return false;
158
+
159
+ return true;
160
+ }
161
+ return false;
162
+ }
163
+
164
+ /**
165
+ * Has Paid
166
+ * Checks if the user has paid for booking
167
+ * @since 1.2
168
+ * @version 1.0
169
+ */
170
+ public function has_paid( $EM_Booking ) {
171
+ if ( $this->core->has_entry( 'ticket_purchase', $EM_Booking->event->post_id, $EM_Booking->person->ID, 's:3:"bid";i:' . $EM_Booking->booking_id . ';' ) ) return true;
172
+ return false;
173
+ }
174
+
175
+ /**
176
+ * AJAX: Process Payment
177
+ * @since 1.2
178
+ * @version 1.0
179
+ */
180
+ public function process_payment() {
181
+ // Security
182
+ //check_ajax_referer( 'mycred-pay-em-booking', 'token' );
183
+
184
+ // Requirements
185
+ if ( !isset( $_POST['booking_id'] ) || !is_user_logged_in() ) die( 'ERROR_1' );
186
+
187
+ // Get Booking
188
+ $booking_id = $_POST['booking_id'];
189
+ $booking = em_get_booking( $booking_id );
190
+
191
+ // User
192
+ if ( $this->core->exclude_user( $booking->person->ID ) ) die( 'ERROR_2' );
193
+
194
+ // User can not pay for this
195
+ if ( !$this->can_pay( $booking ) ) {
196
+ $message = $this->prefs['messages']['error'];
197
+ $status = 'ERROR';
198
+
199
+ // Let others play
200
+ do_action( 'mycred_em_booking_cantpay', $booking, $this );
201
+ }
202
+ // User has not yet paid
203
+ elseif ( !$this->has_paid( $booking ) ) {
204
+ // Price
205
+ $price = $this->core->number( $booking->booking_price );
206
+ if ( !$this->single_currency() ) {
207
+ $exchange_rate = $this->prefs['rate'];
208
+ $price = $this->core->number( $exchange_rate*$price );
209
+ }
210
+
211
+ // Charge
212
+ $this->core->add_creds(
213
+ 'ticket_purchase',
214
+ $booking->person->ID,
215
+ 0-$price,
216
+ $this->prefs['log']['purchase'],
217
+ $booking->event->post_id,
218
+ array( 'ref_type' => 'post', 'bid' => $booking_id )
219
+ );
220
+
221
+ // Update Booking if approval is required (with option to disable this feature)
222
+ if ( get_option( 'dbem_bookings_approval' ) == 1 && apply_filters( 'mycred_em_approve_on_pay', true, $booking, $this ) )
223
+ $booking->approve();
224
+
225
+ $message = $this->prefs['messages']['success'];
226
+ $status = 'OK';
227
+
228
+ // Let others play
229
+ do_action( 'mycred_em_booking_paid', $booking, $this );
230
+ }
231
+ else {
232
+ $message = '';
233
+ $status = '';
234
+ }
235
+
236
+ die( json_encode( array( 'status' => $status, 'message' => $message ) ) );
237
+ }
238
+
239
+ /**
240
+ * Refunds
241
+ * @since 1.2
242
+ * @version 1.0
243
+ */
244
+ public function refunds( $result, $EM_Booking ) {
245
+ // Cancellation
246
+ if ( $EM_Booking->booking_status == 3 && $EM_Booking->previous_status != 3 ) {
247
+ $refund = $this->prefs['refund'];
248
+
249
+ // Make sure user has paid for this to refund
250
+ if ( $this->has_paid( $EM_Booking ) ) {
251
+ // Price
252
+ $price = $EM_Booking->booking_price;
253
+ if ( $this->single_currency() )
254
+ $price = $this->core->number( $price );
255
+ else {
256
+ $exchange_rate = $this->prefs['rate'];
257
+ $price = $this->core->number( $exchange_rate*$price );
258
+ }
259
+
260
+ $event_id = $EM_Booking->get_event();
261
+
262
+ // Charge
263
+ $this->core->add_creds(
264
+ 'ticket_purchase_refund',
265
+ $EM_Booking->person->ID,
266
+ $price,
267
+ $this->prefs['log']['refund'],
268
+ $EM_Booking->event->post_id,
269
+ array( 'ref_type' => 'post', 'bid' => $booking_id )
270
+ );
271
+ }
272
+ }
273
+ return $result;
274
+ }
275
+
276
+ /**
277
+ * Adjust Ticket Columns
278
+ * @since 1.2
279
+ * @version 1.0
280
+ */
281
+ public function ticket_columns( $columns, $EM_Event ) {
282
+ if ( !$EM_Event->is_free() ) {
283
+ unset( $columns['price'] );
284
+ unset( $columns['type'] );
285
+ unset( $columns['spaces'] );
286
+
287
+ $columns['type'] = __( 'Ticket Type', 'mycred' );
288
+
289
+ if ( $this->single_currency() ) {
290
+ $columns['mycred'] = __( 'Price', 'mycred' );
291
+ }
292
+ else {
293
+ $columns['price'] = __( 'Price', 'mycred' );
294
+ $columns['mycred'] = $this->core->plural();
295
+ }
296
+ $columns['spaces'] = __( 'Spaces', 'mycred' );
297
+ }
298
+
299
+ $this->booking_cols = count( $columns );
300
+ return $columns;
301
+ }
302
+
303
+ /**
304
+ * Adjust Ticket Column Content
305
+ * @since 1.2
306
+ * @version 1.0
307
+ */
308
+ public function ticket_col( $EM_Ticket, $EM_Event ) {
309
+ if ( $this->single_currency() )
310
+ $price = $EM_Ticket->get_price(true);
311
+ else
312
+ $price = $this->prefs['rate']*$EM_Ticket->get_price(true); ?>
313
+
314
+ <td class="em-bookings-ticket-table-points"><?php echo $this->core->format_creds( $price ); ?></td>
315
+ <?php
316
+ }
317
+
318
+ /**
319
+ * Add Pay Action
320
+ * @since 1.2
321
+ * @version 1.0
322
+ */
323
+ public function add_pay_button( $cancel_link, $EM_Booking ) {
324
+ if ( $this->can_pay( $EM_Booking ) && !$this->has_paid( $EM_Booking ) ) {
325
+ if ( !empty( $cancel_link ) )
326
+ $cancel_link .= ' &bull; ';
327
+
328
+ $cancel_link .= '<a href="javascript:void(0)" class="mycred-show-pay" data-booking="' . $EM_Booking->booking_id . '">' . $this->prefs['labels']['link'] . '</a>';
329
+ }
330
+ return $cancel_link;
331
+ }
332
+
333
+ /**
334
+ * Payment Box
335
+ * @since 1.2
336
+ * @version 1.0
337
+ */
338
+ public function payment_box( $EM_Booking ) {
339
+ if ( $EM_Booking->booking_status == 0 ) {
340
+ $balance = $this->core->get_users_cred( $EM_Booking->person->ID );
341
+ if ( $balance <= 0 ) return;
342
+
343
+ $price = $EM_Booking->booking_price;
344
+ if ( $price == 0 ) return;
345
+ if ( !$this->single_currency() ) {
346
+ $exchange_rate = $this->prefs['rate'];
347
+ $price = $this->core->number( $exchange_rate*$price );
348
+ } ?>
349
+
350
+ <tr id="mycred-payment-<?php echo $EM_Booking->booking_id; ?>" style="display: none;">
351
+ <td colspan="5">
352
+ <h5><?php echo $this->core->template_tags_general( $this->prefs['labels']['header'] ); ?></h5>
353
+ <?php do_action( 'mycred_em_before_payment_box', $this ); ?>
354
+
355
+ <table style="width:100%;margin-bottom: 0;">
356
+ <tr>
357
+ <td class="info"><?php _e( 'Current Balance', 'mycred' ); ?></td>
358
+ <td class="amount"><?php echo $this->core->format_creds( $balance ); ?></td>
359
+ </tr>
360
+ <tr>
361
+ <td class="info"><?php _e( 'Total Cost', 'mycred' ); ?></td>
362
+ <td class="amount"><?php echo $this->core->format_creds( $price ); ?></td>
363
+ </tr>
364
+ <tr>
365
+ <td class="info"><?php _e( 'Balance After Payment', 'mycred' ); ?></td>
366
+ <td class="amount"><?php echo $this->core->format_creds( $balance-$price ); ?></td>
367
+ </tr>
368
+ <tr>
369
+ <td colspan="2" class="action" style="text-align: right;">
370
+ <input type="hidden" name="mycred-booking-<?php echo $EM_Booking->booking_id; ?>" value="<?php echo $EM_Booking->booking_id; ?>" />
371
+ <input type="hidden" name="mycred-booking-<?php echo $EM_Booking->booking_id; ?>-token" value="<?php echo wp_create_nonce( 'mycred-pay-booking' ); ?>" />
372
+ <input type="button" class="button button-primary button-medium mycred-pay" value="<?php echo $this->prefs['labels']['button']; ?>" />
373
+ </td>
374
+ </tr>
375
+ </table>
376
+ <p id="mycred-message-<?php echo $EM_Booking->booking_id; ?>"></p>
377
+ <?php do_action( 'mycred_em_after_payment_box', $this ); ?>
378
+
379
+ </td>
380
+ </tr>
381
+ <?php
382
+ }
383
+ }
384
+
385
+ /**
386
+ * Payment Box Scripting
387
+ * @since 1.2
388
+ * @version 1.0
389
+ */
390
+ public function insert_scripting() {
391
+ $ajax_url = admin_url( 'admin-ajax.php' ); ?>
392
+
393
+ <script type="text/javascript">
394
+ jQuery(function($) {
395
+ $('a.mycred-show-pay').click(function() {
396
+ var box = $(this).attr( 'data-booking' );
397
+ $('tr#mycred-payment-'+box).toggle();
398
+ });
399
+
400
+ $('input.mycred-pay').click(function() {
401
+ var button = $(this);
402
+ var label = $(this).val();
403
+ var token = button.prev().val();
404
+ var booking = button.prev().prev().val();
405
+ var table = button.parent().parent().parent();
406
+ var message = $('p#mycred-message-'+booking);
407
+
408
+ console.log( 'Token: ' + token );
409
+ $.ajax({
410
+ type : "POST",
411
+ data : {
412
+ action : 'mycred-pay-em-booking',
413
+ token : token,
414
+ booking_id : booking
415
+ },
416
+ dataType : "JSON",
417
+ url : '<?php echo $ajax_url; ?>',
418
+ // Before we start
419
+ beforeSend : function() {
420
+ button.val( 'Processing...' );
421
+ button.attr( 'disabled', 'disabled' );
422
+ },
423
+ // On Successful Communication
424
+ success : function( data ) {
425
+ if ( data.status == 'OK' ) {
426
+ table.hide();
427
+ message.show();
428
+ message.html( data.message );
429
+ }
430
+ else {
431
+ button.attr( 'disabled', 'disabled' );
432
+ button.hide().delay( 1000 );
433
+ message.show();
434
+ message.html( data.message );
435
+ }
436
+
437
+ // Debug
438
+ console.log( data );
439
+ },
440
+ // Error (sent to console)
441
+ error : function( jqXHR, textStatus, errorThrown ) {
442
+ // Debug - uncomment to use
443
+ console.log( jqXHR + ' : ' + textStatus + ' : ' + errorThrown );
444
+ button.val( 'Error - Try Again' );
445
+ button.removeAttr( 'disabled' );
446
+ }
447
+ });
448
+ });
449
+ });
450
+ </script>
451
+ <?php
452
+ }
453
+
454
+ /**
455
+ * Gateway Settings
456
+ * @since 1.2
457
+ * @version 1.0
458
+ */
459
+ public function settings_page() {
460
+ if ( $this->prefs['setup'] == 'multi' )
461
+ $box = 'display: block;';
462
+ else
463
+ $box = 'display: none;';
464
+
465
+ $exchange_message = sprintf(
466
+ __( 'How many %s is 1 %s worth?', 'mycred' ),
467
+ $this->core->plural(),
468
+ em_get_currency_symbol()
469
+ ); ?>
470
+
471
+ <div class="postbox" id="em-opt-mycred">
472
+ <div class="handlediv" title="<?php _e( 'Click to toggle', 'mycred' ); ?>"><br /></div><h3><span><?php echo sprintf( __( '%s Payments', 'mycred' ), $this->label ); ?></span></h3>
473
+ <div class="inside">
474
+ <?php do_action( 'mycred_em_before_settings', $this ); ?>
475
+
476
+ <h4><?php _e( 'Setup', 'mycred' ); ?></h4>
477
+ <table class="form-table">
478
+ <tr>
479
+ <th scope="row"><?php _e( 'Payments', 'mycred' ); ?></th>
480
+ <td>
481
+ <input type="radio" name="mycred_gateway[setup]" id="mycred-gateway-setup-off" value="off"<?php checked( $this->prefs['setup'], 'off' ); ?> /> <label for="mycred-gateway-setup-off"><?php echo $this->core->template_tags_general( __( 'Disabled - Users CAN NOT pay for tickets using %plural%.', 'mycred' ) ); ?></label><br />
482
+ <input type="radio" name="mycred_gateway[setup]" id="mycred-gateway-setup-single" value="single"<?php checked( $this->prefs['setup'], 'single' ); ?> /> <label for="mycred-gateway-setup-single"><?php echo $this->core->template_tags_general( __( 'Single - Users can ONLY pay for tickets using %plural%.', 'mycred' ) ); ?></label><br />
483
+ <input type="radio" name="mycred_gateway[setup]" id="mycred-gateway-setup-multi" value="multi"<?php checked( $this->prefs['setup'], 'multi' ); ?> /> <label for="mycred-gateway-setup-multi"><?php echo $this->core->template_tags_general( __( 'Multi - Users can pay for tickets using other gateways or %plural%.', 'mycred' ) ); ?></label>
484
+ </td>
485
+ </tr>
486
+ <tr>
487
+ <th scope="row"><?php _e( 'Refunds', 'mycred' ); ?></th>
488
+ <td>
489
+ <input name="mycred_gateway[refund]" type="text" id="mycred-gateway-log-refund" value="<?php echo $this->prefs['refund']; ?>" size="5" /> %<br />
490
+ <span class="description"><?php _e( 'The percentage of the paid amount to refund if a booking gets cancelled. User zero for no refunds. No refunds are given to "Rejected" bookings.', 'mycred' ); ?></span>
491
+ </td>
492
+ </tr>
493
+ </table>
494
+ <table class="form-table" id="mycred-exchange-rate" style="<?php echo $box; ?>">
495
+ <tr>
496
+ <th scope="row"><?php _e( 'Exchange Rate', 'mycred' ); ?></th>
497
+ <td>
498
+ <input name="mycred_gateway[rate]" type="text" id="mycred-gateway-rate" size="6" value="<?php echo $this->prefs['rate']; ?>" /><br />
499
+ <span class="description"><?php echo $exchange_message; ?></span>
500
+ </td>
501
+ </tr>
502
+ </table>
503
+ <h4><?php _e( 'Log Templates', 'mycred' ); ?></h4>
504
+ <table class="form-table">
505
+ <tr>
506
+ <th scope="row"><?php _e( 'Purchases', 'mycred' ); ?></th>
507
+ <td>
508
+ <input name="mycred_gateway[log][purchase]" type="text" id="mycred-gateway-log-purchase" style="width: 95%;" value="<?php echo $this->prefs['log']['purchase']; ?>" size="45" /><br />
509
+ <span class="description"><?php _e( 'Available template tags: General and Post related.', 'mycred' ); ?></span>
510
+ </td>
511
+ </tr>
512
+ <tr>
513
+ <th scope="row"><?php _e( 'Refunds', 'mycred' ); ?></th>
514
+ <td>
515
+ <input name="mycred_gateway[log][refund]" type="text" id="mycred-gateway-log-refund" style="width: 95%;" value="<?php echo $this->prefs['log']['refund']; ?>" size="45" /><br />
516
+ <span class="description"><?php _e( 'Available template tags: General and Post related.', 'mycred' ); ?></span>
517
+ </td>
518
+ </tr>
519
+ </table>
520
+ <script type="text/javascript">
521
+ jQuery(function($){
522
+ $('input[name="mycred_gateway[setup]"]').change(function(){
523
+ if ( $(this).val() == 'multi' ) {
524
+ $('#mycred-exchange-rate').show();
525
+ }
526
+ else {
527
+ $('#mycred-exchange-rate').hide();
528
+ }
529
+ });
530
+ });
531
+ </script>
532
+ <h4><?php _e( 'Labels', 'mycred' ); ?></h4>
533
+ <table class="form-table">
534
+ <tr valign="top">
535
+ <th scope="row"><?php _e( 'Payment Link Label', 'mycred' ); ?></th>
536
+ <td>
537
+ <input name="mycred_gateway[labels][link]" type="text" id="mycred-gateway-labels-link" style="width: 95%" value="<?php echo $this->prefs['labels']['link']; ?>" size="45" /><br />
538
+ <span class="description"><?php _e( 'The payment link shows / hides the payment form under "My Bookings". No HTML allowed.', 'mycred' ); ?></span>
539
+ </td>
540
+ </tr>
541
+ <tr valign="top">
542
+ <th scope="row"><?php _e( 'Payment Header', 'mycred' ); ?></th>
543
+ <td>
544
+ <input name="mycred_gateway[labels][header]" type="text" id="mycred-gateway-labels-header" style="width: 95%" value="<?php echo $this->prefs['labels']['header']; ?>" size="45" /><br />
545
+ <span class="description"><?php _e( 'Shown on top of the payment form. No HTML allowed.', 'mycred' ); ?></span>
546
+ </td>
547
+ </tr>
548
+ <tr valign="top">
549
+ <th scope="row"><?php _e( 'Button Label', 'mycred' ); ?></th>
550
+ <td>
551
+ <input name="mycred_gateway[labels][button]" type="text" id="mycred-gateway-labels-button" style="width: 95%" value="<?php echo $this->prefs['labels']['button']; ?>" size="45" /><br />
552
+ <span class="description"><?php _e( 'The button label for payments. No HTML allowed!', 'mycred' ); ?></span>
553
+ </td>
554
+ </tr>
555
+ </table>
556
+ <h4><?php _e( 'Messages', 'mycred' ); ?></h4>
557
+ <table class='form-table'>
558
+ <tr valign="top">
559
+ <th scope="row"><?php _e( 'Successful Payments', 'mycred' ); ?></th>
560
+ <td>
561
+ <input type="text" name="mycred_gateway[messages][success]" id="mycred-gateway-messages-success" style="width: 95%;" value="<?php echo stripslashes( $this->prefs['messages']['success'] ); ?>" /><br />
562
+ <span class="description"><?php _e( 'No HTML allowed! Available template tags: General', 'mycred' ); ?></span>
563
+ </td>
564
+ </tr>
565
+ <tr valign="top">
566
+ <th scope="row"><?php _e( 'Insufficient Funds', 'mycred' ); ?></th>
567
+ <td>
568
+ <input type="text" name="mycred_gateway[messages][error]" id="mycred-gateway-messages-error" style="width: 95%;" value="<?php echo stripslashes( $this->prefs['messages']['error'] ); ?>" /><br />
569
+ <span class="description"><?php _e( 'No HTML allowed! Available template tags: General', 'mycred' ); ?></span>
570
+ </td>
571
+ </tr>
572
+ </table>
573
+ <?php do_action( 'mycred_em_after_settings', $this ); ?>
574
+
575
+ </div> <!-- . inside -->
576
+ </div> <!-- .postbox -->
577
+ <?php
578
+ }
579
+
580
+ /**
581
+ * Save Settings
582
+ * @since 1.2
583
+ * @version 1.0
584
+ */
585
+ public function save_settings() {
586
+ if ( !isset( $_POST['mycred_gateway'] ) || !is_array( $_POST['mycred_gateway'] ) ) return;
587
+
588
+ // Prep
589
+ $data = $_POST['mycred_gateway'];
590
+ $new_settings = array();
591
+
592
+ // Setup
593
+ $new_settings['setup'] = $data['setup'];
594
+ $new_settings['refund'] = abs( $data['refund'] );
595
+
596
+ // Logs
597
+ $new_settings['log']['purchase'] = trim( stripslashes( $data['log']['purchase'] ) );
598
+ $new_settings['log']['refund'] = trim( stripslashes( $data['log']['refund'] ) );
599
+
600
+ if ( $new_settings['setup'] == 'multi' )
601
+ $new_settings['rate'] = sanitize_text_field( $data['rate'] );
602
+ else
603
+ $new_settings['rate'] = $this->prefs['rate'];
604
+
605
+ // Override Pricing Options
606
+ if ( $new_settings['setup'] == 'single' ) {
607
+ update_option( 'dbem_bookings_currency_decimal_point', $this->core->format['separators']['decimal'] );
608
+ update_option( 'dbem_bookings_currency_thousands_sep', $this->core->format['separators']['thousand'] );
609
+ update_option( 'dbem_bookings_currency', 'XMY' );
610
+ if ( empty( $this->core->before ) && !empty( $this->core->after ) )
611
+ $format = '@ #';
612
+ elseif ( !empty( $this->core->before ) && empty( $this->core->after ) )
613
+ $format = '# @';
614
+ update_option( 'dbem_bookings_currency_format', $format );
615
+ }
616
+
617
+ // Labels
618
+ $new_settings['labels']['link'] = sanitize_text_field( stripslashes( $data['labels']['link'] ) );
619
+ $new_settings['labels']['header'] = sanitize_text_field( stripslashes( $data['labels']['header'] ) );
620
+ $new_settings['labels']['button'] = sanitize_text_field( stripslashes( $data['labels']['button'] ) );
621
+
622
+ // Messages
623
+ $new_settings['messages']['success'] = sanitize_text_field( stripslashes( $data['messages']['success'] ) );
624
+ $new_settings['messages']['error'] = sanitize_text_field( stripslashes( $data['messages']['error'] ) );
625
+
626
+ // Save Settings
627
+ $current = $this->prefs;
628
+ $this->prefs = mycred_apply_defaults( $current, $new_settings );
629
+ update_option( 'mycred_eventsmanager_gateway_prefs', $this->prefs );
630
+
631
+ // Let others play
632
+ do_action( 'mycred_em_save_settings', $this );
633
+ }
634
+ }
635
+
636
+ $events = new myCRED_Events_Manager_Gateway();
637
+ $events->load();
638
+ }
639
+ ?>
addons/gateway/myCRED-addon-gateway.php CHANGED
@@ -2,19 +2,28 @@
2
  /**
3
  * Addon: Gateway
4
  * Addon URI: http://mycred.me/add-ons/gateway/
5
- * Version: 1.1
6
- * Description: Let your users pay using their <strong>my</strong>CRED points balance. Supported Carts: WooCommerce, MarketPress.
7
  * Author: Gabriel S Merovingi
8
  * Author URI: http://www.merovingi.com
9
  */
10
  if ( !defined( 'myCRED_VERSION' ) ) exit;
 
11
  define( 'myCRED_GATE', __FILE__ );
12
  define( 'myCRED_GATE_DIR', myCRED_ADDONS_DIR . 'gateway/' );
13
  define( 'myCRED_GATE_ASSETS_DIR', myCRED_GATE_DIR . 'assets/' );
14
  define( 'myCRED_GATE_CART_DIR', myCRED_GATE_DIR . 'carts/' );
 
 
15
  /**
16
  * Supported Carts
17
  */
18
  require_once( myCRED_GATE_CART_DIR . 'mycred-woocommerce.php' );
19
  require_once( myCRED_GATE_CART_DIR . 'mycred-marketpress.php' );
 
 
 
 
 
 
20
  ?>
2
  /**
3
  * Addon: Gateway
4
  * Addon URI: http://mycred.me/add-ons/gateway/
5
+ * Version: 1.2
6
+ * Description: Let your users pay using their <strong>my</strong>CRED points balance. Supported Carts: WooCommerce, MarketPress. Supported Event Bookings: Event Espresso, Events Manager
7
  * Author: Gabriel S Merovingi
8
  * Author URI: http://www.merovingi.com
9
  */
10
  if ( !defined( 'myCRED_VERSION' ) ) exit;
11
+
12
  define( 'myCRED_GATE', __FILE__ );
13
  define( 'myCRED_GATE_DIR', myCRED_ADDONS_DIR . 'gateway/' );
14
  define( 'myCRED_GATE_ASSETS_DIR', myCRED_GATE_DIR . 'assets/' );
15
  define( 'myCRED_GATE_CART_DIR', myCRED_GATE_DIR . 'carts/' );
16
+ define( 'myCRED_GATE_EVENT_DIR', myCRED_GATE_DIR . 'event-booking/' );
17
+
18
  /**
19
  * Supported Carts
20
  */
21
  require_once( myCRED_GATE_CART_DIR . 'mycred-woocommerce.php' );
22
  require_once( myCRED_GATE_CART_DIR . 'mycred-marketpress.php' );
23
+
24
+ /**
25
+ * Supported Event Management Plugins
26
+ */
27
+ require_once( myCRED_GATE_EVENT_DIR . 'mycred-eventespresso3.php' );
28
+ require_once( myCRED_GATE_EVENT_DIR . 'mycred-eventsmanager.php' );
29
  ?>
addons/ranks/includes/mycred-rank-functions.php CHANGED
@@ -68,15 +68,17 @@ if ( !function_exists( 'mycred_get_users_rank' ) ) {
68
  * where the user fits in.
69
  * @param $user_id (int) required user id
70
  * @param $save (bool) option to save the rank to the given users meta data
 
 
71
  * @uses WP_Query()
72
  * @uses mycred_have_ranks()
73
  * @uses update_user_meta()
74
  * @returns empty (string) on failure or the users rank
75
  * @since 1.1
76
- * @version 1.1
77
  */
78
  if ( !function_exists( 'mycred_find_users_rank' ) ) {
79
- function mycred_find_users_rank( $user_id = NULL, $save = false, $amount = 0 ) {
80
  $mycred = mycred_get_settings();
81
 
82
  // Check for exclusion
@@ -84,9 +86,9 @@ if ( !function_exists( 'mycred_find_users_rank' ) ) {
84
 
85
  // Get users balance
86
  if ( $user_id === NULL )
87
- $balance = $mycred->get_users_cred( get_current_user_id() );
88
  else
89
- $balance = $mycred->get_users_cred( $user_id );
90
 
91
  // The new balance before it is saved
92
  $balance = $balance+$amount;
@@ -173,7 +175,6 @@ if ( !function_exists( 'mycred_get_rank_id_from_title' ) ) {
173
  return $rank->ID;
174
  }
175
  }
176
-
177
  /**
178
  * Get My Rank
179
  * Returns the current users rank
68
  * where the user fits in.
69
  * @param $user_id (int) required user id
70
  * @param $save (bool) option to save the rank to the given users meta data
71
+ * @param $amount (int|float) optional amount to add to current balance
72
+ * @param $type (string) optional cred type to check
73
  * @uses WP_Query()
74
  * @uses mycred_have_ranks()
75
  * @uses update_user_meta()
76
  * @returns empty (string) on failure or the users rank
77
  * @since 1.1
78
+ * @version 1.2
79
  */
80
  if ( !function_exists( 'mycred_find_users_rank' ) ) {
81
+ function mycred_find_users_rank( $user_id = NULL, $save = false, $amount = 0, $type = '' ) {
82
  $mycred = mycred_get_settings();
83
 
84
  // Check for exclusion
86
 
87
  // Get users balance
88
  if ( $user_id === NULL )
89
+ $balance = $mycred->get_users_cred( get_current_user_id(), $type );
90
  else
91
+ $balance = $mycred->get_users_cred( $user_id, $type );
92
 
93
  // The new balance before it is saved
94
  $balance = $balance+$amount;
175
  return $rank->ID;
176
  }
177
  }
 
178
  /**
179
  * Get My Rank
180
  * Returns the current users rank
addons/ranks/myCRED-addon-ranks.php CHANGED
@@ -2,7 +2,7 @@
2
  /**
3
  * Addon: Ranks
4
  * Addon URI: http://mycred.me/add-ons/email-notices/
5
- * Version: 1.0.1
6
  * Description: Create ranks for users reaching a certain number of %_plural% with the option to add logos for each rank.
7
  * Author: Gabriel S Merovingi
8
  * Author URI: http://www.merovingi.com
@@ -19,11 +19,11 @@ include_once( myCRED_RANKS_DIR . 'includes/mycred-rank-shortcodes.php' );
19
  * points, ranks are titles that can be given to users when their reach a certain
20
  * amount.
21
  * @since 1.1
22
- * @version 1.0.1
23
  */
24
  if ( !class_exists( 'myCRED_Ranks' ) ) {
25
  class myCRED_Ranks extends myCRED_Module {
26
-
27
  /**
28
  * Construct
29
  */
@@ -32,6 +32,7 @@ if ( !class_exists( 'myCRED_Ranks' ) ) {
32
  'module_name' => 'rank',
33
  'defaults' => array(
34
  'public' => 0,
 
35
  'slug' => 'mycred_rank',
36
  'bb_location' => 'top',
37
  'order' => 'ASC',
@@ -62,11 +63,11 @@ if ( !class_exists( 'myCRED_Ranks' ) ) {
62
  add_action( 'mycred_help', array( $this, 'help' ), 10, 2 );
63
  add_action( 'mycred_parse_tags_user', array( $this, 'parse_rank' ), 10, 3 );
64
  }
65
-
66
  /**
67
  * Hook into Init
68
  * @since 1.1
69
- * @version 1.1
70
  */
71
  public function module_init() {
72
  $this->register_post_type();
@@ -75,28 +76,30 @@ if ( !class_exists( 'myCRED_Ranks' ) ) {
75
 
76
  add_filter( 'pre_get_posts', array( $this, 'adjust_wp_query' ), 20 );
77
  add_action( 'mycred_admin_enqueue', array( $this, 'enqueue_scripts' ) );
78
-
79
  // Instances to update ranks
80
- add_action( 'transition_post_status', array( $this, 'post_status_change' ), 99, 3 );
81
- add_filter( 'mycred_add', array( $this, 'balance_adjustments' ), 99, 3 );
82
- add_action( 'user_register', array( $this, 'registration' ), 999 );
83
-
84
  // BuddyPress
85
  if ( function_exists( 'bp_displayed_user_id' ) && isset( $this->rank['bb_location'] ) && !empty( $this->rank['bb_location'] ) ) {
86
  if ( $this->rank['bb_location'] == 'top' || $this->rank['bb_location'] == 'both' )
87
  add_action( 'bp_before_member_header_meta', array( $this, 'insert_rank_header' ) );
88
-
89
  if ( $this->rank['bb_location'] == 'profile_tab' || $this->rank['bb_location'] == 'both' )
90
  add_action( 'bp_profile_field_item', array( $this, 'insert_rank_profile' ) );
91
  }
92
-
93
  // Shortcodes
94
  add_shortcode( 'mycred_my_rank', 'mycred_render_my_rank' );
95
  add_shortcode( 'mycred_users_of_rank', 'mycred_render_users_of_rank' );
96
  add_shortcode( 'mycred_users_of_all_ranks', 'mycred_render_users_of_all_ranks' );
97
  add_shortcode( 'mycred_list_ranks', 'mycred_render_rank_list' );
 
 
98
  }
99
-
100
  /**
101
  * Hook into Admin Init
102
  * @since 1.1
@@ -105,7 +108,7 @@ if ( !class_exists( 'myCRED_Ranks' ) ) {
105
  public function module_admin_init() {
106
  add_filter( 'manage_mycred_rank_posts_columns', array( $this, 'adjust_column_headers' ) );
107
  add_action( 'manage_mycred_rank_posts_custom_column', array( $this, 'adjust_column_content' ), 10, 2 );
108
-
109
  add_filter( 'manage_users_columns', array( $this, 'custom_user_column' ) );
110
  add_action( 'manage_users_custom_column', array( $this, 'custom_user_column_content' ), 10, 3 );
111
 
@@ -117,7 +120,7 @@ if ( !class_exists( 'myCRED_Ranks' ) ) {
117
  add_action( 'add_meta_boxes_mycred_rank', array( $this, 'add_meta_boxes' ) );
118
  add_action( 'save_post', array( $this, 'save_rank_settings' ) );
119
  }
120
-
121
  /**
122
  * Enqueue Scripts & Styles
123
  * @since 1.1
@@ -134,7 +137,7 @@ if ( !class_exists( 'myCRED_Ranks' ) ) {
134
  wp_dequeue_script( 'autosave' );
135
  }
136
  }
137
-
138
  /**
139
  * Register Rank Post Type
140
  * @since 1.1
@@ -156,7 +159,7 @@ if ( !class_exists( 'myCRED_Ranks' ) ) {
156
  'parent_item_colon' => '',
157
  'menu_name' => __( 'Ranks', 'mycred' )
158
  );
159
-
160
  // Support
161
  $supports = array( 'title', 'thumbnail' );
162
  if ( isset( $this->rank['support']['content'] ) && $this->rank['support']['content'] )
@@ -169,7 +172,7 @@ if ( !class_exists( 'myCRED_Ranks' ) ) {
169
  $supports[] = 'page-attributes';
170
  if ( isset( $this->rank['support']['custom-fields'] ) && $this->rank['support']['custom-fields'] )
171
  $supports[] = 'custom-fields';
172
-
173
  $args = array(
174
  'labels' => $labels,
175
  'public' => (bool) $this->rank['public'],
@@ -180,14 +183,50 @@ if ( !class_exists( 'myCRED_Ranks' ) ) {
180
  'capability_type' => 'page',
181
  'supports' => $supports
182
  );
183
-
184
  // Rewrite
185
  if ( $this->rank['public'] && !empty( $this->rank['slug'] ) ) {
186
  $args['rewrite'] = array( 'slug' => $this->rank['slug'] );
187
  }
188
  register_post_type( 'mycred_rank', apply_filters( 'mycred_register_ranks', $args ) );
189
  }
190
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
191
  /**
192
  * Registration
193
  * Check what rank this user should have
@@ -197,18 +236,33 @@ if ( !class_exists( 'myCRED_Ranks' ) ) {
197
  public function registration( $user_id ) {
198
  mycred_find_users_rank( $user_id, true );
199
  }
200
-
201
  /**
202
  * Balance Adjustment
203
  * Check if users rank should change.
204
  * @since 1.1
205
  * @version 1.1
206
  */
207
- public function balance_adjustments( $reply, $request, $mycred ) {
208
- mycred_find_users_rank( $request['user_id'], true, $request['amount'] );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
209
  return $reply;
210
  }
211
-
212
  /**
213
  * Publishing Content
214
  * Check if users rank should change.
@@ -218,33 +272,34 @@ if ( !class_exists( 'myCRED_Ranks' ) ) {
218
  public function post_status_change( $new_status, $old_status, $post ) {
219
  // Only ranks please
220
  if ( $post->post_type != 'mycred_rank' ) return;
221
-
222
  // Publishing rank
223
  $status = apply_filters( 'mycred_publish_hook_old', array( 'new', 'auto-draft', 'draft', 'private', 'pending', 'scheduled' ) );
224
  if ( in_array( $old_status, $status ) && $new_status == 'publish' ) {
225
  $this->assign_ranks();
226
  }
 
227
  // Trashing of rank
228
  elseif ( $old_status == 'publish' && $new_status == 'trash' ) {
229
  $this->assign_ranks();
230
  }
231
  }
232
-
233
  /**
234
  * Assign Ranks
235
  * Runs though all registered members and assigns ranks
236
  * @since 1.1.1
237
- * @version 1.0
238
  */
239
  public function assign_ranks() {
240
  // Run though all users and find their rank
241
  $mycred = mycred_get_settings();
242
  $args = array();
243
-
244
  // In case we have an exclude list
245
  if ( isset( $mycred->exclude['list'] ) && !empty( $mycred->exclude['list'] ) )
246
  $args['exclude'] = explode( ',', $mycred->exclude['list'] );
247
-
248
  $users = get_users( $args );
249
  $rank_users = array();
250
  if ( $users ) {
@@ -254,11 +309,14 @@ if ( !class_exists( 'myCRED_Ranks' ) ) {
254
  // this check again to avoid including them in this list.
255
  if ( $mycred->exclude_user( $user->ID ) ) continue;
256
  // Find users rank
257
- mycred_find_users_rank( $user->ID, true );
 
 
 
258
  }
259
  }
260
  }
261
-
262
  /**
263
  * Adjust Rank Sort Order
264
  * Adjusts the wp query when viewing ranks to order by the min. point requirement.
@@ -269,14 +327,14 @@ if ( !class_exists( 'myCRED_Ranks' ) ) {
269
  if ( isset( $query->query['post_type'] ) && $query->is_main_query() && $query->query['post_type'] == 'mycred_rank' ) {
270
  $query->set( 'meta_key', 'mycred_rank_min' );
271
  $query->set( 'orderby', 'meta_value_num' );
272
-
273
  if ( !isset( $this->rank['order'] ) ) $this->rank['order'] = 'ASC';
274
  $query->set( 'order', $this->rank['order'] );
275
  }
276
-
277
  return $query;
278
  }
279
-
280
  /**
281
  * Parse Rank
282
  * Parses the %rank% and %rank_logo% template tags.
@@ -300,10 +358,10 @@ if ( !class_exists( 'myCRED_Ranks' ) ) {
300
  $rank_name = mycred_get_users_rank( $user_id );
301
  $content = str_replace( '%rank%', $rank_name, $content );
302
  $content = str_replace( '%rank_logo%', mycred_get_rank_logo( $rank_name ), $content );
303
-
304
  return $content;
305
  }
306
-
307
  /**
308
  * Insert Rank In Profile Header
309
  * @since 1.1
@@ -313,12 +371,12 @@ if ( !class_exists( 'myCRED_Ranks' ) ) {
313
  if ( bp_is_my_profile() || mycred_is_admin() ) {
314
  $user_id = bp_displayed_user_id();
315
  if ( $this->core->exclude_user( $user_id ) ) return;
316
-
317
  $rank_name = mycred_get_users_rank( $user_id );
318
  echo '<div id="mycred-my-rank">' . __( 'Rank', 'mycred' ) . ': ' . $rank_name . ' ' . mycred_get_rank_logo( $rank_name ) . '</div>';
319
  }
320
  }
321
-
322
  /**
323
  * Insert Rank In Profile Details
324
  * @since 1.1
@@ -338,7 +396,7 @@ if ( !class_exists( 'myCRED_Ranks' ) ) {
338
  </tr>
339
  <?php
340
  }
341
-
342
  /**
343
  * Add Default Rank
344
  * Adds the default "Newbie" rank and adds all non-exluded user to this rank.
@@ -355,16 +413,16 @@ if ( !class_exists( 'myCRED_Ranks' ) ) {
355
  $rank['post_title'] = __( 'Newbie', 'mycred' );
356
  $rank['post_type'] = 'mycred_rank';
357
  $rank['post_status'] = 'publish';
358
-
359
  $rank_id = wp_insert_post( $rank );
360
-
361
  update_post_meta( $rank_id, 'mycred_rank_min', 0 );
362
  update_post_meta( $rank_id, 'mycred_rank_max', 9999999 );
363
-
364
  $args = array();
365
  if ( isset( $this->core->exclude['list'] ) && !empty( $this->core->exclude['list'] ) )
366
  $args['exclude'] = explode( ',', $this->core->exclude['list'] );
367
-
368
  $users = get_users( $args );
369
  if ( $users ) {
370
  foreach ( $users as $user ) {
@@ -372,7 +430,7 @@ if ( !class_exists( 'myCRED_Ranks' ) ) {
372
  }
373
  }
374
  }
375
-
376
  /**
377
  * Adjust Post Updated Messages
378
  * @since 1.1
@@ -400,7 +458,7 @@ if ( !class_exists( 'myCRED_Ranks' ) ) {
400
 
401
  return $messages;
402
  }
403
-
404
  /**
405
  * Adjust Row Actions
406
  * @since 1.1
@@ -409,14 +467,14 @@ if ( !class_exists( 'myCRED_Ranks' ) ) {
409
  public function adjust_row_actions( $actions, $post ) {
410
  if ( $post->post_type == 'mycred_rank' ) {
411
  unset( $actions['inline hide-if-no-js'] );
412
-
413
  if ( !$this->rank['public'] )
414
  unset( $actions['view'] );
415
  }
416
 
417
  return $actions;
418
  }
419
-
420
  /**
421
  * Customize Users Column Headers
422
  * @since 1.1.1
@@ -438,7 +496,7 @@ if ( !class_exists( 'myCRED_Ranks' ) ) {
438
 
439
  return mycred_get_users_rank( $user_id );
440
  }
441
-
442
  /**
443
  * Adjust Rank Column Header
444
  * @since 1.1
@@ -478,7 +536,7 @@ if ( !class_exists( 'myCRED_Ranks' ) ) {
478
  $min = get_post_meta( $post_id, 'mycred_rank_min', true );
479
  if ( empty( $min ) && (int) $min !== 0 )
480
  $min = __( 'Any Value', 'mycred' );
481
-
482
  $min = $mycred->template_tags_general( __( 'Minimum %plural%', 'mycred' ) ) . ': ' . $min;
483
  $max = get_post_meta( $post_id, 'mycred_rank_max', true );
484
  if ( empty( $max ) )
@@ -495,7 +553,7 @@ if ( !class_exists( 'myCRED_Ranks' ) ) {
495
  echo '<p>' . $users . '</p>';
496
  }
497
  }
498
-
499
  /**
500
  * Adjust Enter Title Here
501
  * @since 1.1
@@ -508,7 +566,7 @@ if ( !class_exists( 'myCRED_Ranks' ) ) {
508
 
509
  return $title;
510
  }
511
-
512
  /**
513
  * Add Meta Boxes
514
  * @since 1.1
@@ -524,7 +582,7 @@ if ( !class_exists( 'myCRED_Ranks' ) ) {
524
  'high'
525
  );
526
  }
527
-
528
  /**
529
  * Rank Settings Metabox
530
  * @since 1.1
@@ -550,7 +608,7 @@ if ( !class_exists( 'myCRED_Ranks' ) ) {
550
  <div style="display:block;width:50%;margin:0;padding:0;float:left;">
551
  <p><?php _e( 'All Published Ranks', 'mycred' ); ?>:</p>
552
  <?php
553
-
554
  $all = mycred_get_ranks();
555
  if ( !empty( $all ) ) {
556
  foreach ( $all as $rank_id => $rank ) {
@@ -563,15 +621,13 @@ if ( !class_exists( 'myCRED_Ranks' ) ) {
563
  }
564
  else {
565
  echo '<p>' . __( 'No Ranks found', 'mycred' ) . '.</p>';
566
- }
567
- ?>
568
-
569
  </div>
570
  <div class="clear">&nbsp;</div>
571
  </div>
572
  <?php
573
  }
574
-
575
  /**
576
  * Save Email Notice Details
577
  * @since 1.1
@@ -586,32 +642,36 @@ if ( !class_exists( 'myCRED_Ranks' ) ) {
586
  elseif ( !isset( $_POST['mycred_rank'] ) || !is_array( $_POST['mycred_rank'] ) ) return;
587
  // Finally check token
588
  elseif ( !wp_verify_nonce( $_POST['mycred_rank']['token'], 'mycred-edit-rank' ) ) return;
589
-
590
  // Minimum can not be empty
591
  if ( empty( $_POST['mycred_rank']['min'] ) )
592
  $min = 0;
593
  else
594
  $min = trim( $_POST['mycred_rank']['min'] );
595
-
596
  // Maximum can not be empty
597
  if ( empty( $_POST['mycred_rank']['max'] ) )
598
  $max = 999;
599
  else
600
  $max = trim( $_POST['mycred_rank']['max'] );
601
-
602
  update_post_meta( $post_id, 'mycred_rank_min', $min );
603
  update_post_meta( $post_id, 'mycred_rank_max', $max );
604
-
605
  if ( get_post_status( $post_id ) == 'publish' )
606
  $this->assign_ranks();
607
  }
608
-
609
  /**
610
  * Add to General Settings
611
  * @since 1.1
612
- * @version 1.1
613
  */
614
- public function after_general_settings() { ?>
 
 
 
 
615
 
616
  <h4 style="color:#BBD865;"><?php _e( 'Ranks', 'mycred' ); ?></h4>
617
  <div class="body" style="display:none;">
@@ -635,6 +695,25 @@ if ( !class_exists( 'myCRED_Ranks' ) ) {
635
  <label for="<?php echo $this->field_id( 'public' ); ?>"><?php _e( 'If you want to create a template archive for each rank, you must select to have ranks public. Defaults to disabled.', 'mycred' ); ?></label>
636
  </li>
637
  </ol>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
638
  <label class="subheader" for="<?php echo $this->field_id( 'slug' ); ?>"><?php _e( 'Archive URL', 'mycred' ); ?></label>
639
  <ol id="">
640
  <li>
@@ -696,14 +775,71 @@ if ( !class_exists( 'myCRED_Ranks' ) ) {
696
  echo '<input type="hidden" name="' . $this->field_name( 'bb_location' ) . '" value="" />';
697
  } ?>
698
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
699
  </div>
700
  <?php
701
  }
702
-
703
  /**
704
  * Save Settings
705
  * @since 1.1
706
- * @version 1.1
707
  */
708
  public function sanitize_extra_settings( $new_data, $data, $core ) {
709
  $new_data['rank']['support']['content'] = ( isset( $data['rank']['support']['content'] ) ) ? true : false;
@@ -711,14 +847,15 @@ if ( !class_exists( 'myCRED_Ranks' ) ) {
711
  $new_data['rank']['support']['comments'] = ( isset( $data['rank']['support']['comments'] ) ) ? true : false;
712
  $new_data['rank']['support']['page-attributes'] = ( isset( $data['rank']['support']['page-attributes'] ) ) ? true : false;
713
  $new_data['rank']['support']['custom-fields'] = ( isset( $data['rank']['support']['custom-fields'] ) ) ? true : false;
714
-
 
715
  $new_data['rank']['public'] = ( isset( $data['rank']['public'] ) ) ? true : false;
716
  $new_data['rank']['slug'] = sanitize_text_field( $data['rank']['slug'] );
717
  $new_data['rank']['order'] = sanitize_text_field( $data['rank']['order'] );
718
  $new_data['rank']['bb_location'] = sanitize_text_field( $data['rank']['bb_location'] );
719
  return $new_data;
720
  }
721
-
722
  /**
723
  * Help
724
  * @since 1.1
@@ -731,6 +868,8 @@ if ( !class_exists( 'myCRED_Ranks' ) ) {
731
  'title' => __( 'Ranks', 'mycred' ),
732
  'content' => '
733
  <p>' . __( 'You can create ranks according to the amount of points a user has. By default, ranks are only visible in widgets and shortcodes however it is possible for you to also create archive pages in your theme for all ranks or specific ones.', 'mycred' ) . '</p>
 
 
734
  <p><strong>' . __( 'Templates', 'mycred' ) . '</strong></p>
735
  <p>' . __( 'Ranks are just another custom post type which means that you can, if you select to make Ranks Public, create custom template files for ranks in your theme folder.', 'mycred' ) . '</p>
736
  <p>' . sprintf( __( 'For more information on Templates for Custom Post Types visit the <a href="%s">WordPress Codex</a>.', 'mycred' ), 'http://codex.wordpress.org/Post_Types#Custom_Post_Types' ) . '</p>
2
  /**
3
  * Addon: Ranks
4
  * Addon URI: http://mycred.me/add-ons/email-notices/
5
+ * Version: 1.1
6
  * Description: Create ranks for users reaching a certain number of %_plural% with the option to add logos for each rank.
7
  * Author: Gabriel S Merovingi
8
  * Author URI: http://www.merovingi.com
19
  * points, ranks are titles that can be given to users when their reach a certain
20
  * amount.
21
  * @since 1.1
22
+ * @version 1.1
23
  */
24
  if ( !class_exists( 'myCRED_Ranks' ) ) {
25
  class myCRED_Ranks extends myCRED_Module {
26
+
27
  /**
28
  * Construct
29
  */
32
  'module_name' => 'rank',
33
  'defaults' => array(
34
  'public' => 0,
35
+ 'base' => 'current',
36
  'slug' => 'mycred_rank',
37
  'bb_location' => 'top',
38
  'order' => 'ASC',
63
  add_action( 'mycred_help', array( $this, 'help' ), 10, 2 );
64
  add_action( 'mycred_parse_tags_user', array( $this, 'parse_rank' ), 10, 3 );
65
  }
66
+
67
  /**
68
  * Hook into Init
69
  * @since 1.1
70
+ * @version 1.2
71
  */
72
  public function module_init() {
73
  $this->register_post_type();
76
 
77
  add_filter( 'pre_get_posts', array( $this, 'adjust_wp_query' ), 20 );
78
  add_action( 'mycred_admin_enqueue', array( $this, 'enqueue_scripts' ) );
79
+
80
  // Instances to update ranks
81
+ add_action( 'transition_post_status', array( $this, 'post_status_change' ), 99, 3 );
82
+ add_action( 'user_register', array( $this, 'registration' ), 999 );
83
+ add_filter( 'mycred_add', array( $this, 'update_balance' ), 99, 3 );
84
+
85
  // BuddyPress
86
  if ( function_exists( 'bp_displayed_user_id' ) && isset( $this->rank['bb_location'] ) && !empty( $this->rank['bb_location'] ) ) {
87
  if ( $this->rank['bb_location'] == 'top' || $this->rank['bb_location'] == 'both' )
88
  add_action( 'bp_before_member_header_meta', array( $this, 'insert_rank_header' ) );
89
+
90
  if ( $this->rank['bb_location'] == 'profile_tab' || $this->rank['bb_location'] == 'both' )
91
  add_action( 'bp_profile_field_item', array( $this, 'insert_rank_profile' ) );
92
  }
93
+
94
  // Shortcodes
95
  add_shortcode( 'mycred_my_rank', 'mycred_render_my_rank' );
96
  add_shortcode( 'mycred_users_of_rank', 'mycred_render_users_of_rank' );
97
  add_shortcode( 'mycred_users_of_all_ranks', 'mycred_render_users_of_all_ranks' );
98
  add_shortcode( 'mycred_list_ranks', 'mycred_render_rank_list' );
99
+
100
+ add_action( 'wp_ajax_mycred-calc-totals', array( $this, 'calculate_totals' ) );
101
  }
102
+
103
  /**
104
  * Hook into Admin Init
105
  * @since 1.1
108
  public function module_admin_init() {
109
  add_filter( 'manage_mycred_rank_posts_columns', array( $this, 'adjust_column_headers' ) );
110
  add_action( 'manage_mycred_rank_posts_custom_column', array( $this, 'adjust_column_content' ), 10, 2 );
111
+
112
  add_filter( 'manage_users_columns', array( $this, 'custom_user_column' ) );
113
  add_action( 'manage_users_custom_column', array( $this, 'custom_user_column_content' ), 10, 3 );
114
 
120
  add_action( 'add_meta_boxes_mycred_rank', array( $this, 'add_meta_boxes' ) );
121
  add_action( 'save_post', array( $this, 'save_rank_settings' ) );
122
  }
123
+
124
  /**
125
  * Enqueue Scripts & Styles
126
  * @since 1.1
137
  wp_dequeue_script( 'autosave' );
138
  }
139
  }
140
+
141
  /**
142
  * Register Rank Post Type
143
  * @since 1.1
159
  'parent_item_colon' => '',
160
  'menu_name' => __( 'Ranks', 'mycred' )
161
  );
162
+
163
  // Support
164
  $supports = array( 'title', 'thumbnail' );
165
  if ( isset( $this->rank['support']['content'] ) && $this->rank['support']['content'] )
172
  $supports[] = 'page-attributes';
173
  if ( isset( $this->rank['support']['custom-fields'] ) && $this->rank['support']['custom-fields'] )
174
  $supports[] = 'custom-fields';
175
+
176
  $args = array(
177
  'labels' => $labels,
178
  'public' => (bool) $this->rank['public'],
183
  'capability_type' => 'page',
184
  'supports' => $supports
185
  );
186
+
187
  // Rewrite
188
  if ( $this->rank['public'] && !empty( $this->rank['slug'] ) ) {
189
  $args['rewrite'] = array( 'slug' => $this->rank['slug'] );
190
  }
191
  register_post_type( 'mycred_rank', apply_filters( 'mycred_register_ranks', $args ) );
192
  }
193
+
194
+ /**
195
+ * AJAX: Calculate Totals
196
+ * @since 1.2
197
+ * @version 1.0
198
+ */
199
+ public function calculate_totals() {
200
+ // Security
201
+ check_ajax_referer( 'mycred-calc-totals', 'token' );
202
+
203
+ global $wpdb;
204
+
205
+ $db = $wpdb->prefix . 'myCRED_Log';
206
+ $sql = "
207
+ SELECT
208
+ user_id AS ID,
209
+ SUM(CASE WHEN creds > 0 THEN creds ELSE 0 END) as positives_sum,
210
+ SUM(CASE WHEN creds < 0 THEN creds ELSE 0 END) as negatives_sum
211
+ FROM
212
+ $db
213
+ GROUP BY
214
+ user_id;";
215
+ $users = $wpdb->get_results( $sql );
216
+ $count = 0;
217
+ if ( $users ) {
218
+ foreach ( $users as $user ) {
219
+ update_user_meta( $user->ID, $this->core->get_cred_id() . '_total', $user->positives_sum );
220
+ $count = $count+1;
221
+ }
222
+ }
223
+
224
+ if ( $count > 0 )
225
+ die( json_encode( sprintf( __( 'Completed - Total of %d users effected', 'mycred' ), $count ) ) );
226
+ else
227
+ die( json_encode( __( 'Log is Empty', 'mycred' ) ) );
228
+ }
229
+
230
  /**
231
  * Registration
232
  * Check what rank this user should have
236
  public function registration( $user_id ) {
237
  mycred_find_users_rank( $user_id, true );
238
  }
239
+
240
  /**
241
  * Balance Adjustment
242
  * Check if users rank should change.
243
  * @since 1.1
244
  * @version 1.1
245
  */
246
+ public function update_balance( $reply, $request, $mycred ) {
247
+ // Ranks are based on current balance
248
+ if ( $this->rank['base'] == 'current' ) {
249
+ mycred_find_users_rank( $request['user_id'], true, $request['amount'] );
250
+ }
251
+
252
+ // Ranks are based on total
253
+ else {
254
+ // Update total
255
+ $new_total = mycred_update_users_total( $request, $mycred );
256
+ // Get total before update
257
+ $total_before = $this->core->number( $new_total-$request['amount'] );
258
+ // Make sure update went well and that there has been an actual increase
259
+ if ( $new_total !== false && $new_total != $total_before )
260
+ mycred_find_users_rank( $request['user_id'], true, $request['amount'], $this->core->get_cred_id() . '_total' );
261
+ }
262
+
263
  return $reply;
264
  }
265
+
266
  /**
267
  * Publishing Content
268
  * Check if users rank should change.
272
  public function post_status_change( $new_status, $old_status, $post ) {
273
  // Only ranks please
274
  if ( $post->post_type != 'mycred_rank' ) return;
275
+
276
  // Publishing rank
277
  $status = apply_filters( 'mycred_publish_hook_old', array( 'new', 'auto-draft', 'draft', 'private', 'pending', 'scheduled' ) );
278
  if ( in_array( $old_status, $status ) && $new_status == 'publish' ) {
279
  $this->assign_ranks();
280
  }
281
+
282
  // Trashing of rank
283
  elseif ( $old_status == 'publish' && $new_status == 'trash' ) {
284
  $this->assign_ranks();
285
  }
286
  }
287
+
288
  /**
289
  * Assign Ranks
290
  * Runs though all registered members and assigns ranks
291
  * @since 1.1.1
292
+ * @version 1.1
293
  */
294
  public function assign_ranks() {
295
  // Run though all users and find their rank
296
  $mycred = mycred_get_settings();
297
  $args = array();
298
+
299
  // In case we have an exclude list
300
  if ( isset( $mycred->exclude['list'] ) && !empty( $mycred->exclude['list'] ) )
301
  $args['exclude'] = explode( ',', $mycred->exclude['list'] );
302
+
303
  $users = get_users( $args );
304
  $rank_users = array();
305
  if ( $users ) {
309
  // this check again to avoid including them in this list.
310
  if ( $mycred->exclude_user( $user->ID ) ) continue;
311
  // Find users rank
312
+ if ( $this->rank['base'] == 'total' )
313
+ mycred_find_users_rank( $user->ID, true, 0, $this->core->cred_id . '_total' );
314
+ else
315
+ mycred_find_users_rank( $user->ID, true );
316
  }
317
  }
318
  }
319
+
320
  /**
321
  * Adjust Rank Sort Order
322
  * Adjusts the wp query when viewing ranks to order by the min. point requirement.
327
  if ( isset( $query->query['post_type'] ) && $query->is_main_query() && $query->query['post_type'] == 'mycred_rank' ) {
328
  $query->set( 'meta_key', 'mycred_rank_min' );
329
  $query->set( 'orderby', 'meta_value_num' );
330
+
331
  if ( !isset( $this->rank['order'] ) ) $this->rank['order'] = 'ASC';
332
  $query->set( 'order', $this->rank['order'] );
333
  }
334
+
335
  return $query;
336
  }
337
+
338
  /**
339
  * Parse Rank
340
  * Parses the %rank% and %rank_logo% template tags.
358
  $rank_name = mycred_get_users_rank( $user_id );
359
  $content = str_replace( '%rank%', $rank_name, $content );
360
  $content = str_replace( '%rank_logo%', mycred_get_rank_logo( $rank_name ), $content );
361
+
362
  return $content;
363
  }
364
+
365
  /**
366
  * Insert Rank In Profile Header
367
  * @since 1.1
371
  if ( bp_is_my_profile() || mycred_is_admin() ) {
372
  $user_id = bp_displayed_user_id();
373
  if ( $this->core->exclude_user( $user_id ) ) return;
374
+
375
  $rank_name = mycred_get_users_rank( $user_id );
376
  echo '<div id="mycred-my-rank">' . __( 'Rank', 'mycred' ) . ': ' . $rank_name . ' ' . mycred_get_rank_logo( $rank_name ) . '</div>';
377
  }
378
  }
379
+
380
  /**
381
  * Insert Rank In Profile Details
382
  * @since 1.1
396
  </tr>
397
  <?php
398
  }
399
+
400
  /**
401
  * Add Default Rank
402
  * Adds the default "Newbie" rank and adds all non-exluded user to this rank.
413
  $rank['post_title'] = __( 'Newbie', 'mycred' );
414
  $rank['post_type'] = 'mycred_rank';
415
  $rank['post_status'] = 'publish';
416
+
417
  $rank_id = wp_insert_post( $rank );
418
+
419
  update_post_meta( $rank_id, 'mycred_rank_min', 0 );
420
  update_post_meta( $rank_id, 'mycred_rank_max', 9999999 );
421
+
422
  $args = array();
423
  if ( isset( $this->core->exclude['list'] ) && !empty( $this->core->exclude['list'] ) )
424
  $args['exclude'] = explode( ',', $this->core->exclude['list'] );
425
+
426
  $users = get_users( $args );
427
  if ( $users ) {
428
  foreach ( $users as $user ) {
430
  }
431
  }
432
  }
433
+
434
  /**
435
  * Adjust Post Updated Messages
436
  * @since 1.1
458
 
459
  return $messages;
460
  }
461
+
462
  /**
463
  * Adjust Row Actions
464
  * @since 1.1
467
  public function adjust_row_actions( $actions, $post ) {
468
  if ( $post->post_type == 'mycred_rank' ) {
469
  unset( $actions['inline hide-if-no-js'] );
470
+
471
  if ( !$this->rank['public'] )
472
  unset( $actions['view'] );
473
  }
474
 
475
  return $actions;
476
  }
477
+
478
  /**
479
  * Customize Users Column Headers
480
  * @since 1.1.1
496
 
497
  return mycred_get_users_rank( $user_id );
498
  }
499
+
500
  /**
501
  * Adjust Rank Column Header
502
  * @since 1.1
536
  $min = get_post_meta( $post_id, 'mycred_rank_min', true );
537
  if ( empty( $min ) && (int) $min !== 0 )
538
  $min = __( 'Any Value', 'mycred' );
539
+
540
  $min = $mycred->template_tags_general( __( 'Minimum %plural%', 'mycred' ) ) . ': ' . $min;
541
  $max = get_post_meta( $post_id, 'mycred_rank_max', true );
542
  if ( empty( $max ) )
553
  echo '<p>' . $users . '</p>';
554
  }
555
  }
556
+
557
  /**
558
  * Adjust Enter Title Here
559
  * @since 1.1
566
 
567
  return $title;
568
  }
569
+
570
  /**
571
  * Add Meta Boxes
572
  * @since 1.1
582
  'high'
583
  );
584
  }
585
+
586
  /**
587
  * Rank Settings Metabox
588
  * @since 1.1
608
  <div style="display:block;width:50%;margin:0;padding:0;float:left;">
609
  <p><?php _e( 'All Published Ranks', 'mycred' ); ?>:</p>
610
  <?php
611
+
612
  $all = mycred_get_ranks();
613
  if ( !empty( $all ) ) {
614
  foreach ( $all as $rank_id => $rank ) {
621
  }
622
  else {
623
  echo '<p>' . __( 'No Ranks found', 'mycred' ) . '.</p>';
624
+ } ?>
 
 
625
  </div>
626
  <div class="clear">&nbsp;</div>
627
  </div>
628
  <?php
629
  }
630
+
631
  /**
632
  * Save Email Notice Details
633
  * @since 1.1
642
  elseif ( !isset( $_POST['mycred_rank'] ) || !is_array( $_POST['mycred_rank'] ) ) return;
643
  // Finally check token
644
  elseif ( !wp_verify_nonce( $_POST['mycred_rank']['token'], 'mycred-edit-rank' ) ) return;
645
+
646
  // Minimum can not be empty
647
  if ( empty( $_POST['mycred_rank']['min'] ) )
648
  $min = 0;
649
  else
650
  $min = trim( $_POST['mycred_rank']['min'] );
651
+
652
  // Maximum can not be empty
653
  if ( empty( $_POST['mycred_rank']['max'] ) )
654
  $max = 999;
655
  else
656
  $max = trim( $_POST['mycred_rank']['max'] );
657
+
658
  update_post_meta( $post_id, 'mycred_rank_min', $min );
659
  update_post_meta( $post_id, 'mycred_rank_max', $max );
660
+
661
  if ( get_post_status( $post_id ) == 'publish' )
662
  $this->assign_ranks();
663
  }
664
+
665
  /**
666
  * Add to General Settings
667
  * @since 1.1
668
+ * @version 1.2
669
  */
670
+ public function after_general_settings() {
671
+ if ( $this->rank['base'] == 'current' )
672
+ $box = 'display: none;';
673
+ else
674
+ $box = 'display: block;'; ?>
675
 
676
  <h4 style="color:#BBD865;"><?php _e( 'Ranks', 'mycred' ); ?></h4>
677
  <div class="body" style="display:none;">
695
  <label for="<?php echo $this->field_id( 'public' ); ?>"><?php _e( 'If you want to create a template archive for each rank, you must select to have ranks public. Defaults to disabled.', 'mycred' ); ?></label>
696
  </li>
697
  </ol>
698
+ <label class="subheader" for="<?php echo $this->field_id( 'count' ); ?>"><?php _e( 'Rank Basis', 'mycred' ); ?></label>
699
+ <ol id="myCRED-rank-basis">
700
+ <li>
701
+ <input type="radio" name="<?php echo $this->field_name( 'base' ); ?>" id="<?php echo $this->field_id( array( 'base' => 'current' ) ); ?>"<?php checked( $this->rank['base'], 'current' ); ?> value="current" /> <label for="<?php echo $this->field_id( array( 'base' => 'current' ) ); ?>"><?php _e( 'Users are ranked according to their current balance.', 'mycred' ); ?></label>
702
+ </li>
703
+ <li>
704
+ <input type="radio" name="<?php echo $this->field_name( 'base' ); ?>" id="<?php echo $this->field_id( array( 'base' => 'total' ) ); ?>"<?php checked( $this->rank['base'], 'total' ); ?> value="total" /> <label for="<?php echo $this->field_id( array( 'base' => 'total' ) ); ?>"><?php echo $this->core->template_tags_general( __( 'Users are ranked according to the total amount of %_plural% they have accumulated.', 'mycred' ) ); ?></label>
705
+ </li>
706
+ </ol>
707
+ <div id="calc-total" style="<?php echo $box; ?>">
708
+ <label class="subheader" for=""><?php _e( 'Calculate Totals', 'mycred' ); ?></label>
709
+ <ol id="mycred-rank-calculate">
710
+ <li>
711
+ <p><?php _e( 'Use this button to calculate or re-calcualte your users totals. If not used, the users current balance will be used as a starting point.', 'mycred' ); ?><br /><?php _e( 'Once a users total has been calculated, they will be assigned to their appropirate roles. For this reason, it is highly recommended that you first setup your ranks!', 'mycred' ); ?></p>
712
+ <p><strong><?php _e( 'Depending on your log size and number of users this process may take a while. Please do not leave, click "Update Settings" or re-fresh this page until this is completed!', 'mycred' ); ?></strong></p>
713
+ <input type="button" name="mycred-update-totals" id="mycred-update-totals" value="<?php _e( 'Calculate Totals', 'mycred' ); ?>" class="button button-large button-<?php if ( $this->rank['base'] == 'current' ) echo 'secondary'; else echo 'primary'; ?>"<?php if ( $this->rank['base'] == 'current' ) echo ' disabled="disabled"'; ?> />
714
+ </li>
715
+ </ol>
716
+ </div>
717
  <label class="subheader" for="<?php echo $this->field_id( 'slug' ); ?>"><?php _e( 'Archive URL', 'mycred' ); ?></label>
718
  <ol id="">
719
  <li>
775
  echo '<input type="hidden" name="' . $this->field_name( 'bb_location' ) . '" value="" />';
776
  } ?>
777
 
778
+ <script type="text/javascript">
779
+ jQuery(function($){
780
+ $('input[name="<?php echo $this->field_name( 'base' ); ?>"]').change(function(){
781
+ var basis = $(this).val();
782
+ var button = $('#mycred-update-totals');
783
+ // Update
784
+ if ( basis != 'total' ) {
785
+ $("#calc-total").hide();
786
+ button.attr( 'disabled', 'disabled' );
787
+ button.removeClass( 'button-primary' );
788
+ button.addClass( 'button-seconday' );
789
+ }
790
+ else {
791
+ $("#calc-total").show();
792
+ button.removeAttr( 'disabled' );
793
+ button.removeClass( 'button-seconday' );
794
+ button.addClass( 'button-primary' );
795
+ }
796
+ });
797
+
798
+ var mycred_calc = function( button ) {
799
+ $.ajax({
800
+ type : "POST",
801
+ data : {
802
+ action : 'mycred-calc-totals',
803
+ token : '<?php echo wp_create_nonce( 'mycred-calc-totals' ); ?>'
804
+ },
805
+ dataType : "JSON",
806
+ url : '<?php echo admin_url( 'admin-ajax.php' ); ?>',
807
+ // Before we start
808
+ beforeSend : function() {
809
+ button.attr( 'disabled', 'disabled' );
810
+ button.removeClass( 'button-primary' );
811
+ button.addClass( 'button-seconday' );
812
+ button.val( '<?php echo __( 'Processing...', 'mycred' ); ?>' );
813
+ },
814
+ // On Successful Communication
815
+ success : function( data ) {
816
+ button.val( data );
817
+ },
818
+ // Error (sent to console)
819
+ error : function( jqXHR, textStatus, errorThrown ) {
820
+ // Debug - uncomment to use
821
+ console.log( jqXHR );
822
+ button.removeAttr( 'disabled' );
823
+ button.removeClass( 'button-seconday' );
824
+ button.addClass( 'button-primary' );
825
+ button.val( '<?php echo __( 'Script Communication Error', 'mycred' ); ?>' );
826
+ }
827
+ });
828
+ };
829
+
830
+ $('input#mycred-update-totals').click(function(){
831
+ mycred_calc( $(this) );
832
+ });
833
+ });
834
+ </script>
835
  </div>
836
  <?php
837
  }
838
+
839
  /**
840
  * Save Settings
841
  * @since 1.1
842
+ * @version 1.2
843
  */
844
  public function sanitize_extra_settings( $new_data, $data, $core ) {
845
  $new_data['rank']['support']['content'] = ( isset( $data['rank']['support']['content'] ) ) ? true : false;
847
  $new_data['rank']['support']['comments'] = ( isset( $data['rank']['support']['comments'] ) ) ? true : false;
848
  $new_data['rank']['support']['page-attributes'] = ( isset( $data['rank']['support']['page-attributes'] ) ) ? true : false;
849
  $new_data['rank']['support']['custom-fields'] = ( isset( $data['rank']['support']['custom-fields'] ) ) ? true : false;
850
+
851
+ $new_data['rank']['base'] = sanitize_text_field( $data['rank']['base'] );
852
  $new_data['rank']['public'] = ( isset( $data['rank']['public'] ) ) ? true : false;
853
  $new_data['rank']['slug'] = sanitize_text_field( $data['rank']['slug'] );
854
  $new_data['rank']['order'] = sanitize_text_field( $data['rank']['order'] );
855
  $new_data['rank']['bb_location'] = sanitize_text_field( $data['rank']['bb_location'] );
856
  return $new_data;
857
  }
858
+
859
  /**
860
  * Help
861
  * @since 1.1
868
  'title' => __( 'Ranks', 'mycred' ),
869
  'content' => '
870
  <p>' . __( 'You can create ranks according to the amount of points a user has. By default, ranks are only visible in widgets and shortcodes however it is possible for you to also create archive pages in your theme for all ranks or specific ones.', 'mycred' ) . '</p>
871
+ <p><strong>' . __( 'Rank Basis', 'mycred' ) . '</strong></p>
872
+ <p>' . $this->core->template_tags_general( __( 'As of version 1.2, you can select to rank users according to their current balance or the total amount of %_plural% they have accumulated. This is recommended if you do not want users to get demoted if they use their %_plural% to pay for items in your store or event tickets.', 'mycred' ) ) . '</p>
873
  <p><strong>' . __( 'Templates', 'mycred' ) . '</strong></p>
874
  <p>' . __( 'Ranks are just another custom post type which means that you can, if you select to make Ranks Public, create custom template files for ranks in your theme folder.', 'mycred' ) . '</p>
875
  <p>' . sprintf( __( 'For more information on Templates for Custom Post Types visit the <a href="%s">WordPress Codex</a>.', 'mycred' ), 'http://codex.wordpress.org/Post_Types#Custom_Post_Types' ) . '</p>
addons/transfer/myCRED-addon-transfer.php CHANGED
@@ -155,7 +155,7 @@ if ( !class_exists( 'myCRED_Transfer_Creds' ) ) {
155
  /**
156
  * Settings Page
157
  * @since 0.1
158
- * @version 1.0
159
  */
160
  public function after_general_settings() {
161
  // Settings
@@ -173,7 +173,7 @@ if ( !class_exists( 'myCRED_Transfer_Creds' ) ) {
173
  );
174
  $available_limits = apply_filters( 'mycred_transfer_limits', $limits, $settings ); ?>
175
 
176
- <h4 style="color:#BBD865;"><?php _e( 'Transfer CREDs', 'mycred' ); ?></h4>
177
  <div class="body" style="display:none;">
178
  <label class="subheader"><?php _e( 'Log template for sending', 'mycred' ); ?></label>
179
  <ol id="myCRED-transfer-logging-send">
@@ -455,12 +455,15 @@ if ( !class_exists( 'myCRED_Transfer_Creds' ) ) {
455
  /**
456
  * Support for Email Notices
457
  * @since 1.1
458
- * @version 1.0
459
  */
460
  public function email_notices( $data ) {
461
  if ( $data['request']['ref'] == 'transfer' ) {
462
  $message = $data['message'];
463
- $data['message'] = $this->core->template_tags_user( $message, $data['request']['ref_id'] );
 
 
 
464
  }
465
  return $data;
466
  }
155
  /**
156
  * Settings Page
157
  * @since 0.1
158
+ * @version 1.1
159
  */
160
  public function after_general_settings() {
161
  // Settings
173
  );
174
  $available_limits = apply_filters( 'mycred_transfer_limits', $limits, $settings ); ?>
175
 
176
+ <h4 style="color:#BBD865;"><?php echo $this->core->template_tags_general( __( 'Transfer %plural%', 'mycred' ) ); ?></h4>
177
  <div class="body" style="display:none;">
178
  <label class="subheader"><?php _e( 'Log template for sending', 'mycred' ); ?></label>
179
  <ol id="myCRED-transfer-logging-send">
455
  /**
456
  * Support for Email Notices
457
  * @since 1.1
458
+ * @version 1.1
459
  */
460
  public function email_notices( $data ) {
461
  if ( $data['request']['ref'] == 'transfer' ) {
462
  $message = $data['message'];
463
+ if ( $data['request']['ref_id'] == get_current_user_id() )
464
+ $data['message'] = $this->core->template_tags_user( $message, false, wp_current_user_id() );
465
+ else
466
+ $data['message'] = $this->core->template_tags_user( $message, $data['request']['ref_id'] );
467
  }
468
  return $data;
469
  }
assets/css/inline-edit.css ADDED
@@ -0,0 +1,25 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /**
2
+ * myCRED Inline Edit
3
+ * @since 1.2
4
+ * @version 1.0
5
+ */
6
+ .mycred-update-balance { background-color: white; }
7
+ .mycred-update-balance>div { padding: 12px; }
8
+ .mycred-update-balance .ui-dialog-titlebar { line-height: 24px; border-bottom: 1px solid #dedede; }
9
+ .mycred-update-balance .ui-dialog-titlebar:hover { cursor: move; }
10
+ .mycred-update-balance .ui-dialog-titlebar-close { float: right; }
11
+
12
+ body.users-php .ui-widget-overlay { position: fixed; top: 0; left: 0; background-color: rgba(51,51,51,0.2); }
13
+
14
+ .mycred-adjustment-form { display: block; float: none; clear: both; padding: 0; margin: 0; }
15
+ .mycred-adjustment-form .row { line-height: 24px; margin: 0; padding: 0; float: none; margin: 0 0 4px 0; clear: both; }
16
+ .mycred-adjustment-form .row.inline { float: left; clear: none; }
17
+ .mycred-adjustment-form .row.inline span { font-size: 18px; }
18
+
19
+ .mycred-adjustment-form .row label { display: block; margin-bottom: 0; }
20
+ .mycred-adjustment-form .row input[type="text"] { width: 90%; }
21
+ .mycred-adjustment-form .row input[type="button"] { float: right; }
22
+ input#mycred-update-users-balance-amount { width: 25%; }
23
+
24
+ #edit-mycred-balance #mycred-current.done { color: green; }
25
+ .mycred-adjustment-form .row input.error { border-color: red; }
assets/images/cred-icon16.png CHANGED
Binary file
assets/images/cred-icon32.png CHANGED
Binary file
assets/images/logo-menu.png CHANGED
Binary file
assets/js/inline-edit.js ADDED
@@ -0,0 +1,124 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /**
2
+ * myCRED Inline Edit
3
+ * @since 1.2
4
+ * @version 1.0
5
+ */
6
+ jQuery(function($) {
7
+ var username = '';
8
+ var user_id = '';
9
+ var current = '';
10
+ var current_el = '';
11
+
12
+ $(document).ready( function() {
13
+ $('#edit-mycred-balance').dialog({
14
+ dialogClass: 'mycred-update-balance',
15
+ draggable: true,
16
+ autoOpen: false,
17
+ title: myCREDedit.title,
18
+ closeText: myCREDedit.close,
19
+ modal: true,
20
+ width: 500,
21
+ height: 'auto',
22
+ resizable: false,
23
+ show: {
24
+ effect: 'slide',
25
+ direction: 'up',
26
+ duration: 250
27
+ },
28
+ hide: {
29
+ effect: 'slide',
30
+ direction: 'up',
31
+ duration: 250
32
+ }
33
+ });
34
+ });
35
+
36
+ $( 'a.mycred-open-points-editor' ).click( function() {
37
+ username = $(this).parent().parent().parent().siblings( 'td.column-username' ).find( 'strong>a' ).text();
38
+ user_id = $(this).attr( 'data-userid' );
39
+ current = $(this).attr( 'data-current' );
40
+
41
+ $( '#edit-mycred-balance' ).dialog( 'open' );
42
+
43
+ var username_el = $( '#edit-mycred-balance #mycred-username' );
44
+ username_el.empty();
45
+ username_el.text( username );
46
+
47
+ var userid_el = $( '#edit-mycred-balance #mycred-userid' );
48
+ userid_el.empty();
49
+ userid_el.text( user_id );
50
+
51
+ current_el = $( '#edit-mycred-balance #mycred-current' );
52
+ current_el.empty();
53
+ current_el.text( current );
54
+ });
55
+
56
+ $( '#mycred-update-users-balance-submit' ).click( function() {
57
+ var button = $(this);
58
+ var label = button.val();
59
+ var amount_el = $( 'input#mycred-update-users-balance-amount' );
60
+ var entry_el = $( 'input#mycred-update-users-balance-entry' );
61
+
62
+ $.ajax({
63
+ type : "POST",
64
+ data : {
65
+ action: 'mycred-inline-edit-users-balance',
66
+ token: $( 'input#mycred-update-users-balance-token' ).val(),
67
+ user: user_id,
68
+ amount: amount_el.val(),
69
+ entry: entry_el.val()
70
+ },
71
+ dataType : "JSON",
72
+ url : myCREDedit.ajaxurl,
73
+ // Before we start
74
+ beforeSend : function() {
75
+ current_el.removeClass( 'done' );
76
+ entry_el.removeClass( 'error' );
77
+ amount_el.removeClass( 'error' );
78
+
79
+ button.attr( 'value', myCREDedit.working );
80
+ button.attr( 'disabled', 'disabled' );
81
+ },
82
+ // On Successful Communication
83
+ success : function( data ) {
84
+ // Debug
85
+ console.log( data );
86
+
87
+ if ( data.status == 'OK' ) {
88
+ current_el.addClass( 'done' );
89
+ current_el.text( data.current );
90
+ amount_el.val( '' );
91
+ entry_el.val( '' );
92
+ $( 'div#mycred-user-'+user_id+'-balance span' ).text( data.current );
93
+ }
94
+ else if ( data.status == 'ERROR_1' ) {
95
+ $( '#edit-mycred-balance' ).dialog( 'destroy' );
96
+ }
97
+ else if ( data.status == 'ERROR_2' ) {
98
+ alert( data.current );
99
+ amount_el.val( '' );
100
+ entry_el.val( '' );
101
+ }
102
+ else if ( data.status == 'ERROR_3' ) {
103
+ entry_el.addClass( 'error' );
104
+ entry_el.attr( 'title', data.current );
105
+ }
106
+ else if ( data.status == 'ERROR_4' ) {
107
+ amount_el.addClass( 'error' );
108
+ amount_el.attr( 'title', data.current );
109
+ }
110
+
111
+ button.attr( 'value', label );
112
+ button.removeAttr( 'disabled' );
113
+ },
114
+ // Error (sent to console)
115
+ error : function( jqXHR, textStatus, errorThrown ) {
116
+ // Debug
117
+ console.log( jqXHR + ':' + textStatus + ':' + errorThrown );
118
+
119
+ button.attr( 'value', label );
120
+ button.removeAttr( 'disabled' );
121
+ }
122
+ });
123
+ });
124
+ });
assets/js/links.js CHANGED
@@ -1,11 +1,10 @@
1
  /**
2
  * myCRED Points for Link Clicks jQuery Scripts
3
  * @since 0.1
4
- * @version 1.0
5
  */
6
  jQuery(function($) {
7
  var mycred_click = function( points, href, id ) {
8
- //alert( 'You gained '+points+' for clicking on this link. Reference: '+href );
9
  $.ajax({
10
  type : "POST",
11
  data : {
@@ -21,15 +20,13 @@ jQuery(function($) {
21
  beforeSend : function() {},
22
  // On Successful Communication
23
  success : function( data ) {
24
- // Security token could not be verified.
25
- if ( data == 'alert' ) {
26
- alert( 'You gained '+points+' points for clicking on this link.' );
27
- }
28
  },
29
  // Error (sent to console)
30
  error : function( jqXHR, textStatus, errorThrown ) {
31
  // Debug - uncomment to use
32
  //console.log( jqXHR );
 
33
  }
34
  });
35
  };
@@ -37,9 +34,11 @@ jQuery(function($) {
37
  $('.mycred-points-link').click(function(){
38
  if ( $(this).attr( 'id' ) && $(this).attr( 'id' ) != '' ) {
39
  mycred_click( $(this).attr( 'data-amount' ), $(this).attr( 'href' ), $(this).attr( 'id' ) );
 
40
  }
41
  else {
42
  mycred_click( $(this).attr( 'data-amount' ), $(this).attr( 'href' ), '' );
 
43
  }
44
  });
45
  });
1
  /**
2
  * myCRED Points for Link Clicks jQuery Scripts
3
  * @since 0.1
4
+ * @version 1.1
5
  */
6
  jQuery(function($) {
7
  var mycred_click = function( points, href, id ) {
 
8
  $.ajax({
9
  type : "POST",
10
  data : {
20
  beforeSend : function() {},
21
  // On Successful Communication
22
  success : function( data ) {
23
+ setTimeout(function(){ window.location.href = href; }, 1000 );
 
 
 
24
  },
25
  // Error (sent to console)
26
  error : function( jqXHR, textStatus, errorThrown ) {
27
  // Debug - uncomment to use
28
  //console.log( jqXHR );
29
+ setTimeout(function(){ window.location.href = href; }, 1000 );
30
  }
31
  });
32
  };
34
  $('.mycred-points-link').click(function(){
35
  if ( $(this).attr( 'id' ) && $(this).attr( 'id' ) != '' ) {
36
  mycred_click( $(this).attr( 'data-amount' ), $(this).attr( 'href' ), $(this).attr( 'id' ) );
37
+ return false;
38
  }
39
  else {
40
  mycred_click( $(this).attr( 'data-amount' ), $(this).attr( 'href' ), '' );
41
+ return false;
42
  }
43
  });
44
  });
assets/js/video.js ADDED
@@ -0,0 +1,205 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /**
2
+ * myCRED Points for Viewing Videos
3
+ * @since 1.2
4
+ * @version 1.0
5
+ */
6
+ var timer = 0;
7
+
8
+ var duration = {};
9
+ var interval = {};
10
+ var actions = {};
11
+ var seconds = {};
12
+ var amount = {};
13
+ var logic = {};
14
+ var done = {};
15
+
16
+ /**
17
+ * onYouTubePlayerReady
18
+ * For the YouTube API hooking into onStateChange and to get the durration of a video.
19
+ * @since 1.2
20
+ * @version 1.0
21
+ */
22
+ function onYouTubePlayerReady( id ) {
23
+ // Define Player
24
+ var player = document.getElementById( id );
25
+
26
+ // Duration
27
+ duration[ id ] = player.getDuration();
28
+
29
+ // Listen in on state changes
30
+ player.addEventListener( 'onStateChange', 'mycred_video_'+id );
31
+ }
32
+
33
+ /**
34
+ * Ajax Call
35
+ * Calls home to report video views and award points
36
+ * @since 1.2
37
+ * @version 1.0
38
+ */
39
+ function mycred_video_points( id, state, length, watched, uactions, eamount, elogic, einterval ) {
40
+ if ( myCREDvideo.user_id == 0 ) return false;
41
+ // Make sure we are not done
42
+ if ( done[ id ] === undefined ) {
43
+ // Debug
44
+ //console.log( 'Received ID: '+id );
45
+
46
+ // Ajax
47
+ jQuery.ajax({
48
+ type : "POST",
49
+ data : {
50
+ action : 'mycred-video-points',
51
+ token : myCREDvideo.token,
52
+ amount : eamount,
53
+ logic : elogic,
54
+ interval : einterval,
55
+
56
+ video_id : id,
57
+ video_state : state,
58
+ video_length : length,
59
+
60
+ user_id : myCREDvideo.user_id,
61
+ user_watched : watched,
62
+ user_actions : uactions
63
+ },
64
+ dataType : "JSON",
65
+ url : myCREDvideo.ajaxurl,
66
+ // Before we start
67
+ beforeSend : function() {},
68
+ // On Successful Communication
69
+ success : function( data ) {
70
+ console.log( data );
71
+ // If maxed out, add this id to done[] so prevent further calls
72
+ // at least until the page is re-loaded.
73
+ if ( data.status === 'max' ) {
74
+ done[ data.video_id ] = data.amount;
75
+ }
76
+ },
77
+ // Error (sent to console)
78
+ error : function( jqXHR, textStatus, errorThrown ) {
79
+ console.log( jqXHR+':'+textStatus+':'+errorThrown );
80
+ }
81
+ });
82
+ }
83
+ }
84
+
85
+ /**
86
+ * Handle YouTube States
87
+ * @see https://developers.google.com/youtube/js_api_reference
88
+ * @since 1.2
89
+ * @version 1.0
90
+ */
91
+ function mycred_youtube_state( id, state, custom_amount, custom_logic, custom_interval )
92
+ {
93
+ var videoid = id;
94
+ var videostate = state;
95
+
96
+ if ( actions[ id ] === undefined ) {
97
+ actions[ id ] = '';
98
+ }
99
+ if ( seconds[ id ] === undefined ) {
100
+ seconds[ id ] = 0;
101
+ }
102
+
103
+ // Amount override
104
+ if ( custom_amount == 'def' ) {
105
+ amount[ id ] = myCREDvideo.amount;
106
+ }
107
+ else {
108
+ amount[ id ] = parseInt( custom_amount, 10 );
109
+ }
110
+
111
+ // Logic override
112
+ if ( custom_logic == 'def' ) {
113
+ logic[ id ] = myCREDvideo.logic;
114
+ }
115
+ else {
116
+ logic[ id ] = custom_logic.toString();
117
+ }
118
+
119
+ // Interval override
120
+ if ( custom_interval == 'def' ) {
121
+ interval[ id ] = parseInt( myCREDvideo.interval, 10 );
122
+ }
123
+ else {
124
+ interval[ id ] = parseInt( custom_interval, 10 );
125
+ }
126
+
127
+ // Ready
128
+ if ( state != '-1' ) {
129
+
130
+ // Points when video starts
131
+ if ( logic[ id ] == 'play' ) {
132
+ // As soon as we start playing we award points
133
+ if ( state == 1 ) {
134
+ mycred_video_points( videoid, videostate, duration[ videoid ], '', '', amount[ id ], logic[ id ], '' );
135
+ }
136
+ }
137
+
138
+ // Points first when video has ended
139
+ else if ( logic[ id ] == 'full' ) {
140
+
141
+ actions[ id ] = actions[ id ]+state.toString();
142
+
143
+ // Play
144
+ if ( state == 1 ) {
145
+ // Start timer
146
+ timer = setInterval( function() {
147
+ seconds[ id ] = seconds[ id ] + 1;
148
+ }, 1000 );
149
+ }
150
+
151
+ // Finished
152
+ else if ( state == 0 ) {
153
+ // Stop timer
154
+ clearInterval( timer );
155
+
156
+ // Notify myCRED
157
+ mycred_video_points( videoid, videostate, duration[ videoid ], seconds[ videoid ], actions[ videoid ], amount[ id ], logic[ id ], '' );
158
+
159
+ // Reset
160
+ seconds[ id ] = 0;
161
+ actions[ id ] = '';
162
+ }
163
+
164
+ // All else
165
+ else {
166
+ // Stop Timer
167
+ clearInterval( timer );
168
+ }
169
+ }
170
+
171
+ // Points per x number of seconds played
172
+ else if ( logic[ id ] == 'interval' ) {
173
+ // Update actions
174
+ actions[ id ] = actions[ id ]+state.toString();
175
+
176
+ // Video is playing
177
+ if ( state == 1 ) {
178
+ // Start timer
179
+ timer = window.setInterval( function() {
180
+ var laps = parseInt( interval[ id ] / 1000, 10 );
181
+ seconds[ id ] = seconds[ id ] + laps;
182
+ mycred_video_points( videoid, videostate, duration[ videoid ], seconds[ videoid ], actions[ videoid ], amount[ id ], logic[ id ], interval[ id ] );
183
+ }, interval[ id ] );
184
+ }
185
+
186
+ // Video has ended
187
+ else if ( state == 0 ) {
188
+ clearInterval( timer );
189
+ mycred_video_points( videoid, videostate, duration[ videoid ], seconds[ videoid ], actions[ videoid ], amount[ id ], logic[ id ], interval[ id ] );
190
+
191
+ seconds[ id ] = 0;
192
+ actions[ id ] = '';
193
+ }
194
+
195
+ // All else
196
+ else {
197
+ // Stop Timer
198
+ clearInterval( timer );
199
+ }
200
+ }
201
+ }
202
+
203
+ // Debug
204
+ //console.log( 'Video ID: ' + id + ' Actions: ' + actions[ videoid ] + ' Seconds: ' + seconds[ videoid ] + ' Logic: ' + logic[ id ] );
205
+ }
includes/mycred-admin.php CHANGED
@@ -4,7 +4,7 @@ if ( !defined( 'myCRED_VERSION' ) ) exit;
4
  * myCRED_Admin class
5
  * Manages everything concerning the WordPress admin area.
6
  * @since 0.1
7
- * @version 1.0
8
  */
9
  if ( !class_exists( 'myCRED_Admin' ) ) {
10
  class myCRED_Admin {
@@ -23,24 +23,90 @@ if ( !class_exists( 'myCRED_Admin' ) ) {
23
  /**
24
  * Load
25
  * @since 0.1
26
- * @version 1.0
27
  */
28
  public function load() {
 
29
  add_action( 'admin_head', array( $this, 'admin_header' ) );
 
 
30
  add_filter( 'manage_users_columns', array( $this, 'custom_user_column' ) );
31
  add_action( 'manage_users_custom_column', array( $this, 'custom_user_column_content' ), 10, 3 );
 
 
32
  add_action( 'profile_personal_options', array( $this, 'show_my_balance' ), 1 );
33
  add_action( 'personal_options', array( $this, 'adjust_users_balance' ), 1 );
34
  add_action( 'personal_options_update', array( $this, 'adjust_points_manually' ) );
35
  add_action( 'edit_user_profile_update', array( $this, 'adjust_points_manually' ) );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
36
  }
37
 
38
  /**
39
  * Admin Header
40
  * @since 0.1
41
- * @version 1.0
42
  */
43
  public function admin_header() {
 
 
 
 
 
 
44
  $image = plugins_url( 'assets/images/logo-menu.png', myCRED_THIS );
45
  echo '
46
  <style type="text/css">
@@ -64,11 +130,41 @@ if ( !class_exists( 'myCRED_Admin' ) ) {
64
  return $columns;
65
  }
66
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
67
  /**
68
  * Customize User Columns Content
69
  * @filter 'mycred_user_row_actions'
70
  * @since 0.1
71
- * @version 1.0
72
  */
73
  public function custom_user_column_content( $value, $column_name, $user_id ) {
74
  if ( 'mycred-balance' != $column_name ) return $value;
@@ -76,17 +172,17 @@ if ( !class_exists( 'myCRED_Admin' ) ) {
76
  // User is excluded
77
  if ( $this->core->exclude_user( $user_id ) === true ) return __( 'Excluded', 'mycred' );
78
 
79
- $balance = $this->core->get_users_cred( $user_id );
80
- $balance = $this->core->format_creds( $balance );
81
 
82
  // Row actions
83
  $row = array();
84
  $row['history'] = '<a href="' . admin_url( 'admin.php?page=myCRED&user_id=' . $user_id ) . '">' . __( 'History', 'mycred' ) . '</a>';
85
  if ( $this->core->can_edit_creds( get_current_user_id() ) )
86
- $row['adjust'] = '<a href="' . admin_url( 'user-edit.php?user_id=' . $user_id ) . '">' . __( 'Adjust', 'mycred' ) . '</a>';
87
 
88
  $rows = apply_filters( 'mycred_user_row_actions', $row, $user_id, $this->core );
89
- $balance .= '<br /><div class="row-actions">' . $this->row_actions( $rows ) . '</div>';
90
  return $balance;
91
  }
92
 
@@ -146,7 +242,7 @@ if ( !class_exists( 'myCRED_Admin' ) ) {
146
  /**
147
  * Adjust Users Balance
148
  * @since 0.1
149
- * @version 1.0
150
  */
151
  public function adjust_users_balance( $user ) {
152
  global $mycred_errors;
@@ -168,7 +264,7 @@ if ( !class_exists( 'myCRED_Admin' ) ) {
168
  if ( $this->core->can_edit_creds() && !$this->core->can_edit_plugin() )
169
  $req = '(<strong>' . __( 'required', 'mycred' ) . '</strong>)';
170
  else
171
- $req = '(optional)'; ?>
172
 
173
  <tr>
174
  <th scope="row"><label for="myCRED-manual-add-points"><?php echo $label; ?></label></th>
@@ -217,6 +313,35 @@ if ( !class_exists( 'myCRED_Admin' ) ) {
217
 
218
  $this->core->add_creds( 'manual', $user_id, $cred, $entry, get_current_user_id(), $data );
219
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
220
  }
221
  }
222
  ?>
4
  * myCRED_Admin class
5
  * Manages everything concerning the WordPress admin area.
6
  * @since 0.1
7
+ * @version 1.1
8
  */
9
  if ( !class_exists( 'myCRED_Admin' ) ) {
10
  class myCRED_Admin {
23
  /**
24
  * Load
25
  * @since 0.1
26
+ * @version 1.1
27
  */
28
  public function load() {
29
+ // Admin Styling
30
  add_action( 'admin_head', array( $this, 'admin_header' ) );
31
+
32
+ // Custom Columns
33
  add_filter( 'manage_users_columns', array( $this, 'custom_user_column' ) );
34
  add_action( 'manage_users_custom_column', array( $this, 'custom_user_column_content' ), 10, 3 );
35
+
36
+ // User Edit
37
  add_action( 'profile_personal_options', array( $this, 'show_my_balance' ), 1 );
38
  add_action( 'personal_options', array( $this, 'adjust_users_balance' ), 1 );
39
  add_action( 'personal_options_update', array( $this, 'adjust_points_manually' ) );
40
  add_action( 'edit_user_profile_update', array( $this, 'adjust_points_manually' ) );
41
+
42
+ // Sortable Column
43
+ add_filter( 'manage_users_sortable_columns', array( $this, 'sortable_points_column' ) );
44
+ add_action( 'pre_user_query', array( $this, 'sort_by_points' ) );
45
+
46
+ // Inline Editing
47
+ add_action( 'wp_ajax_mycred-inline-edit-users-balance', array( $this, 'inline_edit_user_balance' ) );
48
+ add_action( 'in_admin_footer', array( $this, 'admin_footer' ) );
49
+ }
50
+
51
+ /**
52
+ * Ajax: Inline Edit Users Balance
53
+ * @since 1.2
54
+ * @version 1.0
55
+ */
56
+ public function inline_edit_user_balance() {
57
+ // Security
58
+ check_ajax_referer( 'mycred-update-users-balance', 'token' );
59
+
60
+ // Check current user
61
+ $current_user = get_current_user_id();
62
+ if ( !mycred_is_admin( $current_user ) )
63
+ die( json_encode( array( 'status' => 'ERROR_1' ) ) );
64
+
65
+ // User
66
+ $user_id = abs( $_POST['user'] );
67
+ if ( $this->core->exclude_user( $user_id ) )
68
+ die( json_encode( array( 'status' => 'ERROR_2', 'current' => __( 'User is excluded', 'mycred' ) ) ) );
69
+
70
+ // Log entry
71
+ $entry = trim( $_POST['entry'] );
72
+ if ( $this->core->can_edit_creds() && !$this->core->can_edit_plugin() && empty( $entry ) )
73
+ die( json_encode( array( 'status' => 'ERROR_3', 'current' => __( 'Log Entry can not be empty', 'mycred' ) ) ) );
74
+
75
+ // Amount
76
+ if ( $_POST['amount'] == 0 || empty( $_POST['amount'] ) )
77
+ die( json_encode( array( 'status' => 'ERROR_4', 'current' => __( 'Amount can not be zero', 'mycred' ) ) ) );
78
+ else
79
+ $amount = $this->core->number( $_POST['amount'] );
80
+
81
+ // Data
82
+ $data = apply_filters( 'mycred_manual_change', array( 'ref_type' => 'user' ), $this );
83
+
84
+ // Execute
85
+ $this->core->add_creds(
86
+ 'manual',
87
+ $user_id,
88
+ $amount,
89
+ $entry,
90
+ $current_user,
91
+ $data
92
+ );
93
+
94
+
95
+ die( json_encode( array( 'status' => 'OK', 'current' => $this->core->get_users_cred( $user_id ) ) ) );
96
  }
97
 
98
  /**
99
  * Admin Header
100
  * @since 0.1
101
+ * @version 1.1
102
  */
103
  public function admin_header() {
104
+ $screen = get_current_screen();
105
+ if ( $screen->id == 'users' && mycred_is_admin() ) {
106
+ wp_enqueue_script( 'mycred-inline-edit' );
107
+ wp_enqueue_style( 'mycred-inline-edit' );
108
+ }
109
+
110
  $image = plugins_url( 'assets/images/logo-menu.png', myCRED_THIS );
111
  echo '
112
  <style type="text/css">
130
  return $columns;
131
  }
132
 
133
+ /**
134
+ * Sortable User Column
135
+ * @since 1.2
136
+ * @version 1.0
137
+ */
138
+ public function sortable_points_column( $columns ) {
139
+ $columns['mycred-balance'] = 'mycred';
140
+ return $columns;
141
+ }
142
+
143
+ /**
144
+ * Sort by Points
145
+ * @since 1.2
146
+ * @version 1.1
147
+ */
148
+ public function sort_by_points( $query ) {
149
+ if ( !is_admin() ) return;
150
+ $screen = get_current_screen();
151
+ if ( $screen->id != 'users' ) return;
152
+
153
+ $orderby = $query->get( 'orderby' );
154
+ if ( 'mycred' == $orderby ) {
155
+ global $wpdb;
156
+ $cred_id = $this->core->get_cred_id();
157
+ $order = $query->get( 'order' );
158
+ $query->query_from .= " LEFT JOIN {$wpdb->usermeta} ON ({$wpdb->users}.ID = {$wpdb->usermeta}.user_id AND {$wpdb->usermeta}.meta_key = '$cred_id')";
159
+ $query->query_orderby = "ORDER BY {$wpdb->usermeta}.meta_value+0 $order ";
160
+ }
161
+ }
162
+
163
  /**
164
  * Customize User Columns Content
165
  * @filter 'mycred_user_row_actions'
166
  * @since 0.1
167
+ * @version 1.1
168
  */
169
  public function custom_user_column_content( $value, $column_name, $user_id ) {
170
  if ( 'mycred-balance' != $column_name ) return $value;
172
  // User is excluded
173
  if ( $this->core->exclude_user( $user_id ) === true ) return __( 'Excluded', 'mycred' );
174
 
175
+ $ubalance = $this->core->get_users_cred( $user_id );
176
+ $balance = '<div id="mycred-user-' . $user_id . '-balance">' . $this->core->before . ' <span>' . $this->core->format_number( $ubalance ) . '</span> ' . $this->core->after . '</div>';
177
 
178
  // Row actions
179
  $row = array();
180
  $row['history'] = '<a href="' . admin_url( 'admin.php?page=myCRED&user_id=' . $user_id ) . '">' . __( 'History', 'mycred' ) . '</a>';
181
  if ( $this->core->can_edit_creds( get_current_user_id() ) )
182
+ $row['adjust'] = '<a href="javascript:void(0)" class="mycred-open-points-editor" data-userid="' . $user_id . '" data-current="' . $ubalance . '">' . __( 'Adjust', 'mycred' ) . '</a>';
183
 
184
  $rows = apply_filters( 'mycred_user_row_actions', $row, $user_id, $this->core );
185
+ $balance .= $this->row_actions( $rows );
186
  return $balance;
187
  }
188
 
242
  /**
243
  * Adjust Users Balance
244
  * @since 0.1
245
+ * @version 1.1
246
  */
247
  public function adjust_users_balance( $user ) {
248
  global $mycred_errors;
264
  if ( $this->core->can_edit_creds() && !$this->core->can_edit_plugin() )
265
  $req = '(<strong>' . __( 'required', 'mycred' ) . '</strong>)';
266
  else
267
+ $req = '(' . __( 'optional', 'mycred' ) . ')'; ?>
268
 
269
  <tr>
270
  <th scope="row"><label for="myCRED-manual-add-points"><?php echo $label; ?></label></th>
313
 
314
  $this->core->add_creds( 'manual', $user_id, $cred, $entry, get_current_user_id(), $data );
315
  }
316
+
317
+ /**
318
+ * Admin Footer
319
+ * Inserts the Inline Edit Form modal.
320
+ * @since 1.2
321
+ * @version 1.0
322
+ */
323
+ public function admin_footer() {
324
+ if ( $this->core->can_edit_creds() && !$this->core->can_edit_plugin() )
325
+ $req = '(<strong>' . __( 'required', 'mycred' ) . '</strong>)';
326
+ else
327
+ $req = '(' . __( 'optional', 'mycred' ) . ')'; ?>
328
+
329
+ <div id="edit-mycred-balance" style="display: none;">
330
+ <div class="mycred-adjustment-form">
331
+ <p class="row inline" style="width: 20%"><label><?php _e( 'ID', 'mycred' ); ?>:</label><span id="mycred-userid"></span></p>
332
+ <p class="row inline" style="width: 40%"><label><?php _e( 'User', 'mycred' ); ?>:</label><span id="mycred-username"></span></p>
333
+ <p class="row inline" style="width: 40%"><label><?php _e( 'Current Balance', 'mycred' ); ?>:</label> <span id="mycred-current"></span></p>
334
+ <div class="clear"></div>
335
+ <input type="hidden" name="mycred_update_users_balance[token]" id="mycred-update-users-balance-token" value="<?php echo wp_create_nonce( 'mycred-update-users-balance' ); ?>" />
336
+ <p class="row"><label for="mycred-update-users-balance-amount"><?php _e( 'Amount', 'mycred' ); ?>:</label><input type="text" name="mycred_update_users_balance[amount]" id="mycred-update-users-balance-amount" value="" /><br /><span class="description"><?php _e( 'A positive or negative value', 'mycred' ); ?>.</span></p>
337
+ <p class="row"><label for="mycred-update-users-balance-entry"><?php _e( 'Log Entry', 'mycred' ); ?>:</label><input type="text" name="mycred_update_users_balance[entry]" id="mycred-update-users-balance-entry" value="" /><br /><span class="description"><?php echo $req; ?></span></p>
338
+ <p class="row"><input type="button" name="mycred-update-users-balance-submit" id="mycred-update-users-balance-submit" value="Update Balance" class="button button-primary button-large" /></p>
339
+ <div class="clear"></div>
340
+ </div>
341
+ <div class="clear"></div>
342
+ </div>
343
+ <?php
344
+ }
345
  }
346
  }
347
  ?>
includes/mycred-functions.php CHANGED
@@ -181,7 +181,7 @@ if ( !class_exists( 'myCRED_Settings' ) ) {
181
  * @since 0.1
182
  * @version 1.2
183
  */
184
- public function apply_exchange_rate( $amount, $rate = 1, $round = true ) {
185
  $amount = $this->number( $amount );
186
  if ( !is_numeric( $rate ) || $rate == 1 ) return $amount;
187
 
@@ -197,16 +197,14 @@ if ( !class_exists( 'myCRED_Settings' ) ) {
197
  * @since 0.1
198
  * @version 1.0
199
  */
200
- public function parse_template_tags( $content, $log_entry ) {
201
  // Prep
202
  $reference = $log_entry->ref;
203
  $ref_id = $log_entry->ref_id;
204
  $data = $log_entry->data;
205
 
206
  // Unserialize if serialized
207
- $check = @unserialize( $data );
208
- if ( $check !== false && $data !== 'b:0;' )
209
- $data = unserialize( $data );
210
 
211
  // Run basic template tags first
212
  $content = $this->template_tags_general( $content );
@@ -241,7 +239,7 @@ if ( !class_exists( 'myCRED_Settings' ) ) {
241
  * @since 0.1
242
  * @version 1.1
243
  */
244
- public function template_tags_general( $content ) {
245
  $content = apply_filters( 'mycred_parse_tags_general', $content );
246
 
247
  // Singular
@@ -296,7 +294,7 @@ if ( !class_exists( 'myCRED_Settings' ) ) {
296
  * @since 0.1
297
  * @version 1.0.2
298
  */
299
- public function template_tags_post( $content, $ref_id = NULL, $data = '' ) {
300
  if ( $ref_id === NULL ) return $content;
301
 
302
  // Get Post Object
@@ -347,20 +345,19 @@ if ( !class_exists( 'myCRED_Settings' ) ) {
347
  * @param $data (object) Log entry data object
348
  * @return (string) parsed string
349
  * @since 0.1
350
- * @version 1.0.4
351
  */
352
- public function template_tags_user( $content, $ref_id = NULL, $data = '' ) {
353
  if ( $ref_id === NULL ) return $content;
354
 
355
  // Get User Object
356
  if ( $ref_id !== false )
357
  $user = get_userdata( $ref_id );
358
- else
359
- $user = $ref_id;
360
-
361
- // User does not exist
362
- if ( $user === false ) {
363
- if ( !is_array( $data ) || !array_key_exists( 'ID', $data ) ) return $content;
364
  $user = new StdClass();
365
  foreach ( $data as $key => $value ) {
366
  if ( $key == 'login' )
@@ -369,6 +366,7 @@ if ( !class_exists( 'myCRED_Settings' ) ) {
369
  $user->$key = $value;
370
  }
371
  }
 
372
 
373
  // Let others play first
374
  $content = apply_filters( 'mycred_parse_tags_user', $content, $user, $data );
@@ -423,7 +421,7 @@ if ( !class_exists( 'myCRED_Settings' ) ) {
423
  * @since 0.1
424
  * @version 1.0.2
425
  */
426
- public function template_tags_comment( $content, $ref_id = NULL, $data = '' ) {
427
  if ( $ref_id === NULL ) return $content;
428
 
429
  // Get Comment Object
@@ -475,7 +473,7 @@ if ( !class_exists( 'myCRED_Settings' ) ) {
475
  * @since 0.1
476
  * @version 1.0
477
  */
478
- public function allowed_tags( $data, $allow = '' ) {
479
  if ( $allow === false )
480
  return strip_tags( $data );
481
  elseif ( !empty( $allow ) )
@@ -618,7 +616,7 @@ if ( !class_exists( 'myCRED_Settings' ) ) {
618
  * @since 0.1
619
  * @version 1.0
620
  */
621
- public function exclude_user( $user_id ) {
622
  if ( $this->exclude_plugin_editors() == true && $this->can_edit_plugin( $user_id ) == true ) return true;
623
  if ( $this->exclude_creds_editors() == true && $this->can_edit_creds( $user_id ) == true ) return true;
624
  if ( $this->in_exclude_list( $user_id ) ) return true;
@@ -655,17 +653,20 @@ if ( !class_exists( 'myCRED_Settings' ) ) {
655
  *
656
  * @param $user_id (int), required user id
657
  * @param $type (string), optional cred type to check for
658
- * @returns empty if user id is not set or if no creds were found, else returns creds
659
  * @since 0.1
660
- * @version 1.0
661
  */
662
  public function get_users_cred( $user_id = '', $type = '' ) {
663
- if ( empty( $user_id ) ) return $user_id;
664
 
665
  if ( empty( $type ) ) $type = $this->get_cred_id();
666
  $balance = get_user_meta( $user_id, $type, true );
667
  if ( empty( $balance ) ) $balance = 0;
668
-
 
 
 
669
  return $this->number( $balance );
670
  }
671
 
@@ -677,7 +678,7 @@ if ( !class_exists( 'myCRED_Settings' ) ) {
677
  * @param $amount (int|float), amount to add/deduct from users balance. This value must be pre-formated.
678
  * @returns the new balance.
679
  * @since 0.1
680
- * @version 1.0
681
  */
682
  public function update_users_balance( $user_id = NULL, $amount = NULL ) {
683
  if ( $user_id === NULL || $amount === NULL ) return $amount;
@@ -693,6 +694,9 @@ if ( !class_exists( 'myCRED_Settings' ) ) {
693
  // Rankings
694
  if ( $this->frequency['rate'] == 'always' ) delete_transient( $this->cred_id . '_ranking' );
695
 
 
 
 
696
  // Return the new balance
697
  return $new_balance;
698
  }
@@ -833,6 +837,51 @@ if ( !class_exists( 'myCRED_Settings' ) ) {
833
  if ( !$new_entry ) return false;
834
  return true;
835
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
836
  }
837
  }
838
 
@@ -925,7 +974,7 @@ if ( !function_exists( 'mycred_name' ) ) {
925
  * @version 1.0
926
  */
927
  if ( !function_exists( 'mycred_strip_tags' ) ) {
928
- function mycred_strip_tags( $string, $overwride = '' )
929
  {
930
  $mycred = mycred_get_settings();
931
  return $mycred->allowed_tags( $string, $overwrite );
@@ -1198,6 +1247,62 @@ if ( !function_exists( 'mycred_get_total_by_time' ) ) {
1198
  }
1199
  }
1200
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1201
  /**
1202
  * Apply Defaults
1203
  * Based on the shortcode_atts() function with support for
181
  * @since 0.1
182
  * @version 1.2
183
  */
184
+ public function apply_exchange_rate( $amount = 0, $rate = 1, $round = true ) {
185
  $amount = $this->number( $amount );
186
  if ( !is_numeric( $rate ) || $rate == 1 ) return $amount;
187
 
197
  * @since 0.1
198
  * @version 1.0
199
  */
200
+ public function parse_template_tags( $content = '', $log_entry ) {
201
  // Prep
202
  $reference = $log_entry->ref;
203
  $ref_id = $log_entry->ref_id;
204
  $data = $log_entry->data;
205
 
206
  // Unserialize if serialized
207
+ $data = maybe_unserialize( $data );
 
 
208
 
209
  // Run basic template tags first
210
  $content = $this->template_tags_general( $content );
239
  * @since 0.1
240
  * @version 1.1
241
  */
242
+ public function template_tags_general( $content = '' ) {
243
  $content = apply_filters( 'mycred_parse_tags_general', $content );
244
 
245
  // Singular
294
  * @since 0.1
295
  * @version 1.0.2
296
  */
297
+ public function template_tags_post( $content = '', $ref_id = NULL, $data = '' ) {
298
  if ( $ref_id === NULL ) return $content;
299
 
300
  // Get Post Object
345
  * @param $data (object) Log entry data object
346
  * @return (string) parsed string
347
  * @since 0.1
348
+ * @version 1.1
349
  */
350
+ public function template_tags_user( $content = '', $ref_id = NULL, $data = '' ) {
351
  if ( $ref_id === NULL ) return $content;
352
 
353
  // Get User Object
354
  if ( $ref_id !== false )
355
  $user = get_userdata( $ref_id );
356
+ // User object is passed on though $data
357
+ elseif ( $ref_id === false && is_object( $data ) && isset( $data->ID ) )
358
+ $user = $data;
359
+ // User array is passed on though $data
360
+ elseif ( $ref_id === false && is_array( $data ) || array_key_exists( 'ID', $data ) ) {
 
361
  $user = new StdClass();
362
  foreach ( $data as $key => $value ) {
363
  if ( $key == 'login' )
366
  $user->$key = $value;
367
  }
368
  }
369
+ else return $content;
370
 
371
  // Let others play first
372
  $content = apply_filters( 'mycred_parse_tags_user', $content, $user, $data );
421
  * @since 0.1
422
  * @version 1.0.2
423
  */
424
+ public function template_tags_comment( $content = '', $ref_id = NULL, $data = '' ) {
425
  if ( $ref_id === NULL ) return $content;
426
 
427
  // Get Comment Object
473
  * @since 0.1
474
  * @version 1.0
475
  */
476
+ public function allowed_tags( $data = '', $allow = '' ) {
477
  if ( $allow === false )
478
  return strip_tags( $data );
479
  elseif ( !empty( $allow ) )
616
  * @since 0.1
617
  * @version 1.0
618
  */
619
+ public function exclude_user( $user_id = 0 ) {
620
  if ( $this->exclude_plugin_editors() == true && $this->can_edit_plugin( $user_id ) == true ) return true;
621
  if ( $this->exclude_creds_editors() == true && $this->can_edit_creds( $user_id ) == true ) return true;
622
  if ( $this->in_exclude_list( $user_id ) ) return true;
653
  *
654
  * @param $user_id (int), required user id
655
  * @param $type (string), optional cred type to check for
656
+ * @returns zero if user id is not set or if no creds were found, else returns amount
657
  * @since 0.1
658
+ * @version 1.2
659
  */
660
  public function get_users_cred( $user_id = '', $type = '' ) {
661
+ if ( empty( $user_id ) ) return 0;
662
 
663
  if ( empty( $type ) ) $type = $this->get_cred_id();
664
  $balance = get_user_meta( $user_id, $type, true );
665
  if ( empty( $balance ) ) $balance = 0;
666
+
667
+ // Let others play
668
+ $balance = apply_filters( 'mycred_get_users_cred', $balance, $this, $user_id, $type );
669
+
670
  return $this->number( $balance );
671
  }
672
 
678
  * @param $amount (int|float), amount to add/deduct from users balance. This value must be pre-formated.
679
  * @returns the new balance.
680
  * @since 0.1
681
+ * @version 1.1
682
  */
683
  public function update_users_balance( $user_id = NULL, $amount = NULL ) {
684
  if ( $user_id === NULL || $amount === NULL ) return $amount;
694
  // Rankings
695
  if ( $this->frequency['rate'] == 'always' ) delete_transient( $this->cred_id . '_ranking' );
696
 
697
+ // Let others play
698
+ do_action( 'mycred_update_user_balance', $user_id, $current_balance, $amount, $this->cred_id );
699
+
700
  // Return the new balance
701
  return $new_balance;
702
  }
837
  if ( !$new_entry ) return false;
838
  return true;
839
  }
840
+
841
+ /**
842
+ * Has Entry
843
+ * Checks to see if a given action with reference ID and user ID exists in the log database.
844
+ * @param $reference (string) required reference ID
845
+ * @param $ref_id (int) optional reference id
846
+ * @param $user_id (int) optional user id
847
+ * @param $data (array|string) option data to search
848
+ * @since 0.1
849
+ * @version 1.1
850
+ */
851
+ function has_entry( $reference = '', $ref_id = '', $user_id = '', $data = '' ) {
852
+ global $wpdb;
853
+
854
+ $where = $prep = array();
855
+ if ( !empty( $reference ) ) {
856
+ $where[] = 'ref = %s';
857
+ $prep[] = $reference;
858
+ }
859
+
860
+ if ( !empty( $ref_id ) ) {
861
+ $where[] = 'ref_id = %d';
862
+ $prep[] = $ref_id;
863
+ }
864
+
865
+ if ( !empty( $user_id ) ) {
866
+ $where[] = 'user_id = %d';
867
+ $prep[] = abs( $user_id );
868
+ }
869
+
870
+ if ( !empty( $data ) ) {
871
+ $where[] = 'data = %s';
872
+ $prep[] = maybe_serialize( $data );
873
+ }
874
+
875
+ $where = implode( ' AND ', $where );
876
+
877
+ if ( !empty( $where ) ) {
878
+ $sql = "SELECT * FROM " . $wpdb->prefix . 'myCRED_log' . " WHERE $where";
879
+ $wpdb->get_results( $wpdb->prepare( $sql, $prep ) );
880
+ if ( $wpdb->num_rows > 0 ) return true;
881
+ }
882
+
883
+ return false;
884
+ }
885
  }
886
  }
887
 
974
  * @version 1.0
975
  */
976
  if ( !function_exists( 'mycred_strip_tags' ) ) {
977
+ function mycred_strip_tags( $string = '', $overwride = '' )
978
  {
979
  $mycred = mycred_get_settings();
980
  return $mycred->allowed_tags( $string, $overwrite );
1247
  }
1248
  }
1249
 
1250
+ /**
1251
+ * Get users total creds
1252
+ * Returns the users total creds unformated. If no total is fuond,
1253
+ * the users current balance is returned instead.
1254
+ *
1255
+ * @param $user_id (int), required user id
1256
+ * @param $type (string), optional cred type to check for
1257
+ * @returns zero if user id is not set or if no total were found, else returns creds
1258
+ * @since 1.2
1259
+ * @version 1.0
1260
+ */
1261
+ if ( !function_exists( 'mycred_get_users_total' ) ) {
1262
+ function mycred_get_users_total( $user_id = '', $type = '' ) {
1263
+ if ( empty( $user_id ) ) return 0;
1264
+
1265
+ $mycred = mycred_get_settings();
1266
+ if ( empty( $type ) ) $type = $mycred->get_cred_id();
1267
+ $total = get_user_meta( $user_id, $type . '_total', true );
1268
+ if ( empty( $total ) ) $total = $mycred->get_users_cred( $user_id, $type );
1269
+
1270
+ return $mycred->number( $total );
1271
+ }
1272
+ }
1273
+
1274
+ /**
1275
+ * Update users total creds
1276
+ * Updates a given users total creds balance.
1277
+ *
1278
+ * @param $user_id (int), required user id
1279
+ * @param $request (array), required request array with information on users id (user_id) and amount
1280
+ * @param $mycred (myCRED_Settings object), required myCRED settings object
1281
+ * @returns zero if user id is not set or if no total were found, else returns total
1282
+ * @since 1.2
1283
+ * @version 1.0
1284
+ */
1285
+ if ( !function_exists( 'mycred_update_users_total' ) ) {
1286
+ function mycred_update_users_total( $type = '', $request = NULL, $mycred = NULL ) {
1287
+ if ( $request === NULL || !is_object( $mycred ) || !isset( $request['user_id'] ) || !isset( $request['amount'] ) ) return false;
1288
+ if ( $request['amount'])
1289
+ if ( empty( $type ) ) $type = $mycred->get_cred_id();
1290
+
1291
+ do_action( 'mycred_update_users_total', $request, $type, $mycred );
1292
+
1293
+ $amount = $mycred->number( $request['amount'] );
1294
+ if ( $amount < 0 || $amount == 0 ) return;
1295
+
1296
+ $user_id = $request['user_id'];
1297
+ $users_total = mycred_get_users_total( $user_id, $type );
1298
+
1299
+ $new_total = $mycred->number( $users_total+$amount );
1300
+ update_user_meta( $user_id, $type . '_total', $new_total );
1301
+
1302
+ return $new_total;
1303
+ }
1304
+ }
1305
+
1306
  /**
1307
  * Apply Defaults
1308
  * Based on the shortcode_atts() function with support for
includes/mycred-install.php CHANGED
@@ -132,7 +132,7 @@ if ( !class_exists( 'myCRED_Install' ) ) {
132
  * Uninstall
133
  * @filter 'mycred_uninstall_this'
134
  * @since 0.1
135
- * @version 1.0
136
  */
137
  public function uninstall() {
138
  // Everyone should use this filter to delete everything else they have created before returning the option ids.
@@ -157,6 +157,10 @@ if ( !class_exists( 'myCRED_Install' ) ) {
157
 
158
  delete_option( 'mycred_transients' );
159
 
 
 
 
 
160
  // Clear Cron
161
  wp_clear_scheduled_hook( 'mycred_reset_key' );
162
 
132
  * Uninstall
133
  * @filter 'mycred_uninstall_this'
134
  * @since 0.1
135
+ * @version 1.1
136
  */
137
  public function uninstall() {
138
  // Everyone should use this filter to delete everything else they have created before returning the option ids.
157
 
158
  delete_option( 'mycred_transients' );
159
 
160
+ // Remove Add-on settings
161
+ delete_option( 'mycred_espresso_gateway_prefs' );
162
+ delete_option( 'mycred_eventsmanager_gateway_prefs' );
163
+
164
  // Clear Cron
165
  wp_clear_scheduled_hook( 'mycred_reset_key' );
166
 
includes/mycred-shortcodes.php CHANGED
@@ -290,4 +290,81 @@ if ( !function_exists( 'mycred_render_shortcode_send' ) ) {
290
  return '<input type="button" class="mycred-send-points-button" data-to="' . $to . '" data-ref="' . $ref . '" data-log="' . $log . '" data-amount="' . $amount . '" data-type="' . $type . '" value="' . $mycred->template_tags_general( $content ) . '" />';
291
  }
292
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
293
  ?>
290
  return '<input type="button" class="mycred-send-points-button" data-to="' . $to . '" data-ref="' . $ref . '" data-log="' . $log . '" data-amount="' . $amount . '" data-type="' . $type . '" value="' . $mycred->template_tags_general( $content ) . '" />';
291
  }
292
  }
293
+
294
+ /**
295
+ * myCRED Shortcode: mycred_video
296
+ * This shortcode allows points to be given to the current user
297
+ * for watchinga YouTube video.
298
+ * @see http://mycred.me/shortcodes/mycred_video/
299
+ * @since 1.2
300
+ * @version 1.0
301
+ */
302
+ if ( !function_exists( 'mycred_render_shortcode_video' ) ) {
303
+ function mycred_render_shortcode_video( $atts, $content )
304
+ {
305
+ global $mycred_video_points;
306
+
307
+ extract( shortcode_atts( array(
308
+ 'id' => NULL,
309
+ 'width' => 0,
310
+ 'height' => 0,
311
+ 'amount' => 'def',
312
+ 'logic' => 'def',
313
+ 'interval' => 'def'
314
+ ), $atts ) );
315
+
316
+ // ID is required
317
+ if ( $id === NULL ) return __( 'A video ID is required for this shortcode', 'mycred' );
318
+
319
+ // Width
320
+ if ( $width == 0 )
321
+ $width = 560;
322
+
323
+ // Height
324
+ if ( $height == 0 )
325
+ $height = 315;
326
+
327
+ // Prep Interval by converting it to Miliseconds
328
+ if ( $interval != 'def' )
329
+ $interval = $interval*1000;
330
+
331
+ // Video ID
332
+ $video_id = str_replace( '-', '__', $id );
333
+
334
+ // Construct YouTube Query
335
+ $query = apply_filters( 'mycred_video_query', array(
336
+ 'enablejsapi' => 1,
337
+ 'version' => 3,
338
+ 'playerapiid' => $video_id,
339
+ 'rel' => 0,
340
+ 'controls' => 1,
341
+ 'showinfo' => 0
342
+ ), $atts, $video_id );
343
+
344
+ // Construct Youtube Query Address
345
+ $url = 'http://www.youtube.com/v/' . $id;
346
+ $url = add_query_arg( $query, $url );
347
+
348
+ // Construct Flash Embed
349
+ $embed_args = apply_filters( 'mycred_video_embed_args', array(
350
+ '"' . $url . '"', '"' . $video_id . '"', '"' . $width . '"', '"' . $height . '"', '"9.0.0"', 'null', 'null', '{ allowScriptAccess: "always", wmode: "transparent" }', 'null'
351
+ ), $atts );
352
+
353
+ // Output
354
+ return apply_filters( 'mycred_video_output', '
355
+ <div class="mycred-video-wrapper">
356
+ <script type="text/javascript">
357
+ swfobject.embedSWF(' . implode( ', ', $embed_args ) . ');
358
+ </script>
359
+ <div id="' . $video_id . '_container">
360
+ <div id="' . $video_id . '"></div>
361
+ </div>
362
+ <script type="text/javascript">
363
+ function mycred_video_' . $video_id . '(state) {
364
+ mycred_youtube_state( "' . $video_id . '", state, "' . $amount . '", "' . $logic . '", "' . $interval . '" );
365
+ }
366
+ </script>
367
+ </div>' . "\n", $atts, $embed_args, $video_id );
368
+ }
369
+ }
370
  ?>
includes/mycred-widgets.php CHANGED
@@ -55,7 +55,7 @@ if ( !class_exists( 'myCRED_Widget_Balance' ) ) {
55
  if ( empty( $balance ) ) $balance = 0;
56
 
57
  $layout = $mycred->template_tags_amount( $instance['cred_format'], $balance );
58
- $layout = $mycred->template_tags_user( $layout, $user_id );
59
 
60
  // Include Ranking
61
  if ( $instance['show_rank'] ) {
55
  if ( empty( $balance ) ) $balance = 0;
56
 
57
  $layout = $mycred->template_tags_amount( $instance['cred_format'], $balance );
58
+ $layout = $mycred->template_tags_user( $layout, false, wp_get_current_user() );
59
 
60
  // Include Ranking
61
  if ( $instance['show_rank'] ) {
modules/mycred-module-addons.php CHANGED
@@ -269,7 +269,7 @@ if ( !class_exists( 'myCRED_Addons' ) ) {
269
  if ( !empty( $installed ) ) {
270
  foreach ( $installed as $key => $data ) { ?>
271
 
272
- <h4 class="<?php if ( $this->is_active( $key ) ) echo 'active'; else echo 'inactive'; ?>"><label><?php echo $this->core->template_tags_general( $data['name'] ); ?></label></h4>
273
  <div class="body" style="display:none;">
274
  <div class="wrapper">
275
  <?php $this->present_addon( $key ); ?>
@@ -347,7 +347,7 @@ if ( !class_exists( 'myCRED_Addons' ) ) {
347
  public function present_addon( $key ) {
348
  $addon_data = $this->installed[$key]; ?>
349
 
350
- <div class="description h2"><?php echo $this->core->template_tags_general( $addon_data['description'] ); ?></div>
351
  <p class="links"><?php echo $this->addon_links( $key ); ?></p>
352
  <p><?php echo $this->activate_deactivate( $key ); ?></p>
353
  <div class="clear">&nbsp;</div>
269
  if ( !empty( $installed ) ) {
270
  foreach ( $installed as $key => $data ) { ?>
271
 
272
+ <h4 class="<?php if ( $this->is_active( $key ) ) echo 'active'; else echo 'inactive'; ?>"><label><?php _e( $this->core->template_tags_general( $data['name'] ), 'mycred' ); ?></label></h4>
273
  <div class="body" style="display:none;">
274
  <div class="wrapper">
275
  <?php $this->present_addon( $key ); ?>
347
  public function present_addon( $key ) {
348
  $addon_data = $this->installed[$key]; ?>
349
 
350
+ <div class="description h2"><?php _e( $this->core->template_tags_general( $addon_data['description'] ), 'mycred' ); ?></div>
351
  <p class="links"><?php echo $this->addon_links( $key ); ?></p>
352
  <p><?php echo $this->activate_deactivate( $key ); ?></p>
353
  <div class="clear">&nbsp;</div>
modules/mycred-module-general.php CHANGED
@@ -29,7 +29,7 @@ if ( !class_exists( 'myCRED_General' ) ) {
29
  /**
30
  * Admin Page
31
  * @since 0.1
32
- * @version 1.0
33
  */
34
  public function admin_page() {
35
  if ( !$this->core->can_edit_plugin( get_current_user_id() ) ) wp_die( __( 'Access Denied' ) );
@@ -48,7 +48,7 @@ if ( !class_exists( 'myCRED_General' ) ) {
48
  <div id="mycred-social">
49
  <a href="https://www.facebook.com/myCRED" class="zocial facebook" target="_blank">Facebook</a>
50
  <a href="https://plus.google.com/b/102981932999764129220/102981932999764129220/posts" class="zocial googleplus" target="_blank">Google Plus</a>
51
- <a href="http://wordpress.org/support/plugin/mycred" class="zocial wordpress" target="_blank">Support Forum</a>
52
  </div>
53
  <form method="post" action="options.php">
54
  <?php settings_fields( 'myCRED-general' ); ?>
29
  /**
30
  * Admin Page
31
  * @since 0.1
32
+ * @version 1.1
33
  */
34
  public function admin_page() {
35
  if ( !$this->core->can_edit_plugin( get_current_user_id() ) ) wp_die( __( 'Access Denied' ) );
48
  <div id="mycred-social">
49
  <a href="https://www.facebook.com/myCRED" class="zocial facebook" target="_blank">Facebook</a>
50
  <a href="https://plus.google.com/b/102981932999764129220/102981932999764129220/posts" class="zocial googleplus" target="_blank">Google Plus</a>
51
+ <a href="http://mycred.me/support/forums/" class="zocial wordpress" target="_blank">Support Forum</a>
52
  </div>
53
  <form method="post" action="options.php">
54
  <?php settings_fields( 'myCRED-general' ); ?>
modules/mycred-module-help.php CHANGED
@@ -4,7 +4,7 @@ if ( !defined( 'myCRED_VERSION' ) ) exit;
4
  * myCRED_Help class
5
  * Adds contextual help for myCRED pages and features.
6
  * @since 0.1
7
- * @version 1.0
8
  */
9
  if ( !class_exists( 'myCRED_Help' ) ) {
10
  class myCRED_Help {
@@ -18,8 +18,8 @@ if ( !class_exists( 'myCRED_Help' ) ) {
18
  function __construct() {
19
  if ( is_admin() )
20
  $this->is_admin = true;
21
-
22
- $this->is_admin = false;
23
  }
24
 
25
  /**
@@ -29,7 +29,6 @@ if ( !class_exists( 'myCRED_Help' ) ) {
29
  */
30
  public function load() {
31
  if ( $this->is_admin ) return;
32
-
33
  add_filter( 'contextual_help', array( $this, 'run' ), 10, 3 );
34
  }
35
 
4
  * myCRED_Help class
5
  * Adds contextual help for myCRED pages and features.
6
  * @since 0.1
7
+ * @version 1.0.1
8
  */
9
  if ( !class_exists( 'myCRED_Help' ) ) {
10
  class myCRED_Help {
18
  function __construct() {
19
  if ( is_admin() )
20
  $this->is_admin = true;
21
+ else
22
+ $this->is_admin = false;
23
  }
24
 
25
  /**
29
  */
30
  public function load() {
31
  if ( $this->is_admin ) return;
 
32
  add_filter( 'contextual_help', array( $this, 'run' ), 10, 3 );
33
  }
34
 
modules/mycred-module-hooks.php CHANGED
@@ -118,7 +118,14 @@ if ( !class_exists( 'myCRED_Hooks' ) ) {
118
  'description' => __( 'Award %_plural% to users who clicks on links generated by the [mycred_link] shortcode.', 'mycred' ),
119
  'callback' => array( 'myCRED_Hook_Click_Links' )
120
  );
121
-
 
 
 
 
 
 
 
122
  // Prep for bbPress
123
  if ( class_exists( 'bbPress' ) ) {
124
  $installed['hook_bbpress'] = array(
@@ -191,6 +198,15 @@ if ( !class_exists( 'myCRED_Hooks' ) ) {
191
  );
192
  }
193
 
 
 
 
 
 
 
 
 
 
194
  $installed = apply_filters( 'mycred_setup_hooks', $installed );
195
 
196
  if ( $save === true && $this->core->can_edit_plugin() ) {
@@ -574,7 +590,7 @@ if ( !class_exists( 'myCRED_Hook_Publishing_Content' ) ) {
574
  if ( in_array( $old_status, $status ) && $new_status == 'publish' && array_key_exists( $post_type, $this->prefs ) ) {
575
 
576
  // Make sure this is unique
577
- if ( $this->has_entry( 'publishing_content', $post_id, $user_id ) ) return;
578
 
579
  // Prep
580
  $entry = $this->prefs[$post_type]['log'];
@@ -1117,7 +1133,7 @@ if ( !class_exists( 'myCRED_Hook_Click_Links' ) ) {
1117
  /**
1118
  * Custom Has Entry Check
1119
  * @since 1.1
1120
- * @version 1.0
1121
  */
1122
  public function has_entry( $action = '', $reference = '', $user_id = '', $data = '' ) {
1123
  global $wpdb;
@@ -1130,8 +1146,8 @@ if ( !class_exists( 'myCRED_Hook_Click_Links' ) ) {
1130
  }
1131
  else return false;
1132
 
1133
- $sql = "SELECT id FROM " . $wpdb->prefix . 'myCRED_log' . " WHERE ref = %s AND data LIKE %s";
1134
- $wpdb->get_results( $wpdb->prepare( $sql, $action, $string ) );
1135
  if ( $wpdb->num_rows > 0 ) return true;
1136
 
1137
  return false;
@@ -1140,7 +1156,7 @@ if ( !class_exists( 'myCRED_Hook_Click_Links' ) ) {
1140
  /**
1141
  * AJAX Call Handler
1142
  * @since 1.1
1143
- * @version 1.0
1144
  */
1145
  public function ajax_call_link_points() {
1146
  // We must be logged in
@@ -1149,8 +1165,11 @@ if ( !class_exists( 'myCRED_Hook_Click_Links' ) ) {
1149
  // Security
1150
  check_ajax_referer( 'mycred-link-points', 'token' );
1151
 
 
 
 
1152
  // Check if user should be excluded
1153
- if ( $this->core->exclude_user( get_current_user_id() ) === true ) return;
1154
 
1155
  // If amount is not set we default
1156
  if ( $_POST['amount'] == 0 )
@@ -1161,12 +1180,12 @@ if ( !class_exists( 'myCRED_Hook_Click_Links' ) ) {
1161
  // Limits
1162
  if ( $this->prefs['limit_by'] == 'url' ) {
1163
  if ( !isset( $_POST['url'] ) || empty( $_POST['url'] ) ) die();
1164
- if ( $this->has_entry( 'link_click', $_POST['url'] ) ) die();
1165
  $ref = $_POST['url'];
1166
  }
1167
  elseif ( $this->prefs['limit_by'] == 'id' ) {
1168
  if ( !isset( $_POST['eid'] ) || empty( $_POST['eid'] ) ) die();
1169
- if ( $this->has_entry( 'link_click', $_POST['eid'] ) ) die();
1170
  $ref = $_POST['eid'];
1171
  }
1172
  else {
@@ -1176,7 +1195,7 @@ if ( !class_exists( 'myCRED_Hook_Click_Links' ) ) {
1176
  // Execute
1177
  $this->core->add_creds(
1178
  'link_click',
1179
- get_current_user_id(),
1180
  $amount,
1181
  $this->prefs['log'],
1182
  $ref,
@@ -1227,4 +1246,313 @@ if ( !class_exists( 'myCRED_Hook_Click_Links' ) ) {
1227
  }
1228
  }
1229
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1230
  ?>
118
  'description' => __( 'Award %_plural% to users who clicks on links generated by the [mycred_link] shortcode.', 'mycred' ),
119
  'callback' => array( 'myCRED_Hook_Click_Links' )
120
  );
121
+
122
+ // Video Views
123
+ $installed['video_view'] = array(
124
+ 'title' => __( '%plural% for viewing Videos', 'mycred' ),
125
+ 'description' => __( 'Award %_plural% to users who watches videos embedded using the [mycred_video] shortcode.', 'mycred' ),
126
+ 'callback' => array( 'myCRED_Hook_Video_Views' )
127
+ );
128
+
129
  // Prep for bbPress
130
  if ( class_exists( 'bbPress' ) ) {
131
  $installed['hook_bbpress'] = array(
198
  );
199
  }
200
 
201
+ // GD Star
202
+ if ( defined( 'STARRATING_DEBUG' ) ) {
203
+ $installed['gdstars'] = array(
204
+ 'title' => __( 'GD Star Rating', 'mycred' ),
205
+ 'description' => __( 'Awards %_plural% for users rate items using the GD Star Rating plugin.', 'mycred' ),
206
+ 'callback' => array( 'myCRED_Hook_GD_Star_Rating' )
207
+ );
208
+ }
209
+
210
  $installed = apply_filters( 'mycred_setup_hooks', $installed );
211
 
212
  if ( $save === true && $this->core->can_edit_plugin() ) {
590
  if ( in_array( $old_status, $status ) && $new_status == 'publish' && array_key_exists( $post_type, $this->prefs ) ) {
591
 
592
  // Make sure this is unique
593
+ if ( $this->core->has_entry( 'publishing_content', $post_id, $user_id ) ) return;
594
 
595
  // Prep
596
  $entry = $this->prefs[$post_type]['log'];
1133
  /**
1134
  * Custom Has Entry Check
1135
  * @since 1.1
1136
+ * @version 1.1
1137
  */
1138
  public function has_entry( $action = '', $reference = '', $user_id = '', $data = '' ) {
1139
  global $wpdb;
1146
  }
1147
  else return false;
1148
 
1149
+ $sql = "SELECT id FROM " . $wpdb->prefix . 'myCRED_log' . " WHERE ref = %s AND user_id = %d AND data LIKE %s";
1150
+ $wpdb->get_results( $wpdb->prepare( $sql, $action, $user_id, $string ) );
1151
  if ( $wpdb->num_rows > 0 ) return true;
1152
 
1153
  return false;
1156
  /**
1157
  * AJAX Call Handler
1158
  * @since 1.1
1159
+ * @version 1.1
1160
  */
1161
  public function ajax_call_link_points() {
1162
  // We must be logged in
1165
  // Security
1166
  check_ajax_referer( 'mycred-link-points', 'token' );
1167
 
1168
+ // Current User
1169
+ $user_id = get_current_user_id();
1170
+
1171
  // Check if user should be excluded
1172
+ if ( $this->core->exclude_user( $user_id ) ) return;
1173
 
1174
  // If amount is not set we default
1175
  if ( $_POST['amount'] == 0 )
1180
  // Limits
1181
  if ( $this->prefs['limit_by'] == 'url' ) {
1182
  if ( !isset( $_POST['url'] ) || empty( $_POST['url'] ) ) die();
1183
+ if ( $this->has_entry( 'link_click', $_POST['url'], $user_id ) ) die();
1184
  $ref = $_POST['url'];
1185
  }
1186
  elseif ( $this->prefs['limit_by'] == 'id' ) {
1187
  if ( !isset( $_POST['eid'] ) || empty( $_POST['eid'] ) ) die();
1188
+ if ( $this->has_entry( 'link_click', $_POST['eid'], $user_id ) ) die();
1189
  $ref = $_POST['eid'];
1190
  }
1191
  else {
1195
  // Execute
1196
  $this->core->add_creds(
1197
  'link_click',
1198
+ $user_id,
1199
  $amount,
1200
  $this->prefs['log'],
1201
  $ref,
1246
  }
1247
  }
1248
  }
1249
+
1250
+ /**
1251
+ * Hooks for Viewing Videos
1252
+ * @since 1.2
1253
+ * @version 1.0
1254
+ */
1255
+ if ( !class_exists( 'myCRED_Hook_Video_Views' ) ) {
1256
+ class myCRED_Hook_Video_Views extends myCRED_Hook {
1257
+
1258
+ /**
1259
+ * Construct
1260
+ */
1261
+ function __construct( $hook_prefs ) {
1262
+ parent::__construct( array(
1263
+ 'id' => 'video_view',
1264
+ 'defaults' => array(
1265
+ 'creds' => 1,
1266
+ 'log' => '%plural% for viewing video',
1267
+ 'logic' => 'play',
1268
+ 'interval' => '',
1269
+ 'leniency' => 10
1270
+ )
1271
+ ), $hook_prefs );
1272
+ }
1273
+
1274
+ /**
1275
+ * Run
1276
+ * @since 1.2
1277
+ * @version 1.0
1278
+ */
1279
+ public function run() {
1280
+ add_action( 'mycred_front_enqueue', array( $this, 'register_script' ) );
1281
+
1282
+ add_shortcode( 'mycred_video', 'mycred_render_shortcode_video' );
1283
+ add_action( 'wp_ajax_mycred-video-points', array( $this, 'ajax_call_video_points' ) );
1284
+ }
1285
+
1286
+ /**
1287
+ * Register Script
1288
+ * @since 1.2
1289
+ * @version 1.0
1290
+ */
1291
+ public function register_script() {
1292
+ wp_register_script(
1293
+ 'mycred-video-points',
1294
+ plugins_url( 'assets/js/video.js', myCRED_THIS ),
1295
+ array( 'jquery', 'swfobject' ),
1296
+ myCRED_VERSION . '.1',
1297
+ true
1298
+ );
1299
+ wp_localize_script(
1300
+ 'mycred-video-points',
1301
+ 'myCREDvideo',
1302
+ array(
1303
+ 'ajaxurl' => admin_url( 'admin-ajax.php' ),
1304
+ 'token' => wp_create_nonce( 'mycred-video-points' ),
1305
+ 'interval' => abs( $this->prefs['interval']*1000 ),
1306
+ 'logic' => $this->prefs['logic'],
1307
+ 'amount' => $this->prefs['creds'],
1308
+ 'user_id' => get_current_user_id()
1309
+ )
1310
+ );
1311
+ wp_enqueue_script( 'mycred-video-points' );
1312
+ }
1313
+
1314
+ /**
1315
+ * AJAX Call Handler
1316
+ * @since 1.2
1317
+ * @version 1.0
1318
+ */
1319
+ public function ajax_call_video_points() {
1320
+ // We must be logged in
1321
+ if ( !is_user_logged_in() ) die();
1322
+
1323
+ // Security
1324
+ check_ajax_referer( 'mycred-video-points', 'token' );
1325
+
1326
+ $award = false;
1327
+ $status = 'silence';
1328
+
1329
+ // Check for amount override
1330
+ if ( isset( $_POST['amount'] ) && $_POST['amount'] != $this->prefs['creds'] )
1331
+ $amount = $this->core->number( $_POST['amount'] );
1332
+ else
1333
+ $amount = $this->prefs['creds'];
1334
+
1335
+ // Check for logic override
1336
+ if ( isset( $_POST['logic'] ) || $_POST['logic'] != $this->prefs['logic'] )
1337
+ $logic = $_POST['logic'];
1338
+ else
1339
+ $logic = $this->prefs['logic'];
1340
+
1341
+ // Check for interval override
1342
+ if ( isset( $_POST['interval'] ) && !empty( $_POST['interval'] ) )
1343
+ $interval = abs( $_POST['interval']/1000 );
1344
+ else
1345
+ $interval = abs( $this->prefs['interval'] );
1346
+
1347
+ $video_id = trim( $_POST['video_id'] );
1348
+ $state = trim( $_POST['video_state'] );
1349
+ $duration = abs( $_POST['video_length'] );
1350
+
1351
+ $user_id = abs( $_POST['user_id'] );
1352
+ $watched = abs( $_POST['user_watched'] );
1353
+ $actions = trim( $_POST['user_actions'] );
1354
+
1355
+ // Apply Leniency
1356
+ $leniency = $duration*($this->prefs['leniency']/100);
1357
+ $leniency = floor( $leniency );
1358
+ $watched = $watched + $leniency;
1359
+
1360
+ // Award points as soon as video starts
1361
+ if ( $logic == 'play' ) {
1362
+ if ( $state == 1 && !$this->has_entry( 'watching_video', '', $user_id, $video_id ) ) {
1363
+ $award = true;
1364
+
1365
+ // Execute
1366
+ $this->core->add_creds(
1367
+ 'watching_video',
1368
+ $user_id,
1369
+ $amount,
1370
+ $this->prefs['log'],
1371
+ '',
1372
+ $video_id
1373
+ );
1374
+
1375
+ $status = 'max';
1376
+ }
1377
+ }
1378
+ // Awards points when video finished
1379
+ elseif ( $logic == 'full' ) {
1380
+ // Check for skipping or if we watched more (with leniency) then the video length
1381
+ if ( !preg_match( '/22/', $actions, $matches ) || $watched >= $duration ) {
1382
+ if ( $state == 0 && !$this->has_entry( 'watching_video', '', $user_id, $video_id ) ) {
1383
+ $award = true;
1384
+
1385
+ // Execute
1386
+ $this->core->add_creds(
1387
+ 'watching_video',
1388
+ $user_id,
1389
+ $amount,
1390
+ $this->prefs['log'],
1391
+ '',
1392
+ $video_id
1393
+ );
1394
+
1395
+ $status = 'max';
1396
+ }
1397
+ }
1398
+ }
1399
+ // Awards points in an interval
1400
+ elseif ( $logic == 'interval' ) {
1401
+ // The maximum points a video can earn you
1402
+ $num_intervals = floor( $duration / $interval );
1403
+ $max = abs( $num_intervals * $amount );
1404
+
1405
+ $users_log = $this->get_users_video_log( $video_id, $user_id );
1406
+
1407
+ // Film is playing and we just started
1408
+ if ( $state == 1 && $users_log === NULL ) {
1409
+ $award = true;
1410
+
1411
+ // Execute
1412
+ $this->core->add_creds(
1413
+ 'watching_video',
1414
+ $user_id,
1415
+ $amount,
1416
+ $this->prefs['log'],
1417
+ '',
1418
+ $video_id
1419
+ );
1420
+ }
1421
+ // Film is playing and we have not yet reached maximum on this movie
1422
+ elseif ( $state == 1 && isset( $users_log->creds ) && $users_log->creds+$amount <= $max ) {
1423
+ $award = true;
1424
+ $this->update_creds( $users_log->id, $user_id, $users_log->creds+$amount );
1425
+ $amount = $users_log->creds+$amount;
1426
+ }
1427
+ // Film has ended and we have not reached maximum
1428
+ elseif ( $state == 0 && isset( $users_log->creds ) && $users_log->creds+$amount <= $max ) {
1429
+ $award = true;
1430
+ $this->update_creds( $users_log->id, $user_id, $users_log->creds+$amount );
1431
+ $amount = $users_log->creds+$amount;
1432
+ $status = 'max';
1433
+ }
1434
+ }
1435
+
1436
+ $data = array(
1437
+ 'status' => $status,
1438
+ 'video_id' => $video_id,
1439
+ 'amount' => $amount
1440
+ );
1441
+ die( json_encode( $data ) );
1442
+ }
1443
+
1444
+ /**
1445
+ * Get Users Video Log
1446
+ * Returns the log for a given video id.
1447
+ * @since 1.2
1448
+ * @version 1.0
1449
+ */
1450
+ public function get_users_video_log( $video_id, $user_id ) {
1451
+ global $wpdb;
1452
+
1453
+ $db = $wpdb->prefix . $this->core->db_name;
1454
+ $sql = "SELECT * FROM $db WHERE user_id = %d AND data = %s";
1455
+ return $wpdb->get_row( $wpdb->prepare( $sql, $user_id, $video_id ) );
1456
+ }
1457
+
1458
+ /**
1459
+ * Update Points
1460
+ * @since 1.2
1461
+ * @version 1.0
1462
+ */
1463
+ public function update_creds( $row_id, $user_id, $amount ) {
1464
+ // Prep format
1465
+ if ( !isset( $this->core->format['decimals'] ) )
1466
+ $decimals = $this->core->core['format']['decimals'];
1467
+ else
1468
+ $decimals = $this->core->format['decimals'];
1469
+
1470
+ if ( $decimals > 0 )
1471
+ $format = '%f';
1472
+ else
1473
+ $format = '%d';
1474
+
1475
+ $amount = $this->core->number( $amount );
1476
+
1477
+ global $wpdb;
1478
+
1479
+ $wpdb->update(
1480
+ $wpdb->prefix . $this->core->db_name,
1481
+ array( 'creds' => $amount ),
1482
+ array( 'ID' => $row_id ),
1483
+ array( $format ),
1484
+ array( '%d' )
1485
+ );
1486
+ }
1487
+
1488
+ /**
1489
+ * Preference for Viewing Videos
1490
+ * @since 1.2
1491
+ * @version 1.0
1492
+ */
1493
+ public function preferences() {
1494
+ $prefs = $this->prefs; ?>
1495
+
1496
+ <label class="subheader"><?php echo $this->core->plural(); ?></label>
1497
+ <ol>
1498
+ <li>
1499
+ <div class="h2"><input type="text" name="<?php echo $this->field_name( 'creds' ); ?>" id="<?php echo $this->field_id( 'creds' ); ?>" value="<?php echo $this->core->format_number( $prefs['creds'] ); ?>" size="8" /></div>
1500
+ <span class="description"><?php _e( 'Amount to award for viewing videos.', 'mycred' ); ?></span>
1501
+ </li>
1502
+ </ol>
1503
+ <label class="subheader"><?php _e( 'Log Template', 'mycred' ); ?></label>
1504
+ <ol>
1505
+ <li>
1506
+ <div class="h2"><input type="text" name="<?php echo $this->field_name( 'log' ); ?>" id="<?php echo $this->field_id( 'log' ); ?>" value="<?php echo $prefs['log']; ?>" class="long" /></div>
1507
+ <span class="description"><?php _e( 'Available template tags: General', 'mycred' ); ?></span>
1508
+ </li>
1509
+ </ol>
1510
+ <label class="subheader"><?php _e( 'Award Logic', 'mycred' ); ?></label>
1511
+ <ol>
1512
+ <li><?php echo $this->core->template_tags_general( __( 'Select when %_plural% should be awarded or deducted.', 'mycred' ) ); ?></li>
1513
+ <li><input type="radio" name="<?php echo $this->field_name( 'logic' ); ?>" id="<?php echo $this->field_id( array( 'logic' => 'play' ) ); ?>"<?php checked( $prefs['logic'], 'play' ); ?> value="play" /> <label for="<?php echo $this->field_id( array( 'logic' => 'play' ) ); ?>"><?php _e( 'Play - As soon as video starts playing.', 'mycred' ); ?></label></li>
1514
+ <li><input type="radio" name="<?php echo $this->field_name( 'logic' ); ?>" id="<?php echo $this->field_id( array( 'logic' => 'full' ) ); ?>"<?php checked( $prefs['logic'], 'full' ); ?> value="full" /> <label for="<?php echo $this->field_id( array( 'logic' => 'full' ) ); ?>"><?php _e( 'Full - First when the entire video has played.', 'mycred' ); ?></label></li>
1515
+ <li><input type="radio" name="<?php echo $this->field_name( 'logic' ); ?>" id="<?php echo $this->field_id( array( 'logic' => 'interval' ) ); ?>"<?php checked( $prefs['logic'], 'interval' ); ?> value="interval" /> <label for="<?php echo $this->field_id( array( 'logic' => 'interval' ) ); ?>"><?php echo $this->core->template_tags_general( __( 'Interval - For each x number of seconds watched.', 'mycred' ) ); ?></label></li>
1516
+ </ol>
1517
+ <div id="video-interval"<?php if ( $prefs['logic'] == 'play' || $prefs['logic'] == 'full' ) echo ' style="display: none;"';?>>
1518
+ <label class="subheader"><?php _e( 'Interval', 'mycred' ); ?></label>
1519
+ <ol>
1520
+ <li><?php _e( 'Number of seconds', 'mycred' ); ?></li>
1521
+ <li>
1522
+ <div class="h2"><input type="text" name="<?php echo $this->field_name( 'interval' ); ?>" id="<?php echo $this->field_id( 'interval' ); ?>" value="<?php echo $prefs['interval']; ?>" size="8" /></div>
1523
+ </li>
1524
+ </ol>
1525
+ </div>
1526
+ <div id="video-leniency"<?php if ( $prefs['logic'] == 'play' ) echo ' style="display: none;"';?>>
1527
+ <label class="subheader"><?php _e( 'Leniency', 'mycred' ); ?></label>
1528
+ <ol>
1529
+ <li><?php _e( 'The maximum percentage a users view of a movie can differ from the actual length.', 'mycred' ); ?></li>
1530
+ <li>
1531
+ <div class="h2"><input type="text" name="<?php echo $this->field_name( 'leniency' ); ?>" id="<?php echo $this->field_id( 'leniency' ); ?>" value="<?php echo $prefs['leniency']; ?>" size="4" /> %</div>
1532
+ <span class="description"><?php echo _e( 'Do not set this value to zero! A lot of thing can happen while a user watches a movie and sometimes a few seconds can drop of the counter due to buffering or play back errors.', 'mycred' ); ?></span>
1533
+ </li>
1534
+ </ol>
1535
+ </div>
1536
+ <script type="text/javascript">
1537
+ jQuery(function($){
1538
+ $('input[name="<?php echo $this->field_name( 'logic' ); ?>"]').change(function(){
1539
+ if ( $(this).val() == 'interval' ) {
1540
+ $('#video-interval').show();
1541
+ $('#video-leniency').show();
1542
+ }
1543
+ else if ( $(this).val() == 'full' ) {
1544
+ $('#video-interval').hide();
1545
+ $('#video-leniency').show();
1546
+ }
1547
+ else {
1548
+ $('#video-interval').hide();
1549
+ $('#video-leniency').hide();
1550
+ }
1551
+ });
1552
+ });
1553
+ </script>
1554
+ <?php unset( $this );
1555
+ }
1556
+ }
1557
+ }
1558
  ?>
modules/mycred-module-log.php CHANGED
@@ -58,9 +58,13 @@ if ( !class_exists( 'myCRED_Log' ) ) {
58
  /**
59
  * Add "Creds History" to menu
60
  * @since 0.1
61
- * @version 1.0
62
  */
63
  public function my_history_menu() {
 
 
 
 
64
  $page = add_users_page(
65
  __( 'My History', 'mycred' ),
66
  $this->core->template_tags_general( __( '%plural% History', 'mycred' ) ),
@@ -68,6 +72,7 @@ if ( !class_exists( 'myCRED_Log' ) ) {
68
  'mycred_my_history',
69
  array( $this, 'my_history_page' )
70
  );
 
71
  add_action( 'admin_print_styles-' . $page, array( $this, 'settings_header' ) );
72
  }
73
 
@@ -158,7 +163,7 @@ if ( !class_exists( 'myCRED_Log' ) ) {
158
  /**
159
  * Filter Log options
160
  * @since 0.1
161
- * @version 1.0
162
  */
163
  public function filter_options( $is_profile = false ) {
164
  echo '<div class="alignleft actions">';
@@ -191,81 +196,24 @@ if ( !class_exists( 'myCRED_Log' ) ) {
191
  $show = true;
192
  }
193
 
194
- if ( $show === true )
195
- echo '<input type="submit" class="button medium" value="' . __( 'Filter', 'mycred' ) . '" />';
196
-
197
- echo '</div>';
198
- }
199
-
200
- /**
201
- * Filter by Dates
202
- * @since 0.1
203
- * @version 1.0
204
- */
205
- public function filter_dates( $url = '' ) {
206
- $date_sorting = apply_filters( 'mycred_sort_by_time', array(
207
- '' => __( 'All', 'mycred' ),
208
- 'today' => __( 'Today', 'mycred' ),
209
- 'yesterday' => __( 'Yesterday', 'mycred' ),
210
- 'thisweek' => __( 'This Week', 'mycred' ),
211
- 'thismonth' => __( 'This Month', 'mycred' )
212
- ) );
213
-
214
- if ( !empty( $date_sorting ) ) {
215
- $total = count( $date_sorting );
216
- $count = 0;
217
- echo '<ul class="subsubsub">';
218
- foreach ( $date_sorting as $sorting_id => $sorting_name ) {
219
- $count = $count+1;
220
- echo '<li class="' . $sorting_id . '"><a href="';
221
-
222
- // Build Query Args
223
- $url_args = array();
224
- if ( isset( $_GET['user_id'] ) && !empty( $_GET['user_id'] ) )
225
- $url_args['user_id'] = $_GET['user_id'];
226
- if ( isset( $_GET['ref'] ) && !empty( $_GET['ref'] ) )
227
- $url_args['ref'] = $_GET['ref'];
228
- if ( isset( $_GET['s'] ) && !empty( $_GET['s'] ) )
229
- $url_args['s'] = $_GET['s'];
230
- if ( !empty( $sorting_id ) )
231
- $url_args['show'] = $sorting_id;
232
-
233
- // Build URL
234
- if ( !empty( $url_args ) )
235
- echo add_query_arg( $url_args, $url );
236
- else
237
- echo $url;
238
-
239
- echo '"';
240
-
241
- if ( isset( $_GET['show'] ) && $_GET['show'] == $sorting_id ) echo ' class="current"';
242
- elseif ( !isset( $_GET['show'] ) && empty( $sorting_id ) ) echo ' class="current"';
243
-
244
- echo '>' . $sorting_name . '</a>';
245
- if ( $count != $total ) echo ' | ';
246
- echo '</li>';
247
  }
248
- echo '</ul>';
 
249
  }
250
- }
251
 
252
- /**
253
- * Log Search
254
- * @since 0.1
255
- * @version 1.0
256
- */
257
- public function search() {
258
- if ( isset( $_GET['s'] ) && !empty( $_GET['s'] ) )
259
- $serarch_string = $_GET['s'];
260
- else
261
- $serarch_string = ''; ?>
262
 
263
- <p class="search-box">
264
- <label class="screen-reader-text" for=""><?php _e( 'Search Log', 'mycred' ); ?>:</label>
265
- <input type="search" name="s" value="<?php echo $serarch_string; ?>" />
266
- <input type="submit" name="mycred-search-log" id="search-submit" class="button" value="<?php _e( 'Search Log', 'mycred' ); ?>" />
267
- </p>
268
- <?php
269
  }
270
 
271
  /**
@@ -319,7 +267,7 @@ if ( !class_exists( 'myCRED_Log' ) ) {
319
  /**
320
  * Admin Page
321
  * @since 0.1
322
- * @version 1.0
323
  */
324
  public function admin_page() {
325
  // Security
@@ -342,13 +290,16 @@ if ( !class_exists( 'myCRED_Log' ) ) {
342
  if ( isset( $_GET['show'] ) && !empty( $_GET['show'] ) )
343
  $args['time'] = $_GET['show'];
344
 
 
 
 
345
  $log = new myCRED_Query_Log( $args );
346
  $this->results = $log->results; ?>
347
 
348
  <div class="wrap" id="myCRED-wrap">
349
  <div id="icon-myCRED" class="icon32"><br /></div>
350
  <h2><?php $this->page_title(); ?></h2>
351
- <?php $this->filter_dates( admin_url( 'admin.php?page=myCRED' ) ); ?>
352
 
353
  <?php do_action( 'mycred_top_log_page', $this ); ?>
354
 
@@ -367,7 +318,10 @@ if ( !class_exists( 'myCRED_Log' ) ) {
367
  if ( isset( $_GET['show'] ) && !empty( $_GET['show'] ) )
368
  echo '<input type="hidden" name="show" value="' . $_GET['show'] . '" />';
369
 
370
- $this->search(); ?>
 
 
 
371
 
372
  <input type="hidden" name="page" value="myCRED" />
373
  <?php do_action( 'mycred_above_log_table', $this ); ?>
@@ -396,7 +350,7 @@ if ( !class_exists( 'myCRED_Log' ) ) {
396
  /**
397
  * My History Page
398
  * @since 0.1
399
- * @version 1.0
400
  */
401
  public function my_history_page() {
402
  if ( !is_user_logged_in() ) wp_die( __( 'Access Denied', 'mycred' ) );
@@ -415,6 +369,9 @@ if ( !class_exists( 'myCRED_Log' ) ) {
415
  if ( isset( $_GET['show'] ) && !empty( $_GET['show'] ) )
416
  $args['time'] = $_GET['show'];
417
 
 
 
 
418
  $log = new myCRED_Query_Log( $args );
419
  $this->results = $log->results;
420
  unset( $log->headers['column-username'] ); ?>
@@ -422,12 +379,12 @@ if ( !class_exists( 'myCRED_Log' ) ) {
422
  <div class="wrap" id="myCRED-wrap">
423
  <div id="icon-myCRED" class="icon32"><br /></div>
424
  <h2><?php $this->page_title( __( 'My History', 'mycred' ) ); ?></h2>
425
- <?php $this->filter_dates( admin_url( 'users.php?page=mycred_my_history' ) ); ?>
426
 
427
  <?php do_action( 'mycred_top_my_log_page', $this ); ?>
428
 
429
  <form method="get" action="">
430
- <?php $this->search(); ?>
431
 
432
  <input type="hidden" name="page" value="mycred_my_history" />
433
  <?php do_action( 'mycred_above_my_log_table', $this ); ?>
@@ -455,7 +412,7 @@ if ( !class_exists( 'myCRED_Log' ) ) {
455
  /**
456
  * My History Shortcode render
457
  * @since 0.1
458
- * @version 1.0
459
  */
460
  public function render_my_history( $atts ) {
461
  extract( shortcode_atts( array(
@@ -463,6 +420,7 @@ if ( !class_exists( 'myCRED_Log' ) ) {
463
  'number' => NULL,
464
  'time' => NULL,
465
  'ref' => NULL,
 
466
  'show_user' => false,
467
  'login' => ''
468
  ), $atts ) );
@@ -485,6 +443,9 @@ if ( !class_exists( 'myCRED_Log' ) ) {
485
  if ( $ref !== NULL )
486
  $args['ref'] = $ref;
487
 
 
 
 
488
  $log = new myCRED_Query_Log( $args );
489
  $this->results = $log->results;
490
 
@@ -968,6 +929,79 @@ if ( !class_exists( 'myCRED_Query_Log' ) ) {
968
  public function get_no_entries() {
969
  return __( 'No log entries found', 'mycred' );
970
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
971
  }
972
  }
973
  ?>
58
  /**
59
  * Add "Creds History" to menu
60
  * @since 0.1
61
+ * @version 1.1
62
  */
63
  public function my_history_menu() {
64
+ // Check if user should be excluded
65
+ if ( $this->core->exclude_user( get_current_user_id() ) ) return;
66
+
67
+ // Add Points History to Users menu
68
  $page = add_users_page(
69
  __( 'My History', 'mycred' ),
70
  $this->core->template_tags_general( __( '%plural% History', 'mycred' ) ),
72
  'mycred_my_history',
73
  array( $this, 'my_history_page' )
74
  );
75
+ // Load styles for this page
76
  add_action( 'admin_print_styles-' . $page, array( $this, 'settings_header' ) );
77
  }
78
 
163
  /**
164
  * Filter Log options
165
  * @since 0.1
166
+ * @version 1.1
167
  */
168
  public function filter_options( $is_profile = false ) {
169
  echo '<div class="alignleft actions">';
196
  $show = true;
197
  }
198
 
199
+ // Filter Order
200
+ if ( $this->count_records() > 0 ) {
201
+ echo '<select name="order" id="myCRED-order-filter"><option value="">' . __( 'Show in order', 'mycred' ) . '</option>';
202
+ $options = array( 'ASC' => __( 'Ascending', 'mycred' ), 'DESC' => __( 'Descending', 'mycred' ) );
203
+ foreach ( $options as $value => $label ) {
204
+ echo '<option value="' . $value . '"';
205
+ if ( !isset( $_GET['order'] ) && $value == 'DESC' ) echo ' selected="selected"';
206
+ elseif ( isset( $_GET['order'] ) && $_GET['order'] == $value ) echo ' selected="selected"';
207
+ echo '>' . $label . '</option>';
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
208
  }
209
+ echo '</select>';
210
+ $show = true;
211
  }
 
212
 
213
+ if ( $show === true )
214
+ echo '<input type="submit" class="button medium" value="' . __( 'Filter', 'mycred' ) . '" />';
 
 
 
 
 
 
 
 
215
 
216
+ echo '</div>';
 
 
 
 
 
217
  }
218
 
219
  /**
267
  /**
268
  * Admin Page
269
  * @since 0.1
270
+ * @version 1.1
271
  */
272
  public function admin_page() {
273
  // Security
290
  if ( isset( $_GET['show'] ) && !empty( $_GET['show'] ) )
291
  $args['time'] = $_GET['show'];
292
 
293
+ if ( isset( $_GET['order'] ) && !empty( $_GET['order'] ) )
294
+ $args['order'] = $_GET['order'];
295
+
296
  $log = new myCRED_Query_Log( $args );
297
  $this->results = $log->results; ?>
298
 
299
  <div class="wrap" id="myCRED-wrap">
300
  <div id="icon-myCRED" class="icon32"><br /></div>
301
  <h2><?php $this->page_title(); ?></h2>
302
+ <?php $log->filter_dates( admin_url( 'admin.php?page=myCRED' ) ); ?>
303
 
304
  <?php do_action( 'mycred_top_log_page', $this ); ?>
305
 
318
  if ( isset( $_GET['show'] ) && !empty( $_GET['show'] ) )
319
  echo '<input type="hidden" name="show" value="' . $_GET['show'] . '" />';
320
 
321
+ if ( isset( $_GET['order'] ) && !empty( $_GET['order'] ) )
322
+ echo '<input type="hidden" name="order" value="' . $_GET['order'] . '" />';
323
+
324
+ $log->search(); ?>
325
 
326
  <input type="hidden" name="page" value="myCRED" />
327
  <?php do_action( 'mycred_above_log_table', $this ); ?>
350
  /**
351
  * My History Page
352
  * @since 0.1
353
+ * @version 1.1
354
  */
355
  public function my_history_page() {
356
  if ( !is_user_logged_in() ) wp_die( __( 'Access Denied', 'mycred' ) );
369
  if ( isset( $_GET['show'] ) && !empty( $_GET['show'] ) )
370
  $args['time'] = $_GET['show'];
371
 
372
+ if ( isset( $_GET['order'] ) && !empty( $_GET['order'] ) )
373
+ $args['order'] = $_GET['order'];
374
+
375
  $log = new myCRED_Query_Log( $args );
376
  $this->results = $log->results;
377
  unset( $log->headers['column-username'] ); ?>
379
  <div class="wrap" id="myCRED-wrap">
380
  <div id="icon-myCRED" class="icon32"><br /></div>
381
  <h2><?php $this->page_title( __( 'My History', 'mycred' ) ); ?></h2>
382
+ <?php $log->filter_dates( admin_url( 'users.php?page=mycred_my_history' ) ); ?>
383
 
384
  <?php do_action( 'mycred_top_my_log_page', $this ); ?>
385
 
386
  <form method="get" action="">
387
+ <?php $log->search(); ?>
388
 
389
  <input type="hidden" name="page" value="mycred_my_history" />
390
  <?php do_action( 'mycred_above_my_log_table', $this ); ?>
412
  /**
413
  * My History Shortcode render
414
  * @since 0.1
415
+ * @version 1.1
416
  */
417
  public function render_my_history( $atts ) {
418
  extract( shortcode_atts( array(
420
  'number' => NULL,
421
  'time' => NULL,
422
  'ref' => NULL,
423
+ 'order' => NULL,
424
  'show_user' => false,
425
  'login' => ''
426
  ), $atts ) );
443
  if ( $ref !== NULL )
444
  $args['ref'] = $ref;
445
 
446
+ if ( $order !== NULL )
447
+ $args['order'] = $order;
448
+
449
  $log = new myCRED_Query_Log( $args );
450
  $this->results = $log->results;
451
 
929
  public function get_no_entries() {
930
  return __( 'No log entries found', 'mycred' );
931
  }
932
+
933
+ /**
934
+ * Log Search
935
+ * @since 0.1
936
+ * @version 1.0
937
+ */
938
+ public function search() {
939
+ if ( isset( $_GET['s'] ) && !empty( $_GET['s'] ) )
940
+ $serarch_string = $_GET['s'];
941
+ else
942
+ $serarch_string = ''; ?>
943
+
944
+ <p class="search-box">
945
+ <label class="screen-reader-text" for=""><?php _e( 'Search Log', 'mycred' ); ?>:</label>
946
+ <input type="search" name="s" value="<?php echo $serarch_string; ?>" />
947
+ <input type="submit" name="mycred-search-log" id="search-submit" class="button" value="<?php _e( 'Search Log', 'mycred' ); ?>" />
948
+ </p>
949
+ <?php
950
+ }
951
+
952
+ /**
953
+ * Filter by Dates
954
+ * @since 0.1
955
+ * @version 1.0
956
+ */
957
+ public function filter_dates( $url = '' ) {
958
+ $date_sorting = apply_filters( 'mycred_sort_by_time', array(
959
+ '' => __( 'All', 'mycred' ),
960
+ 'today' => __( 'Today', 'mycred' ),
961
+ 'yesterday' => __( 'Yesterday', 'mycred' ),
962
+ 'thisweek' => __( 'This Week', 'mycred' ),
963
+ 'thismonth' => __( 'This Month', 'mycred' )
964
+ ) );
965
+
966
+ if ( !empty( $date_sorting ) ) {
967
+ $total = count( $date_sorting );
968
+ $count = 0;
969
+ echo '<ul class="subsubsub">';
970
+ foreach ( $date_sorting as $sorting_id => $sorting_name ) {
971
+ $count = $count+1;
972
+ echo '<li class="' . $sorting_id . '"><a href="';
973
+
974
+ // Build Query Args
975
+ $url_args = array();
976
+ if ( isset( $_GET['user_id'] ) && !empty( $_GET['user_id'] ) )
977
+ $url_args['user_id'] = $_GET['user_id'];
978
+ if ( isset( $_GET['ref'] ) && !empty( $_GET['ref'] ) )
979
+ $url_args['ref'] = $_GET['ref'];
980
+ if ( isset( $_GET['order'] ) && !empty( $_GET['order'] ) )
981
+ $url_args['order'] = $_GET['order'];
982
+ if ( isset( $_GET['s'] ) && !empty( $_GET['s'] ) )
983
+ $url_args['s'] = $_GET['s'];
984
+ if ( !empty( $sorting_id ) )
985
+ $url_args['show'] = $sorting_id;
986
+
987
+ // Build URL
988
+ if ( !empty( $url_args ) )
989
+ echo add_query_arg( $url_args, $url );
990
+ else
991
+ echo $url;
992
+
993
+ echo '"';
994
+
995
+ if ( isset( $_GET['show'] ) && $_GET['show'] == $sorting_id ) echo ' class="current"';
996
+ elseif ( !isset( $_GET['show'] ) && empty( $sorting_id ) ) echo ' class="current"';
997
+
998
+ echo '>' . $sorting_name . '</a>';
999
+ if ( $count != $total ) echo ' | ';
1000
+ echo '</li>';
1001
+ }
1002
+ echo '</ul>';
1003
+ }
1004
+ }
1005
  }
1006
  }
1007
  ?>
modules/mycred-module-plugins.php CHANGED
@@ -10,7 +10,7 @@ if ( !defined( 'myCRED_VERSION' ) ) exit;
10
  /**
11
  * bbPress
12
  * @since 0.1
13
- * @version 1.1
14
  */
15
  if ( class_exists( 'bbPress' ) ) {
16
  /**
@@ -32,7 +32,7 @@ if ( class_exists( 'bbPress' ) ) {
32
  /**
33
  * bbPress Hook
34
  * @since 1.1.1
35
- * @version 1.0
36
  */
37
  if ( !class_exists( 'myCRED_bbPress' ) ) {
38
  class myCRED_bbPress extends myCRED_Hook {
@@ -48,19 +48,33 @@ if ( class_exists( 'bbPress' ) ) {
48
  'creds' => 1,
49
  'log' => '%plural% for new forum'
50
  ),
 
 
 
 
51
  'new_topic' => array(
52
  'creds' => 1,
53
  'log' => '%plural% for new forum topic',
54
  'author' => 0
55
  ),
 
 
 
 
56
  'fav_topic' => array(
57
  'creds' => 1,
58
- 'log' => '%plural% for someone favorited your forum topic'
 
59
  ),
60
  'new_reply' => array(
61
  'creds' => 1,
62
  'log' => '%plural% for new forum reply',
63
- 'author' => 0
 
 
 
 
 
64
  ),
65
  'show_points_in_reply' => 0
66
  )
@@ -70,36 +84,47 @@ if ( class_exists( 'bbPress' ) ) {
70
  /**
71
  * Run
72
  * @since 0.1
73
- * @version 1.0
74
  */
75
  public function run() {
 
76
  if ( isset( $this->prefs['show_points_in_reply'] ) && $this->prefs['show_points_in_reply'] == 1 )
77
  add_action( 'bbp_theme_after_reply_author_details', array( $this, 'insert_balance' ) );
78
 
 
79
  if ( $this->prefs['new_forum']['creds'] != 0 )
80
  add_action( 'bbp_new_forum', array( $this, 'new_forum' ), 20 );
81
-
 
 
 
82
  if ( $this->prefs['new_topic']['creds'] != 0 )
83
  add_action( 'bbp_new_topic', array( $this, 'new_topic' ), 20, 4 );
84
-
 
 
 
85
  if ( $this->prefs['fav_topic']['creds'] != 0 )
86
  add_action( 'bbp_add_user_favorite', array( $this, 'fav_topic' ), 10, 2 );
87
-
88
  if ( $this->prefs['new_reply']['creds'] != 0 )
89
  add_action( 'bbp_new_reply', array( $this, 'new_reply' ), 20, 5 );
 
 
 
90
  }
91
 
92
  /**
93
  * New Forum
94
  * @since 1.1.1
95
- * @version 1.0
96
  */
97
  public function new_forum( $forum ) {
98
  // Forum id
99
  $forum_id = $forum['forum_id'];
100
 
101
  // Forum author
102
- $forum_author = bbp_get_forum_author_id( $forum_id );
103
 
104
  // Check if user is excluded
105
  if ( $this->core->exclude_user( $forum_author ) ) return;
@@ -117,6 +142,31 @@ if ( class_exists( 'bbPress' ) ) {
117
  array( 'ref_type' => 'post' )
118
  );
119
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
120
 
121
  /**
122
  * New Topic
@@ -145,18 +195,46 @@ if ( class_exists( 'bbPress' ) ) {
145
  array( 'ref_type' => 'post' )
146
  );
147
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
148
 
149
  /**
150
  * Topic Added to Favorites
151
  * @by Fee (http://wordpress.org/support/profile/wdfee)
152
  * @since 1.1.1
153
- * @version 1.0
154
  */
155
  public function fav_topic( $user_id, $topic_id ) {
156
 
157
  // $user_id is loggedin_user, not author, so get topic author
158
  $topic_author = get_post_field( 'post_author', $topic_id );
159
 
 
 
 
160
  // Check if user is excluded (required)
161
  if ( $this->core->exclude_user( $topic_author ) || $topic_author == $user_id ) return;
162
 
@@ -172,12 +250,15 @@ if ( class_exists( 'bbPress' ) ) {
172
  $topic_id,
173
  array( 'ref_user' => $user_id, 'ref_type' => 'post' )
174
  );
 
 
 
175
  }
176
 
177
  /**
178
  * New Reply
179
  * @since 0.1
180
- * @version 1.1
181
  */
182
  public function new_reply( $reply_id, $topic_id, $forum_id, $anonymous_data, $reply_author ) {
183
  // Check if user is excluded
@@ -187,6 +268,9 @@ if ( class_exists( 'bbPress' ) ) {
187
  if ( (bool) $this->prefs['new_reply']['author'] === false ) {
188
  if ( bbp_get_topic_author_id( $topic_id ) == $reply_author ) return;
189
  }
 
 
 
190
 
191
  // Make sure this is unique event
192
  if ( $this->has_entry( 'new_forum_reply', $reply_id, $reply_author ) ) return;
@@ -200,6 +284,34 @@ if ( class_exists( 'bbPress' ) ) {
200
  $reply_id,
201
  array( 'ref_type' => 'post' )
202
  );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
203
  }
204
 
205
  /**
@@ -214,6 +326,46 @@ if ( class_exists( 'bbPress' ) ) {
214
  $balance = $this->core->get_users_cred( bbp_get_reply_author_id( $reply_id ) );
215
  echo '<div class="mycred-balance">' . $this->core->plural() . ': ' . $this->core->format_creds( $balance ) . '</div>';
216
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
217
 
218
  /**
219
  * Preferences
@@ -231,7 +383,12 @@ if ( class_exists( 'bbPress' ) ) {
231
  if ( !isset( $prefs['fav_topic'] ) )
232
  $prefs['fav_topic'] = array( 'creds' => 1, 'log' => '%plural% for someone favorited your forum topic' );
233
  if ( !isset( $prefs['new_reply']['author'] ) )
234
- $prefs['new_reply']['author'] = 0; ?>
 
 
 
 
 
235
 
236
  <!-- Creds for New Forums -->
237
  <label for="<?php echo $this->field_id( array( 'new_forum', 'creds' ) ); ?>" class="subheader"><?php echo $this->core->template_tags_general( __( '%plural% for New Forum', 'mycred' ) ); ?></label>
@@ -246,6 +403,19 @@ if ( class_exists( 'bbPress' ) ) {
246
  <span class="description"><?php _e( 'Available template tags: General, Post', 'mycred' ); ?></span>
247
  </li>
248
  </ol>
 
 
 
 
 
 
 
 
 
 
 
 
 
249
  <!-- Creds for New Topic -->
250
  <label for="<?php echo $this->field_id( array( 'new_topic', 'creds' ) ); ?>" class="subheader"><?php echo $this->core->template_tags_general( __( '%plural% for New Topic', 'mycred' ) ); ?></label>
251
  <ol id="">
@@ -264,6 +434,19 @@ if ( class_exists( 'bbPress' ) ) {
264
  <label for="<?php echo $this->field_id( array( 'new_topic' => 'author' ) ); ?>"><?php echo $this->core->template_tags_general( __( 'Forum authors can receive %_plural% for creating new topics.', 'mycred' ) ); ?></label>
265
  </li>
266
  </ol>
 
 
 
 
 
 
 
 
 
 
 
 
 
267
  <!-- Creds for Faved Topic -->
268
  <label for="<?php echo $this->field_id( array( 'fav_topic', 'creds' ) ); ?>" class="subheader"><?php echo $this->core->template_tags_general( __( '%plural% for Favorited Topic', 'mycred' ) ); ?></label>
269
  <ol id="">
@@ -276,6 +459,12 @@ if ( class_exists( 'bbPress' ) ) {
276
  <div class="h2"><input type="text" name="<?php echo $this->field_name( array( 'fav_topic', 'log' ) ); ?>" id="<?php echo $this->field_id( array( 'fav_topic', 'log' ) ); ?>" value="<?php echo $prefs['fav_topic']['log']; ?>" class="long" /></div>
277
  <span class="description"><?php _e( 'Available template tags: General, Post', 'mycred' ); ?></span>
278
  </li>
 
 
 
 
 
 
279
  </ol>
280
  <!-- Creds for New Reply -->
281
  <label for="<?php echo $this->field_id( array( 'new_reply', 'creds' ) ); ?>" class="subheader"><?php echo $this->core->template_tags_general( __( '%plural% for New Reply', 'mycred' ) ); ?></label>
@@ -295,6 +484,12 @@ if ( class_exists( 'bbPress' ) ) {
295
  <label for="<?php echo $this->field_id( array( 'new_reply' => 'author' ) ); ?>"><?php echo $this->core->template_tags_general( __( 'Topic authors can receive %_plural% for replying to their own Topic', 'mycred' ) ); ?></label>
296
  </li>
297
  <li class="empty">&nbsp;</li>
 
 
 
 
 
 
298
  <li>
299
  <input type="checkbox" name="<?php echo $this->field_name( 'show_points_in_reply' ); ?>" id="<?php echo $this->field_id( 'show_points_in_reply' ); ?>" <?php checked( $prefs['show_points_in_reply'], 1 ); ?> value="1" /> <label for="<?php echo $this->field_id( 'show_points_in_reply' ); ?>"><?php echo $this->core->template_tags_general( __( 'Show users %_plural% balance in replies', 'mycred' ) ); ?>.</label>
300
  </li>
@@ -1036,7 +1231,7 @@ if ( !class_exists( 'myCRED_Hook_WPFavorite' ) && function_exists( 'wp_favorite_
1036
  if ( $this->core->exclude_user( $user_id ) ) return;
1037
 
1038
  // Make sure this is unique event
1039
- if ( $this->has_entry( 'add_favorite_post', $post_id, $user_id ) ) return;
1040
 
1041
  // Execute
1042
  $this->core->add_creds(
@@ -1063,7 +1258,7 @@ if ( !class_exists( 'myCRED_Hook_WPFavorite' ) && function_exists( 'wp_favorite_
1063
  if ( $this->core->exclude_user( $user_id ) ) return;
1064
 
1065
  // Make sure this is unique event
1066
- if ( $this->has_entry( 'favorite_post_removed', $post_id, $user_id ) ) return;
1067
 
1068
  // Execute
1069
  $this->core->add_creds(
@@ -1158,18 +1353,15 @@ if ( !class_exists( 'myCRED_Hook_Events_Manager' ) && function_exists( 'bp_em_in
1158
  * New Booking
1159
  * When users can make their own bookings.
1160
  * @since 1.1
1161
- * @version 1.0
1162
  */
1163
  public function new_booking( $result, $booking ) {
1164
- $user_id = $booking->person_id;
1165
  // Check for exclusion
1166
  if ( $this->core->exclude_user( $user_id ) ) return $result;
1167
 
1168
  // Successfull Booking
1169
  if ( $result === true ) {
1170
- // Make sure this is unique event
1171
- if ( $this->has_entry( 'event_booking', $booking->event->post_id, $user_id ) ) return $result;
1172
-
1173
  // Execute
1174
  $this->core->add_creds(
1175
  'event_booking',
@@ -1189,10 +1381,10 @@ if ( !class_exists( 'myCRED_Hook_Events_Manager' ) && function_exists( 'bp_em_in
1189
  * Incase an administrator needs to approve bookings first or if booking gets
1190
  * cancelled.
1191
  * @since 1.1
1192
- * @version 1.0
1193
  */
1194
  public function adjust_booking( $result, $booking ) {
1195
- $user_id = $booking->person_id;
1196
  // Check for exclusion
1197
  if ( $this->core->exclude_user( $user_id ) ) return $result;
1198
 
@@ -1200,9 +1392,6 @@ if ( !class_exists( 'myCRED_Hook_Events_Manager' ) && function_exists( 'bp_em_in
1200
  if ( $booking->booking_status == 1 && $booking->previous_status != 1 ) {
1201
  // If we do not award points for attending an event bail now
1202
  if ( $this->prefs['attend']['creds'] == 0 ) return $result;
1203
-
1204
- // Make sure this is unique event
1205
- if ( $this->has_entry( 'event_attendance', $booking->event->post_id, $user_id ) ) return $result;
1206
 
1207
  // Execute
1208
  $this->core->add_creds(
@@ -1218,9 +1407,6 @@ if ( !class_exists( 'myCRED_Hook_Events_Manager' ) && function_exists( 'bp_em_in
1218
  elseif ( $booking->booking_status != 1 && $booking->previous_status == 1 ) {
1219
  // If we do not deduct points for cancellation bail now
1220
  if ( $this->prefs['cancel']['creds'] == 0 ) return $result;
1221
-
1222
- // Make sure this is unique event
1223
- if ( $this->has_entry( 'cancelled_event_attendance', $booking->event->post_id, $user_id ) ) return $result;
1224
 
1225
  // Execute
1226
  $this->core->add_creds(
@@ -1274,4 +1460,113 @@ if ( !class_exists( 'myCRED_Hook_Events_Manager' ) && function_exists( 'bp_em_in
1274
  }
1275
  }
1276
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1277
  ?>
10
  /**
11
  * bbPress
12
  * @since 0.1
13
+ * @version 1.2
14
  */
15
  if ( class_exists( 'bbPress' ) ) {
16
  /**
32
  /**
33
  * bbPress Hook
34
  * @since 1.1.1
35
+ * @version 1.2
36
  */
37
  if ( !class_exists( 'myCRED_bbPress' ) ) {
38
  class myCRED_bbPress extends myCRED_Hook {
48
  'creds' => 1,
49
  'log' => '%plural% for new forum'
50
  ),
51
+ 'delete_forum' => array(
52
+ 'creds' => 0-1,
53
+ 'log' => '%singular% deduction for deleted forum'
54
+ ),
55
  'new_topic' => array(
56
  'creds' => 1,
57
  'log' => '%plural% for new forum topic',
58
  'author' => 0
59
  ),
60
+ 'delete_topic' => array(
61
+ 'creds' => 0-1,
62
+ 'log' => '%singular% deduction for deleted topic'
63
+ ),
64
  'fav_topic' => array(
65
  'creds' => 1,
66
+ 'log' => '%plural% for someone favorited your forum topic',
67
+ 'limit' => 1
68
  ),
69
  'new_reply' => array(
70
  'creds' => 1,
71
  'log' => '%plural% for new forum reply',
72
+ 'author' => 0,
73
+ 'limit' => 10,
74
+ ),
75
+ 'delete_reply' => array(
76
+ 'creds' => 0-1,
77
+ 'log' => '%singular% deduction for deleted reply'
78
  ),
79
  'show_points_in_reply' => 0
80
  )
84
  /**
85
  * Run
86
  * @since 0.1
87
+ * @version 1.2
88
  */
89
  public function run() {
90
+ // Insert Points balance in profile
91
  if ( isset( $this->prefs['show_points_in_reply'] ) && $this->prefs['show_points_in_reply'] == 1 )
92
  add_action( 'bbp_theme_after_reply_author_details', array( $this, 'insert_balance' ) );
93
 
94
+ // New Forum
95
  if ( $this->prefs['new_forum']['creds'] != 0 )
96
  add_action( 'bbp_new_forum', array( $this, 'new_forum' ), 20 );
97
+ // Delete Forum
98
+ if ( $this->prefs['delete_forum']['creds'] != 0 )
99
+ add_action( 'bbp_delete_forum', array( $this, 'delete_forum' ) );
100
+ // New Topic
101
  if ( $this->prefs['new_topic']['creds'] != 0 )
102
  add_action( 'bbp_new_topic', array( $this, 'new_topic' ), 20, 4 );
103
+ // Delete Topic
104
+ if ( $this->prefs['delete_topic']['creds'] != 0 )
105
+ add_action( 'bbp_delete_topic', array( $this, 'delete_topic' ) );
106
+ // Fave Topic
107
  if ( $this->prefs['fav_topic']['creds'] != 0 )
108
  add_action( 'bbp_add_user_favorite', array( $this, 'fav_topic' ), 10, 2 );
109
+ // New Reply
110
  if ( $this->prefs['new_reply']['creds'] != 0 )
111
  add_action( 'bbp_new_reply', array( $this, 'new_reply' ), 20, 5 );
112
+ // Delete Reply
113
+ if ( $this->prefs['delete_reply']['creds'] != 0 )
114
+ add_action( 'bbp_delete_reply', array( $this, 'delete_reply' ) );
115
  }
116
 
117
  /**
118
  * New Forum
119
  * @since 1.1.1
120
+ * @version 1.1
121
  */
122
  public function new_forum( $forum ) {
123
  // Forum id
124
  $forum_id = $forum['forum_id'];
125
 
126
  // Forum author
127
+ $forum_author = $forum['forum_author'];
128
 
129
  // Check if user is excluded
130
  if ( $this->core->exclude_user( $forum_author ) ) return;
142
  array( 'ref_type' => 'post' )
143
  );
144
  }
145
+
146
+ /**
147
+ * Delete Forum
148
+ * @since 1.2
149
+ * @version 1.0
150
+ */
151
+ public function delete_forum( $forum_id ) {
152
+ // Get Author
153
+ $forum_author = bbp_get_forum_author_id( $forum_id );
154
+
155
+ // If gained, points, deduct
156
+ if ( $this->has_entry( 'new_forum', $forum_id, $forum_author ) ) {
157
+
158
+ // Execute
159
+ $this->core->add_creds(
160
+ 'deleted_forum',
161
+ $forum_author,
162
+ $this->prefs['delete_forum']['creds'],
163
+ $this->prefs['delete_forum']['log'],
164
+ $forum_id,
165
+ array( 'ref_type' => 'post' )
166
+ );
167
+
168
+ }
169
+ }
170
 
171
  /**
172
  * New Topic
195
  array( 'ref_type' => 'post' )
196
  );
197
  }
198
+
199
+ /**
200
+ * Delete Topic
201
+ * @since 1.2
202
+ * @version 1.0
203
+ */
204
+ public function delete_topic( $topic_id ) {
205
+ // Get Author
206
+ $topic_author = bbp_get_topic_author_id( $topic_id );
207
+
208
+ // If gained, points, deduct
209
+ if ( $this->has_entry( 'new_forum_topic', $topic_id, $topic_author ) ) {
210
+
211
+ // Execute
212
+ $this->core->add_creds(
213
+ 'deleted_topic',
214
+ $topic_author,
215
+ $this->prefs['delete_topic']['creds'],
216
+ $this->prefs['delete_topic']['log'],
217
+ $topic_id,
218
+ array( 'ref_type' => 'post' )
219
+ );
220
+
221
+ }
222
+ }
223
 
224
  /**
225
  * Topic Added to Favorites
226
  * @by Fee (http://wordpress.org/support/profile/wdfee)
227
  * @since 1.1.1
228
+ * @version 1.2
229
  */
230
  public function fav_topic( $user_id, $topic_id ) {
231
 
232
  // $user_id is loggedin_user, not author, so get topic author
233
  $topic_author = get_post_field( 'post_author', $topic_id );
234
 
235
+ // Enforce Daily Limit
236
+ if ( $this->reached_daily_limit( $topic_author, 'fav_topic' ) ) return;
237
+
238
  // Check if user is excluded (required)
239
  if ( $this->core->exclude_user( $topic_author ) || $topic_author == $user_id ) return;
240
 
250
  $topic_id,
251
  array( 'ref_user' => $user_id, 'ref_type' => 'post' )
252
  );
253
+
254
+ // Update Limit
255
+ $this->update_daily_limit( $topic_author, 'fav_topic' );
256
  }
257
 
258
  /**
259
  * New Reply
260
  * @since 0.1
261
+ * @version 1.2
262
  */
263
  public function new_reply( $reply_id, $topic_id, $forum_id, $anonymous_data, $reply_author ) {
264
  // Check if user is excluded
268
  if ( (bool) $this->prefs['new_reply']['author'] === false ) {
269
  if ( bbp_get_topic_author_id( $topic_id ) == $reply_author ) return;
270
  }
271
+
272
+ // Check daily limit
273
+ if ( $this->reached_daily_limit( $reply_author, 'new_reply' ) ) return;
274
 
275
  // Make sure this is unique event
276
  if ( $this->has_entry( 'new_forum_reply', $reply_id, $reply_author ) ) return;
284
  $reply_id,
285
  array( 'ref_type' => 'post' )
286
  );
287
+
288
+ // Update Limit
289
+ $this->update_daily_limit( $topic_author, 'new_reply' );
290
+ }
291
+
292
+ /**
293
+ * Delete Reply
294
+ * @since 1.2
295
+ * @version 1.0
296
+ */
297
+ public function delete_reply( $reply_id ) {
298
+ // Get Author
299
+ $reply_author = bbp_get_reply_author_id( $reply_id );
300
+
301
+ // If gained, points, deduct
302
+ if ( $this->has_entry( 'new_forum_reply', $reply_id, $reply_author ) ) {
303
+
304
+ // Execute
305
+ $this->core->add_creds(
306
+ 'deleted_reply',
307
+ $reply_author,
308
+ $this->prefs['delete_reply']['creds'],
309
+ $this->prefs['delete_reply']['log'],
310
+ $reply_id,
311
+ array( 'ref_type' => 'post' )
312
+ );
313
+
314
+ }
315
  }
316
 
317
  /**
326
  $balance = $this->core->get_users_cred( bbp_get_reply_author_id( $reply_id ) );
327
  echo '<div class="mycred-balance">' . $this->core->plural() . ': ' . $this->core->format_creds( $balance ) . '</div>';
328
  }
329
+
330
+ /**
331
+ * Reched Daily Limit
332
+ * Checks if a user has reached their daily limit.
333
+ * @since 1.2
334
+ * @version 1.0
335
+ */
336
+ public function reached_daily_limit( $user_id, $id ) {
337
+ // No limit used
338
+ if ( $this->prefs[$id]['limit'] == 0 ) return false;
339
+
340
+ $today = date( 'Y-m-d' );
341
+ $current = get_user_meta( $user_id, 'mycred_bbp_limits_' . $id, true );
342
+ if ( empty( $current ) || !array_key_exists( $today, (array) $current ) )
343
+ $current[$today] = 0;
344
+
345
+ if ( $current[ $today ] < $this->prefs[$id]['limit'] ) return false;
346
+
347
+ return true;
348
+ }
349
+
350
+ /**
351
+ * Update Daily Limit
352
+ * Updates a given users daily limit.
353
+ * @since 1.2
354
+ * @version 1.0
355
+ */
356
+ public function update_daily_limit( $user_id, $id ) {
357
+ // No limit used
358
+ if ( $this->prefs[$id]['limit'] == 0 ) return;
359
+
360
+ $today = date( 'Y-m-d' );
361
+ $current = get_user_meta( $user_id, 'mycred_bbp_limits_' . $id, true );
362
+ if ( empty( $current ) || !array_key_exists( $today, (array) $current ) )
363
+ $current[$today] = 0;
364
+
365
+ $current[ $today ] = $current[ $today ]+1;
366
+
367
+ update_user_meta( $user_id, 'mycred_bbp_limits_' . $id, $current );
368
+ }
369
 
370
  /**
371
  * Preferences
383
  if ( !isset( $prefs['fav_topic'] ) )
384
  $prefs['fav_topic'] = array( 'creds' => 1, 'log' => '%plural% for someone favorited your forum topic' );
385
  if ( !isset( $prefs['new_reply']['author'] ) )
386
+ $prefs['new_reply']['author'] = 0;
387
+
388
+ if ( !isset( $prefs['fav_topic']['limit'] ) )
389
+ $prefs['fav_topic']['limit'] = 0;
390
+ if ( !isset( $prefs['new_reply']['limit'] ) )
391
+ $prefs['new_reply']['limit'] = 0; ?>
392
 
393
  <!-- Creds for New Forums -->
394
  <label for="<?php echo $this->field_id( array( 'new_forum', 'creds' ) ); ?>" class="subheader"><?php echo $this->core->template_tags_general( __( '%plural% for New Forum', 'mycred' ) ); ?></label>
403
  <span class="description"><?php _e( 'Available template tags: General, Post', 'mycred' ); ?></span>
404
  </li>
405
  </ol>
406
+ <!-- Creds for Deleting Forums -->
407
+ <label for="<?php echo $this->field_id( array( 'delete_forum', 'creds' ) ); ?>" class="subheader"><?php echo $this->core->template_tags_general( __( '%plural% for Forum Deletion', 'mycred' ) ); ?></label>
408
+ <ol id="">
409
+ <li>
410
+ <div class="h2"><input type="text" name="<?php echo $this->field_name( array( 'delete_forum', 'creds' ) ); ?>" id="<?php echo $this->field_id( array( 'delete_forum', 'creds' ) ); ?>" value="<?php echo $this->core->format_number( $prefs['delete_forum']['creds'] ); ?>" size="8" /></div>
411
+ </li>
412
+ <li class="empty">&nbsp;</li>
413
+ <li>
414
+ <label for="<?php echo $this->field_id( array( 'delete_forum', 'log' ) ); ?>"><?php _e( 'Log template', 'mycred' ); ?></label>
415
+ <div class="h2"><input type="text" name="<?php echo $this->field_name( array( 'delete_forum', 'log' ) ); ?>" id="<?php echo $this->field_id( array( 'delete_forum', 'log' ) ); ?>" value="<?php echo $prefs['delete_forum']['log']; ?>" class="long" /></div>
416
+ <span class="description"><?php _e( 'Available template tags: General, Post', 'mycred' ); ?></span>
417
+ </li>
418
+ </ol>
419
  <!-- Creds for New Topic -->
420
  <label for="<?php echo $this->field_id( array( 'new_topic', 'creds' ) ); ?>" class="subheader"><?php echo $this->core->template_tags_general( __( '%plural% for New Topic', 'mycred' ) ); ?></label>
421
  <ol id="">
434
  <label for="<?php echo $this->field_id( array( 'new_topic' => 'author' ) ); ?>"><?php echo $this->core->template_tags_general( __( 'Forum authors can receive %_plural% for creating new topics.', 'mycred' ) ); ?></label>
435
  </li>
436
  </ol>
437
+ <!-- Creds for Deleting Topic -->
438
+ <label for="<?php echo $this->field_id( array( 'delete_topic', 'creds' ) ); ?>" class="subheader"><?php echo $this->core->template_tags_general( __( '%plural% for Topic Deletion', 'mycred' ) ); ?></label>
439
+ <ol id="">
440
+ <li>
441
+ <div class="h2"><input type="text" name="<?php echo $this->field_name( array( 'delete_topic', 'creds' ) ); ?>" id="<?php echo $this->field_id( array( 'delete_topic', 'creds' ) ); ?>" value="<?php echo $this->core->format_number( $prefs['delete_topic']['creds'] ); ?>" size="8" /></div>
442
+ </li>
443
+ <li class="empty">&nbsp;</li>
444
+ <li>
445
+ <label for="<?php echo $this->field_id( array( 'delete_topic', 'log' ) ); ?>"><?php _e( 'Log template', 'mycred' ); ?></label>
446
+ <div class="h2"><input type="text" name="<?php echo $this->field_name( array( 'delete_topic', 'log' ) ); ?>" id="<?php echo $this->field_id( array( 'delete_topic', 'log' ) ); ?>" value="<?php echo $prefs['delete_topic']['log']; ?>" class="long" /></div>
447
+ <span class="description"><?php _e( 'Available template tags: General, Post', 'mycred' ); ?></span>
448
+ </li>
449
+ </ol>
450
  <!-- Creds for Faved Topic -->
451
  <label for="<?php echo $this->field_id( array( 'fav_topic', 'creds' ) ); ?>" class="subheader"><?php echo $this->core->template_tags_general( __( '%plural% for Favorited Topic', 'mycred' ) ); ?></label>
452
  <ol id="">
459
  <div class="h2"><input type="text" name="<?php echo $this->field_name( array( 'fav_topic', 'log' ) ); ?>" id="<?php echo $this->field_id( array( 'fav_topic', 'log' ) ); ?>" value="<?php echo $prefs['fav_topic']['log']; ?>" class="long" /></div>
460
  <span class="description"><?php _e( 'Available template tags: General, Post', 'mycred' ); ?></span>
461
  </li>
462
+ <li class="empty">&nbsp;</li>
463
+ <li>
464
+ <label for="<?php echo $this->field_id( array( 'fav_topic', 'limit' ) ); ?>"><?php _e( 'Daily Limit', 'mycred' ); ?></label>
465
+ <div class="h2"><input type="text" name="<?php echo $this->field_name( array( 'fav_topic', 'limit' ) ); ?>" id="<?php echo $this->field_id( array( 'fav_topic', 'limit' ) ); ?>" value="<?php echo $this->core->format_number( $prefs['fav_topic']['limit'] ); ?>" size="8" /></div>
466
+ <span class="description"><?php _e( 'Use zero for unlimited', 'mycred' ); ?></span>
467
+ </li>
468
  </ol>
469
  <!-- Creds for New Reply -->
470
  <label for="<?php echo $this->field_id( array( 'new_reply', 'creds' ) ); ?>" class="subheader"><?php echo $this->core->template_tags_general( __( '%plural% for New Reply', 'mycred' ) ); ?></label>
484
  <label for="<?php echo $this->field_id( array( 'new_reply' => 'author' ) ); ?>"><?php echo $this->core->template_tags_general( __( 'Topic authors can receive %_plural% for replying to their own Topic', 'mycred' ) ); ?></label>
485
  </li>
486
  <li class="empty">&nbsp;</li>
487
+ <li>
488
+ <label for="<?php echo $this->field_id( array( 'new_reply', 'limit' ) ); ?>"><?php _e( 'Daily Limit', 'mycred' ); ?></label>
489
+ <div class="h2"><input type="text" name="<?php echo $this->field_name( array( 'new_reply', 'limit' ) ); ?>" id="<?php echo $this->field_id( array( 'new_reply', 'limit' ) ); ?>" value="<?php echo $this->core->format_number( $prefs['new_reply']['limit'] ); ?>" size="8" /></div>
490
+ <span class="description"><?php _e( 'Use zero for unlimited', 'mycred' ); ?></span>
491
+ </li>
492
+ <li class="empty">&nbsp;</li>
493
  <li>
494
  <input type="checkbox" name="<?php echo $this->field_name( 'show_points_in_reply' ); ?>" id="<?php echo $this->field_id( 'show_points_in_reply' ); ?>" <?php checked( $prefs['show_points_in_reply'], 1 ); ?> value="1" /> <label for="<?php echo $this->field_id( 'show_points_in_reply' ); ?>"><?php echo $this->core->template_tags_general( __( 'Show users %_plural% balance in replies', 'mycred' ) ); ?>.</label>
495
  </li>
1231
  if ( $this->core->exclude_user( $user_id ) ) return;
1232
 
1233
  // Make sure this is unique event
1234
+ if ( $this->core->has_entry( 'add_favorite_post', $post_id, $user_id ) ) return;
1235
 
1236
  // Execute
1237
  $this->core->add_creds(
1258
  if ( $this->core->exclude_user( $user_id ) ) return;
1259
 
1260
  // Make sure this is unique event
1261
+ if ( $this->core->has_entry( 'favorite_post_removed', $post_id, $user_id ) ) return;
1262
 
1263
  // Execute
1264
  $this->core->add_creds(
1353
  * New Booking
1354
  * When users can make their own bookings.
1355
  * @since 1.1
1356
+ * @version 1.1
1357
  */
1358
  public function new_booking( $result, $booking ) {
1359
+ $user_id = $booking->person->id;
1360
  // Check for exclusion
1361
  if ( $this->core->exclude_user( $user_id ) ) return $result;
1362
 
1363
  // Successfull Booking
1364
  if ( $result === true ) {
 
 
 
1365
  // Execute
1366
  $this->core->add_creds(
1367
  'event_booking',
1381
  * Incase an administrator needs to approve bookings first or if booking gets
1382
  * cancelled.
1383
  * @since 1.1
1384
+ * @version 1.1
1385
  */
1386
  public function adjust_booking( $result, $booking ) {
1387
+ $user_id = $booking->person->id;
1388
  // Check for exclusion
1389
  if ( $this->core->exclude_user( $user_id ) ) return $result;
1390
 
1392
  if ( $booking->booking_status == 1 && $booking->previous_status != 1 ) {
1393
  // If we do not award points for attending an event bail now
1394
  if ( $this->prefs['attend']['creds'] == 0 ) return $result;
 
 
 
1395
 
1396
  // Execute
1397
  $this->core->add_creds(
1407
  elseif ( $booking->booking_status != 1 && $booking->previous_status == 1 ) {
1408
  // If we do not deduct points for cancellation bail now
1409
  if ( $this->prefs['cancel']['creds'] == 0 ) return $result;
 
 
 
1410
 
1411
  // Execute
1412
  $this->core->add_creds(
1460
  }
1461
  }
1462
  }
1463
+
1464
+ /**
1465
+ * Hook for GD Star Rating
1466
+ * @since 1.2
1467
+ * @version 1.0
1468
+ */
1469
+ if ( !class_exists( 'myCRED_Hook_GD_Star_Rating' ) && defined( 'STARRATING_DEBUG' ) ) {
1470
+ class myCRED_Hook_GD_Star_Rating extends myCRED_Hook {
1471
+
1472
+ /**
1473
+ * Construct
1474
+ */
1475
+ function __construct( $hook_prefs ) {
1476
+ parent::__construct( array(
1477
+ 'id' => 'gdstars',
1478
+ 'defaults' => array(
1479
+ 'star_rating' => array(
1480
+ 'creds' => 1,
1481
+ 'log' => '%plural% for rating'
1482
+ ),
1483
+ 'up_down' => array(
1484
+ 'creds' => 1,
1485
+ 'log' => '%plural% for rating'
1486
+ )
1487
+ )
1488
+ ), $hook_prefs );
1489
+ }
1490
+
1491
+ /**
1492
+ * Run
1493
+ * @since 1.2
1494
+ * @version 1.0
1495
+ */
1496
+ public function run() {
1497
+ add_action( 'gdsr_vote', array( $this, 'vote' ), 10, 4 );
1498
+ }
1499
+
1500
+ /**
1501
+ * Vote
1502
+ * @since 1.2
1503
+ * @version 1.0
1504
+ */
1505
+ public function vote( $vote_value, $post_id, $vote_tpl, $vote_size ) {
1506
+ if ( !is_user_logged_in() ) return;
1507
+
1508
+ if ( is_string( $vote_value ) && $this->prefs['up_down']['creds'] == 0 ) return;
1509
+ elseif ( !is_string( $vote_value ) && $this->prefs['star_rating']['creds'] == 0 ) return;
1510
+
1511
+ if ( is_string( $vote_value ) ) {
1512
+ $vote = 'up_down';
1513
+ $star = false;
1514
+ }
1515
+ else {
1516
+ $vote = 'star_rating';
1517
+ $star = true;
1518
+ }
1519
+ $user_id = get_current_user_id();
1520
+
1521
+ if ( $this->core->has_entry( 'rating', $post_id, $user_id, $vote ) ) return;
1522
+
1523
+ // Execute
1524
+ $this->core->add_creds(
1525
+ 'rating',
1526
+ $user_id,
1527
+ ( $star ) ? $this->prefs['star_rating']['creds'] : $this->prefs['up_down']['creds'],
1528
+ ( $star ) ? $this->prefs['star_rating']['log'] : $this->prefs['up_down']['log'],
1529
+ $post_id,
1530
+ $vote
1531
+ );
1532
+ }
1533
+
1534
+ /**
1535
+ * Preferences for GD Star Rating
1536
+ * @since 1.2
1537
+ * @version 1.0
1538
+ */
1539
+ public function preferences() {
1540
+ $prefs = $this->prefs; ?>
1541
+
1542
+ <label class="subheader" for="<?php echo $this->field_id( array( 'star_rating' => 'creds' ) ); ?>"><?php _e( 'Rating', 'mycred' ); ?></label>
1543
+ <ol>
1544
+ <li>
1545
+ <div class="h2"><input type="text" name="<?php echo $this->field_name( array( 'star_rating' => 'creds' ) ); ?>" id="<?php echo $this->field_id( array( 'star_rating' => 'creds' ) ); ?>" value="<?php echo $this->core->format_number( $prefs['star_rating']['creds'] ); ?>" size="8" /></div>
1546
+ </li>
1547
+ </ol>
1548
+ <label class="subheader" for="<?php echo $this->field_id( array( 'star_rating' => 'log' ) ); ?>"><?php _e( 'Log Template', 'mycred' ); ?></label>
1549
+ <ol>
1550
+ <li>
1551
+ <div class="h2"><input type="text" name="<?php echo $this->field_name( array( 'star_rating' => 'log' ) ); ?>" id="<?php echo $this->field_id( array( 'star_rating' => 'log' ) ); ?>" value="<?php echo $prefs['star_rating']['log']; ?>" class="long" /></div>
1552
+ <span class="description"><?php _e( 'Available template tags: General', 'mycred' ); ?></span>
1553
+ </li>
1554
+ </ol>
1555
+ <label class="subheader" for="<?php echo $this->field_id( array( 'up_down' => 'creds' ) ); ?>"><?php _e( 'Up / Down Vote', 'mycred' ); ?></label>
1556
+ <ol>
1557
+ <li>
1558
+ <div class="h2"><input type="text" name="<?php echo $this->field_name( array( 'up_down' => 'creds' ) ); ?>" id="<?php echo $this->field_id( array( 'up_down' => 'creds' ) ); ?>" value="<?php echo $this->core->format_number( $prefs['up_down']['creds'] ); ?>" size="8" /></div>
1559
+ </li>
1560
+ </ol>
1561
+ <label class="subheader" for="<?php echo $this->field_id( array( 'up_down' => 'log' ) ); ?>"><?php _e( 'Log Template', 'mycred' ); ?></label>
1562
+ <ol>
1563
+ <li>
1564
+ <div class="h2"><input type="text" name="<?php echo $this->field_name( array( 'up_down' => 'log' ) ); ?>" id="<?php echo $this->field_id( array( 'up_down' => 'log' ) ); ?>" value="<?php echo $prefs['up_down']['log']; ?>" class="long" /></div>
1565
+ <span class="description"><?php _e( 'Available template tags: General', 'mycred' ); ?></span>
1566
+ </li>
1567
+ </ol>
1568
+ <?php unset( $this );
1569
+ }
1570
+ }
1571
+ }
1572
  ?>
modules/mycred-module-subscriptions.php CHANGED
@@ -14,7 +14,7 @@ if ( !defined( 'myCRED_VERSION' ) ) exit;
14
  * @since 1.0.5
15
  * @version 1.0
16
  */
17
- if ( !class_exists( 'myCRED_Hook_Jetpack' ) ) {
18
  class myCRED_Hook_Jetpack extends myCRED_Hook {
19
 
20
  /**
@@ -101,7 +101,7 @@ if ( !class_exists( 'myCRED_Hook_Jetpack' ) ) {
101
  if ( $this->core->exclude_user( $user->ID ) === true ) continue;
102
 
103
  // Make sure this is a unique event
104
- if ( $this->has_entry( 'site_subscription', '', $user->ID ) ) continue;
105
 
106
  // Site Subscriptions
107
  if ( $type == 'site' ) {
@@ -143,7 +143,7 @@ if ( !class_exists( 'myCRED_Hook_Jetpack' ) ) {
143
  if ( $this->core->exclude_user( $user->ID ) === true ) continue;
144
 
145
  // Start with making sure this is a unique event
146
- if ( $this->has_entry( 'comment_subscription', $id, $comment->user_id ) ) continue;
147
 
148
  $post_ids = array();
149
 
@@ -206,7 +206,7 @@ if ( !class_exists( 'myCRED_Hook_Jetpack' ) ) {
206
  return $location;
207
 
208
  // Check that this is a unique event
209
- if ( $this->has_entry( 'site_subscription', '', $user->ID ) )
210
  return $location;
211
 
212
  $this->site_subscribe( $_REQUEST['email'], $user->ID );
@@ -247,7 +247,7 @@ if ( !class_exists( 'myCRED_Hook_Jetpack' ) ) {
247
  if ( $this->core->exclude_user( $user->ID ) === true ) return;
248
 
249
  // Start with making sure this is a unique event
250
- if ( $this->has_entry( 'comment_subscription', $comment_id, $user->ID ) ) return;
251
 
252
  // Handle comment subscription
253
  if ( isset( $_REQUEST['subscribe_comments'] ) )
@@ -334,9 +334,9 @@ if ( !class_exists( 'myCRED_Hook_Jetpack' ) ) {
334
  protected function check_jetpack_subscription( $email = NULL, $post_ids = NULL ) {
335
  if ( $email === NULL ) return 'missing';
336
 
337
- if ( !class_exists( 'Jetpack' ) )
338
  require_once( JETPACK__PLUGIN_DIR . 'jetpack.php' );
339
- if ( !class_exists( 'Jetpack_Subscriptions' ) )
340
  require_once( JETPACK__PLUGIN_DIR . 'modules/subscriptions.php' );
341
 
342
  if ( $post_ids === NULL )
14
  * @since 1.0.5
15
  * @version 1.0
16
  */
17
+ if ( !class_exists( 'myCRED_Hook_Jetpack' ) && defined( 'JETPACK__PLUGIN_DIR' ) ) {
18
  class myCRED_Hook_Jetpack extends myCRED_Hook {
19
 
20
  /**
101
  if ( $this->core->exclude_user( $user->ID ) === true ) continue;
102
 
103
  // Make sure this is a unique event
104
+ if ( $this->core->has_entry( 'site_subscription', '', $user->ID ) ) continue;
105
 
106
  // Site Subscriptions
107
  if ( $type == 'site' ) {
143
  if ( $this->core->exclude_user( $user->ID ) === true ) continue;
144
 
145
  // Start with making sure this is a unique event
146
+ if ( $this->core->has_entry( 'comment_subscription', $id, $comment->user_id ) ) continue;
147
 
148
  $post_ids = array();
149
 
206
  return $location;
207
 
208
  // Check that this is a unique event
209
+ if ( $this->core->has_entry( 'site_subscription', '', $user->ID ) )
210
  return $location;
211
 
212
  $this->site_subscribe( $_REQUEST['email'], $user->ID );
247
  if ( $this->core->exclude_user( $user->ID ) === true ) return;
248
 
249
  // Start with making sure this is a unique event
250
+ if ( $this->core->has_entry( 'comment_subscription', $comment_id, $user->ID ) ) return;
251
 
252
  // Handle comment subscription
253
  if ( isset( $_REQUEST['subscribe_comments'] ) )
334
  protected function check_jetpack_subscription( $email = NULL, $post_ids = NULL ) {
335
  if ( $email === NULL ) return 'missing';
336
 
337
+ if ( !class_exists( 'Jetpack' ) && defined( 'JETPACK__PLUGIN_DIR' ) )
338
  require_once( JETPACK__PLUGIN_DIR . 'jetpack.php' );
339
+ if ( !class_exists( 'Jetpack_Subscriptions' ) && defined( 'JETPACK__PLUGIN_DIR' ) )
340
  require_once( JETPACK__PLUGIN_DIR . 'modules/subscriptions.php' );
341
 
342
  if ( $post_ids === NULL )
mycred.php CHANGED
@@ -3,17 +3,19 @@
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.1.2
7
  Tags: points, tokens, credit, management, reward, charge
8
  Author: Gabriel S Merovingi
9
  Author URI: http://www.merovingi.com
10
  Author Email: mycred@merovingi.com
11
  Requires at least: WP 3.1
12
- Tested up to: WP 3.5.1
 
 
13
  License: GPLv2 or later
14
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
15
  */
16
- define( 'myCRED_VERSION', '1.1.2' );
17
  define( 'myCRED_SLUG', 'mycred' );
18
  define( 'myCRED_NAME', '<strong>my</strong>CRED' );
19
 
@@ -475,10 +477,11 @@ if ( !class_exists( 'myCRED_Core' ) ) {
475
  /**
476
  * Enqueue Admin
477
  * @since 0.1
478
- * @version 1.0
479
  */
480
  function admin_enqueue() {
481
- // Admin Scripts
 
482
  wp_register_script(
483
  'mycred-admin',
484
  plugins_url( 'assets/js/accordion.js', myCRED_THIS ),
@@ -487,6 +490,24 @@ if ( !class_exists( 'myCRED_Core' ) ) {
487
  );
488
  wp_localize_script( 'mycred-admin', 'myCRED', apply_filters( 'mycred_localize_admin', array( 'active' => '-1' ) ) );
489
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
490
  // Admin Style
491
  wp_register_style(
492
  'mycred-admin',
@@ -495,6 +516,13 @@ if ( !class_exists( 'myCRED_Core' ) ) {
495
  myCRED_VERSION . '.1',
496
  'all'
497
  );
 
 
 
 
 
 
 
498
 
499
  // Let others play
500
  do_action( 'mycred_admin_enqueue' );
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.2
7
  Tags: points, tokens, credit, management, reward, charge
8
  Author: Gabriel S Merovingi
9
  Author URI: http://www.merovingi.com
10
  Author Email: mycred@merovingi.com
11
  Requires at least: WP 3.1
12
+ Tested up to: WP 3.6
13
+ Text Domain: mycred
14
+ Domain Path: /lang
15
  License: GPLv2 or later
16
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
17
  */
18
+ define( 'myCRED_VERSION', '1.2' );
19
  define( 'myCRED_SLUG', 'mycred' );
20
  define( 'myCRED_NAME', '<strong>my</strong>CRED' );
21
 
477
  /**
478
  * Enqueue Admin
479
  * @since 0.1
480
+ * @version 1.1
481
  */
482
  function admin_enqueue() {
483
+ $mycred = mycred_get_settings();
484
+ // General Admin Script
485
  wp_register_script(
486
  'mycred-admin',
487
  plugins_url( 'assets/js/accordion.js', myCRED_THIS ),
490
  );
491
  wp_localize_script( 'mycred-admin', 'myCRED', apply_filters( 'mycred_localize_admin', array( 'active' => '-1' ) ) );
492
 
493
+ // Inline Editing Script
494
+ wp_register_script(
495
+ 'mycred-inline-edit',
496
+ plugins_url( 'assets/js/inline-edit.js', myCRED_THIS ),
497
+ array( 'jquery', 'jquery-ui-core', 'jquery-ui-dialog', 'jquery-effects-core', 'jquery-effects-slide' ),
498
+ myCRED_VERSION . '.1'
499
+ );
500
+ wp_localize_script(
501
+ 'mycred-inline-edit',
502
+ 'myCREDedit',
503
+ array(
504
+ 'ajaxurl' => admin_url( 'admin-ajax.php' ),
505
+ 'title' => sprintf( __( 'Edit Users %s balance', 'mycred' ),$mycred->plural() ),
506
+ 'close' => __( 'Close', 'mycred' ),
507
+ 'working' => __( 'Processing...', 'mycred' )
508
+ )
509
+ );
510
+
511
  // Admin Style
512
  wp_register_style(
513
  'mycred-admin',
516
  myCRED_VERSION . '.1',
517
  'all'
518
  );
519
+ wp_register_style(
520
+ 'mycred-inline-edit',
521
+ plugins_url( 'assets/css/inline-edit.css', myCRED_THIS ),
522
+ false,
523
+ myCRED_VERSION . '.1',
524
+ 'all'
525
+ );
526
 
527
  // Let others play
528
  do_action( 'mycred_admin_enqueue' );
readme.txt CHANGED
@@ -1,10 +1,9 @@
1
  === myCRED ===
2
  Contributors: designbymerovingi
3
- Donate Link: http://mycred.me/donate/
4
  Tags:points, tokens, credit, management, reward, charge, community, contest, BuddyPress, Jetpack, bbPress
5
  Requires at least: 3.1
6
- Tested up to: 3.5.2
7
- Stable tag: 1.1.2
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
@@ -128,6 +127,9 @@ Yes but if one of them is bought, all is shown. The mycred_sell_this shortcode w
128
 
129
  == Upgrade Notice ==
130
 
 
 
 
131
  = 1.1.2 =
132
  See: http://mycred.me/download/changelog/
133
 
@@ -140,8 +142,43 @@ See: http://mycred.me/download/changelog/
140
  = 1.0.9.3 =
141
  See: http://mycred.me/download/changelog/2/
142
 
 
 
 
 
 
 
 
 
 
 
 
143
  == Changelog ==
144
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
145
  = 1.1.2 =
146
  * Fixed Bug #35 - Rankings is not displaying in BuddyPress profile header.
147
  * Fixed Bug #36 - Use of incorrect reference when calling hooks.
1
  === myCRED ===
2
  Contributors: designbymerovingi
 
3
  Tags:points, tokens, credit, management, reward, charge, community, contest, BuddyPress, Jetpack, bbPress
4
  Requires at least: 3.1
5
+ Tested up to: 3.6
6
+ Stable tag: 1.2
7
  License: GPLv2 or later
8
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
9
 
127
 
128
  == Upgrade Notice ==
129
 
130
+ = 1.2 =
131
+ See http://mycred.me/download/changelog/
132
+
133
  = 1.1.2 =
134
  See: http://mycred.me/download/changelog/
135
 
142
  = 1.0.9.3 =
143
  See: http://mycred.me/download/changelog/2/
144
 
145
+
146
+ == Other Notes ==
147
+
148
+ = Requirements =
149
+ * PHP version 5.2.4 or greater
150
+ * MySQL version 5.0 or greater
151
+
152
+ = Language Contributors =
153
+ * French - Chouf1 [Dan - BuddyPress France](http://bp-fr.net/)
154
+
155
+
156
  == Changelog ==
157
 
158
+ = 1.2 =
159
+ * Moved the has_entry() method from myCRED_Hook to myCRED Settings to allow use by other features then just hooks.
160
+ * Adjusted Hooks for clicking on links to enforce limits once per user and not once per use.
161
+ * Adjusted links.js to take into account slow server connections.
162
+ * Adjusted bad logic in BuddyPress navigation setup for points history.
163
+ * Added option to re-name the points history slug from the default "mycred-history".
164
+ * Added option to set the number of log entries to retrieve on users points history page.
165
+ * Fixed Bug #39 - If user object is not passed on when wp_login fires, the loggin_in() method fails.
166
+ * Fixed Bug #40 – Adjusted Hooks for clicking on links to enforce limits once per user and not once per use.
167
+ * Fixed Bug #41 - Only the initiator is awarded points when accepting new friendships in BuddyPress.
168
+ * Fixed Bug #42 - Excluded users still see "My Points History" page in the Users menu.
169
+ * Updated bbPress Support by adding the option to enforce a daily limit for topic replies and fav replies. Also added option to deduct points for forums, topics and replies getting deleted.
170
+ * Added new shortcode mycred_video for awarding / deducting points for viewing YouTube videos.
171
+ * Added Inline Editing of users myCRED points.
172
+ * Added option to sort users in the admin area according to their point balance.
173
+ * Added option to sort the myCRED Log Ascending or Descending.
174
+ * Renamed Transfer CREDs to Transfer %plural% on the myCRED > Settings page.
175
+ * Added Support for Event Espresso 3 though the Gateway Add-on.
176
+ * Added Support for Events Manager though the Gateway Add-on.
177
+ * Added "Rank Basis" option for the Rank add-on. Ranks can not be assigned based on current points balance or a users total accumulated points.
178
+ * Added Banking Add-on.
179
+ * Added support for GD Star Rating.
180
+ * Added new templates for MarketPress Gateway Add-on. Now you can customise the message shown when users do not have enough points to pay or are not logged in. Also inserted a table on the payment gateway selection page to show users current balance, cost and balance after payment.
181
+
182
  = 1.1.2 =
183
  * Fixed Bug #35 - Rankings is not displaying in BuddyPress profile header.
184
  * Fixed Bug #36 - Use of incorrect reference when calling hooks.