myCRED - Version 2.4

Version Description

New features and Bug fixes.

Download this release

Release Info

Developer wpexpertsio
Plugin Icon 128x128 myCRED
Version 2.4
Comparing to
See all releases

Code changes from version 2.3.2 to 2.4

Files changed (96) hide show
  1. addons/badges/includes/mycred-badge-functions.php +1 -1
  2. addons/badges/includes/mycred-badge-object.php +1 -1
  3. addons/badges/myCRED-addon-badges.php +51 -30
  4. addons/buy-creds/includes/buycred-shortcodes.php +2 -1
  5. addons/coupons/assets/css/admin.css +70 -0
  6. addons/coupons/assets/js/admin.js +78 -0
  7. addons/coupons/includes/mycred-coupon-object.php +35 -0
  8. addons/coupons/myCRED-addon-coupons.php +299 -5
  9. addons/email-notices/myCRED-addon-email-notices.php +11 -4
  10. addons/ranks/myCRED-addon-ranks.php +3 -0
  11. assets/css/admin.css +0 -146
  12. assets/css/mycred-admin.css +38 -0
  13. assets/css/mycred-front.css +257 -1
  14. assets/images/treasures/badges.jpg +0 -0
  15. assets/images/treasures/currency.jpg +0 -0
  16. assets/images/treasures/fitness.jpg +0 -0
  17. assets/images/treasures/gems.jpg +0 -0
  18. assets/images/treasures/learning.jpg +0 -0
  19. assets/images/treasures/rank.jpg +0 -0
  20. assets/js/accordion.js +0 -14
  21. assets/js/mycred-tools.js +419 -135
  22. assets/screenshot-6.png +0 -0
  23. includes/classes/class.query-leaderboard.php +29 -8
  24. includes/classes/class.query-log.php +1 -1
  25. includes/hooks/external/mycred-hook-affiliatewp.php +1 -0
  26. includes/hooks/mycred-hook-referrals.php +16 -0
  27. includes/hooks/mycred-hook-watching-video.php +3 -3
  28. includes/mycred-blocks/blocks/mycred-affiliate-id/index.js +53 -0
  29. includes/mycred-blocks/blocks/mycred-affiliate-id/mycred-affiliate-id.php +24 -0
  30. includes/mycred-blocks/blocks/mycred-affiliate-link/index.js +67 -0
  31. includes/mycred-blocks/blocks/mycred-affiliate-link/mycred-affiliate-link.php +21 -0
  32. includes/mycred-blocks/blocks/mycred-badges/index.js +58 -0
  33. includes/mycred-blocks/blocks/mycred-badges/mycred-badges.php +17 -0
  34. includes/mycred-blocks/blocks/mycred-best-user/index.js +151 -0
  35. includes/mycred-blocks/blocks/mycred-best-user/mycred-best-user.php +23 -0
  36. includes/mycred-blocks/blocks/mycred-buy-form/index.js +132 -0
  37. includes/mycred-blocks/blocks/mycred-buy-form/mycred-buy-form.php +18 -0
  38. includes/mycred-blocks/blocks/mycred-buy/index.js +142 -0
  39. includes/mycred-blocks/blocks/mycred-buy/mycred-buy.php +36 -0
  40. includes/mycred-blocks/blocks/mycred-email-subsc/index.js +41 -0
  41. includes/mycred-blocks/blocks/mycred-email-subsc/mycred-email-subsc.php +18 -0
  42. includes/mycred-blocks/blocks/mycred-exchange/index.js +108 -0
  43. includes/mycred-blocks/blocks/mycred-exchange/mycred-exchange.php +18 -0
  44. includes/mycred-blocks/blocks/mycred-give/index.js +135 -0
  45. includes/mycred-blocks/blocks/mycred-give/mycred-give.php +26 -0
  46. includes/mycred-blocks/blocks/mycred-history/index.js +198 -0
  47. includes/mycred-blocks/blocks/mycred-history/mycred-history.php +22 -0
  48. includes/mycred-blocks/blocks/mycred-hook-table/index.js +134 -0
  49. includes/mycred-blocks/blocks/mycred-hook-table/mycred-hook-table.php +21 -0
  50. includes/mycred-blocks/blocks/mycred-leaderboard/index.js +212 -0
  51. includes/mycred-blocks/blocks/mycred-leaderboard/mycred-leaderboard.php +21 -0
  52. includes/mycred-blocks/blocks/mycred-link/index.js +229 -0
  53. includes/mycred-blocks/blocks/mycred-link/mycred-link.php +30 -0
  54. includes/mycred-blocks/blocks/mycred-list-ranks/index.js +80 -0
  55. includes/mycred-blocks/blocks/mycred-list-ranks/mycred-list-ranks.php +22 -0
  56. includes/mycred-blocks/blocks/mycred-load-coupon/index.js +72 -0
  57. includes/mycred-blocks/blocks/mycred-load-coupon/mycred-load-coupon.php +18 -0
  58. includes/mycred-blocks/blocks/mycred-my-badges/index.js +91 -0
  59. includes/mycred-blocks/blocks/mycred-my-badges/mycred-my-badges.php +17 -0
  60. includes/mycred-blocks/blocks/mycred-my-balance-converted/index.js +93 -0
  61. includes/mycred-blocks/blocks/mycred-my-balance-converted/mycred-my-balance-converted.php +19 -0
  62. includes/mycred-blocks/blocks/mycred-my-balance/index.js +147 -0
  63. includes/mycred-blocks/blocks/mycred-my-balance/mycred-my-balance.php +28 -0
  64. includes/mycred-blocks/blocks/mycred-my-rank/index.js +125 -0
  65. includes/mycred-blocks/blocks/mycred-my-rank/mycred-my-rank.php +22 -0
  66. includes/mycred-blocks/blocks/mycred-my-ranks/index.js +106 -0
  67. includes/mycred-blocks/blocks/mycred-my-ranks/mycred-my-ranks.php +22 -0
  68. includes/mycred-blocks/blocks/mycred-total-balance/index.js +84 -0
  69. includes/mycred-blocks/blocks/mycred-total-balance/mycred-total-balance.php +21 -0
  70. includes/mycred-blocks/blocks/mycred-total-pts/index.js +104 -0
  71. includes/mycred-blocks/blocks/mycred-total-pts/mycred-total-pts.php +22 -0
  72. includes/mycred-blocks/blocks/mycred-total-since/index.js +118 -0
  73. includes/mycred-blocks/blocks/mycred-total-since/mycred-total-since.php +22 -0
  74. includes/mycred-blocks/blocks/mycred-transfer/index.js +199 -0
  75. includes/mycred-blocks/blocks/mycred-transfer/mycred-transfer.php +17 -0
  76. includes/mycred-blocks/blocks/mycred-users-of-all-ranks/index.js +135 -0
  77. includes/mycred-blocks/blocks/mycred-users-of-all-ranks/mycred-users-of-all-ranks.php +22 -0
  78. includes/mycred-blocks/blocks/mycred-users-of-rank/index.js +152 -0
  79. includes/mycred-blocks/blocks/mycred-users-of-rank/mycred-users-of-rank.php +22 -0
  80. includes/mycred-blocks/blocks/mycred-video/index.js +136 -0
  81. includes/mycred-blocks/blocks/mycred-video/mycred-video.php +22 -0
  82. includes/mycred-blocks/includes/mycred-gutenberg-functions.php +29 -0
  83. includes/mycred-blocks/mycred-blocks.php +120 -0
  84. includes/mycred-functions.php +27 -0
  85. includes/mycred-network.php +0 -243
  86. includes/mycred-remote.php +17 -37
  87. includes/mycred-tools-import-export.php +1246 -0
  88. includes/mycred-tools-setup-import-export.php +629 -0
  89. includes/mycred-tools.php +22 -7
  90. includes/shortcodes/mycred_referal_stats.php +0 -51
  91. includes/shortcodes/mycred_video.php +2 -1
  92. includes/widgets/mycred-widget-leaderboard.php +59 -17
  93. modules/mycred-module-buddypress.php +1 -1
  94. modules/mycred-module-log.php +5 -1
  95. mycred.php +15 -8
  96. readme.txt +40 -4
addons/badges/includes/mycred-badge-functions.php CHANGED
@@ -611,7 +611,7 @@ if ( ! function_exists( 'mycred_get_users_badges' ) ) :
611
  }
612
 
613
  }
614
-
615
  $clean_ids = array();
616
  if ( ! empty( $badge_ids ) ) {
617
  foreach ( $badge_ids as $id => $level ) {
611
  }
612
 
613
  }
614
+
615
  $clean_ids = array();
616
  if ( ! empty( $badge_ids ) ) {
617
  foreach ( $badge_ids as $id => $level ) {
addons/badges/includes/mycred-badge-object.php CHANGED
@@ -819,4 +819,4 @@ if ( ! class_exists( 'myCRED_Badge' ) ) :
819
  }
820
 
821
  }
822
- endif;
819
  }
820
 
821
  }
822
+ endif;
addons/badges/myCRED-addon-badges.php CHANGED
@@ -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 top-right-corner remove-badge-level" data-level="' . $level . '">' . esc_js( __( 'Remove Level', 'mycred' ) ) . '</button>';
1110
 
1111
  $level_image = $this->get_level_image( $setup, $level );
1112
  $empty_level = 'empty dashicons';
@@ -1117,9 +1117,13 @@ th#badge-users { width: 10%; }
1117
 
1118
  $template = str_replace( '{{level}}', $level, $template );
1119
  $template = str_replace( '{{addlevelbutton}}', $add_level, $template );
1120
- $template = str_replace( '{{removelevelbutton}}', $remove_level, $template );
1121
 
1122
  $js_level = str_replace( '{{removelevelbutton}}', $remove_level, $js_level );
 
 
 
 
 
1123
  $js_level = str_replace( '{{emptylevelimage}}', $empty_level, $js_level );
1124
  $js_level = str_replace( '{{levelimage}}', '', $js_level );
1125
  $js_level = str_replace( '{{levelimagebutton}}', esc_js( __( 'Set Image', 'mycred' ) ), $js_level );
@@ -1267,7 +1271,7 @@ th#badge-users { width: 10%; }
1267
 
1268
  $template = str_replace( '{{rewards}}', $rewards, $template );
1269
 
1270
- $rewards = str_replace( $level, '{{level}}', $rewards );
1271
 
1272
  $js_level = str_replace( '{{rewards}}', $rewards, $js_level );
1273
 
@@ -1677,16 +1681,17 @@ th#badge-users { width: 10%; }
1677
  */
1678
  public function badge_user_screen( $user ) {
1679
 
1680
- // Only visible to admins
1681
- if ( ! mycred_is_admin() ) return;
1682
-
1683
  $user_id = $user->ID;
1684
  $all_badges = mycred_get_badge_ids();
1685
  $users_badges = mycred_get_users_badges( $user_id );
1686
 
 
 
 
1687
  ?>
1688
  <style type="text/css">
1689
  .badge-wrapper { min-height: 230px; }
 
1690
  .badge-wrapper select { width: 100%; }
1691
  .badge-image-wrap { text-align: center; }
1692
  .badge-image-wrap .badge-image { display: block; width: 100%; height: 100px; line-height: 100px; }
@@ -1709,6 +1714,7 @@ th#badge-users { width: 10%; }
1709
  $earned = 0;
1710
  $earned_level = 0;
1711
  $badge_image = $badge->main_image;
 
1712
 
1713
  if ( array_key_exists( $badge_id, $users_badges ) ) {
1714
  $earned = 1;
@@ -1716,44 +1722,59 @@ th#badge-users { width: 10%; }
1716
  $badge_image = $badge->get_image( $earned_level );
1717
  }
1718
 
1719
- $level_select = '<input type="hidden" name="mycred_badge_manual[badges][' . $badge_id . '][level]" value="0" /><select disabled="disabled"><option>Level 1</option></select>';
1720
- if ( count( $badge->levels ) > 1 ) {
 
 
1721
 
1722
- $level_select = '<select name="mycred_badge_manual[badges][' . $badge_id . '][level]">';
1723
- $level_select .= '<option value=""';
1724
- if ( ! $earned ) $level_select .= ' selected="selected"';
1725
- $level_select .= '>' . __( 'Select a level', 'mycred' ) . '</option>';
 
 
 
 
 
 
 
 
1726
 
1727
- foreach ( $badge->levels as $level_id => $level ) {
1728
- $level_select .= '<option value="' . $level_id . '"';
1729
- if ( $earned && $earned_level == $level_id ) $level_select .= ' selected="selected"';
1730
- $level_select .= '>' . ( ( $level['label'] != '' ) ? $level['label'] : sprintf( '%s %d', __( 'Level', 'mycred' ), ( $level_id + 1 ) ) ) . '</option>';
1731
  }
1732
 
1733
- $level_select .= '</select>';
 
 
 
 
 
1734
 
1735
  }
1736
 
1737
  ?>
1738
- <div class="badge-wrapper color-option<?php if ( $earned === 1 ) echo ' selected'; ?>" id="mycred-badge<?php echo $badge_id; ?>-wrapper">
1739
- <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 _e( 'Earned', 'mycred' ); ?></label>
1740
- <div class="badge-image-wrap">
 
 
 
1741
 
1742
- <div class="badge-image<?php if ( $badge_image == '' ) echo ' empty'; ?>"><?php echo $badge_image; ?></div>
1743
 
1744
- <h4><?php echo $badge->title; ?></h4>
1745
- </div>
1746
- <div class="badge-actions" style="min-height: 32px;">
1747
 
1748
- <?php echo $level_select; ?>
1749
 
1750
- </div>
1751
 
1752
- <?php if ( $badge->open_badge && array_key_exists( $badge_id, $users_badges ) ):?>
1753
- <div class="badge-image-wrap">
1754
- <a href="<?php echo $badge->get_earned_image( $user_id ); ?> " class="button button-primary button-large mycred-open-badge-download" download>Download</a>
 
 
1755
  </div>
1756
- <?php endif; ?>
1757
  </div>
1758
  <?php
1759
 
1106
  $level = $level_counter;
1107
 
1108
  $add_level = '<button type="button" class="button button-seconary button-small top-right-corner" id="badges-add-new-level">' . esc_js( __( 'Add Level', 'mycred' ) ) . '</button>';
1109
+ $remove_level = '<button type="button" class="button button-seconary button-small top-right-corner remove-badge-level" data-level="{{level}}">' . esc_js( __( 'Remove Level', 'mycred' ) ) . '</button>';
1110
 
1111
  $level_image = $this->get_level_image( $setup, $level );
1112
  $empty_level = 'empty dashicons';
1117
 
1118
  $template = str_replace( '{{level}}', $level, $template );
1119
  $template = str_replace( '{{addlevelbutton}}', $add_level, $template );
 
1120
 
1121
  $js_level = str_replace( '{{removelevelbutton}}', $remove_level, $js_level );
1122
+
1123
+ $remove_level = str_replace( '{{level}}', $level, $remove_level );
1124
+
1125
+ $template = str_replace( '{{removelevelbutton}}', $remove_level, $template );
1126
+
1127
  $js_level = str_replace( '{{emptylevelimage}}', $empty_level, $js_level );
1128
  $js_level = str_replace( '{{levelimage}}', '', $js_level );
1129
  $js_level = str_replace( '{{levelimagebutton}}', esc_js( __( 'Set Image', 'mycred' ) ), $js_level );
1271
 
1272
  $template = str_replace( '{{rewards}}', $rewards, $template );
1273
 
1274
+ $rewards = str_replace( $level, '{{level}}', $rewards );
1275
 
1276
  $js_level = str_replace( '{{rewards}}', $rewards, $js_level );
1277
 
1681
  */
1682
  public function badge_user_screen( $user ) {
1683
 
 
 
 
1684
  $user_id = $user->ID;
1685
  $all_badges = mycred_get_badge_ids();
1686
  $users_badges = mycred_get_users_badges( $user_id );
1687
 
1688
+ if ( ! mycred_is_admin() )
1689
+ $all_badges = array_keys( $users_badges );
1690
+
1691
  ?>
1692
  <style type="text/css">
1693
  .badge-wrapper { min-height: 230px; }
1694
+ .badge-wrapper-center { display: inline-flex; justify-content: center; align-items: center; }
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; }
1714
  $earned = 0;
1715
  $earned_level = 0;
1716
  $badge_image = $badge->main_image;
1717
+ $level_select = '';
1718
 
1719
  if ( array_key_exists( $badge_id, $users_badges ) ) {
1720
  $earned = 1;
1722
  $badge_image = $badge->get_image( $earned_level );
1723
  }
1724
 
1725
+ if ( mycred_is_admin() ) {
1726
+
1727
+ $level_select = '<input type="hidden" name="mycred_badge_manual[badges][' . $badge_id . '][level]" value="0" /><select disabled="disabled"><option>Level 1</option></select>';
1728
+ if ( count( $badge->levels ) > 1 ) {
1729
 
1730
+ $level_select = '<select name="mycred_badge_manual[badges][' . $badge_id . '][level]">';
1731
+ $level_select .= '<option value=""';
1732
+ if ( ! $earned ) $level_select .= ' selected="selected"';
1733
+ $level_select .= '>' . __( 'Select a level', 'mycred' ) . '</option>';
1734
+
1735
+ foreach ( $badge->levels as $level_id => $level ) {
1736
+ $level_select .= '<option value="' . $level_id . '"';
1737
+ if ( $earned && $earned_level == $level_id ) $level_select .= ' selected="selected"';
1738
+ $level_select .= '>' . ( ( $level['label'] != '' ) ? $level['label'] : sprintf( '%s %d', __( 'Level', 'mycred' ), ( $level_id + 1 ) ) ) . '</option>';
1739
+ }
1740
+
1741
+ $level_select .= '</select>';
1742
 
 
 
 
 
1743
  }
1744
 
1745
+ }
1746
+ else {
1747
+
1748
+ if ( ! empty( $badge->levels[ $earned_level ]['label'] ) ) {
1749
+ $level_select = $badge->levels[ $earned_level ]['label'];
1750
+ }
1751
 
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 _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 $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
 
1772
+ <?php if ( $badge->open_badge && array_key_exists( $badge_id, $users_badges ) ):?>
1773
+ <div class="badge-image-wrap">
1774
+ <a href="<?php echo $badge->get_earned_image( $user_id ); ?> " class="button button-primary button-large mycred-open-badge-download" download>Download</a>
1775
+ </div>
1776
+ <?php endif; ?>
1777
  </div>
 
1778
  </div>
1779
  <?php
1780
 
addons/buy-creds/includes/buycred-shortcodes.php CHANGED
@@ -91,6 +91,7 @@ endif;
91
  * Shortcode: mycred_buy_form
92
  * @see http://codex.mycred.me/shortcodes/mycred_buy_form/
93
  * @since 1.0
 
94
  * @version 1.3
95
  */
96
  if ( ! function_exists( 'mycred_render_buy_form_points' ) ) :
@@ -326,7 +327,7 @@ if ( ! function_exists( 'mycred_render_buy_form_points' ) ) :
326
  </div>
327
 
328
  <div class="form-group">
329
- <input type="submit" class="button btn btn-block btn-lg" value="<?php echo $button_label; ?>" />
330
  </div>
331
 
332
  </form>
91
  * Shortcode: mycred_buy_form
92
  * @see http://codex.mycred.me/shortcodes/mycred_buy_form/
93
  * @since 1.0
94
+ * @since 2.4 Submit button input changed with button to add compatibility with modern UI.
95
  * @version 1.3
96
  */
97
  if ( ! function_exists( 'mycred_render_buy_form_points' ) ) :
327
  </div>
328
 
329
  <div class="form-group">
330
+ <button class="button btn btn-block btn-lg" ><?php echo $button_label; ?></button>
331
  </div>
332
 
333
  </form>
addons/coupons/assets/css/admin.css ADDED
@@ -0,0 +1,70 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ .mycred-border{
2
+ border: 1px solid #e9e9e9;
3
+ padding: 0 1em;
4
+ margin: 0 0 .8em;
5
+ }
6
+ .mycred-select-coupon-reward{
7
+ display: inline-block;
8
+ margin-left: 15px;
9
+ }
10
+ .mycred-select-coupon-rewards{
11
+ width: 113px;
12
+ }
13
+ .mycred-coupon-form{
14
+ padding: 15px 10px;
15
+ }
16
+ .mycred-title{
17
+ border-bottom: 1px solid #e9e9e9;
18
+ background-color: #fafafa;
19
+ min-height: 1.5em;
20
+ margin-bottom: 20px;
21
+ }
22
+ .show-badges {
23
+ display: block !important;
24
+ /*border-top: 1px solid #e9e9e9;*/
25
+ margin-bottom: 10px;
26
+ margin-top: 11px;
27
+ }
28
+ .show-ranks {
29
+ display: block !important;
30
+ /*border-top: 1px solid #e9e9e9;*/
31
+ margin-bottom: 10px;
32
+ margin-top: 11px;
33
+ }
34
+ .mycred-select-coupon {
35
+ display: inline-block;
36
+ margin-left: 67px;
37
+ margin-top: 10px;
38
+ }
39
+ .mycred-select-ids {
40
+ width: 113px;
41
+ }
42
+ .mycred-select-coupon-ranks {
43
+ display: inline-block;
44
+ margin-left: 76px;
45
+ margin-top: 10px;
46
+ }
47
+ .mycred-select-ranks {
48
+ width: 113px;
49
+ text-align: center;
50
+ }
51
+ .close-button{
52
+ cursor: pointer;
53
+ color: #a00;
54
+ opacity: 1;
55
+ -webkit-appearance: none!important;
56
+ background: 0 0!important;
57
+ border: none!important;
58
+ position: relative;
59
+ top: 0.87em;
60
+ line-height: 3em;
61
+ display: inline-block;"
62
+ }
63
+ .close-button:hover {
64
+ color: deeppink !important;
65
+ /*color: white;*/
66
+ }
67
+ .mycred-rank-msg{
68
+ color: #aaa;
69
+ font-style: italic;
70
+ }
addons/coupons/assets/js/admin.js ADDED
@@ -0,0 +1,78 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ jQuery(document).ready(function (){
2
+
3
+ var $ = jQuery;
4
+
5
+ $(document).on( 'click', '.mycred-addmore-button', function(event) {
6
+
7
+ $(this).closest('.form').find('.mycred-border').last().after( mycred_coupon_object.html );
8
+
9
+ });
10
+
11
+ jQuery(document).on('click', '#mycred-check', function(){
12
+ if ($(this).prop("checked") == true) {
13
+ $(".mycred-coupon-form").slideDown();
14
+ } else {
15
+ $(".mycred-coupon-form").slideUp();
16
+
17
+ }
18
+ });
19
+
20
+ $(document).on( 'click', '.close-button', function() {
21
+ var container = $(this).closest('.form');
22
+ if ( container.find('.mycred-border').length > 1 ) {
23
+ var dialog = confirm("Are you sure you want to remove this step?");
24
+ if (dialog == true) {
25
+ $(this).closest('.mycred-border').remove();
26
+ }
27
+ }
28
+ });
29
+
30
+
31
+ $( document ).on('change', '.mycred-select-coupon-rewards', function() {
32
+
33
+ var _this = jQuery(this);
34
+ var value = _this.val();
35
+
36
+ $.post(
37
+ ajaxurl,
38
+ {
39
+ action: 'mycred_change_dropdown',
40
+ value: value
41
+ },function( response ) {
42
+ response = JSON.parse( response );
43
+
44
+ var container = _this.closest('.form');
45
+ var selected = [];
46
+
47
+ if( value == 'mycred_coupon_badges' ){
48
+
49
+ var ele = _this.closest('.mycred-border').find( ".mycred-select-ids" ).attr( 'name', 'mycred_coupon[reward][ids][]' );
50
+ container.find('.mycred-select-ids').not(ele).each(function () {
51
+ selected.push( jQuery(this).val() );
52
+ });
53
+
54
+ }else{
55
+
56
+ var ele = _this.closest('.mycred-border').find( ".mycred-select-ids" ).attr( 'name', 'mycred_coupon[reward][ids][]' );
57
+ container.find('.mycred-select-ids').not(ele).each(function () {
58
+ selected.push( jQuery(this).val() );
59
+ });
60
+ }
61
+
62
+ ele.html('');
63
+ jQuery.each( response, function( index ){
64
+
65
+ ele.append( '<option value=' + response[index][0] + '>' + response[index][1] + '</option>' );
66
+
67
+ });
68
+ });
69
+
70
+ if( value == 'mycred_coupon_ranks'){
71
+ $(this).closest('.mycred-border').find( "#change-text" ).text( "Ranks: " );
72
+
73
+ }else{
74
+ $(this).closest('.mycred-border').find( "#change-text" ).text( "Badges :" );
75
+ }
76
+
77
+ });
78
+ })
addons/coupons/includes/mycred-coupon-object.php CHANGED
@@ -76,6 +76,16 @@ if ( ! class_exists( 'myCRED_Coupon' ) ) :
76
  */
77
  public $expires_unix = 0;
78
 
 
 
 
 
 
 
 
 
 
 
79
  /**
80
  * Construct
81
  */
@@ -135,6 +145,8 @@ if ( ! class_exists( 'myCRED_Coupon' ) ) :
135
  $this->requires_max_type = $this->requires_max['type'];
136
 
137
  $this->used = $this->get_usage_count();
 
 
138
 
139
  if ( ! mycred_point_type_exists( $this->point_type ) )
140
  $this->point_type = MYCRED_DEFAULT_TYPE_KEY;
@@ -306,6 +318,29 @@ if ( ! class_exists( 'myCRED_Coupon' ) ) :
306
  $this->point_type
307
  );
308
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
309
  do_action( 'mycred_use_coupon', $user_id, $this );
310
 
311
  // Increment global counter
76
  */
77
  public $expires_unix = 0;
78
 
79
+ /**
80
+ * Check badges/ranks
81
+ */
82
+ public $enabled_disabled = '';
83
+
84
+ /**
85
+ * Assign badges/ranks rewards
86
+ */
87
+ public $rewards = 0;
88
+
89
  /**
90
  * Construct
91
  */
145
  $this->requires_max_type = $this->requires_max['type'];
146
 
147
  $this->used = $this->get_usage_count();
148
+ $this->enabled_disabled = mycred_get_post_meta( $this->post_id, 'check', true );
149
+ $this->rewards = mycred_get_post_meta( $this->post_id, 'reward', true );
150
 
151
  if ( ! mycred_point_type_exists( $this->point_type ) )
152
  $this->point_type = MYCRED_DEFAULT_TYPE_KEY;
318
  $this->point_type
319
  );
320
 
321
+ $enabled_disabled = $this->enabled_disabled;
322
+ $rewards = $this->rewards;
323
+
324
+ if( $enabled_disabled == 'on' ) {
325
+
326
+ if( ! empty ( $rewards ) ) {
327
+
328
+ foreach ($rewards as $key => $value) {
329
+
330
+ if( class_exists( 'myCRED_Badge' ) && $value['types'] == 'mycred_coupon_badges' ) {
331
+ mycred_assign_badge_to_user( $user_id, $value['ids'] );
332
+
333
+ }
334
+
335
+ if( class_exists( 'myCRED_Ranks_Module' ) && $value['types'] == 'mycred_coupon_ranks' && mycred_manual_ranks( $this->point_type ) ) {
336
+ $ranks = new myCRED_Rank( $value['ids'] );
337
+ $ranks->assign($user_id);
338
+
339
+ }
340
+ }
341
+ }
342
+ }
343
+
344
  do_action( 'mycred_use_coupon', $user_id, $this );
345
 
346
  // Increment global counter
addons/coupons/myCRED-addon-coupons.php CHANGED
@@ -56,6 +56,7 @@ if ( ! class_exists( 'myCRED_Coupons_Module' ) ) :
56
 
57
  add_action( 'mycred_add_menu', array( $this, 'add_to_menu' ), $this->menu_pos );
58
  add_action( 'admin_notices', array( $this, 'warn_bad_expiration' ), $this->menu_pos );
 
59
 
60
  }
61
 
@@ -83,6 +84,9 @@ if ( ! class_exists( 'myCRED_Coupons_Module' ) ) :
83
  add_filter( 'bulk_actions-edit-' . MYCRED_COUPON_KEY, array( $this, 'bulk_actions' ) );
84
  add_action( 'save_post_' . MYCRED_COUPON_KEY, array( $this, 'save_coupon' ), 10, 2 );
85
 
 
 
 
86
  }
87
 
88
  /**
@@ -380,7 +384,7 @@ if ( ! class_exists( 'myCRED_Coupons_Module' ) ) :
380
 
381
  wp_enqueue_style( 'mycred-bootstrap-grid' );
382
  wp_enqueue_style( 'mycred-forms' );
383
-
384
  add_filter( 'postbox_classes_' . MYCRED_COUPON_KEY . '_mycred-coupon-setup', array( $this, 'metabox_classes' ) );
385
  add_filter( 'postbox_classes_' . MYCRED_COUPON_KEY . '_mycred-coupon-limits', array( $this, 'metabox_classes' ) );
386
  add_filter( 'postbox_classes_' . MYCRED_COUPON_KEY . '_mycred-coupon-requirements', array( $this, 'metabox_classes' ) );
@@ -395,7 +399,21 @@ if ( ! class_exists( 'myCRED_Coupons_Module' ) ) :
395
  * @since 1.7
396
  * @version 1.0
397
  */
398
- public function coupon_style() { }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
399
 
400
  /**
401
  * Add Meta Boxes
@@ -431,6 +449,17 @@ if ( ! class_exists( 'myCRED_Coupons_Module' ) ) :
431
  'core'
432
  );
433
 
 
 
 
 
 
 
 
 
 
 
 
434
  if ( $post->post_status == 'publish' )
435
  add_meta_box(
436
  'mycred-coupon-usage',
@@ -599,10 +628,254 @@ if ( ! class_exists( 'myCRED_Coupons_Module' ) ) :
599
  </div>
600
  </div>
601
  </div>
602
- <?php
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
603
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
604
  }
605
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
606
  /**
607
  * Metabox: Coupon Usage
608
  * @since 1.6
@@ -637,10 +910,31 @@ if ( ! class_exists( 'myCRED_Coupons_Module' ) ) :
637
  public function save_coupon( $post_id, $post = NULL ) {
638
 
639
  if ( $post === NULL || ! $this->core->user_is_point_editor() || ! isset( $_POST['mycred_coupon'] ) ) return $post_id;
 
 
 
 
640
 
641
  foreach ( $_POST['mycred_coupon'] as $meta_key => $meta_value ) {
642
 
643
- $new_value = sanitize_text_field( $meta_value );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
644
 
645
  // Make sure we provide a valid date that strtotime() can understand
646
  if ( $meta_key == 'expires' && $new_value != '' ) {
@@ -656,9 +950,9 @@ if ( ! class_exists( 'myCRED_Coupons_Module' ) ) :
656
 
657
  // No need to update if it's still the same value
658
  $old_value = mycred_get_post_meta( $post_id, $meta_key, true );
 
659
  if ( $new_value != $old_value )
660
  mycred_update_post_meta( $post_id, $meta_key, $new_value );
661
-
662
  }
663
 
664
  }
56
 
57
  add_action( 'mycred_add_menu', array( $this, 'add_to_menu' ), $this->menu_pos );
58
  add_action( 'admin_notices', array( $this, 'warn_bad_expiration' ), $this->menu_pos );
59
+ add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_admin_scripts' ) );
60
 
61
  }
62
 
84
  add_filter( 'bulk_actions-edit-' . MYCRED_COUPON_KEY, array( $this, 'bulk_actions' ) );
85
  add_action( 'save_post_' . MYCRED_COUPON_KEY, array( $this, 'save_coupon' ), 10, 2 );
86
 
87
+ //AJAX
88
+ add_action( 'wp_ajax_mycred_change_dropdown', array( $this, 'mycred_change_dropdown_ajax_handler' ) );
89
+
90
  }
91
 
92
  /**
384
 
385
  wp_enqueue_style( 'mycred-bootstrap-grid' );
386
  wp_enqueue_style( 'mycred-forms' );
387
+ wp_enqueue_style( MYCRED_SLUG . '-buttons' );
388
  add_filter( 'postbox_classes_' . MYCRED_COUPON_KEY . '_mycred-coupon-setup', array( $this, 'metabox_classes' ) );
389
  add_filter( 'postbox_classes_' . MYCRED_COUPON_KEY . '_mycred-coupon-limits', array( $this, 'metabox_classes' ) );
390
  add_filter( 'postbox_classes_' . MYCRED_COUPON_KEY . '_mycred-coupon-requirements', array( $this, 'metabox_classes' ) );
399
  * @since 1.7
400
  * @version 1.0
401
  */
402
+ public function coupon_style() {
403
+
404
+ }
405
+
406
+ /**
407
+ * Enqueue Admin Script
408
+ * @since 2.4
409
+ * @version 1.0
410
+ */
411
+ public function enqueue_admin_scripts() {
412
+
413
+ wp_register_style( 'mycred-coupon-badge-rank-style', plugins_url( 'assets/css/admin.css', myCRED_COUPONS ), '', myCRED_COUPONS_VERSION );
414
+ wp_register_script( 'mycred-coupon-badge-rank-js', plugins_url( 'assets/js/admin.js', myCRED_COUPONS ), array( 'jquery' ), myCRED_COUPONS_VERSION, true );
415
+
416
+ }
417
 
418
  /**
419
  * Add Meta Boxes
449
  'core'
450
  );
451
 
452
+ if( class_exists( 'myCRED_Badge' ) || class_exists( 'myCRED_Ranks_Module' ) ) {
453
+ add_meta_box(
454
+ 'mycred-coupon-badges-ranks',
455
+ __( 'Assign Badge/Ranks To Users', 'mycred' ),
456
+ array( $this, 'mycred_coupon_badges_ranks' ),
457
+ MYCRED_COUPON_KEY,
458
+ 'advanced',
459
+ 'core'
460
+ );
461
+ }
462
+
463
  if ( $post->post_status == 'publish' )
464
  add_meta_box(
465
  'mycred-coupon-usage',
628
  </div>
629
  </div>
630
  </div>
631
+ <?php
632
+
633
+ }
634
+
635
+ /**
636
+ * Metabox: Coupon Requirements for badge/ranks
637
+ * @since 2.4
638
+ * @version 1.0
639
+ */
640
+ public function mycred_coupon_badges_ranks( $post ) {
641
+
642
+ wp_enqueue_script( 'mycred-coupon-badge-rank-js' );
643
+ wp_enqueue_style( 'mycred-coupon-badge-rank-style' );
644
+ $types_ids = mycred_get_post_meta( $post->ID, 'reward' );
645
+ $check_enable_disable = mycred_get_post_meta( $post->ID, 'check', true );
646
+ $enable_disable = ! empty( $check_enable_disable );
647
+ $coupon = mycred_get_coupon( $post->ID );
648
+ $manual_rank = '';
649
+
650
+ if( class_exists( 'myCRED_Badge' ) ) {
651
+ $badge_id = mycred_get_badge_ids();
652
+ }
653
+ if( class_exists( 'myCRED_Ranks_Module' ) ){
654
+ $ranks = mycred_get_ranks();
655
+ $manual_rank = mycred_manual_ranks( $coupon->point_type );
656
+ }
657
+ ob_start(); ?>
658
+ <div class="mycred-border" >
659
+ <div class="row">
660
+ <div class="mycred-title"><button type="button" class="dashicons-before dashicons-no-alt close-button" ></button><?php
661
+ _e( 'Reward', 'mycred' ); ?>
662
+ </div>
663
+ <div class="col-lg-12 col-md-12 col-sm-12 col-xs-12">
664
+ <div class="form-group">
665
+ <label for="mycred-select-coupon-reward"><?php _e( 'Select Reward Type : ', 'mycred' ); ?></label>
666
+ <div class="mycred-select-coupon-reward" >
667
+ <select name="mycred_coupon[reward][types][]" class="mycred-select-coupon-rewards"><?php
668
+ if( class_exists( 'myCRED_Badge' ) && ( empty( $ranks ) || ! empty( $badge_id ) ) ){ ?>
669
+ <option value="mycred_coupon_badges" ><?php _e( 'Badges', 'mycred' ); ?></option>
670
+ <?php }
671
+ if( class_exists( 'myCRED_Ranks_Module' ) && $manual_rank && ( ! empty( $ranks ) || empty( $badge_id ) ) ) { ?>
672
+ <option value="mycred_coupon_ranks" ><?php _e( 'Ranks', 'mycred' ); ?></option>
673
+ <?php } ?>
674
+ </select>
675
+ </div>
676
+ </div>
677
+ </div>
678
+ </div>
679
+
680
+ <div class="row">
681
+ <div class="col-lg-12 col-md-12 col-sm-12 col-xs-12">
682
+ <div class="form-group">
683
+ <div class="ids show-badges" >
684
+ <label for="mycred-select-coupon" id="change-text"><?php echo class_exists( 'myCRED_Badge' ) && ( empty( $ranks ) || ! empty( $badge_id ) ) ? _e( 'Badges : ', 'mycred' ) : _e( 'Ranks : ', 'mycred' ); ?></label>
685
+ <div class="mycred-select-coupon"><?php
686
+ if( ! empty( $badge_id ) || ! empty( $ranks ) ){?>
687
+ <select name="mycred_coupon[reward][ids][]" class="mycred-select-ids"><?php
688
+ if( class_exists( 'myCRED_Badge' ) ) {
689
+ foreach ($badge_id as $key => $value) {
690
+ $badges = mycred_get_badge( $value );?>
691
+ <option value="<?php echo $value ?>" ><?php _e( $badges->title ) ?></option><?php
692
+ }
693
+ }
694
+ if( class_exists( 'myCRED_Ranks_Module' ) && empty($badge_id) ) {
695
+ foreach ( $ranks as $key => $value ) { ?>
696
+ <option value="<?php echo $value->post_id ?>"><?php _e( $value->post->post_title ) ?></option><?php
697
+ }
698
+ }?>
699
+ </select><?php
700
+ } ?>
701
+ </div>
702
+ </div>
703
+ </div>
704
+ </div>
705
+ </div>
706
+ </div>
707
+
708
+ <?php $html = ob_get_clean(); ?>
709
+
710
+ <div class="mycred-badge-rank-hide-show">
711
+ <div class="mycred-switch">
712
+ <label><strong><?php _e( 'Enable this to assign badge/ranks through coupon.', 'mycred' ); ?></strong></label>
713
+ <label class="mycred-switch1">
714
+ <input type="checkbox" id="mycred-check" name="mycred_coupon[check]" <?php echo $enable_disable == true ? 'checked' : ''; ?>>
715
+ <span class="slider round"></span>
716
+ </label>
717
+ </div>
718
+ </div>
719
+ <div class="form mycred-coupon-form" <?php echo $enable_disable == true ? 'style="display: block;"' : 'style="display: none;"' ?> >
720
+ <label class="mycred-rank-msg">
721
+ <strong><?php _e( 'You can only assign Ranks when Ranks are set to Manual Mode.: ', 'mycred' ); ?></strong>
722
+ </label><?php
723
+
724
+ if( ! empty( $types_ids ) ){
725
+ foreach ( $types_ids[0] as $keys => $values ) {
726
+ echo $this->mycred_coupon_badge_rank_html( $values['types'], $values['ids'], $manual_rank );
727
+ }
728
+ }else {
729
+ echo $html;
730
+ }?>
731
+
732
+ <div><button type="button" class="mycred-addmore-button button-secondary">Add More</button></div>
733
+ </div><?php
734
+
735
+ wp_localize_script( 'mycred-coupon-badge-rank-js', 'mycred_coupon_object',
736
+ array(
737
+ 'html' => $html,
738
+ )
739
+ );
740
+ }
741
+
742
+ public function mycred_coupon_badge_rank_html( $types, $ids, $manual_rank ){
743
+
744
+ $selected_type = '';
745
+
746
+ if( class_exists( 'myCRED_Badge' ) ) {
747
+ $badge_id = mycred_get_badge_ids();
748
+ }
749
+ if( class_exists( 'myCRED_Ranks_Module' ) ){
750
+ $ranks = mycred_get_ranks();
751
+ }
752
+
753
+ ?>
754
+
755
+ <div class="mycred-border" >
756
+ <div class="row">
757
+ <div class="mycred-title"><button type="button" class="dashicons-before dashicons-no-alt close-button" ></button><?php
758
+ _e( 'Reward', 'mycred' ); ?>
759
+ </div>
760
+ <div class="col-lg-12 col-md-12 col-sm-12 col-xs-12">
761
+ <div class="form-group">
762
+ <label for="mycred-select-coupon-reward"><?php _e( 'Select Reward Type : ', 'mycred' ); ?></label>
763
+ <div class="mycred-select-coupon-reward">
764
+ <select name="mycred_coupon[reward][types][]" class="mycred-select-coupon-rewards"><?php
765
+
766
+ if ( class_exists( 'myCRED_Badge' ) ) {
767
+
768
+ if ( $types == 'mycred_coupon_badges' ) $selected_type = 'badge';
769
+
770
+ ?>
771
+ <option value="mycred_coupon_badges" <?php echo $types == 'mycred_coupon_badges' ? 'selected="selected"' : ''; ?>><?php _e( 'Badges', 'mycred' ); ?></option>
772
+ <?php }
773
+ else {
774
+ if ( $types == 'mycred_coupon_badges' && class_exists( 'myCRED_Ranks_Module' ) && $manual_rank ) $selected_type = 'rank';
775
+ }
776
+ if( class_exists( 'myCRED_Ranks_Module' ) && $manual_rank ) {
777
+
778
+ if ( $types == 'mycred_coupon_ranks' ) $selected_type = 'rank';
779
+ ?>
780
+ <option value="mycred_coupon_ranks" <?php echo $types == 'mycred_coupon_ranks' ? 'selected="selected"' : ''; ?>><?php _e( 'Ranks', 'mycred' ); ?></option>
781
+ <?php }
782
+ else{
783
+ if ( $types == 'mycred_coupon_ranks' && class_exists( 'myCRED_Badge' ) ) $selected_type = 'badge';
784
+ } ?>
785
+
786
+
787
+ </select>
788
+ </div>
789
+ </div>
790
+ </div>
791
+
792
+ </div>
793
 
794
+ <div class="row">
795
+ <div class="col-lg-12 col-md-12 col-sm-12 col-xs-12">
796
+ <div class="form-group">
797
+ <div class="ids show-badges" >
798
+ <label for="mycred-select-coupon" id="change-text"><?php ( ! empty( $badge_id ) && $types == 'mycred_coupon_badges' ) ? _e( 'Badges : ', 'mycred' ) : _e( 'Ranks : ', 'mycred' ); ?></label>
799
+ <div class="mycred-select-coupon"><?php
800
+
801
+ if( ! empty( $badge_id ) || ! empty( $ranks ) ){?>
802
+
803
+ <select name="mycred_coupon[reward][ids][]" class="mycred-select-ids"><?php
804
+
805
+ if( $selected_type == 'badge' ){
806
+ foreach ($badge_id as $key => $value) {
807
+ $badges = mycred_get_badge( $value );?>
808
+ <option value="<?php echo $value ?>" <?php echo $ids == $value ? 'selected="selected"' : ''; ?>><?php _e( $badges->title ) ?></option><?php
809
+ }
810
+ }elseif( $selected_type == 'rank' ) {
811
+
812
+ foreach ( $ranks as $key => $value ) { ?>
813
+ <option value="<?php echo $value->post_id ?>" <?php echo $ids == $value->post_id ? 'selected="selected"' : ''; ?>><?php _e( $value->post->post_title ) ?></option><?php
814
+ }
815
+ }
816
+ ?>
817
+
818
+ </select><?php
819
+
820
+ }?>
821
+
822
+ </div>
823
+ </div>
824
+ </div>
825
+ </div>
826
+ </div>
827
+ </div><?php
828
  }
829
 
830
+
831
+ public function mycred_change_dropdown_ajax_handler() {
832
+
833
+ $value = sanitize_text_field( $_POST['value'] );
834
+
835
+ if( class_exists( 'myCRED_Badge' ) ) {
836
+ $badge_id = mycred_get_badge_ids();
837
+ }
838
+ if( class_exists( 'myCRED_Ranks_Module' ) ){
839
+ $ranks = mycred_get_ranks();
840
+ }
841
+
842
+ if ( $value == 'mycred_coupon_badges' ){
843
+
844
+ $ids_title = array();
845
+ foreach ($badge_id as $key => $value) {
846
+
847
+ $badges = mycred_get_badge( $value );
848
+ $badge_title = $badges->title;
849
+ $badge_id = $value;
850
+ $ids_title[] = array( $badge_id, $badge_title );
851
+
852
+ }
853
+
854
+ $ids_title = json_encode( $ids_title );
855
+
856
+ echo $ids_title;
857
+ wp_die();
858
+ }
859
+
860
+ if ( $value == 'mycred_coupon_ranks' ){
861
+
862
+ $ids_title = array();
863
+ foreach ($ranks as $key => $value) {
864
+
865
+ $rank_title = $value->post->post_title;
866
+ $rank_id = $value->post_id;
867
+ $ids_title[] = array( $rank_id, $rank_title );
868
+
869
+ }
870
+
871
+ $ids_title = json_encode( $ids_title );
872
+
873
+ echo $ids_title;
874
+ wp_die();
875
+ }
876
+
877
+ }
878
+
879
  /**
880
  * Metabox: Coupon Usage
881
  * @since 1.6
910
  public function save_coupon( $post_id, $post = NULL ) {
911
 
912
  if ( $post === NULL || ! $this->core->user_is_point_editor() || ! isset( $_POST['mycred_coupon'] ) ) return $post_id;
913
+
914
+ if( ! isset( $_POST['mycred_coupon']['check'] ) ){
915
+ $_POST['mycred_coupon']['check'] = false;
916
+ }
917
 
918
  foreach ( $_POST['mycred_coupon'] as $meta_key => $meta_value ) {
919
 
920
+ if( $meta_key == 'reward' ){
921
+
922
+ $types_ids = array();
923
+ foreach ($meta_value['types'] as $key => $value) {
924
+
925
+ $reward_value = sanitize_text_field( $value );
926
+ $reward_id = sanitize_text_field( $meta_value['ids'][$key] );
927
+
928
+ $types_ids[] = array( 'types' => $reward_value , 'ids' => $reward_id ) ;
929
+
930
+ }
931
+
932
+ $new_value = $types_ids;
933
+ }
934
+ else{
935
+
936
+ $new_value = sanitize_text_field( $meta_value );
937
+ }
938
 
939
  // Make sure we provide a valid date that strtotime() can understand
940
  if ( $meta_key == 'expires' && $new_value != '' ) {
950
 
951
  // No need to update if it's still the same value
952
  $old_value = mycred_get_post_meta( $post_id, $meta_key, true );
953
+
954
  if ( $new_value != $old_value )
955
  mycred_update_post_meta( $post_id, $meta_key, $new_value );
 
956
  }
957
 
958
  }
addons/email-notices/myCRED-addon-email-notices.php CHANGED
@@ -594,7 +594,7 @@ if ( ! class_exists( 'myCRED_Email_Notice_Module' ) ) :
594
  <div class="col-lg-12 col-md-12 col-sm-12 col-xs-12">
595
  <div class="form-group">
596
  <label for="mycred-email-instance"<?php if ( $post->post_status == 'publish' && empty( $trigger ) ) echo ' style="color:red;font-weight:bold;"'; ?>><?php _e( 'Send this email notice when...', 'mycred' ); ?></label>
597
- <select name="mycred_email[instance]" id="mycred-email-instance" class="form-control">
598
  <?php
599
 
600
  // Loop though instances
@@ -643,9 +643,14 @@ if ( ! class_exists( 'myCRED_Email_Notice_Module' ) ) :
643
  <label for="mycred-email-ctype"><?php _e( 'Point Types', 'mycred' ); ?></label>
644
  <?php
645
 
646
- if ( count( $this->point_types ) > 1 ) {
647
 
648
- mycred_types_select_from_checkboxes( 'mycred_email[ctype][]', 'mycred-email-ctype', $email->point_types );
 
 
 
 
 
649
 
650
  }
651
 
@@ -662,6 +667,7 @@ if ( ! class_exists( 'myCRED_Email_Notice_Module' ) ) :
662
  ?>
663
 
664
  </div>
 
665
  <hr />
666
 
667
  <div class="form-group" style="margin-bottom: 0;">
@@ -1000,7 +1006,8 @@ if ( ! class_exists( 'myCRED_Email_Notice_Module' ) ) :
1000
  // Save styling
1001
  if ( ! empty( $_POST['mycred_email']['styling'] ) )
1002
  mycred_update_post_meta( $post_id, 'mycred_email_styling', wp_kses_post( $_POST['mycred_email']['styling'] ) );
1003
-
 
1004
  }
1005
 
1006
  /**
594
  <div class="col-lg-12 col-md-12 col-sm-12 col-xs-12">
595
  <div class="form-group">
596
  <label for="mycred-email-instance"<?php if ( $post->post_status == 'publish' && empty( $trigger ) ) echo ' style="color:red;font-weight:bold;"'; ?>><?php _e( 'Send this email notice when...', 'mycred' ); ?></label>
597
+ <select name="mycred_email[instance]" id="mycred-email-instance" class="form-control mycred-email-instance-options">
598
  <?php
599
 
600
  // Loop though instances
643
  <label for="mycred-email-ctype"><?php _e( 'Point Types', 'mycred' ); ?></label>
644
  <?php
645
 
646
+
647
 
648
+ if ( count( $this->point_types ) > 1 ) {
649
+
650
+ $point_types_html = mycred_types_select_from_checkboxes( 'mycred_email[ctype][]', 'mycred-email-ctype', $email->point_types, true );
651
+
652
+
653
+ echo apply_filters( 'mycred_point_type_checkbox', $point_types_html );
654
 
655
  }
656
 
667
  ?>
668
 
669
  </div>
670
+ <?php do_action('mycred_after_email_triggers', $post); ?>
671
  <hr />
672
 
673
  <div class="form-group" style="margin-bottom: 0;">
1006
  // Save styling
1007
  if ( ! empty( $_POST['mycred_email']['styling'] ) )
1008
  mycred_update_post_meta( $post_id, 'mycred_email_styling', wp_kses_post( $_POST['mycred_email']['styling'] ) );
1009
+
1010
+ do_action( 'mycred_save_email_notice', $post_id );
1011
  }
1012
 
1013
  /**
addons/ranks/myCRED-addon-ranks.php CHANGED
@@ -1519,6 +1519,9 @@ if ( ! class_exists( 'myCRED_Ranks_Module' ) ) :
1519
 
1520
  if ( ! $this->is_manual_mode( $point_type ) )
1521
  mycred_assign_ranks( $point_type );
 
 
 
1522
 
1523
  }
1524
 
1519
 
1520
  if ( ! $this->is_manual_mode( $point_type ) )
1521
  mycred_assign_ranks( $point_type );
1522
+
1523
+ // Let others play
1524
+ do_action( 'mycred_save_rank', $post_id );
1525
 
1526
  }
1527
 
assets/css/admin.css DELETED
@@ -1,146 +0,0 @@
1
- /**
2
- * myCRED Admin Styling
3
- * @since 0.1
4
- * @version 1.3
5
- */
6
- #myCRED-wrap table .column-username { width: 190px; }
7
- #myCRED-wrap table .column-creds { width: 80px; }
8
- #myCRED-wrap table .column-time { width: 160px; }
9
- #myCRED-wrap table .column-actions { width: 160px; }
10
- #myCRED-wrap table .alternate { background-color: white; }
11
- #myCRED-wrap table tbody tr td { padding: 6px; }
12
- #myCRED-wrap table tr.deleted-row td { background-color: red !important; color: white !important; }
13
- #myCRED-wrap table tr.updated-row td { background-color: yellow; }
14
-
15
- /* Text Alignments */
16
- .tl { text-align: left; }
17
- .tc { text-align: center; }
18
- .tr { text-align: right; }
19
- .tj { text-align: justify; }
20
-
21
- /* Specifics */
22
- #myCRED-wrap p.submit { margin-top: 0; padding-top: 0; }
23
- #mycred-social { text-align: right; }
24
-
25
- /* General */
26
- #myCRED-wrap .h2 { font-family: "HelveticaNeue-Light","Helvetica Neue Light","Helvetica Neue",sans-serif; font-size: 22px; line-height: 29px; font-weight: normal; text-shadow: #fff 0 1px 0; }
27
- body.version-3-8 #myCRED-wrap .h2 { line-height: 15px; font-size: 18px; }
28
- body.version-3-8 #myCRED-wrap .h2.description { line-height: 22px; }
29
- body.version-3-8 #myCRED-wrap .h2 input[type="text"] { font-size: 14px; }
30
- #myCRED-wrap .h2 input[type="text"], #myCRED-wrap .h2 input[type="password"] { line-height: inherit; }
31
- #mycred-social-media { display: block; float: right; }
32
- #mycred-social-media a { margin-left: 12px; }
33
-
34
- /* Accordion */
35
- #myCRED-wrap #accordion { margin: 24px 0; padding: 0; float: none; clear: both; }
36
- body #myCRED-wrap #accordion { border-top: none; border-bottom: 1px solid #dedede; }
37
- body.version-3-8 #myCRED-wrap #accordion { border-top: 1px solid #dedede; border-bottom: 1px solid #fafafa; }
38
- #myCRED-wrap #accordion>h4 { font-size: 18px; line-height: 48px; font-weight: normal; color: #464646; font-family: "Open Sans", sans-serif; letter-spacing: 1px; }
39
- #myCRED-wrap #accordion>h4:focus { outline: none; }
40
- #myCRED-wrap #accordion>h4:hover { cursor: pointer; }
41
- #myCRED-wrap #accordion .ui-accordion-header { padding: 0; margin: 0; }
42
- body #myCRED-wrap #accordion .ui-accordion-header { border-top: 1px solid #dedede; border-bottom: none; }
43
- body.version-3-8 #myCRED-wrap #accordion .ui-accordion-header { border-top: 1px solid #fafafa; border-bottom: 1px solid #dedede; }
44
- #myCRED-wrap #accordion .ui-accordion-header input { vertical-align: middle; margin-right: 24px; }
45
- #myCRED-wrap #accordion .ui-state-active { font-weight: normal; }
46
-
47
- #myCRED-wrap #accordion h4 label { vertical-align: inherit; }
48
- #myCRED-wrap #accordion h4 .icon { display: block; width: 48px; height: 48px; margin: 0 0 0 0; padding: 0; float: left; line-height: 48px; }
49
- #myCRED-wrap #accordion h4 .icon { background-repeat: no-repeat; background-image: url(../images/admin-icons.png); background-position: 0 0; }
50
- #myCRED-wrap #accordion h4 .icon.icon-active { background-position: -48px 0; }
51
-
52
- #myCRED-wrap #accordion h4 .registration { background-position: 0 -48px; }
53
- #myCRED-wrap #accordion h4 .registration.icon-active { background-position: -48px -48px; }
54
-
55
- #myCRED-wrap #accordion h4 .logging_in { background-position: 0 -96px; }
56
- #myCRED-wrap #accordion h4 .logging_in.icon-active { background-position: -48px -96px; }
57
-
58
- #myCRED-wrap #accordion h4 .publishing_content { background-position: 0 -144px; }
59
- #myCRED-wrap #accordion h4 .publishing_content.icon-active { background-position: -48px -144px; }
60
-
61
- #myCRED-wrap #accordion h4 .comments { background-position: 0 -192px; }
62
- #myCRED-wrap #accordion h4 .comments.icon-active { background-position: -48px -192px; }
63
-
64
- #myCRED-wrap #accordion h4 .link_click { background-position: 0 -240px; }
65
- #myCRED-wrap #accordion h4 .link_click.icon-active { background-position: -48px -240px; }
66
-
67
- #myCRED-wrap #accordion h4 .video_view { background-position: 0 -288px; }
68
- #myCRED-wrap #accordion h4 .video_view.icon-active { background-position: -48px -288px; }
69
-
70
- #myCRED-wrap #accordion h4 .affiliate { background-position: 0 -336px; }
71
- #myCRED-wrap #accordion h4 .affiliate.icon-active { background-position: -48px -336px; }
72
-
73
- #myCRED-wrap #accordion h4 .remote { background-position: 0 -384px; }
74
- #myCRED-wrap #accordion h4 .remote.icon-active { background-position: -48px -384px; }
75
-
76
- #myCRED-wrap #accordion h4 .site_visit { background-position: 0 -432px; }
77
- #myCRED-wrap #accordion h4 .site_visit.icon-active { background-position: -48px -432px; }
78
-
79
- #myCRED-wrap #accordion h4 .single { background-position: 0 -480px; }
80
- #myCRED-wrap #accordion h4 .multi { background-position: -48px -480px; }
81
-
82
- #myCRED-wrap #accordion h4 .core { background-position: 0 -528px; }
83
- #myCRED-wrap #accordion h4 .core.icon-active { background-position: -48px -528px; }
84
-
85
- #myCRED-wrap #accordion>div { margin: 0; padding: 24px 48px 12px 48px; }
86
- #myCRED-wrap #accordion>div>p { margin-top: 0; }
87
- #myCRED-wrap #accordion .ui-accordion-content { display: none;float: none; clear: both; }
88
- body #myCRED-wrap #accordion .ui-accordion-content { border-top: 1px solid #dedede; border-bottom: none; }
89
- body.version-3-8 #myCRED-wrap #accordion .ui-accordion-content { border-top: 1px solid #fafafa; border-bottom: 1px solid #dedede; }
90
- #myCRED-wrap #accordion .ui-accordion-content .wrapper:after { content: "."; height: 0; visibility: hidden; margin: 0; padding: 0; }
91
-
92
- .ui-accordion-content>div.wrapper { display: block; margin: 0; padding: 0; float: none; clear: both; }
93
- .ui-accordion-content>div.wrapper .clear { height: 0; visibility: hidden; display: block; float: none; clear: both; }
94
- .ui-accordion-content>div.wrapper p { margin: 0; padding: 0; }
95
- .ui-accordion-content>div.wrapper .description { float: right; clear: left; color: gray; font-style: italic; font-weight: normal; width: 50%; text-align: left; }
96
- .ui-accordion-content>div.wrapper .links { margin-bottom: 6px; padding-bottom: 4px; }
97
- .ui-accordion-content>form>p { margin: 0 0 24px 0; }
98
-
99
- .ui-accordion-content .subheader { display: block; width: 20%; float: left; margin: 0; font-size: 14px; font-weight: bold; }
100
- .ui-accordion-content input[type="file"] { line-height: 26px; }
101
-
102
- /* Organized Lists */
103
- #myCRED-wrap ol { list-style-type: none; display: block; padding: 0 0 24px 20%; margin: 0; float: none; clear: right; }
104
- #myCRED-wrap ol:after { content: "."; display: block; height: 0; clear: both; visibility: hidden; }
105
- #myCRED-wrap ol.inline li { display: block; float: left; padding: 0 6px 6px 12px; }
106
- #myCRED-wrap ol.inline li:first-child { padding-left: 0; }
107
- #myCRED-wrap ol.inline li.block { float: none; padding: 0; clear: both; }
108
- #myCRED-wrap ol li.empty { display: block; height: 1px; float: none; clear: both; }
109
- #myCRED-wrap ol input.long { width: 50%; }
110
- #myCRED-wrap ol input.short { width: 80px; }
111
- #myCRED-wrap ol input[type="text"],
112
- #myCRED-wrap ol input[type="checkbox"], #myCRED-wrap ol input[type="radio"] { margin-right: 12px; }
113
- #myCRED-wrap ol li.option .h2, #myCRED-wrap ol li.option select, #myCRED-wrap ol li.option textarea { margin-left: 24px; }
114
-
115
- /* Setup */
116
- #myCRED-wrap>h2 { }
117
- #myCRED-wrap form.setup { width: 70%; }
118
- #myCRED-wrap form.setup ol { padding: 12px; }
119
- #myCRED-wrap form.setup .action-row { text-align: right; }
120
- #myCRED-wrap form.setup .action-row input { margin-right: 12px; }
121
- #myCRED-wrap form.setup ol.center { text-align: center; }
122
- #myCRED-wrap form.setup ol.center li { display: inline-block; min-width: 150px; padding: 0; margin: 0; text-align: center; }
123
- #myCRED-wrap form.setup ol.center li.min { width: 49%; float: left; text-align: left; }
124
- #myCRED-wrap form.setup .exchange-rate label { display: block; text-align: left; font-weight: bold; }
125
- #myCRED-wrap form.setup .delete-cubes label { padding-right: 12px; text-align: left; }
126
- #myCRED-wrap form.setup ol.regular li { text-align: left; float: left; padding: 6px; }
127
- #myCRED-wrap form.setup ol.regular li.tl { width: auto; min-width: inherit; }
128
- #myCRED-wrap form.setup ol li h2 { padding-right: 0; }
129
-
130
- #myCRED-wrap form.setup ul { line-height: 24px; }
131
- #myCRED-wrap form.setup ul li { padding: 6px 0; margin-bottom: 0; }
132
- #myCRED-wrap form.setup ul li span { font-size: smaller; }
133
- #myCRED-wrap form.setup ul li label { display: inline-block; width: 200px; max-width: 30%; font-weight: bold; }
134
- #myCRED-wrap form.setup ul li input { margin-right: 12px; vertical-align: middle; }
135
-
136
- .version-3-8 #accordion pre { background-color: #ddd; color: #333; padding: 6px; }
137
- .mycred-badge { border-radius: 5px; height: 192px; width: 173px; margin: 0 -5px; background: url('../images/about/badge.png') center 11px no-repeat; background-color: white; }
138
- .about-wrap .mycred-badge { position: absolute; top: 0; right: 0; }
139
- body.rtl .about-wrap .mycred-badge { right: auto; left: 0; }
140
- .mycred-actions { margin-bottom: 2em; }
141
-
142
- #mycred-about-wrap .feature-section .col-2:before, #mycred-about-wrap .feature-section .col-2:after, #mycred-about-wrap .feature-section.two-col p:before, #mycred-credit-wrap .feature-section .col-2:before, #mycred-credit-wrap .feature-section .col-2:after, #mycred-credit-wrap .feature-section.two-col p:before { content: ''; }
143
-
144
- /* Export */
145
- #export-log-history { clear: both; float: none; padding-bottom: 12px; margin-top: 12px; border-top: 1px solid #E1E1E1; border-bottom: 1px solid #E1E1E1; margin-bottom: 12px; }
146
- #export-log-history input { outline: none; }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
assets/css/mycred-admin.css CHANGED
@@ -201,4 +201,42 @@ body #myCRED-wrap #accordion .ui-accordion-header.buycred-cashcred-more-tab-btn.
201
  }
202
  h4.buycred-cashcred-more-tab-btn.ui-accordion-header.ui-state-active:before, h4.buycred-cashcred-more-tab-btn.ui-accordion-header:before {
203
  content: '';
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
204
  }
201
  }
202
  h4.buycred-cashcred-more-tab-btn.ui-accordion-header.ui-state-active:before, h4.buycred-cashcred-more-tab-btn.ui-accordion-header:before {
203
  content: '';
204
+ }
205
+
206
+ .v-align-middle{
207
+ vertical-align: middle;
208
+ }
209
+
210
+ .mycred-tools-import-export table tr td {
211
+ width: 215px;
212
+ }
213
+
214
+ .mycred-tools-import-export table tr td:nth-last-child( 1 ) {
215
+ width: max-content;
216
+ }
217
+
218
+ .mycred-tools-import-export table tr {
219
+ height: 55px;
220
+ }
221
+
222
+ .mycred-tools-import-export .mycred-container{
223
+ padding: 10px 0;
224
+ }
225
+
226
+ .mycred-tools-import-export .mycred-container label{
227
+ display: block;
228
+ }
229
+ #myCRED-wrap .mycred-tools-setup ol {
230
+ margin-block-start: 1em;
231
+ margin-block-end: 1em;
232
+ margin-inline-start: 0px;
233
+ margin-inline-end: 0px;
234
+ padding: 0px;
235
+ padding-inline-start: 40px;
236
+ margin-bottom: 0px;
237
+ }
238
+
239
+ .mycred-tools-setup, .mycred-tools-setup-export{
240
+ float: left;
241
+ width: 50%;
242
  }
assets/css/mycred-front.css CHANGED
@@ -1,4 +1,260 @@
1
- .widget .myCRED-rank{float:right}.widget .myCRED-rank span{padding-right:4px;color:gray}.widget .myCRED-balance{display:block;margin-bottom:24px;text-align:center;font-size:larger}.widget .myCRED-leaderboard .cred{float:right}.widget .myCRED-leaderboard .first-item{font-size:110%}.widget .myCRED-history{padding:0;margin:0;list-style-type:none}.widget .myCRED-history .creds{float:right;padding:0;clear:left}.mycred-nav-rank img{display:inherit}button.mycred-submit-transfer.btn.btn-primary.btn-block.btn-lg{margin:20px 0}input.mycred-autofill.form-control.ui-autocomplete-input{margin-left:20px}.mycred-transfer-form input.form-control{margin-left:28px;margin-top:10px}.site .button:focus,.wp-block-button .wp-block-button__link:focus,.wp-block-search__button:focus,input[type=reset]:focus,input[type=submit]:focus{background:0;outline-offset:-6px;outline:2px solid currentColor}.site textarea:focus,input[type=color]:focus,input[type=date]:focus,input[type=datetime-local]:focus,input[type=datetime]:focus,input[type=email]:focus,input[type=month]:focus,input[type=number]:focus,input[type=password]:focus,input[type=search]:focus,input[type=tel]:focus,input[type=text]:focus,input[type=time]:focus,input[type=url]:focus,input[type=week]:focus{color:var(--form--color-text);outline-offset:2px;outline:0}.site .button:focus,.wp-block-button .wp-block-button__link:focus,.wp-block-search__button:focus,input[type=reset]:focus,input[type=submit]:focus{background:0;outline-offset:-6px;outline:0}span.form-control-static{text-transform:capitalize;font-weight:400;margin-left:20px}p.form-control-static{margin:0 16px}form#mycred-transfer-form-transfer{background:#f9f9f9;padding:25px;box-shadow:0 0 20px 0 rgb(0 0 0 / 20%),0 5px 5px 0 rgb(0 0 0 / 24%);border-radius:10px}form#mycred-transfer-form-donation{background:#f9f9f9;padding:25px;margin:150px 0;box-shadow:0 0 20px 0 rgb(0 0 0 / 20%),0 5px 5px 0 rgb(0 0 0 / 24%);border-radius:10px}input#mycred-transfer-form-message-field{margin-left:24px}span#mycred-transfer-form-amount-field{margin-left:28px}.mycred-badges-list-item img{width:25%;display:inline-block;float:left}.mycred-badges-list-item h3{color:red}.mycred-badges-list-item .mycred-left{float:left;width:72%;margin-left:15px}.mycred-badges-list-item .clear{clear:both}.mycred-badges-list-item .mycred-mr-l{margin-left:25px}.mycred-badges-list-item{border-top:0 solid #9c9c9c;min-height:180px;padding:15px 0;cursor:pointer}.mycred-badges-list-item~.mycred-badges-list-item{border-top-width:1px}.mycred-badges-list h3:first-child{margin-bottom:15px;margin-top:0}.mycred-badges-list-item.not-earned{filter:grayscale(1)}.mycred-tabset .mycred-badge-count{color:#fff;font-size:18px;background:#0173aa;border-radius:50%;padding:0 7px}.mycred-badges-list-item .mycred-sup-category{background:#0173aa;color:#fff;margin:0 3px;padding:2px 6px;font-size:14px;border-radius:4px}ul.mycred-badges-list-tabs{list-style-type:none;display:flex;margin:0;padding:0}ul.mycred-badges-list-tabs li{padding:10px;cursor:pointer;border:1px solid transparent;margin-right:5px;margin-bottom:-1px}ul.mycred-badges-list-tabs li.active{border:1px solid #47525d;border-bottom:1px solid #ccc}.mycred-badges-list-panels{border-top:1px solid #47525d}.mycred-badges-list-panel.active{display:initial}.mycred-badges-list-panel{display:none}.mycred-badge-count{color:#fff;font-size:18px;background:#0173aa;border-radius:50%;padding:0 7px;margin-left:5px}.mycred-badge-page .mycred-level-image{width:150px}.mycred-badge-page .mycred-badge-page-level{float:left;width:30%;text-align:center}.mycred-badge-page .mycred-level-requirement{font-size:19px;text-align:left}.mycred-badge-page .mycred-badge-image{width:150px}.mycred-badge-page-level .mycred-level-image{width:70px}.mycred-float-left{float:left}.mycred-float-right{float:right}.mycred-badge-earner-grid img{width:150px;height:150px;padding:10px}.mycred-badge-earner-grid h4{margin:0}.mycred-badge-earner-grid{text-align:center}.mycred-badges-list-item p{margin-top:0}.mycred-left{float:left}.mycred-right{float:right}.mycred-clear{clear:both}.mycred-remove-margin{margin:0}.mycred-remove-padding{padding:0}.mycred-evidence-page .intro{margin-left:45px}.mycred-evidence-page p{font-size:19px;margin:0}.mycred-evidence-page a{text-decoration:none;color:red}.mycred-evidence-page .dashicons-yes-alt{line-height:inherit;color:green}.mycred-badge-page-level ul{margin-left:0;padding-left:20px}.mycred-badge-page-level .mycred-level-reward{text-align:left}.mycred-level-reward{margin-bottom:15px}.mycred-badge-page-level{margin-right:15px}.mycred-badges-list-item:hover{background:#efefef}.mycred-badge-congratulation-msg{background:#f0f0f0;padding:25px 10px;margin:20px 0;border-radius:5px}li.mycred-strike-off{text-decoration:line-through}.mycred-search-bar{padding:10px 0}.mycred-history-wrapper .pagination>li{display:inline-block;padding:5px}.mycred-badge-page-level h4 {text-align: left;}
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2
 
3
 
4
  .mycred_align_left {
1
+ .widget .myCRED-rank {
2
+ float: right;
3
+ }
4
+ .widget .myCRED-rank span {
5
+ padding-right: 4px;
6
+ color: gray;
7
+ }
8
+ .widget .myCRED-balance {
9
+ display: block;
10
+ margin-bottom: 24px;
11
+ text-align: center;
12
+ font-size: larger;
13
+ }
14
+ .widget .myCRED-leaderboard .cred {
15
+ float: right;
16
+ }
17
+ .widget .myCRED-leaderboard .first-item {
18
+ font-size: 110%}
19
+ .widget .myCRED-history {
20
+ padding: 0;
21
+ margin: 0;
22
+ list-style-type: none;
23
+ }
24
+ .widget .myCRED-history .creds {
25
+ float: right;
26
+ padding: 0;
27
+ clear: left;
28
+ }
29
+ .mycred-nav-rank img {
30
+ display: inherit;
31
+ }
32
+ button.mycred-submit-transfer.btn.btn-primary.btn-block.btn-lg {
33
+ margin: 20px 0;
34
+ }
35
+ input.mycred-autofill.form-control.ui-autocomplete-input {
36
+ margin-left: 20px;
37
+ }
38
+ .mycred-transfer-form input.form-control {
39
+ margin-left: 28px;
40
+ margin-top: 10px;
41
+ }
42
+
43
+ span.form-control-static {
44
+ text-transform: capitalize;
45
+ font-weight: 400;
46
+ margin-left: 20px;
47
+ }
48
+ p.form-control-static {
49
+ margin: 0 16px;
50
+ }
51
+ form#mycred-transfer-form-transfer {
52
+ background: #f9f9f9;
53
+ padding: 25px;
54
+ box-shadow: 0 0 20px 0 rgb(0 0 0 / 20%), 0 5px 5px 0 rgb(0 0 0 / 24%);
55
+ border-radius: 10px;
56
+ }
57
+ form#mycred-transfer-form-donation {
58
+ background: #f9f9f9;
59
+ padding: 25px;
60
+ margin: 150px 0;
61
+ box-shadow: 0 0 20px 0 rgb(0 0 0 / 20%), 0 5px 5px 0 rgb(0 0 0 / 24%);
62
+ border-radius: 10px;
63
+ }
64
+ input#mycred-transfer-form-message-field {
65
+ margin-left: 24px;
66
+ }
67
+ span#mycred-transfer-form-amount-field {
68
+ margin-left: 28px;
69
+ }
70
+ .mycred-badges-list-item img {
71
+ width: 25%;
72
+ display: inline-block;
73
+ float: left;
74
+ }
75
+ .mycred-badges-list-item h3 {
76
+ color: red;
77
+ }
78
+ .mycred-badges-list-item .mycred-left {
79
+ float: left;
80
+ width: 72%;
81
+ margin-left: 15px;
82
+ }
83
+ .mycred-badges-list-item .clear {
84
+ clear: both;
85
+ }
86
+ .mycred-badges-list-item .mycred-mr-l {
87
+ margin-left: 25px;
88
+ }
89
+ .mycred-badges-list-item {
90
+ border-top: 0 solid #9c9c9c;
91
+ min-height: 180px;
92
+ padding: 15px 0;
93
+ cursor: pointer;
94
+ }
95
+ .mycred-badges-list-item~.mycred-badges-list-item {
96
+ border-top-width: 1px;
97
+ }
98
+ .mycred-badges-list h3:first-child {
99
+ margin-bottom: 15px;
100
+ margin-top: 0;
101
+ }
102
+ .mycred-badges-list-item.not-earned {
103
+ filter: grayscale(1);
104
+ }
105
+ .mycred-tabset .mycred-badge-count {
106
+ color: #fff;
107
+ font-size: 18px;
108
+ background: #0173aa;
109
+ border-radius: 50%;
110
+ padding: 0 7px;
111
+ }
112
+ .mycred-badges-list-item .mycred-sup-category {
113
+ background: #0173aa;
114
+ color: #fff;
115
+ margin: 0 3px;
116
+ padding: 2px 6px;
117
+ font-size: 14px;
118
+ border-radius: 4px;
119
+ }
120
+ ul.mycred-badges-list-tabs {
121
+ list-style-type: none;
122
+ display: flex;
123
+ margin: 0;
124
+ padding: 0;
125
+ }
126
+ ul.mycred-badges-list-tabs li {
127
+ padding: 10px;
128
+ cursor: pointer;
129
+ border: 1px solid transparent;
130
+ margin-right: 5px;
131
+ margin-bottom: -1px;
132
+ }
133
+ ul.mycred-badges-list-tabs li.active {
134
+ border: 1px solid #47525d;
135
+ border-bottom: 1px solid #ccc;
136
+ }
137
+ .mycred-badges-list-panels {
138
+ border-top: 1px solid #47525d;
139
+ }
140
+ .mycred-badges-list-panel.active {
141
+ display: initial;
142
+ }
143
+ .mycred-badges-list-panel {
144
+ display: none;
145
+ }
146
+ .mycred-badge-count {
147
+ color: #fff;
148
+ font-size: 18px;
149
+ background: #0173aa;
150
+ border-radius: 50%;
151
+ padding: 0 7px;
152
+ margin-left: 5px;
153
+ }
154
+ .mycred-badge-page .mycred-level-image {
155
+ width: 150px;
156
+ }
157
+ .mycred-badge-page .mycred-badge-page-level {
158
+ float: left;
159
+ width: 30%;
160
+ text-align: center;
161
+ }
162
+ .mycred-badge-page .mycred-level-requirement {
163
+ font-size: 19px;
164
+ text-align: left;
165
+ }
166
+ .mycred-badge-page .mycred-badge-image {
167
+ width: 150px;
168
+ }
169
+ .mycred-badge-page-level .mycred-level-image {
170
+ width: 70px;
171
+ }
172
+ .mycred-float-left {
173
+ float: left;
174
+ }
175
+ .mycred-float-right {
176
+ float: right;
177
+ }
178
+ .mycred-badge-earner-grid img {
179
+ width: 150px;
180
+ height: 150px;
181
+ padding: 10px;
182
+ }
183
+ .mycred-badge-earner-grid h4 {
184
+ margin: 0;
185
+ }
186
+ .mycred-badge-earner-grid {
187
+ text-align: center;
188
+ }
189
+ .mycred-badges-list-item p {
190
+ margin-top: 0;
191
+ }
192
+ .mycred-left {
193
+ float: left;
194
+ }
195
+ .mycred-right {
196
+ float: right;
197
+ }
198
+ .mycred-clear {
199
+ clear: both;
200
+ }
201
+ .mycred-remove-margin {
202
+ margin: 0;
203
+ }
204
+ .mycred-remove-padding {
205
+ padding: 0;
206
+ }
207
+ .mycred-evidence-page .intro {
208
+ margin-left: 45px;
209
+ }
210
+ .mycred-evidence-page p {
211
+ font-size: 19px;
212
+ margin: 0;
213
+ }
214
+ .mycred-evidence-page a {
215
+ text-decoration: none;
216
+ color: red;
217
+ }
218
+ .mycred-evidence-page .dashicons-yes-alt {
219
+ line-height: inherit;
220
+ color: green;
221
+ }
222
+ .mycred-badge-page-level ul {
223
+ margin-left: 0;
224
+ padding-left: 20px;
225
+ }
226
+ .mycred-badge-page-level .mycred-level-reward {
227
+ text-align: left;
228
+ }
229
+ .mycred-level-reward {
230
+ margin-bottom: 15px;
231
+ }
232
+ .mycred-badge-page-level {
233
+ margin-right: 15px;
234
+ }
235
+ .mycred-badges-list-item:hover {
236
+ background: #efefef;
237
+ }
238
+ .mycred-badge-congratulation-msg {
239
+ background: #f0f0f0;
240
+ padding: 25px 10px;
241
+ margin: 20px 0;
242
+ border-radius: 5px;
243
+ }
244
+ li.mycred-strike-off {
245
+ text-decoration: line-through;
246
+ }
247
+ .mycred-search-bar {
248
+ padding: 10px 0;
249
+ }
250
+ .mycred-history-wrapper .pagination>li {
251
+ display: inline-block;
252
+ padding: 5px;
253
+ }
254
+ .mycred-badge-page-level h4 {
255
+ text-align: left;
256
+ }
257
+
258
 
259
 
260
  .mycred_align_left {
assets/images/treasures/badges.jpg DELETED
Binary file
assets/images/treasures/currency.jpg DELETED
Binary file
assets/images/treasures/fitness.jpg DELETED
Binary file
assets/images/treasures/gems.jpg DELETED
Binary file
assets/images/treasures/learning.jpg DELETED
Binary file
assets/images/treasures/rank.jpg DELETED
Binary file
assets/js/accordion.js DELETED
@@ -1,14 +0,0 @@
1
- /**
2
- * Accordion
3
- * @since 0.1
4
- * @version 1.0
5
- */
6
- jQuery(function($) {
7
- if ( myCRED.active != '-1' ) {
8
- var active_box = parseInt( myCRED.active, 10 );
9
- }
10
- else {
11
- var active_box = false;
12
- }
13
- $( "#accordion" ).accordion({ collapsible: true, header: "h4", heightStyle: "content", active: active_box });
14
- });
 
 
 
 
 
 
 
 
 
 
 
 
 
 
assets/js/mycred-tools.js CHANGED
@@ -1,132 +1,127 @@
1
- jQuery( document ).ready( function() {
2
 
3
- var $selector = jQuery( '.bulk-award-type' );
4
 
5
  $selector.select2();
6
 
7
- $selector.on( "select2:select", function ( e ) {
8
- if( e.params.data.id == 'points' )
9
- {
10
- jQuery( '.bulk-award-point' ).fadeIn();
11
- jQuery( '.bulk-award-badge' ).fadeOut();
12
- jQuery( '.bulk-award-rank' ).fadeOut();
13
- jQuery( '.tools-revoke-btn' ).remove();
14
- jQuery( '.tools-bulk-assign-award-btn' ).addClass( 'award-points' );
15
- jQuery( '.tools-bulk-assign-award-btn' ).removeClass( 'award-badges' );
16
- jQuery( '.tools-bulk-assign-award-btn' ).removeClass( 'award-ranks' );
17
- jQuery( '.tools-bulk-assign-award-btn' ).html(`Update <span class="dashicons dashicons-update mycred-button1"></span> `);
18
- }
19
- else if( e.params.data.id == 'badges' )
20
- {
21
- jQuery( '.bulk-award-badge' ).fadeIn();
22
- jQuery( '.bulk-award-point' ).fadeOut();
23
- jQuery( '.bulk-award-rank' ).fadeOut();
24
- jQuery( '.tools-bulk-assign-award-btn' ).after(
25
  `<button class="button button-large large button-primary tools-revoke-btn" style="margin-left: 10px;">
26
  <span class="dashicons dashicons-update mycred-button1"></span>
27
  Revoke
28
  </button>`
29
  );
30
- jQuery( '.tools-bulk-assign-award-btn' ).html(`<span class="dashicons dashicons-update mycred-button1"></span> Award`);
31
- jQuery( '.tools-bulk-assign-award-btn' ).addClass( 'award-badges' );
32
- jQuery( '.tools-bulk-assign-award-btn' ).removeClass( 'award-points' );
33
- jQuery( '.tools-bulk-assign-award-btn' ).removeClass( 'award-ranks' );
34
- }
35
- else if( e.params.data.id == 'ranks' )
36
- {
37
- jQuery( '.bulk-award-rank' ).fadeIn();
38
- jQuery( '.bulk-award-point' ).fadeOut();
39
- jQuery( '.bulk-award-badge' ).fadeOut();
40
- jQuery( '.tools-revoke-btn' ).remove();
41
- jQuery( '.tools-bulk-assign-award-btn' ).addClass( 'award-ranks' );
42
- jQuery( '.tools-bulk-assign-award-btn' ).removeClass( 'award-points' );
43
- jQuery( '.tools-bulk-assign-award-btn' ).removeClass( 'award-badges' );
44
- jQuery( '.tools-bulk-assign-award-btn' ).html(`Update <span class="dashicons dashicons-update mycred-button1"></span>`);
45
  }
46
- } );
47
 
48
  //Log Entry
49
- var $logEntry = jQuery( '.log-entry' ).is( ':checked' );
50
 
51
- if( $logEntry )
52
- jQuery( '.log-entry-row' ).show();
53
  else
54
- jQuery( '.log-entry-row' ).hide();
55
 
56
  jQuery(".log-entry").change(function() {
57
- if( this.checked )
58
- jQuery( '.log-entry-row' ).show();
59
  else
60
- jQuery( '.log-entry-row' ).hide();
61
  });
62
 
63
 
64
  //Pointtype
65
- $selector = jQuery( '.bulk-award-pt' );
66
- $selector.select2( {
67
-
68
- } );
69
 
70
  //Users
71
- $selector = jQuery( '.bulk-users' );
72
  $selector.select2();
73
 
74
- var $awardToAll = jQuery( '.award-to-all' ).is( ':checked' );
75
 
76
- if( !$awardToAll )
77
- jQuery( '.users-row' ).show();
78
  else
79
- jQuery( '.users-row' ).hide();
80
 
81
  jQuery(".award-to-all").change(function() {
82
- if( !this.checked )
83
- jQuery( '.users-row' ).show();
84
  else
85
- jQuery( '.users-row' ).hide();
86
  });
87
 
88
  //User Roles
89
- $selector = jQuery( '.bulk-roles' );
90
  $selector.select2();
91
 
92
 
93
  //Badges
94
- $selector = jQuery( '.bulk-badges' );
95
  $selector.select2();
96
 
97
  //Ranks
98
- $selector = jQuery( '.bulk-ranks' );
99
  $selector.select2();
100
 
101
  //Bulk Assign AJAX
102
- jQuery( document ).on( 'click', '.tools-bulk-assign-award-btn', function(e){
103
 
104
  e.preventDefault();
105
 
106
  var $confirm;
107
 
108
- var $selectedType = jQuery( '.bulk-award-type' ).find( ':selected' ).val();
109
- var $pointsToAward = jQuery( '[name="bulk_award_point"]' ).val();
110
- var $pointType = jQuery( '[name="bulk_award_pt"]' ).val();
111
- var $logEntry = jQuery( '.log-entry' ).prop('checked');
112
- var $logEntryText = jQuery( '[name="log_entry_text"]' ).val();
113
- var $awardToAllUsers = jQuery( '.award-to-all' ).prop('checked');
114
- var $users = JSON.stringify( jQuery( '[name="bulk_users"]' ).val() );
115
- var $user_roles = JSON.stringify( jQuery( '[name="bulk_roles"]' ).val() );
116
-
117
- if( $pointsToAward < 0 )
118
- $confirm = confirm( mycredTools.revokeConfirmText );
119
  else
120
- $confirm = confirm( mycredTools.awardConfirmText );
121
 
122
- if( !$confirm )
123
  return false;
124
 
125
  //Ranks
126
- var $rankToAward = jQuery( '.bulk-ranks' ).find( ':selected' ).val();
127
 
128
  //Badges
129
- var $badgesToAward = JSON.stringify( jQuery( '[name="bulk_badges"]' ).val() );
130
 
131
  jQuery.ajax({
132
  url: ajaxurl,
@@ -147,62 +142,54 @@ jQuery( document ).ready( function() {
147
  badges_to_award: $badgesToAward
148
 
149
  },
150
- beforeSend: function()
151
- {
152
- jQuery( '.tools-bulk-assign-award-btn' ).find( 'span' ).css( 'display','inherit' );
153
  },
154
- success: function( data )
155
- {
156
- jQuery( '.tools-bulk-assign-award-btn' ).find( 'span' ).hide();
157
-
158
- if( data.success === true && $pointsToAward < 0 )
159
- {
160
- alert( mycredTools.successfullyDeducted );
161
- resetForm();
162
  return;
163
  }
164
 
165
- if( data.success === true )
166
- {
167
- alert( mycredTools.successfullyAwarded );
168
- resetForm();
169
  }
170
 
171
- if( data.success == 'pointsRequired' )
172
- {
173
- alert( mycredTools.pointsRequired );
174
  }
175
- if( data.success == 'logEntryRequired' )
176
- {
177
- alert( mycredTools.logEntryRequired );
178
  }
179
- if( data.success == 'userOrRoleIsRequired' )
180
- {
181
- alert( mycredTools.userOrRoleIsRequired );
182
  }
183
- if( data.success == 'badgesFieldRequried' )
184
- {
185
- alert( mycredTools.badgesFieldRequried );
186
  }
187
  }
188
  })
189
- } );
190
 
191
  //jQuery Bulk Revoke
192
- jQuery( document ).on( 'click', '.tools-revoke-btn', function(e){
193
 
194
  e.preventDefault();
195
-
196
- var $confirm = confirm( mycredTools.revokeConfirmText );
197
 
198
- if( !$confirm )
 
 
199
  return false;
200
 
201
- var $selectedType = jQuery( '.bulk-award-type' ).find( ':selected' ).val();
202
- var $badgesToRevoke = JSON.stringify( jQuery( '[name="bulk_badges"]' ).val() );
203
- var $awardToAllUsers = jQuery( '.award-to-all' ).prop('checked');
204
- var $users = JSON.stringify( jQuery( '[name="bulk_users"]' ).val() );
205
- var $user_roles = JSON.stringify( jQuery( '[name="bulk_roles"]' ).val() );
206
 
207
 
208
  jQuery.ajax({
@@ -217,35 +204,298 @@ jQuery( document ).ready( function() {
217
  users: $users,
218
  user_roles: $user_roles,
219
  },
220
- beforeSend: function()
221
- {
222
- jQuery( '.tools-revoke-btn' ).find( 'span' ).css( 'display','inherit' );
223
  },
224
- success: function( data )
225
- {
226
- jQuery( '.tools-revoke-btn' ).find( 'span' ).hide();
227
-
228
- if( data.success === true )
229
- {
230
- alert( mycredTools.successfullyRevoked );
231
- resetForm();
232
  }
233
- if( data.success == 'userOrRoleIsRequired' )
234
- {
235
- alert( mycredTools.userOrRoleIsRequired );
236
  }
237
- if( data.success == 'badgesFieldRequried' )
238
- {
239
- alert( mycredTools.badgesFieldRequried );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
240
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
241
  }
242
  });
243
- } );
244
- } );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
245
 
246
  //Reset Form
247
- function resetForm()
248
- {
249
  var $selectedValue = jQuery('.bulk-award-type').val();
250
  jQuery(".mycred-tools-ba-award-form").trigger('reset');
251
  jQuery('#bulk-users').val(null).trigger('change');
@@ -253,8 +503,42 @@ function resetForm()
253
  jQuery('#bulk-badges').val(null).trigger('change');
254
  jQuery('#bulk-ranks').val(null).trigger('change');
255
  jQuery(".log-entry").removeAttr("checked");
256
- jQuery( '.log-entry-row' ).hide();
257
  jQuery(".award-to-all").removeAttr("checked");
258
- jQuery( '.users-row' ).show();
259
- jQuery('.bulk-award-type').val( $selectedValue );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
260
  }
1
+ jQuery(document).ready(function() {
2
 
3
+ var $selector = jQuery('.bulk-award-type');
4
 
5
  $selector.select2();
6
 
7
+ $selector.on("select2:select", function(e) {
8
+ if (e.params.data.id == 'points') {
9
+ jQuery('.bulk-award-point').fadeIn();
10
+ jQuery('.bulk-award-badge').fadeOut();
11
+ jQuery('.bulk-award-rank').fadeOut();
12
+ jQuery('.tools-revoke-btn').remove();
13
+ jQuery('.tools-bulk-assign-award-btn').addClass('award-points');
14
+ jQuery('.tools-bulk-assign-award-btn').removeClass('award-badges');
15
+ jQuery('.tools-bulk-assign-award-btn').removeClass('award-ranks');
16
+ jQuery('.tools-bulk-assign-award-btn').html(`Update <span class="dashicons dashicons-update mycred-button1"></span> `);
17
+ } else if (e.params.data.id == 'badges') {
18
+ jQuery('.bulk-award-badge').fadeIn();
19
+ jQuery('.bulk-award-point').fadeOut();
20
+ jQuery('.bulk-award-rank').fadeOut();
21
+ jQuery('.tools-bulk-assign-award-btn').after(
 
 
 
22
  `<button class="button button-large large button-primary tools-revoke-btn" style="margin-left: 10px;">
23
  <span class="dashicons dashicons-update mycred-button1"></span>
24
  Revoke
25
  </button>`
26
  );
27
+ jQuery('.tools-bulk-assign-award-btn').html(`<span class="dashicons dashicons-update mycred-button1"></span> Award`);
28
+ jQuery('.tools-bulk-assign-award-btn').addClass('award-badges');
29
+ jQuery('.tools-bulk-assign-award-btn').removeClass('award-points');
30
+ jQuery('.tools-bulk-assign-award-btn').removeClass('award-ranks');
31
+ } else if (e.params.data.id == 'ranks') {
32
+ jQuery('.bulk-award-rank').fadeIn();
33
+ jQuery('.bulk-award-point').fadeOut();
34
+ jQuery('.bulk-award-badge').fadeOut();
35
+ jQuery('.tools-revoke-btn').remove();
36
+ jQuery('.tools-bulk-assign-award-btn').addClass('award-ranks');
37
+ jQuery('.tools-bulk-assign-award-btn').removeClass('award-points');
38
+ jQuery('.tools-bulk-assign-award-btn').removeClass('award-badges');
39
+ jQuery('.tools-bulk-assign-award-btn').html(`Update <span class="dashicons dashicons-update mycred-button1"></span>`);
 
 
40
  }
41
+ });
42
 
43
  //Log Entry
44
+ var $logEntry = jQuery('.log-entry').is(':checked');
45
 
46
+ if ($logEntry)
47
+ jQuery('.log-entry-row').show();
48
  else
49
+ jQuery('.log-entry-row').hide();
50
 
51
  jQuery(".log-entry").change(function() {
52
+ if (this.checked)
53
+ jQuery('.log-entry-row').show();
54
  else
55
+ jQuery('.log-entry-row').hide();
56
  });
57
 
58
 
59
  //Pointtype
60
+ $selector = jQuery('.bulk-award-pt');
61
+ $selector.select2({
62
+
63
+ });
64
 
65
  //Users
66
+ $selector = jQuery('.bulk-users');
67
  $selector.select2();
68
 
69
+ var $awardToAll = jQuery('.award-to-all').is(':checked');
70
 
71
+ if (!$awardToAll)
72
+ jQuery('.users-row').show();
73
  else
74
+ jQuery('.users-row').hide();
75
 
76
  jQuery(".award-to-all").change(function() {
77
+ if (!this.checked)
78
+ jQuery('.users-row').show();
79
  else
80
+ jQuery('.users-row').hide();
81
  });
82
 
83
  //User Roles
84
+ $selector = jQuery('.bulk-roles');
85
  $selector.select2();
86
 
87
 
88
  //Badges
89
+ $selector = jQuery('.bulk-badges');
90
  $selector.select2();
91
 
92
  //Ranks
93
+ $selector = jQuery('.bulk-ranks');
94
  $selector.select2();
95
 
96
  //Bulk Assign AJAX
97
+ jQuery(document).on('click', '.tools-bulk-assign-award-btn', function(e) {
98
 
99
  e.preventDefault();
100
 
101
  var $confirm;
102
 
103
+ var $selectedType = jQuery('.bulk-award-type').find(':selected').val();
104
+ var $pointsToAward = jQuery('[name="bulk_award_point"]').val();
105
+ var $pointType = jQuery('[name="bulk_award_pt"]').val();
106
+ var $logEntry = jQuery('.log-entry').prop('checked');
107
+ var $logEntryText = jQuery('[name="log_entry_text"]').val();
108
+ var $awardToAllUsers = jQuery('.award-to-all').prop('checked');
109
+ var $users = JSON.stringify(jQuery('[name="bulk_users"]').val());
110
+ var $user_roles = JSON.stringify(jQuery('[name="bulk_roles"]').val());
111
+
112
+ if ($pointsToAward < 0)
113
+ $confirm = confirm(mycredTools.revokeConfirmText);
114
  else
115
+ $confirm = confirm(mycredTools.awardConfirmText);
116
 
117
+ if (!$confirm)
118
  return false;
119
 
120
  //Ranks
121
+ var $rankToAward = jQuery('.bulk-ranks').find(':selected').val();
122
 
123
  //Badges
124
+ var $badgesToAward = JSON.stringify(jQuery('[name="bulk_badges"]').val());
125
 
126
  jQuery.ajax({
127
  url: ajaxurl,
142
  badges_to_award: $badgesToAward
143
 
144
  },
145
+ beforeSend: function() {
146
+ jQuery('.tools-bulk-assign-award-btn').find('span').css('display', 'inherit');
 
147
  },
148
+ success: function(data) {
149
+ jQuery('.tools-bulk-assign-award-btn').find('span').hide();
150
+
151
+ if (data.success === true && $pointsToAward < 0) {
152
+ alert(mycredTools.successfullyDeducted);
153
+ mycredToolsResetForm();
 
 
154
  return;
155
  }
156
 
157
+ if (data.success === true) {
158
+ alert(mycredTools.successfullyAwarded);
159
+ mycredToolsResetForm();
 
160
  }
161
 
162
+ if (data.success == 'pointsRequired') {
163
+ alert(mycredTools.pointsRequired);
 
164
  }
165
+ if (data.success == 'logEntryRequired') {
166
+ alert(mycredTools.logEntryRequired);
 
167
  }
168
+ if (data.success == 'userOrRoleIsRequired') {
169
+ alert(mycredTools.userOrRoleIsRequired);
 
170
  }
171
+ if (data.success == 'badgesFieldRequried') {
172
+ alert(mycredTools.badgesFieldRequried);
 
173
  }
174
  }
175
  })
176
+ });
177
 
178
  //jQuery Bulk Revoke
179
+ jQuery(document).on('click', '.tools-revoke-btn', function(e) {
180
 
181
  e.preventDefault();
 
 
182
 
183
+ var $confirm = confirm(mycredTools.revokeConfirmText);
184
+
185
+ if (!$confirm)
186
  return false;
187
 
188
+ var $selectedType = jQuery('.bulk-award-type').find(':selected').val();
189
+ var $badgesToRevoke = JSON.stringify(jQuery('[name="bulk_badges"]').val());
190
+ var $awardToAllUsers = jQuery('.award-to-all').prop('checked');
191
+ var $users = JSON.stringify(jQuery('[name="bulk_users"]').val());
192
+ var $user_roles = JSON.stringify(jQuery('[name="bulk_roles"]').val());
193
 
194
 
195
  jQuery.ajax({
204
  users: $users,
205
  user_roles: $user_roles,
206
  },
207
+ beforeSend: function() {
208
+ jQuery('.tools-revoke-btn').find('span').css('display', 'inherit');
 
209
  },
210
+ success: function(data) {
211
+ jQuery('.tools-revoke-btn').find('span').hide();
212
+
213
+ if (data.success === true) {
214
+ alert(mycredTools.successfullyRevoked);
215
+ mycredToolsResetForm();
 
 
216
  }
217
+ if (data.success == 'userOrRoleIsRequired') {
218
+ alert(mycredTools.userOrRoleIsRequired);
 
219
  }
220
+ if (data.success == 'badgesFieldRequried') {
221
+ alert(mycredTools.badgesFieldRequried);
222
+ }
223
+ }
224
+ });
225
+ });
226
+
227
+ /*
228
+ * @since 2.4
229
+ * @version 1.0
230
+ */
231
+ var $pt_selector = jQuery('#tools-type-import-export');
232
+
233
+ $pt_selector.select2();
234
+
235
+ jQuery(document).on('click', '#select-all-pt', function() {
236
+
237
+ jQuery('#tools-type-import-export').select2('destroy');
238
+
239
+ var $values = [];
240
+
241
+ jQuery('#tools-type-import-export option').each(function(i, obj) {
242
+
243
+ if (obj.selected) {
244
+ jQuery('#tools-type-import-export').val(null).trigger('change');
245
+ jQuery('#tools-type-import-export').select2();
246
+ return false;
247
+ }
248
+ if (!obj.selected) {
249
+ jQuery('#tools-type-import-export').find('option').prop('selected', 'selected').end();
250
+ jQuery('#tools-type-import-export').select2();
251
+ return false;
252
+ }
253
+ return false;
254
+ });
255
+ });
256
+
257
+ var $uf_selector = jQuery('#tools-uf-import-export');
258
+ $uf_selector.select2();
259
+
260
+ //Download Formatted Points
261
+ jQuery(document).on('click', '#download-formatted-template-csv', function() {
262
+ var $requestTab = jQuery('.request-tab').val();
263
+ jQuery.ajax({
264
+ url: ajaxurl,
265
+ type: 'POST',
266
+ data: {
267
+ action: 'mycred-tools-import-export',
268
+ request_tab: $requestTab,
269
+ template: 'formatted'
270
+ },
271
+ beforeSend: function() {
272
+ mycredToolsAddLoader('#download-formatted-template-csv');
273
+ },
274
+ success: function(data) {
275
+ mycredToolsDowloadCSV(data, 'formatted-points-template');
276
+ mycredToolsRemoveLoader('#download-formatted-template-csv', 'dashicons dashicons-download v-align-middle');
277
+ }
278
+ });
279
+ });
280
+
281
+ //Downlaod Row Points
282
+ jQuery(document).on('click', '#download-raw-template-csv', function() {
283
+ var $requestTab = jQuery('.request-tab').val();
284
+ jQuery.ajax({
285
+ url: ajaxurl,
286
+ type: 'POST',
287
+ data: {
288
+ action: 'mycred-tools-import-export',
289
+ request_tab: $requestTab,
290
+ template: 'raw'
291
+ },
292
+ beforeSend: function() {
293
+ mycredToolsAddLoader('#download-raw-template-csv');
294
+ },
295
+ success: function(data) {
296
+ mycredToolsDowloadCSV(data, `raw-${$requestTab}-template`);
297
+ mycredToolsRemoveLoader('#download-raw-template-csv', 'dashicons dashicons-download v-align-middle');
298
+ }
299
+ });
300
+ });
301
+
302
+ //Export Raw Points
303
+ jQuery(document).on('click', '#export-raw', function(e) {
304
+
305
+ e.preventDefault();
306
+
307
+ var $requestTab = jQuery('.request-tab').val();
308
+
309
+ var $pt = jQuery('#tools-type-import-export').val();
310
+
311
+ var $userField = jQuery('#tools-uf-import-export').val();
312
+
313
+ var $fileFormat = 'csv';
314
+
315
+ var $postField, $setupTypes = Array();
316
+
317
+ if (($pt == undefined || $pt.length == 0) && $requestTab == 'points') {
318
+ alert('Select alteast one Point Type.');
319
+ return false;
320
+ }
321
+
322
+ if (($pt == undefined || $pt.length == 0) && $requestTab == 'badges') {
323
+ alert('Select alteast one Badge.');
324
+ return false;
325
+ }
326
+
327
+ if (($pt == undefined || $pt.length == 0) && $requestTab == 'ranks') {
328
+ alert('Select alteast one Rank.');
329
+ return false;
330
+ }
331
+
332
+ if ($requestTab == 'badges' || $requestTab == 'ranks')
333
+ var $postField = jQuery('#tools-badge-fields-import-export').val()
334
+
335
+ if ($requestTab == 'setup') {
336
+ $fileFormat = 'json';
337
+ $_setupTypes = jQuery('.mycred-tools-setup input[type=checkbox]');
338
+ var $counter = 0;
339
+ jQuery.each($_setupTypes, function(index, element) {
340
+
341
+ var $elementValue = jQuery(element);
342
+
343
+ if (jQuery(element).is(':checked') === false) return;
344
+
345
+ if (jQuery(element).is(':checked') === true) {
346
+ var $_obj = {};
347
+ var _name = $elementValue.attr('name');
348
+ var $_value = $elementValue.attr('value');
349
+ $_obj[_name] = $_value;
350
+ $setupTypes[$counter] = $_obj;
351
+ $counter++;
352
  }
353
+ });
354
+
355
+ if ($setupTypes.length == 0) {
356
+ alert('Nothing selected to Import.');
357
+ return false;
358
+ }
359
+ }
360
+
361
+ jQuery.ajax({
362
+ url: ajaxurl,
363
+ type: 'POST',
364
+ data: {
365
+ action: 'mycred-tools-import-export',
366
+ request_tab: $requestTab,
367
+ request: 'export',
368
+ template: 'raw',
369
+ user_field: $userField,
370
+ post_field: $postField,
371
+ types: JSON.stringify($pt),
372
+ setup_types: $setupTypes
373
+ },
374
+ beforeSend: function() {
375
+ mycredToolsAddLoader('#export-raw');
376
+ },
377
+ success: function(data) {
378
+ mycredToolsDowloadCSV(data, `raw-${$requestTab}`, $fileFormat);
379
+ mycredToolsRemoveLoader('#export-raw', 'dashicons dashicons-database-export v-align-middle');
380
+ }
381
+ });
382
+ });
383
+
384
+ //Export Formatted
385
+ jQuery(document).on('click', '#export-formatted', function() {
386
+
387
+ var $requestTab = jQuery('.request-tab').val();
388
+
389
+ var $pt = jQuery('#tools-type-import-export').val();
390
+
391
+ var $userField = jQuery('#tools-uf-import-export').val();
392
+
393
+ if ($pt == undefined || $pt.length == 0) {
394
+ alert('Select alteast one Point Type.');
395
+ return false;
396
+ }
397
+
398
+ jQuery.ajax({
399
+ url: ajaxurl,
400
+ type: 'POST',
401
+ data: {
402
+ action: 'mycred-tools-import-export',
403
+ request_tab: $requestTab,
404
+ request: 'export',
405
+ template: 'formatted',
406
+ user_field: $userField,
407
+ types: JSON.stringify($pt)
408
+ },
409
+ beforeSend: function() {
410
+ mycredToolsAddLoader('#export-formatted');
411
+ },
412
+ success: function(data) {
413
+ mycredToolsDowloadCSV(data, `formatted-${$requestTab}`);
414
+ mycredToolsRemoveLoader('#export-formatted', 'dashicons dashicons-database-export v-align-middle');
415
+ }
416
+ });
417
+ });
418
+
419
+ //Import Points
420
+ jQuery(document).on('click', '#import', function(e) {
421
+
422
+ e.preventDefault();
423
+
424
+ var $requestTab = jQuery('.request-tab').val(),
425
+ $importFormatType;
426
+
427
+ if ($requestTab == 'badges' || $requestTab == 'ranks')
428
+ $importFormatType = jQuery('#import-format-type').val();
429
+
430
+ if (document.getElementById('import-file').files.length == 0) {
431
+ alert('Upload file first.');
432
+ return false;
433
+ }
434
+
435
+ if ((document.getElementById('import-file').files[0].type !== 'application/vnd.ms-excel' && document.getElementById('import-file').files[0].type !== 'text/csv') && ($requestTab != 'setup')) {
436
+ alert('Upload csv format file.');
437
+ return false;
438
+ }
439
+
440
+ //Setup
441
+ if (document.getElementById('import-file').files[0].type !== 'application/json' && ($requestTab == 'setup')) {
442
+ alert('Upload JSON format file.');
443
+ return false;
444
+ }
445
+
446
+ var file = jQuery(document).find('#import-file');
447
+ var file = file[0].files[0];
448
+
449
+ var formData = new FormData();
450
+ formData.append('action', 'mycred-tools-import-export');
451
+ formData.append('request_tab', $requestTab);
452
+ formData.append('import_format_type', $importFormatType);
453
+ formData.append('request', 'import');
454
+ formData.append('_file', file);
455
+
456
+
457
+ jQuery.ajax({
458
+ url: mycredTools.ajax_url,
459
+ type: 'POST',
460
+ data: formData,
461
+ contentType: false,
462
+ processData: false,
463
+ error: function(e) {
464
+ console.log('Error', e);
465
+ },
466
+ beforeSend: function() {
467
+ mycredToolsAddLoader('#import');
468
+ },
469
+ success: function(data) {
470
+
471
+ if (data == '')
472
+ data = 'File successfully imported.';
473
+
474
+ alert(data);
475
+ jQuery('#import-file').val('');
476
+ mycredToolsRemoveLoader('#import', 'dashicons dashicons-database-import v-align-middle');
477
  }
478
  });
479
+ });
480
+
481
+ jQuery('#tools-badge-fields-import-export').select2();
482
+
483
+ jQuery('#import-format-type').select2();
484
+
485
+ //Setup Import Export
486
+ jQuery(document).on('change', '.mycred-tools-setup input[type=checkbox]', function(e) {
487
+
488
+ if (this.checked)
489
+ jQuery(this).parent().parent().nextUntil('li').find('input[type=checkbox]').prop('checked', true);
490
+ else
491
+ jQuery(this).parent().parent().nextUntil('li').find('input[type=checkbox]').prop('checked', false);
492
+
493
+ })
494
+
495
+ });
496
 
497
  //Reset Form
498
+ function mycredToolsResetForm() {
 
499
  var $selectedValue = jQuery('.bulk-award-type').val();
500
  jQuery(".mycred-tools-ba-award-form").trigger('reset');
501
  jQuery('#bulk-users').val(null).trigger('change');
503
  jQuery('#bulk-badges').val(null).trigger('change');
504
  jQuery('#bulk-ranks').val(null).trigger('change');
505
  jQuery(".log-entry").removeAttr("checked");
506
+ jQuery('.log-entry-row').hide();
507
  jQuery(".award-to-all").removeAttr("checked");
508
+ jQuery('.users-row').show();
509
+ jQuery('.bulk-award-type').val($selectedValue);
510
+ }
511
+
512
+ //Downlaods CSV
513
+ function mycredToolsDowloadCSV(data, fileName, fileFormat = 'csv') {
514
+ /*
515
+ * Make CSV downloadable
516
+ */
517
+ var downloadLink = document.createElement("a");
518
+ var fileData = ['\ufeff' + data];
519
+
520
+ var blobObject = new Blob(fileData, {
521
+ type: "text/csv;charset=utf-8;"
522
+ });
523
+
524
+ var url = URL.createObjectURL(blobObject);
525
+ downloadLink.href = url;
526
+ downloadLink.download = `${fileName}.${fileFormat}`;
527
+
528
+ /*
529
+ * Actually download CSV
530
+ */
531
+ document.body.appendChild(downloadLink);
532
+ downloadLink.click();
533
+ document.body.removeChild(downloadLink);
534
+ }
535
+
536
+ function mycredToolsAddLoader(parentIdentifier) {
537
+ jQuery(`${parentIdentifier} span`).removeClass();
538
+ jQuery(`${parentIdentifier} span`).addClass('dashicons dashicons-update mycred-button1').css('display', 'inherit');
539
+ }
540
+
541
+ function mycredToolsRemoveLoader(parentIdentifier, iconIdentifier) {
542
+ jQuery(`${parentIdentifier} span`).removeClass();
543
+ jQuery(`${parentIdentifier} span`).addClass(iconIdentifier);
544
  }
assets/screenshot-6.png DELETED
Binary file
includes/classes/class.query-leaderboard.php CHANGED
@@ -15,7 +15,6 @@ if ( ! class_exists( 'myCRED_Query_Leaderboard' ) ) :
15
  public $core = NULL;
16
  public $user_id = 0;
17
  private $max_size = 250;
18
-
19
  public $args = array();
20
  public $based_on = 'balance';
21
  public $references = array();
@@ -216,6 +215,7 @@ if ( ! class_exists( 'myCRED_Query_Leaderboard' ) ) :
216
 
217
  $this->leaderboard = $results;
218
 
 
219
  if ( $append_current_user )
220
  $this->append_current_user();
221
 
@@ -287,10 +287,15 @@ if ( ! class_exists( 'myCRED_Query_Leaderboard' ) ) :
287
  */
288
  public function get_db_query() {
289
 
290
- if ( $this->based_on == 'balance' )
 
291
  $query = $this->get_balance_db_query();
292
- else
 
293
  $query = $this->get_reference_db_query();
 
 
 
294
 
295
  return $query;
296
 
@@ -390,6 +395,7 @@ if ( ! class_exists( 'myCRED_Query_Leaderboard' ) ) :
390
 
391
  global $wpdb, $mycred_log_table;
392
 
 
393
  $time_filter = $this->get_timefilter();
394
  $multisite_check = $this->get_multisitefilter();
395
  $exclude_user_filter = $this->get_exclude_userfilter();
@@ -734,10 +740,22 @@ if ( ! class_exists( 'myCRED_Query_Leaderboard' ) ) :
734
 
735
  global $wpdb;
736
 
 
 
 
 
737
  // Filter: Daily
738
  if ( $this->args['timeframe'] == 'today' ) {
739
  $query = $wpdb->prepare( "AND l.time BETWEEN %d AND %d", strtotime( 'today midnight', $this->now ), $this->args['now'] );
740
  }
 
 
 
 
 
 
 
 
741
  // Filter: Weekly
742
  elseif ( $this->args['timeframe'] == 'this-week' ) {
743
 
@@ -797,7 +815,6 @@ if ( ! class_exists( 'myCRED_Query_Leaderboard' ) ) :
797
  $balance_format = 'CAST( %f AS DECIMAL( ' . $length . ', ' . $this->core->format['decimals'] . ' ) )';
798
  }
799
 
800
- if ( ! $this->args['total'] )
801
  $query = $wpdb->prepare( "AND l.meta_value != {$balance_format}", $this->core->zero() );
802
 
803
  }
@@ -819,21 +836,25 @@ if ( ! class_exists( 'myCRED_Query_Leaderboard' ) ) :
819
 
820
  // Option to exclude zero balances
821
  $query = '';
822
- $checkIDs='~^\d+(,\d+)?$~';
823
  $exclude=$this->args['exclude'];
824
 
825
  if (!empty($exclude)) {
 
826
  if(preg_match($checkIDs,$exclude)){
827
 
828
  $exclude=$this->args['exclude'];
 
829
  }
830
- else{
 
831
  $exclude=mycred_leaderboard_exclude_role($exclude);
 
832
  }
833
- $query = $wpdb->prepare( "AND l.user_id NOT IN (%s) ",$exclude);
 
834
  }
835
  return apply_filters( 'mycred_leaderboard_exclude_user_filter', $query, $this );
836
-
837
  }
838
 
839
  /**
15
  public $core = NULL;
16
  public $user_id = 0;
17
  private $max_size = 250;
 
18
  public $args = array();
19
  public $based_on = 'balance';
20
  public $references = array();
215
 
216
  $this->leaderboard = $results;
217
 
218
+
219
  if ( $append_current_user )
220
  $this->append_current_user();
221
 
287
  */
288
  public function get_db_query() {
289
 
290
+
291
+ if ( $this->based_on == 'balance' ) {
292
  $query = $this->get_balance_db_query();
293
+ }
294
+ else {
295
  $query = $this->get_reference_db_query();
296
+ }
297
+
298
+
299
 
300
  return $query;
301
 
395
 
396
  global $wpdb, $mycred_log_table;
397
 
398
+ $query = '';
399
  $time_filter = $this->get_timefilter();
400
  $multisite_check = $this->get_multisitefilter();
401
  $exclude_user_filter = $this->get_exclude_userfilter();
740
 
741
  global $wpdb;
742
 
743
+
744
+
745
+
746
+
747
  // Filter: Daily
748
  if ( $this->args['timeframe'] == 'today' ) {
749
  $query = $wpdb->prepare( "AND l.time BETWEEN %d AND %d", strtotime( 'today midnight', $this->now ), $this->args['now'] );
750
  }
751
+
752
+ // Filter: Yesterday
753
+ elseif ( $this->args['timeframe'] == 'yesterday' ) {
754
+ $query = $wpdb->prepare( "AND l.time BETWEEN %d AND %d", strtotime( '-1 day midnight', $this->now ), strtotime( 'today midnight', $this->now ));
755
+
756
+ }
757
+
758
+
759
  // Filter: Weekly
760
  elseif ( $this->args['timeframe'] == 'this-week' ) {
761
 
815
  $balance_format = 'CAST( %f AS DECIMAL( ' . $length . ', ' . $this->core->format['decimals'] . ' ) )';
816
  }
817
 
 
818
  $query = $wpdb->prepare( "AND l.meta_value != {$balance_format}", $this->core->zero() );
819
 
820
  }
836
 
837
  // Option to exclude zero balances
838
  $query = '';
839
+ $checkIDs='~^\d+(,\d+)*$~';
840
  $exclude=$this->args['exclude'];
841
 
842
  if (!empty($exclude)) {
843
+
844
  if(preg_match($checkIDs,$exclude)){
845
 
846
  $exclude=$this->args['exclude'];
847
+
848
  }
849
+ elseif(!preg_match($checkIDs,$exclude)){
850
+
851
  $exclude=mycred_leaderboard_exclude_role($exclude);
852
+
853
  }
854
+ $query = $wpdb->prepare( "AND l.user_id NOT IN ($exclude)");
855
+
856
  }
857
  return apply_filters( 'mycred_leaderboard_exclude_user_filter', $query, $this );
 
858
  }
859
 
860
  /**
includes/classes/class.query-log.php CHANGED
@@ -1840,7 +1840,7 @@ jQuery(function($) {
1840
  if ( ! $this->render_mode ) return;
1841
 
1842
  if ( isset( $_GET['s'] ) && $_GET['s'] != '' )
1843
- $serarch_string = $_GET['s'];
1844
  else
1845
  $serarch_string = '';
1846
 
1840
  if ( ! $this->render_mode ) return;
1841
 
1842
  if ( isset( $_GET['s'] ) && $_GET['s'] != '' )
1843
+ $serarch_string = sanitize_text_field( $_GET['s'] );
1844
  else
1845
  $serarch_string = '';
1846
 
includes/hooks/external/mycred-hook-affiliatewp.php CHANGED
@@ -207,6 +207,7 @@ function mycred_load_affiliatewp_hook() {
207
  /**
208
  * Referral Payout
209
  * @since 1.6
 
210
  * @version 1.0
211
  */
212
  public function referral_payouts( $referral_id, $new_status, $old_status ) {
207
  /**
208
  * Referral Payout
209
  * @since 1.6
210
+ * @since 2.4 @filter added `mycred_affiliate_prefs` for LevelCRED
211
  * @version 1.0
212
  */
213
  public function referral_payouts( $referral_id, $new_status, $old_status ) {
includes/hooks/mycred-hook-referrals.php CHANGED
@@ -260,6 +260,8 @@ if ( ! class_exists( 'myCRED_Hook_Affiliate' ) ) :
260
  // If referral counts
261
  if ( $this->ref_counts( $user_id, $IP ) ) {
262
 
 
 
263
  // Award
264
  $this->core->add_creds(
265
  'visitor_referral',
@@ -271,6 +273,8 @@ if ( ! class_exists( 'myCRED_Hook_Affiliate' ) ) :
271
  $this->mycred_type
272
  );
273
 
 
 
274
  do_action( 'mycred_visitor_referral', $user_id, $IP, $this );
275
 
276
  }
@@ -327,10 +331,18 @@ if ( ! class_exists( 'myCRED_Hook_Affiliate' ) ) :
327
  if ( ! headers_sent() )
328
  setcookie( $key, $ref, time()-3600, COOKIEPATH, COOKIE_DOMAIN );
329
 
 
 
330
  // Attempt to get the users IP
331
  $IP = apply_filters( 'mycred_affiliate_IP', $_SERVER['REMOTE_ADDR'], 'signup', $this );
 
 
 
 
332
  if ( $IP != '' && $IP != '0.0.0.0' ) {
333
 
 
 
334
  if ( $this->ref_counts( $user_id, $IP, 'signup' ) ) {
335
 
336
  $hooks = mycred_get_option( 'mycred_pref_hooks', false );
@@ -362,6 +374,8 @@ if ( ! class_exists( 'myCRED_Hook_Affiliate' ) ) :
362
  // Award now
363
  else {
364
 
 
 
365
  $this->core->add_creds(
366
  'signup_referral',
367
  $user_id,
@@ -397,6 +411,8 @@ if ( ! class_exists( 'myCRED_Hook_Affiliate' ) ) :
397
 
398
  if ( $referred_by == '' || $referred_by_IP == '' || $this->mycred_type != $referred_type ) return;
399
 
 
 
400
  // Award
401
  $this->core->add_creds(
402
  'signup_referral',
260
  // If referral counts
261
  if ( $this->ref_counts( $user_id, $IP ) ) {
262
 
263
+ if ( $this->core->has_entry( 'visitor_referral', time(), $user_id, $IP, $this->mycred_type ) ) return;
264
+
265
  // Award
266
  $this->core->add_creds(
267
  'visitor_referral',
273
  $this->mycred_type
274
  );
275
 
276
+
277
+
278
  do_action( 'mycred_visitor_referral', $user_id, $IP, $this );
279
 
280
  }
331
  if ( ! headers_sent() )
332
  setcookie( $key, $ref, time()-3600, COOKIEPATH, COOKIE_DOMAIN );
333
 
334
+
335
+
336
  // Attempt to get the users IP
337
  $IP = apply_filters( 'mycred_affiliate_IP', $_SERVER['REMOTE_ADDR'], 'signup', $this );
338
+
339
+ if ( $this->core->has_entry( 'signup_referral', $new_user_id, $user_id, $IP, $this->mycred_type ) ) return;
340
+
341
+
342
  if ( $IP != '' && $IP != '0.0.0.0' ) {
343
 
344
+ if ( $this->core->has_entry( 'signup_referral', $new_user_id, $user_id, $IP, $this->mycred_type ) ) return;
345
+
346
  if ( $this->ref_counts( $user_id, $IP, 'signup' ) ) {
347
 
348
  $hooks = mycred_get_option( 'mycred_pref_hooks', false );
374
  // Award now
375
  else {
376
 
377
+ if ( $this->core->has_entry( 'signup_referral', $new_user_id, $user_id, $IP, $this->mycred_type ) ) return;
378
+
379
  $this->core->add_creds(
380
  'signup_referral',
381
  $user_id,
411
 
412
  if ( $referred_by == '' || $referred_by_IP == '' || $this->mycred_type != $referred_type ) return;
413
 
414
+ if ( $this->core->has_entry( 'signup_referral', $user_id, $referred_by, $referred_by_IP, $this->mycred_type ) ) return;
415
+
416
  // Award
417
  $this->core->add_creds(
418
  'signup_referral',
includes/hooks/mycred-hook-watching-video.php CHANGED
@@ -37,7 +37,7 @@ if ( ! class_exists( 'myCRED_Hook_Video_Views' ) ) :
37
  add_action( 'wp_ajax_mycred-viewing-videos', array( $this, 'ajax_call_video_points' ) );
38
 
39
  add_filter( 'mycred_video_js', array( $this, 'adjust_js' ) );
40
- add_filter( 'mycred_video_view_' . $this->mycred_type, array( $this, 'video_view' ), 10, 2 );
41
 
42
  }
43
 
@@ -79,7 +79,7 @@ if ( ! class_exists( 'myCRED_Hook_Video_Views' ) ) :
79
 
80
  // Prep
81
  $amount = $this->core->number( $amount );
82
- $interval = abs( $interval / 1000 );
83
 
84
  // Get playback details
85
  $actions = sanitize_text_field( $_POST['video_a'] );
@@ -479,7 +479,7 @@ if ( ! function_exists( 'mycred_video_detect_views' ) ) :
479
  foreach ( explode( ',', $setup[5] ) as $type_key ) {
480
 
481
  $type_key = sanitize_key( $type_key );
482
- if ( mycred_point_type_exists( $type_key ) && ! in_array( $type_id, $types ) )
483
  $types[] = $type_key;
484
 
485
  }
37
  add_action( 'wp_ajax_mycred-viewing-videos', array( $this, 'ajax_call_video_points' ) );
38
 
39
  add_filter( 'mycred_video_js', array( $this, 'adjust_js' ) );
40
+ add_action( 'mycred_video_view_' . $this->mycred_type, array( $this, 'video_view' ), 10 );
41
 
42
  }
43
 
79
 
80
  // Prep
81
  $amount = $this->core->number( $amount );
82
+ $interval = abs( floatval( $interval ) / 1000 );
83
 
84
  // Get playback details
85
  $actions = sanitize_text_field( $_POST['video_a'] );
479
  foreach ( explode( ',', $setup[5] ) as $type_key ) {
480
 
481
  $type_key = sanitize_key( $type_key );
482
+ if ( mycred_point_type_exists( $type_key ) && ! in_array( $type_key, $types ) )
483
  $types[] = $type_key;
484
 
485
  }
includes/mycred-blocks/blocks/mycred-affiliate-id/index.js ADDED
@@ -0,0 +1,53 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /**
2
+ * mb Gutemberg block
3
+ * Copyright (c) 2001-2018. Matteo Bicocchi (Pupunzi)
4
+ */
5
+ //
6
+ (function (wp) {
7
+ var registerBlockType = wp.blocks.registerBlockType;
8
+ var InspectorControls = wp.editor.InspectorControls;
9
+ var el = wp.element.createElement;
10
+ var SelectControl = wp.components.SelectControl;
11
+ var __ = wp.i18n.__;
12
+
13
+ registerBlockType('mycred-blocks/mycred-affiliate-id', {
14
+ title: __('Affiliate ID', 'mycred'),
15
+ category: 'mycred',
16
+ attributes: {
17
+ type: {
18
+ type: 'string'
19
+ }
20
+ },
21
+ edit: function (props) {
22
+ var pt_type = props.attributes.type;
23
+ var content = props.attributes.content;
24
+ var options = [];
25
+ Object.keys(mycred_types).forEach(function (key) {
26
+ options.push({
27
+ label: mycred_types[key],
28
+ value: key
29
+ });
30
+ });
31
+ function setPtType(value) {
32
+ props.setAttributes({type: value});
33
+ }
34
+
35
+ return el('div', {}, [
36
+ el('p', {}, __('Affiliate ID Shortcode', 'mycred')
37
+ ),
38
+ el(InspectorControls, null,
39
+ el(SelectControl, {
40
+ label: __('Point Types', 'mycred'),
41
+ help: __('The point type you want to show the affiliate link for.', 'mycred'),
42
+ value: pt_type,
43
+ onChange: setPtType,
44
+ options
45
+ }),
46
+ )
47
+ ]);
48
+ },
49
+ save: function (props) {
50
+ return null;
51
+ }
52
+ });
53
+ })(window.wp);
includes/mycred-blocks/blocks/mycred-affiliate-id/mycred-affiliate-id.php ADDED
@@ -0,0 +1,24 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ add_action('enqueue_block_editor_assets', 'mycred_affiliate_id');
4
+
5
+ function mycred_affiliate_id() {
6
+
7
+ wp_enqueue_script(
8
+ 'mycred-affiliate-id', plugins_url('index.js', __FILE__), array('wp-blocks', 'wp-element', 'wp-components', 'wp-editor', 'wp-rich-text')
9
+ );
10
+ $mycred_types = mycred_get_types(true);
11
+ $mycred_types = array_merge(array('' => __('Select point type', 'mycred')), $mycred_types);
12
+ wp_localize_script('mycred-affiliate-id', 'mycred_types', $mycred_types);
13
+ }
14
+
15
+ register_block_type('mycred-blocks/mycred-affiliate-id', array(
16
+ 'render_callback' => 'mycred_affiliate_id_callback',
17
+ ));
18
+
19
+ function mycred_affiliate_id_callback($attributes) {
20
+ if ($attributes['type'] == '')
21
+ $attributes['type'] = 'mycred_default';
22
+
23
+ return "[mycred_affiliate_id " . mycred_extract_attributes($attributes) . "]";
24
+ }
includes/mycred-blocks/blocks/mycred-affiliate-link/index.js ADDED
@@ -0,0 +1,67 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /**
2
+ * mb Gutemberg block
3
+ * Copyright (c) 2001-2018. Matteo Bicocchi (Pupunzi)
4
+ */
5
+ //
6
+ (function (wp) {
7
+ var registerBlockType = wp.blocks.registerBlockType;
8
+ var InspectorControls = wp.editor.InspectorControls;
9
+ var el = wp.element.createElement;
10
+ var SelectControl = wp.components.SelectControl;
11
+ var TextControl = wp.components.TextControl;
12
+ var __ = wp.i18n.__;
13
+
14
+ registerBlockType('mycred-blocks/mycred-affiliate-link', {
15
+ title: __('Affiliate Link', 'mycred'),
16
+ category: 'mycred',
17
+ attributes: {
18
+ pt_type: {
19
+ type: 'string'
20
+ },
21
+ url: {
22
+ type: 'string'
23
+ }
24
+ },
25
+ edit: function (props) {
26
+ var pt_type = props.attributes.pt_type;
27
+ var url = props.attributes.url;
28
+ var options = [];
29
+ Object.keys(mycred_types).forEach(function (key) {
30
+ options.push({
31
+ label: mycred_types[key],
32
+ value: key
33
+ });
34
+ });
35
+ function setPtType(value) {
36
+ props.setAttributes({pt_type: value});
37
+ }
38
+ function setUrl(value) {
39
+ props.setAttributes({url: value});
40
+ }
41
+ return el('div', {}, [
42
+ el('p', {}, __('Affiliate Link Shortcode', 'mycred')
43
+ ),
44
+ el(InspectorControls, null,
45
+ el(SelectControl, {
46
+ label: __('Point Types', 'mycred'),
47
+ help: __('The point type you want to show the affiliate link for.', 'mycred'),
48
+ value: pt_type,
49
+ onChange: setPtType,
50
+ options
51
+ }),
52
+ el(TextControl, {
53
+ label: __('URL', 'mycred'),
54
+ help: __('The URL to attach the current users affiliate ID to. No ID is attached for visitors that are not logged in.', 'mycred'),
55
+ type: 'url',
56
+ value: url,
57
+ onChange: setUrl
58
+
59
+ })
60
+ )
61
+ ]);
62
+ },
63
+ save: function (props) {
64
+ return null;
65
+ }
66
+ });
67
+ })(window.wp);
includes/mycred-blocks/blocks/mycred-affiliate-link/mycred-affiliate-link.php ADDED
@@ -0,0 +1,21 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ add_action('enqueue_block_editor_assets', 'mycred_affiliate_link');
4
+
5
+ function mycred_affiliate_link() {
6
+
7
+ wp_enqueue_script(
8
+ 'mycred-affiliate-link', plugins_url('index.js', __FILE__), array('wp-blocks', 'wp-element', 'wp-components', 'wp-editor')
9
+ );
10
+ }
11
+
12
+ register_block_type('mycred-blocks/mycred-affiliate-link', array(
13
+ 'render_callback' => 'mycred_affiliate_link_callback'
14
+ ));
15
+
16
+ function mycred_affiliate_link_callback($attributes) {
17
+ if ($attributes['pt_type'] == '')
18
+ $attributes['pt_type'] = 'mycred_default';
19
+
20
+ return "[mycred_affiliate_link " . mycred_extract_attributes($attributes) . "]";
21
+ }
includes/mycred-blocks/blocks/mycred-badges/index.js ADDED
@@ -0,0 +1,58 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ (function (wp) {
2
+ var registerBlockType = wp.blocks.registerBlockType;
3
+ var InspectorControls = wp.editor.InspectorControls;
4
+ var el = wp.element.createElement;
5
+ var TextControl = wp.components.TextControl;
6
+
7
+ var __ = wp.i18n.__;
8
+ registerBlockType('mycred-blocks/mycred-badges', {
9
+ title: __('Badges', 'mycred'),
10
+ category: 'mycred',
11
+ attributes: {
12
+ width: {
13
+ type: 'string',
14
+ default: 'MYCRED_BADGE_WIDTH'
15
+ },
16
+ height: {
17
+ type: 'string',
18
+ default: 'MYCRED_BADGE_HEIGHT'
19
+ }
20
+ },
21
+ edit: function (props) {
22
+ var width = props.attributes.width;
23
+ var height = props.attributes.height;
24
+
25
+ function setWidth(value) {
26
+ props.setAttributes({width: value});
27
+ }
28
+
29
+ function setHeight(value) {
30
+ props.setAttributes({height: value});
31
+ }
32
+
33
+
34
+ return el('div', {}, [
35
+ el('p', {}, __('Badges Shortcode', 'mycred')
36
+ ),
37
+ el(InspectorControls, null,
38
+ el(TextControl, {
39
+ label: __('Width', 'mycred'),
40
+ help: __('The badge image width to use.', 'mycred'),
41
+ value: width,
42
+ onChange: setWidth
43
+
44
+ }),
45
+ el(TextControl, {
46
+ label: __('Height', 'mycred'),
47
+ help: __('The badge image height to use.', 'mycred'),
48
+ value: height,
49
+ onChange: setHeight
50
+ })
51
+ )
52
+ ]);
53
+ },
54
+ save: function (props) {
55
+ return null;
56
+ }
57
+ });
58
+ })(window.wp);
includes/mycred-blocks/blocks/mycred-badges/mycred-badges.php ADDED
@@ -0,0 +1,17 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ add_action('enqueue_block_editor_assets', 'mycred_badges');
4
+
5
+ function mycred_badges() {
6
+
7
+ wp_enqueue_script(
8
+ 'mycred-badges', plugins_url('index.js', __FILE__), array('wp-blocks', 'wp-element', 'wp-components', 'wp-editor')
9
+ );
10
+ }
11
+ register_block_type('mycred-blocks/mycred-badges', array(
12
+ 'render_callback' => 'mycred_badges_callback'
13
+ ));
14
+
15
+ function mycred_badges_callback($attributes) {
16
+ return "[mycred_badges " . mycred_extract_attributes($attributes) . "]";
17
+ }
includes/mycred-blocks/blocks/mycred-best-user/index.js ADDED
@@ -0,0 +1,151 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /**
2
+ * mb Gutemberg block
3
+ * Copyright (c) 2001-2018. Matteo Bicocchi (Pupunzi)
4
+ */
5
+ (function (wp) {
6
+ var registerBlockType = wp.blocks.registerBlockType;
7
+ var InspectorControls = wp.editor.InspectorControls;
8
+ var el = wp.element.createElement;
9
+ var SelectControl = wp.components.SelectControl;
10
+ var TextControl = wp.components.TextControl;
11
+ var TextareaControl = wp.components.TextareaControl;
12
+ var RichText = wp.editor.RichText;
13
+
14
+ var __ = wp.i18n.__;
15
+
16
+
17
+ registerBlockType('mycred-blocks/mycred-best-user', {
18
+ title: __('Best User', 'mycred'),
19
+ category: 'mycred',
20
+ attributes: {
21
+ ref: {
22
+ type: 'string'
23
+ },
24
+ from: {
25
+ type: 'string'
26
+ },
27
+ until: {
28
+ type: 'string'
29
+ },
30
+ types: {
31
+ type: 'string'
32
+ },
33
+ nothing: {
34
+ type: 'string',
35
+ default: 'No user found'
36
+ },
37
+ order: {
38
+ type: 'string'
39
+ },
40
+ avatar: {
41
+ type: 'integer',
42
+ default: '50'
43
+ },
44
+ content: {
45
+ type: 'string',
46
+ default: '<div class="mycred-best-user">%avatar%<h4>%display_name%</h4></div>'
47
+ }
48
+ },
49
+ edit: function (props) {
50
+ var ref = props.attributes.ref;
51
+ var from = props.attributes.from;
52
+ var until = props.attributes.until;
53
+ var types = props.attributes.types;
54
+ var nothing = props.attributes.nothing;
55
+ var order = props.attributes.order;
56
+ var avatar = props.attributes.avatar;
57
+ var content = props.attributes.content;
58
+
59
+ function setRef(value) {
60
+ props.setAttributes({ref: value});
61
+ }
62
+ function setFrom(value) {
63
+ props.setAttributes({from: value});
64
+ }
65
+ function setUntil(value) {
66
+ props.setAttributes({until: value});
67
+ }
68
+ function setTypes(value) {
69
+ props.setAttributes({types: value});
70
+ }
71
+ function setNth(value) {
72
+ props.setAttributes({nothing: value});
73
+ }
74
+ function setOrder(value) {
75
+ props.setAttributes({order: value});
76
+ }
77
+ function setAvatar(value) {
78
+ props.setAttributes({avatar: value});
79
+ }
80
+
81
+ function setContent(value) {
82
+ props.setAttributes({content: value});
83
+ }
84
+
85
+ return el('div', {}, [
86
+ el('p', {}, __('Best User Shortcode', 'mycred')
87
+ ),
88
+ el(InspectorControls, null,
89
+ el(TextareaControl, {
90
+ label: __('Reference(s)', 'mycred'),
91
+ help: __('Comma separated list of references to add up.', 'mycred'),
92
+ rows: 2,
93
+ value: ref,
94
+ onChange: setRef
95
+ }),
96
+ el(TextControl, {
97
+ label: __('From', 'mycred'),
98
+ help: __('Option to sum up results from a specific date. Can be used in combination with "Until". Leave empty if not used.', 'mycred'),
99
+ value: from,
100
+ onChange: setFrom
101
+ }),
102
+ el(TextControl, {
103
+ label: __('Until', 'mycred'),
104
+ help: __('Option to sum up results until a specific date. Can be used in combination with "From". Leave empty if not used.', 'mycred'),
105
+ value: until,
106
+ onChange: setUntil
107
+ }),
108
+ el(TextareaControl, {
109
+ label: __('Point Type(s)', 'mycred'),
110
+ help: __('A single point type or a comma separated list of point types to use. Use "mycred_default" for the default point type. Can not be empty.', 'mycred'),
111
+ rows: 2,
112
+ value: types,
113
+ onChange: setTypes
114
+ }),
115
+ el(TextControl, {
116
+ label: __('No Results', 'mycred'),
117
+ help: __('Information to show if no results were found. No HTML allowed.', 'mycred'),
118
+ value: nothing,
119
+ onChange: setNth
120
+ }),
121
+ el(SelectControl, {
122
+ label: __('Order', 'mycred'),
123
+ help: __('Order of the results.', 'mycred'),
124
+ value: order,
125
+ onChange: setOrder,
126
+ options: [
127
+ {label: 'Descending', value: 'DESC'},
128
+ {label: 'Ascending', value: 'ASC'}
129
+ ]
130
+ }),
131
+ el(TextControl, {
132
+ label: __('Avatar', 'mycred'),
133
+ help: __('The size of the avatar, if the %avatar% template tag is used in your template', 'mycred'),
134
+ value: avatar,
135
+ onChange: setAvatar
136
+ }),
137
+ el(TextareaControl, {
138
+ label: __('Content', 'mycred'),
139
+ help: __('Content to show visitors viewing this shortcode. Leave empty to show nothing.', 'mycred'),
140
+ value: content,
141
+ onChange: setContent,
142
+ rows:2
143
+ })
144
+ )
145
+ ]);
146
+ },
147
+ save: function (props) {
148
+ return null;
149
+ }
150
+ });
151
+ })(window.wp);
includes/mycred-blocks/blocks/mycred-best-user/mycred-best-user.php ADDED
@@ -0,0 +1,23 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ add_action('enqueue_block_editor_assets', 'mycred_best_user');
4
+
5
+ function mycred_best_user() {
6
+
7
+ wp_enqueue_script(
8
+ 'mycred-best-user', plugins_url('index.js', __FILE__), array('wp-blocks', 'wp-element', 'wp-components', 'wp-editor')
9
+ );
10
+ }
11
+
12
+ register_block_type('mycred-blocks/mycred-best-user', array(
13
+ 'render_callback' => 'mycred_best_user_callback',
14
+ ));
15
+
16
+ function mycred_best_user_callback($attributes) {
17
+ $content = "";
18
+ if (isset($attributes['content'])) {
19
+ $content = $attributes['content'];
20
+ }
21
+ unset($attributes['content']);
22
+ return "[mycred_best_user " . mycred_extract_attributes($attributes) . "]" . $content . "[/mycred_best_user]";
23
+ }
includes/mycred-blocks/blocks/mycred-buy-form/index.js ADDED
@@ -0,0 +1,132 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ (function (wp) {
2
+ var registerBlockType = wp.blocks.registerBlockType;
3
+ var InspectorControls = wp.editor.InspectorControls;
4
+ var el = wp.element.createElement;
5
+ var TextControl = wp.components.TextControl;
6
+ var SelectControl = wp.components.SelectControl;
7
+ var ToggleControl = wp.components.ToggleControl;
8
+ var __ = wp.i18n.__;
9
+ registerBlockType('mycred-blocks/mycred-buy-form', {
10
+ title: __('Buy Form', 'mycred'),
11
+ category: 'mycred',
12
+ attributes: {
13
+ button: {
14
+ type: 'string',
15
+ default: 'Buy Now'
16
+ },
17
+ gateway: {
18
+ type: 'string'
19
+ },
20
+ ctype: {
21
+ type: 'string'
22
+ },
23
+ amount: {
24
+ type: 'string'
25
+ },
26
+ gift_to: {
27
+ type: 'string'
28
+ },
29
+ gift_by: {
30
+ type: 'string'
31
+ },
32
+ inline: {
33
+ type: 'bool',
34
+ default: false
35
+ }
36
+
37
+ },
38
+ edit: function (props) {
39
+ var button = props.attributes.button;
40
+ var gateway = props.attributes.title;
41
+ var ctype = props.attributes.ctype;
42
+ var amount = props.attributes.amount;
43
+ var gift_to = props.attributes.gift_to;
44
+ var gift_by = props.attributes.gift_by;
45
+
46
+ var inline = props.attributes.inline;
47
+
48
+ var options = [];
49
+ function setGateway(value) {
50
+ props.setAttributes({gateway: value});
51
+ }
52
+
53
+ function setButton(value) {
54
+ props.setAttributes({button: value});
55
+ }
56
+
57
+ function setType(value) {
58
+ props.setAttributes({ctype: value});
59
+ }
60
+ function setAmount(value) {
61
+ props.setAttributes({amount: value});
62
+ }
63
+ function setGiftTo(value) {
64
+ props.setAttributes({gift_to: value});
65
+ }
66
+ function setGiftBy(value) {
67
+ props.setAttributes({gift_by: value});
68
+ }
69
+ function setInline(value) {
70
+ props.setAttributes({inline: value});
71
+ }
72
+
73
+ Object.keys(mycred_types).forEach(function (key) {
74
+ options.push({
75
+ label: mycred_types[key],
76
+ value: key
77
+ });
78
+ });
79
+ return el('div', {}, [
80
+ el('p', {}, __('Buy Form Shortcode', 'mycred')
81
+ ),
82
+ el(InspectorControls, null,
83
+ el(TextControl, {
84
+ label: __('Button Label', 'mycred'),
85
+ help: __('The label for the form submit button.', 'mycred'),
86
+ value: button,
87
+ onChange: setButton
88
+ }),
89
+ el(TextControl, {
90
+ label: __('Gateway', 'mycred'),
91
+ help: __('Enter the gateway ID to enforce the use of a specific gateway or leave empty to let users choose.', 'mycred'),
92
+ value: gateway,
93
+ onChange: setGateway,
94
+ }),
95
+ el(SelectControl, {
96
+ label: __('Point Type', 'mycred'),
97
+ help: __('The point type you want to show.', 'mycred'),
98
+ value: ctype,
99
+ onChange: setType,
100
+ options
101
+ }),
102
+ el(TextControl, {
103
+ label: __('Amount', 'mycred'),
104
+ help: __('This can either be a set amount for users to buy, a comma separated list of amounts that users can choose from or left empty in which case the user decides how much they want to buy..', 'mycred'),
105
+ value: amount,
106
+ onChange: setAmount
107
+ }),
108
+ el(TextControl, {
109
+ label: __('Gift to', 'mycred'),
110
+ help: __('By default, the current user will receive the purchased amount. Use "author" to gift purchases to the post author or a specific users ID. Leave empty if not used!', 'mycred'),
111
+ value: gift_to,
112
+ onChange: setGiftTo
113
+ }),
114
+ el(TextControl, {
115
+ label: __('Gift By', 'mycred'),
116
+ value: gift_by,
117
+ onChange: setGiftBy
118
+ }),
119
+ el(ToggleControl, {
120
+ label: __('Inline', 'mycred'),
121
+ help: __('Controls if the form should be inline (1) or not (0). Requires themes using the Bootstrap framework.', 'mycred'),
122
+ checked: inline,
123
+ onChange: setInline
124
+ }),
125
+ )
126
+ ]);
127
+ },
128
+ save: function (props) {
129
+ return null;
130
+ }
131
+ });
132
+ })(window.wp);
includes/mycred-blocks/blocks/mycred-buy-form/mycred-buy-form.php ADDED
@@ -0,0 +1,18 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ add_action('enqueue_block_editor_assets', 'mycred_buy_form');
4
+
5
+ function mycred_buy_form() {
6
+
7
+ wp_enqueue_script(
8
+ 'mycred-buy-form', plugins_url('index.js', __FILE__), array('wp-blocks', 'wp-element', 'wp-components', 'wp-editor')
9
+ );
10
+ }
11
+
12
+ register_block_type('mycred-blocks/mycred-buy-form', array(
13
+ 'render_callback' => 'mycred_buy_form_callback'
14
+ ));
15
+
16
+ function mycred_buy_form_callback($attributes) {
17
+ return "[mycred_buy_form " . mycred_extract_attributes($attributes) . "]";
18
+ }
includes/mycred-blocks/blocks/mycred-buy/index.js ADDED
@@ -0,0 +1,142 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ (function (wp) {
2
+ var registerBlockType = wp.blocks.registerBlockType;
3
+ var InspectorControls = wp.editor.InspectorControls;
4
+ var el = wp.element.createElement;
5
+ var TextControl = wp.components.TextControl;
6
+ var SelectControl = wp.components.SelectControl;
7
+
8
+ var __ = wp.i18n.__;
9
+ registerBlockType('mycred-blocks/mycred-buy', {
10
+ title: __('Buy', 'mycred'),
11
+ category: 'mycred',
12
+ attributes: {
13
+ link_title: {
14
+ type: 'string'
15
+ },
16
+ gateway: {
17
+ type: 'string'
18
+ },
19
+ type: {
20
+ type: 'string'
21
+ },
22
+ amount: {
23
+ type: 'string'
24
+ },
25
+ gift_to: {
26
+ type: 'string'
27
+ },
28
+ clss: {
29
+ type: 'string',
30
+ default: 'mycred-buy-link btn btn-primary btn-lg'
31
+ },
32
+ login: {
33
+ type: 'string',
34
+ default: 'buyCRED Settings'
35
+ }
36
+
37
+ },
38
+ edit: function (props) {
39
+ var link_title = props.attributes.link_title;
40
+ var gateway = props.attributes.gateway;
41
+ var type = props.attributes.type;
42
+ var amount = props.attributes.amount;
43
+ var gift_to = props.attributes.balance_el;
44
+
45
+ var clss = props.attributes.clss;
46
+ var login = props.attributes.login;
47
+
48
+ var options = [];
49
+ var gatewayopt = [];
50
+
51
+ function setLinkTitle(value) {
52
+ props.setAttributes({link_title: value});
53
+ }
54
+ function setGateway(value) {
55
+ props.setAttributes({gateway: value});
56
+ }
57
+
58
+ function setType(value) {
59
+ props.setAttributes({type: value});
60
+ }
61
+ function setAmount(value) {
62
+ props.setAttributes({amount: value});
63
+ }
64
+ function setGiftTo(value) {
65
+ props.setAttributes({gift_to: value});
66
+ }
67
+ function setClass(value) {
68
+ props.setAttributes({clss: value});
69
+ }
70
+ function setLogin(value) {
71
+ props.setAttributes({login: value});
72
+ }
73
+
74
+ Object.keys(mycred_types).forEach(function (key) {
75
+ options.push({
76
+ label: mycred_types[key],
77
+ value: key
78
+ });
79
+ });
80
+
81
+ Object.keys(mycred_buy).forEach(function (key) {
82
+ gatewayopt.push({
83
+ label: key,
84
+ value: mycred_buy[key]
85
+ });
86
+ });
87
+ return el('div', {}, [
88
+ el('p', {}, __('Buy Shortcode', 'mycred')
89
+ ),
90
+ el(InspectorControls, null,
91
+ el(TextControl, {
92
+ label: __('Link Title', 'mycred'),
93
+ help: __('The purchase link title. If not set, the anchor element will be rendered but will be empty. Only leave this entry if you intend to style the element and need this to be empty!', 'mycred'),
94
+ value: link_title,
95
+ onChange: setLinkTitle
96
+ }),
97
+ el(SelectControl, {
98
+ label: __('Gateway', 'mycred'),
99
+ help: __('Required payment gateway to use for this purchase.', 'mycred'),
100
+ value: gateway,
101
+ onChange: setGateway,
102
+ options: gatewayopt
103
+ }),
104
+ el(SelectControl, {
105
+ label: __('Point Type', 'mycred'),
106
+ help: __('The point type you want to show.', 'mycred'),
107
+ value: type,
108
+ onChange: setType,
109
+ options
110
+ }),
111
+ el(TextControl, {
112
+ label: __('Amount', 'mycred'),
113
+ help: __('Amount of points to purchase.', 'mycred'),
114
+ value: amount,
115
+ onChange: setAmount
116
+ }),
117
+ el(TextControl, {
118
+ label: __('Gift to', 'mycred'),
119
+ help: __('By default, the current user will receive the purchased amount. Use "author" to gift purchases to the post author or a specific users ID. Leave empty if not used!', 'mycred'),
120
+ value: gift_to,
121
+ onChange: setGiftTo
122
+ }),
123
+ el(TextControl, {
124
+ label: __('Class', 'mycred'),
125
+ help: __('Optional class to add to the purchase link element', 'mycred'),
126
+ value: clss,
127
+ onChange: setClass
128
+ }),
129
+ el(TextControl, {
130
+ label: __('Login Message', 'mycred'),
131
+ help: __('Optional message to show logged out users viewing this shortcode. Nothing is returned if left empty.', 'mycred'),
132
+ value: login,
133
+ onChange: setLogin
134
+ }),
135
+ )
136
+ ]);
137
+ },
138
+ save: function (props) {
139
+ return null;
140
+ }
141
+ });
142
+ })(window.wp);
includes/mycred-blocks/blocks/mycred-buy/mycred-buy.php ADDED
@@ -0,0 +1,36 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ add_action('enqueue_block_editor_assets', 'mycred_buy');
4
+
5
+ function mycred_buy() {
6
+
7
+ wp_enqueue_script(
8
+ 'mycred-buy', plugins_url('index.js', __FILE__), array('wp-blocks', 'wp-element', 'wp-components', 'wp-editor')
9
+ );
10
+
11
+ $buycred = new myCRED_buyCRED_Module();
12
+ $gateways = array();
13
+ foreach ($buycred->get() as $gateway_id => $gateway) {
14
+ $gateways[$gateway['title']] = $gateway_id;
15
+ }
16
+
17
+ wp_localize_script('mycred-buy', 'mycred_buy', $gateways);
18
+ }
19
+
20
+ register_block_type('mycred-blocks/mycred-buy', array(
21
+ 'render_callback' => 'mycred_buy_callback'
22
+ ));
23
+
24
+ function mycred_buy_callback($attributes) {
25
+ if ($attributes['clss']) {
26
+ $attributes['class'] = $attributes['clss'];
27
+ unset($attributes['clss']);
28
+ }
29
+
30
+ if ($attributes['link_title']) {
31
+ $content = $attributes['link_title'];
32
+ }
33
+ unset($attributes['link_title']);
34
+
35
+ return "[mycred_buy " . mycred_extract_attributes($attributes) . "]" . $content . "[/mycred_buy]";
36
+ }
includes/mycred-blocks/blocks/mycred-email-subsc/index.js ADDED
@@ -0,0 +1,41 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ (function (wp) {
2
+ var registerBlockType = wp.blocks.registerBlockType;
3
+ var InspectorControls = wp.editor.InspectorControls;
4
+ var el = wp.element.createElement;
5
+ var TextControl = wp.components.TextControl;
6
+
7
+ var __ = wp.i18n.__;
8
+ registerBlockType('mycred-blocks/mycred-email-subsc', {
9
+ title: __('Email Subscriptions', 'mycred'),
10
+ category: 'mycred',
11
+ attributes: {
12
+ success: {
13
+ type: 'string',
14
+ default: 'Settings Updated'
15
+ }
16
+ },
17
+ edit: function (props) {
18
+ var success = props.attributes.success;
19
+
20
+ function setSuccess(value) {
21
+ props.setAttributes({success: value});
22
+ }
23
+
24
+ return el('div', {}, [
25
+ el('p', {}, __('Email Subscriptions Shortcode', 'mycred')
26
+ ),
27
+ el(InspectorControls, null,
28
+ el(TextControl, {
29
+ label: __('Success', 'mycred'),
30
+ help: __('Message to show when settings have been changed.', 'mycred'),
31
+ value: success,
32
+ onChange: setSuccess
33
+ })
34
+ )
35
+ ]);
36
+ },
37
+ save: function (props) {
38
+ return null;
39
+ }
40
+ });
41
+ })(window.wp);
includes/mycred-blocks/blocks/mycred-email-subsc/mycred-email-subsc.php ADDED
@@ -0,0 +1,18 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ add_action('enqueue_block_editor_assets', 'mycred_email_subsc');
4
+
5
+ function mycred_email_subsc() {
6
+
7
+ wp_enqueue_script(
8
+ 'mycred-email-subsc', plugins_url('index.js', __FILE__), array('wp-blocks', 'wp-element', 'wp-components', 'wp-editor')
9
+ );
10
+
11
+ }
12
+ register_block_type('mycred-blocks/mycred-email-subsc', array(
13
+ 'render_callback' => 'mycred_email_subsc_callback'
14
+ ));
15
+
16
+ function mycred_email_subsc_callback($attributes) {
17
+ return "[mycred_email_subscriptions " . mycred_extract_attributes($attributes) . "]";
18
+ }
includes/mycred-blocks/blocks/mycred-exchange/index.js ADDED
@@ -0,0 +1,108 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /**
2
+ * mb Gutemberg block
3
+ * Copyright (c) 2001-2018. Matteo Bicocchi (Pupunzi)
4
+ */
5
+ //
6
+ (function (wp) {
7
+ var registerBlockType = wp.blocks.registerBlockType;
8
+ var InspectorControls = wp.editor.InspectorControls;
9
+ var BlockControls = wp.editor.BlockControls;
10
+ var el = wp.element.createElement;
11
+ var SelectControl = wp.components.SelectControl;
12
+ var TextControl = wp.components.TextControl;
13
+ var __ = wp.i18n.__;
14
+ registerBlockType('mycred-blocks/mycred-exchange', {
15
+ title: __('Exchange', 'mycred'),
16
+ category: 'mycred',
17
+ attributes: {
18
+ from: {
19
+ type: 'string'
20
+ },
21
+ to: {
22
+ type: 'string'
23
+ },
24
+ rate: {
25
+ type: 'string',
26
+ default: '1'
27
+ },
28
+ min: {
29
+ type: 'string',
30
+ default: '1'
31
+ },
32
+ button: {
33
+ type: 'string',
34
+ default: 'Exchange'
35
+ }
36
+ },
37
+ edit: function (props) {
38
+ var from = props.attributes.from;
39
+ var to = props.attributes.to;
40
+ var rate = props.attributes.rate;
41
+ var min = props.attributes.min;
42
+ var button = props.attributes.button;
43
+ var options = [];
44
+ Object.keys(mycred_types).forEach(function (key) {
45
+ options.push({
46
+ label: mycred_types[key],
47
+ value: key
48
+ });
49
+ });
50
+ function setFrom(value) {
51
+ props.setAttributes({from: value});
52
+ }
53
+ function setTo(value) {
54
+ props.setAttributes({to: value});
55
+ }
56
+ function setRate(value) {
57
+ props.setAttributes({rate: value});
58
+ }
59
+ function setMin(value) {
60
+ props.setAttributes({min: value});
61
+ }
62
+ function setButton(value) {
63
+ props.setAttributes({button: value});
64
+ }
65
+ return el('div', {}, [
66
+ el('p', {}, 'Exchange Shortcode'
67
+ ),
68
+ el(InspectorControls, null,
69
+ el(SelectControl, {
70
+ label: __('From', 'mycred'),
71
+ helper: __('The point type to exchange from', 'mycred'),
72
+ value: from,
73
+ onChange: setFrom,
74
+ options
75
+ }),
76
+ el(SelectControl, {
77
+ label: __('To', 'mycred'),
78
+ helper: __('The point type to exchange to', 'mycred'),
79
+ value: to,
80
+ onChange: setTo,
81
+ options
82
+ }),
83
+ el(TextControl, {
84
+ label: __('Rate', 'mycred'),
85
+ helper: __('The exchange rate', 'mycred'),
86
+ value: rate,
87
+ onChange: setRate
88
+ }),
89
+ el(TextControl, {
90
+ label: __('Minimum', 'mycred'),
91
+ helper: __('Minimum amount that a user must select to exchange. Use zero for no limit.', 'mycred'),
92
+ value: min,
93
+ onChange: setMin
94
+ }),
95
+ el(TextControl, {
96
+ label: __('Button Label', 'mycred'),
97
+ helper: __('The submit button label', 'mycred'),
98
+ value: button,
99
+ onChange: setButton
100
+ }),
101
+ )
102
+ ]);
103
+ },
104
+ save: function (props) {
105
+ return null;
106
+ }
107
+ });
108
+ })(window.wp);
includes/mycred-blocks/blocks/mycred-exchange/mycred-exchange.php ADDED
@@ -0,0 +1,18 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ add_action('enqueue_block_editor_assets', 'mycred_exchange');
4
+
5
+ function mycred_exchange() {
6
+
7
+ wp_enqueue_script(
8
+ 'mycred-exchange', plugins_url('index.js', __FILE__), array('wp-blocks', 'wp-element', 'wp-components', 'wp-editor')
9
+ );
10
+ }
11
+
12
+ register_block_type('mycred-blocks/mycred-exchange', array(
13
+ 'render_callback' => 'mycred_exchange_user_callback',
14
+ ));
15
+
16
+ function mycred_exchange_user_callback($attributes) {
17
+ return "[mycred_exchange " . mycred_extract_attributes($attributes) . "]";
18
+ }
includes/mycred-blocks/blocks/mycred-give/index.js ADDED
@@ -0,0 +1,135 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /**
2
+ * mb Gutemberg block
3
+ * Copyright (c) 2001-2018. Matteo Bicocchi (Pupunzi)
4
+ */
5
+ //
6
+ (function (wp) {
7
+ var registerBlockType = wp.blocks.registerBlockType;
8
+ var InspectorControls = wp.editor.InspectorControls;
9
+ var el = wp.element.createElement;
10
+ var SelectControl = wp.components.SelectControl;
11
+ var TextControl = wp.components.TextControl;
12
+ var TextareaControl = wp.components.TextareaControl;
13
+ var __ = wp.i18n.__;
14
+
15
+ registerBlockType('mycred-blocks/mycred-give', {
16
+ title: __('Give'),
17
+ category: 'mycred',
18
+ attributes: {
19
+ amount: {
20
+ type: 'string'
21
+ },
22
+ user_id: {
23
+ type: 'string'
24
+ },
25
+ log: {
26
+ type: 'string'
27
+ },
28
+ ref: {
29
+ type: 'string',
30
+ default: 'give'
31
+ },
32
+ limit: {
33
+ type: 'string',
34
+ default: 0
35
+ },
36
+ type: {
37
+ type: 'string'
38
+ },
39
+ content: {
40
+ type: 'string',
41
+ default: ''
42
+ }
43
+ },
44
+ edit: function (props) {
45
+ var amount = props.attributes.amount;
46
+ var user_id = props.attributes.user_id;
47
+ var log = props.attributes.log;
48
+ var ref = props.attributes.ref;
49
+ var limit = props.attributes.limit;
50
+ var pt_type = props.attributes.type;
51
+ var content = props.attributes.content;
52
+
53
+ var options = [];
54
+ Object.keys(mycred_types).forEach(function (key) {
55
+ options.push({
56
+ label: mycred_types[key],
57
+ value: key
58
+ });
59
+ });
60
+ function setRate(value) {
61
+ props.setAttributes({amount: value});
62
+ }
63
+ function setUserId(value) {
64
+ props.setAttributes({user_id: value});
65
+ }
66
+ function setLog(value) {
67
+ props.setAttributes({log: value});
68
+ }
69
+ function setReference(value) {
70
+ props.setAttributes({ref: value});
71
+ }
72
+ function setLimit(value) {
73
+ props.setAttributes({limit: value});
74
+ }
75
+ function setPtType(value) {
76
+ props.setAttributes({type: value});
77
+ }
78
+ function setContent(value) {
79
+ props.setAttributes({content: value});
80
+ }
81
+ return el('div', {}, [
82
+ el('p', {}, 'Give Shortcode'
83
+ ),
84
+ el(InspectorControls, null,
85
+ el(TextControl, {
86
+ label: __('Amount', 'mycred'),
87
+ help: __('Required amount to give the user when this shortcode fires', 'mycred'),
88
+ value: amount,
89
+ onChange: setRate
90
+ }),
91
+ el(TextControl, {
92
+ label: __('User ID', 'mycred'),
93
+ help: __('Option to award a specific user. Use "current" to use five points to the user that views the shortcode. Can not be empty.', 'mycred'),
94
+ value: user_id,
95
+ onChange: setUserId
96
+ }),
97
+ el(TextControl, {
98
+ label: __('Log Entry', 'mycred'),
99
+ help: __('The log entry template. Can not be empty. Does not support HTML elements.', 'mycred'),
100
+ value: log,
101
+ onChange: setLog
102
+ }),
103
+ el(TextControl, {
104
+ label: __('Reference', 'mycred'),
105
+ help: __('A reference to log this transaction under. Can not be empty and must be a lowercase string. Instead of empty spaces please use underscores.', 'mycred'),
106
+ value: ref,
107
+ onChange: setReference
108
+ }),
109
+ el(TextControl, {
110
+ label: __('Limit', 'mycred'),
111
+ help: __('Optional limit the number of times a user can gain points from this shortcode. Use zero for no limit.', 'mycred'),
112
+ value: limit,
113
+ onChange: setLimit
114
+ }),
115
+ el(SelectControl, {
116
+ label: __('Point Type', 'mycred'),
117
+ help: __('The point type you want to give.', 'mycred'),
118
+ value: pt_type,
119
+ onChange: setPtType,
120
+ options
121
+ }),
122
+ el(TextareaControl, {
123
+ label: __('Content', 'mycred'),
124
+ help: __('Content to show visitors viewing this shortcode. Leave empty to show nothing.', 'mycred'),
125
+ value: content,
126
+ onChange: setContent
127
+ })
128
+ )
129
+ ]);
130
+ },
131
+ save: function (props) {
132
+ return null;
133
+ }
134
+ });
135
+ })(window.wp);
includes/mycred-blocks/blocks/mycred-give/mycred-give.php ADDED
@@ -0,0 +1,26 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ add_action('enqueue_block_editor_assets', 'mycred_give');
4
+
5
+ function mycred_give() {
6
+
7
+ wp_enqueue_script(
8
+ 'mycred-give', plugins_url('index.js', __FILE__), array('wp-blocks', 'wp-element', 'wp-components', 'wp-editor')
9
+ );
10
+ }
11
+
12
+ register_block_type('mycred-blocks/mycred-give', array(
13
+ 'render_callback' => 'mycred_give_callback'
14
+ ));
15
+
16
+ function mycred_give_callback($attributes) {
17
+ if ($attributes['type'] == ''){
18
+ $attributes['type'] = 'mycred_default';
19
+ }
20
+ $content='';
21
+ if ($attributes['content'] == '') {
22
+ $content = $attributes['content'];
23
+ }
24
+ unset($attributes['content']);
25
+ return "[mycred_give " . mycred_extract_attributes($attributes) . "]" . $content . "[/mycred_give]";
26
+ }
includes/mycred-blocks/blocks/mycred-history/index.js ADDED
@@ -0,0 +1,198 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ (function (wp) {
2
+ var registerBlockType = wp.blocks.registerBlockType;
3
+ var InspectorControls = wp.editor.InspectorControls;
4
+ var el = wp.element.createElement;
5
+ var TextControl = wp.components.TextControl;
6
+ var SelectControl = wp.components.SelectControl;
7
+ var ToggleControl = wp.components.ToggleControl;
8
+ var __ = wp.i18n.__;
9
+ registerBlockType('mycred-blocks/mycred-history', {
10
+ title: __('History', 'mycred'),
11
+ category: 'mycred',
12
+ attributes: {
13
+ user_id: {
14
+ type: 'string'
15
+ },
16
+ number: {
17
+ type: 'integer',
18
+ default: '10'
19
+ },
20
+ time: {
21
+ type: 'string'
22
+ },
23
+ ref: {
24
+ type: 'string'
25
+ },
26
+ order: {
27
+ type: 'string'
28
+ },
29
+ show_user: {
30
+ type: 'bool',
31
+ default: false
32
+ },
33
+ show_nav: {
34
+ type: 'bool',
35
+ default: true
36
+ },
37
+ login: {
38
+ type: 'string'
39
+ },
40
+ type: {
41
+ type: 'string'
42
+ },
43
+ pagination: {
44
+ type: 'integer',
45
+ default: '10'
46
+ },
47
+ inlinenav: {
48
+ type: 'bool',
49
+ default: false
50
+ }
51
+ },
52
+ edit: function (props) {
53
+ var user_id = props.attributes.user_id;
54
+ var number = props.attributes.number;
55
+ var time = props.attributes.time;
56
+ var ref = props.attributes.ref;
57
+ var order = props.attributes.order;
58
+ var show_user = props.attributes.show_user;
59
+ var show_nav = props.attributes.show_nav;
60
+ var login = props.attributes.login;
61
+ var type = props.attributes.type;
62
+ var pagination = props.attributes.pagination;
63
+ var inlinenav = props.attributes.inlinenav;
64
+
65
+ var options = [];
66
+
67
+ function setUserId(value) {
68
+ props.setAttributes({user_id: value});
69
+ }
70
+ function setNumber(value) {
71
+ props.setAttributes({number: value});
72
+ }
73
+ function setTime(value) {
74
+ props.setAttributes({time: value});
75
+ }
76
+ function setRef(value) {
77
+ props.setAttributes({ref: value});
78
+ }
79
+ function setOrder(value) {
80
+ props.setAttributes({order: value});
81
+ }
82
+ function setShowUser(value) {
83
+ props.setAttributes({show_user: value});
84
+ }
85
+ function setShowNav(value) {
86
+ props.setAttributes({show_nav: value});
87
+ }
88
+ function setLogin(value) {
89
+ props.setAttributes({login: value});
90
+ }
91
+ function setType(value) {
92
+ props.setAttributes({type: value});
93
+ }
94
+ function setPag(value) {
95
+ props.setAttributes({pagination: value});
96
+ }
97
+ function setInlineNav(value) {
98
+ props.setAttributes({inlinenav: value});
99
+ }
100
+ Object.keys(mycred_types).forEach(function (key) {
101
+ options.push({
102
+ label: mycred_types[key],
103
+ value: key
104
+ });
105
+ });
106
+ return el('div', {}, [
107
+ el('p', {}, __('History Shortcode', 'mycred')
108
+ ),
109
+ el(InspectorControls, null,
110
+ el(TextControl, {
111
+ label: __('User ID', 'mycred'),
112
+ help: __('Option to show a specific users history. Use "current" to show the current users history or leave empty to show everyones history.', 'mycred'),
113
+ value: user_id,
114
+ onChange: setUserId
115
+
116
+ }),
117
+ el(TextControl, {
118
+ label: __('Number of Entries', 'mycred'),
119
+ help: __('The number of entries to show per page. Defaults to 10.', 'mycred'),
120
+ value: number,
121
+ onChange: setNumber
122
+
123
+ }),
124
+ el(SelectControl, {
125
+ label: __('Time', 'mycred'),
126
+ help: __('Option to return entries for specific time period.', 'mycred'),
127
+ value: time,
128
+ onChange: setTime,
129
+ options: [
130
+ {label: 'Show All', value: ''},
131
+ {label: 'Today', value: 'today'},
132
+ {label: 'Yesterday', value: 'yesterday'},
133
+ {label: 'This Week', value: 'thisweek'},
134
+ {label: 'This Month', value: 'thismonth'}
135
+ ]
136
+ }),
137
+ el(TextControl, {
138
+ label: __('Reference', 'mycred'),
139
+ help: __('Option to only show log entries for the specified reference. Can be a single reference or a comma separated list of references (without any empty spaces).', 'mycred'),
140
+ value: ref,
141
+ onChange: setRef
142
+
143
+ }),
144
+ el(SelectControl, {
145
+ label: __('Order', 'mycred'),
146
+ help: __('Order of the log entries. Either ASC for ascending or DESC for descending.', 'mycred'),
147
+ value: order,
148
+ onChange: setOrder,
149
+ options: [
150
+ {label: 'Descending', value: 'DESC'},
151
+ {label: 'Ascending', value: 'ASC'}
152
+ ]
153
+ }),
154
+ el(ToggleControl, {
155
+ label: __('Show User Column?', 'mycred'),
156
+ checked: show_user,
157
+ onChange: setShowUser
158
+
159
+ }),
160
+ el(ToggleControl, {
161
+ label: __('Show Navigation?', 'mycred'),
162
+ checked: show_nav,
163
+ onChange: setShowNav
164
+ }),
165
+ el(TextControl, {
166
+ label: __('Login Message', 'mycred'),
167
+ help: __('Message to show a logged out user trying to view this shortcode. Leave empty if you want visitors to see the log as well.', 'mycred'),
168
+ value: login,
169
+ onChange: setLogin
170
+
171
+ }),
172
+ el(SelectControl, {
173
+ label: __('Point Type', 'mycred'),
174
+ help: __('The point type requirement. This controls not just balance requirements but also rank requirement and the reference count requirement above.', 'mycred'),
175
+ value: type,
176
+ onChange: setType,
177
+ options
178
+ }),
179
+ el(TextControl, {
180
+ label: __('Pagination', 'mycred'),
181
+ help: __('The number of pagination links to show. Ignored if you set to hide navigation above. (Requires 1.7)', 'mycred'),
182
+ value: pagination,
183
+ onChange: setPag
184
+ }),
185
+ el(ToggleControl, {
186
+ label: __('Inline Navigation?', 'mycred'),
187
+ help: __('If your theme is rendering the navigation vertically instead of horizontally, make sure you select "Yes" here.', 'mycred'),
188
+ checked: inlinenav,
189
+ onChange: setInlineNav
190
+ }),
191
+ )
192
+ ]);
193
+ },
194
+ save: function (props) {
195
+ return null;
196
+ }
197
+ });
198
+ })(window.wp);
includes/mycred-blocks/blocks/mycred-history/mycred-history.php ADDED
@@ -0,0 +1,22 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ add_action('enqueue_block_editor_assets', 'mycred_history');
4
+
5
+ function mycred_history() {
6
+
7
+ wp_enqueue_script(
8
+ 'mycred-history', plugins_url('index.js', __FILE__), array('wp-blocks', 'wp-element', 'wp-components', 'wp-editor')
9
+ );
10
+ }
11
+
12
+ register_block_type('mycred-blocks/mycred-history', array(
13
+ 'render_callback' => 'mycred_history_callback'
14
+ ));
15
+
16
+ function mycred_history_callback($attributes) {
17
+
18
+ if ($attributes['type'] == '')
19
+ $attributes['type'] = 'mycred_default';
20
+
21
+ return "[mycred_history " . mycred_extract_attributes($attributes) . "]";
22
+ }
includes/mycred-blocks/blocks/mycred-hook-table/index.js ADDED
@@ -0,0 +1,134 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ (function (wp) {
2
+ var registerBlockType = wp.blocks.registerBlockType;
3
+ var InspectorControls = wp.editor.InspectorControls;
4
+ var el = wp.element.createElement;
5
+ var TextControl = wp.components.TextControl;
6
+ var SelectControl = wp.components.SelectControl;
7
+ var ToggleControl = wp.components.ToggleControl;
8
+ var __ = wp.i18n.__;
9
+ registerBlockType('mycred-blocks/mycred-hook-table', {
10
+ title: __('Hook Table', 'mycred'),
11
+ category: 'mycred',
12
+ attributes: {
13
+ type: {
14
+ type: 'string'
15
+ },
16
+ show_gains: {
17
+ type: 'bool',
18
+ default: true
19
+ },
20
+ user: {
21
+ type: 'string',
22
+ default: '-user-'
23
+ },
24
+ post: {
25
+ type: 'string',
26
+ default: '-post-'
27
+ },
28
+ comment: {
29
+ type: 'string',
30
+ default: '-comment-'
31
+ },
32
+ amount: {
33
+ type: 'string'
34
+ },
35
+ nothing: {
36
+ type: 'string'
37
+ }
38
+ },
39
+ edit: function (props) {
40
+ var type = props.attributes.type;
41
+ var show_gains = props.attributes.show_gains;
42
+ var user = props.attributes.user;
43
+ var post = props.attributes.post;
44
+ var comment = props.attributes.comment;
45
+ var amount = props.attributes.amount;
46
+ var nothing = props.attributes.nothing;
47
+
48
+ var options = [];
49
+ function setType(value) {
50
+ props.setAttributes({type: value});
51
+ }
52
+ function setShowGains(value) {
53
+ props.setAttributes({show_gains: value});
54
+ }
55
+ function setUser(value) {
56
+ props.setAttributes({user: value});
57
+ }
58
+ function setPost(value) {
59
+ props.setAttributes({post: value});
60
+ }
61
+ function setComment(value) {
62
+ props.setAttributes({comment: value});
63
+ }
64
+ function setAmount(value) {
65
+ props.setAttributes({amount: value});
66
+ }
67
+ function setNth(value) {
68
+ props.setAttributes({nothing: value});
69
+ }
70
+
71
+ Object.keys(mycred_types).forEach(function (key) {
72
+ options.push({
73
+ label: mycred_types[key],
74
+ value: key
75
+ });
76
+ });
77
+ return el('div', {}, [
78
+ el('p', {}, __('Hook Table Shortcode', 'mycred')
79
+ ),
80
+ el(InspectorControls, null,
81
+ el(SelectControl, {
82
+ label: __('Point Type', 'mycred'),
83
+ help: __('The point type to show hooks for.', 'mycred'),
84
+ value: type,
85
+ onChange: setType,
86
+ options
87
+ }),
88
+ el(ToggleControl, {
89
+ label: __('Show Gains', 'mycred'),
90
+ checked: show_gains,
91
+ onChange: setShowGains
92
+ }),
93
+ el(TextControl, {
94
+ label: __('User', 'mycred'),
95
+ help: __('Text to replace all user related template tags with.', 'mycred'),
96
+ value: user,
97
+ onChange: setUser
98
+
99
+ }),
100
+ el(TextControl, {
101
+ label: __('Post Related Template Tags', 'mycred'),
102
+ help: __('Text to replace all post related template tags with.', 'mycred'),
103
+ value: post,
104
+ onChange: setPost
105
+
106
+ }),
107
+ el(TextControl, {
108
+ label: __('Comment Related Template Tags', 'mycred'),
109
+ help: __('Text to replace all comment related template tags with.', 'mycred'),
110
+ value: comment,
111
+ onChange: setComment
112
+
113
+ }),
114
+ el(TextControl, {
115
+ label: __('Amount Related Template Tags', 'mycred'),
116
+ help: __('Text to replace all amount related template tags with.', 'mycred'),
117
+ value: amount,
118
+ onChange: setAmount
119
+
120
+ }),
121
+ el(TextControl, {
122
+ label: __('No Hooks', 'mycred'),
123
+ help: __('Text to show when there are no active hooks for the selected point type.', 'mycred'),
124
+ value: nothing,
125
+ onChange: setNth
126
+ }),
127
+ )
128
+ ]);
129
+ },
130
+ save: function (props) {
131
+ return null;
132
+ }
133
+ });
134
+ })(window.wp);
includes/mycred-blocks/blocks/mycred-hook-table/mycred-hook-table.php ADDED
@@ -0,0 +1,21 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ add_action('enqueue_block_editor_assets', 'mycred_hook_table');
4
+
5
+ function mycred_hook_table() {
6
+
7
+ wp_enqueue_script(
8
+ 'mycred-hook-table', plugins_url('index.js', __FILE__), array('wp-blocks', 'wp-element', 'wp-components', 'wp-editor')
9
+ );
10
+ }
11
+
12
+ register_block_type('mycred-blocks/mycred-hook-table', array(
13
+ 'render_callback' => 'mycred_hook_table_callback'
14
+ ));
15
+
16
+ function mycred_hook_table_callback($attributes) {
17
+ if ($attributes['type'] == '')
18
+ $attributes['type'] = 'mycred_default';
19
+
20
+ return "[mycred_hook_table " . mycred_extract_attributes($attributes) . "]";
21
+ }
includes/mycred-blocks/blocks/mycred-leaderboard/index.js ADDED
@@ -0,0 +1,212 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ (function (wp) {
2
+ var registerBlockType = wp.blocks.registerBlockType;
3
+ var InspectorControls = wp.editor.InspectorControls;
4
+ var el = wp.element.createElement;
5
+ var TextControl = wp.components.TextControl;
6
+ var SelectControl = wp.components.SelectControl;
7
+ var ToggleControl = wp.components.ToggleControl;
8
+ var __ = wp.i18n.__;
9
+ registerBlockType('mycred-blocks/mycred-leaderboard', {
10
+ title: __('Leaderboard', 'mycred'),
11
+ category: 'mycred',
12
+ attributes: {
13
+ number: {
14
+ type: 'integer',
15
+ default: '25'
16
+ },
17
+ order: {
18
+ type: 'string'
19
+ },
20
+ offset: {
21
+ type: 'string'
22
+ },
23
+ type: {
24
+ type: 'string'
25
+ },
26
+ based_on: {
27
+ type: 'string',
28
+ default: 'balance'
29
+ },
30
+ total: {
31
+ type: 'bool',
32
+ default: false
33
+ },
34
+ wrap: {
35
+ type: 'string',
36
+ default: 'li'
37
+ },
38
+ template: {
39
+ type: 'string',
40
+ default: '#%position% %user_profile_link% %cred_f%'
41
+ },
42
+ nothing: {
43
+ type: 'string',
44
+ default: 'Leaderboard is empty'
45
+ },
46
+ current: {
47
+ type: 'bool',
48
+ default: false
49
+ },
50
+ timeframe: {
51
+ type: 'string'
52
+ },
53
+ exclude_zero: {
54
+ type: 'bool',
55
+ default: true
56
+ }
57
+ },
58
+ edit: function (props) {
59
+ var number = props.attributes.number;
60
+ var order = props.attributes.order;
61
+ var offset = props.attributes.offset;
62
+ var type = props.attributes.type;
63
+
64
+ var based_on = props.attributes.based_on;
65
+ var total = props.attributes.total;
66
+ var wrap = props.attributes.wrap;
67
+
68
+ var template = props.attributes.template;
69
+ var nothing = props.attributes.nothing;
70
+ var current = props.attributes.current;
71
+ var exclude_zero = props.attributes.exclude_zero;
72
+ var timeframe = props.attributes.timeframe;
73
+
74
+ var options = [];
75
+ function setNumber(value) {
76
+ props.setAttributes({number: value});
77
+ }
78
+ function setOffset(value) {
79
+ props.setAttributes({offset: value});
80
+ }
81
+ function setOrder(value) {
82
+ props.setAttributes({order: value});
83
+ }
84
+
85
+ function setType(value) {
86
+ props.setAttributes({type: value});
87
+ }
88
+
89
+ function setBasedOn(value) {
90
+ props.setAttributes({based_on: value});
91
+ }
92
+
93
+ function setTotal(value) {
94
+ props.setAttributes({total: value});
95
+ }
96
+ function setWrap(value) {
97
+ props.setAttributes({wrap: value});
98
+ }
99
+
100
+ function setTemp(value) {
101
+ props.setAttributes({template: value});
102
+ }
103
+
104
+ function setNth(value) {
105
+ props.setAttributes({nothing: value});
106
+ }
107
+
108
+ function setCurrent(value) {
109
+ props.setAttributes({current: value});
110
+ }
111
+ function setExclude(value) {
112
+ props.setAttributes({exclude_zero: value});
113
+ }
114
+
115
+ function setTimeFrame(value) {
116
+ props.setAttributes({timeframe: value});
117
+ }
118
+ Object.keys(mycred_types).forEach(function (key) {
119
+ options.push({
120
+ label: mycred_types[key],
121
+ value: key
122
+ });
123
+ });
124
+ return el('div', {}, [
125
+ el('p', {}, __('Leaderboard Shortcode', 'mycred')
126
+ ),
127
+ el(InspectorControls, null,
128
+ el(TextControl, {
129
+ label: __('Number of Users', 'mycred'),
130
+ help: __('The maximum number of users to include in the leaderboard.', 'mycred'),
131
+ value: number,
132
+ onChange: setNumber
133
+
134
+ }),
135
+ el(SelectControl, {
136
+ label: __('Order', 'mycred'),
137
+ help: __('Order of the leaderboard. Either ASC for ascending or DESC for descending order.', 'mycred'),
138
+ value: order,
139
+ onChange: setOrder,
140
+ options: [
141
+ {label: 'Descending', value: 'DESC'},
142
+ {label: 'Ascending', value: 'ASC'}
143
+ ]
144
+ }),
145
+ el(TextControl, {
146
+ label: __('Offset', 'mycred'),
147
+ help: __('Option to offset the results. Use zero for no offset.', 'mycred'),
148
+ value: offset,
149
+ onChange: setOffset
150
+ }),
151
+ el(SelectControl, {
152
+ label: __('Point Type', 'mycred'),
153
+ help: __('The point type you want to show a leaderboard for.', 'mycred'),
154
+ value: type,
155
+ onChange: setType,
156
+ options
157
+ }),
158
+ el(TextControl, {
159
+ label: __('Based On', 'mycred'),
160
+ help: __('Use "balance" for a leaderboard based on your users balances. Otherwise use the reference you want to base the leaderboard on. Can not be empty!', 'mycred'),
161
+ value: based_on,
162
+ onChange: setBasedOn
163
+ }),
164
+ el(ToggleControl, {
165
+ label: __('Total', 'mycred'),
166
+ checked: total,
167
+ onChange: setTotal
168
+ }),
169
+ el(TextControl, {
170
+ label: __('Row Wrap Element', 'mycred'),
171
+ help: __('The HTML element you want to use for each row in the leaderboard. Will default to list element (li).', 'mycred'),
172
+ value: wrap,
173
+ onChange: setWrap
174
+ }),
175
+ el(TextControl, {
176
+ label: __('Row Template', 'mycred'),
177
+ help: __('The template to use for each row.', 'mycred'),
178
+ value: template,
179
+ onChange: setTemp
180
+ }),
181
+ el(TextControl, {
182
+ label: __('No Results', 'mycred'),
183
+ help: __('Message to show when there are no results to show.', 'mycred'),
184
+ value: nothing,
185
+ onChange: setNth
186
+ }),
187
+ el(ToggleControl, {
188
+ label: __('Current Users Position', 'mycred'),
189
+ help: __('Select if you want to include the current users position in the leaderboard.', 'mycred'),
190
+ checked: current,
191
+ onChange: setCurrent
192
+ }),
193
+ el(ToggleControl, {
194
+ label: __('Exclude Zero Balance', 'mycred'),
195
+ help: __('Only applicable for leaderboards based on balance. By default zero balances are ignored but you can select to override this.', 'mycred'),
196
+ checked: exclude_zero,
197
+ onChange: setExclude
198
+ }),
199
+ el(TextControl, {
200
+ label: __('Timeframe', 'mycred'),
201
+ help: __('Option to limit the leaderboard to a specific timeframe. Leave empty for all time, use "today" for todays leaderboard, "this-week" for this weeks leaderboard, "this-month" for this months leaderboard or enter a date to calculate from (until today). Date must be formatted either YYYY-MM-DD or MM/DD/YYYY. (Requires 1.7)', 'mycred'),
202
+ value: timeframe,
203
+ onChange: setTimeFrame
204
+ }),
205
+ )
206
+ ]);
207
+ },
208
+ save: function (props) {
209
+ return null;
210
+ }
211
+ });
212
+ })(window.wp);
includes/mycred-blocks/blocks/mycred-leaderboard/mycred-leaderboard.php ADDED
@@ -0,0 +1,21 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ add_action('enqueue_block_editor_assets', 'mycred_leaderboard');
4
+
5
+ function mycred_leaderboard() {
6
+
7
+ wp_enqueue_script(
8
+ 'mycred-leaderboard', plugins_url('index.js', __FILE__), array('wp-blocks', 'wp-element', 'wp-components', 'wp-editor')
9
+ );
10
+ }
11
+
12
+ register_block_type('mycred-blocks/mycred-leaderboard', array(
13
+ 'render_callback' => 'mycred_leaderboard_callback'
14
+ ));
15
+
16
+ function mycred_leaderboard_callback($attributes) {
17
+ if ($attributes['type'] == '')
18
+ $attributes['type'] = 'mycred_default';
19
+
20
+ return "[mycred_leaderboard " . mycred_extract_attributes($attributes) . "]";
21
+ }
includes/mycred-blocks/blocks/mycred-link/index.js ADDED
@@ -0,0 +1,229 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ (function (wp) {
2
+ var registerBlockType = wp.blocks.registerBlockType;
3
+ var InspectorControls = wp.editor.InspectorControls;
4
+ var el = wp.element.createElement;
5
+ var TextControl = wp.components.TextControl;
6
+ var SelectControl = wp.components.SelectControl;
7
+ var TextareaControl = wp.components.TextareaControl;
8
+
9
+ var __ = wp.i18n.__;
10
+ registerBlockType('mycred-blocks/mycred-link', {
11
+ title: __('Link', 'mycred'),
12
+ category: 'mycred',
13
+ attributes: {
14
+ href: {
15
+ type: 'string'
16
+ },
17
+ amount: {
18
+ type: 'integer'
19
+ },
20
+ ctype: {
21
+ type: 'string'
22
+ },
23
+ id: {
24
+ type: 'string'
25
+ },
26
+ rel: {
27
+ type: 'string'
28
+ },
29
+ clss: {
30
+ type: 'string'
31
+ },
32
+ title: {
33
+ type: 'string'
34
+ },
35
+ target: {
36
+ type: 'string'
37
+ },
38
+ style: {
39
+ type: 'string'
40
+ },
41
+ hreflang: {
42
+ type: 'string'
43
+ },
44
+ media: {
45
+ type: 'string'
46
+ },
47
+ type: {
48
+ type: 'string'
49
+ },
50
+ onclick: {
51
+ type: 'string'
52
+ },
53
+ content: {
54
+ type: 'string'
55
+ }
56
+ },
57
+ edit: function (props) {
58
+ var href = props.attributes.href;
59
+ var amount = props.attributes.amount;
60
+ var ctype = props.attributes.ctype;
61
+ var id = props.attributes.id;
62
+ var rel = props.attributes.rel;
63
+
64
+ var clss = props.attributes.clss;
65
+ var title = props.attributes.title;
66
+ var target = props.attributes.target;
67
+
68
+ var style = props.attributes.style;
69
+ var hreflang = props.attributes.hreflang;
70
+ var media = props.attributes.media;
71
+ var type = props.attributes.type;
72
+ var onclick = props.attributes.onclick;
73
+ var content = props.attributes.content;
74
+
75
+ var options = [];
76
+
77
+ function setHref(value) {
78
+ props.setAttributes({href: value});
79
+ }
80
+ function setAmount(value) {
81
+ props.setAttributes({amount: value});
82
+ }
83
+ function setCtype(value) {
84
+ props.setAttributes({ctype: value});
85
+ }
86
+
87
+ function setId(value) {
88
+ props.setAttributes({id: value});
89
+ }
90
+ function setRel(value) {
91
+ props.setAttributes({rel: value});
92
+ }
93
+
94
+ function setClass(value) {
95
+ props.setAttributes({clss: value});
96
+ }
97
+
98
+ function setTitle(value) {
99
+ props.setAttributes({title: value});
100
+ }
101
+ function setTarget(value) {
102
+ props.setAttributes({target: value});
103
+ }
104
+
105
+ function setStyle(value) {
106
+ props.setAttributes({style: value});
107
+ }
108
+
109
+ function setHrefLang(value) {
110
+ props.setAttributes({hreflang: value});
111
+ }
112
+
113
+ function setMedia(value) {
114
+ props.setAttributes({media: value});
115
+ }
116
+ function setType(value) {
117
+ props.setAttributes({type: value});
118
+ }
119
+
120
+ function setOnClick(value) {
121
+ props.setAttributes({onclick: value});
122
+ }
123
+ function setContent(value) {
124
+ props.setAttributes({content: value});
125
+ }
126
+
127
+ Object.keys(mycred_types).forEach(function (key) {
128
+ options.push({
129
+ label: mycred_types[key],
130
+ value: key
131
+ });
132
+ });
133
+ return el('div', {}, [
134
+ el('p', {}, __('Link Shortcode', 'mycred')
135
+ ),
136
+ el(InspectorControls, null,
137
+ el(TextControl, {
138
+ label: __('Amount', 'mycred'),
139
+ help: __('Amount of points for clicking on this link. Use zero to give the amount you set in your "Points for clicking on links" hook settings.', 'mycred'),
140
+ value: amount,
141
+ onChange: setAmount
142
+
143
+ }),
144
+ el(TextControl, {
145
+ label: __('HREF', 'mycred'),
146
+ help: __('Required href attribute for the anchor element.', 'mycred'),
147
+ value: href,
148
+ onChange: setHref
149
+ }),
150
+ el(SelectControl, {
151
+ label: __('Point Type', 'mycred'),
152
+ help: __('The point type you want to give', 'mycred'),
153
+ value: ctype,
154
+ onChange: setCtype,
155
+ options
156
+ }),
157
+ el(TextControl, {
158
+ label: __('ID', 'mycred'),
159
+ help: __('Optional id attribute for the anchor element', 'mycred'),
160
+ value: id,
161
+ onChange: setId
162
+ }),
163
+ el(TextControl, {
164
+ label: __('Rel', 'mycred'),
165
+ help: __('Optional rel attribute for the anchor element.', 'mycred'),
166
+ value: rel,
167
+ onChange: setRel
168
+ }),
169
+ el(TextControl, {
170
+ label: __('Title', 'mycred'),
171
+ help: __('Optional title attribute for the anchor element.', 'mycred'),
172
+ value: title,
173
+ onChange: setTitle
174
+ }),
175
+ el(TextControl, {
176
+ label: __('Target', 'mycred'),
177
+ help: __('Optional target attribute for the anchor element.', 'mycred'),
178
+ value: target,
179
+ onChange: setTarget
180
+ }),
181
+ el(TextControl, {
182
+ label: __('Style', 'mycred'),
183
+ help: __('Optional style attribute for the anchor element.', 'mycred'),
184
+ value: style,
185
+ onChange: setStyle
186
+ }),
187
+ el(TextControl, {
188
+ label: __('Class', 'mycred'),
189
+ help: __('Optional class attribute for the anchor element', 'mycred'),
190
+ value: clss,
191
+ onChange: setClass
192
+ }),
193
+ el(TextControl, {
194
+ label: __('HREFLANG', 'mycred'),
195
+ help: __('Optional hreflang attribute for the anchor element', 'mycred'),
196
+ value: hreflang,
197
+ onChange: setHrefLang
198
+ }),
199
+ el(TextControl, {
200
+ label: __('Media', 'mycred'),
201
+ help: __('Optional media attribute for the anchor element.', 'mycred'),
202
+ value: media,
203
+ onChange: setMedia
204
+ }),
205
+ el(TextControl, {
206
+ label: __('Type', 'mycred'),
207
+ help: __('Optional type attribute for the anchor element.', 'mycred'),
208
+ value: type,
209
+ onChange: setType
210
+ }),
211
+ el(TextControl, {
212
+ label: __('OnClick', 'mycred'),
213
+ help: __('Optional onclick attribute.', 'mycred'),
214
+ value: onclick,
215
+ onChange: setOnClick
216
+ }),
217
+ el(TextareaControl, {
218
+ label: __('Link Title', 'mycred'),
219
+ value: content,
220
+ onChange: setContent
221
+ })
222
+ )
223
+ ]);
224
+ },
225
+ save: function (props) {
226
+ return null;
227
+ }
228
+ });
229
+ })(window.wp);
includes/mycred-blocks/blocks/mycred-link/mycred-link.php ADDED
@@ -0,0 +1,30 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ add_action('enqueue_block_editor_assets', 'mycred_link');
4
+
5
+ function mycred_link() {
6
+
7
+ wp_enqueue_script(
8
+ 'mycred-link', plugins_url('index.js', __FILE__), array('wp-blocks', 'wp-element', 'wp-components', 'wp-editor')
9
+ );
10
+ }
11
+
12
+ register_block_type('mycred-blocks/mycred-link', array(
13
+ 'render_callback' => 'mycred_link_callback'
14
+ ));
15
+
16
+ function mycred_link_callback($attributes) {
17
+ if ($attributes['ctype'] == '') {
18
+ $attributes['ctype'] = 'mycred_default';
19
+ }
20
+ $content = "";
21
+ if (isset($attributes['clss'])) {
22
+ $attributes['class'] = $attributes['clss'];
23
+ unset($attributes['clss']);
24
+ }
25
+ if ($attributes['content'] == '') {
26
+ $content = $attributes['content'];
27
+ }
28
+ unset($attributes['content']);
29
+ return "[mycred_link " . mycred_extract_attributes($attributes) . "]" . $content . "[/mycred_link]";
30
+ }
includes/mycred-blocks/blocks/mycred-list-ranks/index.js ADDED
@@ -0,0 +1,80 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ (function (wp) {
2
+ var registerBlockType = wp.blocks.registerBlockType;
3
+ var InspectorControls = wp.editor.InspectorControls;
4
+ var el = wp.element.createElement;
5
+ var TextControl = wp.components.TextControl;
6
+ var SelectControl = wp.components.SelectControl;
7
+ var __ = wp.i18n.__;
8
+ registerBlockType('mycred-blocks/mycred-list-ranks', {
9
+ title: __('List Ranks', 'mycred'),
10
+ category: 'mycred',
11
+ attributes: {
12
+ order: {
13
+ type: 'string'
14
+ },
15
+ ctype: {
16
+ type: 'string'
17
+ },
18
+ wrap: {
19
+ type: 'string',
20
+ default: 'div'
21
+ }
22
+ },
23
+ edit: function (props) {
24
+ var order = props.attributes.order;
25
+ var ctype = props.attributes.ctype;
26
+ var wrap = props.attributes.wrap;
27
+
28
+ var options = [];
29
+
30
+ function setOrder(value) {
31
+ props.setAttributes({order: value});
32
+ }
33
+ function setPtType(value) {
34
+ props.setAttributes({ctype: value});
35
+ }
36
+ function setWrap(value) {
37
+ props.setAttributes({wrap: value});
38
+ }
39
+ Object.keys(mycred_types).forEach(function (key) {
40
+ options.push({
41
+ label: mycred_types[key],
42
+ value: key
43
+ });
44
+ });
45
+
46
+ return el('div', {}, [
47
+ el('p', {}, __('List Ranks Shortcode', 'mycred')
48
+ ),
49
+ el(InspectorControls, null,
50
+ el(SelectControl, {
51
+ label: __('Order', 'mycred'),
52
+ help: __('Rank listing order', 'mycred'),
53
+ value: order,
54
+ onChange: setOrder,
55
+ options: [
56
+ {label: 'Descending', value: 'DESC'},
57
+ {label: 'Ascending', value: 'ASC'}
58
+ ]
59
+ }),
60
+ el(SelectControl, {
61
+ label: __('Point Type', 'mycred'),
62
+ help: __('The point type you want to show', 'mycred'),
63
+ value: ctype,
64
+ onChange: setPtType,
65
+ options
66
+ }),
67
+ el(TextControl, {
68
+ label: __('Wrapper', 'mycred'),
69
+ help: __('The HTML element to use as the main wrapper around this shortcodes results', 'mycred'),
70
+ value: wrap,
71
+ onChange: setWrap
72
+ }),
73
+ )
74
+ ]);
75
+ },
76
+ save: function (props) {
77
+ return null;
78
+ }
79
+ });
80
+ })(window.wp);
includes/mycred-blocks/blocks/mycred-list-ranks/mycred-list-ranks.php ADDED
@@ -0,0 +1,22 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ add_action('enqueue_block_editor_assets', 'mycred_list_ranks');
4
+
5
+ function mycred_list_ranks() {
6
+
7
+ wp_enqueue_script(
8
+ 'mycred-list-ranks', plugins_url('index.js', __FILE__), array('wp-blocks', 'wp-element', 'wp-components', 'wp-editor')
9
+ );
10
+ }
11
+
12
+ register_block_type('mycred-blocks/mycred-list-ranks', array(
13
+ 'render_callback' => 'mycred_list_ranks_callback'
14
+ ));
15
+
16
+ function mycred_list_ranks_callback($attributes) {
17
+
18
+ if ($attributes['ctype'] == '')
19
+ $attributes['ctype'] = 'mycred_default';
20
+
21
+ return "[mycred_list_ranks " . mycred_extract_attributes($attributes) . "]";
22
+ }
includes/mycred-blocks/blocks/mycred-load-coupon/index.js ADDED
@@ -0,0 +1,72 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ (function (wp) {
2
+ var registerBlockType = wp.blocks.registerBlockType;
3
+ var InspectorControls = wp.editor.InspectorControls;
4
+ var el = wp.element.createElement;
5
+ var TextControl = wp.components.TextControl;
6
+
7
+ var __ = wp.i18n.__;
8
+ registerBlockType('mycred-blocks/mycred-load-coupon', {
9
+ title: __('Load Coupon', 'mycred'),
10
+ category: 'mycred',
11
+ attributes: {
12
+ label: {
13
+ type: 'string',
14
+ default: 'Coupon'
15
+ },
16
+ button: {
17
+ type: 'string',
18
+ default: 'Apply Coupon'
19
+ },
20
+ placeholder: {
21
+ type: 'string'
22
+ }
23
+ },
24
+ edit: function (props) {
25
+ var label = props.attributes.label;
26
+ var button = props.attributes.button;
27
+ var placeholder = props.attributes.placeholder;
28
+
29
+ function setLabel(value) {
30
+ props.setAttributes({label: value});
31
+ }
32
+
33
+ function setButton(value) {
34
+ props.setAttributes({button: value});
35
+ }
36
+
37
+ function setPlaceholder(value) {
38
+ props.setAttributes({placeholder: value});
39
+ }
40
+
41
+ return el('div', {}, [
42
+ el('p', {}, __('Load Coupon Shortcode', 'mycred')
43
+ ),
44
+ el(InspectorControls, null,
45
+ el(TextControl, {
46
+ label: __('Label', 'mycred'),
47
+ help: __('The coupon label. Can not be empty.', 'mycred'),
48
+ value: label,
49
+ onChange: setLabel
50
+
51
+ }),
52
+ el(TextControl, {
53
+ label: __('Button Label', 'mycred'),
54
+ help: __('The form submit buttons label.', 'mycred'),
55
+ value: button,
56
+ onChange: setButton
57
+
58
+ }),
59
+ el(TextControl, {
60
+ label: __('Placeholder', 'mycred'),
61
+ help: __('The placeholder label for the coupon field.', 'mycred'),
62
+ value: placeholder,
63
+ onChange: setPlaceholder
64
+ })
65
+ )
66
+ ]);
67
+ },
68
+ save: function (props) {
69
+ return null;
70
+ }
71
+ });
72
+ })(window.wp);
includes/mycred-blocks/blocks/mycred-load-coupon/mycred-load-coupon.php ADDED
@@ -0,0 +1,18 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ add_action('enqueue_block_editor_assets', 'mycred_load_coupon');
4
+
5
+ function mycred_load_coupon() {
6
+
7
+ wp_enqueue_script(
8
+ 'mycred-load-coupon', plugins_url('index.js', __FILE__), array('wp-blocks', 'wp-element', 'wp-components', 'wp-editor')
9
+ );
10
+ }
11
+
12
+ register_block_type('mycred-blocks/mycred-load-coupon', array(
13
+ 'render_callback' => 'mycred_load_coupon_callback'
14
+ ));
15
+
16
+ function mycred_load_coupon_callback($attributes) {
17
+ return "[mycred_load_coupon " . mycred_extract_attributes($attributes) . "]";
18
+ }
includes/mycred-blocks/blocks/mycred-my-badges/index.js ADDED
@@ -0,0 +1,91 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ (function (wp) {
2
+ var registerBlockType = wp.blocks.registerBlockType;
3
+ var InspectorControls = wp.editor.InspectorControls;
4
+ var el = wp.element.createElement;
5
+ var TextControl = wp.components.TextControl;
6
+ var SelectControl = wp.components.SelectControl;
7
+
8
+ var __ = wp.i18n.__;
9
+ registerBlockType('mycred-blocks/mycred-my-badges', {
10
+ title: __('My Badges', 'mycred'),
11
+ category: 'mycred',
12
+ attributes: {
13
+ show: {
14
+ type: 'string',
15
+ default: 'earned'
16
+ },
17
+ width: {
18
+ type: 'string',
19
+ default:'MYCRED_BADGE_WIDTH'
20
+ },
21
+ height: {
22
+ type: 'string',
23
+ default:'MYCRED_BADGE_HEIGHT'
24
+ },
25
+ user_id: {
26
+ type: 'string'
27
+ }
28
+ },
29
+ edit: function (props) {
30
+ var show = props.attributes.show;
31
+ var width = props.attributes.width;
32
+ var height = props.attributes.height;
33
+ var user_id = props.attributes.user_id;
34
+
35
+ function setShow(value) {
36
+ props.setAttributes({show: value});
37
+ }
38
+ function setWidth(value) {
39
+ props.setAttributes({width: value});
40
+ }
41
+
42
+ function setHeight(value) {
43
+ props.setAttributes({height: value});
44
+ }
45
+
46
+ function setUserId(value) {
47
+ props.setAttributes({user_id: value});
48
+ }
49
+
50
+
51
+ return el('div', {}, [
52
+ el('p', {}, __('My Badges Shortcode', 'mycred')
53
+ ),
54
+ el(InspectorControls, null,
55
+ el(SelectControl, {
56
+ label: __('Show', 'mycred'),
57
+ help: __('Select if you want to show only badges that a user has earned or all badges', 'mycred'),
58
+ value: show,
59
+ onChange: setShow,
60
+ options: [
61
+ {'label': 'All Badges', 'value': 'all'},
62
+ {'label': 'Earned Badges', 'value': 'earned'}
63
+ ]
64
+ }),
65
+ el(TextControl, {
66
+ label: __('Width', 'mycred'),
67
+ help: __('The badge image width to use.', 'mycred'),
68
+ value: width,
69
+ onChange: setWidth
70
+
71
+ }),
72
+ el(TextControl, {
73
+ label: __('Height', 'mycred'),
74
+ help: __('The badge image height to use.', 'mycred'),
75
+ value: height,
76
+ onChange: setHeight
77
+ }),
78
+ el(TextControl, {
79
+ label: __('User ID', 'mycred'),
80
+ help: __('Option to show badges of a particular user. If you want to show the badges of the current user, type in current.', 'mycred'),
81
+ value: user_id,
82
+ onChange: setUserId
83
+ })
84
+ )
85
+ ]);
86
+ },
87
+ save: function (props) {
88
+ return null;
89
+ }
90
+ });
91
+ })(window.wp);
includes/mycred-blocks/blocks/mycred-my-badges/mycred-my-badges.php ADDED
@@ -0,0 +1,17 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ add_action('enqueue_block_editor_assets', 'mycred_my_badges');
4
+
5
+ function mycred_my_badges() {
6
+
7
+ wp_enqueue_script(
8
+ 'mycred-my-badges', plugins_url('index.js', __FILE__), array('wp-blocks', 'wp-element', 'wp-components', 'wp-editor')
9
+ );
10
+ }
11
+ register_block_type('mycred-blocks/mycred-my-badges', array(
12
+ 'render_callback' => 'mycred_my_badges_callback'
13
+ ));
14
+
15
+ function mycred_my_badges_callback($attributes) {
16
+ return "[mycred_my_badges " . mycred_extract_attributes($attributes) . "]";
17
+ }
includes/mycred-blocks/blocks/mycred-my-balance-converted/index.js ADDED
@@ -0,0 +1,93 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ (function (wp) {
2
+ var registerBlockType = wp.blocks.registerBlockType;
3
+ var InspectorControls = wp.editor.InspectorControls;
4
+ var el = wp.element.createElement;
5
+ var TextControl = wp.components.TextControl;
6
+ var SelectControl = wp.components.SelectControl;
7
+ var __ = wp.i18n.__;
8
+ registerBlockType('mycred-blocks/mycred-my-balance-converted', {
9
+ title: __('My Balance Converted', 'mycred'),
10
+ category: 'mycred',
11
+ attributes: {
12
+ ctype: {
13
+ type: 'string',
14
+ default: 'mycred_default'
15
+ },
16
+ rate: {
17
+ type: 'number',
18
+ default: 1
19
+ },
20
+ prefix: {
21
+ type: 'string',
22
+ default: ''
23
+ },
24
+ suffix: {
25
+ type: 'string',
26
+ default: ''
27
+ }
28
+ },
29
+ edit: function (props) {
30
+ var ctype = props.attributes.ctype;
31
+ var rate = props.attributes.rate;
32
+ var prefix = props.attributes.prefix;
33
+ var suffix = props.attributes.suffix;
34
+
35
+ var options = [];
36
+ function setCType(value) {
37
+ props.setAttributes({ctype: value});
38
+ }
39
+ function setRate(value) {
40
+ props.setAttributes({rate: value});
41
+ }
42
+ function setPrefix(value) {
43
+ props.setAttributes({prefix: value});
44
+ }
45
+
46
+ function setSuffix(value) {
47
+ props.setAttributes({suffix: value});
48
+ }
49
+
50
+ Object.keys(mycred_types).forEach(function (key) {
51
+ options.push({
52
+ label: mycred_types[key],
53
+ value: key
54
+ });
55
+ });
56
+
57
+ return el('div', {}, [
58
+ el('p', {}, __('My Balance Converted Shortcode', 'mycred')
59
+ ),
60
+ el(InspectorControls, null,
61
+ el(SelectControl, {
62
+ label: __('Point Type', 'mycred'),
63
+ help: __('The point type you want to show a Conversion for.', 'mycred'),
64
+ value: ctype,
65
+ onChange: setCType,
66
+ options
67
+ }),
68
+ el(TextControl, {
69
+ label: __('Conversion Rate', 'mycred'),
70
+ help: __('', 'mycred'),
71
+ value: rate,
72
+ onChange: setRate
73
+ }),
74
+ el(TextControl, {
75
+ label: __('Prefix', 'mycred'),
76
+ help: __('', 'mycred'),
77
+ value: prefix,
78
+ onChange: setPrefix
79
+ }),
80
+ el(TextControl, {
81
+ label: __('Suffix', 'mycred'),
82
+ help: __('', 'mycred'),
83
+ value: suffix,
84
+ onChange: setSuffix
85
+ })
86
+ )
87
+ ]);
88
+ },
89
+ save: function (props) {
90
+ return null;
91
+ }
92
+ });
93
+ })(window.wp);
includes/mycred-blocks/blocks/mycred-my-balance-converted/mycred-my-balance-converted.php ADDED
@@ -0,0 +1,19 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ add_action('enqueue_block_editor_assets', 'mycred_my_balance_converted_assets');
4
+
5
+ function mycred_my_balance_converted_assets() {
6
+
7
+ wp_enqueue_script(
8
+ 'mycred-my-balance-converted', plugins_url('index.js', __FILE__), array('wp-blocks', 'wp-element', 'wp-components', 'wp-editor')
9
+ );
10
+ }
11
+
12
+ register_block_type('mycred-blocks/mycred-my-balance-converted', array(
13
+ 'render_callback' => 'mycred_my_balance_converted_callback'
14
+ ));
15
+
16
+ function mycred_my_balance_converted_callback( $attributes ) {
17
+
18
+ return "[mycred_my_balance_converted " . mycred_extract_attributes( $attributes ) . "]";
19
+ }
includes/mycred-blocks/blocks/mycred-my-balance/index.js ADDED
@@ -0,0 +1,147 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ (function (wp) {
2
+ var registerBlockType = wp.blocks.registerBlockType;
3
+ var InspectorControls = wp.editor.InspectorControls;
4
+ var el = wp.element.createElement;
5
+ var TextControl = wp.components.TextControl;
6
+ var SelectControl = wp.components.SelectControl;
7
+ var ToggleControl = wp.components.ToggleControl;
8
+ var TextareaControl = wp.components.TextareaControl;
9
+ var __ = wp.i18n.__;
10
+ registerBlockType('mycred-blocks/mycred-my-balance', {
11
+ title: __('My Balance', 'mycred'),
12
+ category: 'mycred',
13
+ attributes: {
14
+ user_id: {
15
+ type: 'string'
16
+ },
17
+ title: {
18
+ type: 'string'
19
+ },
20
+ title_el: {
21
+ type: 'string',
22
+ default: 'h1'
23
+ },
24
+ balance_el: {
25
+ type: 'string',
26
+ default: 'div'
27
+ },
28
+ wrapper: {
29
+ type: 'bool',
30
+ default: true
31
+ },
32
+ formatted: {
33
+ type: 'bool',
34
+ default: true
35
+ },
36
+ type: {
37
+ type: 'string'
38
+ },
39
+ content: {
40
+ type: 'string'
41
+ }
42
+ },
43
+ edit: function (props) {
44
+ var user_id = props.attributes.user_id;
45
+ var title = props.attributes.title;
46
+ var title_el = props.attributes.title_el;
47
+ var balance_el = props.attributes.balance_el;
48
+
49
+ var wrapper = props.attributes.wrapper;
50
+ var formatted = props.attributes.formatted;
51
+ var type = props.attributes.type;
52
+ var content = props.attributes.content;
53
+
54
+ var options = [];
55
+
56
+ function setUserId(value) {
57
+ props.setAttributes({user_id: value});
58
+ }
59
+ function setTitle(value) {
60
+ props.setAttributes({title: value});
61
+ }
62
+ function setTitleEl(value) {
63
+ props.setAttributes({title_el: value});
64
+ }
65
+ function setBalanceEl(value) {
66
+ props.setAttributes({balance_el: value});
67
+ }
68
+ function setWrapper(value) {
69
+ props.setAttributes({wrapper: value});
70
+ }
71
+ function setFormatted(value) {
72
+ props.setAttributes({formatted: value});
73
+ }
74
+ function setType(value) {
75
+ props.setAttributes({type: value});
76
+ }
77
+ function setContent(value) {
78
+ props.setAttributes({content: value});
79
+ }
80
+
81
+ Object.keys(mycred_types).forEach(function (key) {
82
+ options.push({
83
+ label: mycred_types[key],
84
+ value: key
85
+ });
86
+ });
87
+ return el('div', {}, [
88
+ el('p', {}, __('My Balance Shortcode', 'mycred')
89
+ ),
90
+ el(InspectorControls, null,
91
+ el(TextControl, {
92
+ label: __('User ID', 'mycred'),
93
+ help: __('The users balance you want to show. Use "current" to show the user who is viewing the shortcode. Can not be empty.', 'mycred'),
94
+ value: user_id,
95
+ onChange: setUserId
96
+ }),
97
+ el(TextControl, {
98
+ label: __('Title', 'mycred'),
99
+ help: __('Optional title to add before the balance.', 'mycred'),
100
+ value: title,
101
+ onChange: setTitle
102
+ }),
103
+ el(TextControl, {
104
+ label: __('Title Element', 'mycred'),
105
+ help: __('The HTML element to wrap around the title. Leave empty if not used.', 'mycred'),
106
+ value: title_el,
107
+ onChange: setTitleEl
108
+ }),
109
+ el(TextControl, {
110
+ label: __('Balance Element', 'mycred'),
111
+ help: __('The HTML element to wrap around the balance. Leave empty to hide wrapping element', 'mycred'),
112
+ value: balance_el,
113
+ onChange: setBalanceEl
114
+ }),
115
+ el(ToggleControl, {
116
+ label: __('Use Wrappers', 'mycred'),
117
+ help: __('Select if you want to wrap the balance for styling or just return the balance amount.', 'mycred'),
118
+ checked: wrapper,
119
+ onChange: setWrapper
120
+ }),
121
+ el(ToggleControl, {
122
+ label: __('Format Balance', 'mycred'),
123
+ help: __('Select if you want to format the balance amount with prefix / suffix or show just the amount. (Requires 1.7)', 'mycred'),
124
+ checked: formatted,
125
+ onChange: setFormatted
126
+ }),
127
+ el(SelectControl, {
128
+ label: __('Point Type', 'mycred'),
129
+ help: __('The point type you want to show.', 'mycred'),
130
+ value: type,
131
+ onChange: setType,
132
+ options
133
+ }),
134
+ el(TextareaControl, {
135
+ label: __('Visitors Message', 'mycred'),
136
+ help: __('Optional message to show when the shortcode is viewed by a visitor that is not logged in.', 'mycred'),
137
+ value: content,
138
+ onChange: setContent
139
+ })
140
+ )
141
+ ]);
142
+ },
143
+ save: function (props) {
144
+ return null;
145
+ }
146
+ });
147
+ })(window.wp);
includes/mycred-blocks/blocks/mycred-my-balance/mycred-my-balance.php ADDED
@@ -0,0 +1,28 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ add_action('enqueue_block_editor_assets', 'mycred_my_balance');
4
+
5
+ function mycred_my_balance() {
6
+
7
+ wp_enqueue_script(
8
+ 'mycred-my-balance', plugins_url('index.js', __FILE__), array('wp-blocks', 'wp-element', 'wp-components', 'wp-editor')
9
+ );
10
+ }
11
+
12
+ register_block_type('mycred-blocks/mycred-my-balance', array(
13
+ 'render_callback' => 'mycred_my_balance_callback'
14
+ ));
15
+
16
+ function mycred_my_balance_callback($attributes) {
17
+ if ($attributes['type'] == ''){
18
+ $attributes['type'] = 'mycred_default';
19
+ }
20
+
21
+ $content = "";
22
+ if (isset($attributes['content'])) {
23
+ $content = $attributes['content'];
24
+ }
25
+ unset($attributes['content']);
26
+
27
+ return "[mycred_my_balance " . mycred_extract_attributes($attributes) . "]" . $content . "[/mycred_my_balance]";
28
+ }
includes/mycred-blocks/blocks/mycred-my-rank/index.js ADDED
@@ -0,0 +1,125 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ (function (wp) {
2
+ var registerBlockType = wp.blocks.registerBlockType;
3
+ var InspectorControls = wp.editor.InspectorControls;
4
+ var el = wp.element.createElement;
5
+ var TextControl = wp.components.TextControl;
6
+ var ToggleControl = wp.components.ToggleControl;
7
+ var SelectControl = wp.components.SelectControl;
8
+ var __ = wp.i18n.__;
9
+ registerBlockType('mycred-blocks/mycred-my-rank', {
10
+ title: __('My Rank', 'mycred'),
11
+ category: 'mycred',
12
+ attributes: {
13
+ user_id: {
14
+ type: 'string'
15
+ },
16
+ show_title: {
17
+ type: 'bool',
18
+ default: true
19
+ },
20
+ show_logo: {
21
+ type: 'bool'
22
+ },
23
+ logo_size: {
24
+ type: 'string',
25
+ default: 'post-thumbnail'
26
+ },
27
+ first: {
28
+ type: 'string',
29
+ default: 'logo'
30
+ },
31
+ ctype: {
32
+ type: 'string'
33
+ }
34
+ },
35
+ edit: function (props) {
36
+ var user_id = props.attributes.user_id;
37
+ var show_title = props.attributes.show_title;
38
+ var show_logo = props.attributes.show_logo;
39
+ var logo_size = props.attributes.logo_size;
40
+ var first = props.attributes.first;
41
+ var ctype = props.attributes.ctype;
42
+
43
+ var options = [];
44
+ function setUserId(value) {
45
+ props.setAttributes({user_id: value});
46
+ }
47
+ function setShowTitle(value) {
48
+ props.setAttributes({show_title: value});
49
+ }
50
+
51
+ function setShowLogo(value) {
52
+ props.setAttributes({show_logo: value});
53
+ }
54
+ function setLogoSize(value) {
55
+ props.setAttributes({logo_size: value});
56
+ }
57
+ function setFirst(value) {
58
+ props.setAttributes({first: value});
59
+ }
60
+
61
+ function setPtType(value) {
62
+ props.setAttributes({ctype: value});
63
+ }
64
+
65
+ Object.keys(mycred_types).forEach(function (key) {
66
+ options.push({
67
+ label: mycred_types[key],
68
+ value: key
69
+ });
70
+ });
71
+
72
+ return el('div', {}, [
73
+ el('p', {}, __('My Rank Shortcode', 'mycred')
74
+ ),
75
+ el(InspectorControls, null,
76
+ el(TextControl, {
77
+ label: __('User ID', 'mycred'),
78
+ help: __('Optional ID of a specific user. If you want to show the rank of the user viewing this shortcode, leave this field empty.', 'mycred'),
79
+ value: user_id,
80
+ onChange: setUserId
81
+
82
+ }),
83
+ el(ToggleControl, {
84
+ label: __('Show Title', 'mycred'),
85
+ help: __('Option to show the rank title. Defaults to yes', 'mycred'),
86
+ checked: show_title,
87
+ onChange: setShowTitle
88
+ }),
89
+ el(ToggleControl, {
90
+ label: __('Show Logo', 'mycred'),
91
+ help: __('Option to show the rank logo. Defaults to no.', 'mycred'),
92
+ checked: show_logo,
93
+ onChange: setShowLogo
94
+ }),
95
+ el(TextControl, {
96
+ label: __('Logo Size', 'mycred'),
97
+ help: __('Registered image size or size in pixels e.g. 100x100', 'mycred'),
98
+ value: logo_size,
99
+ onChange: setLogoSize
100
+ }),
101
+ el(SelectControl, {
102
+ label: __('Order', 'mycred'),
103
+ help: __('Select what you want to show first. This is ignored if you have selected to only show one detail', 'mycred'),
104
+ value: first,
105
+ onChange: setFirst,
106
+ options: [
107
+ {label: 'Logo then Title', value: 'logo'},
108
+ {label: 'Title then Logo', value: 'title'}
109
+ ]
110
+ }),
111
+ el(SelectControl, {
112
+ label: __('Point Type', 'mycred'),
113
+ help: __('The point type you want to show', 'mycred'),
114
+ value: ctype,
115
+ onChange: setPtType,
116
+ options
117
+ }),
118
+ )
119
+ ]);
120
+ },
121
+ save: function (props) {
122
+ return null;
123
+ }
124
+ });
125
+ })(window.wp);
includes/mycred-blocks/blocks/mycred-my-rank/mycred-my-rank.php ADDED
@@ -0,0 +1,22 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ add_action('enqueue_block_editor_assets', 'mycred_my_rank');
4
+
5
+ function mycred_my_rank() {
6
+
7
+ wp_enqueue_script(
8
+ 'mycred-my-rank', plugins_url('index.js', __FILE__), array('wp-blocks', 'wp-element', 'wp-components', 'wp-editor')
9
+ );
10
+ }
11
+
12
+ register_block_type('mycred-blocks/mycred-my-rank', array(
13
+ 'render_callback' => 'mycred_my_rank_callback'
14
+ ));
15
+
16
+ function mycred_my_rank_callback($attributes) {
17
+
18
+ if ($attributes['ctype'] == '')
19
+ $attributes['ctype'] = 'mycred_default';
20
+
21
+ return "[mycred_my_rank " . mycred_extract_attributes($attributes) . "]";
22
+ }
includes/mycred-blocks/blocks/mycred-my-ranks/index.js ADDED
@@ -0,0 +1,106 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ (function (wp) {
2
+ var registerBlockType = wp.blocks.registerBlockType;
3
+ var InspectorControls = wp.editor.InspectorControls;
4
+ var el = wp.element.createElement;
5
+ var TextControl = wp.components.TextControl;
6
+ var ToggleControl = wp.components.ToggleControl;
7
+ var SelectControl = wp.components.SelectControl;
8
+ var __ = wp.i18n.__;
9
+ registerBlockType('mycred-blocks/mycred-my-ranks', {
10
+ title: __('My Ranks', 'mycred'),
11
+ description: __('This Block allows you to show all ranks a user currently has. Note that this is only usable when you have ranks for multiple point types.', 'mycred'),
12
+ category: 'mycred',
13
+ attributes: {
14
+ user_id: {
15
+ type: 'string'
16
+ },
17
+ show_title: {
18
+ type: 'bool',
19
+ default: true
20
+ },
21
+ show_logo: {
22
+ type: 'bool'
23
+ },
24
+ logo_size: {
25
+ type: 'string',
26
+ default: 'post-thumbnail'
27
+ },
28
+ first: {
29
+ type: 'string',
30
+ default: 'logo'
31
+ },
32
+ ctype: {
33
+ type: 'string'
34
+ }
35
+ },
36
+ edit: function (props) {
37
+ var user_id = props.attributes.user_id;
38
+ var show_title = props.attributes.show_title;
39
+ var show_logo = props.attributes.show_logo;
40
+ var logo_size = props.attributes.logo_size;
41
+ var first = props.attributes.first;
42
+
43
+ function setUserId(value) {
44
+ props.setAttributes({user_id: value});
45
+ }
46
+ function setShowTitle(value) {
47
+ props.setAttributes({show_title: value});
48
+ }
49
+
50
+ function setShowLogo(value) {
51
+ props.setAttributes({show_logo: value});
52
+ }
53
+ function setLogoSize(value) {
54
+ props.setAttributes({logo_size: value});
55
+ }
56
+ function setFirst(value) {
57
+ props.setAttributes({first: value});
58
+ }
59
+
60
+ return el('div', {}, [
61
+ el('p', {}, __('My Ranks Shortcode', 'mycred')
62
+ ),
63
+ el(InspectorControls, null,
64
+ el(TextControl, {
65
+ label: __('User ID', 'mycred'),
66
+ help: __('Optional ID of a specific user. If you want to show the rank of the user viewing this shortcode, leave this field empty.', 'mycred'),
67
+ value: user_id,
68
+ onChange: setUserId
69
+
70
+ }),
71
+ el(ToggleControl, {
72
+ label: __('Show Title', 'mycred'),
73
+ help: __('Option to show the rank title. Defaults to yes', 'mycred'),
74
+ checked: show_title,
75
+ onChange: setShowTitle
76
+ }),
77
+ el(ToggleControl, {
78
+ label: __('Show Logo', 'mycred'),
79
+ help: __('Option to show the rank logo. Defaults to no.', 'mycred'),
80
+ checked: show_logo,
81
+ onChange: setShowLogo
82
+ }),
83
+ el(TextControl, {
84
+ label: __('Logo Size', 'mycred'),
85
+ help: __('Registered image size or size in pixels e.g. 100x100', 'mycred'),
86
+ value: logo_size,
87
+ onChange: setLogoSize
88
+ }),
89
+ el(SelectControl, {
90
+ label: __('Order', 'mycred'),
91
+ help: __('Select what you want to show first. This is ignored if you have selected to only show one detail', 'mycred'),
92
+ value: first,
93
+ onChange: setFirst,
94
+ options: [
95
+ {label: 'Logo then Title', value: 'logo'},
96
+ {label: 'Title then Logo', value: 'title'}
97
+ ]
98
+ }),
99
+ )
100
+ ]);
101
+ },
102
+ save: function (props) {
103
+ return null;
104
+ }
105
+ });
106
+ })(window.wp);
includes/mycred-blocks/blocks/mycred-my-ranks/mycred-my-ranks.php ADDED
@@ -0,0 +1,22 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ add_action('enqueue_block_editor_assets', 'mycred_my_ranks');
4
+
5
+ function mycred_my_ranks() {
6
+
7
+ wp_enqueue_script(
8
+ 'mycred-my-ranks', plugins_url('index.js', __FILE__), array('wp-blocks', 'wp-element', 'wp-components', 'wp-editor')
9
+ );
10
+ }
11
+
12
+ register_block_type('mycred-blocks/mycred-my-ranks', array(
13
+ 'render_callback' => 'mycred_my_ranks_callback'
14
+ ));
15
+
16
+ function mycred_my_ranks_callback($attributes) {
17
+
18
+ if ($attributes['ctype'] == '')
19
+ $attributes['ctype'] = 'mycred_default';
20
+
21
+ return "[mycred_my_ranks " . mycred_extract_attributes($attributes) . "]";
22
+ }
includes/mycred-blocks/blocks/mycred-total-balance/index.js ADDED
@@ -0,0 +1,84 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ (function (wp) {
2
+ var registerBlockType = wp.blocks.registerBlockType;
3
+ var InspectorControls = wp.editor.InspectorControls;
4
+ var el = wp.element.createElement;
5
+ var TextControl = wp.components.TextControl;
6
+ var ToggleControl = wp.components.ToggleControl;
7
+ var TextareaControl = wp.components.TextareaControl;
8
+
9
+ var __ = wp.i18n.__;
10
+ registerBlockType('mycred-blocks/mycred-total-balance', {
11
+ title: __('Total Balance', 'mycred'),
12
+ category: 'mycred',
13
+ attributes: {
14
+ user_id: {
15
+ type: 'string'
16
+ },
17
+ types: {
18
+ type: 'string'
19
+ },
20
+ raw: {
21
+ type: 'bool',
22
+ default: false
23
+ },
24
+ total: {
25
+ type: 'bool',
26
+ default: false
27
+ }
28
+ },
29
+ edit: function (props) {
30
+ var user_id = props.attributes.user_id;
31
+ var types = props.attributes.types;
32
+ var raw = props.attributes.raw;
33
+ var total = props.attributes.total;
34
+
35
+ function setUserId(value) {
36
+ props.setAttributes({user_id: value});
37
+ }
38
+ function setPtTypes(value) {
39
+ props.setAttributes({types: value});
40
+ }
41
+ function setRaw(value) {
42
+ props.setAttributes({raw: value});
43
+ }
44
+ function setTotal(value) {
45
+ props.setAttributes({total: value});
46
+ }
47
+ return el('div', {}, [
48
+ el('p', {}, __('Total Balance Shortcode', 'mycred')
49
+ ),
50
+ el(InspectorControls, null,
51
+ el(TextControl, {
52
+ label: __('User ID', 'mycred'),
53
+ help: __('Option to return a specific users balance. Use "current" to show the current users total balance.', 'mycred'),
54
+ value: user_id,
55
+ onChange: setUserId
56
+ }),
57
+ el(TextareaControl, {
58
+ label: __('Point Type(s)', 'mycred'),
59
+ help: __('Either a single point type key, or "all" for adding up all existing point types or a comma separated list of point type keys. No empty spaces allowed!', 'mycred'),
60
+ value: types,
61
+ onChange: setPtTypes,
62
+ rows: 2
63
+ }),
64
+ el(ToggleControl, {
65
+ label: __('Unformatted', 'mycred'),
66
+ help: __('Do you want to just return the amount without any HTML elements?', 'mycred'),
67
+ checked: raw,
68
+ onChange: setRaw
69
+
70
+ }),
71
+ el(ToggleControl, {
72
+ label: __('User ID', 'mycred'),
73
+ help: __('Do you want to show the total balance?', 'mycred'),
74
+ checked: total,
75
+ onChange: setTotal
76
+ }),
77
+ )
78
+ ]);
79
+ },
80
+ save: function (props) {
81
+ return null;
82
+ }
83
+ });
84
+ })(window.wp);
includes/mycred-blocks/blocks/mycred-total-balance/mycred-total-balance.php ADDED
@@ -0,0 +1,21 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ add_action('enqueue_block_editor_assets', 'mycred_total_balance');
4
+
5
+ function mycred_total_balance() {
6
+
7
+ wp_enqueue_script(
8
+ 'mycred-total-balance', plugins_url('index.js', __FILE__), array('wp-blocks', 'wp-element', 'wp-components', 'wp-editor')
9
+ );
10
+ }
11
+
12
+ register_block_type('mycred-blocks/mycred-total-balance', array(
13
+ 'render_callback' => 'mycred_total_balance_callback'
14
+ ));
15
+
16
+ function mycred_total_balance_callback($attributes) {
17
+ if ($attributes['types'] == '')
18
+ $attributes['types'] = 'mycred_default';
19
+
20
+ return "[mycred_total_balance " . mycred_extract_attributes($attributes) . "]";
21
+ }
includes/mycred-blocks/blocks/mycred-total-pts/index.js ADDED
@@ -0,0 +1,104 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ (function (wp) {
2
+ var registerBlockType = wp.blocks.registerBlockType;
3
+ var InspectorControls = wp.editor.InspectorControls;
4
+ var el = wp.element.createElement;
5
+ var TextControl = wp.components.TextControl;
6
+ var ToggleControl = wp.components.ToggleControl;
7
+ var SelectControl = wp.components.SelectControl;
8
+ var __ = wp.i18n.__;
9
+ registerBlockType('mycred-blocks/mycred-total-pts', {
10
+ title: __('Total Points', 'mycred'),
11
+ category: 'mycred',
12
+ attributes: {
13
+ type: {
14
+ type: 'string'
15
+ },
16
+ ref: {
17
+ type: 'string'
18
+ },
19
+ ref_id: {
20
+ type: 'string'
21
+ },
22
+ user_id: {
23
+ type: 'string'
24
+ },
25
+ formatted: {
26
+ type: 'bool',
27
+ default: true
28
+ }
29
+ },
30
+ edit: function (props) {
31
+ var type = props.attributes.type;
32
+ var ref = props.attributes.ref;
33
+ var ref_id = props.attributes.ref_id;
34
+ var user_id = props.attributes.user_id;
35
+ var formatted = props.attributes.formatted;
36
+ var options = [];
37
+
38
+ function setRefId(value) {
39
+ props.setAttributes({ref_id: value});
40
+ }
41
+ function setPtType(value) {
42
+ props.setAttributes({type: value});
43
+ }
44
+ function setRef(value) {
45
+ props.setAttributes({ref: value});
46
+ }
47
+ function setUserId(value) {
48
+ props.setAttributes({user_id: value});
49
+ }
50
+ function setFormatted(value) {
51
+ props.setAttributes({type: value});
52
+ }
53
+
54
+ Object.keys(mycred_types).forEach(function (key) {
55
+ options.push({
56
+ label: mycred_types[key],
57
+ value: key
58
+ });
59
+ });
60
+
61
+ return el('div', {}, [
62
+ el('p', {}, __('Total Points Shortcode', 'mycred')
63
+ ),
64
+ el(InspectorControls, null,
65
+ el(TextControl, {
66
+ label: __('Reference ID', 'mycred'),
67
+ help: __('Option to filter results based on reference ID. Leave empty if not used', 'mycred'),
68
+ value: ref_id,
69
+ onChange: setRefId
70
+
71
+ }),
72
+ el(SelectControl, {
73
+ label: __('Point Type', 'mycred'),
74
+ help: __('The point type to add up', 'mycred'),
75
+ value: type,
76
+ onChange: setPtType,
77
+ options
78
+ }),
79
+ el(TextControl, {
80
+ label: __('Reference', 'mycred'),
81
+ help: __('Option to add up points based on a single reference or a comma separated list of references.', 'mycred'),
82
+ value: ref,
83
+ onChange: setRef
84
+ }),
85
+ el(TextControl, {
86
+ label: __('User ID', 'mycred'),
87
+ help: __('Option to add up points for a specific user. Use "current" for the current user viewing the shortcode or leave empty to add up points for everyone. Must be used in combination with "Reference" and/or "Reference ID" above.', 'mycred'),
88
+ value: user_id,
89
+ onChange: setUserId
90
+ }),
91
+ el(ToggleControl, {
92
+ label: __('Formatted', 'mycred'),
93
+ help: __('Option to show results formatted with prefix / suffix (1) or in plain format (0)', 'mycred'),
94
+ checked: formatted,
95
+ onChange: setFormatted
96
+ }),
97
+ )
98
+ ]);
99
+ },
100
+ save: function (props) {
101
+ return null;
102
+ }
103
+ });
104
+ })(window.wp);
includes/mycred-blocks/blocks/mycred-total-pts/mycred-total-pts.php ADDED
@@ -0,0 +1,22 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ add_action('enqueue_block_editor_assets', 'mycred_total_pts');
4
+
5
+ function mycred_total_pts() {
6
+
7
+ wp_enqueue_script(
8
+ 'mycred-total-pts', plugins_url('index.js', __FILE__), array('wp-blocks', 'wp-element', 'wp-components', 'wp-editor')
9
+ );
10
+ }
11
+
12
+ register_block_type('mycred-blocks/mycred-total-pts', array(
13
+ 'render_callback' => 'mycred_total_pts_callback'
14
+ ));
15
+
16
+ function mycred_total_pts_callback($attributes) {
17
+
18
+ if ($attributes['type'] == '')
19
+ $attributes['type'] = 'mycred_default';
20
+
21
+ return "[mycred_total_points " . mycred_extract_attributes($attributes) . "]";
22
+ }
includes/mycred-blocks/blocks/mycred-total-since/index.js ADDED
@@ -0,0 +1,118 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ (function (wp) {
2
+ var registerBlockType = wp.blocks.registerBlockType;
3
+ var InspectorControls = wp.editor.InspectorControls;
4
+ var el = wp.element.createElement;
5
+ var TextControl = wp.components.TextControl;
6
+ var ToggleControl = wp.components.ToggleControl;
7
+ var SelectControl = wp.components.SelectControl;
8
+ var __ = wp.i18n.__;
9
+ registerBlockType('mycred-blocks/mycred-total-since', {
10
+ title: __('Total Since', 'mycred'),
11
+ category: 'mycred',
12
+ attributes: {
13
+ from: {
14
+ type: 'string'
15
+ },
16
+ until: {
17
+ type: 'string'
18
+ },
19
+ type: {
20
+ type: 'string'
21
+ },
22
+ ref: {
23
+ type: 'string'
24
+ },
25
+ user_id: {
26
+ type: 'string'
27
+ },
28
+ formatted: {
29
+ type: 'bool',
30
+ default: true
31
+ }
32
+ },
33
+ edit: function (props) {
34
+ var from = props.attributes.from;
35
+ var until = props.attributes.until;
36
+ var type = props.attributes.type;
37
+ var ref = props.attributes.ref;
38
+ var user_id = props.attributes.user_id;
39
+ var formatted = props.attributes.formatted;
40
+ var options = [];
41
+
42
+ function setFrom(value) {
43
+ props.setAttributes({from: value});
44
+ }
45
+ function setUntil(value) {
46
+ props.setAttributes({until: value});
47
+ }
48
+ function setPtType(value) {
49
+ props.setAttributes({type: value});
50
+ }
51
+ function setRef(value) {
52
+ props.setAttributes({ref: value});
53
+ }
54
+ function setUserId(value) {
55
+ props.setAttributes({user_id: value});
56
+ }
57
+ function setFormatted(value) {
58
+ props.setAttributes({type: value});
59
+ }
60
+
61
+ Object.keys(mycred_types).forEach(function (key) {
62
+ options.push({
63
+ label: mycred_types[key],
64
+ value: key
65
+ });
66
+ });
67
+
68
+ return el('div', {}, [
69
+ el('p', {}, __('Total Since Shortcode', 'mycred')
70
+ ),
71
+ el(InspectorControls, null,
72
+ el(TextControl, {
73
+ label: __('From', 'mycred'),
74
+ help: __('Option to set from when we should start adding up points. Accepts: "today" for start of today, a UNIX timestamp or a well formatted date. See PHPs strtotime for further information on available options.', 'mycred'),
75
+ value: from,
76
+ onChange: setFrom
77
+
78
+ }),
79
+ el(TextControl, {
80
+ label: __('Until', 'mycred'),
81
+ help: __('Option to set what time to stop counting. Accepts: "now" for now, a UNIX timestamp or a well formatted date. See PHPs strtotime for further information on available options.', 'mycred'),
82
+ value: until,
83
+ onChange: setUntil
84
+
85
+ }),
86
+ el(SelectControl, {
87
+ label: __('Point Type', 'mycred'),
88
+ help: __('The point type to add up', 'mycred'),
89
+ value: type,
90
+ onChange: setPtType,
91
+ options
92
+ }),
93
+ el(TextControl, {
94
+ label: __('Reference', 'mycred'),
95
+ help: __('Option to filter results based on a reference.', 'mycred'),
96
+ value: ref,
97
+ onChange: setRef
98
+ }),
99
+ el(TextControl, {
100
+ label: __('User ID', 'mycred'),
101
+ help: __('Option to add up points for a specific user. Use "current" for the current user viewing the shortcode or leave empty to add up points for everyone. Must be used in combination with "Reference" and/or "Reference ID" above.', 'mycred'),
102
+ value: user_id,
103
+ onChange: setUserId
104
+ }),
105
+ el(ToggleControl, {
106
+ label: __('Formatted', 'mycred'),
107
+ help: __('Option to show results formatted with prefix / suffix (1) or in plain format (0)', 'mycred'),
108
+ checked: formatted,
109
+ onChange: setFormatted
110
+ }),
111
+ )
112
+ ]);
113
+ },
114
+ save: function (props) {
115
+ return null;
116
+ }
117
+ });
118
+ })(window.wp);
includes/mycred-blocks/blocks/mycred-total-since/mycred-total-since.php ADDED
@@ -0,0 +1,22 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ add_action('enqueue_block_editor_assets', 'mycred_total_since');
4
+
5
+ function mycred_total_since() {
6
+
7
+ wp_enqueue_script(
8
+ 'mycred-total-since', plugins_url('index.js', __FILE__), array('wp-blocks', 'wp-element', 'wp-components', 'wp-editor')
9
+ );
10
+ }
11
+
12
+ register_block_type('mycred-blocks/mycred-total-since', array(
13
+ 'render_callback' => 'mycred_total_since_callback'
14
+ ));
15
+
16
+ function mycred_total_since_callback($attributes) {
17
+
18
+ if ($attributes['type'] == '')
19
+ $attributes['type'] = 'mycred_default';
20
+
21
+ return "[mycred_total_since " . mycred_extract_attributes($attributes) . "]";
22
+ }
includes/mycred-blocks/blocks/mycred-transfer/index.js ADDED
@@ -0,0 +1,199 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ (function (wp) {
2
+ var registerBlockType = wp.blocks.registerBlockType;
3
+ var InspectorControls = wp.editor.InspectorControls;
4
+ var el = wp.element.createElement;
5
+ var TextControl = wp.components.TextControl;
6
+ var ToggleControl = wp.components.ToggleControl;
7
+ var TextareaControl = wp.components.TextareaControl;
8
+
9
+ var __ = wp.i18n.__;
10
+ registerBlockType('mycred-blocks/mycred-transfers', {
11
+ title: __('Transfer', 'mycred'),
12
+ category: 'mycred',
13
+ attributes: {
14
+ button: {
15
+ type: 'string'
16
+ },
17
+ pay_to: {
18
+ type: 'string'
19
+ },
20
+ show_balance: {
21
+ type: 'bool',
22
+ default: false
23
+ },
24
+ show_limit: {
25
+ type: 'bool',
26
+ default: false
27
+ },
28
+ types: {
29
+ type: 'string'
30
+ },
31
+ excluded: {
32
+ type: 'string'
33
+ },
34
+ amount: {
35
+ type: 'integer'
36
+ },
37
+ placeholder: {
38
+ type: 'string'
39
+ },
40
+ ref: {
41
+ type: 'string',
42
+ default: 'transfer'
43
+ },
44
+ recipient_label: {
45
+ type: 'string',
46
+ default: 'Recipient'
47
+ },
48
+ amount_label: {
49
+ type: 'string',
50
+ default: 'Amount'
51
+ },
52
+ balance_label: {
53
+ type: 'string',
54
+ default: 'Balance'
55
+ }
56
+ },
57
+ edit: function (props) {
58
+ var button = props.attributes.button;
59
+ var pay_to = props.attributes.pay_to;
60
+ var placeholder = props.attributes.placeholder;
61
+ var show_balance = props.attributes.show_balance;
62
+ var balance_label = props.attributes.balance_label;
63
+ var show_limit = props.attributes.show_limit;
64
+ var ref = props.attributes.ref;
65
+ var amount = props.attributes.amount;
66
+ var types = props.attributes.types;
67
+ var excluded = props.attributes.excluded;
68
+ var recipient_label = props.attributes.recipient_label;
69
+ var amount_label = props.attributes.amount_label;
70
+
71
+ function setButton(value) {
72
+ props.setAttributes({button: value});
73
+ }
74
+ function setAmount(value) {
75
+ props.setAttributes({amount: value});
76
+ }
77
+ function setCtype(value) {
78
+ props.setAttributes({types: value});
79
+ }
80
+
81
+ function setPayTo(value) {
82
+ props.setAttributes({pay_to: value});
83
+ }
84
+ function setRef(value) {
85
+ props.setAttributes({ref: value});
86
+ }
87
+
88
+ function setShowLimit(value) {
89
+ props.setAttributes({show_limit: value});
90
+ }
91
+
92
+ function setShowBalance(value) {
93
+ props.setAttributes({show_balance: value});
94
+ }
95
+
96
+ function setExcluded(value) {
97
+ props.setAttributes({excluded: value});
98
+ }
99
+ function setRecLabel(value) {
100
+ props.setAttributes({recipient_label: value});
101
+ }
102
+
103
+ function setAmountLabel(value) {
104
+ props.setAttributes({amount_label: value});
105
+ }
106
+
107
+ function setBalanceLabel(value) {
108
+ props.setAttributes({balance_labal: value});
109
+ }
110
+
111
+ function setPlaceholder(value) {
112
+ props.setAttributes({placeholder: value});
113
+ }
114
+
115
+ return el('div', {}, [
116
+ el('p', {}, __('Transfer Shortcode', 'mycred')
117
+ ),
118
+ el(InspectorControls, null,
119
+ el(TextControl, {
120
+ label: __('Button Label', 'mycred'),
121
+ help: __('The submit transfer button label. Leave empty to use the default label you set in your settings.', 'mycred'),
122
+ value: button,
123
+ onChange: setButton
124
+ }),
125
+ el(TextControl, {
126
+ label: __('Recipient', 'mycred'),
127
+ help: __('Option to pre-select a specific user to transfer points to. If left empty, the user must nominate the recipient.', 'mycred'),
128
+ value: pay_to,
129
+ onChange: setPayTo
130
+ }),
131
+ el(ToggleControl, {
132
+ label: __('Show Balance', 'mycred'),
133
+ help: __('Option to include the current users balance', 'mycred'),
134
+ checked: show_balance,
135
+ onChange: setShowBalance
136
+ }),
137
+ el(ToggleControl, {
138
+ label: __('Show Limit', 'mycred'),
139
+ help: __('Option to include the current users remaining transfer limit', 'mycred'),
140
+ checked: show_limit,
141
+ onChange: setShowLimit
142
+ }),
143
+ el(TextareaControl, {
144
+ label: __('Point Types', 'mycred'),
145
+ help: __('A comma separated list of point type keys that users can transfer. You can also just use one specific key to lock transfers to this point type only. Otherwise leave this field empty to use the default point type.', 'mycred'),
146
+ value: types,
147
+ onChange: setCtype,
148
+ rows: 2
149
+ }),
150
+ el(TextControl, {
151
+ label: __('Excluded message', 'mycred'),
152
+ help: __('Message to show when the user attempting to make a transfer has been set to be "Excluded" from using myCRED.', 'mycred'),
153
+ value: excluded,
154
+ onChange: setExcluded
155
+ }),
156
+ el(TextControl, {
157
+ label: __('Amount', 'mycred'),
158
+ help: __('Amount of points for clicking on this link. Use zero to give the amount you set in your "Points for clicking on links" hook settings.', 'mycred'),
159
+ value: amount,
160
+ onChange: setAmount
161
+ }),
162
+ el(TextControl, {
163
+ label: __('Placeholder', 'mycred'),
164
+ help: __('Optional text to show in the recipient field via the placeholder attribute.', 'mycred'),
165
+ value: placeholder,
166
+ onChange: setPlaceholder
167
+ }),
168
+ el(TextControl, {
169
+ label: __('Reference', 'mycred'),
170
+ help: __('By default, transfers are logged with "transfer" as reference. You can change this to a unique lowercase word like "donation" or "charity_fund_raiser" to separate transfers made with this shortcode from others.', 'mycred'),
171
+ value: ref,
172
+ onChange: setRef
173
+ }),
174
+ el(TextControl, {
175
+ label: __('Recipient Label', 'mycred'),
176
+ help: __('Option to change the label shown above the recipient field.', 'mycred'),
177
+ value: recipient_label,
178
+ onChange: setRecLabel
179
+ }),
180
+ el(TextControl, {
181
+ label: __('Amount Label', 'mycred'),
182
+ help: __('Option to change the label shown above the amount field.', 'mycred'),
183
+ value: amount_label,
184
+ onChange: setAmountLabel
185
+ }),
186
+ el(TextControl, {
187
+ label: __('Balance Label', 'mycred'),
188
+ help: __('Option to change the label shown above the point type selection. Only used if more then one point type is setup to be transferable.', 'mycred'),
189
+ value: balance_label,
190
+ onChange: setBalanceLabel
191
+ }),
192
+ )
193
+ ]);
194
+ },
195
+ save: function (props) {
196
+ return null;
197
+ }
198
+ });
199
+ })(window.wp);
includes/mycred-blocks/blocks/mycred-transfer/mycred-transfer.php ADDED
@@ -0,0 +1,17 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ add_action('enqueue_block_editor_assets', 'mycred_transfers');
4
+
5
+ function mycred_transfers() {
6
+ wp_enqueue_script(
7
+ 'mycred-transfers', plugins_url('index.js', __FILE__), array('wp-blocks', 'wp-element', 'wp-components', 'wp-editor')
8
+ );
9
+ }
10
+
11
+ register_block_type('mycred-blocks/mycred-transfers', array(
12
+ 'render_callback' => 'mycred_transfer_callback'
13
+ ));
14
+
15
+ function mycred_transfer_callback($attributes) {
16
+ return "[mycred_transfer " . mycred_extract_attributes($attributes) . "]";
17
+ }
includes/mycred-blocks/blocks/mycred-users-of-all-ranks/index.js ADDED
@@ -0,0 +1,135 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ (function (wp) {
2
+ var registerBlockType = wp.blocks.registerBlockType;
3
+ var InspectorControls = wp.editor.InspectorControls;
4
+ var el = wp.element.createElement;
5
+ var TextControl = wp.components.TextControl;
6
+ var ToggleControl = wp.components.ToggleControl;
7
+ var SelectControl = wp.components.SelectControl;
8
+ var __ = wp.i18n.__;
9
+ registerBlockType('mycred-blocks/mycred-users-of-all-ranks', {
10
+ title: __('Users of all ranks', 'mycred'),
11
+ category: 'mycred',
12
+ attributes: {
13
+ login: {
14
+ type: 'string'
15
+ },
16
+ number: {
17
+ type: 'string'
18
+ },
19
+ show_logo: {
20
+ type: 'bool',
21
+ default: true
22
+ },
23
+ logo_size: {
24
+ type: 'string',
25
+ default: 'post-thumbnail'
26
+ },
27
+ wrap: {
28
+ type: 'string',
29
+ default: 'div'
30
+ },
31
+ nothing: {
32
+ type: 'string',
33
+ default: 'No users found with this rank'
34
+ },
35
+ ctype: {
36
+ type: 'string'
37
+ }
38
+ },
39
+ edit: function (props) {
40
+ var login = props.attributes.login;
41
+ var number = props.attributes.number;
42
+ var show_logo = props.attributes.show_logo;
43
+ var logo_size = props.attributes.logo_size;
44
+ var wrap = props.attributes.wrap;
45
+ var nothing = props.attributes.nothing;
46
+ var ctype = props.attributes.ctype;
47
+
48
+ var options = [];
49
+
50
+ function setLogin(value) {
51
+ props.setAttributes({login: value});
52
+ }
53
+ function setNumber(value) {
54
+ props.setAttributes({number: value});
55
+ }
56
+
57
+ function setShowLogo(value) {
58
+ props.setAttributes({show_logo: value});
59
+ }
60
+ function setLogoSize(value) {
61
+ props.setAttributes({logo_size: value});
62
+ }
63
+ function setWrap(value) {
64
+ props.setAttributes({wrap: value});
65
+ }
66
+ function setNothing(value) {
67
+ props.setAttributes({nothing: value});
68
+ }
69
+
70
+ function setPtType(value) {
71
+ props.setAttributes({ctype: value});
72
+ }
73
+
74
+ Object.keys(mycred_types).forEach(function (key) {
75
+ options.push({
76
+ label: mycred_types[key],
77
+ value: key
78
+ });
79
+ });
80
+
81
+ return el('div', {}, [
82
+ el('p', {}, __('Users of all ranks Shortcode', 'mycred')
83
+ ),
84
+ el(InspectorControls, null,
85
+ el(TextControl, {
86
+ label: __('Login Message', 'mycred'),
87
+ help: __('Message to show for logged out users. This shortcode will not return anything if this is left empty.', 'mycred'),
88
+ value: login,
89
+ onChange: setLogin
90
+ }),
91
+ el(TextControl, {
92
+ label: __('Number of Users', 'mycred'),
93
+ help: __('The number of users to return. Use -1 to return all users of this rank.', 'mycred'),
94
+ value: number,
95
+ onChange: setNumber
96
+ }),
97
+ el(SelectControl, {
98
+ label: __('Point Type', 'mycred'),
99
+ help: __('The point type you want to show', 'mycred'),
100
+ value: ctype,
101
+ onChange: setPtType,
102
+ options
103
+ }),
104
+ el(ToggleControl, {
105
+ label: __('Show Logo', 'mycred'),
106
+ help: __('Option to show the rank logo. Defaults to no.', 'mycred'),
107
+ checked: show_logo,
108
+ onChange: setShowLogo
109
+ }),
110
+ el(TextControl, {
111
+ label: __('Logo Size', 'mycred'),
112
+ help: __('The logo size to show. Defaults to "post-thumbnail".', 'mycred'),
113
+ value: logo_size,
114
+ onChange: setLogoSize
115
+ }),
116
+ el(TextControl, {
117
+ label: __('Wrapper Element', 'mycred'),
118
+ help: __('Option to wrap each row in a specific type of HTML element. Defaults to "div" but you can also use "table" to render a table. Can not be empty!', 'mycred'),
119
+ value: wrap,
120
+ onChange: setWrap
121
+ }),
122
+ el(TextControl, {
123
+ label: __('No Results', 'mycred'),
124
+ help: __('Message to show when the given rank has no users.', 'mycred'),
125
+ value: nothing,
126
+ onChange: setNothing
127
+ }),
128
+ )
129
+ ]);
130
+ },
131
+ save: function (props) {
132
+ return null;
133
+ }
134
+ });
135
+ })(window.wp);
includes/mycred-blocks/blocks/mycred-users-of-all-ranks/mycred-users-of-all-ranks.php ADDED
@@ -0,0 +1,22 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ add_action('enqueue_block_editor_assets', 'mycred_users_of_all_ranks');
4
+
5
+ function mycred_users_of_all_ranks() {
6
+
7
+ wp_enqueue_script(
8
+ 'mycred-users-of-all-ranks', plugins_url('index.js', __FILE__), array('wp-blocks', 'wp-element', 'wp-components', 'wp-editor')
9
+ );
10
+ }
11
+
12
+ register_block_type('mycred-blocks/mycred-users-of-all-ranks', array(
13
+ 'render_callback' => 'mycred_users_of_all_ranks_callback'
14
+ ));
15
+
16
+ function mycred_users_of_all_ranks_callback($attributes) {
17
+
18
+ if ($attributes['ctype'] == '')
19
+ $attributes['ctype'] = 'mycred_default';
20
+
21
+ return "[mycred_users_of_all_ranks " . mycred_extract_attributes($attributes) . "]";
22
+ }
includes/mycred-blocks/blocks/mycred-users-of-rank/index.js ADDED
@@ -0,0 +1,152 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ (function (wp) {
2
+ var registerBlockType = wp.blocks.registerBlockType;
3
+ var InspectorControls = wp.editor.InspectorControls;
4
+ var el = wp.element.createElement;
5
+ var TextControl = wp.components.TextControl;
6
+ var SelectControl = wp.components.SelectControl;
7
+ var __ = wp.i18n.__;
8
+
9
+ registerBlockType('mycred-blocks/mycred-users-of-rank', {
10
+ title: __('Users of rank', 'mycred'),
11
+ category: 'mycred',
12
+ attributes: {
13
+ rank_id: {
14
+ type: 'string'
15
+ },
16
+ login: {
17
+ type: 'string'
18
+ },
19
+ number: {
20
+ type: 'string',
21
+ default: '10'
22
+ },
23
+ wrap: {
24
+ type: 'string',
25
+ default: '1'
26
+ },
27
+ col: {
28
+ type: 'string',
29
+ default: '1'
30
+ },
31
+ nothing: {
32
+ type: 'string',
33
+ default: 'No users found with this rank'
34
+ },
35
+ order: {
36
+ type: 'string'
37
+ },
38
+ ctype: {
39
+ type: 'string'
40
+ }
41
+ },
42
+ edit: function (props) {
43
+ var rank_id = props.attributes.rank_id;
44
+ var login = props.attributes.login;
45
+ var number = props.attributes.number;
46
+ var wrap = props.attributes.wrap;
47
+ var col = props.attributes.col;
48
+ var nothing = props.attributes.nothing;
49
+ var order = props.attributes.order;
50
+ var ctype = props.attributes.ctype;
51
+
52
+ var options = [];
53
+
54
+ function setRankId(value) {
55
+ props.setAttributes({rank_id: value});
56
+ }
57
+ function setLogin(value) {
58
+ props.setAttributes({login: value});
59
+ }
60
+ function setNumber(value) {
61
+ props.setAttributes({number: value});
62
+ }
63
+
64
+ function setWrap(value) {
65
+ props.setAttributes({wrap: value});
66
+ }
67
+ function setCol(value) {
68
+ props.setAttributes({col: value});
69
+ }
70
+ function setNothing(value) {
71
+ props.setAttributes({nothing: value});
72
+ }
73
+ function setOrder(value) {
74
+ props.setAttributes({order: value});
75
+ }
76
+
77
+ function setPtType(value) {
78
+ props.setAttributes({ctype: value});
79
+ }
80
+
81
+ Object.keys(mycred_types).forEach(function (key) {
82
+ options.push({
83
+ label: mycred_types[key],
84
+ value: key
85
+ });
86
+ });
87
+
88
+ return el('div', {}, [
89
+ el('p', {}, __('Users of rank Shortcode', 'mycred')
90
+ ),
91
+ el(InspectorControls, null,
92
+ el(TextControl, {
93
+ label: __('Rank ID', 'mycred'),
94
+ help: __('The rank to list users for', 'mycred'),
95
+ value: rank_id,
96
+ onChange: setRankId
97
+ }),
98
+ el(TextControl, {
99
+ label: __('Login Message', 'mycred'),
100
+ help: __('Message to show for logged out users. This shortcode will not return anything if this is left empty.', 'mycred'),
101
+ value: login,
102
+ onChange: setLogin
103
+ }),
104
+ el(TextControl, {
105
+ label: __('Number of Users', 'mycred'),
106
+ help: __('The number of users to return. Use -1 to return all users of this rank.', 'mycred'),
107
+ value: number,
108
+ onChange: setNumber
109
+ }),
110
+ el(TextControl, {
111
+ label: __('Wrapper Element', 'mycred'),
112
+ help: __('Option to wrap each row in a specific type of HTML element. Defaults to "div" but you can also use "table" to render a table. Can not be empty!', 'mycred'),
113
+ value: wrap,
114
+ onChange: setWrap
115
+ }),
116
+ el(TextControl, {
117
+ label: __('Table Columns', 'mycred'),
118
+ help: __('If you are using a table as the wrapper, you can set the number of columns you want to use. Unless you have customized the rendering of this shortcode, this should remain at 1.', 'mycred'),
119
+ value: col,
120
+ onChange: setCol
121
+ }),
122
+ el(TextControl, {
123
+ label: __('No Results', 'mycred'),
124
+ help: __('Message to show when the given rank has no users', 'mycred'),
125
+ value: nothing,
126
+ onChange: setNothing
127
+ }),
128
+ el(SelectControl, {
129
+ label: __('Order', 'mycred'),
130
+ help: __('Users are sorted according to their balance. Here you can select which order you want to show them. Lowest to highest or highest to lowest.', 'mycred'),
131
+ value: order,
132
+ onChange: setOrder,
133
+ options: [
134
+ {label: 'Descending', value: 'DESC'},
135
+ {label: 'Ascending', value: 'ASC'}
136
+ ]
137
+ }),
138
+ el(SelectControl, {
139
+ label: __('Point Type', 'mycred'),
140
+ help: __('The point type you want to show', 'mycred'),
141
+ value: ctype,
142
+ onChange: setPtType,
143
+ options
144
+ }),
145
+ )
146
+ ]);
147
+ },
148
+ save: function (props) {
149
+ return null;
150
+ }
151
+ });
152
+ })(window.wp);
includes/mycred-blocks/blocks/mycred-users-of-rank/mycred-users-of-rank.php ADDED
@@ -0,0 +1,22 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ add_action('enqueue_block_editor_assets', 'mycred_users_of_rank');
4
+
5
+ function mycred_users_of_rank() {
6
+
7
+ wp_enqueue_script(
8
+ 'mycred-users-of-rank', plugins_url('index.js', __FILE__), array('wp-blocks', 'wp-element', 'wp-components', 'wp-editor')
9
+ );
10
+ }
11
+
12
+ register_block_type('mycred-blocks/mycred-users-of-rank', array(
13
+ 'render_callback' => 'mycred_users_of_rank_callback'
14
+ ));
15
+
16
+ function mycred_users_of_rank_callback($attributes) {
17
+
18
+ if ($attributes['ctype'] == '')
19
+ $attributes['ctype'] = 'mycred_default';
20
+
21
+ return "[mycred_users_of_rank " . mycred_extract_attributes($attributes) . "]";
22
+ }
includes/mycred-blocks/blocks/mycred-video/index.js ADDED
@@ -0,0 +1,136 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ (function (wp) {
2
+ var registerBlockType = wp.blocks.registerBlockType;
3
+ var InspectorControls = wp.editor.InspectorControls;
4
+ var el = wp.element.createElement;
5
+ var TextControl = wp.components.TextControl;
6
+ var SelectControl = wp.components.SelectControl;
7
+
8
+ var __ = wp.i18n.__;
9
+ registerBlockType('mycred-blocks/mycred-video', {
10
+ title: __('Video', 'mycred'),
11
+ category: 'mycred',
12
+ attributes: {
13
+ video_id: {
14
+ type: 'string'
15
+ },
16
+ width: {
17
+ type: 'string',
18
+ default: '560'
19
+ },
20
+ height: {
21
+ type: 'string',
22
+ default: '315'
23
+ },
24
+ ctype: {
25
+ type: 'string'
26
+ },
27
+ amount: {
28
+ type: 'string'
29
+ },
30
+ logic: {
31
+ type: 'string'
32
+ },
33
+ interval: {
34
+ type: 'string'
35
+ }
36
+ },
37
+ edit: function (props) {
38
+ var video_id = props.attributes.video_id;
39
+ var width = props.attributes.width;
40
+ var height = props.attributes.height;
41
+ var ctype = props.attributes.ctype;
42
+ var amount = props.attributes.amount;
43
+ var logic = props.attributes.logic;
44
+ var interval = props.attributes.interval;
45
+ var options = [];
46
+ function setVideoId(value) {
47
+ props.setAttributes({video_id: value});
48
+ }
49
+ function setWidth(value) {
50
+ props.setAttributes({width: value});
51
+ }
52
+
53
+ function setHeight(value) {
54
+ props.setAttributes({height: value});
55
+ }
56
+ function setAmount(value) {
57
+ props.setAttributes({amount: value});
58
+ }
59
+ function setLogic(value) {
60
+ props.setAttributes({logic: value});
61
+ }
62
+ function setInterval(value) {
63
+ props.setAttributes({interval: value});
64
+ }
65
+
66
+ function setPtType(value) {
67
+ props.setAttributes({ctype: value});
68
+ }
69
+
70
+ Object.keys(mycred_types).forEach(function (key) {
71
+ options.push({
72
+ label: mycred_types[key],
73
+ value: key
74
+ });
75
+ });
76
+
77
+ return el('div', {}, [
78
+ el('p', {}, __('Video Shortcode', 'mycred')
79
+ ),
80
+ el(InspectorControls, null,
81
+ el(TextControl, {
82
+ label: __('Video ID', 'mycred'),
83
+ help: __('Required video ID to show. No URls or embed codes! Just the video ID', 'mycred'),
84
+ value: video_id,
85
+ onChange: setVideoId
86
+ }),
87
+ el(TextControl, {
88
+ label: __('Width', 'mycred'),
89
+ help: __('Width of the Iframe', 'mycred'),
90
+ value: width,
91
+ onChange: setWidth
92
+ }),
93
+ el(TextControl, {
94
+ label: __('Height', 'mycred'),
95
+ help: __('Height of the Iframe.', 'mycred'),
96
+ value: height,
97
+ onChange: setHeight
98
+ }),
99
+ el(TextControl, {
100
+ label: __('Amount', 'mycred'),
101
+ help: __('The amount of points to give users for watching this video. Leave empty to use your default settings.', 'mycred'),
102
+ value: amount,
103
+ onChange: setAmount
104
+ }),
105
+ el(SelectControl, {
106
+ label: __('Logic', 'mycred'),
107
+ help: __('The award logic to use', 'mycred'),
108
+ value: logic,
109
+ onChange: setLogic,
110
+ options: [
111
+ {label: 'Play - Award points as soon as video starts playing', value: 'play'},
112
+ {label: 'Full - Award points only if user watches the entire video', value: 'full'},
113
+ {label: 'Interval - Award points every x seconds watched', value: 'interval'}
114
+ ]
115
+ }),
116
+ el(TextControl, {
117
+ label: __('Interval', 'mycred'),
118
+ help: __('Number of seconds that a user must watch to get points. Only use this if you have set "Logic" to "Interval".', 'mycred'),
119
+ value: interval,
120
+ onChange: setInterval
121
+ }),
122
+ el(SelectControl, {
123
+ label: __('Point Type', 'mycred'),
124
+ help: __('The point type you want to show', 'mycred'),
125
+ value: ctype,
126
+ onChange: setPtType,
127
+ options
128
+ }),
129
+ )
130
+ ]);
131
+ },
132
+ save: function (props) {
133
+ return null;
134
+ }
135
+ });
136
+ })(window.wp);
includes/mycred-blocks/blocks/mycred-video/mycred-video.php ADDED
@@ -0,0 +1,22 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ add_action('enqueue_block_editor_assets', 'mycred_video');
4
+
5
+ function mycred_video() {
6
+
7
+ wp_enqueue_script(
8
+ 'mycred-video', plugins_url('index.js', __FILE__), array('wp-blocks', 'wp-element', 'wp-components', 'wp-editor')
9
+ );
10
+ }
11
+
12
+ register_block_type('mycred-blocks/mycred-video', array(
13
+ 'render_callback' => 'mycred_video_callback'
14
+ ));
15
+
16
+ function mycred_video_callback($attributes) {
17
+
18
+ if ($attributes['ctype'] == '')
19
+ $attributes['ctype'] = 'mycred_default';
20
+
21
+ return "[mycred_video " . mycred_extract_attributes($attributes) . "]";
22
+ }
includes/mycred-blocks/includes/mycred-gutenberg-functions.php ADDED
@@ -0,0 +1,29 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ function mycred_extract_attributes($attributes) {
4
+ if (empty($attributes)) {
5
+ return;
6
+ }
7
+ foreach ($attributes as $k => $attribute) {
8
+ $attr[] = $k . '=' . "'" . $attribute . "'";
9
+ }
10
+ return implode(' ',$attr);
11
+ }
12
+
13
+ if ( version_compare( $GLOBALS['wp_version'], '5.8-alpha-1', '<' ) ) {
14
+ add_filter('block_categories', 'mb_block_categories', 10, 2);
15
+ } else {
16
+ add_filter('block_categories_all', 'mb_block_categories', 10, 2);
17
+ }
18
+
19
+ function mb_block_categories($categories, $post) {
20
+ /** If mb.ideas is already in categories return categories */
21
+ return array_merge(
22
+ $categories, array(
23
+ array(
24
+ 'slug' => 'mycred',
25
+ 'title' => __('MYCRED', 'mycred'),
26
+ ),
27
+ )
28
+ );
29
+ }
includes/mycred-blocks/mycred-blocks.php ADDED
@@ -0,0 +1,120 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ if (!defined('ABSPATH')) {
4
+ exit; // Exit if accessed directly.
5
+ }
6
+
7
+ define( 'mycred_gutenberg_SLUG', 'mycred-gutenberg-blocks' );
8
+ define( 'mycred_gutenberg_VERSION', '1.1.2' );
9
+ define( 'mycred_gutenberg', __FILE__ );
10
+
11
+ final class MyCred_Gutenberg {
12
+
13
+ private static $_instance = null;
14
+
15
+ /**
16
+ * Instance
17
+ * Ensures only one instance of the class is loaded or can be loaded.
18
+ * @since 1.0.0
19
+ * @access public
20
+ * @static
21
+ * @return MyCred_Gutenberg An instance of the class.
22
+ */
23
+ public static function instance() {
24
+
25
+ if (is_null(self::$_instance)) {
26
+ self::$_instance = new self();
27
+ }
28
+ return self::$_instance;
29
+ }
30
+
31
+ public function __construct() {
32
+ add_action('plugins_loaded', [$this, 'init']);
33
+ }
34
+
35
+ public function init() {
36
+
37
+ if (!class_exists('myCRED_Core')) {
38
+ add_action('admin_notices', [$this, 'admin_notice_mycred_missing_plugin']);
39
+ return;
40
+ }
41
+
42
+ if (!function_exists('register_block_type'))
43
+ return;
44
+
45
+ $this->includes();
46
+ add_action('init', [$this, 'load_modules']);
47
+ }
48
+
49
+ public function admin_notice_mycred_missing_plugin() {
50
+
51
+ if (isset($_GET['activate']))
52
+ unset($_GET['activate']);
53
+
54
+ $message = sprintf(
55
+ esc_html__('"%1$s" requires "%2$s" to be installed and activated.', 'mycred'), '<b>' . esc_html__('myCRED for Gutenberg', 'mycred') . '</b>', '<b>' . esc_html__('myCRED', 'mycred') . '</b>'
56
+ );
57
+
58
+ printf('<div class="notice notice-warning is-dismissible"><p>%1$s</p></div>', $message);
59
+ }
60
+
61
+ public function includes() {
62
+ require_once( __DIR__ . '/includes/mycred-gutenberg-functions.php' );
63
+ }
64
+
65
+ public function load_modules() {
66
+
67
+ $mycred_modules = [
68
+ 'mycred-affiliate-id',
69
+ 'mycred-affiliate-link',
70
+ 'mycred-best-user',
71
+ 'mycred-exchange',
72
+ 'mycred-give',
73
+ 'mycred-history',
74
+ 'mycred-hook-table',
75
+ 'mycred-leaderboard',
76
+ 'mycred-link',
77
+ 'mycred-my-balance',
78
+ 'mycred-total-balance',
79
+ 'mycred-total-pts',
80
+ 'mycred-total-since',
81
+ 'mycred-video',
82
+ 'mycred-my-balance-converted',
83
+ ];
84
+
85
+ if (class_exists('myCRED_Badge_Module')) {
86
+ $mycred_modules[] = 'mycred-my-badges';
87
+ $mycred_modules[] = 'mycred-badges';
88
+ }
89
+
90
+ if (class_exists('myCRED_buyCRED_Module')) {
91
+ $mycred_modules[] = 'mycred-buy';
92
+ $mycred_modules[] = 'mycred-buy-form';
93
+ }
94
+ if (class_exists('myCRED_Coupons_Module')) {
95
+ $mycred_modules[] = 'mycred-load-coupon';
96
+ }
97
+ if (class_exists('myCRED_Email_Notice_Module')) {
98
+ $mycred_modules[] = 'mycred-email-subsc';
99
+ }
100
+
101
+ if (class_exists('myCRED_Ranks_Module')) {
102
+ $mycred_modules[] = 'mycred-my-rank';
103
+ $mycred_modules[] = 'mycred-my-ranks';
104
+ $mycred_modules[] = 'mycred-users-of-all-ranks';
105
+ $mycred_modules[] = 'mycred-users-of-rank';
106
+ $mycred_modules[] = 'mycred-list-ranks';
107
+ }
108
+
109
+ if (class_exists('myCRED_Transfer_Module')) {
110
+ $mycred_modules[] = 'mycred-transfer';
111
+ }
112
+
113
+ foreach ($mycred_modules as $mycred_module) {
114
+ require_once __DIR__ . "/blocks/$mycred_module/$mycred_module.php";
115
+ }
116
+ }
117
+
118
+ }
119
+
120
+ MyCred_Gutenberg::instance();
includes/mycred-functions.php CHANGED
@@ -4252,4 +4252,31 @@ if ( ! function_exists( 'mycred_get_email_instances' ) ) :
4252
  return apply_filters( 'mycred_email_instances', $instances );
4253
 
4254
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4255
  endif;
4252
  return apply_filters( 'mycred_email_instances', $instances );
4253
 
4254
  }
4255
+ endif;
4256
+
4257
+ /**
4258
+ * Sanitizes Array | Associative Array | Multi-dimensional Array
4259
+ * @since 2.4
4260
+ * @version 1.0
4261
+ */
4262
+
4263
+ if( !function_exists( 'mycred_sanitize_array' ) ):
4264
+ function mycred_sanitize_array( $_array )
4265
+ {
4266
+ foreach( $_array as $key => $value )
4267
+ {
4268
+ $key = sanitize_text_field( $key );
4269
+
4270
+ if( is_array( $value ) )
4271
+ {
4272
+ $value = mycred_sanitize_array( $value );
4273
+ }
4274
+ else
4275
+ {
4276
+ $_array[$key] = sanitize_text_field( $value );
4277
+ }
4278
+ }
4279
+
4280
+ return $_array;
4281
+ }
4282
  endif;
includes/mycred-network.php DELETED
@@ -1,243 +0,0 @@
1
- <?php
2
- if ( ! defined( 'myCRED_VERSION' ) ) exit;
3
-
4
- /**
5
- * myCRED_Network class
6
- * @since 0.1
7
- * @version 1.1
8
- */
9
- if ( ! class_exists( 'myCRED_Network_Module' ) ) {
10
- class myCRED_Network_Module {
11
-
12
- public $core;
13
- public $plug;
14
-
15
- /**
16
- * Construct
17
- */
18
- function __construct() {
19
- global $mycred_network;
20
- $this->core = mycred();
21
- }
22
-
23
- /**
24
- * Load
25
- * @since 0.1
26
- * @version 1.0
27
- */
28
- public function load() {
29
- add_action( 'admin_init', array( $this, 'module_admin_init' ) );
30
- add_action( 'admin_head', array( $this, 'admin_menu_styling' ) );
31
- add_action( 'network_admin_menu', array( $this, 'add_menu' ) );
32
-
33
- add_filter( 'site_option_active_sitewide_plugins', array( $this, 'network_check' ) );
34
- }
35
-
36
- /**
37
- * Init
38
- * @since 0.1
39
- * @version 1.0
40
- */
41
- public function module_admin_init() {
42
- register_setting( 'mycred_network', 'mycred_network', array( $this, 'save_network_prefs' ) );
43
- }
44
-
45
- /**
46
- * Add Network Menu Items
47
- * @since 0.1
48
- * @version 1.2
49
- */
50
- public function add_menu() {
51
- $pages[] = add_menu_page(
52
- __( 'myCRED', 'mycred' ),
53
- __( 'myCRED', 'mycred' ),
54
- 'manage_network_options',
55
- 'myCRED_Network',
56
- '',
57
- 'dashicons-star-filled'
58
- );
59
- $pages[] = add_submenu_page(
60
- 'myCRED_Network',
61
- __( 'Network Settings', 'mycred' ),
62
- __( 'Network Settings', 'mycred' ),
63
- 'manage_network_options',
64
- 'myCRED_Network',
65
- array( $this, 'admin_page_settings' )
66
- );
67
-
68
- foreach ( $pages as $page )
69
- add_action( 'admin_print_styles-' . $page, array( $this, 'admin_menu_styling' ) );
70
- }
71
-
72
- /**
73
- * Network Check
74
- * Blocks mycred from being used if the plugin is network wide
75
- * enabled.
76
- * @since 1.3
77
- * @version 1.0
78
- */
79
- public function network_check( $value ) {
80
- global $current_blog;
81
-
82
- $network = mycred_get_settings_network();
83
- if ( empty( $network['block'] ) ) return $value;
84
-
85
- $list = explode( ',', $network['block'] );
86
- if ( in_array( $current_blog->blog_id, $list ) ) {
87
- unset( $value['mycred/mycred.php'] );
88
- }
89
-
90
- return $value;
91
- }
92
-
93
- /**
94
- * Add Admin Menu Styling
95
- * @since 0.1
96
- * @version 1.0
97
- */
98
- public function admin_menu_styling() {
99
- global $wp_version;
100
-
101
- wp_enqueue_style( 'mycred-admin' );
102
- $image = plugins_url( 'assets/images/logo-menu.png', myCRED_THIS ); ?>
103
-
104
- <style type="text/css">
105
- h4:before { float:right; padding-right: 12px; font-size: 14px; font-weight: normal; color: silver; }
106
- h4.ui-accordion-header.ui-state-active:before { content: "<?php _e( 'click to close', 'mycred' ); ?>"; }
107
- h4.ui-accordion-header:before { content: "<?php _e( 'click to open', 'mycred' ); ?>"; }
108
- </style>
109
- <?php
110
- }
111
-
112
- /**
113
- * Load Admin Page Styling
114
- * @since 0.1
115
- * @version 1.0
116
- */
117
- public function admin_print_styles() {
118
- if ( ! wp_style_is( 'mycred-admin', 'registered' ) ) {
119
- wp_register_style(
120
- 'mycred-admin',
121
- plugins_url( 'assets/css/admin.css', myCRED_THIS ),
122
- false,
123
- myCRED_VERSION . '.1',
124
- 'all'
125
- );
126
- }
127
- wp_enqueue_style( 'mycred-admin' );
128
-
129
- if ( ! wp_script_is( 'mycred-admin', 'registered' ) ) {
130
- wp_register_script(
131
- 'mycred-admin',
132
- plugins_url( 'assets/js/accordion.js', myCRED_THIS ),
133
- array( 'jquery', 'jquery-ui-core', 'jquery-ui-accordion' ),
134
- myCRED_VERSION . '.1'
135
- );
136
- wp_localize_script( 'mycred-admin', 'myCRED', apply_filters( 'mycred_localize_admin', array( 'active' => '-1' ) ) );
137
- }
138
- wp_enqueue_script( 'mycred-admin' );
139
- }
140
-
141
- /**
142
- * Network Settings Page
143
- * @since 0.1
144
- * @version 1.1
145
- */
146
- public function admin_page_settings() {
147
- // Security
148
- if ( ! current_user_can( 'manage_network_options' ) ) wp_die( __( 'Access Denied', 'mycred' ) );
149
-
150
- global $mycred_network;
151
-
152
- $prefs = mycred_get_settings_network();
153
- $name = mycred_label(); ?>
154
-
155
- <div class="wrap" id="myCRED-wrap">
156
- <div id="icon-myCRED" class="icon32"><br /></div>
157
- <h2> <?php echo sprintf( __( '%s Network', 'mycred' ), $name ); ?></h2>
158
- <?php
159
-
160
- // Inform user that myCRED has not yet been setup
161
- $setup = get_blog_option( 1, 'mycred_setup_completed', false );
162
- if ( $setup === false )
163
- echo '<div class="error"><p>' . sprintf( __( 'Note! %s has not yet been setup.', 'mycred' ), $name ) . '</p></div>';
164
-
165
- // Settings Updated
166
- if ( isset( $_GET['settings-updated'] ) )
167
- echo '<div class="updated"><p>' . __( 'Network Settings Updated', 'mycred' ) . '</p></div>'; ?>
168
-
169
- <p><?php echo sprintf( __( 'Configure network settings for %s.', 'mycred' ), $name ); ?></p>
170
- <form method="post" action="<?php echo admin_url( 'options.php' ); ?>" class="">
171
- <?php settings_fields( 'mycred_network' ); ?>
172
-
173
- <div class="list-items expandable-li" id="accordion">
174
- <h4><div class="icon icon-inactive core"></div><?php _e( 'Settings', 'mycred' ); ?></h4>
175
- <div class="body" style="display:block;">
176
- <label class="subheader"><?php _e( 'Master Template', 'mycred' ); ?></label>
177
- <ol id="myCRED-network-settings-enabling">
178
- <li>
179
- <input type="radio" name="mycred_network[master]" id="myCRED-network-overwrite-enabled" <?php checked( $prefs['master'], 1 ); ?> value="1" />
180
- <label for="myCRED-network-"><?php _e( 'Yes', 'mycred' ); ?></label>
181
- </li>
182
- <li>
183
- <input type="radio" name="mycred_network[master]" id="myCRED-network-overwrite-disabled" <?php checked( $prefs['master'], 0 ); ?> value="0" />
184
- <label for="myCRED-network-"><?php _e( 'No', 'mycred' ); ?></label>
185
- </li>
186
- <li>
187
- <p class="description"><?php echo sprintf( __( "If enabled, %s will use your main site's settings for all other sites in your network.", 'mycred' ), $name ); ?></p>
188
- </li>
189
- </ol>
190
- <label class="subheader"><?php _e( 'Central Logging', 'mycred' ); ?></label>
191
- <ol id="myCRED-network-log-enabling">
192
- <li>
193
- <input type="radio" name="mycred_network[central]" id="myCRED-network-overwrite-log-enabled" <?php checked( $prefs['central'], 1 ); ?> value="1" />
194
- <label for="myCRED-network-"><?php _e( 'Yes', 'mycred' ); ?></label>
195
- </li>
196
- <li>
197
- <input type="radio" name="mycred_network[central]" id="myCRED-network-overwrite-log-disabled" <?php checked( $prefs['central'], 0 ); ?> value="0" />
198
- <label for="myCRED-network-"><?php _e( 'No', 'mycred' ); ?></label>
199
- </li>
200
- <li>
201
- <p class="description"><?php echo sprintf( __( "If enabled, %s will log all site actions in your main site's log.", 'mycred' ), $name ); ?></p>
202
- </li>
203
- </ol>
204
- <label class="subheader"><?php _e( 'Site Block', 'mycred' ); ?></label>
205
- <ol id="myCRED-network-site-blocks">
206
- <li>
207
- <div class="h2"><input type="text" name="mycred_network[block]" id="myCRED-network-block" value="<?php echo $prefs['block']; ?>" class="long" /></div>
208
- <span class="description"><?php echo sprintf( __( 'Comma separated list of blog ids where %s is to be disabled.', 'mycred' ), $name ); ?></span>
209
- </li>
210
- </ol>
211
- <?php do_action( 'mycred_network_prefs', $this ); ?>
212
-
213
- </div>
214
- <?php do_action( 'mycred_after_network_prefs', $this ); ?>
215
-
216
- </div>
217
- <p><?php submit_button( __( 'Save Network Settings', 'mycred' ), 'primary large', 'submit', false ); ?></p>
218
- </form>
219
- <?php do_action( 'mycred_bottom_network_page', $this ); ?>
220
-
221
- </div>
222
- <?php
223
- }
224
-
225
- /**
226
- * Save Network Settings
227
- * @since 0.1
228
- * @version 1.1
229
- */
230
- public function save_network_prefs( $settings ) {
231
-
232
- $new_settings = array();
233
- $new_settings['master'] = ( isset( $settings['master'] ) ) ? $settings['master'] : 0;
234
- $new_settings['central'] = ( isset( $settings['central'] ) ) ? $settings['central'] : 0;
235
- $new_settings['block'] = sanitize_text_field( $settings['block'] );
236
-
237
- $new_settings = apply_filters( 'mycred_save_network_prefs', $new_settings, $settings, $this->core );
238
-
239
- return $new_settings;
240
- }
241
- }
242
- }
243
- ?>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
includes/mycred-remote.php CHANGED
@@ -53,43 +53,23 @@ if ( ! class_exists( 'myCRED_Remote' ) ) :
53
  */
54
  public function handle_magic() {
55
 
56
- if ( function_exists( 'get_magic_quotes_gpc' ) )
57
- {
58
- if ( get_magic_quotes_gpc() ) {
59
- $process = array( &$_GET, &$_POST, &$_COOKIE, &$_REQUEST );
60
-
61
- foreach ( $process as $key => $val ) {
62
- foreach ( $val as $k => $v ) {
63
- unset( $process[ $key ][ $k ] );
64
- if ( is_array( $v ) ) {
65
- $process[ $key ][ stripslashes( $k ) ] = $v;
66
- $process[] = &$process[ $key ][ stripslashes( $k ) ];
67
- } else {
68
- $process[ $key ][ stripslashes( $k ) ] = stripslashes( $v );
69
- }
70
- }
71
- }
72
-
73
- unset( $process );
74
- }
75
- }
76
- else
77
- {
78
- $process = array( &$_GET, &$_POST, &$_COOKIE, &$_REQUEST );
79
-
80
- foreach ( $process as $key => $val ) {
81
- foreach ( $val as $k => $v ) {
82
- unset( $process[ $key ][ $k ] );
83
- if ( is_array( $v ) ) {
84
- $process[ $key ][ $k ] = $v;
85
- $process[] = &$process[ $key ][ $k ];
86
- } else {
87
- $process[ $key ][ $k ] = $v ;
88
- }
89
- }
90
- }
91
- unset( $process );
92
- }
93
  // Let others play
94
  do_action_ref_array( 'mycred_remote_magic', array( &$this ) );
95
  }
53
  */
54
  public function handle_magic() {
55
 
56
+ $process = array( &$_GET, &$_POST, &$_COOKIE, &$_REQUEST );
57
+
58
+ foreach ( $process as $key => $val ) {
59
+ foreach ( $val as $k => $v ) {
60
+ unset( $process[ $key ][ $k ] );
61
+ if ( is_array( $v ) ) {
62
+ $process[ $key ][ stripslashes( $k ) ] = $v;
63
+ $process[] = &$process[ $key ][ stripslashes( $k ) ];
64
+ } else {
65
+ $process[ $key ][ stripslashes( $k ) ] = stripslashes( $v );
66
+ }
67
+ }
68
+ }
69
+
70
+ unset( $process );
71
+
72
+
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
73
  // Let others play
74
  do_action_ref_array( 'mycred_remote_magic', array( &$this ) );
75
  }
includes/mycred-tools-import-export.php ADDED
@@ -0,0 +1,1246 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ if( !class_exists( 'myCRED_Tools_Import_Export' ) ):
3
+ class myCRED_Tools_Import_Export extends myCRED_Setup_Import_Export
4
+ {
5
+ public $core_point_types;
6
+
7
+ public function __construct()
8
+ {
9
+ $this->core_point_types = mycred_get_types();
10
+
11
+ add_action( 'wp_ajax_mycred-tools-import-export', array( $this,'import_export' ) );
12
+ }
13
+
14
+ public function get_header()
15
+ {
16
+ $points = get_mycred_tools_page_url( 'points' );
17
+ $badges = get_mycred_tools_page_url( 'badges' );
18
+ $ranks = get_mycred_tools_page_url( 'ranks' );
19
+ $setup = get_mycred_tools_page_url( 'setup' );
20
+
21
+ $page = isset( $_GET['mycred-tools'] ) ? $_GET['mycred-tools'] : '';
22
+
23
+ $heading = $_GET['mycred-tools'] == 'setup' ? __( 'Export','mycred' ) : __( 'Import','mycred' );
24
+
25
+ echo "<h1>{$heading}</h1>";
26
+ ?>
27
+
28
+ <div class="subsubsub">
29
+ <a href="<?php echo $points; ?>" class="<?php echo ( isset( $_GET['mycred-tools'] ) && $_GET['mycred-tools'] == 'points' ) ? 'current' : ''; ?>"><?php _e( 'Points','mycred' ); ?></a>
30
+ <?php
31
+ if( class_exists( 'myCRED_Badge' ) )
32
+ {
33
+ $current = ( isset( $_GET['mycred-tools'] ) && $_GET['mycred-tools'] == 'badges' ) ? 'current' : '';
34
+ echo "| <a href='{$badges}' class='{$current}'> Badges</a>";
35
+ }
36
+
37
+ if( class_exists( 'myCRED_Ranks_Module' ) )
38
+ {
39
+ $current = ( isset( $_GET['mycred-tools'] ) && $_GET['mycred-tools'] == 'ranks' ) ? 'current' : '';
40
+ echo "| <a href='{$ranks}' class='{$current}'>Ranks</a>";
41
+ }
42
+ ?>
43
+
44
+ | <a href="<?php echo $setup; ?>" class="<?php echo ( isset( $_GET['mycred-tools'] ) && $_GET['mycred-tools'] == 'setup' ) ? 'current' : ''; ?>"><?php _e( 'Setup','mycred' ); ?></a>
45
+
46
+ <input type="hidden" class="request-tab" value="<?php echo $_GET['mycred-tools'] ?>" />
47
+ </div>
48
+ <br class="clear">
49
+ <?php
50
+
51
+ echo $this->get_body( $page );
52
+ }
53
+
54
+ public function get_body( $page )
55
+ {
56
+ //Points
57
+ if( $page == 'points' )
58
+ $this->get_points_page();
59
+
60
+ //Badges
61
+ if( $page == 'badges' )
62
+ $this->get_badge_page();
63
+
64
+ //Rank
65
+ if( $page == 'ranks' )
66
+ $this->get_rank_page();
67
+
68
+ //Setup
69
+ if( $page == 'setup' )
70
+ $this->get_setup_page();
71
+ }
72
+
73
+ public function get_points_page()
74
+ {
75
+ $uf_options = array(
76
+ 'id' => __( 'ID','mycred' ),
77
+ 'user_name' => __( 'Username','mycred' ),
78
+ 'email' => __( 'Email','mycred' )
79
+ );
80
+
81
+ $uf_attr = array(
82
+ 'id' => 'tools-uf-import-export'
83
+ );
84
+
85
+ $pt_options = $this->core_point_types;
86
+
87
+ $pr_attr = array(
88
+ 'id' => 'tools-type-import-export',
89
+ 'multiple' => 'multiple'
90
+ );
91
+
92
+ ?>
93
+ <div class="mycred-tools-import-export">
94
+ <h3><?php _e( 'User Points','mycred' ); ?></h3>
95
+ <table>
96
+ <tr>
97
+ <td><h4><?php _e( 'CSV File','mycred' ); ?></h4></td>
98
+ <td>
99
+ <form method="post" enctype="multipart/form-data">
100
+ <input type="file" id="import-file" name="file" accept=".csv" />
101
+ <button class="button button-primary", id="import">
102
+ <span class="dashicons dashicons-database-import v-align-middle"></span> <?php _e( 'Import User Points','mycred' ); ?>
103
+ </button>
104
+ </form>
105
+ </td>
106
+ </tr>
107
+ <tr>
108
+ <td>
109
+
110
+ </td>
111
+ <td>
112
+ <button class="button button-secondary" id="download-raw-template-csv">
113
+ <span class="dashicons dashicons-download v-align-middle"></span> <?php _e( 'Download Raw Template','mycred' ); ?>
114
+ </button>
115
+
116
+ <button class="button button-secondary" id="download-formatted-template-csv">
117
+ <span class="dashicons dashicons-download v-align-middle"></span> <?php _e( 'Download Formatted Template','mycred' ); ?>
118
+ </button>
119
+ </td>
120
+ </tr>
121
+ <tr>
122
+ <td>
123
+ <i><?php _e( 'Only raw format can be Import.', 'mycred' ) ?></i>
124
+ </td>
125
+ </tr>
126
+ </table>
127
+ <h1><?php _e( 'Export','mycred' ); ?></h1>
128
+ <h3><?php _e( 'User Points','mycred' ); ?></h3>
129
+ <table>
130
+ <tr>
131
+ <td>
132
+ <?php _e( 'Select Point Types to be Exported','mycred' ); ?>
133
+ </td>
134
+ <td>
135
+ <button class="button button-secondary" id="select-all-pt">
136
+ <span class="dashicons dashicons-download v-align-middle"></span> <?php _e( 'Select/ Deselect All','mycred' ); ?>
137
+ </button>
138
+ </td>
139
+ </tr>
140
+ </table>
141
+
142
+ <div class="mycred-container">
143
+ <label><?php _e( 'Select Point Types','mycred' ); ?></label>
144
+ <?php echo mycred_create_select2( $pt_options, $pr_attr ) ?>
145
+ </div>
146
+
147
+ <div class="mycred-container">
148
+ <label><?php _e( 'User Field in Exported File', 'mycred' ); ?></label>
149
+ <?php echo mycred_create_select2( $uf_options, $uf_attr ) ?>
150
+ </div>
151
+
152
+ <div class="mycred-container">
153
+ <button class="button button-primary" id="export-raw">
154
+ <span class="dashicons dashicons-database-export v-align-middle"></span> <?php _e( 'Export Raw', 'mycred' ); ?>
155
+ </button>
156
+
157
+ <button class="button button-primary" id="export-formatted">
158
+ <span class="dashicons dashicons-database-export v-align-middle"></span> <?php _e( 'Export Formatted', 'mycred' ); ?>
159
+ </button>
160
+ </div>
161
+ </div>
162
+ <?php
163
+ }
164
+
165
+ public function get_badge_page()
166
+ {
167
+ $uf_options = array(
168
+ 'id' => __( 'ID','mycred' ),
169
+ 'user_name' => __( 'Username','mycred' ),
170
+ 'email' => __( 'Email','mycred' )
171
+ );
172
+
173
+ $uf_attr = array(
174
+ 'id' => 'tools-uf-import-export'
175
+ );
176
+
177
+ $badges_options = array();
178
+
179
+ $badge_ids = mycred_get_badge_ids();
180
+
181
+ foreach( $badge_ids as $id )
182
+ $badges_options[$id] = get_the_title( $id );
183
+
184
+ $badges_attr = array(
185
+ 'id' => 'tools-type-import-export',
186
+ 'multiple' => 'multiple'
187
+ );
188
+
189
+ $badges_fields_options = array(
190
+ 'id' => 'ID',
191
+ 'title' => 'Title',
192
+ 'slug' => 'Slug'
193
+ );
194
+
195
+ $badges_fields_attr = array(
196
+ 'id' => 'tools-badge-fields-import-export'
197
+ );
198
+
199
+ $type_options = array(
200
+ 'id' => 'ID',
201
+ 'slug' => 'Slug',
202
+ 'title' => 'Title'
203
+ );
204
+
205
+ $type_attr = array(
206
+ 'id' => 'import-format-type'
207
+ );
208
+
209
+ ?>
210
+ <div class="mycred-tools-import-export">
211
+ <h3><?php _e( 'User Badges','mycred' ); ?></h3>
212
+ <table>
213
+ <tr>
214
+ <td><h4><?php _e( 'CSV File','mycred' ); ?></h4></td>
215
+ <td>
216
+ <form method="post" enctype="multipart/form-data">
217
+ <input type="file" id="import-file" name="file" accept=".csv" />
218
+ <?php echo mycred_create_select2( $type_options, $type_attr ) ?>
219
+ <button class="button button-primary", id="import">
220
+ <span class="dashicons dashicons-database-import v-align-middle"></span> <?php _e( 'Import User Badges','mycred' ); ?>
221
+ </button>
222
+ </form>
223
+ </td>
224
+ </tr>
225
+ <tr>
226
+ <td>
227
+
228
+ </td>
229
+ <td>
230
+ <button class="button button-secondary" id="download-raw-template-csv">
231
+ <span class="dashicons dashicons-download v-align-middle"></span> <?php _e( 'Download Raw Template','mycred' ); ?>
232
+ </button>
233
+ </td>
234
+ </tr>
235
+ <tr>
236
+ <td>
237
+ <i><?php _e( 'Only raw format can be Import.', 'mycred' ) ?></i>
238
+ </td>
239
+ </tr>
240
+ </table>
241
+ <h1><?php _e( 'Export','mycred' ); ?></h1>
242
+ <h3><?php _e( 'User Badges','mycred' ); ?></h3>
243
+ <table>
244
+ <tr>
245
+ <td>
246
+ <?php _e( 'Select Badges to be Exported','mycred' ); ?>
247
+ </td>
248
+ <td>
249
+ <button class="button button-secondary" id="select-all-pt">
250
+ <span class="dashicons dashicons-download v-align-middle"></span> <?php _e( 'Select/ Deselect All','mycred' ); ?>
251
+ </button>
252
+ </td>
253
+ </tr>
254
+ </table>
255
+
256
+ <div class="mycred-container">
257
+ <label><?php _e( 'Select Badges','mycred' ); ?></label>
258
+ <?php echo mycred_create_select2( $badges_options, $badges_attr ) ?>
259
+ </div>
260
+
261
+ <div class="mycred-container">
262
+ <label><?php _e( 'User Field in Exported File', 'mycred' ); ?></label>
263
+ <?php echo mycred_create_select2( $uf_options, $uf_attr ) ?>
264
+ </div>
265
+
266
+ <div class="mycred-container">
267
+ <label><?php _e( 'Badge Fields in Exported File', 'mycred' ); ?></label>
268
+ <?php echo mycred_create_select2( $badges_fields_options, $badges_fields_attr ) ?>
269
+ </div>
270
+
271
+ <div class="mycred-container">
272
+ <button class="button button-primary" id="export-raw">
273
+ <span class="dashicons dashicons-database-export v-align-middle"></span> <?php _e( 'Export Raw', 'mycred' ); ?>
274
+ </button>
275
+ </div>
276
+ </div>
277
+ <?php
278
+ }
279
+
280
+ public function get_rank_page()
281
+ {
282
+ $uf_options = array(
283
+ 'id' => __( 'ID','mycred' ),
284
+ 'user_name' => __( 'Username','mycred' ),
285
+ 'email' => __( 'Email','mycred' )
286
+ );
287
+
288
+ $uf_attr = array(
289
+ 'id' => 'tools-uf-import-export'
290
+ );
291
+
292
+ $ranks_options = array();
293
+
294
+ foreach( $this->core_point_types as $key => $value )
295
+ {
296
+ $_ranks = mycred_get_ranks( 'publish', '-1', 'ASC', $key );
297
+
298
+ foreach( $_ranks as $key => $value )
299
+ {
300
+ $ranks_options[$value->post->ID] = $value->post->post_title;
301
+ }
302
+ }
303
+
304
+ $ranks_attr = array(
305
+ 'id' => 'tools-type-import-export',
306
+ 'multiple' => 'multiple'
307
+ );
308
+
309
+ $ranks_fields_options = array(
310
+ 'id' => 'ID',
311
+ 'title' => 'Title',
312
+ 'slug' => 'Slug'
313
+ );
314
+
315
+ $ranks_fields_attr = array(
316
+ 'id' => 'tools-badge-fields-import-export'
317
+ );
318
+
319
+ $type_options = array(
320
+ 'id' => 'ID',
321
+ 'slug' => 'Slug',
322
+ 'title' => 'Title'
323
+ );
324
+
325
+ $type_attr = array(
326
+ 'id' => 'import-format-type'
327
+ );
328
+
329
+ ?>
330
+ <div class="mycred-tools-import-export">
331
+ <h3><?php _e( 'User Ranks','mycred' ); ?></h3>
332
+ <table>
333
+ <tr>
334
+ <td><h4><?php _e( 'CSV File','mycred' ); ?></h4></td>
335
+ <td>
336
+ <form method="post" enctype="multipart/form-data">
337
+ <input type="file" id="import-file" name="file" accept=".csv" />
338
+ <?php echo mycred_create_select2( $type_options, $type_attr ) ?>
339
+ <button class="button button-primary", id="import">
340
+ <span class="dashicons dashicons-database-import v-align-middle"></span> <?php _e( 'Import User Ranks','mycred' ); ?>
341
+ </button>
342
+ </form>
343
+ </td>
344
+ </tr>
345
+ <tr>
346
+ <td>
347
+
348
+ </td>
349
+ <td>
350
+ <button class="button button-secondary" id="download-raw-template-csv">
351
+ <span class="dashicons dashicons-download v-align-middle"></span> <?php _e( 'Download Raw Template','mycred' ); ?>
352
+ </button>
353
+ </td>
354
+ </tr>
355
+ <tr>
356
+ <td>
357
+ <i><?php _e( 'Make sure Ranks\' Behaviour is set to Manual Mode, Only Raw format can be Import.', 'mycred' ) ?></i>
358
+ </td>
359
+ </tr>
360
+ </table>
361
+ <h1><?php _e( 'Export','mycred' ); ?></h1>
362
+ <h3><?php _e( 'User Ranks','mycred' ); ?></h3>
363
+ <table>
364
+ <tr>
365
+ <td>
366
+ <?php _e( 'Select Ranks to be Exported','mycred' ); ?>
367
+ </td>
368
+ <td>
369
+ <button class="button button-secondary" id="select-all-pt">
370
+ <span class="dashicons dashicons-download v-align-middle"></span> <?php _e( 'Select/ Deselect All','mycred' ); ?>
371
+ </button>
372
+ </td>
373
+ </tr>
374
+ </table>
375
+
376
+ <div class="mycred-container">
377
+ <label><?php _e( 'Select Ranks','mycred' ); ?></label>
378
+ <?php echo mycred_create_select2( $ranks_options, $ranks_attr ) ?>
379
+ </div>
380
+
381
+ <div class="mycred-container">
382
+ <label><?php _e( 'User Field in Exported File', 'mycred' ); ?></label>
383
+ <?php echo mycred_create_select2( $uf_options, $uf_attr ) ?>
384
+ </div>
385
+
386
+ <div class="mycred-container">
387
+ <label><?php _e( 'Rank Fields in Exported File', 'mycred' ); ?></label>
388
+ <?php echo mycred_create_select2( $ranks_fields_options, $ranks_fields_attr ) ?>
389
+ </div>
390
+
391
+ <div class="mycred-container">
392
+ <button class="button button-primary" id="export-raw">
393
+ <span class="dashicons dashicons-database-export v-align-middle"></span> <?php _e( 'Export Raw', 'mycred' ); ?>
394
+ </button>
395
+ </div>
396
+ </div>
397
+ <?php
398
+ }
399
+
400
+
401
+
402
+ public function generate_csv( $assocDataArray ) {
403
+
404
+ if ( !empty( $assocDataArray ) ):
405
+
406
+ $fp = fopen( 'php://output', 'w' );
407
+ fputcsv( $fp, array_keys( reset($assocDataArray) ) );
408
+
409
+ foreach ( $assocDataArray AS $values ):
410
+ fputcsv( $fp, $values );
411
+ endforeach;
412
+
413
+ fclose( $fp );
414
+ endif;
415
+
416
+ exit();
417
+ }
418
+
419
+ public function downlaod_template_csv( $type, $template )
420
+ {
421
+ $date_format = get_option( 'date_format' ) . ' ' . get_option( 'time_format' );
422
+
423
+ if( $type == 'points' && $template == 'formatted' )
424
+ {
425
+ $logs = array(
426
+ array(
427
+ 'reference' => 'logging_in',
428
+ 'user_id' => 1,
429
+ 'date' => 1633344172,
430
+ 'points' => '10',
431
+ 'entry' => 'Points for logging in',
432
+ ),
433
+ array(
434
+ 'reference' => 'logging_in',
435
+ 'user_id' => 2,
436
+ 'date' => 1633344172,
437
+ 'points' => '10',
438
+ 'entry' => 'Points for logging in',
439
+ ),
440
+ array(
441
+ 'reference' => 'logging_in',
442
+ 'user_id' => 2,
443
+ 'date' => 1633344172,
444
+ 'points' => '10',
445
+ 'entry' => 'Points for logging in',
446
+ ),
447
+ array(
448
+ 'reference' => 'logging_in',
449
+ 'user_id' => 1,
450
+ 'date' => 1633344172,
451
+ 'points' => '10',
452
+ 'entry' => 'Points for logging in',
453
+ ),
454
+ );
455
+
456
+ $prep_logs= [];
457
+
458
+ foreach ( $logs as $key => $user ) :
459
+
460
+ $user_identification = $user['user_id'];
461
+
462
+ $prep_logs[$key]['User (ID, username or email)'] = $user_identification;
463
+
464
+ $prep_logs[$key]['Reference'] = $user['reference'];
465
+
466
+ $prep_logs[$key]['Date'] = date_i18n( $date_format, $user['date'] );
467
+
468
+ $prep_logs[$key]['Points'] = $user['points'];
469
+
470
+ $prep_logs[$key]['Entry'] = $user['entry'];
471
+
472
+ endforeach;
473
+
474
+ return $this->generate_csv( $prep_logs );
475
+ }
476
+
477
+ if( $type == 'points' && $template == 'raw' )
478
+ {
479
+ $logs = array(
480
+ array(
481
+ 'id' => 1,
482
+ 'ref' => 'registration',
483
+ 'ref_id' => 1,
484
+ 'user_id' => 1,
485
+ 'creds' => 100,
486
+ 'ctype' => 'mycred_default',
487
+ 'time' => '1633344167',
488
+ 'entry' => 'Manual Entry by Tester',
489
+ 'data' => 'a:1:{s:8:"ref_type";s:4:"user";}'
490
+ ),
491
+ array(
492
+ 'id' => 2,
493
+ 'ref' => 'site_visit',
494
+ 'ref_id' => 1,
495
+ 'user_id' => 1,
496
+ 'creds' => 50,
497
+ 'ctype' => 'mycred_default',
498
+ 'time' => '1633344167',
499
+ 'entry' => 'Manual Entry by Tester',
500
+ 'data' => 'a:1:{s:8:"ref_type";s:4:"user";}'
501
+ ),
502
+ array(
503
+ 'id' => 3,
504
+ 'ref' => 'logging_in',
505
+ 'ref_id' => 1,
506
+ 'user_id' => 1,
507
+ 'creds' => 100,
508
+ 'ctype' => 'mycred_default',
509
+ 'time' => '1633344167',
510
+ 'entry' => '%plural% for logging in',
511
+ 'data' => ''
512
+ ),
513
+ array(
514
+ 'id' => 4,
515
+ 'ref' => 'registration',
516
+ 'ref_id' => 1,
517
+ 'user_id' => 1,
518
+ 'creds' => 100,
519
+ 'ctype' => 'mycred_default',
520
+ 'time' => '1633344167',
521
+ 'entry' => 'Manual Entry by Tester',
522
+ 'data' => 'a:1:{s:8:"ref_type";s:4:"user";}'
523
+ ),
524
+ array(
525
+ 'id' => 5,
526
+ 'ref' => 'link_click',
527
+ 'ref_id' => 1,
528
+ 'user_id' => 1,
529
+ 'creds' => 100,
530
+ 'ctype' => 'mycred_default',
531
+ 'time' => '1633344167',
532
+ 'entry' => '%plural% for clicking on link to: %url%',
533
+ 'data' => 'a:4:{s:8:"ref_type";s:4:"link";s:8:"link_url";s:20:"http://www.mycred.me";s:7:"link_id";s:13:"hswwwmycredme";s:10:"link_title";s:14:"View portfolio";}'
534
+ ),
535
+ );
536
+
537
+ $prep_logs = array();
538
+
539
+ foreach ( $logs as $key => $user ) :
540
+
541
+ $user_identification = $user['user_id'];
542
+
543
+ $prep_logs[$key]['id'] = $user['id'];
544
+
545
+ $prep_logs[$key]['ref'] = $user['ref'];
546
+
547
+ $prep_logs[$key]['ref_id'] = $user['ref_id'];
548
+
549
+ $prep_logs[$key]['user_id'] = $user['user_id'];
550
+
551
+ $prep_logs[$key]['creds'] = $user['creds'];
552
+
553
+ $prep_logs[$key]['ctype'] = $user['ctype'];
554
+
555
+ $prep_logs[$key]['time'] = $user['time'];
556
+
557
+ $prep_logs[$key]['entry'] = $user['entry'];
558
+
559
+ $prep_logs[$key]['data'] = $user['data'];
560
+
561
+ endforeach;
562
+
563
+ return $this->generate_csv( $prep_logs );
564
+ }
565
+
566
+ if( $type == 'badges' && $template == 'raw' )
567
+ {
568
+ $logs = array(
569
+ array(
570
+ 'user' => 1,
571
+ 'badge' => '1, 2, 3'
572
+ ),
573
+ array(
574
+ 'user' => 2,
575
+ 'badge' => '1, 2'
576
+ ),
577
+ array(
578
+ 'user' => 3,
579
+ 'badge' => '2, 3'
580
+ ),
581
+ array(
582
+ 'user' => 4,
583
+ 'badge' => '3, 1'
584
+ ),
585
+ array(
586
+ 'user' => 5,
587
+ 'badge' => '1, 2'
588
+ ),
589
+ );
590
+
591
+ $prep_raw = array();
592
+
593
+ foreach ( $logs as $key => $user ) :
594
+
595
+ $prep_raw[$key]['user'] = $user['user'];
596
+
597
+ $prep_raw[$key]['badge'] = $user['badge'];
598
+
599
+ endforeach;
600
+
601
+ return $this->generate_csv( $prep_raw );
602
+ }
603
+
604
+ if( $type == 'ranks' && $template == 'raw' )
605
+ {
606
+ $logs = array(
607
+ array(
608
+ 'user' => 1,
609
+ 'rank' => '1, 2, 3'
610
+ ),
611
+ array(
612
+ 'user' => 2,
613
+ 'rank' => '1, 2'
614
+ ),
615
+ array(
616
+ 'user' => 3,
617
+ 'rank' => '2, 3'
618
+ ),
619
+ array(
620
+ 'user' => 4,
621
+ 'rank' => '3, 4'
622
+ ),
623
+ array(
624
+ 'user' => 5,
625
+ 'rank' => '1, 3'
626
+ ),
627
+ );
628
+
629
+ $prep_raw = array();
630
+
631
+ foreach ( $logs as $key => $user ) :
632
+
633
+ $prep_raw[$key]['user'] = $user['user'];
634
+
635
+ $prep_raw[$key]['rank'] = $user['rank'];
636
+
637
+ endforeach;
638
+
639
+ return $this->generate_csv( $prep_raw );
640
+ }
641
+
642
+ }
643
+
644
+ public function export_csv( $type, $template, $user_field = 'id', $types = array( MYCRED_DEFAULT_TYPE_KEY ), $post_field = null )
645
+ {
646
+ if( $type == 'points' && $template == 'raw' )
647
+ {
648
+ $args = array(
649
+ 'number' => -1,
650
+ 'order' => 'ASC',
651
+ 'ctype' => array(
652
+ 'ids' => $types,
653
+ 'compare' => 'IN'
654
+ )
655
+ );
656
+
657
+ $logs = new myCRED_Query_Log( $args );
658
+
659
+ $prep_logs = array();
660
+
661
+ foreach ( $logs->results as $key => $log ) :
662
+
663
+ $log->user_id = $this->get_user_by( $user_field, $log->user_id );
664
+
665
+ $user_identification = $log->user_id;
666
+
667
+ $prep_logs[$key]['id'] = $log->id;
668
+
669
+ $prep_logs[$key]['ref'] = $log->ref;
670
+
671
+ $prep_logs[$key]['ref_id'] = $log->ref_id;
672
+
673
+ $prep_logs[$key]['user_id'] = $log->user_id;
674
+
675
+ $prep_logs[$key]['creds'] = $log->creds;
676
+
677
+ $prep_logs[$key]['ctype'] = $log->ctype;
678
+
679
+ $prep_logs[$key]['time'] = $log->time;
680
+
681
+ $prep_logs[$key]['entry'] = $log->entry;
682
+
683
+ $prep_logs[$key]['data'] = $log->data;
684
+
685
+ endforeach;
686
+
687
+ return $this->generate_csv( $prep_logs );
688
+
689
+ }
690
+
691
+ if( $type == 'points' && $template == 'formatted' )
692
+ {
693
+ $date_format = get_option( 'date_format' ) . ' ' . get_option( 'time_format' );
694
+
695
+ $args = array(
696
+ 'number' => -1,
697
+ 'order' => 'ASC',
698
+ 'ctype' => array(
699
+ 'ids' => $types,
700
+ 'compare' => 'IN'
701
+ )
702
+ );
703
+
704
+ $logs = new myCRED_Query_Log( $args );
705
+
706
+ $prep_logs = array();
707
+
708
+ foreach ( $logs->results as $key => $log ) :
709
+
710
+ $log->user_id = $this->get_user_by( $user_field, $log->user_id );
711
+
712
+ $user_identification = $log->user_id;
713
+
714
+ $prep_logs[$key]['User (ID, username or email)'] = $log->user_id;
715
+
716
+ $prep_logs[$key]['Reference'] = ucwords( str_replace( array( '-', '_' ), ' ', $log->ref ) );
717
+
718
+ $prep_logs[$key]['Date'] = date_i18n( $date_format, $log->time );
719
+
720
+ $prep_logs[$key]['Points'] = $log->creds;
721
+
722
+ $mycred = mycred( $log->ctype );
723
+
724
+ $prep_logs[$key]['Entry'] = $mycred->parse_template_tags( $log->entry, $log );
725
+
726
+ endforeach;
727
+
728
+ return $this->generate_csv( $prep_logs );
729
+
730
+ }
731
+
732
+ if( $type == 'badges' && $template == 'raw' )
733
+ {
734
+ $user_ids = $this->get_all_user_ids();
735
+
736
+ $prep_raw = array();
737
+
738
+ foreach( $user_ids as $key => $user_id )
739
+ {
740
+ $user_has_badge = array();
741
+
742
+ foreach( $types as $badge_id )
743
+ {
744
+ if( mycred_user_has_badge( $user_id, $badge_id ) )
745
+ {
746
+ $prep_raw[$key]['user'] = $this->get_user_by( $user_field, $user_id );
747
+
748
+ $user_has_badge[] = $this->get_post_by( $post_field, $badge_id );
749
+ }
750
+ else
751
+ {
752
+ continue;
753
+ }
754
+ $prep_raw[$key]['badge'] = implode( ', ', $user_has_badge );
755
+ }
756
+ }
757
+ $this->generate_csv( $prep_raw );
758
+
759
+ die;
760
+ }
761
+
762
+ //Raw ranks
763
+ if( $type == 'ranks' && $template == 'raw' )
764
+ {
765
+ $user_ids = $this->get_all_user_ids();
766
+
767
+ $prep_raw = array();
768
+
769
+ foreach( $user_ids as $key => $user_id )
770
+ {
771
+ $user_has_rank = array();
772
+
773
+ foreach( $types as $rank_id )
774
+ {
775
+
776
+ $rank = new myCRED_Rank( $rank_id );
777
+
778
+ if( $rank->user_has_rank( $user_id ) )
779
+ {
780
+ $prep_raw[$key]['user'] = $this->get_user_by( $user_field, $user_id );
781
+
782
+ $user_has_rank[] = $this->get_post_by( $post_field, $rank_id );
783
+ }
784
+ else
785
+ {
786
+ continue;
787
+ }
788
+ $prep_raw[$key]['rank'] = implode( ', ', $user_has_rank );
789
+ }
790
+ }
791
+ $this->generate_csv( $prep_raw );
792
+
793
+ die;
794
+ }
795
+
796
+ //Export Setup
797
+ if( $type == 'setup' && $template == 'raw' )
798
+ {
799
+ $this->export_setup( $post_field );
800
+ }
801
+ }
802
+
803
+ public function import_csv( $file_path, $type, $import_format_type = '' )
804
+ {
805
+ $row = 1;
806
+
807
+ if( ( $handle = fopen( $file_path, 'r' ) ) !== false )
808
+ {
809
+ $rows_affected = 0;
810
+
811
+ while( ( $data = fgetcsv( $handle, 1000, ',' ) ) !== false )
812
+ {
813
+
814
+ $num = count( $data );
815
+
816
+ //Start adding
817
+ if( $type == 'points' )
818
+ {
819
+ //If header is not of points
820
+ if( $row == 1 )
821
+ {
822
+ $row++;
823
+ if(
824
+ preg_replace( '/[\x00-\x1F\x7F-\xFF]/', '', $data[0] ) != 'id'
825
+ ||
826
+ preg_replace( '/[\x00-\x1F\x7F-\xFF]/', '', $data[1] ) != 'ref'
827
+ ||
828
+ preg_replace( '/[\x00-\x1F\x7F-\xFF]/', '', $data[2] ) != 'ref_id'
829
+ ||
830
+ preg_replace( '/[\x00-\x1F\x7F-\xFF]/', '', $data[3] ) != 'user_id'
831
+ ||
832
+ preg_replace( '/[\x00-\x1F\x7F-\xFF]/', '', $data[4] ) != 'creds'
833
+ ||
834
+ preg_replace( '/[\x00-\x1F\x7F-\xFF]/', '', $data[5] ) != 'ctype'
835
+ ||
836
+ preg_replace( '/[\x00-\x1F\x7F-\xFF]/', '', $data[6] ) != 'time'
837
+ ||
838
+ preg_replace( '/[\x00-\x1F\x7F-\xFF]/', '', $data[7] ) != 'entry'
839
+ ||
840
+ preg_replace( '/[\x00-\x1F\x7F-\xFF]/', '', $data[8] ) != 'data'
841
+ )
842
+ {
843
+ wp_send_json( "{$rows_affected} rows affected.", 200 );
844
+ }
845
+
846
+ continue;
847
+ }
848
+
849
+
850
+ //Add Creds
851
+ $id = $data[0];
852
+ $ref = $data[1];
853
+ $ref_id = $data[2];
854
+ $user_id = '';
855
+
856
+ //Get User Id
857
+ $user_id = $this->get_user_id( $data[3] );
858
+
859
+ $creds = $data[4];
860
+ $ctype = $data[5];
861
+ $time = $data[6];
862
+ $entry = $data[7];
863
+ $data = $data[8];
864
+
865
+ $add_creds = mycred_add(
866
+ $ref,
867
+ $user_id,
868
+ $creds,
869
+ $entry,
870
+ $ref_id,
871
+ $data,
872
+ $ctype
873
+ );
874
+
875
+ if( $add_creds )
876
+ $rows_affected++;
877
+ }
878
+
879
+ //Start Assigning Badges
880
+ if( $type == 'badges' )
881
+ {
882
+ //If header is not of Badges type
883
+ if( $row == 1 )
884
+ {
885
+ $row++;
886
+ if( preg_replace( '/[\x00-\x1F\x7F-\xFF]/', '', $data[0] ) != 'user' || preg_replace( '/[\x00-\x1F\x7F-\xFF]/', '', $data[1] ) != 'badge' )
887
+ wp_send_json( "{$rows_affected} rows affected.", 200 );
888
+
889
+ continue;
890
+ }
891
+
892
+ $user_id = $this->get_user_id( $data[0] );
893
+
894
+ $badge_ids = explode( ', ', $data[1] );
895
+
896
+ foreach( $badge_ids as $badge )
897
+ {
898
+ $badge_id = $this->get_post_id_by( $import_format_type, $badge, MYCRED_BADGE_KEY );
899
+
900
+ $assigned_badge = mycred_assign_badge_to_user( $user_id, $badge_id );
901
+
902
+ if( $assigned_badge )
903
+ $rows_affected++;
904
+ }
905
+ }
906
+
907
+ //Start Assiging Ranks
908
+ if( $type == 'ranks' )
909
+ {
910
+ //If header is not of rank type
911
+ if( $row == 1 )
912
+ {
913
+ $row++;
914
+ if( preg_replace( '/[\x00-\x1F\x7F-\xFF]/', '', $data[0] ) != 'user' || preg_replace( '/[\x00-\x1F\x7F-\xFF]/', '', $data[1] ) != 'rank' )
915
+ wp_send_json( "{$rows_affected} rows affected.", 200 );
916
+
917
+ continue;
918
+ }
919
+
920
+ $user_id = $this->get_user_id( $data[0] );
921
+
922
+ $rank_ids = explode( ', ', $data[1] );
923
+
924
+ foreach( $rank_ids as $rank_id )
925
+ {
926
+ $rank_id = $this->get_post_id_by( $import_format_type, $rank_id, MYCRED_RANK_KEY );
927
+
928
+ $rank = new myCRED_Rank( $rank_id );
929
+
930
+ $assigned_rank = $rank->assign( $user_id );
931
+
932
+ if( $assigned_rank )
933
+ $rows_affected++;
934
+ }
935
+ }
936
+
937
+ }
938
+
939
+ fclose( $handle );
940
+
941
+ wp_send_json( "{$rows_affected} rows affected.", 200 );
942
+ }
943
+ }
944
+
945
+ public function import_export()
946
+ {
947
+ if( isset( $_POST['action'] ) && $_POST['action'] == 'mycred-tools-import-export' )
948
+ {
949
+ //Export Raw points
950
+ if( isset( $_POST['request_tab'] ) && $_POST['request_tab'] == 'points' && $_POST['request'] == 'export' )
951
+ {
952
+ $point_types = sanitize_text_field( $_POST['types'] );
953
+ $point_types = stripslashes( $point_types );
954
+ $point_types = json_decode( $point_types );
955
+
956
+ $point_types = mycred_sanitize_array( $point_types );
957
+
958
+ $user_field = sanitize_text_field( $_POST['user_field'] );
959
+
960
+ return $this->export_csv( 'points', sanitize_text_field( $_POST['template'] ), $user_field, $point_types );
961
+
962
+ die;
963
+ }
964
+
965
+ //Import Points
966
+ if( isset( $_POST['request_tab'] ) && $_POST['request_tab'] == 'points' && $_POST['request'] == 'import' && isset( $_FILES ) )
967
+ {
968
+ $file_path = sanitize_text_field( $_FILES['_file']['tmp_name'] );
969
+
970
+ $this->import_csv( $file_path, 'points' );
971
+ }
972
+
973
+ //Formatted points template
974
+ if( isset( $_POST['request_tab'] ) && $_POST['request_tab'] == 'points' && $_POST['template'] == 'formatted' )
975
+ {
976
+ return $this->downlaod_template_csv( 'points', 'formatted' );
977
+
978
+ die;
979
+ }
980
+
981
+ //Raw points template
982
+ if( isset( $_POST['request_tab'] ) && $_POST['request_tab'] == 'points' )
983
+ {
984
+ return $this->downlaod_template_csv( 'points', 'raw' );
985
+
986
+ die;
987
+ }
988
+
989
+ //Badges
990
+ //Export Raw Badges
991
+ if( isset( $_POST['request_tab'] ) && $_POST['request_tab'] == 'badges' && $_POST['request'] == 'export' )
992
+ {
993
+ $template = sanitize_text_field( $_POST['template'] );
994
+
995
+ $user_field = sanitize_text_field( $_POST['user_field'] );
996
+
997
+ $post_field = sanitize_text_field( $_POST['post_field'] );
998
+
999
+ $badges = stripslashes( $_POST['types'] );
1000
+
1001
+ $badges = json_decode( $badges );
1002
+
1003
+ $badges = mycred_sanitize_array( $badges );
1004
+
1005
+ return $this->export_csv( 'badges', $template, $user_field, $badges, $post_field);
1006
+
1007
+ die;
1008
+ }
1009
+
1010
+ //Import Badges
1011
+ if( isset( $_POST['request_tab'] ) && $_POST['request_tab'] == 'badges' && $_POST['request'] == 'import' && isset( $_FILES ) )
1012
+ {
1013
+ $file_path = sanitize_text_field( $_FILES['_file']['tmp_name'] );
1014
+
1015
+ $import_format_type = sanitize_text_field( $_POST['import_format_type'] );
1016
+
1017
+ $this->import_csv( $file_path, 'badges', $import_format_type );
1018
+ }
1019
+
1020
+ //Raw Badges template
1021
+ if( isset( $_POST['request_tab'] ) && $_POST['request_tab'] == 'badges' && $_POST['template'] == 'raw' )
1022
+ {
1023
+
1024
+ return $this->downlaod_template_csv( 'badges', 'raw' );
1025
+
1026
+ die;
1027
+ }
1028
+
1029
+ //Ranks
1030
+ //Import Ranks
1031
+ if( isset( $_POST['request_tab'] ) && $_POST['request_tab'] == 'ranks' && $_POST['request'] == 'import' && isset( $_FILES ) )
1032
+ {
1033
+ $file_path = sanitize_text_field( $_FILES['_file']['tmp_name'] );
1034
+
1035
+ $import_format_type = sanitize_text_field( $_POST['import_format_type'] );
1036
+
1037
+ $this->import_csv( $file_path, 'ranks', $import_format_type );
1038
+ }
1039
+
1040
+ //Export Raw Ranks
1041
+ if( isset( $_POST['request_tab'] ) && $_POST['request_tab'] == 'ranks' && $_POST['request'] == 'export' )
1042
+ {
1043
+ $template = sanitize_text_field( $_POST['template'] );
1044
+
1045
+ $user_field = sanitize_text_field( $_POST['user_field'] );
1046
+
1047
+ $post_field = sanitize_text_field( $_POST['post_field'] );
1048
+
1049
+ $ranks = stripslashes( $_POST['types'] );
1050
+
1051
+ $ranks = json_decode( $ranks );
1052
+
1053
+ $ranks = mycred_sanitize_array( $ranks );
1054
+
1055
+ return $this->export_csv( 'ranks', $template, $user_field, $ranks, $post_field );
1056
+
1057
+ die;
1058
+ }
1059
+
1060
+ //Raw Ranks Template
1061
+ if( isset( $_POST['request_tab'] ) && $_POST['request_tab'] == 'ranks' && $_POST['template'] == 'raw' )
1062
+ {
1063
+
1064
+ return $this->downlaod_template_csv( 'ranks', 'raw' );
1065
+
1066
+ die;
1067
+ }
1068
+
1069
+ //Setup
1070
+ //Export Setup
1071
+ if( isset( $_POST['request_tab'] ) && $_POST['request_tab'] == 'setup' && ( isset( $_POST['template'] ) && $_POST['template'] == 'raw' ) )
1072
+ {
1073
+ $setup_types = mycred_sanitize_array( $_POST['setup_types'] );
1074
+
1075
+ $template = sanitize_text_field( $_POST['template'] );
1076
+
1077
+ return $this->export_csv( 'setup', $template, '', '', $setup_types );
1078
+ }
1079
+
1080
+ //Setup
1081
+ //Import Setup
1082
+ if( isset( $_POST['request_tab'] ) && $_POST['request_tab'] == 'setup' && $_POST['request'] == 'import' )
1083
+ {
1084
+ $file_path = sanitize_text_field( $_FILES['_file']['tmp_name'] );
1085
+
1086
+ $this->import_setup_json( $file_path );
1087
+ }
1088
+ }
1089
+ }
1090
+
1091
+ public function get_user_id( $user )
1092
+ {
1093
+ if( filter_var( $user, FILTER_VALIDATE_EMAIL ) )
1094
+ return get_user_by( 'email', $user )->ID;
1095
+
1096
+ if( is_string( $user ) && !is_numeric( $user ) )
1097
+ return get_user_by( 'login', $user )->ID;
1098
+
1099
+ if( is_numeric( $user ) )
1100
+ return $user;
1101
+ }
1102
+
1103
+ public function get_user_by( $user_field, $user_id )
1104
+ {
1105
+ if( $user_field == 'id' )
1106
+ return $user_id = $user_id;
1107
+
1108
+ if( $user_field == 'user_name' )
1109
+ return $user_id = get_userdata( $user_id )->user_login;
1110
+
1111
+ if( $user_field == 'email' )
1112
+ return $user_id = get_userdata( $user_id )->user_email;
1113
+ }
1114
+
1115
+ public function get_all_user_ids()
1116
+ {
1117
+ $user_ids = array();
1118
+
1119
+ foreach( get_users() as $user )
1120
+ $user_ids[] = $user->ID;
1121
+
1122
+ return $user_ids;
1123
+ }
1124
+
1125
+ public function get_post_by( $post_field, $post_id )
1126
+ {
1127
+ if( $post_field == 'id' )
1128
+ return $post_id;
1129
+
1130
+ if( $post_field == 'title' )
1131
+ return get_the_title( $post_id );
1132
+
1133
+ if( $post_field == 'slug' )
1134
+ return get_post_field( 'post_name', $post_id );
1135
+ }
1136
+
1137
+ public function get_post_id_by( $import_format_type, $post_field, $post_type = '' )
1138
+ {
1139
+ if( $import_format_type == 'id' )
1140
+ return $post_field;
1141
+
1142
+ if( $import_format_type == 'slug' )
1143
+ {
1144
+ $args = array(
1145
+ 'name' => $post_field,
1146
+ 'post_status' => 'publish',
1147
+ 'numberposts' => 1,
1148
+ 'post_type' => $post_type
1149
+ );
1150
+
1151
+ return get_posts( $args )[0]->ID;
1152
+ }
1153
+
1154
+ if( $import_format_type == 'title' )
1155
+ {
1156
+ $post = get_page_by_title( $post_field, OBJECT, $post_type );
1157
+
1158
+ return $post->ID;
1159
+ }
1160
+ }
1161
+
1162
+ public function get_badge_categories()
1163
+ {
1164
+ $args = array(
1165
+ 'taxonomy' => MYCRED_BADGE_CATEGORY,
1166
+ 'orderby' => 'name',
1167
+ 'field' => 'name',
1168
+ 'order' => 'ASC',
1169
+ 'hide_empty' => false
1170
+ );
1171
+
1172
+ return get_categories( $args );
1173
+ }
1174
+
1175
+ public function get_uncat_badge_ids()
1176
+ {
1177
+ global $wpdb;
1178
+
1179
+ return $wpdb->get_results(
1180
+ "SELECT SQL_CALC_FOUND_ROWS wp_posts.ID FROM {$wpdb->posts} as wp_posts WHERE 1=1 AND (
1181
+ wp_posts.ID NOT IN (
1182
+ SELECT object_id
1183
+ FROM $wpdb->term_relationships
1184
+ )
1185
+ ) AND wp_posts.post_type = 'mycred_badge' AND (wp_posts.post_status = 'publish' OR wp_posts.post_status = 'future' OR wp_posts.post_status = 'draft' OR wp_posts.post_status = 'pending' OR wp_posts.post_status = 'private') GROUP BY wp_posts.ID ORDER BY wp_posts.post_date DESC LIMIT 0, 10",
1186
+ ARRAY_A
1187
+ );
1188
+ }
1189
+
1190
+ public function insert_attachment_from_url( $url, $parent_post_id = null )
1191
+ {
1192
+
1193
+ if( !class_exists( 'WP_Http' ) )
1194
+ include_once( ABSPATH . WPINC . '/class-http.php' );
1195
+
1196
+ $http = new WP_Http();
1197
+
1198
+ $response = $http->request( $url );
1199
+
1200
+ //If Image not Found/ Just return empty string
1201
+ if( property_exists( $response, 'errors' ) )
1202
+ return '';
1203
+
1204
+ if( $response['response']['code'] != 200 ) {
1205
+ return false;
1206
+ }
1207
+
1208
+ $upload = wp_upload_bits( basename($url), null, $response['body'] );
1209
+ if( !empty( $upload['error'] ) ) {
1210
+ return false;
1211
+ }
1212
+
1213
+ $file_path = $upload['file'];
1214
+ $file_name = basename( $file_path );
1215
+ $file_type = wp_check_filetype( $file_name, null );
1216
+ $attachment_title = sanitize_file_name( pathinfo( $file_name, PATHINFO_FILENAME ) );
1217
+ $wp_upload_dir = wp_upload_dir();
1218
+
1219
+ $post_info = array(
1220
+ 'guid' => $wp_upload_dir['url'] . '/' . $file_name,
1221
+ 'post_mime_type' => $file_type['type'],
1222
+ 'post_title' => $attachment_title,
1223
+ 'post_content' => '',
1224
+ 'post_status' => 'inherit',
1225
+ );
1226
+
1227
+ // Create the attachment
1228
+ $attach_id = wp_insert_attachment( $post_info, $file_path, $parent_post_id );
1229
+
1230
+ // Include image.php
1231
+ require_once( ABSPATH . 'wp-admin/includes/image.php' );
1232
+
1233
+ // Define attachment metadata
1234
+ $attach_data = wp_generate_attachment_metadata( $attach_id, $file_path );
1235
+
1236
+ // Assign metadata to attachment
1237
+ wp_update_attachment_metadata( $attach_id, $attach_data );
1238
+
1239
+ return $attach_id;
1240
+
1241
+ }
1242
+ }
1243
+ endif;
1244
+
1245
+
1246
+ $mycred_tools_import_export = new myCRED_Tools_Import_Export();
includes/mycred-tools-setup-import-export.php ADDED
@@ -0,0 +1,629 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ if( !class_exists( 'myCRED_Setup_Import_Export' ) ):
3
+ class myCRED_Setup_Import_Export
4
+ {
5
+ public $mycred_tools_import_export;
6
+
7
+ public function __construct()
8
+ {
9
+
10
+ }
11
+
12
+ public function get_setup_page()
13
+ {
14
+ $this->mycred_tools_import_export = new myCRED_Tools_Import_Export();
15
+ ?>
16
+ <input type="hidden" class="request-tab" value="<?php if( isset( $_GET['mycred-tools'] ) ) echo $_GET['mycred-tools'] ?>" />
17
+ <form action="" enctype="multipart/form-data" class="mycred-tools-setup">
18
+ <h3><?php _e( 'Setup', 'mycred' ); ?></h3>
19
+ <?php
20
+ if( !empty( $this->mycred_tools_import_export->core_point_types ) )
21
+ {
22
+ ?>
23
+
24
+ <div>
25
+ <div>
26
+ <label class='mycred-switch1'>
27
+ <input type='checkbox' value='all-points' name='all_points' id='all-points'>
28
+ <span class='slider round'></span>
29
+ </label>
30
+ <label for="all-points"><b>All Point Types</b></label>
31
+ </div>
32
+
33
+ <?php
34
+ foreach( $this->mycred_tools_import_export->core_point_types as $key => $value )
35
+ {
36
+ echo "
37
+ <ol>
38
+ <li>
39
+ <label class='mycred-switch1'>
40
+ <input type='checkbox' value='{$key}' name='point_type' id='{$key}-point'>
41
+ <span class='slider round'></span>
42
+ </label>
43
+ <label for='{$key}-point'><b>{$value}</b></labal>
44
+ </li>
45
+ <ol>
46
+ <li>
47
+ <label class='mycred-switch1'>
48
+ <input type='checkbox' value='{$key}' name='hooks' id='{$key}-hooks'>
49
+ <span class='slider round'></span>
50
+ </label>
51
+ <label for='{$key}-hooks'>Hooks</labal>
52
+ </li>
53
+ <li>
54
+ <label class='mycred-switch1'>
55
+ <input type='checkbox' value='{$key}' name='ranks' id='{$key}-ranks'>
56
+ <span class='slider round'></span>
57
+ </label>
58
+ <label for='{$key}-ranks'>Ranks</labal>
59
+ </li>
60
+ </ol>
61
+ </ol>
62
+ ";
63
+ }
64
+ }
65
+ ?>
66
+ </div>
67
+ <ul>
68
+ <?php
69
+
70
+ if( !empty( $this->mycred_tools_import_export->get_badge_categories() ) )
71
+ {
72
+ echo "
73
+ <li>
74
+ <label class='mycred-switch1'>
75
+ <input type='checkbox' value='all-achievements' name='all_achievements' id='all-achievements'>
76
+ <span class='slider round'></span>
77
+ </label>
78
+ <label for='all-achievements'><b>All Achievement Types</b></label>
79
+ </li>
80
+ ";
81
+ echo "<ol>";
82
+ foreach( $this->mycred_tools_import_export->get_badge_categories() as $category )
83
+ {
84
+ echo
85
+ "<li>
86
+ <label class='mycred-switch1'>
87
+ <input type='checkbox' value='{$category->cat_ID}' name='achievements' id='cate-{$category->cat_ID}'>
88
+ <span class='slider round'></span>
89
+ </label>
90
+ <label for='cate-{$category->cat_ID}'><b>{$category->name}</b></label>
91
+ </li>";
92
+
93
+ $badges = mycred_get_badges_by_term_id( $category->cat_ID );
94
+
95
+ foreach( $badges as $badge )
96
+ {
97
+ echo
98
+ "<ol>
99
+ <li>
100
+ <label class='mycred-switch1'>
101
+ <input type='checkbox' value='{$badge->ID}' name='badge_{$category->cat_ID}' id='badge-{$badge->ID}-{$category->cat_ID}'>
102
+ <span class='slider round'></span>
103
+ </label>
104
+ <label for='badge-{$badge->ID}-{$category->cat_ID}'><b>{$badge->post_title}</b></label>
105
+ </li>
106
+ <li>
107
+ <label class='mycred-switch1'>
108
+ <input type='checkbox' value='{$badge->ID}' name='levels_{$category->cat_ID}' id='level-{$badge->ID}-{$category->cat_ID}'>
109
+ <span class='slider round'></span>
110
+ </label>
111
+ <label for='level-{$badge->ID}-{$category->cat_ID}'>Levels</label>
112
+ </li>
113
+ </ol>";
114
+ }
115
+ }
116
+ echo "</ol>";
117
+ }
118
+
119
+ ?>
120
+ </ul>
121
+ <ul>
122
+
123
+ <?php
124
+
125
+ $un_cat_badges = $this->mycred_tools_import_export->get_uncat_badge_ids();
126
+
127
+ if( !empty( $un_cat_badges ) )
128
+ {
129
+ echo "
130
+ <li>
131
+ <label class='mycred-switch1'>
132
+ <input type='checkbox' value='uncat-achievements' name='uncat_achievements' id='uncat-achievements'>
133
+ <span class='slider round'></span>
134
+ </label>
135
+ <label for='uncat-achievements'><b>Uncategorized Achievements</b></label>
136
+ </li>
137
+ ";
138
+ foreach( $un_cat_badges as $data )
139
+ {
140
+ $id = $data['ID'];
141
+ $title = get_the_title( $id );
142
+ echo
143
+ "<ol>
144
+ <li>
145
+ <label class='mycred-switch1'>
146
+ <input type='checkbox' value='{$id}' name='badge' id='uncat-badge-{$id}'>
147
+ <span class='slider round'></span>
148
+ </label>
149
+ <label for='uncat-badge-{$id}'><b>{$title}</b></label>
150
+ </li>
151
+ <li>
152
+ <label class='mycred-switch1'>
153
+ <input type='checkbox' value='{$id}' name='levels' id='uncat-level-{$id}'>
154
+ <span class='slider round'></span>
155
+ </label>
156
+ <label for='uncat-level-{$id}'>Levels</label>
157
+ </li>
158
+ </ol>";
159
+ }
160
+ }
161
+
162
+
163
+ ?>
164
+ </ul>
165
+
166
+ <button class="button button-primary" id="export-raw">
167
+ <span class="dashicons dashicons-database-export v-align-middle"></span> <?php _e( 'Export Setup', 'mycred' ); ?>
168
+ </button>
169
+ </form>
170
+
171
+ <form action="" enctype="multipart/form-data" class="mycred-tools-setup-import">
172
+ <h3><?php _e( 'Import', 'mycred' ); ?></h3>
173
+ <input type="file" id="import-file" name="file" accept=".json" />
174
+ <button class="button button-primary", id="import">
175
+ <span class="dashicons dashicons-database-import v-align-middle"></span> <?php _e( 'Import Setup','mycred' ); ?>
176
+ </button>
177
+ <p><i>
178
+ <?php _e( 'Accepts JSON format.', 'mycred' ); ?>
179
+ </i></p>
180
+ </form>
181
+ <div style="clear: both;"></div>
182
+ <?php
183
+
184
+ }
185
+
186
+ public function export_setup( $post_field )
187
+ {
188
+ $this->mycred_tools_import_export = new myCRED_Tools_Import_Export();
189
+
190
+ $prepare_data = array();
191
+
192
+ $achievement = '';
193
+
194
+ //Making Data Compatible
195
+ foreach( $post_field as $key => $type )
196
+ {
197
+ if( isset( $type['point_type'] ) )
198
+ {
199
+ $prepare_data['point_types'][$type['point_type']] = array();
200
+ $prepare_data['point_types'][$type['point_type']][] = 'pref_core';
201
+ }
202
+
203
+ if( isset( $type['hooks'] ) )
204
+ {
205
+ $prepare_data['point_types'][$type['hooks']][] = 'hooks';
206
+ }
207
+
208
+ if( isset( $type['ranks'] ) )
209
+ {
210
+ $prepare_data['point_types'][$type['ranks']][] = 'ranks';
211
+ }
212
+
213
+ //Making Achievements' key
214
+ if( isset( $type['achievements'] ) )
215
+ {
216
+ $prepare_data['achievements']["achievement_{$type["achievements"]}"] = array( 'achievement' => $type['achievements'] );
217
+ $achievement = $type['achievements'];
218
+ }
219
+
220
+ //Storing Badges into achievements key
221
+ if( array_key_exists( "badge_{$achievement}", $type ) )
222
+ {
223
+ $prepare_data['achievements']["achievement_{$achievement}"]["badge_{$type["badge_{$achievement}"]}"] = $type["badge_{$achievement}"];
224
+ }
225
+
226
+ //Storing levels into achievements key
227
+ if( array_key_exists( "levels_{$achievement}", $type ) )
228
+ {
229
+ $prepare_data['achievements']["achievement_{$achievement}"]["levels_{$type["levels_{$achievement}"]}"] = $type["levels_{$achievement}"];
230
+ }
231
+
232
+ //Storing badges with no Achievement/ Category
233
+ if( isset( $type['badge'] ) )
234
+ {
235
+ $prepare_data['badges'][$type['badge']][] = 'badge';
236
+ }
237
+
238
+ //Storing Levles with no Achievement/ Category
239
+ if( isset( $type['levels'] ) )
240
+ {
241
+ $prepare_data['badges'][$type['levels']][] = 'levels';
242
+ }
243
+ }
244
+
245
+ //Preparing CSV
246
+ $prep_raw = array();
247
+ $counter = 0;
248
+
249
+ foreach( $prepare_data as $key => $type )
250
+ {
251
+ //Point types
252
+ if( $key == 'point_types' )
253
+ {
254
+ foreach( $type as $pt => $value )
255
+ {
256
+ $prep_raw[$counter]['point_type_key'] = $pt;
257
+
258
+ $prep_raw[$counter]['point_type_name'] = mycred_get_point_type_name( $pt );
259
+
260
+ $pref_hooks = MYCRED_DEFAULT_TYPE_KEY == $pt ? 'mycred_pref_core' : "mycred_pref_core_{$pt}";
261
+
262
+ $prep_raw[$counter]['pref_core'] = serialize( mycred_get_option( $pref_hooks ) );
263
+
264
+
265
+ if( in_array( 'hooks', $value ) )
266
+ {
267
+ $pref_hooks = MYCRED_DEFAULT_TYPE_KEY == $pt ? 'mycred_pref_hooks' : "mycred_pref_hooks_{$pt}";
268
+
269
+ $prep_raw[$counter]['hooks'] = serialize( mycred_get_option( $pref_hooks ) );
270
+ }
271
+
272
+ if( in_array( 'ranks', $value ) )
273
+ {
274
+ $prep_raw[$counter]['ranks'] = serialize( mycred_get_ranks( 'publish', '-1', 'DESC', $pt ) );
275
+ }
276
+
277
+ $counter++;
278
+ }
279
+ }
280
+
281
+ if( $key == 'achievements' )
282
+ {
283
+ foreach( $type as $achievement => $value )
284
+ {
285
+ foreach( $value as $badge_level => $bl_value )
286
+ {
287
+ if( $badge_level == 'achievement' )
288
+ {
289
+ $prep_raw['achievements']["achievement_{$bl_value}"] = get_the_category_by_ID( $bl_value );
290
+ }
291
+
292
+ if( strpos( $badge_level, 'badge' ) !== false )
293
+ {
294
+ $prep_raw['achievements'][$bl_value]['badge'] = serialize( get_post( $bl_value ) );
295
+
296
+ if( wp_get_attachment_url( mycred_get_post_meta( $bl_value, 'main_image', true ) ) )
297
+ $prep_raw['achievements'][$bl_value]['thumbnail'] = wp_get_attachment_url( mycred_get_post_meta( $bl_value, 'main_image', true ) );
298
+
299
+ $metas = array();
300
+
301
+ $metas['manual_badge'] = mycred_get_post_meta( $bl_value, 'manual_badge' );
302
+ $metas['open_badge'] = mycred_get_post_meta( $bl_value, 'open_badge' );
303
+ $metas['congratulation_msg'] = mycred_get_post_meta( $bl_value, 'congratulation_msg' );
304
+ $metas['mycred_badge_align'] = mycred_get_post_meta( $bl_value, 'mycred_badge_align' );
305
+ $metas['mycred_layout_check'] = mycred_get_post_meta( $bl_value, 'mycred_layout_check' );
306
+
307
+ $prep_raw['achievements'][$bl_value]['levels_meta']['metas'] = serialize( $metas );
308
+
309
+ }
310
+
311
+ if( strpos( $badge_level, 'levels' ) !== false )
312
+ {
313
+ $badge_prefs = unserialize( mycred_get_post_meta( $bl_value, '' )['badge_prefs'][0] );
314
+
315
+ //Changing Attachment ID with image URL
316
+ foreach( $badge_prefs as $key => $value )
317
+ {
318
+ if( isset( $value['attachment_id'] ) )
319
+ {
320
+ $badge_prefs[$key]['attachment_id'] = wp_get_attachment_url( $value['attachment_id'] );
321
+ }
322
+ }
323
+
324
+ $levels_meta = mycred_get_post_meta( $bl_value, '' );
325
+
326
+ $levels_meta['badge_prefs'][0] = serialize( $badge_prefs );
327
+
328
+ $prep_raw['achievements'][$bl_value]['levels_meta']['levels'] = serialize( $levels_meta );
329
+
330
+ }
331
+ }
332
+ }
333
+ }
334
+
335
+ if( $key == 'badges' )
336
+ {
337
+ foreach( $type as $badge_level => $bl_value )
338
+ {
339
+ if( in_array( 'badge', $bl_value ) )
340
+ {
341
+ $prep_raw['badges'][$badge_level]['badge'] = serialize( get_post( $badge_level, '' ) );
342
+
343
+ if( wp_get_attachment_url( mycred_get_post_meta( $badge_level, 'main_image', true ) ) )
344
+ $prep_raw['badges'][$badge_level]['thumbnail'] = wp_get_attachment_url( mycred_get_post_meta( $badge_level, 'main_image', true ) );
345
+
346
+ $metas = array();
347
+
348
+ $metas['manual_badge'] = mycred_get_post_meta( $bl_value, 'manual_badge' );
349
+ $metas['open_badge'] = mycred_get_post_meta( $bl_value, 'open_badge' );
350
+ $metas['congratulation_msg'] = mycred_get_post_meta( $bl_value, 'congratulation_msg' );
351
+ $metas['mycred_badge_align'] = mycred_get_post_meta( $bl_value, 'mycred_badge_align' );
352
+ $metas['mycred_layout_check'] = mycred_get_post_meta( $bl_value, 'mycred_layout_check' );
353
+
354
+ $prep_raw['badges'][$badge_level]['levels_meta']['metas'] = serialize( $metas );
355
+ }
356
+
357
+ if( in_array( 'levels', $bl_value ) )
358
+ {
359
+ if( array_key_exists( 'badge_prefs' , mycred_get_post_meta( $badge_level, '' ) ) )
360
+ {
361
+ $badge_prefs = unserialize( mycred_get_post_meta( $badge_level, '' )['badge_prefs'][0] );
362
+
363
+ //Changing Attachment ID with image URL
364
+ foreach( $badge_prefs as $key => $value )
365
+ {
366
+ if( isset( $value['attachment_id'] ) )
367
+ {
368
+ $badge_prefs[$key]['attachment_id'] = wp_get_attachment_url( $value['attachment_id'] );
369
+ }
370
+ }
371
+
372
+ $prep_raw['badges'][$badge_level]['levels_meta']['levels'] = serialize( $badge_prefs );
373
+ }
374
+ }
375
+ }
376
+ }
377
+ }
378
+
379
+ echo json_encode( $prep_raw );
380
+
381
+ die;
382
+ }
383
+
384
+ public function import_setup_json( $file_path = '' )
385
+ {
386
+ $this->mycred_tools_import_export = new myCRED_Tools_Import_Export();
387
+
388
+ $json_string = file_get_contents( $file_path );
389
+
390
+ $data = json_decode( preg_replace( '/[\x00-\x1F\x80-\xFF]/', '', $json_string ), true );
391
+
392
+ foreach( $data as $data_key => $data_value )
393
+ {
394
+ //Import Points/ Hooks/ Ranks
395
+ if( is_int( $data_key ) )
396
+ {
397
+ $pt_key = $data_value['point_type_key'];
398
+
399
+ if( isset( $data_value['point_type_key'] ) )
400
+ {
401
+
402
+ $core_pref = $data_value['pref_core'];
403
+
404
+ $option = MYCRED_DEFAULT_TYPE_KEY == $pt_key ? 'mycred_pref_core' : "mycred_pref_core_{$pt_key}";
405
+
406
+ mycred_update_option( $option, unserialize( $core_pref ) );
407
+
408
+ $existing_pts = mycred_get_option( 'mycred_types' );
409
+
410
+ $existing_pts[$data_value['point_type_key']] = $data_value['point_type_name'];
411
+
412
+ mycred_update_option( 'mycred_types', $existing_pts );
413
+
414
+ }
415
+
416
+ //Import Hooks
417
+ if( isset( $data_value['hooks'] ) )
418
+ {
419
+ $hooks = $data_value['hooks'];
420
+
421
+ $option_name = $pt_key == MYCRED_DEFAULT_TYPE_KEY ? 'mycred_pref_hooks' : "mycred_pref_hooks_{$pt_key}";
422
+
423
+ mycred_update_option( $option_name, unserialize( $hooks ) );
424
+ }
425
+
426
+ //Import Ranks
427
+ if( isset( $data_value['ranks'] ) )
428
+ {
429
+ $ranks = unserialize( $data_value['ranks'] );
430
+
431
+ foreach( $ranks as $rank_key => $rank )
432
+ {
433
+ $min = $rank->minimum;
434
+
435
+ $max = $rank->maximum;
436
+
437
+ $ctype = $rank->point_type->cred_id;
438
+
439
+ $logo_url = '';
440
+
441
+ $attachment_id = '';
442
+
443
+ $args = array(
444
+ 'post_author' => get_current_user_id(),
445
+ 'post_date' => $rank->post->post_date,
446
+ 'post_date_gmt' => $rank->post->post_date_gmt,
447
+ 'post_content' => $rank->post->post_content,
448
+ 'post_title' => $rank->post->post_title,
449
+ 'post_status' => $rank->post->post_status,
450
+ 'post_name' => $rank->post->post_name,
451
+ 'post_modified' => $rank->post->post_modified,
452
+ 'post_modified_gmt' => $rank->post->post_modified_gmt,
453
+ 'post_type' => $rank->post->post_type
454
+ );
455
+
456
+ $post_id = wp_insert_post( $args );
457
+
458
+ if( $rank->logo_url != null )
459
+ {
460
+ $logo_url = $rank->logo_url;
461
+
462
+ $attachment_id = $this->mycred_tools_import_export->insert_attachment_from_url( $logo_url );
463
+ }
464
+
465
+ mycred_update_post_meta( $post_id, 'mycred_rank_min', $min );
466
+ mycred_update_post_meta( $post_id, 'mycred_rank_max', $max );
467
+ mycred_update_post_meta( $post_id, 'ctype', $ctype );
468
+ mycred_update_post_meta( $post_id, '_thumbnail_id', $attachment_id );
469
+ }
470
+ }
471
+ }
472
+
473
+ //Achievement
474
+ if( $data_key == 'achievements' )
475
+ {
476
+
477
+ $cat_id = '';
478
+ $post_id = '';
479
+
480
+ foreach( $data_value as $achievement_key => $achievement_value )
481
+ {
482
+ if( strpos( $achievement_key, 'achievement' ) !== false )
483
+ {
484
+ $catarr = array(
485
+ 'taxonomy' => MYCRED_BADGE_CATEGORY,
486
+ 'cat_name' => $achievement_value
487
+ );
488
+
489
+ $cat_id = wp_insert_category( $catarr );
490
+ }
491
+
492
+ if( is_int( $achievement_key ) )
493
+ {
494
+ //Badge
495
+ if( isset( $achievement_value['badge'] ) )
496
+ {
497
+
498
+ $attachment_id = '';
499
+
500
+ $badge = unserialize( $achievement_value['badge'] );
501
+
502
+ $args = array(
503
+ 'post_author' => get_current_user_id(),
504
+ 'post_date' => $badge->post_date,
505
+ 'post_date_gmt' => $badge->post_date_gmt,
506
+ 'post_content' => $badge->post_content,
507
+ 'post_title' => $badge->post_title,
508
+ 'post_status' => $badge->post_status,
509
+ 'post_name' => $badge->post_name,
510
+ 'post_modified' => $badge->post_modified,
511
+ 'post_modified_gmt' => $badge->post_modified_gmt,
512
+ 'post_type' => $badge->post_type
513
+ );
514
+
515
+ $post_id = wp_insert_post( $args );
516
+
517
+ wp_set_object_terms( $post_id, $cat_id, MYCRED_BADGE_CATEGORY );
518
+
519
+ if( isset( $achievement_value['thumbnail'] ) )
520
+ {
521
+ $attachment_id = $this->mycred_tools_import_export->insert_attachment_from_url( $achievement_value['thumbnail'] );
522
+
523
+ mycred_update_post_meta( $post_id, 'main_image', $attachment_id );
524
+
525
+ }
526
+ }
527
+
528
+ //Level
529
+ if( isset( $achievement_value['levels_meta'] ) )
530
+ {
531
+ $level_metas = $achievement_value['levels_meta'];
532
+ $metas = unserialize( $level_metas['metas'] );
533
+
534
+ if( isset( $achievement_value['levels_meta']['levels'] ) )
535
+ {
536
+ $levels = unserialize( $achievement_value['levels_meta']['levels'] );
537
+ $levels = unserialize( $levels['badge_prefs'][0] );
538
+
539
+ foreach( $levels as $key => $l_value )
540
+ {
541
+ if( isset( $l_value['attachment_id'] ) )
542
+ $levels[$key]['attachment_id'] = $this->mycred_tools_import_export->insert_attachment_from_url( $l_value['attachment_id'] );
543
+
544
+ }
545
+
546
+ mycred_update_post_meta( $post_id, 'badge_prefs', $levels );
547
+ }
548
+
549
+ mycred_update_post_meta( $post_id, 'manual_badge', $metas['manual_badge'][0] );
550
+ mycred_update_post_meta( $post_id, 'open_badge', $metas['open_badge'][0] );
551
+ mycred_update_post_meta( $post_id, 'congratulation_msg', $metas['congratulation_msg'][0] );
552
+ mycred_update_post_meta( $post_id, 'mycred_badge_align', $metas['mycred_badge_align'][0] );
553
+ mycred_update_post_meta( $post_id, 'mycred_layout_check', $metas['mycred_layout_check'][0] );
554
+ }
555
+ }
556
+ }
557
+ }
558
+ //Badges
559
+ if( $data_key == 'badges' )
560
+ {
561
+ $post_id = '';
562
+
563
+ foreach( $data_value as $badge_key => $badge_value )
564
+ {
565
+ //Badge
566
+ if( isset( $badge_value['badge'] ) )
567
+ {
568
+ $post_id = '';
569
+
570
+ $badge = unserialize( $badge_value['badge'] );
571
+
572
+ $args = array(
573
+ 'post_author' => get_current_user_id(),
574
+ 'post_date' => $badge->post_date,
575
+ 'post_date_gmt' => $badge->post_date_gmt,
576
+ 'post_content' => $badge->post_content,
577
+ 'post_title' => $badge->post_title,
578
+ 'post_status' => $badge->post_status,
579
+ 'post_name' => $badge->post_name,
580
+ 'post_modified' => $badge->post_modified,
581
+ 'post_modified_gmt' => $badge->post_modified_gmt,
582
+ 'post_type' => $badge->post_type,
583
+ );
584
+
585
+ $post_id = wp_insert_post( $args );
586
+
587
+ if( isset( $badge_value['thumbnail'] ) )
588
+ {
589
+ $attachment_id = $this->mycred_tools_import_export->insert_attachment_from_url( $badge_value['thumbnail'] );
590
+
591
+ mycred_update_post_meta( $post_id, 'main_image', $attachment_id );
592
+
593
+ }
594
+ }
595
+
596
+ //Level
597
+ if( isset( $badge_value['levels_meta'] ) )
598
+ {
599
+ $level_metas = $badge_value['levels_meta'];
600
+ $metas = unserialize( $level_metas['metas'] );
601
+
602
+
603
+ if( isset( $level_metas['levels'] ) )
604
+ {
605
+ $levels = unserialize( $badge_value['levels_meta']['levels'] );
606
+
607
+ foreach( $levels as $key => $l_value )
608
+ {
609
+ if( isset( $l_value['attachment_id'] ) )
610
+ $levels[$key]['attachment_id'] = $this->mycred_tools_import_export->insert_attachment_from_url( $l_value['attachment_id'] );
611
+
612
+ }
613
+ mycred_update_post_meta( $post_id, 'badge_prefs', $levels );
614
+ }
615
+
616
+ mycred_update_post_meta( $post_id, 'manual_badge', $metas['manual_badge'] );
617
+ mycred_update_post_meta( $post_id, 'open_badge', $metas['open_badge'] );
618
+ mycred_update_post_meta( $post_id, 'congratulation_msg', $metas['congratulation_msg'] );
619
+ mycred_update_post_meta( $post_id, 'mycred_badge_align', $metas['mycred_badge_align'] );
620
+ mycred_update_post_meta( $post_id, 'mycred_layout_check', $metas['mycred_layout_check'] );
621
+
622
+ }
623
+ }
624
+ }
625
+ }
626
+ die;
627
+ }
628
+ }
629
+ endif;
includes/mycred-tools.php CHANGED
@@ -22,6 +22,8 @@ class myCRED_Tools {
22
 
23
  public function admin_enqueue_scripts()
24
  {
 
 
25
  wp_enqueue_script( MYCRED_SLUG . '-select2-script' );
26
 
27
  wp_enqueue_style( MYCRED_SLUG . '-select2-style' );
@@ -34,6 +36,7 @@ class myCRED_Tools {
34
  MYCRED_SLUG . '-tools-script',
35
  'mycredTools',
36
  array(
 
37
  'awardConfirmText' => __( 'Do you really want to bulk award?', 'mycred' ),
38
  'revokeConfirmText' => __( 'Do you really want to bulk deduct?', 'mycred' ),
39
  'successfullyAwarded' => __( 'Successfully Awarded.', 'mycred' ),
@@ -64,13 +67,22 @@ class myCRED_Tools {
64
 
65
  /**
66
  * Tools menu callback
 
 
 
67
  */
68
  public function tools_page() {
69
 
70
- $import_export = get_mycred_tools_page_url('import-export');
71
  $logs_cleanup = get_mycred_tools_page_url('logs-cleanup');
72
  $reset_data = get_mycred_tools_page_url('reset-data');
73
-
 
 
 
 
 
 
74
  ?>
75
 
76
  <div class="" id="myCRED-wrap">
@@ -81,8 +93,8 @@ class myCRED_Tools {
81
  <div class="mycred-tools-main-nav">
82
  <h2 class="nav-tab-wrapper">
83
  <a href="<?php echo admin_url('admin.php?page=mycred-tools') ?>" class="nav-tab <?php echo !isset( $_GET['mycred-tools'] ) ? 'nav-tab-active' : ''; ?>">Bulk Assign</a>
84
- <!-- <a href="<?php //echo $import_export ?>" class="nav-tab <?php //echo ( isset( $_GET['mycred-tools'] ) && $_GET['mycred-tools'] == 'import-export' ) ? 'nav-tab-active' : ''; ?>">Import/Export</a>
85
- <a href="<?php //echo $logs_cleanup ?>" class="nav-tab <?php //echo ( isset( $_GET['mycred-tools'] ) && $_GET['mycred-tools'] == 'logs-cleanup' ) ? 'nav-tab-active' : ''; ?>">Logs Cleanup</a>
86
  <a href="<?php //echo $reset_data ?>" class="nav-tab <?php //echo ( isset( $_GET['mycred-tools'] ) && $_GET['mycred-tools'] == 'reset-data' ) ? 'nav-tab-active' : ''; ?>">Reset Data</a> -->
87
  </h2>
88
  </div>
@@ -90,9 +102,12 @@ class myCRED_Tools {
90
  <?php
91
 
92
  if ( isset( $_GET['mycred-tools'] ) ) {
93
- if ( $_GET['mycred-tools'] == 'import-export' ) { ?>
94
- <h1>IMPORT/EXPORT</h1>
95
- <?php
 
 
 
96
  }
97
  }
98
 
22
 
23
  public function admin_enqueue_scripts()
24
  {
25
+ wp_enqueue_style( MYCRED_SLUG . '-admin' );
26
+
27
  wp_enqueue_script( MYCRED_SLUG . '-select2-script' );
28
 
29
  wp_enqueue_style( MYCRED_SLUG . '-select2-style' );
36
  MYCRED_SLUG . '-tools-script',
37
  'mycredTools',
38
  array(
39
+ 'ajax_url' => admin_url( 'admin-ajax.php' ),
40
  'awardConfirmText' => __( 'Do you really want to bulk award?', 'mycred' ),
41
  'revokeConfirmText' => __( 'Do you really want to bulk deduct?', 'mycred' ),
42
  'successfullyAwarded' => __( 'Successfully Awarded.', 'mycred' ),
67
 
68
  /**
69
  * Tools menu callback
70
+ * @since 2.3
71
+ * @since 2.4 Import Export Module Added
72
+ * @version 1.1
73
  */
74
  public function tools_page() {
75
 
76
+ $import_export = get_mycred_tools_page_url('points');
77
  $logs_cleanup = get_mycred_tools_page_url('logs-cleanup');
78
  $reset_data = get_mycred_tools_page_url('reset-data');
79
+ $pages = array(
80
+ 'import-export',
81
+ 'points',
82
+ 'badges',
83
+ 'ranks',
84
+ 'setup'
85
+ );
86
  ?>
87
 
88
  <div class="" id="myCRED-wrap">
93
  <div class="mycred-tools-main-nav">
94
  <h2 class="nav-tab-wrapper">
95
  <a href="<?php echo admin_url('admin.php?page=mycred-tools') ?>" class="nav-tab <?php echo !isset( $_GET['mycred-tools'] ) ? 'nav-tab-active' : ''; ?>">Bulk Assign</a>
96
+ <a href="<?php echo $import_export ?>" class="nav-tab <?php echo ( isset( $_GET['mycred-tools'] ) && in_array( $_GET['mycred-tools'], $pages ) ) ? 'nav-tab-active' : ''; ?>">Import/Export</a>
97
+ <!-- <a href="<?php //echo $logs_cleanup ?>" class="nav-tab <?php //echo ( isset( $_GET['mycred-tools'] ) && $_GET['mycred-tools'] == 'logs-cleanup' ) ? 'nav-tab-active' : ''; ?>">Logs Cleanup</a>
98
  <a href="<?php //echo $reset_data ?>" class="nav-tab <?php //echo ( isset( $_GET['mycred-tools'] ) && $_GET['mycred-tools'] == 'reset-data' ) ? 'nav-tab-active' : ''; ?>">Reset Data</a> -->
99
  </h2>
100
  </div>
102
  <?php
103
 
104
  if ( isset( $_GET['mycred-tools'] ) ) {
105
+
106
+ if ( in_array( $_GET['mycred-tools'], $pages ) )
107
+ {
108
+ $mycred_tools_import_export = new myCRED_Tools_Import_Export();
109
+
110
+ $mycred_tools_import_export->get_header();
111
  }
112
  }
113
 
includes/shortcodes/mycred_referal_stats.php DELETED
@@ -1,51 +0,0 @@
1
- <?php
2
- if ( ! defined( 'myCRED_VERSION' ) ) exit;
3
-
4
- /**
5
- * myCRED Shortcode: mycred_referal_stats
6
- * Returns the referal stats.
7
- * @see http://codex.mycred.me/shortcodes/mycred_referal_stats/
8
- * @since 2.1.1
9
- * @version 1.0
10
- */
11
-
12
- if ( ! function_exists( 'mycred_referal_front' ) ) :
13
- function mycred_referal_front( $atts ){
14
-
15
- extract( shortcode_atts( array(
16
-
17
- 'ctype' => MYCRED_DEFAULT_TYPE_KEY
18
-
19
- ), $atts, MYCRED_SLUG . '_referal' ) );
20
-
21
- $hooks = mycred_get_option( 'mycred_pref_hooks', false );
22
-
23
- if ( $ctype != MYCRED_DEFAULT_TYPE_KEY )
24
- $hooks = mycred_get_option( 'mycred_pref_hooks_' . sanitize_key( $ctype ), false );
25
- $active = $hooks['active'];
26
- if( is_array( $active) && in_array( 'affiliate' , $active )){
27
-
28
- $visit = $hooks['hook_prefs']['affiliate']['visit'];
29
- $signup = $hooks['hook_prefs']['affiliate']['signup'];
30
-
31
- $output = '';
32
-
33
- $user_id = get_current_user_id();
34
-
35
- $output .= '<table class="profile-fields">';
36
-
37
- // Show Visitor referral count
38
- if ( $visit['creds'] != 0 )
39
- $output .= sprintf( '<tr class="field_2 field_ref_count_visit"><td class="label">%s</td><td>%s</td></tr>', __( 'Visitors Referred', 'mycred' ), mycred_count_ref_instances( 'visitor_referral', $user_id, $ctype ) );
40
-
41
- // Show Signup referral count
42
- if ( $signup['creds'] != 0 )
43
- $output .= sprintf( '<tr class="field_3 field_ref_count_signup"><td class="label">%s</td><td>%s</td></tr>', __( 'Signups Referred', 'mycred' ), mycred_count_ref_instances( 'signup_referral', $user_id, $ctype ) );
44
-
45
- $output .= '</table>';
46
- return $output;
47
- }
48
- }
49
- endif;
50
-
51
- add_shortcode( MYCRED_SLUG . '_referral_stats' , 'mycred_referal_front' );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
includes/shortcodes/mycred_video.php CHANGED
@@ -7,6 +7,7 @@ if ( ! defined( 'myCRED_VERSION' ) ) exit;
7
  * for watchinga YouTube video.
8
  * @see http://codex.mycred.me/shortcodes/mycred_video/
9
  * @since 1.2
 
10
  * @version 1.2.2
11
  */
12
  if ( ! function_exists( 'mycred_render_shortcode_video' ) ) :
@@ -45,7 +46,7 @@ if ( ! function_exists( 'mycred_render_shortcode_video' ) ) :
45
  if ( $id === NULL || empty( $id ) ) return __( 'A video ID is required for this shortcode', 'mycred' );
46
 
47
  // Interval
48
- if ( strlen( $interval ) < 3 ) {
49
  $interval = (float) $interval;
50
  $interval = abs( $interval * 1000 );
51
  }
7
  * for watchinga YouTube video.
8
  * @see http://codex.mycred.me/shortcodes/mycred_video/
9
  * @since 1.2
10
+ * @since 2.4 Removed logic, Interval greater than 3 was not working
11
  * @version 1.2.2
12
  */
13
  if ( ! function_exists( 'mycred_render_shortcode_video' ) ) :
46
  if ( $id === NULL || empty( $id ) ) return __( 'A video ID is required for this shortcode', 'mycred' );
47
 
48
  // Interval
49
+ if ( $interval ) {
50
  $interval = (float) $interval;
51
  $interval = abs( $interval * 1000 );
52
  }
includes/widgets/mycred-widget-leaderboard.php CHANGED
@@ -24,18 +24,20 @@ if ( ! class_exists( 'myCRED_Widget_Leaderboard' ) ) :
24
  );
25
 
26
  }
 
27
 
28
  /**
29
  * Widget Output
30
  */
31
  public function widget( $args, $instance ) {
 
32
 
33
  $instance['title'] = isset( $instance['title'] ) ? $instance['title'] : 'Leaderboard';
34
  $instance['type'] = isset( $instance['type'] ) ? $instance['type'] : MYCRED_DEFAULT_TYPE_KEY;
35
  $instance['based_on'] = isset( $instance['based_on'] ) ? $instance['based_on'] : 'balance';
36
  $instance['total'] = isset( $instance['total'] ) ? $instance['total'] : 0;
37
  $instance['number'] = isset( $instance['number'] ) ? $instance['number'] : 5;
38
- $instance['show_visitors'] = isset( $instance['show_visitors'] ) ? $instance['show_visitors'] : 0;
39
  $instance['row_layout'] = isset( $instance['row_layout'] ) ? $instance['row_layout'] : '<span>#%position%</span> <span>%user_profile_link%</span> <span>%cred_f%</span>';
40
  $instance['offset'] = isset( $instance['offset'] ) ? $instance['offset'] : 0;
41
  $instance['order'] = isset( $instance['order'] ) ? $instance['order'] : 'DESC';
@@ -45,14 +47,25 @@ if ( ! class_exists( 'myCRED_Widget_Leaderboard' ) ) :
45
  $instance['wrap'] = isset( $instance['wrap'] ) ? $instance['wrap'] : 'li';
46
  $instance['nothing'] = isset( $instance['nothing'] ) ? $instance['nothing'] : 'Leaderboard is empty';
47
  $instance['exclude_zero'] = isset( $instance['exclude_zero'] ) ? $instance['exclude_zero'] : 1;
 
 
48
 
49
  extract( $args, EXTR_SKIP );
 
50
 
51
  // Check if we want to show this to visitors
52
- if ( (! isset($instance['show_visitors']) || ! $instance['show_visitors']) && ! is_user_logged_in() ) return;
53
-
54
- if ( ! isset( $instance['type'] ) || empty( $instance['type'] ) )
 
 
 
 
 
 
 
55
  $instance['type'] = MYCRED_DEFAULT_TYPE_KEY;
 
56
 
57
  $mycred = mycred( $instance['type'] );
58
 
@@ -67,26 +80,36 @@ if ( ! class_exists( 'myCRED_Widget_Leaderboard' ) ) :
67
  'wrap' => $instance['wrap'],
68
  'nothing' => $instance['nothing'],
69
  'exclude_zero' => $instance['exclude_zero'],
70
- 'exclude' => $instance['exclude']
 
 
71
  );
72
 
73
  if ( isset( $instance['order'] ) )
74
  $args['order'] = $instance['order'];
75
 
76
- if ( isset( $instance['offset'] ) )
77
  $args['offset'] = $instance['offset'];
 
 
 
78
 
79
- if ( isset( $instance['current'] ) )
80
- $args['current'] = 1;
 
 
 
 
 
81
 
82
  echo $before_widget;
83
 
84
  // Title
85
  if ( ! empty( $instance['title'] ) )
86
  echo $before_title . $mycred->template_tags_general( $instance['title'] ) . $after_title;
87
-
88
  echo mycred_render_shortcode_leaderboard( $args );
89
-
90
  // Footer
91
  echo $after_widget;
92
 
@@ -96,6 +119,7 @@ if ( ! class_exists( 'myCRED_Widget_Leaderboard' ) ) :
96
  * Outputs the options form on admin
97
  */
98
  public function form( $instance ) {
 
99
 
100
  // Defaults
101
  $title = isset( $instance['title'] ) ? $instance['title'] : 'Leaderboard';
@@ -104,7 +128,7 @@ if ( ! class_exists( 'myCRED_Widget_Leaderboard' ) ) :
104
  $total = isset( $instance['total'] ) ? $instance['total'] : 0;
105
 
106
  $number = isset( $instance['number'] ) ? $instance['number'] : 5;
107
- $show_visitors = isset( $instance['show_visitors'] ) ? $instance['show_visitors'] : 0;
108
  $row_layout = isset( $instance['row_layout'] ) ? $instance['row_layout'] : '<span>#%position%</span> <span>%user_profile_link%</span> <span>%cred_f%</span>';
109
  $offset = isset( $instance['offset'] ) ? $instance['offset'] : 0;
110
  $order = isset( $instance['order'] ) ? $instance['order'] : 'DESC';
@@ -114,8 +138,12 @@ if ( ! class_exists( 'myCRED_Widget_Leaderboard' ) ) :
114
  $nothing = isset( $instance['nothing'] ) ? $instance['nothing'] : 'Leaderboard is empty';
115
  $exclude_zero = isset( $instance['exclude_zero'] ) ? $instance['exclude_zero'] : 1;
116
  $exclude = isset( $instance['exclude'] ) ? $instance['exclude'] : '';
 
117
  $mycred = mycred( $type );
118
  $mycred_types = mycred_get_types();
 
 
 
119
 
120
  ?>
121
  <p class="myCRED-widget-field">
@@ -163,7 +191,14 @@ if ( ! class_exists( 'myCRED_Widget_Leaderboard' ) ) :
163
  </p>
164
 
165
  <p class="myCRED-widget-field">
166
- <label for="<?php echo esc_attr( $this->get_field_id( 'show_visitors' ) ); ?>"><input type="checkbox" name="<?php echo esc_attr( $this->get_field_name( 'show_visitors' ) ); ?>" id="<?php echo esc_attr( $this->get_field_id( 'show_visitors' ) ); ?>" value="1"<?php checked( $show_visitors, 1 ); ?> class="checkbox" /> <?php _e( 'Visible to non-members', 'mycred' ); ?></label>
 
 
 
 
 
 
 
167
  </p>
168
  <p class="myCRED-widget-field">
169
  <label for="<?php echo esc_attr( $this->get_field_id( 'number' ) ); ?>"><?php _e( 'Number of users', 'mycred' ); ?>:</label>
@@ -199,7 +234,12 @@ if ( ! class_exists( 'myCRED_Widget_Leaderboard' ) ) :
199
  </select>
200
  </p>
201
  <p class="myCRED-widget-field">
202
- <label for="<?php echo esc_attr( $this->get_field_id( 'current' ) ); ?>"><input type="checkbox" name="<?php echo esc_attr( $this->get_field_name( 'current' ) ); ?>" id="<?php echo esc_attr( $this->get_field_id( 'current' ) ); ?>" value="1"<?php checked( $current, 1 ); ?> class="checkbox" /> <?php _e( 'Append current users position', 'mycred' ); ?></label><br />
 
 
 
 
 
203
  <small><?php _e( 'If the current user is not in this leaderboard, you can select to append them at the end with their current position.', 'mycred' ); ?></small>
204
  </p>
205
  <p class="myCRED-widget-field">
@@ -222,22 +262,24 @@ if ( ! class_exists( 'myCRED_Widget_Leaderboard' ) ) :
222
  public function update( $new_instance, $old_instance ) {
223
 
224
  $instance = $old_instance;
225
-
 
226
  $instance['number'] = absint( $new_instance['number'] );
227
  $instance['title'] = wp_kses_post( $new_instance['title'] );
228
  $instance['type'] = sanitize_key( $new_instance['type'] );
229
- $instance['based_on'] = sanitize_key( $new_instance['based_on'] );
230
  $instance['total'] = sanitize_key( $new_instance['total'] );
231
- $instance['show_visitors'] = ( isset( $new_instance['show_visitors'] ) ) ? 1 : 0;
232
  $instance['row_layout'] = wp_kses_post( $new_instance['row_layout'] );
233
  $instance['offset'] = sanitize_text_field( $new_instance['offset'] );
234
  $instance['order'] = sanitize_text_field( $new_instance['order'] );
235
- $instance['current'] = ( isset( $new_instance['current'] ) ) ? 1 : 0;
236
  $instance['timeframe'] = sanitize_text_field( $new_instance['timeframe'] );
237
  $instance['wrap'] = sanitize_text_field( $new_instance['wrap'] );
238
  $instance['nothing'] = sanitize_text_field( $new_instance['nothing'] );
239
  $instance['exclude_zero'] = sanitize_text_field( $new_instance['exclude_zero'] );
240
  $instance['exclude'] = sanitize_text_field( $new_instance['exclude'] );
 
241
 
242
  mycred_flush_widget_cache( 'mycred_widget_list' );
243
 
24
  );
25
 
26
  }
27
+
28
 
29
  /**
30
  * Widget Output
31
  */
32
  public function widget( $args, $instance ) {
33
+
34
 
35
  $instance['title'] = isset( $instance['title'] ) ? $instance['title'] : 'Leaderboard';
36
  $instance['type'] = isset( $instance['type'] ) ? $instance['type'] : MYCRED_DEFAULT_TYPE_KEY;
37
  $instance['based_on'] = isset( $instance['based_on'] ) ? $instance['based_on'] : 'balance';
38
  $instance['total'] = isset( $instance['total'] ) ? $instance['total'] : 0;
39
  $instance['number'] = isset( $instance['number'] ) ? $instance['number'] : 5;
40
+ $instance['show_visitors'] = isset( $instance['show_visitors'] ) ? $instance['show_visitors'] : 0;
41
  $instance['row_layout'] = isset( $instance['row_layout'] ) ? $instance['row_layout'] : '<span>#%position%</span> <span>%user_profile_link%</span> <span>%cred_f%</span>';
42
  $instance['offset'] = isset( $instance['offset'] ) ? $instance['offset'] : 0;
43
  $instance['order'] = isset( $instance['order'] ) ? $instance['order'] : 'DESC';
47
  $instance['wrap'] = isset( $instance['wrap'] ) ? $instance['wrap'] : 'li';
48
  $instance['nothing'] = isset( $instance['nothing'] ) ? $instance['nothing'] : 'Leaderboard is empty';
49
  $instance['exclude_zero'] = isset( $instance['exclude_zero'] ) ? $instance['exclude_zero'] : 1;
50
+ $instance['message'] = isset( $instance['message'] ) ? $instance['message'] : '<a href="%login_url_here%">Login</a> to view leaderboard.';
51
+
52
 
53
  extract( $args, EXTR_SKIP );
54
+
55
 
56
  // Check if we want to show this to visitors
57
+ if ( (! isset($instance['show_visitors']) || ! $instance['show_visitors'] ) && ! is_user_logged_in() ) {
58
+ return;
59
+ }
60
+
61
+
62
+ if ( !is_user_logged_in() && !$instance['show_visitors'] ) {
63
+ return;
64
+ }
65
+
66
+ if ( ! isset( $instance['type'] ) || empty( $instance['type'] ) ) {
67
  $instance['type'] = MYCRED_DEFAULT_TYPE_KEY;
68
+ }
69
 
70
  $mycred = mycred( $instance['type'] );
71
 
80
  'wrap' => $instance['wrap'],
81
  'nothing' => $instance['nothing'],
82
  'exclude_zero' => $instance['exclude_zero'],
83
+ 'exclude' => $instance['exclude'],
84
+ 'message' => $instance['message']
85
+
86
  );
87
 
88
  if ( isset( $instance['order'] ) )
89
  $args['order'] = $instance['order'];
90
 
91
+ if ( isset($instance['offset']) )
92
  $args['offset'] = $instance['offset'];
93
+
94
+ if ( isset($instance['exclude']) )
95
+ $args['exclude'] = $instance['exclude'];
96
 
97
+ if ( $instance['current'] === 0 ) {
98
+ return;
99
+ }
100
+
101
+ if ( isset($instance['current']) ) {
102
+ $args['current'] = $instance['current'];
103
+ }
104
 
105
  echo $before_widget;
106
 
107
  // Title
108
  if ( ! empty( $instance['title'] ) )
109
  echo $before_title . $mycred->template_tags_general( $instance['title'] ) . $after_title;
110
+
111
  echo mycred_render_shortcode_leaderboard( $args );
112
+
113
  // Footer
114
  echo $after_widget;
115
 
119
  * Outputs the options form on admin
120
  */
121
  public function form( $instance ) {
122
+
123
 
124
  // Defaults
125
  $title = isset( $instance['title'] ) ? $instance['title'] : 'Leaderboard';
128
  $total = isset( $instance['total'] ) ? $instance['total'] : 0;
129
 
130
  $number = isset( $instance['number'] ) ? $instance['number'] : 5;
131
+ $show_visitors = isset( $instance['show_visitors'] ) ? $instance['show_visitors'] : 0;
132
  $row_layout = isset( $instance['row_layout'] ) ? $instance['row_layout'] : '<span>#%position%</span> <span>%user_profile_link%</span> <span>%cred_f%</span>';
133
  $offset = isset( $instance['offset'] ) ? $instance['offset'] : 0;
134
  $order = isset( $instance['order'] ) ? $instance['order'] : 'DESC';
138
  $nothing = isset( $instance['nothing'] ) ? $instance['nothing'] : 'Leaderboard is empty';
139
  $exclude_zero = isset( $instance['exclude_zero'] ) ? $instance['exclude_zero'] : 1;
140
  $exclude = isset( $instance['exclude'] ) ? $instance['exclude'] : '';
141
+ $message = isset( $instance['message'] ) ? $instance['message'] : '<a href="%login_url_here%">Login</a> to view leaderboard.';
142
  $mycred = mycred( $type );
143
  $mycred_types = mycred_get_types();
144
+
145
+
146
+
147
 
148
  ?>
149
  <p class="myCRED-widget-field">
191
  </p>
192
 
193
  <p class="myCRED-widget-field">
194
+ <label for="<?php echo esc_attr( $this->get_field_id( 'show_visitors' ) ); ?>">
195
+
196
+
197
+ <input type="checkbox" id="<?php echo esc_attr( $this->get_field_id( 'show_visitors' ) ); ?>" name="<?php echo esc_attr( $this->get_field_name( 'show_visitors' ) ); ?>" value="1" <?php if( $show_visitors == '1') echo "checked = 'checked'"; ?>>
198
+
199
+
200
+
201
+ <?php _e( 'Visible to non-members', 'mycred' ); ?></label>
202
  </p>
203
  <p class="myCRED-widget-field">
204
  <label for="<?php echo esc_attr( $this->get_field_id( 'number' ) ); ?>"><?php _e( 'Number of users', 'mycred' ); ?>:</label>
234
  </select>
235
  </p>
236
  <p class="myCRED-widget-field">
237
+ <label for="<?php echo esc_attr( $this->get_field_id( 'current' ) ); ?>">
238
+ <input type="checkbox" name="<?php echo esc_attr( $this->get_field_name( 'current' ) ); ?>" id="<?php echo esc_attr( $this->get_field_id( 'current' ) ); ?>" value="1"<?php if( $current == '1') echo "checked = 'checked'"; ?> class="checkbox" />
239
+
240
+
241
+
242
+ <?php _e( 'Append current users position', 'mycred' ); ?></label><br />
243
  <small><?php _e( 'If the current user is not in this leaderboard, you can select to append them at the end with their current position.', 'mycred' ); ?></small>
244
  </p>
245
  <p class="myCRED-widget-field">
262
  public function update( $new_instance, $old_instance ) {
263
 
264
  $instance = $old_instance;
265
+
266
+ $instance['show_visitors'] = sanitize_text_field($new_instance['show_visitors']);
267
  $instance['number'] = absint( $new_instance['number'] );
268
  $instance['title'] = wp_kses_post( $new_instance['title'] );
269
  $instance['type'] = sanitize_key( $new_instance['type'] );
270
+ $instance['based_on'] = sanitize_text_field( $new_instance['based_on'] );
271
  $instance['total'] = sanitize_key( $new_instance['total'] );
272
+ $instance['show_visitors'] = ( !empty( $new_instance['show_visitors'] ) ) ? sanitize_text_field( $new_instance['show_visitors'] ) : 0;
273
  $instance['row_layout'] = wp_kses_post( $new_instance['row_layout'] );
274
  $instance['offset'] = sanitize_text_field( $new_instance['offset'] );
275
  $instance['order'] = sanitize_text_field( $new_instance['order'] );
276
+ $instance['current'] = sanitize_text_field( $new_instance['current'] ) ;
277
  $instance['timeframe'] = sanitize_text_field( $new_instance['timeframe'] );
278
  $instance['wrap'] = sanitize_text_field( $new_instance['wrap'] );
279
  $instance['nothing'] = sanitize_text_field( $new_instance['nothing'] );
280
  $instance['exclude_zero'] = sanitize_text_field( $new_instance['exclude_zero'] );
281
  $instance['exclude'] = sanitize_text_field( $new_instance['exclude'] );
282
+
283
 
284
  mycred_flush_widget_cache( 'mycred_widget_list' );
285
 
modules/mycred-module-buddypress.php CHANGED
@@ -421,7 +421,7 @@ if ( ! class_exists( 'myCRED_BuddyPress_Module' ) ) :
421
  }
422
 
423
  ?>
424
- <h4><span class="dashicons dashicons-admin-plugins static"></span><label>BuddyPress</label></h4>
425
  <div class="body" style="display:none;">
426
 
427
  <?php do_action( 'mycred_bp_before_settings', $this ); ?>
421
  }
422
 
423
  ?>
424
+ <h4><span class="dashicons dashicons-admin-plugins static"></span><label><?php echo apply_filters( 'mycred_bp_change_text', 'BuddyPress' ); ?></label></h4>
425
  <div class="body" style="display:none;">
426
 
427
  <?php do_action( 'mycred_bp_before_settings', $this ); ?>
modules/mycred-module-log.php CHANGED
@@ -336,6 +336,10 @@ if ( ! class_exists( 'myCRED_Log_Module' ) ) :
336
  mycred_delete_user_meta( $log_entry->user_id, 'mycred_ref_sums-' . $this->mycred_type );
337
 
338
  mycred_delete_option( 'mycred-cache-total-' . $log_entry->ctype );
 
 
 
 
339
 
340
  }
341
 
@@ -581,7 +585,7 @@ if ( ! class_exists( 'myCRED_Log_Module' ) ) :
581
 
582
  // Search Results
583
  if ( isset( $_GET['s'] ) && ! empty( $_GET['s'] ) )
584
- $search_for = ' <span class="subtitle">' . __( 'Search results for', 'mycred' ) . ' "' . $_GET['s'] . '"</span>';
585
 
586
  elseif ( isset( $_GET['time'] ) && $_GET['time'] != '' ) {
587
  $time = urldecode( $_GET['time'] );
336
  mycred_delete_user_meta( $log_entry->user_id, 'mycred_ref_sums-' . $this->mycred_type );
337
 
338
  mycred_delete_option( 'mycred-cache-total-' . $log_entry->ctype );
339
+
340
+ $old_creds = $this->core->number( $log_entry->creds );
341
+
342
+ $this->core->update_users_balance( $log_entry->user_id, $amount - $old_creds, $point_type );
343
 
344
  }
345
 
585
 
586
  // Search Results
587
  if ( isset( $_GET['s'] ) && ! empty( $_GET['s'] ) )
588
+ $search_for = ' <span class="subtitle">' . __( 'Search results for', 'mycred' ) . ' "' . sanitize_text_field( $_GET['s'] ) . '"</span>';
589
 
590
  elseif ( isset( $_GET['time'] ) && $_GET['time'] != '' ) {
591
  $time = urldecode( $_GET['time'] );
mycred.php CHANGED
@@ -3,7 +3,7 @@
3
  * Plugin Name: myCred
4
  * Plugin URI: https://mycred.me
5
  * Description: An adaptive points management system for WordPress powered websites.
6
- * Version: 2.3.2
7
  * Tags: point, credit, loyalty program, engagement, reward, woocommerce rewards
8
  * Author: myCred
9
  * Author URI: https://mycred.me
@@ -20,7 +20,7 @@ if ( ! class_exists( 'myCRED_Core' ) ) :
20
  final class myCRED_Core {
21
 
22
  // Plugin Version
23
- public $version = '2.3.2';
24
 
25
  // Instnace
26
  protected static $_instance = NULL;
@@ -54,14 +54,14 @@ if ( ! class_exists( 'myCRED_Core' ) ) :
54
  * @since 1.7
55
  * @version 1.0
56
  */
57
- public function __clone() { _doing_it_wrong( __FUNCTION__, 'Cheatin&#8217; huh?', '2.3.2' ); }
58
 
59
  /**
60
  * Not allowed
61
  * @since 1.7
62
  * @version 1.0
63
  */
64
- public function __wakeup() { _doing_it_wrong( __FUNCTION__, 'Cheatin&#8217; huh?', '2.3.2' ); }
65
 
66
  /**
67
  * Get
@@ -82,7 +82,7 @@ if ( ! class_exists( 'myCRED_Core' ) ) :
82
  if ( ! defined( $name ) )
83
  define( $name, $value );
84
  elseif ( ! $definable && defined( $name ) )
85
- _doing_it_wrong( 'myCRED_Core->define()', 'Could not define: ' . $name . ' as it is already defined somewhere else!', '2.2' );
86
  }
87
 
88
  /**
@@ -94,7 +94,7 @@ if ( ! class_exists( 'myCRED_Core' ) ) :
94
  if ( file_exists( $required_file ) )
95
  require_once $required_file;
96
  else
97
- _doing_it_wrong( 'myCRED_Core->file()', 'Requested file ' . $required_file . ' not found.', '2.3.2' );
98
  }
99
 
100
  /**
@@ -176,6 +176,7 @@ if ( ! class_exists( 'myCRED_Core' ) ) :
176
  $this->define( 'myCRED_MEMBERSHIP_DIR', myCRED_ROOT_DIR . 'membership/', false );
177
  $this->define( 'myCRED_CLASSES_DIR', myCRED_INCLUDES_DIR . 'classes/', false );
178
  $this->define( 'myCRED_IMPORTERS_DIR', myCRED_INCLUDES_DIR . 'importers/', false );
 
179
  $this->define( 'myCRED_SHORTCODES_DIR', myCRED_INCLUDES_DIR . 'shortcodes/', false );
180
  $this->define( 'myCRED_WIDGETS_DIR', myCRED_INCLUDES_DIR . 'widgets/', false );
181
  $this->define( 'myCRED_HOOKS_DIR', myCRED_INCLUDES_DIR . 'hooks/', false );
@@ -225,7 +226,8 @@ if ( ! class_exists( 'myCRED_Core' ) ) :
225
  /**
226
  * Include Plugin Files
227
  * @since 1.7
228
- * @version 1.2
 
229
  */
230
  public function includes() {
231
 
@@ -250,7 +252,9 @@ if ( ! class_exists( 'myCRED_Core' ) ) :
250
  $this->file( myCRED_INCLUDES_DIR . 'mycred-nav-menu.php' );
251
  $this->file( myCRED_INCLUDES_DIR . 'mycred-tools.php' );
252
  $this->file( myCRED_INCLUDES_DIR . 'mycred-tools-bulk-assign.php' );
253
-
 
 
254
  if( isset ( $_GET['mycred_tour_guide'] ) ){
255
 
256
  $this->file( myCRED_INCLUDES_DIR . 'mycred-walkthrough.php' );
@@ -278,6 +282,9 @@ if ( ! class_exists( 'myCRED_Core' ) ) :
278
  $this->file( myCRED_MODULES_DIR . 'mycred-module-management.php' );
279
  $this->file( myCRED_MODULES_DIR . 'mycred-module-caching.php' );
280
 
 
 
 
281
  //Uninstall Settings
282
  $this->file( myCRED_INCLUDES_DIR . 'mycred-uninstall.php' );
283
 
3
  * Plugin Name: myCred
4
  * Plugin URI: https://mycred.me
5
  * Description: An adaptive points management system for WordPress powered websites.
6
+ * Version: 2.4
7
  * Tags: point, credit, loyalty program, engagement, reward, woocommerce rewards
8
  * Author: myCred
9
  * Author URI: https://mycred.me
20
  final class myCRED_Core {
21
 
22
  // Plugin Version
23
+ public $version = '2.4';
24
 
25
  // Instnace
26
  protected static $_instance = NULL;
54
  * @since 1.7
55
  * @version 1.0
56
  */
57
+ public function __clone() { _doing_it_wrong( __FUNCTION__, 'Cheatin&#8217; huh?', '2.4' ); }
58
 
59
  /**
60
  * Not allowed
61
  * @since 1.7
62
  * @version 1.0
63
  */
64
+ public function __wakeup() { _doing_it_wrong( __FUNCTION__, 'Cheatin&#8217; huh?', '2.4' ); }
65
 
66
  /**
67
  * Get
82
  if ( ! defined( $name ) )
83
  define( $name, $value );
84
  elseif ( ! $definable && defined( $name ) )
85
+ _doing_it_wrong( 'myCRED_Core->define()', 'Could not define: ' . $name . ' as it is already defined somewhere else!', '2.4' );
86
  }
87
 
88
  /**
94
  if ( file_exists( $required_file ) )
95
  require_once $required_file;
96
  else
97
+ _doing_it_wrong( 'myCRED_Core->file()', 'Requested file ' . $required_file . ' not found.', '2.4' );
98
  }
99
 
100
  /**
176
  $this->define( 'myCRED_MEMBERSHIP_DIR', myCRED_ROOT_DIR . 'membership/', false );
177
  $this->define( 'myCRED_CLASSES_DIR', myCRED_INCLUDES_DIR . 'classes/', false );
178
  $this->define( 'myCRED_IMPORTERS_DIR', myCRED_INCLUDES_DIR . 'importers/', false );
179
+ $this->define( 'myCRED_BLOCKS_DIR', myCRED_INCLUDES_DIR . 'mycred-blocks/', false );
180
  $this->define( 'myCRED_SHORTCODES_DIR', myCRED_INCLUDES_DIR . 'shortcodes/', false );
181
  $this->define( 'myCRED_WIDGETS_DIR', myCRED_INCLUDES_DIR . 'widgets/', false );
182
  $this->define( 'myCRED_HOOKS_DIR', myCRED_INCLUDES_DIR . 'hooks/', false );
226
  /**
227
  * Include Plugin Files
228
  * @since 1.7
229
+ * @since 2.4 Tools Import/ Export Added
230
+ * @version 1.3
231
  */
232
  public function includes() {
233
 
252
  $this->file( myCRED_INCLUDES_DIR . 'mycred-nav-menu.php' );
253
  $this->file( myCRED_INCLUDES_DIR . 'mycred-tools.php' );
254
  $this->file( myCRED_INCLUDES_DIR . 'mycred-tools-bulk-assign.php' );
255
+ $this->file( myCRED_INCLUDES_DIR . 'mycred-tools-setup-import-export.php' );
256
+ $this->file( myCRED_INCLUDES_DIR . 'mycred-tools-import-export.php' );
257
+
258
  if( isset ( $_GET['mycred_tour_guide'] ) ){
259
 
260
  $this->file( myCRED_INCLUDES_DIR . 'mycred-walkthrough.php' );
282
  $this->file( myCRED_MODULES_DIR . 'mycred-module-management.php' );
283
  $this->file( myCRED_MODULES_DIR . 'mycred-module-caching.php' );
284
 
285
+ // Mycred Blocks
286
+ $this->file( myCRED_BLOCKS_DIR . 'mycred-blocks.php' );
287
+
288
  //Uninstall Settings
289
  $this->file( myCRED_INCLUDES_DIR . 'mycred-uninstall.php' );
290
 
readme.txt CHANGED
@@ -3,7 +3,7 @@ Contributors: mycred,wpexpertsio
3
  Tags: badges, gamification, loyalty, points, rewards
4
  Requires at least: 4.8
5
  Tested up to: 5.8.2
6
- Stable tag: 2.3.2
7
  Requires PHP: 7.0
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
@@ -30,17 +30,35 @@ myCred allows **THREE different ways** through which you can award your users:
30
 
31
  * **Badges -** Boost your users' participation by rewarding them for their exceptional performance.
32
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
33
  **Latest update - myCred v2.3**
34
 
35
  **myCred v2.3** is a core update that helps the admin award points, badges and ranks to users in bulk. Similarly, the admin can also choose to revoke these award types from multiple users simultaneously.
36
 
37
  Here are some of the most prominent features of the latest update:
38
 
39
- * A Bulk Assign tool for awarding/revoking points, badges, and ranks in bulk.
40
  * The admin can exclude any user role from receiving points. Previously, the admin could only exclude users using user ID only.
41
  * A timeframe attribute in [mycred_my_balance_converted] shortcode - users can see their converted point balance in a given timeframe using predefined filters (Yesterday, Today, this week, this month, last month).
42
 
43
- **Last update - myCred v2.2**
44
 
45
  **myCred v2.2** focuses on improving the overall user interface, single badge page layout, point-type image, and social media sharing for a better user experience and operational efficiency.
46
 
@@ -281,6 +299,9 @@ You can find a list of [frequently asked questions](https://mycred.me/about/faq/
281
 
282
  == Upgrade Notice ==
283
 
 
 
 
284
  = 2.3.2 =
285
  Code improvement.
286
 
@@ -323,6 +344,21 @@ The banking module have been replaced by Central deposite module, and interest r
323
 
324
  == Changelog ==
325
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
326
  = 2.3.2 =
327
  - **TWAEK** - Code improvement.
328
 
@@ -336,7 +372,7 @@ The banking module have been replaced by Central deposite module, and interest r
336
  - **FIX** - Sometimes user's ranks were not updating automatically.
337
  - **FIX** - Membership page layout issues.
338
  - **FIX** - Points conversion not working when using arrows to increase or decrease the amount in [mycred_cashcred] shortcode.
339
- - **FIX** - buyCred payment dialog couldnt load on the subsite.
340
  - **FIX** - After deleting the badge their data will keep existing on the user's meta.
341
  - **FIX** - "this-week" value not working in [mycred_leaderboard] timeframe attribute when the week starts other than "Monday" in your WordPress setting.
342
 
3
  Tags: badges, gamification, loyalty, points, rewards
4
  Requires at least: 4.8
5
  Tested up to: 5.8.2
6
+ Stable tag: 2.4
7
  Requires PHP: 7.0
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
30
 
31
  * **Badges -** Boost your users' participation by rewarding them for their exceptional performance.
32
 
33
+ **Latest update - myCred v2.4**
34
+
35
+ **myCred v2.4** focuses on expanding the plugin’s ability to import and export points, ranks, and badges from and to other sites. What’s better is that you can choose to export or import complete setup settings like point types, achievements level, and created badges with achievements level with the simplest of ease.
36
+
37
+ Here is a list of the complete features introduced in myCred v2.4:
38
+ * Import or export user points
39
+ * Export all or specific point types
40
+ * Export setup settings for all point types
41
+ * Import or export setup settings in JSON format
42
+ * Import or all or specific export user ranks
43
+ * Import or export all or specific user badges
44
+ * Import badges With ID/Title/Slug
45
+ * Import ranks With ID/Title/Slug
46
+ * Export raw or formatted file
47
+ * Select users fields in the exported file
48
+ * Assign Badges/Ranks using coupons
49
+ * Merged myCred Gutenberg to myCred Core
50
+
51
  **Latest update - myCred v2.3**
52
 
53
  **myCred v2.3** is a core update that helps the admin award points, badges and ranks to users in bulk. Similarly, the admin can also choose to revoke these award types from multiple users simultaneously.
54
 
55
  Here are some of the most prominent features of the latest update:
56
 
57
+ * A "Bulk Assign" tool for awarding/revoking points, badges, and ranks in bulk.
58
  * The admin can exclude any user role from receiving points. Previously, the admin could only exclude users using user ID only.
59
  * A timeframe attribute in [mycred_my_balance_converted] shortcode - users can see their converted point balance in a given timeframe using predefined filters (Yesterday, Today, this week, this month, last month).
60
 
61
+ **Recent update - myCred v2.2**
62
 
63
  **myCred v2.2** focuses on improving the overall user interface, single badge page layout, point-type image, and social media sharing for a better user experience and operational efficiency.
64
 
299
 
300
  == Upgrade Notice ==
301
 
302
+ = 2.4 =
303
+ New features and Bug fixes.
304
+
305
  = 2.3.2 =
306
  Code improvement.
307
 
344
 
345
  == Changelog ==
346
 
347
+ = 2.4 =
348
+ - **NEW** - Introduced an Import/Export tool.
349
+ - **NEW** - Admin can assign "Badges" and "Manual Ranks" using coupons.
350
+ - **NEW** - Merged myCred Gutenberg to myCred Core.
351
+ - **TWEAK** - Code improvements.
352
+ - **FIX** - myCred video interval three-digit value not working
353
+ - **FIX** - exclude_zero attribute not working when total=1 in mycred_leaderboard shortcode.
354
+ - **FIX** - In the badge edit window, remove level button always removes the first level.
355
+ - **FIX** - Badges are not visible in the user profile for non-admin users.
356
+ - **FIX** - When updating log entry it will not reflect on the current balance.
357
+ - **FIX** - CSS confliction with some themes.
358
+ - **FIX** - Stopped users from getting points on signup referral multiple times on a single event.
359
+ - **FIX** - Leaderboard excludes users by role not working.
360
+ - **FIX** - Leaderboard excludes users by comma-separated ids not working.
361
+
362
  = 2.3.2 =
363
  - **TWAEK** - Code improvement.
364
 
372
  - **FIX** - Sometimes user's ranks were not updating automatically.
373
  - **FIX** - Membership page layout issues.
374
  - **FIX** - Points conversion not working when using arrows to increase or decrease the amount in [mycred_cashcred] shortcode.
375
+ - **FIX** - buyCred payment dialog couldn’t load on the subsite.
376
  - **FIX** - After deleting the badge their data will keep existing on the user's meta.
377
  - **FIX** - "this-week" value not working in [mycred_leaderboard] timeframe attribute when the week starts other than "Monday" in your WordPress setting.
378