myCRED - Version 2.4.4.2-beta.1

Version Description

= 2.4.4.2 = * Improvements * Patched security vulnerability.

= 2.4.4.1 = * Improvements * Patched security vulnerability. * Badge UI Fix.

= 2.4.4 = New features and Bug fixes.

= 2.4.3 = Code improvement.

= 2.4.2 = Code improvement.

= 2.4.1 = New features and Bug fixes.

= 2.4 = New features and Bug fixes.

= 2.3.2 = Code improvement.

= 2.3.1 = Improve license system.

= 2.3 = New features and Bug fixes.

= 2.2 = New features and Bug fixes.

= 2.1.1 = New features and Bug fixes.

= 2.1 = New features and Bug fixes.

= 2.0 = The banking module have been replaced by Central deposite module, and interest related functionality has been removed. If you are using simple interest or compound interest related functionality, you will fine the respective functionalities missing after the update.

Download this release

Release Info

Developer wpexpertsio
Plugin Icon 128x128 myCRED
Version 2.4.4.2-beta.1
Comparing to
See all releases

Code changes from version 2.4.4.1 to 2.4.4.2-beta.1

Files changed (101) hide show
  1. abstracts/index.php +1 -1
  2. abstracts/mycred-abstract-hook.php +556 -483
  3. abstracts/mycred-abstract-module.php +747 -639
  4. abstracts/mycred-abstract-object.php +78 -64
  5. addons/badges/assets/css/front.css +1 -1
  6. addons/badges/assets/css/index.php +1 -1
  7. addons/badges/assets/index.php +1 -1
  8. addons/badges/assets/js/front.js +40 -28
  9. addons/badges/assets/js/index.php +1 -1
  10. addons/badges/includes/index.php +1 -1
  11. addons/badges/includes/mycred-badge-functions.php +773 -630
  12. addons/badges/includes/mycred-badge-object.php +641 -552
  13. addons/badges/includes/mycred-badge-secondary.php +90 -80
  14. addons/badges/includes/mycred-badge-shortcodes.php +129 -106
  15. addons/badges/includes/mycred-open-badge.php +244 -222
  16. addons/badges/index.php +1 -1
  17. addons/badges/myCRED-addon-badges.php +2 -15
  18. addons/badges/templates/index.php +1 -1
  19. addons/banking/abstracts/index.php +1 -1
  20. addons/banking/abstracts/mycred-abstract-service.php +424 -363
  21. addons/banking/assets/index.php +1 -1
  22. addons/banking/assets/js/index.php +1 -1
  23. addons/banking/includes/index.php +1 -1
  24. addons/banking/includes/mycred-banking-functions.php +23 -18
  25. addons/banking/index.php +1 -1
  26. addons/banking/services/index.php +1 -1
  27. addons/banking/services/mycred-service-central.php +191 -167
  28. addons/buy-creds/abstracts/index.php +1 -1
  29. addons/buy-creds/abstracts/mycred-abstract-payment-gateway.php +2232 -2135
  30. addons/buy-creds/assets/css/admin-style.css +4 -4
  31. addons/buy-creds/assets/css/index.php +1 -1
  32. addons/buy-creds/assets/images/index.php +1 -1
  33. addons/buy-creds/assets/index.php +1 -1
  34. addons/buy-creds/assets/js/checkout.js +178 -143
  35. addons/buy-creds/assets/js/index.php +1 -1
  36. addons/buy-creds/gateways/Bitpay/Autoloader.php +1 -1
  37. addons/buy-creds/gateways/Bitpay/Client/Adapter/CurlAdapter.php +6 -2
  38. addons/buy-creds/gateways/Bitpay/Client/Client.php +98 -84
  39. addons/buy-creds/gateways/Bitpay/Client/ClientInterface.php +8 -6
  40. addons/buy-creds/gateways/Bitpay/Client/Response.php +1 -1
  41. addons/buy-creds/gateways/Bitpay/Config/Configuration.php +32 -30
  42. addons/buy-creds/gateways/Bitpay/Crypto/HashExtension.php +34 -34
  43. addons/buy-creds/gateways/Bitpay/Crypto/McryptExtension.php +12 -16
  44. addons/buy-creds/gateways/Bitpay/Crypto/OpenSSLExtension.php +32 -34
  45. addons/buy-creds/gateways/Bitpay/Currency.php +3 -3
  46. addons/buy-creds/gateways/Bitpay/DependencyInjection/Loader/ArrayLoader.php +8 -6
  47. addons/buy-creds/gateways/Bitpay/Invoice.php +3 -3
  48. addons/buy-creds/gateways/Bitpay/InvoiceInterface.php +12 -12
  49. addons/buy-creds/gateways/Bitpay/Item.php +1 -1
  50. addons/buy-creds/gateways/Bitpay/Key.php +1 -1
  51. addons/buy-creds/gateways/Bitpay/Math/BcEngine.php +2 -2
  52. addons/buy-creds/gateways/Bitpay/Payout.php +27 -18
  53. addons/buy-creds/gateways/Bitpay/PayoutInstruction.php +14 -7
  54. addons/buy-creds/gateways/Bitpay/PayoutInstructionInterface.php +8 -0
  55. addons/buy-creds/gateways/Bitpay/PayoutInterface.php +1 -0
  56. addons/buy-creds/gateways/Bitpay/PayoutTransaction.php +7 -3
  57. addons/buy-creds/gateways/Bitpay/PayoutTransactionInterface.php +4 -0
  58. addons/buy-creds/gateways/Bitpay/PrivateKey.php +4 -4
  59. addons/buy-creds/gateways/Bitpay/SinKey.php +1 -1
  60. addons/buy-creds/gateways/Bitpay/Storage/EncryptedFilesystemStorage.php +9 -7
  61. addons/buy-creds/gateways/Bitpay/Storage/MockStorage.php +1 -1
  62. addons/buy-creds/gateways/Bitpay/Util/Error.php +31 -31
  63. addons/buy-creds/gateways/Bitpay/Util/Fingerprint.php +1 -1
  64. addons/buy-creds/gateways/Bitpay/Util/Util.php +13 -13
  65. addons/buy-creds/gateways/Bitpay/index.php +1 -1
  66. addons/buy-creds/gateways/bank-transfer.php +220 -192
  67. addons/buy-creds/gateways/bitpay.php +499 -470
  68. addons/buy-creds/gateways/index.php +1 -1
  69. addons/buy-creds/gateways/netbilling.php +316 -287
  70. addons/buy-creds/gateways/paypal-standard.php +369 -339
  71. addons/buy-creds/gateways/skrill.php +402 -368
  72. addons/buy-creds/images/index.php +1 -1
  73. addons/buy-creds/includes/buycred-functions.php +576 -478
  74. addons/buy-creds/includes/buycred-reward-hook.php +229 -213
  75. addons/buy-creds/includes/buycred-reward.php +82 -70
  76. addons/buy-creds/includes/buycred-shortcodes.php +1 -1
  77. addons/buy-creds/includes/index.php +1 -1
  78. addons/buy-creds/index.php +1 -1
  79. addons/buy-creds/modules/buycred-module-core.php +1291 -1173
  80. addons/buy-creds/modules/buycred-module-pending.php +750 -673
  81. addons/buy-creds/modules/index.php +1 -1
  82. addons/buy-creds/myCRED-addon-buy-creds.php +24 -19
  83. addons/buy-creds/templates/buycred-checkout.php +12 -12
  84. addons/buy-creds/templates/index.php +1 -1
  85. addons/cash-creds/abstracts/cashcred-abstract-payment-gateway.php +746 -689
  86. addons/cash-creds/abstracts/index.php +1 -1
  87. addons/cash-creds/assets/css/admin-style.css +50 -50
  88. addons/cash-creds/assets/css/index.php +1 -1
  89. addons/cash-creds/assets/css/withdraw.css +29 -29
  90. addons/cash-creds/assets/images/index.php +1 -1
  91. addons/cash-creds/assets/index.php +1 -1
  92. addons/cash-creds/assets/js/index.php +1 -1
  93. addons/cash-creds/assets/js/withdraw.js +200 -177
  94. addons/cash-creds/gateways/bank-transfer.php +311 -287
  95. addons/cash-creds/gateways/index.php +1 -1
  96. addons/cash-creds/includes/cashcred-functions.php +450 -396
  97. addons/cash-creds/includes/cashcred-shortcodes.php +437 -415
  98. addons/cash-creds/includes/index.php +1 -1
  99. addons/cash-creds/index.php +1 -1
  100. addons/cash-creds/modules/cashcred-module-core.php +2 -2
  101. addons/cash-creds/modules/cashcred-module-withdrawal.php +69 -304
abstracts/index.php CHANGED
@@ -1,3 +1,3 @@
1
  <?php
2
  // Silence is golden.
3
- ?>
1
  <?php
2
  // Silence is golden.
3
+ ?>
abstracts/mycred-abstract-hook.php CHANGED
@@ -1,540 +1,613 @@
1
  <?php
2
- if ( ! defined( 'myCRED_VERSION' ) ) exit;
 
3
 
4
  /**
5
  * myCRED_Hook class
6
- * @see http://codex.mycred.me/classes/mycred_hook/
7
- * @since 0.1
 
8
  * @version 1.3.2
9
  */
10
- if ( ! class_exists( 'myCRED_Hook' ) ) :
11
- abstract class myCRED_Hook {
12
-
13
- /**
14
- * Unique Hook ID
15
- */
16
- public $id = false;
17
-
18
- /**
19
- * The Hooks settings
20
- */
21
- public $prefs = false;
22
-
23
- /**
24
- * The current point type key
25
- */
26
- public $mycred_type = MYCRED_DEFAULT_TYPE_KEY;
27
-
28
- /**
29
- * The myCRED object for the current type
30
- */
31
- public $core = false;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
32
 
33
- /**
34
- * Array of all existing point types
35
- */
36
- public $point_types = array();
37
 
38
- /**
39
- * Indicates if the current instance is for the main point type or not
40
- */
41
- public $is_main_type = true;
42
 
43
- /**
44
- * Construct
45
- */
46
- public function __construct( $args = array(), $hook_prefs = NULL, $type = MYCRED_DEFAULT_TYPE_KEY ) {
 
 
 
 
47
 
48
- if ( ! empty( $args ) ) {
49
- foreach ( $args as $key => $value ) {
50
- $this->$key = $value;
51
- }
52
- }
53
 
54
- // Grab myCRED Settings
55
- $this->core = mycred( $type );
56
- $this->point_types = mycred_get_types();
57
 
58
- if ( $type != '' ) {
59
- $this->core->cred_id = sanitize_text_field( $type );
60
- $this->mycred_type = $this->core->cred_id;
61
- }
 
 
 
 
 
62
 
63
- if ( $this->mycred_type != MYCRED_DEFAULT_TYPE_KEY )
64
- $this->is_main_type = false;
65
 
66
- // Grab settings
67
- if ( $hook_prefs !== NULL ) {
68
 
69
- // Assign prefs if set
70
- if ( isset( $hook_prefs[ $this->id ] ) )
71
- $this->prefs = $hook_prefs[ $this->id ];
72
 
73
- // Defaults must be set
74
- if ( ! isset( $this->defaults ) )
75
- $this->defaults = array();
76
 
77
- }
 
78
 
79
- // Apply default settings if needed
80
- if ( ! empty( $this->defaults ) )
81
- $this->prefs = mycred_apply_defaults( $this->defaults, $this->prefs );
82
 
83
- }
84
 
85
- /**
86
- * Run
87
- * Must be over-ridden by sub-class!
88
- * @since 0.1
89
- * @version 1.0
90
- */
91
- public function run() {
92
 
93
- wp_die( 'function myCRED_Hook::run() must be over-ridden in a sub-class.' );
 
 
 
94
 
95
- }
96
 
97
- /**
98
- * Preferences
99
- * @since 0.1
100
- * @version 1.0
101
- */
102
- public function preferences() {
103
 
104
- echo '<p>' . __( 'This Hook has no settings', 'mycred' ) . '</p>';
 
 
 
 
 
 
 
 
105
 
106
- }
107
 
108
- /**
109
- * Sanitise Preference
110
- * @since 0.1
111
- * @version 1.0
112
- */
113
- public function sanitise_preferences( $data ) {
114
 
115
- return $data;
 
116
 
117
- }
 
 
118
 
119
- /**
120
- * Get Field Name
121
- * Returns the field name for the current hook
122
- * @since 0.1
123
- * @version 1.1
124
- */
125
- public function field_name( $field = '' ) {
126
 
127
- if ( is_array( $field ) ) {
 
128
 
129
- $array = array();
130
- foreach ( $field as $parent => $child ) {
131
 
132
- if ( ! is_numeric( $parent ) )
133
- $array[] = $parent;
134
 
135
- if ( ! empty( $child ) && ! is_array( $child ) )
136
- $array[] = $child;
137
 
138
- }
139
- $field = '[' . implode( '][', $array ) . ']';
 
 
140
 
141
- }
142
- else {
143
 
144
- $field = '[' . $field . ']';
 
 
 
145
 
146
- }
147
 
148
- $option_id = apply_filters( 'mycred_option_id', 'mycred_pref_hooks' );
149
- if ( ! $this->is_main_type )
150
- $option_id = $option_id . '_' . $this->mycred_type;
151
 
152
- return $option_id . '[hook_prefs][' . $this->id . ']' . $field;
 
 
 
 
 
 
 
153
 
154
- }
 
 
155
 
156
- /**
157
- * Get Field ID
158
- * Returns the field id for the current hook
159
- * @since 0.1
160
- * @version 1.2
161
- */
162
- public function field_id( $field = '' ) {
163
 
164
- global $mycred_field_id;
165
 
166
- if ( is_array( $field ) ) {
 
 
167
 
168
- $array = array();
169
- foreach ( $field as $parent => $child ) {
 
 
170
 
171
- if ( ! is_numeric( $parent ) )
172
- $array[] = str_replace( '_', '-', $parent );
 
 
173
 
174
- if ( ! empty( $child ) && ! is_array( $child ) )
175
- $array[] = str_replace( '_', '-', $child );
 
 
176
 
177
- }
178
- $field = implode( '-', $array );
 
 
179
 
180
- }
181
- else {
 
 
 
182
 
183
- $field = str_replace( '_', '-', $field );
 
 
184
 
185
- }
 
 
186
 
187
- $option_id = 'mycred_pref_hooks';
188
- if ( ! $this->is_main_type )
189
- $option_id = $option_id . '_' . $this->mycred_type;
190
 
191
- $option_id = str_replace( '_', '-', $option_id );
 
 
 
192
 
193
- // $mycred_field_id - This little trick is used when widgets are not in a sidebar
194
- // Adding __i__ to IDs will prevent duplicate IDs ever existing on the same page, causing
195
- // scripts or HTML structures from working, like having a checkbox/radio selected when you click on
196
- // the label and not on the input field.
197
 
198
- return $option_id . '-' . str_replace( '_', '-', $this->id ) . '-' . $field . $mycred_field_id;
 
199
 
200
- }
 
 
 
201
 
202
- /**
203
- * Check Limit
204
- * @since 1.6
205
- * @version 1.3
206
- */
207
- public function over_hook_limit( $instance = '', $reference = '', $user_id = NULL, $ref_id = NULL ) {
208
-
209
- // If logging is disabled, we cant use this feature
210
- if ( ! MYCRED_ENABLE_LOGGING ) return false;
211
-
212
- // Enforce limit if this function is used incorrectly
213
- if ( ! isset( $this->prefs[ $instance ] ) && $instance != '' )
214
- return true;
215
-
216
- global $wpdb, $mycred_log_table;
217
-
218
- // Prep
219
- $wheres = array();
220
- $now = current_time( 'timestamp' );
221
-
222
- // If hook uses multiple instances
223
- if ( isset( $this->prefs[ $instance ]['limit'] ) )
224
- $prefs = $this->prefs[ $instance ]['limit'];
225
-
226
- // Else if hook uses single instance
227
- elseif ( isset( $this->prefs['limit'] ) )
228
- $prefs = $this->prefs['limit'];
229
-
230
- // no support for limits
231
- else {
232
- return false;
233
- }
234
-
235
- // If the user ID is not set use the current one
236
- if ( $user_id === NULL )
237
- $user_id = get_current_user_id();
238
-
239
- // If this an existance check or just a regular limit check?
240
- $exists_check = false;
241
- if ( $ref_id !== NULL && strlen( $ref_id ) > 0 )
242
- $exists_check = true;
243
-
244
- if ( count( explode( '/', $prefs ) ) != 2 )
245
- $prefs = '0/x';
246
-
247
- // Set to "no limit"
248
- if ( ! $exists_check && $prefs === '0/x' ) return false;
249
-
250
- // Prep settings
251
- list ( $amount, $period ) = explode( '/', $prefs );
252
- $amount = (int) $amount;
253
-
254
- // We start constructing the query.
255
- $wheres[] = $wpdb->prepare( "user_id = %d", $user_id );
256
- $wheres[] = $wpdb->prepare( "ref = %s", $reference );
257
- $wheres[] = $wpdb->prepare( "ctype = %s", $this->mycred_type );
258
-
259
- if ( $exists_check )
260
- $wheres[] = $wpdb->prepare( "ref_id = %d", $ref_id );
261
-
262
- // If check is based on time
263
- if ( ! in_array( $period, array( 't', 'x' ) ) ) {
264
-
265
- // Per day
266
- if ( $period == 'd' )
267
- $from = mktime( 0, 0, 0, date( 'n', $now ), date( 'j', $now ), date( 'Y', $now ) );
268
-
269
- // Per week
270
- elseif ( $period == 'w' )
271
- $from = mktime( 0, 0, 0, date( "n", $now ), date( "j", $now ) - date( "N", $now ) + 1 );
272
-
273
- // Per Month
274
- elseif ( $period == 'm' )
275
- $from = mktime( 0, 0, 0, date( "n", $now ), 1, date( 'Y', $now ) );
276
-
277
- $wheres[] = $wpdb->prepare( "time BETWEEN %d AND %d", $from, $now );
278
-
279
- }
280
-
281
- $over_limit = false;
282
-
283
- if ( ! empty( $wheres ) ) {
284
-
285
- // Put all wheres together into one string
286
- $wheres = implode( " AND ", $wheres );
287
-
288
- $query = "SELECT COUNT(*) FROM {$mycred_log_table} WHERE {$wheres};";
289
-
290
- //Lets play for others
291
- $query = apply_filters( 'mycred_hook_limit_query', $query, $instance, $reference, $user_id, $ref_id, $wheres, $this );
292
-
293
- // Count
294
- $count = $wpdb->get_var( $query );
295
- if ( $count === NULL ) $count = 0;
296
-
297
- // Existence check has first priority
298
- if ( $count > 0 && $exists_check )
299
- $over_limit = true;
300
-
301
- // Limit check is second priority
302
- elseif ( $period != 'x' && $count >= $amount )
303
- $over_limit = true;
304
-
305
- }
306
-
307
- return apply_filters( 'mycred_over_hook_limit', $over_limit, $instance, $reference, $user_id, $ref_id, $this );
308
-
309
- }
310
-
311
- /**
312
- * Get Limit Types
313
- * @since 1.6
314
- * @version 1.0
315
- */
316
- public function get_limit_types() {
317
-
318
- return apply_filters( 'mycred_hook_limits', array(
319
- 'x' => __( 'No limit', 'mycred' ),
320
- 'd' => __( '/ Day', 'mycred' ),
321
- 'w' => __( '/ Week', 'mycred' ),
322
- 'm' => __( '/ Month', 'mycred' ),
323
- 't' => __( 'in Total', 'mycred' )
324
- ), $this );
325
-
326
- }
327
-
328
- /**
329
- * Select Limit
330
- * @since 1.6
331
- * @version 1.0
332
- */
333
- public function hook_limit_setting( $name = '', $id = '', $selected = '' ) {
334
-
335
- // Convert string value into an array
336
- $check = explode( '/', $selected );
337
- $count = count( $check );
338
-
339
- if ( $count == 0 || ( $count == 1 && $check[0] == 0 ) )
340
- $selected = array( 0, 'x' );
341
-
342
- elseif ( $count == 1 && $check[0] != '' && is_numeric( $check[0] ) )
343
- $selected = array( (int) $check[0], 'd' );
344
-
345
- else
346
- $selected = $check;
347
-
348
- // Hide value field if no limit is set
349
- $hide = 'text';
350
- if ( $selected[1] == 'x' )
351
- $hide = 'hidden';
352
-
353
- // The limit value field
354
- $output = '<div class="h2"><input type="' . $hide . '" size="8" class="mini" name="' . $name . '" id="' . $id . '" value="' . $selected[0] . '" />';
355
-
356
- // Get limit options
357
- $options = $this->get_limit_types();
358
-
359
- // Adjust the field name
360
- $name = str_replace( '[limit]', '[limit_by]', $name );
361
- $name = str_replace( '[alimit]', '[alimit_by]', $name );
362
- $name = apply_filters( 'mycred_hook_limit_name_by', $name, $this );
363
-
364
- // Adjust the field id
365
- $id = str_replace( 'limit', 'limit-by', $id );
366
- $id = str_replace( 'alimit', 'alimit-by', $id );
367
- $id = apply_filters( 'mycred_hook_limit_id_by', $id, $this );
368
-
369
- // Generate dropdown menu
370
- $output .= '<select name="' . $name . '" id="' . $id . '" class="limit-toggle">';
371
- foreach ( $options as $value => $label ) {
372
- $output .= '<option value="' . $value . '"';
373
- if ( $selected[1] == $value ) $output .= ' selected="selected"';
374
- $output .= '>' . $label . '</option>';
375
- }
376
- $output .= '</select></div>';
377
-
378
- return $output;
379
-
380
- }
381
-
382
- /**
383
- * Impose Limits Dropdown
384
- * @since 0.1
385
- * @version 1.3
386
- */
387
- public function impose_limits_dropdown( $pref_id = '', $use_select = true ) {
388
-
389
- $settings = '';
390
- $limits = array(
391
- '' => __( 'No limit', 'mycred' ),
392
- 'twentyfour' => __( 'Once every 24 hours', 'mycred' ),
393
- 'sevendays' => __( 'Once every 7 days', 'mycred' ),
394
- 'daily' => __( 'Once per day (reset at midnight)', 'mycred' )
395
- );
396
- $limits = apply_filters( 'mycred_hook_impose_limits', $limits, $this );
397
-
398
- echo '<select name="' . $this->field_name( $pref_id ) . '" id="' . $this->field_id( $pref_id ) . '" class="form-control">';
399
-
400
- if ( $use_select )
401
- echo '<option value="">' . __( 'Select', 'mycred' ) . '</option>';
402
-
403
- if ( is_array( $pref_id ) ) {
404
-
405
- reset( $pref_id );
406
- $key = key( $pref_id );
407
- $settings = $this->prefs[ $key ][ $pref_id[ $key ] ];
408
-
409
- }
410
- elseif ( isset( $this->prefs[ $pref_id ] ) ) {
411
-
412
- $settings = $this->prefs[ $pref_id ];
413
-
414
- }
415
-
416
- foreach ( $limits as $value => $description ) {
417
- echo '<option value="' . $value . '"';
418
- if ( $settings == $value ) echo ' selected="selected"';
419
- echo '>' . $description . '</option>';
420
- }
421
- echo '</select>';
422
-
423
- }
424
-
425
- /**
426
- * Has Entry
427
- * Moved to myCRED_Settings
428
- * @since 0.1
429
- * @version 1.3
430
- */
431
- public function has_entry( $action = '', $ref_id = '', $user_id = '', $data = '', $point_type = '' ) {
432
-
433
- // If logging is disabled, we cant use this feature
434
- if ( ! MYCRED_ENABLE_LOGGING ) return false;
435
-
436
- if ( $point_type == '' )
437
- $point_type = $this->mycred_type;
438
-
439
- return $this->core->has_entry( $action, $ref_id, $user_id, $data, $point_type );
440
-
441
- }
442
-
443
- /**
444
- * Available Template Tags
445
- * @since 1.4
446
- * @version 1.0
447
- */
448
- public function available_template_tags( $available = array(), $custom = '' ) {
449
-
450
- return $this->core->available_template_tags( $available, $custom );
451
-
452
- }
453
-
454
- /**
455
- * Over Daily Limit
456
- * @since 1.0
457
- * @version 1.1.1
458
- */
459
- public function is_over_daily_limit( $ref = '', $user_id = 0, $max = 0, $ref_id = NULL ) {
460
-
461
- // If logging is disabled, we cant use this feature
462
- if ( ! MYCRED_ENABLE_LOGGING ) return false;
463
-
464
- // Prep
465
- $reply = true;
466
-
467
- // DB Query
468
- $total = $this->limit_query( $ref, $user_id, strtotime( 'today midnight', $this->now ), $this->now, $ref_id );
469
-
470
- if ( $total < $max )
471
- $reply = false;
472
-
473
- return apply_filters( 'mycred_hook_over_daily_limit', $reply, $ref, $user_id, $max );
474
-
475
- }
476
-
477
- /**
478
- * Include Post Type
479
- * Checks if a given post type should be excluded
480
- * @since 0.1
481
- * @version 1.1
482
- */
483
- public function include_post_type( $post_type ) {
484
-
485
- // Exclude Core
486
- $excludes = array( 'post', 'page' );
487
- if ( in_array( $post_type, apply_filters( 'mycred_post_type_excludes', $excludes ) ) ) return false;
488
-
489
- return true;
490
-
491
- }
492
-
493
- /**
494
- * Limit Query
495
- * Queries the myCRED log for the number of occurances of the specified
496
- * refernece and optional reference id for a specific user between two dates.
497
- * @param $ref (string) reference to search for, required
498
- * @param $user_id (int) user id to search for, required
499
- * @param $start (int) unix timestamp for start date, required
500
- * @param $end (int) unix timestamp for the end date, required
501
- * @param $ref_id (int) optional reference id to include in search
502
- * @returns number of entries found (int) or NULL if required params are missing
503
- * @since 1.4
504
- * @version 1.2
505
- */
506
- public function limit_query( $ref = '', $user_id = 0, $start = 0, $end = 0, $ref_id = NULL ) {
507
-
508
- // If logging is disabled, we cant use this feature
509
- if ( ! MYCRED_ENABLE_LOGGING ) return 0;
510
-
511
- // Minimum requirements
512
- if ( empty( $ref ) || $user_id == 0 || $start == 0 || $end == 0 )
513
- return NULL;
514
-
515
- global $wpdb, $mycred_log_table;
516
-
517
- // Prep
518
- $reply = true;
519
- $wheres = array();
520
-
521
- $wheres[] = $wpdb->prepare( "ref = %s", $ref );
522
- $wheres[] = $wpdb->prepare( "user_id = %d", $user_id );
523
- $wheres[] = $wpdb->prepare( "time BETWEEN %d AND %d", $start, $end );
524
- $wheres[] = $wpdb->prepare( "ctype = %s", $this->mycred_type );
525
-
526
- if ( $ref_id !== NULL )
527
- $wheres[] = $wpdb->prepare( "ref_id = %d", $ref_id );
528
-
529
- $wheres = implode( " AND ", $wheres );
530
-
531
- // DB Query
532
- $total = $wpdb->get_var( "SELECT COUNT(*) FROM {$mycred_log_table} WHERE {$wheres};" );
533
- if ( $total === NULL ) $total = 0;
534
-
535
- return apply_filters( 'mycred_hook_limit_query', $total, $ref, $user_id, $ref_id, $start, $end );
536
-
537
- }
538
-
539
- }
540
  endif;
1
  <?php
2
+ if (! defined('myCRED_VERSION') ) { exit;
3
+ }
4
 
5
  /**
6
  * myCRED_Hook class
7
+ *
8
+ * @see http://codex.mycred.me/classes/mycred_hook/
9
+ * @since 0.1
10
  * @version 1.3.2
11
  */
12
+ if (! class_exists('myCRED_Hook') ) :
13
+ abstract class myCRED_Hook
14
+ {
15
+
16
+ /**
17
+ * Unique Hook ID
18
+ */
19
+ public $id = false;
20
+
21
+ /**
22
+ * The Hooks settings
23
+ */
24
+ public $prefs = false;
25
+
26
+ /**
27
+ * The current point type key
28
+ */
29
+ public $mycred_type = MYCRED_DEFAULT_TYPE_KEY;
30
+
31
+ /**
32
+ * The myCRED object for the current type
33
+ */
34
+ public $core = false;
35
+
36
+ /**
37
+ * Array of all existing point types
38
+ */
39
+ public $point_types = array();
40
+
41
+ /**
42
+ * Indicates if the current instance is for the main point type or not
43
+ */
44
+ public $is_main_type = true;
45
+
46
+ /**
47
+ * Construct
48
+ */
49
+ public function __construct( $args = array(), $hook_prefs = null, $type = MYCRED_DEFAULT_TYPE_KEY )
50
+ {
51
+
52
+ if (! empty($args) ) {
53
+ foreach ( $args as $key => $value ) {
54
+ $this->$key = $value;
55
+ }
56
+ }
57
+
58
+ // Grab myCRED Settings
59
+ $this->core = mycred($type);
60
+ $this->point_types = mycred_get_types();
61
+
62
+ if ($type != '' ) {
63
+ $this->core->cred_id = sanitize_text_field($type);
64
+ $this->mycred_type = $this->core->cred_id;
65
+ }
66
+
67
+ if ($this->mycred_type != MYCRED_DEFAULT_TYPE_KEY ) {
68
+ $this->is_main_type = false;
69
+ }
70
+
71
+ // Grab settings
72
+ if ($hook_prefs !== null ) {
73
+
74
+ // Assign prefs if set
75
+ if (isset($hook_prefs[ $this->id ]) ) {
76
+ $this->prefs = $hook_prefs[ $this->id ];
77
+ }
78
+
79
+ // Defaults must be set
80
+ if (! isset($this->defaults) ) {
81
+ $this->defaults = array();
82
+ }
83
+
84
+ }
85
+
86
+ // Apply default settings if needed
87
+ if (! empty($this->defaults) ) {
88
+ $this->prefs = mycred_apply_defaults($this->defaults, $this->prefs);
89
+ }
90
+
91
+ }
92
+
93
+ /**
94
+ * Run
95
+ * Must be over-ridden by sub-class!
96
+ *
97
+ * @since 0.1
98
+ * @version 1.0
99
+ */
100
+ public function run()
101
+ {
102
+
103
+ wp_die('function myCRED_Hook::run() must be over-ridden in a sub-class.');
104
+
105
+ }
106
+
107
+ /**
108
+ * Preferences
109
+ *
110
+ * @since 0.1
111
+ * @version 1.0
112
+ */
113
+ public function preferences()
114
+ {
115
 
116
+ echo '<p>' . __('This Hook has no settings', 'mycred') . '</p>';
 
 
 
117
 
118
+ }
 
 
 
119
 
120
+ /**
121
+ * Sanitise Preference
122
+ *
123
+ * @since 0.1
124
+ * @version 1.0
125
+ */
126
+ public function sanitise_preferences( $data )
127
+ {
128
 
129
+ return $data;
 
 
 
 
130
 
131
+ }
 
 
132
 
133
+ /**
134
+ * Get Field Name
135
+ * Returns the field name for the current hook
136
+ *
137
+ * @since 0.1
138
+ * @version 1.1
139
+ */
140
+ public function field_name( $field = '' )
141
+ {
142
 
143
+ if (is_array($field) ) {
 
144
 
145
+ $array = array();
146
+ foreach ( $field as $parent => $child ) {
147
 
148
+ if (! is_numeric($parent) ) {
149
+ $array[] = $parent;
150
+ }
151
 
152
+ if (! empty($child) && ! is_array($child) ) {
153
+ $array[] = $child;
154
+ }
155
 
156
+ }
157
+ $field = '[' . implode('][', $array) . ']';
158
 
159
+ }
160
+ else {
 
161
 
162
+ $field = '[' . $field . ']';
163
 
164
+ }
 
 
 
 
 
 
165
 
166
+ $option_id = apply_filters('mycred_option_id', 'mycred_pref_hooks');
167
+ if (! $this->is_main_type ) {
168
+ $option_id = $option_id . '_' . $this->mycred_type;
169
+ }
170
 
171
+ return $option_id . '[hook_prefs][' . $this->id . ']' . $field;
172
 
173
+ }
 
 
 
 
 
174
 
175
+ /**
176
+ * Get Field ID
177
+ * Returns the field id for the current hook
178
+ *
179
+ * @since 0.1
180
+ * @version 1.2
181
+ */
182
+ public function field_id( $field = '' )
183
+ {
184
 
185
+ global $mycred_field_id;
186
 
187
+ if (is_array($field) ) {
 
 
 
 
 
188
 
189
+ $array = array();
190
+ foreach ( $field as $parent => $child ) {
191
 
192
+ if (! is_numeric($parent) ) {
193
+ $array[] = str_replace('_', '-', $parent);
194
+ }
195
 
196
+ if (! empty($child) && ! is_array($child) ) {
197
+ $array[] = str_replace('_', '-', $child);
198
+ }
 
 
 
 
199
 
200
+ }
201
+ $field = implode('-', $array);
202
 
203
+ }
204
+ else {
205
 
206
+ $field = str_replace('_', '-', $field);
 
207
 
208
+ }
 
209
 
210
+ $option_id = 'mycred_pref_hooks';
211
+ if (! $this->is_main_type ) {
212
+ $option_id = $option_id . '_' . $this->mycred_type;
213
+ }
214
 
215
+ $option_id = str_replace('_', '-', $option_id);
 
216
 
217
+ // $mycred_field_id - This little trick is used when widgets are not in a sidebar
218
+ // Adding __i__ to IDs will prevent duplicate IDs ever existing on the same page, causing
219
+ // scripts or HTML structures from working, like having a checkbox/radio selected when you click on
220
+ // the label and not on the input field.
221
 
222
+ return $option_id . '-' . str_replace('_', '-', $this->id) . '-' . $field . $mycred_field_id;
223
 
224
+ }
 
 
225
 
226
+ /**
227
+ * Check Limit
228
+ *
229
+ * @since 1.6
230
+ * @version 1.3
231
+ */
232
+ public function over_hook_limit( $instance = '', $reference = '', $user_id = null, $ref_id = null )
233
+ {
234
 
235
+ // If logging is disabled, we cant use this feature
236
+ if (! MYCRED_ENABLE_LOGGING ) { return false;
237
+ }
238
 
239
+ // Enforce limit if this function is used incorrectly
240
+ if (! isset($this->prefs[ $instance ]) && $instance != '' ) {
241
+ return true;
242
+ }
 
 
 
243
 
244
+ global $wpdb, $mycred_log_table;
245
 
246
+ // Prep
247
+ $wheres = array();
248
+ $now = current_time('timestamp');
249
 
250
+ // If hook uses multiple instances
251
+ if (isset($this->prefs[ $instance ]['limit']) ) {
252
+ $prefs = $this->prefs[ $instance ]['limit'];
253
+ }
254
 
255
+ // Else if hook uses single instance
256
+ elseif (isset($this->prefs['limit']) ) {
257
+ $prefs = $this->prefs['limit'];
258
+ }
259
 
260
+ // no support for limits
261
+ else {
262
+ return false;
263
+ }
264
 
265
+ // If the user ID is not set use the current one
266
+ if ($user_id === null ) {
267
+ $user_id = get_current_user_id();
268
+ }
269
 
270
+ // If this an existance check or just a regular limit check?
271
+ $exists_check = false;
272
+ if ($ref_id !== null && strlen($ref_id) > 0 ) {
273
+ $exists_check = true;
274
+ }
275
 
276
+ if (count(explode('/', $prefs)) != 2 ) {
277
+ $prefs = '0/x';
278
+ }
279
 
280
+ // Set to "no limit"
281
+ if (! $exists_check && $prefs === '0/x' ) { return false;
282
+ }
283
 
284
+ // Prep settings
285
+ list ( $amount, $period ) = explode('/', $prefs);
286
+ $amount = (int) $amount;
287
 
288
+ // We start constructing the query.
289
+ $wheres[] = $wpdb->prepare("user_id = %d", $user_id);
290
+ $wheres[] = $wpdb->prepare("ref = %s", $reference);
291
+ $wheres[] = $wpdb->prepare("ctype = %s", $this->mycred_type);
292
 
293
+ if ($exists_check ) {
294
+ $wheres[] = $wpdb->prepare("ref_id = %d", $ref_id);
295
+ }
 
296
 
297
+ // If check is based on time
298
+ if (! in_array($period, array( 't', 'x' )) ) {
299
 
300
+ // Per day
301
+ if ($period == 'd' ) {
302
+ $from = mktime(0, 0, 0, date('n', $now), date('j', $now), date('Y', $now));
303
+ }
304
 
305
+ // Per week
306
+ elseif ($period == 'w' ) {
307
+ $from = mktime(0, 0, 0, date("n", $now), date("j", $now) - date("N", $now) + 1);
308
+ }
309
+
310
+ // Per Month
311
+ elseif ($period == 'm' ) {
312
+ $from = mktime(0, 0, 0, date("n", $now), 1, date('Y', $now));
313
+ }
314
+
315
+ $wheres[] = $wpdb->prepare("time BETWEEN %d AND %d", $from, $now);
316
+
317
+ }
318
+
319
+ $over_limit = false;
320
+
321
+ if (! empty($wheres) ) {
322
+
323
+ // Put all wheres together into one string
324
+ $wheres = implode(" AND ", $wheres);
325
+
326
+ $query = "SELECT COUNT(*) FROM {$mycred_log_table} WHERE {$wheres};";
327
+
328
+ //Lets play for others
329
+ $query = apply_filters('mycred_hook_limit_query', $query, $instance, $reference, $user_id, $ref_id, $wheres, $this);
330
+
331
+ // Count
332
+ $count = $wpdb->get_var($query);
333
+ if ($count === null ) { $count = 0;
334
+ }
335
+
336
+ // Existence check has first priority
337
+ if ($count > 0 && $exists_check ) {
338
+ $over_limit = true;
339
+ }
340
+
341
+ // Limit check is second priority
342
+ elseif ($period != 'x' && $count >= $amount ) {
343
+ $over_limit = true;
344
+ }
345
+
346
+ }
347
+
348
+ return apply_filters('mycred_over_hook_limit', $over_limit, $instance, $reference, $user_id, $ref_id, $this);
349
+
350
+ }
351
+
352
+ /**
353
+ * Get Limit Types
354
+ *
355
+ * @since 1.6
356
+ * @version 1.0
357
+ */
358
+ public function get_limit_types()
359
+ {
360
+
361
+ return apply_filters(
362
+ 'mycred_hook_limits', array(
363
+ 'x' => __('No limit', 'mycred'),
364
+ 'd' => __('/ Day', 'mycred'),
365
+ 'w' => __('/ Week', 'mycred'),
366
+ 'm' => __('/ Month', 'mycred'),
367
+ 't' => __('in Total', 'mycred')
368
+ ), $this
369
+ );
370
+
371
+ }
372
+
373
+ /**
374
+ * Select Limit
375
+ *
376
+ * @since 1.6
377
+ * @version 1.0
378
+ */
379
+ public function hook_limit_setting( $name = '', $id = '', $selected = '' )
380
+ {
381
+
382
+ // Convert string value into an array
383
+ $check = explode('/', $selected);
384
+ $count = count($check);
385
+
386
+ if ($count == 0 || ( $count == 1 && $check[0] == 0 ) ) {
387
+ $selected = array( 0, 'x' );
388
+
389
+ } elseif ($count == 1 && $check[0] != '' && is_numeric($check[0]) ) {
390
+ $selected = array( (int) $check[0], 'd' );
391
+
392
+ } else {
393
+ $selected = $check;
394
+ }
395
+
396
+ // Hide value field if no limit is set
397
+ $hide = 'text';
398
+ if ($selected[1] == 'x' ) {
399
+ $hide = 'hidden';
400
+ }
401
+
402
+ // The limit value field
403
+ $output = '<div class="h2"><input type="' . $hide . '" size="8" class="mini" name="' . $name . '" id="' . $id . '" value="' . $selected[0] . '" />';
404
+
405
+ // Get limit options
406
+ $options = $this->get_limit_types();
407
+
408
+ // Adjust the field name
409
+ $name = str_replace('[limit]', '[limit_by]', $name);
410
+ $name = str_replace('[alimit]', '[alimit_by]', $name);
411
+ $name = apply_filters('mycred_hook_limit_name_by', $name, $this);
412
+
413
+ // Adjust the field id
414
+ $id = str_replace('limit', 'limit-by', $id);
415
+ $id = str_replace('alimit', 'alimit-by', $id);
416
+ $id = apply_filters('mycred_hook_limit_id_by', $id, $this);
417
+
418
+ // Generate dropdown menu
419
+ $output .= '<select name="' . $name . '" id="' . $id . '" class="limit-toggle">';
420
+ foreach ( $options as $value => $label ) {
421
+ $output .= '<option value="' . $value . '"';
422
+ if ($selected[1] == $value ) { $output .= ' selected="selected"';
423
+ }
424
+ $output .= '>' . $label . '</option>';
425
+ }
426
+ $output .= '</select></div>';
427
+
428
+ return $output;
429
+
430
+ }
431
+
432
+ /**
433
+ * Impose Limits Dropdown
434
+ *
435
+ * @since 0.1
436
+ * @version 1.3
437
+ */
438
+ public function impose_limits_dropdown( $pref_id = '', $use_select = true )
439
+ {
440
+
441
+ $settings = '';
442
+ $limits = array(
443
+ '' => __('No limit', 'mycred'),
444
+ 'twentyfour' => __('Once every 24 hours', 'mycred'),
445
+ 'sevendays' => __('Once every 7 days', 'mycred'),
446
+ 'daily' => __('Once per day (reset at midnight)', 'mycred')
447
+ );
448
+ $limits = apply_filters('mycred_hook_impose_limits', $limits, $this);
449
+
450
+ echo '<select name="' . $this->field_name($pref_id) . '" id="' . $this->field_id($pref_id) . '" class="form-control">';
451
+
452
+ if ($use_select ) {
453
+ echo '<option value="">' . __('Select', 'mycred') . '</option>';
454
+ }
455
+
456
+ if (is_array($pref_id) ) {
457
+
458
+ reset($pref_id);
459
+ $key = key($pref_id);
460
+ $settings = $this->prefs[ $key ][ $pref_id[ $key ] ];
461
+
462
+ }
463
+ elseif (isset($this->prefs[ $pref_id ]) ) {
464
+
465
+ $settings = $this->prefs[ $pref_id ];
466
+
467
+ }
468
+
469
+ foreach ( $limits as $value => $description ) {
470
+ echo '<option value="' . $value . '"';
471
+ if ($settings == $value ) { echo ' selected="selected"';
472
+ }
473
+ echo '>' . $description . '</option>';
474
+ }
475
+ echo '</select>';
476
+
477
+ }
478
+
479
+ /**
480
+ * Has Entry
481
+ * Moved to myCRED_Settings
482
+ *
483
+ * @since 0.1
484
+ * @version 1.3
485
+ */
486
+ public function has_entry( $action = '', $ref_id = '', $user_id = '', $data = '', $point_type = '' )
487
+ {
488
+
489
+ // If logging is disabled, we cant use this feature
490
+ if (! MYCRED_ENABLE_LOGGING ) { return false;
491
+ }
492
+
493
+ if ($point_type == '' ) {
494
+ $point_type = $this->mycred_type;
495
+ }
496
+
497
+ return $this->core->has_entry($action, $ref_id, $user_id, $data, $point_type);
498
+
499
+ }
500
+
501
+ /**
502
+ * Available Template Tags
503
+ *
504
+ * @since 1.4
505
+ * @version 1.0
506
+ */
507
+ public function available_template_tags( $available = array(), $custom = '' )
508
+ {
509
+
510
+ return $this->core->available_template_tags($available, $custom);
511
+
512
+ }
513
+
514
+ /**
515
+ * Over Daily Limit
516
+ *
517
+ * @since 1.0
518
+ * @version 1.1.1
519
+ */
520
+ public function is_over_daily_limit( $ref = '', $user_id = 0, $max = 0, $ref_id = null )
521
+ {
522
+
523
+ // If logging is disabled, we cant use this feature
524
+ if (! MYCRED_ENABLE_LOGGING ) { return false;
525
+ }
526
+
527
+ // Prep
528
+ $reply = true;
529
+
530
+ // DB Query
531
+ $total = $this->limit_query($ref, $user_id, strtotime('today midnight', $this->now), $this->now, $ref_id);
532
+
533
+ if ($total < $max ) {
534
+ $reply = false;
535
+ }
536
+
537
+ return apply_filters('mycred_hook_over_daily_limit', $reply, $ref, $user_id, $max);
538
+
539
+ }
540
+
541
+ /**
542
+ * Include Post Type
543
+ * Checks if a given post type should be excluded
544
+ *
545
+ * @since 0.1
546
+ * @version 1.1
547
+ */
548
+ public function include_post_type( $post_type )
549
+ {
550
+
551
+ // Exclude Core
552
+ $excludes = array( 'post', 'page' );
553
+ if (in_array($post_type, apply_filters('mycred_post_type_excludes', $excludes)) ) { return false;
554
+ }
555
+
556
+ return true;
557
+
558
+ }
559
+
560
+ /**
561
+ * Limit Query
562
+ * Queries the myCRED log for the number of occurances of the specified
563
+ * refernece and optional reference id for a specific user between two dates.
564
+ *
565
+ * @param $ref (string) reference to search for, required
566
+ * @param $user_id (int) user id to search for, required
567
+ * @param $start (int) unix timestamp for start date, required
568
+ * @param $end (int) unix timestamp for the end date, required
569
+ * @param $ref_id (int) optional reference id to include in search
570
+ * @returns number of entries found (int) or NULL if required params are missing
571
+ * @since 1.4
572
+ * @version 1.2
573
+ */
574
+ public function limit_query( $ref = '', $user_id = 0, $start = 0, $end = 0, $ref_id = null )
575
+ {
576
+
577
+ // If logging is disabled, we cant use this feature
578
+ if (! MYCRED_ENABLE_LOGGING ) { return 0;
579
+ }
580
+
581
+ // Minimum requirements
582
+ if (empty($ref) || $user_id == 0 || $start == 0 || $end == 0 ) {
583
+ return null;
584
+ }
585
+
586
+ global $wpdb, $mycred_log_table;
587
+
588
+ // Prep
589
+ $reply = true;
590
+ $wheres = array();
591
+
592
+ $wheres[] = $wpdb->prepare("ref = %s", $ref);
593
+ $wheres[] = $wpdb->prepare("user_id = %d", $user_id);
594
+ $wheres[] = $wpdb->prepare("time BETWEEN %d AND %d", $start, $end);
595
+ $wheres[] = $wpdb->prepare("ctype = %s", $this->mycred_type);
596
+
597
+ if ($ref_id !== null ) {
598
+ $wheres[] = $wpdb->prepare("ref_id = %d", $ref_id);
599
+ }
600
+
601
+ $wheres = implode(" AND ", $wheres);
602
+
603
+ // DB Query
604
+ $total = $wpdb->get_var("SELECT COUNT(*) FROM {$mycred_log_table} WHERE {$wheres};");
605
+ if ($total === null ) { $total = 0;
606
+ }
607
+
608
+ return apply_filters('mycred_hook_limit_query', $total, $ref, $user_id, $ref_id, $start, $end);
609
+
610
+ }
611
+
612
+ }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
613
  endif;
abstracts/mycred-abstract-module.php CHANGED
@@ -1,725 +1,833 @@
1
  <?php
2
- if ( ! defined( 'myCRED_VERSION' ) ) exit;
 
3
 
4
  /**
5
  * myCRED_Module class
6
- * @see http://codex.mycred.me/classes/mycred_module/
7
- * @since 0.1
 
8
  * @version 1.3.5
9
  */
10
- if ( ! class_exists( 'myCRED_Module' ) ) :
11
- abstract class myCRED_Module {
 
12
 
13
- // Module ID (unique)
14
- public $module_id;
15
 
16
- // Core settings & functions
17
- public $core;
18
 
19
- // Module name (string)
20
- public $module_name;
21
 
22
- // Option ID (string|array)
23
- public $option_id;
24
 
25
- // Labels (array)
26
- public $labels;
27
 
28
- // Register (bool)
29
- public $register;
30
 
31
- // Screen ID (string)
32
- public $screen_id;
33
 
34
- // Menu Position (int)
35
- public $menu_pos;
36
 
37
- // Default preferences
38
- public $default_prefs = array();
39
 
40
- // Is Main Cred Type
41
- public $is_main_type = true;
42
 
43
- // myCRED Type used
44
- public $mycred_type;
45
 
46
- // All registered point types
47
- public $point_types;
48
 
49
- // Current users ID
50
- public $current_user_id;
51
 
52
- // Current time
53
- public $now;
54
 
55
- // Pages
56
- public $pages = array();
57
 
58
- // Submenu Inside Main menu
59
- public $main_menu;
60
 
61
- /**
62
- * Construct
63
- */
64
- public function __construct( $module_id = '', $args = array(), $type = MYCRED_DEFAULT_TYPE_KEY ) {
 
65
 
66
- // Module ID is required
67
- if ( empty( $module_id ) ) wp_die( 'myCRED_Module() Error. A Module ID is required!' );
 
68
 
69
- $this->module_id = $module_id;
70
- $this->core = mycred( $type );
71
 
72
- if ( ! empty( $type ) ) {
73
- $this->core->cred_id = sanitize_text_field( $type );
74
- $this->mycred_type = $this->core->cred_id;
75
- }
76
 
77
- if ( $this->mycred_type != MYCRED_DEFAULT_TYPE_KEY )
78
- $this->is_main_type = false;
 
79
 
80
- $this->point_types = mycred_get_types();
81
 
82
- // Default arguments
83
- $defaults = array(
84
- 'module_name' => '',
85
- 'option_id' => '',
86
- 'defaults' => array(),
87
- 'labels' => array(
88
- 'menu' => '',
89
- 'page_title' => ''
90
- ),
91
- 'register' => true,
92
- 'screen_id' => '',
93
- 'add_to_core' => false,
94
- 'accordion' => false,
95
- 'cap' => 'plugin',
96
- 'menu_pos' => 10,
97
- 'main_menu' => false
98
- );
99
- $args = wp_parse_args( $args, $defaults );
100
 
101
- $this->module_name = $args['module_name'];
102
- $this->option_id = $args['option_id'];
103
 
104
- if ( ! $this->is_main_type )
105
- $this->option_id .= '_' . $this->mycred_type;
 
106
 
107
- $this->settings_name = 'myCRED-' . $this->module_name;
108
- if ( ! $this->is_main_type )
109
- $this->settings_name .= '-' . $this->mycred_type;
 
110
 
111
- $this->labels = $args['labels'];
112
- $this->register = $args['register'];
113
- $this->screen_id = $args['screen_id'];
114
 
115
- if ( ! $this->is_main_type && ! empty( $this->screen_id ) )
116
- $this->screen_id = 'mycred_' . $this->mycred_type . substr( $this->screen_id, 6 );
 
117
 
118
- $this->add_to_core = $args['add_to_core'];
119
- $this->accordion = $args['accordion'];
120
- $this->cap = $args['cap'];
121
- $this->menu_pos = $args['menu_pos'];
122
 
123
- $this->default_prefs = $args['defaults'];
124
- $this->now = current_time( 'timestamp' );
125
- $this->main_menu = $args['main_menu'];
126
 
127
- $this->set_settings();
128
 
129
- }
130
 
131
- /**
132
- * Set Settings
133
- * @since 0.1
134
- * @version 1.2.1
135
- */
136
- public function set_settings() {
 
 
137
 
138
- $module = $this->module_name;
139
 
140
- // Reqest not to register any settings
141
- if ( $this->register === false ) {
142
 
143
- // If settings does not exist apply defaults
144
- if ( ! isset( $this->core->$module ) )
145
- $this->$module = $this->default_prefs;
 
146
 
147
- // Else append settings
148
- else
149
- $this->$module = $this->core->$module;
 
150
 
151
- // Apply defaults in case new settings have been applied
152
- if ( ! empty( $this->default_prefs ) )
153
- $this->$module = wp_parse_args( $this->$module, $this->default_prefs );
 
154
 
155
- }
156
 
157
- // Request to register settings
158
- else {
159
 
160
- // Option IDs must be provided
161
- if ( ! empty( $this->option_id ) ) {
162
 
163
- // Array = more then one
164
- if ( is_array( $this->option_id ) ) {
165
 
166
- // General settings needs not to be loaded
167
- $pattern = 'mycred_pref_core';
168
- //$matches = array_filter( $this->option_id, function( $a ) use ( $pattern ) { return preg_grep( $a, $pattern ); } );
169
- //if ( ! empty( $matches ) )
170
- $this->$module = $this->core;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
171
 
172
- // Loop and grab
173
- foreach ( $this->option_id as $option_id => $option_name ) {
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
174
 
175
- $settings = mycred_get_option( $option_name, false );
 
 
 
 
 
 
 
 
 
 
 
 
176
 
177
- if ( $settings === false && array_key_exists( $option_id, $defaults ) )
178
- $this->$module[ $option_name ] = $this->default_prefs[ $option_id ];
179
- else
180
- $this->$module[ $option_name ] = $settings;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
181
 
182
- // Apply defaults in case new settings have been applied
183
- if ( array_key_exists( $option_id, $this->default_prefs ) )
184
- $this->$module[ $option_name ] = wp_parse_args( $this->$module[ $option_name ], $this->default_prefs[ $option_id ] );
185
-
186
- }
187
-
188
- }
189
-
190
- // String = one
191
- else {
192
-
193
- // General settings needs not to be loaded
194
- if ( str_replace( 'mycred_pref_core', '', $this->option_id ) == '' )
195
- $this->$module = $this->core;
196
-
197
- // Grab the requested option
198
- else {
199
-
200
- $this->$module = mycred_get_option( $this->option_id, false );
201
-
202
- if ( $this->$module === false && ! empty( $this->default_prefs ) )
203
- $this->$module = $this->default_prefs;
204
-
205
- // Apply defaults in case new settings have been applied
206
- if ( ! empty( $this->default_prefs ) )
207
- $this->$module = wp_parse_args( $this->$module, $this->default_prefs );
208
-
209
- }
210
-
211
- }
212
-
213
- if ( is_array( $this->$module ) ) {
214
-
215
- foreach ( $this->$module as $key => $value ) {
216
- $this->$key = $value;
217
- }
218
-
219
- }
220
-
221
- }
222
-
223
- }
224
-
225
- }
226
-
227
- /**
228
- * Load
229
- * @since 0.1
230
- * @version 1.0.1
231
- */
232
- public function load() {
233
-
234
- if ( ! empty( $this->screen_id ) && ! empty( $this->labels['menu'] ) ) {
235
- add_action( 'mycred_add_menu', array( $this, 'add_menu' ), $this->menu_pos );
236
- add_action( 'admin_init', array( $this, 'set_entries_per_page' ) );
237
- }
238
-
239
- if ( $this->register === true && ! empty( $this->option_id ) )
240
- add_action( 'mycred_admin_init', array( $this, 'register_settings' ), $this->menu_pos );
241
-
242
- if ( $this->add_to_core === true ) {
243
- add_action( 'mycred_after_core_prefs', array( $this, 'after_general_settings' ) );
244
- add_filter( 'mycred_save_core_prefs', array( $this, 'sanitize_extra_settings' ), 90, 3 );
245
- }
246
-
247
- add_action( 'mycred_pre_init', array( $this, 'module_pre_init' ) );
248
- add_action( 'mycred_init', array( $this, 'module_init' ) );
249
- add_action( 'mycred_admin_init', array( $this, 'module_admin_init' ), $this->menu_pos+1 );
250
- add_action( 'mycred_widgets_init', array( $this, 'module_widgets_init' ) );
251
- add_action( 'mycred_admin_enqueue', array( $this, 'scripts_and_styles' ), $this->menu_pos );
252
-
253
- }
254
-
255
- /**
256
- * myCRED Ready
257
- * No longer available as of version 1.4
258
- * @since 1.1.1
259
- * @version 1.0
260
- */
261
- public function module_ready() { }
262
-
263
- /**
264
- * Plugins Loaded (pre init)
265
- * @since 0.1
266
- * @version 1.0
267
- */
268
- public function module_pre_init() { }
269
-
270
- /**
271
- * Init
272
- * @since 0.1
273
- * @version 1.0
274
- */
275
- public function module_init() { }
276
-
277
- /**
278
- * Admin Init
279
- * @since 0.1
280
- * @version 1.0
281
- */
282
- public function module_admin_init() { }
283
-
284
- /**
285
- * Widgets Init
286
- * @since 0.1
287
- * @version 1.0
288
- */
289
- public function module_widgets_init() { }
290
-
291
- /**
292
- * Get
293
- * @since 0.1
294
- * @version 1.0
295
- */
296
- public function get() { }
297
-
298
- /**
299
- * Call
300
- * Either runs a given class method or function.
301
- * Defaults to an empty array if class/function does not exist
302
- * @since 0.1
303
- * @version 1.0.3
304
- */
305
- public function call( $call, $callback, $return = NULL ) {
306
-
307
- // Class
308
- if ( is_array( $callback ) && class_exists( $callback[0] ) ) {
309
-
310
- $class = $callback[0];
311
- $methods = get_class_methods( $class );
312
- if ( in_array( $call, $methods ) ) {
313
- $new = new $class( $this );
314
- return $new->$call( $return );
315
- }
316
-
317
- }
318
-
319
- // Function
320
- elseif ( ! is_array( $callback ) ) {
321
-
322
- if ( function_exists( $callback ) ) {
323
-
324
- if ( $return !== NULL )
325
- return call_user_func( $callback, $return, $this );
326
- else
327
- return call_user_func( $callback, $this );
328
-
329
- }
330
-
331
- }
332
-
333
- if ( $return !== NULL )
334
- return array();
335
-
336
- }
337
-
338
- /**
339
- * If Installed
340
- * Checks if hooks have been installed
341
- *
342
- * @returns (bool) true or false
343
- * @since 0.1
344
- * @version 1.0
345
- */
346
- public function is_installed() {
347
-
348
- $module_name = $this->module_name;
349
- if ( $this->$module_name === false ) return false;
350
- return true;
351
-
352
- }
353
-
354
- /**
355
- * Is Active
356
- * @param $key (string) required key to check for
357
- * @returns (bool) true or false
358
- * @since 0.1
359
- * @version 1.1
360
- */
361
- public function is_active( $key = '' ) {
362
-
363
- $module = $this->module_name;
364
- $is_active = false;
365
-
366
- if ( ! isset( $this->active ) && ! empty( $key ) ) {
367
-
368
- if ( isset( $this->$module['active'] ) )
369
- $active = $this->$module['active'];
370
-
371
- if ( in_array( $key, $active ) )
372
- $is_active = true;
373
-
374
- }
375
-
376
- elseif ( isset( $this->active ) && ! empty( $key ) ) {
377
-
378
- if ( in_array( $key, $this->active ) )
379
- $is_active = true;
380
-
381
- }
382
-
383
- return apply_filters( 'mycred_module_is_active', $is_active, $module, $key, $this );
384
-
385
- }
386
-
387
- /**
388
- * Add Admin Menu Item
389
- * @since 0.1
390
- * @version 1.3
391
- */
392
- public function add_menu() {
393
-
394
- // In case we are using the Master Template feautre on multisites, and this is not the main
395
- // site in the network, bail.
396
- if ( $this->module_id != 'myCRED_Log_Module' && mycred_override_settings() && ! mycred_is_main_site() ) return;
397
-
398
- // Minimum requirements
399
- if ( ! empty( $this->labels ) && ! empty( $this->screen_id ) ) {
400
-
401
- // Menu Slug
402
- $menu_slug = ( ! $this->is_main_type ) ? MYCRED_SLUG . '_' . $this->mycred_type : MYCRED_SLUG;
403
- $label_menu = $label_title = 'Surprise';
404
-
405
- // Capability
406
- $capability = ( $this->cap == 'plugin' ) ? $this->core->get_point_admin_capability() : $this->core->get_point_editor_capability();
407
-
408
- // Menu Label
409
- if ( isset( $this->labels['menu'] ) )
410
- $label_menu = $this->labels['menu'];
411
-
412
- elseif ( isset( $this->labels['page_title'] ) )
413
- $label_menu = $this->labels['page_title'];
414
-
415
- // Page Title
416
- if ( isset( $this->labels['page_title'] ) )
417
- $label_title = $this->labels['page_title'];
418
-
419
- elseif ( isset( $this->labels['menu'] ) )
420
- $label_title = $this->labels['menu'];
421
-
422
- if ( $this->main_menu )
423
- $menu_slug = MYCRED_MAIN_SLUG;
424
-
425
- // Add Submenu Page
426
- $page = add_submenu_page(
427
- $menu_slug,
428
- $label_menu,
429
- $label_title,
430
- $capability,
431
- $this->screen_id,
432
- array( $this, 'admin_page' )
433
- );
434
-
435
- add_action( 'admin_print_styles-' . $page, array( $this, 'settings_page_enqueue' ) );
436
- add_action( 'load-' . $page, array( $this, 'screen_options' ) );
437
-
438
- }
439
-
440
- }
441
-
442
- /**
443
- * Register Scripts & Styles
444
- * @since 1.7
445
- * @version 1.0
446
- */
447
- public function scripts_and_styles() { }
448
-
449
- /**
450
- * Save Log Entries per page
451
- * @since 0.1
452
- * @version 1.0.1
453
- */
454
- public function set_entries_per_page() {
455
-
456
- if ( ! isset( $_REQUEST['wp_screen_options']['option'] ) || ! isset( $_REQUEST['wp_screen_options']['value'] ) ) return;
457
-
458
- $settings_key = 'mycred_epp_' . $_GET['page'];
459
-
460
- if ( $_REQUEST['wp_screen_options']['option'] == $settings_key ) {
461
- $value = absint( $_REQUEST['wp_screen_options']['value'] );
462
- mycred_update_user_meta( get_current_user_id(), $settings_key, '', $value );
463
- }
464
-
465
- }
466
-
467
- /**
468
- * Register Settings
469
- * @since 0.1
470
- * @version 1.1
471
- */
472
- public function register_settings() {
473
-
474
- if ( empty( $this->option_id ) || $this->register === false ) return;
475
-
476
- register_setting( $this->settings_name, $this->option_id, array( $this, 'sanitize_settings' ) );
477
-
478
- }
479
-
480
- /**
481
- * Screen Options
482
- * @since 1.4
483
- * @version 1.0
484
- */
485
- public function screen_options() {
486
-
487
- $this->set_entries_per_page();
488
-
489
- }
490
-
491
- /**
492
- * Add Metabox Class
493
- * @since 1.7
494
- * @version 1.0
495
- */
496
- public function metabox_classes( $classes ) {
497
-
498
- $classes[] = 'mycred-metabox';
499
-
500
- return $classes;
501
-
502
- }
503
-
504
- /**
505
- * Enqueue Scripts & Styles
506
- * Scripts and styles to enqueu on module admin pages.
507
- * @since 1.4
508
- * @version 1.0.1
509
- */
510
- public function settings_page_enqueue() {
511
-
512
- wp_dequeue_script( 'bpge_admin_js_acc' );
513
-
514
- // Load Accordion
515
- if ( $this->accordion ) {
516
-
517
- wp_enqueue_style( 'mycred-admin' );
518
- wp_enqueue_script( 'mycred-accordion' );
519
-
520
- ?>
521
  <!-- myCRED Accordion Styling -->
522
  <style type="text/css">
523
  h4:before { float:right; padding-right: 12px; font-size: 14px; font-weight: normal; color: silver; }
524
- h4.ui-accordion-header.ui-state-active:before { content: "<?php _e( 'click to close', 'mycred' ); ?>"; }
525
- h4.ui-accordion-header:before { content: "<?php _e( 'click to open', 'mycred' ); ?>"; }
526
  </style>
527
- <?php
528
-
529
- }
530
-
531
- $this->settings_header();
532
-
533
- }
534
-
535
- /**
536
- * Settings Header
537
- * Scripts and styles to insert after scripts are printed.
538
- * @since 0.1
539
- * @version 1.2
540
- */
541
- public function settings_header() { }
542
-
543
- /**
544
- * Admin Page
545
- * @since 0.1
546
- * @version 1.0
547
- */
548
- public function admin_page() { }
549
-
550
- /**
551
- * Update Notice
552
- * @since 1.4
553
- * @version 1.0
554
- */
555
- public function update_notice( $get = 'settings-updated', $class = 'updated', $message = '' ) {
556
-
557
- if ( empty( $message ) )
558
- $message = __( 'Settings Updated', 'mycred' );
559
-
560
- if ( isset( $_GET[ $get ] ) )
561
- echo '<div class="' . $class . '"><p>' . $message . '</p></div>';
562
-
563
- }
564
-
565
- /**
566
- * Sanitize Settings
567
- * @since 0.1
568
- * @version 1.0
569
- */
570
- public function sanitize_settings( $post ) {
571
-
572
- return $post;
573
-
574
- }
575
-
576
- /**
577
- * After General Settings
578
- * @since 0.1
579
- * @version 1.0
580
- */
581
- public function after_general_settings( $mycred = NULL ) { }
582
-
583
- /**
584
- * Sanitize Core Settings
585
- * @since 0.1
586
- * @version 1.0
587
- */
588
- public function sanitize_extra_settings( $new_data, $data, $core ) {
589
-
590
- return $new_data;
591
-
592
- }
593
-
594
- /**
595
- * Input Field Name Value
596
- * @since 0.1
597
- * @version 1.0
598
- */
599
- public function field_name( $name = '' ) {
600
-
601
- if ( is_array( $name ) ) {
602
-
603
- $array = array();
604
- foreach ( $name as $parent => $child ) {
605
-
606
- if ( ! is_numeric( $parent ) )
607
- $array[] = $parent;
608
-
609
- if ( ! empty( $child ) && ! is_array( $child ) )
610
- $array[] = $child;
611
-
612
- }
613
- $name = '[' . implode( '][', $array ) . ']';
614
-
615
- }
616
- else {
617
-
618
- $name = '[' . $name . ']';
619
-
620
- }
621
-
622
- if ( $this->add_to_core === true )
623
- $name = '[' . $this->module_name . ']' . $name;
624
-
625
- if ( $this->option_id != '' )
626
- return $this->option_id . $name;
627
-
628
- return 'mycred_pref_core' . $name;
629
-
630
- }
631
 
632
- /**
633
- * Input Field Id Value
634
- * @since 0.1
635
- * @version 1.0
636
- */
637
- public function field_id( $id = '' ) {
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
638
 
639
- if ( is_array( $id ) ) {
640
 
641
- $array = array();
642
- foreach ( $id as $parent => $child ) {
643
 
644
- if ( ! is_numeric( $parent ) )
645
- $array[] = str_replace( '_', '-', $parent );
 
646
 
647
- if ( ! empty( $child ) && ! is_array( $child ) )
648
- $array[] = str_replace( '_', '-', $child );
 
649
 
650
- }
651
- $id = implode( '-', $array );
652
 
653
- }
654
- else {
655
 
656
- $id = str_replace( '_', '-', $id );
657
 
658
- }
659
 
660
- if ( $this->add_to_core === true )
661
- $id = 'prefs' . $id;
 
662
 
663
- $id = strtolower( $this->module_name ) . $id;
664
- $id = strtolower( $id );
665
- $id = str_replace( array( '[', ']' ), '', $id );
666
- $id = str_replace( array( '_', '-' ), '', $id );
667
 
668
- return $id;
669
 
670
- }
671
 
672
- /**
673
- * Available Template Tags
674
- * @since 1.4
675
- * @version 1.0
676
- */
677
- public function available_template_tags( $available = array() ) {
 
 
678
 
679
- return $this->core->available_template_tags( $available );
680
 
681
- }
682
 
683
- /**
684
- * Get Settings URL
685
- * @since 1.4
686
- * @version 1.0.1
687
- */
688
- public function get_settings_url( $module = '' ) {
 
 
689
 
690
- $variables = array( 'page' => MYCRED_SLUG . '-settings' );
691
- if ( ! empty( $module ) )
692
- $variables['open-tab'] = $module;
 
693
 
694
- $url = add_query_arg( $variables, admin_url( 'admin.php' ) );
695
 
696
- return esc_url( $url );
697
 
698
- }
699
 
700
- /**
701
- * Request to Entry
702
- * @since 1.6
703
- * @version 1.0
704
- */
705
- public function request_to_entry( $request = array() ) {
 
 
706
 
707
- if ( empty( $request ) ) return false;
 
708
 
709
- $entry = new stdClass();
710
 
711
- $entry->id = -1;
712
- $entry->ref = $request['ref'];
713
- $entry->ref_id = $request['ref_id'];
714
- $entry->user_id = $request['user_id'];
715
- $entry->time = $this->now;
716
- $entry->entry = $request['entry'];
717
- $entry->data = $request['data'];
718
- $entry->ctype = $request['type'];
719
 
720
- return $entry;
721
 
722
- }
723
 
724
- }
725
  endif;
1
  <?php
2
+ if (! defined('myCRED_VERSION') ) { exit;
3
+ }
4
 
5
  /**
6
  * myCRED_Module class
7
+ *
8
+ * @see http://codex.mycred.me/classes/mycred_module/
9
+ * @since 0.1
10
  * @version 1.3.5
11
  */
12
+ if (! class_exists('myCRED_Module') ) :
13
+ abstract class myCRED_Module
14
+ {
15
 
16
+ // Module ID (unique)
17
+ public $module_id;
18
 
19
+ // Core settings & functions
20
+ public $core;
21
 
22
+ // Module name (string)
23
+ public $module_name;
24
 
25
+ // Option ID (string|array)
26
+ public $option_id;
27
 
28
+ // Labels (array)
29
+ public $labels;
30
 
31
+ // Register (bool)
32
+ public $register;
33
 
34
+ // Screen ID (string)
35
+ public $screen_id;
36
 
37
+ // Menu Position (int)
38
+ public $menu_pos;
39
 
40
+ // Default preferences
41
+ public $default_prefs = array();
42
 
43
+ // Is Main Cred Type
44
+ public $is_main_type = true;
45
 
46
+ // myCRED Type used
47
+ public $mycred_type;
48
 
49
+ // All registered point types
50
+ public $point_types;
51
 
52
+ // Current users ID
53
+ public $current_user_id;
54
 
55
+ // Current time
56
+ public $now;
57
 
58
+ // Pages
59
+ public $pages = array();
60
 
61
+ // Submenu Inside Main menu
62
+ public $main_menu;
63
 
64
+ /**
65
+ * Construct
66
+ */
67
+ public function __construct( $module_id = '', $args = array(), $type = MYCRED_DEFAULT_TYPE_KEY )
68
+ {
69
 
70
+ // Module ID is required
71
+ if (empty($module_id) ) { wp_die('myCRED_Module() Error. A Module ID is required!');
72
+ }
73
 
74
+ $this->module_id = $module_id;
75
+ $this->core = mycred($type);
76
 
77
+ if (! empty($type) ) {
78
+ $this->core->cred_id = sanitize_text_field($type);
79
+ $this->mycred_type = $this->core->cred_id;
80
+ }
81
 
82
+ if ($this->mycred_type != MYCRED_DEFAULT_TYPE_KEY ) {
83
+ $this->is_main_type = false;
84
+ }
85
 
86
+ $this->point_types = mycred_get_types();
87
 
88
+ // Default arguments
89
+ $defaults = array(
90
+ 'module_name' => '',
91
+ 'option_id' => '',
92
+ 'defaults' => array(),
93
+ 'labels' => array(
94
+ 'menu' => '',
95
+ 'page_title' => ''
96
+ ),
97
+ 'register' => true,
98
+ 'screen_id' => '',
99
+ 'add_to_core' => false,
100
+ 'accordion' => false,
101
+ 'cap' => 'plugin',
102
+ 'menu_pos' => 10,
103
+ 'main_menu' => false
104
+ );
105
+ $args = wp_parse_args($args, $defaults);
106
 
107
+ $this->module_name = $args['module_name'];
108
+ $this->option_id = $args['option_id'];
109
 
110
+ if (! $this->is_main_type ) {
111
+ $this->option_id .= '_' . $this->mycred_type;
112
+ }
113
 
114
+ $this->settings_name = 'myCRED-' . $this->module_name;
115
+ if (! $this->is_main_type ) {
116
+ $this->settings_name .= '-' . $this->mycred_type;
117
+ }
118
 
119
+ $this->labels = $args['labels'];
120
+ $this->register = $args['register'];
121
+ $this->screen_id = $args['screen_id'];
122
 
123
+ if (! $this->is_main_type && ! empty($this->screen_id) ) {
124
+ $this->screen_id = 'mycred_' . $this->mycred_type . substr($this->screen_id, 6);
125
+ }
126
 
127
+ $this->add_to_core = $args['add_to_core'];
128
+ $this->accordion = $args['accordion'];
129
+ $this->cap = $args['cap'];
130
+ $this->menu_pos = $args['menu_pos'];
131
 
132
+ $this->default_prefs = $args['defaults'];
133
+ $this->now = current_time('timestamp');
134
+ $this->main_menu = $args['main_menu'];
135
 
136
+ $this->set_settings();
137
 
138
+ }
139
 
140
+ /**
141
+ * Set Settings
142
+ *
143
+ * @since 0.1
144
+ * @version 1.2.1
145
+ */
146
+ public function set_settings()
147
+ {
148
 
149
+ $module = $this->module_name;
150
 
151
+ // Reqest not to register any settings
152
+ if ($this->register === false ) {
153
 
154
+ // If settings does not exist apply defaults
155
+ if (! isset($this->core->$module) ) {
156
+ $this->$module = $this->default_prefs;
157
+ }
158
 
159
+ // Else append settings
160
+ else {
161
+ $this->$module = $this->core->$module;
162
+ }
163
 
164
+ // Apply defaults in case new settings have been applied
165
+ if (! empty($this->default_prefs) ) {
166
+ $this->$module = wp_parse_args($this->$module, $this->default_prefs);
167
+ }
168
 
169
+ }
170
 
171
+ // Request to register settings
172
+ else {
173
 
174
+ // Option IDs must be provided
175
+ if (! empty($this->option_id) ) {
176
 
177
+ // Array = more then one
178
+ if (is_array($this->option_id) ) {
179
 
180
+ // General settings needs not to be loaded
181
+ $pattern = 'mycred_pref_core';
182
+ //$matches = array_filter( $this->option_id, function( $a ) use ( $pattern ) { return preg_grep( $a, $pattern ); } );
183
+ //if ( ! empty( $matches ) )
184
+ $this->$module = $this->core;
185
+
186
+ // Loop and grab
187
+ foreach ( $this->option_id as $option_id => $option_name ) {
188
+
189
+ $settings = mycred_get_option($option_name, false);
190
+
191
+ if ($settings === false && array_key_exists($option_id, $defaults) ) {
192
+ $this->$module[ $option_name ] = $this->default_prefs[ $option_id ];
193
+ } else {
194
+ $this->$module[ $option_name ] = $settings;
195
+ }
196
+
197
+ // Apply defaults in case new settings have been applied
198
+ if (array_key_exists($option_id, $this->default_prefs) ) {
199
+ $this->$module[ $option_name ] = wp_parse_args($this->$module[ $option_name ], $this->default_prefs[ $option_id ]);
200
+ }
201
+
202
+ }
203
+
204
+ }
205
+
206
+ // String = one
207
+ else {
208
+
209
+ // General settings needs not to be loaded
210
+ if (str_replace('mycred_pref_core', '', $this->option_id) == '' ) {
211
+ $this->$module = $this->core;
212
+ }
213
+
214
+ // Grab the requested option
215
+ else {
216
+
217
+ $this->$module = mycred_get_option($this->option_id, false);
218
+
219
+ if ($this->$module === false && ! empty($this->default_prefs) ) {
220
+ $this->$module = $this->default_prefs;
221
+ }
222
+
223
+ // Apply defaults in case new settings have been applied
224
+ if (! empty($this->default_prefs) ) {
225
+ $this->$module = wp_parse_args($this->$module, $this->default_prefs);
226
+ }
227
+
228
+ }
229
+
230
+ }
231
+
232
+ if (is_array($this->$module) ) {
233
+
234
+ foreach ( $this->$module as $key => $value ) {
235
+ $this->$key = $value;
236
+ }
237
+
238
+ }
239
+
240
+ }
241
+
242
+ }
243
+
244
+ }
245
+
246
+ /**
247
+ * Load
248
+ *
249
+ * @since 0.1
250
+ * @version 1.0.1
251
+ */
252
+ public function load()
253
+ {
254
+
255
+ if (! empty($this->screen_id) && ! empty($this->labels['menu']) ) {
256
+ add_action('mycred_add_menu', array( $this, 'add_menu' ), $this->menu_pos);
257
+ add_action('admin_init', array( $this, 'set_entries_per_page' ));
258
+ }
259
+
260
+ if ($this->register === true && ! empty($this->option_id) ) {
261
+ add_action('mycred_admin_init', array( $this, 'register_settings' ), $this->menu_pos);
262
+ }
263
+
264
+ if ($this->add_to_core === true ) {
265
+ add_action('mycred_after_core_prefs', array( $this, 'after_general_settings' ));
266
+ add_filter('mycred_save_core_prefs', array( $this, 'sanitize_extra_settings' ), 90, 3);
267
+ }
268
+
269
+ add_action('mycred_pre_init', array( $this, 'module_pre_init' ));
270
+ add_action('mycred_init', array( $this, 'module_init' ));
271
+ add_action('mycred_admin_init', array( $this, 'module_admin_init' ), $this->menu_pos+1);
272
+ add_action('mycred_widgets_init', array( $this, 'module_widgets_init' ));
273
+ add_action('mycred_admin_enqueue', array( $this, 'scripts_and_styles' ), $this->menu_pos);
274
+
275
+ }
276
+
277
+ /**
278
+ * myCRED Ready
279
+ * No longer available as of version 1.4
280
+ *
281
+ * @since 1.1.1
282
+ * @version 1.0
283
+ */
284
+ public function module_ready()
285
+ {
286
+ }
287
+
288
+ /**
289
+ * Plugins Loaded (pre init)
290
+ *
291
+ * @since 0.1
292
+ * @version 1.0
293
+ */
294
+ public function module_pre_init()
295
+ {
296
+ }
297
+
298
+ /**
299
+ * Init
300
+ *
301
+ * @since 0.1
302
+ * @version 1.0
303
+ */
304
+ public function module_init()
305
+ {
306
+ }
307
+
308
+ /**
309
+ * Admin Init
310
+ *
311
+ * @since 0.1
312
+ * @version 1.0
313
+ */
314
+ public function module_admin_init()
315
+ {
316
+ }
317
+
318
+ /**
319
+ * Widgets Init
320
+ *
321
+ * @since 0.1
322
+ * @version 1.0
323
+ */
324
+ public function module_widgets_init()
325
+ {
326
+ }
327
+
328
+ /**
329
+ * Get
330
+ *
331
+ * @since 0.1
332
+ * @version 1.0
333
+ */
334
+ public function get()
335
+ {
336
+ }
337
+
338
+ /**
339
+ * Call
340
+ * Either runs a given class method or function.
341
+ * Defaults to an empty array if class/function does not exist
342
+ *
343
+ * @since 0.1
344
+ * @version 1.0.3
345
+ */
346
+ public function call( $call, $callback, $return = null )
347
+ {
348
+
349
+ // Class
350
+ if (is_array($callback) && class_exists($callback[0]) ) {
351
+
352
+ $class = $callback[0];
353
+ $methods = get_class_methods($class);
354
+ if (in_array($call, $methods) ) {
355
+ $new = new $class($this);
356
+ return $new->$call($return);
357
+ }
358
+
359
+ }
360
+
361
+ // Function
362
+ elseif (! is_array($callback) ) {
363
+
364
+ if (function_exists($callback) ) {
365
+
366
+ if ($return !== null ) {
367
+ return call_user_func($callback, $return, $this);
368
+ } else {
369
+ return call_user_func($callback, $this);
370
+ }
371
+
372
+ }
373
+
374
+ }
375
+
376
+ if ($return !== null ) {
377
+ return array();
378
+ }
379
+
380
+ }
381
+
382
+ /**
383
+ * If Installed
384
+ * Checks if hooks have been installed
385
+ *
386
+ * @returns (bool) true or false
387
+ * @since 0.1
388
+ * @version 1.0
389
+ */
390
+ public function is_installed()
391
+ {
392
+
393
+ $module_name = $this->module_name;
394
+ if ($this->$module_name === false ) { return false;
395
+ }
396
+ return true;
397
+
398
+ }
399
+
400
+ /**
401
+ * Is Active
402
+ *
403
+ * @param $key (string) required key to check for
404
+ * @returns (bool) true or false
405
+ * @since 0.1
406
+ * @version 1.1
407
+ */
408
+ public function is_active( $key = '' )
409
+ {
410
+
411
+ $module = $this->module_name;
412
+ $is_active = false;
413
+
414
+ if (! isset($this->active) && ! empty($key) ) {
415
+
416
+ if (isset($this->$module['active']) ) {
417
+ $active = $this->$module['active'];
418
+ }
419
+
420
+ if (in_array($key, $active) ) {
421
+ $is_active = true;
422
+ }
423
+
424
+ }
425
+
426
+ elseif (isset($this->active) && ! empty($key) ) {
427
+
428
+ if (in_array($key, $this->active) ) {
429
+ $is_active = true;
430
+ }
431
+
432
+ }
433
+
434
+ return apply_filters('mycred_module_is_active', $is_active, $module, $key, $this);
435
+
436
+ }
437
+
438
+ /**
439
+ * Add Admin Menu Item
440
+ *
441
+ * @since 0.1
442
+ * @version 1.3
443
+ */
444
+ public function add_menu()
445
+ {
446
+
447
+ // In case we are using the Master Template feautre on multisites, and this is not the main
448
+ // site in the network, bail.
449
+ if ($this->module_id != 'myCRED_Log_Module' && mycred_override_settings() && ! mycred_is_main_site() ) { return;
450
+ }
451
+
452
+ // Minimum requirements
453
+ if (! empty($this->labels) && ! empty($this->screen_id) ) {
454
+
455
+ // Menu Slug
456
+ $menu_slug = ( ! $this->is_main_type ) ? MYCRED_SLUG . '_' . $this->mycred_type : MYCRED_SLUG;
457
+ $label_menu = $label_title = 'Surprise';
458
 
459
+ // Capability
460
+ $capability = ( $this->cap == 'plugin' ) ? $this->core->get_point_admin_capability() : $this->core->get_point_editor_capability();
461
+
462
+ // Menu Label
463
+ if (isset($this->labels['menu']) ) {
464
+ $label_menu = $this->labels['menu'];
465
+
466
+ } elseif (isset($this->labels['page_title']) ) {
467
+ $label_menu = $this->labels['page_title'];
468
+ }
469
+
470
+ // Page Title
471
+ if (isset($this->labels['page_title']) ) {
472
+ $label_title = $this->labels['page_title'];
473
+
474
+ } elseif (isset($this->labels['menu']) ) {
475
+ $label_title = $this->labels['menu'];
476
+ }
477
+
478
+ if ($this->main_menu ) {
479
+ $menu_slug = MYCRED_MAIN_SLUG;
480
+ }
481
+
482
+ // Add Submenu Page
483
+ $page = add_submenu_page(
484
+ $menu_slug,
485
+ $label_menu,
486
+ $label_title,
487
+ $capability,
488
+ $this->screen_id,
489
+ array( $this, 'admin_page' )
490
+ );
491
+
492
+ add_action('admin_print_styles-' . $page, array( $this, 'settings_page_enqueue' ));
493
+ add_action('load-' . $page, array( $this, 'screen_options' ));
494
+
495
+ }
496
+
497
+ }
498
+
499
+ /**
500
+ * Register Scripts & Styles
501
+ *
502
+ * @since 1.7
503
+ * @version 1.0
504
+ */
505
+ public function scripts_and_styles()
506
+ {
507
+ }
508
 
509
+ /**
510
+ * Save Log Entries per page
511
+ *
512
+ * @since 0.1
513
+ * @version 1.0.1
514
+ */
515
+ public function set_entries_per_page()
516
+ {
517
+
518
+ if (! isset($_REQUEST['wp_screen_options']['option']) || ! isset($_REQUEST['wp_screen_options']['value']) ) { return;
519
+ }
520
+
521
+ $settings_key = 'mycred_epp_' . $_GET['page'];
522
 
523
+ if ($_REQUEST['wp_screen_options']['option'] == $settings_key ) {
524
+ $value = absint($_REQUEST['wp_screen_options']['value']);
525
+ mycred_update_user_meta(get_current_user_id(), $settings_key, '', $value);
526
+ }
527
+
528
+ }
529
+
530
+ /**
531
+ * Register Settings
532
+ *
533
+ * @since 0.1
534
+ * @version 1.1
535
+ */
536
+ public function register_settings()
537
+ {
538
+
539
+ if (empty($this->option_id) || $this->register === false ) { return;
540
+ }
541
+
542
+ register_setting($this->settings_name, $this->option_id, array( $this, 'sanitize_settings' ));
543
+
544
+ }
545
+
546
+ /**
547
+ * Screen Options
548
+ *
549
+ * @since 1.4
550
+ * @version 1.0
551
+ */
552
+ public function screen_options()
553
+ {
554
+
555
+ $this->set_entries_per_page();
556
+
557
+ }
558
+
559
+ /**
560
+ * Add Metabox Class
561
+ *
562
+ * @since 1.7
563
+ * @version 1.0
564
+ */
565
+ public function metabox_classes( $classes )
566
+ {
567
+
568
+ $classes[] = 'mycred-metabox';
569
+
570
+ return $classes;
571
+
572
+ }
573
+
574
+ /**
575
+ * Enqueue Scripts & Styles
576
+ * Scripts and styles to enqueu on module admin pages.
577
+ *
578
+ * @since 1.4
579
+ * @version 1.0.1
580
+ */
581
+ public function settings_page_enqueue()
582
+ {
583
+
584
+ wp_dequeue_script('bpge_admin_js_acc');
585
+
586
+ // Load Accordion
587
+ if ($this->accordion ) {
588
+
589
+ wp_enqueue_style('mycred-admin');
590
+ wp_enqueue_script('mycred-accordion');
591
 
592
+ ?>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
593
  <!-- myCRED Accordion Styling -->
594
  <style type="text/css">
595
  h4:before { float:right; padding-right: 12px; font-size: 14px; font-weight: normal; color: silver; }
596
+ h4.ui-accordion-header.ui-state-active:before { content: "<?php _e('click to close', 'mycred'); ?>"; }
597
+ h4.ui-accordion-header:before { content: "<?php _e('click to open', 'mycred'); ?>"; }
598
  </style>
599
+ <?php
600
+
601
+ }
602
+
603
+ $this->settings_header();
604
+
605
+ }
606
+
607
+ /**
608
+ * Settings Header
609
+ * Scripts and styles to insert after scripts are printed.
610
+ *
611
+ * @since 0.1
612
+ * @version 1.2
613
+ */
614
+ public function settings_header()
615
+ {
616
+ }
617
+
618
+ /**
619
+ * Admin Page
620
+ *
621
+ * @since 0.1
622
+ * @version 1.0
623
+ */
624
+ public function admin_page()
625
+ {
626
+ }
627
+
628
+ /**
629
+ * Update Notice
630
+ *
631
+ * @since 1.4
632
+ * @version 1.0
633
+ */
634
+ public function update_notice( $get = 'settings-updated', $class = 'updated', $message = '' )
635
+ {
636
+
637
+ if (empty($message) ) {
638
+ $message = __('Settings Updated', 'mycred');
639
+ }
640
+
641
+ if (isset($_GET[ $get ]) ) {
642
+ echo '<div class="' . $class . '"><p>' . $message . '</p></div>';
643
+ }
644
+
645
+ }
646
+
647
+ /**
648
+ * Sanitize Settings
649
+ *
650
+ * @since 0.1
651
+ * @version 1.0
652
+ */
653
+ public function sanitize_settings( $post )
654
+ {
655
+
656
+ return $post;
657
+
658
+ }
659
+
660
+ /**
661
+ * After General Settings
662
+ *
663
+ * @since 0.1
664
+ * @version 1.0
665
+ */
666
+ public function after_general_settings( $mycred = null )
667
+ {
668
+ }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
669
 
670
+ /**
671
+ * Sanitize Core Settings
672
+ *
673
+ * @since 0.1
674
+ * @version 1.0
675
+ */
676
+ public function sanitize_extra_settings( $new_data, $data, $core )
677
+ {
678
+
679
+ return $new_data;
680
+
681
+ }
682
+
683
+ /**
684
+ * Input Field Name Value
685
+ *
686
+ * @since 0.1
687
+ * @version 1.0
688
+ */
689
+ public function field_name( $name = '' )
690
+ {
691
+
692
+ if (is_array($name) ) {
693
+
694
+ $array = array();
695
+ foreach ( $name as $parent => $child ) {
696
+
697
+ if (! is_numeric($parent) ) {
698
+ $array[] = $parent;
699
+ }
700
+
701
+ if (! empty($child) && ! is_array($child) ) {
702
+ $array[] = $child;
703
+ }
704
+
705
+ }
706
+ $name = '[' . implode('][', $array) . ']';
707
+
708
+ }
709
+ else {
710
+
711
+ $name = '[' . $name . ']';
712
+
713
+ }
714
+
715
+ if ($this->add_to_core === true ) {
716
+ $name = '[' . $this->module_name . ']' . $name;
717
+ }
718
+
719
+ if ($this->option_id != '' ) {
720
+ return $this->option_id . $name;
721
+ }
722
+
723
+ return 'mycred_pref_core' . $name;
724
+
725
+ }
726
+
727
+ /**
728
+ * Input Field Id Value
729
+ *
730
+ * @since 0.1
731
+ * @version 1.0
732
+ */
733
+ public function field_id( $id = '' )
734
+ {
735
 
736
+ if (is_array($id) ) {
737
 
738
+ $array = array();
739
+ foreach ( $id as $parent => $child ) {
740
 
741
+ if (! is_numeric($parent) ) {
742
+ $array[] = str_replace('_', '-', $parent);
743
+ }
744
 
745
+ if (! empty($child) && ! is_array($child) ) {
746
+ $array[] = str_replace('_', '-', $child);
747
+ }
748
 
749
+ }
750
+ $id = implode('-', $array);
751
 
752
+ }
753
+ else {
754
 
755
+ $id = str_replace('_', '-', $id);
756
 
757
+ }
758
 
759
+ if ($this->add_to_core === true ) {
760
+ $id = 'prefs' . $id;
761
+ }
762
 
763
+ $id = strtolower($this->module_name) . $id;
764
+ $id = strtolower($id);
765
+ $id = str_replace(array( '[', ']' ), '', $id);
766
+ $id = str_replace(array( '_', '-' ), '', $id);
767
 
768
+ return $id;
769
 
770
+ }
771
 
772
+ /**
773
+ * Available Template Tags
774
+ *
775
+ * @since 1.4
776
+ * @version 1.0
777
+ */
778
+ public function available_template_tags( $available = array() )
779
+ {
780
 
781
+ return $this->core->available_template_tags($available);
782
 
783
+ }
784
 
785
+ /**
786
+ * Get Settings URL
787
+ *
788
+ * @since 1.4
789
+ * @version 1.0.1
790
+ */
791
+ public function get_settings_url( $module = '' )
792
+ {
793
 
794
+ $variables = array( 'page' => MYCRED_SLUG . '-settings' );
795
+ if (! empty($module) ) {
796
+ $variables['open-tab'] = $module;
797
+ }
798
 
799
+ $url = add_query_arg($variables, admin_url('admin.php'));
800
 
801
+ return esc_url($url);
802
 
803
+ }
804
 
805
+ /**
806
+ * Request to Entry
807
+ *
808
+ * @since 1.6
809
+ * @version 1.0
810
+ */
811
+ public function request_to_entry( $request = array() )
812
+ {
813
 
814
+ if (empty($request) ) { return false;
815
+ }
816
 
817
+ $entry = new stdClass();
818
 
819
+ $entry->id = -1;
820
+ $entry->ref = $request['ref'];
821
+ $entry->ref_id = $request['ref_id'];
822
+ $entry->user_id = $request['user_id'];
823
+ $entry->time = $this->now;
824
+ $entry->entry = $request['entry'];
825
+ $entry->data = $request['data'];
826
+ $entry->ctype = $request['type'];
827
 
828
+ return $entry;
829
 
830
+ }
831
 
832
+ }
833
  endif;
abstracts/mycred-abstract-object.php CHANGED
@@ -1,103 +1,117 @@
1
  <?php
2
- if ( ! defined( 'myCRED_VERSION' ) ) exit;
 
3
 
4
  /**
5
  * myCRED_Object class
6
- * @see http://codex.mycred.me/classes/mycred_object/
7
- * @since 1.7
 
8
  * @version 1.1
9
  */
10
- if ( ! class_exists( 'myCRED_Object' ) ) :
11
- abstract class myCRED_Object {
 
12
 
13
- /**
14
- * Construct
15
- */
16
- function __construct() { }
 
 
17
 
18
- /**
19
- * Get
20
- */
21
- public function get( $name = '', $nothing = false ) {
 
22
 
23
- if ( $name == '' ) return $nothing;
 
24
 
25
- $value = $nothing;
26
- if ( is_array( $name ) && ! empty( $name ) ) {
27
 
28
- foreach ( $name as $key => $array_value ) {
29
 
30
- // Example 1: array( 'balance' => 'mycred_default' )
31
- // $this->balance['mycred_default']
32
- if ( isset( $this->$key ) ) {
33
 
34
- if ( $array_value != '' && is_array( $this->$key ) && ! empty( $this->$key ) && array_key_exists( $array_value, $this->$key ) )
35
- $value = $this->$key[ $array_value ];
 
36
 
37
- }
38
 
39
- // Example 2: array( 'total' )
40
- // $this->total
41
- elseif ( isset( $this->$array_value ) )
42
- $value = $this->$array_value;
 
43
 
44
- }
45
 
46
- }
47
- elseif ( ! is_array( $name ) && ! empty( $name ) ) {
48
 
49
- if ( isset( $this->$name ) )
50
- $value = $this->$name;
 
51
 
52
- }
53
 
54
- return $value;
55
 
56
- }
57
 
58
- /**
59
- * Set
60
- */
61
- public function set( $name = '', $new_value = false ) {
 
62
 
63
- if ( $name == '' ) return false;
 
64
 
65
- if ( is_array( $name ) && ! empty( $name ) ) {
66
 
67
- foreach ( $name as $key => $array_value ) {
68
 
69
- // Example 1: array( 'balance' => 'mycred_default' )
70
- // $this->balance['mycred_default']
71
- if ( isset( $this->$key ) ) {
72
 
73
- if ( $array_value != '' ) {
74
 
75
- if ( ! is_array( $this->$key ) )
76
- $this->$key = array();
77
-
78
- $this->$key[ $array_value ] = $new_value;
 
79
 
80
- }
81
 
82
- }
83
 
84
- // Example 2: array( 'total' )
85
- // $this->total
86
- elseif ( isset( $this->$array_value ) )
87
- $this->$value = $new_value;
 
88
 
89
- }
90
 
91
- }
92
- elseif ( ! is_array( $name ) && ! empty( $name ) && isset( $this->$name ) ) {
93
 
94
- $this->$name = $new_value;
95
 
96
- }
97
 
98
- return true;
99
 
100
- }
101
 
102
- }
103
  endif;
1
  <?php
2
+ if (! defined('myCRED_VERSION') ) { exit;
3
+ }
4
 
5
  /**
6
  * myCRED_Object class
7
+ *
8
+ * @see http://codex.mycred.me/classes/mycred_object/
9
+ * @since 1.7
10
  * @version 1.1
11
  */
12
+ if (! class_exists('myCRED_Object') ) :
13
+ abstract class myCRED_Object
14
+ {
15
 
16
+ /**
17
+ * Construct
18
+ */
19
+ function __construct()
20
+ {
21
+ }
22
 
23
+ /**
24
+ * Get
25
+ */
26
+ public function get( $name = '', $nothing = false )
27
+ {
28
 
29
+ if ($name == '' ) { return $nothing;
30
+ }
31
 
32
+ $value = $nothing;
33
+ if (is_array($name) && ! empty($name) ) {
34
 
35
+ foreach ( $name as $key => $array_value ) {
36
 
37
+ // Example 1: array( 'balance' => 'mycred_default' )
38
+ // $this->balance['mycred_default']
39
+ if (isset($this->$key) ) {
40
 
41
+ if ($array_value != '' && is_array($this->$key) && ! empty($this->$key) && array_key_exists($array_value, $this->$key) ) {
42
+ $value = $this->$key[ $array_value ];
43
+ }
44
 
45
+ }
46
 
47
+ // Example 2: array( 'total' )
48
+ // $this->total
49
+ elseif (isset($this->$array_value) ) {
50
+ $value = $this->$array_value;
51
+ }
52
 
53
+ }
54
 
55
+ }
56
+ elseif (! is_array($name) && ! empty($name) ) {
57
 
58
+ if (isset($this->$name) ) {
59
+ $value = $this->$name;
60
+ }
61
 
62
+ }
63
 
64
+ return $value;
65
 
66
+ }
67
 
68
+ /**
69
+ * Set
70
+ */
71
+ public function set( $name = '', $new_value = false )
72
+ {
73
 
74
+ if ($name == '' ) { return false;
75
+ }
76
 
77
+ if (is_array($name) && ! empty($name) ) {
78
 
79
+ foreach ( $name as $key => $array_value ) {
80
 
81
+ // Example 1: array( 'balance' => 'mycred_default' )
82
+ // $this->balance['mycred_default']
83
+ if (isset($this->$key) ) {
84
 
85
+ if ($array_value != '' ) {
86
 
87
+ if (! is_array($this->$key) ) {
88
+ $this->$key = array();
89
+ }
90
+
91
+ $this->$key[ $array_value ] = $new_value;
92
 
93
+ }
94
 
95
+ }
96
 
97
+ // Example 2: array( 'total' )
98
+ // $this->total
99
+ elseif (isset($this->$array_value) ) {
100
+ $this->$value = $new_value;
101
+ }
102
 
103
+ }
104
 
105
+ }
106
+ elseif (! is_array($name) && ! empty($name) && isset($this->$name) ) {
107
 
108
+ $this->$name = $new_value;
109
 
110
+ }
111
 
112
+ return true;
113
 
114
+ }
115
 
116
+ }
117
  endif;
addons/badges/assets/css/front.css CHANGED
@@ -1,7 +1,7 @@
1
  .the-badge {
2
  display: flex;
3
  align-items: center;
4
- justify-content: space-between;
5
  }
6
 
7
  hr.badge-line {
1
  .the-badge {
2
  display: flex;
3
  align-items: center;
4
+ justify-content: space-between;
5
  }
6
 
7
  hr.badge-line {
addons/badges/assets/css/index.php CHANGED
@@ -1,3 +1,3 @@
1
  <?php
2
  // Silence is golden.
3
- ?>
1
  <?php
2
  // Silence is golden.
3
+ ?>
addons/badges/assets/index.php CHANGED
@@ -1,3 +1,3 @@
1
  <?php
2
  // Silence is golden.
3
- ?>
1
  <?php
2
  // Silence is golden.
3
+ ?>
addons/badges/assets/js/front.js CHANGED
@@ -1,33 +1,45 @@
1
- jQuery(document).ready(function(){
 
2
 
3
- //Badges Search Filter
4
- jQuery("#mycerd-badges-search").on("keyup", function() {
5
- var value = jQuery(this).val().toLowerCase();
6
- jQuery(".mycred-badges-list .mycred-badges-list-item").filter(function() {
7
- jQuery(this).toggle(jQuery(this).text().toLowerCase().indexOf(value) > -1)
8
- });
9
- });
 
 
 
 
10
 
11
- //Show Achieved Badges
12
- jQuery(document).on( 'click', '.mycred-achieved-badge-btn', function(e){
13
- e.preventDefault();
14
- jQuery('.not-earned').hide();
15
- jQuery('.earned').show();
16
- });
 
 
17
 
18
- //Show Not Achieved Badges
19
- jQuery(document).on( 'click', '.mycred-not-achieved-badge-btn', function(e){
20
- e.preventDefault();
21
- jQuery('.earned').hide();
22
- jQuery('.not-earned').show();
23
- });
 
 
24
 
25
- //Clear Filter Button
26
- jQuery(document).on( 'click', '.mycred-clear-filter-btn', function(e){
27
- e.preventDefault()
28
- jQuery('.earned').show();
29
- jQuery('.not-earned').show();
30
- jQuery('#mycerd-badges-search').val('');
31
- } )
32
- });
 
 
 
33
 
1
+ jQuery(document).ready(
2
+ function () {
3
 
4
+ //Badges Search Filter
5
+ jQuery("#mycerd-badges-search").on(
6
+ "keyup", function () {
7
+ var value = jQuery(this).val().toLowerCase();
8
+ jQuery(".mycred-badges-list .mycred-badges-list-item").filter(
9
+ function () {
10
+ jQuery(this).toggle(jQuery(this).text().toLowerCase().indexOf(value) > -1)
11
+ }
12
+ );
13
+ }
14
+ );
15
 
16
+ //Show Achieved Badges
17
+ jQuery(document).on(
18
+ 'click', '.mycred-achieved-badge-btn', function (e) {
19
+ e.preventDefault();
20
+ jQuery('.not-earned').hide();
21
+ jQuery('.earned').show();
22
+ }
23
+ );
24
 
25
+ //Show Not Achieved Badges
26
+ jQuery(document).on(
27
+ 'click', '.mycred-not-achieved-badge-btn', function (e) {
28
+ e.preventDefault();
29
+ jQuery('.earned').hide();
30
+ jQuery('.not-earned').show();
31
+ }
32
+ );
33
 
34
+ //Clear Filter Button
35
+ jQuery(document).on(
36
+ 'click', '.mycred-clear-filter-btn', function (e) {
37
+ e.preventDefault()
38
+ jQuery('.earned').show();
39
+ jQuery('.not-earned').show();
40
+ jQuery('#mycerd-badges-search').val('');
41
+ }
42
+ )
43
+ }
44
+ );
45
 
addons/badges/assets/js/index.php CHANGED
@@ -1,3 +1,3 @@
1
  <?php
2
  // Silence is golden.
3
- ?>
1
  <?php
2
  // Silence is golden.
3
+ ?>
addons/badges/includes/index.php CHANGED
@@ -1,3 +1,3 @@
1
  <?php
2
  // Silence is golden.
3
- ?>
1
  <?php
2
  // Silence is golden.
3
+ ?>
addons/badges/includes/mycred-badge-functions.php CHANGED
@@ -1,721 +1,818 @@
1
  <?php
2
- if ( ! defined( 'myCRED_VERSION' ) ) exit;
 
3
 
4
  /**
5
  * Get Badge
6
- * @since 1.7
 
7
  * @version 1.1
8
  */
9
- if ( ! function_exists( 'mycred_get_badge' ) ) :
10
- function mycred_get_badge( $badge_id = NULL, $level = NULL ) {
 
11
 
12
- if ( absint( $badge_id ) === 0 || mycred_get_post_type( $badge_id ) != MYCRED_BADGE_KEY ) return false;
 
13
 
14
- global $mycred_badge;
15
 
16
- $badge_id = absint( $badge_id );
17
 
18
- if ( isset( $mycred_badge )
19
- && ( $mycred_badge instanceof myCRED_Badge )
20
- && ( $badge_id === $mycred_badge->post_id )
21
- ) {
22
- return $mycred_badge;
23
- }
24
 
25
- $mycred_badge = new myCRED_Badge( $badge_id, $level );
26
 
27
- do_action( 'mycred_get_badge' );
28
 
29
- return $mycred_badge;
30
 
31
- }
32
  endif;
33
 
34
  /**
35
  * Get Badge References
36
  * Returns an array of references used by badges for quicker checks.
37
- * @since 1.7
 
38
  * @version 1.0
39
  */
40
- if ( ! function_exists( 'mycred_get_badge_references' ) ) :
41
- function mycred_get_badge_references( $point_type = MYCRED_DEFAULT_TYPE_KEY, $force = false ) {
 
42
 
43
- $references = mycred_get_option( 'mycred-badge-refs-' . $point_type );
44
- if ( ! is_array( $references ) || empty( $references ) || $force ) {
45
 
46
- global $wpdb;
47
 
48
- $new_list = array();
49
 
50
- // Old versions
51
- $references = $wpdb->get_results( "SELECT post_id, meta_value FROM {$wpdb->postmeta} WHERE meta_key = 'badge_requirements';" );
52
- if ( ! empty( $references ) ) {
53
- foreach ( $references as $entry ) {
54
 
55
- $requirement = maybe_unserialize( $entry->meta_value );
56
- if ( ! is_array( $requirement ) || empty( $requirement ) ) continue;
 
57
 
58
- if ( ! array_key_exists( 'type', $requirement ) || $requirement['type'] != $point_type || $requirement['reference'] == '' ) continue;
 
59
 
60
- if ( ! array_key_exists( $requirement['reference'], $new_list ) )
61
- $new_list[ $requirement['reference'] ] = array();
 
62
 
63
- if ( ! in_array( $entry->post_id, $new_list[ $requirement['reference'] ] ) )
64
- $new_list[ $requirement['reference'] ][] = $entry->post_id;
 
65
 
66
- }
67
- }
68
 
69
 
70
- // New version (post 1.7)
71
- $table = mycred_get_db_column( 'postmeta' );
72
- $references = $wpdb->get_results( "SELECT post_id, meta_value FROM {$table} WHERE meta_key = 'badge_prefs';" );
73
- if ( ! empty( $references ) ) {
74
- foreach ( $references as $entry ) {
75
 
76
- // Manual badges should be ignored
77
- if ( absint( mycred_get_post_meta( $entry->post_id, 'manual_badge', true ) ) === 1 ) continue;
 
78
 
79
- $levels = maybe_unserialize( $entry->meta_value );
80
- if ( ! is_array( $levels ) || empty( $levels ) ) continue;
 
81
 
82
- foreach ( $levels as $level => $setup ) {
83
 
84
- if ( $level > 0 ) continue;
 
85
 
86
- foreach ( $setup['requires'] as $requirement_row => $requirement ) {
87
 
88
- if ( $requirement['type'] != $point_type || $requirement['reference'] == '' ) continue;
 
89
 
90
- if ( ! array_key_exists( $requirement['reference'], $new_list ) )
91
- $new_list[ $requirement['reference'] ] = array();
 
92
 
93
- if ( ! in_array( $entry->post_id, $new_list[ $requirement['reference'] ] ) )
94
- $new_list[ $requirement['reference'] ][] = $entry->post_id;
 
95
 
96
- }
97
 
98
- }
99
 
100
- }
101
- }
102
 
103
- if ( ! empty( $new_list ) )
104
- mycred_update_option( 'mycred-badge-references-' . $point_type, $new_list );
 
105
 
106
- $references = $new_list;
107
 
108
- }
109
 
110
- return apply_filters( 'mycred_get_badge_references', $references, $point_type );
111
 
112
- }
113
  endif;
114
 
115
  /**
116
  * Get Badge Requirements
117
  * Returns the badge requirements as an array.
118
- * @since 1.5
 
119
  * @version 1.1
120
  */
121
- if ( ! function_exists( 'mycred_get_badge_requirements' ) ) :
122
- function mycred_get_badge_requirements( $badge_id = NULL ) {
 
123
 
124
- return mycred_get_badge_levels( $badge_id );
125
 
126
- }
127
  endif;
128
 
129
  /**
130
  * Get Badge Levels
131
  * Returns an array of levels associated with a given badge.
132
- * @since 1.7
 
133
  * @version 1.0.1
134
  */
135
- if ( ! function_exists( 'mycred_get_badge_levels' ) ) :
136
- function mycred_get_badge_levels( $badge_id ) {
 
137
 
138
- $setup = mycred_get_post_meta( $badge_id, 'badge_prefs', true );
139
- if ( ! is_array( $setup ) || empty( $setup ) ) {
140
 
141
- // Backwards comp.
142
- $old_setup = mycred_get_post_meta( $badge_id, 'badge_requirements', true );
143
 
144
- // Convert old setup to new
145
- if ( is_array( $old_setup ) && ! empty( $old_setup ) ) {
146
 
147
- $new_setup = array();
148
- foreach ( $old_setup as $level => $requirements ) {
149
 
150
- $level_image = mycred_get_post_meta( $badge_id, 'level_image' . $level, true );
151
- if ( $level_image == '' || $level == 0 )
152
- $level_image = mycred_get_post_meta( $badge_id, 'main_image', true );
 
153
 
154
- $row = array(
155
- 'image_url' => $level_image,
156
- 'attachment_id' => 0,
157
- 'label' => '',
158
- 'compare' => 'AND',
159
- 'requires' => array(),
160
- 'reward' => array(
161
- 'type' => MYCRED_DEFAULT_TYPE_KEY,
162
- 'amount' => 0,
163
- 'log' => ''
164
- )
165
- );
166
 
167
- $row['requires'][] = $requirements;
168
 
169
- $new_setup[] = $row;
170
 
171
- }
172
 
173
- if ( ! empty( $new_setup ) ) {
174
 
175
- mycred_update_post_meta( $badge_id, 'badge_prefs', $new_setup );
176
- mycred_delete_post_meta( $badge_id, 'badge_requirements' );
177
 
178
- $setup = $new_setup;
179
 
180
- }
181
 
182
- }
183
 
184
- }
185
 
186
- if ( empty( $setup ) && ! is_array( $setup ) )
187
- $setup = array();
 
188
 
189
- if ( empty( $setup ) )
190
- $setup[] = array(
191
- 'image_url' => '',
192
- 'attachment_id' => 0,
193
- 'label' => '',
194
- 'compare' => 'AND',
195
- 'requires' => array(
196
- 0 => array(
197
- 'type' => MYCRED_DEFAULT_TYPE_KEY,
198
- 'reference' => '',
199
- 'amount' => '',
200
- 'by' => ''
201
- )
202
- ),
203
- 'reward' => array(
204
- 'type' => MYCRED_DEFAULT_TYPE_KEY,
205
- 'amount' => 0,
206
- 'log' => ''
207
- )
208
- );
 
209
 
210
- return apply_filters( 'mycred_badge_levels', $setup, $badge_id );
211
 
212
- }
213
  endif;
214
 
215
  /**
216
  * Display Badge Requirements
217
  * Returns the badge requirements as a string in a readable format.
218
- * @since 1.5
 
219
  * @version 1.2.2
220
  */
221
- if ( ! function_exists( 'mycred_display_badge_requirement' ) ) :
222
- function mycred_display_badge_requirements( $badge_id = NULL ) {
 
223
 
224
- $badge = mycred_get_badge( $badge_id );
225
- $levels = mycred_get_badge_levels( $badge_id );
226
 
227
- if ( empty( $levels ) ) {
228
 
229
- $reply = '-';
230
 
231
- }
232
- else {
233
 
234
- $point_types = mycred_get_types( true );
235
- $references = mycred_get_all_references();
236
- $req_count = count( $levels[0]['requires'] );
237
 
238
- // Get the requirements for the first level
239
- $base_requirements = array();
240
- foreach ( $levels[0]['requires'] as $requirement_row => $requirement ) {
241
 
242
- if ( $requirement['type'] == '' )
243
- $requirement['type'] = MYCRED_DEFAULT_TYPE_KEY;
 
244
 
245
- if ( ! array_key_exists( $requirement['type'], $point_types ) )
246
- continue;
 
247
 
248
- if ( ! array_key_exists( $requirement['reference'], $references ) )
249
- $reference = '-';
250
- else
251
- $reference = $references[ $requirement['reference'] ];
 
252
 
253
- $base_requirements[ $requirement_row ] = array(
254
- 'type' => $requirement['type'],
255
- 'ref' => $reference,
256
- 'amount' => $requirement['amount'],
257
- 'by' => $requirement['by']
258
- );
259
 
260
- }
261
 
262
- // Loop through each level
263
- $output = array();
264
- foreach ( $levels as $level => $setup ) {
265
 
266
- $level_label = '';
267
 
268
- if ( ! $badge->open_badge ) {
269
-
270
- $level_label = '<strong>' . sprintf( __( 'Level %s', 'mycred' ), ( $level + 1 ) ) . ':</strong>';
271
- if ( $levels[ $level ]['label'] != '' )
272
- $level_label = '<strong>' . $levels[ $level ]['label'] . ':</strong>';
 
273
 
274
- }
275
 
276
- // Construct requirements to be used in an unorganized list.
277
- $level_req = array();
278
- foreach ( $setup['requires'] as $requirement_row => $requirement ) {
279
 
280
- $level_value = $requirement['amount'];
281
- $requirement = $base_requirements[ $requirement_row ];
282
 
283
- $mycred = mycred( $requirement['type'] );
284
 
285
- if ( $level > 0 )
286
- $requirement['amount'] = $level_value;
 
287
 
288
- if ( $requirement['by'] == 'count' )
289
- $rendered_row = sprintf( _x( '%s for "%s" x %d', '"Points" for "reference" x times', 'mycred' ), $mycred->plural(), $requirement['ref'], $requirement['amount'] );
290
- else
291
- $rendered_row = sprintf( _x( '%s %s for "%s"', '"Gained/Lost" "x points" for "reference"', 'mycred' ), ( ( $requirement['amount'] < 0 ) ? __( 'Lost', 'mycred' ) : __( 'Gained', 'mycred' ) ), $mycred->format_creds( $requirement['amount'] ), $requirement['ref'] );
 
292
 
293
- $compare = _x( 'OR', 'Comparison of badge requirements. A OR B', 'mycred' );
294
- if ( $setup['compare'] === 'AND' )
295
- $compare = _x( 'AND', 'Comparison of badge requirements. A AND B', 'mycred' );
 
296
 
297
- if ( $req_count > 1 && $requirement_row+1 < $req_count )
298
- $rendered_row .= ' <span>' . $compare . '</span>';
 
299
 
300
- $level_req[] = $rendered_row;
301
 
302
- }
303
 
304
- if ( empty( $level_req ) ) continue;
 
305
 
306
- $output[] = $level_label . '<ul class="mycred-badge-requirement-list '. ( $badge->open_badge ? 'open_badge' : '' ) .'"><li>' . implode( '</li><li>', $level_req ) . '</li></ul>';
307
 
308
- }
309
 
310
- if ( (int) mycred_get_post_meta( $badge_id, 'manual_badge', true ) === 1 )
311
- $output[] = '<strong><small><em>' . __( 'This badge is manually awarded.', 'mycred' ) . '</em></small></strong>';
 
312
 
313
- $reply = implode( '', $output );
314
 
315
- }
316
 
317
- return apply_filters( 'mycred_badge_display_requirements', $reply, $badge_id );
318
 
319
- }
320
  endif;
321
 
322
  /**
323
  * Count Users with Badge
324
  * Counts the number of users that has the given badge. Option to get count
325
  * of a specific level.
326
- * @since 1.5
 
327
  * @version 1.1
328
  */
329
- if ( ! function_exists( 'mycred_count_users_with_badge' ) ) :
330
- function mycred_count_users_with_badge( $badge_id = NULL, $level = NULL ) {
 
331
 
332
- $badge_id = absint( $badge_id );
333
 
334
- if ( $badge_id === 0 ) return false;
 
335
 
336
- // Get the badge object
337
- $badge = mycred_get_badge( $badge_id );
338
 
339
- // Most likely not a badge post ID
340
- if ( $badge === false ) return false;
 
341
 
342
- return $badge->get_user_count( $level );
343
 
344
- }
345
  endif;
346
 
347
  /**
348
  * Count Users without Badge
349
  * Counts the number of users that does not have a given badge.
350
- * @since 1.5
 
351
  * @version 1.2
352
  */
353
- if ( ! function_exists( 'mycred_count_users_without_badge' ) ) :
354
- function mycred_count_users_without_badge( $badge_id = NULL ) {
 
355
 
356
- $total = count_users();
357
- $with_badge = mycred_count_users_with_badge( $badge_id );
358
- if ( $with_badge === false ) $with_badge = 0;
 
359
 
360
- $without_badge = $total['total_users'] - $with_badge;
361
 
362
- return apply_filters( 'mycred_count_users_without_badge', absint( $without_badge ), $badge_id );
363
 
364
- }
365
  endif;
366
 
367
  /**
368
  * Reference Has Badge
369
  * Checks if a given reference has a badge associated with it.
370
- * @since 1.5
 
371
  * @version 1.4
372
  */
373
- if ( ! function_exists( 'mycred_ref_has_badge' ) ) :
374
- function mycred_ref_has_badge( $reference = NULL, $point_type = MYCRED_DEFAULT_TYPE_KEY ) {
 
375
 
376
- $badge_ids = array();
377
- if ( $reference === NULL || strlen( $reference ) == 0 || ! mycred_point_type_exists( $point_type ) ) return $badge_ids;
 
378
 
379
- $badge_references = mycred_get_badge_references( $point_type );
380
- $badge_references = maybe_unserialize( $badge_references );
381
 
382
- if ( ! empty( $badge_references ) && array_key_exists( $reference, $badge_references ) )
383
- $badge_ids = $badge_references[ $reference ];
 
384
 
385
- if ( empty( $badge_ids ) )
386
- $badge_ids = false;
 
387
 
388
- return apply_filters( 'mycred_ref_has_badge', $badge_ids, $reference, $badge_references, $point_type );
389
 
390
- }
391
  endif;
392
 
393
  /**
394
  * Badge Level Reached
395
  * Checks what level a user has earned for a badge. Returns false if badge was not earned.
396
- * @since 1.7
 
397
  * @version 1.1
398
  */
399
- if ( ! function_exists( 'mycred_badge_level_reached' ) ) :
400
- function mycred_badge_level_reached( $user_id = NULL, $badge_id = NULL ) {
 
401
 
402
- $user_id = absint( $user_id );
403
- $badge_id = absint( $badge_id );
404
 
405
- if ( $user_id === 0 || $badge_id === 0 ) return false;
 
406
 
407
- // Get the badge object
408
- $badge = mycred_get_badge( $badge_id );
409
 
410
- // Most likely not a badge post ID
411
- if ( $badge === false ) return false;
 
412
 
413
- return $badge->query_users_level( $user_id );
414
 
415
- }
416
  endif;
417
 
418
  /**
419
  * Check if User Gets Badge
420
  * Checks if a given user has earned one or multiple badges.
421
- * @since 1.5
 
422
  * @version 1.4
423
  */
424
- if ( ! function_exists( 'mycred_check_if_user_gets_badge' ) ) :
425
- function mycred_check_if_user_gets_badge( $user_id = NULL, $badge_ids = array(), $depreciated = array(), $save = true ) {
 
426
 
427
- $user_id = absint( $user_id );
428
- if ( $user_id === 0 ) return false;
 
429
 
430
- $earned_badge_ids = array();
431
- if ( ! empty( $badge_ids ) ) {
432
- foreach ( $badge_ids as $badge_id ) {
433
 
434
- $badge = mycred_get_badge( $badge_id );
435
- if ( $badge === false ) continue;
 
436
 
437
- $level_reached = $badge->get_level_reached( $user_id );
438
- if ( $level_reached !== false ) {
439
 
440
- if ( $save )
441
- $badge->assign( $user_id, $level_reached );
 
442
 
443
- $earned_badge_ids[] = $badge_id;
444
 
445
- }
446
 
447
- }
448
- }
449
 
450
- return $earned_badge_ids;
451
 
452
- }
453
  endif;
454
 
455
  /**
456
  * Assign Badge
457
  * Assigns a given badge to all users that fulfill the badges requirements.
458
- * @since 1.7
 
459
  * @version 1.2
460
  */
461
- if ( ! function_exists( 'mycred_assign_badge' ) ) :
462
- function mycred_assign_badge( $badge_id = NULL ) {
 
463
 
464
- $user_id = absint( $user_id );
465
- $badge_id = absint( $badge_id );
466
 
467
- if ( $user_id === 0 || $badge_id === 0 ) return false;
 
468
 
469
- // Get the badge object
470
- $badge = mycred_get_badge( $badge_id );
471
 
472
- // Most likely not a badge post ID
473
- if ( $badge === false ) return false;
 
474
 
475
- return $badge->assign_all();
476
 
477
- }
478
  endif;
479
 
480
  /**
481
  * Assign Badge to User
482
- * @since 1.7
 
483
  * @version 1.1
484
  */
485
- if ( ! function_exists( 'mycred_assign_badge_to_user' ) ) :
486
- function mycred_assign_badge_to_user( $user_id = NULL, $badge_id = NULL, $level = 0 ) {
 
487
 
488
- $user_id = absint( $user_id );
489
- $badge_id = absint( $badge_id );
490
- $level = absint( $level );
491
 
492
- if ( $user_id === 0 || $badge_id === 0 ) return false;
 
493
 
494
- // Get the badge object
495
- $badge = mycred_get_badge( $badge_id );
496
 
497
- // Most likely not a badge post ID
498
- if ( $badge === false ) return false;
 
499
 
500
- return $badge->assign( $user_id, $level );
501
 
502
- }
503
  endif;
504
 
505
  /**
506
  * User Has Badge
507
  * Checks if a user has a particular badge by badge ID.
508
- * @since 1.8
 
509
  * @version 1.0
510
  */
511
- if ( ! function_exists( 'mycred_user_has_badge' ) ) :
512
- function mycred_user_has_badge( $user_id = 0, $badge_id = NULL, $level_id = 0 ) {
 
513
 
514
- $user_id = absint( $user_id );
515
- $badge_id = absint( $badge_id );
516
- $level_id = absint( $level_id );
517
 
518
- if ( $user_id === 0 || $badge_id === 0 ) return false;
 
519
 
520
- global $mycred_current_account;
521
 
522
- if ( mycred_is_current_account( $user_id ) && isset( $mycred_current_account->badge_ids ) && ! empty( $mycred_current_account->badge_ids ) ) {
523
 
524
- $has_badge = array_key_exists( $badge_id, $mycred_current_account->badge_ids );
525
 
526
- }
527
- else {
528
 
529
- // Get the badge object
530
- $badge = mycred_get_badge( $badge_id );
531
 
532
- // Most likely not a badge post ID
533
- if ( $badge !== false )
534
- $has_badge = $badge->user_has_badge( $user_id, $level_id );
 
535
 
536
- }
537
 
538
- return $has_badge;
539
 
540
- }
541
  endif;
542
 
543
  /**
544
  * Get Users Badge Level
545
- * @since 1.8
 
546
  * @version 1.0
547
  */
548
- if ( ! function_exists( 'mycred_get_users_badge_level' ) ) :
549
- function mycred_get_users_badge_level( $user_id = 0, $badge_id = NULL ) {
 
550
 
551
- $user_id = absint( $user_id );
552
- $badge_id = absint( $badge_id );
553
 
554
- if ( $user_id === 0 || $badge_id === 0 ) return false;
 
555
 
556
- global $mycred_current_account;
557
 
558
- if ( mycred_is_current_account( $user_id ) && isset( $mycred_current_account->badges ) && ! empty( $mycred_current_account->badges ) && array_key_exists( $badge_id, $mycred_current_account->badges ) )
559
- return $mycred_current_account->badges[ $badge_id ]->level_id;
 
560
 
561
- // Get the badge object
562
- $badge = mycred_get_badge( $badge_id );
563
 
564
- // Most likely not a badge post ID
565
- if ( $badge === false ) return false;
 
566
 
567
- return $badge->get_users_current_level( $user_id );
568
 
569
- }
570
  endif;
571
 
572
  /**
573
  * Get Users Badges
574
  * Returns the badge post IDs that a given user currently holds.
575
- * @since 1.5
 
576
  * @version 1.3
577
  */
578
- if ( ! function_exists( 'mycred_get_users_badges' ) ) :
579
- function mycred_get_users_badges( $user_id = NULL, $force = false ) {
 
580
 
581
- if ( $user_id === NULL ) return array();
 
582
 
583
- global $mycred_current_account;
584
 
585
- if ( mycred_is_current_account( $user_id ) && isset( $mycred_current_account->badge_ids ) && $force == false )
586
- return $mycred_current_account->badge_ids;
 
587
 
588
- $badge_ids = mycred_get_user_meta( $user_id, MYCRED_BADGE_KEY . '_ids', '', true );
589
- if ( !isset($badge_ids) || $badge_ids == '' || $force ) {
590
 
591
- global $wpdb;
592
 
593
- $badge_ids = array();
594
- $query = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM {$wpdb->usermeta} WHERE user_id = %d AND meta_key LIKE %s AND meta_key NOT LIKE '%_issued_on' AND meta_key NOT LIKE '%_ids'", $user_id, mycred_get_meta_key( MYCRED_BADGE_KEY ) . '%' ) );
595
 
596
- if ( ! empty( $query ) ) {
597
 
598
- foreach ( $query as $badge ) {
599
 
600
- $badge_id = str_replace( MYCRED_BADGE_KEY, '', $badge->meta_key );
601
- if ( $badge_id == '' ) continue;
602
-
603
- $badge_id = absint( $badge_id );
604
- if ( ! array_key_exists( $badge_id, $badge_ids ) )
605
- $badge_ids[ $badge_id ] = absint( $badge->meta_value );
 
 
606
 
607
- }
608
 
609
- mycred_update_user_meta( $user_id, MYCRED_BADGE_KEY . '_ids', '', $badge_ids );
610
 
611
- }
612
 
613
- }
614
-
615
- $clean_ids = array();
616
- if ( ! empty( $badge_ids ) ) {
617
- foreach ( $badge_ids as $id => $level ) {
618
 
619
- $id = absint( $id );
620
- if ( $id === 0 || strlen( $level ) < 1 ) continue;
621
- $clean_ids[ $id ] = absint( $level );
 
622
 
623
- }
624
- }
625
 
626
- return apply_filters( 'mycred_get_users_badges', $clean_ids, $user_id );
627
 
628
- }
629
  endif;
630
 
631
  /**
632
  * Display Users Badges
633
  * Will echo all badge images a given user has earned.
634
- * @since 1.5
 
635
  * @version 1.3.2
636
  */
637
- if ( ! function_exists( 'mycred_display_users_badges' ) ) :
638
- function mycred_display_users_badges( $user_id = NULL, $width = MYCRED_BADGE_WIDTH, $height = MYCRED_BADGE_HEIGHT ) {
 
639
 
640
- $user_id = absint( $user_id );
641
- if ( $user_id === 0 ) return;
 
642
 
643
- $users_badges = mycred_get_users_badges( $user_id );
644
 
645
- echo '<div class="row" id="mycred-users-badges"><div class="col-lg-12 col-md-12 col-sm-12 col-xs-12">';
646
 
647
- do_action( 'mycred_before_users_badges', $user_id, $users_badges );
648
 
649
- if ( ! empty( $users_badges ) ) {
650
 
651
- foreach ( $users_badges as $badge_id => $level ) {
652
 
653
- $badge = mycred_get_badge( $badge_id, $level );
654
- if ( $badge === false ) continue;
 
655
 
656
- $badge->image_width = $width;
657
- $badge->image_height = $height;
658
 
659
- $badge_image = '';
660
 
661
- if ( $badge->level_image !== false )
662
- $badge_image = $badge->get_image( $level );
663
- else if( $badge->main_image !== false )
664
- $badge_image = $badge->get_image( 'main' );
 
665
 
666
- if ( !empty( $badge_image ) )
667
- echo apply_filters( 'mycred_the_badge', $badge_image, $badge_id, $badge, $user_id );
 
668
 
669
- }
670
 
671
- }
672
 
673
- do_action( 'mycred_after_users_badges', $user_id, $users_badges );
674
 
675
- echo '</div></div>';
676
 
677
- }
678
  endif;
679
 
680
  /**
681
  * Get Badge IDs
682
  * Returns all published badge post IDs.
683
- * @since 1.5
 
684
  * @version 1.1
685
  */
686
- if ( ! function_exists( 'mycred_get_badge_ids' ) ) :
687
- function mycred_get_badge_ids() {
 
688
 
689
- $badge_ids = wp_cache_get( 'badge_ids', MYCRED_SLUG );
690
- if ( $badge_ids !== false && is_array( $badge_ids ) ) return $badge_ids;
 
691
 
692
- global $wpdb;
693
 
694
- $table = mycred_get_db_column( 'posts' );
695
- $badge_ids = $wpdb->get_col( $wpdb->prepare( "
 
 
696
  SELECT ID
697
  FROM {$table}
698
  WHERE post_type = %s
699
  AND post_status = 'publish'
700
- ORDER BY post_date ASC;", MYCRED_BADGE_KEY ) );
 
 
701
 
702
- wp_cache_set( 'badge_ids', $badge_ids, MYCRED_SLUG );
703
 
704
- return apply_filters( 'mycred_get_badge_ids', $badge_ids );
705
 
706
- }
707
  endif;
708
 
709
  /**
710
  * Get Badges by Term ID
711
- * @since 2.1
 
712
  * @version 1.0
713
- * @param $term_id Pass term Id
714
  * return posts by term Id
715
  */
716
- if( !function_exists( 'mycred_get_badges_by_term_id' ) ) :
717
- function mycred_get_badges_by_term_id($term_id ) {
718
- $badge_args = query_posts(array(
 
 
719
  'post_type' => MYCRED_BADGE_KEY,
720
  'showposts' => -1,
721
  'tax_query' => array(
@@ -734,16 +831,18 @@ endif;
734
 
735
  /**
736
  * Get Badge/ Level Requirements
737
- * @since 2.1
 
738
  * @version 1.0
739
- * @param $badge_id Pass Badge ID
740
  */
741
- if( !function_exists( 'mycred_show_badge_requirements' ) ) :
742
- function mycred_show_badge_requirements( $badge_id ) {
 
743
 
744
  $data = array();
745
- $levels = mycred_get_badge_levels( $badge_id );
746
- if ( empty( $levels ) ) {
747
 
748
  $reply = '-';
749
 
@@ -758,16 +857,19 @@ if( !function_exists( 'mycred_show_badge_requirements' ) ) :
758
  $base_requirements = array();
759
  foreach ($levels[0]['requires'] as $requirement_row => $requirement) {
760
 
761
- if ($requirement['type'] == '')
762
  $requirement['type'] = MYCRED_DEFAULT_TYPE_KEY;
 
763
 
764
- if (!array_key_exists($requirement['type'], $point_types))
765
  continue;
 
766
 
767
- if (!array_key_exists($requirement['reference'], $references))
768
  $reference = '-';
769
- else
770
  $reference = $references[$requirement['reference']];
 
771
 
772
  $base_requirements[$requirement_row] = array(
773
  'type' => $requirement['type'],
@@ -784,22 +886,25 @@ if( !function_exists( 'mycred_show_badge_requirements' ) ) :
784
  //collecting images
785
  $image = false;
786
 
787
- if ( $setup['attachment_id'] > 0 ) {
788
 
789
- $_image = wp_get_attachment_url( $setup['attachment_id'] );
790
- if ( strlen( $_image ) > 5 )
791
  $output['image'] = $_image;
 
792
 
793
  }
794
  else {
795
 
796
- if ( strlen( $setup['image_url'] ) > 5 )
797
  $output['image'] = $setup['image_url'];
 
798
  }
799
 
800
  $level_label = sprintf(__('Level %s', 'mycred'), ($level + 1));
801
- if ($levels[$level]['label'] != '')
802
  $level_label = $levels[$level]['label'];
 
803
 
804
  // Construct requirements to be used in an unorganized list.
805
  $level_req = array();
@@ -809,38 +914,44 @@ if( !function_exists( 'mycred_show_badge_requirements' ) ) :
809
 
810
  $mycred = mycred($requirement['type']);
811
 
812
- if ($level > 0)
813
  $requirement['amount'] = $level_value;
 
814
 
815
- if ($requirement['by'] == 'count')
816
  $rendered_row = sprintf(_x('%s for "%s" x %d', '"Points" for "reference" x times', 'mycred'), $mycred->plural(), $requirement['ref'], $requirement['amount']);
817
- else
818
  $rendered_row = sprintf(_x('%s %s for "%s"', '"Gained/Lost" "x points" for "reference"', 'mycred'), (($requirement['amount'] < 0) ? __('Lost', 'mycred') : __('Gained', 'mycred')), $mycred->format_creds($requirement['amount']), $requirement['ref']);
 
819
 
820
  $compare = _x('OR', 'Comparison of badge requirements. A OR B', 'mycred');
821
- if ($setup['compare'] === 'AND')
822
  $compare = _x('AND', 'Comparison of badge requirements. A AND B', 'mycred');
 
823
 
824
- if ($req_count > 1 && $requirement_row + 1 < $req_count)
825
  $rendered_row .= ' <span>' . $compare . '</span>';
 
826
 
827
  $level_req[] = $rendered_row;
828
 
829
  }
830
 
831
- if ( empty( $level_req ) ) continue;
 
832
 
833
  $output['heading'] = $level_label;
834
  $output['requirements'] = $level_req;
835
  $output["reward_type"] = $setup["reward"]["type"];
836
  $output["amount"] = $setup["reward"]["amount"];
837
 
838
- array_push( $data, $output );
839
 
840
  }
841
 
842
- if ( (int) mycred_get_post_meta( $badge_id, 'manual_badge', true ) === 1 )
843
  $output[] = '<strong><small><em>' . __('This badge is manually awarded.', 'mycred') . '</em></small></strong>';
 
844
 
845
  return $data;
846
  }
@@ -850,18 +961,20 @@ endif;
850
 
851
  /**
852
  * Get users have have specific badge
853
- * @param $badge_id Pass Badge ID
854
- * @param int $level_id
855
- * @return array Will return Array of User ID's have the specific Badge
856
- * @since 2.1
 
857
  * @version 1.0
858
  */
859
- if( !function_exists( 'mycred_get_users_has_earned_badge' ) ) :
860
- function mycred_get_users_has_earned_badge( $badge_id, $level_id = 0 ) {
 
861
 
862
  $users_has_badge = array();
863
 
864
- $badge_id = absint( $badge_id );
865
 
866
  $args = array(
867
  'fields' => array(
@@ -870,7 +983,7 @@ if( !function_exists( 'mycred_get_users_has_earned_badge' ) ) :
870
  )
871
  );
872
 
873
- $users = get_users( $args );
874
 
875
  foreach ( $users as $user ) {
876
 
@@ -879,25 +992,24 @@ if( !function_exists( 'mycred_get_users_has_earned_badge' ) ) :
879
  $user_id = $user->ID;
880
 
881
  // Get the badge object
882
- $badge = mycred_get_badge( $badge_id );
883
 
884
  // Most likely not a badge post ID
885
- if ( $badge !== false ) {
886
-
887
- $current_level = mycred_get_user_meta( $user_id, MYCRED_BADGE_KEY . $badge_id, '', true );
888
 
889
  $current_level = $current_level == '0' ? true : $current_level;
890
 
891
- if ( $current_level )
892
- {
893
  $has_badge = true;
894
 
895
- if ( (int) $current_level < absint( $level_id ) )
896
- {
897
  $has_badge = false;
898
  }
899
- if ( $has_badge )
900
  $users_has_badge[] = $user_id;
 
901
  }
902
  }
903
  }
@@ -908,19 +1020,20 @@ endif;
908
 
909
  /**
910
  * Get Badge Types
911
- * @since 2.1
 
912
  * @version 2.1
913
- * @param $badge_id Pass the Badge id
914
- * @return array Will return all the categories
915
  */
916
- if ( !function_exists('mycred_get_badge_type') ) :
917
- function mycred_get_badge_type( $badge_id ) {
 
918
 
919
- $badge_terms = get_the_terms( $badge_id, MYCRED_BADGE_CATEGORY, '', ', ' );
920
 
921
- if (is_array( $badge_terms ) || is_object($badge_terms))
922
- {
923
- $badge_type = join( ', ', wp_list_pluck($badge_terms, 'name') );
924
 
925
  return $badge_type;
926
  }
@@ -932,27 +1045,31 @@ endif;
932
 
933
  /**
934
  * Get Badge Level Image Url By Passing setup of Level Requirements Use Function mycred_get_badge_requirements()
935
- * @since 2.1
 
936
  * @version 1.0
937
- * @param $setup
938
- * @return bool|false|mixed|string
939
  */
940
- if( !function_exists( 'mycred_get_level_image_url' ) ) :
941
- function mycred_get_level_image_url( $setup ) {
 
942
 
943
  $image = false;
944
 
945
- if ( $setup['attachment_id'] > 0 ) {
946
 
947
- $_image = wp_get_attachment_url( $setup['attachment_id'] );
948
- if ( strlen( $_image ) > 5 )
949
  return $_image;
 
950
 
951
  }
952
  else {
953
 
954
- if ( strlen( $setup['image_url'] ) > 5 )
955
  return $setup['image_url'];
 
956
  }
957
 
958
  return $image;
@@ -962,34 +1079,36 @@ endif;
962
 
963
  /**
964
  * Cretae Evidence page
965
- * @since 2.1
 
966
  * @version 1.0
967
  */
968
- if ( ! function_exists( 'mycred_get_evidence_page_id' ) ) :
969
- function mycred_get_evidence_page_id() {
 
970
 
971
- $evidencePageId = 0;
972
 
973
- $badges = mycred_get_addon_settings( 'badges' );
974
 
975
  //If Open badge enabled
976
- if ( isset( $badges['open_badge'] ) && $badges['open_badge'] == '1' ) {
977
 
978
  $canCreatePage = true;
979
 
980
- $evidence_page_refrence = mycred_get_option( 'open_badge_evidence_page', 0 );
981
 
982
- if ( ! empty( $badges['open_badge_evidence_page'] ) || ! empty( $evidence_page_refrence ) ) {
983
 
984
- $pageId = intval( $evidence_page_refrence );
985
 
986
- if ( ! empty( $badges['open_badge_evidence_page'] ) ) {
987
-
988
- $pageId = intval( $badges['open_badge_evidence_page'] );
989
 
990
- }
991
 
992
- if ( get_post_status( $pageId ) == 'publish' ) {
993
 
994
  $canCreatePage = false;
995
  $evidencePageId = $pageId;
@@ -998,7 +1117,7 @@ if ( ! function_exists( 'mycred_get_evidence_page_id' ) ) :
998
 
999
  }
1000
 
1001
- if ( $canCreatePage ) {
1002
 
1003
  $postData = array(
1004
  'post_content' => '[' . MYCRED_SLUG . '_badge_evidence]',
@@ -1009,13 +1128,13 @@ if ( ! function_exists( 'mycred_get_evidence_page_id' ) ) :
1009
  'post_name' => 'Badge Evidence'
1010
  );
1011
 
1012
- $pageId = wp_insert_post( $postData );
1013
 
1014
- $evidencePageId = intval( $pageId );
1015
 
1016
- mycred_update_option( 'open_badge_evidence_page', $evidencePageId );
1017
 
1018
- mycred_set_badge_evidence_page( $evidencePageId );
1019
 
1020
  }
1021
 
@@ -1028,72 +1147,77 @@ endif;
1028
 
1029
  /**
1030
  * Set Evidence page
1031
- * @since 2.1
 
1032
  * @version 1.0
1033
  */
1034
- if ( ! function_exists( 'mycred_set_badge_evidence_page' ) ) :
1035
- function mycred_set_badge_evidence_page( $page_id ) {
 
1036
 
1037
- $settings = mycred_get_option( 'mycred_pref_core' );
1038
 
1039
- if ( isset( $settings[ 'badges' ] ) ) {
1040
 
1041
- $settings[ 'badges' ][ 'open_badge_evidence_page' ] = intval( $page_id );
1042
 
1043
- mycred_update_option( 'mycred_pref_core', $settings );
1044
 
1045
- }
1046
 
1047
- }
1048
  endif;
1049
 
1050
  /**
1051
  * Get badges list
1052
- * @since 2.1.1
 
1053
  * @version 1.0
1054
  */
1055
- if ( ! function_exists( 'mycred_get_uncategorized_badge_list' ) ) :
1056
- function mycred_get_uncategorized_badge_list() {
 
1057
 
1058
- $badge_list = '';
1059
 
1060
- //Get Badges
1061
  $args = array(
1062
  'numberposts' => -1,
1063
  'post_type' => MYCRED_BADGE_KEY
1064
  );
1065
 
1066
- $badges = get_posts( $args );
1067
 
1068
  $user_id = get_current_user_id();
1069
- $categories = get_categories( $args );
1070
- $category_count = count( $categories );
1071
 
1072
  //Show Badges
1073
  foreach ( $badges as $badge ) {
1074
 
1075
- $badge_object = mycred_get_badge( $badge->ID );
1076
 
1077
  $image_url = $badge_object->main_image_url;
1078
 
1079
- $has_earned = $badge_object->user_has_badge( $user_id ) ? 'earned' : 'not-earned';
1080
 
1081
- $category = mycred_get_badge_type( $badge->ID );
1082
 
1083
- $categories = explode( ',', $category );
1084
 
1085
- $badge_list .= '<div class="mycred-badges-list-item '.$has_earned.'" data-url="'.mycred_get_permalink( $badge->ID ).'">';
1086
 
1087
- if ( $image_url )
1088
- $badge_list .= '<img src="'.esc_url( $image_url ).'" alt="Badge Image">';
 
1089
 
1090
  $badge_list .= '<div class="mycred-left">';
1091
  $badge_list .= '<h3>'.$badge->post_title.'</h3>';
1092
- if( $category_count > 0 ) {
1093
 
1094
  foreach ( $categories as $category ) {
1095
 
1096
- if( $category != '' ) {
1097
 
1098
  $badge_list .= '<sup class="mycred-sup-category">'.$category.'</sup>';
1099
 
@@ -1112,23 +1236,25 @@ if ( ! function_exists( 'mycred_get_uncategorized_badge_list' ) ) :
1112
 
1113
  //mycred-badges-list-item
1114
  $badge_list .= '</div>';
1115
-
1116
  }
1117
 
1118
  return $badge_list;
1119
 
1120
- }
1121
  endif;
1122
 
1123
  /**
1124
  * Get badges list by categories
1125
- * @since 2.1.1
 
1126
  * @version 1.0
1127
  */
1128
- if ( ! function_exists( 'mycred_get_categorized_badge_list' ) ) :
1129
- function mycred_get_categorized_badge_list() {
 
1130
 
1131
- $user_id = get_current_user_id();
1132
 
1133
  $args = array(
1134
  'taxonomy' => MYCRED_BADGE_CATEGORY,
@@ -1138,8 +1264,8 @@ if ( ! function_exists( 'mycred_get_categorized_badge_list' ) ) :
1138
  'hide_empty' => false
1139
  );
1140
 
1141
- $categories = get_categories( $args );
1142
- $category_count = count( $categories );
1143
  $badges_list_tabs = array();
1144
  $badges_list_panels = array();
1145
 
@@ -1149,10 +1275,10 @@ if ( ! function_exists( 'mycred_get_categorized_badge_list' ) ) :
1149
 
1150
  $category_id = $category->cat_ID;
1151
  $category_name = $category->cat_name;
1152
- $category_badges = mycred_get_badges_by_term_id( $category_id );
1153
- $badges_count = count( $category_badges );
1154
 
1155
- if ( $badges_count > 0 ) {
1156
 
1157
  $badges_list_tabs[ $category_id ] = '<li data-id="' . $category_id . '" '. ( $counter == 1 ? 'class="active"' : '' ) .'>';
1158
  $badges_list_tabs[ $category_id ] .= $category_name . '<span class="mycred-badge-count">' . $badges_count . '</span>';
@@ -1164,17 +1290,17 @@ if ( ! function_exists( 'mycred_get_categorized_badge_list' ) ) :
1164
 
1165
  $badge_id = $badge->ID;
1166
 
1167
- $badge_object = mycred_get_badge( $badge_id );
1168
 
1169
  $image_url = $badge_object->main_image_url;
1170
 
1171
- $has_earned = $badge_object->user_has_badge( $user_id ) ? 'earned' : 'not-earned';
1172
 
1173
- $badges_list_panels[ $category_id ] .= '<div class="mycred-badges-list-item '. $has_earned .'" data-url="' . mycred_get_permalink( $badge_id ) . '">';
1174
 
1175
- if ( $image_url ) {
1176
 
1177
- $badges_list_panels[ $category_id ] .= '<img src="' . esc_url( $image_url ) . '" alt="Badge Image">';
1178
 
1179
  }
1180
 
@@ -1193,61 +1319,66 @@ if ( ! function_exists( 'mycred_get_categorized_badge_list' ) ) :
1193
  }
1194
 
1195
  return array(
1196
- 'tabs' => $badges_list_tabs,
1197
- 'panels' => $badges_list_panels,
1198
- 'category_count' => $category_count,
1199
  );
1200
 
1201
- }
1202
  endif;
1203
 
1204
  /**
1205
  * Returns Badge congratulation message.
1206
- * @since 2.2
 
1207
  * @version 1.0
1208
  */
1209
- if ( ! function_exists( 'mycred_badge_show_congratulation_msg' ) ) :
1210
- function mycred_badge_show_congratulation_msg( $user_id, $badge, $settings = NULL ) {
 
1211
 
1212
- $content = '';
1213
 
1214
- if ( empty( $settings ) ) $settings = mycred();
 
1215
 
1216
- if( ! empty( $settings->core["badges"]["show_congo_text"] ) && $badge->user_has_badge( $user_id ) && ! empty( $badge->congratulation_msg ) ) {
1217
 
1218
- $content .= '<div class="mycred-badge-congratulation-msg">' . $badge->congratulation_msg . '</div>';
1219
-
1220
- }
1221
 
1222
- return apply_filters( 'mycred_badge_show_congratulation_msg', $content, $badge, $settings );
1223
 
1224
- }
1225
  endif;
1226
 
1227
  /**
1228
  * Returns Badge main image with share icons.
1229
- * @since 2.2
 
1230
  * @version 1.0
1231
  */
1232
- if ( ! function_exists( 'mycred_badge_show_main_image_with_social_icons' ) ) :
1233
- function mycred_badge_show_main_image_with_social_icons( $user_id, $badge, $mycred = NULL ) {
 
1234
 
1235
- $content = '';
1236
 
1237
- $image_url = $badge->get_earned_image( $user_id );
1238
 
1239
- if ( ! empty( $image_url ) ) {
1240
 
1241
- $content .= '<div class="mycred-badge-image-wrapper">';
1242
 
1243
- $content .= '<img src="' . $image_url . '" class="mycred-badge-image" alt="Badge Image">';
1244
 
1245
- if ( empty( $mycred ) ) $mycred = mycred();
 
1246
 
1247
- //If user has earned badge, show user sharing badge option
1248
- if(
1249
- $badge->user_has_badge( $user_id ) &&
1250
- ! empty( $mycred->core["br_social_share"]["enable_open_badge_ss"] )
1251
  ) {
1252
 
1253
  $facebook_url = "http://www.facebook.com/sharer.php?u=".get_permalink()."&p[images][0]=$image_url";
@@ -1255,157 +1386,169 @@ if ( ! function_exists( 'mycred_badge_show_main_image_with_social_icons' ) ) :
1255
  $linkedin_url = "http://www.linkedin.com/shareArticle?url=".get_permalink()."";
1256
  $pinterest_url = "https://pinterest.com/pin/create/bookmarklet/?media=$image_url&amp;url=".get_permalink()."";
1257
 
1258
- $content .= mycred_br_get_social_icons( $facebook_url, $twitter_url, $linkedin_url, $pinterest_url );
1259
 
1260
  }
1261
 
1262
  $content .= '</div>';
1263
-
1264
- }
1265
 
1266
- return apply_filters( 'mycred_badge_show_main_image_with_social_icons', $content, $badge, $mycred );
1267
 
1268
- }
1269
  endif;
1270
 
1271
  /**
1272
  * Returns Badge description.
1273
- * @since 2.2
 
1274
  * @version 1.0
1275
  */
1276
- if ( ! function_exists( 'mycred_badge_show_description' ) ) :
1277
- function mycred_badge_show_description( $post, $settings = NULL ) {
 
1278
 
1279
- $content = '';
1280
 
1281
- if ( empty( $settings ) ) $settings = mycred();
 
1282
 
1283
- if( ! empty( $settings->core["badges"]["show_level_description"] ) && ! empty( $post->post_content ) ) {
1284
 
1285
- $content .= "<h3>" . __( "Description", "mycred" ) . "</h3>";
1286
  $content .= "<p>" . $post->post_content . "</p>";
1287
-
1288
- }
1289
 
1290
- return apply_filters( 'mycred_badge_show_description', $content, $post, $settings );
1291
 
1292
- }
1293
  endif;
1294
 
1295
  /**
1296
  * Returns Badge levels.
1297
- * @since 2.2
 
1298
  * @version 1.0
1299
  */
1300
- if ( ! function_exists( 'mycred_badge_show_levels' ) ) :
1301
- function mycred_badge_show_levels( $user_id, $badge, $settings = NULL ) {
 
1302
 
1303
- $content = '';
1304
 
1305
- if ( empty( $settings ) ) $settings = mycred();
 
1306
 
1307
- if( ! empty( $settings->core["badges"]["show_levels"] ) || $badge->open_badge && ! empty( $settings->core["badges"]["show_steps_to_achieve"] ) ) {
1308
 
1309
- if ( ! $badge->open_badge )
1310
  $content .= "<h3>" . __("Levels", "mycred") . "</h3>";
1311
- else
1312
  $content .= "<h3>" . __("Requirement", "mycred") . "</h3>";
 
1313
 
1314
- $levels = mycred_show_badge_requirements( $badge->post_id );
1315
 
1316
  foreach ( $levels as $id => $level ) {
1317
 
1318
- $level_image_url = $level["image"];
1319
 
1320
- $heading = $level["heading"];
1321
 
1322
- $requirements = $level["requirements"];
1323
 
1324
- $reward = $level["amount"];
1325
 
1326
- $content .= '<div class="mycred-badge-page-level">';
1327
 
1328
- if ( ! $badge->open_badge ) {
1329
 
1330
- if ( ! empty( $level_image_url ) )
1331
- $content .= '<img src="'.$level_image_url.'" class="mycred-level-image mycred-float-left" />';
 
1332
 
1333
- $content .= "<h4>$heading</h4>";
1334
- }
1335
 
1336
- $content .= "<div class='clear'></div>";
1337
 
1338
- if ( ! empty( $settings->core["badges"]["show_steps_to_achieve"] ) )
1339
- $content .= mycred_badge_level_req_check( $badge->post_id, $id );
 
1340
 
1341
- if ( ! empty( $settings->core["badges"]["show_level_points"] ) && $reward != 0 ) {
1342
 
1343
- $reward_type = mycred( $level['reward_type'] );
1344
 
1345
- $content .= '<div class="mycred-level-reward">' . __('Reward:', 'mycred') . ' ' . $reward_type->format_creds($reward ) .'</div>';
1346
- }
1347
 
1348
- $content .= '</div>';
1349
- }
1350
 
1351
- $content .= '<div class="clear"></div>';
1352
-
1353
- }
1354
 
1355
- return apply_filters( 'mycred_badge_show_levels', $content, $user_id, $badge, $settings );
1356
 
1357
- }
1358
  endif;
1359
 
1360
  /**
1361
  * Returns badge earners.
1362
- * @since 2.2
 
1363
  * @version 1.0
1364
  */
1365
- if ( ! function_exists( 'mycred_badge_show_earners' ) ) :
1366
- function mycred_badge_show_earners( $badge, $settings = NULL ) {
 
1367
 
1368
- $content = '';
1369
 
1370
- if ( empty( $settings ) ) $settings = mycred();
 
1371
 
1372
- if ( ! empty( $settings->core["badges"]["show_earners"] ) ) {
1373
 
1374
- $args = array(
1375
- 'meta_query' => array(
1376
- array(
1377
- 'key' => MYCRED_BADGE_KEY . $badge->post_id,
1378
- 'compare' => 'EXISTS'
1379
- )
1380
- )
1381
- );
1382
- $users_have_badge = get_users( $args );
1383
 
1384
- if ( ! empty( $users_have_badge ) ) {
1385
-
1386
- $content .= '<div class="mycred-badge-earners">';
1387
- $content .= "<h3>" . __("Earners", "mycred") . "</h3>";
1388
  $content .= '<div class="mycred-badge-earner-list">';
1389
 
1390
- foreach ( $users_have_badge as $user ) {
1391
 
1392
- $user_avatar = get_avatar_url( $user->ID );
1393
 
1394
- $content .= '<div class="mycred-badge-earner-grid mycred-float-left">';
1395
- $content .= '<div><img src="' . $user_avatar . '" /></div>';
1396
- $content .= "<h4>$user->display_name</h4>";
1397
- $content .= '</div>';
1398
 
1399
- }
1400
- $content .= '<div class="mycred-clearfix"></div>';
 
1401
  $content .= '</div>';
1402
- $content .= '</div>';
1403
 
1404
- }
1405
-
1406
- }
1407
 
1408
- return apply_filters( 'mycred_badge_show_earners', $content, $badge, $settings );
1409
 
1410
- }
1411
- endif;
1
  <?php
2
+ if (! defined('myCRED_VERSION') ) { exit;
3
+ }
4
 
5
  /**
6
  * Get Badge
7
+ *
8
+ * @since 1.7
9
  * @version 1.1
10
  */
11
+ if (! function_exists('mycred_get_badge') ) :
12
+ function mycred_get_badge( $badge_id = null, $level = null )
13
+ {
14
 
15
+ if (absint($badge_id) === 0 || mycred_get_post_type($badge_id) != MYCRED_BADGE_KEY ) { return false;
16
+ }
17
 
18
+ global $mycred_badge;
19
 
20
+ $badge_id = absint($badge_id);
21
 
22
+ if (isset($mycred_badge)
23
+ && ( $mycred_badge instanceof myCRED_Badge )
24
+ && ( $badge_id === $mycred_badge->post_id )
25
+ ) {
26
+ return $mycred_badge;
27
+ }
28
 
29
+ $mycred_badge = new myCRED_Badge($badge_id, $level);
30
 
31
+ do_action('mycred_get_badge');
32
 
33
+ return $mycred_badge;
34
 
35
+ }
36
  endif;
37
 
38
  /**
39
  * Get Badge References
40
  * Returns an array of references used by badges for quicker checks.
41
+ *
42
+ * @since 1.7
43
  * @version 1.0
44
  */
45
+ if (! function_exists('mycred_get_badge_references') ) :
46
+ function mycred_get_badge_references( $point_type = MYCRED_DEFAULT_TYPE_KEY, $force = false )
47
+ {
48
 
49
+ $references = mycred_get_option('mycred-badge-refs-' . $point_type);
50
+ if (! is_array($references) || empty($references) || $force ) {
51
 
52
+ global $wpdb;
53
 
54
+ $new_list = array();
55
 
56
+ // Old versions
57
+ $references = $wpdb->get_results("SELECT post_id, meta_value FROM {$wpdb->postmeta} WHERE meta_key = 'badge_requirements';");
58
+ if (! empty($references) ) {
59
+ foreach ( $references as $entry ) {
60
 
61
+ $requirement = maybe_unserialize($entry->meta_value);
62
+ if (! is_array($requirement) || empty($requirement) ) { continue;
63
+ }
64
 
65
+ if (! array_key_exists('type', $requirement) || $requirement['type'] != $point_type || $requirement['reference'] == '' ) { continue;
66
+ }
67
 
68
+ if (! array_key_exists($requirement['reference'], $new_list) ) {
69
+ $new_list[ $requirement['reference'] ] = array();
70
+ }
71
 
72
+ if (! in_array($entry->post_id, $new_list[ $requirement['reference'] ]) ) {
73
+ $new_list[ $requirement['reference'] ][] = $entry->post_id;
74
+ }
75
 
76
+ }
77
+ }
78
 
79
 
80
+ // New version (post 1.7)
81
+ $table = mycred_get_db_column('postmeta');
82
+ $references = $wpdb->get_results("SELECT post_id, meta_value FROM {$table} WHERE meta_key = 'badge_prefs';");
83
+ if (! empty($references) ) {
84
+ foreach ( $references as $entry ) {
85
 
86
+ // Manual badges should be ignored
87
+ if (absint(mycred_get_post_meta($entry->post_id, 'manual_badge', true)) === 1 ) { continue;
88
+ }
89
 
90
+ $levels = maybe_unserialize($entry->meta_value);
91
+ if (! is_array($levels) || empty($levels) ) { continue;
92
+ }
93
 
94
+ foreach ( $levels as $level => $setup ) {
95
 
96
+ if ($level > 0 ) { continue;
97
+ }
98
 
99
+ foreach ( $setup['requires'] as $requirement_row => $requirement ) {
100
 
101
+ if ($requirement['type'] != $point_type || $requirement['reference'] == '' ) { continue;
102
+ }
103
 
104
+ if (! array_key_exists($requirement['reference'], $new_list) ) {
105
+ $new_list[ $requirement['reference'] ] = array();
106
+ }
107
 
108
+ if (! in_array($entry->post_id, $new_list[ $requirement['reference'] ]) ) {
109
+ $new_list[ $requirement['reference'] ][] = $entry->post_id;
110
+ }
111
 
112
+ }
113
 
114
+ }
115
 
116
+ }
117
+ }
118
 
119
+ if (! empty($new_list) ) {
120
+ mycred_update_option('mycred-badge-references-' . $point_type, $new_list);
121
+ }
122
 
123
+ $references = $new_list;
124
 
125
+ }
126
 
127
+ return apply_filters('mycred_get_badge_references', $references, $point_type);
128
 
129
+ }
130
  endif;
131
 
132
  /**
133
  * Get Badge Requirements
134
  * Returns the badge requirements as an array.
135
+ *
136
+ * @since 1.5
137
  * @version 1.1
138
  */
139
+ if (! function_exists('mycred_get_badge_requirements') ) :
140
+ function mycred_get_badge_requirements( $badge_id = null )
141
+ {
142
 
143
+ return mycred_get_badge_levels($badge_id);
144
 
145
+ }
146
  endif;
147
 
148
  /**
149
  * Get Badge Levels
150
  * Returns an array of levels associated with a given badge.
151
+ *
152
+ * @since 1.7
153
  * @version 1.0.1
154
  */
155
+ if (! function_exists('mycred_get_badge_levels') ) :
156
+ function mycred_get_badge_levels( $badge_id )
157
+ {
158
 
159
+ $setup = mycred_get_post_meta($badge_id, 'badge_prefs', true);
160
+ if (! is_array($setup) || empty($setup) ) {
161
 
162
+ // Backwards comp.
163
+ $old_setup = mycred_get_post_meta($badge_id, 'badge_requirements', true);
164
 
165
+ // Convert old setup to new
166
+ if (is_array($old_setup) && ! empty($old_setup) ) {
167
 
168
+ $new_setup = array();
169
+ foreach ( $old_setup as $level => $requirements ) {
170
 
171
+ $level_image = mycred_get_post_meta($badge_id, 'level_image' . $level, true);
172
+ if ($level_image == '' || $level == 0 ) {
173
+ $level_image = mycred_get_post_meta($badge_id, 'main_image', true);
174
+ }
175
 
176
+ $row = array(
177
+ 'image_url' => $level_image,
178
+ 'attachment_id' => 0,
179
+ 'label' => '',
180
+ 'compare' => 'AND',
181
+ 'requires' => array(),
182
+ 'reward' => array(
183
+ 'type' => MYCRED_DEFAULT_TYPE_KEY,
184
+ 'amount' => 0,
185
+ 'log' => ''
186
+ )
187
+ );
188
 
189
+ $row['requires'][] = $requirements;
190
 
191
+ $new_setup[] = $row;
192
 
193
+ }
194
 
195
+ if (! empty($new_setup) ) {
196
 
197
+ mycred_update_post_meta($badge_id, 'badge_prefs', $new_setup);
198
+ mycred_delete_post_meta($badge_id, 'badge_requirements');
199
 
200
+ $setup = $new_setup;
201
 
202
+ }
203
 
204
+ }
205
 
206
+ }
207
 
208
+ if (empty($setup) && ! is_array($setup) ) {
209
+ $setup = array();
210
+ }
211
 
212
+ if (empty($setup) ) {
213
+ $setup[] = array(
214
+ 'image_url' => '',
215
+ 'attachment_id' => 0,
216
+ 'label' => '',
217
+ 'compare' => 'AND',
218
+ 'requires' => array(
219
+ 0 => array(
220
+ 'type' => MYCRED_DEFAULT_TYPE_KEY,
221
+ 'reference' => '',
222
+ 'amount' => '',
223
+ 'by' => ''
224
+ )
225
+ ),
226
+ 'reward' => array(
227
+ 'type' => MYCRED_DEFAULT_TYPE_KEY,
228
+ 'amount' => 0,
229
+ 'log' => ''
230
+ )
231
+ );
232
+ }
233
 
234
+ return apply_filters('mycred_badge_levels', $setup, $badge_id);
235
 
236
+ }
237
  endif;
238
 
239
  /**
240
  * Display Badge Requirements
241
  * Returns the badge requirements as a string in a readable format.
242
+ *
243
+ * @since 1.5
244
  * @version 1.2.2
245
  */
246
+ if (! function_exists('mycred_display_badge_requirement') ) :
247
+ function mycred_display_badge_requirements( $badge_id = null )
248
+ {
249
 
250
+ $badge = mycred_get_badge($badge_id);
251
+ $levels = mycred_get_badge_levels($badge_id);
252
 
253
+ if (empty($levels) ) {
254
 
255
+ $reply = '-';
256
 
257
+ }
258
+ else {
259
 
260
+ $point_types = mycred_get_types(true);
261
+ $references = mycred_get_all_references();
262
+ $req_count = count($levels[0]['requires']);
263
 
264
+ // Get the requirements for the first level
265
+ $base_requirements = array();
266
+ foreach ( $levels[0]['requires'] as $requirement_row => $requirement ) {
267
 
268
+ if ($requirement['type'] == '' ) {
269
+ $requirement['type'] = MYCRED_DEFAULT_TYPE_KEY;
270
+ }
271
 
272
+ if (! array_key_exists($requirement['type'], $point_types) ) {
273
+ continue;
274
+ }
275
 
276
+ if (! array_key_exists($requirement['reference'], $references) ) {
277
+ $reference = '-';
278
+ } else {
279
+ $reference = $references[ $requirement['reference'] ];
280
+ }
281
 
282
+ $base_requirements[ $requirement_row ] = array(
283
+ 'type' => $requirement['type'],
284
+ 'ref' => $reference,
285
+ 'amount' => $requirement['amount'],
286
+ 'by' => $requirement['by']
287
+ );
288
 
289
+ }
290
 
291
+ // Loop through each level
292
+ $output = array();
293
+ foreach ( $levels as $level => $setup ) {
294
 
295
+ $level_label = '';
296
 
297
+ if (! $badge->open_badge ) {
298
+
299
+ $level_label = '<strong>' . sprintf(__('Level %s', 'mycred'), ( $level + 1 )) . ':</strong>';
300
+ if ($levels[ $level ]['label'] != '' ) {
301
+ $level_label = '<strong>' . $levels[ $level ]['label'] . ':</strong>';
302
+ }
303
 
304
+ }
305
 
306
+ // Construct requirements to be used in an unorganized list.
307
+ $level_req = array();
308
+ foreach ( $setup['requires'] as $requirement_row => $requirement ) {
309
 
310
+ $level_value = $requirement['amount'];
311
+ $requirement = $base_requirements[ $requirement_row ];
312
 
313
+ $mycred = mycred($requirement['type']);
314
 
315
+ if ($level > 0 ) {
316
+ $requirement['amount'] = $level_value;
317
+ }
318
 
319
+ if ($requirement['by'] == 'count' ) {
320
+ $rendered_row = sprintf(_x('%s for "%s" x %d', '"Points" for "reference" x times', 'mycred'), $mycred->plural(), $requirement['ref'], $requirement['amount']);
321
+ } else {
322
+ $rendered_row = sprintf(_x('%s %s for "%s"', '"Gained/Lost" "x points" for "reference"', 'mycred'), ( ( $requirement['amount'] < 0 ) ? __('Lost', 'mycred') : __('Gained', 'mycred') ), $mycred->format_creds($requirement['amount']), $requirement['ref']);
323
+ }
324
 
325
+ $compare = _x('OR', 'Comparison of badge requirements. A OR B', 'mycred');
326
+ if ($setup['compare'] === 'AND' ) {
327
+ $compare = _x('AND', 'Comparison of badge requirements. A AND B', 'mycred');
328
+ }
329
 
330
+ if ($req_count > 1 && $requirement_row+1 < $req_count ) {
331
+ $rendered_row .= ' <span>' . $compare . '</span>';
332
+ }
333
 
334
+ $level_req[] = $rendered_row;
335
 
336
+ }
337
 
338
+ if (empty($level_req) ) { continue;
339
+ }
340
 
341
+ $output[] = $level_label . '<ul class="mycred-badge-requirement-list '. ( $badge->open_badge ? 'open_badge' : '' ) .'"><li>' . implode('</li><li>', $level_req) . '</li></ul>';
342
 
343
+ }
344
 
345
+ if ((int) mycred_get_post_meta($badge_id, 'manual_badge', true) === 1 ) {
346
+ $output[] = '<strong><small><em>' . __('This badge is manually awarded.', 'mycred') . '</em></small></strong>';
347
+ }
348
 
349
+ $reply = implode('', $output);
350
 
351
+ }
352
 
353
+ return apply_filters('mycred_badge_display_requirements', $reply, $badge_id);
354
 
355
+ }
356
  endif;
357
 
358
  /**
359
  * Count Users with Badge
360
  * Counts the number of users that has the given badge. Option to get count
361
  * of a specific level.
362
+ *
363
+ * @since 1.5
364
  * @version 1.1
365
  */
366
+ if (! function_exists('mycred_count_users_with_badge') ) :
367
+ function mycred_count_users_with_badge( $badge_id = null, $level = null )
368
+ {
369
 
370
+ $badge_id = absint($badge_id);
371
 
372
+ if ($badge_id === 0 ) { return false;
373
+ }
374
 
375
+ // Get the badge object
376
+ $badge = mycred_get_badge($badge_id);
377
 
378
+ // Most likely not a badge post ID
379
+ if ($badge === false ) { return false;
380
+ }
381
 
382
+ return $badge->get_user_count($level);
383
 
384
+ }
385
  endif;
386
 
387
  /**
388
  * Count Users without Badge
389
  * Counts the number of users that does not have a given badge.
390
+ *
391
+ * @since 1.5
392
  * @version 1.2
393
  */
394
+ if (! function_exists('mycred_count_users_without_badge') ) :
395
+ function mycred_count_users_without_badge( $badge_id = null )
396
+ {
397
 
398
+ $total = count_users();
399
+ $with_badge = mycred_count_users_with_badge($badge_id);
400
+ if ($with_badge === false ) { $with_badge = 0;
401
+ }
402
 
403
+ $without_badge = $total['total_users'] - $with_badge;
404
 
405
+ return apply_filters('mycred_count_users_without_badge', absint($without_badge), $badge_id);
406
 
407
+ }
408
  endif;
409
 
410
  /**
411
  * Reference Has Badge
412
  * Checks if a given reference has a badge associated with it.
413
+ *
414
+ * @since 1.5
415
  * @version 1.4
416
  */
417
+ if (! function_exists('mycred_ref_has_badge') ) :
418
+ function mycred_ref_has_badge( $reference = null, $point_type = MYCRED_DEFAULT_TYPE_KEY )
419
+ {
420
 
421
+ $badge_ids = array();
422
+ if ($reference === null || strlen($reference) == 0 || ! mycred_point_type_exists($point_type) ) { return $badge_ids;
423
+ }
424
 
425
+ $badge_references = mycred_get_badge_references($point_type);
426
+ $badge_references = maybe_unserialize($badge_references);
427
 
428
+ if (! empty($badge_references) && array_key_exists($reference, $badge_references) ) {
429
+ $badge_ids = $badge_references[ $reference ];
430
+ }
431
 
432
+ if (empty($badge_ids) ) {
433
+ $badge_ids = false;
434
+ }
435
 
436
+ return apply_filters('mycred_ref_has_badge', $badge_ids, $reference, $badge_references, $point_type);
437
 
438
+ }
439
  endif;
440
 
441
  /**
442
  * Badge Level Reached
443
  * Checks what level a user has earned for a badge. Returns false if badge was not earned.
444
+ *
445
+ * @since 1.7
446
  * @version 1.1
447
  */
448
+ if (! function_exists('mycred_badge_level_reached') ) :
449
+ function mycred_badge_level_reached( $user_id = null, $badge_id = null )
450
+ {
451
 
452
+ $user_id = absint($user_id);
453
+ $badge_id = absint($badge_id);
454
 
455
+ if ($user_id === 0 || $badge_id === 0 ) { return false;
456
+ }
457
 
458
+ // Get the badge object
459
+ $badge = mycred_get_badge($badge_id);
460
 
461
+ // Most likely not a badge post ID
462
+ if ($badge === false ) { return false;
463
+ }
464
 
465
+ return $badge->query_users_level($user_id);
466
 
467
+ }
468
  endif;
469
 
470
  /**
471
  * Check if User Gets Badge
472
  * Checks if a given user has earned one or multiple badges.
473
+ *
474
+ * @since 1.5
475
  * @version 1.4
476
  */
477
+ if (! function_exists('mycred_check_if_user_gets_badge') ) :
478
+ function mycred_check_if_user_gets_badge( $user_id = null, $badge_ids = array(), $depreciated = array(), $save = true )
479
+ {
480
 
481
+ $user_id = absint($user_id);
482
+ if ($user_id === 0 ) { return false;
483
+ }
484
 
485
+ $earned_badge_ids = array();
486
+ if (! empty($badge_ids) ) {
487
+ foreach ( $badge_ids as $badge_id ) {
488
 
489
+ $badge = mycred_get_badge($badge_id);
490
+ if ($badge === false ) { continue;
491
+ }
492
 
493
+ $level_reached = $badge->get_level_reached($user_id);
494
+ if ($level_reached !== false ) {
495
 
496
+ if ($save ) {
497
+ $badge->assign($user_id, $level_reached);
498
+ }
499
 
500
+ $earned_badge_ids[] = $badge_id;
501
 
502
+ }
503
 
504
+ }
505
+ }
506
 
507
+ return $earned_badge_ids;
508
 
509
+ }
510
  endif;
511
 
512
  /**
513
  * Assign Badge
514
  * Assigns a given badge to all users that fulfill the badges requirements.
515
+ *
516
+ * @since 1.7
517
  * @version 1.2
518
  */
519
+ if (! function_exists('mycred_assign_badge') ) :
520
+ function mycred_assign_badge( $badge_id = null )
521
+ {
522
 
523
+ $user_id = absint($user_id);
524
+ $badge_id = absint($badge_id);
525
 
526
+ if ($user_id === 0 || $badge_id === 0 ) { return false;
527
+ }
528
 
529
+ // Get the badge object
530
+ $badge = mycred_get_badge($badge_id);
531
 
532
+ // Most likely not a badge post ID
533
+ if ($badge === false ) { return false;
534
+ }
535
 
536
+ return $badge->assign_all();
537
 
538
+ }
539
  endif;
540
 
541
  /**
542
  * Assign Badge to User
543
+ *
544
+ * @since 1.7
545
  * @version 1.1
546
  */
547
+ if (! function_exists('mycred_assign_badge_to_user') ) :
548
+ function mycred_assign_badge_to_user( $user_id = null, $badge_id = null, $level = 0 )
549
+ {
550
 
551
+ $user_id = absint($user_id);
552
+ $badge_id = absint($badge_id);
553
+ $level = absint($level);
554
 
555
+ if ($user_id === 0 || $badge_id === 0 ) { return false;
556
+ }
557
 
558
+ // Get the badge object
559
+ $badge = mycred_get_badge($badge_id);
560
 
561
+ // Most likely not a badge post ID
562
+ if ($badge === false ) { return false;
563
+ }
564
 
565
+ return $badge->assign($user_id, $level);
566
 
567
+ }
568
  endif;
569
 
570
  /**
571
  * User Has Badge
572
  * Checks if a user has a particular badge by badge ID.
573
+ *
574
+ * @since 1.8
575
  * @version 1.0
576
  */
577
+ if (! function_exists('mycred_user_has_badge') ) :
578
+ function mycred_user_has_badge( $user_id = 0, $badge_id = null, $level_id = 0 )
579
+ {
580
 
581
+ $user_id = absint($user_id);
582
+ $badge_id = absint($badge_id);
583
+ $level_id = absint($level_id);
584
 
585
+ if ($user_id === 0 || $badge_id === 0 ) { return false;
586
+ }
587
 
588
+ global $mycred_current_account;
589
 
590
+ if (mycred_is_current_account($user_id) && isset($mycred_current_account->badge_ids) && ! empty($mycred_current_account->badge_ids) ) {
591
 
592
+ $has_badge = array_key_exists($badge_id, $mycred_current_account->badge_ids);
593
 
594
+ }
595
+ else {
596
 
597
+ // Get the badge object
598
+ $badge = mycred_get_badge($badge_id);
599
 
600
+ // Most likely not a badge post ID
601
+ if ($badge !== false ) {
602
+ $has_badge = $badge->user_has_badge($user_id, $level_id);
603
+ }
604
 
605
+ }
606
 
607
+ return $has_badge;
608
 
609
+ }
610
  endif;
611
 
612
  /**
613
  * Get Users Badge Level
614
+ *
615
+ * @since 1.8
616
  * @version 1.0
617
  */
618
+ if (! function_exists('mycred_get_users_badge_level') ) :
619
+ function mycred_get_users_badge_level( $user_id = 0, $badge_id = null )
620
+ {
621
 
622
+ $user_id = absint($user_id);
623
+ $badge_id = absint($badge_id);
624
 
625
+ if ($user_id === 0 || $badge_id === 0 ) { return false;
626
+ }
627
 
628
+ global $mycred_current_account;
629
 
630
+ if (mycred_is_current_account($user_id) && isset($mycred_current_account->badges) && ! empty($mycred_current_account->badges) && array_key_exists($badge_id, $mycred_current_account->badges) ) {
631
+ return $mycred_current_account->badges[ $badge_id ]->level_id;
632
+ }
633
 
634
+ // Get the badge object
635
+ $badge = mycred_get_badge($badge_id);
636
 
637
+ // Most likely not a badge post ID
638
+ if ($badge === false ) { return false;
639
+ }
640
 
641
+ return $badge->get_users_current_level($user_id);
642
 
643
+ }
644
  endif;
645
 
646
  /**
647
  * Get Users Badges
648
  * Returns the badge post IDs that a given user currently holds.
649
+ *
650
+ * @since 1.5
651
  * @version 1.3
652
  */
653
+ if (! function_exists('mycred_get_users_badges') ) :
654
+ function mycred_get_users_badges( $user_id = null, $force = false )
655
+ {
656
 
657
+ if ($user_id === null ) { return array();
658
+ }
659
 
660
+ global $mycred_current_account;
661
 
662
+ if (mycred_is_current_account($user_id) && isset($mycred_current_account->badge_ids) && $force == false ) {
663
+ return $mycred_current_account->badge_ids;
664
+ }
665
 
666
+ $badge_ids = mycred_get_user_meta($user_id, MYCRED_BADGE_KEY . '_ids', '', true);
667
+ if (!isset($badge_ids) || $badge_ids == '' || $force ) {
668
 
669
+ global $wpdb;
670
 
671
+ $badge_ids = array();
672
+ $query = $wpdb->get_results($wpdb->prepare("SELECT * FROM {$wpdb->usermeta} WHERE user_id = %d AND meta_key LIKE %s AND meta_key NOT LIKE '%_issued_on' AND meta_key NOT LIKE '%_ids'", $user_id, mycred_get_meta_key(MYCRED_BADGE_KEY) . '%'));
673
 
674
+ if (! empty($query) ) {
675
 
676
+ foreach ( $query as $badge ) {
677
 
678
+ $badge_id = str_replace(MYCRED_BADGE_KEY, '', $badge->meta_key);
679
+ if ($badge_id == '' ) { continue;
680
+ }
681
+
682
+ $badge_id = absint($badge_id);
683
+ if (! array_key_exists($badge_id, $badge_ids) ) {
684
+ $badge_ids[ $badge_id ] = absint($badge->meta_value);
685
+ }
686
 
687
+ }
688
 
689
+ mycred_update_user_meta($user_id, MYCRED_BADGE_KEY . '_ids', '', $badge_ids);
690
 
691
+ }
692
 
693
+ }
694
+
695
+ $clean_ids = array();
696
+ if (! empty($badge_ids) ) {
697
+ foreach ( $badge_ids as $id => $level ) {
698
 
699
+ $id = absint($id);
700
+ if ($id === 0 || strlen($level) < 1 ) { continue;
701
+ }
702
+ $clean_ids[ $id ] = absint($level);
703
 
704
+ }
705
+ }
706
 
707
+ return apply_filters('mycred_get_users_badges', $clean_ids, $user_id);
708
 
709
+ }
710
  endif;
711
 
712
  /**
713
  * Display Users Badges
714
  * Will echo all badge images a given user has earned.
715
+ *
716
+ * @since 1.5
717
  * @version 1.3.2
718
  */
719
+ if (! function_exists('mycred_display_users_badges') ) :
720
+ function mycred_display_users_badges( $user_id = null, $width = MYCRED_BADGE_WIDTH, $height = MYCRED_BADGE_HEIGHT )
721
+ {
722
 
723
+ $user_id = absint($user_id);
724
+ if ($user_id === 0 ) { return;
725
+ }
726
 
727
+ $users_badges = mycred_get_users_badges($user_id);
728
 
729
+ echo '<div class="row" id="mycred-users-badges"><div class="col-lg-12 col-md-12 col-sm-12 col-xs-12">';
730
 
731
+ do_action('mycred_before_users_badges', $user_id, $users_badges);
732
 
733
+ if (! empty($users_badges) ) {
734
 
735
+ foreach ( $users_badges as $badge_id => $level ) {
736
 
737
+ $badge = mycred_get_badge($badge_id, $level);
738
+ if ($badge === false ) { continue;
739
+ }
740
 
741
+ $badge->image_width = $width;
742
+ $badge->image_height = $height;
743
 
744
+ $badge_image = '';
745
 
746
+ if ($badge->level_image !== false ) {
747
+ $badge_image = $badge->get_image($level);
748
+ } else if($badge->main_image !== false ) {
749
+ $badge_image = $badge->get_image('main');
750
+ }
751
 
752
+ if (!empty($badge_image) ) {
753
+ echo apply_filters('mycred_the_badge', $badge_image, $badge_id, $badge, $user_id);
754
+ }
755
 
756
+ }
757
 
758
+ }
759
 
760
+ do_action('mycred_after_users_badges', $user_id, $users_badges);
761
 
762
+ echo '</div></div>';
763
 
764
+ }
765
  endif;
766
 
767
  /**
768
  * Get Badge IDs
769
  * Returns all published badge post IDs.
770
+ *
771
+ * @since 1.5
772
  * @version 1.1
773
  */
774
+ if (! function_exists('mycred_get_badge_ids') ) :
775
+ function mycred_get_badge_ids()
776
+ {
777
 
778
+ $badge_ids = wp_cache_get('badge_ids', MYCRED_SLUG);
779
+ if ($badge_ids !== false && is_array($badge_ids) ) { return $badge_ids;
780
+ }
781
 
782
+ global $wpdb;
783
 
784
+ $table = mycred_get_db_column('posts');
785
+ $badge_ids = $wpdb->get_col(
786
+ $wpdb->prepare(
787
+ "
788
  SELECT ID
789
  FROM {$table}
790
  WHERE post_type = %s
791
  AND post_status = 'publish'
792
+ ORDER BY post_date ASC;", MYCRED_BADGE_KEY
793
+ )
794
+ );
795
 
796
+ wp_cache_set('badge_ids', $badge_ids, MYCRED_SLUG);
797
 
798
+ return apply_filters('mycred_get_badge_ids', $badge_ids);
799
 
800
+ }
801
  endif;
802
 
803
  /**
804
  * Get Badges by Term ID
805
+ *
806
+ * @since 2.1
807
  * @version 1.0
808
+ * @param $term_id Pass term Id
809
  * return posts by term Id
810
  */
811
+ if(!function_exists('mycred_get_badges_by_term_id') ) :
812
+ function mycred_get_badges_by_term_id($term_id )
813
+ {
814
+ $badge_args = query_posts(
815
+ array(
816
  'post_type' => MYCRED_BADGE_KEY,
817
  'showposts' => -1,
818
  'tax_query' => array(
831
 
832
  /**
833
  * Get Badge/ Level Requirements
834
+ *
835
+ * @since 2.1
836
  * @version 1.0
837
+ * @param $badge_id Pass Badge ID
838
  */
839
+ if(!function_exists('mycred_show_badge_requirements') ) :
840
+ function mycred_show_badge_requirements( $badge_id )
841
+ {
842
 
843
  $data = array();
844
+ $levels = mycred_get_badge_levels($badge_id);
845
+ if (empty($levels) ) {
846
 
847
  $reply = '-';
848
 
857
  $base_requirements = array();
858
  foreach ($levels[0]['requires'] as $requirement_row => $requirement) {
859
 
860
+ if ($requirement['type'] == '') {
861
  $requirement['type'] = MYCRED_DEFAULT_TYPE_KEY;
862
+ }
863
 
864
+ if (!array_key_exists($requirement['type'], $point_types)) {
865
  continue;
866
+ }
867
 
868
+ if (!array_key_exists($requirement['reference'], $references)) {
869
  $reference = '-';
870
+ } else {
871
  $reference = $references[$requirement['reference']];
872
+ }
873
 
874
  $base_requirements[$requirement_row] = array(
875
  'type' => $requirement['type'],
886
  //collecting images
887
  $image = false;
888
 
889
+ if ($setup['attachment_id'] > 0 ) {
890
 
891
+ $_image = wp_get_attachment_url($setup['attachment_id']);
892
+ if (strlen($_image) > 5 ) {
893
  $output['image'] = $_image;
894
+ }
895
 
896
  }
897
  else {
898
 
899
+ if (strlen($setup['image_url']) > 5 ) {
900
  $output['image'] = $setup['image_url'];
901
+ }
902
  }
903
 
904
  $level_label = sprintf(__('Level %s', 'mycred'), ($level + 1));
905
+ if ($levels[$level]['label'] != '') {
906
  $level_label = $levels[$level]['label'];
907
+ }
908
 
909
  // Construct requirements to be used in an unorganized list.
910
  $level_req = array();
914
 
915
  $mycred = mycred($requirement['type']);
916
 
917
+ if ($level > 0) {
918
  $requirement['amount'] = $level_value;
919
+ }
920
 
921
+ if ($requirement['by'] == 'count') {
922
  $rendered_row = sprintf(_x('%s for "%s" x %d', '"Points" for "reference" x times', 'mycred'), $mycred->plural(), $requirement['ref'], $requirement['amount']);
923
+ } else {
924
  $rendered_row = sprintf(_x('%s %s for "%s"', '"Gained/Lost" "x points" for "reference"', 'mycred'), (($requirement['amount'] < 0) ? __('Lost', 'mycred') : __('Gained', 'mycred')), $mycred->format_creds($requirement['amount']), $requirement['ref']);
925
+ }
926
 
927
  $compare = _x('OR', 'Comparison of badge requirements. A OR B', 'mycred');
928
+ if ($setup['compare'] === 'AND') {
929
  $compare = _x('AND', 'Comparison of badge requirements. A AND B', 'mycred');
930
+ }
931
 
932
+ if ($req_count > 1 && $requirement_row + 1 < $req_count) {
933
  $rendered_row .= ' <span>' . $compare . '</span>';
934
+ }
935
 
936
  $level_req[] = $rendered_row;
937
 
938
  }
939
 
940
+ if (empty($level_req) ) { continue;
941
+ }
942
 
943
  $output['heading'] = $level_label;
944
  $output['requirements'] = $level_req;
945
  $output["reward_type"] = $setup["reward"]["type"];
946
  $output["amount"] = $setup["reward"]["amount"];
947
 
948
+ array_push($data, $output);
949
 
950
  }
951
 
952
+ if ((int) mycred_get_post_meta($badge_id, 'manual_badge', true) === 1 ) {
953
  $output[] = '<strong><small><em>' . __('This badge is manually awarded.', 'mycred') . '</em></small></strong>';
954
+ }
955
 
956
  return $data;
957
  }
961
 
962
  /**
963
  * Get users have have specific badge
964
+ *
965
+ * @param $badge_id Pass Badge ID
966
+ * @param int $level_id
967
+ * @return array Will return Array of User ID's have the specific Badge
968
+ * @since 2.1
969
  * @version 1.0
970
  */
971
+ if(!function_exists('mycred_get_users_has_earned_badge') ) :
972
+ function mycred_get_users_has_earned_badge( $badge_id, $level_id = 0 )
973
+ {
974
 
975
  $users_has_badge = array();
976
 
977
+ $badge_id = absint($badge_id);
978
 
979
  $args = array(
980
  'fields' => array(
983
  )
984
  );
985
 
986
+ $users = get_users($args);
987
 
988
  foreach ( $users as $user ) {
989
 
992
  $user_id = $user->ID;
993
 
994
  // Get the badge object
995
+ $badge = mycred_get_badge($badge_id);
996
 
997
  // Most likely not a badge post ID
998
+ if ($badge !== false ) {
999
+
1000
+ $current_level = mycred_get_user_meta($user_id, MYCRED_BADGE_KEY . $badge_id, '', true);
1001
 
1002
  $current_level = $current_level == '0' ? true : $current_level;
1003
 
1004
+ if ($current_level ) {
 
1005
  $has_badge = true;
1006
 
1007
+ if ((int) $current_level < absint($level_id) ) {
 
1008
  $has_badge = false;
1009
  }
1010
+ if ($has_badge ) {
1011
  $users_has_badge[] = $user_id;
1012
+ }
1013
  }
1014
  }
1015
  }
1020
 
1021
  /**
1022
  * Get Badge Types
1023
+ *
1024
+ * @since 2.1
1025
  * @version 2.1
1026
+ * @param $badge_id Pass the Badge id
1027
+ * @return array Will return all the categories
1028
  */
1029
+ if (!function_exists('mycred_get_badge_type') ) :
1030
+ function mycred_get_badge_type( $badge_id )
1031
+ {
1032
 
1033
+ $badge_terms = get_the_terms($badge_id, MYCRED_BADGE_CATEGORY, '', ', ');
1034
 
1035
+ if (is_array($badge_terms) || is_object($badge_terms)) {
1036
+ $badge_type = join(', ', wp_list_pluck($badge_terms, 'name'));
 
1037
 
1038
  return $badge_type;
1039
  }
1045
 
1046
  /**
1047
  * Get Badge Level Image Url By Passing setup of Level Requirements Use Function mycred_get_badge_requirements()
1048
+ *
1049
+ * @since 2.1
1050
  * @version 1.0
1051
+ * @param $setup
1052
+ * @return bool|false|mixed|string
1053
  */
1054
+ if(!function_exists('mycred_get_level_image_url') ) :
1055
+ function mycred_get_level_image_url( $setup )
1056
+ {
1057
 
1058
  $image = false;
1059
 
1060
+ if ($setup['attachment_id'] > 0 ) {
1061
 
1062
+ $_image = wp_get_attachment_url($setup['attachment_id']);
1063
+ if (strlen($_image) > 5 ) {
1064
  return $_image;
1065
+ }
1066
 
1067
  }
1068
  else {
1069
 
1070
+ if (strlen($setup['image_url']) > 5 ) {
1071
  return $setup['image_url'];
1072
+ }
1073
  }
1074
 
1075
  return $image;
1079
 
1080
  /**
1081
  * Cretae Evidence page
1082
+ *
1083
+ * @since 2.1
1084
  * @version 1.0
1085
  */
1086
+ if (! function_exists('mycred_get_evidence_page_id') ) :
1087
+ function mycred_get_evidence_page_id()
1088
+ {
1089
 
1090
+ $evidencePageId = 0;
1091
 
1092
+ $badges = mycred_get_addon_settings('badges');
1093
 
1094
  //If Open badge enabled
1095
+ if (isset($badges['open_badge']) && $badges['open_badge'] == '1' ) {
1096
 
1097
  $canCreatePage = true;
1098
 
1099
+ $evidence_page_refrence = mycred_get_option('open_badge_evidence_page', 0);
1100
 
1101
+ if (! empty($badges['open_badge_evidence_page']) || ! empty($evidence_page_refrence) ) {
1102
 
1103
+ $pageId = intval($evidence_page_refrence);
1104
 
1105
+ if (! empty($badges['open_badge_evidence_page']) ) {
1106
+
1107
+ $pageId = intval($badges['open_badge_evidence_page']);
1108
 
1109
+ }
1110
 
1111
+ if (get_post_status($pageId) == 'publish' ) {
1112
 
1113
  $canCreatePage = false;
1114
  $evidencePageId = $pageId;
1117
 
1118
  }
1119
 
1120
+ if ($canCreatePage ) {
1121
 
1122
  $postData = array(
1123
  'post_content' => '[' . MYCRED_SLUG . '_badge_evidence]',
1128
  'post_name' => 'Badge Evidence'
1129
  );
1130
 
1131
+ $pageId = wp_insert_post($postData);
1132
 
1133
+ $evidencePageId = intval($pageId);
1134
 
1135
+ mycred_update_option('open_badge_evidence_page', $evidencePageId);
1136
 
1137
+ mycred_set_badge_evidence_page($evidencePageId);
1138
 
1139
  }
1140
 
1147
 
1148
  /**
1149
  * Set Evidence page
1150
+ *
1151
+ * @since 2.1
1152
  * @version 1.0
1153
  */
1154
+ if (! function_exists('mycred_set_badge_evidence_page') ) :
1155
+ function mycred_set_badge_evidence_page( $page_id )
1156
+ {
1157
 
1158
+ $settings = mycred_get_option('mycred_pref_core');
1159
 
1160
+ if (isset($settings[ 'badges' ]) ) {
1161
 
1162
+ $settings[ 'badges' ][ 'open_badge_evidence_page' ] = intval($page_id);
1163
 
1164
+ mycred_update_option('mycred_pref_core', $settings);
1165
 
1166
+ }
1167
 
1168
+ }
1169
  endif;
1170
 
1171
  /**
1172
  * Get badges list
1173
+ *
1174
+ * @since 2.1.1
1175
  * @version 1.0
1176
  */
1177
+ if (! function_exists('mycred_get_uncategorized_badge_list') ) :
1178
+ function mycred_get_uncategorized_badge_list()
1179
+ {
1180
 
1181
+ $badge_list = '';
1182
 
1183
+ //Get Badges
1184
  $args = array(
1185
  'numberposts' => -1,
1186
  'post_type' => MYCRED_BADGE_KEY
1187
  );
1188
 
1189
+ $badges = get_posts($args);
1190
 
1191
  $user_id = get_current_user_id();
1192
+ $categories = get_categories($args);
1193
+ $category_count = count($categories);
1194
 
1195
  //Show Badges
1196
  foreach ( $badges as $badge ) {
1197
 
1198
+ $badge_object = mycred_get_badge($badge->ID);
1199
 
1200
  $image_url = $badge_object->main_image_url;
1201
 
1202
+ $has_earned = $badge_object->user_has_badge($user_id) ? 'earned' : 'not-earned';
1203
 
1204
+ $category = mycred_get_badge_type($badge->ID);
1205
 
1206
+ $categories = explode(',', $category);
1207
 
1208
+ $badge_list .= '<div class="mycred-badges-list-item '.$has_earned.'" data-url="'.mycred_get_permalink($badge->ID).'">';
1209
 
1210
+ if ($image_url ) {
1211
+ $badge_list .= '<img src="'.esc_url($image_url).'" alt="Badge Image">';
1212
+ }
1213
 
1214
  $badge_list .= '<div class="mycred-left">';
1215
  $badge_list .= '<h3>'.$badge->post_title.'</h3>';
1216
+ if($category_count > 0 ) {
1217
 
1218
  foreach ( $categories as $category ) {
1219
 
1220
+ if($category != '' ) {
1221
 
1222
  $badge_list .= '<sup class="mycred-sup-category">'.$category.'</sup>';
1223
 
1236
 
1237
  //mycred-badges-list-item
1238
  $badge_list .= '</div>';
1239
+
1240
  }
1241
 
1242
  return $badge_list;
1243
 
1244
+ }
1245
  endif;
1246
 
1247
  /**
1248
  * Get badges list by categories
1249
+ *
1250
+ * @since 2.1.1
1251
  * @version 1.0
1252
  */
1253
+ if (! function_exists('mycred_get_categorized_badge_list') ) :
1254
+ function mycred_get_categorized_badge_list()
1255
+ {
1256
 
1257
+ $user_id = get_current_user_id();
1258
 
1259
  $args = array(
1260
  'taxonomy' => MYCRED_BADGE_CATEGORY,
1264
  'hide_empty' => false
1265
  );
1266
 
1267
+ $categories = get_categories($args);
1268
+ $category_count = count($categories);
1269
  $badges_list_tabs = array();
1270
  $badges_list_panels = array();
1271
 
1275
 
1276
  $category_id = $category->cat_ID;
1277
  $category_name = $category->cat_name;
1278
+ $category_badges = mycred_get_badges_by_term_id($category_id);
1279
+ $badges_count = count($category_badges);
1280
 
1281
+ if ($badges_count > 0 ) {
1282
 
1283
  $badges_list_tabs[ $category_id ] = '<li data-id="' . $category_id . '" '. ( $counter == 1 ? 'class="active"' : '' ) .'>';
1284
  $badges_list_tabs[ $category_id ] .= $category_name . '<span class="mycred-badge-count">' . $badges_count . '</span>';
1290
 
1291
  $badge_id = $badge->ID;
1292
 
1293
+ $badge_object = mycred_get_badge($badge_id);
1294
 
1295
  $image_url = $badge_object->main_image_url;
1296
 
1297
+ $has_earned = $badge_object->user_has_badge($user_id) ? 'earned' : 'not-earned';
1298
 
1299
+ $badges_list_panels[ $category_id ] .= '<div class="mycred-badges-list-item '. $has_earned .'" data-url="' . mycred_get_permalink($badge_id) . '">';
1300
 
1301
+ if ($image_url ) {
1302
 
1303
+ $badges_list_panels[ $category_id ] .= '<img src="' . esc_url($image_url) . '" alt="Badge Image">';
1304
 
1305
  }
1306
 
1319
  }
1320
 
1321
  return array(
1322
+ 'tabs' => $badges_list_tabs,
1323
+ 'panels' => $badges_list_panels,
1324
+ 'category_count' => $category_count,
1325
  );
1326
 
1327
+ }
1328
  endif;
1329
 
1330
  /**
1331
  * Returns Badge congratulation message.
1332
+ *
1333
+ * @since 2.2
1334
  * @version 1.0
1335
  */
1336
+ if (! function_exists('mycred_badge_show_congratulation_msg') ) :
1337
+ function mycred_badge_show_congratulation_msg( $user_id, $badge, $settings = null )
1338
+ {
1339
 
1340
+ $content = '';
1341
 
1342
+ if (empty($settings) ) { $settings = mycred();
1343
+ }
1344
 
1345
+ if(! empty($settings->core["badges"]["show_congo_text"]) && $badge->user_has_badge($user_id) && ! empty($badge->congratulation_msg) ) {
1346
 
1347
+ $content .= '<div class="mycred-badge-congratulation-msg">' . $badge->congratulation_msg . '</div>';
1348
+
1349
+ }
1350
 
1351
+ return apply_filters('mycred_badge_show_congratulation_msg', $content, $badge, $settings);
1352
 
1353
+ }
1354
  endif;
1355
 
1356
  /**
1357
  * Returns Badge main image with share icons.
1358
+ *
1359
+ * @since 2.2
1360
  * @version 1.0
1361
  */
1362
+ if (! function_exists('mycred_badge_show_main_image_with_social_icons') ) :
1363
+ function mycred_badge_show_main_image_with_social_icons( $user_id, $badge, $mycred = null )
1364
+ {
1365
 
1366
+ $content = '';
1367
 
1368
+ $image_url = $badge->get_earned_image($user_id);
1369
 
1370
+ if (! empty($image_url) ) {
1371
 
1372
+ $content .= '<div class="mycred-badge-image-wrapper">';
1373
 
1374
+ $content .= '<img src="' . $image_url . '" class="mycred-badge-image" alt="Badge Image">';
1375
 
1376
+ if (empty($mycred) ) { $mycred = mycred();
1377
+ }
1378
 
1379
+ //If user has earned badge, show user sharing badge option
1380
+ if($badge->user_has_badge($user_id)
1381
+ && ! empty($mycred->core["br_social_share"]["enable_open_badge_ss"])
 
1382
  ) {
1383
 
1384
  $facebook_url = "http://www.facebook.com/sharer.php?u=".get_permalink()."&p[images][0]=$image_url";
1386
  $linkedin_url = "http://www.linkedin.com/shareArticle?url=".get_permalink()."";
1387
  $pinterest_url = "https://pinterest.com/pin/create/bookmarklet/?media=$image_url&amp;url=".get_permalink()."";
1388
 
1389
+ $content .= mycred_br_get_social_icons($facebook_url, $twitter_url, $linkedin_url, $pinterest_url);
1390
 
1391
  }
1392
 
1393
  $content .= '</div>';
1394
+
1395
+ }
1396
 
1397
+ return apply_filters('mycred_badge_show_main_image_with_social_icons', $content, $badge, $mycred);
1398
 
1399
+ }
1400
  endif;
1401
 
1402
  /**
1403
  * Returns Badge description.
1404
+ *
1405
+ * @since 2.2
1406
  * @version 1.0
1407
  */
1408
+ if (! function_exists('mycred_badge_show_description') ) :
1409
+ function mycred_badge_show_description( $post, $settings = null )
1410
+ {
1411
 
1412
+ $content = '';
1413
 
1414
+ if (empty($settings) ) { $settings = mycred();
1415
+ }
1416
 
1417
+ if(! empty($settings->core["badges"]["show_level_description"]) && ! empty($post->post_content) ) {
1418
 
1419
+ $content .= "<h3>" . __("Description", "mycred") . "</h3>";
1420
  $content .= "<p>" . $post->post_content . "</p>";
1421
+
1422
+ }
1423
 
1424
+ return apply_filters('mycred_badge_show_description', $content, $post, $settings);
1425
 
1426
+ }
1427
  endif;
1428
 
1429
  /**
1430
  * Returns Badge levels.
1431
+ *
1432
+ * @since 2.2
1433
  * @version 1.0
1434
  */
1435
+ if (! function_exists('mycred_badge_show_levels') ) :
1436
+ function mycred_badge_show_levels( $user_id, $badge, $settings = null )
1437
+ {
1438
 
1439
+ $content = '';
1440
 
1441
+ if (empty($settings) ) { $settings = mycred();
1442
+ }
1443
 
1444
+ if(! empty($settings->core["badges"]["show_levels"]) || $badge->open_badge && ! empty($settings->core["badges"]["show_steps_to_achieve"]) ) {
1445
 
1446
+ if (! $badge->open_badge ) {
1447
  $content .= "<h3>" . __("Levels", "mycred") . "</h3>";
1448
+ } else {
1449
  $content .= "<h3>" . __("Requirement", "mycred") . "</h3>";
1450
+ }
1451
 
1452
+ $levels = mycred_show_badge_requirements($badge->post_id);
1453
 
1454
  foreach ( $levels as $id => $level ) {
1455
 
1456
+ $level_image_url = $level["image"];
1457
 
1458
+ $heading = $level["heading"];
1459
 
1460
+ $requirements = $level["requirements"];
1461
 
1462
+ $reward = $level["amount"];
1463
 
1464
+ $content .= '<div class="mycred-badge-page-level">';
1465
 
1466
+ if (! $badge->open_badge ) {
1467
 
1468
+ if (! empty($level_image_url) ) {
1469
+ $content .= '<img src="'.$level_image_url.'" class="mycred-level-image mycred-float-left" />';
1470
+ }
1471
 
1472
+ $content .= "<h4>$heading</h4>";
1473
+ }
1474
 
1475
+ $content .= "<div class='clear'></div>";
1476
 
1477
+ if (! empty($settings->core["badges"]["show_steps_to_achieve"]) ) {
1478
+ $content .= mycred_badge_level_req_check($badge->post_id, $id);
1479
+ }
1480
 
1481
+ if (! empty($settings->core["badges"]["show_level_points"]) && $reward != 0 ) {
1482
 
1483
+ $reward_type = mycred($level['reward_type']);
1484
 
1485
+ $content .= '<div class="mycred-level-reward">' . __('Reward:', 'mycred') . ' ' . $reward_type->format_creds($reward) .'</div>';
1486
+ }
1487
 
1488
+ $content .= '</div>';
1489
+ }
1490
 
1491
+ $content .= '<div class="clear"></div>';
1492
+
1493
+ }
1494
 
1495
+ return apply_filters('mycred_badge_show_levels', $content, $user_id, $badge, $settings);
1496
 
1497
+ }
1498
  endif;
1499
 
1500
  /**
1501
  * Returns badge earners.
1502
+ *
1503
+ * @since 2.2
1504
  * @version 1.0
1505
  */
1506
+ if (! function_exists('mycred_badge_show_earners') ) :
1507
+ function mycred_badge_show_earners( $badge, $settings = null )
1508
+ {
1509
 
1510
+ $content = '';
1511
 
1512
+ if (empty($settings) ) { $settings = mycred();
1513
+ }
1514
 
1515
+ if (! empty($settings->core["badges"]["show_earners"]) ) {
1516
 
1517
+ $args = array(
1518
+ 'meta_query' => array(
1519
+ array(
1520
+ 'key' => MYCRED_BADGE_KEY . $badge->post_id,
1521
+ 'compare' => 'EXISTS'
1522
+ )
1523
+ )
1524
+ );
1525
+ $users_have_badge = get_users($args);
1526
 
1527
+ if (! empty($users_have_badge) ) {
1528
+
1529
+ $content .= '<div class="mycred-badge-earners">';
1530
+ $content .= "<h3>" . __("Earners", "mycred") . "</h3>";
1531
  $content .= '<div class="mycred-badge-earner-list">';
1532
 
1533
+ foreach ( $users_have_badge as $user ) {
1534
 
1535
+ $user_avatar = get_avatar_url($user->ID);
1536
 
1537
+ $content .= '<div class="mycred-badge-earner-grid mycred-float-left">';
1538
+ $content .= '<div><img src="' . $user_avatar . '" /></div>';
1539
+ $content .= "<h4>$user->display_name</h4>";
1540
+ $content .= '</div>';
1541
 
1542
+ }
1543
+ $content .= '<div class="mycred-clearfix"></div>';
1544
+ $content .= '</div>';
1545
  $content .= '</div>';
 
1546
 
1547
+ }
1548
+
1549
+ }
1550
 
1551
+ return apply_filters('mycred_badge_show_earners', $content, $badge, $settings);
1552
 
1553
+ }
1554
+ endif;
addons/badges/includes/mycred-badge-object.php CHANGED
@@ -1,822 +1,911 @@
1
  <?php
2
- if ( ! defined( 'myCRED_VERSION' ) ) exit;
 
3
 
4
  /**
5
  * myCRED_Badge class
6
- * @see http://codex.mycred.me/classes/mycred_badge/
7
- * @since 1.7
 
8
  * @version 1.1
9
  */
10
- if ( ! class_exists( 'myCRED_Badge' ) ) :
11
- class myCRED_Badge extends myCRED_Object {
 
12
 
13
- public $post_id = false;
14
 
15
- public $title = '';
16
- public $earnedby = 0;
17
- public $manual = false;
18
- public $open_badge = false;
19
 
20
- public $levels = array();
21
- public $main_image = false;
22
 
23
- public $level = false;
24
- public $level_id = false;
25
- public $level_label = false;
26
- public $level_image = false;
27
 
28
- public $image_width = false;
29
- public $image_height = false;
30
 
31
- public $references = array();
32
- public $point_types = array();
33
- protected $user_meta_key = '';
34
 
35
- public $user_id = false;
36
- public $current_level = false;
37
 
38
- public $main_image_url = false;
39
- public $congratulation_msg = '';
40
- public $align = 'mycred_align_left';
41
- public $layout = 'mycred_layout_left';
42
 
43
- /**
44
- * Construct
45
- */
46
- function __construct( $object = NULL, $level_id = NULL ) {
 
47
 
48
- parent::__construct();
49
 
50
- if ( is_object( $object ) && isset( $object->post_type ) && $object->post_type == MYCRED_BADGE_KEY )
51
- $this->post_id = $object->ID;
52
 
53
- elseif ( is_numeric( $object ) && mycred_get_post_type( $object ) == MYCRED_BADGE_KEY )
54
- $this->post_id = absint( $object );
55
 
56
- else return false;
 
57
 
58
- $this->image_width = MYCRED_BADGE_WIDTH;
59
- $this->image_height = MYCRED_BADGE_HEIGHT;
60
 
61
- $this->user_meta_key = MYCRED_BADGE_KEY . $this->post_id;
62
 
63
- if ( $level_id !== NULL ) $this->level_id = absint( $level_id );
 
64
 
65
- $this->populate( $object, $level_id );
66
 
67
- }
68
 
69
- /**
70
- * Populate
71
- * @since 1.0
72
- * @version 1.0
73
- */
74
- protected function populate( $object = NULL, $level_id = NULL ) {
 
 
75
 
76
- if ( $this->post_id === false ) return;
 
77
 
78
- // Get base badge details
79
- $this->title = ( isset( $object->post_title ) ) ? $object->post_title : mycred_get_the_title( $this->post_id );
80
- $this->earnedby = ( isset( $object->earnedby ) ) ? $object->earnedby : $this->get_user_count( $level_id );
81
- $this->levels = ( isset( $object->levels ) ) ? $object->levels : mycred_get_badge_levels( $this->post_id );
82
 
83
- if ( ! empty( $this->levels ) ) {
84
 
85
- $this->references = array();
86
- $this->point_types = array();
87
- $this->compare = $this->levels[0]['compare'];
88
 
89
- if ( ! empty( $this->levels[0]['requires'] ) ) {
90
- foreach ( $this->levels[0]['requires'] as $requirement_id => $req ) {
91
 
92
- if ( $req['reference'] != '' && ! in_array( $req['reference'], $this->references ) )
93
- $this->references[] = $req['reference'];
 
94
 
95
- if ( $req['type'] != '' && ! in_array( $req['type'], $this->point_types ) )
96
- $this->point_types[] = $req['type'];
 
97
 
98
- }
99
- }
100
 
101
- }
102
 
103
- // Indicate manual badge
104
- if ( absint( mycred_get_post_meta( $this->post_id, 'manual_badge', true ) ) === 1 )
105
- $this->manual = true;
 
106
 
107
- // Indicate open badge
108
- if ( absint( mycred_get_post_meta( $this->post_id, 'open_badge', true ) ) === 1 ) {
109
 
110
- $badge_setting = mycred_get_addon_settings( 'badges' );
111
 
112
- if ( isset( $badge_setting['open_badge'] ) && $badge_setting['open_badge'] === 1 ) {
113
-
114
- $this->open_badge = true;
115
 
116
- }
117
-
118
- }
119
 
120
- // If we requested a particular level
121
- if ( $level_id !== NULL )
122
- $this->level = $this->get_level( $level_id );
 
123
 
124
- // Get images
125
- $this->main_image = $this->get_image( 'main' );
126
- $this->main_image_url = $this->get_image_url( 'main' );
127
- $this->level_image = $this->get_image( $level_id );
128
- $this->congratulation_msg = mycred_get_post_meta( $this->post_id, 'congratulation_msg', true );
129
- $this->align = mycred_get_post_meta( $this->post_id, 'mycred_badge_align', true );
130
- $this->layout = mycred_get_post_meta( $this->post_id, 'mycred_layout_check', true );
131
 
132
- }
133
 
134
- /**
135
- * Get User Count
136
- * @since 1.0
137
- * @version 1.0
138
- */
139
- public function get_user_count( $level_id = NULL ) {
 
 
140
 
141
- if ( $this->post_id === false ) return 0;
 
142
 
143
- $count = mycred_get_post_meta( $this->post_id, 'total-users-with-badge', true );
144
- if ( $count == '' || $level_id !== NULL ) {
145
 
146
- global $wpdb;
147
 
148
- $level_filter = ( $level_id !== NULL && is_numeric( $level_id ) ) ? $wpdb->prepare( "AND meta_value = %s", $level_id ) : '';
149
 
150
- $count = $wpdb->get_var( $wpdb->prepare( "SELECT COUNT( DISTINCT user_id ) FROM {$wpdb->usermeta} WHERE meta_key = %s {$level_filter};", mycred_get_meta_key( $this->user_meta_key ) ) );
151
- if ( $count === NULL ) $count = 0;
 
152
 
153
- if ( $level_id === NULL )
154
- mycred_update_post_meta( $this->post_id, 'total-users-with-badge', $count, true );
 
155
 
156
- }
157
 
158
- return apply_filters( 'mycred_count_users_with_badge', absint( $count ), $this->post_id );
159
 
160
- }
161
 
162
- /**
163
- * Get Level
164
- * @since 1.0
165
- * @version 1.0
166
- */
167
- public function get_level( $level_id = false ) {
 
 
168
 
169
- if ( $level_id === false || empty( $this->levels ) || ! array_key_exists( $level_id, $this->levels ) ) return false;
 
170
 
171
- return $this->levels[ $level_id ];
172
 
173
- }
174
 
175
- /**
176
- * Get Level Requirements
177
- * @since 1.0
178
- * @version 1.0
179
- */
180
- public function get_level_requirements( $level_id = false ) {
 
 
181
 
182
- if ( $level_id === false || empty( $this->levels ) || ! array_key_exists( $level_id, $this->levels ) ) return false;
 
183
 
184
- return $this->levels[ $level_id ]['requires'];
185
 
186
- }
187
 
188
- /**
189
- * Get Level Reward
190
- * @since 1.0
191
- * @version 1.0
192
- */
193
- public function get_level_reward( $level_id = false ) {
 
 
194
 
195
- if ( $level_id === false || empty( $this->levels ) || ! array_key_exists( $level_id, $this->levels ) ) return false;
 
196
 
197
- return $this->levels[ $level_id ]['reward'];
198
 
199
- }
200
 
201
- /**
202
- * User Has Badge
203
- * @since 1.0
204
- * @version 1.0
205
- */
206
- public function user_has_badge( $user_id = false, $level_id = 0 ) {
 
 
207
 
208
- $has_badge = false;
209
- if ( $user_id === false ) return $has_badge;
 
210
 
211
- $this->user_id = absint( $user_id );
212
- $this->current_level = $this->get_users_current_level( $user_id );
213
 
214
- if ( $this->current_level !== false ) {
215
 
216
- $has_badge = true;
217
 
218
- if ( (int) $this->current_level < absint( $level_id ) )
219
- $has_badge = false;
 
220
 
221
- }
222
 
223
- return apply_filters( 'mycred_user_has_badge', $has_badge, $user_id, $this->post_id, $level_id, $this->current_level );
224
 
225
- }
226
 
227
- /**
228
- * Get Users Current Level
229
- * @since 1.0
230
- * @version 1.0
231
- */
232
- public function get_users_current_level( $user_id = false ) {
 
 
233
 
234
- if ( $user_id === false ) return $has_badge;
 
235
 
236
- global $mycred_current_account;
237
 
238
- $user_id = absint( $user_id );
239
 
240
- if ( mycred_is_current_account( $user_id ) && isset( $mycred_current_account->badge_ids ) && ! empty( $mycred_current_account->badge_ids ) && array_key_exists( $this->post_id, $mycred_current_account->badge_ids ) )
241
- return absint( $mycred_current_account->badge_ids[ $this->post_id ] );
 
242
 
243
- $current_level = mycred_get_user_meta( $user_id, $this->user_meta_key, '', true );
244
- $current_level = ( ! empty( $current_level ) || $current_level === '0' ) ? absint( $current_level ) : false;
245
 
246
- return $current_level;
247
 
248
- }
249
 
250
- /**
251
- * Get Level Reached
252
- * @since 1.0
253
- * @version 1.0
254
- */
255
- public function query_users_level( $user_id = false ) {
 
 
256
 
257
- if ( $user_id === false || empty( $this->levels ) ) return false;
 
258
 
259
- global $wpdb, $mycred_log_table;
260
 
261
- $base_requirements = $this->levels[0]['requires'];
262
- $compare = $this->levels[0]['compare'];
263
- $requirements = count( $base_requirements );
264
- $level_reached = false;
265
- $results = array();
266
 
267
- // Based on the base requirements, we first get the users log entry results
268
- if ( ! empty( $base_requirements ) ) {
269
- foreach ( $base_requirements as $requirement_id => $requirement ) {
270
 
271
- if ( $requirement['type'] == '' )
272
- $requirement['type'] = MYCRED_DEFAULT_TYPE_KEY;
 
273
 
274
- $mycred = mycred( $requirement['type'] );
275
- if ( $mycred->exclude_user( $user_id ) ) continue;
 
276
 
277
- $having = 'COUNT(*)';
278
- if ( $requirement['by'] != 'count' )
279
- $having = 'SUM(creds)';
 
280
 
281
- $query = $wpdb->get_var( $wpdb->prepare( "SELECT {$having} FROM {$mycred_log_table} WHERE ctype = %s AND ref = %s AND user_id = %d;", $requirement['type'], $requirement['reference'], $user_id ) );
282
 
283
- $query = apply_filters( 'mycred_badge_requirement', $query, $requirement_id, $requirement, $having, $user_id );
284
 
285
- if ( $query === NULL ) $query = 0;
 
286
 
287
- $results[ $requirement['reference'] ] = $query;
288
 
289
- }
290
- }
291
 
292
- // Next we loop through the levels and see compare the previous results to the requirements to determan our level
293
- foreach ( $this->levels as $level_id => $level_setup ) {
294
 
295
- $reqs_met = 0;
296
- foreach ( $level_setup['requires'] as $requirement_id => $requirement ) {
297
 
298
- if ( $results[ $requirement['reference'] ] >= $requirement['amount'] )
299
- $reqs_met++;
 
300
 
301
- }
302
 
303
- if ( $compare === 'AND' && $reqs_met >= $requirements )
304
- $level_reached = $level_id;
305
 
306
- elseif ( $compare === 'OR' && $reqs_met > 0 )
307
- $level_reached = $level_id;
 
308
 
309
- }
310
 
311
- do_action( 'mycred_badge_level_reached', $user_id, $this->post_id, $level_reached );
312
 
313
- return $level_reached;
314
 
315
- }
316
 
317
- /**
318
- * Get Users Next Level ID
319
- * @since 1.0
320
- * @version 1.0
321
- */
322
- public function get_users_next_level_id( $user_id = false ) {
 
 
323
 
324
- if ( ! $this->user_has_badge( $user_id ) )
325
- return 0;
 
326
 
327
- $max_level = count( $this->levels );
328
- if ( $this->current_level >= $max_level )
329
- return $max_level;
 
330
 
331
- return $this->current_level;
332
 
333
- }
334
 
335
- /**
336
- * Get Users Next Level
337
- * @since 1.0
338
- * @version 1.0
339
- */
340
- public function get_users_next_level( $user_id = false ) {
 
 
341
 
342
- if ( ! $this->user_has_badge( $user_id ) )
343
- return false;
 
344
 
345
- $next_level_id = $this->get_users_next_level_id( $user_id );
346
 
347
- return $this->get_level( $next_level_id );
348
 
349
- }
350
 
351
- /**
352
- * Assign Badge to User
353
- * @since 1.0
354
- * @since 2.3 Added functions `mycred_update_user_meta`, `mycred_get_user_meta` with `mycred_badge_ids`
355
- * @version 1.0
356
- */
357
- public function assign( $user_id = false, $level_id = 0 ) {
 
 
358
 
359
- if ( $user_id === false || absint( $user_id ) === 0 ) return false;
 
360
 
361
- $previous_level = -1;
362
- $new_level = $level_id;
363
 
364
- if ( $this->user_has_badge( $user_id ) ) {
365
 
366
- // Right now we can not earn the same badge over and over again
367
- // Planing on adding in an option to override this
368
- if ( $this->current_level == $level_id ) return true;
 
369
 
370
- $previous_level = $this->current_level;
371
 
372
- }
373
 
374
- else {
375
- $this->user_id = $user_id;
376
- $this->current_level = $new_level;
377
- }
378
 
379
- $execute = apply_filters( 'mycred_badge_assign', true, $user_id, $new_level, $this );
380
 
381
- if ( $execute ) {
382
-
383
- $new_level = apply_filters( 'mycred_badge_user_value', $new_level, $user_id, $this->post_id );
384
 
385
- mycred_update_user_meta( $user_id, $this->user_meta_key, '', $new_level );
386
- mycred_update_user_meta( $user_id, $this->user_meta_key, '_issued_on', time() );
387
-
388
- $badge_ids = mycred_get_user_meta( $user_id, 'mycred_badge_ids', '', true );
389
-
390
- if ( ! empty( $badge_ids ) && is_array( $badge_ids ) )
391
- $badge_ids[ $this->post_id ] = 0;
392
- else
393
- $badge_ids = array( $this->post_id => 0 );
394
-
395
- mycred_update_user_meta( $user_id, 'mycred_badge_ids', '', $badge_ids );
 
396
 
397
- // Need to update counter with new assignments
398
- if ( $new_level == 0 ) {
399
 
400
- $this->earnedby ++;
401
 
402
- mycred_update_post_meta( $this->post_id, 'total-users-with-badge', $this->earnedby );
403
 
404
- }
405
 
406
- $this->payout_reward( $previous_level, $new_level );
407
-
408
- do_action( 'mycred_after_badge_assign', $user_id, $this->post_id, $new_level );
409
 
410
- }
411
 
412
- return true;
413
 
414
- }
415
 
416
- /**
417
- * Payout Rewards
418
- * @since 1.0
419
- * @version 1.0
420
- */
421
- public function payout_reward( $previous_level = -1, $new_level = 0 ) {
 
 
422
 
423
- // Earning the badge
424
- if ( $previous_level < 0 && $new_level == 0 ) {
425
 
426
- $reward = $this->get_level_reward( $new_level );
427
- if ( $reward !== false && ( $reward['log'] == '' || $reward['amount'] == 0 ) ) return false;
 
428
 
429
- $mycred = mycred( $reward['type'] );
430
 
431
- // Make sure we only get points once for each level we reach for each badge
432
- if ( ! $mycred->has_entry( 'badge_reward', $this->post_id, $this->user_id, 0, $reward['type'] ) ) {
433
 
434
- $exec = apply_filters( 'customize_mycred_badge_condition', true, $this->post_id, $this->user_id, $reward['type']);
435
 
436
- if( $exec ) {
437
 
438
- $mycred->add_creds(
439
- 'badge_reward',
440
- $this->user_id,
441
- $reward['amount'],
442
- $reward['log'],
443
- $this->post_id,
444
- 0,
445
- $reward['type']
446
- );
447
 
448
- do_action( 'mycred_badge_rewardes', $this->user_id, $previous_level, $new_level, $reward, $this );
449
 
450
- }
451
 
452
- }
453
 
454
- }
455
 
456
- // Earning a new level as well
457
- else {
458
 
459
- // Loop through levels to make sure we do not miss rewards if we jump more than one level
460
- for ( $i = $previous_level; $i <= $new_level; $i++ ) {
461
 
462
- $reward = $this->get_level_reward( $i );
463
- if ( $reward !== false && ( $reward['log'] == '' || $reward['amount'] == 0 ) ) continue;
 
464
 
465
- $mycred = mycred( $reward['type'] );
466
 
467
- // Make sure we only get points once for each level we reach for each badge
468
- if ( ! $mycred->has_entry( 'badge_reward', $this->post_id, $this->user_id, $i, $reward['type'] ) ) {
469
 
470
- $exec = apply_filters( 'customize_mycred_badge_condition', true, $this->post_id, $this->user_id, $reward['type']);
471
 
472
- if( $exec ) {
473
 
474
- $mycred->add_creds(
475
- 'badge_reward',
476
- $this->user_id,
477
- $reward['amount'],
478
- $reward['log'],
479
- $this->post_id,
480
- $i,
481
- $reward['type']
482
- );
483
 
484
- do_action( 'mycred_badge_rewardes', $this->user_id, $previous_level, $new_level, $reward, $this );
485
 
486
- }
487
 
488
- }
489
 
490
- }
491
 
492
- }
493
 
494
- return true;
495
 
496
- }
497
 
498
- /**
499
- * Assign Badge to All
500
- * @since 1.0
501
- * @version 1.0
502
- */
503
- public function assign_all() {
 
 
504
 
505
- if ( $this->post_id === false || empty( $this->levels ) ) return false;
 
506
 
507
- global $wpdb, $mycred_log_table;
508
 
509
- $results = array();
510
 
511
- // Need to have some requirements set or we are in trouble
512
- if ( ! empty( $this->levels[0]['requires'] ) ) {
513
 
514
- // Single requirement
515
- if ( count( $this->levels[0]['requires'] ) == 1 ) {
516
 
517
- $requirement = $this->levels[0]['requires'][0];
518
- $having = ( $requirement['by'] != 'count' ) ? 'SUM( creds )' : 'COUNT( id )';
519
- $requirement['type'] = ( $requirement['type'] == '' ) ? MYCRED_DEFAULT_TYPE_KEY : $requirement['type'];
520
 
521
- $results = $wpdb->get_results( $wpdb->prepare( "SELECT DISTINCT user_id, {$having} as total FROM {$mycred_log_table} WHERE ctype = %s AND ref = %s GROUP BY user_id HAVING {$having} >= %f;", $requirement['type'], $requirement['reference'], $requirement['amount'] ) );
522
 
523
- // Find the level id for each result based on their total
524
- if ( ! empty( $results ) ) {
525
- foreach ( $results as $row ) {
526
 
527
- $badge_level_id = 0;
528
 
529
- foreach ( $this->levels as $level_id => $setup ) {
530
- if ( $row->total >= $setup['requires'][0]['amount'] )
531
- $badge_level_id = $level_id;
532
- }
 
533
 
534
- $row->level_id = $badge_level_id;
535
 
536
- }
537
- }
538
 
539
- }
540
 
541
- // Multiple requirements
542
- else {
543
 
544
- $user_ids = array();
545
 
546
- $requirements = count( $this->levels[0]['requires'] );
547
- $compare = $this->levels[0]['compare'];
548
 
549
- // I feel like there must be a better way of doing this
550
- // If you have a suggestion for how to query all users based on multiple requirements, let me know!
551
- foreach ( $this->levels as $level_id => $level_setup ) {
552
 
553
- $level_user_ids = array();
554
 
555
- // Get all user IDs that fulfill each requirements set
556
- if ( ! empty( $level_setup['requires'] ) ) {
557
- foreach ( $level_setup['requires'] as $requirement_id => $requirement ) {
558
 
559
- $having = ( $requirement['by'] != 'count' ) ? 'SUM( creds )' : 'COUNT( id )';
560
- $requirement['type'] = ( $requirement['type'] == '' ) ? MYCRED_DEFAULT_TYPE_KEY : $requirement['type'];
561
 
562
- $level_user_ids[ $requirement_id ] = $wpdb->get_col( $wpdb->prepare( "SELECT DISTINCT user_id FROM {$mycred_log_table} WHERE ctype = %s AND ref = %s GROUP BY user_id HAVING {$having} >= %f;", $requirement['type'], $requirement['reference'], $requirement['amount'] ) );
563
 
564
- }
565
- }
566
 
567
- // OR = get all unique IDs
568
- if ( $compare == 'OR' ) {
569
 
570
- $list = array();
571
- foreach ( $level_user_ids as $requirement_id => $list_of_ids ) {
572
- if ( ! empty( $list_of_ids ) ) {
573
- foreach ( $list_of_ids as $uid ) {
574
- if ( ! in_array( $uid, $list ) )
575
- $list[] = $uid;
576
- }
577
- }
578
- }
 
579
 
580
- }
581
 
582
- // AND = get IDs that are in all requirements
583
- else {
584
 
585
- $list = $_list = array();
586
 
587
- foreach ( $level_user_ids as $requirement_id => $list_of_ids ) {
588
- if ( ! empty( $list_of_ids ) ) {
589
- foreach ( $list_of_ids as $uid ) {
590
- if ( ! array_key_exists( $uid, $_list ) )
591
- $_list[ $uid ] = 1;
592
- else
593
- $_list[ $uid ]++;
594
- }
595
- }
596
- }
 
597
 
598
- foreach ( $_list as $uid => $count ) {
599
- if ( $count >= $requirements )
600
- $list[] = $uid;
601
- }
 
602
 
603
- }
604
 
605
- // If no user has reached the first level, no one will have reached higher levels and there is no need to continue
606
- if ( $level_id == 0 && empty( $list ) ) break;
 
607
 
608
- // Create a list where the array key represents the user ID and the array value represents the badge level reached by the user
609
- foreach ( $list as $user_id ) {
610
- $user_ids[ $user_id ] = $level_id;
611
- }
612
 
613
- }
614
 
615
- if ( ! empty( $user_ids ) ) {
616
- foreach ( $user_ids as $user_id => $level_reached ) {
617
 
618
- $row = new StdClass();
619
- $row->user_id = $user_id;
620
- $row->level_id = $level_reached;
621
 
622
- $results[] = $row;
623
 
624
- }
625
- }
626
 
627
- }
628
-
629
- // Assign results
630
- if ( ! empty( $results ) ) {
631
 
632
- // Assign each user
633
- foreach ( $results as $row )
634
- mycred_update_user_meta( $row->user_id, $this->user_meta_key, '', $row->level_id );
 
635
 
636
- // Update earned count
637
- $this->earnedby = count( $results );
638
 
639
- mycred_update_post_meta( $this->post_id, 'total-users-with-badge', $this->earnedby );
640
 
641
- //Updating issued_on
642
- mycred_update_user_meta( $row->user_id, $this->user_meta_key, '_issued_on', time() );
643
 
644
- }
645
 
646
- }
647
 
648
- return count( $results );
649
 
650
- }
651
 
652
- /**
653
- * Divest Badge from user
654
- * @since 1.0
655
- * @since 2.3 Added functions `mycred_update_user_meta` with `mycred_badge_ids`
656
- * @version 1.0
657
- */
658
- public function divest( $user_id = false ) {
 
 
659
 
660
- if ( $user_id === false || absint( $user_id ) === 0 ) return false;
 
661
 
662
- mycred_delete_user_meta( $user_id, $this->user_meta_key );
663
- mycred_delete_user_meta( $user_id, $this->user_meta_key . '_issued_on' );
664
- $usermeta = mycred_get_user_meta( $user_id, 'mycred_badge_ids', '', true );
665
 
666
- if ( isset( $usermeta[$this->post_id] ) )
667
- unset( $usermeta[$this->post_id] );
 
668
 
669
- $this->earnedby --;
670
- if ( $this->earnedby < 0 ) $this->earnedby = 0;
 
671
 
672
- mycred_update_post_meta( $this->post_id, 'total-users-with-badge', $this->earnedby );
673
- mycred_update_user_meta( $user_id, 'mycred_badge_ids', '', $usermeta );
674
 
675
- return true;
676
 
677
- }
678
 
679
- /**
680
- * Divest Badge from Everyone
681
- * @since 1.0
682
- * @version 1.0
683
- */
684
- public function divest_all() {
 
 
685
 
686
- if ( $this->post_id === false ) return false;
 
687
 
688
- global $wpdb;
689
 
690
- // Delete connections
691
- $count = $wpdb->delete(
692
- $wpdb->usermeta,
693
- array( 'meta_key' => mycred_get_meta_key( $this->user_meta_key ) ),
694
- array( '%s' )
695
- );
696
 
697
- $this->earnedby = 0;
698
 
699
- mycred_update_post_meta( $this->post_id, 'total-users-with-badge', $this->earnedby );
700
 
701
- return $count;
702
 
703
- }
704
 
705
- /**
706
- * Delete Badge
707
- * @since 1.0
708
- * @version 1.0
709
- */
710
- public function delete( $delete_post = false ) {
 
 
711
 
712
- if ( $this->post_id === false ) return false;
 
713
 
714
- $this->divest_all();
715
 
716
- if ( ! empty( $this->point_types ) ) {
717
 
718
- foreach ( $this->point_types as $point_type )
719
- mycred_delete_option( 'mycred-badge-references-' . $point_type );
 
720
 
721
- }
722
 
723
- if ( $delete_post )
724
- mycred_delete_post( $this->post_id, true );
 
725
 
726
- return true;
727
 
728
- }
729
 
730
- /**
731
- * Get Badge Image
732
- * @since 1.0
733
- * @version 1.1
734
- */
735
- public function get_image( $image = NULL ) {
 
 
736
 
737
- $image_identification = false;
738
 
739
- $level = 'none';
740
- if ( $image != 'main' && is_numeric( $image ) ) {
741
 
742
- $level = $image;
743
 
744
- }
745
 
746
- $image_url = $this->get_image_url( $image );
747
 
748
- $image_width = ( $this->image_width !== false ) ? ' width="' . esc_attr( $this->image_width ) . '"' : '';
749
- $image_height = ( $this->image_height !== false ) ? ' height="' . esc_attr( $this->image_height ) . '"' : '';
750
 
751
- if ( ! $image_url ) return false;
 
752
 
753
- $html = '<img src="' . esc_url( $image_url ) . '" class="' . MYCRED_SLUG . '-badge-image badge-level' . esc_attr( $level ) . '" title="' . esc_attr( $this->title ) . '" alt="' . esc_attr( $this->title ) . '"' . $image_width . $image_height . ' />';
754
 
755
- return apply_filters( 'mycred_badge_image', $html, $image, $this );
756
 
757
- }
758
 
759
- public function get_image_url( $image = NULL ) {
 
760
 
761
- $image_identification = false;
762
 
763
- if ( $image === 'main' )
764
- $image_identification = mycred_get_post_meta( $this->post_id, 'main_image', true );
765
 
766
- elseif ( $image !== NULL && is_numeric( $image ) && isset( $this->levels[ $image ]['attachment_id'] ) ) {
767
 
768
- $image_identification = $this->levels[ $image ]['image_url'];
769
- if ( $this->levels[ $image ]['attachment_id'] > 0 ) {
770
- $image_identification = $this->levels[ $image ]['attachment_id'];
771
- }
772
 
773
- }
774
 
775
- if ( $image_identification === false || strlen( $image_identification ) == 0 ) return false;
 
776
 
777
- $image_url = $image_identification;
778
 
779
- if ( is_numeric( $image_identification ) && strpos( '://', (string) $image_identification ) === false )
780
- $image_url = mycred_get_attachment_url( $image_identification );
 
781
 
782
- return apply_filters( 'mycred_badge_image_url', $image_url, $image, $this );
783
 
784
- }
785
 
786
- public function get_earned_image( $user_id ) {
 
787
 
788
- $image_url = $this->main_image_url;
789
 
790
- if ( $this->open_badge && $this->user_has_badge( $user_id ) ) {
791
 
792
- $wp_upload_dirs = wp_upload_dir();
793
- $basedir = trailingslashit( $wp_upload_dirs[ 'basedir' ] );
794
- $baseurl = trailingslashit( $wp_upload_dirs[ 'baseurl' ] );
795
 
796
- $folderName = apply_filters( 'mycred_open_badge_folder', 'open_badges' );
797
 
798
- $open_badge_directory = $basedir . $folderName;
799
 
800
- $open_badge_directory = trailingslashit( $open_badge_directory );
801
 
802
- $badge_id = $this->post_id;
803
 
804
- $filename = "badge-{$badge_id}-{$user_id}.png";
805
-
806
- if ( ! file_exists( $open_badge_directory . $filename ) ) {
807
 
808
- $mycred_Open_Badge = new mycred_Open_Badge();
809
- $mycred_Open_Badge->bake_users_image( $user_id, $badge_id );
810
 
811
- }
812
 
813
- $image_url = trailingslashit( $baseurl . $folderName ) . $filename;
814
 
815
- }
816
 
817
- return $image_url;
818
 
819
- }
820
 
821
- }
822
- endif;
1
  <?php
2
+ if (! defined('myCRED_VERSION') ) { exit;
3
+ }
4
 
5
  /**
6
  * myCRED_Badge class
7
+ *
8
+ * @see http://codex.mycred.me/classes/mycred_badge/
9
+ * @since 1.7
10
  * @version 1.1
11
  */
12
+ if (! class_exists('myCRED_Badge') ) :
13
+ class myCRED_Badge extends myCRED_Object
14
+ {
15
 
16
+ public $post_id = false;
17
 
18
+ public $title = '';
19
+ public $earnedby = 0;
20
+ public $manual = false;
21
+ public $open_badge = false;
22
 
23
+ public $levels = array();
24
+ public $main_image = false;
25
 
26
+ public $level = false;
27
+ public $level_id = false;
28
+ public $level_label = false;
29
+ public $level_image = false;
30
 
31
+ public $image_width = false;
32
+ public $image_height = false;
33
 
34
+ public $references = array();
35
+ public $point_types = array();
36
+ protected $user_meta_key = '';
37
 
38
+ public $user_id = false;
39
+ public $current_level = false;
40
 
41
+ public $main_image_url = false;
42
+ public $congratulation_msg = '';
43
+ public $align = 'mycred_align_left';
44
+ public $layout = 'mycred_layout_left';
45
 
46
+ /**
47
+ * Construct
48
+ */
49
+ function __construct( $object = null, $level_id = null )
50
+ {
51
 
52
+ parent::__construct();
53
 
54
+ if (is_object($object) && isset($object->post_type) && $object->post_type == MYCRED_BADGE_KEY ) {
55
+ $this->post_id = $object->ID;
56
 
57
+ } elseif (is_numeric($object) && mycred_get_post_type($object) == MYCRED_BADGE_KEY ) {
58
+ $this->post_id = absint($object);
59
 
60
+ } else { return false;
61
+ }
62
 
63
+ $this->image_width = MYCRED_BADGE_WIDTH;
64
+ $this->image_height = MYCRED_BADGE_HEIGHT;
65
 
66
+ $this->user_meta_key = MYCRED_BADGE_KEY . $this->post_id;
67
 
68
+ if ($level_id !== null ) { $this->level_id = absint($level_id);
69
+ }
70
 
71
+ $this->populate($object, $level_id);
72
 
73
+ }
74
 
75
+ /**
76
+ * Populate
77
+ *
78
+ * @since 1.0
79
+ * @version 1.0
80
+ */
81
+ protected function populate( $object = null, $level_id = null )
82
+ {
83
 
84
+ if ($this->post_id === false ) { return;
85
+ }
86
 
87
+ // Get base badge details
88
+ $this->title = ( isset($object->post_title) ) ? $object->post_title : mycred_get_the_title($this->post_id);
89
+ $this->earnedby = ( isset($object->earnedby) ) ? $object->earnedby : $this->get_user_count($level_id);
90
+ $this->levels = ( isset($object->levels) ) ? $object->levels : mycred_get_badge_levels($this->post_id);
91
 
92
+ if (! empty($this->levels) ) {
93
 
94
+ $this->references = array();
95
+ $this->point_types = array();
96
+ $this->compare = $this->levels[0]['compare'];
97
 
98
+ if (! empty($this->levels[0]['requires']) ) {
99
+ foreach ( $this->levels[0]['requires'] as $requirement_id => $req ) {
100
 
101
+ if ($req['reference'] != '' && ! in_array($req['reference'], $this->references) ) {
102
+ $this->references[] = $req['reference'];
103
+ }
104
 
105
+ if ($req['type'] != '' && ! in_array($req['type'], $this->point_types) ) {
106
+ $this->point_types[] = $req['type'];
107
+ }
108
 
109
+ }
110
+ }
111
 
112
+ }
113
 
114
+ // Indicate manual badge
115
+ if (absint(mycred_get_post_meta($this->post_id, 'manual_badge', true)) === 1 ) {
116
+ $this->manual = true;
117
+ }
118
 
119
+ // Indicate open badge
120
+ if (absint(mycred_get_post_meta($this->post_id, 'open_badge', true)) === 1 ) {
121
 
122
+ $badge_setting = mycred_get_addon_settings('badges');
123
 
124
+ if (isset($badge_setting['open_badge']) && $badge_setting['open_badge'] === 1 ) {
125
+
126
+ $this->open_badge = true;
127
 
128
+ }
129
+
130
+ }
131
 
132
+ // If we requested a particular level
133
+ if ($level_id !== null ) {
134
+ $this->level = $this->get_level($level_id);
135
+ }
136
 
137
+ // Get images
138
+ $this->main_image = $this->get_image('main');
139
+ $this->main_image_url = $this->get_image_url('main');
140
+ $this->level_image = $this->get_image($level_id);
141
+ $this->congratulation_msg = mycred_get_post_meta($this->post_id, 'congratulation_msg', true);
142
+ $this->align = mycred_get_post_meta($this->post_id, 'mycred_badge_align', true);
143
+ $this->layout = mycred_get_post_meta($this->post_id, 'mycred_layout_check', true);
144
 
145
+ }
146
 
147
+ /**
148
+ * Get User Count
149
+ *
150
+ * @since 1.0
151
+ * @version 1.0
152
+ */
153
+ public function get_user_count( $level_id = null )
154
+ {
155
 
156
+ if ($this->post_id === false ) { return 0;
157
+ }
158
 
159
+ $count = mycred_get_post_meta($this->post_id, 'total-users-with-badge', true);
160
+ if ($count == '' || $level_id !== null ) {
161
 
162
+ global $wpdb;
163
 
164
+ $level_filter = ( $level_id !== null && is_numeric($level_id) ) ? $wpdb->prepare("AND meta_value = %s", $level_id) : '';
165
 
166
+ $count = $wpdb->get_var($wpdb->prepare("SELECT COUNT( DISTINCT user_id ) FROM {$wpdb->usermeta} WHERE meta_key = %s {$level_filter};", mycred_get_meta_key($this->user_meta_key)));
167
+ if ($count === null ) { $count = 0;
168
+ }
169
 
170
+ if ($level_id === null ) {
171
+ mycred_update_post_meta($this->post_id, 'total-users-with-badge', $count, true);
172
+ }
173
 
174
+ }
175
 
176
+ return apply_filters('mycred_count_users_with_badge', absint($count), $this->post_id);
177
 
178
+ }
179
 
180
+ /**
181
+ * Get Level
182
+ *
183
+ * @since 1.0
184
+ * @version 1.0
185
+ */
186
+ public function get_level( $level_id = false )
187
+ {
188
 
189
+ if ($level_id === false || empty($this->levels) || ! array_key_exists($level_id, $this->levels) ) { return false;
190
+ }
191
 
192
+ return $this->levels[ $level_id ];
193
 
194
+ }
195
 
196
+ /**
197
+ * Get Level Requirements
198
+ *
199
+ * @since 1.0
200
+ * @version 1.0
201
+ */
202
+ public function get_level_requirements( $level_id = false )
203
+ {
204
 
205
+ if ($level_id === false || empty($this->levels) || ! array_key_exists($level_id, $this->levels) ) { return false;
206
+ }
207
 
208
+ return $this->levels[ $level_id ]['requires'];
209
 
210
+ }
211
 
212
+ /**
213
+ * Get Level Reward
214
+ *
215
+ * @since 1.0
216
+ * @version 1.0
217
+ */
218
+ public function get_level_reward( $level_id = false )
219
+ {
220
 
221
+ if ($level_id === false || empty($this->levels) || ! array_key_exists($level_id, $this->levels) ) { return false;
222
+ }
223
 
224
+ return $this->levels[ $level_id ]['reward'];
225
 
226
+ }
227
 
228
+ /**
229
+ * User Has Badge
230
+ *
231
+ * @since 1.0
232
+ * @version 1.0
233
+ */
234
+ public function user_has_badge( $user_id = false, $level_id = 0 )
235
+ {
236
 
237
+ $has_badge = false;
238
+ if ($user_id === false ) { return $has_badge;
239
+ }
240
 
241
+ $this->user_id = absint($user_id);
242
+ $this->current_level = $this->get_users_current_level($user_id);
243
 
244
+ if ($this->current_level !== false ) {
245
 
246
+ $has_badge = true;
247
 
248
+ if ((int) $this->current_level < absint($level_id) ) {
249
+ $has_badge = false;
250
+ }
251
 
252
+ }
253
 
254
+ return apply_filters('mycred_user_has_badge', $has_badge, $user_id, $this->post_id, $level_id, $this->current_level);
255
 
256
+ }
257
 
258
+ /**
259
+ * Get Users Current Level
260
+ *
261
+ * @since 1.0
262
+ * @version 1.0
263
+ */
264
+ public function get_users_current_level( $user_id = false )
265
+ {
266
 
267
+ if ($user_id === false ) { return $has_badge;
268
+ }
269
 
270
+ global $mycred_current_account;
271
 
272
+ $user_id = absint($user_id);
273
 
274
+ if (mycred_is_current_account($user_id) && isset($mycred_current_account->badge_ids) && ! empty($mycred_current_account->badge_ids) && array_key_exists($this->post_id, $mycred_current_account->badge_ids) ) {
275
+ return absint($mycred_current_account->badge_ids[ $this->post_id ]);
276
+ }
277
 
278
+ $current_level = mycred_get_user_meta($user_id, $this->user_meta_key, '', true);
279
+ $current_level = ( ! empty($current_level) || $current_level === '0' ) ? absint($current_level) : false;
280
 
281
+ return $current_level;
282
 
283
+ }
284
 
285
+ /**
286
+ * Get Level Reached
287
+ *
288
+ * @since 1.0
289
+ * @version 1.0
290
+ */
291
+ public function query_users_level( $user_id = false )
292
+ {
293
 
294
+ if ($user_id === false || empty($this->levels) ) { return false;
295
+ }
296
 
297
+ global $wpdb, $mycred_log_table;
298
 
299
+ $base_requirements = $this->levels[0]['requires'];
300
+ $compare = $this->levels[0]['compare'];
301
+ $requirements = count($base_requirements);
302
+ $level_reached = false;
303
+ $results = array();
304
 
305
+ // Based on the base requirements, we first get the users log entry results
306
+ if (! empty($base_requirements) ) {
307
+ foreach ( $base_requirements as $requirement_id => $requirement ) {
308
 
309
+ if ($requirement['type'] == '' ) {
310
+ $requirement['type'] = MYCRED_DEFAULT_TYPE_KEY;
311
+ }
312
 
313
+ $mycred = mycred($requirement['type']);
314
+ if ($mycred->exclude_user($user_id) ) { continue;
315
+ }
316
 
317
+ $having = 'COUNT(*)';
318
+ if ($requirement['by'] != 'count' ) {
319
+ $having = 'SUM(creds)';
320
+ }
321
 
322
+ $query = $wpdb->get_var($wpdb->prepare("SELECT {$having} FROM {$mycred_log_table} WHERE ctype = %s AND ref = %s AND user_id = %d;", $requirement['type'], $requirement['reference'], $user_id));
323
 
324
+ $query = apply_filters('mycred_badge_requirement', $query, $requirement_id, $requirement, $having, $user_id);
325
 
326
+ if ($query === null ) { $query = 0;
327
+ }
328
 
329
+ $results[ $requirement['reference'] ] = $query;
330
 
331
+ }
332
+ }
333
 
334
+ // Next we loop through the levels and see compare the previous results to the requirements to determan our level
335
+ foreach ( $this->levels as $level_id => $level_setup ) {
336
 
337
+ $reqs_met = 0;
338
+ foreach ( $level_setup['requires'] as $requirement_id => $requirement ) {
339
 
340
+ if ($results[ $requirement['reference'] ] >= $requirement['amount'] ) {
341
+ $reqs_met++;
342
+ }
343
 
344
+ }
345
 
346
+ if ($compare === 'AND' && $reqs_met >= $requirements ) {
347
+ $level_reached = $level_id;
348
 
349
+ } elseif ($compare === 'OR' && $reqs_met > 0 ) {
350
+ $level_reached = $level_id;
351
+ }
352
 
353
+ }
354
 
355
+ do_action('mycred_badge_level_reached', $user_id, $this->post_id, $level_reached);
356
 
357
+ return $level_reached;
358
 
359
+ }
360
 
361
+ /**
362
+ * Get Users Next Level ID
363
+ *
364
+ * @since 1.0
365
+ * @version 1.0
366
+ */
367
+ public function get_users_next_level_id( $user_id = false )
368
+ {
369
 
370
+ if (! $this->user_has_badge($user_id) ) {
371
+ return 0;
372
+ }
373
 
374
+ $max_level = count($this->levels);
375
+ if ($this->current_level >= $max_level ) {
376
+ return $max_level;
377
+ }
378
 
379
+ return $this->current_level;
380
 
381
+ }
382
 
383
+ /**
384
+ * Get Users Next Level
385
+ *
386
+ * @since 1.0
387
+ * @version 1.0
388
+ */
389
+ public function get_users_next_level( $user_id = false )
390
+ {
391
 
392
+ if (! $this->user_has_badge($user_id) ) {
393
+ return false;
394
+ }
395
 
396
+ $next_level_id = $this->get_users_next_level_id($user_id);
397
 
398
+ return $this->get_level($next_level_id);
399
 
400
+ }
401
 
402
+ /**
403
+ * Assign Badge to User
404
+ *
405
+ * @since 1.0
406
+ * @since 2.3 Added functions `mycred_update_user_meta`, `mycred_get_user_meta` with `mycred_badge_ids`
407
+ * @version 1.0
408
+ */
409
+ public function assign( $user_id = false, $level_id = 0 )
410
+ {
411
 
412
+ if ($user_id === false || absint($user_id) === 0 ) { return false;
413
+ }
414
 
415
+ $previous_level = -1;
416
+ $new_level = $level_id;
417
 
418
+ if ($this->user_has_badge($user_id) ) {
419
 
420
+ // Right now we can not earn the same badge over and over again
421
+ // Planing on adding in an option to override this
422
+ if ($this->current_level == $level_id ) { return true;
423
+ }
424
 
425
+ $previous_level = $this->current_level;
426
 
427
+ }
428
 
429
+ else {
430
+ $this->user_id = $user_id;
431
+ $this->current_level = $new_level;
432
+ }
433
 
434
+ $execute = apply_filters('mycred_badge_assign', true, $user_id, $new_level, $this);
435
 
436
+ if ($execute ) {
437
+
438
+ $new_level = apply_filters('mycred_badge_user_value', $new_level, $user_id, $this->post_id);
439
 
440
+ mycred_update_user_meta($user_id, $this->user_meta_key, '', $new_level);
441
+ mycred_update_user_meta($user_id, $this->user_meta_key, '_issued_on', time());
442
+
443
+ $badge_ids = mycred_get_user_meta($user_id, 'mycred_badge_ids', '', true);
444
+
445
+ if (! empty($badge_ids) && is_array($badge_ids) ) {
446
+ $badge_ids[ $this->post_id ] = 0;
447
+ } else {
448
+ $badge_ids = array( $this->post_id => 0 );
449
+ }
450
+
451
+ mycred_update_user_meta($user_id, 'mycred_badge_ids', '', $badge_ids);
452
 
453
+ // Need to update counter with new assignments
454
+ if ($new_level == 0 ) {
455
 
456
+ $this->earnedby ++;
457
 
458
+ mycred_update_post_meta($this->post_id, 'total-users-with-badge', $this->earnedby);
459
 
460
+ }
461
 
462
+ $this->payout_reward($previous_level, $new_level);
463
+
464
+ do_action('mycred_after_badge_assign', $user_id, $this->post_id, $new_level);
465
 
466
+ }
467
 
468
+ return true;
469
 
470
+ }
471
 
472
+ /**
473
+ * Payout Rewards
474
+ *
475
+ * @since 1.0
476
+ * @version 1.0
477
+ */
478
+ public function payout_reward( $previous_level = -1, $new_level = 0 )
479
+ {
480
 
481
+ // Earning the badge
482
+ if ($previous_level < 0 && $new_level == 0 ) {
483
 
484
+ $reward = $this->get_level_reward($new_level);
485
+ if ($reward !== false && ( $reward['log'] == '' || $reward['amount'] == 0 ) ) { return false;
486
+ }
487
 
488
+ $mycred = mycred($reward['type']);
489
 
490
+ // Make sure we only get points once for each level we reach for each badge
491
+ if (! $mycred->has_entry('badge_reward', $this->post_id, $this->user_id, 0, $reward['type']) ) {
492
 
493
+ $exec = apply_filters('customize_mycred_badge_condition', true, $this->post_id, $this->user_id, $reward['type']);
494
 
495
+ if($exec ) {
496
 
497
+ $mycred->add_creds(
498
+ 'badge_reward',
499
+ $this->user_id,
500
+ $reward['amount'],
501
+ $reward['log'],
502
+ $this->post_id,
503
+ 0,
504
+ $reward['type']
505
+ );
506
 
507
+ do_action('mycred_badge_rewardes', $this->user_id, $previous_level, $new_level, $reward, $this);
508
 
509
+ }
510
 
511
+ }
512
 
513
+ }
514
 
515
+ // Earning a new level as well
516
+ else {
517
 
518
+ // Loop through levels to make sure we do not miss rewards if we jump more than one level
519
+ for ( $i = $previous_level; $i <= $new_level; $i++ ) {
520
 
521
+ $reward = $this->get_level_reward($i);
522
+ if ($reward !== false && ( $reward['log'] == '' || $reward['amount'] == 0 ) ) { continue;
523
+ }
524
 
525
+ $mycred = mycred($reward['type']);
526
 
527
+ // Make sure we only get points once for each level we reach for each badge
528
+ if (! $mycred->has_entry('badge_reward', $this->post_id, $this->user_id, $i, $reward['type']) ) {
529
 
530
+ $exec = apply_filters('customize_mycred_badge_condition', true, $this->post_id, $this->user_id, $reward['type']);
531
 
532
+ if($exec ) {
533
 
534
+ $mycred->add_creds(
535
+ 'badge_reward',
536
+ $this->user_id,
537
+ $reward['amount'],
538
+ $reward['log'],
539
+ $this->post_id,
540
+ $i,
541
+ $reward['type']
542
+ );
543
 
544
+ do_action('mycred_badge_rewardes', $this->user_id, $previous_level, $new_level, $reward, $this);
545
 
546
+ }
547
 
548
+ }
549
 
550
+ }
551
 
552
+ }
553
 
554
+ return true;
555
 
556
+ }
557
 
558
+ /**
559
+ * Assign Badge to All
560
+ *
561
+ * @since 1.0
562
+ * @version 1.0
563
+ */
564
+ public function assign_all()
565
+ {
566
 
567
+ if ($this->post_id === false || empty($this->levels) ) { return false;
568
+ }
569
 
570
+ global $wpdb, $mycred_log_table;
571
 
572
+ $results = array();
573
 
574
+ // Need to have some requirements set or we are in trouble
575
+ if (! empty($this->levels[0]['requires']) ) {
576
 
577
+ // Single requirement
578
+ if (count($this->levels[0]['requires']) == 1 ) {
579
 
580
+ $requirement = $this->levels[0]['requires'][0];
581
+ $having = ( $requirement['by'] != 'count' ) ? 'SUM( creds )' : 'COUNT( id )';
582
+ $requirement['type'] = ( $requirement['type'] == '' ) ? MYCRED_DEFAULT_TYPE_KEY : $requirement['type'];
583
 
584
+ $results = $wpdb->get_results($wpdb->prepare("SELECT DISTINCT user_id, {$having} as total FROM {$mycred_log_table} WHERE ctype = %s AND ref = %s GROUP BY user_id HAVING {$having} >= %f;", $requirement['type'], $requirement['reference'], $requirement['amount']));
585
 
586
+ // Find the level id for each result based on their total
587
+ if (! empty($results) ) {
588
+ foreach ( $results as $row ) {
589
 
590
+ $badge_level_id = 0;
591
 
592
+ foreach ( $this->levels as $level_id => $setup ) {
593
+ if ($row->total >= $setup['requires'][0]['amount'] ) {
594
+ $badge_level_id = $level_id;
595
+ }
596
+ }
597
 
598
+ $row->level_id = $badge_level_id;
599
 
600
+ }
601
+ }
602
 
603
+ }
604
 
605
+ // Multiple requirements
606
+ else {
607
 
608
+ $user_ids = array();
609
 
610
+ $requirements = count($this->levels[0]['requires']);
611
+ $compare = $this->levels[0]['compare'];
612
 
613
+ // I feel like there must be a better way of doing this
614
+ // If you have a suggestion for how to query all users based on multiple requirements, let me know!
615
+ foreach ( $this->levels as $level_id => $level_setup ) {
616
 
617
+ $level_user_ids = array();
618
 
619
+ // Get all user IDs that fulfill each requirements set
620
+ if (! empty($level_setup['requires']) ) {
621
+ foreach ( $level_setup['requires'] as $requirement_id => $requirement ) {
622
 
623
+ $having = ( $requirement['by'] != 'count' ) ? 'SUM( creds )' : 'COUNT( id )';
624
+ $requirement['type'] = ( $requirement['type'] == '' ) ? MYCRED_DEFAULT_TYPE_KEY : $requirement['type'];
625
 
626
+ $level_user_ids[ $requirement_id ] = $wpdb->get_col($wpdb->prepare("SELECT DISTINCT user_id FROM {$mycred_log_table} WHERE ctype = %s AND ref = %s GROUP BY user_id HAVING {$having} >= %f;", $requirement['type'], $requirement['reference'], $requirement['amount']));
627
 
628
+ }
629
+ }
630
 
631
+ // OR = get all unique IDs
632
+ if ($compare == 'OR' ) {
633
 
634
+ $list = array();
635
+ foreach ( $level_user_ids as $requirement_id => $list_of_ids ) {
636
+ if (! empty($list_of_ids) ) {
637
+ foreach ( $list_of_ids as $uid ) {
638
+ if (! in_array($uid, $list) ) {
639
+ $list[] = $uid;
640
+ }
641
+ }
642
+ }
643
+ }
644
 
645
+ }
646
 
647
+ // AND = get IDs that are in all requirements
648
+ else {
649
 
650
+ $list = $_list = array();
651
 
652
+ foreach ( $level_user_ids as $requirement_id => $list_of_ids ) {
653
+ if (! empty($list_of_ids) ) {
654
+ foreach ( $list_of_ids as $uid ) {
655
+ if (! array_key_exists($uid, $_list) ) {
656
+ $_list[ $uid ] = 1;
657
+ } else {
658
+ $_list[ $uid ]++;
659
+ }
660
+ }
661
+ }
662
+ }
663
 
664
+ foreach ( $_list as $uid => $count ) {
665
+ if ($count >= $requirements ) {
666
+ $list[] = $uid;
667
+ }
668
+ }
669
 
670
+ }
671
 
672
+ // If no user has reached the first level, no one will have reached higher levels and there is no need to continue
673
+ if ($level_id == 0 && empty($list) ) { break;
674
+ }
675
 
676
+ // Create a list where the array key represents the user ID and the array value represents the badge level reached by the user
677
+ foreach ( $list as $user_id ) {
678
+ $user_ids[ $user_id ] = $level_id;
679
+ }
680
 
681
+ }
682
 
683
+ if (! empty($user_ids) ) {
684
+ foreach ( $user_ids as $user_id => $level_reached ) {
685
 
686
+ $row = new StdClass();
687
+ $row->user_id = $user_id;
688
+ $row->level_id = $level_reached;
689
 
690
+ $results[] = $row;
691
 
692
+ }
693
+ }
694
 
695
+ }
696
+
697
+ // Assign results
698
+ if (! empty($results) ) {
699
 
700
+ // Assign each user
701
+ foreach ( $results as $row ) {
702
+ mycred_update_user_meta($row->user_id, $this->user_meta_key, '', $row->level_id);
703
+ }
704
 
705
+ // Update earned count
706
+ $this->earnedby = count($results);
707
 
708
+ mycred_update_post_meta($this->post_id, 'total-users-with-badge', $this->earnedby);
709
 
710
+ //Updating issued_on
711
+ mycred_update_user_meta($row->user_id, $this->user_meta_key, '_issued_on', time());
712
 
713
+ }
714
 
715
+ }
716
 
717
+ return count($results);
718
 
719
+ }
720
 
721
+ /**
722
+ * Divest Badge from user
723
+ *
724
+ * @since 1.0
725
+ * @since 2.3 Added functions `mycred_update_user_meta` with `mycred_badge_ids`
726
+ * @version 1.0
727
+ */
728
+ public function divest( $user_id = false )
729
+ {
730
 
731
+ if ($user_id === false || absint($user_id) === 0 ) { return false;
732
+ }
733
 
734
+ mycred_delete_user_meta($user_id, $this->user_meta_key);
735
+ mycred_delete_user_meta($user_id, $this->user_meta_key . '_issued_on');
736
+ $usermeta = mycred_get_user_meta($user_id, 'mycred_badge_ids', '', true);
737
 
738
+ if (isset($usermeta[$this->post_id]) ) {
739
+ unset($usermeta[$this->post_id]);
740
+ }
741
 
742
+ $this->earnedby --;
743
+ if ($this->earnedby < 0 ) { $this->earnedby = 0;
744
+ }
745
 
746
+ mycred_update_post_meta($this->post_id, 'total-users-with-badge', $this->earnedby);
747
+ mycred_update_user_meta($user_id, 'mycred_badge_ids', '', $usermeta);
748
 
749
+ return true;
750
 
751
+ }
752
 
753
+ /**
754
+ * Divest Badge from Everyone
755
+ *
756
+ * @since 1.0
757
+ * @version 1.0
758
+ */
759
+ public function divest_all()
760
+ {
761
 
762
+ if ($this->post_id === false ) { return false;
763
+ }
764
 
765
+ global $wpdb;
766
 
767
+ // Delete connections
768
+ $count = $wpdb->delete(
769
+ $wpdb->usermeta,
770
+ array( 'meta_key' => mycred_get_meta_key($this->user_meta_key) ),
771
+ array( '%s' )
772
+ );
773
 
774
+ $this->earnedby = 0;
775
 
776
+ mycred_update_post_meta($this->post_id, 'total-users-with-badge', $this->earnedby);
777
 
778
+ return $count;
779
 
780
+ }
781
 
782
+ /**
783
+ * Delete Badge
784
+ *
785
+ * @since 1.0
786
+ * @version 1.0
787
+ */
788
+ public function delete( $delete_post = false )
789
+ {
790
 
791
+ if ($this->post_id === false ) { return false;
792
+ }
793
 
794
+ $this->divest_all();
795
 
796
+ if (! empty($this->point_types) ) {
797
 
798
+ foreach ( $this->point_types as $point_type ) {
799
+ mycred_delete_option('mycred-badge-references-' . $point_type);
800
+ }
801
 
802
+ }
803
 
804
+ if ($delete_post ) {
805
+ mycred_delete_post($this->post_id, true);
806
+ }
807
 
808
+ return true;
809
 
810
+ }
811
 
812
+ /**
813
+ * Get Badge Image
814
+ *
815
+ * @since 1.0
816
+ * @version 1.1
817
+ */
818
+ public function get_image( $image = null )
819
+ {
820
 
821
+ $image_identification = false;
822
 
823
+ $level = 'none';
824
+ if ($image != 'main' && is_numeric($image) ) {
825
 
826
+ $level = $image;
827
 
828
+ }
829
 
830
+ $image_url = $this->get_image_url($image);
831
 
832
+ $image_width = ( $this->image_width !== false ) ? ' width="' . esc_attr($this->image_width) . '"' : '';
833
+ $image_height = ( $this->image_height !== false ) ? ' height="' . esc_attr($this->image_height) . '"' : '';
834
 
835
+ if (! $image_url ) { return false;
836
+ }
837
 
838
+ $html = '<img src="' . esc_url($image_url) . '" class="' . MYCRED_SLUG . '-badge-image badge-level' . esc_attr($level) . '" title="' . esc_attr($this->title) . '" alt="' . esc_attr($this->title) . '"' . $image_width . $image_height . ' />';
839
 
840
+ return apply_filters('mycred_badge_image', $html, $image, $this);
841
 
842
+ }
843
 
844
+ public function get_image_url( $image = null )
845
+ {
846
 
847
+ $image_identification = false;
848
 
849
+ if ($image === 'main' ) {
850
+ $image_identification = mycred_get_post_meta($this->post_id, 'main_image', true);
851
 
852
+ } elseif ($image !== null && is_numeric($image) && isset($this->levels[ $image ]['attachment_id']) ) {
853
 
854
+ $image_identification = $this->levels[ $image ]['image_url'];
855
+ if ($this->levels[ $image ]['attachment_id'] > 0 ) {
856
+ $image_identification = $this->levels[ $image ]['attachment_id'];
857
+ }
858
 
859
+ }
860
 
861
+ if ($image_identification === false || strlen($image_identification) == 0 ) { return false;
862
+ }
863
 
864
+ $image_url = $image_identification;
865
 
866
+ if (is_numeric($image_identification) && strpos('://', (string) $image_identification) === false ) {
867
+ $image_url = mycred_get_attachment_url($image_identification);
868
+ }
869
 
870
+ return apply_filters('mycred_badge_image_url', $image_url, $image, $this);
871
 
872
+ }
873
 
874
+ public function get_earned_image( $user_id )
875
+ {
876
 
877
+ $image_url = $this->main_image_url;
878
 
879
+ if ($this->open_badge && $this->user_has_badge($user_id) ) {
880
 
881
+ $wp_upload_dirs = wp_upload_dir();
882
+ $basedir = trailingslashit($wp_upload_dirs[ 'basedir' ]);
883
+ $baseurl = trailingslashit($wp_upload_dirs[ 'baseurl' ]);
884
 
885
+ $folderName = apply_filters('mycred_open_badge_folder', 'open_badges');
886
 
887
+ $open_badge_directory = $basedir . $folderName;
888
 
889
+ $open_badge_directory = trailingslashit($open_badge_directory);
890
 
891
+ $badge_id = $this->post_id;
892
 
893
+ $filename = "badge-{$badge_id}-{$user_id}.png";
894
+
895
+ if (! file_exists($open_badge_directory . $filename) ) {
896
 
897
+ $mycred_Open_Badge = new mycred_Open_Badge();
898
+ $mycred_Open_Badge->bake_users_image($user_id, $badge_id);
899
 
900
+ }
901
 
902
+ $image_url = trailingslashit($baseurl . $folderName) . $filename;
903
 
904
+ }
905
 
906
+ return $image_url;
907
 
908
+ }
909
 
910
+ }
911
+ endif;
addons/badges/includes/mycred-badge-secondary.php CHANGED
@@ -1,103 +1,113 @@
1
  <?php
2
- if ( ! defined( 'myCRED_VERSION' ) ) exit;
 
3
 
4
  /**
5
  * Hook for site visits
6
- * @since 1.5
 
7
  * @version 1.1
8
  */
9
- if ( ! class_exists( 'myCRED_Badge_Secondary' ) ) :
10
- class myCRED_Badge_Secondary {
 
11
 
12
- // Instnace
13
- protected static $_instance = NULL;
14
 
15
- /**
16
- * Construct
17
- */
18
- function __construct() {
 
19
 
20
- add_filter( 'mycred_badge_requirement', array( $this, 'mycred_badge_specific_requirement'), 10, 5 );
21
- add_filter( 'mycred_badge_requirement_specific_template', array( $this, 'badge_specific_template'), 10, 5 );
22
- add_action( 'admin_head', array( $this, 'admin_header' ) );
23
-
24
- }
25
 
26
- /**
27
- * Setup Instance
28
- * @since 1.7
29
- * @version 1.0
30
- */
31
- public static function instance() {
32
- if ( is_null( self::$_instance ) ) {
33
- self::$_instance = new self();
34
- }
35
- return self::$_instance;
36
- }
 
 
37
 
38
- public function mycred_badge_specific_requirement( $query, $requirement_id, $requirement, $having, $user_id ) {
39
-
40
- global $wpdb, $mycred_log_table;
 
41
 
42
- if( $requirement['reference'] == 'link_click' && ! empty( $requirement['specific'] ) && $requirement['specific'] != 'Any' ) {
43
-
44
- $query = $wpdb->get_var( $wpdb->prepare( "SELECT {$having} FROM {$mycred_log_table} WHERE ctype = %s AND ref = %s AND data LIKE %s AND user_id = %d;", $requirement['type'], $requirement['reference'], '%'.$requirement['specific'].'%', $user_id ) );
45
-
46
- }
47
- else if( $requirement['reference'] == 'gravity_form_submission' && ! empty( $requirement['specific'] ) && $requirement['specific'] != 'Any' ) {
48
- $query = $wpdb->get_var( $wpdb->prepare( "SELECT {$having} FROM {$mycred_log_table} WHERE ctype = %s AND ref = %s AND ref_id = %d AND user_id = %d;", $requirement['type'], $requirement['reference'], $requirement['specific'], $user_id ) );
49
- }
50
- return $query;
51
- }
52
 
53
- public function badge_specific_template( $data, $requirement_id, $requirement, $badge, $level ) {
 
54
 
55
- if( $requirement['reference'] == 'link_click' && ! empty( $requirement['specific'] ) && $requirement['specific'] != 'Any' ) {
56
-
57
- $data = '<div class="form-group"><input type="text" name="mycred_badge[levels]['.$level.'][requires]['.$requirement_id.'][specific]" class="form-control specific" value="'.$requirement['specific'].'" data-row="'.$requirement_id.'" /></div>';
58
-
59
- }
60
- else if( $requirement['reference'] == 'gravity_form_submission' && ! empty( $requirement['specific'] ) && $requirement['specific'] != 'Any' ) {
61
- if( class_exists('RGFormsModel') ) {
62
- $gravityforms = RGFormsModel::get_forms();
63
- $form_list = '<option>Any</option>';
64
- foreach ($gravityforms as $form) {
65
- $form_list .= '<option value="'.$form->id.'" '.( $requirement['specific'] == $form->id ? ' selected="selected"' : '').' >'. htmlentities( $form->title, ENT_QUOTES ) .'</option>';
66
- }
67
- $data = '<div class="form-group"><select name="mycred_badge[levels]['.$level.'][requires]['.$requirement_id.'][specific]" class="form-control specific" data-row="'.$requirement_id.'" >'.$form_list.'</select></div>';
68
- }
69
- }
70
- return $data;
71
 
72
- }
73
 
74
- public function admin_header() {
75
- $screen = get_current_screen();
76
-
77
- if ( $screen->id == MYCRED_BADGE_KEY ):?>
78
- <script type="text/javascript">
79
- var mycred_badge_link_click = '<div class="form-group"><input type="text" name="{{element_name}}" data-row="{{reqlevel}}" class="form-control specific" /></div>';
 
80
 
81
- <?php
82
- if( class_exists('RGFormsModel') ) {
83
- $gravityforms = RGFormsModel::get_forms();
84
- $form_list = '<option>Any</option>';
85
- foreach ( $gravityforms as $form ) {
86
- $form_list .= '<option value="'.$form->id.'">'. htmlentities( $form->title, ENT_QUOTES ) .'</option>';
87
- }
88
- $data = '<div class="form-group"><select name="{{element_name}}" class="form-control specific" data-row="{{reqlevel}}" >'.$form_list.'</select></div>';
89
- echo "var mycred_badge_gravity_form_submission = '".$data."';";
90
- }
91
- ?>
92
- </script>
93
- <?php endif;
94
- }
95
 
96
- }
97
  endif;
98
 
99
- function myCRED_Badge_Secondary_init() {
100
- return myCRED_Badge_Secondary::instance();
 
101
  }
102
  myCRED_Badge_Secondary_init();
103
 
1
  <?php
2
+ if (! defined('myCRED_VERSION') ) { exit;
3
+ }
4
 
5
  /**
6
  * Hook for site visits
7
+ *
8
+ * @since 1.5
9
  * @version 1.1
10
  */
11
+ if (! class_exists('myCRED_Badge_Secondary') ) :
12
+ class myCRED_Badge_Secondary
13
+ {
14
 
15
+ // Instnace
16
+ protected static $_instance = null;
17
 
18
+ /**
19
+ * Construct
20
+ */
21
+ function __construct()
22
+ {
23
 
24
+ add_filter('mycred_badge_requirement', array( $this, 'mycred_badge_specific_requirement'), 10, 5);
25
+ add_filter('mycred_badge_requirement_specific_template', array( $this, 'badge_specific_template'), 10, 5);
26
+ add_action('admin_head', array( $this, 'admin_header' ));
27
+
28
+ }
29
 
30
+ /**
31
+ * Setup Instance
32
+ *
33
+ * @since 1.7
34
+ * @version 1.0
35
+ */
36
+ public static function instance()
37
+ {
38
+ if (is_null(self::$_instance) ) {
39
+ self::$_instance = new self();
40
+ }
41
+ return self::$_instance;
42
+ }
43
 
44
+ public function mycred_badge_specific_requirement( $query, $requirement_id, $requirement, $having, $user_id )
45
+ {
46
+
47
+ global $wpdb, $mycred_log_table;
48
 
49
+ if($requirement['reference'] == 'link_click' && ! empty($requirement['specific']) && $requirement['specific'] != 'Any' ) {
50
+
51
+ $query = $wpdb->get_var($wpdb->prepare("SELECT {$having} FROM {$mycred_log_table} WHERE ctype = %s AND ref = %s AND data LIKE %s AND user_id = %d;", $requirement['type'], $requirement['reference'], '%'.$requirement['specific'].'%', $user_id));
52
+
53
+ }
54
+ else if($requirement['reference'] == 'gravity_form_submission' && ! empty($requirement['specific']) && $requirement['specific'] != 'Any' ) {
55
+ $query = $wpdb->get_var($wpdb->prepare("SELECT {$having} FROM {$mycred_log_table} WHERE ctype = %s AND ref = %s AND ref_id = %d AND user_id = %d;", $requirement['type'], $requirement['reference'], $requirement['specific'], $user_id));
56
+ }
57
+ return $query;
58
+ }
59
 
60
+ public function badge_specific_template( $data, $requirement_id, $requirement, $badge, $level )
61
+ {
62
 
63
+ if($requirement['reference'] == 'link_click' && ! empty($requirement['specific']) && $requirement['specific'] != 'Any' ) {
64
+
65
+ $data = '<div class="form-group"><input type="text" name="mycred_badge[levels]['.$level.'][requires]['.$requirement_id.'][specific]" class="form-control specific" value="'.$requirement['specific'].'" data-row="'.$requirement_id.'" /></div>';
66
+
67
+ }
68
+ else if($requirement['reference'] == 'gravity_form_submission' && ! empty($requirement['specific']) && $requirement['specific'] != 'Any' ) {
69
+ if(class_exists('RGFormsModel') ) {
70
+ $gravityforms = RGFormsModel::get_forms();
71
+ $form_list = '<option>Any</option>';
72
+ foreach ($gravityforms as $form) {
73
+ $form_list .= '<option value="'.$form->id.'" '.( $requirement['specific'] == $form->id ? ' selected="selected"' : '').' >'. htmlentities($form->title, ENT_QUOTES) .'</option>';
74
+ }
75
+ $data = '<div class="form-group"><select name="mycred_badge[levels]['.$level.'][requires]['.$requirement_id.'][specific]" class="form-control specific" data-row="'.$requirement_id.'" >'.$form_list.'</select></div>';
76
+ }
77
+ }
78
+ return $data;
79
 
80
+ }
81
 
82
+ public function admin_header()
83
+ {
84
+ $screen = get_current_screen();
85
+
86
+ if ($screen->id == MYCRED_BADGE_KEY ) :?>
87
+ <script type="text/javascript">
88
+ var mycred_badge_link_click = '<div class="form-group"><input type="text" name="{{element_name}}" data-row="{{reqlevel}}" class="form-control specific" /></div>';
89
 
90
+ <?php
91
+ if(class_exists('RGFormsModel') ) {
92
+ $gravityforms = RGFormsModel::get_forms();
93
+ $form_list = '<option>Any</option>';
94
+ foreach ( $gravityforms as $form ) {
95
+ $form_list .= '<option value="'.$form->id.'">'. htmlentities($form->title, ENT_QUOTES) .'</option>';
96
+ }
97
+ $data = '<div class="form-group"><select name="{{element_name}}" class="form-control specific" data-row="{{reqlevel}}" >'.$form_list.'</select></div>';
98
+ echo "var mycred_badge_gravity_form_submission = '".$data."';";
99
+ }
100
+ ?>
101
+ </script>
102
+ <?php endif;
103
+ }
104
 
105
+ }
106
  endif;
107
 
108
+ function myCRED_Badge_Secondary_init()
109
+ {
110
+ return myCRED_Badge_Secondary::instance();
111
  }
112
  myCRED_Badge_Secondary_init();
113
 
addons/badges/includes/mycred-badge-shortcodes.php CHANGED
@@ -1,44 +1,52 @@
1
  <?php
2
- if ( ! defined( 'myCRED_VERSION' ) ) exit;
 
3
 
4
  /**
5
  * Shortcode: mycred_my_badges
6
  * Allows you to show the current users earned badges.
7
- * @since 1.5
 
8
  * @version 1.2.1
9
  */
10
- if ( ! function_exists( 'mycred_render_my_badges' ) ) :
11
- function mycred_render_my_badges( $atts, $content = '' ) {
12
-
13
- extract( shortcode_atts( array(
14
- 'show' => 'earned',
15
- 'width' => MYCRED_BADGE_WIDTH,
16
- 'height' => MYCRED_BADGE_HEIGHT,
17
- 'user_id' => 'current',
18
- 'title' => '',
19
- 'post_excerpt' => ''
20
- ), $atts, MYCRED_SLUG . '_my_badges' ) );
21
-
22
- if ( ! is_user_logged_in() && $user_id == 'current' )
 
 
 
 
 
23
  return $content;
 
24
 
25
- $user_id = mycred_get_user_id( $user_id );
26
 
27
  ob_start();
28
 
29
  echo '<div class="row" id="mycred-users-badges"><div class="col-xs-12">';
30
 
31
  // Show only badges that we have earned
32
- if ( $show == 'earned' ) {
33
 
34
- mycred_display_users_badges( $user_id, $width, $height );
35
 
36
  }
37
 
38
  // Show all badges highlighting the ones we earned
39
- elseif ( $show == 'all' ) {
40
 
41
- $users_badges = mycred_get_users_badges( $user_id );
42
  $all_badges = mycred_get_badge_ids();
43
 
44
  foreach ( $all_badges as $badge_id ) {
@@ -46,11 +54,11 @@ if ( ! function_exists( 'mycred_render_my_badges' ) ) :
46
  echo '<div class="the-badge">';
47
 
48
  // User has not earned badge
49
- if ( ! array_key_exists( $badge_id, $users_badges ) ) {
50
 
51
- $badge = mycred_get_badge( $badge_id );
52
 
53
- $page_id = get_page( $badge_id);
54
 
55
 
56
  $badge->image_width = $width;
@@ -61,31 +69,31 @@ if ( ! function_exists( 'mycred_render_my_badges' ) ) :
61
 
62
 
63
 
64
- if ( $badge->main_image !== false ) {
65
 
66
 
67
 
68
  echo '<div class="demo-badge-image">' . $badge_img . '</div>';
69
 
70
- if($title == 'show'){
71
 
72
 
73
 
74
- echo '<div class="demo-badge-title">' . $badge_title . ' '.'</div>';
75
 
76
- } else {
77
 
78
- echo '<div class="demo-badge-title" style="display:none;">' . $badge_title . ' '.'</div>';
79
 
80
- }
81
 
82
- if($post_excerpt == 'show') {
83
 
84
- echo '<div class="page-excerpt">' . $page_id->post_excerpt . ' '.'</div>';
85
 
86
- } else {
87
- echo '<div class="page-excerpt" style="display:none;">' . $page_id->post_excerpt . ' '.'</div>';;
88
- }
89
 
90
  }
91
 
@@ -95,38 +103,38 @@ if ( ! function_exists( 'mycred_render_my_badges' ) ) :
95
  else {
96
 
97
  $level = $users_badges[ $badge_id ];
98
- $badge = mycred_get_badge( $badge_id, $level );
99
  $badge->image_width = $width;
100
  $badge->image_height = $height;
101
 
102
- $badge_page_id = get_page( $badge_id);
103
 
104
 
105
 
106
- if ( $badge->level_image !== false ) {
107
 
108
 
109
- echo '<div class="demo-badge-image">' . $badge->get_image( $level ) . '</div>';
110
 
111
- if($title == 'show'){
112
 
113
- echo '<div class="demo-badge-title">' . $badge->title . ' '.'</div>';
114
 
115
- }
116
 
117
- else {
118
 
119
- echo '<div class="demo-badge-title" style="display:none;">' . $badge->title . ' '.'</div>';
120
 
121
- }
122
 
123
- if($post_excerpt == 'show') {
124
 
125
- echo '<div class="page-excerpt">' . $badge_page_id->post_excerpt . ' '.'</div>';
126
 
127
- } else {
128
- echo '<div class="page-excerpt" style="display:none;">' . $badge_page_id->post_excerpt . ' '.'</div>';;
129
- }
130
 
131
  }
132
 
@@ -136,7 +144,7 @@ if ( ! function_exists( 'mycred_render_my_badges' ) ) :
136
 
137
  if($title == 'show' || $post_excerpt == 'show') {
138
 
139
- echo '<hr class="badge-line">';
140
  }
141
  else {
142
  echo '';
@@ -149,7 +157,7 @@ if ( ! function_exists( 'mycred_render_my_badges' ) ) :
149
  $output = ob_get_contents();
150
  ob_end_clean();
151
 
152
- return apply_filters( 'mycred_my_badges', $output, $user_id );
153
 
154
  }
155
  endif;
@@ -157,48 +165,55 @@ endif;
157
  /**
158
  * Shortcode: mycred_badges
159
  * Allows you to show all published badges
160
- * @since 1.5
 
161
  * @version 1.1.1
162
  */
163
- if ( ! function_exists( 'mycred_render_badges' ) ) :
164
- function mycred_render_badges( $atts, $template = '' ) {
165
- extract( shortcode_atts( array(
166
- 'width' => MYCRED_BADGE_WIDTH,
167
- 'height' => MYCRED_BADGE_HEIGHT
168
- ), $atts, MYCRED_SLUG . '_badges' ) );
 
 
 
 
 
169
 
170
  $all_badges = mycred_get_badge_ids();
171
 
172
- if ( $template == '' )
173
  $template = '<div class="the-badge row"><div class="col-xs-12"><h3 class="badge-title">%badge_title%</h3><div class="badge-requirements">%requirements%</div><div class="users-with-badge">%count%</div><div class="badge-images">%default_image% %main_image%</div></div></div>';
 
174
 
175
  $output = '<div id="mycred-all-badges">';
176
 
177
- if ( ! empty( $all_badges ) ) {
178
 
179
  foreach ( $all_badges as $badge_id ) {
180
 
181
- $badge = mycred_get_badge( $badge_id, 0 );
182
  $badge->image_width = $width;
183
  $badge->image_height = $height;
184
 
185
  $row = $template;
186
- $row = str_replace( '%badge_title%', $badge->title, $row );
187
- $row = str_replace( '%requirements%', mycred_display_badge_requirements( $badge_id ), $row );
188
- $row = str_replace( '%count%', $badge->earnedby, $row );
189
- $row = str_replace( '%default_image%', $badge->get_image( 'main' ), $row );
190
 
191
- if( mycred_user_has_badge( get_current_user_id(), $badge_id) ) {
192
  $user_id = get_current_user_id();
193
- $badge = mycred_get_badge( $badge_id );
194
- $level = $badge->get_users_current_level( $user_id );
195
- $row = str_replace( '%main_image%', $badge->get_image( $level ), $row );
196
  }
197
  else {
198
- $row = str_replace( '%main_image%', '', $row );
199
  }
200
 
201
- $output .= apply_filters( 'mycred_badges_badge', $row, $badge );
202
 
203
  }
204
 
@@ -206,25 +221,30 @@ if ( ! function_exists( 'mycred_render_badges' ) ) :
206
 
207
  $output .= '</div>';
208
 
209
- return apply_filters( 'mycred_badges', $output );
210
 
211
  }
212
  endif;
213
 
214
  /**
215
  * myCRED Renders Badges List ShortCode
216
- * @param string $atts
217
- * @since 2.1
 
218
  * @version 1.0
219
  */
220
- if( !function_exists( 'mycred_render_badges_list' ) ) :
221
- function mycred_render_badges_list( $atts = '' ) {
 
222
 
223
- extract( shortcode_atts( array(
 
 
224
  'achievement_tabs' => '1'
225
- ),
226
- $atts, MYCRED_SLUG . '_badges_list'
227
- ) );
 
228
 
229
  ob_start();?>
230
 
@@ -239,32 +259,32 @@ if( !function_exists( 'mycred_render_badges_list' ) ) :
239
  </div>
240
 
241
  <?php
242
- if ( $achievement_tabs == 1 ) {
243
 
244
  $badges = mycred_get_categorized_badge_list();
245
 
246
- if ( $badges['category_count'] > 0 ) { ?>
247
  <div class="mycred-badges-list-nav">
248
  <ul class="mycred-badges-list-tabs">
249
  <?php
250
- foreach ( $badges['tabs'] as $id => $element ) {
251
 
252
- echo $element;
253
 
254
- }
255
  ?>
256
  </ul>
257
  </div>
258
  <div class="mycred-badges-list-panels">
259
  <?php
260
- foreach ( $badges['panels'] as $id => $element ) {
261
 
262
- echo $element;
263
 
264
- }
265
  ?>
266
  </div>
267
- <?php
268
  }
269
 
270
  }
@@ -311,37 +331,39 @@ endif;
311
 
312
  /**
313
  * Renders Badge's Evidence ShortCode
314
- * @param string $atts
315
- * @since 2.1
 
316
  * @version 1.0
317
  */
318
- if ( !function_exists( 'mycred_render_badge_evidence' ) ) :
319
- function mycred_render_badge_evidence( $atts = '' ) {
 
320
 
321
  $content = '<div class="mycred-evidence-page">Evidence not found</div>';
322
 
323
- if ( isset( $_GET['uid'] ) && isset( $_GET['bid'] ) ) {
324
 
325
- $user_id = intval( $_GET['uid'] );
326
- $badge_id = intval( $_GET['bid'] );
327
 
328
- $user_info = get_userdata( $user_id );
329
- $badge = mycred_get_badge( $badge_id );
330
 
331
- if ( $user_info && $badge && $badge->open_badge ) {
332
 
333
- $issued_on = mycred_get_user_meta( $user_id, MYCRED_BADGE_KEY . $badge_id, '_issued_on', true );
334
 
335
  $content = '<div class="mycred-evidence-page">
336
  <div class="mycred-left">
337
- <img src="' . $badge->get_earned_image( $user_id ) . '" alt="">
338
  </div>
339
  <div class="mycred-left intro">
340
  <h4 class="mycred-remove-margin">' . $badge->title . '</h4>
341
  <div class="mycred-remove-margin">
342
  <p>Name: '. $user_info->display_name .'</p>
343
  <p>Email: ' . $user_info->user_email . '</p>
344
- <p>Issued On: ' . date( 'Y-m-d\TH:i:sP', $issued_on ) . '</p>
345
  <p><span class="dashicons dashicons-yes-alt"></span> <span class="icon-txt"> Verified</span></p>
346
  </div>
347
  </div>
@@ -357,8 +379,9 @@ if ( !function_exists( 'mycred_render_badge_evidence' ) ) :
357
  }
358
  endif;
359
 
360
- add_action( 'wp_enqueue_scripts', 'enqueue_badge_front_shortcode_scripts' );
361
 
362
- function enqueue_badge_front_shortcode_scripts() {
363
- wp_enqueue_style( 'mycred-badge-front-style', plugins_url( 'assets/css/front.css', myCRED_BADGE ), array(), myCRED_BADGE_VERSION , 'all');
364
- }
 
1
  <?php
2
+ if (! defined('myCRED_VERSION') ) { exit;
3
+ }
4
 
5
  /**
6
  * Shortcode: mycred_my_badges
7
  * Allows you to show the current users earned badges.
8
+ *
9
+ * @since 1.5
10
  * @version 1.2.1
11
  */
12
+ if (! function_exists('mycred_render_my_badges') ) :
13
+ function mycred_render_my_badges( $atts, $content = '' )
14
+ {
15
+
16
+ extract(
17
+ shortcode_atts(
18
+ array(
19
+ 'show' => 'earned',
20
+ 'width' => MYCRED_BADGE_WIDTH,
21
+ 'height' => MYCRED_BADGE_HEIGHT,
22
+ 'user_id' => 'current',
23
+ 'title' => '',
24
+ 'post_excerpt' => ''
25
+ ), $atts, MYCRED_SLUG . '_my_badges'
26
+ )
27
+ );
28
+
29
+ if (! is_user_logged_in() && $user_id == 'current' ) {
30
  return $content;
31
+ }
32
 
33
+ $user_id = mycred_get_user_id($user_id);
34
 
35
  ob_start();
36
 
37
  echo '<div class="row" id="mycred-users-badges"><div class="col-xs-12">';
38
 
39
  // Show only badges that we have earned
40
+ if ($show == 'earned' ) {
41
 
42
+ mycred_display_users_badges($user_id, $width, $height);
43
 
44
  }
45
 
46
  // Show all badges highlighting the ones we earned
47
+ elseif ($show == 'all' ) {
48
 
49
+ $users_badges = mycred_get_users_badges($user_id);
50
  $all_badges = mycred_get_badge_ids();
51
 
52
  foreach ( $all_badges as $badge_id ) {
54
  echo '<div class="the-badge">';
55
 
56
  // User has not earned badge
57
+ if (! array_key_exists($badge_id, $users_badges) ) {
58
 
59
+ $badge = mycred_get_badge($badge_id);
60
 
61
+ $page_id = get_page($badge_id);
62
 
63
 
64
  $badge->image_width = $width;
69
 
70
 
71
 
72
+ if ($badge->main_image !== false ) {
73
 
74
 
75
 
76
  echo '<div class="demo-badge-image">' . $badge_img . '</div>';
77
 
78
+ if($title == 'show') {
79
 
80
 
81
 
82
+ echo '<div class="demo-badge-title">' . $badge_title . ' '.'</div>';
83
 
84
+ } else {
85
 
86
+ echo '<div class="demo-badge-title" style="display:none;">' . $badge_title . ' '.'</div>';
87
 
88
+ }
89
 
90
+ if($post_excerpt == 'show') {
91
 
92
+ echo '<div class="page-excerpt">' . $page_id->post_excerpt . ' '.'</div>';
93
 
94
+ } else {
95
+ echo '<div class="page-excerpt" style="display:none;">' . $page_id->post_excerpt . ' '.'</div>';;
96
+ }
97
 
98
  }
99
 
103
  else {
104
 
105
  $level = $users_badges[ $badge_id ];
106
+ $badge = mycred_get_badge($badge_id, $level);
107
  $badge->image_width = $width;
108
  $badge->image_height = $height;
109
 
110
+ $badge_page_id = get_page($badge_id);
111
 
112
 
113
 
114
+ if ($badge->level_image !== false ) {
115
 
116
 
117
+ echo '<div class="demo-badge-image">' . $badge->get_image($level) . '</div>';
118
 
119
+ if($title == 'show') {
120
 
121
+ echo '<div class="demo-badge-title">' . $badge->title . ' '.'</div>';
122
 
123
+ }
124
 
125
+ else {
126
 
127
+ echo '<div class="demo-badge-title" style="display:none;">' . $badge->title . ' '.'</div>';
128
 
129
+ }
130
 
131
+ if($post_excerpt == 'show') {
132
 
133
+ echo '<div class="page-excerpt">' . $badge_page_id->post_excerpt . ' '.'</div>';
134
 
135
+ } else {
136
+ echo '<div class="page-excerpt" style="display:none;">' . $badge_page_id->post_excerpt . ' '.'</div>';;
137
+ }
138
 
139
  }
140
 
144
 
145
  if($title == 'show' || $post_excerpt == 'show') {
146
 
147
+ echo '<hr class="badge-line">';
148
  }
149
  else {
150
  echo '';
157
  $output = ob_get_contents();
158
  ob_end_clean();
159
 
160
+ return apply_filters('mycred_my_badges', $output, $user_id);
161
 
162
  }
163
  endif;
165
  /**
166
  * Shortcode: mycred_badges
167
  * Allows you to show all published badges
168
+ *
169
+ * @since 1.5
170
  * @version 1.1.1
171
  */
172
+ if (! function_exists('mycred_render_badges') ) :
173
+ function mycred_render_badges( $atts, $template = '' )
174
+ {
175
+ extract(
176
+ shortcode_atts(
177
+ array(
178
+ 'width' => MYCRED_BADGE_WIDTH,
179
+ 'height' => MYCRED_BADGE_HEIGHT
180
+ ), $atts, MYCRED_SLUG . '_badges'
181
+ )
182
+ );
183
 
184
  $all_badges = mycred_get_badge_ids();
185
 
186
+ if ($template == '' ) {
187
  $template = '<div class="the-badge row"><div class="col-xs-12"><h3 class="badge-title">%badge_title%</h3><div class="badge-requirements">%requirements%</div><div class="users-with-badge">%count%</div><div class="badge-images">%default_image% %main_image%</div></div></div>';
188
+ }
189
 
190
  $output = '<div id="mycred-all-badges">';
191
 
192
+ if (! empty($all_badges) ) {
193
 
194
  foreach ( $all_badges as $badge_id ) {
195
 
196
+ $badge = mycred_get_badge($badge_id, 0);
197
  $badge->image_width = $width;
198
  $badge->image_height = $height;
199
 
200
  $row = $template;
201
+ $row = str_replace('%badge_title%', $badge->title, $row);
202
+ $row = str_replace('%requirements%', mycred_display_badge_requirements($badge_id), $row);
203
+ $row = str_replace('%count%', $badge->earnedby, $row);
204
+ $row = str_replace('%default_image%', $badge->get_image('main'), $row);
205
 
206
+ if(mycred_user_has_badge(get_current_user_id(), $badge_id) ) {
207
  $user_id = get_current_user_id();
208
+ $badge = mycred_get_badge($badge_id);
209
+ $level = $badge->get_users_current_level($user_id);
210
+ $row = str_replace('%main_image%', $badge->get_image($level), $row);
211
  }
212
  else {
213
+ $row = str_replace('%main_image%', '', $row);
214
  }
215
 
216
+ $output .= apply_filters('mycred_badges_badge', $row, $badge);
217
 
218
  }
219
 
221
 
222
  $output .= '</div>';
223
 
224
+ return apply_filters('mycred_badges', $output);
225
 
226
  }
227
  endif;
228
 
229
  /**
230
  * myCRED Renders Badges List ShortCode
231
+ *
232
+ * @param string $atts
233
+ * @since 2.1
234
  * @version 1.0
235
  */
236
+ if(!function_exists('mycred_render_badges_list') ) :
237
+ function mycred_render_badges_list( $atts = '' )
238
+ {
239
 
240
+ extract(
241
+ shortcode_atts(
242
+ array(
243
  'achievement_tabs' => '1'
244
+ ),
245
+ $atts, MYCRED_SLUG . '_badges_list'
246
+ )
247
+ );
248
 
249
  ob_start();?>
250
 
259
  </div>
260
 
261
  <?php
262
+ if ($achievement_tabs == 1 ) {
263
 
264
  $badges = mycred_get_categorized_badge_list();
265
 
266
+ if ($badges['category_count'] > 0 ) { ?>
267
  <div class="mycred-badges-list-nav">
268
  <ul class="mycred-badges-list-tabs">
269
  <?php
270
+ foreach ( $badges['tabs'] as $id => $element ) {
271
 
272
+ echo $element;
273
 
274
+ }
275
  ?>
276
  </ul>
277
  </div>
278
  <div class="mycred-badges-list-panels">
279
  <?php
280
+ foreach ( $badges['panels'] as $id => $element ) {
281
 
282
+ echo $element;
283
 
284
+ }
285
  ?>
286
  </div>
287
+ <?php
288
  }
289
 
290
  }
331
 
332
  /**
333
  * Renders Badge's Evidence ShortCode
334
+ *
335
+ * @param string $atts
336
+ * @since 2.1
337
  * @version 1.0
338
  */
339
+ if (!function_exists('mycred_render_badge_evidence') ) :
340
+ function mycred_render_badge_evidence( $atts = '' )
341
+ {
342
 
343
  $content = '<div class="mycred-evidence-page">Evidence not found</div>';
344
 
345
+ if (isset($_GET['uid']) && isset($_GET['bid']) ) {
346
 
347
+ $user_id = intval($_GET['uid']);
348
+ $badge_id = intval($_GET['bid']);
349
 
350
+ $user_info = get_userdata($user_id);
351
+ $badge = mycred_get_badge($badge_id);
352
 
353
+ if ($user_info && $badge && $badge->open_badge ) {
354
 
355
+ $issued_on = mycred_get_user_meta($user_id, MYCRED_BADGE_KEY . $badge_id, '_issued_on', true);
356
 
357
  $content = '<div class="mycred-evidence-page">
358
  <div class="mycred-left">
359
+ <img src="' . $badge->get_earned_image($user_id) . '" alt="">
360
  </div>
361
  <div class="mycred-left intro">
362
  <h4 class="mycred-remove-margin">' . $badge->title . '</h4>
363
  <div class="mycred-remove-margin">
364
  <p>Name: '. $user_info->display_name .'</p>
365
  <p>Email: ' . $user_info->user_email . '</p>
366
+ <p>Issued On: ' . date('Y-m-d\TH:i:sP', $issued_on) . '</p>
367
  <p><span class="dashicons dashicons-yes-alt"></span> <span class="icon-txt"> Verified</span></p>
368
  </div>
369
  </div>
379
  }
380
  endif;
381
 
382
+ add_action('wp_enqueue_scripts', 'enqueue_badge_front_shortcode_scripts');
383
 
384
+ function enqueue_badge_front_shortcode_scripts()
385
+ {
386
+ wp_enqueue_style('mycred-badge-front-style', plugins_url('assets/css/front.css', myCRED_BADGE), array(), myCRED_BADGE_VERSION, 'all');
387
+ }
addons/badges/includes/mycred-open-badge.php CHANGED
@@ -1,296 +1,318 @@
1
  <?php
2
- if ( ! defined( 'myCRED_VERSION' ) ) exit;
 
3
 
4
  /**
5
  * mycred_Open_Badge Class
6
- * @since 2.1
 
7
  * @version 1.0
8
  */
9
- if ( ! class_exists('mycred_Open_Badge') ) :
10
- class mycred_Open_Badge {
 
11
 
12
- public $salt;
13
 
14
- /**
15
- * Construct
16
- */
17
- public function __construct () {
 
18
 
19
- $this->salt = apply_filters( 'mycred_open_badge_salt', 'MYCREDOPENBADGE' );
20
 
21
  }
22
 
23
- public function register_open_badge_routes() {
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
24
 
25
- register_rest_route( 'open-badge', '/assertion/', array(
26
- 'methods' => 'GET',
27
- 'callback' => array( $this, 'get_assertion_data' ),
28
- 'permission_callback' => '__return_true',
29
- ) );
30
 
31
- register_rest_route( 'open-badge', '/info/', array(
32
- 'methods' => 'GET',
33
- 'callback' => array( $this, 'get_badge_info' ),
34
- 'permission_callback' => '__return_true',
35
- ) );
36
 
37
- register_rest_route( 'open-badge', '/issuer/', array(
38
- 'methods' => 'GET',
39
- 'callback' => array( $this, 'get_issuer_data' ),
40
- 'permission_callback' => '__return_true',
41
- ) );
42
-
43
- }
44
 
45
- function bake_users_image( $user_id, $badge_id ) {
 
 
46
 
47
- $badge = mycred_get_badge( $badge_id );
48
 
49
- if ( ! $badge->open_badge ) return;
 
 
 
 
 
 
 
 
 
 
50
 
51
- $wp_upload_dirs = wp_upload_dir();
52
- $basedir = trailingslashit( $wp_upload_dirs[ 'basedir' ] );
53
- $baseurl = trailingslashit( $wp_upload_dirs[ 'baseurl' ] );
 
 
54
 
55
- $folderName = apply_filters( 'mycred_open_badge_folder', 'open_badges' );
56
 
57
- $user_badge_directory = $basedir . $folderName;
58
-
59
- if ( ! file_exists( $user_badge_directory ) && ! is_dir( $user_badge_directory ) ) {
60
- mkdir( $user_badge_directory );
61
- }
62
-
63
- $user_badge_directory = trailingslashit( $user_badge_directory );
64
 
65
- $badge_image = $badge->main_image_url;
66
-
67
- $badge_image_path = str_replace( $baseurl, $basedir, $badge_image );
68
 
69
- $user_info = get_userdata( $user_id );
70
-
71
- $identity = 'sha256$' . hash( 'sha256', $user_info->user_email . $this->salt );
72
-
73
- $json = $this->get_image_json_data( $user_id, $badge_id, $identity, $badge->title, $badge_image );
74
 
75
- $filename = "badge-{$badge_id}-{$user_id}.png";
76
 
77
- $this->bake_image( $badge_image, $badge_image_path, $json, $filename, $user_badge_directory );
78
 
79
- $user_image_url = trailingslashit( $baseurl . $folderName ).$user_id;
 
80
 
81
- $json['user_image'] = trailingslashit( $user_image_url ) . $filename;
82
 
83
- mycred_update_user_meta( $user_id, "open-badge-{$badge_id}-{$user_id}", '', $json );
 
 
 
84
 
85
- }
 
86
 
87
- public function get_assertion_data() {
88
 
89
- $assertion_data = array();
90
 
91
- if ( ! empty( $_GET['uid'] ) && ! empty( $_GET['bid'] ) ) {
92
-
93
- $user_id = intval( $_GET['uid'] );
94
- $badge_id = intval( $_GET['bid'] );
95
 
96
- $user_info = get_userdata( $user_id );
97
- $badge = mycred_get_badge( $badge_id );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
98
 
99
- if ( $user_info && $badge ) {
100
 
101
- mycred_set_current_account( $user_id );
102
 
103
- if( $badge->user_has_badge( $user_id ) ) {
104
 
105
- $identity_id = 'sha256$' . hash( 'sha256', $user_info->user_email . $this->salt );
106
-
107
- $issuedOn = mycred_get_user_meta( $user_id, MYCRED_BADGE_KEY . $badge_id, '_issued_on', true );
108
-
109
- $assertion_data = array(
110
- '@context' => 'https://w3id.org/openbadges/v2',
111
- 'type' => 'Assertion',
112
- 'id' => $this->get_assertion_url( $user_id, $badge_id ),
113
- 'recipient' => array(
114
- 'type' => 'email',
115
- 'hashed' => true,
116
- 'salt' => $this->salt,
117
- 'identity' => $identity_id
118
- ),
119
- 'badge' => $this->get_badge_info_url( $badge_id ),
120
- 'issuedOn' => date( 'Y-m-d\TH:i:sP', $issuedOn ),
121
- 'image' => $badge->main_image_url,
122
- 'verification' => array(
123
- 'type' => 'HostedBadge',
124
- 'verificationProperty' => 'id',
125
- ),
126
- 'evidence' => $this->get_evidence_url( $user_id, $badge_id )
127
- );
128
-
129
- }
130
-
131
- }
132
-
133
- }
134
-
135
- return wp_send_json( $assertion_data );
136
-
137
- }
138
-
139
- public function get_badge_info() {
140
-
141
- $badge_info = array();
142
-
143
- if ( ! empty( $_GET['bid'] ) ) {
144
 
145
- $badge_id = intval( $_GET['bid'] );
146
 
147
- $badge = mycred_get_badge( $badge_id );
148
-
149
- if( $badge ) {
150
-
151
- $badge_info = array(
152
- '@context' => 'https://w3id.org/openbadges/v2',
153
- 'type' => 'BadgeClass',
154
- 'id' => $this->get_badge_info_url( $badge_id ),
155
- 'name' => $badge->title,
156
- 'image' => $badge->main_image_url,
157
- 'description' => '',
158
- 'criteria' => mycred_get_permalink( $badge_id ),
159
- 'issuer' => $this->get_endpoint_url( 'issuer' ),
160
- 'tags' => array()
161
- );
162
-
163
- }
164
 
165
- }
166
 
167
- return wp_send_json( $badge_info );
168
-
169
- }
170
 
171
- public function get_issuer_data() {
172
 
173
- $blog_title = get_bloginfo( 'name' );
174
- $admin_email = get_bloginfo( 'admin_email' );
175
- $blog_url = get_site_url();
176
 
177
- $issuer_data = array(
178
- '@context' => 'https://w3id.org/openbadges/v2',
179
- 'type' => 'Issuer',
180
- 'id' => $this->get_endpoint_url( 'issuer' ),
181
- 'name' => $blog_title,
182
- 'url' => $blog_url,
183
- 'email' => $admin_email
184
- );
185
 
186
- return wp_send_json( $issuer_data );
 
 
 
 
 
 
 
 
 
 
187
 
188
- }
189
 
190
- public function get_image_json_data( $user_id, $badge_id, $identity, $badge_title, $badge_image ) {
191
 
192
- return array(
193
- '@context' => 'https://w3id.org/openbadges/v2',
194
- 'type' => 'Assertion',
195
- 'id' => $this->get_assertion_url( $user_id, $badge_id ),
196
- 'recipient' => array(
197
- 'type' => 'email',
198
- 'hashed' => true,
199
- 'salt' => $this->salt,
200
- 'identity' => $identity
201
- ),
202
- 'badge' => array(
203
- '@context' => 'https://w3id.org/openbadges/v2',
204
- 'type' => 'BadgeClass',
205
- 'id' => $this->get_badge_info_url( $badge_id ),
206
- 'name' => $badge_title,
207
- 'image' => $badge_image,
208
- 'description' => '',
209
- 'criteria' => mycred_get_permalink( $badge_id ),
210
- 'issuer' => $this->get_endpoint_url( 'issuer' ),
211
- 'tags' => [],
212
- ),
213
- 'issuedOn' => date('Y-m-d\TH:i:sP'),
214
- 'image' => $badge_image,
215
- 'verification' => array(
216
- 'type' => 'HostedBadge',
217
- 'verificationProperty' => 'id',
218
- ),
219
- 'evidence' => $this->get_evidence_url( $user_id, $badge_id )
220
- );
221
 
222
- }
 
223
 
224
- public function bake_image( $badge_image, $badge_image_path, $json, $filename, $user_badge_directory ) {
 
 
225
 
226
- $png = file_get_contents( $badge_image );
227
-
228
- if( $png == false ) {
229
- $png = file_get_contents( $badge_image_path, true );
230
- }
 
 
 
231
 
232
- $embed = [
233
- 'openbadges',
234
- '',
235
- '',
236
- '',
237
- '',
238
- ( string ) json_encode( $json ),
239
- ];
240
 
241
- // Glue with null-bytes.
242
- $data = implode( "\0", $embed );
243
 
244
- // Make the CRC.
245
- $crc = pack( "N", crc32( 'iTXt' . $data ) );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
246
 
247
- // Put it all together.
248
- $final = pack( "N", strlen( $data ) ) . 'iTXt' . $data . $crc;
249
 
250
- // What's the length?
251
- $length = strlen( $png );
252
 
253
- // Put this all at the end, before IEND.
254
- // We _should_ be removing all other iTXt blobs with keyword openbadges
255
- // before writing this out.
256
- $png = substr( $png, 0, $length - 12 ) . $final . substr( $png, $length - 12, 12 );
257
-
258
- file_put_contents( $user_badge_directory . '/' . $filename, $png );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
259
 
260
- }
261
 
262
- public function get_endpoint_url( $endpoint ) {
 
263
 
264
- return get_site_url() . '/wp-json/open-badge/' . $endpoint;
265
 
266
- }
267
 
268
- public function get_assertion_url( $user_id, $badge_id ) {
 
269
 
270
- $assertion_url = add_query_arg( 'uid', $user_id, $this->get_endpoint_url( 'assertion' ) );
271
- $assertion_url = add_query_arg( 'bid', $badge_id, $assertion_url );
272
 
273
- return $assertion_url;
274
- }
275
 
276
- public function get_badge_info_url( $badge_id ) {
 
277
 
278
- $badge_info_url = add_query_arg( 'bid', $badge_id, $this->get_endpoint_url( 'info' ) );
279
 
280
- return $badge_info_url;
281
 
282
- }
283
 
284
- public function get_evidence_url( $user_id, $badge_id ) {
 
285
 
286
- $evidence_page_id = mycred_get_evidence_page_id();
287
 
288
- $evidence_url = add_query_arg( 'uid', $user_id, mycred_get_permalink( $evidence_page_id ) );
289
- $evidence_url = add_query_arg( 'bid', $badge_id, $evidence_url );
290
 
291
- return $evidence_url;
292
 
293
- }
294
 
295
- }
296
- endif;
1
  <?php
2
+ if (! defined('myCRED_VERSION') ) { exit;
3
+ }
4
 
5
  /**
6
  * mycred_Open_Badge Class
7
+ *
8
+ * @since 2.1
9
  * @version 1.0
10
  */
11
+ if (! class_exists('mycred_Open_Badge') ) :
12
+ class mycred_Open_Badge
13
+ {
14
 
15
+ public $salt;
16
 
17
+ /**
18
+ * Construct
19
+ */
20
+ public function __construct()
21
+ {
22
 
23
+ $this->salt = apply_filters('mycred_open_badge_salt', 'MYCREDOPENBADGE');
24
 
25
  }
26
 
27
+ public function register_open_badge_routes()
28
+ {
29
+
30
+ register_rest_route(
31
+ 'open-badge', '/assertion/', array(
32
+ 'methods' => 'GET',
33
+ 'callback' => array( $this, 'get_assertion_data' ),
34
+ 'permission_callback' => '__return_true',
35
+ )
36
+ );
37
+
38
+ register_rest_route(
39
+ 'open-badge', '/info/', array(
40
+ 'methods' => 'GET',
41
+ 'callback' => array( $this, 'get_badge_info' ),
42
+ 'permission_callback' => '__return_true',
43
+ )
44
+ );
45
+
46
+ register_rest_route(
47
+ 'open-badge', '/issuer/', array(
48
+ 'methods' => 'GET',
49
+ 'callback' => array( $this, 'get_issuer_data' ),
50
+ 'permission_callback' => '__return_true',
51
+ )
52
+ );
53
+
54
+ }
55
 
56
+ function bake_users_image( $user_id, $badge_id )
57
+ {
 
 
 
58
 
59
+ $badge = mycred_get_badge($badge_id);
 
 
 
 
60
 
61
+ if (! $badge->open_badge ) { return;
62
+ }
 
 
 
 
 
63
 
64
+ $wp_upload_dirs = wp_upload_dir();
65
+ $basedir = trailingslashit($wp_upload_dirs[ 'basedir' ]);
66
+ $baseurl = trailingslashit($wp_upload_dirs[ 'baseurl' ]);
67
 
68
+ $folderName = apply_filters('mycred_open_badge_folder', 'open_badges');
69
 
70
+ $user_badge_directory = $basedir . $folderName;
71
+
72
+ if (! file_exists($user_badge_directory) && ! is_dir($user_badge_directory) ) {
73
+ mkdir($user_badge_directory);
74
+ }
75
+
76
+ $user_badge_directory = trailingslashit($user_badge_directory);
77
+
78
+ $badge_image = $badge->main_image_url;
79
+
80
+ $badge_image_path = str_replace($baseurl, $basedir, $badge_image);
81
 
82
+ $user_info = get_userdata($user_id);
83
+
84
+ $identity = 'sha256$' . hash('sha256', $user_info->user_email . $this->salt);
85
+
86
+ $json = $this->get_image_json_data($user_id, $badge_id, $identity, $badge->title, $badge_image);
87
 
88
+ $filename = "badge-{$badge_id}-{$user_id}.png";
89
 
90
+ $this->bake_image($badge_image, $badge_image_path, $json, $filename, $user_badge_directory);
 
 
 
 
 
 
91
 
92
+ $user_image_url = trailingslashit($baseurl . $folderName).$user_id;
 
 
93
 
94
+ $json['user_image'] = trailingslashit($user_image_url) . $filename;
 
 
 
 
95
 
96
+ mycred_update_user_meta($user_id, "open-badge-{$badge_id}-{$user_id}", '', $json);
97
 
98
+ }
99
 
100
+ public function get_assertion_data()
101
+ {
102
 
103
+ $assertion_data = array();
104
 
105
+ if (! empty($_GET['uid']) && ! empty($_GET['bid']) ) {
106
+
107
+ $user_id = intval($_GET['uid']);
108
+ $badge_id = intval($_GET['bid']);
109
 
110
+ $user_info = get_userdata($user_id);
111
+ $badge = mycred_get_badge($badge_id);
112
 
113
+ if ($user_info && $badge ) {
114
 
115
+ mycred_set_current_account($user_id);
116
 
117
+ if($badge->user_has_badge($user_id) ) {
 
 
 
118
 
119
+ $identity_id = 'sha256$' . hash('sha256', $user_info->user_email . $this->salt);
120
+
121
+ $issuedOn = mycred_get_user_meta($user_id, MYCRED_BADGE_KEY . $badge_id, '_issued_on', true);
122
+
123
+ $assertion_data = array(
124
+ '@context' => 'https://w3id.org/openbadges/v2',
125
+ 'type' => 'Assertion',
126
+ 'id' => $this->get_assertion_url($user_id, $badge_id),
127
+ 'recipient' => array(
128
+ 'type' => 'email',
129
+ 'hashed' => true,
130
+ 'salt' => $this->salt,
131
+ 'identity' => $identity_id
132
+ ),
133
+ 'badge' => $this->get_badge_info_url($badge_id),
134
+ 'issuedOn' => date('Y-m-d\TH:i:sP', $issuedOn),
135
+ 'image' => $badge->main_image_url,
136
+ 'verification' => array(
137
+ 'type' => 'HostedBadge',
138
+ 'verificationProperty' => 'id',
139
+ ),
140
+ 'evidence' => $this->get_evidence_url($user_id, $badge_id)
141
+ );
142
 
143
+ }
144
 
145
+ }
146
 
147
+ }
148
 
149
+ return wp_send_json($assertion_data);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
150
 
151
+ }
152
 
153
+ public function get_badge_info()
154
+ {
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
155
 
156
+ $badge_info = array();
157
 
158
+ if (! empty($_GET['bid']) ) {
 
 
159
 
160
+ $badge_id = intval($_GET['bid']);
161
 
162
+ $badge = mycred_get_badge($badge_id);
 
 
163
 
164
+ if($badge ) {
 
 
 
 
 
 
 
165
 
166
+ $badge_info = array(
167
+ '@context' => 'https://w3id.org/openbadges/v2',
168
+ 'type' => 'BadgeClass',
169
+ 'id' => $this->get_badge_info_url($badge_id),
170
+ 'name' => $badge->title,
171
+ 'image' => $badge->main_image_url,
172
+ 'description' => '',
173
+ 'criteria' => mycred_get_permalink($badge_id),
174
+ 'issuer' => $this->get_endpoint_url('issuer'),
175
+ 'tags' => array()
176
+ );
177
 
178
+ }
179
 
180
+ }
181
 
182
+ return wp_send_json($badge_info);
183
+
184
+ }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
185
 
186
+ public function get_issuer_data()
187
+ {
188
 
189
+ $blog_title = get_bloginfo('name');
190
+ $admin_email = get_bloginfo('admin_email');
191
+ $blog_url = get_site_url();
192
 
193
+ $issuer_data = array(
194
+ '@context' => 'https://w3id.org/openbadges/v2',
195
+ 'type' => 'Issuer',
196
+ 'id' => $this->get_endpoint_url('issuer'),
197
+ 'name' => $blog_title,
198
+ 'url' => $blog_url,
199
+ 'email' => $admin_email
200
+ );
201
 
202
+ return wp_send_json($issuer_data);
 
 
 
 
 
 
 
203
 
204
+ }
 
205
 
206
+ public function get_image_json_data( $user_id, $badge_id, $identity, $badge_title, $badge_image )
207
+ {
208
+
209
+ return array(
210
+ '@context' => 'https://w3id.org/openbadges/v2',
211
+ 'type' => 'Assertion',
212
+ 'id' => $this->get_assertion_url($user_id, $badge_id),
213
+ 'recipient' => array(
214
+ 'type' => 'email',
215
+ 'hashed' => true,
216
+ 'salt' => $this->salt,
217
+ 'identity' => $identity
218
+ ),
219
+ 'badge' => array(
220
+ '@context' => 'https://w3id.org/openbadges/v2',
221
+ 'type' => 'BadgeClass',
222
+ 'id' => $this->get_badge_info_url($badge_id),
223
+ 'name' => $badge_title,
224
+ 'image' => $badge_image,
225
+ 'description' => '',
226
+ 'criteria' => mycred_get_permalink($badge_id),
227
+ 'issuer' => $this->get_endpoint_url('issuer'),
228
+ 'tags' => [],
229
+ ),
230
+ 'issuedOn' => date('Y-m-d\TH:i:sP'),
231
+ 'image' => $badge_image,
232
+ 'verification' => array(
233
+ 'type' => 'HostedBadge',
234
+ 'verificationProperty' => 'id',
235
+ ),
236
+ 'evidence' => $this->get_evidence_url($user_id, $badge_id)
237
+ );
238
 
239
+ }
 
240
 
241
+ public function bake_image( $badge_image, $badge_image_path, $json, $filename, $user_badge_directory )
242
+ {
243
 
244
+ $png = file_get_contents($badge_image);
245
+
246
+ if($png == false ) {
247
+ $png = file_get_contents($badge_image_path, true);
248
+ }
249
+
250
+ $embed = [
251
+ 'openbadges',
252
+ '',
253
+ '',
254
+ '',
255
+ '',
256
+ ( string ) json_encode($json),
257
+ ];
258
+
259
+ // Glue with null-bytes.
260
+ $data = implode("\0", $embed);
261
+
262
+ // Make the CRC.
263
+ $crc = pack("N", crc32('iTXt' . $data));
264
+
265
+ // Put it all together.
266
+ $final = pack("N", strlen($data)) . 'iTXt' . $data . $crc;
267
+
268
+ // What's the length?
269
+ $length = strlen($png);
270
+
271
+ // Put this all at the end, before IEND.
272
+ // We _should_ be removing all other iTXt blobs with keyword openbadges
273
+ // before writing this out.
274
+ $png = substr($png, 0, $length - 12) . $final . substr($png, $length - 12, 12);
275
+
276
+ file_put_contents($user_badge_directory . '/' . $filename, $png);
277
 
278
+ }
279
 
280
+ public function get_endpoint_url( $endpoint )
281
+ {
282
 
283
+ return get_site_url() . '/wp-json/open-badge/' . $endpoint;
284
 
285
+ }
286
 
287
+ public function get_assertion_url( $user_id, $badge_id )
288
+ {
289
 
290
+ $assertion_url = add_query_arg('uid', $user_id, $this->get_endpoint_url('assertion'));
291
+ $assertion_url = add_query_arg('bid', $badge_id, $assertion_url);
292
 
293
+ return $assertion_url;
294
+ }
295
 
296
+ public function get_badge_info_url( $badge_id )
297
+ {
298
 
299
+ $badge_info_url = add_query_arg('bid', $badge_id, $this->get_endpoint_url('info'));
300
 
301
+ return $badge_info_url;
302
 
303
+ }
304
 
305
+ public function get_evidence_url( $user_id, $badge_id )
306
+ {
307
 
308
+ $evidence_page_id = mycred_get_evidence_page_id();
309
 
310
+ $evidence_url = add_query_arg('uid', $user_id, mycred_get_permalink($evidence_page_id));
311
+ $evidence_url = add_query_arg('bid', $badge_id, $evidence_url);
312
 
313
+ return $evidence_url;
314
 
315
+ }
316
 
317
+ }
318
+ endif;
addons/badges/index.php CHANGED
@@ -1,3 +1,3 @@
1
  <?php
2
  // Silence is golden.
3
- ?>
1
  <?php
2
  // Silence is golden.
3
+ ?>
addons/badges/myCRED-addon-badges.php CHANGED
@@ -1070,19 +1070,6 @@ th#badge-users { width: 10%; }
1070
  * @version 1.2
1071
  */
1072
  public function metabox_badge_setup( $post ) {
1073
-
1074
- ?>
1075
-
1076
- <style>
1077
-
1078
- button.button.button-seconary.button-small.remove-badge-level {
1079
- margin-bottom: 5px !important;
1080
- margin-left: 94% !important;
1081
- }
1082
-
1083
- </style>
1084
-
1085
- <?php
1086
 
1087
  $badge = mycred_get_badge( $post->ID );
1088
  $references = mycred_get_all_references();
@@ -1118,8 +1105,8 @@ th#badge-users { width: 10%; }
1118
 
1119
  $level = $level_counter;
1120
 
1121
- $add_level = '<button type="button" class="button button-seconary button-small top-right-corner mt-2" id="badges-add-new-level">' . esc_js( __( 'Add Level', 'mycred' ) ) . '</button>';
1122
- $remove_level = '<button type="button" class="button button-seconary button-small remove-badge-level" data-level="{{level}}">' . esc_js( __( 'Remove Level', 'mycred' ) ) . '</button>';
1123
 
1124
  $level_image = $this->get_level_image( $setup, $level );
1125
  $empty_level = 'empty dashicons';
1070
  * @version 1.2
1071
  */
1072
  public function metabox_badge_setup( $post ) {
 
 
 
 
 
 
 
 
 
 
 
 
 
1073
 
1074
  $badge = mycred_get_badge( $post->ID );
1075
  $references = mycred_get_all_references();
1105
 
1106
  $level = $level_counter;
1107
 
1108
+ $add_level = '<button type="button" class="button button-seconary button-small top-right-corner" id="badges-add-new-level">' . esc_js( __( 'Add Level', 'mycred' ) ) . '</button>';
1109
+ $remove_level = '<button type="button" class="button button-seconary button-small top-right-corner remove-badge-level" data-level="{{level}}">' . esc_js( __( 'Remove Level', 'mycred' ) ) . '</button>';
1110
 
1111
  $level_image = $this->get_level_image( $setup, $level );
1112
  $empty_level = 'empty dashicons';
addons/badges/templates/index.php CHANGED
@@ -1,3 +1,3 @@
1
  <?php
2
  // Silence is golden.
3
- ?>
1
  <?php
2
  // Silence is golden.
3
+ ?>
addons/banking/abstracts/index.php CHANGED
@@ -1,3 +1,3 @@
1
  <?php
2
  // Silence is golden.
3
- ?>
1
  <?php
2
  // Silence is golden.
3
+ ?>
addons/banking/abstracts/mycred-abstract-service.php CHANGED
@@ -1,373 +1,434 @@
1
  <?php
2
- if ( ! defined( 'myCRED_VERSION' ) ) exit;
 
3
 
4
  /**
5
  * myCRED_Service class
6
- * @see http://codex.mycred.me/classes/mycred_service/
7
- * @since 1.2
 
8
  * @version 1.1
9
  */
10
- if ( ! class_exists( 'myCRED_Service' ) ) :
11
- abstract class myCRED_Service {
12
-
13
- // Service ID
14
- public $id;
15
-
16
- // myCRED_Settings Class
17
- public $core;
18
-
19
- // Multipoint types
20
- public $is_main_type = true;
21
- public $mycred_type = MYCRED_DEFAULT_TYPE_KEY;
22
-
23
- // Service Prefs
24
- public $prefs = array();
25
- public $now = 0;
26
-
27
- /**
28
- * Construct
29
- */
30
- function __construct( $args = array(), $service_prefs = NULL, $type = MYCRED_DEFAULT_TYPE_KEY ) {
31
-
32
- if ( ! empty( $args ) ) {
33
- foreach ( $args as $key => $value ) {
34
- $this->$key = $value;
35
- }
36
- }
37
-
38
- // Grab myCRED Settings
39
- $this->core = mycred( $type );
40
- $this->mycred_type = $type;
41
-
42
- if ( $this->mycred_type != MYCRED_DEFAULT_TYPE_KEY )
43
- $this->is_main_type = false;
44
-
45
- // Prep settings
46
- if ( ! empty( $this->defaults ) )
47
- $this->prefs = $this->defaults;
48
-
49
- if ( $service_prefs !== NULL && array_key_exists( $this->id, $service_prefs ) )
50
- $this->prefs = $service_prefs[ $this->id ];
51
-
52
- $this->prefs = wp_parse_args( $this->prefs, $this->defaults );
53
- $this->now = current_time( 'timestamp', 1 );
54
-
55
- }
56
-
57
- /**
58
- * Run
59
- * Must be over-ridden by sub-class!
60
- * @since 1.2
61
- * @version 1.0
62
- */
63
- public function run() {
64
- wp_die( 'function myCRED_Service::run() must be over-ridden in a sub-class.' );
65
- }
66
-
67
- /**
68
- * Preferences
69
- * @since 0.1
70
- * @version 1.0
71
- */
72
- public function preferences() { }
73
-
74
- /**
75
- * Sanitise Preference
76
- * @since 1.2
77
- * @version 1.0
78
- */
79
- public function sanitise_preferences( $post ) {
80
-
81
- return $post;
82
-
83
- }
84
-
85
- /**
86
- * Activate
87
- * @since 1.5.2
88
- * @version 1.0
89
- */
90
- public function activate() { }
91
-
92
- /**
93
- * Deactivate
94
- * @since 1.2
95
- * @version 1.0
96
- */
97
- public function deactivate() { }
98
-
99
- /**
100
- * Ajax Handler
101
- * @since 1.7
102
- * @version 1.0
103
- */
104
- public function ajax_handler() { }
105
-
106
- /**
107
- * User Screen
108
- * @since 1.7
109
- * @version 1.0
110
- */
111
- public function user_screen( $user ) { }
112
-
113
- /**
114
- * Get Field Name
115
- * Returns the field name for the current service
116
- * @since 1.2
117
- * @version 1.1
118
- */
119
- public function field_name( $field = '' ) {
120
-
121
- if ( is_array( $field ) ) {
122
- $array = array();
123
- foreach ( $field as $parent => $child ) {
124
- if ( ! is_numeric( $parent ) )
125
- $array[] = $parent;
126
-
127
- if ( ! empty( $child ) && !is_array( $child ) )
128
- $array[] = $child;
129
- }
130
- $field = '[' . implode( '][', $array ) . ']';
131
- }
132
- else {
133
- $field = '[' . $field . ']';
134
- }
135
-
136
- $option_id = 'mycred_pref_bank';
137
- if ( ! $this->is_main_type )
138
- $option_id = $option_id . '_' . $this->mycred_type;
139
-
140
- return $option_id . '[service_prefs][' . $this->id . ']' . $field;
141
-
142
- }
143
-
144
- /**
145
- * Get Field ID
146
- * Returns the field id for the current service
147
- * @since 1.2
148
- * @version 1.1
149
- */
150
- public function field_id( $field = '' ) {
151
-
152
- if ( is_array( $field ) ) {
153
- $array = array();
154
- foreach ( $field as $parent => $child ) {
155
- if ( ! is_numeric( $parent ) )
156
- $array[] = str_replace( '_', '-', $parent );
157
-
158
- if ( ! empty( $child ) && !is_array( $child ) )
159
- $array[] = str_replace( '_', '-', $child );
160
- }
161
- $field = implode( '-', $array );
162
- }
163
- else {
164
- $field = str_replace( '_', '-', $field );
165
- }
166
-
167
- $option_id = 'mycred_pref_bank';
168
- if ( ! $this->is_main_type )
169
- $option_id = $option_id . '_' . $this->mycred_type;
170
-
171
- $option_id = str_replace( '_', '-', $option_id );
172
- return $option_id . '-' . str_replace( '_', '-', $this->id ) . '-' . $field;
173
-
174
- }
175
-
176
- /**
177
- * Get Days in Year
178
- * @since 1.2
179
- * @version 1.0.2
180
- */
181
- public function get_days_in_year() {
182
-
183
- if ( date( 'L' ) )
184
- $days = 366;
185
- else
186
- $days = 365;
187
-
188
- return apply_filters( 'mycred_banking_days_in_year', $days, $this );
189
-
190
- }
191
-
192
- /**
193
- * Is Large Site?
194
- * @since 1.7
195
- * @version 1.0.1
196
- */
197
- public function is_large_site() {
198
-
199
- $is_large = false;
200
- if ( is_multisite() && wp_is_large_network() )
201
- $is_large = true;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
202
 
203
- else {
204
 
205
- $users = count_users();
206
- if ( $users['total_users'] > 3000 )
207
- $is_large = true;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
208
 
209
- else {
210
-
211
- global $wpdb, $mycred_log_table;
212
-
213
- $total = $wpdb->get_var( "SELECT COUNT(*) FROM {$mycred_log_table};" );
214
- if ( $total !== NULL && $total > 100000 )
215
- $is_large = true;
216
-
217
- }
218
-
219
- }
220
-
221
- return $is_large;
222
-
223
- }
224
-
225
- /**
226
- * Get Excluded User IDs
227
- * @since 1.7
228
- * @version 1.0
229
- */
230
- public function get_excluded_user_ids() {
231
-
232
- global $wpdb;
233
-
234
- $exclude_ids = array();
235
-
236
- if ( strlen( $this->prefs['exclude_ids'] ) > 0 ) {
237
-
238
- foreach ( explode( ',', $this->prefs['exclude_ids'] ) as $user_id ) {
239
- $user_id = absint( preg_replace( "/[^0-9]/", "", $user_id ) );
240
- if ( $user_id === 0 ) continue;
241
- $exclude_ids[] = $user_id;
242
- }
243
-
244
- }
245
-
246
- if ( ! empty( $this->prefs['exclude_roles'] ) ) {
247
-
248
- $args = array();
249
- $args['role__in'] = $this->prefs['exclude_roles'];
250
- $args['fields'] = 'ID';
251
- $user_query = new WP_User_Query( $args );
252
- $user_ids = $user_query->get_results();
253
-
254
- if ( ! empty( $user_ids ) ) {
255
- foreach ( $user_ids as $user_id ) {
256
- if ( in_array( $user_id, $exclude_ids ) ) continue;
257
- $exclude_ids[] = absint( $user_id );
258
- }
259
- }
260
-
261
- }
262
-
263
- if ( $this->core->exclude['list'] != '' ) {
264
-
265
- foreach ( explode( ',', $this->core->exclude['list'] ) as $user_id ) {
266
- $user_id = absint( preg_replace( "/[^0-9]/", "", $user_id ) );
267
- if ( $user_id === 0 || in_array( $user_id, $exclude_ids ) ) continue;
268
- $exclude_ids[] = $user_id;
269
- }
270
-
271
- }
272
-
273
- if ( $this->prefs['min_balance'] != '' && $this->core->number( $this->prefs['min_balance'] ) > $this->core->zero() ) {
274
-
275
- $format = '%d';
276
- if ( $this->core->format['decimals'] > 0 )
277
- $format = '%f';
278
-
279
- $user_ids = $wpdb->get_col( $wpdb->prepare( "SELECT user_id FROM {$wpdb->usermeta} WHERE meta_key = %s AND meta_value < {$format};", $this->mycred_type, $this->prefs['min_balance'] ) );
280
- if ( ! empty( $user_ids ) ) {
281
- foreach ( $user_ids as $user_id ) {
282
- if ( in_array( $user_id, $exclude_ids ) ) continue;
283
- $exclude_ids[] = absint( $user_id );
284
- }
285
- }
286
-
287
- }
288
-
289
- return $exclude_ids;
290
-
291
- }
292
-
293
- /**
294
- * Convert Date to GMT Timestamp
295
- * @since 1.7
296
- * @version 1.0
297
- */
298
- public function date_to_timestamp( $string = '' ) {
299
-
300
- return mycred_date_to_gmt_timestamp( $string );
301
-
302
- }
303
-
304
- /**
305
- * Convert GMT Timestamp to Date
306
- * @since 1.7
307
- * @version 1.0
308
- */
309
- public function timestamp_to_date( $string = '' ) {
310
-
311
- return mycred_gmt_timestamp_to_local( $string );
312
-
313
- }
314
-
315
- /**
316
- * Time Select
317
- * @since 1.7
318
- * @version 1.0
319
- */
320
- public function time_select( $name = '', $id = '', $date = NULL ) {
321
-
322
- $date = ( ( $date !== false && strlen( $date ) > 0 ) ? date( 'H:i', $date ) : '' );
323
- $options = mycred_banking_get_time_options();
324
-
325
- $element = '<select name="' . $name . '" id="' . $id . '" class="form-control">';
326
- foreach ( $options as $time => $label ) {
327
- $element .= '<option value="' . $time . '"';
328
- if ( $date == $time ) $element .= ' selected="selected"';
329
- $element .= '>' . $label . '</option>';
330
- }
331
- $element .= '</select>';
332
-
333
- return $element;
334
-
335
- }
336
-
337
- /**
338
- * Timeframe Dropdown
339
- * @since 1.2
340
- * @version 1.0
341
- */
342
- public function timeframe_dropdown( $pref_id = '', $use_select = true, $hourly = true ) {
343
-
344
- $timeframes = mycred_banking_get_timeframes();
345
- if ( ! $hourly )
346
- unset( $timeframes['hourly'] );
347
-
348
- echo '<select name="' . $this->field_name( $pref_id ) . '" id="' . $this->field_id( $pref_id ) . '" class="form-control">';
349
-
350
- if ( $use_select )
351
- echo '<option value="">' . __( 'Select', 'mycred' ) . '</option>';
352
-
353
- $settings = '';
354
- if ( is_array( $pref_id ) ) {
355
- reset( $pref_id );
356
- $key = key( $pref_id );
357
- $settings = $this->prefs[ $key ][ $pref_id[ $key ] ];
358
- }
359
- elseif ( isset( $this->prefs[ $pref_id ] ) ) {
360
- $settings = $this->prefs[ $pref_id ];
361
- }
362
-
363
- foreach ( $timeframes as $value => $details ) {
364
- echo '<option value="' . $value . '"';
365
- if ( $settings == $value ) echo ' selected="selected"';
366
- echo '>' . $details['label'] . '</option>';
367
- }
368
- echo '</select>';
369
-
370
- }
371
-
372
- }
373
  endif;
1
  <?php
2
+ if (! defined('myCRED_VERSION') ) { exit;
3
+ }
4
 
5
  /**
6
  * myCRED_Service class
7
+ *
8
+ * @see http://codex.mycred.me/classes/mycred_service/
9
+ * @since 1.2
10
  * @version 1.1
11
  */
12
+ if (! class_exists('myCRED_Service') ) :
13
+ abstract class myCRED_Service
14
+ {
15
+
16
+ // Service ID
17
+ public $id;
18
+
19
+ // myCRED_Settings Class
20
+ public $core;
21
+
22
+ // Multipoint types
23
+ public $is_main_type = true;
24
+ public $mycred_type = MYCRED_DEFAULT_TYPE_KEY;
25
+
26
+ // Service Prefs
27
+ public $prefs = array();
28
+ public $now = 0;
29
+
30
+ /**
31
+ * Construct
32
+ */
33
+ function __construct( $args = array(), $service_prefs = null, $type = MYCRED_DEFAULT_TYPE_KEY )
34
+ {
35
+
36
+ if (! empty($args) ) {
37
+ foreach ( $args as $key => $value ) {
38
+ $this->$key = $value;
39
+ }
40
+ }
41
+
42
+ // Grab myCRED Settings
43
+ $this->core = mycred($type);
44
+ $this->mycred_type = $type;
45
+
46
+ if ($this->mycred_type != MYCRED_DEFAULT_TYPE_KEY ) {
47
+ $this->is_main_type = false;
48
+ }
49
+
50
+ // Prep settings
51
+ if (! empty($this->defaults) ) {
52
+ $this->prefs = $this->defaults;
53
+ }
54
+
55
+ if ($service_prefs !== null && array_key_exists($this->id, $service_prefs) ) {
56
+ $this->prefs = $service_prefs[ $this->id ];
57
+ }
58
+
59
+ $this->prefs = wp_parse_args($this->prefs, $this->defaults);
60
+ $this->now = current_time('timestamp', 1);
61
+
62
+ }
63
+
64
+ /**
65
+ * Run
66
+ * Must be over-ridden by sub-class!
67
+ *
68
+ * @since 1.2
69
+ * @version 1.0
70
+ */
71
+ public function run()
72
+ {
73
+ wp_die('function myCRED_Service::run() must be over-ridden in a sub-class.');
74
+ }
75
+
76
+ /**
77
+ * Preferences
78
+ *
79
+ * @since 0.1
80
+ * @version 1.0
81
+ */
82
+ public function preferences()
83
+ {
84
+ }
85
+
86
+ /**
87
+ * Sanitise Preference
88
+ *
89
+ * @since 1.2
90
+ * @version 1.0
91
+ */
92
+ public function sanitise_preferences( $post )
93
+ {
94
+
95
+ return $post;
96
+
97
+ }
98
+
99
+ /**
100
+ * Activate
101
+ *
102
+ * @since 1.5.2
103
+ * @version 1.0
104
+ */
105
+ public function activate()
106
+ {
107
+ }
108
+
109
+ /**
110
+ * Deactivate
111
+ *
112
+ * @since 1.2
113
+ * @version 1.0
114
+ */
115
+ public function deactivate()
116
+ {
117
+ }
118
+
119
+ /**
120
+ * Ajax Handler
121
+ *
122
+ * @since 1.7
123
+ * @version 1.0
124
+ */
125
+ public function ajax_handler()
126
+ {
127
+ }
128
+
129
+ /**
130
+ * User Screen
131
+ *
132
+ * @since 1.7
133
+ * @version 1.0
134
+ */
135
+ public function user_screen( $user )
136
+ {
137
+ }
138
+
139
+ /**
140
+ * Get Field Name
141
+ * Returns the field name for the current service
142
+ *
143
+ * @since 1.2
144
+ * @version 1.1
145
+ */
146
+ public function field_name( $field = '' )
147
+ {
148
+
149
+ if (is_array($field) ) {
150
+ $array = array();
151
+ foreach ( $field as $parent => $child ) {
152
+ if (! is_numeric($parent) ) {
153
+ $array[] = $parent;
154
+ }
155
+
156
+ if (! empty($child) && !is_array($child) ) {
157
+ $array[] = $child;
158
+ }
159
+ }
160
+ $field = '[' . implode('][', $array) . ']';
161
+ }
162
+ else {
163
+ $field = '[' . $field . ']';
164
+ }
165
+
166
+ $option_id = 'mycred_pref_bank';
167
+ if (! $this->is_main_type ) {
168
+ $option_id = $option_id . '_' . $this->mycred_type;
169
+ }
170
+
171
+ return $option_id . '[service_prefs][' . $this->id . ']' . $field;
172
+
173
+ }
174
+
175
+ /**
176
+ * Get Field ID
177
+ * Returns the field id for the current service
178
+ *
179
+ * @since 1.2
180
+ * @version 1.1
181
+ */
182
+ public function field_id( $field = '' )
183
+ {
184
+
185
+ if (is_array($field) ) {
186
+ $array = array();
187
+ foreach ( $field as $parent => $child ) {
188
+ if (! is_numeric($parent) ) {
189
+ $array[] = str_replace('_', '-', $parent);
190
+ }
191
+
192
+ if (! empty($child) && !is_array($child) ) {
193
+ $array[] = str_replace('_', '-', $child);
194
+ }
195
+ }
196
+ $field = implode('-', $array);
197
+ }
198
+ else {
199
+ $field = str_replace('_', '-', $field);
200
+ }
201
+
202
+ $option_id = 'mycred_pref_bank';
203
+ if (! $this->is_main_type ) {
204
+ $option_id = $option_id . '_' . $this->mycred_type;
205
+ }
206
+
207
+ $option_id = str_replace('_', '-', $option_id);
208
+ return $option_id . '-' . str_replace('_', '-', $this->id) . '-' . $field;
209
+
210
+ }
211
+
212
+ /**
213
+ * Get Days in Year
214
+ *
215
+ * @since 1.2
216
+ * @version 1.0.2
217
+ */
218
+ public function get_days_in_year()
219
+ {
220
+
221
+ if (date('L') ) {
222
+ $days = 366;
223
+ } else {
224
+ $days = 365;
225
+ }
226
+
227
+ return apply_filters('mycred_banking_days_in_year', $days, $this);
228
+
229
+ }
230
+
231
+ /**
232
+ * Is Large Site?
233
+ *
234
+ * @since 1.7
235
+ * @version 1.0.1
236
+ */
237
+ public function is_large_site()
238
+ {
239
+
240
+ $is_large = false;
241
+ if (is_multisite() && wp_is_large_network() ) {
242
+ $is_large = true;
243
+
244
+ } else {
245
+
246
+ $users = count_users();
247
+ if ($users['total_users'] > 3000 ) {
248
+ $is_large = true;
249
+
250
+ } else {
251
+
252
+ global $wpdb, $mycred_log_table;
253
+
254
+ $total = $wpdb->get_var("SELECT COUNT(*) FROM {$mycred_log_table};");
255
+ if ($total !== null && $total > 100000 ) {
256
+ $is_large = true;
257
+ }
258
+
259
+ }
260
+
261
+ }
262
+
263
+ return $is_large;
264
+
265
+ }
266
+
267
+ /**
268
+ * Get Excluded User IDs
269
+ *
270
+ * @since 1.7
271
+ * @version 1.0
272
+ */
273
+ public function get_excluded_user_ids()
274
+ {
275
+
276
+ global $wpdb;
277
+
278
+ $exclude_ids = array();
279
+
280
+ if (strlen($this->prefs['exclude_ids']) > 0 ) {
281
+
282
+ foreach ( explode(',', $this->prefs['exclude_ids']) as $user_id ) {
283
+ $user_id = absint(preg_replace("/[^0-9]/", "", $user_id));
284
+ if ($user_id === 0 ) { continue;
285
+ }
286
+ $exclude_ids[] = $user_id;
287
+ }
288
+
289
+ }
290
+
291
+ if (! empty($this->prefs['exclude_roles']) ) {
292
+
293
+ $args = array();
294
+ $args['role__in'] = $this->prefs['exclude_roles'];
295
+ $args['fields'] = 'ID';
296
+ $user_query = new WP_User_Query($args);
297
+ $user_ids = $user_query->get_results();
298
+
299
+ if (! empty($user_ids) ) {
300
+ foreach ( $user_ids as $user_id ) {
301
+ if (in_array($user_id, $exclude_ids) ) { continue;
302
+ }
303
+ $exclude_ids[] = absint($user_id);
304
+ }
305
+ }
306
 
307
+ }
308
 
309
+ if ($this->core->exclude['list'] != '' ) {
310
+
311
+ foreach ( explode(',', $this->core->exclude['list']) as $user_id ) {
312
+ $user_id = absint(preg_replace("/[^0-9]/", "", $user_id));
313
+ if ($user_id === 0 || in_array($user_id, $exclude_ids) ) { continue;
314
+ }
315
+ $exclude_ids[] = $user_id;
316
+ }
317
+
318
+ }
319
+
320
+ if ($this->prefs['min_balance'] != '' && $this->core->number($this->prefs['min_balance']) > $this->core->zero() ) {
321
+
322
+ $format = '%d';
323
+ if ($this->core->format['decimals'] > 0 ) {
324
+ $format = '%f';
325
+ }
326
+
327
+ $user_ids = $wpdb->get_col($wpdb->prepare("SELECT user_id FROM {$wpdb->usermeta} WHERE meta_key = %s AND meta_value < {$format};", $this->mycred_type, $this->prefs['min_balance']));
328
+ if (! empty($user_ids) ) {
329
+ foreach ( $user_ids as $user_id ) {
330
+ if (in_array($user_id, $exclude_ids) ) { continue;
331
+ }
332
+ $exclude_ids[] = absint($user_id);
333
+ }
334
+ }
335
+
336
+ }
337
+
338
+ return $exclude_ids;
339
 
340
+ }
341
+
342
+ /**
343
+ * Convert Date to GMT Timestamp
344
+ *
345
+ * @since 1.7
346
+ * @version 1.0
347
+ */
348
+ public function date_to_timestamp( $string = '' )
349
+ {
350
+
351
+ return mycred_date_to_gmt_timestamp($string);
352
+
353
+ }
354
+
355
+ /**
356
+ * Convert GMT Timestamp to Date
357
+ *
358
+ * @since 1.7
359
+ * @version 1.0
360
+ */
361
+ public function timestamp_to_date( $string = '' )
362
+ {
363
+
364
+ return mycred_gmt_timestamp_to_local($string);
365
+
366
+ }
367
+
368
+ /**
369
+ * Time Select
370
+ *
371
+ * @since 1.7
372
+ * @version 1.0
373
+ */
374
+ public function time_select( $name = '', $id = '', $date = null )
375
+ {
376
+
377
+ $date = ( ( $date !== false && strlen($date) > 0 ) ? date('H:i', $date) : '' );
378
+ $options = mycred_banking_get_time_options();
379
+
380
+ $element = '<select name="' . $name . '" id="' . $id . '" class="form-control">';
381
+ foreach ( $options as $time => $label ) {
382
+ $element .= '<option value="' . $time . '"';
383
+ if ($date == $time ) { $element .= ' selected="selected"';
384
+ }
385
+ $element .= '>' . $label . '</option>';
386
+ }
387
+ $element .= '</select>';
388
+
389
+ return $element;
390
+
391
+ }
392
+
393
+ /**
394
+ * Timeframe Dropdown
395
+ *
396
+ * @since 1.2
397
+ * @version 1.0
398
+ */
399
+ public function timeframe_dropdown( $pref_id = '', $use_select = true, $hourly = true )
400
+ {
401
+
402
+ $timeframes = mycred_banking_get_timeframes();
403
+ if (! $hourly ) {
404
+ unset($timeframes['hourly']);
405
+ }
406
+
407
+ echo '<select name="' . $this->field_name($pref_id) . '" id="' . $this->field_id($pref_id) . '" class="form-control">';
408
+
409
+ if ($use_select ) {
410
+ echo '<option value="">' . __('Select', 'mycred') . '</option>';
411
+ }
412
+
413
+ $settings = '';
414
+ if (is_array($pref_id) ) {
415
+ reset($pref_id);
416
+ $key = key($pref_id);
417
+ $settings = $this->prefs[ $key ][ $pref_id[ $key ] ];
418
+ }
419
+ elseif (isset($this->prefs[ $pref_id ]) ) {
420
+ $settings = $this->prefs[ $pref_id ];
421
+ }
422
+
423
+ foreach ( $timeframes as $value => $details ) {
424
+ echo '<option value="' . $value . '"';
425
+ if ($settings == $value ) { echo ' selected="selected"';
426
+ }
427
+ echo '>' . $details['label'] . '</option>';
428
+ }
429
+ echo '</select>';
430
+
431
+ }
432
+
433
+ }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
434
  endif;
addons/banking/assets/index.php CHANGED
@@ -1,3 +1,3 @@
1
  <?php
2
  // Silence is golden.
3
- ?>
1
  <?php
2
  // Silence is golden.
3
+ ?>
addons/banking/assets/js/index.php CHANGED
@@ -1,3 +1,3 @@
1
  <?php
2
  // Silence is golden.
3
- ?>
1
  <?php
2
  // Silence is golden.
3
+ ?>
addons/banking/includes/index.php CHANGED
@@ -1,3 +1,3 @@
1
  <?php
2
  // Silence is golden.
3
- ?>
1
  <?php
2
  // Silence is golden.
3
+ ?>
addons/banking/includes/mycred-banking-functions.php CHANGED
@@ -1,32 +1,37 @@
1
  <?php
2
- if ( ! defined( 'myCRED_VERSION' ) ) exit;
 
3
 
4
  /**
5
  * Get Next Payout
6
  * Adds seconds to a given time based on the payout period set.
7
- * @since 1.7
 
8
  * @version 1.0
9
  */
10
- if ( ! function_exists( 'mycred_get_banking_addon_settings' ) ) :
11
- function mycred_get_banking_addon_settings( $service = NULL, $point_type = MYCRED_DEFAULT_TYPE_KEY ) {
 
12
 
13
- $default = array(
14
- 'active' => array(),
15
- 'services' => array(),
16
- 'service_prefs' => array()
17
- );
18
 
19
- $option_id = 'mycred_pref_bank';
20
- if ( $point_type != MYCRED_DEFAULT_TYPE_KEY )
21
- $option_id .= '_' . $point_type;
 
22
 
23
- $settings = mycred_get_option( $option_id, $default );
24
- $settings = wp_parse_args( $settings, $default );
25
 
26
- if ( $service !== NULL && array_key_exists( $service, $settings['service_prefs'] ) )
27
- $settings = $settings['service_prefs'][ $service ];
 
28
 
29
- return $settings;
30
 
31
- }
32
  endif;
1
  <?php
2
+ if (! defined('myCRED_VERSION') ) { exit;
3
+ }
4
 
5
  /**
6
  * Get Next Payout
7
  * Adds seconds to a given time based on the payout period set.
8
+ *
9
+ * @since 1.7
10
  * @version 1.0
11
  */
12
+ if (! function_exists('mycred_get_banking_addon_settings') ) :
13
+ function mycred_get_banking_addon_settings( $service = null, $point_type = MYCRED_DEFAULT_TYPE_KEY )
14
+ {
15
 
16
+ $default = array(
17
+ 'active' => array(),
18
+ 'services' => array(),
19
+ 'service_prefs' => array()
20
+ );
21
 
22
+ $option_id = 'mycred_pref_bank';
23
+ if ($point_type != MYCRED_DEFAULT_TYPE_KEY ) {
24
+ $option_id .= '_' . $point_type;
25
+ }
26
 
27
+ $settings = mycred_get_option($option_id, $default);
28
+ $settings = wp_parse_args($settings, $default);
29
 
30
+ if ($service !== null && array_key_exists($service, $settings['service_prefs']) ) {
31
+ $settings = $settings['service_prefs'][ $service ];
32
+ }
33
 
34
+ return $settings;
35
 
36
+ }
37
  endif;
addons/banking/index.php CHANGED
@@ -1,3 +1,3 @@
1
  <?php
2
  // Silence is golden.
3
- ?>
1
  <?php
2
  // Silence is golden.
3
+ ?>
addons/banking/services/index.php CHANGED
@@ -1,3 +1,3 @@
1
  <?php
2
  // Silence is golden.
3
- ?>
1
  <?php
2
  // Silence is golden.
3
+ ?>
addons/banking/services/mycred-service-central.php CHANGED
@@ -1,189 +1,213 @@
1
  <?php
2
- if ( ! defined( 'myCRED_VERSION' ) ) exit;
 
3
 
4
  /**
5
  * myCRED Bank Service - Central Bank
6
- * @since 1.5.2
 
7
  * @version 1.0.1
8
  */
9
- if ( ! class_exists( 'myCRED_Banking_Service_Central' ) ) :
10
- class myCRED_Banking_Service_Central extends myCRED_Service {
11
-
12
- /**
13
- * Construct
14
- */
15
- function __construct( $service_prefs, $type = MYCRED_DEFAULT_TYPE_KEY ) {
16
-
17
- parent::__construct( array(
18
- 'id' => 'central',
19
- 'defaults' => array(
20
- 'bank_id' => '',
21
- 'ignore_manual' => 1
22
- )
23
- ), $service_prefs, $type );
24
-
25
- }
26
-
27
- /**
28
- * Run
29
- * @since 1.5.2
30
- * @version 1.0
31
- */
32
- public function run() {
33
-
34
- add_filter( 'mycred_add', array( $this, 'mycred_add' ), 1, 3 );
35
- add_action( 'wp_ajax_get_bank_accounts', array( $this, 'get_bank_accounts' ) );
36
-
37
- }
38
-
39
- /**
40
- * Add
41
- * @since 1.5.2
42
- * @version 1.0.1
43
- */
44
- public function mycred_add( $reply, $request, $mycred ) {
45
-
46
- // Make sure we are in the correct point type
47
- if ( $this->mycred_type != $mycred->cred_id || $reply === false ) return $reply;
48
-
49
- // Check manual
50
- if ( isset( $this->prefs['ignore_manual'] ) && $this->prefs['ignore_manual'] == 0 && $request['ref'] == 'manual' ) return $reply;
51
-
52
- // Instances to ignore
53
- if ( in_array( $request['ref'], apply_filters( 'mycred_central_banking_ignore', array( 'interest', 'recurring_payout', 'transfer' ), $this ) ) ) return $reply;
54
-
55
- extract( $request );
56
-
57
- // Make sure that the request is not for our bank account
58
- //if ( $user_id == $this->prefs['bank_id'] ) return $reply;
59
-
60
- // Get the banks balance
61
- $bank_balance = $mycred->get_users_balance( $this->prefs['bank_id'], $this->mycred_type );
62
-
63
- // User is to lose points
64
- if ( $amount < 0 ) {
 
 
 
 
 
 
 
 
 
 
 
65
 
66
- // Add the points getting deducted to our bank account
67
- $mycred->update_users_balance( $this->prefs['bank_id'], abs( $amount ), $this->mycred_type );
68
 
69
- // Log event
70
- $mycred->add_to_log( $ref, $this->prefs['bank_id'], abs( $amount ), $entry, $ref_id, $data, $this->mycred_type );
71
 
72
- }
73
 
74
- // User is to gain points
75
- else {
76
 
77
- // First make sure the bank is not bust
78
- if ( $bank_balance <= $mycred->zero() ) return false;
 
79
 
80
- // Second we check if the bank is solvent
81
- if ( $bank_balance-$amount < $mycred->zero() ) return false;
 
82
 
83
- // If we have come this far, the bank has sufficient funds so lets deduct
84
- $mycred->update_users_balance( $this->prefs['bank_id'], 0-$amount, $this->mycred_type );
85
 
86
- // Log event
87
- $mycred->add_to_log( $ref, $this->prefs['bank_id'], 0-$amount, $entry, $ref_id, $data, $this->mycred_type );
88
 
89
- }
90
 
91
- // Return the result
92
- return $reply;
93
 
94
- }
95
 
96
- /**
97
- * Preference for Central Bank
98
- * @since 1.5.2
99
- * @version 1.1
100
- */
101
- public function preferences() {
 
 
102
 
103
- $prefs = $this->prefs;
104
 
105
- if ( ! empty( $this->prefs['bank_id'] ) )
106
- $user = get_userdata( $this->prefs['bank_id'] );
107
- ?>
 
108
  <div class="row">
109
- <div class="col-xs-12">
110
- <div class="row">
111
- <div class="col-sm-4">
112
- <div class="form-group">
113
- <label for="<?php echo $this->field_id( 'bank_id' ); ?>"><?php _e( 'Select Central Deposit Account', 'mycred' ); ?></label>
114
- <select name="<?php echo $this->field_name( 'bank_id' ); ?>" id="<?php echo $this->field_id( 'bank_id' ); ?>" class="form-control mycred_bank_id_select2" style="width:100%;">
115
- <?php if ( ! empty( $this->prefs['bank_id'] ) ): ?>
116
- <option value="<?php echo esc_attr( $user->ID );?>" selected="selected">
117
- <?php echo esc_html( '#'. $user->ID .' - '. $user->display_name . ' (' . $user->user_email . ')' );?>
118
- </option>
119
- <?php endif; ?>
120
- </select>
121
- </div>
122
- <p><span class="description"><?php _e( 'The ID of the user representing the central bank.', 'mycred' ); ?></span></p>
123
- </div>
124
- <div class="col-sm-8">
125
- <div class="form-group">
126
- <div class="checkbox">
127
- <label for="<?php echo $this->field_id( 'ignore_manual' ); ?>" class="manual-adjust">
128
- <input type="checkbox" name="<?php echo $this->field_name( 'ignore_manual' ); ?>" id="<?php echo $this->field_id( 'ignore_manual' ); ?>" value="1"<?php checked( $this->prefs['ignore_manual'], 1 ); ?>> <?php _e( 'Ignore Manual Adjustments', 'mycred' ); ?>
129
- </label>
130
- </div>
131
- </div>
132
- </div>
133
- </div>
134
- </div>
135
  </div>
136
- <?php
137
-
138
- do_action( 'mycred_banking_central', $this );
139
-
140
- }
141
-
142
- /**
143
- * Sanitise Preferences
144
- * @since 1.5.2
145
- * @version 1.1
146
- */
147
- function sanitise_preferences( $post ) {
148
-
149
- $new_settings = array();
150
- $new_settings['bank_id'] = absint( $post['bank_id'] );
151
- $new_settings['ignore_manual'] = ( isset( $post['ignore_manual'] ) ) ? absint( $post['ignore_manual'] ) : 0;
152
-
153
- return apply_filters( 'mycred_banking_save_central', $new_settings, $this );
154
-
155
- }
156
-
157
- /**
158
- * Sanitise Preferences
159
- * @since 1.5.2
160
- * @version 1.1
161
- */
162
- public function get_bank_accounts() {
163
-
164
- $search_term = sanitize_text_field( $_GET['search'] );
165
- $page_no = sanitize_text_field( $_GET['page'] );
166
-
167
- $users_query = new WP_User_Query( array(
168
- 'search' => '*'. $search_term .'*',
169
- 'search_columns' => array(
170
- 'ID',
171
- 'user_login',
172
- 'user_nicename',
173
- 'user_email',
174
- 'display_name'
175
- ),
176
- 'fields' => array( 'ID', 'display_name', 'user_email' ),
177
- 'number' => 10,
178
- 'offset' => ( intval( $page_no ) - 1 ) * 10,
179
- 'orderby' => 'display_name'
180
- ) );
181
- $users = $users_query->get_results();
182
-
183
- echo json_encode( array( 'users' => $users, 'more' => ! empty( $users ) ) );
184
- die;
185
-
186
- }
187
-
188
- }
189
- endif;
 
 
 
 
 
 
1
  <?php
2
+ if (! defined('myCRED_VERSION') ) { exit;
3
+ }
4
 
5
  /**
6
  * myCRED Bank Service - Central Bank
7
+ *
8
+ * @since 1.5.2
9
  * @version 1.0.1
10
  */
11
+ if (! class_exists('myCRED_Banking_Service_Central') ) :
12
+ class myCRED_Banking_Service_Central extends myCRED_Service
13
+ {
14
+
15
+ /**
16
+ * Construct
17
+ */
18
+ function __construct( $service_prefs, $type = MYCRED_DEFAULT_TYPE_KEY )
19
+ {
20
+
21
+ parent::__construct(
22
+ array(
23
+ 'id' => 'central',
24
+ 'defaults' => array(
25
+ 'bank_id' => '',
26
+ 'ignore_manual' => 1
27
+ )
28
+ ), $service_prefs, $type
29
+ );
30
+
31
+ }
32
+
33
+ /**
34
+ * Run
35
+ *
36
+ * @since 1.5.2
37
+ * @version 1.0
38
+ */
39
+ public function run()
40
+ {
41
+
42
+ add_filter('mycred_add', array( $this, 'mycred_add' ), 1, 3);
43
+ add_action('wp_ajax_get_bank_accounts', array( $this, 'get_bank_accounts' ));
44
+
45
+ }
46
+
47
+ /**
48
+ * Add
49
+ *
50
+ * @since 1.5.2
51
+ * @version 1.0.1
52
+ */
53
+ public function mycred_add( $reply, $request, $mycred )
54
+ {
55
+
56
+ // Make sure we are in the correct point type
57
+ if ($this->mycred_type != $mycred->cred_id || $reply === false ) { return $reply;
58
+ }
59
+
60
+ // Check manual
61
+ if (isset($this->prefs['ignore_manual']) && $this->prefs['ignore_manual'] == 0 && $request['ref'] == 'manual' ) { return $reply;
62
+ }
63
+
64
+ // Instances to ignore
65
+ if (in_array($request['ref'], apply_filters('mycred_central_banking_ignore', array( 'interest', 'recurring_payout', 'transfer' ), $this)) ) { return $reply;
66
+ }
67
+
68
+ extract($request);
69
+
70
+ // Make sure that the request is not for our bank account
71
+ //if ( $user_id == $this->prefs['bank_id'] ) return $reply;
72
+
73
+ // Get the banks balance
74
+ $bank_balance = $mycred->get_users_balance($this->prefs['bank_id'], $this->mycred_type);
75
+
76
+ // User is to lose points
77
+ if ($amount < 0 ) {
78
 
79
+ // Add the points getting deducted to our bank account
80
+ $mycred->update_users_balance($this->prefs['bank_id'], abs($amount), $this->mycred_type);
81
 
82
+ // Log event
83
+ $mycred->add_to_log($ref, $this->prefs['bank_id'], abs($amount), $entry, $ref_id, $data, $this->mycred_type);
84
 
85
+ }
86
 
87
+ // User is to gain points
88
+ else {
89
 
90
+ // First make sure the bank is not bust
91
+ if ($bank_balance <= $mycred->zero() ) { return false;
92
+ }
93
 
94
+ // Second we check if the bank is solvent
95
+ if ($bank_balance-$amount < $mycred->zero() ) { return false;
96
+ }
97
 
98
+ // If we have come this far, the bank has sufficient funds so lets deduct
99
+ $mycred->update_users_balance($this->prefs['bank_id'], 0-$amount, $this->mycred_type);
100
 
101
+ // Log event
102
+ $mycred->add_to_log($ref, $this->prefs['bank_id'], 0-$amount, $entry, $ref_id, $data, $this->mycred_type);
103
 
104
+ }
105
 
106
+ // Return the result
107
+ return $reply;
108
 
109
+ }
110
 
111
+ /**
112
+ * Preference for Central Bank
113
+ *
114
+ * @since 1.5.2
115
+ * @version 1.1
116
+ */
117
+ public function preferences()
118
+ {
119
 
120
+ $prefs = $this->prefs;
121
 
122
+ if (! empty($this->prefs['bank_id']) ) {
123
+ $user = get_userdata($this->prefs['bank_id']);
124
+ }
125
+ ?>
126
  <div class="row">
127
+ <div class="col-xs-12">
128
+ <div class="row">
129
+ <div class="col-sm-4">
130
+ <div class="form-group">
131
+ <label for="<?php echo $this->field_id('bank_id'); ?>"><?php _e('Select Central Deposit Account', 'mycred'); ?></label>
132
+ <select name="<?php echo $this->field_name('bank_id'); ?>" id="<?php echo $this->field_id('bank_id'); ?>" class="form-control mycred_bank_id_select2" style="width:100%;">
133
+ <?php if (! empty($this->prefs['bank_id']) ) : ?>
134
+ <option value="<?php echo esc_attr($user->ID);?>" selected="selected">
135
+ <?php echo esc_html('#'. $user->ID .' - '. $user->display_name . ' (' . $user->user_email . ')');?>
136
+ </option>
137
+ <?php endif; ?>
138
+ </select>
139
+ </div>
140
+ <p><span class="description"><?php _e('The ID of the user representing the central bank.', 'mycred'); ?></span></p>
141
+ </div>
142
+ <div class="col-sm-8">
143
+ <div class="form-group">
144
+ <div class="checkbox">
145
+ <label for="<?php echo $this->field_id('ignore_manual'); ?>" class="manual-adjust">
146
+ <input type="checkbox" name="<?php echo $this->field_name('ignore_manual'); ?>" id="<?php echo $this->field_id('ignore_manual'); ?>" value="1"<?php checked($this->prefs['ignore_manual'], 1); ?>> <?php _e('Ignore Manual Adjustments', 'mycred'); ?>
147
+ </label>
148
+ </div>
149
+ </div>
150
+ </div>
151
+ </div>
152
+ </div>
153
  </div>
154
+ <?php
155
+
156
+ do_action('mycred_banking_central', $this);
157
+
158
+ }
159
+
160
+ /**
161
+ * Sanitise Preferences
162
+ *
163
+ * @since 1.5.2
164
+ * @version 1.1
165
+ */
166
+ function sanitise_preferences( $post )
167
+ {
168
+
169
+ $new_settings = array();
170
+ $new_settings['bank_id'] = absint($post['bank_id']);
171
+ $new_settings['ignore_manual'] = ( isset($post['ignore_manual']) ) ? absint($post['ignore_manual']) : 0;
172
+
173
+ return apply_filters('mycred_banking_save_central', $new_settings, $this);
174
+
175
+ }
176
+
177
+ /**
178
+ * Sanitise Preferences
179
+ *
180
+ * @since 1.5.2
181
+ * @version 1.1
182
+ */
183
+ public function get_bank_accounts()
184
+ {
185
+
186
+ $search_term = sanitize_text_field($_GET['search']);
187
+ $page_no = sanitize_text_field($_GET['page']);
188
+
189
+ $users_query = new WP_User_Query(
190
+ array(
191
+ 'search' => '*'. $search_term .'*',
192
+ 'search_columns' => array(
193
+ 'ID',
194
+ 'user_login',
195
+ 'user_nicename',
196
+ 'user_email',
197
+ 'display_name'
198
+ ),
199
+ 'fields' => array( 'ID', 'display_name', 'user_email' ),
200
+ 'number' => 10,
201
+ 'offset' => ( intval($page_no) - 1 ) * 10,
202
+ 'orderby' => 'display_name'
203
+ )
204
+ );
205
+ $users = $users_query->get_results();
206
+
207
+ echo json_encode(array( 'users' => $users, 'more' => ! empty($users) ));
208
+ die;
209
+
210
+ }
211
+
212
+ }
213
+ endif;
addons/buy-creds/abstracts/index.php CHANGED
@@ -1,3 +1,3 @@
1
  <?php
2
  // Silence is golden.
3
- ?>
1
  <?php
2
  // Silence is golden.
3
+ ?>
addons/buy-creds/abstracts/mycred-abstract-payment-gateway.php CHANGED
@@ -1,2286 +1,2383 @@
1
  <?php
2
- if ( ! defined( 'myCRED_VERSION' ) ) exit;
 
3
 
4
  /**
5
  * myCRED_Payment_Gateway class
6
- * @see http://codex.mycred.me/classes/mycred_payment_gateway/
7
- * @since 0.1
 
8
  * @version 1.3
9
  */
10
- if ( ! class_exists( 'myCRED_Payment_Gateway' ) ) :
11
- abstract class myCRED_Payment_Gateway {
12
-
13
- /**
14
- * The Gateways Unique ID
15
- */
16
- public $id = false;
17
-
18
- /**
19
- * Gateway Label
20
- */
21
- public $label = '';
22
-
23
- /**
24
- * Indicates if the gateway is operating in sandbox mode or not
25
- */
26
- public $sandbox_mode = false;
27
-
28
- /**
29
- * The gateways logo URL
30
- */
31
- public $gateway_logo_url = '';
32
-
33
- /**
34
- * Gateways Settings
35
- */
36
- public $prefs = false;
37
-
38
- /**
39
- * Main Point Type Settings
40
- */
41
- public $core;
42
-
43
- /**
44
- * buyCRED Add-on Settings
45
- */
46
- public $buycred = false;
47
-
48
- /**
49
- * The point type being purchased
50
- */
51
- public $point_type = '';
52
-
53
- /**
54
- * The point amount being purchased
55
- */
56
- public $amount = 0;
57
-
58
- /**
59
- * The buyers ID
60
- */
61
- public $buyer_id = false;
62
-
63
- /**
64
- * The recipients ID
65
- */
66
- public $recipient_id = false;
67
-
68
- /**
69
- * Indicates if this is a gift or not
70
- */
71
- public $gifting = false;
72
-
73
- /**
74
- * Indicates if this is a valid purchase request
75
- */
76
- public $valid_request = false;
77
-
78
- /**
79
- * The current users ID
80
- */
81
- public $current_user_id = 0;
82
-
83
- /**
84
- * Redirect fields
85
- */
86
- public $redirect_fields = array();
87
-
88
- /**
89
- * Redirect URL
90
- */
91
- public $redirect_to = '';
92
-
93
- public $errors = array();
94
-
95
- /**
96
- * Toggle ID
97
- */
98
- public $toggle_id = '';
99
-
100
- /**
101
- * Limit Setting
102
- */
103
- public $buycred_limit = array();
104
-
105
- protected $response;
106
- protected $request;
107
- protected $status;
108
-
109
- protected $processing_log = NULL;
110
-
111
- /**
112
- * Construct
113
- */
114
- public function __construct( $args = array(), $gateway_prefs = NULL ) {
115
-
116
- // Make sure gateway prefs is set
117
- if ( $gateway_prefs === NULL ) return;
118
-
119
- // Populate
120
- $this->now = current_time( 'timestamp' );
121
- $this->current_user_id = get_current_user_id();
122
- $this->core = mycred();
123
- $this->buycred = mycred_get_buycred_settings();
124
-
125
- // Arguments
126
- if ( ! empty( $args ) ) {
127
- foreach ( $args as $key => $value ) {
128
- $this->$key = $value;
129
- }
130
- }
131
-
132
- $gateway_settings = $this->defaults;
133
- if ( is_array( $gateway_prefs ) && array_key_exists( $this->id, $gateway_prefs ) )
134
- $gateway_settings = $gateway_prefs[ $this->id ];
135
-
136
- elseif ( is_object( $gateway_prefs ) && array_key_exists( $this->id, $gateway_prefs->gateway_prefs ) )
137
- $gateway_settings = $gateway_prefs->gateway_prefs[ $this->id ];
138
-
139
- $this->prefs = shortcode_atts( $this->defaults, $gateway_settings );
140
-
141
- // Sandbox Mode
142
- $this->sandbox_mode = ( isset( $this->prefs['sandbox'] ) ) ? (bool) $this->prefs['sandbox'] : false;
143
-
144
- // Decode Log Entries
145
- add_filter( 'mycred_prep_template_tags', array( $this, 'decode_log_entries' ), 10, 2 );
146
- add_filter( 'mycred_parse_log_entry_buy_creds_with_' . $this->id, array( $this, 'log_entry' ), 10, 2 );
147
-
148
- }
149
-
150
- /**
151
- * Request Validator
152
- * @since 1.8
153
- * @version 1.0
154
- */
155
- public function valid_request() {
156
-
157
- // Step 1 - We need to be logged in to buy
158
- if ( ! is_user_logged_in() ) return false;
159
-
160
- // Step 2 - We need a valid token to start the request
161
- if ( ! isset( $_REQUEST['token'] ) || ! wp_verify_nonce( $_REQUEST['token'], 'mycred-buy-creds' ) ) return false;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
162
 
163
- $valid = true;
 
164
 
165
- $this->point_type = $this->get_point_type();
166
- if ( $this->point_type != MYCRED_DEFAULT_TYPE_KEY )
167
- $this->core = mycred( $this->point_type );
168
 
169
- $this->buycred_limit = mycred_get_buycred_sale_setup( $this->point_type );
170
 
171
- $this->transaction_id = ( isset( $_REQUEST['revisit'] ) ) ? strtoupper( sanitize_text_field( $_REQUEST['revisit'] ) ) : false;
172
- $this->post_id = ( $this->transaction_id !== false ) ? buycred_get_pending_payment_id( $this->transaction_id ) : false;
173
- $this->buyer_id = $this->current_user_id;
174
- $this->recipient_id = $this->get_recipient_id();
175
- $this->amount = $this->get_amount();
176
- $this->cost = $this->get_cost( $this->amount, $this->point_type );
177
- $this->currency = ( isset( $this->prefs['currency'] ) ) ? $this->prefs['currency'] : '';
178
- $this->maximum = -1;
179
-
180
- if ( $this->core->exclude_user( $this->buyer_id ) ){
181
- $valid = false;
182
- $this->errors[] = __( 'Buyer is excluded from this point type.', 'mycred' );
183
- }
184
- elseif ( $this->core->exclude_user( $this->recipient_id ) ) {
185
- $valid = false;
186
- $this->errors[] = __( 'Recipient is excluded from this point type. ', 'mycred' );
187
- }
188
 
189
- elseif ( $this->amount === false || $this->amount == 0 ){
190
- $valid = false;
191
- $this->errors[] = __( 'An amount value is required.', 'mycred' );
192
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
193
 
194
- elseif ( ! empty( $this->buycred_limit['max'] ) && $this->amount > floatval( $this->buycred_limit['max'] ) ){
195
- $valid = false;
196
- $this->errors[] = apply_filters( 'buycred_max_amount_error', sprintf( __( 'The amount must be less than %d.', 'mycred' ), $this->buycred_limit['max'] ), $this->buycred_limit['max'], $this );
197
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
198
 
199
- elseif ( $this->exceeds_limit() ){
200
- $valid = false;
201
- $this->errors[] = __( 'You have exceeded the limit.', 'mycred' );
202
- }
 
203
 
204
- if ( $valid )
205
- $this->populate_transaction();
206
 
207
- if ( ! empty( $this->errors ) )
208
- $valid = false;
209
 
210
- return apply_filters( 'mycred_valid_buycred_request', $valid, $this );
 
211
 
212
- }
 
 
 
213
 
214
- /**
215
- * Populate Transaction
216
- * @since 1.8
217
- * @since 2.3 @filter added `mycred_buycred_populate_transaction` to avoid pending payments log in some cases.
218
- * @version 1.0
219
- */
220
- public function populate_transaction() {
221
 
222
- if( apply_filters( 'mycred_buycred_populate_transaction', false, $this->id ) )
223
- return;
224
 
225
- // Create a new transaction
226
- $new_transaction = false;
227
- if ( $this->transaction_id === false && $this->post_id === false ) {
 
 
 
 
 
228
 
229
- $this->post_id = $this->add_pending_payment( array(
230
- $this->buyer_id,
231
- $this->recipient_id,
232
- $this->amount,
233
- $this->cost,
234
- $this->currency,
235
- $this->point_type
236
- ) );
 
 
237
 
238
- $this->transaction_id = get_the_title( $this->post_id );
239
 
240
- }
241
 
242
- // Get existing one
243
- elseif ( $this->post_id === false ) {
244
-
245
- $transaction = buycred_get_pending_payment( $this->post_id );
246
-
247
- if ( $transaction !== false ) {
248
-
249
- $new_transaction = true;
250
-
251
- $this->point_type = $transaction->point_type;
252
- $this->amount = $transaction->amount;
253
- $this->cost = $transaction->cost;
254
- $this->currency = $transaction->currency;
255
- $this->buyer_id = $transaction->buyer_id;
256
- $this->recipient_id = $transaction->recipient_id;
257
- $this->transaction_id = $transaction->public_id;
258
-
259
- }
260
-
261
- }
262
-
263
- $this->prep_sale( $new_transaction );
264
-
265
- }
266
-
267
- /**
268
- * Prep Sale
269
- * @since 1.8
270
- * @version 1.0
271
- */
272
- public function prep_sale( $new_transaction = false ) { }
273
-
274
- /**
275
- * Send JSON
276
- * @since 1.8
277
- * @version 1.0
278
- */
279
- public function send_json( $content = '' ) {
280
-
281
- $content = apply_filters( 'mycred_buycred_send_json', $content, $this );
282
-
283
- wp_send_json( $content );
284
-
285
- }
286
-
287
- /**
288
- * Request Exceeds Limit Check
289
- * Checks if a requested amount of points exceeds the "maximum" limit (if used).
290
- * @since 1.8
291
- * @version 1.0
292
- */
293
- public function exceeds_limit() {
294
-
295
- $exceeds = false;
296
- $remaining = mycred_user_can_buycred( $this->buyer_id, $this->point_type );
297
-
298
- // A maximum limit is enforced and we have maxed out
299
- if ( $remaining === 0 ) {
300
-
301
- $exceeds = true;
302
- $this->maximum = 0;
303
-
304
- }
305
-
306
- // A maximum limit is used so we need to make sure the amount we want to buy is valid
307
- elseif ( $remaining !== true ) {
308
-
309
- $this->maximum = $this->core->number( $remaining );
310
-
311
- // The amount remaining is lower than our requested amount
312
- if ( $remaining > 0 && $remaining < $this->amount )
313
- $this->amount = $remaining;
314
-
315
- // Make sure the amount does not exceeds our maximum limit, if it does, reject
316
- else {
317
-
318
- $remaining = $this->core->number( $remaining - $this->amount );
319
-
320
- if ( $remaining < 0 ) {
321
- $exceeds = true;
322
- $this->maximum = 0;
323
- }
324
- else {
325
-
326
- $this->maximum = $remaining;
327
-
328
- }
329
-
330
- }
331
-
332
- }
333
-
334
- return apply_filters( 'mycred_exceeds_buycred_limit', $exceeds, $remaining, $this );
335
-
336
- }
337
-
338
- /**
339
- * Process Purchase
340
- * @since 0.1
341
- * @version 1.0
342
- */
343
- public function process() { }
344
-
345
- /**
346
- * Results Handler
347
- * @since 0.1
348
- * @version 1.0
349
- */
350
- public function returning() { }
351
-
352
- /**
353
- * AJAX Buy Handler
354
- * @since 1.8
355
- * @version 1.0
356
- */
357
- public function ajax_buy() { }
358
-
359
- /**
360
- * Buy Handler
361
- * @since 0.1
362
- * @version 1.0
363
- */
364
- public function buy() { }
365
-
366
- /**
367
- * Admin Init Handler
368
- * @since 1.7
369
- * @version 1.0
370
- */
371
- public function admin_init() { }
372
-
373
- /**
374
- * Preferences
375
- * @since 0.1
376
- * @version 1.0
377
- */
378
- public function preferences() {
379
-
380
- echo '<p>This Payment Gateway has no settings</p>';
381
-
382
- }
383
-
384
- /**
385
- * Sanatize Prefs
386
- * @since 0.1
387
- * @version 1.0
388
- */
389
- public function sanitise_preferences( $data ) {
390
-
391
- return $data;
392
-
393
- }
394
-
395
- /**
396
- * Checkout Header
397
- * @since 1.8
398
- * @version 1.0
399
- */
400
- public function checkout_header() {
401
-
402
- $content = '';
403
-
404
- if ( $this->sandbox_mode )
405
- $content .= '<div class="checkout-header"><div class="warning">' . esc_js( esc_attr( __( 'Test Mode', 'mycred' ) ) ) . '</div></div>';
406
-
407
- $content .= '<div class="checkout-body padded' . ( ( ! $this->sandbox_mode ) ? ' no-header' : '' ) . '">';
408
-
409
- return apply_filters( 'mycred_buycred_checkout_header', $content, $this );
410
-
411
- }
412
-
413
- /**
414
- * Checkout Footer
415
- * @since 1.8
416
- * @version 1.0
417
- */
418
- public function checkout_footer( $button_label = '' ) {
419
-
420
- if ( $button_label == '' )
421
- $button_label = __( 'Continue', 'mycred' );
422
-
423
- $content = '';
424
- if ( ! empty( $this->redirect_fields ) ) {
425
-
426
- $fields = apply_filters( 'mycred_buycred_redirect_fields', $this->redirect_fields, $this );
427
-
428
- if ( ! empty( $fields ) ) {
429
- foreach ( $fields as $name => $value ) $content .= '<input type="hidden" name="' . $name . '" value="' . $value . '" />';
430
- }
431
-
432
- }
433
-
434
- $button = '<button type="button" id="checkout-action-button" data-act="submit" data-value="" class="btn btn-default">' . esc_js( $button_label ) . '</button>';
435
-
436
- // The button
437
- if ( ! empty( $this->toggle_id ) )
438
- $button = '<button type="button" id="checkout-action-button" data-act="toggle" data-value="' . esc_attr( $this->toggle_id ) . '" class="btn btn-default">' . esc_js( $button_label ) . '</button>';
439
-
440
- elseif ( ! empty( $this->redirect_to ) )
441
- $button = '<button type="button" id="checkout-action-button" data-act="redirect" data-value="' . $this->redirect_to . '" class="btn btn-default '. $this->id .'">' . esc_js( $button_label ) . '</button>';
442
-
443
- $button = apply_filters( 'mycred_buycred_checkout_button', $button, $this );
444
-
445
- $content .= '</div>';
446
-
447
- if ( $button != '' )
448
- $content .= '<div class="checkout-footer">' . $button . '</div>';
449
-
450
- return apply_filters( 'mycred_buycred_checkout_footer', $content, $this );
451
-
452
- }
453
-
454
- /**
455
- * Checkout Logo
456
- * @since 1.8
457
- * @version 1.0
458
- */
459
- public function checkout_logo( $title = '' ) {
460
-
461
- if ( $title === '' ) {
462
- if ( isset( $this->prefs['title'] ) ) $title = $this->prefs['title'];
463
- elseif ( isset( $this->prefs['label'] ) ) $title = $this->prefs['label'];
464
- }
465
-
466
- if ( isset( $this->prefs['logo'] ) && ! empty( $this->prefs['logo'] ) )
467
- $content = '<img src="' . $this->prefs['logo'] . '" alt="" />';
468
-
469
- elseif ( isset( $this->prefs['logo_url'] ) && ! empty( $this->prefs['logo_url'] ) )
470
- $content = '<img src="' . $this->prefs['logo_url'] . '" alt="" />';
471
-
472
- elseif ( isset( $this->gateway_logo_url ) && ! empty( $this->gateway_logo_url ) )
473
- $content = '<img src="' . $this->gateway_logo_url . '" alt="" />';
474
-
475
- elseif ( $title !== false ) $content = '<h2 class="gateway-title">' . esc_html( $title ) . '</h2>';
476
- else {
477
- $content = '';
478
- }
479
-
480
- return apply_filters( 'mycred_buycred_checkout_logo', $content, $this );
481
-
482
- }
483
-
484
- /**
485
- * Checkout: Order
486
- * @since 1.8
487
- * @version 1.0
488
- */
489
- public function checkout_order() {
490
-
491
- $table_rows = array();
492
- $point_type_name = apply_filters( 'mycred_buycred_checkout_order', $this->core->plural(), $this );
493
- $table_rows[] = '<tr><td class="item">' . esc_html( $point_type_name ) . '</td><td class="cost right">' . $this->amount . '</td></tr>';
494
- $item_label = apply_filters( 'mycred_buycred_checkout_order', __('Item', 'mycred'), $this );
495
- $amount_label = apply_filters( 'mycred_buycred_checkout_order', __('Amount', 'mycred'), $this );
496
- $cost_label = apply_filters( 'mycred_buycred_checkout_order', __('Cost', 'mycred'), $this );
497
-
498
- if ( $this->gifting )
499
- $table_rows[] = '<tr><td colspan="2"><strong>' . esc_js( esc_attr($cost_label ) ) . ':</strong> ' . esc_html( get_userdata( $this->recipient_id )->display_name ) . '</td></tr>';
500
-
501
- $table_rows[] = '<tr class="total"><td class="item right">' . esc_js( esc_attr( __( 'Cost', 'mycred' ) ) ) . '</td><td class="cost right">' . sprintf( '%s %s', apply_filters( 'mycred_buycred_display_user_amount', $this->cost ), $this->prefs['currency'] ) . '</td></tr>';
502
-
503
- $table_rows = apply_filters( 'mycred_buycred_order_table_rows', $table_rows, $this );
504
-
505
- if ( ! empty( $table_rows ) )
506
- $content = '
507
  <table class="table" cellspacing="0" cellpadding="0">
508
  <thead>
509
  <tr>
510
- <th class="item">' . esc_js( esc_attr($item_label ) ) . '</td>
511
- <th class="cost right">' . esc_js( esc_attr($amount_label ) ) . '</td>
512
  </tr>
513
  </thead>
514
  <tbody>
515
- ' . implode( '', $table_rows ) . '
516
  </tbody>
517
  </table>';
518
-
519
- return apply_filters( 'mycred_buycred_checkout_order', $content, $this );
520
-
521
- }
522
-
523
- /**
524
- * Checkout: Transaction ID
525
- * @since 1.8
526
- * @version 1.0
527
- */
528
- public function checkout_transaction_id() {
529
-
530
- $content = '<h2><span class="text-mutted">' . esc_js( esc_attr( __( 'Transaction ID', 'mycred' ) ) ) . '</span>' . esc_attr( $this->transaction_id ) . '</h2>';
531
-
532
- return apply_filters( 'mycred_buycred_checkout_txtid', $content, $this );
533
-
534
- }
535
-
536
- /**
537
- * Checkout: Cancel
538
- * @since 1.8
539
- * @version 1.0
540
- */
541
- public function checkout_cancel() {
542
-
543
- $content = '<hr /><div class="cancel"><a href="' . $this->get_cancelled( $this->transaction_id ) . '">' . esc_js( esc_attr( __( 'cancel purchase', 'mycred' ) ) ) . '</a></div>';
544
-
545
- return apply_filters( 'mycred_buycred_checkout_cancel', $content, $this );
546
-
547
- }
548
-
549
- /**
550
- * Checkout Page Title
551
- * @since 1.8
552
- * @version 1.0
553
- */
554
- public function checkout_page_title() { }
555
-
556
- /**
557
- * Checkout Page Body
558
- * @since 1.8
559
- * @version 1.0
560
- */
561
- public function checkout_page_body() { }
562
-
563
- /**
564
- * Checkout Page Footer
565
- * @since 1.8
566
- * @version 1.0
567
- */
568
- public function checkout_page_footer() { }
569
-
570
- /**
571
- * Exchange Rate Setup
572
- * @since 1.5
573
- * @version 1.1
574
- */
575
- public function exchange_rate_setup( $default = 'USD' ) {
576
-
577
- if ( ! isset( $this->prefs['exchange'] ) ) return;
578
-
579
- $content = '';
580
- $point_types = array( MYCRED_DEFAULT_TYPE_KEY );
581
-
582
- if ( isset( $this->buycred['types'] ) )
583
- $point_types = (array) $this->buycred['types'];
584
-
585
- foreach ( $point_types as $type_id ) {
586
-
587
- $mycred = mycred( $type_id );
588
-
589
- if ( ! isset( $this->prefs['exchange'][ $type_id ] ) )
590
- $this->prefs['exchange'][ $type_id ] = 1;
591
-
592
- $content .= '
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
593
  <table>
594
  <tr>
595
- <td style="min-width: 100px;"><div class="form-control-static">1 ' . esc_html( $mycred->singular() ) . '</div></td>
596
  <td style="width: 10px;"><div class="form-control-static">=</div></td>
597
- <td><input type="text" name="' . $this->field_name( array( 'exchange' => $type_id ) ) . '" id="' . $this->field_id( array( 'exchange' => $type_id ) ) . '" value="' . esc_attr( $this->prefs['exchange'][ $type_id ] ) . '" size="8" /> ';
598
 
599
 
600
- if ( isset( $this->prefs['currency'] ) )
601
- $content .= '<span class="mycred-gateway-' . $this->id . '-currency">' . ( ( $this->prefs['currency'] == '' ) ? __( 'Select currency', 'mycred' ) : esc_attr( $this->prefs['currency'] ) ) . '</span>';
602
 
603
- else
604
- $content .= '<span>' . esc_attr( $default ) . '</span>';
 
605
 
606
- $content .= '</td>
607
  </tr>
608
  </table>';
609
 
610
- }
611
-
612
- echo apply_filters( 'mycred_buycred_exchange_rate_field', $content, $default, $this );
613
-
614
- }
615
-
616
- /**
617
- * Add Pending Payment
618
- * @since 1.5
619
- * @version 1.1.1
620
- */
621
- public function add_pending_payment( $data ) {
622
-
623
- $post_id = false;
624
- list ( $to, $from, $amount, $cost, $currency, $point_type ) = $data;
625
-
626
- // Title
627
- if ( isset( $_REQUEST['transaction_id'] ) )
628
- $post_title = trim( $_REQUEST['transaction_id'] );
629
- else
630
- $post_title = strtoupper( wp_generate_password( 6, false, false ) );
631
-
632
- $check = $this->transaction_exists( $to, $from, $amount, $cost, $currency, $point_type );
633
- if ( $check !== false ) return $check;
634
-
635
- // Make sure we are not adding more then one pending item
636
- $check = mycred_get_page_by_title( $post_title, ARRAY_A, 'buycred_payment' );
637
- if ( $check === NULL || ( isset( $check['post_status'] ) && $check['post_status'] == 'trash' ) ) {
638
-
639
- // Generate new id and trash old request
640
- if ( isset( $check['post_status'] ) && $check['post_status'] == 'trash' ) {
641
- buycred_trash_pending_payment( $check['ID'] );
642
- $post_title = strtoupper( wp_generate_password( 6, false, false ) );
643
- }
644
-
645
- // Insert post
646
- $post_id = wp_insert_post( array(
647
- 'post_title' => $post_title,
648
- 'post_type' => 'buycred_payment',
649
- 'post_status' => 'publish',
650
- 'post_author' => $from,
651
- 'ping_status' => 'closed',
652
- 'comment_status' => 'open'
653
- ) );
654
-
655
- // Add meta details if insertion was a success
656
- if ( $post_id !== NULL && ! is_wp_error( $post_id ) ) {
657
-
658
- mycred_add_post_meta( $post_id, 'from', $to, true );
659
- mycred_add_post_meta( $post_id, 'to', $from, true );
660
- mycred_add_post_meta( $post_id, 'amount', $amount, true );
661
- mycred_add_post_meta( $post_id, 'cost', $cost, true );
662
- mycred_add_post_meta( $post_id, 'currency', $currency, true );
663
- mycred_add_post_meta( $post_id, 'point_type', $point_type, true);
664
- mycred_add_post_meta( $post_id, 'gateway', $this->id, true );
665
-
666
- mycred_delete_user_meta( $from, 'buycred_pending_payments' );
667
-
668
- $mycred = mycred( $point_type );
669
-
670
- $log_entry = $this->first_comment( sprintf( _x( 'Received new request to purchase %s.', '%s is replaced with the point amount and name.', 'mycred' ), $mycred->format_number( $amount ) . ' ' . $mycred->plural() ) );
671
- $log_entry = apply_filters( 'mycred_new_buycred_request_comment_' . $this->id, $log_entry, $data );
672
-
673
- $this->log_call( $post_id, $log_entry );
674
-
675
- }
676
-
677
- }
678
- else $post_id = $check['ID'];
679
-
680
- return apply_filters( 'mycred_add_pending_payment', $post_id, $data );
681
-
682
- }
683
-
684
- public function transaction_exists( $to, $from, $amount, $cost, $currency, $point_type ) {
685
-
686
- $post_query = array(
687
- 'post_type' => 'buycred_payment',
688
- 'post_status' => 'publish',
689
- 'posts_per_page' => '-1',
690
- 'orderby' => 'date',
691
- 'order' => 'DESC',
692
- 'fields' => 'ids'
693
- );
694
-
695
- $meta_query = array();
696
 
697
- $meta_query[] = array(
698
- 'key' => 'to',
699
- 'value' => $to,
700
- 'compare' => '=',
701
- 'type' => 'NUMERIC'
702
- );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
703
 
704
- $meta_query[] = array(
705
- 'key' => 'from',
706
- 'value' => $from,
707
- 'compare' => '=',
708
- 'type' => 'NUMERIC'
709
- );
710
 
711
- $meta_query[] = array(
712
- 'key' => 'amount',
713
- 'value' => $amount,
714
- 'compare' => '=',
715
- 'type' => 'NUMERIC'
716
- );
717
 
718
- $meta_query[] = array(
719
- 'key' => 'cost',
720
- 'value' => $cost,
721
- 'compare' => '=',
722
- 'type' => 'NUMERIC'
723
- );
724
 
725
- $meta_query[] = array(
726
- 'key' => 'currency',
727
- 'value' => $currency,
728
- 'compare' => '='
729
- );
730
 
731
- $meta_query[] = array(
732
- 'key' => 'point_type',
733
- 'value' => $point_type,
734
- 'compare' => '='
735
- );
736
 
737
- $meta_query[] = array(
738
- 'key' => 'gateway',
739
- 'value' => $this->id,
740
- 'compare' => '='
741
- );
742
 
743
- $post_query['meta_query'] = $meta_query;
744
 
745
- $post_id = false;
746
- $pending = new WP_Query( $post_query );
747
- if ( ! empty( $pending->posts ) ) {
 
 
 
 
 
 
748
 
749
- $post_id = $pending->posts[0];
750
 
751
- wp_reset_postdata();
752
 
753
- }
 
 
 
 
 
 
 
754
 
755
- return $post_id;
756
 
757
- }
758
 
759
- /**
760
- * First Comment
761
- * Used to allow a gateway to adjust the first comment with pending payments.
762
- * @since 1.7.3
763
- * @version 1.0
764
- */
765
- public function first_comment( $comment ) {
766
 
767
- return $comment;
 
 
 
 
 
 
 
 
768
 
769
- }
 
770
 
771
- /**
772
- * Get Pending Payment
773
- * @since 1.5
774
- * @version 1.1
775
- */
776
- public function get_pending_payment( $post_id = NULL ) {
777
 
778
- $pending_payment = buycred_get_pending_payment( $post_id );
779
 
780
- return apply_filters( 'mycred_get_pending_payment', $pending_payment, $post_id );
 
 
 
 
781
 
782
- }
783
 
784
- /**
785
- * Get Recipient ID
786
- * Returns the numeric ID of the user that is nominated to receive the purchased points.
787
- * @since 1.8
788
- * @version 1.0
789
- */
790
- public function get_recipient_id() {
791
 
792
- $this->gifting = false;
793
- $recipient_id = $this->current_user_id;
794
 
795
- // Gift to a user
796
- if ( $this->buycred['gifting']['members'] == 1 ) {
797
 
798
- if ( isset( $_REQUEST['gift_to'] ) ) {
 
 
 
 
 
799
 
800
- $gift_to = absint( $_REQUEST['gift_to'] );
801
- if ( $gift_to > 0 ) {
802
- $recipient_id = $gift_to;
803
- $this->gifting = true;
804
- }
805
 
806
- }
807
 
808
- }
809
 
810
- // Gifting author
811
- if ( $this->buycred['gifting']['authors'] == 1 ) {
 
812
 
813
- if ( isset( $_REQEST['post_id'] ) ) {
814
 
815
- $post_id = absint( $_REQEST['post_id'] );
816
- $post = mycred_get_post( $post_id );
817
- if ( isset( $post->post_author ) ) {
818
- $recipient_id = absint( $post->post_author );
819
- $this->gifting = true;
820
- }
821
 
822
- }
 
 
 
 
 
 
 
823
 
824
- }
 
825
 
826
- return apply_filters( 'mycred_get_buycred_recipient_id', $recipient_id, $this );
 
827
 
828
- }
829
- public function get_to() {
830
 
831
- return $this->get_recipient_id();
 
 
 
832
 
833
- }
834
 
835
- /**
836
- * Get Amount
837
- * @since 1.8
838
- * @version 1.0
839
- */
840
- public function get_amount() {
841
 
842
- $settings = mycred_get_buycred_sale_setup( $this->point_type );
843
- $amount = false;
844
 
845
- // Validate amount ( amount is not zero, higher then minimum required and do not exceed maximum (if set) )
846
- if ( isset( $_REQUEST['amount'] ) && is_numeric( $_REQUEST['amount'] ) ) {
 
 
 
 
 
 
847
 
848
- $amount = $this->core->number( $_REQUEST['amount'] );
849
- $minimum = $this->core->number( $settings['min'] );
850
 
851
- // Enforce minimum
852
- if ( $amount < $minimum )
853
- $amount = $minimum;
854
 
855
- }
 
 
 
856
 
857
- return apply_filters( 'mycred_get_buycred_amount', $amount, $this );
858
 
859
- }
860
 
861
- /**
862
- * Get Point Type
863
- * @since 1.5
864
- * @version 1.2
865
- */
866
- public function get_point_type() {
867
 
868
- $point_type = MYCRED_DEFAULT_TYPE_KEY;
 
 
 
 
 
 
 
869
 
870
- if ( isset( $_REQUEST['ctype'] ) ) {
 
 
871
 
872
- $type_id = sanitize_key( $_REQUEST['ctype'] );
873
- if ( $type_id != '' && mycred_point_type_exists( $type_id ) )
874
- $point_type = $type_id;
875
 
876
- }
 
 
 
877
 
878
- return $point_type;
 
879
 
880
- }
 
 
 
 
 
 
 
 
881
 
882
- /**
883
- * Get Cost
884
- * @since 1.3.2
885
- * @version 1.2
886
- */
887
- public function get_cost( $amount = 0, $point_type = MYCRED_DEFAULT_TYPE_KEY, $raw = false, $custom_rate = 0 ) {
888
 
889
- if(isset($_REQUEST['er_random']) && !empty($_REQUEST['er_random'])){
890
- $custom_rate=mycred_decode_values($_REQUEST['er_random']);
891
- }
892
 
893
- $setup = mycred_get_buycred_sale_setup( $point_type );
 
 
 
894
 
895
- // Apply minimum
896
- if ( $amount < $setup['min'] )
897
- $amount = $setup['min'];
 
898
 
899
- // Calculate cost here so we can use any exchange rate
900
- if ( array_key_exists( $point_type, $this->prefs['exchange'] ) ) {
901
 
902
- // Check for user override
903
- $override = mycred_get_user_meta( $this->current_user_id, 'mycred_buycred_rates_' . $point_type, '', true );
904
- if ( isset( $override[ $this->id ] ) && $override[ $this->id ] != '' )
905
- $rate = $override[ $this->id ];
906
- else if($custom_rate !=0 )
907
- $rate = $custom_rate;
908
- else
909
- $rate = $this->prefs['exchange'][ $point_type ];
910
 
911
- if ( isfloat( $rate ) )
912
- $rate = (float) $rate;
913
- else
914
- $rate = (int) $rate;
 
 
 
 
915
 
916
- $cost = $amount * $rate;
917
 
918
- }
919
- else
920
- $cost = $amount;
921
 
922
- // Return a properly formated cost so PayPal is happy
923
- if ( ! $raw )
924
- $cost = number_format( $cost, 2, '.', '' );
925
 
926
- return apply_filters( 'mycred_buycred_get_cost', $cost, $amount, $point_type, $this->prefs, $setup );
927
 
928
- }
 
929
 
930
- /**
931
- * Get Thank You Page
932
- * @since 0.1
933
- * @version 1.1
934
- */
935
- public function get_thankyou() {
936
 
937
- $url = home_url( '/' );
938
 
939
- // Using a page
940
- if ( $this->buycred['thankyou']['use'] == 'page' ) {
941
 
942
- if ( ! empty( $this->buycred['thankyou']['page'] ) )
943
- $url = mycred_get_permalink( $this->buycred['thankyou']['page'] );
944
 
945
- }
946
 
947
- // Using a custom url
948
- elseif ( $this->buycred['thankyou']['use'] == 'custom' ) {
 
 
 
 
 
 
 
 
 
 
 
 
 
 
949
 
950
- if ( ! empty( $this->buycred['thankyou']['custom'] ) )
951
- $url = $this->buycred['thankyou']['custom'];
 
 
 
 
 
 
 
 
952
 
953
- }
954
 
955
- $profile_url = mycred_get_users_profile_url( $this->buyer_id );
956
- $url = str_replace( '%profile%', $profile_url, $url );
 
 
 
 
 
 
957
 
958
- return apply_filters( 'mycred_buycred_thankyou_url', $url, $this );
959
 
960
- }
 
961
 
962
- /**
963
- * Get Entry
964
- * Returns the appropriate log entry template.
965
- * @since 0.1
966
- * @version 1.1
967
- */
968
- public function get_entry( $recipient_id = false, $buyer_id = false ) {
969
 
970
- if ( $recipient_id === false ) $recipient_id = $this->recipient_id;
971
- if ( $buyer_id === false ) $buyer_id = $this->buyer_id;
972
 
973
- $log_entry = $this->buycred['log'];
 
 
 
 
 
 
 
974
 
975
- // Log entry
976
- if ( $recipient_id != $buyer_id ) {
 
977
 
978
- if ( $this->buycred['gifting']['members'] == 1 || $this->buycred['gifting']['authors'] == 1 )
979
- $log_entry = $this->buycred['gifting']['log'];
980
 
981
- }
982
 
983
- return $log_entry;
 
 
 
 
 
 
 
984
 
985
- }
986
 
987
- /**
988
- * Get Cancelled Page
989
- * @since 0.1
990
- * @version 1.4
991
- */
992
- public function get_cancelled( $transaction_id = NULL ) {
993
 
994
- $url = buycred_get_cancel_transaction_url( $transaction_id );
 
 
 
 
 
 
 
995
 
996
- $profile_url = mycred_get_users_profile_url( $this->buyer_id );
997
- $url = str_replace( '%profile%', $profile_url, $url );
 
 
998
 
999
- return $url;
 
 
 
1000
 
1001
- }
1002
 
1003
- /**
1004
- * Log Gateway Call
1005
- * @since 1.5
1006
- * @version 1.2
1007
- */
1008
- public function log_call( $payment_id, $log ) {
 
 
 
1009
 
1010
- if ( is_array( $log ) )
1011
- $log = implode( '<br />', $log );
 
 
 
 
 
1012
 
1013
- buycred_add_pending_comment( $payment_id, $log );
1014
-
1015
- }
1016
-
1017
- /**
1018
- * Decode Log Entries
1019
- * @since 0.1
1020
- * @version 1.0
1021
- */
1022
- public function log_entry( $content, $log_entry ) {
1023
-
1024
- return $this->core->template_tags_user( $content, $log_entry->ref_id );
1025
-
1026
- }
1027
-
1028
- /**
1029
- * Get Log Entry
1030
- * @since 1.4
1031
- * @version 1.0.1
1032
- */
1033
- public function get_log_entry( $from = 0, $to = 0 ) {
1034
-
1035
- $entry = $this->get_entry( $from, $to );
1036
- if ( isset( $this->label ) )
1037
- $entry = str_replace( '%gateway%', $this->label, $entry );
1038
-
1039
- if ( $this->sandbox_mode ) $entry = 'TEST ' . $entry;
1040
-
1041
- return apply_filters( 'mycred_buycred_get_log_entry', $entry, $from, $to, $this );
1042
-
1043
- }
1044
-
1045
- /**
1046
- * Get Field Name
1047
- * Returns the field name for the current gateway
1048
- * @since 0.1
1049
- * @version 1.0
1050
- */
1051
- public function field_name( $field = '' ) {
1052
-
1053
- if ( is_array( $field ) ) {
1054
-
1055
- $array = array();
1056
- foreach ( $field as $parent => $child ) {
1057
- if ( ! is_numeric( $parent ) )
1058
- $array[] = str_replace( '-', '_', $parent );
1059
-
1060
- if ( ! empty( $child ) && ! is_array( $child ) )
1061
- $array[] = str_replace( '-', '_', $child );
1062
- }
1063
- $field = '[' . implode( '][', $array ) . ']';
1064
-
1065
- }
1066
- else {
1067
-
1068
- $field = '[' . $field . ']';
1069
-
1070
- }
1071
-
1072
- return 'mycred_pref_buycreds[gateway_prefs][' . $this->id . ']' . $field;
1073
-
1074
- }
1075
-
1076
- /**
1077
- * Get Field ID
1078
- * Returns the field id for the current gateway
1079
- * @since 0.1
1080
- * @version 1.0
1081
- */
1082
- public function field_id( $field = '' ) {
1083
-
1084
- if ( is_array( $field ) ) {
1085
-
1086
- $array = array();
1087
- foreach ( $field as $parent => $child ) {
1088
- if ( ! is_numeric( $parent ) )
1089
- $array[] = str_replace( '_', '-', $parent );
1090
-
1091
- if ( ! empty( $child ) && ! is_array( $child ) )
1092
- $array[] = str_replace( '_', '-', $child );
1093
- }
1094
- $field = implode( '-', $array );
1095
-
1096
- }
1097
- else {
1098
-
1099
- $field = str_replace( '_', '-', $field );
1100
-
1101
- }
1102
-
1103
- return 'mycred-gateway-prefs-' . str_replace( '_', '-', $this->id ) . '-' . $field;
1104
-
1105
- }
1106
-
1107
- /**
1108
- * Callback URL
1109
- * @since 0.1
1110
- * @version 1.2
1111
- */
1112
- public function callback_url() {
1113
-
1114
- $url = add_query_arg( 'mycred_call', $this->id, home_url( '/' ) );
1115
-
1116
- return apply_filters( 'mycred_buycred_callback_url', $url, $this );
1117
-
1118
- }
1119
-
1120
- /**
1121
- * Start Log
1122
- * @since 1.4
1123
- * @version 1.0
1124
- */
1125
- public function start_log() {
1126
-
1127
- $this->new_log_entry( 'Incoming confirmation call detected' );
1128
- $this->new_log_entry( sprintf( 'Gateway identified itself as "%s"', $this->id ) );
1129
- $this->new_log_entry( 'Verifying caller' );
1130
-
1131
- }
1132
-
1133
- /**
1134
- * New Log Entry
1135
- * @since 0.1
1136
- * @version 1.0
1137
- */
1138
- public function new_log_entry( $entry = '' ) {
1139
-
1140
- if ( ! isset( $this->processing_log[ $this->id ] ) )
1141
- $this->processing_log[ $this->id ] = array();
1142
-
1143
- $this->processing_log[ $this->id ][] = $entry;
1144
-
1145
- }
1146
-
1147
- /**
1148
- * Save Log Entry
1149
- * @since 0.1
1150
- * @version 1.0
1151
- */
1152
- public function save_log_entry( $id = '', $outcome = '' ) {
1153
-
1154
- update_option( 'mycred_buycred_last_call', array(
1155
- 'gateway' => $this->id,
1156
- 'date' => time(),
1157
- 'outcome' => $outcome,
1158
- 'id' => $id,
1159
- 'entries' => serialize( $this->processing_log[ $this->id ] )
1160
- ) );
1161
-
1162
- }
1163
-
1164
- /**
1165
- * Payment Page Header
1166
- * Pre 1.8 setup. Will be removed as of version 1.9
1167
- * @since 0.1
1168
- * @version 1.2
1169
- */
1170
- public function get_page_header( $site_title = '', $reload = false ) {
1171
-
1172
- // Set Logo
1173
- $logo = '';
1174
- if ( isset( $this->prefs['logo'] ) && ! empty( $this->prefs['logo'] ) )
1175
- $logo = '<img src="' . $this->prefs['logo'] . '" alt="" />';
1176
-
1177
- elseif ( isset( $this->prefs['logo_url'] ) && ! empty( $this->prefs['logo_url'] ) )
1178
- $logo = '<img src="' . $this->prefs['logo_url'] . '" alt="" />';
1179
-
1180
- elseif ( isset( $this->gateway_logo_url ) && ! empty( $this->gateway_logo_url ) )
1181
- $logo = '<img src="' . $this->gateway_logo_url . '" alt="" />';
1182
-
1183
- // Set Title
1184
- if ( $this->sandbox_mode )
1185
- $title = __( 'Test Payment', 'mycred' );
1186
-
1187
- elseif ( isset( $this->label ) )
1188
- $title = $this->label;
1189
-
1190
- else
1191
- $title = __( 'Payment', 'mycred' );
1192
-
1193
- if ( ! isset( $this->transaction_id ) )
1194
- $this->transaction_id = '';
1195
-
1196
- ?><!DOCTYPE html>
1197
  <html <?php language_attributes(); ?>>
1198
  <head>
1199
- <meta charset="<?php bloginfo( 'charset' ); ?>" />
1200
- <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" />
1201
- <meta name="apple-mobile-web-app-capable" content="yes" />
1202
- <title><?php echo $site_title; ?></title>
1203
- <meta name="robots" content="noindex, nofollow" />
1204
- <?php if ( $reload ) echo '<meta http-equiv="refresh" content="2;url=' . $reload . '" />'; ?>
1205
-
1206
- <link rel="stylesheet" href="<?php echo plugins_url( 'assets/css/gateway.css', MYCRED_PURCHASE ); ?>" type="text/css" media="all" />
1207
- <link rel="stylesheet" href="<?php echo plugins_url( 'assets/css/bootstrap-grid.css', myCRED_THIS ); ?>" type="text/css" media="all" />
1208
- <link rel="stylesheet" href="<?php echo plugins_url( 'assets/css/mycred-forms.css', myCRED_THIS ); ?>" type="text/css" media="all" />
1209
- <?php do_action( 'mycred_buycred_page_header', $title, $reload, $this->id ); ?>
 
1210
 
1211
  </head>
1212
  <body class="mycred-metabox">
1213
- <div class="row">
1214
- <div class="col-lg-6 col-md-6 col-sm-12 col-xs-12">
1215
- <?php echo $logo; ?>
1216
- </div>
1217
- <div class="col-lg-6 col-md-6 col-sm-12 col-xs-12 text-right">
1218
- <h2><?php echo $title; ?></h2>
1219
- <p><a href="<?php echo $this->get_cancelled( $this->transaction_id ); ?>" id="return-where-we-came-from"><?php _e( 'Cancel', 'mycred' ); ?></a></p>
1220
- </div>
1221
- </div>
1222
- <?php
1223
-
1224
- do_action( 'mycred_buycred_page_top', $title, $reload, $this->id );
1225
-
1226
- }
1227
- public function purchase_header( $title = '', $reload = false ) {
1228
- $this->get_page_header( $title, $reload );
1229
- }
1230
-
1231
- /**
1232
- * Payment Page Footer
1233
- * @since 0.1
1234
- * @version 1.1
1235
- */
1236
- public function get_page_footer() {
1237
-
1238
- do_action( 'mycred_buycred_page_footer', $this->id );
1239
-
1240
- ?>
1241
- </body>
1242
- </html>
1243
- <?php
1244
-
1245
- }
1246
- public function purchase_footer() {
1247
- $this->get_page_footer();
1248
- }
1249
-
1250
- /**
1251
- * Get Billing Address Form
1252
- * Depreciated as of 1.7. This should be added by the gateway.
1253
- * @since 1.4
1254
- * @version 1.0
1255
- */
1256
- public function get_billing_address_form( $country_dropdown = false ) {
1257
-
1258
- if ( ! is_user_logged_in() ) return;
1259
-
1260
- $user = wp_get_current_user();
1261
-
1262
- // Base
1263
- $user_details = array(
1264
- 'first_name' => ( isset( $_POST['billing']['first_name'] ) ) ? $_POST['billing']['first_name'] : $user->first_name,
1265
- 'last_name' => ( isset( $_POST['billing']['last_name'] ) ) ? $_POST['billing']['last_name'] : $user->last_name,
1266
- 'address1' => ( isset( $_POST['billing']['address1'] ) ) ? $_POST['billing']['address1'] : $user->address1,
1267
- 'address2' => ( isset( $_POST['billing']['address2'] ) ) ? $_POST['billing']['address2'] : $user->address2,
1268
- 'city' => ( isset( $_POST['billing']['city'] ) ) ? $_POST['billing']['city'] : $user->city,
1269
- 'postcode' => ( isset( $_POST['billing']['postcode'] ) ) ? $_POST['billing']['postcode'] : $user->postcode,
1270
- 'state' => ( isset( $_POST['billing']['state'] ) ) ? $_POST['billing']['state'] : $user->state,
1271
- 'country' => ( isset( $_POST['billing']['country'] ) ) ? $_POST['billing']['country'] : $user->country
1272
- );
1273
-
1274
- // Grab WooCommerce User Fields
1275
- if ( ! isset( $_POST['billing']['address1'] ) ) {
1276
-
1277
- if ( class_exists( 'WC_Customer' ) ) {
1278
- $user_details['first_name'] = get_user_meta( $user->ID, 'billing_first_name', true );
1279
- $user_details['last_name'] = get_user_meta( $user->ID, 'billing_last_name', true );
1280
- $user_details['address1'] = get_user_meta( $user->ID, 'billing_address_1', true );
1281
- $user_details['address2'] = get_user_meta( $user->ID, 'billing_address_2', true );
1282
- $user_details['city'] = get_user_meta( $user->ID, 'billing_city', true );
1283
- $user_details['postcode'] = get_user_meta( $user->ID, 'billing_postcode', true );
1284
- $user_details['state'] = get_user_meta( $user->ID, 'billing_state', true );
1285
- }
1286
-
1287
- // Else grab MarketPress User Fields
1288
- elseif ( class_exists( 'MarketPress' ) ) {
1289
- $meta = get_user_meta( $user->ID, 'mp_billing_info', true );
1290
- if ( is_array( $meta ) ) {
1291
- $user_details['address1'] = ( isset( $meta['address1'] ) ) ? $meta['address1'] : '';
1292
- $user_details['address2'] = ( isset( $meta['address2'] ) ) ? $meta['address2'] : '';
1293
- $user_details['city'] = ( isset( $meta['city'] ) ) ? $meta['city'] : '';
1294
- $user_details['postcode'] = ( isset( $meta['zip'] ) ) ? $meta['zip'] : '';
1295
- $user_details['state'] = ( isset( $meta['state'] ) ) ? $meta['state'] : '';
1296
- $user_details['country'] = ( isset( $meta['country'] ) ) ? $meta['country'] : '';
1297
- }
1298
- }
1299
-
1300
- }
1301
-
1302
- // Let others play
1303
- $user_details = apply_filters( 'mycred_buycred_user_details', $user_details, $this );
1304
-
1305
- // Required Fields
1306
- $required_fields = apply_filters( 'mycred_buycred_req_fields', array( 'first_name', 'last_name', 'address1', 'city', 'zip', 'state', 'country' ), $this );
1307
-
1308
- // Show required and optional fields via placeholders
1309
- $required = 'placeholder="required"';
1310
- $optional = 'placeholder="optional"';
1311
-
1312
- ?>
1313
- <div class="row">
1314
- <div class="col-lg-6 col-md-6 col-sm-12 col-xs-12">
1315
- <div class="form-group">
1316
- <label for="billing-first-name"><?php _e( 'First Name', 'mycred' ); ?></label>
1317
- <input type="text" name="billing[first_name]" id="billing-first-name" value="<?php echo $user_details['first_name']; ?>" class="form-control<?php if ( array_key_exists( 'first_name', $this->errors ) ) { echo ' error'; } ?>" <?php if ( in_array( 'first_name', $required_fields ) ) echo $required; else echo $optional; ?> autocomplete="off" />
1318
- </div>
1319
- </div>
1320
- <div class="col-lg-6 col-md-6 col-sm-12 col-xs-12">
1321
- <div class="form-group">
1322
- <label for="billing-last-name"><?php _e( 'Last Name', 'mycred' ); ?></label>
1323
- <input type="text" name="billing[last_name]" id="billing-last-name" value="<?php echo $user_details['last_name']; ?>" class="form-control<?php if ( array_key_exists( 'last_name', $this->errors ) ) { echo ' error'; } ?>" <?php if ( in_array( 'last_name', $required_fields ) ) echo $required; else echo $optional; ?> autocomplete="off" />
1324
- </div>
1325
- </div>
1326
- </div>
1327
- <div class="row">
1328
- <div class="col-lg-12 col-md-12 col-sm-12 col-xs-12">
1329
- <div class="form-group">
1330
- <label for="billing-address1"><?php _e( 'Address Line 1', 'mycred' ); ?></label>
1331
- <input type="text" name="billing[address1]" id="billing-address1" value="<?php echo $user_details['address1']; ?>" class="form-control<?php if ( array_key_exists( 'address1', $this->errors ) ) { echo ' error'; } ?>" <?php if ( in_array( 'address1', $required_fields ) ) echo $required; else echo $optional; ?> autocomplete="off" />
1332
- </div>
1333
- </div>
1334
- </div>
1335
- <div class="row">
1336
- <div class="col-lg-12 col-md-12 col-sm-12 col-xs-12">
1337
- <div class="form-group">
1338
- <label for="billing-address2"><?php _e( 'Address Line 2', 'mycred' ); ?></label>
1339
- <input type="text" name="billing[address2]" id="billing-address2" value="<?php echo $user_details['address2']; ?>" class="form-control<?php if ( array_key_exists( 'address2', $this->errors ) ) { echo ' error'; } ?>" <?php if ( in_array( 'address2', $required_fields ) ) echo $required; else echo $optional; ?> autocomplete="off" />
1340
- </div>
1341
- </div>
1342
- </div>
1343
- <div class="row">
1344
- <div class="col-lg-6 col-md-6 col-sm-12 col-xs-12">
1345
- <div class="form-group">
1346
- <label for="billing-city"><?php _e( 'City', 'mycred' ); ?></label>
1347
- <input type="text" name="billing[city]" id="billing-city" value="<?php echo $user_details['city']; ?>" class="form-control<?php if ( array_key_exists( 'city', $this->errors ) ) { echo ' error'; } ?>" <?php if ( in_array( 'city', $required_fields ) ) echo $required; else echo $optional; ?> autocomplete="off" />
1348
- </div>
1349
- </div>
1350
- <div class="col-lg-6 col-md-6 col-sm-12 col-xs-12">
1351
- <div class="form-group">
1352
- <label for="billing-zip"><?php _e( 'Zip', 'mycred' ); ?></label>
1353
- <input type="text" name="billing[zip]" id="billing-zip" value="<?php echo $user_details['postcode']; ?>" class="form-control<?php if ( array_key_exists( 'zip', $this->errors ) ) { echo ' error'; } ?>" <?php if ( in_array( 'zip', $required_fields ) ) echo $required; else echo $optional; ?> autocomplete="off" />
1354
- </div>
1355
- </div>
1356
- </div>
1357
- <div class="row">
1358
- <div class="col-lg-12 col-md-12 col-sm-12 col-xs-12">
1359
- <div class="form-group">
1360
- <label for="billing-state"><?php _e( 'State', 'mycred' ); ?></label>
1361
- <input type="text" name="billing[state]" id="billing-state" value="<?php echo $user_details['state']; ?>" class="form-control<?php if ( array_key_exists( 'state', $this->errors ) ) { echo ' error'; } ?>" <?php if ( in_array( 'state', $required_fields ) ) echo $required; else echo $optional; ?> autocomplete="off" />
1362
- </div>
1363
- </div>
1364
- </div>
1365
- <div class="row">
1366
- <div class="col-lg-12 col-md-12 col-sm-12 col-xs-12">
1367
- <div class="form-group">
1368
- <label for="billing-country"><?php _e( 'Country', 'mycred' ); ?></label>
1369
-
1370
- <?php if ( $country_dropdown !== false ) : ?>
1371
-
1372
- <select name="billing[country]" id="billing-country" class="form-control">
1373
- <option value=""><?php _e( 'Choose Country', 'mycred' ); ?></option>
1374
-
1375
- <?php $this->list_option_countries(); ?>
1376
-
1377
- </select>
1378
-
1379
- <?php else : ?>
1380
-
1381
- <input type="text" name="billing[country]" id="billing-country" value="<?php echo $user_details['country']; ?>" class="form-control<?php if ( array_key_exists( 'country', $this->errors ) ) { echo ' error'; } ?>" <?php if ( in_array( 'country', $required_fields ) ) echo $required; else echo $optional; ?> autocomplete="off" />
1382
-
1383
- <?php endif; ?>
1384
- </div>
1385
- </div>
1386
- </div>
1387
- <?php
1388
-
1389
- do_action( 'mycred_buycred_after_billing_details', $user_details, $this );
1390
-
1391
- }
1392
-
1393
- /**
1394
- * Get Buyers Name
1395
- * @since 1.6
1396
- * @version 1.0
1397
- */
1398
- public function get_buyers_name( $user_id = NULL ) {
1399
-
1400
- if ( $user_id === NULL ) return '';
1401
-
1402
- $user = get_userdata( $user_id );
1403
- if ( ! isset( $user->ID ) ) return $user_id;
1404
-
1405
- if ( ! empty( $user->first_name ) && ! empty( $user->last_name ) )
1406
- $name = $user->first_name . ' ' . $user->last_name;
1407
-
1408
- elseif ( class_exists( 'WooCommerce' ) )
1409
- $name = get_user_meta( $user_id, 'billing_first_name', true ) . ' ' . get_user_meta( $user_id, 'billing_last_name', true );
1410
-
1411
- else
1412
- $name = $user->display_name;
1413
-
1414
- return $name;
1415
-
1416
- }
1417
-
1418
- /**
1419
- * Get Debug
1420
- * @since 1.0
1421
- * @version 1.0
1422
- */
1423
- public function get_debug() {
1424
-
1425
- ?>
1426
  <h2><?php echo 'Debug'; ?></h2>
1427
  <p><span class="description"><?php echo 'Here you can see information that are collected and sent to this gateway. Debug information is only visible for administrators and are intended for troubleshooting / testing of this gateway. Please disable "Sandbox Mode" when you want to take this gateway online.'; ?></span></p>
1428
  <table id="gateway-debug">
1429
- <thead>
1430
- <tr>
1431
- <th id="gateway-col-section" class="col-section"><?php echo 'Section'; ?></th>
1432
- <th id="gateway-col-result" class="col-result"><?php echo 'Result'; ?></th>
1433
- </tr>
1434
- </thead>
1435
- <tbody>
1436
- <tr>
1437
- <td class="col-section"><?php echo 'Payment Status'; ?></td>
1438
- <td class="col-result"><pre><?php print_r( $this->status ); ?></pre></td>
1439
- </tr>
1440
- <tr>
1441
- <td class="col-section"><?php echo 'Request'; ?></td>
1442
- <td class="col-result"><pre><?php print_r( $this->request ); ?></pre></td>
1443
- </tr>
1444
- <tr>
1445
- <td class="col-section"><?php echo 'Gateway Response'; ?></td>
1446
- <td class="col-result"><pre><?php print_r( $this->response ); ?></pre></td>
1447
- </tr>
1448
- </tbody>
1449
  </table>
1450
- <?php
1451
-
1452
- }
1453
-
1454
- /**
1455
- * Get Errors
1456
- * @since 1.0
1457
- * @version 1.0
1458
- */
1459
- public function get_errors() {
1460
-
1461
- if ( empty( $this->errors ) ) return;
1462
-
1463
- $errors = array();
1464
- foreach ( $this->errors as $form_field => $error_message )
1465
- $errors[] = $error_message;
1466
-
1467
- ?>
1468
- <div class="gateway-error"><?php echo implode( '<br />', $errors ); ?></div>
1469
- <?php
1470
-
1471
- }
1472
-
1473
- /**
1474
- * Form Builder with Redirect
1475
- * Used by gateways that redirects users to a remote processor.
1476
- * @since 0.1
1477
- * @version 1.0
1478
- */
1479
- public function get_page_redirect( $hidden_fields = array(), $location = '' ) {
1480
-
1481
- $id = str_replace( '-', '_', $this->id );
1482
-
1483
- // Logo
1484
- if ( empty( $logo_url ) )
1485
- $logo_url = plugins_url( 'images/cred-icon32.png', myCRED_THIS );
1486
-
1487
- // Hidden Fields
1488
- $hidden_fields = apply_filters( "mycred_{$id}_purchase_fields", $hidden_fields, $this );
1489
-
1490
- ?>
 
 
 
 
 
 
 
1491
  <div class="row">
1492
- <div class="col-lg-12 col-md-12 col-sm-12 col-xs-12">
1493
- <form name="mycred_<?php echo $id; ?>_request" class="form text-center" action="<?php echo $location; ?>" method="post" id="redirect-form">
1494
- <?php foreach ( $hidden_fields as $name => $value ) echo '<input type="hidden" name="' . $name . '" value="' . $value . '" />' . "\n"; ?>
1495
- <img src="<?php echo plugins_url( 'assets/images/loading.gif', MYCRED_PURCHASE ); ?>" alt="Loading" />
1496
- <noscript><input type="submit" name="submit-form" value="<?php printf( __( 'Continue to %s', 'mycred' ), $this->label ); ?>" /></noscript>
1497
- <p id="manual-continue"><a href="javascript:void(0);" onclick="document.mycred_<?php echo $id; ?>_request.submit();return false;"><?php _e( 'Click here if you are not automatically redirected', 'mycred' ); ?></a></p>
1498
- </form>
1499
- </div>
 
1500
  </div>
1501
- <script type="text/javascript"><?php if ( $this->sandbox_mode ) echo '//'; ?>setTimeout( "document.mycred_<?php echo $id; ?>_request.submit()",2000 );</script>
1502
- <?php
1503
-
1504
- }
1505
- public function form_with_redirect( $hidden_fields = array(), $location = '', $logo_url = '', $custom_html = '', $sales_data = '' ) {
1506
- $this->get_page_redirect( $hidden_fields, $location, $custom_html, $sales_data );
1507
- }
1508
-
1509
- /**
1510
- * POST to data
1511
- * @since 0.1
1512
- * @version 1.2
1513
- */
1514
- public function POST_to_data( $unset = false ) {
1515
-
1516
- $data = array();
1517
- foreach ( $_POST as $key => $value ) {
1518
- $data[ $key ] = stripslashes( $value );
1519
- }
1520
- if ( $unset )
1521
- unset( $_POST );
1522
-
1523
- return $data;
1524
-
1525
- }
1526
-
1527
- /**
1528
- * Transaction ID unique
1529
- * Searches the Log for a given transaction.
1530
- *
1531
- * @returns (bool) true if transaction id is unique or false
1532
- * @since 0.1
1533
- * @version 1.0.2
1534
- */
1535
- public function transaction_id_is_unique( $transaction_id = '' ) {
1536
-
1537
- if ( empty( $transaction_id ) ) return false;
1538
-
1539
- global $wpdb, $mycred_log_table;
1540
-
1541
- // Make sure this is a new transaction
1542
- $sql = "
 
 
 
 
 
 
 
1543
  SELECT *
1544
  FROM {$mycred_log_table}
1545
  WHERE ref = %s
1546
  AND data LIKE %s
1547
  AND ctype = %s;";
1548
 
1549
- $gateway = str_replace( '-', '_', $this->id );
1550
- $gateway_id = 'buy_creds_with_' . $gateway;
1551
-
1552
- $check = $wpdb->get_results( $wpdb->prepare( $sql, $gateway_id, "%:\"" . $transaction_id . "\";%", $this->mycred_type ) );
1553
- if ( $wpdb->num_rows > 0 ) return false;
1554
-
1555
- return true;
1556
-
1557
- }
1558
-
1559
- /**
1560
- * Create Unique Transaction ID
1561
- * Returns a unique transaction ID that has no been used by buyCRED yet.
1562
- * @since 1.4
1563
- * @version 1.0.1
1564
- */
1565
- public function create_unique_transaction_id() {
1566
-
1567
- global $wpdb, $mycred_log_table;
1568
-
1569
- do {
1570
-
1571
- $id = strtoupper( wp_generate_password( 12, false, false ) );
1572
- $query = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM {$mycred_log_table} WHERE ref LIKE %s AND data LIKE %s;", 'buy_creds_with_%', "%:\"" . $id . "\";%" ) );
1573
-
1574
- } while ( ! empty( $query ) );
1575
-
1576
- return $id;
1577
-
1578
- }
1579
-
1580
- /**
1581
- * Create Token
1582
- * Returns a wp nonce
1583
- * @since 0.1
1584
- * @version 1.0
1585
- */
1586
- public function create_token( $user_id = NULL ) {
1587
-
1588
- return wp_create_nonce( 'mycred-buy-' . $this->id );
1589
-
1590
- }
1591
-
1592
- /**
1593
- * Verify Token
1594
- * Based on wp_verify_nonce() this function requires the user id used when the token
1595
- * was created as by default not logged in users would generate different tokens causing us
1596
- * to fail.
1597
- * @param $user_id (int) required user id
1598
- * @param $nonce (string) required nonce to check
1599
- * @returns true or false
1600
- * @since 0.1
1601
- * @version 1.0.1
1602
- */
1603
- public function verify_token( $user_id, $nonce ) {
1604
-
1605
- $uid = absint( $user_id );
1606
- $i = wp_nonce_tick();
1607
-
1608
- if ( substr( wp_hash( $i . 'mycred-buy-' . $this->id . $uid, 'nonce' ), -12, 10 ) == $nonce )
1609
- return true;
1610
- if ( substr( wp_hash( ( $i - 1 ) . 'mycred-buy-' . $this->id . $uid, 'nonce' ), -12, 10 ) === $nonce )
1611
- return true;
1612
-
1613
- return false;
1614
-
1615
- }
1616
-
1617
- /**
1618
- * Encode Sales Data
1619
- * @since 0.1
1620
- * @version 1.1
1621
- */
1622
- public function encode_sales_data( $data ) {
1623
-
1624
- $protect = new myCRED_Protect();
1625
- if ( $protect !== false )
1626
- return $protect->do_encode( $data );
1627
-
1628
- return $data;
1629
-
1630
- }
1631
-
1632
- /**
1633
- * Decode Sales Data
1634
- * @since 0.1
1635
- * @version 1.1
1636
- */
1637
- public function decode_sales_data( $data ) {
1638
-
1639
- $protect = new myCRED_Protect();
1640
- if ( $protect !== false )
1641
- return $protect->do_decode( $data );
1642
-
1643
- return $data;
1644
-
1645
- }
1646
-
1647
- /**
1648
- * Currencies Dropdown
1649
- * @since 0.1
1650
- * @version 1.0.2
1651
- */
1652
- public function currencies_dropdown( $name = '', $js = '' ) {
1653
-
1654
- $currencies = array(
1655
- 'USD' => 'US Dollars',
1656
- 'AUD' => 'Australian Dollars',
1657
- 'CAD' => 'Canadian Dollars',
1658
- 'EUR' => 'Euro',
1659
- 'GBP' => 'British Pound Sterling',
1660
- 'JPY' => 'Japanese Yen',
1661
- 'NZD' => 'New Zealand Dollars',
1662
- 'CHF' => 'Swiss Francs',
1663
- 'HKD' => 'Hong Kong Dollars',
1664
- 'SGD' => 'Singapore Dollars',
1665
- 'SEK' => 'Swedish Kronor',
1666
- 'DKK' => 'Danish Kroner',
1667
- 'PLN' => 'Polish Zloty',
1668
- 'NOK' => 'Norwegian Kronor',
1669
- 'HUF' => 'Hungarian Forint',
1670
- 'CZK' => 'Check Koruna',
1671
- 'ILS' => 'Israeli Shekel',
1672
- 'MXN' => 'Mexican Peso',
1673
- 'BRL' => 'Brazilian Real',
1674
- 'MYR' => 'Malaysian Ringgits',
1675
- 'PHP' => 'Philippine Pesos',
1676
- 'RUB' => 'Russian Ruble',
1677
- 'TWD' => 'Taiwan New Dollars',
1678
- 'THB' => 'Thai Baht'
1679
- );
1680
- $currencies = apply_filters( 'mycred_dropdown_currencies', $currencies, $this->id );
1681
- $currencies = apply_filters( 'mycred_dropdown_currencies_' . $this->id, $currencies );
1682
-
1683
- if ( $js != '' )
1684
- $js = ' data-update="' . $js . '"';
1685
-
1686
- echo '<select name="' . $this->field_name( $name ) . '" id="' . $this->field_id( $name ) . '" class="currency form-control"' . $js . '>';
1687
- echo '<option value="">' . __( 'Select', 'mycred' ) . '</option>';
1688
- foreach ( $currencies as $code => $cname ) {
1689
- echo '<option value="' . $code . '"';
1690
- if ( isset( $this->prefs[ $name ] ) && $this->prefs[ $name ] == $code ) echo ' selected="selected"';
1691
- echo '>' . $cname . '</option>';
1692
- }
1693
- echo '</select>';
1694
-
1695
- }
1696
-
1697
- /**
1698
- * Item Type Dropdown
1699
- * @since 0.1
1700
- * @version 1.0
1701
- */
1702
- public function item_types_dropdown( $name = '' ) {
1703
-
1704
- $types = array(
1705
- 'product' => 'Product',
1706
- 'service' => 'Service',
1707
- 'donation' => 'Donation'
1708
- );
1709
- $types = apply_filters( 'mycred_dropdown_item_types', $types );
1710
-
1711
- echo '<select name="' . $this->field_name( $name ) . '" id="' . $this->field_id( $name ) . '">';
1712
- echo '<option value="">' . __( 'Select', 'mycred' ) . '</option>';
1713
- foreach ( $types as $code => $cname ) {
1714
- echo '<option value="' . $code . '"';
1715
- if ( isset( $this->prefs[ $name ] ) && $this->prefs[ $name ] == $code ) echo ' selected="selected"';
1716
- echo '>' . $cname . '</option>';
1717
- }
1718
- echo '</select>';
1719
-
1720
- }
1721
-
1722
- /**
1723
- * Countries Dropdown Options
1724
- * @since 0.1
1725
- * @version 1.0
1726
- */
1727
- public function list_option_countries( $selected = '' ) {
1728
-
1729
- $countries = array (
1730
- "US" => "UNITED STATES",
1731
- "AF" => "AFGHANISTAN",
1732
- "AL" => "ALBANIA",
1733
- "DZ" => "ALGERIA",
1734
- "AS" => "AMERICAN SAMOA",
1735
- "AD" => "ANDORRA",
1736
- "AO" => "ANGOLA",
1737
- "AI" => "ANGUILLA",
1738
- "AQ" => "ANTARCTICA",
1739
- "AG" => "ANTIGUA AND BARBUDA",
1740
- "AR" => "ARGENTINA",
1741
- "AM" => "ARMENIA",
1742
- "AW" => "ARUBA",
1743
- "AU" => "AUSTRALIA",
1744
- "AT" => "AUSTRIA",
1745
- "AZ" => "AZERBAIJAN",
1746
- "BS" => "BAHAMAS",
1747
- "BH" => "BAHRAIN",
1748
- "BD" => "BANGLADESH",
1749
- "BB" => "BARBADOS",
1750
- "BY" => "BELARUS",
1751
- "BE" => "BELGIUM",
1752
- "BZ" => "BELIZE",
1753
- "BJ" => "BENIN",
1754
- "BM" => "BERMUDA",
1755
- "BT" => "BHUTAN",
1756
- "BO" => "BOLIVIA",
1757
- "BA" => "BOSNIA AND HERZEGOVINA",
1758
- "BW" => "BOTSWANA",
1759
- "BV" => "BOUVET ISLAND",
1760
- "BR" => "BRAZIL",
1761
- "IO" => "BRITISH INDIAN OCEAN TERRITORY",
1762
- "BN" => "BRUNEI DARUSSALAM",
1763
- "BG" => "BULGARIA",
1764
- "BF" => "BURKINA FASO",
1765
- "BI" => "BURUNDI",
1766
- "KH" => "CAMBODIA",
1767
- "CM" => "CAMEROON",
1768
- "CA" => "CANADA",
1769
- "CV" => "CAPE VERDE",
1770
- "KY" => "CAYMAN ISLANDS",
1771
- "CF" => "CENTRAL AFRICAN REPUBLIC",
1772
- "TD" => "CHAD",
1773
- "CL" => "CHILE",
1774
- "CN" => "CHINA",
1775
- "CX" => "CHRISTMAS ISLAND",
1776
- "CC" => "COCOS (KEELING) ISLANDS",
1777
- "CO" => "COLOMBIA",
1778
- "KM" => "COMOROS",
1779
- "CG" => "CONGO",
1780
- "CD" => "CONGO, THE DEMOCRATIC REPUBLIC OF THE",
1781
- "CK" => "COOK ISLANDS",
1782
- "CR" => "COSTA RICA",
1783
- "CI" => "COTE D'IVOIRE",
1784
- "HR" => "CROATIA",
1785
- "CU" => "CUBA",
1786
- "CY" => "CYPRUS",
1787
- "CZ" => "CZECH REPUBLIC",
1788
- "DK" => "DENMARK",
1789
- "DJ" => "DJIBOUTI",
1790
- "DM" => "DOMINICA",
1791
- "DO" => "DOMINICAN REPUBLIC",
1792
- "EC" => "ECUADOR",
1793
- "EG" => "EGYPT",
1794
- "SV" => "EL SALVADOR",
1795
- "GQ" => "EQUATORIAL GUINEA",
1796
- "ER" => "ERITREA",
1797
- "EE" => "ESTONIA",
1798
- "ET" => "ETHIOPIA",
1799
- "FK" => "FALKLAND ISLANDS (MALVINAS)",
1800
- "FO" => "FAROE ISLANDS",
1801
- "FJ" => "FIJI",
1802
- "FI" => "FINLAND",
1803
- "FR" => "FRANCE",
1804
- "GF" => "FRENCH GUIANA",
1805
- "PF" => "FRENCH POLYNESIA",
1806
- "TF" => "FRENCH SOUTHERN TERRITORIES",
1807
- "GA" => "GABON",
1808
- "GM" => "GAMBIA",
1809
- "GE" => "GEORGIA",
1810
- "DE" => "GERMANY",
1811
- "GH" => "GHANA",
1812
- "GI" => "GIBRALTAR",
1813
- "GR" => "GREECE",
1814
- "GL" => "GREENLAND",
1815
- "GD" => "GRENADA",
1816
- "GP" => "GUADELOUPE",
1817
- "GU" => "GUAM",
1818
- "GT" => "GUATEMALA",
1819
- "GN" => "GUINEA",
1820
- "GW" => "GUINEA-BISSAU",
1821
- "GY" => "GUYANA",
1822
- "HT" => "HAITI",
1823
- "HM" => "HEARD ISLAND AND MCDONALD ISLANDS",
1824
- "VA" => "HOLY SEE (VATICAN CITY STATE)",
1825
- "HN" => "HONDURAS",
1826
- "HK" => "HONG KONG",
1827
- "HU" => "HUNGARY",
1828
- "IS" => "ICELAND",
1829
- "IN" => "INDIA",
1830
- "ID" => "INDONESIA",
1831
- "IR" => "IRAN, ISLAMIC REPUBLIC OF",
1832
- "IQ" => "IRAQ",
1833
- "IE" => "IRELAND",
1834
- "IL" => "ISRAEL",
1835
- "IT" => "ITALY",
1836
- "JM" => "JAMAICA",
1837
- "JP" => "JAPAN",
1838
- "JO" => "JORDAN",
1839
- "KZ" => "KAZAKHSTAN",
1840
- "KE" => "KENYA",
1841
- "KI" => "KIRIBATI",
1842
- "KP" => "KOREA, DEMOCRATIC PEOPLE'S REPUBLIC OF",
1843
- "KR" => "KOREA, REPUBLIC OF",
1844
- "KW" => "KUWAIT",
1845
- "KG" => "KYRGYZSTAN",
1846
- "LA" => "LAO PEOPLE'S DEMOCRATIC REPUBLIC",
1847
- "LV" => "LATVIA",
1848
- "LB" => "LEBANON",
1849
- "LS" => "LESOTHO",
1850
- "LR" => "LIBERIA",
1851
- "LY" => "LIBYAN ARAB JAMAHIRIYA",
1852
- "LI" => "LIECHTENSTEIN",
1853
- "LT" => "LITHUANIA",
1854
- "LU" => "LUXEMBOURG",
1855
- "MO" => "MACAO",
1856
- "MK" => "MACEDONIA, THE FORMER YUGOSLAV REPUBLIC OF",
1857
- "MG" => "MADAGASCAR",
1858
- "MW" => "MALAWI",
1859
- "MY" => "MALAYSIA",
1860
- "MV" => "MALDIVES",
1861
- "ML" => "MALI",
1862
- "MT" => "MALTA",
1863
- "MH" => "MARSHALL ISLANDS",
1864
- "MQ" => "MARTINIQUE",
1865
- "MR" => "MAURITANIA",
1866
- "MU" => "MAURITIUS",
1867
- "YT" => "MAYOTTE",
1868
- "MX" => "MEXICO",
1869
- "FM" => "MICRONESIA, FEDERATED STATES OF",
1870
- "MD" => "MOLDOVA, REPUBLIC OF",
1871
- "MC" => "MONACO",
1872
- "MN" => "MONGOLIA",
1873
- "MS" => "MONTSERRAT",
1874
- "MA" => "MOROCCO",
1875
- "MZ" => "MOZAMBIQUE",
1876
- "MM" => "MYANMAR",
1877
- "NA" => "NAMIBIA",
1878
- "NR" => "NAURU",
1879
- "NP" => "NEPAL",
1880
- "NL" => "NETHERLANDS",
1881
- "AN" => "NETHERLANDS ANTILLES",
1882
- "NC" => "NEW CALEDONIA",
1883
- "NZ" => "NEW ZEALAND",
1884
- "NI" => "NICARAGUA",
1885
- "NE" => "NIGER",
1886
- "NG" => "NIGERIA",
1887
- "NU" => "NIUE",
1888
- "NF" => "NORFOLK ISLAND",
1889
- "MP" => "NORTHERN MARIANA ISLANDS",
1890
- "NO" => "NORWAY",
1891
- "OM" => "OMAN",
1892
- "PK" => "PAKISTAN",
1893
- "PW" => "PALAU",
1894
- "PS" => "PALESTINIAN TERRITORY, OCCUPIED",
1895
- "PA" => "PANAMA",
1896
- "PG" => "PAPUA NEW GUINEA",
1897
- "PY" => "PARAGUAY",
1898
- "PE" => "PERU",
1899
- "PH" => "PHILIPPINES",
1900
- "PN" => "PITCAIRN",
1901
- "PL" => "POLAND",
1902
- "PT" => "PORTUGAL",
1903
- "PR" => "PUERTO RICO",
1904
- "QA" => "QATAR",
1905
- "RE" => "REUNION",
1906
- "RO" => "ROMANIA",
1907
- "RU" => "RUSSIAN FEDERATION",
1908
- "RW" => "RWANDA",
1909
- "SH" => "SAINT HELENA",
1910
- "KN" => "SAINT KITTS AND NEVIS",
1911
- "LC" => "SAINT LUCIA",
1912
- "PM" => "SAINT PIERRE AND MIQUELON",
1913
- "VC" => "SAINT VINCENT AND THE GRENADINES",
1914
- "WS" => "SAMOA",
1915
- "SM" => "SAN MARINO",
1916
- "ST" => "SAO TOME AND PRINCIPE",
1917
- "SA" => "SAUDI ARABIA",
1918
- "SN" => "SENEGAL",
1919
- "CS" => "SERBIA AND MONTENEGRO",
1920
- "SC" => "SEYCHELLES",
1921
- "SL" => "SIERRA LEONE",
1922
- "SG" => "SINGAPORE",
1923
- "SK" => "SLOVAKIA",
1924
- "SI" => "SLOVENIA",
1925
- "SB" => "SOLOMON ISLANDS",
1926
- "SO" => "SOMALIA",
1927
- "ZA" => "SOUTH AFRICA",
1928
- "GS" => "SOUTH GEORGIA AND THE SOUTH SANDWICH ISLANDS",
1929
- "ES" => "SPAIN",
1930
- "LK" => "SRI LANKA",
1931
- "SD" => "SUDAN",
1932
- "SR" => "SURINAME",
1933
- "SJ" => "SVALBARD AND JAN MAYEN",
1934
- "SZ" => "SWAZILAND",
1935
- "SE" => "SWEDEN",
1936
- "CH" => "SWITZERLAND",
1937
- "SY" => "SYRIAN ARAB REPUBLIC",
1938
- "TW" => "TAIWAN, PROVINCE OF CHINA",
1939
- "TJ" => "TAJIKISTAN",
1940
- "TZ" => "TANZANIA, UNITED REPUBLIC OF",
1941
- "TH" => "THAILAND",
1942
- "TL" => "TIMOR-LESTE",
1943
- "TG" => "TOGO",
1944
- "TK" => "TOKELAU",
1945
- "TO" => "TONGA",
1946
- "TT" => "TRINIDAD AND TOBAGO",
1947
- "TN" => "TUNISIA",
1948
- "TR" => "TURKEY",
1949
- "TM" => "TURKMENISTAN",
1950
- "TC" => "TURKS AND CAICOS ISLANDS",
1951
- "TV" => "TUVALU",
1952
- "UG" => "UGANDA",
1953
- "UA" => "UKRAINE",
1954
- "AE" => "UNITED ARAB EMIRATES",
1955
- "GB" => "UNITED KINGDOM",
1956
- "US" => "UNITED STATES",
1957
- "UM" => "UNITED STATES MINOR OUTLYING ISLANDS",
1958
- "UY" => "URUGUAY",
1959
- "UZ" => "UZBEKISTAN",
1960
- "VU" => "VANUATU",
1961
- "VE" => "VENEZUELA",
1962
- "VN" => "VIET NAM",
1963
- "VG" => "VIRGIN ISLANDS, BRITISH",
1964
- "VI" => "VIRGIN ISLANDS, U.S.",
1965
- "WF" => "WALLIS AND FUTUNA",
1966
- "EH" => "WESTERN SAHARA",
1967
- "YE" => "YEMEN",
1968
- "ZM" => "ZAMBIA",
1969
- "ZW" => "ZIMBABWE"
1970
- );
1971
- $countries = apply_filters( 'mycred_list_option_countries', $countries );
1972
-
1973
- foreach ( $countries as $code => $cname ) {
1974
- echo '<option value="' . $code . '"';
1975
- if ( $selected == $code ) echo ' selected="selected"';
1976
- echo '>' . $cname . '</option>';
1977
- }
1978
-
1979
- }
1980
-
1981
- /**
1982
- * US States Dropdown Options
1983
- * @since 0.1
1984
- * @version 1.0
1985
- */
1986
- public function list_option_us_states( $selected = '', $non_us = false ) {
1987
-
1988
- $states = array (
1989
- "AL" => "Alabama",
1990
- "AK" => "Alaska",
1991
- "AZ" => "Arizona",
1992
- "AR" => "Arkansas",
1993
- "CA" => "California",
1994
- "CO" => "Colorado",
1995
- "CT" => "Connecticut",
1996
- "DC" => "D.C.",
1997
- "DE" => "Delaware",
1998
- "FL" => "Florida",
1999
- "GA" => "Georgia",
2000
- "HI" => "Hawaii",
2001
- "ID" => "Idaho",
2002
- "IL" => "Illinois",
2003
- "IN" => "Indiana",
2004
- "IA" => "Iowa",
2005
- "KS" => "Kansas",
2006
- "KY" => "Kentucky",
2007
- "LA" => "Louisiana",
2008
- "ME" => "Maine",
2009
- "MD" => "Maryland",
2010
- "MA" => "Massachusetts",
2011
- "MI" => "Michigan",
2012
- "MN" => "Minnesota",
2013
- "MS" => "Mississippi",
2014
- "MO" => "Missouri",
2015
- "MT" => "Montana",
2016
- "NE" => "Nebraska",
2017
- "NV" => "Nevada",
2018
- "NH" => "New Hampshire",
2019
- "NJ" => "New Jersey",
2020
- "NM" => "New Mexico",
2021
- "NY" => "New York",
2022
- "NC" => "North Carolina",
2023
- "ND" => "North Dakota",
2024
- "OH" => "Ohio",
2025
- "OK" => "Oklahoma",
2026
- "OR" => "Oregon",
2027
- "PA" => "Pennsylvania",
2028
- "RI" => "Rhode Island",
2029
- "SC" => "South Carolina",
2030
- "SD" => "South Dakota",
2031
- "TN" => "Tennessee",
2032
- "TX" => "Texas",
2033
- "UT" => "Utah",
2034
- "VT" => "Vermont",
2035
- "VA" => "Virginia",
2036
- "WA" => "Washington",
2037
- "WV" => "West Virginia",
2038
- "WI" => "Wisconsin",
2039
- "WY" => "Wyoming"
2040
- );
2041
- $states = apply_filters( 'mycred_list_option_us', $states );
2042
-
2043
- $outside = 'Outside US';
2044
- if ( $non_us == 'top' ) echo '<option value="">' . $outside . '</option>';
2045
- foreach ( $states as $code => $cname ) {
2046
- echo '<option value="' . $code . '"';
2047
- if ( $selected == $code ) echo ' selected="selected"';
2048
- echo '>' . $cname . '</option>';
2049
- }
2050
- if ( $non_us == 'bottom' ) echo '<option value="">' . $outside . '</option>';
2051
-
2052
- }
2053
-
2054
- /**
2055
- * Months Dropdown Options
2056
- * @since 0.1
2057
- * @version 1.0
2058
- */
2059
- public function list_option_months( $selected = '' ) {
2060
-
2061
- $months = array (
2062
- "01" => __( 'January', 'mycred' ),
2063
- "02" => __( 'February', 'mycred' ),
2064
- "03" => __( 'March', 'mycred' ),
2065
- "04" => __( 'April', 'mycred' ),
2066
- "05" => __( 'May', 'mycred' ),
2067
- "06" => __( 'June', 'mycred' ),
2068
- "07" => __( 'July', 'mycred' ),
2069
- "08" => __( 'August', 'mycred' ),
2070
- "09" => __( 'September', 'mycred' ),
2071
- "10" => __( 'October', 'mycred' ),
2072
- "11" => __( 'November', 'mycred' ),
2073
- "12" => __( 'December', 'mycred' )
2074
- );
2075
-
2076
- foreach ( $months as $number => $text ) {
2077
- echo '<option value="' . $number . '"';
2078
- if ( $selected == $number ) echo ' selected="selected"';
2079
- echo '>' . $text . '</option>';
2080
- }
2081
-
2082
- }
2083
-
2084
- /**
2085
- * Years Dropdown Options
2086
- * @since 0.1
2087
- * @version 1.0
2088
- */
2089
- public function list_option_card_years( $selected = '', $number = 16 ) {
2090
-
2091
- $now = current_time( 'timestamp' );
2092
- $yy = date( 'y', $now );
2093
- $yyyy = date( 'Y', $now );
2094
- $count = 0;
2095
- $options = array();
2096
-
2097
- while ( $count <= (int) $number ) {
2098
- $count ++;
2099
- if ( $count > 1 ) {
2100
- $yy++;
2101
- $yyyy++;
2102
- }
2103
- $options[ $yy ] = $yyyy;
2104
- }
2105
-
2106
- foreach ( $options as $key => $value ) {
2107
- echo '<option value="' . $key . '"';
2108
- if ( $selected == $key ) echo ' selected="selected"';
2109
- echo '>' . $value . '</option>';
2110
- }
2111
-
2112
- }
2113
-
2114
- /**
2115
- * IPN - Has Required Fields
2116
- * @since 1.4
2117
- * @version 1.0
2118
- */
2119
- public function IPN_has_required_fields( $required_fields = array(), $method = 'REQUEST' ) {
2120
-
2121
- $missing = 0;
2122
- foreach ( $required_fields as $field_key ) {
2123
- if ( $method == 'POST' ) {
2124
- if ( ! isset( $_POST[ $field_key ] ) )
2125
- $missing ++;
2126
- }
2127
- elseif ( $method == 'GET' ) {
2128
- if ( ! isset( $_GET[ $field_key ] ) )
2129
- $missing ++;
2130
- }
2131
- elseif ( $method == 'REQUEST' ) {
2132
- if ( ! isset( $_REQUEST[ $field_key ] ) )
2133
- $missing ++;
2134
- }
2135
- else {
2136
- if ( ! isset( $method[ $field_key ] ) )
2137
- $missing ++;
2138
- }
2139
- }
2140
-
2141
- if ( $missing > 0 )
2142
- $result = false;
2143
- else
2144
- $result = true;
2145
-
2146
- $result = apply_filters( 'mycred_buycred_IPN_missing', $result, $required_fields, $this->id );
2147
-
2148
- return $result;
2149
-
2150
- }
2151
-
2152
- /**
2153
- * IPN - Is Valid Call
2154
- * @since 1.4
2155
- * @version 1.0
2156
- */
2157
- public function IPN_is_valid_call() {
2158
-
2159
- return false;
2160
-
2161
- }
2162
-
2163
- /**
2164
- * IPN - Is Valid Sale
2165
- * @since 1.4
2166
- * @version 1.1
2167
- */
2168
- public function IPN_is_valid_sale( $sales_data_key = '', $cost_key = '', $transactionid_key = '', $method = '' ) {
2169
-
2170
- if ( $method == 'POST' )
2171
- $post_id = $_POST[ $sales_data_key ];
2172
- elseif ( $method == 'GET' )
2173
- $post_id = $_GET[ $sales_data_key ];
2174
- else
2175
- $post_id = $_REQUEST[ $sales_data_key ];
2176
-
2177
- $pending_payment = $this->get_pending_payment( $post_id );
2178
- if ( $pending_payment === false ) return false;
2179
-
2180
- $result = true;
2181
-
2182
- if ( $method == 'POST' )
2183
- $price = $_POST[ $cost_key ];
2184
- elseif ( $method == 'GET' )
2185
- $price = $_GET[ $cost_key ];
2186
- else
2187
- $price = $_REQUEST[ $cost_key ];
2188
-
2189
- if ( $result === true && $pending_payment['cost'] != $price ) {
2190
- $result = false;
2191
- }
2192
-
2193
- if ( $result === true && isset( $this->prefs['currency'] ) && $this->prefs['currency'] != $pending_payment['currency'] ) {
2194
- $result = false;
2195
- }
2196
-
2197
- if ( $method == 'POST' )
2198
- $transaction_id = $_POST[ $transactionid_key ];
2199
- elseif ( $method == 'GET' )
2200
- $transaction_id = $_GET[ $transactionid_key ];
2201
- else
2202
- $transaction_id = $_REQUEST[ $transactionid_key ];
2203
-
2204
- if ( $result === true && ! $this->transaction_id_is_unique( $transaction_id ) ) {
2205
- $result = false;
2206
- }
2207
-
2208
- $result = apply_filters( 'mycred_buycred_valid_sale', $result, $sales_data_key, $cost_key, $transactionid_key, $method, $this );
2209
-
2210
- if ( $result === true )
2211
- return $decoded_data;
2212
-
2213
- return $result;
2214
-
2215
- }
2216
-
2217
- /**
2218
- * Complete Payment
2219
- * @since 1.4
2220
- * @version 1.4
2221
- */
2222
- public function complete_payment( $pending_payment = NULL, $transaction_id = '' ) {
2223
-
2224
- if ( $pending_payment === NULL ) return false;
2225
-
2226
- $reply = false;
2227
- $mycred = mycred( $pending_payment->point_type );
2228
-
2229
- $reference = 'buy_creds_with_' . str_replace( array( ' ', '-' ), '_', $this->id );
2230
- $sales_data = array(
2231
- 'to' => $pending_payment->recipient_id,
2232
- 'from' => $pending_payment->buyer_id,
2233
- 'amount' => $pending_payment->amount,
2234
- 'cost' => $pending_payment->cost,
2235
- 'currency' => $pending_payment->currency,
2236
- 'ctype' => $pending_payment->point_type
2237
- );
2238
- $data = array( 'ref_type' => 'user', 'txn_id' => $transaction_id, 'sales_data' => implode( '|', $sales_data ) );
2239
-
2240
- if ( ! $mycred->has_entry( $reference, $pending_payment->buyer_id, $pending_payment->recipient_id, $data, $pending_payment->point_type ) ) {
2241
-
2242
- add_filter( 'mycred_get_email_events', array( $this, 'email_notice' ), 10, 2 );
2243
- $reply = $mycred->add_creds(
2244
- $reference,
2245
- $pending_payment->recipient_id,
2246
- $pending_payment->amount,
2247
- $this->get_log_entry( $pending_payment->recipient_id, $pending_payment->buyer_id ),
2248
- $pending_payment->buyer_id,
2249
- $data,
2250
- $pending_payment->point_type
2251
- );
2252
- remove_filter( 'mycred_get_email_events', array( $this, 'email_notice' ), 10, 2 );
2253
-
2254
- }
2255
-
2256
- return apply_filters( 'mycred_buycred_complete_payment', $reply, $transaction_id, $this );
2257
-
2258
- }
2259
-
2260
- /**
2261
- * Email Notice Add-on Support
2262
- * @since 1.5.4
2263
- * @version 1.0
2264
- */
2265
- public function email_notice( $events, $request ) {
2266
-
2267
- if ( substr( $request['ref'], 0, 15 ) == 'buy_creds_with_' )
2268
- $events[] = 'buy_creds|positive';
2269
-
2270
- return $events;
2271
-
2272
- }
2273
-
2274
- /**
2275
- * Trash Pending Payment
2276
- * @since 1.5.3
2277
- * @version 1.0.1
2278
- */
2279
- public function trash_pending_payment( $payment_id ) {
2280
-
2281
- return buycred_trash_pending_payment( $payment_id );
2282
-
2283
- }
2284
-
2285
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2286
  endif;
1
  <?php
2
+ if (! defined('myCRED_VERSION') ) { exit;
3
+ }
4
 
5
  /**
6
  * myCRED_Payment_Gateway class
7
+ *
8
+ * @see http://codex.mycred.me/classes/mycred_payment_gateway/
9
+ * @since 0.1
10
  * @version 1.3
11
  */
12
+ if (! class_exists('myCRED_Payment_Gateway') ) :
13
+ abstract class myCRED_Payment_Gateway
14
+ {
15
+
16
+ /**
17
+ * The Gateways Unique ID
18
+ */
19
+ public $id = false;
20
+
21
+ /**
22
+ * Gateway Label
23
+ */
24
+ public $label = '';
25
+
26
+ /**
27
+ * Indicates if the gateway is operating in sandbox mode or not
28
+ */
29
+ public $sandbox_mode = false;
30
+
31
+ /**
32
+ * The gateways logo URL
33
+ */
34
+ public $gateway_logo_url = '';
35
+
36
+ /**
37
+ * Gateways Settings
38
+ */
39
+ public $prefs = false;
40
+
41
+ /**
42
+ * Main Point Type Settings
43
+ */
44
+ public $core;
45
+
46
+ /**
47
+ * buyCRED Add-on Settings
48
+ */
49
+ public $buycred = false;
50
+
51
+ /**
52
+ * The point type being purchased
53
+ */
54
+ public $point_type = '';
55
+
56
+ /**
57
+ * The point amount being purchased
58
+ */
59
+ public $amount = 0;
60
+
61
+ /**
62
+ * The buyers ID
63
+ */
64
+ public $buyer_id = false;
65
+
66
+ /**
67
+ * The recipients ID
68
+ */
69
+ public $recipient_id = false;
70
+
71
+ /**
72
+ * Indicates if this is a gift or not
73
+ */
74
+ public $gifting = false;
75
+
76
+ /**
77
+ * Indicates if this is a valid purchase request
78
+ */
79
+ public $valid_request = false;
80
+
81
+ /**
82
+ * The current users ID
83
+ */
84
+ public $current_user_id = 0;
85
+
86
+ /**
87
+ * Redirect fields
88
+ */
89
+ public $redirect_fields = array();
90
+
91
+ /**
92
+ * Redirect URL
93
+ */
94
+ public $redirect_to = '';
95
+
96
+ public $errors = array();
97
+
98
+ /**
99
+ * Toggle ID
100
+ */
101
+ public $toggle_id = '';
102
+
103
+ /**
104
+ * Limit Setting
105
+ */
106
+ public $buycred_limit = array();
107
+
108
+ protected $response;
109
+ protected $request;
110
+ protected $status;
111
+
112
+ protected $processing_log = null;
113
+
114
+ /**
115
+ * Construct
116
+ */
117
+ public function __construct( $args = array(), $gateway_prefs = null )
118
+ {
119
+
120
+ // Make sure gateway prefs is set
121
+ if ($gateway_prefs === null ) { return;
122
+ }
123
+
124
+ // Populate
125
+ $this->now = current_time('timestamp');
126
+ $this->current_user_id = get_current_user_id();
127
+ $this->core = mycred();
128
+ $this->buycred = mycred_get_buycred_settings();
129
+
130
+ // Arguments
131
+ if (! empty($args) ) {
132
+ foreach ( $args as $key => $value ) {
133
+ $this->$key = $value;
134
+ }
135
+ }
136
+
137
+ $gateway_settings = $this->defaults;
138
+ if (is_array($gateway_prefs) && array_key_exists($this->id, $gateway_prefs) ) {
139
+ $gateway_settings = $gateway_prefs[ $this->id ];
140
+
141
+ } elseif (is_object($gateway_prefs) && array_key_exists($this->id, $gateway_prefs->gateway_prefs) ) {
142
+ $gateway_settings = $gateway_prefs->gateway_prefs[ $this->id ];
143
+ }
144
+
145
+ $this->prefs = shortcode_atts($this->defaults, $gateway_settings);
146
+
147
+ // Sandbox Mode
148
+ $this->sandbox_mode = ( isset($this->prefs['sandbox']) ) ? (bool) $this->prefs['sandbox'] : false;
149
+
150
+ // Decode Log Entries
151
+ add_filter('mycred_prep_template_tags', array( $this, 'decode_log_entries' ), 10, 2);
152
+ add_filter('mycred_parse_log_entry_buy_creds_with_' . $this->id, array( $this, 'log_entry' ), 10, 2);
153
+
154
+ }
155
+
156
+ /**
157
+ * Request Validator
158
+ *
159
+ * @since 1.8
160
+ * @version 1.0
161
+ */
162
+ public function valid_request()
163
+ {
164
+
165
+ // Step 1 - We need to be logged in to buy
166
+ if (! is_user_logged_in() ) { return false;
167
+ }
168
+
169
+ // Step 2 - We need a valid token to start the request
170
+ if (! isset($_REQUEST['token']) || ! wp_verify_nonce($_REQUEST['token'], 'mycred-buy-creds') ) { return false;
171
+ }
172
+
173
+ $valid = true;
174
+
175
+ $this->point_type = $this->get_point_type();
176
+ if ($this->point_type != MYCRED_DEFAULT_TYPE_KEY ) {
177
+ $this->core = mycred($this->point_type);
178
+ }
179
+
180
+ $this->buycred_limit = mycred_get_buycred_sale_setup($this->point_type);
181
+
182
+ $this->transaction_id = ( isset($_REQUEST['revisit']) ) ? strtoupper(sanitize_text_field($_REQUEST['revisit'])) : false;
183
+ $this->post_id = ( $this->transaction_id !== false ) ? buycred_get_pending_payment_id($this->transaction_id) : false;
184
+ $this->buyer_id = $this->current_user_id;
185
+ $this->recipient_id = $this->get_recipient_id();
186
+ $this->amount = $this->get_amount();
187
+ $this->cost = $this->get_cost($this->amount, $this->point_type);
188
+ $this->currency = ( isset($this->prefs['currency']) ) ? $this->prefs['currency'] : '';
189
+ $this->maximum = -1;
190
+
191
+ if ($this->core->exclude_user($this->buyer_id) ) {
192
+ $valid = false;
193
+ $this->errors[] = __('Buyer is excluded from this point type.', 'mycred');
194
+ }
195
+ elseif ($this->core->exclude_user($this->recipient_id) ) {
196
+ $valid = false;
197
+ $this->errors[] = __('Recipient is excluded from this point type. ', 'mycred');
198
+ }
199
+
200
+ elseif ($this->amount === false || $this->amount == 0 ) {
201
+ $valid = false;
202
+ $this->errors[] = __('An amount value is required.', 'mycred');
203
+ }
204
+
205
+ elseif (! empty($this->buycred_limit['max']) && $this->amount > floatval($this->buycred_limit['max']) ) {
206
+ $valid = false;
207
+ $this->errors[] = apply_filters('buycred_max_amount_error', sprintf(__('The amount must be less than %d.', 'mycred'), $this->buycred_limit['max']), $this->buycred_limit['max'], $this);
208
+ }
209
+
210
+ elseif ($this->exceeds_limit() ) {
211
+ $valid = false;
212
+ $this->errors[] = __('You have exceeded the limit.', 'mycred');
213
+ }
214
+
215
+ if ($valid ) {
216
+ $this->populate_transaction();
217
+ }
218
+
219
+ if (! empty($this->errors) ) {
220
+ $valid = false;
221
+ }
222
+
223
+ return apply_filters('mycred_valid_buycred_request', $valid, $this);
224
+
225
+ }
226
+
227
+ /**
228
+ * Populate Transaction
229
+ *
230
+ * @since 1.8
231
+ * @since 2.3 @filter added `mycred_buycred_populate_transaction` to avoid pending payments log in some cases.
232
+ * @version 1.0
233
+ */
234
+ public function populate_transaction()
235
+ {
236
+
237
+ if(apply_filters('mycred_buycred_populate_transaction', false, $this->id) ) {
238
+ return;
239
+ }
240
+
241
+ // Create a new transaction
242
+ $new_transaction = false;
243
+ if ($this->transaction_id === false && $this->post_id === false ) {
244
+
245
+ $this->post_id = $this->add_pending_payment(
246
+ array(
247
+ $this->buyer_id,
248
+ $this->recipient_id,
249
+ $this->amount,
250
+ $this->cost,
251
+ $this->currency,
252
+ $this->point_type
253
+ )
254
+ );
255
+
256
+ $this->transaction_id = get_the_title($this->post_id);
257
+
258
+ }
259
 
260
+ // Get existing one
261
+ elseif ($this->post_id === false ) {
262
 
263
+ $transaction = buycred_get_pending_payment($this->post_id);
 
 
264
 
265
+ if ($transaction !== false ) {
266
 
267
+ $new_transaction = true;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
268
 
269
+ $this->point_type = $transaction->point_type;
270
+ $this->amount = $transaction->amount;
271
+ $this->cost = $transaction->cost;
272
+ $this->currency = $transaction->currency;
273
+ $this->buyer_id = $transaction->buyer_id;
274
+ $this->recipient_id = $transaction->recipient_id;
275
+ $this->transaction_id = $transaction->public_id;
276
+
277
+ }
278
+
279
+ }
280
+
281
+ $this->prep_sale($new_transaction);
282
+
283
+ }
284
+
285
+ /**
286
+ * Prep Sale
287
+ *
288
+ * @since 1.8
289
+ * @version 1.0
290
+ */
291
+ public function prep_sale( $new_transaction = false )
292
+ {
293
+ }
294
+
295
+ /**
296
+ * Send JSON
297
+ *
298
+ * @since 1.8
299
+ * @version 1.0
300
+ */
301
+ public function send_json( $content = '' )
302
+ {
303
+
304
+ $content = apply_filters('mycred_buycred_send_json', $content, $this);
305
+
306
+ wp_send_json($content);
307
+
308
+ }
309
+
310
+ /**
311
+ * Request Exceeds Limit Check
312
+ * Checks if a requested amount of points exceeds the "maximum" limit (if used).
313
+ *
314
+ * @since 1.8
315
+ * @version 1.0
316
+ */
317
+ public function exceeds_limit()
318
+ {
319
+
320
+ $exceeds = false;
321
+ $remaining = mycred_user_can_buycred($this->buyer_id, $this->point_type);
322
+
323
+ // A maximum limit is enforced and we have maxed out
324
+ if ($remaining === 0 ) {
325
+
326
+ $exceeds = true;
327
+ $this->maximum = 0;
328
+
329
+ }
330
+
331
+ // A maximum limit is used so we need to make sure the amount we want to buy is valid
332
+ elseif ($remaining !== true ) {
333
+
334
+ $this->maximum = $this->core->number($remaining);
335
+
336
+ // The amount remaining is lower than our requested amount
337
+ if ($remaining > 0 && $remaining < $this->amount ) {
338
+ $this->amount = $remaining;
339
+ }
340
+
341
+ // Make sure the amount does not exceeds our maximum limit, if it does, reject
342
+ else {
343
+
344
+ $remaining = $this->core->number($remaining - $this->amount);
345
+
346
+ if ($remaining < 0 ) {
347
+ $exceeds = true;
348
+ $this->maximum = 0;
349
+ }
350
+ else {
351
+
352
+ $this->maximum = $remaining;
353
+
354
+ }
355
+
356
+ }
357
+
358
+ }
359
+
360
+ return apply_filters('mycred_exceeds_buycred_limit', $exceeds, $remaining, $this);
361
+
362
+ }
363
+
364
+ /**
365
+ * Process Purchase
366
+ *
367
+ * @since 0.1
368
+ * @version 1.0
369
+ */
370
+ public function process()
371
+ {
372
+ }
373
+
374
+ /**
375
+ * Results Handler
376
+ *
377
+ * @since 0.1
378
+ * @version 1.0
379
+ */
380
+ public function returning()
381
+ {
382
+ }
383
+
384
+ /**
385
+ * AJAX Buy Handler
386
+ *
387
+ * @since 1.8
388
+ * @version 1.0
389
+ */
390
+ public function ajax_buy()
391
+ {
392
+ }
393
+
394
+ /**
395
+ * Buy Handler
396
+ *
397
+ * @since 0.1
398
+ * @version 1.0
399
+ */
400
+ public function buy()
401
+ {
402
+ }
403
 
404
+ /**
405
+ * Admin Init Handler
406
+ *
407
+ * @since 1.7
408
+ * @version 1.0
409
+ */
410
+ public function admin_init()
411
+ {
412
+ }
413
+
414
+ /**
415
+ * Preferences
416
+ *
417
+ * @since 0.1
418
+ * @version 1.0
419
+ */
420
+ public function preferences()
421
+ {
422
+
423
+ echo '<p>This Payment Gateway has no settings</p>';
424
+
425
+ }
426
+
427
+ /**
428
+ * Sanatize Prefs
429
+ *
430
+ * @since 0.1
431
+ * @version 1.0
432
+ */
433
+ public function sanitise_preferences( $data )
434
+ {
435
+
436
+ return $data;
437
+
438
+ }
439
+
440
+ /**
441
+ * Checkout Header
442
+ *
443
+ * @since 1.8
444
+ * @version 1.0
445
+ */
446
+ public function checkout_header()
447
+ {
448
+
449
+ $content = '';
450
+
451
+ if ($this->sandbox_mode ) {
452
+ $content .= '<div class="checkout-header"><div class="warning">' . esc_js(esc_attr(__('Test Mode', 'mycred'))) . '</div></div>';
453
+ }
454
+
455
+ $content .= '<div class="checkout-body padded' . ( ( ! $this->sandbox_mode ) ? ' no-header' : '' ) . '">';
456
+
457
+ return apply_filters('mycred_buycred_checkout_header', $content, $this);
458
+
459
+ }
460
+
461
+ /**
462
+ * Checkout Footer
463
+ *
464
+ * @since 1.8
465
+ * @version 1.0
466
+ */
467
+ public function checkout_footer( $button_label = '' )
468
+ {
469
+
470
+ if ($button_label == '' ) {
471
+ $button_label = __('Continue', 'mycred');
472
+ }
473
+
474
+ $content = '';
475
+ if (! empty($this->redirect_fields) ) {
476
+
477
+ $fields = apply_filters('mycred_buycred_redirect_fields', $this->redirect_fields, $this);
478
+
479
+ if (! empty($fields) ) {
480
+ foreach ( $fields as $name => $value ) { $content .= '<input type="hidden" name="' . $name . '" value="' . $value . '" />';
481
+ }
482
+ }
483
+
484
+ }
485
+
486
+ $button = '<button type="button" id="checkout-action-button" data-act="submit" data-value="" class="btn btn-default">' . esc_js($button_label) . '</button>';
487
+
488
+ // The button
489
+ if (! empty($this->toggle_id) ) {
490
+ $button = '<button type="button" id="checkout-action-button" data-act="toggle" data-value="' . esc_attr($this->toggle_id) . '" class="btn btn-default">' . esc_js($button_label) . '</button>';
491
+
492
+ } elseif (! empty($this->redirect_to) ) {
493
+ $button = '<button type="button" id="checkout-action-button" data-act="redirect" data-value="' . $this->redirect_to . '" class="btn btn-default '. $this->id .'">' . esc_js($button_label) . '</button>';
494
+ }
495
+
496
+ $button = apply_filters('mycred_buycred_checkout_button', $button, $this);
497
+
498
+ $content .= '</div>';
499
+
500
+ if ($button != '' ) {
501
+ $content .= '<div class="checkout-footer">' . $button . '</div>';
502
+ }
503
+
504
+ return apply_filters('mycred_buycred_checkout_footer', $content, $this);
505
+
506
+ }
507
+
508
+ /**
509
+ * Checkout Logo
510
+ *
511
+ * @since 1.8
512
+ * @version 1.0
513
+ */
514
+ public function checkout_logo( $title = '' )
515
+ {
516
 
517
+ if ($title === '' ) {
518
+ if (isset($this->prefs['title']) ) { $title = $this->prefs['title'];
519
+ } elseif (isset($this->prefs['label']) ) { $title = $this->prefs['label'];
520
+ }
521
+ }
522
 
523
+ if (isset($this->prefs['logo']) && ! empty($this->prefs['logo']) ) {
524
+ $content = '<img src="' . $this->prefs['logo'] . '" alt="" />';
525
 
526
+ } elseif (isset($this->prefs['logo_url']) && ! empty($this->prefs['logo_url']) ) {
527
+ $content = '<img src="' . $this->prefs['logo_url'] . '" alt="" />';
528
 
529
+ } elseif (isset($this->gateway_logo_url) && ! empty($this->gateway_logo_url) ) {
530
+ $content = '<img src="' . $this->gateway_logo_url . '" alt="" />';
531
 
532
+ } elseif ($title !== false ) { $content = '<h2 class="gateway-title">' . esc_html($title) . '</h2>';
533
+ } else {
534
+ $content = '';
535
+ }
536
 
537
+ return apply_filters('mycred_buycred_checkout_logo', $content, $this);
 
 
 
 
 
 
538
 
539
+ }
 
540
 
541
+ /**
542
+ * Checkout: Order
543
+ *
544
+ * @since 1.8
545
+ * @version 1.0
546
+ */
547
+ public function checkout_order()
548
+ {
549
 
550
+ $table_rows = array();
551
+ $point_type_name = apply_filters('mycred_buycred_checkout_order', $this->core->plural(), $this);
552
+ $table_rows[] = '<tr><td class="item">' . esc_html($point_type_name) . '</td><td class="cost right">' . $this->amount . '</td></tr>';
553
+ $item_label = apply_filters('mycred_buycred_checkout_order', __('Item', 'mycred'), $this);
554
+ $amount_label = apply_filters('mycred_buycred_checkout_order', __('Amount', 'mycred'), $this);
555
+ $cost_label = apply_filters('mycred_buycred_checkout_order', __('Cost', 'mycred'), $this);
556
+
557
+ if ($this->gifting ) {
558
+ $table_rows[] = '<tr><td colspan="2"><strong>' . esc_js(esc_attr($cost_label)) . ':</strong> ' . esc_html(get_userdata($this->recipient_id)->display_name) . '</td></tr>';
559
+ }
560
 
561
+ $table_rows[] = '<tr class="total"><td class="item right">' . esc_js(esc_attr(__('Cost', 'mycred'))) . '</td><td class="cost right">' . sprintf('%s %s', apply_filters('mycred_buycred_display_user_amount', $this->cost), $this->prefs['currency']) . '</td></tr>';
562
 
563
+ $table_rows = apply_filters('mycred_buycred_order_table_rows', $table_rows, $this);
564
 
565
+ if (! empty($table_rows) ) {
566
+ $content = '
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
567
  <table class="table" cellspacing="0" cellpadding="0">
568
  <thead>
569
  <tr>
570
+ <th class="item">' . esc_js(esc_attr($item_label)) . '</td>
571
+ <th class="cost right">' . esc_js(esc_attr($amount_label)) . '</td>
572
  </tr>
573
  </thead>
574
  <tbody>
575
+ ' . implode('', $table_rows) . '
576
  </tbody>
577
  </table>';
578
+ }
579
+
580
+ return apply_filters('mycred_buycred_checkout_order', $content, $this);
581
+
582
+ }
583
+
584
+ /**
585
+ * Checkout: Transaction ID
586
+ *
587
+ * @since 1.8
588
+ * @version 1.0
589
+ */
590
+ public function checkout_transaction_id()
591
+ {
592
+
593
+ $content = '<h2><span class="text-mutted">' . esc_js(esc_attr(__('Transaction ID', 'mycred'))) . '</span>' . esc_attr($this->transaction_id) . '</h2>';
594
+
595
+ return apply_filters('mycred_buycred_checkout_txtid', $content, $this);
596
+
597
+ }
598
+
599
+ /**
600
+ * Checkout: Cancel
601
+ *
602
+ * @since 1.8
603
+ * @version 1.0
604
+ */
605
+ public function checkout_cancel()
606
+ {
607
+
608
+ $content = '<hr /><div class="cancel"><a href="' . $this->get_cancelled($this->transaction_id) . '">' . esc_js(esc_attr(__('cancel purchase', 'mycred'))) . '</a></div>';
609
+
610
+ return apply_filters('mycred_buycred_checkout_cancel', $content, $this);
611
+
612
+ }
613
+
614
+ /**
615
+ * Checkout Page Title
616
+ *
617
+ * @since 1.8
618
+ * @version 1.0
619
+ */
620
+ public function checkout_page_title()
621
+ {
622
+ }
623
+
624
+ /**
625
+ * Checkout Page Body
626
+ *
627
+ * @since 1.8
628
+ * @version 1.0
629
+ */
630
+ public function checkout_page_body()
631
+ {
632
+ }
633
+
634
+ /**
635
+ * Checkout Page Footer
636
+ *
637
+ * @since 1.8
638
+ * @version 1.0
639
+ */
640
+ public function checkout_page_footer()
641
+ {
642
+ }
643
+
644
+ /**
645
+ * Exchange Rate Setup
646
+ *
647
+ * @since 1.5
648
+ * @version 1.1
649
+ */
650
+ public function exchange_rate_setup( $default = 'USD' )
651
+ {
652
+
653
+ if (! isset($this->prefs['exchange']) ) { return;
654
+ }
655
+
656
+ $content = '';
657
+ $point_types = array( MYCRED_DEFAULT_TYPE_KEY );
658
+
659
+ if (isset($this->buycred['types']) ) {
660
+ $point_types = (array) $this->buycred['types'];
661
+ }
662
+
663
+ foreach ( $point_types as $type_id ) {
664
+
665
+ $mycred = mycred($type_id);
666
+
667
+ if (! isset($this->prefs['exchange'][ $type_id ]) ) {
668
+ $this->prefs['exchange'][ $type_id ] = 1;
669
+ }
670
+
671
+ $content .= '
672
  <table>
673
  <tr>
674
+ <td style="min-width: 100px;"><div class="form-control-static">1 ' . esc_html($mycred->singular()) . '</div></td>
675
  <td style="width: 10px;"><div class="form-control-static">=</div></td>
676
+ <td><input type="text" name="' . $this->field_name(array( 'exchange' => $type_id )) . '" id="' . $this->field_id(array( 'exchange' => $type_id )) . '" value="' . esc_attr($this->prefs['exchange'][ $type_id ]) . '" size="8" /> ';
677
 
678
 
679
+ if (isset($this->prefs['currency']) ) {
680
+ $content .= '<span class="mycred-gateway-' . $this->id . '-currency">' . ( ( $this->prefs['currency'] == '' ) ? __('Select currency', 'mycred') : esc_attr($this->prefs['currency']) ) . '</span>';
681
 
682
+ } else {
683
+ $content .= '<span>' . esc_attr($default) . '</span>';
684
+ }
685
 
686
+ $content .= '</td>
687
  </tr>
688
  </table>';
689
 
690
+ }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
691
 
692
+ echo apply_filters('mycred_buycred_exchange_rate_field', $content, $default, $this);
693
+
694
+ }
695
+
696
+ /**
697
+ * Add Pending Payment
698
+ *
699
+ * @since 1.5
700
+ * @version 1.1.1
701
+ */
702
+ public function add_pending_payment( $data )
703
+ {
704
+
705
+ $post_id = false;
706
+ list ( $to, $from, $amount, $cost, $currency, $point_type ) = $data;
707
+
708
+ // Title
709
+ if (isset($_REQUEST['transaction_id']) ) {
710
+ $post_title = sanitize_title($_REQUEST['transaction_id']);
711
+ } else {
712
+ $post_title = strtoupper(wp_generate_password(6, false, false));
713
+ }
714
+
715
+ $check = $this->transaction_exists($to, $from, $amount, $cost, $currency, $point_type);
716
+ if ($check !== false ) { return $check;
717
+ }
718
+
719
+ // Make sure we are not adding more then one pending item
720
+ $check = mycred_get_page_by_title($post_title, ARRAY_A, 'buycred_payment');
721
+ if ($check === null || ( isset($check['post_status']) && $check['post_status'] == 'trash' ) ) {
722
+
723
+ // Generate new id and trash old request
724
+ if (isset($check['post_status']) && $check['post_status'] == 'trash' ) {
725
+ buycred_trash_pending_payment($check['ID']);
726
+ $post_title = strtoupper(wp_generate_password(6, false, false));
727
+ }
728
+
729
+ // Insert post
730
+ $post_id = wp_insert_post(
731
+ array(
732
+ 'post_title' => $post_title,
733
+ 'post_type' => 'buycred_payment',
734
+ 'post_status' => 'publish',
735
+ 'post_author' => $from,
736
+ 'ping_status' => 'closed',
737
+ 'comment_status' => 'open'
738
+ )
739
+ );
740
+
741
+ // Add meta details if insertion was a success
742
+ if ($post_id !== null && ! is_wp_error($post_id) ) {
743
+
744
+ mycred_add_post_meta($post_id, 'from', $to, true);
745
+ mycred_add_post_meta($post_id, 'to', $from, true);
746
+ mycred_add_post_meta($post_id, 'amount', $amount, true);
747
+ mycred_add_post_meta($post_id, 'cost', $cost, true);
748
+ mycred_add_post_meta($post_id, 'currency', $currency, true);
749
+ mycred_add_post_meta($post_id, 'point_type', $point_type, true);
750
+ mycred_add_post_meta($post_id, 'gateway', $this->id, true);
751
+
752
+ mycred_delete_user_meta($from, 'buycred_pending_payments');
753
+
754
+ $mycred = mycred($point_type);
755
+
756
+ $log_entry = $this->first_comment(sprintf(_x('Received new request to purchase %s.', '%s is replaced with the point amount and name.', 'mycred'), $mycred->format_number($amount) . ' ' . $mycred->plural()));
757
+ $log_entry = apply_filters('mycred_new_buycred_request_comment_' . $this->id, $log_entry, $data);
758
+
759
+ $this->log_call($post_id, $log_entry);
760
+
761
+ }
762
+
763
+ }
764
+ else { $post_id = $check['ID'];
765
+ }
766
+
767
+ return apply_filters('mycred_add_pending_payment', $post_id, $data);
768
+
769
+ }
770
+
771
+ public function transaction_exists( $to, $from, $amount, $cost, $currency, $point_type )
772
+ {
773
+
774
+ $post_query = array(
775
+ 'post_type' => 'buycred_payment',
776
+ 'post_status' => 'publish',
777
+ 'posts_per_page' => '-1',
778
+ 'orderby' => 'date',
779
+ 'order' => 'DESC',
780
+ 'fields' => 'ids'
781
+ );
782
+
783
+ $meta_query = array();
784
+
785
+ $meta_query[] = array(
786
+ 'key' => 'to',
787
+ 'value' => $to,
788
+ 'compare' => '=',
789
+ 'type' => 'NUMERIC'
790
+ );
791
+
792
+ $meta_query[] = array(
793
+ 'key' => 'from',
794
+ 'value' => $from,
795
+ 'compare' => '=',
796
+ 'type' => 'NUMERIC'
797
+ );
798
+
799
+ $meta_query[] = array(
800
+ 'key' => 'amount',
801
+ 'value' => $amount,
802
+ 'compare' => '=',
803
+ 'type' => 'NUMERIC'
804
+ );
805
+
806
+ $meta_query[] = array(
807
+ 'key' => 'cost',
808
+ 'value' => $cost,
809
+ 'compare' => '=',
810
+ 'type' => 'NUMERIC'
811
+ );
812
+
813
+ $meta_query[] = array(
814
+ 'key' => 'currency',
815
+ 'value' => $currency,
816
+ 'compare' => '='
817
+ );
818
+
819
+ $meta_query[] = array(
820
+ 'key' => 'point_type',
821
+ 'value' => $point_type,
822
+ 'compare' => '='
823
+ );
824
+
825
+ $meta_query[] = array(
826
+ 'key' => 'gateway',
827
+ 'value' => $this->id,
828
+ 'compare' => '='
829
+ );
830
 
831
+ $post_query['meta_query'] = $meta_query;
 
 
 
 
 
832
 
833
+ $post_id = false;
834
+ $pending = new WP_Query($post_query);
835
+ if (! empty($pending->posts) ) {
 
 
 
836
 
837
+ $post_id = $pending->posts[0];
 
 
 
 
 
838
 
839
+ wp_reset_postdata();
 
 
 
 
840
 
841
+ }
 
 
 
 
842
 
843
+ return $post_id;
 
 
 
 
844
 
845
+ }
846
 
847
+ /**
848
+ * First Comment
849
+ * Used to allow a gateway to adjust the first comment with pending payments.
850
+ *
851
+ * @since 1.7.3
852
+ * @version 1.0
853
+ */
854
+ public function first_comment( $comment )
855
+ {
856
 
857
+ return $comment;
858
 
859
+ }
860
 
861
+ /**
862
+ * Get Pending Payment
863
+ *
864
+ * @since 1.5
865
+ * @version 1.1
866
+ */
867
+ public function get_pending_payment( $post_id = null )
868
+ {
869
 
870
+ $pending_payment = buycred_get_pending_payment($post_id);
871
 
872
+ return apply_filters('mycred_get_pending_payment', $pending_payment, $post_id);
873
 
874
+ }
 
 
 
 
 
 
875
 
876
+ /**
877
+ * Get Recipient ID
878
+ * Returns the numeric ID of the user that is nominated to receive the purchased points.
879
+ *
880
+ * @since 1.8
881
+ * @version 1.0
882
+ */
883
+ public function get_recipient_id()
884
+ {
885
 
886
+ $this->gifting = false;
887
+ $recipient_id = $this->current_user_id;
888
 
889
+ // Gift to a user
890
+ if ($this->buycred['gifting']['members'] == 1 ) {
 
 
 
 
891
 
892
+ if (isset($_REQUEST['gift_to']) ) {
893
 
894
+ $gift_to = absint($_REQUEST['gift_to']);
895
+ if ($gift_to > 0 ) {
896
+ $recipient_id = $gift_to;
897
+ $this->gifting = true;
898
+ }
899
 
900
+ }
901
 
902
+ }
 
 
 
 
 
 
903
 
904
+ // Gifting author
905
+ if ($this->buycred['gifting']['authors'] == 1 ) {
906
 
907
+ if (isset($_REQEST['post_id']) ) {
 
908
 
909
+ $post_id = absint($_REQEST['post_id']);
910
+ $post = mycred_get_post($post_id);
911
+ if (isset($post->post_author) ) {
912
+ $recipient_id = absint($post->post_author);
913
+ $this->gifting = true;
914
+ }
915
 
916
+ }
 
 
 
 
917
 
918
+ }
919
 
920
+ return apply_filters('mycred_get_buycred_recipient_id', $recipient_id, $this);
921
 
922
+ }
923
+ public function get_to()
924
+ {
925
 
926
+ return $this->get_recipient_id();
927
 
928
+ }
 
 
 
 
 
929
 
930
+ /**
931
+ * Get Amount
932
+ *
933
+ * @since 1.8
934
+ * @version 1.0
935
+ */
936
+ public function get_amount()
937
+ {
938
 
939
+ $settings = mycred_get_buycred_sale_setup($this->point_type);
940
+ $amount = false;
941
 
942
+ // Validate amount ( amount is not zero, higher then minimum required and do not exceed maximum (if set) )
943
+ if (isset($_REQUEST['amount']) && is_numeric($_REQUEST['amount']) ) {
944
 
945
+ $amount = $this->core->number($_REQUEST['amount']);
946
+ $minimum = $this->core->number($settings['min']);
947
 
948
+ // Enforce minimum
949
+ if ($amount < $minimum ) {
950
+ $amount = $minimum;
951
+ }
952
 
953
+ }
954
 
955
+ return apply_filters('mycred_get_buycred_amount', $amount, $this);
 
 
 
 
 
956
 
957
+ }
 
958
 
959
+ /**
960
+ * Get Point Type
961
+ *
962
+ * @since 1.5
963
+ * @version 1.2
964
+ */
965
+ public function get_point_type()
966
+ {
967
 
968
+ $point_type = MYCRED_DEFAULT_TYPE_KEY;
 
969
 
970
+ if (isset($_REQUEST['ctype']) ) {
 
 
971
 
972
+ $type_id = sanitize_key($_REQUEST['ctype']);
973
+ if ($type_id != '' && mycred_point_type_exists($type_id) ) {
974
+ $point_type = $type_id;
975
+ }
976
 
977
+ }
978
 
979
+ return $point_type;
980
 
981
+ }
 
 
 
 
 
982
 
983
+ /**
984
+ * Get Cost
985
+ *
986
+ * @since 1.3.2
987
+ * @version 1.2
988
+ */
989
+ public function get_cost( $amount = 0, $point_type = MYCRED_DEFAULT_TYPE_KEY, $raw = false, $custom_rate = 0 )
990
+ {
991
 
992
+ if(isset($_REQUEST['er_random']) && !empty($_REQUEST['er_random'])) {
993
+ $custom_rate=mycred_decode_values($_REQUEST['er_random']);
994
+ }
995
 
996
+ $setup = mycred_get_buycred_sale_setup($point_type);
 
 
997
 
998
+ // Apply minimum
999
+ if ($amount < $setup['min'] ) {
1000
+ $amount = $setup['min'];
1001
+ }
1002
 
1003
+ // Calculate cost here so we can use any exchange rate
1004
+ if (array_key_exists($point_type, $this->prefs['exchange']) ) {
1005
 
1006
+ // Check for user override
1007
+ $override = mycred_get_user_meta($this->current_user_id, 'mycred_buycred_rates_' . $point_type, '', true);
1008
+ if (isset($override[ $this->id ]) && $override[ $this->id ] != '' ) {
1009
+ $rate = $override[ $this->id ];
1010
+ } else if($custom_rate !=0 ) {
1011
+ $rate = $custom_rate;
1012
+ } else {
1013
+ $rate = $this->prefs['exchange'][ $point_type ];
1014
+ }
1015
 
1016
+ if (isfloat($rate) ) {
1017
+ $rate = (float) $rate;
1018
+ } else {
1019
+ $rate = (int) $rate;
1020
+ }
 
1021
 
1022
+ $cost = $amount * $rate;
 
 
1023
 
1024
+ }
1025
+ else {
1026
+ $cost = $amount;
1027
+ }
1028
 
1029
+ // Return a properly formated cost so PayPal is happy
1030
+ if (! $raw ) {
1031
+ $cost = number_format($cost, 2, '.', '');
1032
+ }
1033
 
1034
+ return apply_filters('mycred_buycred_get_cost', $cost, $amount, $point_type, $this->prefs, $setup);
 
1035
 
1036
+ }
 
 
 
 
 
 
 
1037
 
1038
+ /**
1039
+ * Get Thank You Page
1040
+ *
1041
+ * @since 0.1
1042
+ * @version 1.1
1043
+ */
1044
+ public function get_thankyou()
1045
+ {
1046
 
1047
+ $url = home_url('/');
1048
 
1049
+ // Using a page
1050
+ if ($this->buycred['thankyou']['use'] == 'page' ) {
 
1051
 
1052
+ if (! empty($this->buycred['thankyou']['page']) ) {
1053
+ $url = mycred_get_permalink($this->buycred['thankyou']['page']);
1054
+ }
1055
 
1056
+ }
1057
 
1058
+ // Using a custom url
1059
+ elseif ($this->buycred['thankyou']['use'] == 'custom' ) {
1060
 
1061
+ if (! empty($this->buycred['thankyou']['custom']) ) {
1062
+ $url = $this->buycred['thankyou']['custom'];
1063
+ }
 
 
 
1064
 
1065
+ }
1066
 
1067
+ $profile_url = mycred_get_users_profile_url($this->buyer_id);
1068
+ $url = str_replace('%profile%', $profile_url, $url);
1069
 
1070
+ return apply_filters('mycred_buycred_thankyou_url', $url, $this);
 
1071
 
1072
+ }
1073
 
1074
+ /**
1075
+ * Get Entry
1076
+ * Returns the appropriate log entry template.
1077
+ *
1078
+ * @since 0.1
1079
+ * @version 1.1
1080
+ */
1081
+ public function get_entry( $recipient_id = false, $buyer_id = false )
1082
+ {
1083
+
1084
+ if ($recipient_id === false ) { $recipient_id = $this->recipient_id;
1085
+ }
1086
+ if ($buyer_id === false ) { $buyer_id = $this->buyer_id;
1087
+ }
1088
+
1089
+ $log_entry = $this->buycred['log'];
1090
 
1091
+ // Log entry
1092
+ if ($recipient_id != $buyer_id ) {
1093
+
1094
+ if ($this->buycred['gifting']['members'] == 1 || $this->buycred['gifting']['authors'] == 1 ) {
1095
+ $log_entry = $this->buycred['gifting']['log'];
1096
+ }
1097
+
1098
+ }
1099
+
1100
+ return $log_entry;
1101
 
1102
+ }
1103
 
1104
+ /**
1105
+ * Get Cancelled Page
1106
+ *
1107
+ * @since 0.1
1108
+ * @version 1.4
1109
+ */
1110
+ public function get_cancelled( $transaction_id = null )
1111
+ {
1112
 
1113
+ $url = buycred_get_cancel_transaction_url($transaction_id);
1114
 
1115
+ $profile_url = mycred_get_users_profile_url($this->buyer_id);
1116
+ $url = str_replace('%profile%', $profile_url, $url);
1117
 
1118
+ return $url;
 
 
 
 
 
 
1119
 
1120
+ }
 
1121
 
1122
+ /**
1123
+ * Log Gateway Call
1124
+ *
1125
+ * @since 1.5
1126
+ * @version 1.2
1127
+ */
1128
+ public function log_call( $payment_id, $log )
1129
+ {
1130
 
1131
+ if (is_array($log) ) {
1132
+ $log = implode('<br />', $log);
1133
+ }
1134
 
1135
+ buycred_add_pending_comment($payment_id, $log);
 
1136
 
1137
+ }
1138
 
1139
+ /**
1140
+ * Decode Log Entries
1141
+ *
1142
+ * @since 0.1
1143
+ * @version 1.0
1144
+ */
1145
+ public function log_entry( $content, $log_entry )
1146
+ {
1147
 
1148
+ return $this->core->template_tags_user($content, $log_entry->ref_id);
1149
 
1150
+ }
 
 
 
 
 
1151
 
1152
+ /**
1153
+ * Get Log Entry
1154
+ *
1155
+ * @since 1.4
1156
+ * @version 1.0.1
1157
+ */
1158
+ public function get_log_entry( $from = 0, $to = 0 )
1159
+ {
1160
 
1161
+ $entry = $this->get_entry($from, $to);
1162
+ if (isset($this->label) ) {
1163
+ $entry = str_replace('%gateway%', $this->label, $entry);
1164
+ }
1165
 
1166
+ if ($this->sandbox_mode ) { $entry = 'TEST ' . $entry;
1167
+ }
1168
+
1169
+ return apply_filters('mycred_buycred_get_log_entry', $entry, $from, $to, $this);
1170
 
1171
+ }
1172
 
1173
+ /**
1174
+ * Get Field Name
1175
+ * Returns the field name for the current gateway
1176
+ *
1177
+ * @since 0.1
1178
+ * @version 1.0
1179
+ */
1180
+ public function field_name( $field = '' )
1181
+ {
1182
 
1183
+ if (is_array($field) ) {
1184
+
1185
+ $array = array();
1186
+ foreach ( $field as $parent => $child ) {
1187
+ if (! is_numeric($parent) ) {
1188
+ $array[] = str_replace('-', '_', $parent);
1189
+ }
1190
 
1191
+ if (! empty($child) && ! is_array($child) ) {
1192
+ $array[] = str_replace('-', '_', $child);
1193
+ }
1194
+ }
1195
+ $field = '[' . implode('][', $array) . ']';
1196
+
1197
+ }
1198
+ else {
1199
+
1200
+ $field = '[' . $field . ']';
1201
+
1202
+ }
1203
+
1204
+ return 'mycred_pref_buycreds[gateway_prefs][' . $this->id . ']' . $field;
1205
+
1206
+ }
1207
+
1208
+ /**
1209
+ * Get Field ID
1210
+ * Returns the field id for the current gateway
1211
+ *
1212
+ * @since 0.1
1213
+ * @version 1.0
1214
+ */
1215
+ public function field_id( $field = '' )
1216
+ {
1217
+
1218
+ if (is_array($field) ) {
1219
+
1220
+ $array = array();
1221
+ foreach ( $field as $parent => $child ) {
1222
+ if (! is_numeric($parent) ) {
1223
+ $array[] = str_replace('_', '-', $parent);
1224
+ }
1225
+
1226
+ if (! empty($child) && ! is_array($child) ) {
1227
+ $array[] = str_replace('_', '-', $child);
1228
+ }
1229
+ }
1230
+ $field = implode('-', $array);
1231
+
1232
+ }
1233
+ else {
1234
+
1235
+ $field = str_replace('_', '-', $field);
1236
+
1237
+ }
1238
+
1239
+ return 'mycred-gateway-prefs-' . str_replace('_', '-', $this->id) . '-' . $field;
1240
+
1241
+ }
1242
+
1243
+ /**
1244
+ * Callback URL
1245
+ *
1246
+ * @since 0.1
1247
+ * @version 1.2
1248
+ */
1249
+ public function callback_url()
1250
+ {
1251
+
1252
+ $url = add_query_arg('mycred_call', $this->id, home_url('/'));
1253
+
1254
+ return apply_filters('mycred_buycred_callback_url', $url, $this);
1255
+
1256
+ }
1257
+
1258
+ /**
1259
+ * Start Log
1260
+ *
1261
+ * @since 1.4
1262
+ * @version 1.0
1263
+ */
1264
+ public function start_log()
1265
+ {
1266
+
1267
+ $this->new_log_entry('Incoming confirmation call detected');
1268
+ $this->new_log_entry(sprintf('Gateway identified itself as "%s"', $this->id));
1269
+ $this->new_log_entry('Verifying caller');
1270
+
1271
+ }
1272
+
1273
+ /**
1274
+ * New Log Entry
1275
+ *
1276
+ * @since 0.1
1277
+ * @version 1.0
1278
+ */
1279
+ public function new_log_entry( $entry = '' )
1280
+ {
1281
+
1282
+ if (! isset($this->processing_log[ $this->id ]) ) {
1283
+ $this->processing_log[ $this->id ] = array();
1284
+ }
1285
+
1286
+ $this->processing_log[ $this->id ][] = $entry;
1287
+
1288
+ }
1289
+
1290
+ /**
1291
+ * Save Log Entry
1292
+ *
1293
+ * @since 0.1
1294
+ * @version 1.0
1295
+ */
1296
+ public function save_log_entry( $id = '', $outcome = '' )
1297
+ {
1298
+
1299
+ update_option(
1300
+ 'mycred_buycred_last_call', array(
1301
+ 'gateway' => $this->id,
1302
+ 'date' => time(),
1303
+ 'outcome' => $outcome,
1304
+ 'id' => $id,
1305
+ 'entries' => serialize($this->processing_log[ $this->id ])
1306
+ )
1307
+ );
1308
+
1309
+ }
1310
+
1311
+ /**
1312
+ * Payment Page Header
1313
+ * Pre 1.8 setup. Will be removed as of version 1.9
1314
+ *
1315
+ * @since 0.1
1316
+ * @version 1.2
1317
+ */
1318
+ public function get_page_header( $site_title = '', $reload = false )
1319
+ {
1320
+
1321
+ // Set Logo
1322
+ $logo = '';
1323
+ if (isset($this->prefs['logo']) && ! empty($this->prefs['logo']) ) {
1324
+ $logo = '<img src="' . $this->prefs['logo'] . '" alt="" />';
1325
+
1326
+ } elseif (isset($this->prefs['logo_url']) && ! empty($this->prefs['logo_url']) ) {
1327
+ $logo = '<img src="' . $this->prefs['logo_url'] . '" alt="" />';
1328
+
1329
+ } elseif (isset($this->gateway_logo_url) && ! empty($this->gateway_logo_url) ) {
1330
+ $logo = '<img src="' . $this->gateway_logo_url . '" alt="" />';
1331
+ }
1332
+
1333
+ // Set Title
1334
+ if ($this->sandbox_mode ) {
1335
+ $title = __('Test Payment', 'mycred');
1336
+
1337
+ } elseif (isset($this->label) ) {
1338
+ $title = $this->label;
1339
+
1340
+ } else {
1341
+ $title = __('Payment', 'mycred');
1342
+ }
1343
+
1344
+ if (! isset($this->transaction_id) ) {
1345
+ $this->transaction_id = '';
1346
+ }
1347
+
1348
+ ?><!DOCTYPE html>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1349
  <html <?php language_attributes(); ?>>
1350
  <head>
1351
+ <meta charset="<?php bloginfo('charset'); ?>" />
1352
+ <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" />
1353
+ <meta name="apple-mobile-web-app-capable" content="yes" />
1354
+ <title><?php echo $site_title; ?></title>
1355
+ <meta name="robots" content="noindex, nofollow" />
1356
+ <?php if ($reload ) { echo '<meta http-equiv="refresh" content="2;url=' . $reload . '" />';
1357
+ } ?>
1358
+
1359
+ <link rel="stylesheet" href="<?php echo plugins_url('assets/css/gateway.css', MYCRED_PURCHASE); ?>" type="text/css" media="all" />
1360
+ <link rel="stylesheet" href="<?php echo plugins_url('assets/css/bootstrap-grid.css', myCRED_THIS); ?>" type="text/css" media="all" />
1361
+ <link rel="stylesheet" href="<?php echo plugins_url('assets/css/mycred-forms.css', myCRED_THIS); ?>" type="text/css" media="all" />
1362
+ <?php do_action('mycred_buycred_page_header', $title, $reload, $this->id); ?>
1363
 
1364
  </head>
1365
  <body class="mycred-metabox">
1366
+ <div class="row">
1367
+ <div class="col-lg-6 col-md-6 col-sm-12 col-xs-12">
1368
+ <?php echo $logo; ?>
1369
+ </div>
1370
+ <div class="col-lg-6 col-md-6 col-sm-12 col-xs-12 text-right">
1371
+ <h2><?php echo $title; ?></h2>
1372
+ <p><a href="<?php echo $this->get_cancelled($this->transaction_id); ?>" id="return-where-we-came-from"><?php _e('Cancel', 'mycred'); ?></a></p>
1373
+ </div>
1374
+ </div>
1375
+ <?php
1376
+
1377
+ do_action('mycred_buycred_page_top', $title, $reload, $this->id);
1378
+
1379
+ }
1380
+ public function purchase_header( $title = '', $reload = false )
1381
+ {
1382
+ $this->get_page_header($title, $reload);
1383
+ }
1384
+
1385
+ /**
1386
+ * Payment Page Footer
1387
+ *
1388
+ * @since 0.1
1389
+ * @version 1.1
1390
+ */
1391
+ public function get_page_footer()
1392
+ {
1393
+
1394
+ do_action('mycred_buycred_page_footer', $this->id);
1395
+
1396
+ ?>
1397
+ </body>
1398
+ </html>
1399
+ <?php
1400
+
1401
+ }
1402
+
1403
+ public function purchase_footer()
1404
+ {
1405
+ $this->get_page_footer();
1406
+ }
1407
+
1408
+ /**
1409
+ * Get Buyers Name
1410
+ *
1411
+ * @since 1.6
1412
+ * @version 1.0
1413
+ */
1414
+ public function get_buyers_name( $user_id = null )
1415
+ {
1416
+
1417
+ if ($user_id === null ) { return '';
1418
+ }
1419
+
1420
+ $user = get_userdata($user_id);
1421
+ if (! isset($user->ID) ) { return $user_id;
1422
+ }
1423
+
1424
+ if (! empty($user->first_name) && ! empty($user->last_name) ) {
1425
+ $name = $user->first_name . ' ' . $user->last_name;
1426
+
1427
+ } elseif (class_exists('WooCommerce') ) {
1428
+ $name = get_user_meta($user_id, 'billing_first_name', true) . ' ' . get_user_meta($user_id, 'billing_last_name', true);
1429
+
1430
+ } else {
1431
+ $name = $user->display_name;
1432
+ }
1433
+
1434
+ return $name;
1435
+
1436
+ }
1437
+
1438
+ /**
1439
+ * Get Debug
1440
+ *
1441
+ * @since 1.0
1442
+ * @version 1.0
1443
+ */
1444
+ public function get_debug()
1445
+ {
1446
+
1447
+ ?>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1448
  <h2><?php echo 'Debug'; ?></h2>
1449
  <p><span class="description"><?php echo 'Here you can see information that are collected and sent to this gateway. Debug information is only visible for administrators and are intended for troubleshooting / testing of this gateway. Please disable "Sandbox Mode" when you want to take this gateway online.'; ?></span></p>
1450
  <table id="gateway-debug">
1451
+ <thead>
1452
+ <tr>
1453
+ <th id="gateway-col-section" class="col-section"><?php echo 'Section'; ?></th>
1454
+ <th id="gateway-col-result" class="col-result"><?php echo 'Result'; ?></th>
1455
+ </tr>
1456
+ </thead>
1457
+ <tbody>
1458
+ <tr>
1459
+ <td class="col-section"><?php echo 'Payment Status'; ?></td>
1460
+ <td class="col-result"><pre><?php print_r($this->status); ?></pre></td>
1461
+ </tr>
1462
+ <tr>
1463
+ <td class="col-section"><?php echo 'Request'; ?></td>
1464
+ <td class="col-result"><pre><?php print_r($this->request); ?></pre></td>
1465
+ </tr>
1466
+ <tr>
1467
+ <td class="col-section"><?php echo 'Gateway Response'; ?></td>
1468
+ <td class="col-result"><pre><?php print_r($this->response); ?></pre></td>
1469
+ </tr>
1470
+ </tbody>
1471
  </table>
1472
+ <?php
1473
+
1474
+ }
1475
+
1476
+ /**
1477
+ * Get Errors
1478
+ *
1479
+ * @since 1.0
1480
+ * @version 1.0
1481
+ */
1482
+ public function get_errors()
1483
+ {
1484
+
1485
+ if (empty($this->errors) ) { return;
1486
+ }
1487
+
1488
+ $errors = array();
1489
+ foreach ( $this->errors as $form_field => $error_message ) {
1490
+ $errors[] = $error_message;
1491
+ }
1492
+
1493
+ ?>
1494
+ <div class="gateway-error"><?php echo implode('<br />', $errors); ?></div>
1495
+ <?php
1496
+
1497
+ }
1498
+
1499
+ /**
1500
+ * Form Builder with Redirect
1501
+ * Used by gateways that redirects users to a remote processor.
1502
+ *
1503
+ * @since 0.1
1504
+ * @version 1.0
1505
+ */
1506
+ public function get_page_redirect( $hidden_fields = array(), $location = '' )
1507
+ {
1508
+
1509
+ $id = str_replace('-', '_', $this->id);
1510
+
1511
+ // Logo
1512
+ if (empty($logo_url) ) {
1513
+ $logo_url = plugins_url('images/cred-icon32.png', myCRED_THIS);
1514
+ }
1515
+
1516
+ // Hidden Fields
1517
+ $hidden_fields = apply_filters("mycred_{$id}_purchase_fields", $hidden_fields, $this);
1518
+
1519
+ ?>
1520
  <div class="row">
1521
+ <div class="col-lg-12 col-md-12 col-sm-12 col-xs-12">
1522
+ <form name="mycred_<?php echo $id; ?>_request" class="form text-center" action="<?php echo $location; ?>" method="post" id="redirect-form">
1523
+ <?php foreach ( $hidden_fields as $name => $value ) { echo '<input type="hidden" name="' . $name . '" value="' . $value . '" />' . "\n";
1524
+ } ?>
1525
+ <img src="<?php echo plugins_url('assets/images/loading.gif', MYCRED_PURCHASE); ?>" alt="Loading" />
1526
+ <noscript><input type="submit" name="submit-form" value="<?php printf(__('Continue to %s', 'mycred'), $this->label); ?>" /></noscript>
1527
+ <p id="manual-continue"><a href="javascript:void(0);" onclick="document.mycred_<?php echo $id; ?>_request.submit();return false;"><?php _e('Click here if you are not automatically redirected', 'mycred'); ?></a></p>
1528
+ </form>
1529
+ </div>
1530
  </div>
1531
+ <script type="text/javascript"><?php if ($this->sandbox_mode ) { echo '//';
1532
+ } ?>setTimeout( "document.mycred_<?php echo $id; ?>_request.submit()",2000 );</script>
1533
+ <?php
1534
+
1535
+ }
1536
+ public function form_with_redirect( $hidden_fields = array(), $location = '', $logo_url = '', $custom_html = '', $sales_data = '' )
1537
+ {
1538
+ $this->get_page_redirect($hidden_fields, $location, $custom_html, $sales_data);
1539
+ }
1540
+
1541
+ /**
1542
+ * POST to data
1543
+ *
1544
+ * @since 0.1
1545
+ * @version 1.2
1546
+ */
1547
+ public function POST_to_data( $unset = false )
1548
+ {
1549
+
1550
+ $data = array();
1551
+ foreach ( $_POST as $key => $value ) {
1552
+ $data[ $key ] = stripslashes($value);
1553
+ }
1554
+ if ($unset ) {
1555
+ unset($_POST);
1556
+ }
1557
+
1558
+ return $data;
1559
+
1560
+ }
1561
+
1562
+ /**
1563
+ * Transaction ID unique
1564
+ * Searches the Log for a given transaction.
1565
+ *
1566
+ * @returns (bool) true if transaction id is unique or false
1567
+ * @since 0.1
1568
+ * @version 1.0.2
1569
+ */
1570
+ public function transaction_id_is_unique( $transaction_id = '' )
1571
+ {
1572
+
1573
+ if (empty($transaction_id) ) { return false;
1574
+ }
1575
+
1576
+ global $wpdb, $mycred_log_table;
1577
+
1578
+ // Make sure this is a new transaction
1579
+ $sql = "
1580
  SELECT *
1581
  FROM {$mycred_log_table}
1582
  WHERE ref = %s
1583
  AND data LIKE %s
1584
  AND ctype = %s;";
1585
 
1586
+ $gateway = str_replace('-', '_', $this->id);
1587
+ $gateway_id = 'buy_creds_with_' . $gateway;
1588
+
1589
+ $check = $wpdb->get_results($wpdb->prepare($sql, $gateway_id, "%:\"" . $transaction_id . "\";%", $this->mycred_type));
1590
+ if ($wpdb->num_rows > 0 ) { return false;
1591
+ }
1592
+
1593
+ return true;
1594
+
1595
+ }
1596
+
1597
+ /**
1598
+ * Create Unique Transaction ID
1599
+ * Returns a unique transaction ID that has no been used by buyCRED yet.
1600
+ *
1601
+ * @since 1.4
1602
+ * @version 1.0.1
1603
+ */
1604
+ public function create_unique_transaction_id()
1605
+ {
1606
+
1607
+ global $wpdb, $mycred_log_table;
1608
+
1609
+ do {
1610
+
1611
+ $id = strtoupper(wp_generate_password(12, false, false));
1612
+ $query = $wpdb->get_row($wpdb->prepare("SELECT * FROM {$mycred_log_table} WHERE ref LIKE %s AND data LIKE %s;", 'buy_creds_with_%', "%:\"" . $id . "\";%"));
1613
+
1614
+ } while ( ! empty($query) );
1615
+
1616
+ return $id;
1617
+
1618
+ }
1619
+
1620
+ /**
1621
+ * Create Token
1622
+ * Returns a wp nonce
1623
+ *
1624
+ * @since 0.1
1625
+ * @version 1.0
1626
+ */
1627
+ public function create_token( $user_id = null )
1628
+ {
1629
+
1630
+ return wp_create_nonce('mycred-buy-' . $this->id);
1631
+
1632
+ }
1633
+
1634
+ /**
1635
+ * Verify Token
1636
+ * Based on wp_verify_nonce() this function requires the user id used when the token
1637
+ * was created as by default not logged in users would generate different tokens causing us
1638
+ * to fail.
1639
+ *
1640
+ * @param $user_id (int) required user id
1641
+ * @param $nonce (string) required nonce to check
1642
+ * @returns true or false
1643
+ * @since 0.1
1644
+ * @version 1.0.1
1645
+ */
1646
+ public function verify_token( $user_id, $nonce )
1647
+ {
1648
+
1649
+ $uid = absint($user_id);
1650
+ $i = wp_nonce_tick();
1651
+
1652
+ if (substr(wp_hash($i . 'mycred-buy-' . $this->id . $uid, 'nonce'), -12, 10) == $nonce ) {
1653
+ return true;
1654
+ }
1655
+ if (substr(wp_hash(( $i - 1 ) . 'mycred-buy-' . $this->id . $uid, 'nonce'), -12, 10) === $nonce ) {
1656
+ return true;
1657
+ }
1658
+
1659
+ return false;
1660
+
1661
+ }
1662
+
1663
+ /**
1664
+ * Encode Sales Data
1665
+ *
1666
+ * @since 0.1
1667
+ * @version 1.1
1668
+ */
1669
+ public function encode_sales_data( $data )
1670
+ {
1671
+
1672
+ $protect = new myCRED_Protect();
1673
+ if ($protect !== false ) {
1674
+ return $protect->do_encode($data);
1675
+ }
1676
+
1677
+ return $data;
1678
+
1679
+ }
1680
+
1681
+ /**
1682
+ * Decode Sales Data
1683
+ *
1684
+ * @since 0.1
1685
+ * @version 1.1
1686
+ */
1687
+ public function decode_sales_data( $data )
1688
+ {
1689
+
1690
+ $protect = new myCRED_Protect();
1691
+ if ($protect !== false ) {
1692
+ return $protect->do_decode($data);
1693
+ }
1694
+
1695
+ return $data;
1696
+
1697
+ }
1698
+
1699
+ /**
1700
+ * Currencies Dropdown
1701
+ *
1702
+ * @since 0.1
1703
+ * @version 1.0.2
1704
+ */
1705
+ public function currencies_dropdown( $name = '', $js = '' )
1706
+ {
1707
+
1708
+ $currencies = array(
1709
+ 'USD' => 'US Dollars',
1710
+ 'AUD' => 'Australian Dollars',
1711
+ 'CAD' => 'Canadian Dollars',
1712
+ 'EUR' => 'Euro',
1713
+ 'GBP' => 'British Pound Sterling',
1714
+ 'JPY' => 'Japanese Yen',
1715
+ 'NZD' => 'New Zealand Dollars',
1716
+ 'CHF' => 'Swiss Francs',
1717
+ 'HKD' => 'Hong Kong Dollars',
1718
+ 'SGD' => 'Singapore Dollars',
1719
+ 'SEK' => 'Swedish Kronor',
1720
+ 'DKK' => 'Danish Kroner',
1721
+ 'PLN' => 'Polish Zloty',
1722
+ 'NOK' => 'Norwegian Kronor',
1723
+ 'HUF' => 'Hungarian Forint',
1724
+ 'CZK' => 'Check Koruna',
1725
+ 'ILS' => 'Israeli Shekel',
1726
+ 'MXN' => 'Mexican Peso',
1727
+ 'BRL' => 'Brazilian Real',
1728
+ 'MYR' => 'Malaysian Ringgits',
1729
+ 'PHP' => 'Philippine Pesos',
1730
+ 'RUB' => 'Russian Ruble',
1731
+ 'TWD' => 'Taiwan New Dollars',
1732
+ 'THB' => 'Thai Baht'
1733
+ );
1734
+ $currencies = apply_filters('mycred_dropdown_currencies', $currencies, $this->id);
1735
+ $currencies = apply_filters('mycred_dropdown_currencies_' . $this->id, $currencies);
1736
+
1737
+ if ($js != '' ) {
1738
+ $js = ' data-update="' . $js . '"';
1739
+ }
1740
+
1741
+ echo '<select name="' . $this->field_name($name) . '" id="' . $this->field_id($name) . '" class="currency form-control"' . $js . '>';
1742
+ echo '<option value="">' . __('Select', 'mycred') . '</option>';
1743
+ foreach ( $currencies as $code => $cname ) {
1744
+ echo '<option value="' . $code . '"';
1745
+ if (isset($this->prefs[ $name ]) && $this->prefs[ $name ] == $code ) { echo ' selected="selected"';
1746
+ }
1747
+ echo '>' . $cname . '</option>';
1748
+ }
1749
+ echo '</select>';
1750
+
1751
+ }
1752
+
1753
+ /**
1754
+ * Item Type Dropdown
1755
+ *
1756
+ * @since 0.1
1757
+ * @version 1.0
1758
+ */
1759
+ public function item_types_dropdown( $name = '' )
1760
+ {
1761
+
1762
+ $types = array(
1763
+ 'product' => 'Product',
1764
+ 'service' => 'Service',
1765
+ 'donation' => 'Donation'
1766
+ );
1767
+ $types = apply_filters('mycred_dropdown_item_types', $types);
1768
+
1769
+ echo '<select name="' . $this->field_name($name) . '" id="' . $this->field_id($name) . '">';
1770
+ echo '<option value="">' . __('Select', 'mycred') . '</option>';
1771
+ foreach ( $types as $code => $cname ) {
1772
+ echo '<option value="' . $code . '"';
1773
+ if (isset($this->prefs[ $name ]) && $this->prefs[ $name ] == $code ) { echo ' selected="selected"';
1774
+ }
1775
+ echo '>' . $cname . '</option>';
1776
+ }
1777
+ echo '</select>';
1778
+
1779
+ }
1780
+
1781
+ /**
1782
+ * Countries Dropdown Options
1783
+ *
1784
+ * @since 0.1
1785
+ * @version 1.0
1786
+ */
1787
+ public function list_option_countries( $selected = '' )
1788
+ {
1789
+
1790
+ $countries = array (
1791
+ "US" => "UNITED STATES",
1792
+ "AF" => "AFGHANISTAN",
1793
+ "AL" => "ALBANIA",
1794
+ "DZ" => "ALGERIA",
1795
+ "AS" => "AMERICAN SAMOA",
1796
+ "AD" => "ANDORRA",
1797
+ "AO" => "ANGOLA",
1798
+ "AI" => "ANGUILLA",
1799
+ "AQ" => "ANTARCTICA",
1800
+ "AG" => "ANTIGUA AND BARBUDA",
1801
+ "AR" => "ARGENTINA",
1802
+ "AM" => "ARMENIA",
1803
+ "AW" => "ARUBA",
1804
+ "AU" => "AUSTRALIA",
1805
+ "AT" => "AUSTRIA",
1806
+ "AZ" => "AZERBAIJAN",
1807
+ "BS" => "BAHAMAS",
1808
+ "BH" => "BAHRAIN",
1809
+ "BD" => "BANGLADESH",
1810
+ "BB" => "BARBADOS",
1811
+ "BY" => "BELARUS",
1812
+ "BE" => "BELGIUM",
1813
+ "BZ" => "BELIZE",
1814
+ "BJ" => "BENIN",
1815
+ "BM" => "BERMUDA",
1816
+ "BT" => "BHUTAN",
1817
+ "BO" => "BOLIVIA",
1818
+ "BA" => "BOSNIA AND HERZEGOVINA",
1819
+ "BW" => "BOTSWANA",
1820
+ "BV" => "BOUVET ISLAND",
1821
+ "BR" => "BRAZIL",
1822
+ "IO" => "BRITISH INDIAN OCEAN TERRITORY",
1823
+ "BN" => "BRUNEI DARUSSALAM",
1824
+ "BG" => "BULGARIA",
1825
+ "BF" => "BURKINA FASO",
1826
+ "BI" => "BURUNDI",
1827
+ "KH" => "CAMBODIA",
1828
+ "CM" => "CAMEROON",
1829
+ "CA" => "CANADA",
1830
+ "CV" => "CAPE VERDE",
1831
+ "KY" => "CAYMAN ISLANDS",
1832
+ "CF" => "CENTRAL AFRICAN REPUBLIC",
1833
+ "TD" => "CHAD",
1834
+ "CL" => "CHILE",
1835
+ "CN" => "CHINA",
1836
+ "CX" => "CHRISTMAS ISLAND",
1837
+ "CC" => "COCOS (KEELING) ISLANDS",
1838
+ "CO" => "COLOMBIA",
1839
+ "KM" => "COMOROS",
1840
+ "CG" => "CONGO",
1841
+ "CD" => "CONGO, THE DEMOCRATIC REPUBLIC OF THE",
1842
+ "CK" => "COOK ISLANDS",
1843
+ "CR" => "COSTA RICA",
1844
+ "CI" => "COTE D'IVOIRE",
1845
+ "HR" => "CROATIA",
1846
+ "CU" => "CUBA",
1847
+ "CY" => "CYPRUS",
1848
+ "CZ" => "CZECH REPUBLIC",
1849
+ "DK" => "DENMARK",
1850
+ "DJ" => "DJIBOUTI",
1851
+ "DM" => "DOMINICA",
1852
+ "DO" => "DOMINICAN REPUBLIC",
1853
+ "EC" => "ECUADOR",
1854
+ "EG" => "EGYPT",
1855
+ "SV" => "EL SALVADOR",
1856
+ "GQ" => "EQUATORIAL GUINEA",
1857
+ "ER" => "ERITREA",
1858
+ "EE" => "ESTONIA",
1859
+ "ET" => "ETHIOPIA",
1860
+ "FK" => "FALKLAND ISLANDS (MALVINAS)",
1861
+ "FO" => "FAROE ISLANDS",
1862
+ "FJ" => "FIJI",
1863
+ "FI" => "FINLAND",
1864
+ "FR" => "FRANCE",
1865
+ "GF" => "FRENCH GUIANA",
1866
+ "PF" => "FRENCH POLYNESIA",
1867
+ "TF" => "FRENCH SOUTHERN TERRITORIES",
1868
+ "GA" => "GABON",
1869
+ "GM" => "GAMBIA",
1870
+ "GE" => "GEORGIA",
1871
+ "DE" => "GERMANY",
1872
+ "GH" => "GHANA",
1873
+ "GI" => "GIBRALTAR",
1874
+ "GR" => "GREECE",
1875
+ "GL" => "GREENLAND",
1876
+ "GD" => "GRENADA",
1877
+ "GP" => "GUADELOUPE",
1878
+ "GU" => "GUAM",
1879
+ "GT" => "GUATEMALA",
1880
+ "GN" => "GUINEA",
1881
+ "GW" => "GUINEA-BISSAU",
1882
+ "GY" => "GUYANA",
1883
+ "HT" => "HAITI",
1884
+ "HM" => "HEARD ISLAND AND MCDONALD ISLANDS",
1885
+ "VA" => "HOLY SEE (VATICAN CITY STATE)",
1886
+ "HN" => "HONDURAS",
1887
+ "HK" => "HONG KONG",
1888
+ "HU" => "HUNGARY",
1889
+ "IS" => "ICELAND",
1890
+ "IN" => "INDIA",
1891
+ "ID" => "INDONESIA",
1892
+ "IR" => "IRAN, ISLAMIC REPUBLIC OF",
1893
+ "IQ" => "IRAQ",
1894
+ "IE" => "IRELAND",
1895
+ "IL" => "ISRAEL",
1896
+ "IT" => "ITALY",
1897
+ "JM" => "JAMAICA",
1898
+ "JP" => "JAPAN",
1899
+ "JO" => "JORDAN",
1900
+ "KZ" => "KAZAKHSTAN",
1901
+ "KE" => "KENYA",
1902
+ "KI" => "KIRIBATI",
1903
+ "KP" => "KOREA, DEMOCRATIC PEOPLE'S REPUBLIC OF",
1904
+ "KR" => "KOREA, REPUBLIC OF",
1905
+ "KW" => "KUWAIT",
1906
+ "KG" => "KYRGYZSTAN",
1907
+ "LA" => "LAO PEOPLE'S DEMOCRATIC REPUBLIC",
1908
+ "LV" => "LATVIA",
1909
+ "LB" => "LEBANON",
1910
+ "LS" => "LESOTHO",
1911
+ "LR" => "LIBERIA",
1912
+ "LY" => "LIBYAN ARAB JAMAHIRIYA",
1913
+ "LI" => "LIECHTENSTEIN",
1914
+ "LT" => "LITHUANIA",
1915
+ "LU" => "LUXEMBOURG",
1916
+ "MO" => "MACAO",
1917
+ "MK" => "MACEDONIA, THE FORMER YUGOSLAV REPUBLIC OF",
1918
+ "MG" => "MADAGASCAR",
1919
+ "MW" => "MALAWI",
1920
+ "MY" => "MALAYSIA",
1921
+ "MV" => "MALDIVES",
1922
+ "ML" => "MALI",
1923
+ "MT" => "MALTA",
1924
+ "MH" => "MARSHALL ISLANDS",
1925
+ "MQ" => "MARTINIQUE",
1926
+ "MR" => "MAURITANIA",
1927
+ "MU" => "MAURITIUS",
1928
+ "YT" => "MAYOTTE",
1929
+ "MX" => "MEXICO",
1930
+ "FM" => "MICRONESIA, FEDERATED STATES OF",
1931
+ "MD" => "MOLDOVA, REPUBLIC OF",
1932
+ "MC" => "MONACO",
1933
+ "MN" => "MONGOLIA",
1934
+ "MS" => "MONTSERRAT",
1935
+ "MA" => "MOROCCO",
1936
+ "MZ" => "MOZAMBIQUE",
1937
+ "MM" => "MYANMAR",
1938
+ "NA" => "NAMIBIA",
1939
+ "NR" => "NAURU",
1940
+ "NP" => "NEPAL",
1941
+ "NL" => "NETHERLANDS",
1942
+ "AN" => "NETHERLANDS ANTILLES",
1943
+ "NC" => "NEW CALEDONIA",
1944
+ "NZ" => "NEW ZEALAND",
1945
+ "NI" => "NICARAGUA",
1946
+ "NE" => "NIGER",
1947
+ "NG" => "NIGERIA",
1948
+ "NU" => "NIUE",
1949
+ "NF" => "NORFOLK ISLAND",
1950
+ "MP" => "NORTHERN MARIANA ISLANDS",
1951
+ "NO" => "NORWAY",
1952
+ "OM" => "OMAN",
1953
+ "PK" => "PAKISTAN",
1954
+ "PW" => "PALAU",
1955
+ "PS" => "PALESTINIAN TERRITORY, OCCUPIED",
1956
+ "PA" => "PANAMA",
1957
+ "PG" => "PAPUA NEW GUINEA",
1958
+ "PY" => "PARAGUAY",
1959
+ "PE" => "PERU",
1960
+ "PH" => "PHILIPPINES",
1961
+ "PN" => "PITCAIRN",
1962
+ "PL" => "POLAND",
1963
+ "PT" => "PORTUGAL",
1964
+ "PR" => "PUERTO RICO",
1965
+ "QA" => "QATAR",
1966
+ "RE" => "REUNION",
1967
+ "RO" => "ROMANIA",
1968
+ "RU" => "RUSSIAN FEDERATION",
1969
+ "RW" => "RWANDA",
1970
+ "SH" => "SAINT HELENA",
1971
+ "KN" => "SAINT KITTS AND NEVIS",
1972
+ "LC" => "SAINT LUCIA",
1973
+ "PM" => "SAINT PIERRE AND MIQUELON",
1974
+ "VC" => "SAINT VINCENT AND THE GRENADINES",
1975
+ "WS" => "SAMOA",
1976
+ "SM" => "SAN MARINO",
1977
+ "ST" => "SAO TOME AND PRINCIPE",
1978
+ "SA" => "SAUDI ARABIA",
1979
+ "SN" => "SENEGAL",
1980
+ "CS" => "SERBIA AND MONTENEGRO",
1981
+ "SC" => "SEYCHELLES",
1982
+ "SL" => "SIERRA LEONE",
1983
+ "SG" => "SINGAPORE",
1984
+ "SK" => "SLOVAKIA",
1985
+ "SI" => "SLOVENIA",
1986
+ "SB" => "SOLOMON ISLANDS",
1987
+ "SO" => "SOMALIA",
1988
+ "ZA" => "SOUTH AFRICA",
1989
+ "GS" => "SOUTH GEORGIA AND THE SOUTH SANDWICH ISLANDS",
1990
+ "ES" => "SPAIN",
1991
+ "LK" => "SRI LANKA",
1992
+ "SD" => "SUDAN",
1993
+ "SR" => "SURINAME",
1994
+ "SJ" => "SVALBARD AND JAN MAYEN",
1995
+ "SZ" => "SWAZILAND",
1996
+ "SE" => "SWEDEN",
1997
+ "CH" => "SWITZERLAND",
1998
+ "SY" => "SYRIAN ARAB REPUBLIC",
1999
+ "TW" => "TAIWAN, PROVINCE OF CHINA",
2000
+ "TJ" => "TAJIKISTAN",
2001
+ "TZ" => "TANZANIA, UNITED REPUBLIC OF",
2002
+ "TH" => "THAILAND",
2003
+ "TL" => "TIMOR-LESTE",
2004
+ "TG" => "TOGO",
2005
+ "TK" => "TOKELAU",
2006
+ "TO" => "TONGA",
2007
+ "TT" => "TRINIDAD AND TOBAGO",
2008
+ "TN" => "TUNISIA",
2009
+ "TR" => "TURKEY",
2010
+ "TM" => "TURKMENISTAN",
2011
+ "TC" => "TURKS AND CAICOS ISLANDS",
2012
+ "TV" => "TUVALU",
2013
+ "UG" => "UGANDA",
2014
+ "UA" => "UKRAINE",
2015
+ "AE" => "UNITED ARAB EMIRATES",
2016
+ "GB" => "UNITED KINGDOM",
2017
+ "US" => "UNITED STATES",
2018
+ "UM" => "UNITED STATES MINOR OUTLYING ISLANDS",
2019
+ "UY" => "URUGUAY",
2020
+ "UZ" => "UZBEKISTAN",
2021
+ "VU" => "VANUATU",
2022
+ "VE" => "VENEZUELA",
2023
+ "VN" => "VIET NAM",
2024
+ "VG" => "VIRGIN ISLANDS, BRITISH",
2025
+ "VI" => "VIRGIN ISLANDS, U.S.",
2026
+ "WF" => "WALLIS AND FUTUNA",
2027
+ "EH" => "WESTERN SAHARA",
2028
+ "YE" => "YEMEN",
2029
+ "ZM" => "ZAMBIA",
2030
+ "ZW" => "ZIMBABWE"
2031
+ );
2032
+ $countries = apply_filters('mycred_list_option_countries', $countries);
2033
+
2034
+ foreach ( $countries as $code => $cname ) {
2035
+ echo '<option value="' . $code . '"';
2036
+ if ($selected == $code ) { echo ' selected="selected"';
2037
+ }
2038
+ echo '>' . $cname . '</option>';
2039
+ }
2040
+
2041
+ }
2042
+
2043
+ /**
2044
+ * US States Dropdown Options
2045
+ *
2046
+ * @since 0.1
2047
+ * @version 1.0
2048
+ */
2049
+ public function list_option_us_states( $selected = '', $non_us = false )
2050
+ {
2051
+
2052
+ $states = array (
2053
+ "AL" => "Alabama",
2054
+ "AK" => "Alaska",
2055
+ "AZ" => "Arizona",
2056
+ "AR" => "Arkansas",
2057
+ "CA" => "California",
2058
+ "CO" => "Colorado",
2059
+ "CT" => "Connecticut",
2060
+ "DC" => "D.C.",
2061
+ "DE" => "Delaware",
2062
+ "FL" => "Florida",
2063
+ "GA" => "Georgia",
2064
+ "HI" => "Hawaii",
2065
+ "ID" => "Idaho",
2066
+ "IL" => "Illinois",
2067
+ "IN" => "Indiana",
2068
+ "IA" => "Iowa",
2069
+ "KS" => "Kansas",
2070
+ "KY" => "Kentucky",
2071
+ "LA" => "Louisiana",
2072
+ "ME" => "Maine",
2073
+ "MD" => "Maryland",
2074
+ "MA" => "Massachusetts",
2075
+ "MI" => "Michigan",
2076
+ "MN" => "Minnesota",
2077
+ "MS" => "Mississippi",
2078
+ "MO" => "Missouri",
2079
+ "MT" => "Montana",
2080
+ "NE" => "Nebraska",
2081
+ "NV" => "Nevada",
2082
+ "NH" => "New Hampshire",
2083
+ "NJ" => "New Jersey",
2084
+ "NM" => "New Mexico",
2085
+ "NY" => "New York",
2086
+ "NC" => "North Carolina",
2087
+ "ND" => "North Dakota",
2088
+ "OH" => "Ohio",
2089
+ "OK" => "Oklahoma",
2090
+ "OR" => "Oregon",
2091
+ "PA" => "Pennsylvania",
2092
+ "RI" => "Rhode Island",
2093
+ "SC" => "South Carolina",
2094
+ "SD" => "South Dakota",
2095
+ "TN" => "Tennessee",
2096
+ "TX" => "Texas",
2097
+ "UT" => "Utah",
2098
+ "VT" => "Vermont",
2099
+ "VA" => "Virginia",
2100
+ "WA" => "Washington",
2101
+ "WV" => "West Virginia",
2102
+ "WI" => "Wisconsin",
2103
+ "WY" => "Wyoming"
2104
+ );
2105
+ $states = apply_filters('mycred_list_option_us', $states);
2106
+
2107
+ $outside = 'Outside US';
2108
+ if ($non_us == 'top' ) { echo '<option value="">' . $outside . '</option>';
2109
+ }
2110
+ foreach ( $states as $code => $cname ) {
2111
+ echo '<option value="' . $code . '"';
2112
+ if ($selected == $code ) { echo ' selected="selected"';
2113
+ }
2114
+ echo '>' . $cname . '</option>';
2115
+ }
2116
+ if ($non_us == 'bottom' ) { echo '<option value="">' . $outside . '</option>';
2117
+ }
2118
+
2119
+ }
2120
+
2121
+ /**
2122
+ * Months Dropdown Options
2123
+ *
2124
+ * @since 0.1
2125
+ * @version 1.0
2126
+ */
2127
+ public function list_option_months( $selected = '' )
2128
+ {
2129
+
2130
+ $months = array (
2131
+ "01" => __('January', 'mycred'),
2132
+ "02" => __('February', 'mycred'),
2133
+ "03" => __('March', 'mycred'),
2134
+ "04" => __('April', 'mycred'),
2135
+ "05" => __('May', 'mycred'),
2136
+ "06" => __('June', 'mycred'),
2137
+ "07" => __('July', 'mycred'),
2138
+ "08" => __('August', 'mycred'),
2139
+ "09" => __('September', 'mycred'),
2140
+ "10" => __('October', 'mycred'),
2141
+ "11" => __('November', 'mycred'),
2142
+ "12" => __('December', 'mycred')
2143
+ );
2144
+
2145
+ foreach ( $months as $number => $text ) {
2146
+ echo '<option value="' . $number . '"';
2147
+ if ($selected == $number ) { echo ' selected="selected"';
2148
+ }
2149
+ echo '>' . $text . '</option>';
2150
+ }
2151
+
2152
+ }
2153
+
2154
+ /**
2155
+ * Years Dropdown Options
2156
+ *
2157
+ * @since 0.1
2158
+ * @version 1.0
2159
+ */
2160
+ public function list_option_card_years( $selected = '', $number = 16 )
2161
+ {
2162
+
2163
+ $now = current_time('timestamp');
2164
+ $yy = date('y', $now);
2165
+ $yyyy = date('Y', $now);
2166
+ $count = 0;
2167
+ $options = array();
2168
+
2169
+ while ( $count <= (int) $number ) {
2170
+ $count ++;
2171
+ if ($count > 1 ) {
2172
+ $yy++;
2173
+ $yyyy++;
2174
+ }
2175
+ $options[ $yy ] = $yyyy;
2176
+ }
2177
+
2178
+ foreach ( $options as $key => $value ) {
2179
+ echo '<option value="' . $key . '"';
2180
+ if ($selected == $key ) { echo ' selected="selected"';
2181
+ }
2182
+ echo '>' . $value . '</option>';
2183
+ }
2184
+
2185
+ }
2186
+
2187
+ /**
2188
+ * IPN - Has Required Fields
2189
+ *
2190
+ * @since 1.4
2191
+ * @version 1.0
2192
+ */
2193
+ public function IPN_has_required_fields( $required_fields = array(), $method = 'REQUEST' )
2194
+ {
2195
+
2196
+ $missing = 0;
2197
+ foreach ( $required_fields as $field_key ) {
2198
+ if ($method == 'POST' ) {
2199
+ if (! isset($_POST[ $field_key ]) ) {
2200
+ $missing ++;
2201
+ }
2202
+ }
2203
+ elseif ($method == 'GET' ) {
2204
+ if (! isset($_GET[ $field_key ]) ) {
2205
+ $missing ++;
2206
+ }
2207
+ }
2208
+ elseif ($method == 'REQUEST' ) {
2209
+ if (! isset($_REQUEST[ $field_key ]) ) {
2210
+ $missing ++;
2211
+ }
2212
+ }
2213
+ else {
2214
+ if (! isset($method[ $field_key ]) ) {
2215
+ $missing ++;
2216
+ }
2217
+ }
2218
+ }
2219
+
2220
+ if ($missing > 0 ) {
2221
+ $result = false;
2222
+ } else {
2223
+ $result = true;
2224
+ }
2225
+
2226
+ $result = apply_filters('mycred_buycred_IPN_missing', $result, $required_fields, $this->id);
2227
+
2228
+ return $result;
2229
+
2230
+ }
2231
+
2232
+ /**
2233
+ * IPN - Is Valid Call
2234
+ *
2235
+ * @since 1.4
2236
+ * @version 1.0
2237
+ */
2238
+ public function IPN_is_valid_call()
2239
+ {
2240
+
2241
+ return false;
2242
+
2243
+ }
2244
+
2245
+ /**
2246
+ * IPN - Is Valid Sale
2247
+ *
2248
+ * @since 1.4
2249
+ * @version 1.1
2250
+ */
2251
+ public function IPN_is_valid_sale( $sales_data_key = '', $cost_key = '', $transactionid_key = '', $method = '' )
2252
+ {
2253
+
2254
+ if ($method == 'POST' ) {
2255
+ $post_id = $_POST[ $sales_data_key ];
2256
+ } elseif ($method == 'GET' ) {
2257
+ $post_id = $_GET[ $sales_data_key ];
2258
+ } else {
2259
+ $post_id = $_REQUEST[ $sales_data_key ];
2260
+ }
2261
+
2262
+ $pending_payment = $this->get_pending_payment($post_id);
2263
+ if ($pending_payment === false ) { return false;
2264
+ }
2265
+
2266
+ $result = true;
2267
+
2268
+ if ($method == 'POST' ) {
2269
+ $price = $_POST[ $cost_key ];
2270
+ } elseif ($method == 'GET' ) {
2271
+ $price = $_GET[ $cost_key ];
2272
+ } else {
2273
+ $price = $_REQUEST[ $cost_key ];
2274
+ }
2275
+
2276
+ if ($result === true && $pending_payment['cost'] != $price ) {
2277
+ $result = false;
2278
+ }
2279
+
2280
+ if ($result === true && isset($this->prefs['currency']) && $this->prefs['currency'] != $pending_payment['currency'] ) {
2281
+ $result = false;
2282
+ }
2283
+
2284
+ if ($method == 'POST' ) {
2285
+ $transaction_id = $_POST[ $transactionid_key ];
2286
+ } elseif ($method == 'GET' ) {
2287
+ $transaction_id = $_GET[ $transactionid_key ];
2288
+ } else {
2289
+ $transaction_id = $_REQUEST[ $transactionid_key ];
2290
+ }
2291
+
2292
+ if ($result === true && ! $this->transaction_id_is_unique($transaction_id) ) {
2293
+ $result = false;
2294
+ }
2295
+
2296
+ $result = apply_filters('mycred_buycred_valid_sale', $result, $sales_data_key, $cost_key, $transactionid_key, $method, $this);
2297
+
2298
+ if ($result === true ) {
2299
+ return $decoded_data;
2300
+ }
2301
+
2302
+ return $result;
2303
+
2304
+ }
2305
+
2306
+ /**
2307
+ * Complete Payment
2308
+ *
2309
+ * @since 1.4
2310
+ * @version 1.4
2311
+ */
2312
+ public function complete_payment( $pending_payment = null, $transaction_id = '' )
2313
+ {
2314
+
2315
+ if ($pending_payment === null ) { return false;
2316
+ }
2317
+
2318
+ $reply = false;
2319
+ $mycred = mycred($pending_payment->point_type);
2320
+
2321
+ $reference = 'buy_creds_with_' . str_replace(array( ' ', '-' ), '_', $this->id);
2322
+ $sales_data = array(
2323
+ 'to' => $pending_payment->recipient_id,
2324
+ 'from' => $pending_payment->buyer_id,
2325
+ 'amount' => $pending_payment->amount,
2326
+ 'cost' => $pending_payment->cost,
2327
+ 'currency' => $pending_payment->currency,
2328
+ 'ctype' => $pending_payment->point_type
2329
+ );
2330
+ $data = array( 'ref_type' => 'user', 'txn_id' => $transaction_id, 'sales_data' => implode('|', $sales_data) );
2331
+
2332
+ if (! $mycred->has_entry($reference, $pending_payment->buyer_id, $pending_payment->recipient_id, $data, $pending_payment->point_type) ) {
2333
+
2334
+ add_filter('mycred_get_email_events', array( $this, 'email_notice' ), 10, 2);
2335
+ $reply = $mycred->add_creds(
2336
+ $reference,
2337
+ $pending_payment->recipient_id,
2338
+ $pending_payment->amount,
2339
+ $this->get_log_entry($pending_payment->recipient_id, $pending_payment->buyer_id),
2340
+ $pending_payment->buyer_id,
2341
+ $data,
2342
+ $pending_payment->point_type
2343
+ );
2344
+ remove_filter('mycred_get_email_events', array( $this, 'email_notice' ), 10, 2);
2345
+
2346
+ }
2347
+
2348
+ return apply_filters('mycred_buycred_complete_payment', $reply, $transaction_id, $this);
2349
+
2350
+ }
2351
+
2352
+ /**
2353
+ * Email Notice Add-on Support
2354
+ *
2355
+ * @since 1.5.4
2356
+ * @version 1.0
2357
+ */
2358
+ public function email_notice( $events, $request )
2359
+ {
2360
+
2361
+ if (substr($request['ref'], 0, 15) == 'buy_creds_with_' ) {
2362
+ $events[] = 'buy_creds|positive';
2363
+ }
2364
+
2365
+ return $events;
2366
+
2367
+ }
2368
+
2369
+ /**
2370
+ * Trash Pending Payment
2371
+ *
2372
+ * @since 1.5.3
2373
+ * @version 1.0.1
2374
+ */
2375
+ public function trash_pending_payment( $payment_id )
2376
+ {
2377
+
2378
+ return buycred_trash_pending_payment($payment_id);
2379
+
2380
+ }
2381
+
2382
+ }
2383
  endif;
addons/buy-creds/assets/css/admin-style.css CHANGED
@@ -1,15 +1,15 @@
1
  .mycred-metabox .widget-content .hook-instance .specific-hook-actions {
2
- margin-bottom: 12px !important;
3
  }
4
 
5
  .mycred-metabox .widget-content .hook-instance:last-child .specific-hook-actions {
6
- margin-bottom: 0px !important;
7
  }
8
 
9
  .mycred-metabox .widget-content .hook-instance .specific-hook-actions .mycred-add-specific-hook {
10
- display: none;
11
  }
12
 
13
  .mycred-metabox .widget-content .hook-instance:last-child .specific-hook-actions .mycred-add-specific-hook {
14
- display: initial;
15
  }
1
  .mycred-metabox .widget-content .hook-instance .specific-hook-actions {
2
+ margin-bottom: 12px !important;
3
  }
4
 
5
  .mycred-metabox .widget-content .hook-instance:last-child .specific-hook-actions {
6
+ margin-bottom: 0px !important;
7
  }
8
 
9
  .mycred-metabox .widget-content .hook-instance .specific-hook-actions .mycred-add-specific-hook {
10
+ display: none;
11
  }
12
 
13
  .mycred-metabox .widget-content .hook-instance:last-child .specific-hook-actions .mycred-add-specific-hook {
14
+ display: initial;
15
  }
addons/buy-creds/assets/css/index.php CHANGED
@@ -1,3 +1,3 @@
1
  <?php
2
  // Silence is golden.
3
- ?>
1
  <?php
2
  // Silence is golden.
3
+ ?>
addons/buy-creds/assets/images/index.php CHANGED
@@ -1,3 +1,3 @@
1
  <?php
2
  // Silence is golden.
3
- ?>
1
  <?php
2
  // Silence is golden.
3
+ ?>
addons/buy-creds/assets/index.php CHANGED
@@ -1,3 +1,3 @@
1
  <?php
2
  // Silence is golden.
3
- ?>
1
  <?php
2
  // Silence is golden.
3
+ ?>
addons/buy-creds/assets/js/checkout.js CHANGED
@@ -1,202 +1,237 @@
1
  /**
2
  * buyCRED Checkout
3
- * @since 1.8
 
4
  * @version 1.0
5
  */
6
- jQuery(function($){
 
 
 
 
 
 
 
 
7
 
8
- var buyCREDcheckout = $( '#buycred-checkout-wrapper' );
9
- var buyCREDform = $( '#buycred-checkout-wrapper #buycred-checkout-form' );
10
- var buyCREDcancel = $( '#cancel-checkout-wrapper' );
11
- var activeForm;
 
 
 
12
 
13
- var buycred_send_call = function( formdata ) {
14
 
15
- $.ajax({
16
- type : "POST",
17
- data : formdata,
18
- dataType : "JSON",
19
- url : buyCRED.ajaxurl,
20
- success : function( response ) {
 
 
 
 
 
 
 
 
 
21
 
22
- console.log(response);
 
 
 
 
 
 
 
 
 
 
 
23
 
24
- if ( typeof response.validationFail === "undefined" ) {
25
- buyCREDform.slideUp(function(){
26
- buyCREDform.empty().append( response ).slideDown();
27
- });
28
- }
29
- else {
30
- buyCREDform.slideUp(function(){
31
- buyCREDform.empty().append( '<div class="padded error">' + response.errors[0] + '</div>' ).slideDown();
32
- });
33
- buyCREDcancel.addClass( 'on' );
34
- }
35
 
36
- }
37
- });
38
 
39
- };
 
40
 
41
- $(document).ready(function(){
42
 
43
- // Forms rendered by mycred_buy
44
- $( 'body' ).on( 'click', '.mycred-buy-link', function(e){
 
 
 
 
45
 
46
- if ( buyCRED.checkout == 'popup' ) {
47
 
48
- e.preventDefault();
 
49
 
50
- buyCREDcancel.removeClass( 'on' );
51
- buyCREDcheckout.addClass( 'open' );
 
52
 
53
- activeForm = $(this);
54
 
55
- var targeturl = $(this).attr( 'href' );
56
- var formdata = JSON.parse( '{"' + decodeURI( targeturl ).replace(/"/g, '\\"').replace(/&/g, '","').replace(/=/g,'":"') + '"}' );
57
- formdata['ajax'] = 1;
58
- formdata['mycred_buy'] = $(this).data( 'gateway' );
59
- console.log( formdata );
60
- buycred_send_call( formdata );
61
 
62
- }
 
63
 
64
- });
65
 
66
- // Forms rendered by mycred_buy_form
67
- $( 'body' ).on( 'submit', '.myCRED-buy-form', function(e){
 
68
 
69
- if ( buyCRED.checkout == 'popup' ) {
 
 
 
 
 
 
 
70
 
71
- e.preventDefault();
 
 
 
 
 
 
 
 
72
 
73
- buyCREDcancel.removeClass( 'on' );
74
- buyCREDcheckout.addClass( 'open' );
75
 
76
- activeForm = $(this);
77
 
78
- var formdata = { ajax : 1 };
79
- var fields = $(this).find( 'input' );
80
- var selects = $(this).find( 'select' );
81
 
82
- fields.each(function(index, item){
83
- var element = $(this);
84
- if ( element.attr( 'name' ) !== undefined ) {
85
- formdata[ element.attr( 'name' ) ] = element.val();
86
- }
87
- });
88
 
89
- selects.each(function(index, item){
90
- var element = $(this);
91
- var option = element.find( ':selected' );
92
- if ( option.val() !== undefined ) {
93
- formdata[ element.attr( 'name' ) ] = option.val();
94
- }
95
- });
96
 
97
- buycred_send_call( formdata );
98
 
99
- }
 
 
 
 
 
 
 
 
 
100
 
101
- });
102
 
103
- $( '#buycred-checkout-wrapper' ).on( 'click', '.checkout-footer button', function(e){
104
 
105
- var buttontype = $(this).data( 'act' );
106
- var buttonvalue = $(this).data( 'value' );
 
 
 
 
107
 
108
- if ( buttontype == 'redirect' ) {
 
109
 
110
- $(this).attr( 'disabled', 'disabled' ).html( buyCRED.redirecting );
111
-
112
- if ( $(this).hasClass('bitpay') ) {
113
- window.location = buttonvalue;
114
- }
115
- else
116
- {
117
- buyCREDform.attr( 'action', buttonvalue );
118
- buyCREDform.submit();
119
- }
120
 
121
- }
122
 
123
- else if ( buttontype == 'toggle' ) {
 
124
 
125
- var toggleelement = $( '#' + buttonvalue );
126
- toggleelement.prev().slideUp(function(){
127
- toggleelement.slideDown();
128
- });
129
 
130
- $(this).parent().slideUp();
131
- buyCREDcancel.addClass( 'on' );
 
132
 
133
- }
134
 
135
- $( '#buycred-checkout-wrapper .cancel a' ).slideUp();
 
 
 
 
 
 
136
 
137
- });
138
 
139
- $( '#buycred-checkout-page' ).on( 'click', '.checkout-footer button', function(){
140
 
141
- var pageform = $( '#buycred-checkout-page form' );
142
- var buttontype = $(this).data( 'act' );
143
- var buttonvalue = $(this).data( 'value' );
144
 
145
- if ( buttontype == 'redirect' ) {
 
 
 
 
 
146
 
147
- if ( $(this).hasClass('bitpay') ) {
148
- window.location = buttonvalue;
149
- }
150
- else {
151
- pageform.attr( 'action', buttonvalue );
152
- pageform.submit();
153
- }
154
 
155
- $(this).attr( 'disabled', 'disabled' ).html( buyCRED.redirecting );
156
 
157
- }
 
158
 
159
- else if ( buttontype == 'toggle' ) {
 
160
 
161
- var toggleelement = $( '#' + buttonvalue );
162
- toggleelement.prev().slideUp(function(){
163
- toggleelement.slideDown();
164
- });
 
 
 
165
 
166
- $(this).parent().slideUp();
 
 
 
167
 
168
- }
 
169
 
170
- });
 
171
 
172
- buyCREDcancel.on( 'click', function(){
173
 
174
- // Reset the form that was originally submitted
175
- var formfields = activeForm.find( 'input.form-control' );
176
- formfields.each(function(){
177
- $(this).val( '' );
178
- });
179
 
180
- $(this).removeClass( 'on' );
181
- buyCREDcheckout.removeClass( 'open' );
182
- buyCREDcancel.removeClass( 'open' );
183
- buyCREDform.attr( 'action', '' ).empty().append( '<div class="loading-indicator"></div>' );
 
184
 
185
- });
 
186
 
187
- $( '#buycred-checkout-wrapper' ).on( 'click', '.cancel a', function(e){
 
188
 
189
- $( '#buycred-checkout-wrapper form .checkout-footer' ).slideUp();
190
-
191
- });
192
-
193
- $( document ).on( 'change', '.mycred-change-pointtypes', function(){
194
-
195
- var value = $(this).find('option:selected').text();
196
- var label = $('.mycred-point-type').html(value);
197
-
198
- });
199
-
200
- });
201
-
202
- });
1
  /**
2
  * buyCRED Checkout
3
+ *
4
+ * @since 1.8
5
  * @version 1.0
6
  */
7
+ jQuery(
8
+ function ($) {
9
+
10
+ var buyCREDcheckout = $('#buycred-checkout-wrapper');
11
+ var buyCREDform = $('#buycred-checkout-wrapper #buycred-checkout-form');
12
+ var buyCREDcancel = $('#cancel-checkout-wrapper');
13
+ var activeForm;
14
+
15
+ var buycred_send_call = function ( formdata ) {
16
 
17
+ $.ajax(
18
+ {
19
+ type : "POST",
20
+ data : formdata,
21
+ dataType : "JSON",
22
+ url : buyCRED.ajaxurl,
23
+ success : function ( response ) {
24
 
25
+ console.log(response);
26
 
27
+ if (typeof response.validationFail === "undefined" ) {
28
+ buyCREDform.slideUp(
29
+ function () {
30
+ buyCREDform.empty().append(response).slideDown();
31
+ }
32
+ );
33
+ }
34
+ else {
35
+ buyCREDform.slideUp(
36
+ function () {
37
+ buyCREDform.empty().append('<div class="padded error">' + response.errors[0] + '</div>').slideDown();
38
+ }
39
+ );
40
+ buyCREDcancel.addClass('on');
41
+ }
42
 
43
+ }
44
+ }
45
+ );
46
+
47
+ };
48
+
49
+ $(document).ready(
50
+ function () {
51
+
52
+ // Forms rendered by mycred_buy
53
+ $('body').on(
54
+ 'click', '.mycred-buy-link', function (e) {
55
 
56
+ if (buyCRED.checkout == 'popup' ) {
 
 
 
 
 
 
 
 
 
 
57
 
58
+ e.preventDefault();
 
59
 
60
+ buyCREDcancel.removeClass('on');
61
+ buyCREDcheckout.addClass('open');
62
 
63
+ activeForm = $(this);
64
 
65
+ var targeturl = $(this).attr('href');
66
+ var formdata = JSON.parse('{"' + decodeURI(targeturl).replace(/"/g, '\\"').replace(/&/g, '","').replace(/=/g,'":"') + '"}');
67
+ formdata['ajax'] = 1;
68
+ formdata['mycred_buy'] = $(this).data('gateway');
69
+ console.log(formdata);
70
+ buycred_send_call(formdata);
71
 
72
+ }
73
 
74
+ }
75
+ );
76
 
77
+ // Forms rendered by mycred_buy_form
78
+ $('body').on(
79
+ 'submit', '.myCRED-buy-form', function (e) {
80
 
81
+ if (buyCRED.checkout == 'popup' ) {
82
 
83
+ e.preventDefault();
 
 
 
 
 
84
 
85
+ buyCREDcancel.removeClass('on');
86
+ buyCREDcheckout.addClass('open');
87
 
88
+ activeForm = $(this);
89
 
90
+ var formdata = { ajax : 1 };
91
+ var fields = $(this).find('input');
92
+ var selects = $(this).find('select');
93
 
94
+ fields.each(
95
+ function (index, item) {
96
+ var element = $(this);
97
+ if (element.attr('name') !== undefined ) {
98
+ formdata[ element.attr('name') ] = element.val();
99
+ }
100
+ }
101
+ );
102
 
103
+ selects.each(
104
+ function (index, item) {
105
+ var element = $(this);
106
+ var option = element.find(':selected');
107
+ if (option.val() !== undefined ) {
108
+ formdata[ element.attr('name') ] = option.val();
109
+ }
110
+ }
111
+ );
112
 
113
+ buycred_send_call(formdata);
 
114
 
115
+ }
116
 
117
+ }
118
+ );
 
119
 
120
+ $('#buycred-checkout-wrapper').on(
121
+ 'click', '.checkout-footer button', function (e) {
 
 
 
 
122
 
123
+ var buttontype = $(this).data('act');
124
+ var buttonvalue = $(this).data('value');
 
 
 
 
 
125
 
126
+ if (buttontype == 'redirect' ) {
127
 
128
+ $(this).attr('disabled', 'disabled').html(buyCRED.redirecting);
129
+
130
+ if ($(this).hasClass('bitpay') ) {
131
+ window.location = buttonvalue;
132
+ }
133
+ else
134
+ {
135
+ buyCREDform.attr('action', buttonvalue);
136
+ buyCREDform.submit();
137
+ }
138
 
139
+ }
140
 
141
+ else if (buttontype == 'toggle' ) {
142
 
143
+ var toggleelement = $('#' + buttonvalue);
144
+ toggleelement.prev().slideUp(
145
+ function () {
146
+ toggleelement.slideDown();
147
+ }
148
+ );
149
 
150
+ $(this).parent().slideUp();
151
+ buyCREDcancel.addClass('on');
152
 
153
+ }
 
 
 
 
 
 
 
 
 
154
 
155
+ $('#buycred-checkout-wrapper .cancel a').slideUp();
156
 
157
+ }
158
+ );
159
 
160
+ $('#buycred-checkout-page').on(
161
+ 'click', '.checkout-footer button', function () {
 
 
162
 
163
+ var pageform = $('#buycred-checkout-page form');
164
+ var buttontype = $(this).data('act');
165
+ var buttonvalue = $(this).data('value');
166
 
167
+ if (buttontype == 'redirect' ) {
168
 
169
+ if ($(this).hasClass('bitpay') ) {
170
+ window.location = buttonvalue;
171
+ }
172
+ else {
173
+ pageform.attr('action', buttonvalue);
174
+ pageform.submit();
175
+ }
176
 
177
+ $(this).attr('disabled', 'disabled').html(buyCRED.redirecting);
178
 
179
+ }
180
 
181
+ else if (buttontype == 'toggle' ) {
 
 
182
 
183
+ var toggleelement = $('#' + buttonvalue);
184
+ toggleelement.prev().slideUp(
185
+ function () {
186
+ toggleelement.slideDown();
187
+ }
188
+ );
189
 
190
+ $(this).parent().slideUp();
 
 
 
 
 
 
191
 
192
+ }
193
 
194
+ }
195
+ );
196
 
197
+ buyCREDcancel.on(
198
+ 'click', function () {
199
 
200
+ // Reset the form that was originally submitted
201
+ var formfields = activeForm.find('input.form-control');
202
+ formfields.each(
203
+ function () {
204
+ $(this).val('');
205
+ }
206
+ );
207
 
208
+ $(this).removeClass('on');
209
+ buyCREDcheckout.removeClass('open');
210
+ buyCREDcancel.removeClass('open');
211
+ buyCREDform.attr('action', '').empty().append('<div class="loading-indicator"></div>');
212
 
213
+ }
214
+ );
215
 
216
+ $('#buycred-checkout-wrapper').on(
217
+ 'click', '.cancel a', function (e) {
218
 
219
+ $('#buycred-checkout-wrapper form .checkout-footer').slideUp();
220
 
221
+ }
222
+ );
 
 
 
223
 
224
+ $(document).on(
225
+ 'change', '.mycred-change-pointtypes', function () {
226
+
227
+ var value = $(this).find('option:selected').text();
228
+ var label = $('.mycred-point-type').html(value);
229
 
230
+ }
231
+ );
232
 
233
+ }
234
+ );
235
 
236
+ }
237
+ );
 
 
 
 
 
 
 
 
 
 
 
 
addons/buy-creds/assets/js/index.php CHANGED
@@ -1,3 +1,3 @@
1
  <?php
2
  // Silence is golden.
3
- ?>
1
  <?php
2
  // Silence is golden.
3
+ ?>
addons/buy-creds/gateways/Bitpay/Autoloader.php CHANGED
@@ -47,7 +47,7 @@ class Autoloader
47
  $file = __DIR__.DIRECTORY_SEPARATOR.str_replace('\\', DIRECTORY_SEPARATOR, $classname).'.php';
48
 
49
  if (is_file($file) && is_readable($file)) {
50
- require_once $file;
51
 
52
  return true;
53
  }
47
  $file = __DIR__.DIRECTORY_SEPARATOR.str_replace('\\', DIRECTORY_SEPARATOR, $classname).'.php';
48
 
49
  if (is_file($file) && is_readable($file)) {
50
+ include_once $file;
51
 
52
  return true;
53
  }
addons/buy-creds/gateways/Bitpay/Client/Adapter/CurlAdapter.php CHANGED
@@ -77,7 +77,11 @@ class CurlAdapter implements AdapterInterface
77
  throw new \Bitpay\Client\ConnectionException($errorMessage);
78
  }
79
 
80
- /** @var ResponseInterface */
 
 
 
 
81
  $response = Response::createFromRawResponse($raw);
82
 
83
  curl_close($curl);
@@ -88,7 +92,7 @@ class CurlAdapter implements AdapterInterface
88
  /**
89
  * Returns an array of default curl settings to use
90
  *
91
- * @param RequestInterface $request
92
  * @return array
93
  */
94
  private function getCurlDefaultOptions(RequestInterface $request)
77
  throw new \Bitpay\Client\ConnectionException($errorMessage);
78
  }
79
 
80
+ /**
81
+ *
82
+ *
83
+ * @var ResponseInterface
84
+ */
85
  $response = Response::createFromRawResponse($raw);
86
 
87
  curl_close($curl);
92
  /**
93
  * Returns an array of default curl settings to use
94
  *
95
+ * @param RequestInterface $request
96
  * @return array
97
  */
98
  private function getCurlDefaultOptions(RequestInterface $request)
addons/buy-creds/gateways/Bitpay/Client/Client.php CHANGED
@@ -98,7 +98,7 @@ class Client implements ClientInterface
98
  }
99
 
100
  /**
101
- * @param TokenInterface $token
102
  * @return ClientInterface
103
  */
104
  public function setToken(TokenInterface $token)
@@ -197,20 +197,22 @@ class Client implements ClientInterface
197
  throw new \Exception('Error with request: no data returned');
198
  }
199
  $currencies = $body['data'];
200
- array_walk($currencies, function (&$value, $key) {
201
- $currency = new \Bitpay\Currency();
202
- $currency
203
- ->setCode($value['code'])
204
- ->setSymbol($value['symbol'])
205
- ->setPrecision($value['precision'])
206
- ->setExchangePctFee($value['exchangePctFee'])
207
- ->setPayoutEnabled($value['payoutEnabled'])
208
- ->setName($value['name'])
209
- ->setPluralName($value['plural'])
210
- ->setAlts($value['alts'])
211
- ->setPayoutFields($value['payoutFields']);
212
- $value = $currency;
213
- });
 
 
214
 
215
  return $currencies;
216
  }
@@ -314,48 +316,54 @@ class Client implements ClientInterface
314
 
315
  $payouts = array();
316
 
317
- array_walk($body['data'], function ($value, $key) use (&$payouts) {
318
- $payout = new \Bitpay\Payout();
319
- $payout
320
- ->setId($value['id'])
321
- ->setAccountId($value['account'])
322
- ->setCurrency(new \Bitpay\Currency($value['currency']))
323
- ->setEffectiveDate($value['effectiveDate'])
324
- ->setRequestdate($value['requestDate'])
325
- ->setPricingMethod($value['pricingMethod'])
326
- ->setStatus($value['status'])
327
- ->setAmount($value['amount'])
328
- ->setResponseToken($value['token'])
329
- ->setRate(@$value['rate'])
330
- ->setBtcAmount(@$value['btc'])
331
- ->setReference(@$value['reference'])
332
- ->setNotificationURL(@$value['notificationURL'])
333
- ->setNotificationEmail(@$value['notificationEmail']);
334
-
335
- array_walk($value['instructions'], function ($value, $key) use (&$payout) {
336
- $instruction = new \Bitpay\PayoutInstruction();
337
- $instruction
338
  ->setId($value['id'])
339
- ->setLabel($value['label'])
340
- ->setAddress($value['address'])
 
 
 
 
341
  ->setAmount($value['amount'])
342
- ->setStatus($value['status']);
343
-
344
- array_walk($value['transactions'], function ($value, $key) use (&$instruction) {
345
- $transaction = new \Bitpay\PayoutTransaction();
346
- $transaction
347
- ->setTransactionId($value['txid'])
348
- ->setAmount($value['amount'])
349
- ->setDate($value['date']);
350
-
351
- $instruction->addTransaction($transaction);
352
- });
353
-
354
- $payout->addInstruction($instruction);
355
- });
356
-
357
- $payouts[] = $payout;
358
- });
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
359
 
360
  return $payouts;
361
  }
@@ -424,28 +432,32 @@ class Client implements ClientInterface
424
  ->setEffectiveDate($data['effectiveDate'])
425
  ->setResponseToken($data['token']);
426
 
427
- array_walk($data['instructions'], function ($value, $key) use (&$payout) {
428
- $instruction = new \Bitpay\PayoutInstruction();
429
- $instruction
430
- ->setId($value['id'])
431
- ->setLabel($value['label'])
432
- ->setAddress($value['address'])
433
- ->setStatus($value['status'])
434
- ->setAmount($value['amount'])
435
- ->setBtc($value['btc']);
436
-
437
- array_walk($value['transactions'], function ($value, $key) use (&$instruction) {
438
- $transaction = new \Bitpay\PayoutTransaction();
439
- $transaction
440
- ->setTransactionId($value['txid'])
441
  ->setAmount($value['amount'])
442
- ->setDate($value['date']);
 
 
 
 
 
 
 
 
443
 
444
- $instruction->addTransaction($transaction);
445
- });
 
446
 
447
- $payout->addInstruction($instruction);
448
- });
 
449
 
450
  return $payout;
451
  }
@@ -470,16 +482,18 @@ class Client implements ClientInterface
470
 
471
  $tokens = array();
472
 
473
- array_walk($body['data'], function ($value, $key) use (&$tokens) {
474
- $key = current(array_keys($value));
475
- $value = current(array_values($value));
476
- $token = new \Bitpay\Token();
477
- $token
478
- ->setFacade($key)
479
- ->setToken($value);
 
480
 
481
- $tokens[$token->getFacade()] = $token;
482
- });
 
483
 
484
  return $tokens;
485
  }
@@ -599,7 +613,7 @@ class Client implements ClientInterface
599
  }
600
 
601
  /**
602
- * @param RequestInterface $request
603
  * @return ResponseInterface
604
  */
605
  public function sendRequest(RequestInterface $request)
98
  }
99
 
100
  /**
101
+ * @param TokenInterface $token
102
  * @return ClientInterface
103
  */
104
  public function setToken(TokenInterface $token)
197
  throw new \Exception('Error with request: no data returned');
198
  }
199
  $currencies = $body['data'];
200
+ array_walk(
201
+ $currencies, function (&$value, $key) {
202
+ $currency = new \Bitpay\Currency();
203
+ $currency
204
+ ->setCode($value['code'])
205
+ ->setSymbol($value['symbol'])
206
+ ->setPrecision($value['precision'])
207
+ ->setExchangePctFee($value['exchangePctFee'])
208
+ ->setPayoutEnabled($value['payoutEnabled'])
209
+ ->setName($value['name'])
210
+ ->setPluralName($value['plural'])
211
+ ->setAlts($value['alts'])
212
+ ->setPayoutFields($value['payoutFields']);
213
+ $value = $currency;
214
+ }
215
+ );
216
 
217
  return $currencies;
218
  }
316
 
317
  $payouts = array();
318
 
319
+ array_walk(
320
+ $body['data'], function ($value, $key) use (&$payouts) {
321
+ $payout = new \Bitpay\Payout();
322
+ $payout
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
323
  ->setId($value['id'])
324
+ ->setAccountId($value['account'])
325
+ ->setCurrency(new \Bitpay\Currency($value['currency']))
326
+ ->setEffectiveDate($value['effectiveDate'])
327
+ ->setRequestdate($value['requestDate'])
328
+ ->setPricingMethod($value['pricingMethod'])
329
+ ->setStatus($value['status'])
330
  ->setAmount($value['amount'])
331
+ ->setResponseToken($value['token'])
332
+ ->setRate(@$value['rate'])
333
+ ->setBtcAmount(@$value['btc'])
334
+ ->setReference(@$value['reference'])
335
+ ->setNotificationURL(@$value['notificationURL'])
336
+ ->setNotificationEmail(@$value['notificationEmail']);
337
+
338
+ array_walk(
339
+ $value['instructions'], function ($value, $key) use (&$payout) {
340
+ $instruction = new \Bitpay\PayoutInstruction();
341
+ $instruction
342
+ ->setId($value['id'])
343
+ ->setLabel($value['label'])
344
+ ->setAddress($value['address'])
345
+ ->setAmount($value['amount'])
346
+ ->setStatus($value['status']);
347
+
348
+ array_walk(
349
+ $value['transactions'], function ($value, $key) use (&$instruction) {
350
+ $transaction = new \Bitpay\PayoutTransaction();
351
+ $transaction
352
+ ->setTransactionId($value['txid'])
353
+ ->setAmount($value['amount'])
354
+ ->setDate($value['date']);
355
+
356
+ $instruction->addTransaction($transaction);
357
+ }
358
+ );
359
+
360
+ $payout->addInstruction($instruction);
361
+ }
362
+ );
363
+
364
+ $payouts[] = $payout;
365
+ }
366
+ );
367
 
368
  return $payouts;
369
  }
432
  ->setEffectiveDate($data['effectiveDate'])
433
  ->setResponseToken($data['token']);
434
 
435
+ array_walk(
436
+ $data['instructions'], function ($value, $key) use (&$payout) {
437
+ $instruction = new \Bitpay\PayoutInstruction();
438
+ $instruction
439
+ ->setId($value['id'])
440
+ ->setLabel($value['label'])
441
+ ->setAddress($value['address'])
442
+ ->setStatus($value['status'])
 
 
 
 
 
 
443
  ->setAmount($value['amount'])
444
+ ->setBtc($value['btc']);
445
+
446
+ array_walk(
447
+ $value['transactions'], function ($value, $key) use (&$instruction) {
448
+ $transaction = new \Bitpay\PayoutTransaction();
449
+ $transaction
450
+ ->setTransactionId($value['txid'])
451
+ ->setAmount($value['amount'])
452
+ ->setDate($value['date']);
453
 
454
+ $instruction->addTransaction($transaction);
455
+ }
456
+ );
457
 
458
+ $payout->addInstruction($instruction);
459
+ }
460
+ );
461
 
462
  return $payout;
463
  }
482
 
483
  $tokens = array();
484
 
485
+ array_walk(
486
+ $body['data'], function ($value, $key) use (&$tokens) {
487
+ $key = current(array_keys($value));
488
+ $value = current(array_values($value));
489
+ $token = new \Bitpay\Token();
490
+ $token
491
+ ->setFacade($key)
492
+ ->setToken($value);
493
 
494
+ $tokens[$token->getFacade()] = $token;
495
+ }
496
+ );
497
 
498
  return $tokens;
499
  }
613
  }
614
 
615
  /**
616
+ * @param RequestInterface $request
617
  * @return ResponseInterface
618
  */
619
  public function sendRequest(RequestInterface $request)
addons/buy-creds/gateways/Bitpay/Client/ClientInterface.php CHANGED
@@ -42,7 +42,7 @@ interface ClientInterface
42
  public function getCurrencies();
43
 
44
  /**
45
- * @param InvoiceInterface $invoiceId
46
  * @return \Bitpay\Invoice
47
  * @throws \Exception
48
  */
@@ -50,7 +50,7 @@ interface ClientInterface
50
  //public function getInvoices();
51
 
52
  /**
53
- * @param $invoiceId
54
  * @return InvoiceInterface
55
  * @throws \Exception
56
  */
@@ -65,28 +65,29 @@ interface ClientInterface
65
 
66
  /**
67
  * Create a Payout Request on Bitpay
68
- * @param PayoutInterface $payout
 
69
  * @return PayoutInterface|mixed
70
  * @throws \Exception
71
  */
72
  public function createPayout(PayoutInterface $payout);
73
 
74
  /**
75
- * @param null $status
76
  * @return array
77
  * @throws \Exception
78
  */
79
  public function getPayouts($status = null);
80
 
81
  /**
82
- * @param $payoutId
83
  * @return \Bitpay\Payout
84
  * @throws \Exception
85
  */
86
  public function getPayout($payoutId);
87
 
88
  /**
89
- * @param PayoutInterface
90
  * @return PayoutInterface|mixed
91
  * @throws \Exception
92
  */
@@ -99,6 +100,7 @@ interface ClientInterface
99
 
100
  /**
101
  * Get an array of tokens indexed by facade
 
102
  * @return array
103
  * @throws \Exception
104
  */
42
  public function getCurrencies();
43
 
44
  /**
45
+ * @param InvoiceInterface $invoiceId
46
  * @return \Bitpay\Invoice
47
  * @throws \Exception
48
  */
50
  //public function getInvoices();
51
 
52
  /**
53
+ * @param $invoiceId
54
  * @return InvoiceInterface
55
  * @throws \Exception
56
  */
65
 
66
  /**
67
  * Create a Payout Request on Bitpay
68
+ *
69
+ * @param PayoutInterface $payout
70
  * @return PayoutInterface|mixed
71
  * @throws \Exception
72
  */
73
  public function createPayout(PayoutInterface $payout);
74
 
75
  /**
76
+ * @param null $status
77
  * @return array
78
  * @throws \Exception
79
  */
80
  public function getPayouts($status = null);
81
 
82
  /**
83
+ * @param $payoutId
84
  * @return \Bitpay\Payout
85
  * @throws \Exception
86
  */
87
  public function getPayout($payoutId);
88
 
89
  /**
90
+ * @param PayoutInterface
91
  * @return PayoutInterface|mixed
92
  * @throws \Exception
93
  */
100
 
101
  /**
102
  * Get an array of tokens indexed by facade
103
+ *
104
  * @return array
105
  * @throws \Exception
106
  */
addons/buy-creds/gateways/Bitpay/Client/Response.php CHANGED
@@ -52,7 +52,7 @@ class Response implements ResponseInterface
52
  }
53
 
54
  /**
55
- * @param string $rawResponse
56
  * @return Response
57
  */
58
  public static function createFromRawResponse($rawResponse)
52
  }
53
 
54
  /**
55
+ * @param string $rawResponse
56
  * @return Response
57
  */
58
  public static function createFromRawResponse($rawResponse)
addons/buy-creds/gateways/Bitpay/Config/Configuration.php CHANGED
@@ -28,33 +28,33 @@ class Configuration implements ConfigurationInterface
28
  $rootNode = $treeBuilder->root('bitpay');
29
  $rootNode
30
  ->children()
31
- ->scalarNode('public_key')
32
- ->info('Public Key Filename')
33
- ->defaultValue(getenv('HOME').'/.bitpay/api.pub')
34
- ->end()
35
- ->scalarNode('private_key')
36
- ->info('Private Key Filename')
37
- ->defaultValue(getenv('HOME').'/.bitpay/api.key')
38
- ->end()
39
- ->scalarNode('sin_key')
40
- ->info('Private Key Filename')
41
- ->defaultValue(getenv('HOME').'/.bitpay/api.sin')
42
- ->end()
43
- ->enumNode('network')
44
- ->values(array('livenet', 'testnet'))
45
- ->info('Network')
46
- ->defaultValue('livenet')
47
- ->end()
48
- ->enumNode('adapter')
49
- ->values(array('curl', 'mock'))
50
- ->info('Client Adapter')
51
- ->defaultValue('curl')
52
- ->end()
53
- ->append($this->addKeyStorageNode())
54
- ->scalarNode('key_storage_password')
55
- ->info('Used to encrypt and decrypt keys when saving to filesystem')
56
- ->defaultNull()
57
- ->end()
58
  ->end();
59
 
60
  return $treeBuilder;
@@ -76,8 +76,9 @@ class Configuration implements ConfigurationInterface
76
  ->info('Class that is used to store your keys')
77
  ->defaultValue('Bitpay\Storage\EncryptedFilesystemStorage')
78
  ->validate()
79
- ->always()
80
- ->then(function ($value) {
 
81
  if (!class_exists($value)) {
82
  throw new \Exception(
83
  sprintf(
@@ -98,7 +99,8 @@ class Configuration implements ConfigurationInterface
98
  }
99
 
100
  return $value;
101
- })
 
102
  ->end();
103
 
104
  return $node;
28
  $rootNode = $treeBuilder->root('bitpay');
29
  $rootNode
30
  ->children()
31
+ ->scalarNode('public_key')
32
+ ->info('Public Key Filename')
33
+ ->defaultValue(getenv('HOME').'/.bitpay/api.pub')
34
+ ->end()
35
+ ->scalarNode('private_key')
36
+ ->info('Private Key Filename')
37
+ ->defaultValue(getenv('HOME').'/.bitpay/api.key')
38
+ ->end()
39
+ ->scalarNode('sin_key')
40
+ ->info('Private Key Filename')
41
+ ->defaultValue(getenv('HOME').'/.bitpay/api.sin')
42
+ ->end()
43
+ ->enumNode('network')
44
+ ->values(array('livenet', 'testnet'))
45
+ ->info('Network')
46
+ ->defaultValue('livenet')
47
+ ->end()
48
+ ->enumNode('adapter')
49
+ ->values(array('curl', 'mock'))
50
+ ->info('Client Adapter')
51
+ ->defaultValue('curl')
52
+ ->end()
53
+ ->append($this->addKeyStorageNode())
54
+ ->scalarNode('key_storage_password')
55
+ ->info('Used to encrypt and decrypt keys when saving to filesystem')
56
+ ->defaultNull()
57
+ ->end()
58
  ->end();
59
 
60
  return $treeBuilder;
76
  ->info('Class that is used to store your keys')
77
  ->defaultValue('Bitpay\Storage\EncryptedFilesystemStorage')
78
  ->validate()
79
+ ->always()
80
+ ->then(
81
+ function ($value) {
82
  if (!class_exists($value)) {
83
  throw new \Exception(
84
  sprintf(
99
  }
100
 
101
  return $value;
102
+ }
103
+ )
104
  ->end();
105
 
106
  return $node;
addons/buy-creds/gateways/Bitpay/Crypto/HashExtension.php CHANGED
@@ -36,7 +36,7 @@ class HashExtension implements CryptoInterface
36
  * Copy a hashing context.
37
  * (PHP 5 >= 5.3.0)
38
  *
39
- * @param resource
40
  * @return resource
41
  */
42
  final public function copy($context)
@@ -77,9 +77,9 @@ class HashExtension implements CryptoInterface
77
  * the message digest is returned.
78
  * (PHP 5 >= 5.1.2, PECL hash >= 1.1)
79
  *
80
- * @param string
81
- * @param string
82
- * @param bool
83
  * @return string
84
  */
85
  public function file($algorithm, $filename, $raw_output = false)
@@ -92,8 +92,8 @@ class HashExtension implements CryptoInterface
92
  * resulting digest.
93
  * (PHP 5 >= 5.1.2, PECL hash >= 1.1)
94
  *
95
- * @param resource
96
- * @param bool
97
  * @return string
98
  */
99
  public function finalize($context, $raw_output = false)
@@ -110,10 +110,10 @@ class HashExtension implements CryptoInterface
110
  * method and the contents of a given file.
111
  * (PHP 5 >= 5.1.2, PECL hash >= 1.1)
112
  *
113
- * @param string
114
- * @param string
115
- * @param string
116
- * @param bool
117
  * @return string
118
  */
119
  public function hmacFile($algorithm, $filename, $key, $raw_output = false)
@@ -126,10 +126,10 @@ class HashExtension implements CryptoInterface
126
  * method and the message passed via $data.
127
  * (PHP 5 >= 5.1.2, PECL hash >= 1.1)
128
  *
129
- * @param string
130
- * @param string
131
- * @param string
132
- * @param bool
133
  * @return string
134
  */
135
  public function hmac($algo, $data, $key, $raw_output = false)
@@ -146,9 +146,9 @@ class HashExtension implements CryptoInterface
146
  * this is specified, the key *must* be used as well.
147
  * (PHP 5 >= 5.1.2, PECL hash >= 1.1)
148
  *
149
- * @param string
150
- * @param int
151
- * @param string
152
  * @return resource
153
  */
154
  public function init($algorithm, $options = 0, $key = null)
@@ -166,12 +166,12 @@ class HashExtension implements CryptoInterface
166
  * randomly with openssl_ramdom_pseudo_bytes().
167
  * (PHP 5 >= 5.5.0)
168
  *
169
- * @param string
170
- * @param string
171
- * @param string
172
- * @param int
173
- * @param int
174
- * @param bool
175
  * @return string
176
  */
177
  public function pbkdf2($algo, $password, $salt, $iterations, $length = 0, $raw_output = false)
@@ -185,9 +185,9 @@ class HashExtension implements CryptoInterface
185
  * FALSE on failure.
186
  * (PHP 5 >= 5.1.2, PECL hash >= 1.1)
187
  *
188
- * @param resource
189
- * @param string
190
- * @param resource
191
  * @return bool
192
  */
193
  public function updateFile($hcontext, $filename, $scontext = null)
@@ -206,9 +206,9 @@ class HashExtension implements CryptoInterface
206
  * context from handle.
207
  * (PHP 5 >= 5.1.2, PECL hash >= 1.1)
208
  *
209
- * @param resource
210
- * @param resource
211
- * @param int
212
  * @return int
213
  */
214
  public function updateStream($context, $handle, $length = -1)
@@ -225,8 +225,8 @@ class HashExtension implements CryptoInterface
225
  * The PHP function itself only returns true.
226
  * (PHP 5 >= 5.1.2, PECL hash >= 1.1)
227
  *
228
- * @param resource
229
- * @param string
230
  * @return bool
231
  */
232
  public function update($context, $data)
@@ -245,9 +245,9 @@ class HashExtension implements CryptoInterface
245
  * $raw_output param is set to true.
246
  * (PHP 5 >= 5.1.2, PECL hash >= 1.1)
247
  *
248
- * @param string
249
- * @param string
250
- * @param bool
251
  * @return string
252
  */
253
  public function generate($algo, $data, $raw_output = false)
36
  * Copy a hashing context.
37
  * (PHP 5 >= 5.3.0)
38
  *
39
+ * @param resource
40
  * @return resource
41
  */
42
  final public function copy($context)
77
  * the message digest is returned.
78
  * (PHP 5 >= 5.1.2, PECL hash >= 1.1)
79
  *
80
+ * @param string
81
+ * @param string
82
+ * @param bool
83
  * @return string
84
  */
85
  public function file($algorithm, $filename, $raw_output = false)
92
  * resulting digest.
93
  * (PHP 5 >= 5.1.2, PECL hash >= 1.1)
94
  *
95
+ * @param resource
96
+ * @param bool
97
  * @return string
98
  */
99
  public function finalize($context, $raw_output = false)
110
  * method and the contents of a given file.
111
  * (PHP 5 >= 5.1.2, PECL hash >= 1.1)
112
  *
113
+ * @param string
114
+ * @param string
115
+ * @param string
116
+ * @param bool
117
  * @return string
118
  */
119
  public function hmacFile($algorithm, $filename, $key, $raw_output = false)
126
  * method and the message passed via $data.
127
  * (PHP 5 >= 5.1.2, PECL hash >= 1.1)
128
  *
129
+ * @param string
130
+ * @param string
131
+ * @param string
132
+ * @param bool
133
  * @return string
134
  */
135
  public function hmac($algo, $data, $key, $raw_output = false)
146
  * this is specified, the key *must* be used as well.
147
  * (PHP 5 >= 5.1.2, PECL hash >= 1.1)
148
  *
149
+ * @param string
150
+ * @param int
151
+ * @param string
152
  * @return resource
153
  */
154
  public function init($algorithm, $options = 0, $key = null)
166
  * randomly with openssl_ramdom_pseudo_bytes().
167
  * (PHP 5 >= 5.5.0)
168
  *
169
+ * @param string
170
+ * @param string
171
+ * @param string
172
+ * @param int
173
+ * @param int
174
+ * @param bool
175
  * @return string
176
  */
177
  public function pbkdf2($algo, $password, $salt, $iterations, $length = 0, $raw_output = false)
185
  * FALSE on failure.
186
  * (PHP 5 >= 5.1.2, PECL hash >= 1.1)
187
  *
188
+ * @param resource
189
+ * @param string
190
+ * @param resource
191
  * @return bool
192
  */
193
  public function updateFile($hcontext, $filename, $scontext = null)
206
  * context from handle.
207
  * (PHP 5 >= 5.1.2, PECL hash >= 1.1)
208
  *
209
+ * @param resource
210
+ * @param resource
211
+ * @param int
212
  * @return int
213
  */
214
  public function updateStream($context, $handle, $length = -1)
225
  * The PHP function itself only returns true.
226
  * (PHP 5 >= 5.1.2, PECL hash >= 1.1)
227
  *
228
+ * @param resource
229
+ * @param string
230
  * @return bool
231
  */
232
  public function update($context, $data)
245
  * $raw_output param is set to true.
246
  * (PHP 5 >= 5.1.2, PECL hash >= 1.1)
247
  *
248
+ * @param string
249
+ * @param string
250
+ * @param bool
251
  * @return string
252
  */
253
  public function generate($algo, $data, $raw_output = false)
addons/buy-creds/gateways/Bitpay/Crypto/McryptExtension.php CHANGED
@@ -35,7 +35,7 @@ class McryptExtension implements CryptoInterface
35
  * on failure. If no IV is needed for the cipher type and mode,
36
  * a zero is returned.
37
  *
38
- * @param string $cipher_type
39
  * @return int|bool
40
  */
41
  public function getIVSize($cipher_type = MCRYPT_TRIPLEDES)
@@ -73,7 +73,7 @@ class McryptExtension implements CryptoInterface
73
  * returns either boolean true/false depending on if the self-test passed
74
  * or failed.
75
  *
76
- * @param string $cipher_type
77
  * @return boolean
78
  */
79
  public function algoSelfTest($cipher_type = MCRYPT_TRIPLEDES)
@@ -82,20 +82,18 @@ class McryptExtension implements CryptoInterface
82
  }
83
 
84
  /**
85
- *
86
  * Encrypts $text based on your $key and $iv. The returned text is
87
  * base-64 encoded to make it easier to work with in various scenarios.
88
  * Default cipher is MCRYPT_TRIPLEDES but you can substitute depending
89
  * on your specific encryption needs.
90
  *
91
- * @param string $text
92
- * @param string $key
93
- * @param string $iv
94
- * @param int $bit_check
95
- * @param string $cipher_type
96
  * @return string $text
97
  * @throws Exception $e
98
- *
99
  */
100
  public function encrypt($text, $key = '', $iv = '', $bit_check = 8, $cipher_type = MCRYPT_TRIPLEDES)
101
  {
@@ -127,20 +125,18 @@ class McryptExtension implements CryptoInterface
127
  }
128
 
129
  /**
130
- *
131
  * Decrypts $text based on your $key and $iv. Make sure you use the same key
132
  * and initialization vector that you used when encrypting the $text. Default
133
  * cipher is MCRYPT_TRIPLEDES but you can substitute depending on the cipher
134
  * used for encrypting the text - very important.
135
  *
136
- * @param string $encrypted_text
137
- * @param string $key
138
- * @param string $iv
139
- * @param int $bit_check
140
- * @param string $cipher_type
141
  * @return string $text
142
  * @throws Exception $e
143
- *
144
  */
145
  public function decrypt($encrypted_text, $key = '', $iv = '', $bit_check = 8, $cipher_type = MCRYPT_TRIPLEDES)
146
  {
35
  * on failure. If no IV is needed for the cipher type and mode,
36
  * a zero is returned.
37
  *
38
+ * @param string $cipher_type
39
  * @return int|bool
40
  */
41
  public function getIVSize($cipher_type = MCRYPT_TRIPLEDES)
73
  * returns either boolean true/false depending on if the self-test passed
74
  * or failed.
75
  *
76
+ * @param string $cipher_type
77
  * @return boolean
78
  */
79
  public function algoSelfTest($cipher_type = MCRYPT_TRIPLEDES)
82
  }
83
 
84
  /**
 
85
  * Encrypts $text based on your $key and $iv. The returned text is
86
  * base-64 encoded to make it easier to work with in various scenarios.
87
  * Default cipher is MCRYPT_TRIPLEDES but you can substitute depending
88
  * on your specific encryption needs.
89
  *
90
+ * @param string $text
91
+ * @param string $key
92
+ * @param string $iv
93
+ * @param int $bit_check
94
+ * @param string $cipher_type
95
  * @return string $text
96
  * @throws Exception $e
 
97
  */
98
  public function encrypt($text, $key = '', $iv = '', $bit_check = 8, $cipher_type = MCRYPT_TRIPLEDES)
99
  {
125
  }
126
 
127
  /**
 
128
  * Decrypts $text based on your $key and $iv. Make sure you use the same key
129
  * and initialization vector that you used when encrypting the $text. Default
130
  * cipher is MCRYPT_TRIPLEDES but you can substitute depending on the cipher
131
  * used for encrypting the text - very important.
132
  *
133
+ * @param string $encrypted_text
134
+ * @param string $key
135
+ * @param string $iv
136
+ * @param int $bit_check
137
+ * @param string $cipher_type
138
  * @return string $text
139
  * @throws Exception $e
 
140
  */
141
  public function decrypt($encrypted_text, $key = '', $iv = '', $bit_check = 8, $cipher_type = MCRYPT_TRIPLEDES)
142
  {
addons/buy-creds/gateways/Bitpay/Crypto/OpenSSLExtension.php CHANGED
@@ -34,8 +34,8 @@ class OpenSSLExtension implements CryptoInterface
34
  * used for point derivation or for generating signatures.
35
  * Only used for assymetric data encryption, as needed.
36
  *
37
- * @param int
38
- * @param string
39
  * @return array|boolean array of keys on success, boolean false on failure
40
  */
41
  final public function generateKeypair($keybits = 512, $digest_alg = 'sha512')
@@ -113,7 +113,7 @@ class OpenSSLExtension implements CryptoInterface
113
  * Generates a high-quality random number suitable for
114
  * use in cryptographic functions and returns hex value.
115
  *
116
- * @param int
117
  * @return string|bool
118
  */
119
  final public function randomNumber($bytes = 32)
@@ -131,7 +131,7 @@ class OpenSSLExtension implements CryptoInterface
131
  * Returns the cipher length on success, or FALSE
132
  * on failure. (PHP 5 >= PHP 5.3.3)
133
  *
134
- * @param string
135
  * @return int|bool
136
  */
137
  final public function cypherIVLength($cypher = '')
@@ -145,9 +145,9 @@ class OpenSSLExtension implements CryptoInterface
145
  * the file named by $outfilename.
146
  * (PHP 4 >= 4.2.0, PHP 5)
147
  *
148
- * @param resource
149
- * @param string
150
- * @param bool
151
  * @return bool
152
  */
153
  final public function saveCSRtoFile($csr, $outfilename, $notext = true)
@@ -165,9 +165,9 @@ class OpenSSLExtension implements CryptoInterface
165
  * $out, which is passed by reference.
166
  * (PHP 4 >= 4.2.0, PHP 5)
167
  *
168
- * @param resource
169
- * @param string
170
- * @param bool
171
  * @return bool
172
  */
173
  final public function saveCSRtoString($csr, $out, $notext = true)
@@ -179,22 +179,21 @@ class OpenSSLExtension implements CryptoInterface
179
  return openssl_csr_export($csr, $out, $notext);
180
  }
181
  /**
182
- *
183
- * Encrypts $text based on your $key and $iv. The returned text is
184
- * base-64 encoded to make it easier to work with in various scenarios.
185
- * Default cipher is AES-256-CBC but you can substitute depending
186
- * on your specific encryption needs.
187
- *
188
- * @param string $text
189
- * @param string $key
190
- * @param string $iv
191
- * @param int $bit_check
192
- * @param string $cipher_type
193
- * @return string $text
194
- * @throws Exception $e
195
- *
196
- */
197
- public function encrypt($text, $key = '', $iv = '', $bit_check = 8, $cipher_type = 'AES-256-CBC') {
198
  try {
199
  if (function_exists('openssl_pkey_new')) {
200
  /* Ensure the key & IV is the same for both encrypt & decrypt. */
@@ -221,22 +220,21 @@ class OpenSSLExtension implements CryptoInterface
221
  }
222
 
223
  /**
224
- *
225
  * Decrypts $text based on your $key and $iv. Make sure you use the same key
226
  * and initialization vector that you used when encrypting the $text. Default
227
  * cipher is AES-256-CBC but you can substitute depending on the cipher
228
  * used for encrypting the text - very important.
229
  *
230
- * @param string $encrypted_text
231
- * @param string $key
232
- * @param string $iv
233
- * @param int $bit_check
234
- * @param string $cipher_type
235
  * @return string $text
236
  * @throws Exception $e
237
- *
238
  */
239
- public function decrypt($encrypted_text, $key = '', $iv = '', $bit_check = 8, $cipher_type = 'AES-256-CBC') {
 
240
  try {
241
  /* Ensure the key & IV is the same for both encrypt & decrypt. */
242
  if (!empty($encrypted_text)) {
34
  * used for point derivation or for generating signatures.
35
  * Only used for assymetric data encryption, as needed.
36
  *
37
+ * @param int
38
+ * @param string
39
  * @return array|boolean array of keys on success, boolean false on failure
40
  */
41
  final public function generateKeypair($keybits = 512, $digest_alg = 'sha512')
113
  * Generates a high-quality random number suitable for
114
  * use in cryptographic functions and returns hex value.
115
  *
116
+ * @param int
117
  * @return string|bool
118
  */
119
  final public function randomNumber($bytes = 32)
131
  * Returns the cipher length on success, or FALSE
132
  * on failure. (PHP 5 >= PHP 5.3.3)
133
  *
134
+ * @param string
135
  * @return int|bool
136
  */
137
  final public function cypherIVLength($cypher = '')
145
  * the file named by $outfilename.
146
  * (PHP 4 >= 4.2.0, PHP 5)
147
  *
148
+ * @param resource
149
+ * @param string
150
+ * @param bool
151
  * @return bool
152
  */
153
  final public function saveCSRtoFile($csr, $outfilename, $notext = true)
165
  * $out, which is passed by reference.
166
  * (PHP 4 >= 4.2.0, PHP 5)
167
  *
168
+ * @param resource
169
+ * @param string
170
+ * @param bool
171
  * @return bool
172
  */
173
  final public function saveCSRtoString($csr, $out, $notext = true)
179
  return openssl_csr_export($csr, $out, $notext);
180
  }
181
  /**
182
+ * Encrypts $text based on your $key and $iv. The returned text is
183
+ * base-64 encoded to make it easier to work with in various scenarios.
184
+ * Default cipher is AES-256-CBC but you can substitute depending
185
+ * on your specific encryption needs.
186
+ *
187
+ * @param string $text
188
+ * @param string $key
189
+ * @param string $iv
190
+ * @param int $bit_check
191
+ * @param string $cipher_type
192
+ * @return string $text
193
+ * @throws Exception $e
194
+ */
195
+ public function encrypt($text, $key = '', $iv = '', $bit_check = 8, $cipher_type = 'AES-256-CBC')
196
+ {
 
197
  try {
198
  if (function_exists('openssl_pkey_new')) {
199
  /* Ensure the key & IV is the same for both encrypt & decrypt. */
220
  }
221
 
222
  /**
 
223
  * Decrypts $text based on your $key and $iv. Make sure you use the same key
224
  * and initialization vector that you used when encrypting the $text. Default
225
  * cipher is AES-256-CBC but you can substitute depending on the cipher
226
  * used for encrypting the text - very important.
227
  *
228
+ * @param string $encrypted_text
229
+ * @param string $key
230
+ * @param string $iv
231
+ * @param int $bit_check
232
+ * @param string $cipher_type
233
  * @return string $text
234
  * @throws Exception $e
 
235
  */
236
+ public function decrypt($encrypted_text, $key = '', $iv = '', $bit_check = 8, $cipher_type = 'AES-256-CBC')
237
+ {
238
  try {
239
  /* Ensure the key & IV is the same for both encrypt & decrypt. */
240
  if (!empty($encrypted_text)) {
addons/buy-creds/gateways/Bitpay/Currency.php CHANGED
@@ -11,7 +11,7 @@ use Bitpay\Client;
11
  /**
12
  * For the most part this should conform to ISO 4217
13
  *
14
- * @see http://en.wikipedia.org/wiki/ISO_4217
15
  * @package Bitpay
16
  */
17
  class Currency implements CurrencyInterface
@@ -86,7 +86,7 @@ class Currency implements CurrencyInterface
86
  protected $payoutFields;
87
 
88
  /**
89
- * @param string $code The Currency Code to use, ie USD
90
  * @throws Exception Throws an exception if the Currency Code is not supported
91
  */
92
  public function __construct($code = null)
@@ -110,7 +110,7 @@ class Currency implements CurrencyInterface
110
  /**
111
  * This will change the $code to all uppercase
112
  *
113
- * @param string $code The Currency Code to use, ie USD
114
  * @throws Exception Throws an exception if the Currency Code is not supported
115
  * @return CurrencyInterface
116
  */
11
  /**
12
  * For the most part this should conform to ISO 4217
13
  *
14
+ * @see http://en.wikipedia.org/wiki/ISO_4217
15
  * @package Bitpay
16
  */
17
  class Currency implements CurrencyInterface
86
  protected $payoutFields;
87
 
88
  /**
89
+ * @param string $code The Currency Code to use, ie USD
90
  * @throws Exception Throws an exception if the Currency Code is not supported
91
  */
92
  public function __construct($code = null)
110
  /**
111
  * This will change the $code to all uppercase
112
  *
113
+ * @param string $code The Currency Code to use, ie USD
114
  * @throws Exception Throws an exception if the Currency Code is not supported
115
  * @return CurrencyInterface
116
  */
addons/buy-creds/gateways/Bitpay/DependencyInjection/Loader/ArrayLoader.php CHANGED
@@ -40,12 +40,14 @@ class ArrayLoader extends Loader
40
  $this->container->getExtensions()
41
  )
42
  );
43
- throw new InvalidArgumentException(sprintf(
44
- 'There is no extension able to load the configuration for "%s". Looked for namespace "%s", found %s',
45
- $namespace,
46
- $namespace,
47
- $extensionNamespaces ? sprintf('"%s"', implode('", "', $extensionNamespaces)) : 'none'
48
- ));
 
 
49
  }
50
  }
51
 
40
  $this->container->getExtensions()
41
  )
42
  );
43
+ throw new InvalidArgumentException(
44
+ sprintf(
45
+ 'There is no extension able to load the configuration for "%s". Looked for namespace "%s", found %s',
46
+ $namespace,
47
+ $namespace,
48
+ $extensionNamespaces ? sprintf('"%s"', implode('", "', $extensionNamespaces)) : 'none'
49
+ )
50
+ );
51
  }
52
  }
53
 
addons/buy-creds/gateways/Bitpay/Invoice.php CHANGED
@@ -666,7 +666,7 @@ class Invoice implements InvoiceInterface
666
  }
667
 
668
  /**
669
- * @param void
670
  * @return
671
  */
672
  public function getBtcPaid()
@@ -688,7 +688,7 @@ class Invoice implements InvoiceInterface
688
  }
689
 
690
  /**
691
- * @param void
692
  * @return Invoice
693
  */
694
  public function getRate()
@@ -717,7 +717,7 @@ class Invoice implements InvoiceInterface
717
  return $this->token;
718
  }
719
  /**
720
- * @param TokenInterface $token
721
  * @return InvoiceInterface
722
  */
723
  public function setToken(TokenInterface $token)
666
  }
667
 
668
  /**
669
+ * @param void
670
  * @return
671
  */
672
  public function getBtcPaid()
688
  }
689
 
690
  /**
691
+ * @param void
692
  * @return Invoice
693
  */
694
  public function getRate()
717
  return $this->token;
718
  }
719
  /**
720
+ * @param TokenInterface $token
721
  * @return InvoiceInterface
722
  */
723
  public function setToken(TokenInterface $token)
addons/buy-creds/gateways/Bitpay/InvoiceInterface.php CHANGED
@@ -246,7 +246,7 @@ interface InvoiceInterface
246
  * characters.
247
  *
248
  * @deprecated
249
- * @return string
250
  */
251
  public function getItemDesc();
252
 
@@ -255,7 +255,7 @@ interface InvoiceInterface
255
  * length is 100 characters.
256
  *
257
  * @deprecated
258
- * @return string
259
  */
260
  public function getItemCode();
261
 
@@ -265,7 +265,7 @@ interface InvoiceInterface
265
  * ● false: Indicates that nothing is to be shipped for this order
266
  *
267
  * @deprecated
268
- * @return boolean
269
  */
270
  public function isPhysical();
271
 
@@ -274,7 +274,7 @@ interface InvoiceInterface
274
  * if provided. Maximum string length of each field is 100 characters.
275
  *
276
  * @deprecated
277
- * @return string
278
  */
279
  public function getBuyerName();
280
 
@@ -283,7 +283,7 @@ interface InvoiceInterface
283
  * if provided. Maximum string length of each field is 100 characters.
284
  *
285
  * @deprecated
286
- * @return string
287
  */
288
  public function getBuyerAddress1();
289
 
@@ -292,7 +292,7 @@ interface InvoiceInterface
292
  * if provided. Maximum string length of each field is 100 characters.
293
  *
294
  * @deprecated
295
- * @return string
296
  */
297
  public function getBuyerAddress2();
298
 
@@ -301,7 +301,7 @@ interface InvoiceInterface
301
  * if provided. Maximum string length of each field is 100 characters.
302
  *
303
  * @deprecated
304
- * @return string
305
  */
306
  public function getBuyerCity();
307
 
@@ -310,7 +310,7 @@ interface InvoiceInterface
310
  * if provided. Maximum string length of each field is 100 characters.
311
  *
312
  * @deprecated
313
- * @return string
314
  */
315
  public function getBuyerState();
316
 
@@ -319,7 +319,7 @@ interface InvoiceInterface
319
  * if provided. Maximum string length of each field is 100 characters.
320
  *
321
  * @deprecated
322
- * @return string
323
  */
324
  public function getBuyerZip();
325
 
@@ -328,7 +328,7 @@ interface InvoiceInterface
328
  * if provided. Maximum string length of each field is 100 characters.
329
  *
330
  * @deprecated
331
- * @return string
332
  */
333
  public function getBuyerCountry();
334
 
@@ -337,7 +337,7 @@ interface InvoiceInterface
337
  * if provided. Maximum string length of each field is 100 characters.
338
  *
339
  * @deprecated
340
- * @return string
341
  */
342
  public function getBuyerEmail();
343
 
@@ -346,7 +346,7 @@ interface InvoiceInterface
346
  * if provided. Maximum string length of each field is 100 characters.
347
  *
348
  * @deprecated
349
- * @return string
350
  */
351
  public function getBuyerPhone();
352
 
246
  * characters.
247
  *
248
  * @deprecated
249
+ * @return string
250
  */
251
  public function getItemDesc();
252
 
255
  * length is 100 characters.
256
  *
257
  * @deprecated
258
+ * @return string
259
  */
260
  public function getItemCode();
261
 
265
  * ● false: Indicates that nothing is to be shipped for this order
266
  *
267
  * @deprecated
268
+ * @return boolean
269
  */
270
  public function isPhysical();
271
 
274
  * if provided. Maximum string length of each field is 100 characters.
275
  *
276
  * @deprecated
277
+ * @return string
278
  */
279
  public function getBuyerName();
280
 
283
  * if provided. Maximum string length of each field is 100 characters.
284
  *
285
  * @deprecated
286
+ * @return string
287
  */
288
  public function getBuyerAddress1();
289
 
292
  * if provided. Maximum string length of each field is 100 characters.
293
  *
294
  * @deprecated
295
+ * @return string
296
  */
297
  public function getBuyerAddress2();
298
 
301
  * if provided. Maximum string length of each field is 100 characters.
302
  *
303
  * @deprecated
304
+ * @return string
305
  */
306
  public function getBuyerCity();
307
 
310
  * if provided. Maximum string length of each field is 100 characters.
311
  *
312
  * @deprecated
313
+ * @return string
314
  */
315
  public function getBuyerState();
316
 
319
  * if provided. Maximum string length of each field is 100 characters.
320
  *
321
  * @deprecated
322
+ * @return string
323
  */
324
  public function getBuyerZip();
325
 
328
  * if provided. Maximum string length of each field is 100 characters.
329
  *
330
  * @deprecated
331
+ * @return string
332
  */
333
  public function getBuyerCountry();
334
 
337
  * if provided. Maximum string length of each field is 100 characters.
338
  *
339
  * @deprecated
340
+ * @return string
341
  */
342
  public function getBuyerEmail();
343
 
346
  * if provided. Maximum string length of each field is 100 characters.
347
  *
348
  * @deprecated
349
+ * @return string
350
  */
351
  public function getBuyerPhone();
352
 
addons/buy-creds/gateways/Bitpay/Item.php CHANGED
@@ -156,7 +156,7 @@ class Item implements ItemInterface
156
  * Checks the new price to include BTC
157
  * values with more than 6 decimals.
158
  *
159
- * @param string $price The price value to check
160
  * @throws \Exception
161
  */
162
  protected function checkPriceFormat($price)
156
  * Checks the new price to include BTC
157
  * values with more than 6 decimals.
158
  *
159
+ * @param string $price The price value to check
160
  * @throws \Exception
161
  */
162
  protected function checkPriceFormat($price)
addons/buy-creds/gateways/Bitpay/Key.php CHANGED
@@ -47,7 +47,7 @@ abstract class Key extends Point implements KeyInterface
47
  /**
48
  * Returns a new instance of self.
49
  *
50
- * @param string $id
51
  * @return \Bitpay\KeyInterface
52
  */
53
  public static function create($id = null)
47
  /**
48
  * Returns a new instance of self.
49
  *
50
+ * @param string $id
51
  * @return \Bitpay\KeyInterface
52
  */
53
  public static function create($id = null)
addons/buy-creds/gateways/Bitpay/Math/BcEngine.php CHANGED
@@ -58,8 +58,8 @@ class BcEngine implements EngineInterface
58
  * Finds inverse number $inv for $num by modulus $mod, such as:
59
  * $inv * $num = 1 (mod $mod)
60
  *
61
- * @param string $num
62
- * @param string $mod
63
  * @return string
64
  * @access public
65
  */
58
  * Finds inverse number $inv for $num by modulus $mod, such as:
59
  * $inv * $num = 1 (mod $mod)
60
  *
61
+ * @param string $num
62
+ * @param string $mod
63
  * @return string
64
  * @access public
65
  */
addons/buy-creds/gateways/Bitpay/Payout.php CHANGED
@@ -8,6 +8,7 @@ namespace Bitpay;
8
 
9
  /**
10
  * Class Payout
 
11
  * @package Bitpay
12
  */
13
  class Payout implements PayoutInterface
@@ -102,7 +103,7 @@ class Payout implements PayoutInterface
102
  /**
103
  * Set the batch ID as assigned from bitpay.
104
  *
105
- * @param $id
106
  * @return $this
107
  */
108
  public function setId($id)
@@ -125,7 +126,7 @@ class Payout implements PayoutInterface
125
  /**
126
  * Set Account Id - Bitpays account ID for the payout.
127
  *
128
- * @param $id
129
  * @return $this
130
  */
131
  public function setAccountId($id)
@@ -147,7 +148,8 @@ class Payout implements PayoutInterface
147
 
148
  /**
149
  * Sets the amount for this payout.
150
- * @param $amount
 
151
  * @return $this
152
  */
153
  public function setAmount($amount)
@@ -169,7 +171,8 @@ class Payout implements PayoutInterface
169
 
170
  /**
171
  * Set Currency
172
- * @param CurrencyInterface $currency
 
173
  * @return $this
174
  */
175
  public function setCurrency(CurrencyInterface $currency)
@@ -191,7 +194,8 @@ class Payout implements PayoutInterface
191
 
192
  /**
193
  * Set Effective date - date payout should be given to employees.
194
- * @param $effectiveDate
 
195
  * @return $this
196
  */
197
  public function setEffectiveDate($effectiveDate)
@@ -213,7 +217,8 @@ class Payout implements PayoutInterface
213
 
214
  /**
215
  * Set the rate in bitcoin for the payouts of this transaction.
216
- * @param $rate
 
217
  * @return $this
218
  */
219
  public function setRate($rate)
@@ -235,7 +240,8 @@ class Payout implements PayoutInterface
235
 
236
  /**
237
  * Set the Bitcoin amount for this payout, once set by Bitpay.
238
- * @param $amount
 
239
  * @return $this
240
  */
241
  public function setBtcAmount($amount)
@@ -278,7 +284,7 @@ class Payout implements PayoutInterface
278
  * Add Instruction of PayoutInstructionInterface type
279
  * Increases $this->amount by value.
280
  *
281
- * @param PayoutInstructionInterface $instruction
282
  * @return $this
283
  */
284
  public function addInstruction(PayoutInstructionInterface $instruction)
@@ -294,9 +300,9 @@ class Payout implements PayoutInterface
294
  * Update Instruction - Supply an index of the instruction to update,
295
  * plus the function and single argument, to do something to an instruction.
296
  *
297
- * @param $index
298
- * @param $function
299
- * @param $argument
300
  * @return $this
301
  */
302
  public function updateInstruction($index, $function, $argument)
@@ -318,7 +324,8 @@ class Payout implements PayoutInterface
318
 
319
  /**
320
  * Sets the status for the current payout request
321
- * @param $status
 
322
  * @return $this
323
  */
324
  public function setStatus($status)
@@ -340,7 +347,8 @@ class Payout implements PayoutInterface
340
 
341
  /**
342
  * Set the token to authorize this request.
343
- * @param TokenInterface $token
 
344
  * @return $this
345
  */
346
  public function setToken(TokenInterface $token)
@@ -362,7 +370,7 @@ class Payout implements PayoutInterface
362
  /**
363
  * Set Response Token - returned by Bitpay when payout request is created
364
  *
365
- * @param $responseToken
366
  * @return $this
367
  */
368
  public function setResponseToken($responseToken)
@@ -383,7 +391,8 @@ class Payout implements PayoutInterface
383
 
384
  /**
385
  * Set the pricing method for this payout request
386
- * @param $pricingMethod
 
387
  * @return $this
388
  */
389
  public function setPricingMethod($pricingMethod)
@@ -406,7 +415,7 @@ class Payout implements PayoutInterface
406
  /**
407
  * Set the payroll providers reference for this payout
408
  *
409
- * @param $reference
410
  * @return $this
411
  */
412
  public function setReference($reference)
@@ -429,7 +438,7 @@ class Payout implements PayoutInterface
429
  /**
430
  * Set an email address where updates to payout status should be sent.
431
  *
432
- * @param $notificationEmail
433
  * @return $this
434
  */
435
  public function setNotificationEmail($notificationEmail)
@@ -452,7 +461,7 @@ class Payout implements PayoutInterface
452
  /**
453
  * Set a notification url - where updated Payout objects will be sent
454
  *
455
- * @param $notificationUrl
456
  * @return $this
457
  */
458
  public function setNotificationUrl($notificationUrl)
8
 
9
  /**
10
  * Class Payout
11
+ *
12
  * @package Bitpay
13
  */
14
  class Payout implements PayoutInterface
103
  /**
104
  * Set the batch ID as assigned from bitpay.
105
  *
106
+ * @param $id
107
  * @return $this
108
  */
109
  public function setId($id)
126
  /**
127
  * Set Account Id - Bitpays account ID for the payout.
128
  *
129
+ * @param $id
130
  * @return $this
131
  */
132
  public function setAccountId($id)
148
 
149
  /**
150
  * Sets the amount for this payout.
151
+ *
152
+ * @param $amount
153
  * @return $this
154
  */
155
  public function setAmount($amount)
171
 
172
  /**
173
  * Set Currency
174
+ *
175
+ * @param CurrencyInterface $currency
176
  * @return $this
177
  */
178
  public function setCurrency(CurrencyInterface $currency)
194
 
195
  /**
196
  * Set Effective date - date payout should be given to employees.
197
+ *
198
+ * @param $effectiveDate
199
  * @return $this
200
  */
201
  public function setEffectiveDate($effectiveDate)
217
 
218
  /**
219
  * Set the rate in bitcoin for the payouts of this transaction.
220
+ *
221
+ * @param $rate
222
  * @return $this
223
  */
224
  public function setRate($rate)
240
 
241
  /**
242
  * Set the Bitcoin amount for this payout, once set by Bitpay.
243
+ *
244
+ * @param $amount
245
  * @return $this
246
  */
247
  public function setBtcAmount($amount)
284
  * Add Instruction of PayoutInstructionInterface type
285
  * Increases $this->amount by value.
286
  *
287
+ * @param PayoutInstructionInterface $instruction
288
  * @return $this
289
  */
290
  public function addInstruction(PayoutInstructionInterface $instruction)
300
  * Update Instruction - Supply an index of the instruction to update,
301
  * plus the function and single argument, to do something to an instruction.
302
  *
303
+ * @param $index
304
+ * @param $function
305
+ * @param $argument
306
  * @return $this
307
  */
308
  public function updateInstruction($index, $function, $argument)
324
 
325
  /**
326
  * Sets the status for the current payout request
327
+ *
328
+ * @param $status
329
  * @return $this
330
  */
331
  public function setStatus($status)
347
 
348
  /**
349
  * Set the token to authorize this request.
350
+ *
351
+ * @param TokenInterface $token
352
  * @return $this
353
  */
354
  public function setToken(TokenInterface $token)
370
  /**
371
  * Set Response Token - returned by Bitpay when payout request is created
372
  *
373
+ * @param $responseToken
374
  * @return $this
375
  */
376
  public function setResponseToken($responseToken)
391
 
392
  /**
393
  * Set the pricing method for this payout request
394
+ *
395
+ * @param $pricingMethod
396
  * @return $this
397
  */
398
  public function setPricingMethod($pricingMethod)
415
  /**
416
  * Set the payroll providers reference for this payout
417
  *
418
+ * @param $reference
419
  * @return $this
420
  */
421
  public function setReference($reference)
438
  /**
439
  * Set an email address where updates to payout status should be sent.
440
  *
441
+ * @param $notificationEmail
442
  * @return $this
443
  */
444
  public function setNotificationEmail($notificationEmail)
461
  /**
462
  * Set a notification url - where updated Payout objects will be sent
463
  *
464
+ * @param $notificationUrl
465
  * @return $this
466
  */
467
  public function setNotificationUrl($notificationUrl)
addons/buy-creds/gateways/Bitpay/PayoutInstruction.php CHANGED
@@ -8,6 +8,7 @@ namespace Bitpay;
8
 
9
  /**
10
  * Class PayoutInstruction
 
11
  * @package Bitpay
12
  */
13
  class PayoutInstruction implements PayoutInstructionInterface
@@ -74,7 +75,7 @@ class PayoutInstruction implements PayoutInstructionInterface
74
  /**
75
  * Set the Bitpay ID for this payout instruction
76
  *
77
- * @param $id
78
  * @return $this
79
  */
80
  public function setId($id)
@@ -95,7 +96,8 @@ class PayoutInstruction implements PayoutInstructionInterface
95
 
96
  /**
97
  * Set the employers label for this instruction.
98
- * @param $label
 
99
  * @return $this
100
  */
101
  public function setLabel($label)
@@ -117,7 +119,8 @@ class PayoutInstruction implements PayoutInstructionInterface
117
 
118
  /**
119
  * Set the bitcoin address for this instruction.
120
- * @param $address
 
121
  * @return $this
122
  */
123
  public function setAddress($address)
@@ -139,7 +142,8 @@ class PayoutInstruction implements PayoutInstructionInterface
139
 
140
  /**
141
  * Set the amount for this instruction.
142
- * @param $amount
 
143
  * @return $this
144
  */
145
  public function setAmount($amount)
@@ -161,7 +165,8 @@ class PayoutInstruction implements PayoutInstructionInterface
161
 
162
  /**
163
  * Set BTC array (available once rates are set)
164
- * @param $btc
 
165
  * @return $this
166
  */
167
  public function setBtc($btc)
@@ -183,7 +188,8 @@ class PayoutInstruction implements PayoutInstructionInterface
183
 
184
  /**
185
  * Set the status for this instruction
186
- * @param $status
 
187
  * @return $this
188
  */
189
  public function setStatus($status)
@@ -205,7 +211,8 @@ class PayoutInstruction implements PayoutInstructionInterface
205
 
206
  /**
207
  * Add payout transaction to the
208
- * @param PayoutTransactionInterface $transaction
 
209
  * @return $this
210
  */
211
  public function addTransaction(PayoutTransactionInterface $transaction)
8
 
9
  /**
10
  * Class PayoutInstruction
11
+ *
12
  * @package Bitpay
13
  */
14
  class PayoutInstruction implements PayoutInstructionInterface
75
  /**
76
  * Set the Bitpay ID for this payout instruction
77
  *
78
+ * @param $id
79
  * @return $this
80
  */
81
  public function setId($id)
96
 
97
  /**
98
  * Set the employers label for this instruction.
99
+ *
100
+ * @param $label
101
  * @return $this
102
  */
103
  public function setLabel($label)
119
 
120
  /**
121
  * Set the bitcoin address for this instruction.
122
+ *
123
+ * @param $address
124
  * @return $this
125
  */
126
  public function setAddress($address)
142
 
143
  /**
144
  * Set the amount for this instruction.
145
+ *
146
+ * @param $amount
147
  * @return $this
148
  */
149
  public function setAmount($amount)
165
 
166
  /**
167
  * Set BTC array (available once rates are set)
168
+ *
169
+ * @param $btc
170
  * @return $this
171
  */
172
  public function setBtc($btc)
188
 
189
  /**
190
  * Set the status for this instruction
191
+ *
192
+ * @param $status
193
  * @return $this
194
  */
195
  public function setStatus($status)
211
 
212
  /**
213
  * Add payout transaction to the
214
+ *
215
+ * @param PayoutTransactionInterface $transaction
216
  * @return $this
217
  */
218
  public function addTransaction(PayoutTransactionInterface $transaction)
addons/buy-creds/gateways/Bitpay/PayoutInstructionInterface.php CHANGED
@@ -8,6 +8,7 @@ namespace Bitpay;
8
 
9
  /**
10
  * Interface PayoutInstructionInterface
 
11
  * @package Bitpay
12
  */
13
  interface PayoutInstructionInterface
@@ -15,42 +16,49 @@ interface PayoutInstructionInterface
15
 
16
  /**
17
  * Get Bitpay ID for this instruction.
 
18
  * @return string
19
  */
20
  public function getId();
21
 
22
  /**
23
  * Get Label for instruction payout.
 
24
  * @return string
25
  */
26
  public function getLabel();
27
 
28
  /**
29
  * Get the bitcoin address for the recipient.
 
30
  * @return string
31
  */
32
  public function getAddress();
33
 
34
  /**
35
  * Return the amount to pay the recipient.
 
36
  * @return string
37
  */
38
  public function getAmount();
39
 
40
  /**
41
  * Get the BTC array (once rates are set)
 
42
  * @return array
43
  */
44
  public function getBtc();
45
 
46
  /**
47
  * Return the status of this payout instruction
 
48
  * @return string
49
  */
50
  public function getStatus();
51
 
52
  /**
53
  * Return the transactions for this payout
 
54
  * @return array
55
  */
56
  public function getTransactions();
8
 
9
  /**
10
  * Interface PayoutInstructionInterface
11
+ *
12
  * @package Bitpay
13
  */
14
  interface PayoutInstructionInterface
16
 
17
  /**
18
  * Get Bitpay ID for this instruction.
19
+ *
20
  * @return string
21
  */
22
  public function getId();
23
 
24
  /**
25
  * Get Label for instruction payout.
26
+ *
27
  * @return string
28
  */
29
  public function getLabel();
30
 
31
  /**
32
  * Get the bitcoin address for the recipient.
33
+ *
34
  * @return string
35
  */
36
  public function getAddress();
37
 
38
  /**
39
  * Return the amount to pay the recipient.
40
+ *
41
  * @return string
42
  */
43
  public function getAmount();
44
 
45
  /**
46
  * Get the BTC array (once rates are set)
47
+ *
48
  * @return array
49
  */
50
  public function getBtc();
51
 
52
  /**
53
  * Return the status of this payout instruction
54
+ *
55
  * @return string
56
  */
57
  public function getStatus();
58
 
59
  /**
60
  * Return the transactions for this payout
61
+ *
62
  * @return array
63
  */
64
  public function getTransactions();
addons/buy-creds/gateways/Bitpay/PayoutInterface.php CHANGED
@@ -8,6 +8,7 @@ namespace Bitpay;
8
 
9
  /**
10
  * Interface PayoutInterface
 
11
  * @package Bitpay
12
  */
13
  interface PayoutInterface
8
 
9
  /**
10
  * Interface PayoutInterface
11
+ *
12
  * @package Bitpay
13
  */
14
  interface PayoutInterface
addons/buy-creds/gateways/Bitpay/PayoutTransaction.php CHANGED
@@ -8,6 +8,7 @@ namespace Bitpay;
8
 
9
  /**
10
  * Class PayoutTransaction
 
11
  * @package Bitpay
12
  */
13
  class PayoutTransaction implements PayoutTransactionInterface
@@ -37,7 +38,8 @@ class PayoutTransaction implements PayoutTransactionInterface
37
 
38
  /**
39
  * Set transaction ID for payout.
40
- * @param $txid
 
41
  * @return $this
42
  */
43
  public function setTransactionId($txid)
@@ -59,7 +61,8 @@ class PayoutTransaction implements PayoutTransactionInterface
59
 
60
  /**
61
  * Set the amount of bitcoin paid in the paout.
62
- * @param $amount
 
63
  * @return $this
64
  */
65
  public function setAmount($amount)
@@ -81,7 +84,8 @@ class PayoutTransaction implements PayoutTransactionInterface
81
 
82
  /**
83
  * Set the date and time of when the payment was sent.
84
- * @param $date
 
85
  * @return $this
86
  */
87
  public function setDate($date)
8
 
9
  /**
10
  * Class PayoutTransaction
11
+ *
12
  * @package Bitpay
13
  */
14
  class PayoutTransaction implements PayoutTransactionInterface
38
 
39
  /**
40
  * Set transaction ID for payout.
41
+ *
42
+ * @param $txid
43
  * @return $this
44
  */
45
  public function setTransactionId($txid)
61
 
62
  /**
63
  * Set the amount of bitcoin paid in the paout.
64
+ *
65
+ * @param $amount
66
  * @return $this
67
  */
68
  public function setAmount($amount)
84
 
85
  /**
86
  * Set the date and time of when the payment was sent.
87
+ *
88
+ * @param $date
89
  * @return $this
90
  */
91
  public function setDate($date)
addons/buy-creds/gateways/Bitpay/PayoutTransactionInterface.php CHANGED
@@ -8,24 +8,28 @@ namespace Bitpay;
8
 
9
  /**
10
  * Class PayoutTransaction
 
11
  * @package Bitpay
12
  */
13
  interface PayoutTransactionInterface
14
  {
15
  /**
16
  * Get bitcoin blockchain transaction ID for the payout transaction.
 
17
  * @return mixed
18
  */
19
  public function getTransactionID();
20
 
21
  /**
22
  * The amount of bitcoin paid.
 
23
  * @return float
24
  */
25
  public function getAmount();
26
 
27
  /**
28
  * The date and time when the payment was sent.
 
29
  * @return string
30
  */
31
  public function getDate();
8
 
9
  /**
10
  * Class PayoutTransaction
11
+ *
12
  * @package Bitpay
13
  */
14
  interface PayoutTransactionInterface
15
  {
16
  /**
17
  * Get bitcoin blockchain transaction ID for the payout transaction.
18
+ *
19
  * @return mixed
20
  */
21
  public function getTransactionID();
22
 
23
  /**
24
  * The amount of bitcoin paid.
25
+ *
26
  * @return float
27
  */
28
  public function getAmount();
29
 
30
  /**
31
  * The date and time when the payment was sent.
32
+ *
33
  * @return string
34
  */
35
  public function getDate();
addons/buy-creds/gateways/Bitpay/PrivateKey.php CHANGED
@@ -13,7 +13,7 @@ use Bitpay\Math\Math;
13
 
14
  /**
15
  * @package Bitcore
16
- * @see https://en.bitcoin.it/wiki/List_of_address_prefixes
17
  */
18
  class PrivateKey extends Key
19
  {
@@ -191,8 +191,8 @@ class PrivateKey extends Key
191
  * 0x30 + size(all) + 0x02 + size(r) + r + 0x02 + size(s) + s
192
  * http://www.itu.int/ITU-T/studygroups/com17/languages/X.690-0207.pdf
193
  *
194
- * @param string
195
- * @param string
196
  * @return string
197
  */
198
  public static function serializeSig($r, $s)
@@ -304,7 +304,7 @@ class PrivateKey extends Key
304
  /**
305
  * Encodes keypair data to PEM format.
306
  *
307
- * @param array $keypair The keypair info.
308
  * @return string The data to decode.
309
  */
310
  public function pemEncode($keypair)
13
 
14
  /**
15
  * @package Bitcore
16
+ * @see https://en.bitcoin.it/wiki/List_of_address_prefixes
17
  */
18
  class PrivateKey extends Key
19
  {
191
  * 0x30 + size(all) + 0x02 + size(r) + r + 0x02 + size(s) + s
192
  * http://www.itu.int/ITU-T/studygroups/com17/languages/X.690-0207.pdf
193
  *
194
+ * @param string
195
+ * @param string
196
  * @return string
197
  */
198
  public static function serializeSig($r, $s)
304
  /**
305
  * Encodes keypair data to PEM format.
306
  *
307
+ * @param array $keypair The keypair info.
308
  * @return string The data to decode.
309
  */
310
  public function pemEncode($keypair)
addons/buy-creds/gateways/Bitpay/SinKey.php CHANGED
@@ -41,7 +41,7 @@ class SinKey extends Key
41
  }
42
 
43
  /**
44
- * @param PublicKey
45
  * @return SinKey
46
  */
47
  public function setPublicKey(PublicKey $publicKey)
41
  }
42
 
43
  /**
44
+ * @param PublicKey
45
  * @return SinKey
46
  */
47
  public function setPublicKey(PublicKey $publicKey)
addons/buy-creds/gateways/Bitpay/Storage/EncryptedFilesystemStorage.php CHANGED
@@ -53,13 +53,15 @@ class EncryptedFilesystemStorage implements StorageInterface
53
  {
54
  $path = $key->getId();
55
  $data = serialize($key);
56
- $encoded = bin2hex(openssl_encrypt(
57
- $data,
58
- self::METHOD,
59
- $this->password,
60
- 1,
61
- self::IV
62
- ));
 
 
63
 
64
  file_put_contents($path, $encoded);
65
  }
53
  {
54
  $path = $key->getId();
55
  $data = serialize($key);
56
+ $encoded = bin2hex(
57
+ openssl_encrypt(
58
+ $data,
59
+ self::METHOD,
60
+ $this->password,
61
+ 1,
62
+ self::IV
63
+ )
64
+ );
65
 
66
  file_put_contents($path, $encoded);
67
  }
addons/buy-creds/gateways/Bitpay/Storage/MockStorage.php CHANGED
@@ -8,7 +8,7 @@ namespace Bitpay\Storage;
8
 
9
  /**
10
  * @codeCoverageIgnore
11
- * @package Bitcore
12
  */
13
  class MockStorage implements StorageInterface
14
  {
8
 
9
  /**
10
  * @codeCoverageIgnore
11
+ * @package Bitcore
12
  */
13
  class MockStorage implements StorageInterface
14
  {
addons/buy-creds/gateways/Bitpay/Util/Error.php CHANGED
@@ -15,9 +15,9 @@ class Error
15
  * and args.
16
  * (PHP 4 >= 4.3.0, PHP 5)
17
  *
18
- * @param bool
19
- * @param bool
20
- * @param int
21
  * @return array|void
22
  */
23
  final public function backtrace($print = false, $options = false, $limit = 0)
@@ -37,7 +37,7 @@ class Error
37
  * Returns NULL if there hasn't been an error yet.
38
  * (PHP 5 >= 5.2.0)
39
  *
40
- * @param void
41
  * @return array
42
  */
43
  final public function last()
@@ -69,7 +69,7 @@ class Error
69
  * parameter is given.
70
  * (PHP 4, PHP 5)
71
  *
72
- * @param bool
73
  * @return int
74
  */
75
  final public function reporting($level = false)
@@ -98,32 +98,32 @@ class Error
98
  $error_types = E_ALL | E_STRICT;
99
  }
100
  switch (strtolower($type)) {
101
- case 'error':
102
- switch (strtolower($action)) {
103
- case 'restore':
104
- return restore_error_handler();
105
- break;
106
- case 'set':
107
- return set_error_handler($callable_handler, $error_types);
108
- break;
109
- default:
110
- return false;
111
- }
112
- break;
113
- case 'exception':
114
- switch (strtolower($action)) {
115
- case 'restore':
116
- return restore_exception_handler();
117
- break;
118
- case 'set':
119
- return set_exception_handler($callable_handler);
120
- break;
121
- default:
122
- return false;
123
- }
124
- break;
125
  default:
126
  return false;
 
 
 
 
127
  }
128
  }
129
 
@@ -134,8 +134,8 @@ class Error
134
  * limited to 1024 bytes.
135
  * (PHP 4 >= 4.0.1, PHP 5)
136
  *
137
- * @param string
138
- * @param int
139
  * @return bool
140
  */
141
  final public function raise($error_msg, $error_type = E_USER_NOTICE)
15
  * and args.
16
  * (PHP 4 >= 4.3.0, PHP 5)
17
  *
18
+ * @param bool
19
+ * @param bool
20
+ * @param int
21
  * @return array|void
22
  */
23
  final public function backtrace($print = false, $options = false, $limit = 0)
37
  * Returns NULL if there hasn't been an error yet.
38
  * (PHP 5 >= 5.2.0)
39
  *
40
+ * @param void
41
  * @return array
42
  */
43
  final public function last()
69
  * parameter is given.
70
  * (PHP 4, PHP 5)
71
  *
72
+ * @param bool
73
  * @return int
74
  */
75
  final public function reporting($level = false)
98
  $error_types = E_ALL | E_STRICT;
99
  }
100
  switch (strtolower($type)) {
101
+ case 'error':
102
+ switch (strtolower($action)) {
103
+ case 'restore':
104
+ return restore_error_handler();
105
+ break;
106
+ case 'set':
107
+ return set_error_handler($callable_handler, $error_types);
108
+ break;
109
+ default:
110
+ return false;
111
+ }
112
+ break;
113
+ case 'exception':
114
+ switch (strtolower($action)) {
115
+ case 'restore':
116
+ return restore_exception_handler();
117
+ break;
118
+ case 'set':
119
+ return set_exception_handler($callable_handler);
120
+ break;
 
 
 
 
121
  default:
122
  return false;
123
+ }
124
+ break;
125
+ default:
126
+ return false;
127
  }
128
  }
129
 
134
  * limited to 1024 bytes.
135
  * (PHP 4 >= 4.0.1, PHP 5)
136
  *
137
+ * @param string
138
+ * @param int
139
  * @return bool
140
  */
141
  final public function raise($error_msg, $error_type = E_USER_NOTICE)
addons/buy-creds/gateways/Bitpay/Util/Fingerprint.php CHANGED
@@ -19,7 +19,7 @@ class Fingerprint
19
  * takes the hash of that value to use as the env
20
  * fingerprint.
21
  *
22
- * @param void
23
  * @return string
24
  */
25
  final public static function generate()
19
  * takes the hash of that value to use as the env
20
  * fingerprint.
21
  *
22
+ * @param void
23
  * @return string
24
  */
25
  final public static function generate()
addons/buy-creds/gateways/Bitpay/Util/Util.php CHANGED
@@ -219,7 +219,7 @@ class Util
219
  *
220
  * @see http://php.net/manual/en/function.decbin.php but for large numbers
221
  *
222
- * @param string
223
  * @return string
224
  */
225
  public static function decToBin($dec)
@@ -252,8 +252,8 @@ class Util
252
  * xR = s2 - 2xP mod p
253
  * yR = -yP + s(xP - xR) mod p
254
  *
255
- * @param PointInterface $point
256
- * @param CurveParameterInterface
257
  * @return PointInterface
258
  */
259
  public static function pointDouble(PointInterface $point, CurveParameterInterface $parameters = null)
@@ -305,16 +305,16 @@ class Util
305
  }
306
 
307
  /**
308
- * Point addition method P + Q = R where:
309
- * s = (yP - yQ)/(xP - xQ) mod p
310
- * xR = s2 - xP - xQ mod p
311
- * yR = -yP + s(xP - xR) mod p
312
- *
313
- * @param PointInterface
314
- * @param PointInterface
315
- *
316
- * @return PointInterface
317
- */
318
  public static function pointAdd(PointInterface $P, PointInterface $Q)
319
  {
320
  if ($P->isInfinity()) {
219
  *
220
  * @see http://php.net/manual/en/function.decbin.php but for large numbers
221
  *
222
+ * @param string
223
  * @return string
224
  */
225
  public static function decToBin($dec)
252
  * xR = s2 - 2xP mod p
253
  * yR = -yP + s(xP - xR) mod p
254
  *
255
+ * @param PointInterface $point
256
+ * @param CurveParameterInterface
257
  * @return PointInterface
258
  */
259
  public static function pointDouble(PointInterface $point, CurveParameterInterface $parameters = null)
305
  }
306
 
307
  /**
308
+ * Point addition method P + Q = R where:
309
+ * s = (yP - yQ)/(xP - xQ) mod p
310
+ * xR = s2 - xP - xQ mod p
311
+ * yR = -yP + s(xP - xR) mod p
312
+ *
313
+ * @param PointInterface
314
+ * @param PointInterface
315
+ *
316
+ * @return PointInterface
317
+ */
318
  public static function pointAdd(PointInterface $P, PointInterface $Q)
319
  {
320
  if ($P->isInfinity()) {
addons/buy-creds/gateways/Bitpay/index.php CHANGED
@@ -1,3 +1,3 @@
1
  <?php
2
  // Silence is golden.
3
- ?>
1
  <?php
2
  // Silence is golden.
3
+ ?>
addons/buy-creds/gateways/bank-transfer.php CHANGED
@@ -1,237 +1,265 @@
1
  <?php
2
- if ( ! defined( 'myCRED_VERSION' ) ) exit;
 
3
 
4
  /**
5
  * myCRED_Bank_Transfer class
6
  * Manual payment gateway - bank transfers
7
- * @since 1.7
 
8
  * @version 1.1
9
  */
10
- if ( ! class_exists( 'myCRED_Bank_Transfer' ) ) :
11
- class myCRED_Bank_Transfer extends myCRED_Payment_Gateway {
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
12
 
13
- /**
14
- * Construct
15
- */
16
- public function __construct( $gateway_prefs ) {
17
 
18
- $types = mycred_get_types();
19
- $default_exchange = array();
20
- foreach ( $types as $type => $label )
21
- $default_exchange[ $type ] = 1;
22
 
23
- parent::__construct( array(
24
- 'id' => 'bank',
25
- 'label' => 'Bank Transfer',
26
- 'documentation' => 'http://codex.mycred.me/chapter-iii/buycred/payment-gateways/bank-transfers/',
27
- 'gateway_logo_url' => '',
28
- 'defaults' => array(
29
- 'title' => '',
30
- 'account' => '',
31
- 'logo_url' => '',
32
- 'currency' => 'EUR',
33
- 'exchange' => $default_exchange
34
- )
35
- ), $gateway_prefs );
36
 
37
- }
 
 
 
 
 
 
 
38
 
39
- /**
40
- * Process Handler
41
- * @since 1.0
42
- * @version 1.0
43
- */
44
- public function process() { }
45
 
46
- /**
47
- * Results Handler
48
- * @since 1.0
49
- * @version 1.0
50
- */
51
- public function returning() {
52
 
53
- add_filter( 'mycred_setup_gateways', array( $this, 'relable_gateway' ) );
 
 
 
 
 
 
 
54
 
55
- }
56
 
57
- /**
58
- * Admin Init Handler
59
- * @since 1.7
60
- * @version 1.0
61
- */
62
- public function admin_init() {
63
 
64
- add_filter( 'mycred_setup_gateways', array( $this, 'relable_gateway' ) );
65
 
66
- }
 
67
 
68
- /**
69
- * Results Handler
70
- * @since 1.7.6
71
- * @version 1.0
72
- */
73
- public function relable_gateway( $installed ) {
74
 
75
- if ( ! empty( $this->prefs['title'] ) && $this->prefs['title'] != $installed['bank']['title'] )
76
- $installed['bank']['title'] = $this->prefs['title'];
77
 
78
- return $installed;
79
 
80
- }
81
 
82
- /**
83
- * AJAX Buy Handler
84
- * @since 1.8
85
- * @version 1.0
86
- */
87
- public function ajax_buy() {
88
 
89
- $this->toggle_id = 'buycred-checkout-step2';
 
 
 
 
 
 
 
90
 
91
- $content = $this->checkout_header();
92
- $content .= $this->checkout_logo();
93
 
94
- $content .= '<div id="buycred-checkout-step1">';
95
-
96
- $content .= $this->checkout_order();
97
- $content .= $this->checkout_cancel();
98
-
99
- $content .= '</div><div id="buycred-checkout-step2" style="display: none;">';
100
-
101
- $content .= $this->checkout_transaction_id();
102
- $content .= wptexturize( wpautop( $this->prefs['account'] ) );
103
-
104
- $content .= '</div>';
105
-
106
- $content .= $this->checkout_footer();
107
-
108
- // Return a JSON response
109
- $this->send_json( $content );
110
-
111
- }
112
-
113
- /**
114
- * Checkout Page Title
115
- * @since 1.8
116
- * @version 1.0
117
- */
118
- public function checkout_page_title() {
119
-
120
- echo $this->checkout_logo();
121
-
122
- }
123
-
124
- /**
125
- * Checkout Page Body
126
- * @since 1.8
127
- * @version 1.0
128
- */
129
- public function checkout_page_body() {
130
-
131
- $this->toggle_id = 'buycred-checkout-step2';
132
-
133
- echo $this->checkout_header();
134
- echo $this->checkout_logo( false );
135
-
136
- echo '<div id="buycred-checkout-step1">';
137
-
138
- echo $this->checkout_order();
139
- echo $this->checkout_cancel();
140
-
141
- echo '</div><div id="buycred-checkout-step2" style="display: none;">';
142
-
143
- echo $this->checkout_transaction_id();
144
- echo wptexturize( wpautop( $this->prefs['account'] ) );
145
-
146
- echo '</div>';
147
-
148
- echo $this->checkout_footer();
149
-
150
- }
151
-
152
- /**
153
- * Preferences
154
- * @since 1.0
155
- * @version 1.0
156
- */
157
- public function preferences() {
158
-
159
- $prefs = $this->prefs;
160
-
161
- ?>
162
  <div class="row">
163
- <div class="col-lg-6 col-md-6 col-sm-12 col-xs-12">
164
- <h3><?php _e( 'Details', 'mycred' ); ?></h3>
165
- <div class="form-group">
166
- <label for="<?php echo $this->field_id( 'title' ); ?>"><?php _e( 'Title', 'mycred' ); ?></label>
167
- <input type="text" name="<?php echo $this->field_name( 'title' ); ?>" id="<?php echo $this->field_id( 'title' ); ?>" value="<?php echo esc_attr( $prefs['title'] ); ?>" class="form-control" />
168
- </div>
169
- <div class="form-group">
170
- <label for="<?php echo $this->field_id( 'logo_url' ); ?>"><?php _e( 'Logo URL', 'mycred' ); ?></label>
171
- <input type="text" name="<?php echo $this->field_name( 'logo_url' ); ?>" id="<?php echo $this->field_id( 'logo_url' ); ?>" value="<?php echo esc_attr( $prefs['logo_url'] ); ?>" class="form-control" />
172
- </div>
173
- </div>
174
- <div class="col-lg-6 col-md-6 col-sm-12 col-xs-12">
175
- <h3><?php _e( 'Setup', 'mycred' ); ?></h3>
176
- <div class="form-group">
177
- <label for="<?php echo $this->field_id( 'currency' ); ?>"><?php _e( 'Currency', 'mycred' ); ?></label>
178
- <input type="text" name="<?php echo $this->field_name( 'currency' ); ?>" id="<?php echo $this->field_id( 'currency' ); ?>" value="<?php echo esc_attr( $prefs['currency'] ); ?>" class="form-control" />
179
- </div>
180
- <div class="form-group">
181
- <label><?php _e( 'Exchange Rates', 'mycred' ); ?></label>
182
-
183
- <?php $this->exchange_rate_setup(); ?>
184
-
185
- </div>
186
- </div>
187
  </div>
188
  <div class="row">
189
- <div class="col-lg-12 col-md-12 col-sm-12 col-xs-12">
190
- <div class="form-group">
191
- <label for="buycredbanktransferaccount"><?php _e( 'Bank Account Information', 'mycred' ); ?></label>
192
- <?php wp_editor( $prefs['account'], 'buycredbanktransferaccount', array( 'textarea_name' => $this->field_name( 'account' ), 'textarea_rows' => 10 ) ); ?>
193
- </div>
194
- </div>
195
  </div>
196
  <script type="text/javascript">
197
  jQuery(function($){
198
 
199
- $( '#mycred-gateway-prefs-bank-currency' ).change(function(){
200
- $( 'span.mycred-gateway-bank-currency' ).text( $(this).val() );
201
- });
202
 
203
  });
204
  </script>
205
- <?php
206
 
207
- }
208
 
209
- /**
210
- * Sanatize Prefs
211
- * @since 1.0
212
- * @version 1.0
213
- */
214
- public function sanitise_preferences( $data ) {
 
 
215
 
216
- $new_data = array();
217
 
218
- $new_data['title'] = sanitize_text_field( $data['title'] );
219
- $new_data['logo_url'] = sanitize_text_field( $data['logo_url'] );
220
- $new_data['account'] = wp_kses_post( $data['account'] );
221
- $new_data['currency'] = sanitize_text_field( $data['currency'] );
222
 
223
- // If exchange is less then 1 we must start with a zero
224
- if ( isset( $data['exchange'] ) ) {
225
- foreach ( (array) $data['exchange'] as $type => $rate ) {
226
- if ( $rate != 1 && in_array( substr( $rate, 0, 1 ), array( '.', ',' ) ) )
227
- $data['exchange'][ $type ] = (float) '0' . $rate;
228
- }
229
- }
230
- $new_data['exchange'] = $data['exchange'];
 
231
 
232
- return $new_data;
233
 
234
- }
235
 
236
- }
237
  endif;
1
  <?php
2
+ if (! defined('myCRED_VERSION') ) { exit;
3
+ }
4
 
5
  /**
6
  * myCRED_Bank_Transfer class
7
  * Manual payment gateway - bank transfers
8
+ *
9
+ * @since 1.7
10
  * @version 1.1
11
  */
12
+ if (! class_exists('myCRED_Bank_Transfer') ) :
13
+ class myCRED_Bank_Transfer extends myCRED_Payment_Gateway
14
+ {
15
+
16
+ /**
17
+ * Construct
18
+ */
19
+ public function __construct( $gateway_prefs )
20
+ {
21
+
22
+ $types = mycred_get_types();
23
+ $default_exchange = array();
24
+ foreach ( $types as $type => $label ) {
25
+ $default_exchange[ $type ] = 1;
26
+ }
27
+
28
+ parent::__construct(
29
+ array(
30
+ 'id' => 'bank',
31
+ 'label' => 'Bank Transfer',
32
+ 'documentation' => 'http://codex.mycred.me/chapter-iii/buycred/payment-gateways/bank-transfers/',
33
+ 'gateway_logo_url' => '',
34
+ 'defaults' => array(
35
+ 'title' => '',
36
+ 'account' => '',
37
+ 'logo_url' => '',
38
+ 'currency' => 'EUR',
39
+ 'exchange' => $default_exchange
40
+ )
41
+ ), $gateway_prefs
42
+ );
43
+
44
+ }
45
+
46
+ /**
47
+ * Process Handler
48
+ *
49
+ * @since 1.0
50
+ * @version 1.0
51
+ */
52
+ public function process()
53
+ {
54
+ }
55
+
56
+ /**
57
+ * Results Handler
58
+ *
59
+ * @since 1.0
60
+ * @version 1.0
61
+ */
62
+ public function returning()
63
+ {
64
+
65
+ add_filter('mycred_setup_gateways', array( $this, 'relable_gateway' ));
66
+
67
+ }
68
+
69
+ /**
70
+ * Admin Init Handler
71
+ *
72
+ * @since 1.7
73
+ * @version 1.0
74
+ */
75
+ public function admin_init()
76
+ {
77
+
78
+ add_filter('mycred_setup_gateways', array( $this, 'relable_gateway' ));
79
+
80
+ }
81
+
82
+ /**
83
+ * Results Handler
84
+ *
85
+ * @since 1.7.6
86
+ * @version 1.0
87
+ */
88
+ public function relable_gateway( $installed )
89
+ {
90
+
91
+ if (! empty($this->prefs['title']) && $this->prefs['title'] != $installed['bank']['title'] ) {
92
+ $installed['bank']['title'] = $this->prefs['title'];
93
+ }
94
+
95
+ return $installed;
96
+
97
+ }
98
+
99
+ /**
100
+ * AJAX Buy Handler
101
+ *
102
+ * @since 1.8
103
+ * @version 1.0
104
+ */
105
+ public function ajax_buy()
106
+ {
107
+
108
+ $this->toggle_id = 'buycred-checkout-step2';
109
+
110
+ $content = $this->checkout_header();
111
+ $content .= $this->checkout_logo();
112
+
113
+ $content .= '<div id="buycred-checkout-step1">';
114
+
115
+ $content .= $this->checkout_order();
116
+ $content .= $this->checkout_cancel();
117
+
118
+ $content .= '</div><div id="buycred-checkout-step2" style="display: none;">';
119
+
120
+ $content .= $this->checkout_transaction_id();
121
+ $content .= wptexturize(wpautop($this->prefs['account']));
122
+
123
+ $content .= '</div>';
124
 
125
+ $content .= $this->checkout_footer();
 
 
 
126
 
127
+ // Return a JSON response
128
+ $this->send_json($content);
 
 
129
 
130
+ }
 
 
 
 
 
 
 
 
 
 
 
 
131
 
132
+ /**
133
+ * Checkout Page Title
134
+ *
135
+ * @since 1.8
136
+ * @version 1.0
137
+ */
138
+ public function checkout_page_title()
139
+ {
140
 
141
+ echo $this->checkout_logo();
 
 
 
 
 
142
 
143
+ }
 
 
 
 
 
144
 
145
+ /**
146
+ * Checkout Page Body
147
+ *
148
+ * @since 1.8
149
+ * @version 1.0
150
+ */
151
+ public function checkout_page_body()
152
+ {
153
 
154
+ $this->toggle_id = 'buycred-checkout-step2';
155
 
156
+ echo $this->checkout_header();
157
+ echo $this->checkout_logo(false);
 
 
 
 
158
 
159
+ echo '<div id="buycred-checkout-step1">';
160
 
161
+ echo $this->checkout_order();
162
+ echo $this->checkout_cancel();
163
 
164
+ echo '</div><div id="buycred-checkout-step2" style="display: none;">';
 
 
 
 
 
165
 
166
+ echo $this->checkout_transaction_id();
167
+ echo wptexturize(wpautop($this->prefs['account']));
168
 
169
+ echo '</div>';
170
 
171
+ echo $this->checkout_footer();
172
 
173
+ }
 
 
 
 
 
174
 
175
+ /**
176
+ * Preferences
177
+ *
178
+ * @since 1.0
179
+ * @version 1.0
180
+ */
181
+ public function preferences()
182
+ {
183
 
184
+ $prefs = $this->prefs;
 
185
 
186
+ ?>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
187
  <div class="row">
188
+ <div class="col-lg-6 col-md-6 col-sm-12 col-xs-12">
189
+ <h3><?php _e('Details', 'mycred'); ?></h3>
190
+ <div class="form-group">
191
+ <label for="<?php echo $this->field_id('title'); ?>"><?php _e('Title', 'mycred'); ?></label>
192
+ <input type="text" name="<?php echo $this->field_name('title'); ?>" id="<?php echo $this->field_id('title'); ?>" value="<?php echo esc_attr($prefs['title']); ?>" class="form-control" />
193
+ </div>
194
+ <div class="form-group">
195
+ <label for="<?php echo $this->field_id('logo_url'); ?>"><?php _e('Logo URL', 'mycred'); ?></label>
196
+ <input type="text" name="<?php echo $this->field_name('logo_url'); ?>" id="<?php echo $this->field_id('logo_url'); ?>" value="<?php echo esc_attr($prefs['logo_url']); ?>" class="form-control" />
197
+ </div>
198
+ </div>
199
+ <div class="col-lg-6 col-md-6 col-sm-12 col-xs-12">
200
+ <h3><?php _e('Setup', 'mycred'); ?></h3>
201
+ <div class="form-group">
202
+ <label for="<?php echo $this->field_id('currency'); ?>"><?php _e('Currency', 'mycred'); ?></label>
203
+ <input type="text" name="<?php echo $this->field_name('currency'); ?>" id="<?php echo $this->field_id('currency'); ?>" value="<?php echo esc_attr($prefs['currency']); ?>" class="form-control" />
204
+ </div>
205
+ <div class="form-group">
206
+ <label><?php _e('Exchange Rates', 'mycred'); ?></label>
207
+
208
+ <?php $this->exchange_rate_setup(); ?>
209
+
210
+ </div>
211
+ </div>
212
  </div>
213
  <div class="row">
214
+ <div class="col-lg-12 col-md-12 col-sm-12 col-xs-12">
215
+ <div class="form-group">
216
+ <label for="buycredbanktransferaccount"><?php _e('Bank Account Information', 'mycred'); ?></label>
217
+ <?php wp_editor($prefs['account'], 'buycredbanktransferaccount', array( 'textarea_name' => $this->field_name('account'), 'textarea_rows' => 10 )); ?>
218
+ </div>
219
+ </div>
220
  </div>
221
  <script type="text/javascript">
222
  jQuery(function($){
223
 
224
+ $( '#mycred-gateway-prefs-bank-currency' ).change(function(){
225
+ $( 'span.mycred-gateway-bank-currency' ).text( $(this).val() );
226
+ });
227
 
228
  });
229
  </script>
230
+ <?php
231
 
232
+ }
233
 
234
+ /**
235
+ * Sanatize Prefs
236
+ *
237
+ * @since 1.0
238
+ * @version 1.0
239
+ */
240
+ public function sanitise_preferences( $data )
241
+ {
242
 
243
+ $new_data = array();
244
 
245
+ $new_data['title'] = sanitize_text_field($data['title']);
246
+ $new_data['logo_url'] = sanitize_text_field($data['logo_url']);
247
+ $new_data['account'] = wp_kses_post($data['account']);
248
+ $new_data['currency'] = sanitize_text_field($data['currency']);
249
 
250
+ // If exchange is less then 1 we must start with a zero
251
+ if (isset($data['exchange']) ) {
252
+ foreach ( (array) $data['exchange'] as $type => $rate ) {
253
+ if ($rate != 1 && in_array(substr($rate, 0, 1), array( '.', ',' )) ) {
254
+ $data['exchange'][ $type ] = (float) '0' . $rate;
255
+ }
256
+ }
257
+ }
258
+ $new_data['exchange'] = $data['exchange'];
259
 
260
+ return $new_data;
261
 
262
+ }
263
 
264
+ }
265
  endif;
addons/buy-creds/gateways/bitpay.php CHANGED
@@ -1,610 +1,637 @@
1
  <?php
2
- if ( ! defined( 'myCRED_VERSION' ) ) exit;
 
3
 
4
  /**
5
  * Load BitPay PHP Library
6
- * @since 1.8
 
7
  * @version 1.0
8
  */
9
- if ( ! class_exists( 'WC_Gateway_Bitpay' ) ) {
10
 
11
- $autoloader_param = __DIR__ . '/Bitpay/Autoloader.php';
12
 
13
- // Load up the BitPay library
14
- if ( true === file_exists( $autoloader_param ) && true === is_readable( $autoloader_param ) ) {
15
 
16
- require_once $autoloader_param;
17
- \Bitpay\Autoloader::register();
18
 
19
- }
20
 
21
- // Exist for quirks in object serialization...
22
- if ( false === class_exists( 'PrivateKey' ) ) {
23
- include_once( __DIR__ . '/Bitpay/PrivateKey.php' );
24
- }
25
 
26
- if ( false === class_exists( 'PublicKey' ) ) {
27
- include_once( __DIR__ . '/Bitpay/PublicKey.php' );
28
- }
29
 
30
- if ( false === class_exists( 'Token' ) ) {
31
- include_once( __DIR__ . '/Bitpay/Token.php' );
32
- }
33
 
34
  }
35
 
36
  /**
37
  * myCRED_Bitpay class
38
  * BitPay (Bitcoins) - Payment Gateway
39
- * @since 1.4
 
40
  * @version 1.2
41
  */
42
- if ( ! class_exists( 'myCRED_Bitpay' ) ) :
43
- class myCRED_Bitpay extends myCRED_Payment_Gateway {
44
-
45
- /**
46
- * Construct
47
- */
48
- public function __construct( $gateway_prefs ) {
49
-
50
- $types = mycred_get_types();
51
- $default_exchange = array();
52
- foreach ( $types as $type => $label )
53
- $default_exchange[ $type ] = 1;
54
 
55
- parent::__construct( array(
56
- 'id' => 'bitpay',
57
- 'label' => 'Bitpay',
58
- 'gateway_logo_url' => plugins_url( 'assets/images/bitpay.png', MYCRED_PURCHASE ),
59
- 'defaults' => array(
60
- 'sandbox' => 0,
61
- 'api_public' => '',
62
- 'api_secret' => '',
63
- 'api_sign' => '',
64
- 'api_token' => '',
65
- 'api_label' => '',
66
- 'currency' => 'USD',
67
- 'exchange' => $default_exchange,
68
- 'item_name' => 'Purchase of myCRED %plural%',
69
- 'logo_url' => '',
70
- 'speed' => 'high',
71
- 'notifications' => 1
72
- )
73
- ), $gateway_prefs );
74
 
75
- $this->is_ready = false;
76
- if ( isset( $this->prefs['api_public'] ) && ! empty( $this->prefs['api_public'] ) && isset( $this->prefs['api_secret'] ) && ! empty( $this->prefs['api_secret'] ) )
77
- $this->is_ready = true;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
78
 
79
- }
80
 
81
- /**
82
- * Process
83
- * @since 1.4
84
- * @version 1.2
85
- */
86
- public function process() {
 
 
87
 
88
- $post = file_get_contents( "php://input" );
89
- if ( ! empty( $post ) ) {
90
 
91
- $new_call = array();
92
- $json = json_decode( $post, true );
93
- if ( ! empty( $json ) && array_key_exists( 'id', $json ) && array_key_exists( 'url', $json ) ) {
94
 
95
- try {
96
 
97
- $client = new \Bitpay\Client\Client();
98
- if ( false === strpos( $json['url'], 'test' ) )
99
- $network = new \Bitpay\Network\Livenet();
100
- else
101
- $network = new \Bitpay\Network\Testnet();
 
102
 
103
- $client->setNetwork( $network );
104
- $curlAdapter = new \Bitpay\Client\Adapter\CurlAdapter();
105
- $client->setAdapter( $curlAdapter );
106
 
107
- $client->setPrivateKey( buycred_bitpay_decrypt( $this->prefs['api_secret'] ) );
108
- $client->setPublicKey( buycred_bitpay_decrypt( $this->prefs['api_public'] ) );
109
- $client->setToken( buycred_bitpay_decrypt( $this->prefs['api_token'] ) );
110
 
111
- $invoice = $client->getInvoice( $json['id'] );
112
 
113
- } catch ( \Exception $e ) {
114
 
115
- $new_call[] = $e->getMessage();
116
 
117
- }
118
 
119
- if ( empty( $new_call ) ) {
120
 
121
- $transaction_id = $invoice->getOrderId();
122
- $pending_post_id = buycred_get_pending_payment_id( $transaction_id );
123
- $pending_payment = $this->get_pending_payment( $pending_post_id );
124
 
125
- if ( $pending_payment !== false ) {
126
 
127
- // If account is credited, delete the post and it's comments.
128
- if ( $this->complete_payment( $pending_payment, $json['id'] ) )
129
- $this->trash_pending_payment( $pending_post_id );
130
- else
131
- $new_call[] = __( 'Failed to credit users account.', 'mycred' );
 
132
 
133
- // Log Call
134
- if ( ! empty( $new_call ) )
135
- $this->log_call( $pending_post_id, $new_call );
 
136
 
137
- }
138
 
139
- }
140
 
141
- }
142
 
143
- }
144
 
145
- }
146
 
147
- /**
148
- * Returning
149
- * @since 1.4
150
- * @version 1.0
151
- */
152
- public function returning() { }
 
 
 
153
 
154
- /**
155
- * Admin Init Handler
156
- * @since 1.8
157
- * @version 1.0
158
- */
159
- public function admin_init() {
 
 
160
 
161
- add_action( 'wp_ajax_buycred-bitpay-pairing', array( $this, 'ajax_pair' ) );
162
 
163
- }
164
 
165
- /**
166
- * AJAX: Pair with bitPay
167
- * @since 1.8
168
- * @version 1.0
169
- */
170
- public function ajax_pair() {
 
 
171
 
172
- check_ajax_referer( 'buycred-pair-bitpay', 'token' );
173
 
174
- $pairing_code = sanitize_text_field( $_POST['code'] );
175
- $network = sanitize_text_field( $_POST['network'] );
176
 
177
- try {
178
 
179
- $key = new \Bitpay\PrivateKey();
180
- $key->generate();
181
 
182
- $pub = new \Bitpay\PublicKey();
183
- $pub->setPrivateKey( $key );
184
- $pub->generate();
185
 
186
- $sin = new \Bitpay\SinKey();
187
- $sin->setPublicKey( $pub );
188
- $sin->generate();
189
 
190
- $client = new \Bitpay\Client\Client();
191
 
192
- if ( $network === 'live' )
193
- $client->setNetwork( new \Bitpay\Network\Livenet() );
194
- else
195
- $client->setNetwork( new \Bitpay\Network\Testnet() );
 
196
 
197
- $curlAdapter = new \Bitpay\Client\Adapter\CurlAdapter();
198
 
199
- $client->setAdapter( $curlAdapter );
200
- $client->setPrivateKey( $key );
201
- $client->setPublicKey( $pub );
202
 
203
- } catch ( \Exception $e ) {
204
- wp_send_json_error( $e->getMessage() );
205
- }
206
 
207
- $label = preg_replace( '/[^a-zA-Z0-9 \-\_\.]/', '', get_bloginfo() );
208
- $label = substr( 'buyCRED - ' . $label, 0, 59 );
209
 
210
- try {
211
 
212
- $token = $client->createToken(
213
- array(
214
- 'id' => (string) $sin,
215
- 'pairingCode' => $pairing_code,
216
- 'label' => $label,
217
- )
218
- );
219
 
220
- } catch ( \Exception $e ) {
221
 
222
- wp_send_json_error( $e->getMessage() );
223
 
224
- }
225
 
226
- if ( $network !== 'live' )
227
- $label .= ' (Testnet)';
 
228
 
229
- wp_send_json_success( array(
230
- 'api_secret' => '<input type="hidden" name="' . $this->field_name( 'api_secret' ) . '" value="' . buycred_bitpay_encrypt( $key ) . '" />',
231
- 'api_public' => '<input type="hidden" name="' . $this->field_name( 'api_public' ) . '" value="' . buycred_bitpay_encrypt( $pub ) . '" />',
232
- 'api_sign' => '<input type="hidden" name="' . $this->field_name( 'api_sign' ) . '" value="' . (string) $sin . '" />',
233
- 'api_token' => '<input type="hidden" name="' . $this->field_name( 'api_token' ) . '" value="' . buycred_bitpay_encrypt( $token ) . '" />',
234
- 'label' => '<input type="hidden" name="' . $this->field_name( 'api_label' ) . '" value="' . $label . '" /><p class="form-control-static">' . $label . '</p>'
235
- ) );
 
 
236
 
237
- }
238
 
239
- /**
240
- * Prep Sale
241
- * @since 1.8
242
- * @version 1.0
243
- */
244
- public function prep_sale( $new_transaction = false ) {
 
 
245
 
246
- // Set currency
247
- $this->currency = ( $this->currency == '' ) ? $this->prefs['currency'] : $this->currency;
248
 
249
- //Set Cost in raw format
250
- $this->cost = $this->get_cost( $this->amount, $this->point_type, true );
251
 
252
- // Item Name
253
- $item_name = str_replace( '%number%', $this->amount, $this->prefs['item_name'] );
254
- $item_name = $this->core->template_tags_general( $item_name );
255
 
256
- $user = get_userdata( $this->buyer_id );
257
 
258
- // Based on the "BitPay for WooCommerce" plugin issued by Bitpay
259
- try {
260
 
261
- // Currency
262
- $currency = new \Bitpay\Currency( $this->currency );
263
 
264
- // First, we set the client
265
- $client = new \Bitpay\Client\Client();
266
 
267
- if ( ! $this->sandbox_mode )
268
- $client->setNetwork( new \Bitpay\Network\Livenet() );
269
- else
270
- $client->setNetwork( new \Bitpay\Network\Testnet() );
 
271
 
272
- $curlAdapter = new \Bitpay\Client\Adapter\CurlAdapter();
273
- $client->setAdapter($curlAdapter);
274
 
275
- $client->setPrivateKey( buycred_bitpay_decrypt( $this->prefs['api_secret'] ) );
276
- $client->setPublicKey( buycred_bitpay_decrypt( $this->prefs['api_public'] ) );
277
- $client->setToken( buycred_bitpay_decrypt( $this->prefs['api_token'] ) );
278
 
279
- // Next, we create an invoice object
280
- $invoice = new \Bitpay\Invoice();
281
- $invoice->setOrderId( (string) $this->transaction_id );
282
- $invoice->setCurrency( $currency ) ;
283
- $invoice->setFullNotifications( ( ( $this->prefs['notifications'] ) ? true : false ) );
284
 
285
- // Next, we set the invoice item
286
- $item = new \Bitpay\Item();
287
- $item->setPrice( $this->cost );
288
- $item->setDescription( $item_name );
289
 
290
- // This includes setting the buyer
291
- $buyer = new \Bitpay\Buyer();
292
- $buyer->setEmail( $user->user_email );
293
 
294
- $invoice->setBuyer( $buyer );
295
- $invoice->setItem( $item );
296
 
297
- // Append extras
298
- $invoice->setRedirectUrl( $this->get_thankyou() );
299
- $invoice->setNotificationUrl( $this->callback_url() );
300
- $invoice->setTransactionSpeed( $this->prefs['speed'] );
301
 
302
- // Create an invoice
303
- $invoice = $client->createInvoice( $invoice );
304
 
305
- } catch ( \Exception $e ) {
306
 
307
- $this->errors[] = $e->getMessage();
308
 
309
- }
310
 
311
- if ( empty( $this->errors ) ) {
312
 
313
- $this->redirect_to = $invoice->getUrl();
314
 
315
- }
316
 
317
- }
318
 
319
- /**
320
- * AJAX Buy Handler
321
- * @since 1.8
322
- * @version 1.0
323
- */
324
- public function ajax_buy() {
 
 
325
 
326
- // Construct the checkout box content
327
- $content = $this->checkout_header();
328
- $content .= $this->checkout_logo();
329
- $content .= $this->checkout_order();
330
- $content .= $this->checkout_cancel();
331
- $content .= $this->checkout_footer();
332
 
333
- // Return a JSON response
334
- $this->send_json( $content );
335
 
336
- }
337
 
338
- /**
339
- * Checkout Page Body
340
- * This gateway only uses the checkout body.
341
- * @since 1.8
342
- * @version 1.0
343
- */
344
- public function checkout_page_body() {
 
 
345
 
346
- echo $this->checkout_header();
347
- echo $this->checkout_logo( false );
348
 
349
- echo $this->checkout_order();
350
- echo $this->checkout_cancel();
351
 
352
- echo $this->checkout_footer();
353
 
354
- }
355
 
356
- /**
357
- * Gateway Prefs
358
- * @since 1.4
359
- * @version 1.0
360
- */
361
- function preferences() {
 
 
362
 
363
- $prefs = $this->prefs;
364
 
365
- ?>
366
  <div class="row">
367
- <div class="col-lg-6 col-md-6 col-sm-12 col-xs-12">
368
- <h3><?php _e( 'Details', 'mycred' ); ?></h3>
369
-
370
- <?php if ( ! $this->is_ready ) : ?>
371
-
372
- <div class="form-group">
373
- <label><?php _e( 'API Token', 'mycred' ); ?></label>
374
- <div class="form-inline" id="bitpay-pairing-wrapper">
375
- <input type="text" id="bitpay-pair-code" class="form-control" placeholder="Pairing Code" value="" />
376
- <select id="bitpay-pair-network" class="form-control">
377
- <option value="live">Livenet</option>
378
- <option value="test">Testnet</option>
379
- </select>
380
- <button type="button" id="sync-bitpay-pairing-code" class="button button-secondary">Sync</button>
381
- </div>
382
- <p class="description bitpay-link" id="bitpay-link-live"><span>Get a pairing code: <a href="https://bitpay.com/api-tokens" target="_blank">https://bitpay.com/api-tokens</a></span></p>
383
- <p class="description bitpay-link" id="bitpay-link-test" style="display: none;"><span>Get a pairing code: <a href="https://test.bitpay.com/api-tokens" target="_blank">https://test.bitpay.com/api-tokens</a></span></p>
384
- </div>
385
  <script type="text/javascript">
386
  jQuery(function($){
387
 
388
- $( '#sync-bitpay-pairing-code' ).click(function(e){
389
 
390
- e.preventDefault();
391
 
392
- var pairwrapper = $( '#bitpay-pairing-wrapper' );
393
 
394
- $.ajax({
395
- type : "POST",
396
- data : {
397
- action : 'buycred-bitpay-pairing',
398
- token : '<?php echo wp_create_nonce( 'buycred-pair-bitpay' ); ?>',
399
- code : $( '#bitpay-pair-code' ).val(),
400
- network : $( '#bitpay-pair-network' ).find( ':selected' ).val(),
401
- },
402
- dataType : "JSON",
403
- url : '<?php echo admin_url( 'admin-ajax.php' ); ?>',
404
- beforeSend : function() {
405
 
406
- $( '#sync-bitpay-pairing-code' ).attr( 'disabled', 'disabled' );
407
 
408
- },
409
- success : function( response ) {
410
 
411
- if ( response.success ) {
412
 
413
- pairwrapper.slideUp(function(){
414
- pairwrapper.empty();
415
- $.each( response.data, function(index,element){
416
- pairwrapper.append( element );
417
- });
418
- pairwrapper.slideDown();
419
- });
420
 
421
- }
422
- else {
423
 
424
- alert( response.data );
425
- $( '#sync-bitpay-pairing-code' ).removeAttr( 'disabled' );
426
 
427
- }
428
 
429
- },
430
- error : function() {
431
- alert( 'Communications Error' );
432
- }
433
- });
434
 
435
- });
436
 
437
- $( '#bitpay-pair-network' ).change(function(){
438
 
439
- $( '.bitpay-link' ).hide();
440
- var selectedmode = $(this).find( ':selected' );
441
- $( '#bitpay-link-' + selectedmode.val() ).show();
442
 
443
- });
444
 
445
  });
446
  </script>
447
 
448
- <?php else : ?>
449
-
450
- <div class="form-group">
451
- <label><?php _e( 'API Token', 'mycred' ); ?></label>
452
- <p class="form-control-static"><?php echo esc_attr( $prefs['api_label'] ); ?></p>
453
- <button type="button" id="bitpay-cancel-pair" class="button button-secondary">Revoke Token</button>
454
- <input type="hidden" class="reset-api" name="<?php echo $this->field_name( 'api_secret' ); ?>" value="<?php echo esc_attr( $prefs['api_secret'] ); ?>" />
455
- <input type="hidden" class="reset-api" name="<?php echo $this->field_name( 'api_public' ); ?>" value="<?php echo esc_attr( $prefs['api_public'] ); ?>" />
456
- <input type="hidden" class="reset-api" name="<?php echo $this->field_name( 'api_sign' ); ?>" value="<?php echo esc_attr( $prefs['api_sign'] ); ?>" />
457
- <input type="hidden" class="reset-api" name="<?php echo $this->field_name( 'api_token' ); ?>" value="<?php echo esc_attr( $prefs['api_token'] ); ?>" />
458
- <input type="hidden" class="reset-api" name="<?php echo $this->field_name( 'api_label' ); ?>" value="<?php echo esc_attr( $prefs['api_label'] ); ?>" />
459
- </div>
460
  <script type="text/javascript">
461
  jQuery(function($){
462
 
463
- $( '#bitpay-cancel-pair' ).click(function(e){
464
 
465
- e.preventDefault();
466
 
467
- if ( confirm( '<?php echo esc_js( esc_attr( __( 'Are you sure you want to do this?', 'mycred' ) ) ); ?>' ) ) {
468
 
469
- $( 'input.reset-api' ).val( '' );
470
- $(this).before().html( '<?php echo esc_js( __( 'Removed - Remember to save your changes.', 'mycred' ) ); ?>' );
471
 
472
- }
473
 
474
- });
475
 
476
  });
477
  </script>
478
 
479
- <?php endif; ?>
480
-
481
- <div class="form-group">
482
- <label for="<?php echo $this->field_id( 'item_name' ); ?>"><?php _e( 'Item Name', 'mycred' ); ?></label>
483
- <input type="text" name="<?php echo $this->field_name( 'item_name' ); ?>" id="<?php echo $this->field_id( 'item_name' ); ?>" value="<?php echo esc_attr( $prefs['item_name'] ); ?>" class="form-control" />
484
- </div>
485
- <div class="form-group">
486
- <label for="<?php echo $this->field_id( 'logo_url' ); ?>"><?php _e( 'Logo URL', 'mycred' ); ?></label>
487
- <input type="text" name="<?php echo $this->field_name( 'logo_url' ); ?>" id="<?php echo $this->field_id( 'logo_url' ); ?>" value="<?php echo esc_attr( $prefs['logo_url'] ); ?>" class="form-control" />
488
- </div>
489
- <div class="row">
490
- <div class="col-lg-6 col-md-6 col-sm-12 col-xs-12">
491
- <div class="form-group">
492
- <label for="<?php echo $this->field_id( 'speed' ); ?>"><?php _e( 'Transaction Speed', 'mycred' ); ?></label>
493
- <select name="<?php echo $this->field_name( 'speed' ); ?>" id="<?php echo $this->field_id( 'speed' ); ?>" class="form-control">
494
- <?php
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
495
 
496
- $options = array(
497
- 'high' => __( 'High', 'mycred' ),
498
- 'medium' => __( 'Medium', 'mycred' ),
499
- 'low' => __( 'Low', 'mycred' )
500
- );
501
- foreach ( $options as $value => $label ) {
502
- echo '<option value="' . $value . '"';
503
- if ( $prefs['speed'] == $value ) echo ' selected="selected"';
504
- echo '>' . $label . '</option>';
505
- }
506
-
507
- ?>
508
-
509
- </select>
510
- </div>
511
- </div>
512
- <div class="col-lg-6 col-md-6 col-sm-12 col-xs-12">
513
- <div class="form-group">
514
- <label for="<?php echo $this->field_id( 'notifications' ); ?>"><?php _e( 'Full Notifications', 'mycred' ); ?></label>
515
- <select name="<?php echo $this->field_name( 'notifications' ); ?>" id="<?php echo $this->field_id( 'notifications' ); ?>" class="form-control">
516
- <?php
517
 
518
- $options = array(
519
- 0 => __( 'No', 'mycred' ),
520
- 1 => __( 'Yes', 'mycred' )
521
- );
522
- foreach ( $options as $value => $label ) {
523
- echo '<option value="' . $value . '"';
524
- if ( $prefs['notifications'] == $value ) echo ' selected="selected"';
525
- echo '>' . $label . '</option>';
526
- }
527
-
528
- ?>
529
-
530
- </select>
531
- </div>
532
- </div>
533
- </div>
534
- </div>
535
- <div class="col-lg-6 col-md-6 col-sm-12 col-xs-12">
536
- <h3><?php _e( 'Setup', 'mycred' ); ?></h3>
537
- <div class="form-group">
538
- <label for="<?php echo $this->field_id( 'currency' ); ?>"><?php _e( 'Currency', 'mycred' ); ?></label>
539
- <input type="text" name="<?php echo $this->field_name( 'currency' ); ?>" id="<?php echo $this->field_id( 'currency' ); ?>" value="<?php echo $prefs['currency']; ?>" class="form-control" maxlength="3" placeholder="<?php _e( 'Currency Code', 'mycred' ); ?>" />
540
-
541
- </div>
542
- <div class="form-group">
543
- <label><?php _e( 'Exchange Rates', 'mycred' ); ?></label>
544
-
545
- <?php $this->exchange_rate_setup(); ?>
546
-
547
- </div>
548
- </div>
549
- </div>
550
- <?php
551
 
552
- }
553
-
554
- /**
555
- * Sanatize Prefs
556
- * @since 1.4
557
- * @version 1.2
558
- */
559
- public function sanitise_preferences( $data ) {
560
-
561
- $new_data = array();
562
-
563
- if ( array_key_exists( 'api_secret', $data ) ) {
564
- $new_data['api_secret'] = sanitize_text_field( $data['api_secret'] );
565
- $new_data['api_public'] = sanitize_text_field( $data['api_public'] );
566
- $new_data['api_sign'] = sanitize_text_field( $data['api_sign'] );
567
- $new_data['api_token'] = sanitize_text_field( $data['api_token'] );
568
- $new_data['api_label'] = sanitize_text_field( $data['api_label'] );
569
- }
570
- else {
571
- $new_data['api_secret'] = '';
572
- $new_data['api_public'] = '';
573
- $new_data['api_sign'] = '';
574
- $new_data['api_token'] = '';
575
- $new_data['api_label'] = '';
576
- }
577
-
578
- $new_data['sandbox'] = ( isset( $data['sandbox'] ) ) ? 1 : 0;
579
- $new_data['currency'] = sanitize_text_field( $data['currency'] );
580
- $new_data['item_name'] = sanitize_text_field( $data['item_name'] );
581
- $new_data['logo_url'] = sanitize_text_field( $data['logo_url'] );
582
- $new_data['speed'] = sanitize_text_field( $data['speed'] );
583
- $new_data['notifications'] = sanitize_text_field( $data['notifications'] );
584
-
585
- // If exchange is less then 1 we must start with a zero
586
- if ( isset( $data['exchange'] ) ) {
587
- foreach ( (array) $data['exchange'] as $type => $rate ) {
588
- if ( $rate != 1 && in_array( substr( $rate, 0, 1 ), array( '.', ',' ) ) )
589
- $data['exchange'][ $type ] = (float) '0' . $rate;
590
- }
591
- }
592
- $new_data['exchange'] = $data['exchange'];
593
-
594
- return $new_data;
595
-
596
- }
597
-
598
- }
599
  endif;
600
 
601
  /**
602
  * Bitpay Encrypt
603
- * @since 1.8
 
604
  * @version 1.0
605
  */
606
- if ( ! function_exists( 'buycred_bitpay_encrypt' ) ) :
607
- function buycred_bitpay_encrypt( $data ) {
 
608
 
609
  if (false === isset($data) || true === empty($data)) {
610
  throw new \Exception('The Bitpay payment plugin was called to encrypt data but no data was passed!');
@@ -613,10 +640,10 @@ if ( ! function_exists( 'buycred_bitpay_encrypt' ) ) :
613
  $openssl_ext = new \Bitpay\Crypto\OpenSSLExtension();
614
  $fingerprint = sha1(sha1(__DIR__));
615
 
616
- if (true === isset($fingerprint) &&
617
- true === isset($openssl_ext) &&
618
- strlen($fingerprint) > 24)
619
- {
620
  $fingerprint = substr($fingerprint, 0, 24);
621
 
622
  if (false === isset($fingerprint) || true === empty($fingerprint)) {
@@ -634,16 +661,18 @@ if ( ! function_exists( 'buycred_bitpay_encrypt' ) ) :
634
  wp_die('Invalid server fingerprint generated');
635
  }
636
 
637
- }
638
  endif;
639
 
640
  /**
641
  * Bitpay Decrypt
642
- * @since 1.8
 
643
  * @version 1.0
644
  */
645
- if ( ! function_exists( 'buycred_bitpay_decrypt' ) ) :
646
- function buycred_bitpay_decrypt( $encrypted ) {
 
647
 
648
  if (false === isset($encrypted) || true === empty($encrypted)) {
649
  throw new \Exception('The Bitpay payment plugin was called to decrypt data but no data was passed!');
@@ -652,10 +681,10 @@ if ( ! function_exists( 'buycred_bitpay_decrypt' ) ) :
652
 
653
  $fingerprint = sha1(sha1(__DIR__));
654
 
655
- if (true === isset($fingerprint) &&
656
- true === isset($openssl_ext) &&
657
- strlen($fingerprint) > 24)
658
- {
659
  $fingerprint = substr($fingerprint, 0, 24);
660
 
661
  if (false === isset($fingerprint) || true === empty($fingerprint)) {
@@ -680,5 +709,5 @@ if ( ! function_exists( 'buycred_bitpay_decrypt' ) ) :
680
  wp_die('Invalid server fingerprint generated');
681
  }
682
 
683
- }
684
  endif;
1
  <?php
2
+ if (! defined('myCRED_VERSION') ) { exit;
3
+ }
4
 
5
  /**
6
  * Load BitPay PHP Library
7
+ *
8
+ * @since 1.8
9
  * @version 1.0
10
  */
11
+ if (! class_exists('WC_Gateway_Bitpay') ) {
12
 
13
+ $autoloader_param = __DIR__ . '/Bitpay/Autoloader.php';
14
 
15
+ // Load up the BitPay library
16
+ if (true === file_exists($autoloader_param) && true === is_readable($autoloader_param) ) {
17
 
18
+ include_once $autoloader_param;
19
+ \Bitpay\Autoloader::register();
20
 
21
+ }
22
 
23
+ // Exist for quirks in object serialization...
24
+ if (false === class_exists('PrivateKey') ) {
25
+ include_once __DIR__ . '/Bitpay/PrivateKey.php';
26
+ }
27
 
28
+ if (false === class_exists('PublicKey') ) {
29
+ include_once __DIR__ . '/Bitpay/PublicKey.php';
30
+ }
31
 
32
+ if (false === class_exists('Token') ) {
33
+ include_once __DIR__ . '/Bitpay/Token.php';
34
+ }
35
 
36
  }
37
 
38
  /**
39
  * myCRED_Bitpay class
40
  * BitPay (Bitcoins) - Payment Gateway
41
+ *
42
+ * @since 1.4
43
  * @version 1.2
44
  */
45
+ if (! class_exists('myCRED_Bitpay') ) :
46
+ class myCRED_Bitpay extends myCRED_Payment_Gateway
47
+ {
48
+
49
+ /**
50
+ * Construct
51
+ */
52
+ public function __construct( $gateway_prefs )
53
+ {
 
 
 
54
 
55
+ $types = mycred_get_types();
56
+ $default_exchange = array();
57
+ foreach ( $types as $type => $label ) {
58
+ $default_exchange[ $type ] = 1;
59
+ }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
60
 
61
+ parent::__construct(
62
+ array(
63
+ 'id' => 'bitpay',
64
+ 'label' => 'Bitpay',
65
+ 'gateway_logo_url' => plugins_url('assets/images/bitpay.png', MYCRED_PURCHASE),
66
+ 'defaults' => array(
67
+ 'sandbox' => 0,
68
+ 'api_public' => '',
69
+ 'api_secret' => '',
70
+ 'api_sign' => '',
71
+ 'api_token' => '',
72
+ 'api_label' => '',
73
+ 'currency' => 'USD',
74
+ 'exchange' => $default_exchange,
75
+ 'item_name' => 'Purchase of myCRED %plural%',
76
+ 'logo_url' => '',
77
+ 'speed' => 'high',
78
+ 'notifications' => 1
79
+ )
80
+ ), $gateway_prefs
81
+ );
82
+
83
+ $this->is_ready = false;
84
+ if (isset($this->prefs['api_public']) && ! empty($this->prefs['api_public']) && isset($this->prefs['api_secret']) && ! empty($this->prefs['api_secret']) ) {
85
+ $this->is_ready = true;
86
+ }
87
 
88
+ }
89
 
90
+ /**
91
+ * Process
92
+ *
93
+ * @since 1.4
94
+ * @version 1.2
95
+ */
96
+ public function process()
97
+ {
98
 
99
+ $post = file_get_contents("php://input");
100
+ if (! empty($post) ) {
101
 
102
+ $new_call = array();
103
+ $json = json_decode($post, true);
104
+ if (! empty($json) && array_key_exists('id', $json) && array_key_exists('url', $json) ) {
105
 
106
+ try {
107
 
108
+ $client = new \Bitpay\Client\Client();
109
+ if (false === strpos($json['url'], 'test') ) {
110
+ $network = new \Bitpay\Network\Livenet();
111
+ } else {
112
+ $network = new \Bitpay\Network\Testnet();
113
+ }
114
 
115
+ $client->setNetwork($network);
116
+ $curlAdapter = new \Bitpay\Client\Adapter\CurlAdapter();
117
+ $client->setAdapter($curlAdapter);
118
 
119
+ $client->setPrivateKey(buycred_bitpay_decrypt($this->prefs['api_secret']));
120
+ $client->setPublicKey(buycred_bitpay_decrypt($this->prefs['api_public']));
121
+ $client->setToken(buycred_bitpay_decrypt($this->prefs['api_token']));
122
 
123
+ $invoice = $client->getInvoice($json['id']);
124
 
125
+ } catch ( \Exception $e ) {
126
 
127
+ $new_call[] = $e->getMessage();
128
 
129
+ }
130
 
131
+ if (empty($new_call) ) {
132
 
133
+ $transaction_id = $invoice->getOrderId();
134
+ $pending_post_id = buycred_get_pending_payment_id($transaction_id);
135
+ $pending_payment = $this->get_pending_payment($pending_post_id);
136
 
137
+ if ($pending_payment !== false ) {
138
 
139
+ // If account is credited, delete the post and it's comments.
140
+ if ($this->complete_payment($pending_payment, $json['id']) ) {
141
+ $this->trash_pending_payment($pending_post_id);
142
+ } else {
143
+ $new_call[] = __('Failed to credit users account.', 'mycred');
144
+ }
145
 
146
+ // Log Call
147
+ if (! empty($new_call) ) {
148
+ $this->log_call($pending_post_id, $new_call);
149
+ }
150
 
151
+ }
152
 
153
+ }
154
 
155
+ }
156
 
157
+ }
158
 
159
+ }
160
 
161
+ /**
162
+ * Returning
163
+ *
164
+ * @since 1.4
165
+ * @version 1.0
166
+ */
167
+ public function returning()
168
+ {
169
+ }
170
 
171
+ /**
172
+ * Admin Init Handler
173
+ *
174
+ * @since 1.8
175
+ * @version 1.0
176
+ */
177
+ public function admin_init()
178
+ {
179
 
180
+ add_action('wp_ajax_buycred-bitpay-pairing', array( $this, 'ajax_pair' ));
181
 
182
+ }
183
 
184
+ /**
185
+ * AJAX: Pair with bitPay
186
+ *
187
+ * @since 1.8
188
+ * @version 1.0
189
+ */
190
+ public function ajax_pair()
191
+ {
192
 
193
+ check_ajax_referer('buycred-pair-bitpay', 'token');
194
 
195
+ $pairing_code = sanitize_text_field($_POST['code']);
196
+ $network = sanitize_text_field($_POST['network']);
197
 
198
+ try {
199
 
200
+ $key = new \Bitpay\PrivateKey();
201
+ $key->generate();
202
 
203
+ $pub = new \Bitpay\PublicKey();
204
+ $pub->setPrivateKey($key);
205
+ $pub->generate();
206
 
207
+ $sin = new \Bitpay\SinKey();
208
+ $sin->setPublicKey($pub);
209
+ $sin->generate();
210
 
211
+ $client = new \Bitpay\Client\Client();
212
 
213
+ if ($network === 'live' ) {
214
+ $client->setNetwork(new \Bitpay\Network\Livenet());
215
+ } else {
216
+ $client->setNetwork(new \Bitpay\Network\Testnet());
217
+ }
218
 
219
+ $curlAdapter = new \Bitpay\Client\Adapter\CurlAdapter();
220
 
221
+ $client->setAdapter($curlAdapter);
222
+ $client->setPrivateKey($key);
223
+ $client->setPublicKey($pub);
224
 
225
+ } catch ( \Exception $e ) {
226
+ wp_send_json_error($e->getMessage());
227
+ }
228
 
229
+ $label = preg_replace('/[^a-zA-Z0-9 \-\_\.]/', '', get_bloginfo());
230
+ $label = substr('buyCRED - ' . $label, 0, 59);
231
 
232
+ try {
233
 
234
+ $token = $client->createToken(
235
+ array(
236
+ 'id' => (string) $sin,
237
+ 'pairingCode' => $pairing_code,
238
+ 'label' => $label,
239
+ )
240
+ );
241
 
242
+ } catch ( \Exception $e ) {
243
 
244
+ wp_send_json_error($e->getMessage());
245
 
246
+ }
247
 
248
+ if ($network !== 'live' ) {
249
+ $label .= ' (Testnet)';
250
+ }
251
 
252
+ wp_send_json_success(
253
+ array(
254
+ 'api_secret' => '<input type="hidden" name="' . $this->field_name('api_secret') . '" value="' . buycred_bitpay_encrypt($key) . '" />',
255
+ 'api_public' => '<input type="hidden" name="' . $this->field_name('api_public') . '" value="' . buycred_bitpay_encrypt($pub) . '" />',
256
+ 'api_sign' => '<input type="hidden" name="' . $this->field_name('api_sign') . '" value="' . (string) $sin . '" />',
257
+ 'api_token' => '<input type="hidden" name="' . $this->field_name('api_token') . '" value="' . buycred_bitpay_encrypt($token) . '" />',
258
+ 'label' => '<input type="hidden" name="' . $this->field_name('api_label') . '" value="' . $label . '" /><p class="form-control-static">' . $label . '</p>'
259
+ )
260
+ );
261
 
262
+ }
263
 
264
+ /**
265
+ * Prep Sale
266
+ *
267
+ * @since 1.8
268
+ * @version 1.0
269
+ */
270
+ public function prep_sale( $new_transaction = false )
271
+ {
272
 
273
+ // Set currency
274
+ $this->currency = ( $this->currency == '' ) ? $this->prefs['currency'] : $this->currency;
275
 
276
+ //Set Cost in raw format
277
+ $this->cost = $this->get_cost($this->amount, $this->point_type, true);
278
 
279
+ // Item Name
280
+ $item_name = str_replace('%number%', $this->amount, $this->prefs['item_name']);
281
+ $item_name = $this->core->template_tags_general($item_name);
282
 
283
+ $user = get_userdata($this->buyer_id);
284
 
285
+ // Based on the "BitPay for WooCommerce" plugin issued by Bitpay
286
+ try {
287
 
288
+ // Currency
289
+ $currency = new \Bitpay\Currency($this->currency);
290
 
291
+ // First, we set the client
292
+ $client = new \Bitpay\Client\Client();
293
 
294
+ if (! $this->sandbox_mode ) {
295
+ $client->setNetwork(new \Bitpay\Network\Livenet());
296
+ } else {
297
+ $client->setNetwork(new \Bitpay\Network\Testnet());
298
+ }
299
 
300
+ $curlAdapter = new \Bitpay\Client\Adapter\CurlAdapter();
301
+ $client->setAdapter($curlAdapter);
302
 
303
+ $client->setPrivateKey(buycred_bitpay_decrypt($this->prefs['api_secret']));
304
+ $client->setPublicKey(buycred_bitpay_decrypt($this->prefs['api_public']));
305
+ $client->setToken(buycred_bitpay_decrypt($this->prefs['api_token']));
306
 
307
+ // Next, we create an invoice object
308
+ $invoice = new \Bitpay\Invoice();
309
+ $invoice->setOrderId((string) $this->transaction_id);
310
+ $invoice->setCurrency($currency);
311
+ $invoice->setFullNotifications(( ( $this->prefs['notifications'] ) ? true : false ));
312
 
313
+ // Next, we set the invoice item
314
+ $item = new \Bitpay\Item();
315
+ $item->setPrice($this->cost);
316
+ $item->setDescription($item_name);
317
 
318
+ // This includes setting the buyer
319
+ $buyer = new \Bitpay\Buyer();
320
+ $buyer->setEmail($user->user_email);
321
 
322
+ $invoice->setBuyer($buyer);
323
+ $invoice->setItem($item);
324
 
325
+ // Append extras
326
+ $invoice->setRedirectUrl($this->get_thankyou());
327
+ $invoice->setNotificationUrl($this->callback_url());
328
+ $invoice->setTransactionSpeed($this->prefs['speed']);
329
 
330
+ // Create an invoice
331
+ $invoice = $client->createInvoice($invoice);
332
 
333
+ } catch ( \Exception $e ) {
334
 
335
+ $this->errors[] = $e->getMessage();
336
 
337
+ }
338
 
339
+ if (empty($this->errors) ) {
340
 
341
+ $this->redirect_to = $invoice->getUrl();
342
 
343
+ }
344
 
345
+ }
346
 
347
+ /**
348
+ * AJAX Buy Handler
349
+ *
350
+ * @since 1.8
351
+ * @version 1.0
352
+ */
353
+ public function ajax_buy()
354
+ {
355
 
356
+ // Construct the checkout box content
357
+ $content = $this->checkout_header();
358
+ $content .= $this->checkout_logo();
359
+ $content .= $this->checkout_order();
360
+ $content .= $this->checkout_cancel();
361
+ $content .= $this->checkout_footer();
362
 
363
+ // Return a JSON response
364
+ $this->send_json($content);
365
 
366
+ }
367
 
368
+ /**
369
+ * Checkout Page Body
370
+ * This gateway only uses the checkout body.
371
+ *
372
+ * @since 1.8
373
+ * @version 1.0
374
+ */
375
+ public function checkout_page_body()
376
+ {
377
 
378
+ echo $this->checkout_header();
379
+ echo $this->checkout_logo(false);
380
 
381
+ echo $this->checkout_order();
382
+ echo $this->checkout_cancel();
383
 
384
+ echo $this->checkout_footer();
385
 
386
+ }
387
 
388
+ /**
389
+ * Gateway Prefs
390
+ *
391
+ * @since 1.4
392
+ * @version 1.0
393
+ */
394
+ function preferences()
395
+ {
396
 
397
+ $prefs = $this->prefs;
398
 
399
+ ?>
400
  <div class="row">
401
+ <div class="col-lg-6 col-md-6 col-sm-12 col-xs-12">
402
+ <h3><?php _e('Details', 'mycred'); ?></h3>
403
+
404
+ <?php if (! $this->is_ready ) : ?>
405
+
406
+ <div class="form-group">
407
+ <label><?php _e('API Token', 'mycred'); ?></label>
408
+ <div class="form-inline" id="bitpay-pairing-wrapper">
409
+ <input type="text" id="bitpay-pair-code" class="form-control" placeholder="Pairing Code" value="" />
410
+ <select id="bitpay-pair-network" class="form-control">
411
+ <option value="live">Livenet</option>
412
+ <option value="test">Testnet</option>
413
+ </select>
414
+ <button type="button" id="sync-bitpay-pairing-code" class="button button-secondary">Sync</button>
415
+ </div>
416
+ <p class="description bitpay-link" id="bitpay-link-live"><span>Get a pairing code: <a href="https://bitpay.com/api-tokens" target="_blank">https://bitpay.com/api-tokens</a></span></p>
417
+ <p class="description bitpay-link" id="bitpay-link-test" style="display: none;"><span>Get a pairing code: <a href="https://test.bitpay.com/api-tokens" target="_blank">https://test.bitpay.com/api-tokens</a></span></p>
418
+ </div>
419
  <script type="text/javascript">
420
  jQuery(function($){
421
 
422
+ $( '#sync-bitpay-pairing-code' ).click(function(e){
423
 
424
+ e.preventDefault();
425
 
426
+ var pairwrapper = $( '#bitpay-pairing-wrapper' );
427
 
428
+ $.ajax({
429
+ type : "POST",
430
+ data : {
431
+ action : 'buycred-bitpay-pairing',
432
+ token : '<?php echo wp_create_nonce('buycred-pair-bitpay'); ?>',
433
+ code : $( '#bitpay-pair-code' ).val(),
434
+ network : $( '#bitpay-pair-network' ).find( ':selected' ).val(),
435
+ },
436
+ dataType : "JSON",
437
+ url : '<?php echo admin_url('admin-ajax.php'); ?>',
438
+ beforeSend : function() {
439
 
440
+ $( '#sync-bitpay-pairing-code' ).attr( 'disabled', 'disabled' );
441
 
442
+ },
443
+ success : function( response ) {
444
 
445
+ if ( response.success ) {
446
 
447
+ pairwrapper.slideUp(function(){
448
+ pairwrapper.empty();
449
+ $.each( response.data, function(index,element){
450
+ pairwrapper.append( element );
451
+ });
452
+ pairwrapper.slideDown();
453
+ });
454
 
455
+ }
456
+ else {
457
 
458
+ alert( response.data );
459
+ $( '#sync-bitpay-pairing-code' ).removeAttr( 'disabled' );
460
 
461
+ }
462
 
463
+ },
464
+ error : function() {
465
+ alert( 'Communications Error' );
466
+ }
467
+ });
468
 
469
+ });
470
 
471
+ $( '#bitpay-pair-network' ).change(function(){
472
 
473
+ $( '.bitpay-link' ).hide();
474
+ var selectedmode = $(this).find( ':selected' );
475
+ $( '#bitpay-link-' + selectedmode.val() ).show();
476
 
477
+ });
478
 
479
  });
480
  </script>
481
 
482
+ <?php else : ?>
483
+
484
+ <div class="form-group">
485
+ <label><?php _e('API Token', 'mycred'); ?></label>
486
+ <p class="form-control-static"><?php echo esc_attr($prefs['api_label']); ?></p>
487
+ <button type="button" id="bitpay-cancel-pair" class="button button-secondary">Revoke Token</button>
488
+ <input type="hidden" class="reset-api" name="<?php echo $this->field_name('api_secret'); ?>" value="<?php echo esc_attr($prefs['api_secret']); ?>" />
489
+ <input type="hidden" class="reset-api" name="<?php echo $this->field_name('api_public'); ?>" value="<?php echo esc_attr($prefs['api_public']); ?>" />
490
+ <input type="hidden" class="reset-api" name="<?php echo $this->field_name('api_sign'); ?>" value="<?php echo esc_attr($prefs['api_sign']); ?>" />
491
+ <input type="hidden" class="reset-api" name="<?php echo $this->field_name('api_token'); ?>" value="<?php echo esc_attr($prefs['api_token']); ?>" />
492
+ <input type="hidden" class="reset-api" name="<?php echo $this->field_name('api_label'); ?>" value="<?php echo esc_attr($prefs['api_label']); ?>" />
493
+ </div>
494
  <script type="text/javascript">
495
  jQuery(function($){
496
 
497
+ $( '#bitpay-cancel-pair' ).click(function(e){
498
 
499
+ e.preventDefault();
500
 
501
+ if ( confirm( '<?php echo esc_js(esc_attr(__('Are you sure you want to do this?', 'mycred'))); ?>' ) ) {
502
 
503
+ $( 'input.reset-api' ).val( '' );
504
+ $(this).before().html( '<?php echo esc_js(__('Removed - Remember to save your changes.', 'mycred')); ?>' );
505
 
506
+ }
507
 
508
+ });
509
 
510
  });
511
  </script>
512
 
513
+ <?php endif; ?>
514
+
515
+ <div class="form-group">
516
+ <label for="<?php echo $this->field_id('item_name'); ?>"><?php _e('Item Name', 'mycred'); ?></label>
517
+ <input type="text" name="<?php echo $this->field_name('item_name'); ?>" id="<?php echo $this->field_id('item_name'); ?>" value="<?php echo esc_attr($prefs['item_name']); ?>" class="form-control" />
518
+ </div>
519
+ <div class="form-group">
520
+ <label for="<?php echo $this->field_id('logo_url'); ?>"><?php _e('Logo URL', 'mycred'); ?></label>
521
+ <input type="text" name="<?php echo $this->field_name('logo_url'); ?>" id="<?php echo $this->field_id('logo_url'); ?>" value="<?php echo esc_attr($prefs['logo_url']); ?>" class="form-control" />
522
+ </div>
523
+ <div class="row">
524
+ <div class="col-lg-6 col-md-6 col-sm-12 col-xs-12">
525
+ <div class="form-group">
526
+ <label for="<?php echo $this->field_id('speed'); ?>"><?php _e('Transaction Speed', 'mycred'); ?></label>
527
+ <select name="<?php echo $this->field_name('speed'); ?>" id="<?php echo $this->field_id('speed'); ?>" class="form-control">
528
+ <?php
529
+ $options = array(
530
+ 'high' => __('High', 'mycred'),
531
+ 'medium' => __('Medium', 'mycred'),
532
+ 'low' => __('Low', 'mycred')
533
+ );
534
+ foreach ( $options as $value => $label ) :?>
535
+ <option value="<?php echo esc_attr($value);?>" <?php selected($prefs['speed'], $value);?>><?php echo esc_html($label);?></option>
536
+ <?php endforeach;?>
537
+ </select>
538
+ </div>
539
+ </div>
540
+ <div class="col-lg-6 col-md-6 col-sm-12 col-xs-12">
541
+ <div class="form-group">
542
+ <label for="<?php echo $this->field_id('notifications'); ?>"><?php _e('Full Notifications', 'mycred'); ?></label>
543
+ <select name="<?php echo $this->field_name('notifications'); ?>" id="<?php echo $this->field_id('notifications'); ?>" class="form-control">
544
+ <?php
545
+ $options = array(
546
+ 0 => __('No', 'mycred'),
547
+ 1 => __('Yes', 'mycred')
548
+ );
549
+ foreach ( $options as $value => $label ) :?>
550
+ <option value="<?php echo esc_attr($value);?>" <?php selected($prefs['notifications'], $value);?>><?php echo esc_html($label);?></option>
551
+ <?php endforeach;?>
552
+ </select>
553
+ </div>
554
+ </div>
555
+ </div>
556
+ </div>
557
+ <div class="col-lg-6 col-md-6 col-sm-12 col-xs-12">
558
+ <h3><?php _e('Setup', 'mycred'); ?></h3>
559
+ <div class="form-group">
560
+ <label for="<?php echo $this->field_id('currency'); ?>"><?php _e('Currency', 'mycred'); ?></label>
561
+ <input type="text" name="<?php echo $this->field_name('currency'); ?>" id="<?php echo $this->field_id('currency'); ?>" value="<?php echo $prefs['currency']; ?>" class="form-control" maxlength="3" placeholder="<?php _e('Currency Code', 'mycred'); ?>" />
562
+
563
+ </div>
564
+ <div class="form-group">
565
+ <label><?php _e('Exchange Rates', 'mycred'); ?></label>
566
+
567
+ <?php $this->exchange_rate_setup(); ?>
568
+
569
+ </div>
570
+ </div>
571
+ </div>
572
+ <?php
573
 
574
+ }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
575
 
576
+ /**
577
+ * Sanatize Prefs
578
+ *
579
+ * @since 1.4
580
+ * @version 1.2
581
+ */
582
+ public function sanitise_preferences( $data )
583
+ {
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
584
 
585
+ $new_data = array();
586
+
587
+ if (array_key_exists('api_secret', $data) ) {
588
+ $new_data['api_secret'] = sanitize_text_field($data['api_secret']);
589
+ $new_data['api_public'] = sanitize_text_field($data['api_public']);
590
+ $new_data['api_sign'] = sanitize_text_field($data['api_sign']);
591
+ $new_data['api_token'] = sanitize_text_field($data['api_token']);
592
+ $new_data['api_label'] = sanitize_text_field($data['api_label']);
593
+ }
594
+ else {
595
+ $new_data['api_secret'] = '';
596
+ $new_data['api_public'] = '';
597
+ $new_data['api_sign'] = '';
598
+ $new_data['api_token'] = '';
599
+ $new_data['api_label'] = '';
600
+ }
601
+
602
+ $new_data['sandbox'] = ( isset($data['sandbox']) ) ? 1 : 0;
603
+ $new_data['currency'] = sanitize_text_field($data['currency']);
604
+ $new_data['item_name'] = sanitize_text_field($data['item_name']);
605
+ $new_data['logo_url'] = sanitize_text_field($data['logo_url']);
606
+ $new_data['speed'] = sanitize_text_field($data['speed']);
607
+ $new_data['notifications'] = sanitize_text_field($data['notifications']);
608
+
609
+ // If exchange is less then 1 we must start with a zero
610
+ if (isset($data['exchange']) ) {
611
+ foreach ( (array) $data['exchange'] as $type => $rate ) {
612
+ if ($rate != 1 && in_array(substr($rate, 0, 1), array( '.', ',' )) ) {
613
+ $data['exchange'][ $type ] = (float) '0' . $rate;
614
+ }
615
+ }
616
+ }
617
+ $new_data['exchange'] = $data['exchange'];
618
+
619
+ return $new_data;
620
+
621
+ }
622
+
623
+ }
 
 
 
 
 
 
 
 
624
  endif;
625
 
626
  /**
627
  * Bitpay Encrypt
628
+ *
629
+ * @since 1.8
630
  * @version 1.0
631
  */
632
+ if (! function_exists('buycred_bitpay_encrypt') ) :
633
+ function buycred_bitpay_encrypt( $data )
634
+ {
635
 
636
  if (false === isset($data) || true === empty($data)) {
637
  throw new \Exception('The Bitpay payment plugin was called to encrypt data but no data was passed!');
640
  $openssl_ext = new \Bitpay\Crypto\OpenSSLExtension();
641
  $fingerprint = sha1(sha1(__DIR__));
642
 
643
+ if (true === isset($fingerprint)
644
+ && true === isset($openssl_ext)
645
+ && strlen($fingerprint) > 24
646
+ ) {
647
  $fingerprint = substr($fingerprint, 0, 24);
648
 
649
  if (false === isset($fingerprint) || true === empty($fingerprint)) {
661
  wp_die('Invalid server fingerprint generated');
662
  }
663
 
664
+ }
665
  endif;
666
 
667
  /**
668
  * Bitpay Decrypt
669
+ *
670
+ * @since 1.8
671
  * @version 1.0
672
  */
673
+ if (! function_exists('buycred_bitpay_decrypt') ) :
674
+ function buycred_bitpay_decrypt( $encrypted )
675
+ {
676
 
677
  if (false === isset($encrypted) || true === empty($encrypted)) {
678
  throw new \Exception('The Bitpay payment plugin was called to decrypt data but no data was passed!');
681
 
682
  $fingerprint = sha1(sha1(__DIR__));
683
 
684
+ if (true === isset($fingerprint)
685
+ && true === isset($openssl_ext)
686
+ && strlen($fingerprint) > 24
687
+ ) {
688
  $fingerprint = substr($fingerprint, 0, 24);
689
 
690
  if (false === isset($fingerprint) || true === empty($fingerprint)) {
709
  wp_die('Invalid server fingerprint generated');
710
  }
711
 
712
+ }
713
  endif;
addons/buy-creds/gateways/index.php CHANGED
@@ -1,3 +1,3 @@
1
  <?php
2
  // Silence is golden.
3
- ?>
1
  <?php
2
  // Silence is golden.
3
+ ?>
addons/buy-creds/gateways/netbilling.php CHANGED
@@ -1,297 +1,326 @@
1
  <?php
2
- if ( ! defined( 'myCRED_VERSION' ) ) exit;
 
3
 
4
  /**
5
  * myCRED_NETbilling class
6
  * NETbilling Payment Gateway
7
- * @see http://secure.netbilling.com/public/docs/merchant/public/directmode/directmode3protocol.html
8
- * @since 0.1
 
9
  * @version 1.3
10
  */
11
- if ( ! class_exists( 'myCRED_NETbilling' ) ) :
12
- class myCRED_NETbilling extends myCRED_Payment_Gateway {
13
-
14
- protected $http_code = '';
15
-
16
- /**
17
- * Construct
18
- */
19
- public function __construct( $gateway_prefs ) {
20
-
21
- global $netbilling_errors;
22
-
23
- $types = mycred_get_types();
24
- $default_exchange = array();
25
- foreach ( $types as $type => $label )
26
- $default_exchange[ $type ] = 1;
27
-
28
- parent::__construct( array(
29
- 'id' => 'netbilling',
30
- 'label' => 'NETbilling',
31
- 'gateway_logo_url' => plugins_url( 'assets/images/netbilling.png', MYCRED_PURCHASE ),
32
- 'defaults' => array(
33
- 'sandbox' => 0,
34
- 'account' => '',
35
- 'site_tag' => '',
36
- 'item_name' => 'Purchase of myCRED %plural%',
37
- 'exchange' => $default_exchange,
38
- 'logo_url' => '',
39
- 'cryptokey' => '',
40
- 'currency' => 'USD'
41
- )
42
- ), $gateway_prefs );
43
-
44
- }
45
-
46
- /**
47
- * IPN - Is Valid Call
48
- * Replaces the default check
49
- * @since 1.4
50
- * @version 1.0
51
- */
52
- public function IPN_is_valid_call() {
53
-
54
- $result = true;
55
-
56
- // Accounts Match
57
- $account = explode( ':', $_REQUEST['Ecom_Ezic_AccountAndSitetag'] );
58
- if ( $account[0] != $this->prefs['account'] || $account[1] != $this->prefs['site_tag'] )
59
- $result = false;
60
-
61
- // Crypto Check
62
- $crypto_check = md5( $this->prefs['cryptokey'] . $_REQUEST['Ecom_Cost_Total'] . $_REQUEST['Ecom_Receipt_Description'] );
63
- if ( $crypto_check != $_REQUEST['Ecom_Ezic_Security_HashValue_MD5'] )
64
- $result = false;
65
-
66
- return $result;
67
-
68
- }
69
-
70
- /**
71
- * Process
72
- * @since 0.1
73
- * @version 1.2
74
- */
75
- public function process() {
76
-
77
- // Required fields
78
- if ( isset( $_REQUEST['Ecom_UserData_salesdata'] ) && isset( $_REQUEST['Ecom_Ezic_Response_TransactionID'] ) && isset( $_REQUEST['Ecom_Cost_Total'] ) ) {
79
-
80
- // Get Pending Payment
81
- $pending_post_id = sanitize_key( $_REQUEST['Ecom_UserData_salesdata'] );
82
- $pending_payment = $this->get_pending_payment( $pending_post_id );
83
- if ( $pending_payment !== false ) {
84
-
85
- // Verify Call with PayPal
86
- if ( $this->IPN_is_valid_call() ) {
87
-
88
- $errors = false;
89
- $new_call = array();
90
-
91
- // Check amount paid
92
- if ( $_REQUEST['Ecom_Cost_Total'] != $pending_payment->cost ) {
93
- $new_call[] = sprintf( __( 'Price mismatch. Expected: %s Received: %s', 'mycred' ), $pending_payment->cost, $_REQUEST['Ecom_Cost_Total'] );
94
- $errors = true;
95
- }
96
-
97
- // Check status
98
- if ( $_REQUEST['Ecom_Ezic_Response_StatusCode'] != 1 ) {
99
- $new_call[] = sprintf( __( 'Payment not completed. Received: %s', 'mycred' ), $_REQUEST['Ecom_Ezic_Response_StatusCode'] );
100
- $errors = true;
101
- }
102
-
103
- // Credit payment
104
- if ( $errors === false ) {
105
-
106
- // If account is credited, delete the post and it's comments.
107
- if ( $this->complete_payment( $pending_payment, $_REQUEST['Ecom_Ezic_Response_TransactionID'] ) )
108
- $this->trash_pending_payment( $pending_post_id );
109
- else
110
- $new_call[] = __( 'Failed to credit users account.', 'mycred' );
111
-
112
- }
113
-
114
- // Log Call
115
- if ( ! empty( $new_call ) )
116
- $this->log_call( $pending_post_id, $new_call );
117
-
118
- }
119
-
120
- }
121
-
122
- }
123
-
124
- }
125
-
126
- /**
127
- * Returns
128
- * @since 0.1
129
- * @version 1.1
130
- */
131
- public function returning() {
132
-
133
- if ( isset( $_REQUEST['Ecom_Ezic_AccountAndSitetag'] ) && isset( $_REQUEST['Ecom_UserData_salesdata'] ) )
134
- $this->process();
135
-
136
- }
137
-
138
- /**
139
- * Prep Sale
140
- * @since 1.8
141
- * @version 1.0
142
- */
143
- public function prep_sale( $new_transaction = false ) {
144
-
145
- // Set currency
146
- $this->currency = ( $this->currency == '' ) ? $this->prefs['currency'] : $this->currency;
147
-
148
- // The item name
149
- $item_name = str_replace( '%number%', $this->amount, $this->prefs['item_name'] );
150
- $item_name = $this->core->template_tags_general( $item_name );
151
-
152
- // This gateway redirects, so we need to populate redirect_to
153
- $this->redirect_to = 'https://secure.netbilling.com/gw/native/interactive2.2';
154
-
155
- // Transaction variables that needs to be submitted
156
- $this->redirect_fields = array(
157
- 'Ecom_Ezic_AccountAndSitetag' => $this->prefs['account'] . ':' . $this->prefs['site_tag'],
158
- 'Ecom_Ezic_Payment_AuthorizationType' => 'SALE',
159
- 'Ecom_Receipt_Description' => $item_name,
160
- 'Ecom_Ezic_Fulfillment_ReturnMethod' => 'POST',
161
- 'Ecom_Cost_Total' => $this->cost,
162
- 'Ecom_UserData_salesdata' => $this->transaction_id,
163
- 'Ecom_Ezic_Fulfillment_ReturnURL' => $this->get_thankyou(),
164
- 'Ecom_Ezic_Fulfillment_GiveUpURL' => $this->get_cancelled( $this->transaction_id ),
165
- 'Ecom_Ezic_Security_HashValue_MD5' => md5( $this->prefs['cryptokey'] . $this->cost . $item_name ),
166
- 'Ecom_Ezic_Security_HashFields' => 'Ecom_Cost_Total Ecom_Receipt_Description'
167
- );
168
-
169
- }
170
-
171
- /**
172
- * AJAX Buy Handler
173
- * @since 1.8
174
- * @version 1.0
175
- */
176
- public function ajax_buy() {
177
-
178
- // Construct the checkout box content
179
- $content = $this->checkout_header();
180
- $content .= $this->checkout_logo();
181
- $content .= $this->checkout_order();
182
- $content .= $this->checkout_cancel();
183
- $content .= $this->checkout_footer();
184
-
185
- // Return a JSON response
186
- $this->send_json( $content );
187
-
188
- }
189
-
190
- /**
191
- * Checkout Page Body
192
- * This gateway only uses the checkout body.
193
- * @since 1.8
194
- * @version 1.0
195
- */
196
- public function checkout_page_body() {
197
-
198
- echo $this->checkout_header();
199
- echo $this->checkout_logo( false );
200
-
201
- echo $this->checkout_order();
202
- echo $this->checkout_cancel();
203
-
204
- echo $this->checkout_footer();
205
-
206
- }
207
-
208
- /**
209
- * Preferences
210
- * @since 0.1
211
- * @version 1.1
212
- */
213
- public function preferences() {
214
-
215
- $prefs = $this->prefs;
216
-
217
- ?>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
218
  <div class="row">
219
- <div class="col-lg-6 col-md-6 col-sm-12 col-xs-12">
220
- <h3><?php _e( 'Details', 'mycred' ); ?></h3>
221
- <div class="form-group">
222
- <label for="<?php echo $this->field_id( 'account' ); ?>"><?php _e( 'Account ID', 'mycred' ); ?></label>
223
- <input type="text" name="<?php echo $this->field_name( 'account' ); ?>" id="<?php echo $this->field_id( 'account' ); ?>" value="<?php echo esc_attr( $prefs['account'] ); ?>" class="form-control" />
224
- </div>
225
- <div class="form-group">
226
- <label for="<?php echo $this->field_id( 'site_tag' ); ?>"><?php _e( 'Site Tag', 'mycred' ); ?></label>
227
- <input type="text" name="<?php echo $this->field_name( 'site_tag' ); ?>" id="<?php echo $this->field_id( 'site_tag' ); ?>" value="<?php echo esc_attr( $prefs['site_tag'] ); ?>" class="form-control" />
228
- </div>
229
- <div class="form-group">
230
- <label for="<?php echo $this->field_id( 'cryptokey' ); ?>"><?php _e( 'Order Integrity Key', 'mycred' ); ?></label>
231
- <input type="password" name="<?php echo $this->field_name( 'cryptokey' ); ?>" id="<?php echo $this->field_id( 'cryptokey' ); ?>" value="<?php echo esc_attr( $prefs['cryptokey'] ); ?>" class="form-control" />
232
- <p><span class="description"><?php _e( 'Found under Step 12 on the Fraud Defense page.', 'mycred' ); ?></span></p>
233
- </div>
234
- <div class="form-group">
235
- <label for="<?php echo $this->field_id( 'item_name' ); ?>"><?php _e( 'Item Name', 'mycred' ); ?></label>
236
- <input type="text" name="<?php echo $this->field_name( 'item_name' ); ?>" id="<?php echo $this->field_id( 'item_name' ); ?>" value="<?php echo esc_attr( $prefs['item_name'] ); ?>" class="form-control" />
237
- </div>
238
- <div class="form-group">
239
- <label for="<?php echo $this->field_id( 'logo_url' ); ?>"><?php _e( 'Logo URL', 'mycred' ); ?></label>
240
- <input type="text" name="<?php echo $this->field_name( 'logo_url' ); ?>" id="<?php echo $this->field_id( 'logo_url' ); ?>" value="<?php echo esc_attr( $prefs['logo_url'] ); ?>" class="form-control" />
241
- </div>
242
- </div>
243
- <div class="col-lg-6 col-md-6 col-sm-12 col-xs-12">
244
- <h3><?php _e( 'Setup', 'mycred' ); ?></h3>
245
- <div class="form-group">
246
- <label><?php _e( 'Currency', 'mycred' ); ?></label>
247
- <input type="text" readonly="readonly" class="form-control" name="<?php echo $this->field_name( 'currency' ); ?>" value="USD" />
248
- </div>
249
- <div class="form-group">
250
- <label><?php _e( 'Exchange Rates', 'mycred' ); ?></label>
251
-
252
- <?php $this->exchange_rate_setup(); ?>
253
-
254
- </div>
255
- <div class="form-group">
256
- <label><?php _e( 'Postback CGI URL', 'mycred' ); ?></label>
257
- <code style="padding: 12px;display:block;"><?php echo $this->callback_url(); ?></code>
258
- <p><?php _e( 'For this gateway to work, you must login to your NETbilling account and edit your site. Under "Default payment form settings" make sure the Postback CGI URL is set to the above address and "Return method" is set to POST.', 'mycred' ); ?></p>
259
- </div>
260
- </div>
261
  </div>
262
- <?php
263
-
264
- }
265
-
266
- /**
267
- * Sanatize Prefs
268
- * @since 0.1
269
- * @version 1.2
270
- */
271
- public function sanitise_preferences( $data ) {
272
-
273
- $new_data = array();
274
-
275
- $new_data['sandbox'] = ( isset( $data['sandbox'] ) ) ? 1 : 0;
276
- $new_data['account'] = sanitize_text_field( $data['account'] );
277
- $new_data['currency'] = sanitize_text_field( $data['currency'] );
278
- $new_data['site_tag'] = sanitize_text_field( $data['site_tag'] );
279
- $new_data['cryptokey'] = sanitize_text_field( $data['cryptokey'] );
280
- $new_data['item_name'] = sanitize_text_field( $data['item_name'] );
281
- $new_data['logo_url'] = sanitize_text_field( $data['logo_url'] );
282
-
283
- // If exchange is less then 1 we must start with a zero
284
- if ( isset( $data['exchange'] ) ) {
285
- foreach ( (array) $data['exchange'] as $type => $rate ) {
286
- if ( $rate != 1 && in_array( substr( $rate, 0, 1 ), array( '.', ',' ) ) )
287
- $data['exchange'][ $type ] = (float) '0' . $rate;
288
- }
289
- }
290
- $new_data['exchange'] = $data['exchange'];
291
-
292
- return $new_data;
293
-
294
- }
295
-
296
- }
 
 
 
297
  endif;
1
  <?php
2
+ if (! defined('myCRED_VERSION') ) { exit;
3
+ }
4
 
5
  /**
6
  * myCRED_NETbilling class
7
  * NETbilling Payment Gateway
8
+ *
9
+ * @see http://secure.netbilling.com/public/docs/merchant/public/directmode/directmode3protocol.html
10
+ * @since 0.1
11
  * @version 1.3
12
  */
13
+ if (! class_exists('myCRED_NETbilling') ) :
14
+ class myCRED_NETbilling extends myCRED_Payment_Gateway
15
+ {
16
+
17
+ protected $http_code = '';
18
+
19
+ /**
20
+ * Construct
21
+ */
22
+ public function __construct( $gateway_prefs )
23
+ {
24
+
25
+ global $netbilling_errors;
26
+
27
+ $types = mycred_get_types();
28
+ $default_exchange = array();
29
+ foreach ( $types as $type => $label ) {
30
+ $default_exchange[ $type ] = 1;
31
+ }
32
+
33
+ parent::__construct(
34
+ array(
35
+ 'id' => 'netbilling',
36
+ 'label' => 'NETbilling',
37
+ 'gateway_logo_url' => plugins_url('assets/images/netbilling.png', MYCRED_PURCHASE),
38
+ 'defaults' => array(
39
+ 'sandbox' => 0,
40
+ 'account' => '',
41
+ 'site_tag' => '',
42
+ 'item_name' => 'Purchase of myCRED %plural%',
43
+ 'exchange' => $default_exchange,
44
+ 'logo_url' => '',
45
+ 'cryptokey' => '',
46
+ 'currency' => 'USD'
47
+ )
48
+ ), $gateway_prefs
49
+ );
50
+
51
+ }
52
+
53
+ /**
54
+ * IPN - Is Valid Call
55
+ * Replaces the default check
56
+ *
57
+ * @since 1.4
58
+ * @version 1.0
59
+ */
60
+ public function IPN_is_valid_call()
61
+ {
62
+
63
+ $result = true;
64
+
65
+ // Accounts Match
66
+ $account = explode(':', $_REQUEST['Ecom_Ezic_AccountAndSitetag']);
67
+ if ($account[0] != $this->prefs['account'] || $account[1] != $this->prefs['site_tag'] ) {
68
+ $result = false;
69
+ }
70
+
71
+ // Crypto Check
72
+ $crypto_check = md5($this->prefs['cryptokey'] . $_REQUEST['Ecom_Cost_Total'] . $_REQUEST['Ecom_Receipt_Description']);
73
+ if ($crypto_check != $_REQUEST['Ecom_Ezic_Security_HashValue_MD5'] ) {
74
+ $result = false;
75
+ }
76
+
77
+ return $result;
78
+
79
+ }
80
+
81
+ /**
82
+ * Process
83
+ *
84
+ * @since 0.1
85
+ * @version 1.2
86
+ */
87
+ public function process()
88
+ {
89
+
90
+ // Required fields
91
+ if (isset($_REQUEST['Ecom_UserData_salesdata']) && isset($_REQUEST['Ecom_Ezic_Response_TransactionID']) && isset($_REQUEST['Ecom_Cost_Total']) ) {
92
+
93
+ // Get Pending Payment
94
+ $pending_post_id = sanitize_key($_REQUEST['Ecom_UserData_salesdata']);
95
+ $pending_payment = $this->get_pending_payment($pending_post_id);
96
+ if ($pending_payment !== false ) {
97
+
98
+ // Verify Call with PayPal
99
+ if ($this->IPN_is_valid_call() ) {
100
+
101
+ $errors = false;
102
+ $new_call = array();
103
+
104
+ // Check amount paid
105
+ if ($_REQUEST['Ecom_Cost_Total'] != $pending_payment->cost ) {
106
+ $new_call[] = sprintf(__('Price mismatch. Expected: %s Received: %s', 'mycred'), $pending_payment->cost, $_REQUEST['Ecom_Cost_Total']);
107
+ $errors = true;
108
+ }
109
+
110
+ // Check status
111
+ if ($_REQUEST['Ecom_Ezic_Response_StatusCode'] != 1 ) {
112
+ $new_call[] = sprintf(__('Payment not completed. Received: %s', 'mycred'), $_REQUEST['Ecom_Ezic_Response_StatusCode']);
113
+ $errors = true;
114
+ }
115
+
116
+ // Credit payment
117
+ if ($errors === false ) {
118
+
119
+ // If account is credited, delete the post and it's comments.
120
+ if ($this->complete_payment($pending_payment, $_REQUEST['Ecom_Ezic_Response_TransactionID']) ) {
121
+ $this->trash_pending_payment($pending_post_id);
122
+ } else {
123
+ $new_call[] = __('Failed to credit users account.', 'mycred');
124
+ }
125
+
126
+ }
127
+
128
+ // Log Call
129
+ if (! empty($new_call) ) {
130
+ $this->log_call($pending_post_id, $new_call);
131
+ }
132
+
133
+ }
134
+
135
+ }
136
+
137
+ }
138
+
139
+ }
140
+
141
+ /**
142
+ * Returns
143
+ *
144
+ * @since 0.1
145
+ * @version 1.1
146
+ */
147
+ public function returning()
148
+ {
149
+
150
+ if (isset($_REQUEST['Ecom_Ezic_AccountAndSitetag']) && isset($_REQUEST['Ecom_UserData_salesdata']) ) {
151
+ $this->process();
152
+ }
153
+
154
+ }
155
+
156
+ /**
157
+ * Prep Sale
158
+ *
159
+ * @since 1.8
160
+ * @version 1.0
161
+ */
162
+ public function prep_sale( $new_transaction = false )
163
+ {
164
+
165
+ // Set currency
166
+ $this->currency = ( $this->currency == '' ) ? $this->prefs['currency'] : $this->currency;
167
+
168
+ // The item name
169
+ $item_name = str_replace('%number%', $this->amount, $this->prefs['item_name']);
170
+ $item_name = $this->core->template_tags_general($item_name);
171
+
172
+ // This gateway redirects, so we need to populate redirect_to
173
+ $this->redirect_to = 'https://secure.netbilling.com/gw/native/interactive2.2';
174
+
175
+ // Transaction variables that needs to be submitted
176
+ $this->redirect_fields = array(
177
+ 'Ecom_Ezic_AccountAndSitetag' => $this->prefs['account'] . ':' . $this->prefs['site_tag'],
178
+ 'Ecom_Ezic_Payment_AuthorizationType' => 'SALE',
179
+ 'Ecom_Receipt_Description' => $item_name,
180
+ 'Ecom_Ezic_Fulfillment_ReturnMethod' => 'POST',
181
+ 'Ecom_Cost_Total' => $this->cost,
182
+ 'Ecom_UserData_salesdata' => $this->transaction_id,
183
+ 'Ecom_Ezic_Fulfillment_ReturnURL' => $this->get_thankyou(),
184
+ 'Ecom_Ezic_Fulfillment_GiveUpURL' => $this->get_cancelled($this->transaction_id),
185
+ 'Ecom_Ezic_Security_HashValue_MD5' => md5($this->prefs['cryptokey'] . $this->cost . $item_name),
186
+ 'Ecom_Ezic_Security_HashFields' => 'Ecom_Cost_Total Ecom_Receipt_Description'
187
+ );
188
+
189
+ }
190
+
191
+ /**
192
+ * AJAX Buy Handler
193
+ *
194
+ * @since 1.8
195
+ * @version 1.0
196
+ */
197
+ public function ajax_buy()
198
+ {
199
+
200
+ // Construct the checkout box content
201
+ $content = $this->checkout_header();
202
+ $content .= $this->checkout_logo();
203
+ $content .= $this->checkout_order();
204
+ $content .= $this->checkout_cancel();
205
+ $content .= $this->checkout_footer();
206
+
207
+ // Return a JSON response
208
+ $this->send_json($content);
209
+
210
+ }
211
+
212
+ /**
213
+ * Checkout Page Body
214
+ * This gateway only uses the checkout body.
215
+ *
216
+ * @since 1.8
217
+ * @version 1.0
218
+ */
219
+ public function checkout_page_body()
220
+ {
221
+
222
+ echo $this->checkout_header();
223
+ echo $this->checkout_logo(false);
224
+
225
+ echo $this->checkout_order();
226
+ echo $this->checkout_cancel();
227
+
228
+ echo $this->checkout_footer();
229
+
230
+ }
231
+
232
+ /**
233
+ * Preferences
234
+ *
235
+ * @since 0.1
236
+ * @version 1.1
237
+ */
238
+ public function preferences()
239
+ {
240
+
241
+ $prefs = $this->prefs;
242
+
243
+ ?>
244
  <div class="row">
245
+ <div class="col-lg-6 col-md-6 col-sm-12 col-xs-12">
246
+ <h3><?php _e('Details', 'mycred'); ?></h3>
247
+ <div class="form-group">
248
+ <label for="<?php echo $this->field_id('account'); ?>"><?php _e('Account ID', 'mycred'); ?></label>
249
+ <input type="text" name="<?php echo $this->field_name('account'); ?>" id="<?php echo $this->field_id('account'); ?>" value="<?php echo esc_attr($prefs['account']); ?>" class="form-control" />
250
+ </div>
251
+ <div class="form-group">
252
+ <label for="<?php echo $this->field_id('site_tag'); ?>"><?php _e('Site Tag', 'mycred'); ?></label>
253
+ <input type="text" name="<?php echo $this->field_name('site_tag'); ?>" id="<?php echo $this->field_id('site_tag'); ?>" value="<?php echo esc_attr($prefs['site_tag']); ?>" class="form-control" />
254
+ </div>
255
+ <div class="form-group">
256
+ <label for="<?php echo $this->field_id('cryptokey'); ?>"><?php _e('Order Integrity Key', 'mycred'); ?></label>
257
+ <input type="password" name="<?php echo $this->field_name('cryptokey'); ?>" id="<?php echo $this->field_id('cryptokey'); ?>" value="<?php echo esc_attr($prefs['cryptokey']); ?>" class="form-control" />
258
+ <p><span class="description"><?php _e('Found under Step 12 on the Fraud Defense page.', 'mycred'); ?></span></p>
259
+ </div>
260
+ <div class="form-group">
261
+ <label for="<?php echo $this->field_id('item_name'); ?>"><?php _e('Item Name', 'mycred'); ?></label>
262
+ <input type="text" name="<?php echo $this->field_name('item_name'); ?>" id="<?php echo $this->field_id('item_name'); ?>" value="<?php echo esc_attr($prefs['item_name']); ?>" class="form-control" />
263
+ </div>
264
+ <div class="form-group">
265
+ <label for="<?php echo $this->field_id('logo_url'); ?>"><?php _e('Logo URL', 'mycred'); ?></label>
266
+ <input type="text" name="<?php echo $this->field_name('logo_url'); ?>" id="<?php echo $this->field_id('logo_url'); ?>" value="<?php echo esc_attr($prefs['logo_url']); ?>" class="form-control" />
267
+ </div>
268
+ </div>
269
+ <div class="col-lg-6 col-md-6 col-sm-12 col-xs-12">
270
+ <h3><?php _e('Setup', 'mycred'); ?></h3>
271
+ <div class="form-group">
272
+ <label><?php _e('Currency', 'mycred'); ?></label>
273
+ <input type="text" readonly="readonly" class="form-control" name="<?php echo $this->field_name('currency'); ?>" value="USD" />
274
+ </div>
275
+ <div class="form-group">
276
+ <label><?php _e('Exchange Rates', 'mycred'); ?></label>
277
+
278
+ <?php $this->exchange_rate_setup(); ?>
279
+
280
+ </div>
281
+ <div class="form-group">
282
+ <label><?php _e('Postback CGI URL', 'mycred'); ?></label>
283
+ <code style="padding: 12px;display:block;"><?php echo $this->callback_url(); ?></code>
284
+ <p><?php _e('For this gateway to work, you must login to your NETbilling account and edit your site. Under "Default payment form settings" make sure the Postback CGI URL is set to the above address and "Return method" is set to POST.', 'mycred'); ?></p>
285
+ </div>
286
+ </div>
287
  </div>
288
+ <?php
289
+
290
+ }
291
+
292
+ /**
293
+ * Sanatize Prefs
294
+ *
295
+ * @since 0.1
296
+ * @version 1.2
297
+ */
298
+ public function sanitise_preferences( $data )
299
+ {
300
+
301
+ $new_data = array();
302
+
303
+ $new_data['sandbox'] = ( isset($data['sandbox']) ) ? 1 : 0;
304
+ $new_data['account'] = sanitize_text_field($data['account']);
305
+ $new_data['currency'] = sanitize_text_field($data['currency']);
306
+ $new_data['site_tag'] = sanitize_text_field($data['site_tag']);
307
+ $new_data['cryptokey'] = sanitize_text_field($data['cryptokey']);
308
+ $new_data['item_name'] = sanitize_text_field($data['item_name']);
309
+ $new_data['logo_url'] = sanitize_text_field($data['logo_url']);
310
+
311
+ // If exchange is less then 1 we must start with a zero
312
+ if (isset($data['exchange']) ) {
313
+ foreach ( (array) $data['exchange'] as $type => $rate ) {
314
+ if ($rate != 1 && in_array(substr($rate, 0, 1), array( '.', ',' )) ) {
315
+ $data['exchange'][ $type ] = (float) '0' . $rate;
316
+ }
317
+ }
318
+ }
319
+ $new_data['exchange'] = $data['exchange'];
320
+
321
+ return $new_data;
322
+
323
+ }
324
+
325
+ }
326
  endif;
addons/buy-creds/gateways/paypal-standard.php CHANGED
@@ -1,349 +1,379 @@
1
  <?php
2
- if ( ! defined( 'myCRED_VERSION' ) ) exit;
 
3
 
4
  /**
5
  * myCRED_PayPal class
6
  * PayPal Payments Standard - Payment Gateway
7
- * @since 0.1
 
8
  * @version 1.3
9
  */
10
- if ( ! class_exists( 'myCRED_PayPal_Standard' ) ) :
11
- class myCRED_PayPal_Standard extends myCRED_Payment_Gateway {
12
-
13
- /**
14
- * Construct
15
- */
16
- public function __construct( $gateway_prefs ) {
17
-
18
- $types = mycred_get_types();
19
- $default_exchange = array();
20
- foreach ( $types as $type => $label )
21
- $default_exchange[ $type ] = 1;
22
-
23
- parent::__construct( array(
24
- 'id' => 'paypal-standard',
25
- 'label' => 'PayPal',
26
- 'gateway_logo_url' => plugins_url( 'assets/images/paypal.png', MYCRED_PURCHASE ),
27
- 'defaults' => array(
28
- 'sandbox' => 0,
29
- 'currency' => '',
30
- 'account' => '',
31
- 'logo_url' => '',
32
- 'item_name' => 'Purchase of myCRED %plural%',
33
- 'exchange' => $default_exchange
34
- )
35
- ), $gateway_prefs );
36
-
37
- }
38
-
39
- /**
40
- * IPN - Is Valid Call
41
- * Replaces the default check
42
- * @since 1.4
43
- * @version 1.0.1
44
- */
45
- public function IPN_is_valid_call() {
46
-
47
- // PayPal Host
48
- $host = 'www.paypal.com';
49
- if ( $this->sandbox_mode )
50
- $host = 'www.sandbox.paypal.com';
51
-
52
- $data = $this->POST_to_data();
53
-
54
- // Prep Respons
55
- $request = 'cmd=_notify-validate';
56
- $get_magic_quotes_exists = false;
57
- if ( function_exists( 'get_magic_quotes_gpc' ) )
58
- $get_magic_quotes_exists = true;
59
-
60
- foreach ( $data as $key => $value ) {
61
- if ( $get_magic_quotes_exists == true && get_magic_quotes_gpc() == 1 )
62
- $value = urlencode( stripslashes( $value ) );
63
- else
64
- $value = urlencode( $value );
65
-
66
- $request .= "&$key=$value";
67
- }
68
-
69
- // Call PayPal
70
- $curl_attempts = apply_filters( 'mycred_paypal_standard_max_attempts', 3 );
71
- $attempt = 1;
72
- $result = '';
73
- // We will make a x number of curl attempts before finishing with a fsock.
74
- do {
75
-
76
- $call = curl_init( "https://$host/cgi-bin/webscr" );
77
- curl_setopt( $call, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1 );
78
- curl_setopt( $call, CURLOPT_POST, 1 );
79
- curl_setopt( $call, CURLOPT_RETURNTRANSFER, 1 );
80
- curl_setopt( $call, CURLOPT_POSTFIELDS, $request );
81
- curl_setopt( $call, CURLOPT_SSL_VERIFYPEER, 1 );
82
- curl_setopt( $call, CURLOPT_CAINFO, MYCRED_PURCHASE_DIR . '/cacert.pem' );
83
- curl_setopt( $call, CURLOPT_SSL_VERIFYHOST, 2 );
84
- curl_setopt( $call, CURLOPT_FRESH_CONNECT, 1 );
85
- curl_setopt( $call, CURLOPT_FORBID_REUSE, 1 );
86
- curl_setopt( $call, CURLOPT_HTTPHEADER, array( 'Connection: Close', 'User-Agent: myCRED' ) );
87
- $result = curl_exec( $call );
88
-
89
- // End on success
90
- if ( $result !== false ) {
91
- curl_close( $call );
92
- break;
93
- }
94
-
95
- curl_close( $call );
96
-
97
- // Final try
98
- if ( $attempt == $curl_attempts ) {
99
- $header = "POST /cgi-bin/webscr HTTP/1.0\r\n";
100
- $header .= "Content-Type: application/x-www-form-urlencoded\r\n";
101
- $header .= "Content-Length: " . strlen( $request ) . "\r\n\r\n";
102
- $fp = fsockopen( 'ssl://' . $host, 443, $errno, $errstr, 30 );
103
- if ( $fp ) {
104
- fputs( $fp, $header . $request );
105
- while ( ! feof( $fp ) ) {
106
- $result = fgets( $fp, 1024 );
107
- }
108
- fclose( $fp );
109
- }
110
- }
111
- $attempt++;
112
-
113
- } while ( $attempt <= $curl_attempts );
114
-
115
- if ( strcmp( $result, "VERIFIED" ) == 0 )
116
- return true;
117
-
118
- return false;
119
-
120
- }
121
-
122
- /**
123
- * Process Handler
124
- * @since 0.1
125
- * @version 1.3
126
- */
127
- public function process() {
128
-
129
- // Required fields
130
- if ( isset( $_POST['custom'] ) && isset( $_POST['txn_id'] ) && isset( $_POST['mc_gross'] ) ) {
131
-
132
- // Get Pending Payment
133
- $pending_post_id = sanitize_key( $_POST['custom'] );
134
- $pending_payment = $this->get_pending_payment( $pending_post_id );
135
- if ( $pending_payment !== false ) {
136
-
137
- // Verify Call with PayPal
138
- if ( $this->IPN_is_valid_call() ) {
139
-
140
- $errors = false;
141
- $new_call = array();
142
-
143
- // Check amount paid
144
- if ( $_POST['mc_gross'] != $pending_payment->cost ) {
145
- $new_call[] = sprintf( __( 'Price mismatch. Expected: %s Received: %s', 'mycred' ), $pending_payment->cost, $_POST['mc_gross'] );
146
- $errors = true;
147
- }
148
-
149
- // Check currency
150
- if ( $_POST['mc_currency'] != $pending_payment->currency ) {
151
- $new_call[] = sprintf( __( 'Currency mismatch. Expected: %s Received: %s', 'mycred' ), $pending_payment->currency, $_POST['mc_currency'] );
152
- $errors = true;
153
- }
154
-
155
- // Check status
156
- if ( $_POST['payment_status'] != 'Completed' ) {
157
- $new_call[] = sprintf( __( 'Payment not completed. Received: %s', 'mycred' ), $_POST['payment_status'] );
158
- $errors = true;
159
- }
160
-
161
- // Credit payment
162
- if ( $errors === false ) {
163
-
164
- // If account is credited, delete the post and it's comments.
165
- if ( $this->complete_payment( $pending_payment, $_POST['txn_id'] ) )
166
- $this->trash_pending_payment( $pending_post_id );
167
- else
168
- $new_call[] = __( 'Failed to credit users account.', 'mycred' );
169
-
170
- }
171
-
172
- // Log Call
173
- if ( ! empty( $new_call ) )
174
- $this->log_call( $pending_post_id, $new_call );
175
-
176
- }
177
-
178
- }
179
-
180
- }
181
-
182
- }
183
-
184
- /**
185
- * Results Handler
186
- * @since 0.1
187
- * @version 1.0.1
188
- */
189
- public function returning() {
190
-
191
- if ( isset( $_REQUEST['tx'] ) && isset( $_REQUEST['st'] ) && $_REQUEST['st'] == 'Completed' ) {
192
- $this->get_page_header( __( 'Success', 'mycred' ), $this->get_thankyou() );
193
- echo '<h1 style="text-align:center;">' . __( 'Thank you for your purchase', 'mycred' ) . '</h1>';
194
- $this->get_page_footer();
195
- exit;
196
- }
197
-
198
- }
199
-
200
- /**
201
- * Prep Sale
202
- * @since 1.8
203
- * @version 1.0
204
- */
205
- public function prep_sale( $new_transaction = false ) {
206
-
207
- // Set currency
208
- $this->currency = ( $this->currency == '' ) ? $this->prefs['currency'] : $this->currency;
209
-
210
- // The item name
211
- $item_name = str_replace( '%number%', $this->amount, $this->prefs['item_name'] );
212
- $item_name = $this->core->template_tags_general( $item_name );
213
-
214
- // This gateway redirects, so we need to populate redirect_to
215
- $this->redirect_to = ( $this->sandbox_mode ) ? 'https://www.sandbox.paypal.com/cgi-bin/webscr' : 'https://www.paypal.com/cgi-bin/webscr';
216
-
217
- // Transaction variables that needs to be submitted
218
- $this->redirect_fields = array(
219
- 'cmd' => '_xclick',
220
- 'business' => $this->prefs['account'],
221
- 'item_name' => $item_name,
222
- 'quantity' => 1,
223
- 'amount' => $this->cost,
224
- 'currency_code' => $this->currency,
225
- 'no_shipping' => 1,
226
- 'no_note' => 1,
227
- 'custom' => $this->transaction_id,
228
- 'return' => $this->get_thankyou(),
229
- 'notify_url' => $this->callback_url(),
230
- 'rm' => 2,
231
- 'cbt' => sprintf( _x( 'Return to %s', 'Return label. %s = Website name', 'mycred' ), get_bloginfo( 'name' ) ),
232
- 'cancel_return' => $this->get_cancelled( $this->transaction_id )
233
- );
234
-
235
- }
236
-
237
- /**
238
- * AJAX Buy Handler
239
- * @since 1.8
240
- * @version 1.0
241
- */
242
- public function ajax_buy() {
243
-
244
- // Construct the checkout box content
245
- $content = $this->checkout_header();
246
- $content .= $this->checkout_logo();
247
- $content .= $this->checkout_order();
248
- $content .= $this->checkout_cancel();
249
- $content .= $this->checkout_footer();
250
-
251
- // Return a JSON response
252
- $this->send_json( $content );
253
-
254
- }
255
-
256
- /**
257
- * Checkout Page Body
258
- * This gateway only uses the checkout body.
259
- * @since 1.8
260
- * @version 1.0
261
- */
262
- public function checkout_page_body() {
263
-
264
- echo $this->checkout_header();
265
- echo $this->checkout_logo( false );
266
-
267
- echo $this->checkout_order();
268
- echo $this->checkout_cancel();
269
-
270
- echo $this->checkout_footer();
271
-
272
- }
273
-
274
- /**
275
- * Preferences
276
- * @since 0.1
277
- * @version 1.0
278
- */
279
- public function preferences() {
280
-
281
- $prefs = $this->prefs;
282
-
283
- ?>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
284
  <div class="row">
285
- <div class="col-lg-6 col-md-6 col-sm-12 col-xs-12">
286
- <h3><?php _e( 'Details', 'mycred' ); ?></h3>
287
- <div class="form-group">
288
- <label for="<?php echo $this->field_id( 'account' ); ?>"><?php _e( 'Account Email', 'mycred' ); ?></label>
289
- <input type="text" name="<?php echo $this->field_name( 'account' ); ?>" id="<?php echo $this->field_id( 'account' ); ?>" value="<?php echo esc_attr( $prefs['account'] ); ?>" class="form-control" />
290
- </div>
291
- <div class="form-group">
292
- <label for="<?php echo $this->field_id( 'item_name' ); ?>"><?php _e( 'Item Name', 'mycred' ); ?></label>
293
- <input type="text" name="<?php echo $this->field_name( 'item_name' ); ?>" id="<?php echo $this->field_id( 'item_name' ); ?>" value="<?php echo esc_attr( $prefs['item_name'] ); ?>" class="form-control" />
294
- </div>
295
- <div class="form-group">
296
- <label for="<?php echo $this->field_id( 'logo_url' ); ?>"><?php _e( 'Logo URL', 'mycred' ); ?></label>
297
- <input type="text" name="<?php echo $this->field_name( 'logo_url' ); ?>" id="<?php echo $this->field_id( 'logo_url' ); ?>" value="<?php echo esc_attr( $prefs['logo_url'] ); ?>" class="form-control" />
298
- </div>
299
- </div>
300
- <div class="col-lg-6 col-md-6 col-sm-12 col-xs-12">
301
- <h3><?php _e( 'Setup', 'mycred' ); ?></h3>
302
- <div class="form-group">
303
- <label for="<?php echo $this->field_id( 'currency' ); ?>"><?php _e( 'Currency', 'mycred' ); ?></label>
304
-
305
- <?php $this->currencies_dropdown( 'currency', 'mycred-gateway-paypal-standard-currency' ); ?>
306
-
307
- </div>
308
- <div class="form-group">
309
- <label><?php _e( 'Exchange Rates', 'mycred' ); ?></label>
310
-
311
- <?php $this->exchange_rate_setup(); ?>
312
-
313
- </div>
314
- </div>
315
  </div>
316
- <?php
317
-
318
- }
319
-
320
- /**
321
- * Sanatize Prefs
322
- * @since 0.1
323
- * @version 1.3
324
- */
325
- public function sanitise_preferences( $data ) {
326
-
327
- $new_data = array();
328
-
329
- $new_data['sandbox'] = ( isset( $data['sandbox'] ) ) ? 1 : 0;
330
- $new_data['currency'] = sanitize_text_field( $data['currency'] );
331
- $new_data['account'] = sanitize_text_field( $data['account'] );
332
- $new_data['item_name'] = sanitize_text_field( $data['item_name'] );
333
- $new_data['logo_url'] = sanitize_text_field( $data['logo_url'] );
334
-
335
- // If exchange is less then 1 we must start with a zero
336
- if ( isset( $data['exchange'] ) ) {
337
- foreach ( (array) $data['exchange'] as $type => $rate ) {
338
- if ( $rate != 1 && in_array( substr( $rate, 0, 1 ), array( '.', ',' ) ) )
339
- $data['exchange'][ $type ] = (float) '0' . $rate;
340
- }
341
- }
342
- $new_data['exchange'] = $data['exchange'];
343
-
344
- return $new_data;
345
-
346
- }
347
-
348
- }
 
 
 
349
  endif;
1
  <?php
2
+ if (! defined('myCRED_VERSION') ) { exit;
3
+ }
4
 
5
  /**
6
  * myCRED_PayPal class
7
  * PayPal Payments Standard - Payment Gateway
8
+ *
9
+ * @since 0.1
10
  * @version 1.3
11
  */
12
+ if (! class_exists('myCRED_PayPal_Standard') ) :
13
+ class myCRED_PayPal_Standard extends myCRED_Payment_Gateway
14
+ {
15
+
16
+ /**
17
+ * Construct
18
+ */
19
+ public function __construct( $gateway_prefs )
20
+ {
21
+
22
+ $types = mycred_get_types();
23
+ $default_exchange = array();
24
+ foreach ( $types as $type => $label ) {
25
+ $default_exchange[ $type ] = 1;
26
+ }
27
+
28
+ parent::__construct(
29
+ array(
30
+ 'id' => 'paypal-standard',
31
+ 'label' => 'PayPal',
32
+ 'gateway_logo_url' => plugins_url('assets/images/paypal.png', MYCRED_PURCHASE),
33
+ 'defaults' => array(
34
+ 'sandbox' => 0,
35
+ 'currency' => '',
36
+ 'account' => '',
37
+ 'logo_url' => '',
38
+ 'item_name' => 'Purchase of myCRED %plural%',
39
+ 'exchange' => $default_exchange
40
+ )
41
+ ), $gateway_prefs
42
+ );
43
+
44
+ }
45
+
46
+ /**
47
+ * IPN - Is Valid Call
48
+ * Replaces the default check
49
+ *
50
+ * @since 1.4
51
+ * @version 1.0.1
52
+ */
53
+ public function IPN_is_valid_call()
54
+ {
55
+
56
+ // PayPal Host
57
+ $host = 'www.paypal.com';
58
+ if ($this->sandbox_mode ) {
59
+ $host = 'www.sandbox.paypal.com';
60
+ }
61
+
62
+ $data = $this->POST_to_data();
63
+
64
+ // Prep Respons
65
+ $request = 'cmd=_notify-validate';
66
+ $get_magic_quotes_exists = false;
67
+ if (function_exists('get_magic_quotes_gpc') ) {
68
+ $get_magic_quotes_exists = true;
69
+ }
70
+
71
+ foreach ( $data as $key => $value ) {
72
+ if ($get_magic_quotes_exists == true && get_magic_quotes_gpc() == 1 ) {
73
+ $value = urlencode(stripslashes($value));
74
+ } else {
75
+ $value = urlencode($value);
76
+ }
77
+
78
+ $request .= "&$key=$value";
79
+ }
80
+
81
+ // Call PayPal
82
+ $curl_attempts = apply_filters('mycred_paypal_standard_max_attempts', 3);
83
+ $attempt = 1;
84
+ $result = '';
85
+ // We will make a x number of curl attempts before finishing with a fsock.
86
+ do {
87
+
88
+ $call = curl_init("https://$host/cgi-bin/webscr");
89
+ curl_setopt($call, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
90
+ curl_setopt($call, CURLOPT_POST, 1);
91
+ curl_setopt($call, CURLOPT_RETURNTRANSFER, 1);
92
+ curl_setopt($call, CURLOPT_POSTFIELDS, $request);
93
+ curl_setopt($call, CURLOPT_SSL_VERIFYPEER, 1);
94
+ curl_setopt($call, CURLOPT_CAINFO, MYCRED_PURCHASE_DIR . '/cacert.pem');
95
+ curl_setopt($call, CURLOPT_SSL_VERIFYHOST, 2);
96
+ curl_setopt($call, CURLOPT_FRESH_CONNECT, 1);
97
+ curl_setopt($call, CURLOPT_FORBID_REUSE, 1);
98
+ curl_setopt($call, CURLOPT_HTTPHEADER, array( 'Connection: Close', 'User-Agent: myCRED' ));
99
+ $result = curl_exec($call);
100
+
101
+ // End on success
102
+ if ($result !== false ) {
103
+ curl_close($call);
104
+ break;
105
+ }
106
+
107
+ curl_close($call);
108
+
109
+ // Final try
110
+ if ($attempt == $curl_attempts ) {
111
+ $header = "POST /cgi-bin/webscr HTTP/1.0\r\n";
112
+ $header .= "Content-Type: application/x-www-form-urlencoded\r\n";
113
+ $header .= "Content-Length: " . strlen($request) . "\r\n\r\n";
114
+ $fp = fsockopen('ssl://' . $host, 443, $errno, $errstr, 30);
115
+ if ($fp ) {
116
+ fputs($fp, $header . $request);
117
+ while ( ! feof($fp) ) {
118
+ $result = fgets($fp, 1024);
119
+ }
120
+ fclose($fp);
121
+ }
122
+ }
123
+ $attempt++;
124
+
125
+ } while ( $attempt <= $curl_attempts );
126
+
127
+ if (strcmp($result, "VERIFIED") == 0 ) {
128
+ return true;
129
+ }
130
+
131
+ return false;
132
+
133
+ }
134
+
135
+ /**
136
+ * Process Handler
137
+ *
138
+ * @since 0.1
139
+ * @version 1.3
140
+ */
141
+ public function process()
142
+ {
143
+
144
+ // Required fields
145
+ if (isset($_POST['custom']) && isset($_POST['txn_id']) && isset($_POST['mc_gross']) ) {
146
+
147
+ // Get Pending Payment
148
+ $pending_post_id = sanitize_key($_POST['custom']);
149
+ $pending_payment = $this->get_pending_payment($pending_post_id);
150
+ if ($pending_payment !== false ) {
151
+
152
+ // Verify Call with PayPal
153
+ if ($this->IPN_is_valid_call() ) {
154
+
155
+ $errors = false;
156
+ $new_call = array();
157
+
158
+ // Check amount paid
159
+ if ($_POST['mc_gross'] != $pending_payment->cost ) {
160
+ $new_call[] = sprintf(__('Price mismatch. Expected: %s Received: %s', 'mycred'), $pending_payment->cost, $_POST['mc_gross']);
161
+ $errors = true;
162
+ }
163
+
164
+ // Check currency
165
+ if ($_POST['mc_currency'] != $pending_payment->currency ) {
166
+ $new_call[] = sprintf(__('Currency mismatch. Expected: %s Received: %s', 'mycred'), $pending_payment->currency, $_POST['mc_currency']);
167
+ $errors = true;
168
+ }
169
+
170
+ // Check status
171
+ if ($_POST['payment_status'] != 'Completed' ) {
172
+ $new_call[] = sprintf(__('Payment not completed. Received: %s', 'mycred'), $_POST['payment_status']);
173
+ $errors = true;
174
+ }
175
+
176
+ // Credit payment
177
+ if ($errors === false ) {
178
+
179
+ // If account is credited, delete the post and it's comments.
180
+ if ($this->complete_payment($pending_payment, $_POST['txn_id']) ) {
181
+ $this->trash_pending_payment($pending_post_id);
182
+ } else {
183
+ $new_call[] = __('Failed to credit users account.', 'mycred');
184
+ }
185
+
186
+ }
187
+
188
+ // Log Call
189
+ if (! empty($new_call) ) {
190
+ $this->log_call($pending_post_id, $new_call);
191
+ }
192
+
193
+ }
194
+
195
+ }
196
+
197
+ }
198
+
199
+ }
200
+
201
+ /**
202
+ * Results Handler
203
+ *
204
+ * @since 0.1
205
+ * @version 1.0.1
206
+ */
207
+ public function returning()
208
+ {
209
+
210
+ if (isset($_REQUEST['tx']) && isset($_REQUEST['st']) && $_REQUEST['st'] == 'Completed' ) {
211
+ $this->get_page_header(__('Success', 'mycred'), $this->get_thankyou());
212
+ echo '<h1 style="text-align:center;">' . __('Thank you for your purchase', 'mycred') . '</h1>';
213
+ $this->get_page_footer();
214
+ exit;
215
+ }
216
+
217
+ }
218
+
219
+ /**
220
+ * Prep Sale
221
+ *
222
+ * @since 1.8
223
+ * @version 1.0
224
+ */
225
+ public function prep_sale( $new_transaction = false )
226
+ {
227
+
228
+ // Set currency
229
+ $this->currency = ( $this->currency == '' ) ? $this->prefs['currency'] : $this->currency;
230
+
231
+ // The item name
232
+ $item_name = str_replace('%number%', $this->amount, $this->prefs['item_name']);
233
+ $item_name = $this->core->template_tags_general($item_name);
234
+
235
+ // This gateway redirects, so we need to populate redirect_to
236
+ $this->redirect_to = ( $this->sandbox_mode ) ? 'https://www.sandbox.paypal.com/cgi-bin/webscr' : 'https://www.paypal.com/cgi-bin/webscr';
237
+
238
+ // Transaction variables that needs to be submitted
239
+ $this->redirect_fields = array(
240
+ 'cmd' => '_xclick',
241
+ 'business' => $this->prefs['account'],
242
+ 'item_name' => $item_name,
243
+ 'quantity' => 1,
244
+ 'amount' => $this->cost,
245
+ 'currency_code' => $this->currency,
246
+ 'no_shipping' => 1,
247
+ 'no_note' => 1,
248
+ 'custom' => $this->transaction_id,
249
+ 'return' => $this->get_thankyou(),
250
+ 'notify_url' => $this->callback_url(),
251
+ 'rm' => 2,
252
+ 'cbt' => sprintf(_x('Return to %s', 'Return label. %s = Website name', 'mycred'), get_bloginfo('name')),
253
+ 'cancel_return' => $this->get_cancelled($this->transaction_id)
254
+ );
255
+
256
+ }
257
+
258
+ /**
259
+ * AJAX Buy Handler
260
+ *
261
+ * @since 1.8
262
+ * @version 1.0
263
+ */
264
+ public function ajax_buy()
265
+ {
266
+
267
+ // Construct the checkout box content
268
+ $content = $this->checkout_header();
269
+ $content .= $this->checkout_logo();
270
+ $content .= $this->checkout_order();
271
+ $content .= $this->checkout_cancel();
272
+ $content .= $this->checkout_footer();
273
+
274
+ // Return a JSON response
275
+ $this->send_json($content);
276
+
277
+ }
278
+
279
+ /**
280
+ * Checkout Page Body
281
+ * This gateway only uses the checkout body.
282
+ *
283
+ * @since 1.8
284
+ * @version 1.0
285
+ */
286
+ public function checkout_page_body()
287
+ {
288
+
289
+ echo $this->checkout_header();
290
+ echo $this->checkout_logo(false);
291
+
292
+ echo $this->checkout_order();
293
+ echo $this->checkout_cancel();
294
+
295
+ echo $this->checkout_footer();
296
+
297
+ }
298
+
299
+ /**
300
+ * Preferences
301
+ *
302
+ * @since 0.1
303
+ * @version 1.0
304
+ */
305
+ public function preferences()
306
+ {
307
+
308
+ $prefs = $this->prefs;
309
+
310
+ ?>
311
  <div class="row">
312
+ <div class="col-lg-6 col-md-6 col-sm-12 col-xs-12">
313
+ <h3><?php _e('Details', 'mycred'); ?></h3>
314
+ <div class="form-group">
315
+ <label for="<?php echo $this->field_id('account'); ?>"><?php _e('Account Email', 'mycred'); ?></label>
316
+ <input type="text" name="<?php echo $this->field_name('account'); ?>" id="<?php echo $this->field_id('account'); ?>" value="<?php echo esc_attr($prefs['account']); ?>" class="form-control" />
317
+ </div>
318
+ <div class="form-group">
319
+ <label for="<?php echo $this->field_id('item_name'); ?>"><?php _e('Item Name', 'mycred'); ?></label>
320
+ <input type="text" name="<?php echo $this->field_name('item_name'); ?>" id="<?php echo $this->field_id('item_name'); ?>" value="<?php echo esc_attr($prefs['item_name']); ?>" class="form-control" />
321
+ </div>
322
+ <div class="form-group">
323
+ <label for="<?php echo $this->field_id('logo_url'); ?>"><?php _e('Logo URL', 'mycred'); ?></label>
324
+ <input type="text" name="<?php echo $this->field_name('logo_url'); ?>" id="<?php echo $this->field_id('logo_url'); ?>" value="<?php echo esc_attr($prefs['logo_url']); ?>" class="form-control" />
325
+ </div>
326
+ </div>
327
+ <div class="col-lg-6 col-md-6 col-sm-12 col-xs-12">
328
+ <h3><?php _e('Setup', 'mycred'); ?></h3>
329
+ <div class="form-group">
330
+ <label for="<?php echo $this->field_id('currency'); ?>"><?php _e('Currency', 'mycred'); ?></label>
331
+
332
+ <?php $this->currencies_dropdown('currency', 'mycred-gateway-paypal-standard-currency'); ?>
333
+
334
+ </div>
335
+ <div class="form-group">
336
+ <label><?php _e('Exchange Rates', 'mycred'); ?></label>
337
+
338
+ <?php $this->exchange_rate_setup(); ?>
339
+
340
+ </div>
341
+ </div>
342
  </div>
343
+ <?php
344
+
345
+ }
346
+
347
+ /**
348
+ * Sanatize Prefs
349
+ *
350
+ * @since 0.1
351
+ * @version 1.3
352
+ */
353
+ public function sanitise_preferences( $data )
354
+ {
355
+
356
+ $new_data = array();
357
+
358
+ $new_data['sandbox'] = ( isset($data['sandbox']) ) ? 1 : 0;
359
+ $new_data['currency'] = sanitize_text_field($data['currency']);
360
+ $new_data['account'] = sanitize_text_field($data['account']);
361
+ $new_data['item_name'] = sanitize_text_field($data['item_name']);
362
+ $new_data['logo_url'] = sanitize_text_field($data['logo_url']);
363
+
364
+ // If exchange is less then 1 we must start with a zero
365
+ if (isset($data['exchange']) ) {
366
+ foreach ( (array) $data['exchange'] as $type => $rate ) {
367
+ if ($rate != 1 && in_array(substr($rate, 0, 1), array( '.', ',' )) ) {
368
+ $data['exchange'][ $type ] = (float) '0' . $rate;
369
+ }
370
+ }
371
+ }
372
+ $new_data['exchange'] = $data['exchange'];
373
+
374
+ return $new_data;
375
+
376
+ }
377
+
378
+ }
379
  endif;
addons/buy-creds/gateways/skrill.php CHANGED
@@ -1,380 +1,414 @@
1
  <?php
2
- if ( ! defined( 'myCRED_VERSION' ) ) exit;
 
3
 
4
  /**
5
  * myCRED_Skrill class
6
  * Skrill (Moneybookers) - Payment Gateway
7
- * @since 0.1
 
8
  * @version 1.2
9
  */
10
- if ( ! class_exists( 'myCRED_Skrill' ) ) :
11
- class myCRED_Skrill extends myCRED_Payment_Gateway {
12
-
13
- /**
14
- * Construct
15
- */
16
- public function __construct( $gateway_prefs ) {
17
-
18
- $types = mycred_get_types();
19
- $default_exchange = array();
20
- foreach ( $types as $type => $label )
21
- $default_exchange[ $type ] = 1;
22
-
23
- parent::__construct( array(
24
- 'id' => 'skrill',
25
- 'label' => 'Skrill Payment',
26
- 'gateway_logo_url' => plugins_url( 'assets/images/skrill.png', MYCRED_PURCHASE ),
27
- 'defaults' => array(
28
- 'sandbox' => 0,
29
- 'currency' => '',
30
- 'account' => '',
31
- 'word' => '',
32
- 'account_title' => '',
33
- 'account_logo' => '',
34
- 'logo_url' => '',
35
- 'confirmation_note' => '',
36
- 'email_receipt' => 0,
37
- 'item_name' => 'Purchase of myCRED %plural%',
38
- 'exchange' => $default_exchange
39
- )
40
- ), $gateway_prefs );
41
-
42
- }
43
-
44
- /**
45
- * IPN - Is Valid Call
46
- * Replaces the default check
47
- * @since 1.4
48
- * @version 1.1
49
- */
50
- public function IPN_is_valid_call() {
51
-
52
- $result = true;
53
-
54
- $check = $_POST['merchant_id'] . $_POST['transaction_id'] . strtoupper( md5( $this->prefs['word'] ) ) . $_POST['mb_amount'] . $_POST['mb_currency'] . $_POST['status'];
55
- if ( strtoupper( md5( $check ) ) !== $_POST['md5sig'] )
56
- $result = false;
57
-
58
- if ( $_POST['pay_to_email'] != trim( $this->prefs['account'] ) )
59
- $result = false;
60
-
61
- return $result;
62
-
63
- }
64
-
65
- /**
66
- * Process Handler
67
- * @since 0.1
68
- * @version 1.2
69
- */
70
- public function process() {
71
-
72
- // Required fields
73
- if ( isset( $_POST['sales_data'] ) && isset( $_POST['transaction_id'] ) && isset( $_POST['amount'] ) ) {
74
-
75
- // Get Pending Payment
76
- $pending_post_id = sanitize_key( $_POST['sales_data'] );
77
- $pending_payment = $this->get_pending_payment( $pending_post_id );
78
- if ( $pending_payment !== false ) {
79
-
80
- // Verify Call with PayPal
81
- if ( $this->IPN_is_valid_call() ) {
82
-
83
- $errors = false;
84
- $new_call = array();
85
-
86
- // Check amount paid
87
- if ( $_POST['amount'] != $pending_payment->cost ) {
88
- $new_call[] = sprintf( __( 'Price mismatch. Expected: %s Received: %s', 'mycred' ), $pending_payment->cost, $_POST['amount'] );
89
- $errors = true;
90
- }
91
-
92
- // Check currency
93
- if ( $_POST['currency'] != $pending_payment->currency ) {
94
- $new_call[] = sprintf( __( 'Currency mismatch. Expected: %s Received: %s', 'mycred' ), $pending_payment->currency, $_POST['currency'] );
95
- $errors = true;
96
- }
97
-
98
- // Check status
99
- if ( $_POST['status'] != '2' ) {
100
- $new_call[] = sprintf( __( 'Payment not completed. Received: %s', 'mycred' ), $_POST['status'] );
101
- $errors = true;
102
- }
103
-
104
- // Credit payment
105
- if ( $errors === false ) {
106
-
107
- // If account is credited, delete the post and it's comments.
108
- if ( $this->complete_payment( $pending_payment, $_POST['transaction_id'] ) )
109
- $this->trash_pending_payment( $pending_post_id );
110
- else
111
- $new_call[] = __( 'Failed to credit users account.', 'mycred' );
112
-
113
- }
114
-
115
- // Log Call
116
- if ( ! empty( $new_call ) )
117
- $this->log_call( $pending_post_id, $new_call );
118
-
119
- }
120
-
121
- }
122
-
123
- }
124
-
125
- }
126
-
127
- /**
128
- * Results Handler
129
- * @since 0.1
130
- * @version 1.1
131
- */
132
- public function returning() {
133
-
134
- if ( isset( $_GET['transaction_id'] ) && ! empty( $_GET['transaction_id'] ) && isset( $_GET['msid'] ) && ! empty( $_GET['msid'] ) ) {
135
- $this->get_page_header( __( 'Success', 'mycred' ), $this->get_thankyou() );
136
- echo '<h1>' . __( 'Thank you for your purchase', 'mycred' ) . '</h1>';
137
- $this->get_page_footer();
138
- exit;
139
- }
140
-
141
- }
142
-
143
- /**
144
- * Prep Sale
145
- * @since 1.8
146
- * @version 1.0
147
- */
148
- public function prep_sale( $new_transaction = false ) {
149
-
150
- // Set currency
151
- $this->currency = ( $this->currency == '' ) ? $this->prefs['currency'] : $this->currency;
152
-
153
- // Item Name
154
- $item_name = str_replace( '%number%', $this->amount, $this->prefs['item_name'] );
155
- $item_name = $this->core->template_tags_general( $item_name );
156
-
157
- $this->redirect_to = 'https://www.moneybookers.com/app/payment.pl';
158
-
159
- $redirect_fields = array(
160
- 'pay_to_email' => $this->prefs['account'],
161
- 'transaction_id' => $this->transaction_id,
162
- 'return_url' => $this->get_thankyou(),
163
- 'cancel_url' => $this->get_cancelled( $this->transaction_id ),
164
- 'status_url' => $this->callback_url(),
165
- 'return_url_text' => get_bloginfo( 'name' ),
166
- 'hide_login' => 1,
167
- 'merchant_fields' => 'sales_data',
168
- 'sales_data' => $this->post_id,
169
- 'amount' => $this->cost,
170
- 'currency' => $this->prefs['currency'],
171
- 'detail1_description' => __( 'Item Name', 'mycred' ),
172
- 'detail1_text' => $item_name
173
- );
174
-
175
- // Customize Checkout Page
176
- if ( isset( $this->prefs['account_title'] ) && ! empty( $this->prefs['account_title'] ) )
177
- $redirect_fields['recipient_description'] = $this->core->template_tags_general( $this->prefs['account_title'] );
178
-
179
- if ( isset( $this->prefs['account_logo'] ) && ! empty( $this->prefs['account_logo'] ) )
180
- $redirect_fields['logo_url'] = $this->prefs['account_logo'];
181
-
182
- if ( isset( $this->prefs['confirmation_note'] ) && ! empty( $this->prefs['confirmation_note'] ) )
183
- $redirect_fields['confirmation_note'] = $this->core->template_tags_general( $this->prefs['confirmation_note'] );
184
-
185
- // If we want an email receipt for purchases
186
- if ( isset( $this->prefs['email_receipt'] ) && ! empty( $this->prefs['email_receipt'] ) )
187
- $redirect_fields['status_url2'] = $this->prefs['account'];
188
-
189
- // Gifting
190
- if ( $this->gifting ) {
191
-
192
- $user = get_userdata( $this->recipient_id );
193
- $redirect_fields['detail2_description'] = __( 'Recipient', 'mycred' );
194
- $redirect_fields['detail2_text'] = $user->display_name;
195
-
196
- }
197
-
198
- $this->redirect_fields = $redirect_fields;
199
-
200
- }
201
-
202
- /**
203
- * AJAX Buy Handler
204
- * @since 1.8
205
- * @version 1.0
206
- */
207
- public function ajax_buy() {
208
-
209
- // Construct the checkout box content
210
- $content = $this->checkout_header();
211
- $content .= $this->checkout_logo();
212
- $content .= $this->checkout_order();
213
- $content .= $this->checkout_cancel();
214
- $content .= $this->checkout_footer();
215
-
216
- // Return a JSON response
217
- $this->send_json( $content );
218
-
219
- }
220
-
221
- /**
222
- * Checkout Page Body
223
- * This gateway only uses the checkout body.
224
- * @since 1.8
225
- * @version 1.0
226
- */
227
- public function checkout_page_body() {
228
-
229
- echo $this->checkout_header();
230
- echo $this->checkout_logo( false );
231
-
232
- echo $this->checkout_order();
233
- echo $this->checkout_cancel();
234
-
235
- echo $this->checkout_footer();
236
-
237
- }
238
-
239
- /**
240
- * Preferences
241
- * @since 0.1
242
- * @version 1.0.1
243
- */
244
- public function preferences() {
245
-
246
- add_filter( 'mycred_dropdown_currencies', array( $this, 'skrill_currencies' ) );
247
- $prefs = $this->prefs;
248
-
249
- ?>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
250
  <div class="row">
251
- <div class="col-lg-6 col-md-6 col-sm-12 col-xs-12">
252
- <h3><?php _e( 'Details', 'mycred' ); ?></h3>
253
- <div class="form-group">
254
- <label for="<?php echo $this->field_id( 'account' ); ?>"><?php _e( 'Account Email', 'mycred' ); ?></label>
255
- <input type="text" name="<?php echo $this->field_name( 'account' ); ?>" id="<?php echo $this->field_id( 'account' ); ?>" value="<?php echo esc_attr( $prefs['account'] ); ?>" class="form-control" />
256
- </div>
257
- <div class="form-group">
258
- <label for="<?php echo $this->field_id( 'word' ); ?>"><?php _e( 'Secret Word', 'mycred' ); ?></label>
259
- <input type="text" name="<?php echo $this->field_name( 'word' ); ?>" id="<?php echo $this->field_id( 'word' ); ?>" value="<?php echo esc_attr( $prefs['word'] ); ?>" class="form-control" />
260
- </div>
261
- <div class="form-group">
262
- <label for="<?php echo $this->field_id( 'item_name' ); ?>"><?php _e( 'Item Name', 'mycred' ); ?></label>
263
- <input type="text" name="<?php echo $this->field_name( 'item_name' ); ?>" id="<?php echo $this->field_id( 'item_name' ); ?>" value="<?php echo esc_attr( $prefs['item_name'] ); ?>" class="form-control" />
264
- </div>
265
- <div class="form-group">
266
- <label for="<?php echo $this->field_id( 'logo_url' ); ?>"><?php _e( 'Logo URL', 'mycred' ); ?></label>
267
- <input type="text" name="<?php echo $this->field_name( 'logo_url' ); ?>" id="<?php echo $this->field_id( 'logo_url' ); ?>" value="<?php echo esc_attr( $prefs['logo_url'] ); ?>" class="form-control" />
268
- </div>
269
- <div class="form-group">
270
- <label for="<?php echo $this->field_id( 'email_receipt' ); ?>"><input type="checkbox" name="<?php echo $this->field_name( 'email_receipt' ); ?>" id="<?php echo $this->field_id( 'email_receipt' ); ?>" value="1"<?php checked( $prefs['email_receipt'], 1 ); ?> /> <?php _e( 'Ask Skrill to send me a confirmation email for each successful purchase.', 'mycred' ); ?></label>
271
- </div>
272
- </div>
273
- <div class="col-lg-6 col-md-6 col-sm-12 col-xs-12">
274
- <h3><?php _e( 'Setup', 'mycred' ); ?></h3>
275
- <div class="form-group">
276
- <label for="<?php echo $this->field_id( 'currency' ); ?>"><?php _e( 'Currency', 'mycred' ); ?></label>
277
-
278
- <?php $this->currencies_dropdown( 'currency', 'mycred-gateway-skrill-currency' ); ?>
279
-
280
- </div>
281
- <div class="form-group">
282
- <label><?php _e( 'Exchange Rates', 'mycred' ); ?></label>
283
-
284
- <?php $this->exchange_rate_setup(); ?>
285
-
286
- </div>
287
- </div>
288
  </div>
289
- <h3><?php _e( 'Checkout Page', 'mycred' ); ?></h3>
290
  <div class="row">
291
- <div class="col-lg-12 col-md-12 col-sm-12 col-xs-12">
292
- <div class="form-group">
293
- <label for="<?php echo $this->field_id( 'account_title' ); ?>"><?php _e( 'Title', 'mycred' ); ?></label>
294
- <p><span class="description"><?php _e( 'If left empty, your account email is used as title on the Skill Payment Page.', 'mycred' ); ?></span></p>
295
- <input type="text" name="<?php echo $this->field_name( 'account_title' ); ?>" id="<?php echo $this->field_id( 'account_title' ); ?>" value="<?php echo esc_attr( $prefs['account_title'] ); ?>" class="form-control" />
296
- </div>
297
- <div class="form-group">
298
- <label for="<?php echo $this->field_id( 'confirmation_note' ); ?>"><?php _e( 'Confirmation Note', 'mycred' ); ?></label>
299
- <p><span class="description"><?php _e( 'Optional text to show user once a transaction has been successfully completed. This text is shown by Skrill.', 'mycred' ); ?></span></p>
300
- <textarea rows="10" cols="50" name="<?php echo $this->field_name( 'confirmation_note' ); ?>" id="<?php echo $this->field_id( 'confirmation_note' ); ?>" class="form-control"><?php echo esc_html( $prefs['confirmation_note'] ); ?></textarea>
301
- </div>
302
- </div>
303
  </div>
304
- <?php
305
-
306
- remove_filter( 'mycred_dropdown_currencies', array( $this, 'skrill_currencies' ) );
307
-
308
- }
309
-
310
- /**
311
- * Sanatize Prefs
312
- * @since 0.1
313
- * @version 1.1
314
- */
315
- public function sanitise_preferences( $data ) {
316
-
317
- $new_data = array();
318
-
319
- $new_data['sandbox'] = ( isset( $data['sandbox'] ) ) ? 1 : 0;
320
- $new_data['currency'] = sanitize_text_field( $data['currency'] );
321
- $new_data['account'] = sanitize_text_field( $data['account'] );
322
- $new_data['word'] = sanitize_text_field( $data['word'] );
323
- $new_data['item_name'] = sanitize_text_field( $data['item_name'] );
324
- $new_data['logo_url'] = sanitize_text_field( $data['logo_url'] );
325
- $new_data['email_receipt'] = ( isset( $data['email_receipt'] ) ) ? 1 : 0;
326
- $new_data['account_title'] = substr( $data['account_title'], 0, 30 );
327
- $new_data['confirmation_note'] = substr( $data['confirmation_note'], 0, 240 );
328
-
329
- // If exchange is less then 1 we must start with a zero
330
- if ( isset( $data['exchange'] ) ) {
331
- foreach ( (array) $data['exchange'] as $type => $rate ) {
332
- if ( $rate != 1 && in_array( substr( $rate, 0, 1 ), array( '.', ',' ) ) )
333
- $data['exchange'][ $type ] = (float) '0' . $rate;
334
- }
335
- }
336
- $new_data['exchange'] = $data['exchange'];
337
-
338
- return $new_data;
339
-
340
- }
341
-
342
- /**
343
- * Adjust Currencies
344
- * @since 1.0.6
345
- * @version 1.0
346
- */
347
- public function skrill_currencies( $currencies ) {
348
-
349
- $currencies['RON'] = 'Romanian Leu';
350
- $currencies['TRY'] = 'New Turkish Lira';
351
- $currencies['RON'] = 'Romanian Leu';
352
- $currencies['AED'] = 'Utd. Arab Emir. Dirham';
353
- $currencies['MAD'] = 'Moroccan Dirham';
354
- $currencies['QAR'] = 'Qatari Rial';
355
- $currencies['SAR'] = 'Saudi Riyal';
356
- $currencies['SKK'] = 'Slovakian Koruna';
357
- $currencies['EEK'] = 'Estonian Kroon';
358
- $currencies['BGN'] = 'Bulgarian Leva';
359
- $currencies['ISK'] = 'Iceland Krona';
360
- $currencies['INR'] = 'Indian Rupee';
361
- $currencies['LVL'] = 'Latvian Lat';
362
- $currencies['KRW'] = 'South-Korean Won';
363
- $currencies['ZAR'] = 'South-African Rand';
364
- $currencies['HRK'] = 'Croatian Kuna';
365
- $currencies['LTL'] = 'Lithuanian Litas';
366
- $currencies['JOD'] = 'Jordanian Dinar';
367
- $currencies['OMR'] = 'Omani Rial';
368
- $currencies['RSD'] = 'Serbian Dinar';
369
- $currencies['TND'] = 'Tunisian Dinar';
370
-
371
- unset( $currencies['MXN'] );
372
- unset( $currencies['BRL'] );
373
- unset( $currencies['PHP'] );
374
-
375
- return $currencies;
376
-
377
- }
378
-
379
- }
 
 
 
 
 
380
  endif;
1
  <?php
2
+ if (! defined('myCRED_VERSION') ) { exit;
3
+ }
4
 
5
  /**
6
  * myCRED_Skrill class
7
  * Skrill (Moneybookers) - Payment Gateway
8
+ *
9
+ * @since 0.1
10
  * @version 1.2
11
  */
12
+ if (! class_exists('myCRED_Skrill') ) :
13
+ class myCRED_Skrill extends myCRED_Payment_Gateway
14
+ {
15
+
16
+ /**
17
+ * Construct
18
+ */
19
+ public function __construct( $gateway_prefs )
20
+ {
21
+
22
+ $types = mycred_get_types();
23
+ $default_exchange = array();
24
+ foreach ( $types as $type => $label ) {
25
+ $default_exchange[ $type ] = 1;
26
+ }
27
+
28
+ parent::__construct(
29
+ array(
30
+ 'id' => 'skrill',
31
+ 'label' => 'Skrill Payment',
32
+ 'gateway_logo_url' => plugins_url('assets/images/skrill.png', MYCRED_PURCHASE),
33
+ 'defaults' => array(
34
+ 'sandbox' => 0,
35
+ 'currency' => '',
36
+ 'account' => '',
37
+ 'word' => '',
38
+ 'account_title' => '',
39
+ 'account_logo' => '',
40
+ 'logo_url' => '',
41
+ 'confirmation_note' => '',
42
+ 'email_receipt' => 0,
43
+ 'item_name' => 'Purchase of myCRED %plural%',
44
+ 'exchange' => $default_exchange
45
+ )
46
+ ), $gateway_prefs
47
+ );
48
+
49
+ }
50
+
51
+ /**
52
+ * IPN - Is Valid Call
53
+ * Replaces the default check
54
+ *
55
+ * @since 1.4
56
+ * @version 1.1
57
+ */
58
+ public function IPN_is_valid_call()
59
+ {
60
+
61
+ $result = true;
62
+
63
+ $check = $_POST['merchant_id'] . $_POST['transaction_id'] . strtoupper(md5($this->prefs['word'])) . $_POST['mb_amount'] . $_POST['mb_currency'] . $_POST['status'];
64
+ if (strtoupper(md5($check)) !== $_POST['md5sig'] ) {
65
+ $result = false;
66
+ }
67
+
68
+ if ($_POST['pay_to_email'] != trim($this->prefs['account']) ) {
69
+ $result = false;
70
+ }
71
+
72
+ return $result;
73
+
74
+ }
75
+
76
+ /**
77
+ * Process Handler
78
+ *
79
+ * @since 0.1
80
+ * @version 1.2
81
+ */
82
+ public function process()
83
+ {
84
+
85
+ // Required fields
86
+ if (isset($_POST['sales_data']) && isset($_POST['transaction_id']) && isset($_POST['amount']) ) {
87
+
88
+ // Get Pending Payment
89
+ $pending_post_id = sanitize_key($_POST['sales_data']);
90
+ $pending_payment = $this->get_pending_payment($pending_post_id);
91
+ if ($pending_payment !== false ) {
92
+
93
+ // Verify Call with PayPal
94
+ if ($this->IPN_is_valid_call() ) {
95
+
96
+ $errors = false;
97
+ $new_call = array();
98
+
99
+ // Check amount paid
100
+ if ($_POST['amount'] != $pending_payment->cost ) {
101
+ $new_call[] = sprintf(__('Price mismatch. Expected: %s Received: %s', 'mycred'), $pending_payment->cost, $_POST['amount']);
102
+ $errors = true;
103
+ }
104
+
105
+ // Check currency
106
+ if ($_POST['currency'] != $pending_payment->currency ) {
107
+ $new_call[] = sprintf(__('Currency mismatch. Expected: %s Received: %s', 'mycred'), $pending_payment->currency, $_POST['currency']);
108
+ $errors = true;
109
+ }
110
+
111
+ // Check status
112
+ if ($_POST['status'] != '2' ) {
113
+ $new_call[] = sprintf(__('Payment not completed. Received: %s', 'mycred'), $_POST['status']);
114
+ $errors = true;
115
+ }
116
+
117
+ // Credit payment
118
+ if ($errors === false ) {
119
+
120
+ // If account is credited, delete the post and it's comments.
121
+ if ($this->complete_payment($pending_payment, $_POST['transaction_id']) ) {
122
+ $this->trash_pending_payment($pending_post_id);
123
+ } else {
124
+ $new_call[] = __('Failed to credit users account.', 'mycred');
125
+ }
126
+
127
+ }
128
+
129
+ // Log Call
130
+ if (! empty($new_call) ) {
131
+ $this->log_call($pending_post_id, $new_call);
132
+ }
133
+
134
+ }
135
+
136
+ }
137
+
138
+ }
139
+
140
+ }
141
+
142
+ /**
143
+ * Results Handler
144
+ *
145
+ * @since 0.1
146
+ * @version 1.1
147
+ */
148
+ public function returning()
149
+ {
150
+
151
+ if (isset($_GET['transaction_id']) && ! empty($_GET['transaction_id']) && isset($_GET['msid']) && ! empty($_GET['msid']) ) {
152
+ $this->get_page_header(__('Success', 'mycred'), $this->get_thankyou());
153
+ echo '<h1>' . __('Thank you for your purchase', 'mycred') . '</h1>';
154
+ $this->get_page_footer();
155
+ exit;
156
+ }
157
+
158
+ }
159
+
160
+ /**
161
+ * Prep Sale
162
+ *
163
+ * @since 1.8
164
+ * @version 1.0
165
+ */
166
+ public function prep_sale( $new_transaction = false )
167
+ {
168
+
169
+ // Set currency
170
+ $this->currency = ( $this->currency == '' ) ? $this->prefs['currency'] : $this->currency;
171
+
172
+ // Item Name
173
+ $item_name = str_replace('%number%', $this->amount, $this->prefs['item_name']);
174
+ $item_name = $this->core->template_tags_general($item_name);
175
+
176
+ $this->redirect_to = 'https://www.moneybookers.com/app/payment.pl';
177
+
178
+ $redirect_fields = array(
179
+ 'pay_to_email' => $this->prefs['account'],
180
+ 'transaction_id' => $this->transaction_id,
181
+ 'return_url' => $this->get_thankyou(),
182
+ 'cancel_url' => $this->get_cancelled($this->transaction_id),
183
+ 'status_url' => $this->callback_url(),
184
+ 'return_url_text' => get_bloginfo('name'),
185
+ 'hide_login' => 1,
186
+ 'merchant_fields' => 'sales_data',
187
+ 'sales_data' => $this->post_id,
188
+ 'amount' => $this->cost,
189
+ 'currency' => $this->prefs['currency'],
190
+ 'detail1_description' => __('Item Name', 'mycred'),
191
+ 'detail1_text' => $item_name
192
+ );
193
+
194
+ // Customize Checkout Page
195
+ if (isset($this->prefs['account_title']) && ! empty($this->prefs['account_title']) ) {
196
+ $redirect_fields['recipient_description'] = $this->core->template_tags_general($this->prefs['account_title']);
197
+ }
198
+
199
+ if (isset($this->prefs['account_logo']) && ! empty($this->prefs['account_logo']) ) {
200
+ $redirect_fields['logo_url'] = $this->prefs['account_logo'];
201
+ }
202
+
203
+ if (isset($this->prefs['confirmation_note']) && ! empty($this->prefs['confirmation_note']) ) {
204
+ $redirect_fields['confirmation_note'] = $this->core->template_tags_general($this->prefs['confirmation_note']);
205
+ }
206
+
207
+ // If we want an email receipt for purchases
208
+ if (isset($this->prefs['email_receipt']) && ! empty($this->prefs['email_receipt']) ) {
209
+ $redirect_fields['status_url2'] = $this->prefs['account'];
210
+ }
211
+
212
+ // Gifting
213
+ if ($this->gifting ) {
214
+
215
+ $user = get_userdata($this->recipient_id);
216
+ $redirect_fields['detail2_description'] = __('Recipient', 'mycred');
217
+ $redirect_fields['detail2_text'] = $user->display_name;
218
+
219
+ }
220
+
221
+ $this->redirect_fields = $redirect_fields;
222
+
223
+ }
224
+
225
+ /**
226
+ * AJAX Buy Handler
227
+ *
228
+ * @since 1.8
229
+ * @version 1.0
230
+ */
231
+ public function ajax_buy()
232
+ {
233
+
234
+ // Construct the checkout box content
235
+ $content = $this->checkout_header();
236
+ $content .= $this->checkout_logo();
237
+ $content .= $this->checkout_order();
238
+ $content .= $this->checkout_cancel();
239
+ $content .= $this->checkout_footer();
240
+
241
+ // Return a JSON response
242
+ $this->send_json($content);
243
+
244
+ }
245
+
246
+ /**
247
+ * Checkout Page Body
248
+ * This gateway only uses the checkout body.
249
+ *
250
+ * @since 1.8
251
+ * @version 1.0
252
+ */
253
+ public function checkout_page_body()
254
+ {
255
+
256
+ echo $this->checkout_header();
257
+ echo $this->checkout_logo(false);
258
+
259
+ echo $this->checkout_order();
260
+ echo $this->checkout_cancel();
261
+
262
+ echo $this->checkout_footer();
263
+
264
+ }
265
+
266
+ /**
267
+ * Preferences
268
+ *
269
+ * @since 0.1
270
+ * @version 1.0.1
271
+ */
272
+ public function preferences()
273
+ {
274
+
275
+ add_filter('mycred_dropdown_currencies', array( $this, 'skrill_currencies' ));
276
+ $prefs = $this->prefs;
277
+
278
+ ?>
279
  <div class="row">
280
+ <div class="col-lg-6 col-md-6 col-sm-12 col-xs-12">
281
+ <h3><?php _e('Details', 'mycred'); ?></h3>
282
+ <div class="form-group">
283
+ <label for="<?php echo $this->field_id('account'); ?>"><?php _e('Account Email', 'mycred'); ?></label>
284
+ <input type="text" name="<?php echo $this->field_name('account'); ?>" id="<?php echo $this->field_id('account'); ?>" value="<?php echo esc_attr($prefs['account']); ?>" class="form-control" />
285
+ </div>
286
+ <div class="form-group">
287
+ <label for="<?php echo $this->field_id('word'); ?>"><?php _e('Secret Word', 'mycred'); ?></label>
288
+ <input type="text" name="<?php echo $this->field_name('word'); ?>" id="<?php echo $this->field_id('word'); ?>" value="<?php echo esc_attr($prefs['word']); ?>" class="form-control" />
289
+ </div>
290
+ <div class="form-group">
291
+ <label for="<?php echo $this->field_id('item_name'); ?>"><?php _e('Item Name', 'mycred'); ?></label>
292
+ <input type="text" name="<?php echo $this->field_name('item_name'); ?>" id="<?php echo $this->field_id('item_name'); ?>" value="<?php echo esc_attr($prefs['item_name']); ?>" class="form-control" />
293
+ </div>
294
+ <div class="form-group">
295
+ <label for="<?php echo $this->field_id('logo_url'); ?>"><?php _e('Logo URL', 'mycred'); ?></label>
296
+ <input type="text" name="<?php echo $this->field_name('logo_url'); ?>" id="<?php echo $this->field_id('logo_url'); ?>" value="<?php echo esc_attr($prefs['logo_url']); ?>" class="form-control" />
297
+ </div>
298
+ <div class="form-group">
299
+ <label for="<?php echo $this->field_id('email_receipt'); ?>"><input type="checkbox" name="<?php echo $this->field_name('email_receipt'); ?>" id="<?php echo $this->field_id('email_receipt'); ?>" value="1"<?php checked($prefs['email_receipt'], 1); ?> /> <?php _e('Ask Skrill to send me a confirmation email for each successful purchase.', 'mycred'); ?></label>
300
+ </div>
301
+ </div>
302
+ <div class="col-lg-6 col-md-6 col-sm-12 col-xs-12">
303
+ <h3><?php _e('Setup', 'mycred'); ?></h3>
304
+ <div class="form-group">
305
+ <label for="<?php echo $this->field_id('currency'); ?>"><?php _e('Currency', 'mycred'); ?></label>
306
+
307
+ <?php $this->currencies_dropdown('currency', 'mycred-gateway-skrill-currency'); ?>
308
+
309
+ </div>
310
+ <div class="form-group">
311
+ <label><?php _e('Exchange Rates', 'mycred'); ?></label>
312
+
313
+ <?php $this->exchange_rate_setup(); ?>
314
+
315
+ </div>
316
+ </div>
317
  </div>
318
+ <h3><?php _e('Checkout Page', 'mycred'); ?></h3>
319
  <div class="row">
320
+ <div class="col-lg-12 col-md-12 col-sm-12 col-xs-12">
321
+ <div class="form-group">
322
+ <label for="<?php echo $this->field_id('account_title'); ?>"><?php _e('Title', 'mycred'); ?></label>
323
+ <p><span class="description"><?php _e('If left empty, your account email is used as title on the Skill Payment Page.', 'mycred'); ?></span></p>
324
+ <input type="text" name="<?php echo $this->field_name('account_title'); ?>" id="<?php echo $this->field_id('account_title'); ?>" value="<?php echo esc_attr($prefs['account_title']); ?>" class="form-control" />
325
+ </div>
326
+ <div class="form-group">
327
+ <label for="<?php echo $this->field_id('confirmation_note'); ?>"><?php _e('Confirmation Note', 'mycred'); ?></label>
328
+ <p><span class="description"><?php _e('Optional text to show user once a transaction has been successfully completed. This text is shown by Skrill.', 'mycred'); ?></span></p>
329
+ <textarea rows="10" cols="50" name="<?php echo $this->field_name('confirmation_note'); ?>" id="<?php echo $this->field_id('confirmation_note'); ?>" class="form-control"><?php echo esc_html($prefs['confirmation_note']); ?></textarea>
330
+ </div>
331
+ </div>
332
  </div>
333
+ <?php
334
+
335
+ remove_filter('mycred_dropdown_currencies', array( $this, 'skrill_currencies' ));
336
+
337
+ }
338
+
339
+ /**
340
+ * Sanatize Prefs
341
+ *
342
+ * @since 0.1
343
+ * @version 1.1
344
+ */
345
+ public function sanitise_preferences( $data )
346
+ {
347
+
348
+ $new_data = array();
349
+
350
+ $new_data['sandbox'] = ( isset($data['sandbox']) ) ? 1 : 0;
351
+ $new_data['currency'] = sanitize_text_field($data['currency']);
352
+ $new_data['account'] = sanitize_text_field($data['account']);
353
+ $new_data['word'] = sanitize_text_field($data['word']);
354
+ $new_data['item_name'] = sanitize_text_field($data['item_name']);
355
+ $new_data['logo_url'] = sanitize_text_field($data['logo_url']);
356
+ $new_data['email_receipt'] = ( isset($data['email_receipt']) ) ? 1 : 0;
357
+ $new_data['account_title'] = substr($data['account_title'], 0, 30);
358
+ $new_data['confirmation_note'] = substr($data['confirmation_note'], 0, 240);
359
+
360
+ // If exchange is less then 1 we must start with a zero
361
+ if (isset($data['exchange']) ) {
362
+ foreach ( (array) $data['exchange'] as $type => $rate ) {
363
+ if ($rate != 1 && in_array(substr($rate, 0, 1), array( '.', ',' )) ) {
364
+ $data['exchange'][ $type ] = (float) '0' . $rate;
365
+ }
366
+ }
367
+ }
368
+ $new_data['exchange'] = $data['exchange'];
369
+
370
+ return $new_data;
371
+
372
+ }
373
+
374
+ /**
375
+ * Adjust Currencies
376
+ *
377
+ * @since 1.0.6
378
+ * @version 1.0
379
+ */
380
+ public function skrill_currencies( $currencies )
381
+ {
382
+
383
+ $currencies['RON'] = 'Romanian Leu';
384
+ $currencies['TRY'] = 'New Turkish Lira';
385
+ $currencies['RON'] = 'Romanian Leu';
386
+ $currencies['AED'] = 'Utd. Arab Emir. Dirham';
387
+ $currencies['MAD'] = 'Moroccan Dirham';
388
+ $currencies['QAR'] = 'Qatari Rial';
389
+ $currencies['SAR'] = 'Saudi Riyal';
390
+ $currencies['SKK'] = 'Slovakian Koruna';
391
+ $currencies['EEK'] = 'Estonian Kroon';
392
+ $currencies['BGN'] = 'Bulgarian Leva';
393
+ $currencies['ISK'] = 'Iceland Krona';
394
+ $currencies['INR'] = 'Indian Rupee';
395
+ $currencies['LVL'] = 'Latvian Lat';
396
+ $currencies['KRW'] = 'South-Korean Won';
397
+ $currencies['ZAR'] = 'South-African Rand';
398
+ $currencies['HRK'] = 'Croatian Kuna';
399
+ $currencies['LTL'] = 'Lithuanian Litas';
400
+ $currencies['JOD'] = 'Jordanian Dinar';
401
+ $currencies['OMR'] = 'Omani Rial';
402
+ $currencies['RSD'] = 'Serbian Dinar';
403
+ $currencies['TND'] = 'Tunisian Dinar';
404
+
405
+ unset($currencies['MXN']);
406
+ unset($currencies['BRL']);
407
+ unset($currencies['PHP']);
408
+
409
+ return $currencies;
410
+
411
+ }
412
+
413
+ }
414
  endif;
addons/buy-creds/images/index.php CHANGED
@@ -1,3 +1,3 @@
1
  <?php
2
  // Silence is golden.
3
- ?>
1
  <?php
2
  // Silence is golden.
3
+ ?>
addons/buy-creds/includes/buycred-functions.php CHANGED
@@ -1,205 +1,222 @@
1
  <?php
2
- if ( ! defined( 'MYCRED_PURCHASE' ) ) exit;
 
3
 
4
  /**
5
  * Get buyCRED Setup
6
- * @since 1.8
 
7
  * @version 1.0
8
  */
9
- if ( ! function_exists( 'mycred_get_buycred_settings' ) ) :
10
- function mycred_get_buycred_settings() {
11
-
12
- $defaults = array(
13
- 'types' => array( MYCRED_DEFAULT_TYPE_KEY ),
14
- 'checkout' => 'page',
15
- 'log' => '%plural% purchase',
16
- 'login' => __( 'Please login to purchase %_plural%', 'mycred' ),
17
- 'custom_log' => 0,
18
- 'thankyou' => array(
19
- 'use' => 'page',
20
- 'custom' => '',
21
- 'page' => ''
22
- ),
23
- 'cancelled' => array(
24
- 'use' => 'custom',
25
- 'custom' => '',
26
- 'page' => ''
27
- ),
28
- 'gifting' => array(
29
- 'members' => 1,
30
- 'authors' => 1,
31
- 'log' => __( 'Gift purchase from %display_name%.', 'mycred' )
32
- )
33
- );
34
-
35
- $settings = mycred_get_addon_settings( 'buy_creds' );
36
- $settings = wp_parse_args( $settings, $defaults );
37
-
38
- return apply_filters( 'mycred_get_buycred_settings', $settings );
39
-
40
- }
 
41
  endif;
42
 
43
  /**
44
  * Get Gateways
45
- * @since 1.8
 
46
  * @version 1.0
47
  */
48
- if ( ! function_exists( 'mycred_get_buycred_gateways' ) ) :
49
- function mycred_get_buycred_gateways() {
50
-
51
- $installed = array();
52
-
53
- // PayPal Standard
54
- $installed['paypal-standard'] = array(
55
- 'title' => 'PayPal Payments Standard',
56
- 'documentation' => 'http://codex.mycred.me/chapter-iii/buycred/payment-gateways/paypal/',
57
- 'callback' => array( 'myCRED_PayPal_Standard' ),
58
- 'icon' => 'dashicons-admin-generic',
59
- 'sandbox' => true,
60
- 'external' => true,
61
- 'custom_rate' => true
62
- );
63
-
64
- // BitPay
65
- $installed['bitpay'] = array(
66
- 'title' => 'BitPay (Bitcoins)',
67
- 'documentation' => 'http://codex.mycred.me/chapter-iii/buycred/payment-gateways/bitpay/',
68
- 'callback' => array( 'myCRED_Bitpay' ),
69
- 'icon' => 'dashicons-admin-generic',
70
- 'sandbox' => true,
71
- 'external' => true,
72
- 'custom_rate' => true
73
- );
74
-
75
- // NetBilling
76
- $installed['netbilling'] = array(
77
- 'title' => 'NETBilling',
78
- 'callback' => array( 'myCRED_NETbilling' ),
79
- 'documentation' => 'http://codex.mycred.me/chapter-iii/buycred/payment-gateways/netbilling/',
80
- 'icon' => 'dashicons-admin-generic',
81
- 'sandbox' => true,
82
- 'external' => true,
83
- 'custom_rate' => true
84
- );
85
-
86
- // Skrill
87
- $installed['skrill'] = array(
88
- 'title' => 'Skrill (Moneybookers)',
89
- 'callback' => array( 'myCRED_Skrill' ),
90
- 'documentation' => 'http://codex.mycred.me/chapter-iii/buycred/payment-gateways/skrill/',
91
- 'icon' => 'dashicons-admin-generic',
92
- 'sandbox' => true,
93
- 'external' => true,
94
- 'custom_rate' => true
95
- );
96
-
97
- // Bank Transfers
98
- $installed['bank'] = array(
99
- 'title' => __( 'Bank Transfer', 'mycred' ),
100
- 'documentation' => 'http://codex.mycred.me/chapter-iii/buycred/payment-gateways/bank-transfers/',
101
- 'callback' => array( 'myCRED_Bank_Transfer' ),
102
- 'icon' => 'dashicons-admin-generic',
103
- 'sandbox' => false,
104
- 'external' => false,
105
- 'custom_rate' => true
106
- );
107
-
108
- return apply_filters( 'mycred_setup_gateways', $installed );
109
-
110
- }
 
111
  endif;
112
 
113
  /**
114
  * Get buyCRED Setup
115
- * @since 1.8
 
116
  * @version 1.0
117
  */
118
- if ( ! function_exists( 'mycred_get_requested_gateway_id' ) ) :
119
- function mycred_get_requested_gateway_id() {
 
120
 
121
- $gateway_id = false;
122
 
123
- if ( isset( $_REQUEST['mycred_call'] ) )
124
- $gateway_id = trim( $_REQUEST['mycred_call'] );
125
 
126
- elseif ( isset( $_REQUEST['mycred_buy'] ) && is_user_logged_in() )
127
- $gateway_id = trim( $_REQUEST['mycred_buy'] );
 
128
 
129
- return apply_filters( 'mycred_gateway_id', $gateway_id );
130
 
131
- }
132
  endif;
133
 
134
  /**
135
  * Get buyCRED Setup
136
- * @since 1.8
 
137
  * @version 1.0
138
  */
139
- if ( ! function_exists( 'mycred_get_buycred_sale_setup' ) ) :
140
- function mycred_get_buycred_sale_setup( $point_type = MYCRED_DEFAULT_TYPE_KEY ) {
 
141
 
142
- $defaults = array(
143
- 'min' => '',
144
- 'max' => '',
145
- 'time' => ''
146
- );
147
 
148
- $saved = mycred_get_option( 'buycred-setup-' . $point_type, $defaults );
149
- $settings = shortcode_atts( $defaults, $saved );
150
 
151
- return apply_filters( 'mycred_get_buycred_sale_setup', $settings, $point_type );
152
 
153
- }
154
  endif;
155
 
156
  /**
157
  * Get Gateway References
158
- * @since 1.8
 
159
  * @version 1.0
160
  */
161
- if ( ! function_exists( 'mycred_get_buycred_gateway_refs' ) ) :
162
- function mycred_get_buycred_gateway_refs( $point_type = MYCRED_DEFAULT_TYPE_KEY ) {
 
163
 
164
- $references = array(
165
- 'buy_creds_with_paypal_standard',
166
- 'buy_creds_with_skrill',
167
- 'buy_creds_with_netbilling',
168
- 'buy_creds_with_bitpay',
169
- 'buy_creds_with_bank'
170
- );
171
 
172
- return apply_filters( 'mycred_buycred_log_refs', $references, $point_type );
173
 
174
- }
175
  endif;
176
 
177
  /**
178
  * Purchase Limit Dropdown
179
- * @since 1.8
 
180
  * @version 1.0
181
  */
182
- if ( ! function_exists( 'mycred_purchase_limit_dropdown' ) ) :
183
- function mycred_purchase_limit_dropdown( $name = '', $id = '', $selected = '' ) {
184
-
185
- $options = apply_filters( 'mycred_buycred_limit_dropdown', array(
186
- '' => __( 'No limit', 'mycred' ),
187
- 'day' => __( '/ Day', 'mycred' ),
188
- 'week' => __( '/ Week', 'mycred' ),
189
- 'month' => __( '/ Month', 'mycred' )
190
- ) );
191
-
192
- $output = '<select name="' . $name . '" id="' . $id . '" class="form-control">';
193
- foreach ( $options as $value => $label ) {
194
- $output .= '<option value="' . $value . '"';
195
- if ( $selected == $value ) $output .= ' selected="selected"';
196
- $output .= '>' . $label . '</option>';
197
- }
198
- $output .= '</select>';
199
-
200
- echo $output;
201
-
202
- }
 
 
 
 
203
  endif;
204
 
205
  /**
@@ -207,131 +224,152 @@ endif;
207
  * Returns false if the user is excluded or when using this function with invalid values.
208
  * Else returns true if the user can buy as much as they wish else a point value if a max limit is enforced.
209
  * Note that this can result in a zero value being returned, if the user has reached their purchase limit but are not excluded.
210
- * @since 1.8
 
211
  * @version 1.0
212
  */
213
- if ( ! function_exists( 'mycred_user_can_buycred' ) ) :
214
- function mycred_user_can_buycred( $user_id = 0, $point_type = MYCRED_DEFAULT_TYPE_KEY ) {
 
215
 
216
- $can_buy = false;
217
- $total = 0;
218
- $settings = mycred_get_buycred_settings();
219
- $user_id = absint( $user_id );
220
 
221
- // Need a valid ID, the point type must be enabled for sale
222
- if ( $user_id === 0 || ! in_array( $point_type, $settings['types'] ) ) return $can_buy;
 
223
 
224
- $mycred = mycred( $point_type );
225
- $setup = mycred_get_buycred_sale_setup( $point_type );
226
 
227
- // We need to get the lowest possible value for this point type or the minimum amount we set in our settings
228
- $minimum = $mycred->number( ( ( $setup['min'] == '' ) ? $mycred->get_lowest_value() : $setup['min'] ) );
229
 
230
- $can_buy = true;
231
 
232
- // Incase we are enforcing a maximum we need to check how much we already purchased this period
233
- // So we can see how much is left on the limit
234
- if ( MYCRED_ENABLE_LOGGING && $setup['time'] != '' && $setup['max'] != '' && $setup['max'] > 0 ) {
235
 
236
- $maximum = $mycred->number( $setup['max'] );
237
 
238
- $total = mycred_get_users_total_purchase( $user_id, $point_type, $setup['time'] );
239
- $total = $mycred->number( $total );
240
 
241
- if ( $total < $maximum )
242
- $can_buy = $mycred->number( $maximum - $total );
 
243
 
244
- // Now that we have a "remaining" amount, we need to make sure it is more than the minimum
245
- if ( $can_buy < $minimum )
246
- $can_buy = 0;
 
247
 
248
- }
249
 
250
- return apply_filters( 'mycred_user_can_buycred', $can_buy, $user_id, $point_type, $total );
251
 
252
- }
253
  endif;
254
 
255
  /**
256
  * Is Gateway Usable
257
  * Checks if a gateway (based on it's ID) is "usable" as in it is installed and active.
258
  * Note that this will not take into account if sandbox mode is used or not.
259
- * @since 1.8
 
260
  * @version 1.0
261
  */
262
- if ( ! function_exists( 'mycred_buycred_gateway_is_usable' ) ) :
263
- function mycred_buycred_gateway_is_usable( $gateway_id ) {
 
264
 
265
- global $buycred_instance;
266
 
267
- $usable = false;
268
- if ( isset( $buycred_instance->active ) && array_key_exists( $gateway_id, $buycred_instance->active ) )
269
- $usable = true;
 
270
 
271
- return $usable;
272
 
273
- }
274
  endif;
275
 
276
  /**
277
  * Get Users Total Purchase
278
- * @since 1.8
 
279
  * @version 1.0
280
  */
281
- if ( ! function_exists( 'mycred_get_users_total_purchase' ) ) :
282
- function mycred_get_users_total_purchase( $user_id = false, $point_type = MYCRED_DEFAULT_TYPE_KEY, $timeframe = 'all' ) {
 
283
 
284
- $from = 0;
285
- $total = 0;
286
- if ( ! MYCRED_ENABLE_LOGGING ) return $total;
 
287
 
288
- $user_id = absint( $user_id );
289
- if ( $user_id === 0 || ! mycred_point_type_exists( $point_type ) ) return $total;
 
290
 
291
- global $wpdb, $mycred_log_table;
292
 
293
- if ( $timeframe != 'all' ) {
294
 
295
- $now = current_time( 'timestamp' );
296
 
297
- // By default we assume $timeframe = 'day'
298
- $today = strtotime( date( 'Y-m-d' ) . ' midnight', $now );
299
 
300
- // Per week
301
- if ( $timeframe == 'week' ) {
302
 
303
- $weekday = date( 'w', $now );
304
- $thisweek = strtotime( '-' . ( $weekday+1 ) . ' days midnight', $now );
305
- if ( get_option( 'start_of_week' ) == $weekday )
306
- $thisweek = $today;
 
307
 
308
- $from = $thisweek;
309
 
310
- }
311
 
312
- // Per month
313
- elseif ( $timeframe == 'month' )
314
- $from = strtotime( date( 'Y-m-01' ) . ' midnight', $now );
 
315
 
316
- }
317
 
318
- // First we need to count the completed purchases
319
- $completed = $wpdb->get_var( $wpdb->prepare( "
 
 
320
  SELECT SUM(creds)
321
  FROM {$mycred_log_table}
322
  WHERE user_id = %d
323
  AND ctype = %s
324
  AND ref LIKE %s
325
- AND time > %d", $user_id, $point_type, 'buy_creds_with_%', $from ) );
 
 
326
 
327
- if ( $completed === NULL ) $completed = 0;
 
328
 
329
- // Multisite Master Template support
330
- $posts = mycred_get_db_column( 'posts' );
331
- $postmeta = mycred_get_db_column( 'postmeta' );
332
 
333
- // Next we need to tally up pending payments
334
- $pending = $wpdb->get_var( $wpdb->prepare( "
 
 
335
  SELECT SUM( a.meta_value )
336
  FROM {$posts} p
337
  LEFT JOIN {$postmeta} a
@@ -341,420 +379,480 @@ if ( ! function_exists( 'mycred_get_users_total_purchase' ) ) :
341
  WHERE p.post_type = %s
342
  AND p.post_status = 'publish'
343
  AND p.post_author = %d
344
- AND t.meta_value = %s;", 'buycred_payment', $user_id, $point_type ) );
 
 
345
 
346
- if ( $pending === NULL ) $pending = 0;
 
347
 
348
- $total = $completed + $pending;
349
 
350
- return apply_filters( 'mycred_get_users_total_purchase', $total, $user_id, $point_type, $completed, $total );
351
 
352
- }
353
  endif;
354
 
355
  /**
356
  * Get Pending Payment
357
- * @since 1.7
 
358
  * @version 1.0
359
  */
360
- if ( ! function_exists( 'buycred_get_pending_payment_id' ) ) :
361
- function buycred_get_pending_payment_id( $payment_id = NULL ) {
 
362
 
363
- if ( $payment_id === NULL || $payment_id == '' ) return false;
 
364
 
365
- // In case we are using the transaction ID instead of the post ID.
366
- $post_id = false;
367
- if ( ! is_numeric( $payment_id ) ) {
368
 
369
- $post = mycred_get_page_by_title( strtoupper( $payment_id ), OBJECT, 'buycred_payment' );
370
- if ( $post === NULL ) return false;
 
371
 
372
- $post_id = $post->ID;
373
 
374
- }
375
- else {
376
- $post_id = absint( $payment_id );
377
- }
378
 
379
- return $post_id;
380
 
381
- }
382
  endif;
383
 
384
  /**
385
  * Get Pending Payment
386
- * @since 1.7
 
387
  * @version 1.0
388
  */
389
- if ( ! function_exists( 'buycred_get_pending_payment' ) ) :
390
- function buycred_get_pending_payment( $payment_id = NULL ) {
391
-
392
- // Construct fake pending object ( when no pending payment object exists )
393
- if ( is_array( $payment_id ) ) {
394
-
395
- $pending_payment = new StdClass();
396
- $pending_payment->payment_id = false;
397
- $pending_payment->public_id = $payment_id['public_id'];
398
- $pending_payment->point_type = $payment_id['point_type'];
399
- $pending_payment->amount = $payment_id['amount'];
400
- $pending_payment->cost = $payment_id['cost'];
401
- $pending_payment->currency = $payment_id['currency'];
402
- $pending_payment->buyer_id = $payment_id['buyer_id'];
403
- $pending_payment->recipient_id = $payment_id['recipient_id'];
404
- $pending_payment->gateway_id = $payment_id['gateway_id'];
405
- $pending_payment->transaction_id = $payment_id['transaction_id'];
406
- $pending_payment->cancel_url = false;
407
- $pending_payment->pay_now_url = false;
408
-
409
- }
410
-
411
- else {
412
-
413
- $payment_id = buycred_get_pending_payment_id( $payment_id );
414
-
415
- if ( $payment_id === false ) return false;
416
-
417
- $pending_payment = new StdClass();
418
- $pending_payment->payment_id = absint( $payment_id );
419
- $pending_payment->public_id = get_the_title( $payment_id );
420
- $pending_payment->point_type = mycred_get_post_meta( $payment_id, 'point_type', true );
421
- $pending_payment->amount = mycred_get_post_meta( $payment_id, 'amount', true );
422
- $pending_payment->cost = mycred_get_post_meta( $payment_id, 'cost', true );
423
- $pending_payment->currency = mycred_get_post_meta( $payment_id, 'currency', true );
424
- $pending_payment->buyer_id = mycred_get_post_meta( $payment_id, 'from', true );
425
- $pending_payment->recipient_id = mycred_get_post_meta( $payment_id, 'to', true );
426
- $pending_payment->gateway_id = mycred_get_post_meta( $payment_id, 'gateway', true );
427
- $pending_payment->transaction_id = $pending_payment->public_id;
428
-
429
- $pending_payment->cancel_url = buycred_get_cancel_transaction_url( $pending_payment->public_id );
430
-
431
- $pending_payment->pay_now_url = add_query_arg( array(
432
- 'mycred_buy' => $pending_payment->gateway_id,
433
- 'amount' => $pending_payment->amount,
434
- 'revisit' => $payment_id,
435
- 'token' => wp_create_nonce( 'mycred-buy-creds' )
436
- ), set_url_scheme( 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'] ) );
437
-
438
- }
439
-
440
- return apply_filters( 'buycred_get_pending_payment', $pending_payment, $payment_id );
441
-
442
- }
 
 
 
 
443
  endif;
444
 
445
  /**
446
  * Add Pending Comment
447
- * @since 1.7
 
448
  * @version 1.1
449
  */
450
- if ( ! function_exists( 'buycred_add_pending_comment' ) ) :
451
- function buycred_add_pending_comment( $payment_id = NULL, $comment = NULL, $time = NULL ) {
452
-
453
- if ( ! MYCRED_BUY_PENDING_COMMENTS ) return true;
454
-
455
- $post_id = buycred_get_pending_payment_id( $payment_id );
456
- if ( $post_id === false ) return false;
457
-
458
- global $mycred_modules;
459
-
460
- if ( $time === NULL || $time == 'now' )
461
- $time = current_time( 'mysql' );
462
-
463
- $author = 'buyCRED';
464
- $gateway = mycred_get_post_meta( $post_id, 'gateway', true );
465
- $gateways = mycred_get_buycred_gateways();
466
- $author_url = sprintf( 'buyCRED: %s %s', __( 'Unknown Gateway', 'mycred' ), $gateway );
467
- $author_email = apply_filters( 'mycred_buycred_comment_email', 'buycred-service@mycred.me' );
468
-
469
- if ( array_key_exists( $gateway, $gateways ) )
470
- $author = sprintf( 'buyCRED: %s %s', $gateways[ $gateway ]['title'], __( 'Gateway', 'mycred' ) );
471
-
472
- return wp_insert_comment( array(
473
- 'comment_post_ID' => $post_id,
474
- 'comment_author' => $author,
475
- 'comment_author_email' => $author_email,
476
- 'comment_content' => $comment,
477
- 'comment_type' => 'buycred',
478
- 'comment_author_IP' => $_SERVER['REMOTE_ADDR'],
479
- 'comment_date' => $time,
480
- 'comment_approved' => 1,
481
- 'user_id' => 0
482
- ) );
483
-
484
- }
 
 
 
 
 
 
 
485
  endif;
486
 
487
  /**
488
  * Get Cancel URL
489
- * @since 1.7
 
490
  * @version 1.0.1
491
  */
492
- if ( ! function_exists( 'buycred_get_cancel_transaction_url' ) ) :
493
- function buycred_get_cancel_transaction_url( $transaction_id = NULL ) {
 
494
 
495
- $settings = mycred_get_buycred_settings();
496
- $base = set_url_scheme( 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'] );
497
 
498
- // Cancel page
499
- if ( $settings['cancelled']['use'] == 'page' ) {
500
 
501
- if ( ! empty( $settings['cancelled']['page'] ) && $settings['cancelled']['page'] > 0 )
502
- $base = mycred_get_permalink( $settings['cancelled']['page'] );
 
503
 
504
- }
505
 
506
- // Custom URL
507
- elseif ( $settings['cancelled']['use'] != 'page' && $settings['cancelled']['custom'] != '' ) {
508
 
509
- $base = esc_url_raw( $settings['cancelled']['custom'] );
510
 
511
- }
512
 
513
- // Override
514
- if ( isset( $_REQUEST['return_to'] ) && esc_url_raw( $_REQUEST['return_to'] ) != '' )
515
- $base = esc_url_raw( $_REQUEST['return_to'] );
 
516
 
517
- if ( $transaction_id !== NULL )
518
- $url = add_query_arg( array( 'buycred-cancel' => $transaction_id, '_token' => wp_create_nonce( 'buycred-cancel-pending-payment' ) ), $base );
519
- else
520
- $url = $base;
 
521
 
522
- return apply_filters( 'mycred_buycred_cancel_url', $url, $transaction_id, $base );
523
 
524
- }
525
  endif;
526
 
527
  /**
528
  * Get Users Pending Payments
529
- * @since 1.7
 
530
  * @version 1.0.2
531
  */
532
- if ( ! function_exists( 'buycred_get_users_pending_payments' ) ) :
533
- function buycred_get_users_pending_payments( $user_id = NULL, $point_type = '' ) {
 
534
 
535
- $user_id = absint( $user_id );
536
- if ( $user_id === 0 ) return false;
 
537
 
538
- $pending = mycred_get_user_meta( $user_id, 'buycred_pending_payments', '', true );
539
- if ( ! is_array( $pending ) ) {
540
 
541
- global $wpdb;
542
 
543
- $pending = array();
544
- $table = mycred_get_db_column( 'posts' );
545
- $saved = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM {$table} posts WHERE posts.post_type = 'buycred_payment' AND posts.post_author = %d AND posts.post_status = 'publish';", $user_id ) );
546
 
547
- if ( ! empty( $saved ) ) {
548
 
549
- foreach ( $saved as $entry ) {
550
 
551
- $point_type = mycred_get_post_meta( $entry->ID, 'point_type', true );
552
- if ( $point_type == '' ) $point_type = MYCRED_DEFAULT_TYPE_KEY;
 
553
 
554
- if ( ! array_key_exists( $point_type, $pending ) )
555
- $pending[ $point_type ] = array();
 
556
 
557
- $pending[ $point_type ][] = buycred_get_pending_payment( (int) $entry->ID );
558
 
559
- }
560
 
561
- }
562
 
563
- else {
564
 
565
- if ( $point_type == '' )
566
- $pending[ MYCRED_DEFAULT_TYPE_KEY ] = array();
567
- else
568
- $pending[ $point_type ] = array();
 
569
 
570
- }
571
 
572
- mycred_add_user_meta( $user_id, 'buycred_pending_payments', '', $pending, true );
573
 
574
- }
575
 
576
- if ( $point_type != '' && mycred_point_type_exists( $point_type ) ) {
577
 
578
- if ( ! is_array( $pending ) || ! array_key_exists( $point_type, $pending ) )
579
- return false;
 
580
 
581
- return $pending[ $point_type ];
582
 
583
- }
584
 
585
- return $pending;
586
 
587
- }
588
  endif;
589
 
590
  /**
591
  * buyCRED Gateway Constructor
592
- * @since 1.7
 
593
  * @version 1.1
594
  */
595
- if ( ! function_exists( 'buycred_gateway' ) ) :
596
- function buycred_gateway( $gateway_id = NULL ) {
 
597
 
598
- global $buycred_gateway, $mycred_modules;
599
 
600
- if ( isset( $buycred_gateway )
601
- && ( $buycred_gateway instanceof myCRED_Payment_Gateway )
602
- && ( $gateway_id === $buycred_gateway->id )
603
- ) {
604
- return $buycred_gateway;
605
- }
606
 
607
- $buycred_gateway = false;
608
- $installed = $mycred_modules['solo']['buycred']->get();
609
- if ( array_key_exists( $gateway_id, $installed ) ) {
610
 
611
- $class = $installed[ $gateway_id ]['callback'][0];
612
 
613
- // Construct Gateway
614
- $buycred_gateway = new $class( $mycred_modules['solo']['buycred']->gateway_prefs );
615
 
616
- }
617
 
618
- return $buycred_gateway;
619
 
620
- }
621
  endif;
622
 
623
  /**
624
  * Delete Pending Payment
625
- * @since 1.7
 
626
  * @version 1.0
627
  */
628
- if ( ! function_exists( 'buycred_trash_pending_payment' ) ) :
629
- function buycred_trash_pending_payment( $payment_id = NULL ) {
 
630
 
631
- $pending_payment = buycred_get_pending_payment( $payment_id );
632
- if ( $pending_payment === false ) return false;
 
633
 
634
- mycred_delete_user_meta( $pending_payment->buyer_id, 'buycred_pending_payments' );
635
 
636
- return wp_trash_post( $pending_payment->payment_id );
637
 
638
- }
639
  endif;
640
 
641
  /**
642
  * Complete Pending Payment
643
- * @since 1.7
 
644
  * @version 1.0
645
  */
646
- if ( ! function_exists( 'buycred_complete_pending_payment' ) ) :
647
- function buycred_complete_pending_payment( $pending_id ) {
 
648
 
649
- $pending_payment = buycred_get_pending_payment( $pending_id );
650
- if ( $pending_payment === false ) return false;
 
651
 
652
- $gateway = buycred_gateway( $pending_payment->gateway_id );
653
- if ( $gateway === false ) return false;
 
654
 
655
- // Complete Payment
656
- $paid = $gateway->complete_payment( $pending_payment, $pending_payment->transaction_id );
657
 
658
- if ( $paid )
659
- return buycred_trash_pending_payment( $pending_id );
 
660
 
661
- return $paid;
662
 
663
- }
664
  endif;
665
 
666
  /**
667
  * Checkout Title
668
- * @since 1.8
 
669
  * @version 1.0
670
  */
671
- if ( ! function_exists( 'buycred_checkout_title' ) ) :
672
- function buycred_checkout_title() {
 
673
 
674
- global $buycred_instance;
675
 
676
- if ( $buycred_instance->gateway !== false )
677
- $buycred_instance->gateway->checkout_page_title();
 
678
 
679
- }
680
  endif;
681
 
682
  /**
683
  * Checkout Body
684
- * @since 1.8
 
685
  * @version 1.0
686
  */
687
- if ( ! function_exists( 'buycred_checkout_body' ) ) :
688
- function buycred_checkout_body() {
 
689
 
690
- global $buycred_instance;
691
 
692
- if ( $buycred_instance->gateway !== false )
693
- $buycred_instance->gateway->checkout_page_body();
 
694
 
695
- }
696
  endif;
697
 
698
  /**
699
  * Checkout Logo
700
- * @since 1.8
 
701
  * @version 1.0
702
  */
703
- if ( ! function_exists( 'buycred_checkout_logo' ) ) :
704
- function buycred_checkout_logo() {
 
705
 
706
- global $buycred_instance;
707
 
708
- if ( $buycred_instance->gateway !== false )
709
- $buycred_instance->gateway->checkout_logo();
 
710
 
711
- }
712
  endif;
713
 
714
  /**
715
  * Checkout Order
716
- * @since 1.8
 
717
  * @version 1.0
718
  */
719
- if ( ! function_exists( 'buycred_checkout_order' ) ) :
720
- function buycred_checkout_order() {
 
721
 
722
- global $buycred_instance;
723
 
724
- if ( $buycred_instance->gateway !== false )
725
- $buycred_instance->gateway->checkout_order();
 
726
 
727
- }
728
  endif;
729
 
730
  /**
731
  * Checkout Cancel
732
- * @since 1.8
 
733
  * @version 1.0
734
  */
735
- if ( ! function_exists( 'buycred_checkout_cancel' ) ) :
736
- function buycred_checkout_cancel() {
 
737
 
738
- global $buycred_instance;
739
 
740
- if ( $buycred_instance->gateway !== false )
741
- $buycred_instance->gateway->checkout_cancel();
 
742
 
743
- }
744
  endif;
745
 
746
  /**
747
  * Checkout Footer
748
- * @since 1.8
 
749
  * @version 1.0
750
  */
751
- if ( ! function_exists( 'buycred_checkout_footer' ) ) :
752
- function buycred_checkout_footer() {
 
753
 
754
- global $buycred_instance;
755
 
756
- if ( $buycred_instance->gateway !== false )
757
- $buycred_instance->gateway->checkout_page_footer();
 
758
 
759
- }
760
- endif;
1
  <?php
2
+ if (! defined('MYCRED_PURCHASE') ) { exit;
3
+ }
4
 
5
  /**
6
  * Get buyCRED Setup
7
+ *
8
+ * @since 1.8
9
  * @version 1.0
10
  */
11
+ if (! function_exists('mycred_get_buycred_settings') ) :
12
+ function mycred_get_buycred_settings()
13
+ {
14
+
15
+ $defaults = array(
16
+ 'types' => array( MYCRED_DEFAULT_TYPE_KEY ),
17
+ 'checkout' => 'page',
18
+ 'log' => '%plural% purchase',
19
+ 'login' => __('Please login to purchase %_plural%', 'mycred'),
20
+ 'custom_log' => 0,
21
+ 'thankyou' => array(
22
+ 'use' => 'page',
23
+ 'custom' => '',
24
+ 'page' => ''
25
+ ),
26
+ 'cancelled' => array(
27
+ 'use' => 'custom',
28
+ 'custom' => '',
29
+ 'page' => ''
30
+ ),
31
+ 'gifting' => array(
32
+ 'members' => 1,
33
+ 'authors' => 1,
34
+ 'log' => __('Gift purchase from %display_name%.', 'mycred')
35
+ )
36
+ );
37
+
38
+ $settings = mycred_get_addon_settings('buy_creds');
39
+ $settings = wp_parse_args($settings, $defaults);
40
+
41
+ return apply_filters('mycred_get_buycred_settings', $settings);
42
+
43
+ }
44
  endif;
45
 
46
  /**
47
  * Get Gateways
48
+ *
49
+ * @since 1.8
50
  * @version 1.0
51
  */
52
+ if (! function_exists('mycred_get_buycred_gateways') ) :
53
+ function mycred_get_buycred_gateways()
54
+ {
55
+
56
+ $installed = array();
57
+
58
+ // PayPal Standard
59
+ $installed['paypal-standard'] = array(
60
+ 'title' => 'PayPal Payments Standard',
61
+ 'documentation' => 'http://codex.mycred.me/chapter-iii/buycred/payment-gateways/paypal/',
62
+ 'callback' => array( 'myCRED_PayPal_Standard' ),
63
+ 'icon' => 'dashicons-admin-generic',
64
+ 'sandbox' => true,
65
+ 'external' => true,
66
+ 'custom_rate' => true
67
+ );
68
+
69
+ // BitPay
70
+ $installed['bitpay'] = array(
71
+ 'title' => 'BitPay (Bitcoins)',
72
+ 'documentation' => 'http://codex.mycred.me/chapter-iii/buycred/payment-gateways/bitpay/',
73
+ 'callback' => array( 'myCRED_Bitpay' ),
74
+ 'icon' => 'dashicons-admin-generic',
75
+ 'sandbox' => true,
76
+ 'external' => true,
77
+ 'custom_rate' => true
78
+ );
79
+
80
+ // NetBilling
81
+ $installed['netbilling'] = array(
82
+ 'title' => 'NETBilling',
83
+ 'callback' => array( 'myCRED_NETbilling' ),
84
+ 'documentation' => 'http://codex.mycred.me/chapter-iii/buycred/payment-gateways/netbilling/',
85
+ 'icon' => 'dashicons-admin-generic',
86
+ 'sandbox' => true,
87
+ 'external' => true,
88
+ 'custom_rate' => true
89
+ );
90
+
91
+ // Skrill
92
+ $installed['skrill'] = array(
93
+ 'title' => 'Skrill (Moneybookers)',
94
+ 'callback' => array( 'myCRED_Skrill' ),
95
+ 'documentation' => 'http://codex.mycred.me/chapter-iii/buycred/payment-gateways/skrill/',
96
+ 'icon' => 'dashicons-admin-generic',
97
+ 'sandbox' => true,
98
+ 'external' => true,
99
+ 'custom_rate' => true
100
+ );
101
+
102
+ // Bank Transfers
103
+ $installed['bank'] = array(
104
+ 'title' => __('Bank Transfer', 'mycred'),
105
+ 'documentation' => 'http://codex.mycred.me/chapter-iii/buycred/payment-gateways/bank-transfers/',
106
+ 'callback' => array( 'myCRED_Bank_Transfer' ),
107
+ 'icon' => 'dashicons-admin-generic',
108
+ 'sandbox' => false,
109
+ 'external' => false,
110
+ 'custom_rate' => true
111
+ );
112
+
113
+ return apply_filters('mycred_setup_gateways', $installed);
114
+
115
+ }
116
  endif;
117
 
118
  /**
119
  * Get buyCRED Setup
120
+ *
121
+ * @since 1.8
122
  * @version 1.0
123
  */
124
+ if (! function_exists('mycred_get_requested_gateway_id') ) :
125
+ function mycred_get_requested_gateway_id()
126
+ {
127
 
128
+ $gateway_id = false;
129
 
130
+ if (isset($_REQUEST['mycred_call']) ) {
131
+ $gateway_id = sanitize_key($_REQUEST['mycred_call']);
132
 
133
+ } elseif (isset($_REQUEST['mycred_buy']) && is_user_logged_in() ) {
134
+ $gateway_id = sanitize_key($_REQUEST['mycred_buy']);
135
+ }
136
 
137
+ return apply_filters('mycred_gateway_id', $gateway_id);
138
 
139
+ }
140
  endif;
141
 
142
  /**
143
  * Get buyCRED Setup
144
+ *
145
+ * @since 1.8
146
  * @version 1.0
147
  */
148
+ if (! function_exists('mycred_get_buycred_sale_setup') ) :
149
+ function mycred_get_buycred_sale_setup( $point_type = MYCRED_DEFAULT_TYPE_KEY )
150
+ {
151
 
152
+ $defaults = array(
153
+ 'min' => '',
154
+ 'max' => '',
155
+ 'time' => ''
156
+ );
157
 
158
+ $saved = mycred_get_option('buycred-setup-' . $point_type, $defaults);
159
+ $settings = shortcode_atts($defaults, $saved);
160
 
161
+ return apply_filters('mycred_get_buycred_sale_setup', $settings, $point_type);
162
 
163
+ }
164
  endif;
165
 
166
  /**
167
  * Get Gateway References
168
+ *
169
+ * @since 1.8
170
  * @version 1.0
171
  */
172
+ if (! function_exists('mycred_get_buycred_gateway_refs') ) :
173
+ function mycred_get_buycred_gateway_refs( $point_type = MYCRED_DEFAULT_TYPE_KEY )
174
+ {
175
 
176
+ $references = array(
177
+ 'buy_creds_with_paypal_standard',
178
+ 'buy_creds_with_skrill',
179
+ 'buy_creds_with_netbilling',
180
+ 'buy_creds_with_bitpay',
181
+ 'buy_creds_with_bank'
182
+ );
183
 
184
+ return apply_filters('mycred_buycred_log_refs', $references, $point_type);
185
 
186
+ }
187
  endif;
188
 
189
  /**
190
  * Purchase Limit Dropdown
191
+ *
192
+ * @since 1.8
193
  * @version 1.0
194
  */
195
+ if (! function_exists('mycred_purchase_limit_dropdown') ) :
196
+ function mycred_purchase_limit_dropdown( $name = '', $id = '', $selected = '' )
197
+ {
198
+
199
+ $options = apply_filters(
200
+ 'mycred_buycred_limit_dropdown', array(
201
+ '' => __('No limit', 'mycred'),
202
+ 'day' => __('/ Day', 'mycred'),
203
+ 'week' => __('/ Week', 'mycred'),
204
+ 'month' => __('/ Month', 'mycred')
205
+ )
206
+ );
207
+
208
+ $output = '<select name="' . $name . '" id="' . $id . '" class="form-control">';
209
+ foreach ( $options as $value => $label ) {
210
+ $output .= '<option value="' . $value . '"';
211
+ if ($selected == $value ) { $output .= ' selected="selected"';
212
+ }
213
+ $output .= '>' . $label . '</option>';
214
+ }
215
+ $output .= '</select>';
216
+
217
+ echo $output;
218
+
219
+ }
220
  endif;
221
 
222
  /**
224
  * Returns false if the user is excluded or when using this function with invalid values.
225
  * Else returns true if the user can buy as much as they wish else a point value if a max limit is enforced.
226
  * Note that this can result in a zero value being returned, if the user has reached their purchase limit but are not excluded.
227
+ *
228
+ * @since 1.8
229
  * @version 1.0
230
  */
231
+ if (! function_exists('mycred_user_can_buycred') ) :
232
+ function mycred_user_can_buycred( $user_id = 0, $point_type = MYCRED_DEFAULT_TYPE_KEY )
233
+ {
234
 
235
+ $can_buy = false;
236
+ $total = 0;
237
+ $settings = mycred_get_buycred_settings();
238
+ $user_id = absint($user_id);
239
 
240
+ // Need a valid ID, the point type must be enabled for sale
241
+ if ($user_id === 0 || ! in_array($point_type, $settings['types']) ) { return $can_buy;
242
+ }
243
 
244
+ $mycred = mycred($point_type);
245
+ $setup = mycred_get_buycred_sale_setup($point_type);
246
 
247
+ // We need to get the lowest possible value for this point type or the minimum amount we set in our settings
248
+ $minimum = $mycred->number(( ( $setup['min'] == '' ) ? $mycred->get_lowest_value() : $setup['min'] ));
249
 
250
+ $can_buy = true;
251
 
252
+ // Incase we are enforcing a maximum we need to check how much we already purchased this period
253
+ // So we can see how much is left on the limit
254
+ if (MYCRED_ENABLE_LOGGING && $setup['time'] != '' && $setup['max'] != '' && $setup['max'] > 0 ) {
255
 
256
+ $maximum = $mycred->number($setup['max']);
257
 
258
+ $total = mycred_get_users_total_purchase($user_id, $point_type, $setup['time']);
259
+ $total = $mycred->number($total);
260
 
261
+ if ($total < $maximum ) {
262
+ $can_buy = $mycred->number($maximum - $total);
263
+ }
264
 
265
+ // Now that we have a "remaining" amount, we need to make sure it is more than the minimum
266
+ if ($can_buy < $minimum ) {
267
+ $can_buy = 0;
268
+ }
269
 
270
+ }
271
 
272
+ return apply_filters('mycred_user_can_buycred', $can_buy, $user_id, $point_type, $total);
273
 
274
+ }
275
  endif;
276
 
277
  /**
278
  * Is Gateway Usable
279
  * Checks if a gateway (based on it's ID) is "usable" as in it is installed and active.
280
  * Note that this will not take into account if sandbox mode is used or not.
281
+ *
282
+ * @since 1.8
283
  * @version 1.0
284
  */
285
+ if (! function_exists('mycred_buycred_gateway_is_usable') ) :
286
+ function mycred_buycred_gateway_is_usable( $gateway_id )
287
+ {
288
 
289
+ global $buycred_instance;
290
 
291
+ $usable = false;
292
+ if (isset($buycred_instance->active) && array_key_exists($gateway_id, $buycred_instance->active) ) {
293
+ $usable = true;
294
+ }
295
 
296
+ return $usable;
297
 
298
+ }
299
  endif;
300
 
301
  /**
302
  * Get Users Total Purchase
303
+ *
304
+ * @since 1.8
305
  * @version 1.0
306
  */
307
+ if (! function_exists('mycred_get_users_total_purchase') ) :
308
+ function mycred_get_users_total_purchase( $user_id = false, $point_type = MYCRED_DEFAULT_TYPE_KEY, $timeframe = 'all' )
309
+ {
310
 
311
+ $from = 0;
312
+ $total = 0;
313
+ if (! MYCRED_ENABLE_LOGGING ) { return $total;
314
+ }
315
 
316
+ $user_id = absint($user_id);
317
+ if ($user_id === 0 || ! mycred_point_type_exists($point_type) ) { return $total;
318
+ }
319
 
320
+ global $wpdb, $mycred_log_table;
321
 
322
+ if ($timeframe != 'all' ) {
323
 
324
+ $now = current_time('timestamp');
325
 
326
+ // By default we assume $timeframe = 'day'
327
+ $today = strtotime(date('Y-m-d') . ' midnight', $now);
328
 
329
+ // Per week
330
+ if ($timeframe == 'week' ) {
331
 
332
+ $weekday = date('w', $now);
333
+ $thisweek = strtotime('-' . ( $weekday+1 ) . ' days midnight', $now);
334
+ if (get_option('start_of_week') == $weekday ) {
335
+ $thisweek = $today;
336
+ }
337
 
338
+ $from = $thisweek;
339
 
340
+ }
341
 
342
+ // Per month
343
+ elseif ($timeframe == 'month' ) {
344
+ $from = strtotime(date('Y-m-01') . ' midnight', $now);
345
+ }
346
 
347
+ }
348
 
349
+ // First we need to count the completed purchases
350
+ $completed = $wpdb->get_var(
351
+ $wpdb->prepare(
352
+ "
353
  SELECT SUM(creds)
354
  FROM {$mycred_log_table}
355
  WHERE user_id = %d
356
  AND ctype = %s
357
  AND ref LIKE %s
358
+ AND time > %d", $user_id, $point_type, 'buy_creds_with_%', $from
359
+ )
360
+ );
361
 
362
+ if ($completed === null ) { $completed = 0;
363
+ }
364
 
365
+ // Multisite Master Template support
366
+ $posts = mycred_get_db_column('posts');
367
+ $postmeta = mycred_get_db_column('postmeta');
368
 
369
+ // Next we need to tally up pending payments
370
+ $pending = $wpdb->get_var(
371
+ $wpdb->prepare(
372
+ "
373
  SELECT SUM( a.meta_value )
374
  FROM {$posts} p
375
  LEFT JOIN {$postmeta} a
379
  WHERE p.post_type = %s
380
  AND p.post_status = 'publish'
381
  AND p.post_author = %d
382
+ AND t.meta_value = %s;", 'buycred_payment', $user_id, $point_type
383
+ )
384
+ );
385
 
386
+ if ($pending === null ) { $pending = 0;
387
+ }
388
 
389
+ $total = $completed + $pending;
390
 
391
+ return apply_filters('mycred_get_users_total_purchase', $total, $user_id, $point_type, $completed, $total);
392
 
393
+ }
394
  endif;
395
 
396
  /**
397
  * Get Pending Payment
398
+ *
399
+ * @since 1.7
400
  * @version 1.0
401
  */
402
+ if (! function_exists('buycred_get_pending_payment_id') ) :
403
+ function buycred_get_pending_payment_id( $payment_id = null )
404
+ {
405
 
406
+ if ($payment_id === null || $payment_id == '' ) { return false;
407
+ }
408
 
409
+ // In case we are using the transaction ID instead of the post ID.
410
+ $post_id = false;
411
+ if (! is_numeric($payment_id) ) {
412
 
413
+ $post = mycred_get_page_by_title(strtoupper($payment_id), OBJECT, 'buycred_payment');
414
+ if ($post === null ) { return false;
415
+ }
416
 
417
+ $post_id = $post->ID;
418
 
419
+ }
420
+ else {
421
+ $post_id = absint($payment_id);
422
+ }
423
 
424
+ return $post_id;
425
 
426
+ }
427
  endif;
428
 
429
  /**
430
  * Get Pending Payment
431
+ *
432
+ * @since 1.7
433
  * @version 1.0
434
  */
435
+ if (! function_exists('buycred_get_pending_payment') ) :
436
+ function buycred_get_pending_payment( $payment_id = null )
437
+ {
438
+
439
+ // Construct fake pending object ( when no pending payment object exists )
440
+ if (is_array($payment_id) ) {
441
+
442
+ $pending_payment = new StdClass();
443
+ $pending_payment->payment_id = false;
444
+ $pending_payment->public_id = $payment_id['public_id'];
445
+ $pending_payment->point_type = $payment_id['point_type'];
446
+ $pending_payment->amount = $payment_id['amount'];
447
+ $pending_payment->cost = $payment_id['cost'];
448
+ $pending_payment->currency = $payment_id['currency'];
449
+ $pending_payment->buyer_id = $payment_id['buyer_id'];
450
+ $pending_payment->recipient_id = $payment_id['recipient_id'];
451
+ $pending_payment->gateway_id = $payment_id['gateway_id'];
452
+ $pending_payment->transaction_id = $payment_id['transaction_id'];
453
+ $pending_payment->cancel_url = false;
454
+ $pending_payment->pay_now_url = false;
455
+
456
+ }
457
+
458
+ else {
459
+
460
+ $payment_id = buycred_get_pending_payment_id($payment_id);
461
+
462
+ if ($payment_id === false ) { return false;
463
+ }
464
+
465
+ $pending_payment = new StdClass();
466
+ $pending_payment->payment_id = absint($payment_id);
467
+ $pending_payment->public_id = get_the_title($payment_id);
468
+ $pending_payment->point_type = mycred_get_post_meta($payment_id, 'point_type', true);
469
+ $pending_payment->amount = mycred_get_post_meta($payment_id, 'amount', true);
470
+ $pending_payment->cost = mycred_get_post_meta($payment_id, 'cost', true);
471
+ $pending_payment->currency = mycred_get_post_meta($payment_id, 'currency', true);
472
+ $pending_payment->buyer_id = mycred_get_post_meta($payment_id, 'from', true);
473
+ $pending_payment->recipient_id = mycred_get_post_meta($payment_id, 'to', true);
474
+ $pending_payment->gateway_id = mycred_get_post_meta($payment_id, 'gateway', true);
475
+ $pending_payment->transaction_id = $pending_payment->public_id;
476
+
477
+ $pending_payment->cancel_url = buycred_get_cancel_transaction_url($pending_payment->public_id);
478
+
479
+ $pending_payment->pay_now_url = add_query_arg(
480
+ array(
481
+ 'mycred_buy' => $pending_payment->gateway_id,
482
+ 'amount' => $pending_payment->amount,
483
+ 'revisit' => $payment_id,
484
+ 'token' => wp_create_nonce('mycred-buy-creds')
485
+ ), set_url_scheme(sanitize_url('http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']))
486
+ );
487
+
488
+ }
489
+
490
+ return apply_filters('buycred_get_pending_payment', $pending_payment, $payment_id);
491
+
492
+ }
493
  endif;
494
 
495
  /**
496
  * Add Pending Comment
497
+ *
498
+ * @since 1.7
499
  * @version 1.1
500
  */
501
+ if (! function_exists('buycred_add_pending_comment') ) :
502
+ function buycred_add_pending_comment( $payment_id = null, $comment = null, $time = null )
503
+ {
504
+
505
+ if (! MYCRED_BUY_PENDING_COMMENTS ) { return true;
506
+ }
507
+
508
+ $post_id = buycred_get_pending_payment_id($payment_id);
509
+ if ($post_id === false ) { return false;
510
+ }
511
+
512
+ global $mycred_modules;
513
+
514
+ if ($time === null || $time == 'now' ) {
515
+ $time = current_time('mysql');
516
+ }
517
+
518
+ $author = 'buyCRED';
519
+ $gateway = mycred_get_post_meta($post_id, 'gateway', true);
520
+ $gateways = mycred_get_buycred_gateways();
521
+ $author_url = sprintf('buyCRED: %s %s', __('Unknown Gateway', 'mycred'), $gateway);
522
+ $author_email = apply_filters('mycred_buycred_comment_email', 'buycred-service@mycred.me');
523
+
524
+ if (array_key_exists($gateway, $gateways) ) {
525
+ $author = sprintf('buyCRED: %s %s', $gateways[ $gateway ]['title'], __('Gateway', 'mycred'));
526
+ }
527
+
528
+ return wp_insert_comment(
529
+ array(
530
+ 'comment_post_ID' => $post_id,
531
+ 'comment_author' => $author,
532
+ 'comment_author_email' => $author_email,
533
+ 'comment_content' => $comment,
534
+ 'comment_type' => 'buycred',
535
+ 'comment_author_IP' => sanitize_text_field($_SERVER['REMOTE_ADDR']),
536
+ 'comment_date' => $time,
537
+ 'comment_approved' => 1,
538
+ 'user_id' => 0
539
+ )
540
+ );
541
+
542
+ }
543
  endif;
544
 
545
  /**
546
  * Get Cancel URL
547
+ *
548
+ * @since 1.7
549
  * @version 1.0.1
550
  */
551
+ if (! function_exists('buycred_get_cancel_transaction_url') ) :
552
+ function buycred_get_cancel_transaction_url( $transaction_id = null )
553
+ {
554
 
555
+ $settings = mycred_get_buycred_settings();
556
+ $base = set_url_scheme(sanitize_url('http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']));
557
 
558
+ // Cancel page
559
+ if ($settings['cancelled']['use'] == 'page' ) {
560
 
561
+ if (! empty($settings['cancelled']['page']) && $settings['cancelled']['page'] > 0 ) {
562
+ $base = mycred_get_permalink($settings['cancelled']['page']);
563
+ }
564
 
565
+ }
566
 
567
+ // Custom URL
568
+ elseif ($settings['cancelled']['use'] != 'page' && $settings['cancelled']['custom'] != '' ) {
569
 
570
+ $base = esc_url_raw($settings['cancelled']['custom']);
571
 
572
+ }
573
 
574
+ // Override
575
+ if (isset($_REQUEST['return_to']) && esc_url_raw($_REQUEST['return_to']) != '' ) {
576
+ $base = esc_url_raw($_REQUEST['return_to']);
577
+ }
578
 
579
+ if ($transaction_id !== null ) {
580
+ $url = add_query_arg(array( 'buycred-cancel' => $transaction_id, '_token' => wp_create_nonce('buycred-cancel-pending-payment') ), $base);
581
+ } else {
582
+ $url = $base;
583
+ }
584
 
585
+ return apply_filters('mycred_buycred_cancel_url', $url, $transaction_id, $base);
586
 
587
+ }
588
  endif;
589
 
590
  /**
591
  * Get Users Pending Payments
592
+ *
593
+ * @since 1.7
594
  * @version 1.0.2
595
  */
596
+ if (! function_exists('buycred_get_users_pending_payments') ) :
597
+ function buycred_get_users_pending_payments( $user_id = null, $point_type = '' )
598
+ {
599
 
600
+ $user_id = absint($user_id);
601
+ if ($user_id === 0 ) { return false;
602
+ }
603
 
604
+ $pending = mycred_get_user_meta($user_id, 'buycred_pending_payments', '', true);
605
+ if (! is_array($pending) ) {
606
 
607
+ global $wpdb;
608
 
609
+ $pending = array();
610
+ $table = mycred_get_db_column('posts');
611
+ $saved = $wpdb->get_results($wpdb->prepare("SELECT * FROM {$table} posts WHERE posts.post_type = 'buycred_payment' AND posts.post_author = %d AND posts.post_status = 'publish';", $user_id));
612
 
613
+ if (! empty($saved) ) {
614
 
615
+ foreach ( $saved as $entry ) {
616
 
617
+ $point_type = mycred_get_post_meta($entry->ID, 'point_type', true);
618
+ if ($point_type == '' ) { $point_type = MYCRED_DEFAULT_TYPE_KEY;
619
+ }
620
 
621
+ if (! array_key_exists($point_type, $pending) ) {
622
+ $pending[ $point_type ] = array();
623
+ }
624
 
625
+ $pending[ $point_type ][] = buycred_get_pending_payment((int) $entry->ID);
626
 
627
+ }
628
 
629
+ }
630
 
631
+ else {
632
 
633
+ if ($point_type == '' ) {
634
+ $pending[ MYCRED_DEFAULT_TYPE_KEY ] = array();
635
+ } else {
636
+ $pending[ $point_type ] = array();
637
+ }
638
 
639
+ }
640
 
641
+ mycred_add_user_meta($user_id, 'buycred_pending_payments', '', $pending, true);
642
 
643
+ }
644
 
645
+ if ($point_type != '' && mycred_point_type_exists($point_type) ) {
646
 
647
+ if (! is_array($pending) || ! array_key_exists($point_type, $pending) ) {
648
+ return false;
649
+ }
650
 
651
+ return $pending[ $point_type ];
652
 
653
+ }
654
 
655
+ return $pending;
656
 
657
+ }
658
  endif;
659
 
660
  /**
661
  * buyCRED Gateway Constructor
662
+ *
663
+ * @since 1.7
664
  * @version 1.1
665
  */
666
+ if (! function_exists('buycred_gateway') ) :
667
+ function buycred_gateway( $gateway_id = null )
668
+ {
669
 
670
+ global $buycred_gateway, $mycred_modules;
671
 
672
+ if (isset($buycred_gateway)
673
+ && ( $buycred_gateway instanceof myCRED_Payment_Gateway )
674
+ && ( $gateway_id === $buycred_gateway->id )
675
+ ) {
676
+ return $buycred_gateway;
677
+ }
678
 
679
+ $buycred_gateway = false;
680
+ $installed = $mycred_modules['solo']['buycred']->get();
681
+ if (array_key_exists($gateway_id, $installed) ) {
682
 
683
+ $class = $installed[ $gateway_id ]['callback'][0];
684
 
685
+ // Construct Gateway
686
+ $buycred_gateway = new $class($mycred_modules['solo']['buycred']->gateway_prefs);
687
 
688
+ }
689
 
690
+ return $buycred_gateway;
691
 
692
+ }
693
  endif;
694
 
695
  /**
696
  * Delete Pending Payment
697
+ *
698
+ * @since 1.7
699
  * @version 1.0
700
  */
701
+ if (! function_exists('buycred_trash_pending_payment') ) :
702
+ function buycred_trash_pending_payment( $payment_id = null )
703
+ {
704
 
705
+ $pending_payment = buycred_get_pending_payment($payment_id);
706
+ if ($pending_payment === false ) { return false;
707
+ }
708
 
709
+ mycred_delete_user_meta($pending_payment->buyer_id, 'buycred_pending_payments');
710
 
711
+ return wp_trash_post($pending_payment->payment_id);
712
 
713
+ }
714
  endif;
715
 
716
  /**
717
  * Complete Pending Payment
718
+ *
719
+ * @since 1.7
720
  * @version 1.0
721
  */
722
+ if (! function_exists('buycred_complete_pending_payment') ) :
723
+ function buycred_complete_pending_payment( $pending_id )
724
+ {
725
 
726
+ $pending_payment = buycred_get_pending_payment($pending_id);
727
+ if ($pending_payment === false ) { return false;
728
+ }
729
 
730
+ $gateway = buycred_gateway($pending_payment->gateway_id);
731
+ if ($gateway === false ) { return false;
732
+ }
733
 
734
+ // Complete Payment
735
+ $paid = $gateway->complete_payment($pending_payment, $pending_payment->transaction_id);
736
 
737
+ if ($paid ) {
738
+ return buycred_trash_pending_payment($pending_id);
739
+ }
740
 
741
+ return $paid;
742
 
743
+ }
744
  endif;
745
 
746
  /**
747
  * Checkout Title
748
+ *
749
+ * @since 1.8
750
  * @version 1.0
751
  */
752
+ if (! function_exists('buycred_checkout_title') ) :
753
+ function buycred_checkout_title()
754
+ {
755
 
756
+ global $buycred_instance;
757
 
758
+ if ($buycred_instance->gateway !== false ) {
759
+ $buycred_instance->gateway->checkout_page_title();
760
+ }
761
 
762
+ }
763
  endif;
764
 
765
  /**
766
  * Checkout Body
767
+ *
768
+ * @since 1.8
769
  * @version 1.0
770
  */
771
+ if (! function_exists('buycred_checkout_body') ) :
772
+ function buycred_checkout_body()
773
+ {
774
 
775
+ global $buycred_instance;
776
 
777
+ if ($buycred_instance->gateway !== false ) {
778
+ $buycred_instance->gateway->checkout_page_body();
779
+ }
780
 
781
+ }
782
  endif;
783
 
784
  /**
785
  * Checkout Logo
786
+ *
787
+ * @since 1.8
788
  * @version 1.0
789
  */
790
+ if (! function_exists('buycred_checkout_logo') ) :
791
+ function buycred_checkout_logo()
792
+ {
793
 
794
+ global $buycred_instance;
795
 
796
+ if ($buycred_instance->gateway !== false ) {
797
+ $buycred_instance->gateway->checkout_logo();
798
+ }
799
 
800
+ }
801
  endif;
802
 
803
  /**
804
  * Checkout Order
805
+ *
806
+ * @since 1.8
807
  * @version 1.0
808
  */
809
+ if (! function_exists('buycred_checkout_order') ) :
810
+ function buycred_checkout_order()
811
+ {
812
 
813
+ global $buycred_instance;
814
 
815
+ if ($buycred_instance->gateway !== false ) {
816
+ $buycred_instance->gateway->checkout_order();
817
+ }
818
 
819
+ }
820
  endif;
821
 
822
  /**
823
  * Checkout Cancel
824
+ *
825
+ * @since 1.8
826
  * @version 1.0
827
  */
828
+ if (! function_exists('buycred_checkout_cancel') ) :
829
+ function buycred_checkout_cancel()
830
+ {
831
 
832
+ global $buycred_instance;
833
 
834
+ if ($buycred_instance->gateway !== false ) {
835
+ $buycred_instance->gateway->checkout_cancel();
836
+ }
837
 
838
+ }
839
  endif;
840
 
841
  /**
842
  * Checkout Footer
843
+ *
844
+ * @since 1.8
845
  * @version 1.0
846
  */
847
+ if (! function_exists('buycred_checkout_footer') ) :
848
+ function buycred_checkout_footer()
849
+ {
850
 
851
+ global $buycred_instance;
852
 
853
+ if ($buycred_instance->gateway !== false ) {
854
+ $buycred_instance->gateway->checkout_page_footer();
855
+ }
856
 
857
+ }
858
+ endif;
addons/buy-creds/includes/buycred-reward-hook.php CHANGED
@@ -1,219 +1,235 @@
1
  <?php
2
- if ( ! defined( 'MYCRED_PURCHASE' ) ) exit;
 
3
 
4
  /**
5
  * myCRED_Addons_Module class
6
- * @since 0.1
 
7
  * @version 1.1.1
8
  */
9
- if ( ! class_exists( 'myCRED_buyCRED_Reward_Hook' ) ) :
10
- class myCRED_buyCRED_Reward_Hook extends myCRED_Hook {
11
-
12
- /**
13
- * Construct
14
- */
15
- function __construct( $hook_prefs, $type = MYCRED_DEFAULT_TYPE_KEY ) {
16
-
17
- parent::__construct( array(
18
- 'id' => 'buycred_reward',
19
- 'defaults' => array(
20
- 'creds' => array(),
21
- 'log' => array(),
22
- 'min' => array(),
23
- 'max' => array()
24
- )
25
- ), $hook_prefs, $type );
26
-
27
- }
28
-
29
- /**
30
- * Run
31
- * @since 1.8
32
- * @version 1.0
33
- */
34
- public function run() {
35
-
36
- add_filter( 'mycred_add_finished', array( $this, 'assign_buycred_reward' ), 20, 3 );
37
-
38
- }
39
-
40
- /**
41
- * Page Load
42
- * @since 1.8
43
- * @version 1.0
44
- */
45
- public function assign_buycred_reward( $result, $request, $mycred ) {
46
-
47
- extract( $request );
48
-
49
- if ( ! $result || strpos( $ref, 'buy_creds_with' ) === false ) return $result;;
50
-
51
- // Make sure user is not excluded
52
- if ( $this->core->exclude_user( $user_id ) ) return;
53
-
54
- if (
55
- ! empty( $this->prefs['creds'] ) &&
56
- ! empty( $this->prefs['log'] ) &&
57
- ! empty( $this->prefs['min'] ) &&
58
- ! empty( $this->prefs['max'] )
59
- ) {
60
-
61
-
62
- $threshold = array();
63
-
64
- foreach ( $this->prefs['creds'] as $key => $value ) {
65
-
66
- if (
67
- floatval( $amount ) >= floatval( $this->prefs['min'][$key] ) &&
68
- floatval( $amount ) <= floatval( $this->prefs['max'][$key] )
69
- ) {
70
- array_push( $threshold, $key );
71
- }
72
-
73
- }
74
-
75
- if ( ! empty( $threshold ) ) {
76
-
77
- $hook_index = end( $threshold );
78
-
79
- // Execute
80
- $this->core->add_creds(
81
- 'buycred_reward',
82
- $user_id,
83
- $this->prefs['creds'][$hook_index],
84
- $this->prefs['log'][$hook_index],
85
- $ref_id,
86
- $data,
87
- $this->mycred_type
88
- );
89
- }
90
-
91
- }
92
-
93
- return $result;
94
-
95
- }
96
-
97
- /**
98
- * Preference for Anniversary Hook
99
- * @since 1.8
100
- * @version 1.0
101
- */
102
- public function preferences() {
103
-
104
- $prefs = $this->prefs;
105
-
106
- if ( count( $prefs['creds'] ) > 0 ) {
107
- $hooks = $this->buycred_reward_arrange_data( $prefs );
108
- $this->buycred_reward_setting( $hooks, $this );
109
- }
110
- else {
111
- $default_data = array(
112
- array(
113
- 'creds' => '10',
114
- 'log' => 'Reward for Buying %plural%.',
115
- 'min' => '1',
116
- 'max' => '10'
117
- )
118
- );
119
- $this->buycred_reward_setting( $default_data, $this );
120
- }
121
-
122
- }
123
-
124
- /**
125
- * Sanitize Preferences
126
- */
127
- public function sanitise_preferences( $data ) {
128
-
129
- $new_data = array();
130
-
131
- foreach ( $data as $data_key => $data_value ) {
132
- foreach ( $data_value as $key => $value) {
133
- if ( $data_key == 'creds' ) {
134
- $new_data[$data_key][$key] = ( !empty( $value ) ) ? floatval( $value ) : 10;
135
- }
136
- else if ( $data_key == 'log' ) {
137
- $new_data[$data_key][$key] = ( !empty( $value ) ) ? sanitize_text_field( $value ) : 'Reward for Buying %plural%.';
138
- }
139
- else if ( $data_key == 'min' ) {
140
- $new_data[$data_key][$key] = ( !empty( $value ) ) ? floatval( $value ) : 1;
141
- }
142
- else if ( $data_key == 'max' ) {
143
- $new_data[$data_key][$key] = ( !empty( $value ) ) ? floatval( $value ) : 1;
144
- }
145
- }
146
- }
147
- return $new_data;
148
- }
149
-
150
- public function buycred_reward_arrange_data( $data ){
151
- $hook_data = array();
152
- foreach ( $data['creds'] as $key => $value ) {
153
- $hook_data[$key]['creds'] = $data['creds'][$key];
154
- $hook_data[$key]['log'] = $data['log'][$key];
155
- $hook_data[$key]['min'] = $data['min'][$key];
156
- $hook_data[$key]['max'] = $data['max'][$key];
157
- }
158
- return $hook_data;
159
- }
160
-
161
- public function buycred_reward_setting( $data ){
162
-
163
- foreach ( $data as $hook ):?>
164
- <div class="hook-instance">
165
- <div class="row">
166
- <div class="col-lg-6 col-md-6 col-sm-12 col-xs-12">
167
- <div class="form-group">
168
- <label>Reward <?php echo $this->core->plural(); ?></label>
169
- <input type="text" name="<?php echo $this->name( $this->mycred_type, 'creds' ); ?>" value="<?php echo $this->core->number( $hook['creds'] ); ?>" class="form-control buycred-reward-creds" />
170
- </div>
171
- </div>
172
- <div class="col-lg-6 col-md-6 col-sm-12 col-xs-12">
173
- <div class="form-group">
174
- <label><?php _e( 'Log Template', 'mycred' ); ?></label>
175
- <input type="text" name="<?php echo $this->name( $this->mycred_type, 'log' ); ?>" placeholder="<?php _e( 'required', 'mycred' ); ?>" value="<?php echo esc_attr( $hook['log'] ); ?>" class="form-control buycred-reward-log" />
176
- <span class="description"><?php echo $this->available_template_tags( array( 'general' ) ); ?></span>
177
- </div>
178
- </div>
179
- </div>
180
- <div class="row">
181
- <div class="col-lg-6 col-md-6 col-sm-12 col-xs-12">
182
- <div class="form-group">
183
- <label><?php _e( 'Minimum', 'mycred' ); ?></label>
184
- <input type="text" name="<?php echo $this->name( $this->mycred_type, 'min' ); ?>" value="<?php echo $this->core->number( $hook['min'] ); ?>" class="form-control buycred-reward-min" />
185
- </div>
186
- </div>
187
- <div class="col-lg-6 col-md-6 col-sm-12 col-xs-12">
188
- <div class="form-group">
189
- <label><?php _e( 'Maximium', 'mycred' ); ?></label>
190
- <input type="text" name="<?php echo $this->name( $this->mycred_type, 'max' ); ?>" value="<?php echo $this->core->number( $hook['max'] ); ?>" class="form-control buycred-reward-max" />
191
- </div>
192
- </div>
193
- </div>
194
- <div class="row">
195
- <div class="col-lg-12 col-md-12 col-sm-12 col-xs-12">
196
- <div class="form-group specific-hook-actions textright">
197
- <button class="button button-small mycred-add-specific-hook" type="button">Add More</button>
198
- <button class="button button-small mycred-remove-specific-hook" type="button">Remove</button>
199
- </div>
200
- </div>
201
- </div>
202
- </div>
203
- <?php
204
- endforeach;
205
- }
206
-
207
- public function name( $type, $attr ){
208
-
209
- $hook_prefs_key = 'mycred_pref_hooks';
210
-
211
- if ( $type != MYCRED_DEFAULT_TYPE_KEY ) {
212
- $hook_prefs_key = 'mycred_pref_hooks_'.$type;
213
- }
214
-
215
- return "{$hook_prefs_key}[hook_prefs][buycred_reward][{$attr}][]";
216
- }
217
-
218
- }
219
- endif;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  <?php
2
+ if (! defined('MYCRED_PURCHASE') ) { exit;
3
+ }
4
 
5
  /**
6
  * myCRED_Addons_Module class
7
+ *
8
+ * @since 0.1
9
  * @version 1.1.1
10
  */
11
+ if (! class_exists('myCRED_buyCRED_Reward_Hook') ) :
12
+ class myCRED_buyCRED_Reward_Hook extends myCRED_Hook
13
+ {
14
+
15
+ /**
16
+ * Construct
17
+ */
18
+ function __construct( $hook_prefs, $type = MYCRED_DEFAULT_TYPE_KEY )
19
+ {
20
+
21
+ parent::__construct(
22
+ array(
23
+ 'id' => 'buycred_reward',
24
+ 'defaults' => array(
25
+ 'creds' => array(),
26
+ 'log' => array(),
27
+ 'min' => array(),
28
+ 'max' => array()
29
+ )
30
+ ), $hook_prefs, $type
31
+ );
32
+
33
+ }
34
+
35
+ /**
36
+ * Run
37
+ *
38
+ * @since 1.8
39
+ * @version 1.0
40
+ */
41
+ public function run()
42
+ {
43
+
44
+ add_filter('mycred_add_finished', array( $this, 'assign_buycred_reward' ), 20, 3);
45
+
46
+ }
47
+
48
+ /**
49
+ * Page Load
50
+ *
51
+ * @since 1.8
52
+ * @version 1.0
53
+ */
54
+ public function assign_buycred_reward( $result, $request, $mycred )
55
+ {
56
+
57
+ extract($request);
58
+
59
+ if (! $result || strpos($ref, 'buy_creds_with') === false ) { return $result;
60
+ };
61
+
62
+ // Make sure user is not excluded
63
+ if ($this->core->exclude_user($user_id) ) { return;
64
+ }
65
+
66
+ if (! empty($this->prefs['creds'])
67
+ && ! empty($this->prefs['log'])
68
+ && ! empty($this->prefs['min'])
69
+ && ! empty($this->prefs['max'])
70
+ ) {
71
+
72
+
73
+ $threshold = array();
74
+
75
+ foreach ( $this->prefs['creds'] as $key => $value ) {
76
+
77
+ if (floatval($amount) >= floatval($this->prefs['min'][$key])
78
+ && floatval($amount) <= floatval($this->prefs['max'][$key])
79
+ ) {
80
+ array_push($threshold, $key);
81
+ }
82
+
83
+ }
84
+
85
+ if (! empty($threshold) ) {
86
+
87
+ $hook_index = end($threshold);
88
+
89
+ // Execute
90
+ $this->core->add_creds(
91
+ 'buycred_reward',
92
+ $user_id,
93
+ $this->prefs['creds'][$hook_index],
94
+ $this->prefs['log'][$hook_index],
95
+ $ref_id,
96
+ $data,
97
+ $this->mycred_type
98
+ );
99
+ }
100
+
101
+ }
102
+
103
+ return $result;
104
+
105
+ }
106
+
107
+ /**
108
+ * Preference for Anniversary Hook
109
+ *
110
+ * @since 1.8
111
+ * @version 1.0
112
+ */
113
+ public function preferences()
114
+ {
115
+
116
+ $prefs = $this->prefs;
117
+
118
+ if (count($prefs['creds']) > 0 ) {
119
+ $hooks = $this->buycred_reward_arrange_data($prefs);
120
+ $this->buycred_reward_setting($hooks, $this);
121
+ }
122
+ else {
123
+ $default_data = array(
124
+ array(
125
+ 'creds' => '10',
126
+ 'log' => 'Reward for Buying %plural%.',
127
+ 'min' => '1',
128
+ 'max' => '10'
129
+ )
130
+ );
131
+ $this->buycred_reward_setting($default_data, $this);
132
+ }
133
+
134
+ }
135
+
136
+ /**
137
+ * Sanitize Preferences
138
+ */
139
+ public function sanitise_preferences( $data )
140
+ {
141
+
142
+ $new_data = array();
143
+
144
+ foreach ( $data as $data_key => $data_value ) {
145
+ foreach ( $data_value as $key => $value) {
146
+ if ($data_key == 'creds' ) {
147
+ $new_data[$data_key][$key] = ( !empty($value) ) ? floatval($value) : 10;
148
+ }
149
+ else if ($data_key == 'log' ) {
150
+ $new_data[$data_key][$key] = ( !empty($value) ) ? sanitize_text_field($value) : 'Reward for Buying %plural%.';
151
+ }
152
+ else if ($data_key == 'min' ) {
153
+ $new_data[$data_key][$key] = ( !empty($value) ) ? floatval($value) : 1;
154
+ }
155
+ else if ($data_key == 'max' ) {
156
+ $new_data[$data_key][$key] = ( !empty($value) ) ? floatval($value) : 1;
157
+ }
158
+ }
159
+ }
160
+ return $new_data;
161
+ }
162
+
163
+ public function buycred_reward_arrange_data( $data )
164
+ {
165
+ $hook_data = array();
166
+ foreach ( $data['creds'] as $key => $value ) {
167
+ $hook_data[$key]['creds'] = $data['creds'][$key];
168
+ $hook_data[$key]['log'] = $data['log'][$key];
169
+ $hook_data[$key]['min'] = $data['min'][$key];
170
+ $hook_data[$key]['max'] = $data['max'][$key];
171
+ }
172
+ return $hook_data;
173
+ }
174
+
175
+ public function buycred_reward_setting( $data )
176
+ {
177
+
178
+ foreach ( $data as $hook ):?>
179
+ <div class="hook-instance">
180
+ <div class="row">
181
+ <div class="col-lg-6 col-md-6 col-sm-12 col-xs-12">
182
+ <div class="form-group">
183
+ <label>Reward <?php echo $this->core->plural(); ?></label>
184
+ <input type="text" name="<?php echo $this->name($this->mycred_type, 'creds'); ?>" value="<?php echo $this->core->number($hook['creds']); ?>" class="form-control buycred-reward-creds" />
185
+ </div>
186
+ </div>
187
+ <div class="col-lg-6 col-md-6 col-sm-12 col-xs-12">
188
+ <div class="form-group">
189
+ <label><?php _e('Log Template', 'mycred'); ?></label>
190
+ <input type="text" name="<?php echo $this->name($this->mycred_type, 'log'); ?>" placeholder="<?php _e('required', 'mycred'); ?>" value="<?php echo esc_attr($hook['log']); ?>" class="form-control buycred-reward-log" />
191
+ <span class="description"><?php echo $this->available_template_tags(array( 'general' )); ?></span>
192
+ </div>
193
+ </div>
194
+ </div>
195
+ <div class="row">
196
+ <div class="col-lg-6 col-md-6 col-sm-12 col-xs-12">
197
+ <div class="form-group">
198
+ <label><?php _e('Minimum', 'mycred'); ?></label>
199
+ <input type="text" name="<?php echo $this->name($this->mycred_type, 'min'); ?>" value="<?php echo $this->core->number($hook['min']); ?>" class="form-control buycred-reward-min" />
200
+ </div>
201
+ </div>
202
+ <div class="col-lg-6 col-md-6 col-sm-12 col-xs-12">
203
+ <div class="form-group">
204
+ <label><?php _e('Maximium', 'mycred'); ?></label>
205
+ <input type="text" name="<?php echo $this->name($this->mycred_type, 'max'); ?>" value="<?php echo $this->core->number($hook['max']); ?>" class="form-control buycred-reward-max" />
206
+ </div>
207
+ </div>
208
+ </div>
209
+ <div class="row">
210
+ <div class="col-lg-12 col-md-12 col-sm-12 col-xs-12">
211
+ <div class="form-group specific-hook-actions textright">
212
+ <button class="button button-small mycred-add-specific-hook" type="button">Add More</button>
213
+ <button class="button button-small mycred-remove-specific-hook" type="button">Remove</button>
214
+ </div>
215
+ </div>
216
+ </div>
217
+ </div>
218
+ <?php
219
+ endforeach;
220
+ }
221
+
222
+ public function name( $type, $attr )
223
+ {
224
+
225
+ $hook_prefs_key = 'mycred_pref_hooks';
226
+
227
+ if ($type != MYCRED_DEFAULT_TYPE_KEY ) {
228
+ $hook_prefs_key = 'mycred_pref_hooks_'.$type;
229
+ }
230
+
231
+ return "{$hook_prefs_key}[hook_prefs][buycred_reward][{$attr}][]";
232
+ }
233
+
234
+ }
235
+ endif;
addons/buy-creds/includes/buycred-reward.php CHANGED
@@ -1,79 +1,91 @@
1
  <?php
2
- if ( ! defined( 'MYCRED_PURCHASE' ) ) exit;
 
3
 
4
  /**
5
  * myCRED_buyCRED_Module class
6
- * @since 0.1
 
7
  * @version 1.4.1
8
  */
9
- if ( ! class_exists( 'myCRED_buyCRED_Reward' ) ) :
10
- class myCRED_buyCRED_Reward {
11
-
12
- // Instnace
13
- protected static $_instance = NULL;
14
-
15
- /**
16
- * Construct
17
- */
18
- function __construct() {
19
-
20
- add_action( 'mycred_admin_enqueue', array( $this, 'register_assets' ) );
21
- add_filter( 'mycred_setup_hooks', array( $this, 'register_buycred_reward_hook' ), 10, 2 );
22
- add_action( 'mycred_load_hooks', array( $this, 'load_buycred_reward_hook' ) );
23
- add_filter( 'mycred_all_references', array( $this, 'register_buycred_reward_refrence' ) );
24
-
25
- }
26
-
27
- /**
28
- * Setup Instance
29
- * @since 1.7
30
- * @version 1.0
31
- */
32
- public static function instance() {
33
- if ( is_null( self::$_instance ) ) {
34
- self::$_instance = new self();
35
- }
36
- return self::$_instance;
37
- }
38
-
39
- /**
40
- * Register Assets
41
- * @since 1.8
42
- * @version 1.0
43
- */
44
- public function register_assets() {
45
-
46
- wp_enqueue_style( 'buycred-admin-style', plugins_url( 'assets/css/admin-style.css', MYCRED_PURCHASE ), array(), MYCRED_PURCHASE_VERSION, 'all' );
47
- wp_enqueue_script( 'buycred-admin-script', plugins_url( 'assets/js/admin-script.js', MYCRED_PURCHASE ), array( 'jquery' ), MYCRED_PURCHASE_VERSION, 'all' );
48
-
49
- }
50
-
51
- public function load_buycred_reward_hook() {
52
- require_once MYCRED_BUYCRED_INCLUDES_DIR . 'buycred-reward-hook.php';
53
- }
54
-
55
- public function register_buycred_reward_hook( $installed ) {
56
-
57
- $installed['buycred_reward'] = array(
58
- 'title' => __('Reward for Buying %plural%', 'mycred'),
59
- 'description' => __('Adds a myCred hook for buyCred reward.', 'mycred'),
60
- 'callback' => array('myCRED_buyCRED_Reward_Hook')
61
- );
62
-
63
- return $installed;
64
- }
65
-
66
-
67
- public function register_buycred_reward_refrence( $list ) {
68
-
69
- $list['buycred_reward'] = __('Reward for buyCRED Purchase', 'mycred');
70
- return $list;
71
- }
72
-
73
- }
 
 
 
 
 
 
 
 
 
74
  endif;
75
 
76
- function mycred_buycred_reward_init() {
77
- return myCRED_buyCRED_Reward::instance();
 
78
  }
79
- mycred_buycred_reward_init();
1
  <?php
2
+ if (! defined('MYCRED_PURCHASE') ) { exit;
3
+ }
4
 
5
  /**
6
  * myCRED_buyCRED_Module class
7
+ *
8
+ * @since 0.1
9
  * @version 1.4.1
10
  */
11
+ if (! class_exists('myCRED_buyCRED_Reward') ) :
12
+ class myCRED_buyCRED_Reward
13
+ {
14
+
15
+ // Instnace
16
+ protected static $_instance = null;
17
+
18
+ /**
19
+ * Construct
20
+ */
21
+ function __construct()
22
+ {
23
+
24
+ add_action('mycred_admin_enqueue', array( $this, 'register_assets' ));
25
+ add_filter('mycred_setup_hooks', array( $this, 'register_buycred_reward_hook' ), 10, 2);
26
+ add_action('mycred_load_hooks', array( $this, 'load_buycred_reward_hook' ));
27
+ add_filter('mycred_all_references', array( $this, 'register_buycred_reward_refrence' ));
28
+
29
+ }
30
+
31
+ /**
32
+ * Setup Instance
33
+ *
34
+ * @since 1.7
35
+ * @version 1.0
36
+ */
37
+ public static function instance()
38
+ {
39
+ if (is_null(self::$_instance) ) {
40
+ self::$_instance = new self();
41
+ }
42
+ return self::$_instance;
43
+ }
44
+
45
+ /**
46
+ * Register Assets
47
+ *
48
+ * @since 1.8
49
+ * @version 1.0
50
+ */
51
+ public function register_assets()
52
+ {
53
+
54
+ wp_enqueue_style('buycred-admin-style', plugins_url('assets/css/admin-style.css', MYCRED_PURCHASE), array(), MYCRED_PURCHASE_VERSION, 'all');
55
+ wp_enqueue_script('buycred-admin-script', plugins_url('assets/js/admin-script.js', MYCRED_PURCHASE), array( 'jquery' ), MYCRED_PURCHASE_VERSION, 'all');
56
+
57
+ }
58
+
59
+ public function load_buycred_reward_hook()
60
+ {
61
+ include_once MYCRED_BUYCRED_INCLUDES_DIR . 'buycred-reward-hook.php';
62
+ }
63
+
64
+ public function register_buycred_reward_hook( $installed )
65
+ {
66
+
67
+ $installed['buycred_reward'] = array(
68
+ 'title' => __('Reward for Buying %plural%', 'mycred'),
69
+ 'description' => __('Adds a myCred hook for buyCred reward.', 'mycred'),
70
+ 'callback' => array('myCRED_buyCRED_Reward_Hook')
71
+ );
72
+
73
+ return $installed;
74
+ }
75
+
76
+
77
+ public function register_buycred_reward_refrence( $list )
78
+ {
79
+
80
+ $list['buycred_reward'] = __('Reward for buyCRED Purchase', 'mycred');
81
+ return $list;
82
+ }
83
+
84
+ }
85
  endif;
86
 
87
+ function mycred_buycred_reward_init()
88
+ {
89
+ return myCRED_buyCRED_Reward::instance();
90
  }
91
+ mycred_buycred_reward_init();
addons/buy-creds/includes/buycred-shortcodes.php CHANGED
@@ -77,7 +77,7 @@ if ( ! function_exists( 'mycred_render_buy_points' ) ) :
77
  if ( empty( $classes ) || ! in_array( 'mycred-buy-link', $classes ) )
78
  $classes[] = 'mycred-buy-link';
79
 
80
- $current_url = set_url_scheme( 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'] );
81
  if ( is_ssl() )
82
  $current_url = str_replace( 'http://', 'https://', $current_url );
83
 
77
  if ( empty( $classes ) || ! in_array( 'mycred-buy-link', $classes ) )
78
  $classes[] = 'mycred-buy-link';
79
 
80
+ $current_url = set_url_scheme( sanitize_url('http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']) );
81
  if ( is_ssl() )
82
  $current_url = str_replace( 'http://', 'https://', $current_url );
83
 
addons/buy-creds/includes/index.php CHANGED
@@ -1,3 +1,3 @@
1
  <?php
2
  // Silence is golden.
3
- ?>
1
  <?php
2
  // Silence is golden.
3
+ ?>
addons/buy-creds/index.php CHANGED
@@ -1,3 +1,3 @@
1
  <?php
2
  // Silence is golden.
3
- ?>
1
  <?php
2
  // Silence is golden.
3
+ ?>
addons/buy-creds/modules/buycred-module-core.php CHANGED
@@ -1,323 +1,358 @@
1
  <?php
2
- if ( ! defined( 'MYCRED_PURCHASE' ) ) exit;
 
3
 
4
  /**
5
  * myCRED_buyCRED_Module class
6
- * @since 0.1
 
7
  * @version 1.4.1
8
  */
9
- if ( ! class_exists( 'myCRED_buyCRED_Module' ) ) :
10
- class myCRED_buyCRED_Module extends myCRED_Module {
11
-
12
- public $purchase_log = '';
13
-
14
- /**
15
- * Construct
16
- */
17
- function __construct( $type = MYCRED_DEFAULT_TYPE_KEY ) {
18
-
19
- parent::__construct( 'myCRED_BuyCRED_Module', array(
20
- 'module_name' => 'gateways',
21
- 'option_id' => 'mycred_pref_buycreds',
22
- 'defaults' => array(
23
- 'installed' => array(),
24
- 'active' => array(),
25
- 'gateway_prefs' => array()
26
- ),
27
- 'labels' => array(
28
- 'menu' => __( 'buyCred Gateways', 'mycred' ),
29
- 'page_title' => __( 'buyCred Gateways', 'mycred' ),
30
- 'page_header' => __( 'buyCred Gateways', 'mycred' )
31
- ),
32
- 'screen_id' => MYCRED_SLUG . '-gateways',
33
- 'accordion' => true,
34
- 'add_to_core' => true,
35
- 'menu_pos' => 70,
36
- 'main_menu' => true
37
- ), $type );
38
-
39
- $this->mycred_type = MYCRED_DEFAULT_TYPE_KEY;
40
-
41
- }
42
-
43
- /**
44
- * Load
45
- * @version 1.0.2
46
- */
47
- public function load() {
48
-
49
- add_filter( 'mycred_parse_log_entry', array( $this, 'render_gift_tags' ), 10, 2 );
50
-
51
- add_action( 'mycred_init', array( $this, 'module_init' ), $this->menu_pos );
52
- add_action( 'wp_loaded', array( $this, 'module_run' ) );
53
-
54
- add_action( 'mycred_register_assets', array( $this, 'register_assets' ) );
55
- add_action( 'mycred_front_enqueue_footer', array( $this, 'enqueue_footer' ) );
56
-
57
- add_action( 'mycred_admin_init', array( $this, 'module_admin_init' ), $this->menu_pos );
58
- add_action( 'mycred_admin_init', array( $this, 'register_settings' ), $this->menu_pos+1 );
59
- add_action( 'mycred_add_menu', array( $this, 'add_menu' ), $this->menu_pos );
60
- add_action( 'mycred_add_menu', array( $this, 'add_to_menu' ), $this->menu_pos+1 );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
61
 
62
- add_action( 'mycred_after_core_prefs', array( $this, 'after_general_settings' ) );
63
- add_filter( 'mycred_save_core_prefs', array( $this, 'sanitize_extra_settings' ), 90, 3 );
64
-
65
- add_action('pre_get_comments', array( $this, 'hide_buycred_transactions' ) );
66
-
67
- }
68
-
69
- /**
70
- * Init
71
- * Register shortcodes.
72
- * @since 0.1
73
- * @version 1.4
74
- */
75
- public function module_init() {
76
-
77
- // Add shortcodes first
78
- add_shortcode( MYCRED_SLUG . '_buy', 'mycred_render_buy_points' );
79
- add_shortcode( MYCRED_SLUG . '_buy_form', 'mycred_render_buy_form_points' );
80
-
81
- $this->setup_instance();
82
 
83
- $this->current_user_id = get_current_user_id();
84
-
85
- }
86
-
87
- /**
88
- * Register Assets
89
- * @since 1.8
90
- * @version 1.0
91
- */
92
- public function register_assets() {
93
-
94
- wp_register_style( 'buycred-checkout', plugins_url( 'assets/css/checkout.css', MYCRED_PURCHASE ), array(), MYCRED_PURCHASE_VERSION, 'all' );
95
- wp_register_script( 'buycred-checkout', plugins_url( 'assets/js/checkout.js', MYCRED_PURCHASE ), array( 'jquery' ), MYCRED_PURCHASE_VERSION, 'all' );
96
-
97
- }
98
 
99
- /**
100
- * Setup Purchase Instance
101
- * @since 1.8
102
- * @version 1.0
103
- */
104
- public function setup_instance() {
105
 
106
- global $buycred_instance;
 
 
107
 
108
- $buycred_instance = new StdClass();
109
- $buycred_instance->settings = mycred_get_buycred_settings();
110
- $buycred_instance->active = array();
111
- $buycred_instance->gateway_id = false;
112
- $buycred_instance->checkout = false;
113
- $buycred_instance->cancelled = false;
114
- $buycred_instance->error = false;
115
- $buycred_instance->gateway = false;
116
 
117
- }
118
 
119
- /**
120
- * Get Payment Gateways
121
- * Retreivs all available payment gateways that can be used to buyCRED
122
- * @since 0.1
123
- * @version 1.1.1
124
- */
125
- public function get() {
126
 
127
- $installed = mycred_get_buycred_gateways();
 
 
 
 
 
 
 
 
128
 
129
- // Untill all custom gateways have been updated, make sure all gateways have an external setting
130
- if ( ! empty( $installed ) ) {
131
- foreach ( $installed as $id => $settings ) {
132
 
133
- if ( ! array_key_exists( 'external', $settings ) )
134
- $installed[ $id ]['external'] = true;
135
 
136
- if ( ! array_key_exists( 'custom_rate', $settings ) )
137
- $installed[ $id ]['custom_rate'] = false;
 
138
 
139
- }
140
- }
 
 
 
 
141
 
142
- return $installed;
 
143
 
144
- }
 
 
 
 
 
 
145
 
146
- /**
147
- * Run
148
- * Runs a gateway if requested.
149
- * @since 1.7
150
- * @version 1.0
151
- */
152
- public function module_run() {
153
 
154
- global $buycred_instance;
155
 
156
- // Prep
157
- $installed = $this->get();
 
 
 
 
 
158
 
159
- // Make sure we have installed gateways.
160
- if ( empty( $installed ) ) return;
161
 
162
- // We only want to deal with active gateways
163
- foreach ( $installed as $id => $data ) {
164
- if ( $this->is_active( $id ) )
165
- $buycred_instance->active[ $id ] = $data;
166
- }
167
 
168
- if ( empty( $buycred_instance->active ) ) return;
 
169
 
170
- /**
171
- * Step 1 - Look for returns
172
- * Runs though all active payment gateways and lets them decide if this is the
173
- * user returning after a remote purchase. Each gateway should know what to look
174
- * for to determen if they are responsible for handling the return.
175
- */
176
- foreach ( $buycred_instance->active as $id => $data ) {
177
 
178
- if ( $data['external'] === true )
179
- $this->call( 'returning', $buycred_instance->active[ $id ]['callback'] );
180
 
181
- }
 
182
 
183
- /**
184
- * Step 2 - Check for gateway calls
185
- * Checks to see if a gateway should be loaded.
186
- */
187
- $buycred_instance->gateway_id = mycred_get_requested_gateway_id();
188
- $buycred_instance->checkout = false;
189
- $buycred_instance->is_ajax = ( isset( $_REQUEST['ajax'] ) && $_REQUEST['ajax'] == 1 ) ? true : false;
190
 
191
- do_action( 'mycred_pre_process_buycred' );
 
192
 
193
- // If we have a valid gateway ID and the gateway is active, lets run that gateway.
194
- if ( $buycred_instance->gateway_id !== false && array_key_exists( $buycred_instance->gateway_id, $buycred_instance->active ) ) {
195
 
196
- // Construct Gateway
197
- $buycred_instance->gateway = buycred_gateway( $buycred_instance->gateway_id );
198
 
199
- // Check payment processing
200
- if ( isset( $_REQUEST['mycred_call'] ) ) {
 
 
 
 
 
 
201
 
202
- $buycred_instance->gateway->process();
203
 
204
- do_action( 'mycred_buycred_process', $buycred_instance->gateway_id, $this->gateway_prefs );
205
- do_action( "mycred_buycred_process_{$gateway_id}", $this->gateway_prefs );
 
206
 
207
- }
208
 
209
- add_action( 'template_redirect', array( $this, 'process_new_request' ) );
210
- add_filter( 'template_include', array( $this, 'checkout_page' ) );
211
 
212
- }
213
 
214
- }
 
 
215
 
216
- /**
217
- * Process New Request
218
- * @since 1.8
219
- * @version 1.0
220
- */
221
- public function process_new_request() {
222
 
223
- global $buycred_instance, $buycred_sale;
 
224
 
225
- if ( $buycred_instance->checkout === false && isset( $_REQUEST['mycred_buy'] ) )
226
- $buycred_instance->checkout = true;
227
 
228
- if ( $buycred_instance->checkout ) {
229
-
230
- $buycred_sale = true;
231
-
232
- if ( $buycred_instance->gateway->valid_request() ) {
233
-
234
- if ( $buycred_instance->is_ajax )
235
- $buycred_instance->gateway->ajax_buy();
236
-
237
- do_action( 'mycred_buycred_buy', $buycred_instance->gateway_id, $this->gateway_prefs );
238
- do_action( "mycred_buycred_buy_{$buycred_instance->gateway_id}", $this->gateway_prefs );
239
-
240
- }
241
- else {
242
-
243
- if ( ! empty( $buycred_instance->gateway->errors ) ) {
244
- $buycred_instance->checkout = false;
245
-
246
- if ( $buycred_instance->is_ajax )
247
- die( json_encode( array( 'validationFail' => true , 'errors' => $buycred_instance->gateway->errors ) ) );
248
- else
249
- {
250
- foreach( $buycred_instance->gateway->errors as $error )
251
- {
252
- global $wp;
253
- echo "
254
  <script>
255
  alert('".$error."');
256
- location.replace( '".home_url( $wp->request )."' );
257
  </script>
258
  ";
259
- }
260
- }
261
- }
262
 
263
- }
264
 
265
- }
266
 
267
- }
268
 
269
- /**
270
- * Checkout Page
271
- * @since 1.8
272
- * @version 1.0
273
- */
274
- public function checkout_page( $template ) {
 
 
275
 
276
- global $buycred_instance;
277
 
278
- if ( $buycred_instance->checkout ) {
279
 
280
- return MYCRED_BUYCRED_TEMPLATES_DIR . 'buycred-checkout.php';
281
- $override = mycred_locate_template( 'buycred-checkout.php', MYCRED_SLUG, MYCRED_BUYCRED_TEMPLATES_DIR );
282
- if ( ! $override )
283
- $template = $override;
 
284
 
285
- }
286
 
287
- return $template;
288
 
289
- }
290
 
291
- /**
292
- * Enqueue Footer
293
- * @since 1.8
294
- * @version 1.0
295
- */
296
- public function enqueue_footer() {
 
 
297
 
298
- global $buycred_instance, $buycred_sale;
299
 
300
- $settings = mycred_get_buycred_settings();
301
 
302
- if ( $buycred_sale ) {
303
 
304
- wp_enqueue_style( 'buycred-checkout' );
305
 
306
- wp_localize_script(
307
- 'buycred-checkout',
308
- 'buyCRED',
309
- apply_filters( 'mycred_buycred_checkout_js', array(
310
- 'ajaxurl' => get_site_url(),
311
- 'token' => wp_create_nonce( 'mycred-buy-creds' ),
312
- 'checkout' => $settings['checkout'],
313
- 'redirecting' => esc_js( esc_attr__( 'Redirecting', 'mycred' ) ),
314
- 'error' => 'communications error'
315
- ), $this )
316
- );
317
- wp_enqueue_script( 'buycred-checkout' );
 
 
318
 
319
- if ( $settings['checkout'] != 'page' ) {
320
- echo '
321
  <div id="cancel-checkout-wrapper"><a href="javascript:void(0);">X</a></div>
322
  <div id="buycred-checkout-wrapper">
323
  <div class="checkout-inside">
@@ -334,1162 +369,1245 @@ if ( ! class_exists( 'myCRED_buyCRED_Module' ) ) :
334
  </div>
335
  </div>
336
  </div>';
337
- }
338
 
339
- }
340
 
341
- }
342
 
343
- /**
344
- * Admin Init
345
- * @since 1.5
346
- * @version 1.1
347
- */
348
- public function module_admin_init() {
 
 
349
 
350
- add_action( 'mycred_user_edit_after_balances', array( $this, 'exchange_rates_user_screen' ), 30 );
351
 
352
- add_action( 'personal_options_update', array( $this, 'save_manual_exchange_rates' ), 30 );
353
- add_action( 'edit_user_profile_update', array( $this, 'save_manual_exchange_rates' ), 30 );
354
 
355
- // Prep
356
- $installed = mycred_get_buycred_gateways();
357
 
358
- // Make sure we have installed gateways.
359
- if ( empty( $installed ) ) return;
 
360
 
361
- /**
362
- * Admin Init
363
- * Runs though all installed gateways to allow admin inits.
364
- */
365
- foreach ( $installed as $id => $data )
366
- $this->call( 'admin_init', $installed[ $id ]['callback'] );
 
367
 
368
- }
369
 
370
- /**
371
- * Add to General Settings
372
- * @since 0.1
373
- * @version 1.2
374
- */
375
- public function after_general_settings( $mycred = NULL ) {
 
 
376
 
377
- // Reset while on this screen so we can use $this->field_id() and $this->field_name()
378
- $this->module_name = 'buy_creds';
379
- $this->option_id = '';
380
 
381
- $uses_buddypress = class_exists( 'BuddyPress' );
382
 
383
- $settings = mycred_get_buycred_settings();
384
 
385
- ?>
386
  <h4><span class="dashicons dashicons-admin-plugins static"></span><strong>buy</strong>CRED</h4>
387
  <div class="body" style="display:none;">
388
 
389
- <div class="row">
390
- <div class="col-lg-8 col-md-8 col-sm-12 col-xs-12">
391
- <h3><?php _e( 'Sale Setup', 'mycred' ); ?></h3>
392
- <?php
393
-
394
- foreach ( $this->point_types as $type_id => $label ) {
395
-
396
- $mycred = mycred( $type_id );
397
- $sale_setup = mycred_get_buycred_sale_setup( $type_id );
398
-
399
- ?>
400
- <div class="row">
401
- <div class="col-lg-3 col-md-3 col-sm-12 col-xs-12">
402
-
403
- <div class="form-group">
404
- <label for="buycred-type-<?php echo esc_attr( $type_id ); ?>-enabled"><?php echo $mycred->plural(); ?></label>
405
- <div class="checkbox" style="padding-top: 4px;">
406
- <label for="buycred-type-<?php echo esc_attr( $type_id ); ?>-enabled"><input type="checkbox" name="mycred_pref_core[buy_creds][types][<?php echo esc_attr( $type_id ); ?>][enabled]" id="buycred-type-<?php echo esc_attr( $type_id ); ?>-enabled"<?php if ( in_array( $type_id, $settings['types'] ) ) echo ' checked="checked"'; ?> value="<?php echo esc_attr( $type_id ); ?>" /> <?php _e( 'Enable', 'mycred' ); ?></label>
407
- </div>
408
- </div>
409
-
410
- </div>
411
- <div class="col-lg-3 col-md-3 col-sm-12 col-xs-12">
412
-
413
- <div class="form-group">
414
- <label for="buycred-type-<?php echo esc_attr( $type_id ); ?>-min"><?php _e( 'Minimum Amount', 'mycred' ); ?></label>
415
- <input type="text" name="mycred_pref_core[buy_creds][types][<?php echo esc_attr( $type_id ); ?>][min]" id="buycred-type-<?php echo esc_attr( $type_id ); ?>-min" class="form-control" placeholder="<?php echo $mycred->get_lowest_value(); ?>" value="<?php echo esc_attr( $sale_setup['min'] ); ?>" />
416
- </div>
417
-
418
- </div>
419
- <div class="col-lg-6 col-md-6 col-sm-12 col-xs-12">
420
-
421
- <div class="form-group">
422
- <label for="buycred-type-<?php echo esc_attr( $type_id ); ?>-max"><?php _e( 'Maximum', 'mycred' ); ?></label>
423
- <div class="row">
424
- <div class="col-lg-6 col-md-6 col-sm-6 col-xs-6">
425
- <input type="text" name="mycred_pref_core[buy_creds][types][<?php echo esc_attr( $type_id ); ?>][max]" id="buycred-type-<?php echo esc_attr( $type_id ); ?>-max" class="form-control" placeholder="<?php _e( 'No limit', 'mycred' ); ?>" value="<?php echo esc_attr( $sale_setup['max'] ); ?>" />
426
- </div>
427
- <div class="col-lg-6 col-md-6 col-sm-6 col-xs-6">
428
- <?php mycred_purchase_limit_dropdown( 'mycred_pref_core[buy_creds][types][' . $type_id . '][time]', 'buycred-type-' . $type_id . '-time', $sale_setup['time'] ); ?>
429
- </div>
430
- </div>
431
- </div>
432
-
433
- </div>
434
- </div>
435
- <?php
436
-
437
- }
438
-
439
- ?>
440
- <hr />
441
- <div class="form-group">
442
- <div class="checkbox">
443
- <label for="<?php echo $this->field_id( 'custom_log' ); ?>"><input type="checkbox" name="<?php echo $this->field_name( 'custom_log' ); ?>" id="<?php echo $this->field_id( 'custom_log' ); ?>"<?php checked( $settings['custom_log'], 1 ); ?> value="1" /> <?php echo $this->core->template_tags_general( __( 'Create a dedicated log for purchases.', 'mycred' ) ); ?></label>
444
- </div>
445
- </div>
446
- </div>
447
- <div class="col-lg-4 col-md-4 col-sm-12 col-xs-12">
448
- <h3><?php _e( 'Checkout', 'mycred' ); ?></h3>
449
-
450
- <div class="form-group">
451
-
452
- <div class="row">
453
- <div class="col-lg-6 col-md-6 col-sm-6 col-xs-6 text-center">
454
- <label for="<?php echo $this->field_id( 'checkout-full' ); ?>">
455
- <img src="<?php echo plugins_url( 'assets/images/checkout-full.png', MYCRED_PURCHASE ); ?>" alt="" style="max-width: 100%; height: auto;" />
456
- <input type="radio" name="<?php echo $this->field_name( 'checkout' ); ?>"<?php checked( $settings['checkout'], 'page' ); ?> id="<?php echo $this->field_id( 'checkout-full' ); ?>" value="page" /> Full Page
457
- </label>
458
- </div>
459
- <div class="col-lg-6 col-md-6 col-sm-6 col-xs-6 text-center">
460
- <label for="<?php echo $this->field_id( 'checkout-popup' ); ?>">
461
- <img src="<?php echo plugins_url( 'assets/images/checkout-popup.png', MYCRED_PURCHASE ); ?>" alt="" style="max-width: 100%; height: auto;" />
462
- <input type="radio" name="<?php echo $this->field_name( 'checkout' ); ?>"<?php checked( $settings['checkout'], 'popup' ); ?> id="<?php echo $this->field_id( 'checkout-popup' ); ?>" value="popup" /> Popup
463
- </label>
464
- </div>
465
- </div>
466
-
467
- </div>
468
-
469
- </div>
470
- </div>
471
-
472
- <h3><?php _e( 'Redirects', 'mycred' ); ?></h3>
473
- <div class="row">
474
- <div class="col-lg-6 col-md-6 col-sm-12 col-xs-12">
475
-
476
- <div class="form-group">
477
- <p style="margin-top: 0;"><span class="description"><?php _e( 'Where should users be redirected to upon successfully completing a purchase. You can nominate a specific URL or a page.', 'mycred' ); ?></span></p>
478
- </div>
479
- <div class="form-group">
480
- <label for="<?php echo $this->field_id( array( 'thankyou' => 'page' ) ); ?>"><?php _e( 'Redirect to Page', 'mycred' ); ?></label>
481
- <?php
482
-
483
- // Thank you page dropdown
484
- $thankyou_args = array(
485
- 'name' => $this->field_name( array( 'thankyou' => 'page' ) ),
486
- 'id' => $this->field_id( array( 'thankyou' => 'page' ) ) . '-id',
487
- 'selected' => $settings['thankyou']['page'],
488
- 'show_option_none' => __( 'Select', 'mycred' ),
489
- 'class' => 'form-control'
490
- );
491
- wp_dropdown_pages( $thankyou_args );
492
-
493
- ?>
494
- </div>
495
- <div class="form-group">
496
- <label for="<?php echo $this->field_id( array( 'thankyou' => 'custom' ) ); ?>"><?php _e( 'Redirect to URL', 'mycred' ); ?></label>
497
- <input type="text" name="<?php echo $this->field_name( array( 'thankyou' => 'custom' ) ); ?>" id="<?php echo $this->field_id( array( 'thankyou' => 'custom' ) ); ?>" placeholder="https://" class="form-control" value="<?php echo esc_attr( $settings['thankyou']['custom'] ); ?>" />
498
- </div>
499
- <?php if ( $uses_buddypress ) : ?>
500
- <p style="margin-top: 0;"><span class="description"><?php _e( 'You can use %profile% for the base URL of the users profile.', 'mycred' ); ?></span></p>
501
- <?php endif; ?>
502
-
503
- </div>
504
- <div class="col-lg-6 col-md-6 col-sm-12 col-xs-12">
505
-
506
- <div class="form-group">
507
- <p style="margin-top: 0;"><span class="description"><?php _e( 'Where should users be redirected to if they cancel a transaction. You can nominate a specific URL or a page.', 'mycred' ); ?></span></p>
508
- </div>
509
- <div class="form-group">
510
- <label for="<?php echo $this->field_id( array( 'cancelled' => 'page' ) ); ?>"><?php _e( 'Redirect to Page', 'mycred' ); ?></label>
511
- <?php
512
-
513
- // Thank you page dropdown
514
- $thankyou_args = array(
515
- 'name' => $this->field_name( array( 'cancelled' => 'page' ) ),
516
- 'id' => $this->field_id( array( 'cancelled' => 'page' ) ) . '-id',
517
- 'selected' => $settings['cancelled']['page'],
518
- 'show_option_none' => __( 'Select', 'mycred' ),
519
- 'class' => 'form-control'
520
- );
521
- wp_dropdown_pages( $thankyou_args );
522
-
523
- ?>
524
- </div>
525
- <div class="form-group">
526
- <label for="<?php echo $this->field_id( array( 'cancelled' => 'custom' ) ); ?>"><?php _e( 'Redirect to URL', 'mycred' ); ?></label>
527
- <input type="text" name="<?php echo $this->field_name( array( 'cancelled' => 'custom' ) ); ?>" id="<?php echo $this->field_id( array( 'cancelled' => 'custom' ) ); ?>" placeholder="https://" class="form-control" value="<?php echo esc_attr( $settings['cancelled']['custom'] ); ?>" />
528
- </div>
529
- <?php if ( $uses_buddypress ) : ?>
530
- <p style="margin-top: 0;"><span class="description"><?php _e( 'You can use %profile% for the base URL of the users profile.', 'mycred' ); ?></span></p>
531
- <?php endif; ?>
532
-
533
- </div>
534
- </div>
535
-
536
- <h3><?php _e( 'Templates', 'mycred' ); ?></h3>
537
- <div class="row">
538
- <div class="col-lg-6 col-md-6 col-sm-12 col-xs-12">
539
-
540
- <div class="form-group">
541
- <label for="<?php echo $this->field_id( 'login' ); ?>"><?php _e( 'Login Message', 'mycred' ); ?></label>
542
- <input type="text" name="<?php echo $this->field_name( 'login' ); ?>" id="<?php echo $this->field_id( 'login' ); ?>" class="form-control" value="<?php echo esc_attr( $settings['login'] ); ?>" />
543
- <p><span class="description"><?php _e( 'Message to show in shortcodes when viewed by someone who is not logged in.', 'mycred' ); ?></span></p>
544
- </div>
545
-
546
- </div>
547
- <div class="col-lg-6 col-md-6 col-sm-12 col-xs-12">
548
-
549
- <div class="form-group">
550
- <label for="<?php echo $this->field_id( 'log' ); ?>"><?php _e( 'Log Template', 'mycred' ); ?></label>
551
- <input type="text" name="<?php echo $this->field_name( 'log' ); ?>" id="<?php echo $this->field_id( 'log' ); ?>" class="form-control" placeholder="<?php _e( 'Required', 'mycred' ); ?>" value="<?php echo esc_attr( $settings['log'] ); ?>" />
552
- <p><span class="description"><?php echo $this->core->available_template_tags( array( 'general' ), '%gateway%' ); ?></span></p>
553
- </div>
554
-
555
- </div>
556
- </div>
557
-
558
- <h3><?php _e( 'Gifting', 'mycred' ); ?></h3>
559
- <div class="row">
560
- <div class="col-lg-6 col-md-6 col-sm-12 col-xs-12">
561
-
562
- <div class="form-group">
563
- <div class="checkbox">
564
- <label for="<?php echo $this->field_id( array( 'gifting' => 'members' ) ); ?>"><input type="checkbox" name="<?php echo $this->field_name( array( 'gifting' => 'members' ) ); ?>" id="<?php echo $this->field_id( array( 'gifting' => 'members' ) ); ?>"<?php checked( $settings['gifting']['members'], 1 ); ?> value="1" /> <?php echo $this->core->template_tags_general( __( 'Allow users to buy %_plural% for other users.', 'mycred' ) ); ?></label>
565
- </div>
566
- <div class="checkbox">
567
- <label for="<?php echo $this->field_id( array( 'gifting' => 'authors' ) ); ?>"><input type="checkbox" name="<?php echo $this->field_name( array( 'gifting' => 'authors' ) ); ?>" id="<?php echo $this->field_id( array( 'gifting' => 'authors' ) ); ?>"<?php checked( $settings['gifting']['authors'], 1 ); ?> value="1" /> <?php echo $this->core->template_tags_general( __( 'Allow users to buy %_plural% for content authors.', 'mycred' ) ); ?></label>
568
- </div>
569
- </div>
570
-
571
- </div>
572
- <div class="col-lg-6 col-md-6 col-sm-12 col-xs-12">
573
-
574
- <div class="form-group">
575
- <label for="<?php echo $this->field_id( array( 'gifting' => 'log' ) ); ?>"><?php _e( 'Log Template', 'mycred' ); ?></label>
576
- <input type="text" name="<?php echo $this->field_name( array( 'gifting' => 'log' ) ); ?>" id="<?php echo $this->field_id( 'log' ); ?>" class="form-control" placeholder="<?php _e( 'Required', 'mycred' ); ?>" value="<?php echo esc_attr( $settings['gifting']['log'] ); ?>" />
577
- <p><span class="description"><?php echo $this->core->available_template_tags( array( 'general', 'user' ) ); ?></span></p>
578
- </div>
579
-
580
- </div>
581
- </div>
582
-
583
- <h3 style="margin-bottom: 0;"><?php _e( 'Available Shortcodes', 'mycred' ); ?></h3>
584
- <div class="row">
585
- <div class="col-lg-12 col-md-12 col-sm-12 col-xs-12">
586
- <p><a href="http://codex.mycred.me/shortcodes/mycred_buy/" target="_blank">[mycred_buy]</a>, <a href="http://codex.mycred.me/shortcodes/mycred_buy_form/" target="_blank">[mycred_buy_form]</a>, <a href="http://codex.mycred.me/shortcodes/mycred_buy_pending/" target="_blank">[mycred_buy_pending]</a></p>
587
- </div>
588
- </div>
 
589
 
590
  </div>
591
- <?php
592
 
593
- $this->module_name = 'gateways';
594
- $this->option_id = 'mycred_pref_buycreds';
595
 
596
- }
597
 
598
- /**
599
- * Save Settings
600
- * @since 0.1
601
- * @version 1.2
602
- */
603
- public function sanitize_extra_settings( $new_data, $data, $core ) {
 
 
604
 
605
- $point_types = array();
606
 
607
- if ( isset( $data['buy_creds']['types'] ) && ! empty( $data['buy_creds']['types'] ) ) {
608
- foreach ( $data['buy_creds']['types'] as $type_id => $setup ) {
609
 
610
- $type_id = sanitize_key( $type_id );
611
- if ( ! mycred_point_type_exists( $type_id ) ) continue;
 
612
 
613
- if ( isset( $setup['enabled'] ) )
614
- $point_types[] = $type_id;
 
615
 
616
- $settings = array();
617
- $settings['min'] = sanitize_text_field( $setup['min'] );
618
- $settings['max'] = sanitize_text_field( $setup['max'] );
619
- $settings['time'] = sanitize_key( $setup['time'] );
620
 
621
- $settings = shortcode_atts( mycred_get_buycred_sale_setup( $type_id ), $settings );
622
 
623
- mycred_update_option( 'buycred-setup-' . $type_id, $settings );
624
 
625
- }
626
- }
627
 
628
- if ( empty( $point_types ) )
629
- $point_types[] = MYCRED_DEFAULT_TYPE_KEY;
 
630
 
631
- $new_data['buy_creds']['types'] = $point_types;
632
 
633
- $new_data['buy_creds']['checkout'] = sanitize_key( $data['buy_creds']['checkout'] );
634
- $new_data['buy_creds']['log'] = sanitize_text_field( $data['buy_creds']['log'] );
635
- $new_data['buy_creds']['login'] = wp_kses_post( $data['buy_creds']['login'] );
636
 
637
- $new_data['buy_creds']['thankyou']['page'] = absint( $data['buy_creds']['thankyou']['page'] );
638
- $new_data['buy_creds']['thankyou']['custom'] = sanitize_text_field( $data['buy_creds']['thankyou']['custom'] );
639
- $new_data['buy_creds']['thankyou']['use'] = ( $new_data['buy_creds']['thankyou']['custom'] != '' ) ? 'custom' : 'page';
640
 
641
- $new_data['buy_creds']['cancelled']['page'] = absint( $data['buy_creds']['cancelled']['page'] );
642
- $new_data['buy_creds']['cancelled']['custom'] = sanitize_text_field( $data['buy_creds']['cancelled']['custom'] );
643
- $new_data['buy_creds']['cancelled']['use'] = ( $new_data['buy_creds']['cancelled']['custom'] != '' ) ? 'custom' : 'page';
644
 
645
- $new_data['buy_creds']['custom_log'] = ( ! isset( $data['buy_creds']['custom_log'] ) ) ? 0 : 1;
646
 
647
- $new_data['buy_creds']['gifting']['members'] = ( ! isset( $data['buy_creds']['gifting']['members'] ) ) ? 0 : 1;
648
- $new_data['buy_creds']['gifting']['authors'] = ( ! isset( $data['buy_creds']['gifting']['authors'] ) ) ? 0 : 1;
649
- $new_data['buy_creds']['gifting']['log'] = sanitize_text_field( $data['buy_creds']['gifting']['log'] );
650
 
651
- delete_option( 'mycred_buycred_reset' );
652
 
653
- return $new_data;
654
 
655
- }
656
 
657
- /**
658
- * Render Gift Tags
659
- * @since 1.4.1
660
- * @version 1.0
661
- */
662
- public function render_gift_tags( $content, $log ) {
 
 
663
 
664
- if ( substr( $log->ref, 0, 15 ) != 'buy_creds_with_' ) return $content;
665
- return $this->core->template_tags_user( $content, absint( $log->ref_id ) );
 
666
 
667
- }
668
 
669
- /**
670
- * Add Admin Menu Item
671
- * @since 0.1
672
- * @version 1.2
673
- */
674
- public function add_to_menu() {
 
 
675
 
676
- // In case we are using the Master Template feautre on multisites, and this is not the main
677
- // site in the network, bail.
678
- if ( mycred_override_settings() && ! mycred_is_main_site() ) return;
 
679
 
680
- // If we selected to insert a purchase log
681
- if ( isset( $this->core->buy_creds['custom_log'] ) && $this->core->buy_creds['custom_log'] ) {
682
 
683
- $pages = array();
684
- $point_types = ( isset( $this->core->buy_creds['types'] ) && ! empty( $this->core->buy_creds['types'] ) ) ? $this->core->buy_creds['types'] : array( MYCRED_DEFAULT_TYPE_KEY );
685
 
686
- foreach ( $point_types as $type_id ) {
687
 
688
- $mycred = mycred( $type_id );
689
- $menu_slug = ( $type_id != MYCRED_DEFAULT_TYPE_KEY ) ? MYCRED_SLUG . '_' . $type_id : MYCRED_SLUG;
690
 
691
- $pages[] = add_submenu_page(
692
- $menu_slug,
693
- __( 'buyCRED Purchase Log', 'mycred' ),
694
- __( 'Purchase Log', 'mycred' ),
695
- $mycred->get_point_editor_capability(),
696
- MYCRED_SLUG . '-purchases-' . $type_id,
697
- array( $this, 'purchase_log_page' )
698
- );
699
 
700
- }
701
 
702
- foreach ( $pages as $page ) {
703
 
704
- add_action( 'admin_print_styles-' . $page, array( $this, 'settings_page_enqueue' ) );
705
- add_action( 'load-' . $page, array( $this, 'screen_options' ) );
706
 
707
- }
708
 
709
- $this->purchase_log = $pages;
710
 
711
- }
712
 
713
- }
714
 
715
- /**
716
- * Page Header
717
- * @since 1.3
718
- * @version 1.2
719
- */
720
- public function settings_header() {
 
 
721
 
722
- wp_enqueue_style( 'mycred-admin' );
723
- wp_enqueue_style( 'mycred-bootstrap-grid' );
724
- wp_enqueue_style( 'mycred-forms' );
725
 
726
- }
727
 
728
- /**
729
- * Payment Gateways Page
730
- * @since 0.1
731
- * @since 2.3 Added more gateways in tab `mycred_buycred_more_gateways_tab`
732
- * @version 1.2.2
733
- */
734
- public function admin_page() {
 
 
735
 
736
- // Security
737
- if ( ! $this->core->user_is_point_admin() ) wp_die( 'Access Denied' );
 
738
 
739
- $installed = $this->get();
740
 
741
- ?>
742
  <div class="wrap mycred-metabox" id="myCRED-wrap">
743
- <h1><?php _e( 'buyCred Payment Gateways', 'mycred' ); ?></h1>
744
- <?php
745
-
746
- // Updated settings
747
- if ( isset( $_GET['settings-updated'] ) && $_GET['settings-updated'] == true )
748
- echo '<div class="updated settings-error"><p>' . __( 'Settings Updated', 'mycred' ) . '</p></div>';
749
-
750
- ?>
751
- <form method="post" action="options.php" class="form">
752
-
753
- <?php settings_fields( $this->settings_name ); ?>
754
-
755
- <?php do_action( 'mycred_before_buycreds_page', $this ); ?>
756
-
757
- <div class="list-items expandable-li" id="accordion">
758
- <?php
759
-
760
- if ( ! empty( $installed ) ) {
761
- foreach ( $installed as $key => $data ) {
762
-
763
- $has_documentation = ( array_key_exists( 'documentation', $data ) && ! empty( $data['documentation'] ) ) ? esc_url_raw( $data['documentation'] ) : false;
764
- $has_test_mode = ( array_key_exists( 'sandbox', $data ) ) ? (bool) $data['sandbox'] : false;
765
- $sandbox_mode = ( array_key_exists( $key, $this->gateway_prefs ) && array_key_exists( 'sandbox', $this->gateway_prefs[ $key ] ) && $this->gateway_prefs[ $key ]['sandbox'] === 1 ) ? true : false;
766
-
767
- if ( ! array_key_exists( 'icon', $data ) )
768
- $data['icon'] = 'dashicons-admin-plugins';
769
-
770
- $column_class = 'col-lg-6 col-md-6 col-sm-12 col-xs-12';
771
- if ( ! $has_documentation && ! $has_test_mode )
772
- $column_class = 'col-lg-12 col-md-12 col-sm-12 col-xs-12';
773
- elseif ( $has_documentation && $has_test_mode )
774
- $column_class = 'col-lg-4 col-md-4 col-sm-12 col-xs-12';
775
-
776
- ?>
777
- <h4><span class="dashicons <?php echo $data['icon']; ?><?php if ( $this->is_active( $key ) ) { if ( $sandbox_mode ) echo ' debug'; else echo ' active'; } else echo ' static'; ?>"></span><?php echo $this->core->template_tags_general( $data['title'] ); ?></h4>
778
- <div class="body" style="display: none;">
779
-
780
- <div class="row">
781
- <div class="col-lg-4 col-md-4 col-sm-12 col-xs-12">
782
- <div class="form-group">
783
- <div>&nbsp;</div>
784
- <label for="buycred-gateway-<?php echo $key; ?>"><input type="checkbox" name="mycred_pref_buycreds[active][]" id="buycred-gateway-<?php echo $key; ?>" value="<?php echo $key; ?>"<?php if ( $this->is_active( $key ) ) echo ' checked="checked"'; ?> /> <?php _e( 'Enable', 'mycred' ); ?></label>
785
- </div>
786
- </div>
787
- <div class="col-lg-4 col-md-4 col-sm-12 col-xs-12">
788
- <?php if ( $has_test_mode ) : ?>
789
- <div class="form-group">
790
- <div>&nbsp;</div>
791
- <label for="buycred-gateway-<?php echo $key; ?>-sandbox"><input type="checkbox" name="mycred_pref_buycreds[gateway_prefs][<?php echo $key; ?>][sandbox]" id="buycred-gateway-<?php echo $key; ?>-sandbox" value="<?php echo $key; ?>"<?php if ( $sandbox_mode ) echo ' checked="checked"'; ?> /> <?php _e( 'Sandbox Mode', 'mycred' ); ?></label>
792
- </div>
793
- <?php endif; ?>
794
- </div>
795
- <div class="col-lg-4 col-md-4 col-sm-12 col-xs-12" style="text-align: right;">
796
- <?php if ( MYCRED_DEFAULT_LABEL === 'myCRED' && $has_documentation ) : ?>
797
- <div class="form-group">
798
- <div>&nbsp;</div>
799
- <a href="<?php echo $has_documentation; ?>" target="_blank"><?php _e( 'Documentation', 'mycred' ); ?></a>
800
- </div>
801
- <?php endif; ?>
802
- </div>
803
- </div>
804
- <hr />
805
-
806
- <?php $this->call( 'preferences', $data['callback'] ); ?>
807
-
808
- <input type="hidden" name="mycred_pref_buycreds[installed]" value="<?php echo $key; ?>" />
809
- </div>
810
- <?php
811
-
812
- }
813
- }
814
-
815
- $more_gateways_tab = array();
816
-
817
- $more_gateways_tab[] = array(
818
- 'icon' => 'dashicons dashicons-admin-generic static',
819
- 'text' => 'Stripe',
820
- 'additional_text' => 'Paid',
821
- 'url' => 'https://mycred.me/store/buycred-stripe/',
822
- 'status' => 'disabled',
823
- 'plugin' => 'mycred-stripe/mycred-stripe.php'
824
- );
825
-
826
- $more_gateways_tab[] = array(
827
- 'icon' => 'dashicons dashicons-admin-generic static',
828
- 'text' => 'Coinbase',
829
- 'additional_text' => 'Paid',
830
- 'url' => 'https://mycred.me/store/buycred-coinbase/',
831
- 'status' => 'disabled',
832
- 'plugin' => 'mycred-coinbase/mycred-coinbase.php'
833
- );
834
-
835
- $more_gateways_tab[] = array(
836
- 'icon' => 'dashicons dashicons-admin-generic static',
837
- 'text' => 'More Gateways',
838
- 'url' => 'https://mycred.me/product-category/buycred-gateways/',
839
- );
840
-
841
- $more_gateways_tab = apply_filters( 'mycred_buycred_more_gateways_tab', $more_gateways_tab );
842
-
843
- if( MYCRED_SHOW_PREMIUM_ADDONS )
844
- {
845
- include_once( ABSPATH . 'wp-admin/includes/plugin.php' );
846
-
847
- foreach( $more_gateways_tab as $key => $gateway )
848
- {
849
-
850
- if ( isset( $gateway['plugin'] ) && is_plugin_active( $gateway['plugin'] ) )
851
- continue;
852
-
853
- $disabled_class = ( isset( $gateway['status'] ) && $gateway['status'] == 'disabled' ) ? 'disabled-tab' : '';
854
-
855
- $content = "
 
 
 
 
 
 
 
 
 
856
  <h4 class='ui-accordion-header ui-corner-top ui-accordion-header-collapsed ui-corner-all ui-state-default ui-accordion-icons buycred-cashcred-more-tab-btn {$disabled_class}' data-url='{$gateway['url']}'>
857
  <span class='ui-accordion-header-icon ui-icon ui-icon-triangle-1-e'></span>
858
  <span class='{$gateway['icon']}'></span>
859
  {$gateway['text']}";
860
 
861
- if( array_key_exists( 'additional_text', $gateway ) && !empty( $gateway['additional_text'] ) )
862
- $content .= "<span class='additional-text'>{$gateway['additional_text']}</span>";
863
-
864
- $content .= "</h4>
 
865
  <div class='body' style='display:none; padding: 0px; border: none;'>
866
  </div>";
867
 
868
- echo $content;
869
- }
870
- }
871
- ?>
872
 
873
- </div>
874
 
875
- <?php do_action( 'mycred_after_buycreds_page', $this ); ?>
876
 
877
- <p><?php submit_button( __( 'Update Settings', 'mycred' ), 'primary large', 'submit', false ); ?></p>
878
 
879
- </form>
880
 
881
- <?php do_action( 'mycred_bottom_buycreds_page', $this ); ?>
882
 
883
  <script type="text/javascript">
884
  jQuery(function($) {
885
- $( 'select.currency' ).change(function(){
886
- var target = $(this).attr( 'data-update' );
887
- $( '.' + target ).empty();
888
- $( '.' + target ).text( $(this).val() );
889
- });
890
  });
891
  </script>
892
  </div>
893
- <?php
894
-
895
- }
896
-
897
- /**
898
- * Sanititze Settings
899
- * @since 0.1
900
- * @version 1.3.1
901
- */
902
- public function sanitize_settings( $data ) {
903
-
904
- $data = apply_filters( 'mycred_buycred_save_prefs', $data );
905
- $installed = $this->get();
906
-
907
- if ( empty( $installed ) ) return $data;
908
-
909
- foreach ( $installed as $gateway_id => $gateway ) {
910
-
911
- $gateway_id = (string) $gateway_id;
912
- $submitted_data = ( ! empty( $data['gateway_prefs'] ) && array_key_exists( $gateway_id, $data['gateway_prefs'] ) ) ? $data['gateway_prefs'][ $gateway_id ] : false;
913
-
914
- // No need to do anything if we have no data
915
- if ( $submitted_data !== false )
916
- $data['gateway_prefs'][ $gateway_id ] = $this->call( 'sanitise_preferences', $installed[ $gateway_id ]['callback'], $submitted_data );
917
-
918
- }
919
-
920
- return $data;
921
-
922
- }
923
-
924
- /**
925
- * Purchase Log Screen Options
926
- * @since 1.4
927
- * @version 1.1
928
- */
929
- public function screen_options() {
930
-
931
- if ( empty( $this->purchase_log ) ) return;
932
-
933
- $meta_key = 'mycred_payments_' . str_replace( MYCRED_SLUG . '-purchases-', '', $_GET['page'] );
934
-
935
- if ( isset( $_REQUEST['wp_screen_options']['option'] ) && isset( $_REQUEST['wp_screen_options']['value'] ) ) {
936
-
937
- if ( $_REQUEST['wp_screen_options']['option'] == $meta_key ) {
938
- $value = absint( $_REQUEST['wp_screen_options']['value'] );
939
- mycred_update_user_meta( $this->current_user_id, $meta_key, $value );
940
- }
941
-
942
- }
943
-
944
- $args = array(
945
- 'label' => __( 'Payments', 'mycred' ),
946
- 'default' => 10,
947
- 'option' => $meta_key
948
- );
949
- add_screen_option( 'per_page', $args );
950
-
951
- }
952
-
953
- /**
954
- * Purchase Log
955
- * Render the dedicated admin screen where all point purchases are shown from the myCRED Log.
956
- * This screen is added in for each point type that is set to be for sale.
957
- * @since 1.4
958
- * @version 1.5
959
- */
960
- public function purchase_log_page() {
961
-
962
- $point_type = str_replace( 'mycred-purchases-', '', $_GET['page'] );
963
- $installed = $this->get();
964
-
965
- $mycred = $this->core;
966
- if ( $point_type != MYCRED_DEFAULT_TYPE_KEY && mycred_point_type_exists( $point_type ) )
967
- $mycred = mycred( $point_type );
968
-
969
- // Security (incase the user has setup different capabilities to manage this particular point type)
970
- if ( ! $mycred->user_is_point_editor() ) wp_die( 'Access Denied' );
971
-
972
- // Get references
973
- $references = mycred_get_buycred_gateway_refs( $point_type );
974
 
975
- $search_args = mycred_get_search_args();
976
- $filter_url = admin_url( 'admin.php?page=' . MYCRED_SLUG . '-purchases-' . $point_type );
977
-
978
- $per_page = mycred_get_user_meta( $this->current_user_id, 'mycred_payments_' . $point_type, '', true );
979
- if ( empty( $per_page ) || $per_page < 1 ) $per_page = 10;
980
-
981
- // Entries per page
982
- if ( ! array_key_exists( 'number', $search_args ) )
983
- $search_args['number'] = absint( $per_page );
984
-
985
- $search_args['ctype'] = $point_type;
986
- $search_args['ref'] = array(
987
- 'ids' => $references,
988
- 'compare' => 'IN'
989
- );
990
-
991
- $log = new myCRED_Query_Log( $search_args );
992
- $log->headers = apply_filters( 'mycred_buycred_log_columns', array(
993
- 'column-gateway' => __( 'Gateway', 'mycred' ),
994
- 'column-username' => __( 'Buyer', 'mycred' ),
995
- 'column-date' => __( 'Date', 'mycred' ),
996
- 'column-amount' => $mycred->plural(),
997
- 'column-payed' => __( 'Payed', 'mycred' ),
998
- 'column-tranid' => __( 'Transaction ID', 'mycred' )
999
- ) );
1000
-
1001
- ?>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1002
  <div class="wrap list" id="myCRED-wrap">
1003
- <h1><?php _e( 'Purchase Log', 'mycred' ); ?></h1>
1004
 
1005
- <?php $log->filter_dates( esc_url( $filter_url ) ); ?>
1006
 
1007
- <form method="get" action="" name="mycred-buycred-form" novalidate>
1008
- <input type="hidden" name="page" value="<?php echo esc_attr( $_GET['page'] ); ?>" />
1009
- <?php
1010
 
1011
- if ( array_key_exists( 's', $search_args ) )
1012
- echo '<input type="hidden" name="s" value="' . esc_attr( $search_args['s'] ) . '" />';
 
1013
 
1014
- if ( isset( $_GET['ref'] ) )
1015
- echo '<input type="hidden" name="show" value="' . esc_attr( $_GET['ref'] ) . '" />';
 
1016
 
1017
- if ( isset( $_GET['show'] ) )
1018
- echo '<input type="hidden" name="show" value="' . esc_attr( $_GET['show'] ) . '" />';
 
1019
 
1020
- if ( array_key_exists( 'order', $search_args ) )
1021
- echo '<input type="hidden" name="order" value="' . esc_attr( $search_args['order'] ) . '" />';
 
1022
 
1023
- if ( array_key_exists( 'paged', $search_args ) )
1024
- echo '<input type="hidden" name="paged" value="' . esc_attr( $search_args['paged'] ) . '" />';
 
1025
 
1026
- $log->search();
1027
 
1028
- ?>
1029
 
1030
- <?php do_action( 'mycred_above_payment_log_table', $this ); ?>
1031
 
1032
- <div class="tablenav top">
1033
 
1034
- <?php $log->table_nav( 'top' ); ?>
1035
 
1036
- </div>
1037
- <table class="wp-list-table widefat fixed striped users mycred-table" cellspacing="0">
1038
- <thead>
1039
- <tr>
1040
- <?php
1041
 
1042
- foreach ( $log->headers as $col_id => $col_title )
1043
- echo '<th scope="col" id="' . str_replace( 'column-', '', $col_id ) . '" class="manage-column ' . $col_id . '">' . $col_title . '</th>';
 
1044
 
1045
- ?>
1046
- </tr>
1047
- </thead>
1048
- <tfoot>
1049
- <tr>
1050
- <?php
1051
 
1052
- foreach ( $log->headers as $col_id => $col_title )
1053
- echo '<th scope="col" class="manage-column ' . $col_id . '">' . $col_title . '</th>';
 
1054
 
1055
- ?>
1056
- </tr>
1057
- </tfoot>
1058
- <tbody id="the-list">
1059
- <?php
1060
 
1061
- // If we have results
1062
- if ( $log->have_entries() ) {
1063
 
1064
- // Prep
1065
- $date_format = get_option( 'date_format' ) . ' ' . get_option( 'time_format' );
1066
- $entry_data = '';
1067
- $alt = 0;
1068
 
1069
- // Loop results
1070
- foreach ( $log->results as $log_entry ) {
1071
 
1072
- // Highlight alternate rows
1073
- $alt = $alt + 1;
1074
- $class = '';
1075
- $style = '';
1076
- if ( $alt % 2 == 0 ) $class = ' alt';
 
1077
 
1078
- // Prep Sales data for use in columns
1079
- $sales_data = $this->get_sales_data_from_log_data( $log_entry->data );
1080
- list ( $buyer_id, $payer_id, $amount, $cost, $currency, $token, $other ) = $sales_data;
1081
 
1082
- // Default Currency
1083
- if ( empty( $currency ) )
1084
- $currency = 'USD';
 
1085
 
1086
- $gateway_name = str_replace( 'buy_creds_with_', '', $log_entry->ref );
1087
 
1088
- // Color rows based on if the transaction was made in Sandbox mode or using a gateway that no longer is used.
1089
- if ( ! array_key_exists( str_replace( '_', '-', $gateway_name ), $installed ) )
1090
- $style = ' style="color:silver;"';
1091
 
1092
- elseif ( ! $this->is_active( str_replace( '_', '-', $gateway_name ) ) )
1093
- $style = ' style="color:gray;"';
1094
 
1095
- elseif ( substr( $log_entry->entry, 0, 4 ) == 'TEST' )
1096
- $style = ' style="color:orange;"';
 
1097
 
1098
- echo '<tr class="myCRED-log-row' . $class . '" id="mycred-log-entry-' . $log_entry->id . '">';
1099
 
1100
- // Run though columns
1101
- foreach ( $log->headers as $column_id => $column_name ) {
1102
 
1103
- echo '<td class="' . $column_id . '"' . $style . '>';
1104
 
1105
- switch ( $column_id ) {
1106
 
1107
- // Used gateway
1108
- case 'column-gateway' :
1109
 
1110
- $gateway = str_replace( array( '-', '_' ), ' ', $gateway_name );
1111
- echo ucwords( $gateway );
1112
 
1113
- break;
1114
 
1115
- // Username Column
1116
- case 'column-username' :
1117
 
1118
- $user = get_userdata( $log_entry->user_id );
1119
- if ( $user === false )
1120
- echo 'ID: ' . $log_entry->user_id;
1121
- else
1122
- echo $user->display_name . ' <em><small>(ID: ' . $log_entry->user_id . ')</small></em>';
 
1123
 
1124
- break;
1125
 
1126
- // Date & Time Column
1127
- case 'column-date' :
1128
 
1129
- echo date( $date_format, $log_entry->time );
1130
 
1131
- break;
1132
 
1133
- // Amount Column
1134
- case 'column-amount' :
1135
 
1136
- echo $mycred->format_creds( $log_entry->creds );
1137
 
1138
- break;
1139
 
1140
- // Amount Paid
1141
- case 'column-payed' :
1142
 
1143
- $cost = 'n/a';
1144
- $currency = '';
1145
- $data = maybe_unserialize( $log_entry->data );
1146
- if ( is_array( $data ) && array_key_exists( 'sales_data', $data ) ) {
1147
 
1148
- $sales_data = explode( '|', $data['sales_data'] );
1149
- if ( count( $sales_data ) >= 5 ) {
1150
- $cost = $sales_data[3];
1151
- $currency = $sales_data[4];
1152
- }
1153
 
1154
- }
1155
 
1156
- if ( $cost === 'n/a' )
1157
- echo 'n/a';
1158
 
1159
- else {
1160
 
1161
- $rendered_cost = apply_filters( 'mycred_buycred_display_cost', $cost . ' ' . $currency, $sales_data, $log_entry, $gateway_name );
1162
- $rendered_cost = apply_filters( 'mycred_buycred_display_cost_' . $gateway_name, $rendered_cost, $sales_data, $log_entry );
1163
 
1164
- echo $rendered_cost;
1165
 
1166
- }
1167
 
1168
- break;
1169
 
1170
- // Transaction ID
1171
- case 'column-tranid' :
1172
 
1173
- $transaction_id = $log_entry->time . $log_entry->user_id;
1174
- $saved_data = maybe_unserialize( $log_entry->data );
1175
 
1176
- if ( isset( $saved_data['txn_id'] ) )
1177
- $transaction_id = $saved_data['txn_id'];
1178
 
1179
- elseif ( isset( $saved_data['transaction_id'] ) )
1180
- $transaction_id = $saved_data['transaction_id'];
 
1181
 
1182
- echo $transaction_id;
1183
 
1184
- break;
1185
 
1186
- default :
1187
 
1188
- do_action( "mycred_payment_log_{$column_id}", $log_entry );
1189
- do_action( "mycred_payment_log_{$column_id}_{$type}", $log_entry );
1190
 
1191
- break;
1192
 
1193
- }
1194
 
1195
- echo '</td>';
1196
 
1197
- }
1198
 
1199
- echo '</tr>';
1200
 
1201
- }
1202
 
1203
- }
1204
 
1205
- // No log entry
1206
- else {
1207
 
1208
- echo '<tr><td colspan="' . count( $log->headers ) . '" class="no-entries">' . __( 'No purchases found', 'mycred' ) . '</td></tr>';
1209
 
1210
- }
1211
 
1212
- ?>
1213
- </tbody>
1214
- </table>
1215
- <div class="tablenav bottom">
1216
 
1217
- <?php $log->table_nav( 'bottom' ); ?>
1218
 
1219
- </div>
1220
 
1221
- <?php do_action( 'mycred_below_payment_log_table', $this ); ?>
1222
 
1223
- </form>
1224
  </div>
1225
- <?php
1226
 
1227
- }
1228
 
1229
- /**
1230
- * Get Sales Data from Log Data
1231
- * @since 1.4
1232
- * @version 1.0.1
1233
- */
1234
- public function get_sales_data_from_log_data( $log_data = '' ) {
 
 
1235
 
1236
- $defaults = array( '', '', '', '', '', '', '' );
1237
- $log_data = maybe_unserialize( $log_data );
1238
 
1239
- $found_data = array();
1240
- if ( is_array( $log_data ) && array_key_exists( 'sales_data', $log_data ) ) {
1241
- if ( is_array( $log_data['sales_data'] ) )
1242
- $found_data = $log_data['sales_data'];
1243
- else
1244
- $found_data = explode( '|', $log_data['sales_data'] );
1245
- }
1246
- elseif ( ! empty( $log_data ) && ! is_array( $log_data ) ) {
1247
- $try = explode( '|', $log_data );
1248
- if ( count( $try == 7 ) )
1249
- $found_data = $log_data;
1250
- }
 
 
1251
 
1252
- return wp_parse_args( $found_data, $defaults );
1253
 
1254
- }
1255
 
1256
- /**
1257
- * User Rates Admin Screen
1258
- * @since 1.5
1259
- * @version 1.0
1260
- */
1261
- public function exchange_rates_user_screen( $user ) {
 
 
1262
 
1263
- // Make sure buyCRED is setup
1264
- if ( ! isset( $this->core->buy_creds['types'] ) || empty( $this->core->buy_creds['types'] ) ) return;
 
1265
 
1266
- // Only visible to admins
1267
- if ( ! mycred_is_admin() ) return;
 
1268
 
1269
- $mycred_types = mycred_get_types( true );
1270
- $point_types_for_sale = $this->core->buy_creds['types'];
1271
- $installed = $this->get();
1272
- $available_options = array();
1273
 
1274
- foreach ( $installed as $gateway_id => $prefs ) {
1275
 
1276
- // Gateway is not active or settings have not yet been saved
1277
- if ( ! $this->is_active( $gateway_id ) || ! array_key_exists( $gateway_id, $this->gateway_prefs ) || ! $prefs['custom_rate'] ) continue;
 
1278
 
1279
- $gateway_prefs = $this->gateway_prefs[ $gateway_id ];
1280
 
1281
- // Need a currency
1282
- if ( array_key_exists( 'currency', $gateway_prefs ) && $gateway_prefs['currency'] == '' ) continue;
 
1283
 
1284
- if ( ! array_key_exists( 'currency', $gateway_prefs ) )
1285
- $gateway_prefs['currency'] = 'USD';
 
1286
 
1287
- $setup = array( 'name' => $prefs['title'], 'currency' => $gateway_prefs['currency'], 'types' => array() );
1288
 
1289
- foreach ( $mycred_types as $point_type_key => $label ) {
1290
 
1291
- $row = array( 'name' => $label, 'enabled' => false, 'excluded' => true, 'default' => 0, 'override' => false, 'custom' => '', 'before' => '' );
1292
 
1293
- if ( in_array( $point_type_key, $point_types_for_sale ) && array_key_exists( $point_type_key, $gateway_prefs['exchange'] ) ) {
1294
 
1295
- $row['enabled'] = true;
1296
 
1297
- $mycred = mycred( $point_type_key );
1298
 
1299
- if ( ! $mycred->exclude_user( $user->ID ) ) {
1300
 
1301
- $row['excluded'] = false;
1302
- $row['default'] = $gateway_prefs['exchange'][ $point_type_key ];
1303
 
1304
- $row['before'] = $mycred->format_creds( 1 ) . ' = ';
1305
 
1306
- $saved_overrides = (array) mycred_get_user_meta( $user->ID, 'mycred_buycred_rates_' . $point_type_key, '', true );
1307
 
1308
- if ( ! empty( $saved_overrides ) && array_key_exists( $gateway_id, $saved_overrides ) ) {
1309
 
1310
- $row['override'] = true;
1311
- $row['custom'] = $saved_overrides[ $gateway_id ];
1312
 
1313
- }
1314
 
1315
- }
1316
 
1317
- }
1318
 
1319
- $setup['types'][ $point_type_key ] = $row;
1320
 
1321
- }
1322
 
1323
- $available_options[ $gateway_id ] = $setup;
1324
 
1325
- }
1326
 
1327
- if ( empty( $available_options ) ) return;
 
1328
 
1329
- ?>
1330
- <p class="mycred-p"><?php _e( 'Users exchange rate when buying points.', 'mycred' ); ?></p>
1331
  <table class="form-table mycred-inline-table">
1332
- <?php
1333
-
1334
- foreach ( $available_options as $gateway_id => $setup ) :
1335
-
1336
- ?>
1337
- <tr>
1338
- <th scope="row"><?php echo esc_attr( $setup['name'] ); ?></th>
1339
- <td>
1340
- <fieldset id="mycred-buycred-list" class="buycred-list">
1341
- <legend class="screen-reader-text"><span><?php _e( 'buyCRED Exchange Rates', 'mycred' ); ?></span></legend>
1342
- <?php
1343
-
1344
- foreach ( $setup['types'] as $type_id => $data ) {
1345
-
1346
- // This point type is not for sale
1347
- if ( ! $data['enabled'] ) {
1348
-
1349
- ?>
1350
- <div class="mycred-wrapper buycred-wrapper disabled-option color-option">
1351
- <div><?php printf( _x( 'Buying %s', 'Points Name', 'mycred' ), $data['name'] ); ?></div>
1352
- <div class="balance-row">
1353
- <div class="balance-view"><?php _e( 'Disabled', 'mycred' ); ?></div>
1354
- <div class="balance-desc"><em><?php _e( 'This point type is not for sale.', 'mycred' ); ?></em></div>
1355
- </div>
1356
- </div>
1357
- <?php
1358
-
1359
- }
1360
-
1361
- // This user is excluded from this point type
1362
- elseif ( $data['excluded'] ) {
1363
-
1364
- ?>
1365
- <div class="mycred-wrapper buycred-wrapper excluded-option color-option">
1366
- <div><?php printf( _x( 'Buying %s', 'Buying Points', 'mycred' ), $data['name'] ); ?></div>
1367
- <div class="balance-row">
1368
- <div class="balance-view"><?php _e( 'Excluded', 'mycred' ); ?></div>
1369
- <div class="balance-desc"><em><?php printf( _x( 'User can not buy %s', 'Points Name', 'mycred' ), $data['name'] ); ?></em></div>
1370
- </div>
1371
- </div>
1372
- <?php
1373
-
1374
- }
1375
-
1376
- // Eligeble user
1377
- else {
1378
-
1379
- ?>
1380
- <div class="mycred-wrapper buycred-wrapper color-option selected">
1381
- <div><?php printf( _x( 'Buying %s', 'Buying Points', 'mycred' ), $data['name'] ); ?></div>
1382
- <div class="balance-row">
1383
- <div class="balance-view"><?php echo $data['before']; ?><input type="text" name="mycred_adjust_users_buyrates[<?php echo $type_id; ?>][<?php echo $gateway_id; ?>]" placeholder="<?php echo $data['default']; ?>" value="<?php if ( $data['override'] ) echo esc_attr( $data['custom'] ); ?>" class="short" size="8" /><?php echo ' ' . $setup['currency']; ?></div>
1384
- <div class="balance-desc"><em><?php _e( 'Leave empty to use the default rate.', 'mycred' ); ?></em></div>
1385
- </div>
1386
- </div>
1387
- <?php
1388
-
1389
- }
1390
-
1391
- }
1392
-
1393
- ?>
1394
- </fieldset>
1395
- </td>
1396
- </tr>
1397
- <?php
1398
-
1399
- endforeach;
1400
-
1401
- ?>
 
1402
  </table>
1403
  <hr />
1404
  <script type="text/javascript">
1405
  jQuery(function($) {
1406
 
1407
- $( '.buycred-wrapper label input.trigger-buycred' ).change(function(){
1408
 
1409
- if ( $(this).val().length > 0 )
1410
- $(this).parent().parent().parent().addClass( 'selected' );
1411
 
1412
- else
1413
- $(this).parent().parent().parent().removeClass( 'selected' );
1414
 
1415
- });
1416
 
1417
  });
1418
  </script>
1419
- <?php
1420
 
1421
- }
1422
 
1423
- /**
1424
- * Save Override
1425
- * @since 1.5
1426
- * @version 1.2
1427
- */
1428
- public function save_manual_exchange_rates( $user_id ) {
 
 
1429
 
1430
- if ( ! mycred_is_admin() ) return;
 
1431
 
1432
- if ( isset( $_POST['mycred_adjust_users_buyrates'] ) && is_array( $_POST['mycred_adjust_users_buyrates'] ) && ! empty( $_POST['mycred_adjust_users_buyrates'] ) ) {
1433
 
1434
- foreach ( $_POST['mycred_adjust_users_buyrates'] as $ctype => $gateway ) {
1435
 
1436
- $ctype = sanitize_key( $ctype );
1437
- $mycred = mycred( $ctype );
1438
 
1439
- if ( ! $mycred->exclude_user( $user_id ) ) {
1440
 
1441
- $new_rates = array();
1442
- foreach ( (array) $gateway as $gateway_id => $rate ) {
1443
 
1444
- if ( $rate == '' ) continue;
 
1445
 
1446
- if ( $rate != 1 && in_array( substr( $rate, 0, 1 ), array( '.', ',' ) ) )
1447
- $rate = (float) '0' . $rate;
 
1448
 
1449
- $new_rates[ $gateway_id ] = $rate;
1450
 
1451
- }
1452
 
1453
- if ( ! empty( $new_rates ) )
1454
- mycred_update_user_meta( $user_id, 'mycred_buycred_rates_' . $ctype, '', $new_rates );
1455
- else
1456
- mycred_delete_user_meta( $user_id, 'mycred_buycred_rates_' . $ctype );
 
1457
 
1458
- }
1459
 
1460
- }
1461
 
1462
- }
1463
 
1464
- }
1465
 
1466
- /**
1467
- * Hide Comments
1468
- * @since 1.8.9
1469
- * @version 1.0
1470
- */
1471
- public function hide_buycred_transactions( $query ) {
 
 
1472
 
1473
- $query->query_vars['type__not_in'] = 'buycred';
1474
-
1475
- }
1476
 
1477
- }
1478
  endif;
1479
 
1480
  /**
1481
  * Load buyCRED Module
1482
- * @since 1.7
 
1483
  * @version 1.0
1484
  */
1485
- if ( ! function_exists( 'mycred_load_buycred_core_addon' ) ) :
1486
- function mycred_load_buycred_core_addon( $modules, $point_types ) {
 
1487
 
1488
- $modules['solo']['buycred'] = new myCRED_buyCRED_Module();
1489
- $modules['solo']['buycred']->load();
1490
 
1491
- return $modules;
1492
 
1493
- }
1494
  endif;
1495
- add_filter( 'mycred_load_modules', 'mycred_load_buycred_core_addon', 30, 2 );
1
  <?php
2
+ if (! defined('MYCRED_PURCHASE') ) { exit;
3
+ }
4
 
5
  /**
6
  * myCRED_buyCRED_Module class
7
+ *
8
+ * @since 0.1
9
  * @version 1.4.1
10
  */
11
+ if (! class_exists('myCRED_buyCRED_Module') ) :
12
+ class myCRED_buyCRED_Module extends myCRED_Module
13
+ {
14
+
15
+ public $purchase_log = '';
16
+
17
+ /**
18
+ * Construct
19
+ */
20
+ function __construct( $type = MYCRED_DEFAULT_TYPE_KEY )
21
+ {
22
+
23
+ parent::__construct(
24
+ 'myCRED_BuyCRED_Module', array(
25
+ 'module_name' => 'gateways',
26
+ 'option_id' => 'mycred_pref_buycreds',
27
+ 'defaults' => array(
28
+ 'installed' => array(),
29
+ 'active' => array(),
30
+ 'gateway_prefs' => array()
31
+ ),
32
+ 'labels' => array(
33
+ 'menu' => __('buyCred Gateways', 'mycred'),
34
+ 'page_title' => __('buyCred Gateways', 'mycred'),
35
+ 'page_header' => __('buyCred Gateways', 'mycred')
36
+ ),
37
+ 'screen_id' => MYCRED_SLUG . '-gateways',
38
+ 'accordion' => true,
39
+ 'add_to_core' => true,
40
+ 'menu_pos' => 70,
41
+ 'main_menu' => true
42
+ ), $type
43
+ );
44
+
45
+ $this->mycred_type = MYCRED_DEFAULT_TYPE_KEY;
46
+
47
+ }
48
+
49
+ /**
50
+ * Load
51
+ *
52
+ * @version 1.0.2
53
+ */
54
+ public function load()
55
+ {
56
+
57
+ add_filter('mycred_parse_log_entry', array( $this, 'render_gift_tags' ), 10, 2);
58
+
59
+ add_action('mycred_init', array( $this, 'module_init' ), $this->menu_pos);
60
+ add_action('wp_loaded', array( $this, 'module_run' ));
61
+
62
+ add_action('mycred_register_assets', array( $this, 'register_assets' ));
63
+ add_action('mycred_front_enqueue_footer', array( $this, 'enqueue_footer' ));
64
+
65
+ add_action('mycred_admin_init', array( $this, 'module_admin_init' ), $this->menu_pos);
66
+ add_action('mycred_admin_init', array( $this, 'register_settings' ), $this->menu_pos+1);
67
+ add_action('mycred_add_menu', array( $this, 'add_menu' ), $this->menu_pos);
68
+ add_action('mycred_add_menu', array( $this, 'add_to_menu' ), $this->menu_pos+1);
69
+
70
+ add_action('mycred_after_core_prefs', array( $this, 'after_general_settings' ));
71
+ add_filter('mycred_save_core_prefs', array( $this, 'sanitize_extra_settings' ), 90, 3);
72
+
73
+ add_action('pre_get_comments', array( $this, 'hide_buycred_transactions' ));
74
+
75
+ }
76
+
77
+ /**
78
+ * Init
79
+ * Register shortcodes.
80
+ *
81
+ * @since 0.1
82
+ * @version 1.4
83
+ */
84
+ public function module_init()
85
+ {
86
+
87
+ // Add shortcodes first
88
+ add_shortcode(MYCRED_SLUG . '_buy', 'mycred_render_buy_points');
89
+ add_shortcode(MYCRED_SLUG . '_buy_form', 'mycred_render_buy_form_points');
90
+
91
+ $this->setup_instance();
92
+
93
+ $this->current_user_id = get_current_user_id();
94
+
95
+ }
96
+
97
+ /**
98
+ * Register Assets
99
+ *
100
+ * @since 1.8
101
+ * @version 1.0
102
+ */
103
+ public function register_assets()
104
+ {
105
+
106
+ wp_register_style('buycred-checkout', plugins_url('assets/css/checkout.css', MYCRED_PURCHASE), array(), MYCRED_PURCHASE_VERSION, 'all');
107
+ wp_register_script('buycred-checkout', plugins_url('assets/js/checkout.js', MYCRED_PURCHASE), array( 'jquery' ), MYCRED_PURCHASE_VERSION, 'all');
108
+
109
+ }
110
+
111
+ /**
112
+ * Setup Purchase Instance
113
+ *
114
+ * @since 1.8
115
+ * @version 1.0
116
+ */
117
+ public function setup_instance()
118
+ {
119
+
120
+ global $buycred_instance;
121
+
122
+ $buycred_instance = new StdClass();
123
+ $buycred_instance->settings = mycred_get_buycred_settings();
124
+ $buycred_instance->active = array();
125
+ $buycred_instance->gateway_id = false;
126
+ $buycred_instance->checkout = false;
127
+ $buycred_instance->cancelled = false;
128
+ $buycred_instance->error = false;
129
+ $buycred_instance->gateway = false;
130
+
131
+ }
132
+
133
+ /**
134
+ * Get Payment Gateways
135
+ * Retreivs all available payment gateways that can be used to buyCRED
136
+ *
137
+ * @since 0.1
138
+ * @version 1.1.1
139
+ */
140
+ public function get()
141
+ {
142
 
143
+ $installed = mycred_get_buycred_gateways();
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
144
 
145
+ // Untill all custom gateways have been updated, make sure all gateways have an external setting
146
+ if (! empty($installed) ) {
147
+ foreach ( $installed as $id => $settings ) {
 
 
 
 
 
 
 
 
 
 
 
 
148
 
149
+ if (! array_key_exists('external', $settings) ) {
150
+ $installed[ $id ]['external'] = true;
151
+ }
 
 
 
152
 
153
+ if (! array_key_exists('custom_rate', $settings) ) {
154
+ $installed[ $id ]['custom_rate'] = false;
155
+ }
156
 
157
+ }
158
+ }
 
 
 
 
 
 
159
 
160
+ return $installed;
161
 
162
+ }
 
 
 
 
 
 
163
 
164
+ /**
165
+ * Run
166
+ * Runs a gateway if requested.
167
+ *
168
+ * @since 1.7
169
+ * @version 1.0
170
+ */
171
+ public function module_run()
172
+ {
173
 
174
+ global $buycred_instance;
 
 
175
 
176
+ // Prep
177
+ $installed = $this->get();
178
 
179
+ // Make sure we have installed gateways.
180
+ if (empty($installed) ) { return;
181
+ }
182
 
183
+ // We only want to deal with active gateways
184
+ foreach ( $installed as $id => $data ) {
185
+ if ($this->is_active($id) ) {
186
+ $buycred_instance->active[ $id ] = $data;
187
+ }
188
+ }
189
 
190
+ if (empty($buycred_instance->active) ) { return;
191
+ }
192
 
193
+ /**
194
+ * Step 1 - Look for returns
195
+ * Runs though all active payment gateways and lets them decide if this is the
196
+ * user returning after a remote purchase. Each gateway should know what to look
197
+ * for to determen if they are responsible for handling the return.
198
+ */
199
+ foreach ( $buycred_instance->active as $id => $data ) {
200
 
201
+ if ($data['external'] === true ) {
202
+ $this->call('returning', $buycred_instance->active[ $id ]['callback']);
203
+ }
 
 
 
 
204
 
205
+ }
206
 
207
+ /**
208
+ * Step 2 - Check for gateway calls
209
+ * Checks to see if a gateway should be loaded.
210
+ */
211
+ $buycred_instance->gateway_id = mycred_get_requested_gateway_id();
212
+ $buycred_instance->checkout = false;
213
+ $buycred_instance->is_ajax = ( isset($_REQUEST['ajax']) && $_REQUEST['ajax'] == 1 ) ? true : false;
214
 
215
+ do_action('mycred_pre_process_buycred');
 
216
 
217
+ // If we have a valid gateway ID and the gateway is active, lets run that gateway.
218
+ if ($buycred_instance->gateway_id !== false && array_key_exists($buycred_instance->gateway_id, $buycred_instance->active) ) {
 
 
 
219
 
220
+ // Construct Gateway
221
+ $buycred_instance->gateway = buycred_gateway($buycred_instance->gateway_id);
222
 
223
+ // Check payment processing
224
+ if (isset($_REQUEST['mycred_call']) ) {
 
 
 
 
 
225
 
226
+ $buycred_instance->gateway->process();
 
227
 
228
+ do_action('mycred_buycred_process', $buycred_instance->gateway_id, $this->gateway_prefs);
229
+ do_action("mycred_buycred_process_{$gateway_id}", $this->gateway_prefs);
230
 
231
+ }
 
 
 
 
 
 
232
 
233
+ add_action('template_redirect', array( $this, 'process_new_request' ));
234
+ add_filter('template_include', array( $this, 'checkout_page' ),999);
235
 
236
+ }
 
237
 
238
+ }
 
239
 
240
+ /**
241
+ * Process New Request
242
+ *
243
+ * @since 1.8
244
+ * @version 1.0
245
+ */
246
+ public function process_new_request()
247
+ {
248
 
249
+ global $buycred_instance, $buycred_sale;
250
 
251
+ if ($buycred_instance->checkout === false && isset($_REQUEST['mycred_buy']) ) {
252
+ $buycred_instance->checkout = true;
253
+ }
254
 
255
+ if ($buycred_instance->checkout ) {
256
 
257
+ $buycred_sale = true;
 
258
 
259
+ if ($buycred_instance->gateway->valid_request() ) {
260
 
261
+ if ($buycred_instance->is_ajax ) {
262
+ $buycred_instance->gateway->ajax_buy();
263
+ }
264
 
265
+ do_action('mycred_buycred_buy', $buycred_instance->gateway_id, $this->gateway_prefs);
266
+ do_action("mycred_buycred_buy_{$buycred_instance->gateway_id}", $this->gateway_prefs);
 
 
 
 
267
 
268
+ }
269
+ else {
270
 
271
+ if (! empty($buycred_instance->gateway->errors) ) {
272
+ $buycred_instance->checkout = false;
273
 
274
+ if ($buycred_instance->is_ajax ) {
275
+ die(json_encode(array( 'validationFail' => true , 'errors' => $buycred_instance->gateway->errors )));
276
+ } else
277
+ {
278
+ foreach( $buycred_instance->gateway->errors as $error )
279
+ {
280
+ global $wp;
281
+ echo "
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
282
  <script>
283
  alert('".$error."');
284
+ location.replace( '".home_url($wp->request)."' );
285
  </script>
286
  ";
287
+ }
288
+ }
289
+ }
290
 
291
+ }
292
 
293
+ }
294
 
295
+ }
296
 
297
+ /**
298
+ * Checkout Page
299
+ *
300
+ * @since 1.8
301
+ * @version 1.0
302
+ */
303
+ public function checkout_page( $template )
304
+ {
305
 
306
+ global $buycred_instance;
307
 
308
+ if ($buycred_instance->checkout ) {
309
 
310
+ return MYCRED_BUYCRED_TEMPLATES_DIR . 'buycred-checkout.php';
311
+ $override = mycred_locate_template('buycred-checkout.php', MYCRED_SLUG, MYCRED_BUYCRED_TEMPLATES_DIR);
312
+ if (! $override ) {
313
+ $template = $override;
314
+ }
315
 
316
+ }
317
 
318
+ return $template;
319
 
320
+ }
321
 
322
+ /**
323
+ * Enqueue Footer
324
+ *
325
+ * @since 1.8
326
+ * @version 1.0
327
+ */
328
+ public function enqueue_footer()
329
+ {
330
 
331
+ global $buycred_instance, $buycred_sale;
332
 
333
+ $settings = mycred_get_buycred_settings();
334
 
335
+ if ($buycred_sale ) {
336
 
337
+ wp_enqueue_style('buycred-checkout');
338
 
339
+ wp_localize_script(
340
+ 'buycred-checkout',
341
+ 'buyCRED',
342
+ apply_filters(
343
+ 'mycred_buycred_checkout_js', array(
344
+ 'ajaxurl' => get_site_url(),
345
+ 'token' => wp_create_nonce('mycred-buy-creds'),
346
+ 'checkout' => $settings['checkout'],
347
+ 'redirecting' => esc_js(esc_attr__('Redirecting', 'mycred')),
348
+ 'error' => 'communications error'
349
+ ), $this
350
+ )
351
+ );
352
+ wp_enqueue_script('buycred-checkout');
353
 
354
+ if ($settings['checkout'] != 'page' ) {
355
+ echo '
356
  <div id="cancel-checkout-wrapper"><a href="javascript:void(0);">X</a></div>
357
  <div id="buycred-checkout-wrapper">
358
  <div class="checkout-inside">
369
  </div>
370
  </div>
371
  </div>';
372
+ }
373
 
374
+ }
375
 
376
+ }
377
 
378
+ /**
379
+ * Admin Init
380
+ *
381
+ * @since 1.5
382
+ * @version 1.1
383
+ */
384
+ public function module_admin_init()
385
+ {
386
 
387
+ add_action('mycred_user_edit_after_balances', array( $this, 'exchange_rates_user_screen' ), 30);
388
 
389
+ add_action('personal_options_update', array( $this, 'save_manual_exchange_rates' ), 30);
390
+ add_action('edit_user_profile_update', array( $this, 'save_manual_exchange_rates' ), 30);
391
 
392
+ // Prep
393
+ $installed = mycred_get_buycred_gateways();
394
 
395
+ // Make sure we have installed gateways.
396
+ if (empty($installed) ) { return;
397
+ }
398
 
399
+ /**
400
+ * Admin Init
401
+ * Runs though all installed gateways to allow admin inits.
402
+ */
403
+ foreach ( $installed as $id => $data ) {
404
+ $this->call('admin_init', $installed[ $id ]['callback']);
405
+ }
406
 
407
+ }
408
 
409
+ /**
410
+ * Add to General Settings
411
+ *
412
+ * @since 0.1
413
+ * @version 1.2
414
+ */
415
+ public function after_general_settings( $mycred = null )
416
+ {
417
 
418
+ // Reset while on this screen so we can use $this->field_id() and $this->field_name()
419
+ $this->module_name = 'buy_creds';
420
+ $this->option_id = '';
421
 
422
+ $uses_buddypress = class_exists('BuddyPress');
423
 
424
+ $settings = mycred_get_buycred_settings();
425
 
426
+ ?>
427
  <h4><span class="dashicons dashicons-admin-plugins static"></span><strong>buy</strong>CRED</h4>
428
  <div class="body" style="display:none;">
429
 
430
+ <div class="row">
431
+ <div class="col-lg-8 col-md-8 col-sm-12 col-xs-12">
432
+ <h3><?php _e('Sale Setup', 'mycred'); ?></h3>
433
+ <?php
434
+
435
+ foreach ( $this->point_types as $type_id => $label ) {
436
+
437
+ $mycred = mycred($type_id);
438
+ $sale_setup = mycred_get_buycred_sale_setup($type_id);
439
+
440
+ ?>
441
+ <div class="row">
442
+ <div class="col-lg-3 col-md-3 col-sm-12 col-xs-12">
443
+
444
+ <div class="form-group">
445
+ <label for="buycred-type-<?php echo esc_attr($type_id); ?>-enabled"><?php echo $mycred->plural(); ?></label>
446
+ <div class="checkbox" style="padding-top: 4px;">
447
+ <label for="buycred-type-<?php echo esc_attr($type_id); ?>-enabled"><input type="checkbox" name="mycred_pref_core[buy_creds][types][<?php echo esc_attr($type_id); ?>][enabled]" id="buycred-type-<?php echo esc_attr($type_id); ?>-enabled"<?php if (in_array($type_id, $settings['types']) ) { echo ' checked="checked"';
448
+ } ?> value="<?php echo esc_attr($type_id); ?>" /> <?php _e('Enable', 'mycred'); ?></label>
449
+ </div>
450
+ </div>
451
+
452
+ </div>
453
+ <div class="col-lg-3 col-md-3 col-sm-12 col-xs-12">
454
+
455
+ <div class="form-group">
456
+ <label for="buycred-type-<?php echo esc_attr($type_id); ?>-min"><?php _e('Minimum Amount', 'mycred'); ?></label>
457
+ <input type="text" name="mycred_pref_core[buy_creds][types][<?php echo esc_attr($type_id); ?>][min]" id="buycred-type-<?php echo esc_attr($type_id); ?>-min" class="form-control" placeholder="<?php echo $mycred->get_lowest_value(); ?>" value="<?php echo esc_attr($sale_setup['min']); ?>" />
458
+ </div>
459
+
460
+ </div>
461
+ <div class="col-lg-6 col-md-6 col-sm-12 col-xs-12">
462
+
463
+ <div class="form-group">
464
+ <label for="buycred-type-<?php echo esc_attr($type_id); ?>-max"><?php _e('Maximum', 'mycred'); ?></label>
465
+ <div class="row">
466
+ <div class="col-lg-6 col-md-6 col-sm-6 col-xs-6">
467
+ <input type="text" name="mycred_pref_core[buy_creds][types][<?php echo esc_attr($type_id); ?>][max]" id="buycred-type-<?php echo esc_attr($type_id); ?>-max" class="form-control" placeholder="<?php _e('No limit', 'mycred'); ?>" value="<?php echo esc_attr($sale_setup['max']); ?>" />
468
+ </div>
469
+ <div class="col-lg-6 col-md-6 col-sm-6 col-xs-6">
470
+ <?php mycred_purchase_limit_dropdown('mycred_pref_core[buy_creds][types][' . $type_id . '][time]', 'buycred-type-' . $type_id . '-time', $sale_setup['time']); ?>
471
+ </div>
472
+ </div>
473
+ </div>
474
+
475
+ </div>
476
+ </div>
477
+ <?php
478
+
479
+ }
480
+
481
+ ?>
482
+ <hr />
483
+ <div class="form-group">
484
+ <div class="checkbox">
485
+ <label for="<?php echo $this->field_id('custom_log'); ?>"><input type="checkbox" name="<?php echo $this->field_name('custom_log'); ?>" id="<?php echo $this->field_id('custom_log'); ?>"<?php checked($settings['custom_log'], 1); ?> value="1" /> <?php echo $this->core->template_tags_general(__('Create a dedicated log for purchases.', 'mycred')); ?></label>
486
+ </div>
487
+ </div>
488
+ </div>
489
+ <div class="col-lg-4 col-md-4 col-sm-12 col-xs-12">
490
+ <h3><?php _e('Checkout', 'mycred'); ?></h3>
491
+
492
+ <div class="form-group">
493
+
494
+ <div class="row">
495
+ <div class="col-lg-6 col-md-6 col-sm-6 col-xs-6 text-center">
496
+ <label for="<?php echo $this->field_id('checkout-full'); ?>">
497
+ <img src="<?php echo plugins_url('assets/images/checkout-full.png', MYCRED_PURCHASE); ?>" alt="" style="max-width: 100%; height: auto;" />
498
+ <input type="radio" name="<?php echo $this->field_name('checkout'); ?>"<?php checked($settings['checkout'], 'page'); ?> id="<?php echo $this->field_id('checkout-full'); ?>" value="page" /> Full Page
499
+ </label>
500
+ </div>
501
+ <div class="col-lg-6 col-md-6 col-sm-6 col-xs-6 text-center">
502
+ <label for="<?php echo $this->field_id('checkout-popup'); ?>">
503
+ <img src="<?php echo plugins_url('assets/images/checkout-popup.png', MYCRED_PURCHASE); ?>" alt="" style="max-width: 100%; height: auto;" />
504
+ <input type="radio" name="<?php echo $this->field_name('checkout'); ?>"<?php checked($settings['checkout'], 'popup'); ?> id="<?php echo $this->field_id('checkout-popup'); ?>" value="popup" /> Popup
505
+ </label>
506
+ </div>
507
+ </div>
508
+
509
+ </div>
510
+
511
+ </div>
512
+ </div>
513
+
514
+ <h3><?php _e('Redirects', 'mycred'); ?></h3>
515
+ <div class="row">
516
+ <div class="col-lg-6 col-md-6 col-sm-12 col-xs-12">
517
+
518
+ <div class="form-group">
519
+ <p style="margin-top: 0;"><span class="description"><?php _e('Where should users be redirected to upon successfully completing a purchase. You can nominate a specific URL or a page.', 'mycred'); ?></span></p>
520
+ </div>
521
+ <div class="form-group">
522
+ <label for="<?php echo $this->field_id(array( 'thankyou' => 'page' )); ?>"><?php _e('Redirect to Page', 'mycred'); ?></label>
523
+ <?php
524
+
525
+ // Thank you page dropdown
526
+ $thankyou_args = array(
527
+ 'name' => $this->field_name(array( 'thankyou' => 'page' )),
528
+ 'id' => $this->field_id(array( 'thankyou' => 'page' )) . '-id',
529
+ 'selected' => $settings['thankyou']['page'],
530
+ 'show_option_none' => __('Select', 'mycred'),
531
+ 'class' => 'form-control'
532
+ );
533
+ wp_dropdown_pages($thankyou_args);
534
+
535
+ ?>
536
+ </div>
537
+ <div class="form-group">
538
+ <label for="<?php echo $this->field_id(array( 'thankyou' => 'custom' )); ?>"><?php _e('Redirect to URL', 'mycred'); ?></label>
539
+ <input type="text" name="<?php echo $this->field_name(array( 'thankyou' => 'custom' )); ?>" id="<?php echo $this->field_id(array( 'thankyou' => 'custom' )); ?>" placeholder="https://" class="form-control" value="<?php echo esc_attr($settings['thankyou']['custom']); ?>" />
540
+ </div>
541
+ <?php if ($uses_buddypress ) : ?>
542
+ <p style="margin-top: 0;"><span class="description"><?php _e('You can use %profile% for the base URL of the users profile.', 'mycred'); ?></span></p>
543
+ <?php endif; ?>
544
+
545
+ </div>
546
+ <div class="col-lg-6 col-md-6 col-sm-12 col-xs-12">
547
+
548
+ <div class="form-group">
549
+ <p style="margin-top: 0;"><span class="description"><?php _e('Where should users be redirected to if they cancel a transaction. You can nominate a specific URL or a page.', 'mycred'); ?></span></p>
550
+ </div>
551
+ <div class="form-group">
552
+ <label for="<?php echo $this->field_id(array( 'cancelled' => 'page' )); ?>"><?php _e('Redirect to Page', 'mycred'); ?></label>
553
+ <?php
554
+
555
+ // Thank you page dropdown
556
+ $thankyou_args = array(
557
+ 'name' => $this->field_name(array( 'cancelled' => 'page' )),
558
+ 'id' => $this->field_id(array( 'cancelled' => 'page' )) . '-id',
559
+ 'selected' => $settings['cancelled']['page'],
560
+ 'show_option_none' => __('Select', 'mycred'),
561
+ 'class' => 'form-control'
562
+ );
563
+ wp_dropdown_pages($thankyou_args);
564
+
565
+ ?>
566
+ </div>
567
+ <div class="form-group">
568
+ <label for="<?php echo $this->field_id(array( 'cancelled' => 'custom' )); ?>"><?php _e('Redirect to URL', 'mycred'); ?></label>
569
+ <input type="text" name="<?php echo $this->field_name(array( 'cancelled' => 'custom' )); ?>" id="<?php echo $this->field_id(array( 'cancelled' => 'custom' )); ?>" placeholder="https://" class="form-control" value="<?php echo esc_attr($settings['cancelled']['custom']); ?>" />
570
+ </div>
571
+ <?php if ($uses_buddypress ) : ?>
572
+ <p style="margin-top: 0;"><span class="description"><?php _e('You can use %profile% for the base URL of the users profile.', 'mycred'); ?></span></p>
573
+ <?php endif; ?>
574
+
575
+ </div>
576
+ </div>
577
+
578
+ <h3><?php _e('Templates', 'mycred'); ?></h3>
579
+ <div class="row">
580
+ <div class="col-lg-6 col-md-6 col-sm-12 col-xs-12">
581
+
582
+ <div class="form-group">
583
+ <label for="<?php echo $this->field_id('login'); ?>"><?php _e('Login Message', 'mycred'); ?></label>
584
+ <input type="text" name="<?php echo $this->field_name('login'); ?>" id="<?php echo $this->field_id('login'); ?>" class="form-control" value="<?php echo esc_attr($settings['login']); ?>" />
585
+ <p><span class="description"><?php _e('Message to show in shortcodes when viewed by someone who is not logged in.', 'mycred'); ?></span></p>
586
+ </div>
587
+
588
+ </div>
589
+ <div class="col-lg-6 col-md-6 col-sm-12 col-xs-12">
590
+
591
+ <div class="form-group">
592
+ <label for="<?php echo $this->field_id('log'); ?>"><?php _e('Log Template', 'mycred'); ?></label>
593
+ <input type="text" name="<?php echo $this->field_name('log'); ?>" id="<?php echo $this->field_id('log'); ?>" class="form-control" placeholder="<?php _e('Required', 'mycred'); ?>" value="<?php echo esc_attr($settings['log']); ?>" />
594
+ <p><span class="description"><?php echo $this->core->available_template_tags(array( 'general' ), '%gateway%'); ?></span></p>
595
+ </div>
596
+
597
+ </div>
598
+ </div>
599
+
600
+ <h3><?php _e('Gifting', 'mycred'); ?></h3>
601
+ <div class="row">
602
+ <div class="col-lg-6 col-md-6 col-sm-12 col-xs-12">
603
+
604
+ <div class="form-group">
605
+ <div class="checkbox">
606
+ <label for="<?php echo $this->field_id(array( 'gifting' => 'members' )); ?>"><input type="checkbox" name="<?php echo $this->field_name(array( 'gifting' => 'members' )); ?>" id="<?php echo $this->field_id(array( 'gifting' => 'members' )); ?>"<?php checked($settings['gifting']['members'], 1); ?> value="1" /> <?php echo $this->core->template_tags_general(__('Allow users to buy %_plural% for other users.', 'mycred')); ?></label>
607
+ </div>
608
+ <div class="checkbox">
609
+ <label for="<?php echo $this->field_id(array( 'gifting' => 'authors' )); ?>"><input type="checkbox" name="<?php echo $this->field_name(array( 'gifting' => 'authors' )); ?>" id="<?php echo $this->field_id(array( 'gifting' => 'authors' )); ?>"<?php checked($settings['gifting']['authors'], 1); ?> value="1" /> <?php echo $this->core->template_tags_general(__('Allow users to buy %_plural% for content authors.', 'mycred')); ?></label>
610
+ </div>
611
+ </div>
612
+
613
+ </div>
614
+ <div class="col-lg-6 col-md-6 col-sm-12 col-xs-12">
615
+
616
+ <div class="form-group">
617
+ <label for="<?php echo $this->field_id(array( 'gifting' => 'log' )); ?>"><?php _e('Log Template', 'mycred'); ?></label>
618
+ <input type="text" name="<?php echo $this->field_name(array( 'gifting' => 'log' )); ?>" id="<?php echo $this->field_id('log'); ?>" class="form-control" placeholder="<?php _e('Required', 'mycred'); ?>" value="<?php echo esc_attr($settings['gifting']['log']); ?>" />
619
+ <p><span class="description"><?php echo $this->core->available_template_tags(array( 'general', 'user' )); ?></span></p>
620
+ </div>
621
+
622
+ </div>
623
+ </div>
624
+
625
+ <h3 style="margin-bottom: 0;"><?php _e('Available Shortcodes', 'mycred'); ?></h3>
626
+ <div class="row">
627
+ <div class="col-lg-12 col-md-12 col-sm-12 col-xs-12">
628
+ <p><a href="http://codex.mycred.me/shortcodes/mycred_buy/" target="_blank">[mycred_buy]</a>, <a href="http://codex.mycred.me/shortcodes/mycred_buy_form/" target="_blank">[mycred_buy_form]</a>, <a href="http://codex.mycred.me/shortcodes/mycred_buy_pending/" target="_blank">[mycred_buy_pending]</a></p>
629
+ </div>
630
+ </div>
631
 
632
  </div>
633
+ <?php
634
 
635
+ $this->module_name = 'gateways';
636
+ $this->option_id = 'mycred_pref_buycreds';
637
 
638
+ }
639
 
640
+ /**
641
+ * Save Settings
642
+ *
643
+ * @since 0.1
644
+ * @version 1.2
645
+ */
646
+ public function sanitize_extra_settings( $new_data, $data, $core )
647
+ {
648
 
649
+ $point_types = array();
650
 
651
+ if (isset($data['buy_creds']['types']) && ! empty($data['buy_creds']['types']) ) {
652
+ foreach ( $data['buy_creds']['types'] as $type_id => $setup ) {
653
 
654
+ $type_id = sanitize_key($type_id);
655
+ if (! mycred_point_type_exists($type_id) ) { continue;
656
+ }
657
 
658
+ if (isset($setup['enabled']) ) {
659
+ $point_types[] = $type_id;
660
+ }
661
 
662
+ $settings = array();
663
+ $settings['min'] = sanitize_text_field($setup['min']);
664
+ $settings['max'] = sanitize_text_field($setup['max']);
665
+ $settings['time'] = sanitize_key($setup['time']);
666
 
667
+ $settings = shortcode_atts(mycred_get_buycred_sale_setup($type_id), $settings);
668
 
669
+ mycred_update_option('buycred-setup-' . $type_id, $settings);
670
 
671
+ }
672
+ }
673
 
674
+ if (empty($point_types) ) {
675
+ $point_types[] = MYCRED_DEFAULT_TYPE_KEY;
676
+ }
677
 
678
+ $new_data['buy_creds']['types'] = $point_types;
679
 
680
+ $new_data['buy_creds']['checkout'] = sanitize_key($data['buy_creds']['checkout']);
681
+ $new_data['buy_creds']['log'] = sanitize_text_field($data['buy_creds']['log']);
682
+ $new_data['buy_creds']['login'] = wp_kses_post($data['buy_creds']['login']);
683
 
684
+ $new_data['buy_creds']['thankyou']['page'] = absint($data['buy_creds']['thankyou']['page']);
685
+ $new_data['buy_creds']['thankyou']['custom'] = sanitize_text_field($data['buy_creds']['thankyou']['custom']);
686
+ $new_data['buy_creds']['thankyou']['use'] = ( $new_data['buy_creds']['thankyou']['custom'] != '' ) ? 'custom' : 'page';
687
 
688
+ $new_data['buy_creds']['cancelled']['page'] = absint($data['buy_creds']['cancelled']['page']);
689
+ $new_data['buy_creds']['cancelled']['custom'] = sanitize_text_field($data['buy_creds']['cancelled']['custom']);
690
+ $new_data['buy_creds']['cancelled']['use'] = ( $new_data['buy_creds']['cancelled']['custom'] != '' ) ? 'custom' : 'page';
691
 
692
+ $new_data['buy_creds']['custom_log'] = ( ! isset($data['buy_creds']['custom_log']) ) ? 0 : 1;
693
 
694
+ $new_data['buy_creds']['gifting']['members'] = ( ! isset($data['buy_creds']['gifting']['members']) ) ? 0 : 1;
695
+ $new_data['buy_creds']['gifting']['authors'] = ( ! isset($data['buy_creds']['gifting']['authors']) ) ? 0 : 1;
696
+ $new_data['buy_creds']['gifting']['log'] = sanitize_text_field($data['buy_creds']['gifting']['log']);
697
 
698
+ delete_option('mycred_buycred_reset');
699
 
700
+ return $new_data;
701
 
702
+ }
703
 
704
+ /**
705
+ * Render Gift Tags
706
+ *
707
+ * @since 1.4.1
708
+ * @version 1.0
709
+ */
710
+ public function render_gift_tags( $content, $log )
711
+ {
712
 
713
+ if (substr($log->ref, 0, 15) != 'buy_creds_with_' ) { return $content;
714
+ }
715
+ return $this->core->template_tags_user($content, absint($log->ref_id));
716
 
717
+ }
718
 
719
+ /**
720
+ * Add Admin Menu Item
721
+ *
722
+ * @since 0.1
723
+ * @version 1.2
724
+ */
725
+ public function add_to_menu()
726
+ {
727
 
728
+ // In case we are using the Master Template feautre on multisites, and this is not the main
729
+ // site in the network, bail.
730
+ if (mycred_override_settings() && ! mycred_is_main_site() ) { return;
731
+ }
732
 
733
+ // If we selected to insert a purchase log
734
+ if (isset($this->core->buy_creds['custom_log']) && $this->core->buy_creds['custom_log'] ) {
735
 
736
+ $pages = array();
737
+ $point_types = ( isset($this->core->buy_creds['types']) && ! empty($this->core->buy_creds['types']) ) ? $this->core->buy_creds['types'] : array( MYCRED_DEFAULT_TYPE_KEY );
738
 
739
+ foreach ( $point_types as $type_id ) {
740
 
741
+ $mycred = mycred($type_id);
742
+ $menu_slug = ( $type_id != MYCRED_DEFAULT_TYPE_KEY ) ? MYCRED_SLUG . '_' . $type_id : MYCRED_SLUG;
743
 
744
+ $pages[] = add_submenu_page(
745
+ $menu_slug,
746
+ __('buyCRED Purchase Log', 'mycred'),
747
+ __('Purchase Log', 'mycred'),
748
+ $mycred->get_point_editor_capability(),
749
+ MYCRED_SLUG . '-purchases-' . $type_id,
750
+ array( $this, 'purchase_log_page' )
751
+ );
752
 
753
+ }
754
 
755
+ foreach ( $pages as $page ) {
756
 
757
+ add_action('admin_print_styles-' . $page, array( $this, 'settings_page_enqueue' ));
758
+ add_action('load-' . $page, array( $this, 'screen_options' ));
759
 
760
+ }
761
 
762
+ $this->purchase_log = $pages;
763
 
764
+ }
765
 
766
+ }
767
 
768
+ /**
769
+ * Page Header
770
+ *
771
+ * @since 1.3
772
+ * @version 1.2
773
+ */
774
+ public function settings_header()
775
+ {
776
 
777
+ wp_enqueue_style('mycred-admin');
778
+ wp_enqueue_style('mycred-bootstrap-grid');
779
+ wp_enqueue_style('mycred-forms');
780
 
781
+ }
782
 
783
+ /**
784
+ * Payment Gateways Page
785
+ *
786
+ * @since 0.1
787
+ * @since 2.3 Added more gateways in tab `mycred_buycred_more_gateways_tab`
788
+ * @version 1.2.2
789
+ */
790
+ public function admin_page()
791
+ {
792
 
793
+ // Security
794
+ if (! $this->core->user_is_point_admin() ) { wp_die('Access Denied');
795
+ }
796
 
797
+ $installed = $this->get();
798
 
799
+ ?>
800
  <div class="wrap mycred-metabox" id="myCRED-wrap">
801
+ <h1><?php _e('buyCred Payment Gateways', 'mycred'); ?></h1>
802
+ <?php
803
+
804
+ // Updated settings
805
+ if (isset($_GET['settings-updated']) && $_GET['settings-updated'] == true ) {
806
+ echo '<div class="updated settings-error"><p>' . __('Settings Updated', 'mycred') . '</p></div>';
807
+ }
808
+
809
+ ?>
810
+ <form method="post" action="options.php" class="form">
811
+
812
+ <?php settings_fields($this->settings_name); ?>
813
+
814
+ <?php do_action('mycred_before_buycreds_page', $this); ?>
815
+
816
+ <div class="list-items expandable-li" id="accordion">
817
+ <?php
818
+
819
+ if (! empty($installed) ) {
820
+ foreach ( $installed as $key => $data ) {
821
+
822
+ $has_documentation = ( array_key_exists('documentation', $data) && ! empty($data['documentation']) ) ? esc_url_raw($data['documentation']) : false;
823
+ $has_test_mode = ( array_key_exists('sandbox', $data) ) ? (bool) $data['sandbox'] : false;
824
+ $sandbox_mode = ( array_key_exists($key, $this->gateway_prefs) && array_key_exists('sandbox', $this->gateway_prefs[ $key ]) && $this->gateway_prefs[ $key ]['sandbox'] === 1 ) ? true : false;
825
+
826
+ if (! array_key_exists('icon', $data) ) {
827
+ $data['icon'] = 'dashicons-admin-plugins';
828
+ }
829
+
830
+ $column_class = 'col-lg-6 col-md-6 col-sm-12 col-xs-12';
831
+ if (! $has_documentation && ! $has_test_mode ) {
832
+ $column_class = 'col-lg-12 col-md-12 col-sm-12 col-xs-12';
833
+ } elseif ($has_documentation && $has_test_mode ) {
834
+ $column_class = 'col-lg-4 col-md-4 col-sm-12 col-xs-12';
835
+ }
836
+
837
+ ?>
838
+ <h4><span class="dashicons <?php echo $data['icon']; ?><?php if ($this->is_active($key) ) { if ($sandbox_mode ) { echo ' debug';
839
+ } else { echo ' active';
840
+ }
841
+ } else { echo ' static';
842
+ } ?>"></span><?php echo $this->core->template_tags_general($data['title']); ?></h4>
843
+ <div class="body" style="display: none;">
844
+
845
+ <div class="row">
846
+ <div class="col-lg-4 col-md-4 col-sm-12 col-xs-12">
847
+ <div class="form-group">
848
+ <div>&nbsp;</div>
849
+ <label for="buycred-gateway-<?php echo $key; ?>"><input type="checkbox" name="mycred_pref_buycreds[active][]" id="buycred-gateway-<?php echo $key; ?>" value="<?php echo $key; ?>"<?php if ($this->is_active($key) ) { echo ' checked="checked"';
850
+ } ?> /> <?php _e('Enable', 'mycred'); ?></label>
851
+ </div>
852
+ </div>
853
+ <div class="col-lg-4 col-md-4 col-sm-12 col-xs-12">
854
+ <?php if ($has_test_mode ) : ?>
855
+ <div class="form-group">
856
+ <div>&nbsp;</div>
857
+ <label for="buycred-gateway-<?php echo $key; ?>-sandbox"><input type="checkbox" name="mycred_pref_buycreds[gateway_prefs][<?php echo $key; ?>][sandbox]" id="buycred-gateway-<?php echo $key; ?>-sandbox" value="<?php echo $key; ?>"<?php if ($sandbox_mode ) { echo ' checked="checked"';
858
+ } ?> /> <?php _e('Sandbox Mode', 'mycred'); ?></label>
859
+ </div>
860
+ <?php endif; ?>
861
+ </div>
862
+ <div class="col-lg-4 col-md-4 col-sm-12 col-xs-12" style="text-align: right;">
863
+ <?php if (MYCRED_DEFAULT_LABEL === 'myCRED' && $has_documentation ) : ?>
864
+ <div class="form-group">
865
+ <div>&nbsp;</div>
866
+ <a href="<?php echo $has_documentation; ?>" target="_blank"><?php _e('Documentation', 'mycred'); ?></a>
867
+ </div>
868
+ <?php endif; ?>
869
+ </div>
870
+ </div>
871
+ <hr />
872
+
873
+ <?php $this->call('preferences', $data['callback']); ?>
874
+
875
+ <input type="hidden" name="mycred_pref_buycreds[installed]" value="<?php echo $key; ?>" />
876
+ </div>
877
+ <?php
878
+
879
+ }
880
+ }
881
+
882
+ $more_gateways_tab = array();
883
+
884
+ $more_gateways_tab[] = array(
885
+ 'icon' => 'dashicons dashicons-admin-generic static',
886
+ 'text' => 'Stripe',
887
+ 'additional_text' => 'Paid',
888
+ 'url' => 'https://mycred.me/store/buycred-stripe/',
889
+ 'status' => 'disabled',
890
+ 'plugin' => 'mycred-stripe/mycred-stripe.php'
891
+ );
892
+
893
+ $more_gateways_tab[] = array(
894
+ 'icon' => 'dashicons dashicons-admin-generic static',
895
+ 'text' => 'Coinbase',
896
+ 'additional_text' => 'Paid',
897
+ 'url' => 'https://mycred.me/store/buycred-coinbase/',
898
+ 'status' => 'disabled',
899
+ 'plugin' => 'mycred-coinbase/mycred-coinbase.php'
900
+ );
901
+
902
+ $more_gateways_tab[] = array(
903
+ 'icon' => 'dashicons dashicons-admin-generic static',
904
+ 'text' => 'More Gateways',
905
+ 'url' => 'https://mycred.me/product-category/buycred-gateways/',
906
+ );
907
+
908
+ $more_gateways_tab = apply_filters('mycred_buycred_more_gateways_tab', $more_gateways_tab);
909
+
910
+ if(MYCRED_SHOW_PREMIUM_ADDONS ) {
911
+ include_once ABSPATH . 'wp-admin/includes/plugin.php';
912
+
913
+ foreach( $more_gateways_tab as $key => $gateway )
914
+ {
915
+
916
+ if (isset($gateway['plugin']) && is_plugin_active($gateway['plugin']) ) {
917
+ continue;
918
+ }
919
+
920
+ $disabled_class = ( isset($gateway['status']) && $gateway['status'] == 'disabled' ) ? 'disabled-tab' : '';
921
+
922
+ $content = "
923
  <h4 class='ui-accordion-header ui-corner-top ui-accordion-header-collapsed ui-corner-all ui-state-default ui-accordion-icons buycred-cashcred-more-tab-btn {$disabled_class}' data-url='{$gateway['url']}'>
924
  <span class='ui-accordion-header-icon ui-icon ui-icon-triangle-1-e'></span>
925
  <span class='{$gateway['icon']}'></span>
926
  {$gateway['text']}";
927
 
928
+ if(array_key_exists('additional_text', $gateway) && !empty($gateway['additional_text']) ) {
929
+ $content .= "<span class='additional-text'>{$gateway['additional_text']}</span>";
930
+ }
931
+
932
+ $content .= "</h4>
933
  <div class='body' style='display:none; padding: 0px; border: none;'>
934
  </div>";
935
 
936
+ echo $content;
937
+ }
938
+ }
939
+ ?>
940
 
941
+ </div>
942
 
943
+ <?php do_action('mycred_after_buycreds_page', $this); ?>
944
 
945
+ <p><?php submit_button(__('Update Settings', 'mycred'), 'primary large', 'submit', false); ?></p>
946
 
947
+ </form>
948
 
949
+ <?php do_action('mycred_bottom_buycreds_page', $this); ?>
950
 
951
  <script type="text/javascript">
952
  jQuery(function($) {
953
+ $( 'select.currency' ).change(function(){
954
+ var target = $(this).attr( 'data-update' );
955
+ $( '.' + target ).empty();
956
+ $( '.' + target ).text( $(this).val() );
957
+ });
958
  });
959
  </script>
960
  </div>
961
+ <?php
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
962
 
963
+ }
964
+
965
+ /**
966
+ * Sanititze Settings
967
+ *
968
+ * @since 0.1
969
+ * @version 1.3.1
970
+ */
971
+ public function sanitize_settings( $data )
972
+ {
973
+
974
+ $data = apply_filters('mycred_buycred_save_prefs', $data);
975
+ $installed = $this->get();
976
+
977
+ if (empty($installed) ) { return $data;
978
+ }
979
+
980
+ foreach ( $installed as $gateway_id => $gateway ) {
981
+
982
+ $gateway_id = (string) $gateway_id;
983
+ $submitted_data = ( ! empty($data['gateway_prefs']) && array_key_exists($gateway_id, $data['gateway_prefs']) ) ? $data['gateway_prefs'][ $gateway_id ] : false;
984
+
985
+ // No need to do anything if we have no data
986
+ if ($submitted_data !== false ) {
987
+ $data['gateway_prefs'][ $gateway_id ] = $this->call('sanitise_preferences', $installed[ $gateway_id ]['callback'], $submitted_data);
988
+ }
989
+
990
+ }
991
+
992
+ return $data;
993
+
994
+ }
995
+
996
+ /**
997
+ * Purchase Log Screen Options
998
+ *
999
+ * @since 1.4
1000
+ * @version 1.1
1001
+ */
1002
+ public function screen_options()
1003
+ {
1004
+
1005
+ if (empty($this->purchase_log) ) { return;
1006
+ }
1007
+
1008
+ $meta_key = 'mycred_payments_' . str_replace(MYCRED_SLUG . '-purchases-', '', $_GET['page']);
1009
+
1010
+ if (isset($_REQUEST['wp_screen_options']['option']) && isset($_REQUEST['wp_screen_options']['value']) ) {
1011
+
1012
+ if ($_REQUEST['wp_screen_options']['option'] == $meta_key ) {
1013
+ $value = absint($_REQUEST['wp_screen_options']['value']);
1014
+ mycred_update_user_meta($this->current_user_id, $meta_key, $value);
1015
+ }
1016
+
1017
+ }
1018
+
1019
+ $args = array(
1020
+ 'label' => __('Payments', 'mycred'),
1021
+ 'default' => 10,
1022
+ 'option' => $meta_key
1023
+ );
1024
+ add_screen_option('per_page', $args);
1025
+
1026
+ }
1027
+
1028
+ /**
1029
+ * Purchase Log
1030
+ * Render the dedicated admin screen where all point purchases are shown from the myCRED Log.
1031
+ * This screen is added in for each point type that is set to be for sale.
1032
+ *
1033
+ * @since 1.4
1034
+ * @version 1.5
1035
+ */
1036
+ public function purchase_log_page()
1037
+ {
1038
+
1039
+ $point_type = str_replace('mycred-purchases-', '', $_GET['page']);
1040
+ $installed = $this->get();
1041
+
1042
+ $mycred = $this->core;
1043
+ if ($point_type != MYCRED_DEFAULT_TYPE_KEY && mycred_point_type_exists($point_type) ) {
1044
+ $mycred = mycred($point_type);
1045
+ }
1046
+
1047
+ // Security (incase the user has setup different capabilities to manage this particular point type)
1048
+ if (! $mycred->user_is_point_editor() ) { wp_die('Access Denied');
1049
+ }
1050
+
1051
+ // Get references
1052
+ $references = mycred_get_buycred_gateway_refs($point_type);
1053
+
1054
+ $search_args = mycred_get_search_args();
1055
+ $filter_url = admin_url('admin.php?page=' . MYCRED_SLUG . '-purchases-' . $point_type);
1056
+
1057
+ $per_page = mycred_get_user_meta($this->current_user_id, 'mycred_payments_' . $point_type, '', true);
1058
+ if (empty($per_page) || $per_page < 1 ) { $per_page = 10;
1059
+ }
1060
+
1061
+ // Entries per page
1062
+ if (! array_key_exists('number', $search_args) ) {
1063
+ $search_args['number'] = absint($per_page);
1064
+ }
1065
+
1066
+ $search_args['ctype'] = $point_type;
1067
+ $search_args['ref'] = array(
1068
+ 'ids' => $references,
1069
+ 'compare' => 'IN'
1070
+ );
1071
+
1072
+ $log = new myCRED_Query_Log($search_args);
1073
+ $log->headers = apply_filters(
1074
+ 'mycred_buycred_log_columns', array(
1075
+ 'column-gateway' => __('Gateway', 'mycred'),
1076
+ 'column-username' => __('Buyer', 'mycred'),
1077
+ 'column-date' => __('Date', 'mycred'),
1078
+ 'column-amount' => $mycred->plural(),
1079
+ 'column-payed' => __('Payed', 'mycred'),
1080
+ 'column-tranid' => __('Transaction ID', 'mycred')
1081
+ )
1082
+ );
1083
+
1084
+ ?>
1085
  <div class="wrap list" id="myCRED-wrap">
1086
+ <h1><?php _e('Purchase Log', 'mycred'); ?></h1>
1087
 
1088
+ <?php $log->filter_dates(esc_url($filter_url)); ?>
1089
 
1090
+ <form method="get" action="" name="mycred-buycred-form" novalidate>
1091
+ <input type="hidden" name="page" value="<?php echo esc_attr($_GET['page']); ?>" />
1092
+ <?php
1093
 
1094
+ if (array_key_exists('s', $search_args) ) {
1095
+ echo '<input type="hidden" name="s" value="' . esc_attr($search_args['s']) . '" />';
1096
+ }
1097
 
1098
+ if (isset($_GET['ref']) ) {
1099
+ echo '<input type="hidden" name="show" value="' . esc_attr($_GET['ref']) . '" />';
1100
+ }
1101
 
1102
+ if (isset($_GET['show']) ) {
1103
+ echo '<input type="hidden" name="show" value="' . esc_attr($_GET['show']) . '" />';
1104
+ }
1105
 
1106
+ if (array_key_exists('order', $search_args) ) {
1107
+ echo '<input type="hidden" name="order" value="' . esc_attr($search_args['order']) . '" />';
1108
+ }
1109
 
1110
+ if (array_key_exists('paged', $search_args) ) {
1111
+ echo '<input type="hidden" name="paged" value="' . esc_attr($search_args['paged']) . '" />';
1112
+ }
1113
 
1114
+ $log->search();
1115
 
1116
+ ?>
1117
 
1118
+ <?php do_action('mycred_above_payment_log_table', $this); ?>
1119
 
1120
+ <div class="tablenav top">
1121
 
1122
+ <?php $log->table_nav('top'); ?>
1123
 
1124
+ </div>
1125
+ <table class="wp-list-table widefat fixed striped users mycred-table" cellspacing="0">
1126
+ <thead>
1127
+ <tr>
1128
+ <?php
1129
 
1130
+ foreach ( $log->headers as $col_id => $col_title ) {
1131
+ echo '<th scope="col" id="' . str_replace('column-', '', $col_id) . '" class="manage-column ' . $col_id . '">' . $col_title . '</th>';
1132
+ }
1133
 
1134
+ ?>
1135
+ </tr>
1136
+ </thead>
1137
+ <tfoot>
1138
+ <tr>
1139
+ <?php
1140
 
1141
+ foreach ( $log->headers as $col_id => $col_title ) {
1142
+ echo '<th scope="col" class="manage-column ' . $col_id . '">' . $col_title . '</th>';
1143
+ }
1144
 
1145
+ ?>
1146
+ </tr>
1147
+ </tfoot>
1148
+ <tbody id="the-list">
1149
+ <?php
1150
 
1151
+ // If we have results
1152
+ if ($log->have_entries() ) {
1153
 
1154
+ // Prep
1155
+ $date_format = get_option('date_format') . ' ' . get_option('time_format');
1156
+ $entry_data = '';
1157
+ $alt = 0;
1158
 
1159
+ // Loop results
1160
+ foreach ( $log->results as $log_entry ) {
1161
 
1162
+ // Highlight alternate rows
1163
+ $alt = $alt + 1;
1164
+ $class = '';
1165
+ $style = '';
1166
+ if ($alt % 2 == 0 ) { $class = ' alt';
1167
+ }
1168
 
1169
+ // Prep Sales data for use in columns
1170
+ $sales_data = $this->get_sales_data_from_log_data($log_entry->data);
1171
+ list ( $buyer_id, $payer_id, $amount, $cost, $currency, $token, $other ) = $sales_data;
1172
 
1173
+ // Default Currency
1174
+ if (empty($currency) ) {
1175
+ $currency = 'USD';
1176
+ }
1177
 
1178
+ $gateway_name = str_replace('buy_creds_with_', '', $log_entry->ref);
1179
 
1180
+ // Color rows based on if the transaction was made in Sandbox mode or using a gateway that no longer is used.
1181
+ if (! array_key_exists(str_replace('_', '-', $gateway_name), $installed) ) {
1182
+ $style = ' style="color:silver;"';
1183
 
1184
+ } elseif (! $this->is_active(str_replace('_', '-', $gateway_name)) ) {
1185
+ $style = ' style="color:gray;"';
1186
 
1187
+ } elseif (substr($log_entry->entry, 0, 4) == 'TEST' ) {
1188
+ $style = ' style="color:orange;"';
1189
+ }
1190
 
1191
+ echo '<tr class="myCRED-log-row' . $class . '" id="mycred-log-entry-' . $log_entry->id . '">';
1192
 
1193
+ // Run though columns
1194
+ foreach ( $log->headers as $column_id => $column_name ) {
1195
 
1196
+ echo '<td class="' . $column_id . '"' . $style . '>';
1197
 
1198
+ switch ( $column_id ) {
1199
 
1200
+ // Used gateway
1201
+ case 'column-gateway' :
1202
 
1203
+ $gateway = str_replace(array( '-', '_' ), ' ', $gateway_name);
1204
+ echo ucwords($gateway);
1205
 
1206
+ break;
1207
 
1208
+ // Username Column
1209
+ case 'column-username' :
1210
 
1211
+ $user = get_userdata($log_entry->user_id);
1212
+ if ($user === false ) {
1213
+ echo 'ID: ' . $log_entry->user_id;
1214
+ } else {
1215
+ echo $user->display_name . ' <em><small>(ID: ' . $log_entry->user_id . ')</small></em>';
1216
+ }
1217
 
1218
+ break;
1219
 
1220
+ // Date & Time Column
1221
+ case 'column-date' :
1222
 
1223
+ echo date($date_format, $log_entry->time);
1224
 
1225
+ break;
1226
 
1227
+ // Amount Column
1228
+ case 'column-amount' :
1229
 
1230
+ echo $mycred->format_creds($log_entry->creds);
1231
 
1232
+ break;
1233
 
1234
+ // Amount Paid
1235
+ case 'column-payed' :
1236
 
1237
+ $cost = 'n/a';
1238
+ $currency = '';
1239
+ $data = maybe_unserialize($log_entry->data);
1240
+ if (is_array($data) && array_key_exists('sales_data', $data) ) {
1241
 
1242
+ $sales_data = explode('|', $data['sales_data']);
1243
+ if (count($sales_data) >= 5 ) {
1244
+ $cost = $sales_data[3];
1245
+ $currency = $sales_data[4];
1246
+ }
1247
 
1248
+ }
1249
 
1250
+ if ($cost === 'n/a' ) {
1251
+ echo 'n/a';
1252
 
1253
+ } else {
1254
 
1255
+ $rendered_cost = apply_filters('mycred_buycred_display_cost', $cost . ' ' . $currency, $sales_data, $log_entry, $gateway_name);
1256
+ $rendered_cost = apply_filters('mycred_buycred_display_cost_' . $gateway_name, $rendered_cost, $sales_data, $log_entry);
1257
 
1258
+ echo $rendered_cost;
1259
 
1260
+ }
1261
 
1262
+ break;
1263
 
1264
+ // Transaction ID
1265
+ case 'column-tranid' :
1266
 
1267
+ $transaction_id = $log_entry->time . $log_entry->user_id;
1268
+ $saved_data = maybe_unserialize($log_entry->data);
1269
 
1270
+ if (isset($saved_data['txn_id']) ) {
1271
+ $transaction_id = $saved_data['txn_id'];
1272
 
1273
+ } elseif (isset($saved_data['transaction_id']) ) {
1274
+ $transaction_id = $saved_data['transaction_id'];
1275
+ }
1276
 
1277
+ echo $transaction_id;
1278
 
1279
+ break;
1280
 
1281
+ default :
1282
 
1283
+ do_action("mycred_payment_log_{$column_id}", $log_entry);
1284
+ do_action("mycred_payment_log_{$column_id}_{$type}", $log_entry);
1285
 
1286
+ break;
1287
 
1288
+ }
1289
 
1290
+ echo '</td>';
1291
 
1292
+ }
1293
 
1294
+ echo '</tr>';
1295
 
1296
+ }
1297
 
1298
+ }
1299
 
1300
+ // No log entry
1301
+ else {
1302
 
1303
+ echo '<tr><td colspan="' . count($log->headers) . '" class="no-entries">' . __('No purchases found', 'mycred') . '</td></tr>';
1304
 
1305
+ }
1306
 
1307
+ ?>
1308
+ </tbody>
1309
+ </table>
1310
+ <div class="tablenav bottom">
1311
 
1312
+ <?php $log->table_nav('bottom'); ?>
1313
 
1314
+ </div>
1315
 
1316
+ <?php do_action('mycred_below_payment_log_table', $this); ?>
1317
 
1318
+ </form>
1319
  </div>
1320
+ <?php
1321
 
1322
+ }
1323
 
1324
+ /**
1325
+ * Get Sales Data from Log Data
1326
+ *
1327
+ * @since 1.4
1328
+ * @version 1.0.1
1329
+ */
1330
+ public function get_sales_data_from_log_data( $log_data = '' )
1331
+ {
1332
 
1333
+ $defaults = array( '', '', '', '', '', '', '' );
1334
+ $log_data = maybe_unserialize($log_data);
1335
 
1336
+ $found_data = array();
1337
+ if (is_array($log_data) && array_key_exists('sales_data', $log_data) ) {
1338
+ if (is_array($log_data['sales_data']) ) {
1339
+ $found_data = $log_data['sales_data'];
1340
+ } else {
1341
+ $found_data = explode('|', $log_data['sales_data']);
1342
+ }
1343
+ }
1344
+ elseif (! empty($log_data) && ! is_array($log_data) ) {
1345
+ $try = explode('|', $log_data);
1346
+ if (count($try == 7) ) {
1347
+ $found_data = $log_data;
1348
+ }
1349
+ }
1350
 
1351
+ return wp_parse_args($found_data, $defaults);
1352
 
1353
+ }
1354
 
1355
+ /**
1356
+ * User Rates Admin Screen
1357
+ *
1358
+ * @since 1.5
1359
+ * @version 1.0
1360
+ */
1361
+ public function exchange_rates_user_screen( $user )
1362
+ {
1363
 
1364
+ // Make sure buyCRED is setup
1365
+ if (! isset($this->core->buy_creds['types']) || empty($this->core->buy_creds['types']) ) { return;
1366
+ }
1367
 
1368
+ // Only visible to admins
1369
+ if (! mycred_is_admin() ) { return;
1370
+ }
1371
 
1372
+ $mycred_types = mycred_get_types(true);
1373
+ $point_types_for_sale = $this->core->buy_creds['types'];
1374
+ $installed = $this->get();
1375
+ $available_options = array();
1376
 
1377
+ foreach ( $installed as $gateway_id => $prefs ) {
1378
 
1379
+ // Gateway is not active or settings have not yet been saved
1380
+ if (! $this->is_active($gateway_id) || ! array_key_exists($gateway_id, $this->gateway_prefs) || ! $prefs['custom_rate'] ) { continue;
1381
+ }
1382
 
1383
+ $gateway_prefs = $this->gateway_prefs[ $gateway_id ];
1384
 
1385
+ // Need a currency
1386
+ if (array_key_exists('currency', $gateway_prefs) && $gateway_prefs['currency'] == '' ) { continue;
1387
+ }
1388
 
1389
+ if (! array_key_exists('currency', $gateway_prefs) ) {
1390
+ $gateway_prefs['currency'] = 'USD';
1391
+ }
1392
 
1393
+ $setup = array( 'name' => $prefs['title'], 'currency' => $gateway_prefs['currency'], 'types' => array() );
1394
 
1395
+ foreach ( $mycred_types as $point_type_key => $label ) {
1396
 
1397
+ $row = array( 'name' => $label, 'enabled' => false, 'excluded' => true, 'default' => 0, 'override' => false, 'custom' => '', 'before' => '' );
1398
 
1399
+ if (in_array($point_type_key, $point_types_for_sale) && array_key_exists($point_type_key, $gateway_prefs['exchange']) ) {
1400
 
1401
+ $row['enabled'] = true;
1402
 
1403
+ $mycred = mycred($point_type_key);
1404
 
1405
+ if (! $mycred->exclude_user($user->ID) ) {
1406
 
1407
+ $row['excluded'] = false;
1408
+ $row['default'] = $gateway_prefs['exchange'][ $point_type_key ];
1409
 
1410
+ $row['before'] = $mycred->format_creds(1) . ' = ';
1411
 
1412
+ $saved_overrides = (array) mycred_get_user_meta($user->ID, 'mycred_buycred_rates_' . $point_type_key, '', true);
1413
 
1414
+ if (! empty($saved_overrides) && array_key_exists($gateway_id, $saved_overrides) ) {
1415
 
1416
+ $row['override'] = true;
1417
+ $row['custom'] = $saved_overrides[ $gateway_id ];
1418
 
1419
+ }
1420
 
1421
+ }
1422
 
1423
+ }
1424
 
1425
+ $setup['types'][ $point_type_key ] = $row;
1426
 
1427
+ }
1428
 
1429
+ $available_options[ $gateway_id ] = $setup;
1430
 
1431
+ }
1432
 
1433
+ if (empty($available_options) ) { return;
1434
+ }
1435
 
1436
+ ?>
1437
+ <p class="mycred-p"><?php _e('Users exchange rate when buying points.', 'mycred'); ?></p>
1438
  <table class="form-table mycred-inline-table">
1439
+ <?php
1440
+
1441
+ foreach ( $available_options as $gateway_id => $setup ) :
1442
+
1443
+ ?>
1444
+ <tr>
1445
+ <th scope="row"><?php echo esc_attr($setup['name']); ?></th>
1446
+ <td>
1447
+ <fieldset id="mycred-buycred-list" class="buycred-list">
1448
+ <legend class="screen-reader-text"><span><?php _e('buyCRED Exchange Rates', 'mycred'); ?></span></legend>
1449
+ <?php
1450
+
1451
+ foreach ( $setup['types'] as $type_id => $data ) {
1452
+
1453
+ // This point type is not for sale
1454
+ if (! $data['enabled'] ) {
1455
+
1456
+ ?>
1457
+ <div class="mycred-wrapper buycred-wrapper disabled-option color-option">
1458
+ <div><?php printf(_x('Buying %s', 'Points Name', 'mycred'), $data['name']); ?></div>
1459
+ <div class="balance-row">
1460
+ <div class="balance-view"><?php _e('Disabled', 'mycred'); ?></div>
1461
+ <div class="balance-desc"><em><?php _e('This point type is not for sale.', 'mycred'); ?></em></div>
1462
+ </div>
1463
+ </div>
1464
+ <?php
1465
+
1466
+ }
1467
+
1468
+ // This user is excluded from this point type
1469
+ elseif ($data['excluded'] ) {
1470
+
1471
+ ?>
1472
+ <div class="mycred-wrapper buycred-wrapper excluded-option color-option">
1473
+ <div><?php printf(_x('Buying %s', 'Buying Points', 'mycred'), $data['name']); ?></div>
1474
+ <div class="balance-row">
1475
+ <div class="balance-view"><?php _e('Excluded', 'mycred'); ?></div>
1476
+ <div class="balance-desc"><em><?php printf(_x('User can not buy %s', 'Points Name', 'mycred'), $data['name']); ?></em></div>
1477
+ </div>
1478
+ </div>
1479
+ <?php
1480
+
1481
+ }
1482
+
1483
+ // Eligeble user
1484
+ else {
1485
+
1486
+ ?>
1487
+ <div class="mycred-wrapper buycred-wrapper color-option selected">
1488
+ <div><?php printf(_x('Buying %s', 'Buying Points', 'mycred'), $data['name']); ?></div>
1489
+ <div class="balance-row">
1490
+ <div class="balance-view"><?php echo $data['before']; ?><input type="text" name="mycred_adjust_users_buyrates[<?php echo $type_id; ?>][<?php echo $gateway_id; ?>]" placeholder="<?php echo $data['default']; ?>" value="<?php if ($data['override'] ) { echo esc_attr($data['custom']);
1491
+ } ?>" class="short" size="8" /><?php echo ' ' . $setup['currency']; ?></div>
1492
+ <div class="balance-desc"><em><?php _e('Leave empty to use the default rate.', 'mycred'); ?></em></div>
1493
+ </div>
1494
+ </div>
1495
+ <?php
1496
+
1497
+ }
1498
+
1499
+ }
1500
+
1501
+ ?>
1502
+ </fieldset>
1503
+ </td>
1504
+ </tr>
1505
+ <?php
1506
+
1507
+ endforeach;
1508
+
1509
+ ?>
1510
  </table>
1511
  <hr />
1512
  <script type="text/javascript">
1513
  jQuery(function($) {
1514
 
1515
+ $( '.buycred-wrapper label input.trigger-buycred' ).change(function(){
1516
 
1517
+ if ( $(this).val().length > 0 )
1518
+ $(this).parent().parent().parent().addClass( 'selected' );
1519
 
1520
+ else
1521
+ $(this).parent().parent().parent().removeClass( 'selected' );
1522
 
1523
+ });
1524
 
1525
  });
1526
  </script>
1527
+ <?php
1528
 
1529
+ }
1530
 
1531
+ /**
1532
+ * Save Override
1533
+ *
1534
+ * @since 1.5
1535
+ * @version 1.2
1536
+ */
1537
+ public function save_manual_exchange_rates( $user_id )
1538
+ {
1539
 
1540
+ if (! mycred_is_admin() ) { return;
1541
+ }
1542
 
1543
+ if (isset($_POST['mycred_adjust_users_buyrates']) && is_array($_POST['mycred_adjust_users_buyrates']) && ! empty($_POST['mycred_adjust_users_buyrates']) ) {
1544
 
1545
+ foreach ( $_POST['mycred_adjust_users_buyrates'] as $ctype => $gateway ) {
1546
 
1547
+ $ctype = sanitize_key($ctype);
1548
+ $mycred = mycred($ctype);
1549
 
1550
+ if (! $mycred->exclude_user($user_id) ) {
1551
 
1552
+ $new_rates = array();
1553
+ foreach ( (array) $gateway as $gateway_id => $rate ) {
1554
 
1555
+ if ($rate == '' ) { continue;
1556
+ }
1557
 
1558
+ if ($rate != 1 && in_array(substr($rate, 0, 1), array( '.', ',' )) ) {
1559
+ $rate = (float) '0' . $rate;
1560
+ }
1561
 
1562
+ $new_rates[ $gateway_id ] = $rate;
1563
 
1564
+ }
1565
 
1566
+ if (! empty($new_rates) ) {
1567
+ mycred_update_user_meta($user_id, 'mycred_buycred_rates_' . $ctype, '', $new_rates);
1568
+ } else {
1569
+ mycred_delete_user_meta($user_id, 'mycred_buycred_rates_' . $ctype);
1570
+ }
1571
 
1572
+ }
1573
 
1574
+ }
1575
 
1576
+ }
1577
 
1578
+ }
1579
 
1580
+ /**
1581
+ * Hide Comments
1582
+ *
1583
+ * @since 1.8.9
1584
+ * @version 1.0
1585
+ */
1586
+ public function hide_buycred_transactions( $query )
1587
+ {
1588
 
1589
+ $query->query_vars['type__not_in'] = 'buycred';
1590
+
1591
+ }
1592
 
1593
+ }
1594
  endif;
1595
 
1596
  /**
1597
  * Load buyCRED Module
1598
+ *
1599
+ * @since 1.7
1600
  * @version 1.0
1601
  */
1602
+ if (! function_exists('mycred_load_buycred_core_addon') ) :
1603
+ function mycred_load_buycred_core_addon( $modules, $point_types )
1604
+ {
1605
 
1606
+ $modules['solo']['buycred'] = new myCRED_buyCRED_Module();
1607
+ $modules['solo']['buycred']->load();
1608
 
1609
+ return $modules;
1610
 
1611
+ }
1612
  endif;
1613
+ add_filter('mycred_load_modules', 'mycred_load_buycred_core_addon', 30, 2);
addons/buy-creds/modules/buycred-module-pending.php CHANGED
@@ -1,786 +1,863 @@
1
  <?php
2
- if ( ! defined( 'MYCRED_PURCHASE' ) ) exit;
 
3
 
4
  /**
5
  * buyCRED_Pending_Payments class
6
- * @since 1.7
 
7
  * @version 1.2
8
  */
9
- if ( ! class_exists( 'buyCRED_Pending_Payments' ) ) :
10
- class buyCRED_Pending_Payments extends myCRED_Module {
 
11
 
12
- /**
13
- * Construct
14
- */
15
- function __construct( $type = MYCRED_DEFAULT_TYPE_KEY ) {
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
16
 
17
- parent::__construct( 'buyCRED_Pending_Payments', array(
18
- 'module_name' => 'pending_payments',
19
- 'option_id' => '',
20
- 'defaults' => array(),
21
- 'screen_id' => '',
22
- 'accordion' => false,
23
- 'add_to_core' => false,
24
- 'menu_pos' => 75
25
- ), $type );
26
 
27
- }
28
 
29
- /**
30
- * Load
31
- * @version 1.0.1
32
- */
33
- public function load() {
 
 
 
34
 
35
- add_action( 'mycred_init', array( $this, 'module_init' ), $this->menu_pos );
36
- add_action( 'mycred_admin_init', array( $this, 'module_admin_init' ), $this->menu_pos );
37
 
38
- }
39
 
40
- /**
41
- * Module Init
42
- * @since 1.7
43
- * @version 1.2
44
- */
45
- public function module_init() {
46
 
47
- $this->register_pending_payments();
 
48
 
49
- add_shortcode( MYCRED_SLUG . '_buy_pending', 'mycred_render_pending_purchases' );
50
 
51
- add_action( 'mycred_pre_process_buycred', array( $this, 'intercept_cancellations' ) );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
52
 
53
- add_action( 'mycred_add_menu', array( $this, 'add_to_menu' ), $this->menu_pos );
54
- add_action( 'transition_post_status', array( $this, 'pending_transitions' ), 10, 3 );
55
 
56
- }
57
 
58
- /**
59
- * Intercept Cancellations
60
- * @since 1.7
61
- * @version 1.1
62
- */
63
- public function intercept_cancellations() {
64
 
65
- global $buycred_instance;
66
 
67
- // Intercept payment cancellations
68
- if ( isset( $_REQUEST['buycred-cancel'] ) && isset( $_REQUEST['_token'] ) && wp_verify_nonce( $_REQUEST['_token'], 'buycred-cancel-pending-payment' ) ) {
69
 
70
- // Get pending payment object
71
- $pending_payment_id = sanitize_text_field( $_REQUEST['buycred-cancel'] );
72
-
73
- // Move item to trash
74
- buycred_trash_pending_payment( $pending_payment_id );
75
-
76
- // Redirect
77
- wp_safe_redirect( remove_query_arg( array( 'buycred-cancel', '_token' ) ) );
78
- exit;
79
-
80
- }
81
-
82
- }
83
-
84
- /**
85
- * Pending Transitions
86
- * @since 1.8
87
- * @version 1.0
88
- */
89
- public function pending_transitions( $new_status, $old_status, $post ) {
90
-
91
- if ( $post->post_status == MYCRED_BUY_KEY ) {
92
-
93
- mycred_delete_user_meta( $post->post_author, 'buycred_pending_payments' );
94
-
95
- }
96
-
97
- }
98
-
99
- /**
100
- * Module Admin Init
101
- * @since 1.7
102
- * @version 1.1
103
- */
104
- public function module_admin_init() {
105
-
106
- add_filter( 'parent_file', array( $this, 'parent_file' ) );
107
- add_filter( 'submenu_file', array( $this, 'subparent_file' ), 10, 2 );
108
-
109
- add_action( 'admin_notices', array( $this, 'admin_notices' ) );
110
- add_filter( 'post_row_actions', array( $this, 'adjust_row_actions' ), 10, 2 );
111
- add_action( 'admin_head-post.php', array( $this, 'edit_pending_payment_style' ) );
112
- add_action( 'admin_head-edit.php', array( $this, 'pending_payments_style' ) );
113
- add_filter( 'post_updated_messages', array( $this, 'post_updated_messages' ) );
114
-
115
- add_filter( 'manage_' . MYCRED_BUY_KEY . '_posts_columns', array( $this, 'adjust_column_headers' ) );
116
- add_action( 'manage_' . MYCRED_BUY_KEY . '_posts_custom_column', array( $this, 'adjust_column_content' ), 10, 2 );
117
- add_filter( 'bulk_actions-edit-' . MYCRED_BUY_KEY, array( $this, 'bulk_actions' ) );
118
- add_action( 'save_post_' . MYCRED_BUY_KEY, array( $this, 'save_pending_payment' ), 10, 2 );
119
-
120
- // Intercept payment completions
121
- if ( isset( $_GET['credit'] ) && isset( $_GET['token'] ) && wp_verify_nonce( $_GET['token'], 'buycred-payout-pending' ) ) {
122
-
123
- $pending_id = absint( $_GET['credit'] );
124
-
125
- if ( $this->core->user_is_point_editor() ) {
126
-
127
- $url = remove_query_arg( array( 'credit', 'token' ) );
128
-
129
- if ( buycred_complete_pending_payment( $pending_id ) ) {
130
- $url = add_query_arg( array( 'credited' => 1 ), $url );
131
- }
132
- else {
133
- $url = add_query_arg( array( 'credited' => 0 ), $url );
134
- }
135
-
136
- wp_safe_redirect( $url );
137
- exit;
138
-
139
- }
140
-
141
- }
142
-
143
- }
144
-
145
- /**
146
- * Register Pending Payments
147
- * @since 1.5
148
- * @version 1.1
149
- */
150
- protected function register_pending_payments() {
151
-
152
- $labels = array(
153
- 'name' => _x( 'buyCred Pending Payments', 'Post Type General Name', 'mycred' ),
154
- 'singular_name' => _x( 'buyCred Pending Payment', 'Post Type Singular Name', 'mycred' ),
155
- 'menu_name' => __( 'buyCred Pending Payments', 'mycred' ),
156
- 'parent_item_colon' => '',
157
- 'all_items' => __( 'buyCred Pending Payments', 'mycred' ),
158
- 'view_item' => '',
159
- 'add_new_item' => '',
160
- 'add_new' => '',
161
- 'edit_item' => __( 'Edit buyCred Pending Payment', 'mycred' ),
162
- 'update_item' => '',
163
- 'search_items' => '',
164
- 'not_found' => __( 'Not found in Trash', 'mycred' ),
165
- 'not_found_in_trash' => __( 'Not found in Trash', 'mycred' ),
166
- );
167
- $args = array(
168
- 'labels' => $labels,
169
- 'supports' => array( 'title', 'comments' ),
170
- 'hierarchical' => false,
171
- 'public' => false,
172
- 'show_ui' => true,
173
- 'show_in_menu' => false,
174
- 'show_in_nav_menus' => false,
175
- 'show_in_admin_bar' => false,
176
- 'can_export' => true,
177
- 'has_archive' => false,
178
- 'exclude_from_search' => true,
179
- 'publicly_queryable' => false,
180
- 'register_meta_box_cb' => array( $this, 'add_metaboxes' )
181
- );
182
- register_post_type( MYCRED_BUY_KEY, apply_filters( 'mycred_setup_pending_payment', $args ) );
183
-
184
- }
185
-
186
- /**
187
- * Adjust Post Updated Messages
188
- * @since 1.7
189
- * @version 1.1
190
- */
191
- public function post_updated_messages( $messages ) {
192
-
193
- $messages[ MYCRED_BUY_KEY ] = array(
194
- 0 => '',
195
- 1 => __( 'Payment Updated.', 'mycred' ),
196
- 2 => __( 'Payment Updated.', 'mycred' ),
197
- 3 => __( 'Payment Updated.', 'mycred' ),
198
- 4 => __( 'Payment Updated.', 'mycred' ),
199
- 5 => __( 'Payment Updated.', 'mycred' ),
200
- 6 => __( 'Payment Updated.', 'mycred' ),
201
- 7 => __( 'Payment Updated.', 'mycred' ),
202
- 8 => __( 'Payment Updated.', 'mycred' ),
203
- 9 => __( 'Payment Updated.', 'mycred' ),
204
- 10 => ''
205
- );
206
-
207
- return $messages;
208
-
209
- }
210
-
211
- /**
212
- * Add Comment
213
- * @since 1.7
214
- * @version 1.0
215
- */
216
- public function add_comment( $post_id, $event = '', $time = NULL ) {
217
-
218
- return buycred_add_pending_comment( $post_id, $event, $time );
219
-
220
- }
221
-
222
- /**
223
- * Admin Notices
224
- * @since 1.7
225
- * @version 1.1
226
- */
227
- public function admin_notices() {
228
-
229
- if ( isset( $_GET['post_type'] ) && $_GET['post_type'] == MYCRED_BUY_KEY && isset( $_GET['credited'] ) ) {
230
-
231
- if ( $_GET['credited'] == 1 )
232
- echo '<div id="message" class="updated notice is-dismissible"><p>' . __( 'Pending payment successfully credited to account.', 'mycred' ) . '</p><button type="button" class="notice-dismiss"></button></div>';
233
-
234
- elseif ( $_GET['credited'] == 0 )
235
- echo '<div id="message" class="error notice is-dismissible"><p>' . __( 'Failed to credit the pending payment to account.', 'mycred' ) . '</p><button type="button" class="notice-dismiss"></button></div>';
236
-
237
- }
238
-
239
- }
240
-
241
- /**
242
- * Add Admin Menu Item
243
- * @since 1.7
244
- * @version 1.1
245
- */
246
- public function add_to_menu() {
247
-
248
- mycred_add_main_submenu(
249
- __( 'Pending Payments', 'mycred' ),
250
- __( 'Pending Payments', 'mycred' ),
251
- $this->core->get_point_editor_capability(),
252
- 'edit.php?post_type=' . MYCRED_BUY_KEY
253
- );
254
-
255
- }
256
-
257
- /**
258
- * Parent File
259
- * @since 1.7
260
- * @version 1.0.1
261
- */
262
- public function parent_file( $parent = '' ) {
263
-
264
- global $pagenow;
265
-
266
- if ( isset( $_GET['post'] ) && mycred_get_post_type( $_GET['post'] ) == MYCRED_BUY_KEY && isset( $_GET['action'] ) && $_GET['action'] == 'edit' )
267
- return MYCRED_MAIN_SLUG;
268
-
269
- return $parent;
270
 
271
- }
 
 
 
 
 
 
 
 
 
 
272
 
273
- /**
274
- * Sub Parent File
275
- * @since 1.7.8
276
- * @version 1.0
277
- */
278
- public function subparent_file( $subparent = '', $parent = '' ) {
279
 
280
- global $pagenow;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
281
 
282
- if ( ( $pagenow == 'edit.php' || $pagenow == 'post-new.php' ) && isset( $_GET['post_type'] ) && $_GET['post_type'] == MYCRED_BUY_KEY ) {
 
 
283
 
284
- return 'edit.php?post_type=' . MYCRED_BUY_KEY;
285
-
286
- }
287
 
288
- elseif ( $pagenow == 'post.php' && isset( $_GET['post'] ) && mycred_get_post_type( $_GET['post'] ) == MYCRED_BUY_KEY ) {
 
289
 
290
- return 'edit.php?post_type=' . MYCRED_BUY_KEY;
 
291
 
292
- }
293
 
294
- return $subparent;
 
295
 
296
- }
 
297
 
298
- /**
299
- * Pending Payment Column Headers
300
- * @since 1.5
301
- * @version 1.0
302
- */
303
- public function adjust_column_headers( $columns ) {
304
 
305
- return array(
306
- 'cb' => $columns['cb'],
307
- 'comments' => $columns['comments'],
308
- 'title' => __( 'Transaction ID', 'mycred' ),
309
- 'date' => $columns['date'],
310
- 'author' => __( 'Buyer', 'mycred' ),
311
- 'amount' => __( 'Amount', 'mycred' ),
312
- 'cost' => __( 'Cost', 'mycred' ),
313
- 'gateway' => __( 'Gateway', 'mycred' ),
314
- 'ctype' => __( 'Type', 'mycred' )
315
- );
316
 
317
- }
318
 
319
- /**
320
- * Pending Payment Column Content
321
- * @since 1.5
322
- * @version 1.0
323
- */
324
- public function adjust_column_content( $column_name, $post_id ) {
325
 
326
- global $mycred_modules;
 
327
 
328
- switch ( $column_name ) {
329
- case 'author' :
330
 
331
- $from = (int) mycred_get_post_meta( $post_id, 'from', true );
332
- $user = get_userdata( $from );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
333
 
334
- if ( isset( $user->display_name ) )
335
- echo '<a href="' . add_query_arg( array( 'user_id' => $user->ID ), admin_url( 'user-edit.php' ) ) . '">' . $user->display_name . '</a>';
336
- else
337
- echo 'ID: ' . $from;
338
 
339
- break;
340
- case 'amount';
341
 
342
- $type = mycred_get_post_meta( $post_id, 'point_type', true );
343
- $amount = mycred_get_post_meta( $post_id, 'amount', true );
344
- $mycred = mycred( $type );
 
 
 
 
 
 
 
 
 
345
 
346
- echo $mycred->format_creds( $amount );
347
 
348
- break;
349
- case 'cost';
350
 
351
- $cost = mycred_get_post_meta( $post_id, 'cost', true );
352
- $currency = mycred_get_post_meta( $post_id, 'currency', true );
353
 
354
- echo $cost . ' ' . $currency;
 
 
 
 
 
 
 
355
 
356
- break;
357
- case 'gateway';
358
 
359
- $gateway = mycred_get_post_meta( $post_id, 'gateway', true );
360
- $installed = $mycred_modules['solo']['buycred']->get();
361
 
362
- if ( isset( $installed[ $gateway ] ) )
363
- echo $installed[ $gateway ]['title'];
364
- else
365
- echo $gateway;
366
 
367
- break;
368
- case 'ctype';
369
 
370
- $type = mycred_get_post_meta( $post_id, 'point_type', true );
371
-
372
- if ( isset( $this->point_types[ $type ] ) )
373
- echo $this->point_types[ $type ];
374
- else
375
- echo $type;
376
-
377
- break;
378
- }
379
-
380
- }
381
-
382
- /**
383
- * Adjust Bulk Actions
384
- * @since 1.5
385
- * @version 1.0
386
- */
387
- public function bulk_actions( $actions ) {
388
-
389
- unset( $actions['edit'] );
390
- return $actions;
391
-
392
- }
393
-
394
- /**
395
- * Pending Payment Row Actions
396
- * @since 1.5
397
- * @version 1.2
398
- */
399
- public function adjust_row_actions( $actions, $post ) {
400
-
401
- if ( $post->post_type == MYCRED_BUY_KEY && $post->post_status != 'trash' ) {
402
-
403
- unset( $actions['inline hide-if-no-js'] );
404
-
405
- // Add option to "Pay Out" now
406
- if ( $this->core->user_is_point_editor() )
407
- $actions['credit'] = '<a href="' . esc_url( add_query_arg( array(
408
- 'post_type' => $post->post_type,
409
- 'credit' => $post->ID,
410
- 'token' => wp_create_nonce( 'buycred-payout-pending' )
411
- ), admin_url( 'edit.php' ) ) ) . '">' . __( 'Pay Out', 'mycred' ) . '</a>';
412
-
413
- }
414
-
415
- return $actions;
416
-
417
- }
418
-
419
- /**
420
- * Edit Pending Payment Style
421
- * @since 1.7
422
- * @version 1.0.1
423
- */
424
- public function edit_pending_payment_style() {
425
-
426
- global $post_type;
427
-
428
- if ( $post_type !== MYCRED_BUY_KEY ) return;
429
-
430
- wp_enqueue_style( 'mycred-bootstrap-grid' );
431
- wp_enqueue_style( 'mycred-forms' );
432
-
433
- add_filter( 'postbox_classes_buycred_payment_buycred-pending-payment', array( $this, 'metabox_classes' ) );
434
- add_filter( 'postbox_classes_buycred_payment_buycred-pending-comments', array( $this, 'metabox_classes' ) );
435
-
436
- ?>
437
  <script type="text/javascript">
438
  jQuery(function($){
439
 
440
- $(document).ready(function(){
441
- $( 'h1 .page-title-action, .wrap .page-title-action' ).remove();
442
- $( '#titlewrap #title' ).attr( 'readonly', 'readonly' ).addClass( 'readonly' );
443
- });
444
 
445
  });
446
  </script>
447
- <?php
448
 
449
- }
450
 
451
- /**
452
- * Pending Payment Style
453
- * @since 1.7
454
- * @version 1.0.1
455
- */
456
- public function pending_payments_style() {
 
 
457
 
458
- global $post_type;
459
 
460
- if ( $post_type !== MYCRED_BUY_KEY ) return;
 
461
 
462
- ?>
463
  <script type="text/javascript">
464
  jQuery(function($){
465
 
466
- $(document).ready(function(){
467
- $( 'h1 .page-title-action, .wrap .page-title-action' ).remove();
468
- });
469
 
470
  });
471
  </script>
472
- <?php
473
-
474
- }
475
-
476
- /**
477
- * Add Metaboxes
478
- * @since 1.7
479
- * @version 1.1
480
- */
481
- public function add_metaboxes() {
482
-
483
- add_meta_box(
484
- 'buycred-pending-payment',
485
- __( 'Pending Payment', 'mycred' ),
486
- array( $this, 'metabox_pending_payment' ),
487
- MYCRED_BUY_KEY,
488
- 'normal',
489
- 'high'
490
- );
491
-
492
- if ( MYCRED_BUY_PENDING_COMMENTS )
493
- add_meta_box(
494
- 'buycred-pending-comments',
495
- __( 'History', 'mycred' ),
496
- array( $this, 'metabox_pending_comments' ),
497
- MYCRED_BUY_KEY,
498
- 'normal',
499
- 'default'
500
- );
501
-
502
- remove_meta_box( 'commentstatusdiv', MYCRED_BUY_KEY, 'normal' );
503
- remove_meta_box( 'commentsdiv', MYCRED_BUY_KEY, 'normal' );
504
-
505
- remove_meta_box( 'submitdiv', MYCRED_BUY_KEY, 'side' );
506
- add_meta_box(
507
- 'submitdiv',
508
- __( 'Actions', 'mycred' ),
509
- array( $this, 'metabox_pending_actions' ),
510
- MYCRED_BUY_KEY,
511
- 'side',
512
- 'high'
513
- );
514
-
515
- }
516
-
517
- /**
518
- * Metabox: Pending Actions
519
- * @since 1.7
520
- * @version 1.0
521
- */
522
- public function metabox_pending_actions( $post ) {
523
-
524
- $payout_url = add_query_arg( array(
525
- 'post_type' => $post->post_type,
526
- 'credit' => $post->ID,
527
- 'token' => wp_create_nonce( 'buycred-payout-pending' )
528
- ), admin_url( 'edit.php' ) );
529
-
530
- $delete_url = get_delete_post_link( $post->ID );
531
-
532
- ?>
 
 
 
 
 
 
 
533
  <div class="submitbox mycred-metabox" id="submitpost">
534
- <div id="minor-publishing">
535
- <div style="display:none;">
536
- <?php submit_button( __( 'Save', 'mycred' ), 'button', 'save' ); ?>
537
- </div>
538
 
539
- <div id="minor-publishing-actions">
540
 
541
- <div><a href="<?php echo $payout_url; ?>" class="button button-secondary button-block"><?php _e( 'Pay Out', 'mycred' ); ?></a></div>
542
- <div><a href="<?php echo $delete_url; ?>" class="button button-secondary button-block"><?php _e( 'Trash', 'mycred' ); ?></a></div>
543
 
544
- </div>
545
 
546
- <div class="clear"></div>
547
- </div>
548
- <div id="major-publishing-actions">
549
 
550
- <div id="publishing-action">
551
- <span class="spinner"></span>
552
 
553
- <input type="submit" id="publish" class="button button-primary primary button-large" value="<?php _e( 'Save Changes', 'mycred' ); ?>" />
554
 
555
- </div>
556
- <div class="clear"></div>
557
- </div>
558
  </div>
559
- <?php
560
-
561
- }
562
-
563
- /**
564
- * Metabox: Pending Payment
565
- * @since 1.7
566
- * @version 1.0.1
567
- */
568
- public function metabox_pending_payment( $post ) {
569
-
570
- global $mycred_modules;
571
-
572
- $pending_payment = buycred_get_pending_payment( $post->ID );
573
- $buyer_name = 'ID: ' . $pending_payment->buyer_id;
574
-
575
- $buyer_object = get_userdata( $pending_payment->buyer_id );
576
- if ( isset( $buyer_object->ID ) ) {
577
- $buyer_name = $buyer_object->display_name;
578
- if ( $buyer_name == '' )
579
- $buyer_name = $buyer_object->user_email;
580
- }
581
-
582
- if ( $pending_payment->recipient_id == $pending_payment->buyer_id )
583
- $recipient_name = $buyer_name;
584
-
585
- else {
586
- $recipient_name = 'ID: ' . $pending_payment->recipient_id;
587
- $recipient_object = get_userdata( $pending_payment->recipient_id );
588
- if ( isset( $recipient_object->ID ) ) {
589
- $recipient_name = $recipient_object->display_name;
590
- if ( $recipient_name == '' )
591
- $recipient_name = $recipient_object->user_email;
592
- }
593
- }
594
-
595
- if ( $pending_payment->point_type == $this->core->cred_id )
596
- $mycred = $this->core;
597
-
598
- else
599
- $mycred = mycred( $pending_payment->point_type );
600
-
601
- ?>
 
 
 
 
 
602
  <div class="form">
603
- <div class="row">
604
- <div class="col-md-6">
605
- <div class="form-group">
606
- <label><?php _e( 'Payer', 'mycred' ); ?></label>
607
- <p class="form-control-static"><?php echo esc_attr( $buyer_name ); ?></p>
608
- </div>
609
- </div>
610
- <div class="col-md-6">
611
- <div class="form-group">
612
- <label><?php _e( 'Recipient', 'mycred' ); ?></label>
613
- <p class="form-control-static"><?php echo esc_attr( $recipient_name ); ?></p>
614
- </div>
615
- </div>
616
- </div>
617
- <div class="row">
618
- <div class="col-md-3 col-sm-6">
619
- <div class="form-group">
620
- <label for="buycred-pending-payment-point_type"><?php _e( 'Point Type', 'mycred' ); ?></label>
621
- <?php
622
-
623
- // Just one point type is set for sale. No need for a dropdown menu
624
- if ( count( $this->core->buy_creds['types'] ) == 1 ) {
625
-
626
- ?>
627
- <p class="form-control-static"><?php echo strip_tags( $mycred->plural() ); ?></p>
628
- <input type="hidden" name="buycred_pending_payment[point_type]" value="<?php echo $pending_payment->point_type; ?>" />
629
- <?php
630
-
631
- }
632
-
633
- // Multiple point types are set for sale. Show a dropdown menu
634
- else {
635
-
636
- ?>
637
- <select name="buycred_pending_payment[point_type]" id="buycred-pending-payment-point_type" class="form-control">
638
- <?php
639
-
640
- foreach ( $this->core->buy_creds['types'] as $point_type ) {
641
-
642
- echo '<option value="' . $point_type . '"';
643
- if ( $pending_payment->point_type == $point_type ) echo ' selected="selected"';
644
- echo '>' . mycred_get_point_type_name( $point_type, false ) . '</option>';
645
-
646
- }
647
-
648
- ?>
649
- </select>
650
- <?php
651
-
652
- }
653
-
654
- ?>
655
- </div>
656
- </div>
657
- <div class="col-md-3 col-sm-6">
658
- <div class="form-group">
659
- <label for="buycred-pending-payment-gateway"><?php _e( 'Gateway', 'mycred' ); ?></label>
660
- <select name="buycred_pending_payment[gateway]" id="buycred-pending-payment-gateway" class="form-control">
661
- <?php
662
-
663
- foreach ( $mycred_modules['solo']['buycred']->get() as $gateway_id => $info ) {
664
-
665
- echo '<option value="' . $gateway_id . '"';
666
- if ( $pending_payment->gateway_id == $gateway_id ) echo ' selected="selected"';
667
- if ( ! $mycred_modules['solo']['buycred']->is_active( $gateway_id ) ) echo ' disabled="disabled"';
668
- echo '>' . $info['title'] . '</option>';
669
-
670
- }
671
-
672
- ?>
673
- </select>
674
- </div>
675
- </div>
676
- <div class="col-md-2 col-sm-6">
677
- <div class="form-group">
678
- <label for="buycred-pending-payment-amount"><?php _e( 'Amount', 'mycred' ); ?></label>
679
- <input type="text" name="buycred_pending_payment[amount]" id="buycred-pending-payment-amount" class="form-control" value="<?php echo $mycred->number( $pending_payment->amount ); ?>" />
680
- </div>
681
- </div>
682
- <div class="col-md-2 col-sm-6">
683
- <div class="form-group">
684
- <label for="buycred-pending-payment-cost"><?php _e( 'Cost', 'mycred' ); ?></label>
685
- <input type="text" name="buycred_pending_payment[cost]" id="buycred-pending-payment-cost" class="form-control" value="<?php echo esc_attr( $pending_payment->cost ); ?>" />
686
- </div>
687
- </div>
688
- <div class="col-md-2 col-sm-6">
689
- <div class="form-group">
690
- <label for="buycred-pending-payment-currency"><?php _e( 'Currency', 'mycred' ); ?></label>
691
- <input type="text" name="buycred_pending_payment[currency]" id="buycred-pending-payment-currency" class="form-control" value="<?php echo esc_attr( $pending_payment->currency ); ?>" />
692
- </div>
693
- </div>
694
- </div>
 
 
 
695
  </div>
696
- <?php
697
 
698
- }
699
 
700
- /**
701
- * Metabox: Pending Payment Comments
702
- * @since 1.7
703
- * @version 1.0
704
- */
705
- public function metabox_pending_comments( $post ) {
 
 
706
 
707
- $comments = get_comments( array( 'post_id' => $post->ID ) );
708
 
709
- echo '<ul class="history">';
710
 
711
- if ( empty( $comments ) ) {
712
 
713
- $c = new StdClass();
714
- $c->comment_date = $post->post_date;
715
- $c->comment_content = __( 'Pending request created.', 'mycred' );
716
 
717
- $event = $this->add_comment( $post->ID, $c->comment_content, $c->comment_date );
718
- if ( $event === false )
719
- $c->comment_content .= ' Unsaved';
720
 
721
- else
722
- $c->comment_content .= ' ' . $event;
 
723
 
724
- $comments[] = $c;
725
 
726
- }
727
 
728
- foreach ( $comments as $comment ) {
729
 
730
- echo '<li><time>' . $comment->comment_date . '</time><p>' . $comment->comment_content . '</p></li>';
731
 
732
- }
733
 
734
- echo '</ul>';
735
 
736
- }
737
 
738
- /**
739
- * Save Pending Payment
740
- * @since 1.7
741
- * @version 1.0
742
- */
743
- public function save_pending_payment( $post_id, $post ) {
 
 
744
 
745
- if ( ! $this->core->user_is_point_editor() || ! isset( $_POST['buycred_pending_payment'] ) ) return;
 
746
 
747
- $pending_payment = $_POST['buycred_pending_payment'];
748
- $changed = false;
749
 
750
- foreach ( $pending_payment as $meta_key => $meta_value ) {
751
 
752
- $new_value = sanitize_text_field( $meta_value );
753
- $old_value = mycred_get_post_meta( $post_id, $meta_key, true );
754
- if ( $new_value != $old_value ) {
755
- mycred_update_post_meta( $post_id, $meta_key, $new_value );
756
- $changed = true;
757
- }
758
 
759
- }
760
 
761
- if ( $changed ) {
762
- $user = wp_get_current_user();
763
- $this->add_comment( $post_id, sprintf( __( 'Pending payment updated by %s', 'mycred' ), $user->user_login ) );
764
- }
765
 
766
- }
767
 
768
- }
769
  endif;
770
 
771
  /**
772
  * Load buyCRED Pending Module
773
- * @since 1.7
 
774
  * @version 1.0
775
  */
776
- if ( ! function_exists( 'mycred_load_buycred_pending_addon' ) ) :
777
- function mycred_load_buycred_pending_addon( $modules, $point_types ) {
 
778
 
779
- $modules['solo']['buycred-pending'] = new buyCRED_Pending_Payments();
780
- $modules['solo']['buycred-pending']->load();
781
 
782
- return $modules;
783
 
784
- }
785
  endif;
786
- add_filter( 'mycred_load_modules', 'mycred_load_buycred_pending_addon', 40, 2 );
1
  <?php
2
+ if (! defined('MYCRED_PURCHASE') ) { exit;
3
+ }
4
 
5
  /**
6
  * buyCRED_Pending_Payments class
7
+ *
8
+ * @since 1.7
9
  * @version 1.2
10
  */
11
+ if (! class_exists('buyCRED_Pending_Payments') ) :
12
+ class buyCRED_Pending_Payments extends myCRED_Module
13
+ {
14
 
15
+ /**
16
+ * Construct
17
+ */
18
+ function __construct( $type = MYCRED_DEFAULT_TYPE_KEY )
19
+ {
20
+
21
+ parent::__construct(
22
+ 'buyCRED_Pending_Payments', array(
23
+ 'module_name' => 'pending_payments',
24
+ 'option_id' => '',
25
+ 'defaults' => array(),
26
+ 'screen_id' => '',
27
+ 'accordion' => false,
28
+ 'add_to_core' => false,
29
+ 'menu_pos' => 75
30
+ ), $type
31
+ );
32
+
33
+ }
34
+
35
+ /**
36
+ * Load
37
+ *
38
+ * @version 1.0.1
39
+ */
40
+ public function load()
41
+ {
42
 
43
+ add_action('mycred_init', array( $this, 'module_init' ), $this->menu_pos);
44
+ add_action('mycred_admin_init', array( $this, 'module_admin_init' ), $this->menu_pos);
 
 
 
 
 
 
 
45
 
46
+ }
47
 
48
+ /**
49
+ * Module Init
50
+ *
51
+ * @since 1.7
52
+ * @version 1.2
53
+ */
54
+ public function module_init()
55
+ {
56
 
57
+ $this->register_pending_payments();
 
58
 
59
+ add_shortcode(MYCRED_SLUG . '_buy_pending', 'mycred_render_pending_purchases');
60
 
61
+ add_action('mycred_pre_process_buycred', array( $this, 'intercept_cancellations' ));
 
 
 
 
 
62
 
63
+ add_action('mycred_add_menu', array( $this, 'add_to_menu' ), $this->menu_pos);
64
+ add_action('transition_post_status', array( $this, 'pending_transitions' ), 10, 3);
65
 
66
+ }
67
 
68
+ /**
69
+ * Intercept Cancellations
70
+ *
71
+ * @since 1.7
72
+ * @version 1.1
73
+ */
74
+ public function intercept_cancellations()
75
+ {
76
+
77
+ global $buycred_instance;
78
+
79
+ // Intercept payment cancellations
80
+ if (isset($_REQUEST['buycred-cancel']) && isset($_REQUEST['_token']) && wp_verify_nonce($_REQUEST['_token'], 'buycred-cancel-pending-payment') ) {
81
+
82
+ // Get pending payment object
83
+ $pending_payment_id = sanitize_text_field($_REQUEST['buycred-cancel']);
84
+
85
+ // Move item to trash
86
+ buycred_trash_pending_payment($pending_payment_id);
87
+
88
+ // Redirect
89
+ wp_safe_redirect(remove_query_arg(array( 'buycred-cancel', '_token' )));
90
+ exit;
91
+
92
+ }
93
+
94
+ }
95
+
96
+ /**
97
+ * Pending Transitions
98
+ *
99
+ * @since 1.8
100
+ * @version 1.0
101
+ */
102
+ public function pending_transitions( $new_status, $old_status, $post )
103
+ {
104
+
105
+ if ($post->post_status == MYCRED_BUY_KEY ) {
106
+
107
+ mycred_delete_user_meta($post->post_author, 'buycred_pending_payments');
108
+
109
+ }
110
+
111
+ }
112
+
113
+ /**
114
+ * Module Admin Init
115
+ *
116
+ * @since 1.7
117
+ * @version 1.1
118
+ */
119
+ public function module_admin_init()
120
+ {
121
+
122
+ add_filter('parent_file', array( $this, 'parent_file' ));
123
+ add_filter('submenu_file', array( $this, 'subparent_file' ), 10, 2);
124
+
125
+ add_action('admin_notices', array( $this, 'admin_notices' ));
126
+ add_filter('post_row_actions', array( $this, 'adjust_row_actions' ), 10, 2);
127
+ add_action('admin_head-post.php', array( $this, 'edit_pending_payment_style' ));
128
+ add_action('admin_head-edit.php', array( $this, 'pending_payments_style' ));
129
+ add_filter('post_updated_messages', array( $this, 'post_updated_messages' ));
130
+
131
+ add_filter('manage_' . MYCRED_BUY_KEY . '_posts_columns', array( $this, 'adjust_column_headers' ));
132
+ add_action('manage_' . MYCRED_BUY_KEY . '_posts_custom_column', array( $this, 'adjust_column_content' ), 10, 2);
133
+ add_filter('bulk_actions-edit-' . MYCRED_BUY_KEY, array( $this, 'bulk_actions' ));
134
+ add_action('save_post_' . MYCRED_BUY_KEY, array( $this, 'save_pending_payment' ), 10, 2);
135
+
136
+ // Intercept payment completions
137
+ if (isset($_GET['credit']) && isset($_GET['token']) && wp_verify_nonce($_GET['token'], 'buycred-payout-pending') ) {
138
+
139
+ $pending_id = absint($_GET['credit']);
140
+
141
+ if ($this->core->user_is_point_editor() ) {
142
+
143
+ $url = remove_query_arg(array( 'credit', 'token' ));
144
+
145
+ if (buycred_complete_pending_payment($pending_id) ) {
146
+ $url = add_query_arg(array( 'credited' => 1 ), $url);
147
+ }
148
+ else {
149
+ $url = add_query_arg(array( 'credited' => 0 ), $url);
150
+ }
151
+
152
+ wp_safe_redirect($url);
153
+ exit;
154
+
155
+ }
156
+
157
+ }
158
+
159
+ }
160
+
161
+ /**
162
+ * Register Pending Payments
163
+ *
164
+ * @since 1.5
165
+ * @version 1.1
166
+ */
167
+ protected function register_pending_payments()
168
+ {
169
+
170
+ $labels = array(
171
+ 'name' => _x('buyCred Pending Payments', 'Post Type General Name', 'mycred'),
172
+ 'singular_name' => _x('buyCred Pending Payment', 'Post Type Singular Name', 'mycred'),
173
+ 'menu_name' => __('buyCred Pending Payments', 'mycred'),
174
+ 'parent_item_colon' => '',
175
+ 'all_items' => __('buyCred Pending Payments', 'mycred'),
176
+ 'view_item' => '',
177
+ 'add_new_item' => '',
178
+ 'add_new' => '',
179
+ 'edit_item' => __('Edit buyCred Pending Payment', 'mycred'),
180
+ 'update_item' => '',
181
+ 'search_items' => '',
182
+ 'not_found' => __('Not found in Trash', 'mycred'),
183
+ 'not_found_in_trash' => __('Not found in Trash', 'mycred'),
184
+ );
185
+ $args = array(
186
+ 'labels' => $labels,
187
+ 'supports' => array( 'title', 'comments' ),
188
+ 'hierarchical' => false,
189
+ 'public' => false,
190
+ 'show_ui' => true,
191
+ 'show_in_menu' => false,
192
+ 'show_in_nav_menus' => false,
193
+ 'show_in_admin_bar' => false,
194
+ 'can_export' => true,
195
+ 'has_archive' => false,
196
+ 'exclude_from_search' => true,
197
+ 'publicly_queryable' => false,
198
+ 'register_meta_box_cb' => array( $this, 'add_metaboxes' )
199
+ );
200
+ register_post_type(MYCRED_BUY_KEY, apply_filters('mycred_setup_pending_payment', $args));
201
+
202
+ }
203
+
204
+ /**
205
+ * Adjust Post Updated Messages
206
+ *
207
+ * @since 1.7
208
+ * @version 1.1
209
+ */
210
+ public function post_updated_messages( $messages )
211
+ {
212
+
213
+ $messages[ MYCRED_BUY_KEY ] = array(
214
+ 0 => '',
215
+ 1 => __('Payment Updated.', 'mycred'),
216
+ 2 => __('Payment Updated.', 'mycred'),
217
+ 3 => __('Payment Updated.', 'mycred'),
218
+ 4 => __('Payment Updated.', 'mycred'),
219
+ 5 => __('Payment Updated.', 'mycred'),
220
+ 6 => __('Payment Updated.', 'mycred'),
221
+ 7 => __('Payment Updated.', 'mycred'),
222
+ 8 => __('Payment Updated.', 'mycred'),
223
+ 9 => __('Payment Updated.', 'mycred'),
224
+ 10 => ''
225
+ );
226
+
227
+ return $messages;
228
+
229
+ }
230
+
231
+ /**
232
+ * Add Comment
233
+ *
234
+ * @since 1.7
235
+ * @version 1.0
236
+ */
237
+ public function add_comment( $post_id, $event = '', $time = null )
238
+ {
239
+
240
+ return buycred_add_pending_comment($post_id, $event, $time);
241
+
242
+ }
243
+
244
+ /**
245
+ * Admin Notices
246
+ *
247
+ * @since 1.7
248
+ * @version 1.1
249
+ */
250
+ public function admin_notices()
251
+ {
252
+
253
+ if (isset($_GET['post_type']) && $_GET['post_type'] == MYCRED_BUY_KEY && isset($_GET['credited']) ) {
254
+
255
+ if ($_GET['credited'] == 1 ) {
256
+ echo '<div id="message" class="updated notice is-dismissible"><p>' . __('Pending payment successfully credited to account.', 'mycred') . '</p><button type="button" class="notice-dismiss"></button></div>';
257
+
258
+ } elseif ($_GET['credited'] == 0 ) {
259
+ echo '<div id="message" class="error notice is-dismissible"><p>' . __('Failed to credit the pending payment to account.', 'mycred') . '</p><button type="button" class="notice-dismiss"></button></div>';
260
+ }
261
+
262
+ }
263
+
264
+ }
265
+
266
+ /**
267
+ * Add Admin Menu Item
268
+ *
269
+ * @since 1.7
270
+ * @version 1.1
271
+ */
272
+ public function add_to_menu()
273
+ {
274
+
275
+ mycred_add_main_submenu(
276
+ __('Pending Payments', 'mycred'),
277
+ __('Pending Payments', 'mycred'),
278
+ $this->core->get_point_editor_capability(),
279
+ 'edit.php?post_type=' . MYCRED_BUY_KEY
280
+ );
281
+
282
+ }
283
+
284
+ /**
285
+ * Parent File
286
+ *
287
+ * @since 1.7
288
+ * @version 1.0.1
289
+ */
290
+ public function parent_file( $parent = '' )
291
+ {
292
+
293
+ global $pagenow;
294
+
295
+ if (isset($_GET['post']) && mycred_get_post_type($_GET['post']) == MYCRED_BUY_KEY && isset($_GET['action']) && $_GET['action'] == 'edit' ) {
296
+ return MYCRED_MAIN_SLUG;
297
+ }
298
+
299
+ return $parent;
300
+
301
+ }
302
+
303
+ /**
304
+ * Sub Parent File
305
+ *
306
+ * @since 1.7.8
307
+ * @version 1.0
308
+ */
309
+ public function subparent_file( $subparent = '', $parent = '' )
310
+ {
311
+
312
+ global $pagenow;
313
+
314
+ if (( $pagenow == 'edit.php' || $pagenow == 'post-new.php' ) && isset($_GET['post_type']) && $_GET['post_type'] == MYCRED_BUY_KEY ) {
315
+
316
+ return 'edit.php?post_type=' . MYCRED_BUY_KEY;
317
+
318
+ }
319
 
320
+ elseif ($pagenow == 'post.php' && isset($_GET['post']) && mycred_get_post_type($_GET['post']) == MYCRED_BUY_KEY ) {
 
321
 
322
+ return 'edit.php?post_type=' . MYCRED_BUY_KEY;
323
 
324
+ }
 
 
 
 
 
325
 
326
+ return $subparent;
327
 
328
+ }
 
329
 
330
+ /**
331
+ * Pending Payment Column Headers
332
+ *
333
+ * @since 1.5
334
+ * @version 1.0
335
+ */
336
+ public function adjust_column_headers( $columns )
337
+ {
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
338
 
339
+ return array(
340
+ 'cb' => $columns['cb'],
341
+ 'comments' => $columns['comments'],
342
+ 'title' => __('Transaction ID', 'mycred'),
343
+ 'date' => $columns['date'],
344
+ 'author' => __('Buyer', 'mycred'),
345
+ 'amount' => __('Amount', 'mycred'),
346
+ 'cost' => __('Cost', 'mycred'),
347
+ 'gateway' => __('Gateway', 'mycred'),
348
+ 'ctype' => __('Type', 'mycred')
349
+ );
350
 
351
+ }
 
 
 
 
 
352
 
353
+ /**
354
+ * Pending Payment Column Content
355
+ *
356
+ * @since 1.5
357
+ * @version 1.0
358
+ */
359
+ public function adjust_column_content( $column_name, $post_id )
360
+ {
361
+
362
+ global $mycred_modules;
363
+
364
+ switch ( $column_name ) {
365
+ case 'author' :
366
+
367
+ $from = (int) mycred_get_post_meta($post_id, 'from', true);
368
+ $user = get_userdata($from);
369
+
370
+ if (isset($user->display_name) ) {
371
+ echo '<a href="' . add_query_arg(array( 'user_id' => $user->ID ), admin_url('user-edit.php')) . '">' . $user->display_name . '</a>';
372
+ } else {
373
+ echo 'ID: ' . $from;
374
+ }
375
+
376
+ break;
377
+ case 'amount';
378
 
379
+ $type = mycred_get_post_meta($post_id, 'point_type', true);
380
+ $amount = mycred_get_post_meta($post_id, 'amount', true);
381
+ $mycred = mycred($type);
382
 
383
+ echo $mycred->format_creds($amount);
 
 
384
 
385
+ break;
386
+ case 'cost';
387
 
388
+ $cost = mycred_get_post_meta($post_id, 'cost', true);
389
+ $currency = mycred_get_post_meta($post_id, 'currency', true);
390
 
391
+ echo $cost . ' ' . $currency;
392
 
393
+ break;
394
+ case 'gateway';
395
 
396
+ $gateway = mycred_get_post_meta($post_id, 'gateway', true);
397
+ $installed = $mycred_modules['solo']['buycred']->get();
398
 
399
+ if (isset($installed[ $gateway ]) ) {
400
+ echo $installed[ $gateway ]['title'];
401
+ } else {
402
+ echo $gateway;
403
+ }
 
404
 
405
+ break;
406
+ case 'ctype';
 
 
 
 
 
 
 
 
 
407
 
408
+ $type = mycred_get_post_meta($post_id, 'point_type', true);
409
 
410
+ if (isset($this->point_types[ $type ]) ) {
411
+ echo $this->point_types[ $type ];
412
+ } else {
413
+ echo $type;
414
+ }
 
415
 
416
+ break;
417
+ }
418
 
419
+ }
 
420
 
421
+ /**
422
+ * Adjust Bulk Actions
423
+ *
424
+ * @since 1.5
425
+ * @version 1.0
426
+ */
427
+ public function bulk_actions( $actions )
428
+ {
429
+
430
+ unset($actions['edit']);
431
+ return $actions;
432
+
433
+ }
434
+
435
+ /**
436
+ * Pending Payment Row Actions
437
+ *
438
+ * @since 1.5
439
+ * @version 1.2
440
+ */
441
+ public function adjust_row_actions( $actions, $post )
442
+ {
443
 
444
+ if ($post->post_type == MYCRED_BUY_KEY && $post->post_status != 'trash' ) {
 
 
 
445
 
446
+ unset($actions['inline hide-if-no-js']);
 
447
 
448
+ // Add option to "Pay Out" now
449
+ if ($this->core->user_is_point_editor() ) {
450
+ $actions['credit'] = '<a href="' . esc_url(
451
+ add_query_arg(
452
+ array(
453
+ 'post_type' => $post->post_type,
454
+ 'credit' => $post->ID,
455
+ 'token' => wp_create_nonce('buycred-payout-pending')
456
+ ), admin_url('edit.php')
457
+ )
458
+ ) . '">' . __('Pay Out', 'mycred') . '</a>';
459
+ }
460
 
461
+ }
462
 
463
+ return $actions;
 
464
 
465
+ }
 
466
 
467
+ /**
468
+ * Edit Pending Payment Style
469
+ *
470
+ * @since 1.7
471
+ * @version 1.0.1
472
+ */
473
+ public function edit_pending_payment_style()
474
+ {
475
 
476
+ global $post_type;
 
477
 
478
+ if ($post_type !== MYCRED_BUY_KEY ) { return;
479
+ }
480
 
481
+ wp_enqueue_style('mycred-bootstrap-grid');
482
+ wp_enqueue_style('mycred-forms');
 
 
483
 
484
+ add_filter('postbox_classes_buycred_payment_buycred-pending-payment', array( $this, 'metabox_classes' ));
485
+ add_filter('postbox_classes_buycred_payment_buycred-pending-comments', array( $this, 'metabox_classes' ));
486
 
487
+ ?>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
488
  <script type="text/javascript">
489
  jQuery(function($){
490
 
491
+ $(document).ready(function(){
492
+ $( 'h1 .page-title-action, .wrap .page-title-action' ).remove();
493
+ $( '#titlewrap #title' ).attr( 'readonly', 'readonly' ).addClass( 'readonly' );
494
+ });
495
 
496
  });
497
  </script>
498
+ <?php
499
 
500
+ }
501
 
502
+ /**
503
+ * Pending Payment Style
504
+ *
505
+ * @since 1.7
506
+ * @version 1.0.1
507
+ */
508
+ public function pending_payments_style()
509
+ {
510
 
511
+ global $post_type;
512
 
513
+ if ($post_type !== MYCRED_BUY_KEY ) { return;
514
+ }
515
 
516
+ ?>
517
  <script type="text/javascript">
518
  jQuery(function($){
519
 
520
+ $(document).ready(function(){
521
+ $( 'h1 .page-title-action, .wrap .page-title-action' ).remove();
522
+ });
523
 
524
  });
525
  </script>
526
+ <?php
527
+
528
+ }
529
+
530
+ /**
531
+ * Add Metaboxes
532
+ *
533
+ * @since 1.7
534
+ * @version 1.1
535
+ */
536
+ public function add_metaboxes()
537
+ {
538
+
539
+ add_meta_box(
540
+ 'buycred-pending-payment',
541
+ __('Pending Payment', 'mycred'),
542
+ array( $this, 'metabox_pending_payment' ),
543
+ MYCRED_BUY_KEY,
544
+ 'normal',
545
+ 'high'
546
+ );
547
+
548
+ if (MYCRED_BUY_PENDING_COMMENTS ) {
549
+ add_meta_box(
550
+ 'buycred-pending-comments',
551
+ __('History', 'mycred'),
552
+ array( $this, 'metabox_pending_comments' ),
553
+ MYCRED_BUY_KEY,
554
+ 'normal',
555
+ 'default'
556
+ );
557
+ }
558
+
559
+ remove_meta_box('commentstatusdiv', MYCRED_BUY_KEY, 'normal');
560
+ remove_meta_box('commentsdiv', MYCRED_BUY_KEY, 'normal');
561
+
562
+ remove_meta_box('submitdiv', MYCRED_BUY_KEY, 'side');
563
+ add_meta_box(
564
+ 'submitdiv',
565
+ __('Actions', 'mycred'),
566
+ array( $this, 'metabox_pending_actions' ),
567
+ MYCRED_BUY_KEY,
568
+ 'side',
569
+ 'high'
570
+ );
571
+
572
+ }
573
+
574
+ /**
575
+ * Metabox: Pending Actions
576
+ *
577
+ * @since 1.7
578
+ * @version 1.0
579
+ */
580
+ public function metabox_pending_actions( $post )
581
+ {
582
+
583
+ $payout_url = add_query_arg(
584
+ array(
585
+ 'post_type' => $post->post_type,
586
+ 'credit' => $post->ID,
587
+ 'token' => wp_create_nonce('buycred-payout-pending')
588
+ ), admin_url('edit.php')
589
+ );
590
+
591
+ $delete_url = get_delete_post_link($post->ID);
592
+
593
+ ?>
594
  <div class="submitbox mycred-metabox" id="submitpost">
595
+ <div id="minor-publishing">
596
+ <div style="display:none;">
597
+ <?php submit_button(__('Save', 'mycred'), 'button', 'save'); ?>
598
+ </div>
599
 
600
+ <div id="minor-publishing-actions">
601
 
602
+ <div><a href="<?php echo $payout_url; ?>" class="button button-secondary button-block"><?php _e('Pay Out', 'mycred'); ?></a></div>
603
+ <div><a href="<?php echo $delete_url; ?>" class="button button-secondary button-block"><?php _e('Trash', 'mycred'); ?></a></div>
604
 
605
+ </div>
606
 
607
+ <div class="clear"></div>
608
+ </div>
609
+ <div id="major-publishing-actions">
610
 
611
+ <div id="publishing-action">
612
+ <span class="spinner"></span>
613
 
614
+ <input type="submit" id="publish" class="button button-primary primary button-large" value="<?php _e('Save Changes', 'mycred'); ?>" />
615
 
616
+ </div>
617
+ <div class="clear"></div>
618
+ </div>
619
  </div>
620
+ <?php
621
+
622
+ }
623
+
624
+ /**
625
+ * Metabox: Pending Payment
626
+ *
627
+ * @since 1.7
628
+ * @version 1.0.1
629
+ */
630
+ public function metabox_pending_payment( $post )
631
+ {
632
+
633
+ global $mycred_modules;
634
+
635
+ $pending_payment = buycred_get_pending_payment($post->ID);
636
+ $buyer_name = 'ID: ' . $pending_payment->buyer_id;
637
+
638
+ $buyer_object = get_userdata($pending_payment->buyer_id);
639
+ if (isset($buyer_object->ID) ) {
640
+ $buyer_name = $buyer_object->display_name;
641
+ if ($buyer_name == '' ) {
642
+ $buyer_name = $buyer_object->user_email;
643
+ }
644
+ }
645
+
646
+ if ($pending_payment->recipient_id == $pending_payment->buyer_id ) {
647
+ $recipient_name = $buyer_name;
648
+
649
+ } else {
650
+ $recipient_name = 'ID: ' . $pending_payment->recipient_id;
651
+ $recipient_object = get_userdata($pending_payment->recipient_id);
652
+ if (isset($recipient_object->ID) ) {
653
+ $recipient_name = $recipient_object->display_name;
654
+ if ($recipient_name == '' ) {
655
+ $recipient_name = $recipient_object->user_email;
656
+ }
657
+ }
658
+ }
659
+
660
+ if ($pending_payment->point_type == $this->core->cred_id ) {
661
+ $mycred = $this->core;
662
+
663
+ } else {
664
+ $mycred = mycred($pending_payment->point_type);
665
+ }
666
+
667
+ ?>
668
  <div class="form">
669
+ <div class="row">
670
+ <div class="col-md-6">
671
+ <div class="form-group">
672
+ <label><?php _e('Payer', 'mycred'); ?></label>
673
+ <p class="form-control-static"><?php echo esc_attr($buyer_name); ?></p>
674
+ </div>
675
+ </div>
676
+ <div class="col-md-6">
677
+ <div class="form-group">
678
+ <label><?php _e('Recipient', 'mycred'); ?></label>
679
+ <p class="form-control-static"><?php echo esc_attr($recipient_name); ?></p>
680
+ </div>
681
+ </div>
682
+ </div>
683
+ <div class="row">
684
+ <div class="col-md-3 col-sm-6">
685
+ <div class="form-group">
686
+ <label for="buycred-pending-payment-point_type"><?php _e('Point Type', 'mycred'); ?></label>
687
+ <?php
688
+
689
+ // Just one point type is set for sale. No need for a dropdown menu
690
+ if (count($this->core->buy_creds['types']) == 1 ) {
691
+
692
+ ?>
693
+ <p class="form-control-static"><?php echo strip_tags($mycred->plural()); ?></p>
694
+ <input type="hidden" name="buycred_pending_payment[point_type]" value="<?php echo $pending_payment->point_type; ?>" />
695
+ <?php
696
+
697
+ }
698
+
699
+ // Multiple point types are set for sale. Show a dropdown menu
700
+ else {
701
+
702
+ ?>
703
+ <select name="buycred_pending_payment[point_type]" id="buycred-pending-payment-point_type" class="form-control">
704
+ <?php
705
+
706
+ foreach ( $this->core->buy_creds['types'] as $point_type ) {
707
+
708
+ echo '<option value="' . $point_type . '"';
709
+ if ($pending_payment->point_type == $point_type ) { echo ' selected="selected"';
710
+ }
711
+ echo '>' . mycred_get_point_type_name($point_type, false) . '</option>';
712
+
713
+ }
714
+
715
+ ?>
716
+ </select>
717
+ <?php
718
+
719
+ }
720
+
721
+ ?>
722
+ </div>
723
+ </div>
724
+ <div class="col-md-3 col-sm-6">
725
+ <div class="form-group">
726
+ <label for="buycred-pending-payment-gateway"><?php _e('Gateway', 'mycred'); ?></label>
727
+ <select name="buycred_pending_payment[gateway]" id="buycred-pending-payment-gateway" class="form-control">
728
+ <?php
729
+
730
+ foreach ( $mycred_modules['solo']['buycred']->get() as $gateway_id => $info ) {
731
+
732
+ echo '<option value="' . $gateway_id . '"';
733
+ if ($pending_payment->gateway_id == $gateway_id ) { echo ' selected="selected"';
734
+ }
735
+ if (! $mycred_modules['solo']['buycred']->is_active($gateway_id) ) { echo ' disabled="disabled"';
736
+ }
737
+ echo '>' . $info['title'] . '</option>';
738
+
739
+ }
740
+
741
+ ?>
742
+ </select>
743
+ </div>
744
+ </div>
745
+ <div class="col-md-2 col-sm-6">
746
+ <div class="form-group">
747
+ <label for="buycred-pending-payment-amount"><?php _e('Amount', 'mycred'); ?></label>
748
+ <input type="text" name="buycred_pending_payment[amount]" id="buycred-pending-payment-amount" class="form-control" value="<?php echo $mycred->number($pending_payment->amount); ?>" />
749
+ </div>
750
+ </div>
751
+ <div class="col-md-2 col-sm-6">
752
+ <div class="form-group">
753
+ <label for="buycred-pending-payment-cost"><?php _e('Cost', 'mycred'); ?></label>
754
+ <input type="text" name="buycred_pending_payment[cost]" id="buycred-pending-payment-cost" class="form-control" value="<?php echo esc_attr($pending_payment->cost); ?>" />
755
+ </div>
756
+ </div>
757
+ <div class="col-md-2 col-sm-6">
758
+ <div class="form-group">
759
+ <label for="buycred-pending-payment-currency"><?php _e('Currency', 'mycred'); ?></label>
760
+ <input type="text" name="buycred_pending_payment[currency]" id="buycred-pending-payment-currency" class="form-control" value="<?php echo esc_attr($pending_payment->currency); ?>" />
761
+ </div>
762
+ </div>
763
+ </div>
764
  </div>
765
+ <?php
766
 
767
+ }
768
 
769
+ /**
770
+ * Metabox: Pending Payment Comments
771
+ *
772
+ * @since 1.7
773
+ * @version 1.0
774
+ */
775
+ public function metabox_pending_comments( $post )
776
+ {
777
 
778
+ $comments = get_comments(array( 'post_id' => $post->ID ));
779
 
780
+ echo '<ul class="history">';
781
 
782
+ if (empty($comments) ) {
783
 
784
+ $c = new StdClass();
785
+ $c->comment_date = $post->post_date;
786
+ $c->comment_content = __('Pending request created.', 'mycred');
787
 
788
+ $event = $this->add_comment($post->ID, $c->comment_content, $c->comment_date);
789
+ if ($event === false ) {
790
+ $c->comment_content .= ' Unsaved';
791
 
792
+ } else {
793
+ $c->comment_content .= ' ' . $event;
794
+ }
795
 
796
+ $comments[] = $c;
797
 
798
+ }
799
 
800
+ foreach ( $comments as $comment ) {
801
 
802
+ echo '<li><time>' . $comment->comment_date . '</time><p>' . $comment->comment_content . '</p></li>';
803
 
804
+ }
805
 
806
+ echo '</ul>';
807
 
808
+ }
809
 
810
+ /**
811
+ * Save Pending Payment
812
+ *
813
+ * @since 1.7
814
+ * @version 1.0
815
+ */
816
+ public function save_pending_payment( $post_id, $post )
817
+ {
818
 
819
+ if (! $this->core->user_is_point_editor() || ! isset($_POST['buycred_pending_payment']) ) { return;
820
+ }
821
 
822
+ $pending_payment = $_POST['buycred_pending_payment'];
823
+ $changed = false;
824
 
825
+ foreach ( $pending_payment as $meta_key => $meta_value ) {
826
 
827
+ $new_value = sanitize_text_field($meta_value);
828
+ $old_value = mycred_get_post_meta($post_id, $meta_key, true);
829
+ if ($new_value != $old_value ) {
830
+ mycred_update_post_meta($post_id, $meta_key, $new_value);
831
+ $changed = true;
832
+ }
833
 
834
+ }
835
 
836
+ if ($changed ) {
837
+ $user = wp_get_current_user();
838
+ $this->add_comment($post_id, sprintf(__('Pending payment updated by %s', 'mycred'), $user->user_login));
839
+ }
840
 
841
+ }
842
 
843
+ }
844
  endif;
845
 
846
  /**
847
  * Load buyCRED Pending Module
848
+ *
849
+ * @since 1.7
850
  * @version 1.0
851
  */
852
+ if (! function_exists('mycred_load_buycred_pending_addon') ) :
853
+ function mycred_load_buycred_pending_addon( $modules, $point_types )
854
+ {
855
 
856
+ $modules['solo']['buycred-pending'] = new buyCRED_Pending_Payments();
857
+ $modules['solo']['buycred-pending']->load();
858
 
859
+ return $modules;
860
 
861
+ }
862
  endif;
863
+ add_filter('mycred_load_modules', 'mycred_load_buycred_pending_addon', 40, 2);
addons/buy-creds/modules/index.php CHANGED
@@ -1,3 +1,3 @@
1
  <?php
2
  // Silence is golden.
3
- ?>
1
  <?php
2
  // Silence is golden.
3
+ ?>
addons/buy-creds/myCRED-addon-buy-creds.php CHANGED
@@ -4,22 +4,25 @@
4
  * Addon URI: http://codex.mycred.me/chapter-iii/buycred/
5
  * Version: 1.6
6
  */
7
- if ( ! defined( 'myCRED_VERSION' ) ) exit;
8
-
9
- define( 'MYCRED_PURCHASE', __FILE__ );
10
- define( 'MYCRED_PURCHASE_VERSION', '1.6' );
11
- define( 'MYCRED_PURCHASE_DIR', myCRED_ADDONS_DIR . 'buy-creds/' );
12
- define( 'MYCRED_BUYCRED_ABSTRACT_DIR', MYCRED_PURCHASE_DIR . 'abstracts/' );
13
- define( 'MYCRED_BUYCRED_GATEWAYS_DIR', MYCRED_PURCHASE_DIR . 'gateways/' );
14
- define( 'MYCRED_BUYCRED_MODULES_DIR', MYCRED_PURCHASE_DIR . 'modules/' );
15
- define( 'MYCRED_BUYCRED_INCLUDES_DIR', MYCRED_PURCHASE_DIR . 'includes/' );
16
- define( 'MYCRED_BUYCRED_TEMPLATES_DIR', MYCRED_PURCHASE_DIR . 'templates/' );
17
-
18
- if ( ! defined( 'MYCRED_BUY_PENDING_COMMENTS' ) )
19
- define( 'MYCRED_BUY_PENDING_COMMENTS', true );
20
-
21
- if ( ! defined( 'MYCRED_BUY_KEY' ) )
22
- define( 'MYCRED_BUY_KEY', 'buycred_payment' );
 
 
 
23
 
24
  /**
25
  * Load Dependencies
@@ -32,7 +35,8 @@ require_once MYCRED_BUYCRED_INCLUDES_DIR . 'buycred-reward.php';
32
 
33
  /**
34
  * Load Built-in Gateways
35
- * @since 1.4
 
36
  * @version 1.0
37
  */
38
  require_once MYCRED_BUYCRED_GATEWAYS_DIR . 'paypal-standard.php';
@@ -41,11 +45,12 @@ require_once MYCRED_BUYCRED_GATEWAYS_DIR . 'netbilling.php';
41
  require_once MYCRED_BUYCRED_GATEWAYS_DIR . 'skrill.php';
42
  require_once MYCRED_BUYCRED_GATEWAYS_DIR . 'bank-transfer.php';
43
 
44
- do_action( 'mycred_buycred_load_gateways' );
45
 
46
  /**
47
  * Load Modules
48
- * @since 1.7
 
49
  * @version 1.0
50
  */
51
  require_once MYCRED_BUYCRED_MODULES_DIR . 'buycred-module-core.php';
4
  * Addon URI: http://codex.mycred.me/chapter-iii/buycred/
5
  * Version: 1.6
6
  */
7
+ if (! defined('myCRED_VERSION') ) { exit;
8
+ }
9
+
10
+ define('MYCRED_PURCHASE', __FILE__);
11
+ define('MYCRED_PURCHASE_VERSION', '1.6');
12
+ define('MYCRED_PURCHASE_DIR', myCRED_ADDONS_DIR . 'buy-creds/');
13
+ define('MYCRED_BUYCRED_ABSTRACT_DIR', MYCRED_PURCHASE_DIR . 'abstracts/');
14
+ define('MYCRED_BUYCRED_GATEWAYS_DIR', MYCRED_PURCHASE_DIR . 'gateways/');
15
+ define('MYCRED_BUYCRED_MODULES_DIR', MYCRED_PURCHASE_DIR . 'modules/');
16
+ define('MYCRED_BUYCRED_INCLUDES_DIR', MYCRED_PURCHASE_DIR . 'includes/');
17
+ define('MYCRED_BUYCRED_TEMPLATES_DIR', MYCRED_PURCHASE_DIR . 'templates/');
18
+
19
+ if (! defined('MYCRED_BUY_PENDING_COMMENTS') ) {
20
+ define('MYCRED_BUY_PENDING_COMMENTS', true);
21
+ }
22
+
23
+ if (! defined('MYCRED_BUY_KEY') ) {
24
+ define('MYCRED_BUY_KEY', 'buycred_payment');
25
+ }
26
 
27
  /**
28
  * Load Dependencies
35
 
36
  /**
37
  * Load Built-in Gateways
38
+ *
39
+ * @since 1.4
40
  * @version 1.0
41
  */
42
  require_once MYCRED_BUYCRED_GATEWAYS_DIR . 'paypal-standard.php';
45
  require_once MYCRED_BUYCRED_GATEWAYS_DIR . 'skrill.php';
46
  require_once MYCRED_BUYCRED_GATEWAYS_DIR . 'bank-transfer.php';
47
 
48
+ do_action('mycred_buycred_load_gateways');
49
 
50
  /**
51
  * Load Modules
52
+ *
53
+ * @since 1.7
54
  * @version 1.0
55
  */
56
  require_once MYCRED_BUYCRED_MODULES_DIR . 'buycred-module-core.php';
addons/buy-creds/templates/buycred-checkout.php CHANGED
@@ -1,25 +1,25 @@
1
  <?php get_header(); ?>
2
 
3
  <div id="buycred-checkout-page">
4
- <div class="checkout-header">
5
 
6
- <?php buycred_checkout_title(); ?>
7
 
8
- </div>
9
- <div class="checkout-order">
10
 
11
- <form method="post" action="" id="buycred-checkout-form">
12
 
13
- <?php buycred_checkout_body(); ?>
14
 
15
- </form>
16
 
17
- </div>
18
- <div class="checkout-footer">
19
 
20
- <?php buycred_checkout_footer(); ?>
21
 
22
- </div>
23
  </div>
24
 
25
- <?php get_footer(); ?>
1
  <?php get_header(); ?>
2
 
3
  <div id="buycred-checkout-page">
4
+ <div class="checkout-header">
5
 
6
+ <?php buycred_checkout_title(); ?>
7
 
8
+ </div>
9
+ <div class="checkout-order">
10
 
11
+ <form method="post" action="" id="buycred-checkout-form">
12
 
13
+ <?php buycred_checkout_body(); ?>
14
 
15
+ </form>
16
 
17
+ </div>
18
+ <div class="checkout-footer">
19
 
20
+ <?php buycred_checkout_footer(); ?>
21
 
22
+ </div>
23
  </div>
24
 
25
+ <?php get_footer(); ?>
addons/buy-creds/templates/index.php CHANGED
@@ -1,3 +1,3 @@
1
  <?php
2
  // Silence is golden.
3
- ?>
1
  <?php
2
  // Silence is golden.
3
+ ?>
addons/cash-creds/abstracts/cashcred-abstract-payment-gateway.php CHANGED
@@ -1,715 +1,772 @@
1
  <?php
2
- if ( ! defined( 'myCRED_VERSION' ) ) exit;
 
3
 
4
  /**
5
  * myCRED_Cash_Payment_Gateway class
6
- * @see http://codex.mycred.me/classes/myCRED_Cash_Payment_Gateway/
7
- * @since 0.1
 
8
  * @version 1.3
9
  */
10
- if ( ! class_exists( 'myCRED_Cash_Payment_Gateway' ) ) :
11
- abstract class myCRED_Cash_Payment_Gateway {
12
-
13
- /**
14
- * The Gateways Unique ID
15
- */
16
- public $id = false;
17
-
18
- /**
19
- * Gateway Label
20
- */
21
- public $label = '';
22
-
23
- /**
24
- * Indicates if the gateway is operating in sandbox mode or not
25
- */
26
- public $sandbox_mode = false;
27
-
28
- /**
29
- * Gateways Settings
30
- */
31
- public $prefs = false;
32
-
33
- /**
34
- * Main Point Type Settings
35
- */
36
- public $core;
37
-
38
- /**
39
- * The current users ID
40
- */
41
- public $current_user_id = 0;
42
-
43
- protected $errors = array();
44
-
45
- /**
46
- * Construct
47
- */
48
- public function __construct( $args = array(), $gateway_prefs = NULL ) {
49
-
50
- // Make sure gateway prefs is set
51
- if ( $gateway_prefs === NULL ) return;
52
-
53
- // Populate
54
- $this->current_user_id = get_current_user_id();
55
- $this->core = mycred();
56
-
57
- // Arguments
58
- if ( ! empty( $args ) ) {
59
- foreach ( $args as $key => $value ) {
60
- $this->$key = $value;
61
- }
62
- }
63
-
64
- $gateway_settings = $this->defaults;
65
- if ( is_array( $gateway_prefs ) && array_key_exists( $this->id, $gateway_prefs ) )
66
- $gateway_settings = $gateway_prefs[ $this->id ];
67
-
68
- elseif ( is_object( $gateway_prefs ) && array_key_exists( $this->id, $gateway_prefs->gateway_prefs ) )
69
- $gateway_settings = $gateway_prefs->gateway_prefs[ $this->id ];
70
-
71
- $this->prefs = shortcode_atts( $this->defaults, $gateway_settings );
72
-
73
- // Sandbox Mode
74
- $this->sandbox_mode = ( isset( $this->prefs['sandbox'] ) ) ? (bool) $this->prefs['sandbox'] : false;
75
-
76
- }
77
-
78
- /**
79
- * Process Purchase
80
- * @since 0.1
81
- * @version 1.0
82
- */
83
- public function process($post = false) { }
84
-
85
- /**
86
- * Results Handler
87
- * @since 0.1
88
- * @version 1.0
89
- */
90
- public function returning() { }
91
-
92
- /**
93
- * Admin Init Handler
94
- * @since 1.7
95
- * @version 1.0
96
- */
97
- public function admin_init() { }
98
-
99
- /**
100
- * Preferences
101
- * @since 0.1
102
- * @version 1.0
103
- */
104
- public function preferences() {
105
-
106
- echo '<p>This Payment Gateway has no settings</p>';
107
-
108
- }
109
-
110
- /**
111
- * Sanatize Prefs
112
- * @since 0.1
113
- * @version 1.0
114
- */
115
- public function sanitise_preferences( $data ) {
116
-
117
- return $data;
118
-
119
- }
120
-
121
- /**
122
- * Exchange Rate Setup
123
- * @since 1.5
124
- * @version 1.1
125
- */
126
- public function exchange_rate_setup( $default = 'USD' ) {
127
-
128
- if ( ! isset( $this->prefs['exchange'] ) ) return;
129
-
130
- $content = '';
131
- $point_types = mycred_get_types();
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
132
 
133
- foreach ( $point_types as $type_id => $label ) {
134
 
135
- $mycred = mycred( $type_id );
136
 
137
- if ( ! isset( $this->prefs['exchange'][ $type_id ] ) )
138
- $this->prefs['exchange'][ $type_id ] = 1;
 
139
 
140
- $content .= '
141
  <table>
142
  <tr>
143
- <td style="min-width: 100px;"><div class="form-control-static">1 ' . esc_html( $mycred->singular() ) . '</div></td>
144
  <td style="width: 10px;"><div class="form-control-static">=</div></td>
145
- <td><input type="text" name="' . $this->field_name( array( 'exchange' => $type_id ) ) . '" id="' . $this->field_id( array( 'exchange' => $type_id ) ) . '" value="' . esc_attr( $this->prefs['exchange'][ $type_id ] ) . '" size="8" /> ';
146
 
147
 
148
- if ( isset( $this->prefs['currency'] ) )
149
- $content .= '<span class="mycred-gateway-' . $this->id . '-currency">' . ( ( $this->prefs['currency'] == '' ) ? __( 'Select currency', 'mycred' ) : esc_attr( $this->prefs['currency'] ) ) . '</span>';
150
 
151
- else
152
- $content .= '<span>' . esc_attr( $default ) . '</span>';
 
153
 
154
- $content .= '</td>
155
  </tr>
156
  </table>';
157
 
158
- }
159
 
160
- echo apply_filters( 'mycred_cashcred_exchange_rate_field', $content, $default, $this );
161
 
162
- }
163
 
164
- /**
165
- * Get Field Name
166
- * Returns the field name for the current gateway
167
- * @since 0.1
168
- * @version 1.0
169
- */
170
- public function field_name( $field = '' ) {
171
-
172
- if ( is_array( $field ) ) {
173
-
174
- $array = array();
175
- foreach ( $field as $parent => $child ) {
176
- if ( ! is_numeric( $parent ) )
177
- $array[] = str_replace( '-', '_', $parent );
178
-
179
- if ( ! empty( $child ) && ! is_array( $child ) )
180
- $array[] = str_replace( '-', '_', $child );
181
- }
182
- $field = '[' . implode( '][', $array ) . ']';
183
-
184
- }
185
- else {
186
-
187
- $field = '[' . $field . ']';
188
-
189
- }
190
-
191
- return 'mycred_pref_cashcreds[gateway_prefs][' . $this->id . ']' . $field;
192
-
193
- }
194
-
195
- /**
196
- * Get Field ID
197
- * Returns the field id for the current gateway
198
- * @since 0.1
199
- * @version 1.0
200
- */
201
- public function field_id( $field = '' ) {
202
-
203
- if ( is_array( $field ) ) {
204
-
205
- $array = array();
206
- foreach ( $field as $parent => $child ) {
207
- if ( ! is_numeric( $parent ) )
208
- $array[] = str_replace( '_', '-', $parent );
209
-
210
- if ( ! empty( $child ) && ! is_array( $child ) )
211
- $array[] = str_replace( '_', '-', $child );
212
- }
213
- $field = implode( '-', $array );
214
-
215
- }
216
- else {
217
-
218
- $field = str_replace( '_', '-', $field );
219
-
220
- }
221
-
222
- return 'mycred-gateway-prefs-' . str_replace( '_', '-', $this->id ) . '-' . $field;
223
-
224
- }
225
-
226
- /**
227
- * Get Errors
228
- * @since 1.0
229
- * @version 1.0
230
- */
231
- public function get_errors() {
232
-
233
- if ( empty( $this->errors ) ) return;
234
-
235
- $errors = array();
236
- foreach ( $this->errors as $form_field => $error_message )
237
- $errors[] = $error_message;
238
-
239
- ?>
240
- <div class="gateway-error"><?php echo implode( '<br />', $errors ); ?></div>
241
- <?php
242
-
243
- }
244
-
245
- /**
246
- * Currencies Dropdown
247
- * @since 0.1
248
- * @version 1.0.2
249
- */
250
- public function currencies_dropdown( $name = '', $js = '' ) {
251
- $currencies = [
252
- 'AUD' => 'Australian dollar',
253
- 'BRL' => 'Brazilian real',
254
- 'CAD' => 'Canadian dollar',
255
- 'CNY' => 'Chinese Renmenbi',
256
- 'CZK' => 'Czech koruna',
257
- 'DKK' => 'Danish krone',
258
- 'EUR' => 'Euro',
259
- 'HKD' => 'Hong Kong dollar',
260
- 'HUF' => 'Hungarian forint',
261
- 'INR' => 'Indian rupee',
262
- 'ILS' => 'Israeli new shekel',
263
- 'JPY' => 'Japanese yen',
264
- 'MYR' => 'Malaysian ringgit',
265
- 'MXN' => 'Mexican peso',
266
- 'TWD' => 'New Taiwan dollar',
267
- 'NZD' => 'New Zealand dollar',
268
- 'NOK' => 'Norwegian krone',
269
- 'PHP' => 'Philippine peso',
270
- 'PLN' => 'Polish złoty',
271
- 'GBP' => 'Pound sterling',
272
- 'RUB' => 'Russian ruble',
273
- 'SGD' => 'Singapore dollar',
274
- 'SEK' => 'Swedish krona',
275
- 'CHF' => 'Swiss franc',
276
- 'THB' => 'Thai baht',
277
- 'USD' => 'United States dollar'
 
 
 
 
 
 
 
 
 
 
 
 
 
 
278
  ];
279
 
280
- $currencies = apply_filters( 'mycred_dropdown_currencies', $currencies, $this->id );
281
- $currencies = apply_filters( 'mycred_dropdown_currencies_' . $this->id, $currencies );
282
-
283
- if ( $js != '' )
284
- $js = ' data-update="' . $js . '"';
285
-
286
- echo '<select name="' . $this->field_name( $name ) . '" id="' . $this->field_id( $name ) . '" class="currency form-control"' . $js . '>';
287
- echo '<option value="">' . __( 'Select', 'mycred' ) . '</option>';
288
- foreach ( $currencies as $code => $cname ) {
289
- echo '<option value="' . $code . '"';
290
- if ( isset( $this->prefs[ $name ] ) && $this->prefs[ $name ] == $code ) echo ' selected="selected"';
291
- echo '>' . $cname . '</option>';
292
- }
293
- echo '</select>';
294
-
295
- }
296
-
297
- /**
298
- * Item Type Dropdown
299
- * @since 0.1
300
- * @version 1.0
301
- */
302
- public function item_types_dropdown( $name = '' ) {
303
-
304
- $types = array(
305
- 'product' => 'Product',
306
- 'service' => 'Service',
307
- 'donation' => 'Donation'
308
- );
309
- $types = apply_filters( 'mycred_dropdown_item_types', $types );
310
-
311
- echo '<select name="' . $this->field_name( $name ) . '" id="' . $this->field_id( $name ) . '">';
312
- echo '<option value="">' . __( 'Select', 'mycred' ) . '</option>';
313
- foreach ( $types as $code => $cname ) {
314
- echo '<option value="' . $code . '"';
315
- if ( isset( $this->prefs[ $name ] ) && $this->prefs[ $name ] == $code ) echo ' selected="selected"';
316
- echo '>' . $cname . '</option>';
317
- }
318
- echo '</select>';
319
-
320
- }
321
-
322
- /**
323
- * Countries Dropdown Options
324
- * @since 0.1
325
- * @version 1.0
326
- */
327
- public function list_option_countries( $selected = '' ) {
328
-
329
- $countries = array (
330
- "US" => "UNITED STATES",
331
- "AF" => "AFGHANISTAN",
332
- "AL" => "ALBANIA",
333
- "DZ" => "ALGERIA",
334
- "AS" => "AMERICAN SAMOA",
335
- "AD" => "ANDORRA",
336
- "AO" => "ANGOLA",
337
- "AI" => "ANGUILLA",
338
- "AQ" => "ANTARCTICA",
339
- "AG" => "ANTIGUA AND BARBUDA",
340
- "AR" => "ARGENTINA",
341
- "AM" => "ARMENIA",
342
- "AW" => "ARUBA",
343
- "AU" => "AUSTRALIA",
344
- "AT" => "AUSTRIA",
345
- "AZ" => "AZERBAIJAN",
346
- "BS" => "BAHAMAS",
347
- "BH" => "BAHRAIN",
348
- "BD" => "BANGLADESH",
349
- "BB" => "BARBADOS",
350
- "BY" => "BELARUS",
351
- "BE" => "BELGIUM",
352
- "BZ" => "BELIZE",
353
- "BJ" => "BENIN",
354
- "BM" => "BERMUDA",
355
- "BT" => "BHUTAN",
356
- "BO" => "BOLIVIA",
357
- "BA" => "BOSNIA AND HERZEGOVINA",
358
- "BW" => "BOTSWANA",
359
- "BV" => "BOUVET ISLAND",
360
- "BR" => "BRAZIL",
361
- "IO" => "BRITISH INDIAN OCEAN TERRITORY",
362
- "BN" => "BRUNEI DARUSSALAM",
363
- "BG" => "BULGARIA",
364
- "BF" => "BURKINA FASO",
365
- "BI" => "BURUNDI",
366
- "KH" => "CAMBODIA",
367
- "CM" => "CAMEROON",
368
- "CA" => "CANADA",
369
- "CV" => "CAPE VERDE",
370
- "KY" => "CAYMAN ISLANDS",
371
- "CF" => "CENTRAL AFRICAN REPUBLIC",
372
- "TD" => "CHAD",
373
- "CL" => "CHILE",
374
- "CN" => "CHINA",
375
- "CX" => "CHRISTMAS ISLAND",
376
- "CC" => "COCOS (KEELING) ISLANDS",
377
- "CO" => "COLOMBIA",
378
- "KM" => "COMOROS",
379
- "CG" => "CONGO",
380
- "CD" => "CONGO, THE DEMOCRATIC REPUBLIC OF THE",
381
- "CK" => "COOK ISLANDS",
382
- "CR" => "COSTA RICA",
383
- "CI" => "COTE D'IVOIRE",
384
- "HR" => "CROATIA",
385
- "CU" => "CUBA",
386
- "CY" => "CYPRUS",
387
- "CZ" => "CZECH REPUBLIC",
388
- "DK" => "DENMARK",
389
- "DJ" => "DJIBOUTI",
390
- "DM" => "DOMINICA",
391
- "DO" => "DOMINICAN REPUBLIC",
392
- "EC" => "ECUADOR",
393
- "EG" => "EGYPT",
394
- "SV" => "EL SALVADOR",
395
- "GQ" => "EQUATORIAL GUINEA",
396
- "ER" => "ERITREA",
397
- "EE" => "ESTONIA",
398
- "ET" => "ETHIOPIA",
399
- "FK" => "FALKLAND ISLANDS (MALVINAS)",
400
- "FO" => "FAROE ISLANDS",
401
- "FJ" => "FIJI",
402
- "FI" => "FINLAND",
403
- "FR" => "FRANCE",
404
- "GF" => "FRENCH GUIANA",
405
- "PF" => "FRENCH POLYNESIA",
406
- "TF" => "FRENCH SOUTHERN TERRITORIES",
407
- "GA" => "GABON",
408
- "GM" => "GAMBIA",
409
- "GE" => "GEORGIA",
410
- "DE" => "GERMANY",
411
- "GH" => "GHANA",
412
- "GI" => "GIBRALTAR",
413
- "GR" => "GREECE",
414
- "GL" => "GREENLAND",
415
- "GD" => "GRENADA",
416
- "GP" => "GUADELOUPE",
417
- "GU" => "GUAM",
418
- "GT" => "GUATEMALA",
419
- "GN" => "GUINEA",
420
- "GW" => "GUINEA-BISSAU",
421
- "GY" => "GUYANA",
422
- "HT" => "HAITI",
423
- "HM" => "HEARD ISLAND AND MCDONALD ISLANDS",
424
- "VA" => "HOLY SEE (VATICAN CITY STATE)",
425
- "HN" => "HONDURAS",
426
- "HK" => "HONG KONG",
427
- "HU" => "HUNGARY",
428
- "IS" => "ICELAND",
429
- "IN" => "INDIA",
430
- "ID" => "INDONESIA",
431
- "IR" => "IRAN, ISLAMIC REPUBLIC OF",
432
- "IQ" => "IRAQ",
433
- "IE" => "IRELAND",
434
- "IL" => "ISRAEL",
435
- "IT" => "ITALY",
436
- "JM" => "JAMAICA",
437
- "JP" => "JAPAN",
438
- "JO" => "JORDAN",
439
- "KZ" => "KAZAKHSTAN",
440
- "KE" => "KENYA",
441
- "KI" => "KIRIBATI",
442
- "KP" => "KOREA, DEMOCRATIC PEOPLE'S REPUBLIC OF",
443
- "KR" => "KOREA, REPUBLIC OF",
444
- "KW" => "KUWAIT",
445
- "KG" => "KYRGYZSTAN",
446
- "LA" => "LAO PEOPLE'S DEMOCRATIC REPUBLIC",
447
- "LV" => "LATVIA",
448
- "LB" => "LEBANON",
449
- "LS" => "LESOTHO",
450
- "LR" => "LIBERIA",
451
- "LY" => "LIBYAN ARAB JAMAHIRIYA",
452
- "LI" => "LIECHTENSTEIN",
453
- "LT" => "LITHUANIA",
454
- "LU" => "LUXEMBOURG",
455
- "MO" => "MACAO",
456
- "MK" => "MACEDONIA, THE FORMER YUGOSLAV REPUBLIC OF",
457
- "MG" => "MADAGASCAR",
458
- "MW" => "MALAWI",
459
- "MY" => "MALAYSIA",
460
- "MV" => "MALDIVES",
461
- "ML" => "MALI",
462
- "MT" => "MALTA",
463
- "MH" => "MARSHALL ISLANDS",
464
- "MQ" => "MARTINIQUE",
465
- "MR" => "MAURITANIA",
466
- "MU" => "MAURITIUS",
467
- "YT" => "MAYOTTE",
468
- "MX" => "MEXICO",
469
- "FM" => "MICRONESIA, FEDERATED STATES OF",
470
- "MD" => "MOLDOVA, REPUBLIC OF",
471
- "MC" => "MONACO",
472
- "MN" => "MONGOLIA",
473
- "MS" => "MONTSERRAT",
474
- "MA" => "MOROCCO",
475
- "MZ" => "MOZAMBIQUE",
476
- "MM" => "MYANMAR",
477
- "NA" => "NAMIBIA",
478
- "NR" => "NAURU",
479
- "NP" => "NEPAL",
480
- "NL" => "NETHERLANDS",
481
- "AN" => "NETHERLANDS ANTILLES",
482
- "NC" => "NEW CALEDONIA",
483
- "NZ" => "NEW ZEALAND",
484
- "NI" => "NICARAGUA",
485
- "NE" => "NIGER",
486
- "NG" => "NIGERIA",
487
- "NU" => "NIUE",
488
- "NF" => "NORFOLK ISLAND",
489
- "MP" => "NORTHERN MARIANA ISLANDS",
490
- "NO" => "NORWAY",
491
- "OM" => "OMAN",
492
- "PK" => "PAKISTAN",
493
- "PW" => "PALAU",
494
- "PS" => "PALESTINIAN TERRITORY, OCCUPIED",
495
- "PA" => "PANAMA",
496
- "PG" => "PAPUA NEW GUINEA",
497
- "PY" => "PARAGUAY",
498
- "PE" => "PERU",
499
- "PH" => "PHILIPPINES",
500
- "PN" => "PITCAIRN",
501
- "PL" => "POLAND",
502
- "PT" => "PORTUGAL",
503
- "PR" => "PUERTO RICO",
504
- "QA" => "QATAR",
505
- "RE" => "REUNION",
506
- "RO" => "ROMANIA",
507
- "RU" => "RUSSIAN FEDERATION",
508
- "RW" => "RWANDA",
509
- "SH" => "SAINT HELENA",
510
- "KN" => "SAINT KITTS AND NEVIS",
511
- "LC" => "SAINT LUCIA",
512
- "PM" => "SAINT PIERRE AND MIQUELON",
513
- "VC" => "SAINT VINCENT AND THE GRENADINES",
514
- "WS" => "SAMOA",
515
- "SM" => "SAN MARINO",
516
- "ST" => "SAO TOME AND PRINCIPE",
517
- "SA" => "SAUDI ARABIA",
518
- "SN" => "SENEGAL",
519
- "CS" => "SERBIA AND MONTENEGRO",
520
- "SC" => "SEYCHELLES",
521
- "SL" => "SIERRA LEONE",
522
- "SG" => "SINGAPORE",
523
- "SK" => "SLOVAKIA",
524
- "SI" => "SLOVENIA",
525
- "SB" => "SOLOMON ISLANDS",
526
- "SO" => "SOMALIA",
527
- "ZA" => "SOUTH AFRICA",
528
- "GS" => "SOUTH GEORGIA AND THE SOUTH SANDWICH ISLANDS",
529
- "ES" => "SPAIN",
530
- "LK" => "SRI LANKA",
531
- "SD" => "SUDAN",
532
- "SR" => "SURINAME",
533
- "SJ" => "SVALBARD AND JAN MAYEN",
534
- "SZ" => "SWAZILAND",
535
- "SE" => "SWEDEN",
536
- "CH" => "SWITZERLAND",
537
- "SY" => "SYRIAN ARAB REPUBLIC",
538
- "TW" => "TAIWAN, PROVINCE OF CHINA",
539
- "TJ" => "TAJIKISTAN",
540
- "TZ" => "TANZANIA, UNITED REPUBLIC OF",
541
- "TH" => "THAILAND",
542
- "TL" => "TIMOR-LESTE",
543
- "TG" => "TOGO",
544
- "TK" => "TOKELAU",
545
- "TO" => "TONGA",
546
- "TT" => "TRINIDAD AND TOBAGO",
547
- "TN" => "TUNISIA",
548
- "TR" => "TURKEY",
549
- "TM" => "TURKMENISTAN",
550
- "TC" => "TURKS AND CAICOS ISLANDS",
551
- "TV" => "TUVALU",
552
- "UG" => "UGANDA",
553
- "UA" => "UKRAINE",
554
- "AE" => "UNITED ARAB EMIRATES",
555
- "GB" => "UNITED KINGDOM",
556
- "US" => "UNITED STATES",
557
- "UM" => "UNITED STATES MINOR OUTLYING ISLANDS",
558
- "UY" => "URUGUAY",
559
- "UZ" => "UZBEKISTAN",
560
- "VU" => "VANUATU",
561
- "VE" => "VENEZUELA",
562
- "VN" => "VIET NAM",
563
- "VG" => "VIRGIN ISLANDS, BRITISH",
564
- "VI" => "VIRGIN ISLANDS, U.S.",
565
- "WF" => "WALLIS AND FUTUNA",
566
- "EH" => "WESTERN SAHARA",
567
- "YE" => "YEMEN",
568
- "ZM" => "ZAMBIA",
569
- "ZW" => "ZIMBABWE"
570
- );
571
- $countries = apply_filters( 'mycred_list_option_countries', $countries );
572
-
573
- foreach ( $countries as $code => $cname ) {
574
- echo '<option value="' . $code . '"';
575
- if ( $selected == $code ) echo ' selected="selected"';
576
- echo '>' . $cname . '</option>';
577
- }
578
-
579
- }
580
-
581
- /**
582
- * US States Dropdown Options
583
- * @since 0.1
584
- * @version 1.0
585
- */
586
- public function list_option_us_states( $selected = '', $non_us = false ) {
587
-
588
- $states = array (
589
- "AL" => "Alabama",
590
- "AK" => "Alaska",
591
- "AZ" => "Arizona",
592
- "AR" => "Arkansas",
593
- "CA" => "California",
594
- "CO" => "Colorado",
595
- "CT" => "Connecticut",
596
- "DC" => "D.C.",
597
- "DE" => "Delaware",
598
- "FL" => "Florida",
599
- "GA" => "Georgia",
600
- "HI" => "Hawaii",
601
- "ID" => "Idaho",
602
- "IL" => "Illinois",
603
- "IN" => "Indiana",
604
- "IA" => "Iowa",
605
- "KS" => "Kansas",
606
- "KY" => "Kentucky",
607
- "LA" => "Louisiana",
608
- "ME" => "Maine",
609
- "MD" => "Maryland",
610
- "MA" => "Massachusetts",
611
- "MI" => "Michigan",
612
- "MN" => "Minnesota",
613
- "MS" => "Mississippi",
614
- "MO" => "Missouri",
615
- "MT" => "Montana",
616
- "NE" => "Nebraska",
617
- "NV" => "Nevada",
618
- "NH" => "New Hampshire",
619
- "NJ" => "New Jersey",
620
- "NM" => "New Mexico",
621
- "NY" => "New York",
622
- "NC" => "North Carolina",
623
- "ND" => "North Dakota",
624
- "OH" => "Ohio",
625
- "OK" => "Oklahoma",
626
- "OR" => "Oregon",
627
- "PA" => "Pennsylvania",
628
- "RI" => "Rhode Island",
629
- "SC" => "South Carolina",
630
- "SD" => "South Dakota",
631
- "TN" => "Tennessee",
632
- "TX" => "Texas",
633
- "UT" => "Utah",
634
- "VT" => "Vermont",
635
- "VA" => "Virginia",
636
- "WA" => "Washington",
637
- "WV" => "West Virginia",
638
- "WI" => "Wisconsin",
639
- "WY" => "Wyoming"
640
- );
641
- $states = apply_filters( 'mycred_list_option_us', $states );
642
-
643
- $outside = 'Outside US';
644
- if ( $non_us == 'top' ) echo '<option value="">' . $outside . '</option>';
645
- foreach ( $states as $code => $cname ) {
646
- echo '<option value="' . $code . '"';
647
- if ( $selected == $code ) echo ' selected="selected"';
648
- echo '>' . $cname . '</option>';
649
- }
650
- if ( $non_us == 'bottom' ) echo '<option value="">' . $outside . '</option>';
651
-
652
- }
653
-
654
- /**
655
- * Months Dropdown Options
656
- * @since 0.1
657
- * @version 1.0
658
- */
659
- public function list_option_months( $selected = '' ) {
660
-
661
- $months = array (
662
- "01" => __( 'January', 'mycred' ),
663
- "02" => __( 'February', 'mycred' ),
664
- "03" => __( 'March', 'mycred' ),
665
- "04" => __( 'April', 'mycred' ),
666
- "05" => __( 'May', 'mycred' ),
667
- "06" => __( 'June', 'mycred' ),
668
- "07" => __( 'July', 'mycred' ),
669
- "08" => __( 'August', 'mycred' ),
670
- "09" => __( 'September', 'mycred' ),
671
- "10" => __( 'October', 'mycred' ),
672
- "11" => __( 'November', 'mycred' ),
673
- "12" => __( 'December', 'mycred' )
674
- );
675
-
676
- foreach ( $months as $number => $text ) {
677
- echo '<option value="' . $number . '"';
678
- if ( $selected == $number ) echo ' selected="selected"';
679
- echo '>' . $text . '</option>';
680
- }
681
-
682
- }
683
-
684
- /**
685
- * Years Dropdown Options
686
- * @since 0.1
687
- * @version 1.0
688
- */
689
- public function list_option_card_years( $selected = '', $number = 16 ) {
690
-
691
- $now = current_time( 'timestamp' );
692
- $yy = date( 'y', $now );
693
- $yyyy = date( 'Y', $now );
694
- $count = 0;
695
- $options = array();
696
-
697
- while ( $count <= (int) $number ) {
698
- $count ++;
699
- if ( $count > 1 ) {
700
- $yy++;
701
- $yyyy++;
702
- }
703
- $options[ $yy ] = $yyyy;
704
- }
705
-
706
- foreach ( $options as $key => $value ) {
707
- echo '<option value="' . $key . '"';
708
- if ( $selected == $key ) echo ' selected="selected"';
709
- echo '>' . $value . '</option>';
710
- }
711
-
712
- }
713
-
714
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
715
  endif;
1
  <?php
2
+ if (! defined('myCRED_VERSION') ) { exit;
3
+ }
4
 
5
  /**
6
  * myCRED_Cash_Payment_Gateway class
7
+ *
8
+ * @see http://codex.mycred.me/classes/myCRED_Cash_Payment_Gateway/
9
+ * @since 0.1
10
  * @version 1.3
11
  */
12
+ if (! class_exists('myCRED_Cash_Payment_Gateway') ) :
13
+ abstract class myCRED_Cash_Payment_Gateway
14
+ {
15
+
16
+ /**
17
+ * The Gateways Unique ID
18
+ */
19
+ public $id = false;
20
+
21
+ /**
22
+ * Gateway Label
23
+ */
24
+ public $label = '';
25
+
26
+ /**
27
+ * Indicates if the gateway is operating in sandbox mode or not
28
+ */
29
+ public $sandbox_mode = false;
30
+
31
+ /**
32
+ * Gateways Settings
33
+ */
34
+ public $prefs = false;
35
+
36
+ /**
37
+ * Main Point Type Settings
38
+ */
39
+ public $core;
40
+
41
+ /**
42
+ * The current users ID
43
+ */
44
+ public $current_user_id = 0;
45
+
46
+ protected $errors = array();
47
+
48
+ /**
49
+ * Construct
50
+ */
51
+ public function __construct( $args = array(), $gateway_prefs = null )
52
+ {
53
+
54
+ // Make sure gateway prefs is set
55
+ if ($gateway_prefs === null ) { return;
56
+ }
57
+
58
+ // Populate
59
+ $this->current_user_id = get_current_user_id();
60
+ $this->core = mycred();
61
+
62
+ // Arguments
63
+ if (! empty($args) ) {
64
+ foreach ( $args as $key => $value ) {
65
+ $this->$key = $value;
66
+ }
67
+ }
68
+
69
+ $gateway_settings = $this->defaults;
70
+ if (is_array($gateway_prefs) && array_key_exists($this->id, $gateway_prefs) ) {
71
+ $gateway_settings = $gateway_prefs[ $this->id ];
72
+
73
+ } elseif (is_object($gateway_prefs) && array_key_exists($this->id, $gateway_prefs->gateway_prefs) ) {
74
+ $gateway_settings = $gateway_prefs->gateway_prefs[ $this->id ];
75
+ }
76
+
77
+ $this->prefs = shortcode_atts($this->defaults, $gateway_settings);
78
+
79
+ // Sandbox Mode
80
+ $this->sandbox_mode = ( isset($this->prefs['sandbox']) ) ? (bool) $this->prefs['sandbox'] : false;
81
+
82
+ }
83
+
84
+ /**
85
+ * Process Purchase
86
+ *
87
+ * @since 0.1
88
+ * @version 1.0
89
+ */
90
+ public function process($post = false)
91
+ {
92
+ }
93
+
94
+ /**
95
+ * Results Handler
96
+ *
97
+ * @since 0.1
98
+ * @version 1.0
99
+ */
100
+ public function returning()
101
+ {
102
+ }
103
+
104
+ /**
105
+ * Admin Init Handler
106
+ *
107
+ * @since 1.7
108
+ * @version 1.0
109
+ */
110
+ public function admin_init()
111
+ {
112
+ }
113
+
114
+ /**
115
+ * Preferences
116
+ *
117
+ * @since 0.1
118
+ * @version 1.0
119
+ */
120
+ public function preferences()
121
+ {
122
+
123
+ echo '<p>This Payment Gateway has no settings</p>';
124
+
125
+ }
126
+
127
+ /**
128
+ * Sanatize Prefs
129
+ *
130
+ * @since 0.1
131
+ * @version 1.0
132
+ */
133
+ public function sanitise_preferences( $data )
134
+ {
135
+
136
+ return $data;
137
+
138
+ }
139
+
140
+ /**
141
+ * Exchange Rate Setup
142
+ *
143
+ * @since 1.5
144
+ * @version 1.1
145
+ */
146
+ public function exchange_rate_setup( $default = 'USD' )
147
+ {
148
+
149
+ if (! isset($this->prefs['exchange']) ) { return;
150
+ }
151
+
152
+ $content = '';
153
+ $point_types = mycred_get_types();
154
 
155
+ foreach ( $point_types as $type_id => $label ) {
156
 
157
+ $mycred = mycred($type_id);
158
 
159
+ if (! isset($this->prefs['exchange'][ $type_id ]) ) {
160
+ $this->prefs['exchange'][ $type_id ] = 1;
161
+ }
162
 
163
+ $content .= '
164
  <table>
165
  <tr>
166
+ <td style="min-width: 100px;"><div class="form-control-static">1 ' . esc_html($mycred->singular()) . '</div></td>
167
  <td style="width: 10px;"><div class="form-control-static">=</div></td>
168
+ <td><input type="text" name="' . $this->field_name(array( 'exchange' => $type_id )) . '" id="' . $this->field_id(array( 'exchange' => $type_id )) . '" value="' . esc_attr($this->prefs['exchange'][ $type_id ]) . '" size="8" /> ';
169
 
170
 
171
+ if (isset($this->prefs['currency']) ) {
172
+ $content .= '<span class="mycred-gateway-' . $this->id . '-currency">' . ( ( $this->prefs['currency'] == '' ) ? __('Select currency', 'mycred') : esc_attr($this->prefs['currency']) ) . '</span>';
173
 
174
+ } else {
175
+ $content .= '<span>' . esc_attr($default) . '</span>';
176
+ }
177
 
178
+ $content .= '</td>
179
  </tr>
180
  </table>';
181
 
182
+ }
183
 
184
+ echo apply_filters('mycred_cashcred_exchange_rate_field', $content, $default, $this);
185
 
186
+ }
187
 
188
+ /**
189
+ * Get Field Name
190
+ * Returns the field name for the current gateway
191
+ *
192
+ * @since 0.1
193
+ * @version 1.0
194
+ */
195
+ public function field_name( $field = '' )
196
+ {
197
+
198
+ if (is_array($field) ) {
199
+
200
+ $array = array();
201
+ foreach ( $field as $parent => $child ) {
202
+ if (! is_numeric($parent) ) {
203
+ $array[] = str_replace('-', '_', $parent);
204
+ }
205
+
206
+ if (! empty($child) && ! is_array($child) ) {
207
+ $array[] = str_replace('-', '_', $child);
208
+ }
209
+ }
210
+ $field = '[' . implode('][', $array) . ']';
211
+
212
+ }
213
+ else {
214
+
215
+ $field = '[' . $field . ']';
216
+
217
+ }
218
+
219
+ return 'mycred_pref_cashcreds[gateway_prefs][' . $this->id . ']' . $field;
220
+
221
+ }
222
+
223
+ /**
224
+ * Get Field ID
225
+ * Returns the field id for the current gateway
226
+ *
227
+ * @since 0.1
228
+ * @version 1.0
229
+ */
230
+ public function field_id( $field = '' )
231
+ {
232
+
233
+ if (is_array($field) ) {
234
+
235
+ $array = array();
236
+ foreach ( $field as $parent => $child ) {
237
+ if (! is_numeric($parent) ) {
238
+ $array[] = str_replace('_', '-', $parent);
239
+ }
240
+
241
+ if (! empty($child) && ! is_array($child) ) {
242
+ $array[] = str_replace('_', '-', $child);
243
+ }
244
+ }
245
+ $field = implode('-', $array);
246
+
247
+ }
248
+ else {
249
+
250
+ $field = str_replace('_', '-', $field);
251
+
252
+ }
253
+
254
+ return 'mycred-gateway-prefs-' . str_replace('_', '-', $this->id) . '-' . $field;
255
+
256
+ }
257
+
258
+ /**
259
+ * Get Errors
260
+ *
261
+ * @since 1.0
262
+ * @version 1.0
263
+ */
264
+ public function get_errors()
265
+ {
266
+
267
+ if (empty($this->errors) ) { return;
268
+ }
269
+
270
+ $errors = array();
271
+ foreach ( $this->errors as $form_field => $error_message ) {
272
+ $errors[] = $error_message;
273
+ }
274
+
275
+ ?>
276
+ <div class="gateway-error"><?php echo implode('<br />', $errors); ?></div>
277
+ <?php
278
+
279
+ }
280
+
281
+ /**
282
+ * Currencies Dropdown
283
+ *
284
+ * @since 0.1
285
+ * @version 1.0.2
286
+ */
287
+ public function currencies_dropdown( $name = '', $js = '' )
288
+ {
289
+ $currencies = [
290
+ 'AUD' => 'Australian dollar',
291
+ 'BRL' => 'Brazilian real',
292
+ 'CAD' => 'Canadian dollar',
293
+ 'CNY' => 'Chinese Renmenbi',
294
+ 'CZK' => 'Czech koruna',
295
+ 'DKK' => 'Danish krone',
296
+ 'EUR' => 'Euro',
297
+ 'HKD' => 'Hong Kong dollar',
298
+ 'HUF' => 'Hungarian forint',
299
+ 'INR' => 'Indian rupee',
300
+ 'ILS' => 'Israeli new shekel',
301
+ 'JPY' => 'Japanese yen',
302
+ 'MYR' => 'Malaysian ringgit',
303
+ 'MXN' => 'Mexican peso',
304
+ 'TWD' => 'New Taiwan dollar',
305
+ 'NZD' => 'New Zealand dollar',
306
+ 'NOK' => 'Norwegian krone',
307
+ 'PHP' => 'Philippine peso',
308
+ 'PLN' => 'Polish złoty',
309
+ 'GBP' => 'Pound sterling',
310
+ 'RUB' => 'Russian ruble',
311
+ 'SGD' => 'Singapore dollar',
312
+ 'SEK' => 'Swedish krona',
313
+ 'CHF' => 'Swiss franc',
314
+ 'THB' => 'Thai baht',
315
+ 'USD' => 'United States dollar'
316
  ];
317
 
318
+ $currencies = apply_filters('mycred_dropdown_currencies', $currencies, $this->id);
319
+ $currencies = apply_filters('mycred_dropdown_currencies_' . $this->id, $currencies);
320
+
321
+ if ($js != '' ) {
322
+ $js = ' data-update="' . $js . '"';
323
+ }
324
+
325
+ echo '<select name="' . $this->field_name($name) . '" id="' . $this->field_id($name) . '" class="currency form-control"' . $js . '>';
326
+ echo '<option value="">' . __('Select', 'mycred') . '</option>';
327
+ foreach ( $currencies as $code => $cname ) {
328
+ echo '<option value="' . $code . '"';
329
+ if (isset($this->prefs[ $name ]) && $this->prefs[ $name ] == $code ) { echo ' selected="selected"';
330
+ }
331
+ echo '>' . $cname . '</option>';
332
+ }
333
+ echo '</select>';
334
+
335
+ }
336
+
337
+ /**
338
+ * Item Type Dropdown
339
+ *
340
+ * @since 0.1
341
+ * @version 1.0
342
+ */
343
+ public function item_types_dropdown( $name = '' )
344
+ {
345
+
346
+ $types = array(
347
+ 'product' => 'Product',
348
+ 'service' => 'Service',
349
+ 'donation' => 'Donation'
350
+ );
351
+ $types = apply_filters('mycred_dropdown_item_types', $types);
352
+
353
+ echo '<select name="' . $this->field_name($name) . '" id="' . $this->field_id($name) . '">';
354
+ echo '<option value="">' . __('Select', 'mycred') . '</option>';
355
+ foreach ( $types as $code => $cname ) {
356
+ echo '<option value="' . $code . '"';
357
+ if (isset($this->prefs[ $name ]) && $this->prefs[ $name ] == $code ) { echo ' selected="selected"';
358
+ }
359
+ echo '>' . $cname . '</option>';
360
+ }
361
+ echo '</select>';
362
+
363
+ }
364
+
365
+ /**
366
+ * Countries Dropdown Options
367
+ *
368
+ * @since 0.1
369
+ * @version 1.0
370
+ */
371
+ public function list_option_countries( $selected = '' )
372
+ {
373
+
374
+ $countries = array (
375
+ "US" => "UNITED STATES",
376
+ "AF" => "AFGHANISTAN",
377
+ "AL" => "ALBANIA",
378
+ "DZ" => "ALGERIA",
379
+ "AS" => "AMERICAN SAMOA",
380
+ "AD" => "ANDORRA",
381
+ "AO" => "ANGOLA",
382
+ "AI" => "ANGUILLA",
383
+ "AQ" => "ANTARCTICA",
384
+ "AG" => "ANTIGUA AND BARBUDA",
385
+ "AR" => "ARGENTINA",
386
+ "AM" => "ARMENIA",
387
+ "AW" => "ARUBA",
388
+ "AU" => "AUSTRALIA",
389
+ "AT" => "AUSTRIA",
390
+ "AZ" => "AZERBAIJAN",
391
+ "BS" => "BAHAMAS",
392
+ "BH" => "BAHRAIN",
393
+ "BD" => "BANGLADESH",
394
+ "BB" => "BARBADOS",
395
+ "BY" => "BELARUS",
396
+ "BE" => "BELGIUM",
397
+ "BZ" => "BELIZE",
398
+ "BJ" => "BENIN",
399
+ "BM" => "BERMUDA",
400
+ "BT" => "BHUTAN",
401
+ "BO" => "BOLIVIA",
402
+ "BA" => "BOSNIA AND HERZEGOVINA",
403
+ "BW" => "BOTSWANA",
404
+ "BV" => "BOUVET ISLAND",
405
+ "BR" => "BRAZIL",
406
+ "IO" => "BRITISH INDIAN OCEAN TERRITORY",
407
+ "BN" => "BRUNEI DARUSSALAM",
408
+ "BG" => "BULGARIA",
409
+ "BF" => "BURKINA FASO",
410
+ "BI" => "BURUNDI",
411
+ "KH" => "CAMBODIA",
412
+ "CM" => "CAMEROON",
413
+ "CA" => "CANADA",
414
+ "CV" => "CAPE VERDE",
415
+ "KY" => "CAYMAN ISLANDS",
416
+ "CF" => "CENTRAL AFRICAN REPUBLIC",
417
+ "TD" => "CHAD",
418
+ "CL" => "CHILE",
419
+ "CN" => "CHINA",
420
+ "CX" => "CHRISTMAS ISLAND",
421
+ "CC" => "COCOS (KEELING) ISLANDS",
422
+ "CO" => "COLOMBIA",
423
+ "KM" => "COMOROS",
424
+ "CG" => "CONGO",
425
+ "CD" => "CONGO, THE DEMOCRATIC REPUBLIC OF THE",
426
+ "CK" => "COOK ISLANDS",
427
+ "CR" => "COSTA RICA",
428
+ "CI" => "COTE D'IVOIRE",
429
+ "HR" => "CROATIA",
430
+ "CU" => "CUBA",
431
+ "CY" => "CYPRUS",
432
+ "CZ" => "CZECH REPUBLIC",
433
+ "DK" => "DENMARK",
434
+ "DJ" => "DJIBOUTI",
435
+ "DM" => "DOMINICA",
436
+ "DO" => "DOMINICAN REPUBLIC",
437
+ "EC" => "ECUADOR",
438
+ "EG" => "EGYPT",
439
+ "SV" => "EL SALVADOR",
440
+ "GQ" => "EQUATORIAL GUINEA",
441
+ "ER" => "ERITREA",
442
+ "EE" => "ESTONIA",
443
+ "ET" => "ETHIOPIA",
444
+ "FK" => "FALKLAND ISLANDS (MALVINAS)",
445
+ "FO" => "FAROE ISLANDS",
446
+ "FJ" => "FIJI",
447
+ "FI" => "FINLAND",
448
+ "FR" => "FRANCE",
449
+ "GF" => "FRENCH GUIANA",
450
+ "PF" => "FRENCH POLYNESIA",
451
+ "TF" => "FRENCH SOUTHERN TERRITORIES",
452
+ "GA" => "GABON",
453
+ "GM" => "GAMBIA",
454
+ "GE" => "GEORGIA",
455
+ "DE" => "GERMANY",
456
+ "GH" => "GHANA",
457
+ "GI" => "GIBRALTAR",
458
+ "GR" => "GREECE",
459
+ "GL" => "GREENLAND",
460
+ "GD" => "GRENADA",
461
+ "GP" => "GUADELOUPE",
462
+ "GU" => "GUAM",
463
+ "GT" => "GUATEMALA",
464
+ "GN" => "GUINEA",
465
+ "GW" => "GUINEA-BISSAU",
466
+ "GY" => "GUYANA",
467
+ "HT" => "HAITI",
468
+ "HM" => "HEARD ISLAND AND MCDONALD ISLANDS",
469
+ "VA" => "HOLY SEE (VATICAN CITY STATE)",
470
+ "HN" => "HONDURAS",
471
+ "HK" => "HONG KONG",
472
+ "HU" => "HUNGARY",
473
+ "IS" => "ICELAND",
474
+ "IN" => "INDIA",
475
+ "ID" => "INDONESIA",
476
+ "IR" => "IRAN, ISLAMIC REPUBLIC OF",
477
+ "IQ" => "IRAQ",
478
+ "IE" => "IRELAND",
479
+ "IL" => "ISRAEL",
480
+ "IT" => "ITALY",
481
+ "JM" => "JAMAICA",
482
+ "JP" => "JAPAN",
483
+ "JO" => "JORDAN",
484
+ "KZ" => "KAZAKHSTAN",
485
+ "KE" => "KENYA",
486
+ "KI" => "KIRIBATI",
487
+ "KP" => "KOREA, DEMOCRATIC PEOPLE'S REPUBLIC OF",
488
+ "KR" => "KOREA, REPUBLIC OF",
489
+ "KW" => "KUWAIT",
490
+ "KG" => "KYRGYZSTAN",
491
+ "LA" => "LAO PEOPLE'S DEMOCRATIC REPUBLIC",
492
+ "LV" => "LATVIA",
493
+ "LB" => "LEBANON",
494
+ "LS" => "LESOTHO",
495
+ "LR" => "LIBERIA",
496
+ "LY" => "LIBYAN ARAB JAMAHIRIYA",
497
+ "LI" => "LIECHTENSTEIN",
498
+ "LT" => "LITHUANIA",
499
+ "LU" => "LUXEMBOURG",
500
+ "MO" => "MACAO",
501
+ "MK" => "MACEDONIA, THE FORMER YUGOSLAV REPUBLIC OF",
502
+ "MG" => "MADAGASCAR",
503
+ "MW" => "MALAWI",
504
+ "MY" => "MALAYSIA",
505
+ "MV" => "MALDIVES",
506
+ "ML" => "MALI",
507
+ "MT" => "MALTA",
508
+ "MH" => "MARSHALL ISLANDS",
509
+ "MQ" => "MARTINIQUE",
510
+ "MR" => "MAURITANIA",
511
+ "MU" => "MAURITIUS",
512
+ "YT" => "MAYOTTE",
513
+ "MX" => "MEXICO",
514
+ "FM" => "MICRONESIA, FEDERATED STATES OF",
515
+ "MD" => "MOLDOVA, REPUBLIC OF",
516
+ "MC" => "MONACO",
517
+ "MN" => "MONGOLIA",
518
+ "MS" => "MONTSERRAT",
519
+ "MA" => "MOROCCO",
520
+ "MZ" => "MOZAMBIQUE",
521
+ "MM" => "MYANMAR",
522
+ "NA" => "NAMIBIA",
523
+ "NR" => "NAURU",
524
+ "NP" => "NEPAL",
525
+ "NL" => "NETHERLANDS",
526
+ "AN" => "NETHERLANDS ANTILLES",
527
+ "NC" => "NEW CALEDONIA",
528
+ "NZ" => "NEW ZEALAND",
529
+ "NI" => "NICARAGUA",
530
+ "NE" => "NIGER",
531
+ "NG" => "NIGERIA",
532
+ "NU" => "NIUE",
533
+ "NF" => "NORFOLK ISLAND",
534
+ "MP" => "NORTHERN MARIANA ISLANDS",
535
+ "NO" => "NORWAY",
536
+ "OM" => "OMAN",
537
+ "PK" => "PAKISTAN",
538
+ "PW" => "PALAU",
539
+ "PS" => "PALESTINIAN TERRITORY, OCCUPIED",
540
+ "PA" => "PANAMA",
541
+ "PG" => "PAPUA NEW GUINEA",
542
+ "PY" => "PARAGUAY",
543
+ "PE" => "PERU",
544
+ "PH" => "PHILIPPINES",
545
+ "PN" => "PITCAIRN",
546
+ "PL" => "POLAND",
547
+ "PT" => "PORTUGAL",
548
+ "PR" => "PUERTO RICO",
549
+ "QA" => "QATAR",
550
+ "RE" => "REUNION",
551
+ "RO" => "ROMANIA",
552
+ "RU" => "RUSSIAN FEDERATION",
553
+ "RW" => "RWANDA",
554
+ "SH" => "SAINT HELENA",
555
+ "KN" => "SAINT KITTS AND NEVIS",
556
+ "LC" => "SAINT LUCIA",
557
+ "PM" => "SAINT PIERRE AND MIQUELON",
558
+ "VC" => "SAINT VINCENT AND THE GRENADINES",
559
+ "WS" => "SAMOA",
560
+ "SM" => "SAN MARINO",
561
+ "ST" => "SAO TOME AND PRINCIPE",
562
+ "SA" => "SAUDI ARABIA",
563
+ "SN" => "SENEGAL",
564
+ "CS" => "SERBIA AND MONTENEGRO",
565
+ "SC" => "SEYCHELLES",
566
+ "SL" => "SIERRA LEONE",
567
+ "SG" => "SINGAPORE",
568
+ "SK" => "SLOVAKIA",
569
+ "SI" => "SLOVENIA",
570
+ "SB" => "SOLOMON ISLANDS",
571
+ "SO" => "SOMALIA",
572
+ "ZA" => "SOUTH AFRICA",
573
+ "GS" => "SOUTH GEORGIA AND THE SOUTH SANDWICH ISLANDS",
574
+ "ES" => "SPAIN",
575
+ "LK" => "SRI LANKA",
576
+ "SD" => "SUDAN",
577
+ "SR" => "SURINAME",
578
+ "SJ" => "SVALBARD AND JAN MAYEN",
579
+ "SZ" => "SWAZILAND",
580
+ "SE" => "SWEDEN",
581
+ "CH" => "SWITZERLAND",
582
+ "SY" => "SYRIAN ARAB REPUBLIC",
583
+ "TW" => "TAIWAN, PROVINCE OF CHINA",
584
+ "TJ" => "TAJIKISTAN",
585
+ "TZ" => "TANZANIA, UNITED REPUBLIC OF",
586
+ "TH" => "THAILAND",
587
+ "TL" => "TIMOR-LESTE",
588
+ "TG" => "TOGO",
589
+ "TK" => "TOKELAU",
590
+ "TO" => "TONGA",
591
+ "TT" => "TRINIDAD AND TOBAGO",
592
+ "TN" => "TUNISIA",
593
+ "TR" => "TURKEY",
594
+ "TM" => "TURKMENISTAN",
595
+ "TC" => "TURKS AND CAICOS ISLANDS",
596
+ "TV" => "TUVALU",
597
+ "UG" => "UGANDA",
598
+ "UA" => "UKRAINE",
599
+ "AE" => "UNITED ARAB EMIRATES",
600
+ "GB" => "UNITED KINGDOM",
601
+ "US" => "UNITED STATES",
602
+ "UM" => "UNITED STATES MINOR OUTLYING ISLANDS",
603
+ "UY" => "URUGUAY",
604
+ "UZ" => "UZBEKISTAN",
605
+ "VU" => "VANUATU",
606
+ "VE" => "VENEZUELA",
607
+ "VN" => "VIET NAM",
608
+ "VG" => "VIRGIN ISLANDS, BRITISH",
609
+ "VI" => "VIRGIN ISLANDS, U.S.",
610
+ "WF" => "WALLIS AND FUTUNA",
611
+ "EH" => "WESTERN SAHARA",
612
+ "YE" => "YEMEN",
613
+ "ZM" => "ZAMBIA",
614
+ "ZW" => "ZIMBABWE"
615
+ );
616
+ $countries = apply_filters('mycred_list_option_countries', $countries);
617
+
618
+ foreach ( $countries as $code => $cname ) {
619
+ echo '<option value="' . $code . '"';
620
+ if ($selected == $code ) { echo ' selected="selected"';
621
+ }
622
+ echo '>' . $cname . '</option>';
623
+ }
624
+
625
+ }
626
+
627
+ /**
628
+ * US States Dropdown Options
629
+ *
630
+ * @since 0.1
631
+ * @version 1.0
632
+ */
633
+ public function list_option_us_states( $selected = '', $non_us = false )
634
+ {
635
+
636
+ $states = array (
637
+ "AL" => "Alabama",
638
+ "AK" => "Alaska",
639
+ "AZ" => "Arizona",
640
+ "AR" => "Arkansas",
641
+ "CA" => "California",
642
+ "CO" => "Colorado",
643
+ "CT" => "Connecticut",
644
+ "DC" => "D.C.",
645
+ "DE" => "Delaware",
646
+ "FL" => "Florida",
647
+ "GA" => "Georgia",
648
+ "HI" => "Hawaii",
649
+ "ID" => "Idaho",
650
+ "IL" => "Illinois",
651
+ "IN" => "Indiana",
652
+ "IA" => "Iowa",
653
+ "KS" => "Kansas",
654
+ "KY" => "Kentucky",
655
+ "LA" => "Louisiana",
656
+ "ME" => "Maine",
657
+ "MD" => "Maryland",
658
+ "MA" => "Massachusetts",
659
+ "MI" => "Michigan",
660
+ "MN" => "Minnesota",
661
+ "MS" => "Mississippi",
662
+ "MO" => "Missouri",
663
+ "MT" => "Montana",
664
+ "NE" => "Nebraska",
665
+ "NV" => "Nevada",
666
+ "NH" => "New Hampshire",
667
+ "NJ" => "New Jersey",
668
+ "NM" => "New Mexico",
669
+ "NY" => "New York",
670
+ "NC" => "North Carolina",
671
+ "ND" => "North Dakota",
672
+ "OH" => "Ohio",
673
+ "OK" => "Oklahoma",
674
+ "OR" => "Oregon",
675
+ "PA" => "Pennsylvania",
676
+ "RI" => "Rhode Island",
677
+ "SC" => "South Carolina",
678
+ "SD" => "South Dakota",
679
+ "TN" => "Tennessee",
680
+ "TX" => "Texas",
681
+ "UT" => "Utah",
682
+ "VT" => "Vermont",
683
+ "VA" => "Virginia",
684
+ "WA" => "Washington",
685
+ "WV" => "West Virginia",
686
+ "WI" => "Wisconsin",
687
+ "WY" => "Wyoming"
688
+ );
689
+ $states = apply_filters('mycred_list_option_us', $states);
690
+
691
+ $outside = 'Outside US';
692
+ if ($non_us == 'top' ) { echo '<option value="">' . $outside . '</option>';
693
+ }
694
+ foreach ( $states as $code => $cname ) {
695
+ echo '<option value="' . $code . '"';
696
+ if ($selected == $code ) { echo ' selected="selected"';
697
+ }
698
+ echo '>' . $cname . '</option>';
699
+ }
700
+ if ($non_us == 'bottom' ) { echo '<option value="">' . $outside . '</option>';
701
+ }
702
+
703
+ }
704
+
705
+ /**
706
+ * Months Dropdown Options
707
+ *
708
+ * @since 0.1
709
+ * @version 1.0
710
+ */
711
+ public function list_option_months( $selected = '' )
712
+ {
713
+
714
+ $months = array (
715
+ "01" => __('January', 'mycred'),
716
+ "02" => __('February', 'mycred'),
717
+ "03" => __('March', 'mycred'),
718
+ "04" => __('April', 'mycred'),
719
+ "05" => __('May', 'mycred'),
720
+ "06" => __('June', 'mycred'),
721
+ "07" => __('July', 'mycred'),
722
+ "08" => __('August', 'mycred'),
723
+ "09" => __('September', 'mycred'),
724
+ "10" => __('October', 'mycred'),
725
+ "11" => __('November', 'mycred'),
726
+ "12" => __('December', 'mycred')
727
+ );
728
+
729
+ foreach ( $months as $number => $text ) {
730
+ echo '<option value="' . $number . '"';
731
+ if ($selected == $number ) { echo ' selected="selected"';
732
+ }
733
+ echo '>' . $text . '</option>';
734
+ }
735
+
736
+ }
737
+
738
+ /**
739
+ * Years Dropdown Options
740
+ *
741
+ * @since 0.1
742
+ * @version 1.0
743
+ */
744
+ public function list_option_card_years( $selected = '', $number = 16 )
745
+ {
746
+
747
+ $now = current_time('timestamp');
748
+ $yy = date('y', $now);
749
+ $yyyy = date('Y', $now);
750
+ $count = 0;
751
+ $options = array();
752
+
753
+ while ( $count <= (int) $number ) {
754
+ $count ++;
755
+ if ($count > 1 ) {
756
+ $yy++;
757
+ $yyyy++;
758
+ }
759
+ $options[ $yy ] = $yyyy;
760
+ }
761
+
762
+ foreach ( $options as $key => $value ) {
763
+ echo '<option value="' . $key . '"';
764
+ if ($selected == $key ) { echo ' selected="selected"';
765
+ }
766
+ echo '>' . $value . '</option>';
767
+ }
768
+
769
+ }
770
+
771
+ }
772
  endif;
addons/cash-creds/abstracts/index.php CHANGED
@@ -1,3 +1,3 @@
1
  <?php
2
  // Silence is golden.
3
- ?>
1
  <?php
2
  // Silence is golden.
3
+ ?>
addons/cash-creds/assets/css/admin-style.css CHANGED
@@ -1,88 +1,88 @@
1
  .type-cashcred_withdrawal .cashcred_Approved{
2
- background-color: #008505;
3
- padding: 5px;
4
- border: 1px solid #008906;
5
- color: white;
6
- border-radius: 5px;
7
  }
8
  .type-cashcred_withdrawal .cashcred_Pending{
9
- background-color: #f6cb4a;
10
- padding: 5px;
11
- border: 1px solid #cc9900;
12
- color: white;
13
- border-radius: 5px;
14
  }
15
  .type-cashcred_withdrawal .cashcred_Cancelled{
16
- background-color: #bd2419;
17
- padding: 5px;
18
- border: 1px solid #a70b00;
19
- color: white;
20
- border-radius: 5px;
21
  }
22
  .cashcred_bages {
23
- margin-top: 10px;
24
  }
25
  .history li {
26
- padding: 6px;
27
- background-color: #f7f7f7;
28
- border: 1px solid #c9c9c9;
29
- border-radius: 10px;
30
- -webkit-box-shadow: 0px 1px 1px 0px rgba(0,0,0,0.35);
31
- -moz-box-shadow: 0px 1px 1px 0px rgba(0,0,0,0.35);
32
- box-shadow: 0px 1px 1px 0px rgba(0,0,0,0.35);
33
  }
34
 
35
  #cashcred-comments .history li time {
36
- font-weight: 600;
37
  }
38
 
39
  .readonly_fields[readonly]{
40
- opacity: 0.6;
41
  }
42
 
43
  #cashcred-comments .history p {
44
- border-top: 1px solid silver;
45
- margin-top: 5px;
46
- background-color: #e7e7e7;
47
- padding: 7px;
48
- border-radius: 6px;
49
  }
50
 
51
 
52
  #cashcred-developer-log pre {
53
- white-space: pre-wrap;
54
- white-space: -moz-pre-wrap;
55
- white-space: -pre-wrap;
56
- white-space: -o-pre-wrap;
57
- word-wrap: break-word;
58
- background-color: #e6e6e6;
59
- padding: 10px;
60
- border: solid 1px #c8c8c8;
61
- border-radius: 5px;
62
  }
63
 
64
  #payment_gateway_detail input.form-control {
65
- width: 100%;
66
  }
67
  #payment_gateway_detail .inside{ padding: 4px;}
68
  .cashcred_panel {
69
- background-color: #e6e6e6;
70
- padding: 10px;
71
- border: 1px solid #c9c9c9;
72
- margin-bottom: 5px;
73
  }
74
  #cashcred_withdrawal_request .row select ,#cashcred_withdrawal_request .row input{
75
- width: 100%;
76
  }
77
  #cashcred-payment-status .spinner
78
  {
79
- display:none;
80
  }
81
  #cashcred-payment-status .spinner.is-active {
82
- display:block;
83
- float: left;
84
- position: absolute;
85
- left: 10px;
86
  }
87
  #payment_response{
88
  display:none;
1
  .type-cashcred_withdrawal .cashcred_Approved{
2
+ background-color: #008505;
3
+ padding: 5px;
4
+ border: 1px solid #008906;
5
+ color: white;
6
+ border-radius: 5px;
7
  }
8
  .type-cashcred_withdrawal .cashcred_Pending{
9
+ background-color: #f6cb4a;
10
+ padding: 5px;
11
+ border: 1px solid #cc9900;
12
+ color: white;
13
+ border-radius: 5px;
14
  }
15
  .type-cashcred_withdrawal .cashcred_Cancelled{
16
+ background-color: #bd2419;
17
+ padding: 5px;
18
+ border: 1px solid #a70b00;
19
+ color: white;
20
+ border-radius: 5px;
21
  }
22
  .cashcred_bages {
23
+ margin-top: 10px;
24
  }
25
  .history li {
26
+ padding: 6px;
27
+ background-color: #f7f7f7;
28
+ border: 1px solid #c9c9c9;
29
+ border-radius: 10px;
30
+ -webkit-box-shadow: 0px 1px 1px 0px rgba(0,0,0,0.35);
31
+ -moz-box-shadow: 0px 1px 1px 0px rgba(0,0,0,0.35);
32
+ box-shadow: 0px 1px 1px 0px rgba(0,0,0,0.35);
33
  }
34
 
35
  #cashcred-comments .history li time {
36
+ font-weight: 600;
37
  }
38
 
39
  .readonly_fields[readonly]{
40
+ opacity: 0.6;
41
  }
42
 
43
  #cashcred-comments .history p {
44
+ border-top: 1px solid silver;
45
+ margin-top: 5px;
46
+ background-color: #e7e7e7;
47
+ padding: 7px;
48
+ border-radius: 6px;
49
  }
50
 
51
 
52
  #cashcred-developer-log pre {
53
+ white-space: pre-wrap;
54
+ white-space: -moz-pre-wrap;
55
+ white-space: -pre-wrap;
56
+ white-space: -o-pre-wrap;
57
+ word-wrap: break-word;
58
+ background-color: #e6e6e6;
59
+ padding: 10px;
60
+ border: solid 1px #c8c8c8;
61
+ border-radius: 5px;
62
  }
63
 
64
  #payment_gateway_detail input.form-control {
65
+ width: 100%;
66
  }
67
  #payment_gateway_detail .inside{ padding: 4px;}
68
  .cashcred_panel {
69
+ background-color: #e6e6e6;
70
+ padding: 10px;
71
+ border: 1px solid #c9c9c9;
72
+ margin-bottom: 5px;
73
  }
74
  #cashcred_withdrawal_request .row select ,#cashcred_withdrawal_request .row input{
75
+ width: 100%;
76
  }
77
  #cashcred-payment-status .spinner
78
  {
79
+ display:none;
80
  }
81
  #cashcred-payment-status .spinner.is-active {
82
+ display:block;
83
+ float: left;
84
+ position: absolute;
85
+ left: 10px;
86
  }
87
  #payment_response{
88
  display:none;
addons/cash-creds/assets/css/index.php CHANGED
@@ -1,3 +1,3 @@
1
  <?php
2
  // Silence is golden.
3
- ?>
1
  <?php
2
  // Silence is golden.
3
+ ?>
addons/cash-creds/assets/css/withdraw.css CHANGED
@@ -1,17 +1,17 @@
1
  #cashcred {
2
- width: 100%;
3
  }
4
 
5
  #cashcred * {
6
- box-sizing: border-box;
7
  }
8
 
9
  #cashcred ul.cashcred-nav-tabs li {
10
- display: inline-block;
11
- padding: 10px;
12
- position: relative;
13
- border: 1px solid #e9e9e9;
14
- margin-right: 5px;
15
  margin-bottom: 5px;
16
  }
17
 
@@ -27,12 +27,12 @@
27
  }
28
 
29
  #cashcred #cashcred_tab_content .cashcred-tab {
30
- border: 1px solid #e9e9e9;
31
- padding: 5px;
32
- width: 100%;
33
- margin-top: 5px;
34
- padding-right: 10px;
35
- padding-left: 10px;
36
  }
37
 
38
  #cashcred .form-group label {
@@ -53,8 +53,8 @@
53
  }
54
 
55
  #cashcred input[type=submit] {
56
- margin-top: 10px;
57
- margin-bottom: 5px;
58
  }
59
 
60
  #cashcred input[type=submit]:hover {
@@ -62,35 +62,35 @@
62
  }
63
 
64
  #cashcred select {
65
- cursor: pointer;
66
  }
67
 
68
  #cashcred_total{
69
- text-align: right;
70
- margin-top: 15px;
71
- margin-bottom: 15px;
72
- border-bottom: 3px double #cccccc;
73
- border-top: 3px double #cccccc;
74
- padding: 10px;
75
- min-width: 140px;
76
- float: right;
77
  }
78
 
79
  div#submit_button, .amount_label{
80
- float: left;
81
  }
82
 
83
  .cashcred-tab{
84
- display:none;
85
  }
86
 
87
  .cashcred-min {
88
- font-style: italic;
89
  }
90
 
91
  .cashcred_gateway_notice {
92
- display: none;
93
- color: red;
94
  font-size: smaller;
95
  }
96
 
1
  #cashcred {
2
+ width: 100%;
3
  }
4
 
5
  #cashcred * {
6
+ box-sizing: border-box;
7
  }
8
 
9
  #cashcred ul.cashcred-nav-tabs li {
10
+ display: inline-block;
11
+ padding: 10px;
12
+ position: relative;
13
+ border: 1px solid #e9e9e9;
14
+ margin-right: 5px;
15
  margin-bottom: 5px;
16
  }
17
 
27
  }
28
 
29
  #cashcred #cashcred_tab_content .cashcred-tab {
30
+ border: 1px solid #e9e9e9;
31
+ padding: 5px;
32
+ width: 100%;
33
+ margin-top: 5px;
34
+ padding-right: 10px;
35
+ padding-left: 10px;
36
  }
37
 
38
  #cashcred .form-group label {
53
  }
54
 
55
  #cashcred input[type=submit] {
56
+ margin-top: 10px;
57
+ margin-bottom: 5px;
58
  }
59
 
60
  #cashcred input[type=submit]:hover {
62
  }
63
 
64
  #cashcred select {
65
+ cursor: pointer;
66
  }
67
 
68
  #cashcred_total{
69
+ text-align: right;
70
+ margin-top: 15px;
71
+ margin-bottom: 15px;
72
+ border-bottom: 3px double #cccccc;
73
+ border-top: 3px double #cccccc;
74
+ padding: 10px;
75
+ min-width: 140px;
76
+ float: right;
77
  }
78
 
79
  div#submit_button, .amount_label{
80
+ float: left;
81
  }
82
 
83
  .cashcred-tab{
84
+ display:none;
85
  }
86
 
87
  .cashcred-min {
88
+ font-style: italic;
89
  }
90
 
91
  .cashcred_gateway_notice {
92
+ display: none;
93
+ color: red;
94
  font-size: smaller;
95
  }
96
 
addons/cash-creds/assets/images/index.php CHANGED
@@ -1,3 +1,3 @@
1
  <?php
2
  // Silence is golden.
3
- ?>
1
  <?php
2
  // Silence is golden.
3
+ ?>
addons/cash-creds/assets/index.php CHANGED
@@ -1,3 +1,3 @@
1
  <?php
2
  // Silence is golden.
3
- ?>
1
  <?php
2
  // Silence is golden.
3
+ ?>
addons/cash-creds/assets/js/index.php CHANGED
@@ -1,3 +1,3 @@
1
  <?php
2
  // Silence is golden.
3
- ?>
1
  <?php
2
  // Silence is golden.
3
+ ?>
addons/cash-creds/assets/js/withdraw.js CHANGED
@@ -1,185 +1,208 @@
1
  /**
2
  * CashCred Withdraw
3
- * @since 2.0
 
4
  * @version 1.0
5
  */
6
- jQuery(function($){
7
-
8
- $(document).ready(function() {
9
-
10
-
11
-
12
- if ( $( "#cashcred_pay_method" ).length ) {
13
- exchange_calculation();
14
- display_cashcred_gateway_notice();
15
- }
16
-
17
- $( "#cashcred_point_type" ).change(function() {
18
- exchange_calculation();
19
- });
20
-
21
- $( "#cashcred_pay_method" ).change(function() {
22
- exchange_calculation();
23
- display_cashcred_gateway_notice();
24
- });
25
-
26
- $( '.mycred-cashcred-form' ).on( 'keyup change', '#withdraw_points', function( e ){
 
 
 
 
 
 
 
27
 
28
- exchange_calculation();
29
-
30
- });
31
-
32
-
33
- $( 'body' ).on( 'submit', '.mycred-cashcred-form', function( e ){
34
-
35
-
36
-
37
- withdraw_points = $( "#withdraw_points" ).val();
38
- if( parseFloat( withdraw_points ) <= 0 ) {
39
- e.preventDefault();
40
- }
41
- });
42
-
43
- $('.cashcred-nav-tabs li').click( function(){
44
- var id = $(this).attr('id');
45
- $('.cashcred-nav-tabs li').removeClass('active');
46
- $('.cashcred-tab').hide();
47
- $(this).addClass('active');
48
- $('#'+ id + 'c').show();
49
- });
50
-
51
- $('.cashcred-tab').hide();
52
- $('#tab1c').show();
53
-
54
- var elementType = $('#cashcred_save_settings').prop('nodeName');
55
-
56
- if ( elementType != 'INPUT' ) {
57
- first_tab_active = $("#cashcred_save_settings option:first").val();
58
- $('.cashcred_panel').hide();
59
- $('#panel_'+first_tab_active).show();
60
- }
61
-
62
- $("select#cashcred_save_settings").change( function(){
63
- id = $(this).val();
64
- $('.cashcred_panel').hide();
65
- $('#panel_'+id).show();
66
- });
67
-
68
- });
69
-
70
- function exchange_calculation(){
71
-
72
- cashcred_point_type = $( "#cashcred_point_type" ).val();
73
- cashcred_pay_method = $( "#cashcred_pay_method" ).val();
74
- withdraw_points = $( "#withdraw_points" ).val();
75
- cashcred_fee = cashcred_fee_setting( cashcred_point_type, withdraw_points );
76
- currency_code = cashcred.exchange[cashcred_pay_method].currency;
77
- conversion_rate = cashcred.exchange[cashcred_pay_method].point_type[cashcred_point_type];
78
-
79
- min = cashcred.exchange[cashcred_pay_method].min;
80
- max = cashcred.exchange[cashcred_pay_method].max
81
-
82
- amount = withdraw_points * conversion_rate;
83
-
84
- $( "#withdraw_points" ).attr({"max" : max , "min" : min });
85
-
86
- $( '.cashcred-min span' ).html( min );
87
-
88
- $( "#cashcred_currency_symbol" ).html(currency_code);
89
- $( "#cashcred_total_amount" ).html(amount.toFixed(2).replace(/\d(?=(\d{3})+\.)/g, '$&,'));
90
-
91
- }
92
-
93
- function display_cashcred_gateway_notice() {
94
-
95
- if ( cashcred.gateway_notices[ $('#cashcred_pay_method').val() ] ) {
96
-
97
- $('.cashcred_gateway_notice').show();
98
-
99
- }
100
- else {
101
-
102
- $('.cashcred_gateway_notice').hide();
103
-
104
- }
105
-
106
- }
107
-
108
- function cashcred_fee_setting( point_type, withdraw_points ) {
109
-
110
- if ( cashcred_data.cashcred_setting.use == 1 ) {
111
- var fee = 0;
112
- var ctype = cashcred_data.cashcred_setting.types[point_type];
113
- var by = cashcred_data.cashcred_setting.types[point_type].by;
114
- var fee_amount = cashcred_data.cashcred_setting.types[point_type].amount;
115
- var max_cap = cashcred_data.cashcred_setting.types[point_type].max_cap;
116
- var min_cap = cashcred_data.cashcred_setting.types[point_type].min_cap;
117
- var presentation = cashcred_data.cashcred_setting.types[point_type].presentation;
118
-
119
- //formats
120
- decimals = cashcred_data.format[point_type].decimals;
121
- decimal_sep = cashcred_data.format[point_type].separators.decimal;
122
- thousand_sep = cashcred_data.format[point_type].separators.thousand;
123
- if( withdraw_points > 0 ) {
124
- fee = fee_amount;
125
- if( by == 'percent' ){
126
- fee = ( ( fee_amount / 100 ) * withdraw_points );
127
- fee_amount = fee_amount + '%';
128
- }
129
-
130
- if( min_cap != 0 )
131
- fee = ( parseInt(fee) + parseInt(min_cap) );
132
-
133
-
134
- if ( max_cap != 0 && fee > max_cap )
135
- fee = max_cap;
136
-
137
- presentation = presentation.replace( "%fee%", fee_amount );
138
- presentation = presentation.replace( "%min%", min_cap );
139
- presentation = presentation.replace( "%max%", max_cap );
140
- presentation = presentation.replace( "%total%", mycred_number_format( fee, decimals, decimal_sep, thousand_sep ) );
141
-
142
- $('.cashcred-fee').show();
143
- $( '.cashcred-fee span' ).html( presentation );
144
- }
145
-
146
- }
147
- else {
148
-
149
- $('.cashcred-fee').hide();
150
-
151
- }
152
- }
153
-
154
- function mycred_number_format ( number, decimals, dec_point, thousands_sep ) {
155
-
156
- // Strip all characters but numerical ones.
157
- number = (number + '').replace(/[^0-9+\-Ee.]/g, '');
158
- var n = !isFinite(+number) ? 0 : +number,
159
- prec = !isFinite(+decimals) ? 0 : Math.abs(decimals),
160
- sep = (typeof thousands_sep === 'undefined') ? ',' : thousands_sep,
161
- dec = (typeof dec_point === 'undefined') ? '.' : dec_point,
162
- s = '',
163
- toFixedFix = function (n, prec) {
164
- var k = Math.pow(10, prec);
165
- return '' + Math.round(n * k) / k;
166
- };
167
-
168
- // Fix for IE parseFloat(0.55).toFixed(0) = 0;
169
- s = (prec ? toFixedFix(n, prec) : '' + Math.round(n)).split('.');
170
- if (s[0].length > 3) {
171
- s[0] = s[0].replace(/\B(?=(?:\d{3})+(?!\d))/g, sep);
172
- }
173
- if ((s[1] || '').length < prec) {
174
- s[1] = s[1] || '';
175
- s[1] += new Array(prec - s[1].length + 1).join('0');
176
- }
177
-
178
- return s.join(dec) ;
179
- }
180
-
181
-
182
- });
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
183
 
184
 
185
 
1
  /**
2
  * CashCred Withdraw
3
+ *
4
+ * @since 2.0
5
  * @version 1.0
6
  */
7
+ jQuery(
8
+ function ($) {
9
+
10
+ $(document).ready(
11
+ function () {
12
+
13
+
14
+
15
+ if ($("#cashcred_pay_method").length ) {
16
+ exchange_calculation();
17
+ display_cashcred_gateway_notice();
18
+ }
19
+
20
+ $("#cashcred_point_type").change(
21
+ function () {
22
+ exchange_calculation();
23
+ }
24
+ );
25
+
26
+ $("#cashcred_pay_method").change(
27
+ function () {
28
+ exchange_calculation();
29
+ display_cashcred_gateway_notice();
30
+ }
31
+ );
32
+
33
+ $('.mycred-cashcred-form').on(
34
+ 'keyup change', '#withdraw_points', function ( e ) {
35
 
36
+ exchange_calculation();
37
+
38
+ }
39
+ );
40
+
41
+
42
+ $('body').on(
43
+ 'submit', '.mycred-cashcred-form', function ( e ) {
44
+
45
+
46
+
47
+ withdraw_points = $("#withdraw_points").val();
48
+ if(parseFloat(withdraw_points) <= 0 ) {
49
+ e.preventDefault();
50
+ }
51
+ }
52
+ );
53
+
54
+ $('.cashcred-nav-tabs li').click(
55
+ function () {
56
+ var id = $(this).attr('id');
57
+ $('.cashcred-nav-tabs li').removeClass('active');
58
+ $('.cashcred-tab').hide();
59
+ $(this).addClass('active');
60
+ $('#'+ id + 'c').show();
61
+ }
62
+ );
63
+
64
+ $('.cashcred-tab').hide();
65
+ $('#tab1c').show();
66
+
67
+ var elementType = $('#cashcred_save_settings').prop('nodeName');
68
+
69
+ if (elementType != 'INPUT' ) {
70
+ first_tab_active = $("#cashcred_save_settings option:first").val();
71
+ $('.cashcred_panel').hide();
72
+ $('#panel_'+first_tab_active).show();
73
+ }
74
+
75
+ $("select#cashcred_save_settings").change(
76
+ function () {
77
+ id = $(this).val();
78
+ $('.cashcred_panel').hide();
79
+ $('#panel_'+id).show();
80
+ }
81
+ );
82
+
83
+ }
84
+ );
85
+
86
+ function exchange_calculation()
87
+ {
88
+
89
+ cashcred_point_type = $("#cashcred_point_type").val();
90
+ cashcred_pay_method = $("#cashcred_pay_method").val();
91
+ withdraw_points = $("#withdraw_points").val();
92
+ cashcred_fee = cashcred_fee_setting(cashcred_point_type, withdraw_points);
93
+ currency_code = cashcred.exchange[cashcred_pay_method].currency;
94
+ conversion_rate = cashcred.exchange[cashcred_pay_method].point_type[cashcred_point_type];
95
+
96
+ min = cashcred.exchange[cashcred_pay_method].min;
97
+ max = cashcred.exchange[cashcred_pay_method].max
98
+
99
+ amount = withdraw_points * conversion_rate;
100
+
101
+ $("#withdraw_points").attr({"max" : max , "min" : min });
102
+
103
+ $('.cashcred-min span').html(min);
104
+
105
+ $("#cashcred_currency_symbol").html(currency_code);
106
+ $("#cashcred_total_amount").html(amount.toFixed(2).replace(/\d(?=(\d{3})+\.)/g, '$&,'));
107
+
108
+ }
109
+
110
+ function display_cashcred_gateway_notice()
111
+ {
112
+
113
+ if (cashcred.gateway_notices[ $('#cashcred_pay_method').val() ] ) {
114
+
115
+ $('.cashcred_gateway_notice').show();
116
+
117
+ }
118
+ else {
119
+
120
+ $('.cashcred_gateway_notice').hide();
121
+
122
+ }
123
+
124
+ }
125
+
126
+ function cashcred_fee_setting( point_type, withdraw_points )
127
+ {
128
+
129
+ if (cashcred_data.cashcred_setting.use == 1 ) {
130
+ var fee = 0;
131
+ var ctype = cashcred_data.cashcred_setting.types[point_type];
132
+ var by = cashcred_data.cashcred_setting.types[point_type].by;
133
+ var fee_amount = cashcred_data.cashcred_setting.types[point_type].amount;
134
+ var max_cap = cashcred_data.cashcred_setting.types[point_type].max_cap;
135
+ var min_cap = cashcred_data.cashcred_setting.types[point_type].min_cap;
136
+ var presentation = cashcred_data.cashcred_setting.types[point_type].presentation;
137
+
138
+ //formats
139
+ decimals = cashcred_data.format[point_type].decimals;
140
+ decimal_sep = cashcred_data.format[point_type].separators.decimal;
141
+ thousand_sep = cashcred_data.format[point_type].separators.thousand;
142
+ if(withdraw_points > 0 ) {
143
+ fee = fee_amount;
144
+ if(by == 'percent' ) {
145
+ fee = ( ( fee_amount / 100 ) * withdraw_points );
146
+ fee_amount = fee_amount + '%';
147
+ }
148
+
149
+ if(min_cap != 0 ) {
150
+ fee = ( parseInt(fee) + parseInt(min_cap) );
151
+ }
152
+
153
+
154
+ if (max_cap != 0 && fee > max_cap ) {
155
+ fee = max_cap;
156
+ }
157
+
158
+ presentation = presentation.replace("%fee%", fee_amount);
159
+ presentation = presentation.replace("%min%", min_cap);
160
+ presentation = presentation.replace("%max%", max_cap);
161
+ presentation = presentation.replace("%total%", mycred_number_format(fee, decimals, decimal_sep, thousand_sep));
162
+
163
+ $('.cashcred-fee').show();
164
+ $('.cashcred-fee span').html(presentation);
165
+ }
166
+
167
+ }
168
+ else {
169
+
170
+ $('.cashcred-fee').hide();
171
+
172
+ }
173
+ }
174
+
175
+ function mycred_number_format( number, decimals, dec_point, thousands_sep )
176
+ {
177
+
178
+ // Strip all characters but numerical ones.
179
+ number = (number + '').replace(/[^0-9+\-Ee.]/g, '');
180
+ var n = !isFinite(+number) ? 0 : +number,
181
+ prec = !isFinite(+decimals) ? 0 : Math.abs(decimals),
182
+ sep = (typeof thousands_sep === 'undefined') ? ',' : thousands_sep,
183
+ dec = (typeof dec_point === 'undefined') ? '.' : dec_point,
184
+ s = '',
185
+ toFixedFix = function (n, prec) {
186
+ var k = Math.pow(10, prec);
187
+ return '' + Math.round(n * k) / k;
188
+ };
189
+
190
+ // Fix for IE parseFloat(0.55).toFixed(0) = 0;
191
+ s = (prec ? toFixedFix(n, prec) : '' + Math.round(n)).split('.');
192
+ if (s[0].length > 3) {
193
+ s[0] = s[0].replace(/\B(?=(?:\d{3})+(?!\d))/g, sep);
194
+ }
195
+ if ((s[1] || '').length < prec) {
196
+ s[1] = s[1] || '';
197
+ s[1] += new Array(prec - s[1].length + 1).join('0');
198
+ }
199
+
200
+ return s.join(dec);
201
+ }
202
+
203
+
204
+ }
205
+ );
206
 
207
 
208
 
addons/cash-creds/gateways/bank-transfer.php CHANGED
@@ -1,306 +1,330 @@
1
  <?php
2
- if ( ! defined( 'myCRED_VERSION' ) ) exit;
 
3
 
4
  /**
5
  * myCRED_cashcred_Bank_Transfer class
6
  * Manual payment gateway - bank transfers
7
- * @since 1.7
 
8
  * @version 1.1
9
  */
10
- if ( ! class_exists( 'myCRED_cashcred_Bank_Transfer' ) ) :
11
- class myCRED_cashcred_Bank_Transfer extends myCRED_Cash_Payment_Gateway {
12
-
13
- /**
14
- * Construct
15
- */
16
- public function __construct( $gateway_prefs ) {
17
-
18
- $types = mycred_get_types();
19
-
20
- $default_exchange = array();
21
-
22
- foreach ( $types as $type => $label ) $default_exchange[ $type ] = 1;
23
-
24
- parent::__construct( array(
25
- 'id' => 'bank',
26
- 'label' => 'Bank Transfer',
27
- 'documentation' => 'http://codex.mycred.me/chapter-iii/buycred/payment-gateways/bank-transfers/',
28
- 'gateway_logo_url' => '',
29
- 'defaults' => array(
30
- 'enable_additional_notes' => '',
31
- 'additional_notes' => '',
32
- 'minimum_amount' => '',
33
- 'maximum_amount' => '',
34
- 'currency' => 'EUR',
35
- 'exchange' => $default_exchange
36
- )
37
- ), $gateway_prefs );
38
-
39
- }
40
-
41
- /**
42
- * Process Handler
43
- * @since 1.0
44
- * @version 1.0
45
- */
46
- public function process( $post = false ) {
47
-
48
- $time = current_time( 'mysql' );
49
-
50
- update_post_meta( $post, 'cashcred_payment_transfer_date', $time );
51
-
52
- return array (
53
- 'status' => true ,
54
- 'message' => 'Amount transfer successfully to your bank account',
55
- 'date' => $time
56
- );
 
 
 
 
 
 
 
57
 
58
- }
59
-
60
- /**
61
- * Results Handler
62
- * @since 1.0
63
- * @version 1.0
64
- */
65
- public function returning() {
66
-
67
- add_filter( 'mycred_setup_gateways', array( $this, 'relable_gateway' ) );
68
-
69
- }
70
-
71
- /**
72
- * Admin Init Handler
73
- * @since 1.7
74
- * @version 1.0
75
- */
76
- public function admin_init() {
77
-
78
- add_filter( 'mycred_setup_gateways', array( $this, 'relable_gateway' ) );
79
-
80
- }
81
-
82
- /**
83
- * Results Handler
84
- * @since 1.7.6
85
- * @version 1.0
86
- */
87
- public function relable_gateway( $installed ) {
88
-
89
- if ( ! empty( $this->prefs['title'] ) && $this->prefs['title'] != $installed['bank']['title'] )
90
- $installed['bank']['title'] = $this->prefs['title'];
91
-
92
- return $installed;
93
-
94
- }
95
-
96
-
97
- /**
98
- * Preferences
99
- * @since 1.0
100
- * @version 1.0
101
- */
102
- public function preferences() {
103
-
104
- $prefs = $this->prefs;
105
- ?>
 
 
 
 
 
 
 
 
 
106
  <div class="row">
107
- <div class="col-lg-6 col-md-6 col-sm-12 col-xs-12">
108
- <h3><?php _e( 'Details', 'mycred' ); ?></h3>
109
-
110
- <div class="form-group">
111
- <label for="<?php echo $this->field_id( 'minimum_amount' ); ?>"><?php _e( 'Minimum Points Withdrawal', 'mycred' ); ?></label>
112
- <input type="number" name="<?php echo $this->field_name( 'minimum_amount' ); ?>" id="<?php echo $this->field_id( 'minimum_amount' ); ?>" min="1" value="<?php echo esc_attr( $prefs['minimum_amount'] ); ?>" class="form-control" />
113
- </div>
114
-
115
- <div class="form-group">
116
- <label for="<?php echo $this->field_id( 'maximum_amount' ); ?>"><?php _e( 'Maximum Points Withdrawal', 'mycred' ); ?></label>
117
- <input type="number" name="<?php echo $this->field_name( 'maximum_amount' ); ?>" id="<?php echo $this->field_id( 'maximum_amount' ); ?>" value="<?php echo esc_attr( $prefs['maximum_amount'] ); ?>" class="form-control" />
118
- </div>
119
-
120
- <div class="form-group">
121
- <label for="<?php echo $this->field_id( 'enable_additional_notes' ); ?>"><input type="checkbox" name="<?php echo $this->field_name( 'enable_additional_notes' ); ?>" id="<?php echo $this->field_id( 'enable_additional_notes' ); ?>" value="1"<?php checked( $prefs['enable_additional_notes'], 1 ); ?> /> <?php _e( 'Enable Additional Notes', 'mycred' ); ?></label>
122
- </div>
123
-
124
- </div>
125
- <div class="col-lg-6 col-md-6 col-sm-12 col-xs-12">
126
- <h3><?php _e( 'Setup', 'mycred' ); ?></h3>
127
-
128
- <div class="form-group">
129
- <label for="<?php echo $this->field_id( 'currency' ); ?>"><?php _e( 'Currency', 'mycred' ); ?></label>
130
- <input type="text" name="<?php echo $this->field_name( 'currency' ); ?>" id="<?php echo $this->field_id( 'currency' ); ?>" value="<?php echo esc_attr( $prefs['currency'] ); ?>" class="form-control" />
131
- </div>
132
-
133
- <div class="form-group">
134
- <label><?php _e( 'Exchange Rates', 'mycred' ); ?></label>
135
-
136
- <?php $this->exchange_rate_setup(); ?>
137
-
138
- </div>
139
-
140
- </div>
141
  </div>
142
 
143
  <div class="row" id="additional_notes_show">
144
- <div class="col-lg-12 col-md-12 col-sm-12 col-xs-12">
145
- <div class="form-group">
146
- <label for="cashcredbanktransferaccount"><?php _e( 'Additional notes', 'mycred' ); ?></label>
147
- <?php wp_editor( $prefs['additional_notes'], 'cashcredbanktransferaccount', array( 'textarea_name' => $this->field_name( 'additional_notes' ), 'textarea_rows' => 10 ) ); ?>
148
- </div>
149
- </div>
150
  </div>
151
  <script>
152
- // on change additional-notes div hide
153
- jQuery(function() {
154
-
155
- jQuery('#mycred-gateway-prefs-bank-enable-additional-notes').change(function() {
156
-
157
- if (jQuery(this).is(':checked')) {
158
-
159
- jQuery('#additional_notes_show').slideDown('fast');
160
-
161
- }
162
- else {
163
-
164
- jQuery('#additional_notes_show').slideUp(400);
165
-
166
- }
167
-
168
- });
169
 
170
  });
171
 
172
- // onload additional-notes div hide
173
- if (jQuery('#mycred-gateway-prefs-bank-enable-additional-notes').is(':checked')) {
174
-
175
- jQuery('#additional_notes_show').slideDown('fast');
176
-
177
- }
178
- else {
179
-
180
- jQuery('#additional_notes_show').slideUp(400);
181
-
182
- }
183
  </script>
184
- <?php
185
- }
186
-
187
- public function cashcred_payment_settings( $data ) {
188
-
189
- $mycred_pref_cashcreds = mycred_get_option( 'mycred_pref_cashcreds' , false );
190
-
191
- $fields = $this->form_fields();
192
-
193
- $bank_form = new CashCred_Gateway_Fields( $data, $fields );
194
-
195
- ?>
196
- <div id="panel_<?php echo $data;?>" class="cashcred_panel">
197
-
198
- <h3><?php echo apply_filters( 'mycred_cashcred_bank_transfer_title', __( 'Bank account details', 'mycred' ) ); ?></h3>
199
-
200
- <?php if( isset( $mycred_pref_cashcreds["gateway_prefs"]["bank"]["enable_additional_notes"] ) ): ?>
201
- <div class="form-group">
202
- <p><?php echo $mycred_pref_cashcreds["gateway_prefs"]["bank"]["additional_notes"]; ?></p>
203
- </div>
204
- <?php endif;?>
205
-
206
- <?php $bank_form->generate_form(); ?>
207
-
208
- </div>
209
-
210
- <?php
211
- }
212
-
213
-
214
- /**
215
- * Bank Transfer Form Fields
216
- * @since 2.0
217
- * @version 1.0
218
- */
219
- public function form_fields() {
220
-
221
- $gateway_fields = array(
222
- 'ac_name' => array(
223
- 'type' => 'text',
224
- 'lable' => 'Account name',
225
- 'classes' => 'form-control',
226
- 'placeholder' => 'Account name',
227
- ),
228
- 'ac_number' => array(
229
- 'type' => 'text',
230
- 'lable' => 'Account number',
231
- 'classes' => 'form-control',
232
- 'placeholder' => 'Account number',
233
- ),
234
- 'ac_code' => array(
235
- 'type' => 'text',
236
- 'lable' => 'Sort code',
237
- 'classes' => 'form-control',
238
- 'placeholder' => 'Sort code',
239
- ),
240
- 'ba_name' => array(
241
- 'type' => 'text',
242
- 'lable' => 'Bank name',
243
- 'classes' => 'form-control',
244
- 'placeholder' => 'Bank name',
245
- ),
246
- 'ro_number' => array(
247
- 'type' => 'text',
248
- 'lable' => 'Routing number',
249
- 'classes' => 'form-control',
250
- 'placeholder' => 'Routing number',
251
- ),
252
- 'ib_name' => array(
253
- 'type' => 'text',
254
- 'lable' => 'IBAN',
255
- 'classes' => 'form-control',
256
- 'placeholder' => 'IBAN',
257
- ),
258
- 'sw_code' => array(
259
- 'type' => 'text',
260
- 'lable' => 'Swift code',
261
- 'classes' => 'form-control',
262
- 'placeholder' => 'Swift code',
263
- )
264
- );
265
-
266
- return apply_filters( 'mycred_cashcred_bank_transfer_fields', $gateway_fields );
267
-
268
- }
269
-
270
-
271
- /**
272
- * Sanatize Prefs
273
- * @since 1.0
274
- * @version 1.0
275
- */
276
- public function sanitise_preferences( $data ) {
277
-
278
- $new_data = array();
279
-
280
- $new_data['additional_notes'] = sanitize_text_field( $data['additional_notes'] );
281
-
282
- if( isset( $data['enable_additional_notes'] ) ) {
283
-
284
- $new_data['enable_additional_notes'] = sanitize_text_field( $data['enable_additional_notes'] );
285
-
286
- }
287
- $new_data['minimum_amount'] = sanitize_text_field( $data['minimum_amount'] );
288
- $new_data['maximum_amount'] = sanitize_text_field( $data['maximum_amount'] );
289
- $new_data['additional_notes'] = wp_kses_post( $data['additional_notes'] );
290
- $new_data['currency'] = sanitize_text_field( $data['currency'] );
291
-
292
- // If exchange is less then 1 we must start with a zero
293
- if ( isset( $data['exchange'] ) ) {
294
- foreach ( (array) $data['exchange'] as $type => $rate ) {
295
- if ( $rate != 1 && in_array( substr( $rate, 0, 1 ), array( '.', ',' ) ) )
296
- $data['exchange'][ $type ] = (float) '0' . $rate;
297
- }
298
- }
299
- $new_data['exchange'] = $data['exchange'];
300
-
301
- return $new_data;
302
-
303
- }
304
-
305
- }
 
 
 
 
 
 
306
  endif;
1
  <?php
2
+ if (! defined('myCRED_VERSION') ) { exit;
3
+ }
4
 
5
  /**
6
  * myCRED_cashcred_Bank_Transfer class
7
  * Manual payment gateway - bank transfers
8
+ *
9
+ * @since 1.7
10
  * @version 1.1
11
  */
12
+ if (! class_exists('myCRED_cashcred_Bank_Transfer') ) :
13
+ class myCRED_cashcred_Bank_Transfer extends myCRED_Cash_Payment_Gateway
14
+ {
15
+
16
+ /**
17
+ * Construct
18
+ */
19
+ public function __construct( $gateway_prefs )
20
+ {
21
+
22
+ $types = mycred_get_types();
23
+
24
+ $default_exchange = array();
25
+
26
+ foreach ( $types as $type => $label ) { $default_exchange[ $type ] = 1;
27
+ }
28
+
29
+ parent::__construct(
30
+ array(
31
+ 'id' => 'bank',
32
+ 'label' => 'Bank Transfer',
33
+ 'documentation' => 'http://codex.mycred.me/chapter-iii/buycred/payment-gateways/bank-transfers/',
34
+ 'gateway_logo_url' => '',
35
+ 'defaults' => array(
36
+ 'enable_additional_notes' => '',
37
+ 'additional_notes' => '',
38
+ 'minimum_amount' => '',
39
+ 'maximum_amount' => '',
40
+ 'currency' => 'EUR',
41
+ 'exchange' => $default_exchange
42
+ )
43
+ ), $gateway_prefs
44
+ );
45
+
46
+ }
47
+
48
+ /**
49
+ * Process Handler
50
+ *
51
+ * @since 1.0
52
+ * @version 1.0
53
+ */
54
+ public function process( $post = false )
55
+ {
56
+
57
+ $time = current_time('mysql');
58
+
59
+ update_post_meta($post, 'cashcred_payment_transfer_date', $time);
60
+
61
+ return array (
62
+ 'status' => true ,
63
+ 'message' => 'Amount transfer successfully to your bank account',
64
+ 'date' => $time
65
+ );
66
 
67
+ }
68
+
69
+ /**
70
+ * Results Handler
71
+ *
72
+ * @since 1.0
73
+ * @version 1.0
74
+ */
75
+ public function returning()
76
+ {
77
+
78
+ add_filter('mycred_setup_gateways', array( $this, 'relable_gateway' ));
79
+
80
+ }
81
+
82
+ /**
83
+ * Admin Init Handler
84
+ *
85
+ * @since 1.7
86
+ * @version 1.0
87
+ */
88
+ public function admin_init()
89
+ {
90
+
91
+ add_filter('mycred_setup_gateways', array( $this, 'relable_gateway' ));
92
+
93
+ }
94
+
95
+ /**
96
+ * Results Handler
97
+ *
98
+ * @since 1.7.6
99
+ * @version 1.0
100
+ */
101
+ public function relable_gateway( $installed )
102
+ {
103
+
104
+ if (! empty($this->prefs['title']) && $this->prefs['title'] != $installed['bank']['title'] ) {
105
+ $installed['bank']['title'] = $this->prefs['title'];
106
+ }
107
+
108
+ return $installed;
109
+
110
+ }
111
+
112
+
113
+ /**
114
+ * Preferences
115
+ *
116
+ * @since 1.0
117
+ * @version 1.0
118
+ */
119
+ public function preferences()
120
+ {
121
+
122
+ $prefs = $this->prefs;
123
+ ?>
124
  <div class="row">
125
+ <div class="col-lg-6 col-md-6 col-sm-12 col-xs-12">
126
+ <h3><?php _e('Details', 'mycred'); ?></h3>
127
+
128
+ <div class="form-group">
129
+ <label for="<?php echo $this->field_id('minimum_amount'); ?>"><?php _e('Minimum Points Withdrawal', 'mycred'); ?></label>
130
+ <input type="number" name="<?php echo $this->field_name('minimum_amount'); ?>" id="<?php echo $this->field_id('minimum_amount'); ?>" min="1" value="<?php echo esc_attr($prefs['minimum_amount']); ?>" class="form-control" />
131
+ </div>
132
+
133
+ <div class="form-group">
134
+ <label for="<?php echo $this->field_id('maximum_amount'); ?>"><?php _e('Maximum Points Withdrawal', 'mycred'); ?></label>
135
+ <input type="number" name="<?php echo $this->field_name('maximum_amount'); ?>" id="<?php echo $this->field_id('maximum_amount'); ?>" value="<?php echo esc_attr($prefs['maximum_amount']); ?>" class="form-control" />
136
+ </div>
137
+
138
+ <div class="form-group">
139
+ <label for="<?php echo $this->field_id('enable_additional_notes'); ?>"><input type="checkbox" name="<?php echo $this->field_name('enable_additional_notes'); ?>" id="<?php echo $this->field_id('enable_additional_notes'); ?>" value="1"<?php checked($prefs['enable_additional_notes'], 1); ?> /> <?php _e('Enable Additional Notes', 'mycred'); ?></label>
140
+ </div>
141
+
142
+ </div>
143
+ <div class="col-lg-6 col-md-6 col-sm-12 col-xs-12">
144
+ <h3><?php _e('Setup', 'mycred'); ?></h3>
145
+
146
+ <div class="form-group">
147
+ <label for="<?php echo $this->field_id('currency'); ?>"><?php _e('Currency', 'mycred'); ?></label>
148
+ <input type="text" name="<?php echo $this->field_name('currency'); ?>" id="<?php echo $this->field_id('currency'); ?>" value="<?php echo esc_attr($prefs['currency']); ?>" class="form-control" />
149
+ </div>
150
+
151
+ <div class="form-group">
152
+ <label><?php _e('Exchange Rates', 'mycred'); ?></label>
153
+
154
+ <?php $this->exchange_rate_setup(); ?>
155
+
156
+ </div>
157
+
158
+ </div>
159
  </div>
160
 
161
  <div class="row" id="additional_notes_show">
162
+ <div class="col-lg-12 col-md-12 col-sm-12 col-xs-12">
163
+ <div class="form-group">
164
+ <label for="cashcredbanktransferaccount"><?php _e('Additional notes', 'mycred'); ?></label>
165
+ <?php wp_editor($prefs['additional_notes'], 'cashcredbanktransferaccount', array( 'textarea_name' => $this->field_name('additional_notes'), 'textarea_rows' => 10 )); ?>
166
+ </div>
167
+ </div>
168
  </div>
169
  <script>
170
+ // on change additional-notes div hide
171
+ jQuery(function() {
172
+
173
+ jQuery('#mycred-gateway-prefs-bank-enable-additional-notes').change(function() {
174
+
175
+ if (jQuery(this).is(':checked')) {
176
+
177
+ jQuery('#additional_notes_show').slideDown('fast');
178
+
179
+ }
180
+ else {
181
+
182
+ jQuery('#additional_notes_show').slideUp(400);
183
+
184
+ }
185
+
186
+ });
187
 
188
  });
189
 
190
+ // onload additional-notes div hide
191
+ if (jQuery('#mycred-gateway-prefs-bank-enable-additional-notes').is(':checked')) {
192
+
193
+ jQuery('#additional_notes_show').slideDown('fast');
194
+
195
+ }
196
+ else {
197
+
198
+ jQuery('#additional_notes_show').slideUp(400);
199
+
200
+ }
201
  </script>
202
+ <?php
203
+ }
204
+
205
+ public function cashcred_payment_settings( $data )
206
+ {
207
+
208
+ $mycred_pref_cashcreds = mycred_get_option('mycred_pref_cashcreds', false);
209
+
210
+ $fields = $this->form_fields();
211
+
212
+ $bank_form = new CashCred_Gateway_Fields($data, $fields);
213
+
214
+ ?>
215
+ <div id="panel_<?php echo $data;?>" class="cashcred_panel">
216
+
217
+ <h3><?php echo apply_filters('mycred_cashcred_bank_transfer_title', __('Bank account details', 'mycred')); ?></h3>
218
+
219
+ <?php if(isset($mycred_pref_cashcreds["gateway_prefs"]["bank"]["enable_additional_notes"]) ) : ?>
220
+ <div class="form-group">
221
+ <p><?php echo $mycred_pref_cashcreds["gateway_prefs"]["bank"]["additional_notes"]; ?></p>
222
+ </div>
223
+ <?php endif;?>
224
+
225
+ <?php $bank_form->generate_form(); ?>
226
+
227
+ </div>
228
+
229
+ <?php
230
+ }
231
+
232
+
233
+ /**
234
+ * Bank Transfer Form Fields
235
+ *
236
+ * @since 2.0
237
+ * @version 1.0
238
+ */
239
+ public function form_fields()
240
+ {
241
+
242
+ $gateway_fields = array(
243
+ 'ac_name' => array(
244
+ 'type' => 'text',
245
+ 'lable' => 'Account name',
246
+ 'classes' => 'form-control',
247
+ 'placeholder' => 'Account name',
248
+ ),
249
+ 'ac_number' => array(
250
+ 'type' => 'text',
251
+ 'lable' => 'Account number',
252
+ 'classes' => 'form-control',
253
+ 'placeholder' => 'Account number',
254
+ ),
255
+ 'ac_code' => array(
256
+ 'type' => 'text',
257
+ 'lable' => 'Sort code',
258
+ 'classes' => 'form-control',
259
+ 'placeholder' => 'Sort code',
260
+ ),
261
+ 'ba_name' => array(
262
+ 'type' => 'text',
263
+ 'lable' => 'Bank name',
264
+ 'classes' => 'form-control',
265
+ 'placeholder' => 'Bank name',
266
+ ),
267
+ 'ro_number' => array(
268
+ 'type' => 'text',
269
+ 'lable' => 'Routing number',
270
+ 'classes' => 'form-control',
271
+ 'placeholder' => 'Routing number',
272
+ ),
273
+ 'ib_name' => array(
274
+ 'type' => 'text',
275
+ 'lable' => 'IBAN',
276
+ 'classes' => 'form-control',
277
+ 'placeholder' => 'IBAN',
278
+ ),
279
+ 'sw_code' => array(
280
+ 'type' => 'text',
281
+ 'lable' => 'Swift code',
282
+ 'classes' => 'form-control',
283
+ 'placeholder' => 'Swift code',
284
+ )
285
+ );
286
+
287
+ return apply_filters('mycred_cashcred_bank_transfer_fields', $gateway_fields);
288
+
289
+ }
290
+
291
+
292
+ /**
293
+ * Sanatize Prefs
294
+ *
295
+ * @since 1.0
296
+ * @version 1.0
297
+ */
298
+ public function sanitise_preferences( $data )
299
+ {
300
+
301
+ $new_data = array();
302
+
303
+ $new_data['additional_notes'] = sanitize_text_field($data['additional_notes']);
304
+
305
+ if(isset($data['enable_additional_notes']) ) {
306
+
307
+ $new_data['enable_additional_notes'] = sanitize_text_field($data['enable_additional_notes']);
308
+
309
+ }
310
+ $new_data['minimum_amount'] = sanitize_text_field($data['minimum_amount']);
311
+ $new_data['maximum_amount'] = sanitize_text_field($data['maximum_amount']);
312
+ $new_data['additional_notes'] = wp_kses_post($data['additional_notes']);
313
+ $new_data['currency'] = sanitize_text_field($data['currency']);
314
+
315
+ // If exchange is less then 1 we must start with a zero
316
+ if (isset($data['exchange']) ) {
317
+ foreach ( (array) $data['exchange'] as $type => $rate ) {
318
+ if ($rate != 1 && in_array(substr($rate, 0, 1), array( '.', ',' )) ) {
319
+ $data['exchange'][ $type ] = (float) '0' . $rate;
320
+ }
321
+ }
322
+ }
323
+ $new_data['exchange'] = $data['exchange'];
324
+
325
+ return $new_data;
326
+
327
+ }
328
+
329
+ }
330
  endif;
addons/cash-creds/gateways/index.php CHANGED
@@ -1,3 +1,3 @@
1
  <?php
2
  // Silence is golden.
3
- ?>
1
  <?php
2
  // Silence is golden.
3
+ ?>
addons/cash-creds/includes/cashcred-functions.php CHANGED
@@ -1,587 +1,641 @@
1
  <?php
2
- if ( ! defined( 'MYCRED_CASHCRED' ) ) exit;
 
3
 
4
  /**
5
  * Get Gateways
6
- * @since 1.8
 
7
  * @version 1.0
8
  */
9
- if ( ! function_exists( 'mycred_get_cashcred_gateways' ) ) :
10
- function mycred_get_cashcred_gateways() {
 
11
 
12
- $installed = array();
13
 
14
- // Bank Transfers
15
- $installed['bank'] = array(
16
- 'title' => __( 'Bank Transfer', 'mycred' ),
17
- 'documentation' => 'http://codex.mycred.me/chapter-iii/buycred/payment-gateways/bank-transfers/',
18
- 'callback' => array( 'myCRED_cashcred_Bank_Transfer' ),
19
- 'icon' => 'dashicons-admin-generic',
20
- 'sandbox' => false,
21
- 'external' => false,
22
- 'custom_rate' => true
23
- );
24
 
25
- return apply_filters( 'mycred_cashcred_setup_gateways', $installed );
26
 
27
- }
28
  endif;
29
 
30
  /**
31
  * Get buyCRED Setup
32
- * @since 1.8
 
33
  * @version 1.0
34
  */
35
- if ( ! function_exists( 'cashcred_get_requested_gateway_id' ) ) :
36
- function cashcred_get_requested_gateway_id() {
 
37
 
38
- $gateway_id = false;
39
-
40
- if ( isset( $_REQUEST['cashcred_pay_method'] ) && is_user_logged_in() )
41
- $gateway_id = trim( $_REQUEST['cashcred_pay_method'] );
 
42
 
43
- return apply_filters( 'mycred_gateway_id', $gateway_id );
44
 
45
- }
46
  endif;
47
 
48
- if ( ! function_exists( 'cashcred_register_fields' ) ) :
49
- function cashcred_register_fields($type,$name) {
50
-
51
- return 'cashcred_user_settings['.$type.']['.$name.']';
 
52
 
53
- }
54
  endif;
55
 
56
- if ( ! function_exists( 'cashcred_get_user_payment_details' ) ) :
57
- function cashcred_get_user_payment_details() {
 
58
 
59
- $user_id = get_current_user_id();
60
 
61
- if ( is_admin() ) {
62
- $post_id = get_the_ID();
63
- $user_id = check_site_get_post_meta( $post_id, 'from', true );
64
- }
65
- return mycred_get_user_meta( $user_id, 'cashcred_user_settings', '', true );
66
 
67
- }
68
  endif;
69
 
70
  /**
71
  * Display Messages
72
- * @since 1.9
 
73
  * @version 1.0
74
  *
75
  * $type = error, success
76
  */
77
- if ( ! function_exists( 'cashcred_display_message' ) ) :
78
- function cashcred_display_message() {
79
-
80
- $cashcred_notice = mycred_get_user_meta( get_current_user_id(), 'cashcred_notice', '', true );
81
-
82
- if( ! empty( $cashcred_notice ) ) {?>
83
- <p class="cashcred-notice">
84
- <?php echo $cashcred_notice; ?>
85
- </p>
86
- <?php
87
-
88
- if ( ! isset( $_POST['cashcred_withdraw_wpnonce'] ) )
89
- mycred_delete_user_meta( get_current_user_id(), 'cashcred_notice' );
90
- }
 
 
91
 
92
- }
93
  endif;
94
 
95
  /**
96
  * Return list of Gateways.
97
  * If a $gateway empty return all active gateways.
98
- * @since 1.9
 
99
  * @version 1.0
100
  */
101
- if ( ! function_exists( 'cashcred_get_usable_gateways' ) ) :
102
- function cashcred_get_usable_gateways( $gateways ) {
 
103
 
104
- global $cashcred_instance;
105
 
106
- $gateways_list = array();
107
 
108
- if ( empty( $cashcred_instance->active ) ) $gateways_list;
 
109
 
110
- if ( empty( $gateways ) ) {
111
 
112
- $gateways_list = $cashcred_instance->active;
113
-
114
- }
115
- else {
116
 
117
- $gateways = explode( ',', $gateways );
118
 
119
- foreach ( $gateways as $gateway_id ) {
120
 
121
- if ( array_key_exists( $gateway_id, $cashcred_instance->active ) )
122
- $gateways_list[ $gateway_id ] = $cashcred_instance->active[ $gateway_id ];
 
123
 
124
- }
125
 
126
- }
127
 
128
- return $gateways_list;
129
 
130
- }
131
  endif;
132
 
133
  /**
134
  * Return list of usable Point Types for the given user.
135
  * If a $types empty return all point types.
136
- * @since 1.9
 
137
  * @version 1.0
138
  */
139
- if ( ! function_exists( 'cashcred_get_point_types' ) ) :
140
- function cashcred_get_point_types( $types, $user_id ) {
 
141
 
142
- global $mycred_types;
143
 
144
- $point_types = array();
145
 
146
- $available_types = array_keys( $mycred_types );
147
 
148
- if ( ! empty( $types ) ) {
149
-
150
- $types = explode( ',', $types );
151
- $available_types = array_intersect( $available_types, $types );
152
 
153
- }
154
 
155
- foreach ( $available_types as $type_id ) {
156
-
157
- $mycred = mycred( $type_id );
158
-
159
- if ( ! $mycred->exclude_user( $user_id ) ) {
160
-
161
- $point_types[ $type_id ] = $mycred;
162
 
163
- }
164
 
165
- }
166
 
167
- return $point_types;
168
 
169
- }
170
  endif;
171
 
172
  /**
173
  * Return list of Point Types Which user have balance.
174
  * If a $types empty return all point types.
175
- * @since 1.9
 
176
  * @version 1.0
177
  */
178
- if ( ! function_exists( 'cashcred_is_user_have_balances' ) ) :
179
- function cashcred_is_user_have_balances( $point_types, $user_id ) {
 
180
 
181
- $usable_point_types = array();
182
 
183
- foreach ( $point_types as $point_type ) {
184
- if ( $point_type->get_users_balance( $user_id ) > 0 ) {
185
- $usable_point_types[ $point_type->cred_id ] = $point_type;
186
- }
187
- }
188
 
189
- return $usable_point_types;
190
 
191
- }
192
  endif;
193
 
194
  /**
195
  * Get Withdraw requests.
196
  * $status | Pending, Approved, Cancelled
197
- * @since 1.9
 
198
  * @version 1.0
199
  */
200
- if ( ! function_exists( 'cashcred_get_withdraw_requests' ) ) :
201
- function cashcred_get_withdraw_requests( $status = 'Pending' ) {
202
-
203
- $meta_query = array(
204
- array(
205
- 'key' => 'status',
206
- 'value' => $status,
207
- 'compare' => '='
208
- ),
209
- array(
210
- 'key' => 'from',
211
- 'value' => get_current_user_id(),
212
- 'compare' => '='
213
- )
214
- );
215
-
216
- if ( $status == 'Pending' ) {
217
- array_push(
218
- $meta_query,
219
- array(
220
- 'key' => 'points',
221
- 'value' => '',
222
- 'compare' => '!='
223
- )
224
- );
225
- }
226
-
227
- $args = array(
228
- 'post_type' => 'cashcred_withdrawal',
229
- 'post_status' => 'publish' ,
230
- 'posts_per_page' => -1,
231
- 'paged' => get_query_var('paged'),
232
- 'meta_query' => $meta_query
233
- );
234
-
235
- return get_posts( $args );
236
-
237
- }
 
238
  endif;
239
 
240
  /**
241
  * Get Pending Payment
242
- * @since 1.7
 
243
  * @version 1.0
244
  */
245
- if ( ! function_exists( 'cashcred_get_pending_payment_id' ) ) :
246
- function cashcred_get_pending_payment_id( $payment_id = NULL ) {
 
247
 
248
- if ( $payment_id === NULL || $payment_id == '' ) return false;
 
249
 
250
- // In case we are using the transaction ID instead of the post ID.
251
- $post_id = false;
252
- if ( ! is_numeric( $payment_id ) ) {
253
 
254
- $post = mycred_get_page_by_title( strtoupper( $payment_id ), OBJECT, 'buycred_payment' );
255
- if ( $post === NULL ) return false;
 
256
 
257
- $post_id = $post->ID;
258
 
259
- }
260
- else {
261
- $post_id = absint( $payment_id );
262
- }
263
 
264
- return $post_id;
265
 
266
- }
267
  endif;
268
 
269
  /**
270
  * Get Pending Payment
271
- * @since 1.7
 
272
  * @version 1.0
273
  */
274
- if ( ! function_exists( 'cashcred_get_payment_settings' ) ) :
275
- function cashcred_get_payment_settings( $payment_id = NULL ) {
276
-
277
- // Construct fake pending object ( when no pending payment object exists )
278
- if ( is_array( $payment_id ) ) {
279
-
280
- $pending_payment = new StdClass();
281
- $pending_payment->payment_id = false;
282
- $pending_payment->public_id = $payment_id['public_id'];
283
- $pending_payment->point_type = $payment_id['point_type'];
284
- $pending_payment->points = $payment_id['points'];
285
- $pending_payment->cost = $payment_id['cost'];
286
- $pending_payment->currency = $payment_id['currency'];
287
- $pending_payment->gateway_id = $payment_id['gateway_id'];
288
- $pending_payment->transaction_id = $payment_id['transaction_id'];
289
-
290
- }
291
-
292
- else {
293
-
294
- $payment_id = cashcred_get_pending_payment_id( $payment_id );
295
-
296
- if ( $payment_id === false ) return false;
297
-
298
- $pending_payment = new StdClass();
299
- $pending_payment->payment_id = absint( $payment_id );
300
- $pending_payment->public_id = get_the_title( $payment_id );
301
- $pending_payment->point_type = check_site_get_post_meta( $payment_id, 'point_type', true );
302
- $pending_payment->points = check_site_get_post_meta( $payment_id, 'points', true );
303
- $pending_payment->cost = check_site_get_post_meta( $payment_id, 'cost', true );
304
- $pending_payment->currency = check_site_get_post_meta( $payment_id, 'currency', true );
305
- $pending_payment->gateway_id = check_site_get_post_meta( $payment_id, 'gateway', true );
306
- $pending_payment->transaction_id = $pending_payment->public_id;
 
 
 
 
 
 
307
 
308
- }
309
-
310
- return apply_filters( 'cashcred_get_payment_settings', $pending_payment, $payment_id );
311
-
312
- }
313
  endif;
314
 
315
  /**
316
  * Add Pending Comment
317
- * @since 1.7
 
318
  * @version 1.1
319
  */
320
- if ( ! function_exists( 'cashcred_add_comment' ) ) :
321
- function cashcred_add_comment( $payment_id = NULL, $comment = NULL, $time = null ) {
322
-
323
- if ( ! MYCRED_CASHCRED_PENDING_COMMENTS ) return true;
324
-
325
- $post_id = cashcred_get_pending_payment_id( $payment_id );
326
- if ( $post_id === false ) return false;
327
-
328
- global $mycred_modules;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
329
 
330
- if ( $time === null || $time == 'now' )
331
- $time = current_time( 'mysql' );
332
-
333
- $author = 'cashcred';
334
- $gateway = mycred_get_post_meta( $post_id, 'gateway', true );
335
- $gateways = mycred_get_cashcred_gateways();
336
- $author_url = sprintf( 'buyCRED: %s %s', __( 'Unknown Gateway', 'mycred' ), $gateway );
337
- $author_email = apply_filters( 'mycred_buycred_comment_email', 'buycred-service@mycred.me' );
338
-
339
- if ( array_key_exists( $gateway, $gateways ) )
340
- $author = sprintf( 'buyCRED: %s %s', $gateways[ $gateway ]['title'], __( 'Gateway', 'mycred' ) );
341
-
342
- return wp_insert_comment( array(
343
- 'comment_post_ID' => $post_id,
344
- 'comment_author' => $author,
345
- 'comment_author_email' => $author_email,
346
- 'comment_content' => $comment,
347
- 'comment_type' => 'cashcred',
348
- 'comment_author_IP' => $_SERVER['REMOTE_ADDR'],
349
- 'comment_date' => $time,
350
- 'comment_approved' => 1,
351
- 'user_id' => 0
352
- ) );
353
-
354
- }
355
  endif;
356
 
357
  /**
358
  * buyCRED Gateway Constructor
359
- * @since 1.7
 
360
  * @version 1.1
361
  */
362
- if ( ! function_exists( 'cashcred_gateway' ) ) :
363
- function cashcred_gateway( $gateway_id = NULL ) {
 
364
 
365
- global $cashcred_gateway, $mycred_modules;
366
-
367
- if ( isset( $cashcred_gateway )
368
- && ( $cashcred_gateway instanceof myCRED_Cash_Payment_Gateway )
369
- && ( $gateway_id === $cashcred_gateway->id )
370
- ) {
371
- return $cashcred_gateway;
372
- }
373
 
374
- $cashcred_gateway = false;
375
- $installed = $mycred_modules['solo']['cashcred']->get();
376
- if ( array_key_exists( $gateway_id, $installed ) ) {
377
 
378
- $class = $installed[ $gateway_id ]['callback'][0];
379
 
380
- // Construct Gateway
381
- $cashcred_gateway = new $class( $mycred_modules['solo']['cashcred']->gateway_prefs );
382
 
383
- }
384
 
385
- return $cashcred_gateway;
386
 
387
- }
388
  endif;
389
 
390
  /**
391
  * CashCred_Gateway_Fields class
392
- * @since 2.0
 
393
  * @version 1.0
394
  */
395
- if ( ! class_exists( 'CashCred_Gateway_Fields' ) ) :
396
- class CashCred_Gateway_Fields {
 
397
 
398
- public $gateway_name;
399
 
400
- private $gateway_fields;
401
 
402
- /**
403
- * Construct
404
- * @since 2.0
405
- * @version 1.0
406
- */
407
- public function __construct( $name, $fields ) {
 
 
408
 
409
- $this->gateway_name = $name;
410
- $this->gateway_fields = $fields;
411
 
412
- $this->populate();
413
 
414
- }
415
 
416
- private function populate() {
 
417
 
418
- $user_payment_details = cashcred_get_user_payment_details();
419
 
420
- foreach( $this->gateway_fields as $gateway_field_id => $gateway_field_data ){
421
 
422
- $field_value = '';
423
 
424
- if ( ! empty( $user_payment_details[ $this->gateway_name ][ $gateway_field_id ] ) ) {
425
- $field_value = $user_payment_details[ $this->gateway_name ][ $gateway_field_id ];
426
- }
427
 
428
- $this->{ $gateway_field_id } = $field_value;
429
- }
430
 
431
- }
432
 
433
- public function field_name( $field_name ) {
 
434
 
435
- return "cashcred_user_settings[$this->gateway_name][$field_name]";
436
 
437
- }
438
 
439
- public function generate_form() {
 
440
 
441
- foreach ( $this->gateway_fields as $gateway_field_id => $gateway_field_data ): ?>
442
 
443
- <div class="form-group">
444
- <label><?php echo $gateway_field_data['lable']; ?></label>
445
- <input type="text" name="<?php echo $this->field_name( $gateway_field_id );?>" class="<?php echo $gateway_field_data['classes']; ?>" placeholder="<?php echo $gateway_field_data['placeholder']; ?>" value="<?php echo $this->{$gateway_field_id};?>">
446
- </div>
447
 
448
- <?php
449
- endforeach;
450
- }
451
 
452
- }
453
  endif;
454
 
455
- if ( ! function_exists( 'mycred_get_cashcred_settings' ) ) :
456
- function mycred_get_cashcred_settings() {
457
-
458
- $defaults = array(
459
- 'debugging' => 'disable',
460
- 'fees' => array(
461
- 'use' => 0,
462
- 'account' => 0,
463
- 'types' => array(
464
- 'mycred_default' => array(
465
- 'by' => 'percent',
466
- 'amount' => 0,
467
- 'min_cap' => 0,
468
- 'max_cap' => 0,
469
- 'presentation' => '( %fee% + %min% ) max. %max% = %total%'
470
- )
471
- )
472
- )
473
- );
474
-
475
- $settings = mycred_get_addon_settings( 'cashcreds' );
476
- $settings = wp_parse_args( $settings, $defaults );
477
-
478
- return apply_filters( 'mycred_get_cashcred_settings', $settings );
479
-
480
- }
 
481
  endif;
482
 
483
  /**
484
  * add postmeta by checking multisite and current blog
485
- * @param $post_id post id
486
- * @param $key meta key
487
- * @param bool $unique
 
488
  * @return mixed
489
  */
490
- if( !function_exists('check_site_add_post_meta') ):
491
- function check_site_add_post_meta( $post_id, $meta_key, $meta_value, $unique = false ) {
492
- if(is_multisite() AND !is_main_site() AND mycred_override_settings()) {
493
- return add_post_meta( $post_id, $meta_key, $meta_value, $unique );
494
- }
495
- else {
496
- return mycred_add_post_meta( $post_id, $meta_key, $meta_value, $unique );
497
- }
498
- }
 
499
  endif;
500
 
501
  /**
502
  * Returns postmeta by checking multisite and current blog
503
- * @param $post_id post id
504
- * @param $key meta key
505
- * @param bool $single
 
506
  * @return mixed
507
  */
508
- if( ! function_exists('check_site_get_post_meta') ):
509
- function check_site_get_post_meta( $post_id, $key, $single = false ) {
510
- if( is_multisite() AND !is_main_site() AND mycred_override_settings() ) {
511
- return get_post_meta( $post_id, $key, $single );
512
- }
513
- else {
514
- return mycred_get_post_meta( $post_id, $key, $single );
515
- }
516
- }
 
517
  endif;
518
 
519
  /**
520
  * cashCred get user's settings
521
  */
522
- if(!function_exists('cashcred_get_user_settings')):
523
- function cashcred_get_user_settings() {
 
524
  $check = '';
525
- $cashcred_user_setting = '';
526
-
527
- if( is_multisite() AND !is_main_site() AND mycred_override_settings() ) {
528
- $check = true;
529
- }
530
- else {
531
- $check = false;
532
- }
533
-
534
- if( $check ) {
535
- return 'cashcred_user_settings_' . get_current_blog_id();
536
- }
537
- else {
538
- return 'cashcred_user_settings';
539
- }
540
  }
541
  endif;
542
 
543
  /**
544
  *Checks site is multisite or not and update post meta
545
- * @param $post_id post id
546
- * @param $key meta key
547
- * @param $new_value new meta value
 
548
  * @return mixed
549
  */
550
- if( ! function_exists( 'check_site_update_post_meta' ) ):
551
- function check_site_update_post_meta( $post_id, $meta_key, $new_value ) {
 
552
  if(is_multisite() AND !is_main_site() AND mycred_override_settings()) {
553
- return update_post_meta( $post_id, $meta_key, $new_value );
554
- }
555
- else {
556
- return mycred_update_post_meta( $post_id, $meta_key, $new_value );
557
- }
558
  }
559
  endif;
560
 
561
  /**
562
  * Update payment status
563
  */
564
- if( ! function_exists( 'mycred_cashcred_update_status' ) ):
565
- function mycred_cashcred_update_status( $post_id, $meta_key, $meta_value ) {
566
- check_site_update_post_meta( $post_id, $meta_key, $meta_value );
567
-
568
- $mycred_pref_cashcreds = mycred_get_option( 'mycred_pref_cashcreds',false );
569
-
570
- $point_type = check_site_get_post_meta( $post_id, 'point_type', true );
571
- $points = check_site_get_post_meta( $post_id, 'points', true );
572
- $cashcred_pay_method = check_site_get_post_meta( $post_id, 'gateway' , true );
573
-
574
- $user_id = get_post_field( 'post_author', $post_id );
575
- $user_balance = mycred_get_users_balance( $user_id, $point_type );
576
- $payment_withdrawal_request = array(
577
- 'point_type' => $point_type,
578
- 'cashcred_pay_method' => $cashcred_pay_method,
579
- 'points' => $points,
580
- 'user_balance' => $user_balance,
581
- 'user_id' => $user_id,
582
- 'post_id' => $post_id
583
- );
584
-
585
- do_action( 'mycred_after_payment_request', $payment_withdrawal_request , $meta_value );
586
- }
587
- endif;
 
1
  <?php
2
+ if (! defined('MYCRED_CASHCRED') ) { exit;
3
+ }
4
 
5
  /**
6
  * Get Gateways
7
+ *
8
+ * @since 1.8
9
  * @version 1.0
10
  */
11
+ if (! function_exists('mycred_get_cashcred_gateways') ) :
12
+ function mycred_get_cashcred_gateways()
13
+ {
14
 
15
+ $installed = array();
16
 
17
+ // Bank Transfers
18
+ $installed['bank'] = array(
19
+ 'title' => __('Bank Transfer', 'mycred'),
20
+ 'documentation' => 'http://codex.mycred.me/chapter-iii/buycred/payment-gateways/bank-transfers/',
21
+ 'callback' => array( 'myCRED_cashcred_Bank_Transfer' ),
22
+ 'icon' => 'dashicons-admin-generic',
23
+ 'sandbox' => false,
24
+ 'external' => false,
25
+ 'custom_rate' => true
26
+ );
27
 
28
+ return apply_filters('mycred_cashcred_setup_gateways', $installed);
29
 
30
+ }
31
  endif;
32
 
33
  /**
34
  * Get buyCRED Setup
35
+ *
36
+ * @since 1.8
37
  * @version 1.0
38
  */
39
+ if (! function_exists('cashcred_get_requested_gateway_id') ) :
40
+ function cashcred_get_requested_gateway_id()
41
+ {
42
 
43
+ $gateway_id = false;
44
+
45
+ if (isset($_REQUEST['cashcred_pay_method']) && is_user_logged_in() ) {
46
+ $gateway_id = trim($_REQUEST['cashcred_pay_method']);
47
+ }
48
 
49
+ return apply_filters('mycred_gateway_id', $gateway_id);
50
 
51
+ }
52
  endif;
53
 
54
+ if (! function_exists('cashcred_register_fields') ) :
55
+ function cashcred_register_fields($type,$name)
56
+ {
57
+
58
+ return 'cashcred_user_settings['.$type.']['.$name.']';
59
 
60
+ }
61
  endif;
62
 
63
+ if (! function_exists('cashcred_get_user_payment_details') ) :
64
+ function cashcred_get_user_payment_details()
65
+ {
66
 
67
+ $user_id = get_current_user_id();
68
 
69
+ if (is_admin() ) {
70
+ $post_id = get_the_ID();
71
+ $user_id = check_site_get_post_meta($post_id, 'from', true);
72
+ }
73
+ return mycred_get_user_meta($user_id, 'cashcred_user_settings', '', true);
74
 
75
+ }
76
  endif;
77
 
78
  /**
79
  * Display Messages
80
+ *
81
+ * @since 1.9
82
  * @version 1.0
83
  *
84
  * $type = error, success
85
  */
86
+ if (! function_exists('cashcred_display_message') ) :
87
+ function cashcred_display_message()
88
+ {
89
+
90
+ $cashcred_notice = mycred_get_user_meta(get_current_user_id(), 'cashcred_notice', '', true);
91
+
92
+ if(! empty($cashcred_notice) ) {?>
93
+ <p class="cashcred-notice">
94
+ <?php echo $cashcred_notice; ?>
95
+ </p>
96
+ <?php
97
+
98
+ if (! isset($_POST['cashcred_withdraw_wpnonce']) ) {
99
+ mycred_delete_user_meta(get_current_user_id(), 'cashcred_notice');
100
+ }
101
+ }
102
 
103
+ }
104
  endif;
105
 
106
  /**
107
  * Return list of Gateways.
108
  * If a $gateway empty return all active gateways.
109
+ *
110
+ * @since 1.9
111
  * @version 1.0
112
  */
113
+ if (! function_exists('cashcred_get_usable_gateways') ) :
114
+ function cashcred_get_usable_gateways( $gateways )
115
+ {
116
 
117
+ global $cashcred_instance;
118
 
119
+ $gateways_list = array();
120
 
121
+ if (empty($cashcred_instance->active) ) { $gateways_list;
122
+ }
123
 
124
+ if (empty($gateways) ) {
125
 
126
+ $gateways_list = $cashcred_instance->active;
127
+
128
+ }
129
+ else {
130
 
131
+ $gateways = explode(',', $gateways);
132
 
133
+ foreach ( $gateways as $gateway_id ) {
134
 
135
+ if (array_key_exists($gateway_id, $cashcred_instance->active) ) {
136
+ $gateways_list[ $gateway_id ] = $cashcred_instance->active[ $gateway_id ];
137
+ }
138
 
139
+ }
140
 
141
+ }
142
 
143
+ return $gateways_list;
144
 
145
+ }
146
  endif;
147
 
148
  /**
149
  * Return list of usable Point Types for the given user.
150
  * If a $types empty return all point types.
151
+ *
152
+ * @since 1.9
153
  * @version 1.0
154
  */
155
+ if (! function_exists('cashcred_get_point_types') ) :
156
+ function cashcred_get_point_types( $types, $user_id )
157
+ {
158
 
159
+ global $mycred_types;
160
 
161
+ $point_types = array();
162
 
163
+ $available_types = array_keys($mycred_types);
164
 
165
+ if (! empty($types) ) {
166
+
167
+ $types = explode(',', $types);
168
+ $available_types = array_intersect($available_types, $types);
169
 
170
+ }
171
 
172
+ foreach ( $available_types as $type_id ) {
173
+
174
+ $mycred = mycred($type_id);
175
+
176
+ if (! $mycred->exclude_user($user_id) ) {
177
+
178
+ $point_types[ $type_id ] = $mycred;
179
 
180
+ }
181
 
182
+ }
183
 
184
+ return $point_types;
185
 
186
+ }
187
  endif;
188
 
189
  /**
190
  * Return list of Point Types Which user have balance.
191
  * If a $types empty return all point types.
192
+ *
193
+ * @since 1.9
194
  * @version 1.0
195
  */
196
+ if (! function_exists('cashcred_is_user_have_balances') ) :
197
+ function cashcred_is_user_have_balances( $point_types, $user_id )
198
+ {
199
 
200
+ $usable_point_types = array();
201
 
202
+ foreach ( $point_types as $point_type ) {
203
+ if ($point_type->get_users_balance($user_id) > 0 ) {
204
+ $usable_point_types[ $point_type->cred_id ] = $point_type;
205
+ }
206
+ }
207
 
208
+ return $usable_point_types;
209
 
210
+ }
211
  endif;
212
 
213
  /**
214
  * Get Withdraw requests.
215
  * $status | Pending, Approved, Cancelled
216
+ *
217
+ * @since 1.9
218
  * @version 1.0
219
  */
220
+ if (! function_exists('cashcred_get_withdraw_requests') ) :
221
+ function cashcred_get_withdraw_requests( $status = 'Pending' )
222
+ {
223
+
224
+ $meta_query = array(
225
+ array(
226
+ 'key' => 'status',
227
+ 'value' => $status,
228
+ 'compare' => '='
229
+ ),
230
+ array(
231
+ 'key' => 'from',
232
+ 'value' => get_current_user_id(),
233
+ 'compare' => '='
234
+ )
235
+ );
236
+
237
+ if ($status == 'Pending' ) {
238
+ array_push(
239
+ $meta_query,
240
+ array(
241
+ 'key' => 'points',
242
+ 'value' => '',
243
+ 'compare' => '!='
244
+ )
245
+ );
246
+ }
247
+
248
+ $args = array(
249
+ 'post_type' => 'cashcred_withdrawal',
250
+ 'post_status' => 'publish' ,
251
+ 'posts_per_page' => -1,
252
+ 'paged' => get_query_var('paged'),
253
+ 'meta_query' => $meta_query
254
+ );
255
+
256
+ return get_posts($args);
257
+
258
+ }
259
  endif;
260
 
261
  /**
262
  * Get Pending Payment
263
+ *
264
+ * @since 1.7
265
  * @version 1.0
266
  */
267
+ if (! function_exists('cashcred_get_pending_payment_id') ) :
268
+ function cashcred_get_pending_payment_id( $payment_id = null )
269
+ {
270
 
271
+ if ($payment_id === null || $payment_id == '' ) { return false;
272
+ }
273
 
274
+ // In case we are using the transaction ID instead of the post ID.
275
+ $post_id = false;
276
+ if (! is_numeric($payment_id) ) {
277
 
278
+ $post = mycred_get_page_by_title(strtoupper($payment_id), OBJECT, 'buycred_payment');
279
+ if ($post === null ) { return false;
280
+ }
281
 
282
+ $post_id = $post->ID;
283
 
284
+ }
285
+ else {
286
+ $post_id = absint($payment_id);
287
+ }
288
 
289
+ return $post_id;
290
 
291
+ }
292
  endif;
293
 
294
  /**
295
  * Get Pending Payment
296
+ *
297
+ * @since 1.7
298
  * @version 1.0
299
  */
300
+ if (! function_exists('cashcred_get_payment_settings') ) :
301
+ function cashcred_get_payment_settings( $payment_id = null )
302
+ {
303
+
304
+ // Construct fake pending object ( when no pending payment object exists )
305
+ if (is_array($payment_id) ) {
306
+
307
+ $pending_payment = new StdClass();
308
+ $pending_payment->payment_id = false;
309
+ $pending_payment->public_id = $payment_id['public_id'];
310
+ $pending_payment->point_type = $payment_id['point_type'];
311
+ $pending_payment->points = $payment_id['points'];
312
+ $pending_payment->cost = $payment_id['cost'];
313
+ $pending_payment->currency = $payment_id['currency'];
314
+ $pending_payment->gateway_id = $payment_id['gateway_id'];
315
+ $pending_payment->transaction_id = $payment_id['transaction_id'];
316
+
317
+ }
318
+
319
+ else {
320
+
321
+ $payment_id = cashcred_get_pending_payment_id($payment_id);
322
+
323
+ if ($payment_id === false ) { return false;
324
+ }
325
+
326
+ $pending_payment = new StdClass();
327
+ $pending_payment->payment_id = absint($payment_id);
328
+ $pending_payment->public_id = get_the_title($payment_id);
329
+ $pending_payment->point_type = check_site_get_post_meta($payment_id, 'point_type', true);
330
+ $pending_payment->points = check_site_get_post_meta($payment_id, 'points', true);
331
+ $pending_payment->cost = check_site_get_post_meta($payment_id, 'cost', true);
332
+ $pending_payment->currency = check_site_get_post_meta($payment_id, 'currency', true);
333
+ $pending_payment->gateway_id = check_site_get_post_meta($payment_id, 'gateway', true);
334
+ $pending_payment->transaction_id = $pending_payment->public_id;
335
+
336
+ }
337
+
338
+ return apply_filters('cashcred_get_payment_settings', $pending_payment, $payment_id);
339
 
340
+ }
 
 
 
 
341
  endif;
342
 
343
  /**
344
  * Add Pending Comment
345
+ *
346
+ * @since 1.7
347
  * @version 1.1
348
  */
349
+ if (! function_exists('cashcred_add_comment') ) :
350
+ function cashcred_add_comment( $payment_id = null, $comment = null, $time = null )
351
+ {
352
+
353
+ if (! MYCRED_CASHCRED_PENDING_COMMENTS ) { return true;
354
+ }
355
+
356
+ $post_id = cashcred_get_pending_payment_id($payment_id);
357
+ if ($post_id === false ) { return false;
358
+ }
359
+
360
+ global $mycred_modules;
361
+
362
+ if ($time === null || $time == 'now' ) {
363
+ $time = current_time('mysql');
364
+ }
365
+
366
+ $author = 'cashcred';
367
+ $gateway = mycred_get_post_meta($post_id, 'gateway', true);
368
+ $gateways = mycred_get_cashcred_gateways();
369
+ $author_url = sprintf('buyCRED: %s %s', __('Unknown Gateway', 'mycred'), $gateway);
370
+ $author_email = apply_filters('mycred_buycred_comment_email', 'buycred-service@mycred.me');
371
+
372
+ if (array_key_exists($gateway, $gateways) ) {
373
+ $author = sprintf('buyCRED: %s %s', $gateways[ $gateway ]['title'], __('Gateway', 'mycred'));
374
+ }
375
+
376
+ return wp_insert_comment(
377
+ array(
378
+ 'comment_post_ID' => $post_id,
379
+ 'comment_author' => $author,
380
+ 'comment_author_email' => $author_email,
381
+ 'comment_content' => $comment,
382
+ 'comment_type' => 'cashcred',
383
+ 'comment_author_IP' => sanitize_text_field($_SERVER['REMOTE_ADDR']),
384
+ 'comment_date' => $time,
385
+ 'comment_approved' => 1,
386
+ 'user_id' => 0
387
+ )
388
+ );
389
 
390
+ }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
391
  endif;
392
 
393
  /**
394
  * buyCRED Gateway Constructor
395
+ *
396
+ * @since 1.7
397
  * @version 1.1
398
  */
399
+ if (! function_exists('cashcred_gateway') ) :
400
+ function cashcred_gateway( $gateway_id = null )
401
+ {
402
 
403
+ global $cashcred_gateway, $mycred_modules;
404
+
405
+ if (isset($cashcred_gateway)
406
+ && ( $cashcred_gateway instanceof myCRED_Cash_Payment_Gateway )
407
+ && ( $gateway_id === $cashcred_gateway->id )
408
+ ) {
409
+ return $cashcred_gateway;
410
+ }
411
 
412
+ $cashcred_gateway = false;
413
+ $installed = $mycred_modules['solo']['cashcred']->get();
414
+ if (array_key_exists($gateway_id, $installed) ) {
415
 
416
+ $class = $installed[ $gateway_id ]['callback'][0];
417
 
418
+ // Construct Gateway
419
+ $cashcred_gateway = new $class($mycred_modules['solo']['cashcred']->gateway_prefs);
420
 
421
+ }
422
 
423
+ return $cashcred_gateway;
424
 
425
+ }
426
  endif;
427
 
428
  /**
429
  * CashCred_Gateway_Fields class
430
+ *
431
+ * @since 2.0
432
  * @version 1.0
433
  */
434
+ if (! class_exists('CashCred_Gateway_Fields') ) :
435
+ class CashCred_Gateway_Fields
436
+ {
437
 
438
+ public $gateway_name;
439
 
440
+ private $gateway_fields;
441
 
442
+ /**
443
+ * Construct
444
+ *
445
+ * @since 2.0
446
+ * @version 1.0
447
+ */
448
+ public function __construct( $name, $fields )
449
+ {
450
 
451
+ $this->gateway_name = $name;
452
+ $this->gateway_fields = $fields;
453
 
454
+ $this->populate();
455
 
456
+ }
457
 
458
+ private function populate()
459
+ {
460
 
461
+ $user_payment_details = cashcred_get_user_payment_details();
462
 
463
+ foreach( $this->gateway_fields as $gateway_field_id => $gateway_field_data ){
464
 
465
+ $field_value = '';
466
 
467
+ if (! empty($user_payment_details[ $this->gateway_name ][ $gateway_field_id ]) ) {
468
+ $field_value = $user_payment_details[ $this->gateway_name ][ $gateway_field_id ];
469
+ }
470
 
471
+ $this->{ $gateway_field_id } = $field_value;
472
+ }
473
 
474
+ }
475
 
476
+ public function field_name( $field_name )
477
+ {
478
 
479
+ return "cashcred_user_settings[$this->gateway_name][$field_name]";
480
 
481
+ }
482
 
483
+ public function generate_form()
484
+ {
485
 
486
+ foreach ( $this->gateway_fields as $gateway_field_id => $gateway_field_data ): ?>
487
 
488
+ <div class="form-group">
489
+ <label><?php echo $gateway_field_data['lable']; ?></label>
490
+ <input type="text" name="<?php echo $this->field_name($gateway_field_id);?>" class="<?php echo $gateway_field_data['classes']; ?>" placeholder="<?php echo $gateway_field_data['placeholder']; ?>" value="<?php echo $this->{$gateway_field_id};?>">
491
+ </div>
492
 
493
+ <?php
494
+ endforeach;
495
+ }
496
 
497
+ }
498
  endif;
499
 
500
+ if (! function_exists('mycred_get_cashcred_settings') ) :
501
+ function mycred_get_cashcred_settings()
502
+ {
503
+
504
+ $defaults = array(
505
+ 'debugging' => 'disable',
506
+ 'fees' => array(
507
+ 'use' => 0,
508
+ 'account' => 0,
509
+ 'types' => array(
510
+ 'mycred_default' => array(
511
+ 'by' => 'percent',
512
+ 'amount' => 0,
513
+ 'min_cap' => 0,
514
+ 'max_cap' => 0,
515
+ 'presentation' => '( %fee% + %min% ) max. %max% = %total%'
516
+ )
517
+ )
518
+ )
519
+ );
520
+
521
+ $settings = mycred_get_addon_settings('cashcreds');
522
+ $settings = wp_parse_args($settings, $defaults);
523
+
524
+ return apply_filters('mycred_get_cashcred_settings', $settings);
525
+
526
+ }
527
  endif;
528
 
529
  /**
530
  * add postmeta by checking multisite and current blog
531
+ *
532
+ * @param $post_id post id
533
+ * @param $key meta key
534
+ * @param bool $unique
535
  * @return mixed
536
  */
537
+ if(!function_exists('check_site_add_post_meta') ) :
538
+ function check_site_add_post_meta( $post_id, $meta_key, $meta_value, $unique = false )
539
+ {
540
+ if(is_multisite() AND !is_main_site() AND mycred_override_settings()) {
541
+ return add_post_meta($post_id, $meta_key, $meta_value, $unique);
542
+ }
543
+ else {
544
+ return mycred_add_post_meta($post_id, $meta_key, $meta_value, $unique);
545
+ }
546
+ }
547
  endif;
548
 
549
  /**
550
  * Returns postmeta by checking multisite and current blog
551
+ *
552
+ * @param $post_id post id
553
+ * @param $key meta key
554
+ * @param bool $single
555
  * @return mixed
556
  */
557
+ if(! function_exists('check_site_get_post_meta') ) :
558
+ function check_site_get_post_meta( $post_id, $key, $single = false )
559
+ {
560
+ if(is_multisite() AND !is_main_site() AND mycred_override_settings() ) {
561
+ return get_post_meta($post_id, $key, $single);
562
+ }
563
+ else {
564
+ return mycred_get_post_meta($post_id, $key, $single);
565
+ }
566
+ }
567
  endif;
568
 
569
  /**
570
  * cashCred get user's settings
571
  */
572
+ if(!function_exists('cashcred_get_user_settings')) :
573
+ function cashcred_get_user_settings()
574
+ {
575
  $check = '';
576
+ $cashcred_user_setting = '';
577
+
578
+ if(is_multisite() AND !is_main_site() AND mycred_override_settings() ) {
579
+ $check = true;
580
+ }
581
+ else {
582
+ $check = false;
583
+ }
584
+
585
+ if($check ) {
586
+ return 'cashcred_user_settings_' . get_current_blog_id();
587
+ }
588
+ else {
589
+ return 'cashcred_user_settings';
590
+ }
591
  }
592
  endif;
593
 
594
  /**
595
  *Checks site is multisite or not and update post meta
596
+ *
597
+ * @param $post_id post id
598
+ * @param $key meta key
599
+ * @param $new_value new meta value
600
  * @return mixed
601
  */
602
+ if(! function_exists('check_site_update_post_meta') ) :
603
+ function check_site_update_post_meta( $post_id, $meta_key, $new_value )
604
+ {
605
  if(is_multisite() AND !is_main_site() AND mycred_override_settings()) {
606
+ return update_post_meta($post_id, $meta_key, $new_value);
607
+ }
608
+ else {
609
+ return mycred_update_post_meta($post_id, $meta_key, $new_value);
610
+ }
611
  }
612
  endif;
613
 
614
  /**
615
  * Update payment status
616
  */
617
+ if(! function_exists('mycred_cashcred_update_status') ) :
618
+ function mycred_cashcred_update_status( $post_id, $meta_key, $meta_value )
619
+ {
620
+ check_site_update_post_meta($post_id, $meta_key, $meta_value);
621
+
622
+ $mycred_pref_cashcreds = mycred_get_option('mycred_pref_cashcreds', false);
623
+
624
+ $point_type = check_site_get_post_meta($post_id, 'point_type', true);
625
+ $points = check_site_get_post_meta($post_id, 'points', true);
626
+ $cashcred_pay_method = check_site_get_post_meta($post_id, 'gateway', true);
627
+
628
+ $user_id = get_post_field('post_author', $post_id);
629
+ $user_balance = mycred_get_users_balance($user_id, $point_type);
630
+ $payment_withdrawal_request = array(
631
+ 'point_type' => $point_type,
632
+ 'cashcred_pay_method' => $cashcred_pay_method,
633
+ 'points' => $points,
634
+ 'user_balance' => $user_balance,
635
+ 'user_id' => $user_id,
636
+ 'post_id' => $post_id
637
+ );
638
+
639
+ do_action('mycred_after_payment_request', $payment_withdrawal_request, $meta_value);
640
+ }
641
+ endif;
addons/cash-creds/includes/cashcred-shortcodes.php CHANGED
@@ -1,424 +1,446 @@
1
  <?php
2
- if ( ! defined( 'MYCRED_CASHCRED' ) ) exit;
 
3
 
4
  /**
5
  * Shortcode: mycred_cashcred
6
- * @see http://codex.mycred.me/shortcodes/mycred_cashcred/
7
- * @since 1.0
 
8
  * @version 1.3
9
  */
10
 
11
- if ( ! function_exists( 'mycred_render_cashcred' ) ) :
12
- function mycred_render_cashcred( $atts = array(), $content = '' ) {
13
-
14
- extract( shortcode_atts( array(
15
- 'button' => __( 'Submit Request', 'mycred' ),
16
- 'gateways' => '',
17
- 'types' => '',
18
- 'amount' => '',
19
- 'excluded' => 'You have excluded from this point type.',
20
- 'insufficient' => 'Insufficient Points for Withdrawal.'
21
- ), $atts, MYCRED_SLUG . '_cashcred' ) );
22
-
23
- // If we are not logged in
24
- if ( ! is_user_logged_in() ) return $content;
25
-
26
- global $cashcred_instance, $mycred_modules, $cashcred_withdraw;
27
-
28
- // Prepare
29
- $user_id = get_current_user_id();
30
-
31
- $gateways = cashcred_get_usable_gateways( $gateways );
32
-
33
- // Make sure we have a gateway we can use
34
- if ( empty( $gateways ) ) return __( 'No gateway available.', 'mycred' );
35
-
36
- $point_types = cashcred_get_point_types( $types, $user_id );
37
-
38
- //We are excluded
39
- if ( empty( $point_types ) ) return $excluded;
40
-
41
- $point_types = cashcred_is_user_have_balances( $point_types, $user_id );
42
-
43
- //Insufficient points for withdrawal.
44
- if ( empty( $point_types ) ) return $insufficient;
45
-
46
- // From this moment on, we need to indicate the shortcode usage for scripts and styles.
47
- $cashcred_withdraw = true;
48
-
49
- // Button Label
50
- $button_label = $point_types[ current(array_keys($point_types)) ]->template_tags_general( $button );
51
-
52
- $cashcred_setting = mycred_get_cashcred_settings();
53
-
54
- ob_start();
55
-
56
- $pending_withdrawal = cashcred_get_withdraw_requests('Pending');
57
- ?>
 
 
 
 
 
 
 
 
 
 
58
  <div id="cashcred">
59
- <ul class="cashcred-nav-tabs">
60
- <li id="tab1" class="active"><?php _e( 'Withdraw Request', 'mycred' ); ?></li>
61
- <li id="tab2"><?php _e( 'Approved Requests', 'mycred' ); ?></li>
62
- <li id="tab3"><?php _e( 'Cancelled Requests', 'mycred' ); ?></li>
63
- <li id="tab4"><?php _e( 'Payment Settings', 'mycred' ); ?></li>
64
- </ul>
65
- <div id="cashcred_tab_content">
66
- <!--------First tab--------->
67
- <div id="tab1c" class="cashcred-tab">
68
- <?php cashcred_display_message(); ?>
69
-
70
- <?php if( count( $pending_withdrawal ) > 0 ){ ?>
71
- <h4><?php echo "You have pending withdrawal"; ?></h4>
72
- <table>
73
- <thead>
74
- <tr>
75
- <th><span class="nobr">ID</span></th>
76
- <th><span class="nobr">Points</span></th>
77
- <?php
78
- if ( ! empty( $cashcred_setting['fees']['types'] ) ) {
79
- if ( $cashcred_setting['fees']['use'] == 1 ) { ?>
80
- <th><span class="nobr">Fee</span></th><?php
81
- }
82
- }?>
83
- <th><span class="nobr">Amount</span></th>
84
- <th><span class="nobr">Point Type</span></th>
85
- <th><span class="nobr">Gateway</span></th>
86
- <th><span class="nobr">Date</span></th>
87
- </tr>
88
- </thead>
89
- <tbody>
90
- <?php foreach( $pending_withdrawal as $post ):?>
91
- <tr>
92
- <td><?php echo $post->post_name; ?></td>
93
- <td><?php echo get_post_meta($post->ID,'points',true);?></td>
94
- <?php
95
- if ( ! empty( $cashcred_setting['fees']['types'] ) ) {
96
-
97
- if ( $cashcred_setting['fees']['use'] == 1 ) { ?>
98
-
99
- <td><?php
100
-
101
- $type_data = $cashcred_setting['fees']['types'][get_post_meta($post->ID,'point_type',true)];
102
-
103
- if ( $type_data['by'] == 'percent' ) {
104
- $fee = ( ( $type_data['amount'] / 100 ) * (int)get_post_meta($post->ID,'points',true) );
105
- }
106
- else{
107
- $fee = $type_data['amount'];
108
- }
109
-
110
- if( $type_data['min_cap'] != 0 )
111
- $fee = $fee + $type_data['min_cap'];
112
-
113
- if( $type_data['max_cap'] != 0 && $fee > $type_data['max_cap'] )
114
- $fee = $type_data['max_cap'];
115
-
116
- echo $fee; ?>
117
- </td><?php
118
- }
119
- }?>
120
- <td>
121
- <?php echo get_post_meta($post->ID,'currency',true). " " .get_post_meta($post->ID,'points',true) * get_post_meta($post->ID,'cost',true); ?>
122
- </td>
123
- <td><?php echo mycred_get_types()[get_post_meta($post->ID,'point_type',true)];?></td>
124
- <td>
125
- <?php
126
- $gateway = get_post_meta($post->ID,'gateway',true);
127
- $installed = $mycred_modules['solo']['cashcred']->get();
128
- if ( isset( $installed[ $gateway ] ) )
129
- echo $installed[ $gateway ]['title'];
130
- else
131
- echo $gateway;
132
- ?>
133
- </td>
134
- <td><?php echo $post->post_date; ?></td>
135
- </tr>
136
- <?php endforeach;?>
137
- </tbody>
138
- </table>
139
- <?php } else {
140
- $mycred_cashcred_gateway_notice = apply_filters( 'mycred_cashcred_gateway_notice', 'Selected gateway details are incomplete.' );
141
- ?>
142
-
143
- <div class="cashcred_gateway_notice"><?php _e( $mycred_cashcred_gateway_notice, 'mycred' ) ?></div>
144
-
145
- <form method="post" class="mycred-cashcred-form" action="">
146
-
147
- <?php wp_nonce_field( 'cashCred-withdraw-request', 'cashcred_withdraw_wpnonce' ); ?>
148
-
149
- <?php if( count( $point_types ) > 1 ) {?>
150
- <div class="form-group">
151
- <label for="gateway"><?php _e( 'Withdraw Point Type', 'mycred' ); ?></label>
152
- <select id="cashcred_point_type" name="cashcred_point_type" class="form-control">
153
- <?php
154
- foreach( $point_types as $point_type_id => $point_type_obj ) {
155
- echo '<option value="' . $point_type_id . '">' . esc_html( $point_type_obj->plural() ) . '</option>';
156
- }
157
- ?>
158
- </select>
159
- </div>
160
- <?php } else {?>
161
- <input type="hidden" id="cashcred_point_type" name="cashcred_point_type" value="<?php echo esc_attr( current(array_keys($point_types)) ); ?>" />
162
- <?php } ?>
163
-
164
- <?php if ( count( $gateways ) > 1 ) { ?>
165
- <div class="form-group">
166
- <label for="gateway"><?php _e( 'Withdrawal Payment Method', 'mycred' ); ?></label>
167
- <select id="cashcred_pay_method" name="cashcred_pay_method" class="form-control">
168
- <?php
169
- foreach ( $gateways as $gateway_id => $gateway_data ) {
170
- echo '<option value="' . esc_attr( $gateway_id ) . '">' . esc_html( $gateway_data['title'] ) . '</option>';
171
- }
172
- ?>
173
- </select>
174
- </div>
175
- <?php } else { ?>
176
- <input type="hidden" id="cashcred_pay_method" name="cashcred_pay_method" value="<?php echo esc_attr( current(array_keys($gateways)) ); ?>" />
177
- <?php } ?>
178
-
179
- <div class="form-group">
180
- <label><?php echo sprintf( __('Withdraw %s value', 'mycred'), $point_types[ current(array_keys($point_types)) ]->plural() ); ?></label>
181
- <?php
182
- $amount = ! empty( $amount ) ? floatval( $amount ) : 0;
183
- ?>
184
- <input type="number" id="withdraw_points" name="points" class="form-control" placeholder="0" value="<?php echo ! empty($amount) ? $amount : 0; ?>" required />
185
- <p class="cashcred-min"><?php echo __('Minimum Amount: ');?><span></span></p>
186
-
187
- <?php
188
-
189
- if ( ! empty( $cashcred_setting['fees'] ) ){
190
-
191
- if( $cashcred_setting['fees']['use'] == 1 ) { ?>
192
-
193
- <p class="cashcred-fee" ><?php echo __('Fee : '); ?>
194
-
195
- <span></span>
196
-
197
- </p> <?php
198
- }
199
-
200
- $format = array();
201
- foreach ($point_types as $key => $value) {
202
- $format[$key] = $point_types[$key]->core['format'];
203
-
204
- }
205
-
206
- wp_localize_script( 'cashcred-withdraw', 'cashcred_data',
207
- array(
208
- 'cashcred_setting' => $cashcred_setting['fees'],
209
- 'format' => $format,
210
- )
211
- );
212
-
213
- }
214
- ?>
215
- </div>
216
- <div class="mycred-cashcred-withdraw-form-footer">
217
- <div id="cashcred_total" class="form-group">
218
- <strong>
219
- <span class="amount_label">Amount:&nbsp;</span>
220
- <span id="cashcred_currency_symbol"></span>
221
- <span id="cashcred_total_amount"></span>
222
- </strong>
223
- </div>
224
- <div id="submit_button" class="form-group">
225
- <input type="submit" class="button" value="<?php echo $button_label; ?>" />
226
- </div>
227
- <div class="mycred-clearfix"></div>
228
- </div>
229
- </form>
230
- <?php } ?>
231
- </div>
232
- <!--------End First tab--------->
233
-
234
- <!--------Secound tab--------->
235
- <div id="tab2c" class="cashcred-tab">
236
- <h4>Approved Requests</h4>
237
- <?php
238
- $posts = cashcred_get_withdraw_requests('Approved');
239
- ?>
240
- <table>
241
- <thead>
242
- <tr>
243
- <th><span class="nobr">ID</span></th>
244
- <th><span class="nobr">Points</span></th>
245
- <?php
246
- if ( ! empty( $cashcred_setting['fees']['types'] ) ) {
247
- if ( $cashcred_setting['fees']['use'] == 1 ) { ?>
248
- <th><span class="nobr">Fee</span></th><?php
249
- }
250
- }?>
251
- <th><span class="nobr">Amount</span></th>
252
- <th><span class="nobr">Point Type</span></th>
253
- <th><span class="nobr">Gateway</span></th>
254
- <th><span class="nobr">Date</span></th>
255
- </tr>
256
- </thead>
257
- <tbody>
258
- <?php foreach($posts as $post) {?>
259
- <tr>
260
- <td><?php echo $post->post_name; ?></td>
261
- <td><?php echo get_post_meta($post->ID,'points',true);?></td>
262
- <?php
263
- if ( ! empty( $cashcred_setting['fees']['types'] ) ) {
264
-
265
- if ( $cashcred_setting['fees']['use'] == 1 ) { ?>
266
-
267
- <td><?php
268
-
269
- $type_data = $cashcred_setting['fees']['types'][get_post_meta($post->ID,'point_type',true)];
270
-
271
- if ( $type_data['by'] == 'percent' ) {
272
- $fee = ( ( $type_data['amount'] / 100 ) * (int)get_post_meta($post->ID,'points',true) );
273
- }
274
- else{
275
- $fee = $type_data['amount'];
276
- }
277
-
278
- if( $type_data['min_cap'] != 0 )
279
- $fee = $fee + $type_data['min_cap'];
280
-
281
- if( $type_data['max_cap'] != 0 && $fee > $type_data['max_cap'] )
282
- $fee = $type_data['max_cap'];
283
-
284
- echo $fee; ?>
285
- </td><?php
286
- }
287
- }?>
288
- <td>
289
- <?php echo get_post_meta($post->ID,'currency',true). " " .get_post_meta($post->ID,'points',true) * get_post_meta($post->ID,'cost',true);?>
290
- </td>
291
- <td><?php echo mycred_get_types()[get_post_meta($post->ID,'point_type',true)]; ?></td>
292
- <td>
293
- <?php
294
- $gateway = get_post_meta($post->ID,'gateway',true);
295
- $installed = $mycred_modules['solo']['cashcred']->get();
296
- if ( isset( $installed[ $gateway ] ) )
297
- echo $installed[ $gateway ]['title'];
298
- else
299
- echo $gateway;
300
- ?>
301
- </td>
302
- <td><?php echo $post->post_date; ?></td>
303
- </tr>
304
- <?php } ?>
305
- </tbody>
306
- </table>
307
- </div>
308
- <!--------End Secound tab--------->
309
-
310
- <!--------Third tab--------->
311
- <div id="tab3c" class="cashcred-tab">
312
- <h4>Cancelled Requests</h4>
313
- <?php
314
- $posts = cashcred_get_withdraw_requests('Cancelled');
315
- ?>
316
- <table>
317
- <thead>
318
- <tr>
319
- <th><span class="nobr">ID</span></th>
320
- <th><span class="nobr">Points</span></th>
321
- <?php
322
- if ( ! empty( $cashcred_setting['fees']['types'] ) ) {
323
- if ( $cashcred_setting['fees']['use'] == 1 ) { ?>
324
- <th><span class="nobr">Fee</span></th><?php
325
- }
326
- }?>
327
- <th><span class="nobr">Amount</span></th>
328
- <th><span class="nobr">Point Type</span></th>
329
- <th><span class="nobr">Gateway</span></th>
330
- <th><span class="nobr">Date</span></th>
331
- </tr>
332
- </thead>
333
- <tbody>
334
- <?php foreach($posts as $post) {?>
335
- <tr>
336
- <td><?php echo $post->post_name; ?></td>
337
-
338
- <td><?php echo get_post_meta($post->ID,'points',true);?></td>
339
- <?php
340
- if ( ! empty( $cashcred_setting['fees']['types'] ) ) {
341
-
342
- if ( $cashcred_setting['fees']['use'] == 1 ) { ?>
343
-
344
- <td><?php
345
-
346
- $type_data = $cashcred_setting['fees']['types'][get_post_meta($post->ID,'point_type',true)];
347
-
348
- if ( $type_data['by'] == 'percent' ) {
349
- $fee = ( ( $type_data['amount'] / 100 ) * (int)get_post_meta($post->ID,'points',true) );
350
- }
351
- else{
352
- $fee = $type_data['amount'];
353
- }
354
-
355
- if( $type_data['min_cap'] != 0 )
356
- $fee = $fee + $type_data['min_cap'];
357
-
358
- if( $type_data['max_cap'] != 0 && $fee > $type_data['max_cap'] )
359
- $fee = $type_data['max_cap'];
360
-
361
- echo $fee; ?>
362
- </td><?php
363
- }
364
- }?>
365
- <td>
366
- <?php echo get_post_meta($post->ID,'currency',true). " " .get_post_meta($post->ID,'points',true) * get_post_meta($post->ID,'cost',true);?>
367
- </td>
368
- <td><?php echo mycred_get_types()[get_post_meta($post->ID,'point_type',true)];?></td>
369
- <td>
370
- <?php
371
- $gateway = get_post_meta($post->ID,'gateway',true);
372
- $installed = $mycred_modules['solo']['cashcred']->get();
373
- if ( isset( $installed[ $gateway ] ) )
374
- echo $installed[ $gateway ]['title'];
375
- else
376
- echo $gateway;
377
- ?>
378
- </td>
379
- <td><?php echo $post->post_date; ?></td>
380
- </tr>
381
- <?php } ?>
382
- </tbody>
383
- </table>
384
- </div>
385
- <!--------End Third tab--------->
386
-
387
- <!--------Fourth tab--------->
388
- <div id="tab4c" class="cashcred-tab">
389
- <form action="" method="POST">
390
- <?php if ( count( $gateways ) > 1 ):?>
391
- <select class="form-control" name="cashcred_save_settings" id="cashcred_save_settings">
392
- <?php
393
- foreach ( $gateways as $key => $active_gateways_value ) {
394
- echo '<option value="' . $key . '"> '. $active_gateways_value['title'] .' </option>';
395
- }
396
- ?>
397
- </select>
398
- <?php else:?>
399
- <input type="hidden" name="cashcred_save_settings" id="cashcred_save_settings" value="<?php echo esc_attr( current(array_keys($gateways)) ); ?>" />
400
- <?php endif;?>
401
- <?php
402
- wp_nonce_field( 'cashCred-payment-settings', 'cashcred_settings_wpnonce' );
403
-
404
- foreach ( $gateways as $key => $active_gateways_value ) {
405
-
406
- $MyCred_payment_setting_call = new $active_gateways_value['callback'][0]($key);
407
- $MyCred_payment_setting_call->cashcred_payment_settings($key) ;
408
-
409
- }
410
- ?>
411
- <div id="cashcred_save_settings" class="form-group">
412
- <input type="submit" class="button" value="Save" />
413
- </div>
414
- </form>
415
- </div>
416
- <!--------End Fourth tab--------->
417
- </div>
 
 
 
 
 
 
 
 
 
 
418
  </div>
419
- <?php
420
- $content = ob_get_contents();
421
- ob_end_clean();
422
- return $content;
423
- }
424
- endif;
1
  <?php
2
+ if (! defined('MYCRED_CASHCRED') ) { exit;
3
+ }
4
 
5
  /**
6
  * Shortcode: mycred_cashcred
7
+ *
8
+ * @see http://codex.mycred.me/shortcodes/mycred_cashcred/
9
+ * @since 1.0
10
  * @version 1.3
11
  */
12
 
13
+ if (! function_exists('mycred_render_cashcred') ) :
14
+ function mycred_render_cashcred( $atts = array(), $content = '' )
15
+ {
16
+
17
+ extract(
18
+ shortcode_atts(
19
+ array(
20
+ 'button' => __('Submit Request', 'mycred'),
21
+ 'gateways' => '',
22
+ 'types' => '',
23
+ 'amount' => '',
24
+ 'excluded' => 'You have excluded from this point type.',
25
+ 'insufficient' => 'Insufficient Points for Withdrawal.'
26
+ ), $atts, MYCRED_SLUG . '_cashcred'
27
+ )
28
+ );
29
+
30
+ // If we are not logged in
31
+ if (! is_user_logged_in() ) { return $content;
32
+ }
33
+
34
+ global $cashcred_instance, $mycred_modules, $cashcred_withdraw;
35
+
36
+ // Prepare
37
+ $user_id = get_current_user_id();
38
+
39
+ $gateways = cashcred_get_usable_gateways($gateways);
40
+
41
+ // Make sure we have a gateway we can use
42
+ if (empty($gateways) ) {
43
+ return __('No gateway available.', 'mycred');
44
+ }
45
+
46
+ $point_types = cashcred_get_point_types($types, $user_id);
47
+
48
+ //We are excluded
49
+ if (empty($point_types) ) { return $excluded;
50
+ }
51
+
52
+ $point_types = cashcred_is_user_have_balances($point_types, $user_id);
53
+
54
+ //Insufficient points for withdrawal.
55
+ if (empty($point_types) ) { return $insufficient;
56
+ }
57
+
58
+ // From this moment on, we need to indicate the shortcode usage for scripts and styles.
59
+ $cashcred_withdraw = true;
60
+
61
+ // Button Label
62
+ $button_label = $point_types[ current(array_keys($point_types)) ]->template_tags_general($button);
63
+
64
+ $cashcred_setting = mycred_get_cashcred_settings();
65
+
66
+ ob_start();
67
+
68
+ $pending_withdrawal = cashcred_get_withdraw_requests('Pending');
69
+ ?>
70
  <div id="cashcred">
71
+ <ul class="cashcred-nav-tabs">
72
+ <li id="tab1" class="active"><?php _e('Withdraw Request', 'mycred'); ?></li>
73
+ <li id="tab2"><?php _e('Approved Requests', 'mycred'); ?></li>
74
+ <li id="tab3"><?php _e('Cancelled Requests', 'mycred'); ?></li>
75
+ <li id="tab4"><?php _e('Payment Settings', 'mycred'); ?></li>
76
+ </ul>
77
+ <div id="cashcred_tab_content">
78
+ <!--------First tab--------->
79
+ <div id="tab1c" class="cashcred-tab">
80
+ <?php cashcred_display_message(); ?>
81
+
82
+ <?php if(count($pending_withdrawal) > 0 ) { ?>
83
+ <h4><?php echo "You have pending withdrawal"; ?></h4>
84
+ <table>
85
+ <thead>
86
+ <tr>
87
+ <th><span class="nobr">ID</span></th>
88
+ <th><span class="nobr">Points</span></th>
89
+ <?php
90
+ if (! empty($cashcred_setting['fees']['types']) ) {
91
+ if ($cashcred_setting['fees']['use'] == 1 ) { ?>
92
+ <th><span class="nobr">Fee</span></th><?php
93
+ }
94
+ }?>
95
+ <th><span class="nobr">Amount</span></th>
96
+ <th><span class="nobr">Point Type</span></th>
97
+ <th><span class="nobr">Gateway</span></th>
98
+ <th><span class="nobr">Date</span></th>
99
+ </tr>
100
+ </thead>
101
+ <tbody>
102
+ <?php foreach( $pending_withdrawal as $post ):?>
103
+ <tr>
104
+ <td><?php echo $post->post_name; ?></td>
105
+ <td><?php echo get_post_meta($post->ID, 'points', true);?></td>
106
+ <?php
107
+ if (! empty($cashcred_setting['fees']['types']) ) {
108
+
109
+ if ($cashcred_setting['fees']['use'] == 1 ) { ?>
110
+
111
+ <td><?php
112
+
113
+ $type_data = $cashcred_setting['fees']['types'][get_post_meta($post->ID, 'point_type', true)];
114
+
115
+ if ($type_data['by'] == 'percent' ) {
116
+ $fee = ( ( $type_data['amount'] / 100 ) * (int)get_post_meta($post->ID, 'points', true) );
117
+ }
118
+ else{
119
+ $fee = $type_data['amount'];
120
+ }
121
+
122
+ if($type_data['min_cap'] != 0 ) {
123
+ $fee = $fee + $type_data['min_cap'];
124
+ }
125
+
126
+ if($type_data['max_cap'] != 0 && $fee > $type_data['max_cap'] ) {
127
+ $fee = $type_data['max_cap'];
128
+ }
129
+
130
+ echo $fee; ?>
131
+ </td><?php
132
+ }
133
+ }?>
134
+ <td>
135
+ <?php echo get_post_meta($post->ID, 'currency', true). " " .get_post_meta($post->ID, 'points', true) * get_post_meta($post->ID, 'cost', true); ?>
136
+ </td>
137
+ <td><?php echo mycred_get_types()[get_post_meta($post->ID, 'point_type', true)];?></td>
138
+ <td>
139
+ <?php
140
+ $gateway = get_post_meta($post->ID, 'gateway', true);
141
+ $installed = $mycred_modules['solo']['cashcred']->get();
142
+ if (isset($installed[ $gateway ]) ) {
143
+ echo $installed[ $gateway ]['title'];
144
+ } else {
145
+ echo $gateway;
146
+ }
147
+ ?>
148
+ </td>
149
+ <td><?php echo $post->post_date; ?></td>
150
+ </tr>
151
+ <?php endforeach;?>
152
+ </tbody>
153
+ </table>
154
+ <?php } else {
155
+ $mycred_cashcred_gateway_notice = apply_filters('mycred_cashcred_gateway_notice', 'Selected gateway details are incomplete.');
156
+ ?>
157
+
158
+ <div class="cashcred_gateway_notice"><?php _e($mycred_cashcred_gateway_notice, 'mycred') ?></div>
159
+
160
+ <form method="post" class="mycred-cashcred-form" action="">
161
+
162
+ <?php wp_nonce_field('cashCred-withdraw-request', 'cashcred_withdraw_wpnonce'); ?>
163
+
164
+ <?php if(count($point_types) > 1 ) {?>
165
+ <div class="form-group">
166
+ <label for="gateway"><?php _e('Withdraw Point Type', 'mycred'); ?></label>
167
+ <select id="cashcred_point_type" name="cashcred_point_type" class="form-control">
168
+ <?php
169
+ foreach( $point_types as $point_type_id => $point_type_obj ) {
170
+ echo '<option value="' . $point_type_id . '">' . esc_html($point_type_obj->plural()) . '</option>';
171
+ }
172
+ ?>
173
+ </select>
174
+ </div>
175
+ <?php } else {?>
176
+ <input type="hidden" id="cashcred_point_type" name="cashcred_point_type" value="<?php echo esc_attr(current(array_keys($point_types))); ?>" />
177
+ <?php } ?>
178
+
179
+ <?php if (count($gateways) > 1 ) { ?>
180
+ <div class="form-group">
181
+ <label for="gateway"><?php _e('Withdrawal Payment Method', 'mycred'); ?></label>
182
+ <select id="cashcred_pay_method" name="cashcred_pay_method" class="form-control">
183
+ <?php
184
+ foreach ( $gateways as $gateway_id => $gateway_data ) {
185
+ echo '<option value="' . esc_attr($gateway_id) . '">' . esc_html($gateway_data['title']) . '</option>';
186
+ }
187
+ ?>
188
+ </select>
189
+ </div>
190
+ <?php } else { ?>
191
+ <input type="hidden" id="cashcred_pay_method" name="cashcred_pay_method" value="<?php echo esc_attr(current(array_keys($gateways))); ?>" />
192
+ <?php } ?>
193
+
194
+ <div class="form-group">
195
+ <label><?php echo sprintf(__('Withdraw %s value', 'mycred'), $point_types[ current(array_keys($point_types)) ]->plural()); ?></label>
196
+ <?php
197
+ $amount = ! empty($amount) ? floatval($amount) : 0;
198
+ ?>
199
+ <input type="number" id="withdraw_points" name="points" class="form-control" placeholder="0" value="<?php echo ! empty($amount) ? $amount : 0; ?>" required />
200
+ <p class="cashcred-min"><?php echo __('Minimum Amount: ');?><span></span></p>
201
+
202
+ <?php
203
+
204
+ if (! empty($cashcred_setting['fees']) ) {
205
+
206
+ if($cashcred_setting['fees']['use'] == 1 ) { ?>
207
+
208
+ <p class="cashcred-fee" ><?php echo __('Fee : '); ?>
209
+
210
+ <span></span>
211
+
212
+ </p> <?php
213
+ }
214
+
215
+ $format = array();
216
+ foreach ($point_types as $key => $value) {
217
+ $format[$key] = $point_types[$key]->core['format'];
218
+
219
+ }
220
+
221
+ wp_localize_script(
222
+ 'cashcred-withdraw', 'cashcred_data',
223
+ array(
224
+ 'cashcred_setting' => $cashcred_setting['fees'],
225
+ 'format' => $format,
226
+ )
227
+ );
228
+
229
+ }
230
+ ?>
231
+ </div>
232
+ <div class="mycred-cashcred-withdraw-form-footer">
233
+ <div id="cashcred_total" class="form-group">
234
+ <strong>
235
+ <span class="amount_label">Amount:&nbsp;</span>
236
+ <span id="cashcred_currency_symbol"></span>
237
+ <span id="cashcred_total_amount"></span>
238
+ </strong>
239
+ </div>
240
+ <div id="submit_button" class="form-group">
241
+ <input type="submit" class="button" value="<?php echo $button_label; ?>" />
242
+ </div>
243
+ <div class="mycred-clearfix"></div>
244
+ </div>
245
+ </form>
246
+ <?php } ?>
247
+ </div>
248
+ <!--------End First tab--------->
249
+
250
+ <!--------Secound tab--------->
251
+ <div id="tab2c" class="cashcred-tab">
252
+ <h4>Approved Requests</h4>
253
+ <?php
254
+ $posts = cashcred_get_withdraw_requests('Approved');
255
+ ?>
256
+ <table>
257
+ <thead>
258
+ <tr>
259
+ <th><span class="nobr">ID</span></th>
260
+ <th><span class="nobr">Points</span></th>
261
+ <?php
262
+ if (! empty($cashcred_setting['fees']['types']) ) {
263
+ if ($cashcred_setting['fees']['use'] == 1 ) { ?>
264
+ <th><span class="nobr">Fee</span></th><?php
265
+ }
266
+ }?>
267
+ <th><span class="nobr">Amount</span></th>
268
+ <th><span class="nobr">Point Type</span></th>
269
+ <th><span class="nobr">Gateway</span></th>
270
+ <th><span class="nobr">Date</span></th>
271
+ </tr>
272
+ </thead>
273
+ <tbody>
274
+ <?php foreach($posts as $post) {?>
275
+ <tr>
276
+ <td><?php echo $post->post_name; ?></td>
277
+ <td><?php echo get_post_meta($post->ID, 'points', true);?></td>
278
+ <?php
279
+ if (! empty($cashcred_setting['fees']['types']) ) {
280
+
281
+ if ($cashcred_setting['fees']['use'] == 1 ) { ?>
282
+
283
+ <td><?php
284
+
285
+ $type_data = $cashcred_setting['fees']['types'][get_post_meta($post->ID, 'point_type', true)];
286
+
287
+ if ($type_data['by'] == 'percent' ) {
288
+ $fee = ( ( $type_data['amount'] / 100 ) * (int)get_post_meta($post->ID, 'points', true) );
289
+ }
290
+ else{
291
+ $fee = $type_data['amount'];
292
+ }
293
+
294
+ if($type_data['min_cap'] != 0 ) {
295
+ $fee = $fee + $type_data['min_cap'];
296
+ }
297
+
298
+ if($type_data['max_cap'] != 0 && $fee > $type_data['max_cap'] ) {
299
+ $fee = $type_data['max_cap'];
300
+ }
301
+
302
+ echo $fee; ?>
303
+ </td><?php
304
+ }
305
+ }?>
306
+ <td>
307
+ <?php echo get_post_meta($post->ID, 'currency', true). " " .get_post_meta($post->ID, 'points', true) * get_post_meta($post->ID, 'cost', true);?>
308
+ </td>
309
+ <td><?php echo mycred_get_types()[get_post_meta($post->ID, 'point_type', true)]; ?></td>
310
+ <td>
311
+ <?php
312
+ $gateway = get_post_meta($post->ID, 'gateway', true);
313
+ $installed = $mycred_modules['solo']['cashcred']->get();
314
+ if (isset($installed[ $gateway ]) ) {
315
+ echo $installed[ $gateway ]['title'];
316
+ } else {
317
+ echo $gateway;
318
+ }
319
+ ?>
320
+ </td>
321
+ <td><?php echo $post->post_date; ?></td>
322
+ </tr>
323
+ <?php } ?>
324
+ </tbody>
325
+ </table>
326
+ </div>
327
+ <!--------End Secound tab--------->
328
+
329
+ <!--------Third tab--------->
330
+ <div id="tab3c" class="cashcred-tab">
331
+ <h4>Cancelled Requests</h4>
332
+ <?php
333
+ $posts = cashcred_get_withdraw_requests('Cancelled');
334
+ ?>
335
+ <table>
336
+ <thead>
337
+ <tr>
338
+ <th><span class="nobr">ID</span></th>
339
+ <th><span class="nobr">Points</span></th>
340
+ <?php
341
+ if (! empty($cashcred_setting['fees']['types']) ) {
342
+ if ($cashcred_setting['fees']['use'] == 1 ) { ?>
343
+ <th><span class="nobr">Fee</span></th><?php
344
+ }
345
+ }?>
346
+ <th><span class="nobr">Amount</span></th>
347
+ <th><span class="nobr">Point Type</span></th>
348
+ <th><span class="nobr">Gateway</span></th>
349
+ <th><span class="nobr">Date</span></th>
350
+ </tr>
351
+ </thead>
352
+ <tbody>
353
+ <?php foreach($posts as $post) {?>
354
+ <tr>
355
+ <td><?php echo $post->post_name; ?></td>
356
+
357
+ <td><?php echo get_post_meta($post->ID, 'points', true);?></td>
358
+ <?php
359
+ if (! empty($cashcred_setting['fees']['types']) ) {
360
+
361
+ if ($cashcred_setting['fees']['use'] == 1 ) { ?>
362
+
363
+ <td><?php
364
+
365
+ $type_data = $cashcred_setting['fees']['types'][get_post_meta($post->ID, 'point_type', true)];
366
+
367
+ if ($type_data['by'] == 'percent' ) {
368
+ $fee = ( ( $type_data['amount'] / 100 ) * (int)get_post_meta($post->ID, 'points', true) );
369
+ }
370
+ else{
371
+ $fee = $type_data['amount'];
372
+ }
373
+
374
+ if($type_data['min_cap'] != 0 ) {
375
+ $fee = $fee + $type_data['min_cap'];
376
+ }
377
+
378
+ if($type_data['max_cap'] != 0 && $fee > $type_data['max_cap'] ) {
379
+ $fee = $type_data['max_cap'];
380
+ }
381
+
382
+ echo $fee; ?>
383
+ </td><?php
384
+ }
385
+ }?>
386
+ <td>
387
+ <?php echo get_post_meta($post->ID, 'currency', true). " " .get_post_meta($post->ID, 'points', true) * get_post_meta($post->ID, 'cost', true);?>
388
+ </td>
389
+ <td><?php echo mycred_get_types()[get_post_meta($post->ID, 'point_type', true)];?></td>
390
+ <td>
391
+ <?php
392
+ $gateway = get_post_meta($post->ID, 'gateway', true);
393
+ $installed = $mycred_modules['solo']['cashcred']->get();
394
+ if (isset($installed[ $gateway ]) ) {
395
+ echo $installed[ $gateway ]['title'];
396
+ } else {
397
+ echo $gateway;
398
+ }
399
+ ?>
400
+ </td>
401
+ <td><?php echo $post->post_date; ?></td>
402
+ </tr>
403
+ <?php } ?>
404
+ </tbody>
405
+ </table>
406
+ </div>
407
+ <!--------End Third tab--------->
408
+
409
+ <!--------Fourth tab--------->
410
+ <div id="tab4c" class="cashcred-tab">
411
+ <form action="" method="POST">
412
+ <?php if (count($gateways) > 1 ) :?>
413
+ <select class="form-control" name="cashcred_save_settings" id="cashcred_save_settings">
414
+ <?php
415
+ foreach ( $gateways as $key => $active_gateways_value ) {
416
+ echo '<option value="' . $key . '"> '. $active_gateways_value['title'] .' </option>';
417
+ }
418
+ ?>
419
+ </select>
420
+ <?php else:?>
421
+ <input type="hidden" name="cashcred_save_settings" id="cashcred_save_settings" value="<?php echo esc_attr(current(array_keys($gateways))); ?>" />
422
+ <?php endif;?>
423
+ <?php
424
+ wp_nonce_field('cashCred-payment-settings', 'cashcred_settings_wpnonce');
425
+
426
+ foreach ( $gateways as $key => $active_gateways_value ) {
427
+
428
+ $MyCred_payment_setting_call = new $active_gateways_value['callback'][0]($key);
429
+ $MyCred_payment_setting_call->cashcred_payment_settings($key);
430
+
431
+ }
432
+ ?>
433
+ <div id="cashcred_save_settings" class="form-group">
434
+ <input type="submit" class="button" value="Save" />
435
+ </div>
436
+ </form>
437
+ </div>
438
+ <!--------End Fourth tab--------->
439
+ </div>
440
  </div>
441
+ <?php
442
+ $content = ob_get_contents();
443
+ ob_end_clean();
444
+ return $content;
445
+ }
446
+ endif;
addons/cash-creds/includes/index.php CHANGED
@@ -1,3 +1,3 @@
1
  <?php
2
  // Silence is golden.
3
- ?>
1
  <?php
2
  // Silence is golden.
3
+ ?>
addons/cash-creds/index.php CHANGED
@@ -1,3 +1,3 @@
1
  <?php
2
  // Silence is golden.
3
- ?>
1
  <?php
2
  // Silence is golden.
3
+ ?>
addons/cash-creds/modules/cashcred-module-core.php CHANGED
@@ -359,7 +359,7 @@ if ( ! class_exists( 'myCRED_cashCRED_Module' ) ) :
359
  'comment_author_email' => $author_email,
360
  'comment_content' => $comment,
361
  'comment_type' => 'cashcred',
362
- 'comment_author_IP' => $_SERVER['REMOTE_ADDR'],
363
  'comment_date' => $time,
364
  'comment_approved' => 1,
365
  'user_id' => 0
@@ -525,7 +525,7 @@ if ( ! class_exists( 'myCRED_cashCRED_Module' ) ) :
525
  check_site_add_post_meta( $post_id, 'cost', $cost, true );
526
  check_site_add_post_meta( $post_id, 'currency', $currency, true );
527
  check_site_add_post_meta( $post_id, 'from', get_current_user_id(), true );
528
- check_site_add_post_meta( $post_id, 'user_ip', $_SERVER['REMOTE_ADDR'], true );
529
  check_site_add_post_meta( $post_id, 'manual', 'Manual', true );
530
 
531
  if( isset( $mycred_pref_cashcreds['gateway_prefs'][ $cashcred_pay_method ]["allow_auto_withdrawal"] ) &&
359
  'comment_author_email' => $author_email,
360
  'comment_content' => $comment,
361
  'comment_type' => 'cashcred',
362
+ 'comment_author_IP' => sanitize_text_field($_SERVER['REMOTE_ADDR']),
363
  'comment_date' => $time,
364
  'comment_approved' => 1,
365
  'user_id' => 0
525
  check_site_add_post_meta( $post_id, 'cost', $cost, true );
526
  check_site_add_post_meta( $post_id, 'currency', $currency, true );
527
  check_site_add_post_meta( $post_id, 'from', get_current_user_id(), true );
528
+ check_site_add_post_meta( $post_id, 'user_ip', sanitize_text_field($_SERVER['REMOTE_ADDR']), true );
529
  check_site_add_post_meta( $post_id, 'manual', 'Manual', true );
530
 
531
  if( isset( $mycred_pref_cashcreds['gateway_prefs'][ $cashcred_pay_method ]["allow_auto_withdrawal"] ) &&
addons/cash-creds/modules/cashcred-module-withdrawal.php CHANGED
@@ -1,1225 +1,1301 @@
1
  <?php
2
- if ( ! defined( 'MYCRED_CASHCRED' ) ) exit;
 
3
 
4
  /**
5
  * cashCRED_Pending_Payments class
6
- * @since 1.7
 
7
  * @version 1.2
8
  */
9
- if ( ! class_exists( 'cashCRED_Pending_Payments' ) ) :
10
- class cashCRED_Pending_Payments extends myCRED_Module {
11
-
12
- /**
13
- * Construct
14
- */
15
- function __construct( $type = MYCRED_DEFAULT_TYPE_KEY ) {
16
-
17
- parent::__construct( 'cashCRED_Payments', array(
18
- 'module_name' => 'cashCRED_Payments',
19
- 'option_id' => '',
20
- 'defaults' => array(),
21
- 'screen_id' => '',
22
- 'accordion' => false,
23
- 'add_to_core' => false,
24
- 'menu_pos' => 81
25
- ), $type );
26
-
27
- }
28
-
29
- /**
30
- * Load
31
- * @version 1.0.1
32
- */
33
- public function load() {
34
-
35
- add_action( 'mycred_init', array( $this, 'module_init' ), $this->menu_pos );
36
- add_action( 'mycred_admin_init', array( $this, 'module_admin_init' ), $this->menu_pos );
37
-
38
- }
39
-
40
- /**
41
- * Module Init
42
- * @since 1.7
43
- * @version 1.2
44
- */
45
- public function module_init() {
46
-
47
- $this->register_cashcred_payments();
48
-
49
- add_action( 'mycred_add_menu', array( $this, 'add_to_menu' ), $this->menu_pos );
50
-
51
- }
52
-
53
- /**
54
- * Module Admin Init
55
- * @since 1.7
56
- * @version 1.1
57
- */
58
- public function module_admin_init() {
59
-
60
- add_filter( 'parent_file', array( $this, 'parent_file' ) );
61
- add_filter( 'submenu_file', array( $this, 'subparent_file' ), 10, 2 );
62
-
63
- add_action( 'admin_notices', array( $this, 'admin_notices' ) );
 
 
 
 
 
 
 
 
 
 
64
 
65
- add_action( 'admin_head-post.php', array( $this, 'edit_pending_payment_style' ) );
66
- add_filter( 'post_updated_messages', array( $this, 'post_updated_messages' ) );
67
-
68
- add_filter( 'manage_' . MYCRED_CASHCRED_KEY . '_posts_columns', array( $this, 'adjust_column_headers' ) );
69
- add_action( 'manage_' . MYCRED_CASHCRED_KEY . '_posts_custom_column', array( $this, 'adjust_column_content' ), 10, 2 );
70
- add_filter( 'bulk_actions-edit-' . MYCRED_CASHCRED_KEY, array( $this, 'bulk_actions' ) );
71
- add_action( 'save_post_' . MYCRED_CASHCRED_KEY, array( $this, 'save_pending_payment' ), 10, 2 );
72
-
73
- add_action( 'restrict_manage_posts', array( $this, 'cashcred_filter_html' ) );
74
- add_action( 'parse_query', array( $this, 'cashcred_filter_query' ) );
75
-
76
- add_action( 'admin_enqueue_scripts', array( $this, 'cashcred_admin_assets' ) );
77
-
78
- }
79
-
80
- public function cashcred_admin_assets() {
81
-
82
- global $post_type;
83
-
84
- if ( $post_type == MYCRED_CASHCRED_KEY ) {
85
-
86
- wp_register_style( 'cashcred-admin', plugins_url( 'assets/css/admin-style.css', MYCRED_CASHCRED ), array(), MYCRED_CASHCRED_VERSION, 'all' );
87
- wp_enqueue_style( 'cashcred-admin' );
88
-
89
- wp_register_script( 'cashcred-admin-script', plugins_url( 'assets/js/admin-script.js', MYCRED_CASHCRED ), array( 'jquery' ), MYCRED_CASHCRED_VERSION, 'all' );
90
- wp_enqueue_script( 'cashcred-admin-script' );
91
-
92
- }
93
-
94
- }
95
-
96
- public function cashcred_filter_html() {
97
-
98
- global $wp_query, $mycred_modules, $post_type;
99
-
100
- if ( $post_type == MYCRED_CASHCRED_KEY ) {
101
-
102
- $status = array( 'Approved', 'Pending', 'Cancelled' );
103
-
104
- $current_plugin = '';
105
- if( isset( $_GET['Status'] ) ) {
106
- $current_plugin = $_GET['Status'];
107
- }
108
- ?>
109
- <select name="Status" id="Status">
110
- <option value="all" <?php selected( 'all', $current_plugin ); ?>>
111
- <?php _e( 'All Status', 'mycred' ); ?>
112
- </option>
113
- <?php foreach( $status as $key => $value ) { ?>
114
- <option value="<?php echo esc_attr( $value ); ?>" <?php selected( $value, $current_plugin ); ?>>
115
- <?php echo esc_attr( $value ); ?>
116
- </option>
117
- <?php } ?>
118
- </select>
119
- <?php
120
- $current_selected = '';
121
- if( isset( $_GET['gateway'] ) ) {
122
- $current_selected = $_GET['gateway']; // Check if option has been selected
123
- }
124
- ?>
125
- <select name="gateway" id="gateway">
126
- <option value="all" <?php selected( 'all', $current_selected ); ?>>
127
- <?php _e( 'All Gateway', 'mycred' ); ?>
128
- </option>
129
- <?php
130
- foreach ( $mycred_modules['solo']['cashcred']->get() as $gateway_id => $info ) { ?>
131
- <option value="<?php echo esc_attr( $gateway_id ); ?>" <?php selected( $gateway_id, $current_selected ); ?>>
132
- <?php echo esc_attr( $info['title'] ); ?>
133
- </option>
134
- <?php } ?>
135
- </select>
136
- <?php
137
- $current_user = '';
138
- if( isset( $_GET['user_id'] ) ) {
139
- $current_user = $_GET['user_id']; // Check if option has been selected
140
- }
141
- $users = get_users( array( 'fields' => array( 'ID' , 'user_nicename') ) );
142
- ?>
143
- <select name="user_id" id="user_id">
144
- <option value="all" <?php selected( 'all', $current_user ); ?>>
145
- <?php _e( 'All Users', 'mycred' ); ?>
146
- </option>
147
- <?php
148
- foreach ( $users as $user ) { ?>
149
- <option value="<?php echo esc_attr( $user->ID ); ?>" <?php selected( $user->ID, $current_user ); ?>>
150
- <?php echo esc_attr( $user->user_nicename ); ?>
151
- </option>
152
- <?php } ?>
153
- </select>
154
- <?php
155
- }
156
- }
157
-
158
- public function cashcred_filter_query( $query ) {
159
-
160
- global $pagenow;
161
- $meta_query = array();
162
-
163
- $post_type = isset( $_GET['post_type'] ) ? $_GET['post_type'] : '';
164
-
165
- /* Gateway filter */
166
- if ( is_admin() && $pagenow=='edit.php' && $post_type == 'cashcred_withdrawal' && isset( $_GET['gateway'] ) && $_GET['gateway'] !='all' ) {
167
-
168
- $meta_query[] = array(
169
- 'key' => 'gateway',
170
- 'value' => $_GET['gateway'],
171
- 'compare' => '='
172
- );
173
- }
174
-
175
- /* Payment status filter */
176
- if ( is_admin() && $pagenow=='edit.php' && $post_type == 'cashcred_withdrawal' && isset( $_GET['Status'] ) && $_GET['Status'] !='all' ) {
177
-
178
- $meta_query[] = array(
179
- 'key' => 'Status',
180
- 'value' => $_GET['Status'],
181
- 'compare' => '='
182
- );
183
-
184
- }
185
-
186
- /* User filter */
187
- if ( is_admin() && $post_type == 'cashcred_withdrawal' && isset( $_GET['user_id'] ) && $_GET['user_id'] !='all') {
188
-
189
- $meta_query[] = array(
190
- 'key' => 'from',
191
- 'value' => $_GET['user_id'],
192
- 'compare' => '='
193
- );
194
- }
195
-
196
- if( ! empty( $meta_query ) )
197
- $query->set( 'meta_query', $meta_query );
198
-
199
- }
200
-
201
- /**
202
- * Register Pending Payments
203
- * @since 1.5
204
- * @version 1.1
205
- */
206
- protected function register_cashcred_payments() {
207
-
208
- $labels = array(
209
- 'name' => _x( 'cashCred Withdrawal', 'Post Type General Name', 'mycred' ),
210
- 'singular_name' => _x( 'cashCred Withdrawal', 'Post Type Singular Name', 'mycred' ),
211
- 'menu_name' => __( 'cashCred Withdrawal', 'mycred' ),
212
- 'parent_item_colon' => '',
213
- 'all_items' => __( 'cashCred Withdrawal', 'mycred' ),
214
- 'view_item' => '',
215
- 'add_new_item' => '',
216
- 'add_new' => '',
217
- 'edit_item' => __( 'Edit Withdrawal Request', 'mycred' ),
218
- 'update_item' => '',
219
- 'search_items' => '',
220
- 'not_found' => __( 'Not found in Trash', 'mycred' ),
221
- 'not_found_in_trash' => __( 'Not found in Trash', 'mycred' ),
222
- );
223
- $args = array(
224
- 'labels' => $labels,
225
- 'supports' => array( 'title', 'comments' ),
226
- 'hierarchical' => false,
227
- 'public' => false,
228
- 'show_ui' => true,
229
- 'show_in_menu' => false,
230
- 'show_in_nav_menus' => false,
231
- 'show_in_admin_bar' => false,
232
- 'can_export' => true,
233
- 'has_archive' => false,
234
- 'exclude_from_search' => true,
235
- 'publicly_queryable' => false,
236
- 'register_meta_box_cb' => array( $this, 'add_metaboxes' )
237
- );
238
- register_post_type( MYCRED_CASHCRED_KEY, apply_filters( 'mycred_setup_cashcred_payment', $args ) );
239
-
240
- }
241
-
242
- /**
243
- * Adjust Post Updated Messages
244
- * @since 1.7
245
- * @version 1.1
246
- */
247
- public function post_updated_messages( $messages ) {
248
-
249
- $messages[ MYCRED_CASHCRED_KEY ] = array(
250
- 0 => '',
251
- 1 => __( 'Payment Updated.', 'mycred' ),
252
- 2 => __( 'Payment Updated.', 'mycred' ),
253
- 3 => __( 'Payment Updated.', 'mycred' ),
254
- 4 => __( 'Payment Updated.', 'mycred' ),
255
- 5 => __( 'Payment Updated.', 'mycred' ),
256
- 6 => __( 'Payment Updated.', 'mycred' ),
257
- 7 => __( 'Payment Updated.', 'mycred' ),
258
- 8 => __( 'Payment Updated.', 'mycred' ),
259
- 9 => __( 'Payment Updated.', 'mycred' ),
260
- 10 => ''
261
- );
262
-
263
- return $messages;
264
-
265
- }
266
-
267
- /**
268
- * Add Comment
269
- * @since 1.7
270
- * @version 1.0
271
- */
272
- public function add_comment( $post_id, $event = '', $time = NULL ) {
273
-
274
- return cashcred_add_comment( $post_id, $event, $time );
275
-
276
- }
277
-
278
- /**
279
- * Admin Notices
280
- * @since 1.7
281
- * @version 1.1
282
- */
283
- public function admin_notices() {
284
-
285
- if ( isset( $_GET['post_type'] ) && $_GET['post_type'] == MYCRED_CASHCRED_KEY && isset( $_GET['credited'] ) ) {
286
-
287
- if ( $_GET['credited'] == 1 )
288
- echo '<div id="message" class="updated notice is-dismissible"><p>' . __( 'Pending payment successfully credited to account.', 'mycred' ) . '</p><button type="button" class="notice-dismiss"></button></div>';
289
-
290
- elseif ( $_GET['credited'] == 0 )
291
- echo '<div id="message" class="error notice is-dismissible"><p>' . __( 'Failed to credit the pending payment to account.', 'mycred' ) . '</p><button type="button" class="notice-dismiss"></button></div>';
292
-
293
- }
294
-
295
- }
296
-
297
- /**
298
- * Add Admin Menu Item
299
- * @since 1.7
300
- * @version 1.1
301
- */
302
- public function add_to_menu() {
303
-
304
- // In case we are using the Master Template feautre on multisites, and this is not the main
305
- // site in the network, bail.
306
- //if ( mycred_override_settings() && ! mycred_is_main_site() ) return;
307
-
308
- mycred_add_main_submenu(
309
- __( 'cashCred Withdrawal', 'mycred' ),
310
- __( 'cashCred Withdrawal', 'mycred' ),
311
- $this->core->get_poin
1
  <?php
2
+ if (! defined('MYCRED_CASHCRED') ) { exit;
3
+ }
4
 
5
  /**
6
  * cashCRED_Pending_Payments class
7
+ *
8
+ * @since 1.7
9
  * @version 1.2
10
  */
11
+ if (! class_exists('cashCRED_Pending_Payments') ) :
12
+ class cashCRED_Pending_Payments extends myCRED_Module
13
+ {
14
+
15
+ /**
16
+ * Construct
17
+ */
18
+ function __construct( $type = MYCRED_DEFAULT_TYPE_KEY )
19
+ {
20
+
21
+ parent::__construct(
22
+ 'cashCRED_Payments', array(
23
+ 'module_name' => 'cashCRED_Payments',
24
+ 'option_id' => '',
25
+ 'defaults' => array(),
26
+ 'screen_id' => '',
27
+ 'accordion' => false,
28
+ 'add_to_core' => false,
29
+ 'menu_pos' => 81
30
+ ), $type
31
+ );
32
+
33
+ }
34
+
35
+ /**
36
+ * Load
37
+ *
38
+ * @version 1.0.1
39
+ */
40
+ public function load()
41
+ {
42
+
43
+ add_action('mycred_init', array( $this, 'module_init' ), $this->menu_pos);
44
+ add_action('mycred_admin_init', array( $this, 'module_admin_init' ), $this->menu_pos);
45
+
46
+ }
47
+
48
+ /**
49
+ * Module Init
50
+ *
51
+ * @since 1.7
52
+ * @version 1.2
53
+ */
54
+ public function module_init()
55
+ {
56
+
57
+ $this->register_cashcred_payments();
58
+
59
+ add_action('mycred_add_menu', array( $this, 'add_to_menu' ), $this->menu_pos);
60
+
61
+ }
62
+
63
+ /**
64
+ * Module Admin Init
65
+ *
66
+ * @since 1.7
67
+ * @version 1.1
68
+ */
69
+ public function module_admin_init()
70
+ {
71
+
72
+ add_filter('parent_file', array( $this, 'parent_file' ));
73
+ add_filter('submenu_file', array( $this, 'subparent_file' ), 10, 2);
74
+
75
+ add_action('admin_notices', array( $this, 'admin_notices' ));
76