Version Description
Code improvement.
Download this release
Release Info
Developer | wpexpertsio |
Plugin | myCRED |
Version | 2.4.4.3 |
Comparing to | |
See all releases |
Code changes from version 2.4.4.2 to 2.4.4.3
- abstracts/index.php +1 -1
- abstracts/mycred-abstract-hook.php +481 -556
- abstracts/mycred-abstract-module.php +641 -750
- abstracts/mycred-abstract-object.php +64 -78
- addons/badges/assets/css/front.css +1 -1
- addons/badges/assets/css/index.php +1 -1
- addons/badges/assets/index.php +1 -1
- addons/badges/assets/js/front.js +28 -40
- addons/badges/assets/js/index.php +1 -1
- addons/badges/includes/index.php +1 -1
- addons/badges/includes/mycred-badge-functions.php +632 -775
- addons/badges/includes/mycred-badge-object.php +552 -641
- addons/badges/includes/mycred-badge-secondary.php +80 -90
- addons/badges/includes/mycred-badge-shortcodes.php +111 -131
- addons/badges/includes/mycred-open-badge.php +222 -244
- addons/badges/index.php +1 -1
- addons/badges/myCRED-addon-badges.php +51 -51
- addons/badges/templates/index.php +1 -1
- addons/badges/templates/mycred-metabox-badge-alignment.php +5 -5
- addons/badges/templates/mycred-metabox-badge-layout.php +5 -5
- addons/banking/abstracts/index.php +1 -1
- addons/banking/abstracts/mycred-abstract-service.php +363 -424
- addons/banking/assets/index.php +1 -1
- addons/banking/assets/js/index.php +1 -1
- addons/banking/includes/index.php +1 -1
- addons/banking/includes/mycred-banking-functions.php +18 -23
- addons/banking/index.php +1 -1
- addons/banking/myCRED-addon-banking.php +8 -8
- addons/banking/services/index.php +1 -1
- addons/banking/services/mycred-service-central.php +167 -191
- addons/buy-creds/abstracts/index.php +1 -1
- addons/buy-creds/abstracts/mycred-abstract-payment-gateway.php +2011 -2232
- addons/buy-creds/assets/css/admin-style.css +4 -4
- addons/buy-creds/assets/css/index.php +1 -1
- addons/buy-creds/assets/images/index.php +1 -1
- addons/buy-creds/assets/index.php +1 -1
- addons/buy-creds/assets/js/checkout.js +143 -178
- addons/buy-creds/assets/js/index.php +1 -1
- addons/buy-creds/gateways/Bitpay/Autoloader.php +1 -1
- addons/buy-creds/gateways/Bitpay/Client/Adapter/CurlAdapter.php +2 -6
- addons/buy-creds/gateways/Bitpay/Client/Client.php +84 -98
- addons/buy-creds/gateways/Bitpay/Client/ClientInterface.php +6 -8
- addons/buy-creds/gateways/Bitpay/Client/Response.php +1 -1
- addons/buy-creds/gateways/Bitpay/Config/Configuration.php +30 -32
- addons/buy-creds/gateways/Bitpay/Crypto/HashExtension.php +34 -34
- addons/buy-creds/gateways/Bitpay/Crypto/McryptExtension.php +16 -12
- addons/buy-creds/gateways/Bitpay/Crypto/OpenSSLExtension.php +34 -32
- addons/buy-creds/gateways/Bitpay/Currency.php +3 -3
- addons/buy-creds/gateways/Bitpay/DependencyInjection/Loader/ArrayLoader.php +6 -8
- addons/buy-creds/gateways/Bitpay/Invoice.php +3 -3
- addons/buy-creds/gateways/Bitpay/InvoiceInterface.php +12 -12
- addons/buy-creds/gateways/Bitpay/Item.php +1 -1
- addons/buy-creds/gateways/Bitpay/Key.php +1 -1
- addons/buy-creds/gateways/Bitpay/Math/BcEngine.php +2 -2
- addons/buy-creds/gateways/Bitpay/Payout.php +18 -27
- addons/buy-creds/gateways/Bitpay/PayoutInstruction.php +7 -14
- addons/buy-creds/gateways/Bitpay/PayoutInstructionInterface.php +0 -8
- addons/buy-creds/gateways/Bitpay/PayoutInterface.php +0 -1
- addons/buy-creds/gateways/Bitpay/PayoutTransaction.php +3 -7
- addons/buy-creds/gateways/Bitpay/PayoutTransactionInterface.php +0 -4
- addons/buy-creds/gateways/Bitpay/PrivateKey.php +4 -4
- addons/buy-creds/gateways/Bitpay/SinKey.php +1 -1
- addons/buy-creds/gateways/Bitpay/Storage/EncryptedFilesystemStorage.php +7 -9
- addons/buy-creds/gateways/Bitpay/Storage/MockStorage.php +1 -1
- addons/buy-creds/gateways/Bitpay/Util/Error.php +31 -31
- addons/buy-creds/gateways/Bitpay/Util/Fingerprint.php +1 -1
- addons/buy-creds/gateways/Bitpay/Util/Util.php +13 -13
- addons/buy-creds/gateways/Bitpay/index.php +1 -1
- addons/buy-creds/gateways/bank-transfer.php +192 -220
- addons/buy-creds/gateways/bitpay.php +466 -499
- addons/buy-creds/gateways/index.php +1 -1
- addons/buy-creds/gateways/netbilling.php +287 -316
- addons/buy-creds/gateways/paypal-standard.php +339 -369
- addons/buy-creds/gateways/skrill.php +368 -402
- addons/buy-creds/images/index.php +1 -1
- addons/buy-creds/includes/buycred-functions.php +478 -576
- addons/buy-creds/includes/buycred-reward-hook.php +213 -229
- addons/buy-creds/includes/buycred-reward.php +70 -82
- addons/buy-creds/includes/buycred-shortcodes.php +4 -4
- addons/buy-creds/includes/index.php +1 -1
- addons/buy-creds/index.php +1 -1
- addons/buy-creds/modules/buycred-module-core.php +1173 -1291
- addons/buy-creds/modules/buycred-module-pending.php +673 -750
- addons/buy-creds/modules/index.php +1 -1
- addons/buy-creds/myCRED-addon-buy-creds.php +19 -24
- addons/buy-creds/templates/buycred-checkout.php +12 -12
- addons/buy-creds/templates/index.php +1 -1
- addons/cash-creds/abstracts/cashcred-abstract-payment-gateway.php +681 -746
- addons/cash-creds/abstracts/index.php +1 -1
- addons/cash-creds/assets/css/admin-style.css +50 -50
- addons/cash-creds/assets/css/index.php +1 -1
- addons/cash-creds/assets/css/withdraw.css +29 -29
- addons/cash-creds/assets/images/index.php +1 -1
- addons/cash-creds/assets/index.php +1 -1
- addons/cash-creds/assets/js/index.php +1 -1
- addons/cash-creds/assets/js/withdraw.js +181 -204
- addons/cash-creds/gateways/bank-transfer.php +287 -311
- addons/cash-creds/gateways/index.php +1 -1
- addons/cash-creds/includes/cashcred-functions.php +164 -225
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,613 +1,538 @@
|
|
1 |
<?php
|
2 |
-
if (! defined('myCRED_VERSION') )
|
3 |
-
}
|
4 |
|
5 |
/**
|
6 |
* myCRED_Hook class
|
7 |
-
*
|
8 |
-
* @
|
9 |
-
* @since 0.1
|
10 |
* @version 1.3.2
|
11 |
*/
|
12 |
-
if (! class_exists('myCRED_Hook') ) :
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
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 |
-
|
|
|
|
|
|
|
117 |
|
118 |
-
|
|
|
|
|
|
|
119 |
|
120 |
-
|
121 |
-
|
122 |
-
|
123 |
-
|
124 |
-
* @version 1.0
|
125 |
-
*/
|
126 |
-
public function sanitise_preferences( $data )
|
127 |
-
{
|
128 |
|
129 |
-
|
|
|
|
|
|
|
|
|
130 |
|
131 |
-
|
|
|
|
|
132 |
|
133 |
-
|
134 |
-
|
135 |
-
|
136 |
-
|
137 |
-
* @since 0.1
|
138 |
-
* @version 1.1
|
139 |
-
*/
|
140 |
-
public function field_name( $field = '' )
|
141 |
-
{
|
142 |
|
143 |
-
|
|
|
144 |
|
145 |
-
|
146 |
-
|
147 |
|
148 |
-
|
149 |
-
|
150 |
-
|
151 |
|
152 |
-
|
153 |
-
|
154 |
-
|
155 |
|
156 |
-
|
157 |
-
$field = '[' . implode('][', $array) . ']';
|
158 |
|
159 |
-
|
160 |
-
|
|
|
161 |
|
162 |
-
|
163 |
|
164 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
165 |
|
166 |
-
|
167 |
-
if (! $this->is_main_type ) {
|
168 |
-
$option_id = $option_id . '_' . $this->mycred_type;
|
169 |
-
}
|
170 |
|
171 |
-
|
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 |
-
|
186 |
|
187 |
-
|
|
|
|
|
|
|
|
|
|
|
188 |
|
189 |
-
|
190 |
-
foreach ( $field as $parent => $child ) {
|
191 |
|
192 |
-
|
193 |
-
$array[] = str_replace('_', '-', $parent);
|
194 |
-
}
|
195 |
|
196 |
-
|
197 |
-
|
198 |
-
|
|
|
|
|
|
|
|
|
199 |
|
200 |
-
|
201 |
-
$field = implode('-', $array);
|
202 |
|
203 |
-
|
204 |
-
|
205 |
|
206 |
-
|
|
|
207 |
|
208 |
-
|
|
|
209 |
|
210 |
-
|
211 |
-
|
212 |
-
$option_id = $option_id . '_' . $this->mycred_type;
|
213 |
-
}
|
214 |
|
215 |
-
|
|
|
216 |
|
217 |
-
|
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 |
-
|
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 |
-
|
236 |
-
if (! MYCRED_ENABLE_LOGGING ) { return false;
|
237 |
-
}
|
238 |
|
239 |
-
|
240 |
-
|
241 |
-
|
242 |
-
|
|
|
|
|
|
|
243 |
|
244 |
-
|
245 |
|
246 |
-
|
247 |
-
$wheres = array();
|
248 |
-
$now = current_time('timestamp');
|
249 |
|
250 |
-
|
251 |
-
|
252 |
-
$prefs = $this->prefs[ $instance ]['limit'];
|
253 |
-
}
|
254 |
|
255 |
-
|
256 |
-
|
257 |
-
$prefs = $this->prefs['limit'];
|
258 |
-
}
|
259 |
|
260 |
-
|
261 |
-
|
262 |
-
return false;
|
263 |
-
}
|
264 |
|
265 |
-
|
266 |
-
|
267 |
-
$user_id = get_current_user_id();
|
268 |
-
}
|
269 |
|
270 |
-
|
271 |
-
|
272 |
-
if ($ref_id !== null && strlen($ref_id) > 0 ) {
|
273 |
-
$exists_check = true;
|
274 |
-
}
|
275 |
|
276 |
-
|
277 |
-
$prefs = '0/x';
|
278 |
-
}
|
279 |
|
280 |
-
|
281 |
-
if (! $exists_check && $prefs === '0/x' ) { return false;
|
282 |
-
}
|
283 |
|
284 |
-
|
285 |
-
|
286 |
-
|
287 |
|
288 |
-
|
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 |
-
|
294 |
-
|
295 |
-
|
|
|
296 |
|
297 |
-
|
298 |
-
if (! in_array($period, array( 't', 'x' )) ) {
|
299 |
|
300 |
-
|
301 |
-
if ($period == 'd' ) {
|
302 |
-
$from = mktime(0, 0, 0, date('n', $now), date('j', $now), date('Y', $now));
|
303 |
-
}
|
304 |
|
305 |
-
|
306 |
-
|
307 |
-
|
308 |
-
|
309 |
-
|
310 |
-
|
311 |
-
|
312 |
-
|
313 |
-
|
314 |
-
|
315 |
-
|
316 |
-
|
317 |
-
|
318 |
-
|
319 |
-
|
320 |
-
|
321 |
-
|
322 |
-
|
323 |
-
|
324 |
-
|
325 |
-
|
326 |
-
|
327 |
-
|
328 |
-
|
329 |
-
|
330 |
-
|
331 |
-
|
332 |
-
|
333 |
-
|
334 |
-
|
335 |
-
|
336 |
-
|
337 |
-
|
338 |
-
|
339 |
-
|
340 |
-
|
341 |
-
|
342 |
-
|
343 |
-
|
344 |
-
|
345 |
-
|
346 |
-
|
347 |
-
|
348 |
-
|
349 |
-
|
350 |
-
|
351 |
-
|
352 |
-
|
353 |
-
|
354 |
-
|
355 |
-
|
356 |
-
|
357 |
-
|
358 |
-
|
359 |
-
|
360 |
-
|
361 |
-
|
362 |
-
|
363 |
-
|
364 |
-
|
365 |
-
|
366 |
-
|
367 |
-
|
368 |
-
|
369 |
-
|
370 |
-
|
371 |
-
|
372 |
-
|
373 |
-
|
374 |
-
|
375 |
-
|
376 |
-
|
377 |
-
|
378 |
-
|
379 |
-
|
380 |
-
|
381 |
-
|
382 |
-
|
383 |
-
|
384 |
-
|
385 |
-
|
386 |
-
|
387 |
-
|
388 |
-
|
389 |
-
|
390 |
-
|
391 |
-
|
392 |
-
|
393 |
-
|
394 |
-
|
395 |
-
|
396 |
-
|
397 |
-
|
398 |
-
|
399 |
-
|
400 |
-
|
401 |
-
|
402 |
-
|
403 |
-
|
404 |
-
|
405 |
-
|
406 |
-
|
407 |
-
|
408 |
-
|
409 |
-
|
410 |
-
|
411 |
-
|
412 |
-
|
413 |
-
|
414 |
-
|
415 |
-
|
416 |
-
|
417 |
-
|
418 |
-
|
419 |
-
|
420 |
-
|
421 |
-
|
422 |
-
|
423 |
-
|
424 |
-
|
425 |
-
|
426 |
-
|
427 |
-
|
428 |
-
|
429 |
-
|
430 |
-
|
431 |
-
|
432 |
-
|
433 |
-
|
434 |
-
|
435 |
-
|
436 |
-
|
437 |
-
|
438 |
-
|
439 |
-
|
440 |
-
|
441 |
-
|
442 |
-
|
443 |
-
|
444 |
-
|
445 |
-
|
446 |
-
|
447 |
-
|
448 |
-
|
449 |
-
|
450 |
-
|
451 |
-
|
452 |
-
|
453 |
-
|
454 |
-
|
455 |
-
|
456 |
-
|
457 |
-
|
458 |
-
|
459 |
-
|
460 |
-
|
461 |
-
|
462 |
-
|
463 |
-
|
464 |
-
|
465 |
-
|
466 |
-
|
467 |
-
|
468 |
-
|
469 |
-
|
470 |
-
|
471 |
-
|
472 |
-
|
473 |
-
|
474 |
-
|
475 |
-
|
476 |
-
|
477 |
-
|
478 |
-
|
479 |
-
|
480 |
-
|
481 |
-
|
482 |
-
|
483 |
-
|
484 |
-
|
485 |
-
|
486 |
-
|
487 |
-
|
488 |
-
|
489 |
-
|
490 |
-
|
491 |
-
|
492 |
-
|
493 |
-
|
494 |
-
|
495 |
-
|
496 |
-
|
497 |
-
|
498 |
-
|
499 |
-
|
500 |
-
|
501 |
-
|
502 |
-
|
503 |
-
|
504 |
-
|
505 |
-
|
506 |
-
|
507 |
-
|
508 |
-
|
509 |
-
|
510 |
-
|
511 |
-
|
512 |
-
|
513 |
-
|
514 |
-
|
515 |
-
|
516 |
-
|
517 |
-
|
518 |
-
|
519 |
-
|
520 |
-
|
521 |
-
|
522 |
-
|
523 |
-
|
524 |
-
|
525 |
-
|
526 |
-
|
527 |
-
|
528 |
-
|
529 |
-
|
530 |
-
|
531 |
-
|
532 |
-
|
533 |
-
|
534 |
-
|
535 |
-
|
536 |
-
|
537 |
-
|
538 |
-
|
539 |
-
|
540 |
-
|
541 |
-
|
542 |
-
|
543 |
-
|
544 |
-
|
545 |
-
|
546 |
-
|
547 |
-
|
548 |
-
|
549 |
-
|
550 |
-
|
551 |
-
|
552 |
-
|
553 |
-
|
554 |
-
|
555 |
-
|
556 |
-
|
557 |
-
|
558 |
-
|
559 |
-
|
560 |
-
|
561 |
-
|
562 |
-
|
563 |
-
|
564 |
-
|
565 |
-
|
566 |
-
|
567 |
-
|
568 |
-
|
569 |
-
|
570 |
-
|
571 |
-
|
572 |
-
|
573 |
-
|
574 |
-
|
575 |
-
|
576 |
-
|
577 |
-
|
578 |
-
|
579 |
-
|
580 |
-
|
581 |
-
|
582 |
-
|
583 |
-
|
584 |
-
|
585 |
-
|
586 |
-
|
587 |
-
|
588 |
-
|
589 |
-
|
590 |
-
|
591 |
-
|
592 |
-
|
593 |
-
|
594 |
-
|
595 |
-
|
596 |
-
|
597 |
-
|
598 |
-
|
599 |
-
|
600 |
-
|
601 |
-
|
602 |
-
|
603 |
-
|
604 |
-
|
605 |
-
|
606 |
-
|
607 |
-
|
608 |
-
|
609 |
-
|
610 |
-
|
611 |
-
|
612 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
613 |
endif;
|
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>' . esc_html__( '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="' . esc_attr( $this->field_name( $pref_id ) ) . '" id="' . esc_attr( $this->field_id( $pref_id ) ) . '" class="form-control">';
|
399 |
+
|
400 |
+
if ( $use_select )
|
401 |
+
echo '<option value="">' . esc_html__( '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="' . esc_attr( $value ) . '" ' . selected( $settings, $value ) . '>' . esc_html( $description ) . '</option>';
|
418 |
+
}
|
419 |
+
echo '</select>';
|
420 |
+
|
421 |
+
}
|
422 |
+
|
423 |
+
/**
|
424 |
+
* Has Entry
|
425 |
+
* Moved to myCRED_Settings
|
426 |
+
* @since 0.1
|
427 |
+
* @version 1.3
|
428 |
+
*/
|
429 |
+
public function has_entry( $action = '', $ref_id = '', $user_id = '', $data = '', $point_type = '' ) {
|
430 |
+
|
431 |
+
// If logging is disabled, we cant use this feature
|
432 |
+
if ( ! MYCRED_ENABLE_LOGGING ) return false;
|
433 |
+
|
434 |
+
if ( $point_type == '' )
|
435 |
+
$point_type = $this->mycred_type;
|
436 |
+
|
437 |
+
return $this->core->has_entry( $action, $ref_id, $user_id, $data, $point_type );
|
438 |
+
|
439 |
+
}
|
440 |
+
|
441 |
+
/**
|
442 |
+
* Available Template Tags
|
443 |
+
* @since 1.4
|
444 |
+
* @version 1.0
|
445 |
+
*/
|
446 |
+
public function available_template_tags( $available = array(), $custom = '' ) {
|
447 |
+
|
448 |
+
return $this->core->available_template_tags( $available, $custom );
|
449 |
+
|
450 |
+
}
|
451 |
+
|
452 |
+
/**
|
453 |
+
* Over Daily Limit
|
454 |
+
* @since 1.0
|
455 |
+
* @version 1.1.1
|
456 |
+
*/
|
457 |
+
public function is_over_daily_limit( $ref = '', $user_id = 0, $max = 0, $ref_id = NULL ) {
|
458 |
+
|
459 |
+
// If logging is disabled, we cant use this feature
|
460 |
+
if ( ! MYCRED_ENABLE_LOGGING ) return false;
|
461 |
+
|
462 |
+
// Prep
|
463 |
+
$reply = true;
|
464 |
+
|
465 |
+
// DB Query
|
466 |
+
$total = $this->limit_query( $ref, $user_id, strtotime( 'today midnight', $this->now ), $this->now, $ref_id );
|
467 |
+
|
468 |
+
if ( $total < $max )
|
469 |
+
$reply = false;
|
470 |
+
|
471 |
+
return apply_filters( 'mycred_hook_over_daily_limit', $reply, $ref, $user_id, $max );
|
472 |
+
|
473 |
+
}
|
474 |
+
|
475 |
+
/**
|
476 |
+
* Include Post Type
|
477 |
+
* Checks if a given post type should be excluded
|
478 |
+
* @since 0.1
|
479 |
+
* @version 1.1
|
480 |
+
*/
|
481 |
+
public function include_post_type( $post_type ) {
|
482 |
+
|
483 |
+
// Exclude Core
|
484 |
+
$excludes = array( 'post', 'page' );
|
485 |
+
if ( in_array( $post_type, apply_filters( 'mycred_post_type_excludes', $excludes ) ) ) return false;
|
486 |
+
|
487 |
+
return true;
|
488 |
+
|
489 |
+
}
|
490 |
+
|
491 |
+
/**
|
492 |
+
* Limit Query
|
493 |
+
* Queries the myCRED log for the number of occurances of the specified
|
494 |
+
* refernece and optional reference id for a specific user between two dates.
|
495 |
+
* @param $ref (string) reference to search for, required
|
496 |
+
* @param $user_id (int) user id to search for, required
|
497 |
+
* @param $start (int) unix timestamp for start date, required
|
498 |
+
* @param $end (int) unix timestamp for the end date, required
|
499 |
+
* @param $ref_id (int) optional reference id to include in search
|
500 |
+
* @returns number of entries found (int) or NULL if required params are missing
|
501 |
+
* @since 1.4
|
502 |
+
* @version 1.2
|
503 |
+
*/
|
504 |
+
public function limit_query( $ref = '', $user_id = 0, $start = 0, $end = 0, $ref_id = NULL ) {
|
505 |
+
|
506 |
+
// If logging is disabled, we cant use this feature
|
507 |
+
if ( ! MYCRED_ENABLE_LOGGING ) return 0;
|
508 |
+
|
509 |
+
// Minimum requirements
|
510 |
+
if ( empty( $ref ) || $user_id == 0 || $start == 0 || $end == 0 )
|
511 |
+
return NULL;
|
512 |
+
|
513 |
+
global $wpdb, $mycred_log_table;
|
514 |
+
|
515 |
+
// Prep
|
516 |
+
$reply = true;
|
517 |
+
$wheres = array();
|
518 |
+
|
519 |
+
$wheres[] = $wpdb->prepare( "ref = %s", $ref );
|
520 |
+
$wheres[] = $wpdb->prepare( "user_id = %d", $user_id );
|
521 |
+
$wheres[] = $wpdb->prepare( "time BETWEEN %d AND %d", $start, $end );
|
522 |
+
$wheres[] = $wpdb->prepare( "ctype = %s", $this->mycred_type );
|
523 |
+
|
524 |
+
if ( $ref_id !== NULL )
|
525 |
+
$wheres[] = $wpdb->prepare( "ref_id = %d", $ref_id );
|
526 |
+
|
527 |
+
$wheres = implode( " AND ", $wheres );
|
528 |
+
|
529 |
+
// DB Query
|
530 |
+
$total = $wpdb->get_var( "SELECT COUNT(*) FROM {$mycred_log_table} WHERE {$wheres};" );
|
531 |
+
if ( $total === NULL ) $total = 0;
|
532 |
+
|
533 |
+
return apply_filters( 'mycred_hook_limit_query', $total, $ref, $user_id, $ref_id, $start, $end );
|
534 |
+
|
535 |
+
}
|
536 |
+
|
537 |
+
}
|
538 |
endif;
|
abstracts/mycred-abstract-module.php
CHANGED
@@ -1,834 +1,725 @@
|
|
1 |
<?php
|
2 |
-
if (! defined('myCRED_VERSION') )
|
3 |
-
}
|
4 |
|
5 |
/**
|
6 |
* myCRED_Module class
|
7 |
-
*
|
8 |
-
* @
|
9 |
-
* @since 0.1
|
10 |
* @version 1.3.5
|
11 |
*/
|
12 |
-
if (! class_exists('myCRED_Module') ) :
|
13 |
-
|
14 |
-
{
|
15 |
|
16 |
-
|
17 |
-
|
18 |
|
19 |
-
|
20 |
-
|
21 |
|
22 |
-
|
23 |
-
|
24 |
|
25 |
-
|
26 |
-
|
27 |
|
28 |
-
|
29 |
-
|
30 |
|
31 |
-
|
32 |
-
|
33 |
|
34 |
-
|
35 |
-
|
36 |
|
37 |
-
|
38 |
-
|
39 |
|
40 |
-
|
41 |
-
|
42 |
|
43 |
-
|
44 |
-
|
45 |
|
46 |
-
|
47 |
-
|
48 |
|
49 |
-
|
50 |
-
|
51 |
|
52 |
-
|
53 |
-
|
54 |
|
55 |
-
|
56 |
-
|
57 |
|
58 |
-
|
59 |
-
|
60 |
|
61 |
-
|
62 |
-
|
63 |
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
{
|
69 |
|
70 |
-
|
71 |
-
|
72 |
-
}
|
73 |
|
74 |
-
|
75 |
-
|
76 |
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
|
82 |
-
|
83 |
-
|
84 |
-
}
|
85 |
|
86 |
-
|
87 |
|
88 |
-
|
89 |
-
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
-
|
94 |
-
|
95 |
-
|
96 |
-
|
97 |
-
|
98 |
-
|
99 |
-
|
100 |
-
|
101 |
-
|
102 |
-
|
103 |
-
|
104 |
-
|
105 |
-
|
106 |
|
107 |
-
|
108 |
-
|
109 |
|
110 |
-
|
111 |
-
|
112 |
-
}
|
113 |
|
114 |
-
|
115 |
-
|
116 |
-
|
117 |
-
}
|
118 |
|
119 |
-
|
120 |
-
|
121 |
-
|
122 |
|
123 |
-
|
124 |
-
|
125 |
-
}
|
126 |
|
127 |
-
|
128 |
-
|
129 |
-
|
130 |
-
|
131 |
|
132 |
-
|
133 |
-
|
134 |
-
|
135 |
|
136 |
-
|
137 |
|
138 |
-
|
139 |
|
140 |
-
|
141 |
-
|
142 |
-
|
143 |
-
|
144 |
-
|
145 |
-
|
146 |
-
public function set_settings()
|
147 |
-
{
|
148 |
|
149 |
-
|
150 |
|
151 |
-
|
152 |
-
|
153 |
|
154 |
-
|
155 |
-
|
156 |
-
|
157 |
-
}
|
158 |
|
159 |
-
|
160 |
-
|
161 |
-
|
162 |
-
}
|
163 |
|
164 |
-
|
165 |
-
|
166 |
-
|
167 |
-
}
|
168 |
|
169 |
-
|
170 |
|
171 |
-
|
172 |
-
|
173 |
|
174 |
-
|
175 |
-
|
176 |
|
177 |
-
|
178 |
-
|
179 |
|
180 |
-
|
181 |
-
|
182 |
-
|
183 |
-
|
184 |
-
|
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 |
-
|
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']) || ! isset( $_GET['page'] ) ) {
|
519 |
-
return;
|
520 |
-
}
|
521 |
-
|
522 |
-
$settings_key = 'mycred_epp_' . sanitize_key( $_GET['page'] );
|
523 |
|
524 |
-
|
525 |
-
|
526 |
-
|
527 |
-
|
528 |
-
|
529 |
-
|
530 |
-
|
531 |
-
|
532 |
-
|
533 |
-
|
534 |
-
|
535 |
-
|
536 |
-
|
537 |
-
|
538 |
-
|
539 |
-
|
540 |
-
|
541 |
-
|
542 |
-
|
543 |
-
|
544 |
-
|
545 |
-
|
546 |
-
|
547 |
-
|
548 |
-
|
549 |
-
|
550 |
-
|
551 |
-
|
552 |
-
|
553 |
-
|
554 |
-
|
555 |
-
|
556 |
-
|
557 |
-
|
558 |
-
|
559 |
-
|
560 |
-
|
561 |
-
|
562 |
-
|
563 |
-
|
564 |
-
|
565 |
-
|
566 |
-
|
567 |
-
|
568 |
-
|
569 |
-
|
570 |
-
|
571 |
-
|
572 |
-
|
573 |
-
|
574 |
-
|
575 |
-
|
576 |
-
|
577 |
-
|
578 |
-
|
579 |
-
|
580 |
-
|
581 |
-
|
582 |
-
|
583 |
-
|
584 |
-
|
585 |
-
|
586 |
-
|
587 |
-
|
588 |
-
|
589 |
-
|
590 |
-
|
591 |
-
|
592 |
-
|
593 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
594 |
<!-- myCRED Accordion Styling -->
|
595 |
<style type="text/css">
|
596 |
h4:before { float:right; padding-right: 12px; font-size: 14px; font-weight: normal; color: silver; }
|
597 |
-
h4.ui-accordion-header.ui-state-active:before { content: "<?php esc_html_e('click to close', 'mycred'); ?>"; }
|
598 |
-
h4.ui-accordion-header:before { content: "<?php esc_html_e('click to open', 'mycred'); ?>"; }
|
599 |
</style>
|
600 |
-
|
601 |
-
|
602 |
-
|
603 |
-
|
604 |
-
|
605 |
-
|
606 |
-
|
607 |
-
|
608 |
-
|
609 |
-
|
610 |
-
|
611 |
-
|
612 |
-
|
613 |
-
|
614 |
-
|
615 |
-
|
616 |
-
|
617 |
-
|
618 |
-
|
619 |
-
|
620 |
-
|
621 |
-
|
622 |
-
|
623 |
-
|
624 |
-
|
625 |
-
|
626 |
-
|
627 |
-
|
628 |
-
|
629 |
-
|
630 |
-
|
631 |
-
|
632 |
-
|
633 |
-
|
634 |
-
|
635 |
-
|
636 |
-
|
637 |
-
|
638 |
-
|
639 |
-
|
640 |
-
|
641 |
-
|
642 |
-
|
643 |
-
|
644 |
-
|
645 |
-
|
646 |
-
|
647 |
-
|
648 |
-
|
649 |
-
|
650 |
-
|
651 |
-
|
652 |
-
|
653 |
-
|
654 |
-
|
655 |
-
|
656 |
-
|
657 |
-
|
658 |
-
|
659 |
-
|
660 |
-
|
661 |
-
|
662 |
-
|
663 |
-
|
664 |
-
|
665 |
-
|
666 |
-
|
667 |
-
|
668 |
-
|
669 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
670 |
|
671 |
-
|
672 |
-
|
673 |
-
|
674 |
-
|
675 |
-
|
676 |
-
|
677 |
-
public function sanitize_extra_settings( $new_data, $data, $core )
|
678 |
-
{
|
679 |
-
|
680 |
-
return $new_data;
|
681 |
-
|
682 |
-
}
|
683 |
-
|
684 |
-
/**
|
685 |
-
* Input Field Name Value
|
686 |
-
*
|
687 |
-
* @since 0.1
|
688 |
-
* @version 1.0
|
689 |
-
*/
|
690 |
-
public function field_name( $name = '' )
|
691 |
-
{
|
692 |
-
|
693 |
-
if (is_array($name) ) {
|
694 |
-
|
695 |
-
$array = array();
|
696 |
-
foreach ( $name as $parent => $child ) {
|
697 |
-
|
698 |
-
if (! is_numeric($parent) ) {
|
699 |
-
$array[] = $parent;
|
700 |
-
}
|
701 |
-
|
702 |
-
if (! empty($child) && ! is_array($child) ) {
|
703 |
-
$array[] = $child;
|
704 |
-
}
|
705 |
-
|
706 |
-
}
|
707 |
-
$name = '[' . implode('][', $array) . ']';
|
708 |
-
|
709 |
-
}
|
710 |
-
else {
|
711 |
-
|
712 |
-
$name = '[' . $name . ']';
|
713 |
-
|
714 |
-
}
|
715 |
-
|
716 |
-
if ($this->add_to_core === true ) {
|
717 |
-
$name = '[' . $this->module_name . ']' . $name;
|
718 |
-
}
|
719 |
-
|
720 |
-
if ($this->option_id != '' ) {
|
721 |
-
return $this->option_id . $name;
|
722 |
-
}
|
723 |
-
|
724 |
-
return 'mycred_pref_core' . $name;
|
725 |
-
|
726 |
-
}
|
727 |
-
|
728 |
-
/**
|
729 |
-
* Input Field Id Value
|
730 |
-
*
|
731 |
-
* @since 0.1
|
732 |
-
* @version 1.0
|
733 |
-
*/
|
734 |
-
public function field_id( $id = '' )
|
735 |
-
{
|
736 |
|
737 |
-
|
738 |
|
739 |
-
|
740 |
-
|
741 |
|
742 |
-
|
743 |
-
|
744 |
-
}
|
745 |
|
746 |
-
|
747 |
-
|
748 |
-
}
|
749 |
|
750 |
-
|
751 |
-
|
752 |
|
753 |
-
|
754 |
-
|
755 |
|
756 |
-
|
757 |
|
758 |
-
|
759 |
|
760 |
-
|
761 |
-
|
762 |
-
}
|
763 |
|
764 |
-
|
765 |
-
|
766 |
-
|
767 |
-
|
768 |
|
769 |
-
|
770 |
|
771 |
-
|
772 |
|
773 |
-
|
774 |
-
|
775 |
-
|
776 |
-
|
777 |
-
|
778 |
-
|
779 |
-
public function available_template_tags( $available = array() )
|
780 |
-
{
|
781 |
|
782 |
-
|
783 |
|
784 |
-
|
785 |
|
786 |
-
|
787 |
-
|
788 |
-
|
789 |
-
|
790 |
-
|
791 |
-
|
792 |
-
public function get_settings_url( $module = '' )
|
793 |
-
{
|
794 |
|
795 |
-
|
796 |
-
|
797 |
-
|
798 |
-
}
|
799 |
|
800 |
-
|
801 |
|
802 |
-
|
803 |
|
804 |
-
|
805 |
|
806 |
-
|
807 |
-
|
808 |
-
|
809 |
-
|
810 |
-
|
811 |
-
|
812 |
-
public function request_to_entry( $request = array() )
|
813 |
-
{
|
814 |
|
815 |
-
|
816 |
-
}
|
817 |
|
818 |
-
|
819 |
|
820 |
-
|
821 |
-
|
822 |
-
|
823 |
-
|
824 |
-
|
825 |
-
|
826 |
-
|
827 |
-
|
828 |
|
829 |
-
|
830 |
|
831 |
-
|
832 |
|
833 |
-
|
834 |
endif;
|
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'] ) || ! isset( $_GET['page'] ) ) return;
|
457 |
+
|
458 |
+
$settings_key = 'mycred_epp_' . sanitize_key( $_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 esc_html_e( 'click to close', 'mycred' ); ?>"; }
|
525 |
+
h4.ui-accordion-header:before { content: "<?php esc_html_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="' . esc_attr( $class ) . '"><p>' . esc_html( $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;
|
abstracts/mycred-abstract-object.php
CHANGED
@@ -1,117 +1,103 @@
|
|
1 |
<?php
|
2 |
-
if (! defined('myCRED_VERSION') )
|
3 |
-
}
|
4 |
|
5 |
/**
|
6 |
* myCRED_Object class
|
7 |
-
*
|
8 |
-
* @
|
9 |
-
* @since 1.7
|
10 |
* @version 1.1
|
11 |
*/
|
12 |
-
if (! class_exists('myCRED_Object') ) :
|
13 |
-
|
14 |
-
{
|
15 |
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
{
|
21 |
-
}
|
22 |
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
{
|
28 |
|
29 |
-
|
30 |
-
}
|
31 |
|
32 |
-
|
33 |
-
|
34 |
|
35 |
-
|
36 |
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
|
41 |
-
|
42 |
-
|
43 |
-
}
|
44 |
|
45 |
-
|
46 |
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
}
|
52 |
|
53 |
-
|
54 |
|
55 |
-
|
56 |
-
|
57 |
|
58 |
-
|
59 |
-
|
60 |
-
}
|
61 |
|
62 |
-
|
63 |
|
64 |
-
|
65 |
|
66 |
-
|
67 |
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
{
|
73 |
|
74 |
-
|
75 |
-
}
|
76 |
|
77 |
-
|
78 |
|
79 |
-
|
80 |
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
|
85 |
-
|
86 |
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
-
|
91 |
-
$this->$key[ $array_value ] = $new_value;
|
92 |
|
93 |
-
|
94 |
|
95 |
-
|
96 |
|
97 |
-
|
98 |
-
|
99 |
-
|
100 |
-
|
101 |
-
}
|
102 |
|
103 |
-
|
104 |
|
105 |
-
|
106 |
-
|
107 |
|
108 |
-
|
109 |
|
110 |
-
|
111 |
|
112 |
-
|
113 |
|
114 |
-
|
115 |
|
116 |
-
|
117 |
endif;
|
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;
|
addons/badges/assets/css/front.css
CHANGED
@@ -1,7 +1,7 @@
|
|
1 |
.the-badge {
|
2 |
display: flex;
|
3 |
align-items: center;
|
4 |
-
|
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,45 +1,33 @@
|
|
1 |
-
jQuery(document).ready(
|
2 |
-
function () {
|
3 |
|
4 |
-
|
5 |
-
|
6 |
-
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
}
|
12 |
-
);
|
13 |
-
}
|
14 |
-
);
|
15 |
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
}
|
23 |
-
);
|
24 |
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
}
|
32 |
-
);
|
33 |
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
)
|
43 |
-
}
|
44 |
-
);
|
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 |
|
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,818 +1,721 @@
|
|
1 |
<?php
|
2 |
-
if (! defined('myCRED_VERSION') )
|
3 |
-
}
|
4 |
|
5 |
/**
|
6 |
* Get Badge
|
7 |
-
*
|
8 |
-
* @since 1.7
|
9 |
* @version 1.1
|
10 |
*/
|
11 |
-
if (! function_exists('mycred_get_badge') ) :
|
12 |
-
|
13 |
-
{
|
14 |
|
15 |
-
|
16 |
-
}
|
17 |
|
18 |
-
|
19 |
|
20 |
-
|
21 |
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
|
29 |
-
|
30 |
|
31 |
-
|
32 |
|
33 |
-
|
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 |
-
|
47 |
-
{
|
48 |
|
49 |
-
|
50 |
-
|
51 |
|
52 |
-
|
53 |
|
54 |
-
|
55 |
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
|
61 |
-
|
62 |
-
|
63 |
-
}
|
64 |
|
65 |
-
|
66 |
-
}
|
67 |
|
68 |
-
|
69 |
-
|
70 |
-
}
|
71 |
|
72 |
-
|
73 |
-
|
74 |
-
}
|
75 |
|
76 |
-
|
77 |
-
|
78 |
|
79 |
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
|
86 |
-
|
87 |
-
|
88 |
-
}
|
89 |
|
90 |
-
|
91 |
-
|
92 |
-
}
|
93 |
|
94 |
-
|
95 |
|
96 |
-
|
97 |
-
}
|
98 |
|
99 |
-
|
100 |
|
101 |
-
|
102 |
-
}
|
103 |
|
104 |
-
|
105 |
-
|
106 |
-
}
|
107 |
|
108 |
-
|
109 |
-
|
110 |
-
}
|
111 |
|
112 |
-
|
113 |
|
114 |
-
|
115 |
|
116 |
-
|
117 |
-
|
118 |
|
119 |
-
|
120 |
-
|
121 |
-
}
|
122 |
|
123 |
-
|
124 |
|
125 |
-
|
126 |
|
127 |
-
|
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 |
-
|
141 |
-
{
|
142 |
|
143 |
-
|
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 |
-
|
157 |
-
{
|
158 |
|
159 |
-
|
160 |
-
|
161 |
|
162 |
-
|
163 |
-
|
164 |
|
165 |
-
|
166 |
-
|
167 |
|
168 |
-
|
169 |
-
|
170 |
|
171 |
-
|
172 |
-
|
173 |
-
|
174 |
-
}
|
175 |
|
176 |
-
|
177 |
-
|
178 |
-
|
179 |
-
|
180 |
-
|
181 |
-
|
182 |
-
|
183 |
-
|
184 |
-
|
185 |
-
|
186 |
-
|
187 |
-
|
188 |
|
189 |
-
|
190 |
|
191 |
-
|
192 |
|
193 |
-
|
194 |
|
195 |
-
|
196 |
|
197 |
-
|
198 |
-
|
199 |
|
200 |
-
|
201 |
|
202 |
-
|
203 |
|
204 |
-
|
205 |
|
206 |
-
|
207 |
|
208 |
-
|
209 |
-
|
210 |
-
}
|
211 |
|
212 |
-
|
213 |
-
|
214 |
-
|
215 |
-
|
216 |
-
|
217 |
-
|
218 |
-
|
219 |
-
|
220 |
-
|
221 |
-
|
222 |
-
|
223 |
-
|
224 |
-
|
225 |
-
|
226 |
-
|
227 |
-
|
228 |
-
|
229 |
-
|
230 |
-
|
231 |
-
|
232 |
-
}
|
233 |
|
234 |
-
|
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 |
-
|
248 |
-
{
|
249 |
|
250 |
-
|
251 |
-
|
252 |
|
253 |
-
|
254 |
|
255 |
-
|
256 |
|
257 |
-
|
258 |
-
|
259 |
|
260 |
-
|
261 |
-
|
262 |
-
|
263 |
|
264 |
-
|
265 |
-
|
266 |
-
|
267 |
|
268 |
-
|
269 |
-
|
270 |
-
}
|
271 |
|
272 |
-
|
273 |
-
|
274 |
-
}
|
275 |
|
276 |
-
|
277 |
-
|
278 |
-
|
279 |
-
|
280 |
-
}
|
281 |
|
282 |
-
|
283 |
-
|
284 |
-
|
285 |
-
|
286 |
-
|
287 |
-
|
288 |
|
289 |
-
|
290 |
|
291 |
-
|
292 |
-
|
293 |
-
|
294 |
|
295 |
-
|
296 |
|
297 |
-
|
298 |
-
|
299 |
-
|
300 |
-
|
301 |
-
|
302 |
-
}
|
303 |
|
304 |
-
|
305 |
|
306 |
-
|
307 |
-
|
308 |
-
|
309 |
|
310 |
-
|
311 |
-
|
312 |
|
313 |
-
|
314 |
|
315 |
-
|
316 |
-
|
317 |
-
}
|
318 |
|
319 |
-
|
320 |
-
|
321 |
-
|
322 |
-
|
323 |
-
}
|
324 |
|
325 |
-
|
326 |
-
|
327 |
-
|
328 |
-
}
|
329 |
|
330 |
-
|
331 |
-
|
332 |
-
}
|
333 |
|
334 |
-
|
335 |
|
336 |
-
|
337 |
|
338 |
-
|
339 |
-
}
|
340 |
|
341 |
-
|
342 |
|
343 |
-
|
344 |
|
345 |
-
|
346 |
-
|
347 |
-
}
|
348 |
|
349 |
-
|
350 |
|
351 |
-
|
352 |
|
353 |
-
|
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 |
-
|
368 |
-
{
|
369 |
|
370 |
-
|
371 |
|
372 |
-
|
373 |
-
}
|
374 |
|
375 |
-
|
376 |
-
|
377 |
|
378 |
-
|
379 |
-
|
380 |
-
}
|
381 |
|
382 |
-
|
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 |
-
|
396 |
-
{
|
397 |
|
398 |
-
|
399 |
-
|
400 |
-
|
401 |
-
}
|
402 |
|
403 |
-
|
404 |
|
405 |
-
|
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 |
-
|
419 |
-
{
|
420 |
|
421 |
-
|
422 |
-
|
423 |
-
}
|
424 |
|
425 |
-
|
426 |
-
|
427 |
|
428 |
-
|
429 |
-
|
430 |
-
}
|
431 |
|
432 |
-
|
433 |
-
|
434 |
-
}
|
435 |
|
436 |
-
|
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 |
-
|
450 |
-
{
|
451 |
|
452 |
-
|
453 |
-
|
454 |
|
455 |
-
|
456 |
-
}
|
457 |
|
458 |
-
|
459 |
-
|
460 |
|
461 |
-
|
462 |
-
|
463 |
-
}
|
464 |
|
465 |
-
|
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 |
-
|
479 |
-
{
|
480 |
|
481 |
-
|
482 |
-
|
483 |
-
}
|
484 |
|
485 |
-
|
486 |
-
|
487 |
-
|
488 |
|
489 |
-
|
490 |
-
|
491 |
-
}
|
492 |
|
493 |
-
|
494 |
-
|
495 |
|
496 |
-
|
497 |
-
|
498 |
-
}
|
499 |
|
500 |
-
|
501 |
|
502 |
-
|
503 |
|
504 |
-
|
505 |
-
|
506 |
|
507 |
-
|
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 |
-
|
521 |
-
{
|
522 |
|
523 |
-
|
524 |
-
|
525 |
|
526 |
-
|
527 |
-
}
|
528 |
|
529 |
-
|
530 |
-
|
531 |
|
532 |
-
|
533 |
-
|
534 |
-
}
|
535 |
|
536 |
-
|
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 |
-
|
549 |
-
{
|
550 |
|
551 |
-
|
552 |
-
|
553 |
-
|
554 |
|
555 |
-
|
556 |
-
}
|
557 |
|
558 |
-
|
559 |
-
|
560 |
|
561 |
-
|
562 |
-
|
563 |
-
}
|
564 |
|
565 |
-
|
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 |
-
|
579 |
-
{
|
580 |
|
581 |
-
|
582 |
-
|
583 |
-
|
584 |
|
585 |
-
|
586 |
-
}
|
587 |
|
588 |
-
|
589 |
|
590 |
-
|
591 |
|
592 |
-
|
593 |
|
594 |
-
|
595 |
-
|
596 |
|
597 |
-
|
598 |
-
|
599 |
|
600 |
-
|
601 |
-
|
602 |
-
|
603 |
-
}
|
604 |
|
605 |
-
|
606 |
|
607 |
-
|
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 |
-
|
620 |
-
{
|
621 |
|
622 |
-
|
623 |
-
|
624 |
|
625 |
-
|
626 |
-
}
|
627 |
|
628 |
-
|
629 |
|
630 |
-
|
631 |
-
|
632 |
-
}
|
633 |
|
634 |
-
|
635 |
-
|
636 |
|
637 |
-
|
638 |
-
|
639 |
-
}
|
640 |
|
641 |
-
|
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 |
-
|
655 |
-
{
|
656 |
|
657 |
-
|
658 |
-
}
|
659 |
|
660 |
-
|
661 |
|
662 |
-
|
663 |
-
|
664 |
-
}
|
665 |
|
666 |
-
|
667 |
-
|
668 |
|
669 |
-
|
670 |
|
671 |
-
|
672 |
-
|
673 |
|
674 |
-
|
675 |
|
676 |
-
|
677 |
|
678 |
-
|
679 |
-
|
680 |
-
|
681 |
-
|
682 |
-
|
683 |
-
|
684 |
-
$badge_ids[ $badge_id ] = absint($badge->meta_value);
|
685 |
-
}
|
686 |
|
687 |
-
|
688 |
|
689 |
-
|
690 |
|
691 |
-
|
692 |
|
693 |
-
|
694 |
-
|
695 |
-
|
696 |
-
|
697 |
-
|
698 |
|
699 |
-
|
700 |
-
|
701 |
-
|
702 |
-
$clean_ids[ $id ] = absint($level);
|
703 |
|
704 |
-
|
705 |
-
|
706 |
|
707 |
-
|
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 |
-
|
721 |
-
{
|
722 |
|
723 |
-
|
724 |
-
|
725 |
-
}
|
726 |
|
727 |
-
|
728 |
|
729 |
-
|
730 |
|
731 |
-
|
732 |
|
733 |
-
|
734 |
|
735 |
-
|
736 |
|
737 |
-
|
738 |
-
|
739 |
-
}
|
740 |
|
741 |
-
|
742 |
-
|
743 |
|
744 |
-
|
745 |
|
746 |
-
|
747 |
-
|
748 |
-
|
749 |
-
|
750 |
-
}
|
751 |
|
752 |
-
|
753 |
-
|
754 |
-
}
|
755 |
|
756 |
-
|
757 |
|
758 |
-
|
759 |
|
760 |
-
|
761 |
|
762 |
-
|
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 |
-
|
776 |
-
{
|
777 |
|
778 |
-
|
779 |
-
|
780 |
-
}
|
781 |
|
782 |
-
|
783 |
|
784 |
-
|
785 |
-
|
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 |
-
|
797 |
|
798 |
-
|
799 |
|
800 |
-
|
801 |
endif;
|
802 |
|
803 |
/**
|
804 |
* Get Badges by Term ID
|
805 |
-
*
|
806 |
-
* @since 2.1
|
807 |
* @version 1.0
|
808 |
-
* @param
|
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,18 +734,16 @@ endif;
|
|
831 |
|
832 |
/**
|
833 |
* Get Badge/ Level Requirements
|
834 |
-
*
|
835 |
-
* @since 2.1
|
836 |
* @version 1.0
|
837 |
-
* @param
|
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,19 +758,16 @@ if(!function_exists('mycred_show_badge_requirements') ) :
|
|
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 |
-
|
871 |
$reference = $references[$requirement['reference']];
|
872 |
-
}
|
873 |
|
874 |
$base_requirements[$requirement_row] = array(
|
875 |
'type' => $requirement['type'],
|
@@ -886,25 +784,22 @@ if(!function_exists('mycred_show_badge_requirements') ) :
|
|
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,44 +809,38 @@ if(!function_exists('mycred_show_badge_requirements') ) :
|
|
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(
|
923 |
-
|
924 |
-
$rendered_row = sprintf(
|
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) )
|
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,20 +850,18 @@ endif;
|
|
961 |
|
962 |
/**
|
963 |
* Get users have have specific badge
|
964 |
-
*
|
965 |
-
* @param
|
966 |
-
* @
|
967 |
-
* @
|
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,7 +870,7 @@ if(!function_exists('mycred_get_users_has_earned_badge') ) :
|
|
983 |
)
|
984 |
);
|
985 |
|
986 |
-
$users = get_users($args);
|
987 |
|
988 |
foreach ( $users as $user ) {
|
989 |
|
@@ -992,24 +879,25 @@ if(!function_exists('mycred_get_users_has_earned_badge') ) :
|
|
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,20 +908,19 @@ endif;
|
|
1020 |
|
1021 |
/**
|
1022 |
* Get Badge Types
|
1023 |
-
*
|
1024 |
-
* @since 2.1
|
1025 |
* @version 2.1
|
1026 |
-
* @param
|
1027 |
-
* @return
|
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 |
-
|
|
|
1037 |
|
1038 |
return $badge_type;
|
1039 |
}
|
@@ -1045,31 +932,27 @@ endif;
|
|
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
|
1052 |
-
* @return
|
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,36 +962,34 @@ endif;
|
|
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 |
-
|
1088 |
-
{
|
1089 |
|
1090 |
-
|
1091 |
|
1092 |
-
|
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 |
-
|
1104 |
|
1105 |
-
|
1106 |
-
|
1107 |
-
|
1108 |
|
1109 |
-
|
1110 |
|
1111 |
-
if (get_post_status($pageId) == 'publish' ) {
|
1112 |
|
1113 |
$canCreatePage = false;
|
1114 |
$evidencePageId = $pageId;
|
@@ -1117,7 +998,7 @@ if (! function_exists('mycred_get_evidence_page_id') ) :
|
|
1117 |
|
1118 |
}
|
1119 |
|
1120 |
-
if ($canCreatePage ) {
|
1121 |
|
1122 |
$postData = array(
|
1123 |
'post_content' => '[' . MYCRED_SLUG . '_badge_evidence]',
|
@@ -1128,13 +1009,13 @@ if (! function_exists('mycred_get_evidence_page_id') ) :
|
|
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,77 +1028,72 @@ endif;
|
|
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 |
-
|
1156 |
-
{
|
1157 |
|
1158 |
-
|
1159 |
|
1160 |
-
|
1161 |
|
1162 |
-
|
1163 |
|
1164 |
-
|
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 |
-
|
1179 |
-
{
|
1180 |
|
1181 |
-
|
1182 |
|
1183 |
-
|
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 |
-
|
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,25 +1112,23 @@ if (! function_exists('mycred_get_uncategorized_badge_list') ) :
|
|
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 |
-
|
1255 |
-
{
|
1256 |
|
1257 |
-
|
1258 |
|
1259 |
$args = array(
|
1260 |
'taxonomy' => MYCRED_BADGE_CATEGORY,
|
@@ -1264,8 +1138,8 @@ if (! function_exists('mycred_get_categorized_badge_list') ) :
|
|
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,10 +1149,10 @@ if (! function_exists('mycred_get_categorized_badge_list') ) :
|
|
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,17 +1164,17 @@ if (! function_exists('mycred_get_categorized_badge_list') ) :
|
|
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,66 +1193,61 @@ if (! function_exists('mycred_get_categorized_badge_list') ) :
|
|
1319 |
}
|
1320 |
|
1321 |
return array(
|
1322 |
-
|
1323 |
-
|
1324 |
-
|
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 |
-
|
1338 |
-
{
|
1339 |
|
1340 |
-
|
1341 |
|
1342 |
-
|
1343 |
-
}
|
1344 |
|
1345 |
-
|
1346 |
|
1347 |
-
|
1348 |
-
|
1349 |
-
|
1350 |
|
1351 |
-
|
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 |
-
|
1364 |
-
{
|
1365 |
|
1366 |
-
|
1367 |
|
1368 |
-
|
1369 |
|
1370 |
-
|
1371 |
|
1372 |
-
|
1373 |
|
1374 |
-
|
1375 |
|
1376 |
-
|
1377 |
-
}
|
1378 |
|
1379 |
-
|
1380 |
-
if(
|
1381 |
-
|
|
|
1382 |
) {
|
1383 |
|
1384 |
$facebook_url = "http://www.facebook.com/sharer.php?u=".get_permalink()."&p[images][0]=$image_url";
|
@@ -1386,169 +1255,157 @@ if (! function_exists('mycred_badge_show_main_image_with_social_icons') ) :
|
|
1386 |
$linkedin_url = "http://www.linkedin.com/shareArticle?url=".get_permalink()."";
|
1387 |
$pinterest_url = "https://pinterest.com/pin/create/bookmarklet/?media=$image_url&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 |
-
|
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 |
-
|
1410 |
-
{
|
1411 |
|
1412 |
-
|
1413 |
|
1414 |
-
|
1415 |
-
}
|
1416 |
|
1417 |
-
|
1418 |
|
1419 |
-
|
1420 |
$content .= "<p>" . $post->post_content . "</p>";
|
1421 |
-
|
1422 |
-
|
1423 |
|
1424 |
-
|
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 |
-
|
1437 |
-
{
|
1438 |
|
1439 |
-
|
1440 |
|
1441 |
-
|
1442 |
-
}
|
1443 |
|
1444 |
-
|
1445 |
|
1446 |
-
|
1447 |
$content .= "<h3>" . __("Levels", "mycred") . "</h3>";
|
1448 |
-
|
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 |
-
|
1457 |
|
1458 |
-
|
1459 |
|
1460 |
-
|
1461 |
|
1462 |
-
|
1463 |
|
1464 |
-
|
1465 |
|
1466 |
-
|
1467 |
|
1468 |
-
|
1469 |
-
|
1470 |
-
}
|
1471 |
|
1472 |
-
|
1473 |
-
|
1474 |
|
1475 |
-
|
1476 |
|
1477 |
-
|
1478 |
-
|
1479 |
-
}
|
1480 |
|
1481 |
-
|
1482 |
|
1483 |
-
|
1484 |
|
1485 |
-
|
1486 |
-
|
1487 |
|
1488 |
-
|
1489 |
-
|
1490 |
|
1491 |
-
|
1492 |
-
|
1493 |
-
|
1494 |
|
1495 |
-
|
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 |
-
|
1508 |
-
{
|
1509 |
|
1510 |
-
|
1511 |
|
1512 |
-
|
1513 |
-
}
|
1514 |
|
1515 |
-
|
1516 |
|
1517 |
-
|
1518 |
-
|
1519 |
-
|
1520 |
-
|
1521 |
-
|
1522 |
-
|
1523 |
-
|
1524 |
-
|
1525 |
-
|
1526 |
|
1527 |
-
|
1528 |
-
|
1529 |
-
|
1530 |
-
|
1531 |
$content .= '<div class="mycred-badge-earner-list">';
|
1532 |
|
1533 |
-
|
1534 |
|
1535 |
-
|
1536 |
|
1537 |
-
|
1538 |
-
|
1539 |
-
|
1540 |
-
|
1541 |
|
1542 |
-
|
1543 |
-
|
1544 |
-
$content .= '</div>';
|
1545 |
$content .= '</div>';
|
|
|
1546 |
|
1547 |
-
|
1548 |
-
|
1549 |
-
|
1550 |
|
1551 |
-
|
1552 |
|
1553 |
-
|
1554 |
-
endif;
|
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 wp_kses_post( 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 |
|
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 |
$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 |
//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 |
|
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 |
|
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 |
)
|
871 |
);
|
872 |
|
873 |
+
$users = get_users( $args );
|
874 |
|
875 |
foreach ( $users as $user ) {
|
876 |
|
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 |
|
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 |
|
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 |
|
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 |
|
999 |
}
|
1000 |
|
1001 |
+
if ( $canCreatePage ) {
|
1002 |
|
1003 |
$postData = array(
|
1004 |
'post_content' => '[' . MYCRED_SLUG . '_badge_evidence]',
|
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 |
|
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 |
|
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 |
'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 |
|
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 |
|
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 |
}
|
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 |
$linkedin_url = "http://www.linkedin.com/shareArticle?url=".get_permalink()."";
|
1256 |
$pinterest_url = "https://pinterest.com/pin/create/bookmarklet/?media=$image_url&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;
|
addons/badges/includes/mycred-badge-object.php
CHANGED
@@ -1,911 +1,822 @@
|
|
1 |
<?php
|
2 |
-
if (! defined('myCRED_VERSION') )
|
3 |
-
}
|
4 |
|
5 |
/**
|
6 |
* myCRED_Badge class
|
7 |
-
*
|
8 |
-
* @
|
9 |
-
* @since 1.7
|
10 |
* @version 1.1
|
11 |
*/
|
12 |
-
if (! class_exists('myCRED_Badge') ) :
|
13 |
-
|
14 |
-
{
|
15 |
|
16 |
-
|
17 |
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
|
23 |
-
|
24 |
-
|
25 |
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
|
31 |
-
|
32 |
-
|
33 |
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
|
38 |
-
|
39 |
-
|
40 |
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
{
|
51 |
|
52 |
-
|
53 |
|
54 |
-
|
55 |
-
|
56 |
|
57 |
-
|
58 |
-
|
59 |
|
60 |
-
|
61 |
-
}
|
62 |
|
63 |
-
|
64 |
-
|
65 |
|
66 |
-
|
67 |
|
68 |
-
|
69 |
-
}
|
70 |
|
71 |
-
|
72 |
|
73 |
-
|
74 |
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
protected function populate( $object = null, $level_id = null )
|
82 |
-
{
|
83 |
|
84 |
-
|
85 |
-
}
|
86 |
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
-
|
91 |
|
92 |
-
|
93 |
|
94 |
-
|
95 |
-
|
96 |
-
|
97 |
|
98 |
-
|
99 |
-
|
100 |
|
101 |
-
|
102 |
-
|
103 |
-
}
|
104 |
|
105 |
-
|
106 |
-
|
107 |
-
}
|
108 |
|
109 |
-
|
110 |
-
|
111 |
|
112 |
-
|
113 |
|
114 |
-
|
115 |
-
|
116 |
-
|
117 |
-
}
|
118 |
|
119 |
-
|
120 |
-
|
121 |
|
122 |
-
|
123 |
|
124 |
-
|
125 |
-
|
126 |
-
|
127 |
|
128 |
-
|
129 |
-
|
130 |
-
|
131 |
|
132 |
-
|
133 |
-
|
134 |
-
|
135 |
-
}
|
136 |
|
137 |
-
|
138 |
-
|
139 |
-
|
140 |
-
|
141 |
-
|
142 |
-
|
143 |
-
|
144 |
|
145 |
-
|
146 |
|
147 |
-
|
148 |
-
|
149 |
-
|
150 |
-
|
151 |
-
|
152 |
-
|
153 |
-
public function get_user_count( $level_id = null )
|
154 |
-
{
|
155 |
|
156 |
-
|
157 |
-
}
|
158 |
|
159 |
-
|
160 |
-
|
161 |
|
162 |
-
|
163 |
|
164 |
-
|
165 |
|
166 |
-
|
167 |
-
|
168 |
-
}
|
169 |
|
170 |
-
|
171 |
-
|
172 |
-
}
|
173 |
|
174 |
-
|
175 |
|
176 |
-
|
177 |
|
178 |
-
|
179 |
|
180 |
-
|
181 |
-
|
182 |
-
|
183 |
-
|
184 |
-
|
185 |
-
|
186 |
-
public function get_level( $level_id = false )
|
187 |
-
{
|
188 |
|
189 |
-
|
190 |
-
}
|
191 |
|
192 |
-
|
193 |
|
194 |
-
|
195 |
|
196 |
-
|
197 |
-
|
198 |
-
|
199 |
-
|
200 |
-
|
201 |
-
|
202 |
-
public function get_level_requirements( $level_id = false )
|
203 |
-
{
|
204 |
|
205 |
-
|
206 |
-
}
|
207 |
|
208 |
-
|
209 |
|
210 |
-
|
211 |
|
212 |
-
|
213 |
-
|
214 |
-
|
215 |
-
|
216 |
-
|
217 |
-
|
218 |
-
public function get_level_reward( $level_id = false )
|
219 |
-
{
|
220 |
|
221 |
-
|
222 |
-
}
|
223 |
|
224 |
-
|
225 |
|
226 |
-
|
227 |
|
228 |
-
|
229 |
-
|
230 |
-
|
231 |
-
|
232 |
-
|
233 |
-
|
234 |
-
public function user_has_badge( $user_id = false, $level_id = 0 )
|
235 |
-
{
|
236 |
|
237 |
-
|
238 |
-
|
239 |
-
}
|
240 |
|
241 |
-
|
242 |
-
|
243 |
|
244 |
-
|
245 |
|
246 |
-
|
247 |
|
248 |
-
|
249 |
-
|
250 |
-
}
|
251 |
|
252 |
-
|
253 |
|
254 |
-
|
255 |
|
256 |
-
|
257 |
|
258 |
-
|
259 |
-
|
260 |
-
|
261 |
-
|
262 |
-
|
263 |
-
|
264 |
-
public function get_users_current_level( $user_id = false )
|
265 |
-
{
|
266 |
|
267 |
-
|
268 |
-
}
|
269 |
|
270 |
-
|
271 |
|
272 |
-
|
273 |
|
274 |
-
|
275 |
-
|
276 |
-
}
|
277 |
|
278 |
-
|
279 |
-
|
280 |
|
281 |
-
|
282 |
|
283 |
-
|
284 |
|
285 |
-
|
286 |
-
|
287 |
-
|
288 |
-
|
289 |
-
|
290 |
-
|
291 |
-
public function query_users_level( $user_id = false )
|
292 |
-
{
|
293 |
|
294 |
-
|
295 |
-
}
|
296 |
|
297 |
-
|
298 |
|
299 |
-
|
300 |
-
|
301 |
-
|
302 |
-
|
303 |
-
|
304 |
|
305 |
-
|
306 |
-
|
307 |
-
|
308 |
|
309 |
-
|
310 |
-
|
311 |
-
}
|
312 |
|
313 |
-
|
314 |
-
|
315 |
-
}
|
316 |
|
317 |
-
|
318 |
-
|
319 |
-
|
320 |
-
}
|
321 |
|
322 |
-
|
323 |
|
324 |
-
|
325 |
|
326 |
-
|
327 |
-
}
|
328 |
|
329 |
-
|
330 |
|
331 |
-
|
332 |
-
|
333 |
|
334 |
-
|
335 |
-
|
336 |
|
337 |
-
|
338 |
-
|
339 |
|
340 |
-
|
341 |
-
|
342 |
-
}
|
343 |
|
344 |
-
|
345 |
|
346 |
-
|
347 |
-
|
348 |
|
349 |
-
|
350 |
-
|
351 |
-
}
|
352 |
|
353 |
-
|
354 |
|
355 |
-
|
356 |
|
357 |
-
|
358 |
|
359 |
-
|
360 |
|
361 |
-
|
362 |
-
|
363 |
-
|
364 |
-
|
365 |
-
|
366 |
-
|
367 |
-
public function get_users_next_level_id( $user_id = false )
|
368 |
-
{
|
369 |
|
370 |
-
|
371 |
-
|
372 |
-
}
|
373 |
|
374 |
-
|
375 |
-
|
376 |
-
|
377 |
-
}
|
378 |
|
379 |
-
|
380 |
|
381 |
-
|
382 |
|
383 |
-
|
384 |
-
|
385 |
-
|
386 |
-
|
387 |
-
|
388 |
-
|
389 |
-
public function get_users_next_level( $user_id = false )
|
390 |
-
{
|
391 |
|
392 |
-
|
393 |
-
|
394 |
-
}
|
395 |
|
396 |
-
|
397 |
|
398 |
-
|
399 |
|
400 |
-
|
401 |
|
402 |
-
|
403 |
-
|
404 |
-
|
405 |
-
|
406 |
-
|
407 |
-
|
408 |
-
|
409 |
-
public function assign( $user_id = false, $level_id = 0 )
|
410 |
-
{
|
411 |
|
412 |
-
|
413 |
-
}
|
414 |
|
415 |
-
|
416 |
-
|
417 |
|
418 |
-
|
419 |
|
420 |
-
|
421 |
-
|
422 |
-
|
423 |
-
}
|
424 |
|
425 |
-
|
426 |
|
427 |
-
|
428 |
|
429 |
-
|
430 |
-
|
431 |
-
|
432 |
-
|
433 |
|
434 |
-
|
435 |
|
436 |
-
|
437 |
-
|
438 |
-
|
439 |
|
440 |
-
|
441 |
-
|
442 |
-
|
443 |
-
|
444 |
-
|
445 |
-
|
446 |
-
|
447 |
-
|
448 |
-
|
449 |
-
|
450 |
-
|
451 |
-
mycred_update_user_meta($user_id, 'mycred_badge_ids', '', $badge_ids);
|
452 |
|
453 |
-
|
454 |
-
|
455 |
|
456 |
-
|
457 |
|
458 |
-
|
459 |
|
460 |
-
|
461 |
|
462 |
-
|
463 |
-
|
464 |
-
|
465 |
|
466 |
-
|
467 |
|
468 |
-
|
469 |
|
470 |
-
|
471 |
|
472 |
-
|
473 |
-
|
474 |
-
|
475 |
-
|
476 |
-
|
477 |
-
|
478 |
-
public function payout_reward( $previous_level = -1, $new_level = 0 )
|
479 |
-
{
|
480 |
|
481 |
-
|
482 |
-
|
483 |
|
484 |
-
|
485 |
-
|
486 |
-
}
|
487 |
|
488 |
-
|
489 |
|
490 |
-
|
491 |
-
|
492 |
|
493 |
-
|
494 |
|
495 |
-
|
496 |
|
497 |
-
|
498 |
-
|
499 |
-
|
500 |
-
|
501 |
-
|
502 |
-
|
503 |
-
|
504 |
-
|
505 |
-
|
506 |
|
507 |
-
|
508 |
|
509 |
-
|
510 |
|
511 |
-
|
512 |
|
513 |
-
|
514 |
|
515 |
-
|
516 |
-
|
517 |
|
518 |
-
|
519 |
-
|
520 |
|
521 |
-
|
522 |
-
|
523 |
-
}
|
524 |
|
525 |
-
|
526 |
|
527 |
-
|
528 |
-
|
529 |
|
530 |
-
|
531 |
|
532 |
-
|
533 |
|
534 |
-
|
535 |
-
|
536 |
-
|
537 |
-
|
538 |
-
|
539 |
-
|
540 |
-
|
541 |
-
|
542 |
-
|
543 |
|
544 |
-
|
545 |
|
546 |
-
|
547 |
|
548 |
-
|
549 |
|
550 |
-
|
551 |
|
552 |
-
|
553 |
|
554 |
-
|
555 |
|
556 |
-
|
557 |
|
558 |
-
|
559 |
-
|
560 |
-
|
561 |
-
|
562 |
-
|
563 |
-
|
564 |
-
public function assign_all()
|
565 |
-
{
|
566 |
|
567 |
-
|
568 |
-
}
|
569 |
|
570 |
-
|
571 |
|
572 |
-
|
573 |
|
574 |
-
|
575 |
-
|
576 |
|
577 |
-
|
578 |
-
|
579 |
|
580 |
-
|
581 |
-
|
582 |
-
|
583 |
|
584 |
-
|
585 |
|
586 |
-
|
587 |
-
|
588 |
-
|
589 |
|
590 |
-
|
591 |
|
592 |
-
|
593 |
-
|
594 |
-
|
595 |
-
|
596 |
-
}
|
597 |
|
598 |
-
|
599 |
|
600 |
-
|
601 |
-
|
602 |
|
603 |
-
|
604 |
|
605 |
-
|
606 |
-
|
607 |
|
608 |
-
|
609 |
|
610 |
-
|
611 |
-
|
612 |
|
613 |
-
|
614 |
-
|
615 |
-
|
616 |
|
617 |
-
|
618 |
|
619 |
-
|
620 |
-
|
621 |
-
|
622 |
|
623 |
-
|
624 |
-
|
625 |
|
626 |
-
|
627 |
|
628 |
-
|
629 |
-
|
630 |
|
631 |
-
|
632 |
-
|
633 |
|
634 |
-
|
635 |
-
|
636 |
-
|
637 |
-
|
638 |
-
|
639 |
-
|
640 |
-
|
641 |
-
|
642 |
-
|
643 |
-
}
|
644 |
|
645 |
-
|
646 |
|
647 |
-
|
648 |
-
|
649 |
|
650 |
-
|
651 |
|
652 |
-
|
653 |
-
|
654 |
-
|
655 |
-
|
656 |
-
|
657 |
-
|
658 |
-
|
659 |
-
|
660 |
-
|
661 |
-
|
662 |
-
}
|
663 |
|
664 |
-
|
665 |
-
|
666 |
-
|
667 |
-
|
668 |
-
}
|
669 |
|
670 |
-
|
671 |
|
672 |
-
|
673 |
-
|
674 |
-
}
|
675 |
|
676 |
-
|
677 |
-
|
678 |
-
|
679 |
-
|
680 |
|
681 |
-
|
682 |
|
683 |
-
|
684 |
-
|
685 |
|
686 |
-
|
687 |
-
|
688 |
-
|
689 |
|
690 |
-
|
691 |
|
692 |
-
|
693 |
-
|
694 |
|
695 |
-
|
696 |
-
|
697 |
-
|
698 |
-
|
699 |
|
700 |
-
|
701 |
-
|
702 |
-
|
703 |
-
}
|
704 |
|
705 |
-
|
706 |
-
|
707 |
|
708 |
-
|
709 |
|
710 |
-
|
711 |
-
mycred_update_user_meta($row->user_id, $this->user_meta_key, '_issued_on', time());
|
712 |
|
713 |
-
|
714 |
|
715 |
-
|
716 |
|
717 |
-
|
718 |
|
719 |
-
|
720 |
|
721 |
-
|
722 |
-
|
723 |
-
|
724 |
-
|
725 |
-
|
726 |
-
|
727 |
-
|
728 |
-
public function divest( $user_id = false )
|
729 |
-
{
|
730 |
|
731 |
-
|
732 |
-
}
|
733 |
|
734 |
-
|
735 |
-
|
736 |
-
|
737 |
|
738 |
-
|
739 |
-
|
740 |
-
}
|
741 |
|
742 |
-
|
743 |
-
|
744 |
-
}
|
745 |
|
746 |
-
|
747 |
-
|
748 |
|
749 |
-
|
750 |
|
751 |
-
|
752 |
|
753 |
-
|
754 |
-
|
755 |
-
|
756 |
-
|
757 |
-
|
758 |
-
|
759 |
-
public function divest_all()
|
760 |
-
{
|
761 |
|
762 |
-
|
763 |
-
}
|
764 |
|
765 |
-
|
766 |
|
767 |
-
|
768 |
-
|
769 |
-
|
770 |
-
|
771 |
-
|
772 |
-
|
773 |
|
774 |
-
|
775 |
|
776 |
-
|
777 |
|
778 |
-
|
779 |
|
780 |
-
|
781 |
|
782 |
-
|
783 |
-
|
784 |
-
|
785 |
-
|
786 |
-
|
787 |
-
|
788 |
-
public function delete( $delete_post = false )
|
789 |
-
{
|
790 |
|
791 |
-
|
792 |
-
}
|
793 |
|
794 |
-
|
795 |
|
796 |
-
|
797 |
|
798 |
-
|
799 |
-
|
800 |
-
}
|
801 |
|
802 |
-
|
803 |
|
804 |
-
|
805 |
-
|
806 |
-
}
|
807 |
|
808 |
-
|
809 |
|
810 |
-
|
811 |
|
812 |
-
|
813 |
-
|
814 |
-
|
815 |
-
|
816 |
-
|
817 |
-
|
818 |
-
public function get_image( $image = null )
|
819 |
-
{
|
820 |
|
821 |
-
|
822 |
|
823 |
-
|
824 |
-
|
825 |
|
826 |
-
|
827 |
|
828 |
-
|
829 |
|
830 |
-
|
831 |
|
832 |
-
|
833 |
-
|
834 |
|
835 |
-
|
836 |
-
}
|
837 |
|
838 |
-
|
839 |
|
840 |
-
|
841 |
|
842 |
-
|
843 |
|
844 |
-
|
845 |
-
{
|
846 |
|
847 |
-
|
848 |
|
849 |
-
|
850 |
-
|
851 |
|
852 |
-
|
853 |
|
854 |
-
|
855 |
-
|
856 |
-
|
857 |
-
|
858 |
|
859 |
-
|
860 |
|
861 |
-
|
862 |
-
}
|
863 |
|
864 |
-
|
865 |
|
866 |
-
|
867 |
-
|
868 |
-
}
|
869 |
|
870 |
-
|
871 |
|
872 |
-
|
873 |
|
874 |
-
|
875 |
-
{
|
876 |
|
877 |
-
|
878 |
|
879 |
-
|
880 |
|
881 |
-
|
882 |
-
|
883 |
-
|
884 |
|
885 |
-
|
886 |
|
887 |
-
|
888 |
|
889 |
-
|
890 |
|
891 |
-
|
892 |
|
893 |
-
|
894 |
-
|
895 |
-
|
896 |
|
897 |
-
|
898 |
-
|
899 |
|
900 |
-
|
901 |
|
902 |
-
|
903 |
|
904 |
-
|
905 |
|
906 |
-
|
907 |
|
908 |
-
|
909 |
|
910 |
-
|
911 |
-
endif;
|
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;
|
addons/badges/includes/mycred-badge-secondary.php
CHANGED
@@ -1,113 +1,103 @@
|
|
1 |
<?php
|
2 |
-
if (! defined('myCRED_VERSION') )
|
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 |
-
|
13 |
-
{
|
14 |
|
15 |
-
|
16 |
-
|
17 |
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
{
|
23 |
|
24 |
-
|
25 |
-
|
26 |
-
add_action('admin_head', array( $this, 'admin_header' ));
|
27 |
-
|
28 |
-
|
29 |
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
return self::$_instance;
|
42 |
-
}
|
43 |
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
global $wpdb, $mycred_log_table;
|
48 |
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
|
60 |
-
|
61 |
-
{
|
62 |
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
|
80 |
-
|
81 |
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
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 |
-
|
91 |
-
|
92 |
-
|
93 |
-
|
94 |
-
|
95 |
-
|
96 |
-
|
97 |
-
|
98 |
-
|
99 |
-
|
100 |
-
|
101 |
-
|
102 |
-
|
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 |
|
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 |
|
addons/badges/includes/mycred-badge-shortcodes.php
CHANGED
@@ -1,52 +1,44 @@
|
|
1 |
<?php
|
2 |
-
if (! defined('myCRED_VERSION') )
|
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 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
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,11 +46,11 @@ if (! function_exists('mycred_render_my_badges') ) :
|
|
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;
|
@@ -67,69 +59,69 @@ if (! function_exists('mycred_render_my_badges') ) :
|
|
67 |
$badge_title = $badge->title;
|
68 |
$badge_img = $badge->main_image;
|
69 |
|
70 |
-
|
71 |
-
|
72 |
-
if ($badge->main_image !== false ) {
|
73 |
|
74 |
echo '<div class="demo-badge-image">' . wp_kses_post( $badge_img ) . '</div>';
|
75 |
|
76 |
-
if($title == 'show') {
|
77 |
|
78 |
-
echo '<div class="demo-badge-title">' . esc_html( $badge_title ) . '
|
79 |
|
80 |
-
}
|
|
|
81 |
|
82 |
-
echo '<div class="demo-badge-title" style="display:none;">' . esc_html( $badge_title ) . '
|
83 |
|
84 |
}
|
85 |
|
86 |
-
if($post_excerpt == 'show') {
|
|
|
|
|
87 |
|
88 |
-
|
|
|
89 |
|
90 |
-
|
91 |
-
|
92 |
}
|
93 |
|
94 |
}
|
95 |
|
96 |
}
|
97 |
-
|
98 |
// User has earned badge
|
99 |
else {
|
100 |
|
101 |
$level = $users_badges[ $badge_id ];
|
102 |
-
$badge = mycred_get_badge($badge_id, $level);
|
103 |
$badge->image_width = $width;
|
104 |
$badge->image_height = $height;
|
105 |
|
106 |
-
|
107 |
-
|
108 |
-
|
109 |
|
110 |
-
if ($badge->level_image !== false ) {
|
111 |
|
|
|
112 |
|
113 |
-
|
114 |
|
115 |
-
|
116 |
-
|
117 |
-
echo '<div class="demo-badge-title">' . esc_html( $badge->title ) . ' '.'</div>';
|
118 |
|
119 |
}
|
120 |
-
|
121 |
else {
|
122 |
|
123 |
-
|
124 |
|
125 |
}
|
126 |
|
127 |
-
if($post_excerpt == 'show') {
|
128 |
-
|
129 |
-
echo
|
130 |
|
131 |
-
}
|
132 |
-
|
|
|
|
|
|
|
133 |
}
|
134 |
|
135 |
}
|
@@ -138,12 +130,15 @@ if (! function_exists('mycred_render_my_badges') ) :
|
|
138 |
|
139 |
echo '</div>';
|
140 |
|
141 |
-
if($title == 'show' || $post_excerpt == 'show') {
|
142 |
|
143 |
echo '<hr class="badge-line">';
|
|
|
144 |
}
|
145 |
else {
|
|
|
146 |
echo '';
|
|
|
147 |
}
|
148 |
}
|
149 |
|
@@ -153,7 +148,7 @@ if (! function_exists('mycred_render_my_badges') ) :
|
|
153 |
$output = ob_get_contents();
|
154 |
ob_end_clean();
|
155 |
|
156 |
-
return apply_filters('mycred_my_badges', $output, $user_id);
|
157 |
|
158 |
}
|
159 |
endif;
|
@@ -161,55 +156,48 @@ endif;
|
|
161 |
/**
|
162 |
* Shortcode: mycred_badges
|
163 |
* Allows you to show all published badges
|
164 |
-
*
|
165 |
-
* @since 1.5
|
166 |
* @version 1.1.1
|
167 |
*/
|
168 |
-
if (! function_exists('mycred_render_badges') ) :
|
169 |
-
function mycred_render_badges( $atts, $template = '' )
|
170 |
-
|
171 |
-
|
172 |
-
|
173 |
-
|
174 |
-
'width' => MYCRED_BADGE_WIDTH,
|
175 |
-
'height' => MYCRED_BADGE_HEIGHT
|
176 |
-
), $atts, MYCRED_SLUG . '_badges'
|
177 |
-
)
|
178 |
-
);
|
179 |
|
180 |
$all_badges = mycred_get_badge_ids();
|
181 |
|
182 |
-
if ($template == '' )
|
183 |
$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>';
|
184 |
-
}
|
185 |
|
186 |
$output = '<div id="mycred-all-badges">';
|
187 |
|
188 |
-
if (! empty($all_badges) ) {
|
189 |
|
190 |
foreach ( $all_badges as $badge_id ) {
|
191 |
|
192 |
-
$badge = mycred_get_badge($badge_id, 0);
|
193 |
$badge->image_width = $width;
|
194 |
$badge->image_height = $height;
|
195 |
|
196 |
$row = $template;
|
197 |
-
$row = str_replace('%badge_title%', $badge->title, $row);
|
198 |
-
$row = str_replace('%requirements%', mycred_display_badge_requirements($badge_id), $row);
|
199 |
-
$row = str_replace('%count%', $badge->earnedby, $row);
|
200 |
-
$row = str_replace('%default_image%', $badge->get_image('main'), $row);
|
201 |
|
202 |
-
if(mycred_user_has_badge(get_current_user_id(), $badge_id) ) {
|
203 |
$user_id = get_current_user_id();
|
204 |
-
$badge = mycred_get_badge($badge_id);
|
205 |
-
$level = $badge->get_users_current_level($user_id);
|
206 |
-
$row = str_replace('%main_image%', $badge->get_image($level), $row);
|
207 |
}
|
208 |
else {
|
209 |
-
$row = str_replace('%main_image%', '', $row);
|
210 |
}
|
211 |
|
212 |
-
$output .= apply_filters('mycred_badges_badge', $row, $badge);
|
213 |
|
214 |
}
|
215 |
|
@@ -217,30 +205,25 @@ if (! function_exists('mycred_render_badges') ) :
|
|
217 |
|
218 |
$output .= '</div>';
|
219 |
|
220 |
-
return apply_filters('mycred_badges', $output);
|
221 |
|
222 |
}
|
223 |
endif;
|
224 |
|
225 |
/**
|
226 |
* myCRED Renders Badges List ShortCode
|
227 |
-
*
|
228 |
-
* @
|
229 |
-
* @since 2.1
|
230 |
* @version 1.0
|
231 |
*/
|
232 |
-
if(!function_exists('mycred_render_badges_list') ) :
|
233 |
-
function mycred_render_badges_list( $atts = '' )
|
234 |
-
{
|
235 |
|
236 |
-
extract(
|
237 |
-
shortcode_atts(
|
238 |
-
array(
|
239 |
'achievement_tabs' => '1'
|
240 |
-
|
241 |
-
|
242 |
-
|
243 |
-
);
|
244 |
|
245 |
ob_start();?>
|
246 |
|
@@ -255,32 +238,32 @@ if(!function_exists('mycred_render_badges_list') ) :
|
|
255 |
</div>
|
256 |
|
257 |
<?php
|
258 |
-
if ($achievement_tabs == 1 ) {
|
259 |
|
260 |
$badges = mycred_get_categorized_badge_list();
|
261 |
|
262 |
-
if ($badges['category_count'] > 0 ) { ?>
|
263 |
<div class="mycred-badges-list-nav">
|
264 |
<ul class="mycred-badges-list-tabs">
|
265 |
<?php
|
266 |
-
|
267 |
|
268 |
-
|
269 |
|
270 |
-
|
271 |
?>
|
272 |
</ul>
|
273 |
</div>
|
274 |
<div class="mycred-badges-list-panels">
|
275 |
<?php
|
276 |
-
|
277 |
|
278 |
-
|
279 |
|
280 |
-
|
281 |
?>
|
282 |
</div>
|
283 |
-
|
284 |
}
|
285 |
|
286 |
}
|
@@ -327,39 +310,37 @@ endif;
|
|
327 |
|
328 |
/**
|
329 |
* Renders Badge's Evidence ShortCode
|
330 |
-
*
|
331 |
-
* @
|
332 |
-
* @since 2.1
|
333 |
* @version 1.0
|
334 |
*/
|
335 |
-
if (!function_exists('mycred_render_badge_evidence') ) :
|
336 |
-
function mycred_render_badge_evidence( $atts = '' )
|
337 |
-
{
|
338 |
|
339 |
$content = '<div class="mycred-evidence-page">Evidence not found</div>';
|
340 |
|
341 |
-
if (isset($_GET['uid']) && isset($_GET['bid']) ) {
|
342 |
|
343 |
-
$user_id = intval($_GET['uid']);
|
344 |
-
$badge_id = intval($_GET['bid']);
|
345 |
|
346 |
-
$user_info = get_userdata($user_id);
|
347 |
-
$badge = mycred_get_badge($badge_id);
|
348 |
|
349 |
-
if ($user_info && $badge && $badge->open_badge ) {
|
350 |
|
351 |
-
$issued_on = mycred_get_user_meta($user_id, MYCRED_BADGE_KEY . $badge_id, '_issued_on', true);
|
352 |
|
353 |
$content = '<div class="mycred-evidence-page">
|
354 |
<div class="mycred-left">
|
355 |
-
<img src="' . $badge->get_earned_image($user_id) . '" alt="">
|
356 |
</div>
|
357 |
<div class="mycred-left intro">
|
358 |
<h4 class="mycred-remove-margin">' . $badge->title . '</h4>
|
359 |
<div class="mycred-remove-margin">
|
360 |
<p>Name: '. $user_info->display_name .'</p>
|
361 |
<p>Email: ' . $user_info->user_email . '</p>
|
362 |
-
<p>Issued On: ' . date('Y-m-d\TH:i:sP', $issued_on) . '</p>
|
363 |
<p><span class="dashicons dashicons-yes-alt"></span> <span class="icon-txt"> Verified</span></p>
|
364 |
</div>
|
365 |
</div>
|
@@ -375,9 +356,8 @@ if (!function_exists('mycred_render_badge_evidence') ) :
|
|
375 |
}
|
376 |
endif;
|
377 |
|
378 |
-
add_action('wp_enqueue_scripts', 'enqueue_badge_front_shortcode_scripts');
|
379 |
|
380 |
-
function enqueue_badge_front_shortcode_scripts()
|
381 |
-
|
382 |
-
|
383 |
-
}
|
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 |
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;
|
59 |
$badge_title = $badge->title;
|
60 |
$badge_img = $badge->main_image;
|
61 |
|
62 |
+
if ( $badge->main_image !== false ) {
|
|
|
|
|
63 |
|
64 |
echo '<div class="demo-badge-image">' . wp_kses_post( $badge_img ) . '</div>';
|
65 |
|
66 |
+
if( $title == 'show' ) {
|
67 |
|
68 |
+
echo '<div class="demo-badge-title">' . esc_html( $badge_title ) . '</div>';
|
69 |
|
70 |
+
}
|
71 |
+
else {
|
72 |
|
73 |
+
echo '<div class="demo-badge-title" style="display:none;">' . esc_html( $badge_title ) . '</div>';
|
74 |
|
75 |
}
|
76 |
|
77 |
+
if( $post_excerpt == 'show' ) {
|
78 |
+
|
79 |
+
echo '<div class="page-excerpt">' . esc_html( $page_id->post_excerpt ) . '</div>';
|
80 |
|
81 |
+
}
|
82 |
+
else {
|
83 |
|
84 |
+
echo '<div class="page-excerpt" style="display:none;">' . esc_html( $page_id->post_excerpt ) . '</div>';
|
85 |
+
|
86 |
}
|
87 |
|
88 |
}
|
89 |
|
90 |
}
|
|
|
91 |
// User has earned badge
|
92 |
else {
|
93 |
|
94 |
$level = $users_badges[ $badge_id ];
|
95 |
+
$badge = mycred_get_badge( $badge_id, $level );
|
96 |
$badge->image_width = $width;
|
97 |
$badge->image_height = $height;
|
98 |
|
99 |
+
$badge_page_id = get_page( $badge_id);
|
|
|
|
|
100 |
|
101 |
+
if ( $badge->level_image !== false ) {
|
102 |
|
103 |
+
echo '<div class="demo-badge-image">' . wp_kses_post( $badge->get_image( $level ) ) . '</div>';
|
104 |
|
105 |
+
if( $title == 'show' ) {
|
106 |
|
107 |
+
echo '<div class="demo-badge-title">' . esc_html( $badge->title ) . '</div>';
|
|
|
|
|
108 |
|
109 |
}
|
|
|
110 |
else {
|
111 |
|
112 |
+
echo '<div class="demo-badge-title" style="display:none;">' . esc_html( $badge->title ) . '</div>';
|
113 |
|
114 |
}
|
115 |
|
116 |
+
if( $post_excerpt == 'show' ) {
|
117 |
+
|
118 |
+
echo '<div class="page-excerpt">' . esc_html( $badge_page_id->post_excerpt ) . '</div>';
|
119 |
|
120 |
+
}
|
121 |
+
else {
|
122 |
+
|
123 |
+
echo '<div class="page-excerpt" style="display:none;">' . esc_html( $badge_page_id->post_excerpt ) . '</div>';
|
124 |
+
|
125 |
}
|
126 |
|
127 |
}
|
130 |
|
131 |
echo '</div>';
|
132 |
|
133 |
+
if( $title == 'show' || $post_excerpt == 'show' ) {
|
134 |
|
135 |
echo '<hr class="badge-line">';
|
136 |
+
|
137 |
}
|
138 |
else {
|
139 |
+
|
140 |
echo '';
|
141 |
+
|
142 |
}
|
143 |
}
|
144 |
|
148 |
$output = ob_get_contents();
|
149 |
ob_end_clean();
|
150 |
|
151 |
+
return apply_filters( 'mycred_my_badges', $output, $user_id );
|
152 |
|
153 |
}
|
154 |
endif;
|
156 |
/**
|
157 |
* Shortcode: mycred_badges
|
158 |
* Allows you to show all published badges
|
159 |
+
* @since 1.5
|
|
|
160 |
* @version 1.1.1
|
161 |
*/
|
162 |
+
if ( ! function_exists( 'mycred_render_badges' ) ) :
|
163 |
+
function mycred_render_badges( $atts, $template = '' ) {
|
164 |
+
extract( shortcode_atts( array(
|
165 |
+
'width' => MYCRED_BADGE_WIDTH,
|
166 |
+
'height' => MYCRED_BADGE_HEIGHT
|
167 |
+
), $atts, MYCRED_SLUG . '_badges' ) );
|
|
|
|
|
|
|
|
|
|
|
168 |
|
169 |
$all_badges = mycred_get_badge_ids();
|
170 |
|
171 |
+
if ( $template == '' )
|
172 |
$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>';
|
|
|
173 |
|
174 |
$output = '<div id="mycred-all-badges">';
|
175 |
|
176 |
+
if ( ! empty( $all_badges ) ) {
|
177 |
|
178 |
foreach ( $all_badges as $badge_id ) {
|
179 |
|
180 |
+
$badge = mycred_get_badge( $badge_id, 0 );
|
181 |
$badge->image_width = $width;
|
182 |
$badge->image_height = $height;
|
183 |
|
184 |
$row = $template;
|
185 |
+
$row = str_replace( '%badge_title%', $badge->title, $row );
|
186 |
+
$row = str_replace( '%requirements%', mycred_display_badge_requirements( $badge_id ), $row );
|
187 |
+
$row = str_replace( '%count%', $badge->earnedby, $row );
|
188 |
+
$row = str_replace( '%default_image%', $badge->get_image( 'main' ), $row );
|
189 |
|
190 |
+
if( mycred_user_has_badge( get_current_user_id(), $badge_id) ) {
|
191 |
$user_id = get_current_user_id();
|
192 |
+
$badge = mycred_get_badge( $badge_id );
|
193 |
+
$level = $badge->get_users_current_level( $user_id );
|
194 |
+
$row = str_replace( '%main_image%', $badge->get_image( $level ), $row );
|
195 |
}
|
196 |
else {
|
197 |
+
$row = str_replace( '%main_image%', '', $row );
|
198 |
}
|
199 |
|
200 |
+
$output .= apply_filters( 'mycred_badges_badge', $row, $badge );
|
201 |
|
202 |
}
|
203 |
|
205 |
|
206 |
$output .= '</div>';
|
207 |
|
208 |
+
return apply_filters( 'mycred_badges', $output );
|
209 |
|
210 |
}
|
211 |
endif;
|
212 |
|
213 |
/**
|
214 |
* myCRED Renders Badges List ShortCode
|
215 |
+
* @param string $atts
|
216 |
+
* @since 2.1
|
|
|
217 |
* @version 1.0
|
218 |
*/
|
219 |
+
if( !function_exists( 'mycred_render_badges_list' ) ) :
|
220 |
+
function mycred_render_badges_list( $atts = '' ) {
|
|
|
221 |
|
222 |
+
extract( shortcode_atts( array(
|
|
|
|
|
223 |
'achievement_tabs' => '1'
|
224 |
+
),
|
225 |
+
$atts, MYCRED_SLUG . '_badges_list'
|
226 |
+
) );
|
|
|
227 |
|
228 |
ob_start();?>
|
229 |
|
238 |
</div>
|
239 |
|
240 |
<?php
|
241 |
+
if ( $achievement_tabs == 1 ) {
|
242 |
|
243 |
$badges = mycred_get_categorized_badge_list();
|
244 |
|
245 |
+
if ( $badges['category_count'] > 0 ) { ?>
|
246 |
<div class="mycred-badges-list-nav">
|
247 |
<ul class="mycred-badges-list-tabs">
|
248 |
<?php
|
249 |
+
foreach ( $badges['tabs'] as $id => $element ) {
|
250 |
|
251 |
+
echo wp_kses_post( $element );
|
252 |
|
253 |
+
}
|
254 |
?>
|
255 |
</ul>
|
256 |
</div>
|
257 |
<div class="mycred-badges-list-panels">
|
258 |
<?php
|
259 |
+
foreach ( $badges['panels'] as $id => $element ) {
|
260 |
|
261 |
+
echo wp_kses_post( $element );
|
262 |
|
263 |
+
}
|
264 |
?>
|
265 |
</div>
|
266 |
+
<?php
|
267 |
}
|
268 |
|
269 |
}
|
310 |
|
311 |
/**
|
312 |
* Renders Badge's Evidence ShortCode
|
313 |
+
* @param string $atts
|
314 |
+
* @since 2.1
|
|
|
315 |
* @version 1.0
|
316 |
*/
|
317 |
+
if ( !function_exists( 'mycred_render_badge_evidence' ) ) :
|
318 |
+
function mycred_render_badge_evidence( $atts = '' ) {
|
|
|
319 |
|
320 |
$content = '<div class="mycred-evidence-page">Evidence not found</div>';
|
321 |
|
322 |
+
if ( isset( $_GET['uid'] ) && isset( $_GET['bid'] ) ) {
|
323 |
|
324 |
+
$user_id = intval( $_GET['uid'] );
|
325 |
+
$badge_id = intval( $_GET['bid'] );
|
326 |
|
327 |
+
$user_info = get_userdata( $user_id );
|
328 |
+
$badge = mycred_get_badge( $badge_id );
|
329 |
|
330 |
+
if ( $user_info && $badge && $badge->open_badge ) {
|
331 |
|
332 |
+
$issued_on = mycred_get_user_meta( $user_id, MYCRED_BADGE_KEY . $badge_id, '_issued_on', true );
|
333 |
|
334 |
$content = '<div class="mycred-evidence-page">
|
335 |
<div class="mycred-left">
|
336 |
+
<img src="' . $badge->get_earned_image( $user_id ) . '" alt="">
|
337 |
</div>
|
338 |
<div class="mycred-left intro">
|
339 |
<h4 class="mycred-remove-margin">' . $badge->title . '</h4>
|
340 |
<div class="mycred-remove-margin">
|
341 |
<p>Name: '. $user_info->display_name .'</p>
|
342 |
<p>Email: ' . $user_info->user_email . '</p>
|
343 |
+
<p>Issued On: ' . date( 'Y-m-d\TH:i:sP', $issued_on ) . '</p>
|
344 |
<p><span class="dashicons dashicons-yes-alt"></span> <span class="icon-txt"> Verified</span></p>
|
345 |
</div>
|
346 |
</div>
|
356 |
}
|
357 |
endif;
|
358 |
|
359 |
+
add_action( 'wp_enqueue_scripts', 'enqueue_badge_front_shortcode_scripts' );
|
360 |
|
361 |
+
function enqueue_badge_front_shortcode_scripts() {
|
362 |
+
wp_enqueue_style( 'mycred-badge-front-style', plugins_url( 'assets/css/front.css', myCRED_BADGE ), array(), myCRED_BADGE_VERSION , 'all');
|
363 |
+
}
|
|
addons/badges/includes/mycred-open-badge.php
CHANGED
@@ -1,318 +1,296 @@
|
|
1 |
<?php
|
2 |
-
if (! defined('myCRED_VERSION') )
|
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 |
-
|
13 |
-
{
|
14 |
|
15 |
-
|
16 |
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
{
|
22 |
|
23 |
-
|
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 |
-
|
57 |
-
|
|
|
|
|
|
|
58 |
|
59 |
-
|
|
|
|
|
|
|
|
|
60 |
|
61 |
-
|
62 |
-
|
|
|
|
|
|
|
|
|
|
|
63 |
|
64 |
-
|
65 |
-
$basedir = trailingslashit($wp_upload_dirs[ 'basedir' ]);
|
66 |
-
$baseurl = trailingslashit($wp_upload_dirs[ 'baseurl' ]);
|
67 |
|
68 |
-
|
69 |
|
70 |
-
|
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 |
-
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
$json = $this->get_image_json_data($user_id, $badge_id, $identity, $badge->title, $badge_image);
|
87 |
|
88 |
-
|
89 |
|
90 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
91 |
|
92 |
-
|
|
|
|
|
93 |
|
94 |
-
|
|
|
|
|
|
|
|
|
95 |
|
96 |
-
|
97 |
|
98 |
-
|
99 |
|
100 |
-
|
101 |
-
{
|
102 |
|
103 |
-
|
104 |
|
105 |
-
|
106 |
-
|
107 |
-
$user_id = intval($_GET['uid']);
|
108 |
-
$badge_id = intval($_GET['bid']);
|
109 |
|
110 |
-
|
111 |
-
$badge = mycred_get_badge($badge_id);
|
112 |
|
113 |
-
|
114 |
|
115 |
-
|
116 |
|
117 |
-
|
|
|
|
|
|
|
118 |
|
119 |
-
|
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 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
150 |
|
151 |
-
|
152 |
|
153 |
-
|
154 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
155 |
|
156 |
-
|
157 |
|
158 |
-
|
|
|
|
|
159 |
|
160 |
-
|
161 |
|
162 |
-
|
|
|
|
|
163 |
|
164 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
165 |
|
166 |
-
|
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 |
-
|
183 |
-
|
184 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
185 |
|
186 |
-
|
187 |
-
{
|
188 |
|
189 |
-
|
190 |
-
$admin_email = get_bloginfo('admin_email');
|
191 |
-
$blog_url = get_site_url();
|
192 |
|
193 |
-
|
194 |
-
|
195 |
-
|
196 |
-
|
197 |
-
|
198 |
-
'url' => $blog_url,
|
199 |
-
'email' => $admin_email
|
200 |
-
);
|
201 |
|
202 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
203 |
|
204 |
-
|
|
|
205 |
|
206 |
-
|
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 |
-
|
242 |
-
|
243 |
|
244 |
-
|
245 |
-
|
246 |
-
|
247 |
-
|
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 |
-
|
281 |
-
{
|
282 |
|
283 |
-
|
284 |
|
285 |
-
|
286 |
|
287 |
-
|
288 |
-
{
|
289 |
|
290 |
-
|
291 |
-
|
292 |
|
293 |
-
|
294 |
-
|
295 |
|
296 |
-
|
297 |
-
{
|
298 |
|
299 |
-
|
300 |
|
301 |
-
|
302 |
|
303 |
-
|
304 |
|
305 |
-
|
306 |
-
{
|
307 |
|
308 |
-
|
309 |
|
310 |
-
|
311 |
-
|
312 |
|
313 |
-
|
314 |
|
315 |
-
|
316 |
|
317 |
-
|
318 |
-
endif;
|
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;
|
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
@@ -502,7 +502,7 @@ if ( ! class_exists( 'myCRED_Badge_Module' ) ) :
|
|
502 |
|
503 |
}
|
504 |
|
505 |
-
elseif ( $pagenow == 'post.php' && isset( $_GET['post'] ) && mycred_get_post_type(
|
506 |
|
507 |
return MYCRED_MAIN_SLUG;
|
508 |
|
@@ -534,7 +534,7 @@ if ( ! class_exists( 'myCRED_Badge_Module' ) ) :
|
|
534 |
|
535 |
}
|
536 |
|
537 |
-
elseif ( $pagenow == 'post.php' && isset( $_GET['post'] ) && mycred_get_post_type(
|
538 |
|
539 |
return 'edit.php?post_type=' . MYCRED_BADGE_KEY;
|
540 |
|
@@ -624,7 +624,7 @@ if ( ! class_exists( 'myCRED_Badge_Module' ) ) :
|
|
624 |
echo '-';
|
625 |
|
626 |
elseif ( $badge->main_image !== false )
|
627 |
-
echo wp_kses_post($badge->main_image);
|
628 |
|
629 |
}
|
630 |
|
@@ -636,7 +636,7 @@ if ( ! class_exists( 'myCRED_Badge_Module' ) ) :
|
|
636 |
if ( $badge->open_badge || $image === false )
|
637 |
echo '-';
|
638 |
else
|
639 |
-
echo wp_kses_post($image);
|
640 |
|
641 |
}
|
642 |
|
@@ -664,7 +664,7 @@ if ( ! class_exists( 'myCRED_Badge_Module' ) ) :
|
|
664 |
|
665 |
$badge = mycred_get_badge_type( $badge_id );
|
666 |
|
667 |
-
echo
|
668 |
|
669 |
}
|
670 |
|
@@ -947,7 +947,7 @@ th#badge-users { width: 10%; }
|
|
947 |
data : {
|
948 |
action : button.attr( 'data-action' ),
|
949 |
token : button.attr( 'data-token' ),
|
950 |
-
badge_id : <?php echo
|
951 |
},
|
952 |
dataType : "JSON",
|
953 |
url : ajaxurl,
|
@@ -970,7 +970,7 @@ th#badge-users { width: 10%; }
|
|
970 |
|
971 |
</div>
|
972 |
<div id="mycred-manual-badge" class="seperate-bottom">
|
973 |
-
<label for="mycred-badge-is-manual"><input type="checkbox" name="mycred_badge[manual]" id="mycred-badge-is-manual"
|
974 |
</div>
|
975 |
<?php
|
976 |
|
@@ -998,7 +998,7 @@ th#badge-users { width: 10%; }
|
|
998 |
<div class="col-lg-12 col-md-12 col-sm-12 col-xs-12">
|
999 |
<div class="default-image text-center seperate-bottom">
|
1000 |
<div class="default-image-wrapper image-wrapper<?php if ( $default_image == '' ) echo ' empty dashicons'; ?>">
|
1001 |
-
<?php echo wp_kses_post($default_image); ?>
|
1002 |
<input type="hidden" name="mycred_badge[main_image]" id="badge-main-image-id" value="<?php if ( $attachment ) echo esc_attr( $di ); ?>" />
|
1003 |
<input type="hidden" name="mycred_badge[main_image_url]" id="badge-main-image-url" value="<?php if ( $di != '' && strpos( '://', $di ) !== false ) echo esc_attr( $default_image ); ?>" />
|
1004 |
</div>
|
@@ -1041,9 +1041,9 @@ th#badge-users { width: 10%; }
|
|
1041 |
|
1042 |
?>
|
1043 |
<div id="mycred-open-badge" class="seperate-bottom">
|
1044 |
-
<label for="mycred-badge-is-open-badge"><input type="checkbox" name="mycred_badge[open_badge]" id="mycred-badge-is-open-badge"<?php if ( $open_badge ) echo ' checked="checked"'; ?> value="1" /> <?php
|
1045 |
</div>
|
1046 |
-
<span class="description"><?php
|
1047 |
<?php
|
1048 |
|
1049 |
}
|
@@ -1059,7 +1059,7 @@ th#badge-users { width: 10%; }
|
|
1059 |
|
1060 |
?>
|
1061 |
<style>#mycred-badge-congratulation-msg{display:block;margin:12px 0 0;width:100%;}</style>
|
1062 |
-
<textarea name="mycred_badge[congratulation_msg]" placeholder="You have earned this Badge!" id="mycred-badge-congratulation-msg"><?php echo empty( $congratulation_msg ) ? '' : $congratulation_msg; ?></textarea>
|
1063 |
<?php
|
1064 |
|
1065 |
}
|
@@ -1106,7 +1106,7 @@ th#badge-users { width: 10%; }
|
|
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
|
1110 |
|
1111 |
$level_image = $this->get_level_image( $setup, $level );
|
1112 |
$empty_level = 'empty dashicons';
|
@@ -1275,7 +1275,7 @@ th#badge-users { width: 10%; }
|
|
1275 |
|
1276 |
$js_level = str_replace( '{{rewards}}', $rewards, $js_level );
|
1277 |
|
1278 |
-
echo
|
1279 |
|
1280 |
$level_counter++;
|
1281 |
|
@@ -1474,31 +1474,31 @@ th#badge-users { width: 10%; }
|
|
1474 |
$bbpress = ( ( class_exists( 'bbPress' ) ) ? true : false );
|
1475 |
|
1476 |
?>
|
1477 |
-
<h4><span class="dashicons dashicons-admin-plugins static"></span><?php
|
1478 |
<div class="body" style="display:none;">
|
1479 |
|
1480 |
-
<h3><?php
|
1481 |
|
1482 |
<div class="row">
|
1483 |
<div class="col-lg-6 col-md-6 col-sm-12 col-xs-12">
|
1484 |
|
1485 |
<div class="form-group">
|
1486 |
<div class="checkbox" style="padding-top: 4px;">
|
1487 |
-
<label for="<?php echo $this->field_id( 'show_level_description' ); ?>">
|
1488 |
-
<input type="checkbox" name="<?php echo $this->field_name( 'show_level_description' ); ?>" id="<?php echo $this->field_id( 'show_level_description' ); ?>" <?php checked( $settings['show_level_description'], 1 ); ?> value="1"><?php
|
1489 |
</label>
|
1490 |
</div>
|
1491 |
</div>
|
1492 |
|
1493 |
<div class="form-group">
|
1494 |
<div class="checkbox" style="padding-top: 4px;">
|
1495 |
-
<label for="<?php echo $this->field_id( 'show_congo_text' ); ?>"><input type="checkbox" name="<?php echo $this->field_name( 'show_congo_text' ); ?>" id="<?php echo $this->field_id( 'show_congo_text' ); ?>" <?php checked( $settings['show_congo_text'], 1 ); ?> value="1"> <?php
|
1496 |
</div>
|
1497 |
</div>
|
1498 |
|
1499 |
<div class="form-group">
|
1500 |
<div class="checkbox" style="padding-top: 4px;">
|
1501 |
-
<label for="<?php echo $this->field_id( 'show_steps_to_achieve' ); ?>"><input type="checkbox" name="<?php echo $this->field_name( 'show_steps_to_achieve' ); ?>" id="<?php echo $this->field_id( 'show_steps_to_achieve' ); ?>" <?php checked( $settings['show_steps_to_achieve'], 1 ); ?> value="1"> <?php
|
1502 |
</div>
|
1503 |
</div>
|
1504 |
|
@@ -1507,38 +1507,38 @@ th#badge-users { width: 10%; }
|
|
1507 |
|
1508 |
<div class="form-group">
|
1509 |
<div class="checkbox" style="padding-top: 4px;">
|
1510 |
-
<label for="<?php echo $this->field_id( 'show_levels' ); ?>"><input type="checkbox" name="<?php echo $this->field_name( 'show_levels' ); ?>" id="<?php echo $this->field_id( 'show_levels' ); ?>" <?php checked( $settings['show_levels'], 1 ); ?> value="1"> <?php
|
1511 |
</div>
|
1512 |
</div>
|
1513 |
|
1514 |
<div class="form-group">
|
1515 |
<div class="checkbox" style="padding-top: 4px;">
|
1516 |
-
<label for="<?php echo $this->field_id( 'show_level_points' ); ?>"><input type="checkbox" name="<?php echo $this->field_name( 'show_level_points' ); ?>" id="<?php echo $this->field_id( 'show_level_points' ); ?>" <?php checked( $settings['show_level_points'], 1 ); ?> value="1"> <?php
|
1517 |
</div>
|
1518 |
</div>
|
1519 |
|
1520 |
<div class="form-group">
|
1521 |
<div class="checkbox" style="padding-top: 4px;">
|
1522 |
-
<label for="<?php echo $this->field_id( 'show_earners' ); ?>"><input type="checkbox" name="<?php echo $this->field_name( 'show_earners' ); ?>" id="<?php echo $this->field_id( 'show_earners' ); ?>" <?php checked( $settings['show_earners'], 1 ); ?> value="1"> <?php
|
1523 |
</div>
|
1524 |
</div>
|
1525 |
|
1526 |
</div>
|
1527 |
</div>
|
1528 |
|
1529 |
-
<h3><?php
|
1530 |
<div class="row">
|
1531 |
<div class="col-lg-6 col-md-6 col-sm-12 col-xs-12">
|
1532 |
<div class="form-group">
|
1533 |
<div class="checkbox">
|
1534 |
-
<label for="<?php echo $this->field_id( 'open_badge' ); ?>"><input type="checkbox" name="<?php echo $this->field_name( 'open_badge' ); ?>" id="<?php echo $this->field_id( 'open_badge' ); ?>" <?php checked( $settings['open_badge'], 1 ); ?> value="1" > <?php
|
1535 |
</div>
|
1536 |
</div>
|
1537 |
</div>
|
1538 |
<?php if( $settings['open_badge'] == '1' ):?>
|
1539 |
<div class="col-lg-6 col-md-6 col-sm-12 col-xs-12">
|
1540 |
<div class="form-group">
|
1541 |
-
<label for="<?php echo $this->field_id( 'open_badge_evidence_page' ); ?>"><?php
|
1542 |
<?php
|
1543 |
|
1544 |
$selectedEvidencePage = mycred_get_evidence_page_id();
|
@@ -1549,7 +1549,7 @@ th#badge-users { width: 10%; }
|
|
1549 |
'selected' => $selectedEvidencePage
|
1550 |
);
|
1551 |
|
1552 |
-
wp_dropdown_pages( $args );
|
1553 |
?>
|
1554 |
</div>
|
1555 |
</div>
|
@@ -1561,13 +1561,13 @@ th#badge-users { width: 10%; }
|
|
1561 |
<?php endif;?>
|
1562 |
</div>
|
1563 |
|
1564 |
-
<h3><?php
|
1565 |
<div class="row">
|
1566 |
<div class="col-lg-6 col-md-6 col-sm-6 col-xs-12">
|
1567 |
<div class="form-group">
|
1568 |
-
<label for="<?php echo $this->field_id( 'buddypress' ); ?>">BuddyPress</label>
|
1569 |
<?php if ( $buddypress ) : ?>
|
1570 |
-
<select name="<?php echo $this->field_name( 'buddypress' ); ?>" id="<?php echo $this->field_id( 'buddypress' ); ?>" class="form-control">
|
1571 |
<?php
|
1572 |
|
1573 |
$buddypress_options = array(
|
@@ -1578,9 +1578,9 @@ th#badge-users { width: 10%; }
|
|
1578 |
);
|
1579 |
|
1580 |
foreach ( $buddypress_options as $location => $description ) {
|
1581 |
-
echo '<option value="' . $location . '"';
|
1582 |
if ( isset( $settings['buddypress'] ) && $settings['buddypress'] == $location ) echo ' selected="selected"';
|
1583 |
-
echo '>' . $description . '</option>';
|
1584 |
}
|
1585 |
|
1586 |
?>
|
@@ -1589,19 +1589,19 @@ th#badge-users { width: 10%; }
|
|
1589 |
</div>
|
1590 |
<div class="form-group">
|
1591 |
<div class="checkbox">
|
1592 |
-
<label for="<?php echo $this->field_id( 'show_all_bp' ); ?>"><input type="checkbox" name="<?php echo $this->field_name( 'show_all_bp' ); ?>" id="<?php echo $this->field_id( 'show_all_bp' ); ?>" <?php checked( $settings['show_all_bp'], 1 ); ?> value="1" /> <?php
|
1593 |
</div>
|
1594 |
<?php else : ?>
|
1595 |
-
<input type="hidden" name="<?php echo $this->field_name( 'buddypress' ); ?>" id="<?php echo $this->field_id( 'buddypress' ); ?>" value="" />
|
1596 |
-
<p><span class="description"><?php
|
1597 |
<?php endif; ?>
|
1598 |
</div>
|
1599 |
</div>
|
1600 |
<div class="col-lg-6 col-md-6 col-sm-6 col-xs-12">
|
1601 |
<div class="form-group">
|
1602 |
-
<label for="<?php echo $this->field_id( 'bbpress' ); ?>">bbPress</label>
|
1603 |
<?php if ( $bbpress ) : ?>
|
1604 |
-
<select name="<?php echo $this->field_name( 'bbpress' ); ?>" id="<?php echo $this->field_id( 'bbpress' ); ?>" class="form-control">
|
1605 |
<?php
|
1606 |
|
1607 |
$bbpress_options = array(
|
@@ -1612,9 +1612,9 @@ th#badge-users { width: 10%; }
|
|
1612 |
);
|
1613 |
|
1614 |
foreach ( $bbpress_options as $location => $description ) {
|
1615 |
-
echo '<option value="' . $location . '"';
|
1616 |
if ( isset( $settings['bbpress'] ) && $settings['bbpress'] == $location ) echo ' selected="selected"';
|
1617 |
-
echo '>' . $description . '</option>';
|
1618 |
}
|
1619 |
|
1620 |
?>
|
@@ -1623,17 +1623,17 @@ th#badge-users { width: 10%; }
|
|
1623 |
</div>
|
1624 |
<div class="form-group">
|
1625 |
<div class="checkbox">
|
1626 |
-
<label for="<?php echo $this->field_id( 'show_all_bb' ); ?>"><input type="checkbox" name="<?php echo $this->field_name( 'show_all_bb' ); ?>" id="<?php echo $this->field_id( 'show_all_bb' ); ?>" <?php checked( $settings['show_all_bb'], 1 ); ?> value="1" /> <?php
|
1627 |
</div>
|
1628 |
<?php else : ?>
|
1629 |
-
<input type="hidden" name="<?php echo $this->field_name( 'bbpress' ); ?>" id="<?php echo $this->field_id( 'bbpress' ); ?>" value="" />
|
1630 |
-
<p><span class="description"><?php
|
1631 |
<?php endif; ?>
|
1632 |
</div>
|
1633 |
</div>
|
1634 |
</div>
|
1635 |
|
1636 |
-
<h3 style="margin-bottom: 0;"><?php
|
1637 |
<div class="row">
|
1638 |
<div class="col-lg-12 col-md-12 col-sm-12 col-xs-12">
|
1639 |
<p><a href="http://codex.mycred.me/shortcodes/mycred_my_badges/" target="_blank">[mycred_my_badges]</a>, <a href="http://codex.mycred.me/shortcodes/mycred_badges/" target="_blank">[mycred_badges]</a></p>
|
@@ -1695,15 +1695,15 @@ th#badge-users { width: 10%; }
|
|
1695 |
.badge-wrapper select { width: 100%; }
|
1696 |
.badge-image-wrap { text-align: center; }
|
1697 |
.badge-image-wrap .badge-image { display: block; width: 100%; height: 100px; line-height: 100px; }
|
1698 |
-
.badge-image-wrap .badge-image.empty { content: "<?php
|
1699 |
.badge-image-wrap .badge-image img { width: auto; height: auto; max-height: 100px; }
|
1700 |
</style>
|
1701 |
<table class="form-table">
|
1702 |
<tr>
|
1703 |
-
<th scope="row"><?php
|
1704 |
<td>
|
1705 |
<fieldset id="mycred-badge-list" class="badge-list">
|
1706 |
-
<legend class="screen-reader-text"><span><?php
|
1707 |
<?php
|
1708 |
|
1709 |
if ( ! empty( $all_badges ) ) {
|
@@ -1752,20 +1752,20 @@ th#badge-users { width: 10%; }
|
|
1752 |
}
|
1753 |
|
1754 |
?>
|
1755 |
-
<div class="badge-wrapper<?php if ( ! mycred_is_admin() ) echo ' badge-wrapper-center'; ?> color-option<?php if ( $earned === 1 ) echo ' selected'; ?>" id="mycred-badge<?php echo $badge_id; ?>-wrapper">
|
1756 |
<div>
|
1757 |
<?php if ( mycred_is_admin() ):?>
|
1758 |
-
<label for="mycred-badge<?php echo $badge_id; ?>"><input type="checkbox" name="mycred_badge_manual[badges][<?php echo $badge_id; ?>][has]" class="toggle-badge" id="mycred-badge<?php echo $badge_id; ?>" <?php checked( $earned, 1 );?> value="1" /> <?php
|
1759 |
<?php endif; ?>
|
1760 |
<div class="badge-image-wrap">
|
1761 |
|
1762 |
-
<div class="badge-image<?php if ( $badge_image == '' ) echo ' empty'; ?>"><?php echo $badge_image; ?></div>
|
1763 |
|
1764 |
-
<h4><?php echo $badge->title; ?></h4>
|
1765 |
</div>
|
1766 |
<div class="badge-actions" style="min-height: 32px;">
|
1767 |
|
1768 |
-
<?php echo $level_select; ?>
|
1769 |
|
1770 |
</div>
|
1771 |
|
@@ -1783,7 +1783,7 @@ th#badge-users { width: 10%; }
|
|
1783 |
|
1784 |
?>
|
1785 |
</fieldset>
|
1786 |
-
<input type="hidden" name="mycred_badge_manual[token]" value="<?php echo wp_create_nonce( 'mycred-manual-badges' . $user_id ); ?>" />
|
1787 |
</td>
|
1788 |
</tr>
|
1789 |
</table>
|
502 |
|
503 |
}
|
504 |
|
505 |
+
elseif ( $pagenow == 'post.php' && isset( $_GET['post'] ) && mycred_get_post_type( $_GET['post'] ) == MYCRED_BADGE_KEY ) {
|
506 |
|
507 |
return MYCRED_MAIN_SLUG;
|
508 |
|
534 |
|
535 |
}
|
536 |
|
537 |
+
elseif ( $pagenow == 'post.php' && isset( $_GET['post'] ) && mycred_get_post_type( $_GET['post'] ) == MYCRED_BADGE_KEY ) {
|
538 |
|
539 |
return 'edit.php?post_type=' . MYCRED_BADGE_KEY;
|
540 |
|
624 |
echo '-';
|
625 |
|
626 |
elseif ( $badge->main_image !== false )
|
627 |
+
echo wp_kses_post( $badge->main_image );
|
628 |
|
629 |
}
|
630 |
|
636 |
if ( $badge->open_badge || $image === false )
|
637 |
echo '-';
|
638 |
else
|
639 |
+
echo wp_kses_post( $image );
|
640 |
|
641 |
}
|
642 |
|
664 |
|
665 |
$badge = mycred_get_badge_type( $badge_id );
|
666 |
|
667 |
+
echo $badge == false ? 'No Acheivement Type' : esc_html( $badge );
|
668 |
|
669 |
}
|
670 |
|
947 |
data : {
|
948 |
action : button.attr( 'data-action' ),
|
949 |
token : button.attr( 'data-token' ),
|
950 |
+
badge_id : <?php echo absint( $post->ID ); ?>
|
951 |
},
|
952 |
dataType : "JSON",
|
953 |
url : ajaxurl,
|
970 |
|
971 |
</div>
|
972 |
<div id="mycred-manual-badge" class="seperate-bottom">
|
973 |
+
<label for="mycred-badge-is-manual"><input type="checkbox" name="mycred_badge[manual]" id="mycred-badge-is-manual"<?php if ( $manual_badge ) echo ' checked="checked"'; ?> value="1" /> <?php esc_html_e( 'This badge is manually awarded.', 'mycred' ); ?></label>
|
974 |
</div>
|
975 |
<?php
|
976 |
|
998 |
<div class="col-lg-12 col-md-12 col-sm-12 col-xs-12">
|
999 |
<div class="default-image text-center seperate-bottom">
|
1000 |
<div class="default-image-wrapper image-wrapper<?php if ( $default_image == '' ) echo ' empty dashicons'; ?>">
|
1001 |
+
<?php echo wp_kses_post( $default_image ); ?>
|
1002 |
<input type="hidden" name="mycred_badge[main_image]" id="badge-main-image-id" value="<?php if ( $attachment ) echo esc_attr( $di ); ?>" />
|
1003 |
<input type="hidden" name="mycred_badge[main_image_url]" id="badge-main-image-url" value="<?php if ( $di != '' && strpos( '://', $di ) !== false ) echo esc_attr( $default_image ); ?>" />
|
1004 |
</div>
|
1041 |
|
1042 |
?>
|
1043 |
<div id="mycred-open-badge" class="seperate-bottom">
|
1044 |
+
<label for="mycred-badge-is-open-badge"><input type="checkbox" name="mycred_badge[open_badge]" id="mycred-badge-is-open-badge"<?php if ( $open_badge ) echo ' checked="checked"'; ?> value="1" /> <?php esc_html_e( 'This badge is Open Badge.', 'mycred' ); ?></label>
|
1045 |
</div>
|
1046 |
+
<span class="description"><?php esc_html_e( 'Multi level badge settings will be disable when switched to open badge.', 'mycred' ); ?></span>
|
1047 |
<?php
|
1048 |
|
1049 |
}
|
1059 |
|
1060 |
?>
|
1061 |
<style>#mycred-badge-congratulation-msg{display:block;margin:12px 0 0;width:100%;}</style>
|
1062 |
+
<textarea name="mycred_badge[congratulation_msg]" placeholder="You have earned this Badge!" id="mycred-badge-congratulation-msg"><?php echo empty( $congratulation_msg ) ? '' : esc_textarea( $congratulation_msg ); ?></textarea>
|
1063 |
<?php
|
1064 |
|
1065 |
}
|
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 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';
|
1275 |
|
1276 |
$js_level = str_replace( '{{rewards}}', $rewards, $js_level );
|
1277 |
|
1278 |
+
echo $template;
|
1279 |
|
1280 |
$level_counter++;
|
1281 |
|
1474 |
$bbpress = ( ( class_exists( 'bbPress' ) ) ? true : false );
|
1475 |
|
1476 |
?>
|
1477 |
+
<h4><span class="dashicons dashicons-admin-plugins static"></span><?php esc_html_e( 'Badges', 'mycred' ); ?></h4>
|
1478 |
<div class="body" style="display:none;">
|
1479 |
|
1480 |
+
<h3><?php esc_html_e( 'Single Badge Page', 'mycred' ); ?></h3>
|
1481 |
|
1482 |
<div class="row">
|
1483 |
<div class="col-lg-6 col-md-6 col-sm-12 col-xs-12">
|
1484 |
|
1485 |
<div class="form-group">
|
1486 |
<div class="checkbox" style="padding-top: 4px;">
|
1487 |
+
<label for="<?php echo esc_attr( $this->field_id( 'show_level_description' ) ); ?>">
|
1488 |
+
<input type="checkbox" name="<?php echo esc_attr( $this->field_name( 'show_level_description' ) ); ?>" id="<?php echo esc_attr( $this->field_id( 'show_level_description' ) ); ?>" <?php checked( $settings['show_level_description'], 1 ); ?> value="1"><?php esc_html_e('Show Level Description', 'mycred'); ?>
|
1489 |
</label>
|
1490 |
</div>
|
1491 |
</div>
|
1492 |
|
1493 |
<div class="form-group">
|
1494 |
<div class="checkbox" style="padding-top: 4px;">
|
1495 |
+
<label for="<?php echo esc_attr( $this->field_id( 'show_congo_text' ) ); ?>"><input type="checkbox" name="<?php echo esc_attr( $this->field_name( 'show_congo_text' ) ); ?>" id="<?php echo esc_attr( $this->field_id( 'show_congo_text' ) ); ?>" <?php checked( $settings['show_congo_text'], 1 ); ?> value="1"> <?php esc_html_e('Show Congratulation Text', 'mycred'); ?></label>
|
1496 |
</div>
|
1497 |
</div>
|
1498 |
|
1499 |
<div class="form-group">
|
1500 |
<div class="checkbox" style="padding-top: 4px;">
|
1501 |
+
<label for="<?php echo esc_attr( $this->field_id( 'show_steps_to_achieve' ) ); ?>"><input type="checkbox" name="<?php echo esc_attr( $this->field_name( 'show_steps_to_achieve' ) ); ?>" id="<?php echo esc_attr( $this->field_id( 'show_steps_to_achieve' ) ); ?>" <?php checked( $settings['show_steps_to_achieve'], 1 ); ?> value="1"> <?php esc_html_e('Show Steps to Achieve', 'mycred'); ?></label>
|
1502 |
</div>
|
1503 |
</div>
|
1504 |
|
1507 |
|
1508 |
<div class="form-group">
|
1509 |
<div class="checkbox" style="padding-top: 4px;">
|
1510 |
+
<label for="<?php echo esc_attr( $this->field_id( 'show_levels' ) ); ?>"><input type="checkbox" name="<?php echo esc_attr( $this->field_name( 'show_levels' ) ); ?>" id="<?php echo esc_attr( $this->field_id( 'show_levels' ) ); ?>" <?php checked( $settings['show_levels'], 1 ); ?> value="1"> <?php esc_html_e('Show Levels', 'mycred'); ?></label>
|
1511 |
</div>
|
1512 |
</div>
|
1513 |
|
1514 |
<div class="form-group">
|
1515 |
<div class="checkbox" style="padding-top: 4px;">
|
1516 |
+
<label for="<?php echo esc_attr( $this->field_id( 'show_level_points' ) ); ?>"><input type="checkbox" name="<?php echo esc_attr( $this->field_name( 'show_level_points' ) ); ?>" id="<?php echo esc_attr( $this->field_id( 'show_level_points' ) ); ?>" <?php checked( $settings['show_level_points'], 1 ); ?> value="1"> <?php esc_html_e('Show Level Reward', 'mycred'); ?></label>
|
1517 |
</div>
|
1518 |
</div>
|
1519 |
|
1520 |
<div class="form-group">
|
1521 |
<div class="checkbox" style="padding-top: 4px;">
|
1522 |
+
<label for="<?php echo esc_attr( $this->field_id( 'show_earners' ) ); ?>"><input type="checkbox" name="<?php echo esc_attr( $this->field_name( 'show_earners' ) ); ?>" id="<?php echo esc_attr( $this->field_id( 'show_earners' ) ); ?>" <?php checked( $settings['show_earners'], 1 ); ?> value="1"> <?php esc_html_e('Show Earners', 'mycred'); ?></label>
|
1523 |
</div>
|
1524 |
</div>
|
1525 |
|
1526 |
</div>
|
1527 |
</div>
|
1528 |
|
1529 |
+
<h3><?php esc_html_e( 'Open Badge', 'mycred' ); ?></h3>
|
1530 |
<div class="row">
|
1531 |
<div class="col-lg-6 col-md-6 col-sm-12 col-xs-12">
|
1532 |
<div class="form-group">
|
1533 |
<div class="checkbox">
|
1534 |
+
<label for="<?php echo esc_attr( $this->field_id( 'open_badge' ) ); ?>"><input type="checkbox" name="<?php echo esc_attr( $this->field_name( 'open_badge' ) ); ?>" id="<?php echo esc_attr( $this->field_id( 'open_badge' ) ); ?>" <?php checked( $settings['open_badge'], 1 ); ?> value="1" > <?php esc_html_e( 'Enable Open Badge.', 'mycred' ); ?></label>
|
1535 |
</div>
|
1536 |
</div>
|
1537 |
</div>
|
1538 |
<?php if( $settings['open_badge'] == '1' ):?>
|
1539 |
<div class="col-lg-6 col-md-6 col-sm-12 col-xs-12">
|
1540 |
<div class="form-group">
|
1541 |
+
<label for="<?php echo esc_attr( $this->field_id( 'open_badge_evidence_page' ) ); ?>"><?php esc_html_e( 'Evidence Page', 'mycred' ); ?></label>
|
1542 |
<?php
|
1543 |
|
1544 |
$selectedEvidencePage = mycred_get_evidence_page_id();
|
1549 |
'selected' => $selectedEvidencePage
|
1550 |
);
|
1551 |
|
1552 |
+
wp_dropdown_pages( esc_attr( $args ) );
|
1553 |
?>
|
1554 |
</div>
|
1555 |
</div>
|
1561 |
<?php endif;?>
|
1562 |
</div>
|
1563 |
|
1564 |
+
<h3><?php esc_html_e( 'Third-party Integrations', 'mycred' ); ?></h3>
|
1565 |
<div class="row">
|
1566 |
<div class="col-lg-6 col-md-6 col-sm-6 col-xs-12">
|
1567 |
<div class="form-group">
|
1568 |
+
<label for="<?php echo esc_attr( $this->field_id( 'buddypress' ) ); ?>">BuddyPress</label>
|
1569 |
<?php if ( $buddypress ) : ?>
|
1570 |
+
<select name="<?php echo esc_attr( $this->field_name( 'buddypress' ) ); ?>" id="<?php echo esc_attr( $this->field_id( 'buddypress' ) ); ?>" class="form-control">
|
1571 |
<?php
|
1572 |
|
1573 |
$buddypress_options = array(
|
1578 |
);
|
1579 |
|
1580 |
foreach ( $buddypress_options as $location => $description ) {
|
1581 |
+
echo '<option value="' . esc_attr( $location ) . '"';
|
1582 |
if ( isset( $settings['buddypress'] ) && $settings['buddypress'] == $location ) echo ' selected="selected"';
|
1583 |
+
echo '>' . esc_html( $description ) . '</option>';
|
1584 |
}
|
1585 |
|
1586 |
?>
|
1589 |
</div>
|
1590 |
<div class="form-group">
|
1591 |
<div class="checkbox">
|
1592 |
+
<label for="<?php echo esc_attr( $this->field_id( 'show_all_bp' ) ); ?>"><input type="checkbox" name="<?php echo esc_attr( $this->field_name( 'show_all_bp' ) ); ?>" id="<?php echo esc_attr( $this->field_id( 'show_all_bp' ) ); ?>" <?php checked( $settings['show_all_bp'], 1 ); ?> value="1" /> <?php esc_html_e( 'Show all badges, including badges users have not yet earned.', 'mycred' ); ?></label>
|
1593 |
</div>
|
1594 |
<?php else : ?>
|
1595 |
+
<input type="hidden" name="<?php echo esc_attr( $this->field_name( 'buddypress' ) ); ?>" id="<?php echo esc_attr( $this->field_id( 'buddypress' ) ); ?>" value="" />
|
1596 |
+
<p><span class="description"><?php esc_html_e( 'Not installed', 'mycred' ); ?></span></p>
|
1597 |
<?php endif; ?>
|
1598 |
</div>
|
1599 |
</div>
|
1600 |
<div class="col-lg-6 col-md-6 col-sm-6 col-xs-12">
|
1601 |
<div class="form-group">
|
1602 |
+
<label for="<?php echo esc_attr( $this->field_id( 'bbpress' ) ); ?>">bbPress</label>
|
1603 |
<?php if ( $bbpress ) : ?>
|
1604 |
+
<select name="<?php echo esc_attr( $this->field_name( 'bbpress' ) ); ?>" id="<?php echo esc_attr( $this->field_id( 'bbpress' ) ); ?>" class="form-control">
|
1605 |
<?php
|
1606 |
|
1607 |
$bbpress_options = array(
|
1612 |
);
|
1613 |
|
1614 |
foreach ( $bbpress_options as $location => $description ) {
|
1615 |
+
echo '<option value="' . esc_attr( $location ) . '"';
|
1616 |
if ( isset( $settings['bbpress'] ) && $settings['bbpress'] == $location ) echo ' selected="selected"';
|
1617 |
+
echo '>' . esc_html( $description ) . '</option>';
|
1618 |
}
|
1619 |
|
1620 |
?>
|
1623 |
</div>
|
1624 |
<div class="form-group">
|
1625 |
<div class="checkbox">
|
1626 |
+
<label for="<?php echo esc_attr( $this->field_id( 'show_all_bb' ) ); ?>"><input type="checkbox" name="<?php echo esc_attr( $this->field_name( 'show_all_bb' ) ); ?>" id="<?php echo esc_attr( $this->field_id( 'show_all_bb' ) ); ?>" <?php checked( $settings['show_all_bb'], 1 ); ?> value="1" /> <?php esc_html_e( 'Show all badges, including badges users have not yet earned.', 'mycred' ); ?></label>
|
1627 |
</div>
|
1628 |
<?php else : ?>
|
1629 |
+
<input type="hidden" name="<?php echo esc_attr( $this->field_name( 'bbpress' ) ); ?>" id="<?php echo esc_attr( $this->field_id( 'bbpress' ) ); ?>" value="" />
|
1630 |
+
<p><span class="description"><?php esc_html_e( 'Not installed', 'mycred' ); ?></span></p>
|
1631 |
<?php endif; ?>
|
1632 |
</div>
|
1633 |
</div>
|
1634 |
</div>
|
1635 |
|
1636 |
+
<h3 style="margin-bottom: 0;"><?php esc_html_e( 'Available Shortcodes', 'mycred' ); ?></h3>
|
1637 |
<div class="row">
|
1638 |
<div class="col-lg-12 col-md-12 col-sm-12 col-xs-12">
|
1639 |
<p><a href="http://codex.mycred.me/shortcodes/mycred_my_badges/" target="_blank">[mycred_my_badges]</a>, <a href="http://codex.mycred.me/shortcodes/mycred_badges/" target="_blank">[mycred_badges]</a></p>
|
1695 |
.badge-wrapper select { width: 100%; }
|
1696 |
.badge-image-wrap { text-align: center; }
|
1697 |
.badge-image-wrap .badge-image { display: block; width: 100%; height: 100px; line-height: 100px; }
|
1698 |
+
.badge-image-wrap .badge-image.empty { content: "<?php esc_html_e( 'No image set', 'mycred' ); ?>"; }
|
1699 |
.badge-image-wrap .badge-image img { width: auto; height: auto; max-height: 100px; }
|
1700 |
</style>
|
1701 |
<table class="form-table">
|
1702 |
<tr>
|
1703 |
+
<th scope="row"><?php esc_html_e( 'Badges', 'mycred' ); ?></th>
|
1704 |
<td>
|
1705 |
<fieldset id="mycred-badge-list" class="badge-list">
|
1706 |
+
<legend class="screen-reader-text"><span><?php esc_html_e( 'Badges', 'mycred' ); ?></span></legend>
|
1707 |
<?php
|
1708 |
|
1709 |
if ( ! empty( $all_badges ) ) {
|
1752 |
}
|
1753 |
|
1754 |
?>
|
1755 |
+
<div class="badge-wrapper<?php if ( ! mycred_is_admin() ) echo ' badge-wrapper-center'; ?> color-option<?php if ( $earned === 1 ) echo ' selected'; ?>" id="mycred-badge<?php echo esc_attr( $badge_id ); ?>-wrapper">
|
1756 |
<div>
|
1757 |
<?php if ( mycred_is_admin() ):?>
|
1758 |
+
<label for="mycred-badge<?php echo esc_attr( $badge_id ); ?>"><input type="checkbox" name="mycred_badge_manual[badges][<?php echo $badge_id; ?>][has]" class="toggle-badge" id="mycred-badge<?php echo esc_attr( $badge_id ); ?>" <?php checked( $earned, 1 );?> value="1" /> <?php esc_html_e( 'Earned', 'mycred' ); ?></label>
|
1759 |
<?php endif; ?>
|
1760 |
<div class="badge-image-wrap">
|
1761 |
|
1762 |
+
<div class="badge-image<?php if ( $badge_image == '' ) echo ' empty'; ?>"><?php echo wp_kses_post( $badge_image ); ?></div>
|
1763 |
|
1764 |
+
<h4><?php echo esc_html( $badge->title ); ?></h4>
|
1765 |
</div>
|
1766 |
<div class="badge-actions" style="min-height: 32px;">
|
1767 |
|
1768 |
+
<?php echo esc_html( $level_select ); ?>
|
1769 |
|
1770 |
</div>
|
1771 |
|
1783 |
|
1784 |
?>
|
1785 |
</fieldset>
|
1786 |
+
<input type="hidden" name="mycred_badge_manual[token]" value="<?php echo esc_attr( wp_create_nonce( 'mycred-manual-badges' . $user_id ) ); ?>" />
|
1787 |
</td>
|
1788 |
</tr>
|
1789 |
</table>
|
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/badges/templates/mycred-metabox-badge-alignment.php
CHANGED
@@ -7,31 +7,31 @@
|
|
7 |
<li>
|
8 |
<input type="radio" class="mycred-align-radio" name="mycred_badge[mycred_badge_align]" id="mycred_align_left" value="mycred_align_left" <?php echo ( $mycred_badge_align == 'mycred_align_left' ) ? 'checked' : '' ; ?>>
|
9 |
<label for="mycred_align_left">
|
10 |
-
<svg id="Layer_1" data-name="Layer 1" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 62.26 61.16"><defs><style>.cls-1{fill:#10212b;}.cls-2{fill:#aab5bc;}.cls-3{fill:none;stroke:#10212b;stroke-miterlimit:10;}</style></defs><title>icon</title><rect class="cls-1" x="9.02" y="13.98" width="43.07" height="3.33" rx="1.67"/><rect class="cls-2" x="10.55" y="18.88" width="39.58" height="1.27" rx="0.44"/><rect class="cls-2" x="10.55" y="21.18" width="39.58" height="1.27" rx="0.44"/><rect class="cls-2" x="10.55" y="23.48" width="39.58" height="1.27" rx="0.44"/><rect class="cls-2" x="10.55" y="25.78" width="39.58" height="1.27" rx="0.44"/><rect class="cls-2" x="10.55" y="28.08" width="39.58" height="1.27" rx="0.44"/><rect class="cls-2" x="10.55" y="30.38" width="20.48" height="1.27" rx="0.44"/><rect class="cls-1" x="9.02" y="36.13" width="43.07" height="3.33" rx="1.67"/><rect class="cls-2" x="10.55" y="41.03" width="39.58" height="1.27" rx="0.44"/><rect class="cls-2" x="10.55" y="43.33" width="39.58" height="1.27" rx="0.44"/><rect class="cls-2" x="10.55" y="45.63" width="39.58" height="1.27" rx="0.44"/><rect class="cls-2" x="10.55" y="47.81" width="20.48" height="1.27" rx="0.44"/><path class="cls-2" d="M61.76,2.53v5H.5v-5c0-1.12.68-2,1.53-2h58.2C61.07.5,61.76,1.41,61.76,2.53Z"/><circle class="cls-1" cx="58.22" cy="4.64" r="0.63"/><circle class="cls-1" cx="55.83" cy="4.64" r="0.63"/><circle class="cls-1" cx="52.67" cy="4.64" r="0.63"/><rect class="cls-3" x="0.5" y="0.5" width="61.26" height="60.16"/></svg><?php
|
11 |
</label>
|
12 |
</li>
|
13 |
<li>
|
14 |
<input type="radio" class="mycred-align-radio" name="mycred_badge[mycred_badge_align]" id="mycred_align_right" value="mycred_align_right" <?php echo ( $mycred_badge_align == 'mycred_align_right' ) ? 'checked' : '' ; ?>>
|
15 |
<label for="mycred_align_right">
|
16 |
-
<svg id="Layer_1" data-name="Layer 1" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 62.26 61.16"><defs><style>.cls-1{fill:#10212b;}.cls-2{fill:#aab5bc;}.cls-3{fill:none;stroke:#10212b;stroke-miterlimit:10;}</style></defs><title>icon</title><rect class="cls-1" x="9.02" y="13.98" width="43.07" height="3.33" rx="1.67"/><rect class="cls-2" x="10.76" y="20.03" width="39.58" height="1.27" rx="0.44"/><rect class="cls-2" x="10.76" y="22.33" width="39.58" height="1.27" rx="0.44"/><rect class="cls-2" x="10.76" y="24.63" width="39.58" height="1.27" rx="0.44"/><rect class="cls-2" x="10.76" y="26.93" width="39.58" height="1.27" rx="0.44"/><rect class="cls-2" x="10.76" y="29.23" width="39.58" height="1.27" rx="0.44"/><rect class="cls-2" x="29.86" y="31.53" width="20.48" height="1.27" rx="0.44"/><rect class="cls-1" x="9.02" y="36.13" width="43.07" height="3.33" rx="1.67"/><rect class="cls-2" x="10.76" y="42.18" width="39.58" height="1.27" rx="0.44"/><rect class="cls-2" x="10.76" y="44.48" width="39.58" height="1.27" rx="0.44"/><rect class="cls-2" x="10.76" y="46.78" width="39.58" height="1.27" rx="0.44"/><rect class="cls-2" x="29.86" y="49.08" width="20.48" height="1.27" rx="0.44"/><path class="cls-2" d="M61.76,2.53v5H.5v-5c0-1.12.68-2,1.53-2h58.2C61.07.5,61.76,1.41,61.76,2.53Z"/><circle class="cls-1" cx="58.22" cy="4.64" r="0.63"/><circle class="cls-1" cx="55.83" cy="4.64" r="0.63"/><circle class="cls-1" cx="52.67" cy="4.64" r="0.63"/><rect class="cls-3" x="0.5" y="0.5" width="61.26" height="60.16"/></svg><?php
|
17 |
</label>
|
18 |
</li>
|
19 |
<li>
|
20 |
<input type="radio" class="mycred-align-radio" name="mycred_badge[mycred_badge_align]" id="mycred_align_center" value="mycred_align_center" <?php echo ( $mycred_badge_align == 'mycred_align_center' ) ? 'checked' : '' ; ?>>
|
21 |
<label for="mycred_align_center">
|
22 |
-
<svg id="Layer_1" data-name="Layer 1" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 62.26 61.16"><defs><style>.cls-1{fill:#10212b;}.cls-2{fill:#aab5bc;}.cls-3{fill:none;stroke:#10212b;stroke-miterlimit:10;}</style></defs><title>icon</title><rect class="cls-1" x="9.59" y="13.98" width="43.07" height="3.33" rx="1.67"/><rect class="cls-2" x="11.34" y="18.4" width="39.58" height="1.27" rx="0.44"/><rect class="cls-2" x="11.34" y="20.7" width="39.58" height="1.27" rx="0.44"/><rect class="cls-2" x="11.34" y="23" width="39.58" height="1.27" rx="0.44"/><rect class="cls-2" x="11.34" y="25.3" width="39.58" height="1.27" rx="0.44"/><rect class="cls-2" x="11.34" y="27.6" width="39.58" height="1.27" rx="0.44"/><rect class="cls-2" x="20.89" y="29.9" width="20.48" height="1.27" rx="0.44"/><rect class="cls-1" x="9.59" y="36.13" width="43.07" height="3.33" rx="1.67"/><rect class="cls-2" x="11.34" y="40.55" width="39.58" height="1.27" rx="0.44"/><rect class="cls-2" x="11.34" y="42.85" width="39.58" height="1.27" rx="0.44"/><rect class="cls-2" x="11.34" y="45.15" width="39.58" height="1.27" rx="0.44"/><rect class="cls-2" x="20.89" y="47.45" width="20.48" height="1.27" rx="0.44"/><path class="cls-2" d="M61.76,2.53v5H.5v-5c0-1.12.68-2,1.53-2h58.2C61.07.5,61.76,1.41,61.76,2.53Z"/><circle class="cls-1" cx="58.22" cy="4.64" r="0.63"/><circle class="cls-1" cx="55.83" cy="4.64" r="0.63"/><circle class="cls-1" cx="52.67" cy="4.64" r="0.63"/><rect class="cls-3" x="0.5" y="0.5" width="61.26" height="60.16"/></svg><?php
|
23 |
</label>
|
24 |
</li>
|
25 |
<li>
|
26 |
<input type="radio" class="mycred-align-radio" name="mycred_badge[mycred_badge_align]" id="mycred_align_justify" value="mycred_align_justify" <?php echo ( $mycred_badge_align == 'mycred_align_justify' ) ? 'checked' : '' ; ?>>
|
27 |
<label for="mycred_align_justify">
|
28 |
-
<svg id="Layer_1" data-name="Layer 1" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 62.26 61.16"><defs><style>.cls-1{fill:#10212b;}.cls-2{fill:#aab5bc;}.cls-3{fill:none;stroke:#10212b;stroke-miterlimit:10;}</style></defs><title>icon</title><rect class="cls-1" x="9.59" y="13.98" width="43.07" height="3.33" rx="1.67"/><rect class="cls-2" x="11.34" y="20.03" width="39.58" height="1.27" rx="0.44"/><rect class="cls-2" x="11.34" y="22.33" width="39.58" height="1.27" rx="0.44"/><rect class="cls-2" x="11.34" y="24.63" width="39.58" height="1.27" rx="0.44"/><rect class="cls-2" x="11.34" y="26.93" width="39.58" height="1.27" rx="0.44"/><rect class="cls-2" x="11.34" y="29.23" width="39.58" height="1.27" rx="0.44"/><rect class="cls-1" x="9.59" y="36.13" width="43.07" height="3.33" rx="1.67"/><rect class="cls-2" x="11.34" y="42.18" width="39.58" height="1.27" rx="0.44"/><rect class="cls-2" x="11.34" y="44.48" width="39.58" height="1.27" rx="0.44"/><rect class="cls-2" x="11.34" y="46.78" width="39.58" height="1.27" rx="0.44"/><path class="cls-2" d="M61.76,2.53v5H.5v-5c0-1.12.68-2,1.53-2h58.2C61.07.5,61.76,1.41,61.76,2.53Z"/><circle class="cls-1" cx="58.22" cy="4.64" r="0.63"/><circle class="cls-1" cx="55.83" cy="4.64" r="0.63"/><circle class="cls-1" cx="52.67" cy="4.64" r="0.63"/><rect class="cls-3" x="0.5" y="0.5" width="61.26" height="60.16"/></svg><?php
|
29 |
</label>
|
30 |
</li>
|
31 |
<li>
|
32 |
<input type="radio" class="mycred-align-radio" name="mycred_badge[mycred_badge_align]" id="mycred_align_none" value="mycred_align_none" <?php echo ($mycred_badge_align == 'mycred_align_none' ) ? 'checked' : '' ; if ( empty( $mycred_badge_align ) ) echo 'checked'; ?>>
|
33 |
<label for="mycred_align_none">
|
34 |
-
<svg id="Layer_1" data-name="Layer 1" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 62.26 61.16"><defs><style>.cls-1{fill:#10212b;}.cls-2{fill:#aab5bc;}.cls-3{fill:none;stroke:#10212b;stroke-miterlimit:10;}</style></defs><title>icon</title><rect class="cls-1" x="9.02" y="13.98" width="43.07" height="3.33" rx="1.67"/><rect class="cls-2" x="10.42" y="19.03" width="39.58" height="1.27" rx="0.44"/><rect class="cls-2" x="10.42" y="21.33" width="39.58" height="1.27" rx="0.44"/><rect class="cls-2" x="10.42" y="23.63" width="39.58" height="1.27" rx="0.44"/><rect class="cls-2" x="10.42" y="25.93" width="39.58" height="1.27" rx="0.44"/><rect class="cls-2" x="10.42" y="28.23" width="39.58" height="1.27" rx="0.44"/><rect class="cls-2" x="10.42" y="30.53" width="20.48" height="1.27" rx="0.44"/><rect class="cls-1" x="9.02" y="36.13" width="43.07" height="3.33" rx="1.67"/><rect class="cls-2" x="10.42" y="41.18" width="39.58" height="1.27" rx="0.44"/><rect class="cls-2" x="10.42" y="43.48" width="39.58" height="1.27" rx="0.44"/><rect class="cls-2" x="10.42" y="45.78" width="39.58" height="1.27" rx="0.44"/><rect class="cls-2" x="10.42" y="48.08" width="20.48" height="1.27" rx="0.44"/><path class="cls-2" d="M61.76,2.53v5H.5v-5c0-1.12.68-2,1.53-2h58.2C61.07.5,61.76,1.41,61.76,2.53Z"/><circle class="cls-1" cx="58.22" cy="4.64" r="0.63"/><circle class="cls-1" cx="55.83" cy="4.64" r="0.63"/><circle class="cls-1" cx="52.67" cy="4.64" r="0.63"/><rect class="cls-3" x="0.5" y="0.5" width="61.26" height="60.16"/></svg><?php
|
35 |
</label>
|
36 |
</li>
|
37 |
</ul>
|
7 |
<li>
|
8 |
<input type="radio" class="mycred-align-radio" name="mycred_badge[mycred_badge_align]" id="mycred_align_left" value="mycred_align_left" <?php echo ( $mycred_badge_align == 'mycred_align_left' ) ? 'checked' : '' ; ?>>
|
9 |
<label for="mycred_align_left">
|
10 |
+
<svg id="Layer_1" data-name="Layer 1" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 62.26 61.16"><defs><style>.cls-1{fill:#10212b;}.cls-2{fill:#aab5bc;}.cls-3{fill:none;stroke:#10212b;stroke-miterlimit:10;}</style></defs><title>icon</title><rect class="cls-1" x="9.02" y="13.98" width="43.07" height="3.33" rx="1.67"/><rect class="cls-2" x="10.55" y="18.88" width="39.58" height="1.27" rx="0.44"/><rect class="cls-2" x="10.55" y="21.18" width="39.58" height="1.27" rx="0.44"/><rect class="cls-2" x="10.55" y="23.48" width="39.58" height="1.27" rx="0.44"/><rect class="cls-2" x="10.55" y="25.78" width="39.58" height="1.27" rx="0.44"/><rect class="cls-2" x="10.55" y="28.08" width="39.58" height="1.27" rx="0.44"/><rect class="cls-2" x="10.55" y="30.38" width="20.48" height="1.27" rx="0.44"/><rect class="cls-1" x="9.02" y="36.13" width="43.07" height="3.33" rx="1.67"/><rect class="cls-2" x="10.55" y="41.03" width="39.58" height="1.27" rx="0.44"/><rect class="cls-2" x="10.55" y="43.33" width="39.58" height="1.27" rx="0.44"/><rect class="cls-2" x="10.55" y="45.63" width="39.58" height="1.27" rx="0.44"/><rect class="cls-2" x="10.55" y="47.81" width="20.48" height="1.27" rx="0.44"/><path class="cls-2" d="M61.76,2.53v5H.5v-5c0-1.12.68-2,1.53-2h58.2C61.07.5,61.76,1.41,61.76,2.53Z"/><circle class="cls-1" cx="58.22" cy="4.64" r="0.63"/><circle class="cls-1" cx="55.83" cy="4.64" r="0.63"/><circle class="cls-1" cx="52.67" cy="4.64" r="0.63"/><rect class="cls-3" x="0.5" y="0.5" width="61.26" height="60.16"/></svg><?php esc_html_e( 'Left', 'mycred' ); ?>
|
11 |
</label>
|
12 |
</li>
|
13 |
<li>
|
14 |
<input type="radio" class="mycred-align-radio" name="mycred_badge[mycred_badge_align]" id="mycred_align_right" value="mycred_align_right" <?php echo ( $mycred_badge_align == 'mycred_align_right' ) ? 'checked' : '' ; ?>>
|
15 |
<label for="mycred_align_right">
|
16 |
+
<svg id="Layer_1" data-name="Layer 1" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 62.26 61.16"><defs><style>.cls-1{fill:#10212b;}.cls-2{fill:#aab5bc;}.cls-3{fill:none;stroke:#10212b;stroke-miterlimit:10;}</style></defs><title>icon</title><rect class="cls-1" x="9.02" y="13.98" width="43.07" height="3.33" rx="1.67"/><rect class="cls-2" x="10.76" y="20.03" width="39.58" height="1.27" rx="0.44"/><rect class="cls-2" x="10.76" y="22.33" width="39.58" height="1.27" rx="0.44"/><rect class="cls-2" x="10.76" y="24.63" width="39.58" height="1.27" rx="0.44"/><rect class="cls-2" x="10.76" y="26.93" width="39.58" height="1.27" rx="0.44"/><rect class="cls-2" x="10.76" y="29.23" width="39.58" height="1.27" rx="0.44"/><rect class="cls-2" x="29.86" y="31.53" width="20.48" height="1.27" rx="0.44"/><rect class="cls-1" x="9.02" y="36.13" width="43.07" height="3.33" rx="1.67"/><rect class="cls-2" x="10.76" y="42.18" width="39.58" height="1.27" rx="0.44"/><rect class="cls-2" x="10.76" y="44.48" width="39.58" height="1.27" rx="0.44"/><rect class="cls-2" x="10.76" y="46.78" width="39.58" height="1.27" rx="0.44"/><rect class="cls-2" x="29.86" y="49.08" width="20.48" height="1.27" rx="0.44"/><path class="cls-2" d="M61.76,2.53v5H.5v-5c0-1.12.68-2,1.53-2h58.2C61.07.5,61.76,1.41,61.76,2.53Z"/><circle class="cls-1" cx="58.22" cy="4.64" r="0.63"/><circle class="cls-1" cx="55.83" cy="4.64" r="0.63"/><circle class="cls-1" cx="52.67" cy="4.64" r="0.63"/><rect class="cls-3" x="0.5" y="0.5" width="61.26" height="60.16"/></svg><?php esc_html_e( 'Right', 'mycred' ); ?>
|
17 |
</label>
|
18 |
</li>
|
19 |
<li>
|
20 |
<input type="radio" class="mycred-align-radio" name="mycred_badge[mycred_badge_align]" id="mycred_align_center" value="mycred_align_center" <?php echo ( $mycred_badge_align == 'mycred_align_center' ) ? 'checked' : '' ; ?>>
|
21 |
<label for="mycred_align_center">
|
22 |
+
<svg id="Layer_1" data-name="Layer 1" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 62.26 61.16"><defs><style>.cls-1{fill:#10212b;}.cls-2{fill:#aab5bc;}.cls-3{fill:none;stroke:#10212b;stroke-miterlimit:10;}</style></defs><title>icon</title><rect class="cls-1" x="9.59" y="13.98" width="43.07" height="3.33" rx="1.67"/><rect class="cls-2" x="11.34" y="18.4" width="39.58" height="1.27" rx="0.44"/><rect class="cls-2" x="11.34" y="20.7" width="39.58" height="1.27" rx="0.44"/><rect class="cls-2" x="11.34" y="23" width="39.58" height="1.27" rx="0.44"/><rect class="cls-2" x="11.34" y="25.3" width="39.58" height="1.27" rx="0.44"/><rect class="cls-2" x="11.34" y="27.6" width="39.58" height="1.27" rx="0.44"/><rect class="cls-2" x="20.89" y="29.9" width="20.48" height="1.27" rx="0.44"/><rect class="cls-1" x="9.59" y="36.13" width="43.07" height="3.33" rx="1.67"/><rect class="cls-2" x="11.34" y="40.55" width="39.58" height="1.27" rx="0.44"/><rect class="cls-2" x="11.34" y="42.85" width="39.58" height="1.27" rx="0.44"/><rect class="cls-2" x="11.34" y="45.15" width="39.58" height="1.27" rx="0.44"/><rect class="cls-2" x="20.89" y="47.45" width="20.48" height="1.27" rx="0.44"/><path class="cls-2" d="M61.76,2.53v5H.5v-5c0-1.12.68-2,1.53-2h58.2C61.07.5,61.76,1.41,61.76,2.53Z"/><circle class="cls-1" cx="58.22" cy="4.64" r="0.63"/><circle class="cls-1" cx="55.83" cy="4.64" r="0.63"/><circle class="cls-1" cx="52.67" cy="4.64" r="0.63"/><rect class="cls-3" x="0.5" y="0.5" width="61.26" height="60.16"/></svg><?php esc_html_e( 'Center', 'mycred' ); ?>
|
23 |
</label>
|
24 |
</li>
|
25 |
<li>
|
26 |
<input type="radio" class="mycred-align-radio" name="mycred_badge[mycred_badge_align]" id="mycred_align_justify" value="mycred_align_justify" <?php echo ( $mycred_badge_align == 'mycred_align_justify' ) ? 'checked' : '' ; ?>>
|
27 |
<label for="mycred_align_justify">
|
28 |
+
<svg id="Layer_1" data-name="Layer 1" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 62.26 61.16"><defs><style>.cls-1{fill:#10212b;}.cls-2{fill:#aab5bc;}.cls-3{fill:none;stroke:#10212b;stroke-miterlimit:10;}</style></defs><title>icon</title><rect class="cls-1" x="9.59" y="13.98" width="43.07" height="3.33" rx="1.67"/><rect class="cls-2" x="11.34" y="20.03" width="39.58" height="1.27" rx="0.44"/><rect class="cls-2" x="11.34" y="22.33" width="39.58" height="1.27" rx="0.44"/><rect class="cls-2" x="11.34" y="24.63" width="39.58" height="1.27" rx="0.44"/><rect class="cls-2" x="11.34" y="26.93" width="39.58" height="1.27" rx="0.44"/><rect class="cls-2" x="11.34" y="29.23" width="39.58" height="1.27" rx="0.44"/><rect class="cls-1" x="9.59" y="36.13" width="43.07" height="3.33" rx="1.67"/><rect class="cls-2" x="11.34" y="42.18" width="39.58" height="1.27" rx="0.44"/><rect class="cls-2" x="11.34" y="44.48" width="39.58" height="1.27" rx="0.44"/><rect class="cls-2" x="11.34" y="46.78" width="39.58" height="1.27" rx="0.44"/><path class="cls-2" d="M61.76,2.53v5H.5v-5c0-1.12.68-2,1.53-2h58.2C61.07.5,61.76,1.41,61.76,2.53Z"/><circle class="cls-1" cx="58.22" cy="4.64" r="0.63"/><circle class="cls-1" cx="55.83" cy="4.64" r="0.63"/><circle class="cls-1" cx="52.67" cy="4.64" r="0.63"/><rect class="cls-3" x="0.5" y="0.5" width="61.26" height="60.16"/></svg><?php esc_html_e( 'Justify', 'mycred' ); ?>
|
29 |
</label>
|
30 |
</li>
|
31 |
<li>
|
32 |
<input type="radio" class="mycred-align-radio" name="mycred_badge[mycred_badge_align]" id="mycred_align_none" value="mycred_align_none" <?php echo ($mycred_badge_align == 'mycred_align_none' ) ? 'checked' : '' ; if ( empty( $mycred_badge_align ) ) echo 'checked'; ?>>
|
33 |
<label for="mycred_align_none">
|
34 |
+
<svg id="Layer_1" data-name="Layer 1" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 62.26 61.16"><defs><style>.cls-1{fill:#10212b;}.cls-2{fill:#aab5bc;}.cls-3{fill:none;stroke:#10212b;stroke-miterlimit:10;}</style></defs><title>icon</title><rect class="cls-1" x="9.02" y="13.98" width="43.07" height="3.33" rx="1.67"/><rect class="cls-2" x="10.42" y="19.03" width="39.58" height="1.27" rx="0.44"/><rect class="cls-2" x="10.42" y="21.33" width="39.58" height="1.27" rx="0.44"/><rect class="cls-2" x="10.42" y="23.63" width="39.58" height="1.27" rx="0.44"/><rect class="cls-2" x="10.42" y="25.93" width="39.58" height="1.27" rx="0.44"/><rect class="cls-2" x="10.42" y="28.23" width="39.58" height="1.27" rx="0.44"/><rect class="cls-2" x="10.42" y="30.53" width="20.48" height="1.27" rx="0.44"/><rect class="cls-1" x="9.02" y="36.13" width="43.07" height="3.33" rx="1.67"/><rect class="cls-2" x="10.42" y="41.18" width="39.58" height="1.27" rx="0.44"/><rect class="cls-2" x="10.42" y="43.48" width="39.58" height="1.27" rx="0.44"/><rect class="cls-2" x="10.42" y="45.78" width="39.58" height="1.27" rx="0.44"/><rect class="cls-2" x="10.42" y="48.08" width="20.48" height="1.27" rx="0.44"/><path class="cls-2" d="M61.76,2.53v5H.5v-5c0-1.12.68-2,1.53-2h58.2C61.07.5,61.76,1.41,61.76,2.53Z"/><circle class="cls-1" cx="58.22" cy="4.64" r="0.63"/><circle class="cls-1" cx="55.83" cy="4.64" r="0.63"/><circle class="cls-1" cx="52.67" cy="4.64" r="0.63"/><rect class="cls-3" x="0.5" y="0.5" width="61.26" height="60.16"/></svg><?php esc_html_e( 'None', 'mycred' ); ?>
|
35 |
</label>
|
36 |
</li>
|
37 |
</ul>
|
addons/badges/templates/mycred-metabox-badge-layout.php
CHANGED
@@ -7,31 +7,31 @@
|
|
7 |
<li>
|
8 |
<input type="radio" class="mycred-layout-radio" name="mycred_badge[mycred_layout_check]" id="mycred_layout_left" value="mycred_layout_left" <?php echo ( $mycred_layout == 'mycred_layout_left' ) ? 'checked' : '' ; ?>>
|
9 |
<label for="mycred_layout_left">
|
10 |
-
<svg id="Layer_1" data-name="Layer 1" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 62.26 61.16"><defs><style>.cls-1{fill:#aab5bc;}.cls-2{fill:#10212b;}.cls-3{fill:none;stroke:#10212b;stroke-miterlimit:10;}</style></defs><title>icon</title><path class="cls-1" d="M61.76,2.53v5H.5v-5c0-1.12.68-2,1.53-2h58.2C61.07.5,61.76,1.41,61.76,2.53Z"/><path class="cls-2" d="M24.51,15.85H5.93a1.34,1.34,0,0,0-1.34,1.33v11.7a1.34,1.34,0,0,0,1.34,1.34H24.51a1.34,1.34,0,0,0,1.33-1.34V17.18A1.34,1.34,0,0,0,24.51,15.85Zm.9,13a.9.9,0,0,1-.9.91H5.93A.91.91,0,0,1,5,28.88V17.18a.9.9,0,0,1,.91-.9H24.51a.9.9,0,0,1,.9.9Z"/><rect class="cls-2" x="28.02" y="16.06" width="29.65" height="2.29" rx="1.15"/><rect class="cls-1" x="29.22" y="20.23" width="27.24" height="0.87" rx="0.44"/><rect class="cls-1" x="29.22" y="21.81" width="27.24" height="0.87" rx="0.44"/><rect class="cls-1" x="29.22" y="23.39" width="27.24" height="0.87" rx="0.44"/><rect class="cls-1" x="29.22" y="24.98" width="27.24" height="0.87" rx="0.44"/><rect class="cls-1" x="29.22" y="26.56" width="27.24" height="0.87" rx="0.44"/><rect class="cls-1" x="29.22" y="28.14" width="14.1" height="0.87" rx="0.44"/><rect class="cls-1" x="29.22" y="31.5" width="27.24" height="0.87" rx="0.44"/><rect class="cls-1" x="29.22" y="33.09" width="27.24" height="0.87" rx="0.44"/><rect class="cls-1" x="29.22" y="34.67" width="27.24" height="0.87" rx="0.44"/><rect class="cls-1" x="29.22" y="36.25" width="14.1" height="0.87" rx="0.44"/><rect class="cls-1" x="31.65" y="45.35" width="20.1" height="0.87" rx="0.44"/><rect class="cls-1" x="31.65" y="48.26" width="24.49" height="0.87" rx="0.44"/><rect class="cls-1" x="31.65" y="51.04" width="14.1" height="0.87" rx="0.44"/><rect class="cls-2" x="28.02" y="41" width="29.65" height="2.29" rx="1.15"/><circle class="cls-1" cx="29.95" cy="45.95" r="0.6"/><circle class="cls-1" cx="29.95" cy="48.7" r="0.6"/><circle class="cls-1" cx="29.95" cy="51.47" r="0.6"/><path class="cls-2" d="M25.84,20.29v8.59a1.34,1.34,0,0,1-1.33,1.34H5.93a1.34,1.34,0,0,1-1.34-1.34v-.64c.13-.14.27-.3.43-.46a10.18,10.18,0,0,1,6.71-3.1c5.4-.31,8.69-5.59,13.68-4.5l.22.05Z"/><circle class="cls-2" cx="7.5" cy="19.24" r="1.22"/><circle class="cls-2" cx="58.22" cy="4.64" r="0.63"/><circle class="cls-2" cx="55.83" cy="4.64" r="0.63"/><circle class="cls-2" cx="52.67" cy="4.64" r="0.63"/><rect class="cls-3" x="0.5" y="0.5" width="61.26" height="60.16"/></svg><?php
|
11 |
</label>
|
12 |
</li>
|
13 |
<li>
|
14 |
<input type="radio" class="mycred-layout-radio" name="mycred_badge[mycred_layout_check]" id="mycred_layout_top" value="mycred_layout_top" <?php echo ( $mycred_layout == 'mycred_layout_top' ) ? 'checked' : '' ; ?>>
|
15 |
<label for="mycred_layout_top">
|
16 |
-
<svg id="Layer_1" data-name="Layer 1" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 62.26 61.16"><defs><style>.cls-1{fill:#aab5bc;}.cls-2{fill:#10212b;}.cls-3{fill:none;stroke:#10212b;stroke-miterlimit:10;}</style></defs><title>icon</title><path class="cls-1" d="M61.76,2.53v5H.5v-5c0-1.12.68-2,1.53-2h58.2C61.07.5,61.76,1.41,61.76,2.53Z"/><rect class="cls-2" x="16.31" y="31.62" width="29.65" height="2.29" rx="1.15"/><rect class="cls-1" x="17.51" y="35.78" width="27.24" height="0.87" rx="0.44"/><rect class="cls-1" x="17.51" y="37.37" width="27.24" height="0.87" rx="0.44"/><rect class="cls-1" x="17.51" y="38.95" width="27.24" height="0.87" rx="0.44"/><rect class="cls-1" x="17.51" y="40.53" width="27.24" height="0.87" rx="0.44"/><rect class="cls-1" x="17.51" y="42.11" width="27.24" height="0.87" rx="0.44"/><rect class="cls-1" x="17.51" y="43.7" width="14.1" height="0.87" rx="0.44"/><rect class="cls-1" x="17.51" y="47.06" width="27.24" height="0.87" rx="0.44"/><rect class="cls-1" x="17.51" y="48.64" width="27.24" height="0.87" rx="0.44"/><rect class="cls-1" x="17.51" y="50.22" width="27.24" height="0.87" rx="0.44"/><rect class="cls-1" x="17.51" y="51.81" width="14.1" height="0.87" rx="0.44"/><path class="cls-2" d="M40.42,13.17H21.84a1.34,1.34,0,0,0-1.34,1.34v11.7a1.34,1.34,0,0,0,1.34,1.33H40.42a1.34,1.34,0,0,0,1.33-1.33V14.51A1.34,1.34,0,0,0,40.42,13.17Zm.9,13a.9.9,0,0,1-.9.9H21.84a.9.9,0,0,1-.91-.9V14.51a.91.91,0,0,1,.91-.91H40.42a.9.9,0,0,1,.9.91Z"/><path class="cls-2" d="M41.75,17.62v8.59a1.34,1.34,0,0,1-1.33,1.33H21.84a1.34,1.34,0,0,1-1.34-1.33v-.64c.13-.15.27-.3.43-.46A10.21,10.21,0,0,1,27.64,22c5.4-.31,8.69-5.58,13.68-4.49l.22,0A1.29,1.29,0,0,1,41.75,17.62Z"/><circle class="cls-2" cx="23.41" cy="16.56" r="1.22"/><circle class="cls-2" cx="58.22" cy="4.64" r="0.63"/><circle class="cls-2" cx="55.83" cy="4.64" r="0.63"/><circle class="cls-2" cx="52.67" cy="4.64" r="0.63"/><rect class="cls-3" x="0.5" y="0.5" width="61.26" height="60.16"/></svg><?php
|
17 |
</label>
|
18 |
</li>
|
19 |
<li>
|
20 |
<input type="radio" class="mycred-layout-radio" name="mycred_badge[mycred_layout_check]" id="mycred_layout_right" value="mycred_layout_right" <?php echo ( $mycred_layout == 'mycred_layout_right' ) ? 'checked' : '' ; ?>>
|
21 |
<label for="mycred_layout_right">
|
22 |
-
<svg id="Layer_1" data-name="Layer 1" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 62.26 61.16"><defs><style>.cls-1{fill:#aab5bc;}.cls-2{fill:#10212b;}.cls-3{fill:none;stroke:#10212b;stroke-miterlimit:10;}</style></defs><title>icon</title><path class="cls-1" d="M61.76,2.53v5H.5v-5c0-1.12.68-2,1.53-2h58.2C61.07.5,61.76,1.41,61.76,2.53Z"/><rect class="cls-2" x="4.59" y="16.06" width="29.65" height="2.29" rx="1.15"/><rect class="cls-1" x="5.79" y="20.23" width="27.24" height="0.87" rx="0.44"/><rect class="cls-1" x="5.79" y="21.81" width="27.24" height="0.87" rx="0.44"/><rect class="cls-1" x="5.79" y="23.39" width="27.24" height="0.87" rx="0.44"/><rect class="cls-1" x="5.79" y="24.98" width="27.24" height="0.87" rx="0.44"/><rect class="cls-1" x="5.79" y="26.56" width="27.24" height="0.87" rx="0.44"/><rect class="cls-1" x="5.79" y="28.14" width="14.1" height="0.87" rx="0.44"/><rect class="cls-1" x="5.79" y="31.5" width="27.24" height="0.87" rx="0.44"/><rect class="cls-1" x="5.79" y="33.09" width="27.24" height="0.87" rx="0.44"/><rect class="cls-1" x="5.79" y="34.67" width="27.24" height="0.87" rx="0.44"/><rect class="cls-1" x="5.79" y="36.25" width="14.1" height="0.87" rx="0.44"/><rect class="cls-1" x="8.22" y="45.35" width="20.1" height="0.87" rx="0.44"/><rect class="cls-1" x="8.22" y="48.26" width="24.49" height="0.87" rx="0.44"/><rect class="cls-1" x="8.22" y="51.04" width="14.1" height="0.87" rx="0.44"/><rect class="cls-2" x="4.59" y="41" width="29.65" height="2.29" rx="1.15"/><circle class="cls-1" cx="6.52" cy="45.95" r="0.6"/><circle class="cls-1" cx="6.52" cy="48.7" r="0.6"/><circle class="cls-1" cx="6.52" cy="51.47" r="0.6"/><path class="cls-2" d="M56.33,15.85H37.75a1.34,1.34,0,0,0-1.34,1.33v11.7a1.34,1.34,0,0,0,1.34,1.34H56.33a1.34,1.34,0,0,0,1.34-1.34V17.18A1.34,1.34,0,0,0,56.33,15.85Zm.9,13a.9.9,0,0,1-.9.91H37.75a.91.91,0,0,1-.91-.91V17.18a.9.9,0,0,1,.91-.9H56.33a.9.9,0,0,1,.9.9Z"/><path class="cls-2" d="M57.67,20.29v8.59a1.34,1.34,0,0,1-1.34,1.34H37.75a1.34,1.34,0,0,1-1.34-1.34v-.64c.13-.14.27-.3.43-.46a10.21,10.21,0,0,1,6.72-3.1c5.39-.31,8.68-5.59,13.67-4.5l.22.05Z"/><circle class="cls-2" cx="39.32" cy="19.24" r="1.22"/><rect class="cls-3" x="0.5" y="0.5" width="61.26" height="60.16"/></svg><?php
|
23 |
</label>
|
24 |
</li>
|
25 |
<li>
|
26 |
<input type="radio" class="mycred-layout-radio" name="mycred_badge[mycred_layout_check]" id="mycred_layout_bottom" value="mycred_layout_bottom" <?php echo ( $mycred_layout == 'mycred_layout_bottom' ) ? 'checked' : '' ; ?>>
|
27 |
<label for="mycred_layout_bottom">
|
28 |
-
<svg id="Layer_1" data-name="Layer 1" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 62.26 61.16"><defs><style>.cls-1{fill:#aab5bc;}.cls-2{fill:#10212b;}.cls-3{fill:none;stroke:#10212b;stroke-miterlimit:10;}</style></defs><title>icon</title><path class="cls-1" d="M61.76,2.53v5H.5v-5c0-1.12.68-2,1.53-2h58.2C61.07.5,61.76,1.41,61.76,2.53Z"/><rect class="cls-2" x="16.31" y="12.76" width="29.65" height="2.29" rx="1.15"/><rect class="cls-1" x="17.51" y="16.92" width="27.24" height="0.87" rx="0.44"/><rect class="cls-1" x="17.51" y="18.51" width="27.24" height="0.87" rx="0.44"/><rect class="cls-1" x="17.51" y="20.09" width="27.24" height="0.87" rx="0.44"/><rect class="cls-1" x="17.51" y="21.67" width="27.24" height="0.87" rx="0.44"/><rect class="cls-1" x="17.51" y="23.26" width="27.24" height="0.87" rx="0.44"/><rect class="cls-1" x="24.08" y="24.84" width="14.1" height="0.87" rx="0.44"/><rect class="cls-1" x="17.51" y="28.2" width="27.24" height="0.87" rx="0.44"/><rect class="cls-1" x="17.51" y="29.78" width="27.24" height="0.87" rx="0.44"/><rect class="cls-1" x="17.51" y="31.37" width="27.24" height="0.87" rx="0.44"/><rect class="cls-1" x="24.08" y="32.95" width="14.1" height="0.87" rx="0.44"/><path class="cls-2" d="M40.42,40.74H21.84a1.34,1.34,0,0,0-1.34,1.34v11.7a1.34,1.34,0,0,0,1.34,1.34H40.42a1.34,1.34,0,0,0,1.33-1.34V42.08A1.34,1.34,0,0,0,40.42,40.74Zm.9,13a.9.9,0,0,1-.9.91H21.84a.91.91,0,0,1-.91-.91V42.08a.9.9,0,0,1,.91-.9H40.42a.9.9,0,0,1,.9.9Z"/><path class="cls-2" d="M41.75,45.19v8.59a1.34,1.34,0,0,1-1.33,1.34H21.84a1.34,1.34,0,0,1-1.34-1.34v-.64c.13-.15.27-.3.43-.46a10.21,10.21,0,0,1,6.71-3.11c5.4-.3,8.69-5.58,13.68-4.49l.22.05Z"/><circle class="cls-2" cx="23.41" cy="44.14" r="1.22"/><circle class="cls-2" cx="58.22" cy="4.64" r="0.63"/><circle class="cls-2" cx="55.83" cy="4.64" r="0.63"/><circle class="cls-2" cx="52.67" cy="4.64" r="0.63"/><rect class="cls-3" x="0.5" y="0.5" width="61.26" height="60.16"/></svg><?php
|
29 |
</label>
|
30 |
</li>
|
31 |
<li>
|
32 |
<input type="radio" class="mycred-layout-radio" name="mycred_badge[mycred_layout_check]" id="mycred_layout_none" value="mycred_layout_none" <?php echo ($mycred_layout == 'mycred_layout_none' ) ? 'checked' : '' ; if ( empty( $mycred_layout ) ) echo 'checked'; ?>>
|
33 |
<label for="mycred_layout_none">
|
34 |
-
<svg id="Layer_1" data-name="Layer 1" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 62.26 61.16"><defs><style>.cls-1{fill:#aab5bc;}.cls-2{fill:#10212b;}.cls-3{fill:none;stroke:#10212b;stroke-miterlimit:10;}</style></defs><title>icon</title><path class="cls-1" d="M61.76,2.53v5H.5v-5c0-1.12.68-2,1.53-2h58.2C61.07.5,61.76,1.41,61.76,2.53Z"/><rect class="cls-2" x="6.4" y="31.62" width="29.65" height="2.29" rx="1.15"/><rect class="cls-1" x="7.61" y="35.78" width="27.24" height="0.87" rx="0.44"/><rect class="cls-1" x="7.61" y="37.37" width="27.24" height="0.87" rx="0.44"/><rect class="cls-1" x="7.61" y="38.95" width="27.24" height="0.87" rx="0.44"/><rect class="cls-1" x="7.61" y="40.53" width="27.24" height="0.87" rx="0.44"/><rect class="cls-1" x="7.61" y="42.11" width="27.24" height="0.87" rx="0.44"/><rect class="cls-1" x="7.61" y="43.7" width="14.1" height="0.87" rx="0.44"/><rect class="cls-1" x="7.61" y="47.06" width="27.24" height="0.87" rx="0.44"/><rect class="cls-1" x="7.61" y="48.64" width="27.24" height="0.87" rx="0.44"/><rect class="cls-1" x="7.61" y="50.22" width="27.24" height="0.87" rx="0.44"/><rect class="cls-1" x="7.61" y="51.81" width="14.1" height="0.87" rx="0.44"/><path class="cls-2" d="M26.32,13.17H7.74A1.34,1.34,0,0,0,6.4,14.51v11.7a1.34,1.34,0,0,0,1.34,1.33H26.32a1.34,1.34,0,0,0,1.34-1.33V14.51A1.34,1.34,0,0,0,26.32,13.17Zm.91,13a.9.9,0,0,1-.91.9H7.74a.9.9,0,0,1-.9-.9V14.51a.9.9,0,0,1,.9-.91H26.32a.91.91,0,0,1,.91.91Z"/><path class="cls-2" d="M27.66,17.62v8.59a1.34,1.34,0,0,1-1.34,1.33H7.74A1.34,1.34,0,0,1,6.4,26.21v-.64c.13-.15.28-.3.44-.46A10.16,10.16,0,0,1,13.55,22c5.39-.31,8.68-5.58,13.68-4.49l.21,0Z"/><circle class="cls-2" cx="9.31" cy="16.56" r="1.22"/><circle class="cls-2" cx="58.22" cy="4.64" r="0.63"/><circle class="cls-2" cx="55.83" cy="4.64" r="0.63"/><circle class="cls-2" cx="52.67" cy="4.64" r="0.63"/><rect class="cls-3" x="0.5" y="0.5" width="61.26" height="60.16"/></svg><?php
|
35 |
</label>
|
36 |
</li>
|
37 |
</ul>
|
7 |
<li>
|
8 |
<input type="radio" class="mycred-layout-radio" name="mycred_badge[mycred_layout_check]" id="mycred_layout_left" value="mycred_layout_left" <?php echo ( $mycred_layout == 'mycred_layout_left' ) ? 'checked' : '' ; ?>>
|
9 |
<label for="mycred_layout_left">
|
10 |
+
<svg id="Layer_1" data-name="Layer 1" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 62.26 61.16"><defs><style>.cls-1{fill:#aab5bc;}.cls-2{fill:#10212b;}.cls-3{fill:none;stroke:#10212b;stroke-miterlimit:10;}</style></defs><title>icon</title><path class="cls-1" d="M61.76,2.53v5H.5v-5c0-1.12.68-2,1.53-2h58.2C61.07.5,61.76,1.41,61.76,2.53Z"/><path class="cls-2" d="M24.51,15.85H5.93a1.34,1.34,0,0,0-1.34,1.33v11.7a1.34,1.34,0,0,0,1.34,1.34H24.51a1.34,1.34,0,0,0,1.33-1.34V17.18A1.34,1.34,0,0,0,24.51,15.85Zm.9,13a.9.9,0,0,1-.9.91H5.93A.91.91,0,0,1,5,28.88V17.18a.9.9,0,0,1,.91-.9H24.51a.9.9,0,0,1,.9.9Z"/><rect class="cls-2" x="28.02" y="16.06" width="29.65" height="2.29" rx="1.15"/><rect class="cls-1" x="29.22" y="20.23" width="27.24" height="0.87" rx="0.44"/><rect class="cls-1" x="29.22" y="21.81" width="27.24" height="0.87" rx="0.44"/><rect class="cls-1" x="29.22" y="23.39" width="27.24" height="0.87" rx="0.44"/><rect class="cls-1" x="29.22" y="24.98" width="27.24" height="0.87" rx="0.44"/><rect class="cls-1" x="29.22" y="26.56" width="27.24" height="0.87" rx="0.44"/><rect class="cls-1" x="29.22" y="28.14" width="14.1" height="0.87" rx="0.44"/><rect class="cls-1" x="29.22" y="31.5" width="27.24" height="0.87" rx="0.44"/><rect class="cls-1" x="29.22" y="33.09" width="27.24" height="0.87" rx="0.44"/><rect class="cls-1" x="29.22" y="34.67" width="27.24" height="0.87" rx="0.44"/><rect class="cls-1" x="29.22" y="36.25" width="14.1" height="0.87" rx="0.44"/><rect class="cls-1" x="31.65" y="45.35" width="20.1" height="0.87" rx="0.44"/><rect class="cls-1" x="31.65" y="48.26" width="24.49" height="0.87" rx="0.44"/><rect class="cls-1" x="31.65" y="51.04" width="14.1" height="0.87" rx="0.44"/><rect class="cls-2" x="28.02" y="41" width="29.65" height="2.29" rx="1.15"/><circle class="cls-1" cx="29.95" cy="45.95" r="0.6"/><circle class="cls-1" cx="29.95" cy="48.7" r="0.6"/><circle class="cls-1" cx="29.95" cy="51.47" r="0.6"/><path class="cls-2" d="M25.84,20.29v8.59a1.34,1.34,0,0,1-1.33,1.34H5.93a1.34,1.34,0,0,1-1.34-1.34v-.64c.13-.14.27-.3.43-.46a10.18,10.18,0,0,1,6.71-3.1c5.4-.31,8.69-5.59,13.68-4.5l.22.05Z"/><circle class="cls-2" cx="7.5" cy="19.24" r="1.22"/><circle class="cls-2" cx="58.22" cy="4.64" r="0.63"/><circle class="cls-2" cx="55.83" cy="4.64" r="0.63"/><circle class="cls-2" cx="52.67" cy="4.64" r="0.63"/><rect class="cls-3" x="0.5" y="0.5" width="61.26" height="60.16"/></svg><?php esc_html_e( 'Left', 'mycred' ); ?>
|
11 |
</label>
|
12 |
</li>
|
13 |
<li>
|
14 |
<input type="radio" class="mycred-layout-radio" name="mycred_badge[mycred_layout_check]" id="mycred_layout_top" value="mycred_layout_top" <?php echo ( $mycred_layout == 'mycred_layout_top' ) ? 'checked' : '' ; ?>>
|
15 |
<label for="mycred_layout_top">
|
16 |
+
<svg id="Layer_1" data-name="Layer 1" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 62.26 61.16"><defs><style>.cls-1{fill:#aab5bc;}.cls-2{fill:#10212b;}.cls-3{fill:none;stroke:#10212b;stroke-miterlimit:10;}</style></defs><title>icon</title><path class="cls-1" d="M61.76,2.53v5H.5v-5c0-1.12.68-2,1.53-2h58.2C61.07.5,61.76,1.41,61.76,2.53Z"/><rect class="cls-2" x="16.31" y="31.62" width="29.65" height="2.29" rx="1.15"/><rect class="cls-1" x="17.51" y="35.78" width="27.24" height="0.87" rx="0.44"/><rect class="cls-1" x="17.51" y="37.37" width="27.24" height="0.87" rx="0.44"/><rect class="cls-1" x="17.51" y="38.95" width="27.24" height="0.87" rx="0.44"/><rect class="cls-1" x="17.51" y="40.53" width="27.24" height="0.87" rx="0.44"/><rect class="cls-1" x="17.51" y="42.11" width="27.24" height="0.87" rx="0.44"/><rect class="cls-1" x="17.51" y="43.7" width="14.1" height="0.87" rx="0.44"/><rect class="cls-1" x="17.51" y="47.06" width="27.24" height="0.87" rx="0.44"/><rect class="cls-1" x="17.51" y="48.64" width="27.24" height="0.87" rx="0.44"/><rect class="cls-1" x="17.51" y="50.22" width="27.24" height="0.87" rx="0.44"/><rect class="cls-1" x="17.51" y="51.81" width="14.1" height="0.87" rx="0.44"/><path class="cls-2" d="M40.42,13.17H21.84a1.34,1.34,0,0,0-1.34,1.34v11.7a1.34,1.34,0,0,0,1.34,1.33H40.42a1.34,1.34,0,0,0,1.33-1.33V14.51A1.34,1.34,0,0,0,40.42,13.17Zm.9,13a.9.9,0,0,1-.9.9H21.84a.9.9,0,0,1-.91-.9V14.51a.91.91,0,0,1,.91-.91H40.42a.9.9,0,0,1,.9.91Z"/><path class="cls-2" d="M41.75,17.62v8.59a1.34,1.34,0,0,1-1.33,1.33H21.84a1.34,1.34,0,0,1-1.34-1.33v-.64c.13-.15.27-.3.43-.46A10.21,10.21,0,0,1,27.64,22c5.4-.31,8.69-5.58,13.68-4.49l.22,0A1.29,1.29,0,0,1,41.75,17.62Z"/><circle class="cls-2" cx="23.41" cy="16.56" r="1.22"/><circle class="cls-2" cx="58.22" cy="4.64" r="0.63"/><circle class="cls-2" cx="55.83" cy="4.64" r="0.63"/><circle class="cls-2" cx="52.67" cy="4.64" r="0.63"/><rect class="cls-3" x="0.5" y="0.5" width="61.26" height="60.16"/></svg><?php esc_html_e( 'Top', 'mycred' ); ?>
|
17 |
</label>
|
18 |
</li>
|
19 |
<li>
|
20 |
<input type="radio" class="mycred-layout-radio" name="mycred_badge[mycred_layout_check]" id="mycred_layout_right" value="mycred_layout_right" <?php echo ( $mycred_layout == 'mycred_layout_right' ) ? 'checked' : '' ; ?>>
|
21 |
<label for="mycred_layout_right">
|
22 |
+
<svg id="Layer_1" data-name="Layer 1" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 62.26 61.16"><defs><style>.cls-1{fill:#aab5bc;}.cls-2{fill:#10212b;}.cls-3{fill:none;stroke:#10212b;stroke-miterlimit:10;}</style></defs><title>icon</title><path class="cls-1" d="M61.76,2.53v5H.5v-5c0-1.12.68-2,1.53-2h58.2C61.07.5,61.76,1.41,61.76,2.53Z"/><rect class="cls-2" x="4.59" y="16.06" width="29.65" height="2.29" rx="1.15"/><rect class="cls-1" x="5.79" y="20.23" width="27.24" height="0.87" rx="0.44"/><rect class="cls-1" x="5.79" y="21.81" width="27.24" height="0.87" rx="0.44"/><rect class="cls-1" x="5.79" y="23.39" width="27.24" height="0.87" rx="0.44"/><rect class="cls-1" x="5.79" y="24.98" width="27.24" height="0.87" rx="0.44"/><rect class="cls-1" x="5.79" y="26.56" width="27.24" height="0.87" rx="0.44"/><rect class="cls-1" x="5.79" y="28.14" width="14.1" height="0.87" rx="0.44"/><rect class="cls-1" x="5.79" y="31.5" width="27.24" height="0.87" rx="0.44"/><rect class="cls-1" x="5.79" y="33.09" width="27.24" height="0.87" rx="0.44"/><rect class="cls-1" x="5.79" y="34.67" width="27.24" height="0.87" rx="0.44"/><rect class="cls-1" x="5.79" y="36.25" width="14.1" height="0.87" rx="0.44"/><rect class="cls-1" x="8.22" y="45.35" width="20.1" height="0.87" rx="0.44"/><rect class="cls-1" x="8.22" y="48.26" width="24.49" height="0.87" rx="0.44"/><rect class="cls-1" x="8.22" y="51.04" width="14.1" height="0.87" rx="0.44"/><rect class="cls-2" x="4.59" y="41" width="29.65" height="2.29" rx="1.15"/><circle class="cls-1" cx="6.52" cy="45.95" r="0.6"/><circle class="cls-1" cx="6.52" cy="48.7" r="0.6"/><circle class="cls-1" cx="6.52" cy="51.47" r="0.6"/><path class="cls-2" d="M56.33,15.85H37.75a1.34,1.34,0,0,0-1.34,1.33v11.7a1.34,1.34,0,0,0,1.34,1.34H56.33a1.34,1.34,0,0,0,1.34-1.34V17.18A1.34,1.34,0,0,0,56.33,15.85Zm.9,13a.9.9,0,0,1-.9.91H37.75a.91.91,0,0,1-.91-.91V17.18a.9.9,0,0,1,.91-.9H56.33a.9.9,0,0,1,.9.9Z"/><path class="cls-2" d="M57.67,20.29v8.59a1.34,1.34,0,0,1-1.34,1.34H37.75a1.34,1.34,0,0,1-1.34-1.34v-.64c.13-.14.27-.3.43-.46a10.21,10.21,0,0,1,6.72-3.1c5.39-.31,8.68-5.59,13.67-4.5l.22.05Z"/><circle class="cls-2" cx="39.32" cy="19.24" r="1.22"/><rect class="cls-3" x="0.5" y="0.5" width="61.26" height="60.16"/></svg><?php esc_html_e( 'Right', 'mycred' ); ?>
|
23 |
</label>
|
24 |
</li>
|
25 |
<li>
|
26 |
<input type="radio" class="mycred-layout-radio" name="mycred_badge[mycred_layout_check]" id="mycred_layout_bottom" value="mycred_layout_bottom" <?php echo ( $mycred_layout == 'mycred_layout_bottom' ) ? 'checked' : '' ; ?>>
|
27 |
<label for="mycred_layout_bottom">
|
28 |
+
<svg id="Layer_1" data-name="Layer 1" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 62.26 61.16"><defs><style>.cls-1{fill:#aab5bc;}.cls-2{fill:#10212b;}.cls-3{fill:none;stroke:#10212b;stroke-miterlimit:10;}</style></defs><title>icon</title><path class="cls-1" d="M61.76,2.53v5H.5v-5c0-1.12.68-2,1.53-2h58.2C61.07.5,61.76,1.41,61.76,2.53Z"/><rect class="cls-2" x="16.31" y="12.76" width="29.65" height="2.29" rx="1.15"/><rect class="cls-1" x="17.51" y="16.92" width="27.24" height="0.87" rx="0.44"/><rect class="cls-1" x="17.51" y="18.51" width="27.24" height="0.87" rx="0.44"/><rect class="cls-1" x="17.51" y="20.09" width="27.24" height="0.87" rx="0.44"/><rect class="cls-1" x="17.51" y="21.67" width="27.24" height="0.87" rx="0.44"/><rect class="cls-1" x="17.51" y="23.26" width="27.24" height="0.87" rx="0.44"/><rect class="cls-1" x="24.08" y="24.84" width="14.1" height="0.87" rx="0.44"/><rect class="cls-1" x="17.51" y="28.2" width="27.24" height="0.87" rx="0.44"/><rect class="cls-1" x="17.51" y="29.78" width="27.24" height="0.87" rx="0.44"/><rect class="cls-1" x="17.51" y="31.37" width="27.24" height="0.87" rx="0.44"/><rect class="cls-1" x="24.08" y="32.95" width="14.1" height="0.87" rx="0.44"/><path class="cls-2" d="M40.42,40.74H21.84a1.34,1.34,0,0,0-1.34,1.34v11.7a1.34,1.34,0,0,0,1.34,1.34H40.42a1.34,1.34,0,0,0,1.33-1.34V42.08A1.34,1.34,0,0,0,40.42,40.74Zm.9,13a.9.9,0,0,1-.9.91H21.84a.91.91,0,0,1-.91-.91V42.08a.9.9,0,0,1,.91-.9H40.42a.9.9,0,0,1,.9.9Z"/><path class="cls-2" d="M41.75,45.19v8.59a1.34,1.34,0,0,1-1.33,1.34H21.84a1.34,1.34,0,0,1-1.34-1.34v-.64c.13-.15.27-.3.43-.46a10.21,10.21,0,0,1,6.71-3.11c5.4-.3,8.69-5.58,13.68-4.49l.22.05Z"/><circle class="cls-2" cx="23.41" cy="44.14" r="1.22"/><circle class="cls-2" cx="58.22" cy="4.64" r="0.63"/><circle class="cls-2" cx="55.83" cy="4.64" r="0.63"/><circle class="cls-2" cx="52.67" cy="4.64" r="0.63"/><rect class="cls-3" x="0.5" y="0.5" width="61.26" height="60.16"/></svg><?php esc_html_e( 'Bottom', 'mycred' ); ?>
|
29 |
</label>
|
30 |
</li>
|
31 |
<li>
|
32 |
<input type="radio" class="mycred-layout-radio" name="mycred_badge[mycred_layout_check]" id="mycred_layout_none" value="mycred_layout_none" <?php echo ($mycred_layout == 'mycred_layout_none' ) ? 'checked' : '' ; if ( empty( $mycred_layout ) ) echo 'checked'; ?>>
|
33 |
<label for="mycred_layout_none">
|
34 |
+
<svg id="Layer_1" data-name="Layer 1" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 62.26 61.16"><defs><style>.cls-1{fill:#aab5bc;}.cls-2{fill:#10212b;}.cls-3{fill:none;stroke:#10212b;stroke-miterlimit:10;}</style></defs><title>icon</title><path class="cls-1" d="M61.76,2.53v5H.5v-5c0-1.12.68-2,1.53-2h58.2C61.07.5,61.76,1.41,61.76,2.53Z"/><rect class="cls-2" x="6.4" y="31.62" width="29.65" height="2.29" rx="1.15"/><rect class="cls-1" x="7.61" y="35.78" width="27.24" height="0.87" rx="0.44"/><rect class="cls-1" x="7.61" y="37.37" width="27.24" height="0.87" rx="0.44"/><rect class="cls-1" x="7.61" y="38.95" width="27.24" height="0.87" rx="0.44"/><rect class="cls-1" x="7.61" y="40.53" width="27.24" height="0.87" rx="0.44"/><rect class="cls-1" x="7.61" y="42.11" width="27.24" height="0.87" rx="0.44"/><rect class="cls-1" x="7.61" y="43.7" width="14.1" height="0.87" rx="0.44"/><rect class="cls-1" x="7.61" y="47.06" width="27.24" height="0.87" rx="0.44"/><rect class="cls-1" x="7.61" y="48.64" width="27.24" height="0.87" rx="0.44"/><rect class="cls-1" x="7.61" y="50.22" width="27.24" height="0.87" rx="0.44"/><rect class="cls-1" x="7.61" y="51.81" width="14.1" height="0.87" rx="0.44"/><path class="cls-2" d="M26.32,13.17H7.74A1.34,1.34,0,0,0,6.4,14.51v11.7a1.34,1.34,0,0,0,1.34,1.33H26.32a1.34,1.34,0,0,0,1.34-1.33V14.51A1.34,1.34,0,0,0,26.32,13.17Zm.91,13a.9.9,0,0,1-.91.9H7.74a.9.9,0,0,1-.9-.9V14.51a.9.9,0,0,1,.9-.91H26.32a.91.91,0,0,1,.91.91Z"/><path class="cls-2" d="M27.66,17.62v8.59a1.34,1.34,0,0,1-1.34,1.33H7.74A1.34,1.34,0,0,1,6.4,26.21v-.64c.13-.15.28-.3.44-.46A10.16,10.16,0,0,1,13.55,22c5.39-.31,8.68-5.58,13.68-4.49l.21,0Z"/><circle class="cls-2" cx="9.31" cy="16.56" r="1.22"/><circle class="cls-2" cx="58.22" cy="4.64" r="0.63"/><circle class="cls-2" cx="55.83" cy="4.64" r="0.63"/><circle class="cls-2" cx="52.67" cy="4.64" r="0.63"/><rect class="cls-3" x="0.5" y="0.5" width="61.26" height="60.16"/></svg><?php esc_html_e( 'None', 'mycred' ); ?>
|
35 |
</label>
|
36 |
</li>
|
37 |
</ul>
|
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,434 +1,373 @@
|
|
1 |
<?php
|
2 |
-
if (! defined('myCRED_VERSION') )
|
3 |
-
}
|
4 |
|
5 |
/**
|
6 |
* myCRED_Service class
|
7 |
-
*
|
8 |
-
* @
|
9 |
-
* @since 1.2
|
10 |
* @version 1.1
|
11 |
*/
|
12 |
-
if (! class_exists('myCRED_Service') ) :
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
-
|
94 |
-
|
95 |
-
|
96 |
-
|
97 |
-
|
98 |
-
|
99 |
-
|
100 |
-
|
101 |
-
|
102 |
-
|
103 |
-
|
104 |
-
|
105 |
-
|
106 |
-
|
107 |
-
|
108 |
-
|
109 |
-
|
110 |
-
|
111 |
-
|
112 |
-
|
113 |
-
|
114 |
-
|
115 |
-
|
116 |
-
|
117 |
-
|
118 |
-
|
119 |
-
|
120 |
-
|
121 |
-
|
122 |
-
|
123 |
-
|
124 |
-
|
125 |
-
|
126 |
-
|
127 |
-
|
128 |
-
|
129 |
-
|
130 |
-
|
131 |
-
|
132 |
-
|
133 |
-
|
134 |
-
|
135 |
-
|
136 |
-
|
137 |
-
|
138 |
-
|
139 |
-
|
140 |
-
|
141 |
-
|
142 |
-
|
143 |
-
|
144 |
-
|
145 |
-
|
146 |
-
|
147 |
-
|
148 |
-
|
149 |
-
|
150 |
-
|
151 |
-
|
152 |
-
|
153 |
-
|
154 |
-
|
155 |
-
|
156 |
-
|
157 |
-
|
158 |
-
|
159 |
-
|
160 |
-
|
161 |
-
|
162 |
-
|
163 |
-
|
164 |
-
|
165 |
-
|
166 |
-
|
167 |
-
|
168 |
-
|
169 |
-
|
170 |
-
|
171 |
-
|
172 |
-
|
173 |
-
|
174 |
-
|
175 |
-
|
176 |
-
|
177 |
-
|
178 |
-
|
179 |
-
|
180 |
-
|
181 |
-
|
182 |
-
|
183 |
-
|
184 |
-
|
185 |
-
|
186 |
-
|
187 |
-
|
188 |
-
|
189 |
-
|
190 |
-
|
191 |
-
|
192 |
-
|
193 |
-
|
194 |
-
|
195 |
-
|
196 |
-
|
197 |
-
|
198 |
-
|
199 |
-
|
200 |
-
|
201 |
-
|
202 |
-
|
203 |
-
|
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 |
-
|
310 |
-
|
311 |
-
|
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 |
-
|
344 |
-
|
345 |
-
|
346 |
-
|
347 |
-
|
348 |
-
|
349 |
-
|
350 |
-
|
351 |
-
|
352 |
-
|
353 |
-
|
354 |
-
|
355 |
-
|
356 |
-
|
357 |
-
|
358 |
-
|
359 |
-
|
360 |
-
|
361 |
-
|
362 |
-
|
363 |
-
|
364 |
-
|
365 |
-
|
366 |
-
|
367 |
-
|
368 |
-
|
369 |
-
|
370 |
-
|
371 |
-
|
372 |
-
|
373 |
-
|
374 |
-
|
375 |
-
|
376 |
-
|
377 |
-
|
378 |
-
|
379 |
-
|
380 |
-
|
381 |
-
|
382 |
-
|
383 |
-
|
384 |
-
|
385 |
-
|
386 |
-
|
387 |
-
|
388 |
-
|
389 |
-
|
390 |
-
|
391 |
-
|
392 |
-
|
393 |
-
|
394 |
-
|
395 |
-
|
396 |
-
|
397 |
-
|
398 |
-
|
399 |
-
|
400 |
-
|
401 |
-
|
402 |
-
|
403 |
-
|
404 |
-
|
405 |
-
|
406 |
-
|
407 |
-
|
408 |
-
|
409 |
-
|
410 |
-
|
411 |
-
|
412 |
-
|
413 |
-
|
414 |
-
|
415 |
-
|
416 |
-
|
417 |
-
|
418 |
-
|
419 |
-
|
420 |
-
|
421 |
-
|
422 |
-
|
423 |
-
|
424 |
-
|
425 |
-
|
426 |
-
|
427 |
-
|
428 |
-
|
429 |
-
|
430 |
-
|
431 |
-
|
432 |
-
|
433 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
434 |
endif;
|
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="' . esc_attr( $this->field_name( $pref_id ) ) . '" id="' . esc_attr( $this->field_id( $pref_id ) ) . '" class="form-control">';
|
349 |
+
|
350 |
+
if ( $use_select )
|
351 |
+
echo '<option value="">' . esc_html__( '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="' . esc_attr( $value ) . '"';
|
365 |
+
if ( $settings == $value ) echo ' selected="selected"';
|
366 |
+
echo '>' . esc_html( $details['label'] ) . '</option>';
|
367 |
+
}
|
368 |
+
echo '</select>';
|
369 |
+
|
370 |
+
}
|
371 |
+
|
372 |
+
}
|
373 |
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,37 +1,32 @@
|
|
1 |
<?php
|
2 |
-
if (! defined('myCRED_VERSION') )
|
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 |
-
|
14 |
-
{
|
15 |
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
}
|
26 |
|
27 |
-
|
28 |
-
|
29 |
|
30 |
-
|
31 |
-
|
32 |
-
}
|
33 |
|
34 |
-
|
35 |
|
36 |
-
|
37 |
endif;
|
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;
|
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/myCRED-addon-banking.php
CHANGED
@@ -206,7 +206,7 @@ if ( ! class_exists( 'myCRED_Banking_Module' ) ) :
|
|
206 |
|
207 |
<?php $this->update_notice(); ?>
|
208 |
|
209 |
-
<h1><?php
|
210 |
<form method="post" class="form" action="options.php">
|
211 |
|
212 |
<?php settings_fields( $this->settings_name ); ?>
|
@@ -220,13 +220,13 @@ if ( ! class_exists( 'myCRED_Banking_Module' ) ) :
|
|
220 |
foreach ( $installed as $key => $data ) {
|
221 |
|
222 |
?>
|
223 |
-
<h4><span class="dashicons <?php echo $data['icon']; ?><?php if ( $this->is_active( $key ) ) echo ' active'; else echo ' static'; ?>"></span><?php echo $this->core->template_tags_general( $data['title'] ); ?></h4>
|
224 |
<div class="body" style="display: none;">
|
225 |
-
<p><?php echo nl2br( $this->core->template_tags_general( $data['description'] ) ); ?></p>
|
226 |
-
<label class="subheader" for="mycred-bank-service-<?php echo $key; ?>"><?php
|
227 |
<ol>
|
228 |
<li>
|
229 |
-
<input type="checkbox" name="<?php echo $this->option_id; ?>[active][]" id="mycred-bank-service-<?php echo $key; ?>" value="<?php echo $key; ?>"<?php if ( $this->is_active( $key ) ) echo ' checked="checked"'; ?> />
|
230 |
</li>
|
231 |
</ol>
|
232 |
|
@@ -242,7 +242,7 @@ if ( ! class_exists( 'myCRED_Banking_Module' ) ) :
|
|
242 |
|
243 |
</div>
|
244 |
|
245 |
-
<?php submit_button(
|
246 |
|
247 |
</form>
|
248 |
</div>
|
@@ -335,13 +335,13 @@ if ( ! class_exists( 'myCRED_Banking_Module' ) ) :
|
|
335 |
public function ajax_handler() {
|
336 |
|
337 |
// Make sure this is an ajax call for this point type
|
338 |
-
if ( isset( $_REQUEST['_token'] ) && wp_verify_nonce( $_REQUEST['_token'], 'run-mycred-bank-task' . $this->mycred_type ) ) {
|
339 |
|
340 |
// Make sure ajax call is made by an admin
|
341 |
if ( $this->core->user_is_point_admin() ) {
|
342 |
|
343 |
// Get the service requesting to use this
|
344 |
-
$service = sanitize_key( $_POST['service'] );
|
345 |
$installed = $this->get();
|
346 |
|
347 |
// If there is such a service, load it's ajax handler
|
206 |
|
207 |
<?php $this->update_notice(); ?>
|
208 |
|
209 |
+
<h1><?php esc_html_e( 'Central Deposit', 'mycred' ); ?></h1>
|
210 |
<form method="post" class="form" action="options.php">
|
211 |
|
212 |
<?php settings_fields( $this->settings_name ); ?>
|
220 |
foreach ( $installed as $key => $data ) {
|
221 |
|
222 |
?>
|
223 |
+
<h4><span class="dashicons <?php echo esc_attr( $data['icon'] ); ?><?php if ( $this->is_active( $key ) ) echo ' active'; else echo ' static'; ?>"></span><?php echo esc_html( $this->core->template_tags_general( $data['title'] ) ); ?></h4>
|
224 |
<div class="body" style="display: none;">
|
225 |
+
<p><?php echo nl2br( esc_html( $this->core->template_tags_general( $data['description'] ) ) ); ?></p>
|
226 |
+
<label class="subheader" for="mycred-bank-service-<?php echo esc_attr( $key ); ?>"><?php esc_html_e( 'Enable', 'mycred' ); ?></label>
|
227 |
<ol>
|
228 |
<li>
|
229 |
+
<input type="checkbox" name="<?php echo esc_attr( $this->option_id ); ?>[active][]" id="mycred-bank-service-<?php echo esc_attr( $key ); ?>" value="<?php echo esc_attr( $key ); ?>"<?php if ( $this->is_active( $key ) ) echo ' checked="checked"'; ?> />
|
230 |
</li>
|
231 |
</ol>
|
232 |
|
242 |
|
243 |
</div>
|
244 |
|
245 |
+
<?php submit_button( esc_html__( 'Update Changes', 'mycred' ), 'primary large', 'submit', false ); ?>
|
246 |
|
247 |
</form>
|
248 |
</div>
|
335 |
public function ajax_handler() {
|
336 |
|
337 |
// Make sure this is an ajax call for this point type
|
338 |
+
if ( isset( $_REQUEST['_token'] ) && wp_verify_nonce( sanitize_text_field( wp_unslash( $_REQUEST['_token'] ) ), 'run-mycred-bank-task' . $this->mycred_type ) ) {
|
339 |
|
340 |
// Make sure ajax call is made by an admin
|
341 |
if ( $this->core->user_is_point_admin() ) {
|
342 |
|
343 |
// Get the service requesting to use this
|
344 |
+
$service = ( isset( $_POST['service'] ) ? sanitize_key( wp_unslash( $_POST['service'] ) ) : '' );
|
345 |
$installed = $this->get();
|
346 |
|
347 |
// If there is such a service, load it's ajax handler
|
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,213 +1,189 @@
|
|
1 |
<?php
|
2 |
-
if (! defined('myCRED_VERSION') )
|
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 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
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 |
-
|
80 |
-
|
81 |
|
82 |
-
|
83 |
-
|
84 |
|
85 |
-
|
86 |
|
87 |
-
|
88 |
-
|
89 |
|
90 |
-
|
91 |
-
|
92 |
-
}
|
93 |
|
94 |
-
|
95 |
-
|
96 |
-
}
|
97 |
|
98 |
-
|
99 |
-
|
100 |
|
101 |
-
|
102 |
-
|
103 |
|
104 |
-
|
105 |
|
106 |
-
|
107 |
-
|
108 |
|
109 |
-
|
110 |
|
111 |
-
|
112 |
-
|
113 |
-
|
114 |
-
|
115 |
-
|
116 |
-
|
117 |
-
public function preferences()
|
118 |
-
{
|
119 |
|
120 |
-
|
121 |
|
122 |
-
|
123 |
-
|
124 |
-
|
125 |
-
?>
|
126 |
<div class="row">
|
127 |
-
|
128 |
-
|
129 |
-
|
130 |
-
|
131 |
-
|
132 |
-
|
133 |
-
|
134 |
-
|
135 |
-
|
136 |
-
|
137 |
-
|
138 |
-
|
139 |
-
|
140 |
-
|
141 |
-
|
142 |
-
|
143 |
-
|
144 |
-
|
145 |
-
|
146 |
-
|
147 |
-
|
148 |
-
|
149 |
-
|
150 |
-
|
151 |
-
|
152 |
-
|
153 |
</div>
|
154 |
-
|
155 |
-
|
156 |
-
|
157 |
-
|
158 |
-
|
159 |
-
|
160 |
-
|
161 |
-
|
162 |
-
|
163 |
-
|
164 |
-
|
165 |
-
|
166 |
-
|
167 |
-
|
168 |
-
|
169 |
-
|
170 |
-
|
171 |
-
|
172 |
-
|
173 |
-
|
174 |
-
|
175 |
-
|
176 |
-
|
177 |
-
|
178 |
-
|
179 |
-
|
180 |
-
|
181 |
-
|
182 |
-
|
183 |
-
|
184 |
-
|
185 |
-
|
186 |
-
|
187 |
-
|
188 |
-
|
189 |
-
|
190 |
-
|
191 |
-
|
192 |
-
|
193 |
-
|
194 |
-
|
195 |
-
|
196 |
-
|
197 |
-
|
198 |
-
|
199 |
-
|
200 |
-
|
201 |
-
|
202 |
-
|
203 |
-
|
204 |
-
|
205 |
-
|
206 |
-
|
207 |
-
|
208 |
-
die;
|
209 |
-
|
210 |
-
}
|
211 |
-
|
212 |
-
}
|
213 |
-
endif;
|
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 esc_attr( $this->field_id( 'bank_id' ) ); ?>"><?php esc_html_e( 'Select Central Deposit Account', 'mycred' ); ?></label>
|
114 |
+
<select name="<?php echo esc_attr( $this->field_name( 'bank_id' ) ); ?>" id="<?php echo esc_attr( $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 esc_html_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 esc_attr( $this->field_id( 'ignore_manual' ) ); ?>" class="manual-adjust">
|
128 |
+
<input type="checkbox" name="<?php echo esc_attr( $this->field_name( 'ignore_manual' ) ); ?>" id="<?php echo esc_attr( $this->field_id( 'ignore_manual' ) ); ?>" value="1"<?php checked( $this->prefs['ignore_manual'], 1 ); ?>> <?php esc_html_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 = ( isset( $_GET['search'] ) ? sanitize_text_field( wp_unslash( $_GET['search'] ) ) : '' );
|
165 |
+
$page_no = ( isset( $_GET['page'] ) ? absint( $_GET['page'] ) : 1 );
|
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' => ( $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;
|
|
|
|
|
|
|
|
|
|
|
|
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,2383 +1,2162 @@
|
|
1 |
<?php
|
2 |
-
if (! defined('myCRED_VERSION') )
|
3 |
-
}
|
4 |
|
5 |
/**
|
6 |
* myCRED_Payment_Gateway class
|
7 |
-
*
|
8 |
-
* @
|
9 |
-
* @since 0.1
|
10 |
* @version 1.3
|
11 |
*/
|
12 |
-
if (! class_exists('myCRED_Payment_Gateway') ) :
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
-
|
94 |
-
|
95 |
-
|
96 |
-
|
97 |
-
|
98 |
-
|
99 |
-
|
100 |
-
|
101 |
-
|
102 |
-
|
103 |
-
|
104 |
-
|
105 |
-
|
106 |
-
|
107 |
-
|
108 |
-
|
109 |
-
|
110 |
-
|
111 |
-
|
112 |
-
|
113 |
-
|
114 |
-
|
115 |
-
|
116 |
-
|
117 |
-
|
118 |
-
|
119 |
-
|
120 |
-
|
121 |
-
|
122 |
-
|
123 |
-
|
124 |
-
|
125 |
-
|
126 |
-
|
127 |
-
|
128 |
-
|
129 |
-
|
130 |
-
|
131 |
-
|
132 |
-
|
133 |
-
|
134 |
-
|
135 |
-
|
136 |
-
|
137 |
-
|
138 |
-
|
139 |
-
|
140 |
-
|
141 |
-
|
142 |
-
|
143 |
-
|
144 |
-
|
145 |
-
|
146 |
-
|
147 |
-
|
148 |
-
|
149 |
-
|
150 |
-
|
151 |
-
|
152 |
-
|
153 |
-
|
154 |
-
|
155 |
-
|
156 |
-
|
157 |
-
|
158 |
-
|
159 |
-
|
160 |
-
|
161 |
-
|
162 |
-
|
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 |
-
|
261 |
-
elseif ($this->post_id === false ) {
|
262 |
|
263 |
-
|
|
|
|
|
264 |
|
265 |
-
|
266 |
|
267 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
268 |
|
269 |
-
|
270 |
-
|
271 |
-
|
272 |
-
|
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 |
-
|
406 |
-
|
407 |
-
|
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 |
-
|
518 |
-
|
519 |
-
|
520 |
-
|
521 |
-
}
|
522 |
|
523 |
-
|
524 |
-
|
525 |
|
526 |
-
|
527 |
-
|
528 |
|
529 |
-
|
530 |
-
$content = '<img src="' . $this->gateway_logo_url . '" alt="" />';
|
531 |
|
532 |
-
|
533 |
-
} else {
|
534 |
-
$content = '';
|
535 |
-
}
|
536 |
|
537 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
538 |
|
539 |
-
|
|
|
540 |
|
541 |
-
|
542 |
-
|
543 |
-
|
544 |
-
* @since 1.8
|
545 |
-
* @version 1.0
|
546 |
-
*/
|
547 |
-
public function checkout_order()
|
548 |
-
{
|
549 |
|
550 |
-
|
551 |
-
|
552 |
-
|
553 |
-
|
554 |
-
|
555 |
-
|
556 |
-
|
557 |
-
|
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 |
-
|
562 |
|
563 |
-
|
564 |
|
565 |
-
|
566 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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 |
-
|
581 |
-
|
582 |
-
|
583 |
-
|
584 |
-
|
585 |
-
|
586 |
-
|
587 |
-
|
588 |
-
|
589 |
-
|
590 |
-
|
591 |
-
|
592 |
-
|
593 |
-
|
594 |
-
|
595 |
-
|
596 |
-
|
597 |
-
|
598 |
-
|
599 |
-
|
600 |
-
|
601 |
-
|
602 |
-
|
603 |
-
|
604 |
-
|
605 |
-
|
606 |
-
|
607 |
-
|
608 |
-
|
609 |
-
|
610 |
-
|
611 |
-
|
612 |
-
|
613 |
-
|
614 |
-
|
615 |
-
|
616 |
-
|
617 |
-
|
618 |
-
|
619 |
-
|
620 |
-
|
621 |
-
|
622 |
-
|
623 |
-
|
624 |
-
|
625 |
-
|
626 |
-
|
627 |
-
|
628 |
-
|
629 |
-
|
630 |
-
|
631 |
-
|
632 |
-
|
633 |
-
|
634 |
-
|
635 |
-
|
636 |
-
|
637 |
-
|
638 |
-
|
639 |
-
|
640 |
-
|
641 |
-
|
642 |
-
|
643 |
-
|
644 |
-
|
645 |
-
|
646 |
-
|
647 |
-
|
648 |
-
|
649 |
-
|
650 |
-
|
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 |
-
|
680 |
-
|
681 |
|
682 |
-
|
683 |
-
|
684 |
-
}
|
685 |
|
686 |
-
|
687 |
</tr>
|
688 |
</table>';
|
689 |
|
690 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
691 |
|
692 |
-
|
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 |
-
|
832 |
|
833 |
-
|
834 |
-
|
835 |
-
|
|
|
|
|
|
|
836 |
|
837 |
-
|
838 |
|
839 |
-
|
840 |
|
841 |
-
|
|
|
|
|
842 |
|
843 |
-
|
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 |
-
|
|
|
|
|
|
|
|
|
|
|
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 |
-
|
|
|
|
|
871 |
|
872 |
-
|
|
|
873 |
|
874 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
875 |
|
876 |
-
|
877 |
-
|
878 |
-
|
879 |
-
|
880 |
-
* @since 1.8
|
881 |
-
* @version 1.0
|
882 |
-
*/
|
883 |
-
public function get_recipient_id()
|
884 |
-
{
|
885 |
|
886 |
-
|
887 |
-
$recipient_id = $this->current_user_id;
|
888 |
|
889 |
-
|
890 |
-
|
|
|
891 |
|
892 |
-
|
|
|
|
|
893 |
|
894 |
-
|
895 |
-
if ($gift_to > 0 ) {
|
896 |
-
$recipient_id = $gift_to;
|
897 |
-
$this->gifting = true;
|
898 |
-
}
|
899 |
|
900 |
-
|
901 |
|
902 |
-
|
|
|
|
|
|
|
|
|
|
|
903 |
|
904 |
-
|
905 |
-
if ($this->buycred['gifting']['authors'] == 1 ) {
|
906 |
|
907 |
-
|
|
|
908 |
|
909 |
-
|
910 |
-
|
911 |
-
if (isset($post->post_author) ) {
|
912 |
-
$recipient_id = absint($post->post_author);
|
913 |
-
$this->gifting = true;
|
914 |
-
}
|
915 |
|
916 |
-
|
917 |
|
918 |
-
|
|
|
919 |
|
920 |
-
|
|
|
921 |
|
922 |
-
|
923 |
-
public function get_to()
|
924 |
-
{
|
925 |
|
926 |
-
|
|
|
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 |
-
|
940 |
-
|
|
|
|
|
|
|
|
|
|
|
941 |
|
942 |
-
|
943 |
-
|
944 |
|
945 |
-
|
946 |
-
$minimum = $this->core->number($settings['min']);
|
947 |
|
948 |
-
|
949 |
-
|
950 |
-
$amount = $minimum;
|
951 |
-
}
|
952 |
|
953 |
-
|
|
|
954 |
|
955 |
-
|
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 |
-
|
|
|
|
|
|
|
|
|
|
|
969 |
|
970 |
-
|
971 |
|
972 |
-
|
973 |
-
|
974 |
-
$point_type = $type_id;
|
975 |
-
}
|
976 |
|
977 |
-
|
978 |
|
979 |
-
|
980 |
|
981 |
-
|
|
|
|
|
|
|
|
|
|
|
982 |
|
983 |
-
|
984 |
-
|
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 |
-
|
993 |
-
$custom_rate=mycred_decode_values($_REQUEST['er_random']);
|
994 |
-
}
|
995 |
|
996 |
-
|
997 |
|
998 |
-
|
999 |
-
|
1000 |
-
|
1001 |
-
|
|
|
|
|
1002 |
|
1003 |
-
|
1004 |
-
if (array_key_exists($point_type, $this->prefs['exchange']) ) {
|
1005 |
|
1006 |
-
|
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 |
-
|
1017 |
-
|
1018 |
-
|
1019 |
-
|
1020 |
-
|
|
|
1021 |
|
1022 |
-
|
|
|
|
|
1023 |
|
1024 |
-
|
1025 |
-
|
1026 |
-
|
1027 |
-
}
|
1028 |
|
1029 |
-
|
1030 |
-
if (! $raw ) {
|
1031 |
-
$cost = number_format($cost, 2, '.', '');
|
1032 |
-
}
|
1033 |
|
1034 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
1035 |
|
1036 |
-
|
1037 |
|
1038 |
-
|
1039 |
-
|
1040 |
-
|
1041 |
-
|
1042 |
-
* @version 1.1
|
1043 |
-
*/
|
1044 |
-
public function get_thankyou()
|
1045 |
-
{
|
1046 |
|
1047 |
-
|
|
|
|
|
|
|
1048 |
|
1049 |
-
|
1050 |
-
|
1051 |
|
1052 |
-
|
1053 |
-
$url = mycred_get_permalink($this->buycred['thankyou']['page']);
|
1054 |
-
}
|
1055 |
|
1056 |
-
|
1057 |
|
1058 |
-
|
1059 |
-
elseif ($this->buycred['thankyou']['use'] == 'custom' ) {
|
1060 |
|
1061 |
-
|
1062 |
-
$url = $this->buycred['thankyou']['custom'];
|
1063 |
-
}
|
1064 |
|
1065 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
1066 |
|
1067 |
-
|
1068 |
-
$url = str_replace('%profile%', $profile_url, $url);
|
1069 |
|
1070 |
-
|
|
|
|
|
|
|
1071 |
|
1072 |
-
|
|
|
|
|
|
|
1073 |
|
1074 |
-
|
1075 |
-
|
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 |
-
|
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 |
-
|
1114 |
|
1115 |
-
|
1116 |
-
|
|
|
|
|
|
|
|
|
1117 |
|
1118 |
-
|
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 |
-
|
1132 |
-
|
1133 |
-
|
|
|
|
|
|
|
1134 |
|
1135 |
-
|
|
|
|
|
1136 |
|
1137 |
-
|
1138 |
|
1139 |
-
|
1140 |
-
|
1141 |
-
|
1142 |
-
|
1143 |
-
|
1144 |
-
|
1145 |
-
public function log_entry( $content, $log_entry )
|
1146 |
-
{
|
1147 |
|
1148 |
-
|
|
|
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 |
-
|
1162 |
-
|
1163 |
-
|
1164 |
-
|
|
|
|
|
1165 |
|
1166 |
-
|
1167 |
-
|
1168 |
-
|
1169 |
-
|
|
|
|
|
|
|
1170 |
|
1171 |
-
|
1172 |
|
1173 |
-
|
1174 |
-
|
1175 |
-
|
1176 |
-
|
1177 |
-
|
1178 |
-
|
1179 |
-
|
1180 |
-
public function field_name( $field = '' )
|
1181 |
-
{
|
1182 |
|
1183 |
-
|
1184 |
-
|
1185 |
-
|
1186 |
-
|
1187 |
-
if (! is_numeric($parent) ) {
|
1188 |
-
$array[] = str_replace('-', '_', $parent);
|
1189 |
-
}
|
1190 |
|
1191 |
-
|
1192 |
-
|
1193 |
-
|
1194 |
-
|
1195 |
-
|
1196 |
-
|
1197 |
-
|
1198 |
-
|
1199 |
-
|
1200 |
-
|
1201 |
-
|
1202 |
-
|
1203 |
-
|
1204 |
-
|
1205 |
-
|
1206 |
-
|
1207 |
-
|
1208 |
-
|
1209 |
-
|
1210 |
-
|
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 |
-
|
1352 |
-
|
1353 |
-
|
1354 |
-
|
1355 |
-
|
1356 |
-
|
1357 |
-
|
1358 |
-
|
1359 |
-
|
1360 |
-
|
1361 |
-
|
1362 |
-
<?php do_action('mycred_buycred_page_header', $title, $reload, $this->id); ?>
|
1363 |
|
1364 |
</head>
|
1365 |
<body class="mycred-metabox">
|
1366 |
-
|
1367 |
-
|
1368 |
-
|
1369 |
-
|
1370 |
-
|
1371 |
-
|
1372 |
-
|
1373 |
-
|
1374 |
-
|
1375 |
-
|
1376 |
-
|
1377 |
-
|
1378 |
-
|
1379 |
-
|
1380 |
-
|
1381 |
-
|
1382 |
-
|
1383 |
-
|
1384 |
-
|
1385 |
-
|
1386 |
-
|
1387 |
-
|
1388 |
-
|
1389 |
-
|
1390 |
-
|
1391 |
-
|
1392 |
-
|
1393 |
-
|
1394 |
-
|
1395 |
-
|
1396 |
-
|
1397 |
-
|
1398 |
-
|
1399 |
-
|
1400 |
-
|
1401 |
-
|
1402 |
-
|
1403 |
-
|
1404 |
-
|
1405 |
-
|
1406 |
-
|
1407 |
-
|
1408 |
-
|
1409 |
-
|
1410 |
-
|
1411 |
-
|
1412 |
-
|
1413 |
-
|
1414 |
-
|
1415 |
-
|
1416 |
-
|
1417 |
-
|
1418 |
-
|
1419 |
-
|
1420 |
-
|
1421 |
-
|
1422 |
-
|
1423 |
-
|
1424 |
-
|
1425 |
-
|
1426 |
-
|
1427 |
-
|
1428 |
-
|
1429 |
-
|
1430 |
-
|
1431 |
-
|
1432 |
-
|
1433 |
-
|
1434 |
-
|
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 |
-
|
1452 |
-
|
1453 |
-
|
1454 |
-
|
1455 |
-
|
1456 |
-
|
1457 |
-
|
1458 |
-
|
1459 |
-
|
1460 |
-
|
1461 |
-
|
1462 |
-
|
1463 |
-
|
1464 |
-
|
1465 |
-
|
1466 |
-
|
1467 |
-
|
1468 |
-
|
1469 |
-
|
1470 |
-
|
1471 |
</table>
|
1472 |
-
|
1473 |
-
|
1474 |
-
|
1475 |
-
|
1476 |
-
|
1477 |
-
|
1478 |
-
|
1479 |
-
|
1480 |
-
|
1481 |
-
|
1482 |
-
|
1483 |
-
|
1484 |
-
|
1485 |
-
|
1486 |
-
|
1487 |
-
|
1488 |
-
|
1489 |
-
|
1490 |
-
|
1491 |
-
|
1492 |
-
|
1493 |
-
|
1494 |
-
|
1495 |
-
|
1496 |
-
|
1497 |
-
|
1498 |
-
|
1499 |
-
|
1500 |
-
|
1501 |
-
|
1502 |
-
|
1503 |
-
|
1504 |
-
|
1505 |
-
|
1506 |
-
|
1507 |
-
|
1508 |
-
|
1509 |
-
|
1510 |
-
|
1511 |
-
|
1512 |
-
|
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 |
-
|
1522 |
-
|
1523 |
-
|
1524 |
-
|
1525 |
-
|
1526 |
-
|
1527 |
-
|
1528 |
-
|
1529 |
-
</div>
|
1530 |
</div>
|
1531 |
-
<script type="text/javascript"><?php if ($this->sandbox_mode )
|
1532 |
-
|
1533 |
-
|
1534 |
-
|
1535 |
-
|
1536 |
-
|
1537 |
-
|
1538 |
-
|
1539 |
-
|
1540 |
-
|
1541 |
-
|
1542 |
-
|
1543 |
-
|
1544 |
-
|
1545 |
-
|
1546 |
-
|
1547 |
-
|
1548 |
-
|
1549 |
-
|
1550 |
-
|
1551 |
-
|
1552 |
-
|
1553 |
-
|
1554 |
-
|
1555 |
-
|
1556 |
-
|
1557 |
-
|
1558 |
-
|
1559 |
-
|
1560 |
-
|
1561 |
-
|
1562 |
-
|
1563 |
-
|
1564 |
-
|
1565 |
-
|
1566 |
-
|
1567 |
-
|
1568 |
-
|
1569 |
-
|
1570 |
-
|
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 |
-
|
1587 |
-
|
1588 |
-
|
1589 |
-
|
1590 |
-
|
1591 |
-
|
1592 |
-
|
1593 |
-
|
1594 |
-
|
1595 |
-
|
1596 |
-
|
1597 |
-
|
1598 |
-
|
1599 |
-
|
1600 |
-
|
1601 |
-
|
1602 |
-
|
1603 |
-
|
1604 |
-
|
1605 |
-
|
1606 |
-
|
1607 |
-
|
1608 |
-
|
1609 |
-
|
1610 |
-
|
1611 |
-
|
1612 |
-
|
1613 |
-
|
1614 |
-
|
1615 |
-
|
1616 |
-
|
1617 |
-
|
1618 |
-
|
1619 |
-
|
1620 |
-
|
1621 |
-
|
1622 |
-
|
1623 |
-
|
1624 |
-
|
1625 |
-
|
1626 |
-
|
1627 |
-
|
1628 |
-
|
1629 |
-
|
1630 |
-
|
1631 |
-
|
1632 |
-
|
1633 |
-
|
1634 |
-
|
1635 |
-
|
1636 |
-
|
1637 |
-
|
1638 |
-
|
1639 |
-
|
1640 |
-
|
1641 |
-
|
1642 |
-
|
1643 |
-
|
1644 |
-
|
1645 |
-
|
1646 |
-
|
1647 |
-
|
1648 |
-
|
1649 |
-
|
1650 |
-
|
1651 |
-
|
1652 |
-
|
1653 |
-
|
1654 |
-
|
1655 |
-
|
1656 |
-
|
1657 |
-
|
1658 |
-
|
1659 |
-
|
1660 |
-
|
1661 |
-
|
1662 |
-
|
1663 |
-
|
1664 |
-
|
1665 |
-
|
1666 |
-
|
1667 |
-
|
1668 |
-
|
1669 |
-
|
1670 |
-
|
1671 |
-
|
1672 |
-
|
1673 |
-
|
1674 |
-
|
1675 |
-
|
1676 |
-
|
1677 |
-
|
1678 |
-
|
1679 |
-
|
1680 |
-
|
1681 |
-
|
1682 |
-
|
1683 |
-
|
1684 |
-
|
1685 |
-
|
1686 |
-
|
1687 |
-
|
1688 |
-
|
1689 |
-
|
1690 |
-
|
1691 |
-
|
1692 |
-
|
1693 |
-
|
1694 |
-
|
1695 |
-
|
1696 |
-
|
1697 |
-
|
1698 |
-
|
1699 |
-
|
1700 |
-
|
1701 |
-
|
1702 |
-
|
1703 |
-
|
1704 |
-
|
1705 |
-
|
1706 |
-
|
1707 |
-
|
1708 |
-
|
1709 |
-
|
1710 |
-
|
1711 |
-
|
1712 |
-
|
1713 |
-
|
1714 |
-
|
1715 |
-
|
1716 |
-
|
1717 |
-
|
1718 |
-
|
1719 |
-
|
1720 |
-
|
1721 |
-
|
1722 |
-
|
1723 |
-
|
1724 |
-
|
1725 |
-
|
1726 |
-
|
1727 |
-
|
1728 |
-
|
1729 |
-
|
1730 |
-
|
1731 |
-
|
1732 |
-
|
1733 |
-
|
1734 |
-
|
1735 |
-
|
1736 |
-
|
1737 |
-
|
1738 |
-
|
1739 |
-
|
1740 |
-
|
1741 |
-
|
1742 |
-
|
1743 |
-
|
1744 |
-
|
1745 |
-
|
1746 |
-
|
1747 |
-
|
1748 |
-
|
1749 |
-
|
1750 |
-
|
1751 |
-
|
1752 |
-
|
1753 |
-
|
1754 |
-
|
1755 |
-
|
1756 |
-
|
1757 |
-
|
1758 |
-
|
1759 |
-
|
1760 |
-
|
1761 |
-
|
1762 |
-
|
1763 |
-
|
1764 |
-
|
1765 |
-
|
1766 |
-
|
1767 |
-
|
1768 |
-
|
1769 |
-
|
1770 |
-
|
1771 |
-
|
1772 |
-
|
1773 |
-
|
1774 |
-
|
1775 |
-
|
1776 |
-
|
1777 |
-
|
1778 |
-
|
1779 |
-
|
1780 |
-
|
1781 |
-
|
1782 |
-
|
1783 |
-
|
1784 |
-
|
1785 |
-
|
1786 |
-
|
1787 |
-
|
1788 |
-
|
1789 |
-
|
1790 |
-
|
1791 |
-
|
1792 |
-
|
1793 |
-
|
1794 |
-
|
1795 |
-
|
1796 |
-
|
1797 |
-
|
1798 |
-
|
1799 |
-
|
1800 |
-
|
1801 |
-
|
1802 |
-
|
1803 |
-
|
1804 |
-
|
1805 |
-
|
1806 |
-
|
1807 |
-
|
1808 |
-
|
1809 |
-
|
1810 |
-
|
1811 |
-
|
1812 |
-
|
1813 |
-
|
1814 |
-
|
1815 |
-
|
1816 |
-
|
1817 |
-
|
1818 |
-
|
1819 |
-
|
1820 |
-
|
1821 |
-
|
1822 |
-
|
1823 |
-
|
1824 |
-
|
1825 |
-
|
1826 |
-
|
1827 |
-
|
1828 |
-
|
1829 |
-
|
1830 |
-
|
1831 |
-
|
1832 |
-
|
1833 |
-
|
1834 |
-
|
1835 |
-
|
1836 |
-
|
1837 |
-
|
1838 |
-
|
1839 |
-
|
1840 |
-
|
1841 |
-
|
1842 |
-
|
1843 |
-
|
1844 |
-
|
1845 |
-
|
1846 |
-
|
1847 |
-
|
1848 |
-
|
1849 |
-
|
1850 |
-
|
1851 |
-
|
1852 |
-
|
1853 |
-
|
1854 |
-
|
1855 |
-
|
1856 |
-
|
1857 |
-
|
1858 |
-
|
1859 |
-
|
1860 |
-
|
1861 |
-
|
1862 |
-
|
1863 |
-
|
1864 |
-
|
1865 |
-
|
1866 |
-
|
1867 |
-
|
1868 |
-
|
1869 |
-
|
1870 |
-
|
1871 |
-
|
1872 |
-
|
1873 |
-
|
1874 |
-
|
1875 |
-
|
1876 |
-
|
1877 |
-
|
1878 |
-
|
1879 |
-
|
1880 |
-
|
1881 |
-
|
1882 |
-
|
1883 |
-
|
1884 |
-
|
1885 |
-
|
1886 |
-
|
1887 |
-
|
1888 |
-
|
1889 |
-
|
1890 |
-
|
1891 |
-
|
1892 |
-
|
1893 |
-
|
1894 |
-
|
1895 |
-
|
1896 |
-
|
1897 |
-
|
1898 |
-
|
1899 |
-
|
1900 |
-
|
1901 |
-
|
1902 |
-
|
1903 |
-
|
1904 |
-
|
1905 |
-
|
1906 |
-
|
1907 |
-
|
1908 |
-
|
1909 |
-
|
1910 |
-
|
1911 |
-
|
1912 |
-
|
1913 |
-
|
1914 |
-
|
1915 |
-
|
1916 |
-
|
1917 |
-
|
1918 |
-
|
1919 |
-
|
1920 |
-
|
1921 |
-
|
1922 |
-
|
1923 |
-
|
1924 |
-
|
1925 |
-
|
1926 |
-
|
1927 |
-
|
1928 |
-
|
1929 |
-
|
1930 |
-
|
1931 |
-
|
1932 |
-
|
1933 |
-
|
1934 |
-
|
1935 |
-
|
1936 |
-
|
1937 |
-
|
1938 |
-
|
1939 |
-
|
1940 |
-
|
1941 |
-
|
1942 |
-
|
1943 |
-
|
1944 |
-
|
1945 |
-
|
1946 |
-
|
1947 |
-
|
1948 |
-
|
1949 |
-
|
1950 |
-
|
1951 |
-
|
1952 |
-
|
1953 |
-
|
1954 |
-
|
1955 |
-
|
1956 |
-
|
1957 |
-
|
1958 |
-
|
1959 |
-
|
1960 |
-
|
1961 |
-
|
1962 |
-
|
1963 |
-
|
1964 |
-
|
1965 |
-
|
1966 |
-
|
1967 |
-
|
1968 |
-
|
1969 |
-
|
1970 |
-
|
1971 |
-
|
1972 |
-
|
1973 |
-
|
1974 |
-
|
1975 |
-
|
1976 |
-
|
1977 |
-
|
1978 |
-
|
1979 |
-
|
1980 |
-
|
1981 |
-
|
1982 |
-
|
1983 |
-
|
1984 |
-
|
1985 |
-
|
1986 |
-
|
1987 |
-
|
1988 |
-
|
1989 |
-
|
1990 |
-
|
1991 |
-
|
1992 |
-
|
1993 |
-
|
1994 |
-
|
1995 |
-
|
1996 |
-
|
1997 |
-
|
1998 |
-
|
1999 |
-
|
2000 |
-
|
2001 |
-
|
2002 |
-
|
2003 |
-
|
2004 |
-
|
2005 |
-
|
2006 |
-
|
2007 |
-
|
2008 |
-
|
2009 |
-
|
2010 |
-
|
2011 |
-
|
2012 |
-
|
2013 |
-
|
2014 |
-
|
2015 |
-
|
2016 |
-
|
2017 |
-
|
2018 |
-
|
2019 |
-
|
2020 |
-
|
2021 |
-
|
2022 |
-
|
2023 |
-
|
2024 |
-
|
2025 |
-
|
2026 |
-
|
2027 |
-
|
2028 |
-
|
2029 |
-
|
2030 |
-
|
2031 |
-
|
2032 |
-
|
2033 |
-
|
2034 |
-
|
2035 |
-
|
2036 |
-
|
2037 |
-
|
2038 |
-
|
2039 |
-
|
2040 |
-
|
2041 |
-
|
2042 |
-
|
2043 |
-
|
2044 |
-
|
2045 |
-
|
2046 |
-
|
2047 |
-
|
2048 |
-
|
2049 |
-
|
2050 |
-
|
2051 |
-
|
2052 |
-
|
2053 |
-
|
2054 |
-
|
2055 |
-
|
2056 |
-
|
2057 |
-
|
2058 |
-
|
2059 |
-
|
2060 |
-
|
2061 |
-
|
2062 |
-
|
2063 |
-
|
2064 |
-
|
2065 |
-
|
2066 |
-
|
2067 |
-
|
2068 |
-
|
2069 |
-
|
2070 |
-
|
2071 |
-
|
2072 |
-
|
2073 |
-
|
2074 |
-
|
2075 |
-
|
2076 |
-
|
2077 |
-
|
2078 |
-
|
2079 |
-
|
2080 |
-
|
2081 |
-
|
2082 |
-
|
2083 |
-
|
2084 |
-
|
2085 |
-
|
2086 |
-
|
2087 |
-
|
2088 |
-
|
2089 |
-
|
2090 |
-
|
2091 |
-
|
2092 |
-
|
2093 |
-
|
2094 |
-
|
2095 |
-
|
2096 |
-
|
2097 |
-
|
2098 |
-
|
2099 |
-
|
2100 |
-
|
2101 |
-
|
2102 |
-
|
2103 |
-
|
2104 |
-
|
2105 |
-
|
2106 |
-
|
2107 |
-
|
2108 |
-
|
2109 |
-
|
2110 |
-
|
2111 |
-
|
2112 |
-
|
2113 |
-
|
2114 |
-
|
2115 |
-
|
2116 |
-
|
2117 |
-
|
2118 |
-
|
2119 |
-
|
2120 |
-
|
2121 |
-
|
2122 |
-
|
2123 |
-
|
2124 |
-
|
2125 |
-
|
2126 |
-
|
2127 |
-
|
2128 |
-
|
2129 |
-
|
2130 |
-
|
2131 |
-
|
2132 |
-
|
2133 |
-
|
2134 |
-
|
2135 |
-
|
2136 |
-
|
2137 |
-
|
2138 |
-
|
2139 |
-
|
2140 |
-
|
2141 |
-
|
2142 |
-
|
2143 |
-
|
2144 |
-
|
2145 |
-
|
2146 |
-
|
2147 |
-
|
2148 |
-
|
2149 |
-
|
2150 |
-
|
2151 |
-
|
2152 |
-
|
2153 |
-
|
2154 |
-
|
2155 |
-
|
2156 |
-
|
2157 |
-
|
2158 |
-
|
2159 |
-
|
2160 |
-
|
2161 |
-
|
2162 |
-
|
2163 |
-
|
2164 |
-
|
2165 |
-
|
2166 |
-
|
2167 |
-
|
2168 |
-
|
2169 |
-
|
2170 |
-
|
2171 |
-
|
2172 |
-
|
2173 |
-
|
2174 |
-
|
2175 |
-
|
2176 |
-
|
2177 |
-
|
2178 |
-
|
2179 |
-
|
2180 |
-
|
2181 |
-
|
2182 |
-
|
2183 |
-
|
2184 |
-
|
2185 |
-
|
2186 |
-
|
2187 |
-
|
2188 |
-
|
2189 |
-
|
2190 |
-
|
2191 |
-
|
2192 |
-
|
2193 |
-
|
2194 |
-
|
2195 |
-
|
2196 |
-
|
2197 |
-
|
2198 |
-
|
2199 |
-
|
2200 |
-
|
2201 |
-
|
2202 |
-
|
2203 |
-
|
2204 |
-
|
2205 |
-
|
2206 |
-
|
2207 |
-
|
2208 |
-
|
2209 |
-
|
2210 |
-
|
2211 |
-
|
2212 |
-
|
2213 |
-
|
2214 |
-
|
2215 |
-
|
2216 |
-
|
2217 |
-
|
2218 |
-
|
2219 |
-
|
2220 |
-
|
2221 |
-
|
2222 |
-
|
2223 |
-
|
2224 |
-
|
2225 |
-
|
2226 |
-
|
2227 |
-
|
2228 |
-
|
2229 |
-
|
2230 |
-
|
2231 |
-
|
2232 |
-
|
2233 |
-
|
2234 |
-
|
2235 |
-
|
2236 |
-
|
2237 |
-
|
2238 |
-
|
2239 |
-
|
2240 |
-
|
2241 |
-
|
2242 |
-
|
2243 |
-
|
2244 |
-
|
2245 |
-
|
2246 |
-
|
2247 |
-
|
2248 |
-
|
2249 |
-
|
2250 |
-
|
2251 |
-
|
2252 |
-
|
2253 |
-
|
2254 |
-
|
2255 |
-
|
2256 |
-
|
2257 |
-
|
2258 |
-
|
2259 |
-
|
2260 |
-
|
2261 |
-
|
2262 |
-
|
2263 |
-
|
2264 |
-
|
2265 |
-
|
2266 |
-
|
2267 |
-
|
2268 |
-
|
2269 |
-
|
2270 |
-
|
2271 |
-
|
2272 |
-
|
2273 |
-
|
2274 |
-
|
2275 |
-
|
2276 |
-
|
2277 |
-
|
2278 |
-
|
2279 |
-
|
2280 |
-
|
2281 |
-
|
2282 |
-
|
2283 |
-
|
2284 |
-
|
2285 |
-
|
2286 |
-
|
2287 |
-
|
2288 |
-
|
2289 |
-
|
2290 |
-
|
2291 |
-
|
2292 |
-
|
2293 |
-
|
2294 |
-
|
2295 |
-
|
2296 |
-
|
2297 |
-
|
2298 |
-
|
2299 |
-
|
2300 |
-
|
2301 |
-
|
2302 |
-
|
2303 |
-
|
2304 |
-
|
2305 |
-
|
2306 |
-
|
2307 |
-
|
2308 |
-
|
2309 |
-
|
2310 |
-
|
2311 |
-
|
2312 |
-
|
2313 |
-
|
2314 |
-
|
2315 |
-
|
2316 |
-
|
2317 |
-
|
2318 |
-
|
2319 |
-
|
2320 |
-
|
2321 |
-
|
2322 |
-
|
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;
|
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( sanitize_text_field( wp_unslash( $_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( wp_unslash( $_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 |
+
$allowed_tags = array(
|
613 |
+
'table' => array(),
|
614 |
+
'tr' => array(),
|
615 |
+
'td' => array( 'style' => array() ),
|
616 |
+
'div' => array( 'class' => array() ),
|
617 |
+
'input' => array(
|
618 |
+
'type' => array(),
|
619 |
+
'name' => array(),
|
620 |
+
'id' => array(),
|
621 |
+
'value' => array(),
|
622 |
+
'size' => array()
|
623 |
+
),
|
624 |
+
'span' => array( 'class' => array() )
|
625 |
+
);
|
626 |
+
|
627 |
+
echo wp_kses( apply_filters( 'mycred_buycred_exchange_rate_field', $content, $default, $this ), $allowed_tags );
|
628 |
+
|
629 |
+
}
|
630 |
+
|
631 |
+
/**
|
632 |
+
* Add Pending Payment
|
633 |
+
* @since 1.5
|
634 |
+
* @version 1.1.1
|
635 |
+
*/
|
636 |
+
public function add_pending_payment( $data ) {
|
637 |
+
|
638 |
+
$post_id = false;
|
639 |
+
list ( $to, $from, $amount, $cost, $currency, $point_type ) = $data;
|
640 |
+
|
641 |
+
// Title
|
642 |
+
if ( isset( $_REQUEST['transaction_id'] ) )
|
643 |
+
$post_title = sanitize_title( wp_unslash( $_REQUEST['transaction_id'] ) );
|
644 |
+
else
|
645 |
+
$post_title = strtoupper( wp_generate_password( 6, false, false ) );
|
646 |
+
|
647 |
+
$check = $this->transaction_exists( $to, $from, $amount, $cost, $currency, $point_type );
|
648 |
+
if ( $check !== false ) return $check;
|
649 |
+
|
650 |
+
// Make sure we are not adding more then one pending item
|
651 |
+
$check = mycred_get_page_by_title( $post_title, ARRAY_A, 'buycred_payment' );
|
652 |
+
if ( $check === NULL || ( isset( $check['post_status'] ) && $check['post_status'] == 'trash' ) ) {
|
653 |
+
|
654 |
+
// Generate new id and trash old request
|
655 |
+
if ( isset( $check['post_status'] ) && $check['post_status'] == 'trash' ) {
|
656 |
+
buycred_trash_pending_payment( $check['ID'] );
|
657 |
+
$post_title = strtoupper( wp_generate_password( 6, false, false ) );
|
658 |
+
}
|
659 |
+
|
660 |
+
// Insert post
|
661 |
+
$post_id = wp_insert_post( array(
|
662 |
+
'post_title' => $post_title,
|
663 |
+
'post_type' => 'buycred_payment',
|
664 |
+
'post_status' => 'publish',
|
665 |
+
'post_author' => $from,
|
666 |
+
'ping_status' => 'closed',
|
667 |
+
'comment_status' => 'open'
|
668 |
+
) );
|
669 |
+
|
670 |
+
// Add meta details if insertion was a success
|
671 |
+
if ( $post_id !== NULL && ! is_wp_error( $post_id ) ) {
|
672 |
+
|
673 |
+
mycred_add_post_meta( $post_id, 'from', $to, true );
|
674 |
+
mycred_add_post_meta( $post_id, 'to', $from, true );
|
675 |
+
mycred_add_post_meta( $post_id, 'amount', $amount, true );
|
676 |
+
mycred_add_post_meta( $post_id, 'cost', $cost, true );
|
677 |
+
mycred_add_post_meta( $post_id, 'currency', $currency, true );
|
678 |
+
mycred_add_post_meta( $post_id, 'point_type', $point_type, true);
|
679 |
+
mycred_add_post_meta( $post_id, 'gateway', $this->id, true );
|
680 |
+
|
681 |
+
mycred_delete_user_meta( $from, 'buycred_pending_payments' );
|
682 |
+
|
683 |
+
$mycred = mycred( $point_type );
|
684 |
+
|
685 |
+
$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() ) );
|
686 |
+
$log_entry = apply_filters( 'mycred_new_buycred_request_comment_' . $this->id, $log_entry, $data );
|
687 |
+
|
688 |
+
$this->log_call( $post_id, $log_entry );
|
689 |
+
|
690 |
+
}
|
691 |
+
|
692 |
+
}
|
693 |
+
else $post_id = $check['ID'];
|
694 |
+
|
695 |
+
return apply_filters( 'mycred_add_pending_payment', $post_id, $data );
|
696 |
+
|
697 |
+
}
|
698 |
+
|
699 |
+
public function transaction_exists( $to, $from, $amount, $cost, $currency, $point_type ) {
|
700 |
+
|
701 |
+
$post_query = array(
|
702 |
+
'post_type' => 'buycred_payment',
|
703 |
+
'post_status' => 'publish',
|
704 |
+
'posts_per_page' => '-1',
|
705 |
+
'orderby' => 'date',
|
706 |
+
'order' => 'DESC',
|
707 |
+
'fields' => 'ids'
|
708 |
+
);
|
709 |
+
|
710 |
+
$meta_query = array();
|
711 |
+
|
712 |
+
$meta_query[] = array(
|
713 |
+
'key' => 'to',
|
714 |
+
'value' => $to,
|
715 |
+
'compare' => '=',
|
716 |
+
'type' => 'NUMERIC'
|
717 |
+
);
|
718 |
+
|
719 |
+
$meta_query[] = array(
|
720 |
+
'key' => 'from',
|
721 |
+
'value' => $from,
|
722 |
+
'compare' => '=',
|
723 |
+
'type' => 'NUMERIC'
|
724 |
+
);
|
725 |
+
|
726 |
+
$meta_query[] = array(
|
727 |
+
'key' => 'amount',
|
728 |
+
'value' => $amount,
|
729 |
+
'compare' => '=',
|
730 |
+
'type' => 'NUMERIC'
|
731 |
+
);
|
732 |
+
|
733 |
+
$meta_query[] = array(
|
734 |
+
'key' => 'cost',
|
735 |
+
'value' => $cost,
|
736 |
+
'compare' => '=',
|
737 |
+
'type' => 'NUMERIC'
|
738 |
+
);
|
739 |
+
|
740 |
+
$meta_query[] = array(
|
741 |
+
'key' => 'currency',
|
742 |
+
'value' => $currency,
|
743 |
+
'compare' => '='
|
744 |
+
);
|
745 |
+
|
746 |
+
$meta_query[] = array(
|
747 |
+
'key' => 'point_type',
|
748 |
+
'value' => $point_type,
|
749 |
+
'compare' => '='
|
750 |
+
);
|
751 |
+
|
752 |
+
$meta_query[] = array(
|
753 |
+
'key' => 'gateway',
|
754 |
+
'value' => $this->id,
|
755 |
+
'compare' => '='
|
756 |
+
);
|
757 |
+
|
758 |
+
$post_query['meta_query'] = $meta_query;
|
759 |
+
|
760 |
+
$post_id = false;
|
761 |
+
$pending = new WP_Query( $post_query );
|
762 |
+
if ( ! empty( $pending->posts ) ) {
|
763 |
+
|
764 |
+
$post_id = $pending->posts[0];
|
765 |
+
|
766 |
+
wp_reset_postdata();
|
767 |
+
|
768 |
+
}
|
769 |
+
|
770 |
+
return $post_id;
|
771 |
+
|
772 |
+
}
|
773 |
+
|
774 |
+
/**
|
775 |
+
* First Comment
|
776 |
+
* Used to allow a gateway to adjust the first comment with pending payments.
|
777 |
+
* @since 1.7.3
|
778 |
+
* @version 1.0
|
779 |
+
*/
|
780 |
+
public function first_comment( $comment ) {
|
781 |
+
|
782 |
+
return $comment;
|
783 |
+
|
784 |
+
}
|
785 |
+
|
786 |
+
/**
|
787 |
+
* Get Pending Payment
|
788 |
+
* @since 1.5
|
789 |
+
* @version 1.1
|
790 |
+
*/
|
791 |
+
public function get_pending_payment( $post_id = NULL ) {
|
792 |
+
|
793 |
+
$pending_payment = buycred_get_pending_payment( $post_id );
|
794 |
+
|
795 |
+
return apply_filters( 'mycred_get_pending_payment', $pending_payment, $post_id );
|
796 |
+
|
797 |
+
}
|
798 |
+
|
799 |
+
/**
|
800 |
+
* Get Recipient ID
|
801 |
+
* Returns the numeric ID of the user that is nominated to receive the purchased points.
|
802 |
+
* @since 1.8
|
803 |
+
* @version 1.0
|
804 |
+
*/
|
805 |
+
public function get_recipient_id() {
|
806 |
+
|
807 |
+
$this->gifting = false;
|
808 |
+
$recipient_id = $this->current_user_id;
|
809 |
+
|
810 |
+
// Gift to a user
|
811 |
+
if ( $this->buycred['gifting']['members'] == 1 ) {
|
812 |
+
|
813 |
+
if ( isset( $_REQUEST['gift_to'] ) ) {
|
814 |
+
|
815 |
+
$gift_to = absint( $_REQUEST['gift_to'] );
|
816 |
+
if ( $gift_to > 0 ) {
|
817 |
+
$recipient_id = $gift_to;
|
818 |
+
$this->gifting = true;
|
819 |
+
}
|
820 |
+
|
821 |
+
}
|
822 |
+
|
823 |
+
}
|
824 |
+
|
825 |
+
// Gifting author
|
826 |
+
if ( $this->buycred['gifting']['authors'] == 1 ) {
|
827 |
+
|
828 |
+
if ( isset( $_REQEST['post_id'] ) ) {
|
829 |
+
|
830 |
+
$post_id = absint( $_REQEST['post_id'] );
|
831 |
+
$post = mycred_get_post( $post_id );
|
832 |
+
if ( isset( $post->post_author ) ) {
|
833 |
+
$recipient_id = absint( $post->post_author );
|
834 |
+
$this->gifting = true;
|
835 |
+
}
|
836 |
+
|
837 |
+
}
|
838 |
+
|
839 |
+
}
|
840 |
+
|
841 |
+
return apply_filters( 'mycred_get_buycred_recipient_id', $recipient_id, $this );
|
842 |
+
|
843 |
+
}
|
844 |
+
|
845 |
+
public function get_to() {
|
846 |
+
|
847 |
+
return $this->get_recipient_id();
|
848 |
+
|
849 |
+
}
|
850 |
+
|
851 |
+
/**
|
852 |
+
* Get Amount
|
853 |
+
* @since 1.8
|
854 |
+
* @version 1.0
|
855 |
+
*/
|
856 |
+
public function get_amount() {
|
857 |
+
|
858 |
+
$settings = mycred_get_buycred_sale_setup( $this->point_type );
|
859 |
+
$amount = false;
|
860 |
+
|
861 |
+
// Validate amount ( amount is not zero, higher then minimum required and do not exceed maximum (if set) )
|
862 |
+
if ( isset( $_REQUEST['amount'] ) && is_numeric( $_REQUEST['amount'] ) ) {
|
863 |
+
|
864 |
+
$amount = $this->core->number( sanitize_text_field( wp_unslash( $_REQUEST['amount'] ) ) );
|
865 |
+
$minimum = $this->core->number( $settings['min'] );
|
866 |
+
|
867 |
+
// Enforce minimum
|
868 |
+
if ( $amount < $minimum )
|
869 |
+
$amount = $minimum;
|
870 |
+
|
871 |
+
}
|
872 |
|
873 |
+
return apply_filters( 'mycred_get_buycred_amount', $amount, $this );
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
874 |
|
875 |
+
}
|
876 |
|
877 |
+
/**
|
878 |
+
* Get Point Type
|
879 |
+
* @since 1.5
|
880 |
+
* @version 1.2
|
881 |
+
*/
|
882 |
+
public function get_point_type() {
|
883 |
|
884 |
+
$point_type = MYCRED_DEFAULT_TYPE_KEY;
|
885 |
|
886 |
+
if ( isset( $_REQUEST['ctype'] ) ) {
|
887 |
|
888 |
+
$type_id = sanitize_key( $_REQUEST['ctype'] );
|
889 |
+
if ( $type_id != '' && mycred_point_type_exists( $type_id ) )
|
890 |
+
$point_type = $type_id;
|
891 |
|
892 |
+
}
|
893 |
|
894 |
+
return $point_type;
|
895 |
|
896 |
+
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
897 |
|
898 |
+
/**
|
899 |
+
* Get Cost
|
900 |
+
* @since 1.3.2
|
901 |
+
* @version 1.2
|
902 |
+
*/
|
903 |
+
public function get_cost( $amount = 0, $point_type = MYCRED_DEFAULT_TYPE_KEY, $raw = false, $custom_rate = 0 ) {
|
904 |
|
905 |
+
if( ! empty( $_REQUEST['er_random'] ) ) {
|
906 |
+
|
907 |
+
$custom_rate = mycred_decode_values( $_REQUEST['er_random'] );
|
908 |
+
|
909 |
+
}
|
910 |
|
911 |
+
$setup = mycred_get_buycred_sale_setup( $point_type );
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
912 |
|
913 |
+
// Apply minimum
|
914 |
+
if ( $amount < $setup['min'] )
|
915 |
+
$amount = $setup['min'];
|
916 |
|
917 |
+
// Calculate cost here so we can use any exchange rate
|
918 |
+
if ( array_key_exists( $point_type, $this->prefs['exchange'] ) ) {
|
919 |
|
920 |
+
// Check for user override
|
921 |
+
$override = mycred_get_user_meta( $this->current_user_id, 'mycred_buycred_rates_' . $point_type, '', true );
|
922 |
+
if ( isset( $override[ $this->id ] ) && $override[ $this->id ] != '' )
|
923 |
+
$rate = $override[ $this->id ];
|
924 |
+
else if( $custom_rate !=0 )
|
925 |
+
$rate = $custom_rate;
|
926 |
+
else
|
927 |
+
$rate = $this->prefs['exchange'][ $point_type ];
|
928 |
|
929 |
+
if ( isfloat( $rate ) )
|
930 |
+
$rate = (float) $rate;
|
931 |
+
else
|
932 |
+
$rate = (int) $rate;
|
|
|
|
|
|
|
|
|
|
|
933 |
|
934 |
+
$cost = $amount * $rate;
|
|
|
935 |
|
936 |
+
}
|
937 |
+
else
|
938 |
+
$cost = $amount;
|
939 |
|
940 |
+
// Return a properly formated cost so PayPal is happy
|
941 |
+
if ( ! $raw )
|
942 |
+
$cost = number_format( $cost, 2, '.', '' );
|
943 |
|
944 |
+
return apply_filters( 'mycred_buycred_get_cost', $cost, $amount, $point_type, $this->prefs, $setup );
|
|
|
|
|
|
|
|
|
945 |
|
946 |
+
}
|
947 |
|
948 |
+
/**
|
949 |
+
* Get Thank You Page
|
950 |
+
* @since 0.1
|
951 |
+
* @version 1.1
|
952 |
+
*/
|
953 |
+
public function get_thankyou() {
|
954 |
|
955 |
+
$url = home_url( '/' );
|
|
|
956 |
|
957 |
+
// Using a page
|
958 |
+
if ( $this->buycred['thankyou']['use'] == 'page' ) {
|
959 |
|
960 |
+
if ( ! empty( $this->buycred['thankyou']['page'] ) )
|
961 |
+
$url = mycred_get_permalink( $this->buycred['thankyou']['page'] );
|
|
|
|
|
|
|
|
|
962 |
|
963 |
+
}
|
964 |
|
965 |
+
// Using a custom url
|
966 |
+
elseif ( $this->buycred['thankyou']['use'] == 'custom' ) {
|
967 |
|
968 |
+
if ( ! empty( $this->buycred['thankyou']['custom'] ) )
|
969 |
+
$url = $this->buycred['thankyou']['custom'];
|
970 |
|
971 |
+
}
|
|
|
|
|
972 |
|
973 |
+
$profile_url = mycred_get_users_profile_url( $this->buyer_id );
|
974 |
+
$url = str_replace( '%profile%', $profile_url, $url );
|
975 |
|
976 |
+
return apply_filters( 'mycred_buycred_thankyou_url', $url, $this );
|
977 |
|
978 |
+
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
979 |
|
980 |
+
/**
|
981 |
+
* Get Entry
|
982 |
+
* Returns the appropriate log entry template.
|
983 |
+
* @since 0.1
|
984 |
+
* @version 1.1
|
985 |
+
*/
|
986 |
+
public function get_entry( $recipient_id = false, $buyer_id = false ) {
|
987 |
|
988 |
+
if ( $recipient_id === false ) $recipient_id = $this->recipient_id;
|
989 |
+
if ( $buyer_id === false ) $buyer_id = $this->buyer_id;
|
990 |
|
991 |
+
$log_entry = $this->buycred['log'];
|
|
|
992 |
|
993 |
+
// Log entry
|
994 |
+
if ( $recipient_id != $buyer_id ) {
|
|
|
|
|
995 |
|
996 |
+
if ( $this->buycred['gifting']['members'] == 1 || $this->buycred['gifting']['authors'] == 1 )
|
997 |
+
$log_entry = $this->buycred['gifting']['log'];
|
998 |
|
999 |
+
}
|
1000 |
|
1001 |
+
return $log_entry;
|
1002 |
|
1003 |
+
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1004 |
|
1005 |
+
/**
|
1006 |
+
* Get Cancelled Page
|
1007 |
+
* @since 0.1
|
1008 |
+
* @version 1.4
|
1009 |
+
*/
|
1010 |
+
public function get_cancelled( $transaction_id = NULL ) {
|
1011 |
|
1012 |
+
$url = buycred_get_cancel_transaction_url( $transaction_id );
|
1013 |
|
1014 |
+
$profile_url = mycred_get_users_profile_url( $this->buyer_id );
|
1015 |
+
$url = str_replace( '%profile%', $profile_url, $url );
|
|
|
|
|
1016 |
|
1017 |
+
return $url;
|
1018 |
|
1019 |
+
}
|
1020 |
|
1021 |
+
/**
|
1022 |
+
* Log Gateway Call
|
1023 |
+
* @since 1.5
|
1024 |
+
* @version 1.2
|
1025 |
+
*/
|
1026 |
+
public function log_call( $payment_id, $log ) {
|
1027 |
|
1028 |
+
if ( is_array( $log ) )
|
1029 |
+
$log = implode( '<br />', $log );
|
|
|
|
|
|
|
|
|
|
|
|
|
1030 |
|
1031 |
+
buycred_add_pending_comment( $payment_id, $log );
|
|
|
|
|
1032 |
|
1033 |
+
}
|
1034 |
|
1035 |
+
/**
|
1036 |
+
* Decode Log Entries
|
1037 |
+
* @since 0.1
|
1038 |
+
* @version 1.0
|
1039 |
+
*/
|
1040 |
+
public function log_entry( $content, $log_entry ) {
|
1041 |
|
1042 |
+
return $this->core->template_tags_user( $content, $log_entry->ref_id );
|
|
|
1043 |
|
1044 |
+
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1045 |
|
1046 |
+
/**
|
1047 |
+
* Get Log Entry
|
1048 |
+
* @since 1.4
|
1049 |
+
* @version 1.0.1
|
1050 |
+
*/
|
1051 |
+
public function get_log_entry( $from = 0, $to = 0 ) {
|
1052 |
|
1053 |
+
$entry = $this->get_entry( $from, $to );
|
1054 |
+
if ( isset( $this->label ) )
|
1055 |
+
$entry = str_replace( '%gateway%', $this->label, $entry );
|
1056 |
|
1057 |
+
if ( $this->sandbox_mode ) $entry = 'TEST ' . $entry;
|
1058 |
+
|
1059 |
+
return apply_filters( 'mycred_buycred_get_log_entry', $entry, $from, $to, $this );
|
|
|
1060 |
|
1061 |
+
}
|
|
|
|
|
|
|
1062 |
|
1063 |
+
/**
|
1064 |
+
* Get Field Name
|
1065 |
+
* Returns the field name for the current gateway
|
1066 |
+
* @since 0.1
|
1067 |
+
* @version 1.0
|
1068 |
+
*/
|
1069 |
+
public function field_name( $field = '' ) {
|
1070 |
|
1071 |
+
if ( is_array( $field ) ) {
|
1072 |
|
1073 |
+
$array = array();
|
1074 |
+
foreach ( $field as $parent => $child ) {
|
1075 |
+
if ( ! is_numeric( $parent ) )
|
1076 |
+
$array[] = str_replace( '-', '_', $parent );
|
|
|
|
|
|
|
|
|
1077 |
|
1078 |
+
if ( ! empty( $child ) && ! is_array( $child ) )
|
1079 |
+
$array[] = str_replace( '-', '_', $child );
|
1080 |
+
}
|
1081 |
+
$field = '[' . implode( '][', $array ) . ']';
|
1082 |
|
1083 |
+
}
|
1084 |
+
else {
|
1085 |
|
1086 |
+
$field = '[' . $field . ']';
|
|
|
|
|
1087 |
|
1088 |
+
}
|
1089 |
|
1090 |
+
return 'mycred_pref_buycreds[gateway_prefs][' . $this->id . ']' . $field;
|
|
|
1091 |
|
1092 |
+
}
|
|
|
|
|
1093 |
|
1094 |
+
/**
|
1095 |
+
* Get Field ID
|
1096 |
+
* Returns the field id for the current gateway
|
1097 |
+
* @since 0.1
|
1098 |
+
* @version 1.0
|
1099 |
+
*/
|
1100 |
+
public function field_id( $field = '' ) {
|
1101 |
|
1102 |
+
if ( is_array( $field ) ) {
|
|
|
1103 |
|
1104 |
+
$array = array();
|
1105 |
+
foreach ( $field as $parent => $child ) {
|
1106 |
+
if ( ! is_numeric( $parent ) )
|
1107 |
+
$array[] = str_replace( '_', '-', $parent );
|
1108 |
|
1109 |
+
if ( ! empty( $child ) && ! is_array( $child ) )
|
1110 |
+
$array[] = str_replace( '_', '-', $child );
|
1111 |
+
}
|
1112 |
+
$field = implode( '-', $array );
|
1113 |
|
1114 |
+
}
|
1115 |
+
else {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1116 |
|
1117 |
+
$field = str_replace( '_', '-', $field );
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1118 |
|
1119 |
+
}
|
1120 |
|
1121 |
+
return 'mycred-gateway-prefs-' . str_replace( '_', '-', $this->id ) . '-' . $field;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1122 |
|
1123 |
+
}
|
1124 |
|
1125 |
+
/**
|
1126 |
+
* Callback URL
|
1127 |
+
* @since 0.1
|
1128 |
+
* @version 1.2
|
1129 |
+
*/
|
1130 |
+
public function callback_url() {
|
1131 |
|
1132 |
+
$url = add_query_arg( 'mycred_call', $this->id, home_url( '/' ) );
|
1133 |
|
1134 |
+
return apply_filters( 'mycred_buycred_callback_url', $url, $this );
|
1135 |
|
1136 |
+
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1137 |
|
1138 |
+
/**
|
1139 |
+
* Start Log
|
1140 |
+
* @since 1.4
|
1141 |
+
* @version 1.0
|
1142 |
+
*/
|
1143 |
+
public function start_log() {
|
1144 |
|
1145 |
+
$this->new_log_entry( 'Incoming confirmation call detected' );
|
1146 |
+
$this->new_log_entry( sprintf( 'Gateway identified itself as "%s"', $this->id ) );
|
1147 |
+
$this->new_log_entry( 'Verifying caller' );
|
1148 |
|
1149 |
+
}
|
1150 |
|
1151 |
+
/**
|
1152 |
+
* New Log Entry
|
1153 |
+
* @since 0.1
|
1154 |
+
* @version 1.0
|
1155 |
+
*/
|
1156 |
+
public function new_log_entry( $entry = '' ) {
|
|
|
|
|
1157 |
|
1158 |
+
if ( ! isset( $this->processing_log[ $this->id ] ) )
|
1159 |
+
$this->processing_log[ $this->id ] = array();
|
1160 |
|
1161 |
+
$this->processing_log[ $this->id ][] = $entry;
|
1162 |
|
1163 |
+
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1164 |
|
1165 |
+
/**
|
1166 |
+
* Save Log Entry
|
1167 |
+
* @since 0.1
|
1168 |
+
* @version 1.0
|
1169 |
+
*/
|
1170 |
+
public function save_log_entry( $id = '', $outcome = '' ) {
|
1171 |
|
1172 |
+
update_option( 'mycred_buycred_last_call', array(
|
1173 |
+
'gateway' => $this->id,
|
1174 |
+
'date' => time(),
|
1175 |
+
'outcome' => $outcome,
|
1176 |
+
'id' => $id,
|
1177 |
+
'entries' => serialize( $this->processing_log[ $this->id ] )
|
1178 |
+
) );
|
1179 |
|
1180 |
+
}
|
1181 |
|
1182 |
+
/**
|
1183 |
+
* Payment Page Header
|
1184 |
+
* Pre 1.8 setup. Will be removed as of version 1.9
|
1185 |
+
* @since 0.1
|
1186 |
+
* @version 1.2
|
1187 |
+
*/
|
1188 |
+
public function get_page_header( $site_title = '', $reload = false ) {
|
|
|
|
|
1189 |
|
1190 |
+
// Set Logo
|
1191 |
+
$logo = '';
|
1192 |
+
if ( isset( $this->prefs['logo'] ) && ! empty( $this->prefs['logo'] ) )
|
1193 |
+
$logo = '<img src="' . $this->prefs['logo'] . '" alt="" />';
|
|
|
|
|
|
|
1194 |
|
1195 |
+
elseif ( isset( $this->prefs['logo_url'] ) && ! empty( $this->prefs['logo_url'] ) )
|
1196 |
+
$logo = '<img src="' . $this->prefs['logo_url'] . '" alt="" />';
|
1197 |
+
|
1198 |
+
elseif ( isset( $this->gateway_logo_url ) && ! empty( $this->gateway_logo_url ) )
|
1199 |
+
$logo = '<img src="' . $this->gateway_logo_url . '" alt="" />';
|
1200 |
+
|
1201 |
+
// Set Title
|
1202 |
+
if ( $this->sandbox_mode )
|
1203 |
+
$title = __( 'Test Payment', 'mycred' );
|
1204 |
+
|
1205 |
+
elseif ( isset( $this->label ) )
|
1206 |
+
$title = $this->label;
|
1207 |
+
|
1208 |
+
else
|
1209 |
+
$title = __( 'Payment', 'mycred' );
|
1210 |
+
|
1211 |
+
if ( ! isset( $this->transaction_id ) )
|
1212 |
+
$this->transaction_id = '';
|
1213 |
+
|
1214 |
+
?><!DOCTYPE html>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1215 |
<html <?php language_attributes(); ?>>
|
1216 |
<head>
|
1217 |
+
<meta charset="<?php bloginfo( 'charset' ); ?>" />
|
1218 |
+
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" />
|
1219 |
+
<meta name="apple-mobile-web-app-capable" content="yes" />
|
1220 |
+
<title><?php echo $site_title; ?></title>
|
1221 |
+
<meta name="robots" content="noindex, nofollow" />
|
1222 |
+
<?php if ( $reload ) echo '<meta http-equiv="refresh" content="2;url=' . $reload . '" />'; ?>
|
1223 |
+
|
1224 |
+
<link rel="stylesheet" href="<?php echo plugins_url( 'assets/css/gateway.css', MYCRED_PURCHASE ); ?>" type="text/css" media="all" />
|
1225 |
+
<link rel="stylesheet" href="<?php echo plugins_url( 'assets/css/bootstrap-grid.css', myCRED_THIS ); ?>" type="text/css" media="all" />
|
1226 |
+
<link rel="stylesheet" href="<?php echo plugins_url( 'assets/css/mycred-forms.css', myCRED_THIS ); ?>" type="text/css" media="all" />
|
1227 |
+
<?php do_action( 'mycred_buycred_page_header', $title, $reload, $this->id ); ?>
|
|
|
1228 |
|
1229 |
</head>
|
1230 |
<body class="mycred-metabox">
|
1231 |
+
<div class="row">
|
1232 |
+
<div class="col-lg-6 col-md-6 col-sm-12 col-xs-12">
|
1233 |
+
<?php echo $logo; ?>
|
1234 |
+
</div>
|
1235 |
+
<div class="col-lg-6 col-md-6 col-sm-12 col-xs-12 text-right">
|
1236 |
+
<h2><?php echo $title; ?></h2>
|
1237 |
+
<p><a href="<?php echo $this->get_cancelled( $this->transaction_id ); ?>" id="return-where-we-came-from"><?php _e( 'Cancel', 'mycred' ); ?></a></p>
|
1238 |
+
</div>
|
1239 |
+
</div>
|
1240 |
+
<?php
|
1241 |
+
|
1242 |
+
do_action( 'mycred_buycred_page_top', $title, $reload, $this->id );
|
1243 |
+
|
1244 |
+
}
|
1245 |
+
public function purchase_header( $title = '', $reload = false ) {
|
1246 |
+
$this->get_page_header( $title, $reload );
|
1247 |
+
}
|
1248 |
+
|
1249 |
+
/**
|
1250 |
+
* Payment Page Footer
|
1251 |
+
* @since 0.1
|
1252 |
+
* @version 1.1
|
1253 |
+
*/
|
1254 |
+
public function get_page_footer() {
|
1255 |
+
|
1256 |
+
do_action( 'mycred_buycred_page_footer', $this->id );
|
1257 |
+
|
1258 |
+
?>
|
1259 |
+
</body>
|
1260 |
+
</html>
|
1261 |
+
<?php
|
1262 |
+
|
1263 |
+
}
|
1264 |
+
|
1265 |
+
public function purchase_footer() {
|
1266 |
+
$this->get_page_footer();
|
1267 |
+
}
|
1268 |
+
|
1269 |
+
/**
|
1270 |
+
* Get Buyers Name
|
1271 |
+
* @since 1.6
|
1272 |
+
* @version 1.0
|
1273 |
+
*/
|
1274 |
+
public function get_buyers_name( $user_id = NULL ) {
|
1275 |
+
|
1276 |
+
if ( $user_id === NULL ) return '';
|
1277 |
+
|
1278 |
+
$user = get_userdata( $user_id );
|
1279 |
+
if ( ! isset( $user->ID ) ) return $user_id;
|
1280 |
+
|
1281 |
+
if ( ! empty( $user->first_name ) && ! empty( $user->last_name ) )
|
1282 |
+
$name = $user->first_name . ' ' . $user->last_name;
|
1283 |
+
|
1284 |
+
elseif ( class_exists( 'WooCommerce' ) )
|
1285 |
+
$name = get_user_meta( $user_id, 'billing_first_name', true ) . ' ' . get_user_meta( $user_id, 'billing_last_name', true );
|
1286 |
+
|
1287 |
+
else
|
1288 |
+
$name = $user->display_name;
|
1289 |
+
|
1290 |
+
return $name;
|
1291 |
+
|
1292 |
+
}
|
1293 |
+
|
1294 |
+
/**
|
1295 |
+
* Get Debug
|
1296 |
+
* @since 1.0
|
1297 |
+
* @version 1.0
|
1298 |
+
*/
|
1299 |
+
public function get_debug() {
|
1300 |
+
|
1301 |
+
?>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1302 |
<h2><?php echo 'Debug'; ?></h2>
|
1303 |
<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>
|
1304 |
<table id="gateway-debug">
|
1305 |
+
<thead>
|
1306 |
+
<tr>
|
1307 |
+
<th id="gateway-col-section" class="col-section"><?php echo 'Section'; ?></th>
|
1308 |
+
<th id="gateway-col-result" class="col-result"><?php echo 'Result'; ?></th>
|
1309 |
+
</tr>
|
1310 |
+
</thead>
|
1311 |
+
<tbody>
|
1312 |
+
<tr>
|
1313 |
+
<td class="col-section"><?php echo 'Payment Status'; ?></td>
|
1314 |
+
<td class="col-result"><pre><?php print_r( $this->status ); ?></pre></td>
|
1315 |
+
</tr>
|
1316 |
+
<tr>
|
1317 |
+
<td class="col-section"><?php echo 'Request'; ?></td>
|
1318 |
+
<td class="col-result"><pre><?php print_r( $this->request ); ?></pre></td>
|
1319 |
+
</tr>
|
1320 |
+
<tr>
|
1321 |
+
<td class="col-section"><?php echo 'Gateway Response'; ?></td>
|
1322 |
+
<td class="col-result"><pre><?php print_r( $this->response ); ?></pre></td>
|
1323 |
+
</tr>
|
1324 |
+
</tbody>
|
1325 |
</table>
|
1326 |
+
<?php
|
1327 |
+
|
1328 |
+
}
|
1329 |
+
|
1330 |
+
/**
|
1331 |
+
* Get Errors
|
1332 |
+
* @since 1.0
|
1333 |
+
* @version 1.0
|
1334 |
+
*/
|
1335 |
+
public function get_errors() {
|
1336 |
+
|
1337 |
+
if ( empty( $this->errors ) ) return;
|
1338 |
+
|
1339 |
+
$errors = array();
|
1340 |
+
foreach ( $this->errors as $form_field => $error_message )
|
1341 |
+
$errors[] = $error_message;
|
1342 |
+
|
1343 |
+
?>
|
1344 |
+
<div class="gateway-error"><?php echo implode( '<br />', $errors ); ?></div>
|
1345 |
+
<?php
|
1346 |
+
|
1347 |
+
}
|
1348 |
+
|
1349 |
+
/**
|
1350 |
+
* Form Builder with Redirect
|
1351 |
+
* Used by gateways that redirects users to a remote processor.
|
1352 |
+
* @since 0.1
|
1353 |
+
* @version 1.0
|
1354 |
+
*/
|
1355 |
+
public function get_page_redirect( $hidden_fields = array(), $location = '' ) {
|
1356 |
+
|
1357 |
+
$id = str_replace( '-', '_', $this->id );
|
1358 |
+
|
1359 |
+
// Logo
|
1360 |
+
if ( empty( $logo_url ) )
|
1361 |
+
$logo_url = plugins_url( 'images/cred-icon32.png', myCRED_THIS );
|
1362 |
+
|
1363 |
+
// Hidden Fields
|
1364 |
+
$hidden_fields = apply_filters( "mycred_{$id}_purchase_fields", $hidden_fields, $this );
|
1365 |
+
|
1366 |
+
?>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1367 |
<div class="row">
|
1368 |
+
<div class="col-lg-12 col-md-12 col-sm-12 col-xs-12">
|
1369 |
+
<form name="mycred_<?php echo $id; ?>_request" class="form text-center" action="<?php echo $location; ?>" method="post" id="redirect-form">
|
1370 |
+
<?php foreach ( $hidden_fields as $name => $value ) echo '<input type="hidden" name="' . $name . '" value="' . $value . '" />' . "\n"; ?>
|
1371 |
+
<img src="<?php echo plugins_url( 'assets/images/loading.gif', MYCRED_PURCHASE ); ?>" alt="Loading" />
|
1372 |
+
<noscript><input type="submit" name="submit-form" value="<?php printf( __( 'Continue to %s', 'mycred' ), $this->label ); ?>" /></noscript>
|
1373 |
+
<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>
|
1374 |
+
</form>
|
1375 |
+
</div>
|
|
|
1376 |
</div>
|
1377 |
+
<script type="text/javascript"><?php if ( $this->sandbox_mode ) echo '//'; ?>setTimeout( "document.mycred_<?php echo $id; ?>_request.submit()",2000 );</script>
|
1378 |
+
<?php
|
1379 |
+
|
1380 |
+
}
|
1381 |
+
public function form_with_redirect( $hidden_fields = array(), $location = '', $logo_url = '', $custom_html = '', $sales_data = '' ) {
|
1382 |
+
$this->get_page_redirect( $hidden_fields, $location, $custom_html, $sales_data );
|
1383 |
+
}
|
1384 |
+
|
1385 |
+
/**
|
1386 |
+
* POST to data
|
1387 |
+
* @since 0.1
|
1388 |
+
* @version 1.2
|
1389 |
+
*/
|
1390 |
+
public function POST_to_data( $unset = false ) {
|
1391 |
+
|
1392 |
+
$data = array();
|
1393 |
+
foreach ( $_POST as $key => $value ) {
|
1394 |
+
$data[ $key ] = stripslashes( $value );
|
1395 |
+
}
|
1396 |
+
if ( $unset )
|
1397 |
+
unset( $_POST );
|
1398 |
+
|
1399 |
+
return $data;
|
1400 |
+
|
1401 |
+
}
|
1402 |
+
|
1403 |
+
/**
|
1404 |
+
* Transaction ID unique
|
1405 |
+
* Searches the Log for a given transaction.
|
1406 |
+
*
|
1407 |
+
* @returns (bool) true if transaction id is unique or false
|
1408 |
+
* @since 0.1
|
1409 |
+
* @version 1.0.2
|
1410 |
+
*/
|
1411 |
+
public function transaction_id_is_unique( $transaction_id = '' ) {
|
1412 |
+
|
1413 |
+
if ( empty( $transaction_id ) ) return false;
|
1414 |
+
|
1415 |
+
global $wpdb, $mycred_log_table;
|
1416 |
+
|
1417 |
+
// Make sure this is a new transaction
|
1418 |
+
$sql = "
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1419 |
SELECT *
|
1420 |
FROM {$mycred_log_table}
|
1421 |
WHERE ref = %s
|
1422 |
AND data LIKE %s
|
1423 |
AND ctype = %s;";
|
1424 |
|
1425 |
+
$gateway = str_replace( '-', '_', $this->id );
|
1426 |
+
$gateway_id = 'buy_creds_with_' . $gateway;
|
1427 |
+
|
1428 |
+
$check = $wpdb->get_results( $wpdb->prepare( $sql, $gateway_id, "%:\"" . $transaction_id . "\";%", $this->mycred_type ) );
|
1429 |
+
if ( $wpdb->num_rows > 0 ) return false;
|
1430 |
+
|
1431 |
+
return true;
|
1432 |
+
|
1433 |
+
}
|
1434 |
+
|
1435 |
+
/**
|
1436 |
+
* Create Unique Transaction ID
|
1437 |
+
* Returns a unique transaction ID that has no been used by buyCRED yet.
|
1438 |
+
* @since 1.4
|
1439 |
+
* @version 1.0.1
|
1440 |
+
*/
|
1441 |
+
public function create_unique_transaction_id() {
|
1442 |
+
|
1443 |
+
global $wpdb, $mycred_log_table;
|
1444 |
+
|
1445 |
+
do {
|
1446 |
+
|
1447 |
+
$id = strtoupper( wp_generate_password( 12, false, false ) );
|
1448 |
+
$query = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM {$mycred_log_table} WHERE ref LIKE %s AND data LIKE %s;", 'buy_creds_with_%', "%:\"" . $id . "\";%" ) );
|
1449 |
+
|
1450 |
+
} while ( ! empty( $query ) );
|
1451 |
+
|
1452 |
+
return $id;
|
1453 |
+
|
1454 |
+
}
|
1455 |
+
|
1456 |
+
/**
|
1457 |
+
* Create Token
|
1458 |
+
* Returns a wp nonce
|
1459 |
+
* @since 0.1
|
1460 |
+
* @version 1.0
|
1461 |
+
*/
|
1462 |
+
public function create_token( $user_id = NULL ) {
|
1463 |
+
|
1464 |
+
return wp_create_nonce( 'mycred-buy-' . $this->id );
|
1465 |
+
|
1466 |
+
}
|
1467 |
+
|
1468 |
+
/**
|
1469 |
+
* Verify Token
|
1470 |
+
* Based on wp_verify_nonce() this function requires the user id used when the token
|
1471 |
+
* was created as by default not logged in users would generate different tokens causing us
|
1472 |
+
* to fail.
|
1473 |
+
* @param $user_id (int) required user id
|
1474 |
+
* @param $nonce (string) required nonce to check
|
1475 |
+
* @returns true or false
|
1476 |
+
* @since 0.1
|
1477 |
+
* @version 1.0.1
|
1478 |
+
*/
|
1479 |
+
public function verify_token( $user_id, $nonce ) {
|
1480 |
+
|
1481 |
+
$uid = absint( $user_id );
|
1482 |
+
$i = wp_nonce_tick();
|
1483 |
+
|
1484 |
+
if ( substr( wp_hash( $i . 'mycred-buy-' . $this->id . $uid, 'nonce' ), -12, 10 ) == $nonce )
|
1485 |
+
return true;
|
1486 |
+
if ( substr( wp_hash( ( $i - 1 ) . 'mycred-buy-' . $this->id . $uid, 'nonce' ), -12, 10 ) === $nonce )
|
1487 |
+
return true;
|
1488 |
+
|
1489 |
+
return false;
|
1490 |
+
|
1491 |
+
}
|
1492 |
+
|
1493 |
+
/**
|
1494 |
+
* Encode Sales Data
|
1495 |
+
* @since 0.1
|
1496 |
+
* @version 1.1
|
1497 |
+
*/
|
1498 |
+
public function encode_sales_data( $data ) {
|
1499 |
+
|
1500 |
+
$protect = new myCRED_Protect();
|
1501 |
+
if ( $protect !== false )
|
1502 |
+
return $protect->do_encode( $data );
|
1503 |
+
|
1504 |
+
return $data;
|
1505 |
+
|
1506 |
+
}
|
1507 |
+
|
1508 |
+
/**
|
1509 |
+
* Decode Sales Data
|
1510 |
+
* @since 0.1
|
1511 |
+
* @version 1.1
|
1512 |
+
*/
|
1513 |
+
public function decode_sales_data( $data ) {
|
1514 |
+
|
1515 |
+
$protect = new myCRED_Protect();
|
1516 |
+
if ( $protect !== false )
|
1517 |
+
return $protect->do_decode( $data );
|
1518 |
+
|
1519 |
+
return $data;
|
1520 |
+
|
1521 |
+
}
|
1522 |
+
|
1523 |
+
/**
|
1524 |
+
* Currencies Dropdown
|
1525 |
+
* @since 0.1
|
1526 |
+
* @version 1.0.2
|
1527 |
+
*/
|
1528 |
+
public function currencies_dropdown( $name = '', $js = '' ) {
|
1529 |
+
|
1530 |
+
$currencies = array(
|
1531 |
+
'USD' => 'US Dollars',
|
1532 |
+
'AUD' => 'Australian Dollars',
|
1533 |
+
'CAD' => 'Canadian Dollars',
|
1534 |
+
'EUR' => 'Euro',
|
1535 |
+
'GBP' => 'British Pound Sterling',
|
1536 |
+
'JPY' => 'Japanese Yen',
|
1537 |
+
'NZD' => 'New Zealand Dollars',
|
1538 |
+
'CHF' => 'Swiss Francs',
|
1539 |
+
'HKD' => 'Hong Kong Dollars',
|
1540 |
+
'SGD' => 'Singapore Dollars',
|
1541 |
+
'SEK' => 'Swedish Kronor',
|
1542 |
+
'DKK' => 'Danish Kroner',
|
1543 |
+
'PLN' => 'Polish Zloty',
|
1544 |
+
'NOK' => 'Norwegian Kronor',
|
1545 |
+
'HUF' => 'Hungarian Forint',
|
1546 |
+
'CZK' => 'Check Koruna',
|
1547 |
+
'ILS' => 'Israeli Shekel',
|
1548 |
+
'MXN' => 'Mexican Peso',
|
1549 |
+
'BRL' => 'Brazilian Real',
|
1550 |
+
'MYR' => 'Malaysian Ringgits',
|
1551 |
+
'PHP' => 'Philippine Pesos',
|
1552 |
+
'RUB' => 'Russian Ruble',
|
1553 |
+
'TWD' => 'Taiwan New Dollars',
|
1554 |
+
'THB' => 'Thai Baht'
|
1555 |
+
);
|
1556 |
+
$currencies = apply_filters( 'mycred_dropdown_currencies', $currencies, $this->id );
|
1557 |
+
$currencies = apply_filters( 'mycred_dropdown_currencies_' . $this->id, $currencies );
|
1558 |
+
|
1559 |
+
if ( $js != '' )
|
1560 |
+
$js = ' data-update="' . $js . '"';
|
1561 |
+
|
1562 |
+
echo '<select name="' . $this->field_name( $name ) . '" id="' . $this->field_id( $name ) . '" class="currency form-control"' . $js . '>';
|
1563 |
+
echo '<option value="">' . __( 'Select', 'mycred' ) . '</option>';
|
1564 |
+
foreach ( $currencies as $code => $cname ) {
|
1565 |
+
echo '<option value="' . $code . '"';
|
1566 |
+
if ( isset( $this->prefs[ $name ] ) && $this->prefs[ $name ] == $code ) echo ' selected="selected"';
|
1567 |
+
echo '>' . $cname . '</option>';
|
1568 |
+
}
|
1569 |
+
echo '</select>';
|
1570 |
+
|
1571 |
+
}
|
1572 |
+
|
1573 |
+
/**
|
1574 |
+
* Item Type Dropdown
|
1575 |
+
* @since 0.1
|
1576 |
+
* @version 1.0
|
1577 |
+
*/
|
1578 |
+
public function item_types_dropdown( $name = '' ) {
|
1579 |
+
|
1580 |
+
$types = array(
|
1581 |
+
'product' => 'Product',
|
1582 |
+
'service' => 'Service',
|
1583 |
+
'donation' => 'Donation'
|
1584 |
+
);
|
1585 |
+
$types = apply_filters( 'mycred_dropdown_item_types', $types );
|
1586 |
+
|
1587 |
+
echo '<select name="' . $this->field_name( $name ) . '" id="' . $this->field_id( $name ) . '">';
|
1588 |
+
echo '<option value="">' . __( 'Select', 'mycred' ) . '</option>';
|
1589 |
+
foreach ( $types as $code => $cname ) {
|
1590 |
+
echo '<option value="' . $code . '"';
|
1591 |
+
if ( isset( $this->prefs[ $name ] ) && $this->prefs[ $name ] == $code ) echo ' selected="selected"';
|
1592 |
+
echo '>' . $cname . '</option>';
|
1593 |
+
}
|
1594 |
+
echo '</select>';
|
1595 |
+
|
1596 |
+
}
|
1597 |
+
|
1598 |
+
/**
|
1599 |
+
* Countries Dropdown Options
|
1600 |
+
* @since 0.1
|
1601 |
+
* @version 1.0
|
1602 |
+
*/
|
1603 |
+
public function list_option_countries( $selected = '' ) {
|
1604 |
+
|
1605 |
+
$countries = array (
|
1606 |
+
"US" => "UNITED STATES",
|
1607 |
+
"AF" => "AFGHANISTAN",
|
1608 |
+
"AL" => "ALBANIA",
|
1609 |
+
"DZ" => "ALGERIA",
|
1610 |
+
"AS" => "AMERICAN SAMOA",
|
1611 |
+
"AD" => "ANDORRA",
|
1612 |
+
"AO" => "ANGOLA",
|
1613 |
+
"AI" => "ANGUILLA",
|
1614 |
+
"AQ" => "ANTARCTICA",
|
1615 |
+
"AG" => "ANTIGUA AND BARBUDA",
|
1616 |
+
"AR" => "ARGENTINA",
|
1617 |
+
"AM" => "ARMENIA",
|
1618 |
+
"AW" => "ARUBA",
|
1619 |
+
"AU" => "AUSTRALIA",
|
1620 |
+
"AT" => "AUSTRIA",
|
1621 |
+
"AZ" => "AZERBAIJAN",
|
1622 |
+
"BS" => "BAHAMAS",
|
1623 |
+
"BH" => "BAHRAIN",
|
1624 |
+
"BD" => "BANGLADESH",
|
1625 |
+
"BB" => "BARBADOS",
|
1626 |
+
"BY" => "BELARUS",
|
1627 |
+
"BE" => "BELGIUM",
|
1628 |
+
"BZ" => "BELIZE",
|
1629 |
+
"BJ" => "BENIN",
|
1630 |
+
"BM" => "BERMUDA",
|
1631 |
+
"BT" => "BHUTAN",
|
1632 |
+
"BO" => "BOLIVIA",
|
1633 |
+
"BA" => "BOSNIA AND HERZEGOVINA",
|
1634 |
+
"BW" => "BOTSWANA",
|
1635 |
+
"BV" => "BOUVET ISLAND",
|
1636 |
+
"BR" => "BRAZIL",
|
1637 |
+
"IO" => "BRITISH INDIAN OCEAN TERRITORY",
|
1638 |
+
"BN" => "BRUNEI DARUSSALAM",
|
1639 |
+
"BG" => "BULGARIA",
|
1640 |
+
"BF" => "BURKINA FASO",
|
1641 |
+
"BI" => "BURUNDI",
|
1642 |
+
"KH" => "CAMBODIA",
|
1643 |
+
"CM" => "CAMEROON",
|
1644 |
+
"CA" => "CANADA",
|
1645 |
+
"CV" => "CAPE VERDE",
|
1646 |
+
"KY" => "CAYMAN ISLANDS",
|
1647 |
+
"CF" => "CENTRAL AFRICAN REPUBLIC",
|
1648 |
+
"TD" => "CHAD",
|
1649 |
+
"CL" => "CHILE",
|
1650 |
+
"CN" => "CHINA",
|
1651 |
+
"CX" => "CHRISTMAS ISLAND",
|
1652 |
+
"CC" => "COCOS (KEELING) ISLANDS",
|
1653 |
+
"CO" => "COLOMBIA",
|
1654 |
+
"KM" => "COMOROS",
|
1655 |
+
"CG" => "CONGO",
|
1656 |
+
"CD" => "CONGO, THE DEMOCRATIC REPUBLIC OF THE",
|
1657 |
+
"CK" => "COOK ISLANDS",
|
1658 |
+
"CR" => "COSTA RICA",
|
1659 |
+
"CI" => "COTE D'IVOIRE",
|
1660 |
+
"HR" => "CROATIA",
|
1661 |
+
"CU" => "CUBA",
|
1662 |
+
"CY" => "CYPRUS",
|
1663 |
+
"CZ" => "CZECH REPUBLIC",
|
1664 |
+
"DK" => "DENMARK",
|
1665 |
+
"DJ" => "DJIBOUTI",
|
1666 |
+
"DM" => "DOMINICA",
|
1667 |
+
"DO" => "DOMINICAN REPUBLIC",
|
1668 |
+
"EC" => "ECUADOR",
|
1669 |
+
"EG" => "EGYPT",
|
1670 |
+
"SV" => "EL SALVADOR",
|
1671 |
+
"GQ" => "EQUATORIAL GUINEA",
|
1672 |
+
"ER" => "ERITREA",
|
1673 |
+
"EE" => "ESTONIA",
|
1674 |
+
"ET" => "ETHIOPIA",
|
1675 |
+
"FK" => "FALKLAND ISLANDS (MALVINAS)",
|
1676 |
+
"FO" => "FAROE ISLANDS",
|
1677 |
+
"FJ" => "FIJI",
|
1678 |
+
"FI" => "FINLAND",
|
1679 |
+
"FR" => "FRANCE",
|
1680 |
+
"GF" => "FRENCH GUIANA",
|
1681 |
+
"PF" => "FRENCH POLYNESIA",
|
1682 |
+
"TF" => "FRENCH SOUTHERN TERRITORIES",
|
1683 |
+
"GA" => "GABON",
|
1684 |
+
"GM" => "GAMBIA",
|
1685 |
+
"GE" => "GEORGIA",
|
1686 |
+
"DE" => "GERMANY",
|
1687 |
+
"GH" => "GHANA",
|
1688 |
+
"GI" => "GIBRALTAR",
|
1689 |
+
"GR" => "GREECE",
|
1690 |
+
"GL" => "GREENLAND",
|
1691 |
+
"GD" => "GRENADA",
|
1692 |
+
"GP" => "GUADELOUPE",
|
1693 |
+
"GU" => "GUAM",
|
1694 |
+
"GT" => "GUATEMALA",
|
1695 |
+
"GN" => "GUINEA",
|
1696 |
+
"GW" => "GUINEA-BISSAU",
|
1697 |
+
"GY" => "GUYANA",
|
1698 |
+
"HT" => "HAITI",
|
1699 |
+
"HM" => "HEARD ISLAND AND MCDONALD ISLANDS",
|
1700 |
+
"VA" => "HOLY SEE (VATICAN CITY STATE)",
|
1701 |
+
"HN" => "HONDURAS",
|
1702 |
+
"HK" => "HONG KONG",
|
1703 |
+
"HU" => "HUNGARY",
|
1704 |
+
"IS" => "ICELAND",
|
1705 |
+
"IN" => "INDIA",
|
1706 |
+
"ID" => "INDONESIA",
|
1707 |
+
"IR" => "IRAN, ISLAMIC REPUBLIC OF",
|
1708 |
+
"IQ" => "IRAQ",
|
1709 |
+
"IE" => "IRELAND",
|
1710 |
+
"IL" => "ISRAEL",
|
1711 |
+
"IT" => "ITALY",
|
1712 |
+
"JM" => "JAMAICA",
|
1713 |
+
"JP" => "JAPAN",
|
1714 |
+
"JO" => "JORDAN",
|
1715 |
+
"KZ" => "KAZAKHSTAN",
|
1716 |
+
"KE" => "KENYA",
|
1717 |
+
"KI" => "KIRIBATI",
|
1718 |
+
"KP" => "KOREA, DEMOCRATIC PEOPLE'S REPUBLIC OF",
|
1719 |
+
"KR" => "KOREA, REPUBLIC OF",
|
1720 |
+
"KW" => "KUWAIT",
|
1721 |
+
"KG" => "KYRGYZSTAN",
|
1722 |
+
"LA" => "LAO PEOPLE'S DEMOCRATIC REPUBLIC",
|
1723 |
+
"LV" => "LATVIA",
|
1724 |
+
"LB" => "LEBANON",
|
1725 |
+
"LS" => "LESOTHO",
|
1726 |
+
"LR" => "LIBERIA",
|
1727 |
+
"LY" => "LIBYAN ARAB JAMAHIRIYA",
|
1728 |
+
"LI" => "LIECHTENSTEIN",
|
1729 |
+
"LT" => "LITHUANIA",
|
1730 |
+
"LU" => "LUXEMBOURG",
|
1731 |
+
"MO" => "MACAO",
|
1732 |
+
"MK" => "MACEDONIA, THE FORMER YUGOSLAV REPUBLIC OF",
|
1733 |
+
"MG" => "MADAGASCAR",
|
1734 |
+
"MW" => "MALAWI",
|
1735 |
+
"MY" => "MALAYSIA",
|
1736 |
+
"MV" => "MALDIVES",
|
1737 |
+
"ML" => "MALI",
|
1738 |
+
"MT" => "MALTA",
|
1739 |
+
"MH" => "MARSHALL ISLANDS",
|
1740 |
+
"MQ" => "MARTINIQUE",
|
1741 |
+
"MR" => "MAURITANIA",
|
1742 |
+
"MU" => "MAURITIUS",
|
1743 |
+
"YT" => "MAYOTTE",
|
1744 |
+
"MX" => "MEXICO",
|
1745 |
+
"FM" => "MICRONESIA, FEDERATED STATES OF",
|
1746 |
+
"MD" => "MOLDOVA, REPUBLIC OF",
|
1747 |
+
"MC" => "MONACO",
|
1748 |
+
"MN" => "MONGOLIA",
|
1749 |
+
"MS" => "MONTSERRAT",
|
1750 |
+
"MA" => "MOROCCO",
|
1751 |
+
"MZ" => "MOZAMBIQUE",
|
1752 |
+
"MM" => "MYANMAR",
|
1753 |
+
"NA" => "NAMIBIA",
|
1754 |
+
"NR" => "NAURU",
|
1755 |
+
"NP" => "NEPAL",
|
1756 |
+
"NL" => "NETHERLANDS",
|
1757 |
+
"AN" => "NETHERLANDS ANTILLES",
|
1758 |
+
"NC" => "NEW CALEDONIA",
|
1759 |
+
"NZ" => "NEW ZEALAND",
|
1760 |
+
"NI" => "NICARAGUA",
|
1761 |
+
"NE" => "NIGER",
|
1762 |
+
"NG" => "NIGERIA",
|
1763 |
+
"NU" => "NIUE",
|
1764 |
+
"NF" => "NORFOLK ISLAND",
|
1765 |
+
"MP" => "NORTHERN MARIANA ISLANDS",
|
1766 |
+
"NO" => "NORWAY",
|
1767 |
+
"OM" => "OMAN",
|
1768 |
+
"PK" => "PAKISTAN",
|
1769 |
+
"PW" => "PALAU",
|
1770 |
+
"PS" => "PALESTINIAN TERRITORY, OCCUPIED",
|
1771 |
+
"PA" => "PANAMA",
|
1772 |
+
"PG" => "PAPUA NEW GUINEA",
|
1773 |
+
"PY" => "PARAGUAY",
|
1774 |
+
"PE" => "PERU",
|
1775 |
+
"PH" => "PHILIPPINES",
|
1776 |
+
"PN" => "PITCAIRN",
|
1777 |
+
"PL" => "POLAND",
|
1778 |
+
"PT" => "PORTUGAL",
|
1779 |
+
"PR" => "PUERTO RICO",
|
1780 |
+
"QA" => "QATAR",
|
1781 |
+
"RE" => "REUNION",
|
1782 |
+
"RO" => "ROMANIA",
|
1783 |
+
"RU" => "RUSSIAN FEDERATION",
|
1784 |
+
"RW" => "RWANDA",
|
1785 |
+
"SH" => "SAINT HELENA",
|
1786 |
+
"KN" => "SAINT KITTS AND NEVIS",
|
1787 |
+
"LC" => "SAINT LUCIA",
|
1788 |
+
"PM" => "SAINT PIERRE AND MIQUELON",
|
1789 |
+
"VC" => "SAINT VINCENT AND THE GRENADINES",
|
1790 |
+
"WS" => "SAMOA",
|
1791 |
+
"SM" => "SAN MARINO",
|
1792 |
+
"ST" => "SAO TOME AND PRINCIPE",
|
1793 |
+
"SA" => "SAUDI ARABIA",
|
1794 |
+
"SN" => "SENEGAL",
|
1795 |
+
"CS" => "SERBIA AND MONTENEGRO",
|
1796 |
+
"SC" => "SEYCHELLES",
|
1797 |
+
"SL" => "SIERRA LEONE",
|
1798 |
+
"SG" => "SINGAPORE",
|
1799 |
+
"SK" => "SLOVAKIA",
|
1800 |
+
"SI" => "SLOVENIA",
|
1801 |
+
"SB" => "SOLOMON ISLANDS",
|
1802 |
+
"SO" => "SOMALIA",
|
1803 |
+
"ZA" => "SOUTH AFRICA",
|
1804 |
+
"GS" => "SOUTH GEORGIA AND THE SOUTH SANDWICH ISLANDS",
|
1805 |
+
"ES" => "SPAIN",
|
1806 |
+
"LK" => "SRI LANKA",
|
1807 |
+
"SD" => "SUDAN",
|
1808 |
+
"SR" => "SURINAME",
|
1809 |
+
"SJ" => "SVALBARD AND JAN MAYEN",
|
1810 |
+
"SZ" => "SWAZILAND",
|
1811 |
+
"SE" => "SWEDEN",
|
1812 |
+
"CH" => "SWITZERLAND",
|
1813 |
+
"SY" => "SYRIAN ARAB REPUBLIC",
|
1814 |
+
"TW" => "TAIWAN, PROVINCE OF CHINA",
|
1815 |
+
"TJ" => "TAJIKISTAN",
|
1816 |
+
"TZ" => "TANZANIA, UNITED REPUBLIC OF",
|
1817 |
+
"TH" => "THAILAND",
|
1818 |
+
"TL" => "TIMOR-LESTE",
|
1819 |
+
"TG" => "TOGO",
|
1820 |
+
"TK" => "TOKELAU",
|
1821 |
+
"TO" => "TONGA",
|
1822 |
+
"TT" => "TRINIDAD AND TOBAGO",
|
1823 |
+
"TN" => "TUNISIA",
|
1824 |
+
"TR" => "TURKEY",
|
1825 |
+
"TM" => "TURKMENISTAN",
|
1826 |
+
"TC" => "TURKS AND CAICOS ISLANDS",
|
1827 |
+
"TV" => "TUVALU",
|
1828 |
+
"UG" => "UGANDA",
|
1829 |
+
"UA" => "UKRAINE",
|
1830 |
+
"AE" => "UNITED ARAB EMIRATES",
|
1831 |
+
"GB" => "UNITED KINGDOM",
|
1832 |
+
"US" => "UNITED STATES",
|
1833 |
+
"UM" => "UNITED STATES MINOR OUTLYING ISLANDS",
|
1834 |
+
"UY" => "URUGUAY",
|
1835 |
+
"UZ" => "UZBEKISTAN",
|
1836 |
+
"VU" => "VANUATU",
|
1837 |
+
"VE" => "VENEZUELA",
|
1838 |
+
"VN" => "VIET NAM",
|
1839 |
+
"VG" => "VIRGIN ISLANDS, BRITISH",
|
1840 |
+
"VI" => "VIRGIN ISLANDS, U.S.",
|
1841 |
+
"WF" => "WALLIS AND FUTUNA",
|
1842 |
+
"EH" => "WESTERN SAHARA",
|
1843 |
+
"YE" => "YEMEN",
|
1844 |
+
"ZM" => "ZAMBIA",
|
1845 |
+
"ZW" => "ZIMBABWE"
|
1846 |
+
);
|
1847 |
+
$countries = apply_filters( 'mycred_list_option_countries', $countries );
|
1848 |
+
|
1849 |
+
foreach ( $countries as $code => $cname ) {
|
1850 |
+
echo '<option value="' . $code . '"';
|
1851 |
+
if ( $selected == $code ) echo ' selected="selected"';
|
1852 |
+
echo '>' . $cname . '</option>';
|
1853 |
+
}
|
1854 |
+
|
1855 |
+
}
|
1856 |
+
|
1857 |
+
/**
|
1858 |
+
* US States Dropdown Options
|
1859 |
+
* @since 0.1
|
1860 |
+
* @version 1.0
|
1861 |
+
*/
|
1862 |
+
public function list_option_us_states( $selected = '', $non_us = false ) {
|
1863 |
+
|
1864 |
+
$states = array (
|
1865 |
+
"AL" => "Alabama",
|
1866 |
+
"AK" => "Alaska",
|
1867 |
+
"AZ" => "Arizona",
|
1868 |
+
"AR" => "Arkansas",
|
1869 |
+
"CA" => "California",
|
1870 |
+
"CO" => "Colorado",
|
1871 |
+
"CT" => "Connecticut",
|
1872 |
+
"DC" => "D.C.",
|
1873 |
+
"DE" => "Delaware",
|
1874 |
+
"FL" => "Florida",
|
1875 |
+
"GA" => "Georgia",
|
1876 |
+
"HI" => "Hawaii",
|
1877 |
+
"ID" => "Idaho",
|
1878 |
+
"IL" => "Illinois",
|
1879 |
+
"IN" => "Indiana",
|
1880 |
+
"IA" => "Iowa",
|
1881 |
+
"KS" => "Kansas",
|
1882 |
+
"KY" => "Kentucky",
|
1883 |
+
"LA" => "Louisiana",
|
1884 |
+
"ME" => "Maine",
|
1885 |
+
"MD" => "Maryland",
|
1886 |
+
"MA" => "Massachusetts",
|
1887 |
+
"MI" => "Michigan",
|
1888 |
+
"MN" => "Minnesota",
|
1889 |
+
"MS" => "Mississippi",
|
1890 |
+
"MO" => "Missouri",
|
1891 |
+
"MT" => "Montana",
|
1892 |
+
"NE" => "Nebraska",
|
1893 |
+
"NV" => "Nevada",
|
1894 |
+
"NH" => "New Hampshire",
|
1895 |
+
"NJ" => "New Jersey",
|
1896 |
+
"NM" => "New Mexico",
|
1897 |
+
"NY" => "New York",
|
1898 |
+
"NC" => "North Carolina",
|
1899 |
+
"ND" => "North Dakota",
|
1900 |
+
"OH" => "Ohio",
|
1901 |
+
"OK" => "Oklahoma",
|
1902 |
+
"OR" => "Oregon",
|
1903 |
+
"PA" => "Pennsylvania",
|
1904 |
+
"RI" => "Rhode Island",
|
1905 |
+
"SC" => "South Carolina",
|
1906 |
+
"SD" => "South Dakota",
|
1907 |
+
"TN" => "Tennessee",
|
1908 |
+
"TX" => "Texas",
|
1909 |
+
"UT" => "Utah",
|
1910 |
+
"VT" => "Vermont",
|
1911 |
+
"VA" => "Virginia",
|
1912 |
+
"WA" => "Washington",
|
1913 |
+
"WV" => "West Virginia",
|
1914 |
+
"WI" => "Wisconsin",
|
1915 |
+
"WY" => "Wyoming"
|
1916 |
+
);
|
1917 |
+
$states = apply_filters( 'mycred_list_option_us', $states );
|
1918 |
+
|
1919 |
+
$outside = 'Outside US';
|
1920 |
+
if ( $non_us == 'top' ) echo '<option value="">' . $outside . '</option>';
|
1921 |
+
foreach ( $states as $code => $cname ) {
|
1922 |
+
echo '<option value="' . $code . '"';
|
1923 |
+
if ( $selected == $code ) echo ' selected="selected"';
|
1924 |
+
echo '>' . $cname . '</option>';
|
1925 |
+
}
|
1926 |
+
if ( $non_us == 'bottom' ) echo '<option value="">' . $outside . '</option>';
|
1927 |
+
|
1928 |
+
}
|
1929 |
+
|
1930 |
+
/**
|
1931 |
+
* Months Dropdown Options
|
1932 |
+
* @since 0.1
|
1933 |
+
* @version 1.0
|
1934 |
+
*/
|
1935 |
+
public function list_option_months( $selected = '' ) {
|
1936 |
+
|
1937 |
+
$months = array (
|
1938 |
+
"01" => __( 'January', 'mycred' ),
|
1939 |
+
"02" => __( 'February', 'mycred' ),
|
1940 |
+
"03" => __( 'March', 'mycred' ),
|
1941 |
+
"04" => __( 'April', 'mycred' ),
|
1942 |
+
"05" => __( 'May', 'mycred' ),
|
1943 |
+
"06" => __( 'June', 'mycred' ),
|
1944 |
+
"07" => __( 'July', 'mycred' ),
|
1945 |
+
"08" => __( 'August', 'mycred' ),
|
1946 |
+
"09" => __( 'September', 'mycred' ),
|
1947 |
+
"10" => __( 'October', 'mycred' ),
|
1948 |
+
"11" => __( 'November', 'mycred' ),
|
1949 |
+
"12" => __( 'December', 'mycred' )
|
1950 |
+
);
|
1951 |
+
|
1952 |
+
foreach ( $months as $number => $text ) {
|
1953 |
+
echo '<option value="' . $number . '"';
|
1954 |
+
if ( $selected == $number ) echo ' selected="selected"';
|
1955 |
+
echo '>' . $text . '</option>';
|
1956 |
+
}
|
1957 |
+
|
1958 |
+
}
|
1959 |
+
|
1960 |
+
/**
|
1961 |
+
* Years Dropdown Options
|
1962 |
+
* @since 0.1
|
1963 |
+
* @version 1.0
|
1964 |
+
*/
|
1965 |
+
public function list_option_card_years( $selected = '', $number = 16 ) {
|
1966 |
+
|
1967 |
+
$now = current_time( 'timestamp' );
|
1968 |
+
$yy = date( 'y', $now );
|
1969 |
+
$yyyy = date( 'Y', $now );
|
1970 |
+
$count = 0;
|
1971 |
+
$options = array();
|
1972 |
+
|
1973 |
+
while ( $count <= (int) $number ) {
|
1974 |
+
$count ++;
|
1975 |
+
if ( $count > 1 ) {
|
1976 |
+
$yy++;
|
1977 |
+
$yyyy++;
|
1978 |
+
}
|
1979 |
+
$options[ $yy ] = $yyyy;
|
1980 |
+
}
|
1981 |
+
|
1982 |
+
foreach ( $options as $key => $value ) {
|
1983 |
+
echo '<option value="' . $key . '"';
|
1984 |
+
if ( $selected == $key ) echo ' selected="selected"';
|
1985 |
+
echo '>' . $value . '</option>';
|
1986 |
+
}
|
1987 |
+
|
1988 |
+
}
|
1989 |
+
|
1990 |
+
/**
|
1991 |
+
* IPN - Has Required Fields
|
1992 |
+
* @since 1.4
|
1993 |
+
* @version 1.0
|
1994 |
+
*/
|
1995 |
+
public function IPN_has_required_fields( $required_fields = array(), $method = 'REQUEST' ) {
|
1996 |
+
|
1997 |
+
$missing = 0;
|
1998 |
+
foreach ( $required_fields as $field_key ) {
|
1999 |
+
if ( $method == 'POST' ) {
|
2000 |
+
if ( ! isset( $_POST[ $field_key ] ) )
|
2001 |
+
$missing ++;
|
2002 |
+
}
|
2003 |
+
elseif ( $method == 'GET' ) {
|
2004 |
+
if ( ! isset( $_GET[ $field_key ] ) )
|
2005 |
+
$missing ++;
|
2006 |
+
}
|
2007 |
+
elseif ( $method == 'REQUEST' ) {
|
2008 |
+
if ( ! isset( $_REQUEST[ $field_key ] ) )
|
2009 |
+
$missing ++;
|
2010 |
+
}
|
2011 |
+
else {
|
2012 |
+
if ( ! isset( $method[ $field_key ] ) )
|
2013 |
+
$missing ++;
|
2014 |
+
}
|
2015 |
+
}
|
2016 |
+
|
2017 |
+
if ( $missing > 0 )
|
2018 |
+
$result = false;
|
2019 |
+
else
|
2020 |
+
$result = true;
|
2021 |
+
|
2022 |
+
$result = apply_filters( 'mycred_buycred_IPN_missing', $result, $required_fields, $this->id );
|
2023 |
+
|
2024 |
+
return $result;
|
2025 |
+
|
2026 |
+
}
|
2027 |
+
|
2028 |
+
/**
|
2029 |
+
* IPN - Is Valid Call
|
2030 |
+
* @since 1.4
|
2031 |
+
* @version 1.0
|
2032 |
+
*/
|
2033 |
+
public function IPN_is_valid_call() {
|
2034 |
+
|
2035 |
+
return false;
|
2036 |
+
|
2037 |
+
}
|
2038 |
+
|
2039 |
+
/**
|
2040 |
+
* IPN - Is Valid Sale
|
2041 |
+
* @since 1.4
|
2042 |
+
* @version 1.1
|
2043 |
+
*/
|
2044 |
+
public function IPN_is_valid_sale( $sales_data_key = '', $cost_key = '', $transactionid_key = '', $method = '' ) {
|
2045 |
+
|
2046 |
+
if ( $method == 'POST' )
|
2047 |
+
$post_id = absint( $_POST[ $sales_data_key ] );
|
2048 |
+
elseif ( $method == 'GET' )
|
2049 |
+
$post_id = absint( $_GET[ $sales_data_key ] );
|
2050 |
+
else
|
2051 |
+
$post_id = absint( $_REQUEST[ $sales_data_key ] );
|
2052 |
+
|
2053 |
+
$pending_payment = $this->get_pending_payment( $post_id );
|
2054 |
+
if ( $pending_payment === false ) return false;
|
2055 |
+
|
2056 |
+
$result = true;
|
2057 |
+
|
2058 |
+
if ( $method == 'POST' )
|
2059 |
+
$price = floatval( $_POST[ $cost_key ] );
|
2060 |
+
elseif ( $method == 'GET' )
|
2061 |
+
$price = floatval( $_GET[ $cost_key ] );
|
2062 |
+
else
|
2063 |
+
$price = floatval( $_REQUEST[ $cost_key ] );
|
2064 |
+
|
2065 |
+
if ( $result === true && $pending_payment['cost'] != $price ) {
|
2066 |
+
$result = false;
|
2067 |
+
}
|
2068 |
+
|
2069 |
+
if ( $result === true && isset( $this->prefs['currency'] ) && $this->prefs['currency'] != $pending_payment['currency'] ) {
|
2070 |
+
$result = false;
|
2071 |
+
}
|
2072 |
+
|
2073 |
+
if ( $method == 'POST' )
|
2074 |
+
$transaction_id = sanitize_title( $_POST[ $transactionid_key ] );
|
2075 |
+
elseif ( $method == 'GET' )
|
2076 |
+
$transaction_id = sanitize_title( $_GET[ $transactionid_key ] );
|
2077 |
+
else
|
2078 |
+
$transaction_id = sanitize_title( $_REQUEST[ $transactionid_key ] );
|
2079 |
+
|
2080 |
+
if ( $result === true && ! $this->transaction_id_is_unique( $transaction_id ) ) {
|
2081 |
+
$result = false;
|
2082 |
+
}
|
2083 |
+
|
2084 |
+
$result = apply_filters( 'mycred_buycred_valid_sale', $result, $sales_data_key, $cost_key, $transactionid_key, $method, $this );
|
2085 |
+
|
2086 |
+
if ( $result === true )
|
2087 |
+
return $decoded_data;
|
2088 |
+
|
2089 |
+
return $result;
|
2090 |
+
|
2091 |
+
}
|
2092 |
+
|
2093 |
+
/**
|
2094 |
+
* Complete Payment
|
2095 |
+
* @since 1.4
|
2096 |
+
* @version 1.4
|
2097 |
+
*/
|
2098 |
+
public function complete_payment( $pending_payment = NULL, $transaction_id = '' ) {
|
2099 |
+
|
2100 |
+
if ( $pending_payment === NULL ) return false;
|
2101 |
+
|
2102 |
+
$reply = false;
|
2103 |
+
$mycred = mycred( $pending_payment->point_type );
|
2104 |
+
|
2105 |
+
$reference = 'buy_creds_with_' . str_replace( array( ' ', '-' ), '_', $this->id );
|
2106 |
+
$sales_data = array(
|
2107 |
+
'to' => $pending_payment->recipient_id,
|
2108 |
+
'from' => $pending_payment->buyer_id,
|
2109 |
+
'amount' => $pending_payment->amount,
|
2110 |
+
'cost' => $pending_payment->cost,
|
2111 |
+
'currency' => $pending_payment->currency,
|
2112 |
+
'ctype' => $pending_payment->point_type
|
2113 |
+
);
|
2114 |
+
$data = array( 'ref_type' => 'user', 'txn_id' => $transaction_id, 'sales_data' => implode( '|', $sales_data ) );
|
2115 |
+
|
2116 |
+
if ( ! $mycred->has_entry( $reference, $pending_payment->buyer_id, $pending_payment->recipient_id, $data, $pending_payment->point_type ) ) {
|
2117 |
+
|
2118 |
+
add_filter( 'mycred_get_email_events', array( $this, 'email_notice' ), 10, 2 );
|
2119 |
+
$reply = $mycred->add_creds(
|
2120 |
+
$reference,
|
2121 |
+
$pending_payment->recipient_id,
|
2122 |
+
$pending_payment->amount,
|
2123 |
+
$this->get_log_entry( $pending_payment->recipient_id, $pending_payment->buyer_id ),
|
2124 |
+
$pending_payment->buyer_id,
|
2125 |
+
$data,
|
2126 |
+
$pending_payment->point_type
|
2127 |
+
);
|
2128 |
+
remove_filter( 'mycred_get_email_events', array( $this, 'email_notice' ), 10, 2 );
|
2129 |
+
|
2130 |
+
}
|
2131 |
+
|
2132 |
+
return apply_filters( 'mycred_buycred_complete_payment', $reply, $transaction_id, $this );
|
2133 |
+
|
2134 |
+
}
|
2135 |
+
|
2136 |
+
/**
|
2137 |
+
* Email Notice Add-on Support
|
2138 |
+
* @since 1.5.4
|
2139 |
+
* @version 1.0
|
2140 |
+
*/
|
2141 |
+
public function email_notice( $events, $request ) {
|
2142 |
+
|
2143 |
+
if ( substr( $request['ref'], 0, 15 ) == 'buy_creds_with_' )
|
2144 |
+
$events[] = 'buy_creds|positive';
|
2145 |
+
|
2146 |
+
return $events;
|
2147 |
+
|
2148 |
+
}
|
2149 |
+
|
2150 |
+
/**
|
2151 |
+
* Trash Pending Payment
|
2152 |
+
* @since 1.5.3
|
2153 |
+
* @version 1.0.1
|
2154 |
+
*/
|
2155 |
+
public function trash_pending_payment( $payment_id ) {
|
2156 |
+
|
2157 |
+
return buycred_trash_pending_payment( $payment_id );
|
2158 |
+
|
2159 |
+
}
|
2160 |
+
|
2161 |
+
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2162 |
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 |
-
|
3 |
}
|
4 |
|
5 |
.mycred-metabox .widget-content .hook-instance:last-child .specific-hook-actions {
|
6 |
-
|
7 |
}
|
8 |
|
9 |
.mycred-metabox .widget-content .hook-instance .specific-hook-actions .mycred-add-specific-hook {
|
10 |
-
|
11 |
}
|
12 |
|
13 |
.mycred-metabox .widget-content .hook-instance:last-child .specific-hook-actions .mycred-add-specific-hook {
|
14 |
-
|
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,237 +1,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 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
dataType : "JSON",
|
22 |
-
url : buyCRED.ajaxurl,
|
23 |
-
success : function ( response ) {
|
24 |
|
25 |
-
|
26 |
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
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 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
57 |
|
58 |
-
|
|
|
59 |
|
60 |
-
|
61 |
-
buyCREDcheckout.addClass('open');
|
62 |
|
63 |
-
|
64 |
|
65 |
-
|
66 |
-
|
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 |
-
|
78 |
-
|
79 |
-
'submit', '.myCRED-buy-form', function (e) {
|
80 |
|
81 |
-
|
82 |
|
83 |
-
|
|
|
|
|
|
|
|
|
|
|
84 |
|
85 |
-
|
86 |
-
buyCREDcheckout.addClass('open');
|
87 |
|
88 |
-
|
89 |
|
90 |
-
|
91 |
-
|
92 |
-
var selects = $(this).find('select');
|
93 |
|
94 |
-
|
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 |
-
|
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 |
-
|
|
|
114 |
|
115 |
-
|
116 |
|
117 |
-
|
118 |
-
|
|
|
119 |
|
120 |
-
|
121 |
-
|
|
|
|
|
|
|
|
|
122 |
|
123 |
-
|
124 |
-
|
|
|
|
|
|
|
|
|
|
|
125 |
|
126 |
-
|
127 |
|
128 |
-
|
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 |
-
|
142 |
|
143 |
-
|
144 |
-
|
145 |
-
function () {
|
146 |
-
toggleelement.slideDown();
|
147 |
-
}
|
148 |
-
);
|
149 |
|
150 |
-
|
151 |
-
buyCREDcancel.addClass('on');
|
152 |
|
153 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
154 |
|
155 |
-
|
156 |
|
157 |
-
|
158 |
-
);
|
159 |
|
160 |
-
|
161 |
-
|
|
|
|
|
162 |
|
163 |
-
|
164 |
-
|
165 |
-
var buttonvalue = $(this).data('value');
|
166 |
|
167 |
-
|
168 |
|
169 |
-
|
170 |
-
window.location = buttonvalue;
|
171 |
-
}
|
172 |
-
else {
|
173 |
-
pageform.attr('action', buttonvalue);
|
174 |
-
pageform.submit();
|
175 |
-
}
|
176 |
|
177 |
-
|
178 |
|
179 |
-
|
180 |
|
181 |
-
|
|
|
|
|
182 |
|
183 |
-
|
184 |
-
toggleelement.prev().slideUp(
|
185 |
-
function () {
|
186 |
-
toggleelement.slideDown();
|
187 |
-
}
|
188 |
-
);
|
189 |
|
190 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
191 |
|
192 |
-
|
193 |
|
194 |
-
|
195 |
-
);
|
196 |
|
197 |
-
|
198 |
-
'click', function () {
|
199 |
|
200 |
-
|
201 |
-
|
202 |
-
|
203 |
-
|
204 |
-
$(this).val('');
|
205 |
-
}
|
206 |
-
);
|
207 |
|
208 |
-
|
209 |
-
buyCREDcheckout.removeClass('open');
|
210 |
-
buyCREDcancel.removeClass('open');
|
211 |
-
buyCREDform.attr('action', '').empty().append('<div class="loading-indicator"></div>');
|
212 |
|
213 |
-
|
214 |
-
);
|
215 |
|
216 |
-
|
217 |
-
'click', '.cancel a', function (e) {
|
218 |
|
219 |
-
|
220 |
|
221 |
-
|
222 |
-
|
|
|
|
|
|
|
223 |
|
224 |
-
|
225 |
-
|
226 |
-
|
227 |
-
|
228 |
-
var label = $('.mycred-point-type').html(value);
|
229 |
|
230 |
-
|
231 |
-
);
|
232 |
|
233 |
-
|
234 |
-
);
|
235 |
|
236 |
-
|
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 |
+
});
|
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 |
-
|
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 |
+
require_once $file;
|
51 |
|
52 |
return true;
|
53 |
}
|
addons/buy-creds/gateways/Bitpay/Client/Adapter/CurlAdapter.php
CHANGED
@@ -77,11 +77,7 @@ class CurlAdapter implements AdapterInterface
|
|
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,7 +88,7 @@ class CurlAdapter implements AdapterInterface
|
|
92 |
/**
|
93 |
* Returns an array of default curl settings to use
|
94 |
*
|
95 |
-
* @param
|
96 |
* @return array
|
97 |
*/
|
98 |
private function getCurlDefaultOptions(RequestInterface $request)
|
77 |
throw new \Bitpay\Client\ConnectionException($errorMessage);
|
78 |
}
|
79 |
|
80 |
+
/** @var ResponseInterface */
|
|
|
|
|
|
|
|
|
81 |
$response = Response::createFromRawResponse($raw);
|
82 |
|
83 |
curl_close($curl);
|
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)
|
addons/buy-creds/gateways/Bitpay/Client/Client.php
CHANGED
@@ -98,7 +98,7 @@ class Client implements ClientInterface
|
|
98 |
}
|
99 |
|
100 |
/**
|
101 |
-
* @param
|
102 |
* @return ClientInterface
|
103 |
*/
|
104 |
public function setToken(TokenInterface $token)
|
@@ -197,22 +197,20 @@ class Client implements ClientInterface
|
|
197 |
throw new \Exception('Error with request: no data returned');
|
198 |
}
|
199 |
$currencies = $body['data'];
|
200 |
-
array_walk(
|
201 |
-
$
|
202 |
-
|
203 |
-
$
|
204 |
-
|
205 |
-
|
206 |
-
|
207 |
-
|
208 |
-
|
209 |
-
|
210 |
-
|
211 |
-
|
212 |
-
|
213 |
-
|
214 |
-
}
|
215 |
-
);
|
216 |
|
217 |
return $currencies;
|
218 |
}
|
@@ -316,54 +314,48 @@ class Client implements ClientInterface
|
|
316 |
|
317 |
$payouts = array();
|
318 |
|
319 |
-
array_walk(
|
320 |
-
$
|
321 |
-
|
322 |
-
$
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
323 |
->setId($value['id'])
|
324 |
-
->
|
325 |
-
->
|
326 |
-
->setEffectiveDate($value['effectiveDate'])
|
327 |
-
->setRequestdate($value['requestDate'])
|
328 |
-
->setPricingMethod($value['pricingMethod'])
|
329 |
-
->setStatus($value['status'])
|
330 |
->setAmount($value['amount'])
|
331 |
-
->
|
332 |
-
|
333 |
-
|
334 |
-
|
335 |
-
|
336 |
-
|
337 |
-
|
338 |
-
|
339 |
-
|
340 |
-
|
341 |
-
|
342 |
-
|
343 |
-
|
344 |
-
|
345 |
-
|
346 |
-
|
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,32 +424,28 @@ class Client implements ClientInterface
|
|
432 |
->setEffectiveDate($data['effectiveDate'])
|
433 |
->setResponseToken($data['token']);
|
434 |
|
435 |
-
array_walk(
|
436 |
-
$
|
437 |
-
|
438 |
-
$
|
439 |
-
|
440 |
-
|
441 |
-
|
442 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
443 |
->setAmount($value['amount'])
|
444 |
-
->
|
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 |
-
|
455 |
-
|
456 |
-
);
|
457 |
|
458 |
-
|
459 |
-
|
460 |
-
);
|
461 |
|
462 |
return $payout;
|
463 |
}
|
@@ -482,18 +470,16 @@ class Client implements ClientInterface
|
|
482 |
|
483 |
$tokens = array();
|
484 |
|
485 |
-
array_walk(
|
486 |
-
$
|
487 |
-
|
488 |
-
|
489 |
-
|
490 |
-
$
|
491 |
-
|
492 |
-
->setToken($value);
|
493 |
|
494 |
-
|
495 |
-
|
496 |
-
);
|
497 |
|
498 |
return $tokens;
|
499 |
}
|
@@ -613,7 +599,7 @@ class Client implements ClientInterface
|
|
613 |
}
|
614 |
|
615 |
/**
|
616 |
-
* @param
|
617 |
* @return ResponseInterface
|
618 |
*/
|
619 |
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($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 |
|
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 |
->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 |
|
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 |
}
|
600 |
|
601 |
/**
|
602 |
+
* @param RequestInterface $request
|
603 |
* @return ResponseInterface
|
604 |
*/
|
605 |
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
|
46 |
* @return \Bitpay\Invoice
|
47 |
* @throws \Exception
|
48 |
*/
|
@@ -50,7 +50,7 @@ interface ClientInterface
|
|
50 |
//public function getInvoices();
|
51 |
|
52 |
/**
|
53 |
-
* @param
|
54 |
* @return InvoiceInterface
|
55 |
* @throws \Exception
|
56 |
*/
|
@@ -65,29 +65,28 @@ interface ClientInterface
|
|
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
|
77 |
* @return array
|
78 |
* @throws \Exception
|
79 |
*/
|
80 |
public function getPayouts($status = null);
|
81 |
|
82 |
/**
|
83 |
-
* @param
|
84 |
* @return \Bitpay\Payout
|
85 |
* @throws \Exception
|
86 |
*/
|
87 |
public function getPayout($payoutId);
|
88 |
|
89 |
/**
|
90 |
-
* @param
|
91 |
* @return PayoutInterface|mixed
|
92 |
* @throws \Exception
|
93 |
*/
|
@@ -100,7 +99,6 @@ interface ClientInterface
|
|
100 |
|
101 |
/**
|
102 |
* Get an array of tokens indexed by facade
|
103 |
-
*
|
104 |
* @return array
|
105 |
* @throws \Exception
|
106 |
*/
|
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 |
+
* @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 |
|
100 |
/**
|
101 |
* Get an array of tokens indexed by facade
|
|
|
102 |
* @return array
|
103 |
* @throws \Exception
|
104 |
*/
|
addons/buy-creds/gateways/Bitpay/Client/Response.php
CHANGED
@@ -52,7 +52,7 @@ class Response implements ResponseInterface
|
|
52 |
}
|
53 |
|
54 |
/**
|
55 |
-
* @param
|
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 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
->end();
|
59 |
|
60 |
return $treeBuilder;
|
@@ -76,9 +76,8 @@ class Configuration implements ConfigurationInterface
|
|
76 |
->info('Class that is used to store your keys')
|
77 |
->defaultValue('Bitpay\Storage\EncryptedFilesystemStorage')
|
78 |
->validate()
|
79 |
-
|
80 |
-
|
81 |
-
function ($value) {
|
82 |
if (!class_exists($value)) {
|
83 |
throw new \Exception(
|
84 |
sprintf(
|
@@ -99,8 +98,7 @@ class Configuration implements ConfigurationInterface
|
|
99 |
}
|
100 |
|
101 |
return $value;
|
102 |
-
}
|
103 |
-
)
|
104 |
->end();
|
105 |
|
106 |
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(function ($value) {
|
|
|
81 |
if (!class_exists($value)) {
|
82 |
throw new \Exception(
|
83 |
sprintf(
|
98 |
}
|
99 |
|
100 |
return $value;
|
101 |
+
})
|
|
|
102 |
->end();
|
103 |
|
104 |
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
|
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
|
81 |
-
* @param
|
82 |
-
* @param
|
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
|
96 |
-
* @param
|
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
|
114 |
-
* @param
|
115 |
-
* @param
|
116 |
-
* @param
|
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
|
130 |
-
* @param
|
131 |
-
* @param
|
132 |
-
* @param
|
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
|
150 |
-
* @param
|
151 |
-
* @param
|
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
|
170 |
-
* @param
|
171 |
-
* @param
|
172 |
-
* @param
|
173 |
-
* @param
|
174 |
-
* @param
|
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
|
189 |
-
* @param
|
190 |
-
* @param
|
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
|
210 |
-
* @param
|
211 |
-
* @param
|
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
|
229 |
-
* @param
|
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
|
249 |
-
* @param
|
250 |
-
* @param
|
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
|
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
|
77 |
* @return boolean
|
78 |
*/
|
79 |
public function algoSelfTest($cipher_type = MCRYPT_TRIPLEDES)
|
@@ -82,18 +82,20 @@ class McryptExtension implements CryptoInterface
|
|
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
|
91 |
-
* @param string
|
92 |
-
* @param string
|
93 |
-
* @param int
|
94 |
-
* @param string
|
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,18 +127,20 @@ class McryptExtension implements CryptoInterface
|
|
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
|
134 |
-
* @param string
|
135 |
-
* @param string
|
136 |
-
* @param int
|
137 |
-
* @param string
|
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 |
{
|
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 |
+
*
|
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 |
}
|
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 |
{
|
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
|
38 |
-
* @param
|
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
|
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
|
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
|
149 |
-
* @param
|
150 |
-
* @param
|
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
|
169 |
-
* @param
|
170 |
-
* @param
|
171 |
* @return bool
|
172 |
*/
|
173 |
final public function saveCSRtoString($csr, $out, $notext = true)
|
@@ -179,21 +179,22 @@ class OpenSSLExtension implements CryptoInterface
|
|
179 |
return openssl_csr_export($csr, $out, $notext);
|
180 |
}
|
181 |
/**
|
182 |
-
|
183 |
-
|
184 |
-
|
185 |
-
|
186 |
-
|
187 |
-
|
188 |
-
|
189 |
-
|
190 |
-
|
191 |
-
|
192 |
-
|
193 |
-
|
194 |
-
|
195 |
-
|
196 |
-
|
|
|
197 |
try {
|
198 |
if (function_exists('openssl_pkey_new')) {
|
199 |
/* Ensure the key & IV is the same for both encrypt & decrypt. */
|
@@ -220,21 +221,22 @@ class OpenSSLExtension implements CryptoInterface
|
|
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
|
229 |
-
* @param string
|
230 |
-
* @param string
|
231 |
-
* @param int
|
232 |
-
* @param string
|
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)) {
|
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 |
+
*
|
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 |
}
|
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)) {
|
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
|
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
|
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
|
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,14 +40,12 @@ class ArrayLoader extends Loader
|
|
40 |
$this->container->getExtensions()
|
41 |
)
|
42 |
);
|
43 |
-
throw new InvalidArgumentException(
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
)
|
50 |
-
);
|
51 |
}
|
52 |
}
|
53 |
|
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 |
|
addons/buy-creds/gateways/Bitpay/Invoice.php
CHANGED
@@ -666,7 +666,7 @@ class Invoice implements InvoiceInterface
|
|
666 |
}
|
667 |
|
668 |
/**
|
669 |
-
* @param
|
670 |
* @return
|
671 |
*/
|
672 |
public function getBtcPaid()
|
@@ -688,7 +688,7 @@ class Invoice implements InvoiceInterface
|
|
688 |
}
|
689 |
|
690 |
/**
|
691 |
-
* @param
|
692 |
* @return Invoice
|
693 |
*/
|
694 |
public function getRate()
|
@@ -717,7 +717,7 @@ class Invoice implements InvoiceInterface
|
|
717 |
return $this->token;
|
718 |
}
|
719 |
/**
|
720 |
-
* @param
|
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
|
250 |
*/
|
251 |
public function getItemDesc();
|
252 |
|
@@ -255,7 +255,7 @@ interface InvoiceInterface
|
|
255 |
* length is 100 characters.
|
256 |
*
|
257 |
* @deprecated
|
258 |
-
* @return
|
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
|
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
|
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
|
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
|
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
|
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
|
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
|
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
|
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
|
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
|
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
|
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
|
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
|
62 |
-
* @param
|
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,7 +8,6 @@ namespace Bitpay;
|
|
8 |
|
9 |
/**
|
10 |
* Class Payout
|
11 |
-
*
|
12 |
* @package Bitpay
|
13 |
*/
|
14 |
class Payout implements PayoutInterface
|
@@ -103,7 +102,7 @@ class Payout implements PayoutInterface
|
|
103 |
/**
|
104 |
* Set the batch ID as assigned from bitpay.
|
105 |
*
|
106 |
-
* @param
|
107 |
* @return $this
|
108 |
*/
|
109 |
public function setId($id)
|
@@ -126,7 +125,7 @@ class Payout implements PayoutInterface
|
|
126 |
/**
|
127 |
* Set Account Id - Bitpays account ID for the payout.
|
128 |
*
|
129 |
-
* @param
|
130 |
* @return $this
|
131 |
*/
|
132 |
public function setAccountId($id)
|
@@ -148,8 +147,7 @@ class Payout implements PayoutInterface
|
|
148 |
|
149 |
/**
|
150 |
* Sets the amount for this payout.
|
151 |
-
*
|
152 |
-
* @param $amount
|
153 |
* @return $this
|
154 |
*/
|
155 |
public function setAmount($amount)
|
@@ -171,8 +169,7 @@ class Payout implements PayoutInterface
|
|
171 |
|
172 |
/**
|
173 |
* Set Currency
|
174 |
-
*
|
175 |
-
* @param CurrencyInterface $currency
|
176 |
* @return $this
|
177 |
*/
|
178 |
public function setCurrency(CurrencyInterface $currency)
|
@@ -194,8 +191,7 @@ class Payout implements PayoutInterface
|
|
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,8 +213,7 @@ class Payout implements PayoutInterface
|
|
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,8 +235,7 @@ class Payout implements PayoutInterface
|
|
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,7 +278,7 @@ class Payout implements PayoutInterface
|
|
284 |
* Add Instruction of PayoutInstructionInterface type
|
285 |
* Increases $this->amount by value.
|
286 |
*
|
287 |
-
* @param
|
288 |
* @return $this
|
289 |
*/
|
290 |
public function addInstruction(PayoutInstructionInterface $instruction)
|
@@ -300,9 +294,9 @@ class Payout implements PayoutInterface
|
|
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
|
304 |
-
* @param
|
305 |
-
* @param
|
306 |
* @return $this
|
307 |
*/
|
308 |
public function updateInstruction($index, $function, $argument)
|
@@ -324,8 +318,7 @@ class Payout implements PayoutInterface
|
|
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,8 +340,7 @@ class Payout implements PayoutInterface
|
|
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,7 +362,7 @@ class Payout implements PayoutInterface
|
|
370 |
/**
|
371 |
* Set Response Token - returned by Bitpay when payout request is created
|
372 |
*
|
373 |
-
* @param
|
374 |
* @return $this
|
375 |
*/
|
376 |
public function setResponseToken($responseToken)
|
@@ -391,8 +383,7 @@ class Payout implements PayoutInterface
|
|
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,7 +406,7 @@ class Payout implements PayoutInterface
|
|
415 |
/**
|
416 |
* Set the payroll providers reference for this payout
|
417 |
*
|
418 |
-
* @param
|
419 |
* @return $this
|
420 |
*/
|
421 |
public function setReference($reference)
|
@@ -438,7 +429,7 @@ class Payout implements PayoutInterface
|
|
438 |
/**
|
439 |
* Set an email address where updates to payout status should be sent.
|
440 |
*
|
441 |
-
* @param
|
442 |
* @return $this
|
443 |
*/
|
444 |
public function setNotificationEmail($notificationEmail)
|
@@ -461,7 +452,7 @@ class Payout implements PayoutInterface
|
|
461 |
/**
|
462 |
* Set a notification url - where updated Payout objects will be sent
|
463 |
*
|
464 |
-
* @param
|
465 |
* @return $this
|
466 |
*/
|
467 |
public function setNotificationUrl($notificationUrl)
|
8 |
|
9 |
/**
|
10 |
* Class Payout
|
|
|
11 |
* @package Bitpay
|
12 |
*/
|
13 |
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 |
/**
|
126 |
* Set Account Id - Bitpays account ID for the payout.
|
127 |
*
|
128 |
+
* @param $id
|
129 |
* @return $this
|
130 |
*/
|
131 |
public function setAccountId($id)
|
147 |
|
148 |
/**
|
149 |
* Sets the amount for this payout.
|
150 |
+
* @param $amount
|
|
|
151 |
* @return $this
|
152 |
*/
|
153 |
public function setAmount($amount)
|
169 |
|
170 |
/**
|
171 |
* Set Currency
|
172 |
+
* @param CurrencyInterface $currency
|
|
|
173 |
* @return $this
|
174 |
*/
|
175 |
public function setCurrency(CurrencyInterface $currency)
|
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 |
|
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 |
|
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 |
* 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 |
* 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 |
|
319 |
/**
|
320 |
* Sets the status for the current payout request
|
321 |
+
* @param $status
|
|
|
322 |
* @return $this
|
323 |
*/
|
324 |
public function setStatus($status)
|
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 |
/**
|
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 |
|
384 |
/**
|
385 |
* Set the pricing method for this payout request
|
386 |
+
* @param $pricingMethod
|
|
|
387 |
* @return $this
|
388 |
*/
|
389 |
public function setPricingMethod($pricingMethod)
|
406 |
/**
|
407 |
* Set the payroll providers reference for this payout
|
408 |
*
|
409 |
+
* @param $reference
|
410 |
* @return $this
|
411 |
*/
|
412 |
public function setReference($reference)
|
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 |
/**
|
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)
|
addons/buy-creds/gateways/Bitpay/PayoutInstruction.php
CHANGED
@@ -8,7 +8,6 @@ namespace Bitpay;
|
|
8 |
|
9 |
/**
|
10 |
* Class PayoutInstruction
|
11 |
-
*
|
12 |
* @package Bitpay
|
13 |
*/
|
14 |
class PayoutInstruction implements PayoutInstructionInterface
|
@@ -75,7 +74,7 @@ class PayoutInstruction implements PayoutInstructionInterface
|
|
75 |
/**
|
76 |
* Set the Bitpay ID for this payout instruction
|
77 |
*
|
78 |
-
* @param
|
79 |
* @return $this
|
80 |
*/
|
81 |
public function setId($id)
|
@@ -96,8 +95,7 @@ class PayoutInstruction implements PayoutInstructionInterface
|
|
96 |
|
97 |
/**
|
98 |
* Set the employers label for this instruction.
|
99 |
-
*
|
100 |
-
* @param $label
|
101 |
* @return $this
|
102 |
*/
|
103 |
public function setLabel($label)
|
@@ -119,8 +117,7 @@ class PayoutInstruction implements PayoutInstructionInterface
|
|
119 |
|
120 |
/**
|
121 |
* Set the bitcoin address for this instruction.
|
122 |
-
*
|
123 |
-
* @param $address
|
124 |
* @return $this
|
125 |
*/
|
126 |
public function setAddress($address)
|
@@ -142,8 +139,7 @@ class PayoutInstruction implements PayoutInstructionInterface
|
|
142 |
|
143 |
/**
|
144 |
* Set the amount for this instruction.
|
145 |
-
*
|
146 |
-
* @param $amount
|
147 |
* @return $this
|
148 |
*/
|
149 |
public function setAmount($amount)
|
@@ -165,8 +161,7 @@ class PayoutInstruction implements PayoutInstructionInterface
|
|
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,8 +183,7 @@ class PayoutInstruction implements PayoutInstructionInterface
|
|
188 |
|
189 |
/**
|
190 |
* Set the status for this instruction
|
191 |
-
*
|
192 |
-
* @param $status
|
193 |
* @return $this
|
194 |
*/
|
195 |
public function setStatus($status)
|
@@ -211,8 +205,7 @@ class PayoutInstruction implements PayoutInstructionInterface
|
|
211 |
|
212 |
/**
|
213 |
* Add payout transaction to the
|
214 |
-
*
|
215 |
-
* @param PayoutTransactionInterface $transaction
|
216 |
* @return $this
|
217 |
*/
|
218 |
public function addTransaction(PayoutTransactionInterface $transaction)
|
8 |
|
9 |
/**
|
10 |
* Class PayoutInstruction
|
|
|
11 |
* @package Bitpay
|
12 |
*/
|
13 |
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 |
|
96 |
/**
|
97 |
* Set the employers label for this instruction.
|
98 |
+
* @param $label
|
|
|
99 |
* @return $this
|
100 |
*/
|
101 |
public function setLabel($label)
|
117 |
|
118 |
/**
|
119 |
* Set the bitcoin address for this instruction.
|
120 |
+
* @param $address
|
|
|
121 |
* @return $this
|
122 |
*/
|
123 |
public function setAddress($address)
|
139 |
|
140 |
/**
|
141 |
* Set the amount for this instruction.
|
142 |
+
* @param $amount
|
|
|
143 |
* @return $this
|
144 |
*/
|
145 |
public function setAmount($amount)
|
161 |
|
162 |
/**
|
163 |
* Set BTC array (available once rates are set)
|
164 |
+
* @param $btc
|
|
|
165 |
* @return $this
|
166 |
*/
|
167 |
public function setBtc($btc)
|
183 |
|
184 |
/**
|
185 |
* Set the status for this instruction
|
186 |
+
* @param $status
|
|
|
187 |
* @return $this
|
188 |
*/
|
189 |
public function setStatus($status)
|
205 |
|
206 |
/**
|
207 |
* Add payout transaction to the
|
208 |
+
* @param PayoutTransactionInterface $transaction
|
|
|
209 |
* @return $this
|
210 |
*/
|
211 |
public function addTransaction(PayoutTransactionInterface $transaction)
|
addons/buy-creds/gateways/Bitpay/PayoutInstructionInterface.php
CHANGED
@@ -8,7 +8,6 @@ namespace Bitpay;
|
|
8 |
|
9 |
/**
|
10 |
* Interface PayoutInstructionInterface
|
11 |
-
*
|
12 |
* @package Bitpay
|
13 |
*/
|
14 |
interface PayoutInstructionInterface
|
@@ -16,49 +15,42 @@ 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();
|
8 |
|
9 |
/**
|
10 |
* Interface PayoutInstructionInterface
|
|
|
11 |
* @package Bitpay
|
12 |
*/
|
13 |
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();
|
addons/buy-creds/gateways/Bitpay/PayoutInterface.php
CHANGED
@@ -8,7 +8,6 @@ namespace Bitpay;
|
|
8 |
|
9 |
/**
|
10 |
* Interface PayoutInterface
|
11 |
-
*
|
12 |
* @package Bitpay
|
13 |
*/
|
14 |
interface PayoutInterface
|
8 |
|
9 |
/**
|
10 |
* Interface PayoutInterface
|
|
|
11 |
* @package Bitpay
|
12 |
*/
|
13 |
interface PayoutInterface
|
addons/buy-creds/gateways/Bitpay/PayoutTransaction.php
CHANGED
@@ -8,7 +8,6 @@ namespace Bitpay;
|
|
8 |
|
9 |
/**
|
10 |
* Class PayoutTransaction
|
11 |
-
*
|
12 |
* @package Bitpay
|
13 |
*/
|
14 |
class PayoutTransaction implements PayoutTransactionInterface
|
@@ -38,8 +37,7 @@ 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,8 +59,7 @@ class PayoutTransaction implements PayoutTransactionInterface
|
|
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,8 +81,7 @@ class PayoutTransaction implements PayoutTransactionInterface
|
|
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)
|
8 |
|
9 |
/**
|
10 |
* Class PayoutTransaction
|
|
|
11 |
* @package Bitpay
|
12 |
*/
|
13 |
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 |
|
60 |
/**
|
61 |
* Set the amount of bitcoin paid in the paout.
|
62 |
+
* @param $amount
|
|
|
63 |
* @return $this
|
64 |
*/
|
65 |
public function setAmount($amount)
|
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)
|
addons/buy-creds/gateways/Bitpay/PayoutTransactionInterface.php
CHANGED
@@ -8,28 +8,24 @@ namespace Bitpay;
|
|
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();
|
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();
|
addons/buy-creds/gateways/Bitpay/PrivateKey.php
CHANGED
@@ -13,7 +13,7 @@ use Bitpay\Math\Math;
|
|
13 |
|
14 |
/**
|
15 |
* @package Bitcore
|
16 |
-
* @see
|
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
|
195 |
-
* @param
|
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
|
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
|
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,15 +53,13 @@ class EncryptedFilesystemStorage implements StorageInterface
|
|
53 |
{
|
54 |
$path = $key->getId();
|
55 |
$data = serialize($key);
|
56 |
-
$encoded = bin2hex(
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
)
|
64 |
-
);
|
65 |
|
66 |
file_put_contents($path, $encoded);
|
67 |
}
|
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 |
}
|
addons/buy-creds/gateways/Bitpay/Storage/MockStorage.php
CHANGED
@@ -8,7 +8,7 @@ namespace Bitpay\Storage;
|
|
8 |
|
9 |
/**
|
10 |
* @codeCoverageIgnore
|
11 |
-
* @package
|
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
|
19 |
-
* @param
|
20 |
-
* @param
|
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
|
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
|
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 |
-
|
102 |
-
|
103 |
-
|
104 |
-
|
105 |
-
|
106 |
-
|
107 |
-
|
108 |
-
|
109 |
-
|
110 |
-
|
111 |
-
|
112 |
-
|
113 |
-
|
114 |
-
|
115 |
-
|
116 |
-
|
117 |
-
|
118 |
-
|
119 |
-
|
120 |
-
|
|
|
|
|
|
|
|
|
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
|
138 |
-
* @param
|
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
|
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
|
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
|
256 |
-
* @param
|
257 |
* @return PointInterface
|
258 |
*/
|
259 |
public static function pointDouble(PointInterface $point, CurveParameterInterface $parameters = null)
|
@@ -305,16 +305,16 @@ class Util
|
|
305 |
}
|
306 |
|
307 |
/**
|
308 |
-
|
309 |
-
|
310 |
-
|
311 |
-
|
312 |
-
|
313 |
-
|
314 |
-
|
315 |
-
|
316 |
-
|
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,265 +1,237 @@
|
|
1 |
<?php
|
2 |
-
if (! defined('myCRED_VERSION') )
|
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 |
-
|
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 |
-
|
|
|
|
|
|
|
126 |
|
127 |
-
|
128 |
-
|
|
|
|
|
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 |
-
|
|
|
|
|
|
|
|
|
|
|
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 |
-
|
155 |
|
156 |
-
|
157 |
-
|
|
|
|
|
|
|
|
|
158 |
|
159 |
-
|
160 |
|
161 |
-
|
162 |
-
echo $this->checkout_cancel();
|
163 |
|
164 |
-
|
|
|
|
|
|
|
|
|
|
|
165 |
|
166 |
-
|
167 |
-
|
168 |
|
169 |
-
|
170 |
|
171 |
-
|
172 |
|
173 |
-
|
|
|
|
|
|
|
|
|
|
|
174 |
|
175 |
-
|
176 |
-
* Preferences
|
177 |
-
*
|
178 |
-
* @since 1.0
|
179 |
-
* @version 1.0
|
180 |
-
*/
|
181 |
-
public function preferences()
|
182 |
-
{
|
183 |
|
184 |
-
|
|
|
185 |
|
186 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
187 |
<div class="row">
|
188 |
-
|
189 |
-
|
190 |
-
|
191 |
-
|
192 |
-
|
193 |
-
|
194 |
-
|
195 |
-
|
196 |
-
|
197 |
-
|
198 |
-
|
199 |
-
|
200 |
-
|
201 |
-
|
202 |
-
|
203 |
-
|
204 |
-
|
205 |
-
|
206 |
-
|
207 |
-
|
208 |
-
|
209 |
-
|
210 |
-
|
211 |
-
|
212 |
</div>
|
213 |
<div class="row">
|
214 |
-
|
215 |
-
|
216 |
-
|
217 |
-
|
218 |
-
|
219 |
-
|
220 |
</div>
|
221 |
<script type="text/javascript">
|
222 |
jQuery(function($){
|
223 |
|
224 |
-
|
225 |
-
|
226 |
-
|
227 |
|
228 |
});
|
229 |
</script>
|
230 |
-
|
231 |
|
232 |
-
|
233 |
|
234 |
-
|
235 |
-
|
236 |
-
|
237 |
-
|
238 |
-
|
239 |
-
|
240 |
-
public function sanitise_preferences( $data )
|
241 |
-
{
|
242 |
|
243 |
-
|
244 |
|
245 |
-
|
246 |
-
|
247 |
-
|
248 |
-
|
249 |
|
250 |
-
|
251 |
-
|
252 |
-
|
253 |
-
|
254 |
-
|
255 |
-
|
256 |
-
|
257 |
-
|
258 |
-
$new_data['exchange'] = $data['exchange'];
|
259 |
|
260 |
-
|
261 |
|
262 |
-
|
263 |
|
264 |
-
|
265 |
endif;
|
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;
|
addons/buy-creds/gateways/bitpay.php
CHANGED
@@ -1,637 +1,606 @@
|
|
1 |
<?php
|
2 |
-
if (! defined('myCRED_VERSION') )
|
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 |
-
|
14 |
|
15 |
-
|
16 |
-
|
17 |
|
18 |
-
|
19 |
-
|
20 |
|
21 |
-
|
22 |
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
|
32 |
-
|
33 |
-
|
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 |
-
|
47 |
-
{
|
48 |
-
|
49 |
-
/**
|
50 |
-
* Construct
|
51 |
-
*/
|
52 |
-
public function __construct( $gateway_prefs )
|
53 |
-
{
|
54 |
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
}
|
60 |
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
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 |
-
|
92 |
-
|
93 |
-
* @since 1.4
|
94 |
-
* @version 1.2
|
95 |
-
*/
|
96 |
-
public function process()
|
97 |
-
{
|
98 |
|
99 |
-
|
100 |
-
if (! empty($post) ) {
|
101 |
|
102 |
-
|
103 |
-
|
104 |
-
|
|
|
|
|
|
|
105 |
|
106 |
-
|
|
|
107 |
|
108 |
-
|
109 |
-
|
110 |
-
|
111 |
-
} else {
|
112 |
-
$network = new \Bitpay\Network\Testnet();
|
113 |
-
}
|
114 |
|
115 |
-
|
116 |
-
$curlAdapter = new \Bitpay\Client\Adapter\CurlAdapter();
|
117 |
-
$client->setAdapter($curlAdapter);
|
118 |
|
119 |
-
|
120 |
-
|
121 |
-
|
|
|
|
|
122 |
|
123 |
-
|
|
|
|
|
124 |
|
125 |
-
|
|
|
|
|
126 |
|
127 |
-
|
128 |
|
129 |
-
|
130 |
|
131 |
-
|
132 |
|
133 |
-
|
134 |
-
$pending_post_id = buycred_get_pending_payment_id($transaction_id);
|
135 |
-
$pending_payment = $this->get_pending_payment($pending_post_id);
|
136 |
|
137 |
-
|
138 |
|
139 |
-
|
140 |
-
|
141 |
-
|
142 |
-
} else {
|
143 |
-
$new_call[] = __('Failed to credit users account.', 'mycred');
|
144 |
-
}
|
145 |
|
146 |
-
|
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 |
-
|
|
|
|
|
|
|
|
|
|
|
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 |
-
|
194 |
|
195 |
-
|
196 |
-
|
|
|
|
|
|
|
|
|
197 |
|
198 |
-
|
199 |
|
200 |
-
|
201 |
-
|
202 |
|
203 |
-
|
204 |
-
$pub->setPrivateKey($key);
|
205 |
-
$pub->generate();
|
206 |
|
207 |
-
|
208 |
-
|
209 |
-
$sin->generate();
|
210 |
|
211 |
-
|
|
|
|
|
212 |
|
213 |
-
|
214 |
-
|
215 |
-
|
216 |
-
$client->setNetwork(new \Bitpay\Network\Testnet());
|
217 |
-
}
|
218 |
|
219 |
-
|
220 |
|
221 |
-
|
222 |
-
|
223 |
-
|
|
|
224 |
|
225 |
-
|
226 |
-
wp_send_json_error($e->getMessage());
|
227 |
-
}
|
228 |
|
229 |
-
|
230 |
-
|
|
|
231 |
|
232 |
-
|
|
|
|
|
233 |
|
234 |
-
|
235 |
-
|
236 |
-
'id' => (string) $sin,
|
237 |
-
'pairingCode' => $pairing_code,
|
238 |
-
'label' => $label,
|
239 |
-
)
|
240 |
-
);
|
241 |
|
242 |
-
|
243 |
|
244 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
245 |
|
246 |
-
|
247 |
|
248 |
-
|
249 |
-
$label .= ' (Testnet)';
|
250 |
-
}
|
251 |
|
252 |
-
|
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 |
-
|
266 |
-
|
267 |
-
|
268 |
-
|
269 |
-
|
270 |
-
|
271 |
-
{
|
272 |
|
273 |
-
|
274 |
-
$this->currency = ( $this->currency == '' ) ? $this->prefs['currency'] : $this->currency;
|
275 |
|
276 |
-
|
277 |
-
|
|
|
|
|
|
|
|
|
278 |
|
279 |
-
|
280 |
-
|
281 |
-
$item_name = $this->core->template_tags_general($item_name);
|
282 |
|
283 |
-
|
|
|
284 |
|
285 |
-
|
286 |
-
|
|
|
287 |
|
288 |
-
|
289 |
-
$currency = new \Bitpay\Currency($this->currency);
|
290 |
|
291 |
-
|
292 |
-
|
293 |
|
294 |
-
|
295 |
-
|
296 |
-
} else {
|
297 |
-
$client->setNetwork(new \Bitpay\Network\Testnet());
|
298 |
-
}
|
299 |
|
300 |
-
|
301 |
-
|
302 |
|
303 |
-
|
304 |
-
|
305 |
-
|
|
|
306 |
|
307 |
-
|
308 |
-
|
309 |
-
$invoice->setOrderId((string) $this->transaction_id);
|
310 |
-
$invoice->setCurrency($currency);
|
311 |
-
$invoice->setFullNotifications(( ( $this->prefs['notifications'] ) ? true : false ));
|
312 |
|
313 |
-
|
314 |
-
|
315 |
-
|
316 |
-
$item->setDescription($item_name);
|
317 |
|
318 |
-
|
319 |
-
|
320 |
-
|
|
|
|
|
321 |
|
322 |
-
|
323 |
-
|
|
|
|
|
324 |
|
325 |
-
|
326 |
-
|
327 |
-
|
328 |
-
$invoice->setTransactionSpeed($this->prefs['speed']);
|
329 |
|
330 |
-
|
331 |
-
|
332 |
|
333 |
-
|
|
|
|
|
|
|
334 |
|
335 |
-
|
|
|
336 |
|
337 |
-
|
338 |
|
339 |
-
|
340 |
|
341 |
-
|
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 |
-
|
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 |
-
|
364 |
-
|
|
|
|
|
|
|
|
|
365 |
|
366 |
-
|
|
|
|
|
|
|
|
|
|
|
367 |
|
368 |
-
|
369 |
-
|
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 |
-
|
379 |
-
echo $this->checkout_logo(false);
|
380 |
|
381 |
-
|
382 |
-
|
|
|
|
|
|
|
|
|
|
|
383 |
|
384 |
-
|
|
|
385 |
|
386 |
-
|
|
|
387 |
|
388 |
-
|
389 |
-
|
390 |
-
|
391 |
-
|
392 |
-
|
393 |
-
|
394 |
-
|
395 |
-
|
|
|
|
|
396 |
|
397 |
-
|
398 |
|
399 |
-
|
400 |
<div class="row">
|
401 |
-
|
402 |
-
|
403 |
-
|
404 |
-
|
405 |
-
|
406 |
-
|
407 |
-
|
408 |
-
|
409 |
-
|
410 |
-
|
411 |
-
|
412 |
-
|
413 |
-
|
414 |
-
|
415 |
-
|
416 |
-
|
417 |
-
|
418 |
-
|
419 |
<script type="text/javascript">
|
420 |
jQuery(function($){
|
421 |
|
422 |
-
|
423 |
|
424 |
-
|
425 |
|
426 |
-
|
427 |
|
428 |
-
|
429 |
-
|
430 |
-
|
431 |
-
|
432 |
-
|
433 |
-
|
434 |
-
|
435 |
-
|
436 |
-
|
437 |
-
|
438 |
-
|
439 |
|
440 |
-
|
441 |
|
442 |
-
|
443 |
-
|
444 |
|
445 |
-
|
446 |
|
447 |
-
|
448 |
-
|
449 |
-
|
450 |
-
|
451 |
-
|
452 |
-
|
453 |
-
|
454 |
|
455 |
-
|
456 |
-
|
457 |
|
458 |
-
|
459 |
-
|
460 |
|
461 |
-
|
462 |
|
463 |
-
|
464 |
-
|
465 |
-
|
466 |
-
|
467 |
-
|
468 |
|
469 |
-
|
470 |
|
471 |
-
|
472 |
|
473 |
-
|
474 |
-
|
475 |
-
|
476 |
|
477 |
-
|
478 |
|
479 |
});
|
480 |
</script>
|
481 |
|
482 |
-
|
483 |
-
|
484 |
-
|
485 |
-
|
486 |
-
|
487 |
-
|
488 |
-
|
489 |
-
|
490 |
-
|
491 |
-
|
492 |
-
|
493 |
-
|
494 |
<script type="text/javascript">
|
495 |
jQuery(function($){
|
496 |
|
497 |
-
|
498 |
|
499 |
-
|
500 |
|
501 |
-
|
502 |
|
503 |
-
|
504 |
-
|
505 |
|
506 |
-
|
507 |
|
508 |
-
|
509 |
|
510 |
});
|
511 |
</script>
|
512 |
|
513 |
-
|
514 |
-
|
515 |
-
|
516 |
-
|
517 |
-
|
518 |
-
|
519 |
-
|
520 |
-
|
521 |
-
|
522 |
-
|
523 |
-
|
524 |
-
|
525 |
-
|
526 |
-
|
527 |
-
|
528 |
-
|
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 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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 |
-
|
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,10 +609,10 @@ if (! function_exists('buycred_bitpay_encrypt') ) :
|
|
640 |
$openssl_ext = new \Bitpay\Crypto\OpenSSLExtension();
|
641 |
$fingerprint = sha1(sha1(__DIR__));
|
642 |
|
643 |
-
if (true === isset($fingerprint)
|
644 |
-
|
645 |
-
|
646 |
-
|
647 |
$fingerprint = substr($fingerprint, 0, 24);
|
648 |
|
649 |
if (false === isset($fingerprint) || true === empty($fingerprint)) {
|
@@ -661,18 +630,16 @@ if (! function_exists('buycred_bitpay_encrypt') ) :
|
|
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,10 +648,10 @@ if (! function_exists('buycred_bitpay_decrypt') ) :
|
|
681 |
|
682 |
$fingerprint = sha1(sha1(__DIR__));
|
683 |
|
684 |
-
if (true === isset($fingerprint)
|
685 |
-
|
686 |
-
|
687 |
-
|
688 |
$fingerprint = substr($fingerprint, 0, 24);
|
689 |
|
690 |
if (false === isset($fingerprint) || true === empty($fingerprint)) {
|
@@ -709,5 +676,5 @@ if (! function_exists('buycred_bitpay_decrypt') ) :
|
|
709 |
wp_die('Invalid server fingerprint generated');
|
710 |
}
|
711 |
|
712 |
-
|
713 |
endif;
|
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="' . esc_attr( $value ) . '" ' . selected( $prefs['speed'], $value ) . '>' . esc_html( $label ) . '</option>';
|
503 |
+
}
|
504 |
+
|
505 |
+
?>
|
506 |
+
|
507 |
+
</select>
|
508 |
+
</div>
|
509 |
+
</div>
|
510 |
+
<div class="col-lg-6 col-md-6 col-sm-12 col-xs-12">
|
511 |
+
<div class="form-group">
|
512 |
+
<label for="<?php echo $this->field_id( 'notifications' ); ?>"><?php _e( 'Full Notifications', 'mycred' ); ?></label>
|
513 |
+
<select name="<?php echo $this->field_name( 'notifications' ); ?>" id="<?php echo $this->field_id( 'notifications' ); ?>" class="form-control">
|
514 |
+
<?php
|
515 |
|
516 |
+
$options = array(
|
517 |
+
0 => __( 'No', 'mycred' ),
|
518 |
+
1 => __( 'Yes', 'mycred' )
|
519 |
+
);
|
520 |
+
foreach ( $options as $value => $label ) {
|
521 |
+
echo '<option value="' . esc_attr( $value ) . '" ' . selected( $prefs['notifications'], $value ) . '>' . esc_html( $label ) . '</option>';
|
522 |
+
}
|
523 |
+
|
524 |
+
?>
|
525 |
+
|
526 |
+
</select>
|
527 |
+
</div>
|
528 |
+
</div>
|
529 |
+
</div>
|
530 |
+
</div>
|
531 |
+
<div class="col-lg-6 col-md-6 col-sm-12 col-xs-12">
|
532 |
+
<h3><?php _e( 'Setup', 'mycred' ); ?></h3>
|
533 |
+
<div class="form-group">
|
534 |
+
<label for="<?php echo $this->field_id( 'currency' ); ?>"><?php _e( 'Currency', 'mycred' ); ?></label>
|
535 |
+
<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' ); ?>" />
|
536 |
+
|
537 |
+
</div>
|
538 |
+
<div class="form-group">
|
539 |
+
<label><?php _e( 'Exchange Rates', 'mycred' ); ?></label>
|
540 |
+
|
541 |
+
<?php $this->exchange_rate_setup(); ?>
|
542 |
+
|
543 |
+
</div>
|
544 |
+
</div>
|
545 |
+
</div>
|
546 |
+
<?php
|
547 |
|
548 |
+
}
|
549 |
+
|
550 |
+
/**
|
551 |
+
* Sanatize Prefs
|
552 |
+
* @since 1.4
|
553 |
+
* @version 1.2
|
554 |
+
*/
|
555 |
+
public function sanitise_preferences( $data ) {
|
556 |
+
|
557 |
+
$new_data = array();
|
558 |
+
|
559 |
+
if ( array_key_exists( 'api_secret', $data ) ) {
|
560 |
+
$new_data['api_secret'] = sanitize_text_field( $data['api_secret'] );
|
561 |
+
$new_data['api_public'] = sanitize_text_field( $data['api_public'] );
|
562 |
+
$new_data['api_sign'] = sanitize_text_field( $data['api_sign'] );
|
563 |
+
$new_data['api_token'] = sanitize_text_field( $data['api_token'] );
|
564 |
+
$new_data['api_label'] = sanitize_text_field( $data['api_label'] );
|
565 |
+
}
|
566 |
+
else {
|
567 |
+
$new_data['api_secret'] = '';
|
568 |
+
$new_data['api_public'] = '';
|
569 |
+
$new_data['api_sign'] = '';
|
570 |
+
$new_data['api_token'] = '';
|
571 |
+
$new_data['api_label'] = '';
|
572 |
+
}
|
573 |
+
|
574 |
+
$new_data['sandbox'] = ( isset( $data['sandbox'] ) ) ? 1 : 0;
|
575 |
+
$new_data['currency'] = sanitize_text_field( $data['currency'] );
|
576 |
+
$new_data['item_name'] = sanitize_text_field( $data['item_name'] );
|
577 |
+
$new_data['logo_url'] = sanitize_text_field( $data['logo_url'] );
|
578 |
+
$new_data['speed'] = sanitize_text_field( $data['speed'] );
|
579 |
+
$new_data['notifications'] = sanitize_text_field( $data['notifications'] );
|
580 |
+
|
581 |
+
// If exchange is less then 1 we must start with a zero
|
582 |
+
if ( isset( $data['exchange'] ) ) {
|
583 |
+
foreach ( (array) $data['exchange'] as $type => $rate ) {
|
584 |
+
if ( $rate != 1 && in_array( substr( $rate, 0, 1 ), array( '.', ',' ) ) )
|
585 |
+
$data['exchange'][ $type ] = (float) '0' . $rate;
|
586 |
+
}
|
587 |
+
}
|
588 |
+
$new_data['exchange'] = $data['exchange'];
|
589 |
+
|
590 |
+
return $new_data;
|
591 |
+
|
592 |
+
}
|
593 |
+
|
594 |
+
}
|
595 |
endif;
|
596 |
|
597 |
/**
|
598 |
* Bitpay Encrypt
|
599 |
+
* @since 1.8
|
|
|
600 |
* @version 1.0
|
601 |
*/
|
602 |
+
if ( ! function_exists( 'buycred_bitpay_encrypt' ) ) :
|
603 |
+
function buycred_bitpay_encrypt( $data ) {
|
|
|
604 |
|
605 |
if (false === isset($data) || true === empty($data)) {
|
606 |
throw new \Exception('The Bitpay payment plugin was called to encrypt data but no data was passed!');
|
609 |
$openssl_ext = new \Bitpay\Crypto\OpenSSLExtension();
|
610 |
$fingerprint = sha1(sha1(__DIR__));
|
611 |
|
612 |
+
if (true === isset($fingerprint) &&
|
613 |
+
true === isset($openssl_ext) &&
|
614 |
+
strlen($fingerprint) > 24)
|
615 |
+
{
|
616 |
$fingerprint = substr($fingerprint, 0, 24);
|
617 |
|
618 |
if (false === isset($fingerprint) || true === empty($fingerprint)) {
|
630 |
wp_die('Invalid server fingerprint generated');
|
631 |
}
|
632 |
|
633 |
+
}
|
634 |
endif;
|
635 |
|
636 |
/**
|
637 |
* Bitpay Decrypt
|
638 |
+
* @since 1.8
|
|
|
639 |
* @version 1.0
|
640 |
*/
|
641 |
+
if ( ! function_exists( 'buycred_bitpay_decrypt' ) ) :
|
642 |
+
function buycred_bitpay_decrypt( $encrypted ) {
|
|
|
643 |
|
644 |
if (false === isset($encrypted) || true === empty($encrypted)) {
|
645 |
throw new \Exception('The Bitpay payment plugin was called to decrypt data but no data was passed!');
|
648 |
|
649 |
$fingerprint = sha1(sha1(__DIR__));
|
650 |
|
651 |
+
if (true === isset($fingerprint) &&
|
652 |
+
true === isset($openssl_ext) &&
|
653 |
+
strlen($fingerprint) > 24)
|
654 |
+
{
|
655 |
$fingerprint = substr($fingerprint, 0, 24);
|
656 |
|
657 |
if (false === isset($fingerprint) || true === empty($fingerprint)) {
|
676 |
wp_die('Invalid server fingerprint generated');
|
677 |
}
|
678 |
|
679 |
+
}
|
680 |
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,326 +1,297 @@
|
|
1 |
<?php
|
2 |
-
if (! defined('myCRED_VERSION') )
|
3 |
-
}
|
4 |
|
5 |
/**
|
6 |
* myCRED_NETbilling class
|
7 |
* NETbilling Payment Gateway
|
8 |
-
*
|
9 |
-
* @
|
10 |
-
* @since 0.1
|
11 |
* @version 1.3
|
12 |
*/
|
13 |
-
if (! class_exists('myCRED_NETbilling') ) :
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
-
|
94 |
-
|
95 |
-
|
96 |
-
|
97 |
-
|
98 |
-
|
99 |
-
|
100 |
-
|
101 |
-
|
102 |
-
|
103 |
-
|
104 |
-
|
105 |
-
|
106 |
-
|
107 |
-
|
108 |
-
|
109 |
-
|
110 |
-
|
111 |
-
|
112 |
-
|
113 |
-
|
114 |
-
|
115 |
-
|
116 |
-
|
117 |
-
|
118 |
-
|
119 |
-
|
120 |
-
|
121 |
-
|
122 |
-
|
123 |
-
|
124 |
-
|
125 |
-
|
126 |
-
|
127 |
-
|
128 |
-
|
129 |
-
|
130 |
-
|
131 |
-
|
132 |
-
|
133 |
-
|
134 |
-
|
135 |
-
|
136 |
-
|
137 |
-
|
138 |
-
|
139 |
-
|
140 |
-
|
141 |
-
|
142 |
-
|
143 |
-
|
144 |
-
|
145 |
-
|
146 |
-
|
147 |
-
|
148 |
-
|
149 |
-
|
150 |
-
|
151 |
-
|
152 |
-
|
153 |
-
|
154 |
-
|
155 |
-
|
156 |
-
|
157 |
-
|
158 |
-
|
159 |
-
|
160 |
-
|
161 |
-
|
162 |
-
|
163 |
-
|
164 |
-
|
165 |
-
|
166 |
-
|
167 |
-
|
168 |
-
|
169 |
-
|
170 |
-
|
171 |
-
|
172 |
-
|
173 |
-
|
174 |
-
|
175 |
-
|
176 |
-
|
177 |
-
|
178 |
-
|
179 |
-
|
180 |
-
|
181 |
-
|
182 |
-
|
183 |
-
|
184 |
-
|
185 |
-
|
186 |
-
|
187 |
-
|
188 |
-
|
189 |
-
|
190 |
-
|
191 |
-
|
192 |
-
|
193 |
-
|
194 |
-
|
195 |
-
|
196 |
-
|
197 |
-
|
198 |
-
|
199 |
-
|
200 |
-
|
201 |
-
|
202 |
-
|
203 |
-
|
204 |
-
|
205 |
-
|
206 |
-
|
207 |
-
|
208 |
-
|
209 |
-
|
210 |
-
|
211 |
-
|
212 |
-
|
213 |
-
|
214 |
-
|
215 |
-
|
216 |
-
|
217 |
-
|
218 |
-
|
219 |
-
|
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 |
-
|
246 |
-
|
247 |
-
|
248 |
-
|
249 |
-
|
250 |
-
|
251 |
-
|
252 |
-
|
253 |
-
|
254 |
-
|
255 |
-
|
256 |
-
|
257 |
-
|
258 |
-
|
259 |
-
|
260 |
-
|
261 |
-
|
262 |
-
|
263 |
-
|
264 |
-
|
265 |
-
|
266 |
-
|
267 |
-
|
268 |
-
|
269 |
-
|
270 |
-
|
271 |
-
|
272 |
-
|
273 |
-
|
274 |
-
|
275 |
-
|
276 |
-
|
277 |
-
|
278 |
-
|
279 |
-
|
280 |
-
|
281 |
-
|
282 |
-
|
283 |
-
|
284 |
-
|
285 |
-
|
286 |
-
|
287 |
</div>
|
288 |
-
|
289 |
-
|
290 |
-
|
291 |
-
|
292 |
-
|
293 |
-
|
294 |
-
|
295 |
-
|
296 |
-
|
297 |
-
|
298 |
-
|
299 |
-
|
300 |
-
|
301 |
-
|
302 |
-
|
303 |
-
|
304 |
-
|
305 |
-
|
306 |
-
|
307 |
-
|
308 |
-
|
309 |
-
|
310 |
-
|
311 |
-
|
312 |
-
|
313 |
-
|
314 |
-
|
315 |
-
|
316 |
-
|
317 |
-
|
318 |
-
|
319 |
-
|
320 |
-
|
321 |
-
|
322 |
-
|
323 |
-
}
|
324 |
-
|
325 |
-
}
|
326 |
endif;
|
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( ':', sanitize_text_field( $_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'] . sanitize_text_field( $_REQUEST['Ecom_Cost_Total'] ) . sanitize_text_field( $_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' ), absint( $_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, sanitize_title( $_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;
|
addons/buy-creds/gateways/paypal-standard.php
CHANGED
@@ -1,379 +1,349 @@
|
|
1 |
<?php
|
2 |
-
if (! defined('myCRED_VERSION') )
|
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 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
-
|
94 |
-
|
95 |
-
|
96 |
-
|
97 |
-
|
98 |
-
|
99 |
-
|
100 |
-
|
101 |
-
|
102 |
-
|
103 |
-
|
104 |
-
|
105 |
-
|
106 |
-
|
107 |
-
|
108 |
-
|
109 |
-
|
110 |
-
|
111 |
-
|
112 |
-
|
113 |
-
|
114 |
-
|
115 |
-
|
116 |
-
|
117 |
-
|
118 |
-
|
119 |
-
|
120 |
-
|
121 |
-
|
122 |
-
|
123 |
-
|
124 |
-
|
125 |
-
|
126 |
-
|
127 |
-
|
128 |
-
|
129 |
-
|
130 |
-
|
131 |
-
|
132 |
-
|
133 |
-
|
134 |
-
|
135 |
-
|
136 |
-
|
137 |
-
|
138 |
-
|
139 |
-
|
140 |
-
|
141 |
-
|
142 |
-
|
143 |
-
|
144 |
-
|
145 |
-
|
146 |
-
|
147 |
-
|
148 |
-
|
149 |
-
|
150 |
-
|
151 |
-
|
152 |
-
|
153 |
-
|
154 |
-
|
155 |
-
|
156 |
-
|
157 |
-
|
158 |
-
|
159 |
-
|
160 |
-
|
161 |
-
|
162 |
-
|
163 |
-
|
164 |
-
|
165 |
-
|
166 |
-
|
167 |
-
|
168 |
-
|
169 |
-
|
170 |
-
|
171 |
-
|
172 |
-
|
173 |
-
|
174 |
-
|
175 |
-
|
176 |
-
|
177 |
-
|
178 |
-
|
179 |
-
|
180 |
-
|
181 |
-
|
182 |
-
|
183 |
-
|
184 |
-
|
185 |
-
|
186 |
-
|
187 |
-
|
188 |
-
|
189 |
-
|
190 |
-
|
191 |
-
|
192 |
-
|
193 |
-
|
194 |
-
|
195 |
-
|
196 |
-
|
197 |
-
|
198 |
-
|
199 |
-
|
200 |
-
|
201 |
-
|
202 |
-
|
203 |
-
|
204 |
-
|
205 |
-
|
206 |
-
|
207 |
-
|
208 |
-
|
209 |
-
|
210 |
-
|
211 |
-
|
212 |
-
|
213 |
-
|
214 |
-
|
215 |
-
|
216 |
-
|
217 |
-
|
218 |
-
|
219 |
-
|
220 |
-
|
221 |
-
|
222 |
-
|
223 |
-
|
224 |
-
|
225 |
-
|
226 |
-
|
227 |
-
|
228 |
-
|
229 |
-
|
230 |
-
|
231 |
-
|
232 |
-
|
233 |
-
|
234 |
-
|
235 |
-
|
236 |
-
|
237 |
-
|
238 |
-
|
239 |
-
|
240 |
-
|
241 |
-
|
242 |
-
|
243 |
-
|
244 |
-
|
245 |
-
|
246 |
-
|
247 |
-
|
248 |
-
|
249 |
-
|
250 |
-
|
251 |
-
|
252 |
-
|
253 |
-
|
254 |
-
|
255 |
-
|
256 |
-
|
257 |
-
|
258 |
-
|
259 |
-
|
260 |
-
|
261 |
-
|
262 |
-
|
263 |
-
|
264 |
-
|
265 |
-
|
266 |
-
|
267 |
-
|
268 |
-
|
269 |
-
|
270 |
-
|
271 |
-
|
272 |
-
|
273 |
-
|
274 |
-
|
275 |
-
|
276 |
-
|
277 |
-
|
278 |
-
|
279 |
-
|
280 |
-
|
281 |
-
|
282 |
-
|
283 |
-
|
284 |
-
|
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 |
-
|
313 |
-
|
314 |
-
|
315 |
-
|
316 |
-
|
317 |
-
|
318 |
-
|
319 |
-
|
320 |
-
|
321 |
-
|
322 |
-
|
323 |
-
|
324 |
-
|
325 |
-
|
326 |
-
|
327 |
-
|
328 |
-
|
329 |
-
|
330 |
-
|
331 |
-
|
332 |
-
|
333 |
-
|
334 |
-
|
335 |
-
|
336 |
-
|
337 |
-
|
338 |
-
|
339 |
-
|
340 |
-
|
341 |
-
|
342 |
</div>
|
343 |
-
|
344 |
-
|
345 |
-
|
346 |
-
|
347 |
-
|
348 |
-
|
349 |
-
|
350 |
-
|
351 |
-
|
352 |
-
|
353 |
-
|
354 |
-
|
355 |
-
|
356 |
-
|
357 |
-
|
358 |
-
|
359 |
-
|
360 |
-
|
361 |
-
|
362 |
-
|
363 |
-
|
364 |
-
|
365 |
-
|
366 |
-
|
367 |
-
|
368 |
-
|
369 |
-
|
370 |
-
|
371 |
-
|
372 |
-
|
373 |
-
|
374 |
-
|
375 |
-
|
376 |
-
}
|
377 |
-
|
378 |
-
}
|
379 |
endif;
|
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;
|
addons/buy-creds/gateways/skrill.php
CHANGED
@@ -1,414 +1,380 @@
|
|
1 |
<?php
|
2 |
-
if (! defined('myCRED_VERSION') )
|
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 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
-
|
94 |
-
|
95 |
-
|
96 |
-
|
97 |
-
|
98 |
-
|
99 |
-
|
100 |
-
|
101 |
-
|
102 |
-
|
103 |
-
|
104 |
-
|
105 |
-
|
106 |
-
|
107 |
-
|
108 |
-
|
109 |
-
|
110 |
-
|
111 |
-
|
112 |
-
|
113 |
-
|
114 |
-
|
115 |
-
|
116 |
-
|
117 |
-
|
118 |
-
|
119 |
-
|
120 |
-
|
121 |
-
|
122 |
-
|
123 |
-
|
124 |
-
|
125 |
-
|
126 |
-
|
127 |
-
|
128 |
-
|
129 |
-
|
130 |
-
|
131 |
-
|
132 |
-
|
133 |
-
|
134 |
-
|
135 |
-
|
136 |
-
|
137 |
-
|
138 |
-
|
139 |
-
|
140 |
-
|
141 |
-
|
142 |
-
|
143 |
-
|
144 |
-
|
145 |
-
|
146 |
-
|
147 |
-
|
148 |
-
|
149 |
-
|
150 |
-
|
151 |
-
|
152 |
-
|
153 |
-
|
154 |
-
|
155 |
-
|
156 |
-
|
157 |
-
|
158 |
-
|
159 |
-
|
160 |
-
|
161 |
-
|
162 |
-
|
163 |
-
|
164 |
-
|
165 |
-
|
166 |
-
|
167 |
-
|
168 |
-
|
169 |
-
|
170 |
-
|
171 |
-
|
172 |
-
|
173 |
-
|
174 |
-
|
175 |
-
|
176 |
-
|
177 |
-
|
178 |
-
|
179 |
-
|
180 |
-
|
181 |
-
|
182 |
-
|
183 |
-
|
184 |
-
|
185 |
-
|
186 |
-
|
187 |
-
|
188 |
-
|
189 |
-
|
190 |
-
|
191 |
-
|
192 |
-
|
193 |
-
|
194 |
-
|
195 |
-
|
196 |
-
|
197 |
-
|
198 |
-
|
199 |
-
|
200 |
-
|
201 |
-
|
202 |
-
|
203 |
-
|
204 |
-
|
205 |
-
|
206 |
-
|
207 |
-
|
208 |
-
|
209 |
-
|
210 |
-
|
211 |
-
|
212 |
-
|
213 |
-
|
214 |
-
|
215 |
-
|
216 |
-
|
217 |
-
|
218 |
-
|
219 |
-
|
220 |
-
|
221 |
-
|
222 |
-
|
223 |
-
|
224 |
-
|
225 |
-
|
226 |
-
|
227 |
-
|
228 |
-
|
229 |
-
|
230 |
-
|
231 |
-
|
232 |
-
|
233 |
-
|
234 |
-
|
235 |
-
|
236 |
-
|
237 |
-
|
238 |
-
|
239 |
-
|
240 |
-
|
241 |
-
|
242 |
-
|
243 |
-
|
244 |
-
|
245 |
-
|
246 |
-
|
247 |
-
|
248 |
-
|
249 |
-
|
250 |
-
|
251 |
-
|
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 |
-
|
281 |
-
|
282 |
-
|
283 |
-
|
284 |
-
|
285 |
-
|
286 |
-
|
287 |
-
|
288 |
-
|
289 |
-
|
290 |
-
|
291 |
-
|
292 |
-
|
293 |
-
|
294 |
-
|
295 |
-
|
296 |
-
|
297 |
-
|
298 |
-
|
299 |
-
|
300 |
-
|
301 |
-
|
302 |
-
|
303 |
-
|
304 |
-
|
305 |
-
|
306 |
-
|
307 |
-
|
308 |
-
|
309 |
-
|
310 |
-
|
311 |
-
|
312 |
-
|
313 |
-
|
314 |
-
|
315 |
-
|
316 |
-
|
317 |
</div>
|
318 |
-
<h3><?php _e('Checkout Page', 'mycred'); ?></h3>
|
319 |
<div class="row">
|
320 |
-
|
321 |
-
|
322 |
-
|
323 |
-
|
324 |
-
|
325 |
-
|
326 |
-
|
327 |
-
|
328 |
-
|
329 |
-
|
330 |
-
|
331 |
-
|
332 |
</div>
|
333 |
-
|
334 |
-
|
335 |
-
|
336 |
-
|
337 |
-
|
338 |
-
|
339 |
-
|
340 |
-
|
341 |
-
|
342 |
-
|
343 |
-
|
344 |
-
|
345 |
-
|
346 |
-
|
347 |
-
|
348 |
-
|
349 |
-
|
350 |
-
|
351 |
-
|
352 |
-
|
353 |
-
|
354 |
-
|
355 |
-
|
356 |
-
|
357 |
-
|
358 |
-
|
359 |
-
|
360 |
-
|
361 |
-
|
362 |
-
|
363 |
-
|
364 |
-
|
365 |
-
|
366 |
-
|
367 |
-
|
368 |
-
|
369 |
-
|
370 |
-
|
371 |
-
|
372 |
-
|
373 |
-
|
374 |
-
|
375 |
-
|
376 |
-
|
377 |
-
|
378 |
-
|
379 |
-
|
380 |
-
|
381 |
-
|
382 |
-
|
383 |
-
|
384 |
-
|
385 |
-
|
386 |
-
|
387 |
-
|
388 |
-
|
389 |
-
|
390 |
-
|
391 |
-
|
392 |
-
|
393 |
-
|
394 |
-
|
395 |
-
|
396 |
-
|
397 |
-
|
398 |
-
|
399 |
-
|
400 |
-
|
401 |
-
|
402 |
-
|
403 |
-
|
404 |
-
|
405 |
-
|
406 |
-
|
407 |
-
|
408 |
-
|
409 |
-
return $currencies;
|
410 |
-
|
411 |
-
}
|
412 |
-
|
413 |
-
}
|
414 |
endif;
|
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 = sanitize_text_field( $_POST['merchant_id'] ) . sanitize_text_field( $_POST['transaction_id'] ) . strtoupper( md5( $this->prefs['word'] ) ) . sanitize_text_field( $_POST['mb_amount'] ) . sanitize_text_field( $_POST['mb_currency'] ) . sanitize_text_field( $_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;
|
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,222 +1,205 @@
|
|
1 |
<?php
|
2 |
-
if (! defined('MYCRED_PURCHASE') )
|
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 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
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 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
-
|
94 |
-
|
95 |
-
|
96 |
-
|
97 |
-
|
98 |
-
|
99 |
-
|
100 |
-
|
101 |
-
|
102 |
-
|
103 |
-
|
104 |
-
|
105 |
-
|
106 |
-
|
107 |
-
|
108 |
-
|
109 |
-
|
110 |
-
|
111 |
-
|
112 |
-
|
113 |
-
|
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 |
-
|
126 |
-
{
|
127 |
|
128 |
-
|
129 |
|
130 |
-
|
131 |
-
|
132 |
|
133 |
-
|
134 |
-
|
135 |
-
}
|
136 |
|
137 |
-
|
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 |
-
|
150 |
-
{
|
151 |
|
152 |
-
|
153 |
-
|
154 |
-
|
155 |
-
|
156 |
-
|
157 |
|
158 |
-
|
159 |
-
|
160 |
|
161 |
-
|
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 |
-
|
174 |
-
{
|
175 |
|
176 |
-
|
177 |
-
|
178 |
-
|
179 |
-
|
180 |
-
|
181 |
-
|
182 |
-
|
183 |
|
184 |
-
|
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 |
-
|
197 |
-
|
198 |
-
|
199 |
-
|
200 |
-
|
201 |
-
|
202 |
-
|
203 |
-
|
204 |
-
|
205 |
-
|
206 |
-
|
207 |
-
|
208 |
-
|
209 |
-
|
210 |
-
|
211 |
-
|
212 |
-
|
213 |
-
|
214 |
-
|
215 |
-
|
216 |
-
|
217 |
-
echo $output;
|
218 |
-
|
219 |
-
}
|
220 |
endif;
|
221 |
|
222 |
/**
|
@@ -224,152 +207,131 @@ endif;
|
|
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 |
-
|
233 |
-
{
|
234 |
|
235 |
-
|
236 |
-
|
237 |
-
|
238 |
-
|
239 |
|
240 |
-
|
241 |
-
|
242 |
-
}
|
243 |
|
244 |
-
|
245 |
-
|
246 |
|
247 |
-
|
248 |
-
|
249 |
|
250 |
-
|
251 |
|
252 |
-
|
253 |
-
|
254 |
-
|
255 |
|
256 |
-
|
257 |
|
258 |
-
|
259 |
-
|
260 |
|
261 |
-
|
262 |
-
|
263 |
-
}
|
264 |
|
265 |
-
|
266 |
-
|
267 |
-
|
268 |
-
}
|
269 |
|
270 |
-
|
271 |
|
272 |
-
|
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 |
-
|
287 |
-
{
|
288 |
|
289 |
-
|
290 |
|
291 |
-
|
292 |
-
|
293 |
-
|
294 |
-
}
|
295 |
|
296 |
-
|
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 |
-
|
309 |
-
{
|
310 |
|
311 |
-
|
312 |
-
|
313 |
-
|
314 |
-
}
|
315 |
|
316 |
-
|
317 |
-
|
318 |
-
}
|
319 |
|
320 |
-
|
321 |
|
322 |
-
|
323 |
|
324 |
-
|
325 |
|
326 |
-
|
327 |
-
|
328 |
|
329 |
-
|
330 |
-
|
331 |
|
332 |
-
|
333 |
-
|
334 |
-
|
335 |
-
|
336 |
-
}
|
337 |
|
338 |
-
|
339 |
|
340 |
-
|
341 |
|
342 |
-
|
343 |
-
|
344 |
-
|
345 |
-
}
|
346 |
|
347 |
-
|
348 |
|
349 |
-
|
350 |
-
|
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 |
-
|
363 |
-
}
|
364 |
|
365 |
-
|
366 |
-
|
367 |
-
|
368 |
|
369 |
-
|
370 |
-
|
371 |
-
$wpdb->prepare(
|
372 |
-
"
|
373 |
SELECT SUM( a.meta_value )
|
374 |
FROM {$posts} p
|
375 |
LEFT JOIN {$postmeta} a
|
@@ -379,480 +341,420 @@ if (! function_exists('mycred_get_users_total_purchase') ) :
|
|
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 |
-
|
387 |
-
}
|
388 |
|
389 |
-
|
390 |
|
391 |
-
|
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 |
-
|
404 |
-
{
|
405 |
|
406 |
-
|
407 |
-
}
|
408 |
|
409 |
-
|
410 |
-
|
411 |
-
|
412 |
|
413 |
-
|
414 |
-
|
415 |
-
}
|
416 |
|
417 |
-
|
418 |
|
419 |
-
|
420 |
-
|
421 |
-
|
422 |
-
|
423 |
|
424 |
-
|
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 |
-
|
437 |
-
|
438 |
-
|
439 |
-
|
440 |
-
|
441 |
-
|
442 |
-
|
443 |
-
|
444 |
-
|
445 |
-
|
446 |
-
|
447 |
-
|
448 |
-
|
449 |
-
|
450 |
-
|
451 |
-
|
452 |
-
|
453 |
-
|
454 |
-
|
455 |
-
|
456 |
-
|
457 |
-
|
458 |
-
|
459 |
-
|
460 |
-
|
461 |
-
|
462 |
-
|
463 |
-
|
464 |
-
|
465 |
-
|
466 |
-
|
467 |
-
|
468 |
-
|
469 |
-
|
470 |
-
|
471 |
-
|
472 |
-
|
473 |
-
|
474 |
-
|
475 |
-
|
476 |
-
|
477 |
-
|
478 |
-
|
479 |
-
|
480 |
-
|
481 |
-
|
482 |
-
|
483 |
-
|
484 |
-
|
485 |
-
|
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 |
-
|
503 |
-
|
504 |
-
|
505 |
-
|
506 |
-
|
507 |
-
|
508 |
-
|
509 |
-
|
510 |
-
|
511 |
-
|
512 |
-
|
513 |
-
|
514 |
-
|
515 |
-
|
516 |
-
|
517 |
-
|
518 |
-
|
519 |
-
|
520 |
-
|
521 |
-
|
522 |
-
|
523 |
-
|
524 |
-
|
525 |
-
|
526 |
-
|
527 |
-
|
528 |
-
|
529 |
-
|
530 |
-
|
531 |
-
|
532 |
-
|
533 |
-
|
534 |
-
|
535 |
-
|
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 |
-
|
553 |
-
{
|
554 |
|
555 |
-
|
556 |
-
|
557 |
|
558 |
-
|
559 |
-
|
560 |
|
561 |
-
|
562 |
-
|
563 |
-
}
|
564 |
|
565 |
-
|
566 |
|
567 |
-
|
568 |
-
|
569 |
|
570 |
-
|
571 |
|
572 |
-
|
573 |
|
574 |
-
|
575 |
-
|
576 |
-
|
577 |
-
}
|
578 |
|
579 |
-
|
580 |
-
|
581 |
-
|
582 |
-
|
583 |
-
}
|
584 |
|
585 |
-
|
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 |
-
|
598 |
-
{
|
599 |
|
600 |
-
|
601 |
-
|
602 |
-
}
|
603 |
|
604 |
-
|
605 |
-
|
606 |
|
607 |
-
|
608 |
|
609 |
-
|
610 |
-
|
611 |
-
|
612 |
|
613 |
-
|
614 |
|
615 |
-
|
616 |
|
617 |
-
|
618 |
-
|
619 |
-
}
|
620 |
|
621 |
-
|
622 |
-
|
623 |
-
}
|
624 |
|
625 |
-
|
626 |
|
627 |
-
|
628 |
|
629 |
-
|
630 |
|
631 |
-
|
632 |
|
633 |
-
|
634 |
-
|
635 |
-
|
636 |
-
|
637 |
-
}
|
638 |
|
639 |
-
|
640 |
|
641 |
-
|
642 |
|
643 |
-
|
644 |
|
645 |
-
|
646 |
|
647 |
-
|
648 |
-
|
649 |
-
}
|
650 |
|
651 |
-
|
652 |
|
653 |
-
|
654 |
|
655 |
-
|
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 |
-
|
668 |
-
{
|
669 |
|
670 |
-
|
671 |
|
672 |
-
|
673 |
-
|
674 |
-
|
675 |
-
|
676 |
-
|
677 |
-
|
678 |
|
679 |
-
|
680 |
-
|
681 |
-
|
682 |
|
683 |
-
|
684 |
|
685 |
-
|
686 |
-
|
687 |
|
688 |
-
|
689 |
|
690 |
-
|
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 |
-
|
703 |
-
{
|
704 |
|
705 |
-
|
706 |
-
|
707 |
-
}
|
708 |
|
709 |
-
|
710 |
|
711 |
-
|
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 |
-
|
724 |
-
{
|
725 |
|
726 |
-
|
727 |
-
|
728 |
-
}
|
729 |
|
730 |
-
|
731 |
-
|
732 |
-
}
|
733 |
|
734 |
-
|
735 |
-
|
736 |
|
737 |
-
|
738 |
-
|
739 |
-
}
|
740 |
|
741 |
-
|
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 |
-
|
754 |
-
{
|
755 |
|
756 |
-
|
757 |
|
758 |
-
|
759 |
-
|
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 |
-
|
773 |
-
{
|
774 |
|
775 |
-
|
776 |
|
777 |
-
|
778 |
-
|
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 |
-
|
792 |
-
{
|
793 |
|
794 |
-
|
795 |
|
796 |
-
|
797 |
-
|
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 |
-
|
811 |
-
{
|
812 |
|
813 |
-
|
814 |
|
815 |
-
|
816 |
-
|
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 |
-
|
830 |
-
{
|
831 |
|
832 |
-
|
833 |
|
834 |
-
|
835 |
-
|
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 |
-
|
849 |
-
{
|
850 |
|
851 |
-
|
852 |
|
853 |
-
|
854 |
-
|
855 |
-
}
|
856 |
|
857 |
-
|
858 |
-
endif;
|
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 = sanitize_key( $_REQUEST['mycred_call'] );
|
125 |
|
126 |
+
elseif ( isset( $_REQUEST['mycred_buy'] ) && is_user_logged_in() )
|
127 |
+
$gateway_id = sanitize_key( $_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 |
* 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 |
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( sanitize_url( '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' => sanitize_text_field( $_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( sanitize_url( '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;
|
addons/buy-creds/includes/buycred-reward-hook.php
CHANGED
@@ -1,235 +1,219 @@
|
|
1 |
<?php
|
2 |
-
if (! defined('MYCRED_PURCHASE') )
|
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 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
-
|
94 |
-
|
95 |
-
|
96 |
-
|
97 |
-
|
98 |
-
|
99 |
-
|
100 |
-
|
101 |
-
|
102 |
-
|
103 |
-
|
104 |
-
|
105 |
-
|
106 |
-
|
107 |
-
|
108 |
-
|
109 |
-
|
110 |
-
|
111 |
-
|
112 |
-
|
113 |
-
|
114 |
-
|
115 |
-
|
116 |
-
|
117 |
-
|
118 |
-
|
119 |
-
|
120 |
-
|
121 |
-
|
122 |
-
|
123 |
-
|
124 |
-
|
125 |
-
|
126 |
-
|
127 |
-
|
128 |
-
|
129 |
-
|
130 |
-
|
131 |
-
|
132 |
-
|
133 |
-
|
134 |
-
|
135 |
-
|
136 |
-
|
137 |
-
|
138 |
-
|
139 |
-
|
140 |
-
|
141 |
-
|
142 |
-
|
143 |
-
|
144 |
-
|
145 |
-
|
146 |
-
|
147 |
-
|
148 |
-
|
149 |
-
|
150 |
-
|
151 |
-
|
152 |
-
|
153 |
-
|
154 |
-
|
155 |
-
|
156 |
-
|
157 |
-
|
158 |
-
|
159 |
-
|
160 |
-
|
161 |
-
|
162 |
-
|
163 |
-
|
164 |
-
|
165 |
-
|
166 |
-
|
167 |
-
|
168 |
-
|
169 |
-
|
170 |
-
|
171 |
-
|
172 |
-
|
173 |
-
|
174 |
-
|
175 |
-
|
176 |
-
|
177 |
-
|
178 |
-
|
179 |
-
|
180 |
-
|
181 |
-
|
182 |
-
|
183 |
-
|
184 |
-
|
185 |
-
|
186 |
-
|
187 |
-
|
188 |
-
|
189 |
-
|
190 |
-
|
191 |
-
|
192 |
-
|
193 |
-
|
194 |
-
|
195 |
-
|
196 |
-
|
197 |
-
|
198 |
-
|
199 |
-
|
200 |
-
|
201 |
-
|
202 |
-
|
203 |
-
|
204 |
-
|
205 |
-
|
206 |
-
|
207 |
-
|
208 |
-
|
209 |
-
|
210 |
-
|
211 |
-
|
212 |
-
|
213 |
-
|
214 |
-
|
215 |
-
|
216 |
-
|
217 |
-
|
218 |
-
|
219 |
-
|
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;
|
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;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
addons/buy-creds/includes/buycred-reward.php
CHANGED
@@ -1,91 +1,79 @@
|
|
1 |
<?php
|
2 |
-
if (! defined('MYCRED_PURCHASE') )
|
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 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
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();
|
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();
|
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( sanitize_url('http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']) );
|
81 |
if ( is_ssl() )
|
82 |
$current_url = str_replace( 'http://', 'https://', $current_url );
|
83 |
|
@@ -222,10 +222,10 @@ if ( ! function_exists( 'mycred_render_buy_form_points' ) ) :
|
|
222 |
<input type="hidden" name="ctype" value="<?php echo esc_attr( $point_types[0][0] ); ?>" /><?php
|
223 |
}
|
224 |
|
225 |
-
if(
|
226 |
-
$e_rate=mycred_encode_values($e_rate);
|
227 |
?>
|
228 |
-
<input type="hidden" name="er_random" value="<?php echo esc_attr($e_rate); ?>" />
|
229 |
<?php } ?>
|
230 |
<div class="form-group">
|
231 |
<label class="mycred-point-type"><?php echo $point_types[0][1]; ?></label>
|
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 |
|
222 |
<input type="hidden" name="ctype" value="<?php echo esc_attr( $point_types[0][0] ); ?>" /><?php
|
223 |
}
|
224 |
|
225 |
+
if( ! empty( $e_rate ) ) {
|
226 |
+
$e_rate = mycred_encode_values( $e_rate );
|
227 |
?>
|
228 |
+
<input type="hidden" name="er_random" value="<?php echo esc_attr( $e_rate ); ?>" />
|
229 |
<?php } ?>
|
230 |
<div class="form-group">
|
231 |
<label class="mycred-point-type"><?php echo $point_types[0][1]; ?></label>
|
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,358 +1,323 @@
|
|
1 |
<?php
|
2 |
-
if (! defined('MYCRED_PURCHASE') )
|
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 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
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 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
144 |
|
145 |
-
|
146 |
-
|
147 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
148 |
|
149 |
-
|
150 |
-
|
151 |
-
|
|
|
|
|
|
|
152 |
|
153 |
-
|
154 |
-
$installed[ $id ]['custom_rate'] = false;
|
155 |
-
}
|
156 |
|
157 |
-
|
158 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
159 |
|
160 |
-
|
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 |
-
|
|
|
|
|
175 |
|
176 |
-
|
177 |
-
|
178 |
|
179 |
-
|
180 |
-
|
181 |
-
}
|
182 |
|
183 |
-
|
184 |
-
|
185 |
-
if ($this->is_active($id) ) {
|
186 |
-
$buycred_instance->active[ $id ] = $data;
|
187 |
-
}
|
188 |
-
}
|
189 |
|
190 |
-
|
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 |
-
|
202 |
-
|
203 |
-
|
|
|
|
|
|
|
|
|
204 |
|
205 |
-
|
206 |
|
207 |
-
|
208 |
-
|
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 |
-
|
|
|
216 |
|
217 |
-
|
218 |
-
|
|
|
|
|
|
|
219 |
|
220 |
-
|
221 |
-
$buycred_instance->gateway = buycred_gateway($buycred_instance->gateway_id);
|
222 |
|
223 |
-
|
224 |
-
|
|
|
|
|
|
|
|
|
|
|
225 |
|
226 |
-
|
|
|
227 |
|
228 |
-
|
229 |
-
do_action("mycred_buycred_process_{$gateway_id}", $this->gateway_prefs);
|
230 |
|
231 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
232 |
|
233 |
-
|
234 |
-
add_filter('template_include', array( $this, 'checkout_page' ),999);
|
235 |
|
236 |
-
|
|
|
237 |
|
238 |
-
|
|
|
239 |
|
240 |
-
|
241 |
-
|
242 |
-
*
|
243 |
-
* @since 1.8
|
244 |
-
* @version 1.0
|
245 |
-
*/
|
246 |
-
public function process_new_request()
|
247 |
-
{
|
248 |
|
249 |
-
|
250 |
|
251 |
-
|
252 |
-
|
253 |
-
}
|
254 |
|
255 |
-
|
256 |
|
257 |
-
|
|
|
258 |
|
259 |
-
|
260 |
|
261 |
-
|
262 |
-
$buycred_instance->gateway->ajax_buy();
|
263 |
-
}
|
264 |
|
265 |
-
|
266 |
-
|
|
|
|
|
|
|
|
|
267 |
|
268 |
-
|
269 |
-
else {
|
270 |
|
271 |
-
|
272 |
-
|
273 |
|
274 |
-
|
275 |
-
|
276 |
-
|
277 |
-
|
278 |
-
|
279 |
-
|
280 |
-
|
281 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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 |
-
|
299 |
-
|
300 |
-
|
301 |
-
|
302 |
-
|
303 |
-
public function checkout_page( $template )
|
304 |
-
{
|
305 |
|
306 |
-
|
307 |
|
308 |
-
|
309 |
|
310 |
-
|
311 |
-
|
312 |
-
|
313 |
-
|
314 |
-
}
|
315 |
|
316 |
-
|
317 |
|
318 |
-
|
319 |
|
320 |
-
|
321 |
|
322 |
-
|
323 |
-
|
324 |
-
|
325 |
-
|
326 |
-
|
327 |
-
|
328 |
-
public function enqueue_footer()
|
329 |
-
{
|
330 |
|
331 |
-
|
332 |
|
333 |
-
|
334 |
|
335 |
-
|
336 |
|
337 |
-
|
338 |
|
339 |
-
|
340 |
-
|
341 |
-
|
342 |
-
|
343 |
-
|
344 |
-
|
345 |
-
|
346 |
-
|
347 |
-
|
348 |
-
|
349 |
-
|
350 |
-
|
351 |
-
);
|
352 |
-
wp_enqueue_script('buycred-checkout');
|
353 |
|
354 |
-
|
355 |
-
|
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,1245 +334,1162 @@ if (! class_exists('myCRED_buyCRED_Module') ) :
|
|
369 |
</div>
|
370 |
</div>
|
371 |
</div>';
|
372 |
-
|
373 |
|
374 |
-
|
375 |
|
376 |
-
|
377 |
|
378 |
-
|
379 |
-
|
380 |
-
|
381 |
-
|
382 |
-
|
383 |
-
|
384 |
-
public function module_admin_init()
|
385 |
-
{
|
386 |
|
387 |
-
|
388 |
|
389 |
-
|
390 |
-
|
391 |
|
392 |
-
|
393 |
-
|
394 |
|
395 |
-
|
396 |
-
|
397 |
-
}
|
398 |
|
399 |
-
|
400 |
-
|
401 |
-
|
402 |
-
|
403 |
-
|
404 |
-
|
405 |
-
}
|
406 |
|
407 |
-
|
408 |
|
409 |
-
|
410 |
-
|
411 |
-
|
412 |
-
|
413 |
-
|
414 |
-
|
415 |
-
public function after_general_settings( $mycred = null )
|
416 |
-
{
|
417 |
|
418 |
-
|
419 |
-
|
420 |
-
|
421 |
|
422 |
-
|
423 |
|
424 |
-
|
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 |
-
|
431 |
-
|
432 |
-
|
433 |
-
|
434 |
-
|
435 |
-
|
436 |
-
|
437 |
-
|
438 |
-
|
439 |
-
|
440 |
-
|
441 |
-
|
442 |
-
|
443 |
-
|
444 |
-
|
445 |
-
|
446 |
-
|
447 |
-
|
448 |
-
|
449 |
-
|
450 |
-
|
451 |
-
|
452 |
-
|
453 |
-
|
454 |
-
|
455 |
-
|
456 |
-
|
457 |
-
|
458 |
-
|
459 |
-
|
460 |
-
|
461 |
-
|
462 |
-
|
463 |
-
|
464 |
-
|
465 |
-
|
466 |
-
|
467 |
-
|
468 |
-
|
469 |
-
|
470 |
-
|
471 |
-
|
472 |
-
|
473 |
-
|
474 |
-
|
475 |
-
|
476 |
-
|
477 |
-
|
478 |
-
|
479 |
-
|
480 |
-
|
481 |
-
|
482 |
-
|
483 |
-
|
484 |
-
|
485 |
-
|
486 |
-
|
487 |
-
|
488 |
-
|
489 |
-
|
490 |
-
|
491 |
-
|
492 |
-
|
493 |
-
|
494 |
-
|
495 |
-
|
496 |
-
|
497 |
-
|
498 |
-
|
499 |
-
|
500 |
-
|
501 |
-
|
502 |
-
|
503 |
-
|
504 |
-
|
505 |
-
|
506 |
-
|
507 |
-
|
508 |
-
|
509 |
-
|
510 |
-
|
511 |
-
|
512 |
-
|
513 |
-
|
514 |
-
|
515 |
-
|
516 |
-
|
517 |
-
|
518 |
-
|
519 |
-
|
520 |
-
|
521 |
-
|
522 |
-
|
523 |
-
|
524 |
-
|
525 |
-
|
526 |
-
|
527 |
-
|
528 |
-
|
529 |
-
|
530 |
-
|
531 |
-
|
532 |
-
|
533 |
-
|
534 |
-
|
535 |
-
|
536 |
-
|
537 |
-
|
538 |
-
|
539 |
-
|
540 |
-
|
541 |
-
|
542 |
-
|
543 |
-
|
544 |
-
|
545 |
-
|
546 |
-
|
547 |
-
|
548 |
-
|
549 |
-
|
550 |
-
|
551 |
-
|
552 |
-
|
553 |
-
|
554 |
-
|
555 |
-
|
556 |
-
|
557 |
-
|
558 |
-
|
559 |
-
|
560 |
-
|
561 |
-
|
562 |
-
|
563 |
-
|
564 |
-
|
565 |
-
|
566 |
-
|
567 |
-
|
568 |
-
|
569 |
-
|
570 |
-
|
571 |
-
|
572 |
-
|
573 |
-
|
574 |
-
|
575 |
-
|
576 |
-
|
577 |
-
|
578 |
-
|
579 |
-
|
580 |
-
|
581 |
-
|
582 |
-
|
583 |
-
|
584 |
-
|
585 |
-
|
586 |
-
|
587 |
-
|
588 |
-
|
589 |
-
|
590 |
-
|
591 |
-
|
592 |
-
|
593 |
-
|
594 |
-
|
595 |
-
|
596 |
-
|
597 |
-
|
598 |
-
|
599 |
-
|
600 |
-
|
601 |
-
|
602 |
-
|
603 |
-
|
604 |
-
|
605 |
-
|
606 |
-
|
607 |
-
|
608 |
-
|
609 |
-
|
610 |
-
|
611 |
-
|
612 |
-
|
613 |
-
|
614 |
-
|
615 |
-
|
616 |
-
|
617 |
-
|
618 |
-
|
619 |
-
|
620 |
-
|
621 |
-
|
622 |
-
|
623 |
-
|
624 |
-
|
625 |
-
|
626 |
-
|
627 |
-
|
628 |
-
|
629 |
-
|
630 |
-
</div>
|
631 |
|
632 |
</div>
|
633 |
-
|
634 |
|
635 |
-
|
636 |
-
|
637 |
|
638 |
-
|
639 |
|
640 |
-
|
641 |
-
|
642 |
-
|
643 |
-
|
644 |
-
|
645 |
-
|
646 |
-
public function sanitize_extra_settings( $new_data, $data, $core )
|
647 |
-
{
|
648 |
|
649 |
-
|
650 |
|
651 |
-
|
652 |
-
|
653 |
|
654 |
-
|
655 |
-
|
656 |
-
}
|
657 |
|
658 |
-
|
659 |
-
|
660 |
-
}
|
661 |
|
662 |
-
|
663 |
-
|
664 |
-
|
665 |
-
|
666 |
|
667 |
-
|
668 |
|
669 |
-
|
670 |
|
671 |
-
|
672 |
-
|
673 |
|
674 |
-
|
675 |
-
|
676 |
-
}
|
677 |
|
678 |
-
|
679 |
|
680 |
-
|
681 |
-
|
682 |
-
|
683 |
|
684 |
-
|
685 |
-
|
686 |
-
|
687 |
|
688 |
-
|
689 |
-
|
690 |
-
|
691 |
|
692 |
-
|
693 |
|
694 |
-
|
695 |
-
|
696 |
-
|
697 |
|
698 |
-
|
699 |
|
700 |
-
|
701 |
|
702 |
-
|
703 |
|
704 |
-
|
705 |
-
|
706 |
-
|
707 |
-
|
708 |
-
|
709 |
-
|
710 |
-
public function render_gift_tags( $content, $log )
|
711 |
-
{
|
712 |
|
713 |
-
|
714 |
-
|
715 |
-
return $this->core->template_tags_user($content, absint($log->ref_id));
|
716 |
|
717 |
-
|
718 |
|
719 |
-
|
720 |
-
|
721 |
-
|
722 |
-
|
723 |
-
|
724 |
-
|
725 |
-
public function add_to_menu()
|
726 |
-
{
|
727 |
|
728 |
-
|
729 |
-
|
730 |
-
|
731 |
-
}
|
732 |
|
733 |
-
|
734 |
-
|
735 |
|
736 |
-
|
737 |
-
|
738 |
|
739 |
-
|
740 |
|
741 |
-
|
742 |
-
|
743 |
|
744 |
-
|
745 |
-
|
746 |
-
|
747 |
-
|
748 |
-
|
749 |
-
|
750 |
-
|
751 |
-
|
752 |
|
753 |
-
|
754 |
|
755 |
-
|
756 |
|
757 |
-
|
758 |
-
|
759 |
|
760 |
-
|
761 |
|
762 |
-
|
763 |
|
764 |
-
|
765 |
|
766 |
-
|
767 |
|
768 |
-
|
769 |
-
|
770 |
-
|
771 |
-
|
772 |
-
|
773 |
-
|
774 |
-
public function settings_header()
|
775 |
-
{
|
776 |
|
777 |
-
|
778 |
-
|
779 |
-
|
780 |
|
781 |
-
|
782 |
|
783 |
-
|
784 |
-
|
785 |
-
|
786 |
-
|
787 |
-
|
788 |
-
|
789 |
-
|
790 |
-
public function admin_page()
|
791 |
-
{
|
792 |
|
793 |
-
|
794 |
-
|
795 |
-
}
|
796 |
|
797 |
-
|
798 |
|
799 |
-
|
800 |
<div class="wrap mycred-metabox" id="myCRED-wrap">
|
801 |
-
|
802 |
-
|
803 |
-
|
804 |
-
|
805 |
-
|
806 |
-
|
807 |
-
|
808 |
-
|
809 |
-
|
810 |
-
|
811 |
-
|
812 |
-
|
813 |
-
|
814 |
-
|
815 |
-
|
816 |
-
|
817 |
-
|
818 |
-
|
819 |
-
|
820 |
-
|
821 |
-
|
822 |
-
|
823 |
-
|
824 |
-
|
825 |
-
|
826 |
-
|
827 |
-
|
828 |
-
|
829 |
-
|
830 |
-
|
831 |
-
|
832 |
-
|
833 |
-
|
834 |
-
|
835 |
-
|
836 |
-
|
837 |
-
|
838 |
-
|
839 |
-
|
840 |
-
|
841 |
-
|
842 |
-
|
843 |
-
|
844 |
-
|
845 |
-
|
846 |
-
|
847 |
-
|
848 |
-
|
849 |
-
|
850 |
-
|
851 |
-
|
852 |
-
|
853 |
-
|
854 |
-
|
855 |
-
|
856 |
-
|
857 |
-
|
858 |
-
|
859 |
-
|
860 |
-
|
861 |
-
|
862 |
-
|
863 |
-
|
864 |
-
|
865 |
-
|
866 |
-
|
867 |
-
|
868 |
-
|
869 |
-
|
870 |
-
|
871 |
-
|
872 |
-
|
873 |
-
|
874 |
-
|
875 |
-
|
876 |
-
|
877 |
-
|
878 |
-
|
879 |
-
|
880 |
-
|
881 |
-
|
882 |
-
|
883 |
-
|
884 |
-
|
885 |
-
|
886 |
-
|
887 |
-
|
888 |
-
|
889 |
-
|
890 |
-
|
891 |
-
|
892 |
-
|
893 |
-
|
894 |
-
|
895 |
-
|
896 |
-
|
897 |
-
|
898 |
-
|
899 |
-
|
900 |
-
|
901 |
-
|
902 |
-
|
903 |
-
|
904 |
-
|
905 |
-
|
906 |
-
|
907 |
-
|
908 |
-
|
909 |
-
|
910 |
-
|
911 |
-
|
912 |
-
|
913 |
-
|
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 |
-
|
929 |
-
|
930 |
-
|
931 |
-
|
932 |
-
$content .= "</h4>
|
933 |
<div class='body' style='display:none; padding: 0px; border: none;'>
|
934 |
</div>";
|
935 |
|
936 |
-
|
937 |
-
|
938 |
-
|
939 |
-
|
940 |
|
941 |
-
|
942 |
|
943 |
-
|
944 |
|
945 |
-
|
946 |
|
947 |
-
|
948 |
|
949 |
-
|
950 |
|
951 |
<script type="text/javascript">
|
952 |
jQuery(function($) {
|
953 |
-
|
954 |
-
|
955 |
-
|
956 |
-
|
957 |
-
|
958 |
});
|
959 |
</script>
|
960 |
</div>
|
961 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
962 |
|
963 |
-
|
964 |
-
|
965 |
-
|
966 |
-
|
967 |
-
|
968 |
-
|
969 |
-
|
970 |
-
|
971 |
-
|
972 |
-
|
973 |
-
|
974 |
-
|
975 |
-
|
976 |
-
|
977 |
-
|
978 |
-
|
979 |
-
|
980 |
-
|
981 |
-
|
982 |
-
|
983 |
-
|
984 |
-
|
985 |
-
|
986 |
-
|
987 |
-
|
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-', '', sanitize_key( $_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 |
-
|
1087 |
|
1088 |
-
|
1089 |
|
1090 |
-
|
1091 |
-
|
1092 |
-
|
1093 |
|
1094 |
-
|
1095 |
-
|
1096 |
-
}
|
1097 |
|
1098 |
-
|
1099 |
-
|
1100 |
-
}
|
1101 |
|
1102 |
-
|
1103 |
-
|
1104 |
-
}
|
1105 |
|
1106 |
-
|
1107 |
-
|
1108 |
-
}
|
1109 |
|
1110 |
-
|
1111 |
-
|
1112 |
-
}
|
1113 |
|
1114 |
-
|
1115 |
|
1116 |
-
|
1117 |
|
1118 |
-
|
1119 |
|
1120 |
-
|
1121 |
|
1122 |
-
|
1123 |
|
1124 |
-
|
1125 |
-
|
1126 |
-
|
1127 |
-
|
1128 |
-
|
1129 |
|
1130 |
-
|
1131 |
-
|
1132 |
-
}
|
1133 |
|
1134 |
-
|
1135 |
-
|
1136 |
-
|
1137 |
-
|
1138 |
-
|
1139 |
-
|
1140 |
|
1141 |
-
|
1142 |
-
|
1143 |
-
}
|
1144 |
|
1145 |
-
|
1146 |
-
|
1147 |
-
|
1148 |
-
|
1149 |
-
|
1150 |
|
1151 |
-
|
1152 |
-
|
1153 |
|
1154 |
-
|
1155 |
-
|
1156 |
-
|
1157 |
-
|
1158 |
|
1159 |
-
|
1160 |
-
|
1161 |
|
1162 |
-
|
1163 |
-
|
1164 |
-
|
1165 |
-
|
1166 |
-
|
1167 |
-
}
|
1168 |
|
1169 |
-
|
1170 |
-
|
1171 |
-
|
1172 |
|
1173 |
-
|
1174 |
-
|
1175 |
-
|
1176 |
-
}
|
1177 |
|
1178 |
-
|
1179 |
|
1180 |
-
|
1181 |
-
|
1182 |
-
|
1183 |
|
1184 |
-
|
1185 |
-
|
1186 |
|
1187 |
-
|
1188 |
-
|
1189 |
-
}
|
1190 |
|
1191 |
-
|
1192 |
|
1193 |
-
|
1194 |
-
|
1195 |
|
1196 |
-
|
1197 |
|
1198 |
-
|
1199 |
|
1200 |
-
|
1201 |
-
|
1202 |
|
1203 |
-
|
1204 |
-
|
1205 |
|
1206 |
-
|
1207 |
|
1208 |
-
|
1209 |
-
|
1210 |
|
1211 |
-
|
1212 |
-
|
1213 |
-
|
1214 |
-
|
1215 |
-
|
1216 |
-
}
|
1217 |
|
1218 |
-
|
1219 |
|
1220 |
-
|
1221 |
-
|
1222 |
|
1223 |
-
|
1224 |
|
1225 |
-
|
1226 |
|
1227 |
-
|
1228 |
-
|
1229 |
|
1230 |
-
|
1231 |
|
1232 |
-
|
1233 |
|
1234 |
-
|
1235 |
-
|
1236 |
|
1237 |
-
|
1238 |
-
|
1239 |
-
|
1240 |
-
|
1241 |
|
1242 |
-
|
1243 |
-
|
1244 |
-
|
1245 |
-
|
1246 |
-
|
1247 |
|
1248 |
-
|
1249 |
|
1250 |
-
|
1251 |
-
|
1252 |
|
1253 |
-
|
1254 |
|
1255 |
-
|
1256 |
-
|
1257 |
|
1258 |
-
|
1259 |
|
1260 |
-
|
1261 |
|
1262 |
-
|
1263 |
|
1264 |
-
|
1265 |
-
|
1266 |
|
1267 |
-
|
1268 |
-
|
1269 |
|
1270 |
-
|
1271 |
-
|
1272 |
|
1273 |
-
|
1274 |
-
|
1275 |
-
}
|
1276 |
|
1277 |
-
|
1278 |
|
1279 |
-
|
1280 |
|
1281 |
-
|
1282 |
|
1283 |
-
|
1284 |
-
|
1285 |
|
1286 |
-
|
1287 |
|
1288 |
-
|
1289 |
|
1290 |
-
|
1291 |
|
1292 |
-
|
1293 |
|
1294 |
-
|
1295 |
|
1296 |
-
|
1297 |
|
1298 |
-
|
1299 |
|
1300 |
-
|
1301 |
-
|
1302 |
|
1303 |
-
|
1304 |
|
1305 |
-
|
1306 |
|
1307 |
-
|
1308 |
-
|
1309 |
-
|
1310 |
-
|
1311 |
|
1312 |
-
|
1313 |
|
1314 |
-
|
1315 |
|
1316 |
-
|
1317 |
|
1318 |
-
|
1319 |
</div>
|
1320 |
-
|
1321 |
|
1322 |
-
|
1323 |
|
1324 |
-
|
1325 |
-
|
1326 |
-
|
1327 |
-
|
1328 |
-
|
1329 |
-
|
1330 |
-
public function get_sales_data_from_log_data( $log_data = '' )
|
1331 |
-
{
|
1332 |
|
1333 |
-
|
1334 |
-
|
1335 |
|
1336 |
-
|
1337 |
-
|
1338 |
-
|
1339 |
-
|
1340 |
-
|
1341 |
-
|
1342 |
-
|
1343 |
-
|
1344 |
-
|
1345 |
-
|
1346 |
-
|
1347 |
-
|
1348 |
-
}
|
1349 |
-
}
|
1350 |
|
1351 |
-
|
1352 |
|
1353 |
-
|
1354 |
|
1355 |
-
|
1356 |
-
|
1357 |
-
|
1358 |
-
|
1359 |
-
|
1360 |
-
|
1361 |
-
public function exchange_rates_user_screen( $user )
|
1362 |
-
{
|
1363 |
|
1364 |
-
|
1365 |
-
|
1366 |
-
}
|
1367 |
|
1368 |
-
|
1369 |
-
|
1370 |
-
}
|
1371 |
|
1372 |
-
|
1373 |
-
|
1374 |
-
|
1375 |
-
|
1376 |
|
1377 |
-
|
1378 |
|
1379 |
-
|
1380 |
-
|
1381 |
-
}
|
1382 |
|
1383 |
-
|
1384 |
|
1385 |
-
|
1386 |
-
|
1387 |
-
}
|
1388 |
|
1389 |
-
|
1390 |
-
|
1391 |
-
}
|
1392 |
|
1393 |
-
|
1394 |
|
1395 |
-
|
1396 |
|
1397 |
-
|
1398 |
|
1399 |
-
|
1400 |
|
1401 |
-
|
1402 |
|
1403 |
-
|
1404 |
|
1405 |
-
|
1406 |
|
1407 |
-
|
1408 |
-
|
1409 |
|
1410 |
-
|
1411 |
|
1412 |
-
|
1413 |
|
1414 |
-
|
1415 |
|
1416 |
-
|
1417 |
-
|
1418 |
|
1419 |
-
|
1420 |
|
1421 |
-
|
1422 |
|
1423 |
-
|
1424 |
|
1425 |
-
|
1426 |
|
1427 |
-
|
1428 |
|
1429 |
-
|
1430 |
|
1431 |
-
|
1432 |
|
1433 |
-
|
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 |
-
|
1440 |
-
|
1441 |
-
|
1442 |
-
|
1443 |
-
|
1444 |
-
|
1445 |
-
|
1446 |
-
|
1447 |
-
|
1448 |
-
|
1449 |
-
|
1450 |
-
|
1451 |
-
|
1452 |
-
|
1453 |
-
|
1454 |
-
|
1455 |
-
|
1456 |
-
|
1457 |
-
|
1458 |
-
|
1459 |
-
|
1460 |
-
|
1461 |
-
|
1462 |
-
|
1463 |
-
|
1464 |
-
|
1465 |
-
|
1466 |
-
|
1467 |
-
|
1468 |
-
|
1469 |
-
|
1470 |
-
|
1471 |
-
|
1472 |
-
|
1473 |
-
|
1474 |
-
|
1475 |
-
|
1476 |
-
|
1477 |
-
|
1478 |
-
|
1479 |
-
|
1480 |
-
|
1481 |
-
|
1482 |
-
|
1483 |
-
|
1484 |
-
|
1485 |
-
|
1486 |
-
|
1487 |
-
|
1488 |
-
|
1489 |
-
|
1490 |
-
|
1491 |
-
|
1492 |
-
|
1493 |
-
|
1494 |
-
|
1495 |
-
|
1496 |
-
|
1497 |
-
|
1498 |
-
|
1499 |
-
|
1500 |
-
|
1501 |
-
|
1502 |
-
|
1503 |
-
|
1504 |
-
|
1505 |
-
|
1506 |
-
|
1507 |
-
|
1508 |
-
|
1509 |
-
?>
|
1510 |
</table>
|
1511 |
<hr />
|
1512 |
<script type="text/javascript">
|
1513 |
jQuery(function($) {
|
1514 |
|
1515 |
-
|
1516 |
|
1517 |
-
|
1518 |
-
|
1519 |
|
1520 |
-
|
1521 |
-
|
1522 |
|
1523 |
-
|
1524 |
|
1525 |
});
|
1526 |
</script>
|
1527 |
-
|
1528 |
|
1529 |
-
|
1530 |
|
1531 |
-
|
1532 |
-
|
1533 |
-
|
1534 |
-
|
1535 |
-
|
1536 |
-
|
1537 |
-
public function save_manual_exchange_rates( $user_id )
|
1538 |
-
{
|
1539 |
|
1540 |
-
|
1541 |
-
}
|
1542 |
|
1543 |
-
|
1544 |
|
1545 |
-
|
1546 |
|
1547 |
-
|
1548 |
-
|
1549 |
|
1550 |
-
|
1551 |
|
1552 |
-
|
1553 |
-
|
1554 |
|
1555 |
-
|
1556 |
-
}
|
1557 |
|
1558 |
-
|
1559 |
-
|
1560 |
-
}
|
1561 |
|
1562 |
-
|
1563 |
|
1564 |
-
|
1565 |
|
1566 |
-
|
1567 |
-
|
1568 |
-
|
1569 |
-
|
1570 |
-
}
|
1571 |
|
1572 |
-
|
1573 |
|
1574 |
-
|
1575 |
|
1576 |
-
|
1577 |
|
1578 |
-
|
1579 |
|
1580 |
-
|
1581 |
-
|
1582 |
-
|
1583 |
-
|
1584 |
-
|
1585 |
-
|
1586 |
-
public function hide_buycred_transactions( $query )
|
1587 |
-
{
|
1588 |
|
1589 |
-
|
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 |
-
|
1604 |
-
{
|
1605 |
|
1606 |
-
|
1607 |
-
|
1608 |
|
1609 |
-
|
1610 |
|
1611 |
-
|
1612 |
endif;
|
1613 |
-
add_filter('mycred_load_modules', 'mycred_load_buycred_core_addon', 30, 2);
|
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 |
</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> </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> </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> </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-', '', sanitize_key( $_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 );
|
addons/buy-creds/modules/buycred-module-pending.php
CHANGED
@@ -1,863 +1,786 @@
|
|
1 |
<?php
|
2 |
-
if (! defined('MYCRED_PURCHASE') )
|
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 |
-
|
13 |
-
{
|
14 |
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
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 |
-
|
44 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
45 |
|
46 |
-
|
47 |
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
*/
|
54 |
-
public function module_init()
|
55 |
-
{
|
56 |
|
57 |
-
|
|
|
58 |
|
59 |
-
|
60 |
|
61 |
-
|
|
|
|
|
|
|
|
|
|
|
62 |
|
63 |
-
|
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 |
-
|
|
|
321 |
|
322 |
-
|
323 |
|
324 |
-
|
|
|
|
|
|
|
|
|
|
|
325 |
|
326 |
-
|
327 |
|
328 |
-
|
|
|
329 |
|
330 |
-
|
331 |
-
|
332 |
-
|
333 |
-
|
334 |
-
|
335 |
-
|
336 |
-
|
337 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
338 |
|
339 |
-
|
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 |
-
|
380 |
-
$amount = mycred_get_post_meta($post_id, 'amount', true);
|
381 |
-
$mycred = mycred($type);
|
382 |
|
383 |
-
|
|
|
|
|
384 |
|
385 |
-
|
386 |
-
case 'cost';
|
387 |
|
388 |
-
|
389 |
-
$currency = mycred_get_post_meta($post_id, 'currency', true);
|
390 |
|
391 |
-
|
392 |
|
393 |
-
|
394 |
-
case 'gateway';
|
395 |
|
396 |
-
|
397 |
-
$installed = $mycred_modules['solo']['buycred']->get();
|
398 |
|
399 |
-
|
400 |
-
|
401 |
-
|
402 |
-
|
403 |
-
|
|
|
404 |
|
405 |
-
|
406 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
407 |
|
408 |
-
|
409 |
|
410 |
-
|
411 |
-
|
412 |
-
|
413 |
-
|
414 |
-
|
|
|
415 |
|
416 |
-
|
417 |
-
}
|
418 |
|
419 |
-
|
|
|
420 |
|
421 |
-
|
422 |
-
|
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 |
-
|
|
|
|
|
|
|
445 |
|
446 |
-
|
|
|
447 |
|
448 |
-
|
449 |
-
|
450 |
-
|
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 |
-
|
|
|
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 |
-
|
|
|
477 |
|
478 |
-
|
479 |
-
|
480 |
|
481 |
-
|
482 |
-
|
|
|
|
|
483 |
|
484 |
-
|
485 |
-
|
486 |
|
487 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
488 |
<script type="text/javascript">
|
489 |
jQuery(function($){
|
490 |
|
491 |
-
|
492 |
-
|
493 |
-
|
494 |
-
|
495 |
|
496 |
});
|
497 |
</script>
|
498 |
-
|
499 |
|
500 |
-
|
501 |
|
502 |
-
|
503 |
-
|
504 |
-
|
505 |
-
|
506 |
-
|
507 |
-
|
508 |
-
public function pending_payments_style()
|
509 |
-
{
|
510 |
|
511 |
-
|
512 |
|
513 |
-
|
514 |
-
}
|
515 |
|
516 |
-
|
517 |
<script type="text/javascript">
|
518 |
jQuery(function($){
|
519 |
|
520 |
-
|
521 |
-
|
522 |
-
|
523 |
|
524 |
});
|
525 |
</script>
|
526 |
-
|
527 |
-
|
528 |
-
|
529 |
-
|
530 |
-
|
531 |
-
|
532 |
-
|
533 |
-
|
534 |
-
|
535 |
-
|
536 |
-
|
537 |
-
|
538 |
-
|
539 |
-
|
540 |
-
|
541 |
-
|
542 |
-
|
543 |
-
|
544 |
-
|
545 |
-
|
546 |
-
|
547 |
-
|
548 |
-
|
549 |
-
|
550 |
-
|
551 |
-
|
552 |
-
|
553 |
-
|
554 |
-
|
555 |
-
|
556 |
-
|
557 |
-
|
558 |
-
|
559 |
-
|
560 |
-
|
561 |
-
|
562 |
-
|
563 |
-
|
564 |
-
|
565 |
-
|
566 |
-
|
567 |
-
|
568 |
-
|
569 |
-
|
570 |
-
|
571 |
-
|
572 |
-
|
573 |
-
|
574 |
-
|
575 |
-
|
576 |
-
|
577 |
-
|
578 |
-
|
579 |
-
|
580 |
-
|
581 |
-
|
582 |
-
|
583 |
-
|
584 |
-
|
585 |
-
|
586 |
-
|
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 |
-
|
596 |
-
|
597 |
-
|
598 |
-
|
599 |
|
600 |
-
|
601 |
|
602 |
-
|
603 |
-
|
604 |
|
605 |
-
|
606 |
|
607 |
-
|
608 |
-
|
609 |
-
|
610 |
|
611 |
-
|
612 |
-
|
613 |
|
614 |
-
|
615 |
|
616 |
-
|
617 |
-
|
618 |
-
|
619 |
</div>
|
620 |
-
|
621 |
-
|
622 |
-
|
623 |
-
|
624 |
-
|
625 |
-
|
626 |
-
|
627 |
-
|
628 |
-
|
629 |
-
|
630 |
-
|
631 |
-
|
632 |
-
|
633 |
-
|
634 |
-
|
635 |
-
|
636 |
-
|
637 |
-
|
638 |
-
|
639 |
-
|
640 |
-
|
641 |
-
|
642 |
-
|
643 |
-
|
644 |
-
|
645 |
-
|
646 |
-
|
647 |
-
|
648 |
-
|
649 |
-
|
650 |
-
|
651 |
-
|
652 |
-
|
653 |
-
|
654 |
-
|
655 |
-
|
656 |
-
|
657 |
-
|
658 |
-
|
659 |
-
|
660 |
-
|
661 |
-
|
662 |
-
|
663 |
-
} else {
|
664 |
-
$mycred = mycred($pending_payment->point_type);
|
665 |
-
}
|
666 |
-
|
667 |
-
?>
|
668 |
<div class="form">
|
669 |
-
|
670 |
-
|
671 |
-
|
672 |
-
|
673 |
-
|
674 |
-
|
675 |
-
|
676 |
-
|
677 |
-
|
678 |
-
|
679 |
-
|
680 |
-
|
681 |
-
|
682 |
-
|
683 |
-
|
684 |
-
|
685 |
-
|
686 |
-
|
687 |
-
|
688 |
-
|
689 |
-
|
690 |
-
|
691 |
-
|
692 |
-
|
693 |
-
|
694 |
-
|
695 |
-
|
696 |
-
|
697 |
-
|
698 |
-
|
699 |
-
|
700 |
-
|
701 |
-
|
702 |
-
|
703 |
-
|
704 |
-
|
705 |
-
|
706 |
-
|
707 |
-
|
708 |
-
|
709 |
-
|
710 |
-
|
711 |
-
|
712 |
-
|
713 |
-
|
714 |
-
|
715 |
-
|
716 |
-
|
717 |
-
|
718 |
-
|
719 |
-
|
720 |
-
|
721 |
-
|
722 |
-
|
723 |
-
|
724 |
-
|
725 |
-
|
726 |
-
|
727 |
-
|
728 |
-
|
729 |
-
|
730 |
-
|
731 |
-
|
732 |
-
|
733 |
-
|
734 |
-
|
735 |
-
|
736 |
-
|
737 |
-
|
738 |
-
|
739 |
-
|
740 |
-
|
741 |
-
|
742 |
-
|
743 |
-
|
744 |
-
|
745 |
-
|
746 |
-
|
747 |
-
|
748 |
-
|
749 |
-
|
750 |
-
|
751 |
-
|
752 |
-
|
753 |
-
|
754 |
-
|
755 |
-
|
756 |
-
|
757 |
-
|
758 |
-
|
759 |
-
|
760 |
-
|
761 |
-
</div>
|
762 |
-
</div>
|
763 |
-
</div>
|
764 |
</div>
|
765 |
-
|
766 |
|
767 |
-
|
768 |
|
769 |
-
|
770 |
-
|
771 |
-
|
772 |
-
|
773 |
-
|
774 |
-
|
775 |
-
public function metabox_pending_comments( $post )
|
776 |
-
{
|
777 |
|
778 |
-
|
779 |
|
780 |
-
|
781 |
|
782 |
-
|
783 |
|
784 |
-
|
785 |
-
|
786 |
-
|
787 |
|
788 |
-
|
789 |
-
|
790 |
-
|
791 |
|
792 |
-
|
793 |
-
|
794 |
-
}
|
795 |
|
796 |
-
|
797 |
|
798 |
-
|
799 |
|
800 |
-
|
801 |
|
802 |
-
|
803 |
|
804 |
-
|
805 |
|
806 |
-
|
807 |
|
808 |
-
|
809 |
|
810 |
-
|
811 |
-
|
812 |
-
|
813 |
-
|
814 |
-
|
815 |
-
|
816 |
-
public function save_pending_payment( $post_id, $post )
|
817 |
-
{
|
818 |
|
819 |
-
|
820 |
-
}
|
821 |
|
822 |
-
|
823 |
-
|
824 |
|
825 |
-
|
826 |
|
827 |
-
|
828 |
-
|
829 |
-
|
830 |
-
|
831 |
-
|
832 |
-
|
833 |
|
834 |
-
|
835 |
|
836 |
-
|
837 |
-
|
838 |
-
|
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 |
-
|
854 |
-
{
|
855 |
|
856 |
-
|
857 |
-
|
858 |
|
859 |
-
|
860 |
|
861 |
-
|
862 |
endif;
|
863 |
-
add_filter('mycred_load_modules', 'mycred_load_buycred_pending_addon', 40, 2);
|
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 );
|
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,25 +4,22 @@
|
|
4 |
* Addon URI: http://codex.mycred.me/chapter-iii/buycred/
|
5 |
* Version: 1.6
|
6 |
*/
|
7 |
-
if (! defined('myCRED_VERSION') )
|
8 |
-
|
9 |
-
|
10 |
-
define('
|
11 |
-
define('
|
12 |
-
define('
|
13 |
-
define('
|
14 |
-
define('
|
15 |
-
define('
|
16 |
-
define('
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
if (! defined('MYCRED_BUY_KEY') ) {
|
24 |
-
define('MYCRED_BUY_KEY', 'buycred_payment');
|
25 |
-
}
|
26 |
|
27 |
/**
|
28 |
* Load Dependencies
|
@@ -35,8 +32,7 @@ require_once MYCRED_BUYCRED_INCLUDES_DIR . 'buycred-reward.php';
|
|
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,12 +41,11 @@ require_once MYCRED_BUYCRED_GATEWAYS_DIR . 'netbilling.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';
|
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 |
|
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 |
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';
|
addons/buy-creds/templates/buycred-checkout.php
CHANGED
@@ -1,25 +1,25 @@
|
|
1 |
<?php get_header(); ?>
|
2 |
|
3 |
<div id="buycred-checkout-page">
|
4 |
-
|
5 |
|
6 |
-
|
7 |
|
8 |
-
|
9 |
-
|
10 |
|
11 |
-
|
12 |
|
13 |
-
|
14 |
|
15 |
-
|
16 |
|
17 |
-
|
18 |
-
|
19 |
|
20 |
-
|
21 |
|
22 |
-
|
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,772 +1,707 @@
|
|
1 |
<?php
|
2 |
-
if (! defined('myCRED_VERSION') )
|
3 |
-
}
|
4 |
|
5 |
/**
|
6 |
* myCRED_Cash_Payment_Gateway class
|
7 |
-
*
|
8 |
-
* @
|
9 |
-
* @since 0.1
|
10 |
* @version 1.3
|
11 |
*/
|
12 |
-
if (! class_exists('myCRED_Cash_Payment_Gateway') ) :
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
-
|
94 |
-
|
95 |
-
|
96 |
-
|
97 |
-
|
98 |
-
|
99 |
-
|
100 |
-
|
101 |
-
|
102 |
-
|
103 |
-
|
104 |
-
|
105 |
-
|
106 |
-
|
107 |
-
|
108 |
-
|
109 |
-
|
110 |
-
|
111 |
-
|
112 |
-
|
113 |
-
|
114 |
-
|
115 |
-
|
116 |
-
|
117 |
-
|
118 |
-
|
119 |
-
|
120 |
-
|
121 |
-
|
122 |
-
|
123 |
-
|
124 |
-
|
125 |
-
|
126 |
-
|
127 |
-
|
128 |
-
|
129 |
-
|
130 |
-
|
131 |
-
|
132 |
-
|
133 |
-
|
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 |
-
|
156 |
|
157 |
-
|
158 |
|
159 |
-
|
160 |
-
|
161 |
-
}
|
162 |
|
163 |
-
|
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 |
-
|
172 |
-
|
173 |
|
174 |
-
|
175 |
-
|
176 |
-
}
|
177 |
|
178 |
-
|
179 |
</tr>
|
180 |
</table>';
|
181 |
|
182 |
-
|
183 |
|
184 |
-
|
185 |
|
186 |
-
|
187 |
|
188 |
-
|
189 |
-
|
190 |
-
|
191 |
-
|
192 |
-
|
193 |
-
|
194 |
-
|
195 |
-
|
196 |
-
|
197 |
-
|
198 |
-
|
199 |
-
|
200 |
-
|
201 |
-
|
202 |
-
|
203 |
-
|
204 |
-
|
205 |
-
|
206 |
-
|
207 |
-
|
208 |
-
|
209 |
-
|
210 |
-
|
211 |
-
|
212 |
-
|
213 |
-
|
214 |
-
|
215 |
-
|
216 |
-
|
217 |
-
|
218 |
-
|
219 |
-
|
220 |
-
|
221 |
-
|
222 |
-
|
223 |
-
|
224 |
-
|
225 |
-
|
226 |
-
|
227 |
-
|
228 |
-
|
229 |
-
|
230 |
-
|
231 |
-
|
232 |
-
|
233 |
-
|
234 |
-
|
235 |
-
|
236 |
-
|
237 |
-
|
238 |
-
|
239 |
-
|
240 |
-
|
241 |
-
|
242 |
-
|
243 |
-
|
244 |
-
|
245 |
-
|
246 |
-
|
247 |
-
|
248 |
-
|
249 |
-
|
250 |
-
|
251 |
-
|
252 |
-
|
253 |
-
|
254 |
-
|
255 |
-
|
256 |
-
|
257 |
-
|
258 |
-
|
259 |
-
|
260 |
-
|
261 |
-
|
262 |
-
|
263 |
-
|
264 |
-
|
265 |
-
|
266 |
-
|
267 |
-
|
268 |
-
|
269 |
-
|
270 |
-
|
271 |
-
|
272 |
-
|
273 |
-
|
274 |
-
|
275 |
-
|
276 |
-
|
277 |
-
|
278 |
-
|
279 |
-
|
280 |
-
|
281 |
-
|
282 |
-
|
283 |
-
|
284 |
-
|
285 |
-
|
286 |
-
|
287 |
-
|
288 |
-
|
289 |
-
|
290 |
-
'
|
291 |
-
'
|
292 |
-
'
|
293 |
-
'
|
294 |
-
'
|
295 |
-
'
|
296 |
-
'
|
297 |
-
'
|
298 |
-
'
|
299 |
-
'
|
300 |
-
'
|
301 |
-
'
|
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 |
-
|
319 |
-
|
320 |
-
|
321 |
-
|
322 |
-
|
323 |
-
|
324 |
-
|
325 |
-
|
326 |
-
|
327 |
-
|
328 |
-
|
329 |
-
|
330 |
-
|
331 |
-
|
332 |
-
|
333 |
-
|
334 |
-
|
335 |
-
|
336 |
-
|
337 |
-
|
338 |
-
|
339 |
-
|
340 |
-
|
341 |
-
|
342 |
-
|
343 |
-
|
344 |
-
|
345 |
-
|
346 |
-
|
347 |
-
|
348 |
-
|
349 |
-
|
350 |
-
|
351 |
-
|
352 |
-
|
353 |
-
|
354 |
-
|
355 |
-
|
356 |
-
|
357 |
-
|
358 |
-
|
359 |
-
|
360 |
-
|
361 |
-
|
362 |
-
|
363 |
-
|
364 |
-
|
365 |
-
|
366 |
-
|
367 |
-
|
368 |
-
|
369 |
-
|
370 |
-
|
371 |
-
|
372 |
-
|
373 |
-
|
374 |
-
|
375 |
-
|
376 |
-
|
377 |
-
|
378 |
-
|
379 |
-
|
380 |
-
|
381 |
-
|
382 |
-
|
383 |
-
|
384 |
-
|
385 |
-
|
386 |
-
|
387 |
-
|
388 |
-
|
389 |
-
|
390 |
-
|
391 |
-
|
392 |
-
|
393 |
-
|
394 |
-
|
395 |
-
|
396 |
-
|
397 |
-
|
398 |
-
|
399 |
-
|
400 |
-
|
401 |
-
|
402 |
-
|
403 |
-
|
404 |
-
|
405 |
-
|
406 |
-
|
407 |
-
|
408 |
-
|
409 |
-
|
410 |
-
|
411 |
-
|
412 |
-
|
413 |
-
|
414 |
-
|
415 |
-
|
416 |
-
|
417 |
-
|
418 |
-
|
419 |
-
|
420 |
-
|
421 |
-
|
422 |
-
|
423 |
-
|
424 |
-
|
425 |
-
|
426 |
-
|
427 |
-
|
428 |
-
|
429 |
-
|
430 |
-
|
431 |
-
|
432 |
-
|
433 |
-
|
434 |
-
|
435 |
-
|
436 |
-
|
437 |
-
|
438 |
-
|
439 |
-
|
440 |
-
|
441 |
-
|
442 |
-
|
443 |
-
|
444 |
-
|
445 |
-
|
446 |
-
|
447 |
-
|
448 |
-
|
449 |
-
|
450 |
-
|
451 |
-
|
452 |
-
|
453 |
-
|
454 |
-
|
455 |
-
|
456 |
-
|
457 |
-
|
458 |
-
|
459 |
-
|
460 |
-
|
461 |
-
|
462 |
-
|
463 |
-
|
464 |
-
|
465 |
-
|
466 |
-
|
467 |
-
|
468 |
-
|
469 |
-
|
470 |
-
|
471 |
-
|
472 |
-
|
473 |
-
|
474 |
-
|
475 |
-
|
476 |
-
|
477 |
-
|
478 |
-
|
479 |
-
|
480 |
-
|
481 |
-
|
482 |
-
|
483 |
-
|
484 |
-
|
485 |
-
|
486 |
-
|
487 |
-
|
488 |
-
|
489 |
-
|
490 |
-
|
491 |
-
|
492 |
-
|
493 |
-
|
494 |
-
|
495 |
-
|
496 |
-
|
497 |
-
|
498 |
-
|
499 |
-
|
500 |
-
|
501 |
-
|
502 |
-
|
503 |
-
|
504 |
-
|
505 |
-
|
506 |
-
|
507 |
-
|
508 |
-
|
509 |
-
|
510 |
-
|
511 |
-
|
512 |
-
|
513 |
-
|
514 |
-
|
515 |
-
|
516 |
-
|
517 |
-
|
518 |
-
|
519 |
-
|
520 |
-
|
521 |
-
|
522 |
-
|
523 |
-
|
524 |
-
|
525 |
-
|
526 |
-
|
527 |
-
|
528 |
-
|
529 |
-
|
530 |
-
|
531 |
-
|
532 |
-
|
533 |
-
|
534 |
-
|
535 |
-
|
536 |
-
|
537 |
-
|
538 |
-
|
539 |
-
|
540 |
-
|
541 |
-
|
542 |
-
|
543 |
-
|
544 |
-
|
545 |
-
|
546 |
-
|
547 |
-
|
548 |
-
|
549 |
-
|
550 |
-
|
551 |
-
|
552 |
-
|
553 |
-
|
554 |
-
|
555 |
-
|
556 |
-
|
557 |
-
|
558 |
-
|
559 |
-
|
560 |
-
|
561 |
-
|
562 |
-
|
563 |
-
|
564 |
-
|
565 |
-
|
566 |
-
|
567 |
-
|
568 |
-
|
569 |
-
|
570 |
-
|
571 |
-
|
572 |
-
|
573 |
-
|
574 |
-
|
575 |
-
|
576 |
-
|
577 |
-
|
578 |
-
|
579 |
-
|
580 |
-
|
581 |
-
|
582 |
-
|
583 |
-
|
584 |
-
|
585 |
-
|
586 |
-
|
587 |
-
|
588 |
-
|
589 |
-
|
590 |
-
|
591 |
-
|
592 |
-
|
593 |
-
|
594 |
-
|
595 |
-
|
596 |
-
|
597 |
-
|
598 |
-
|
599 |
-
|
600 |
-
|
601 |
-
|
602 |
-
|
603 |
-
|
604 |
-
|
605 |
-
|
606 |
-
|
607 |
-
|
608 |
-
|
609 |
-
|
610 |
-
|
611 |
-
|
612 |
-
|
613 |
-
|
614 |
-
|
615 |
-
|
616 |
-
|
617 |
-
|
618 |
-
|
619 |
-
|
620 |
-
|
621 |
-
|
622 |
-
|
623 |
-
|
624 |
-
|
625 |
-
|
626 |
-
|
627 |
-
|
628 |
-
|
629 |
-
|
630 |
-
|
631 |
-
|
632 |
-
|
633 |
-
|
634 |
-
|
635 |
-
|
636 |
-
|
637 |
-
|
638 |
-
|
639 |
-
|
640 |
-
|
641 |
-
|
642 |
-
|
643 |
-
|
644 |
-
|
645 |
-
|
646 |
-
|
647 |
-
|
648 |
-
|
649 |
-
|
650 |
-
|
651 |
-
|
652 |
-
|
653 |
-
|
654 |
-
|
655 |
-
|
656 |
-
|
657 |
-
|
658 |
-
|
659 |
-
|
660 |
-
|
661 |
-
|
662 |
-
|
663 |
-
|
664 |
-
|
665 |
-
|
666 |
-
|
667 |
-
|
668 |
-
|
669 |
-
|
670 |
-
|
671 |
-
|
672 |
-
|
673 |
-
|
674 |
-
|
675 |
-
|
676 |
-
|
677 |
-
|
678 |
-
|
679 |
-
|
680 |
-
|
681 |
-
|
682 |
-
|
683 |
-
|
684 |
-
|
685 |
-
|
686 |
-
|
687 |
-
|
688 |
-
|
689 |
-
|
690 |
-
|
691 |
-
|
692 |
-
|
693 |
-
|
694 |
-
|
695 |
-
|
696 |
-
|
697 |
-
|
698 |
-
|
699 |
-
|
700 |
-
|
701 |
-
|
702 |
-
|
703 |
-
|
704 |
-
|
705 |
-
|
706 |
-
|
707 |
-
|
708 |
-
|
709 |
-
|
710 |
-
|
711 |
-
|
712 |
-
|
713 |
-
|
714 |
-
|
715 |
-
|
716 |
-
|
717 |
-
|
718 |
-
|
719 |
-
|
720 |
-
|
721 |
-
|
722 |
-
|
723 |
-
|
724 |
-
|
725 |
-
|
726 |
-
|
727 |
-
|
728 |
-
|
729 |
-
|
730 |
-
|
731 |
-
|
732 |
-
|
733 |
-
|
734 |
-
|
735 |
-
|
736 |
-
|
737 |
-
|
738 |
-
|
739 |
-
|
740 |
-
|
741 |
-
|
742 |
-
|
743 |
-
|
744 |
-
|
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="' . esc_attr( $key ) . '"';
|
764 |
-
if ($selected == $key ) { echo ' selected="selected"';
|
765 |
-
}
|
766 |
-
echo '>' . esc_html( $value ) . '</option>';
|
767 |
-
}
|
768 |
-
|
769 |
-
}
|
770 |
-
|
771 |
-
}
|
772 |
endif;
|
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="' . esc_attr( $code ) . '" ' . selected( $selected, $code ) . '>' . esc_html( $cname ) . '</option>';
|
575 |
+
}
|
576 |
+
|
577 |
+
}
|
578 |
+
|
579 |
+
/**
|
580 |
+
* US States Dropdown Options
|
581 |
+
* @since 0.1
|
582 |
+
* @version 1.0
|
583 |
+
*/
|
584 |
+
public function list_option_us_states( $selected = '', $non_us = false ) {
|
585 |
+
|
586 |
+
$states = array (
|
587 |
+
"AL" => "Alabama",
|
588 |
+
"AK" => "Alaska",
|
589 |
+
"AZ" => "Arizona",
|
590 |
+
"AR" => "Arkansas",
|
591 |
+
"CA" => "California",
|
592 |
+
"CO" => "Colorado",
|
593 |
+
"CT" => "Connecticut",
|
594 |
+
"DC" => "D.C.",
|
595 |
+
"DE" => "Delaware",
|
596 |
+
"FL" => "Florida",
|
597 |
+
"GA" => "Georgia",
|
598 |
+
"HI" => "Hawaii",
|
599 |
+
"ID" => "Idaho",
|
600 |
+
"IL" => "Illinois",
|
601 |
+
"IN" => "Indiana",
|
602 |
+
"IA" => "Iowa",
|
603 |
+
"KS" => "Kansas",
|
604 |
+
"KY" => "Kentucky",
|
605 |
+
"LA" => "Louisiana",
|
606 |
+
"ME" => "Maine",
|
607 |
+
"MD" => "Maryland",
|
608 |
+
"MA" => "Massachusetts",
|
609 |
+
"MI" => "Michigan",
|
610 |
+
"MN" => "Minnesota",
|
611 |
+
"MS" => "Mississippi",
|
612 |
+
"MO" => "Missouri",
|
613 |
+
"MT" => "Montana",
|
614 |
+
"NE" => "Nebraska",
|
615 |
+
"NV" => "Nevada",
|
616 |
+
"NH" => "New Hampshire",
|
617 |
+
"NJ" => "New Jersey",
|
618 |
+
"NM" => "New Mexico",
|
619 |
+
"NY" => "New York",
|
620 |
+
"NC" => "North Carolina",
|
621 |
+
"ND" => "North Dakota",
|
622 |
+
"OH" => "Ohio",
|
623 |
+
"OK" => "Oklahoma",
|
624 |
+
"OR" => "Oregon",
|
625 |
+
"PA" => "Pennsylvania",
|
626 |
+
"RI" => "Rhode Island",
|
627 |
+
"SC" => "South Carolina",
|
628 |
+
"SD" => "South Dakota",
|
629 |
+
"TN" => "Tennessee",
|
630 |
+
"TX" => "Texas",
|
631 |
+
"UT" => "Utah",
|
632 |
+
"VT" => "Vermont",
|
633 |
+
"VA" => "Virginia",
|
634 |
+
"WA" => "Washington",
|
635 |
+
"WV" => "West Virginia",
|
636 |
+
"WI" => "Wisconsin",
|
637 |
+
"WY" => "Wyoming"
|
638 |
+
);
|
639 |
+
$states = apply_filters( 'mycred_list_option_us', $states );
|
640 |
+
|
641 |
+
$outside = 'Outside US';
|
642 |
+
if ( $non_us == 'top' ) echo '<option value="">' . esc_html( $outside ) . '</option>';
|
643 |
+
foreach ( $states as $code => $cname ) {
|
644 |
+
echo '<option value="' . esc_attr( $code ) . '" ' . selected( $selected, $code ) . '>' . esc_html( $cname ) . '</option>';
|
645 |
+
}
|
646 |
+
if ( $non_us == 'bottom' ) echo '<option value="">' . esc_html( $outside ) . '</option>';
|
647 |
+
|
648 |
+
}
|
649 |
+
|
650 |
+
/**
|
651 |
+
* Months Dropdown Options
|
652 |
+
* @since 0.1
|
653 |
+
* @version 1.0
|
654 |
+
*/
|
655 |
+
public function list_option_months( $selected = '' ) {
|
656 |
+
|
657 |
+
$months = array (
|
658 |
+
"01" => __( 'January', 'mycred' ),
|
659 |
+
"02" => __( 'February', 'mycred' ),
|
660 |
+
"03" => __( 'March', 'mycred' ),
|
661 |
+
"04" => __( 'April', 'mycred' ),
|
662 |
+
"05" => __( 'May', 'mycred' ),
|
663 |
+
"06" => __( 'June', 'mycred' ),
|
664 |
+
"07" => __( 'July', 'mycred' ),
|
665 |
+
"08" => __( 'August', 'mycred' ),
|
666 |
+
"09" => __( 'September', 'mycred' ),
|
667 |
+
"10" => __( 'October', 'mycred' ),
|
668 |
+
"11" => __( 'November', 'mycred' ),
|
669 |
+
"12" => __( 'December', 'mycred' )
|
670 |
+
);
|
671 |
+
|
672 |
+
foreach ( $months as $number => $text ) {
|
673 |
+
echo '<option value="' . esc_attr( $number ) . '" ' . selected( $selected, $number ) . '>' . esc_html( $text ) . '</option>';
|
674 |
+
}
|
675 |
+
|
676 |
+
}
|
677 |
+
|
678 |
+
/**
|
679 |
+
* Years Dropdown Options
|
680 |
+
* @since 0.1
|
681 |
+
* @version 1.0
|
682 |
+
*/
|
683 |
+
public function list_option_card_years( $selected = '', $number = 16 ) {
|
684 |
+
|
685 |
+
$now = current_time( 'timestamp' );
|
686 |
+
$yy = date( 'y', $now );
|
687 |
+
$yyyy = date( 'Y', $now );
|
688 |
+
$count = 0;
|
689 |
+
$options = array();
|
690 |
+
|
691 |
+
while ( $count <= (int) $number ) {
|
692 |
+
$count ++;
|
693 |
+
if ( $count > 1 ) {
|
694 |
+
$yy++;
|
695 |
+
$yyyy++;
|
696 |
+
}
|
697 |
+
$options[ $yy ] = $yyyy;
|
698 |
+
}
|
699 |
+
|
700 |
+
foreach ( $options as $key => $value ) {
|
701 |
+
echo '<option value="' . esc_attr( $key ) . '" ' . selected( $selected, $key ) . '>' . esc_html( $value ) . '</option>';
|
702 |
+
}
|
703 |
+
|
704 |
+
}
|
705 |
+
|
706 |
+
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
707 |
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 |
-
|
3 |
-
|
4 |
-
|
5 |
-
|
6 |
-
|
7 |
}
|
8 |
.type-cashcred_withdrawal .cashcred_Pending{
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
}
|
15 |
.type-cashcred_withdrawal .cashcred_Cancelled{
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
}
|
22 |
.cashcred_bages {
|
23 |
-
|
24 |
}
|
25 |
.history li {
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
}
|
34 |
|
35 |
#cashcred-comments .history li time {
|
36 |
-
|
37 |
}
|
38 |
|
39 |
.readonly_fields[readonly]{
|
40 |
-
|
41 |
}
|
42 |
|
43 |
#cashcred-comments .history p {
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
}
|
50 |
|
51 |
|
52 |
#cashcred-developer-log pre {
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
}
|
63 |
|
64 |
#payment_gateway_detail input.form-control {
|
65 |
-
|
66 |
}
|
67 |
#payment_gateway_detail .inside{ padding: 4px;}
|
68 |
.cashcred_panel {
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
}
|
74 |
#cashcred_withdrawal_request .row select ,#cashcred_withdrawal_request .row input{
|
75 |
-
|
76 |
}
|
77 |
#cashcred-payment-status .spinner
|
78 |
{
|
79 |
-
|
80 |
}
|
81 |
#cashcred-payment-status .spinner.is-active {
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
|
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 |
-
|
3 |
}
|
4 |
|
5 |
#cashcred * {
|
6 |
-
|
7 |
}
|
8 |
|
9 |
#cashcred ul.cashcred-nav-tabs li {
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
margin-bottom: 5px;
|
16 |
}
|
17 |
|
@@ -27,12 +27,12 @@
|
|
27 |
}
|
28 |
|
29 |
#cashcred #cashcred_tab_content .cashcred-tab {
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
}
|
37 |
|
38 |
#cashcred .form-group label {
|
@@ -53,8 +53,8 @@
|
|
53 |
}
|
54 |
|
55 |
#cashcred input[type=submit] {
|
56 |
-
|
57 |
-
|
58 |
}
|
59 |
|
60 |
#cashcred input[type=submit]:hover {
|
@@ -62,35 +62,35 @@
|
|
62 |
}
|
63 |
|
64 |
#cashcred select {
|
65 |
-
|
66 |
}
|
67 |
|
68 |
#cashcred_total{
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
}
|
78 |
|
79 |
div#submit_button, .amount_label{
|
80 |
-
|
81 |
}
|
82 |
|
83 |
.cashcred-tab{
|
84 |
-
|
85 |
}
|
86 |
|
87 |
.cashcred-min {
|
88 |
-
|
89 |
}
|
90 |
|
91 |
.cashcred_gateway_notice {
|
92 |
-
|
93 |
-
|
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,212 +1,189 @@
|
|
1 |
/**
|
2 |
* CashCred Withdraw
|
3 |
-
*
|
4 |
-
* @since 2.0
|
5 |
* @version 1.0
|
6 |
*/
|
7 |
-
jQuery(
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
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 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
-
|
94 |
-
|
95 |
-
|
96 |
-
|
97 |
-
|
98 |
-
|
99 |
-
|
100 |
-
|
101 |
-
|
102 |
-
|
103 |
-
|
104 |
-
|
105 |
-
|
106 |
-
|
107 |
-
|
108 |
-
|
109 |
-
|
110 |
-
|
111 |
-
|
112 |
-
|
113 |
-
|
114 |
-
|
115 |
-
|
116 |
-
|
117 |
-
|
118 |
-
|
119 |
-
|
120 |
-
|
121 |
-
|
122 |
-
|
123 |
-
|
124 |
-
|
125 |
-
|
126 |
-
|
127 |
-
|
128 |
-
|
129 |
-
|
130 |
-
|
131 |
-
|
132 |
-
|
133 |
-
|
134 |
-
|
135 |
-
|
136 |
-
|
137 |
-
|
138 |
-
|
139 |
-
|
140 |
-
|
141 |
-
|
142 |
-
|
143 |
-
|
144 |
-
|
145 |
-
|
146 |
-
|
147 |
-
|
148 |
-
|
149 |
-
|
150 |
-
|
151 |
-
|
152 |
-
|
153 |
-
|
154 |
-
|
155 |
-
|
156 |
-
|
157 |
-
|
158 |
-
|
159 |
-
|
160 |
-
|
161 |
-
|
162 |
-
|
163 |
-
|
164 |
-
|
165 |
-
|
166 |
-
|
167 |
-
|
168 |
-
|
169 |
-
|
170 |
-
|
171 |
-
|
172 |
-
|
173 |
-
|
174 |
-
|
175 |
-
|
176 |
-
|
177 |
-
|
178 |
-
|
179 |
-
|
180 |
-
|
181 |
-
|
182 |
-
|
183 |
-
|
184 |
-
|
185 |
-
|
186 |
-
|
187 |
-
|
188 |
-
|
189 |
-
|
190 |
-
|
191 |
-
|
192 |
-
|
193 |
-
|
194 |
-
|
195 |
-
s = (prec ? toFixedFix(n, prec) : '' + Math.round(n)).split('.');
|
196 |
-
if (s[0].length > 3) {
|
197 |
-
s[0] = s[0].replace(/\B(?=(?:\d{3})+(?!\d))/g, sep);
|
198 |
-
}
|
199 |
-
if ((s[1] || '').length < prec) {
|
200 |
-
s[1] = s[1] || '';
|
201 |
-
s[1] += new Array(prec - s[1].length + 1).join('0');
|
202 |
-
}
|
203 |
-
|
204 |
-
return s.join(dec);
|
205 |
-
}
|
206 |
-
|
207 |
-
|
208 |
-
}
|
209 |
-
);
|
210 |
|
211 |
|
212 |
|
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 |
+
if ( typeof conversion_rate === 'undefined' ) {
|
80 |
+
conversion_rate = 1;
|
81 |
+
}
|
82 |
+
|
83 |
+
min = cashcred.exchange[cashcred_pay_method].min;
|
84 |
+
max = cashcred.exchange[cashcred_pay_method].max
|
85 |
+
|
86 |
+
amount = withdraw_points * conversion_rate;
|
87 |
+
|
88 |
+
$( "#withdraw_points" ).attr({"max" : max , "min" : min });
|
89 |
+
|
90 |
+
$( '.cashcred-min span' ).html( min );
|
91 |
+
|
92 |
+
$( "#cashcred_currency_symbol" ).html(currency_code);
|
93 |
+
$( "#cashcred_total_amount" ).html(amount.toFixed(2).replace(/\d(?=(\d{3})+\.)/g, '$&,'));
|
94 |
+
|
95 |
+
}
|
96 |
+
|
97 |
+
function display_cashcred_gateway_notice() {
|
98 |
+
|
99 |
+
if ( cashcred.gateway_notices[ $('#cashcred_pay_method').val() ] ) {
|
100 |
+
|
101 |
+
$('.cashcred_gateway_notice').show();
|
102 |
+
|
103 |
+
}
|
104 |
+
else {
|
105 |
+
|
106 |
+
$('.cashcred_gateway_notice').hide();
|
107 |
+
|
108 |
+
}
|
109 |
+
|
110 |
+
}
|
111 |
+
|
112 |
+
function cashcred_fee_setting( point_type, withdraw_points ) {
|
113 |
+
|
114 |
+
if ( cashcred_data.cashcred_setting.use == 1 ) {
|
115 |
+
var fee = 0;
|
116 |
+
var ctype = cashcred_data.cashcred_setting.types[point_type];
|
117 |
+
var by = cashcred_data.cashcred_setting.types[point_type].by;
|
118 |
+
var fee_amount = cashcred_data.cashcred_setting.types[point_type].amount;
|
119 |
+
var max_cap = cashcred_data.cashcred_setting.types[point_type].max_cap;
|
120 |
+
var min_cap = cashcred_data.cashcred_setting.types[point_type].min_cap;
|
121 |
+
var presentation = cashcred_data.cashcred_setting.types[point_type].presentation;
|
122 |
+
|
123 |
+
//formats
|
124 |
+
decimals = cashcred_data.format[point_type].decimals;
|
125 |
+
decimal_sep = cashcred_data.format[point_type].separators.decimal;
|
126 |
+
thousand_sep = cashcred_data.format[point_type].separators.thousand;
|
127 |
+
if( withdraw_points > 0 ) {
|
128 |
+
fee = fee_amount;
|
129 |
+
if( by == 'percent' ){
|
130 |
+
fee = ( ( fee_amount / 100 ) * withdraw_points );
|
131 |
+
fee_amount = fee_amount + '%';
|
132 |
+
}
|
133 |
+
|
134 |
+
if( min_cap != 0 )
|
135 |
+
fee = ( parseInt(fee) + parseInt(min_cap) );
|
136 |
+
|
137 |
+
|
138 |
+
if ( max_cap != 0 && fee > max_cap )
|
139 |
+
fee = max_cap;
|
140 |
+
|
141 |
+
presentation = presentation.replace( "%fee%", fee_amount );
|
142 |
+
presentation = presentation.replace( "%min%", min_cap );
|
143 |
+
presentation = presentation.replace( "%max%", max_cap );
|
144 |
+
presentation = presentation.replace( "%total%", mycred_number_format( fee, decimals, decimal_sep, thousand_sep ) );
|
145 |
+
|
146 |
+
$('.cashcred-fee').show();
|
147 |
+
$( '.cashcred-fee span' ).html( presentation );
|
148 |
+
}
|
149 |
+
|
150 |
+
}
|
151 |
+
else {
|
152 |
+
|
153 |
+
$('.cashcred-fee').hide();
|
154 |
+
|
155 |
+
}
|
156 |
+
}
|
157 |
+
|
158 |
+
function mycred_number_format ( number, decimals, dec_point, thousands_sep ) {
|
159 |
+
|
160 |
+
// Strip all characters but numerical ones.
|
161 |
+
number = (number + '').replace(/[^0-9+\-Ee.]/g, '');
|
162 |
+
var n = !isFinite(+number) ? 0 : +number,
|
163 |
+
prec = !isFinite(+decimals) ? 0 : Math.abs(decimals),
|
164 |
+
sep = (typeof thousands_sep === 'undefined') ? ',' : thousands_sep,
|
165 |
+
dec = (typeof dec_point === 'undefined') ? '.' : dec_point,
|
166 |
+
s = '',
|
167 |
+
toFixedFix = function (n, prec) {
|
168 |
+
var k = Math.pow(10, prec);
|
169 |
+
return '' + Math.round(n * k) / k;
|
170 |
+
};
|
171 |
+
|
172 |
+
// Fix for IE parseFloat(0.55).toFixed(0) = 0;
|
173 |
+
s = (prec ? toFixedFix(n, prec) : '' + Math.round(n)).split('.');
|
174 |
+
if (s[0].length > 3) {
|
175 |
+
s[0] = s[0].replace(/\B(?=(?:\d{3})+(?!\d))/g, sep);
|
176 |
+
}
|
177 |
+
if ((s[1] || '').length < prec) {
|
178 |
+
s[1] = s[1] || '';
|
179 |
+
s[1] += new Array(prec - s[1].length + 1).join('0');
|
180 |
+
}
|
181 |
+
|
182 |
+
return s.join(dec) ;
|
183 |
+
}
|
184 |
+
|
185 |
+
|
186 |
+
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
187 |
|
188 |
|
189 |
|
addons/cash-creds/gateways/bank-transfer.php
CHANGED
@@ -1,330 +1,306 @@
|
|
1 |
<?php
|
2 |
-
if (! defined('myCRED_VERSION') )
|
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 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
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 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
-
|
94 |
-
|
95 |
-
|
96 |
-
|
97 |
-
|
98 |
-
|
99 |
-
|
100 |
-
|
101 |
-
|
102 |
-
|
103 |
-
|
104 |
-
|
105 |
-
|
106 |
-
|
107 |
-
|
108 |
-
|
109 |
-
|
110 |
-
|
111 |
-
|
112 |
-
|
113 |
-
|
114 |
-
|
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 |
-
|
126 |
-
|
127 |
-
|
128 |
-
|
129 |
-
|
130 |
-
|
131 |
-
|
132 |
-
|
133 |
-
|
134 |
-
|
135 |
-
|
136 |
-
|
137 |
-
|
138 |
-
|
139 |
-
|
140 |
-
|
141 |
-
|
142 |
-
|
143 |
-
|
144 |
-
|
145 |
-
|
146 |
-
|
147 |
-
|
148 |
-
|
149 |
-
|
150 |
-
|
151 |
-
|
152 |
-
|
153 |
-
|
154 |
-
|
155 |
-
|
156 |
-
|
157 |
-
|
158 |
-
|
159 |
</div>
|
160 |
|
161 |
<div class="row" id="additional_notes_show">
|
162 |
-
|
163 |
-
|
164 |
-
|
165 |
-
|
166 |
-
|
167 |
-
|
168 |
</div>
|
169 |
<script>
|
170 |
-
|
171 |
-
|
172 |
-
|
173 |
-
|
174 |
-
|
175 |
-
|
176 |
-
|
177 |
-
|
178 |
-
|
179 |
-
|
180 |
-
|
181 |
-
|
182 |
-
|
183 |
-
|
184 |
-
|
185 |
-
|
186 |
-
|
187 |
|
188 |
});
|
189 |
|
190 |
-
|
191 |
-
|
192 |
-
|
193 |
-
|
194 |
-
|
195 |
-
|
196 |
-
|
197 |
-
|
198 |
-
|
199 |
-
|
200 |
-
|
201 |
</script>
|
202 |
-
|
203 |
-
|
204 |
-
|
205 |
-
|
206 |
-
|
207 |
-
|
208 |
-
|
209 |
-
|
210 |
-
|
211 |
-
|
212 |
-
|
213 |
-
|
214 |
-
|
215 |
-
|
216 |
-
|
217 |
-
|
218 |
-
|
219 |
-
|
220 |
-
|
221 |
-
|
222 |
-
|
223 |
-
|
224 |
-
|
225 |
-
|
226 |
-
|
227 |
-
|
228 |
-
|
229 |
-
|
230 |
-
|
231 |
-
|
232 |
-
|
233 |
-
|
234 |
-
|
235 |
-
|
236 |
-
|
237 |
-
|
238 |
-
|
239 |
-
|
240 |
-
|
241 |
-
|
242 |
-
|
243 |
-
|
244 |
-
|
245 |
-
|
246 |
-
|
247 |
-
|
248 |
-
|
249 |
-
|
250 |
-
|
251 |
-
|
252 |
-
|
253 |
-
|
254 |
-
|
255 |
-
|
256 |
-
|
257 |
-
|
258 |
-
|
259 |
-
|
260 |
-
|
261 |
-
|
262 |
-
|
263 |
-
|
264 |
-
|
265 |
-
|
266 |
-
|
267 |
-
|
268 |
-
|
269 |
-
|
270 |
-
|
271 |
-
|
272 |
-
|
273 |
-
|
274 |
-
|
275 |
-
|
276 |
-
|
277 |
-
|
278 |
-
|
279 |
-
|
280 |
-
|
281 |
-
|
282 |
-
|
283 |
-
|
284 |
-
|
285 |
-
|
286 |
-
|
287 |
-
|
288 |
-
|
289 |
-
|
290 |
-
|
291 |
-
|
292 |
-
|
293 |
-
|
294 |
-
|
295 |
-
|
296 |
-
|
297 |
-
|
298 |
-
|
299 |
-
|
300 |
-
|
301 |
-
|
302 |
-
|
303 |
-
|
304 |
-
|
305 |
-
|
306 |
-
|
307 |
-
|
308 |
-
|
309 |
-
|
310 |
-
|
311 |
-
|
312 |
-
|
313 |
-
|
314 |
-
|
315 |
-
|
316 |
-
|
317 |
-
|
318 |
-
|
319 |
-
|
320 |
-
|
321 |
-
|
322 |
-
|
323 |
-
|
324 |
-
|
325 |
-
return $new_data;
|
326 |
-
|
327 |
-
}
|
328 |
-
|
329 |
-
}
|
330 |
endif;
|
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;
|
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,641 +1,587 @@
|
|
1 |
<?php
|
2 |
-
if (! defined('MYCRED_CASHCRED') )
|
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 |
-
|
13 |
-
{
|
14 |
|
15 |
-
|
16 |
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
|
28 |
-
|
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 |
-
|
41 |
-
{
|
42 |
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
}
|
48 |
|
49 |
-
|
50 |
|
51 |
-
|
52 |
endif;
|
53 |
|
54 |
-
if (! function_exists('cashcred_register_fields') ) :
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
return 'cashcred_user_settings['.$type.']['.$name.']';
|
59 |
|
60 |
-
|
61 |
endif;
|
62 |
|
63 |
-
if (! function_exists('cashcred_get_user_payment_details') ) :
|
64 |
-
|
65 |
-
{
|
66 |
|
67 |
-
|
68 |
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
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 |
-
|
88 |
-
|
89 |
-
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
-
|
94 |
-
|
95 |
-
|
96 |
-
|
97 |
-
|
98 |
-
|
99 |
-
|
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 |
-
|
115 |
-
{
|
116 |
|
117 |
-
|
118 |
|
119 |
-
|
120 |
|
121 |
-
|
122 |
-
}
|
123 |
|
124 |
-
|
125 |
|
126 |
-
|
127 |
-
|
128 |
-
|
129 |
-
|
130 |
|
131 |
-
|
132 |
|
133 |
-
|
134 |
|
135 |
-
|
136 |
-
|
137 |
-
}
|
138 |
|
139 |
-
|
140 |
|
141 |
-
|
142 |
|
143 |
-
|
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 |
-
|
157 |
-
{
|
158 |
|
159 |
-
|
160 |
|
161 |
-
|
162 |
|
163 |
-
|
164 |
|
165 |
-
|
166 |
-
|
167 |
-
|
168 |
-
|
169 |
|
170 |
-
|
171 |
|
172 |
-
|
173 |
-
|
174 |
-
|
175 |
-
|
176 |
-
|
177 |
-
|
178 |
-
|
179 |
|
180 |
-
|
181 |
|
182 |
-
|
183 |
|
184 |
-
|
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 |
-
|
198 |
-
{
|
199 |
|
200 |
-
|
201 |
|
202 |
-
|
203 |
-
|
204 |
-
|
205 |
-
|
206 |
-
|
207 |
|
208 |
-
|
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 |
-
|
222 |
-
|
223 |
-
|
224 |
-
|
225 |
-
|
226 |
-
|
227 |
-
|
228 |
-
|
229 |
-
|
230 |
-
|
231 |
-
|
232 |
-
|
233 |
-
|
234 |
-
|
235 |
-
|
236 |
-
|
237 |
-
|
238 |
-
|
239 |
-
|
240 |
-
|
241 |
-
|
242 |
-
|
243 |
-
|
244 |
-
|
245 |
-
|
246 |
-
|
247 |
-
|
248 |
-
|
249 |
-
|
250 |
-
|
251 |
-
|
252 |
-
|
253 |
-
|
254 |
-
|
255 |
-
|
256 |
-
|
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 |
-
|
269 |
-
{
|
270 |
|
271 |
-
|
272 |
-
}
|
273 |
|
274 |
-
|
275 |
-
|
276 |
-
|
277 |
|
278 |
-
|
279 |
-
|
280 |
-
}
|
281 |
|
282 |
-
|
283 |
|
284 |
-
|
285 |
-
|
286 |
-
|
287 |
-
|
288 |
|
289 |
-
|
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 |
-
|
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 |
*/
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|