myCRED - Version 1.7.9.5

Version Description

FIX - Notification error.

Download this release

Release Info

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

Code changes from version 1.7.9.3 to 1.7.9.5

Files changed (159) hide show
  1. abstracts/mycred-abstract-module.php +18 -18
  2. abstracts/mycred-abstract-object.php +0 -39
  3. addons/badges/assets/js/edit-badge.js +0 -456
  4. addons/badges/includes/mycred-badge-object.php +0 -97
  5. addons/banking/assets/js/manage-schedules.js +0 -180
  6. addons/banking/includes/mycred-banking-functions.php +0 -389
  7. addons/banking/services/mycred-bank-service-interest.php +344 -0
  8. addons/banking/services/mycred-bank-service-payouts.php +308 -0
  9. addons/banking/services/mycred-service-central.php +0 -145
  10. addons/banking/services/mycred-service-interest.php +0 -691
  11. addons/banking/services/mycred-service-payouts.php +0 -1002
  12. addons/{badges/assets/js → buddypress}/index.php +0 -0
  13. addons/buy-creds/abstracts/mycred-abstract-payment-gateway.php +2 -8
  14. addons/buy-creds/gateways/bank-transfer.php +0 -260
  15. addons/buy-creds/gateways/bitpay.php +3 -2
  16. addons/{banking/assets → buy-creds/images}/index.php +0 -0
  17. addons/buy-creds/images/loading.gif +0 -0
  18. addons/buy-creds/images/netbilling.png +0 -0
  19. addons/buy-creds/images/skrill.png +0 -0
  20. addons/buy-creds/images/zombaio.jpg +0 -0
  21. addons/buy-creds/includes/buycred-functions.php +0 -295
  22. addons/buy-creds/modules/buycred-module-core.php +0 -1591
  23. addons/buy-creds/modules/buycred-module-pending.php +0 -862
  24. addons/email-notices/assets/css/edit-email-notice.css +0 -21
  25. addons/email-notices/css/edit-email-notice.css +11 -0
  26. addons/email-notices/{assets/css → css}/email-notice.css +0 -0
  27. addons/{banking/assets/js → email-notices/css}/index.php +0 -0
  28. addons/gateway/carts/mycred-marketpress.php +579 -0
  29. addons/{banking/includes → gateway/event-booking}/index.php +0 -0
  30. addons/gateway/event-booking/mycred-eventsmanager-pro.php +641 -0
  31. addons/{buy-creds/includes → gateway/membership}/index.php +0 -0
  32. addons/import/includes/File-CSV-DataSource.php +834 -0
  33. addons/{buy-creds/modules → import/includes}/index.php +0 -0
  34. addons/{email-notices/assets/css → import}/index.php +0 -0
  35. addons/import/myCRED-addon-import.php +782 -0
  36. addons/{email-notices/assets → notifications/css}/index.php +0 -0
  37. addons/notifications/{assets/css → css}/notify.css +0 -0
  38. addons/notifications/{assets/css → js}/index.php +0 -0
  39. addons/notifications/{assets/js → js}/notify.js +1 -1
  40. addons/notifications/myCRED-addon-notifications.php +7 -3
  41. addons/ranks/assets/js/tweaks.js +0 -18
  42. addons/ranks/includes/mycred-rank-object.php +0 -78
  43. addons/{notifications/assets → ranks/js}/index.php +0 -0
  44. addons/ranks/{assets/js → js}/management.js +8 -11
  45. addons/sell-content/assets/js/buy-content.js +0 -61
  46. addons/sell-content/assets/js/index.php +0 -3
  47. addons/sell-content/css/edit.css +12 -0
  48. addons/{notifications/assets/js → sell-content/css}/index.php +0 -0
  49. addons/sell-content/includes/index.php +0 -3
  50. addons/sell-content/includes/mycred-sell-functions.php +0 -848
  51. addons/sell-content/includes/mycred-sell-shortcodes.php +0 -334
  52. addons/sell-content/js/buy-content.js +46 -0
  53. addons/{ranks/assets → sell-content/js}/index.php +0 -0
  54. addons/stats/abstracts/index.php +0 -3
  55. addons/stats/abstracts/mycred-abstract-stat-widget.php +0 -183
  56. addons/stats/assets/css/index.php +0 -3
  57. addons/stats/assets/css/mycred-statistics-admin.css +0 -56
  58. addons/stats/assets/css/mycred-statistics.css +0 -22
  59. addons/stats/assets/index.php +0 -3
  60. addons/stats/assets/js/Chart.js +0 -3421
  61. addons/stats/assets/js/index.php +0 -3
  62. addons/stats/includes/classes/class.query-stats.php +0 -27
  63. addons/stats/includes/classes/index.php +0 -3
  64. addons/stats/includes/index.php +0 -3
  65. addons/stats/includes/mycred-stats-functions.php +0 -199
  66. addons/stats/includes/mycred-stats-shortcodes.php +0 -35
  67. addons/stats/index.php +0 -3
  68. addons/stats/myCRED-addon-stats.php +0 -452
  69. addons/stats/widgets/index.php +0 -3
  70. addons/stats/widgets/mycred-stats-widget-circulation.php +0 -392
  71. addons/stats/widgets/mycred-stats-widget-daily-gains.php +0 -204
  72. addons/stats/widgets/mycred-stats-widget-daily-loses.php +0 -204
  73. addons/transfer/assets/index.php +0 -3
  74. addons/transfer/assets/js/index.php +0 -3
  75. addons/transfer/assets/js/mycred-transfer.js +0 -141
  76. addons/{ranks/assets/js → transfer/css}/index.php +0 -0
  77. addons/transfer/css/transfer.css +33 -0
  78. addons/transfer/includes/index.php +0 -3
  79. addons/transfer/includes/mycred-transfer-functions.php +0 -275
  80. addons/transfer/includes/mycred-transfer-shortcodes.php +0 -357
  81. addons/transfer/includes/mycred-transfer-widgets.php +0 -157
  82. addons/{sell-content/assets → transfer/js}/index.php +0 -0
  83. addons/transfer/js/transfer.js +111 -0
  84. assets/css/{mycred-admin.css → admin.css} +26 -68
  85. assets/css/bootstrap-grid.css +0 -2
  86. assets/css/inline-edit.css +5 -0
  87. assets/css/mycred-edit-balance.css +0 -85
  88. assets/css/mycred-edit-log.css +0 -65
  89. assets/css/mycred-forms.css +0 -53
  90. assets/css/overview.css +34 -0
  91. assets/css/{mycred-front.css → widget.css} +0 -0
  92. assets/images/about/badge.png +0 -0
  93. assets/images/badge.png +0 -0
  94. assets/images/badges-addon.png +0 -0
  95. assets/images/banking-addon.png +0 -0
  96. assets/images/buy-creds-addon.png +0 -0
  97. assets/images/coupons-addon.png +0 -0
  98. assets/images/email-notifications-addon.png +0 -0
  99. assets/images/gateway-addon.png +0 -0
  100. assets/images/mycred-about-balance.png +0 -0
  101. assets/images/mycred-about-hooks.png +0 -0
  102. assets/images/mycred-loading.gif +0 -0
  103. assets/images/notifications-addon.png +0 -0
  104. assets/images/ranks-addon.png +0 -0
  105. assets/images/sell-content-addon.png +0 -0
  106. assets/images/statistics-addon.png +0 -0
  107. assets/images/token-sitting.png +0 -0
  108. assets/images/transfer-addon.png +0 -0
  109. assets/js/{mycred-accordion.js → accordion.js} +6 -8
  110. assets/js/edit-log.js +278 -0
  111. assets/js/inline-edit.js +129 -0
  112. assets/js/{mycred-type-management.js → management.js} +28 -158
  113. assets/js/mycred-admin-widgets.js +0 -608
  114. assets/js/mycred-edit-balance.js +0 -292
  115. assets/js/mycred-edit-log.js +0 -387
  116. assets/libs/jquery-numerator.js +0 -137
  117. assets/libs/mustache.min.js +0 -1
  118. assets/libs/parsecsv.lib.php +0 -0
  119. assets/screenshot-5.png +0 -0
  120. includes/classes/class.query-export.php +0 -589
  121. includes/classes/class.query-leaderboard.php +0 -799
  122. includes/classes/class.query-log.php +0 -2696
  123. includes/classes/index.php +0 -3
  124. includes/mycred-admin.php +788 -0
  125. includes/mycred-depreciated.php +356 -0
  126. includes/mycred-importer.php +107 -0
  127. includes/mycred-install.php +0 -4
  128. includes/mycred-leaderboard.php +320 -0
  129. includes/mycred-log.php +902 -0
  130. includes/mycred-network.php +243 -0
  131. includes/mycred-object.php +0 -227
  132. includes/mycred-protect.php +16 -18
  133. includes/mycred-referrals.php +0 -72
  134. includes/mycred-remote.php +1 -3
  135. includes/mycred-setup.php +0 -481
  136. includes/mycred-shortcodes.php +1056 -0
  137. includes/shortcodes/index.php +0 -3
  138. includes/shortcodes/mycred_affiliate_id.php +0 -20
  139. includes/shortcodes/mycred_affiliate_link.php +0 -20
  140. includes/shortcodes/mycred_best_user.php +0 -137
  141. includes/shortcodes/mycred_exchange.php +0 -227
  142. includes/shortcodes/mycred_give.php +0 -54
  143. includes/shortcodes/mycred_hide_if.php +0 -122
  144. includes/shortcodes/mycred_history.php +0 -87
  145. includes/shortcodes/mycred_hook_table.php +0 -130
  146. includes/shortcodes/mycred_leaderboard.php +0 -42
  147. includes/shortcodes/mycred_leaderboard_position.php +0 -63
  148. includes/shortcodes/mycred_link.php +0 -102
  149. includes/shortcodes/mycred_my_balance.php +0 -79
  150. includes/shortcodes/mycred_send.php +0 -163
  151. includes/shortcodes/mycred_show_if.php +0 -122
  152. includes/shortcodes/mycred_total_balance.php +0 -83
  153. includes/shortcodes/mycred_total_points.php +0 -91
  154. includes/shortcodes/mycred_total_since.php +0 -38
  155. includes/shortcodes/mycred_video.php +0 -107
  156. lang/mycred-fr_FR.mo +0 -0
  157. lang/mycred-fr_FR.po +0 -0
  158. lang/mycred-ja_JP.mo +0 -0
  159. lang/mycred-ja_JP.po +0 -693
abstracts/mycred-abstract-module.php CHANGED
@@ -136,16 +136,16 @@ if ( ! class_exists( 'myCRED_Module' ) ) :
136
  if ( $this->register === false ) {
137
 
138
  // If settings does not exist apply defaults
139
- if ( ! isset( $this->core->$module ) )
140
- $this->$module = $this->default_prefs;
141
 
142
  // Else append settings
143
  else
144
- $this->$module = $this->core->$module;
145
 
146
  // Apply defaults in case new settings have been applied
147
  if ( ! empty( $this->default_prefs ) )
148
- $this->$module = wp_parse_args( $this->$module, $this->default_prefs );
149
 
150
  }
151
 
@@ -162,7 +162,7 @@ if ( ! class_exists( 'myCRED_Module' ) ) :
162
  $pattern = 'mycred_pref_core';
163
  //$matches = array_filter( $this->option_id, function( $a ) use ( $pattern ) { return preg_grep( $a, $pattern ); } );
164
  //if ( ! empty( $matches ) )
165
- $this->$module = $this->core;
166
 
167
  // Loop and grab
168
  foreach ( $this->option_id as $option_id => $option_name ) {
@@ -170,13 +170,13 @@ if ( ! class_exists( 'myCRED_Module' ) ) :
170
  $settings = mycred_get_option( $option_name, false );
171
 
172
  if ( $settings === false && array_key_exists( $option_id, $defaults ) )
173
- $this->$module[ $option_name ] = $this->default_prefs[ $option_id ];
174
  else
175
- $this->$module[ $option_name ] = $settings;
176
 
177
  // Apply defaults in case new settings have been applied
178
  if ( array_key_exists( $option_id, $this->default_prefs ) )
179
- $this->$module[ $option_name ] = wp_parse_args( $this->$module[ $option_name ], $this->default_prefs[ $option_id ] );
180
 
181
  }
182
 
@@ -187,27 +187,27 @@ if ( ! class_exists( 'myCRED_Module' ) ) :
187
 
188
  // General settings needs not to be loaded
189
  if ( str_replace( 'mycred_pref_core', '', $this->option_id ) == '' )
190
- $this->$module = $this->core;
191
 
192
  // Grab the requested option
193
  else {
194
 
195
- $this->$module = mycred_get_option( $this->option_id, false );
196
 
197
- if ( $this->$module === false && ! empty( $this->default_prefs ) )
198
- $this->$module = $this->default_prefs;
199
 
200
  // Apply defaults in case new settings have been applied
201
  if ( ! empty( $this->default_prefs ) )
202
- $this->$module = wp_parse_args( $this->$module, $this->default_prefs );
203
 
204
  }
205
 
206
  }
207
 
208
- if ( is_array( $this->$module ) ) {
209
 
210
- foreach ( $this->$module as $key => $value ) {
211
  $this->$key = $value;
212
  }
213
 
@@ -341,7 +341,7 @@ if ( ! class_exists( 'myCRED_Module' ) ) :
341
  function is_installed() {
342
 
343
  $module_name = $this->module_name;
344
- if ( $this->$module_name === false ) return false;
345
  return true;
346
 
347
  }
@@ -360,8 +360,8 @@ if ( ! class_exists( 'myCRED_Module' ) ) :
360
 
361
  if ( ! isset( $this->active ) && ! empty( $key ) ) {
362
 
363
- if ( isset( $this->$module['active'] ) )
364
- $active = $this->$module['active'];
365
 
366
  if ( in_array( $key, $active ) )
367
  $is_active = true;
136
  if ( $this->register === false ) {
137
 
138
  // If settings does not exist apply defaults
139
+ if ( ! isset( $this->core->{$module} ) )
140
+ $this->{$module} = $this->default_prefs;
141
 
142
  // Else append settings
143
  else
144
+ $this->{$module} = $this->core->{$module};
145
 
146
  // Apply defaults in case new settings have been applied
147
  if ( ! empty( $this->default_prefs ) )
148
+ $this->{$module} = wp_parse_args( $this->{$module}, $this->default_prefs );
149
 
150
  }
151
 
162
  $pattern = 'mycred_pref_core';
163
  //$matches = array_filter( $this->option_id, function( $a ) use ( $pattern ) { return preg_grep( $a, $pattern ); } );
164
  //if ( ! empty( $matches ) )
165
+ $this->{$module} = $this->core;
166
 
167
  // Loop and grab
168
  foreach ( $this->option_id as $option_id => $option_name ) {
170
  $settings = mycred_get_option( $option_name, false );
171
 
172
  if ( $settings === false && array_key_exists( $option_id, $defaults ) )
173
+ $this->{$module[ $option_name ]} = $this->default_prefs[ $option_id ];
174
  else
175
+ $this->{$module[ $option_name ]} = $settings;
176
 
177
  // Apply defaults in case new settings have been applied
178
  if ( array_key_exists( $option_id, $this->default_prefs ) )
179
+ $this->{$module[ $option_name ]} = wp_parse_args( $this->{$module[ $option_name ]}, $this->default_prefs[ $option_id ] );
180
 
181
  }
182
 
187
 
188
  // General settings needs not to be loaded
189
  if ( str_replace( 'mycred_pref_core', '', $this->option_id ) == '' )
190
+ $this->{$module} = $this->core;
191
 
192
  // Grab the requested option
193
  else {
194
 
195
+ $this->{$module} = mycred_get_option( $this->option_id, false );
196
 
197
+ if ( $this->{$module} === false && ! empty( $this->default_prefs ) )
198
+ $this->{$module} = $this->default_prefs;
199
 
200
  // Apply defaults in case new settings have been applied
201
  if ( ! empty( $this->default_prefs ) )
202
+ $this->{$module} = wp_parse_args( $this->{$module}, $this->default_prefs );
203
 
204
  }
205
 
206
  }
207
 
208
+ if ( is_array( $this->{$module} ) ) {
209
 
210
+ foreach ( $this->{$module} as $key => $value ) {
211
  $this->$key = $value;
212
  }
213
 
341
  function is_installed() {
342
 
343
  $module_name = $this->module_name;
344
+ if ( $this->module_name === false ) return false;
345
  return true;
346
 
347
  }
360
 
361
  if ( ! isset( $this->active ) && ! empty( $key ) ) {
362
 
363
+ if ( isset( $this->{$module['active']} ) )
364
+ $active = $this->{$module['active']};
365
 
366
  if ( in_array( $key, $active ) )
367
  $is_active = true;
abstracts/mycred-abstract-object.php DELETED
@@ -1,39 +0,0 @@
1
- <?php
2
- if ( ! defined( 'myCRED_VERSION' ) ) exit;
3
-
4
- /**
5
- * myCRED_Object class
6
- * @see http://codex.mycred.me/classes/mycred_object/
7
- * @since 1.7
8
- * @version 1.0
9
- */
10
- if ( ! class_exists( 'myCRED_Object' ) ) :
11
- abstract class myCRED_Object {
12
-
13
- /**
14
- * Construct
15
- */
16
- function __construct() {
17
-
18
- if ( ! did_action( 'init' ) )
19
- wp_die( 'myCRED_Account class used too early. This class should be called after the init action fires.' );
20
-
21
- }
22
-
23
- public function get_mycred( $object = NULL, $type_id = MYCRED_DEFAULT_TYPE_KEY ) {
24
-
25
- if ( ! is_object( $object ) ) {
26
-
27
- if ( ! is_string( $type_id ) || ! mycred_point_type_exists( $type_id ) )
28
- $type_id = MYCRED_DEFAULT_TYPE_KEY;
29
-
30
- $object = mycred( $type_id );
31
-
32
- }
33
-
34
- return $object;
35
-
36
- }
37
-
38
- }
39
- endif;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
addons/badges/assets/js/edit-badge.js DELETED
@@ -1,456 +0,0 @@
1
- jQuery(function($){
2
-
3
- var myCREDBadgeLevelsWrap = $( '#mycred-badge-setup .inside' );
4
-
5
- var AddNewLevelButton = $( '#badges-add-new-level' );
6
- var AddNewRequirementButton = $( '#badges-add-new-requirement' );
7
- var ChangeDefaultImageButton = $( '#badges-change-default-image' );
8
-
9
- var TotalBadgeLevels = 1;
10
- var TotalRequirements = 1;
11
- var UsedtoCompare = 'AND';
12
-
13
- var PointTypeSelect = $( 'select#badge-select-point-type' );
14
- var ReferenceSelect = $( 'select#badge-select-reference' );
15
- var RequirementTypeSelect = $( 'select#badge-select-requirement-type' );
16
- var RequirementCompare = $( '#badge-requirement-compare a' );
17
-
18
- var LevelImageSelector;
19
- var DefaultImageSelector;
20
-
21
- /**
22
- * Get Badge Requirements Template
23
- * Creates a template of the top-level badge's set requirements.
24
- * @since 1.7
25
- * @version 1.0
26
- */
27
- var mycred_get_badge_requirement_template = function( badgelevel ) {
28
-
29
- var template = '';
30
-
31
- // Loop through each requirement set for the top-level badge
32
- $( '#mycred-badge-level0 .level-requirements .row-narrow' ).each(function(index){
33
-
34
- // Row
35
- var required_row_id = $(this).data( 'row' );
36
-
37
- // Point Type
38
- var required_point_type = $(this).find( 'select.point-type option:selected' );
39
- if ( required_point_type === undefined || required_point_type == '' )
40
- required_point_type = '-';
41
- else
42
- required_point_type = required_point_type.text();
43
-
44
- // Reference
45
- var required_reference = $(this).find( 'select.reference option:selected' );
46
- if ( required_reference === undefined || required_reference == '' )
47
- required_reference = '-';
48
- else
49
- required_reference = required_reference.text();
50
-
51
- // Amount
52
- var required_amount = $(this).find( 'input.form-control' ).val();
53
-
54
- // Requirement type
55
- var required_type = $(this).find( 'select.req-type option:selected' );
56
- if ( required_type === undefined || required_type == '' )
57
- required_type = '-';
58
- else
59
- required_type = required_type.text();
60
-
61
- // Comparison
62
- var compare_to_show = myCREDBadge.compareOR;
63
- if ( UsedtoCompare == 'AND' )
64
- compare_to_show = myCREDBadge.compareAND;
65
-
66
- var totalrequirements = $( '#mycred-badge-level0 .level-requirements .row-narrow' ).length;
67
- if ( totalrequirements > 1 && index+1 == totalrequirements || ( totalrequirements == 1 && index == 0 ) )
68
- compare_to_show = '';
69
-
70
- // Render fresh requirement template
71
- template += Mustache.render( BadgeRequirement, {
72
- level : badgelevel,
73
- reqlevel : required_row_id,
74
- selectedtype : required_point_type,
75
- selectedref : required_reference,
76
- reqamount : required_amount,
77
- selectedby : required_type,
78
- comparelabel : compare_to_show
79
- });
80
-
81
- });
82
-
83
- return template;
84
-
85
- };
86
-
87
- $(document).ready(function(){
88
-
89
- TotalBadgeLevels = $( '#mycred-badge-setup #badge-levels .badge-level' ).length;
90
- TotalRequirements = $( '#mycred-badge-setup .level-requirements .row-narrow' ).length;
91
-
92
- console.log( 'Total levels detected: ' + TotalBadgeLevels );
93
-
94
- // Change Requirement Compare Action
95
- RequirementCompare.click(function(e){
96
-
97
- e.preventDefault();
98
-
99
- var refselectcompare = $(this);
100
- refselectcompare.blur();
101
-
102
- if ( refselectcompare.hasClass( 'selected' ) ) return false;
103
-
104
- var currentlyselected = $( '#badge-requirement-compare a.selected' );
105
- if ( currentlyselected !== undefined )
106
- currentlyselected.removeClass( 'selected' );
107
-
108
- UsedtoCompare = refselectcompare.data( 'do' );
109
- $( '#badge-requirement-compare input' ).val( UsedtoCompare );
110
-
111
- refselectcompare.addClass( 'selected' );
112
-
113
- // Make sure there is more then one level
114
- var numberoflevels = $( '#mycred-badge-setup #badge-levels .badge-level' ).length;
115
- if ( numberoflevels == 1 ) return;
116
-
117
- var newrequirementlevel = $( '#mycred-badge-level0 .level-requirements .row-narrow' ).length;
118
-
119
- var compare_to_show = myCREDBadge.compareOR;
120
- if ( UsedtoCompare == 'AND' )
121
- compare_to_show = myCREDBadge.compareAND;
122
-
123
- // Loop through all place holders for each level and change the text
124
- $( '#mycred-badge-setup #badge-levels .level-requirements .level-compare p' ).each(function(index){
125
-
126
- $(this).fadeOut(function(){
127
-
128
- var reqrowid = $(this).data( 'row' );
129
-
130
- if ( newrequirementlevel > 1 && reqrowid+1 == newrequirementlevel )
131
- $(this).empty().fadeIn();
132
-
133
- else
134
- $(this).empty().text( compare_to_show ).fadeIn();
135
-
136
- });
137
-
138
- });
139
-
140
- });
141
-
142
- // Add New Requirement Action
143
- AddNewRequirementButton.click(function(e){
144
-
145
- e.preventDefault();
146
-
147
- console.log( 'Add new requirement clicked' );
148
- // Prep
149
- var totallevels = $( '#mycred-badge-setup #badge-levels .badge-level' );
150
- var totalrequirements = $( '#mycred-badge-level0 .level-requirements .row-narrow' );
151
- var newrequirementlevel = totalrequirements.length;
152
-
153
- // Render a fresh requirement row
154
- var template = Mustache.render( BadgeNewRequrement, {
155
- reqlevel : newrequirementlevel,
156
- level : 0,
157
- reqamount : ''
158
- });
159
-
160
- // Insert fresh row to the top level
161
- $( '#mycred-badge-setup #mycred-badge-level0 .level-requirements' ).append( template );
162
-
163
- if ( totallevels.length > 1 ) {
164
-
165
- // Loop through each level and insert a blank requirement row for each one
166
- totallevels.each(function( index ){
167
-
168
- var currentlevel = $(this).data( 'level' );
169
-
170
- // Skip firt row as we just added one in there
171
- if ( currentlevel > 0 ) {
172
-
173
- var compare_to_show = myCREDBadge.compareOR;
174
- if ( UsedtoCompare == 'AND' )
175
- compare_to_show = myCREDBadge.compareAND;
176
-
177
- // Render a fresh requirement row
178
- var reqtemplate = Mustache.render( BadgeRequirement, {
179
- level : currentlevel,
180
- reqlevel : newrequirementlevel,
181
- reqamount : '',
182
- selectedtype : '-',
183
- selectedref : '-',
184
- selectedby : '-',
185
- comparelabel : ''
186
- });
187
-
188
- // Insert fresh row to the requirement list
189
- $( '#mycred-badge-setup #mycred-badge-level' + currentlevel + ' .level-requirements' ).append( reqtemplate );
190
-
191
- if ( newrequirementlevel > 0 ) {
192
-
193
- for ( var i = newrequirementlevel-1; i > -1; i-- ) {
194
-
195
- $( '#mycred-badge-setup #mycred-badge-level' + currentlevel + ' #level' + currentlevel + 'requirement' + i + ' .level-compare p' ).fadeOut(function(){
196
- $(this).empty().text( compare_to_show ).fadeIn();
197
- });
198
-
199
- }
200
-
201
- }
202
-
203
- }
204
-
205
- // Next!
206
-
207
- });
208
-
209
- }
210
-
211
- });
212
-
213
- // Remove Requirement Action
214
- $( '#mycred-badge-setup' ).on( 'click', 'button.remove-requirement', function(e){
215
-
216
- var rowtoremove = $(this).data( 'req' );
217
-
218
- $( '#level0requirement' + rowtoremove ).slideUp(function(){
219
- $(this).remove();
220
- });
221
-
222
- $( '#mycred-badge-setup #badge-levels .badge-level' ).each(function( index ){
223
-
224
- var currentlevel = $(this).data( 'level' );
225
-
226
- if ( currentlevel > 0 ) {
227
-
228
- $( '#mycred-badge-setup #level' + currentlevel + 'requirement' + rowtoremove ).remove();
229
-
230
- }
231
-
232
- });
233
-
234
- });
235
-
236
- // Change Point Type Requirement Action
237
- $( '#mycred-badge-setup' ).on( 'change', 'select.point-type', function(e){
238
-
239
- var typeselectelement = $(this);
240
-
241
- // Make sure something was selected
242
- var selectedtype = typeselectelement.find( ':selected' );
243
- if ( selectedtype === undefined ) return;
244
-
245
- // Make sure there is more then one level
246
- var numberoflevels = $( '#mycred-badge-setup #badge-levels .badge-level' ).length;
247
- if ( numberoflevels == 1 ) return;
248
-
249
- var requirementrow = typeselectelement.data( 'row' );
250
-
251
- // Loop through each level
252
- $( '#mycred-badge-setup #badge-levels .badge-level' ).each(function(index){
253
-
254
- var badgelevel = $(this).data( 'level' );
255
- if ( badgelevel == 0 ) { return true; }
256
-
257
- var subrequirementrow = $(this).find( '#level' + badgelevel + 'requirement' + requirementrow + ' .level-type p' );
258
- if ( subrequirementrow !== undefined ) {
259
-
260
- subrequirementrow.fadeOut(function(){
261
- subrequirementrow.empty().text( selectedtype.text() ).fadeIn();
262
- });
263
-
264
- }
265
-
266
- });
267
-
268
- });
269
-
270
- // Change Reference Requrirement Action
271
- $( '#mycred-badge-setup' ).on( 'change', 'select.reference', function(e){
272
-
273
- var refselectelement = $(this);
274
-
275
- // Make sure something was selected
276
- var selectedref = refselectelement.find( ':selected' );
277
- if ( selectedref === undefined ) return;
278
-
279
- // Make sure there is more then one level
280
- var numberoflevels = $( '#mycred-badge-setup #badge-levels .badge-level' ).length;
281
- if ( numberoflevels == 1 ) return;
282
-
283
- var requirementrow = refselectelement.data( 'row' );
284
-
285
- // Loop through each level
286
- $( '#mycred-badge-setup #badge-levels .badge-level' ).each(function(index){
287
-
288
- var badgelevel = $(this).data( 'level' );
289
- if ( badgelevel == 0 ) { return true; }
290
-
291
- var subrequirementrow = $(this).find( '#level' + badgelevel + 'requirement' + requirementrow + ' .level-ref p' );
292
- if ( subrequirementrow !== undefined ) {
293
-
294
- subrequirementrow.fadeOut(function(){
295
- subrequirementrow.empty().text( selectedref.text() ).fadeIn();
296
- });
297
-
298
- }
299
-
300
- });
301
-
302
- });
303
-
304
- // Change Requirement Type Action
305
- $( '#mycred-badge-setup' ).on( 'change', 'select.req-type', function(e){
306
-
307
- var reftypeselectelement = $(this);
308
-
309
- // Make sure something was selected
310
- var selectedreftype = reftypeselectelement.find( ':selected' );
311
- if ( selectedreftype === undefined ) return;
312
-
313
- // Make sure there is more then one level
314
- var numberoflevels = $( '#mycred-badge-setup #badge-levels .badge-level' ).length;
315
- if ( numberoflevels == 1 ) return;
316
-
317
- var requirementrow = reftypeselectelement.data( 'row' );
318
-
319
- // Loop through each level
320
- $( '#mycred-badge-setup #badge-levels .badge-level' ).each(function(index){
321
-
322
- var badgelevel = $(this).data( 'level' );
323
- if ( badgelevel == 0 ) { return true; }
324
-
325
- var subrequirementrow = $(this).find( '#level' + badgelevel + 'requirement' + requirementrow + ' .level-type-by p' );
326
- if ( subrequirementrow !== undefined ) {
327
-
328
- subrequirementrow.fadeOut(function(){
329
- subrequirementrow.empty().text( selectedreftype.text() ).fadeIn();
330
- });
331
-
332
- }
333
-
334
- });
335
-
336
- });
337
-
338
- // Add New Level Action
339
- AddNewLevelButton.click(function(e){
340
-
341
- e.preventDefault();
342
-
343
- console.log( 'Add new level button' );
344
- // Prep
345
- TotalBadgeLevels = $( '#mycred-badge-setup #badge-levels .badge-level' ).length;
346
- TotalRequirements = $( '#mycred-badge-setup .level-requirements .row-narrow' ).length;
347
-
348
- // Get the top-level requirement list as a template
349
- var reqtemplate = mycred_get_badge_requirement_template( TotalBadgeLevels );
350
-
351
- // Render a fresh level
352
- var template = Mustache.render( BadgeLevel, {
353
- level : TotalBadgeLevels,
354
- levelone : ( parseInt( TotalBadgeLevels ) + 1 ),
355
- requirements : reqtemplate
356
- });
357
-
358
- // Insert fresh row
359
- $( '#mycred-badge-setup #badge-levels' ).append( template );
360
-
361
- });
362
-
363
- // Set / Change Level Image Action
364
- $( '#mycred-badge-setup' ).on( 'click', 'button.change-level-image', function(e){
365
-
366
- console.log( 'Change level image button' );
367
-
368
- var button = $(this);
369
- var currentlevel = button.data( 'level' );
370
-
371
- LevelImageSelector = wp.media.frames.file_frame = wp.media({
372
- title : myCREDBadge.uploadtitle,
373
- button : {
374
- text : myCREDBadge.uploadbutton
375
- },
376
- multiple : false
377
- });
378
-
379
- // When a file is selected, grab the URL and set it as the text field's value
380
- LevelImageSelector.on( 'select', function(){
381
-
382
- attachment = LevelImageSelector.state().get('selection').first().toJSON();
383
- if ( attachment.url != '' ) {
384
-
385
- $( '#mycred-badge-level' + currentlevel + ' .level-image-wrapper' ).fadeOut(function(){
386
-
387
- $( '#mycred-badge-level' + currentlevel + ' .level-image-wrapper' ).empty().removeClass( 'empty dashicons' ).html( '<img src="' + attachment.url + '" alt="Badge level image" \/><input type="hidden" name="mycred_badge[levels][' + currentlevel + '][attachment_id]" value="' + attachment.id + '" \/><input type="hidden" name="mycred_badge[levels][' + currentlevel + '][image]" value="" \/>' ).fadeIn();
388
- button.text( myCREDBadge.changeimage );
389
-
390
- });
391
-
392
- }
393
-
394
- });
395
-
396
- // Open the uploader dialog
397
- LevelImageSelector.open();
398
-
399
- });
400
-
401
- // Remove Level Action
402
- $( '#mycred-badge-setup' ).on( 'click', 'button.remove-badge-level', function(e){
403
-
404
- var leveltoremove = $(this).data( 'level' );
405
- if ( $( '#mycred-badge-level' + leveltoremove ) === undefined ) return false;
406
-
407
- console.log( 'Remove level button' );
408
-
409
- if ( ! confirm( myCREDBadge.remove ) ) return false;
410
-
411
- $( '#mycred-badge-level' + leveltoremove ).slideUp().remove();
412
- TotalBadgeLevels--;
413
-
414
- });
415
-
416
- // Change Default Image Action
417
- ChangeDefaultImageButton.click(function(e){
418
-
419
- e.preventDefault();
420
- console.log( 'Change default image button' );
421
-
422
- var button = $(this);
423
-
424
- DefaultImageSelector = wp.media.frames.file_frame = wp.media({
425
- title : myCREDBadge.uploadtitle,
426
- button : {
427
- text : myCREDBadge.uploadbutton
428
- },
429
- multiple : false
430
- });
431
-
432
- // When a file is selected, grab the URL and set it as the text field's value
433
- DefaultImageSelector.on( 'select', function(){
434
-
435
- attachment = DefaultImageSelector.state().get('selection').first().toJSON();
436
- if ( attachment.url != '' ) {
437
-
438
- $( '#mycred-badge-default .default-image-wrapper' ).fadeOut(function(){
439
-
440
- $( '#mycred-badge-default .default-image-wrapper' ).empty().removeClass( 'empty dashicons' ).html( '<img src="' + attachment.url + '" alt="Badge default image" \/><input type="hidden" name="mycred_badge[main_image]" value="' + attachment.id + '" \/><input type="hidden" name="mycred_badge[main_image_url]" value="" \/>' ).fadeIn();
441
- button.text( myCREDBadge.changeimage );
442
-
443
- });
444
-
445
- }
446
-
447
- });
448
-
449
- // Open the uploader dialog
450
- DefaultImageSelector.open();
451
-
452
- });
453
-
454
- });
455
-
456
- });
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
addons/badges/includes/mycred-badge-object.php DELETED
@@ -1,97 +0,0 @@
1
- <?php
2
- if ( ! defined( 'myCRED_VERSION' ) ) exit;
3
-
4
- /**
5
- * myCRED_Badge class
6
- * @see http://codex.mycred.me/classes/mycred_badge/
7
- * @since 1.7
8
- * @version 1.0
9
- */
10
- if ( ! class_exists( 'myCRED_Badge' ) ) :
11
- class myCRED_Badge extends myCRED_Object {
12
-
13
- public $post_id = false;
14
- public $title = '';
15
- public $earnedby = 0;
16
- public $manual = false;
17
- public $levels = array();
18
- public $level = false;
19
- public $level_label = false;
20
- public $main_image = false;
21
- public $level_image = false;
22
- public $image_width = false;
23
- public $image_height = false;
24
-
25
- /**
26
- * Construct
27
- */
28
- function __construct( $badge_id = NULL, $level = NULL ) {
29
-
30
- parent::__construct();
31
-
32
- $badge_id = absint( $badge_id );
33
-
34
- if ( get_post_type( $badge_id ) != 'mycred_badge' ) return;
35
-
36
- $this->image_width = MYCRED_BADGE_WIDTH;
37
- $this->image_height = MYCRED_BADGE_HEIGHT;
38
-
39
- $this->populate( $badge_id, $level );
40
-
41
- }
42
-
43
- protected function populate( $badge_id = NULL, $level = NULL ) {
44
-
45
- $this->post_id = absint( $badge_id );
46
- $this->title = get_the_title( $this->post_id );
47
- $this->earnedby = mycred_count_users_with_badge( $badge_id, $level );
48
- $this->levels = mycred_get_badge_levels( $this->post_id );
49
-
50
- if ( absint( get_post_meta( $this->post_id, 'manual_badge', true ) ) === 1 )
51
- $this->manual = true;
52
-
53
- if ( $level !== NULL && ! empty( $this->levels ) && array_key_exists( $level, $this->levels ) ) {
54
- $this->level = $this->levels[ $level ];
55
- if ( $this->level['label'] != '' )
56
- $this->level_label = $this->level['label'];
57
- }
58
-
59
- $this->main_image = $this->get_image( 'main' );
60
- $this->level_image = $this->get_image( $level );
61
-
62
- }
63
-
64
- public function get_image( $image = NULL ) {
65
-
66
- $image_identification = false;
67
- $level = 0;
68
-
69
- if ( $image === 'main' )
70
- $image_identification = get_post_meta( $this->post_id, 'main_image', true );
71
-
72
- elseif ( $image !== NULL && is_numeric( $image ) && isset( $this->levels[ $image ]['attachment_id'] ) ) {
73
-
74
- $level = $image;
75
- $image_identification = $this->levels[ $image ]['image_url'];
76
- if ( $this->levels[ $image ]['attachment_id'] > 0 )
77
- $image_identification = $this->levels[ $image ]['attachment_id'];
78
-
79
- }
80
-
81
- if ( $image_identification === false || strlen( $image_identification ) == 0 ) return false;
82
-
83
- $image_url = $image_identification;
84
- if ( is_numeric( $image_identification ) && strpos( '://', $image_identification ) === false )
85
- $image_url = wp_get_attachment_url( $image_identification );
86
-
87
- $image_width = ( $this->image_width !== false ) ? ' width="' . esc_attr( $this->image_width ) . '"' : '';
88
- $image_height = ( $this->image_height !== false ) ? ' height="' . esc_attr( $this->image_height ) . '"' : '';
89
-
90
- $html = '<img src="' . esc_url( $image_url ) . '" class="' . MYCRED_SLUG . '-badge-image badge-level' . esc_attr( $level ) . '" title="' . esc_attr( $this->title ) . '" alt="' . esc_attr( $this->title ) . '"' . $image_width . $image_height . ' />';
91
-
92
- return apply_filters( 'mycred_badge_image', $html, $image, $this );
93
-
94
- }
95
-
96
- }
97
- endif;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
addons/banking/assets/js/manage-schedules.js DELETED
@@ -1,180 +0,0 @@
1
- jQuery(function($) {
2
-
3
- var RecurringSchedule = $( '#manage-recurring-schedule' );
4
- var currentBankService = '';
5
- var wWidth = $(window).width();
6
- var dWidth = wWidth * 0.75;
7
-
8
- function check_form_for_empty_fields() {
9
-
10
- var emptyfields = 0;
11
-
12
- $( '#manage-recurring-schedule-form input.cant-be-empty' ).each(function(index){
13
-
14
- var fieldvalue = $(this).val();
15
- if ( fieldvalue.length == 0 ) {
16
- $(this).parent().addClass( 'has-error' );
17
- emptyfields++;
18
- }
19
- else
20
- $(this).parent().removeClass( 'has-error' );
21
-
22
- });
23
-
24
- if ( emptyfields > 0 )
25
- return false;
26
-
27
- else return true;
28
-
29
- };
30
-
31
- $(document).ready(function(){
32
-
33
- if ( dWidth < 250 )
34
- dWidth = wWidth;
35
-
36
- if ( dWidth > 960 )
37
- dWidth = 960;
38
-
39
- /**
40
- * Setup Schedule Modal
41
- */
42
- RecurringSchedule.dialog({
43
- dialogClass : 'mycred-update-balance mycred-metabox',
44
- draggable : true,
45
- autoOpen : false,
46
- title : Banking.new,
47
- closeText : Banking.close,
48
- modal : true,
49
- width : dWidth,
50
- height : 'auto',
51
- resizable : false,
52
- position : { my: "center", at: "top+25%", of: window },
53
- show : {
54
- effect : 'fadeIn',
55
- duration : 250
56
- },
57
- hide : {
58
- effect : 'fadeOut',
59
- duration : 250
60
- }
61
- });
62
-
63
- RecurringSchedule.on( "dialogclose", function( event, ui ) {
64
-
65
- $( '#manage-recurring-schedule-form' ).empty();
66
- $( '#mycred-processing' ).show();
67
-
68
- } );
69
-
70
- // Schedule
71
- $( '#add-new-schedule' ).click(function(e){
72
-
73
- e.preventDefault();
74
-
75
- $(this).blur();
76
-
77
- RecurringSchedule.dialog({ title : Banking.new });
78
- RecurringSchedule.dialog( 'open' );
79
- $( '#manage-recurring-schedule-form' ).submit();
80
-
81
- });
82
-
83
- // Form submissions
84
- $( '#manage-recurring-schedule-form' ).on( 'submit', function(e){
85
-
86
- e.preventDefault();
87
-
88
- if ( check_form_for_empty_fields() === false ) {
89
- alert( Banking.emptyfields );
90
- return false;
91
- }
92
-
93
- $( '#mycred-processing' ).show();
94
-
95
- var thisform = $(this);
96
-
97
- $.ajax({
98
- type : 'POST',
99
- data : {
100
- action : 'run-mycred-bank-service',
101
- _token : Banking.token,
102
- service : 'payouts',
103
- form : thisform.serialize()
104
- },
105
- dataType : 'JSON',
106
- url : Banking.ajaxurl,
107
- beforeSend : function(){
108
- thisform.slideUp();
109
- },
110
- success : function( response ) {
111
-
112
- if ( response.success === undefined ) {
113
- location.reload();
114
- return false;
115
- }
116
-
117
- $( '#mycred-processing' ).hide();
118
-
119
- thisform.empty().append( response.data.form ).slideDown();
120
-
121
- if ( response.data.table !== false ) {
122
-
123
- var scheduletable = $( '#recurring-schedule-body tr' );
124
- if ( scheduletable.length == 1 )
125
- $( '#no-banking-schedules' ).hide();
126
-
127
- $( '#recurring-schedule-body #no-banking-schedules' ).before( response.data.table );
128
-
129
- }
130
- else {
131
- var scheduletable = $( '#recurring-schedule-body tr' );
132
- if ( scheduletable.length == 1 )
133
- $( '#no-banking-schedules' ).show();
134
- }
135
-
136
- }
137
- });
138
-
139
- });
140
-
141
- // View Schedule
142
- $( '#recurring-schedule-body' ).on( 'click', 'a.view-recurring-schedule', function(e){
143
-
144
- e.preventDefault();
145
-
146
- $(this).blur();
147
-
148
- var scheduleid = $(this).data( 'id' );
149
- $( '#manage-recurring-schedule-form' ).append( '<input type="hidden" name="schedule_id" value="' + scheduleid + '" />' );
150
-
151
- RecurringSchedule.dialog({ title : $(this).data( 'title' ) });
152
- RecurringSchedule.dialog( 'open' );
153
- $( '#manage-recurring-schedule-form' ).submit();
154
-
155
- });
156
-
157
- // Delete Schedule
158
- $( '#recurring-schedule-body' ).on( 'click', 'a.delete-recurring-schedule', function(e){
159
-
160
- e.preventDefault();
161
-
162
- $(this).blur();
163
-
164
- var scheduleid = $(this).data( 'id' );
165
- $( '#manage-recurring-schedule-form' ).append( '<input type="hidden" name="remove_token" value="' + scheduleid + '" />' );
166
-
167
- if ( confirm( Banking.confirmremoval ) ) {
168
- RecurringSchedule.dialog({ title : $(this).data( 'title' ) });
169
- RecurringSchedule.dialog( 'open' );
170
- $( '#manage-recurring-schedule-form' ).submit();
171
- }
172
- else {
173
- $( '#manage-recurring-schedule-form' ).empty();
174
- }
175
-
176
- });
177
-
178
- });
179
-
180
- });
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
addons/banking/includes/mycred-banking-functions.php DELETED
@@ -1,389 +0,0 @@
1
- <?php
2
- if ( ! defined( 'myCRED_VERSION' ) ) exit;
3
-
4
- /**
5
- * Get Next Payout
6
- * Adds seconds to a given time based on the payout period set.
7
- * @since 1.7
8
- * @version 1.0
9
- */
10
- if ( ! function_exists( 'mycred_get_banking_addon_settings' ) ) :
11
- function mycred_get_banking_addon_settings( $service = NULL, $point_type = MYCRED_DEFAULT_TYPE_KEY ) {
12
-
13
- $default = array(
14
- 'active' => array(),
15
- 'services' => array(),
16
- 'service_prefs' => array()
17
- );
18
-
19
- $option_id = 'mycred_pref_bank';
20
- if ( $point_type != MYCRED_DEFAULT_TYPE_KEY )
21
- $option_id .= '_' . $point_type;
22
-
23
- $settings = mycred_get_option( $option_id, $default );
24
- $settings = wp_parse_args( $settings, $default );
25
-
26
- if ( $service !== NULL && array_key_exists( $service, $settings['service_prefs'] ) )
27
- $settings = $settings['service_prefs'][ $service ];
28
-
29
- return $settings;
30
-
31
- }
32
- endif;
33
-
34
- /**
35
- * Get Next Payout
36
- * Adds seconds to a given time based on the payout period set.
37
- * @since 1.7
38
- * @version 1.0
39
- */
40
- if ( ! function_exists( 'mycred_banking_get_next_payout' ) ) :
41
- function mycred_banking_get_next_payout( $prefs = '', $time = 0 ) {
42
-
43
- if ( $prefs == 'hourly' )
44
- return $time + HOUR_IN_SECONDS;
45
-
46
- elseif ( $prefs == 'daily' )
47
- return $time + DAY_IN_SECONDS;
48
-
49
- elseif ( $prefs == 'weekly' )
50
- return $time + WEEK_IN_SECONDS;
51
-
52
- elseif ( $prefs == 'monthly' )
53
- return $time + MONTH_IN_SECONDS;
54
-
55
- elseif ( $prefs == 'quarterly' )
56
- return $time + ( MONTH_IN_SECONDS * 4 );
57
-
58
- elseif ( $prefs == 'semiannually' )
59
- return $time + ( MONTH_IN_SECONDS * 6 );
60
-
61
- elseif ( $prefs == 'annually' )
62
- return $time + YEAR_IN_SECONDS;
63
-
64
- return apply_filters( 'mycred_banking_get_next_payout', $time, $prefs );
65
-
66
- }
67
- endif;
68
-
69
- /**
70
- * Get Timeframes
71
- * @since 1.7
72
- * @version 1.0
73
- */
74
- if ( ! function_exists( 'mycred_banking_get_timeframes' ) ) :
75
- function mycred_banking_get_timeframes() {
76
-
77
- $timeframes = array(
78
- 'hourly' => array(
79
- 'label' => __( 'Hourly', 'mycred' ),
80
- 'single' => __( 'Hour', 'mycred' ),
81
- 'date_format' => 'G'
82
- ),
83
- 'daily' => array(
84
- 'label' => __( 'Daily', 'mycred' ),
85
- 'single' => __( 'Day', 'mycred' ),
86
- 'date_format' => 'z'
87
- ),
88
- 'weekly' => array(
89
- 'label' => __( 'Weekly', 'mycred' ),
90
- 'single' => __( 'Week', 'mycred' ),
91
- 'date_format' => 'W'
92
- ),
93
- 'monthly' => array(
94
- 'label' => __( 'Monthly', 'mycred' ),
95
- 'single' => __( 'Month', 'mycred' ),
96
- 'date_format' => 'M'
97
- ),
98
- 'quarterly' => array(
99
- 'label' => __( 'Quarterly', 'mycred' ),
100
- 'single' => __( 'Quarter', 'mycred' ),
101
- 'date_format' => 'Y'
102
- ),
103
- 'semiannually' => array(
104
- 'label' => __( 'Semiannually', 'mycred' ),
105
- 'single' => __( 'Semiannual', 'mycred' ),
106
- 'date_format' => 'Y'
107
- ),
108
- 'annually' => array(
109
- 'label' => __( 'Annually', 'mycred' ),
110
- 'single' => __( 'Annual', 'mycred' ),
111
- 'date_format' => 'Y'
112
- )
113
- );
114
-
115
- return apply_filters( 'mycred_banking_timeframes', $timeframes );
116
-
117
- }
118
- endif;
119
-
120
- /**
121
- * Get Time Options
122
- * Returns an array of 24 hours with support for either 24 or 12 hour formats.
123
- * @since 1.7
124
- * @version 1.0
125
- */
126
- if ( ! function_exists( 'mycred_banking_get_time_options' ) ) :
127
- function mycred_banking_get_time_options( $twelve_hour = false ) {
128
-
129
- $options = array(
130
- '00:00' => '00:00',
131
- '01:00' => '01:00',
132
- '02:00' => '02:00',
133
- '03:00' => '03:00',
134
- '04:00' => '04:00',
135
- '05:00' => '05:00',
136
- '06:00' => '06:00',
137
- '07:00' => '07:00',
138
- '08:00' => '08:00',
139
- '09:00' => '09:00',
140
- '10:00' => '10:00',
141
- '11:00' => '11:00',
142
- '12:00' => '12:00',
143
- '13:00' => '13:00',
144
- '14:00' => '14:00',
145
- '15:00' => '15:00',
146
- '16:00' => '16:00',
147
- '17:00' => '17:00',
148
- '18:00' => '18:00',
149
- '19:00' => '19:00',
150
- '20:00' => '20:00',
151
- '21:00' => '21:00',
152
- '22:00' => '22:00',
153
- '23:00' => '23:00'
154
- );
155
-
156
- $time_format = get_option( 'time_format' );
157
- if ( str_replace( array( 'a', 'A' ), '', $time_format ) != $time_format || $twelve_hour )
158
- $options = array(
159
- '00:00' => '12:00 AM',
160
- '01:00' => '1:00 AM',
161
- '02:00' => '2:00 AM',
162
- '03:00' => '3:00 AM',
163
- '04:00' => '4:00 AM',
164
- '05:00' => '5:00 AM',
165
- '06:00' => '6:00 AM',
166
- '07:00' => '7:00 AM',
167
- '08:00' => '8:00 AM',
168
- '09:00' => '9:00 AM',
169
- '10:00' => '10:00 AM',
170
- '11:00' => '11:00 AM',
171
- '12:00' => '12:00 PM',
172
- '13:00' => '1:00 PM',
173
- '14:00' => '2:00 PM',
174
- '15:00' => '3:00 PM',
175
- '16:00' => '4:00 PM',
176
- '17:00' => '5:00 PM',
177
- '18:00' => '6:00 PM',
178
- '19:00' => '7:00 PM',
179
- '20:00' => '8:00 PM',
180
- '21:00' => '9:00 PM',
181
- '22:00' => '10:00 PM',
182
- '23:00' => '11:00 PM'
183
- );
184
-
185
- return apply_filters( 'mycred_banking_time_options', $options );
186
-
187
- }
188
- endif;
189
-
190
- /**
191
- * Get Recurring Payout Schedules
192
- * @since 1.7
193
- * @version 1.0
194
- */
195
- if ( ! function_exists( 'mycred_get_recurring_payout_schedules' ) ) :
196
- function mycred_get_recurring_payout_schedules( $point_type = MYCRED_DEFAULT_TYPE_KEY ) {
197
-
198
- $schedules = mycred_get_option( 'mycred-recurring-schedule-' . $point_type, array() );
199
- $defaults = mycred_get_recurring_payout_defaults();
200
-
201
- $results = array();
202
- if ( ! empty( $schedules ) ) {
203
-
204
- foreach ( $schedules as $schedule_id => $setup )
205
- $results[ $schedule_id ] = shortcode_atts( $defaults, $setup );
206
-
207
- }
208
-
209
- return $results;
210
-
211
- }
212
- endif;
213
-
214
- /**
215
- * Get Recurring Payout Defaults
216
- * @since 1.7
217
- * @version 1.0
218
- */
219
- if ( ! function_exists( 'mycred_get_recurring_payout_defaults' ) ) :
220
- function mycred_get_recurring_payout_defaults() {
221
-
222
- $defaults = array(
223
- 'job_title' => '',
224
- 'status' => 0,
225
- 'payout' => '',
226
- 'frequency' => 'daily',
227
- 'last_run' => '',
228
- 'total_runs' => 1,
229
- 'runs_remaining' => 0,
230
- 'min_balance' => 0,
231
- 'max_balance' => 0,
232
- 'id_exclude' => 'exclude',
233
- 'id_list' => '',
234
- 'role_exclude' => 'exclude',
235
- 'role_list' => array(),
236
- 'log_template' => '%plural% payout',
237
- 'total_completed' => 0,
238
- 'total_misses' => 0,
239
- 'ignore_central' => 0
240
- );
241
-
242
- return $defaults;
243
-
244
- }
245
- endif;
246
-
247
- /**
248
- * Get Recurring Payout
249
- * Returns the settings of a specific recurring payout.
250
- * @since 1.7
251
- * @version 1.0
252
- */
253
- if ( ! function_exists( 'mycred_get_recurring_payout' ) ) :
254
- function mycred_get_recurring_payout( $schedule_id = NULL, $point_type = MYCRED_DEFAULT_TYPE_KEY ) {
255
-
256
- $result = false;
257
- $schedules = mycred_get_recurring_payout_schedules( $point_type );
258
-
259
- if ( array_key_exists( $schedule_id, $schedules ) )
260
- $result = $schedules[ $schedule_id ];
261
-
262
- return $result;
263
-
264
- }
265
- endif;
266
-
267
- /**
268
- * Add New Recurring Payout
269
- * @since 1.7
270
- * @version 1.0
271
- */
272
- if ( ! function_exists( 'mycred_add_new_recurring_payout' ) ) :
273
- function mycred_add_new_recurring_payout( $new_id = '', $schedule_setup = array(), $point_type = MYCRED_DEFAULT_TYPE_KEY ) {
274
-
275
- $default = mycred_get_recurring_payout_defaults();
276
- $new_id = sanitize_key( $new_id );
277
- $schedule_setup = shortcode_atts( $default, $schedule_setup );
278
- $mycred = mycred( $point_type );
279
-
280
- // Validate first
281
- $title = sanitize_text_field( $schedule_setup['job_title'] );
282
- if ( $title == '' )
283
- return new WP_Error( 'invalid', __( 'A title must be set.', 'mycred' ) );
284
-
285
- $schedule_setup['job_title'] = $title;
286
-
287
- $payout = sanitize_text_field( $schedule_setup['payout'] );
288
- $payout = $mycred->number( $payout );
289
- if ( $payout == $mycred->zero() )
290
- return new WP_Error( 'invalid', __( 'The amount to payout can not be zero.', 'mycred' ) );
291
-
292
- $schedule_setup['payout'] = $payout;
293
-
294
- $last_run = absint( $schedule_setup['last_run'] );
295
- if ( $last_run < time() )
296
- return new WP_Error( 'invalid', __( 'Start date can not be in the past.', 'mycred' ) );
297
-
298
- $schedule_setup['last_run'] = $last_run;
299
-
300
- $total_runs = sanitize_text_field( $schedule_setup['total_runs'] );
301
- if ( $total_runs < -1 ) $total_runs = -1;
302
- if ( $total_runs == 0 )
303
- return new WP_Error( 'invalid', __( 'Repeat can not be zero.', 'mycred' ) );
304
-
305
- $schedule_setup['total_runs'] = $total_runs;
306
-
307
- $schedules = mycred_get_recurring_payout_schedules( $point_type );
308
- if ( array_key_exists( $new_id, $schedules ) )
309
- return new WP_Error( 'invalid', __( 'Duplicate schedule.', 'mycred' ) );
310
-
311
- $schedule_setup['status'] = 0;
312
- $schedule_setup['runs_remaining'] = $schedule_setup['total_runs'];
313
-
314
- $schedules[ $new_id ] = $schedule_setup;
315
-
316
- // Save
317
- mycred_update_option( 'mycred-recurring-schedule-' . $point_type, $schedules );
318
-
319
- // Add Schedule to CRON
320
- wp_schedule_single_event( $last_run, 'mycred-recurring-' . $new_id, array( 'id' => $new_id ) );
321
-
322
- return $schedule_setup;
323
-
324
- }
325
- endif;
326
-
327
- /**
328
- * Update Recurring Payout
329
- * @since 1.7
330
- * @version 1.0
331
- */
332
- if ( ! function_exists( 'mycred_update_recurring_payout' ) ) :
333
- function mycred_update_recurring_payout( $schedule_id = '', $schedule_setup = array(), $point_type = MYCRED_DEFAULT_TYPE_KEY ) {
334
-
335
- $result = false;
336
- $setup = mycred_get_recurring_payout( $schedule_id, $point_type );
337
-
338
- if ( is_array( $setup ) ) {
339
-
340
- $schedules = mycred_get_recurring_payout_schedules( $point_type );
341
-
342
- $schedules[ $schedule_id ] = shortcode_atts( $setup, $schedule_setup );
343
-
344
- mycred_update_option( 'mycred-recurring-schedule-' . $point_type, $schedules );
345
-
346
- $result = true;
347
-
348
- }
349
-
350
- return $result;
351
-
352
- }
353
- endif;
354
-
355
- /**
356
- * Delete Recurring Payout
357
- * @since 1.7
358
- * @version 1.0
359
- */
360
- if ( ! function_exists( 'mycred_delete_recurring_payout' ) ) :
361
- function mycred_delete_recurring_payout( $id_to_remove = NULL, $point_type = MYCRED_DEFAULT_TYPE_KEY ) {
362
-
363
- $result = false;
364
- $schedules = mycred_get_recurring_payout_schedules( $point_type );
365
-
366
- if ( ! empty( $schedules ) ) {
367
-
368
- $new_schedule = array();
369
- foreach ( $schedules as $schedule_id => $schedule_setup ) {
370
-
371
- if ( $schedule_id == $id_to_remove ) continue;
372
- $new_schedule[ $schedule_id ] = $schedule_setup;
373
-
374
- }
375
-
376
- // Save
377
- mycred_update_option( 'mycred-recurring-schedule-' . $point_type, $new_schedule );
378
-
379
- // Clear schedule in CRON
380
- wp_clear_scheduled_hook( 'mycred-recurring-' . $schedule_id, array( 'id' => $schedule_id ) );
381
-
382
- $result = true;
383
-
384
- }
385
-
386
- return $result;
387
-
388
- }
389
- endif;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
addons/banking/services/mycred-bank-service-interest.php ADDED
@@ -0,0 +1,344 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * myCRED Bank Service - Interest
4
+ * @since 1.2
5
+ * @version 1.1
6
+ */
7
+ if ( ! defined( 'myCRED_VERSION' ) ) exit;
8
+
9
+ if ( ! class_exists( 'myCRED_Banking_Service_Interest' ) ) {
10
+ class myCRED_Banking_Service_Interest extends myCRED_Service {
11
+
12
+ /**
13
+ * Construct
14
+ */
15
+ function __construct( $service_prefs ) {
16
+ parent::__construct( array(
17
+ 'id' => 'interest',
18
+ 'defaults' => array(
19
+ 'rate' => array(
20
+ 'amount' => 2,
21
+ 'period' => 1,
22
+ 'pay_out' => 'monthly'
23
+ ),
24
+ 'last_payout' => '',
25
+ 'log' => __( '%plural% interest rate payment', 'mycred' ),
26
+ 'min_balance' => 1,
27
+ 'run_time' => 60
28
+ )
29
+ ), $service_prefs );
30
+ }
31
+
32
+ /**
33
+ * Run
34
+ * @since 1.2
35
+ * @version 1.0
36
+ */
37
+ public function run() {
38
+ add_action( 'wp_loaded', array( $this, 'process' ) );
39
+ add_action( 'mycred_banking_interest_compound', array( $this, 'do_compound' ) );
40
+ add_action( 'mycred_banking_do_compound_batch', array( $this, 'do_compound_batch' ) );
41
+
42
+ add_action( 'mycred_banking_interest_payout', array( $this, 'do_payouts' ) );
43
+ add_action( 'mycred_banking_interest_do_batch', array( $this, 'do_interest_batch' ) );
44
+ }
45
+
46
+ /**
47
+ * Deactivation
48
+ * @since 1.2
49
+ * @version 1.0
50
+ */
51
+ public function deactivate() {
52
+ // Unschedule compounding
53
+ $timestamp = wp_next_scheduled( 'mycred_banking_interest_compound' );
54
+ if ( $timestamp !== false )
55
+ wp_clear_scheduled_hook( $timestamp, 'mycred_banking_interest_compound' );
56
+
57
+ // Unschedule payouts
58
+ $timestamp = wp_next_scheduled( 'mycred_banking_interest_payout' );
59
+ if ( $timestamp !== false )
60
+ wp_clear_scheduled_hook( $timestamp, 'mycred_banking_interest_payout' );
61
+ }
62
+
63
+ /**
64
+ * Process
65
+ * Determines if we should run a payout or not and schedule the daily
66
+ * compounding.
67
+ * @since 1.2
68
+ * @version 1.0
69
+ */
70
+ public function process() {
71
+ // Unschedule if amount is set to zero
72
+ if ( $this->prefs['rate']['amount'] == $this->core->zero() ) {
73
+ $timestamp = wp_next_scheduled( 'mycred_banking_interest_compound' );
74
+ if ( $timestamp !== false )
75
+ wp_clear_scheduled_hook( $timestamp, 'mycred_banking_interest_compound' );
76
+ }
77
+
78
+ // Schedule if none exist
79
+ if ( ! wp_next_scheduled( 'mycred_banking_interest_compound' ) ) {
80
+ wp_schedule_event( time(), 'daily', 'mycred_banking_interest_compound' );
81
+ }
82
+
83
+ $unow = date_i18n( 'U' );
84
+ // Cant pay interest on zero
85
+ if ( $this->prefs['rate']['amount'] == $this->core->zero() ) return;
86
+
87
+ // Should we payout
88
+ $payout_now = $this->get_now( $this->prefs['rate']['pay_out'] );
89
+ if ( empty( $this->prefs['last_payout'] ) || $this->prefs['last_payout'] === NULL ) {
90
+ $last_payout = $this->get_last_run( $unow, $this->prefs['rate']['pay_out'] );
91
+ $this->save( 'last_payout', $unow );
92
+ }
93
+ else {
94
+ $last_payout = $this->get_last_run( $this->prefs['last_payout'], $this->prefs['rate']['pay_out'] );
95
+ }
96
+ if ( $payout_now === false || $last_payout === false ) return;
97
+
98
+ // Time to run?
99
+ if ( $this->time_to_run( $this->prefs['rate']['pay_out'], $last_payout ) ) {
100
+ // Save
101
+ $this->save( 'last_payout', $unow );
102
+
103
+ // Schedule Payouts
104
+ if ( wp_next_scheduled( 'mycred_banking_interest_payout' ) === false )
105
+ wp_schedule_single_event( time(), 'mycred_banking_interest_payout' );
106
+ }
107
+ }
108
+
109
+ /**
110
+ * Do Compound
111
+ * Either runs compounding on every single user in one go, or split the users
112
+ * up into groups of 2000 IDs and do them in batches.
113
+ * @since 1.2
114
+ * @version 1.0
115
+ */
116
+ public function do_compound() {
117
+ if ( $this->prefs['rate']['amount'] == $this->core->zero() ) return;
118
+ // Get users
119
+ $users = $this->get_users();
120
+ $total = count( $users );
121
+ $threshold = (int) apply_filters( 'mycred_do_banking_limit', 2000 );
122
+
123
+ if ( (int) $total > $threshold ) {
124
+ $batches = array_chunk( $users, $threshold );
125
+ $time = time();
126
+
127
+ $set = 0;
128
+ foreach ( $batches as $batch_id => $batch ) {
129
+ $set = $set+1;
130
+ $run_time = ( $time + ( 60*$set ) );
131
+ if ( wp_next_scheduled( $run_time, 'mycred_banking_do_compound_batch', array( $batch ) ) === false )
132
+ wp_schedule_single_event( $run_time, 'mycred_banking_do_compound_batch', array( $batch ) );
133
+ }
134
+ }
135
+ else {
136
+ $this->do_compound_batch( $users );
137
+ }
138
+ }
139
+
140
+ /**
141
+ * Do Compound Batch
142
+ * Compounds interest for each user ID given in batch.
143
+ * @since 1.2
144
+ * @version 1.2.1
145
+ */
146
+ public function do_compound_batch( $batch ) {
147
+ if ( !empty( $batch ) && is_array( $batch ) ) {
148
+
149
+ set_time_limit( $this->prefs['run_time'] );
150
+
151
+ foreach ( $batch as $user_id ) {
152
+ $user_id = intval( $user_id );
153
+
154
+ // Current balance
155
+ $balance = $this->core->get_users_cred( $user_id );
156
+ if ( $balance == 0 ) continue;
157
+
158
+ // Get past interest
159
+ $past_interest = mycred_get_user_meta( $user_id, $this->core->get_cred_id() . '_comp', '', true );
160
+ if ( empty( $past_interest ) ) $past_interest = 0;
161
+
162
+ // Min Balance Limit
163
+ if ( $balance < $this->core->number( $this->prefs['min_balance'] ) ) continue;
164
+
165
+ // Convert rate
166
+ $rate = $this->prefs['rate']['amount']/100;
167
+
168
+ // Period
169
+ $period = $this->prefs['rate']['period']/$this->get_days_in_year();
170
+
171
+ // Compound
172
+ $interest = ( $balance + $past_interest ) * $rate * $period;
173
+ $interest = round( $interest, 2 );
174
+
175
+ // Save interest
176
+ mycred_update_user_meta( $user_id, $this->core->get_cred_id() . '_comp', '', $interest );
177
+ }
178
+ }
179
+ }
180
+
181
+ /**
182
+ * Payout
183
+ * Will either payout to all users in one go or if there is more then
184
+ * 2000 members, do them in batches of 2000 at a time.
185
+ * @since 1.2
186
+ * @version 1.1
187
+ */
188
+ public function do_payouts() {
189
+ // Make sure to clear any stray schedules to prevent duplicates
190
+ wp_clear_scheduled_hook( 'mycred_banking_interest_payout' );
191
+
192
+ // Query
193
+ $users = $this->get_users();
194
+ $total = count( $users );
195
+ $threshold = (int) apply_filters( 'mycred_do_banking_limit', 2000 );
196
+
197
+ if ( (int) $total > $threshold ) {
198
+ $batches = array_chunk( $users, $threshold );
199
+ $time = time();
200
+
201
+ $set = 0;
202
+ foreach ( $batches as $batch_id => $batch ) {
203
+ $set = $set+1;
204
+ $run_time = ( $time + ( 60*$set ) );
205
+ if ( wp_next_scheduled( $run_time, 'mycred_banking_interest_do_batch', array( $batch ) ) === false )
206
+ wp_schedule_single_event( $run_time, 'mycred_banking_interest_do_batch', array( $batch ) );
207
+ }
208
+ }
209
+ else {
210
+ $this->do_interest_batch( $users );
211
+ }
212
+ }
213
+
214
+ /**
215
+ * Do Payout
216
+ * Runs though all user compounded interest and pays.
217
+ * @since 1.2
218
+ * @version 1.2.1
219
+ */
220
+ public function do_interest_batch( $batch ) {
221
+ if ( !empty( $batch ) && is_array( $batch ) ) {
222
+
223
+ set_time_limit( $this->prefs['run_time'] );
224
+
225
+ foreach ( $batch as $user_id ) {
226
+ $user_id = intval( $user_id );
227
+
228
+ // Get past interest
229
+ $past_interest = mycred_get_user_meta( $user_id, $this->core->get_cred_id() . '_comp', '', true );
230
+ if ( empty( $past_interest ) || $past_interest == 0 ) continue;
231
+
232
+ // Pay / Charge
233
+ $this->core->add_creds(
234
+ 'payout',
235
+ $user_id,
236
+ $past_interest,
237
+ $this->prefs['log']
238
+ );
239
+
240
+ // Reset past interest
241
+ mycred_update_user_meta( $user_id, $this->core->get_cred_id() . '_comp', '', 0 );
242
+ }
243
+ }
244
+ }
245
+
246
+ /**
247
+ * Save
248
+ * Saves the given preference id for rates.
249
+ * from the active list.
250
+ * @since 1.2
251
+ * @version 1.1
252
+ */
253
+ public function save( $id, $now ) {
254
+ if ( !isset( $this->prefs[ $id ] ) ) return;
255
+ $this->prefs[ $id ] = $now;
256
+
257
+ // Get Bank settings
258
+ $bank = mycred_get_option( 'mycred_pref_bank' );
259
+
260
+ // Update settings
261
+ $bank['service_prefs'][$this->id] = $this->prefs;
262
+
263
+ // Save new settings
264
+ mycred_update_option( 'mycred_pref_bank', $bank );
265
+ }
266
+
267
+ /**
268
+ * Preference for Savings
269
+ * @since 1.2
270
+ * @version 1.2
271
+ */
272
+ public function preferences() {
273
+ $prefs = $this->prefs; ?>
274
+
275
+ <label class="subheader"><?php _e( 'Interest Rate', 'mycred' ); ?></label>
276
+ <ol class="inline">
277
+ <li>
278
+ <label>&nbsp;</label>
279
+ <div class="h2"><input type="text" name="<?php echo $this->field_name( array( 'rate' => 'amount' ) ); ?>" id="<?php echo $this->field_id( array( 'rate' => 'amount' ) ); ?>" value="<?php echo $this->core->format_number( $prefs['rate']['amount'] ); ?>" size="4" /> %</div>
280
+ </li>
281
+ <li>
282
+ <label for="<?php echo $this->field_id( array( 'rate' => 'pay_out' ) ); ?>"><?php _e( 'Payed / Charged', 'mycred' ); ?></label><br />
283
+ <?php $this->timeframe_dropdown( array( 'rate' => 'pay_out' ), false, false ); ?>
284
+
285
+ </li>
286
+ <li class="block">
287
+ <input type="hidden" name="<?php echo $this->field_name( 'last_payout' ); ?>" value="<?php echo $prefs['last_payout']; ?>" />
288
+ <span class="description"><?php _e( 'The interest rate can be either positive or negative and is compounded daily.', 'mycred' ); ?></span>
289
+ </li>
290
+ </ol>
291
+ <label class="subheader"><?php _e( 'Minimum Balance', 'mycred' ); ?></label>
292
+ <ol>
293
+ <li>
294
+ <div class="h2"><?php if ( $this->core->before != '' ) echo $this->core->before . ' '; ?><input type="text" name="<?php echo $this->field_name( 'min_balance' ); ?>" id="<?php echo $this->field_id( 'min_balance' ); ?>" value="<?php echo $this->core->format_number( $prefs['min_balance'] ); ?>" size="8" /><?php if ( $this->core->after != '' ) echo ' ' . $this->core->after; ?></div>
295
+ <span class="description"><?php _e( 'The minimum requires balance for interest to apply.', 'mycred' ); ?></span>
296
+ </li>
297
+ </ol>
298
+ <label class="subheader"><?php _e( 'Log Template', 'mycred' ); ?></label>
299
+ <ol>
300
+ <li>
301
+ <div class="h2"><input type="text" name="<?php echo $this->field_name( 'log' ); ?>" id="<?php echo $this->field_id( 'log' ); ?>" value="<?php echo $prefs['log']; ?>" style="width: 65%;" /></div>
302
+ <span class="description"><?php echo $this->core->available_template_tags( array( 'general' ), '%timeframe%, %rate%, %base%' ); ?></span>
303
+ </li>
304
+ </ol>
305
+ <label class="subheader" for="<?php echo $this->field_id( 'run_time' ); ?>"><?php _e( 'Run Time', 'mycred' ); ?></label>
306
+ <ol>
307
+ <li>
308
+ <div class="h2"><input type="text" name="<?php echo $this->field_name( 'run_time' ); ?>" id="<?php echo $this->field_id( 'run_time' ); ?>" value="<?php echo $prefs['run_time']; ?>" size="4" /></div>
309
+ <span class="description"><?php _e( 'For large websites, if you are running into time out issues during payouts, you can set the number of seconds a process can run. Use zero for unlimited, but be careful especially if you are on a shared server.', 'mycred' ); ?></span>
310
+ </li>
311
+ </ol>
312
+ <?php do_action( 'mycred_banking_compound_interest', $this->prefs ); ?>
313
+ <?php
314
+ }
315
+
316
+ /**
317
+ * Sanitise Preferences
318
+ * @since 1.2
319
+ * @version 1.2
320
+ */
321
+ function sanitise_preferences( $post ) {
322
+ $new_settings = $post;
323
+
324
+ $new_settings['rate']['amount'] = str_replace( ',', '.', trim( $post['rate']['amount'] ) );
325
+
326
+ $new_settings['rate']['period'] = $this->get_days_in_year();
327
+
328
+ $new_settings['rate']['pay_out'] = sanitize_text_field( $post['rate']['pay_out'] );
329
+
330
+ $new_settings['min_balance'] = str_replace( ',', '.', trim( $post['min_balance'] ) );
331
+
332
+ $new_settings['last_payout'] = trim( $post['last_payout'] );
333
+
334
+ $new_settings['log'] = trim( $post['log'] );
335
+
336
+ $post['run_time'] = abs( $post['run_time'] );
337
+ $new_settings['run_time'] = sanitize_text_field( $post['run_time'] );
338
+
339
+ return apply_filters( 'mycred_banking_save_interest', $new_settings, $this->prefs );
340
+ }
341
+ }
342
+ }
343
+
344
+ ?>
addons/banking/services/mycred-bank-service-payouts.php ADDED
@@ -0,0 +1,308 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * myCRED Bank Service - Recurring Payouts
4
+ * @since 1.2
5
+ * @version 1.1
6
+ */
7
+ if ( !defined( 'myCRED_VERSION' ) ) exit;
8
+
9
+ if ( !class_exists( 'myCRED_Banking_Service_Payouts' ) ) {
10
+ class myCRED_Banking_Service_Payouts extends myCRED_Service {
11
+
12
+ /**
13
+ * Construct
14
+ */
15
+ function __construct( $service_prefs ) {
16
+ parent::__construct( array(
17
+ 'id' => 'payouts',
18
+ 'defaults' => array(
19
+ 'amount' => 10,
20
+ 'rate' => 'daily',
21
+ 'log' => __( 'Daily %_plural%', 'mycred' ),
22
+ 'excludes' => '',
23
+ 'cycles' => 0,
24
+ 'last_run' => '',
25
+ 'run_time' => 60
26
+ )
27
+ ), $service_prefs );
28
+ }
29
+
30
+ /**
31
+ * Run
32
+ * @since 1.2
33
+ * @version 1.0
34
+ */
35
+ public function run() {
36
+ add_action( 'wp_loaded', array( $this, 'process' ) );
37
+ add_action( 'mycred_banking_recurring_payout', array( $this, 'do_payouts' ) );
38
+ add_action( 'mycred_banking_do_batch', array( $this, 'do_payout_batch' ), 10, 3 );
39
+ }
40
+
41
+ /**
42
+ * Deactivation
43
+ * @since 1.2
44
+ * @version 1.0
45
+ */
46
+ public function deactivate() {
47
+ // Unschedule payouts
48
+ wp_clear_scheduled_hook( 'mycred_banking_recurring_payout' );
49
+ }
50
+
51
+ /**
52
+ * Process
53
+ * Determines if we should run a payout or not.
54
+ * @since 1.2
55
+ * @version 1.1
56
+ */
57
+ public function process() {
58
+ // Get cycles
59
+ $cycles = (int) $this->prefs['cycles'];
60
+ // Zero cycles left, bail
61
+ if ( $cycles == 0 ) return;
62
+
63
+ // No amount = no payout
64
+ if ( !isset( $this->prefs['amount'] ) || $this->prefs['amount'] == 0 ) return;
65
+
66
+ $unow = date_i18n( 'U' );
67
+ $now = $this->get_now( $this->prefs['rate'] );
68
+ // No last run, save now as last run
69
+ if ( empty( $this->prefs['last_run'] ) || $this->prefs['last_run'] === NULL ) {
70
+ $last_run = $this->get_last_run( $unow, $this->prefs['rate'] );
71
+ $this->save( $unow, $cycles );
72
+ }
73
+ // Last run
74
+ else {
75
+ $last_run = $this->get_last_run( $this->prefs['last_run'], $this->prefs['rate'] );
76
+ }
77
+ // If now or last run returns false bail
78
+ if ( $now === false || $last_run === false ) return;
79
+
80
+ // Is it time to run?
81
+ if ( $this->time_to_run( $this->prefs['rate'], $last_run ) ) {
82
+ // Cycles (-1 means no limit)
83
+ if ( $cycles > 0-1 ) {
84
+ $cycles = $cycles-1;
85
+ }
86
+ // Save
87
+ $this->save( $unow, $cycles );
88
+
89
+ // Schedule payouts
90
+ if ( wp_next_scheduled( 'mycred_banking_recurring_payout', array( $cycles ) ) === false )
91
+ wp_schedule_single_event( time(), 'mycred_banking_recurring_payout', array( $cycles ) );
92
+ }
93
+ }
94
+
95
+ /**
96
+ * Payout
97
+ * In this first step, we start by gathering all user ID's.
98
+ * If the amount is higher then our threshold, we split up the ID's
99
+ * into batches and schedule then seperate. This is due to the maximum
100
+ * execution limit which will not be enough to handle a lot of users in one go.
101
+ * @since 1.2
102
+ * @version 1.1
103
+ */
104
+ public function do_payouts( $cycle = NULL ) {
105
+ // Make sure to clear any stray schedules to prevent duplicates
106
+ wp_clear_scheduled_hook( 'mycred_banking_recurring_payout' );
107
+
108
+ // Query
109
+ $users = $this->get_users();
110
+ $total = count( $users );
111
+ $threshold = (int) apply_filters( 'mycred_do_banking_limit', 2000 );
112
+
113
+ // If we are over the threshold we need to batch
114
+ if ( (int) $total > $threshold ) {
115
+ $batches = array_chunk( $users, $threshold );
116
+ $time = time();
117
+
118
+ $set = 0;
119
+ foreach ( $batches as $batch_id => $batch ) {
120
+ $set = $set+1;
121
+ // Run time = current time + 60 seconds for each set
122
+ $run_time = ( $time + ( 60*$set ) );
123
+ if ( wp_next_scheduled( $run_time, 'mycred_banking_do_batch', array( $batch, $set, $cycle ) ) === false )
124
+ wp_schedule_single_event( $run_time, 'mycred_banking_do_batch', array( $batch, $set, $cycle ) );
125
+ }
126
+ set_transient( 'mycred_banking_num_payout_batches', $set, HOUR_IN_SECONDS );
127
+ }
128
+ // Run single batch now
129
+ else {
130
+ $this->do_payout_batch( $users, NULL, $cycle );
131
+ }
132
+ }
133
+
134
+ /**
135
+ * Do Batch
136
+ * Applies points to a batch of user ID's. This is also where we check for exclusions.
137
+ * @since 1.2
138
+ * @version 1.2.1
139
+ */
140
+ public function do_payout_batch( $batch, $set = NULL, $cycle = NULL ) {
141
+ if ( !empty( $batch ) && is_array( $batch ) ) {
142
+
143
+ set_time_limit( $this->prefs['run_time'] );
144
+
145
+ foreach ( $batch as $user_id ) {
146
+ $user_id = intval( $user_id );
147
+
148
+ // Add / Deduct points
149
+ $this->core->update_users_balance( $user_id, $this->prefs['amount'] );
150
+ $this->core->add_to_log(
151
+ 'payout',
152
+ $user_id,
153
+ $this->prefs['amount'],
154
+ $this->prefs['log']
155
+ );
156
+ }
157
+ // If multiple sets, check if this is the last one to deactivate
158
+ if ( $set !== NULL ) {
159
+ $total = get_transient( 'mycred_banking_num_payout_batches' );
160
+ if ( $total !== false && $set == $total ) {
161
+ delete_transient( 'mycred_banking_num_payout_batches' );
162
+
163
+ if ( $cycle == 0 )
164
+ $this->save( date_i18n( 'U' ), 0, true );
165
+ }
166
+ }
167
+ // Single set, check if cycle is zero to deactivate
168
+ elseif ( $set === NULL && $cycle == 0 )
169
+ $this->save( date_i18n( 'U' ), 0, true );
170
+ }
171
+ }
172
+
173
+ /**
174
+ * Save
175
+ * Saves the last run and the number of cycles run.
176
+ * @since 1.2
177
+ * @version 1.1.1
178
+ */
179
+ public function save( $now = 0, $cycles = 0, $deactivate = false ) {
180
+ // Update last run
181
+ $this->prefs['last_run'] = $now;
182
+ // Update cycles count
183
+ $this->prefs['cycles'] = $cycles;
184
+
185
+ // Get Bank settings
186
+ $bank = get_option( 'mycred_pref_bank' );
187
+
188
+ // Update settings
189
+ $bank['service_prefs'][ $this->id ] = $this->prefs;
190
+
191
+ // Deactivate this service if this is the last run
192
+ if ( $cycles == 0 && $deactivate ) {
193
+ // Should return the service id as a key for us to unset
194
+ if ( ( $key = array_search( $this->id, $bank['active'] ) ) !== false ) {
195
+ unset( $bank['active'][ $key ] );
196
+ }
197
+ }
198
+
199
+ // Save new settings
200
+ update_option( 'mycred_pref_bank', $bank );
201
+ }
202
+
203
+ /**
204
+ * Preference for Savings
205
+ * @since 1.2
206
+ * @version 1.1
207
+ */
208
+ public function preferences() {
209
+ $prefs = $this->prefs;
210
+
211
+ // Last run
212
+ $last_run = $prefs['last_run'];
213
+ if ( empty( $last_run ) )
214
+ $last_run = __( 'Not yet run', 'mycred' );
215
+ else
216
+ $last_run = date_i18n( get_option( 'date_format' ) . ' : ' . get_option( 'time_format' ), $last_run ); ?>
217
+
218
+
219
+ <label class="subheader"><?php _e( 'Pay Users', 'mycred' ); ?></label>
220
+ <ol class="inline">
221
+ <li>
222
+ <label><?php _e( 'Amount', 'mycred' ); ?></label>
223
+ <div class="h2"><?php if ( !empty( $this->core->before ) ) echo $this->core->before . ' '; ?><input type="text" name="<?php echo $this->field_name( 'amount' ); ?>" id="<?php echo $this->field_id( 'amount' ); ?>" value="<?php echo $this->core->format_number( $prefs['amount'] ); ?>" size="8" /><?php if ( !empty( $this->core->after ) ) echo ' ' . $this->core->after; ?></div>
224
+ <span class="description"><?php _e( 'Can not be zero.', 'mycred' ); ?></span>
225
+ <input type="hidden" name="<?php echo $this->field_name( 'last_run' ); ?>" value="<?php echo $prefs['last_run']; ?>" />
226
+ </li>
227
+ <li>
228
+ <label for="<?php echo $this->field_id( 'rate' ); ?>"><?php _e( 'Interval', 'mycred' ); ?></label><br />
229
+ <?php $this->timeframe_dropdown( 'rate', false ); ?>
230
+
231
+ </li>
232
+ <li>
233
+ <label><?php _e( 'Cycles', 'mycred' ); ?></label>
234
+ <div class="h2"><input type="text" name="<?php echo $this->field_name( 'cycles' ); ?>" id="<?php echo $this->field_id( 'cycles' ); ?>" value="<?php echo $prefs['cycles']; ?>" size="8" /></div>
235
+ <span class="description"><?php _e( 'Set to -1 for unlimited', 'mycred' ); ?></span>
236
+ </li>
237
+ <li>
238
+ <label><?php _e( 'Last Run / Activated', 'mycred' ); ?></label><br />
239
+ <div class="h2"><?php echo $last_run; ?></div>
240
+ </li>
241
+ <li class="block"><strong><?php _e( 'Interval', 'mycred' ); ?></strong><br /><?php echo $this->core->template_tags_general( __( 'Select how often you want to award %_plural%. Note that when this service is enabled, the first payout will be in the beginning of the next period. So with a "Daily" interval, the first payout will occur first thing in the morning.', 'mycred' ) ); ?></li>
242
+ <li class="block"><strong><?php _e( 'Cycles', 'mycred' ); ?></strong><br /><?php _e( 'Cycles let you choose how many intervals this service should run. Each time a cycle runs, the value will decrease until it hits zero, in which case this service will deactivate itself. Use -1 to run unlimited times.', 'mycred' ); ?></li>
243
+ <li class="block"><strong><?php _e( 'Important', 'mycred' ); ?></strong><br /><?php _e( 'You can always stop payouts by deactivating this service. Just remember that if you deactivate while there are cycles left, this service will continue on when it gets re-activated. Set cycles to zero to reset.', 'mycred' ); ?></li>
244
+ </ol>
245
+ <label class="subheader" for="<?php echo $this->field_id( 'excludes' ); ?>"><?php _e( 'Excludes', 'mycred' ); ?></label>
246
+ <ol>
247
+ <li>
248
+ <div class="h2"><input type="text" name="<?php echo $this->field_name( 'excludes' ); ?>" id="<?php echo $this->field_id( 'excludes' ); ?>" value="<?php echo $prefs['excludes']; ?>" style="width: 65%;" /></div>
249
+ <span class="description"><?php _e( 'Comma separated list of user IDs to exclude from this service. No spaces allowed!', 'mycred' ); ?></span>
250
+ </li>
251
+ </ol>
252
+ <label class="subheader" for="<?php echo $this->field_id( 'log' ); ?>"><?php _e( 'Log Template', 'mycred' ); ?></label>
253
+ <ol>
254
+ <li>
255
+ <div class="h2"><input type="text" name="<?php echo $this->field_name( 'log' ); ?>" id="<?php echo $this->field_id( 'log' ); ?>" value="<?php echo $prefs['log']; ?>" style="width: 65%;" /></div>
256
+ <span class="description"><?php echo $this->core->available_template_tags( array( 'general' ) ); ?></span>
257
+ </li>
258
+ </ol>
259
+ <label class="subheader" for="<?php echo $this->field_id( 'run_time' ); ?>"><?php _e( 'Run Time', 'mycred' ); ?></label>
260
+ <ol>
261
+ <li>
262
+ <div class="h2"><input type="text" name="<?php echo $this->field_name( 'run_time' ); ?>" id="<?php echo $this->field_id( 'run_time' ); ?>" value="<?php echo $prefs['run_time']; ?>" size="4" /></div>
263
+ <span class="description"><?php _e( 'For large websites, if you are running into time out issues during payouts, you can set the number of seconds a process can run. Use zero for unlimited, but be careful especially if you are on a shared server.', 'mycred' ); ?></span>
264
+ </li>
265
+ </ol>
266
+ <?php do_action( 'mycred_banking_recurring_payouts', $this->prefs ); ?>
267
+ <?php
268
+ }
269
+
270
+ /**
271
+ * Sanitise Preferences
272
+ * @since 1.2
273
+ * @version 1.1
274
+ */
275
+ function sanitise_preferences( $post ) {
276
+ // Amount
277
+ $new_settings['amount'] = trim( $post['amount'] );
278
+
279
+ // Rate
280
+ $new_settings['rate'] = sanitize_text_field( $post['rate'] );
281
+
282
+ // Cycles
283
+ $new_settings['cycles'] = sanitize_text_field( $post['cycles'] );
284
+
285
+ // Last Run
286
+ $new_settings['last_run'] = $post['last_run'];
287
+ $current_cycles = $this->prefs['cycles'];
288
+ // Moving from -1 or 0 to any higher number indicates a new start. In these cases, we will
289
+ // reset the last run timestamp to prevent this service from running right away.
290
+ if ( ( $current_cycles == 0 || $current_cycles == 0-1 ) && $new_settings['cycles'] > 0 )
291
+ $new_settings['last_run'] = '';
292
+
293
+ // Excludes
294
+ $excludes = str_replace( ' ', '', $post['excludes'] );
295
+ $new_settings['excludes'] = sanitize_text_field( $excludes );
296
+
297
+ // Log
298
+ $new_settings['log'] = trim( $post['log'] );
299
+
300
+ // Run Time
301
+ $post['run_time'] = abs( $post['run_time'] );
302
+ $new_settings['run_time'] = sanitize_text_field( $post['run_time'] );
303
+
304
+ return apply_filters( 'mycred_banking_save_recurring', $new_settings, $this->prefs );
305
+ }
306
+ }
307
+ }
308
+ ?>
addons/banking/services/mycred-service-central.php DELETED
@@ -1,145 +0,0 @@
1
- <?php
2
- if ( ! defined( 'myCRED_VERSION' ) ) exit;
3
-
4
- /**
5
- * myCRED Bank Service - Central Bank
6
- * @since 1.5.2
7
- * @version 1.0.1
8
- */
9
- if ( ! class_exists( 'myCRED_Banking_Service_Central' ) ) :
10
- class myCRED_Banking_Service_Central extends myCRED_Service {
11
-
12
- /**
13
- * Construct
14
- */
15
- function __construct( $service_prefs, $type = MYCRED_DEFAULT_TYPE_KEY ) {
16
-
17
- parent::__construct( array(
18
- 'id' => 'central',
19
- 'defaults' => array(
20
- 'bank_id' => '',
21
- 'ignore_manual' => 1
22
- )
23
- ), $service_prefs, $type );
24
-
25
- }
26
-
27
- /**
28
- * Run
29
- * @since 1.5.2
30
- * @version 1.0
31
- */
32
- public function run() {
33
-
34
- add_filter( 'mycred_add', array( $this, 'mycred_add' ), 1, 3 );
35
-
36
- }
37
-
38
- /**
39
- * Add
40
- * @since 1.5.2
41
- * @version 1.0.1
42
- */
43
- public function mycred_add( $reply, $request, $mycred ) {
44
-
45
- // Make sure we are in the correct point type
46
- if ( $this->mycred_type != $mycred->cred_id || $reply === false ) return $reply;
47
-
48
- // Check manual
49
- if ( isset( $this->prefs['ignore_manual'] ) && $this->prefs['ignore_manual'] == 0 && $request['ref'] == 'manual' ) return $reply;
50
-
51
- // Instances to ignore
52
- if ( in_array( $request['ref'], apply_filters( 'mycred_central_banking_ignore', array( 'interest', 'recurring_payout', 'transfer' ), $this ) ) ) return $reply;
53
-
54
- extract( $request );
55
-
56
- // Make sure that the request is not for our bank account
57
- if ( $user_id == $this->prefs['bank_id'] ) return $reply;
58
-
59
- // Get the banks balance
60
- $bank_balance = $mycred->get_users_balance( $this->prefs['bank_id'], $this->mycred_type );
61
-
62
- // User is to lose points
63
- if ( $amount < 0 ) {
64
-
65
- // Add the points getting deducted to our bank account
66
- $mycred->update_users_balance( $this->prefs['bank_id'], abs( $amount ), $this->mycred_type );
67
-
68
- // Log event
69
- $mycred->add_to_log( $ref, $this->prefs['bank_id'], abs( $amount ), $entry, $ref_id, $data, $this->mycred_type );
70
-
71
- }
72
-
73
- // User is to gain points
74
- else {
75
-
76
- // First make sure the bank is not bust
77
- if ( $bank_balance <= $mycred->zero() ) return false;
78
-
79
- // Second we check if the bank is solvent
80
- if ( $bank_balance-$amount < $mycred->zero() ) return false;
81
-
82
- // If we have come this far, the bank has sufficient funds so lets deduct
83
- $mycred->update_users_balance( $this->prefs['bank_id'], 0-$amount, $this->mycred_type );
84
-
85
- // Log event
86
- $mycred->add_to_log( $ref, $this->prefs['bank_id'], 0-$amount, $entry, $ref_id, $data, $this->mycred_type );
87
-
88
- }
89
-
90
- // Return the result
91
- return $reply;
92
-
93
- }
94
-
95
- /**
96
- * Preference for Central Bank
97
- * @since 1.5.2
98
- * @version 1.1
99
- */
100
- public function preferences() {
101
-
102
- $prefs = $this->prefs;
103
-
104
- ?>
105
- <div class="row">
106
- <div class="col-xs-12">
107
- <div class="row">
108
- <div class="col-sm-4">
109
- <div class="form-group">
110
- <label for="<?php echo $this->field_id( 'bank_id' ); ?>"><?php _e( 'Central Bank Account', 'mycred' ); ?></label>
111
- <input type="text" name="<?php echo $this->field_name( 'bank_id' ); ?>" id="<?php echo $this->field_id( 'bank_id' ); ?>" class="form-control" placeholder="<?php _e( 'Required', 'mycred' ); ?>" value="<?php echo esc_attr( $this->prefs['bank_id'] ); ?>" />
112
- </div>
113
- <p><span class="description"><?php _e( 'The ID of the user representing the central bank.', 'mycred' ); ?></span></p>
114
- </div>
115
- <div class="col-sm-8">
116
- <div class="form-group">
117
- <div class="checkbox"<label for="<?php echo $this->field_id( 'ignore_manual' ); ?>"><input type="checkbox" name="<?php echo $this->field_name( 'ignore_manual' ); ?>" id="<?php echo $this->field_id( 'ignore_manual' ); ?>" value="1"<?php checked( $this->prefs['ignore_manual'], 1 ); ?> /> <?php _e( 'Ignore Manual Adjustments', 'mycred' ); ?></label></div>
118
- </div>
119
- </div>
120
- </div>
121
- </div>
122
- </div>
123
- <?php
124
-
125
- do_action( 'mycred_banking_central', $this );
126
-
127
- }
128
-
129
- /**
130
- * Sanitise Preferences
131
- * @since 1.5.2
132
- * @version 1.1
133
- */
134
- function sanitise_preferences( $post ) {
135
-
136
- $new_settings = array();
137
- $new_settings['bank_id'] = absint( $post['bank_id'] );
138
- $new_settings['ignore_manual'] = ( isset( $post['ignore_manual'] ) ) ? absint( $post['ignore_manual'] ) : 0;
139
-
140
- return apply_filters( 'mycred_banking_save_central', $new_settings, $this );
141
-
142
- }
143
-
144
- }
145
- endif;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
addons/banking/services/mycred-service-interest.php DELETED
@@ -1,691 +0,0 @@
1
- <?php
2
- if ( ! defined( 'myCRED_VERSION' ) ) exit;
3
-
4
- /**
5
- * myCRED Bank Service - Interest
6
- * @since 1.2
7
- * @version 1.2
8
- */
9
- if ( ! class_exists( 'myCRED_Banking_Service_Interest' ) ) :
10
- class myCRED_Banking_Service_Interest extends myCRED_Service {
11
-
12
- public $cron_compound_key = '';
13
- public $cron_payout_key = '';
14
- public $compound_meta_key = '';
15
-
16
- /**
17
- * Construct
18
- */
19
- function __construct( $service_prefs, $type = MYCRED_DEFAULT_TYPE_KEY ) {
20
-
21
- parent::__construct( array(
22
- 'id' => 'interest',
23
- 'defaults' => array(
24
- 'rate' => array(
25
- 'amount' => 2,
26
- 'pay_out' => 'monthly'
27
- ),
28
- 'log' => __( '%plural% interest rate payment', 'mycred' ),
29
- 'min_balance' => 1,
30
- 'exclude_ids' => '',
31
- 'exclude_roles' => array()
32
- )
33
- ), $service_prefs, $type );
34
-
35
- $this->cron_compound_key = 'mycred_bank_interest_comp' . $type;
36
- $this->cron_payout_key = 'mycred_bank_interest_pay' . $type;
37
- $this->compound_meta_key = $type . '_comp';
38
- $this->log_reference = apply_filters( 'mycred_bank_interest_reference', 'interest', $this );
39
-
40
- }
41
-
42
- /**
43
- * Deactivate Service
44
- * Used if the service is no longer reach the minimum requirements or when the
45
- * service is disabled in the admin area.
46
- * @since 1.5.2
47
- * @version 1.1
48
- */
49
- public function deactivate() {
50
-
51
- $timestamp = wp_next_scheduled( $this->cron_compound_key );
52
- if ( $timestamp !== false )
53
- wp_clear_scheduled_hook( $this->cron_compound_key );
54
-
55
- $timestamp = wp_next_scheduled( $this->cron_payout_key );
56
- if ( $timestamp !== false )
57
- wp_clear_scheduled_hook( $this->cron_payout_key );
58
-
59
- }
60
-
61
- /**
62
- * Is Ready
63
- * Checks to make sure the most common "bugs" users experience with this service
64
- * are taken care of. An empty log or empty interest rate will not work.
65
- * @since 1.7
66
- * @version 1.0
67
- */
68
- protected function is_ready() {
69
-
70
- $rate = $this->prefs['rate']['amount'];
71
- if ( strlen( $rate ) == 0 ) return false;
72
-
73
- $log = $this->prefs['log'];
74
- if ( strlen( $log ) == 0 ) return false;
75
-
76
- return true;
77
-
78
- }
79
-
80
- /**
81
- * Run
82
- * Actions taken during WordPress init. Hooks into the cron jobs and schedules
83
- * the cron jobs if not scheduled. Will only run if service is enabled.
84
- * @since 1.2
85
- * @version 1.1
86
- */
87
- public function run() {
88
-
89
- // Make sure we can run this service
90
- if ( ! $this->is_ready() ) {
91
-
92
- $this->deactivate();
93
- return;
94
-
95
- }
96
-
97
- add_action( 'mycred_bank_interest_comp' . $this->mycred_type, array( $this, 'do_compounding' ), 10 );
98
- add_action( 'mycred_bank_interest_pay' . $this->mycred_type, array( $this, 'do_interest_payout' ), 10 );
99
-
100
- $now = $this->now;
101
-
102
- // Make sure there is a compounding scheduled
103
- $compound = wp_next_scheduled( $this->cron_compound_key );
104
- if ( $compound === false )
105
- wp_schedule_single_event( $now + 600, $this->cron_compound_key );
106
-
107
- // Make sure there is a compounding scheduled
108
- $payout = wp_next_scheduled( $this->cron_payout_key );
109
- if ( $payout === false ) {
110
-
111
- $now += mycred_banking_get_next_payout( $this->prefs['rate']['pay_out'] );
112
- wp_schedule_single_event( $now, $this->cron_payout_key );
113
-
114
- }
115
-
116
- add_action( 'personal_options_update', array( $this, 'save_custom_rate' ), 30 );
117
- add_action( 'edit_user_profile_update', array( $this, 'save_custom_rate' ), 30 );
118
-
119
- }
120
-
121
- /**
122
- * Do Interest Compounding
123
- * Compounds interest on balances each day.
124
- * @since 1.5.2
125
- * @version 1.1
126
- */
127
- public function do_compounding() {
128
-
129
- global $wpdb;
130
-
131
- $limit = '';
132
- $select = "user_id, meta_value as value";
133
-
134
- // Default number of balances we will be running through for now
135
- $number = absint( apply_filters( 'mycred_compound_max_limit', 1500, $this ) );
136
-
137
- // On large sites, we need to do this in batches
138
- if ( $this->is_large_site() ) {
139
-
140
- // Schedule our next event in 2 minutes
141
- wp_schedule_single_event( ( $this->now + 180 ), $this->cron_compound_key );
142
-
143
- $transient_key = 'mycred-compoun-' . $this->mycred_type;
144
- $offset = get_transient( $transient_key );
145
-
146
- // Apply limit and set a transient to keep track of our progress
147
- if ( $offset === false ) {
148
-
149
- set_transient( $transient_key, $number, HOUR_IN_SECONDS );
150
- $limit = "LIMIT 0,{$number}";
151
-
152
- }
153
-
154
- // While in loop, we need to keep track of our progress
155
- else {
156
-
157
- delete_transient( $transient_key );
158
- set_transient( $transient_key, $offset + $number, HOUR_IN_SECONDS );
159
- $limit = "LIMIT {$offset},{$number}";
160
-
161
- }
162
-
163
- // Save total rows so we can check when we are finished
164
- $select = "SQL_CALC_FOUND_ROWS " . $select;
165
-
166
- // Used to store the time at which tomorrows run should be running
167
- $original_start = get_option( 'mycred_todays_compound_started', false );
168
- if ( $original_start === false )
169
- update_option( 'mycred_todays_compound_started', $this->now );
170
-
171
- }
172
-
173
- // Should be able to run through 1500 users on most sites
174
- else {
175
- wp_schedule_single_event( ( $this->now + DAY_IN_SECONDS ), $this->cron_compound_key );
176
- }
177
-
178
- $format = '%d';
179
- if ( $this->core->format['decimals'] > 0 )
180
- $format = '%f';
181
-
182
- $wheres = array();
183
- $wheres[] = $wpdb->prepare( "meta_key = %s", $this->mycred_type );
184
- $wheres[] = $wpdb->prepare( "meta_value != {$format}", $this->core->zero() );
185
-
186
- // Check if we need to exclude certain users
187
- $excluded = $this->get_excluded_user_ids();
188
- if ( ! empty( $excluded ) )
189
- $wheres[] = "user_id NOT IN (" . implode( ', ', $excluded ) . ")";
190
-
191
- // Apply minimum balance requirement (if used)
192
- $minimum = ( ( $this->prefs['min_balance'] != '' ) ? $this->core->number( $this->prefs['min_balance'] ) : 0 );
193
- if ( $minimum > 0 )
194
- $wheres[] = $wpdb->prepare( "meta_value >= {$format}", $minimum );
195
-
196
- // A few items we need for calculations
197
- $days_in_year = $this->get_days_in_year();
198
- $period = apply_filters( 'mycred_compound_period', 1, $this );
199
- if ( $period > 0 ) $period = ( $period / $days_in_year );
200
-
201
- // Get the balance key
202
- $balance_key = mycred_get_meta_key( $this->mycred_type );
203
-
204
- // Construct the WHERE statement
205
- $wheres = implode( ' AND ', $wheres );
206
-
207
- // Run query
208
- $user_balances = $wpdb->get_results( "SELECT {$select} FROM {$wpdb->usermeta} WHERE {$wheres} ORDER BY umeta_id ASC {$limit};" );
209
-
210
- if ( ! empty( $user_balances ) ) {
211
-
212
- // Loop through each balance
213
- foreach ( $user_balances as $entry ) {
214
-
215
- $balance = (float) $entry->value;
216
-
217
- // Do not apply an interest on negative values
218
- if ( $balance <= $this->core->zero() && apply_filters( 'mycred_compound_negative_interest', false, $this ) === false ) continue;
219
-
220
- // Get the interest we have earned up until now
221
- $saved_interest = mycred_get_user_meta( $entry->user_id, $this->compound_meta_key );
222
- if ( $saved_interest == '' ) $saved_interest = 0;
223
-
224
- // Allow customization of the calculated interest
225
- $interest_rate = $this->get_users_interest_rate( $entry->user_id, $this->prefs['rate']['amount'] );
226
- if ( $interest_rate > 0 ) {
227
-
228
- // Compound interest
229
- $interest_rate = $interest_rate / 100;
230
- $interest = ( ( $balance + $saved_interest ) * $interest_rate ) * $period;
231
-
232
- // Save the new interest
233
- mycred_update_user_meta( $entry->user_id, $this->compound_meta_key, '', $interest );
234
-
235
- }
236
-
237
- // NEXT!
238
-
239
- }
240
-
241
- }
242
-
243
- // On large sites, check if we finished.
244
- if ( $limit != '' ) {
245
-
246
- $offset += $number;
247
- $total_rows = $wpdb->get_var( 'SELECT FOUND_ROWS()' );
248
-
249
- if ( count( $user_balances ) < $number || $offset > $total_rows ) {
250
-
251
- // Always clean up after ourselves
252
- delete_transient( $transient_key );
253
-
254
- // Get the time we should have started
255
- $original_start = (int) get_option( 'mycred_todays_compound_started', $this->now );
256
- delete_option( 'mycred_todays_compound_started' );
257
-
258
- // Schedule tomorrows run
259
- wp_schedule_single_event( ( $original_start + DAY_IN_SECONDS ), $this->cron_compound_key );
260
-
261
- }
262
-
263
- }
264
-
265
- }
266
-
267
- /**
268
- * Do Interest Payout
269
- * Handles payouts of pending compounded interests.
270
- * @since 1.5.2
271
- * @version 1.2
272
- */
273
- public function do_interest_payout() {
274
-
275
- global $wpdb;
276
-
277
- $now = $this->now;
278
-
279
- // Default number of balances we will be running through for now
280
- $number = absint( apply_filters( 'mycred_compound_pay_max_limit', 1500, $this ) );
281
- $total_rows = $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(*) FROM {$wpdb->usermeta} WHERE meta_key = %s;", $this->compound_meta_key ) );
282
-
283
- // If we have more then what can handle in one go, schedule in the next run in 2 minutes time
284
- if ( $total_rows > $number ) {
285
-
286
- // Schedule our next event in 2 minutes
287
- wp_schedule_single_event( ( $now + 180 ), $this->cron_payout_key );
288
-
289
- // Used to store the time at which the next run should be running
290
- $original_start = get_option( 'mycred_todays_compound_payout_started', false );
291
- if ( $original_start === false )
292
- update_option( 'mycred_todays_compound_payout_started', $now );
293
-
294
- }
295
-
296
- // Get pending interests
297
- $pending_interests = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM {$wpdb->usermeta} WHERE meta_key = %s LIMIT {$number};", $this->compound_meta_key ) );
298
-
299
- if ( ! empty( $pending_interests ) ) {
300
-
301
- // Loop through each
302
- foreach ( $pending_interests as $entry ) {
303
-
304
- // Make sure the payout is unique
305
- if ( ! $this->core->has_entry( $this->log_reference, $entry->umeta_id, $entry->user_id, '', $this->mycred_type ) ) {
306
-
307
- // Attempt to pay
308
- $payout = $this->core->add_creds(
309
- $this->log_reference,
310
- $entry->user_id,
311
- $entry->meta_value,
312
- $this->prefs['log'],
313
- $entry->umeta_id,
314
- '',
315
- $this->mycred_type
316
- );
317
-
318
- // Payout successfull
319
- if ( $payout ) {
320
- $total_rows--;
321
- mycred_delete_user_meta( $entry->user_id, $this->compound_meta_key );
322
- }
323
-
324
- // NEXT!
325
-
326
- }
327
-
328
- }
329
-
330
- }
331
-
332
- // Nothing more to payout
333
- if ( $total_rows <= 0 ) {
334
-
335
- // Get the time we should have done our scheduling
336
- $original_start = (int) get_option( 'mycred_todays_compound_payout_started', $now );
337
- if ( $original_start != $now )
338
- delete_option( 'mycred_todays_compound_payout_started' );
339
-
340
- // Schedule next run
341
- $next = $original_start + mycred_banking_get_next_payout( $this->prefs['rate']['pay_out'] );
342
- wp_schedule_single_event( $next, $this->cron_payout_key );
343
-
344
- }
345
-
346
- }
347
-
348
- /**
349
- * Get Pending Interest
350
- * Returns the total amount of points that have been compounded but not yet paid out.
351
- * @since 1.7
352
- * @version 1.0
353
- */
354
- protected function get_pending_interest() {
355
-
356
- global $wpdb;
357
-
358
- $amount = $wpdb->get_var( $wpdb->prepare( "SELECT SUM( meta_value ) FROM {$wpdb->usermeta} WHERE meta_key = %s;", $this->compound_meta_key ) );
359
- if ( $amount === NULL ) $amount = 0;
360
-
361
- return $this->core->number( $amount );
362
-
363
- }
364
-
365
- /**
366
- * Get Users Interet Rate
367
- * Takes into account any custom rates that might have been saved for the given user.
368
- * @since 1.7
369
- * @version 1.0
370
- */
371
- public function get_users_interest_rate( $user_id = 0, $default = 0 ) {
372
-
373
- $rate = $default;
374
- $saved = mycred_get_user_meta( $user_id, 'mycred_banking_rate_' . $this->mycred_type );
375
- if ( strlen( $saved ) > 0 )
376
- $rate = $saved;
377
-
378
- return apply_filters( 'mycred_get_users_interest_rate', $rate, $user_id, $default, $this );
379
-
380
- }
381
-
382
- /**
383
- * Settings Screen
384
- * Renders the service settings on the Banking page in the admin area.
385
- * @since 1.2
386
- * @version 1.3
387
- */
388
- public function preferences() {
389
-
390
- $cyear = $cmonth = $cday = $chour = $cminute = $csecond = '';
391
- $pyear = $pmonth = $pday = $phour = $pminute = $psecond = '';
392
- $editable_roles = array_reverse( get_editable_roles() );
393
-
394
- // If scheduled, split the date and time of the cron timestamp
395
- $compound = wp_next_scheduled( $this->cron_compound_key );
396
- if ( $compound !== false ) {
397
-
398
- $compound = $this->timestamp_to_date( $compound );
399
-
400
- $date = date( 'Y-m-d', $compound );
401
- list ( $cyear, $cmonth, $cday ) = explode( '-', $date );
402
-
403
- $time = date( 'H:i:s', $compound );
404
- list ( $chour, $cminute, $cseconds ) = explode( ':', $time );
405
-
406
- }
407
-
408
- // If scheduled, split the date and time of the cron timestamp
409
- $payout = wp_next_scheduled( $this->cron_payout_key );
410
- if ( $payout !== false ) {
411
-
412
- $payout = $this->timestamp_to_date( $payout );
413
-
414
- $date = date( 'Y-m-d', $payout );
415
- list ( $pyear, $pmonth, $pday ) = explode( '-', $date );
416
-
417
- $time = date( 'H:i:s', $payout );
418
- list ( $phour, $pminute, $pseconds ) = explode( ':', $time );
419
-
420
- }
421
-
422
- ?>
423
- <div class="row">
424
- <div class="col-sm-6">
425
-
426
- <table class="widefat fixed striped" cellpadding="0" cellspacing="0">
427
- <thead>
428
- <tr>
429
- <th style="width: 100%;" colspan="4"><?php _e( 'Daily Compound Schedule', 'mycred' ); ?></th>
430
- </tr>
431
- <tr>
432
- <th style="width: 30%;"><?php _e( 'Year', 'mycred' ); ?></th>
433
- <th style="width: 20%;"><?php _e( 'Month', 'mycred' ); ?></th>
434
- <th style="width: 20%;"><?php _e( 'Day', 'mycred' ); ?></th>
435
- <th style="width: 30%;"><?php _e( 'Time', 'mycred' ); ?></th>
436
- </tr>
437
- </thead>
438
- <tbody>
439
- <tr>
440
- <td><input type="text" name="<?php echo $this->field_name( array( 'cron_compound' => 'year' ) ); ?>" id="<?php echo $this->field_id( array( 'cron_compound' => 'year' ) ); ?>" class="form-control" placeholder="<?php echo $cyear; ?>" maxlength="4" size="6" value="" /></td>
441
- <td><input type="text" name="<?php echo $this->field_name( array( 'cron_compound' => 'month' ) ); ?>" id="<?php echo $this->field_id( array( 'cron_compound' => 'month' ) ); ?>" class="form-control" placeholder="<?php echo $cmonth; ?>" maxlength="2" size="4" value="" /></td>
442
- <td><input type="text" name="<?php echo $this->field_name( array( 'cron_compound' => 'day' ) ); ?>" id="<?php echo $this->field_id( array( 'cron_compound' => 'day' ) ); ?>" class="form-control" placeholder="<?php echo $cday; ?>" maxlength="2" size="4" value="" /></td>
443
- <td><?php echo $this->time_select( $this->field_name( array( 'cron_compound' => 'time' ) ), $this->field_id( array( 'cron_compound' => 'time' ) ), $compound ); ?></td>
444
- </tr>
445
- </tbody>
446
- </table>
447
-
448
- </div>
449
- <div class="col-sm-6">
450
-
451
- <table class="widefat fixed striped" cellpadding="0" cellspacing="0">
452
- <thead>
453
- <tr>
454
- <th style="width: 100%;" colspan="4"><?php _e( 'Payout Schedule', 'mycred' ); ?></th>
455
- </tr>
456
- <tr>
457
- <th style="width: 30%;"><?php _e( 'Year', 'mycred' ); ?></th>
458
- <th style="width: 20%;"><?php _e( 'Month', 'mycred' ); ?></th>
459
- <th style="width: 20%;"><?php _e( 'Day', 'mycred' ); ?></th>
460
- <th style="width: 30%;"><?php _e( 'Time', 'mycred' ); ?></th>
461
- </tr>
462
- </thead>
463
- <tbody>
464
- <tr>
465
- <td><input type="text" name="<?php echo $this->field_name( array( 'cron_payout' => 'year' ) ); ?>" id="<?php echo $this->field_id( array( 'cron_payout' => 'year' ) ); ?>" class="form-control" placeholder="<?php echo $pyear; ?>" maxlength="4" size="6" value="" /></td>
466
- <td><input type="text" name="<?php echo $this->field_name( array( 'cron_payout' => 'month' ) ); ?>" id="<?php echo $this->field_id( array( 'cron_payout' => 'month' ) ); ?>" class="form-control" placeholder="<?php echo $pmonth; ?>" maxlength="2" size="4" value="" /></td>
467
- <td><input type="text" name="<?php echo $this->field_name( array( 'cron_payout' => 'day' ) ); ?>" id="<?php echo $this->field_id( array( 'cron_payout' => 'day' ) ); ?>" class="form-control" placeholder="<?php echo $pday; ?>" maxlength="2" size="4" value="" /></td>
468
- <td><?php echo $this->time_select( $this->field_name( array( 'cron_payout' => 'time' ) ), $this->field_id( array( 'cron_payout' => 'time' ) ), $payout ); ?></td>
469
- </tr>
470
- </tbody>
471
- </table>
472
-
473
- </div>
474
- </div>
475
- <div class="row">
476
- <div class="col-sm-6">
477
- <h3><?php _e( 'Setup', 'mycred' ); ?></h3>
478
- <div class="row">
479
- <div class="col-sm-3 col-xs-10">
480
- <div class="form-group">
481
- <label for="<?php echo $this->field_id( array( 'rate' => 'amount' ) ); ?>"><?php _e( 'Interest Rate', 'mycred' ); ?></label>
482
- <input type="text" name="<?php echo $this->field_name( array( 'rate' => 'amount' ) ); ?>" id="<?php echo $this->field_id( array( 'rate' => 'amount' ) ); ?>" class="form-control" placeholder="<?php _e( 'Required', 'mycred' ); ?>" value="<?php echo esc_attr( $this->prefs['rate']['amount'] ); ?>" />
483
- </div>
484
- </div>
485
- <div class="col-xs-1">
486
- <div class="form-group">
487
- <label>&nbsp;</label>
488
- <p class="form-control-static">%</p>
489
- </div>
490
- </div>
491
- <div class="col-sm-4 col-xs-6">
492
- <div class="form-group">
493
- <label for="<?php echo $this->field_id( array( 'name' => 'pay_out' ) ); ?>"><?php _e( 'Payout Frequency', 'mycred' ); ?></label>
494
- <?php $this->timeframe_dropdown( array( 'rate' => 'pay_out' ), false, false ); ?>
495
- </div>
496
- </div>
497
- <div class="col-sm-4 col-xs-6">
498
- <div class="form-group">
499
- <label for="<?php echo $this->field_id( 'min_balance' ); ?>"><?php _e( 'Minimum Balance', 'mycred' ); ?></label>
500
- <input type="text" name="<?php echo $this->field_name( 'min_balance' ); ?>" id="<?php echo $this->field_id( 'min_balance' ); ?>" class="form-control" placeholder="<?php _e( 'Required', 'mycred' ); ?>" value="<?php echo $this->core->number( $this->prefs['min_balance'] ); ?>" />
501
- </div>
502
- </div>
503
- </div>
504
- </div>
505
- <div class="col-sm-6">
506
- <h3><?php _e( 'Payout Log Table', 'mycred' ); ?></h3>
507
- <div class="row">
508
- <div class="col-xs-12">
509
- <div class="form-group">
510
- <label for="<?php echo $this->field_id( 'log' ); ?>"><?php _e( 'Log Template', 'mycred' ); ?></label>
511
- <input type="text" name="<?php echo $this->field_name( 'log' ); ?>" id="<?php echo $this->field_id( 'log' ); ?>" class="form-control" value="<?php echo esc_attr( $this->prefs['log'] ); ?>" />
512
- </div>
513
- </div>
514
- </div>
515
- </div>
516
- </div>
517
- <div class="row">
518
- <div class="col-xs-12">
519
- <p><span class="description"><?php _e( 'Changing the payout period once the service is enabled, will only take effect once the currently scheduled payout runs. To change this, you will also need to adjust the payout schedule above.', 'mycred' ); ?></span></p>
520
- </div>
521
- </div>
522
- <div class="row">
523
- <div class="col-sm-6">
524
- <h3><?php _e( 'Exclude by ID', 'mycred' ); ?></h3>
525
- <div class="row">
526
- <div class="col-xs-12">
527
- <div class="form-group">
528
- <label for="<?php echo $this->field_id( 'exclude_ids' ); ?>"><?php _e( 'Comma separated list of user IDs', 'mycred' ); ?></label>
529
- <input type="text" name="<?php echo $this->field_name( 'exclude_ids' ); ?>" id="<?php echo $this->field_id( 'exclude_ids' ); ?>" class="form-control" placeholder="<?php _e( 'Comma separated list of user IDs', 'mycred' ); ?>" value="<?php echo esc_attr( $this->prefs['exclude_ids'] ); ?>" />
530
- </div>
531
- </div>
532
- </div>
533
- </div>
534
- <div class="col-sm-6">
535
- <h3><?php _e( 'Exclude by Role', 'mycred' ); ?></h3>
536
- <div class="row">
537
- <div class="col-xs-12">
538
- <div class="form-group">
539
- <label for="<?php echo $this->field_id( 'exclude_roles' ); ?>"><?php _e( 'Roles to exclude', 'mycred' ); ?></label>
540
- </div>
541
- <div class="row">
542
- <?php
543
-
544
- foreach ( $editable_roles as $role => $details ) {
545
-
546
- $name = translate_user_role( $details['name'] );
547
-
548
- echo '<div class="col-xs-6"><div class="checkbox"><label for="' . $this->field_id( 'exclude-roles-' . $role ) . '"><input type="checkbox" name="' . $this->field_name( 'exclude_roles][' ) . '" id="' . $this->field_id( 'exclude-roles-' . $role ) . '" value="' . esc_attr( $role ) . '"';
549
- if ( in_array( $role, (array) $this->prefs['exclude_roles'] ) ) echo ' checked="checked"';
550
- echo ' />' . $name . '</label></div></div>';
551
- }
552
-
553
- ?>
554
- </div>
555
- </div>
556
- </div>
557
- </div>
558
- </div>
559
- <?php
560
-
561
- do_action( 'mycred_banking_compound_interest', $this );
562
-
563
- }
564
-
565
- /**
566
- * Sanitise Preferences
567
- * @since 1.2
568
- * @version 1.4
569
- */
570
- public function sanitise_preferences( $post ) {
571
-
572
- $new_settings = array( 'rate' => array() );
573
- $new_settings['rate']['amount'] = str_replace( ',', '.', sanitize_text_field( $post['rate']['amount'] ) );
574
- if ( $new_settings['rate']['amount'] == '' ) $new_settings['rate']['amount'] = 0;
575
-
576
- $new_settings['rate']['pay_out'] = sanitize_text_field( $post['rate']['pay_out'] );
577
-
578
- $new_settings['log'] = sanitize_text_field( $post['log'] );
579
- $new_settings['min_balance'] = $this->core->number( str_replace( ',', '.', sanitize_text_field( $post['min_balance'] ) ) );
580
- $new_settings['exclude_ids'] = sanitize_text_field( $post['exclude_ids'] );
581
-
582
- if ( ! isset( $post['exclude_roles'] ) )
583
- $post['exclude_roles'] = array();
584
-
585
- $new_settings['exclude_roles'] = $post['exclude_roles'];
586
-
587
- $rescheduled = false;
588
-
589
- // Re-schedule compound cron job
590
- if ( $post['cron_compound']['year'] != '' && $post['cron_compound']['month'] != '' && $post['cron_compound']['day'] != '' && $post['cron_compound']['time'] != '' ) {
591
-
592
- $year = absint( $post['cron_compound']['year'] );
593
- $month = zeroise( absint( $post['cron_compound']['month'] ), 2 );
594
- $day = zeroise( absint( $post['cron_compound']['day'] ), 2 );
595
-
596
- $compound = $this->date_to_timestamp( $year . '-' . $month . '-' . $day . ' ' . $post['cron_compound']['time'] . ':00' );
597
- if ( $compound !== false && $compound > $this->now ) {
598
-
599
- $timestamp = wp_next_scheduled( $this->cron_compound_key );
600
- if ( $timestamp !== false ) {
601
- wp_clear_scheduled_hook( $this->cron_compound_key );
602
- $rescheduled = true;
603
- }
604
-
605
- wp_schedule_single_event( $compound, $this->cron_compound_key );
606
-
607
- }
608
-
609
- }
610
-
611
- // Re-schedule payout cron job
612
- if ( $post['cron_payout']['year'] != '' && $post['cron_payout']['month'] != '' && $post['cron_payout']['day'] != '' && $post['cron_payout']['time'] != '' ) {
613
-
614
- $year = absint( $post['cron_payout']['year'] );
615
- $month = zeroise( absint( $post['cron_payout']['month'] ), 2 );
616
- $day = zeroise( absint( $post['cron_payout']['day'] ), 2 );
617
-
618
- $payout = $this->date_to_timestamp( $year . '-' . $month . '-' . $day . ' ' . $post['cron_payout']['time'] . ':00' );
619
- if ( $payout !== false && $payout > $this->now ) {
620
-
621
- $timestamp = wp_next_scheduled( $this->cron_payout_key );
622
- if ( $timestamp !== false ) {
623
- wp_clear_scheduled_hook( $this->cron_payout_key );
624
- $rescheduled = true;
625
- }
626
-
627
- wp_schedule_single_event( $payout, $this->cron_payout_key );
628
-
629
- }
630
-
631
- }
632
-
633
- return apply_filters( 'mycred_banking_save_interest', $new_settings, $this, $rescheduled );
634
-
635
- }
636
-
637
- /**
638
- * User Screen
639
- * @since 1.7
640
- * @version 1.0
641
- */
642
- public function user_screen( $user ) {
643
-
644
- // Only visible to admins
645
- if ( ! mycred_is_admin() ) return;
646
-
647
- $users_rate = mycred_get_user_meta( $user->ID, 'mycred_banking_rate_' . $this->mycred_type );
648
-
649
- ?>
650
- <table class="form-table">
651
- <tr>
652
- <th><label for="compoun-interest-rate-<?php echo $this->mycred_type; ?>"><?php _e( 'Interest Rate', 'mycred' ); echo ' (' . $this->core->plural() . ')'; ?></label></th>
653
- <td>
654
- <input type="text" size="8" name="mycred_interest_rate[<?php echo $this->mycred_type; ?>][rate]" id="compoun-interest-rate-<?php echo $this->mycred_type; ?>" placeholder="<?php echo esc_attr( $this->prefs['rate']['amount'] . ' %' ); ?>" value="<?php echo esc_attr( $users_rate ); ?>" /> %
655
- <p><span class="description"><?php _e( 'Leave empty to pay the default rate.', 'mycred' ); ?></span></p>
656
- </td>
657
- </tr>
658
- </table>
659
- <?php
660
-
661
- }
662
-
663
- /**
664
- * Save User Override
665
- * @since 1.5.2
666
- * @version 1.0.2
667
- */
668
- function save_custom_rate( $user_id ) {
669
-
670
- // Only visible to admins
671
- if ( ! mycred_is_admin() ) return;
672
-
673
- if ( isset( $_POST['mycred_interest_rate'] ) && array_key_exists( $this->mycred_type, $_POST['mycred_interest_rate'] ) ) {
674
-
675
- $rate = sanitize_text_field( $_POST['mycred_interest_rate'][ $this->mycred_type ]['rate'] );
676
- if ( strlen( $rate ) > 0 ) {
677
-
678
- $rate = str_replace( ',', '.', $rate );
679
- if ( $rate != $this->prefs['rate']['amount'] )
680
- mycred_update_user_meta( $user_id, 'mycred_banking_rate_' . $this->mycred_type, '', $rate );
681
- else
682
- mycred_delete_user_meta( $user_id, 'mycred_banking_rate_' . $this->mycred_type );
683
-
684
- }
685
-
686
- }
687
-
688
- }
689
-
690
- }
691
- endif;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
addons/banking/services/mycred-service-payouts.php DELETED
@@ -1,1002 +0,0 @@
1
- <?php
2
- if ( ! defined( 'myCRED_VERSION' ) ) exit;
3
-
4
- /**
5
- * myCRED Bank Service - Recurring Payouts
6
- * @since 1.2
7
- * @version 1.2
8
- */
9
- if ( ! class_exists( 'myCRED_Banking_Service_Payouts' ) ) :
10
- class myCRED_Banking_Service_Payouts extends myCRED_Service {
11
-
12
- public $default_schedule = array();
13
- public $statuses = array();
14
- public $schedules = array();
15
- public $log_reference = '';
16
-
17
- /**
18
- * Construct
19
- */
20
- function __construct( $service_prefs, $type = MYCRED_DEFAULT_TYPE_KEY ) {
21
-
22
- parent::__construct( array(
23
- 'id' => 'payouts',
24
- 'defaults' => array()
25
- ), $service_prefs, $type );
26
-
27
- $this->default_schedule = mycred_get_recurring_payout_defaults();
28
-
29
- $this->statuses = array(
30
- 0 => __( 'Waiting to Start', 'mycred' ),
31
- 1 => __( 'Active', 'mycred' ),
32
- 2 => __( 'Running', 'mycred' ),
33
- 3 => __( 'Finished', 'mycred' ),
34
- 4 => __( 'Stopped', 'mycred' )
35
- );
36
-
37
- $this->schedules = mycred_get_recurring_payout_schedules( $type );
38
- $this->log_reference = apply_filters( 'mycred_bank_recurring_reference', 'recurring', $this );
39
-
40
- }
41
-
42
- /**
43
- * Activate Service
44
- * @since 1.5.2
45
- * @version 1.1
46
- */
47
- public function activate() {
48
-
49
- if ( ! empty( $this->schedules ) ) {
50
- foreach ( $this->schedules as $schedule_id => $setup ) {
51
-
52
- // Status 3 = finished and Status 4 = Stopped
53
- if ( absint( $setup['status'] ) > 2 ) continue;
54
-
55
- $next_run = mycred_banking_get_next_payout( $setup['frequency'], $setup['last_run'] );
56
- $timestamp = wp_next_scheduled( 'mycred-recurring-' . $schedule_id );
57
-
58
- if ( $timestamp !== false )
59
- $next_run = $timestamp;
60
-
61
- // We did not miss our schedule, lets re-schedule
62
- if ( $next_run > $this->now )
63
- wp_schedule_single_event( $next_run, 'mycred-recurring-' . $schedule_id, array( 'id' => $schedule_id ) );
64
-
65
- // Upps, we missed it, clear and disable this setup
66
- else {
67
-
68
- $setup['status'] = 4;
69
- mycred_update_recurring_payout( $schedule_id, $setup, $this->mycred_type );
70
-
71
- if ( $timestamp !== false )
72
- wp_clear_scheduled_hook( 'mycred-recurring-' . $schedule_id, array( 'id' => $schedule_id ) );
73
-
74
- }
75
-
76
- }
77
- }
78
-
79
- }
80
-
81
- /**
82
- * Deactivation
83
- * @since 1.2
84
- * @version 1.1
85
- */
86
- public function deactivate() {
87
-
88
- if ( ! empty( $this->schedules ) ) {
89
- foreach ( $this->schedules as $schedule_id => $setup ) {
90
-
91
- // Status 3 = finished and Status 4 = Stopped
92
- if ( absint( $setup['status'] ) > 2 ) continue;
93
-
94
- wp_clear_scheduled_hook( 'mycred-recurring-' . $schedule_id, array( 'id' => $schedule_id ) );
95
-
96
- }
97
- }
98
-
99
- }
100
-
101
- /**
102
- * Run
103
- * @since 1.2
104
- * @version 1.1
105
- */
106
- public function run() {
107
-
108
- if ( ! empty( $this->schedules ) ) {
109
- foreach ( $this->schedules as $schedule_id => $setup ) {
110
-
111
- // Status 3 = finished and Status 4 = Stopped
112
- if ( absint( $setup['status'] ) > 2 ) continue;
113
-
114
- add_action( 'mycred-recurring-' . $schedule_id, array( $this, 'run_schedule' ) );
115
-
116
- }
117
- }
118
-
119
- }
120
-
121
- /**
122
- * Run Schedule
123
- * @since 1.2
124
- * @version 1.1
125
- */
126
- public function run_schedule( $schedule_id = NULL ) {
127
-
128
- if ( $schedule_id === NULL ) return;
129
-
130
- // Get settings
131
- $setup = mycred_get_recurring_payout( $schedule_id, $this->mycred_type );
132
- $instance = 'mycred-recurring-' . $schedule_id;
133
- $infinite_run = ( ( $setup['runs_remaining'] < 0 ) ? true : false );
134
- $runs_left = absint( $setup['runs_remaining'] );
135
- $next_run = mycred_banking_get_next_payout( $setup['frequency'], $this->now );
136
-
137
- // Need to make sure amount is not zero
138
- if ( $setup['payout'] == '' || $this->core->number( $setup['payout'] ) === $this->core->zero() ) return;
139
-
140
- // No runs remaining - Move to finish
141
- if ( ! $infinite_run && $runs_left === 0 ) {
142
-
143
- $setup['status'] = 3;
144
- $setup['last_run'] = $this->now;
145
-
146
- mycred_update_recurring_payout( $schedule_id, $setup, $this->mycred_type );
147
- wp_clear_scheduled_hook( $instance );
148
-
149
- return;
150
-
151
- }
152
-
153
- // No need to run if the central bank is out of funds
154
- $settings = mycred_get_banking_addon_settings( NULL, $this->mycred_type );
155
- $ignore_central_bank = false;
156
- if ( in_array( 'central', $settings['active'] ) && $setup['ignore_central'] == 1 )
157
- $ignore_central_bank = true;
158
-
159
- // Default number of balances we will be running through for now
160
- $number = absint( apply_filters( 'mycred_recurring_max_limit', 1500, $this ) );
161
- $original_start = get_option( 'mycred-recurring-next-run-' . $schedule_id, false );
162
-
163
- $single_instance = true;
164
- $transient_key = 'mycred-recurring-' . $schedule_id;
165
- $offset = get_transient( $transient_key );
166
- if ( $offset === false ) $offset = 0;
167
-
168
- // Get eligible users
169
- $eligeble_users = $this->get_eligible_users( $number, $offset, $setup );
170
-
171
- // Check if we can do this in a single instance or if we need multiple
172
- if ( ( $eligeble_users['total'] - $offset ) > $number ) {
173
-
174
- $single_instance = false;
175
-
176
- // Schedule our next event in 2 minutes
177
- wp_schedule_single_event( ( $this->now + 180 ), $instance );
178
-
179
- // Apply limit and set a transient to keep track of our progress
180
- if ( $offset === 0 )
181
- set_transient( $transient_key, $number, HOUR_IN_SECONDS );
182
-
183
- // While in loop, we need to keep track of our progress
184
- else {
185
-
186
- delete_transient( $transient_key );
187
- $offset += count( $eligeble_users['results'] );
188
- set_transient( $transient_key, $offset, HOUR_IN_SECONDS );
189
-
190
- }
191
-
192
- if ( $original_start === false )
193
- update_option( 'mycred-recurring-next-run-' . $schedule_id, $next_run );
194
-
195
- }
196
-
197
- // Single instance
198
- else {
199
-
200
- if ( $original_start === false )
201
- $original_start = $next_run;
202
-
203
- else {
204
- delete_transient( $transient_key );
205
- delete_option( 'mycred-recurring-next-run-' . $schedule_id );
206
- }
207
-
208
- wp_schedule_single_event( $original_start, $instance, array( 'id' => $schedule_id ) );
209
-
210
- }
211
-
212
- // Loop through users and payout
213
- $missed = $completed = 0;
214
- if ( ! empty( $eligeble_users['results'] ) ) {
215
-
216
- foreach ( $eligeble_users['results'] as $user_id ) {
217
-
218
- if ( ! $ignore_central_bank ) {
219
-
220
- $paid = $this->core->add_creds(
221
- $this->log_reference,
222
- $user_id,
223
- $setup['payout'],
224
- $setup['log_template'],
225
- 0,
226
- $schedule_id,
227
- $this->mycred_type
228
- );
229
-
230
- }
231
-
232
- // Ignore the central bank and just pay
233
- // Curcumvents any custom code using the mycred_add, mycred_run_this and mycred_add_finished filters.
234
- else {
235
-
236
- $this->core->update_users_balance( $user_id, $setup['payout'], $this->mycred_type );
237
- $this->core->add_to_log(
238
- $this->log_reference,
239
- $user_id,
240
- $setup['payout'],
241
- $setup['log_template'],
242
- 0,
243
- $schedule_id,
244
- $this->mycred_type
245
- );
246
-
247
- $paid = true;
248
-
249
- }
250
-
251
- if ( $paid )
252
- $completed ++;
253
- else
254
- $missed ++;
255
-
256
- }
257
-
258
- }
259
-
260
- if ( $setup['status'] == 0 )
261
- $setup['status'] = 1;
262
-
263
- $setup['total_completed'] = ( $setup['total_completed'] + $completed );
264
- $setup['total_misses'] = ( $setup['total_misses'] + $missed );
265
-
266
- mycred_update_recurring_payout( $schedule_id, $setup, $this->mycred_type );
267
-
268
- // In case we finished, update the schedule and clear the CRON
269
- if ( $single_instance ) {
270
-
271
- if ( ! $infinite_run ) {
272
-
273
- $runs_left--;
274
-
275
- $setup['runs_remaining'] = $runs_left;
276
-
277
- }
278
-
279
- $setup['last_run'] = $this->now;
280
-
281
- if ( ! $infinite_run && $runs_left == 0 )
282
- $setup['status'] = 3;
283
-
284
- mycred_update_recurring_payout( $schedule_id, $setup, $this->mycred_type );
285
-
286
- if ( ! $infinite_run && $runs_left === 0 )
287
- wp_clear_scheduled_hook( $instance );
288
-
289
- }
290
-
291
- }
292
-
293
- /**
294
- * Get Eligible Users
295
- * @since 1.7
296
- * @version 1.0
297
- */
298
- public function get_eligible_users( $number = 0, $offset = 0, $setup ) {
299
-
300
- global $wpdb;
301
-
302
- $query_args = array();
303
- $meta_query = array();
304
-
305
- // Only interested in the user IDs.
306
- $query_args['fields'] = 'ID';
307
- $query_args['orderby'] = 'ID';
308
-
309
- $query_args['number'] = $number;
310
-
311
- if ( $offset > 0 )
312
- $query_args['offset'] = $offset;
313
-
314
- // Limit by minimum balance
315
- if ( $setup['min_balance'] != 0 && $setup['max_balance'] == 0 )
316
- $meta_query[] = array(
317
- 'key' => $this->mycred_type,
318
- 'value' => $this->core->number( $setup['min_balance'] ),
319
- 'compare' => '>=',
320
- 'type' => 'NUMERIC'
321
- );
322
-
323
- // Limit by maximum balance
324
- elseif ( $setup['min_balance'] == 0 && $setup['max_balance'] != 0 )
325
- $meta_query[] = array(
326
- 'key' => $this->mycred_type,
327
- 'value' => $this->core->number( $setup['max_balance'] ),
328
- 'compare' => '<',
329
- 'type' => 'NUMERIC'
330
- );
331
-
332
- // Range
333
- elseif ( $setup['min_balance'] != 0 && $setup['max_balance'] != 0 )
334
- $meta_query[] = array(
335
- 'key' => $this->mycred_type,
336
- 'value' => array( $this->core->number( $setup['min_balance'] ), $this->core->number( $setup['max_balance'] ) ),
337
- 'compare' => 'BETWEEN',
338
- 'type' => 'NUMERIC'
339
- );
340
-
341
- // Limit by id
342
- if ( $setup['id_list'] != '' ) {
343
-
344
- $user_id_list = array();
345
-
346
- $list_of_ids = explode( ',', $setup['id_list'] );
347
- foreach ( $list_of_ids as $user_id ) {
348
- $user_id = absint( trim( $user_id ) );
349
- if ( $user_id !== 0 && ! in_array( $user_id, $clean_ids ) )
350
- $user_id_list[] = $user_id;
351
- }
352
-
353
- // Take into account users that have been excluded via the point type
354
- if ( ! empty( $this->core->exclude['list'] ) ) {
355
- $list_of_ids = explode( ',', $this->core->exclude['list'] );
356
- foreach ( $list_of_ids as $user_id ) {
357
- $user_id = absint( trim( $user_id ) );
358
- if ( $user_id !== 0 && ! in_array( $user_id, $clean_ids ) )
359
- $user_id_list[] = $user_id;
360
- }
361
- }
362
-
363
- if ( ! empty( $user_id_list ) ) {
364
-
365
- if ( $setup['id_exclude'] == 'exclude' )
366
- $query_args['exclude'] = $user_id_list;
367
- else
368
- $query_args['include'] = $user_id_list;
369
-
370
- }
371
-
372
- }
373
-
374
- // Limit by role
375
- if ( ! empty( $setup['role_list'] ) ) {
376
-
377
- $blog_id = 0;
378
- if ( ! mycred_centralize_log() ) {
379
- $blog_id = get_current_blog_id();
380
- $query_args['blog_id'] = $blog_id;
381
- }
382
-
383
- $role_query = array();
384
-
385
- // Exclude by role = role is not x AND role is not y
386
- // Include by role = role is x OR role is y
387
- if ( count( $setup['role_list'] ) > 1 )
388
- $role_query['relation'] = ( ( $setup['role_exclude'] == 'exclude' ) ? 'AND' : 'OR' );
389
-
390
- // Since the "role__in" and "role__not_in" arguments are not available until WordPress 4.4, we just use meta query for this.
391
- foreach ( $setup['role_list'] as $role )
392
- $role_query[] = array(
393
- 'key' => $wpdb->get_blog_prefix( $blog_id ) . 'capabilities',
394
- 'value' => '"' . $role . '"',
395
- 'compare' => ( ( $setup['role_exclude'] == 'exclude' ) ? 'NOT LIKE' : 'LIKE' )
396
- );
397
-
398
- $meta_query[] = $role_query;
399
-
400
- }
401
-
402
-
403
- if ( ! empty( $meta_query ) )
404
- $query_args['meta_query'] = $meta_query;
405
-
406
- $query = new WP_User_Query( $query_args );
407
-
408
- return array(
409
- 'total' => $query->get_total(),
410
- 'results' => $query->get_results()
411
- );
412
-
413
- }
414
-
415
- /**
416
- * Display Schedule Table
417
- * @since 1.7
418
- * @version 1.0
419
- */
420
- public function display_schedule_table( $schedule = NULL ) {
421
-
422
- $content = '';
423
- $date_format = get_option( 'date_format' );
424
- $time_format = get_option( 'time_format' );
425
- $timeframes = mycred_banking_get_timeframes();
426
-
427
- $schedules = mycred_get_recurring_payout_schedules( $this->mycred_type );
428
-
429
- // This function is also used to display just one particular table row
430
- if ( $schedule !== NULL )
431
- $schedules = array( $schedule['id'] => $schedule );
432
-
433
- if ( ! empty( $schedules ) ) {
434
-
435
- ob_start();
436
-
437
- foreach ( $schedules as $schedule_id => $setup ) {
438
-
439
- $setup = shortcode_atts( $this->default_schedule, $setup );
440
- $last_run = $this->timestamp_to_date( $setup['last_run'] );
441
- $next_run = mycred_banking_get_next_payout( $setup['frequency'], $last_run );
442
-
443
- // Pending start
444
- if ( $setup['status'] == 0 ) {
445
- $next_run = date( $date_format . ' ' . $time_format, $last_run );
446
- $last_run = __( 'Not yet started', 'mycred' );
447
- }
448
-
449
- // Running
450
- elseif ( $setup['status'] == 1 ) {
451
- $last_run = date( $date_format . ' ' . $time_format, $last_run );
452
- $next_run = date( $date_format . ' ' . $time_format, $next_run );
453
- }
454
-
455
- // CRON job is running right now
456
- elseif ( $setup['status'] == 2 ) {
457
- $last_run = __( 'Currently Running', 'mycred' );
458
- $next_run = '-';
459
- }
460
-
461
- // Finished or stopped
462
- else {
463
- $last_run = date( $date_format . ' ' . $time_format, $last_run );
464
- $next_run = '-';
465
- }
466
-
467
- ?>
468
- <tr id="schedule-<?php echo $schedule_id; ?>">
469
- <td class="col-job-title">
470
- <div><?php echo esc_attr( $setup['job_title'] ); ?></div>
471
- <div class="row-actions">
472
- <span class="edit"><a href="javascript:void(0);" class="view-recurring-schedule" data-id="<?php echo $schedule_id; ?>" data-title="<?php _e( 'View Schedule', 'mycred' ); ?>"><?php _e( 'View', 'mycred' ); ?></a> | </span> <span class="delete"><a href="javascript:void(0);" class="delete-recurring-schedule" data-id="<?php echo $schedule_id; ?>" data-title="<?php _e( 'Delete Schedule', 'mycred' ); ?>"><?php _e( 'Delete', 'mycred' ); ?></a></span>
473
- </div>
474
- </td>
475
- <td class="col-job-status">
476
- <div><?php if ( array_key_exists( $setup['status'], $this->statuses ) ) echo $this->statuses[ $setup['status'] ]; else echo '-'; ?></div>
477
- </td>
478
- <td class="col-job-frequency">
479
- <div><?php if ( array_key_exists( $setup['frequency'], $timeframes ) ) echo $timeframes[ $setup['frequency'] ]['label']; else echo '-'; ?></div>
480
- </td>
481
- <td class="col-job-last-ran">
482
- <div><?php echo $last_run; ?></div>
483
- </td>
484
- <td class="col-job-next-run">
485
- <div><?php echo $next_run; ?></div>
486
- </td>
487
- </tr>
488
- <?php
489
-
490
- }
491
-
492
- $content = ob_get_contents();
493
- ob_end_clean();
494
-
495
- }
496
-
497
- return $content;
498
-
499
- }
500
-
501
- /**
502
- * View Schedule Form
503
- * @since 1.7
504
- * @version 1.0
505
- */
506
- public function view_schedule_form( $schedule_id, $setup ) {
507
-
508
- $limits = array();
509
- $date_format = get_option( 'date_format' );
510
- $time_format = get_option( 'time_format' );
511
- $timeframes = mycred_banking_get_timeframes();
512
- $settings = mycred_get_banking_addon_settings( NULL, $this->mycred_type );
513
-
514
- global $wpdb;
515
-
516
- $total_payout = $wpdb->get_var( $wpdb->prepare( "SELECT SUM(creds) FROM {$this->core->log_table} WHERE ref = %s AND data = %s;", $this->log_reference, $schedule_id ) );
517
- if ( $total_payout === NULL ) $total_payout = 0;
518
-
519
- $last_run = mycred_gmt_timestamp_to_local( $setup['last_run'] );
520
- $eligeble_users = $this->get_eligible_users( 1, 5, $setup );
521
-
522
- if ( $setup['min_balance'] != 0 )
523
- $limits[] = '<div class="col-xs-6"><p>' . __( 'Min. Balance', 'mycred' ) . ': ' . $this->core->format_creds( $setup['min_balance'] ) . '</p></div>';
524
-
525
- if ( $setup['max_balance'] != 0 )
526
- $limits[] = '<div class="col-xs-6"><p>' . __( 'Max. Balance', 'mycred' ) . ': ' . $this->core->format_creds( $setup['max_balance'] ) . '</p></div>';
527
-
528
- if ( $setup['id_list'] != '' ) {
529
-
530
- if ( $setup['id_exclude'] == 'exclude' )
531
- $limits[] = '<div class="col-xs-6"><p>' . __( 'Exclude Users', 'mycred' ) . ': ' . esc_attr( $setup['id_list'] ) . '</p></div>';
532
- else
533
- $limits[] = '<div class="col-xs-6"><p>' . __( 'Include Users', 'mycred' ) . ': ' . esc_attr( $setup['id_list'] ) . '</p></div>';
534
-
535
- }
536
-
537
- if ( ! empty( $setup['role_list'] ) ) {
538
-
539
- if ( $setup['role_exclude'] == 'exclude' )
540
- $limits[] = '<div class="col-xs-12"><p>' . __( 'Exclude Roles', 'mycred' ) . ': <code>' . implode( '</code>, <code>', $setup['role_list'] ) . '</code></p></div>';
541
- else
542
- $limits[] = '<div class="col-xs-12"><p>' . __( 'Include Roles', 'mycred' ) . ': <code>' . implode( '</code>, <code>', $setup['role_list'] ) . '</code></p></div>';
543
-
544
- }
545
-
546
- ob_start();
547
-
548
- ?>
549
- <div class="padded">
550
- <div class="row">
551
- <div class="col-xs-3">
552
- <div class="form-group">
553
- <label><?php _e( 'ID', 'mycred' ); ?></label>
554
- <p class="form-control-static"><?php echo esc_attr( $schedule_id ); ?></p>
555
- </div>
556
- </div>
557
- <div class="col-xs-6">
558
- <div class="form-group">
559
- <label><?php _e( 'Job Title', 'mycred' ); ?></label>
560
- <p class="form-control-static"><?php echo esc_attr( $setup['job_title'] ); ?></p>
561
- </div>
562
- </div>
563
- <div class="col-xs-3">
564
- <div class="form-group">
565
- <label><?php _e( 'Status', 'mycred' ); ?></label>
566
- <p class="form-control-static"><?php if ( array_key_exists( $setup['status'], $this->statuses ) ) echo $this->statuses[ $setup['status'] ]; else echo '-'; ?></p>
567
- </div>
568
- </div>
569
- </div>
570
- <div class="row">
571
- <div class="col-xs-5">
572
- <div class="form-group">
573
- <label><?php if ( $setup['status'] == 0 ) _e( 'Start Date', 'mycred' ); else _e( 'Last Run', 'mycred' ); ?></label>
574
- <p class="form-control-static"><?php echo date( $date_format . ' ' . $time_format, $last_run ); ?></p>
575
- </div>
576
- </div>
577
- <div class="col-xs-2">
578
- <div class="form-group">
579
- <label><?php _e( 'Eligible', 'mycred' ); ?></label>
580
- <p class="form-control-static"><?php printf( _n( '1 User', '%d Users', $eligeble_users['total'], 'mycred' ), $eligeble_users['total'] ); ?></p>
581
- </div>
582
- </div>
583
- <div class="col-xs-2">
584
- <div class="form-group">
585
- <label><?php _e( 'Runs', 'mycred' ); ?></label>
586
- <p class="form-control-static"><?php echo esc_attr( ( ( $setup['total_runs'] < 0 ) ? __( 'Infinite', 'mycred' ) : $setup['total_runs'] ) ); ?></p>
587
- </div>
588
- </div>
589
- <div class="col-xs-3">
590
- <div class="form-group">
591
- <label><?php _e( 'Payout', 'mycred' ); ?></label>
592
- <p class="form-control-static"><?php printf( '%s / %s', $this->core->format_creds( $setup['payout'] ), $timeframes[ $setup['frequency'] ]['single'] ); ?></p>
593
- </div>
594
- </div>
595
- </div>
596
- <?php if ( ! empty( $limits ) ) : ?>
597
- <div class="row">
598
- <div class="col-xs-12">
599
- <strong><label><?php _e( 'Limits', 'mycred' ); ?>:</label></strong>
600
- <div class="row list">
601
- <?php echo implode( '', $limits ); ?>
602
- </div>
603
- </div>
604
- </div>
605
- <?php endif; ?>
606
- <div class="row">
607
- <div class="col-xs-12">
608
- <?php if ( $setup['ignore_central'] == 1 && in_array( 'central', $settings['active'] ) ) : ?>
609
- <p><strong><?php _e( 'Will payout even if the central bank account has run out of funds.', 'mycred' ); ?></strong></p>
610
- <?php endif; ?>
611
- <table class="widefat fixed striped">
612
- <thead>
613
- <tr>
614
- <th style="width: 25%;"><?php _e( 'Paid Out', 'mycred' ); ?></th>
615
- <th style="width: 25%;"><?php _e( 'Completed', 'mycred' ); ?></th>
616
- <th style="width: 25%;"><?php _e( 'Misses', 'mycred' ); ?> *</th>
617
- <th style="width: 25%;"><?php _e( 'Runs Left', 'mycred' ); ?></th>
618
- </tr>
619
- </thead>
620
- <tbody>
621
- <tr>
622
- <td>
623
- <h1><?php echo $this->core->format_creds( $total_payout ); ?></h1>
624
- </td>
625
- <td>
626
- <h1><?php echo absint( $setup['total_completed'] ); ?></h1>
627
- </td>
628
- <td>
629
- <h1><?php echo absint( $setup['total_misses'] ); ?></h1>
630
- </td>
631
- <td>
632
- <h1><?php echo absint( $setup['runs_remaining'] ); ?></h1>
633
- </td>
634
- </tr>
635
- </tbody>
636
- </table>
637
- <p><span class="description">* <?php _e( 'A miss is when a payout was declined by the plugin. This can be due to custom code declining the payout or if the user is excluded.', 'mycred' ); ?></span></p>
638
- </div>
639
- </div>
640
- </div>
641
- <?php
642
-
643
- $content = ob_get_contents();
644
- ob_end_clean();
645
-
646
- return $content;
647
-
648
- }
649
-
650
- /**
651
- * Manage Schedule Form
652
- * @since 1.7
653
- * @version 1.0
654
- */
655
- public function manage_schedule_form( $schedule_id, $setup ) {
656
-
657
- $year = $month = $day = '';
658
- $time = NULL;
659
-
660
- $timeframes = mycred_banking_get_timeframes();
661
- $compound = wp_next_scheduled( $setup['last_run'] );
662
- $settings = mycred_get_banking_addon_settings( NULL, $this->mycred_type );
663
-
664
- if ( $compound !== false ) {
665
-
666
- $last_run = $this->timestamp_to_date( $setup['last_run'] );
667
-
668
- $date = date( 'Y-m-d', $last_run );
669
- list ( $year, $month, $day ) = explode( '-', $date );
670
-
671
- $time = date( 'H:i', $last_run );
672
-
673
- }
674
-
675
- ob_start();
676
-
677
- ?>
678
- <div class="padded">
679
- <div class="row">
680
- <div class="col-xs-6">
681
- <div class="form-group">
682
- <label><?php _e( 'Schedule Title', 'mycred' ); ?></label>
683
- <input type="text" name="job_title" class="form-control cant-be-empty" value="<?php echo esc_attr( $setup['job_title'] ); ?>" />
684
- </div>
685
- </div>
686
- <div class="col-xs-3">
687
- <div class="form-group">
688
- <label><?php echo $this->core->plural(); ?></label>
689
- <input type="text" name="payout" class="form-control cant-be-empty" placeholder="<?php echo $this->core->zero(); ?>" value="" />
690
- </div>
691
- </div>
692
- <div class="col-xs-3">
693
- <div class="form-group">
694
- <label><?php _e( 'Frequency', 'mycred' ); ?></label>
695
- <select name="frequency" class="form-control">
696
- <?php
697
-
698
- foreach ( $timeframes as $value => $data ) {
699
- echo '<option value="' . $value . '"';
700
- if ( $setup['frequency'] == $value ) echo ' selected="selected"';
701
- echo '>' . $data['label'] . '</option>';
702
- }
703
-
704
- ?>
705
- </select>
706
- </div>
707
- </div>
708
- <div class="col-xs-12">
709
- <div class="form-group">
710
- <label><?php _e( 'Log Template', 'mycred' ); ?></label>
711
- <input type="text" name="log_template" class="form-control cant-be-empty" value="<?php echo esc_attr( $setup['log_template'] ); ?>" />
712
- </div>
713
- <?php if ( in_array( 'central', $settings['active'] ) ) : ?>
714
- <div class="form-group">
715
- <div class="checkbox"><label for="new-schedule-ignore-central-bank"><input type="checkbox" name="ignore_central" id="new-schedule-ignore-central-bank"<?php checked( $setup['ignore_central'], 1 ); ?> value="1" /> <?php _e( 'Payout even if the central bank account runs out of funds.', 'mycred' ); ?></label></div>
716
- </div>
717
- <?php else : ?>
718
- <input type="hidden" name="ignore_central"<?php checked( $setup['ignore_central'], 1 ); ?> value="1" />
719
- <?php endif; ?>
720
- </div>
721
- </div>
722
- <h3><?php _e( 'First Payout', 'mycred' ); ?></h3>
723
- <div class="row">
724
- <div class="col-xs-8">
725
- <div class="row">
726
- <div class="col-xs-3">
727
- <div class="form-group">
728
- <label><?php _e( 'Year', 'mycred' ); ?></label>
729
- <input type="text" name="last_run[year]" class="form-control cant-be-empty" placeholder="YYYY" value="<?php echo esc_attr( $year ); ?>" />
730
- </div>
731
- </div>
732
- <div class="col-xs-3">
733
- <div class="form-group">
734
- <label><?php _e( 'Month', 'mycred' ); ?></label>
735
- <input type="text" name="last_run[month]" class="form-control cant-be-empty" placeholder="MM" value="<?php echo esc_attr( $month ); ?>" />
736
- </div>
737
- </div>
738
- <div class="col-xs-3">
739
- <div class="form-group">
740
- <label><?php _e( 'Date', 'mycred' ); ?></label>
741
- <input type="text" name="last_run[day]" class="form-control cant-be-empty" placeholder="DD" value="<?php echo esc_attr( $day ); ?>" />
742
- </div>
743
- </div>
744
- <div class="col-xs-3">
745
- <div class="form-group">
746
- <label><?php _e( 'Time', 'mycred' ); ?></label>
747
- <?php echo $this->time_select( 'last_run[time]', 'last-run-time', $time ); ?>
748
- </div>
749
- </div>
750
- </div>
751
- </div>
752
- <div class="col-xs-4">
753
- <div class="form-group">
754
- <label><?php _e( 'Repeat', 'mycred' ); ?></label>
755
- <input type="number" name="total_runs" class="form-control" placeholder="0" min="-1" max="256" value="<?php echo esc_attr( $setup['total_runs'] ); ?>" />
756
- <p><span class="description"><?php _e( 'Use -1 for infinite runs.', 'mycred' ); ?></span></p>
757
- </div>
758
- </div>
759
- </div>
760
- <h3><?php _e( 'Limits', 'mycred' ); ?></h3>
761
- <div class="row">
762
- <div class="col-sm-4 col-xs-12">
763
- <div class="row">
764
- <div class="col-sm-12 col-xs-6">
765
- <div class="form-group">
766
- <label><?php _e( 'Min. Balance', 'mycred' ); ?></label>
767
- <input type="number" name="min_balance" class="form-control" placeholder="0" min="0" value="<?php echo esc_attr( $setup['min_balance'] ); ?>" />
768
- <p><span class="description"><?php _e( 'Use zero to disable.', 'mycred' ); ?></span></p>
769
- </div>
770
- </div>
771
- <div class="col-sm-12 col-xs-6">
772
- <div class="form-group">
773
- <label><?php _e( 'Max. Balance', 'mycred' ); ?></label>
774
- <input type="number" name="max_balance" class="form-control" placeholder="0" min="0" value="<?php echo esc_attr( $setup['max_balance'] ); ?>" />
775
- <p><span class="description"><?php _e( 'Use zero to disable.', 'mycred' ); ?></span></p>
776
- </div>
777
- </div>
778
- </div>
779
- </div>
780
- <div class="col-sm-8 col-xs-12">
781
- <div class="row">
782
- <div class="col-sm-5 col-xs-12">
783
- <div class="form-group">
784
- <label><?php _e( 'Limit by ID', 'mycred' ); ?></label>
785
- <?php echo $this->include_exclude_dropdown( 'id_exclude', 'exclude-include-id', $setup['id_exclude'] ); ?>
786
- </div>
787
- </div>
788
- <div class="col-sm-7 col-xs-12">
789
- <div class="form-group">
790
- <label class="xs-hidden">&nbsp;</label>
791
- <input type="text" name="id_list" class="form-control" placeholder="<?php _e( 'Comma separated list of user IDs', 'mycred' ); ?>" value="<?php echo esc_attr( $setup['id_list'] ); ?>" />
792
- </div>
793
- </div>
794
- </div>
795
- <div class="row">
796
- <div class="col-sm-5 col-xs-12">
797
- <div class="form-group">
798
- <label><?php _e( 'Limit by Role(s)', 'mycred' ); ?></label>
799
- <?php echo $this->include_exclude_dropdown( 'role_exclude', 'exclude-include-role', $setup['role_exclude'] ); ?>
800
- </div>
801
- </div>
802
- <div class="col-sm-7 col-xs-12">
803
- <div class="row">
804
- <?php
805
-
806
- $editable_roles = array_reverse( get_editable_roles() );
807
- foreach ( $editable_roles as $role => $details ) {
808
-
809
- $name = translate_user_role( $details['name'] );
810
-
811
- echo '<div class="col-sm-6 col-xs-4"><label for="role-list-' . esc_attr( $role ) . '"><input type="checkbox" name="role_list[]" id="role-list-' . esc_attr( $role ) . '" value="' . esc_attr( $role ) . '"';
812
- if ( in_array( $role, (array) $setup['role_list'] ) ) echo ' checked="checked"';
813
- echo ' />' . $name . '</label></div>';
814
- }
815
-
816
- ?>
817
- </div>
818
- </div>
819
- </div>
820
- </div>
821
- </div>
822
- <div class="row">
823
- <div class="col-xs-12 tr">
824
- <input type="hidden" name="new_id" value="<?php echo $schedule_id; ?>" />
825
- <input type="submit" class="button button-primary" value="<?php _e( 'Schedule', 'mycred' ); ?>" />
826
- </div>
827
- </div>
828
- </div>
829
- <?php
830
-
831
- $content = ob_get_contents();
832
- ob_end_clean();
833
-
834
- return $content;
835
-
836
- }
837
-
838
- /**
839
- * Include Exclude Dropdown
840
- * @since 1.7
841
- * @version 1.0
842
- */
843
- public function include_exclude_dropdown( $name = '', $id = '', $selected = '' ) {
844
-
845
- $options = array(
846
- 'include' => __( 'Include:', 'mycred' ),
847
- 'exclude' => __( 'Exclude:', 'mycred' )
848
- );
849
-
850
- $content = '<select name="' . $name . '" id="' . $id . '" class="form-control">';
851
- foreach ( $options as $value => $label ) {
852
- $content .= '<option value="' . $value . '"';
853
- if ( $selected == $value ) $content .= ' selected="selected"';
854
- $content .= '>' . $label . '</option>';
855
- }
856
- $content .= '</select>';
857
-
858
- return $content;
859
-
860
- }
861
-
862
- /**
863
- * Preference for recurring payouts
864
- * @since 1.2
865
- * @version 1.2
866
- */
867
- public function preferences() {
868
-
869
- $schedules = mycred_get_recurring_payout_schedules( $this->mycred_type );
870
-
871
- ?>
872
- <p><?php _e( 'As long as this service remains disabled, none of your scheduled payouts will run!', 'mycred' ); ?></p>
873
- <div class="row">
874
- <div class="col-xs-12">
875
- <h3><?php _e( 'Schedules', 'mycred' ); ?></h3>
876
- <table class="widefat fixed striped" cellpadding="0" cellspacing="0">
877
- <thead>
878
- <tr>
879
- <th style="width: 25%;"><?php _e( 'Job Title', 'mycred' ); ?></th>
880
- <th style="width: 15%;"><?php _e( 'Status', 'mycred' ); ?></th>
881
- <th style="width: 20%;"><?php _e( 'Frequency', 'mycred' ); ?></th>
882
- <th style="width: 20%;"><?php _e( 'Last Ran', 'mycred' ); ?></th>
883
- <th style="width: 20%;"><?php _e( 'Next Run', 'mycred' ); ?></th>
884
- </tr>
885
- </thead>
886
- <tbody id="recurring-schedule-body">
887
-
888
- <?php echo $this->display_schedule_table(); ?>
889
-
890
- <tr id="no-banking-schedules"<?php if ( ! empty( $schedules ) ) echo ' style="display: none;"'; ?>>
891
- <td colspan="5"><?php _e( 'No schedules found.', 'mycred' ); ?></td>
892
- </tr>
893
- </tbody>
894
- </table>
895
- <input type="hidden" name="<?php echo $this->field_name( 'here' ); ?>" value="1" />
896
- <p style="text-align: right;"><button type="button" id="add-new-schedule" class="button button-secondary"><?php _e( 'Add New', 'mycred' ); ?></button>
897
- </div>
898
- </div>
899
- <?php
900
-
901
- do_action( 'mycred_banking_recurring_payouts', $this );
902
-
903
- }
904
-
905
- /**
906
- * Sanitise Preferences
907
- * @since 1.2
908
- * @version 1.1
909
- */
910
- function sanitise_preferences( $post ) {
911
-
912
- return apply_filters( 'mycred_banking_save_recurring', array(), $this );
913
-
914
- }
915
-
916
- /**
917
- * Ajax Handler
918
- * @since 1.7
919
- * @version 1.0
920
- */
921
- function ajax_handler() {
922
-
923
- parse_str( $_POST['form'], $form );
924
-
925
- // Add new Schedule
926
- if ( empty( $form ) ) {
927
- $new_id = strtolower( wp_generate_password( 6, false, false ) );
928
- wp_send_json_success( array( 'form' => $this->manage_schedule_form( $new_id, $this->default_schedule ), 'table' => false ) );
929
- }
930
-
931
- // Save new Schedule
932
- if ( array_key_exists( 'new_id', $form ) ) {
933
-
934
- $setup = shortcode_atts( $this->default_schedule, $form );
935
-
936
- // Prep start time and convert it into a gmt unix timestamp
937
- $year = absint( $form['last_run']['year'] );
938
- $month = zeroise( absint( $form['last_run']['month'] ), 2 );
939
- $day = zeroise( absint( $form['last_run']['day'] ), 2 );
940
- $time = sanitize_text_field( $form['last_run']['time'] );
941
-
942
- $setup['last_run'] = $this->date_to_timestamp( $year . '-' . $month . '-' . $day . ' ' . $time . ':00' );
943
-
944
- // Attempt to add new payout schedule
945
- $results = mycred_add_new_recurring_payout( $form['new_id'], $setup, $this->mycred_type );
946
-
947
- // Something went wrong
948
- if ( is_wp_error( $results ) ) {
949
- $content = '<div class="alert alert-warning">' . $results->get_error_message() . '</div>';
950
- $content .= $this->manage_schedule_form( $form['new_id'], $setup );
951
- wp_send_json_success( array( 'form' => $content, 'table' => false ) );
952
- }
953
-
954
- $results['id'] = $form['new_id'];
955
- $message = '<div class="alert alert-success">' . __( 'Schedule Added', 'mycred' ) . '</div>';
956
-
957
- $table_row = $this->display_schedule_table( $results );
958
- $eligeble_users = $this->get_eligible_users( 5, 0, $setup );
959
-
960
- // Warn user if no users are eligile for a payout based of their setup
961
- if ( $eligeble_users['total'] == 0 )
962
- $message .= '<div class="padded"><p>' . __( 'While the recurring payout has been successfully saved, based on the limits you set, right now there are no users that are eligible for a payout!', 'mycred' ) . '</p></div>';
963
-
964
- wp_send_json_success( array( 'form' => $message, 'table' => $table_row ) );
965
-
966
- }
967
-
968
- // View existing schedule
969
- elseif ( array_key_exists( 'schedule_id', $form ) ) {
970
-
971
- $schedule_id = sanitize_key( $form['schedule_id'] );
972
- $setup = mycred_get_recurring_payout( $schedule_id, $this->mycred_type );
973
- if ( $setup === false ) {
974
- $content = '<div class="alert alert-warning">' . __( 'Schedule not found. Please refresh this page and try again.', 'mycred' ) . '</div>';
975
- wp_send_json_success( array( 'form' => $content, 'table' => false ) );
976
- }
977
-
978
- wp_send_json_success( array( 'form' => $this->view_schedule_form( $schedule_id, $setup ), 'table' => false ) );
979
-
980
- }
981
-
982
- // Delete existing schedule
983
- elseif ( array_key_exists( 'remove_token', $form ) ) {
984
-
985
- $schedule_id = sanitize_key( $form['remove_token'] );
986
- $setup = mycred_get_recurring_payout( $schedule_id, $this->mycred_type );
987
- if ( $setup === false ) {
988
- $content = '<div class="alert alert-warning">' . __( 'Schedule not found. Please refresh this page and try again.', 'mycred' ) . '</div>';
989
- wp_send_json_success( array( 'form' => $content, 'table' => false ) );
990
- }
991
-
992
- mycred_delete_recurring_payout( $schedule_id, $this->mycred_type );
993
- $content = '<div class="alert alert-success">' . __( 'Schedule Deleted', 'mycred' ) . '</div>';
994
- $content .= "<script type=\"text/javascript\">jQuery(function($) { $( 'tr#schedule-{$schedule_id}' ).remove(); });</script>";
995
- wp_send_json_success( array( 'form' => $content, 'table' => false ) );
996
-
997
- }
998
-
999
- }
1000
-
1001
- }
1002
- endif;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
addons/{badges/assets/js → buddypress}/index.php RENAMED
File without changes
addons/buy-creds/abstracts/mycred-abstract-payment-gateway.php CHANGED
@@ -1713,17 +1713,11 @@ if ( ! class_exists( 'myCRED_Payment_Gateway' ) ) :
1713
  /**
1714
  * Trash Pending Payment
1715
  * @since 1.5.3
1716
- * @version 1.0
1717
  */
1718
  function trash_pending_payment( $payment_id ) {
1719
 
1720
- if ( is_numeric( $payment_id ) )
1721
- $post = get_post( $payment_id );
1722
- else
1723
- $post = get_page_by_title( $payment_id, OBJECT, 'buycred_payment' );
1724
-
1725
- if ( isset( $post->ID ) )
1726
- wp_trash_post( $post->ID );
1727
 
1728
  }
1729
 
1713
  /**
1714
  * Trash Pending Payment
1715
  * @since 1.5.3
1716
+ * @version 1.0.1
1717
  */
1718
  function trash_pending_payment( $payment_id ) {
1719
 
1720
+ return buycred_trash_pending_payment( $payment_id );
 
 
 
 
 
 
1721
 
1722
  }
1723
 
addons/buy-creds/gateways/bank-transfer.php DELETED
@@ -1,260 +0,0 @@
1
- <?php
2
- if ( ! defined( 'myCRED_VERSION' ) ) exit;
3
-
4
- /**
5
- * myCRED_Bank_Transfer class
6
- * Manual payment gateway - bank transfers
7
- * @since 1.7
8
- * @version 1.0
9
- */
10
- if ( ! class_exists( 'myCRED_Bank_Transfer' ) ) :
11
- class myCRED_Bank_Transfer extends myCRED_Payment_Gateway {
12
-
13
- /**
14
- * Construct
15
- */
16
- function __construct( $gateway_prefs ) {
17
-
18
- $types = mycred_get_types();
19
- $default_exchange = array();
20
- foreach ( $types as $type => $label )
21
- $default_exchange[ $type ] = 1;
22
-
23
- parent::__construct( array(
24
- 'id' => 'bank',
25
- 'label' => 'Bank Transfer',
26
- 'gateway_logo_url' => '',
27
- 'defaults' => array(
28
- 'logo' => '',
29
- 'title' => '',
30
- 'account' => '',
31
- 'currency' => 'EUR',
32
- 'exchange' => $default_exchange
33
- )
34
- ), $gateway_prefs );
35
-
36
- }
37
-
38
- /**
39
- * Process Handler
40
- * @since 1.0
41
- * @version 1.0
42
- */
43
- public function process() { }
44
-
45
- /**
46
- * Results Handler
47
- * @since 1.0
48
- * @version 1.0
49
- */
50
- public function returning() {
51
-
52
- add_filter( 'mycred_setup_gateways', array( $this, 'relable_gateway' ) );
53
-
54
- }
55
-
56
- /**
57
- * Admin Init Handler
58
- * @since 1.7
59
- * @version 1.0
60
- */
61
- function admin_init() {
62
-
63
- add_filter( 'mycred_setup_gateways', array( $this, 'relable_gateway' ) );
64
-
65
- }
66
-
67
- /**
68
- * Results Handler
69
- * @since 1.7.6
70
- * @version 1.0
71
- */
72
- public function relable_gateway( $installed ) {
73
-
74
- if ( ! empty( $this->prefs['title'] ) && $this->prefs['title'] != $installed['bank']['title'] )
75
- $installed['bank']['title'] = $this->prefs['title'];
76
-
77
- return $installed;
78
-
79
- }
80
-
81
- /**
82
- * Buy Handler
83
- * @since 1.0
84
- * @version 1.0
85
- */
86
- public function buy() {
87
-
88
- if ( empty( $this->prefs['account'] ) ) wp_die( __( 'Please setup this gateway before attempting to make a purchase!', 'mycred' ) );
89
-
90
- // Prep
91
- $type = $this->get_point_type();
92
- $mycred = mycred( $type );
93
-
94
- $amount = $mycred->number( $_REQUEST['amount'] );
95
- $amount = abs( $amount );
96
-
97
- $cost = $this->get_cost( $amount, $type );
98
- $to = $this->get_to();
99
- $from = get_current_user_id();
100
- $thankyou_url = $this->get_thankyou();
101
-
102
- // Revisiting pending payment
103
- if ( isset( $_REQUEST['revisit'] ) )
104
- $this->transaction_id = strtoupper( sanitize_text_field( $_REQUEST['revisit'] ) );
105
-
106
- // New pending payment
107
- else {
108
- $post_id = $this->add_pending_payment( array( $to, $from, $amount, $cost, $this->prefs['currency'], $type ) );
109
- $this->transaction_id = get_the_title( $post_id );
110
- }
111
-
112
- $cancel_url = $this->get_cancelled( $this->transaction_id );
113
-
114
- // Set Logo
115
- $logo = '';
116
- if ( isset( $this->prefs['logo'] ) && ! empty( $this->prefs['logo'] ) )
117
- $logo = '<img src="' . $this->prefs['logo'] . '" alt="" />';
118
-
119
- elseif ( isset( $this->prefs['logo_url'] ) && ! empty( $this->prefs['logo_url'] ) )
120
- $logo = '<img src="' . $this->prefs['logo_url'] . '" alt="" />';
121
- elseif ( isset( $this->gateway_logo_url ) && ! empty( $this->gateway_logo_url ) )
122
- $logo = '<img src="' . $this->gateway_logo_url . '" alt="" />';
123
-
124
- if ( $this->sandbox_mode )
125
- $title = __( 'Test Payment', 'mycred' );
126
- elseif ( ! empty( $this->prefs['title'] ) )
127
- $title = $this->prefs['title'];
128
- else
129
- $title = __( 'Payment', 'mycred' );
130
-
131
- $this->get_page_header( $title );
132
-
133
- ?>
134
- <div class="row">
135
- <div class="col-lg-12 col-md-12 col-sm-12 col-xs-12">
136
- <table cellpadding="0" cellspacing="0">
137
- <thead>
138
- <tr>
139
- <th id="gateway-order-item" class="order-item"><?php _e( 'Item', 'mycred' ); ?></th>
140
- <th id="gateway-order-amount" class="order-amount"><?php echo $this->core->plural() ?></th>
141
- <th id="gateway-order-cost" class="order-cost"><?php _e( 'Cost', 'mycred' ); ?></th>
142
- <th id="gateway-order-transaction" class="order-transaction"><?php _e( 'Transaction ID', 'mycred' ); ?></th>
143
- </tr>
144
- </thead>
145
- <tbody>
146
- <tr>
147
- <td class="order-item"><?php echo apply_filters( 'mycred_buycred_order_name', sprintf( __( '%s Purchase', 'mycred' ), $this->core->singular() ), $amount, $cost, $this ); ?></td>
148
- <td class="order-amount"><?php echo $amount; ?></td>
149
- <td class="order-cost"><?php echo $cost; ?> <?php if ( isset( $this->prefs['currency'] ) ) echo $this->prefs['currency']; else echo 'USD'; ?></td>
150
- <td class="order-transaction"><?php echo $this->transaction_id; ?></td>
151
- </tr>
152
- </tbody>
153
- </table>
154
- </div>
155
- </div>
156
- <div class="row">
157
- <div class="col-lg-12 col-md-12 col-sm-12 col-xs-12">
158
- <div id="buycred-bank-details">
159
-
160
- <?php echo wptexturize( wpautop( $this->prefs['account'] ) ); ?>
161
-
162
- </div>
163
- </div>
164
- </div>
165
- <div class="row">
166
- <div class="col-lg-12 col-md-12 col-sm-12 col-xs-12">
167
- <div id="buycred-continue">
168
- <p style="text-align:center;"><a href="<?php echo $this->get_thankyou(); ?>"><?php _e( 'Continue', 'mycred' ); ?></a></p>
169
- </div>
170
- </div>
171
- </div>
172
- <?php
173
-
174
- $this->get_page_footer();
175
-
176
- exit;
177
-
178
- }
179
-
180
- /**
181
- * Preferences
182
- * @since 1.0
183
- * @version 1.0
184
- */
185
- function preferences() {
186
-
187
- $prefs = $this->prefs;
188
-
189
- ?>
190
- <label class="subheader" for="<?php echo $this->field_id( 'title' ); ?>"><?php _e( 'Title', 'mycred' ); ?></label>
191
- <ol>
192
- <li>
193
- <div class="h2"><input type="text" name="<?php echo $this->field_name( 'title' ); ?>" id="<?php echo $this->field_id( 'title' ); ?>" value="<?php echo esc_attr( $prefs['title'] ); ?>" class="long" /></div>
194
- </li>
195
- </ol>
196
- <label class="subheader" for="<?php echo $this->field_id( 'logo' ); ?>"><?php _e( 'Checkout Logo', 'mycred' ); ?></label>
197
- <ol>
198
- <li>
199
- <div class="h2"><input type="text" name="<?php echo $this->field_name( 'logo' ); ?>" id="<?php echo $this->field_id( 'logo' ); ?>" value="<?php echo esc_attr( $prefs['logo'] ); ?>" class="long" /></div>
200
- </li>
201
- </ol>
202
- <label class="subheader" for="buycredbanktransferaccount"><?php _e( 'Bank Account Information', 'mycred' ); ?></label>
203
- <ol>
204
- <li>
205
- <?php wp_editor( $prefs['account'], 'buycredbanktransferaccount', array( 'textarea_name' => $this->field_name( 'account' ), 'textarea_rows' => 10 ) ); ?>
206
- <span class="description"><?php _e( 'Bank transfer details to show the user on the checkout page.', 'mycred' ); ?></span>
207
- </li>
208
- </ol>
209
- <label class="subheader" for="<?php echo $this->field_id( 'currency' ); ?>"><?php _e( 'Currency', 'mycred' ); ?></label>
210
- <ol>
211
- <li>
212
- <div class="h2"><input type="text" name="<?php echo $this->field_name( 'currency' ); ?>" id="<?php echo $this->field_id( 'currency' ); ?>" data-update="mycred-gateway-bank-currency" value="<?php echo esc_attr( $prefs['currency'] ); ?>" size="8" maxlength="3" /></div>
213
- </li>
214
- </ol>
215
- <label class="subheader"><?php _e( 'Exchange Rates', 'mycred' ); ?></label>
216
- <ol>
217
- <?php $this->exchange_rate_setup(); ?>
218
- </ol>
219
- <script type="text/javascript">
220
- jQuery(function($){
221
-
222
- $( '#mycred-gateway-prefs-bank-currency' ).change(function(){
223
- $( 'span.mycred-gateway-bank-currency' ).text( $(this).val() );
224
- });
225
-
226
- });
227
- </script>
228
- <?php
229
-
230
- }
231
-
232
- /**
233
- * Sanatize Prefs
234
- * @since 1.0
235
- * @version 1.0
236
- */
237
- public function sanitise_preferences( $data ) {
238
-
239
- $new_data = array();
240
-
241
- $new_data['title'] = sanitize_text_field( $data['title'] );
242
- $new_data['logo'] = sanitize_text_field( $data['logo'] );
243
- $new_data['account'] = wp_kses_post( $data['account'] );
244
- $new_data['currency'] = sanitize_text_field( $data['currency'] );
245
-
246
- // If exchange is less then 1 we must start with a zero
247
- if ( isset( $data['exchange'] ) ) {
248
- foreach ( (array) $data['exchange'] as $type => $rate ) {
249
- if ( $rate != 1 && in_array( substr( $rate, 0, 1 ), array( '.', ',' ) ) )
250
- $data['exchange'][ $type ] = (float) '0' . $rate;
251
- }
252
- }
253
- $new_data['exchange'] = $data['exchange'];
254
-
255
- return $new_data;
256
-
257
- }
258
-
259
- }
260
- endif;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
addons/buy-creds/gateways/bitpay.php CHANGED
@@ -156,7 +156,7 @@ if ( ! class_exists( 'myCRED_Bitpay' ) ) :
156
  /**
157
  * Buy Creds
158
  * @since 1.4
159
- * @version 1.2
160
  */
161
  public function buy() {
162
 
@@ -200,7 +200,8 @@ if ( ! class_exists( 'myCRED_Bitpay' ) ) :
200
  'fullNotifications' => ( $this->prefs['notifications'] ) ? true : false,
201
  'posData' => $this->transaction_id,
202
  'buyerName' => $this->get_buyers_name( $from ),
203
- 'itemDesc' => $item_name
 
204
  ) );
205
 
206
  // Request Failed
156
  /**
157
  * Buy Creds
158
  * @since 1.4
159
+ * @version 1.2.1
160
  */
161
  public function buy() {
162
 
200
  'fullNotifications' => ( $this->prefs['notifications'] ) ? true : false,
201
  'posData' => $this->transaction_id,
202
  'buyerName' => $this->get_buyers_name( $from ),
203
+ 'itemDesc' => $item_name,
204
+ 'redirectURL' => $this->get_thankyou()
205
  ) );
206
 
207
  // Request Failed
addons/{banking/assets → buy-creds/images}/index.php RENAMED
File without changes
addons/buy-creds/images/loading.gif ADDED
Binary file
addons/buy-creds/images/netbilling.png ADDED
Binary file
addons/buy-creds/images/skrill.png ADDED
Binary file
addons/buy-creds/images/zombaio.jpg ADDED
Binary file
addons/buy-creds/includes/buycred-functions.php DELETED
@@ -1,295 +0,0 @@
1
- <?php
2
- if ( ! defined( 'MYCRED_PURCHASE' ) ) exit;
3
-
4
- /**
5
- * Get Pending Payment
6
- * @since 1.7
7
- * @version 1.0
8
- */
9
- if ( ! function_exists( 'buycred_get_pending_payment_id' ) ) :
10
- function buycred_get_pending_payment_id( $payment_id = NULL ) {
11
-
12
- if ( $payment_id === NULL || $payment_id == '' ) return false;
13
-
14
- // In case we are using the transaction ID instead of the post ID.
15
- $post_id = false;
16
- if ( ! is_numeric( $payment_id ) ) {
17
-
18
- $post = get_page_by_title( strtoupper( $payment_id ), OBJECT, 'buycred_payment' );
19
- if ( $post === NULL ) return false;
20
-
21
- $post_id = $post->ID;
22
-
23
- }
24
- else {
25
- $post_id = absint( $payment_id );
26
- }
27
-
28
- return $post_id;
29
-
30
- }
31
- endif;
32
-
33
- /**
34
- * Get Pending Payment
35
- * @since 1.7
36
- * @version 1.0
37
- */
38
- if ( ! function_exists( 'buycred_get_pending_payment' ) ) :
39
- function buycred_get_pending_payment( $payment_id = NULL ) {
40
-
41
- // Construct fake pending object ( when no pending payment object exists )
42
- if ( is_array( $payment_id ) ) {
43
-
44
- $pending_payment = new StdClass();
45
- $pending_payment->payment_id = false;
46
- $pending_payment->public_id = $payment_id['public_id'];
47
- $pending_payment->point_type = $payment_id['point_type'];
48
- $pending_payment->amount = $payment_id['amount'];
49
- $pending_payment->cost = $payment_id['cost'];
50
- $pending_payment->currency = $payment_id['currency'];
51
- $pending_payment->buyer_id = $payment_id['buyer_id'];
52
- $pending_payment->recipient_id = $payment_id['recipient_id'];
53
- $pending_payment->gateway_id = $payment_id['gateway_id'];
54
- $pending_payment->transaction_id = $payment_id['transaction_id'];
55
- $pending_payment->cancel_url = false;
56
- $pending_payment->pay_now_url = false;
57
-
58
- }
59
-
60
- else {
61
-
62
- $payment_id = buycred_get_pending_payment_id( $payment_id );
63
-
64
- if ( $payment_id === false ) return false;
65
-
66
- $pending_payment = new StdClass();
67
- $pending_payment->payment_id = absint( $payment_id );
68
- $pending_payment->public_id = get_the_title( $payment_id );
69
- $pending_payment->point_type = get_post_meta( $payment_id, 'point_type', true );
70
- $pending_payment->amount = get_post_meta( $payment_id, 'amount', true );
71
- $pending_payment->cost = get_post_meta( $payment_id, 'cost', true );
72
- $pending_payment->currency = get_post_meta( $payment_id, 'currency', true );
73
- $pending_payment->buyer_id = get_post_meta( $payment_id, 'from', true );
74
- $pending_payment->recipient_id = get_post_meta( $payment_id, 'to', true );
75
- $pending_payment->gateway_id = get_post_meta( $payment_id, 'gateway', true );
76
- $pending_payment->transaction_id = get_the_title( $payment_id );
77
-
78
- $pending_payment->cancel_url = buycred_get_cancel_transaction_url( $pending_payment->public_id );
79
-
80
- $pending_payment->pay_now_url = add_query_arg( array(
81
- 'mycred_buy' => $pending_payment->gateway_id,
82
- 'amount' => $pending_payment->amount,
83
- 'revisit' => $payment_id,
84
- 'token' => wp_create_nonce( 'mycred-buy-creds' )
85
- ), set_url_scheme( 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'] ) );
86
-
87
- }
88
-
89
- return apply_filters( 'buycred_get_pending_payment', $pending_payment, $payment_id );
90
-
91
- }
92
- endif;
93
-
94
- /**
95
- * Add Pending Comment
96
- * @since 1.7
97
- * @version 1.0.1
98
- */
99
- if ( ! function_exists( 'buycred_add_pending_comment' ) ) :
100
- function buycred_add_pending_comment( $payment_id = NULL, $comment = NULL, $time = NULL ) {
101
-
102
- if ( MYCRED_BUYCRED_PENDING_COMMENTS === false ) return true;
103
-
104
- $post_id = buycred_get_pending_payment_id( $payment_id );
105
- if ( $post_id === false ) return false;
106
-
107
- global $mycred_modules;
108
-
109
- if ( $time === NULL || $time == 'now' )
110
- $time = current_time( 'mysql' );
111
-
112
- $author = 'buyCRED';
113
- $gateway = get_post_meta( $post_id, 'gateway', true );
114
- $gateways = $mycred_modules['solo']['buycred']->get();
115
- $author_url = sprintf( 'buyCRED: %s %s', __( 'Unknown Gateway', 'mycred' ), $gateway );
116
- $author_email = apply_filters( 'mycred_buycred_comment_email', 'buycred-service@mycred.me' );
117
-
118
- if ( array_key_exists( $gateway, $gateways ) )
119
- $author = sprintf( 'buyCRED: %s %s', $gateways[ $gateway ]['title'], __( 'Gateway', 'mycred' ) );
120
-
121
- return wp_insert_comment( array(
122
- 'comment_post_ID' => $post_id,
123
- 'comment_author' => $author,
124
- 'comment_author_email' => $author_email,
125
- 'comment_content' => $comment,
126
- 'comment_type' => 'comment',
127
- 'comment_author_IP' => $_SERVER['REMOTE_ADDR'],
128
- 'comment_date' => $time,
129
- 'comment_approved' => 1,
130
- 'user_id' => 0
131
- ) );
132
-
133
- }
134
- endif;
135
-
136
- /**
137
- * Get Cancel URL
138
- * @since 1.7
139
- * @version 1.0.1
140
- */
141
- if ( ! function_exists( 'buycred_get_cancel_transaction_url' ) ) :
142
- function buycred_get_cancel_transaction_url( $transaction_id = NULL ) {
143
-
144
- $mycred = mycred();
145
- $base = get_bloginfo( 'url' );
146
-
147
- // Cancel page
148
- if ( $mycred->buy_creds['cancelled']['use'] == 'page' ) {
149
- if ( ! empty( $mycred->buy_creds['cancelled']['page'] ) )
150
- $base = get_permalink( $mycred->buy_creds['cancelled']['page'] );
151
- }
152
-
153
- // Custom URL
154
- else {
155
- $base = get_bloginfo( 'url' ) . '/' . $mycred->buy_creds['cancelled']['custom'];
156
- }
157
-
158
- // Override
159
- if ( isset( $_REQUEST['return_to'] ) && esc_url_raw( $_REQUEST['return_to'] ) != '' )
160
- $base = esc_url_raw( $_REQUEST['return_to'] );
161
-
162
- if ( $transaction_id !== NULL )
163
- $url = add_query_arg( array( 'buycred-cancel' => $transaction_id, '_token' => wp_create_nonce( 'buycred-cancel-pending-payment' ) ), $base );
164
- else
165
- $url = $base;
166
-
167
- return apply_filters( 'mycred_buycred_cancel_url', $url, $transaction_id );
168
-
169
- }
170
- endif;
171
-
172
-
173
-
174
-
175
- /**
176
- * Get Users Pending Payments
177
- * @since 1.7
178
- * @version 1.0.1
179
- */
180
- if ( ! function_exists( 'buycred_get_users_pending_payments' ) ) :
181
- function buycred_get_users_pending_payments( $user_id = NULL, $point_type = NULL ) {
182
-
183
- $user_id = absint( $user_id );
184
- if ( $user_id === 0 ) return false;
185
-
186
- $pending = get_user_meta( $user_id, 'buycred_pending_payments', true );
187
- if ( $pending == '' ) {
188
-
189
- global $wpdb;
190
-
191
- $pending = array();
192
- $saved = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM {$wpdb->posts} posts WHERE posts.post_type = 'buycred_payment' AND posts.post_author = %d AND posts.post_status = 'publish';", $user_id ) );
193
- if ( ! empty( $saved ) ) {
194
-
195
- foreach ( $saved as $entry ) {
196
-
197
- $point_type = get_post_meta( $entry->ID, 'point_type', true );
198
- if ( $point_type == '' ) $point_type = MYCRED_DEFAULT_TYPE_KEY;
199
-
200
- if ( ! array_key_exists( $point_type, $pending ) )
201
- $pending[ $point_type ] = array();
202
-
203
- $pending[ $point_type ][] = buycred_get_pending_payment( (int) $entry->ID );
204
-
205
- }
206
-
207
- add_user_meta( $user_id, 'buycred_pending_payments', $pending, true );
208
-
209
- }
210
-
211
- }
212
-
213
- if ( $point_type !== NULL && mycred_point_type_exists( $point_type ) ) {
214
-
215
- if ( ! array_key_exists( $point_type, $pending ) )
216
- return false;
217
-
218
- return $pending[ $point_type ];
219
-
220
- }
221
-
222
- return $pending;
223
-
224
- }
225
- endif;
226
-
227
- /**
228
- * buyCRED Gateway Constructor
229
- * @since 1.7
230
- * @version 1.0
231
- */
232
- if ( ! function_exists( 'buycred_gateway' ) ) :
233
- function buycred_gateway( $gateway_id = NULL ) {
234
-
235
- global $mycred_modules;
236
-
237
- $gateway = false;
238
- $installed = $mycred_modules['solo']['buycred']->get();
239
-
240
- if ( array_key_exists( $gateway_id, $installed ) ) {
241
-
242
- $class = $installed[ $gateway_id ]['callback'][0];
243
-
244
- // Construct Gateway
245
- $gateway = new $class( $mycred_modules['solo']['buycred']->gateway_prefs );
246
-
247
- }
248
-
249
- return $gateway;
250
-
251
- }
252
- endif;
253
-
254
- /**
255
- * Delete Pending Payment
256
- * @since 1.7
257
- * @version 1.0
258
- */
259
- if ( ! function_exists( 'buycred_trash_pending_payment' ) ) :
260
- function buycred_trash_pending_payment( $payment_id = NULL ) {
261
-
262
- $pending_payment = buycred_get_pending_payment( $payment_id );
263
- if ( $pending_payment === false ) return false;
264
-
265
- delete_user_meta( $pending_payment->buyer_id, 'buycred_pending_payments' );
266
-
267
- return wp_trash_post( $pending_payment->payment_id );
268
-
269
- }
270
- endif;
271
-
272
- /**
273
- * Complete Pending Payment
274
- * @since 1.7
275
- * @version 1.0
276
- */
277
- if ( ! function_exists( 'buycred_complete_pending_payment' ) ) :
278
- function buycred_complete_pending_payment( $pending_id ) {
279
-
280
- $pending_payment = buycred_get_pending_payment( $pending_id );
281
- if ( $pending_payment === false ) return false;
282
-
283
- $gateway = buycred_gateway( $pending_payment->gateway_id );
284
- if ( $gateway === false ) return false;
285
-
286
- // Complete Payment
287
- $paid = $gateway->complete_payment( $pending_payment, $pending_payment->transaction_id );
288
-
289
- if ( $paid )
290
- return buycred_trash_pending_payment( $pending_id );
291
-
292
- return $paid;
293
-
294
- }
295
- endif;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
addons/buy-creds/modules/buycred-module-core.php DELETED
@@ -1,1591 +0,0 @@
1
- <?php
2
- if ( ! defined( 'MYCRED_PURCHASE' ) ) exit;
3
-
4
- /**
5
- * myCRED_buyCRED_Module class
6
- * @since 0.1
7
- * @version 1.4.1
8
- */
9
- if ( ! class_exists( 'myCRED_buyCRED_Module' ) ) :
10
- class myCRED_buyCRED_Module extends myCRED_Module {
11
-
12
- public $purchase_log = '';
13
-
14
- /**
15
- * Construct
16
- */
17
- function __construct( $type = MYCRED_DEFAULT_TYPE_KEY ) {
18
-
19
- parent::__construct( 'myCRED_BuyCRED_Module', array(
20
- 'module_name' => 'gateways',
21
- 'option_id' => 'mycred_pref_buycreds',
22
- 'defaults' => array(
23
- 'installed' => array(),
24
- 'active' => array(),
25
- 'gateway_prefs' => array()
26
- ),
27
- 'labels' => array(
28
- 'menu' => __( 'Payment Gateways', 'mycred' ),
29
- 'page_title' => __( 'Payment Gateways', 'mycred' ),
30
- 'page_header' => __( 'Payment Gateways', 'mycred' )
31
- ),
32
- 'screen_id' => MYCRED_SLUG . '-gateways',
33
- 'accordion' => true,
34
- 'add_to_core' => true,
35
- 'menu_pos' => 70
36
- ), $type );
37
-
38
- // Adjust Module to the selected point type
39
- $this->mycred_type = MYCRED_DEFAULT_TYPE_KEY;
40
- if ( isset( $this->core->buy_creds['type'] ) )
41
- $this->mycred_type = $this->core->buy_creds['type'];
42
-
43
- }
44
-
45
- /**
46
- * Load
47
- * @version 1.0.2
48
- */
49
- public function load() {
50
-
51
- add_filter( 'mycred_parse_log_entry', array( $this, 'render_gift_tags' ), 10, 2 );
52
-
53
- add_action( 'mycred_init', array( $this, 'module_init' ), $this->menu_pos );
54
- add_action( 'wp_loaded', array( $this, 'module_run' ) );
55
- add_action( 'mycred_admin_init', array( $this, 'module_admin_init' ), $this->menu_pos );
56
-
57
- add_action( 'mycred_admin_init', array( $this, 'register_settings' ), $this->menu_pos+1 );
58
- add_action( 'mycred_add_menu', array( $this, 'add_menu' ), $this->menu_pos );
59
- add_action( 'mycred_add_menu', array( $this, 'add_to_menu' ), $this->menu_pos+1 );
60
- add_action( 'mycred_after_core_prefs', array( $this, 'after_general_settings' ) );
61
- add_filter( 'mycred_save_core_prefs', array( $this, 'sanitize_extra_settings' ), 90, 3 );
62
-
63
- }
64
-
65
- /**
66
- * Init
67
- * Register shortcodes.
68
- * @since 0.1
69
- * @version 1.4
70
- */
71
- public function module_init() {
72
-
73
- // Add shortcodes first
74
- add_shortcode( 'mycred_buy', array( $this, 'render_shortcode_basic' ) );
75
- add_shortcode( 'mycred_buy_form', array( $this, 'render_shortcode_form' ) );
76
-
77
- $this->current_user_id = get_current_user_id();
78
-
79
- }
80
-
81
- /**
82
- * Get Payment Gateways
83
- * Retreivs all available payment gateways that can be used to buy CREDs.
84
- * @since 0.1
85
- * @version 1.1.1
86
- */
87
- public function get() {
88
-
89
- $installed = array();
90
-
91
- // PayPal Standard
92
- $installed['paypal-standard'] = array(
93
- 'title' => 'PayPal Payments Standard',
94
- 'callback' => array( 'myCRED_PayPal_Standard' ),
95
- 'icon' => 'dashicons-admin-generic',
96
- 'external' => true,
97
- 'custom_rate' => true
98
- );
99
-
100
- // BitPay
101
- $installed['bitpay'] = array(
102
- 'title' => 'BitPay (Bitcoins)',
103
- 'callback' => array( 'myCRED_Bitpay' ),
104
- 'icon' => 'dashicons-admin-generic',
105
- 'external' => true,
106
- 'custom_rate' => true
107
- );
108
-
109
- // NetBilling
110
- $installed['netbilling'] = array(
111
- 'title' => 'NETBilling',
112
- 'callback' => array( 'myCRED_NETbilling' ),
113
- 'icon' => 'dashicons-admin-generic',
114
- 'external' => true,
115
- 'custom_rate' => true
116
- );
117
-
118
- // Skrill
119
- $installed['skrill'] = array(
120
- 'title' => 'Skrill (Moneybookers)',
121
- 'callback' => array( 'myCRED_Skrill' ),
122
- 'icon' => 'dashicons-admin-generic',
123
- 'external' => true,
124
- 'custom_rate' => true
125
- );
126
-
127
- // Zombaio
128
- $installed['zombaio'] = array(
129
- 'title' => 'Zombaio',
130
- 'callback' => array( 'myCRED_Zombaio' ),
131
- 'icon' => 'dashicons-admin-generic',
132
- 'external' => true,
133
- 'custom_rate' => false
134
- );
135
-
136
- // Bank Transfers
137
- $installed['bank'] = array(
138
- 'title' => __( 'Bank Transfer', 'mycred' ),
139
- 'callback' => array( 'myCRED_Bank_Transfer' ),
140
- 'icon' => 'dashicons-admin-generic',
141
- 'external' => false,
142
- 'custom_rate' => true
143
- );
144
-
145
- $installed = apply_filters( 'mycred_setup_gateways', $installed );
146
-
147
- // Untill all custom gateways have been updated, make sure all gateways have an external setting
148
- if ( ! empty( $installed ) ) {
149
- foreach ( $installed as $id => $settings ) {
150
-
151
- if ( ! array_key_exists( 'external', $settings ) )
152
- $installed[ $id ]['external'] = true;
153
-
154
- if ( ! array_key_exists( 'custom_rate', $settings ) )
155
- $installed[ $id ]['custom_rate'] = false;
156
-
157
- }
158
- }
159
-
160
- return $installed;
161
-
162
- }
163
-
164
- /**
165
- * Run
166
- * Runs a gateway if requested.
167
- * @since 1.7
168
- * @version 1.0
169
- */
170
- public function module_run() {
171
-
172
- // Prep
173
- $installed = $this->get();
174
-
175
- // Make sure we have installed gateways.
176
- if ( empty( $installed ) ) return;
177
-
178
- /**
179
- * Step 1 - Look for returns
180
- * Runs though all active payment gateways and lets them decide if this is the
181
- * user returning after a remote purchase. Each gateway should know what to look
182
- * for to determen if they are responsible for handling the return.
183
- */
184
- foreach ( $installed as $id => $data ) {
185
-
186
- // Only applicable if the gateway is active and marked as external (new in 1.7)
187
- if ( $this->is_active( $id ) && $data['external'] === true )
188
- $this->call( 'returning', $installed[ $id ]['callback'] );
189
-
190
- }
191
-
192
- /**
193
- * Step 2 - Check for gateway calls
194
- * Checks to see if a gateway should be loaded.
195
- */
196
- $gateway_id = false;
197
- $process = false;
198
-
199
- if ( isset( $_REQUEST['mycred_call'] ) )
200
- $gateway_id = trim( $_REQUEST['mycred_call'] );
201
-
202
- elseif ( isset( $_REQUEST['mycred_buy'] ) && is_user_logged_in() )
203
- $gateway_id = trim( $_REQUEST['mycred_buy'] );
204
-
205
- elseif ( isset( $_REQUEST['wp_zombaio_ips'] ) || isset( $_REQUEST['ZombaioGWPass'] ) ) {
206
- $gateway_id = 'zombaio';
207
- $process = true;
208
- }
209
-
210
- $gateway_id = apply_filters( 'mycred_gateway_id', $gateway_id );
211
-
212
- // If we have a valid gateway ID and the gateway is active, lets run that gateway.
213
- if ( $gateway_id !== false && array_key_exists( $gateway_id, $installed ) && $this->is_active( $gateway_id ) ) {
214
-
215
- // Construct Gateway
216
- $gateway = buycred_gateway( $gateway_id );
217
-
218
- // Check payment processing
219
- if ( isset( $_REQUEST['mycred_call'] ) || ( $gateway_id == 'zombaio' && $process ) ) {
220
-
221
- $gateway->process();
222
-
223
- do_action( 'mycred_buycred_process', $gateway_id, $this->gateway_prefs, $this->core->buy_creds );
224
- do_action( "mycred_buycred_process_{$gateway_id}", $this->gateway_prefs, $this->core->buy_creds );
225
-
226
- }
227
-
228
- // Check purchase request
229
- if ( isset( $_REQUEST['mycred_buy'] ) ) {
230
-
231
- // Validate token
232
- $token = false;
233
- if ( isset( $_REQUEST['token'] ) && wp_verify_nonce( $_REQUEST['token'], 'mycred-buy-creds' ) )
234
- $token = true;
235
-
236
- // Validate amount ( amount is not zero and higher then minimum required )
237
- $amount = false;
238
- if ( isset( $_REQUEST['amount'] ) && is_numeric( $_REQUEST['amount'] ) && $_REQUEST['amount'] >= $this->core->buy_creds['minimum'] )
239
- $amount = true;
240
-
241
- if ( $token && $amount ) {
242
-
243
- $gateway->buy();
244
-
245
- do_action( 'mycred_buycred_buy', $gateway_id, $this->gateway_prefs, $this->core->buy_creds );
246
- do_action( "mycred_buycred_buy_{$gateway_id}", $this->gateway_prefs, $this->core->buy_creds );
247
-
248
- }
249
-
250
- }
251
-
252
- }
253
-
254
- }
255
-
256
- /**
257
- * Admin Init
258
- * @since 1.5
259
- * @version 1.1
260
- */
261
- function module_admin_init() {
262
-
263
- add_action( 'mycred_user_edit_after_balances', array( $this, 'exchange_rates_user_screen' ), 30 );
264
-
265
- add_action( 'personal_options_update', array( $this, 'save_manual_exchange_rates' ), 30 );
266
- add_action( 'edit_user_profile_update', array( $this, 'save_manual_exchange_rates' ), 30 );
267
-
268
- // Prep
269
- $installed = $this->get();
270
-
271
- // Make sure we have installed gateways.
272
- if ( empty( $installed ) ) return;
273
-
274
- /**
275
- * Admin Init
276
- * Runs though all installed gateways to allow admin inits.
277
- */
278
- foreach ( $installed as $id => $data )
279
- $this->call( 'admin_init', $installed[ $id ]['callback'] );
280
-
281
- }
282
-
283
- /**
284
- * Add to General Settings
285
- * @since 0.1
286
- * @version 1.2
287
- */
288
- public function after_general_settings( $mycred = NULL ) {
289
-
290
- // Reset while on this screen so we can use $this->field_id() and $this->field_name()
291
- $this->module_name = 'buy_creds';
292
- $this->option_id = '';
293
-
294
- // Since we are both registering our own settings and want to hook into
295
- // the core settings, we need to define our "defaults" here.
296
- $defaults = array(
297
- 'minimum' => 1,
298
- 'types' => array( MYCRED_DEFAULT_TYPE_KEY ),
299
- 'exchange' => 1,
300
- 'log' => '%plural% purchase',
301
- 'login' => __( 'Please login to purchase %_plural%', 'mycred' ),
302
- 'custom_log' => 0,
303
- 'thankyou' => array(
304
- 'use' => 'page',
305
- 'custom' => '',
306
- 'page' => ''
307
- ),
308
- 'cancelled' => array(
309
- 'use' => 'custom',
310
- 'custom' => '',
311
- 'page' => ''
312
- ),
313
- 'gifting' => array(
314
- 'members' => 1,
315
- 'authors' => 1,
316
- 'log' => __( 'Gift purchase from %display_name%.', 'mycred' )
317
- )
318
- );
319
-
320
- if ( isset( $this->core->buy_creds ) )
321
- $settings = $this->core->buy_creds;
322
- else
323
- $settings = $defaults;
324
-
325
- ?>
326
- <h4><span class="dashicons dashicons-admin-plugins static"></span><strong>buy</strong>CRED</h4>
327
- <div class="body" style="display:none;">
328
-
329
- <h3><?php _e( 'Features', 'mycred' ); ?></h3>
330
- <div class="row">
331
- <div class="col-lg-6 col-md-6 col-sm-12 col-xs-12">
332
- <div class="form-group">
333
- <label for="mycred-transfer-type"><?php _e( 'Point Types', 'mycred' ); ?></label>
334
- <?php if ( count( $this->point_types ) > 1 ) : ?>
335
- <?php mycred_types_select_from_checkboxes( 'mycred_pref_core[buy_creds][types][]', $this->field_id( 'types' ), $settings['types'] ); ?>
336
- <p><span class="description"><?php _e( 'Select the point types that users can buy. You must select at least one!', 'mycred' ); ?></span></p>
337
- <?php else : ?>
338
- <p class="form-control-static"><?php echo $this->core->plural(); ?></p>
339
- <input type="hidden" name="mycred_pref_core[buy_creds][types][]" value="<?php echo MYCRED_DEFAULT_TYPE_KEY; ?>" />
340
- <?php endif; ?>
341
- </div>
342
- </div>
343
- <div class="col-lg-6 col-md-6 col-sm-12 col-xs-12">
344
- <div class="form-group">
345
- <label for="<?php echo $this->field_id( 'minimum' ); ?>"><?php echo $this->core->template_tags_general( __( 'Minimum %plural%', 'mycred' ) ); ?></label>
346
- <input type="text" name="<?php echo $this->field_name( 'minimum' ); ?>" id="<?php echo $this->field_id( 'minimum' ); ?>" class="form-control" placeholder="<?php _e( 'Required', 'mycred' ); ?>" value="<?php echo esc_attr( $settings['minimum'] ); ?>" />
347
- <p><span class="description"><?php echo $this->core->template_tags_amount( __( 'Minimum amount of %plural% a user must purchase. Will default to %cred%.', 'mycred' ), 1 ); ?></span></p>
348
- </div>
349
- </div>
350
- </div>
351
- <div class="row">
352
- <div class="col-lg-12 col-md-12 col-sm-12 col-xs-12">
353
- <div class="form-group">
354
- <div class="checkbox">
355
- <label for="<?php echo $this->field_id( 'custom_log' ); ?>"><input type="checkbox" name="<?php echo $this->field_name( 'custom_log' ); ?>" id="<?php echo $this->field_id( 'custom_log' ); ?>"<?php checked( $settings['custom_log'], 1 ); ?> value="1" /> <?php echo $this->core->template_tags_general( __( 'Show seperate log for %_plural% purchases.', 'mycred' ) ); ?></label>
356
- </div>
357
- </div>
358
- </div>
359
- </div>
360
-
361
- <h3><?php _e( 'Redirects', 'mycred' ); ?></h3>
362
- <div class="row">
363
- <div class="col-lg-6 col-md-6 col-sm-12 col-xs-12">
364
- <div class="form-group">
365
- <p style="margin-top: 0;"><span class="description"><?php _e( 'Where should users be redirected to upon successfully completing a purchase. You can nominate a specific URL or a page.', 'mycred' ); ?></span></p>
366
- </div>
367
- <div class="form-group">
368
- <label for="<?php echo $this->field_id( array( 'thankyou' => 'page' ) ); ?>"><?php _e( 'Redirect to Page', 'mycred' ); ?></label>
369
- <?php
370
-
371
- // Thank you page dropdown
372
- $thankyou_args = array(
373
- 'name' => $this->field_name( array( 'thankyou' => 'page' ) ),
374
- 'id' => $this->field_id( array( 'thankyou' => 'page' ) ) . '-id',
375
- 'selected' => $settings['thankyou']['page'],
376
- 'show_option_none' => __( 'Select', 'mycred' ),
377
- 'class' => 'form-control'
378
- );
379
- wp_dropdown_pages( $thankyou_args );
380
-
381
- ?>
382
- </div>
383
- <div class="form-group">
384
- <label for="<?php echo $this->field_id( array( 'thankyou' => 'custom' ) ); ?>"><?php _e( 'Redirect to URL', 'mycred' ); ?></label>
385
- <input type="text" name="<?php echo $this->field_name( array( 'thankyou' => 'custom' ) ); ?>" id="<?php echo $this->field_id( array( 'thankyou' => 'custom' ) ); ?>" placeholder="https://" class="form-control" value="<?php echo esc_attr( $settings['thankyou']['custom'] ); ?>" />
386
- </div>
387
- </div>
388
- <div class="col-lg-6 col-md-6 col-sm-12 col-xs-12">
389
- <div class="form-group">
390
- <p style="margin-top: 0;"><span class="description"><?php _e( 'Where should users be redirected to if they cancel a transaction. You can nominate a specific URL or a page.', 'mycred' ); ?></span></p>
391
- </div>
392
- <div class="form-group">
393
- <label for="<?php echo $this->field_id( array( 'cancelled' => 'page' ) ); ?>"><?php _e( 'Redirect to Page', 'mycred' ); ?></label>
394
- <?php
395
-
396
- // Thank you page dropdown
397
- $thankyou_args = array(
398
- 'name' => $this->field_name( array( 'cancelled' => 'page' ) ),
399
- 'id' => $this->field_id( array( 'cancelled' => 'page' ) ) . '-id',
400
- 'selected' => $settings['cancelled']['page'],
401
- 'show_option_none' => __( 'Select', 'mycred' ),
402
- 'class' => 'form-control'
403
- );
404
- wp_dropdown_pages( $thankyou_args );
405
-
406
- ?>
407
- </div>
408
- <div class="form-group">
409
- <label for="<?php echo $this->field_id( array( 'cancelled' => 'custom' ) ); ?>"><?php _e( 'Redirect to URL', 'mycred' ); ?></label>
410
- <input type="text" name="<?php echo $this->field_name( array( 'cancelled' => 'custom' ) ); ?>" id="<?php echo $this->field_id( array( 'cancelled' => 'custom' ) ); ?>" placeholder="https://" class="form-control" value="<?php echo esc_attr( $settings['cancelled']['custom'] ); ?>" />
411
- </div>
412
- </div>
413
- </div>
414
-
415
- <h3><?php _e( 'Templates', 'mycred' ); ?></h3>
416
- <div class="row">
417
- <div class="col-lg-6 col-md-6 col-sm-12 col-xs-12">
418
- <div class="form-group">
419
- <label for="<?php echo $this->field_id( 'login' ); ?>"><?php _e( 'Login Message', 'mycred' ); ?></label>
420
- <input type="text" name="<?php echo $this->field_name( 'login' ); ?>" id="<?php echo $this->field_id( 'login' ); ?>" class="form-control" value="<?php echo esc_attr( $settings['login'] ); ?>" />
421
- <p><span class="description"><?php _e( 'Message to show in shortcodes when viewed by someone who is not logged in.', 'mycred' ); ?></span></p>
422
- </div>
423
- </div>
424
- <div class="col-lg-6 col-md-6 col-sm-12 col-xs-12">
425
- <div class="form-group">
426
- <label for="<?php echo $this->field_id( 'log' ); ?>"><?php _e( 'Log Template', 'mycred' ); ?></label>
427
- <input type="text" name="<?php echo $this->field_name( 'log' ); ?>" id="<?php echo $this->field_id( 'log' ); ?>" class="form-control" placeholder="<?php _e( 'Required', 'mycred' ); ?>" value="<?php echo esc_attr( $settings['log'] ); ?>" />
428
- <p><span class="description"><?php echo $this->core->available_template_tags( array( 'general' ), '%gateway%' ); ?></span></p>
429
- </div>
430
- </div>
431
- </div>
432
-
433
- <h3><?php _e( 'Gifting', 'mycred' ); ?></h3>
434
- <div class="row">
435
- <div class="col-lg-6 col-md-6 col-sm-12 col-xs-12">
436
- <div class="form-group">
437
- <div class="checkbox">
438
- <label for="<?php echo $this->field_id( array( 'gifting' => 'members' ) ); ?>"><input type="checkbox" name="<?php echo $this->field_name( array( 'gifting' => 'members' ) ); ?>" id="<?php echo $this->field_id( array( 'gifting' => 'members' ) ); ?>"<?php checked( $settings['gifting']['members'], 1 ); ?> value="1" /> <?php echo $this->core->template_tags_general( __( 'Allow users to buy %_plural% for other users.', 'mycred' ) ); ?></label>
439
- </div>
440
- </div>
441
- </div>
442
- <div class="col-lg-6 col-md-6 col-sm-12 col-xs-12">
443
- <div class="form-group">
444
- <div class="checkbox">
445
- <label for="<?php echo $this->field_id( array( 'gifting' => 'authors' ) ); ?>"><input type="checkbox" name="<?php echo $this->field_name( array( 'gifting' => 'authors' ) ); ?>" id="<?php echo $this->field_id( array( 'gifting' => 'authors' ) ); ?>"<?php checked( $settings['gifting']['authors'], 1 ); ?> value="1" /> <?php echo $this->core->template_tags_general( __( 'Allow users to buy %_plural% for content authors.', 'mycred' ) ); ?></label>
446
- </div>
447
- </div>
448
- </div>
449
- </div>
450
- <div class="row">
451
- <div class="col-lg-12 col-md-12 col-sm-12 col-xs-12">
452
- <div class="form-group">
453
- <label for="<?php echo $this->field_id( array( 'gifting' => 'log' ) ); ?>"><?php _e( 'Log Template', 'mycred' ); ?></label>
454
- <input type="text" name="<?php echo $this->field_name( array( 'gifting' => 'log' ) ); ?>" id="<?php echo $this->field_id( 'log' ); ?>" class="form-control" placeholder="<?php _e( 'Required', 'mycred' ); ?>" value="<?php echo esc_attr( $settings['gifting']['log'] ); ?>" />
455
- <p><span class="description"><?php echo $this->core->available_template_tags( array( 'general', 'user' ) ); ?></span></p>
456
- </div>
457
- </div>
458
- </div>
459
-
460
- <h3 style="margin-bottom: 0;"><?php _e( 'Available Shortcodes', 'mycred' ); ?></h3>
461
- <div class="row">
462
- <div class="col-lg-12 col-md-12 col-sm-12 col-xs-12">
463
- <p><a href="http://codex.mycred.me/shortcodes/mycred_buy/" target="_blank">[mycred_buy]</a>, <a href="http://codex.mycred.me/shortcodes/mycred_buy_form/" target="_blank">[mycred_buy_form]</a>, <a href="http://codex.mycred.me/shortcodes/mycred_buy_pending/" target="_blank">[mycred_buy_pending]</a></p>
464
- </div>
465
- </div>
466
-
467
- </div>
468
- <?php
469
-
470
- $this->module_name = 'gateways';
471
- $this->option_id = 'mycred_pref_buycreds';
472
-
473
- }
474
-
475
- /**
476
- * Save Settings
477
- * @since 0.1
478
- * @version 1.1.2
479
- */
480
- public function sanitize_extra_settings( $new_data, $data, $core ) {
481
-
482
- if ( ! isset( $data['buy_creds']['types'] ) )
483
- $new_data['buy_creds']['types'] = array( MYCRED_DEFAULT_TYPE_KEY );
484
- else
485
- $new_data['buy_creds']['types'] = $data['buy_creds']['types'];
486
-
487
- $new_data['buy_creds']['minimum'] = abs( $data['buy_creds']['minimum'] );
488
- $new_data['buy_creds']['log'] = sanitize_text_field( $data['buy_creds']['log'] );
489
- $new_data['buy_creds']['login'] = wp_kses_post( $data['buy_creds']['login'] );
490
-
491
- $new_data['buy_creds']['thankyou']['page'] = absint( $data['buy_creds']['thankyou']['page'] );
492
- $new_data['buy_creds']['thankyou']['custom'] = sanitize_text_field( $data['buy_creds']['thankyou']['custom'] );
493
- $new_data['buy_creds']['thankyou']['use'] = ( $new_data['buy_creds']['thankyou']['custom'] != '' ) ? 'custom' : 'page';
494
-
495
- $new_data['buy_creds']['cancelled']['page'] = absint( $data['buy_creds']['cancelled']['page'] );
496
- $new_data['buy_creds']['cancelled']['custom'] = sanitize_text_field( $data['buy_creds']['cancelled']['custom'] );
497
- $new_data['buy_creds']['cancelled']['use'] = ( $new_data['buy_creds']['cancelled']['custom'] != '' ) ? 'custom' : 'page';
498
-
499
- $new_data['buy_creds']['custom_log'] = ( ! isset( $data['buy_creds']['custom_log'] ) ) ? 0 : 1;
500
-
501
- $new_data['buy_creds']['gifting']['members'] = ( ! isset( $data['buy_creds']['gifting']['members'] ) ) ? 0 : 1;
502
- $new_data['buy_creds']['gifting']['authors'] = ( ! isset( $data['buy_creds']['gifting']['authors'] ) ) ? 0 : 1;
503
- $new_data['buy_creds']['gifting']['log'] = sanitize_text_field( $data['buy_creds']['gifting']['log'] );
504
-
505
- delete_option( 'mycred_buycred_reset' );
506
-
507
- return $new_data;
508
-
509
- }
510
-
511
- /**
512
- * Render Gift Tags
513
- * @since 1.4.1
514
- * @version 1.0
515
- */
516
- public function render_gift_tags( $content, $log ) {
517
-
518
- if ( substr( $log->ref, 0, 15 ) != 'buy_creds_with_' ) return $content;
519
- return $this->core->template_tags_user( $content, absint( $log->ref_id ) );
520
-
521
- }
522
-
523
- /**
524
- * Add Admin Menu Item
525
- * @since 0.1
526
- * @version 1.1.1
527
- */
528
- public function add_to_menu() {
529
-
530
- if ( isset( $this->core->buy_creds['custom_log'] ) && $this->core->buy_creds['custom_log'] ) {
531
-
532
- $types = array( MYCRED_DEFAULT_TYPE_KEY );
533
- if ( isset( $this->core->buy_creds['types'] ) )
534
- $types = $this->core->buy_creds['types'];
535
-
536
- $pages = array();
537
- foreach ( $types as $type ) {
538
-
539
- $mycred = mycred( $type );
540
- $menu_slug = MYCRED_SLUG;
541
-
542
- if ( $type != MYCRED_DEFAULT_TYPE_KEY )
543
- $menu_slug = MYCRED_SLUG . '_' . trim( $type );
544
-
545
- $pages[] = add_submenu_page(
546
- $menu_slug,
547
- __( 'buyCRED Purchase Log', 'mycred' ),
548
- __( 'Purchase Log', 'mycred' ),
549
- $mycred->edit_plugin_cap(),
550
- MYCRED_SLUG . '-purchases-' . $type,
551
- array( $this, 'purchase_log_page' )
552
- );
553
-
554
- }
555
-
556
- foreach ( $pages as $page ) {
557
-
558
- add_action( 'admin_print_styles-' . $page, array( $this, 'settings_page_enqueue' ) );
559
- add_action( 'load-' . $page, array( $this, 'screen_options' ) );
560
-
561
- }
562
-
563
- $this->purchase_log = $pages;
564
-
565
- }
566
-
567
- }
568
-
569
- /**
570
- * Page Header
571
- * @since 1.3
572
- * @version 1.1
573
- */
574
- public function settings_header() {
575
-
576
- wp_enqueue_style( 'mycred-admin' );
577
- wp_enqueue_style( 'mycred-bootstrap-grid' );
578
- wp_enqueue_style( 'mycred-forms' );
579
-
580
- }
581
-
582
- /**
583
- * Payment Gateways Page
584
- * @since 0.1
585
- * @version 1.2.2
586
- */
587
- public function admin_page() {
588
-
589
- // Security
590
- if ( ! $this->core->can_edit_creds() ) wp_die( 'Access Denied' );
591
-
592
- $installed = $this->get();
593
-
594
- ?>
595
- <div class="wrap list mycred-metabox" id="myCRED-wrap">
596
- <h1><?php printf( __( '%s Payment Gateways', 'mycred' ), '<strong>buy</strong>CRED' ); ?> <a href="<?php echo esc_url( add_query_arg( array( 'page' => MYCRED_SLUG . '-settings', 'open-tab' => 'buycred_module' ), admin_url( 'admin.php' ) ) ); ?>" class="page-title-action"><?php _e( 'Settings', 'mycred' ); ?></a></h1>
597
- <?php
598
-
599
- // Updated settings
600
- if ( isset( $_GET['settings-updated'] ) && $_GET['settings-updated'] == true )
601
- echo '<div class="updated settings-error"><p>' . __( 'Settings Updated', 'mycred' ) . '</p></div>';
602
-
603
- ?>
604
- <form method="post" action="options.php" class="form">
605
-
606
- <?php settings_fields( $this->settings_name ); ?>
607
-
608
- <?php do_action( 'mycred_before_buycreds_page', $this ); ?>
609
-
610
- <div class="list-items expandable-li" id="accordion">
611
- <?php
612
-
613
- if ( ! empty( $installed ) ) {
614
- foreach ( $installed as $key => $data ) {
615
-
616
- if ( ! array_key_exists( 'icon', $data ) )
617
- $data['icon'] = 'dashicons-admin-plugins';
618
-
619
- ?>
620
- <h4><span class="dashicons <?php echo $data['icon']; ?><?php if ( $this->is_active( $key ) ) { if ( array_key_exists( 'sandbox', $this->gateway_prefs[ $key ] ) && $this->gateway_prefs[ $key ]['sandbox'] === 1 ) echo ' debug'; else echo ' active'; } else echo ' static'; ?>"></span><?php echo $this->core->template_tags_general( $data['title'] ); ?></h4>
621
- <div class="body" style="display: none;">
622
- <label class="subheader"><?php _e( 'Enable', 'mycred' ); ?></label>
623
- <ol>
624
- <li>
625
- <input type="checkbox" name="mycred_pref_buycreds[active][]" id="mycred-gateway-<?php echo $key; ?>" value="<?php echo $key; ?>"<?php if ( $this->is_active( $key ) ) echo ' checked="checked"'; ?> />
626
- </li>
627
- </ol>
628
-
629
- <?php if ( array_key_exists( $key, $this->gateway_prefs ) && array_key_exists( 'sandbox', $this->gateway_prefs[ $key ] ) ) : ?>
630
-
631
- <label class="subheader" for="mycred-gateway-<?php echo $key; ?>-sandbox"><?php _e( 'Sandbox Mode', 'mycred' ); ?></label>
632
- <ol>
633
- <li>
634
- <input type="checkbox" name="mycred_pref_buycreds[gateway_prefs][<?php echo $key; ?>][sandbox]" id="mycred-gateway-<?php echo $key; ?>-sandbox" value="1"<?php checked( $this->gateway_prefs[ $key ]['sandbox'], 1 ); ?> /> <span class="description"><?php _e( 'Enable for test purchases.', 'mycred' ); ?></span>
635
- </li>
636
- </ol>
637
-
638
- <?php endif; ?>
639
-
640
- <?php $this->call( 'preferences', $data['callback'] ); ?>
641
-
642
- <input type="hidden" name="mycred_pref_buycreds[installed]" value="<?php echo $key; ?>" />
643
- </div>
644
- <?php
645
-
646
- }
647
- }
648
-
649
- ?>
650
- </div>
651
-
652
- <?php do_action( 'mycred_after_buycreds_page', $this ); ?>
653
-
654
- <p><?php submit_button( __( 'Update Settings', 'mycred' ), 'primary large', 'submit', false ); ?> <a href="http://mycred.me/product-category/buycred-gateways/" class="button button-secondary button-large" target="_blank"><?php _e( 'More Gateways', 'mycred' ); ?></a></p>
655
-
656
- </form>
657
-
658
- <?php do_action( 'mycred_bottom_buycreds_page', $this ); ?>
659
-
660
- <script type="text/javascript">
661
- jQuery(function($) {
662
- $( 'select.currency' ).change(function(){
663
- var target = $(this).attr( 'data-update' );
664
- $( '.' + target ).empty();
665
- $( '.' + target ).text( $(this).val() );
666
- });
667
- });
668
- </script>
669
- </div>
670
- <?php
671
-
672
- }
673
-
674
- /**
675
- * Sanititze Settings
676
- * @since 0.1
677
- * @version 1.3.1
678
- */
679
- public function sanitize_settings( $data ) {
680
-
681
- $data = apply_filters( 'mycred_buycred_save_prefs', $data );
682
- $installed = $this->get();
683
-
684
- if ( empty( $installed ) ) return $data;
685
-
686
- foreach ( $installed as $id => $gdata )
687
- $data['gateway_prefs'][ $id ] = $this->call( 'sanitise_preferences', $installed[ $id ]['callback'], ( ( array_key_exists( $id, $data['gateway_prefs'] ) ) ? $data['gateway_prefs'][ $id ] : array() ) );
688
-
689
- return $data;
690
-
691
- }
692
-
693
- /**
694
- * Purchase Log Screen Options
695
- * @since 1.4
696
- * @version 1.1
697
- */
698
- public function screen_options() {
699
-
700
- if ( empty( $this->purchase_log ) ) return;
701
-
702
- $meta_key = 'mycred_payments_' . str_replace( MYCRED_SLUG . '-purchases-', '', $_GET['page'] );
703
-
704
- if ( isset( $_REQUEST['wp_screen_options']['option'] ) && isset( $_REQUEST['wp_screen_options']['value'] ) ) {
705
-
706
- if ( $_REQUEST['wp_screen_options']['option'] == $meta_key ) {
707
- $value = absint( $_REQUEST['wp_screen_options']['value'] );
708
- update_user_meta( $this->current_user_id, $meta_key, $value );
709
- }
710
-
711
- }
712
-
713
- $args = array(
714
- 'label' => __( 'Payments', 'mycred' ),
715
- 'default' => 10,
716
- 'option' => $meta_key
717
- );
718
- add_screen_option( 'per_page', $args );
719
-
720
- }
721
-
722
- /**
723
- * Purchase Log
724
- * Render the dedicated admin screen where all point purchases are shown from the myCRED Log.
725
- * This screen is added in for each point type that is set to be for sale.
726
- * @since 1.4
727
- * @version 1.4.2
728
- */
729
- public function purchase_log_page() {
730
-
731
- $point_type = str_replace( 'mycred-purchases-', '', $_GET['page'] );
732
- $installed = $this->get();
733
-
734
- $mycred = $this->core;
735
- if ( $point_type != MYCRED_DEFAULT_TYPE_KEY && mycred_point_type_exists( $point_type ) )
736
- $mycred = mycred( $point_type );
737
-
738
- // Security (incase the user has setup different capabilities to manage this particular point type)
739
- if ( ! $mycred->can_edit_creds() ) wp_die( 'Access Denied' );
740
-
741
- $search_args = mycred_get_search_args();
742
-
743
- $per_page = mycred_get_user_meta( $this->current_user_id, 'mycred_payments_' . $point_type, '', true );
744
- if ( empty( $per_page ) || $per_page < 1 ) $per_page = 10;
745
-
746
- // Entries per page
747
- if ( ! array_key_exists( 'number', $search_args ) )
748
- $search_args['number'] = absint( $per_page );
749
-
750
- // Get references
751
- $references = apply_filters( 'mycred_buycred_log_refs', array(
752
- 'buy_creds_with_paypal_standard',
753
- 'buy_creds_with_skrill',
754
- 'buy_creds_with_zombaio',
755
- 'buy_creds_with_netbilling',
756
- 'buy_creds_with_bitpay',
757
- 'buy_creds_with_bank'
758
- ), $this, $point_type );
759
-
760
- $search_args['ctype'] = $point_type;
761
-
762
- $search_args['ref'] = array(
763
- 'ids' => $references,
764
- 'compare' => 'IN'
765
- );
766
-
767
- $log = new myCRED_Query_Log( $search_args );
768
-
769
- $log->headers = apply_filters( 'mycred_buycred_log_columns', array(
770
- 'column-gateway' => __( 'Gateway', 'mycred' ),
771
- 'column-username' => __( 'Buyer', 'mycred' ),
772
- 'column-date' => __( 'Date', 'mycred' ),
773
- 'column-amount' => $mycred->plural(),
774
- 'column-payed' => __( 'Payed', 'mycred' ),
775
- 'column-tranid' => __( 'Transaction ID', 'mycred' )
776
- ) );
777
-
778
- $filter_url = admin_url( 'admin.php?page=' . MYCRED_SLUG . '-purchases-' . $point_type );
779
-
780
- ?>
781
- <div class="wrap list" id="myCRED-wrap">
782
- <h1><?php _e( 'Purchase Log', 'mycred' ); ?></h1>
783
-
784
- <?php $log->filter_dates( esc_url( $filter_url ) ); ?>
785
-
786
- <form method="get" action="" name="mycred-buycred-form" novalidate>
787
- <input type="hidden" name="page" value="<?php echo esc_attr( $_GET['page'] ); ?>" />
788
- <?php
789
-
790
- if ( array_key_exists( 's', $search_args ) )
791
- echo '<input type="hidden" name="s" value="' . esc_attr( $search_args['s'] ) . '" />';
792
-
793
- if ( isset( $_GET['ref'] ) )
794
- echo '<input type="hidden" name="show" value="' . esc_attr( $_GET['ref'] ) . '" />';
795
-
796
- if ( isset( $_GET['show'] ) )
797
- echo '<input type="hidden" name="show" value="' . esc_attr( $_GET['show'] ) . '" />';
798
-
799
- if ( array_key_exists( 'order', $search_args ) )
800
- echo '<input type="hidden" name="order" value="' . esc_attr( $search_args['order'] ) . '" />';
801
-
802
- if ( array_key_exists( 'paged', $search_args ) )
803
- echo '<input type="hidden" name="paged" value="' . esc_attr( $search_args['paged'] ) . '" />';
804
-
805
- $log->search();
806
-
807
- ?>
808
-
809
- <?php do_action( 'mycred_above_payment_log_table', $this ); ?>
810
-
811
- <div class="tablenav top">
812
-
813
- <?php $log->table_nav( 'top' ); ?>
814
-
815
- </div>
816
- <table class="table wp-list-table widefat mycred-table log-entries" cellspacing="0">
817
- <thead>
818
- <tr>
819
- <?php
820
-
821
- foreach ( $log->headers as $col_id => $col_title )
822
- echo '<th scope="col" id="' . str_replace( 'column-', '', $col_id ) . '" class="manage-column ' . $col_id . '">' . $col_title . '</th>';
823
-
824
- ?>
825
- </tr>
826
- </thead>
827
- <tfoot>
828
- <tr>
829
- <?php
830
-
831
- foreach ( $log->headers as $col_id => $col_title )
832
- echo '<th scope="col" class="manage-column ' . $col_id . '">' . $col_title . '</th>';
833
-
834
- ?>
835
- </tr>
836
- </tfoot>
837
- <tbody id="the-list">
838
- <?php
839
-
840
- // If we have results
841
- if ( $log->have_entries() ) {
842
-
843
- // Prep
844
- $date_format = get_option( 'date_format' ) . ' ' . get_option( 'time_format' );
845
- $entry_data = '';
846
- $alt = 0;
847
-
848
- // Loop results
849
- foreach ( $log->results as $log_entry ) {
850
-
851
- // Highlight alternate rows
852
- $alt = $alt+1;
853
- if ( $alt % 2 == 0 )
854
- $class = ' alt';
855
- else
856
- $class = '';
857
-
858
- // Prep Sales data for use in columns
859
- $sales_data = $this->get_sales_data_from_log_data( $log_entry->data );
860
- list ( $buyer_id, $payer_id, $amount, $cost, $currency, $token, $other ) = $sales_data;
861
-
862
- // Default Currency
863
- if ( empty( $currency ) )
864
- $currency = 'USD';
865
-
866
- $gateway_name = str_replace( 'buy_creds_with_', '', $log_entry->ref );
867
-
868
- // Color rows based on if the transaction was made in Sandbox mode or using a gateway that no longer is used.
869
- if ( ! array_key_exists( str_replace( '_', '-', $gateway_name ), $installed ) )
870
- $style = ' style="color:silver;"';
871
- elseif ( ! $this->is_active( str_replace( '_', '-', $gateway_name ) ) )
872
- $style = ' style="color:gray;"';
873
- elseif ( substr( $log_entry->entry, 0, 4 ) == 'TEST' )
874
- $style = ' style="color:orange;"';
875
- else
876
- $style = '';
877
-
878
- echo '<tr class="myCRED-log-row' . $class . '" id="mycred-log-entry-' . $log_entry->id . '">';
879
-
880
- // Run though columns
881
- foreach ( $log->headers as $column_id => $column_name ) {
882
-
883
- echo '<td class="' . $column_id . '"' . $style . '>';
884
-
885
- switch ( $column_id ) {
886
-
887
- // Used gateway
888
- case 'column-gateway' :
889
-
890
- $gateway = str_replace( array( '-', '_' ), ' ', $gateway_name );
891
- echo ucwords( $gateway );
892
-
893
- break;
894
-
895
- // Username Column
896
- case 'column-username' :
897
-
898
- $user = get_userdata( $log_entry->user_id );
899
- if ( $user === false )
900
- echo 'ID: ' . $log_entry->user_id;
901
- else
902
- echo $user->display_name . ' <em><small>(ID: ' . $log_entry->user_id . ')</small></em>';
903
-
904
- break;
905
-
906
- // Date & Time Column
907
- case 'column-date' :
908
-
909
- echo date( $date_format, $log_entry->time );
910
-
911
- break;
912
-
913
- // Amount Column
914
- case 'column-amount' :
915
-
916
- echo $mycred->format_creds( $log_entry->creds );
917
-
918
- break;
919
-
920
- // Amount Paid
921
- case 'column-payed' :
922
-
923
- $cost = 'n/a';
924
- $currency = '';
925
- $data = maybe_unserialize( $log_entry->data );
926
- if ( is_array( $data ) && array_key_exists( 'sales_data', $data ) ) {
927
-
928
- $sales_data = explode( '|', $data['sales_data'] );
929
- if ( count( $sales_data ) >= 5 ) {
930
- $cost = $sales_data[3];
931
- $currency = $sales_data[4];
932
- }
933
-
934
- }
935
-
936
- if ( $cost === 'n/a' )
937
- echo 'n/a';
938
-
939
- else {
940
-
941
- $rendered_cost = apply_filters( 'mycred_buycred_display_cost', $cost . ' ' . $currency, $sales_data, $log_entry, $gateway_name );
942
- $rendered_cost = apply_filters( 'mycred_buycred_display_cost_' . $gateway_name, $rendered_cost, $sales_data, $log_entry );
943
-
944
- echo $rendered_cost;
945
-
946
- }
947
-
948
- break;
949
-
950
- // Transaction ID
951
- case 'column-tranid' :
952
-
953
- $transaction_id = $log_entry->time . $log_entry->user_id;
954
- $saved_data = maybe_unserialize( $log_entry->data );
955
- if ( isset( $saved_data['txn_id'] ) )
956
- $transaction_id = $saved_data['txn_id'];
957
- elseif ( isset( $saved_data['transaction_id'] ) )
958
- $transaction_id = $saved_data['transaction_id'];
959
-
960
- echo $transaction_id;
961
-
962
- break;
963
-
964
- default :
965
-
966
- do_action( "mycred_payment_log_{$column_id}", $log_entry );
967
- do_action( "mycred_payment_log_{$column_id}_{$type}", $log_entry );
968
-
969
- break;
970
-
971
- }
972
-
973
- echo '</td>';
974
-
975
- }
976
-
977
- echo '</tr>';
978
-
979
- }
980
-
981
- }
982
-
983
- // No log entry
984
- else {
985
-
986
- echo '<tr><td colspan="' . count( $log->headers ) . '" class="no-entries">' . __( 'No purchases found', 'mycred' ) . '</td></tr>';
987
-
988
- }
989
-
990
- ?>
991
- </tbody>
992
- </table>
993
- <div class="tablenav bottom">
994
-
995
- <?php $log->table_nav( 'bottom' ); ?>
996
-
997
- </div>
998
-
999
- <?php do_action( 'mycred_below_payment_log_table', $this ); ?>
1000
-
1001
- </form>
1002
- </div>
1003
- <?php
1004
-
1005
- }
1006
-
1007
- /**
1008
- * Get Sales Data from Log Data
1009
- * @since 1.4
1010
- * @version 1.0.1
1011
- */
1012
- public function get_sales_data_from_log_data( $log_data = '' ) {
1013
-
1014
- $defaults = array( '', '', '', '', '', '', '' );
1015
- $log_data = maybe_unserialize( $log_data );
1016
-
1017
- $found_data = array();
1018
- if ( is_array( $log_data ) && array_key_exists( 'sales_data', $log_data ) ) {
1019
- if ( is_array( $log_data['sales_data'] ) )
1020
- $found_data = $log_data['sales_data'];
1021
- else
1022
- $found_data = explode( '|', $log_data['sales_data'] );
1023
- }
1024
- elseif ( ! empty( $log_data ) && ! is_array( $log_data ) ) {
1025
- $try = explode( '|', $log_data );
1026
- if ( count( $try == 7 ) )
1027
- $found_data = $log_data;
1028
- }
1029
-
1030
- return wp_parse_args( $found_data, $defaults );
1031
-
1032
- }
1033
-
1034
- /**
1035
- * User Rates Admin Screen
1036
- * @since 1.5
1037
- * @version 1.0
1038
- */
1039
- public function exchange_rates_user_screen( $user ) {
1040
-
1041
- // Make sure buyCRED is setup
1042
- if ( ! isset( $this->core->buy_creds['types'] ) || empty( $this->core->buy_creds['types'] ) ) return;
1043
-
1044
- // Only visible to admins
1045
- if ( ! mycred_is_admin() ) return;
1046
-
1047
- $mycred_types = mycred_get_types( true );
1048
- $point_types_for_sale = $this->core->buy_creds['types'];
1049
- $installed = $this->get();
1050
- $available_options = array();
1051
-
1052
- foreach ( $installed as $gateway_id => $prefs ) {
1053
-
1054
- // Gateway is not active or settings have not yet been saved
1055
- if ( ! $this->is_active( $gateway_id ) || ! array_key_exists( $gateway_id, $this->gateway_prefs ) || ! $prefs['custom_rate'] ) continue;
1056
-
1057
- $gateway_prefs = $this->gateway_prefs[ $gateway_id ];
1058
-
1059
- // Need a currency
1060
- if ( array_key_exists( 'currency', $gateway_prefs ) && $gateway_prefs['currency'] == '' ) continue;
1061
-
1062
- if ( ! array_key_exists( 'currency', $gateway_prefs ) )
1063
- $gateway_prefs['currency'] = 'USD';
1064
-
1065
- $setup = array( 'name' => $prefs['title'], 'currency' => $gateway_prefs['currency'], 'types' => array() );
1066
-
1067
- foreach ( $mycred_types as $point_type_key => $label ) {
1068
-
1069
- $row = array( 'name' => $label, 'enabled' => false, 'excluded' => true, 'default' => 0, 'override' => false, 'custom' => '', 'before' => '' );
1070
-
1071
- if ( in_array( $point_type_key, $point_types_for_sale ) && array_key_exists( $point_type_key, $gateway_prefs['exchange'] ) ) {
1072
-
1073
- $row['enabled'] = true;
1074
-
1075
- $mycred = mycred( $point_type_key );
1076
-
1077
- if ( ! $mycred->exclude_user( $user->ID ) ) {
1078
-
1079
- $row['excluded'] = false;
1080
- $row['default'] = $gateway_prefs['exchange'][ $point_type_key ];
1081
-
1082
- $row['before'] = $mycred->format_creds( 1 ) . ' = ';
1083
-
1084
- $saved_overrides = (array) mycred_get_user_meta( $user->ID, 'mycred_buycred_rates_' . $point_type_key, '', true );
1085
-
1086
- if ( ! empty( $saved_overrides ) && array_key_exists( $gateway_id, $saved_overrides ) ) {
1087
-
1088
- $row['override'] = true;
1089
- $row['custom'] = $saved_overrides[ $gateway_id ];
1090
-
1091
- }
1092
-
1093
- }
1094
-
1095
- }
1096
-
1097
- $setup['types'][ $point_type_key ] = $row;
1098
-
1099
- }
1100
-
1101
- $available_options[ $gateway_id ] = $setup;
1102
-
1103
- }
1104
-
1105
- if ( empty( $available_options ) ) return;
1106
-
1107
- ?>
1108
- <p class="mycred-p"><?php _e( 'Users exchange rate when buying points.', 'mycred' ); ?></p>
1109
- <table class="form-table mycred-inline-table">
1110
- <?php
1111
-
1112
- foreach ( $available_options as $gateway_id => $setup ) :
1113
-
1114
- ?>
1115
- <tr>
1116
- <th scope="row"><?php echo esc_attr( $setup['name'] ); ?></th>
1117
- <td>
1118
- <fieldset id="mycred-buycred-list" class="buycred-list">
1119
- <legend class="screen-reader-text"><span><?php _e( 'buyCRED Exchange Rates', 'mycred' ); ?></span></legend>
1120
- <?php
1121
-
1122
- foreach ( $setup['types'] as $type_id => $data ) {
1123
-
1124
- // This point type is not for sale
1125
- if ( ! $data['enabled'] ) {
1126
-
1127
- ?>
1128
- <div class="mycred-wrapper buycred-wrapper disabled-option color-option">
1129
- <div><?php printf( _x( 'Buying %s', 'Points Name', 'mycred' ), $data['name'] ); ?></div>
1130
- <div class="balance-row">
1131
- <div class="balance-view"><?php _e( 'Disabled', 'mycred' ); ?></div>
1132
- <div class="balance-desc"><em><?php _e( 'This point type is not for sale.', 'mycred' ); ?></em></div>
1133
- </div>
1134
- </div>
1135
- <?php
1136
-
1137
- }
1138
-
1139
- // This user is excluded from this point type
1140
- elseif ( $data['excluded'] ) {
1141
-
1142
- ?>
1143
- <div class="mycred-wrapper buycred-wrapper excluded-option color-option">
1144
- <div><?php printf( _x( 'Buying %s', 'Buying Points', 'mycred' ), $data['name'] ); ?></div>
1145
- <div class="balance-row">
1146
- <div class="balance-view"><?php _e( 'Excluded', 'mycred' ); ?></div>
1147
- <div class="balance-desc"><em><?php printf( _x( 'User can not buy %s', 'Points Name', 'mycred' ), $data['name'] ); ?></em></div>
1148
- </div>
1149
- </div>
1150
- <?php
1151
-
1152
- }
1153
-
1154
- // Eligeble user
1155
- else {
1156
-
1157
- ?>
1158
- <div class="mycred-wrapper buycred-wrapper color-option selected">
1159
- <div><?php printf( _x( 'Buying %s', 'Buying Points', 'mycred' ), $data['name'] ); ?></div>
1160
- <div class="balance-row">
1161
- <div class="balance-view"><?php echo $data['before']; ?><input type="text" name="mycred_adjust_users_buyrates[<?php echo $type_id; ?>][<?php echo $gateway_id; ?>]" placeholder="<?php echo $data['default']; ?>" value="<?php if ( $data['override'] ) echo esc_attr( $data['custom'] ); ?>" class="short" size="8" /><?php echo ' ' . $setup['currency']; ?></div>
1162
- <div class="balance-desc"><em><?php _e( 'Leave empty to use the default rate.', 'mycred' ); ?></em></div>
1163
- </div>
1164
- </div>
1165
- <?php
1166
-
1167
- }
1168
-
1169
- }
1170
-
1171
- ?>
1172
- </fieldset>
1173
- </td>
1174
- </tr>
1175
- <?php
1176
-
1177
- endforeach;
1178
-
1179
- ?>
1180
- </table>
1181
- <hr />
1182
- <script type="text/javascript">
1183
- jQuery(function($) {
1184
-
1185
- $( '.buycred-wrapper label input.trigger-buycred' ).change(function(){
1186
-
1187
- if ( $(this).val().length > 0 )
1188
- $(this).parent().parent().parent().addClass( 'selected' );
1189
-
1190
- else
1191
- $(this).parent().parent().parent().removeClass( 'selected' );
1192
-
1193
- });
1194
-
1195
- });
1196
- </script>
1197
- <?php
1198
-
1199
- }
1200
-
1201
- /**
1202
- * Save Override
1203
- * @since 1.5
1204
- * @version 1.2
1205
- */
1206
- public function save_manual_exchange_rates( $user_id ) {
1207
-
1208
- if ( ! mycred_is_admin() ) return;
1209
-
1210
- if ( isset( $_POST['mycred_adjust_users_buyrates'] ) && is_array( $_POST['mycred_adjust_users_buyrates'] ) && ! empty( $_POST['mycred_adjust_users_buyrates'] ) ) {
1211
-
1212
- foreach ( $_POST['mycred_adjust_users_buyrates'] as $ctype => $gateway ) {
1213
-
1214
- $ctype = sanitize_key( $ctype );
1215
- $mycred = mycred( $ctype );
1216
-
1217
- if ( ! $mycred->exclude_user( $user_id ) ) {
1218
-
1219
- $new_rates = array();
1220
- foreach ( (array) $gateway as $gateway_id => $rate ) {
1221
-
1222
- if ( $rate == '' ) continue;
1223
-
1224
- if ( $rate != 1 && in_array( substr( $rate, 0, 1 ), array( '.', ',' ) ) )
1225
- $rate = (float) '0' . $rate;
1226
-
1227
- $new_rates[ $gateway_id ] = $rate;
1228
-
1229
- }
1230
-
1231
- if ( ! empty( $new_rates ) )
1232
- mycred_update_user_meta( $user_id, 'mycred_buycred_rates_' . $ctype, '', $new_rates );
1233
- else
1234
- mycred_delete_user_meta( $user_id, 'mycred_buycred_rates_' . $ctype );
1235
-
1236
- }
1237
-
1238
- }
1239
-
1240
- }
1241
-
1242
- }
1243
-
1244
- /**
1245
- * Render Shortcode Basic
1246
- * This shortcode returns a link element to a specified payment gateway.
1247
- * @since 0.1
1248
- * @version 1.6
1249
- */
1250
- public function render_shortcode_basic( $atts, $title = '' ) {
1251
-
1252
- // Make sure the add-on has been setup
1253
- if ( ! isset( $this->core->buy_creds ) ) {
1254
- if ( mycred_is_admin() )
1255
- return '<p style="color:red;"><a href="' . $this->get_settings_url( 'buycred_module' ) . '">This Add-on needs to setup before you can use this shortcode.</a></p>';
1256
- else
1257
- return '';
1258
- }
1259
-
1260
- extract( shortcode_atts( array(
1261
- 'gateway' => '',
1262
- 'ctype' => MYCRED_DEFAULT_TYPE_KEY,
1263
- 'amount' => '',
1264
- 'gift_to' => '',
1265
- 'class' => 'mycred-buy-link btn btn-primary btn-lg',
1266
- 'login' => $this->core->template_tags_general( $this->core->buy_creds['login'] )
1267
- ), $atts ) );
1268
-
1269
- // Make sure we are trying to sell a point type that is allowed to be purchased
1270
- if ( ! in_array( $ctype, $this->core->buy_creds['types'] ) )
1271
- $ctype = $this->core->buy_creds['types'][0];
1272
-
1273
- if ( $ctype == $this->core->cred_id )
1274
- $mycred = $this->core;
1275
- else
1276
- $mycred = mycred( $ctype );
1277
-
1278
- global $post;
1279
-
1280
- // If we are not logged in
1281
- if ( $this->current_user_id == 0 ) return '<div class="mycred-buy login">' . $mycred->template_tags_general( $login ) . '</div>';
1282
-
1283
- // Arguments
1284
- $args = array( 'ctype' => $ctype, 'token' => wp_create_nonce( 'mycred-buy-creds' ) );
1285
-
1286
- // Gateways
1287
- $installed = $this->get();
1288
-
1289
- if ( empty( $installed ) ) return 'No gateways installed.';
1290
- elseif ( ! empty( $gateway ) && ! array_key_exists( $gateway, $installed ) ) return 'Gateway does not exist.';
1291
- elseif ( empty( $this->active ) ) return 'No active gateways found.';
1292
-
1293
- // If no gateway is set, chooce the first one that is active
1294
- if ( empty( $gateway ) || ! array_key_exists( $gateway, $installed ) ) {
1295
-
1296
- $gateway_to_use = false;
1297
- foreach ( $installed as $gateway_id => $info ) {
1298
- if ( ! $this->is_active( $gateway_id ) ) continue;
1299
- $gateway_to_use = $gateway_id;
1300
- break;
1301
- }
1302
-
1303
- // Doubt this should happen if we come this far but you can never be sure
1304
- if ( $gateway_to_use === false ) return 'No active gateways found.';
1305
-
1306
- $gateway = $gateway_to_use;
1307
-
1308
- }
1309
-
1310
- $args['mycred_buy'] = $gateway;
1311
- $classes[] = $gateway;
1312
-
1313
- // Prep
1314
- $buyer_id = $this->current_user_id;
1315
- $recipient_id = $buyer_id;
1316
-
1317
- if ( $this->core->buy_creds['gifting']['authors'] && $gift_to == 'author' )
1318
- $recipient_id = $post->post_author;
1319
-
1320
- if ( $this->core->buy_creds['gifting']['members'] && absint( $gift_to ) !== 0 )
1321
- $recipient_id = absint( $gift_to );
1322
-
1323
- if ( $recipient_id !== $buyer_id )
1324
- $args['gift_to'] = $recipient_id;
1325
-
1326
- // Allow user related template tags to be used in the button label
1327
- $title = $mycred->template_tags_general( $title );
1328
- $title = $mycred->template_tags_user( $title, $recipient_id );
1329
-
1330
- // Amount
1331
- $minimum = $mycred->number( $this->core->buy_creds['minimum'] );
1332
- $amount = $mycred->number( $amount );
1333
-
1334
- // Enfoce the minimum we set in our buyCRED settings
1335
- if ( $amount < $minimum )
1336
- $amount = $minimum;
1337
-
1338
- $args['amount'] = $amount;
1339
-
1340
- // Let others add items to the arguments
1341
- $args = apply_filters( 'mycred_buy_args', $args, $atts, $mycred );
1342
-
1343
- // Classes
1344
- $classes = explode( ' ', $class );
1345
-
1346
- if ( empty( $classes ) )
1347
- $classes[] = 'mycred-buy-link';
1348
-
1349
- $current_url = set_url_scheme( 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'] );
1350
-
1351
- // Construct anchor element to take us to the checkout page
1352
- return '<a href="' . esc_url( add_query_arg( $args, $current_url ) ) . '" class="' . implode( ' ', $classes ) . '" title="' . esc_attr( strip_tags( $title ) ) . '">' . do_shortcode( $title ) . '</a>';
1353
-
1354
- }
1355
-
1356
- /**
1357
- * Render Shortcode Form
1358
- * Returns an advanced version allowing for further customizations.
1359
- * @since 0.1
1360
- * @version 1.6
1361
- */
1362
- public function render_shortcode_form( $atts, $content = '' ) {
1363
-
1364
- // Make sure the add-on has been setup
1365
- if ( ! isset( $this->core->buy_creds ) ) {
1366
- if ( mycred_is_admin() )
1367
- return '<p style="color:red;"><a href="' . $this->get_settings_url( 'buycred_module' ) . '">This Add-on needs to setup before you can use this shortcode.</a></p>';
1368
- else
1369
- return '';
1370
- }
1371
-
1372
- extract( shortcode_atts( array(
1373
- 'button' => __( 'Buy Now', 'mycred' ),
1374
- 'gateway' => '',
1375
- 'ctype' => MYCRED_DEFAULT_TYPE_KEY,
1376
- 'amount' => '',
1377
- 'gift_to' => '',
1378
- 'gift_by' => __( 'Username', 'mycred' ),
1379
- 'inline' => 0
1380
- ), $atts ) );
1381
-
1382
- // If we are not logged in
1383
- if ( $this->current_user_id == 0 ) return $content;
1384
-
1385
- // Get gateways
1386
- $installed = $this->get();
1387
-
1388
- // Catch errors
1389
- if ( empty( $installed ) ) return 'No gateways installed.';
1390
- elseif ( ! empty( $gateway ) && ! array_key_exists( $gateway, $installed ) ) return 'Gateway does not exist.';
1391
- elseif ( empty( $this->active ) ) return 'No active gateways found.';
1392
- elseif ( ! empty( $gateway ) && ! $this->is_active( $gateway ) ) return 'The selected gateway is not active.';
1393
-
1394
- // Make sure we are trying to sell a point type that is allowed to be purchased
1395
- if ( ! in_array( $ctype, $this->core->buy_creds['types'] ) )
1396
- $ctype = $this->core->buy_creds['types'][0];
1397
-
1398
- if ( $ctype == $this->core->cred_id )
1399
- $mycred = $this->core;
1400
- else
1401
- $mycred = mycred( $ctype );
1402
-
1403
- global $post;
1404
-
1405
- // Prep
1406
- $buyer_id = $this->current_user_id;
1407
- $recipient_id = $buyer_id;
1408
- $classes = array( 'myCRED-buy-form' );
1409
-
1410
- if ( $this->core->buy_creds['gifting']['authors'] && $gift_to == 'author' )
1411
- $recipient_id = $post->post_author;
1412
-
1413
- if ( $this->core->buy_creds['gifting']['members'] && absint( $gift_to ) !== 0 )
1414
- $recipient_id = absint( $gift_to );
1415
-
1416
- $button_label = $mycred->template_tags_general( $button );
1417
-
1418
- if ( ! empty( $gateway ) ) {
1419
- $gateway_name = explode( ' ', $installed[ $gateway ]['title'] );
1420
- $button_label = str_replace( '%gateway%', $gateway_name[0], $button_label );
1421
- $classes[] = $gateway_name[0];
1422
- }
1423
-
1424
- $amounts = array();
1425
- $minimum = $this->core->number( $this->core->buy_creds['minimum'] );
1426
- if ( ! empty( $amount ) ) {
1427
- $_amounts = explode( ',', $amount );
1428
- foreach ( $_amounts as $_amount ) {
1429
- $_amount = $mycred->number( $_amount );
1430
- if ( $_amount === $mycred->zero() ) continue;
1431
- $amounts[] = $_amount;
1432
- }
1433
- }
1434
-
1435
- ob_start();
1436
-
1437
- ?>
1438
- <div class="row">
1439
- <div class="col-xs-12">
1440
- <form method="post" class="form<?php if ( $inline == 1 ) echo '-inline'; ?> <?php echo implode( ' ', $classes ); ?>" action="">
1441
- <input type="hidden" name="token" value="<?php echo wp_create_nonce( 'mycred-buy-creds' ); ?>" />
1442
- <input type="hidden" name="transaction_id" value="<?php echo strtoupper( wp_generate_password( 6, false, false ) ); ?>" />
1443
- <input type="hidden" name="ctype" value="<?php echo $ctype; ?>" />
1444
-
1445
- <div class="form-group">
1446
- <label><?php echo $mycred->plural(); ?></label>
1447
- <?php
1448
-
1449
- // No amount given - user must nominate the amount
1450
- if ( count( $amounts ) == 0 ) :
1451
-
1452
- ?>
1453
- <input type="text" name="amount" class="form-control" placeholder="<?php echo $mycred->format_creds( $minimum ); ?>" min="<?php echo $minimum; ?>" value="" />
1454
- <?php
1455
-
1456
- // Amount given
1457
- else :
1458
-
1459
- // One amount - this is the amount a user must buy
1460
- if ( count( $amount ) > 1 ) {
1461
-
1462
- ?>
1463
- <p class="form-control-static"><?php echo $mycred->format_creds( $amounts[0] ); ?></p>
1464
- <input type="hidden" name="amount" value="<?php echo $amounts[0]; ?>" />
1465
- <?php
1466
-
1467
- }
1468
-
1469
- // Multiple items - user selects the amount from a dropdown menu
1470
- else {
1471
-
1472
- ?>
1473
- <select name="amount" class="form-control">
1474
- <?php
1475
-
1476
- foreach ( $amounts as $amount )
1477
- echo '<option value="' . $amount . '">' . $mycred->format_creds( $amount ) . '</option>';
1478
-
1479
- ?>
1480
- </select>
1481
- <?php
1482
-
1483
- }
1484
-
1485
- endif;
1486
-
1487
- ?>
1488
- <?php if ( $gift_to != '' ) : ?>
1489
-
1490
- <div class="form-group">
1491
- <label for="gift_to"><?php _e( 'Recipient', 'mycred' ); ?></label>
1492
- <?php
1493
-
1494
- // Post author - show the authors name
1495
- if ( $this->core->buy_creds['gifting']['authors'] && $gift_to == 'author' ) {
1496
-
1497
- $author = get_userdata( $recipient_id );
1498
-
1499
- ?>
1500
- <p class="form-control-static"><?php echo $author->display_name; ?></p>
1501
- <input type="hidden" name="gift_to" value="<?php echo $recipient_id; ?>" />
1502
- <?php
1503
-
1504
- }
1505
-
1506
- // Specific User - show the members name
1507
- elseif ( $this->core->buy_creds['gifting']['members'] && absint( $gift_to ) !== 0 ) {
1508
-
1509
- $member = get_userdata( $recipient_id );
1510
-
1511
- ?>
1512
- <p class="form-control-static"><?php echo $member->display_name; ?></p>
1513
- <input type="hidden" name="gift_to" value="<?php echo $recipient_id; ?>" />
1514
- <?php
1515
-
1516
- }
1517
-
1518
- // Users need to nominate recipient
1519
- else {
1520
-
1521
- ?>
1522
- <input type="text" class="form-control pick-user" name="gift_to" placeholder="<?php echo $gift_by; ?>" value="" />
1523
- <?php
1524
-
1525
- }
1526
-
1527
- ?>
1528
- </div>
1529
-
1530
- <?php endif; ?>
1531
-
1532
- <?php if ( empty( $gateway ) && count( $installed ) > 1 ) : ?>
1533
-
1534
- <div class="form-group">
1535
- <label for="gateway"><?php _e( 'Pay Using', 'mycred' ); ?></label>
1536
- <select name="mycred_buy" class="form-control">
1537
- <?php
1538
-
1539
- foreach ( $installed as $gateway_id => $info ) {
1540
-
1541
- if ( $this->is_active( $gateway_id ) )
1542
- echo '<option value="' . $gateway_id . '">' . $info['title'] . '</option>';
1543
-
1544
- }
1545
-
1546
- ?>
1547
- </select>
1548
- </div>
1549
-
1550
- <?php else : ?>
1551
-
1552
- <input type="hidden" name="mycred_buy" value="<?php echo $gateway; ?>" />
1553
-
1554
- <?php endif; ?>
1555
-
1556
- <div class="form-group">
1557
- <input type="submit" class="btn btn-primary btn-block btn-lg" value="<?php echo $button_label; ?>" />
1558
- </div>
1559
- </div>
1560
-
1561
- </form>
1562
- </div>
1563
- </div>
1564
- <?php
1565
-
1566
- $content = ob_get_contents();
1567
- ob_end_clean();
1568
-
1569
- return $content;
1570
-
1571
- }
1572
-
1573
- }
1574
- endif;
1575
-
1576
- /**
1577
- * Load buyCRED Module
1578
- * @since 1.7
1579
- * @version 1.0
1580
- */
1581
- if ( ! function_exists( 'mycred_load_buycred_core_addon' ) ) :
1582
- function mycred_load_buycred_core_addon( $modules, $point_types ) {
1583
-
1584
- $modules['solo']['buycred'] = new myCRED_buyCRED_Module();
1585
- $modules['solo']['buycred']->load();
1586
-
1587
- return $modules;
1588
-
1589
- }
1590
- endif;
1591
- add_filter( 'mycred_load_modules', 'mycred_load_buycred_core_addon', 30, 2 );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
addons/buy-creds/modules/buycred-module-pending.php DELETED
@@ -1,862 +0,0 @@
1
- <?php
2
- if ( ! defined( 'MYCRED_PURCHASE' ) ) exit;
3
-
4
- /**
5
- * buyCRED_Pending_Payments class
6
- * @since 1.7
7
- * @version 1.0.1
8
- */
9
- if ( ! class_exists( 'buyCRED_Pending_Payments' ) ) :
10
- class buyCRED_Pending_Payments extends myCRED_Module {
11
-
12
- /**
13
- * Construct
14
- */
15
- function __construct( $type = MYCRED_DEFAULT_TYPE_KEY ) {
16
-
17
- parent::__construct( 'buyCRED_Pending_Payments', array(
18
- 'module_name' => 'pending_payments',
19
- 'option_id' => '',
20
- 'defaults' => array(),
21
- 'screen_id' => '',
22
- 'accordion' => false,
23
- 'add_to_core' => false,
24
- 'menu_pos' => 75
25
- ), $type );
26
-
27
- }
28
-
29
- /**
30
- * Load
31
- * @version 1.0.1
32
- */
33
- public function load() {
34
-
35
- add_action( 'mycred_init', array( $this, 'module_init' ), $this->menu_pos );
36
- add_action( 'mycred_admin_init', array( $this, 'module_admin_init' ), $this->menu_pos );
37
-
38
- }
39
-
40
- /**
41
- * Module Init
42
- * @since 1.7
43
- * @version 1.0.1
44
- */
45
- public function module_init() {
46
-
47
- $this->register_pending_payments();
48
-
49
- add_shortcode( 'mycred_buy_pending', array( $this, 'render_shortcode_pending' ) );
50
-
51
- add_action( 'mycred_add_menu', array( $this, 'add_to_menu' ), $this->menu_pos );
52
- add_action( 'template_redirect', array( $this, 'intercept_cancellations' ) );
53
-
54
- }
55
-
56
- /**
57
- * Intercept Cancellations
58
- * @since 1.7
59
- * @version 1.0.1
60
- */
61
- public function intercept_cancellations() {
62
-
63
- // Intercept payment cancellations
64
- if ( isset( $_REQUEST['buycred-cancel'] ) && isset( $_REQUEST['_token'] ) && wp_verify_nonce( $_REQUEST['_token'], 'buycred-cancel-pending-payment' ) ) {
65
-
66
- // Get pending payment object
67
- $pending_payment_id = sanitize_text_field( $_REQUEST['buycred-cancel'] );
68
- $pending_payment = buycred_get_pending_payment( $pending_payment_id );
69
-
70
- // Make sure pending payment still exists and that we are cancelling our own and not someone elses
71
- if ( $pending_payment === false || $pending_payment->buyer_id != get_current_user_id() ) return;
72
-
73
- // Delete cache
74
- delete_user_meta( $pending_payment->buyer_id, 'buycred_pending_payments' );
75
-
76
- // Move item to trash
77
- wp_trash_post( $pending_payment->payment_id );
78
-
79
- // Redirect
80
- wp_redirect( remove_query_arg( array( 'buycred-cancel', '_token' ) ) );
81
- exit;
82
-
83
- }
84
-
85
- }
86
-
87
- /**
88
- * Module Admin Init
89
- * @since 1.7
90
- * @version 1.0.1
91
- */
92
- public function module_admin_init() {
93
-
94
- add_filter( 'parent_file', array( $this, 'parent_file' ) );
95
- add_filter( 'submenu_file', array( $this, 'subparent_file' ), 10, 2 );
96
-
97
- add_action( 'admin_notices', array( $this, 'admin_notices' ) );
98
- add_filter( 'manage_buycred_payment_posts_columns', array( $this, 'adjust_column_headers' ) );
99
- add_action( 'manage_buycred_payment_posts_custom_column', array( $this, 'adjust_column_content' ), 10, 2 );
100
- add_filter( 'bulk_actions-edit-buycred_payment', array( $this, 'bulk_actions' ) );
101
- add_filter( 'post_row_actions', array( $this, 'adjust_row_actions' ), 10, 2 );
102
- add_action( 'admin_head-post.php', array( $this, 'edit_pending_payment_style' ) );
103
- add_action( 'admin_head-edit.php', array( $this, 'pending_payments_style' ) );
104
- add_action( 'save_post_buycred_payment', array( $this, 'save_pending_payment' ), 10, 2 );
105
- add_filter( 'post_updated_messages', array( $this, 'post_updated_messages' ) );
106
-
107
- // Intercept payment completions
108
- if ( isset( $_GET['credit'] ) && isset( $_GET['token'] ) && wp_verify_nonce( $_GET['token'], 'buycred-payout-pending' ) ) {
109
-
110
- $pending_id = absint( $_GET['credit'] );
111
-
112
- if ( $this->core->can_edit_creds() ) {
113
-
114
- $url = remove_query_arg( array( 'credit', 'token' ) );
115
-
116
- if ( buycred_complete_pending_payment( $pending_id ) ) {
117
- $url = add_query_arg( array( 'credited' => 1 ), $url );
118
- }
119
- else {
120
- $url = add_query_arg( array( 'credited' => 0 ), $url );
121
- }
122
-
123
- wp_safe_redirect( $url );
124
- exit;
125
-
126
- }
127
-
128
- }
129
-
130
- }
131
-
132
- /**
133
- * Register Pending Payments
134
- * @since 1.5
135
- * @version 1.0.1
136
- */
137
- protected function register_pending_payments() {
138
-
139
- $labels = array(
140
- 'name' => _x( 'Pending Payments', 'Post Type General Name', 'mycred' ),
141
- 'singular_name' => _x( 'Pending Payment', 'Post Type Singular Name', 'mycred' ),
142
- 'menu_name' => __( 'Pending Payments', 'mycred' ),
143
- 'parent_item_colon' => '',
144
- 'all_items' => __( 'Pending Payments', 'mycred' ),
145
- 'view_item' => '',
146
- 'add_new_item' => '',
147
- 'add_new' => '',
148
- 'edit_item' => __( 'Edit Pending Payment', 'mycred' ),
149
- 'update_item' => '',
150
- 'search_items' => '',
151
- 'not_found' => __( 'Not found in Trash', 'mycred' ),
152
- 'not_found_in_trash' => __( 'Not found in Trash', 'mycred' ),
153
- );
154
- $args = array(
155
- 'labels' => $labels,
156
- 'supports' => array( 'title', 'comments' ),
157
- 'hierarchical' => false,
158
- 'public' => false,
159
- 'show_ui' => true,
160
- 'show_in_menu' => false,
161
- 'show_in_nav_menus' => false,
162
- 'show_in_admin_bar' => false,
163
- 'can_export' => true,
164
- 'has_archive' => false,
165
- 'exclude_from_search' => true,
166
- 'publicly_queryable' => false,
167
- 'register_meta_box_cb' => array( $this, 'add_metaboxes' )
168
- );
169
- register_post_type( 'buycred_payment', apply_filters( 'mycred_setup_pending_payment', $args ) );
170
-
171
- }
172
-
173
- /**
174
- * Adjust Post Updated Messages
175
- * @since 1.7
176
- * @version 1.0
177
- */
178
- public function post_updated_messages( $messages ) {
179
-
180
- $messages['buycred_payment'] = array(
181
- 0 => '',
182
- 1 => __( 'Payment Updated.', 'mycred' ),
183
- 2 => __( 'Payment Updated.', 'mycred' ),
184
- 3 => __( 'Payment Updated.', 'mycred' ),
185
- 4 => __( 'Payment Updated.', 'mycred' ),
186
- 5 => __( 'Payment Updated.', 'mycred' ),
187
- 6 => __( 'Payment Updated.', 'mycred' ),
188
- 7 => __( 'Payment Updated.', 'mycred' ),
189
- 8 => __( 'Payment Updated.', 'mycred' ),
190
- 9 => __( 'Payment Updated.', 'mycred' ),
191
- 10 => ''
192
- );
193
-
194
- return $messages;
195
-
196
- }
197
-
198
- /**
199
- * Add Comment
200
- * @since 1.7
201
- * @version 1.0
202
- */
203
- public function add_comment( $post_id, $event = '', $time = NULL ) {
204
-
205
- return buycred_add_pending_comment( $post_id, $event, $time );
206
-
207
- }
208
-
209
- /**
210
- * Admin Notices
211
- * @since 1.7
212
- * @version 1.0
213
- */
214
- public function admin_notices() {
215
-
216
- if ( isset( $_GET['post_type'] ) && $_GET['post_type'] == 'buycred_payment' && isset( $_GET['credited'] ) ) {
217
- if ( $_GET['credited'] == 1 )
218
- echo '<div id="message" class="updated notice is-dismissible"><p>' . __( 'Pending payment successfully credited to account.', 'mycred' ) . '</p><button type="button" class="notice-dismiss"></button></div>';
219
- elseif ( $_GET['credited'] == 0 )
220
- echo '<div id="message" class="error notice is-dismissible"><p>' . __( 'Failed to credit the pending payment to account.', 'mycred' ) . '</p><button type="button" class="notice-dismiss"></button></div>';
221
- }
222
-
223
- }
224
-
225
- /**
226
- * Add Admin Menu Item
227
- * @since 1.7
228
- * @version 1.0.1
229
- */
230
- public function add_to_menu() {
231
-
232
- add_submenu_page(
233
- MYCRED_SLUG,
234
- __( 'Pending Payments', 'mycred' ),
235
- __( 'Pending Payments', 'mycred' ),
236
- $this->core->edit_creds_cap(),
237
- 'edit.php?post_type=buycred_payment'
238
- );
239
-
240
- }
241
-
242
- /**
243
- * Parent File
244
- * @since 1.7
245
- * @version 1.0.1
246
- */
247
- public function parent_file( $parent = '' ) {
248
-
249
- global $pagenow;
250
-
251
- if ( isset( $_GET['post'] ) && get_post_type( $_GET['post'] ) == 'buycred_payment' && isset( $_GET['action'] ) && $_GET['action'] == 'edit' )
252
- return MYCRED_SLUG;
253
-
254
- return $parent;
255
-
256
- }
257
-
258
- /**
259
- * Sub Parent File
260
- * @since 1.7.8
261
- * @version 1.0
262
- */
263
- public function subparent_file( $subparent = '', $parent = '' ) {
264
-
265
- global $pagenow;
266
-
267
- if ( ( $pagenow == 'edit.php' || $pagenow == 'post-new.php' ) && isset( $_GET['post_type'] ) && $_GET['post_type'] == 'buycred_payment' ) {
268
-
269
- return 'edit.php?post_type=buycred_payment';
270
-
271
- }
272
-
273
- elseif ( $pagenow == 'post.php' && isset( $_GET['post'] ) && get_post_type( $_GET['post'] ) == 'buycred_payment' ) {
274
-
275
- return 'edit.php?post_type=buycred_payment';
276
-
277
- }
278
-
279
- return $subparent;
280
-
281
- }
282
-
283
- /**
284
- * Pending Payment Column Headers
285
- * @since 1.5
286
- * @version 1.0
287
- */
288
- public function adjust_column_headers( $columns ) {
289
-
290
- return array(
291
- 'cb' => $columns['cb'],
292
- 'comments' => $columns['comments'],
293
- 'title' => __( 'Transaction ID', 'mycred' ),
294
- 'date' => $columns['date'],
295
- 'author' => __( 'Buyer', 'mycred' ),
296
- 'amount' => __( 'Amount', 'mycred' ),
297
- 'cost' => __( 'Cost', 'mycred' ),
298
- 'gateway' => __( 'Gateway', 'mycred' ),
299
- 'ctype' => __( 'Type', 'mycred' )
300
- );
301
-
302
- }
303
-
304
- /**
305
- * Pending Payment Column Content
306
- * @since 1.5
307
- * @version 1.0
308
- */
309
- public function adjust_column_content( $column_name, $post_id ) {
310
-
311
- global $mycred_modules;
312
-
313
- switch ( $column_name ) {
314
- case 'author' :
315
-
316
- $from = (int) get_post_meta( $post_id, 'from', true );
317
- $user = get_userdata( $from );
318
-
319
- if ( isset( $user->display_name ) )
320
- echo '<a href="' . add_query_arg( array( 'user_id' => $user->ID ), admin_url( 'user-edit.php' ) ) . '">' . $user->display_name . '</a>';
321
- else
322
- echo 'ID: ' . $from;
323
-
324
- break;
325
- case 'amount';
326
-
327
- $type = get_post_meta( $post_id, 'point_type', true );
328
- $amount = get_post_meta( $post_id, 'amount', true );
329
- $mycred = mycred( $type );
330
-
331
- echo $mycred->format_creds( $amount );
332
-
333
- break;
334
- case 'cost';
335
-
336
- $cost = get_post_meta( $post_id, 'cost', true );
337
- $currency = get_post_meta( $post_id, 'currency', true );
338
-
339
- echo $cost . ' ' . $currency;
340
-
341
- break;
342
- case 'gateway';
343
-
344
- $gateway = get_post_meta( $post_id, 'gateway', true );
345
- $installed = $mycred_modules['solo']['buycred']->get();
346
-
347
- if ( isset( $installed[ $gateway ] ) )
348
- echo $installed[ $gateway ]['title'];
349
- else
350
- echo $gateway;
351
-
352
- break;
353
- case 'ctype';
354
-
355
- $type = get_post_meta( $post_id, 'point_type', true );
356
-
357
- if ( isset( $this->point_types[ $type ] ) )
358
- echo $this->point_types[ $type ];
359
- else
360
- echo $type;
361
-
362
- break;
363
- }
364
-
365
- }
366
-
367
- /**
368
- * Adjust Bulk Actions
369
- * @since 1.5
370
- * @version 1.0
371
- */
372
- public function bulk_actions( $actions ) {
373
-
374
- unset( $actions['edit'] );
375
- return $actions;
376
-
377
- }
378
-
379
- /**
380
- * Pending Payment Row Actions
381
- * @since 1.5
382
- * @version 1.1
383
- */
384
- public function adjust_row_actions( $actions, $post ) {
385
-
386
- if ( $post->post_type == 'buycred_payment' && $post->post_status != 'trash' ) {
387
-
388
- unset( $actions['inline hide-if-no-js'] );
389
-
390
- // Add option to "Pay Out" now
391
- if ( $this->core->can_edit_creds() )
392
- $actions['credit'] = '<a href="' . esc_url( add_query_arg( array(
393
- 'post_type' => $post->post_type,
394
- 'credit' => $post->ID,
395
- 'token' => wp_create_nonce( 'buycred-payout-pending' )
396
- ), admin_url( 'edit.php' ) ) ) . '">' . __( 'Pay Out', 'mycred' ) . '</a>';
397
-
398
- }
399
-
400
- return $actions;
401
-
402
- }
403
-
404
- /**
405
- * Edit Pending Payment Style
406
- * @since 1.7
407
- * @version 1.0.1
408
- */
409
- public function edit_pending_payment_style() {
410
-
411
- global $post_type;
412
-
413
- if ( $post_type !== 'buycred_payment' ) return;
414
-
415
- wp_enqueue_style( 'mycred-bootstrap-grid' );
416
- wp_enqueue_style( 'mycred-forms' );
417
-
418
- add_filter( 'postbox_classes_buycred_payment_buycred-pending-payment', array( $this, 'metabox_classes' ) );
419
- add_filter( 'postbox_classes_buycred_payment_buycred-pending-comments', array( $this, 'metabox_classes' ) );
420
-
421
- ?>
422
- <script type="text/javascript">
423
- jQuery(function($){
424
-
425
- $(document).ready(function(){
426
- $( 'h1 .page-title-action, .wrap .page-title-action' ).remove();
427
- $( '#titlewrap #title' ).attr( 'readonly', 'readonly' ).addClass( 'readonly' );
428
- });
429
-
430
- });
431
- </script>
432
- <?php
433
-
434
- }
435
-
436
- /**
437
- * Pending Payment Style
438
- * @since 1.7
439
- * @version 1.0.1
440
- */
441
- public function pending_payments_style() {
442
-
443
- global $post_type;
444
-
445
- if ( $post_type !== 'buycred_payment' ) return;
446
-
447
- ?>
448
- <script type="text/javascript">
449
- jQuery(function($){
450
-
451
- $(document).ready(function(){
452
- $( 'h1 .page-title-action, .wrap .page-title-action' ).remove();
453
- });
454
-
455
- });
456
- </script>
457
- <?php
458
-
459
- }
460
-
461
- /**
462
- * Add Metaboxes
463
- * @since 1.7
464
- * @version 1.0
465
- */
466
- public function add_metaboxes() {
467
-
468
- add_meta_box( 'buycred-pending-payment', __( 'Pending Payment', 'mycred' ), array( $this, 'metabox_pending_payment' ), 'buycred_payment', 'normal', 'high' );
469
-
470
- if ( MYCRED_BUYCRED_PENDING_COMMENTS !== false )
471
- add_meta_box( 'buycred-pending-comments', __( 'History', 'mycred' ), array( $this, 'metabox_pending_comments' ), 'buycred_payment', 'normal', 'default' );
472
-
473
- remove_meta_box( 'commentstatusdiv', 'buycred_payment', 'normal' );
474
- remove_meta_box( 'commentsdiv', 'buycred_payment', 'normal' );
475
-
476
- remove_meta_box( 'submitdiv', 'buycred_payment', 'side' );
477
- add_meta_box( 'submitdiv', __( 'Actions', 'mycred' ), array( $this, 'metabox_pending_actions' ), 'buycred_payment', 'side', 'high' );
478
-
479
- }
480
-
481
- /**
482
- * Metabox: Pending Actions
483
- * @since 1.7
484
- * @version 1.0
485
- */
486
- public function metabox_pending_actions( $post ) {
487
-
488
- $payout_url = add_query_arg( array(
489
- 'post_type' => $post->post_type,
490
- 'credit' => $post->ID,
491
- 'token' => wp_create_nonce( 'buycred-payout-pending' )
492
- ), admin_url( 'edit.php' ) );
493
-
494
- $delete_url = get_delete_post_link( $post->ID );
495
-
496
- ?>
497
- <div class="submitbox mycred-metabox" id="submitpost">
498
- <div id="minor-publishing">
499
- <div style="display:none;">
500
- <?php submit_button( __( 'Save', 'mycred' ), 'button', 'save' ); ?>
501
- </div>
502
-
503
- <div id="minor-publishing-actions">
504
-
505
- <div><a href="<?php echo $payout_url; ?>" class="button button-secondary button-block"><?php _e( 'Pay Out', 'mycred' ); ?></a></div>
506
- <div><a href="<?php echo $delete_url; ?>" class="button button-secondary button-block"><?php _e( 'Trash', 'mycred' ); ?></a></div>
507
-
508
- </div>
509
-
510
- <div class="clear"></div>
511
- </div>
512
- <div id="major-publishing-actions">
513
-
514
- <div id="publishing-action">
515
- <span class="spinner"></span>
516
-
517
- <input type="submit" id="publish" class="button button-primary primary button-large" value="<?php _e( 'Save Changes', 'mycred' ); ?>" />
518
-
519
- </div>
520
- <div class="clear"></div>
521
- </div>
522
- </div>
523
- <?php
524
-
525
- }
526
-
527
- /**
528
- * Metabox: Pending Payment
529
- * @since 1.7
530
- * @version 1.0.1
531
- */
532
- public function metabox_pending_payment( $post ) {
533
-
534
- global $mycred_modules;
535
-
536
- $pending_payment = buycred_get_pending_payment( $post->ID );
537
- $buyer_name = 'ID: ' . $pending_payment->buyer_id;
538
-
539
- $buyer_object = get_userdata( $pending_payment->buyer_id );
540
- if ( isset( $buyer_object->ID ) ) {
541
- $buyer_name = $buyer_object->display_name;
542
- if ( $buyer_name == '' )
543
- $buyer_name = $buyer_object->user_email;
544
- }
545
-
546
- if ( $pending_payment->recipient_id == $pending_payment->buyer_id )
547
- $recipient_name = $buyer_name;
548
-
549
- else {
550
- $recipient_name = 'ID: ' . $pending_payment->recipient_id;
551
- $recipient_object = get_userdata( $pending_payment->recipient_id );
552
- if ( isset( $recipient_object->ID ) ) {
553
- $recipient_name = $recipient_object->display_name;
554
- if ( $recipient_name == '' )
555
- $recipient_name = $recipient_object->user_email;
556
- }
557
- }
558
-
559
- if ( $pending_payment->point_type == $this->core->cred_id )
560
- $mycred = $this->core;
561
-
562
- else
563
- $mycred = mycred( $type );
564
-
565
- ?>
566
- <div class="form">
567
- <div class="row">
568
- <div class="col-md-6">
569
- <div class="form-group">
570
- <label><?php _e( 'Payer', 'mycred' ); ?></label>
571
- <p class="form-control-static"><?php echo esc_attr( $buyer_name ); ?></p>
572
- </div>
573
- </div>
574
- <div class="col-md-6">
575
- <div class="form-group">
576
- <label><?php _e( 'Recipient', 'mycred' ); ?></label>
577
- <p class="form-control-static"><?php echo esc_attr( $recipient_name ); ?></p>
578
- </div>
579
- </div>
580
- </div>
581
- <div class="row">
582
- <div class="col-md-3 col-sm-6">
583
- <div class="form-group">
584
- <label for="buycred-pending-payment-point_type"><?php _e( 'Point Type', 'mycred' ); ?></label>
585
- <?php
586
-
587
- // Just one point type is set for sale. No need for a dropdown menu
588
- if ( count( $this->core->buy_creds['types'] ) == 1 ) {
589
-
590
- ?>
591
- <p class="form-control-static"><?php echo strip_tags( $mycred->plural() ); ?></p>
592
- <input type="hidden" name="buycred_pending_payment[point_type]" value="<?php echo $pending_payment->point_type; ?>" />
593
- <?php
594
-
595
- }
596
-
597
- // Multiple point types are set for sale. Show a dropdown menu
598
- else {
599
-
600
- ?>
601
- <select name="buycred_pending_payment[point_type]" id="buycred-pending-payment-point_type" class="form-control">
602
- <?php
603
-
604
- foreach ( $this->core->buy_creds['types'] as $point_type ) {
605
-
606
- echo '<option value="' . $point_type . '"';
607
- if ( $pending_payment->point_type == $point_type ) echo ' selected="selected"';
608
- echo '>' . mycred_get_point_type_name( $pending_payment->point_type, false ) . '</option>';
609
-
610
- }
611
-
612
- ?>
613
- </select>
614
- <?php
615
-
616
- }
617
-
618
- ?>
619
- </div>
620
- </div>
621
- <div class="col-md-3 col-sm-6">
622
- <div class="form-group">
623
- <label for="buycred-pending-payment-gateway"><?php _e( 'Gateway', 'mycred' ); ?></label>
624
- <select name="buycred_pending_payment[gateway]" id="buycred-pending-payment-gateway" class="form-control">
625
- <?php
626
-
627
- foreach ( $mycred_modules['solo']['buycred']->get() as $gateway_id => $info ) {
628
-
629
- echo '<option value="' . $gateway_id . '"';
630
- if ( $pending_payment->gateway_id == $gateway_id ) echo ' selected="selected"';
631
- if ( ! $mycred_modules['solo']['buycred']->is_active( $gateway_id ) ) echo ' disabled="disabled"';
632
- echo '>' . $info['title'] . '</option>';
633
-
634
- }
635
-
636
- ?>
637
- </select>
638
- </div>
639
- </div>
640
- <div class="col-md-2 col-sm-6">
641
- <div class="form-group">
642
- <label for="buycred-pending-payment-amount"><?php _e( 'Amount', 'mycred' ); ?></label>
643
- <input type="text" name="buycred_pending_payment[amount]" id="buycred-pending-payment-amount" class="form-control" value="<?php echo $mycred->number( $pending_payment->amount ); ?>" />
644
- </div>
645
- </div>
646
- <div class="col-md-2 col-sm-6">
647
- <div class="form-group">
648
- <label for="buycred-pending-payment-cost"><?php _e( 'Cost', 'mycred' ); ?></label>
649
- <input type="text" name="buycred_pending_payment[cost]" id="buycred-pending-payment-cost" class="form-control" value="<?php echo esc_attr( $pending_payment->cost ); ?>" />
650
- </div>
651
- </div>
652
- <div class="col-md-2 col-sm-6">
653
- <div class="form-group">
654
- <label for="buycred-pending-payment-currency"><?php _e( 'Currency', 'mycred' ); ?></label>
655
- <input type="text" name="buycred_pending_payment[currency]" id="buycred-pending-payment-currency" class="form-control" value="<?php echo esc_attr( $pending_payment->currency ); ?>" />
656
- </div>
657
- </div>
658
- </div>
659
- </div>
660
- <?php
661
-
662
- }
663
-
664
- /**
665
- * Metabox: Pending Payment Comments
666
- * @since 1.7
667
- * @version 1.0
668
- */
669
- public function metabox_pending_comments( $post ) {
670
-
671
- $comments = get_comments( array( 'post_id' => $post->ID ) );
672
-
673
- echo '<ul class="history">';
674
-
675
- if ( empty( $comments ) ) {
676
-
677
- $c = new StdClass();
678
- $c->comment_date = $post->post_date;
679
- $c->comment_content = __( 'Pending request created.', 'mycred' );
680
-
681
- $event = $this->add_comment( $post->ID, $c->comment_content, $c->comment_date );
682
- if ( $event === false )
683
- $c->comment_content .= ' Unsaved';
684
-
685
- else
686
- $c->comment_content .= ' ' . $event;
687
-
688
- $comments[] = $c;
689
-
690
- }
691
-
692
- foreach ( $comments as $comment ) {
693
-
694
- echo '<li><time>' . $comment->comment_date . '</time><p>' . $comment->comment_content . '</p></li>';
695
-
696
- }
697
-
698
- echo '</ul>';
699
-
700
- }
701
-
702
- /**
703
- * Save Pending Payment
704
- * @since 1.7
705
- * @version 1.0
706
- */
707
- public function save_pending_payment( $post_id, $post ) {
708
-
709
- if ( ! current_user_can( $this->core->edit_creds_cap() ) || ! isset( $_POST['buycred_pending_payment'] ) ) return;
710
-
711
- $pending_payment = $_POST['buycred_pending_payment'];
712
- $changed = false;
713
-
714
- foreach ( $pending_payment as $meta_key => $meta_value ) {
715
-
716
- $new_value = sanitize_text_field( $meta_value );
717
- $old_value = get_post_meta( $post_id, $meta_key, true );
718
- if ( $new_value != $old_value ) {
719
- update_post_meta( $post_id, $meta_key, $new_value );
720
- $changed = true;
721
- }
722
-
723
- }
724
-
725
- if ( $changed ) {
726
- $user = wp_get_current_user();
727
- $this->add_comment( $post_id, sprintf( __( 'Pending payment updated by %s', 'mycred' ), $user->user_login ) );
728
- }
729
-
730
- }
731
-
732
- /**
733
- * Render Shortcode Pending
734
- * @since 1.5
735
- * @version 1.1
736
- */
737
- public function render_shortcode_pending( $attr, $content = '' ) {
738
-
739
- // Must be logged in
740
- if ( ! is_user_logged_in() ) return $content;
741
-
742
- extract( shortcode_atts( array(
743
- 'ctype' => MYCRED_DEFAULT_TYPE_KEY,
744
- 'pay_now' => __( 'Pay Now', 'mycred' ),
745
- 'cancel' => __( 'Cancel', 'mycred' )
746
- ), $attr ) );
747
-
748
- $user_id = get_current_user_id();
749
- $pending = buycred_get_users_pending_payments( $user_id, $ctype );
750
-
751
- ob_start();
752
-
753
- ?>
754
- <div id="pending-buycred-payments-<?php echo $ctype; ?>">
755
- <table class="table">
756
- <thead>
757
- <tr>
758
- <th class="column-transaction-id"><?php _e( 'Transaction ID', 'mycred' ); ?></th>
759
- <th class="column-gateway"><?php _e( 'Gateway', 'mycred' ); ?></th>
760
- <th class="column-amount"><?php _e( 'Amount', 'mycred' ); ?></th>
761
- <th class="column-cost"><?php _e( 'Cost', 'mycred' ); ?></th>
762
- <?php if ( $ctype == '' ) : ?><th class="column-ctype"><?php _e( 'Point Type', 'mycred' ); ?></th><?php endif; ?>
763
- <th class="column-actions"><?php _e( 'Actions', 'mycred' ); ?></th>
764
- </tr>
765
- </thead>
766
- <tbody>
767
- <?php
768
-
769
- if ( ! empty( $pending ) ) {
770
-
771
- // Showing all point types
772
- if ( $ctype == '' ) {
773
-
774
- foreach ( $pending as $point_type => $entries ) {
775
-
776
- if ( empty( $entries ) ) continue;
777
-
778
- foreach ( $entries as $entry ) {
779
-
780
- ?>
781
- <tr>
782
- <td class="column-transaction-id"><?php echo esc_attr( $entry->public_id ); ?></td>
783
- <td class="column-gateway"><?php echo $this->adjust_column_content( 'gateway', $entry->payment_id ); ?></td>
784
- <td class="column-amount"><?php echo $this->adjust_column_content( 'amount', $entry->payment_id ); ?></td>
785
- <td class="column-cost"><?php echo $this->adjust_column_content( 'cost', $entry->payment_id ); ?></td>
786
- <td class="column-ctype"><?php echo mycred_get_point_type_name( $entry->point_type, false ); ?></td>
787
- <td class="column-actions">
788
- <a href="<?php echo esc_url( $entry->pay_now_url ); ?>"><?php echo $pay_now; ?></a> &bull; <a href="<?php echo esc_url( $entry->cancel_url ); ?>"><?php echo $cancel; ?></a>
789
- </td>
790
- </tr>
791
- <?php
792
-
793
- }
794
-
795
- }
796
-
797
- }
798
-
799
- // Showing a particular point type
800
- else {
801
-
802
- foreach ( $pending as $entry ) {
803
-
804
- ?>
805
- <tr>
806
- <td class="column-transaction-id"><?php echo esc_attr( $entry->public_id ); ?></td>
807
- <td class="column-gateway"><?php echo $this->adjust_column_content( 'gateway', $entry->payment_id ); ?></td>
808
- <td class="column-amount"><?php echo $this->adjust_column_content( 'amount', $entry->payment_id ); ?></td>
809
- <td class="column-cost"><?php echo $this->adjust_column_content( 'cost', $entry->payment_id ); ?></td>
810
- <td class="column-actions">
811
- <a href="<?php echo esc_url( $entry->pay_now_url ); ?>"><?php echo $pay_now; ?></a> &bull; <a href="<?php echo esc_url( $entry->cancel_url ); ?>"><?php echo $cancel; ?></a>
812
- </td>
813
- </tr>
814
- <?php
815
-
816
- }
817
-
818
- }
819
-
820
- }
821
- else {
822
-
823
- ?>
824
- <tr>
825
- <td colspan="<?php if ( $ctype == '' ) echo '6'; else echo '5'; ?>"><?php _e( 'No pending payments found', 'mycred' ); ?></td>
826
- </tr>
827
- <?php
828
-
829
- }
830
-
831
- ?>
832
- </tbody>
833
- </table>
834
- </div>
835
- <?php
836
-
837
- $output = ob_get_contents();
838
- ob_end_clean();
839
-
840
- return $output;
841
-
842
- }
843
-
844
- }
845
- endif;
846
-
847
- /**
848
- * Load buyCRED Pending Module
849
- * @since 1.7
850
- * @version 1.0
851
- */
852
- if ( ! function_exists( 'mycred_load_buycred_pending_addon' ) ) :
853
- function mycred_load_buycred_pending_addon( $modules, $point_types ) {
854
-
855
- $modules['solo']['buycred-pending'] = new buyCRED_Pending_Payments();
856
- $modules['solo']['buycred-pending']->load();
857
-
858
- return $modules;
859
-
860
- }
861
- endif;
862
- add_filter( 'mycred_load_modules', 'mycred_load_buycred_pending_addon', 40, 2 );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
addons/email-notices/assets/css/edit-email-notice.css DELETED
@@ -1,21 +0,0 @@
1
- #poststuff #mycred_email_settings .inside { margin: 0; padding: 0; }
2
- #poststuff .inside .mycred-save { text-align: right; padding: 10px 10px 8px; border-top: 1px solid #ddd; clear: both; margin-top: -2px; background-color: #F5F5F5; }
3
- .mycred-inline label { padding: 0 6px; }
4
-
5
- #mycred-email-notice { border-bottom: 1px solid #DDD; padding-bottom: 8px; margin-top: 0; }
6
-
7
- #mycred_email_settings .misc-pub-section { border-bottom: 1px solid #ddd; }
8
- #mycred_email_settings select { margin-bottom: 6px; min-width: 95%; }
9
- #mycred_email_settings .mycred-inline input[type="radio"] { margin-right: 0; }
10
- #mycred_email_settings input[type="text"] { margin-bottom: 6px; width: 95%; }
11
-
12
- #mycred-test { line-height: 25px; vertical-align: middle; text-align: left; float: left; }
13
- #mycred-text .spinner { float: left; }
14
- #mycred-email-styling { width: 95%; max-width: 98%; min-width: 95%; min-height: 100px; height: 100px; max-height: 200px; }
15
-
16
- #mycred_email_template_tags ul { display: block; width: 50%; height: auto; float: left; }
17
- #mycred_email_template_tags ul .title { font-size: large; }
18
- #mycred_email_template_tags ul li strong { display: block; float: left; min-width: 40%; }
19
- #mycred_email_template_tags ul li div { padding-left: 40%; }
20
-
21
- #misc-publishing-actions #visibility, #misc-publishing-actions .misc-pub-curtime { display: none; display: none !important; }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
addons/email-notices/css/edit-email-notice.css ADDED
@@ -0,0 +1,11 @@
 
 
 
 
 
 
 
 
 
 
 
1
+ #poststuff #mycred_email_settings .inside { margin: 0; padding: 0; }
2
+ #poststuff .inside .mycred-save { text-align: right; padding: 10px 10px 8px; border-top: 1px solid #f5f5f5; clear: both; margin-top: -2px; }
3
+ .mycred-inline label { padding: 0 6px; }
4
+ #mycred_email_settings select { margin-bottom: 6px; }
5
+ #mycred_email_settings input[type="text"] { margin-bottom: 6px; width: 80%; }
6
+ #mycred-test { line-height: 25px; vertical-align: middle; text-align: left; float: left; }
7
+ #mycred-text .spinner { float: left; }
8
+ #mycred-email-styling { width: 95%; max-width: 98%; min-width: 95%; min-height: 100px; height: 100px; max-height: 200px; }
9
+
10
+ #mycred_email_template_tags ul { display: block; width: 50%; height: auto; float: left; }
11
+ #mycred_email_template_tags ul .title { font-size: large; }
addons/email-notices/{assets/css → css}/email-notice.css RENAMED
File without changes
addons/{banking/assets/js → email-notices/css}/index.php RENAMED
File without changes
addons/gateway/carts/mycred-marketpress.php ADDED
@@ -0,0 +1,579 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ if ( ! defined( 'myCRED_VERSION' ) ) exit;
3
+
4
+ /**
5
+ * MarketPress Payment Gateway
6
+ * @since 1.1
7
+ * @version 1.3
8
+ */
9
+ if ( ! function_exists( 'mycred_init_marketpress_gateway' ) ) {
10
+ add_action( 'mp_load_gateway_plugins', 'mycred_init_marketpress_gateway' );
11
+ function mycred_init_marketpress_gateway()
12
+ {
13
+ if ( ! class_exists( 'MP_Gateway_API' ) ) return;
14
+
15
+ class MP_Gateway_myCRED extends MP_Gateway_API {
16
+
17
+ var $plugin_name = 'mycred';
18
+ var $admin_name = 'myCRED';
19
+ var $public_name = 'myCRED';
20
+ var $mycred_type = 'mycred_default';
21
+ var $method_img_url = '';
22
+ var $method_button_img_url = '';
23
+ var $force_ssl = false;
24
+ var $ipn_url;
25
+ var $skip_form = false;
26
+
27
+ /**
28
+ * Runs when your class is instantiated. Use to setup your plugin instead of __construct()
29
+ */
30
+ function on_creation() {
31
+ global $mp;
32
+ $settings = get_option( 'mp_settings' );
33
+
34
+ //set names here to be able to translate
35
+ $this->admin_name = 'myCRED';
36
+
37
+ $this->public_name = mycred_label( true );
38
+ if ( isset( $settings['gateways']['mycred']['name'] ) && ! empty( $settings['gateways']['mycred']['name'] ) )
39
+ $this->public_name = $settings['gateways']['mycred']['name'];
40
+
41
+ $this->method_img_url = plugins_url( 'assets/images/cred-icon32.png', myCRED_THIS );
42
+ if ( isset( $settings['gateways']['mycred']['logo'] ) && ! empty( $settings['gateways']['mycred']['logo'] ) )
43
+ $this->method_img_url = $settings['gateways']['mycred']['logo'];
44
+
45
+ $this->method_button_img_url = $this->public_name;
46
+
47
+ if ( ! isset( $settings['gateways']['mycred']['type'] ) )
48
+ $this->mycred_type = 'mycred_default';
49
+ else
50
+ $this->mycred_type = $settings['gateways']['mycred']['type'];
51
+
52
+ $this->mycred = mycred( $this->mycred_type );
53
+ }
54
+
55
+ /**
56
+ * Use Exchange
57
+ * Checks to see if exchange is needed.
58
+ * @since 1.1
59
+ * @version 1.0
60
+ */
61
+ function use_exchange() {
62
+ global $mp;
63
+
64
+ $settings = get_option( 'mp_settings' );
65
+ if ( $settings['currency'] == 'POINTS' ) return false;
66
+ return true;
67
+ }
68
+
69
+ /**
70
+ * Returns the current carts total.
71
+ * @since 1.2
72
+ * @version 1.0
73
+ */
74
+ function get_cart_total( $cart = NULL ) {
75
+ global $mp;
76
+
77
+ // Get total
78
+ $totals = array();
79
+ foreach ( $cart as $product_id => $variations ) {
80
+ foreach ( $variations as $data ) {
81
+ $totals[] = $mp->before_tax_price( $data['price'], $product_id ) * $data['quantity'];
82
+ }
83
+ }
84
+ $total = array_sum( $totals );
85
+
86
+ // Apply Coupons
87
+ if ( $coupon = $mp->coupon_value( $mp->get_coupon_code(), $total ) ) {
88
+ $total = $coupon['new_total'];
89
+ }
90
+
91
+ // Shipping Cost
92
+ if ( ( $shipping_price = $mp->shipping_price() ) !== false ) {
93
+ $total = $total + $shipping_price;
94
+ }
95
+
96
+ // Tax
97
+ if ( ( $tax_price = $mp->tax_price() ) !== false ) {
98
+ $total = $total + $tax_price;
99
+ }
100
+
101
+ $settings = get_option( 'mp_settings' );
102
+ if ( $this->use_exchange() )
103
+ return $this->mycred->apply_exchange_rate( $total, $settings['gateways']['mycred']['exchange'] );
104
+ else
105
+ return $this->mycred->number( $total );
106
+ }
107
+
108
+ /**
109
+ * Return fields you need to add to the payment screen, like your credit card info fields
110
+ *
111
+ * @param array $cart. Contains the cart contents for the current blog, global cart if $mp->global_cart is true
112
+ * @param array $shipping_info. Contains shipping info and email in case you need it
113
+ * @since 1.1
114
+ * @version 1.1
115
+ */
116
+ function payment_form( $cart, $shipping_info ) {
117
+ global $mp;
118
+
119
+ $settings = get_option( 'mp_settings' );
120
+
121
+ if ( ! is_user_logged_in() ) {
122
+ $message = str_replace( '%login_url_here%', wp_login_url( mp_checkout_step_url( 'checkout' ) ), $settings['gateways']['mycred']['visitors'] );
123
+ $message = $this->mycred->template_tags_general( $message );
124
+ return '<div id="mp-mycred-balance">' . $message . '</div>';
125
+ }
126
+
127
+ $balance = $this->mycred->get_users_cred( get_current_user_id(), $this->mycred_type );
128
+ $total = $this->get_cart_total( $cart );
129
+
130
+ // Low balance
131
+ if ( $balance-$total < 0 ) {
132
+ $message = $this->mycred->template_tags_user( $settings['gateways']['mycred']['lowfunds'], false, wp_get_current_user() );
133
+ $instructions = '<div id="mp-mycred-balance">' . $message . '</div>';
134
+ $red = ' style="color: red;"';
135
+ }
136
+ else {
137
+ $instructions = $this->mycred->template_tags_general( $settings['gateways']['mycred']['instructions'] );
138
+ $red = '';
139
+ }
140
+
141
+ // Return Cost
142
+ return '
143
+ <div id="mp-mycred-balance">' . $instructions . '</div>
144
+ <div id="mp-mycred-cost">
145
+ <table style="width:100%;">
146
+ <tr>
147
+ <td class="info">' . __( 'Current Balance', 'mycred' ) . '</td>
148
+ <td class="amount">' . $this->mycred->format_creds( $balance ) . '</td>
149
+ </tr>
150
+ <tr>
151
+ <td class="info">' . __( 'Total Cost', 'mycred' ) . '</td>
152
+ <td class="amount">' . $this->mycred->format_creds( $total ) . '</td>
153
+ </tr>
154
+ <tr>
155
+ <td class="info">' . __( 'Balance After Purchase', 'mycred' ) . '</td>
156
+ <td class="amount"' . $red . '>' . $this->mycred->format_creds( $balance-$total ) . '</td>
157
+ </tr>
158
+ </table>
159
+ </div>';
160
+ }
161
+
162
+ /**
163
+ * Return the chosen payment details here for final confirmation. You probably don't need
164
+ * to post anything in the form as it should be in your $_SESSION var already.
165
+ *
166
+ * @param array $cart. Contains the cart contents for the current blog, global cart if $mp->global_cart is true
167
+ * @param array $shipping_info. Contains shipping info and email in case you need it
168
+ * @since 1.1
169
+ * @version 1.1
170
+ */
171
+ function confirm_payment_form( $cart, $shipping_info ) {
172
+ global $mp;
173
+
174
+ $settings = get_option( 'mp_settings' );
175
+ $user_id = get_current_user_id();
176
+ $balance = $this->mycred->get_users_cred( get_current_user_id(), $this->mycred_type );
177
+ $total = $this->get_cart_total( $cart );
178
+
179
+ $table = '<table class="mycred-cart-cost"><thead><tr><th>' . __( 'Payment', 'mycred' ) . '</th></tr></thead>';
180
+ if ( $balance-$total < 0 ) {
181
+ $message = $this->mycred->template_tags_user( $settings['gateways']['mycred']['lowfunds'], false, wp_get_current_user() );
182
+ $table .= '<tr><td id="mp-mycred-cost" style="color: red; font-weight: bold;"><p>' . $message . ' <a href="' . mp_checkout_step_url( 'checkout' ) . '">' . __( 'Go Back', 'mycred' ) . '</a></td></tr>';
183
+ }
184
+ else
185
+ $table .= '<tr><td id="mp-mycred-cost" class="mycred-ok">' . $this->mycred->format_creds( $total ) . ' ' . __( 'will be deducted from your account.', 'mycred' ) . '</td></tr>';
186
+
187
+ return $table . '</table>';
188
+ }
189
+
190
+ function process_payment_form( $cart, $shipping_info ) { }
191
+
192
+ /**
193
+ * Use this to do the final payment. Create the order then process the payment. If
194
+ * you know the payment is successful right away go ahead and change the order status
195
+ * as well.
196
+ * Call $mp->cart_checkout_error($msg, $context); to handle errors. If no errors
197
+ * it will redirect to the next step.
198
+ *
199
+ * @param array $cart. Contains the cart contents for the current blog, global cart if $mp->global_cart is true
200
+ * @param array $shipping_info. Contains shipping info and email in case you need it
201
+ * @since 1.1
202
+ * @version 1.2.1
203
+ */
204
+ function process_payment( $cart, $shipping_info ) {
205
+ global $mp;
206
+
207
+ $settings = get_option('mp_settings');
208
+ $user_id = get_current_user_id();
209
+ $insolvent = $this->mycred->template_tags_user( $settings['gateways']['mycred']['lowfunds'], false, wp_get_current_user() );
210
+ $timestamp = time();
211
+
212
+ // This gateway requires buyer to be logged in
213
+ if ( ! is_user_logged_in() ) {
214
+ $message = str_replace( '%login_url_here%', wp_login_url( mp_checkout_step_url( 'checkout' ) ), $settings['gateways']['mycred']['visitors'] );
215
+ $mp->cart_checkout_error( $this->mycred->template_tags_general( $message ) );
216
+ }
217
+
218
+ // Make sure current user is not excluded from using myCRED
219
+ if ( $this->mycred->exclude_user( $user_id ) )
220
+ $mp->cart_checkout_error(
221
+ sprintf( __( 'Sorry, but you can not use this gateway as your account is excluded. Please <a href="%s">select a different payment method</a>.', 'mycred' ), mp_checkout_step_url( 'checkout' ) )
222
+ );
223
+
224
+ // Get users balance
225
+ $balance = $this->mycred->get_users_cred( $user_id, $this->mycred_type );
226
+ $total = $this->get_cart_total( $cart );
227
+
228
+ // Low balance or Insolvent
229
+ if ( $balance <= $this->mycred->zero() || $balance-$total < $this->mycred->zero() ) {
230
+ $mp->cart_checkout_error(
231
+ $insolvent . ' <a href="' . mp_checkout_step_url( 'checkout' ) . '">' . __( 'Go Back', 'mycred' ) . '</a>'
232
+ );
233
+ return;
234
+ }
235
+
236
+ // Let others decline a store order
237
+ $decline = apply_filters( 'mycred_decline_store_purchase', false, $cart, $this );
238
+ if ( $decline !== false ) {
239
+ $mp->cart_checkout_error( $decline );
240
+ return;
241
+ }
242
+
243
+ // Create MarketPress order
244
+ $order_id = $mp->generate_order_id();
245
+ $payment_info['gateway_public_name'] = $this->public_name;
246
+ $payment_info['gateway_private_name'] = $this->admin_name;
247
+ $payment_info['status'][ $timestamp ] = __( 'Paid', 'mycred' );
248
+ $payment_info['total'] = $total;
249
+ $payment_info['currency'] = $settings['currency'];
250
+ $payment_info['method'] = __( 'myCRED', 'mycred' );
251
+ $payment_info['transaction_id'] = $order_id;
252
+ $paid = true;
253
+ $result = $mp->create_order( $order_id, $cart, $shipping_info, $payment_info, $paid );
254
+
255
+ $order = get_page_by_title( $result, 'OBJECT', 'mp_order' );
256
+
257
+ // Deduct cost
258
+ $this->mycred->add_creds(
259
+ 'marketpress_payment',
260
+ $user_id,
261
+ 0-$total,
262
+ $settings['gateways']['mycred']['log_template'],
263
+ $order->ID,
264
+ array( 'ref_type' => 'post' ),
265
+ $this->mycred_type
266
+ );
267
+
268
+ // Profit Sharing
269
+ if ( $settings['gateways']['mycred']['profit_share_percent'] > 0 ) {
270
+ foreach ( $cart as $product_id => $variations ) {
271
+ // Get Product
272
+ $product = get_post( (int) $product_id );
273
+
274
+ // Continue if product has just been deleted or owner is buyer
275
+ if ( $product === NULL || $product->post_author == $cui ) continue;
276
+
277
+ foreach ( $variations as $data ) {
278
+ $price = $data['price'];
279
+ $quantity = $data['quantity'];
280
+ $cost = $price*$quantity;
281
+
282
+ // Calculate Share
283
+ $share = ( $settings['gateways']['mycred']['profit_share_percent'] / 100 ) * $cost;
284
+
285
+ // Payout
286
+ $this->mycred->add_creds(
287
+ 'store_sale',
288
+ $product->post_author,
289
+ $share,
290
+ $settings['gateways']['mycred']['profit_share_log'],
291
+ $product->ID,
292
+ array( 'ref_type' => 'post' ),
293
+ $this->mycred_type
294
+ );
295
+ }
296
+ }
297
+ }
298
+ }
299
+
300
+ function order_confirmation( $order ) { }
301
+
302
+ /**
303
+ * Filters the order confirmation email message body. You may want to append something to
304
+ * the message. Optional
305
+ * @since 1.1
306
+ * @version 1.0
307
+ */
308
+ function order_confirmation_email( $msg, $order ) {
309
+ global $mp;
310
+ $settings = get_option('mp_settings');
311
+
312
+ if ( isset( $settings['gateways']['mycred']['email'] ) )
313
+ $msg = $mp->filter_email( $order, $settings['gateways']['mycred']['email'] );
314
+ else
315
+ $msg = $settings['email']['new_order_txt'];
316
+
317
+ return $msg;
318
+ }
319
+
320
+ /**
321
+ * Return any html you want to show on the confirmation screen after checkout. This
322
+ * should be a payment details box and message.
323
+ * @since 1.1
324
+ * @version 1.1
325
+ */
326
+ function order_confirmation_msg( $content, $order ) {
327
+ global $mp;
328
+ $settings = get_option('mp_settings');
329
+
330
+ $mycred = mycred();
331
+ $user_id = get_current_user_id();
332
+
333
+ return $content . str_replace(
334
+ 'TOTAL',
335
+ $mp->format_currency( $order->mp_payment_info['currency'], $order->mp_payment_info['total'] ),
336
+ $mycred->template_tags_user( $settings['gateways']['mycred']['confirmation'], false, wp_get_current_user() )
337
+ );
338
+ }
339
+
340
+ /**
341
+ * myCRED Gateway Settings
342
+ * @since 1.1
343
+ * @version 1.3
344
+ */
345
+ function gateway_settings_box( $settings ) {
346
+ global $mp;
347
+ $settings = get_option( 'mp_settings' );
348
+ $mycred = mycred();
349
+
350
+ $name = mycred_label( true );
351
+ $settings['gateways']['mycred'] = shortcode_atts( array(
352
+ 'name' => $name . ' ' . $mycred->template_tags_general( __( '%_singular% Balance', 'mycred' ) ),
353
+ 'logo' => $this->method_button_img_url,
354
+ 'type' => 'mycred_default',
355
+ 'log_template' => __( 'Payment for Order: #%order_id%', 'mycred' ),
356
+ 'exchange' => 1,
357
+ 'profit_share_percent' => 0,
358
+ 'profit_share_log' => __( 'Product Sale: %post_title%', 'mycred' ),
359
+ 'instructions' => __( 'Pay using your account balance.', 'mycred' ),
360
+ 'confirmation' => __( 'TOTAL amount has been deducted from your account. Your current balance is: %balance_f%', 'mycred' ),
361
+ 'lowfunds' => __( 'Insufficient funds.', 'mycred' ),
362
+ 'visitors' => __( 'You must be logged in to pay with %_plural%. Please <a href="%login_url_here%">login</a>.', 'mycred' ),
363
+ 'email' => $settings['email']['new_order_txt']
364
+ ), ( isset( $settings['gateways']['mycred'] ) ) ? $settings['gateways']['mycred'] : array() ); ?>
365
+
366
+ <div id="mp_mycred_payments" class="postbox mp-pages-msgs">
367
+ <h3 class="handle"><span><?php echo $name . ' ' . __( 'Settings', 'mycred' ); ?></span></h3>
368
+ <div class="inside">
369
+ <span class="description"><?php echo sprintf( __( 'Let your users pay for items in their shopping cart using their %s Account. Note! This gateway requires your users to be logged in when making a purchase!', 'mycred' ), $name ); ?></span>
370
+ <table class="form-table">
371
+ <tr>
372
+ <th scope="row"><label for="mycred-method-name"><?php _e( 'Method Name', 'mycred' ); ?></label></th>
373
+ <td>
374
+ <span class="description"><?php _e( 'Enter a public name for this payment method that is displayed to users - No HTML', 'mycred' ); ?></span>
375
+ <p><input value="<?php echo esc_attr( $settings['gateways']['mycred']['name'] ); ?>" style="width: 100%;" name="mp[gateways][mycred][name]" id="mycred-method-name" type="text" /></p>
376
+ </td>
377
+ </tr>
378
+ <tr>
379
+ <th scope="row"><label for="mycred-method-logo"><?php _e( 'Gateway Logo URL', 'mycred' ); ?></label></th>
380
+ <td>
381
+ <p><input value="<?php echo esc_attr( $settings['gateways']['mycred']['logo'] ); ?>" style="width: 100%;" name="mp[gateways][mycred][logo]" id="mycred-method-logo" type="text" /></p>
382
+ </td>
383
+ </tr>
384
+ <tr>
385
+ <th scope="row"><label for="mycred-method-type"><?php _e( 'Point Type', 'mycred' ); ?></label></th>
386
+ <td>
387
+ <?php mycred_types_select_from_dropdown( 'mp[gateways][mycred][type]', 'mycred-method-type', $settings['gateways']['mycred']['type'] ); ?>
388
+ </td>
389
+ </tr>
390
+ <tr>
391
+ <th scope="row"><label for="mycred-log-template"><?php _e( 'Log Template', 'mycred' ); ?></label></th>
392
+ <td>
393
+ <span class="description"><?php echo $mycred->available_template_tags( array( 'general' ), '%order_id%, %order_link%' ); ?></span>
394
+ <p><input value="<?php echo esc_attr( $settings['gateways']['mycred']['log_template'] ); ?>" style="width: 100%;" name="mp[gateways][mycred][log_template]" id="mycred-log-template" type="text" /></p>
395
+ </td>
396
+ </tr>
397
+ <?php
398
+ // Exchange rate
399
+ if ( $this->use_exchange() ) :
400
+ $exchange_desc = __( 'How much is 1 %_singular% worth in %currency%?', 'mycred' );
401
+ $exchange_desc = $mycred->template_tags_general( $exchange_desc );
402
+ $exchange_desc = str_replace( '%currency%', $settings['currency'], $exchange_desc ); ?>
403
+
404
+ <tr>
405
+ <th scope="row"><label for="mycred-exchange-rate"><?php _e( 'Exchange Rate', 'mycred' ); ?></label></th>
406
+ <td>
407
+ <span class="description"><?php echo $exchange_desc; ?></span>
408
+ <p><input value="<?php echo esc_attr( $settings['gateways']['mycred']['exchange'] ); ?>" size="8" name="mp[gateways][mycred][exchange]" id="mycred-exchange-rate" type="text" /></p>
409
+ </td>
410
+ </tr>
411
+ <?php endif; ?>
412
+
413
+ <tr>
414
+ <td colspan="2"><h4><?php _e( 'Profit Sharing', 'mycred' ); ?></h4></td>
415
+ </tr>
416
+ <tr>
417
+ <th scope="row"><label for="mycred-profit-sharing"><?php _e( 'Percentage', 'mycred' ); ?></label></th>
418
+ <td>
419
+ <span class="description"><?php _e( 'Option to share sales with the product owner. Use zero to disable.', 'mycred' ); ?></span>
420
+ <p><input value="<?php echo esc_attr( $settings['gateways']['mycred']['profit_share_percent'] ); ?>" size="8" name="mp[gateways][mycred][profit_share_percent]" id="mycred-profit-sharing" type="text" /> %</p>
421
+ </td>
422
+ </tr>
423
+ <tr>
424
+ <th scope="row"><label for="mycred-profit-sharing-log"><?php _e( 'Log Template', 'mycred' ); ?></label></th>
425
+ <td>
426
+ <span class="description"><?php echo $mycred->available_template_tags( array( 'general', 'post' ) ); ?></span>
427
+ <p><input value="<?php echo esc_attr( $settings['gateways']['mycred']['profit_share_log'] ); ?>" style="width: 100%;" name="mp[gateways][mycred][profit_share_log]" id="mycred-profit-sharing-log" type="text" /></p>
428
+ </td>
429
+ </tr>
430
+ <tr>
431
+ <td colspan="2"><h4><?php _e( 'Messages', 'mycred' ); ?></h4></td>
432
+ </tr>
433
+ <tr>
434
+ <th scope="row"><label for="mycred-lowfunds"><?php _e( 'Insufficient Funds', 'mycred' ); ?></label></th>
435
+ <td>
436
+ <span class="description"><?php _e( 'Message to show when the user can not use this gateway.', 'mycred' ); ?></span>
437
+ <p><input type="text" name="mp[gateways][mycred][lowfunds]" id="mycred-lowfunds" style="width: 100%;" value="<?php echo esc_attr( $settings['gateways']['mycred']['lowfunds'] ); ?>"><br />
438
+ <span class="description"><?php echo $mycred->available_template_tags( array( 'general' ) ); ?></span></p>
439
+ </td>
440
+ </tr>
441
+ <tr>
442
+ <th scope="row"><label for="mycred-visitors"><?php _e( 'Visitors', 'mycred' ); ?></label></th>
443
+ <td>
444
+ <span class="description"><?php _e( 'Message to show to buyers that are not logged in.', 'mycred' ); ?></span>
445
+ <p><input type="text" name="mp[gateways][mycred][visitors]" id="mycred-visitors" style="width: 100%;" value="<?php echo esc_attr( $settings['gateways']['mycred']['visitors'] ); ?>"><br />
446
+ <span class="description"><?php echo $mycred->available_template_tags( array( 'general' ) ); ?></span></p>
447
+ </td>
448
+ </tr>
449
+ <tr>
450
+ <th scope="row"><label for="mycred-instructions"><?php _e( 'User Instructions', 'mycred' ); ?></label></th>
451
+ <td>
452
+ <span class="description"><?php _e( 'Information to show users before payment.', 'mycred' ); ?></span>
453
+ <p><?php wp_editor( $settings['gateways']['mycred']['instructions'] , 'mycred-instructions', array( 'textarea_name' => 'mp[gateways][mycred][instructions]' ) ); ?><br />
454
+ <span class="description"><?php echo $mycred->available_template_tags( array( 'general' ), '%balance% or %balance_f%' ); ?></span></p>
455
+ </td>
456
+ </tr>
457
+ <tr>
458
+ <th scope="row"><label for="mycred-confirmation"><?php _e( 'Confirmation Information', 'mycred' ); ?></label></th>
459
+ <td>
460
+ <span class="description"><?php _e( 'Information to display on the order confirmation page. - HTML allowed', 'mycred' ); ?></span>
461
+ <p><?php wp_editor( $settings['gateways']['mycred']['confirmation'], 'mycred-confirmation', array( 'textarea_name' => 'mp[gateways][mycred][confirmation]' ) ); ?><br />
462
+ <span class="description"><?php echo $mycred->available_template_tags( array( 'general' ), '%balance% or %balance_f%' ); ?></span></p>
463
+ </td>
464
+ </tr>
465
+ <tr>
466
+ <th scope="row"><label for="mycred-email"><?php _e( 'Order Confirmation Email', 'mycred' ); ?></label></th>
467
+ <td>
468
+ <span class="description"><?php echo sprintf( __( 'This is the email text to send to those who have made %s checkouts. It overrides the default order checkout email. These codes will be replaced with order details: CUSTOMERNAME, ORDERID, ORDERINFO, SHIPPINGINFO, PAYMENTINFO, TOTAL, TRACKINGURL. No HTML allowed.', 'mycred' ), $name ); ?></span>
469
+ <p><textarea id="mycred-email" name="mp[gateways][mycred][email]" class="mp_emails_txt"><?php echo esc_textarea( $settings['gateways']['mycred']['email'] ); ?></textarea></p>
470
+ <span class="description"><?php echo $mycred->available_template_tags( array( 'general' ), '%balance% or %balance_f%' ); ?></span>
471
+ </td>
472
+ </tr>
473
+ </table>
474
+ </div>
475
+ </div>
476
+ <?php
477
+ }
478
+
479
+ /**
480
+ * Filter Gateway Settings
481
+ * @since 1.1
482
+ * @version 1.3
483
+ */
484
+ function process_gateway_settings( $settings ) {
485
+ // Name (no html)
486
+ $settings['gateways']['mycred']['name'] = stripslashes( wp_filter_nohtml_kses( $settings['gateways']['mycred']['name'] ) );
487
+
488
+ // Log Template (no html)
489
+ $settings['gateways']['mycred']['log_template'] = stripslashes( wp_filter_nohtml_kses( $settings['gateways']['mycred']['log_template'] ) );
490
+ $settings['gateways']['mycred']['type'] = sanitize_text_field( $settings['gateways']['mycred']['type'] );
491
+ $settings['gateways']['mycred']['logo'] = stripslashes( wp_filter_nohtml_kses( $settings['gateways']['mycred']['logo'] ) );
492
+
493
+ // Exchange rate (if used)
494
+ if ( $this->use_exchange() ) {
495
+ // Decimals must start with a zero
496
+ if ( $settings['gateways']['mycred']['exchange'] != 1 && substr( $settings['gateways']['mycred']['exchange'], 0, 1 ) != '0' ) {
497
+ $settings['gateways']['mycred']['exchange'] = (float) '0' . $settings['gateways']['mycred']['exchange'];
498
+ }
499
+ // Decimal seperator must be punctuation and not comma
500
+ $settings['gateways']['mycred']['exchange'] = str_replace( ',', '.', $settings['gateways']['mycred']['exchange'] );
501
+ }
502
+ else
503
+ $settings['gateways']['mycred']['exchange'] = 1;
504
+
505
+ $settings['gateways']['mycred']['profit_share_percent'] = stripslashes( trim( $settings['gateways']['mycred']['profit_share_percent'] ) );
506
+ $settings['gateways']['mycred']['profit_share_log'] = stripslashes( wp_filter_nohtml_kses( $settings['gateways']['mycred']['profit_share_log'] ) );
507
+
508
+ $settings['gateways']['mycred']['lowfunds'] = stripslashes( wp_filter_post_kses( $settings['gateways']['mycred']['lowfunds'] ) );
509
+ $settings['gateways']['mycred']['visitors'] = stripslashes( wp_filter_post_kses( $settings['gateways']['mycred']['visitors'] ) );
510
+ $settings['gateways']['mycred']['instructions'] = stripslashes( wp_filter_post_kses( $settings['gateways']['mycred']['instructions'] ) );
511
+ $settings['gateways']['mycred']['confirmation'] = stripslashes( wp_filter_post_kses( $settings['gateways']['mycred']['confirmation'] ) );
512
+
513
+ // Email (no html)
514
+ $settings['gateways']['mycred']['email'] = stripslashes( wp_filter_nohtml_kses( $settings['gateways']['mycred']['email'] ) );
515
+
516
+ return $settings;
517
+ }
518
+ }
519
+ mp_register_gateway_plugin( 'MP_Gateway_myCRED', 'mycred', 'myCRED' );
520
+ }
521
+ }
522
+
523
+
524
+
525
+ /**
526
+ * Filter the myCRED Log
527
+ * Parses the %order_id% and %order_link% template tags.
528
+ * @since 1.1
529
+ * @version 1.1
530
+ */
531
+ if ( ! function_exists( 'mycred_marketpress_parse_log' ) ) {
532
+ add_filter( 'mycred_parse_log_entry_marketpress_payment', 'mycred_marketpress_parse_log', 90, 2 );
533
+ function mycred_marketpress_parse_log( $content, $log_entry )
534
+ {
535
+ // Prep
536
+ global $mp;
537
+ $mycred = mycred( $log_entry->ctype );
538
+ $order = get_post( $log_entry->ref_id );
539
+ $order_id = $order->post_title;
540
+ $user_id = get_current_user_id();
541
+
542
+ // Order ID
543
+ $content = str_replace( '%order_id%', $order->post_title, $content );
544
+
545
+ // Link to order if we can edit plugin or are the user who made the order
546
+ if ( $user_id == $log_entry->user_id || $mycred->can_edit_plugin( $user_id ) ) {
547
+ $track_link = '<a href="' . mp_orderstatus_link( false, true ) . $order_id . '/' . '">#' . $order->post_title . '/' . '</a>';
548
+ $content = str_replace( '%order_link%', $track_link, $content );
549
+ }
550
+ else {
551
+ $content = str_replace( '%order_link%', '#' . $order_id, $content );
552
+ }
553
+
554
+ return $content;
555
+ }
556
+ }
557
+
558
+ /**
559
+ * Parse Email Notice
560
+ * @since 1.2.2
561
+ * @version 1.0
562
+ */
563
+ if ( ! function_exists( 'mycred_market_parse_email' ) ) {
564
+ add_filter( 'mycred_email_before_send', 'mycred_market_parse_email' );
565
+ function mycred_market_parse_email( $email )
566
+ {
567
+ if ( $email['request']['ref'] == 'marketpress_payment' ) {
568
+ $order = get_post( (int) $email['request']['ref_id'] );
569
+ if ( isset( $order->id ) ) {
570
+ $track_link = '<a href="' . mp_orderstatus_link( false, true ) . $order_id . '/' . '">#' . $order->post_title . '/' . '</a>';
571
+
572
+ $content = str_replace( '%order_id%', $order->post_title, $email['request']['entry'] );
573
+ $email['request']['entry'] = str_replace( '%order_link%', $track_link, $content );
574
+ }
575
+ }
576
+ return $email;
577
+ }
578
+ }
579
+ ?>
addons/{banking/includes → gateway/event-booking}/index.php RENAMED
File without changes
addons/gateway/event-booking/mycred-eventsmanager-pro.php ADDED
@@ -0,0 +1,641 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ if ( ! defined( 'myCRED_VERSION' ) ) exit;
3
+
4
+ /**
5
+ * Events Manager Pro Gateway
6
+ * @since 1.3
7
+ * @version 1.1
8
+ */
9
+ if ( ! class_exists( 'EM_Gateway_myCRED' ) ) {
10
+ class EM_Gateway_myCRED extends EM_Gateway {
11
+
12
+ public $gateway = 'mycred';
13
+ public $title = '';
14
+ public $status = 1;
15
+ public $status_txt = '';
16
+ public $mycred_type = 'mycred_default';
17
+ public $button_enabled = true;
18
+ public $supports_multiple_bookings = true;
19
+
20
+ public $registered_timer = 0;
21
+
22
+ /**
23
+ * Construct
24
+ */
25
+ function __construct() {
26
+ // Default settings
27
+ $defaults = array(
28
+ 'setup' => 'off',
29
+ 'type' => 'mycred_default',
30
+ 'rate' => 100,
31
+ 'share' => 0,
32
+ 'log' => array(
33
+ 'purchase' => __( 'Payment for tickets to %link_with_title%', 'mycred' ),
34
+ 'refund' => __( 'Ticket refund for %link_with_title%', 'mycred' )
35
+ ),
36
+ 'refund' => 0,
37
+ 'labels' => array(
38
+ 'header' => __( 'Pay using your %_plural% balance', 'mycred' ),
39
+ 'button' => __( 'Pay Now', 'mycred' ),
40
+ 'link' => __( 'Pay', 'mycred' )
41
+ ),
42
+ 'messages' => array(
43
+ 'success' => __( 'Thank you for your payment!', 'mycred' ),
44
+ 'error' => __( "I'm sorry but you can not pay for these tickets using %_plural%", 'mycred' )
45
+ )
46
+ );
47
+
48
+ // Settings
49
+ $settings = get_option( 'mycred_eventsmanager_gateway_prefs' );
50
+ $this->prefs = mycred_apply_defaults( $defaults, $settings );
51
+
52
+ $this->mycred_type = $this->prefs['type'];
53
+
54
+ // Load myCRED
55
+ $this->core = mycred( $this->mycred_type );
56
+
57
+ // Apply Whitelabeling
58
+ $this->label = mycred_label();
59
+ $this->title = strip_tags( $this->label );
60
+ $this->status_txt = 'Paid using ' . strip_tags( $this->label );
61
+
62
+ parent::__construct();
63
+
64
+ if ( !$this->is_active() ) return;
65
+
66
+ // Currency
67
+ add_filter( 'em_get_currencies', array( $this, 'add_currency' ) );
68
+ if ( $this->single_currency() )
69
+ add_filter( 'em_get_currency_formatted', array( $this, 'format_price' ), 10, 4 );
70
+
71
+ // Adjust Ticket Columns
72
+ add_filter( 'em_booking_form_tickets_cols', array( $this, 'ticket_columns' ), 10, 2 );
73
+ add_action( 'em_booking_form_tickets_col_mycred', array( $this, 'ticket_col' ), 10, 2 );
74
+ add_filter( 'em_bookings_table_cols_col_action', array( $this, 'bookings_table_actions' ), 10, 2 );
75
+
76
+ // Refund
77
+ if ( $this->prefs['refund'] != 0 )
78
+ add_filter( 'em_booking_set_status', array( $this, 'refunds' ), 10, 2 );
79
+ }
80
+
81
+ /**
82
+ * Add Currency
83
+ * Adds "Points" as a form of currency
84
+ * @since 1.3
85
+ * @version 1.0
86
+ */
87
+ public function add_currency( $currencies ) {
88
+ $currencies->names['XMY'] = $this->core->plural();
89
+ if ( empty( $this->core->before ) && !empty( $this->core->after ) ) {
90
+ $currencies->symbols['XMY'] = $this->core->after;
91
+ $currencies->symbols['XMY'] = $this->core->after;
92
+ }
93
+ elseif ( !empty( $this->core->before ) && empty( $this->core->after ) ) {
94
+ $currencies->true_symbols['XMY'] = $this->core->before;
95
+ $currencies->true_symbols['XMY'] = $this->core->after;
96
+ }
97
+
98
+ return $currencies;
99
+ }
100
+
101
+ /**
102
+ * Check if using Single Currency
103
+ * @since 1.3
104
+ * @version 1.0
105
+ */
106
+ public function single_currency() {
107
+ if ( $this->prefs['setup'] == 'single' ) return true;
108
+ return false;
109
+ }
110
+
111
+ /**
112
+ * Format Price
113
+ * @since 1.3
114
+ * @version 1.0
115
+ */
116
+ public function format_price( $formatted_price, $price, $currency, $format ) {
117
+ if ( $currency == 'XMY' )
118
+ return $this->core->format_creds( $price );
119
+ else
120
+ return $formatted_price;
121
+ }
122
+
123
+ /**
124
+ * Adjust Ticket Columns
125
+ * @since 1.3
126
+ * @version 1.0
127
+ */
128
+ public function ticket_columns( $columns, $EM_Event ) {
129
+ if ( ! $EM_Event->is_free() ) {
130
+ unset( $columns['price'] );
131
+ unset( $columns['type'] );
132
+ unset( $columns['spaces'] );
133
+
134
+ $columns['type'] = __( 'Ticket Type', 'mycred' );
135
+
136
+ if ( $this->single_currency() ) {
137
+ $columns['mycred'] = __( 'Price', 'mycred' );
138
+ }
139
+ else {
140
+ $columns['price'] = __( 'Price', 'mycred' );
141
+ $columns['mycred'] = $this->core->plural();
142
+ }
143
+ $columns['spaces'] = __( 'Spaces', 'mycred' );
144
+ }
145
+
146
+ $this->booking_cols = count( $columns );
147
+ return $columns;
148
+ }
149
+
150
+ /**
151
+ * Adjust Ticket Column Content
152
+ * @since 1.3
153
+ * @version 1.0
154
+ */
155
+ public function ticket_col( $EM_Ticket, $EM_Event ) {
156
+ $ticket_price = $EM_Ticket->get_price( false );
157
+ if ( $this->single_currency() )
158
+ $price = $ticket_price;
159
+ else
160
+ $price = $this->prefs['rate']*$ticket_price;
161
+
162
+ if ( empty( $ticket_price ) )
163
+ $price = 0; ?>
164
+
165
+ <td class="em-bookings-ticket-table-points"><?php echo $this->core->format_creds( $price ); ?></td>
166
+ <?php
167
+ }
168
+
169
+ /**
170
+ * Shows button, not needed if using the new form display
171
+ * @since 1.3
172
+ * @version 1.0
173
+ */
174
+ function booking_form_button() {
175
+ if ( ! is_user_logged_in() ) return;
176
+ $user_id = get_current_user_id();
177
+
178
+ // Check for exclusion
179
+ if ( $this->core->exclude_user( $user_id ) ) return;
180
+
181
+ // Make sure we have points
182
+ if ( $this->core->get_users_cred( $user_id, $this->mycred_type ) <= $this->core->format_number( 0 ) ) return;
183
+
184
+ $button = get_option( 'em_'. $this->gateway . '_button', $this->title );
185
+ ob_start();
186
+ if ( preg_match( '/https?:\/\//', $button ) ) { ?>
187
+ <input type="image" class="em-booking-submit em-gateway-button" id="em-gateway-button-<?php echo $this->gateway; ?>" src="<?php echo $button; ?>" alt="<?php echo $this->title; ?>" />
188
+ <?php } else { ?>
189
+ <input type="submit" class="em-booking-submit em-gateway-button" id="em-gateway-button-<?php echo $this->gateway; ?>" value="<?php echo $button; ?>" />
190
+ <?php }
191
+ $output = ob_get_contents();
192
+ ob_end_clean();
193
+
194
+ return $output;
195
+ }
196
+
197
+ /**
198
+ * Add Booking
199
+ * @since 1.3
200
+ * @version 1.0
201
+ */
202
+ function booking_add( $EM_Event, $EM_Booking, $post_validation = false ) {
203
+ parent::booking_add( $EM_Event, $EM_Booking, $post_validation );
204
+ if ( $post_validation && empty( $EM_Booking->booking_id ) ) {
205
+ if ( get_option( 'dbem_multiple_bookings' ) && get_class( $EM_Booking ) == 'EM_Multiple_Booking' ) {
206
+ add_filter( 'em_multiple_booking_save', array( &$this, 'booking_payment' ), 2, 2 );
207
+ } else {
208
+ add_filter( 'em_booking_save', array( &$this, 'booking_payment' ), 2, 2 );
209
+ }
210
+ }
211
+ }
212
+
213
+ /**
214
+ * Booking Payment
215
+ * @since 1.3
216
+ * @version 1.1
217
+ */
218
+ function booking_payment( $result, $EM_Booking ) {
219
+ global $wpdb, $wp_rewrite, $EM_Notices;
220
+ //make sure booking save was successful before we try anything
221
+ if ( $result ) {
222
+ // Event is not free
223
+ if ( $EM_Booking->get_price() > 0 ) {
224
+ $ok = true;
225
+
226
+ // User is excluded from using this gateway
227
+ if ( $this->core->exclude_user( $EM_Booking->person->ID ) ) {
228
+ $EM_Booking->add_error( __( 'You can not pay using this gateway.', 'mycred' ) );
229
+ $ok = false;
230
+ }
231
+ // User can not afford to pay
232
+ elseif ( ! $this->can_pay( $EM_Booking ) ) {
233
+ $EM_Booking->add_error( $this->core->template_tags_general( $this->prefs['messages']['error'] ) );
234
+ $ok = false;
235
+ }
236
+ // User has not yet paid (prefered)
237
+ elseif ( ! $this->has_paid( $EM_Booking ) ) {
238
+ // Price
239
+ $price = $this->core->number( $EM_Booking->booking_price );
240
+ if ( ! $this->single_currency() ) {
241
+ $exchange_rate = $this->prefs['rate'];
242
+ $price = $this->core->number( $exchange_rate*$price );
243
+ }
244
+
245
+ // Charge
246
+ $this->core->add_creds(
247
+ 'ticket_purchase',
248
+ $EM_Booking->person->ID,
249
+ 0-$price,
250
+ $this->prefs['log']['purchase'],
251
+ $EM_Booking->event->post_id,
252
+ array( 'ref_type' => 'post', 'bid' => (int) $EM_Booking->booking_id ),
253
+ $this->mycred_type
254
+ );
255
+
256
+ // Log transaction with EM
257
+ $transaction_id = time() . $EM_Booking->person->ID;
258
+ $EM_Booking->booking_meta[ $this->gateway ] = array( 'txn_id' => $transaction_id, 'amount' => $price );
259
+ $this->record_transaction( $EM_Booking, $EM_Booking->get_price( false, false, true ), get_option( 'dbem_bookings_currency' ), current_time( 'mysql' ), $transaction_id, 'Completed', '' );
260
+
261
+ // Profit sharing
262
+ if ( $this->prefs['share'] != 0 ) {
263
+ $event_post = get_post( (int) $EM_Booking->event->post_id );
264
+ if ( $event_post !== NULL ) {
265
+ $share = ( $this->prefs['share']/100 ) * $price;
266
+ $this->core->add_creds(
267
+ 'ticket_sale',
268
+ $event_post->post_author,
269
+ $share,
270
+ $this->prefs['log']['purchase'],
271
+ $event_post->ID,
272
+ array( 'ref_type' => 'post', 'bid' => (int) $EM_Booking->booking_id ),
273
+ $this->mycred_type
274
+ );
275
+ }
276
+ }
277
+ }
278
+ // Something went horribly wrong
279
+ else {
280
+ $ok = false;
281
+ }
282
+
283
+ // Successfull Payment
284
+ if ( $ok ) {
285
+ if ( ! get_option( 'em_' . $this->gateway . '_manual_approval', false ) || ! get_option( 'dbem_bookings_approval' ) ) {
286
+ $EM_Booking->set_status( 1, false ); //Approve
287
+ } else {
288
+ $EM_Booking->set_status( 0, false ); //Set back to normal "pending"
289
+ }
290
+ }
291
+ // Error in payment - delete booking
292
+ else {
293
+ // Delete any user that got registered for this event
294
+ if ( ! is_user_logged_in() && get_option( 'dbem_bookings_anonymous' ) && !get_option( 'dbem_bookings_registration_disable' ) && ! empty( $EM_Booking->person_id ) ) {
295
+ $EM_Person = $EM_Booking->get_person();
296
+ if ( strtotime( $EM_Person->data->user_registered ) >= $this->registered_timer ) {
297
+ if ( is_multisite() ) {
298
+ include_once( ABSPATH . '/wp-admin/includes/ms.php' );
299
+ wpmu_delete_user( $EM_Person->ID );
300
+ } else {
301
+ include_once( ABSPATH . '/wp-admin/includes/user.php' );
302
+ wp_delete_user( $EM_Person->ID );
303
+ }
304
+
305
+ // remove email confirmation
306
+ global $EM_Notices;
307
+ $EM_Notices->notices['confirms'] = array();
308
+ }
309
+ }
310
+
311
+ // Delete booking
312
+ $EM_Booking->delete();
313
+ return false;
314
+ }
315
+ }
316
+ }
317
+ return $result;
318
+ }
319
+
320
+ /**
321
+ * Refunds
322
+ * @since 1.3
323
+ * @version 1.1
324
+ */
325
+ public function refunds( $result, $EM_Booking ) {
326
+ // Cancellation = refund
327
+ if ( $EM_Booking->booking_status == 3 && $EM_Booking->previous_status == 1 && $this->prefs['refund'] > 0 ) {
328
+
329
+ // Make sure user has paid for this to refund
330
+ if ( $this->has_paid( $EM_Booking ) ) {
331
+
332
+ // Price
333
+ if ( $this->single_currency() )
334
+ $price = $this->core->number( $EM_Booking->booking_price );
335
+ else
336
+ $price = $this->core->number( $this->prefs['rate']*$EM_Booking->booking_price );
337
+
338
+ // Refund
339
+ if ( $this->prefs['refund'] != 100 )
340
+ $refund = ( $this->prefs['refund'] / 100 ) * $price;
341
+ else
342
+ $refund = $price;
343
+
344
+ // Charge
345
+ $this->core->add_creds(
346
+ 'ticket_purchase_refund',
347
+ $EM_Booking->person->ID,
348
+ $refund,
349
+ $this->prefs['log']['refund'],
350
+ $EM_Booking->event->post_id,
351
+ array( 'ref_type' => 'post', 'bid' => (int) $booking_id ),
352
+ $this->mycred_type
353
+ );
354
+ }
355
+ }
356
+ return $result;
357
+ }
358
+
359
+ /**
360
+ * Customize Booking Table Actions
361
+ * @since 1.3
362
+ * @version 1.0
363
+ */
364
+ function bookings_table_actions( $actions, $EM_Booking ) {
365
+ if ( $EM_Booking->booking_status == 1 && $this->uses_gateway( $EM_Booking ) ) {
366
+ return array(
367
+ 'reject' => '<a class="em-bookings-reject" href="' . em_add_get_params( $url, array(
368
+ 'action' => 'bookings_reject',
369
+ 'booking_id' => $EM_Booking->booking_id
370
+ ) ) . '">' . __( 'Reject', 'mycred' ) . '</a>',
371
+ 'delete' => '<span class="trash"><a class="em-bookings-delete" href="' . em_add_get_params( $url, array(
372
+ 'action' => 'bookings_delete',
373
+ 'booking_id' => $EM_Booking->booking_id
374
+ ) ) . '">' . __( 'Delete', 'mycred' ) . '</a></span>',
375
+ 'edit' => '<a class="em-bookings-edit" href="' . em_add_get_params( $EM_Booking->get_event()->get_bookings_url(), array(
376
+ 'booking_id' => $EM_Booking->booking_id,
377
+ 'em_ajax' => null,
378
+ 'em_obj' => null
379
+ ) ) . '">' . __( 'Edit/View', 'mycred' ) . '</a>'
380
+ );
381
+ }
382
+
383
+ return $actions;
384
+ }
385
+
386
+ /**
387
+ * Can Pay Check
388
+ * Checks if the user can pay for their booking.
389
+ * @since 1.2
390
+ * @version 1.1
391
+ */
392
+ public function can_pay( $EM_Booking ) {
393
+ $EM_Event = $EM_Booking->get_event();
394
+ // You cant pay for free events
395
+ if ( $EM_Event->is_free() ) return false;
396
+
397
+ $balance = $this->core->get_users_cred( $EM_Booking->person->ID, $this->mycred_type );
398
+ if ( $balance <= $this->core->zero() ) return false;
399
+
400
+ $price = $this->core->number( $EM_Booking->booking_price );
401
+ if ( $price == $this->core->zero() ) return true;
402
+ if ( ! $this->single_currency() ) {
403
+ $exchange_rate = $this->prefs['rate'];
404
+ $price = $this->core->number( $exchange_rate*$price );
405
+ }
406
+
407
+ if ( $balance-$price < $this->core->zero() ) return false;
408
+
409
+ return true;
410
+ }
411
+
412
+ /**
413
+ * Has Paid
414
+ * Checks if the user has paid for booking
415
+ * @since 1.3
416
+ * @version 1.2
417
+ */
418
+ public function has_paid( $EM_Booking ) {
419
+ if ( $this->core->has_entry(
420
+ 'ticket_purchase',
421
+ $EM_Booking->event->post_id,
422
+ $EM_Booking->person->ID,
423
+ array(
424
+ 'ref_type' => 'post',
425
+ 'bid' => (int) $EM_Booking->booking_id
426
+ ),
427
+ $this->mycred_type
428
+ ) )
429
+ return true;
430
+
431
+ return false;
432
+ }
433
+
434
+ /**
435
+ * Getway Settings
436
+ * @since 1.3
437
+ * @version 1.2
438
+ */
439
+ function mysettings() {
440
+ global $page, $action;
441
+ $gateway_link = admin_url( 'edit.php?post_type=' . EM_POST_TYPE_EVENT . '&page=events-manager-options#bookings' );
442
+
443
+ if ( $this->prefs['setup'] == 'multi' )
444
+ $box = 'display: block;';
445
+ else
446
+ $box = 'display: none;';
447
+
448
+ $exchange_message = sprintf(
449
+ __( 'How many %s is 1 %s worth?', 'mycred' ),
450
+ $this->core->plural(),
451
+ em_get_currency_symbol()
452
+ );
453
+
454
+ $mycred_types = mycred_get_types();
455
+
456
+ do_action( 'mycred_em_before_settings', $this ); ?>
457
+
458
+ <h4><?php _e( 'Setup', 'mycred' ); ?></h4>
459
+ <table class="form-table">
460
+ <?php if ( count( $mycred_types ) > 1 ) : ?>
461
+
462
+ <tr>
463
+ <th scope="row"><?php _e( 'Point Type', 'mycred' ); ?></th>
464
+ <td>
465
+ <?php mycred_types_select_from_dropdown( 'mycred_gateway[type]', 'mycred-gateway-type', $this->prefs['type'] ); ?>
466
+
467
+ </td>
468
+ </tr>
469
+ <?php else : ?>
470
+
471
+ <input type="hidden" name="mycred_gateway[type]" value="mycred_default" />
472
+ <?php endif; ?>
473
+
474
+ <tr>
475
+ <th scope="row"><?php _e( 'Payments', 'mycred' ); ?></th>
476
+ <td>
477
+ <input type="radio" name="mycred_gateway[setup]" id="mycred-gateway-setup-off" value="off"<?php checked( $this->prefs['setup'], 'off' ); ?> /> <label for="mycred-gateway-setup-off"><?php echo $this->core->template_tags_general( __( 'Disabled - Users CAN NOT pay for tickets using %plural%.', 'mycred' ) ); ?></label><br />
478
+ <input type="radio" name="mycred_gateway[setup]" id="mycred-gateway-setup-single" value="single"<?php checked( $this->prefs['setup'], 'single' ); ?> /> <label for="mycred-gateway-setup-single"><?php echo $this->core->template_tags_general( __( 'Single - Users can ONLY pay for tickets using %plural%.', 'mycred' ) ); ?></label><br />
479
+ <input type="radio" name="mycred_gateway[setup]" id="mycred-gateway-setup-multi" value="multi"<?php checked( $this->prefs['setup'], 'multi' ); ?> /> <label for="mycred-gateway-setup-multi"><?php echo $this->core->template_tags_general( __( 'Multi - Users can pay for tickets using other gateways or %plural%.', 'mycred' ) ); ?></label>
480
+ </td>
481
+ </tr>
482
+ <tr>
483
+ <th scope="row"><?php _e( 'Refunds', 'mycred' ); ?></th>
484
+ <td>
485
+ <input name="mycred_gateway[refund]" type="text" id="mycred-gateway-log-refund" value="<?php echo $this->prefs['refund']; ?>" size="5" /> %<br />
486
+ <span class="description"><?php _e( 'The percentage of the paid amount to refund if a user cancels their booking. Use zero for no refunds. No refunds are given to "Rejected" bookings!', 'mycred' ); ?></span>
487
+ </td>
488
+ </tr>
489
+ <tr>
490
+ <th scope="row"><?php _e( 'Profit Sharing', 'mycred' ); ?></th>
491
+ <td>
492
+ <input name="mycred_gateway[share]" type="text" id="mycred-gateway-profit-sharing" value="<?php echo $this->prefs['share']; ?>" size="5" /> %<br />
493
+ <span class="description"><?php _e( 'Option to share sales with the product owner. Use zero to disable.', 'mycred' ); ?></span>
494
+ </td>
495
+ </tr>
496
+ </table>
497
+ <table class="form-table" id="mycred-exchange-rate" style="<?php echo $box; ?>">
498
+ <tr>
499
+ <th scope="row"><?php _e( 'Exchange Rate', 'mycred' ); ?></th>
500
+ <td>
501
+ <input name="mycred_gateway[rate]" type="text" id="mycred-gateway-rate" size="6" value="<?php echo $this->prefs['rate']; ?>" /><br />
502
+ <span class="description"><?php echo $exchange_message; ?></span>
503
+ </td>
504
+ </tr>
505
+ </table>
506
+ <h4><?php _e( 'Log Templates', 'mycred' ); ?></h4>
507
+ <table class="form-table">
508
+ <tr>
509
+ <th scope="row"><?php _e( 'Purchases', 'mycred' ); ?></th>
510
+ <td>
511
+ <input name="mycred_gateway[log][purchase]" type="text" id="mycred-gateway-log-purchase" style="width: 95%;" value="<?php echo $this->prefs['log']['purchase']; ?>" size="45" /><br />
512
+ <span class="description"><?php echo $this->core->available_template_tags( array( 'general', 'post' ) ); ?>></span>
513
+ </td>
514
+ </tr>
515
+ <tr>
516
+ <th scope="row"><?php _e( 'Refunds', 'mycred' ); ?></th>
517
+ <td>
518
+ <input name="mycred_gateway[log][refund]" type="text" id="mycred-gateway-log-refund" style="width: 95%;" value="<?php echo $this->prefs['log']['refund']; ?>" size="45" /><br />
519
+ <span class="description"><?php echo $this->core->available_template_tags( array( 'general', 'post' ) ); ?></span>
520
+ </td>
521
+ </tr>
522
+ </table>
523
+ <script type="text/javascript">
524
+ jQuery(function($){
525
+ $('input[name="mycred_gateway[setup]"]').change(function(){
526
+ if ( $(this).val() == 'multi' ) {
527
+ $('#mycred-exchange-rate').show();
528
+ }
529
+ else {
530
+ $('#mycred-exchange-rate').hide();
531
+ }
532
+ });
533
+ });
534
+ </script>
535
+ <h4><?php _e( 'Labels', 'mycred' ); ?></h4>
536
+ <table class="form-table">
537
+ <tr valign="top">
538
+ <th scope="row"><?php _e( 'Payment Link Label', 'mycred' ); ?></th>
539
+ <td>
540
+ <input name="mycred_gateway[labels][link]" type="text" id="mycred-gateway-labels-link" style="width: 95%" value="<?php echo $this->prefs['labels']['link']; ?>" size="45" /><br />
541
+ <span class="description"><?php _e( 'The payment link shows / hides the payment form under "My Bookings". No HTML allowed.', 'mycred' ); ?></span>
542
+ </td>
543
+ </tr>
544
+ <tr valign="top">
545
+ <th scope="row"><?php _e( 'Payment Header', 'mycred' ); ?></th>
546
+ <td>
547
+ <input name="mycred_gateway[labels][header]" type="text" id="mycred-gateway-labels-header" style="width: 95%" value="<?php echo $this->prefs['labels']['header']; ?>" size="45" /><br />
548
+ <span class="description"><?php _e( 'Shown on top of the payment form. No HTML allowed.', 'mycred' ); ?></span>
549
+ </td>
550
+ </tr>
551
+ <tr valign="top">
552
+ <th scope="row"><?php _e( 'Button Label', 'mycred' ); ?></th>
553
+ <td>
554
+ <input name="mycred_gateway[labels][button]" type="text" id="mycred-gateway-labels-button" style="width: 95%" value="<?php echo $this->prefs['labels']['button']; ?>" size="45" /><br />
555
+ <span class="description"><?php _e( 'The button label for payments. No HTML allowed!', 'mycred' ); ?></span>
556
+ </td>
557
+ </tr>
558
+ </table>
559
+ <h4><?php _e( 'Messages', 'mycred' ); ?></h4>
560
+ <table class='form-table'>
561
+ <tr valign="top">
562
+ <th scope="row"><?php _e( 'Successful Payments', 'mycred' ); ?></th>
563
+ <td>
564
+ <input type="text" name="mycred_gateway[messages][success]" id="mycred-gateway-messages-success" style="width: 95%;" value="<?php echo stripslashes( $this->prefs['messages']['success'] ); ?>" /><br />
565
+ <span class="description"><?php _e( 'No HTML allowed!', 'mycred' ); ?><br /><?php echo $this->core->available_template_tags( array( 'general' ) ); ?></span>
566
+ </td>
567
+ </tr>
568
+ <tr valign="top">
569
+ <th scope="row"><?php _e( 'Insufficient Funds', 'mycred' ); ?></th>
570
+ <td>
571
+ <input type="text" name="mycred_gateway[messages][error]" id="mycred-gateway-messages-error" style="width: 95%;" value="<?php echo stripslashes( $this->prefs['messages']['error'] ); ?>" /><br />
572
+ <span class="description"><?php _e( 'No HTML allowed!', 'mycred' ); ?><br /><?php echo $this->core->available_template_tags( array( 'general' ) ); ?></span>
573
+ </td>
574
+ </tr>
575
+ </table>
576
+ <?php do_action( 'mycred_em_after_settings', $this );
577
+ }
578
+
579
+ /**
580
+ * Update Getway Settings
581
+ * @since 1.3
582
+ * @version 1.1
583
+ */
584
+ function update() {
585
+ parent::update();
586
+ if ( ! isset( $_POST['mycred_gateway'] ) || ! is_array( $_POST['mycred_gateway'] ) ) return;
587
+
588
+ // Prep
589
+ $data = $_POST['mycred_gateway'];
590
+ $new_settings = array();
591
+
592
+ // Setup
593
+ $new_settings['setup'] = $data['setup'];
594
+ $new_settings['type'] = sanitize_text_field( $data['type'] );
595
+ $new_settings['refund'] = abs( $data['refund'] );
596
+ $new_settings['share'] = abs( $data['share'] );
597
+
598
+ // Logs
599
+ $new_settings['log']['purchase'] = trim( stripslashes( $data['log']['purchase'] ) );
600
+ $new_settings['log']['refund'] = trim( stripslashes( $data['log']['refund'] ) );
601
+
602
+ if ( $new_settings['setup'] == 'multi' )
603
+ $new_settings['rate'] = sanitize_text_field( $data['rate'] );
604
+ else
605
+ $new_settings['rate'] = $this->prefs['rate'];
606
+
607
+ // Override Pricing Options
608
+ if ( $new_settings['setup'] == 'single' ) {
609
+ update_option( 'dbem_bookings_currency_decimal_point', $this->core->format['separators']['decimal'] );
610
+ update_option( 'dbem_bookings_currency_thousands_sep', $this->core->format['separators']['thousand'] );
611
+ update_option( 'dbem_bookings_currency', 'XMY' );
612
+ if ( empty( $this->core->before ) && !empty( $this->core->after ) )
613
+ $format = '@ #';
614
+ elseif ( !empty( $this->core->before ) && empty( $this->core->after ) )
615
+ $format = '# @';
616
+ update_option( 'dbem_bookings_currency_format', $format );
617
+ }
618
+
619
+ // Labels
620
+ $new_settings['labels']['link'] = sanitize_text_field( stripslashes( $data['labels']['link'] ) );
621
+ $new_settings['labels']['header'] = sanitize_text_field( stripslashes( $data['labels']['header'] ) );
622
+ $new_settings['labels']['button'] = sanitize_text_field( stripslashes( $data['labels']['button'] ) );
623
+
624
+ // Messages
625
+ $new_settings['messages']['success'] = sanitize_text_field( stripslashes( $data['messages']['success'] ) );
626
+ $new_settings['messages']['error'] = sanitize_text_field( stripslashes( $data['messages']['error'] ) );
627
+
628
+ // Save Settings
629
+ $current = $this->prefs;
630
+ $this->prefs = mycred_apply_defaults( $current, $new_settings );
631
+ update_option( 'mycred_eventsmanager_gateway_prefs', $this->prefs );
632
+
633
+ // Let others play
634
+ do_action( 'mycred_em_save_settings', $this );
635
+
636
+ //default action is to return true
637
+ return true;
638
+ }
639
+ }
640
+ }
641
+ ?>
addons/{buy-creds/includes → gateway/membership}/index.php RENAMED
File without changes
addons/import/includes/File-CSV-DataSource.php ADDED
@@ -0,0 +1,834 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
3
+ if ( !defined( 'myCRED_VERSION' ) ) exit;
4
+ /**
5
+ * CSV Import Class
6
+ *
7
+ * LICENSE: The MIT License
8
+ *
9
+ * Copyright (c) <2008> <Kazuyoshi Tlacaelel>
10
+ *
11
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
12
+ * of this software and associated documentation files (the "Software"), to deal
13
+ * in the Software without restriction, including without limitation the rights
14
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
15
+ * copies of the Software, and to permit persons to whom the Software is
16
+ * furnished to do so, subject to the following conditions:
17
+ *
18
+ * The above copyright notice and this permission notice shall be included in
19
+ * all copies or substantial portions of the Software.
20
+ *
21
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
22
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
23
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
24
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
25
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
26
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
27
+ * THE SOFTWARE.
28
+ *
29
+ * @author Kazuyoshi Tlacaelel <kazu.dev@gmail.com>
30
+ * @edited Gabriel Sebastian Merovingi
31
+ * @copyright 2008 Kazuyoshi Tlacaelel
32
+ * @license The MIT License
33
+ * @version 1.0.1
34
+ * @link http://code.google.com/p/php-csv-parser/
35
+ */
36
+ if ( !class_exists( 'File_CSV_DataSource' ) ) {
37
+ class File_CSV_DataSource {
38
+
39
+ /**
40
+ * CSV Parsing Default-settings
41
+ * @var array
42
+ * @access public
43
+ */
44
+ public $settings = array(
45
+ 'delimiter' => ',',
46
+ 'eol' => ";",
47
+ 'length' => 999999,
48
+ 'escape' => '"'
49
+ );
50
+
51
+ /**
52
+ * Imported Data from CSV
53
+ * @var array
54
+ * @access protected
55
+ */
56
+ protected $rows = array();
57
+
58
+ /**
59
+ * CSV File to parse
60
+ * @var string
61
+ * @access protected
62
+ */
63
+ protected $_filename = '';
64
+
65
+ /**
66
+ * CSV Headers to parse
67
+ * @var array
68
+ * @access protected
69
+ */
70
+ protected $headers = array();
71
+
72
+ /**
73
+ * Data Load Initialize
74
+ * @param mixed $filename please look at the load() method
75
+ * @access public
76
+ * @see load()
77
+ * @return void
78
+ */
79
+ public function __construct( $filename = null ) {
80
+ $this->load( $filename );
81
+ }
82
+
83
+ /**
84
+ * CSV File Loader
85
+ * Indicates the object which file is to be loaded
86
+ *
87
+ * @param string $filename the csv filename to load
88
+ * @access public
89
+ * @return boolean true if file was loaded successfully
90
+ * @see isSymmetric(), getAsymmetricRows(), symmetrize()
91
+ */
92
+ public function load( $filename ) {
93
+ $this->_filename = $filename;
94
+ $this->flush();
95
+ return $this->parse();
96
+ }
97
+
98
+ /**
99
+ * Settings Alterator
100
+ * Lets you define different settings for scanning given array will override the internal settings
101
+ *
102
+ * @param mixed $array containing settings to use
103
+ * @access public
104
+ * @return boolean true if changes where applyed successfully
105
+ * @see $settings
106
+ */
107
+ public function settings( $array ) {
108
+ $this->settings = array_merge( $this->settings, $array );
109
+ }
110
+
111
+ /**
112
+ * Header Fetcher
113
+ * Gets csv headers into an array
114
+ *
115
+ * @access public
116
+ * @return array
117
+ */
118
+ public function getHeaders() {
119
+ return $this->headers;
120
+ }
121
+
122
+ /**
123
+ * Header Counter
124
+ * Retrives the total number of loaded headers
125
+ *
126
+ * @access public
127
+ * @return integer gets the length of headers
128
+ */
129
+ public function countHeaders() {
130
+ return count( $this->headers );
131
+ }
132
+
133
+ /**
134
+ * Header and Row Relationship Builder
135
+ * Attempts to create a relationship for every single cell that was captured and its corresponding header.
136
+ * The sample below shows how a connection/relationship is built.
137
+ *
138
+ * @param array $columns the columns to connect, if nothing is given all headers will be used to create a connection
139
+ * @access public
140
+ * @return array If the data is not symmetric an empty array will be returned instead
141
+ * @see isSymmetric(), getAsymmetricRows(), symmetrize(), getHeaders()
142
+ */
143
+ public function connect( $columns = array() ) {
144
+ if ( !$this->isSymmetric() ) return array();
145
+
146
+ if ( !is_array( $columns ) ) return array();
147
+
148
+ if ( $columns === array() ) $columns = $this->headers;
149
+
150
+ $ret_arr = array();
151
+
152
+ foreach ( $this->rows as $record ) {
153
+ $item_array = array();
154
+ foreach ( $record as $column => $value ) {
155
+ $header = $this->headers[$column];
156
+ if ( in_array( $header, $columns ) ) {
157
+ $item_array[$header] = $value;
158
+ }
159
+ }
160
+
161
+ // do not append empty results
162
+ if ( $item_array !== array() )
163
+ array_push( $ret_arr, $item_array );
164
+ }
165
+
166
+ return $ret_arr;
167
+ }
168
+
169
+ /**
170
+ * Data Length/Symmetry Checker
171
+ * Tells if the headers and all of the contents length match.
172
+ *
173
+ * Note: there is a lot of methods that won't work if data is not symmetric this method is very important!
174
+ *
175
+ * @access public
176
+ * @return boolean
177
+ * @see symmetrize(), getAsymmetricRows(), isSymmetric()
178
+ */
179
+ public function isSymmetric() {
180
+ $hc = count( $this->headers );
181
+ foreach ( $this->rows as $row ) {
182
+ if ( count( $row ) != $hc ) {
183
+ return false;
184
+ }
185
+ }
186
+ return true;
187
+ }
188
+
189
+ /**
190
+ * Asymmetric Data Fetcher
191
+ * Finds the rows that do not match the headers length lets assume that we add one more row to our csv file.
192
+ * that has only two values. Something like
193
+ *
194
+ * @access public
195
+ * @return array filled with rows that do not match headers
196
+ * @see getHeaders(), symmetrize(), isSymmetric(),
197
+ * getAsymmetricRows()
198
+ */
199
+ public function getAsymmetricRows() {
200
+ $ret_arr = array();
201
+ $hc = count( $this->headers );
202
+ foreach ( $this->rows as $row ) {
203
+ if ( count( $row ) != $hc ) {
204
+ $ret_arr[] = $row;
205
+ }
206
+ }
207
+ return $ret_arr;
208
+ }
209
+
210
+ /**
211
+ * All Rows Length Equalizer
212
+ * Makes the length of all rows and headers the same. If no $value is given
213
+ * all unexistent cells will be filled with empty spaces
214
+ *
215
+ * @param mixed $value the value to fill the unexistent cells
216
+ * @access public
217
+ * @return array
218
+ * @see isSymmetric(), getAsymmetricRows(), symmetrize()
219
+ */
220
+ public function symmetrize( $value = '' ) {
221
+ $max_length = 0;
222
+ $headers_length = count( $this->headers );
223
+
224
+ foreach ( $this->rows as $row ) {
225
+ $row_length = count( $row );
226
+ if ( $max_length < $row_length ) {
227
+ $max_length = $row_length;
228
+ }
229
+ }
230
+
231
+ if ( $max_length < $headers_length ) $max_length = $headers_length;
232
+
233
+ foreach ( $this->rows as $key => $row ) {
234
+ $this->rows[$key] = array_pad( $row, $max_length, $value );
235
+ }
236
+
237
+ $this->headers = array_pad( $this->headers, $max_length, $value );
238
+ }
239
+
240
+ /**
241
+ * Grid Walker
242
+ * Travels through the whole dataset executing a callback per each cell
243
+ *
244
+ * Note: callback functions get the value of the cell as an argument, and whatever that
245
+ * callback returns will be used to replace the current value of that cell.
246
+ *
247
+ * @param string $callback the callback function to be called per each cell in the dataset.
248
+ * @access public
249
+ * @return void
250
+ * @see walkColumn(), walkRow(), fillColumn(), fillRow(), fillCell()
251
+ */
252
+ public function walkGrid( $callback ) {
253
+ foreach ( array_keys( $this->getRows() ) as $key ) {
254
+ if ( !$this->walkRow( $key, $callback ) ) {
255
+ return false;
256
+ }
257
+ }
258
+ return true;
259
+ }
260
+
261
+ /**
262
+ * Column Fetcher
263
+ * Gets all the data for a specific column identified by $name
264
+ *
265
+ * Note! $name is the same as the items returned by getHeaders()
266
+ *
267
+ * @param string $name the name of the column to fetch
268
+ * @access public
269
+ * @return array filled with values of a column
270
+ * @see getHeaders(), fillColumn(), appendColumn(), getCell(), getRows(),
271
+ * getRow(), hasColumn()
272
+ */
273
+ public function getColumn( $name ) {
274
+ if ( !in_array( $name, $this->headers ) ) return array();
275
+
276
+ $ret_arr = array();
277
+ $key = array_search( $name, $this->headers, true );
278
+ foreach ( $this->rows as $data ) {
279
+ $ret_arr[] = $data[$key];
280
+ }
281
+ return $ret_arr;
282
+ }
283
+
284
+ /**
285
+ * Column Existance Checker
286
+ * Checks if a column exists, columns are identified by their header name.
287
+ *
288
+ * @param string $string an item returned by getHeaders()
289
+ * @access public
290
+ * @return boolean
291
+ * @see getHeaders()
292
+ */
293
+ public function hasColumn( $string ) {
294
+ return in_array( $string, $this->headers );
295
+ }
296
+
297
+ /**
298
+ * Column Appender
299
+ * Appends a column and each or all values in it can be dinamically filled. Only when the $values argument is given.
300
+ *
301
+ * @param string $column an item returned by getHeaders()
302
+ * @param mixed $values same as fillColumn()
303
+ * @access public
304
+ * @return boolean
305
+ * @see getHeaders(), fillColumn(), fillCell(), createHeaders(),
306
+ * setHeaders()
307
+ */
308
+ public function appendColumn( $column, $values = null ) {
309
+ if ( $this->hasColumn( $column ) ) return false;
310
+
311
+ $this->headers[] = $column;
312
+ $length = $this->countHeaders();
313
+ $rows = array();
314
+
315
+ foreach ( $this->rows as $row ) {
316
+ $rows[] = array_pad( $row, $length, '' );
317
+ }
318
+
319
+ $this->rows = $rows;
320
+
321
+ if ( $values === null ) $values = '';
322
+
323
+ return $this->fillColumn( $column, $values );
324
+ }
325
+
326
+ /**
327
+ * Collumn Data Injector
328
+ * Fills alll the data in the given column with $values
329
+ *
330
+ * @param mixed $column the column identified by a string
331
+ * @param mixed $values ither one of the following
332
+ * - (Number) will fill the whole column with the value of number
333
+ * - (String) will fill the whole column with the value of string
334
+ * - (Array) will fill the while column with the values of array
335
+ * the array gets ignored if it does not match the length of rows
336
+ *
337
+ * @access public
338
+ * @return void
339
+ */
340
+ public function fillColumn( $column, $values = null ) {
341
+ if ( !$this->hasColumn( $column ) ) return false;
342
+
343
+ if ( $values === null ) return false;
344
+
345
+ if ( !$this->isSymmetric() ) return false;
346
+
347
+ $y = array_search( $column, $this->headers );
348
+
349
+ if ( is_numeric( $values ) || is_string( $values ) ) {
350
+ foreach ( range( 0, $this->countRows() -1 ) as $x ) {
351
+ $this->fillCell( $x, $y, $values );
352
+ }
353
+ return true;
354
+ }
355
+
356
+ if ( $values === array() ) return false;
357
+
358
+ $length = $this->countRows();
359
+ if ( is_array( $values ) && $length == count( $values ) ) {
360
+ for ( $x = 0; $x < $length; $x++ ) {
361
+ $this->fillCell( $x, $y, $values[$x] );
362
+ }
363
+ return true;
364
+ }
365
+
366
+ return false;
367
+ }
368
+
369
+ /**
370
+ * Column Remover
371
+ * Completly removes a whole column identified by $name
372
+ * Note: that this function will only work if data is symmetric.
373
+ *
374
+ * @param string $name same as the ones returned by getHeaders();
375
+ * @access public
376
+ * @return boolean
377
+ * @see hasColumn(), getHeaders(), createHeaders(), setHeaders(),
378
+ * isSymmetric(), getAsymmetricRows()
379
+ */
380
+ public function removeColumn( $name ) {
381
+ if ( !in_array( $name, $this->headers ) ) return false;
382
+
383
+ if ( !$this->isSymmetric() ) return false;
384
+
385
+ $key = array_search( $name, $this->headers );
386
+ unset( $this->headers[$key] );
387
+ $this->resetKeys( $this->headers );
388
+
389
+ foreach ( $this->rows as $target => $row ) {
390
+ unset( $this->rows[$target][$key] );
391
+ $this->resetKeys( $this->rows[$target] );
392
+ }
393
+
394
+ return $this->isSymmetric();
395
+ }
396
+
397
+ /**
398
+ * Column Walker
399
+ * Goes through the whole column and executes a callback for each
400
+ * one of the cells in it.
401
+ *
402
+ * Note: callback functions get the value of the cell as an
403
+ * argument, and whatever that callback returns will be used to
404
+ * replace the current value of that cell.
405
+ *
406
+ * @param string $name the header name used to identify the column
407
+ * @param string $callback the callback function to be called per
408
+ * each cell value
409
+ *
410
+ * @access public
411
+ * @return boolean
412
+ * @see getHeaders(), fillColumn(), appendColumn()
413
+ */
414
+ public function walkColumn( $name, $callback ) {
415
+ if ( !$this->isSymmetric() ) return false;
416
+
417
+ if ( !$this->hasColumn( $name ) ) return false;
418
+
419
+ if ( !function_exists( $callback ) ) return false;
420
+
421
+ $column = $this->getColumn( $name );
422
+ foreach ( $column as $key => $cell ) {
423
+ $column[$key] = $callback( $cell );
424
+ }
425
+ return $this->fillColumn( $name, $column );
426
+ }
427
+
428
+ /**
429
+ * Cell Fetcher
430
+ * Gets the value of a specific cell by given coordinates
431
+ *
432
+ * Note: That indexes start with zero, and headers are not
433
+ * searched.
434
+ *
435
+ * @access public
436
+ * @return mixed|false the value of the cell or false if the cell does not exist
437
+ * @see getHeaders(), hasCell(), getRow(), getRows(), getColumn()
438
+ */
439
+ public function getCell( $x, $y ) {
440
+ if ( $this->hasCell( $x, $y ) ) {
441
+ $row = $this->getRow( $x );
442
+ return $row[$y];
443
+ }
444
+ return false;
445
+ }
446
+
447
+ /**
448
+ * Cell Value Filler
449
+ * Replaces the value of a specific cell
450
+ *
451
+ * @param integer $x the row to fetch
452
+ * @param integer $y the column to fetch
453
+ * @param mixed $value the value to fill the cell with
454
+ * @access public
455
+ * @return boolean
456
+ * @see hasCell(), getRow(), getRows(), getColumn()
457
+ */
458
+ public function fillCell( $x, $y, $value ) {
459
+ if ( !$this->hasCell( $x, $y ) ) return false;
460
+
461
+ $row = $this->getRow( $x );
462
+ $row[$y] = $value;
463
+ $this->rows[$x] = $row;
464
+
465
+ return true;
466
+ }
467
+
468
+ /**
469
+ * Checks if a coordinate is valid
470
+ *
471
+ * @param mixed $x the row to fetch
472
+ * @param mixed $y the column to fetch
473
+ * @access public
474
+ * @return void
475
+ */
476
+ public function hasCell( $x, $y ) {
477
+ $has_x = array_key_exists( $x, $this->rows );
478
+ $has_y = array_key_exists( $y, $this->headers );
479
+ return ( $has_x && $has_y );
480
+ }
481
+
482
+ /**
483
+ * Row Fetcher
484
+ * Note: first row is zero
485
+ *
486
+ * @param integer $number the row number to fetch
487
+ * @access public
488
+ * @return array the row identified by number, if $number does
489
+ * not exist an empty array is returned instead
490
+ */
491
+ public function getRow( $number ) {
492
+ $raw = $this->rows;
493
+ if ( array_key_exists( $number, $raw ) ) {
494
+ return $raw[$number];
495
+ }
496
+ return array();
497
+ }
498
+
499
+ /**
500
+ * Multiple Row Fetcher
501
+ * Extracts a rows in the following fashion
502
+ * - all rows if no $range argument is given
503
+ * - a range of rows identified by their key
504
+ * - if rows in range are not found nothing is retrived instead
505
+ * - if no rows were found an empty array is returned
506
+ *
507
+ * @param array $range a list of rows to retrive
508
+ * @access public
509
+ * @return array
510
+ */
511
+ public function getRows( $range = array() ) {
512
+ if ( is_array( $range ) && ( $range === array() ) ) return $this->rows;
513
+
514
+ if ( !is_array( $range ) ) return $this->rows;
515
+
516
+ $ret_arr = array();
517
+ foreach ( $this->rows as $key => $row ) {
518
+ if ( in_array( $key, $range ) ) {
519
+ $ret_arr[] = $row;
520
+ }
521
+ }
522
+ return $ret_arr;
523
+ }
524
+
525
+ /**
526
+ * Row Counter
527
+ * This function will exclude the headers
528
+ *
529
+ * @access public
530
+ * @return integer
531
+ */
532
+ public function countRows() {
533
+ return count( $this->rows );
534
+ }
535
+
536
+ /**
537
+ * Row Appender
538
+ * Aggregates one more row to the currently loaded dataset
539
+ *
540
+ * @param array $values the values to be appended to the row
541
+ * @access public
542
+ * @return boolean
543
+ */
544
+ public function appendRow( $values ) {
545
+ $this->rows[] = array();
546
+ $this->symmetrize();
547
+ return $this->fillRow( $this->countRows() - 1, $values );
548
+ }
549
+
550
+ /**
551
+ * Fill Row
552
+ * Replaces the contents of cells in one given row with $values.
553
+ *
554
+ * @param integer $row the row to fill identified by its key
555
+ * @param mixed $values the value to use, if a string or number
556
+ * is given the whole row will be replaced with this value.
557
+ * if an array is given instead the values will be used to fill
558
+ * the row. Only when the currently loaded dataset is symmetric
559
+ * @access public
560
+ * @return boolean
561
+ * @see isSymmetric(), getAsymmetricRows(), symmetrize(), fillColumn(),
562
+ * fillCell(), appendRow()
563
+ */
564
+ public function fillRow( $row, $values ) {
565
+ if ( !$this->hasRow( $row ) ) return false;
566
+
567
+ if ( is_string( $values ) || is_numeric( $values ) ) {
568
+ foreach ( $this->rows[$row] as $key => $cell ) {
569
+ $this->rows[$row][$key] = $values;
570
+ }
571
+ return true;
572
+ }
573
+
574
+ $eql_to_headers = ( $this->countHeaders() == count( $values ) );
575
+ if ( is_array( $values ) && $this->isSymmetric() && $eql_to_headers ) {
576
+ $this->rows[$row] = $values;
577
+ return true;
578
+ }
579
+
580
+ return false;
581
+ }
582
+
583
+ /**
584
+ * Row Existance Checker
585
+ * Scans currently loaded dataset and checks if a given row identified by $number exists
586
+ *
587
+ * @param mixed $number a numeric value that identifies the row you are trying to fetch.
588
+ * @access public
589
+ * @return boolean
590
+ * @see getRow(), getRows(), appendRow(), fillRow()
591
+ */
592
+ public function hasRow( $number ) {
593
+ return ( in_array( $number, array_keys( $this->rows ) ) );
594
+ }
595
+
596
+ /**
597
+ * Row Remover
598
+ * Removes one row from the current data set.
599
+ *
600
+ * @param mixed $number the key that identifies that row
601
+ * @access public
602
+ * @return boolean
603
+ * @see hasColumn(), getHeaders(), createHeaders(), setHeaders(),
604
+ * isSymmetric(), getAsymmetricRows()
605
+ */
606
+ public function removeRow( $number ) {
607
+ $cnt = $this->countRows();
608
+ $row = $this->getRow( $number );
609
+ if ( is_array( $row ) && ( $row != array() ) ) {
610
+ unset( $this->rows[$number] );
611
+ } else {
612
+ return false;
613
+ }
614
+ $this->resetKeys( $this->rows );
615
+ return ( $cnt == ( $this->countRows() + 1 ) );
616
+ }
617
+
618
+ /**
619
+ * Row Walker
620
+ * Goes through one full row of data and executes a callback function per each cell in that row.
621
+ *
622
+ * Note: callback functions get the value of the cell as an argument, and whatever that callback
623
+ * returns will be used to replace the current value of that cell.
624
+ *
625
+ * @param string|integer $row anything that is numeric is a valid row identificator. As long as
626
+ * it is within the range of the currently loaded dataset
627
+ * @param string $callback the callback function to be executed per each cell in a row
628
+ * @access public
629
+ * @return boolean
630
+ * - false if callback does not exist
631
+ * - false if row does not exits
632
+ */
633
+ public function walkRow( $row, $callback ) {
634
+ if ( !function_exists( $callback ) ) return false;
635
+
636
+ if ( $this->hasRow( $row ) ) {
637
+ foreach ( $this->getRow( $row ) as $key => $value ) {
638
+ $this->rows[$row][$key] = $callback( $value );
639
+ }
640
+ return true;
641
+ }
642
+ return false;
643
+ }
644
+
645
+ /**
646
+ * Raw Data as array
647
+ * Gets the data that was retrived from the csv file as an array
648
+ *
649
+ * Note: that changes and alterations made to rows, columns and values will
650
+ * also reflect on what this function retrives.
651
+ *
652
+ * @access public
653
+ * @return array
654
+ * @see connect(), getHeaders(), getRows(), isSymmetric(), getAsymmetricRows(),
655
+ * symmetrize()
656
+ */
657
+ public function getRawArray() {
658
+ $ret_arr = array();
659
+ $ret_arr[] = $this->headers;
660
+ foreach ( $this->rows as $row ) {
661
+ $ret_arr[] = $row;
662
+ }
663
+ return $ret_arr;
664
+ }
665
+
666
+ /**
667
+ * Header Creator
668
+ * Uses prefix and creates a header for each column suffixed by a numeric value
669
+ * By default the first row is interpreted as headers but if we have a csv file with
670
+ * data only and no headers it becomes really annoying to work with the current loaded data.
671
+ * This function will create a set dinamically generated headers and make the current
672
+ * headers accessable with the row handling functions
673
+ *
674
+ * Note: that the csv file contains only data but no headers
675
+ *
676
+ * @param string $prefix string to use as prefix for each independent header
677
+ * @access public
678
+ * @return boolean fails if data is not symmetric
679
+ * @see isSymmetric(), getAsymmetricRows()
680
+ */
681
+ public function createHeaders( $prefix ) {
682
+ if ( !$this->isSymmetric() ) return false;
683
+
684
+ $length = count( $this->headers ) + 1;
685
+ $this->moveHeadersToRows();
686
+
687
+ $ret_arr = array();
688
+ for ( $i = 1; $i < $length; $i++ ) {
689
+ $ret_arr[] = $prefix . "_$i";
690
+ }
691
+ $this->headers = $ret_arr;
692
+ return $this->isSymmetric();
693
+ }
694
+
695
+ /**
696
+ * Header Injector
697
+ * Uses a $list of values which wil be used to replace current headers.
698
+ *
699
+ * Note: that given $list must match the length of all rows.
700
+ * Known as symmetric. see isSymmetric() and getAsymmetricRows() methods
701
+ * Also, that current headers will be used as first row of data
702
+ * and consecuently all rows order will change with this action.
703
+ *
704
+ * @param array $list a collection of names to use as headers,
705
+ * @access public
706
+ * @return boolean fails if data is not symmetric
707
+ * @see isSymmetric(), getAsymmetricRows(), getHeaders(), createHeaders()
708
+ */
709
+ public function setHeaders( $list ) {
710
+ if ( !$this->isSymmetric() ) return false;
711
+
712
+ if ( !is_array( $list ) ) return false;
713
+
714
+ if ( count( $list ) != count( $this->headers ) ) return false;
715
+
716
+ $this->moveHeadersToRows();
717
+ $this->headers = $list;
718
+ return true;
719
+ }
720
+
721
+ /**
722
+ * CSV Parser
723
+ * Reads csv data and transforms it into php-data
724
+ *
725
+ * @access protected
726
+ * @return boolean
727
+ */
728
+ protected function parse() {
729
+ if ( !$this->validates() ) return false;
730
+
731
+ $c = 0;
732
+ $d = $this->settings['delimiter'];
733
+ $e = $this->settings['escape'];
734
+ $l = $this->settings['length'];
735
+
736
+ $res = fopen( $this->_filename, 'r' );
737
+
738
+ while ( $keys = fgetcsv( $res, $l, $d, $e ) ) {
739
+
740
+ if ( $c == 0 ) {
741
+ $this->headers = $keys;
742
+ } else {
743
+ array_push( $this->rows, $keys );
744
+ }
745
+ $c ++;
746
+ }
747
+
748
+ fclose( $res );
749
+ $this->removeEmpty();
750
+ return true;
751
+ }
752
+
753
+ /**
754
+ * Empty row remover
755
+ * Removes all records that have been defined but have no data.
756
+ *
757
+ * @access protected
758
+ * @return array containing only the rows that have data
759
+ */
760
+ protected function removeEmpty() {
761
+ $ret_arr = array();
762
+ foreach ( $this->rows as $row ) {
763
+ $line = trim( join( '', $row ) );
764
+ if ( !empty( $line ) ) {
765
+ $ret_arr[] = $row;
766
+ }
767
+ }
768
+ $this->rows = $ret_arr;
769
+ }
770
+
771
+ /**
772
+ * CSV File Validator
773
+ * Checks wheather if the given csv file is valid or not
774
+ *
775
+ * @access protected
776
+ * @return boolean
777
+ */
778
+ protected function validates() {
779
+ // file existance
780
+ if ( !file_exists( $this->_filename ) ) return false;
781
+
782
+ // file readability
783
+ if ( !is_readable( $this->_filename ) ) return false;
784
+
785
+ return true;
786
+ }
787
+
788
+ /**
789
+ * Header Relocator
790
+ * @access protected
791
+ * @return void
792
+ */
793
+ protected function moveHeadersToRows() {
794
+ $arr = array();
795
+ $arr[] = $this->headers;
796
+ foreach ( $this->rows as $row ) {
797
+ $arr[] = $row;
798
+ }
799
+ $this->rows = $arr;
800
+ $this->headers = array();
801
+ }
802
+
803
+ /**
804
+ * Array Key Reseter
805
+ * Makes sure that an array's keys are setted in a correct numerical order
806
+ *
807
+ * Note: that this function does not return anything, all changes are made to
808
+ * the original array as a reference
809
+ *
810
+ * @param array &$array any array, if keys are strings they will be replaced with numeric values
811
+ * @access protected
812
+ * @return void
813
+ */
814
+ protected function resetKeys( &$array ) {
815
+ $arr = array();
816
+ foreach ( $array as $item ) {
817
+ $arr[] = $item;
818
+ }
819
+ $array = $arr;
820
+ }
821
+
822
+ /**
823
+ * Object Data Flusher
824
+ * Tells this object to forget all data loaded and start from scratch
825
+ * @access protected
826
+ * @return void
827
+ */
828
+ protected function flush() {
829
+ $this->rows = array();
830
+ $this->headers = array();
831
+ }
832
+ }
833
+ }
834
+ ?>
addons/{buy-creds/modules → import/includes}/index.php RENAMED
File without changes
addons/{email-notices/assets/css → import}/index.php RENAMED
File without changes
addons/import/myCRED-addon-import.php ADDED
@@ -0,0 +1,782 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Addon: Import
4
+ * Addon URI: http://mycred.me/add-ons/import/
5
+ * Version: 1.0.2
6
+ * Description: With the Import add-on you can import CSV files, CubePoints or existing points under any custom user meta values.
7
+ * Author: Gabriel S Merovingi
8
+ * Author URI: http://www.merovingi.com
9
+ */
10
+ // Translate Header (by Dan bp-fr)
11
+ $mycred_addon_header_translate = array(
12
+ __( 'Import', 'mycred' ),
13
+ __( 'With the Import add-on you can import CSV files, CubePoints or existing points under any custom user meta values.', 'mycred' )
14
+ );
15
+
16
+ if ( !defined( 'myCRED_VERSION' ) ) exit;
17
+
18
+ define( 'myCRED_IMPORT', __FILE__ );
19
+ define( 'myCRED_IMPORT_VERSION', myCRED_VERSION . '.1' );
20
+ /**
21
+ * myCRED_Import class
22
+ *
23
+ * Manages all available imports.
24
+ * @since 0.1
25
+ * @version 1.0
26
+ */
27
+ if ( !class_exists( 'myCRED_Import' ) ) {
28
+ class myCRED_Import extends myCRED_Module {
29
+
30
+ public $errors = '';
31
+ public $import_ok = false;
32
+
33
+ /**
34
+ * Construct
35
+ */
36
+ function __construct() {
37
+ parent::__construct( 'myCRED_Import', array(
38
+ 'module_name' => 'import',
39
+ 'labels' => array(
40
+ 'menu' => __( 'Import', 'mycred' ),
41
+ 'page_title' => __( 'Import', 'mycred' ),
42
+ 'page_header' => __( 'Import', 'mycred' )
43
+ ),
44
+ 'screen_id' => 'myCRED_page_import',
45
+ 'accordion' => true,
46
+ 'register' => false,
47
+ 'menu_pos' => 90
48
+ ) );
49
+
50
+ add_action( 'mycred_help', array( $this, 'help' ), 10, 2 );
51
+ }
52
+
53
+ /**
54
+ * Module Init
55
+ * @since 0.1
56
+ * @version 1.0
57
+ */
58
+ public function module_init() {
59
+ $installed = $this->get();
60
+
61
+ // If an import is selected, run it
62
+ if ( empty( $installed ) || !isset( $_REQUEST['selected-import'] ) ) return;
63
+ if ( !array_key_exists( $_REQUEST['selected-import'], $installed ) ) return;
64
+
65
+ $call = 'import_' . $_REQUEST['selected-import'];
66
+ $this->$call();
67
+
68
+ // Open accordion for import
69
+ add_filter( 'mycred_localize_admin', array( $this, 'accordion' ) );
70
+ }
71
+
72
+ /**
73
+ * Adjust Accordion
74
+ * Marks the given import as active.
75
+ * @since 0.1
76
+ * @version 1.0
77
+ */
78
+ public function accordion() {
79
+ $key = array_search( trim( $_REQUEST['selected-import'] ), array_keys( $this->installed ) );
80
+ return array( 'active' => $key );
81
+ }
82
+
83
+ /**
84
+ * Get Imports
85
+ * @since 0.1
86
+ * @version 1.0
87
+ */
88
+ public function get( $save = false ) {
89
+ // Defaults
90
+ $installed['csv'] = array(
91
+ 'title' => __( 'CSV File', 'mycred' ),
92
+ 'description' => __( 'Import %_plural% from a comma-separated values (CSV) file.', 'mycred' )
93
+ );
94
+ $installed['cubepoints'] = array(
95
+ 'title' => __( 'CubePoints', 'mycred' ),
96
+ 'description' => __( 'Import CubePoints', 'mycred' )
97
+ );
98
+ $installed['custom'] = array(
99
+ 'title' => __( 'Custom User Meta', 'mycred' ),
100
+ 'description' => __( 'Import %_plural% from pre-existing custom user meta.', 'mycred' )
101
+ );
102
+ $installed = apply_filters( 'mycred_setup_imports', $installed );
103
+
104
+ $this->installed = $installed;
105
+ return $installed;
106
+ }
107
+
108
+ /**
109
+ * Update Users
110
+ * @param $data (array), required associative array of users and amounts to be added to their account.
111
+ * @since 0.1
112
+ * @version 1.1
113
+ */
114
+ public function update_users( $data = array(), $verify = true ) {
115
+ // Prep
116
+ $id_user_by = 'id';
117
+ if ( isset( $_POST['id_user_by'] ) )
118
+ $id_user_by = $_POST['id_user_by'];
119
+
120
+ $xrate = 1;
121
+ if ( isset( $_POST['xrate'] ) )
122
+ $xrate = $_POST['xrate'];
123
+
124
+ $round = false;
125
+ if ( isset( $_POST['round'] ) && $_POST['round'] != 'none' )
126
+ $round = $_POST['round'];
127
+
128
+ $precision = false;
129
+ if ( isset( $_POST['precision'] ) && $_POST['precision'] != 0 )
130
+ $precision = $_POST['precision'];
131
+
132
+ // Loop
133
+ $imports = $skipped = 0;
134
+ foreach ( $data as $row ) {
135
+ // mycred_user and mycred_amount are two mandatory columns!
136
+ if ( !isset( $row['mycred_user'] ) || empty( $row['mycred_user'] ) ) {
137
+ $skipped = $skipped+1;
138
+ continue;
139
+ }
140
+ if ( !isset( $row['mycred_amount'] ) || empty( $row['mycred_amount'] ) ) {
141
+ $skipped = $skipped+1;
142
+ continue;
143
+ }
144
+
145
+ // Verify User exist
146
+ if ( $verify === true ) {
147
+ // Get User (and with that confirm user exists)
148
+ $user = get_user_by( $id_user_by, $row['mycred_user'] );
149
+
150
+ // User does not exist
151
+ if ( $user === false ) {
152
+ $skipped = $skipped+1;
153
+ continue;
154
+ }
155
+
156
+ // User ID
157
+ $user_id = $user->ID;
158
+ unset( $user );
159
+ }
160
+ else {
161
+ $user_id = $row['mycred_user'];
162
+ }
163
+
164
+ // Users is excluded
165
+ if ( $this->core->exclude_user( $user_id ) ) {
166
+ $skipped = $skipped+1;
167
+ continue;
168
+ }
169
+
170
+ // Amount (can not be zero)
171
+ $cred = $this->core->number( $row['mycred_amount'] );
172
+ if ( $cred == 0 ) {
173
+ $skipped = $skipped+1;
174
+ continue;
175
+ }
176
+
177
+ // If exchange rate is not 1 for 1
178
+ if ( $xrate != 1 ) {
179
+ // Cred = rate*amount
180
+ $amount = $xrate * $row['mycred_amount'];
181
+ $cred = $this->core->round_value( $amount, $round, $precision );
182
+ }
183
+
184
+ // Adjust Balance
185
+ $new_balance = $this->core->update_users_balance( $user_id, $cred );
186
+
187
+ // First we check if the mycred_log column is used
188
+ if ( isset( $row['mycred_log'] ) && !empty( $row['mycred_log'] ) ) {
189
+ $this->core->add_to_log( 'import', $user_id, $cred, $row['mycred_log'] );
190
+ }
191
+ // Second we check if the log template is set
192
+ elseif ( isset( $_POST['log_template'] ) && !empty( $_POST['log_template'] ) ) {
193
+ $this->core->add_to_log( 'import', $user_id, $cred, sanitize_text_field( $_POST['log_template'] ) );
194
+ }
195
+
196
+ $imports = $imports+1;
197
+ }
198
+
199
+ // Pass on the news
200
+ $this->imports = $imports;
201
+ $this->skipped = $skipped;
202
+
203
+ unset( $data );
204
+ }
205
+
206
+ /**
207
+ * CSV Importer
208
+ * Based on the csv-importer plugin. Thanks for teaching me something new.
209
+ *
210
+ * @see http://wordpress.org/extend/plugins/csv-importer/
211
+ * @since 0.1
212
+ * @version 1.0
213
+ */
214
+ public function import_csv() {
215
+ // We need a file. or else...
216
+ if ( !isset( $_FILES['mycred_csv'] ) || empty( $_FILES['mycred_csv']['tmp_name'] ) ) {
217
+ $this->errors = __( 'No file selected. Please select your CSV file and try again.', 'mycred' );
218
+ return;
219
+ }
220
+
221
+ // Grab CSV Data Fetcher
222
+ require_once( myCRED_ADDONS_DIR . 'import/includes/File-CSV-DataSource.php' );
223
+
224
+ // Prep
225
+ $time_start = microtime( true );
226
+ $csv = new File_CSV_DataSource();
227
+ $file = $_FILES['mycred_csv']['tmp_name'];
228
+ $this->strip_BOM( $file );
229
+
230
+ // Failed to load file
231
+ if ( !$csv->load( $file ) ) {
232
+ $this->errors = __( 'Failed to load file.', 'mycred' );
233
+ return;
234
+ }
235
+
236
+ // Equality for all
237
+ $csv->symmetrize();
238
+
239
+ // Update
240
+ $this->update_users( $csv->connect() );
241
+
242
+ // Unlink
243
+ if ( file_exists( $file ) ) {
244
+ @unlink( $file );
245
+ }
246
+
247
+ // Time
248
+ $exec_time = microtime( true ) - $time_start;
249
+
250
+ // Throw an error if there were no imports just skipps
251
+ if ( $this->imports == 0 && $this->skipped != 0 ) {
252
+ $this->errors = sprintf(
253
+ __( 'Zero rows imported! Skipped %d entries. Import completed in %.2f seconds.', 'mycred' ),
254
+ $this->skipped,
255
+ $exec_time
256
+ );
257
+ return;
258
+ }
259
+
260
+ // Throw an error if there were no imports and no skipps
261
+ elseif ( $this->imports == 0 && $this->skipped == 0 ) {
262
+ $this->errors = __( 'No valid records found in file. Make sure you have selected the correct way to identify users in the mycred_user column!', 'mycred' );
263
+ return;
264
+ }
265
+
266
+ // The joy of success
267
+ $this->import_ok = sprintf(
268
+ __( 'Import successfully completed. A total of %d users were effected and %d entires were skipped. Import completed in %.2f seconds.', 'mycred' ),
269
+ $this->imports,
270
+ $this->skipped,
271
+ $exec_time
272
+ );
273
+
274
+ // Clean Up
275
+ unset( $_FILES );
276
+ unset( $csv );
277
+
278
+ // Close accordion
279
+ unset( $_POST );
280
+ }
281
+
282
+ /**
283
+ * Import CubePoints
284
+ * @since 0.1
285
+ * @version 1.2
286
+ */
287
+ public function import_cubepoints() {
288
+ $delete = false;
289
+ if ( isset( $_POST['delete'] ) ) $delete = true;
290
+
291
+ $meta_key = 'cpoints';
292
+ $time_start = microtime( true );
293
+
294
+ global $wpdb;
295
+
296
+ // DB Query
297
+ $SQL = "SELECT * FROM {$wpdb->usermeta} WHERE meta_key = %s;";
298
+ $search = $wpdb->get_results( $wpdb->prepare( $SQL, $meta_key ) );
299
+
300
+ // No results
301
+ if ( $wpdb->num_rows == 0 ) {
302
+ $this->errors = __( 'No CubePoints found.', 'mycred' );
303
+ return;
304
+ }
305
+
306
+ // Found something
307
+ else {
308
+ // Construct a new array for $this->update_users() to match the format used
309
+ // when importing CSV files. User ID goes under 'mycred_user' while 'mycred_amount' holds the value.
310
+ $data = array();
311
+ foreach ( $search as $result ) {
312
+ $data[] = array(
313
+ 'mycred_user' => $result->user_id,
314
+ 'mycred_amount' => $result->meta_value,
315
+ 'mycred_log' => ( isset( $_POST['log_template'] ) ) ? sanitize_text_field( $_POST['log_template'] ) : ''
316
+ );
317
+ }
318
+
319
+ // Update User without the need to verify the user
320
+ $this->update_users( $data, false );
321
+
322
+ // Delete old value if requested
323
+ if ( $delete === true ) {
324
+ foreach ( $search as $result ) {
325
+ delete_user_meta( $result->user_id, $meta_key );
326
+ }
327
+ }
328
+ }
329
+
330
+ // Time
331
+ $exec_time = microtime( true ) - $time_start;
332
+
333
+ // Throw an error if there were no imports just skipps
334
+ if ( $this->imports == 0 && $this->skipped != 0 ) {
335
+ $this->errors = sprintf(
336
+ __( 'Zero CubePoints imported! Skipped %d entries. Import completed in %.2f seconds.', 'mycred' ),
337
+ $this->skipped,
338
+ $exec_time
339
+ );
340
+ return;
341
+ }
342
+
343
+ // Throw an error if there were no imports and no skipps
344
+ elseif ( $this->imports == 0 && $this->skipped == 0 ) {
345
+ $this->errors = __( 'No valid CubePoints founds.', 'mycred' );
346
+ return;
347
+ }
348
+
349
+ // The joy of success
350
+ $this->import_ok = sprintf(
351
+ __( 'Import successfully completed. A total of %d users were effected and %d entires were skipped. Import completed in %.2f seconds.', 'mycred' ),
352
+ $this->imports,
353
+ $this->skipped,
354
+ $exec_time
355
+ );
356
+
357
+ // Clean Up
358
+ unset( $search );
359
+
360
+ // Close Accordion
361
+ unset( $_POST );
362
+ }
363
+
364
+ /**
365
+ * Import Custom User Meta
366
+ * @since 0.1
367
+ * @version 1.0.1
368
+ */
369
+ public function import_custom() {
370
+ if ( !isset( $_POST['meta_key'] ) || empty( $_POST['meta_key'] ) ) {
371
+ $this->errors = __( 'Missing meta key. Not sure what I should be looking for.', 'mycred' );
372
+ return;
373
+ }
374
+
375
+ // Prep
376
+ $delete = false;
377
+ if ( isset( $_POST['delete'] ) ) $delete = true;
378
+
379
+ $meta_key = $_POST['meta_key'];
380
+ $time_start = microtime( true );
381
+
382
+ global $wpdb;
383
+
384
+ // DB Query
385
+ $SQL = "SELECT * FROM {$pwbd->usermeta} WHERE meta_key = %s;";
386
+ $search = $wpdb->get_results( $wpdb->prepare( $SQL, $meta_key ) );
387
+
388
+ // No results
389
+ if ( $wpdb->num_rows == 0 ) {
390
+ $this->errors = sprintf( __( 'No rows found for the <strong>%s</strong> meta key.', 'mycred' ), $meta_key );
391
+ return;
392
+ }
393
+
394
+ // Found something
395
+ else {
396
+ // Construct a new array for $this->update_users() to match the format used
397
+ // when importing CSV files. User ID goes under 'mycred_user' while 'mycred_amount' holds the value.
398
+ $data = array();
399
+ foreach ( $search as $result ) {
400
+ $data[] = array(
401
+ 'mycred_user' => $result->user_id,
402
+ 'mycred_amount' => $result->meta_value
403
+ );
404
+ }
405
+
406
+ // Update User without the need to verify the user
407
+ $this->update_users( $data, false );
408
+
409
+ // Delete old value if requested
410
+ if ( $delete === true ) {
411
+ foreach ( $search as $result ) {
412
+ delete_user_meta( $result->user_id, $meta_key );
413
+ }
414
+ }
415
+ }
416
+
417
+ // Time
418
+ $exec_time = microtime( true ) - $time_start;
419
+
420
+ // Throw an error if there were no imports just skipps
421
+ if ( $this->imports == 0 && $this->skipped != 0 ) {
422
+ $this->errors = sprintf(
423
+ __( 'Zero rows imported! Skipped %d entries. Import completed in %.2f seconds.', 'mycred' ),
424
+ $this->skipped,
425
+ $exec_time
426
+ );
427
+ return;
428
+ }
429
+
430
+ // Throw an error if there were no imports and no skipps
431
+ elseif ( $this->imports == 0 && $this->skipped == 0 ) {
432
+ $this->errors = __( 'No valid records founds.', 'mycred' );
433
+ return;
434
+ }
435
+
436
+ // The joy of success
437
+ $this->import_ok = sprintf(
438
+ __( 'Import successfully completed. A total of %d users were effected and %d entires were skipped. Import completed in %.2f seconds.', 'mycred' ),
439
+ $this->imports,
440
+ $this->skipped,
441
+ $exec_time
442
+ );
443
+
444
+ // Clean Up
445
+ unset( $search );
446
+
447
+ // Close Accordion
448
+ unset( $_POST );
449
+ }
450
+
451
+ /**
452
+ * Admin Page
453
+ * @since 0.1
454
+ * @version 1.0
455
+ */
456
+ public function admin_page() {
457
+ // Security
458
+ if ( !$this->core->can_edit_plugin( get_current_user_id() ) ) wp_die( __( 'Access Denied', 'mycred' ) );
459
+
460
+ // Available Imports
461
+ if ( empty( $this->installed ) )
462
+ $this->get(); ?>
463
+
464
+ <div class="wrap list" id="myCRED-wrap">
465
+ <div id="icon-myCRED" class="icon32"><br /></div>
466
+ <h2><?php echo sprintf( __( '%s Import', 'mycred' ), mycred_label() ); ?></h2>
467
+ <?php
468
+ // Errors
469
+ if ( !empty( $this->errors ) ) {
470
+ echo '<div class="error"><p>' . $this->errors . '</p></div>';
471
+ }
472
+
473
+ // Success
474
+ elseif ( $this->import_ok !== false ) {
475
+ echo '<div class="updated"><p>' . $this->import_ok . '</p></div>';
476
+ } ?>
477
+
478
+ <p><?php _e( 'Remember to de-activate this add-on once you are done importing!', 'mycred' ); ?></p>
479
+ <div class="list-items expandable-li" id="accordion">
480
+ <?php
481
+ if ( !empty( $this->installed ) ) {
482
+ foreach ( $this->installed as $id => $data ) {
483
+ $call = $id . '_form';
484
+ $this->$call( $data );
485
+ }
486
+ } ?>
487
+
488
+ </div>
489
+ </div>
490
+ <?php
491
+ unset( $this );
492
+ }
493
+
494
+ /**
495
+ * CSV Import Form
496
+ * @since 0.1
497
+ * @version 1.0
498
+ */
499
+ public function csv_form( $data ) {
500
+ $max_upload = (int) ( ini_get( 'upload_max_filesize' ) );
501
+ $max_post = (int) ( ini_get( 'post_max_size' ) );
502
+ $memory_limit = (int) ( ini_get( 'memory_limit' ) );
503
+ $upload_mb = min( $max_upload, $max_post, $memory_limit ); ?>
504
+
505
+ <h4><div class="icon icon-active"></div><label><?php echo $data['title']; ?></label></h4>
506
+ <div class="body" style="display:none;">
507
+ <form class="add:the-list: validate" method="post" enctype="multipart/form-data">
508
+ <input type="hidden" name="selected-import" value="csv" />
509
+ <p><?php echo nl2br( $this->core->template_tags_general( $data['description'] ) ); ?></p>
510
+ <label class="subheader" for="mycred-csv-file"><?php _e( 'File', 'mycred' ); ?></label>
511
+ <ol>
512
+ <li>
513
+ <div><input type="file" name="mycred_csv" id="mycred-csv-file" value="" aria-required="true" /></div>
514
+ <span class="description"><?php echo __( 'Maximum allowed upload size is ', 'mycred' ) . $upload_mb . ' Mb<br />' . __( 'Required columns: <code>mycred_user</code> and <code>mycred_amount</code>. Optional columns: <code>mycred_log</code>.', 'mycred' ); ?></span>
515
+ </li>
516
+ </ol>
517
+ <label class="subheader"><?php _e( 'Identify Users By', 'mycred' ); ?></label>
518
+ <ol>
519
+ <li>
520
+ <input type="radio" name="id_user_by" id="mycred-csv-by-id" value="id" checked="checked" /><label for="mycred-csv-by-id"><?php _e( 'ID', 'mycred' ); ?></label><br />
521
+ <input type="radio" name="id_user_by" id="mycred-csv-by-login" value="login" /><label for="mycred-csv-by-login"><?php _e( 'Username', 'mycred' ); ?></label><br />
522
+ <input type="radio" name="id_user_by" id="mycred-csv-by-email" value="email" /><label for="mycred-csv-by-email"><?php _e( 'Email', 'mycred' ); ?></label>
523
+ </li>
524
+ </ol>
525
+ <label class="subheader" for="mycred-csv-xrate"><?php _e( 'Exchange Rate', 'mycred' ); ?></label>
526
+ <ol>
527
+ <li>
528
+ <div class="h2"><input type="text" name="xrate" id="mycred-csv-xrate" value="<?php echo $this->core->format_number( 1 ); ?>" class="short" /> = <?php echo $this->core->format_creds( 1 ); ?></div>
529
+ <span class="description"><?php _e( 'How much is 1 imported value worth?', 'mycred' ); ?></span>
530
+ </li>
531
+ </ol>
532
+ <ol class="inline">
533
+ <li>
534
+ <label><?php _e( 'Round', 'mycred' ); ?></label><br />
535
+ <input type="radio" name="round" id="mycred-csv-round-none" value="none" checked="checked" /> <label for="mycred-csv-round-none"><?php _e( 'None', 'mycred' ); ?></label><br />
536
+ <input type="radio" name="round" id="mycred-csv-round-up" value="up" /> <label for="mycred-csv-round-up"><?php _e( 'Round Up', 'mycred' ); ?></label><br />
537
+ <input type="radio" name="round" id="mycred-csv-round-down" value="down" /> <label for="mycred-csv-round-down"><?php _e( 'Round Down', 'mycred' ); ?></label>
538
+ </li>
539
+ <?php if ( $this->core->format['decimals'] > 0 ) { ?>
540
+
541
+ <li>
542
+ <label for="mycred-csv-precision"><?php _e( 'Precision', 'mycred' ); ?></label>
543
+ <div class="h2"><input type="text" name="precision" id="mycred-csv-precision" value="1" class="short" /></div>
544
+ <span class="description"><?php echo __( 'The optional number of decimal digits to round to. Use zero to round the nearest whole number.', 'mycred' ); ?></span>
545
+ </li>
546
+ <?php } ?>
547
+
548
+ </ol>
549
+ <label class="subheader" for="mycred-csv-log-template"><?php _e( 'Log Entry', 'mycred' ); ?></label>
550
+ <ol>
551
+ <li>
552
+ <div class="h2"><input type="text" name="log_template" id="mycred-csv-log-template" value="" class="long" /></div>
553
+ <span class="description"><?php _e( 'See the help tab for available template tags. Leave blank to disable.', 'mycred' ); ?></span>
554
+ </li>
555
+ </ol>
556
+ <ol>
557
+ <li>
558
+ <input type="submit" name="submit" id="mycred-csv-submit" value="<?php _e( 'Run Import', 'mycred' ); ?>" class="button button-primary button-large" />
559
+ </li>
560
+ </ol>
561
+ </form>
562
+ </div>
563
+ <?php
564
+ }
565
+
566
+ /**
567
+ * CubePoints Import Form
568
+ * @since 0.1
569
+ * @version 1.0
570
+ */
571
+ public function cubepoints_form( $data ) {
572
+ $quick_check = get_users( array(
573
+ 'meta_key' => 'cpoints',
574
+ 'fields' => 'ID'
575
+ ) );
576
+ $cp_users = count( $quick_check ); ?>
577
+
578
+ <h4><div class="icon icon-<?php if ( $cp_users > 0 ) echo 'active'; else echo 'inactive'; ?>"></div><label><?php echo $data['title']; ?></label></h4>
579
+ <div class="body" style="display:none;">
580
+ <form class="add:the-list: validate" method="post" enctype="multipart/form-data">
581
+ <input type="hidden" name="selected-import" value="cubepoints" />
582
+ <p><?php
583
+
584
+ if ( $cp_users > 0 )
585
+ echo sprintf( __( 'Found %d users with CubePoints.', 'mycred' ), $cp_users );
586
+ else
587
+ _e( 'No CubePoints found.', 'mycred' ); ?></p>
588
+ <label class="subheader" for="mycred-cubepoints-user-meta-key"><?php _e( 'Meta Key', 'mycred' ); ?></label>
589
+ <ol>
590
+ <li>
591
+ <div class="h2"><input type="text" name="meta_key" id="mycred-cubepoints-user-meta-key" value="cpoints" class="disabled medium" disabled="disabled" /></div>
592
+ </li>
593
+ </ol>
594
+ <label class="subheader" for="mycred-cubepoints-xrate"><?php _e( 'Exchange Rate', 'mycred' ); ?></label>
595
+ <ol>
596
+ <li>
597
+ <div class="h2"><input type="text" name="xrate" id="mycred-cubepoints-xrate" value="<?php echo $this->core->format_number( 1 ); ?>" class="short" /><?php echo 'CubePoint'; ?> = <?php echo $this->core->format_creds( 1 ); ?></div>
598
+ </li>
599
+ </ol>
600
+ <ol class="inline">
601
+ <li>
602
+ <label><?php _e( 'Round', 'mycred' ); ?></label><br />
603
+ <input type="radio" name="round" id="mycred-cubepoints-round-none" value="none" checked="checked" /> <label for="mycred-cubepoints-round-none"><?php _e( 'Do not round', 'mycred' ); ?></label><br />
604
+ <input type="radio" name="round" id="mycred-cubepoints-round-up" value="up" /> <label for="mycred-cubepoints-round-up"><?php _e( 'Round Up', 'mycred' ); ?></label><br />
605
+ <input type="radio" name="round" id="mycred-cubepoints-round-down" value="down" /> <label for="mycred-cubepoints-round-down"><?php _e( 'Round Down', 'mycred' ); ?></label>
606
+ </li>
607
+ <?php if ( $this->core->format['decimals'] > 0 ) { ?>
608
+
609
+ <li>
610
+ <label for="mycred-cubepoints-precision"><?php _e( 'Precision', 'mycred' ); ?></label>
611
+ <div class="h2"><input type="text" name="precision" id="mycred-cubepoints-precision" value="1" class="short" /></div>
612
+ <span class="description"><?php echo __( 'The optional number of decimal digits to round to. Use zero to round the nearest whole number.', 'mycred' ); ?></span>
613
+ </li>
614
+ <?php } ?>
615
+
616
+ </ol>
617
+ <label class="subheader" for="mycred-cubepoints-delete"><?php _e( 'After Import', 'mycred' ); ?></label>
618
+ <ol>
619
+ <li>
620
+ <input type="checkbox" name="delete" id="mycred-cubepoints-delete" value="no" /> <label for="mycred-cubepoints-delete"><?php _e( 'Delete users CubePoints balance.', 'mycred' ); ?></label>
621
+ </li>
622
+ </ol>
623
+ <label class="subheader" for="mycred-cubepoints-log-template"><?php _e( 'Log Entry', 'mycred' ); ?></label>
624
+ <ol>
625
+ <li>
626
+ <div class="h2"><input type="text" name="log_template" id="mycred-cubepoints-log-template" value="" class="long" /></div>
627
+ <span class="description"><?php _e( 'See the help tab for available template tags. Leave blank to disable.', 'mycred' ); ?></span>
628
+ </li>
629
+ </ol>
630
+ <ol>
631
+ <li>
632
+ <input type="submit" name="submit" id="mycred-cubepoints-submit" value="<?php _e( 'Run Import', 'mycred' ); ?>" class="button button-primary button-large" />
633
+ </li>
634
+ </ol>
635
+ </form>
636
+ </div>
637
+ <?php
638
+ }
639
+
640
+ /**
641
+ * Custom User Meta Import Form
642
+ * @since 0.1
643
+ * @version 1.0
644
+ */
645
+ public function custom_form( $data ) { ?>
646
+
647
+ <h4><div class="icon icon-active"></div><label><?php echo $data['title']; ?></label></h4>
648
+ <div class="body" style="display:none;">
649
+ <form class="add:the-list: validate" method="post" enctype="multipart/form-data">
650
+ <input type="hidden" name="selected-import" value="custom" />
651
+ <p><?php echo nl2br( $this->core->template_tags_general( $data['description'] ) ); ?></p>
652
+ <label class="subheader" for="mycred-custom-user-meta-key"><?php _e( 'Meta Key', 'mycred' ); ?></label>
653
+ <ol>
654
+ <li>
655
+ <div class="h2"><input type="text" name="meta_key" id="mycred-custom-user-meta-key" value="" class="medium" /></div>
656
+ </li>
657
+ </ol>
658
+ <label class="subheader" for="mycred-custom-xrate"><?php _e( 'Exchange Rate', 'mycred' ); ?></label>
659
+ <ol>
660
+ <li>
661
+ <div class="h2"><input type="text" name="xrate" id="mycred-custom-xrate" value="<?php echo $this->core->format_number( 1 ); ?>" class="short" /> = <?php echo $this->core->format_creds( 1 ); ?></div>
662
+ </li>
663
+ </ol>
664
+ <ol class="inline">
665
+ <li>
666
+ <label><?php _e( 'Round', 'mycred' ); ?></label><br />
667
+ <input type="radio" name="round" id="mycred-custom-round-none" value="none" checked="checked" /> <label for="mycred-custom-round-none"><?php _e( 'Do not round', 'mycred' ); ?></label><br />
668
+ <input type="radio" name="round" id="mycred-custom-round-up" value="up" /> <label for="mycred-custom-round-up"><?php _e( 'Round Up', 'mycred' ); ?></label><br />
669
+ <input type="radio" name="round" id="mycred-custom-round-down" value="down" /> <label for="mycred-custom-round-down"><?php _e( 'Round Down', 'mycred' ); ?></label>
670
+ </li>
671
+ <?php if ( $this->core->format['decimals'] > 0 ) { ?>
672
+
673
+ <li>
674
+ <label for="mycred-custom-precision"><?php _e( 'Precision', 'mycred' ); ?></label>
675
+ <div class="h2"><input type="text" name="precision" id="mycred-custom-precision" value="1" class="short" /></div>
676
+ <span class="description"><?php echo __( 'The optional number of decimal digits to round to. Use zero to round the nearest whole number.', 'mycred' ); ?></span>
677
+ </li>
678
+ <?php } ?>
679
+
680
+ </ol>
681
+ <label class="subheader" for="mycred-custom-log-template"><?php _e( 'Log Entry', 'mycred' ); ?></label>
682
+ <ol>
683
+ <li>
684
+ <div class="h2"><input type="text" name="log_template" id="mycred-custom-log-template" value="" class="long" /></div>
685
+ <span class="description"><?php _e( 'See the help tab for available template tags. Leave blank to disable.', 'mycred' ); ?></span>
686
+ </li>
687
+ </ol>
688
+ <label class="subheader" for="mycred-custom-delete"><?php _e( 'After Import', 'mycred' ); ?></label>
689
+ <ol>
690
+ <li>
691
+ <input type="checkbox" name="delete" id="mycred-custom-delete" value="no" /> <label for="mycred-custom-delete"><?php _e( 'Delete the old value.', 'mycred' ); ?></label>
692
+ </li>
693
+ </ol>
694
+ <ol>
695
+ <li>
696
+ <input type="submit" name="submit" id="mycred-custom-submit" value="<?php _e( 'Run Import', 'mycred' ); ?>" class="button button-primary button-large" />
697
+ </li>
698
+ </ol>
699
+ </form>
700
+ </div>
701
+ <?php
702
+ unset( $this );
703
+ }
704
+
705
+ /**
706
+ * Delete BOM from UTF-8 file.
707
+ * @see http://wordpress.org/extend/plugins/csv-importer/
708
+ * @param string $fname
709
+ * @return void
710
+ */
711
+ public function strip_BOM( $fname ) {
712
+ $res = fopen( $fname, 'rb' );
713
+ if ( false !== $res ) {
714
+ $bytes = fread( $res, 3 );
715
+ if ( $bytes == pack( 'CCC', 0xef, 0xbb, 0xbf ) ) {
716
+ fclose( $res );
717
+
718
+ $contents = file_get_contents( $fname );
719
+ if ( false === $contents ) {
720
+ trigger_error( __( 'Failed to get file contents.', 'mycred' ), E_USER_WARNING );
721
+ }
722
+ $contents = substr( $contents, 3 );
723
+ $success = file_put_contents( $fname, $contents );
724
+ if ( false === $success ) {
725
+ trigger_error( __( 'Failed to put file contents.', 'mycred' ), E_USER_WARNING );
726
+ }
727
+ } else {
728
+ fclose( $res );
729
+ }
730
+ }
731
+ }
732
+
733
+ /**
734
+ * Contextual Help
735
+ * @since 0.1
736
+ * @version 1.0
737
+ */
738
+ public function help( $screen_id, $screen ) {
739
+ if ( $screen_id != 'mycred_page_myCRED_page_import' ) return;
740
+
741
+ $screen->add_help_tab( array(
742
+ 'id' => 'mycred-import',
743
+ 'title' => __( 'Import', 'mycred' ),
744
+ 'content' => '
745
+ <p>' . $this->core->template_tags_general( __( 'This add-on lets you import %_plural% either though a CSV-file or from your database. Remember that the import can take time depending on your file size or the number of users being imported.', 'mycred' ) ) . '</p>'
746
+ ) );
747
+ $screen->add_help_tab( array(
748
+ 'id' => 'mycred-import-csv',
749
+ 'title' => __( 'CSV File', 'mycred' ),
750
+ 'content' => '
751
+ <p><strong>' . __( 'CSV Import', 'mycred' ) . '</strong></p>
752
+ <p>' . __( 'Imports using a comma-separated values file requires the following columns:', 'mycred' ) . '</p>
753
+ <p><code>mycred_user</code> ' . __( 'Column identifing the user. All rows must identify the user the same way, either using an ID, Username (user_login) or email. Users that can not be found will be ignored.', 'mycred' ) . '<br />
754
+ <code>mycred_amount</code> ' . __( 'Column with the amount to be imported. If set, an exchange rate is applied to this value before import.', 'mycred' ) . '</p>
755
+ <p>' . __( 'Optionally you can also use the <code>mycred_log</code> column to pre-define the log entry for each import.', 'mycred' ) . '</p>'
756
+ ) );
757
+ $screen->add_help_tab( array(
758
+ 'id' => 'mycred-import-cube',
759
+ 'title' => __( 'Cubepoints', 'mycred' ),
760
+ 'content' => '
761
+ <p><strong>' . __( 'Cubepoints Import', 'mycred' ) . '</strong></p>
762
+ <p>' . __( 'When this page loads, the importer will automatically check if you have been using Cubepoints. If you have, you can import these with the option to delete the original Cubepoints once completed to help keep your database clean.', 'mycred' ) . '</p>
763
+ <p>' . __( 'Before a value is imported, you can apply an exchange rate. To import without changing the value, use 1 as the exchange rate.', 'mycred' ) . '</p>
764
+ <p>' . __( 'You can select to add a log entry for each import or leave the template empty to skip.', 'mycred' ) . '</p>
765
+ <p>' . __( 'The Cubepoints importer will automatically disable itself if no Cubepoints installation exists.', 'mycred' ) . '</p>'
766
+ ) );
767
+ $screen->add_help_tab( array(
768
+ 'id' => 'mycred-import-custom',
769
+ 'title' => __( 'Custom User Meta', 'mycred' ),
770
+ 'content' => '
771
+ <p><strong>' . __( 'Custom User Meta Import', 'mycred' ) . '</strong></p>
772
+ <p>' . __( 'You can import any type of points that have previously been saved in your database. All you need is the meta key under which it has been saved.', 'mycred' ) . '</p>
773
+ <p>' . __( 'Before a value is imported, you can apply an exchange rate. To import without changing the value, use 1 as the exchange rate.', 'mycred' ) . '</p>
774
+ <p>' . __( 'You can select to add a log entry for each import or leave the template empty to skip.', 'mycred' ) . '</p>
775
+ <p>' . __( 'Please note that the meta key is case sensitive and can not contain whitespaces!', 'mycred' ) . '</p>'
776
+ ) );
777
+ }
778
+ }
779
+ $import = new myCRED_Import();
780
+ $import->load();
781
+ }
782
+ ?>
addons/{email-notices/assets → notifications/css}/index.php RENAMED
File without changes
addons/notifications/{assets/css → css}/notify.css RENAMED
File without changes
addons/notifications/{assets/css → js}/index.php RENAMED
File without changes
addons/notifications/{assets/js → js}/notify.js RENAMED
@@ -34,7 +34,7 @@
34
  var defaults = {
35
  inEffect: {opacity: 'show'}, // in effect
36
  inEffectDuration: 600, // in effect duration in miliseconds
37
- stayTime: parseInt( myCRED_Notice.duration, 10 ) * 1000, // time in miliseconds before the item has to disappear
38
  text: '', // content of the item
39
  stay: true, // should the notice item stay or not?
40
  type: 'succes' // could also be error, succes
34
  var defaults = {
35
  inEffect: {opacity: 'show'}, // in effect
36
  inEffectDuration: 600, // in effect duration in miliseconds
37
+ stayTime: parseInt( myCRED_Notice.duration, 10 ), // time in miliseconds before the item has to disappear
38
  text: '', // content of the item
39
  stay: true, // should the notice item stay or not?
40
  type: 'succes' // could also be error, succes
addons/notifications/myCRED-addon-notifications.php CHANGED
@@ -170,9 +170,13 @@ if ( ! class_exists( 'myCRED_Notifications_Module' ) ) :
170
  $data = get_transient( 'mycred_notice_' . $user_id );
171
 
172
  if ( $data === false || ! is_array( $data ) ) return;
173
-
174
- foreach ( $data as $notice )
175
- add_filter( 'mycred_notifications', create_function( '$query', '$query[]=\'' . $notice . '\'; return $query;' ) );
 
 
 
 
176
 
177
  delete_transient( 'mycred_notice_' . $user_id );
178
 
170
  $data = get_transient( 'mycred_notice_' . $user_id );
171
 
172
  if ( $data === false || ! is_array( $data ) ) return;
173
+ /*fixed notification error create_function replase this*/
174
+ foreach ( $data as $notice ){
175
+ $notice_query = function ($query) use ($notice) {
176
+ $query[]= $notice ; return $query;
177
+ };
178
+ add_filter( 'mycred_notifications', $notice_query );
179
+ }
180
 
181
  delete_transient( 'mycred_notice_' . $user_id );
182
 
addons/ranks/assets/js/tweaks.js DELETED
@@ -1,18 +0,0 @@
1
- /**
2
- * myCRED Rank Tweaks
3
- * @since 1.6
4
- * @version 1.0.1
5
- */
6
- (function($) {
7
-
8
- // When the page has loaded, append the point type to the "Add New" button url
9
- // This will make sure the new rank is created for the correct point type.
10
- $( document ).ready(function() {
11
-
12
- var newurl = $( 'a.add-new-h2' ).attr( 'href' );
13
- newurl = newurl + '&ctype=' + myCRED_Ranks.rank_ctype;
14
- $( 'a.add-new-h2' ).attr( 'href', newurl );
15
-
16
- });
17
-
18
- })( jQuery );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
addons/ranks/includes/mycred-rank-object.php DELETED
@@ -1,78 +0,0 @@
1
- <?php
2
- if ( ! defined( 'myCRED_VERSION' ) ) exit;
3
-
4
- /**
5
- * myCRED_Rank class
6
- * @see http://codex.mycred.me/classes/mycred_rank/
7
- * @since 1.7
8
- * @version 1.0
9
- */
10
- if ( ! class_exists( 'myCRED_Rank' ) ) :
11
- class myCRED_Rank extends myCRED_Object {
12
-
13
- public $post_id = false;
14
- public $post = false;
15
- public $title = '';
16
- public $minimum = NULL;
17
- public $maximum = NULL;
18
- public $count = 0;
19
-
20
- public $has_logo = false;
21
- public $logo_id = false;
22
- public $logo_url = false;
23
- public $image_width = false;
24
- public $image_height = false;
25
-
26
- public $point_type = false;
27
-
28
- /**
29
- * Construct
30
- */
31
- function __construct( $rank_id = NULL ) {
32
-
33
- parent::__construct();
34
-
35
- $rank_id = absint( $rank_id );
36
- if ( $rank_id === 0 ) return;
37
-
38
- if ( get_post_type( $rank_id ) != 'mycred_rank' ) return;
39
-
40
- $this->image_width = MYCRED_RANK_WIDTH;
41
- $this->image_height = MYCRED_RANK_HEIGHT;
42
-
43
- $this->populate( $rank_id );
44
-
45
- }
46
-
47
- protected function populate( $rank_id = NULL ) {
48
-
49
- $this->post_id = absint( $rank_id );
50
- $this->post = get_post( $this->post_id );
51
- $this->title = get_the_title( $this->post_id );
52
- $this->minimum = get_post_meta( $this->post_id, 'mycred_rank_min', true );
53
- $this->maximum = get_post_meta( $this->post_id, 'mycred_rank_max', true );
54
- $this->count = mycred_count_users_with_rank( $this->post_id );
55
-
56
- $this->has_logo = mycred_rank_has_logo( $this->post_id );
57
- $this->logo_id = get_post_thumbnail_id( $this->post );
58
- $this->logo_url = wp_get_attachment_url( $this->logo_id );
59
-
60
- $point_type = get_post_meta( $this->post_id, 'ctype', true );
61
- if ( ! mycred_point_type_exists( $point_type ) )
62
- $point_type = MYCRED_DEFAULT_TYPE_KEY;
63
-
64
- $this->point_type = new myCRED_Point_Type( $point_type );
65
-
66
- }
67
-
68
- public function get_image( $image = 'logo' ) {
69
-
70
- if ( $image === 'logo' )
71
- return '<img src="' . esc_url( $this->logo_url ) . '" alt="' . esc_attr( $this->title ) . '" width="' . $this->image_width . '" height="' . $this->image_height . '" />';
72
-
73
- return '';
74
-
75
- }
76
-
77
- }
78
- endif;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
addons/{notifications/assets → ranks/js}/index.php RENAMED
File without changes
addons/ranks/{assets/js → js}/management.js RENAMED
@@ -1,18 +1,17 @@
1
  /**
2
  * myCRED Management Scripts
3
  * @since 1.3
4
- * @version 1.1.1
5
  */
6
- jQuery(function($){
7
 
8
- var mycred_action_delete_ranks = function( button, pointtype ) {
9
  var label = button.val();
10
  $.ajax({
11
  type : "POST",
12
  data : {
13
  action : 'mycred-action-delete-ranks',
14
- token : myCRED_Ranks.token,
15
- ctype : pointtype
16
  },
17
  dataType : "JSON",
18
  url : myCRED_Ranks.ajaxurl,
@@ -45,18 +44,17 @@ jQuery(function($){
45
  $( 'input#mycred-manage-action-reset-ranks' ).click(function(){
46
  // Confirm action
47
  if ( confirm( myCRED_Ranks.confirm_del ) ) {
48
- mycred_action_delete_ranks( $(this), $(this).data( 'type' ) );
49
  }
50
  });
51
 
52
- var mycred_action_assign_ranks = function( button, pointtype ) {
53
  var label = button.val();
54
  $.ajax({
55
  type : "POST",
56
  data : {
57
  action : 'mycred-action-assign-ranks',
58
- token : myCRED_Ranks.token,
59
- ctype : pointtype
60
  },
61
  dataType : "JSON",
62
  url : myCRED_Ranks.ajaxurl,
@@ -87,8 +85,7 @@ jQuery(function($){
87
  $( 'input#mycred-manage-action-assign-ranks' ).click(function(){
88
  // Confirm action
89
  if ( confirm( myCRED_Ranks.confirm_assign ) ) {
90
- mycred_action_assign_ranks( $(this), $(this).data( 'type' ) );
91
  }
92
  });
93
-
94
  });
1
  /**
2
  * myCRED Management Scripts
3
  * @since 1.3
4
+ * @version 1.0
5
  */
6
+ jQuery(function($) {
7
 
8
+ var mycred_action_delete_ranks = function( button ) {
9
  var label = button.val();
10
  $.ajax({
11
  type : "POST",
12
  data : {
13
  action : 'mycred-action-delete-ranks',
14
+ token : myCRED_Ranks.token
 
15
  },
16
  dataType : "JSON",
17
  url : myCRED_Ranks.ajaxurl,
44
  $( 'input#mycred-manage-action-reset-ranks' ).click(function(){
45
  // Confirm action
46
  if ( confirm( myCRED_Ranks.confirm_del ) ) {
47
+ mycred_action_delete_ranks( $(this) );
48
  }
49
  });
50
 
51
+ var mycred_action_assign_ranks = function( button ) {
52
  var label = button.val();
53
  $.ajax({
54
  type : "POST",
55
  data : {
56
  action : 'mycred-action-assign-ranks',
57
+ token : myCRED_Ranks.token
 
58
  },
59
  dataType : "JSON",
60
  url : myCRED_Ranks.ajaxurl,
85
  $( 'input#mycred-manage-action-assign-ranks' ).click(function(){
86
  // Confirm action
87
  if ( confirm( myCRED_Ranks.confirm_assign ) ) {
88
+ mycred_action_assign_ranks( $(this) );
89
  }
90
  });
 
91
  });
addons/sell-content/assets/js/buy-content.js DELETED
@@ -1,61 +0,0 @@
1
- /**
2
- * myCRED Sell Content
3
- * @since 1.1
4
- * @version 1.1
5
- */
6
- (function($) {
7
-
8
- $( '.mycred-sell-this-wrapper' ).on( 'click', '.mycred-buy-this-content-button', function(){
9
-
10
- var button = $(this);
11
- var post_id = button.data( 'pid' );
12
- var point_type = button.data( 'type' );
13
- var buttonlabel = button.html();
14
- var content_for_sale = $( '#mycred-buy-content' + post_id );
15
-
16
- $.ajax({
17
- type : "POST",
18
- data : {
19
- action : 'mycred-buy-content',
20
- token : myCREDBuyContent.token,
21
- postid : post_id,
22
- ctype : point_type
23
- },
24
- dataType : "JSON",
25
- url : myCREDBuyContent.ajaxurl,
26
- beforeSend : function() {
27
-
28
- button.attr( 'disabled', 'disabled' ).html( myCREDBuyContent.working );
29
-
30
- },
31
- success : function( response ) {
32
-
33
- if ( response.success === undefined || ( response.success === true && myCREDBuyContent.reload === '1' ) )
34
- location.reload();
35
-
36
- else {
37
-
38
- if ( response.success ) {
39
- content_for_sale.fadeOut(function(){
40
- content_for_sale.removeClass( 'mycred-sell-this-wrapper mycred-sell-entire-content mycred-sell-partial-content' ).empty().append( response.data ).fadeIn();
41
- });
42
- }
43
-
44
- else {
45
-
46
- button.removeAttr( 'disabled' ).html( buttonlabel );
47
-
48
- alert( response.data.message );
49
-
50
- }
51
-
52
- }
53
-
54
- console.log( response );
55
-
56
- }
57
- });
58
-
59
- });
60
-
61
- })( jQuery );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
addons/sell-content/assets/js/index.php DELETED
@@ -1,3 +0,0 @@
1
- <?php
2
- // Silence is golden.
3
- ?>
 
 
 
addons/sell-content/css/edit.css ADDED
@@ -0,0 +1,12 @@
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #mycred_sell_content { }
2
+ #mycred_sell_content .inside input[type="checkbox"] { margin-right: 12px; }
3
+
4
+ #mycred_sell_content .inside ul { }
5
+ #mycred_sell_content .inside ul li label { padding-right: 12px; }
6
+ #mycred_sell_content .inside ul li>input, #mycred_sell_content .inside ul li .formated { float: right; }
7
+
8
+ #mycred_sell_content .inside ul li { float: none; clear: both; line-height: 25px; }
9
+ #mycred_sell_content .inside ul li.long input { width: 100%; float: none; clear: both; }
10
+
11
+ p#mycred-submit { text-align: right; }
12
+ #mycred_sell_content .inside ul li input.disabled { background-color: #F8F8F8; border-color: #DFDFDF; }
addons/{notifications/assets/js → sell-content/css}/index.php RENAMED
File without changes
addons/sell-content/includes/index.php DELETED
@@ -1,3 +0,0 @@
1
- <?php
2
- // Silence is golden.
3
- ?>
 
 
 
addons/sell-content/includes/mycred-sell-functions.php DELETED
@@ -1,848 +0,0 @@
1
- <?php
2
- if ( ! defined( 'myCRED_VERSION' ) ) exit;
3
-
4
- /**
5
- * Sell Content Settings
6
- * Returns the sell content add-ons settings.
7
- * @since 1.7
8
- * @version 1.0.1
9
- */
10
- if ( ! function_exists( 'mycred_sell_content_settings' ) ) :
11
- function mycred_sell_content_settings() {
12
-
13
- $mycred = mycred();
14
- if ( isset( $mycred->sell_content ) )
15
- $settings = $mycred->sell_content;
16
-
17
- else {
18
-
19
- global $mycred_modules;
20
-
21
- $settings = $mycred_modules['solo']['content']->sell_content;
22
-
23
- }
24
-
25
- return $settings;
26
-
27
- }
28
- endif;
29
-
30
- /**
31
- * Get Post Types
32
- * Returns an array of sellable post types. In order for a post type to be
33
- * considered "usable", it must be public.
34
- * @since 1.7
35
- * @version 1.0.1
36
- */
37
- if ( ! function_exists( 'mycred_sell_content_post_types' ) ) :
38
- function mycred_sell_content_post_types() {
39
-
40
- $args = array(
41
- 'public' => true,
42
- '_builtin' => false
43
- );
44
-
45
- $post_types = get_post_types( $args, 'objects', 'OR' );
46
-
47
- $eligeble_types = array();
48
- $mycred_post_types = get_mycred_post_types();
49
-
50
- if ( ! empty( $post_types ) ) {
51
- foreach ( $post_types as $post_type => $setup ) {
52
-
53
- if ( $setup->public != 1 ) continue;
54
-
55
- if ( in_array( $post_type, $mycred_post_types ) || $post_type == 'attachment' ) continue;
56
-
57
- $eligeble_types[ $post_type ] = $setup->labels->name;
58
-
59
- }
60
- }
61
-
62
- return $eligeble_types;
63
-
64
- }
65
- endif;
66
-
67
- /**
68
- * Get The Post ID
69
- * Will attempt to get the current posts ID. Also supports bbPress
70
- * where it will return either the form ID (if viewing a forum), the topic ID
71
- * (if viewing a topic) or the reply ID (if viewing a reply).
72
- * @since 1.7
73
- * @version 1.0
74
- */
75
- if ( ! function_exists( 'mycred_sell_content_post_id' ) ) :
76
- function mycred_sell_content_post_id() {
77
-
78
- $post_id = $bbp_topic_id = $bbp_reply_id = false;
79
-
80
- // Check if we are selling access to bbPress forum, topic or reply
81
- if ( function_exists( 'bbpress' ) ) {
82
-
83
- global $wp_query;
84
-
85
- $bbp = bbpress();
86
-
87
- // Currently inside a topic loop
88
- if ( ! empty( $bbp->topic_query->in_the_loop ) && isset( $bbp->topic_query->post->ID ) )
89
- $bbp_topic_id = $bbp->topic_query->post->ID;
90
-
91
- // Currently inside a search loop
92
- elseif ( ! empty( $bbp->search_query->in_the_loop ) && isset( $bbp->search_query->post->ID ) && bbp_is_topic( $bbp->search_query->post->ID ) )
93
- $bbp_topic_id = $bbp->search_query->post->ID;
94
-
95
- // Currently viewing/editing a topic, likely alone
96
- elseif ( ( bbp_is_single_topic() || bbp_is_topic_edit() ) && ! empty( $bbp->current_topic_id ) )
97
- $bbp_topic_id = $bbp->current_topic_id;
98
-
99
- // Currently viewing/editing a topic, likely in a loop
100
- elseif ( ( bbp_is_single_topic() || bbp_is_topic_edit() ) && isset( $wp_query->post->ID ) )
101
- $bbp_topic_id = $wp_query->post->ID;
102
-
103
- // So far, no topic found, check if we are in a reply
104
- if ( $bbp_topic_id === false ) {
105
-
106
- // Currently inside a replies loop
107
- if ( ! empty( $bbp->reply_query->in_the_loop ) && isset( $bbp->reply_query->post->ID ) )
108
- $bbp_reply_id = $bbp->reply_query->post->ID;
109
-
110
- // Currently inside a search loop
111
- elseif ( ! empty( $bbp->search_query->in_the_loop ) && isset( $bbp->search_query->post->ID ) && bbp_is_reply( $bbp->search_query->post->ID ) )
112
- $bbp_reply_id = $bbp->search_query->post->ID;
113
-
114
- // Currently viewing a forum
115
- elseif ( ( bbp_is_single_reply() || bbp_is_reply_edit() ) && ! empty( $bbp->current_reply_id ) )
116
- $bbp_reply_id = $bbp->current_reply_id;
117
-
118
- // Currently viewing a reply
119
- elseif ( ( bbp_is_single_reply() || bbp_is_reply_edit() ) && isset( $wp_query->post->ID ) )
120
- $bbp_reply_id = $wp_query->post->ID;
121
-
122
- if ( $bbp_reply_id !== false )
123
- $post_id = $bbp_reply_id;
124
-
125
- }
126
-
127
- // Else we are in a topic
128
- else $post_id = $bbp_topic_id;
129
-
130
- }
131
-
132
- if ( $post_id === false ) {
133
-
134
- global $post;
135
-
136
- if ( isset( $post->ID ) )
137
- $post_id = $post->ID;
138
-
139
- }
140
-
141
- return apply_filters( 'mycred_sell_this_get_post_ID', $post_id );
142
-
143
- }
144
- endif;
145
-
146
- /**
147
- * Post Type for Sale
148
- * Returns either true (post type is for sale) or false (post type not for sale).
149
- * @since 1.7
150
- * @version 1.0.1
151
- */
152
- if ( ! function_exists( 'mycred_post_type_for_sale' ) ) :
153
- function mycred_post_type_for_sale( $post_type = NULL ) {
154
-
155
- $settings = mycred_sell_content_settings();
156
- $for_sale = false;
157
-
158
- if ( array_key_exists( 'post_types', $settings ) && ! empty( $settings['post_types'] ) ) {
159
-
160
- $post_types = explode( ',', $settings['post_types'] );
161
- if ( in_array( $post_type, $post_types ) )
162
- $for_sale = true;
163
-
164
- }
165
-
166
- // BuddyPress support to prevent issues when we select to sell access to all pages.
167
- if ( function_exists( 'bp_current_component' ) && bp_current_component() !== false )
168
- $for_sale = false;
169
-
170
- return apply_filters( 'mycred_post_type_for_sale', $for_sale, $post_type );
171
-
172
- }
173
- endif;
174
-
175
- /**
176
- * Post is for Sale
177
- * Returns true (post is for sale) or false (post is not for sale).
178
- * @since 1.7
179
- * @version 1.0.1
180
- */
181
- if ( ! function_exists( 'mycred_post_is_for_sale' ) ) :
182
- function mycred_post_is_for_sale( $post = NULL ) {
183
-
184
- if ( ! is_object( $post ) )
185
- $post = get_post( $post );
186
-
187
- // Invalid post - not for sale
188
- if ( ! isset( $post->ID ) ) return false;
189
-
190
- $settings = mycred_sell_content_settings();
191
- $point_types = $settings['type'];
192
- $for_sale = false;
193
-
194
- // We start with checking the post type.
195
- if ( mycred_post_type_for_sale( $post->post_type ) && array_key_exists( $post->post_type, $settings['filters'] ) ) {
196
-
197
- $filter = $settings['filters'][ $post->post_type ]['by'];
198
- $list = explode( ',', $settings['filters'][ $post->post_type ]['list'] );
199
-
200
- // Manual filter - check saved settings
201
- if ( $filter === 'manual' ) {
202
-
203
- // Loop through each point type we allow and check the settings to see if anyone is enabled
204
- foreach ( $point_types as $type_id ) {
205
-
206
- $suffix = '_' . $type_id;
207
- if ( $type_id == MYCRED_DEFAULT_TYPE_KEY )
208
- $suffix = '';
209
-
210
- $sale_setup = (array) get_post_meta( $post->ID, 'myCRED_sell_content' . $suffix, true );
211
- if ( array_key_exists( 'status', $sale_setup ) && $sale_setup['status'] === 'enabled' )
212
- $for_sale = true;
213
-
214
- }
215
-
216
- }
217
-
218
- // All posts for sale
219
- elseif ( $filter === 'all' ) {
220
-
221
- $for_sale = true;
222
-
223
- }
224
-
225
- // Posts are set for sale but some are excluded
226
- elseif ( $filter === 'exclude' ) {
227
-
228
- // If post is not excluded, it is for sale
229
- if ( ! in_array( $post->ID, $list ) )
230
- $for_sale = true;
231
-
232
- }
233
-
234
- // Posts are not for sale but some are
235
- elseif ( $filter === 'include' ) {
236
-
237
- // If post is included, it is for sale
238
- if ( in_array( $post->ID, $list ) )
239
- $for_sale = true;
240
-
241
- }
242
-
243
- // Taxonomy check
244
- else {
245
-
246
- $check = 'include';
247
- $taxonomy = $filter;
248
-
249
- if ( substr( $taxonomy, 0, 1 ) === '-' ) {
250
- $check = 'exclude';
251
- $taxonomy = ltrim( $taxonomy );
252
- }
253
-
254
- // Get post terms
255
- $terms = wp_get_post_terms( $post->ID, $taxonomy );
256
-
257
- // Taxonomy exclude check
258
- if ( $check === 'exclude' ) {
259
-
260
- if ( ! empty( $terms ) ) {
261
- foreach ( $terms as $term ) {
262
-
263
- if ( in_array( $term->slug, $list ) ) continue;
264
- $for_sale = true;
265
-
266
- }
267
- }
268
-
269
- // No terms - not excluded
270
- else {
271
- $for_sale = true;
272
- }
273
-
274
- }
275
-
276
- // Taxonomy include check
277
- else {
278
-
279
- if ( ! empty( $terms ) ) {
280
- foreach ( $terms as $term ) {
281
-
282
- if ( ! in_array( $term->slug, $list ) ) continue;
283
- $for_sale = true;
284
-
285
- }
286
- }
287
-
288
- }
289
-
290
- }
291
-
292
- }
293
-
294
- return apply_filters( 'mycred_post_is_for_sale', $for_sale, $post, $settings );
295
-
296
- }
297
- endif;
298
-
299
- /**
300
- * User Has Paid
301
- * Checks if a user has paid for the given post. Will also take into account
302
- * if a purchase has expired (if used).
303
- * @since 1.7
304
- * @version 1.0
305
- */
306
- if ( ! function_exists( 'mycred_user_paid_for_content' ) ) :
307
- function mycred_user_paid_for_content( $user_id = NULL, $post_id = NULL ) {
308
-
309
- global $wpdb, $mycred;
310
-
311
- $has_paid = false;
312
- $last_payment = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM {$mycred->log_table} WHERE user_id = %d AND ref = 'buy_content' AND ref_id = %d ORDER BY time DESC LIMIT 1;", $user_id, $post_id ) );
313
-
314
- // Found a payment
315
- if ( $last_payment !== NULL ) {
316
-
317
- $has_paid = true;
318
-
319
- // Check for expirations
320
- if ( mycred_content_purchase_has_expired( $last_payment ) )
321
- $has_paid = false;
322
-
323
- }
324
-
325
- // All else there are no purchases
326
- return apply_filters( 'mycred_user_has_paid_for_content', $has_paid, $user_id, $post_id, $last_payment );
327
-
328
- }
329
- endif;
330
-
331
- /**
332
- * Sale Expired
333
- * Checks if a given purchase has expired. Left this in place from the old version
334
- * for backwards comp.
335
- * @since 1.7
336
- * @version 1.1
337
- */
338
- if ( ! function_exists( 'mycred_content_purchase_has_expired' ) ) :
339
- function mycred_content_purchase_has_expired( $payment = NULL ) {
340
-
341
- $has_expired = false;
342
- if ( ! is_object( $payment ) ) return $has_expired;
343
-
344
- $length = mycred_sell_content_get_expiration_length( $payment->ref_id, $payment->ctype );
345
-
346
- // If expiration is set
347
- if ( $length > 0 ) {
348
-
349
- $expiration = apply_filters( 'mycred_sell_expire_calc', absint( $length * HOUR_IN_SECONDS ), $length, $payment->user_id, $payment->ref_id );
350
- $expiration = $expiration + $payment->time;
351
-
352
- if ( $expiration <= current_time( 'timestamp' ) )
353
- $has_expired = true;
354
-
355
- }
356
-
357
- return apply_filters( 'mycred_sell_content_sale_expired', $has_expired, $payment->user_id, $payment->ref_id, $payment->time, $length );
358
-
359
- }
360
- endif;
361
-
362
- /**
363
- * Get Expiration Length
364
- * @since 1.7.9.1
365
- * @version 1.0
366
- */
367
- if ( ! function_exists( 'mycred_sell_content_get_expiration_length' ) ) :
368
- function mycred_sell_content_get_expiration_length( $post_id = NULL, $type = MYCRED_DEFAULT_TYPE_KEY ) {
369
-
370
- $length = 0;
371
- if ( $post_id === NULL ) return $length;
372
-
373
- $settings = mycred_sell_content_settings();
374
- $post = get_post( $post_id );
375
- $point_types = $settings['type'];
376
- $has_expired = false;
377
-
378
- // Invalid post
379
- if ( ! isset( $post->ID ) ) return $length;
380
-
381
- $filter = $settings['filters'][ $post->post_type ]['by'];
382
-
383
- // Manual mode - expiration settings are found in the post setting
384
- if ( $filter === 'manual' ) {
385
-
386
- $suffix = '_' . $type;
387
- if ( $type == MYCRED_DEFAULT_TYPE_KEY )
388
- $suffix = '';
389
-
390
- $sale_setup = (array) get_post_meta( $post->ID, 'myCRED_sell_content' . $suffix, true );
391
- if ( ! empty( $sale_setup ) && array_key_exists( 'expire', $sale_setup ) && $sale_setup['expire'] > 0 )
392
- $length = $sale_setup['expire'];
393
-
394
- }
395
-
396
- // Else we need to check the point type setup in our add-on settings.
397
- else {
398
-
399
- $point_type_setup = (array) mycred_get_option( 'mycred_sell_this_' . $type );
400
- if ( ! empty( $point_type_setup ) && array_key_exists( 'expire', $point_type_setup ) && $point_type_setup['expire'] > 0 )
401
- $length = $point_type_setup['expire'];
402
-
403
- }
404
-
405
- return apply_filters( 'mycred_sell_content_expiration', $length, $post );
406
-
407
- }
408
- endif;
409
-
410
- /**
411
- * Get Payment Buttons
412
- * Returns all payment buttons a user can use to pay for a given post.
413
- * @since 1.7
414
- * @version 1.1
415
- */
416
- if ( ! function_exists( 'mycred_sell_content_payment_buttons' ) ) :
417
- function mycred_sell_content_payment_buttons( $user_id = NULL, $post_id = NULL ) {
418
-
419
- if ( $user_id === NULL || $post_id === NULL ) return false;
420
-
421
- $settings = mycred_sell_content_settings();
422
- $post = get_post( $post_id );
423
- $result = false;
424
-
425
- if ( ! empty( $settings['type'] ) ) {
426
-
427
- $buttons = array();
428
-
429
- foreach ( $settings['type'] as $point_type ) {
430
-
431
- // Load point type
432
- $mycred = mycred( $point_type );
433
- $setup = mycred_get_option( 'mycred_sell_this_' . $point_type );
434
- $price = mycred_get_content_price( $post_id, $point_type, $user_id );
435
- $status = $setup['status'];
436
-
437
- // Manual mode
438
- if ( $settings['filters'][ $post->post_type ]['by'] == 'manual' ) {
439
-
440
- $suffix = ( $point_type != MYCRED_DEFAULT_TYPE_KEY ) ? '_' . $point_type : '';
441
- $manual_setup = (array) get_post_meta( $post_id, 'myCRED_sell_content' . $suffix, true );
442
- if ( ! empty( $manual_setup ) && array_key_exists( 'status', $manual_setup ) )
443
- $status = $manual_setup['status'];
444
-
445
- }
446
-
447
- // Point type not enabled
448
- if ( $status == 'disabled' ) continue;
449
-
450
- // Make sure we are not excluded from this type
451
- if ( $mycred->exclude_user( $user_id ) ) continue;
452
-
453
- // Make sure we can afford to pay
454
- if ( $mycred->get_users_balance( $user_id, $point_type ) < $price ) continue;
455
-
456
- $button_label = str_replace( '%price%', $mycred->format_creds( $price ), $setup['button_label'] );
457
-
458
- $button = '<button type="button" class="mycred-buy-this-content-button ' . $setup['button_classes'] . '" data-pid="' . $post_id . '" data-type="' . $point_type . '">' . $button_label . '</button>';
459
- $buttons[] = apply_filters( 'mycred_sell_this_button', $button, $post, $setup, $mycred );
460
-
461
- }
462
-
463
- if ( ! empty( $buttons ) )
464
- $result = implode( ' ', $buttons );
465
-
466
- }
467
-
468
- // Return a string of buttons or false if user can not afford
469
- return apply_filters( 'mycred_sellcontent_buttons', $result, $user_id, $post_id );
470
-
471
- }
472
- endif;
473
-
474
- /**
475
- * Sell Content Template
476
- * Parses a particular template.
477
- * @since 1.7
478
- * @version 1.0.1
479
- */
480
- if ( ! function_exists( 'mycred_sell_content_template' ) ) :
481
- function mycred_sell_content_template( $template = '', $post = NULL, $type = 'mycred-sell-partial-content', $status = 'visitor' ) {
482
-
483
- if ( ! is_object( $post ) || strlen( $template ) === 0 ) return $template;
484
-
485
- $post_type = get_post_type_object( $post->post_type );
486
- $url = get_permalink( $post->ID );
487
-
488
- // Remove old tags that are no longer supported
489
- $template = str_replace( array( '%price%', '%expires%', ), '', $template );
490
-
491
- $template = str_replace( '%post_title%', get_the_title( $post->ID ), $template );
492
- $template = str_replace( '%post_type%', $post_type->labels->singular_name, $template );
493
- $template = str_replace( '%post_url%', $url, $template );
494
- $template = str_replace( '%link_with_title%', '<a href="' . $url . '">' . $post->post_title . '</a>', $template );
495
-
496
- $template = apply_filters( 'mycred_sell_content_template', $template, $post, $type );
497
- $template = do_shortcode( $template );
498
-
499
- $wrapper_classes = array();
500
- $wrapper_classes[] = 'mycred-sell-this-wrapper';
501
- $wrapper_classes[] = esc_attr( $type );
502
- $wrapper_classes[] = esc_attr( $status );
503
-
504
- $wrapper_classes = apply_filters( 'mycred_sell_template_class', $wrapper_classes, $post );
505
-
506
- return '<div id="mycred-buy-content' . $post->ID . '" class="' . implode( ' ', $wrapper_classes ) . '" data-pid="' . $post->ID . '">' . $template . '</div>';
507
-
508
- }
509
- endif;
510
-
511
- /**
512
- * New Purchase
513
- * Handles the purchase of a particular post by a given user.
514
- * @returns true (bool) on success or an error message (string)
515
- * @since 1.7
516
- * @version 1.0
517
- */
518
- if ( ! function_exists( 'mycred_sell_content_new_purchase' ) ) :
519
- function mycred_sell_content_new_purchase( $post = NULL, $user_id = NULL, $point_type = NULL ) {
520
-
521
- if ( ! is_object( $post ) )
522
- $post = get_post( $post );
523
-
524
- if ( ! isset( $post->ID ) ) return false;
525
-
526
- $mycred = mycred( $point_type );
527
- $settings = mycred_sell_content_settings();
528
- $setup = mycred_get_option( 'mycred_sell_this_' . $point_type );
529
- $result = apply_filters( 'mycred_before_content_purchase', false, $post->ID, $user_id, $point_type );
530
-
531
- // We handle payment
532
- if ( $result === false ) {
533
-
534
- // Disabled point type or user is excluded.
535
- if ( $setup['status'] === 'disabled' || $mycred->exclude_user( $user_id ) )
536
- $result = sprintf( _x( 'You can not pay using %s', 'Point type name', 'mycred' ), $mycred->plural() );
537
-
538
- else {
539
-
540
- $balance = $mycred->get_users_balance( $user_id, $point_type );
541
- $price = mycred_get_content_price( $post->ID, $point_type, $user_id );
542
-
543
- // Insufficient funds (not free)
544
- if ( $price > 0 && $balance < $price )
545
- $result = __( 'Insufficient funds.', 'mycred' );
546
-
547
- // Content is not free
548
- elseif ( $price > 0 ) {
549
-
550
- // Need a unqiue transaction id
551
- $transaction_id = 'TXID' . $user_id . current_time( 'timestamp' ) . $post->ID;
552
-
553
- // Charge buyer
554
- $mycred->add_creds(
555
- 'buy_content',
556
- $user_id,
557
- 0 - $price,
558
- $setup['log_payment'],
559
- $post->ID,
560
- array(
561
- 'ref_type' => 'post',
562
- 'purchase_id' => $transaction_id,
563
- 'seller' => $post->post_author
564
- ),
565
- $point_type
566
- );
567
-
568
- // Profit Sharing
569
- if ( $setup['profit_share'] > 0 ) {
570
-
571
- // Let others play with the users profit share
572
- $percentage = mycred_get_authors_profit_share( $post->post_author, $point_type, $setup['profit_share'] );
573
- if ( $percentage !== false ) {
574
-
575
- // Convert percentage to a share amount
576
- $share = ( $percentage / 100 ) * $price;
577
-
578
- // Pay the author
579
- $mycred->add_creds(
580
- 'sell_content',
581
- $post->post_author,
582
- $share,
583
- $setup['log_sale'],
584
- $post->ID,
585
- array(
586
- 'ref_type' => 'post',
587
- 'purchase_id' => $transaction_id,
588
- 'buyer' => $user_id
589
- ),
590
- $point_type
591
- );
592
-
593
- }
594
-
595
- }
596
-
597
- $result = true;
598
-
599
- // Delete counters to trigger new db query
600
- delete_post_meta( $post->ID, '_mycred_content_sales' );
601
- delete_post_meta( $post->ID, '_mycred_content_buyers' );
602
-
603
- }
604
-
605
- // Free
606
- else {
607
- $result = true;
608
- }
609
-
610
- }
611
-
612
- }
613
-
614
- return apply_filters( 'mycred_after_content_purchase', $result, $post, $user_id, $point_type );
615
-
616
- }
617
- endif;
618
-
619
- /**
620
- * Get Content Price
621
- * Returns the contents price.
622
- * @since 1.7
623
- * @version 1.0.1
624
- */
625
- if ( ! function_exists( 'mycred_get_content_price' ) ) :
626
- function mycred_get_content_price( $post_id = NULL, $point_type = NULL, $user_id = NULL ) {
627
-
628
- $mycred = mycred( $point_type );
629
- $settings = mycred_sell_content_settings();
630
-
631
- $setup = mycred_get_option( 'mycred_sell_this_' . $point_type );
632
- $price = $mycred->number( $setup['price'] );
633
- $post_type = get_post_type( $post_id );
634
-
635
- if ( array_key_exists( $post_type, $settings['filters'] ) && $settings['filters'][ $post_type ]['by'] === 'manual' ) {
636
-
637
- $suffix = '_' . $point_type;
638
- if ( $point_type == MYCRED_DEFAULT_TYPE_KEY )
639
- $suffix = '';
640
-
641
- $sale_setup = (array) get_post_meta( $post_id, 'myCRED_sell_content' . $suffix, true );
642
- if ( array_key_exists( 'price', $sale_setup ) )
643
- $price = $mycred->number( $sale_setup['price'] );
644
-
645
- }
646
-
647
- return apply_filters( 'mycred_get_content_price', $price, $post_id, $point_type, $user_id );
648
-
649
- }
650
- endif;
651
-
652
- /**
653
- * Get Users Purchased Content
654
- * Returns an array of log entries for content purchases.
655
- * @since 1.7
656
- * @version 1.0.1
657
- */
658
- if ( ! function_exists( 'mycred_get_users_purchased_content' ) ) :
659
- function mycred_get_users_purchased_content( $user_id = NULL, $number = 25, $order = 'DESC', $point_type = NULL ) {
660
-
661
- global $wpdb, $mycred;
662
-
663
- $limit = '';
664
- if ( absint( $number ) > 0 )
665
- $limit = $wpdb->prepare( "LIMIT 0,%d", $number );
666
-
667
- $wheres = array();
668
- $wheres[] = "ref = 'buy_content'";
669
- $wheres[] = $wpdb->prepare( "user_id = %d", $user_id );
670
-
671
- if ( $point_type !== NULL && mycred_point_type_exists( $point_type ) )
672
- $wheres[] = $wpdb->prepare( "ctype = %s", $point_type );
673
-
674
- $wheres = 'WHERE ' . implode( ' AND ', $wheres );
675
-
676
- if ( ! in_array( $order, array( 'ASC', 'DESC' ) ) )
677
- $order = 'DESC';
678
-
679
- $sql = apply_filters( 'mycred_get_users_purchased_content', "SELECT * FROM {$mycred->log_table} log INNER JOIN {$wpdb->posts} posts ON ( log.ref_id = posts.ID ) {$wheres} ORDER BY time {$order} {$limit};", $user_id, $number, $order, $point_type );
680
-
681
- return $wpdb->get_results( $sql );
682
-
683
- }
684
- endif;
685
-
686
- /**
687
- * Get Posts Buyers
688
- * Returns an array of User IDs of the user that has purchased
689
- * a given post.
690
- * @since 1.7
691
- * @version 1.0
692
- */
693
- if ( ! function_exists( 'mycred_get_posts_buyers' ) ) :
694
- function mycred_get_posts_buyers( $post_id = NULL, $number = 25, $point_type = NULL ) {
695
-
696
- global $wpdb, $mycred;
697
-
698
- $limit = '';
699
- if ( absint( $number ) > 0 )
700
- $limit = $wpdb->prepare( "LIMIT 0,%d", $number );
701
-
702
- $wheres = array();
703
- $wheres[] = "ref = 'buy_content'";
704
- $wheres[] = $wpdb->prepare( "ref_id = %d", $post_id );
705
-
706
- if ( $point_type !== NULL && mycred_point_type_exists( $point_type ) )
707
- $wheres[] = $wpdb->prepare( "ctype = %s", $point_type );
708
-
709
- $wheres = 'WHERE ' . implode( ' AND ', $wheres );
710
-
711
- return $wpdb->get_col( "SELECT user_id FROM {$mycred->log_table} {$wheres} ORDER BY time DESC {$limit};" );
712
-
713
- }
714
- endif;
715
-
716
- /**
717
- * Get Content Sales Count
718
- * Returns the number of times a content has been purchased.
719
- * @since 1.7
720
- * @version 1.0
721
- */
722
- if ( ! function_exists( 'mycred_get_content_sales_count' ) ) :
723
- function mycred_get_content_sales_count( $post_id = NULL ) {
724
-
725
- $count = get_post_meta( $post_id, '_mycred_content_sales', true );
726
- if ( strlen( $count ) == 0 ) {
727
-
728
- $count = mycred_count_ref_id_instances( 'buy_content', $post_id );
729
- add_post_meta( $post_id, '_mycred_content_sales', $count, true );
730
-
731
- }
732
-
733
- return apply_filters( 'mycred_content_sales_count', $count, $post_id );
734
-
735
- }
736
- endif;
737
-
738
- /**
739
- * Get Content Buyer Count
740
- * Returns the number of buyers a particular content has.
741
- * @since 1.7
742
- * @version 1.0
743
- */
744
- if ( ! function_exists( 'mycred_get_content_buyers_count' ) ) :
745
- function mycred_get_content_buyers_count( $post_id = NULL ) {
746
-
747
- $count = get_post_meta( $post_id, '_mycred_content_buyers', true );
748
- if ( strlen( $count ) == 0 ) {
749
-
750
- global $wpdb, $mycred;
751
-
752
- $count = $wpdb->get_var( $wpdb->prepare( "SELECT COUNT( DISTINCT user_id ) FROM {$mycred->log_table} WHERE ref = 'buy_content' AND ref_id = %d;", $post_id ) );
753
- if ( $count === NULL ) $count = 0;
754
-
755
- add_post_meta( $post_id, '_mycred_content_buyers', $count, true );
756
-
757
- }
758
-
759
- return apply_filters( '_mycred_content_buyers', $count, $post_id );
760
-
761
- }
762
- endif;
763
-
764
- /**
765
- * Get Authors Profit Share
766
- * Get a particular users profit share percentage. If not set, the general setup for the given
767
- * point type is returned instead.
768
- * @since 1.7
769
- * @version 1.0
770
- */
771
- if ( ! function_exists( 'mycred_get_authors_profit_share' ) ) :
772
- function mycred_get_authors_profit_share( $user_id = NULL, $point_type = NULL, $default = false ) {
773
-
774
- $users_share = mycred_get_user_meta( $user_id, 'mycred_sell_content_share_' . $point_type, '', true );
775
- if ( strlen( $users_share ) == 0 )
776
- $users_share = $default;
777
-
778
- return apply_filters( 'mycred_sell_content_profit_share', $users_share, $user_id, $point_type, $default );
779
-
780
- }
781
- endif;
782
-
783
- /**
784
- * Get Post Type Options
785
- * Returns an array of filter options for post types.
786
- * @since 1.7
787
- * @version 1.0
788
- */
789
- if ( ! function_exists( 'mycred_get_post_type_options' ) ) :
790
- function mycred_get_post_type_options( $post_type ) {
791
-
792
- $type = get_post_type_object( $post_type );
793
- if ( ! is_object( $type ) ) return;
794
-
795
- $options = array();
796
- $options['all'] = array(
797
- 'label' => sprintf( _x( 'All %s', 'all post type name', 'mycred' ), $type->labels->name ),
798
- 'data' => ''
799
- );
800
- $options['manual'] = array(
801
- 'label' => sprintf( _x( '%s I manually select', 'all post type name', 'mycred' ), $type->labels->name ),
802
- 'data' => ''
803
- );
804
- $options['exclude'] = array(
805
- 'label' => sprintf( _x( 'All %s except', '%s = post type name', 'mycred' ), $type->labels->name ),
806
- 'data' => sprintf( _x( 'Comma separated list of %s IDs to exclude', '%s = post type name', 'mycred' ), $type->labels->singular_name )
807
- );
808
- $options['include'] = array(
809
- 'label' => sprintf( _x( 'Only %s', '%s = post type name', 'mycred' ), $type->labels->name ),
810
- 'data' => sprintf( _x( 'Comma separated list of %s IDs', '%s = post type name', 'mycred' ), $type->labels->singular_name )
811
- );
812
-
813
- $taxonomies = get_object_taxonomies( $post_type, 'objects' );
814
- if ( ! empty( $taxonomies ) ) {
815
-
816
- foreach ( $taxonomies as $taxonomy_id => $term ) {
817
-
818
- if ( ! $term->public ) continue;
819
-
820
- if ( $term->hierarchical ) {
821
- $options[ $taxonomy_id ] = array(
822
- 'label' => sprintf( _x( 'Only %s in %s', 'e.g. Only "Posts" in "Categories"', 'mycred' ), $type->labels->name, $term->labels->name ),
823
- 'data' => sprintf( _x( 'Comma separated list of %s slugs', '%s = taxonomy name', 'mycred' ), $term->labels->singular_name )
824
- );
825
- $options[ '_' . $taxonomy_id ] = array(
826
- 'label' => sprintf( _x( 'Only %s not in %s', 'e.g. Only "Posts" not in "Categories"', 'mycred' ), $type->labels->name, $term->labels->name ),
827
- 'data' => sprintf( _x( 'Comma separated list of %s slugs', '%s = taxonomy name', 'mycred' ), $term->labels->singular_name )
828
- );
829
- }
830
- else {
831
- $options[ $taxonomy_id ] = array(
832
- 'label' => sprintf( _x( 'Only %s with %s', 'e.g. Only "Posts" with "Tags"', 'mycred' ), $type->labels->name, $term->labels->name ),
833
- 'data' => sprintf( _x( 'Comma separated list of %s slugs', '%s = taxonomy name', 'mycred' ), $term->labels->singular_name )
834
- );
835
- $options[ '_' . $taxonomy_id ] = array(
836
- 'label' => sprintf( _x( 'Only %s without %s', 'e.g. Only "Posts" without "Tags"', 'mycred' ), $type->labels->name, $term->labels->name ),
837
- 'data' => sprintf( _x( 'Comma separated list of %s slugs', '%s = taxonomy name', 'mycred' ), $term->labels->singular_name )
838
- );
839
- }
840
-
841
- }
842
-
843
- }
844
-
845
- return apply_filters( 'mycred_sell_post_type_options', $options, $post_type );
846
-
847
- }
848
- endif;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
addons/sell-content/includes/mycred-sell-shortcodes.php DELETED
@@ -1,334 +0,0 @@
1
- <?php
2
- if ( ! defined( 'myCRED_VERSION' ) ) exit;
3
-
4
- /**
5
- * Shortcode: Sell This
6
- * This shortcode is intended to be used when selling parts of a content.
7
- * Can only be used once per content.
8
- * @since 1.7
9
- * @version 1.0.3
10
- */
11
- if ( ! function_exists( 'mycred_render_sell_this' ) ) :
12
- function mycred_render_sell_this( $atts, $content = '' ) {
13
-
14
- global $mycred_partial_content_sale, $mycred_modules;
15
-
16
- $post_id = mycred_sell_content_post_id();
17
- $post = get_post( $post_id );
18
- $user_id = get_current_user_id();
19
- $is_admin = mycred_is_admin( $user_id );
20
- $is_owner = ( (int) $post->post_author === $user_id ) ? true : false;
21
-
22
- $mycred_partial_content_sale = true;
23
-
24
- // Logged in users
25
- if ( is_user_logged_in() ) {
26
-
27
- // Authors and admins do not pay
28
- if ( ! $is_admin && ! $is_owner ) {
29
-
30
- // In case we have not paid
31
- if ( ! mycred_user_paid_for_content( $user_id, $post_id ) ) {
32
-
33
- // Get Payment Options
34
- $payment_options = mycred_sell_content_payment_buttons( $user_id, $post_id );
35
-
36
- // User can buy
37
- if ( $payment_options !== false ) {
38
-
39
- $content = $mycred_modules['solo']['content']->sell_content['templates']['members'];
40
- $content = str_replace( '%buy_button%', $payment_options, $content );
41
- $content = mycred_sell_content_template( $content, $post, 'mycred-sell-partial-content', 'mycred-sell-unpaid' );
42
-
43
- }
44
-
45
- // Can not afford to buy
46
- else {
47
-
48
- $content = $mycred_modules['solo']['content']->sell_content['templates']['cantafford'];
49
- $content = mycred_sell_content_template( $content, $post, 'mycred-sell-partial-content', 'mycred-sell-insufficient' );
50
-
51
- }
52
-
53
- }
54
-
55
- }
56
-
57
- /**
58
- * Incase the shortcode is used incorrectly
59
- * Since the shortcode is only used to indicate which part of the content that is for sale, we need to make sure it can only be used
60
- * on content that has been set to be purchasable. In manual mode, this means we must have clicked to enable sale in the metabox.
61
- * In auto modes, the particular post types setup must be enabled and the post must fit any filter criteria we might have set.
62
- * Since the content might have monetary value, we do not want to just show it, but to warn admin/post author and appologize to the user.
63
- * @since 1.7.8
64
- */
65
- elseif ( ! mycred_post_is_for_sale( $post ) ) {
66
-
67
- if ( $is_admin || $is_owner )
68
- return '<p>' . sprintf( '%s %s', __( 'This shortcode can not be used in content that has not been set for sale!', 'mycred' ), '<a href="' . get_edit_post_link( $post_id ) ) . '">' . __( 'Edit', 'mycred' ) . '</a></p>';
69
-
70
- return '<p>' . __( 'This content is currently unattainable. Apologies for the inconvenience.', 'mycred' ) . '</p>';
71
-
72
- }
73
-
74
- }
75
-
76
- // Visitors
77
- else {
78
-
79
- $content = $mycred_modules['solo']['content']->sell_content['templates']['visitors'];
80
- $content = mycred_sell_content_template( $content, $post, 'mycred-sell-partial-content', 'mycred-sell-visitor' );
81
-
82
- }
83
-
84
- return do_shortcode( $content );
85
-
86
- }
87
- endif;
88
-
89
- /**
90
- * Shortcode: Sell This AJAX
91
- * Depreciated as of version 1.7 and will be removed in version 1.8
92
- * @since 1.3
93
- * @version 1.0
94
- */
95
- if ( ! function_exists( 'mycred_render_sell_this_ajax' ) ) :
96
- function mycred_render_sell_this_ajax( $atts, $content = '' ) {
97
-
98
- _doing_it_wrong( 'mycred_render_sell_this_ajax', 'The mycred_sell_this_ajax shortcode has been depreciated and will be removed in version 1.8.', '1.7' );
99
-
100
- return mycred_render_sell_this( $atts, $content );
101
-
102
- }
103
- endif;
104
-
105
- /**
106
- * Shortcode: Sales Counter
107
- * Renders the total number of times this post has been purchased or the total number of
108
- * active sales right now, if sales expire.
109
- * @attribute wrapper (string) - optional html element to wrap around the value.
110
- * @attribute post_id (int) - option to get the count for the provided post ID.
111
- * @since 1.7
112
- * @version 1.0
113
- */
114
- if ( ! function_exists( 'mycred_render_sell_count' ) ) :
115
- function mycred_render_sell_count( $atts, $content = '' ) {
116
-
117
- extract( shortcode_atts( array(
118
- 'wrapper' => '',
119
- 'post_id' => NULL
120
- ), $atts ) );
121
-
122
- if ( $post_id === NULL )
123
- $post_id = mycred_sell_content_post_id();
124
-
125
- $content = '';
126
-
127
- if ( $wrapper != '' )
128
- $content .= '<' . $wrapper . ' class="mycred-sell-this-sales-count">';
129
-
130
- $content .= mycred_get_content_sales_count( $post_id );
131
-
132
- if ( $wrapper != '' )
133
- $content .= '</' . $wrapper . '>';
134
-
135
- return $content;
136
-
137
- }
138
- endif;
139
-
140
- /**
141
- * Shortcode: Sales Buyer Counter
142
- * Renders the total number of unique users that has purchased this content.
143
- * @attribute wrapper (string) - optional html element to wrap around the value.
144
- * @attribute post_id (int) - option to get the count for the provided post ID.
145
- * @since 1.7
146
- * @version 1.0
147
- */
148
- if ( ! function_exists( 'mycred_render_sell_buyer_count' ) ) :
149
- function mycred_render_sell_buyer_count( $atts, $content = '' ) {
150
-
151
- extract( shortcode_atts( array(
152
- 'wrapper' => '',
153
- 'post_id' => NULL
154
- ), $atts ) );
155
-
156
- if ( $post_id === NULL )
157
- $post_id = mycred_sell_content_post_id();
158
-
159
- $content = '';
160
-
161
- if ( $wrapper != '' )
162
- $content .= '<' . $wrapper . ' class="mycred-sell-this-author-count">';
163
-
164
- $content .= mycred_get_content_buyers_count( $post_id );
165
-
166
- if ( $wrapper != '' )
167
- $content .= '</' . $wrapper . '>';
168
-
169
- return $content;
170
-
171
- }
172
- endif;
173
-
174
- /**
175
- * Shortcode: Sales History
176
- * Will show a given users payment history with links to the posts
177
- * they have purchased.
178
- * @since 1.7
179
- * @version 1.1
180
- */
181
- if ( ! function_exists( 'mycred_render_sell_history' ) ) :
182
- function mycred_render_sell_history( $atts, $content = '' ) {
183
-
184
- extract( shortcode_atts( array(
185
- 'user_id' => 'current',
186
- 'number' => 25,
187
- 'nothing' => 'No purchases found',
188
- 'ctype' => NULL,
189
- 'order' => 'DESC'
190
- ), $atts ) );
191
-
192
- // Not logged in
193
- if ( ! is_user_logged_in() && $user_id == 'current' )
194
- return $content;
195
-
196
- $user_id = mycred_get_user_id( $user_id );
197
- $date_format = get_option( 'date_format' );
198
- $expiration = apply_filters( 'mycred_sell_exp_title', __( 'Hour(s)', 'mycred' ) );
199
- $purchases = mycred_get_users_purchased_content( $user_id, $number, $order, $ctype );
200
-
201
- $columns = apply_filters( 'mycred_sales_history_columns', array(
202
- 'col-date' => __( 'Date', 'mycred' ),
203
- 'col-title' => __( 'Title', 'mycred' ),
204
- 'col-amount' => __( 'Cost', 'mycred' ),
205
- 'col-expires' => __( 'Expires', 'mycred' )
206
- ), $atts );
207
-
208
- if ( empty( $purchases ) && $nothing == '' ) return;
209
-
210
- ob_start();
211
-
212
- ?>
213
- <div class="table-responsive mycred-sell-this-history">
214
- <table class="table">
215
- <thead>
216
- <tr>
217
- <?php
218
-
219
- foreach ( $columns as $column_id => $column_label )
220
- echo '<th class="mycred-sell-' . $column_id . ' ' . $column_id . '">' . $column_label . '</th>';
221
-
222
- ?>
223
- </thead>
224
- <tbody>
225
- <?php
226
-
227
- if ( ! empty( $purchases ) ) {
228
- foreach ( $purchases as $entry ) {
229
-
230
- $mycred = mycred( $entry->ctype );
231
- $expirares_in = mycred_sell_content_get_expiration_length( $entry->ref_id, $entry->ctype );
232
-
233
- echo '<td class="mycred-sell-' . $column_id . ' ' . $column_id . '">';
234
-
235
- foreach ( $columns as $column_id => $column_label ) {
236
-
237
- if ( $column_id == 'col-date' )
238
- echo date( $date_format, $entry->time );
239
-
240
- elseif ( $column_id == 'col-title' )
241
- echo '<a href="' . get_permalink( $entry->ref_id ) . '">' . get_the_title( $entry->ref_id ) . '</a>';
242
-
243
- elseif ( $column_id == 'col-amount' )
244
- echo '<td class="">' . $mycred->format_creds( abs( $entry->creds ) ) . '</td>';
245
-
246
- elseif ( $column_id == 'col-expires' ) {
247
-
248
- $expires = __( 'Never', 'mycred' );
249
- if ( $prefs['expire'] > 0 )
250
- $expires = sprintf( _x( 'Purchase expires in %s', 'e.g. 10 hours', 'mycred' ), $expirares_in . ' ' . $expiration );
251
-
252
- echo '<td class="">' . $expires . '</td>';
253
-
254
- }
255
- else {
256
-
257
- do_action( 'mycred_sales_history_column', $column_id, $entry );
258
- do_action( 'mycred_sales_history_column_' . $column_id, $entry );
259
-
260
- }
261
-
262
- }
263
-
264
- echo '</td>';
265
-
266
- }
267
- }
268
- else {
269
-
270
- echo '<tr><td class="no-results" colspan="' . count( $columns ) . '">' . $nothing . '</td></tr>';
271
-
272
- }
273
-
274
- ?>
275
- </tbody>
276
- </table>
277
- </div>
278
- <?php
279
-
280
- $content = ob_get_contents();
281
- ob_end_clean();
282
-
283
- return $content;
284
-
285
- }
286
- endif;
287
-
288
- /**
289
- * Shortcode: Buyer Avatars
290
- * Renders a given number of avatars of past buyers for this post.
291
- * @since 1.7
292
- * @version 1.0
293
- */
294
- if ( ! function_exists( 'mycred_render_sell_buyer_avatars' ) ) :
295
- function mycred_render_sell_buyer_avatars( $atts, $content = '' ) {
296
-
297
- extract( shortcode_atts( array(
298
- 'post_id' => NULL,
299
- 'number' => 10,
300
- 'size' => 42,
301
- 'ctype' => NULL,
302
- 'use_email' => 0,
303
- 'default' => '',
304
- 'alt' => ''
305
- ), $atts ) );
306
-
307
- if ( $post_id === NULL )
308
- $post_id = mycred_sell_content_post_id();
309
-
310
- $buyers = mycred_get_posts_buyers( $post_id, $number, $ctype );
311
-
312
- $content = '';
313
- if ( ! empty( $buyers ) ) {
314
- foreach ( $buyers as $buyer_id ) {
315
-
316
- $identification = $buyer_id;
317
- if ( absint( $use_email ) === 1 ) {
318
- $buyer_object = get_userdata( $buyer_id );
319
- if ( ! isset( $buyer_object->ID ) ) continue;
320
- $identification = $buyer_object->user_email;
321
- }
322
-
323
- $avatar = get_avatar( $identification, $size, $default, $alt );
324
- $avatar = apply_filters( 'mycred_sell_content_buyer_avatar', $avatar, $buyer_id, $post_id );
325
- if ( $avatar !== false )
326
- $content .= $avatar;
327
-
328
- }
329
- }
330
-
331
- return '<div class="mycred-sell-this-buyers">' . $content . '</div>';
332
-
333
- }
334
- endif;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
addons/sell-content/js/buy-content.js ADDED
@@ -0,0 +1,46 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /**
2
+ * myCRED Sell Content
3
+ * @since 1.1
4
+ * @version 1.0
5
+ */
6
+ jQuery(function($) {
7
+ var mycred_buy_content = function( button, label ) {
8
+ wrapper = button.parents( 'div.mycred-content-forsale' );
9
+ $.ajax({
10
+ type : "POST",
11
+ data : {
12
+ action : 'mycred-buy-content',
13
+ postid : button.attr( 'data-id' ),
14
+ token : myCREDsell.token
15
+ },
16
+ dataType : "HTML",
17
+ url : myCREDsell.ajaxurl,
18
+ // Before we start
19
+ beforeSend : function() {
20
+ button.attr( 'value', myCREDsell.working );
21
+ button.attr( 'disabled', 'disabled' );
22
+ wrapper.slideUp();
23
+ },
24
+ // On Successful Communication
25
+ success : function( data ) {
26
+ wrapper.empty();
27
+ wrapper.append( data );
28
+ wrapper.slideDown();
29
+ },
30
+ // Error (sent to console)
31
+ error : function( jqXHR, textStatus, errorThrown ) {
32
+ button.attr( 'value', 'Upps!' );
33
+ button.removeAttr( 'disabled' );
34
+ wrapper.slideDown();
35
+ // Debug - uncomment to use
36
+ console.log( jqXHR );
37
+ console.log( textStatus );
38
+ console.log( errorThrown );
39
+ }
40
+ });
41
+ };
42
+
43
+ $('.mycred-sell-this-button').click(function(){
44
+ mycred_buy_content( $(this), $(this).attr( 'value' ) );
45
+ });
46
+ });
addons/{ranks/assets → sell-content/js}/index.php RENAMED
File without changes
addons/stats/abstracts/index.php DELETED
@@ -1,3 +0,0 @@
1
- <?php
2
- // Silence is golden.
3
- ?>
 
 
 
addons/stats/abstracts/mycred-abstract-stat-widget.php DELETED
@@ -1,183 +0,0 @@
1
- <?php
2
- if ( ! defined( 'myCRED_VERSION' ) ) exit;
3
-
4
- /**
5
- * myCRED_Statistics_Widget class
6
- * @see http://codex.mycred.me/
7
- * @since 1.6
8
- * @version 1.0
9
- */
10
- if ( ! class_exists( 'myCRED_Statistics_Widget' ) ) :
11
- abstract class myCRED_Statistics_Widget {
12
-
13
- public $id;
14
- public $ctypes;
15
- public $dates;
16
-
17
- public $args;
18
- public $core;
19
- public $colors;
20
-
21
- /**
22
- * Construct
23
- */
24
- function __construct( $widget_id = NULL, $args = array(), $default = NULL ) {
25
-
26
- if ( $widget_id === NULL ) return false;
27
-
28
- $this->id = str_replace( array( '_', '-', ' ' ), '', $widget_id );
29
- $this->ctypes = mycred_get_types();
30
-
31
- if ( ! is_array( $default ) )
32
- $default = array(
33
- 'ctypes' => 'all',
34
- 'span' => 0,
35
- 'number' => 5
36
- );
37
-
38
- $this->args = wp_parse_args( $args, $default );
39
-
40
- if ( $this->args['ctypes'] == 'all' )
41
- $this->core = mycred();
42
- else
43
- $this->core = mycred( $this->args['ctypes'] );
44
-
45
- $this->colors = mycred_get_type_color();
46
- $this->now = current_time( 'timestamp' );
47
-
48
- }
49
-
50
- /**
51
- * Get Data
52
- * @version 1.0
53
- */
54
- function get_data() {
55
- return array();
56
- }
57
-
58
- /**
59
- * Widget
60
- * @version 1.0
61
- */
62
- function widget() {
63
- wp_die( 'function myCRED_Statistics_Widget::widget() must be over-ridden in a sub-class.' );
64
- }
65
-
66
- /**
67
- * Preferences
68
- * @version 1.0
69
- */
70
- function preferences() {
71
-
72
- }
73
-
74
- /**
75
- * Sanitize Preferences
76
- * @version 1.0
77
- */
78
- function sanitise_preferences( $data ) {
79
- return $data;
80
- }
81
-
82
-
83
-
84
- /**
85
- * Action Buttons
86
- * @version 1.0.1
87
- */
88
- function action_buttons() {
89
-
90
- $screen_id = MYCRED_SLUG;
91
- $buttons = array();
92
-
93
- if ( $this->args['ctypes'] != 'all' ) {
94
-
95
- $this->args['ctypes'] = str_replace( 'view_', '', $this->args['ctypes'] );
96
- if ( $this->args['ctypes'] != MYCRED_DEFAULT_TYPE_KEY )
97
- $screen_id .= '_' . $this->args['ctypes'];
98
-
99
- $url = add_query_arg( array( 'page' => $screen_id ), admin_url( 'admin.php' ) );
100
- $buttons[] = '<a href="' . esc_url( $url ) . '" class="button button-secondary button-large">' . __( 'View Log', 'mycred' ) . '</a>';
101
-
102
- $url = add_query_arg( array( 'page' => $screen_id . '-hooks' ), admin_url( 'admin.php' ) );
103
- $buttons[] = '<a href="' . esc_url( $url ) . '" class="button button-secondary button-large">' . __( 'Hooks', 'mycred' ) . '</a>';
104
-
105
- $url = add_query_arg( array( 'page' => $screen_id . '-settings' ), admin_url( 'admin.php' ) );
106
- $buttons[] = '<a href="' . esc_url( $url ) . '" class="button button-secondary button-large">' . __( 'Settings', 'mycred' ) . '</a>';
107
-
108
- }
109
-
110
- $output = '';
111
- if ( ! empty( $buttons ) ) {
112
- $output = '<p class="circulation-buttons mycred-action-buttons">' . implode( ' ', $buttons ) . '</p>';
113
- }
114
-
115
- return apply_filters( 'mycred_stats_action_buttons', $output, $this );
116
-
117
- }
118
-
119
- /**
120
- * Format Number
121
- * Attempts to combine all decimal type setups when displaying
122
- * an overall value. Otherwise the give value will be formatted
123
- * according to the selected point type.
124
- * @version 1.0
125
- */
126
- function format_number( $value = 0 ) {
127
-
128
- $result = $value;
129
- if ( isset( $this->args['ctypes'] ) ) {
130
-
131
- // All point types
132
- $selected_type = sanitize_text_field( $this->args['ctypes'] );
133
- if ( $selected_type == 'all' ) {
134
-
135
- // Find the highest decimal value
136
- $decimal_values = array();
137
- foreach ( $this->ctypes as $type_id => $label ) {
138
-
139
- $mycred = mycred( $type_id );
140
-
141
- if ( ! isset( $mycred->format['decimals'] ) )
142
- $decimals = $mycred->core['format']['decimals'];
143
- else
144
- $decimals = $mycred->format['decimals'];
145
-
146
- $decimal_values[ $decimals ] = $type_id;
147
-
148
- }
149
-
150
- // Sort to get the highest value
151
- krsort( $decimal_values, SORT_NUMERIC );
152
- reset( $decimal_values );
153
- $highest = key( $decimal_values );
154
-
155
- // Format the value using the highest decimal value
156
- $mycred = mycred( $decimal_values[ $highest ] );
157
- $result = $mycred->format_number( $value );
158
-
159
- }
160
-
161
- // Specific point type
162
- else {
163
-
164
- // Default type - always available under $this->core
165
- if ( $selected_type == MYCRED_DEFAULT_TYPE_KEY )
166
- $result = $this->core->format_number( $value );
167
-
168
- // Custom type
169
- elseif ( array_key_exists( $selected_type, $this->ctypes ) ) {
170
- $mycred = mycred( $selected_type );
171
- $result = $mycred->format_number( $value );
172
- }
173
-
174
- }
175
-
176
- }
177
-
178
- return $result;
179
-
180
- }
181
-
182
- }
183
- endif;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
addons/stats/assets/css/index.php DELETED
@@ -1,3 +0,0 @@
1
- <?php
2
- // Silence is golden.
3
- ?>
 
 
 
addons/stats/assets/css/mycred-statistics-admin.css DELETED
@@ -1,56 +0,0 @@
1
- ul#section-nav { border-bottom:solid 1px #ccc; width:100%; margin-top:1em; margin-bottom: 24px; padding:1em 0; padding-bottom: 0; height: 35px; }
2
- ul#section-nav li { margin-left:0.4em; float:left;font-weight: bold;font-size: 15px;line-height: 24px;}
3
- ul#section-nav li a {text-decoration: none;color:#888;}
4
- ul#section-nav li a:hover, ul#section-nav li.nav-tab-active a {text-decoration: none;color:#000; }
5
-
6
- div#wpfooter { display: none; }
7
-
8
- #mycred-stats-body { display: block; width: 100%; min-height: 400px; float: none; clear: both; }
9
- #mycred-stats-body a { text-decoration: none; }
10
- #mycred-stats-body a:hover { text-decoration: underline; }
11
- #mycred-stats-body .mycred-stat-widget { display: block; float: none; clear: both; }
12
- #mycred-stats-body .mycred-stat-widget .left-column { width: 240px; min-height: 240px; float: left; margin-right: 24px; }
13
-
14
- #mycred-log-is-empty, .mycred-empty-widget { display: block; width: 100%; height: 400px; }
15
- #mycred-log-is-empty p, .mycred-empty-widget p { margin-top: 180px; line-height: 40px; margin-bottom: 0; padding: 0; text-align: center; font-size: 20px; font-weight: 100; }
16
-
17
- #chart-wrapper { display: block; width: 100%; overflow: hidden; min-height: 450px; }
18
- #chart-wrapper .padding { margin: 12px; }
19
-
20
- canvas#point-gain-chart { height: 420px !important; }
21
- .mycred-chart-legend ul { display: block; list-style-type: none; height: 18px; }
22
- .mycred-chart-legend ul li { display: block; float: left; padding-right: 12px; height: 18px; line-height: 18px; min-width: 100px; }
23
- .mycred-chart-legend ul li span { display: block; float: left; margin-right: 12px; width: 18px; height: 18px; }
24
-
25
- #mycred-stats-overview { padding: 24px 0; }
26
- #mycred-stats-circulation { width: 240px; height: 240px; float: left; margin-right: 24px; }
27
-
28
- canvas#total-circulation-chart { width: 240px !important; height: 240px !important; }
29
-
30
- #total-per-point-type { }
31
- #total-per-point-type li { display: inline; padding-right: 24px; color: #888; }
32
-
33
- #mycred-stats-overview { margin-bottom: 48px; }
34
- #mycred-stats-overview .table { margin-left: 265px; }
35
- #mycred-stats-overview .table table { width: 100%; }
36
- #mycred-stats-overview table tr th { text-align: left; line-height: 24px; font-size: 16px; font-weight: 100; padding: 24px 0 0 0; }
37
- #mycred-stats-overview table tr.subheader th { border-bottom: 1px solid #ddd; font-size: 12px; line-height: 12px; padding: 6px 0; }
38
- #mycred-stats-overview table tr td { padding: 6px 0; border-bottom: 1px solid #dedede; }
39
- #mycred-stats-overview table tr .rowtitle { width: auto; }
40
- #mycred-stats-overview table tr .doublecell { width: 20%; }
41
- #mycred-stats-overview table tr .cell { width: 10%; color: #888; padding-right: 4px; }
42
- #mycred-stats-overview table tr td.last { padding-right: 0; }
43
-
44
- #mycred-stats-body p.mycred-action-buttons a:hover { text-decoration: none; }
45
-
46
- .mycred-popular-items { width: 240px; float: left; margin-right: 24px; }
47
- .mycred-popular-items ol { float: none; clear: both; margin-top: 32px; }
48
- .mycred-popular-items ol > li { border-bottom: 1px solid #dedede; float: none; clear: both; }
49
- .mycred-popular-items ol > li span.view { float: right; }
50
- .mycred-popular-items ol li ul { margin: 0; padding: 0; list-style-type: none; float: none; clear: both; color: #888; }
51
- .mycred-popular-items ol li ul li { margin: 0; padding: 0; width: 50%; display: block; float: left; font-size: 14px; font-weight: 100; line-height: 32px; }
52
-
53
- .last-ten-days-chart { margin-left: 265px; min-height: 400px; padding-top: 24px; margin-bottom: 56px; }
54
- .last-ten-days-chart canvas#point-gain-chart { width: 100%; }
55
-
56
- .empty-mycred-stat { display: block; float: none; width: 100%; height: 400px; background-color: white; }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
addons/stats/assets/css/mycred-statistics.css DELETED
@@ -1,22 +0,0 @@
1
- .mycred-stat-widget {
2
-
3
- }
4
- .mycred-stat-widget canvas {
5
- margin-top: 12px;
6
- }
7
- .mycred-stat-widget h1 {
8
- margin: 0 0 24px 0;
9
- }
10
- .mycred-stat-widget ul {
11
- margin: 0 0 24px 0;
12
- padding: 0 0 0 0;
13
- }
14
- .mycred-stat-widget ul li {
15
- display: inline;
16
- margin: 0 12px 0 0;
17
- padding: 0 0 0 0;
18
- list-style-type: none;
19
- }
20
- .mycred-stats-table table {
21
- background-color: transparent;
22
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
addons/stats/assets/index.php DELETED
@@ -1,3 +0,0 @@
1
- <?php
2
- // Silence is golden.
3
- ?>
 
 
 
addons/stats/assets/js/Chart.js DELETED
@@ -1,3421 +0,0 @@
1
- /*
2
- * Chart.js
3
- * http://chartjs.org/
4
- * Version: 1.1
5
- */
6
- (function(){
7
-
8
- "use strict";
9
-
10
- //Declare root variable - window in the browser, global on the server
11
- var root = this,
12
- previous = root.Chart;
13
-
14
- //Occupy the global variable of Chart, and create a simple base class
15
- var Chart = function(context){
16
- var chart = this;
17
- this.canvas = context.canvas;
18
-
19
- this.ctx = context;
20
-
21
- //Variables global to the chart
22
- var width = this.width = context.canvas.width;
23
- var height = this.height = context.canvas.height;
24
- this.aspectRatio = this.width / this.height;
25
- //High pixel density displays - multiply the size of the canvas height/width by the device pixel ratio, then scale.
26
- helpers.retinaScale(this);
27
-
28
- return this;
29
- };
30
- //Globally expose the defaults to allow for user updating/changing
31
- Chart.defaults = {
32
- global: {
33
- // Boolean - Whether to animate the chart
34
- animation: true,
35
-
36
- // Number - Number of animation steps
37
- animationSteps: 60,
38
-
39
- // String - Animation easing effect
40
- animationEasing: "easeOutQuart",
41
-
42
- // Boolean - If we should show the scale at all
43
- showScale: true,
44
-
45
- // Boolean - If we want to override with a hard coded scale
46
- scaleOverride: false,
47
-
48
- // ** Required if scaleOverride is true **
49
- // Number - The number of steps in a hard coded scale
50
- scaleSteps: null,
51
- // Number - The value jump in the hard coded scale
52
- scaleStepWidth: null,
53
- // Number - The scale starting value
54
- scaleStartValue: null,
55
-
56
- // String - Colour of the scale line
57
- scaleLineColor: "rgba(0,0,0,.1)",
58
-
59
- // Number - Pixel width of the scale line
60
- scaleLineWidth: 1,
61
-
62
- // Boolean - Whether to show labels on the scale
63
- scaleShowLabels: true,
64
-
65
- // Interpolated JS string - can access value
66
- scaleLabel: "<%=value%>",
67
-
68
- // Boolean - Whether the scale should stick to integers, and not show any floats even if drawing space is there
69
- scaleIntegersOnly: true,
70
-
71
- // Boolean - Whether the scale should start at zero, or an order of magnitude down from the lowest value
72
- scaleBeginAtZero: false,
73
-
74
- // String - Scale label font declaration for the scale label
75
- scaleFontFamily: "'Helvetica Neue', 'Helvetica', 'Arial', sans-serif",
76
-
77
- // Number - Scale label font size in pixels
78
- scaleFontSize: 12,
79
-
80
- // String - Scale label font weight style
81
- scaleFontStyle: "normal",
82
-
83
- // String - Scale label font colour
84
- scaleFontColor: "#666",
85
-
86
- // Boolean - Limit number of x labels
87
- scaleLimitXLabels: false,
88
-
89
- // Number - Limit number of x labels to
90
- scaleLimitXLabelsTo: 32,
91
-
92
- // Boolean - whether or not the chart should be responsive and resize when the browser does.
93
- responsive: false,
94
-
95
- // Boolean - whether to maintain the starting aspect ratio or not when responsive, if set to false, will take up entire container
96
- maintainAspectRatio: true,
97
-
98
- // Boolean - Determines whether to draw tooltips on the canvas or not - attaches events to touchmove & mousemove
99
- showTooltips: true,
100
-
101
- // Array - Array of string names to attach tooltip events
102
- tooltipEvents: ["mousemove", "touchstart", "touchmove", "mouseout"],
103
-
104
- // String - Tooltip background colour
105
- tooltipFillColor: "rgba(0,0,0,0.8)",
106
-
107
- // String - Tooltip label font declaration for the scale label
108
- tooltipFontFamily: "'Helvetica Neue', 'Helvetica', 'Arial', sans-serif",
109
-
110
- // Number - Tooltip label font size in pixels
111
- tooltipFontSize: 14,
112
-
113
- // String - Tooltip font weight style
114
- tooltipFontStyle: "normal",
115
-
116
- // String - Tooltip label font colour
117
- tooltipFontColor: "#fff",
118
-
119
- // String - Tooltip title font declaration for the scale label
120
- tooltipTitleFontFamily: "'Helvetica Neue', 'Helvetica', 'Arial', sans-serif",
121
-
122
- // Number - Tooltip title font size in pixels
123
- tooltipTitleFontSize: 14,
124
-
125
- // String - Tooltip title font weight style
126
- tooltipTitleFontStyle: "bold",
127
-
128
- // String - Tooltip title font colour
129
- tooltipTitleFontColor: "#fff",
130
-
131
- // Number - pixel width of padding around tooltip text
132
- tooltipYPadding: 6,
133
-
134
- // Number - pixel width of padding around tooltip text
135
- tooltipXPadding: 6,
136
-
137
- // Number - Size of the caret on the tooltip
138
- tooltipCaretSize: 8,
139
-
140
- // Number - Pixel radius of the tooltip border
141
- tooltipCornerRadius: 6,
142
-
143
- // Number - Pixel offset from point x to tooltip edge
144
- tooltipXOffset: 10,
145
-
146
- // String - Template string for single tooltips
147
- tooltipTemplate: "<%if (label){%><%=label%>: <%}%><%= value %>",
148
-
149
- // String - Template string for single tooltips
150
- multiTooltipTemplate: "<%= value %>",
151
-
152
- // String - Colour behind the legend colour block
153
- multiTooltipKeyBackground: '#fff',
154
-
155
- // Function - Will fire on animation progression.
156
- onAnimationProgress: function(){},
157
-
158
- // Function - Will fire on animation completion.
159
- onAnimationComplete: function(){}
160
-
161
- }
162
- };
163
-
164
- //Create a dictionary of chart types, to allow for extension of existing types
165
- Chart.types = {};
166
-
167
- //Global Chart helpers object for utility methods and classes
168
- var helpers = Chart.helpers = {};
169
-
170
- //-- Basic js utility methods
171
- var each = helpers.each = function(loopable,callback,self){
172
- var additionalArgs = Array.prototype.slice.call(arguments, 3);
173
- // Check to see if null or undefined firstly.
174
- if (loopable){
175
- if (loopable.length === +loopable.length){
176
- var i;
177
- for (i=0; i<loopable.length; i++){
178
- callback.apply(self,[loopable[i], i].concat(additionalArgs));
179
- }
180
- }
181
- else{
182
- for (var item in loopable){
183
- callback.apply(self,[loopable[item],item].concat(additionalArgs));
184
- }
185
- }
186
- }
187
- },
188
- clone = helpers.clone = function(obj){
189
- var objClone = {};
190
- each(obj,function(value,key){
191
- if (obj.hasOwnProperty(key)) objClone[key] = value;
192
- });
193
- return objClone;
194
- },
195
- extend = helpers.extend = function(base){
196
- each(Array.prototype.slice.call(arguments,1), function(extensionObject) {
197
- each(extensionObject,function(value,key){
198
- if (extensionObject.hasOwnProperty(key)) base[key] = value;
199
- });
200
- });
201
- return base;
202
- },
203
- merge = helpers.merge = function(base,master){
204
- //Merge properties in left object over to a shallow clone of object right.
205
- var args = Array.prototype.slice.call(arguments,0);
206
- args.unshift({});
207
- return extend.apply(null, args);
208
- },
209
- indexOf = helpers.indexOf = function(arrayToSearch, item){
210
- if (Array.prototype.indexOf) {
211
- return arrayToSearch.indexOf(item);
212
- }
213
- else{
214
- for (var i = 0; i < arrayToSearch.length; i++) {
215
- if (arrayToSearch[i] === item) return i;
216
- }
217
- return -1;
218
- }
219
- },
220
- where = helpers.where = function(collection, filterCallback){
221
- var filtered = [];
222
-
223
- helpers.each(collection, function(item){
224
- if (filterCallback(item)){
225
- filtered.push(item);
226
- }
227
- });
228
-
229
- return filtered;
230
- },
231
- findNextWhere = helpers.findNextWhere = function(arrayToSearch, filterCallback, startIndex){
232
- // Default to start of the array
233
- if (!startIndex){
234
- startIndex = -1;
235
- }
236
- for (var i = startIndex + 1; i < arrayToSearch.length; i++) {
237
- var currentItem = arrayToSearch[i];
238
- if (filterCallback(currentItem)){
239
- return currentItem;
240
- }
241
- }
242
- },
243
- findPreviousWhere = helpers.findPreviousWhere = function(arrayToSearch, filterCallback, startIndex){
244
- // Default to end of the array
245
- if (!startIndex){
246
- startIndex = arrayToSearch.length;
247
- }
248
- for (var i = startIndex - 1; i >= 0; i--) {
249
- var currentItem = arrayToSearch[i];
250
- if (filterCallback(currentItem)){
251
- return currentItem;
252
- }
253
- }
254
- },
255
- inherits = helpers.inherits = function(extensions){
256
- //Basic javascript inheritance based on the model created in Backbone.js
257
- var parent = this;
258
- var ChartElement = (extensions && extensions.hasOwnProperty("constructor")) ? extensions.constructor : function(){ return parent.apply(this, arguments); };
259
-
260
- var Surrogate = function(){ this.constructor = ChartElement;};
261
- Surrogate.prototype = parent.prototype;
262
- ChartElement.prototype = new Surrogate();
263
-
264
- ChartElement.extend = inherits;
265
-
266
- if (extensions) extend(ChartElement.prototype, extensions);
267
-
268
- ChartElement.__super__ = parent.prototype;
269
-
270
- return ChartElement;
271
- },
272
- noop = helpers.noop = function(){},
273
- uid = helpers.uid = (function(){
274
- var id=0;
275
- return function(){
276
- return "chart-" + id++;
277
- };
278
- })(),
279
- warn = helpers.warn = function(str){
280
- //Method for warning of errors
281
- if (window.console && typeof window.console.warn == "function") console.warn(str);
282
- },
283
- amd = helpers.amd = (typeof define == 'function' && define.amd),
284
- //-- Math methods
285
- isNumber = helpers.isNumber = function(n){
286
- return !isNaN(parseFloat(n)) && isFinite(n);
287
- },
288
- max = helpers.max = function(array){
289
- return Math.max.apply( Math, array );
290
- },
291
- min = helpers.min = function(array){
292
- return Math.min.apply( Math, array );
293
- },
294
- cap = helpers.cap = function(valueToCap,maxValue,minValue){
295
- if(isNumber(maxValue)) {
296
- if( valueToCap > maxValue ) {
297
- return maxValue;
298
- }
299
- }
300
- else if(isNumber(minValue)){
301
- if ( valueToCap < minValue ){
302
- return minValue;
303
- }
304
- }
305
- return valueToCap;
306
- },
307
- getDecimalPlaces = helpers.getDecimalPlaces = function(num){
308
- if (num%1!==0 && isNumber(num)){
309
- return num.toString().split(".")[1].length;
310
- }
311
- else {
312
- return 0;
313
- }
314
- },
315
- toRadians = helpers.radians = function(degrees){
316
- return degrees * (Math.PI/180);
317
- },
318
- // Gets the angle from vertical upright to the point about a centre.
319
- getAngleFromPoint = helpers.getAngleFromPoint = function(centrePoint, anglePoint){
320
- var distanceFromXCenter = anglePoint.x - centrePoint.x,
321
- distanceFromYCenter = anglePoint.y - centrePoint.y,
322
- radialDistanceFromCenter = Math.sqrt( distanceFromXCenter * distanceFromXCenter + distanceFromYCenter * distanceFromYCenter);
323
-
324
-
325
- var angle = Math.PI * 2 + Math.atan2(distanceFromYCenter, distanceFromXCenter);
326
-
327
- //If the segment is in the top left quadrant, we need to add another rotation to the angle
328
- if (distanceFromXCenter < 0 && distanceFromYCenter < 0){
329
- angle += Math.PI*2;
330
- }
331
-
332
- return {
333
- angle: angle,
334
- distance: radialDistanceFromCenter
335
- };
336
- },
337
- aliasPixel = helpers.aliasPixel = function(pixelWidth){
338
- return (pixelWidth % 2 === 0) ? 0 : 0.5;
339
- },
340
- splineCurve = helpers.splineCurve = function(FirstPoint,MiddlePoint,AfterPoint,t){
341
- //Props to Rob Spencer at scaled innovation for his post on splining between points
342
- //http://scaledinnovation.com/analytics/splines/aboutSplines.html
343
- var d01=Math.sqrt(Math.pow(MiddlePoint.x-FirstPoint.x,2)+Math.pow(MiddlePoint.y-FirstPoint.y,2)),
344
- d12=Math.sqrt(Math.pow(AfterPoint.x-MiddlePoint.x,2)+Math.pow(AfterPoint.y-MiddlePoint.y,2)),
345
- fa=t*d01/(d01+d12),// scaling factor for triangle Ta
346
- fb=t*d12/(d01+d12);
347
- return {
348
- inner : {
349
- x : MiddlePoint.x-fa*(AfterPoint.x-FirstPoint.x),
350
- y : MiddlePoint.y-fa*(AfterPoint.y-FirstPoint.y)
351
- },
352
- outer : {
353
- x: MiddlePoint.x+fb*(AfterPoint.x-FirstPoint.x),
354
- y : MiddlePoint.y+fb*(AfterPoint.y-FirstPoint.y)
355
- }
356
- };
357
- },
358
- calculateOrderOfMagnitude = helpers.calculateOrderOfMagnitude = function(val){
359
- return Math.floor(Math.log(val) / Math.LN10);
360
- },
361
- calculateScaleRange = helpers.calculateScaleRange = function(valuesArray, drawingSize, textSize, startFromZero, integersOnly){
362
-
363
- //Set a minimum step of two - a point at the top of the graph, and a point at the base
364
- var minSteps = 2,
365
- maxSteps = Math.floor(drawingSize/(textSize * 1.5)),
366
- skipFitting = (minSteps >= maxSteps);
367
-
368
- var maxValue = max(valuesArray),
369
- minValue = Number.POSITIVE_INFINITY;
370
-
371
- // Ignore nulls since we don't construct points for them (since Math.min treats them as 0)
372
- each(valuesArray, function( value ){
373
- if (value < minValue && value != null){
374
- minValue = value;
375
- }
376
- });
377
-
378
- // We need some degree of seperation here to calculate the scales if all the values are the same
379
- // Adding/minusing 0.5 will give us a range of 1.
380
- if (maxValue === minValue){
381
- maxValue += 0.5;
382
- // So we don't end up with a graph with a negative start value if we've said always start from zero
383
- if (minValue >= 0.5 && !startFromZero){
384
- minValue -= 0.5;
385
- }
386
- else{
387
- // Make up a whole number above the values
388
- maxValue += 0.5;
389
- }
390
- }
391
-
392
- var valueRange = Math.abs(maxValue - minValue),
393
- rangeOrderOfMagnitude = calculateOrderOfMagnitude(valueRange),
394
- graphMax = Math.ceil(maxValue / (1 * Math.pow(10, rangeOrderOfMagnitude))) * Math.pow(10, rangeOrderOfMagnitude),
395
- graphMin = (startFromZero) ? 0 : Math.floor(minValue / (1 * Math.pow(10, rangeOrderOfMagnitude))) * Math.pow(10, rangeOrderOfMagnitude),
396
- graphRange = graphMax - graphMin,
397
- stepValue = Math.pow(10, rangeOrderOfMagnitude),
398
- numberOfSteps = Math.round(graphRange / stepValue);
399
-
400
- //If we have more space on the graph we'll use it to give more definition to the data
401
- while((numberOfSteps > maxSteps || (numberOfSteps * 2) < maxSteps) && !skipFitting) {
402
- if(numberOfSteps > maxSteps){
403
- stepValue *=2;
404
- numberOfSteps = Math.round(graphRange/stepValue);
405
- // Don't ever deal with a decimal number of steps - cancel fitting and just use the minimum number of steps.
406
- if (numberOfSteps % 1 !== 0){
407
- skipFitting = true;
408
- }
409
- }
410
- //We can fit in double the amount of scale points on the scale
411
- else{
412
- //If user has declared ints only, and the step value isn't a decimal
413
- if (integersOnly && rangeOrderOfMagnitude >= 0){
414
- //If the user has said integers only, we need to check that making the scale more granular wouldn't make it a float
415
- if((numberOfSteps * 5) < maxSteps && stepValue/5 % 1 === 0){
416
- stepValue /=5;
417
- numberOfSteps = Math.round(graphRange/stepValue);
418
- }
419
- else if(stepValue/2 % 1 === 0){
420
- stepValue /=2;
421
- numberOfSteps = Math.round(graphRange/stepValue);
422
- }
423
- //If it would make it a float break out of the loop
424
- else{
425
- break;
426
- }
427
- }
428
- //If the scale doesn't have to be an int, make the scale more granular anyway.
429
- else{
430
- stepValue /=2;
431
- numberOfSteps = Math.round(graphRange/stepValue);
432
- }
433
-
434
- }
435
- }
436
-
437
- if (skipFitting){
438
- numberOfSteps = minSteps;
439
- stepValue = graphRange / numberOfSteps;
440
- }
441
-
442
- // Drop unnecessary steps
443
- if(!startFromZero) {
444
- while(minValue > graphMin + stepValue) {
445
- numberOfSteps--;
446
- graphMin += stepValue;
447
- }
448
- }
449
-
450
- while(maxValue < graphMax - stepValue) {
451
- numberOfSteps--;
452
- graphMax -= stepValue;
453
- }
454
-
455
- return {
456
- steps : numberOfSteps,
457
- stepValue : stepValue,
458
- min : graphMin,
459
- max : graphMin + (numberOfSteps * stepValue)
460
- };
461
-
462
- },
463
- /* jshint ignore:start */
464
- // Blows up jshint errors based on the new Function constructor
465
- //Templating methods
466
- //Javascript micro templating by John Resig - source at http://ejohn.org/blog/javascript-micro-templating/
467
- template = helpers.template = function(templateString, valuesObject){
468
- // If templateString is function rather than string-template - call the function for valuesObject
469
- if(templateString instanceof Function){
470
- return templateString(valuesObject);
471
- }
472
-
473
- var cache = {};
474
- function tmpl(str, data){
475
- // Figure out if we're getting a template, or if we need to
476
- // load the template - and be sure to cache the result.
477
- var fn = !/\W/.test(str) ?
478
- cache[str] = cache[str] :
479
-
480
- // Generate a reusable function that will serve as a template
481
- // generator (and which will be cached).
482
- new Function("obj",
483
- "var p=[],print=function(){p.push.apply(p,arguments);};" +
484
-
485
- // Introduce the data as local variables using with(){}
486
- "with(obj){p.push('" +
487
-
488
- // Convert the template into pure JavaScript
489
- str
490
- .replace(/[\r\t\n]/g, " ")
491
- .split("<%").join("\t")
492
- .replace(/((^|%>)[^\t]*)'/g, "$1\r")
493
- .replace(/\t=(.*?)%>/g, "',$1,'")
494
- .split("\t").join("');")
495
- .split("%>").join("p.push('")
496
- .split("\r").join("\\'") +
497
- "');}return p.join('');"
498
- );
499
-
500
- // Provide some basic currying to the user
501
- return data ? fn( data ) : fn;
502
- }
503
- return tmpl(templateString,valuesObject);
504
- },
505
- /* jshint ignore:end */
506
- generateLabels = helpers.generateLabels = function(templateString,numberOfSteps,graphMin,stepValue){
507
- var labelsArray = new Array(numberOfSteps);
508
- if (labelTemplateString){
509
- each(labelsArray,function(val,index){
510
- labelsArray[index] = template(templateString,{value: (graphMin + (stepValue*(index+1)))});
511
- });
512
- }
513
- return labelsArray;
514
- },
515
- //--Animation methods
516
- //Easing functions adapted from Robert Penner's easing equations
517
- //http://www.robertpenner.com/easing/
518
- easingEffects = helpers.easingEffects = {
519
- linear: function (t) {
520
- return t;
521
- },
522
- easeInQuad: function (t) {
523
- return t * t;
524
- },
525
- easeOutQuad: function (t) {
526
- return -1 * t * (t - 2);
527
- },
528
- easeInOutQuad: function (t) {
529
- if ((t /= 1 / 2) < 1) return 1 / 2 * t * t;
530
- return -1 / 2 * ((--t) * (t - 2) - 1);
531
- },
532
- easeInCubic: function (t) {
533
- return t * t * t;
534
- },
535
- easeOutCubic: function (t) {
536
- return 1 * ((t = t / 1 - 1) * t * t + 1);
537
- },
538
- easeInOutCubic: function (t) {
539
- if ((t /= 1 / 2) < 1) return 1 / 2 * t * t * t;
540
- return 1 / 2 * ((t -= 2) * t * t + 2);
541
- },
542
- easeInQuart: function (t) {
543
- return t * t * t * t;
544
- },
545
- easeOutQuart: function (t) {
546
- return -1 * ((t = t / 1 - 1) * t * t * t - 1);
547
- },
548
- easeInOutQuart: function (t) {
549
- if ((t /= 1 / 2) < 1) return 1 / 2 * t * t * t * t;
550
- return -1 / 2 * ((t -= 2) * t * t * t - 2);
551
- },
552
- easeInQuint: function (t) {
553
- return 1 * (t /= 1) * t * t * t * t;
554
- },
555
- easeOutQuint: function (t) {
556
- return 1 * ((t = t / 1 - 1) * t * t * t * t + 1);
557
- },
558
- easeInOutQuint: function (t) {
559
- if ((t /= 1 / 2) < 1) return 1 / 2 * t * t * t * t * t;
560
- return 1 / 2 * ((t -= 2) * t * t * t * t + 2);
561
- },
562
- easeInSine: function (t) {
563
- return -1 * Math.cos(t / 1 * (Math.PI / 2)) + 1;
564
- },
565
- easeOutSine: function (t) {
566
- return 1 * Math.sin(t / 1 * (Math.PI / 2));
567
- },
568
- easeInOutSine: function (t) {
569
- return -1 / 2 * (Math.cos(Math.PI * t / 1) - 1);
570
- },
571
- easeInExpo: function (t) {
572
- return (t === 0) ? 1 : 1 * Math.pow(2, 10 * (t / 1 - 1));
573
- },
574
- easeOutExpo: function (t) {
575
- return (t === 1) ? 1 : 1 * (-Math.pow(2, -10 * t / 1) + 1);
576
- },
577
- easeInOutExpo: function (t) {
578
- if (t === 0) return 0;
579
- if (t === 1) return 1;
580
- if ((t /= 1 / 2) < 1) return 1 / 2 * Math.pow(2, 10 * (t - 1));
581
- return 1 / 2 * (-Math.pow(2, -10 * --t) + 2);
582
- },
583
- easeInCirc: function (t) {
584
- if (t >= 1) return t;
585
- return -1 * (Math.sqrt(1 - (t /= 1) * t) - 1);
586
- },
587
- easeOutCirc: function (t) {
588
- return 1 * Math.sqrt(1 - (t = t / 1 - 1) * t);
589
- },
590
- easeInOutCirc: function (t) {
591
- if ((t /= 1 / 2) < 1) return -1 / 2 * (Math.sqrt(1 - t * t) - 1);
592
- return 1 / 2 * (Math.sqrt(1 - (t -= 2) * t) + 1);
593
- },
594
- easeInElastic: function (t) {
595
- var s = 1.70158;
596
- var p = 0;
597
- var a = 1;
598
- if (t === 0) return 0;
599
- if ((t /= 1) == 1) return 1;
600
- if (!p) p = 1 * 0.3;
601
- if (a < Math.abs(1)) {
602
- a = 1;
603
- s = p / 4;
604
- } else s = p / (2 * Math.PI) * Math.asin(1 / a);
605
- return -(a * Math.pow(2, 10 * (t -= 1)) * Math.sin((t * 1 - s) * (2 * Math.PI) / p));
606
- },
607
- easeOutElastic: function (t) {
608
- var s = 1.70158;
609
- var p = 0;
610
- var a = 1;
611
- if (t === 0) return 0;
612
- if ((t /= 1) == 1) return 1;
613
- if (!p) p = 1 * 0.3;
614
- if (a < Math.abs(1)) {
615
- a = 1;
616
- s = p / 4;
617
- } else s = p / (2 * Math.PI) * Math.asin(1 / a);
618
- return a * Math.pow(2, -10 * t) * Math.sin((t * 1 - s) * (2 * Math.PI) / p) + 1;
619
- },
620
- easeInOutElastic: function (t) {
621
- var s = 1.70158;
622
- var p = 0;
623
- var a = 1;
624
- if (t === 0) return 0;
625
- if ((t /= 1 / 2) == 2) return 1;
626
- if (!p) p = 1 * (0.3 * 1.5);
627
- if (a < Math.abs(1)) {
628
- a = 1;
629
- s = p / 4;
630
- } else s = p / (2 * Math.PI) * Math.asin(1 / a);
631
- if (t < 1) return -0.5 * (a * Math.pow(2, 10 * (t -= 1)) * Math.sin((t * 1 - s) * (2 * Math.PI) / p));
632
- return a * Math.pow(2, -10 * (t -= 1)) * Math.sin((t * 1 - s) * (2 * Math.PI) / p) * 0.5 + 1;
633
- },
634
- easeInBack: function (t) {
635
- var s = 1.70158;
636
- return 1 * (t /= 1) * t * ((s + 1) * t - s);
637
- },
638
- easeOutBack: function (t) {
639
- var s = 1.70158;
640
- return 1 * ((t = t / 1 - 1) * t * ((s + 1) * t + s) + 1);
641
- },
642
- easeInOutBack: function (t) {
643
- var s = 1.70158;
644
- if ((t /= 1 / 2) < 1) return 1 / 2 * (t * t * (((s *= (1.525)) + 1) * t - s));
645
- return 1 / 2 * ((t -= 2) * t * (((s *= (1.525)) + 1) * t + s) + 2);
646
- },
647
- easeInBounce: function (t) {
648
- return 1 - easingEffects.easeOutBounce(1 - t);
649
- },
650
- easeOutBounce: function (t) {
651
- if ((t /= 1) < (1 / 2.75)) {
652
- return 1 * (7.5625 * t * t);
653
- } else if (t < (2 / 2.75)) {
654
- return 1 * (7.5625 * (t -= (1.5 / 2.75)) * t + 0.75);
655
- } else if (t < (2.5 / 2.75)) {
656
- return 1 * (7.5625 * (t -= (2.25 / 2.75)) * t + 0.9375);
657
- } else {
658
- return 1 * (7.5625 * (t -= (2.625 / 2.75)) * t + 0.984375);
659
- }
660
- },
661
- easeInOutBounce: function (t) {
662
- if (t < 1 / 2) return easingEffects.easeInBounce(t * 2) * 0.5;
663
- return easingEffects.easeOutBounce(t * 2 - 1) * 0.5 + 1 * 0.5;
664
- }
665
- },
666
- //Request animation polyfill - http://www.paulirish.com/2011/requestanimationframe-for-smart-animating/
667
- requestAnimFrame = helpers.requestAnimFrame = (function(){
668
- return window.requestAnimationFrame ||
669
- window.webkitRequestAnimationFrame ||
670
- window.mozRequestAnimationFrame ||
671
- window.oRequestAnimationFrame ||
672
- window.msRequestAnimationFrame ||
673
- function(callback) {
674
- return window.setTimeout(callback, 1000 / 60);
675
- };
676
- })(),
677
- cancelAnimFrame = helpers.cancelAnimFrame = (function(){
678
- return window.cancelAnimationFrame ||
679
- window.webkitCancelAnimationFrame ||
680
- window.mozCancelAnimationFrame ||
681
- window.oCancelAnimationFrame ||
682
- window.msCancelAnimationFrame ||
683
- function(callback) {
684
- return window.clearTimeout(callback, 1000 / 60);
685
- };
686
- })(),
687
- animationLoop = helpers.animationLoop = function(callback,totalSteps,easingString,onProgress,onComplete,chartInstance){
688
-
689
- var currentStep = 0,
690
- easingFunction = easingEffects[easingString] || easingEffects.linear;
691
-
692
- var animationFrame = function(){
693
- currentStep++;
694
- var stepDecimal = currentStep/totalSteps;
695
- var easeDecimal = easingFunction(stepDecimal);
696
-
697
- callback.call(chartInstance,easeDecimal,stepDecimal, currentStep);
698
- onProgress.call(chartInstance,easeDecimal,stepDecimal);
699
- if (currentStep < totalSteps){
700
- chartInstance.animationFrame = requestAnimFrame(animationFrame);
701
- } else{
702
- onComplete.apply(chartInstance);
703
- }
704
- };
705
- requestAnimFrame(animationFrame);
706
- },
707
- //-- DOM methods
708
- getRelativePosition = helpers.getRelativePosition = function(evt){
709
- var mouseX, mouseY;
710
- var e = evt.originalEvent || evt,
711
- canvas = evt.currentTarget || evt.srcElement,
712
- boundingRect = canvas.getBoundingClientRect();
713
-
714
- if (e.touches){
715
- mouseX = e.touches[0].clientX - boundingRect.left;
716
- mouseY = e.touches[0].clientY - boundingRect.top;
717
-
718
- }
719
- else{
720
- mouseX = e.clientX - boundingRect.left;
721
- mouseY = e.clientY - boundingRect.top;
722
- }
723
-
724
- return {
725
- x : mouseX,
726
- y : mouseY
727
- };
728
-
729
- },
730
- addEvent = helpers.addEvent = function(node,eventType,method){
731
- if (node.addEventListener){
732
- node.addEventListener(eventType,method);
733
- } else if (node.attachEvent){
734
- node.attachEvent("on"+eventType, method);
735
- } else {
736
- node["on"+eventType] = method;
737
- }
738
- },
739
- removeEvent = helpers.removeEvent = function(node, eventType, handler){
740
- if (node.removeEventListener){
741
- node.removeEventListener(eventType, handler, false);
742
- } else if (node.detachEvent){
743
- node.detachEvent("on"+eventType,handler);
744
- } else{
745
- node["on" + eventType] = noop;
746
- }
747
- },
748
- bindEvents = helpers.bindEvents = function(chartInstance, arrayOfEvents, handler){
749
- // Create the events object if it's not already present
750
- if (!chartInstance.events) chartInstance.events = {};
751
-
752
- each(arrayOfEvents,function(eventName){
753
- chartInstance.events[eventName] = function(){
754
- handler.apply(chartInstance, arguments);
755
- };
756
- addEvent(chartInstance.chart.canvas,eventName,chartInstance.events[eventName]);
757
- });
758
- },
759
- unbindEvents = helpers.unbindEvents = function (chartInstance, arrayOfEvents) {
760
- each(arrayOfEvents, function(handler,eventName){
761
- removeEvent(chartInstance.chart.canvas, eventName, handler);
762
- });
763
- },
764
- getMaximumWidth = helpers.getMaximumWidth = function(domNode){
765
- var container = domNode.parentNode;
766
- // TODO = check cross browser stuff with this.
767
- return container.clientWidth;
768
- },
769
- getMaximumHeight = helpers.getMaximumHeight = function(domNode){
770
- var container = domNode.parentNode;
771
- // TODO = check cross browser stuff with this.
772
- return container.clientHeight;
773
- },
774
- getMaximumSize = helpers.getMaximumSize = helpers.getMaximumWidth, // legacy support
775
- retinaScale = helpers.retinaScale = function(chart){
776
- var ctx = chart.ctx,
777
- width = chart.canvas.width,
778
- height = chart.canvas.height;
779
-
780
- if (window.devicePixelRatio) {
781
- ctx.canvas.style.width = width + "px";
782
- ctx.canvas.style.height = height + "px";
783
- ctx.canvas.height = height * window.devicePixelRatio;
784
- ctx.canvas.width = width * window.devicePixelRatio;
785
- ctx.scale(window.devicePixelRatio, window.devicePixelRatio);
786
- }
787
- },
788
- //-- Canvas methods
789
- clear = helpers.clear = function(chart){
790
- chart.ctx.clearRect(0,0,chart.width,chart.height);
791
- },
792
- fontString = helpers.fontString = function(pixelSize,fontStyle,fontFamily){
793
- return fontStyle + " " + pixelSize+"px " + fontFamily;
794
- },
795
- longestText = helpers.longestText = function(ctx,font,arrayOfStrings){
796
- ctx.font = font;
797
- var longest = 0;
798
- each(arrayOfStrings,function(string){
799
- var textWidth = ctx.measureText(string).width;
800
- longest = (textWidth > longest) ? textWidth : longest;
801
- });
802
- return longest;
803
- },
804
- drawRoundedRectangle = helpers.drawRoundedRectangle = function(ctx,x,y,width,height,radius){
805
- ctx.beginPath();
806
- ctx.moveTo(x + radius, y);
807
- ctx.lineTo(x + width - radius, y);
808
- ctx.quadraticCurveTo(x + width, y, x + width, y + radius);
809
- ctx.lineTo(x + width, y + height - radius);
810
- ctx.quadraticCurveTo(x + width, y + height, x + width - radius, y + height);
811
- ctx.lineTo(x + radius, y + height);
812
- ctx.quadraticCurveTo(x, y + height, x, y + height - radius);
813
- ctx.lineTo(x, y + radius);
814
- ctx.quadraticCurveTo(x, y, x + radius, y);
815
- ctx.closePath();
816
- };
817
-
818
-
819
- //Store a reference to each instance - allowing us to globally resize chart instances on window resize.
820
- //Destroy method on the chart will remove the instance of the chart from this reference.
821
- Chart.instances = {};
822
-
823
- Chart.Type = function(data,options,chart){
824
- this.options = options;
825
- this.chart = chart;
826
- this.id = uid();
827
- //Add the chart instance to the global namespace
828
- Chart.instances[this.id] = this;
829
-
830
- // Initialize is always called when a chart type is created
831
- // By default it is a no op, but it should be extended
832
- if (options.responsive){
833
- this.resize();
834
- }
835
- this.initialize.call(this,data);
836
- };
837
-
838
- //Core methods that'll be a part of every chart type
839
- extend(Chart.Type.prototype,{
840
- initialize : function(){return this;},
841
- clear : function(){
842
- clear(this.chart);
843
- return this;
844
- },
845
- stop : function(){
846
- // Stops any current animation loop occuring
847
- helpers.cancelAnimFrame.call(root, this.animationFrame);
848
- return this;
849
- },
850
- resize : function(callback){
851
- this.stop();
852
- var canvas = this.chart.canvas,
853
- newWidth = getMaximumWidth(this.chart.canvas),
854
- newHeight = this.options.maintainAspectRatio ? newWidth / this.chart.aspectRatio : getMaximumHeight(this.chart.canvas);
855
-
856
- canvas.width = this.chart.width = newWidth;
857
- canvas.height = this.chart.height = newHeight;
858
-
859
- retinaScale(this.chart);
860
-
861
- if (typeof callback === "function"){
862
- callback.apply(this, Array.prototype.slice.call(arguments, 1));
863
- }
864
- return this;
865
- },
866
- reflow : noop,
867
- render : function(reflow){
868
- if (reflow){
869
- this.reflow();
870
- }
871
- if (this.options.animation && !reflow){
872
- helpers.animationLoop(
873
- this.draw,
874
- this.options.animationSteps,
875
- this.options.animationEasing,
876
- this.options.onAnimationProgress,
877
- this.options.onAnimationComplete,
878
- this
879
- );
880
- }
881
- else{
882
- this.draw();
883
- this.options.onAnimationComplete.call(this);
884
- }
885
- return this;
886
- },
887
- generateLegend : function(){
888
- return template(this.options.legendTemplate,this);
889
- },
890
- destroy : function(){
891
- this.clear();
892
- unbindEvents(this, this.events);
893
- delete Chart.instances[this.id];
894
- },
895
- showTooltip : function(ChartElements, forceRedraw){
896
- // Only redraw the chart if we've actually changed what we're hovering on.
897
- if (typeof this.activeElements === 'undefined') this.activeElements = [];
898
-
899
- var isChanged = (function(Elements){
900
- var changed = false;
901
-
902
- if (Elements.length !== this.activeElements.length){
903
- changed = true;
904
- return changed;
905
- }
906
-
907
- each(Elements, function(element, index){
908
- if (element !== this.activeElements[index]){
909
- changed = true;
910
- }
911
- }, this);
912
- return changed;
913
- }).call(this, ChartElements);
914
-
915
- if (!isChanged && !forceRedraw){
916
- return;
917
- }
918
- else{
919
- this.activeElements = ChartElements;
920
- }
921
- this.draw();
922
- if (ChartElements.length > 0){
923
- // If we have multiple datasets, show a MultiTooltip for all of the data points at that index
924
- if (this.datasets && this.datasets.length > 1) {
925
- var dataArray,
926
- dataIndex;
927
-
928
- for (var i = this.datasets.length - 1; i >= 0; i--) {
929
- dataArray = this.datasets[i].points || this.datasets[i].bars || this.datasets[i].segments;
930
- dataIndex = indexOf(dataArray, ChartElements[0]);
931
- if (dataIndex !== -1){
932
- break;
933
- }
934
- }
935
- var tooltipLabels = [],
936
- tooltipColors = [],
937
- medianPosition = (function(index) {
938
-
939
- // Get all the points at that particular index
940
- var Elements = [],
941
- dataCollection,
942
- xPositions = [],
943
- yPositions = [],
944
- xMax,
945
- yMax,
946
- xMin,
947
- yMin;
948
- helpers.each(this.datasets, function(dataset){
949
- dataCollection = dataset.points || dataset.bars || dataset.segments;
950
- if (dataCollection[dataIndex] && dataCollection[dataIndex].hasValue()){
951
- Elements.push(dataCollection[dataIndex]);
952
- }
953
- });
954
-
955
- helpers.each(Elements, function(element) {
956
- xPositions.push(element.x);
957
- yPositions.push(element.y);
958
-
959
-
960
- //Include any colour information about the element
961
- tooltipLabels.push(helpers.template(this.options.multiTooltipTemplate, element));
962
- tooltipColors.push({
963
- fill: element._saved.fillColor || element.fillColor,
964
- stroke: element._saved.strokeColor || element.strokeColor
965
- });
966
-
967
- }, this);
968
-
969
- yMin = min(yPositions);
970
- yMax = max(yPositions);
971
-
972
- xMin = min(xPositions);
973
- xMax = max(xPositions);
974
-
975
- return {
976
- x: (xMin > this.chart.width/2) ? xMin : xMax,
977
- y: (yMin + yMax)/2
978
- };
979
- }).call(this, dataIndex);
980
-
981
- new Chart.MultiTooltip({
982
- x: medianPosition.x,
983
- y: medianPosition.y,
984
- xPadding: this.options.tooltipXPadding,
985
- yPadding: this.options.tooltipYPadding,
986
- xOffset: this.options.tooltipXOffset,
987
- fillColor: this.options.tooltipFillColor,
988
- textColor: this.options.tooltipFontColor,
989
- fontFamily: this.options.tooltipFontFamily,
990
- fontStyle: this.options.tooltipFontStyle,
991
- fontSize: this.options.tooltipFontSize,
992
- titleTextColor: this.options.tooltipTitleFontColor,
993
- titleFontFamily: this.options.tooltipTitleFontFamily,
994
- titleFontStyle: this.options.tooltipTitleFontStyle,
995
- titleFontSize: this.options.tooltipTitleFontSize,
996
- cornerRadius: this.options.tooltipCornerRadius,
997
- labels: tooltipLabels,
998
- legendColors: tooltipColors,
999
- legendColorBackground : this.options.multiTooltipKeyBackground,
1000
- title: ChartElements[0].label,
1001
- chart: this.chart,
1002
- ctx: this.chart.ctx
1003
- }).draw();
1004
-
1005
- } else {
1006
- each(ChartElements, function(Element) {
1007
- var tooltipPosition = Element.tooltipPosition();
1008
- new Chart.Tooltip({
1009
- x: Math.round(tooltipPosition.x),
1010
- y: Math.round(tooltipPosition.y),
1011
- xPadding: this.options.tooltipXPadding,
1012
- yPadding: this.options.tooltipYPadding,
1013
- fillColor: this.options.tooltipFillColor,
1014
- textColor: this.options.tooltipFontColor,
1015
- fontFamily: this.options.tooltipFontFamily,
1016
- fontStyle: this.options.tooltipFontStyle,
1017
- fontSize: this.options.tooltipFontSize,
1018
- caretHeight: this.options.tooltipCaretSize,
1019
- cornerRadius: this.options.tooltipCornerRadius,
1020
- text: template(this.options.tooltipTemplate, Element),
1021
- chart: this.chart
1022
- }).draw();
1023
- }, this);
1024
- }
1025
- }
1026
- return this;
1027
- },
1028
- toBase64Image : function(){
1029
- return this.chart.canvas.toDataURL.apply(this.chart.canvas, arguments);
1030
- }
1031
- });
1032
-
1033
- Chart.Type.extend = function(extensions){
1034
-
1035
- var parent = this;
1036
-
1037
- var ChartType = function(){
1038
- return parent.apply(this,arguments);
1039
- };
1040
-
1041
- //Copy the prototype object of the this class
1042
- ChartType.prototype = clone(parent.prototype);
1043
- //Now overwrite some of the properties in the base class with the new extensions
1044
- extend(ChartType.prototype, extensions);
1045
-
1046
- ChartType.extend = Chart.Type.extend;
1047
-
1048
- if (extensions.name || parent.prototype.name){
1049
-
1050
- var chartName = extensions.name || parent.prototype.name;
1051
- //Assign any potential default values of the new chart type
1052
-
1053
- //If none are defined, we'll use a clone of the chart type this is being extended from.
1054
- //I.e. if we extend a line chart, we'll use the defaults from the line chart if our new chart
1055
- //doesn't define some defaults of their own.
1056
-
1057
- var baseDefaults = (Chart.defaults[parent.prototype.name]) ? clone(Chart.defaults[parent.prototype.name]) : {};
1058
-
1059
- Chart.defaults[chartName] = extend(baseDefaults,extensions.defaults);
1060
-
1061
- Chart.types[chartName] = ChartType;
1062
-
1063
- //Register this new chart type in the Chart prototype
1064
- Chart.prototype[chartName] = function(data,options){
1065
- var config = merge(Chart.defaults.global, Chart.defaults[chartName], options || {});
1066
- return new ChartType(data,config,this);
1067
- };
1068
- } else{
1069
- warn("Name not provided for this chart, so it hasn't been registered");
1070
- }
1071
- return parent;
1072
- };
1073
-
1074
- Chart.Element = function(configuration){
1075
- extend(this,configuration);
1076
- this.initialize.apply(this,arguments);
1077
- this.save();
1078
- };
1079
- extend(Chart.Element.prototype,{
1080
- initialize : function(){},
1081
- restore : function(props){
1082
- if (!props){
1083
- extend(this,this._saved);
1084
- } else {
1085
- each(props,function(key){
1086
- this[key] = this._saved[key];
1087
- },this);
1088
- }
1089
- return this;
1090
- },
1091
- save : function(){
1092
- this._saved = clone(this);
1093
- delete this._saved._saved;
1094
- return this;
1095
- },
1096
- update : function(newProps){
1097
- each(newProps,function(value,key){
1098
- this._saved[key] = this[key];
1099
- this[key] = value;
1100
- },this);
1101
- return this;
1102
- },
1103
- transition : function(props,ease){
1104
- each(props,function(value,key){
1105
- this[key] = ((value - this._saved[key]) * ease) + this._saved[key];
1106
- },this);
1107
- return this;
1108
- },
1109
- tooltipPosition : function(){
1110
- return {
1111
- x : this.x,
1112
- y : this.y
1113
- };
1114
- },
1115
- hasValue: function(){
1116
- return isNumber(this.value);
1117
- }
1118
- });
1119
-
1120
- Chart.Element.extend = inherits;
1121
-
1122
-
1123
- Chart.Point = Chart.Element.extend({
1124
- display: true,
1125
- inRange: function(chartX,chartY){
1126
- var hitDetectionRange = this.hitDetectionRadius + this.radius;
1127
- return ((Math.pow(chartX-this.x, 2)+Math.pow(chartY-this.y, 2)) < Math.pow(hitDetectionRange,2));
1128
- },
1129
- draw : function(){
1130
- if (this.display){
1131
- var ctx = this.ctx;
1132
- ctx.beginPath();
1133
-
1134
- ctx.arc(this.x, this.y, this.radius, 0, Math.PI*2);
1135
- ctx.closePath();
1136
-
1137
- ctx.strokeStyle = this.strokeColor;
1138
- ctx.lineWidth = this.strokeWidth;
1139
-
1140
- ctx.fillStyle = this.fillColor;
1141
-
1142
- ctx.fill();
1143
- ctx.stroke();
1144
- }
1145
-
1146
-
1147
- //Quick debug for bezier curve splining
1148
- //Highlights control points and the line between them.
1149
- //Handy for dev - stripped in the min version.
1150
-
1151
- // ctx.save();
1152
- // ctx.fillStyle = "black";
1153
- // ctx.strokeStyle = "black"
1154
- // ctx.beginPath();
1155
- // ctx.arc(this.controlPoints.inner.x,this.controlPoints.inner.y, 2, 0, Math.PI*2);
1156
- // ctx.fill();
1157
-
1158
- // ctx.beginPath();
1159
- // ctx.arc(this.controlPoints.outer.x,this.controlPoints.outer.y, 2, 0, Math.PI*2);
1160
- // ctx.fill();
1161
-
1162
- // ctx.moveTo(this.controlPoints.inner.x,this.controlPoints.inner.y);
1163
- // ctx.lineTo(this.x, this.y);
1164
- // ctx.lineTo(this.controlPoints.outer.x,this.controlPoints.outer.y);
1165
- // ctx.stroke();
1166
-
1167
- // ctx.restore();
1168
-
1169
-
1170
-
1171
- }
1172
- });
1173
-
1174
- Chart.Arc = Chart.Element.extend({
1175
- inRange : function(chartX,chartY){
1176
-
1177
- var pointRelativePosition = helpers.getAngleFromPoint(this, {
1178
- x: chartX,
1179
- y: chartY
1180
- });
1181
-
1182
- //Check if within the range of the open/close angle
1183
- var betweenAngles = (pointRelativePosition.angle >= this.startAngle && pointRelativePosition.angle <= this.endAngle),
1184
- withinRadius = (pointRelativePosition.distance >= this.innerRadius && pointRelativePosition.distance <= this.outerRadius);
1185
-
1186
- return (betweenAngles && withinRadius);
1187
- //Ensure within the outside of the arc centre, but inside arc outer
1188
- },
1189
- tooltipPosition : function(){
1190
- var centreAngle = this.startAngle + ((this.endAngle - this.startAngle) / 2),
1191
- rangeFromCentre = (this.outerRadius - this.innerRadius) / 2 + this.innerRadius;
1192
- return {
1193
- x : this.x + (Math.cos(centreAngle) * rangeFromCentre),
1194
- y : this.y + (Math.sin(centreAngle) * rangeFromCentre)
1195
- };
1196
- },
1197
- draw : function(animationPercent){
1198
-
1199
- var easingDecimal = animationPercent || 1;
1200
-
1201
- var ctx = this.ctx;
1202
-
1203
- ctx.beginPath();
1204
-
1205
- ctx.arc(this.x, this.y, this.outerRadius, this.startAngle, this.endAngle);
1206
-
1207
- ctx.arc(this.x, this.y, this.innerRadius, this.endAngle, this.startAngle, true);
1208
-
1209
- ctx.closePath();
1210
- ctx.strokeStyle = this.strokeColor;
1211
- ctx.lineWidth = this.strokeWidth;
1212
-
1213
- ctx.fillStyle = this.fillColor;
1214
-
1215
- ctx.fill();
1216
- ctx.lineJoin = 'bevel';
1217
-
1218
- if (this.showStroke){
1219
- ctx.stroke();
1220
- }
1221
- }
1222
- });
1223
-
1224
- Chart.Rectangle = Chart.Element.extend({
1225
- draw : function(){
1226
- var ctx = this.ctx,
1227
- halfWidth = this.width/2,
1228
- leftX = this.x - halfWidth,
1229
- rightX = this.x + halfWidth,
1230
- top = this.base - (this.base - this.y),
1231
- halfStroke = this.strokeWidth / 2;
1232
-
1233
- // Canvas doesn't allow us to stroke inside the width so we can
1234
- // adjust the sizes to fit if we're setting a stroke on the line
1235
- if (this.showStroke){
1236
- leftX += halfStroke;
1237
- rightX -= halfStroke;
1238
- top += halfStroke;
1239
- }
1240
-
1241
- ctx.beginPath();
1242
-
1243
- ctx.fillStyle = this.fillColor;
1244
- ctx.strokeStyle = this.strokeColor;
1245
- ctx.lineWidth = this.strokeWidth;
1246
-
1247
- // It'd be nice to keep this class totally generic to any rectangle
1248
- // and simply specify which border to miss out.
1249
- ctx.moveTo(leftX, this.base);
1250
- ctx.lineTo(leftX, top);
1251
- ctx.lineTo(rightX, top);
1252
- ctx.lineTo(rightX, this.base);
1253
- ctx.fill();
1254
- if (this.showStroke){
1255
- ctx.stroke();
1256
- }
1257
- },
1258
- height : function(){
1259
- return this.base - this.y;
1260
- },
1261
- inRange : function(chartX,chartY){
1262
- return (chartX >= this.x - this.width/2 && chartX <= this.x + this.width/2) && (chartY >= this.y && chartY <= this.base);
1263
- }
1264
- });
1265
-
1266
- Chart.Tooltip = Chart.Element.extend({
1267
- draw : function(){
1268
-
1269
- var ctx = this.chart.ctx;
1270
-
1271
- ctx.font = fontString(this.fontSize,this.fontStyle,this.fontFamily);
1272
-
1273
- this.xAlign = "center";
1274
- this.yAlign = "above";
1275
-
1276
- //Distance between the actual element.y position and the start of the tooltip caret
1277
- var caretPadding = 2;
1278
-
1279
- var tooltipWidth = ctx.measureText(this.text).width + 2*this.xPadding,
1280
- tooltipRectHeight = this.fontSize + 2*this.yPadding,
1281
- tooltipHeight = tooltipRectHeight + this.caretHeight + caretPadding;
1282
-
1283
- if (this.x + tooltipWidth/2 >this.chart.width){
1284
- this.xAlign = "left";
1285
- } else if (this.x - tooltipWidth/2 < 0){
1286
- this.xAlign = "right";
1287
- }
1288
-
1289
- if (this.y - tooltipHeight < 0){
1290
- this.yAlign = "below";
1291
- }
1292
-
1293
-
1294
- var tooltipX = this.x - tooltipWidth/2,
1295
- tooltipY = this.y - tooltipHeight;
1296
-
1297
- ctx.fillStyle = this.fillColor;
1298
-
1299
- switch(this.yAlign)
1300
- {
1301
- case "above":
1302
- //Draw a caret above the x/y
1303
- ctx.beginPath();
1304
- ctx.moveTo(this.x,this.y - caretPadding);
1305
- ctx.lineTo(this.x + this.caretHeight, this.y - (caretPadding + this.caretHeight));
1306
- ctx.lineTo(this.x - this.caretHeight, this.y - (caretPadding + this.caretHeight));
1307
- ctx.closePath();
1308
- ctx.fill();
1309
- break;
1310
- case "below":
1311
- tooltipY = this.y + caretPadding + this.caretHeight;
1312
- //Draw a caret below the x/y
1313
- ctx.beginPath();
1314
- ctx.moveTo(this.x, this.y + caretPadding);
1315
- ctx.lineTo(this.x + this.caretHeight, this.y + caretPadding + this.caretHeight);
1316
- ctx.lineTo(this.x - this.caretHeight, this.y + caretPadding + this.caretHeight);
1317
- ctx.closePath();
1318
- ctx.fill();
1319
- break;
1320
- }
1321
-
1322
- switch(this.xAlign)
1323
- {
1324
- case "left":
1325
- tooltipX = this.x - tooltipWidth + (this.cornerRadius + this.caretHeight);
1326
- break;
1327
- case "right":
1328
- tooltipX = this.x - (this.cornerRadius + this.caretHeight);
1329
- break;
1330
- }
1331
-
1332
- drawRoundedRectangle(ctx,tooltipX,tooltipY,tooltipWidth,tooltipRectHeight,this.cornerRadius);
1333
-
1334
- ctx.fill();
1335
-
1336
- ctx.fillStyle = this.textColor;
1337
- ctx.textAlign = "center";
1338
- ctx.textBaseline = "middle";
1339
- ctx.fillText(this.text, tooltipX + tooltipWidth/2, tooltipY + tooltipRectHeight/2);
1340
- }
1341
- });
1342
-
1343
- Chart.MultiTooltip = Chart.Element.extend({
1344
- initialize : function(){
1345
- this.font = fontString(this.fontSize,this.fontStyle,this.fontFamily);
1346
-
1347
- this.titleFont = fontString(this.titleFontSize,this.titleFontStyle,this.titleFontFamily);
1348
-
1349
- this.height = (this.labels.length * this.fontSize) + ((this.labels.length-1) * (this.fontSize/2)) + (this.yPadding*2) + this.titleFontSize *1.5;
1350
-
1351
- this.ctx.font = this.titleFont;
1352
-
1353
- var titleWidth = this.ctx.measureText(this.title).width,
1354
- //Label has a legend square as well so account for this.
1355
- labelWidth = longestText(this.ctx,this.font,this.labels) + this.fontSize + 3,
1356
- longestTextWidth = max([labelWidth,titleWidth]);
1357
-
1358
- this.width = longestTextWidth + (this.xPadding*2);
1359
-
1360
-
1361
- var halfHeight = this.height/2;
1362
-
1363
- //Check to ensure the height will fit on the canvas
1364
- //The three is to buffer form the very
1365
- if (this.y - halfHeight < 0 ){
1366
- this.y = halfHeight;
1367
- } else if (this.y + halfHeight > this.chart.height){
1368
- this.y = this.chart.height - halfHeight;
1369
- }
1370
-
1371
- //Decide whether to align left or right based on position on canvas
1372
- if (this.x > this.chart.width/2){
1373
- this.x -= this.xOffset + this.width;
1374
- } else {
1375
- this.x += this.xOffset;
1376
- }
1377
-
1378
-
1379
- },
1380
- getLineHeight : function(index){
1381
- var baseLineHeight = this.y - (this.height/2) + this.yPadding,
1382
- afterTitleIndex = index-1;
1383
-
1384
- //If the index is zero, we're getting the title
1385
- if (index === 0){
1386
- return baseLineHeight + this.titleFontSize/2;
1387
- } else{
1388
- return baseLineHeight + ((this.fontSize*1.5*afterTitleIndex) + this.fontSize/2) + this.titleFontSize * 1.5;
1389
- }
1390
-
1391
- },
1392
- draw : function(){
1393
- drawRoundedRectangle(this.ctx,this.x,this.y - this.height/2,this.width,this.height,this.cornerRadius);
1394
- var ctx = this.ctx;
1395
- ctx.fillStyle = this.fillColor;
1396
- ctx.fill();
1397
- ctx.closePath();
1398
-
1399
- ctx.textAlign = "left";
1400
- ctx.textBaseline = "middle";
1401
- ctx.fillStyle = this.titleTextColor;
1402
- ctx.font = this.titleFont;
1403
-
1404
- ctx.fillText(this.title,this.x + this.xPadding, this.getLineHeight(0));
1405
-
1406
- ctx.font = this.font;
1407
- helpers.each(this.labels,function(label,index){
1408
- ctx.fillStyle = this.textColor;
1409
- ctx.fillText(label,this.x + this.xPadding + this.fontSize + 3, this.getLineHeight(index + 1));
1410
-
1411
- //A bit gnarly, but clearing this rectangle breaks when using explorercanvas (clears whole canvas)
1412
- //ctx.clearRect(this.x + this.xPadding, this.getLineHeight(index + 1) - this.fontSize/2, this.fontSize, this.fontSize);
1413
- //Instead we'll make a white filled block to put the legendColour palette over.
1414
-
1415
- ctx.fillStyle = this.legendColorBackground;
1416
- ctx.fillRect(this.x + this.xPadding, this.getLineHeight(index + 1) - this.fontSize/2, this.fontSize, this.fontSize);
1417
-
1418
- ctx.fillStyle = this.legendColors[index].fill;
1419
- ctx.fillRect(this.x + this.xPadding, this.getLineHeight(index + 1) - this.fontSize/2, this.fontSize, this.fontSize);
1420
-
1421
-
1422
- },this);
1423
- }
1424
- });
1425
-
1426
- Chart.Scale = Chart.Element.extend({
1427
- initialize : function(){
1428
- this.fit();
1429
- },
1430
- buildYLabels : function(){
1431
- this.yLabels = [];
1432
-
1433
- var stepDecimalPlaces = getDecimalPlaces(this.stepValue);
1434
-
1435
- for (var i=0; i<=this.steps; i++){
1436
- this.yLabels.push(template(this.templateString,{value:(this.min + (i * this.stepValue)).toFixed(stepDecimalPlaces)}));
1437
- }
1438
- this.yLabelWidth = (this.display && this.showLabels) ? longestText(this.ctx,this.font,this.yLabels) : 0;
1439
- },
1440
- addXLabel : function(label){
1441
- this.xLabels.push(label);
1442
- this.valuesCount++;
1443
- this.fit();
1444
- },
1445
- removeXLabel : function(){
1446
- this.xLabels.shift();
1447
- this.valuesCount--;
1448
- this.fit();
1449
- },
1450
- // Fitting loop to rotate x Labels and figure out what fits there, and also calculate how many Y steps to use
1451
- fit: function(){
1452
- // First we need the width of the yLabels, assuming the xLabels aren't rotated
1453
-
1454
- // To do that we need the base line at the top and base of the chart, assuming there is no x label rotation
1455
- this.startPoint = (this.display) ? this.fontSize : 0;
1456
- this.endPoint = (this.display) ? this.height - (this.fontSize * 1.5) - 5 : this.height; // -5 to pad labels
1457
-
1458
- // Apply padding settings to the start and end point.
1459
- this.startPoint += this.padding;
1460
- this.endPoint -= this.padding;
1461
-
1462
- // Cache the starting height, so can determine if we need to recalculate the scale yAxis
1463
- var cachedHeight = this.endPoint - this.startPoint,
1464
- cachedYLabelWidth;
1465
-
1466
- // Build the current yLabels so we have an idea of what size they'll be to start
1467
- /*
1468
- * This sets what is returned from calculateScaleRange as static properties of this class:
1469
- *
1470
- this.steps;
1471
- this.stepValue;
1472
- this.min;
1473
- this.max;
1474
- *
1475
- */
1476
- this.calculateYRange(cachedHeight);
1477
-
1478
- // With these properties set we can now build the array of yLabels
1479
- // and also the width of the largest yLabel
1480
- this.buildYLabels();
1481
-
1482
- this.calculateXLabelRotation();
1483
-
1484
- while((cachedHeight > this.endPoint - this.startPoint)){
1485
- cachedHeight = this.endPoint - this.startPoint;
1486
- cachedYLabelWidth = this.yLabelWidth;
1487
-
1488
- this.calculateYRange(cachedHeight);
1489
- this.buildYLabels();
1490
-
1491
- // Only go through the xLabel loop again if the yLabel width has changed
1492
- if (cachedYLabelWidth < this.yLabelWidth){
1493
- this.calculateXLabelRotation();
1494
- }
1495
- }
1496
-
1497
- },
1498
- calculateXLabelRotation : function(){
1499
- //Get the width of each grid by calculating the difference
1500
- //between x offsets between 0 and 1.
1501
-
1502
- this.ctx.font = this.font;
1503
-
1504
- var firstWidth = this.ctx.measureText(this.xLabels[0]).width,
1505
- lastWidth = this.ctx.measureText(this.xLabels[this.xLabels.length - 1]).width,
1506
- firstRotated,
1507
- lastRotated;
1508
-
1509
-
1510
- this.xScalePaddingRight = lastWidth/2 + 3;
1511
- this.xScalePaddingLeft = (firstWidth/2 > this.yLabelWidth + 10) ? firstWidth/2 : this.yLabelWidth + 10;
1512
-
1513
- this.xLabelRotation = 0;
1514
- if (this.display){
1515
- var originalLabelWidth = longestText(this.ctx,this.font,this.xLabels),
1516
- cosRotation,
1517
- firstRotatedWidth;
1518
- this.xLabelWidth = originalLabelWidth;
1519
- //Allow 3 pixels x2 padding either side for label readability
1520
- var xGridWidth = Math.floor(this.calculateX(1) - this.calculateX(0)) - 6;
1521
-
1522
- //Max label rotate should be 90 - also act as a loop counter
1523
- while ((this.xLabelWidth > xGridWidth && this.xLabelRotation === 0) || (this.xLabelWidth > xGridWidth && this.xLabelRotation <= 90 && this.xLabelRotation > 0)){
1524
- cosRotation = Math.cos(toRadians(this.xLabelRotation));
1525
-
1526
- firstRotated = cosRotation * firstWidth;
1527
- lastRotated = cosRotation * lastWidth;
1528
-
1529
- // We're right aligning the text now.
1530
- if (firstRotated + this.fontSize / 2 > this.yLabelWidth + 8){
1531
- this.xScalePaddingLeft = firstRotated + this.fontSize / 2;
1532
- }
1533
- this.xScalePaddingRight = this.fontSize/2;
1534
-
1535
-
1536
- this.xLabelRotation++;
1537
- this.xLabelWidth = cosRotation * originalLabelWidth;
1538
-
1539
- }
1540
- if (this.xLabelRotation > 0){
1541
- this.endPoint -= Math.sin(toRadians(this.xLabelRotation))*originalLabelWidth + 3;
1542
- }
1543
- }
1544
- else{
1545
- this.xLabelWidth = 0;
1546
- this.xScalePaddingRight = this.padding;
1547
- this.xScalePaddingLeft = this.padding;
1548
- }
1549
-
1550
- },
1551
- // Needs to be overidden in each Chart type
1552
- // Otherwise we need to pass all the data into the scale class
1553
- calculateYRange: noop,
1554
- drawingArea: function(){
1555
- return this.startPoint - this.endPoint;
1556
- },
1557
- calculateY : function(value){
1558
- var scalingFactor = this.drawingArea() / (this.min - this.max);
1559
- return this.endPoint - (scalingFactor * (value - this.min));
1560
- },
1561
- calculateX : function(index){
1562
- var isRotated = (this.xLabelRotation > 0),
1563
- // innerWidth = (this.offsetGridLines) ? this.width - offsetLeft - this.padding : this.width - (offsetLeft + halfLabelWidth * 2) - this.padding,
1564
- innerWidth = this.width - (this.xScalePaddingLeft + this.xScalePaddingRight),
1565
- valueWidth = innerWidth/(this.valuesCount - ((this.offsetGridLines) ? 0 : 1)),
1566
- valueOffset = (valueWidth * index) + this.xScalePaddingLeft;
1567
-
1568
- if (this.offsetGridLines){
1569
- valueOffset += (valueWidth/2);
1570
- }
1571
-
1572
- return Math.round(valueOffset);
1573
- },
1574
- update : function(newProps){
1575
- helpers.extend(this, newProps);
1576
- this.fit();
1577
- },
1578
- draw : function(){
1579
- var ctx = this.ctx,
1580
- yLabelGap = (this.endPoint - this.startPoint) / this.steps,
1581
- xStart = Math.round(this.xScalePaddingLeft);
1582
- if (this.display){
1583
- ctx.fillStyle = this.textColor;
1584
- ctx.font = this.font;
1585
- each(this.yLabels,function(labelString,index){
1586
- var yLabelCenter = this.endPoint - (yLabelGap * index),
1587
- linePositionY = Math.round(yLabelCenter);
1588
-
1589
- ctx.textAlign = "right";
1590
- ctx.textBaseline = "middle";
1591
- if (this.showLabels){
1592
- ctx.fillText(labelString,xStart - 10,yLabelCenter);
1593
- }
1594
- ctx.beginPath();
1595
- if (index > 0){
1596
- // This is a grid line in the centre, so drop that
1597
- ctx.lineWidth = this.gridLineWidth;
1598
- ctx.strokeStyle = this.gridLineColor;
1599
- } else {
1600
- // This is the first line on the scale
1601
- ctx.lineWidth = this.lineWidth;
1602
- ctx.strokeStyle = this.lineColor;
1603
- }
1604
-
1605
- linePositionY += helpers.aliasPixel(ctx.lineWidth);
1606
-
1607
- ctx.moveTo(xStart, linePositionY);
1608
- ctx.lineTo(this.width, linePositionY);
1609
- ctx.stroke();
1610
- ctx.closePath();
1611
-
1612
- ctx.lineWidth = this.lineWidth;
1613
- ctx.strokeStyle = this.lineColor;
1614
- ctx.beginPath();
1615
- ctx.moveTo(xStart - 5, linePositionY);
1616
- ctx.lineTo(xStart, linePositionY);
1617
- ctx.stroke();
1618
- ctx.closePath();
1619
-
1620
- },this);
1621
-
1622
- if(this.limitXLabels) {
1623
- var xDrawEvery = Math.round(this.xLabels.length / (this.limitXLabelsTo-1));
1624
- }
1625
- else {
1626
- var xDrawEvery = 1;
1627
- }
1628
-
1629
- each(this.xLabels,function(label,index){
1630
- var xPos = this.calculateX(index) + aliasPixel(this.lineWidth),
1631
- // Check to see if line/bar here and decide where to place the line
1632
- linePos = this.calculateX(index - (this.offsetGridLines ? 0.5 : 0)) + aliasPixel(this.lineWidth),
1633
- isRotated = (this.xLabelRotation > 0);
1634
-
1635
- ctx.beginPath();
1636
-
1637
- if (index > 0){
1638
- // This is a grid line in the centre, so drop that
1639
- ctx.lineWidth = this.gridLineWidth;
1640
- ctx.strokeStyle = this.gridLineColor;
1641
- } else {
1642
- // This is the first line on the scale
1643
- ctx.lineWidth = this.lineWidth;
1644
- ctx.strokeStyle = this.lineColor;
1645
- }
1646
- if(index == 0 || (index+1) % xDrawEvery == 0 || index == this.xLabels.length-1)
1647
- {
1648
- ctx.moveTo(linePos,this.endPoint);
1649
- ctx.lineTo(linePos,this.startPoint - 3);
1650
- ctx.stroke();
1651
- ctx.closePath();
1652
- }
1653
-
1654
- ctx.lineWidth = this.lineWidth;
1655
- ctx.strokeStyle = this.lineColor;
1656
-
1657
-
1658
- // Small lines at the bottom of the base grid line
1659
- ctx.beginPath();
1660
- ctx.moveTo(linePos,this.endPoint);
1661
- ctx.lineTo(linePos,this.endPoint + 5);
1662
- ctx.stroke();
1663
- ctx.closePath();
1664
-
1665
- ctx.save();
1666
- ctx.translate(xPos,(isRotated) ? this.endPoint + 12 : this.endPoint + 8);
1667
- ctx.rotate(toRadians(this.xLabelRotation)*-1);
1668
- ctx.font = this.font;
1669
- ctx.textAlign = (isRotated) ? "right" : "center";
1670
- ctx.textBaseline = (isRotated) ? "middle" : "top";
1671
- ctx.fillText(label, 0, 0);
1672
- ctx.restore();
1673
- },this);
1674
-
1675
- }
1676
- }
1677
-
1678
- });
1679
-
1680
- Chart.RadialScale = Chart.Element.extend({
1681
- initialize: function(){
1682
- this.size = min([this.height, this.width]);
1683
- this.drawingArea = (this.display) ? (this.size/2) - (this.fontSize/2 + this.backdropPaddingY) : (this.size/2);
1684
- },
1685
- calculateCenterOffset: function(value){
1686
- // Take into account half font size + the yPadding of the top value
1687
- var scalingFactor = this.drawingArea / (this.max - this.min);
1688
-
1689
- return (value - this.min) * scalingFactor;
1690
- },
1691
- update : function(){
1692
- if (!this.lineArc){
1693
- this.setScaleSize();
1694
- } else {
1695
- this.drawingArea = (this.display) ? (this.size/2) - (this.fontSize/2 + this.backdropPaddingY) : (this.size/2);
1696
- }
1697
- this.buildYLabels();
1698
- },
1699
- buildYLabels: function(){
1700
- this.yLabels = [];
1701
-
1702
- var stepDecimalPlaces = getDecimalPlaces(this.stepValue);
1703
-
1704
- for (var i=0; i<=this.steps; i++){
1705
- this.yLabels.push(template(this.templateString,{value:(this.min + (i * this.stepValue)).toFixed(stepDecimalPlaces)}));
1706
- }
1707
- },
1708
- getCircumference : function(){
1709
- return ((Math.PI*2) / this.valuesCount);
1710
- },
1711
- setScaleSize: function(){
1712
- /*
1713
- * Right, this is really confusing and there is a lot of maths going on here
1714
- * The gist of the problem is here: https://gist.github.com/nnnick/696cc9c55f4b0beb8fe9
1715
- *
1716
- * Reaction: https://dl.dropboxusercontent.com/u/34601363/toomuchscience.gif
1717
- *
1718
- * Solution:
1719
- *
1720
- * We assume the radius of the polygon is half the size of the canvas at first
1721
- * at each index we check if the text overlaps.
1722
- *
1723
- * Where it does, we store that angle and that index.
1724
- *
1725
- * After finding the largest index and angle we calculate how much we need to remove
1726
- * from the shape radius to move the point inwards by that x.
1727
- *
1728
- * We average the left and right distances to get the maximum shape radius that can fit in the box
1729
- * along with labels.
1730
- *
1731
- * Once we have that, we can find the centre point for the chart, by taking the x text protrusion
1732
- * on each side, removing that from the size, halving it and adding the left x protrusion width.
1733
- *
1734
- * This will mean we have a shape fitted to the canvas, as large as it can be with the labels
1735
- * and position it in the most space efficient manner
1736
- *
1737
- * https://dl.dropboxusercontent.com/u/34601363/yeahscience.gif
1738
- */
1739
-
1740
-
1741
- // Get maximum radius of the polygon. Either half the height (minus the text width) or half the width.
1742
- // Use this to calculate the offset + change. - Make sure L/R protrusion is at least 0 to stop issues with centre points
1743
- var largestPossibleRadius = min([(this.height/2 - this.pointLabelFontSize - 5), this.width/2]),
1744
- pointPosition,
1745
- i,
1746
- textWidth,
1747
- halfTextWidth,
1748
- furthestRight = this.width,
1749
- furthestRightIndex,
1750
- furthestRightAngle,
1751
- furthestLeft = 0,
1752
- furthestLeftIndex,
1753
- furthestLeftAngle,
1754
- xProtrusionLeft,
1755
- xProtrusionRight,
1756
- radiusReductionRight,
1757
- radiusReductionLeft,
1758
- maxWidthRadius;
1759
- this.ctx.font = fontString(this.pointLabelFontSize,this.pointLabelFontStyle,this.pointLabelFontFamily);
1760
- for (i=0;i<this.valuesCount;i++){
1761
- // 5px to space the text slightly out - similar to what we do in the draw function.
1762
- pointPosition = this.getPointPosition(i, largestPossibleRadius);
1763
- textWidth = this.ctx.measureText(template(this.templateString, { value: this.labels[i] })).width + 5;
1764
- if (i === 0 || i === this.valuesCount/2){
1765
- // If we're at index zero, or exactly the middle, we're at exactly the top/bottom
1766
- // of the radar chart, so text will be aligned centrally, so we'll half it and compare
1767
- // w/left and right text sizes
1768
- halfTextWidth = textWidth/2;
1769
- if (pointPosition.x + halfTextWidth > furthestRight) {
1770
- furthestRight = pointPosition.x + halfTextWidth;
1771
- furthestRightIndex = i;
1772
- }
1773
- if (pointPosition.x - halfTextWidth < furthestLeft) {
1774
- furthestLeft = pointPosition.x - halfTextWidth;
1775
- furthestLeftIndex = i;
1776
- }
1777
- }
1778
- else if (i < this.valuesCount/2) {
1779
- // Less than half the values means we'll left align the text
1780
- if (pointPosition.x + textWidth > furthestRight) {
1781
- furthestRight = pointPosition.x + textWidth;
1782
- furthestRightIndex = i;
1783
- }
1784
- }
1785
- else if (i > this.valuesCount/2){
1786
- // More than half the values means we'll right align the text
1787
- if (pointPosition.x - textWidth < furthestLeft) {
1788
- furthestLeft = pointPosition.x - textWidth;
1789
- furthestLeftIndex = i;
1790
- }
1791
- }
1792
- }
1793
-
1794
- xProtrusionLeft = furthestLeft;
1795
-
1796
- xProtrusionRight = Math.ceil(furthestRight - this.width);
1797
-
1798
- furthestRightAngle = this.getIndexAngle(furthestRightIndex);
1799
-
1800
- furthestLeftAngle = this.getIndexAngle(furthestLeftIndex);
1801
-
1802
- radiusReductionRight = xProtrusionRight / Math.sin(furthestRightAngle + Math.PI/2);
1803
-
1804
- radiusReductionLeft = xProtrusionLeft / Math.sin(furthestLeftAngle + Math.PI/2);
1805
-
1806
- // Ensure we actually need to reduce the size of the chart
1807
- radiusReductionRight = (isNumber(radiusReductionRight)) ? radiusReductionRight : 0;
1808
- radiusReductionLeft = (isNumber(radiusReductionLeft)) ? radiusReductionLeft : 0;
1809
-
1810
- this.drawingArea = largestPossibleRadius - (radiusReductionLeft + radiusReductionRight)/2;
1811
-
1812
- //this.drawingArea = min([maxWidthRadius, (this.height - (2 * (this.pointLabelFontSize + 5)))/2])
1813
- this.setCenterPoint(radiusReductionLeft, radiusReductionRight);
1814
-
1815
- },
1816
- setCenterPoint: function(leftMovement, rightMovement){
1817
-
1818
- var maxRight = this.width - rightMovement - this.drawingArea,
1819
- maxLeft = leftMovement + this.drawingArea;
1820
-
1821
- this.xCenter = (maxLeft + maxRight)/2;
1822
- // Always vertically in the centre as the text height doesn't change
1823
- this.yCenter = (this.height/2);
1824
- },
1825
-
1826
- getIndexAngle : function(index){
1827
- var angleMultiplier = (Math.PI * 2) / this.valuesCount;
1828
- // Start from the top instead of right, so remove a quarter of the circle
1829
-
1830
- return index * angleMultiplier - (Math.PI/2);
1831
- },
1832
- getPointPosition : function(index, distanceFromCenter){
1833
- var thisAngle = this.getIndexAngle(index);
1834
- return {
1835
- x : (Math.cos(thisAngle) * distanceFromCenter) + this.xCenter,
1836
- y : (Math.sin(thisAngle) * distanceFromCenter) + this.yCenter
1837
- };
1838
- },
1839
- draw: function(){
1840
- if (this.display){
1841
- var ctx = this.ctx;
1842
- each(this.yLabels, function(label, index){
1843
- // Don't draw a centre value
1844
- if (index > 0){
1845
- var yCenterOffset = index * (this.drawingArea/this.steps),
1846
- yHeight = this.yCenter - yCenterOffset,
1847
- pointPosition;
1848
-
1849
- // Draw circular lines around the scale
1850
- if (this.lineWidth > 0){
1851
- ctx.strokeStyle = this.lineColor;
1852
- ctx.lineWidth = this.lineWidth;
1853
-
1854
- if(this.lineArc){
1855
- ctx.beginPath();
1856
- ctx.arc(this.xCenter, this.yCenter, yCenterOffset, 0, Math.PI*2);
1857
- ctx.closePath();
1858
- ctx.stroke();
1859
- } else{
1860
- ctx.beginPath();
1861
- for (var i=0;i<this.valuesCount;i++)
1862
- {
1863
- pointPosition = this.getPointPosition(i, this.calculateCenterOffset(this.min + (index * this.stepValue)));
1864
- if (i === 0){
1865
- ctx.moveTo(pointPosition.x, pointPosition.y);
1866
- } else {
1867
- ctx.lineTo(pointPosition.x, pointPosition.y);
1868
- }
1869
- }
1870
- ctx.closePath();
1871
- ctx.stroke();
1872
- }
1873
- }
1874
- if(this.showLabels){
1875
- ctx.font = fontString(this.fontSize,this.fontStyle,this.fontFamily);
1876
- if (this.showLabelBackdrop){
1877
- var labelWidth = ctx.measureText(label).width;
1878
- ctx.fillStyle = this.backdropColor;
1879
- ctx.fillRect(
1880
- this.xCenter - labelWidth/2 - this.backdropPaddingX,
1881
- yHeight - this.fontSize/2 - this.backdropPaddingY,
1882
- labelWidth + this.backdropPaddingX*2,
1883
- this.fontSize + this.backdropPaddingY*2
1884
- );
1885
- }
1886
- ctx.textAlign = 'center';
1887
- ctx.textBaseline = "middle";
1888
- ctx.fillStyle = this.fontColor;
1889
- ctx.fillText(label, this.xCenter, yHeight);
1890
- }
1891
- }
1892
- }, this);
1893
-
1894
- if (!this.lineArc){
1895
- ctx.lineWidth = this.angleLineWidth;
1896
- ctx.strokeStyle = this.angleLineColor;
1897
- for (var i = this.valuesCount - 1; i >= 0; i--) {
1898
- if (this.angleLineWidth > 0){
1899
- var outerPosition = this.getPointPosition(i, this.calculateCenterOffset(this.max));
1900
- ctx.beginPath();
1901
- ctx.moveTo(this.xCenter, this.yCenter);
1902
- ctx.lineTo(outerPosition.x, outerPosition.y);
1903
- ctx.stroke();
1904
- ctx.closePath();
1905
- }
1906
- // Extra 3px out for some label spacing
1907
- var pointLabelPosition = this.getPointPosition(i, this.calculateCenterOffset(this.max) + 5);
1908
- ctx.font = fontString(this.pointLabelFontSize,this.pointLabelFontStyle,this.pointLabelFontFamily);
1909
- ctx.fillStyle = this.pointLabelFontColor;
1910
-
1911
- var labelsCount = this.labels.length,
1912
- halfLabelsCount = this.labels.length/2,
1913
- quarterLabelsCount = halfLabelsCount/2,
1914
- upperHalf = (i < quarterLabelsCount || i > labelsCount - quarterLabelsCount),
1915
- exactQuarter = (i === quarterLabelsCount || i === labelsCount - quarterLabelsCount);
1916
- if (i === 0){
1917
- ctx.textAlign = 'center';
1918
- } else if(i === halfLabelsCount){
1919
- ctx.textAlign = 'center';
1920
- } else if (i < halfLabelsCount){
1921
- ctx.textAlign = 'left';
1922
- } else {
1923
- ctx.textAlign = 'right';
1924
- }
1925
-
1926
- // Set the correct text baseline based on outer positioning
1927
- if (exactQuarter){
1928
- ctx.textBaseline = 'middle';
1929
- } else if (upperHalf){
1930
- ctx.textBaseline = 'bottom';
1931
- } else {
1932
- ctx.textBaseline = 'top';
1933
- }
1934
-
1935
- ctx.fillText(this.labels[i], pointLabelPosition.x, pointLabelPosition.y);
1936
- }
1937
- }
1938
- }
1939
- }
1940
- });
1941
-
1942
- // Attach global event to resize each chart instance when the browser resizes
1943
- helpers.addEvent(window, "resize", (function(){
1944
- // Basic debounce of resize function so it doesn't hurt performance when resizing browser.
1945
- var timeout;
1946
- return function(){
1947
- clearTimeout(timeout);
1948
- timeout = setTimeout(function(){
1949
- each(Chart.instances,function(instance){
1950
- // If the responsive flag is set in the chart instance config
1951
- // Cascade the resize event down to the chart.
1952
- if (instance.options.responsive){
1953
- instance.resize(instance.render, true);
1954
- }
1955
- });
1956
- }, 50);
1957
- };
1958
- })());
1959
-
1960
-
1961
- if (amd) {
1962
- define(function(){
1963
- return Chart;
1964
- });
1965
- } else if (typeof module === 'object' && module.exports) {
1966
- module.exports = Chart;
1967
- }
1968
-
1969
- root.Chart = Chart;
1970
-
1971
- Chart.noConflict = function(){
1972
- root.Chart = previous;
1973
- return Chart;
1974
- };
1975
-
1976
- }).call(this);
1977
-
1978
- (function(){
1979
- "use strict";
1980
-
1981
- var root = this,
1982
- Chart = root.Chart,
1983
- helpers = Chart.helpers;
1984
-
1985
-
1986
- var defaultConfig = {
1987
- //Boolean - Whether the scale should start at zero, or an order of magnitude down from the lowest value
1988
- scaleBeginAtZero : true,
1989
-
1990
- //Boolean - Whether grid lines are shown across the chart
1991
- scaleShowGridLines : true,
1992
-
1993
- //String - Colour of the grid lines
1994
- scaleGridLineColor : "rgba(0,0,0,.05)",
1995
-
1996
- //Number - Width of the grid lines
1997
- scaleGridLineWidth : 1,
1998
-
1999
- //Boolean - If there is a stroke on each bar
2000
- barShowStroke : true,
2001
-
2002
- //Number - Pixel width of the bar stroke
2003
- barStrokeWidth : 2,
2004
-
2005
- //Number - Spacing between each of the X value sets
2006
- barValueSpacing : 5,
2007
-
2008
- //Number - Spacing between data sets within X values
2009
- barDatasetSpacing : 1,
2010
-
2011
- //String - A legend template
2012
- legendTemplate : "<ul class=\"<%=name.toLowerCase()%>-legend\"><% for (var i=0; i<datasets.length; i++){%><li><span style=\"background-color:<%=datasets[i].fillColor%>\"></span><%if(datasets[i].label){%><%=datasets[i].label%><%}%></li><%}%></ul>"
2013
-
2014
- };
2015
-
2016
-
2017
- Chart.Type.extend({
2018
- name: "Bar",
2019
- defaults : defaultConfig,
2020
- initialize: function(data){
2021
-
2022
- //Expose options as a scope variable here so we can access it in the ScaleClass
2023
- var options = this.options;
2024
-
2025
- this.ScaleClass = Chart.Scale.extend({
2026
- offsetGridLines : true,
2027
- calculateBarX : function(datasetCount, datasetIndex, barIndex){
2028
- //Reusable method for calculating the xPosition of a given bar based on datasetIndex & width of the bar
2029
- var xWidth = this.calculateBaseWidth(),
2030
- xAbsolute = this.calculateX(barIndex) - (xWidth/2),
2031
- barWidth = this.calculateBarWidth(datasetCount);
2032
-
2033
- return xAbsolute + (barWidth * datasetIndex) + (datasetIndex * options.barDatasetSpacing) + barWidth/2;
2034
- },
2035
- calculateBaseWidth : function(){
2036
- return (this.calculateX(1) - this.calculateX(0)) - (2*options.barValueSpacing);
2037
- },
2038
- calculateBarWidth : function(datasetCount){
2039
- //The padding between datasets is to the right of each bar, providing that there are more than 1 dataset
2040
- var baseWidth = this.calculateBaseWidth() - ((datasetCount - 1) * options.barDatasetSpacing);
2041
-
2042
- return (baseWidth / datasetCount);
2043
- }
2044
- });
2045
-
2046
- this.datasets = [];
2047
-
2048
- //Set up tooltip events on the chart
2049
- if (this.options.showTooltips){
2050
- helpers.bindEvents(this, this.options.tooltipEvents, function(evt){
2051
- var activeBars = (evt.type !== 'mouseout') ? this.getBarsAtEvent(evt) : [];
2052
-
2053
- this.eachBars(function(bar){
2054
- bar.restore(['fillColor', 'strokeColor']);
2055
- });
2056
- helpers.each(activeBars, function(activeBar){
2057
- activeBar.fillColor = activeBar.highlightFill;
2058
- activeBar.strokeColor = activeBar.highlightStroke;
2059
- });
2060
- this.showTooltip(activeBars);
2061
- });
2062
- }
2063
-
2064
- //Declare the extension of the default point, to cater for the options passed in to the constructor
2065
- this.BarClass = Chart.Rectangle.extend({
2066
- strokeWidth : this.options.barStrokeWidth,
2067
- showStroke : this.options.barShowStroke,
2068
- ctx : this.chart.ctx
2069
- });
2070
-
2071
- //Iterate through each of the datasets, and build this into a property of the chart
2072
- helpers.each(data.datasets,function(dataset,datasetIndex){
2073
-
2074
- var datasetObject = {
2075
- label : dataset.label || null,
2076
- fillColor : dataset.fillColor,
2077
- strokeColor : dataset.strokeColor,
2078
- bars : []
2079
- };
2080
-
2081
- this.datasets.push(datasetObject);
2082
-
2083
- helpers.each(dataset.data,function(dataPoint,index){
2084
- //Add a new point for each piece of data, passing any required data to draw.
2085
- datasetObject.bars.push(new this.BarClass({
2086
- value : dataPoint,
2087
- label : data.labels[index],
2088
- datasetLabel: dataset.label,
2089
- strokeColor : dataset.strokeColor,
2090
- fillColor : dataset.fillColor,
2091
- highlightFill : dataset.highlightFill || dataset.fillColor,
2092
- highlightStroke : dataset.highlightStroke || dataset.strokeColor
2093
- }));
2094
- },this);
2095
-
2096
- },this);
2097
-
2098
- this.buildScale(data.labels);
2099
-
2100
- this.BarClass.prototype.base = this.scale.endPoint;
2101
-
2102
- this.eachBars(function(bar, index, datasetIndex){
2103
- helpers.extend(bar, {
2104
- width : this.scale.calculateBarWidth(this.datasets.length),
2105
- x: this.scale.calculateBarX(this.datasets.length, datasetIndex, index),
2106
- y: this.scale.endPoint
2107
- });
2108
- bar.save();
2109
- }, this);
2110
-
2111
- this.render();
2112
- },
2113
- update : function(){
2114
- this.scale.update();
2115
- // Reset any highlight colours before updating.
2116
- helpers.each(this.activeElements, function(activeElement){
2117
- activeElement.restore(['fillColor', 'strokeColor']);
2118
- });
2119
-
2120
- this.eachBars(function(bar){
2121
- bar.save();
2122
- });
2123
- this.render();
2124
- },
2125
- eachBars : function(callback){
2126
- helpers.each(this.datasets,function(dataset, datasetIndex){
2127
- helpers.each(dataset.bars, callback, this, datasetIndex);
2128
- },this);
2129
- },
2130
- getBarsAtEvent : function(e){
2131
- var barsArray = [],
2132
- eventPosition = helpers.getRelativePosition(e),
2133
- datasetIterator = function(dataset){
2134
- barsArray.push(dataset.bars[barIndex]);
2135
- },
2136
- barIndex;
2137
-
2138
- for (var datasetIndex = 0; datasetIndex < this.datasets.length; datasetIndex++) {
2139
- for (barIndex = 0; barIndex < this.datasets[datasetIndex].bars.length; barIndex++) {
2140
- if (this.datasets[datasetIndex].bars[barIndex].inRange(eventPosition.x,eventPosition.y)){
2141
- helpers.each(this.datasets, datasetIterator);
2142
- return barsArray;
2143
- }
2144
- }
2145
- }
2146
-
2147
- return barsArray;
2148
- },
2149
- buildScale : function(labels){
2150
- var self = this;
2151
-
2152
- var dataTotal = function(){
2153
- var values = [];
2154
- self.eachBars(function(bar){
2155
- values.push(bar.value);
2156
- });
2157
- return values;
2158
- };
2159
-
2160
- var scaleOptions = {
2161
- templateString : this.options.scaleLabel,
2162
- height : this.chart.height,
2163
- width : this.chart.width,
2164
- ctx : this.chart.ctx,
2165
- textColor : this.options.scaleFontColor,
2166
- fontSize : this.options.scaleFontSize,
2167
- fontStyle : this.options.scaleFontStyle,
2168
- fontFamily : this.options.scaleFontFamily,
2169
- valuesCount : labels.length,
2170
- beginAtZero : this.options.scaleBeginAtZero,
2171
- integersOnly : this.options.scaleIntegersOnly,
2172
- calculateYRange: function(currentHeight){
2173
- var updatedRanges = helpers.calculateScaleRange(
2174
- dataTotal(),
2175
- currentHeight,
2176
- this.fontSize,
2177
- this.beginAtZero,
2178
- this.integersOnly
2179
- );
2180
- helpers.extend(this, updatedRanges);
2181
- },
2182
- xLabels : labels,
2183
- limitXLabels: this.options.scaleLimitXLabels,
2184
- limitXLabelsTo: this.options.scaleLimitXLabelsTo,
2185
- font : helpers.fontString(this.options.scaleFontSize, this.options.scaleFontStyle, this.options.scaleFontFamily),
2186
- lineWidth : this.options.scaleLineWidth,
2187
- lineColor : this.options.scaleLineColor,
2188
- gridLineWidth : (this.options.scaleShowGridLines) ? this.options.scaleGridLineWidth : 0,
2189
- gridLineColor : (this.options.scaleShowGridLines) ? this.options.scaleGridLineColor : "rgba(0,0,0,0)",
2190
- padding : (this.options.showScale) ? 0 : (this.options.barShowStroke) ? this.options.barStrokeWidth : 0,
2191
- showLabels : this.options.scaleShowLabels,
2192
- display : this.options.showScale
2193
- };
2194
-
2195
- if (this.options.scaleOverride){
2196
- helpers.extend(scaleOptions, {
2197
- calculateYRange: helpers.noop,
2198
- steps: this.options.scaleSteps,
2199
- stepValue: this.options.scaleStepWidth,
2200
- min: this.options.scaleStartValue,
2201
- max: this.options.scaleStartValue + (this.options.scaleSteps * this.options.scaleStepWidth)
2202
- });
2203
- }
2204
-
2205
- this.scale = new this.ScaleClass(scaleOptions);
2206
- },
2207
- addData : function(valuesArray,label){
2208
- //Map the values array for each of the datasets
2209
- helpers.each(valuesArray,function(value,datasetIndex){
2210
- //Add a new point for each piece of data, passing any required data to draw.
2211
- this.datasets[datasetIndex].bars.push(new this.BarClass({
2212
- value : value,
2213
- label : label,
2214
- x: this.scale.calculateBarX(this.datasets.length, datasetIndex, this.scale.valuesCount+1),
2215
- y: this.scale.endPoint,
2216
- width : this.scale.calculateBarWidth(this.datasets.length),
2217
- base : this.scale.endPoint,
2218
- strokeColor : this.datasets[datasetIndex].strokeColor,
2219
- fillColor : this.datasets[datasetIndex].fillColor
2220
- }));
2221
- },this);
2222
-
2223
- this.scale.addXLabel(label);
2224
- //Then re-render the chart.
2225
- this.update();
2226
- },
2227
- removeData : function(){
2228
- this.scale.removeXLabel();
2229
- //Then re-render the chart.
2230
- helpers.each(this.datasets,function(dataset){
2231
- dataset.bars.shift();
2232
- },this);
2233
- this.update();
2234
- },
2235
- reflow : function(){
2236
- helpers.extend(this.BarClass.prototype,{
2237
- y: this.scale.endPoint,
2238
- base : this.scale.endPoint
2239
- });
2240
- var newScaleProps = helpers.extend({
2241
- height : this.chart.height,
2242
- width : this.chart.width
2243
- });
2244
- this.scale.update(newScaleProps);
2245
- },
2246
- draw : function(ease){
2247
- var easingDecimal = ease || 1;
2248
- this.clear();
2249
-
2250
- var ctx = this.chart.ctx;
2251
-
2252
- this.scale.draw(easingDecimal);
2253
-
2254
- //Draw all the bars for each dataset
2255
- helpers.each(this.datasets,function(dataset,datasetIndex){
2256
- helpers.each(dataset.bars,function(bar,index){
2257
- if (bar.hasValue()){
2258
- bar.base = this.scale.endPoint;
2259
- //Transition then draw
2260
- bar.transition({
2261
- x : this.scale.calculateBarX(this.datasets.length, datasetIndex, index),
2262
- y : this.scale.calculateY(bar.value),
2263
- width : this.scale.calculateBarWidth(this.datasets.length)
2264
- }, easingDecimal).draw();
2265
- }
2266
- },this);
2267
-
2268
- },this);
2269
- }
2270
- });
2271
-
2272
-
2273
- }).call(this);
2274
- (function(){
2275
- "use strict";
2276
-
2277
- var root = this,
2278
- Chart = root.Chart,
2279
- //Cache a local reference to Chart.helpers
2280
- helpers = Chart.helpers;
2281
-
2282
- var defaultConfig = {
2283
- //Boolean - Whether we should show a stroke on each segment
2284
- segmentShowStroke : true,
2285
-
2286
- //String - The colour of each segment stroke
2287
- segmentStrokeColor : "#fff",
2288
-
2289
- //Number - The width of each segment stroke
2290
- segmentStrokeWidth : 2,
2291
-
2292
- //The percentage of the chart that we cut out of the middle.
2293
- percentageInnerCutout : 50,
2294
-
2295
- //Number - Amount of animation steps
2296
- animationSteps : 100,
2297
-
2298
- //String - Animation easing effect
2299
- animationEasing : "easeOutBounce",
2300
-
2301
- //Boolean - Whether we animate the rotation of the Doughnut
2302
- animateRotate : true,
2303
-
2304
- //Boolean - Whether we animate scaling the Doughnut from the centre
2305
- animateScale : false,
2306
-
2307
- //String - A legend template
2308
- legendTemplate : "<ul class=\"<%=name.toLowerCase()%>-legend\"><% for (var i=0; i<segments.length; i++){%><li><span style=\"background-color:<%=segments[i].fillColor%>\"></span><%if(segments[i].label){%><%=segments[i].label%><%}%></li><%}%></ul>"
2309
-
2310
- };
2311
-
2312
-
2313
- Chart.Type.extend({
2314
- //Passing in a name registers this chart in the Chart namespace
2315
- name: "Doughnut",
2316
- //Providing a defaults will also register the deafults in the chart namespace
2317
- defaults : defaultConfig,
2318
- //Initialize is fired when the chart is initialized - Data is passed in as a parameter
2319
- //Config is automatically merged by the core of Chart.js, and is available at this.options
2320
- initialize: function(data){
2321
-
2322
- //Declare segments as a static property to prevent inheriting across the Chart type prototype
2323
- this.segments = [];
2324
- this.outerRadius = (helpers.min([this.chart.width,this.chart.height]) - this.options.segmentStrokeWidth/2)/2;
2325
-
2326
- this.SegmentArc = Chart.Arc.extend({
2327
- ctx : this.chart.ctx,
2328
- x : this.chart.width/2,
2329
- y : this.chart.height/2
2330
- });
2331
-
2332
- //Set up tooltip events on the chart
2333
- if (this.options.showTooltips){
2334
- helpers.bindEvents(this, this.options.tooltipEvents, function(evt){
2335
- var activeSegments = (evt.type !== 'mouseout') ? this.getSegmentsAtEvent(evt) : [];
2336
-
2337
- helpers.each(this.segments,function(segment){
2338
- segment.restore(["fillColor"]);
2339
- });
2340
- helpers.each(activeSegments,function(activeSegment){
2341
- activeSegment.fillColor = activeSegment.highlightColor;
2342
- });
2343
- this.showTooltip(activeSegments);
2344
- });
2345
- }
2346
- this.calculateTotal(data);
2347
-
2348
- helpers.each(data,function(datapoint, index){
2349
- this.addData(datapoint, index, true);
2350
- },this);
2351
-
2352
- this.render();
2353
- },
2354
- getSegmentsAtEvent : function(e){
2355
- var segmentsArray = [];
2356
-
2357
- var location = helpers.getRelativePosition(e);
2358
-
2359
- helpers.each(this.segments,function(segment){
2360
- if (segment.inRange(location.x,location.y)) segmentsArray.push(segment);
2361
- },this);
2362
- return segmentsArray;
2363
- },
2364
- addData : function(segment, atIndex, silent){
2365
- var index = atIndex || this.segments.length;
2366
- this.segments.splice(index, 0, new this.SegmentArc({
2367
- value : segment.value,
2368
- outerRadius : (this.options.animateScale) ? 0 : this.outerRadius,
2369
- innerRadius : (this.options.animateScale) ? 0 : (this.outerRadius/100) * this.options.percentageInnerCutout,
2370
- fillColor : segment.color,
2371
- highlightColor : segment.highlight || segment.color,
2372
- showStroke : this.options.segmentShowStroke,
2373
- strokeWidth : this.options.segmentStrokeWidth,
2374
- strokeColor : this.options.segmentStrokeColor,
2375
- startAngle : Math.PI * 1.5,
2376
- circumference : (this.options.animateRotate) ? 0 : this.calculateCircumference(segment.value),
2377
- label : segment.label
2378
- }));
2379
- if (!silent){
2380
- this.reflow();
2381
- this.update();
2382
- }
2383
- },
2384
- calculateCircumference : function(value) {
2385
- if ( this.total > 0 ) {
2386
- return (Math.PI*2)*(value / this.total);
2387
- } else {
2388
- return 0;
2389
- }
2390
- },
2391
- calculateTotal : function(data){
2392
- this.total = 0;
2393
- helpers.each(data,function(segment){
2394
- this.total += segment.value;
2395
- },this);
2396
- },
2397
- update : function(){
2398
- this.calculateTotal(this.segments);
2399
-
2400
- // Reset any highlight colours before updating.
2401
- helpers.each(this.activeElements, function(activeElement){
2402
- activeElement.restore(['fillColor']);
2403
- });
2404
-
2405
- helpers.each(this.segments,function(segment){
2406
- segment.save();
2407
- });
2408
- this.render();
2409
- },
2410
-
2411
- removeData: function(atIndex){
2412
- var indexToDelete = (helpers.isNumber(atIndex)) ? atIndex : this.segments.length-1;
2413
- this.segments.splice(indexToDelete, 1);
2414
- this.reflow();
2415
- this.update();
2416
- },
2417
-
2418
- reflow : function(){
2419
- helpers.extend(this.SegmentArc.prototype,{
2420
- x : this.chart.width/2,
2421
- y : this.chart.height/2
2422
- });
2423
- this.outerRadius = (helpers.min([this.chart.width,this.chart.height]) - this.options.segmentStrokeWidth/2)/2;
2424
- helpers.each(this.segments, function(segment){
2425
- segment.update({
2426
- outerRadius : this.outerRadius,
2427
- innerRadius : (this.outerRadius/100) * this.options.percentageInnerCutout
2428
- });
2429
- }, this);
2430
- },
2431
- draw : function(easeDecimal){
2432
- var animDecimal = (easeDecimal) ? easeDecimal : 1;
2433
- this.clear();
2434
- helpers.each(this.segments,function(segment,index){
2435
- segment.transition({
2436
- circumference : this.calculateCircumference(segment.value),
2437
- outerRadius : this.outerRadius,
2438
- innerRadius : (this.outerRadius/100) * this.options.percentageInnerCutout
2439
- },animDecimal);
2440
-
2441
- segment.endAngle = segment.startAngle + segment.circumference;
2442
-
2443
- segment.draw();
2444
- if (index === 0){
2445
- segment.startAngle = Math.PI * 1.5;
2446
- }
2447
- //Check to see if it's the last segment, if not get the next and update the start angle
2448
- if (index < this.segments.length-1){
2449
- this.segments[index+1].startAngle = segment.endAngle;
2450
- }
2451
- },this);
2452
-
2453
- }
2454
- });
2455
-
2456
- Chart.types.Doughnut.extend({
2457
- name : "Pie",
2458
- defaults : helpers.merge(defaultConfig,{percentageInnerCutout : 0})
2459
- });
2460
-
2461
- }).call(this);
2462
-
2463
- (function(){
2464
- "use strict";
2465
-
2466
- var root = this,
2467
- Chart = root.Chart,
2468
- helpers = Chart.helpers;
2469
-
2470
- var defaultConfig = {
2471
-
2472
- ///Boolean - Whether grid lines are shown across the chart
2473
- scaleShowGridLines : true,
2474
-
2475
- //String - Colour of the grid lines
2476
- scaleGridLineColor : "rgba(0,0,0,.05)",
2477
-
2478
- //Number - Width of the grid lines
2479
- scaleGridLineWidth : 1,
2480
-
2481
- //Boolean - Whether the line is curved between points
2482
- bezierCurve : true,
2483
-
2484
- //Number - Tension of the bezier curve between points
2485
- bezierCurveTension : 0.4,
2486
-
2487
- //Boolean - Whether to show a dot for each point
2488
- pointDot : true,
2489
-
2490
- //Number - Radius of each point dot in pixels
2491
- pointDotRadius : 4,
2492
-
2493
- //Number - Pixel width of point dot stroke
2494
- pointDotStrokeWidth : 1,
2495
-
2496
- //Number - amount extra to add to the radius to cater for hit detection outside the drawn point
2497
- pointHitDetectionRadius : 0,
2498
-
2499
- //Boolean - Whether to show a stroke for datasets
2500
- datasetStroke : true,
2501
-
2502
- //Number - Pixel width of dataset stroke
2503
- datasetStrokeWidth : 2,
2504
-
2505
- //Boolean - Whether to fill the dataset with a colour
2506
- datasetFill : true,
2507
-
2508
- //String - A legend template
2509
- legendTemplate : "<ul class=\"<%=name.toLowerCase()%>-legend\"><% for (var i=0; i<datasets.length; i++){%><li><span style=\"background-color:<%=datasets[i].strokeColor%>\"></span><%if(datasets[i].label){%><%=datasets[i].label%><%}%></li><%}%></ul>"
2510
-
2511
- };
2512
-
2513
-
2514
- Chart.Type.extend({
2515
- name: "Line",
2516
- defaults : defaultConfig,
2517
- initialize: function(data){
2518
- //Declare the extension of the default point, to cater for the options passed in to the constructor
2519
- this.PointClass = Chart.Point.extend({
2520
- strokeWidth : this.options.pointDotStrokeWidth,
2521
- radius : this.options.pointDotRadius,
2522
- display: this.options.pointDot,
2523
- hitDetectionRadius : this.options.pointHitDetectionRadius,
2524
- ctx : this.chart.ctx,
2525
- inRange : function(mouseX){
2526
- return (Math.pow(mouseX-this.x, 2) < Math.pow(this.radius + this.hitDetectionRadius,2));
2527
- }
2528
- });
2529
-
2530
- this.datasets = [];
2531
-
2532
- //Set up tooltip events on the chart
2533
- if (this.options.showTooltips){
2534
- helpers.bindEvents(this, this.options.tooltipEvents, function(evt){
2535
- var activePoints = (evt.type !== 'mouseout') ? this.getPointsAtEvent(evt) : [];
2536
- this.eachPoints(function(point){
2537
- point.restore(['fillColor', 'strokeColor']);
2538
- });
2539
- helpers.each(activePoints, function(activePoint){
2540
- activePoint.fillColor = activePoint.highlightFill;
2541
- activePoint.strokeColor = activePoint.highlightStroke;
2542
- });
2543
- this.showTooltip(activePoints);
2544
- });
2545
- }
2546
-
2547
- //Iterate through each of the datasets, and build this into a property of the chart
2548
- helpers.each(data.datasets,function(dataset){
2549
-
2550
- var datasetObject = {
2551
- label : dataset.label || null,
2552
- fillColor : dataset.fillColor,
2553
- strokeColor : dataset.strokeColor,
2554
- pointColor : dataset.pointColor,
2555
- pointStrokeColor : dataset.pointStrokeColor,
2556
- points : []
2557
- };
2558
-
2559
- this.datasets.push(datasetObject);
2560
-
2561
-
2562
- helpers.each(dataset.data,function(dataPoint,index){
2563
- //Add a new point for each piece of data, passing any required data to draw.
2564
- datasetObject.points.push(new this.PointClass({
2565
- value : dataPoint,
2566
- label : data.labels[index],
2567
- datasetLabel: dataset.label,
2568
- strokeColor : dataset.pointStrokeColor,
2569
- fillColor : dataset.pointColor,
2570
- highlightFill : dataset.pointHighlightFill || dataset.pointColor,
2571
- highlightStroke : dataset.pointHighlightStroke || dataset.pointStrokeColor
2572
- }));
2573
- },this);
2574
-
2575
- this.buildScale(data.labels);
2576
-
2577
-
2578
- this.eachPoints(function(point, index){
2579
- helpers.extend(point, {
2580
- x: this.scale.calculateX(index),
2581
- y: this.scale.endPoint
2582
- });
2583
- point.save();
2584
- }, this);
2585
-
2586
- },this);
2587
-
2588
-
2589
- this.render();
2590
- },
2591
- update : function(){
2592
- this.scale.update();
2593
- // Reset any highlight colours before updating.
2594
- helpers.each(this.activeElements, function(activeElement){
2595
- activeElement.restore(['fillColor', 'strokeColor']);
2596
- });
2597
- this.eachPoints(function(point){
2598
- point.save();
2599
- });
2600
- this.render();
2601
- },
2602
- eachPoints : function(callback){
2603
- helpers.each(this.datasets,function(dataset){
2604
- helpers.each(dataset.points,callback,this);
2605
- },this);
2606
- },
2607
- getPointsAtEvent : function(e){
2608
- var pointsArray = [],
2609
- eventPosition = helpers.getRelativePosition(e);
2610
- helpers.each(this.datasets,function(dataset){
2611
- helpers.each(dataset.points,function(point){
2612
- if (point.inRange(eventPosition.x,eventPosition.y)) pointsArray.push(point);
2613
- });
2614
- },this);
2615
- return pointsArray;
2616
- },
2617
- buildScale : function(labels){
2618
- var self = this;
2619
-
2620
- var dataTotal = function(){
2621
- var values = [];
2622
- self.eachPoints(function(point){
2623
- values.push(point.value);
2624
- });
2625
-
2626
- return values;
2627
- };
2628
-
2629
- var scaleOptions = {
2630
- templateString : this.options.scaleLabel,
2631
- height : this.chart.height,
2632
- width : this.chart.width,
2633
- ctx : this.chart.ctx,
2634
- textColor : this.options.scaleFontColor,
2635
- fontSize : this.options.scaleFontSize,
2636
- fontStyle : this.options.scaleFontStyle,
2637
- fontFamily : this.options.scaleFontFamily,
2638
- valuesCount : labels.length,
2639
- beginAtZero : this.options.scaleBeginAtZero,
2640
- integersOnly : this.options.scaleIntegersOnly,
2641
- calculateYRange : function(currentHeight){
2642
- var updatedRanges = helpers.calculateScaleRange(
2643
- dataTotal(),
2644
- currentHeight,
2645
- this.fontSize,
2646
- this.beginAtZero,
2647
- this.integersOnly
2648
- );
2649
- helpers.extend(this, updatedRanges);
2650
- },
2651
- xLabels : labels,
2652
- limitXLabels: this.options.scaleLimitXLabels,
2653
- limitXLabelsTo: this.options.scaleLimitXLabelsTo,
2654
- font : helpers.fontString(this.options.scaleFontSize, this.options.scaleFontStyle, this.options.scaleFontFamily),
2655
- lineWidth : this.options.scaleLineWidth,
2656
- lineColor : this.options.scaleLineColor,
2657
- gridLineWidth : (this.options.scaleShowGridLines) ? this.options.scaleGridLineWidth : 0,
2658
- gridLineColor : (this.options.scaleShowGridLines) ? this.options.scaleGridLineColor : "rgba(0,0,0,0)",
2659
- padding: (this.options.showScale) ? 0 : this.options.pointDotRadius + this.options.pointDotStrokeWidth,
2660
- showLabels : this.options.scaleShowLabels,
2661
- display : this.options.showScale
2662
- };
2663
-
2664
- if (this.options.scaleOverride){
2665
- helpers.extend(scaleOptions, {
2666
- calculateYRange: helpers.noop,
2667
- steps: this.options.scaleSteps,
2668
- stepValue: this.options.scaleStepWidth,
2669
- min: this.options.scaleStartValue,
2670
- max: this.options.scaleStartValue + (this.options.scaleSteps * this.options.scaleStepWidth)
2671
- });
2672
- }
2673
-
2674
-
2675
- this.scale = new Chart.Scale(scaleOptions);
2676
- },
2677
- addData : function(valuesArray,label){
2678
- //Map the values array for each of the datasets
2679
-
2680
- helpers.each(valuesArray,function(value,datasetIndex){
2681
- //Add a new point for each piece of data, passing any required data to draw.
2682
- this.datasets[datasetIndex].points.push(new this.PointClass({
2683
- value : value,
2684
- label : label,
2685
- x: this.scale.calculateX(this.scale.valuesCount+1),
2686
- y: this.scale.endPoint,
2687
- strokeColor : this.datasets[datasetIndex].pointStrokeColor,
2688
- fillColor : this.datasets[datasetIndex].pointColor
2689
- }));
2690
- },this);
2691
-
2692
- this.scale.addXLabel(label);
2693
- //Then re-render the chart.
2694
- this.update();
2695
- },
2696
- removeData : function(){
2697
- this.scale.removeXLabel();
2698
- //Then re-render the chart.
2699
- helpers.each(this.datasets,function(dataset){
2700
- dataset.points.shift();
2701
- },this);
2702
- this.update();
2703
- },
2704
- reflow : function(){
2705
- var newScaleProps = helpers.extend({
2706
- height : this.chart.height,
2707
- width : this.chart.width
2708
- });
2709
- this.scale.update(newScaleProps);
2710
- },
2711
- draw : function(ease){
2712
- var easingDecimal = ease || 1;
2713
- this.clear();
2714
-
2715
- var ctx = this.chart.ctx;
2716
-
2717
- // Some helper methods for getting the next/prev points
2718
- var hasValue = function(item){
2719
- return item.value !== null;
2720
- },
2721
- nextPoint = function(point, collection, index){
2722
- return helpers.findNextWhere(collection, hasValue, index) || point;
2723
- },
2724
- previousPoint = function(point, collection, index){
2725
- return helpers.findPreviousWhere(collection, hasValue, index) || point;
2726
- };
2727
-
2728
- this.scale.draw(easingDecimal);
2729
-
2730
-
2731
- helpers.each(this.datasets,function(dataset){
2732
- var pointsWithValues = helpers.where(dataset.points, hasValue);
2733
-
2734
- //Transition each point first so that the line and point drawing isn't out of sync
2735
- //We can use this extra loop to calculate the control points of this dataset also in this loop
2736
-
2737
- helpers.each(dataset.points, function(point, index){
2738
- if (point.hasValue()){
2739
- point.transition({
2740
- y : this.scale.calculateY(point.value),
2741
- x : this.scale.calculateX(index)
2742
- }, easingDecimal);
2743
- }
2744
- },this);
2745
-
2746
-
2747
- // Control points need to be calculated in a seperate loop, because we need to know the current x/y of the point
2748
- // This would cause issues when there is no animation, because the y of the next point would be 0, so beziers would be skewed
2749
- if (this.options.bezierCurve){
2750
- helpers.each(pointsWithValues, function(point, index){
2751
- var tension = (index > 0 && index < pointsWithValues.length - 1) ? this.options.bezierCurveTension : 0;
2752
- point.controlPoints = helpers.splineCurve(
2753
- previousPoint(point, pointsWithValues, index),
2754
- point,
2755
- nextPoint(point, pointsWithValues, index),
2756
- tension
2757
- );
2758
-
2759
- // Prevent the bezier going outside of the bounds of the graph
2760
-
2761
- // Cap puter bezier handles to the upper/lower scale bounds
2762
- if (point.controlPoints.outer.y > this.scale.endPoint){
2763
- point.controlPoints.outer.y = this.scale.endPoint;
2764
- }
2765
- else if (point.controlPoints.outer.y < this.scale.startPoint){
2766
- point.controlPoints.outer.y = this.scale.startPoint;
2767
- }
2768
-
2769
- // Cap inner bezier handles to the upper/lower scale bounds
2770
- if (point.controlPoints.inner.y > this.scale.endPoint){
2771
- point.controlPoints.inner.y = this.scale.endPoint;
2772
- }
2773
- else if (point.controlPoints.inner.y < this.scale.startPoint){
2774
- point.controlPoints.inner.y = this.scale.startPoint;
2775
- }
2776
- },this);
2777
- }
2778
-
2779
-
2780
- //Draw the line between all the points
2781
- ctx.lineWidth = this.options.datasetStrokeWidth;
2782
- ctx.strokeStyle = dataset.strokeColor;
2783
- ctx.beginPath();
2784
-
2785
- helpers.each(pointsWithValues, function(point, index){
2786
- if (index === 0){
2787
- ctx.moveTo(point.x, point.y);
2788
- }
2789
- else{
2790
- if(this.options.bezierCurve){
2791
- var previous = previousPoint(point, pointsWithValues, index);
2792
-
2793
- ctx.bezierCurveTo(
2794
- previous.controlPoints.outer.x,
2795
- previous.controlPoints.outer.y,
2796
- point.controlPoints.inner.x,
2797
- point.controlPoints.inner.y,
2798
- point.x,
2799
- point.y
2800
- );
2801
- }
2802
- else{
2803
- ctx.lineTo(point.x,point.y);
2804
- }
2805
- }
2806
- }, this);
2807
-
2808
- ctx.stroke();
2809
-
2810
- if (this.options.datasetFill && pointsWithValues.length > 0){
2811
- //Round off the line by going to the base of the chart, back to the start, then fill.
2812
- ctx.lineTo(pointsWithValues[pointsWithValues.length - 1].x, this.scale.endPoint);
2813
- ctx.lineTo(pointsWithValues[0].x, this.scale.endPoint);
2814
- ctx.fillStyle = dataset.fillColor;
2815
- ctx.closePath();
2816
- ctx.fill();
2817
- }
2818
-
2819
- //Now draw the points over the line
2820
- //A little inefficient double looping, but better than the line
2821
- //lagging behind the point positions
2822
- helpers.each(pointsWithValues,function(point){
2823
- point.draw();
2824
- });
2825
- },this);
2826
- }
2827
- });
2828
-
2829
-
2830
- }).call(this);
2831
- (function(){
2832
- "use strict";
2833
-
2834
- var root = this,
2835
- Chart = root.Chart,
2836
- //Cache a local reference to Chart.helpers
2837
- helpers = Chart.helpers;
2838
-
2839
- var defaultConfig = {
2840
- //Boolean - Show a backdrop to the scale label
2841
- scaleShowLabelBackdrop : true,
2842
-
2843
- //String - The colour of the label backdrop
2844
- scaleBackdropColor : "rgba(255,255,255,0.75)",
2845
-
2846
- // Boolean - Whether the scale should begin at zero
2847
- scaleBeginAtZero : true,
2848
-
2849
- //Number - The backdrop padding above & below the label in pixels
2850
- scaleBackdropPaddingY : 2,
2851
-
2852
- //Number - The backdrop padding to the side of the label in pixels
2853
- scaleBackdropPaddingX : 2,
2854
-
2855
- //Boolean - Show line for each value in the scale
2856
- scaleShowLine : true,
2857
-
2858
- //Boolean - Stroke a line around each segment in the chart
2859
- segmentShowStroke : true,
2860
-
2861
- //String - The colour of the stroke on each segement.
2862
- segmentStrokeColor : "#fff",
2863
-
2864
- //Number - The width of the stroke value in pixels
2865
- segmentStrokeWidth : 2,
2866
-
2867
- //Number - Amount of animation steps
2868
- animationSteps : 100,
2869
-
2870
- //String - Animation easing effect.
2871
- animationEasing : "easeOutBounce",
2872
-
2873
- //Boolean - Whether to animate the rotation of the chart
2874
- animateRotate : true,
2875
-
2876
- //Boolean - Whether to animate scaling the chart from the centre
2877
- animateScale : false,
2878
-
2879
- //String - A legend template
2880
- legendTemplate : "<ul class=\"<%=name.toLowerCase()%>-legend\"><% for (var i=0; i<segments.length; i++){%><li><span style=\"background-color:<%=segments[i].fillColor%>\"></span><%if(segments[i].label){%><%=segments[i].label%><%}%></li><%}%></ul>"
2881
- };
2882
-
2883
-
2884
- Chart.Type.extend({
2885
- //Passing in a name registers this chart in the Chart namespace
2886
- name: "PolarArea",
2887
- //Providing a defaults will also register the deafults in the chart namespace
2888
- defaults : defaultConfig,
2889
- //Initialize is fired when the chart is initialized - Data is passed in as a parameter
2890
- //Config is automatically merged by the core of Chart.js, and is available at this.options
2891
- initialize: function(data){
2892
- this.segments = [];
2893
- //Declare segment class as a chart instance specific class, so it can share props for this instance
2894
- this.SegmentArc = Chart.Arc.extend({
2895
- showStroke : this.options.segmentShowStroke,
2896
- strokeWidth : this.options.segmentStrokeWidth,
2897
- strokeColor : this.options.segmentStrokeColor,
2898
- ctx : this.chart.ctx,
2899
- innerRadius : 0,
2900
- x : this.chart.width/2,
2901
- y : this.chart.height/2
2902
- });
2903
- this.scale = new Chart.RadialScale({
2904
- display: this.options.showScale,
2905
- fontStyle: this.options.scaleFontStyle,
2906
- fontSize: this.options.scaleFontSize,
2907
- fontFamily: this.options.scaleFontFamily,
2908
- fontColor: this.options.scaleFontColor,
2909
- showLabels: this.options.scaleShowLabels,
2910
- showLabelBackdrop: this.options.scaleShowLabelBackdrop,
2911
- backdropColor: this.options.scaleBackdropColor,
2912
- backdropPaddingY : this.options.scaleBackdropPaddingY,
2913
- backdropPaddingX: this.options.scaleBackdropPaddingX,
2914
- lineWidth: (this.options.scaleShowLine) ? this.options.scaleLineWidth : 0,
2915
- lineColor: this.options.scaleLineColor,
2916
- lineArc: true,
2917
- width: this.chart.width,
2918
- height: this.chart.height,
2919
- xCenter: this.chart.width/2,
2920
- yCenter: this.chart.height/2,
2921
- ctx : this.chart.ctx,
2922
- templateString: this.options.scaleLabel,
2923
- valuesCount: data.length
2924
- });
2925
-
2926
- this.updateScaleRange(data);
2927
-
2928
- this.scale.update();
2929
-
2930
- helpers.each(data,function(segment,index){
2931
- this.addData(segment,index,true);
2932
- },this);
2933
-
2934
- //Set up tooltip events on the chart
2935
- if (this.options.showTooltips){
2936
- helpers.bindEvents(this, this.options.tooltipEvents, function(evt){
2937
- var activeSegments = (evt.type !== 'mouseout') ? this.getSegmentsAtEvent(evt) : [];
2938
- helpers.each(this.segments,function(segment){
2939
- segment.restore(["fillColor"]);
2940
- });
2941
- helpers.each(activeSegments,function(activeSegment){
2942
- activeSegment.fillColor = activeSegment.highlightColor;
2943
- });
2944
- this.showTooltip(activeSegments);
2945
- });
2946
- }
2947
-
2948
- this.render();
2949
- },
2950
- getSegmentsAtEvent : function(e){
2951
- var segmentsArray = [];
2952
-
2953
- var location = helpers.getRelativePosition(e);
2954
-
2955
- helpers.each(this.segments,function(segment){
2956
- if (segment.inRange(location.x,location.y)) segmentsArray.push(segment);
2957
- },this);
2958
- return segmentsArray;
2959
- },
2960
- addData : function(segment, atIndex, silent){
2961
- var index = atIndex || this.segments.length;
2962
-
2963
- this.segments.splice(index, 0, new this.SegmentArc({
2964
- fillColor: segment.color,
2965
- highlightColor: segment.highlight || segment.color,
2966
- label: segment.label,
2967
- value: segment.value,
2968
- outerRadius: (this.options.animateScale) ? 0 : this.scale.calculateCenterOffset(segment.value),
2969
- circumference: (this.options.animateRotate) ? 0 : this.scale.getCircumference(),
2970
- startAngle: Math.PI * 1.5
2971
- }));
2972
- if (!silent){
2973
- this.reflow();
2974
- this.update();
2975
- }
2976
- },
2977
- removeData: function(atIndex){
2978
- var indexToDelete = (helpers.isNumber(atIndex)) ? atIndex : this.segments.length-1;
2979
- this.segments.splice(indexToDelete, 1);
2980
- this.reflow();
2981
- this.update();
2982
- },
2983
- calculateTotal: function(data){
2984
- this.total = 0;
2985
- helpers.each(data,function(segment){
2986
- this.total += segment.value;
2987
- },this);
2988
- this.scale.valuesCount = this.segments.length;
2989
- },
2990
- updateScaleRange: function(datapoints){
2991
- var valuesArray = [];
2992
- helpers.each(datapoints,function(segment){
2993
- valuesArray.push(segment.value);
2994
- });
2995
-
2996
- var scaleSizes = (this.options.scaleOverride) ?
2997
- {
2998
- steps: this.options.scaleSteps,
2999
- stepValue: this.options.scaleStepWidth,
3000
- min: this.options.scaleStartValue,
3001
- max: this.options.scaleStartValue + (this.options.scaleSteps * this.options.scaleStepWidth)
3002
- } :
3003
- helpers.calculateScaleRange(
3004
- valuesArray,
3005
- helpers.min([this.chart.width, this.chart.height])/2,
3006
- this.options.scaleFontSize,
3007
- this.options.scaleBeginAtZero,
3008
- this.options.scaleIntegersOnly
3009
- );
3010
-
3011
- helpers.extend(
3012
- this.scale,
3013
- scaleSizes,
3014
- {
3015
- size: helpers.min([this.chart.width, this.chart.height]),
3016
- xCenter: this.chart.width/2,
3017
- yCenter: this.chart.height/2
3018
- }
3019
- );
3020
-
3021
- },
3022
- update : function(){
3023
- this.calculateTotal(this.segments);
3024
-
3025
- helpers.each(this.segments,function(segment){
3026
- segment.save();
3027
- });
3028
- this.render();
3029
- },
3030
- reflow : function(){
3031
- helpers.extend(this.SegmentArc.prototype,{
3032
- x : this.chart.width/2,
3033
- y : this.chart.height/2
3034
- });
3035
- this.updateScaleRange(this.segments);
3036
- this.scale.update();
3037
-
3038
- helpers.extend(this.scale,{
3039
- xCenter: this.chart.width/2,
3040
- yCenter: this.chart.height/2
3041
- });
3042
-
3043
- helpers.each(this.segments, function(segment){
3044
- segment.update({
3045
- outerRadius : this.scale.calculateCenterOffset(segment.value)
3046
- });
3047
- }, this);
3048
-
3049
- },
3050
- draw : function(ease){
3051
- var easingDecimal = ease || 1;
3052
- //Clear & draw the canvas
3053
- this.clear();
3054
- helpers.each(this.segments,function(segment, index){
3055
- segment.transition({
3056
- circumference : this.scale.getCircumference(),
3057
- outerRadius : this.scale.calculateCenterOffset(segment.value)
3058
- },easingDecimal);
3059
-
3060
- segment.endAngle = segment.startAngle + segment.circumference;
3061
-
3062
- // If we've removed the first segment we need to set the first one to
3063
- // start at the top.
3064
- if (index === 0){
3065
- segment.startAngle = Math.PI * 1.5;
3066
- }
3067
-
3068
- //Check to see if it's the last segment, if not get the next and update the start angle
3069
- if (index < this.segments.length - 1){
3070
- this.segments[index+1].startAngle = segment.endAngle;
3071
- }
3072
- segment.draw();
3073
- }, this);
3074
- this.scale.draw();
3075
- }
3076
- });
3077
-
3078
- }).call(this);
3079
- (function(){
3080
- "use strict";
3081
-
3082
- var root = this,
3083
- Chart = root.Chart,
3084
- helpers = Chart.helpers;
3085
-
3086
-
3087
-
3088
- Chart.Type.extend({
3089
- name: "Radar",
3090
- defaults:{
3091
- //Boolean - Whether to show lines for each scale point
3092
- scaleShowLine : true,
3093
-
3094
- //Boolean - Whether we show the angle lines out of the radar
3095
- angleShowLineOut : true,
3096
-
3097
- //Boolean - Whether to show labels on the scale
3098
- scaleShowLabels : false,
3099
-
3100
- // Boolean - Whether the scale should begin at zero
3101
- scaleBeginAtZero : true,
3102
-
3103
- //String - Colour of the angle line
3104
- angleLineColor : "rgba(0,0,0,.1)",
3105
-
3106
- //Number - Pixel width of the angle line
3107
- angleLineWidth : 1,
3108
-
3109
- //String - Point label font declaration
3110
- pointLabelFontFamily : "'Arial'",
3111
-
3112
- //String - Point label font weight
3113
- pointLabelFontStyle : "normal",
3114
-
3115
- //Number - Point label font size in pixels
3116
- pointLabelFontSize : 10,
3117
-
3118
- //String - Point label font colour
3119
- pointLabelFontColor : "#666",
3120
-
3121
- //Boolean - Whether to show a dot for each point
3122
- pointDot : true,
3123
-
3124
- //Number - Radius of each point dot in pixels
3125
- pointDotRadius : 3,
3126
-
3127
- //Number - Pixel width of point dot stroke
3128
- pointDotStrokeWidth : 1,
3129
-
3130
- //Number - amount extra to add to the radius to cater for hit detection outside the drawn point
3131
- pointHitDetectionRadius : 20,
3132
-
3133
- //Boolean - Whether to show a stroke for datasets
3134
- datasetStroke : true,
3135
-
3136
- //Number - Pixel width of dataset stroke
3137
- datasetStrokeWidth : 2,
3138
-
3139
- //Boolean - Whether to fill the dataset with a colour
3140
- datasetFill : true,
3141
-
3142
- //String - A legend template
3143
- legendTemplate : "<ul class=\"<%=name.toLowerCase()%>-legend\"><% for (var i=0; i<datasets.length; i++){%><li><span style=\"background-color:<%=datasets[i].strokeColor%>\"></span><%if(datasets[i].label){%><%=datasets[i].label%><%}%></li><%}%></ul>"
3144
-
3145
- },
3146
-
3147
- initialize: function(data){
3148
- this.PointClass = Chart.Point.extend({
3149
- strokeWidth : this.options.pointDotStrokeWidth,
3150
- radius : this.options.pointDotRadius,
3151
- display: this.options.pointDot,
3152
- hitDetectionRadius : this.options.pointHitDetectionRadius,
3153
- ctx : this.chart.ctx
3154
- });
3155
-
3156
- this.datasets = [];
3157
-
3158
- this.buildScale(data);
3159
-
3160
- //Set up tooltip events on the chart
3161
- if (this.options.showTooltips){
3162
- helpers.bindEvents(this, this.options.tooltipEvents, function(evt){
3163
- var activePointsCollection = (evt.type !== 'mouseout') ? this.getPointsAtEvent(evt) : [];
3164
-
3165
- this.eachPoints(function(point){
3166
- point.restore(['fillColor', 'strokeColor']);
3167
- });
3168
- helpers.each(activePointsCollection, function(activePoint){
3169
- activePoint.fillColor = activePoint.highlightFill;
3170
- activePoint.strokeColor = activePoint.highlightStroke;
3171
- });
3172
-
3173
- this.showTooltip(activePointsCollection);
3174
- });
3175
- }
3176
-
3177
- //Iterate through each of the datasets, and build this into a property of the chart
3178
- helpers.each(data.datasets,function(dataset){
3179
-
3180
- var datasetObject = {
3181
- label: dataset.label || null,
3182
- fillColor : dataset.fillColor,
3183
- strokeColor : dataset.strokeColor,
3184
- pointColor : dataset.pointColor,
3185
- pointStrokeColor : dataset.pointStrokeColor,
3186
- points : []
3187
- };
3188
-
3189
- this.datasets.push(datasetObject);
3190
-
3191
- helpers.each(dataset.data,function(dataPoint,index){
3192
- //Add a new point for each piece of data, passing any required data to draw.
3193
- var pointPosition;
3194
- if (!this.scale.animation){
3195
- pointPosition = this.scale.getPointPosition(index, this.scale.calculateCenterOffset(dataPoint));
3196
- }
3197
- datasetObject.points.push(new this.PointClass({
3198
- value : dataPoint,
3199
- label : data.labels[index],
3200
- datasetLabel: dataset.label,
3201
- x: (this.options.animation) ? this.scale.xCenter : pointPosition.x,
3202
- y: (this.options.animation) ? this.scale.yCenter : pointPosition.y,
3203
- strokeColor : dataset.pointStrokeColor,
3204
- fillColor : dataset.pointColor,
3205
- highlightFill : dataset.pointHighlightFill || dataset.pointColor,
3206
- highlightStroke : dataset.pointHighlightStroke || dataset.pointStrokeColor
3207
- }));
3208
- },this);
3209
-
3210
- },this);
3211
-
3212
- this.render();
3213
- },
3214
- eachPoints : function(callback){
3215
- helpers.each(this.datasets,function(dataset){
3216
- helpers.each(dataset.points,callback,this);
3217
- },this);
3218
- },
3219
-
3220
- getPointsAtEvent : function(evt){
3221
- var mousePosition = helpers.getRelativePosition(evt),
3222
- fromCenter = helpers.getAngleFromPoint({
3223
- x: this.scale.xCenter,
3224
- y: this.scale.yCenter
3225
- }, mousePosition);
3226
-
3227
- var anglePerIndex = (Math.PI * 2) /this.scale.valuesCount,
3228
- pointIndex = Math.round((fromCenter.angle - Math.PI * 1.5) / anglePerIndex),
3229
- activePointsCollection = [];
3230
-
3231
- // If we're at the top, make the pointIndex 0 to get the first of the array.
3232
- if (pointIndex >= this.scale.valuesCount || pointIndex < 0){
3233
- pointIndex = 0;
3234
- }
3235
-
3236
- if (fromCenter.distance <= this.scale.drawingArea){
3237
- helpers.each(this.datasets, function(dataset){
3238
- activePointsCollection.push(dataset.points[pointIndex]);
3239
- });
3240
- }
3241
-
3242
- return activePointsCollection;
3243
- },
3244
-
3245
- buildScale : function(data){
3246
- this.scale = new Chart.RadialScale({
3247
- display: this.options.showScale,
3248
- fontStyle: this.options.scaleFontStyle,
3249
- fontSize: this.options.scaleFontSize,
3250
- fontFamily: this.options.scaleFontFamily,
3251
- fontColor: this.options.scaleFontColor,
3252
- showLabels: this.options.scaleShowLabels,
3253
- showLabelBackdrop: this.options.scaleShowLabelBackdrop,
3254
- backdropColor: this.options.scaleBackdropColor,
3255
- backdropPaddingY : this.options.scaleBackdropPaddingY,
3256
- backdropPaddingX: this.options.scaleBackdropPaddingX,
3257
- lineWidth: (this.options.scaleShowLine) ? this.options.scaleLineWidth : 0,
3258
- lineColor: this.options.scaleLineColor,
3259
- angleLineColor : this.options.angleLineColor,
3260
- angleLineWidth : (this.options.angleShowLineOut) ? this.options.angleLineWidth : 0,
3261
- // Point labels at the edge of each line
3262
- pointLabelFontColor : this.options.pointLabelFontColor,
3263
- pointLabelFontSize : this.options.pointLabelFontSize,
3264
- pointLabelFontFamily : this.options.pointLabelFontFamily,
3265
- pointLabelFontStyle : this.options.pointLabelFontStyle,
3266
- height : this.chart.height,
3267
- width: this.chart.width,
3268
- xCenter: this.chart.width/2,
3269
- yCenter: this.chart.height/2,
3270
- ctx : this.chart.ctx,
3271
- templateString: this.options.scaleLabel,
3272
- labels: data.labels,
3273
- valuesCount: data.datasets[0].data.length
3274
- });
3275
-
3276
- this.scale.setScaleSize();
3277
- this.updateScaleRange(data.datasets);
3278
- this.scale.buildYLabels();
3279
- },
3280
- updateScaleRange: function(datasets){
3281
- var valuesArray = (function(){
3282
- var totalDataArray = [];
3283
- helpers.each(datasets,function(dataset){
3284
- if (dataset.data){
3285
- totalDataArray = totalDataArray.concat(dataset.data);
3286
- }
3287
- else {
3288
- helpers.each(dataset.points, function(point){
3289
- totalDataArray.push(point.value);
3290
- });
3291
- }
3292
- });
3293
- return totalDataArray;
3294
- })();
3295
-
3296
-
3297
- var scaleSizes = (this.options.scaleOverride) ?
3298
- {
3299
- steps: this.options.scaleSteps,
3300
- stepValue: this.options.scaleStepWidth,
3301
- min: this.options.scaleStartValue,
3302
- max: this.options.scaleStartValue + (this.options.scaleSteps * this.options.scaleStepWidth)
3303
- } :
3304
- helpers.calculateScaleRange(
3305
- valuesArray,
3306
- helpers.min([this.chart.width, this.chart.height])/2,
3307
- this.options.scaleFontSize,
3308
- this.options.scaleBeginAtZero,
3309
- this.options.scaleIntegersOnly
3310
- );
3311
-
3312
- helpers.extend(
3313
- this.scale,
3314
- scaleSizes
3315
- );
3316
-
3317
- },
3318
- addData : function(valuesArray,label){
3319
- //Map the values array for each of the datasets
3320
- this.scale.valuesCount++;
3321
- helpers.each(valuesArray,function(value,datasetIndex){
3322
- var pointPosition = this.scale.getPointPosition(this.scale.valuesCount, this.scale.calculateCenterOffset(value));
3323
- this.datasets[datasetIndex].points.push(new this.PointClass({
3324
- value : value,
3325
- label : label,
3326
- x: pointPosition.x,
3327
- y: pointPosition.y,
3328
- strokeColor : this.datasets[datasetIndex].pointStrokeColor,
3329
- fillColor : this.datasets[datasetIndex].pointColor
3330
- }));
3331
- },this);
3332
-
3333
- this.scale.labels.push(label);
3334
-
3335
- this.reflow();
3336
-
3337
- this.update();
3338
- },
3339
- removeData : function(){
3340
- this.scale.valuesCount--;
3341
- this.scale.labels.shift();
3342
- helpers.each(this.datasets,function(dataset){
3343
- dataset.points.shift();
3344
- },this);
3345
- this.reflow();
3346
- this.update();
3347
- },
3348
- update : function(){
3349
- this.eachPoints(function(point){
3350
- point.save();
3351
- });
3352
- this.reflow();
3353
- this.render();
3354
- },
3355
- reflow: function(){
3356
- helpers.extend(this.scale, {
3357
- width : this.chart.width,
3358
- height: this.chart.height,
3359
- size : helpers.min([this.chart.width, this.chart.height]),
3360
- xCenter: this.chart.width/2,
3361
- yCenter: this.chart.height/2
3362
- });
3363
- this.updateScaleRange(this.datasets);
3364
- this.scale.setScaleSize();
3365
- this.scale.buildYLabels();
3366
- },
3367
- draw : function(ease){
3368
- var easeDecimal = ease || 1,
3369
- ctx = this.chart.ctx;
3370
- this.clear();
3371
- this.scale.draw();
3372
-
3373
- helpers.each(this.datasets,function(dataset){
3374
-
3375
- //Transition each point first so that the line and point drawing isn't out of sync
3376
- helpers.each(dataset.points,function(point,index){
3377
- if (point.hasValue()){
3378
- point.transition(this.scale.getPointPosition(index, this.scale.calculateCenterOffset(point.value)), easeDecimal);
3379
- }
3380
- },this);
3381
-
3382
-
3383
-
3384
- //Draw the line between all the points
3385
- ctx.lineWidth = this.options.datasetStrokeWidth;
3386
- ctx.strokeStyle = dataset.strokeColor;
3387
- ctx.beginPath();
3388
- helpers.each(dataset.points,function(point,index){
3389
- if (index === 0){
3390
- ctx.moveTo(point.x,point.y);
3391
- }
3392
- else{
3393
- ctx.lineTo(point.x,point.y);
3394
- }
3395
- },this);
3396
- ctx.closePath();
3397
- ctx.stroke();
3398
-
3399
- ctx.fillStyle = dataset.fillColor;
3400
- ctx.fill();
3401
-
3402
- //Now draw the points over the line
3403
- //A little inefficient double looping, but better than the line
3404
- //lagging behind the point positions
3405
- helpers.each(dataset.points,function(point){
3406
- if (point.hasValue()){
3407
- point.draw();
3408
- }
3409
- });
3410
-
3411
- },this);
3412
-
3413
- }
3414
-
3415
- });
3416
-
3417
-
3418
-
3419
-
3420
-
3421
- }).call(this);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
addons/stats/assets/js/index.php DELETED
@@ -1,3 +0,0 @@
1
- <?php
2
- // Silence is golden.
3
- ?>
 
 
 
addons/stats/includes/classes/class.query-stats.php DELETED
@@ -1,27 +0,0 @@
1
- <?php
2
- if ( ! defined( 'myCRED_VERSION' ) ) exit;
3
-
4
- /**
5
- * Query Statistics
6
- * @see http://codex.mycred.me/classes/mycred_query_stats/
7
- * @since 1.7
8
- * @version 1.0
9
- */
10
- if ( ! class_exists( 'myCRED_Query_Stats' ) ) :
11
- class myCRED_Query_Stats {
12
-
13
- protected $db = '';
14
-
15
- /**
16
- * Construct
17
- */
18
- public function __construct() {
19
-
20
- global $mycred;
21
-
22
- $this->db = $mycred->log_table;
23
-
24
- }
25
-
26
- }
27
- endif;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
addons/stats/includes/classes/index.php DELETED
@@ -1,3 +0,0 @@
1
- <?php
2
- // Silence is golden.
3
- ?>
 
 
 
addons/stats/includes/index.php DELETED
@@ -1,3 +0,0 @@
1
- <?php
2
- // Silence is golden.
3
- ?>
 
 
 
addons/stats/includes/mycred-stats-functions.php DELETED
@@ -1,199 +0,0 @@
1
- <?php
2
- if ( ! defined( 'myCRED_STATS_VERSION' ) ) exit;
3
-
4
- /**
5
- * Get Stats Days
6
- * @since 1.6
7
- * @version 1.0
8
- */
9
- if ( ! function_exists( 'mycred_get_stat_dates' ) ) :
10
- function mycred_get_stat_dates( $instance = '', $value = 0 ) {
11
-
12
- $now = current_time( 'timestamp' );
13
-
14
- $results = array();
15
- switch ( $instance ) {
16
-
17
- case 'x_dates' :
18
-
19
- $from = $value - 1;
20
- $start = date( 'U', strtotime( '-' . $from . ' days midnight', $now ) );
21
- for ( $i = 0 ; $i < $value ; $i ++ ) {
22
- if ( $i == 0 )
23
- $new_start = $start;
24
- else
25
- $new_start = $start + ( 86400 * $i );
26
-
27
- $results[] = array(
28
- 'label' => date( 'Y-m-d', $new_start ),
29
- 'from' => $new_start,
30
- 'until' => ( $new_start + 86399 )
31
- );
32
- }
33
-
34
- break;
35
-
36
- case 'today_this' :
37
-
38
- $start = date( 'U', strtotime( 'today midnight', $now ) );
39
- $results[] = array(
40
- 'key' => 'today',
41
- 'from' => $start,
42
- 'until' => $now
43
- );
44
-
45
- $this_week = mktime( 0, 0, 0, date( "n", $now ), date( "j", $now ) - date( "N", $now ) + 1 );
46
- $results[] = array(
47
- 'key' => 'thisweek',
48
- 'from' => $this_week,
49
- 'until' => $now
50
- );
51
-
52
- $this_month = mktime( 0, 0, 0, date( "n", $now ), 1, date( 'Y', $now ) );
53
- $results[] = array(
54
- 'key' => 'thismonth',
55
- 'from' => $this_month,
56
- 'until' => $now
57
- );
58
-
59
- $this_year = mktime( 0, 0, 0, 1, 1, date( 'Y', $now ) );
60
- $results[] = array(
61
- 'key' => 'thisyear',
62
- 'from' => $this_year,
63
- 'until' => $now
64
- );
65
-
66
- break;
67
-
68
- }
69
- return $results;
70
-
71
- }
72
- endif;
73
-
74
- /**
75
- * Get Type Color
76
- * @since 1.6
77
- * @version 1.0
78
- */
79
- if ( ! function_exists( 'mycred_get_type_color' ) ) :
80
- function mycred_get_type_color( $type = NULL ) {
81
-
82
- //$set = array( 'rgba(221,73,167,1)', 'rgba(106,187,218,1)', 'rgba(111,70,161,1)' );
83
- //$set = array( 'rgba(213,78,33,1)', 'rgba(46,162,204,1)', 'rgba(34,34,34,1)' );
84
- $set = array( 'rgba(204,175,11,1)', 'rgba(221,130,59,1)', 'rgba(207,73,68,1)', 'rgba(180,60,56,1)', 'rgba(34,34,34,1)' );
85
- $types = mycred_get_types();
86
- $saved = mycred_get_option( 'mycred-point-colors', $set );
87
-
88
- $colors = array();
89
- $row = 0;
90
- foreach ( $types as $type_id => $label ) {
91
-
92
- if ( array_key_exists( $type_id, $saved ) )
93
- $value = $saved[ $type_id ];
94
- else
95
- $value = $set[ $row ];
96
-
97
- $colors[ $type_id ] = $value;
98
- $row ++;
99
-
100
- }
101
-
102
- $result = $colors;
103
- if ( $type !== NULL && array_key_exists( $type, $colors ) )
104
- $result = $colors[ $type ];
105
-
106
- return apply_filters( 'mycred_point_type_colors', $result, $set, $type, $types );
107
-
108
- }
109
- endif;
110
-
111
- /**
112
- * RGB to HEX
113
- * @since 1.6
114
- * @version 1.0
115
- */
116
- if ( ! function_exists( 'mycred_rgb_to_hex' ) ) :
117
- function mycred_rgb_to_hex( $rgb = '' ) {
118
-
119
- if ( ! is_array( $rgb ) ) {
120
- $rgb = str_replace( array( ' ', 'rgb(', 'rgba(', ')' ), '', $rgb );
121
- $rgb = explode( ',', $rgb );
122
- }
123
-
124
- $hex = "#";
125
- $hex .= str_pad( dechex( $rgb[0] ), 2, "0", STR_PAD_LEFT );
126
- $hex .= str_pad( dechex( $rgb[1] ), 2, "0", STR_PAD_LEFT );
127
- $hex .= str_pad( dechex( $rgb[2] ), 2, "0", STR_PAD_LEFT );
128
-
129
- return $hex;
130
- }
131
- endif;
132
-
133
- /**
134
- * HEX to RGB
135
- * @since 1.6
136
- * @version 1.0
137
- */
138
- if ( ! function_exists( 'mycred_hex_to_rgb' ) ) :
139
- function mycred_hex_to_rgb( $hex = '', $rgba = true ) {
140
-
141
- $hex = str_replace( '#', '', $hex );
142
-
143
- if ( strlen( $hex ) == 3 ) {
144
- $r = hexdec( substr( $hex, 0, 1 ) . substr( $hex, 0, 1 ) );
145
- $g = hexdec( substr( $hex, 1, 1 ) . substr( $hex, 1, 1 ) );
146
- $b = hexdec( substr( $hex, 2, 1 ) . substr( $hex, 2, 1 ) );
147
- } else {
148
- $r = hexdec( substr( $hex, 0, 2 ) );
149
- $g = hexdec( substr( $hex, 2, 2 ) );
150
- $b = hexdec( substr( $hex, 4, 2 ) );
151
- }
152
- $rgb = array( $r, $g, $b );
153
-
154
- if ( $rgba )
155
- $rgb = 'rgba(' . implode( ',', $rgb ) . ',1)';
156
- else
157
- $rgb = 'rgb(' . implode( ',', $rgb ) . ')';
158
-
159
- return $rgb;
160
-
161
- }
162
- endif;
163
-
164
- /**
165
- * Inverse HEX colors
166
- * @since 1.6
167
- * @version 1.0
168
- */
169
- if ( ! function_exists( 'mycred_inverse_hex_color' ) ) :
170
- function mycred_inverse_hex_color( $color = '' ) {
171
-
172
- $color = str_replace( '#', '', $color );
173
- if ( strlen( $color ) != 6 ) { return '000000'; }
174
- $rgb = '';
175
- for ( $x = 0 ; $x < 3 ; $x++ ) {
176
- $c = 255 - hexdec( substr( $color, ( 2*$x ), 2 ) );
177
- $c = ( $c < 0 ) ? 0 : dechex( $c );
178
- $rgb .= ( strlen( $c ) < 2 ) ? '0' . $c : $c;
179
- }
180
- return '#' . $rgb;
181
-
182
- }
183
- endif;
184
-
185
- /**
186
- * Inverse RGB color
187
- * @since 1.6
188
- * @version 1.0
189
- */
190
- if ( ! function_exists( 'mycred_inverse_rgb_color' ) ) :
191
- function mycred_inverse_rgb_color( $color = '' ) {
192
-
193
- $color = mycred_rgb_to_hex( $color );
194
- $inversed = mycred_inverse_hex_color( $color );
195
- $inversed = mycred_hex_to_rgb( $inversed );
196
- return $inversed;
197
-
198
- }
199
- endif;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
addons/stats/includes/mycred-stats-shortcodes.php DELETED
@@ -1,35 +0,0 @@
1
- <?php
2
- if ( ! defined( 'myCRED_STATS_VERSION' ) ) exit;
3
-
4
- /**
5
- * Shortcode: myCRED Statistics
6
- * @since 1.6.8
7
- * @version 1.0
8
- */
9
- if ( ! function_exists( 'mycred_statistics_shortcode_render' ) ) :
10
- function mycred_statistics_shortcode_render( $atts ) {
11
-
12
- extract( shortcode_atts( array(
13
- 'id' => 'overallcirculation',
14
- 'show' => 'total',
15
- 'ctype' => '',
16
- 'chart' => 'lines'
17
- ), $atts ) );
18
-
19
- global $mycred_load_stats;
20
-
21
- $mycred_load_stats = true;
22
-
23
- $args = array();
24
-
25
- ob_start();
26
-
27
-
28
-
29
- $content = ob_get_contents();
30
- ob_end_clean();
31
-
32
- return $content;
33
-
34
- }
35
- endif;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
addons/stats/index.php DELETED
@@ -1,3 +0,0 @@
1
- <?php
2
- // Silence is golden.
3
- ?>
 
 
 
addons/stats/myCRED-addon-stats.php DELETED
@@ -1,452 +0,0 @@
1
- <?php
2
- /**
3
- * Addon: Stats
4
- * Addon URI: http://mycred.me/add-ons/stats/
5
- * Version: 1.2.1
6
- */
7
- if ( ! defined( 'myCRED_VERSION' ) ) exit;
8
-
9
- define( 'myCRED_STATS', __FILE__ );
10
- define( 'myCRED_STATS_VERSION', '1.2.1' );
11
- define( 'myCRED_STATS_DIR', myCRED_ADDONS_DIR . 'stats/' );
12
- define( 'myCRED_STATS_WIDGETS_DIR', myCRED_STATS_DIR . 'widgets/' );
13
-
14
- /**
15
- * Required Files
16
- */
17
- require_once myCRED_STATS_DIR . 'includes/mycred-stats-functions.php';
18
- require_once myCRED_STATS_DIR . 'includes/mycred-stats-shortcodes.php';
19
-
20
- require_once myCRED_STATS_DIR . 'includes/classes/class.query-stats.php';
21
-
22
- require_once myCRED_STATS_DIR . 'abstracts/mycred-abstract-stat-widget.php';
23
-
24
- /**
25
- * Core Widgets
26
- */
27
- require_once myCRED_STATS_WIDGETS_DIR . 'mycred-stats-widget-circulation.php';
28
- require_once myCRED_STATS_WIDGETS_DIR . 'mycred-stats-widget-daily-gains.php';
29
- require_once myCRED_STATS_WIDGETS_DIR . 'mycred-stats-widget-daily-loses.php';
30
-
31
- do_action( 'mycred_stats_load_widgets' );
32
-
33
- /**
34
- * myCRED_Stats_Module class
35
- * @since 1.6
36
- * @version 1.1
37
- */
38
- if ( ! class_exists( 'myCRED_Stats_Module' ) ) :
39
- class myCRED_Stats_Module extends myCRED_Module {
40
-
41
- public $user;
42
- public $screen;
43
- public $ctypes;
44
- public $colors;
45
-
46
- /**
47
- * Construct
48
- */
49
- function __construct( $type = MYCRED_DEFAULT_TYPE_KEY ) {
50
-
51
- parent::__construct( 'myCRED_Stats_Module', array(
52
- 'module_name' => 'stats',
53
- 'accordion' => false,
54
- 'register' => false,
55
- 'add_to_core' => false
56
- ), $type );
57
-
58
- $this->label = sprintf( '%s %s', mycred_label(), __( 'Statistics', 'mycred' ) );
59
- $this->colors = mycred_get_type_color();
60
-
61
- }
62
-
63
- /**
64
- * Init
65
- * @since 1.6
66
- * @version 1.0.1
67
- */
68
- public function module_init() {
69
-
70
- global $mycred_types, $mycred_load_stats;
71
-
72
- $mycred_load_stats = false;
73
-
74
- // Scripts & Styles
75
- add_action( 'mycred_front_enqueue', array( $this, 'register_scripts' ), 30 );
76
- add_action( 'admin_enqueue_scripts', array( $this, 'register_scripts' ) );
77
- add_action( 'wp_footer', array( $this, 'load_front_scripts' ), 5 );
78
-
79
- // Add shortcode
80
- add_shortcode( 'mycred_statistics', 'mycred_statistics_shortcode_render' );
81
-
82
- // Add color options to each point type
83
- add_action( 'mycred_core_prefs', array( $this, 'color_settings' ) );
84
- add_filter( 'mycred_save_core_prefs', array( $this, 'sanitize_extra_settings' ), 10, 3 );
85
- foreach ( $mycred_types as $type_id => $type ) {
86
-
87
- if ( $type_id === MYCRED_DEFAULT_TYPE_KEY ) continue;
88
-
89
- add_action( 'mycred_core_prefs' . $type_id, array( $this, 'color_settings' ) );
90
- add_filter( 'mycred_save_core_prefs' . $type_id, array( $this, 'sanitize_extra_settings' ), 10, 3 );
91
-
92
- }
93
-
94
- // Add admin screen
95
- add_action( 'admin_menu', array( $this, 'add_menu' ) );
96
-
97
- }
98
-
99
- /**
100
- * Register Front Scripts
101
- * @since 1.6
102
- * @version 1.1
103
- */
104
- public function register_scripts() {
105
-
106
- // Stylesheets
107
- wp_register_style(
108
- 'mycred-stats',
109
- plugins_url( 'assets/css/mycred-statistics.css', myCRED_STATS ),
110
- array(),
111
- '1.1',
112
- 'all'
113
- );
114
-
115
- // Stylesheets
116
- wp_register_style(
117
- 'mycred-stats-admin',
118
- plugins_url( 'assets/css/mycred-statistics-admin.css', myCRED_STATS ),
119
- array(),
120
- myCRED_STATS_VERSION,
121
- 'all'
122
- );
123
-
124
- // Scripts
125
- wp_register_script(
126
- 'chart-js',
127
- plugins_url( 'assets/js/Chart.js', myCRED_STATS ),
128
- array( 'jquery' ),
129
- myCRED_STATS_VERSION,
130
- true
131
- );
132
-
133
- }
134
-
135
- /**
136
- * Admin Screen Styles
137
- * @since 1.6.8
138
- * @version 1.1
139
- */
140
- public function load_front_scripts() {
141
-
142
- global $mycred_load_stats;
143
-
144
- if ( $mycred_load_stats === true ) {
145
-
146
- wp_enqueue_style( 'mycred-stats' );
147
- wp_enqueue_script( 'chart-js' );
148
-
149
- }
150
-
151
- }
152
-
153
- /**
154
- * Color Settings
155
- * @since 1.7
156
- * @version 1.0
157
- */
158
- public function color_settings( $settings ) {
159
-
160
- $colors = mycred_get_type_color( $settings->mycred_type );
161
- if ( ! is_array( $colors ) ) {
162
- $colors = array(
163
- 'positive' => mycred_rgb_to_hex( $colors ),
164
- 'negative' => ''
165
- );
166
- $colors['negative'] = mycred_inverse_hex_color( $colors['positive'] );
167
- }
168
- elseif ( is_array( $colors ) && $colors['positive'] != '' && $colors['negative'] == '' )
169
- $colors['negative'] = mycred_rgb_to_hex( $colors );
170
-
171
- ?>
172
- <h3><?php _e( 'Statistics Color', 'mycred' ); ?></h3>
173
- <div class="row">
174
- <div class="col-lg-6 col-md-6 col-sm-12 col-xs-12">
175
- <div class="form-group">
176
- <label for="<?php echo $settings->field_id( array( 'colors' => 'positive' ) ); ?>"><?php _e( 'Positive Values', 'mycred' ); ?></label>
177
- <input type="text" name="<?php echo $settings->field_name( array( 'colors' => 'positive' ) ); ?>" id="<?php echo $settings->field_id( array( 'colors' => 'positive' ) ); ?>" value="<?php echo esc_attr( $colors['positive'] ); ?>" class="wp-color-picker-field" data-default-color="#dedede" />
178
- </div>
179
- </div>
180
- <div class="col-lg-6 col-md-6 col-sm-12 col-xs-12">
181
- <div class="form-group">
182
- <label for="<?php echo $settings->field_id( array( 'colors' => 'negative' ) ); ?>"><?php _e( 'Negative Values', 'mycred' ); ?></label>
183
- <input type="text" name="<?php echo $settings->field_name( array( 'colors' => 'negative' ) ); ?>" id="<?php echo $settings->field_id( array( 'colors' => 'negative' ) ); ?>" value="<?php echo esc_attr( $colors['negative'] ); ?>" class="wp-color-picker-field" data-default-color="" />
184
- </div>
185
- </div>
186
- </div>
187
- <script type="text/javascript">
188
- jQuery(document).ready(function($){
189
-
190
- // Load wp color picker
191
- $( '.wp-color-picker-field' ).wpColorPicker();
192
-
193
- });
194
- </script>
195
- <?php
196
-
197
- }
198
-
199
- /**
200
- * Sanitize & Save Settings
201
- * @since 1.7
202
- * @version 1.0.1
203
- */
204
- public function sanitize_extra_settings( $new_data, $data, $general ) {
205
-
206
- if ( array_key_exists( 'colors', $data ) ) {
207
-
208
- $colors = array();
209
- $colors['positive'] = sanitize_text_field( $data['colors']['positive'] );
210
- $colors['negative'] = sanitize_text_field( $data['colors']['negative'] );
211
-
212
- $saved = mycred_get_type_color();
213
- $saved[ $general->mycred_type ] = $colors;
214
-
215
- mycred_update_option( 'mycred-point-colors', $saved );
216
-
217
- }
218
-
219
- if ( array_key_exists( 'colors', $new_data ) )
220
- unset( $new_data['colors'] );
221
-
222
- return $new_data;
223
-
224
- }
225
-
226
- /**
227
- * Add Menu
228
- * @since 1.6
229
- * @version 1.0
230
- */
231
- public function add_menu() {
232
-
233
- $page = add_dashboard_page(
234
- $this->label,
235
- $this->label,
236
- $this->core->edit_creds_cap(),
237
- 'mycred-stats',
238
- array( $this, 'admin_page' )
239
- );
240
-
241
- add_action( 'admin_print_styles-' . $page, array( $this, 'admin_page_header' ) );
242
-
243
- }
244
-
245
- public function get_tabs() {
246
-
247
- $tabs = array();
248
- $tabs['overview'] = __( 'Overview', 'mycred' );
249
-
250
- foreach ( $this->point_types as $type_id => $label ) {
251
- $mycred = mycred( $type_id );
252
- $tabs[ 'view_' . $type_id ] = $mycred->plural();
253
- }
254
-
255
- return apply_filters( 'mycred_statistics_tabs', $tabs );
256
-
257
- }
258
-
259
- /**
260
- * Admin Page Header
261
- * @since 1.6
262
- * @version 1.1
263
- */
264
- public function admin_page_header() {
265
-
266
- wp_enqueue_style( 'mycred-stats' );
267
- wp_enqueue_style( 'mycred-stats-admin' );
268
- wp_enqueue_script( 'chart-js' );
269
-
270
- do_action( 'mycred_stats_page_header', $this );
271
-
272
- }
273
-
274
- /**
275
- * Has Entries
276
- * @since 1.6
277
- * @version 1.0
278
- */
279
- public function has_entries() {
280
-
281
- global $wpdb;
282
-
283
- $reply = true;
284
- $count = $wpdb->get_var( "SELECT COUNT(*) FROM {$this->core->log_table};" );
285
- if ( $count === NULL || $count < 1 )
286
- $reply = false;
287
-
288
- return apply_filters( 'mycred_stats_has_entries', $reply, $this );
289
-
290
- }
291
-
292
- /**
293
- * Admin Page
294
- * @since 1.6
295
- * @version 1.0.2
296
- */
297
- public function admin_page() {
298
-
299
- // Security
300
- if ( ! $this->core->can_edit_creds() ) wp_die( 'Access Denied' );
301
-
302
- $current = 'overview';
303
- if ( isset( $_GET['view'] ) )
304
- $current = $_GET['view'];
305
-
306
- $tabs = $this->get_tabs();
307
-
308
- ?>
309
- <div id="mycred-stats" class="wrap">
310
- <h1><?php echo $this->label; ?><a href="javascript:void(0);" onClick="window.location.href=window.location.href" class="add-new-h2" id="refresh-mycred-stats"><?php _e( 'Refresh', 'mycred' ); ?></a></h1>
311
- <?php
312
-
313
- do_action( 'mycred_stats_page_before', $this );
314
-
315
- // No use loading the widgets if no log entries exists
316
- if ( $this->has_entries() ) {
317
-
318
- ?>
319
- <ul id="section-nav" class="nav-tab-wrapper">
320
- <?php
321
-
322
- foreach ( $tabs as $tab_id => $tab_label ) {
323
-
324
- $classes = 'nav-tab';
325
- if ( $current == $tab_id ) $classes .= ' nav-tab-active';
326
-
327
- if ( $tab_id != 'general' )
328
- $url = add_query_arg( array( 'page' => $_GET['page'], 'view' => $tab_id ), admin_url( 'admin.php' ) );
329
- else
330
- $url = add_query_arg( array( 'page' => $_GET['page'] ), admin_url( 'admin.php' ) );
331
-
332
- echo '<li class="' . $classes . '"><a href="' . esc_url( $url ) . '">' . $tab_label . '</a></li>';
333
-
334
- }
335
-
336
- ?>
337
- </ul>
338
-
339
- <div id="mycred-stats-body" class="clear clearfix">
340
-
341
- <?php
342
-
343
- // Render tab
344
- if ( has_action( 'mycred_stats_screen_' . $current ) ) {
345
-
346
- do_action( 'mycred_stats_screen_' . $current );
347
-
348
- }
349
-
350
- elseif ( $current === 'overview' ) {
351
-
352
- $widgets = apply_filters( 'mycred_stats_overview_widgets', array(
353
- 0 => array( 'id' => 'overallcirculation', 'class' => 'myCRED_Stats_Widget_Circulation', 'args' => array( 'ctypes' => 'all' ) ),
354
- 1 => array( 'id' => 'overallgains', 'class' => 'myCRED_Stats_Widget_Daily_Gains', 'args' => array( 'ctypes' => 'all', 'span' => 10, 'number' => 5 ) ),
355
- 2 => array( 'id' => 'overallloses', 'class' => 'myCRED_Stats_Widget_Daily_Loses', 'args' => array( 'ctypes' => 'all', 'span' => 10, 'number' => 5 ) )
356
- ), $this );
357
-
358
- if ( ! empty( $widgets ) ) {
359
- foreach ( $widgets as $num => $swidget ) {
360
-
361
- $widget = $swidget['class'];
362
- if ( class_exists( $widget ) ) {
363
-
364
- $w = new $widget( $swidget['id'], $swidget['args'] );
365
-
366
- echo '<div class="mycred-stat-widget">';
367
-
368
- $w->widget();
369
-
370
- echo '</div>';
371
-
372
- $w = NULL;
373
-
374
- }
375
-
376
- }
377
- }
378
-
379
- }
380
-
381
- elseif ( substr( $current, 0, 5 ) === 'view_' ) {
382
-
383
- $widgets = apply_filters( 'mycred_stats_' . $current . '_widgets', array(
384
- 0 => array( 'id' => $current . 'circulation', 'class' => 'myCRED_Stats_Widget_Circulation', 'args' => array( 'ctypes' => str_replace( 'view_', '', $current ) ) ),
385
- 1 => array( 'id' => $current . 'gains', 'class' => 'myCRED_Stats_Widget_Daily_Gains', 'args' => array( 'ctypes' => str_replace( 'view_', '', $current ), 'span' => 10, 'number' => 5 ) ),
386
- 2 => array( 'id' => $current . 'loses', 'class' => 'myCRED_Stats_Widget_Daily_Loses', 'args' => array( 'ctypes' => str_replace( 'view_', '', $current ), 'span' => 10, 'number' => 5 ) )
387
- ), $this );
388
-
389
- if ( ! empty( $widgets ) ) {
390
- foreach ( $widgets as $num => $swidget ) {
391
-
392
- $widget = $swidget['class'];
393
- if ( class_exists( $widget ) ) {
394
-
395
- $w = new $widget( $swidget['id'], $swidget['args'] );
396
-
397
- echo '<div class="mycred-stat-widget">';
398
-
399
- $w->widget();
400
-
401
- echo '</div>';
402
-
403
- $w = NULL;
404
-
405
- }
406
-
407
- }
408
- }
409
-
410
- }
411
-
412
- }
413
- else {
414
-
415
- ?>
416
- <div id="mycred-log-is-empty">
417
- <p><?php _e( 'Your log is empty. No statistics can be shown.', 'mycred' ); ?></p>
418
- </div>
419
- <?php
420
-
421
- }
422
-
423
- ?>
424
- </div>
425
- </div>
426
-
427
- </div>
428
- <?php
429
-
430
- do_action( 'mycred_stats_page_after', $this );
431
-
432
- }
433
-
434
- }
435
- endif;
436
-
437
- /**
438
- * Load Statistics Module
439
- * @since 1.7
440
- * @version 1.0
441
- */
442
- if ( ! function_exists( 'mycred_load_statistics_addon' ) ) :
443
- function mycred_load_statistics_addon( $modules, $point_types ) {
444
-
445
- $modules['solo']['stats'] = new myCRED_Stats_Module();
446
- $modules['solo']['stats']->load();
447
-
448
- return $modules;
449
-
450
- }
451
- endif;
452
- add_filter( 'mycred_load_modules', 'mycred_load_statistics_addon', 100, 2 );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
addons/stats/widgets/index.php DELETED
@@ -1,3 +0,0 @@
1
- <?php
2
- // Silence is golden.
3
- ?>
 
 
 
addons/stats/widgets/mycred-stats-widget-circulation.php DELETED
@@ -1,392 +0,0 @@
1
- <?php
2
- if ( ! defined( 'myCRED_STATS_VERSION' ) ) exit;
3
-
4
- /**
5
- * Stats Widget: Circulation
6
- * @version 1.0
7
- */
8
- if ( ! class_exists( 'myCRED_Stats_Widget_Circulation' ) ) :
9
- class myCRED_Stats_Widget_Circulation extends myCRED_Statistics_Widget {
10
-
11
- /**
12
- * Constructor
13
- */
14
- function __construct( $widget_id = '', $args = array() ) {
15
- if ( $widget_id == '' )
16
- $widget_id = 'circulation';
17
-
18
- parent::__construct( $widget_id, $args );
19
- $this->dates = mycred_get_stat_dates( 'today_this' );
20
- }
21
-
22
- /**
23
- * Get Data
24
- * @version 1.0
25
- */
26
- function get_data() {
27
-
28
- global $wpdb;
29
-
30
- if ( $this->args['ctypes'] == 'all' )
31
- $point_types = $this->ctypes;
32
- else
33
- $point_types = array( $this->args['ctypes'] => $this->ctypes[ $this->args['ctypes'] ] );
34
-
35
- $series = $totals = array();
36
- $all = 0;
37
-
38
- foreach ( $point_types as $type_id => $label ) {
39
-
40
- $mycred = mycred( $type_id );
41
- $total = $wpdb->get_var( $wpdb->prepare( "SELECT SUM( meta_value ) FROM {$wpdb->usermeta} WHERE meta_key = %s;", $type_id ) );
42
- if ( $total === NULL ) $total = 0;
43
-
44
- $totals[] = '<strong>' . sprintf( __( 'Total %s:', 'mycred' ), $this->ctypes[ $type_id ] ) . '</strong> <span style="color:' . $this->colors[ $type_id ]['positive'] . '">' . $mycred->format_creds( $total ) . '</span>';
45
- $all = $all + $total;
46
- $series[] = "{ value: " . $total . ", color: '" . $this->colors[ $type_id ]['positive'] . "', highlight: '" . $this->colors[ $type_id ]['negative'] . "', label: '" . esc_attr( $label ) . "' }";
47
-
48
- }
49
-
50
- return array(
51
- 'total' => $all,
52
- 'totals' => $totals,
53
- 'series' => $series
54
- );
55
-
56
- }
57
-
58
- /**
59
- * Get Gains and Loses
60
- * @version 1.0
61
- */
62
- function gains_and_loses() {
63
-
64
- global $wpdb;
65
-
66
- if ( $this->args['ctypes'] == 'all' )
67
- $point_types = $this->ctypes;
68
- else
69
- $point_types = array( $this->args['ctypes'] => $this->ctypes[ $this->args['ctypes'] ] );
70
-
71
- $series = array();
72
- foreach ( $point_types as $type_id => $label ) {
73
-
74
- if ( ! array_key_exists( $type_id, $series ) )
75
- $series[ $type_id ] = array();
76
-
77
- $values = array();
78
- foreach ( $this->dates as $date ) {
79
-
80
- if ( ! array_key_exists( $date['key'], $series[ $type_id ] ) )
81
- $series[ $type_id ][ $date['key'] ] = array(
82
- 'gains' => 0,
83
- 'loses' => 0
84
- );
85
-
86
- $query = $wpdb->get_col( $wpdb->prepare( "
87
- SELECT creds
88
- FROM {$this->core->log_table}
89
- WHERE ctype = %s
90
- AND time BETWEEN %d AND %d;", $type_id, $date['from'], $date['until'] ) );
91
-
92
- if ( ! empty( $query ) ) {
93
- foreach ( $query as $entry ) {
94
- if ( $entry > 0 )
95
- $series[ $type_id ][ $date['key'] ]['gains'] = $series[ $type_id ][ $date['key'] ]['gains'] + $entry;
96
- else
97
- $series[ $type_id ][ $date['key'] ]['loses'] = $series[ $type_id ][ $date['key'] ]['loses'] + $entry;
98
- }
99
- }
100
-
101
- }
102
-
103
- }
104
-
105
- return $series;
106
-
107
- }
108
-
109
- /**
110
- * Get Total
111
- * @version 1.0
112
- */
113
- function get_total( $ctype = '', $positive = true ) {
114
-
115
- global $wpdb;
116
-
117
- if ( $positive )
118
- $total = $wpdb->get_var( $wpdb->prepare( "SELECT SUM( creds ) FROM {$this->core->log_table} WHERE ctype = %s AND creds > 0;", $ctype ) );
119
- else
120
- $total = $wpdb->get_var( $wpdb->prepare( "SELECT SUM( creds ) FROM {$this->core->log_table} WHERE ctype = %s AND creds < 0;", $ctype ) );
121
-
122
- if ( $total === NULL )
123
- $total = 0;
124
-
125
- return $total;
126
-
127
- }
128
-
129
- /**
130
- * Front Widget
131
- * @version 1.0
132
- */
133
- function front_widget() {
134
-
135
- if ( $this->args['ctypes'] == 'all' )
136
- $label = __( 'Total amount in circulation', 'mycred' );
137
- else
138
- $label = sprintf( __( 'Total amount of %s in circulation', 'mycred' ), $this->ctypes[ $this->args['ctypes'] ] );
139
-
140
- $circulation = $this->get_data();
141
- $gains_loses = $this->gains_and_loses();
142
-
143
- ?>
144
- <div id="mycred-stats-overview" class="row">
145
- <div id="mycred-stats-<?php echo $this->id; ?>" class="col-lg-3 col-md-3 col-sm-12 col-xs-12">
146
- <canvas id="total-circulation-<?php echo $this->id; ?>-chart"></canvas>
147
- </div>
148
- <div class="col-lg-9 col-md-9 col-sm-12 col-xs-12">
149
- <h1><?php echo $label; ?>: <?php echo $this->format_number( $circulation['total'] ); ?></h1>
150
- <?php
151
-
152
- if ( $this->args['ctypes'] == 'all' ) :
153
-
154
- ?>
155
- <ul id="total-per-point-type"><li><?php echo implode( '</li><li>', $circulation['totals'] ); ?></li></ul>
156
- <?php
157
-
158
- else :
159
-
160
- $circulation = array( 'series' => array() );
161
- $mycred = mycred( $this->args['ctypes'] );
162
-
163
- $gains = $this->get_total( $this->args['ctypes'] );
164
- $loses = $this->get_total( $this->args['ctypes'], false );
165
-
166
- $total = $gains + abs( $loses );
167
- $gains_p = number_format( ( ( $gains / $total ) * 100 ), 0 );
168
- $gains_l = number_format( ( 100 - $gains_p ), 0 );
169
-
170
- $color = $gain_color = $this->colors[ $this->args['ctypes'] ]['positive'];
171
- $circulation['series'][] = "{ value: {$gains_p}, color: '" . $color . "', highlight: '" . $color . "', label: '" . esc_attr__( 'Total gains (%)', 'mycred' ) . "' }";
172
-
173
- $color = $lose_color = $this->colors[ $this->args['ctypes'] ]['positive'];
174
- $circulation['series'][] = "{ value: {$gains_l}, color: '" . $color . "', highlight: '" . $color . "', label: '" . esc_attr__( 'Total loses (%)', 'mycred' ) . "' }";
175
-
176
- //
177
- ?>
178
- <ul id="total-per-point-type"><li><?php printf( __( 'Total Gained: %s', 'mycred' ), '<span style="color:' . $gain_color . '">' . $mycred->format_creds( $gains ) . '</span>' ); ?></li><li><?php printf( __( 'Total Spent: %s', 'mycred' ), '<span style="color:' . $lose_color . '">' . $mycred->format_creds( $loses ) . '</span>' ); ?></li></ul>
179
- <?php
180
-
181
- endif;
182
-
183
- ?>
184
- <div class="table-responsive mycred-stats-table">
185
- <table class="table table-condensed" cellpadding="0" cellspacing="0">
186
- <thead>
187
- <tr>
188
- <th class="rowtitle"></th>
189
- <th class="doublecell" colspan="2"><?php _e( 'Today', 'mycred' ); ?></th>
190
- <th class="doublecell" colspan="2"><?php _e( 'This Week', 'mycred' ); ?></th>
191
- <th class="doublecell" colspan="2"><?php _e( 'This Month', 'mycred' ); ?></th>
192
- <th class="doublecell" colspan="2"><?php _e( 'This Year', 'mycred' ); ?></th>
193
- </tr>
194
- <tr class="subheader">
195
- <th class="rowtitle"></th>
196
- <th class="cell"><?php _e( 'Gained', 'mycred' ); ?></th>
197
- <th class="cell"><?php _e( 'Lost', 'mycred' ); ?></th>
198
- <th class="cell"><?php _e( 'Gained', 'mycred' ); ?></th>
199
- <th class="cell"><?php _e( 'Lost', 'mycred' ); ?></th>
200
- <th class="cell"><?php _e( 'Gained', 'mycred' ); ?></th>
201
- <th class="cell"><?php _e( 'Lost', 'mycred' ); ?></th>
202
- <th class="cell"><?php _e( 'Gained', 'mycred' ); ?></th>
203
- <th class="cell last"><?php _e( 'Lost', 'mycred' ); ?></th>
204
- </tr>
205
- </thead>
206
- <tbody>
207
- <?php
208
-
209
- foreach ( $gains_loses as $type_id => $dates ) {
210
-
211
- $mycred = mycred( $type_id );
212
-
213
- ?>
214
- <tr style="color: <?php echo $this->colors[ $type_id ]['positive']; ?>;">
215
- <td class="rowtitle"><?php echo $this->ctypes[ $type_id ]; ?></td>
216
- <?php
217
-
218
- $page_id = MYCRED_SLUG;
219
- if ( $type_id != MYCRED_DEFAULT_TYPE_KEY )
220
- $page_id .= '_' . $type_id;
221
-
222
- $base_url = add_query_arg( array( 'page' => $page_id ), admin_url( 'admin.php' ) );
223
- foreach ( $dates as $key => $item ) {
224
- echo '<td class="cell">' . $mycred->format_number( $item['gains'] ) . '</td>';
225
- echo '<td class="cell">' . $mycred->format_number( $item['loses'] ) . '</td>';
226
- }
227
-
228
- }
229
-
230
- ?>
231
- </tbody>
232
- </table>
233
- </div>
234
- </div>
235
- </div>
236
- <script type="text/javascript">
237
- jQuery(function($) {
238
-
239
- var <?php echo $this->id; ?> = $( '#total-circulation-<?php echo $this->id; ?>-chart' ).get(0).getContext( '2d' );
240
- <?php echo $this->id; ?>.canvas.width = 240;
241
- <?php echo $this->id; ?>.canvas.height = 240;
242
-
243
- var <?php echo $this->id; ?>chart = new Chart( <?php echo $this->id; ?> ).Doughnut([
244
- <?php echo implode( ',', $circulation['series'] ); ?>
245
- ],{
246
- segmentStrokeColor : '#F1F1F1',
247
- segmentStrokeWidth : 3,
248
- percentageInnerCutout : 60
249
- });
250
-
251
- });
252
- </script>
253
- <?php
254
-
255
- }
256
-
257
- /**
258
- * Display
259
- * @version 1.0.2
260
- */
261
- function widget() {
262
-
263
- if ( $this->args['ctypes'] == 'all' )
264
- $label = __( 'Total amount in circulation', 'mycred' );
265
- else
266
- $label = sprintf( __( 'Total amount of %s in circulation', 'mycred' ), $this->ctypes[ $this->args['ctypes'] ] );
267
-
268
- $circulation = $this->get_data();
269
- $gains_loses = $this->gains_and_loses();
270
-
271
- ?>
272
- <div id="mycred-stats-overview" class="clear clearfix">
273
- <div id="mycred-stats-<?php echo $this->id; ?>" class="left-column">
274
- <canvas id="total-circulation-<?php echo $this->id; ?>-chart"></canvas>
275
- </div>
276
- <h1><?php echo $label; ?>: <?php echo $this->format_number( $circulation['total'] ); ?></h1>
277
- <?php
278
-
279
- if ( $this->args['ctypes'] == 'all' ) :
280
-
281
- ?>
282
- <ul id="total-per-point-type"><li><?php echo implode( '</li><li>', $circulation['totals'] ); ?></li></ul>
283
- <?php
284
-
285
- else :
286
-
287
- $circulation = array( 'series' => array() );
288
- $mycred = mycred( $this->args['ctypes'] );
289
-
290
- $gains = $this->get_total( $this->args['ctypes'] );
291
- $loses = $this->get_total( $this->args['ctypes'], false );
292
-
293
- $total = $gains + abs( $loses );
294
- $gains_p = $gains_l = 0;
295
- if ( $total != 0 ) {
296
- $gains_p = number_format( ( ( $gains / $total ) * 100 ), 0 );
297
- $gains_l = number_format( ( 100 - $gains_p ), 0 );
298
- }
299
-
300
- $color = $gain_color = $this->colors[ $this->args['ctypes'] ]['positive'];
301
- $circulation['series'][] = "{ value: {$gains_p}, color: '" . $color . "', highlight: '" . $color . "', label: '" . esc_attr__( 'Total gains (%)', 'mycred' ) . "' }";
302
-
303
-
304
- $color = $lose_color = $this->colors[ $this->args['ctypes'] ]['negative'];
305
- $circulation['series'][] = "{ value: {$gains_l}, color: '" . $color . "', highlight: '" . $color . "', label: '" . esc_attr__( 'Total loses (%)', 'mycred' ) . "' }";
306
-
307
- ?>
308
- <ul id="total-per-point-type"><li><?php printf( __( 'Total Gained: %s', 'mycred' ), '<span style="color:' . $gain_color . '">' . $mycred->format_creds( $gains ) . '</span>' ); ?></li><li><?php printf( __( 'Total Spent: %s', 'mycred' ), '<span style="color:' . $lose_color . '">' . $mycred->format_creds( $loses ) . '</span>' ); ?></li></ul>
309
- <?php
310
-
311
- endif;
312
-
313
- ?>
314
- <div class="table">
315
- <table cellpadding="0" cellspacing="0">
316
- <thead>
317
- <tr>
318
- <th class="rowtitle"></th>
319
- <th class="doublecell" colspan="2"><?php _e( 'Today', 'mycred' ); ?></th>
320
- <th class="doublecell" colspan="2"><?php _e( 'This Week', 'mycred' ); ?></th>
321
- <th class="doublecell" colspan="2"><?php _e( 'This Month', 'mycred' ); ?></th>
322
- <th class="doublecell" colspan="2"><?php _e( 'This Year', 'mycred' ); ?></th>
323
- </tr>
324
- <tr class="subheader">
325
- <th class="rowtitle"></th>
326
- <th class="cell"><?php _e( 'Gained', 'mycred' ); ?></th>
327
- <th class="cell"><?php _e( 'Lost', 'mycred' ); ?></th>
328
- <th class="cell"><?php _e( 'Gained', 'mycred' ); ?></th>
329
- <th class="cell"><?php _e( 'Lost', 'mycred' ); ?></th>
330
- <th class="cell"><?php _e( 'Gained', 'mycred' ); ?></th>
331
- <th class="cell"><?php _e( 'Lost', 'mycred' ); ?></th>
332
- <th class="cell"><?php _e( 'Gained', 'mycred' ); ?></th>
333
- <th class="cell last"><?php _e( 'Lost', 'mycred' ); ?></th>
334
- </tr>
335
- </thead>
336
- <tbody>
337
- <?php
338
-
339
- foreach ( $gains_loses as $type_id => $dates ) {
340
-
341
- $type_id = str_replace( 'view_', '', $type_id );
342
- $mycred = mycred( $type_id );
343
-
344
- ?>
345
- <tr style="color: <?php echo $this->colors[ $type_id ]['positive']; ?>;">
346
- <td class="rowtitle"><?php echo $this->ctypes[ $type_id ]; ?></td>
347
- <?php
348
-
349
- $page_id = MYCRED_SLUG;
350
- if ( $type_id != MYCRED_DEFAULT_TYPE_KEY )
351
- $page_id .= '_' . $type_id;
352
-
353
- $base_url = add_query_arg( array( 'page' => $page_id ), admin_url( 'admin.php' ) );
354
- foreach ( $dates as $key => $item ) {
355
- $url = add_query_arg( array( 'show' => $key ), $base_url );
356
- echo '<td class="cell"><a href="' . esc_url( $url ) . '">' . $mycred->format_number( $item['gains'] ) . '</a></td>';
357
- $url = add_query_arg( array( 'show' => $key, 'num' => 0, 'compare' => urlencode( '<' ) ), $base_url );
358
- echo '<td class="cell"><a href="' . esc_url( $url ) . '">' . $mycred->format_number( $item['loses'] ) . '</a></td>';
359
- }
360
-
361
- }
362
-
363
- ?>
364
- </tbody>
365
- </table>
366
- <?php echo $this->action_buttons(); ?>
367
- </div>
368
- <div class="clear clearfix"></div>
369
- </div>
370
- <script type="text/javascript">
371
- jQuery(function($) {
372
-
373
- var <?php echo $this->id; ?> = $( '#total-circulation-<?php echo $this->id; ?>-chart' ).get(0).getContext( '2d' );
374
- <?php echo $this->id; ?>.canvas.width = 240;
375
- <?php echo $this->id; ?>.canvas.height = 240;
376
-
377
- var <?php echo $this->id; ?>chart = new Chart( <?php echo $this->id; ?> ).Doughnut([
378
- <?php echo implode( ',', $circulation['series'] ); ?>
379
- ],{
380
- segmentStrokeColor : '#F1F1F1',
381
- segmentStrokeWidth : 3,
382
- percentageInnerCutout : 60
383
- });
384
-
385
- });
386
- </script>
387
- <?php
388
-
389
- }
390
-
391
- }
392
- endif;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
addons/stats/widgets/mycred-stats-widget-daily-gains.php DELETED
@@ -1,204 +0,0 @@
1
- <?php
2
- if ( ! defined( 'myCRED_STATS_VERSION' ) ) exit;
3
-
4
- /**
5
- * Stats Widget:
6
- * @version 1.0
7
- */
8
- if ( ! class_exists( 'myCRED_Stats_Widget_Daily_Gains' ) ) :
9
- class myCRED_Stats_Widget_Daily_Gains extends myCRED_Statistics_Widget {
10
-
11
- /**
12
- * Constructor
13
- */
14
- function __construct( $widget_id = '', $args = array() ) {
15
- if ( $widget_id == '' )
16
- $widget_id = 'dailygains';
17
-
18
- parent::__construct( $widget_id, $args );
19
- $this->dates = mycred_get_stat_dates( 'x_dates', $this->args['span'] );
20
- }
21
-
22
- /**
23
- * Get Data
24
- * @version 1.0
25
- */
26
- function get_data() {
27
-
28
- global $wpdb;
29
-
30
- $ctype_limit = '';
31
- if ( $this->args['ctypes'] != 'all' )
32
- $ctype_limit = $wpdb->prepare( "AND ctype = %s", $this->args['ctypes'] );
33
-
34
- return $wpdb->get_results( $wpdb->prepare( "
35
- SELECT ref, COUNT(*) AS count, SUM( creds ) AS total, ctype AS type
36
- FROM {$this->core->log_table}
37
- WHERE creds > 0
38
- AND time BETWEEN %d AND %d
39
- {$ctype_limit}
40
- GROUP BY ref ORDER BY total DESC LIMIT 0,%d;", strtotime( '-' . $this->args['span'] . ' days midnight', $this->now ), $this->now, $this->args['number'] ) );
41
-
42
- }
43
-
44
- /**
45
- * Get Gains
46
- * @version 1.0
47
- */
48
- function get_gains() {
49
-
50
- global $wpdb;
51
-
52
- if ( $this->args['ctypes'] == 'all' )
53
- $point_types = $this->ctypes;
54
- else
55
- $point_types = array( $this->args['ctypes'] => $this->ctypes[ $this->args['ctypes'] ] );
56
-
57
- $series = $ctypes = $categories = array();
58
- $num = 0;
59
-
60
-
61
- if ( count( $point_types ) > 0 ) {
62
-
63
- foreach ( $point_types as $type_id => $label ) {
64
-
65
- $num ++;
66
-
67
- $count = $wpdb->get_var( "SELECT COUNT( * ) FROM {$this->core->log_table} WHERE ctype = '{$type_id}';" );
68
- if ( $count === NULL )
69
- $count = $num;
70
-
71
- $ctypes[ $count ] = $type_id;
72
-
73
- }
74
-
75
- ksort( $ctypes, SORT_NUMERIC );
76
-
77
- }
78
-
79
- foreach ( $ctypes as $count => $type_id ) {
80
-
81
- $values = array();
82
- foreach ( $this->dates as $date ) {
83
-
84
- $query = $wpdb->get_var( $wpdb->prepare( "
85
- SELECT SUM( creds )
86
- FROM {$this->core->log_table}
87
- WHERE creds > 0
88
- AND ctype = %s
89
- AND time BETWEEN %d AND %d;", $type_id, $date['from'], $date['until'] ) );
90
-
91
- if ( $query === NULL ) $query = 0;
92
-
93
- $values[] = abs( $query );
94
-
95
- if ( ! in_array( $date['label'], $categories ) )
96
- $categories[] = esc_attr( $date['label'] );
97
-
98
- }
99
-
100
- $mycred = mycred( $type_id );
101
- $series[] = "{ label : '" . esc_js( $mycred->plural() ) . "', fillColor : '" . str_replace( ',1)', ',0.3)', $this->colors[ $type_id ]['positive'] ) . "', strokeColor : '" . $this->colors[ $type_id ]['positive'] . "', pointColor : '" . $this->colors[ $type_id ]['positive'] . "', data : [" . implode( ', ', $values ) . "] }";
102
-
103
- }
104
-
105
- return array(
106
- 'categories' => $categories,
107
- 'series' => $series
108
- );
109
-
110
- }
111
-
112
- /**
113
- * Display
114
- * @version 1.0.1
115
- */
116
- function widget() {
117
-
118
- $label = __( 'Most common ways your users have gained points during this period.', 'mycred' );
119
- if ( $this->args['ctypes'] != 'all' )
120
- $label = $this->core->template_tags_general( __( 'Most common ways your users have gained %_plural% during this period.', 'mycred' ) );
121
-
122
- $ten_day_gain = $this->get_data();
123
- $earned = $this->get_gains();
124
-
125
- ?>
126
- <div id="" class="clear clearfix">
127
- <h1><?php _e( 'Gains in the last 10 days', 'mycred' ); ?></h1>
128
- <p><span class="description"><?php echo $label; ?></span></p>
129
- <?php
130
-
131
- if ( ! empty( $ten_day_gain ) ) {
132
-
133
- echo '<div class="mycred-popular-items"><ol>';
134
- foreach ( $ten_day_gain as $item ) {
135
-
136
- if ( isset( $refs[ $item->ref ] ) )
137
- $label = $refs[ $item->ref ];
138
- else
139
- $label = ucfirst( str_replace( '_', ' ', $item->ref ) );
140
-
141
- $page_id = MYCRED_SLUG;
142
- if ( $item->type != MYCRED_DEFAULT_TYPE_KEY )
143
- $page_id .= '_' . $item->type;
144
-
145
- $base_url = admin_url( 'admin.php' );
146
- $url = add_query_arg( array( 'ref' => $item->ref, 'page' => $page_id ), $base_url );
147
-
148
- ?>
149
- <li>
150
- <strong style="color:<?php echo $this->colors[ $item->type ]['positive']; ?>;"><?php echo $label; ?></strong>
151
- <span class="view"><a href="<?php echo esc_url( $url ); ?>"><?php _e( 'View', 'mycred' ); ?></a></span>
152
- <ul>
153
- <li><?php echo number_format( $item->total, 0, '.', ' ' ); ?></li>
154
- <li><?php echo $item->count; ?></li>
155
- </ul>
156
- <div class="clear clearfix"></div>
157
- </li>
158
- <?php
159
-
160
- }
161
-
162
- echo '</ol></div><div class="last-ten-days-chart"><canvas id="daily-gain-' . $this->id . '-chart"></canvas><div id="' . $this->id . '-legend" class="mycred-chart-legend clear clearfix"></div></div>';
163
-
164
- }
165
- else {
166
- echo '<div class="mycred-empty-widget"><p>' . __( 'No data found', 'mycred' ) . '</p></div>';
167
- }
168
-
169
- ?>
170
- <div class="clear clearfix"></div>
171
- </div>
172
- <?php
173
-
174
- if ( ! empty( $ten_day_gain ) ) :
175
-
176
- ?>
177
- <script type="text/javascript">
178
- jQuery(function($) {
179
-
180
- var <?php echo $this->id; ?> = $( '#daily-gain-<?php echo $this->id; ?>-chart' ).get(0).getContext( '2d' );
181
-
182
- <?php echo $this->id; ?>.canvas.height = 400;
183
- var <?php echo $this->id; ?>chart = new Chart( <?php echo $this->id; ?> ).Line({
184
- labels : [<?php echo "'" . implode( "', '", $earned['categories'] ) . "'"; ?>],
185
- datasets : [<?php echo implode( ',', $earned['series'] ); ?>]
186
- },{
187
- bezierCurve: false,
188
- responsive: true,
189
- maintainAspectRatio: false
190
- });
191
-
192
- var <?php echo $this->id; ?>legend = <?php echo $this->id; ?>chart.generateLegend();
193
- $( '#<?php echo $this->id; ?>-legend' ).append( <?php echo $this->id; ?>legend );
194
-
195
- });
196
- </script>
197
- <?php
198
-
199
- endif;
200
-
201
- }
202
-
203
- }
204
- endif;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
addons/stats/widgets/mycred-stats-widget-daily-loses.php DELETED
@@ -1,204 +0,0 @@
1
- <?php
2
- if ( ! defined( 'myCRED_STATS_VERSION' ) ) exit;
3
-
4
- /**
5
- * Stats Widget:
6
- * @version 1.0
7
- */
8
- if ( ! class_exists( 'myCRED_Stats_Widget_Daily_Loses' ) ) :
9
- class myCRED_Stats_Widget_Daily_Loses extends myCRED_Statistics_Widget {
10
-
11
- /**
12
- * Constructor
13
- */
14
- function __construct( $widget_id = '', $args = array() ) {
15
- if ( $widget_id == '' )
16
- $widget_id = 'dailyloses';
17
-
18
- parent::__construct( $widget_id, $args );
19
- $this->dates = mycred_get_stat_dates( 'x_dates', $this->args['span'] );
20
- }
21
-
22
- /**
23
- * Get Data
24
- * @version 1.0
25
- */
26
- function get_data() {
27
-
28
- global $wpdb;
29
-
30
- $ctype_limit = '';
31
- if ( $this->args['ctypes'] != 'all' )
32
- $ctype_limit = $wpdb->prepare( "AND ctype = %s", $this->args['ctypes'] );
33
-
34
- return $wpdb->get_results( $wpdb->prepare( "
35
- SELECT ref, COUNT(*) AS count, SUM( creds ) AS total, ctype AS type
36
- FROM {$this->core->log_table}
37
- WHERE creds < 0
38
- AND time BETWEEN %d AND %d
39
- {$ctype_limit}
40
- GROUP BY ref ORDER BY total DESC LIMIT 0,%d;", strtotime( '-' . $this->args['span'] . ' days midnight', $this->now ), $this->now, $this->args['number'] ) );
41
-
42
- }
43
-
44
- /**
45
- * Get Spending
46
- * @version 1.0
47
- */
48
- function get_spending() {
49
-
50
- global $wpdb;
51
-
52
- if ( $this->args['ctypes'] == 'all' )
53
- $point_types = $this->ctypes;
54
- else
55
- $point_types = array( $this->args['ctypes'] => $this->ctypes[ $this->args['ctypes'] ] );
56
-
57
- $series = $ctypes = $categories = array();
58
- $num = 0;
59
-
60
-
61
- if ( count( $point_types ) > 0 ) {
62
-
63
- foreach ( $point_types as $type_id => $label ) {
64
-
65
- $num ++;
66
-
67
- $count = $wpdb->get_var( "SELECT COUNT( * ) FROM {$this->core->log_table} WHERE ctype = '{$type_id}';" );
68
- if ( $count === NULL )
69
- $count = $num;
70
-
71
- $ctypes[ $count ] = $type_id;
72
-
73
- }
74
-
75
- ksort( $ctypes, SORT_NUMERIC );
76
-
77
- }
78
-
79
- foreach ( $ctypes as $count => $type_id ) {
80
-
81
- $values = array();
82
- foreach ( $this->dates as $date ) {
83
-
84
- $query = $wpdb->get_var( $wpdb->prepare( "
85
- SELECT SUM( creds )
86
- FROM {$this->core->log_table}
87
- WHERE creds < 0
88
- AND ctype = %s
89
- AND time BETWEEN %d AND %d;", $type_id, $date['from'], $date['until'] ) );
90
-
91
- if ( $query === NULL ) $query = 0;
92
-
93
- $values[] = abs( $query );
94
-
95
- if ( ! in_array( $date['label'], $categories ) )
96
- $categories[] = esc_attr( $date['label'] );
97
-
98
- }
99
-
100
- $mycred = mycred( $type_id );
101
- $series[] = "{ label : '" . esc_js( $mycred->plural() ) . "', fillColor : '" . str_replace( ',1)', ',0.3)', $this->colors[ $type_id ]['negative'] ) . "', strokeColor : '" . $this->colors[ $type_id ]['negative'] . "', pointColor : '" . $this->colors[ $type_id ]['negative'] . "', data : [" . implode( ', ', $values ) . "] }";
102
-
103
- }
104
-
105
- return array(
106
- 'categories' => $categories,
107
- 'series' => $series
108
- );
109
-
110
- }
111
-
112
- /**
113
- * Display
114
- * @version 1.0.1
115
- */
116
- function widget() {
117
-
118
- $lose_label = __( 'Most common ways your users have lost or spent points during this period.', 'mycred' );
119
- if ( $this->args['ctypes'] != 'all' )
120
- $lose_label = $this->core->template_tags_general( __( 'Most common ways your users have lost or spent %_plural% during this period.', 'mycred' ) );
121
-
122
- $ten_day_lose = $this->get_data();
123
- $spending = $this->get_spending();
124
-
125
- ?>
126
- <div id="" class="clear clearfix">
127
- <h1><?php _e( 'Loses in the last 10 days', 'mycred' ); ?></h1>
128
- <p><span class="description"><?php echo $lose_label; ?></span></p>
129
- <?php
130
-
131
- if ( ! empty( $ten_day_lose ) ) {
132
-
133
- echo '<div class="mycred-popular-items"><ol>';
134
- foreach ( $ten_day_lose as $item ) {
135
-
136
- if ( isset( $refs[ $item->ref ] ) )
137
- $label = $refs[ $item->ref ];
138
- else
139
- $label = ucfirst( str_replace( '_', ' ', $item->ref ) );
140
-
141
- $page_id = MYCRED_SLUG;
142
- if ( $item->type != MYCRED_DEFAULT_TYPE_KEY )
143
- $page_id .= '_' . $item->type;
144
-
145
- $base_url = admin_url( 'admin.php' );
146
- $url = add_query_arg( array( 'ref' => $item->ref, 'page' => $page_id ), $base_url );
147
-
148
- ?>
149
- <li>
150
- <strong style="color:<?php echo $this->colors[ $item->type ]['negative']; ?>;"><?php echo $label; ?></strong>
151
- <span class="view"><a href="<?php echo esc_url( $url ); ?>"><?php _e( 'View', 'mycred' ); ?></a></span>
152
- <ul>
153
- <li><?php echo number_format( $item->total, 0, '.', ' ' ); ?></li>
154
- <li><?php echo $item->count; ?></li>
155
- </ul>
156
- <div class="clear clearfix"></div>
157
- </li>
158
- <?php
159
-
160
- }
161
-
162
- echo '</ol></div><div class="last-ten-days-chart"><canvas id="daily-loses-' . $this->id . '-chart"></canvas><div id="' . $this->id . '-legend" class="mycred-chart-legend clear clearfix"></div></div>';
163
-
164
- }
165
- else {
166
- echo '<div class="mycred-empty-widget"><p>' . __( 'No data found', 'mycred' ) . '</p></div>';
167
- }
168
-
169
- ?>
170
- <div class="clear clearfix"></div>
171
- </div>
172
- <?php
173
-
174
- if ( ! empty( $ten_day_lose ) ) :
175
-
176
- ?>
177
- <script type="text/javascript">
178
- jQuery(function($) {
179
-
180
- var <?php echo $this->id; ?> = $( '#daily-loses-<?php echo $this->id; ?>-chart' ).get(0).getContext( '2d' );
181
-
182
- <?php echo $this->id; ?>.canvas.height = 400;
183
- var <?php echo $this->id; ?>chart = new Chart( <?php echo $this->id; ?> ).Line({
184
- labels : [<?php echo "'" . implode( "', '", $spending['categories'] ) . "'"; ?>],
185
- datasets : [<?php echo implode( ',', $spending['series'] ); ?>]
186
- },{
187
- bezierCurve: false,
188
- responsive: true,
189
- maintainAspectRatio: false
190
- });
191
-
192
- var <?php echo $this->id; ?>legend = <?php echo $this->id; ?>chart.generateLegend();
193
- $( '#<?php echo $this->id; ?>-legend' ).append( <?php echo $this->id; ?>legend );
194
-
195
- });
196
- </script>
197
- <?php
198
-
199
- endif;
200
-
201
- }
202
-
203
- }
204
- endif;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
addons/transfer/assets/index.php DELETED
@@ -1,3 +0,0 @@
1
- <?php
2
- // Silence is golden.
3
- ?>
 
 
 
addons/transfer/assets/js/index.php DELETED
@@ -1,3 +0,0 @@
1
- <?php
2
- // Silence is golden.
3
- ?>
 
 
 
addons/transfer/assets/js/mycred-transfer.js DELETED
@@ -1,141 +0,0 @@
1
- /**
2
- * myCRED Transfer jQuery
3
- * Handles transfer requests and autocomplete of recipient search.
4
- *
5
- * @requires jQuery
6
- * @requires jQuery UI
7
- * @requires jQuery Autocomplete
8
- * @since 0.1
9
- * @version 1.5.2
10
- */
11
- (function($) {
12
-
13
- var mycred_transfer_cache = {};
14
-
15
- // Autocomplete
16
- // @api http://api.jqueryui.com/autocomplete/
17
- var mycred_transfer_autofill = $( 'input.mycred-autofill' ).autocomplete({
18
-
19
- minLength : 2,
20
- source : function( request, response ) {
21
-
22
- var term = request.term;
23
- if ( term in mycred_transfer_cache ) {
24
- response( mycred_transfer_cache[ term ] );
25
- return;
26
- }
27
-
28
- var send = {
29
- action : "mycred-autocomplete",
30
- token : myCREDTransfer.token,
31
- string : request
32
- };
33
-
34
- $.getJSON( myCREDTransfer.ajaxurl, send, function( data, status, xhr ) {
35
- mycred_transfer_cache[ term ] = data;
36
- response( data );
37
- });
38
-
39
- },
40
- messages: {
41
- noResults : '',
42
- results : function() {}
43
- },
44
- position: { my : "right top", at: "right bottom" }
45
-
46
- });
47
-
48
- $( 'input.mycred-autofill' ).click(function(){
49
-
50
- if ( myCREDTransfer.autofill == 'none' ) return false;
51
-
52
- var formfieldid = $(this).data( 'form' );
53
- mycred_transfer_autofill.autocomplete( "option", "appendTo", '#mycred-transfer-form-' + formfieldid + ' .select-recipient-wrapper' );
54
- console.log( formfieldid );
55
-
56
- });
57
-
58
- // Transfer form submissions
59
- // @since 1.6.3
60
- $( 'html body' ).on( 'submit', 'form.mycred-transfer-form', function(e){
61
-
62
- console.log( 'new transfer' );
63
-
64
- var transferform = $(this);
65
- var formrefid = transferform.data( 'ref' );
66
- var formid = '#mycred-transfer-form-' + formrefid;
67
- var submitbutton = $( formid + ' input.mycred-submit-transfer' );
68
- var buttonlabel = submitbutton.val();
69
-
70
- e.preventDefault();
71
-
72
- $.ajax({
73
- type : "POST",
74
- data : {
75
- action : 'mycred-new-transfer',
76
- form : transferform.serialize(),
77
- },
78
- dataType : "JSON",
79
- url : myCREDTransfer.ajaxurl,
80
- beforeSend : function() {
81
-
82
- $( formid + 'input.form-control' ).each(function(index){
83
- $(this).attr( 'disabled', 'disabled' );
84
- });
85
-
86
- submitbutton.val( myCREDTransfer.working );
87
-
88
- },
89
- success : function( response ) {
90
-
91
- console.log( response );
92
-
93
- $( formid + ' input.form-control' ).each(function(index){
94
- $(this).removeAttr( 'disabled' );
95
- });
96
-
97
- submitbutton.val( buttonlabel );
98
-
99
- if ( response.success !== undefined ) {
100
-
101
- if ( response.success ) {
102
-
103
- // Allow customizations to present custom success messages
104
- if ( response.data.message !== undefined && response.data.message != '' )
105
- alert( response.data.message );
106
- else
107
- alert( myCREDTransfer.completed );
108
-
109
- if ( $( response.data.css ) !== undefined )
110
- $( response.data.css ).empty().html( response.data.balance );
111
-
112
- // Reset form
113
- $( formid + ' input.form-control' ).each(function(index){
114
- $(this).val( '' );
115
- });
116
-
117
- $( formid + ' select' ).each(function(index){
118
- var selecteditem = $(this).find( ':selected' );
119
- if ( selecteditem !== undefined )
120
- selecteditem.removeAttr( 'selected' );
121
- });
122
-
123
- // If we require reload after submission, do so now
124
- if ( myCREDTransfer.reload == '1' ) location.reload();
125
-
126
- }
127
-
128
- else if ( myCREDTransfer[ response.data ] !== undefined )
129
- alert( myCREDTransfer[ response.data ] );
130
-
131
- }
132
-
133
- }
134
-
135
- });
136
-
137
- return false;
138
-
139
- });
140
-
141
- })( jQuery );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
addons/{ranks/assets/js → transfer/css}/index.php RENAMED
File without changes
addons/transfer/css/transfer.css ADDED
@@ -0,0 +1,33 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /**
2
+ * Transfer Styling
3
+ * @since 0.1
4
+ * @version 1.1
5
+ */
6
+ .mycred-transfer-cred-wrapper { display: block; float: none; clear: both; margin: 0; padding: 0; }
7
+ .mycred-transfer-cred-wrapper>p { margin-bottom: 6px; }
8
+ .mycred-transfer-cred-wrapper ol { margin: 0; padding: 0; float: none; clear: both; }
9
+ .mycred-transfer-cred-wrapper ol li { list-style-type: none; float: left; margin: 0; padding: 0; }
10
+ .widget .mycred-transfer-cred-wrapper ol li { float: none; }
11
+
12
+ .mycred-transfer-cred-wrapper ol li.mycred-send-to { width: 40%; }
13
+ .mycred-transfer-cred-wrapper ol li.mycred-send-to div.transfer-to { height: 100px; }
14
+ .widget .mycred-transfer-cred-wrapper ol li.mycred-send-to { width: 100%; }
15
+
16
+ .mycred-transfer-cred-wrapper ol li.mycred-send-amount { width: 60%; }
17
+ .widget .mycred-transfer-cred-wrapper ol li.mycred-send-amount { width: 100%; }
18
+ .mycred-transfer-cred-wrapper ol li.mycred-send-details span:empty { display: none; }
19
+ .mycred-transfer-cred-wrapper .mycred-click { float: right; }
20
+
21
+ .mycred-transfer-cred-wrapper ol li label { display: block; }
22
+ .mycred-transfer-cred-wrapper ol li input[type="text"] { width: 90%; }
23
+ .mycred-transfer-cred-wrapper ol li input[type="text"].short { width: 40%; }
24
+ .mycred-transfer-cred-wrapper ol li input[type="button"] { }
25
+
26
+ .mycred-transfer-info { margin: 0; padding: 6px 0; display: block; clear: both; float: none; }
27
+ .mycred-transfer-info p { font-size: smaller; line-height: 16px; margin: 0; padding: 0; }
28
+
29
+ ul.ui-autocomplete { border: none; margin: 0; padding: 6px 0 0 0; width: 100%; z-index: 10 !important; }
30
+ ul.ui-autocomplete li { background-color: white; padding: 0 4px; display: block; margin: 0; width: 90%; text-align: left; border-bottom: 1px solid silver; list-style-type: none; }
31
+ ul.ui-autocomplete li:first-child { border-top: 1px solid silver; }
32
+ ul.ui-autocomplete li:hover { background-color: #eee; }
33
+ ul.ui-autocomplete li a { display: block; cursor: pointer; width: 100%; margin: 0; padding: 8px 0; }
addons/transfer/includes/index.php DELETED
@@ -1,3 +0,0 @@
1
- <?php
2
- // Silence is golden.
3
- ?>
 
 
 
addons/transfer/includes/mycred-transfer-functions.php DELETED
@@ -1,275 +0,0 @@
1
- <?php
2
- if ( ! defined( 'myCRED_VERSION' ) ) exit;
3
-
4
- /**
5
- * User Can Transfer
6
- * @see http://mycred.me/functions/mycred_user_can_transfer/
7
- * @param $user_id (int) requred user id
8
- * @param $amount (int) optional amount to check against balance
9
- * @returns true if no limit is set, 'limit' (string) if user is over limit else the amount of creds left
10
- * @filter 'mycred_user_can_transfer'
11
- * @filter 'mycred_transfer_limit'
12
- * @filter 'mycred_transfer_acc_limit'
13
- * @since 0.1
14
- * @version 1.4.1
15
- */
16
- if ( ! function_exists( 'mycred_user_can_transfer' ) ) :
17
- function mycred_user_can_transfer( $user_id = NULL, $amount = NULL, $type = MYCRED_DEFAULT_TYPE_KEY, $reference = NULL ) {
18
-
19
- if ( $user_id === NULL )
20
- $user_id = get_current_user_id();
21
-
22
- if ( $reference === NULL )
23
- $reference = 'transfer';
24
-
25
- if ( ! mycred_point_type_exists( $type ) )
26
- $type = MYCRED_DEFAULT_TYPE_KEY;
27
-
28
- // Grab Settings
29
- $settings = mycred_get_addon_settings( 'transfers' );
30
- $mycred = mycred( $type );
31
- $zero = $mycred->zero();
32
-
33
- // Get users balance
34
- $balance = $mycred->get_users_balance( $user_id, $type );
35
-
36
- // Get Transfer Max
37
- $max = apply_filters( 'mycred_transfer_limit', $mycred->number( $settings['limit']['amount'] ), $user_id, $amount, $settings, $reference );
38
-
39
- // If an amount is given, deduct this amount to see if the transaction
40
- // brings us over the account limit
41
- if ( $amount !== NULL )
42
- $balance = $mycred->number( $balance - $amount );
43
-
44
- // Zero
45
- // The lowest amount a user can have on their account. By default, this
46
- // is zero. But you can override this via the mycred_transfer_acc_limit hook.
47
- $account_limit = $mycred->number( apply_filters( 'mycred_transfer_acc_limit', $zero, $type, $user_id, $reference ) );
48
-
49
- // Check if we would go minus
50
- if ( $balance < $account_limit ) return 'low';
51
-
52
- // If there are no limits, return the current balance
53
- if ( $settings['limit']['limit'] == 'none' ) return $balance;
54
-
55
- // Else we have a limit to impose
56
- $now = current_time( 'timestamp' );
57
- $max = $mycred->number( $settings['limit']['amount'] );
58
-
59
- // Daily limit
60
- if ( $settings['limit']['limit'] == 'daily' )
61
- $total = mycred_get_total_by_time( 'today', 'now', $reference, $user_id, $type );
62
-
63
- // Weekly limit
64
- elseif ( $settings['limit']['limit'] == 'weekly' ) {
65
- $this_week = mktime( 0, 0, 0, date( 'n', $now ), date( 'j', $now ) - date( 'n', $now ) + 1 );
66
- $total = mycred_get_total_by_time( $this_week, 'now', $reference, $user_id, $type );
67
- }
68
-
69
- // Custom limits will need to return the result
70
- // here and now. Accepted answers are 'limit', 'low' or the amount left on limit.
71
- else {
72
- return apply_filters( 'mycred_user_can_transfer', 'limit', $user_id, $amount, $settings, $reference );
73
- }
74
-
75
- // We are adding up point deducations.
76
- $total = abs( $total );
77
-
78
- if ( $amount !== NULL ) {
79
-
80
- $total = $mycred->number( $total + $amount );
81
-
82
- // Transfer limit reached
83
- if ( $total > $max ) return 'limit';
84
-
85
- }
86
-
87
- else {
88
-
89
- // Transfer limit reached
90
- if ( $total >= $max ) return 'limit';
91
-
92
- }
93
-
94
- // Return whats remaining of limit
95
- return $mycred->number( $max - $total );
96
-
97
- }
98
- endif;
99
-
100
- /**
101
- * New Transfer
102
- * @since 1.7.6
103
- * @version 1.0.2
104
- */
105
- if ( ! function_exists( 'mycred_new_transfer' ) ) :
106
- function mycred_new_transfer( $request = array() ) {
107
-
108
- $request = apply_filters( 'mycred_new_transfer_args', shortcode_atts( array(
109
- 'transaction_id' => NULL,
110
- 'sender_id' => NULL,
111
- 'recipient_id' => NULL,
112
- 'reference' => 'transfer',
113
- 'charge' => NULL,
114
- 'payout' => NULL,
115
- 'point_type' => MYCRED_DEFAULT_TYPE_KEY,
116
- 'data' => ''
117
- ), $request ) );
118
-
119
- extract( $request );
120
-
121
- if ( $transaction_id === NULL || $sender_id === NULL || $recipient_id === NULL || $charge === NULL || $payout === NULL ) return 'error_9';
122
-
123
- $point_type = sanitize_key( $point_type );
124
- $settings = mycred_get_addon_settings( 'transfers' );
125
- $mycred = mycred( $point_type );
126
-
127
- $result = 'error_9';
128
-
129
- if ( $mycred->exclude_user( $sender_id ) )
130
- return 'error_4';
131
-
132
- // The recipient is excluded from the point type
133
- if ( $mycred->exclude_user( $recipient_id ) )
134
- return 'error_4';
135
-
136
- // Check if we can complete this transaction before we run it
137
- $attempt_check = mycred_user_can_transfer( $sender_id, $charge, $point_type, $reference );
138
-
139
- // Insufficient funds
140
- if ( $attempt_check === 'low' )
141
- return 'error_7';
142
-
143
- // Limit reached
144
- if ( $attempt_check === 'limit' )
145
- return 'error_8';
146
-
147
- // Prevent Duplicate transactions
148
- if ( $mycred->has_entry( $reference, $recipient_id, $sender_id, $data, $point_type ) )
149
- return 'error_9';
150
-
151
- // Let others play before we execute the transfer
152
- do_action( 'mycred_transfer_ready', $transaction_id, $request, $settings );
153
-
154
- // First take the amount from the sender
155
- if ( $mycred->add_creds(
156
- $reference,
157
- $sender_id,
158
- 0 - $charge,
159
- $settings['logs']['sending'],
160
- $recipient_id,
161
- $data,
162
- $point_type
163
- ) ) {
164
-
165
- // Then add the amount to the receipient
166
- if ( ! $mycred->has_entry( $reference, $sender_id, $recipient_id, $data, $point_type ) ) {
167
-
168
- $mycred->add_creds(
169
- $reference,
170
- $recipient_id,
171
- $payout,
172
- $settings['logs']['receiving'],
173
- $sender_id,
174
- $data,
175
- $point_type
176
- );
177
-
178
- // Let others play once transaction is completed
179
- do_action( 'mycred_transfer_completed', $transaction_id, $request, $settings );
180
-
181
- // Return the good news
182
- $result = array(
183
- 'amount' => $payout,
184
- 'css' => '.mycred-balance-' . $point_type,
185
- 'balance' => $mycred->format_creds( $attempt_check ),
186
- 'zero' => ( ( $attempt_check <= $mycred->zero() ) ? true : false )
187
- );
188
-
189
- }
190
-
191
- }
192
-
193
- return apply_filters( 'mycred_new_transfer', $result, $request, $attempt_check );
194
-
195
- }
196
- endif;
197
-
198
- /**
199
- * Get Users Transfer History
200
- * @since 1.3.3
201
- * @version 1.0
202
- */
203
- if ( ! function_exists( 'mycred_get_users_transfer_history' ) ) :
204
- function mycred_get_users_transfer_history( $user_id, $type = MYCRED_DEFAULT_TYPE_KEY, $key = NULL ) {
205
-
206
- if ( $key === NULL )
207
- $key = 'mycred_transactions';
208
-
209
- if ( $type != MYCRED_DEFAULT_TYPE_KEY && $type != '' )
210
- $key .= '_' . $type;
211
-
212
- $default = array(
213
- 'frame' => '',
214
- 'amount' => 0
215
- );
216
- return mycred_apply_defaults( $default, mycred_get_user_meta( $user_id, $key, '', true ) );
217
-
218
- }
219
- endif;
220
-
221
- /**
222
- * Render Transfer Message
223
- * @since 1.7.6
224
- * @version 1.0
225
- */
226
- if ( ! function_exists( 'mycred_transfer_render_message' ) ) :
227
- function mycred_transfer_render_message( $original = '', $data = array() ) {
228
-
229
- if ( empty( $original ) || empty( $data ) ) return $original;
230
-
231
- // Default message
232
- $message = apply_filters( 'mycred_transfer_default_message', '-', $original, $data );
233
-
234
- // Get saved message
235
- if ( ! empty( $data ) && array_key_exists( 'message', $data ) && ! empty( $data['message'] ) )
236
- $message = $data['message'];
237
-
238
- $content = str_replace( '%transfer_message%', $message, $original );
239
-
240
- return apply_filters( 'mycred_transfer_message', $content, $original, $message, $data );
241
-
242
- }
243
- endif;
244
-
245
- /**
246
- * Update Users Transfer History
247
- * @since 1.3.3
248
- * @version 1.0
249
- */
250
- if ( ! function_exists( 'mycred_update_users_transfer_history' ) ) :
251
- function mycred_update_users_transfer_history( $user_id, $history, $type = MYCRED_DEFAULT_TYPE_KEY, $key = NULL ) {
252
-
253
- if ( $key === NULL )
254
- $key = 'mycred_transactions';
255
-
256
- if ( $type != MYCRED_DEFAULT_TYPE_KEY && $type != '' )
257
- $key .= '_' . $type;
258
-
259
- // Get current history
260
- $current = mycred_get_users_transfer_history( $user_id, $type, $key );
261
-
262
- // Reset
263
- if ( $history === true )
264
- $new_history = array(
265
- 'frame' => '',
266
- 'amount' => 0
267
- );
268
-
269
- // Update
270
- else $new_history = mycred_apply_defaults( $current, $history );
271
-
272
- mycred_update_user_meta( $user_id, $key, '', $new_history );
273
-
274
- }
275
- endif;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
addons/transfer/includes/mycred-transfer-shortcodes.php DELETED
@@ -1,357 +0,0 @@
1
- <?php
2
- if ( ! defined( 'myCRED_VERSION' ) ) exit;
3
-
4
- /**
5
- * Transfer Shortcode Render
6
- * Renders a transfer form that allows users to send points to other users.
7
- * @see http://mycred.me/functions/mycred_transfer_render/
8
- * @since 0.1
9
- * @version 1.7.3
10
- */
11
- if ( ! function_exists( 'mycred_transfer_render' ) ) :
12
- function mycred_transfer_render( $atts, $content = NULL ) {
13
-
14
- global $mycred_do_transfer;
15
-
16
- // Settings
17
- $mycred = mycred();
18
- $pref = mycred_get_addon_settings( 'transfers' );
19
- $output = '';
20
-
21
- // Get Attributes
22
- extract( shortcode_atts( array(
23
- 'button' => '',
24
- 'pay_to' => '',
25
- 'show_balance' => 0,
26
- 'show_limit' => 0,
27
- 'ref' => 'transfer',
28
- 'amount' => '',
29
- 'placeholder' => '',
30
- 'types' => $pref['types'],
31
- 'excluded' => '',
32
- 'recipient_label' => __( 'Recipient', 'mycred' ),
33
- 'amount_label' => __( 'Amount', 'mycred' ),
34
- 'balance_label' => __( 'Balance', 'mycred' ),
35
- 'message_label' => __( 'Message', 'mycred' )
36
- ), $atts ) );
37
-
38
- if ( $ref == '' )
39
- $ref = 'transfer';
40
-
41
- // If we are not logged in
42
- if ( ! is_user_logged_in() ) {
43
-
44
- if ( isset( $pref['templates']['login'] ) && ! empty( $pref['templates']['login'] ) )
45
- $content .= '<p class="mycred-transfer-login">' . $mycred->template_tags_general( $pref['templates']['login'] ) . '</p>';
46
-
47
- return do_shortcode( $content );
48
-
49
- }
50
-
51
- $charge_from = get_current_user_id();
52
-
53
- // Point Types
54
- if ( ! is_array( $types ) )
55
- $raw = explode( ',', $types );
56
- else
57
- $raw = $types;
58
-
59
- $clean = array();
60
- foreach ( $raw as $id ) {
61
-
62
- $id = sanitize_key( $id );
63
- if ( $id != '' )
64
- $clean[] = sanitize_key( $id );
65
-
66
- }
67
-
68
- $available_types = array();
69
- $available_balances = array();
70
-
71
- // Default
72
- if ( count( $clean ) == 1 ) {
73
-
74
- $point_type = $clean[0];
75
- if ( $point_type != MYCRED_DEFAULT_TYPE_KEY )
76
- $mycred = mycred( $point_type );
77
-
78
- // Make sure user is not excluded
79
- if ( $mycred->exclude_user( $charge_from ) ) return '<div class="row"><div class="col-lg-12 col-md-12 col-sm-12 col-xs-12"><p>' . $excluded . '</p></div></div>';
80
-
81
- // See if we can send the lowest value
82
- $status = mycred_user_can_transfer( $charge_from, $mycred->get_lowest_value(), $point_type, $ref );
83
- $balance = $mycred->get_users_balance( $charge_from );
84
-
85
- // Error. Not enough creds
86
- if ( $status === 'low' ) {
87
-
88
- if ( isset( $pref['errors']['low'] ) && ! empty( $pref['errors']['low'] ) ) {
89
- $no_cred = str_replace( '%limit%', $pref['limit']['limit'], $pref['errors']['low'] );
90
- $no_cred = str_replace( '%Limit%', ucwords( $pref['limit']['limit'] ), $no_cred );
91
- $no_cred = str_replace( '%left%', $mycred->format_creds( $status ), $no_cred );
92
- $output .= '<p class="mycred-transfer-low">' . $mycred->template_tags_general( $no_cred ) . '</p>';
93
- }
94
-
95
- return do_shortcode( $output );
96
-
97
- }
98
-
99
- // Error. Over limit
100
- if ( $status === 'limit' ) {
101
-
102
- if ( isset( $pref['errors']['over'] ) && ! empty( $pref['errors']['over'] ) ) {
103
- $no_cred = str_replace( '%limit%', $pref['limit']['limit'], $pref['errors']['over'] );
104
- $no_cred = str_replace( '%Limit%', ucwords( $pref['limit']['limit'] ), $no_cred );
105
- $no_cred = str_replace( '%left%', $mycred->format_creds( $status ), $no_cred );
106
- $output .= '<p class="mycred-transfer-over">' . $mycred->template_tags_general( $no_cred ) . '</p>';
107
- }
108
-
109
- return do_shortcode( $output );
110
-
111
- }
112
-
113
- $available_types[ MYCRED_DEFAULT_TYPE_KEY ] = $mycred->plural();
114
- $balance_template = $pref['templates']['balance'];
115
- $balance_template = str_replace( '%cred%', '<span class="mycred-balance-' . MYCRED_DEFAULT_TYPE_KEY . '">' . $balance . '</span>', $balance_template );
116
- $balance_template = str_replace( array( '%cred_f%', '%balance%' ), '<span class="mycred-balance-' . MYCRED_DEFAULT_TYPE_KEY . '">' . $mycred->format_creds( $balance ) . '</span>', $balance_template );
117
- $available_balances[ MYCRED_DEFAULT_TYPE_KEY ] = $mycred->template_tags_general( $balance_template );
118
-
119
- }
120
-
121
- // Multiple
122
- else {
123
-
124
- foreach ( $clean as $point_type ) {
125
-
126
- $points = mycred( $point_type );
127
- if ( $points->exclude_user( $charge_from ) ) continue;
128
-
129
- // See if we can send the lowest value
130
- $status = mycred_user_can_transfer( $charge_from, $points->get_lowest_value(), $point_type, $ref );
131
- if ( $status === 'low' || $status === 'limit' ) continue;
132
-
133
- $balance = $points->get_users_balance( $charge_from );
134
-
135
- $available_types[ $point_type ] = $points->plural();
136
- $balance_template = $pref['templates']['balance'];
137
- $balance_template = str_replace( '%cred%', '<span class="mycred-balance-' . $point_type . '">' . $balance . '</span>', $balance_template );
138
- $balance_template = str_replace( array( '%cred_f%', '%balance%' ), '<span class="mycred-balance-' . $point_type . '">' . $points->format_creds( $balance ) . '</span>', $balance_template );
139
- $available_balances[ $point_type ] = $points->template_tags_general( $balance_template );
140
-
141
- }
142
-
143
- // User does not have access
144
- if ( count( $available_types ) == 0 )
145
- return '<div class="row"><div class="col-lg-12 col-md-12 col-sm-12 col-xs-12"><p>' . $excluded . '</p></div></div>';
146
-
147
- }
148
-
149
- // Flag for scripts & styles
150
- $mycred_do_transfer = true;
151
-
152
- // Placeholder
153
- if ( $placeholder == '' ) {
154
-
155
- $pln = '';
156
- if ( $pref['autofill'] == 'user_login' )
157
- $pln = __( 'username', 'mycred' );
158
-
159
- elseif ( $pref['autofill'] == 'user_email' )
160
- $pln = __( 'email', 'mycred' );
161
-
162
- $placeholder = sprintf( apply_filters( 'mycred_transfer_to_placeholder', __( 'recipients %s', 'mycred' ), $pref, $atts ), $pln );
163
-
164
- }
165
-
166
- // Recipient Input field
167
- $to_input = '<input type="text" name="mycred_new_transfer[recipient_id]" value="" aria-required="true" class="mycred-autofill form-control" data-form="' . $ref . '" placeholder="' . $placeholder . '" />';
168
-
169
- // If recipient is set, pre-populate it with the recipients details
170
- if ( $pay_to != '' ) {
171
-
172
- $pay_to = mycred_get_user_id( $pay_to );
173
- $user = get_userdata( $pay_to );
174
- if ( $user !== false ) {
175
-
176
- $value = $user->display_name;
177
- if ( isset( $user->$pref['autofill'] ) )
178
- $value = $user->$pref['autofill'];
179
-
180
- $to_input = '<p class="form-control-static">' . $value . '</p><input type="hidden" name="mycred_new_transfer[recipient_id]" value="' . ( ( isset( $user->$pref['autofill'] ) ) ? $user->$pref['autofill'] : $pay_to ) . '" />';
181
-
182
- }
183
-
184
- }
185
-
186
- $to_input = apply_filters( 'mycred_transfer_to_field', $to_input, $pref, $atts );
187
-
188
- // Show Balance
189
- $extras = array();
190
- if ( (bool) $show_balance && ! empty( $pref['templates']['balance'] ) ) {
191
-
192
- if ( ! empty( $available_balances ) ) {
193
- foreach ( $available_balances as $balance_type => $balance ) {
194
- $extras[] = $balance;
195
- }
196
- }
197
-
198
- }
199
-
200
-
201
- // Show Limits
202
- if ( (bool) $show_limit === true && ! empty( $pref['templates']['limit'] ) && $pref['limit']['limit'] != 'none' && count( $available_types ) == 1 ) {
203
-
204
- $limit_text = str_replace( '%_limit%', $pref['limit']['limit'], $pref['templates']['limit'] );
205
- $limit_text = str_replace( '%limit%', ucwords( $pref['limit']['limit'] ), $limit_text );
206
- $limit_text = str_replace( '%left%', $mycred->format_creds( $status ), $limit_text );
207
- $extras[] = $mycred->template_tags_general( $limit_text );
208
-
209
- }
210
-
211
- if ( $button == '' )
212
- $button = $pref['templates']['button'];
213
-
214
- // Main output
215
- ob_start();
216
-
217
- ?>
218
- <div class="mycred-transfer-cred-wrapper"<?php if ( $ref != '' ) echo ' id="transfer-form-' . $ref . '"'; ?>>
219
- <form class="form mycred-transfer mycred-transfer-form" id="mycred-transfer-form-<?php echo esc_attr( $ref ); ?>" method="post" data-ref="<?php echo esc_attr( $ref ); ?>" action="">
220
-
221
- <?php do_action( 'mycred_transfer_form_start', $atts, $pref ); ?>
222
-
223
- <div class="row">
224
-
225
- <div class="col-lg-6 col-md-6 col-sm-12 col-xs-12">
226
- <div class="form-group select-recipient-wrapper">
227
- <?php if ( $recipient_label != '' ) : ?><label><?php echo $recipient_label; ?>:</label><?php endif; ?>
228
- <?php echo $to_input; ?>
229
- </div>
230
- <?php do_action( 'mycred_transfer_form_to', $atts, $pref ); ?>
231
- </div>
232
-
233
- <?php
234
-
235
- if ( count( $available_types ) == 1 ) {
236
-
237
- ?>
238
- <div class="col-lg-6 col-md-6 col-sm-12 col-xs-12">
239
- <div class="form-group select-amount-wrapper">
240
- <?php if ( $amount_label != '' ) : ?><label><?php echo $amount_label; ?>:</label><?php endif; ?>
241
- <?php if ( $amount == '' ) : ?>
242
- <input type="text" name="mycred_new_transfer[amount]" placeholder="<?php echo $mycred->get_lowest_value(); ?>" class="form-control" value="" />
243
- <?php else : ?>
244
- <input type="hidden" name="mycred_new_transfer[amount]" value="<?php echo $amount; ?>" />
245
- <p class="form-control-static"><?php echo $mycred->format_creds( $amount ); ?></p>
246
- <?php endif; ?>
247
- <input type="hidden" name="mycred_new_transfer[ctype]" value="<?php echo $clean[0]; ?>" />
248
- </div>
249
- <?php do_action( 'mycred_transfer_form_amount', $atts, $pref ); ?>
250
- </div>
251
- <?php
252
-
253
- }
254
-
255
- else {
256
-
257
- ?>
258
- <div class="col-lg-3 col-md-3 col-sm-6 col-xs-12">
259
- <div class="form-group select-amount-wrapper">
260
- <?php if ( $amount_label != '' ) : ?><label><?php echo $amount_label; ?>:</label><?php endif; ?>
261
- <?php if ( $amount == '' ) : ?>
262
- <input type="text" name="mycred_new_transfer[amount]" placeholder="<?php echo $mycred->get_lowest_value(); ?>" class="form-control" value="" />
263
- <?php else : ?>
264
- <input type="hidden" name="mycred_new_transfer[amount]" value="<?php echo $amount; ?>" />
265
- <p class="form-control-static"><?php echo $mycred->format_creds( $amount ); ?></p>
266
- <?php endif; ?>
267
- </div>
268
- <?php do_action( 'mycred_transfer_form_amount', $atts, $pref ); ?>
269
- </div>
270
- <div class="col-lg-3 col-md-3 col-sm-6 col-xs-12">
271
- <div class="form-group select-point-type-wrapper">
272
- <?php if ( $balance_label != '' ) : ?><label><?php echo $balance_label; ?>:</label><?php endif; ?>
273
- <select name="mycred_new_transfer[ctype]" class="form-control">
274
- <?php foreach ( $available_types as $type => $plural ) echo '<option value="' . $type . '">' . $plural . '</option>'; ?>
275
- </select>
276
- </div>
277
- </div>
278
- <?php
279
-
280
- }
281
-
282
- ?>
283
- </div>
284
- <?php
285
-
286
- // Messaging if enabled
287
- if ( array_key_exists( 'message', $pref ) && $pref['message'] > 0 ) {
288
-
289
- ?>
290
- <div class="row">
291
- <div class="col-lg-12 col-md-12 col-sm-12 col-xs-12">
292
- <div class="form-group">
293
- <label><?php echo $message_label; ?></label>
294
- <input type="text" name="mycred_new_transfer[message]" class="form-control" value="" />
295
- </div>
296
- </div>
297
- </div>
298
- <?php
299
-
300
- }
301
-
302
- // Show extras
303
- if ( ! empty( $extras ) ) {
304
-
305
- $extras_to_show = count( $extras );
306
- $col = 'col-lg-12 col-md-12 col-sm-12 col-xs-12';
307
- if ( $extras_to_show == 2 )
308
- $col = 'col-lg-6 col-md-6 col-sm-12 col-xs-12';
309
- elseif ( $extras_to_show == 3 )
310
- $col = 'col-lg-4 col-md-4 col-sm-12 col-xs-12';
311
- elseif ( $extras_to_show == 4 )
312
- $col = 'col-lg-3 col-md-3 col-sm-12 col-xs-12';
313
- elseif ( $extras_to_show > 4 )
314
- $col = 'col-lg-2 col-md-2 col-sm-12 col-xs-12';
315
-
316
- ?>
317
- <div class="row">
318
-
319
- <?php foreach ( $extras as $extra_content ) { ?>
320
-
321
- <div class="<?php echo $col; ?>">
322
- <?php echo do_shortcode( $extra_content ); ?>
323
- </div>
324
-
325
- <?php } ?>
326
-
327
- </div>
328
- <?php
329
-
330
- }
331
-
332
- do_action( 'mycred_transfer_form_extra', $atts, $pref );
333
-
334
- ?>
335
- <div class="row">
336
-
337
- <div class="col-lg-12 col-md-12 col-sm-12 col-xs-12">
338
- <input type="hidden" name="mycred_new_transfer[token]" value="<?php echo wp_create_nonce( 'mycred-new-transfer-' . $ref ); ?>" />
339
- <input type="hidden" name="mycred_new_transfer[reference]" value="<?php echo esc_attr( $ref ); ?>" />
340
- <input type="submit" class="btn btn-primary btn-block btn-lg mycred-submit-transfer" value="<?php echo esc_attr( $button ); ?>" />
341
- </div>
342
-
343
- </div>
344
-
345
- <?php do_action( 'mycred_transfer_form_end', $atts, $pref ); ?>
346
-
347
- </form>
348
- </div>
349
- <?php
350
-
351
- $output = ob_get_contents();
352
- ob_end_clean();
353
-
354
- return do_shortcode( apply_filters( 'mycred_transfer_render', $output, $atts, $mycred ) );
355
-
356
- }
357
- endif;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
addons/transfer/includes/mycred-transfer-widgets.php DELETED
@@ -1,157 +0,0 @@
1
- <?php
2
- if ( ! defined( 'myCRED_VERSION' ) ) exit;
3
-
4
- /**
5
- * Widget: myCRED Transfer
6
- * @since 0.1
7
- * @version 1.2.2
8
- */
9
- if ( ! class_exists( 'myCRED_Widget_Transfer' ) ) :
10
- class myCRED_Widget_Transfer extends WP_Widget {
11
-
12
- /**
13
- * Construct
14
- */
15
- public function __construct() {
16
-
17
- parent::__construct(
18
- 'mycred_widget_transfer',
19
- sprintf( __( '(%s) Transfer', 'mycred' ), mycred_label( true ) ),
20
- array(
21
- 'classname' => 'widget-my-cred-transfer',
22
- 'description' => __( 'Allow transfers between users.', 'mycred' )
23
- )
24
- );
25
-
26
- }
27
-
28
- /**
29
- * Widget Output
30
- */
31
- public function widget( $args, $instance ) {
32
-
33
- extract( $args, EXTR_SKIP );
34
-
35
- $instance = shortcode_atts( array(
36
- 'title' => '',
37
- 'button' => 'Transfer',
38
- 'pay_to' => '',
39
- 'show_balance' => 0,
40
- 'show_limit' => 0,
41
- 'reference' => 'transfer',
42
- 'amount' => '',
43
- 'excluded' => '',
44
- 'types' => MYCRED_DEFAULT_TYPE_KEY,
45
- 'placeholder' => ''
46
- ), $instance );
47
-
48
- echo $before_widget;
49
-
50
- // Title
51
- if ( ! empty( $instance['title'] ) )
52
- echo $before_title . $instance['title'] . $after_title;
53
-
54
- // Let the shortcode to the job
55
- echo mycred_transfer_render( array(
56
- 'button' => $instance['button'],
57
- 'pay_to' => $instance['pay_to'],
58
- 'show_balance' => $instance['show_balance'],
59
- 'show_limit' => $instance['show_limit'],
60
- 'ref' => $instance['reference'],
61
- 'amount' => $instance['amount'],
62
- 'excluded' => $instance['excluded'],
63
- 'types' => $instance['types'],
64
- 'placeholder' => $instance['placeholder']
65
- ) );
66
-
67
- echo $after_widget;
68
-
69
- }
70
-
71
- /**
72
- * Outputs the options form on admin
73
- */
74
- public function form( $instance ) {
75
-
76
- // Defaults
77
- $title = isset( $instance['title'] ) ? $instance['title'] : 'Transfer';
78
- $show_balance = isset( $instance['show_balance'] ) ? $instance['show_balance'] : 0;
79
- $show_limit = isset( $instance['show_limit'] ) ? $instance['show_balance'] : 0;
80
- $button = isset( $instance['button'] ) ? $instance['button'] : 'Transfer';
81
- $amount = isset( $instance['amount'] ) ? $instance['amount'] : '';
82
- $reference = isset( $instance['reference'] ) ? $instance['reference'] : 'transfer';
83
- $recipient = isset( $instance['pay_to'] ) ? $instance['pay_to'] : '';
84
- $point_types = isset( $instance['types'] ) ? $instance['types'] : MYCRED_DEFAULT_TYPE_KEY;
85
- $excluded = isset( $instance['excluded'] ) ? $instance['excluded'] : '';
86
- $placeholder = isset( $instance['placeholder'] ) ? $instance['placeholder'] : '';
87
-
88
- ?>
89
- <!-- Widget Options -->
90
- <p class="myCRED-widget-field">
91
- <label for="<?php echo esc_attr( $this->get_field_id( 'title' ) ); ?>"><?php _e( 'Title', 'mycred' ); ?>:</label>
92
- <input id="<?php echo esc_attr( $this->get_field_id( 'title' ) ); ?>" name="<?php echo esc_attr( $this->get_field_name( 'title' ) ); ?>" type="text" placeholder="<?php _e( 'optional', 'mycred' ); ?>" value="<?php echo esc_attr( $title ); ?>" class="widefat" />
93
- </p>
94
- <p class="myCRED-widget-field">
95
- <label for="<?php echo esc_attr( $this->get_field_id( 'show_balance' ) ); ?>"><input type="checkbox" name="<?php echo esc_attr( $this->get_field_name( 'show_balance' ) ); ?>" id="<?php echo esc_attr( $this->get_field_id( 'show_balance' ) ); ?>" value="1"<?php checked( $show_balance, true ); ?> class="checkbox" /> <?php _e( 'Show users balance', 'mycred' ); ?></label>
96
- </p>
97
- <p class="myCRED-widget-field">
98
- <label for="<?php echo esc_attr( $this->get_field_id( 'show_limit' ) ); ?>"><input type="checkbox" name="<?php echo esc_attr( $this->get_field_name( 'show_limit' ) ); ?>" id="<?php echo esc_attr( $this->get_field_id( 'show_limit' ) ); ?>" value="1"<?php checked( $show_balance, true ); ?> class="checkbox" /> <?php _e( 'Show users limit', 'mycred' ); ?></label>
99
- </p>
100
- <p class="myCRED-widget-field">
101
- <label for="<?php echo esc_attr( $this->get_field_id( 'button' ) ); ?>"><?php _e( 'Button Label', 'mycred' ); ?>:</label>
102
- <input id="<?php echo esc_attr( $this->get_field_id( 'button' ) ); ?>" name="<?php echo esc_attr( $this->get_field_name( 'button' ) ); ?>" type="text" placeholder="<?php _e( 'required', 'mycred' ); ?>" value="<?php echo esc_attr( $button ); ?>" class="widefat" />
103
- </p>
104
- <p class="myCRED-widget-field">
105
- <label for="<?php echo esc_attr( $this->get_field_id( 'amount' ) ); ?>"><?php _e( 'Amount', 'mycred' ); ?>:</label>
106
- <input id="<?php echo esc_attr( $this->get_field_id( 'amount' ) ); ?>" name="<?php echo esc_attr( $this->get_field_name( 'amount' ) ); ?>" type="text" placeholder="<?php _e( 'required', 'mycred' ); ?>" value="<?php echo esc_attr( $amount ); ?>" class="widefat" />
107
- </p>
108
- <p class="myCRED-widget-field">
109
- <label for="<?php echo esc_attr( $this->get_field_id( 'reference' ) ); ?>"><?php _e( 'Reference', 'mycred' ); ?>:</label>
110
- <input id="<?php echo esc_attr( $this->get_field_id( 'reference' ) ); ?>" name="<?php echo esc_attr( $this->get_field_name( 'reference' ) ); ?>" type="text" placeholder="<?php _e( 'required', 'mycred' ); ?>" value="<?php echo esc_attr( $reference ); ?>" class="widefat" />
111
- </p>
112
- <p class="myCRED-widget-field">
113
- <label for="<?php echo esc_attr( $this->get_field_id( 'pay_to' ) ); ?>"><?php _e( 'Recipient', 'mycred' ); ?>:</label>
114
- <input id="<?php echo esc_attr( $this->get_field_id( 'pay_to' ) ); ?>" name="<?php echo esc_attr( $this->get_field_name( 'pay_to' ) ); ?>" type="text" placeholder="<?php _e( 'optional', 'mycred' ); ?>" value="<?php echo esc_attr( $recipient ); ?>" class="widefat" />
115
- </p>
116
- <p class="myCRED-widget-field">
117
- <label for="<?php echo esc_attr( $this->get_field_id( 'placeholder' ) ); ?>"><?php _e( 'Recipient Placeholder', 'mycred' ); ?>:</label>
118
- <input id="<?php echo esc_attr( $this->get_field_id( 'placeholder' ) ); ?>" name="<?php echo esc_attr( $this->get_field_name( 'placeholder' ) ); ?>" type="text" placeholder="<?php _e( 'optional', 'mycred' ); ?>" value="<?php echo esc_attr( $placeholder ); ?>" class="widefat" />
119
- </p>
120
- <p class="myCRED-widget-field">
121
- <label for="<?php echo esc_attr( $this->get_field_id( 'types' ) ); ?>"><?php _e( 'Point Types', 'mycred' ); ?>:</label>
122
- <input id="<?php echo esc_attr( $this->get_field_id( 'types' ) ); ?>" name="<?php echo esc_attr( $this->get_field_name( 'types' ) ); ?>" type="text" placeholder="<?php _e( 'required', 'mycred' ); ?>" value="<?php echo esc_attr( $point_types ); ?>" class="widefat" />
123
- </p>
124
- <p class="myCRED-widget-field">
125
- <label for="<?php echo esc_attr( $this->get_field_id( 'excluded' ) ); ?>"><?php _e( 'Message for Excluded Users', 'mycred' ); ?>:</label>
126
- <input id="<?php echo esc_attr( $this->get_field_id( 'excluded' ) ); ?>" name="<?php echo esc_attr( $this->get_field_name( 'excluded' ) ); ?>" placeholder="<?php _e( 'optional', 'mycred' ); ?>" type="text" value="<?php echo esc_attr( $excluded ); ?>" class="widefat" />
127
- </p>
128
- <?php
129
-
130
- }
131
-
132
- /**
133
- * Processes widget options to be saved
134
- */
135
- public function update( $new_instance, $old_instance ) {
136
-
137
- $instance = $old_instance;
138
-
139
- $instance['title'] = wp_kses_post( $new_instance['title'] );
140
- $instance['show_balance'] = ( isset( $new_instance['show_balance'] ) ) ? 1 : 0;
141
- $instance['show_limit'] = ( isset( $new_instance['show_limit'] ) ) ? 1 : 0;
142
- $instance['button'] = sanitize_text_field( $new_instance['button'] );
143
- $instance['amount'] = sanitize_text_field( $new_instance['amount'] );
144
- $instance['reference'] = sanitize_key( $new_instance['reference'] );
145
- $instance['pay_to'] = sanitize_text_field( $new_instance['pay_to'] );
146
- $instance['placeholder'] = sanitize_text_field( $new_instance['placeholder'] );
147
- $instance['types'] = sanitize_text_field( $new_instance['types'] );
148
- $instance['excluded'] = sanitize_text_field( $new_instance['excluded'] );
149
-
150
- mycred_flush_widget_cache( 'mycred_widget_transfer' );
151
-
152
- return $instance;
153
-
154
- }
155
-
156
- }
157
- endif;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
addons/{sell-content/assets → transfer/js}/index.php RENAMED
File without changes
addons/transfer/js/transfer.js ADDED
@@ -0,0 +1,111 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /**
2
+ * myCRED Transfer jQuery
3
+ * Handles transfer requests and autocomplete of recipient search.
4
+ *
5
+ * @requires jQuery
6
+ * @requires jQuery UI
7
+ * @requires jQuery Autocomplete
8
+ * @since 0.1
9
+ * @version 1.4
10
+ */
11
+ jQuery(function($){
12
+ // Transfer function
13
+ var transfer_creds = function( submitted_form, label ) {
14
+ $.ajax({
15
+ type : "POST",
16
+ data : {
17
+ action : 'mycred-transfer-creds',
18
+ form : submitted_form,
19
+ token : myCRED.token
20
+ },
21
+ dataType : "JSON",
22
+ url : myCRED.ajaxurl,
23
+ // Before we start
24
+ beforeSend : function() {
25
+ // Prevent users from clicking multiple times
26
+ $( '.mycred-click' ).val( myCRED.working );
27
+ $( '.mycred-click' ).attr( 'disabled', 'disabled' );
28
+ },
29
+ // On Successful Communication
30
+ success : function( data ) {
31
+ $( '.mycred-click' ).val( label );
32
+ $( '.mycred-click' ).removeAttr( 'disabled' );
33
+
34
+ // Error
35
+ if ( myCRED[ data ] !== undefined )
36
+ alert( myCRED[ data ] );
37
+
38
+ // Completed
39
+ else if ( data == 'ok' ) {
40
+ alert( myCRED.completed );
41
+
42
+ // If reload is set
43
+ if ( myCRED.reload == '1' )
44
+ location.reload();
45
+ }
46
+
47
+ // WP Nonce no longer valid / we have been logged out
48
+ else if ( data == '-1' || data == 0 )
49
+ location.reload();
50
+
51
+ // All else
52
+ else {
53
+ $('.mycred-click').attr( 'value', data );
54
+ if ( myCRED.reload == '1' )
55
+ location.reload();
56
+ }
57
+ }
58
+ });
59
+ };
60
+
61
+ // Autocomplete
62
+ // @api http://api.jqueryui.com/autocomplete/
63
+ var cache = {};
64
+ $( 'input.mycred-autofill' ).autocomplete({
65
+ minLength: 2,
66
+ source: function( request, response ) {
67
+ var term = request.term;
68
+ if ( term in cache ) {
69
+ response( cache[ term ] );
70
+ return;
71
+ }
72
+
73
+ var send = {
74
+ action : "mycred-autocomplete",
75
+ token : myCRED.atoken,
76
+ string : request
77
+ };
78
+ $.getJSON( myCRED.ajaxurl, send, function( data, status, xhr ) {
79
+ cache[ term ] = data;
80
+ // Debug - uncomment to use
81
+ //console.log( data );
82
+ //console.log( status );
83
+ response( data );
84
+ });
85
+ },
86
+ messages: {
87
+ noResults: '',
88
+ results: function() {}
89
+ },
90
+ appendTo : 'div.transfer-to'
91
+ });
92
+
93
+ // Attempt Transfer
94
+ $( '.mycred-click' ).click(function(){
95
+
96
+ // The form
97
+ var the_form = $(this).parent().parent().parent();
98
+
99
+ // To:
100
+ var receipient = $(this).parent().prev().children( 'div' ).children( 'input' ).val();
101
+
102
+ // Amount:
103
+ var creds = $(this).prev().children( 'input[name=mycred-transfer-amount]' ).val();
104
+
105
+ // If elements are not emepty attempt transfer
106
+ if ( receipient != '' && creds != '' ) {
107
+ transfer_creds( the_form.serialize(), $(this).val() );
108
+ }
109
+
110
+ });
111
+ });
assets/css/{mycred-admin.css → admin.css} RENAMED
@@ -1,17 +1,16 @@
1
  /**
2
  * myCRED Admin Styling
3
  * @since 0.1
4
- * @version 1.4
5
  */
6
- #myCRED-wrap table th#creds { width: 10%; }
 
 
 
7
  #myCRED-wrap table .alternate { background-color: white; }
8
- #myCRED-wrap table tr.deleted-row td, #myCRED-wrap table tr.deleted-row th { background-color: red !important; }
9
- #myCRED-wrap table tr.deleted-row td, #myCRED-wrap table tr.deleted-row td * { color: white !important; }
10
- #myCRED-wrap table tr.updated-row td, #myCRED-wrap table tr.updated-row th { background-color: yellow; }
11
-
12
- #myCRED-wrap input[type=radio] { margin-top: 0; }
13
- #myCRED-wrap input.large-text, #myCRED-wrap textarea.large-text { display: block; width: 80%; }
14
- #myCRED-wrap textarea.large-text { margin-bottom: 6px; }
15
 
16
  /* Text Alignments */
17
  .tl { text-align: left; }
@@ -22,54 +21,29 @@
22
  /* Specifics */
23
  #myCRED-wrap p.submit { margin-top: 0; padding-top: 0; }
24
  #mycred-social { text-align: right; }
25
- body.post-type-buycred_payment a.add-new-h2, body.post-type-buycred_payment .view-switch { display: none; }
26
 
27
  /* General */
28
- #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; min-height: 39px; }
29
  body.version-3-8 #myCRED-wrap .h2 { line-height: 15px; font-size: 18px; }
30
  body.version-3-8 #myCRED-wrap .h2.description { line-height: 22px; }
31
- body.version-3-8 #myCRED-wrap .h2 input[type="text"], body.version-3-8 #myCRED-wrap .h2 input[type="number"] { font-size: 14px; }
32
- #myCRED-wrap .h2 input[type="text"], #myCRED-wrap .h2 input[type="password"], #myCRED-wrap .h2 input[type="number"] { line-height: inherit; }
33
- #myCRED-wrap .h2 input[type="number"] { height: auto; }
34
- #myCRED-wrap #mycred-update-log-decimals { height: 36px; line-height: 36px; margin-top: 1px; }
35
  #mycred-social-media { display: block; float: right; }
36
  #mycred-social-media a { margin-left: 12px; }
37
- p span.description { display: block; line-height: 16px; }
38
- .modal .mycred-container .row { margin-bottom: 6px; }
39
- .mycred-container p { margin: 3px 0 12px 0; }
40
- .mycred-container .list p { margin: 0 0 3px 0; }
41
- .mycred-container p code { padding: 2px 4px; }
42
-
43
- .inline-warning { background: #fff; border-left: 4px solid #dc3232; -webkit-box-shadow: 0 1px 1px 0 rgba(0,0,0,.1); box-shadow: 0 1px 1px 0 rgba(0,0,0,.1); margin: 0 0 0 0; padding: 1px 12px; }
44
-
45
- #myCRED-wrap .alert { padding: 24px; margin: 0 0 12px 0; }
46
- #myCRED-wrap .alert-warning { background-color: orange; color: #333; }
47
- #myCRED-wrap .table { width: 100%; }
48
-
49
- .loading-indicator { height: 5px; width: 100%; position: relative; overflow: hidden; background-color: white; }
50
- .loading-indicator:before { display: block; position: absolute; content: ""; left: -200px; width: 200px; height: 5px; background-color: #c5d93d; animation: loading 2s linear infinite; }
51
- @keyframes loading { from { left: -200px; width: 30%; } 25% { width: 50%; } 50% { width: 50%; } 70% { width: 50%; } 80% { left: 75%; } 95% { left: 100%; } to { left: 100%; } }
52
 
53
  /* Accordion */
54
  #myCRED-wrap #accordion { margin: 24px 0; padding: 0; float: none; clear: both; }
55
  body #myCRED-wrap #accordion { border-top: none; border-bottom: 1px solid #dedede; }
56
  body.version-3-8 #myCRED-wrap #accordion { border-top: 1px solid #dedede; border-bottom: 1px solid #fafafa; }
57
- #myCRED-wrap #accordion>h4 { font-size: 18px; line-height: 48px; font-weight: normal; color: #464646; font-family: "Open Sans", sans-serif; letter-spacing: 1px; width: 100%; text-align: left; }
58
  #myCRED-wrap #accordion>h4:focus { outline: none; }
59
  #myCRED-wrap #accordion>h4:hover { cursor: pointer; }
60
- #myCRED-wrap #accordion .ui-accordion-header { padding: 0; margin: 0; background-color: transparent; background: none; border-left: none; border-right: none; }
61
- #myCRED-wrap .ui-accordion .ui-accordion-header .ui-accordion-header-icon { display: none; }
62
  body #myCRED-wrap #accordion .ui-accordion-header { border-top: 1px solid #dedede; border-bottom: none; }
63
  body.version-3-8 #myCRED-wrap #accordion .ui-accordion-header { border-top: 1px solid #fafafa; border-bottom: 1px solid #dedede; }
64
  #myCRED-wrap #accordion .ui-accordion-header input { vertical-align: middle; margin-right: 24px; }
65
  #myCRED-wrap #accordion .ui-state-active { font-weight: normal; }
66
 
67
- #myCRED-wrap #accordion h4 .dashicons { display: block; width: 48px; height: 48px; margin: 0 0 0 0; padding: 0; float: left; line-height: 48px; font-size: 26px; }
68
- #myCRED-wrap #accordion h4 .dashicons.active { color: #46b450; }
69
- #myCRED-wrap #accordion h4 .dashicons.inactive { color: #dc3232; }
70
- #myCRED-wrap #accordion h4 .dashicons.static { color: #333; }
71
- #myCRED-wrap #accordion h4 .dashicons.debug { color: orange; }
72
-
73
  #myCRED-wrap #accordion h4 label { vertical-align: inherit; }
74
  #myCRED-wrap #accordion h4 .icon { display: block; width: 48px; height: 48px; margin: 0 0 0 0; padding: 0; float: left; line-height: 48px; }
75
  #myCRED-wrap #accordion h4 .icon { background-repeat: no-repeat; background-image: url(../images/admin-icons.png); background-position: 0 0; }
@@ -108,13 +82,12 @@ body.version-3-8 #myCRED-wrap #accordion .ui-accordion-header { border-top: 1px
108
  #myCRED-wrap #accordion h4 .core { background-position: 0 -528px; }
109
  #myCRED-wrap #accordion h4 .core.icon-active { background-position: -48px -528px; }
110
 
111
- #myCRED-wrap #accordion>div { margin: 0; padding: 12px; }
112
  #myCRED-wrap #accordion>div>p { margin-top: 0; }
113
  #myCRED-wrap #accordion .ui-accordion-content { display: none;float: none; clear: both; }
114
- body #myCRED-wrap #accordion .ui-accordion-content { border-top: 1px solid #dedede; border-bottom: none; background-color: transparent; background: none; border-left: none; border-right: none; }
115
  body.version-3-8 #myCRED-wrap #accordion .ui-accordion-content { border-top: 1px solid #fafafa; border-bottom: 1px solid #dedede; }
116
  #myCRED-wrap #accordion .ui-accordion-content .wrapper:after { content: "."; height: 0; visibility: hidden; margin: 0; padding: 0; }
117
- .ui-widget-overlay { position: fixed; top: 0; left: 0; width: 100%; height: 100%; background: repeat-x scroll 70% 70% #000; opacity: 0.7; overflow: hidden; background: repeat-x scroll 70% 70% #000; z-index: 99; }
118
 
119
  .ui-accordion-content>div.wrapper { display: block; margin: 0; padding: 0; float: none; clear: both; }
120
  .ui-accordion-content>div.wrapper .clear { height: 0; visibility: hidden; display: block; float: none; clear: both; }
@@ -128,19 +101,16 @@ body.version-3-8 #myCRED-wrap #accordion .ui-accordion-content { border-top: 1px
128
 
129
  /* Organized Lists */
130
  #myCRED-wrap ol { list-style-type: none; display: block; padding: 0 0 24px 20%; margin: 0; float: none; clear: right; }
131
- #myCRED-wrap ol.sub-bordered { padding-bottom: 12px; margin-bottom: 12px; border-bottom: 1px dashed #ddd; }
132
- #myCRED-wrap ol.slim { padding-bottom: 0; }
133
  #myCRED-wrap ol:after { content: "."; display: block; height: 0; clear: both; visibility: hidden; }
134
  #myCRED-wrap ol.inline li { display: block; float: left; padding: 0 6px 6px 12px; }
135
  #myCRED-wrap ol.inline li:first-child { padding-left: 0; }
136
- #myCRED-wrap ol.inline li.block { float: none; padding: 0; }
137
- #myCRED-wrap ol.inline.slim li.half { width: 49%; }
138
  #myCRED-wrap ol li.empty { display: block; height: 1px; float: none; clear: both; }
139
- #myCRED-wrap ol input.long { width: 85%; }
140
  #myCRED-wrap ol input.short { width: 80px; }
141
- #myCRED-wrap ol input[type="text"], #myCRED-wrap ol input[type="checkbox"], #myCRED-wrap ol input[type="radio"] { margin-right: 12px; }
 
142
  #myCRED-wrap ol li.option .h2, #myCRED-wrap ol li.option select, #myCRED-wrap ol li.option textarea { margin-left: 24px; }
143
- #myCRED-wrap ol li h3 { margin-top: 0; margin-bottom: 0; }
144
 
145
  /* Setup */
146
  #myCRED-wrap>h2 { }
@@ -164,25 +134,13 @@ body.version-3-8 #myCRED-wrap #accordion .ui-accordion-content { border-top: 1px
164
  #myCRED-wrap form.setup ul li input { margin-right: 12px; vertical-align: middle; }
165
 
166
  .version-3-8 #accordion pre { background-color: #ddd; color: #333; padding: 6px; }
 
 
 
167
  .mycred-actions { margin-bottom: 2em; }
168
- #mycred-badge { color: #222; background-color: white; }
 
169
 
170
  /* Export */
171
- #export-log-history { clear: both; float: none; padding: 24px 0; margin-top: 12px; border-top: 1px solid #E1E1E1; border-bottom: 1px solid #E1E1E1; margin-bottom: 12px; }
172
- #export-log-history input { outline: none; }
173
- #export-log-history p { margin-bottom: 0; }
174
-
175
- /* Exporter */
176
- #export-points { background-color: #f3f3f3; font-size: 14px; }
177
- #export-points .form { display: block; padding: 12px; }
178
- .mycred-export-points { font-family: "Open Sans",sans-serif; background-color: white !important; z-index: 9999 !important; border: none !important; border-radius: 0 !important; background-image: none !important; padding: 0 !important; overflow: visible !important; }
179
- .mycred-export-points.ui-dialog .ui-dialog-content { padding: 0 0 0 0; }
180
- .mycred-export-points .ui-widget-header { border: none !important; background: transparent !important; font-weight: normal !important; }
181
- .mycred-export-points .ui-dialog-titlebar { line-height: 24px !important; border-bottom: 1px solid #ddd !important; border-left: none; border-top: none; border-right: none; padding: 12px !important; border-radius: 0 !important; }
182
- .mycred-export-points .ui-dialog-titlebar:hover { cursor: move; }
183
- .mycred-export-points .ui-dialog-titlebar-close { float: right; margin: 0 12px 0 0; background: 0 0; border: none; -webkit-box-shadow: none; box-shadow: none; color: #666; cursor: pointer; display: block; padding: 0; position: absolute; top: 0; right: 0; width: 36px; height: 36px; text-align: center; font-size: 13px; line-height: 26px; vertical-align: top; white-space: nowrap; }
184
- .mycred-export-points .ui-icon { display: none !important; }
185
- .mycred-export-points .ui-button:focus, .mycred-export-points .ui-button:active { outline: none !important; }
186
- .mycred-export-points .ui-button .ui-button-text { display: block; text-indent: 0; }
187
- .mycred-export-points .ui-dialog-title { font-size: 22px; font-weight: 600; margin: 0 0 0 0; width: auto !important; float: none !important; }
188
- .mycred-export-points .form-control { width: 100%; margin-bottom: 6px; }
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; }
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; }
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; }
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 { }
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/bootstrap-grid.css DELETED
@@ -1,2 +0,0 @@
1
- /* Bootstrap Grid System 3.2 */
2
- @-ms-viewport { width: device-width; } .visible-xs, .visible-sm, .visible-md, .visible-lg { display: none !important; } .visible-xs-block, .visible-xs-inline, .visible-xs-inline-block, .visible-sm-block, .visible-sm-inline, .visible-sm-inline-block, .visible-md-block, .visible-md-inline, .visible-md-inline-block, .visible-lg-block, .visible-lg-inline, .visible-lg-inline-block { display: none !important; }@media (max-width: 767px) { .visible-xs { display: block !important; } table.visible-xs { display: table; } tr.visible-xs { display: table-row !important; } th.visible-xs, td.visible-xs { display: table-cell !important; }}@media (max-width: 767px) { .visible-xs-block { display: block !important; }}@media (max-width: 767px) { .visible-xs-inline { display: inline !important; }}@media (max-width: 767px) { .visible-xs-inline-block { display: inline-block !important; }}@media (min-width: 768px) and (max-width: 991px) { .visible-sm { display: block !important; } table.visible-sm { display: table; } tr.visible-sm { display: table-row !important; } th.visible-sm, td.visible-sm { display: table-cell !important; }}@media (min-width: 768px) and (max-width: 991px) { .visible-sm-block { display: block !important; }}@media (min-width: 768px) and (max-width: 991px) { .visible-sm-inline { display: inline !important; }}@media (min-width: 768px) and (max-width: 991px) { .visible-sm-inline-block { display: inline-block !important; }}@media (min-width: 992px) and (max-width: 1199px) { .visible-md { display: block !important; } table.visible-md { display: table; } tr.visible-md { display: table-row !important; } th.visible-md, td.visible-md { display: table-cell !important; }}@media (min-width: 992px) and (max-width: 1199px) { .visible-md-block { display: block !important; }}@media (min-width: 992px) and (max-width: 1199px) { .visible-md-inline { display: inline !important; }}@media (min-width: 992px) and (max-width: 1199px) { .visible-md-inline-block { display: inline-block !important; }}@media (min-width: 1200px) { .visible-lg { display: block !important; } table.visible-lg { display: table; } tr.visible-lg { display: table-row !important; } th.visible-lg, td.visible-lg { display: table-cell !important; }}@media (min-width: 1200px) { .visible-lg-block { display: block !important; }}@media (min-width: 1200px) { .visible-lg-inline { display: inline !important; }}@media (min-width: 1200px) { .visible-lg-inline-block { display: inline-block !important; }}@media (max-width: 767px) { .hidden-xs { display: none !important; }}@media (min-width: 768px) and (max-width: 991px) { .hidden-sm { display: none !important; }}@media (min-width: 992px) and (max-width: 1199px) { .hidden-md { display: none !important; }}@media (min-width: 1200px) { .hidden-lg { display: none !important; }} .visible-print { display: none !important; }@media print { .visible-print { display: block !important; } table.visible-print { display: table; } tr.visible-print { display: table-row !important; } th.visible-print, td.visible-print { display: table-cell !important; }} .visible-print-block { display: none !important; }@media print { .visible-print-block { display: block !important; }} .visible-print-inline { display: none !important; }@media print { .visible-print-inline { display: inline !important; }} .visible-print-inline-block { display: none !important; }@media print { .visible-print-inline-block { display: inline-block !important; }}@media print { .hidden-print { display: none !important; }} .container { margin-right: auto; margin-left: auto; padding-left: 12px; padding-right: 12px; }@media (min-width: 768px) { .container { width: 750px; }}@media (min-width: 992px) { .container { width: 970px; }}@media (min-width: 1200px) { .container { width: 1170px; }} .container-fluid { margin-right: auto; margin-left: auto; padding-left: 12px; padding-right: 12px; } .row { margin-left: -12px; margin-right: -12px; } .col, .col-xs-1, .col-sm-1, .col-md-1, .col-lg-1, .col-xs-2, .col-sm-2, .col-md-2, .col-lg-2, .col-xs-3, .col-sm-3, .col-md-3, .col-lg-3, .col-xs-4, .col-sm-4, .col-md-4, .col-lg-4, .col-xs-5, .col-sm-5, .col-md-5, .col-lg-5, .col-xs-6, .col-sm-6, .col-md-6, .col-lg-6, .col-xs-7, .col-sm-7, .col-md-7, .col-lg-7, .col-xs-8, .col-sm-8, .col-md-8, .col-lg-8, .col-xs-9, .col-sm-9, .col-md-9, .col-lg-9, .col-xs-10, .col-sm-10, .col-md-10, .col-lg-10, .col-xs-11, .col-sm-11, .col-md-11, .col-lg-11, .col-xs-12, .col-sm-12, .col-md-12, .col-lg-12 { position: relative; min-height: 1px; padding-left: 12px; padding-right: 12px; } .col, .col-xs-1, .col-xs-2, .col-xs-3, .col-xs-4, .col-xs-5, .col-xs-6, .col-xs-7, .col-xs-8, .col-xs-9, .col-xs-10, .col-xs-11, .col-xs-12 { float: left; } .col-xs-12 { width: 100%; } .col-xs-11 { width: 91.66666667%; } .col-xs-10 { width: 83.33333333%; } .col-xs-9 { width: 75%; } .col-xs-8 { width: 66.66666667%; } .col-xs-7 { width: 58.33333333%; } .col-xs-6 { width: 50%; } .col-xs-5 { width: 41.66666667%; } .col-xs-4 { width: 33.33333333%; } .col-xs-3 { width: 25%; } .col-xs-2 { width: 16.66666667%; } .col-xs-1 { width: 8.33333333%; } .col-xs-pull-12 { right: 100%; } .col-xs-pull-11 { right: 91.66666667%; } .col-xs-pull-10 { right: 83.33333333%; } .col-xs-pull-9 { right: 75%; } .col-xs-pull-8 { right: 66.66666667%; } .col-xs-pull-7 { right: 58.33333333%; } .col-xs-pull-6 { right: 50%; } .col-xs-pull-5 { right: 41.66666667%; } .col-xs-pull-4 { right: 33.33333333%; } .col-xs-pull-3 { right: 25%; } .col-xs-pull-2 { right: 16.66666667%; } .col-xs-pull-1 { right: 8.33333333%; } .col-xs-pull-0 { right: auto; } .col-xs-push-12 { left: 100%; } .col-xs-push-11 { left: 91.66666667%; } .col-xs-push-10 { left: 83.33333333%; } .col-xs-push-9 { left: 75%; } .col-xs-push-8 { left: 66.66666667%; } .col-xs-push-7 { left: 58.33333333%; } .col-xs-push-6 { left: 50%; } .col-xs-push-5 { left: 41.66666667%; } .col-xs-push-4 { left: 33.33333333%; } .col-xs-push-3 { left: 25%; } .col-xs-push-2 { left: 16.66666667%; } .col-xs-push-1 { left: 8.33333333%; } .col-xs-push-0 { left: auto; } .col-xs-offset-12 { margin-left: 100%; } .col-xs-offset-11 { margin-left: 91.66666667%; } .col-xs-offset-10 { margin-left: 83.33333333%; } .col-xs-offset-9 { margin-left: 75%; } .col-xs-offset-8 { margin-left: 66.66666667%; } .col-xs-offset-7 { margin-left: 58.33333333%; } .col-xs-offset-6 { margin-left: 50%; } .col-xs-offset-5 { margin-left: 41.66666667%; } .col-xs-offset-4 { margin-left: 33.33333333%; } .col-xs-offset-3 { margin-left: 25%; } .col-xs-offset-2 { margin-left: 16.66666667%; } .col-xs-offset-1 { margin-left: 8.33333333%; } .col-xs-offset-0 { margin-left: 0%; }@media (min-width: 768px) { .col, .col-sm-1, .col-sm-2, .col-sm-3, .col-sm-4, .col-sm-5, .col-sm-6, .col-sm-7, .col-sm-8, .col-sm-9, .col-sm-10, .col-sm-11, .col-sm-12 { float: left; } .col-sm-12 { width: 100%; } .col-sm-11 { width: 91.66666667%; } .col-sm-10 { width: 83.33333333%; } .col-sm-9 { width: 75%; } .col-sm-8 { width: 66.66666667%; } .col-sm-7 { width: 58.33333333%; } .col-sm-6 { width: 50%; } .col-sm-5 { width: 41.66666667%; } .col-sm-4 { width: 33.33333333%; } .col-sm-3 { width: 25%; } .col-sm-2 { width: 16.66666667%; } .col-sm-1 { width: 8.33333333%; } .col-sm-pull-12 { right: 100%; } .col-sm-pull-11 { right: 91.66666667%; } .col-sm-pull-10 { right: 83.33333333%; } .col-sm-pull-9 { right: 75%; } .col-sm-pull-8 { right: 66.66666667%; } .col-sm-pull-7 { right: 58.33333333%; } .col-sm-pull-6 { right: 50%; } .col-sm-pull-5 { right: 41.66666667%; } .col-sm-pull-4 { right: 33.33333333%; } .col-sm-pull-3 { right: 25%; } .col-sm-pull-2 { right: 16.66666667%; } .col-sm-pull-1 { right: 8.33333333%; } .col-sm-pull-0 { right: auto; } .col-sm-push-12 { left: 100%; } .col-sm-push-11 { left: 91.66666667%; } .col-sm-push-10 { left: 83.33333333%; } .col-sm-push-9 { left: 75%; } .col-sm-push-8 { left: 66.66666667%; } .col-sm-push-7 { left: 58.33333333%; } .col-sm-push-6 { left: 50%; } .col-sm-push-5 { left: 41.66666667%; } .col-sm-push-4 { left: 33.33333333%; } .col-sm-push-3 { left: 25%; } .col-sm-push-2 { left: 16.66666667%; } .col-sm-push-1 { left: 8.33333333%; } .col-sm-push-0 { left: auto; } .col-sm-offset-12 { margin-left: 100%; } .col-sm-offset-11 { margin-left: 91.66666667%; } .col-sm-offset-10 { margin-left: 83.33333333%; } .col-sm-offset-9 { margin-left: 75%; } .col-sm-offset-8 { margin-left: 66.66666667%; } .col-sm-offset-7 { margin-left: 58.33333333%; } .col-sm-offset-6 { margin-left: 50%; } .col-sm-offset-5 { margin-left: 41.66666667%; } .col-sm-offset-4 { margin-left: 33.33333333%; } .col-sm-offset-3 { margin-left: 25%; } .col-sm-offset-2 { margin-left: 16.66666667%; } .col-sm-offset-1 { margin-left: 8.33333333%; } .col-sm-offset-0 { margin-left: 0%; }}@media (min-width: 992px) { .col, .col-md-1, .col-md-2, .col-md-3, .col-md-4, .col-md-5, .col-md-6, .col-md-7, .col-md-8, .col-md-9, .col-md-10, .col-md-11, .col-md-12 { float: left; } .col-md-12 { width: 100%; } .col-md-11 { width: 91.66666667%; } .col-md-10 { width: 83.33333333%; } .col-md-9 { width: 75%; } .col-md-8 { width: 66.66666667%; } .col-md-7 { width: 58.33333333%; } .col-md-6 { width: 50%; } .col-md-5 { width: 41.66666667%; } .col-md-4 { width: 33.33333333%; } .col-md-3 { width: 25%; } .col-md-2 { width: 16.66666667%; } .col-md-1 { width: 8.33333333%; } .col-md-pull-12 { right: 100%; } .col-md-pull-11 { right: 91.66666667%; } .col-md-pull-10 { right: 83.33333333%; } .col-md-pull-9 { right: 75%; } .col-md-pull-8 { right: 66.66666667%; } .col-md-pull-7 { right: 58.33333333%; } .col-md-pull-6 { right: 50%; } .col-md-pull-5 { right: 41.66666667%; } .col-md-pull-4 { right: 33.33333333%; } .col-md-pull-3 { right: 25%; } .col-md-pull-2 { right: 16.66666667%; } .col-md-pull-1 { right: 8.33333333%; } .col-md-pull-0 { right: auto; } .col-md-push-12 { left: 100%; } .col-md-push-11 { left: 91.66666667%; } .col-md-push-10 { left: 83.33333333%; } .col-md-push-9 { left: 75%; } .col-md-push-8 { left: 66.66666667%; } .col-md-push-7 { left: 58.33333333%; } .col-md-push-6 { left: 50%; } .col-md-push-5 { left: 41.66666667%; } .col-md-push-4 { left: 33.33333333%; } .col-md-push-3 { left: 25%; } .col-md-push-2 { left: 16.66666667%; } .col-md-push-1 { left: 8.33333333%; } .col-md-push-0 { left: auto; } .col-md-offset-12 { margin-left: 100%; } .col-md-offset-11 { margin-left: 91.66666667%; } .col-md-offset-10 { margin-left: 83.33333333%; } .col-md-offset-9 { margin-left: 75%; } .col-md-offset-8 { margin-left: 66.66666667%; } .col-md-offset-7 { margin-left: 58.33333333%; } .col-md-offset-6 { margin-left: 50%; } .col-md-offset-5 { margin-left: 41.66666667%; } .col-md-offset-4 { margin-left: 33.33333333%; } .col-md-offset-3 { margin-left: 25%; } .col-md-offset-2 { margin-left: 16.66666667%; } .col-md-offset-1 { margin-left: 8.33333333%; } .col-md-offset-0 { margin-left: 0%; }}@media (min-width: 1200px) { .col, .col-lg-1, .col-lg-2, .col-lg-3, .col-lg-4, .col-lg-5, .col-lg-6, .col-lg-7, .col-lg-8, .col-lg-9, .col-lg-10, .col-lg-11, .col-lg-12 { float: left; } .col-lg-12 { width: 100%; } .col-lg-11 { width: 91.66666667%; } .col-lg-10 { width: 83.33333333%; } .col-lg-9 { width: 75%; } .col-lg-8 { width: 66.66666667%; } .col-lg-7 { width: 58.33333333%; } .col-lg-6 { width: 50%; } .col-lg-5 { width: 41.66666667%; } .col-lg-4 { width: 33.33333333%; } .col-lg-3 { width: 25%; } .col-lg-2 { width: 16.66666667%; } .col-lg-1 { width: 8.33333333%; } .col-lg-pull-12 { right: 100%; } .col-lg-pull-11 { right: 91.66666667%; } .col-lg-pull-10 { right: 83.33333333%; } .col-lg-pull-9 { right: 75%; } .col-lg-pull-8 { right: 66.66666667%; } .col-lg-pull-7 { right: 58.33333333%; } .col-lg-pull-6 { right: 50%; } .col-lg-pull-5 { right: 41.66666667%; } .col-lg-pull-4 { right: 33.33333333%; } .col-lg-pull-3 { right: 25%; } .col-lg-pull-2 { right: 16.66666667%; } .col-lg-pull-1 { right: 8.33333333%; } .col-lg-pull-0 { right: auto; } .col-lg-push-12 { left: 100%; } .col-lg-push-11 { left: 91.66666667%; } .col-lg-push-10 { left: 83.33333333%; } .col-lg-push-9 { left: 75%; } .col-lg-push-8 { left: 66.66666667%; } .col-lg-push-7 { left: 58.33333333%; } .col-lg-push-6 { left: 50%; } .col-lg-push-5 { left: 41.66666667%; } .col-lg-push-4 { left: 33.33333333%; } .col-lg-push-3 { left: 25%; } .col-lg-push-2 { left: 16.66666667%; } .col-lg-push-1 { left: 8.33333333%; } .col-lg-push-0 { left: auto; } .col-lg-offset-12 { margin-left: 100%; } .col-lg-offset-11 { margin-left: 91.66666667%; } .col-lg-offset-10 { margin-left: 83.33333333%; } .col-lg-offset-9 { margin-left: 75%; } .col-lg-offset-8 { margin-left: 66.66666667%; } .col-lg-offset-7 { margin-left: 58.33333333%; } .col-lg-offset-6 { margin-left: 50%; } .col-lg-offset-5 { margin-left: 41.66666667%; } .col-lg-offset-4 { margin-left: 33.33333333%; } .col-lg-offset-3 { margin-left: 25%; } .col-lg-offset-2 { margin-left: 16.66666667%; } .col-lg-offset-1 { margin-left: 8.33333333%; } .col-lg-offset-0 { margin-left: 0%; }} .clearfix, .clearfix:before, .clearfix:after, .container:before, .container:after, .container-fluid:before, .container-fluid:after, .row:before, .row:after { content: " "; display: table; } .clearfix:after, .container:after, .container-fluid:after, .row:after { clear: both; } .center-block { display: block; margin-left: auto; margin-right: auto; } .pull-right { float: right !important; } .pull-left { float: left !important; } .mycred-container *, .mycred-container *:before, .mycred-container *:after, .mycred-metabox *, .mycred-metabox *:before, .mycred-metabox *:after { -webkit-box-sizing: border-box; -moz-box-sizing: border-box; box-sizing: border-box; } .mycred-metabox .padded { padding: 12px; }
 
 
assets/css/inline-edit.css ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
1
+ .mycred-update-balance { background-color:white; }.mycred-update-balance>div { padding:12px; }.mycred-update-balance .ui-dialog-titlebar { line-height:24px; border-bottom: 1px solid #dedede; }.mycred-update-balance .ui-dialog-titlebar:hover { cursor:move; }.mycred-update-balance .ui-dialog-titlebar-close { float:right; }body.users-php .ui-widget-overlay { position:fixed; top:0; left:0; width:100%; height:100%; background: repeat-x scroll 50% 50% #AAA; opacity:0.3; overflow:hidden; background: repeat-x scroll 50% 50% #333; }.mycred-adjustment-form { display:block; float:none; clear:both; padding:0; margin:0; }.mycred-adjustment-form .row { line-height:24px; margin:0; padding:0; float:none; margin: 0 0 4px 0; clear:both; }.mycred-adjustment-form .row.inline { float:left; clear:none; }}.mycred-update-balance .mycred-adjustment-form .row.inline span { font-size:18px; }.mycred-adjustment-form .row label { display:block; margin-bottom:0; }.mycred-adjustment-form .row input[type="text"] { width:90%; }.mycred-adjustment-form .row input[type="button"] { float:right; }input#mycred-update-users-balance-amount { width:25%; }#edit-mycred-balance #mycred-current.done { color:green; }.mycred-adjustment-form .row input.error { border-color:red; }
2
+
3
+ .mycred-edit-log-entry { background-color:white; }.mycred-edit-log-entry>div { padding:12px; }.mycred-edit-log-entry .ui-dialog-titlebar { line-height:24px; border-bottom: 1px solid #dedede; }.mycred-edit-log-entry .ui-dialog-titlebar:hover { cursor:move; }.mycred-edit-log-entry .ui-dialog-titlebar-close { float:right; }body .ui-widget-overlay { position:fixed; top:0; left:0; width:100%; height:100%; background: repeat-x scroll 50% 50% #AAA; opacity:0.3; overflow:hidden; background: repeat-x scroll 50% 50% #333; }#edit-mycred-log-entry .mycred-adjustment-form .row label{ font-weight:bold; }#edit-mycred-log-entry .mycred-adjustment-form .row input[type="button"] { float:right; margin-left: 24px; }#edit-mycred-log-entry #mycred-current.done { color:green; }.mycred-adjustment-form .row input.error { border-color:red; }
4
+
5
+ .mycred-export-points { background-color:white; }.mycred-export-points>div { padding:12px; }.mycred-export-points .ui-dialog-titlebar { line-height:24px; border-bottom: 1px solid #dedede; }.mycred-export-points .ui-dialog-titlebar:hover { cursor:move; }.mycred-export-points .ui-dialog-titlebar-close { float:right; }
assets/css/mycred-edit-balance.css DELETED
@@ -1,85 +0,0 @@
1
- /* Editor */
2
- .mycred-update-balance { font-family: "Open Sans",sans-serif; background-color: white !important; z-index: 9999 !important; border: none !important; border-radius: 0 !important; background-image: none !important; padding: 0 !important; overflow: visible !important; }
3
- .mycred-update-balance.ui-dialog .ui-dialog-content { padding: 0 0 0 0; }
4
- .mycred-update-balance .ui-widget-header { border: none !important; background: transparent !important; font-weight: normal !important; }
5
- .mycred-update-balance .ui-dialog-titlebar { line-height: 24px !important; border-bottom: 1px solid #ddd !important; border-left: none; border-top: none; border-right: none; padding: 12px !important; border-radius: 0 !important; }
6
- .mycred-update-balance .ui-dialog-titlebar:hover { cursor: move; }
7
- .mycred-update-balance .ui-dialog-titlebar-close { float: right; margin: 0 12px 0 0; background: 0 0; border: none; -webkit-box-shadow: none; box-shadow: none; color: #666; cursor: pointer; display: block; padding: 0; position: absolute; top: 0; right: 0; width: 36px; height: 36px; text-align: center; font-size: 13px; line-height: 26px; vertical-align: top; white-space: nowrap; }
8
- .mycred-update-balance .ui-icon { display: none !important; }
9
- .mycred-update-balance .ui-button:focus, .mycred-update-balance .ui-button:active { outline: none !important; }
10
- .mycred-update-balance .ui-button .ui-button-text { display: block; text-indent: 0; }
11
- .mycred-update-balance .ui-dialog-title { font-size: 22px; font-weight: 600; margin: 0 0 0 0; width: auto !important; float: none !important; }
12
- body.users-php .ui-widget-overlay { position: fixed; top: 0; left: 0; width: 100%; height: 100%; background: repeat-x scroll 70% 70% #000; opacity: 0.7; overflow: hidden; background: repeat-x scroll 70% 70% #000; z-index: 99; }
13
- #edit-mycred-balance { background-color: #f3f3f3; font-size: 14px; }
14
- #edit-mycred-balance form { display: block; padding: 12px; }
15
- #edit-mycred-balance .row { margin-bottom: 24px; }
16
- #edit-mycred-balance .row.ledger { margin-bottom: 6px; font-size: 12px; line-height: 18px; border-bottom: 1px solid #ddd; padding-bottom: 6px; }
17
- #edit-mycred-balance .row.ledger:last-of-type { border-bottom: 0; margin-bottom: 0; }
18
- #edit-mycred-balance .row.ledger.header { margin-bottom: 6px; font-size: 14px; line-height: 22px; }
19
- #edit-mycred-balance .row.ledger .row { border-bottom: 1px solid #ddd; padding-bottom: 6px; }
20
- #edit-mycred-balance .row.last { margin-bottom: 0; }
21
- #edit-mycred-balance .row input { width: 99%; }
22
- #edit-mycred-balance .row .button { width: 99%; }
23
- #edit-mycred-balance .row input.regular-text { width: 99%; }
24
- #edit-mycred-balance .row select { width: 99%; }
25
- #edit-mycred-balance .row .button-secondary { float: right; }
26
- #edit-mycred-balance .row.ledger .button-secondary { float: none; }
27
- #edit-mycred-balance .row.ledger p { text-align: center; margin: 6px 0 0 0; }
28
- #edit-mycred-balance .row span { display: block; font-size: 12px; line-height: 16px; padding: 2px 0 0 3px; }
29
- #edit-mycred-balance .row label { display: block; font-weight: bold; line-height: 22px; }
30
- #edit-mycred-balance .text-right { text-align: right; }
31
- #edit-mycred-balance #mycred-editor-results { line-height: 30px; }
32
- #mycred-users-mini-ledger .border { border-top: 1px solid #ddd; padding: 12px; margin: 0 0 0 0; background-color: #e8e8e8; }
33
- #mycred-processing { text-align: center; min-height: 4px; width: 100%; }
34
- img#mycred-token-sitting { display: none; }
35
-
36
- fieldset#mycred-badge-list .badge-wrapper img { margin: 0 auto; max-width: 100px; height: auto; width: 100px; }
37
- fieldset#mycred-badge-list .badge-wrapper .no-badge-image { margin: 0 auto; max-width: 100px; height: auto; width: 100px;line-height: 100px; }
38
- fieldset#mycred-badge-list .badge-wrapper label { display: block; }
39
- fieldset#mycred-badge-list .badge-image-wrap { text-align: center; }
40
- fieldset#mycred-badge-list .badge-image-wrap h4 { margin: 0 0 0 0; }
41
- fieldset#mycred-badge-list .badge-actions { text-align: center; }
42
-
43
- .loading-indicator { height: 5px; width: 100%; position: relative; overflow: hidden; background-color: white; }
44
- .loading-indicator:before { display: block; position: absolute; content: ""; left: -200px; width: 200px; height: 5px; background-color: #c5d93d; animation: loading 2s linear infinite; }
45
- @keyframes loading { from { left: -200px; width: 30%; } 25% { width: 50%; } 50% { width: 50%; } 70% { width: 50%; } 80% { left: 75%; } 95% { left: 100%; } to { left: 100%; } }
46
-
47
- .mycred-wrapper.color-option { width: 48%; }
48
- p.mycred-p { margin: 12px 0 0 0; }
49
- .mycred-inline-table { margin: 0 0 18px 0; }
50
- .mycred-wrapper { min-height: 100px; padding: 15px !important; border: 1px solid #ddd; }
51
- .mycred-wrapper:hover { cursor: default; }
52
- .mycred-wrapper.disabled-option { color: #949494; }
53
- .mycred-wrapper.disabled-option:hover { background-color: transparent; }
54
- .mycred-wrapper .toggle-mycred-balance-editor { float: right; }
55
- .mycred-wrapper .balance-desc { font-size: 12px; line-height: 15px; color: #949494; }
56
- .balance-row { display: block; height: 32px; line-height: 32px; font-size: 18px; }
57
- .balance-row > div { height: 32px; line-height: inherit; font-size: inherit; vertical-align: top; }
58
- .balance-row .balance-edit { display: none; }
59
- .balance-row.edit .balance-view { display: none; }
60
- .balance-row.edit .balance-edit { display: block; }
61
- .balance-row input { width: 100%; margin: 0 12px 0 0; }
62
- .balance-row input.half { width: 60% !important; display: inline-block !important; margin-right: 6px; }
63
- .balance-row input.short { width: 30% !important; display: inline-block !important; margin: 0 3px; }
64
- #mycred-edit-user-wrapper h2 { margin: 12px 0 6px 0; }
65
-
66
- @media screen and (max-width: 782px) {
67
-
68
- .balance-row { display: block; height: auto; line-height: 1.5em; font-size: 18px; }
69
- .balance-row > div { height: auto; line-height: 42px; font-size: inherit; vertical-align: top; }
70
-
71
- }
72
-
73
- @media screen and (max-width: 520px) {
74
-
75
- .mycred-wrapper.color-option { width: 100%; }
76
-
77
-
78
- }
79
-
80
- @media screen and (min-width: 1400px) {
81
-
82
- .mycred-wrapper.color-option { width: 24% !important; }
83
-
84
-
85
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
assets/css/mycred-edit-log.css DELETED
@@ -1,65 +0,0 @@
1
- /* Editor */
2
- .mycred-edit-logentry { font-family: "Open Sans",sans-serif; background-color: white !important; z-index: 9999 !important; border: none !important; border-radius: 0 !important; background-image: none !important; padding: 0 !important; overflow: visible !important; }
3
- .mycred-edit-logentry.ui-dialog .ui-dialog-content { padding: 0 0 0 0; }
4
- .mycred-edit-logentry .ui-widget-header { border: none !important; background: transparent !important; font-weight: normal !important; }
5
- .mycred-edit-logentry .ui-dialog-titlebar { line-height: 24px !important; border-bottom: 1px solid #ddd !important; border-left: none; border-top: none; border-right: none; padding: 12px !important; border-radius: 0 !important; }
6
- .mycred-edit-logentry .ui-dialog-titlebar:hover { cursor: move; }
7
- .mycred-edit-logentry .ui-dialog-titlebar-close { float: right; margin: 0 12px 0 0; background: 0 0; border: none; -webkit-box-shadow: none; box-shadow: none; color: #666; cursor: pointer; display: block; padding: 0; position: absolute; top: 0; right: 0; width: 36px; height: 36px; text-align: center; font-size: 13px; line-height: 26px; vertical-align: top; white-space: nowrap; }
8
- .mycred-edit-logentry .ui-icon { display: none !important; }
9
- .mycred-edit-logentry .ui-button:focus, .mycred-edit-logentry .ui-button:active { outline: none !important; }
10
- .mycred-edit-logentry .ui-button .ui-button-text { display: block; text-indent: 0; }
11
- .mycred-edit-logentry .ui-dialog-title { font-size: 22px; font-weight: 600; margin: 0 0 0 0; width: auto !important; float: none !important; }
12
- body .ui-widget-overlay { position: fixed; top: 0; left: 0; width: 100%; height: 100%; background: repeat-x scroll 70% 70% #000; opacity: 0.7; overflow: hidden; background: repeat-x scroll 70% 70% #000; z-index: 99; }
13
- #edit-mycred-log-entry { background-color: #f3f3f3; font-size: 14px; }
14
- #edit-mycred-log-entry form { display: block; padding: 12px; }
15
- #edit-mycred-log-entry .row { margin-bottom: 24px; }
16
- #edit-mycred-log-entry .row.ledger { margin-bottom: 3px; font-size: 12px; line-height: 18px; }
17
- #edit-mycred-log-entry .row.ledger.header { margin-bottom: 6px; font-size: 14px; line-height: 22px; }
18
- #edit-mycred-log-entry .row.ledger .row { border-bottom: 1px solid #ddd; padding-bottom: 6px; }
19
- #edit-mycred-log-entry .row.last { margin-bottom: 0; }
20
- #edit-mycred-log-entry .row input { width: 99%; }
21
- #edit-mycred-log-entry .row .button { width: 99%; }
22
- #edit-mycred-log-entry .row input.regular-text { width: 99%; }
23
- #edit-mycred-log-entry .row select { width: 99%; }
24
- #edit-mycred-log-entry .row.ledger .button-secondary { float: none; }
25
- #edit-mycred-log-entry .row.ledger p { text-align: center; margin: 6px 0 0 0; }
26
- #edit-mycred-log-entry .row span { display: block; font-size: 12px; line-height: 16px; padding: 2px 0 0 3px; }
27
- #edit-mycred-log-entry .row span span { display: inline; padding-left: 12px; }
28
- #edit-mycred-log-entry .row label { display: block; font-weight: bold; line-height: 22px; }
29
- #edit-mycred-log-entry .text-right { text-align: right; }
30
- #edit-mycred-log-entry .text-center { text-align: center; }
31
- #edit-mycred-log-entry #mycred-editor-results { line-height: 30px; }
32
- img#mycred-token-sitting { display: none; }
33
-
34
- .flash {
35
- -moz-animation: flash 0.5s ease-out;
36
- -moz-animation-iteration-count: 1;
37
-
38
- -webkit-animation: flash 0.5s ease-out;
39
- -webkit-animation-iteration-count: 1;
40
-
41
- -ms-animation: flash 1s ease-out;
42
- -ms-animation-iteration-count: 1;
43
- }
44
-
45
- @-webkit-keyframes flash {
46
- 0% { background-color: none; }
47
- 50% { background-color: #fbf8b2; }
48
- 100% { background-color: none; }
49
- }
50
-
51
- @-moz-keyframes flash {
52
- 0% { background-color: none; }
53
- 50% { background-color: #fbf8b2; }
54
- 100% { background-color: none; }
55
- }
56
-
57
- @-ms-keyframes flash {
58
- 0% { background-color: none; }
59
- 50% { background-color: #fbf8b2; }
60
- 100% { background-color: none; }
61
- }
62
-
63
- .loading-indicator { height: 5px; width: 100%; position: relative; overflow: hidden; background-color: white; }
64
- .loading-indicator:before { display: block; position: absolute; content: ""; left: -200px; width: 200px; height: 5px; background-color: #c5d93d; animation: loading 2s linear infinite; }
65
- @keyframes loading { from { left: -200px; width: 30%; } 25% { width: 50%; } 50% { width: 50%; } 70% { width: 50%; } 80% { left: 75%; } 95% { left: 100%; } to { left: 100%; } }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
assets/css/mycred-forms.css DELETED
@@ -1,53 +0,0 @@
1
- #titlewrap #title.readonly { color: rgba(51,51,51,.5); cursor: not-allowed; }
2
- #poststuff .mycred-metabox .inside { margin: 0 0 0 0; padding: 12px; background-color: #f5f5f5; }
3
- .mycred-metabox .text-center { text-align: center; }
4
- .mycred-metabox .text-center img { margin: 0 auto; }
5
- .mycred-metabox .row { margin-bottom: 12px; }
6
- .mycred-metabox .row-narrow { margin-bottom: 0; }
7
- .mycred-metabox .row.padded-row { padding: 0 12px; }
8
- .mycred-metabox .row:last-child { margin-bottom: 0; }
9
- .mycred-metabox .form-control { vertical-align: top; }
10
- .mycred-metabox .form .form-control { width: 100%; margin-bottom: 0; }
11
- .mycred-metabox .form-group { margin-bottom: 12px; }
12
- .mycred-metabox .form-group.slim { margin-bottom: 0; }
13
- .mycred-metabox .form-group label { display: block; font-weight: bold; font-size: 12px; line-height: 18px; }
14
- .mycred-metabox .form-inline label { display: inline-block; }
15
- .mycred-metabox .form-group label.slim { font-weight: normal; }
16
- .mycred-metabox .form-control-static { margin: 0 0 6px 0; }
17
- .mycred-metabox .form .form-control-static { margin: 0 0 0 0; line-height: 27px; }
18
- .mycred-metabox .form-inline .form-control { width: auto; }
19
- .mycred-metabox .form-inline .form-control-static { margin: 0 0 0 0; line-height: 27px; }
20
- .mycred-metabox ul.history { margin: 0 0 0 0; padding: 0 0 0 0; }
21
- .mycred-metabox ul.history li { margin: 0 0 0 0; padding: 6px 0; border-bottom: 1px solid #ddd; }
22
- .mycred-metabox ul.history li:last-child { border-bottom: none; }
23
- .mycred-metabox ul.history li time { display: block; font-size: 10px; line-height: 18px; font-style: italic; }
24
- .mycred-metabox ul.history li p { margin: 0 0 0 0; }
25
- .mycred-metabox .button-block { width: 100%; display: block; }
26
- .mycred-metabox #minor-publishing-actions > div { padding-bottom: 10px; text-align: center; }
27
- .mycred-metabox .req-title { font-size: 10px; line-height: 24px; border-bottom: 1px solid #ddd; margin-bottom: 12px; }
28
- .mycred-metabox .label-field input { border: 1px solid transparent; background-color: transparent; box-shadow: none; text-align: center; color: #aaa; width: 50%; margin: 12px auto; }
29
- .mycred-metabox .top-right-corner { position: absolute; top: 0; right: 12px; }
30
- .seperate-bottom { padding-bottom: 12px; border-bottom: 1px solid #ddd; margin-bottom: 12px; }
31
- .mycred-metabox .padd-bottom { padding-bottom: 12px; }
32
- .mycred-metabox .badge-level { padding-bottom: 12px; border-bottom: 1px solid #ddd; margin-bottom: 12px; }
33
- .mycred-metabox .badge-level:last-child { padding-bottom: 0; border-bottom: none; margin-bottom: 0; }
34
- .mycred-metabox .image-wrapper { width: 100%; min-height: 114px; padding-bottom: 12px; }
35
- .mycred-metabox .image-wrapper.empty:before { display: block; margin: 0 auto; width: 90%; height: 100px; line-height: 100px; text-align: center; border: 2px dashed #ddd; color: #ddd; content: "\f128"; }
36
- .mycred-metabox .level-image .image-wrapper.empty:before { width: 50%; }
37
- .mycred-metabox .image-wrapper img { max-width: 100%; height: auto; margin: 0 auto; max-height: 100px; }
38
- .mycred-metabox a.selected { color: #aaa; text-decoration: none; cursor: not-allowed; }
39
- .mycred-metabox a.selected:hover { text-decoration: none; color: #ddd; cursor: not-allowed; }
40
- .mycred-metabox .level-type-by p { padding-left: 12px; }
41
- .mycred-metabox .level-compare p { color: #aaa; }
42
-
43
- .form-inline .form-group { display: inline-block; margin-bottom: 0; vertical-align: middle; }
44
- .form-inline .form-control { display: inline-block; width: auto; vertical-align: middle; }
45
- .form-inline .form-control-static { display: inline-block; }
46
- .form-inline .input-group { display: inline-table; vertical-align: middle; }
47
- .form-inline .input-group .input-group-addon, .form-inline .input-group .input-group-btn, .form-inline .input-group .form-control { width: auto; }
48
- .form-inline .input-group > .form-control { width: 100%; }
49
- .form-inline .control-label { margin-bottom: 0; vertical-align: middle; }
50
- .form-inline .radio, .form-inline .checkbox { display: inline-block; margin-top: 0; margin-bottom: 0; vertical-align: middle; }
51
- .form-inline .radio label, .form-inline .checkbox label { padding-left: 0; }
52
- .form-inline .radio input[type="radio"], .form-inline .checkbox input[type="checkbox"] { position: relative; margin-left: 0; }
53
- .form-inline .has-feedback .form-control-feedback { top: 0; }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
assets/css/overview.css ADDED
@@ -0,0 +1,34 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #mycred_overview p.sub,
2
+ #mycred_overview .table, #mycred_overview .versions { margin: -12px; }
3
+ #mycred_overview .inside { font-size: 13px; padding-top: 20px; }
4
+ body.mp6 #mycred_overview p.sub { padding: 5px 0 15px; font-size: 11px; font-weight: 600; left: 14px; letter-spacing: 1px; position: absolute; text-transform: uppercase; top: -17px; }
5
+ body #mycred_overview p.sub { padding: 5px 0 15px; color: #8f8f8f; font-size: 14px; position: absolute; top: -17px; left: 15px; }
6
+ #mycred_overview .table { margin: 0; padding: 0; position: relative; }
7
+ body.mp6 #mycred_overview .table_content { float: left; width: 45%; }
8
+ body #mycred_overview .table_content { float: left; width: 45%; border-top: 1px solid #ececec; }
9
+ #mycred_overview .table_content.push { margin-right: 9%; }
10
+ #mycred_overview table td { padding: 3px 0; white-space: nowrap; }
11
+ #mycred_overview table tr.first td { border-top: none; }
12
+ #mycred_overview td.b { padding-right: 6px; text-align: right; font-size: 14px; width: 1%; }
13
+ #mycred_overview td.b a { font-size: 18px; }
14
+ #mycred_overview td.b a:hover { color: #d54e21; }
15
+ #mycred_overview .t { padding-right: 12px; }
16
+ #mycred_overview .t,
17
+ #mycred_overview .b { font-size: 14px; padding-top: 4px; }
18
+ #mycred_overview .t a { white-space: nowrap; }
19
+ #mycred_overview .spam { color: red; }
20
+ #mycred_overview .waiting { color: #e66f00; }
21
+ #mycred_overview .approved { color: green; }
22
+ #mycred_overview .versions { padding: 6px 10px 12px; clear: both; }
23
+ #mycred_overview a.button { float: right; clear: right; position: relative; top: -5px; }
24
+ #mycred_overview .no-modules { color: #dedede; text-align: center; margin-top: 0; }
25
+
26
+ div.columns-3 #mycred_overview .table_content,
27
+ div.columns-4 #mycred_overview .table_content { float: none; width: 100%; clear: both; margin-bottom: 42px; }
28
+ div.columns-3 #mycred_overview .table_content.push,
29
+ div.columns-4 #mycred_overview .table_content.push { margin-right: 0; }
30
+ div.columns-4 #mycred_overview td.b a,
31
+ div.columns-4 #mycred_overview .t { font-size: 12px; }
32
+ div.columns-4 #mycred_overview td { line-height: 1em; }
33
+
34
+ #mycred_overview form.dashboard-widget-control-form { overflow: visible; }
assets/css/{mycred-front.css → widget.css} RENAMED
File without changes
assets/images/about/badge.png ADDED
Binary file
assets/images/badge.png DELETED
Binary file
assets/images/badges-addon.png DELETED
Binary file
assets/images/banking-addon.png DELETED
Binary file
assets/images/buy-creds-addon.png DELETED
Binary file
assets/images/coupons-addon.png DELETED
Binary file
assets/images/email-notifications-addon.png DELETED
Binary file
assets/images/gateway-addon.png DELETED
Binary file
assets/images/mycred-about-balance.png DELETED
Binary file
assets/images/mycred-about-hooks.png DELETED
Binary file
assets/images/mycred-loading.gif DELETED
Binary file
assets/images/notifications-addon.png DELETED
Binary file
assets/images/ranks-addon.png DELETED
Binary file
assets/images/sell-content-addon.png DELETED
Binary file
assets/images/statistics-addon.png DELETED
Binary file
assets/images/token-sitting.png DELETED
Binary file
assets/images/transfer-addon.png DELETED
Binary file
assets/js/{mycred-accordion.js → accordion.js} RENAMED
@@ -1,16 +1,14 @@
1
  /**
2
  * Accordion
3
  * @since 0.1
4
- * @version 1.1
5
  */
6
  jQuery(function($) {
7
-
8
- var active_box = false;
9
- if ( typeof myCRED !== 'undefined' ) {
10
- if ( myCRED.active != '-1' )
11
- active_box = parseInt( myCRED.active, 10 );
12
  }
13
-
14
  $( "#accordion" ).accordion({ collapsible: true, header: "h4", heightStyle: "content", active: active_box });
15
-
16
  });
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/edit-log.js ADDED
@@ -0,0 +1,278 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /**
2
+ * myCRED Edit Log Scripts
3
+ * These scripts are used to edit or delete entries
4
+ * in the myCRED Log.
5
+ * @since 1.4
6
+ * @version 1.1
7
+ */
8
+ jQuery(function($) {
9
+
10
+ /**
11
+ * Click To Toggle Script
12
+ */
13
+ $( '.click-to-toggle' ).click(function(){
14
+ var target = $(this).attr( 'data-toggle' );
15
+ $( '#' + target ).toggle();
16
+ });
17
+
18
+ /**
19
+ * Delete Log Entry AJAX caller
20
+ */
21
+ var mycred_delete_log_entry = function( rowid, button ) {
22
+ $.ajax({
23
+ type : "POST",
24
+ data : {
25
+ action : 'mycred-delete-log-entry',
26
+ token : myCREDLog.tokens.delete_row,
27
+ row : rowid
28
+ },
29
+ dataType : "JSON",
30
+ url : myCREDLog.ajaxurl,
31
+ success : function( response ) {
32
+ // Debug
33
+ //console.log( response );
34
+
35
+ var parentrow = button.parent().parent().parent();
36
+ var actioncol = button.parent().parent();
37
+
38
+ if ( response.success ) {
39
+ actioncol.empty();
40
+ actioncol.text( response.data );
41
+
42
+ parentrow.addClass( 'deleted-row' );
43
+ parentrow.fadeOut( 3000, function(){ parentrow.remove(); });
44
+ }
45
+ else {
46
+ actioncol.empty();
47
+ actioncol.text( response.data );
48
+ }
49
+ },
50
+ error : function( jqXHR, textStatus, errorThrown ) {
51
+ // Debug
52
+ //console.log( jqXHR );
53
+ //console.log( 'textStatus: ' + textStatus + ' | errorThrown: ' + errorThrown );
54
+ }
55
+ });
56
+ }
57
+
58
+ /**
59
+ * Log Entry Deletion Trigger
60
+ */
61
+ $( '.mycred-delete-row' ).click(function(){
62
+ // Require user to confirm deletion
63
+ if ( ! confirm( myCREDLog.messages.delete_row ) )
64
+ return false;
65
+
66
+ // Execute AJAX call
67
+ mycred_delete_log_entry( $(this).attr( 'data-id' ), $(this) );
68
+ });
69
+
70
+ var log_row_id = '';
71
+ var log_user = '';
72
+ var log_time = '';
73
+ var log_cred = '';
74
+
75
+ var log_entry_raw = '';
76
+ var log_entry = '';
77
+
78
+ /**
79
+ * Setup Log Editor Modal
80
+ */
81
+ $('#edit-mycred-log-entry').dialog({
82
+ dialogClass : 'mycred-edit-log-entry',
83
+ draggable : true,
84
+ autoOpen : false,
85
+ title : myCREDLog.title,
86
+ closeText : myCREDLog.close,
87
+ modal : true,
88
+ width : 500,
89
+ height : 'auto',
90
+ resizable : false,
91
+ show : {
92
+ effect : 'slide',
93
+ direction : 'up',
94
+ duration : 250
95
+ },
96
+ hide : {
97
+ effect : 'slide',
98
+ direction : 'up',
99
+ duration : 250
100
+ }
101
+ });
102
+
103
+ /**
104
+ * Edit Modal Trigger
105
+ */
106
+ $( '.mycred-open-log-entry-editor' ).click( function() {
107
+
108
+ // Get the details we want to show
109
+ log_row_id = $(this).attr( 'data-id' );
110
+ log_user = $(this).parent().siblings( 'td.column-username' ).children( 'span' ).text();
111
+ log_time = $(this).parent().siblings( 'td.column-time' ).text();
112
+ log_cred = $(this).parent().siblings( 'td.column-creds' ).text();
113
+
114
+ log_entry_raw = $(this).parent().siblings( 'td.column-entry' ).children( 'div.raw' ).text();
115
+ log_entry = $(this).parent().siblings( 'td.column-entry' ).children( 'div.entry' ).text();
116
+
117
+ // Show the modal window
118
+ $( '#edit-mycred-log-entry' ).dialog( 'open' );
119
+
120
+ // Populate the form
121
+ var username_el = $( '#edit-mycred-log-entry #mycred-username' );
122
+ username_el.empty();
123
+ username_el.text( log_user );
124
+
125
+ var time_el = $( '#edit-mycred-log-entry #mycred-time' );
126
+ time_el.empty();
127
+ time_el.text( log_time );
128
+
129
+ var creds_el = $( '#edit-mycred-log-entry #mycred-creds' );
130
+ creds_el.empty();
131
+ creds_el.text( log_cred );
132
+
133
+ var entry_el = $( '#edit-mycred-log-entry #mycred-raw-entry' );
134
+ entry_el.val( '' );
135
+ entry_el.val( log_entry );
136
+
137
+ var raw_entry_el = $( '#edit-mycred-log-entry #mycred-new-entry' );
138
+ raw_entry_el.val( '' );
139
+ raw_entry_el.val( log_entry_raw );
140
+
141
+ $( 'input#mycred-log-row-id' ).val( log_row_id );
142
+
143
+ });
144
+
145
+ /**
146
+ * Edit AJAX Call
147
+ */
148
+ var mycred_update_log_entry = function( rowid, entry, button ) {
149
+ var button_label = button.val();
150
+
151
+ $.ajax({
152
+ type : "POST",
153
+ data : {
154
+ action : 'mycred-update-log-entry',
155
+ token : myCREDLog.tokens.update_row,
156
+ row : rowid,
157
+ new_entry : entry
158
+ },
159
+ dataType : "JSON",
160
+ url : myCREDLog.ajaxurl,
161
+ beforeSend : function() {
162
+
163
+ button.removeClass( 'button-primary' );
164
+ button.addClass( 'button-secondary' );
165
+ button.val( myCREDLog.working );
166
+ },
167
+ success : function( response ) {
168
+ // Debug
169
+ console.log( response );
170
+
171
+ var effected_row = $( '#mycred-log-entry-' + response.data.row_id );
172
+ button.removeClass( 'button-secondary' );
173
+
174
+ if ( response.success ) {
175
+ effected_row.addClass( 'updated-row' );
176
+ effected_row.children( 'td.column-entry' ).children( 'div.raw' ).empty().html( response.data.new_entry_raw );
177
+
178
+ $( '#edit-mycred-log-entry #mycred-raw-entry' ).val( response.data.new_entry );
179
+
180
+ effected_row.children( 'td.column-entry' ).children( 'div.entry' ).empty().html( response.data.new_entry );
181
+
182
+ $( '#edit-mycred-log-entry #mycred-new-entry' ).val( response.data.new_entry_raw );
183
+
184
+ button.val( response.data.label );
185
+ setTimeout(function(){ button.val( button_label ); button.addClass( 'button-primary' ); }, 5000 );
186
+ }
187
+ else {
188
+ button.val( response.data );
189
+ setTimeout(function(){ button.val( button_label ); button.addClass( 'button-primary' ); }, 5000 );
190
+ }
191
+ },
192
+ error : function( jqXHR, textStatus, errorThrown ) {
193
+ // Debug
194
+ //console.log( jqXHR );
195
+ //console.log( 'textStatus: ' + textStatus + ' | errorThrown: ' + errorThrown );
196
+ }
197
+ });
198
+ }
199
+
200
+ /**
201
+ * Edit AJAX Call Trigger
202
+ */
203
+ $( '#mycred-update-log-entry' ).click( function() {
204
+ mycred_update_log_entry( $(this).next().val(), $( 'input#mycred-new-entry' ).val(), $(this) );
205
+ });
206
+
207
+ /* global setUserSetting, ajaxurl, commonL10n, alert, confirm, toggleWithKeyboard, pagenow */
208
+ var showNotice, adminMenu, columns, validateForm, screenMeta;
209
+
210
+ // Removed in 3.3.
211
+ // (perhaps) needed for back-compat
212
+ adminMenu = {
213
+ init : function() {},
214
+ fold : function() {},
215
+ restoreMenuState : function() {},
216
+ toggle : function() {},
217
+ favorites : function() {}
218
+ };
219
+
220
+ // show/hide/save table columns
221
+ columns = {
222
+ init : function() {
223
+ var that = this;
224
+ $('.hide-column-tog', '#adv-settings').click( function() {
225
+ var $t = $(this), column = $t.val();
226
+ if ( $t.prop('checked') )
227
+ that.checked(column);
228
+ else
229
+ that.unchecked(column);
230
+
231
+ columns.saveManageColumnsState();
232
+ });
233
+ },
234
+
235
+ saveManageColumnsState : function() {
236
+ var hidden = this.hidden();
237
+ $.post(ajaxurl, {
238
+ action: 'hidden-columns',
239
+ hidden: hidden,
240
+ screenoptionnonce: $('#screenoptionnonce').val(),
241
+ page: pagenow
242
+ });
243
+ },
244
+
245
+ checked : function(column) {
246
+ $('.' + column).show();
247
+ this.colSpanChange(+1);
248
+ },
249
+
250
+ unchecked : function(column) {
251
+ $('.' + column).hide();
252
+ this.colSpanChange(-1);
253
+ },
254
+
255
+ hidden : function() {
256
+ return $('.manage-column').filter(':hidden').map(function() { return this.id; }).get().join(',');
257
+ },
258
+
259
+ useCheckboxesForHidden : function() {
260
+ this.hidden = function(){
261
+ return $('.hide-column-tog').not(':checked').map(function() {
262
+ var id = this.id;
263
+ return id.substring( id, id.length - 5 );
264
+ }).get().join(',');
265
+ };
266
+ },
267
+
268
+ colSpanChange : function(diff) {
269
+ var $t = $('table').find('.colspanchange'), n;
270
+ if ( !$t.length )
271
+ return;
272
+ n = parseInt( $t.attr('colspan'), 10 ) + diff;
273
+ $t.attr('colspan', n.toString());
274
+ }
275
+ };
276
+
277
+ $(document).ready(function(){columns.init();});
278
+ });
assets/js/inline-edit.js ADDED
@@ -0,0 +1,129 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /**
2
+ * myCRED Inline Edit
3
+ * @since 1.2
4
+ * @version 1.2
5
+ */
6
+ jQuery(function($) {
7
+
8
+ var username = '';
9
+ var user_id = '';
10
+ var current = '';
11
+ var current_el = '';
12
+
13
+ /**
14
+ * Setup Points Editor Modal
15
+ */
16
+ $(document).ready( function() {
17
+ $('#edit-mycred-balance').dialog({
18
+ dialogClass : 'mycred-update-balance',
19
+ draggable : true,
20
+ autoOpen : false,
21
+ title : myCREDedit.title,
22
+ closeText : myCREDedit.close,
23
+ modal : true,
24
+ width : 500,
25
+ height : 'auto',
26
+ resizable : false,
27
+ show : {
28
+ effect : 'slide',
29
+ direction : 'up',
30
+ duration : 250
31
+ },
32
+ hide : {
33
+ effect : 'slide',
34
+ direction : 'up',
35
+ duration : 250
36
+ }
37
+ });
38
+ });
39
+
40
+ /**
41
+ * Edit Points Trigger
42
+ */
43
+ $( '.mycred-open-points-editor' ).click( function() {
44
+
45
+ $( '#edit-mycred-balance' ).dialog( 'open' );
46
+
47
+ $( '#edit-mycred-balance #mycred-username' ).empty().text( $(this).attr( 'data-username' ) );
48
+
49
+ $( '#edit-mycred-balance #mycred-userid' ).empty().text( $(this).attr( 'data-userid' ) );
50
+
51
+ $( '#edit-mycred-balance #mycred-current' ).empty().text( $(this).attr( 'data-current' ) );
52
+
53
+ $( '#mycred-update-users-balance-type' ).val( $(this).attr( 'data-type' ) );
54
+ });
55
+
56
+ /**
57
+ * Update Balance AJAX Caller
58
+ */
59
+ $( '#mycred-update-users-balance-submit' ).click( function() {
60
+ var button = $(this);
61
+ var label = button.val();
62
+ var current_el = $( '#edit-mycred-balance #mycred-current' );
63
+ var user_id = $( '#edit-mycred-balance #mycred-userid' ).text();
64
+ var amount_el = $( 'input#mycred-update-users-balance-amount' );
65
+ var entry_el = $( 'input#mycred-update-users-balance-entry' );
66
+ var type_el = $( '#mycred-update-users-balance-type' );
67
+
68
+ $.ajax({
69
+ type : "POST",
70
+ data : {
71
+ action : 'mycred-inline-edit-users-balance',
72
+ token : $( 'input#mycred-update-users-balance-token' ).val(),
73
+ user : user_id,
74
+ amount : amount_el.val(),
75
+ entry : entry_el.val(),
76
+ type : type_el.val()
77
+ },
78
+ dataType : "JSON",
79
+ url : myCREDedit.ajaxurl,
80
+ // Before we start
81
+ beforeSend : function() {
82
+ current_el.removeClass( 'done' );
83
+ entry_el.removeClass( 'error' );
84
+ amount_el.removeClass( 'error' );
85
+
86
+ button.attr( 'value', myCREDedit.working );
87
+ button.attr( 'disabled', 'disabled' );
88
+ },
89
+ // On Successful Communication
90
+ success : function( response ) {
91
+ // Debug
92
+ console.log( response );
93
+
94
+ if ( response.success ) {
95
+ current_el.addClass( 'done' );
96
+ current_el.text( response.data );
97
+ amount_el.val( '' );
98
+ entry_el.val( '' );
99
+ $( 'div#mycred-user-' + user_id + '-balance-' + type_el.val() + ' span' ).empty().html( response.data );
100
+ }
101
+ else {
102
+ if ( response.data.error == 'ERROR_1' ) {
103
+ $( '#edit-mycred-balance' ).dialog( 'destroy' );
104
+ }
105
+ else if ( response.data.error == 'ERROR_2' ) {
106
+ alert( response.data.message );
107
+ amount_el.val( '' );
108
+ entry_el.val( '' );
109
+ }
110
+ else {
111
+ entry_el.addClass( 'error' );
112
+ entry_el.attr( 'title', response.data.message );
113
+ }
114
+ }
115
+
116
+ button.attr( 'value', label );
117
+ button.removeAttr( 'disabled' );
118
+ },
119
+ // Error (sent to console)
120
+ error : function( jqXHR, textStatus, errorThrown ) {
121
+ // Debug
122
+ //console.log( jqXHR + ':' + textStatus + ':' + errorThrown );
123
+
124
+ button.attr( 'value', label );
125
+ button.removeAttr( 'disabled' );
126
+ }
127
+ });
128
+ });
129
+ });
assets/js/{mycred-type-management.js → management.js} RENAMED
@@ -1,38 +1,14 @@
1
  /**
2
  * myCRED Management Scripts
3
  * @since 1.3
4
- * @version 1.4
5
  */
6
  jQuery(function($) {
7
 
8
- var wWidth = $(window).width();
9
- var dWidth = wWidth * 0.75;
10
-
11
- /**
12
- * Make sure new point type key is
13
- * correctly formatted. Only lowercase letters and underscores
14
- * are allowed. Warn user if needed.
15
- */
16
- $( '#mycred-new-ctype-key-value' ).on( 'change', function(){
17
-
18
- var ctype_key = $(this).val();
19
- var re = /^[a-z_]+$/;
20
- if ( ! re.test( ctype_key ) ) {
21
- $(this).css( 'border-color', 'red' );
22
- $( '#mycred-ctype-warning' ).css( 'color', 'red' );
23
- }
24
- else {
25
- $(this).css( 'border-color', 'green' );
26
- $( '#mycred-ctype-warning' ).css( 'color', '' );
27
- }
28
-
29
- });
30
-
31
  /**
32
  * Empty Log AJAX Caller
33
  */
34
  var mycred_action_empty_log = function( button ) {
35
-
36
  var label = button.val();
37
  $.ajax({
38
  type : "POST",
@@ -48,7 +24,6 @@ jQuery(function($) {
48
  button.attr( 'disabled', 'disabled' );
49
  },
50
  success : function( response ) {
51
-
52
  if ( response.success ) {
53
  $( 'input#mycred-manage-table-rows' ).val( response.data );
54
  button.val( myCREDmanage.done );
@@ -59,30 +34,24 @@ jQuery(function($) {
59
  button.removeAttr( 'disabled' );
60
  alert( response.data );
61
  }
62
-
63
  }
64
  });
65
-
66
  };
67
 
68
  /**
69
  * Empty Log Trigger
70
  */
71
- $( '#mycred-manage-action-empty-log' ).click(function(){
72
-
73
  // Confirm action
74
  if ( confirm( myCREDmanage.confirm_log ) )
75
  mycred_action_empty_log( $(this) );
76
-
77
  });
78
 
79
  /**
80
  * Reset Balance AJAX Caller
81
  */
82
  var mycred_action_reset_balance = function( button ) {
83
-
84
  var label = button.val();
85
-
86
  $.ajax({
87
  type : "POST",
88
  data : {
@@ -97,84 +66,55 @@ jQuery(function($) {
97
  button.attr( 'disabled', 'disabled' );
98
  },
99
  success : function( response ) {
100
-
101
- console.log( response );
102
  if ( response.success ) {
103
- button.text( response.data );
104
  button.removeClass( 'button-primary' );
105
  }
106
  else {
107
- button.text( label );
108
  button.removeAttr( 'disabled' );
109
  alert( response.data );
110
  }
111
-
112
  }
113
  });
114
-
115
  };
116
 
117
  /**
118
  * Reset Balance Trigger
119
  */
120
- $( '#mycred-manage-action-reset-accounts' ).click(function(){
121
-
122
  // Confirm action
123
  if ( confirm( myCREDmanage.confirm_reset ) )
124
  mycred_action_reset_balance( $(this) );
125
-
126
  });
127
 
128
- $(document).ready( function() {
129
-
130
- if ( dWidth < 250 )
131
- dWidth = wWidth;
132
-
133
- if ( dWidth > 960 )
134
- dWidth = 960;
135
-
136
- /**
137
- * Export Balances Modal
138
- */
139
- $( '#export-points' ).dialog({
140
- dialogClass : 'mycred-export-points',
141
- draggable : true,
142
- autoOpen : false,
143
- title : myCREDmanage.export_title,
144
- closeText : myCREDmanage.export_close,
145
- modal : true,
146
- width : dWidth,
147
- height : 'auto',
148
- resizable : false,
149
- position : { my: "center", at: "top+25%", of: window },
150
- show : {
151
- effect : 'fadeIn',
152
- duration : 250
153
- },
154
- hide : {
155
- effect : 'fadeOut',
156
- duration : 250
157
- }
158
- });
159
-
160
- /**
161
- * Export balances Modal Trigger
162
- */
163
- $( '#mycred-export-users-points' ).click( function() {
164
-
165
- $(this).blur();
166
-
167
- $( '#export-points' ).dialog( 'open' );
168
-
169
- });
170
 
 
 
 
 
 
171
  });
172
 
173
  /**
174
  * Export Balances AJAX Caller
175
  */
176
  var mycred_action_export_balances = function( button ) {
177
-
178
  var label = button.val();
179
  $.ajax({
180
  type : "POST",
@@ -192,6 +132,8 @@ jQuery(function($) {
192
  button.attr( 'disabled', 'disabled' );
193
  },
194
  success : function( response ) {
 
 
195
 
196
  if ( response.success ) {
197
  setTimeout(function(){
@@ -207,26 +149,21 @@ jQuery(function($) {
207
  button.val( label );
208
  button.before( response.data );
209
  }
210
-
211
  }
212
  });
213
-
214
  };
215
 
216
  /**
217
  * Balance Export Trigger
218
  */
219
  $( '#mycred-run-exporter' ).click(function(){
220
-
221
  mycred_action_export_balances( $(this) );
222
-
223
  });
224
 
225
  /**
226
  * Generate Key AJAX Caller
227
  */
228
  var mycred_generate_key = function() {
229
-
230
  $.ajax({
231
  type : "POST",
232
  data : {
@@ -240,8 +177,7 @@ jQuery(function($) {
240
  $( '#mycred-length-counter' ).text( response.data.length );
241
  }
242
  });
243
-
244
- };
245
 
246
  /**
247
  * Generate Key Trigger
@@ -263,70 +199,4 @@ jQuery(function($) {
263
  $( '#myCRED-remote-key' ).keyup(function(){
264
  $( '#mycred-length-counter' ).text( $(this).val().length );
265
  });
266
-
267
- /**
268
- * Adjust Decimals AJAX Caller
269
- */
270
- var mycred_adjust_max_decimals = function( button, label, decval ) {
271
-
272
- $.ajax({
273
- type : "POST",
274
- data : {
275
- action : 'mycred-action-max-decimals',
276
- token : myCREDmanage.token,
277
- decimals : decval
278
- },
279
- dataType : "JSON",
280
- url : myCREDmanage.ajaxurl,
281
- beforeSend : function() {
282
- button.attr( 'value', myCREDmanage.working );
283
- button.attr( 'disabled', 'disabled' );
284
- },
285
- success : function( response ) {
286
-
287
- if ( response.success ) {
288
- button.val( response.data.label );
289
- setTimeout(function(){
290
- window.location.href = response.data.url;
291
- }, 4000 );
292
- }
293
- else {
294
- button.val( response.data );
295
- setTimeout(function(){
296
- button.removeAttr( 'disabled' );
297
- button.val( label );
298
- }, 4000 );
299
- }
300
-
301
- }
302
- });
303
-
304
- };
305
-
306
- /**
307
- * Show / Hide Update Button
308
- */
309
- $( '#mycred-adjust-decimal-places' ).change(function(){
310
-
311
- var originaldec = $(this).data( 'org' );
312
- var newvalue = $(this).val();
313
-
314
- if ( originaldec != newvalue )
315
- $( '#mycred-update-log-decimals' ).show();
316
- else
317
- $( '#mycred-update-log-decimals' ).hide();
318
-
319
- });
320
-
321
- /**
322
- * Update Log Decimals Trigger
323
- */
324
- $( '#mycred-update-log-decimals' ).click(function(){
325
-
326
- if ( confirm( myCREDmanage.decimals ) ) {
327
- mycred_adjust_max_decimals( $(this), $(this).val(), $( '#mycred-adjust-decimal-places' ).val() );
328
- }
329
-
330
- });
331
-
332
  });
1
  /**
2
  * myCRED Management Scripts
3
  * @since 1.3
4
+ * @version 1.2
5
  */
6
  jQuery(function($) {
7
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
8
  /**
9
  * Empty Log AJAX Caller
10
  */
11
  var mycred_action_empty_log = function( button ) {
 
12
  var label = button.val();
13
  $.ajax({
14
  type : "POST",
24
  button.attr( 'disabled', 'disabled' );
25
  },
26
  success : function( response ) {
 
27
  if ( response.success ) {
28
  $( 'input#mycred-manage-table-rows' ).val( response.data );
29
  button.val( myCREDmanage.done );
34
  button.removeAttr( 'disabled' );
35
  alert( response.data );
36
  }
 
37
  }
38
  });
 
39
  };
40
 
41
  /**
42
  * Empty Log Trigger
43
  */
44
+ $( 'input#mycred-manage-action-empty-log' ).click(function(){
 
45
  // Confirm action
46
  if ( confirm( myCREDmanage.confirm_log ) )
47
  mycred_action_empty_log( $(this) );
 
48
  });
49
 
50
  /**
51
  * Reset Balance AJAX Caller
52
  */
53
  var mycred_action_reset_balance = function( button ) {
 
54
  var label = button.val();
 
55
  $.ajax({
56
  type : "POST",
57
  data : {
66
  button.attr( 'disabled', 'disabled' );
67
  },
68
  success : function( response ) {
 
 
69
  if ( response.success ) {
70
+ button.val( response.data );
71
  button.removeClass( 'button-primary' );
72
  }
73
  else {
74
+ button.val( label );
75
  button.removeAttr( 'disabled' );
76
  alert( response.data );
77
  }
 
78
  }
79
  });
 
80
  };
81
 
82
  /**
83
  * Reset Balance Trigger
84
  */
85
+ $( 'input#mycred-manage-action-reset-accounts' ).click(function(){
 
86
  // Confirm action
87
  if ( confirm( myCREDmanage.confirm_reset ) )
88
  mycred_action_reset_balance( $(this) );
 
89
  });
90
 
91
+ /**
92
+ * Export Balances Modal
93
+ */
94
+ $('#export-points').dialog({
95
+ dialogClass : 'mycred-export-points',
96
+ draggable : false,
97
+ autoOpen : false,
98
+ closeText : myCREDmanage.export_close,
99
+ title : myCREDmanage.export_title,
100
+ modal : true,
101
+ width : 500,
102
+ resizable : false,
103
+ show : { effect: 'slide', direction: 'up', duration: 250 },
104
+ hide : { effect: 'slide', direction: 'up', duration: 250 }
105
+ });
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
106
 
107
+ /**
108
+ * Export balances Modal Trigger
109
+ */
110
+ $( '#mycred-export-users-points' ).click( function() {
111
+ $( '#export-points' ).dialog( 'open' );
112
  });
113
 
114
  /**
115
  * Export Balances AJAX Caller
116
  */
117
  var mycred_action_export_balances = function( button ) {
 
118
  var label = button.val();
119
  $.ajax({
120
  type : "POST",
132
  button.attr( 'disabled', 'disabled' );
133
  },
134
  success : function( response ) {
135
+ // Debug
136
+ //console.log( response );
137
 
138
  if ( response.success ) {
139
  setTimeout(function(){
149
  button.val( label );
150
  button.before( response.data );
151
  }
 
152
  }
153
  });
 
154
  };
155
 
156
  /**
157
  * Balance Export Trigger
158
  */
159
  $( '#mycred-run-exporter' ).click(function(){
 
160
  mycred_action_export_balances( $(this) );
 
161
  });
162
 
163
  /**
164
  * Generate Key AJAX Caller
165
  */
166
  var mycred_generate_key = function() {
 
167
  $.ajax({
168
  type : "POST",
169
  data : {
177
  $( '#mycred-length-counter' ).text( response.data.length );
178
  }
179
  });
180
+ }
 
181
 
182
  /**
183
  * Generate Key Trigger
199
  $( '#myCRED-remote-key' ).keyup(function(){
200
  $( '#mycred-length-counter' ).text( $(this).val().length );
201
  });
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
202
  });
assets/js/mycred-admin-widgets.js DELETED
@@ -1,608 +0,0 @@
1
- /**
2
- * myCRED Hook Management
3
- * Clone of the WordPress Widget management script with the ajax actions changed.
4
- * @since 1.7
5
- * @version 1.0
6
- */
7
- /*global ajaxurl, isRtl */
8
- var wpWidgets;
9
- (function($) {
10
- var $document = $( document );
11
-
12
- wpWidgets = {
13
- /**
14
- * A closed Sidebar that gets a Widget dragged over it.
15
- *
16
- * @var element|null
17
- */
18
- hoveredSidebar: null,
19
-
20
- init : function() {
21
- var rem, the_id,
22
- self = this,
23
- chooser = $('.widgets-chooser'),
24
- selectSidebar = chooser.find('.widgets-chooser-sidebars'),
25
- sidebars = $('div.widgets-sortables'),
26
- isRTL = !! ( 'undefined' !== typeof isRtl && isRtl );
27
-
28
- $('#widgets-right .sidebar-name').click( function() {
29
- var $this = $(this),
30
- $wrap = $this.closest('.widgets-holder-wrap');
31
-
32
- if ( $wrap.hasClass('closed') ) {
33
- $wrap.removeClass('closed');
34
- $this.parent().sortable('refresh');
35
- } else {
36
- $wrap.addClass('closed');
37
- }
38
-
39
- $document.triggerHandler( 'wp-pin-menu' );
40
- });
41
-
42
- $('#widgets-left .sidebar-name').click( function() {
43
- $(this).closest('.widgets-holder-wrap').toggleClass('closed');
44
- $document.triggerHandler( 'wp-pin-menu' );
45
- });
46
-
47
- $(document.body).bind('click.widgets-toggle', function(e) {
48
- var target = $(e.target),
49
- css = { 'z-index': 100 },
50
- widget, inside, targetWidth, widgetWidth, margin;
51
-
52
- if ( target.parents('.widget-top').length && ! target.parents('#available-widgets').length ) {
53
- widget = target.closest('div.widget');
54
- inside = widget.children('.widget-inside');
55
- targetWidth = parseInt( widget.find('input.widget-width').val(), 10 ),
56
- widgetWidth = widget.parent().width();
57
-
58
- if ( inside.is(':hidden') ) {
59
- if ( targetWidth > 250 && ( targetWidth + 30 > widgetWidth ) && widget.closest('div.widgets-sortables').length ) {
60
- if ( widget.closest('div.widget-liquid-right').length ) {
61
- margin = isRTL ? 'margin-right' : 'margin-left';
62
- } else {
63
- margin = isRTL ? 'margin-left' : 'margin-right';
64
- }
65
-
66
- css[ margin ] = widgetWidth - ( targetWidth + 30 ) + 'px';
67
- widget.css( css );
68
- }
69
- widget.addClass( 'open' );
70
- inside.slideDown('fast');
71
- } else {
72
- inside.slideUp('fast', function() {
73
- widget.attr( 'style', '' );
74
- widget.removeClass( 'open' );
75
- });
76
- }
77
- e.preventDefault();
78
- } else if ( target.hasClass('widget-control-save') ) {
79
- wpWidgets.save( target.closest('div.widget'), 0, 1, 0 );
80
- e.preventDefault();
81
- } else if ( target.hasClass('widget-control-remove') ) {
82
- wpWidgets.save( target.closest('div.widget'), 1, 1, 0 );
83
- e.preventDefault();
84
- } else if ( target.hasClass('widget-control-close') ) {
85
- widget = target.closest('div.widget');
86
- widget.removeClass( 'open' );
87
- wpWidgets.close( widget );
88
- e.preventDefault();
89
- } else if ( target.attr( 'id' ) === 'inactive-widgets-control-remove' ) {
90
- wpWidgets.removeInactiveWidgets();
91
- e.preventDefault();
92
- }
93
- });
94
-
95
- sidebars.children('.widget').each( function() {
96
- var $this = $(this);
97
-
98
- wpWidgets.appendTitle( this );
99
-
100
- if ( $this.find( 'p.widget-error' ).length ) {
101
- $this.find( 'a.widget-action' ).trigger('click');
102
- }
103
- });
104
-
105
- $('#widget-list').children('.widget').draggable({
106
- connectToSortable: 'div.widgets-sortables',
107
- handle: '> .widget-top > .widget-title',
108
- distance: 2,
109
- helper: 'clone',
110
- zIndex: 100,
111
- containment: '#wpwrap',
112
- refreshPositions: true,
113
- start: function( event, ui ) {
114
- var chooser = $(this).find('.widgets-chooser');
115
-
116
- ui.helper.find('div.widget-description').hide();
117
- the_id = this.id;
118
-
119
- if ( chooser.length ) {
120
- // Hide the chooser and move it out of the widget
121
- $( '#wpbody-content' ).append( chooser.hide() );
122
- // Delete the cloned chooser from the drag helper
123
- ui.helper.find('.widgets-chooser').remove();
124
- self.clearWidgetSelection();
125
- }
126
- },
127
- stop: function() {
128
- if ( rem ) {
129
- $(rem).hide();
130
- }
131
-
132
- rem = '';
133
- }
134
- });
135
-
136
- /**
137
- * Opens and closes previously closed Sidebars when Widgets are dragged over/out of them.
138
- */
139
- sidebars.droppable( {
140
- tolerance: 'intersect',
141
-
142
- /**
143
- * Open Sidebar when a Widget gets dragged over it.
144
- *
145
- * @param event
146
- */
147
- over: function( event ) {
148
- var $wrap = $( event.target ).parent();
149
-
150
- if ( wpWidgets.hoveredSidebar && ! $wrap.is( wpWidgets.hoveredSidebar ) ) {
151
- // Close the previous Sidebar as the Widget has been dragged onto another Sidebar.
152
- wpWidgets.closeSidebar( event );
153
- }
154
-
155
- if ( $wrap.hasClass( 'closed' ) ) {
156
- wpWidgets.hoveredSidebar = $wrap;
157
- $wrap.removeClass( 'closed' );
158
- }
159
-
160
- $( this ).sortable( 'refresh' );
161
- },
162
-
163
- /**
164
- * Close Sidebar when the Widget gets dragged out of it.
165
- *
166
- * @param event
167
- */
168
- out: function( event ) {
169
- if ( wpWidgets.hoveredSidebar ) {
170
- wpWidgets.closeSidebar( event );
171
- }
172
- }
173
- } );
174
-
175
- sidebars.sortable({
176
- placeholder: 'widget-placeholder',
177
- items: '> .widget',
178
- handle: '> .widget-top > .widget-title',
179
- cursor: 'move',
180
- distance: 2,
181
- containment: '#wpwrap',
182
- tolerance: 'pointer',
183
- refreshPositions: true,
184
- start: function( event, ui ) {
185
- var height, $this = $(this),
186
- $wrap = $this.parent(),
187
- inside = ui.item.children('.widget-inside');
188
-
189
- if ( inside.css('display') === 'block' ) {
190
- ui.item.removeClass('open');
191
- inside.hide();
192
- $(this).sortable('refreshPositions');
193
- }
194
-
195
- if ( ! $wrap.hasClass('closed') ) {
196
- // Lock all open sidebars min-height when starting to drag.
197
- // Prevents jumping when dragging a widget from an open sidebar to a closed sidebar below.
198
- height = ui.item.hasClass('ui-draggable') ? $this.height() : 1 + $this.height();
199
- $this.css( 'min-height', height + 'px' );
200
- }
201
- },
202
-
203
- stop: function( event, ui ) {
204
- var addNew, widgetNumber, $sidebar, $children, child, item,
205
- $widget = ui.item,
206
- id = the_id;
207
-
208
- // Reset the var to hold a previously closed sidebar.
209
- wpWidgets.hoveredSidebar = null;
210
-
211
- if ( $widget.hasClass('deleting') ) {
212
- wpWidgets.save( $widget, 1, 0, 1 ); // delete widget
213
- $widget.remove();
214
- return;
215
- }
216
-
217
- addNew = $widget.find('input.add_new').val();
218
- widgetNumber = $widget.find('input.multi_number').val();
219
-
220
- $widget.attr( 'style', '' ).removeClass('ui-draggable');
221
- the_id = '';
222
-
223
- if ( addNew ) {
224
- if ( 'multi' === addNew ) {
225
- $widget.html(
226
- $widget.html().replace( /<[^<>]+>/g, function( tag ) {
227
- return tag.replace( /__i__|%i%/g, widgetNumber );
228
- })
229
- );
230
-
231
- $widget.attr( 'id', id.replace( '__i__', widgetNumber ) );
232
- widgetNumber++;
233
-
234
- $( 'div#' + id ).find( 'input.multi_number' ).val( widgetNumber );
235
- } else if ( 'single' === addNew ) {
236
- if ( id === undefined ) id = $widget.attr( 'id' );
237
- $widget.attr( 'id', 'new-' + id );
238
- rem = 'div#' + id;
239
- }
240
-
241
- wpWidgets.save( $widget, 0, 0, 1 );
242
- $widget.find('input.add_new').val('');
243
- $document.trigger( 'widget-added', [ $widget ] );
244
- }
245
-
246
- $sidebar = $widget.parent();
247
-
248
- if ( $sidebar.parent().hasClass('closed') ) {
249
- $sidebar.parent().removeClass('closed');
250
- $children = $sidebar.children('.widget');
251
-
252
- // Make sure the dropped widget is at the top
253
- if ( $children.length > 1 ) {
254
- child = $children.get(0);
255
- item = $widget.get(0);
256
-
257
- if ( child.id && item.id && child.id !== item.id ) {
258
- $( child ).before( $widget );
259
- }
260
- }
261
- }
262
-
263
- if ( addNew ) {
264
- $widget.find( 'a.widget-action' ).trigger('click');
265
- } else {
266
- wpWidgets.saveOrder( $sidebar.attr('id') );
267
- }
268
- },
269
-
270
- activate: function() {
271
- $(this).parent().addClass( 'widget-hover' );
272
- },
273
-
274
- deactivate: function() {
275
- // Remove all min-height added on "start"
276
- $(this).css( 'min-height', '' ).parent().removeClass( 'widget-hover' );
277
- },
278
-
279
- receive: function( event, ui ) {
280
- var $sender = $( ui.sender );
281
-
282
- // Don't add more widgets to orphaned sidebars
283
- if ( this.id.indexOf('orphaned_widgets') > -1 ) {
284
- $sender.sortable('cancel');
285
- return;
286
- }
287
-
288
- // If the last widget was moved out of an orphaned sidebar, close and remove it.
289
- if ( $sender.attr('id').indexOf('orphaned_widgets') > -1 && ! $sender.children('.widget').length ) {
290
- $sender.parents('.orphan-sidebar').slideUp( 400, function(){ $(this).remove(); } );
291
- }
292
- }
293
- }).sortable( 'option', 'connectWith', 'div.widgets-sortables' );
294
-
295
- $('#available-widgets').droppable({
296
- tolerance: 'pointer',
297
- accept: function(o){
298
- return $(o).parent().attr('id') !== 'widget-list';
299
- },
300
- drop: function(e,ui) {
301
- ui.draggable.addClass('deleting');
302
- $('#removing-widget').hide().children('span').empty();
303
- },
304
- over: function(e,ui) {
305
- ui.draggable.addClass('deleting');
306
- $('div.widget-placeholder').hide();
307
-
308
- if ( ui.draggable.hasClass('ui-sortable-helper') ) {
309
- $('#removing-widget').show().children('span')
310
- .html( ui.draggable.find( 'div.widget-title' ).children( 'h3' ).html() );
311
- }
312
- },
313
- out: function(e,ui) {
314
- ui.draggable.removeClass('deleting');
315
- $('div.widget-placeholder').show();
316
- $('#removing-widget').hide().children('span').empty();
317
- }
318
- });
319
-
320
- // Area Chooser
321
- $( '#widgets-right .widgets-holder-wrap' ).each( function( index, element ) {
322
- var $element = $( element ),
323
- name = $element.find( '.sidebar-name h2' ).text(),
324
- id = $element.find( '.widgets-sortables' ).attr( 'id' ),
325
- li = $('<li tabindex="0">').text( $.trim( name ) );
326
-
327
- if ( index === 0 ) {
328
- li.addClass( 'widgets-chooser-selected' );
329
- }
330
-
331
- selectSidebar.append( li );
332
- li.data( 'sidebarId', id );
333
- });
334
-
335
- $( '#available-widgets .widget .widget-title' ).on( 'click.widgets-chooser', function() {
336
- var $widget = $(this).closest( '.widget' );
337
-
338
- if ( $widget.hasClass( 'widget-in-question' ) || $( '#widgets-left' ).hasClass( 'chooser' ) ) {
339
- self.closeChooser();
340
- } else {
341
- // Open the chooser
342
- self.clearWidgetSelection();
343
- $( '#widgets-left' ).addClass( 'chooser' );
344
- $widget.addClass( 'widget-in-question' ).children( '.widget-description' ).after( chooser );
345
-
346
- chooser.slideDown( 300, function() {
347
- selectSidebar.find('.widgets-chooser-selected').focus();
348
- });
349
-
350
- selectSidebar.find( 'li' ).on( 'focusin.widgets-chooser', function() {
351
- selectSidebar.find('.widgets-chooser-selected').removeClass( 'widgets-chooser-selected' );
352
- $(this).addClass( 'widgets-chooser-selected' );
353
- } );
354
- }
355
- });
356
-
357
- // Add event handlers
358
- chooser.on( 'click.widgets-chooser', function( event ) {
359
- var $target = $( event.target );
360
-
361
- if ( $target.hasClass('button-primary') ) {
362
- self.addWidget( chooser );
363
- self.closeChooser();
364
- } else if ( $target.hasClass('button-secondary') ) {
365
- self.closeChooser();
366
- }
367
- }).on( 'keyup.widgets-chooser', function( event ) {
368
- if ( event.which === $.ui.keyCode.ENTER ) {
369
- if ( $( event.target ).hasClass('button-secondary') ) {
370
- // Close instead of adding when pressing Enter on the Cancel button
371
- self.closeChooser();
372
- } else {
373
- self.addWidget( chooser );
374
- self.closeChooser();
375
- }
376
- } else if ( event.which === $.ui.keyCode.ESCAPE ) {
377
- self.closeChooser();
378
- }
379
- });
380
- },
381
-
382
- saveOrder : function( sidebarId ) {
383
- var data = {
384
- action: 'mycred-hook-order',
385
- savewidgets: $('#_wpnonce_widgets').val(),
386
- ctype: myCREDHooks.type,
387
- sidebars: []
388
- };
389
-
390
- if ( sidebarId ) {
391
- $( '#' + sidebarId ).find( '.spinner:first' ).addClass( 'is-active' );
392
- }
393
-
394
- $('div.widgets-sortables').each( function() {
395
- if ( $(this).sortable ) {
396
- data['sidebars[' + $(this).attr('id') + ']'] = $(this).sortable('toArray').join(',');
397
- }
398
- });
399
-
400
- $.post( ajaxurl, data, function(mho) {
401
- console.log( 'myCRED Hook Order' );
402
- $( '#inactive-widgets-control-remove' ).prop( 'disabled' , ! $( '#wp_inactive_widgets .widget' ).length );
403
- $( '.spinner' ).removeClass( 'is-active' );
404
- });
405
- },
406
-
407
- save : function( widget, del, animate, order ) {
408
- var sidebarId = widget.closest('div.widgets-sortables').attr('id'),
409
- data = widget.find('form').serialize(), a;
410
-
411
- widget = $(widget);
412
- $( '.spinner', widget ).addClass( 'is-active' );
413
-
414
- a = {
415
- action: 'mycred-save-hook',
416
- savewidgets: $('#_wpnonce_widgets').val(),
417
- ctype: myCREDHooks.type,
418
- sidebar: sidebarId
419
- };
420
-
421
- if ( del ) {
422
- a.delete_widget = 1;
423
- }
424
-
425
- data += '&' + $.param(a);
426
-
427
- $.post( ajaxurl, data, function(r) {
428
- var id;
429
- console.log( 'myCRED Save Hook' );
430
- if ( del ) {
431
- if ( ! $('input.widget_number', widget).val() ) {
432
- id = $('input.widget-id', widget).val();
433
- $('#available-widgets').find('input.widget-id').each(function(){
434
- if ( $(this).val() === id ) {
435
- $(this).closest('div.widget').show();
436
- }
437
- });
438
- }
439
-
440
- if ( animate ) {
441
- order = 0;
442
- widget.slideUp('fast', function(){
443
- $(this).remove();
444
- wpWidgets.saveOrder();
445
- });
446
- } else {
447
- widget.remove();
448
-
449
- if ( sidebarId === 'wp_inactive_widgets' ) {
450
- $( '#inactive-widgets-control-remove' ).prop( 'disabled' , ! $( '#wp_inactive_widgets .widget' ).length );
451
- }
452
- }
453
- } else {
454
- $( '.spinner' ).removeClass( 'is-active' );
455
- if ( r && r.length > 2 ) {
456
- $( 'div.widget-content', widget ).html( r );
457
- wpWidgets.appendTitle( widget );
458
- $document.trigger( 'widget-updated', [ widget ] );
459
-
460
- if ( sidebarId === 'wp_inactive_widgets' ) {
461
- $( '#inactive-widgets-control-remove' ).prop( 'disabled' , ! $( '#wp_inactive_widgets .widget' ).length );
462
- }
463
- }
464
- }
465
-
466
- if ( order ) {
467
- wpWidgets.saveOrder();
468
- }
469
- });
470
- },
471
-
472
- removeInactiveWidgets : function() {
473
- var $element = $( '.remove-inactive-widgets' ), a, data;
474
-
475
- $( '.spinner', $element ).addClass( 'is-active' );
476
-
477
- a = {
478
- action : 'delete-mycred-hook',
479
- ctype: myCREDHooks.type,
480
- removeinactivewidgets : $( '#_wpnonce_remove_inactive_widgets' ).val()
481
- };
482
-
483
- data = $.param( a );
484
-
485
- $.post( ajaxurl, data, function() {
486
- console.log( 'myCRED delete inactive Hook' );
487
- $( '#wp_inactive_widgets .widget' ).remove();
488
- $( '#inactive-widgets-control-remove' ).prop( 'disabled' , true );
489
- $( '.spinner', $element ).removeClass( 'is-active' );
490
- } );
491
- },
492
-
493
- appendTitle : function(widget) {
494
- var title = $('input[id*="-title"]', widget).val() || '';
495
-
496
- if ( title ) {
497
- title = ': ' + title.replace(/<[^<>]+>/g, '').replace(/</g, '&lt;').replace(/>/g, '&gt;');
498
- }
499
-
500
- $(widget).children('.widget-top').children('.widget-title').children()
501
- .children('.in-widget-title').html(title);
502
-
503
- },
504
-
505
- close : function(widget) {
506
- widget.children('.widget-inside').slideUp('fast', function() {
507
- widget.attr( 'style', '' );
508
- });
509
- },
510
-
511
- addWidget: function( chooser ) {
512
- var widget, widgetId, add, n, viewportTop, viewportBottom, sidebarBounds,
513
- sidebarId = chooser.find( '.widgets-chooser-selected' ).data('sidebarId'),
514
- sidebar = $( '#' + sidebarId );
515
-
516
- widget = $('#available-widgets').find('.widget-in-question').clone();
517
- widgetId = widget.attr('id');
518
- add = widget.find( 'input.add_new' ).val();
519
- n = widget.find( 'input.multi_number' ).val();
520
-
521
- // Remove the cloned chooser from the widget
522
- widget.find('.widgets-chooser').remove();
523
-
524
- if ( 'multi' === add ) {
525
- widget.html(
526
- widget.html().replace( /<[^<>]+>/g, function(m) {
527
- return m.replace( /__i__|%i%/g, n );
528
- })
529
- );
530
-
531
- widget.attr( 'id', widgetId.replace( '__i__', n ) );
532
- n++;
533
- $( '#' + widgetId ).find('input.multi_number').val(n);
534
- } else if ( 'single' === add ) {
535
- widget.attr( 'id', 'new-' + widgetId );
536
- $( '#' + widgetId ).hide();
537
- console.log( 'hidden a widget' );
538
- }
539
-
540
- // Open the widgets container
541
- sidebar.closest( '.widgets-holder-wrap' ).removeClass('closed');
542
-
543
- sidebar.append( widget );
544
- sidebar.sortable('refresh');
545
-
546
- wpWidgets.save( widget, 0, 0, 1 );
547
- // No longer "new" widget
548
- widget.find( 'input.add_new' ).val('');
549
-
550
- $document.trigger( 'widget-added', [ widget ] );
551
-
552
- /*
553
- * Check if any part of the sidebar is visible in the viewport. If it is, don't scroll.
554
- * Otherwise, scroll up to so the sidebar is in view.
555
- *
556
- * We do this by comparing the top and bottom, of the sidebar so see if they are within
557
- * the bounds of the viewport.
558
- */
559
- viewportTop = $(window).scrollTop();
560
- viewportBottom = viewportTop + $(window).height();
561
- sidebarBounds = sidebar.offset();
562
-
563
- sidebarBounds.bottom = sidebarBounds.top + sidebar.outerHeight();
564
-
565
- if ( viewportTop > sidebarBounds.bottom || viewportBottom < sidebarBounds.top ) {
566
- $( 'html, body' ).animate({
567
- scrollTop: sidebarBounds.top - 130
568
- }, 200 );
569
- }
570
-
571
- window.setTimeout( function() {
572
- // Cannot use a callback in the animation above as it fires twice,
573
- // have to queue this "by hand".
574
- widget.find( '.widget-title' ).trigger('click');
575
- }, 250 );
576
- },
577
-
578
- closeChooser: function() {
579
- var self = this;
580
-
581
- $( '.widgets-chooser' ).slideUp( 200, function() {
582
- $( '#wpbody-content' ).append( this );
583
- self.clearWidgetSelection();
584
- });
585
- },
586
-
587
- clearWidgetSelection: function() {
588
- $( '#widgets-left' ).removeClass( 'chooser' );
589
- $( '.widget-in-question' ).removeClass( 'widget-in-question' );
590
- },
591
-
592
- /**
593
- * Closes a Sidebar that was previously closed, but opened by dragging a Widget over it.
594
- *
595
- * Used when a Widget gets dragged in/out of the Sidebar and never dropped.
596
- *
597
- * @param sidebar
598
- */
599
- closeSidebar: function( sidebar ) {
600
- this.hoveredSidebar.addClass( 'closed' );
601
- $( sidebar.target ).css( 'min-height', '' );
602
- this.hoveredSidebar = null;
603
- }
604
- };
605
-
606
- $document.ready( function(){ wpWidgets.init(); } );
607
-
608
- })(jQuery);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
assets/js/mycred-edit-balance.js DELETED
@@ -1,292 +0,0 @@
1
- /**
2
- * myCRED Editor
3
- * Handles the product type editor in the WordPress admin area on the "Users" page.
4
- * @since 1.0
5
- * @version 1.3
6
- */
7
- jQuery(function($) {
8
-
9
- var myCREDtype = myCREDedit.defaulttype;
10
- var myCREDuser = 0;
11
-
12
- var myCREDEditorModal = $( '#edit-mycred-balance' );
13
- var myCREDEditorLedger = $( '#mycred-users-mini-ledger' );
14
- var myCREDEditorResults = $( '#mycred-editor-results' );
15
-
16
- var myCREDIDtoShow = $( '#mycred-userid-to-show' );
17
- var myCREDUsernametoShow = $( '#mycred-username-to-show' );
18
- var myCREDCBalancetoShow = $( '#mycred-current-to-show' );
19
- var myCREDTBalancetoShow = $( '#mycred-total-to-show' );
20
-
21
- var myCREDAmount = $( 'input#mycred-editor-amount' );
22
- var myCREDReference = $( 'select#mycred-editor-reference' );
23
- var myCREDCustomRefWrap = $( '#mycred-custom-reference-wrapper' );
24
- var myCREDCustomRef = $( 'input#mycred-editor-custom-reference' );
25
- var myCREDLogEntry = $( 'input#mycred-editor-entry' );
26
-
27
- var wWidth = $(window).width();
28
- var dWidth = wWidth * 0.75;
29
-
30
- /**
31
- * Reset Editor
32
- */
33
- function mycred_reset_editor() {
34
-
35
- var currentreference = myCREDReference.find( ':selected' );
36
- if ( currentreference !== undefined && currentreference.val() != myCREDedit.ref ) {
37
- currentreference.removeAttr( 'selected' );
38
- }
39
-
40
- myCREDAmount.val( '' );
41
- myCREDCustomRef.val( '' );
42
- myCREDLogEntry.val( '' );
43
-
44
- $( 'select#mycred-editor-reference option[value="' + myCREDedit.ref + '"]' ).attr( 'selected', 'selected' );
45
- myCREDCustomRefWrap.hide();
46
-
47
- myCREDuser = 0;
48
-
49
- }
50
-
51
- /**
52
- * Animate Balance
53
- */
54
- function mycred_animate_balance( elementtoanimate, finalAmount, decimals ) {
55
-
56
- var currentbalance = elementtoanimate.text();
57
-
58
- // Float
59
- if ( decimals > 0 ) {
60
-
61
- currentbalance = parseFloat( currentbalance );
62
- finalAmount = parseFloat( finalAmount );
63
-
64
- var decimal_factor = decimals === 0 ? 1 : Math.pow( 10, decimals );
65
-
66
- elementtoanimate.prop( 'number', currentbalance ).numerator({
67
- toValue : finalAmount,
68
- fromValue : currentbalance,
69
- rounding : decimals,
70
- duration : 2000
71
- });
72
-
73
- }
74
- // Int
75
- else {
76
-
77
- currentbalance = parseInt( currentbalance );
78
- finalAmount = parseInt( finalAmount );
79
-
80
- elementtoanimate.prop( 'number', currentbalance ).numerator({
81
- toValue : finalAmount,
82
- fromValue : currentbalance,
83
- duration : 2000
84
- });
85
-
86
- }
87
-
88
- }
89
-
90
- $(document).ready( function() {
91
-
92
- if ( dWidth < 250 )
93
- dWidth = wWidth;
94
-
95
- if ( dWidth > 960 )
96
- dWidth = 960;
97
-
98
- /**
99
- * Setup Editor Window
100
- */
101
- myCREDEditorModal.dialog({
102
- dialogClass : 'mycred-update-balance',
103
- draggable : true,
104
- autoOpen : false,
105
- title : myCREDedit.title,
106
- closeText : myCREDedit.close,
107
- modal : true,
108
- width : dWidth,
109
- height : 'auto',
110
- resizable : false,
111
- position : { my: "center", at: "top+25%", of: window },
112
- show : {
113
- effect : 'fadeIn',
114
- duration : 250
115
- },
116
- hide : {
117
- effect : 'fadeOut',
118
- duration : 250
119
- }
120
- });
121
-
122
- /**
123
- * Toggle Editor
124
- */
125
- $( '.mycred-open-points-editor' ).click( function(e) {
126
-
127
- e.preventDefault();
128
-
129
- myCREDtype = $(this).data( 'type' );
130
- myCREDuser = $(this).data( 'userid' );
131
-
132
- if ( myCREDEditorLedger.hasClass( 'shown' ) )
133
- myCREDEditorLedger.slideUp().removeClass( 'shown' );
134
-
135
- myCREDEditorResults.empty();
136
-
137
- // Setup the information we show about the user
138
- myCREDIDtoShow.empty().text( myCREDuser );
139
- myCREDUsernametoShow.empty().text( $(this).data( 'username' ) );
140
- myCREDCBalancetoShow.empty().text( $(this).data( 'current' ) );
141
- myCREDTBalancetoShow.empty().text( $(this).data( 'total' ) );
142
-
143
- $( 'input#mycred-edit-balance-of-user' ).val( myCREDuser );
144
- $( 'input#mycred-edit-balance-of-type' ).val( myCREDtype );
145
-
146
- // Setup amount placeholder
147
- myCREDAmount.attr( 'placeholder', $(this).data( 'zero' ) );
148
-
149
- console.log( 'Editing ' + $(this).data( 'username' ) + ' s balance' );
150
-
151
- // Show editor
152
- myCREDEditorModal.dialog( 'open' );
153
-
154
- });
155
-
156
- /**
157
- * Toggle custom reference field
158
- */
159
- myCREDReference.change(function() {
160
-
161
- var selectedreference = $(this).find( ':selected' );
162
- if ( selectedreference === undefined ) return false;
163
-
164
- if ( selectedreference.val() == 'mycred_custom' )
165
- myCREDCustomRefWrap.slideDown();
166
-
167
- else {
168
- myCREDCustomRefWrap.slideUp();
169
- myCREDCustomRef.val( '' );
170
- }
171
-
172
- });
173
-
174
- /**
175
- * Toggle mini ledger
176
- */
177
- $( 'button#load-users-mycred-history' ).click(function() {
178
-
179
- if ( myCREDEditorLedger.hasClass( 'shown' ) ) {
180
- myCREDEditorLedger.slideUp(function(){
181
- $( '#mycred-users-mini-ledger .border' ).empty().html( myCREDedit.loading );
182
- }).removeClass( 'shown' );
183
-
184
- }
185
-
186
- else {
187
-
188
- $( '#mycred-users-mini-ledger .border' ).empty().html( myCREDedit.loading );
189
- myCREDEditorLedger.slideDown().addClass( 'shown' );
190
- $(this).attr( 'disabled', 'disabled' );
191
-
192
- $.ajax({
193
- type : 'POST',
194
- data : {
195
- action : 'mycred-admin-recent-activity',
196
- token : myCREDedit.ledgertoken,
197
- userid : myCREDuser,
198
- type : myCREDtype
199
- },
200
- dataType : 'HTML',
201
- url : myCREDedit.ajaxurl,
202
- success : function( response ) {
203
-
204
- $( '#mycred-users-mini-ledger .border #mycred-processing' ).slideUp(function(){
205
- $( '#mycred-users-mini-ledger .border' ).empty().html( response ).slideDown();
206
- $( 'button#load-users-mycred-history' ).removeAttr( 'disabled' );
207
- });
208
-
209
- }
210
- });
211
-
212
- }
213
-
214
- });
215
-
216
- /**
217
- * Editor Submit
218
- */
219
- $( 'form#mycred-editor-form' ).submit( function(e) {
220
-
221
- e.preventDefault();
222
-
223
- $.ajax({
224
- type : 'POST',
225
- data : {
226
- action : 'mycred-admin-editor',
227
- token : myCREDedit.token,
228
- form : $(this).serialize()
229
- },
230
- dataType : 'JSON',
231
- url : myCREDedit.ajaxurl,
232
- beforeSend : function() {
233
-
234
- // Disable all fields in the form to prevent edits while we submit the form
235
- $( 'form#mycred-editor-form input' ).attr( 'readonly', 'readonly' );
236
- $( 'form#mycred-editor-form select' ).attr( 'readonly', 'readonly' );
237
-
238
- if ( myCREDEditorLedger.hasClass( 'shown' ) )
239
- $( 'button#load-users-mycred-history' ).click();
240
-
241
- // Disable submit button and show that we are working
242
- $( '#mycred-editor-submit' ).val( myCREDedit.working ).attr( 'disabled', 'disabled' );
243
- myCREDEditorResults.empty();
244
- $( '#mycred-editor-indicator' ).addClass( 'is-active' );
245
-
246
- },
247
- success : function( response ) {
248
-
249
- $( '#mycred-editor-indicator' ).removeClass( 'is-active' );
250
-
251
- // Security token has expired or something is blocking access to the ajax handler
252
- if ( response.success === undefined ) {
253
- myCREDEditorModal.dialog( 'destroy' );
254
- location.reload();
255
- }
256
-
257
- console.log( response );
258
-
259
- // Remove form restrictions
260
- $( 'form#mycred-editor-form input' ).removeAttr( 'readonly' );
261
- $( 'form#mycred-editor-form select' ).removeAttr( 'readonly' );
262
-
263
- // All went well, clear the form
264
- if ( response.success ) {
265
-
266
- mycred_animate_balance( myCREDCBalancetoShow, response.data.current, response.data.decimals );
267
- mycred_animate_balance( myCREDTBalancetoShow, response.data.total, response.data.decimals );
268
-
269
- $( '#mycred-user-' + myCREDuser + '-balance-' + myCREDtype + ' span' ).empty().text( response.data.current );
270
- $( '#mycred-user-' + myCREDuser + '-balance-total-' + myCREDtype + ' small span' ).empty().text( response.data.current );
271
-
272
- mycred_reset_editor();
273
-
274
- }
275
-
276
- // Update results
277
- myCREDEditorResults.html( response.data.results );
278
-
279
- // Reset submit button
280
- $( '#mycred-editor-submit' ).val( response.data.label ).removeAttr( 'disabled', 'disabled' );
281
-
282
- }
283
-
284
- });
285
-
286
- return false;
287
-
288
- });
289
-
290
- });
291
-
292
- });
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
assets/js/mycred-edit-log.js DELETED
@@ -1,387 +0,0 @@
1
- /**
2
- * myCRED Edit Log Scripts
3
- * These scripts are used to edit or delete entries
4
- * in the myCRED Log.
5
- * @since 1.4
6
- * @version 1.2.5
7
- */
8
- jQuery(function($) {
9
-
10
- var wWidth = $(window).width();
11
- var dWidth = wWidth * 0.75;
12
-
13
- var myCREDRowId = 0;
14
- var myCREDRow = '';
15
- var myCREDReference = '';
16
-
17
- var myCREDEditorModal = $( '#edit-mycred-log-entry' );
18
- var myCREDEditorResults = $( '#mycred-editor-results' );
19
- var myCREDAvailableTags = $( '#available-template-tags' );
20
-
21
- var myCREDUsertoShow = $( '#mycred-user-to-show' );
22
- var myCREDDatetoShow = $( '#mycred-date-to-show' );
23
- var myCREDAmounttoShow = $( '#mycred-creds-to-show' );
24
- var myCREDReferencetoShow = $( '#mycred-referece-to-show' );
25
- var myCREDOldEntrytoShow = $( '#mycred-old-entry-to-show' );
26
- var myCREDNewEntrytoShow = $( '#mycred-new-entry-to-show' );
27
-
28
- /**
29
- * Reset Editor
30
- */
31
- function mycred_reset_editor() {
32
-
33
- myCREDEditorResults.empty();
34
- myCREDUsertoShow.empty();
35
- myCREDDatetoShow.empty();
36
- myCREDAmounttoShow.val( '' );
37
- myCREDReferencetoShow.empty();
38
- myCREDOldEntrytoShow.empty();
39
- myCREDNewEntrytoShow.val( '' );
40
- myCREDAvailableTags.empty();
41
-
42
- $.each( myCREDLog.references, function( index ){
43
-
44
- var optiontoinsert = '<option value=\"' + index + '\"';
45
- if ( myCREDReference == index ) optiontoinsert += ' selected=\"selected\"';
46
- optiontoinsert += '>' + myCREDLog.references[ index ] + '<\/option>';
47
-
48
- myCREDReferencetoShow.append( optiontoinsert );
49
-
50
- });
51
-
52
- $( 'button#mycred-delete-entry-in-editor' ).attr( 'data', myCREDRowId );
53
-
54
- }
55
-
56
- /**
57
- * Animate Row Deletion
58
- */
59
- function mycred_animate_row_deletion( rowtoanimate ) {
60
-
61
- var rowtodelete = $( '#entry-' + rowtoanimate );
62
- if ( rowtodelete === undefined ) return;
63
-
64
- rowtodelete.addClass( 'deleted-row' ).fadeOut( 2000, function(){
65
- rowtodelete.remove();
66
- });
67
-
68
- }
69
-
70
- /**
71
- * Animate Row Update
72
- */
73
- function mycred_animate_row_update( newrow ) {
74
-
75
- var affectedrow = $( '#entry-' + myCREDRowId );
76
-
77
- affectedrow.addClass( 'updated-row' ).fadeOut(function(){
78
- affectedrow.empty().append( newrow ).fadeIn( 2000, function(){
79
- affectedrow.removeClass( 'updated-row' );
80
- });
81
- });
82
-
83
- }
84
-
85
- /**
86
- * Update Log Entry
87
- */
88
- function mycred_update_entry( submission ) {
89
-
90
- var submitbutton = $( '#mycred-editor-submit' );
91
- var submitlabel = submitbutton.val();
92
-
93
- $.ajax({
94
- type : "POST",
95
- data : {
96
- action : 'mycred-update-log-entry',
97
- token : myCREDLog.tokens.update,
98
- screen : myCREDLog.screen,
99
- page : myCREDLog.page,
100
- rowid : myCREDRowId,
101
- ctype : myCREDLog.ctype,
102
- form : submission
103
- },
104
- dataType : "JSON",
105
- url : myCREDLog.ajaxurl,
106
- beforeSend : function() {
107
-
108
- myCREDAmounttoShow.attr( 'readonly', 'readonly' );
109
- myCREDReferencetoShow.attr( 'readonly', 'readonly' );
110
- myCREDNewEntrytoShow.attr( 'readonly', 'readonly' );
111
-
112
- // Prep results box
113
- myCREDEditorResults.empty();
114
- $( '#mycred-editor-indicator' ).addClass( 'is-active' );
115
-
116
- // Indicate that we are doing something
117
- submitbutton.empty().text( myCREDLog.working );
118
-
119
- },
120
- success : function( response ) {
121
-
122
- // Remove indicator
123
- $( '#mycred-editor-indicator' ).removeClass( 'is-active' );
124
-
125
- // Most likelly the wpnonce has expired (screen open too long)
126
- if ( response.success === undefined ) {
127
- myCREDEditorModal.dialog( 'destroy' );
128
- location.reload();
129
- }
130
-
131
- // Ok, something was done
132
- else {
133
-
134
- myCREDAmounttoShow.removeAttr( 'readonly' );
135
- myCREDReferencetoShow.removeAttr( 'readonly' );
136
- myCREDNewEntrytoShow.removeAttr( 'readonly' );
137
-
138
- submitbutton.empty().text( submitlabel );
139
-
140
- myCREDEditorResults.text( response.data.message );
141
-
142
- if ( response.success === true ) {
143
- mycred_animate_row_update( response.data.results );
144
- }
145
-
146
- }
147
-
148
- }
149
- });
150
-
151
- }
152
-
153
- /**
154
- * Delete Log Entry
155
- */
156
- function mycred_delete_entry( entryid ) {
157
-
158
- var ismodalopen = myCREDEditorModal.dialog( "isOpen" );
159
- var deletebutton = $( '#mycred-delete-entry-in-editor' );
160
- var deletelabel = deletebutton.text();
161
-
162
- $.ajax({
163
- type : "POST",
164
- data : {
165
- action : 'mycred-delete-log-entry',
166
- token : myCREDLog.tokens.delete,
167
- row : entryid
168
- },
169
- dataType : "JSON",
170
- url : myCREDLog.ajaxurl,
171
- beforeSend : function() {
172
-
173
- if ( ismodalopen === true ) {
174
-
175
- // Make sure we can not make adjustments while we wait fo the AJAX handler to get back to us
176
- myCREDAmounttoShow.attr( 'readonly', 'readonly' );
177
- myCREDReferencetoShow.attr( 'readonly', 'readonly' );
178
- myCREDNewEntrytoShow.attr( 'readonly', 'readonly' );
179
-
180
- // Prep results box
181
- myCREDEditorResults.empty();
182
- $( '#mycred-editor-indicator' ).addClass( 'is-active' );
183
-
184
- // Indicate that we are doing something
185
- deletebutton.empty().text( myCREDLog.working );
186
-
187
- }
188
-
189
- },
190
- success : function( response ) {
191
-
192
- // Remove indicator
193
- $( '#mycred-editor-indicator' ).removeClass( 'is-active' );
194
-
195
- // Most likelly the wpnonce has expired (screen open too long)
196
- if ( response.success === undefined ) {
197
- myCREDEditorModal.dialog( 'destroy' );
198
- location.reload();
199
- }
200
-
201
- // Ok, something was done
202
- else {
203
-
204
- // Act based on where we clicked to delete - In modal
205
- if ( ismodalopen === true ) {
206
-
207
- myCREDEditorResults.text( response.data );
208
-
209
- // Request failed for some reason, restore form usability
210
- if ( response.success !== true ) {
211
-
212
- myCREDAmounttoShow.removeAttr( 'readonly' );
213
- myCREDReferencetoShow.removeAttr( 'readonly' );
214
- myCREDNewEntrytoShow.removeAttr( 'readonly' );
215
-
216
- deletebutton.empty().text( deletelabel );
217
-
218
- }
219
-
220
- // All good. Close Dialog
221
- else {
222
-
223
- // Reset row id
224
- myCREDRowId = 0;
225
-
226
- // Restore button label for next opening
227
- deletebutton.empty().text( deletelabel );
228
-
229
- // Close dialog window
230
- myCREDEditorModal.dialog( 'close' );
231
-
232
- }
233
-
234
- }
235
-
236
- // In table
237
- else {
238
-
239
- if ( response.success !== true )
240
- alert( response.data );
241
-
242
- }
243
-
244
- // No matter which button we pressed, animate the row removal if successfull
245
- if ( response.success === true )
246
- mycred_animate_row_deletion( entryid );
247
-
248
- }
249
-
250
- }
251
- });
252
-
253
- }
254
-
255
- /**
256
- * Once Ready
257
- */
258
- $(document).ready( function() {
259
-
260
- // Adjust modal width based on device width
261
- if ( dWidth < 250 )
262
- dWidth = wWidth;
263
-
264
- if ( dWidth > 960 )
265
- dWidth = 960;
266
-
267
- /**
268
- * Setup Editor Window
269
- */
270
- myCREDEditorModal.dialog({
271
- dialogClass : 'mycred-edit-logentry',
272
- draggable : true,
273
- autoOpen : false,
274
- title : myCREDLog.title,
275
- closeText : myCREDLog.close,
276
- modal : true,
277
- width : dWidth,
278
- height : 'auto',
279
- resizable : false,
280
- position : { my: "center", at: "top+25%", of: window },
281
- show : {
282
- effect : 'fadeIn',
283
- duration : 250
284
- },
285
- hide : {
286
- effect : 'fadeOut',
287
- duration : 250
288
- }
289
- });
290
-
291
- /**
292
- * Toggle Editor
293
- */
294
- $( 'tbody#the-list' ).on( 'click', '.mycred-open-log-entry-editor', function(e) {
295
-
296
- e.preventDefault();
297
-
298
- myCREDRowId = $(this).data( 'id' );
299
- myCREDReference = $(this).data( 'ref' );
300
- myCREDRow = '#entry-' + myCREDRowId;
301
-
302
- mycred_reset_editor();
303
-
304
- myCREDUsertoShow.append( $( myCREDRow + ' td.column-username strong' ).text() );
305
- myCREDDatetoShow.append( $( myCREDRow + ' td.column-time time' ).text() );
306
- myCREDOldEntrytoShow.append( $( myCREDRow + ' td.column-entry' ).text() );
307
- myCREDNewEntrytoShow.val( $( myCREDRow + ' td.column-entry' ).data( 'raw' ) );
308
-
309
- var amounttoshow = $( myCREDRow + ' td.column-creds' ).data( 'raw' );
310
- myCREDAmounttoShow.val( amounttoshow ).attr( 'placeholder', amounttoshow );
311
-
312
- // Show editor
313
- myCREDEditorModal.dialog( 'open' );
314
-
315
- });
316
-
317
- /**
318
- * Trigger Log Deletion
319
- */
320
- $( 'tbody#the-list' ).on( 'click', '.mycred-delete-row', function(){
321
-
322
- // Require user to confirm deletion (if used)
323
- if ( myCREDLog.messages.delete_row != '' && ! confirm( myCREDLog.messages.delete ) )
324
- return false;
325
-
326
- var deletebutton = $(this);
327
- var rowtodelete = deletebutton.data( 'id' );
328
-
329
- if ( rowtodelete === undefined || rowtodelete == '' )
330
- rowtodelete = myCREDRowId;
331
- else
332
- myCREDRowId = rowtodelete;
333
-
334
- mycred_delete_entry( rowtodelete );
335
-
336
- });
337
- $( '#mycred-delete-entry-in-editor' ).on( 'click', function(e){
338
-
339
- e.preventDefault();
340
-
341
- // Require user to confirm deletion (if used)
342
- if ( myCREDLog.messages.delete_row != '' && ! confirm( myCREDLog.messages.delete ) )
343
- return false;
344
-
345
- var deletebutton = $(this);
346
- var rowtodelete = deletebutton.data( 'id' );
347
-
348
- if ( rowtodelete === undefined || rowtodelete == '' )
349
- rowtodelete = myCREDRowId;
350
- else
351
- myCREDRowId = rowtodelete;
352
-
353
- mycred_delete_entry( rowtodelete );
354
-
355
- });
356
-
357
- /**
358
- * Submit New Log Entry
359
- */
360
- $( '#edit-mycred-log-entry' ).on( 'submit', 'form#mycred-editor-form', function(e){
361
-
362
- e.preventDefault();
363
-
364
- mycred_update_entry( $(this).serialize() );
365
-
366
- });
367
-
368
- });
369
-
370
- // Checkbox select in table
371
- // @see http://stackoverflow.com/questions/19164816/jquery-select-all-checkboxes-in-table
372
- $( '#myCRED-wrap form table thead .check-column input' ).click(function(e){
373
- var table= $(e.target).closest('table');
374
- $('.check-column input',table).prop( 'checked',this.checked );
375
- });
376
-
377
- /**
378
- * Click To Toggle Script
379
- */
380
- $( '.click-to-toggle' ).click(function(){
381
-
382
- var target = $(this).attr( 'data-toggle' );
383
- $( '#' + target ).toggle();
384
-
385
- });
386
-
387
- });
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
assets/libs/jquery-numerator.js DELETED
@@ -1,137 +0,0 @@
1
- /*
2
- * jQuery Numerator Plugin 0.2.1
3
- * https://github.com/garethdn/jquery-numerator
4
- *
5
- * Copyright 2015, Gareth Nolan
6
- * http://ie.linkedin.com/in/garethnolan/
7
-
8
- * Based on jQuery Boilerplate by Zeno Rocha with the help of Addy Osmani
9
- * http://jqueryboilerplate.com
10
- *
11
- * Licensed under the MIT license:
12
- * http://www.opensource.org/licenses/MIT
13
- */
14
-
15
- ;(function (factory) {
16
- 'use strict';
17
- if (typeof define === 'function' && define.amd) {
18
- // AMD is used - Register as an anonymous module.
19
- define(['jquery'], factory);
20
- } else if (typeof exports === 'object') {
21
- factory(require('jquery'));
22
- } else {
23
- // Neither AMD nor CommonJS used. Use global variables.
24
- if (typeof jQuery === 'undefined') {
25
- throw 'jquery-numerator requires jQuery to be loaded first';
26
- }
27
- factory(jQuery);
28
- }
29
- }(function ($) {
30
-
31
- var pluginName = "numerator",
32
- defaults = {
33
- easing: 'swing',
34
- duration: 500,
35
- delimiter: undefined,
36
- rounding: 0,
37
- toValue: undefined,
38
- fromValue: undefined,
39
- queue: false,
40
- onStart: function(){},
41
- onStep: function(){},
42
- onProgress: function(){},
43
- onComplete: function(){}
44
- };
45
-
46
- function Plugin ( element, options ) {
47
- this.element = element;
48
- this.settings = $.extend( {}, defaults, options );
49
- this._defaults = defaults;
50
- this._name = pluginName;
51
- this.init();
52
- }
53
-
54
- Plugin.prototype = {
55
-
56
- init: function () {
57
- this.parseElement();
58
- this.setValue();
59
- },
60
-
61
- parseElement: function () {
62
- var elText = $.trim($(this.element).text());
63
-
64
- this.settings.fromValue = this.settings.fromValue || this.format(elText);
65
- },
66
-
67
- setValue: function() {
68
- var self = this;
69
-
70
- $({value: self.settings.fromValue}).animate({value: self.settings.toValue}, {
71
-
72
- duration: parseInt(self.settings.duration, 10),
73
-
74
- easing: self.settings.easing,
75
-
76
- start: self.settings.onStart,
77
-
78
- step: function(now, fx) {
79
- $(self.element).text(self.format(now));
80
- // accepts two params - (now, fx)
81
- self.settings.onStep(now, fx);
82
- },
83
-
84
- // accepts three params - (animation object, progress ratio, time remaining(ms))
85
- progress: self.settings.onProgress,
86
-
87
- complete: self.settings.onComplete
88
- });
89
- },
90
-
91
- format: function(value){
92
- var self = this;
93
-
94
- if ( parseInt(this.settings.rounding ) < 1) {
95
- value = parseInt(value, 10);
96
- } else {
97
- value = parseFloat(value).toFixed( parseInt(this.settings.rounding) );
98
- }
99
-
100
- if (self.settings.delimiter) {
101
- return this.delimit(value)
102
- } else {
103
- return value;
104
- }
105
- },
106
-
107
- // TODO: Add comments to this function
108
- delimit: function(value){
109
- var self = this;
110
-
111
- value = value.toString();
112
-
113
- if (self.settings.rounding && parseInt(self.settings.rounding, 10) > 0) {
114
- var decimals = value.substring( (value.length - (self.settings.rounding + 1)), value.length ),
115
- wholeValue = value.substring( 0, (value.length - (self.settings.rounding + 1)));
116
-
117
- return self.addDelimiter(wholeValue) + decimals;
118
- } else {
119
- return self.addDelimiter(value);
120
- }
121
- },
122
-
123
- addDelimiter: function(value){
124
- return value.toString().replace(/\B(?=(\d{3})+(?!\d))/g, this.settings.delimiter);
125
- }
126
- };
127
-
128
- $.fn[ pluginName ] = function ( options ) {
129
- return this.each(function() {
130
- if ( $.data( this, "plugin_" + pluginName ) ) {
131
- $.data(this, 'plugin_' + pluginName, null);
132
- }
133
- $.data( this, "plugin_" + pluginName, new Plugin( this, options ) );
134
- });
135
- };
136
-
137
- }));
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
assets/libs/mustache.min.js DELETED
@@ -1 +0,0 @@
1
- (function defineMustache(global,factory){if(typeof exports==="object"&&exports&&typeof exports.nodeName!=="string"){factory(exports)}else if(typeof define==="function"&&define.amd){define(["exports"],factory)}else{global.Mustache={};factory(global.Mustache)}})(this,function mustacheFactory(mustache){var objectToString=Object.prototype.toString;var isArray=Array.isArray||function isArrayPolyfill(object){return objectToString.call(object)==="[object Array]"};function isFunction(object){return typeof object==="function"}function typeStr(obj){return isArray(obj)?"array":typeof obj}function escapeRegExp(string){return string.replace(/[\-\[\]{}()*+?.,\\\^$|#\s]/g,"\\$&")}function hasProperty(obj,propName){return obj!=null&&typeof obj==="object"&&propName in obj}var regExpTest=RegExp.prototype.test;function testRegExp(re,string){return regExpTest.call(re,string)}var nonSpaceRe=/\S/;function isWhitespace(string){return!testRegExp(nonSpaceRe,string)}var entityMap={"&":"&amp;","<":"&lt;",">":"&gt;",'"':"&quot;","'":"&#39;","/":"&#x2F;","`":"&#x60;","=":"&#x3D;"};function escapeHtml(string){return String(string).replace(/[&<>"'`=\/]/g,function fromEntityMap(s){return entityMap[s]})}var whiteRe=/\s*/;var spaceRe=/\s+/;var equalsRe=/\s*=/;var curlyRe=/\s*\}/;var tagRe=/#|\^|\/|>|\{|&|=|!/;function parseTemplate(template,tags){if(!template)return[];var sections=[];var tokens=[];var spaces=[];var hasTag=false;var nonSpace=false;function stripSpace(){if(hasTag&&!nonSpace){while(spaces.length)delete tokens[spaces.pop()]}else{spaces=[]}hasTag=false;nonSpace=false}var openingTagRe,closingTagRe,closingCurlyRe;function compileTags(tagsToCompile){if(typeof tagsToCompile==="string")tagsToCompile=tagsToCompile.split(spaceRe,2);if(!isArray(tagsToCompile)||tagsToCompile.length!==2)throw new Error("Invalid tags: "+tagsToCompile);openingTagRe=new RegExp(escapeRegExp(tagsToCompile[0])+"\\s*");closingTagRe=new RegExp("\\s*"+escapeRegExp(tagsToCompile[1]));closingCurlyRe=new RegExp("\\s*"+escapeRegExp("}"+tagsToCompile[1]))}compileTags(tags||mustache.tags);var scanner=new Scanner(template);var start,type,value,chr,token,openSection;while(!scanner.eos()){start=scanner.pos;value=scanner.scanUntil(openingTagRe);if(value){for(var i=0,valueLength=value.length;i<valueLength;++i){chr=value.charAt(i);if(isWhitespace(chr)){spaces.push(tokens.length)}else{nonSpace=true}tokens.push(["text",chr,start,start+1]);start+=1;if(chr==="\n")stripSpace()}}if(!scanner.scan(openingTagRe))break;hasTag=true;type=scanner.scan(tagRe)||"name";scanner.scan(whiteRe);if(type==="="){value=scanner.scanUntil(equalsRe);scanner.scan(equalsRe);scanner.scanUntil(closingTagRe)}else if(type==="{"){value=scanner.scanUntil(closingCurlyRe);scanner.scan(curlyRe);scanner.scanUntil(closingTagRe);type="&"}else{value=scanner.scanUntil(closingTagRe)}if(!scanner.scan(closingTagRe))throw new Error("Unclosed tag at "+scanner.pos);token=[type,value,start,scanner.pos];tokens.push(token);if(type==="#"||type==="^"){sections.push(token)}else if(type==="/"){openSection=sections.pop();if(!openSection)throw new Error('Unopened section "'+value+'" at '+start);if(openSection[1]!==value)throw new Error('Unclosed section "'+openSection[1]+'" at '+start)}else if(type==="name"||type==="{"||type==="&"){nonSpace=true}else if(type==="="){compileTags(value)}}openSection=sections.pop();if(openSection)throw new Error('Unclosed section "'+openSection[1]+'" at '+scanner.pos);return nestTokens(squashTokens(tokens))}function squashTokens(tokens){var squashedTokens=[];var token,lastToken;for(var i=0,numTokens=tokens.length;i<numTokens;++i){token=tokens[i];if(token){if(token[0]==="text"&&lastToken&&lastToken[0]==="text"){lastToken[1]+=token[1];lastToken[3]=token[3]}else{squashedTokens.push(token);lastToken=token}}}return squashedTokens}function nestTokens(tokens){var nestedTokens=[];var collector=nestedTokens;var sections=[];var token,section;for(var i=0,numTokens=tokens.length;i<numTokens;++i){token=tokens[i];switch(token[0]){case"#":case"^":collector.push(token);sections.push(token);collector=token[4]=[];break;case"/":section=sections.pop();section[5]=token[2];collector=sections.length>0?sections[sections.length-1][4]:nestedTokens;break;default:collector.push(token)}}return nestedTokens}function Scanner(string){this.string=string;this.tail=string;this.pos=0}Scanner.prototype.eos=function eos(){return this.tail===""};Scanner.prototype.scan=function scan(re){var match=this.tail.match(re);if(!match||match.index!==0)return"";var string=match[0];this.tail=this.tail.substring(string.length);this.pos+=string.length;return string};Scanner.prototype.scanUntil=function scanUntil(re){var index=this.tail.search(re),match;switch(index){case-1:match=this.tail;this.tail="";break;case 0:match="";break;default:match=this.tail.substring(0,index);this.tail=this.tail.substring(index)}this.pos+=match.length;return match};function Context(view,parentContext){this.view=view;this.cache={".":this.view};this.parent=parentContext}Context.prototype.push=function push(view){return new Context(view,this)};Context.prototype.lookup=function lookup(name){var cache=this.cache;var value;if(cache.hasOwnProperty(name)){value=cache[name]}else{var context=this,names,index,lookupHit=false;while(context){if(name.indexOf(".")>0){value=context.view;names=name.split(".");index=0;while(value!=null&&index<names.length){if(index===names.length-1)lookupHit=hasProperty(value,names[index]);value=value[names[index++]]}}else{value=context.view[name];lookupHit=hasProperty(context.view,name)}if(lookupHit)break;context=context.parent}cache[name]=value}if(isFunction(value))value=value.call(this.view);return value};function Writer(){this.cache={}}Writer.prototype.clearCache=function clearCache(){this.cache={}};Writer.prototype.parse=function parse(template,tags){var cache=this.cache;var tokens=cache[template];if(tokens==null)tokens=cache[template]=parseTemplate(template,tags);return tokens};Writer.prototype.render=function render(template,view,partials){var tokens=this.parse(template);var context=view instanceof Context?view:new Context(view);return this.renderTokens(tokens,context,partials,template)};Writer.prototype.renderTokens=function renderTokens(tokens,context,partials,originalTemplate){var buffer="";var token,symbol,value;for(var i=0,numTokens=tokens.length;i<numTokens;++i){value=undefined;token=tokens[i];symbol=token[0];if(symbol==="#")value=this.renderSection(token,context,partials,originalTemplate);else if(symbol==="^")value=this.renderInverted(token,context,partials,originalTemplate);else if(symbol===">")value=this.renderPartial(token,context,partials,originalTemplate);else if(symbol==="&")value=this.unescapedValue(token,context);else if(symbol==="name")value=this.escapedValue(token,context);else if(symbol==="text")value=this.rawValue(token);if(value!==undefined)buffer+=value}return buffer};Writer.prototype.renderSection=function renderSection(token,context,partials,originalTemplate){var self=this;var buffer="";var value=context.lookup(token[1]);function subRender(template){return self.render(template,context,partials)}if(!value)return;if(isArray(value)){for(var j=0,valueLength=value.length;j<valueLength;++j){buffer+=this.renderTokens(token[4],context.push(value[j]),partials,originalTemplate)}}else if(typeof value==="object"||typeof value==="string"||typeof value==="number"){buffer+=this.renderTokens(token[4],context.push(value),partials,originalTemplate)}else if(isFunction(value)){if(typeof originalTemplate!=="string")throw new Error("Cannot use higher-order sections without the original template");value=value.call(context.view,originalTemplate.slice(token[3],token[5]),subRender);if(value!=null)buffer+=value}else{buffer+=this.renderTokens(token[4],context,partials,originalTemplate)}return buffer};Writer.prototype.renderInverted=function renderInverted(token,context,partials,originalTemplate){var value=context.lookup(token[1]);if(!value||isArray(value)&&value.length===0)return this.renderTokens(token[4],context,partials,originalTemplate)};Writer.prototype.renderPartial=function renderPartial(token,context,partials){if(!partials)return;var value=isFunction(partials)?partials(token[1]):partials[token[1]];if(value!=null)return this.renderTokens(this.parse(value),context,partials,value)};Writer.prototype.unescapedValue=function unescapedValue(token,context){var value=context.lookup(token[1]);if(value!=null)return value};Writer.prototype.escapedValue=function escapedValue(token,context){var value=context.lookup(token[1]);if(value!=null)return mustache.escape(value)};Writer.prototype.rawValue=function rawValue(token){return token[1]};mustache.name="mustache.js";mustache.version="2.2.1";mustache.tags=["{{","}}"];var defaultWriter=new Writer;mustache.clearCache=function clearCache(){return defaultWriter.clearCache()};mustache.parse=function parse(template,tags){return defaultWriter.parse(template,tags)};mustache.render=function render(template,view,partials){if(typeof template!=="string"){throw new TypeError('Invalid template! Template should be a "string" '+'but "'+typeStr(template)+'" was given as the first '+"argument for mustache#render(template, view, partials)")}return defaultWriter.render(template,view,partials)};mustache.to_html=function to_html(template,view,partials,send){var result=mustache.render(template,view,partials);if(isFunction(send)){send(result)}else{return result}};mustache.escape=escapeHtml;mustache.Scanner=Scanner;mustache.Context=Context;mustache.Writer=Writer});
 
assets/libs/parsecsv.lib.php CHANGED
File without changes
assets/screenshot-5.png ADDED
Binary file
includes/classes/class.query-export.php DELETED
@@ -1,589 +0,0 @@
1
- <?php
2
- if ( ! defined( 'myCRED_VERSION' ) ) exit;
3
-
4
- /**
5
- * Query Export
6
- * @see http://codex.mycred.me/classes/mycred_query_export/
7
- * @since 1.7
8
- * @version 1.0
9
- */
10
- if ( ! class_exists( 'myCRED_Query_Export' ) ) :
11
- class myCRED_Query_Export {
12
-
13
- protected $db = '';
14
-
15
- public $args = array();
16
- public $headers = array();
17
- public $raw = false;
18
- public $file_name = '';
19
- public $references = array();
20
- public $orderby = '';
21
- public $limit = '';
22
- public $user_id = false;
23
-
24
- protected $data = array();
25
- protected $types = array();
26
-
27
- /**
28
- * Construct
29
- */
30
- public function __construct( $args = array(), $headers = array() ) {
31
-
32
- global $mycred;
33
-
34
- $this->args = apply_filters( 'mycred_export_args', shortcode_atts( array(
35
- 'raw' => false,
36
- 'number' => -1,
37
- 'order' => 'time',
38
- 'orderby' => 'DESC',
39
- 'date_format' => get_option( 'date_format' )
40
- ), $args ), $args );
41
-
42
- $this->db = $mycred->log_table;
43
- $this->raw = $this->args['raw'];
44
- $this->references = mycred_get_all_references();
45
-
46
- $this->set_orderby();
47
- $this->set_limit();
48
- $this->set_column_headers( $headers );
49
-
50
- }
51
-
52
- /**
53
- * Set Export File Name
54
- * Sets the file name we will use when we export.
55
- * @version 1.0
56
- */
57
- public function set_export_file_name( $name = '' ) {
58
-
59
- $file = mb_ereg_replace( "([^\w\s\d\-_~,;\[\]\(\).])", '', $name );
60
- $file = mb_ereg_replace( "([\.]{2,})", '', $name );
61
-
62
- if ( $file === NULL || $file === false || strlen( $file ) == 0 )
63
- $file = 'mycred-export-' . date( $this->args['date_format'], current_time( 'timestamp' ) ) . '.csv';
64
-
65
- $username = '';
66
- $point_type = 'default';
67
-
68
- if ( $this->user_id !== false ) {
69
-
70
- $user = get_userdata( $this->user_id );
71
- if ( isset( $user->user_login ) )
72
- $username = $user->user_login;
73
-
74
- }
75
-
76
- if ( ! empty( $this->types ) && count( $this->types ) == 1 ) {
77
- foreach ( $this->types as $type_id => $mycred )
78
- $point_type = $type_id;
79
- }
80
-
81
- $file = str_replace( '%username%', $username, $file );
82
- $file = str_replace( '%point_type%', $point_type, $file );
83
-
84
- $this->file_name = apply_filters( 'mycred_export_file_name', $file, $name, $this );
85
-
86
- }
87
-
88
- /**
89
- * Get Data by IDs
90
- * Retreaves log entries based on a set of entry ids.
91
- * @version 1.0
92
- */
93
- public function get_data_by_ids( $ids = array() ) {
94
-
95
- $ids = $this->clean_ids( $ids );
96
- if ( $ids === true || empty( $ids ) || empty( $this->headers ) ) return false;
97
-
98
- global $wpdb;
99
-
100
- $id_list = implode( ', ', $ids );
101
- $data = $wpdb->get_results( "SELECT * FROM {$this->db} WHERE id IN ({$id_list}) ORDER BY {$this->orderby} {$this->limit};" );
102
-
103
- $exportable_data = array();
104
- if ( ! empty( $data ) ) {
105
-
106
- $this->set_point_types( $data );
107
-
108
- foreach ( $data as $entry ) {
109
-
110
- if ( $this->raw )
111
- $exportable_data[] = $this->get_raw_entry( $entry );
112
- else
113
- $exportable_data[] = $this->get_rendered_entry( $entry );
114
-
115
- }
116
-
117
- }
118
- $this->data = $exportable_data;
119
-
120
- return $exportable_data;
121
-
122
- }
123
-
124
- /**
125
- * Get Data by User
126
- * Retreaves log entries based on a given user ID.
127
- * @version 1.0
128
- */
129
- public function get_data_by_user( $user_id = NULL ) {
130
-
131
- $user_id = absint( $user_id );
132
- if ( $user_id === 0 ) return false;
133
-
134
- global $wpdb;
135
-
136
- $this->user_id = $user_id;
137
- $data = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM {$this->db} WHERE user_id = %d ORDER BY {$this->orderby} {$this->limit};", $user_id ) );
138
-
139
- $exportable_data = array();
140
- if ( ! empty( $data ) ) {
141
-
142
- $this->set_point_types( $data );
143
-
144
- foreach ( $data as $entry ) {
145
-
146
- if ( $this->raw )
147
- $exportable_data[] = $this->get_raw_entry( $entry );
148
- else
149
- $exportable_data[] = $this->get_rendered_entry( $entry );
150
-
151
- }
152
-
153
- }
154
- $this->data = $exportable_data;
155
-
156
- return $exportable_data;
157
-
158
- }
159
-
160
- /**
161
- * Get Data by Type
162
- * Retreaves log entries based on a given point type.
163
- * @version 1.0
164
- */
165
- public function get_data_by_type( $point_type = NULL ) {
166
-
167
- $point_type = sanitize_key( $point_type );
168
- if ( ! mycred_point_type_exists( $point_type ) ) return false;
169
-
170
- global $wpdb;
171
-
172
- $data = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM {$this->db} WHERE ctype = %s ORDER BY {$this->orderby} {$this->limit};", $point_type ) );
173
-
174
- $exportable_data = array();
175
- if ( ! empty( $data ) ) {
176
-
177
- $types = array();
178
- $types[ $point_type ] = mycred( $point_type );
179
- $this->types = $types;
180
-
181
- foreach ( $data as $entry ) {
182
-
183
- if ( $this->raw )
184
- $exportable_data[] = $this->get_raw_entry( $entry );
185
- else
186
- $exportable_data[] = $this->get_rendered_entry( $entry );
187
-
188
- }
189
-
190
- }
191
- $this->data = $exportable_data;
192
-
193
- return $exportable_data;
194
-
195
- }
196
-
197
- /**
198
- * Get Data by Query
199
- * Retreaves log entries based on an array of query arguments.
200
- * @version 1.0
201
- */
202
- public function get_data_by_query( $args = array() ) {
203
-
204
- $log = new myCRED_Query_Log( $args );
205
-
206
- if ( $log->have_entries() )
207
- $this->data = $log->results;
208
-
209
- $log->reset_query();
210
-
211
- }
212
-
213
- /**
214
- * Set Orderby
215
- * Converts a valid set of order arguments into the order arguments the export
216
- * db queries will use.
217
- * @version 1.0
218
- */
219
- protected function set_orderby() {
220
-
221
- $default = 'time DESC';
222
- $order = sanitize_key( $this->args['order'] );
223
- $by = sanitize_text_field( $this->args['orderby'] );
224
-
225
- if ( ! in_array( $order, array( 'id', 'time', 'user_id', 'creds', 'ctype', 'entry', 'data', 'ref', 'ref_id' ) ) )
226
- $order = 'time';
227
-
228
- if ( ! in_array( $by, array( 'ASC', 'DESC' ) ) )
229
- $by = 'DESC';
230
-
231
- $orderby = $order . ' ' . $by;
232
- if ( strlen( $orderby ) === 1 )
233
- $orderby = $default;
234
-
235
- $this->orderby = apply_filters( 'mycred_export_orderby', $orderby, $this->args );
236
-
237
- }
238
-
239
- /**
240
- * Set Limit
241
- * Sets the limit argument to be used in the db queries based on the argument we gave.
242
- * @version 1.0
243
- */
244
- protected function set_limit() {
245
-
246
- $number = (int) sanitize_text_field( $this->args['number'] );
247
- if ( $number > 0 )
248
- $number = absint( $number );
249
-
250
- if ( $number > 0 )
251
- $this->limit = 'LIMIT 0,' . $number;
252
-
253
- }
254
-
255
- /**
256
- * Set Column Headers
257
- * Sets a valid set of column headers for the export.
258
- * @version 1.0
259
- */
260
- protected function set_column_headers( $headers = array() ) {
261
-
262
- if ( empty( $headers ) || ! is_array( $headers ) )
263
- $headers = array( 'ref' => __( 'Reference', 'mycred' ), 'ref_id' => __( 'Reference ID', 'mycred' ), 'user_id' => __( 'User', 'mycred' ), 'creds' => __( 'Amount', 'mycred' ), 'ctype' => __( 'Point Type', 'mycred' ), 'time' => __( 'Date', 'mycred' ), 'entry' => __( 'Entry', 'mycred' ), 'data' => __( 'Data', 'mycred' ) );
264
-
265
- if ( ! $this->raw ) {
266
- unset( $headers['ref_id'] );
267
- unset( $headers['data'] );
268
- }
269
-
270
- $headers = apply_filters( 'mycred_export_headers', $headers, $this->raw );
271
-
272
- if ( $this->raw )
273
- $this->headers = array_keys( $headers );
274
-
275
- else
276
- $this->headers = array_values( $headers );
277
-
278
- }
279
-
280
- /**
281
- * Clean IDs
282
- * Sanitization function for array of entry ids. Also eliminates duplicates.
283
- * @returns array of intregers or false
284
- * @version 1.0
285
- */
286
- protected function clean_ids( $data = array() ) {
287
-
288
- if ( empty( $data ) ) return false;
289
-
290
- $clean_ids = array();
291
- foreach ( $data as $unknown_id ) {
292
- $abs_int = absint( $unknown_id );
293
- if ( $abs_int === 0 || in_array( $abs_int, $clean_ids ) ) continue;
294
- $clean_ids[] = $abs_int;
295
- }
296
-
297
- return $clean_ids;
298
-
299
- }
300
-
301
- /**
302
- * Set Point Types
303
- * Populates $this->types with all the point types found int the data.
304
- * @version 1.0
305
- */
306
- protected function set_point_types( $data ) {
307
-
308
- $types = array();
309
- foreach ( $data as $entry ) {
310
-
311
- if ( isset( $entry->ctype ) && sanitize_text_field( $entry->ctype ) !== '' && ! array_key_exists( $entry->ctype, $types ) )
312
- $types[ $entry->ctype ] = mycred( $entry->ctype );
313
-
314
- }
315
-
316
- $this->types = $types;
317
-
318
- }
319
-
320
- /**
321
- * Get Raw Entry
322
- * Returns the values for all columns in the current export row in raw format.
323
- * @version 1.0
324
- */
325
- protected function get_raw_entry( $entry ) {
326
-
327
- $row = array();
328
- if ( ! empty( $this->headers ) ) {
329
- foreach ( $this->headers as $header_id ) {
330
-
331
- $value = '';
332
- if ( isset( $entry->$header_id ) )
333
- $value = $entry->$header_id;
334
-
335
- $row[ $header_id ] = $value;
336
-
337
- }
338
- }
339
-
340
- return $row;
341
-
342
- }
343
-
344
- /**
345
- * Get Rendered Entry
346
- * Returns the values for all columns in the current export row formatted.
347
- * @version 1.0
348
- */
349
- protected function get_rendered_entry( $entry ) {
350
-
351
- $row = array();
352
- $type = $entry->ctype;
353
-
354
- if ( ! empty( $this->headers ) ) {
355
- foreach ( $this->headers as $header_id ) {
356
-
357
- switch ( $header_id ) {
358
-
359
- case 'ref' :
360
- case __( 'Reference', 'mycred' ) :
361
-
362
- $content = '';
363
- if ( array_key_exists( $entry->ref, $this->references ) )
364
- $content = $this->references[ $entry->ref ];
365
-
366
- $content = apply_filters( 'mycred_log_ref', $content, $entry->ref, $entry );
367
-
368
- break;
369
-
370
- case 'user_id' :
371
- case __( 'User', 'mycred' ) :
372
-
373
- $user = get_userdata( $entry->user_id );
374
- $display_name = '<span>' . __( 'User Missing', 'mycred' ) . ' (ID: ' . $entry->user_id . ')</span>';
375
- if ( isset( $user->display_name ) )
376
- $display_name = $user->display_name;
377
-
378
- $content = apply_filters( 'mycred_log_username', $display_name, $entry->user_id, $entry );
379
-
380
- break;
381
-
382
- case 'creds' :
383
- case __( 'Amount', 'mycred' ) :
384
-
385
- $content = $this->types[ $type ]->format_creds( $entry->creds );
386
- $content = apply_filters( 'mycred_log_creds', $content, $entry->creds, $entry );
387
-
388
- break;
389
-
390
- case 'ctype' :
391
- case __( 'Point Type', 'mycred' ) :
392
-
393
- $content = $this->types[ $type ]->plural();
394
- $content = apply_filters( 'mycred_log_ctype', $content, $entry->ctype, $entry );
395
-
396
- break;
397
-
398
- case 'time' :
399
- case __( 'Date', 'mycred' ) :
400
-
401
- $content = apply_filters( 'mycred_log_date', date( $this->args['date_format'], $entry->time ), $entry->time, $entry );
402
-
403
- break;
404
-
405
- case 'entry' :
406
- case __( 'Entry', 'mycred' ) :
407
-
408
- $content = $this->types[ $type ]->parse_template_tags( $entry->entry, $entry );
409
- $content = apply_filters( 'mycred_log_entry', $content, $entry->entry, $entry );
410
-
411
- break;
412
-
413
- // Let others play
414
- default :
415
-
416
- $content = apply_filters( 'mycred_log_' . $header_id, '', $entry );
417
-
418
- break;
419
-
420
- }
421
-
422
- $row[ $header_id ] = $content;
423
-
424
- }
425
- }
426
-
427
- return $row;
428
-
429
- }
430
-
431
- /**
432
- * Do Export
433
- * If data is available for export, we run the export tool.
434
- * @version 1.0.1
435
- */
436
- public function do_export() {
437
-
438
- if ( empty( $this->data ) ) return false;
439
-
440
- // Load parseCSV
441
- if ( ! class_exists( 'parseCSV' ) )
442
- require_once myCRED_ASSETS_DIR . 'libs/parsecsv.lib.php';
443
-
444
- $csv = new parseCSV();
445
- $csv->output( true, $this->file_name, $this->data, $this->headers );
446
-
447
- exit;
448
-
449
- }
450
-
451
- }
452
- endif;
453
-
454
- /**
455
- * Get Export Formats
456
- * Returns an arry of supported formats.
457
- * @since 1.7
458
- * @version 1.0
459
- */
460
- if ( ! function_exists( 'mycred_get_export_formats' ) ) :
461
- function mycred_get_export_formats() {
462
-
463
- return apply_filters( 'mycred_export_formats', array(
464
- 'raw' => __( 'Export log entries raw', 'mycred' ),
465
- 'formatted' => __( 'Export log entries formatted', 'mycred' )
466
- ) );
467
-
468
- }
469
- endif;
470
-
471
- /**
472
- * Get Log Exports
473
- * Returns an associative array of log export options.
474
- * @since 1.4
475
- * @version 1.2
476
- */
477
- if ( ! function_exists( 'mycred_get_log_exports' ) ) :
478
- function mycred_get_log_exports() {
479
-
480
- $defaults = array(
481
- 'all' => array(
482
- 'label' => __( 'All Log Entries', 'mycred' ),
483
- 'my_label' => NULL,
484
- 'class' => 'btn btn-primary button button-primary'
485
- ),
486
- 'search' => array(
487
- 'label' => __( 'Search Results', 'mycred' ),
488
- 'my_label' => NULL,
489
- 'class' => 'btn btn-primary button button-secondary'
490
- ),
491
- 'user' => array(
492
- 'label' => __( 'Users Log Entries', 'mycred' ),
493
- 'my_label' => __( 'Export History', 'mycred' ),
494
- 'class' => 'btn btn-primary button button-secondary'
495
- )
496
- );
497
-
498
- return apply_filters( 'mycred_log_exports', $defaults );
499
-
500
- }
501
- endif;
502
-
503
- /**
504
- * Get Export URL
505
- * Returns the URL for triggering an export (if allowed).
506
- * @since 1.7
507
- * @version 1.0
508
- */
509
- if ( ! function_exists( 'mycred_get_export_url' ) ) :
510
- function mycred_get_export_url( $set = 'all', $raw = false ) {
511
-
512
- $export_url = false;
513
- $is_admin = ( ( function_exists( 'is_admin' ) && is_admin() ) ? true : false );
514
-
515
- if ( ! $is_admin ) {
516
-
517
- global $wp;
518
- $current_url = add_query_arg( $wp->query_string, '', home_url( $wp->request . '/' ) );
519
-
520
- }
521
- else {
522
-
523
- $current_url = admin_url( 'admin.php' );
524
-
525
- }
526
-
527
- if ( is_user_logged_in() ) {
528
-
529
- $args = array();
530
-
531
- if ( $is_admin ) {
532
-
533
- if ( isset( $_GET['page'] ) )
534
- $args['page'] = $_GET['page'];
535
-
536
- $args['mycred-action'] = 'export';
537
- $args['_token'] = wp_create_nonce( 'mycred-export-request-admin' );
538
-
539
- }
540
- else {
541
-
542
- $args['mycred-action'] = 'export';
543
- $args['_token'] = wp_create_nonce( 'mycred-export-request' );
544
-
545
- }
546
-
547
- $args['set'] = sanitize_key( $set );
548
-
549
- if ( $raw )
550
- $args['raw'] = 'export-raw';
551
-
552
- $export_url = add_query_arg( $args, $current_url );
553
-
554
- }
555
-
556
- return apply_filters( 'mycred_get_export_url', $export_url, $set, $is_admin );
557
-
558
- }
559
- endif;
560
-
561
- /**
562
- * Is Valid Export URL
563
- * Checks if a valid export URL is present.
564
- * @since 1.7
565
- * @version 1.0
566
- */
567
- if ( ! function_exists( 'mycred_is_valid_export_url' ) ) :
568
- function mycred_is_valid_export_url( $admin = false ) {
569
-
570
- $valid = false;
571
- $token = 'mycred-export-request';
572
- if ( $admin )
573
- $token = 'mycred-export-request-admin';
574
-
575
- if ( is_user_logged_in() ) {
576
-
577
- if ( isset( $_REQUEST['mycred-action'] ) && isset( $_REQUEST['_token'] ) && substr( $_REQUEST['mycred-action'], 0, 6 ) === 'export' ) {
578
-
579
- if ( wp_verify_nonce( $_REQUEST['_token'], $token ) )
580
- $valid = true;
581
-
582
- }
583
-
584
- }
585
-
586
- return apply_filters( 'mycred_is_valid_export_url', $valid, $admin );
587
-
588
- }
589
- endif;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
includes/classes/class.query-leaderboard.php DELETED
@@ -1,799 +0,0 @@
1
- <?php
2
- if ( ! defined( 'myCRED_VERSION' ) ) exit;
3
-
4
- /**
5
- * Query Log
6
- * @see http://codex.mycred.me/classes/mycred_query_leaderboard/
7
- * @since 1.7.9.1
8
- * @version 1.0
9
- */
10
- if ( ! class_exists( 'myCRED_Query_Leaderboard' ) ) :
11
- class myCRED_Query_Leaderboard {
12
-
13
- public $id = '';
14
- public $now = 0;
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();
22
- public $order = '';
23
- public $limit = '';
24
-
25
- public $leaderboard = false;
26
-
27
- /**
28
- * Construct
29
- * Preps the class for getting a leaderboard based on the
30
- * given arguments. Validates these arguments.
31
- * @since 1.0
32
- * @version 1.0.1
33
- */
34
- public function __construct( $args = array() ) {
35
-
36
- if ( ! MYCRED_ENABLE_LOGGING ) return false;
37
-
38
- // Generate a unique ID that identifies the leaderboard we are trying to build
39
- $this->id = md5( implode( '|', $args ) );
40
-
41
- // Parse and validate the given args
42
- $this->parse_args( $args );
43
-
44
- $this->now = current_time( 'timestamp' );
45
- $this->core = mycred( $this->args['type'] );
46
- $this->user_id = get_current_user_id();
47
- $this->max_size = apply_filters( 'mycred_max_leaderboard_size', 250, $this );
48
-
49
- // What is the leaderboard based on
50
- $this->based_on = $this->args['based_on'];
51
- $this->order = $this->args['order'];
52
-
53
- // Setup limit
54
- if ( $this->args['number'] > 0 ) {
55
-
56
- $this->limit = 'LIMIT ' . $this->args['number'];
57
- if ( $this->args['offset'] != 0 )
58
- $this->limit = 'LIMIT ' . $this->args['offset'] . ', ' . $this->args['number'];
59
-
60
- }
61
-
62
- }
63
-
64
- /**
65
- * Parse Arguments
66
- * We have two jobs: Make sure we provide arguments we can understand and
67
- * that the arguments we provided are valid.
68
- * @since 1.0
69
- * @version 1.0
70
- */
71
- public function parse_args( $args = array() ) {
72
-
73
- /**
74
- * Populate Query Arguments
75
- * @uses mycred_query_leaderboard_args
76
- * @see http://codex.mycred.me/filters/mycred_query_leaderboard_args/
77
- */
78
- $defaults = array(
79
- 'based_on' => 'balance',
80
- 'number' => 25,
81
- 'offset' => 0,
82
- 'type' => MYCRED_DEFAULT_TYPE_KEY,
83
- 'timeframe' => '',
84
- 'order' => 'DESC',
85
- 'total' => 0,
86
- 'exclude_zero' => 1,
87
- 'forced' => 0
88
- );
89
- $args = apply_filters( 'mycred_query_leaderboard_args', shortcode_atts( $defaults, $args ), $args, $this );
90
-
91
- // Based on
92
- $based_on = sanitize_text_field( $args['based_on'] );
93
- if ( $based_on != 'balance' ) {
94
-
95
- $references = array();
96
- if ( ! empty( $args['based_on'] ) ) {
97
- foreach ( explode( ',', $based_on ) as $ref ) {
98
- $ref = sanitize_key( $ref );
99
- if ( strlen( $ref ) == 0 ) continue;
100
- $references[] = $ref;
101
- }
102
- $this->references = $references;
103
- }
104
-
105
- $based_on = 'references';
106
-
107
- }
108
-
109
- $args['based_on'] = $based_on;
110
-
111
- // Number or leaderboard size
112
- $number = (int) sanitize_key( $args['number'] );
113
- if ( $number < -1 )
114
- $number = -1;
115
-
116
- elseif ( ! is_numeric( $number ) )
117
- $number = 25;
118
-
119
- elseif ( $number > $this->max_size )
120
- $number = $this->max_size;
121
-
122
- $args['number'] = $number;
123
-
124
- // Option to offset
125
- $offset = (int) sanitize_key( $args['offset'] );
126
- if ( ! is_numeric( $offset ) )
127
- $offset = 0;
128
-
129
- $args['offset'] = $offset;
130
-
131
- // Point Type
132
- $point_type = sanitize_key( $args['type'] );
133
- if ( ! mycred_point_type_exists( $point_type ) )
134
- $point_type = MYCRED_DEFAULT_TYPE_KEY;
135
-
136
- $args['type'] = $point_type;
137
-
138
- // Timeframe
139
- $args['timeframe'] = sanitize_text_field( $args['timeframe'] );
140
-
141
- // Order
142
- $order = strtoupper( sanitize_text_field( $args['order'] ) );
143
- if ( ! in_array( $order, array( 'ASC', 'DESC' ) ) )
144
- $order = 'DESC';
145
-
146
- $args['order'] = $order;
147
-
148
- // Show total balance
149
- $args['total'] = (bool) $args['total'];
150
-
151
- // Exclude zero balances
152
- $args['exclude_zero'] = (bool) $args['exclude_zero'];
153
-
154
- // Force a new leaderboard instead of a cached one (if used)
155
- $args['forced'] = (bool) $args['forced'];
156
-
157
- $this->args = $args;
158
-
159
- }
160
-
161
- /**
162
- * Get Leaderboard Results
163
- * Returns the leaderboard data in an array form or false if the query results in no data.
164
- * @since 1.0
165
- * @version 1.0
166
- */
167
- public function get_leaderboard_results( $append_current_user = false ) {
168
-
169
- $results = $this->get_cache();
170
- if ( $results === false ) {
171
-
172
- global $wpdb;
173
-
174
- $results = $wpdb->get_results( $this->get_db_query(), 'ARRAY_A' );
175
- if ( empty( $results ) )
176
- $results = false;
177
-
178
- }
179
-
180
- if ( $results !== false )
181
- $this->cache_result( $results );
182
-
183
- $this->leaderboard = $results;
184
-
185
- if ( $append_current_user )
186
- $this->append_current_user();
187
-
188
- $results = $this->leaderboard;
189
- $this->leaderboard = apply_filters( 'mycred_get_leaderboard_results', $results, $append_current_user, $this );
190
-
191
- }
192
-
193
- /**
194
- * Append Current User
195
- * Appends the current logged in user to the end of the leaderboard if the user is not in the results.
196
- * This is done separatelly since we can not cache a leaderboard for each user that might view the board.
197
- * @since 1.0
198
- * @version 1.0
199
- */
200
- public function append_current_user( $return = false ) {
201
-
202
- if ( ! is_user_logged_in() || $this->leaderboard === false || $this->core->exclude_user( $this->user_id ) ) return;
203
-
204
- // First we need to check if the user is already in the leaderboard
205
- if ( $this->user_in_leaderboard() ) return;
206
-
207
- // User is not in the leaderboard so we need to append him/her to the end of the leaderboard array.
208
- $new_row = array( 'ID' => $this->user_id );
209
- $new_row['position'] = $this->get_users_current_position();
210
- $new_row['cred'] = $this->get_users_current_value();
211
-
212
- if ( $return )
213
- return $new_row;
214
-
215
- $this->leaderboard[] = $new_row;
216
-
217
- }
218
-
219
- /**
220
- * User In Leaderboard
221
- * Checks if a given user or the current user is in the leaderboard.
222
- * @since 1.0
223
- * @version 1.0
224
- */
225
- public function user_in_leaderboard( $user_id = NULL ) {
226
-
227
- $in_leaderboard = false;
228
- if ( $this->leaderboard !== false && ! empty( $this->leaderboard ) ) {
229
-
230
- if ( $user_id === NULL || absint( $user_id ) === 0 )
231
- $user_id = $this->user_id;
232
-
233
- $user_id = absint( $user_id );
234
-
235
- foreach ( $this->leaderboard as $position => $user ) {
236
- if ( absint( $user['ID'] ) === $user_id ) {
237
- $in_leaderboard = true;
238
- break;
239
- }
240
- }
241
-
242
- }
243
-
244
- return apply_filters( 'mycred_user_in_leaderboard', $in_leaderboard, $user_id, $this );
245
-
246
- }
247
-
248
- /**
249
- * Get Database Query
250
- * Returns the SQL query required for generating a leaderboard.
251
- * @since 1.0
252
- * @version 1.0
253
- */
254
- public function get_db_query() {
255
-
256
- if ( $this->based_on == 'balance' )
257
- $query = $this->get_balance_db_query();
258
- else
259
- $query = $this->get_reference_db_query();
260
-
261
- return $query;
262
-
263
- }
264
-
265
- /**
266
- * Get Balance Database Query
267
- * Returns the SQL query required for generating a leaderboard that is based on balances.
268
- * @since 1.0
269
- * @version 1.0
270
- */
271
- public function get_balance_db_query() {
272
-
273
- global $wpdb, $mycred_log_table;
274
-
275
- $query = '';
276
- $time_filter = $this->get_timefilter();
277
- $exclude_filter = $this->get_excludefilter();
278
- $multisite_check = $this->get_multisitefilter();
279
-
280
- // Total balance
281
- if ( $this->args['total'] ) {
282
-
283
- $query = $wpdb->prepare( "
284
- SELECT l.user_id AS ID, SUM( l.creds ) AS cred
285
- FROM {$mycred_log_table} l
286
- {$multisite_check}
287
- WHERE l.ctype = %s AND ( ( l.creds > 0 ) OR ( l.creds < 0 AND l.ref = 'manual' ) )
288
- {$time_filter}
289
- {$exclude_filter}
290
- GROUP BY l.user_id
291
- ORDER BY SUM( l.creds ) {$this->order}, l.user_id ASC
292
- {$this->limit};", $this->args['type'] );
293
-
294
- }
295
-
296
- // Current Balance
297
- else {
298
-
299
- $query = $wpdb->prepare( "
300
- SELECT DISTINCT u.ID, l.meta_value AS cred
301
- FROM {$wpdb->users} u
302
- INNER JOIN {$wpdb->usermeta} l ON ( u.ID = l.user_id )
303
- {$multisite_check}
304
- WHERE l.meta_key = %s
305
- {$exclude_filter}
306
- ORDER BY l.meta_value+0 {$this->order}, l.user_id ASC
307
- {$this->limit};", mycred_get_meta_key( $this->args['type'] ) );
308
-
309
- }
310
-
311
- return apply_filters( 'mycred_get_balance_leaderboard_sql', $query, $this );
312
-
313
- }
314
-
315
- /**
316
- * Get Balance Database Query
317
- * Returns the SQL query required for generating a leaderboard that is based on references.
318
- * @since 1.0
319
- * @version 1.0
320
- */
321
- public function get_reference_db_query() {
322
-
323
- global $wpdb, $mycred_log_table;
324
-
325
- $time_filter = $this->get_timefilter();
326
- $multisite_check = $this->get_multisitefilter();
327
-
328
- $reference = 'l.ref = %s';
329
- if ( count( $this->references ) > 1 )
330
- $reference = 'l.ref IN ( %s' . str_repeat( ', %s', ( count( $this->references ) - 1 ) ) . ' )';
331
-
332
- if ( mycred_centralize_log() )
333
- $query = $wpdb->prepare( "SELECT DISTINCT l.user_id AS ID, SUM( l.creds ) AS cred FROM {$mycred_log_table} l WHERE {$reference} {$time_filter} GROUP BY l.user_id ORDER BY SUM( l.creds ) {$this->order} {$this->limit};", $this->references );
334
-
335
- // Multisite support
336
- else {
337
-
338
- $blog_id = absint( $GLOBALS['blog_id'] );
339
- $query = $wpdb->prepare( "
340
- SELECT DISTINCT l.user_id AS ID, SUM( l.creds ) AS cred
341
- FROM {$mycred_log_table} l
342
- {$multisite_check}
343
- WHERE {$reference}
344
- {$time_filter}
345
- GROUP BY l.user_id
346
- ORDER BY SUM( l.creds ) {$this->order}, l.user_id ASC
347
- {$this->limit};", $this->references );
348
-
349
- }
350
-
351
- return apply_filters( 'mycred_get_reference_leaderboard_sql', $query, $this );
352
-
353
- }
354
-
355
- /**
356
- * Get Users Leaderboard Position
357
- * @since 1.0
358
- * @version 1.0
359
- */
360
- public function get_users_current_position( $user_id = NULL, $no_position = '' ) {
361
-
362
- $position = false;
363
- // Better safe than sorry
364
- if ( $user_id === NULL && ! is_user_logged_in() ) return $position;
365
-
366
- if ( $user_id === NULL || absint( $user_id ) === 0 )
367
- $user_id = $this->user_id;
368
-
369
- global $wpdb, $mycred_log_table;
370
-
371
- $time_filter = $this->get_timefilter();
372
- $exclude_filter = $this->get_excludefilter();
373
- $multisite_check = $this->get_multisitefilter();
374
-
375
- if ( $this->based_on == 'balance' ) {
376
-
377
- // Current Balance
378
- if ( $this->args['total'] ) {
379
-
380
- $position = $wpdb->get_var( $wpdb->prepare( "
381
- SELECT rank FROM (
382
- SELECT s.*, @rank := @rank + 1 rank FROM (
383
- SELECT l.user_id, sum( l.creds ) TotalPoints FROM {$mycred_log_table} l
384
- {$multisite_check}
385
- WHERE l.ctype = %s AND ( ( l.creds > 0 ) OR ( l.creds < 0 AND l.ref = 'manual' ) )
386
- {$time_filter}
387
- {$exclude_filter}
388
- GROUP BY l.user_id
389
- ) s, (SELECT @rank := 0) init
390
- ORDER BY TotalPoints DESC, s.user_id ASC
391
- ) r
392
- WHERE user_id = %d", $this->args['type'], $user_id ) );
393
-
394
- }
395
-
396
- else {
397
-
398
- $position = $wpdb->get_var( $wpdb->prepare( "
399
- SELECT rank FROM (
400
- SELECT s.*, @rank := @rank + 1 rank FROM (
401
- SELECT l.user_id, l.meta_value AS Balance FROM {$wpdb->usermeta} l
402
- {$multisite_check}
403
- WHERE l.meta_key = %s
404
- {$exclude_filter}
405
- ) s, (SELECT @rank := 0) init
406
- ORDER BY Balance+0 DESC, s.user_id ASC
407
- ) r
408
- WHERE user_id = %d", mycred_get_meta_key( $this->args['type'] ), $user_id ) );
409
-
410
- }
411
-
412
- }
413
-
414
- else {
415
-
416
- $reference = 'l.ref = %s';
417
- if ( count( $this->references ) > 1 )
418
- $reference = 'l.ref IN ( %s' . str_repeat( ', %s', ( count( $this->references ) - 1 ) ) . ' )';
419
-
420
- $position = $wpdb->get_var( $wpdb->prepare( "
421
- SELECT rank FROM (
422
- SELECT s.*, @rank := @rank + 1 rank FROM (
423
- SELECT l.user_id, sum( l.creds ) TotalPoints FROM {$mycred_log_table} l
424
- {$multisite_check}
425
- WHERE l.ctype = %s AND ( ( l.creds > 0 ) OR ( l.creds < 0 AND l.ref = 'manual' ) )
426
- {$reference}
427
- {$time_filter}
428
- {$exclude_filter}
429
- GROUP BY l.user_id
430
- ) s, (SELECT @rank := 0) init
431
- ORDER BY TotalPoints DESC, s.user_id ASC
432
- ) r
433
- WHERE user_id = %d", $this->args['type'], $user_id ) );
434
-
435
- }
436
-
437
- if ( $position === NULL )
438
- $position = $no_position;
439
-
440
- return apply_filters( 'mycred_get_leaderboard_position', $position, $user_id, $no_position, $this );
441
-
442
- }
443
-
444
- /**
445
- * Get Users Leaderboard Value
446
- * @since 1.0
447
- * @version 1.0
448
- */
449
- public function get_users_current_value( $user_id = NULL ) {
450
-
451
- if ( $user_id === NULL || absint( $user_id ) === 0 )
452
- $user_id = $this->user_id;
453
-
454
- global $wpdb, $mycred_log_table;
455
-
456
- $time_filter = $this->get_timefilter();
457
- $multisite_check = $this->get_multisitefilter();
458
-
459
- if ( $this->based_on == 'balance' ) {
460
-
461
- $value = $this->core->get_users_balance( $user_id );
462
- if ( $this->args['total'] ) {
463
-
464
- if ( $this->args['timeframe'] == '' )
465
- $value = mycred_query_users_total( $user_id, $this->args['type'] );
466
-
467
- else {
468
-
469
- $value = $wpdb->get_var( $wpdb->prepare( "
470
- SELECT SUM( l.creds )
471
- FROM {$mycred_log_table} l
472
- {$multisite_check}
473
- WHERE l.ctype = %s AND ( ( l.creds > 0 ) OR ( l.creds < 0 AND l.ref = 'manual' ) )
474
- AND user_id = %d
475
- {$time_filter};", $this->args['type'], $user_id ) );
476
-
477
- if ( $value === NULL ) $value = 0;
478
-
479
- }
480
-
481
- }
482
-
483
- }
484
-
485
- else {
486
-
487
- $reference = 'l.ref = %s';
488
- if ( count( $this->references ) > 1 )
489
- $reference = 'l.ref IN ( %s' . str_repeat( ', %s', ( count( $this->references ) - 1 ) ) . ' )';
490
-
491
- if ( mycred_centralize_log() )
492
- $query = $wpdb->prepare( "SELECT SUM( l.creds ) FROM {$mycred_log_table} l WHERE {$reference} AND user_id = %d {$time_filter};", $this->references, $user_id );
493
-
494
- // Multisite support
495
- else {
496
-
497
- $blog_id = absint( $GLOBALS['blog_id'] );
498
- $query = $wpdb->prepare( "
499
- SELECT SUM( l.creds )
500
- FROM {$mycred_log_table} l
501
- {$multisite_check}
502
- WHERE {$reference}
503
- AND user_id = %d
504
- {$time_filter};", $this->references, $user_id );
505
-
506
- }
507
-
508
- $value = $wpdb->get_var( $query );
509
- if ( $value === NULL ) $value = 0;
510
-
511
- }
512
-
513
- return apply_filters( 'mycred_get_users_leaderboard_value', $value, $user_id, $this );
514
-
515
- }
516
-
517
- /**
518
- * Get Time Filter
519
- * Generates the required SQL query for filtering results based on time.
520
- * Can only be used when the leaderboard is based either on total balance or based on references.
521
- * @since 1.0
522
- * @version 1.0
523
- */
524
- public function get_timefilter() {
525
-
526
- $query = '';
527
- if ( $this->args['timeframe'] === NULL || strlen( $this->args['timeframe'] ) == 0 ) return $query;
528
-
529
- global $wpdb;
530
-
531
- // Start of the week based of our settings
532
- $week_starts = get_option( 'start_of_week' );
533
- if ( $week_starts == 0 )
534
- $week_starts = 'sunday';
535
- else
536
- $week_starts = 'monday';
537
-
538
- // Filter: Daily
539
- if ( $this->args['timeframe'] == 'today' )
540
- $query = $wpdb->prepare( "AND l.time BETWEEN %d AND %d", strtotime( 'today midnight', $this->now ), $this->now );
541
-
542
- // Filter: Weekly
543
- elseif ( $this->args['timeframe'] == 'this-week' )
544
- $query = $wpdb->prepare( "AND l.time BETWEEN %d AND %d", strtotime( $week_starts . ' this week', $this->now ), $this->now );
545
-
546
- // Filter: Monthly
547
- elseif ( $this->args['timeframe'] == 'this-month' )
548
- $query = $wpdb->prepare( "AND l.time BETWEEN %d AND %d", strtotime( date( 'Y-m-01', $this->now ) ), $this->now );
549
-
550
- else {
551
-
552
- $start_from = strtotime( $this->args['timeframe'], $this->now );
553
- if ( $start_from !== false && $start_from > 0 )
554
- $query = $wpdb->prepare( "AND l.time BETWEEN %d AND %d", $start_from, $this->now );
555
-
556
- }
557
-
558
- return apply_filters( 'mycred_leaderboard_time_filter', $query, $this );
559
-
560
- }
561
-
562
- /**
563
- * Get Exclude Filter
564
- * Generates the required SQL query for filtering results based on if zero balances should
565
- * be part of the leaderboard or not. By default, myCRED will not give a user a balance until they
566
- * gain or lose points. A user that has no balance and is not excluded, is considered to have zero balance.
567
- * @since 1.0
568
- * @version 1.0
569
- */
570
- public function get_excludefilter() {
571
-
572
- global $wpdb;
573
-
574
- // Option to exclude zero balances
575
- $query = '';
576
- if ( $this->args['exclude_zero'] ) {
577
-
578
- $balance_format = '%d';
579
- if ( isset( $this->core->format['decimals'] ) && $this->core->format['decimals'] > 0 ) {
580
- $length = absint( 65 - $this->core->format['decimals'] );
581
- $balance_format = 'CAST( %f AS DECIMAL( ' . $length . ', ' . $this->core->format['decimals'] . ' ) )';
582
- }
583
-
584
- if ( ! $this->args['total'] )
585
- $query = $wpdb->prepare( "AND l.meta_value != {$balance_format}", $this->core->zero() );
586
-
587
- }
588
-
589
- return apply_filters( 'mycred_leaderboard_exclude_filter', $query, $this );
590
-
591
- }
592
-
593
- /**
594
- * Get Multisite Filter
595
- * Generates the required SQL query for filtering results based on our multisite setup.
596
- * Will return an empty string if we are not using multisites or if we have centralized the log.
597
- * @since 1.0
598
- * @version 1.0
599
- */
600
- public function get_multisitefilter() {
601
-
602
- global $wpdb;
603
-
604
- $multisite_check = "";
605
- if ( ! mycred_centralize_log() ) {
606
-
607
- $blog_id = absint( $GLOBALS['blog_id'] );
608
- $multisite_check = "LEFT JOIN {$wpdb->usermeta} cap ON ( l.user_id = cap.user_id AND cap.meta_key = 'cap.wp_{$blog_id}_capabilities' )";
609
-
610
- }
611
-
612
- return apply_filters( 'mycred_leaderboard_musite_filter', $multisite_check, $this );
613
-
614
- }
615
-
616
- /**
617
- * Get Cache Key
618
- * @since 1.0
619
- * @version 1.0
620
- */
621
- public function get_cache_key() {
622
-
623
- return 'mycred-leaderboard-' . md5( implode( '|', $this->args ) );
624
-
625
- }
626
-
627
- /**
628
- * Get Cached Leaderboard
629
- * @since 1.0
630
- * @version 1.0
631
- */
632
- public function get_cache() {
633
-
634
- if ( $this->args['forced'] == 1 || MYCRED_DISABLE_LEADERBOARD_CACHE ) return false;
635
-
636
- $cached_results = get_option( $this->get_cache_key(), false );
637
- if ( $cached_results !== false )
638
- $cached_results = maybe_unserialize( $cached_results );
639
-
640
- return $cached_results;
641
-
642
- }
643
-
644
- /**
645
- * Cache Results
646
- * @since 1.0
647
- * @version 1.0
648
- */
649
- public function cache_result( $data = array() ) {
650
-
651
- if ( MYCRED_DISABLE_LEADERBOARD_CACHE ) return;
652
-
653
- if ( $this->to_big_to_cache() ) return;
654
-
655
- update_option( $this->get_cache_key(), $data );
656
-
657
- }
658
-
659
- /**
660
- * Check if the cache is too big for storage in the db.
661
- * @since 1.0
662
- * @version 1.0
663
- */
664
- public function to_big_to_cache() {
665
-
666
- $big = false;
667
- if ( $this->leaderboard !== false ) {
668
-
669
-
670
-
671
- }
672
-
673
- return $big;
674
-
675
- }
676
-
677
- /**
678
- * Is Leaderboard
679
- * @since 1.0
680
- * @version 1.0
681
- */
682
- public function is_leaderboard( $args = array() ) {
683
-
684
- return ( $this->id == md5( implode( '|', $args ) ) );
685
-
686
- }
687
-
688
- /**
689
- * Render Leaderboard
690
- * @since 1.0
691
- * @version 1.0
692
- */
693
- public function render( $args = array(), $content = '' ) {
694
-
695
- extract( shortcode_atts( array(
696
- 'wrap' => 'li',
697
- 'template' => '#%position% %user_profile_link% %cred_f%',
698
- 'nothing' => 'Leaderboard is empty',
699
- ), $args ) );
700
-
701
- $output = '';
702
-
703
- // Leaderboard is empty
704
- if ( $this->leaderboard === false || empty( $this->leaderboard ) ) {
705
-
706
- $output .= '<p class="mycred-leaderboard-none">' . $nothing . '</p>';
707
-
708
- }
709
-
710
- // Got results to show
711
- else {
712
-
713
- // Wrapper
714
- if ( $wrap == 'li' )
715
- $output .= '<ol class="myCRED-leaderboard list-unstyled">';
716
-
717
- // Loop
718
- foreach ( $this->leaderboard as $position => $user ) {
719
-
720
- // Prep
721
- $class = array();
722
- $row = $position;
723
-
724
- if ( array_key_exists( 'position', $user ) )
725
- $position = $user['position'];
726
-
727
- else {
728
-
729
- if ( $this->args['offset'] != '' && $this->args['offset'] > 0 )
730
- $position = $position + $this->args['offset'];
731
-
732
- $position++;
733
-
734
- }
735
-
736
- // Classes
737
- $class[] = 'item-' . $row;
738
- if ( $position == 0 )
739
- $class[] = 'first-item';
740
-
741
- if ( $this->user_id > 0 && $user['ID'] == $this->user_id )
742
- $class[] = 'current-user';
743
-
744
- if ( $position % 2 != 0 )
745
- $class[] = 'alt';
746
-
747
- $row_template = $template;
748
- if ( ! empty( $content ) )
749
- $row_template = $content;
750
-
751
- // Template Tags
752
- $layout = str_replace( array( '%ranking%', '%position%' ), $position, $row_template );
753
-
754
- $layout = $this->core->template_tags_amount( $layout, $user['cred'] );
755
- $layout = $this->core->template_tags_user( $layout, $user['ID'] );
756
-
757
- // Wrapper
758
- if ( ! empty( $wrap ) )
759
- $layout = '<' . $wrap . ' class="%classes%">' . $layout . '</' . $wrap . '>';
760
-
761
- $layout = str_replace( '%classes%', apply_filters( 'mycred_ranking_classes', implode( ' ', $class ), $this ), $layout );
762
- $layout = apply_filters( 'mycred_ranking_row', $layout, $template, $user, $position, $this );
763
-
764
- $output .= $layout . "\n";
765
-
766
- }
767
-
768
- if ( $wrap == 'li' )
769
- $output .= '</ol>';
770
-
771
- }
772
-
773
- return apply_filters( 'mycred_leaderboard', $output, $args, $this );
774
-
775
- }
776
-
777
- }
778
- endif;
779
-
780
- /**
781
- * Get Leaderboard
782
- * @since 1.7.9.1
783
- * @version 1.0
784
- */
785
- if ( ! function_exists( 'mycred_get_leaderboard' ) ) :
786
- function mycred_get_leaderboard( $args = array() ) {
787
-
788
- global $mycred_leaderboard;
789
-
790
- // No need to do extra work if we already have the correct global
791
- if ( is_object( $mycred_leaderboard ) && $mycred_leaderboard->is_leaderboard( $args ) )
792
- return $mycred_leaderboard;
793
-
794
- $mycred_leaderboard = new myCRED_Query_Leaderboard( $args );
795
-
796
- return $mycred_leaderboard;
797
-
798
- }
799
- endif;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
includes/classes/class.query-log.php DELETED
@@ -1,2696 +0,0 @@
1
- <?php
2
- if ( ! defined( 'myCRED_VERSION' ) ) exit;
3
-
4
- /**
5
- * Query Log
6
- * @see http://codex.mycred.me/classes/mycred_query_log/
7
- * @since 0.1
8
- * @version 1.7
9
- */
10
- if ( ! class_exists( 'myCRED_Query_Log' ) ) :
11
- class myCRED_Query_Log {
12
-
13
- public $now = 0;
14
- public $render_mode = true;
15
- public $args = array();
16
- public $request = '';
17
- public $num_rows = 0;
18
- public $max_num_pages = 1;
19
- public $total_rows = 0;
20
-
21
- public $results = array();
22
-
23
- public $headers = array();
24
- public $hidden_headers = array();
25
- public $core;
26
- public $is_admin = false;
27
- public $references = array();
28
- public $types = array();
29
- public $refs = array();
30
-
31
- /**
32
- * Construct
33
- */
34
- public function __construct( $args = array(), $array = false ) {
35
-
36
- if ( ! MYCRED_ENABLE_LOGGING ) return false;
37
-
38
- global $wpdb;
39
-
40
- $select = $where = $sortby = $limits = '';
41
- $wheres = array();
42
- $this->now = current_time( 'timestamp' );
43
- $this->references = mycred_get_all_references();
44
-
45
- /**
46
- * Populate Query Arguments
47
- * @uses mycred_query_log_args
48
- * @see http://codex.mycred.me/filters/mycred_query_log_args/
49
- */
50
- $defaults = array(
51
- 'entry_id' => NULL,
52
- 'user_id' => NULL,
53
- 'ctype' => MYCRED_DEFAULT_TYPE_KEY,
54
- 'time' => NULL,
55
- 'ref' => NULL,
56
- 'ref_id' => NULL,
57
- 'amount' => NULL,
58
- 's' => NULL,
59
- 'data' => NULL,
60
- 'number' => 25,
61
- 'offset' => '',
62
- 'orderby' => 'time',
63
- 'order' => 'DESC',
64
- 'ids' => false, // depreciated as of 1.7.5
65
- 'fields' => 'all', // in favor for fields
66
- 'paged' => '',
67
- 'page_arg' => 'page'
68
- );
69
- $this->args = apply_filters( 'mycred_query_log_args', wp_parse_args( $args, $defaults ), $defaults );
70
-
71
- // Need to be sure the page_arg argument is set.
72
- if ( ! array_key_exists( 'page_arg', $this->args ) ) $this->args['page_arg'] = 'page';
73
-
74
- if ( $this->args['paged'] == '' )
75
- $this->args['paged'] = $this->get_pagenum();
76
-
77
- /**
78
- * Setup Point Format
79
- * Make sure the core property is loaded for the correct point type as this will
80
- * determen how we format point related values. When we have a query for multiple point types,
81
- * the default type dictates formating. If the default type does not use decimals, neither does any other type.
82
- */
83
- $this->core = mycred();
84
- $this->types[ MYCRED_DEFAULT_TYPE_KEY ] = $this->core;
85
- $format = '%d';
86
- if ( isset( $this->core->format['decimals'] ) && $this->core->format['decimals'] > 0 ) {
87
- $length = 65 - $this->core->format['decimals'];
88
- $format = 'CAST( %f AS DECIMAL( ' . $length . ', ' . $this->core->format['decimals'] . ' ) )';
89
- }
90
-
91
- if ( $this->args['ctype'] !== NULL && ! empty( $this->args['ctype'] ) ) {
92
-
93
- // Convert string queries to array queries
94
- if ( ! is_array( $this->args['ctype'] ) ) {
95
-
96
- $point_types = ( ( count( explode( ',', $this->args['ctype'] ) ) > 0 ) ? explode( ',', $this->args['ctype'] ) : array( $this->args['ctype'] ) );
97
-
98
- // Single point type query
99
- if ( count( $point_types ) == 1 )
100
- $this->args['ctype'] = array( 'ids' => $point_types[0], 'compare' => '=' );
101
-
102
- // Multiple point types query
103
- elseif ( count( $point_types ) > 1 ) {
104
-
105
- $this->args['ctype'] = array( 'ids' => $point_types, 'compare' => 'IN' );
106
-
107
- }
108
-
109
- }
110
-
111
- // Check if this is a single point type query
112
- // We need to do this to see if the query is for a point type that is not the default one
113
- // This is to format values correctly based on the point types setup
114
- if ( ( is_array( $this->args['ctype']['ids'] ) && count( $this->args['ctype']['ids'] ) == 1 ) || ! is_array( $this->args['ctype']['ids'] ) ) {
115
-
116
- if ( ! is_array( $this->args['ctype']['ids'] ) )
117
- $requested_point_type = $this->args['ctype']['ids'];
118
- else
119
- $requested_point_type = $this->args['ctype']['ids'][0];
120
-
121
- // If this is a query for a custom point type, change the balance format now
122
- if ( $requested_point_type != $this->core->cred_id ) {
123
- $this->core = mycred( $requested_point_type );
124
- if ( isset( $this->core->format['decimals'] ) && $this->core->format['decimals'] > 0 ) {
125
- $length = 65 - $this->core->format['decimals'];
126
- $format = 'CAST( %f AS DECIMAL( ' . $length . ', ' . $this->core->format['decimals'] . ' ) )';
127
- }
128
- }
129
-
130
- if ( ! array_key_exists( $requested_point_type, $this->types ) )
131
- $this->types[ $requested_point_type ] = $this->core;
132
-
133
- }
134
-
135
- // Indicate that this query uses multiple point types.
136
- // Mainly used to load the correct label for the point amount column in the table
137
- elseif ( is_array( $this->args['ctype']['ids'] ) && count( $this->args['ctype']['ids'] ) > 1 ) {
138
-
139
- // Populate the types property with each point type object
140
- // This is used so the correct point type format is shown in the table for each row
141
- foreach ( $this->args['ctype']['ids'] as $point_type_key ) {
142
- if ( ! array_key_exists( $point_type_key, $this->types ) )
143
- $this->types[ $point_type_key ] = mycred( $point_type_key );
144
- }
145
-
146
- }
147
-
148
- }
149
-
150
- /**
151
- * Entry ID Query
152
- *
153
-
154
- // Singular check
155
- entry_id=1
156
- 'entry_id' => array(
157
- 'ids' => 1,
158
- 'compare' => '='
159
- )
160
- 'entry_id' => array(
161
- 'ids' => 1,
162
- 'compare' => '!='
163
- )
164
-
165
- // Multiple checks
166
- entry_id=1,2,3
167
- 'entry_id' => array(
168
- 'ids' => array( 1, 2, 3 )
169
- 'compare' => 'IN'
170
- )
171
-
172
- */
173
- if ( $this->args['entry_id'] !== NULL && ! empty( $this->args['entry_id'] ) ) {
174
-
175
- // Convert string queries to array queries
176
- if ( ! is_array( $this->args['entry_id'] ) ) {
177
-
178
- $entry_ids = ( ( count( explode( ',', $this->args['entry_id'] ) ) > 0 ) ? explode( ',', $this->args['entry_id'] ) : array( $this->args['entry_id'] ) );
179
-
180
- // Single user query
181
- if ( count( $entry_ids ) == 1 )
182
- $this->args['entry_id'] = array( 'ids' => $entry_ids[0], 'compare' => '=' );
183
-
184
- // Multiple user query
185
- elseif ( count( $entry_ids ) > 1 )
186
- $this->args['entry_id'] = array( 'ids' => $entry_ids, 'compare' => 'IN' );
187
-
188
- }
189
-
190
- // Make sure query is properly formatted
191
- if ( array_key_exists( 'ids', $this->args['entry_id'] ) && array_key_exists( 'compare', $this->args['entry_id'] ) ) {
192
-
193
- // IN or NOT IN comparisons
194
- if ( in_array( $this->args['entry_id']['compare'], array( 'IN', 'NOT IN' ) ) && is_array( $this->args['entry_id']['ids'] ) )
195
- $wheres[] = $wpdb->prepare( "id IN ( %d" . str_repeat( ", %d", ( count( $this->args['entry_id']['ids'] ) - 1 ) ) . " )", $this->args['entry_id']['ids'] );
196
-
197
- // All other supported comparisons
198
- elseif ( in_array( $this->args['entry_id']['compare'], array( '=', '!=' ) ) && ! is_array( $this->args['entry_id']['ids'] ) ) {
199
-
200
- $compare = esc_sql( $this->args['entry_id']['compare'] );
201
- $wheres[] = $wpdb->prepare( "id {$compare} %d", absint( $this->args['entry_id']['ids'] ) );
202
-
203
- }
204
-
205
- }
206
-
207
- }
208
-
209
- /**
210
- * Point Type Query
211
- *
212
-
213
- // Singular check
214
- ctype=mycred_default
215
- 'ctype' => array(
216
- 'ids' => 'mycred_default',
217
- 'compare' => '='
218
- )
219
- 'ctype' => array(
220
- 'ids' => 'mycred_default',
221
- 'compare' => '!='
222
- )
223
-
224
- // Multiple checks
225
- ctype=mycred_default,custom_point_type
226
- 'ctype' => array(
227
- 'ids' => array( 'mycred_default', 'custom_point_type' )
228
- 'compare' => 'IN'
229
- )
230
-
231
- */
232
- if ( $this->args['ctype'] !== NULL && ! empty( $this->args['ctype'] ) ) {
233
-
234
- // Make sure query is properly formatted
235
- if ( array_key_exists( 'ids', $this->args['ctype'] ) && array_key_exists( 'compare', $this->args['ctype'] ) ) {
236
-
237
- // IN or NOT IN comparisons
238
- if ( in_array( $this->args['ctype']['compare'], array( 'IN', 'NOT IN' ) ) && is_array( $this->args['ctype']['ids'] ) )
239
- $wheres[] = $wpdb->prepare( "ctype IN ( %s" . str_repeat( ", %s", ( count( $this->args['ctype']['ids'] ) - 1 ) ) . " )", $this->args['ctype']['ids'] );
240
-
241
- // All other supported comparisons
242
- elseif ( in_array( $this->args['ctype']['compare'], array( '=', '!=' ) ) && ! is_array( $this->args['ctype']['ids'] ) ) {
243
-
244
- $compare = esc_sql( $this->args['ctype']['compare'] );
245
- $wheres[] = $wpdb->prepare( "ctype {$compare} %s", sanitize_key( $this->args['ctype']['ids'] ) );
246
-
247
- }
248
-
249
- }
250
-
251
- }
252
-
253
- /**
254
- * User ID Query
255
- *
256
-
257
- // Singular check
258
- user_id=1
259
- 'user_id' => array(
260
- 'ids' => 1,
261
- 'compare' => '='
262
- )
263
- 'user_id' => array(
264
- 'ids' => 1,
265
- 'compare' => '!='
266
- )
267
-
268
- // Multiple checks
269
- user_id=1,2,3
270
- 'user_id' => array(
271
- 'ids' => array( 1, 2, 3 )
272
- 'compare' => 'IN'
273
- )
274
-
275
- */
276
- if ( $this->args['user_id'] !== NULL && ! empty( $this->args['user_id'] ) ) {
277
-
278
- // Convert string queries to array queries
279
- if ( ! is_array( $this->args['user_id'] ) ) {
280
-
281
- $user_ids = ( ( count( explode( ',', $this->args['user_id'] ) ) > 0 ) ? explode( ',', $this->args['user_id'] ) : array( $this->args['user_id'] ) );
282
-
283
- // Single user query
284
- if ( count( $user_ids ) == 1 )
285
- $this->args['user_id'] = array( 'ids' => $user_ids[0], 'compare' => '=' );
286
-
287
- // Multiple user query
288
- elseif ( count( $user_ids ) > 1 )
289
- $this->args['user_id'] = array( 'ids' => $user_ids, 'compare' => 'IN' );
290
-
291
- }
292
-
293
- // Make sure query is properly formatted
294
- if ( array_key_exists( 'ids', $this->args['user_id'] ) && array_key_exists( 'compare', $this->args['user_id'] ) ) {
295
-
296
- // IN or NOT IN comparisons
297
- if ( in_array( $this->args['user_id']['compare'], array( 'IN', 'NOT IN' ) ) && is_array( $this->args['user_id']['ids'] ) )
298
- $wheres[] = $wpdb->prepare( "user_id IN ( %d" . str_repeat( ", %d", ( count( $this->args['user_id']['ids'] ) - 1 ) ) . " )", $this->args['user_id']['ids'] );
299
-
300
- // All other supported comparisons
301
- elseif ( in_array( $this->args['user_id']['compare'], array( '=', '!=' ) ) && ! is_array( $this->args['user_id']['ids'] ) ) {
302
-
303
- $compare = esc_sql( $this->args['user_id']['compare'] );
304
- $wheres[] = $wpdb->prepare( "user_id {$compare} %d", absint( $this->args['user_id']['ids'] ) );
305
-
306
- }
307
-
308
- }
309
-
310
- }
311
-
312
- /**
313
- * Reference Query
314
- *
315
-
316
- // Singular check
317
- ref=approved_comment
318
- 'ref' => array(
319
- 'ids' => 'approved_comment',
320
- 'compare' => '='
321
- )
322
- 'ref' => array(
323
- 'ids' => 'approved_comment',
324
- 'compare' => '!='
325
- )
326
-
327
- // Multiple checks
328
- ref=approved_comment,published_content
329
- 'ref' => array(
330
- 'ids' => array( 'approved_comment', 'published_content' )
331
- 'compare' => 'IN'
332
- )
333
-
334
- */
335
- if ( $this->args['ref'] !== NULL && ! empty( $this->args['ref'] ) ) {
336
-
337
- // Convert string queries to array queries
338
- if ( ! is_array( $this->args['ref'] ) ) {
339
-
340
- $references = ( ( count( explode( ',', $this->args['ref'] ) ) > 0 ) ? explode( ',', $this->args['ref'] ) : array( $this->args['ref'] ) );
341
-
342
- // Single reference query
343
- if ( count( $references ) == 1 )
344
- $this->args['ref'] = array( 'ids' => $references[0], 'compare' => '=' );
345
-
346
- // Multiple reference query
347
- elseif ( count( $references ) > 1 )
348
- $this->args['ref'] = array( 'ids' => $references, 'compare' => 'IN' );
349
-
350
- }
351
-
352
- // Make sure query is properly formatted
353
- if ( array_key_exists( 'ids', $this->args['ref'] ) && array_key_exists( 'compare', $this->args['ref'] ) ) {
354
-
355
- // IN or NOT IN comparisons
356
- if ( in_array( $this->args['ref']['compare'], array( 'IN', 'NOT IN' ) ) && is_array( $this->args['ref']['ids'] ) )
357
- $wheres[] = $wpdb->prepare( "ref IN ( %s" . str_repeat( ", %s", ( count( $this->args['ref']['ids'] ) - 1 ) ) . " )", $this->args['ref']['ids'] );
358
-
359
- // All other supported comparisons
360
- elseif ( in_array( $this->args['ref']['compare'], array( '=', '!=' ) ) && ! is_array( $this->args['ref']['ids'] ) ) {
361
-
362
- $compare = esc_sql( $this->args['ref']['compare'] );
363
- $wheres[] = $wpdb->prepare( "ref {$compare} %s", sanitize_key( $this->args['ref']['ids'] ) );
364
-
365
- }
366
-
367
- }
368
-
369
- }
370
-
371
- /**
372
- * Reference ID Query
373
- *
374
-
375
- // Singular check
376
- ref_id=1
377
- 'ref_id' => array(
378
- 'ids' => 1,
379
- 'compare' => '='
380
- )
381
- 'ref_id' => array(
382
- 'ids' => 1,
383
- 'compare' => '!='
384
- )
385
-
386
- // Multiple checks
387
- ref_id=1,2,3
388
- 'ref_id' => array(
389
- 'ids' => array( 1, 2, 3 )
390
- 'compare' => 'IN'
391
- )
392
-
393
- */
394
- if ( $this->args['ref_id'] !== NULL && ! empty( $this->args['ref_id'] ) ) {
395
-
396
- // Convert string queries to array queries
397
- if ( ! is_array( $this->args['ref_id'] ) ) {
398
-
399
- $reference_ids = ( ( count( explode( ',', $this->args['ref_id'] ) ) > 0 ) ? explode( ',', $this->args['ref_id'] ) : array( $this->args['ref_id'] ) );
400
-
401
- // Single id query
402
- if ( count( $reference_ids ) == 1 )
403
- $this->args['ref_id'] = array( 'ids' => $reference_ids[0], 'compare' => '=' );
404
-
405
- // Multiple id query
406
- elseif ( count( $reference_ids ) > 1 )
407
- $this->args['ref_id'] = array( 'ids' => $reference_ids, 'compare' => 'IN' );
408
-
409
- }
410
-
411
- // Make sure query is properly formatted
412
- if ( array_key_exists( 'ids', $this->args['ref_id'] ) && array_key_exists( 'compare', $this->args['ref_id'] ) ) {
413
-
414
- // IN or NOT IN comparisons
415
- if ( in_array( $this->args['ref_id']['compare'], array( 'IN', 'NOT IN' ) ) && is_array( $this->args['ref_id']['ids'] ) )
416
- $wheres[] = $wpdb->prepare( "ref_id IN ( %d" . str_repeat( ", %d", ( count( $this->args['ref_id']['ids'] ) - 1 ) ) . " )", $this->args['ref_id']['ids'] );
417
-
418
- // All other supported comparisons
419
- elseif ( in_array( $this->args['ref_id']['compare'], array( '=', '!=', '>', '>=', '<', '<=' ) ) && ! is_array( $this->args['ref_id']['ids'] ) ) {
420
-
421
- $compare = esc_sql( $this->args['ref_id']['compare'] );
422
- $wheres[] = $wpdb->prepare( "ref_id {$compare} %d", absint( $this->args['ref_id']['ids'] ) );
423
-
424
- }
425
-
426
- }
427
-
428
- }
429
-
430
- /**
431
- * Amount Query
432
- *
433
-
434
- // Comparisons
435
- 'amount' => array(
436
- 'num' => 10,
437
- 'compare' => '<'
438
- )
439
-
440
- // Between (Range)
441
- 'amount' => array(
442
- 'num' => array( 1, 10 ),
443
- 'compare' => 'BETWEEN'
444
- )
445
-
446
- // Specific amount
447
- amount=10
448
- 'amount' => array(
449
- 'num' => 10,
450
- 'compare' => '='
451
- )
452
-
453
- // One of these (list)
454
- amount=1,10,12,14
455
- 'amount' => array(
456
- 'num' => array( 1, 10, 12, 14 ),
457
- 'compare' => 'IN'
458
- )
459
-
460
- */
461
- if ( $this->args['amount'] !== NULL && ! empty( $this->args['amount'] ) ) {
462
-
463
- // Convert string queries to array queries
464
- if ( ! is_array( $this->args['amount'] ) ) {
465
-
466
- $point_value = ( ( count( explode( ',', $this->args['amount'] ) ) > 0 ) ? explode( ',', $this->args['amount'] ) : array( $this->args['amount'] ) );
467
-
468
- // Single amount query
469
- if ( count( $point_value ) == 1 )
470
- $this->args['amount'] = array( 'num' => $point_value[0], 'compare' => '=' );
471
-
472
- // Multiple amounts query
473
- elseif ( count( $point_value ) > 1 )
474
- $this->args['amount'] = array( 'num' => $point_value, 'compare' => 'IN' );
475
-
476
- }
477
-
478
- // Make sure query is properly formatted
479
- if ( array_key_exists( 'num', $this->args['amount'] ) && array_key_exists( 'compare', $this->args['amount'] ) ) {
480
-
481
- // Between (requires num to be an array)
482
- if ( in_array( $this->args['amount']['compare'], array( 'BETWEEN', 'NOT BETWEEN' ) ) && is_array( $this->args['amount']['num'] ) ) {
483
-
484
- $between = esc_sql( $this->args['amount']['compare'] );
485
- $wheres[] = $wpdb->prepare( "creds {$between} {$format} AND {$format}", $this->args['amount']['num'] );
486
-
487
- }
488
-
489
- // IN or NOT IN comparisons
490
- elseif ( in_array( $this->args['amount']['compare'], array( 'IN', 'NOT IN' ) ) && is_array( $this->args['amount']['num'] ) )
491
- $wheres[] = $wpdb->prepare( "creds IN ( {$format}" . str_repeat( ',' . $format, ( count( $this->args['amount']['num'] ) - 1 ) ) . " )", $this->args['amount']['num'] );
492
-
493
- // All other supported comparisons
494
- elseif ( in_array( $this->args['amount']['compare'], array( '=', '!=', '>', '>=', '<', '<=' ) ) && ! is_array( $this->args['amount']['num'] ) ) {
495
-
496
- $compare = esc_sql( $this->args['amount']['compare'] );
497
- $wheres[] = $wpdb->prepare( "creds {$compare} {$format}", $this->args['amount']['num'] );
498
-
499
- }
500
-
501
- }
502
-
503
- }
504
-
505
- /**
506
- * Time Query
507
- * Supports either YYYY-MM-DD or MM/DD/YYYY date formats or unix timestamps
508
- * Dates can use time for more precise queries but it is not required. If no time is set, the dates last second is used
509
- * So e.g. 2016-01-01 will become 2016-01-01 23:59:59. If this is not desired, then a time has to be included when using string dates.
510
- * Not applicable when providing unix timestamps.
511
- * @uses strtotime() http://php.net/manual/en/function.strtotime.php
512
- *
513
-
514
- // Todays entries
515
- time=today
516
- 'time' => array(
517
- 'dates' => 'today',
518
- 'compare' => '='
519
- )
520
-
521
- // Yesterdays entries
522
- time=yesterday
523
- 'time' => array(
524
- 'dates' => 'yesterday',
525
- 'compare' => '='
526
- )
527
-
528
- // This weeks entries
529
- time=thisweek
530
- 'time' => array(
531
- 'dates' => 'thisweek',
532
- 'compare' => '='
533
- )
534
-
535
- // This months entries
536
- time=thismonth
537
- 'time' => array(
538
- 'dates' => 'thismonth',
539
- 'compare' => '='
540
- )
541
-
542
- // Between two dates
543
- 'time' => array(
544
- 'dates' => array( '2016-01-01', '2016-12-31' ),
545
- 'compare' => 'BETWEEN'
546
- )
547
-
548
- // Specific date
549
- time=2016-01-01
550
- 'time' => array(
551
- 'dates' => '2016-01-01',
552
- 'compare' => '='
553
- )
554
-
555
- // Comparisons
556
- 'time' => array(
557
- 'dates' => '2016-01-01 00:00:00',
558
- 'compare' => '<='
559
- )
560
-
561
- */
562
- if ( $this->args['time'] !== NULL && ! empty( $this->args['time'] ) ) {
563
-
564
- // Convert string queries to array queries
565
- if ( ! is_array( $this->args['time'] ) ) {
566
-
567
- $datetimes = ( ( count( explode( ',', $this->args['time'] ) ) > 0 ) ? explode( ',', $this->args['time'] ) : array( $this->args['time'] ) );
568
- $dates = $this->get_timestamps( $datetimes );
569
-
570
- if ( $dates !== false ) {
571
-
572
- // Single time query
573
- if ( count( $dates ) == 1 )
574
- $this->args['time'] = array( 'dates' => $dates[0], 'compare' => '=' );
575
-
576
- // Keyword time query or between two dates
577
- elseif ( count( $dates ) == 2 || in_array( $this->args['time'], array( 'today', 'yesterday', 'thisweek', 'thismonth' ) ) )
578
- $this->args['time'] = array( 'dates' => $dates, 'compare' => 'BETWEEN' );
579
-
580
- // Multiple time query
581
- else
582
- $this->args['time'] = array( 'dates' => $dates, 'compare' => 'IN' );
583
-
584
- }
585
-
586
- }
587
-
588
- // Make sure query is properly formatted
589
- if ( is_array( $this->args['time'] ) && array_key_exists( 'dates', $this->args['time'] ) && array_key_exists( 'compare', $this->args['time'] ) ) {
590
-
591
- // Between (requires dates to be an array)
592
- if ( in_array( $this->args['time']['compare'], array( 'BETWEEN', 'NOT BETWEEN' ) ) && is_array( $this->args['time']['dates'] ) ) {
593
-
594
- $between = esc_sql( $this->args['time']['compare'] );
595
- $dates = $this->get_timestamps( $this->args['time']['dates'] );
596
- if ( $dates !== false )
597
- $wheres[] = $wpdb->prepare( "time {$between} %d AND %d", $dates );
598
-
599
- $this->args['time']['dates'] = $dates;
600
-
601
- }
602
-
603
- // IN or NOT IN comparisons
604
- elseif ( in_array( $this->args['time']['compare'], array( 'IN', 'NOT IN' ) ) && is_array( $this->args['time']['dates'] ) ) {
605
-
606
- $dates = $this->get_timestamps( $this->args['time']['dates'] );
607
- if ( $dates !== false )
608
- $wheres[] = $wpdb->prepare( "time IN ( %d" . str_repeat( ",%d", ( count( $this->args['time']['dates'] ) - 1 ) ) . " )", $dates );
609
-
610
- }
611
-
612
- // All other supported comparisons
613
- elseif ( in_array( $this->args['time']['compare'], array( '=', '!=', '>', '>=', '<', '<=' ) ) && ! is_array( $this->args['time']['dates'] ) ) {
614
-
615
- $compare = esc_sql( $this->args['time']['compare'] );
616
- $date = $this->get_timestamp( $this->args['time']['dates'] );
617
- if ( $date !== false )
618
- $wheres[] = $wpdb->prepare( "time {$compare} %d", $date );
619
-
620
- }
621
-
622
- }
623
-
624
- }
625
-
626
- /**
627
- * Search Entries Query
628
- *
629
-
630
- // Search
631
- s=hello
632
-
633
- */
634
- if ( $this->args['s'] !== NULL && ! empty( $this->args['s'] ) ) {
635
-
636
- $search_query = sanitize_text_field( $this->args['s'] );
637
-
638
- // Check if we are using wildcards
639
- if ( str_replace( '%', '', $search_query ) != $search_query )
640
- $wheres[] = $wpdb->prepare( "entry LIKE %s", $search_query );
641
-
642
- else
643
- $wheres[] = $wpdb->prepare( "entry = %s", $search_query );
644
-
645
- }
646
-
647
- /**
648
- * Search Data Column Query
649
- *
650
-
651
- // Search
652
- data=boo
653
-
654
- */
655
- if ( $this->args['data'] !== NULL && ! empty( $this->args['data'] ) ) {
656
-
657
- $data_query = sanitize_text_field( $this->args['data'] );
658
-
659
- // Check if we are using wildcards
660
- if ( str_replace( '%', '', $data_query ) != $data_query )
661
- $wheres[] = $wpdb->prepare( "data LIKE %s", $data_query );
662
-
663
- else
664
- $wheres[] = $wpdb->prepare( "data = %s", $data_query );
665
-
666
- }
667
-
668
- /**
669
- * Ordering of results
670
- *
671
-
672
- // Single order
673
- orderby=time&order=ASC
674
-
675
- // Multiple orders
676
- 'orderby' => array( 'time' => 'ASC', 'id' => 'ASC' )
677
-
678
- */
679
- $sortby = "ORDER BY time DESC";
680
- if ( ! empty( $this->args['orderby'] ) ) {
681
-
682
- // Make sure $sortby is valid
683
- $allowed = apply_filters( 'mycred_allowed_sortby', array( 'id', 'ref', 'ref_id', 'user_id', 'creds', 'ctype', 'entry', 'data', 'time' ) );
684
-
685
- // Convert strings to array
686
- if ( ! is_array( $this->args['orderby'] ) && ! empty( $this->args['order'] ) ) {
687
-
688
- $this->args['orderby'] = array( $this->args['orderby'] => $this->args['order'] );
689
-
690
- }
691
-
692
- $orders = array();
693
- $duplicate_check = array();
694
- foreach ( $this->args['orderby'] as $orderby => $order ) {
695
-
696
- $orderby = sanitize_text_field( $orderby );
697
- if ( ! in_array( $orderby, $allowed ) ) $orderby = 'time';
698
-
699
- // Make sure we ar enot attempting to order by the same column multiple times
700
- if ( in_array( $orderby, $duplicate_check ) ) continue;
701
-
702
- $order = sanitize_text_field( $order );
703
- if ( ! in_array( $order, array( 'ASC', 'DESC' ) ) ) $order = 'DESC';
704
- $order = strtoupper( $order );
705
-
706
- $orders[] = $orderby . ' ' . $order;
707
- $duplicate_check[] = $orderby;
708
-
709
- }
710
-
711
- $sortby = "ORDER BY " . implode( ', ', $orders );
712
-
713
- }
714
-
715
- /**
716
- * Results Return Option
717
- * Added in 1.7.5, this allows us to use this class to return specific sets of information.
718
- * If fields is set to anything but "all", the results table can not be used.
719
- *
720
-
721
- // Everything (default)
722
- fields=all
723
- ids=0 (depreciated)
724
-
725
- // Return entry ids
726
- fields=ids
727
- ids=1 (depreciated)
728
-
729
- // Column
730
- fields=user_id
731
- 'fields' => array( 'user_id' )
732
-
733
- // Multiple columns
734
- fields=id,user_id,creds
735
- 'fields' => array( 'id', 'user_id', 'creds' )
736
-
737
- */
738
- $select = '*';
739
- $get_results = true;
740
- $get_column = false;
741
-
742
- // Support will be removed in future version
743
- if ( (bool) $this->args['ids'] === true )
744
- $this->args['fields'] = array( 'ids' );
745
-
746
- if ( $this->args['fields'] !== NULL && ! empty( $this->args['fields'] ) ) {
747
-
748
- // Convert string queries to array queries
749
- if ( ! is_array( $this->args['fields'] ) ) {
750
-
751
- $columns = ( ( count( explode( ',', $this->args['fields'] ) ) > 0 ) ? explode( ',', $this->args['fields'] ) : array( $this->args['fields'] ) );
752
-
753
- // Return one specific column
754
- if ( count( $columns ) == 1 )
755
- $this->args['fields'] = $columns[0];
756
-
757
- // Return multiple columns
758
- elseif ( count( $columns ) > 1 )
759
- $this->args['fields'] = $columns;
760
-
761
- }
762
-
763
- // All - default
764
- if ( ! is_array( $this->args['fields'] ) && $this->args['fields'] == 'all' ) {
765
-
766
- $select = '*';
767
- $this->render_mode = true;
768
- $get_results = true;
769
- $get_column = false;
770
- }
771
-
772
- // Single column
773
- elseif ( ( is_array( $this->args['fields'] ) && count( $this->args['fields'] ) == 1 ) || ! is_array( $this->args['fields'] ) ) {
774
-
775
- $select = ( ( is_array( $this->args['fields'] ) ) ? esc_sql( $this->args['fields'][0] ) : $this->args['fields'] );
776
- $this->render_mode = false;
777
- $get_results = false;
778
- $get_column = true;
779
-
780
- }
781
-
782
- // Multiple columns
783
- elseif ( is_array( $this->args['fields'] ) ) {
784
-
785
- $select = implode( ', ', $this->args['fields'] );
786
- $this->render_mode = false;
787
- $get_results = true;
788
- $get_column = false;
789
-
790
- }
791
-
792
- }
793
-
794
- /**
795
- * Number of results to return
796
- *
797
-
798
- // Everything
799
- number=-1
800
-
801
- // Entries per page
802
- number=10
803
-
804
- // Offset
805
- offset=10&number=10
806
-
807
- */
808
- $number = $this->args['number'];
809
- if ( $number < -1 ) $number = abs( $number );
810
- elseif ( $number == 0 || $number == -1 ) $number = NULL;
811
-
812
- /**
813
- * Set Query Limit
814
- */
815
- if ( $number !== NULL ) {
816
-
817
- $page = 1;
818
- if ( $this->args['paged'] !== NULL ) {
819
- $page = absint( $this->args['paged'] );
820
- if ( ! $page )
821
- $page = 1;
822
- }
823
-
824
- if ( $this->args['offset'] == '' ) {
825
- $pgstrt = ($page - 1) * $number . ', ';
826
- }
827
-
828
- else {
829
- $offset = absint( $this->args['offset'] );
830
- $pgstrt = $offset . ', ';
831
- }
832
-
833
- $limits = 'LIMIT ' . $pgstrt . $number;
834
-
835
- }
836
-
837
- $found_rows = '';
838
- if ( $limits != '' ) $found_rows = 'SQL_CALC_FOUND_ROWS';
839
-
840
- /**
841
- * Construct Query
842
- */
843
- $where = ( ( ! empty( $wheres ) ) ? 'WHERE ' . implode( ' AND ', $wheres ) : '' );
844
- $this->request = "SELECT {$found_rows} {$select} FROM {$this->core->log_table} {$where} {$sortby} {$limits};";
845
-
846
- /**
847
- * Populate Results
848
- * Based on what we selected to return with the "fields" argument.
849
- */
850
- if ( $get_column ) {
851
-
852
- $this->results = $wpdb->get_col( $this->request );
853
-
854
- }
855
-
856
- else {
857
-
858
- $this->results = $wpdb->get_results( $this->request, $array ? ARRAY_A : OBJECT );
859
-
860
- }
861
-
862
- /**
863
- * Calculate rows and max number of pages for navigation
864
- */
865
- if ( $this->render_mode ) {
866
-
867
- if ( $limits != '' )
868
- $this->num_rows = $wpdb->get_var( 'SELECT FOUND_ROWS()' );
869
- else
870
- $this->num_rows = count( $this->results );
871
-
872
- if ( $limits != '' )
873
- $this->max_num_pages = ceil( $this->num_rows / $number );
874
-
875
- $this->refs = $wpdb->get_col( "SELECT DISTINCT ref FROM {$this->core->log_table} {$where};" );
876
-
877
- }
878
-
879
- $this->total_rows = $wpdb->get_var( "SELECT COUNT(*) FROM {$this->core->log_table}" );
880
-
881
- }
882
-
883
- /**
884
- * Table Headers
885
- * Returns all table column headers.
886
- * @filter mycred_log_column_headers
887
- * @since 0.1
888
- * @version 1.1.3
889
- */
890
- public function table_headers() {
891
-
892
- // Headers already set
893
- if ( ! empty( $this->headers ) || ! $this->render_mode ) return;
894
-
895
- global $mycred_types;
896
-
897
- $columns = array(
898
- 'username' => __( 'User', 'mycred' ),
899
- 'time' => __( 'Date', 'mycred' ),
900
- 'creds' => $this->core->plural(),
901
- 'entry' => __( 'Entry', 'mycred' )
902
- );
903
-
904
- if ( $this->args['user_id'] !== NULL )
905
- unset( $columns['username'] );
906
-
907
- if ( $this->is_admin )
908
- $columns = array(
909
- 'cb' => '',
910
- 'username' => __( 'User', 'mycred' ),
911
- 'ref' => __( 'Reference', 'mycred' ),
912
- 'time' => __( 'Date', 'mycred' ),
913
- 'creds' => $this->core->plural(),
914
- 'entry' => __( 'Entry', 'mycred' )
915
- );
916
-
917
- $headers = $this->headers;
918
- if ( empty( $this->headers ) )
919
- $headers = $columns;
920
-
921
- // If we are showing results for multiple point types, the label will not be correct
922
- // Instead we use a more generic label.
923
- if ( array_key_exists( 'creds', $headers ) && count( $this->types ) > 1 )
924
- $headers['creds'] = __( 'Amount', 'mycred' );
925
-
926
- $this->headers = apply_filters( 'mycred_log_column_headers', $headers, $this, $this->is_admin );
927
-
928
- }
929
-
930
- /**
931
- * Has Entries
932
- * @returns true or false
933
- * @since 0.1
934
- * @version 1.0
935
- */
936
- public function have_entries() {
937
-
938
- if ( ! empty( $this->results ) ) return true;
939
- return false;
940
-
941
- }
942
-
943
- /**
944
- * No Entries
945
- * @since 0.1
946
- * @version 1.0
947
- */
948
- public function no_entries() {
949
-
950
- echo $this->get_no_entries();
951
-
952
- }
953
-
954
- /**
955
- * Get No Entries
956
- * @since 0.1
957
- * @version 1.0
958
- */
959
- public function get_no_entries() {
960
-
961
- return __( 'No log entries found', 'mycred' );
962
-
963
- }
964
-
965
- /**
966
- * Get Page Number
967
- * @since 1.4
968
- * @version 1.0.3
969
- */
970
- public function get_pagenum() {
971
-
972
- global $wp;
973
-
974
- $page_key = ( isset( $this->args['page_arg'] ) && $this->args['page_arg'] !== NULL && $this->args['page_arg'] != '' ) ? $this->args['page_arg'] : 'page';
975
- if ( isset( $wp->query_vars[ $page_key ] ) && $wp->query_vars[ $page_key ] != '' )
976
- $pagenum = absint( $wp->query_vars[ $page_key ] );
977
-
978
- elseif ( isset( $_REQUEST[ $page_key ] ) )
979
- $pagenum = absint( $_REQUEST[ $page_key ] );
980
-
981
- elseif ( isset( $_REQUEST[ $page_key ] ) )
982
- $pagenum = absint( $_REQUEST[ $page_key ] );
983
-
984
- else return 1;
985
-
986
- return max( 1, $pagenum );
987
-
988
- }
989
-
990
- /**
991
- * Table Nav
992
- * @since 0.1
993
- * @version 1.1.1
994
- */
995
- public function table_nav( $location = 'top', $is_profile = false ) {
996
-
997
- if ( ! $this->have_entries() || ! $this->render_mode ) return;
998
-
999
- if ( $location == 'top' ) {
1000
-
1001
- $this->bulk_actions();
1002
- $this->filter_options( $is_profile );
1003
- $this->navigation( $location );
1004
-
1005
- }
1006
- else {
1007
-
1008
- $this->navigation( $location );
1009
-
1010
- }
1011
-
1012
- }
1013
-
1014
- /**
1015
- * Bulk Actions
1016
- * @since 1.7
1017
- * @version 1.0.1
1018
- */
1019
- public function bulk_actions() {
1020
-
1021
- if ( ! $this->is_admin || ! $this->render_mode ) return;
1022
-
1023
- $bulk_actions = apply_filters( 'mycred_log_bulk_actions', array(
1024
- '-1' => __( 'Bulk Actions', 'mycred' ),
1025
- 'export-raw' => __( 'Export Raw', 'mycred' ),
1026
- 'export-format' => __( 'Export Formatted', 'mycred' ),
1027
- 'delete' => __( 'Delete', 'mycred' )
1028
- ), $this );
1029
-
1030
- if ( empty( $bulk_actions ) ) return;
1031
-
1032
- ?>
1033
- <div class="alignleft actions bulkactions">
1034
- <select name="action" id="bulk-action-selector-top">
1035
- <?php
1036
-
1037
- foreach ( $bulk_actions as $action_id => $label )
1038
- echo '<option value="' . $action_id . '">' . $label . '</option>';
1039
-
1040
- ?>
1041
- </select>
1042
- <input type="submit" class="button action" id="doaction" value="<?php _e( 'Apply', 'mycred' ); ?>" />
1043
- </div>
1044
- <?php
1045
-
1046
- }
1047
-
1048
- /**
1049
- * Filter Log options
1050
- * @since 0.1
1051
- * @version 1.3.3
1052
- */
1053
- public function filter_options( $is_profile = false ) {
1054
-
1055
- if ( ! $this->render_mode ) return;
1056
-
1057
- echo '<div class="alignleft actions">';
1058
- $show = false;
1059
-
1060
- // Filter by reference
1061
- if ( ! empty( $this->refs ) ) {
1062
-
1063
- echo '<select name="ref" id="myCRED-reference-filter"><option value="">' . __( 'Show all references', 'mycred' ) . '</option>';
1064
- foreach ( $this->refs as $ref ) {
1065
-
1066
- $label = str_replace( array( '_', '-' ), ' ', $ref );
1067
- echo '<option value="' . $ref . '"';
1068
- if ( isset( $_GET['ref'] ) && $_GET['ref'] == $ref ) echo ' selected="selected"';
1069
- echo '>' . ucwords( $label ) . '</option>';
1070
-
1071
- }
1072
- echo '</select>';
1073
- $show = true;
1074
-
1075
- }
1076
-
1077
- // Filter by user
1078
- if ( $this->core->can_edit_creds() && ! $is_profile && $this->num_rows > 0 ) {
1079
-
1080
- echo '<input type="text" class="form-control" name="user" id="myCRED-user-filter" size="22" placeholder="' . __( 'User ID, Username, Email or Nicename', 'mycred' ) . '" value="' . ( ( isset( $_GET['user'] ) ) ? esc_attr( $_GET['user'] ) : '' ) . '" /> ';
1081
- $show = true;
1082
-
1083
- }
1084
-
1085
- // Filter Order
1086
- if ( $this->num_rows > 0 ) {
1087
-
1088
- echo '<select name="order" id="myCRED-order-filter"><option value="">' . __( 'Show in order', 'mycred' ) . '</option>';
1089
- foreach ( array( 'ASC' => __( 'Ascending', 'mycred' ), 'DESC' => __( 'Descending', 'mycred' ) ) as $value => $label ) {
1090
-
1091
- echo '<option value="' . $value . '"';
1092
- if ( ! isset( $_GET['order'] ) && $value == 'DESC' ) echo ' selected="selected"';
1093
- elseif ( isset( $_GET['order'] ) && $_GET['order'] == $value ) echo ' selected="selected"';
1094
- echo '>' . $label . '</option>';
1095
-
1096
- }
1097
- echo '</select>';
1098
- $show = true;
1099
-
1100
- }
1101
-
1102
- // Let others play
1103
- if ( has_action( 'mycred_filter_log_options' ) ) {
1104
- do_action( 'mycred_filter_log_options', $this );
1105
- $show = true;
1106
- }
1107
-
1108
- if ( $show === true )
1109
- echo '<input type="submit" class="btn btn-default button button-secondary" value="' . __( 'Filter', 'mycred' ) . '" />';
1110
-
1111
- echo '</div>';
1112
-
1113
- }
1114
-
1115
- /**
1116
- * Front Navigation
1117
- * Renders navigation with bootstrap support
1118
- * @since 1.7
1119
- * @version 1.0.1
1120
- */
1121
- public function front_navigation( $location = 'top', $pagination = 10 ) {
1122
-
1123
- if ( ! $this->have_entries() || $this->max_num_pages == 1 || ! $this->render_mode ) return;
1124
-
1125
- ?>
1126
- <div class="row pagination-<?php echo $location; ?>">
1127
- <div class="col-xs-12">
1128
-
1129
- <?php $this->front_pagination( $pagination ); ?>
1130
-
1131
- </div>
1132
- </div>
1133
- <?php
1134
-
1135
- }
1136
-
1137
- /**
1138
- * Navigation Wrapper
1139
- * @since 0.1
1140
- * @version 1.1.1
1141
- */
1142
- public function navigation( $location = 'top', $id = '' ) {
1143
-
1144
- if ( ! $this->render_mode ) return;
1145
-
1146
- ?>
1147
- <h2 class="screen-reader-text sr-only"><?php _e( 'Log entries navigation', 'mycred' ); ?></h2>
1148
- <div class="tablenav-pages<?php if ( $this->max_num_pages == 1 ) echo ' one-page'; ?>">
1149
-
1150
- <?php $this->pagination( $location, $id ); ?>
1151
-
1152
- </div>
1153
- <br class="clear" />
1154
- <?php
1155
-
1156
- }
1157
-
1158
- /**
1159
- * Front Pagination
1160
- * @since 1.7
1161
- * @version 1.0.5
1162
- */
1163
- public function front_pagination( $pages_to_show = 5 ) {
1164
-
1165
- if ( ! $this->have_entries() || ! $this->render_mode ) return;
1166
-
1167
- $page_links = array();
1168
- $total_pages = $this->max_num_pages;
1169
- $current = $this->get_pagenum();
1170
-
1171
- $removable_query_args = wp_removable_query_args();
1172
-
1173
- $current_url = set_url_scheme( 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'] );
1174
- $current_url = remove_query_arg( $removable_query_args, $current_url );
1175
- $current_url = str_replace( '/' . $current . '/', '/', $current_url );
1176
- $current_url = apply_filters( 'mycred_log_front_nav_url', $current_url, $this );
1177
-
1178
- $pages_to_show = absint( $pages_to_show );
1179
- if ( $pages_to_show === 0 ) $pages_to_show = 5;
1180
-
1181
- // We can not show more pages then whats available
1182
- if ( $pages_to_show > $total_pages )
1183
- $pages_to_show = $total_pages;
1184
-
1185
- $disable_first = $disable_last = '';
1186
- if ( $current == 1 )
1187
- $disable_first = ' disabled';
1188
-
1189
- if ( $current == $total_pages )
1190
- $disable_last = ' disabled';
1191
-
1192
- if ( $current == 1 )
1193
- $page_links[] = '<li><span aria-hidden="true">&laquo;</span></li>';
1194
- else {
1195
- $page_links[] = sprintf( '<li><a class="%s" href="%s">%s</a></li>',
1196
- 'first-page',
1197
- esc_url( remove_query_arg( $this->args['page_arg'], $current_url ) ),
1198
- '&laquo;'
1199
- );
1200
- }
1201
-
1202
- if ( $current == 1 )
1203
- $page_links[] = '<li><span class="tablenav-pages-navspan" aria-hidden="true">&lsaquo;</span></li>';
1204
- else {
1205
- $page_links[] = sprintf( '<li><a class="%s" href="%s">%s</a></li>',
1206
- 'prev-page',
1207
- esc_url( add_query_arg( $this->args['page_arg'], max( 1, $current-1 ), $current_url ) ),
1208
- '&lsaquo;'
1209
- );
1210
- }
1211
-
1212
- $start_from = 1;
1213
- if ( $current > $pages_to_show ) {
1214
- $diff = (int) ( $current / $pages_to_show );
1215
- $start_from = $pages_to_show * $diff;
1216
- $pages_to_show = $start_from + $pages_to_show;
1217
- }
1218
-
1219
- for ( $i = $start_from; $i <= $pages_to_show; $i++ ) {
1220
-
1221
- if ( $i != $current )
1222
- $page_links[] = sprintf( '<li><a class="%s" href="%s">%s</a></li>',
1223
- 'mycred-nav',
1224
- esc_url( add_query_arg( $this->args['page_arg'], $i, $current_url ) ),
1225
- $i
1226
- );
1227
-
1228
- else
1229
- $page_links[] = '<li class="active"><span class="current">' . $current . '</span></li>';
1230
-
1231
- }
1232
-
1233
- if ( $current == $total_pages )
1234
- $page_links[] = '<li><span class="tablenav-pages-navspan" aria-hidden="true">&rsaquo;</span></li>';
1235
- else {
1236
- $page_links[] = sprintf( '<li><a class="%s" href="%s">%s</a></li>',
1237
- 'next-page' . $disable_last,
1238
- esc_url( add_query_arg( $this->args['page_arg'], min( $total_pages, $current+1 ), $current_url ) ),
1239
- '&rsaquo;'
1240
- );
1241
- }
1242
-
1243
- if ( $current == $total_pages )
1244
- $page_links[] = '<li><span class="tablenav-pages-navspan" aria-hidden="true">&raquo;</span></li>';
1245
- else {
1246
- $page_links[] = sprintf( '<li><a class="%s" href="%s">%s</a></li>',
1247
- 'last-page' . $disable_last,
1248
- esc_url( add_query_arg( $this->args['page_arg'], $total_pages, $current_url ) ),
1249
- '&raquo;'
1250
- );
1251
- }
1252
-
1253
- echo '<nav><ul class="pagination">' . implode( '', $page_links ) . '</ul></nav>';
1254
-
1255
- }
1256
-
1257
- /**
1258
- * Pagination
1259
- * @since 1.4
1260
- * @version 1.1.2
1261
- */
1262
- public function pagination( $location = 'top', $id = '' ) {
1263
-
1264
- if ( ! $this->render_mode ) return;
1265
-
1266
- $page_links = array();
1267
- $output = '';
1268
- $total_pages = $this->max_num_pages;
1269
- $current = $this->get_pagenum();
1270
- $current_url = set_url_scheme( 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'] );
1271
-
1272
- if ( ! $this->is_admin )
1273
- $current_url = str_replace( '/page/' . $current . '/', '/', $current_url );
1274
-
1275
- $current_url = remove_query_arg( array( 'hotkeys_highlight_last', 'hotkeys_highlight_first' ), $current_url );
1276
- $current_url = apply_filters( 'mycred_log_pagination_url', $current_url, $this );
1277
-
1278
- if ( $this->have_entries() )
1279
- $output = '<span class="displaying-num">' . sprintf( _n( '1 entry', '%d entries', $this->num_rows, 'mycred' ), $this->num_rows ) . '</span>';
1280
-
1281
- $total_pages_before = '<span class="paging-input">';
1282
- $total_pages_after = '</span>';
1283
-
1284
- $disable_first = $disable_last = $disable_prev = $disable_next = false;
1285
-
1286
- if ( $current == 1 ) {
1287
- $disable_first = true;
1288
- $disable_prev = true;
1289
- }
1290
- if ( $current == 2 ) {
1291
- $disable_first = true;
1292
- }
1293
- if ( $current == $total_pages ) {
1294
- $disable_last = true;
1295
- $disable_next = true;
1296
- }
1297
- if ( $current == $total_pages - 1 ) {
1298
- $disable_last = true;
1299
- }
1300
-
1301
- if ( $disable_first ) {
1302
- $page_links[] = '<span class="tablenav-pages-navspan" aria-hidden="true">&laquo;</span>';
1303
- } else {
1304
- $page_links[] = sprintf( "<a class='first-page' href='%s'><span class='screen-reader-text'>%s</span><span aria-hidden='true'>%s</span></a>",
1305
- esc_url( remove_query_arg( 'paged', $current_url ) ),
1306
- __( 'First page' ),
1307
- '&laquo;'
1308
- );
1309
- }
1310
-
1311
- if ( $disable_prev ) {
1312
- $page_links[] = '<span class="tablenav-pages-navspan" aria-hidden="true">&lsaquo;</span>';
1313
- } else {
1314
- $page_links[] = sprintf( "<a class='prev-page' href='%s'><span class='screen-reader-text'>%s</span><span aria-hidden='true'>%s</span></a>",
1315
- esc_url( add_query_arg( 'paged', max( 1, $current-1 ), $current_url ) ),
1316
- __( 'Previous page' ),
1317
- '&lsaquo;'
1318
- );
1319
- }
1320
-
1321
- if ( 'bottom' === $location ) {
1322
- $html_current_page = $current;
1323
- $total_pages_before = '<span class="screen-reader-text">' . __( 'Current Page' ) . '</span><span id="table-paging" class="paging-input">';
1324
- } else {
1325
- $html_current_page = sprintf( "%s<input class='current-page' id='current-page-selector' type='text' name='paged' value='%s' size='%d' aria-describedby='table-paging' />",
1326
- '<label for="current-page-selector" class="screen-reader-text">' . __( 'Current Page' ) . '</label>',
1327
- $current,
1328
- strlen( $total_pages )
1329
- );
1330
- }
1331
- $html_total_pages = sprintf( "<span class='total-pages'>%s</span>", number_format_i18n( $total_pages ) );
1332
- $page_links[] = $total_pages_before . sprintf( _x( '%1$s of %2$s', 'paging' ), $html_current_page, $html_total_pages ) . $total_pages_after;
1333
-
1334
- if ( $disable_next ) {
1335
- $page_links[] = '<span class="tablenav-pages-navspan" aria-hidden="true">&rsaquo;</span>';
1336
- } else {
1337
- $page_links[] = sprintf( "<a class='next-page' href='%s'><span class='screen-reader-text'>%s</span><span aria-hidden='true'>%s</span></a>",
1338
- esc_url( add_query_arg( 'paged', min( $total_pages, $current+1 ), $current_url ) ),
1339
- __( 'Next page' ),
1340
- '&rsaquo;'
1341
- );
1342
- }
1343
-
1344
- if ( $disable_last ) {
1345
- $page_links[] = '<span class="tablenav-pages-navspan" aria-hidden="true">&raquo;</span>';
1346
- } else {
1347
- $page_links[] = sprintf( "<a class='last-page' href='%s'><span class='screen-reader-text'>%s</span><span aria-hidden='true'>%s</span></a>",
1348
- esc_url( add_query_arg( 'paged', $total_pages, $current_url ) ),
1349
- __( 'Last page' ),
1350
- '&raquo;'
1351
- );
1352
- }
1353
-
1354
- $pagination_links_class = 'pagination-links';
1355
- if ( ! empty( $infinite_scroll ) ) {
1356
- $pagination_links_class = ' hide-if-js';
1357
- }
1358
- $output .= "\n<span class='$pagination_links_class'>" . join( "\n", $page_links ) . '</span>';
1359
-
1360
- if ( $total_pages ) {
1361
- $page_class = $total_pages < 2 ? ' one-page' : '';
1362
- } else {
1363
- $page_class = ' no-pages';
1364
- }
1365
-
1366
- echo $output;
1367
-
1368
- }
1369
-
1370
- /**
1371
- * Display
1372
- * @since 0.1
1373
- * @version 1.0.1
1374
- */
1375
- public function display() {
1376
-
1377
- if ( $this->render_mode )
1378
- echo $this->get_display();
1379
-
1380
- }
1381
-
1382
- /**
1383
- * Get Display
1384
- * Generates a table for our results.
1385
- * @since 0.1
1386
- * @version 1.1.2
1387
- */
1388
- public function get_display() {
1389
-
1390
- if ( ! $this->render_mode ) return '';
1391
-
1392
- $this->table_headers();
1393
-
1394
- $table_class = 'table table-condensed mycred-table';
1395
- if ( $this->is_admin )
1396
- $table_class = 'mycred-table wp-list-table widefat fixed striped users';
1397
-
1398
- $output = '';
1399
- if ( ! $this->is_admin )
1400
- $output .= '<div class="table-responsive">';
1401
-
1402
- $output .= '
1403
- <table class="' . apply_filters( 'mycred_log_table_classes', $table_class, $this ) . '" cellspacing="0" cellspacing="0">
1404
- <thead>
1405
- <tr>';
1406
-
1407
- // Table header
1408
- foreach ( $this->headers as $col_id => $col_title ) {
1409
-
1410
- $class = '';
1411
- if ( $col_id != 'username' && in_array( $col_id, $this->hidden_headers ) )
1412
- $class = ' hidden';
1413
-
1414
- if ( $col_id == 'cb' )
1415
- $output .= '<td id="cb" class="manage-column column-cb check-column"><label class="screen-reader-text" for="cb-select-all-1">' . __( 'Select all', 'mycred' ) . '</label><input type="checkbox" id="cb-select-all-1" /></td>';
1416
-
1417
- else
1418
- $output .= '<th scope="col" id="' . $col_id . '" class="manage-column' . ( ( $col_id == 'username' ) ? ' column-primary' : '' ) . ' column-' . $col_id . $class . '">' . $col_title . '</th>';
1419
-
1420
- }
1421
-
1422
- $output .= '
1423
- </tr>
1424
- </thead>
1425
- <tbody id="the-list">';
1426
-
1427
- // Loop
1428
- if ( $this->have_entries() ) {
1429
-
1430
- $alt = 0;
1431
-
1432
- foreach ( $this->results as $log_entry ) {
1433
-
1434
- $row_class = apply_filters( 'mycred_log_row_classes', array( 'entry-' . $log_entry->id, 'type-log-entry', 'format-standard', 'hentry' ), $log_entry );
1435
-
1436
- $alt = $alt+1;
1437
- if ( $alt % 2 == 0 )
1438
- $row_class[] = 'alt';
1439
-
1440
- $output .= '<tr class="' . implode( ' ', $row_class ) . '" id="entry-' . $log_entry->id . '">' . $this->get_the_entry( $log_entry ) . '</tr>';
1441
-
1442
- }
1443
-
1444
- }
1445
- // No log entry
1446
- else {
1447
-
1448
- $output .= '<tr><td colspan="' . count( $this->headers ) . '" class="no-entries">' . $this->get_no_entries() . '</td></tr>';
1449
-
1450
- }
1451
-
1452
- $output .= '
1453
- </tbody>
1454
- <tfoot>
1455
- <tr>';
1456
-
1457
- // Table footer
1458
- foreach ( $this->headers as $col_id => $col_title ) {
1459
-
1460
- $class = '';
1461
- if ( $col_id != 'username' && in_array( $col_id, $this->hidden_headers ) )
1462
- $class = ' hidden';
1463
-
1464
- if ( $col_id == 'cb' )
1465
- $output .= '<td class="manage-column column-cb check-column"><label class="screen-reader-text" for="cb-select-all-2">' . __( 'Select all', 'mycred' ) . '</label><input type="checkbox" id="cb-select-all-2" /></td>';
1466
-
1467
- else
1468
- $output .= '<th scope="col" class="manage-column' . ( ( $col_id == 'username' ) ? ' column-primary' : '' ) . ' column-' . $col_id . $class . '">' . $col_title . '</th>';
1469
-
1470
- }
1471
-
1472
- $output .= '
1473
- </tr>
1474
- </tfoot>
1475
- </table>';
1476
-
1477
- if ( ! $this->is_admin )
1478
- $output .= '</div>';
1479
-
1480
- return $output;
1481
-
1482
- }
1483
-
1484
- /**
1485
- * The Entry
1486
- * @since 0.1
1487
- * @version 1.1.1
1488
- */
1489
- public function the_entry( $log_entry, $wrap = 'td' ) {
1490
-
1491
- if ( $this->render_mode )
1492
- echo $this->get_the_entry( $log_entry, $wrap );
1493
-
1494
- }
1495
-
1496
- /**
1497
- * Get The Entry
1498
- * Generated a single entry row depending on the columns used / requested.
1499
- * @filter mycred_log_date
1500
- * @since 0.1
1501
- * @version 1.4.4
1502
- */
1503
- public function get_the_entry( $log_entry, $wrap = 'td' ) {
1504
-
1505
- if ( ! $this->render_mode ) return '';
1506
-
1507
- $date_format = get_option( 'date_format' ) . ' ' . get_option( 'time_format' );
1508
- $entry_data = '';
1509
-
1510
- // Run though columns
1511
- foreach ( $this->headers as $column_id => $column_name ) {
1512
-
1513
- $hidden = '';
1514
- if ( $column_id != 'username' && in_array( $column_id, $this->hidden_headers ) )
1515
- $hidden = ' hidden';
1516
-
1517
- $content = false;
1518
- $data = '';
1519
-
1520
- switch ( $column_id ) {
1521
-
1522
- // Checkbox column for bulk actions
1523
- case 'cb' :
1524
-
1525
- $entry_data .= '<th scope="row" class="check-column"><label class="screen-reader-text" for="mycred-log-entry' . $log_entry->id . '">' . __( 'Select entry', 'mycred' ) . '</label><input type="checkbox" name="entry[]" id="mycred-log-entry' . $log_entry->id . '" value="' . $log_entry->id . '" /></th>';
1526
-
1527
- break;
1528
-
1529
- // Username Column
1530
- case 'username' :
1531
-
1532
- $user = get_userdata( $log_entry->user_id );
1533
- $display_name = '<span>' . __( 'User Missing', 'mycred' ) . ' (ID: ' . $log_entry->user_id . ')</span>';
1534
- if ( isset( $user->display_name ) )
1535
- $display_name = $user->display_name;
1536
-
1537
- if ( ! $this->is_admin )
1538
- $content = '<span>' . $display_name . '</span>';
1539
-
1540
- else {
1541
- $actions = $this->get_row_actions( $log_entry, $user );
1542
- $content = '<strong>' . $display_name . '</strong>' . $actions;
1543
- }
1544
-
1545
- if ( $this->is_admin )
1546
- $content .= '<button type="button" class="toggle-row"><span class="screen-reader-text">' . __( 'Show more details', 'mycred' ) . '</span></button>';
1547
-
1548
- $content = apply_filters( 'mycred_log_username', $content, $log_entry->user_id, $log_entry );
1549
-
1550
- break;
1551
-
1552
- // Log Entry Column
1553
- case 'ref' :
1554
-
1555
- $reference = ucwords( str_replace( array( '-', '_' ), ' ', $log_entry->ref ) );
1556
- if ( array_key_exists( $log_entry->ref, $this->references ) )
1557
- $reference = $this->references[ $log_entry->ref ];
1558
-
1559
- $content = apply_filters( 'mycred_log_ref', $reference, $log_entry->ref, $log_entry );
1560
-
1561
- break;
1562
-
1563
- // Date & Time Column
1564
- case 'time' :
1565
-
1566
- $content = $time = apply_filters( 'mycred_log_date', date_i18n( $date_format, $log_entry->time ), $log_entry->time, $log_entry );
1567
- $content = '<time>' . $content . '</time>';
1568
-
1569
- if ( $this->is_admin )
1570
- $content .= '<div class="row-actions"><span class="view"><a href="' . add_query_arg( array( 'page' => $_REQUEST['page'], 'time' => $this->get_time_for_filter( $log_entry->time ) ), admin_url( 'admin.php' ) ) . '">' . __( 'Filter by Date', 'mycred' ) . '</a></span></div>';
1571
-
1572
- break;
1573
-
1574
- // Amount Column
1575
- case 'creds' :
1576
-
1577
- $content = $creds = $this->types[ $log_entry->ctype ]->format_creds( $log_entry->creds );
1578
- $content = apply_filters( 'mycred_log_creds', $content, $log_entry->creds, $log_entry );
1579
- $data = ' data-raw="' . esc_attr( $log_entry->creds ) . '"';
1580
-
1581
- break;
1582
-
1583
- // Log Entry Column
1584
- case 'entry' :
1585
-
1586
- $content = $this->types[ $log_entry->ctype ]->parse_template_tags( $log_entry->entry, $log_entry );
1587
- $content = apply_filters( 'mycred_log_entry', $content, $log_entry->entry, $log_entry );
1588
- $data = ' data-raw="' . esc_attr( $log_entry->entry ) . '"';
1589
-
1590
- break;
1591
-
1592
- // Let others play
1593
- default :
1594
-
1595
- $content = apply_filters( 'mycred_log_' . $column_id, false, $log_entry );
1596
-
1597
- break;
1598
-
1599
- }
1600
-
1601
- if ( $content !== false )
1602
- $entry_data .= '<' . $wrap . ' class="' . ( ( $column_id == 'username' ) ? 'column-primary ' : '' ) . 'column-' . $column_id . $hidden . '" data-colname="' . $column_name . '" ' . $data . '>' . $content . '</' . $wrap . '>';
1603
-
1604
- }
1605
-
1606
- return $entry_data;
1607
-
1608
- }
1609
-
1610
- /**
1611
- * Row Actions
1612
- * @since 1.7
1613
- * @version 1.0.1
1614
- */
1615
- public function get_row_actions( $entry, $user ) {
1616
-
1617
- if ( ! $this->is_admin || ! $this->render_mode ) return;
1618
-
1619
- $filter_label = __( 'Filter by User', 'mycred' );
1620
- if ( $user === false )
1621
- $filter_label = __( 'Filter by ID', 'mycred' );
1622
-
1623
- $actions = array();
1624
-
1625
- if ( ! isset( $_REQUEST['user'] ) || $_REQUEST['user'] == '' )
1626
- $actions['view'] = '<a href="' . add_query_arg( array( 'page' => $_REQUEST['page'], 'user' => $entry->user_id ), admin_url( 'admin.php' ) ) . '">' . $filter_label . '</a>';
1627
-
1628
- $actions['edit'] = '<a href="javascript:void(0);" class="mycred-open-log-entry-editor" data-id="' . $entry->id . '" data-ref="' . $entry->ref . '">' . __( 'Edit', 'mycred' ) . '</a>';
1629
- $actions['delete'] = '<a href="javascript:void(0);" class="mycred-delete-row" data-id="' . $entry->id . '">' . __( 'Delete', 'mycred' ) . '</a>';
1630
-
1631
- if ( ! empty( $actions ) ) {
1632
-
1633
- $output = '';
1634
- $counter = 0;
1635
- $count = count( $actions );
1636
- foreach ( $actions as $id => $link ) {
1637
-
1638
- $end = ' | ';
1639
- if ( $counter+1 == $count )
1640
- $end = '';
1641
-
1642
- $output .= '<span class="' . $id . '">' . $link . $end . '</span>';
1643
- $counter ++;
1644
-
1645
- }
1646
-
1647
- return '<div class="row-actions">' . $output . '</div>';
1648
-
1649
- }
1650
-
1651
- }
1652
-
1653
- /**
1654
- * Exporter
1655
- * Displays all available export options.
1656
- * @since 0.1
1657
- * @version 1.1.1
1658
- */
1659
- public function exporter( $title = '', $is_profile = false ) {
1660
-
1661
- // Must be logged in
1662
- if ( ! is_user_logged_in() || ! $this->render_mode ) return;
1663
-
1664
- // Export options
1665
- $exports = mycred_get_log_exports();
1666
- $search_args = mycred_get_search_args();
1667
-
1668
- if ( array_key_exists( 'user', $exports ) && $this->args['user_id'] === NULL )
1669
- unset( $exports['user'] );
1670
-
1671
- ?>
1672
- <div style="display:none;" class="clear" id="export-log-history">
1673
- <?php if ( ! empty( $title ) ) : ?><h3 class="group-title"><?php echo $title; ?></h3><?php endif; ?>
1674
- <?php
1675
-
1676
- if ( ! empty( $exports ) ) {
1677
-
1678
- foreach ( (array) $exports as $id => $data ) {
1679
-
1680
- // Label
1681
- if ( $is_profile )
1682
- $label = $data['my_label'];
1683
- else
1684
- $label = $data['label'];
1685
-
1686
- $url = mycred_get_export_url( $id );
1687
- if ( $url === false ) continue;
1688
-
1689
- echo '<a href="" class="' . $data['class'] . '">' . $label . '</a> ';
1690
-
1691
- }
1692
-
1693
- ?>
1694
- <p><span class="description"><?php _e( 'Log entries are exported to a CSV file and depending on the number of entries selected, the process may take a few seconds.', 'mycred' ); ?></span></p>
1695
- <?php
1696
-
1697
- }
1698
-
1699
- else {
1700
-
1701
- echo '<p>' . __( 'No export options available.', 'mycred' ) . '</p>';
1702
-
1703
- }
1704
-
1705
- ?>
1706
- </div>
1707
- <script type="text/javascript">
1708
- jQuery(function($) {
1709
- $( '.toggle-exporter' ).click(function(){
1710
- $( '#export-log-history' ).toggle();
1711
- });
1712
- });
1713
- </script>
1714
- <?php
1715
-
1716
- }
1717
-
1718
- /**
1719
- * Log Search
1720
- * @since 0.1
1721
- * @version 1.0.5
1722
- */
1723
- public function search() {
1724
-
1725
- if ( ! $this->render_mode ) return;
1726
-
1727
- if ( isset( $_GET['s'] ) && $_GET['s'] != '' )
1728
- $serarch_string = $_GET['s'];
1729
- else
1730
- $serarch_string = '';
1731
-
1732
- ?>
1733
- <p class="search-box">
1734
- <label class="screen-reader-text"><?php _e( 'Search Log', 'mycred' ); ?>:</label>
1735
- <input type="search" name="s" value="<?php echo esc_attr( $serarch_string ); ?>" placeholder="<?php _e( 'search log entries', 'mycred' ); ?>" />
1736
- <input type="submit" id="search-submit" class="button button-medium button-secondary" value="<?php _e( 'Search Log', 'mycred' ); ?>" />
1737
- </p>
1738
- <?php
1739
-
1740
- }
1741
-
1742
- /**
1743
- * Filter by Dates
1744
- * @since 0.1
1745
- * @version 1.0.1
1746
- */
1747
- public function filter_dates( $url = '' ) {
1748
-
1749
- if ( ! $this->render_mode ) return;
1750
-
1751
- $date_sorting = apply_filters( 'mycred_sort_by_time', array(
1752
- '' => __( 'All', 'mycred' ),
1753
- 'today' => __( 'Today', 'mycred' ),
1754
- 'yesterday' => __( 'Yesterday', 'mycred' ),
1755
- 'thisweek' => __( 'This Week', 'mycred' ),
1756
- 'thismonth' => __( 'This Month', 'mycred' )
1757
- ) );
1758
-
1759
- if ( ! empty( $date_sorting ) ) {
1760
-
1761
- $total = count( $date_sorting );
1762
- $count = 0;
1763
-
1764
- echo '<ul class="subsubsub">';
1765
-
1766
- foreach ( $date_sorting as $sorting_id => $sorting_name ) {
1767
-
1768
- $count = $count+1;
1769
-
1770
- echo '<li class="' . $sorting_id . '"><a href="';
1771
-
1772
- // Build Query Args
1773
- $url_args = array();
1774
- if ( isset( $_GET['user_id'] ) && $_GET['user_id'] != '' )
1775
- $url_args['user_id'] = $_GET['user_id'];
1776
-
1777
- if ( isset( $_GET['ref'] ) && $_GET['ref'] != '' )
1778
- $url_args['ref'] = $_GET['ref'];
1779
-
1780
- if ( isset( $_GET['order'] ) && $_GET['order'] != '' )
1781
- $url_args['order'] = $_GET['order'];
1782
-
1783
- if ( isset( $_GET['s'] ) && $_GET['s'] != '' )
1784
- $url_args['s'] = $_GET['s'];
1785
-
1786
- if ( $sorting_id != '' )
1787
- $url_args['show'] = $sorting_id;
1788
-
1789
- // Build URL
1790
- if ( ! empty( $url_args ) )
1791
- echo esc_url( add_query_arg( $url_args, $url ) );
1792
-
1793
- else
1794
- echo esc_url( $url );
1795
-
1796
- echo '"';
1797
-
1798
- if ( isset( $_GET['show'] ) && $_GET['show'] == $sorting_id ) echo ' class="current"';
1799
- elseif ( ! isset( $_GET['show'] ) && $sorting_id == '' ) echo ' class="current"';
1800
-
1801
- echo '>' . $sorting_name . '</a>';
1802
- if ( $count != $total ) echo ' | ';
1803
- echo '</li>';
1804
-
1805
- }
1806
- echo '</ul>';
1807
-
1808
- }
1809
-
1810
- }
1811
-
1812
- /**
1813
- * Get Time from Filter
1814
- * @since 0.1
1815
- * @version 1.0.1
1816
- */
1817
- protected function get_time_for_filter( $timestamp ) {
1818
-
1819
- $start = strtotime( date( 'Y-m-d 00:00:00' ), $timestamp );
1820
- $end = $start + ( DAY_IN_SECONDS - 1 );
1821
-
1822
- return $start . ',' . $end;
1823
-
1824
- }
1825
-
1826
- /**
1827
- * Get User ID
1828
- * Converts username, email or userlogin into an ID if possible
1829
- * @since 1.6.3
1830
- * @version 1.0
1831
- */
1832
- protected function get_user_id( $string = '' ) {
1833
-
1834
- if ( ! is_numeric( $string ) ) {
1835
-
1836
- $user = get_user_by( 'login', $string );
1837
- if ( ! isset( $user->ID ) ) {
1838
-
1839
- $user = get_user_by( 'email', $string );
1840
- if ( ! isset( $user->ID ) ) {
1841
- $user = get_user_by( 'slug', $string );
1842
- if ( ! isset( $user->ID ) )
1843
- return false;
1844
- }
1845
-
1846
- }
1847
- return absint( $user->ID );
1848
-
1849
- }
1850
-
1851
- return $string;
1852
-
1853
- }
1854
-
1855
- /**
1856
- * Get Time from Keyword
1857
- * @since 1.7.5
1858
- * @version 1.0
1859
- */
1860
- protected function get_time_from_keyword( $keyword = '' ) {
1861
-
1862
- $today = strtotime( date( 'Y-m-d' ) . ' midnight', $this->now );
1863
- $todays_date = date( 'd', $this->now );
1864
- $weekday = date( 'w', $this->now );
1865
- $result = array();
1866
-
1867
- $keyword = strtolower( $keyword );
1868
-
1869
- // Today
1870
- if ( $keyword === 'today' ) {
1871
- $result[] = $today;
1872
- $result[] = $this->now;
1873
- }
1874
-
1875
- // Yesterday
1876
- elseif ( $keyword === 'yesterday' ) {
1877
- $result[] = strtotime( '-1 day midnight', $this->now );
1878
- $result[] = strtotime( 'today midnight', $this->now );
1879
- }
1880
-
1881
- // This week
1882
- elseif ( $keyword === 'thisweek' ) {
1883
-
1884
- $thisweek = strtotime( '-' . ( $weekday+1 ) . ' days midnight', $this->now );
1885
- if ( get_option( 'start_of_week' ) == $weekday )
1886
- $thisweek = $today;
1887
-
1888
- $result[] = $thisweek;
1889
- $result[] = $this->now;
1890
-
1891
- }
1892
-
1893
- // This month
1894
- elseif ( $keyword === 'thismonth' ) {
1895
- $result[] = strtotime( date( 'Y-m-01' ) . ' midnight', $this->now );
1896
- $result[] = $this->now;
1897
- }
1898
-
1899
- return $result;
1900
-
1901
- }
1902
-
1903
- /**
1904
- * Get Timestamp
1905
- * @since 1.7
1906
- * @version 1.0
1907
- */
1908
- protected function get_timestamp( $string = '' ) {
1909
-
1910
- // Unix timestamp?
1911
- if ( is_numeric( $string ) && strtotime( date( 'd-m-Y H:i:s', $string ) ) === (int) $string )
1912
- return $string;
1913
-
1914
- $timestamp = strtotime( $string, current_time( 'timestamp' ) );
1915
-
1916
- if ( $timestamp <= 0 )
1917
- $timestamp = false;
1918
-
1919
- return $timestamp;
1920
-
1921
- }
1922
-
1923
- /**
1924
- * Get Timestamps
1925
- * @since 1.7.5
1926
- * @version 1.0
1927
- */
1928
- protected function get_timestamps( $value = NULL ) {
1929
-
1930
- // Can't work with this
1931
- if ( $value === NULL || empty( $value ) ) return false;
1932
-
1933
- $timestamps = array();
1934
- $date_values = array();
1935
- foreach ( (array) $value as $date_string ) {
1936
-
1937
- $date_string = sanitize_text_field( $date_string );
1938
-
1939
- // Unix timestamp?
1940
- if ( is_numeric( $date_string ) && strtotime( date( 'Y-m-d H:i:s', $date_string ) ) === (int) $date_string )
1941
- $date_values[] = $date_string;
1942
-
1943
- // Keyword?
1944
- elseif ( in_array( $date_string, array( 'today', 'yesterday', 'thisweek', 'thismonth' ) ) )
1945
- $date_values[] = $date_string;
1946
-
1947
- // Valid date string?
1948
- elseif ( strtotime( $date_string ) !== false )
1949
- $date_values[] = $date_string;
1950
-
1951
- }
1952
-
1953
- if ( ! empty( $date_values ) ) {
1954
-
1955
- if ( count( $date_values ) == 1 )
1956
- $timestamps = $this->get_time_from_keyword( $date_values[0] );
1957
-
1958
- else {
1959
-
1960
- foreach ( $date_values as $value ) {
1961
-
1962
- if ( is_numeric( $value ) && strtotime( date( 'Y-m-d H:i:s', $value ) ) === (int) $value )
1963
- $timestamps[] = $value;
1964
- else
1965
- $timestamps[] = strtotime( $value, $this->now );
1966
-
1967
- }
1968
-
1969
- }
1970
-
1971
- }
1972
-
1973
- if ( empty( $timestamps ) ) $timestamps = false;
1974
-
1975
- return $timestamps;
1976
-
1977
- }
1978
-
1979
- /**
1980
- * Reset Query
1981
- * @since 1.3
1982
- * @version 1.0
1983
- */
1984
- public function reset_query() {
1985
-
1986
- $this->args = NULL;
1987
- $this->request = NULL;
1988
- $this->prep = NULL;
1989
- $this->num_rows = NULL;
1990
- $this->max_num_pages = NULL;
1991
- $this->total_rows = NULL;
1992
- $this->results = NULL;
1993
- $this->headers = NULL;
1994
-
1995
- }
1996
-
1997
- }
1998
- endif;
1999
-
2000
- /**
2001
- * Get Total Points by Time
2002
- * Counts the total amount of points that has been entered into the log between
2003
- * two given UNIX timestamps. Optionally you can restrict counting to a specific user
2004
- * or specific reference (or both).
2005
- *
2006
- * Will return false if the time stamps are incorrectly formated same for user id (must be int).
2007
- * If you do not want to filter by reference pass NULL and not an empty string or this function will
2008
- * return false. Same goes for the user id!
2009
- *
2010
- * @param $from (int|string) UNIX timestamp from when to start counting. The string 'today' can also
2011
- * be used to start counting from the start of today.
2012
- * @param $to (int|string) UNIX timestamp for when to stop counting. The string 'now' can also be used
2013
- * to count up until now.
2014
- * @param $ref (string) reference to filter by.
2015
- * @param $user_id (int|NULL) user id to filter by.
2016
- * @param $type (string) point type to filer by.
2017
- * @returns total points (int|float) or error message (string)
2018
- * @since 1.1.1
2019
- * @version 1.4.1
2020
- */
2021
- if ( ! function_exists( 'mycred_get_total_by_time' ) ) :
2022
- function mycred_get_total_by_time( $from = 'today', $to = 'now', $ref = NULL, $user_id = NULL, $type = MYCRED_DEFAULT_TYPE_KEY ) {
2023
-
2024
- if ( ! MYCRED_ENABLE_LOGGING ) return 0;
2025
-
2026
- global $wpdb;
2027
-
2028
- // Prep
2029
- $mycred = mycred( $type );
2030
- $wheres = array();
2031
- $now = current_time( 'timestamp' );
2032
-
2033
- // Reference
2034
- if ( $ref !== NULL && strlen( $ref ) > 0 )
2035
- $wheres[] = $wpdb->prepare( 'ref = %s', $ref );
2036
-
2037
- // User
2038
- if ( $user_id !== NULL && strlen( $user_id ) > 0 ) {
2039
-
2040
- // No use to run a calculation if the user is excluded
2041
- if ( $mycred->exclude_user( $user_id ) ) return 0;
2042
-
2043
- $wheres[] = $wpdb->prepare( 'user_id = %d', $user_id );
2044
-
2045
- }
2046
-
2047
- // Default from start of today
2048
- if ( $from == 'today' )
2049
- $from = strtotime( 'today midnight', $now );
2050
-
2051
- // From
2052
- else {
2053
-
2054
- $_from = strtotime( $from, $now );
2055
- if ( $_from === false || $_from < 0 ) return 'Invalid Time ($from)';
2056
-
2057
- $from = $_from;
2058
-
2059
- }
2060
-
2061
- if ( is_numeric( $from ) )
2062
- $wheres[] = $wpdb->prepare( 'time >= %d', $from );
2063
-
2064
- // Until
2065
- if ( $to == 'now' )
2066
- $to = $now;
2067
-
2068
- else {
2069
-
2070
- $_to = strtotime( $to );
2071
- if ( $_to === false || $_to < 0 ) return 'Invalid Time ($to)';
2072
-
2073
- $to = $_to;
2074
-
2075
- }
2076
-
2077
- if ( is_numeric( $to ) )
2078
- $wheres[] = $wpdb->prepare( 'time <= %d', $to );
2079
-
2080
- if ( mycred_point_type_exists( $type ) )
2081
- $wheres[] = $wpdb->prepare( 'ctype = %s', $type );
2082
-
2083
- // Construct
2084
- $where = implode( ' AND ', $wheres );
2085
-
2086
- // Query
2087
- $query = $wpdb->get_var( "
2088
- SELECT SUM( creds )
2089
- FROM {$mycred->log_table}
2090
- WHERE {$where}
2091
- ORDER BY time;" );
2092
-
2093
- if ( $query === NULL || $query == 0 )
2094
- return $mycred->zero();
2095
-
2096
- return $mycred->number( $query );
2097
-
2098
- }
2099
- endif;
2100
-
2101
- /**
2102
- * Get users total creds
2103
- * Returns the users total creds unformated. If no total is fuond,
2104
- * the users current balance is returned instead.
2105
- *
2106
- * @param $user_id (int), required user id
2107
- * @param $type (string), optional cred type to check for
2108
- * @returns zero if user id is not set or if no total were found, else returns creds
2109
- * @since 1.2
2110
- * @version 1.3.1
2111
- */
2112
- if ( ! function_exists( 'mycred_get_users_total' ) ) :
2113
- function mycred_get_users_total( $user_id = '', $type = MYCRED_DEFAULT_TYPE_KEY ) {
2114
-
2115
- if ( $user_id == '' ) return 0;
2116
-
2117
- $mycred = mycred( $type );
2118
- $total = mycred_get_user_meta( $user_id, $type, '_total' );
2119
-
2120
- if ( $total == '' ) {
2121
- $total = mycred_query_users_total( $user_id, $type );
2122
- mycred_update_user_meta( $user_id, $type, '_total', $total );
2123
- }
2124
-
2125
- $total = apply_filters( 'mycred_get_users_total', $total, $user_id, $type );
2126
- return $mycred->number( $total );
2127
-
2128
- }
2129
- endif;
2130
-
2131
- /**
2132
- * Query Users Total
2133
- * Queries the database for the users total acculimated points.
2134
- *
2135
- * @param $user_id (int), required user id
2136
- * @param $type (string), required point type
2137
- * @since 1.4.7
2138
- * @version 1.1.2
2139
- */
2140
- if ( ! function_exists( 'mycred_query_users_total' ) ) :
2141
- function mycred_query_users_total( $user_id, $point_type = MYCRED_DEFAULT_TYPE_KEY ) {
2142
-
2143
- if ( ! MYCRED_ENABLE_LOGGING ) return 0;
2144
-
2145
- if ( ! mycred_point_type_exists( $point_type ) )
2146
- $point_type = MYCRED_DEFAULT_TYPE_KEY;
2147
-
2148
- global $wpdb, $mycred;
2149
-
2150
- $total = $wpdb->get_var( $wpdb->prepare( "
2151
- SELECT SUM( creds )
2152
- FROM {$mycred->log_table}
2153
- WHERE user_id = %d
2154
- AND ( ( creds > 0 ) OR ( creds < 0 AND ref = 'manual' ) )
2155
- AND ctype = %s;", $user_id, $point_type ) );
2156
-
2157
- if ( $total === NULL ) {
2158
-
2159
- $total = $wpdb->get_var( $wpdb->prepare( "
2160
- SELECT meta_value
2161
- FROM {$wpdb->usermeta}
2162
- WHERE user_id = %d
2163
- AND meta_key = %s;", $user_id, mycred_get_meta_key( $point_type ) ) );
2164
-
2165
- if ( $total === NULL )
2166
- $total = 0;
2167
-
2168
- }
2169
-
2170
- return apply_filters( 'mycred_query_users_total', $total, $user_id, $point_type );
2171
-
2172
- }
2173
- endif;
2174
-
2175
- /**
2176
- * Get All References
2177
- * Returns an array of references currently existing in the log
2178
- * for a particular point type. Will return false if empty.
2179
- * @since 1.5
2180
- * @version 1.3.2
2181
- */
2182
- if ( ! function_exists( 'mycred_get_all_references' ) ) :
2183
- function mycred_get_all_references() {
2184
-
2185
- // Hooks
2186
- $hooks = array(
2187
- 'registration' => __( 'Website Registration', 'mycred' ),
2188
- 'site_visit' => __( 'Website Visit', 'mycred' ),
2189
- 'view_content' => __( 'Viewing Content (Member)', 'mycred' ),
2190
- 'view_content_author' => __( 'Viewing Content (Author)', 'mycred' ),
2191
- 'logging_in' => __( 'Logging in', 'mycred' ),
2192
- 'publishing_content' => __( 'Publishing Content', 'mycred' ),
2193
- 'approved_comment' => __( 'Approved Comment', 'mycred' ),
2194
- 'unapproved_comment' => __( 'Unapproved Comment', 'mycred' ),
2195
- 'spam_comment' => __( 'SPAM Comment', 'mycred' ),
2196
- 'deleted_comment' => __( 'Deleted Comment', 'mycred' ),
2197
- 'link_click' => __( 'Link Click', 'mycred' ),
2198
- 'watching_video' => __( 'Watching Video', 'mycred' ),
2199
- 'visitor_referral' => __( 'Visitor Referral', 'mycred' ),
2200
- 'signup_referral' => __( 'Signup Referral', 'mycred' )
2201
- );
2202
-
2203
- if ( class_exists( 'BuddyPress' ) ) {
2204
- $hooks['new_profile_update'] = __( 'New Profile Update', 'mycred' );
2205
- $hooks['deleted_profile_update'] = __( 'Profile Update Removal', 'mycred' );
2206
- $hooks['upload_avatar'] = __( 'Avatar Upload', 'mycred' );
2207
- $hooks['upload_cover'] = __( 'Profile Cover Upload', 'mycred' );
2208
- $hooks['new_friendship'] = __( 'New Friendship', 'mycred' );
2209
- $hooks['ended_friendship'] = __( 'Ended Friendship', 'mycred' );
2210
- $hooks['new_comment'] = __( 'New Profile Comment', 'mycred' );
2211
- $hooks['comment_deletion'] = __( 'Profile Comment Deletion', 'mycred' );
2212
- $hooks['fave_activity'] = __( 'Add Activity to Favorites', 'mycred' );
2213
- $hooks['unfave_activity'] = __( 'Remove Activity from Favorites', 'mycred' );
2214
- $hooks['new_message'] = __( 'New Message', 'mycred' );
2215
- $hooks['sending_gift'] = __( 'Sending Gift', 'mycred' );
2216
- $hooks['creation_of_new_group'] = __( 'New Group', 'mycred' );
2217
- $hooks['deletion_of_group'] = __( 'Deleted Group', 'mycred' );
2218
- $hooks['new_group_forum_topic'] = __( 'New Group Forum Topic', 'mycred' );
2219
- $hooks['edit_group_forum_topic'] = __( 'Edit Group Forum Topic', 'mycred' );
2220
- $hooks['new_group_forum_post'] = __( 'New Group Forum Post', 'mycred' );
2221
- $hooks['edit_group_forum_post'] = __( 'Edit Group Forum Post', 'mycred' );
2222
- $hooks['joining_group'] = __( 'Joining Group', 'mycred' );
2223
- $hooks['leaving_group'] = __( 'Leaving Group', 'mycred' );
2224
- $hooks['upload_group_avatar'] = __( 'New Group Avatar', 'mycred' );
2225
- $hooks['upload_group_cover'] = __( 'New Group Cover', 'mycred' );
2226
- $hooks['new_group_comment'] = __( 'New Group Comment', 'mycred' );
2227
- }
2228
-
2229
- if ( function_exists( 'bpa_init' ) || function_exists( 'bpgpls_init' ) ) {
2230
- $hooks['photo_upload'] = __( 'Photo Upload', 'mycred' );
2231
- $hooks['video_upload'] = __( 'Video Upload', 'mycred' );
2232
- $hooks['music_upload'] = __( 'Music Upload', 'mycred' );
2233
- }
2234
-
2235
- if ( function_exists( 'bp_links_setup_root_component' ) ) {
2236
- $hooks['new_link'] = __( 'New Link', 'mycred' );
2237
- $hooks['link_voting'] = __( 'Link Voting', 'mycred' );
2238
- $hooks['update_link'] = __( 'Link Update', 'mycred' );
2239
- }
2240
-
2241
- if ( class_exists( 'bbPress' ) ) {
2242
- $hooks['new_forum'] = __( 'New Forum (bbPress)', 'mycred' );
2243
- $hooks['new_forum_topic'] = __( 'New Forum Topic (bbPress)', 'mycred' );
2244
- $hooks['topic_favorited'] = __( 'Favorited Topic (bbPress)', 'mycred' );
2245
- $hooks['new_forum_reply'] = __( 'New Topic Reply (bbPress)', 'mycred' );
2246
- }
2247
-
2248
- if ( function_exists( 'wpcf7' ) )
2249
- $hooks['contact_form_submission'] = __( 'Form Submission (Contact Form 7)', 'mycred' );
2250
-
2251
- if ( class_exists( 'GFForms' ) )
2252
- $hooks['gravity_form_submission'] = __( 'Form Submission (Gravity Form)', 'mycred' );
2253
-
2254
- if ( defined( 'SFTOPICS' ) ) {
2255
- $hooks['new_forum_topic'] = __( 'New Forum Topic (SimplePress)', 'mycred' );
2256
- $hooks['new_topic_post'] = __( 'New Forum Post (SimplePress)', 'mycred' );
2257
- }
2258
-
2259
- if ( function_exists( 'install_ShareThis' ) ) {
2260
- $share = mycred_get_share_service_names();
2261
- $hooks = array_merge_recursive( $share, $hooks );
2262
- }
2263
-
2264
- if ( class_exists( 'Affiliate_WP' ) ) {
2265
- $hooks['affiliate_signup'] = __( 'Affiliate Signup (AffiliateWP)', 'mycred' );
2266
- $hooks['affiliate_visit_referral'] = __( 'Referred Visit (AffiliateWP)', 'mycred' );
2267
- $hooks['affiliate_referral'] = __( 'Affiliate Referral (AffiliateWP)', 'mycred' );
2268
- $hooks['affiliate_referral_refund'] = __( 'Referral Refund (AffiliateWP)', 'mycred' );
2269
- }
2270
-
2271
- if ( defined( 'WP_POSTRATINGS_VERSION' ) ) {
2272
- $hooks['post_rating'] = __( 'Adding a Rating', 'mycred' );
2273
- $hooks['post_rating_author'] = __( 'Receiving a Rating', 'mycred' );
2274
- }
2275
-
2276
- if ( function_exists( 'vote_poll' ) )
2277
- $hooks['poll_voting'] = __( 'Poll Voting', 'mycred' );
2278
-
2279
- if ( function_exists( 'invite_anyone_init' ) ) {
2280
- $hooks['sending_an_invite'] = __( 'Sending an Invite', 'mycred' );
2281
- $hooks['accepting_an_invite'] = __( 'Accepting an Invite', 'mycred' );
2282
- }
2283
-
2284
- // Addons
2285
- $addons = array();
2286
- if ( class_exists( 'myCRED_Banking_Module' ) ) {
2287
- $addons['interest'] = __( 'Compound Interest', 'mycred' );
2288
- $addons['recurring'] = __( 'Recurring Payout', 'mycred' );
2289
- }
2290
-
2291
- if ( class_exists( 'myCRED_Badge_Module' ) )
2292
- $hooks['badge_reward'] = __( 'Badge Reward', 'mycred' );
2293
-
2294
- if ( class_exists( 'myCRED_buyCRED_Module' ) ) {
2295
- $addons['buy_creds_with_paypal_standard'] = __( 'buyCRED Purchase (PayPal Standard)', 'mycred' );
2296
- $addons['buy_creds_with_skrill'] = __( 'buyCRED Purchase (Skrill)', 'mycred' );
2297
- $addons['buy_creds_with_zombaio'] = __( 'buyCRED Purchase (Zombaio)', 'mycred' );
2298
- $addons['buy_creds_with_netbilling'] = __( 'buyCRED Purchase (NETBilling)', 'mycred' );
2299
- $addons['buy_creds_with_bitpay'] = __( 'buyCRED Purchase (BitPay)', 'mycred' );
2300
- $addons['buy_creds_with_bank'] = __( 'buyCRED Purchase (Bank Transfer)', 'mycred' );
2301
- $addons = apply_filters( 'mycred_buycred_refs', $addons );
2302
- }
2303
-
2304
- if ( class_exists( 'myCRED_Coupons_Module' ) )
2305
- $addons['coupon'] = __( 'Coupon Usage', 'mycred' );
2306
-
2307
- if ( defined( 'myCRED_GATE' ) ) {
2308
- if ( class_exists( 'WooCommerce' ) ) {
2309
- $addons['woocommerce_payment'] = __( 'Store Purchase (WooCommerce)', 'mycred' );
2310
- $addons['reward'] = __( 'Store Reward (WooCommerce)', 'mycred' );
2311
- $addons['product_review'] = __( 'Product Review (WooCommerce)', 'mycred' );
2312
- }
2313
- if ( class_exists( 'MarketPress' ) ) {
2314
- $addons['marketpress_payment'] = __( 'Store Purchase (MarketPress)', 'mycred' );
2315
- $addons['marketpress_reward'] = __( 'Store Reward (MarketPress)', 'mycred' );
2316
- }
2317
- if ( class_exists( 'wpsc_merchant' ) )
2318
- $addons['wpecom_payment'] = __( 'Store Purchase (WP E-Commerce)', 'mycred' );
2319
-
2320
- $addons = apply_filters( 'mycred_gateway_refs', $addons );
2321
- }
2322
-
2323
- if ( defined( 'EVENT_ESPRESSO_VERSION' ) ) {
2324
- $addons['event_payment'] = __( 'Event Payment (Event Espresso)', 'mycred' );
2325
- $addons['event_sale'] = __( 'Event Sale (Event Espresso)', 'mycred' );
2326
- }
2327
-
2328
- if ( defined( 'EM_VERSION' ) ) {
2329
- $addons['ticket_purchase'] = __( 'Event Payment (Events Manager)', 'mycred' );
2330
- $addons['ticket_sale'] = __( 'Event Sale (Events Manager)', 'mycred' );
2331
- }
2332
-
2333
- if ( class_exists( 'myCRED_Sell_Content_Module' ) ) {
2334
- $addons['buy_content'] = __( 'Content Purchase', 'mycred' );
2335
- $addons['sell_content'] = __( 'Content Sale', 'mycred' );
2336
- }
2337
-
2338
- if ( class_exists( 'myCRED_Transfer_Module' ) )
2339
- $addons['transfer'] = __( 'Transfer', 'mycred' );
2340
-
2341
- $references = array_merge( $hooks, $addons );
2342
-
2343
- $references['manual'] = __( 'Manual Adjustment by Admin', 'mycred' );
2344
-
2345
- return apply_filters( 'mycred_all_references', $references );
2346
-
2347
- }
2348
- endif;
2349
-
2350
- /**
2351
- * Get Used References
2352
- * Returns an array of references currently existing in the log
2353
- * for a particular point type. Will return false if empty.
2354
- * @since 1.5
2355
- * @version 1.0.1
2356
- */
2357
- if ( ! function_exists( 'mycred_get_used_references' ) ) :
2358
- function mycred_get_used_references( $point_type = array() ) {
2359
-
2360
- global $wpdb, $mycred;
2361
-
2362
- $query = "SELECT DISTINCT ref FROM {$mycred->log_table} WHERE ref != ''";
2363
- if ( ! empty( $point_type ) )
2364
- $query .= $wpdb->prepare( " AND ctype IN ( %s" . str_repeat( ",%s", ( count( $point_type ) - 1 ) ) . " )", $point_type );
2365
-
2366
- $references = $wpdb->get_col( $query );
2367
-
2368
- return apply_filters( 'mycred_used_references', $references, $point_type );
2369
-
2370
- }
2371
- endif;
2372
-
2373
- /**
2374
- * Get Used Log Entry Count
2375
- * @since 1.7
2376
- * @version 1.0
2377
- */
2378
- if ( ! function_exists( 'mycred_user_has_log_entries' ) ) :
2379
- function mycred_user_has_log_entries( $user_id = NULL ) {
2380
-
2381
- $user_id = absint( $user_id );
2382
- if ( $user_id === 0 ) return 0;
2383
-
2384
- $count = mycred_get_user_meta( $user_id, 'mycred-log-count' );
2385
- if ( $count == '' ) {
2386
-
2387
- global $wpdb, $mycred;
2388
-
2389
- $count = $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(*) FROM {$mycred->log_table} WHERE user_id = %d;", $user_id ) );
2390
- if ( $count === NULL ) $count = 0;
2391
-
2392
- mycred_add_user_meta( $user_id, 'mycred-log-count', '', $count, true );
2393
-
2394
- }
2395
-
2396
- return $count;
2397
-
2398
- }
2399
- endif;
2400
-
2401
- /**
2402
- * Count All Reference Instances
2403
- * Counts all the reference instances in the log returning the result
2404
- * in an assosiative array.
2405
- * @see http://codex.mycred.me/functions/mycred_count_all_ref_instances/
2406
- * @param $number (int) number of references to return. Defaults to 5. Use '-1' for all.
2407
- * @param $order (string) order to return ASC or DESC
2408
- * @filter mycred_count_all_refs
2409
- * @since 1.3.3
2410
- * @version 1.1.1
2411
- */
2412
- if ( ! function_exists( 'mycred_count_all_ref_instances' ) ) :
2413
- function mycred_count_all_ref_instances( $number = 5, $order = 'DESC', $type = MYCRED_DEFAULT_TYPE_KEY ) {
2414
-
2415
- global $wpdb;
2416
-
2417
- $results = array();
2418
- $mycred = mycred( $type );
2419
-
2420
- $limit = '';
2421
- if ( $number > 0 )
2422
- $limit = ' LIMIT 0,' . absint( $number );
2423
-
2424
- if ( ! in_array( $order, array( 'ASC', 'DESC' ) ) )
2425
- $order = 'DESC';
2426
-
2427
- if ( $type != 'all' )
2428
- $type = $wpdb->prepare( 'WHERE ctype = %s', $mycred->cred_id );
2429
-
2430
- else
2431
- $type = '';
2432
-
2433
- $query = $wpdb->get_results( "SELECT ref, COUNT(*) AS count FROM {$mycred->log_table} {$type} GROUP BY ref ORDER BY count {$order} {$limit};" );
2434
-
2435
- if ( $wpdb->num_rows > 0 ) {
2436
-
2437
- foreach ( $query as $num => $reference ) {
2438
-
2439
- $occurrence = $reference->count;
2440
- if ( $reference->ref == 'transfer' )
2441
- $occurrence = $occurrence/2;
2442
-
2443
- $results[ $reference->ref ] = $occurrence;
2444
-
2445
- }
2446
-
2447
- arsort( $results );
2448
-
2449
- }
2450
-
2451
- return apply_filters( 'mycred_count_all_refs', $results );
2452
-
2453
- }
2454
- endif;
2455
-
2456
- /**
2457
- * Count Reference Instances
2458
- * Counts the total number of occurrences of a specific reference for a user.
2459
- * @see http://codex.mycred.me/functions/mycred_count_ref_instances/
2460
- * @param $reference (string) required reference to check
2461
- * @param $user_id (int) option to check references for a specific user
2462
- * @uses get_var()
2463
- * @since 1.1
2464
- * @version 1.1
2465
- */
2466
- if ( ! function_exists( 'mycred_count_ref_instances' ) ) :
2467
- function mycred_count_ref_instances( $reference = '', $user_id = NULL, $type = MYCRED_DEFAULT_TYPE_KEY ) {
2468
-
2469
- if ( $reference == '' ) return 0;
2470
-
2471
- global $wpdb, $mycred;
2472
-
2473
- $wheres = array();
2474
- $wheres[] = $wpdb->prepare( "ref = %s", $reference );
2475
-
2476
- if ( $user_id !== NULL )
2477
- $wheres[] = $wpdb->prepare( "user_id = %d", $user_id );
2478
-
2479
- if ( mycred_point_type_exists( $type ) )
2480
- $wheres[] = $wpdb->prepare( "ctype = %s", $type );
2481
-
2482
- $wheres = implode( ' AND ', $wheres );
2483
-
2484
- $count = $wpdb->get_var( "SELECT COUNT(*) FROM {$mycred->log_table} WHERE {$wheres};" );
2485
- if ( $count === NULL ) $count = 0;
2486
-
2487
- return $count;
2488
-
2489
- }
2490
- endif;
2491
-
2492
- /**
2493
- * Count Reference ID Instances
2494
- * Counts the total number of occurrences of a specific reference combined with a reference ID for a user.
2495
- * @see http://codex.mycred.me/functions/mycred_count_ref_id_instances/
2496
- * @param $reference (string) required reference to check
2497
- * @param $user_id (int) option to check references for a specific user
2498
- * @uses get_var()
2499
- * @since 1.5.3
2500
- * @version 1.1
2501
- */
2502
- if ( ! function_exists( 'mycred_count_ref_id_instances' ) ) :
2503
- function mycred_count_ref_id_instances( $reference = '', $ref_id = NULL, $user_id = NULL, $type = MYCRED_DEFAULT_TYPE_KEY ) {
2504
-
2505
- if ( $reference == '' || $ref_id === NULL ) return 0;
2506
-
2507
- global $wpdb, $mycred;
2508
-
2509
- $wheres = array();
2510
- $wheres[] = $wpdb->prepare( "ref = %s", $reference );
2511
- $wheres[] = $wpdb->prepare( "ref_id = %d", $ref_id );
2512
-
2513
- if ( $user_id !== NULL )
2514
- $wheres[] = $wpdb->prepare( "user_id = %d", $user_id );
2515
-
2516
- if ( mycred_point_type_exists( $type ) )
2517
- $wheres[] = $wpdb->prepare( "ctype = %s", $type );
2518
-
2519
- $wheres = implode( ' AND ', $wheres );
2520
-
2521
- $count = $wpdb->get_var( "SELECT COUNT(*) FROM {$mycred->log_table} WHERE {$wheres};" );
2522
- if ( $count === NULL ) $count = 0;
2523
-
2524
- return $count;
2525
-
2526
- }
2527
- endif;
2528
-
2529
- /**
2530
- * Get Users Reference Count
2531
- * @since 1.7
2532
- * @version 1.0
2533
- */
2534
- if ( ! function_exists( 'mycred_get_users_reference_count' ) ) :
2535
- function mycred_get_users_reference_count( $user_id = NULL, $point_type = MYCRED_DEFAULT_TYPE_KEY ) {
2536
-
2537
- if ( $user_id === NULL ) return false;
2538
-
2539
- $references = (array) mycred_get_user_meta( $user_id, 'mycred_ref_counts-' . $point_type, '', true );
2540
- $references = maybe_unserialize( $references );
2541
-
2542
- if ( empty( $references ) ) {
2543
-
2544
- global $wpdb;
2545
-
2546
- $query = $wpdb->get_results( $wpdb->prepare( "SELECT COUNT(*) AS total, ref AS reference FROM {$mycred->log_table} WHERE user_id = %d AND ctype = %s GROUP BY ref ORDER BY total DESC;", $user_id, $point_type ) );
2547
- if ( ! empty( $query ) ) {
2548
- foreach ( $query as $result ) {
2549
- $references[ $result->reference ] = $result->total;
2550
- }
2551
- }
2552
-
2553
- mycred_update_user_meta( $user_id, 'mycred_ref_counts-' . $point_type, '', $references );
2554
-
2555
- }
2556
-
2557
- return $references;
2558
-
2559
- }
2560
- endif;
2561
-
2562
- /**
2563
- * Get Users Reference Sum
2564
- * @since 1.7
2565
- * @version 1.1
2566
- */
2567
- if ( ! function_exists( 'mycred_get_users_reference_sum' ) ) :
2568
- function mycred_get_users_reference_sum( $user_id = NULL, $point_type = MYCRED_DEFAULT_TYPE_KEY, $force = false ) {
2569
-
2570
- if ( $user_id === NULL ) return false;
2571
-
2572
- $references = (array) mycred_get_user_meta( $user_id, 'mycred_ref_sums-' . $point_type, '', true );
2573
- $references = maybe_unserialize( $references );
2574
-
2575
- if ( $force || empty( $references ) || empty( $references[0] ) ) {
2576
-
2577
- global $wpdb, $mycred_log_table;
2578
-
2579
- $query = $wpdb->get_results( $wpdb->prepare( "SELECT SUM(creds) AS total, ref AS reference FROM {$mycred_log_table} WHERE user_id = %d AND ctype = %s GROUP BY ref ORDER BY total DESC;", $user_id, $point_type ) );
2580
- if ( ! empty( $query ) ) {
2581
-
2582
- $references = array();
2583
- foreach ( $query as $result ) {
2584
- $references[ $result->reference ] = $result->total;
2585
- }
2586
-
2587
- mycred_update_user_meta( $user_id, 'mycred_ref_sums-' . $point_type, '', $references );
2588
-
2589
- }
2590
-
2591
- }
2592
-
2593
- return $references;
2594
-
2595
- }
2596
- endif;
2597
-
2598
- /**
2599
- * Get Search Args
2600
- * Converts URL arguments into an array of log query friendly arguments.
2601
- * @since 1.7
2602
- * @version 1.0.3
2603
- */
2604
- if ( ! function_exists( 'mycred_get_search_args' ) ) :
2605
- function mycred_get_search_args( $exclude = NULL ) {
2606
-
2607
- if ( $exclude === NULL )
2608
- $exclude = array( 'page', 'mycred-export', 'mycred-action', 'action', 'set', '_token' );
2609
-
2610
- $search_args = array();
2611
- if ( ! empty( $_GET ) ) {
2612
- foreach ( $_GET as $key => $value ) {
2613
-
2614
- $key = sanitize_key( $key );
2615
-
2616
- if ( $key === '' || in_array( $key, $exclude ) ) continue;
2617
-
2618
- if ( in_array( $key, array( 'user_id', 'paged', 'number' ) ) ) {
2619
- $value = absint( $value );
2620
- if ( $value === 0 ) continue;
2621
- }
2622
-
2623
- elseif ( $key == 'user' )
2624
- $value = mycred_get_user_id( $value );
2625
-
2626
- elseif ( is_array( $value ) ) {
2627
-
2628
- $temp = array();
2629
- if ( ! empty( $value ) ) {
2630
- foreach ( $value as $sub_key => $sub_value ) {
2631
- if ( ! is_array( $sub_value ) )
2632
- $temp[ $sub_key ] = sanitize_text_field( $sub_value );
2633
- else
2634
- $temp[ $sub_key ] = $sub_value;
2635
- }
2636
- }
2637
- $value = $temp;
2638
-
2639
- }
2640
-
2641
- else {
2642
- $value = sanitize_text_field( $value );
2643
- if ( strlen( $value ) == 0 ) continue;
2644
- }
2645
-
2646
- if ( $key === 'user' )
2647
- $key = 'user_id';
2648
-
2649
- elseif ( $key === 'show' )
2650
- $key = 'time';
2651
-
2652
- $search_args[ $key ] = $value;
2653
-
2654
- }
2655
- }
2656
-
2657
- if ( ! empty( $search_args ) ) {
2658
-
2659
- // Convert comma separated lists
2660
- if ( array_key_exists( 'time', $search_args ) && str_replace( ',', '', $search_args['time'] ) != $search_args['time'] ) {
2661
-
2662
- $timestamps = explode( ',', $search_args['time'] );
2663
- if ( count( $timestamps ) == 2 )
2664
- $search_args['time'] = array( 'dates' => $timestamps, 'compare' => 'BETWEEN' );
2665
- else
2666
- $search_args['time'] = array( 'dates' => $timestamps, 'compare' => 'IN' );
2667
-
2668
- }
2669
-
2670
- // Convert comma separated lists
2671
- if ( array_key_exists( 'ref', $search_args ) && str_replace( ',', '', $search_args['ref'] ) != $search_args['ref'] ) {
2672
-
2673
- $references = explode( ',', $search_args['ref'] );
2674
- if ( count( $references ) > 1 )
2675
- $search_args['ref'] = array( 'ids' => $references, 'compare' => 'IN' );
2676
-
2677
- }
2678
-
2679
- if ( array_key_exists( 'start', $search_args ) && array_key_exists( 'end', $search_args ) ) {
2680
- $search_args['amount'] = array( 'num' => array( $search_args['start'], $search_args['end'] ), 'compare' => 'BETWEEN' );
2681
- unset( $search_args['start'] );
2682
- unset( $search_args['end'] );
2683
- }
2684
-
2685
- elseif ( array_key_exists( 'num', $search_args ) && array_key_exists( 'compare', $search_args ) ) {
2686
- $search_args['amount'] = array( 'num' => $search_args['num'], 'compare' => urldecode( $search_args['compare'] ) );
2687
- unset( $search_args['num'] );
2688
- unset( $search_args['compare'] );
2689
- }
2690
-
2691
- }
2692
-
2693
- return $search_args;
2694
-
2695
- }
2696
- endif;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
includes/classes/index.php DELETED
@@ -1,3 +0,0 @@
1
- <?php
2
- // Silence is golden.
3
- ?>
 
 
 
includes/mycred-admin.php ADDED
@@ -0,0 +1,788 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ if ( ! defined( 'myCRED_VERSION' ) ) exit;
3
+
4
+ /**
5
+ * myCRED_Admin class
6
+ * Manages everything concerning the WordPress admin area.
7
+ * @since 0.1
8
+ * @version 1.2
9
+ */
10
+ if ( ! class_exists( 'myCRED_Admin' ) ) {
11
+ class myCRED_Admin {
12
+
13
+ public $core;
14
+ public $using_bp = false;
15
+
16
+ /**
17
+ * Construct
18
+ * @since 0.1
19
+ * @version 1.0
20
+ */
21
+ function __construct( $settings = array() ) {
22
+ $this->core = mycred();
23
+ }
24
+
25
+ /**
26
+ * Load
27
+ * @since 0.1
28
+ * @version 1.2
29
+ */
30
+ public function load() {
31
+ // Admin Styling
32
+ add_action( 'admin_head', array( $this, 'admin_header' ) );
33
+ add_action( 'admin_notices', array( $this, 'admin_notices' ) );
34
+
35
+ // Custom Columns
36
+ add_filter( 'manage_users_columns', array( $this, 'custom_user_column' ) );
37
+ add_action( 'manage_users_custom_column', array( $this, 'custom_user_column_content' ), 10, 3 );
38
+
39
+ // User Edit
40
+ global $bp;
41
+
42
+ // Check if BuddyPress is being used
43
+ if ( is_object( $bp ) && isset( $bp->version ) && version_compare( $bp->version, '2.0', '>=' ) && bp_is_active( 'xprofile' ) )
44
+ $this->using_bp = true;
45
+
46
+ // Edit Profile
47
+ if ( ! $this->using_bp )
48
+ add_action( 'edit_user_profile', array( $this, 'user_nav' ) );
49
+ else
50
+ add_action( 'bp_members_admin_profile_nav', array( $this, 'bp_user_nav' ), 10, 2 );
51
+
52
+ add_action( 'personal_options', array( $this, 'show_my_balance' ) );
53
+ add_filter( 'mycred_admin_pages', array( $this, 'edit_profile_menu' ) );
54
+ add_action( 'mycred_init', array( $this, 'edit_profile_actions' ) );
55
+
56
+ // Sortable Column
57
+ add_filter( 'manage_users_sortable_columns', array( $this, 'sortable_points_column' ) );
58
+ add_action( 'pre_user_query', array( $this, 'sort_by_points' ) );
59
+
60
+ // Inline Editing
61
+ add_action( 'wp_ajax_mycred-inline-edit-users-balance', array( $this, 'inline_edit_user_balance' ) );
62
+ add_action( 'in_admin_footer', array( $this, 'admin_footer' ) );
63
+ }
64
+
65
+ /**
66
+ * Profile Actions
67
+ * @since 1.5
68
+ * @version 1.0
69
+ */
70
+ public function edit_profile_actions() {
71
+
72
+ do_action( 'mycred_edit_profile_action' );
73
+
74
+ // Update Balance
75
+ if ( isset( $_POST['mycred_adjust_users_balance_run'] ) && isset( $_POST['mycred_adjust_users_balance'] ) ) {
76
+
77
+ extract( $_POST['mycred_adjust_users_balance'] );
78
+
79
+ if ( wp_verify_nonce( $token, 'mycred-adjust-balance' ) ) {
80
+
81
+ $ctype = sanitize_key( $ctype );
82
+ $mycred = mycred( $ctype );
83
+
84
+ // Enforce requirement for log entry
85
+ if ( $mycred->can_edit_creds() && ! $mycred->can_edit_plugin() && $log == '' ) {
86
+ wp_safe_redirect( add_query_arg( array( 'result' => 'log_error' ) ) );
87
+ exit;
88
+ }
89
+
90
+ // Make sure we can edit creds
91
+ if ( $mycred->can_edit_creds() ) {
92
+
93
+ // Prep
94
+ $user_id = absint( $user_id );
95
+ $amount = $mycred->number( $amount );
96
+ $data = apply_filters( 'mycred_manual_change', array( 'ref_type' => 'user' ), $this );
97
+
98
+ // Run
99
+ $mycred->add_creds(
100
+ 'manual',
101
+ $user_id,
102
+ $amount,
103
+ $log,
104
+ get_current_user_id(),
105
+ $data,
106
+ $ctype
107
+ );
108
+
109
+ wp_safe_redirect( add_query_arg( array( 'result' => 'balance_updated' ) ) );
110
+ exit;
111
+
112
+ }
113
+
114
+ }
115
+
116
+ }
117
+
118
+ // Exclude
119
+ elseif ( isset( $_GET['page'] ) && $_GET['page'] == 'mycred-edit-balance' && isset( $_GET['action'] ) && $_GET['action'] == 'exclude' ) {
120
+
121
+ $ctype = sanitize_key( $_GET['ctype'] );
122
+ $mycred = mycred( $ctype );
123
+
124
+ // Make sure we can edit creds
125
+ if ( $mycred->can_edit_creds() ) {
126
+
127
+ // Make sure user is not already excluded
128
+ $user_id = absint( $_GET['user_id'] );
129
+ if ( ! $mycred->exclude_user( $user_id ) ) {
130
+
131
+ // Get setttings
132
+ $options = $mycred->core;
133
+
134
+ // Get and clean up the exclude list
135
+ $excludes = explode( ',', $options['exclude']['list'] );
136
+ if ( ! empty( $excludes ) ) {
137
+ $_excludes = array();
138
+ foreach ( $excludes as $_user_id ) {
139
+ $_user_id = sanitize_key( $_user_id );
140
+ if ( $_user_id == '' ) continue;
141
+ $_excludes[] = absint( $_user_id );
142
+ }
143
+ $excludes = $_excludes;
144
+ }
145
+
146
+ // If user ID is not yet in list
147
+ if ( ! in_array( $user_id, $excludes ) ) {
148
+ $excludes[] = $user_id;
149
+ $options['exclude']['list'] = implode( ',', $excludes );
150
+
151
+ $option_id = 'mycred_pref_core';
152
+ if ( $ctype != 'mycred_default' )
153
+ $option_id .= '_' . $ctype;
154
+
155
+ mycred_update_option( $option_id, $options );
156
+
157
+ // Remove Users balance
158
+ mycred_delete_user_meta( $user_id, $ctype );
159
+
160
+ global $wpdb;
161
+
162
+ // Delete log entries
163
+ $wpdb->delete(
164
+ $mycred->log_table,
165
+ array( 'user_id' => $user_id, 'ctype' => $ctype ),
166
+ array( '%d', '%s' )
167
+ );
168
+
169
+ wp_safe_redirect( add_query_arg( array( 'user_id' => $user_id, 'result' => 'user_excluded' ), admin_url( 'user-edit.php' ) ) );
170
+ exit;
171
+ }
172
+
173
+ }
174
+
175
+ }
176
+
177
+ }
178
+
179
+ }
180
+
181
+ /**
182
+ * Admin Notices
183
+ * @since 1.4
184
+ * @version 1.1
185
+ */
186
+ public function admin_notices() {
187
+
188
+ // Manual Adjustments
189
+ if ( isset( $_GET['page'] ) && $_GET['page'] == 'mycred-edit-balance' && isset( $_GET['result'] ) ) {
190
+
191
+ if ( $_GET['result'] == 'log_error' )
192
+ echo '<div class="error"><p>' . __( 'A log entry is required in order to adjust this users balance', 'mycred' ) . '</p></div>';
193
+ elseif ( $_GET['result'] == 'balance_updated' )
194
+ echo '<div class="updated"><p>' . __( 'Users balance saved', 'mycred' ) . '</p></div>';
195
+
196
+ }
197
+
198
+ // Exclusions
199
+ elseif ( isset( $_GET['user_id'] ) && isset( $_GET['result'] ) ) {
200
+
201
+ if ( $_GET['result'] == 'user_excluded' )
202
+ echo '<div class="updated"><p>' . __( 'Users excluded', 'mycred' ) . '</p></div>';
203
+
204
+ }
205
+
206
+ if ( get_option( 'mycred_buycred_reset', false ) !== false )
207
+ echo '<div class="error"><p>' . __( 'All buyCRED Payment Gateways have been disabled! Please check your exchange rate settings and update all premium payment gateways!', 'mycred' ) . '</p></div>';
208
+
209
+ do_action( 'mycred_admin_notices' );
210
+
211
+ }
212
+
213
+ /**
214
+ * Ajax: Inline Edit Users Balance
215
+ * @since 1.2
216
+ * @version 1.1
217
+ */
218
+ public function inline_edit_user_balance() {
219
+ // Security
220
+ check_ajax_referer( 'mycred-update-users-balance', 'token' );
221
+
222
+ // Check current user
223
+ $current_user = get_current_user_id();
224
+ if ( ! mycred_is_admin( $current_user ) )
225
+ wp_send_json_error( 'ERROR_1' );
226
+
227
+ // Type
228
+ $type = sanitize_text_field( $_POST['type'] );
229
+
230
+ $mycred = mycred( $type );
231
+
232
+ // User
233
+ $user_id = abs( $_POST['user'] );
234
+ if ( $mycred->exclude_user( $user_id ) )
235
+ wp_send_json_error( array( 'error' => 'ERROR_2', 'message' => __( 'User is excluded', 'mycred' ) ) );
236
+
237
+ // Log entry
238
+ $entry = trim( $_POST['entry'] );
239
+ if ( $mycred->can_edit_creds() && ! $mycred->can_edit_plugin() && empty( $entry ) )
240
+ wp_send_json_error( array( 'error' => 'ERROR_3', 'message' => __( 'Log Entry can not be empty', 'mycred' ) ) );
241
+
242
+ // Amount
243
+ if ( $_POST['amount'] == 0 || empty( $_POST['amount'] ) )
244
+ wp_send_json_error( array( 'error' => 'ERROR_4', 'message' => __( 'Amount can not be zero', 'mycred' ) ) );
245
+ else
246
+ $amount = $mycred->number( $_POST['amount'] );
247
+
248
+ // Data
249
+ $data = apply_filters( 'mycred_manual_change', array( 'ref_type' => 'user' ), $this );
250
+
251
+ // Execute
252
+ $result = $mycred->add_creds(
253
+ 'manual',
254
+ $user_id,
255
+ $amount,
256
+ $entry,
257
+ $current_user,
258
+ $data,
259
+ $type
260
+ );
261
+
262
+ if ( $result !== false )
263
+ wp_send_json_success( $mycred->get_users_cred( $user_id, $type ) );
264
+ else
265
+ wp_send_json_error( array( 'error' => 'ERROR_5', 'message' => __( 'Failed to update this uses balance.', 'mycred' ) ) );
266
+ }
267
+
268
+ /**
269
+ * Admin Header
270
+ * @since 0.1
271
+ * @version 1.3
272
+ */
273
+ public function admin_header() {
274
+ global $wp_version;
275
+
276
+ // Old navigation menu
277
+ if ( version_compare( $wp_version, '3.8', '<' ) ) {
278
+ $image = plugins_url( 'assets/images/logo-menu.png', myCRED_THIS ); ?>
279
+
280
+ <!-- Support for pre 3.8 menus -->
281
+ <style type="text/css">
282
+ <?php foreach ( $mycred_types as $type => $label ) { if ( $mycred_type == 'mycred_default' ) $name = ''; else $name = '_' . $type; ?>
283
+ #adminmenu .toplevel_page_myCRED<?php echo $name; ?> div.wp-menu-image { background-image: url(<?php echo $image; ?>); background-position: 1px -28px; }
284
+ #adminmenu .toplevel_page_myCRED<?php echo $name; ?>:hover div.wp-menu-image,
285
+ #adminmenu .toplevel_page_myCRED<?php echo $name; ?>.current div.wp-menu-image,
286
+ #adminmenu .toplevel_page_myCRED<?php echo $name; ?> .wp-menu-open div.wp-menu-image { background-position: 1px 0; }
287
+ <?php } ?>
288
+ </style>
289
+ <?php
290
+ }
291
+
292
+ $screen = get_current_screen();
293
+ if ( $screen->id == 'users' ) {
294
+ wp_enqueue_script( 'mycred-inline-edit' );
295
+ wp_enqueue_style( 'mycred-inline-edit' );
296
+ }
297
+ }
298
+
299
+ /**
300
+ * Customize Users Column Headers
301
+ * @since 0.1
302
+ * @version 1.1
303
+ */
304
+ public function custom_user_column( $columns ) {
305
+ global $mycred_types;
306
+
307
+ if ( count( $mycred_types ) == 1 )
308
+ $columns['mycred_default'] = $this->core->plural();
309
+ else {
310
+ foreach ( $mycred_types as $type => $label ) {
311
+ if ( $type == 'mycred_default' ) $label = $this->core->plural();
312
+ $columns[ $type ] = $label;
313
+ }
314
+ }
315
+
316
+ return $columns;
317
+ }
318
+
319
+ /**
320
+ * Sortable User Column
321
+ * @since 1.2
322
+ * @version 1.1
323
+ */
324
+ public function sortable_points_column( $columns ) {
325
+ $mycred_types = mycred_get_types();
326
+
327
+ if ( count( $mycred_types ) == 1 )
328
+ $columns['mycred_default'] = 'mycred_default';
329
+ else {
330
+ foreach ( $mycred_types as $type => $label )
331
+ $columns[ $type ] = $type;
332
+ }
333
+
334
+ return $columns;
335
+ }
336
+
337
+ /**
338
+ * Sort by Points
339
+ * @since 1.2
340
+ * @version 1.3
341
+ */
342
+ public function sort_by_points( $query ) {
343
+ if ( ! is_admin() || ( defined( 'DOING_AJAX' ) && DOING_AJAX ) || ! function_exists( 'get_current_screen' ) ) return;
344
+ $screen = get_current_screen();
345
+ if ( $screen === NULL || $screen->id != 'users' ) return;
346
+
347
+ if ( isset( $query->query_vars['orderby'] ) ) {
348
+ global $wpdb;
349
+
350
+ $mycred_types = mycred_get_types();
351
+ $cred_id = $query->query_vars['orderby'];
352
+
353
+ $order = 'ASC';
354
+ if ( isset( $query->query_vars['order'] ) )
355
+ $order = $query->query_vars['order'];
356
+
357
+ $mycred = $this->core;
358
+ if ( isset( $_REQUEST['ctype'] ) && array_key_exists( $_REQUEST['ctype'], $mycred_types ) )
359
+ $mycred = mycred( $_REQUEST['ctype'] );
360
+
361
+ // Sort by only showing users with a particular point type
362
+ if ( $cred_id == 'balance' ) {
363
+
364
+ $amount = $mycred->zero();
365
+ if ( isset( $_REQUEST['amount'] ) )
366
+ $amount = $mycred->number( $_REQUEST['amount'] );
367
+
368
+ $query->query_from .= "
369
+ LEFT JOIN {$wpdb->usermeta}
370
+ ON ({$wpdb->users}.ID = {$wpdb->usermeta}.user_id AND {$wpdb->usermeta}.meta_key = '{$mycred->cred_id}')";
371
+
372
+ $query->query_where .= " AND meta_value = {$amount}";
373
+
374
+ }
375
+
376
+ // Sort a particular point type
377
+ elseif ( array_key_exists( $cred_id, $mycred_types ) ) {
378
+
379
+ $query->query_from .= "
380
+ LEFT JOIN {$wpdb->usermeta}
381
+ ON ({$wpdb->users}.ID = {$wpdb->usermeta}.user_id AND {$wpdb->usermeta}.meta_key = '{$cred_id}')";
382
+
383
+ $query->query_orderby = "ORDER BY {$wpdb->usermeta}.meta_value+0 {$order} ";
384
+
385
+ }
386
+
387
+ }
388
+ }
389
+
390
+ /**
391
+ * Customize User Columns Content
392
+ * @filter 'mycred_user_row_actions'
393
+ * @since 0.1
394
+ * @version 1.3.2
395
+ */
396
+ public function custom_user_column_content( $value, $column_name, $user_id ) {
397
+ global $mycred_types;
398
+
399
+ if ( ! array_key_exists( $column_name, $mycred_types ) ) return $value;
400
+
401
+ $mycred = mycred( $column_name );
402
+
403
+ // User is excluded
404
+ if ( $mycred->exclude_user( $user_id ) === true ) return __( 'Excluded', 'mycred' );
405
+
406
+ $user = get_userdata( $user_id );
407
+
408
+ // Show balance
409
+ $ubalance = $mycred->get_users_cred( $user_id, $column_name );
410
+ $balance = '<div id="mycred-user-' . $user_id . '-balance-' . $column_name . '">' . $mycred->before . ' <span>' . $mycred->format_number( $ubalance ) . '</span> ' . $mycred->after . '</div>';
411
+
412
+ // Show total
413
+ $total = mycred_query_users_total( $user_id, $column_name );
414
+ $balance .= '<small style="display:block;">' . sprintf( __( 'Total: %s', 'mycred' ), $mycred->format_number( $total ) ) . '</small>';
415
+
416
+ $page = 'myCRED';
417
+ if ( $column_name != 'mycred_default' )
418
+ $page .= '_' . $column_name;
419
+
420
+ // Row actions
421
+ $row = array();
422
+ $row['history'] = '<a href="' . admin_url( 'admin.php?page=' . $page . '&user_id=' . $user_id ) . '">' . __( 'History', 'mycred' ) . '</a>';
423
+ $row['adjust'] = '<a href="javascript:void(0)" class="mycred-open-points-editor" data-userid="' . $user_id . '" data-current="' . $ubalance . '" data-type="' . $column_name . '" data-username="' . $user->display_name . '">' . __( 'Adjust', 'mycred' ) . '</a>';
424
+
425
+ $rows = apply_filters( 'mycred_user_row_actions', $row, $user_id, $mycred );
426
+ $balance .= $this->row_actions( $rows );
427
+
428
+ return $balance;
429
+ }
430
+
431
+ /**
432
+ * User Row Actions
433
+ * @since 1.5
434
+ * @version 1.0
435
+ */
436
+ public function row_actions( $actions, $always_visible = false ) {
437
+ $action_count = count( $actions );
438
+ $i = 0;
439
+
440
+ if ( !$action_count )
441
+ return '';
442
+
443
+ $out = '<div class="' . ( $always_visible ? 'row-actions-visible' : 'row-actions' ) . '">';
444
+ foreach ( $actions as $action => $link ) {
445
+ ++$i;
446
+ ( $i == $action_count ) ? $sep = '' : $sep = ' | ';
447
+ $out .= "<span class='$action'>$link$sep</span>";
448
+ }
449
+ $out .= '</div>';
450
+
451
+ return $out;
452
+ }
453
+
454
+ /**
455
+ * Add Admin Page
456
+ * @since 1.5
457
+ * @version 1.0
458
+ */
459
+ public function edit_profile_menu( $pages = array() ) {
460
+ $pages[] = add_users_page(
461
+ __( 'Edit Balance', 'mycred' ),
462
+ __( 'Edit Balance', 'mycred' ),
463
+ 'read',
464
+ 'mycred-edit-balance',
465
+ array( $this, 'edit_profile_screen' )
466
+ );
467
+ return $pages;
468
+ }
469
+
470
+ /**
471
+ * User Nav
472
+ * @since 1.5
473
+ * @version 1.0
474
+ */
475
+ public function user_nav( $user, $current = NULL ) {
476
+ $types = mycred_get_types();
477
+
478
+ $tabs = array();
479
+ $tabs[] = array(
480
+ 'label' => __( 'Profile', 'mycred' ),
481
+ 'url' => add_query_arg( array( 'user_id' => $user->ID ), admin_url( 'user-edit.php' ) ),
482
+ 'classes' => ( $current === NULL ) ? 'nav-tab nav-tab-active' : 'nav-tab'
483
+ );
484
+
485
+ if ( $this->using_bp )
486
+ $tabs[] = array(
487
+ 'label' => __( 'Extended Profile', 'mycred' ),
488
+ 'url' => add_query_arg( array( 'page' => 'bp-profile-edit', 'user_id' => $user->ID ), admin_url( 'users.php' ) ),
489
+ 'classes' => 'nav-tab'
490
+ );
491
+
492
+ foreach ( $types as $type => $label ) {
493
+ $mycred = mycred( $type );
494
+ if ( $mycred->exclude_user( $user->ID ) ) continue;
495
+
496
+ $classes = 'nav-tab';
497
+ if ( isset( $_GET['ctype'] ) && $_GET['ctype'] == $type ) $classes .= ' nav-tab-active';
498
+
499
+ $tabs[] = array(
500
+ 'label' => $mycred->plural(),
501
+ 'url' => add_query_arg( array( 'page' => 'mycred-edit-balance', 'user_id' => $user->ID, 'ctype' => $type ), admin_url( 'users.php' ) ),
502
+ 'classes' => $classes
503
+ );
504
+ }
505
+
506
+ $tabs = apply_filters( 'mycred_edit_profile_tabs', $tabs, $user, false );
507
+
508
+ ?>
509
+ <style type="text/css">
510
+ div#edit-balance-page.wrap form#your-profile, div#profile-page.wrap form#your-profile { position:relative; }
511
+ div#edit-balance-page.wrap form#your-profile h3:first-of-type { margin-top:3em; }
512
+ div#profile-page.wrap form#your-profile h3:first-of-type { margin-top:6em; }
513
+ div#edit-balance-page.wrap form#your-profile ul#profile-nav { border-bottom:solid 1px #ccc; width:100%; }
514
+ div#profile-page.wrap form#your-profile ul#profile-nav { position:absolute; top:-6em; border-bottom:solid 1px #ccc; width:100%; }
515
+ div#edit-balance-page ul#profile-nav { border-bottom:solid 1px #ccc; width:100%; margin-top:1em; margin-bottom:1em; padding:1em 0; padding-bottom: 0; height:2.4em; }
516
+ ul#profile-nav li { margin-left:0.4em; float:left;font-weight: bold;font-size: 15px;line-height: 24px;}
517
+ ul#profile-nav li a {text-decoration: none;color:#888;}
518
+ ul#profile-nav li a:hover, ul#profile-nav li.nav-tab-active a {text-decoration: none;color:#000; }
519
+ </style>
520
+ <ul id="profile-nav" class="nav-tab-wrapper">
521
+
522
+ <?php foreach ( $tabs as $tab ) echo '<li class="' . $tab['classes'] . '"><a href="' . $tab['url'] . '">' . $tab['label'] . '</a></li>'; ?>
523
+
524
+ </ul>
525
+ <?php
526
+ }
527
+
528
+ /**
529
+ * BuddyPress User Nav
530
+ * @since 1.5
531
+ * @version 1.0
532
+ */
533
+ public function bp_user_nav( $active, $user ) {
534
+ $types = mycred_get_types();
535
+
536
+ $tabs = array();
537
+ foreach ( $types as $type => $label ) {
538
+ $mycred = mycred( $type );
539
+ if ( $mycred->exclude_user( $user->ID ) ) continue;
540
+
541
+ $tabs[] = array(
542
+ 'label' => $mycred->plural(),
543
+ 'url' => add_query_arg( array( 'page' => 'mycred-edit-balance', 'user_id' => $user->ID, 'ctype' => $type ), admin_url( 'users.php' ) ),
544
+ 'classes' => 'nav-tab'
545
+ );
546
+ }
547
+
548
+ $tabs = apply_filters( 'mycred_edit_profile_tabs', $tabs, $user, true );
549
+
550
+ if ( ! empty( $tabs ) )
551
+ foreach ( $tabs as $tab ) echo '<li class="' . $tab['classes'] . '"><a href="' . $tab['url'] . '">' . $tab['label'] . '</a></li>';
552
+ }
553
+
554
+ /**
555
+ * Edit Profile Screen
556
+ * @since 1.5
557
+ * @version 1.0
558
+ */
559
+ public function edit_profile_screen() {
560
+ if ( ! isset( $_GET['user_id'] ) ) return;
561
+
562
+ $user_id = absint( $_GET['user_id'] );
563
+
564
+ if ( ! isset( $_GET['ctype'] ) )
565
+ $type = 'mycred_default';
566
+ else
567
+ $type = sanitize_key( $_GET['ctype'] );
568
+
569
+ $mycred = mycred( $type );
570
+
571
+ // Security
572
+ if ( ! $mycred->can_edit_creds() )
573
+ wp_die( __( 'Access Denied', 'mycred' ) );
574
+
575
+ // User is excluded
576
+ if ( $mycred->exclude_user( $user_id ) )
577
+ wp_die( sprintf( __( 'This user is excluded from using %s', 'mycred' ), mycred_label() ) );
578
+
579
+ $user = get_userdata( $user_id );
580
+ $balance = $mycred->get_users_balance( $user_id );
581
+
582
+ if ( $type == 'mycred_default' )
583
+ $log_slug = 'myCRED';
584
+ else
585
+ $log_slug = 'myCRED_' . $type;
586
+
587
+ $history_url = add_query_arg( array( 'page' => $log_slug, 'user_id' => $user->ID ), admin_url( 'admin.php' ) );
588
+ $exclude_url = add_query_arg( array( 'action' => 'exclude' ) ) ?>
589
+
590
+ <style type="text/css">
591
+ div#edit-balance-page table.table { width: 100%; margin-top: 24px; }
592
+ div#edit-balance-page table.table th { text-align: left; }
593
+ div#edit-balance-page table.table td { width: 33%; font-size: 24px; line-height: 48px; }
594
+ div#edit-balance-page table tr td table tr td { vertical-align: top; }
595
+ div#edit-balance-page table.form-table { border-top: 1px solid #ccc; }
596
+ div#edit-balance-page.wrap form#your-profile h3 { margin-top: 3em; }
597
+ </style>
598
+ <div class="wrap" id="edit-balance-page">
599
+ <h2><?php
600
+ _e( 'Edit User', 'mycred' );
601
+ if ( current_user_can( 'create_users' ) ) { ?>
602
+ <a href="user-new.php" class="add-new-h2"><?php echo esc_html_x( 'Add New', 'user', 'mycred' ); ?></a>
603
+ <?php } elseif ( is_multisite() && current_user_can( 'promote_users' ) ) { ?>
604
+ <a href="user-new.php" class="add-new-h2"><?php echo esc_html_x( 'Add Existing', 'user', 'mycred' ); ?></a>
605
+ <?php }
606
+ ?></h2>
607
+ <form id="your-profile" action="" method="post">
608
+ <?php echo $this->user_nav( $user, $type ); ?>
609
+
610
+ <div class="clear clearfix"></div>
611
+ <table class="table">
612
+ <thead>
613
+ <tr>
614
+ <th><?php _e( 'Current Balance', 'mycred' ); ?></th>
615
+ <th><?php printf( __( 'Total %s Accumulated', 'mycred' ), $mycred->plural() ); ?></th>
616
+ <th><?php printf( __( 'Total %s Spent', 'mycred' ), $mycred->plural() ); ?></th>
617
+ </tr>
618
+ </thead>
619
+ <tbody>
620
+ <tr>
621
+ <td><?php echo $mycred->format_creds( $balance ); ?></td>
622
+ <td><?php echo $mycred->format_creds( mycred_get_users_total( $user->ID, $type ) ); ?></td>
623
+ <td><?php echo $mycred->format_creds( $this->get_users_total_spent( $user->ID, $type ) ); ?></td>
624
+ </tr>
625
+ </tbody>
626
+ </table>
627
+ <a href="<?php echo $history_url; ?>" class="button button-secondary"><?php _e( 'View History', 'mycred' ); ?></a>
628
+ <a href="<?php echo $exclude_url; ?>" class="button button-primary" id="mycred-exclude-this-user"><?php _e( 'Exclude User', 'mycred' ); ?></a>
629
+
630
+ <?php do_action( 'mycred_before_edit_profile', $user, $type ); ?>
631
+
632
+ <h3><?php _e( 'Adjust Balance', 'mycred' ); ?></h3>
633
+ <?php $this->adjust_users_balance( $user ); ?>
634
+
635
+ <?php do_action( 'mycred_edit_profile', $user, $type ); ?>
636
+
637
+ </form>
638
+ <script type="text/javascript">
639
+ jQuery(function($) {
640
+ $( 'a#mycred-exclude-this-user' ).click(function(){
641
+ if ( ! confirm( '<?php _e( 'Warning! Excluding this user will result in their balance being deleted along with any entries currently in your log! This can not be undone!', 'mycred' ); ?>' ) )
642
+ return false;
643
+ });
644
+ });
645
+ </script>
646
+ </div>
647
+ <?php
648
+ }
649
+
650
+ /**
651
+ * Get Users Total Accumulated
652
+ * @since 1.5
653
+ * @version 1.0
654
+ */
655
+ public function get_users_total_accumulated( $user_id, $type ) {
656
+ global $wpdb;
657
+
658
+ return $wpdb->get_var( $wpdb->prepare( "
659
+ SELECT SUM( creds )
660
+ FROM {$this->core->log_table}
661
+ WHERE ctype = %s
662
+ AND user_id = %d
663
+ AND creds > 0;", $type, $user_id ) );
664
+ }
665
+
666
+ /**
667
+ * Get Users Total Spending
668
+ * @since 1.5
669
+ * @version 1.0
670
+ */
671
+ public function get_users_total_spent( $user_id, $type ) {
672
+ global $wpdb;
673
+
674
+ return $wpdb->get_var( $wpdb->prepare( "
675
+ SELECT SUM( creds )
676
+ FROM {$this->core->log_table}
677
+ WHERE ctype = %s
678
+ AND user_id = %d
679
+ AND creds < 0;", $type, $user_id ) );
680
+ }
681
+
682
+ /**
683
+ * Insert Ballance into Profile
684
+ * @since 0.1
685
+ * @version 1.1
686
+ */
687
+ public function show_my_balance( $user ) {
688
+ $user_id = $user->ID;
689
+ $mycred_types = mycred_get_types();
690
+
691
+ foreach ( $mycred_types as $type => $label ) {
692
+ $mycred = mycred( $type );
693
+ if ( $mycred->exclude_user( $user_id ) ) continue;
694
+
695
+ $balance = $mycred->get_users_cred( $user_id, $type );
696
+ $balance = $mycred->format_creds( $balance ); ?>
697
+
698
+ <tr>
699
+ <th scope="row"><?php echo $mycred->template_tags_general( __( '%singular% balance', 'mycred' ) ); ?></th>
700
+ <td><h2 style="margin:0;padding:0;"><?php echo $balance; ?></h2></td>
701
+ </tr>
702
+ <?php
703
+ }
704
+ }
705
+
706
+ /**
707
+ * Adjust Users Balance
708
+ * @since 0.1
709
+ * @version 1.2
710
+ */
711
+ public function adjust_users_balance( $user ) {
712
+ if ( ! isset( $_GET['ctype'] ) )
713
+ $type = 'mycred_default';
714
+ else
715
+ $type = sanitize_key( $_GET['ctype'] );
716
+
717
+ $mycred = mycred( $type );
718
+
719
+ if ( $mycred->can_edit_creds() && ! $mycred->can_edit_plugin() )
720
+ $req = '(<strong>' . __( 'required', 'mycred' ) . '</strong>)';
721
+ else
722
+ $req = '(' . __( 'optional', 'mycred' ) . ')'; ?>
723
+
724
+ <table class="form-table">
725
+ <tr>
726
+ <th scope="row"><label for="myCRED-manual-add-points"><?php _e( 'Amount', 'mycred' ) ?></label></th>
727
+ <td id="myCRED-adjust-users-points">
728
+ <input type="text" name="mycred_adjust_users_balance[amount]" id="myCRED-manual-add-points" value="<?php echo $mycred->zero(); ?>" size="8" />
729
+ <input type="hidden" name="mycred_adjust_users_balance[ctype]" value="<?php echo $type; ?>" />
730
+ <input type="hidden" name="mycred_adjust_users_balance[user_id]" value="<?php echo $user->ID; ?>" />
731
+ <input type="hidden" name="mycred_adjust_users_balance[token]" value="<?php echo wp_create_nonce( 'mycred-adjust-balance' ); ?>" />
732
+ </td>
733
+ </tr>
734
+ <tr>
735
+ <th scope="row"><label for="myCRED-manual-add-description"><?php _e( 'Log Entry', 'mycred' ); ?> <?php echo $req; ?></label></th>
736
+ <td>
737
+ <input type="text" name="mycred_adjust_users_balance[log]" id="myCRED-manual-add-description" value="" class="regular-text" /><br />
738
+ <span class="description"><?php echo $mycred->available_template_tags( array( 'general' ) ); ?></span><br /><br />
739
+ <?php submit_button( __( 'Update Balance', 'mycred' ), 'primary medium', 'mycred_adjust_users_balance_run', false ); ?>
740
+ </td>
741
+ </tr>
742
+ </table>
743
+ <?php
744
+ }
745
+
746
+ /**
747
+ * Admin Footer
748
+ * Inserts the Inline Edit Form modal.
749
+ * @since 1.2
750
+ * @version 1.2
751
+ */
752
+ public function admin_footer() {
753
+ $screen = get_current_screen();
754
+ if ( $screen->id != 'users' ) return;
755
+
756
+ if ( $this->core->can_edit_creds() && ! $this->core->can_edit_plugin() )
757
+ $req = '(<strong>' . __( 'required', 'mycred' ) . '</strong>)';
758
+ else
759
+ $req = '(' . __( 'optional', 'mycred' ) . ')';
760
+
761
+ ob_start(); ?>
762
+
763
+ <div id="edit-mycred-balance" style="display: none;">
764
+ <div class="mycred-adjustment-form">
765
+ <p class="row inline" style="width: 20%"><label><?php _e( 'ID', 'mycred' ); ?>:</label><span id="mycred-userid"></span></p>
766
+ <p class="row inline" style="width: 40%"><label><?php _e( 'User', 'mycred' ); ?>:</label><span id="mycred-username"></span></p>
767
+ <p class="row inline" style="width: 40%"><label><?php _e( 'Current Balance', 'mycred' ); ?>:</label> <span id="mycred-current"></span></p>
768
+ <div class="clear"></div>
769
+ <input type="hidden" name="mycred_update_users_balance[token]" id="mycred-update-users-balance-token" value="<?php echo wp_create_nonce( 'mycred-update-users-balance' ); ?>" />
770
+ <input type="hidden" name="mycred_update_users_balance[type]" id="mycred-update-users-balance-type" value="" />
771
+ <p class="row"><label for="mycred-update-users-balance-amount"><?php _e( 'Amount', 'mycred' ); ?>:</label><input type="text" name="mycred_update_users_balance[amount]" id="mycred-update-users-balance-amount" value="" /><br /><span class="description"><?php _e( 'A positive or negative value', 'mycred' ); ?>.</span></p>
772
+ <p class="row"><label for="mycred-update-users-balance-entry"><?php _e( 'Log Entry', 'mycred' ); ?>:</label><input type="text" name="mycred_update_users_balance[entry]" id="mycred-update-users-balance-entry" value="" /><br /><span class="description"><?php echo $req; ?></span></p>
773
+ <p class="row"><input type="button" name="mycred-update-users-balance-submit" id="mycred-update-users-balance-submit" value="<?php _e( 'Update Balance', 'mycred' ); ?>" class="button button-primary button-large" /></p>
774
+ <div class="clear"></div>
775
+ </div>
776
+ <div class="clear"></div>
777
+ </div>
778
+ <?php
779
+
780
+ $content = ob_get_contents();
781
+ ob_end_clean();
782
+
783
+ echo apply_filters( 'mycred_admin_inline_editor', $content );
784
+
785
+ }
786
+ }
787
+ }
788
+ ?>
includes/mycred-depreciated.php ADDED
@@ -0,0 +1,356 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ if ( ! defined( 'myCRED_VERSION' ) ) exit;
3
+
4
+ // _deprecated_function( __FUNCTION__, '1.5.1', 'get_post()' );
5
+
6
+ /**
7
+ * Get Settings
8
+ * Returns myCRED's general settings.
9
+ * @since 0.1
10
+ * @version 1.0
11
+ */
12
+ if ( ! function_exists( 'mycred_get_settings' ) ) :
13
+ function mycred_get_settings()
14
+ {
15
+ _deprecated_function( 'mycred_get_settings()', '1.4', 'mycred()' );
16
+
17
+ return mycred();
18
+ }
19
+ endif;
20
+
21
+ /**
22
+ * myCRED Query Rankings Class
23
+ * @see http://codex.mycred.me/classes/mycred_query_rankings/
24
+ * @since 1.1.2
25
+ * @version 1.1
26
+ */
27
+ if ( ! class_exists( 'myCRED_Query_Rankings' ) ) {
28
+ class myCRED_Query_Rankings {
29
+
30
+ public $args;
31
+ public $count = 0;
32
+ public $result;
33
+
34
+ /**
35
+ * Constructor
36
+ */
37
+ public function __construct( $args = '' ) {
38
+ $this->args = shortcode_atts( array(
39
+ 'number' => '-1',
40
+ 'order' => 'DESC',
41
+ 'user_fields' => 'user_login,display_name,user_email,user_nicename,user_url',
42
+ 'offset' => 0,
43
+ 'zero' => 1,
44
+ 'type' => 'mycred_default'
45
+ ), $args );
46
+ }
47
+
48
+ /**
49
+ * Have Results
50
+ * @returns true or false
51
+ * @since 1.1.2
52
+ * @version 1.0
53
+ */
54
+ public function have_results() {
55
+ if ( !empty( $this->result ) ) return true;
56
+
57
+ return false;
58
+ }
59
+
60
+ /**
61
+ * Get Rankings
62
+ * Queries the DB for all users in order of their point balance.
63
+ * @since 1.1.2
64
+ * @version 1.0.2
65
+ */
66
+ public function get_rankings() {
67
+ global $wpdb;
68
+
69
+ // Type can not be empty
70
+ if ( !empty( $this->args['type'] ) )
71
+ $key = $this->args['type'];
72
+ else
73
+ $key = 'mycred_default';
74
+
75
+ // Order
76
+ if ( !empty( $this->args['order'] ) )
77
+ $order = $this->args['order'];
78
+ else
79
+ $order = 'DESC';
80
+
81
+ // Number
82
+ if ( $this->args['number'] != '-1' )
83
+ $limit = 'LIMIT ' . abs( $this->args['offset'] ) . ',' . abs( $this->args['number'] );
84
+ else
85
+ $limit = '';
86
+
87
+ // User fields
88
+ if ( empty( $this->args['user_fields'] ) )
89
+ $this->args['user_fields'] = 'display_name,user_login';
90
+
91
+ $user_fields = trim( $this->args['user_fields'] );
92
+ $user_fields = str_replace( ' ', '', $user_fields );
93
+ $user_fields = explode( ',', $user_fields );
94
+
95
+ // SELECT
96
+ $selects = array( "{$wpdb->users}.ID" );
97
+ foreach ( $user_fields as $field ) {
98
+ if ( $field == 'ID' ) continue;
99
+ $selects[] = "{$wpdb->users}." . $field;
100
+ }
101
+ $selects[] = "{$wpdb->usermeta}.meta_value AS cred";
102
+ $select = implode( ', ', $selects );
103
+
104
+ // WHERE
105
+ $where = '';
106
+ if ( $this->args['zero'] )
107
+ $where = "WHERE {$wpdb->usermeta}.meta_value > 0 ";
108
+
109
+ $SQL = apply_filters( 'mycred_ranking_sql', "
110
+ SELECT {$select}
111
+ FROM {$wpdb->users}
112
+ LEFT JOIN {$wpdb->usermeta}
113
+ ON {$wpdb->users}.ID = {$wpdb->usermeta}.user_id
114
+ AND {$wpdb->usermeta}.meta_key = %s
115
+ {$where}
116
+ ORDER BY {$wpdb->usermeta}.meta_value+1 {$order} {$limit};", $this->args, $wpdb );
117
+
118
+ $this->result = $wpdb->get_results( $wpdb->prepare( $SQL, $key ), 'ARRAY_A' );
119
+ $this->count = $wpdb->num_rows;
120
+ }
121
+
122
+ /**
123
+ * Save
124
+ * With the option to reset and bypass any set frequency.
125
+ * If a frequency is set to something other then 'always', then that
126
+ * setting is enforced.
127
+ * @since 1.1.2
128
+ * @version 1.0
129
+ */
130
+ public function save( $reset = false ) {
131
+
132
+ }
133
+ }
134
+ }
135
+
136
+ /**
137
+ * myCRED_Rankings class
138
+ * @see http://codex.mycred.me/classes/mycred_rankings/
139
+ * @since 0.1
140
+ * @version 2.0
141
+ */
142
+ if ( !class_exists( 'myCRED_Rankings' ) ) {
143
+ class myCRED_Rankings {
144
+
145
+ public $core;
146
+ public $args;
147
+ public $result;
148
+
149
+ /**
150
+ * Constructor
151
+ */
152
+ public function __construct( $args = array(), $results = array() ) {
153
+ // Get settings
154
+ $mycred = mycred();
155
+ $this->core = $mycred;
156
+ $this->args = $args;
157
+ $this->result = $results;
158
+ }
159
+
160
+ /**
161
+ * Have Results
162
+ * @returns true or false
163
+ * @since 0.1
164
+ * @version 1.1
165
+ */
166
+ public function have_results() {
167
+ if ( !empty( $this->result ) ) return true;
168
+ return false;
169
+ }
170
+
171
+ /**
172
+ * Users Position
173
+ * @param $user_id (int) required user id
174
+ * @returns position (int)
175
+ * @since 0.1
176
+ * @version 1.1
177
+ */
178
+ public function users_position( $user_id = NULL ) {
179
+ if ( $user_id !== NULL ) {
180
+ if ( $this->have_results() ) {
181
+ foreach ( $this->result as $row_id => $row_data ) {
182
+ if ( !isset( $row_data['ID'] ) ) $row_uid = $row_data['user_id'];
183
+ else $row_uid = $row_data['ID'];
184
+
185
+ if ( $row_uid == (int) $user_id ) return $row_id+1;
186
+ }
187
+ }
188
+ }
189
+
190
+ return 0;
191
+ }
192
+
193
+ /**
194
+ * Users Creds
195
+ * @param $user_id (int) user id
196
+ * @returns position (int) or empty
197
+ * @since 0.1
198
+ * @version 1.1
199
+ */
200
+ public function users_creds( $user_id = NULL ) {
201
+ if ( $user_id !== NULL ) {
202
+ if ( $this->have_results() ) {
203
+ foreach ( $this->result as $row_id => $row_data ) {
204
+ if ( !isset( $row_data['ID'] ) ) $row_uid = $row_data['user_id'];
205
+ else $row_uid = $row_data['ID'];
206
+
207
+ if ( $row_uid == (int) $user_id ) return $row_data['creds'];
208
+ }
209
+ }
210
+ }
211
+
212
+ return 0;
213
+ }
214
+
215
+ /**
216
+ * Leaderboard
217
+ * @since 0.1
218
+ * @version 1.0
219
+ */
220
+ public function leaderboard() {
221
+ echo $this->get_leaderboard();
222
+ }
223
+
224
+ /**
225
+ * Get Leaderboard
226
+ * @since 0.1
227
+ * @version 1.1
228
+ */
229
+ public function get_leaderboard() {
230
+ return '<ol class="myCRED-leaderboard">' . $this->loop( 'li' ) . '</ol>';
231
+ }
232
+
233
+ /**
234
+ * Leaderboard Loop
235
+ * @since 1.1.2
236
+ * @version 1.0.2
237
+ */
238
+ public function loop( $wrap = '' ) {
239
+ // Default template
240
+ if ( empty( $this->args['template'] ) ) $this->args['template'] = '#%ranking% %user_profile_link% %cred_f%';
241
+ $output = '';
242
+
243
+ // Loop
244
+ foreach ( $this->result as $position => $row ) {
245
+ // Prep
246
+ $class = array();
247
+
248
+ // Classes
249
+ $class[] = 'item-' . $position;
250
+ if ( $position == 0 )
251
+ $class[] = 'first-item';
252
+
253
+ if ( $position % 2 != 0 )
254
+ $class[] = 'alt';
255
+
256
+ // Template Tags
257
+ if ( !function_exists( 'mycred_get_users_rank' ) )
258
+ $layout = str_replace( array( '%rank%', '%ranking%' ), $position+1, $this->args['template'] );
259
+ else
260
+ $layout = str_replace( '%ranking%', $position+1, $this->args['template'] );
261
+
262
+ $layout = $this->core->template_tags_amount( $layout, $row['cred'] );
263
+ $layout = $this->core->template_tags_user( $layout, false, $row );
264
+
265
+ // Wrapper
266
+ if ( !empty( $wrap ) )
267
+ $layout = '<' . $wrap . ' class="%classes%">' . $layout . '</' . $wrap . '>';
268
+
269
+ $layout = str_replace( '%classes%', apply_filters( 'mycred_ranking_classes', implode( ' ', $class ) ), $layout );
270
+ $layout = apply_filters( 'mycred_ranking_row', $layout, $this->args['template'], $row, $position+1 );
271
+
272
+ $output .= $layout . "\n";
273
+ }
274
+
275
+ return $output;
276
+ }
277
+ }
278
+ }
279
+
280
+ /**
281
+ * Get myCRED Rankings
282
+ * Returns the myCRED_Rankings object containing results.
283
+ *
284
+ * @param $args (array) optional array of arguments for the ranking
285
+ * @var number (int) number of results to return
286
+ * @var order (string) ASC to return with lowest creds or DESC to return highest creds first
287
+ * @var user_fields (string) comma seperated list of table columns to return with each user.
288
+ * @var offset (int) optional number to start from when returning records. defaults to zero (first result)
289
+ * @var type (string) optional points type
290
+ * @var template (string) if this function is called to create a leaderboard this string can contain the template
291
+ * for each user
292
+ * @uses myCRED_Query_Rankings()
293
+ * @uses myCRED_Rankings()
294
+ * @returns class object
295
+ * @since 0.1
296
+ * @version 2.0
297
+ */
298
+ if ( !function_exists( 'mycred_rankings' ) ) {
299
+ function mycred_rankings( $args = array(), $reset = false )
300
+ {
301
+ $default = array(
302
+ 'number' => '-1',
303
+ 'order' => 'DESC',
304
+ 'user_fields' => 'user_login,display_name,user_email,user_nicename,user_url',
305
+ 'offset' => 0,
306
+ 'type' => 'mycred_default',
307
+ 'template' => '#%ranking% %user_profile_link% %cred_f%'
308
+ );
309
+ $args = shortcode_atts( $default, $args );
310
+ $diff = array_diff( $args, $default );
311
+
312
+ global $mycred_rankings;
313
+
314
+ $_rankings = get_transient( $args['type'] . '_ranking' );
315
+ // Transient is missing or request for reset
316
+ if ( false === $_rankings || true === $reset ) {
317
+ $ranking = new myCRED_Query_Rankings( array( 'type' => $args['type'] ) );
318
+ $ranking->get_rankings();
319
+ //$ranking->save( $reset );
320
+
321
+ $_rankings = $ranking->result;
322
+ }
323
+ // Else if arguments are not the default and a new query is required
324
+ elseif ( !empty( $diff ) ) {
325
+ $ranking = new myCRED_Query_Rankings( $args );
326
+ $ranking->get_rankings();
327
+
328
+ $_rankings = $ranking->result;
329
+ }
330
+ $mycred_rankings = new myCRED_Rankings( $args, $_rankings );
331
+
332
+ return $mycred_rankings;
333
+ }
334
+ }
335
+
336
+ /**
337
+ * Get Users Position
338
+ * Returns a given users position in the ranking list.
339
+ *
340
+ * @param $user_id (int) required user id
341
+ * @param $type (string) optional points type
342
+ * @returns position (int) or empty if no record could be made
343
+ * @since 0.1
344
+ * @version 1.1
345
+ */
346
+ if ( !function_exists( 'mycred_rankings_position' ) ) {
347
+ function mycred_rankings_position( $user_id = '', $type = 'mycred_default' )
348
+ {
349
+ $rankings = mycred_rankings( array( 'type' => $type ) );
350
+ return $rankings->users_position( $user_id );
351
+ }
352
+ }
353
+
354
+
355
+
356
+ ?>
includes/mycred-importer.php ADDED
@@ -0,0 +1,107 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ if ( ! defined( 'myCRED_VERSION' ) ) exit;
3
+
4
+ /**
5
+ * Register Importer: Log Entries
6
+ * @since 1.4
7
+ * @version 1.0
8
+ */
9
+ register_importer(
10
+ 'mycred_import_log',
11
+ sprintf( __( '%s Log Import', 'mycred' ), mycred_label() ),
12
+ __( 'Import log entries via a CSV file.', 'mycred' ),
13
+ 'mycred_importer_log_entries'
14
+ );
15
+
16
+ /**
17
+ * Load Importer: Log Entries
18
+ * @since 1.4
19
+ * @version 1.0
20
+ */
21
+ function mycred_importer_log_entries() {
22
+ require_once( ABSPATH . 'wp-admin/includes/import.php' );
23
+
24
+ if ( ! class_exists( 'WP_Importer' ) ) {
25
+ $class_wp_importer = ABSPATH . 'wp-admin/includes/class-wp-importer.php';
26
+ if ( file_exists( $class_wp_importer ) )
27
+ require $class_wp_importer;
28
+ }
29
+
30
+ require_once( myCRED_INCLUDES_DIR . 'importers/mycred-log-entries.php' );
31
+
32
+ $importer = new myCRED_Importer_Log_Entires();
33
+ $importer->load();
34
+ }
35
+
36
+ /**
37
+ * Register Importer: Balances
38
+ * @since 1.4.2
39
+ * @version 1.0
40
+ */
41
+ register_importer(
42
+ 'mycred_import_balance',
43
+ sprintf( __( '%s Balance Import', 'mycred' ), mycred_label() ),
44
+ __( 'Import balances.', 'mycred' ),
45
+ 'mycred_importer_point_balances'
46
+ );
47
+
48
+ /**
49
+ * Load Importer: Point Balances
50
+ * @since 1.4
51
+ * @version 1.0
52
+ */
53
+ function mycred_importer_point_balances() {
54
+ require_once( ABSPATH . 'wp-admin/includes/import.php' );
55
+
56
+ if ( ! class_exists( 'WP_Importer' ) ) {
57
+ $class_wp_importer = ABSPATH . 'wp-admin/includes/class-wp-importer.php';
58
+ if ( file_exists( $class_wp_importer ) )
59
+ require $class_wp_importer;
60
+ }
61
+
62
+ require_once( myCRED_INCLUDES_DIR . 'importers/mycred-balances.php' );
63
+
64
+ $importer = new myCRED_Importer_Balances();
65
+ $importer->load();
66
+ }
67
+
68
+ /**
69
+ * Register Importer: CubePoints
70
+ * @since 1.4
71
+ * @version 1.0
72
+ */
73
+ register_importer(
74
+ 'mycred_import_cp',
75
+ sprintf( __( '%s CubePoints Import', 'mycred' ), mycred_label() ),
76
+ __( 'Import CubePoints log entries and / or balances.', 'mycred' ),
77
+ 'mycred_importer_cubepoints'
78
+ );
79
+
80
+ /**
81
+ * Load Importer: CubePoints
82
+ * @since 1.4
83
+ * @version 1.0
84
+ */
85
+ function mycred_importer_cubepoints() {
86
+ require_once( ABSPATH . 'wp-admin/includes/import.php' );
87
+
88
+ global $wpdb;
89
+
90
+ // No use continuing if there is no log to import
91
+ if ( $wpdb->query( $wpdb->prepare( "SHOW TABLES LIKE %s;", $wpdb->prefix . 'cp' ) ) == 0 ) {
92
+ echo '<p>' . __( 'No CubePoints log exists.', 'mycred' ) . '</p>';
93
+ return;
94
+ }
95
+
96
+ if ( ! class_exists( 'WP_Importer' ) ) {
97
+ $class_wp_importer = ABSPATH . 'wp-admin/includes/class-wp-importer.php';
98
+ if ( file_exists( $class_wp_importer ) )
99
+ require $class_wp_importer;
100
+ }
101
+
102
+ require_once( myCRED_INCLUDES_DIR . 'importers/mycred-cubepoints.php' );
103
+
104
+ $importer = new myCRED_Importer_CubePoints();
105
+ $importer->load();
106
+ }
107
+ ?>
includes/mycred-install.php CHANGED
@@ -72,10 +72,6 @@ if ( ! class_exists( 'myCRED_Install' ) ) :
72
  if ( version_compare( $sql_version, '5.0', '<' ) )
73
  $message[] = __( 'myCRED requires SQL 5.0 or higher. Version detected: ', 'mycred' ) . ' ' . $sql_version;
74
 
75
- // mcrypt library check (if missing, this will cause a fatal error)
76
- $extensions = get_loaded_extensions();
77
- if ( ! in_array( 'mcrypt', $extensions ) && MYCRED_DISABLE_PROTECTION === false )
78
- $message[] = __( 'The mcrypt PHP library must be enabled in order to use this plugin! Please check your PHP configuration or contact your host and ask them to enable it for you!', 'mycred' );
79
 
80
  // Not empty $message means there are issues
81
  if ( ! empty( $message ) ) {
72
  if ( version_compare( $sql_version, '5.0', '<' ) )
73
  $message[] = __( 'myCRED requires SQL 5.0 or higher. Version detected: ', 'mycred' ) . ' ' . $sql_version;
74
 
 
 
 
 
75
 
76
  // Not empty $message means there are issues
77
  if ( ! empty( $message ) ) {
includes/mycred-leaderboard.php ADDED
@@ -0,0 +1,320 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ if ( ! defined( 'myCRED_VERSION' ) ) exit;
3
+
4
+ /**
5
+ * Get myCRED Leaderboard
6
+ * Returns the myCRED_Leaderboard object containing results.
7
+ *
8
+ * @param $args (array) optional array of arguments for the ranking
9
+ * @var number (int) number of results to return
10
+ * @var order (string) ASC to return with lowest creds or DESC to return highest creds first
11
+ * @var user_fields (string) comma seperated list of table columns to return with each user.
12
+ * @var offset (int) optional number to start from when returning records. defaults to zero (first result)
13
+ * @var type (string) optional points type
14
+ * @var template (string) if this function is called to create a leaderboard this string can contain the template
15
+ * for each user
16
+ * @uses myCRED_Query_Rankings()
17
+ * @uses myCRED_Rankings()
18
+ * @returns class object
19
+ * @since 1.4
20
+ * @version 1.0
21
+ */
22
+ if ( ! function_exists( 'mycred_get_leaderboard' ) ) :
23
+ function mycred_get_leaderboard( $args = array(), $reset = false, $raw = false )
24
+ {
25
+ $default = array(
26
+ 'number' => '-1',
27
+ 'order' => 'DESC',
28
+ 'user_fields' => 'user_login,display_name,user_email,user_nicename,user_url',
29
+ 'offset' => 0,
30
+ 'type' => 'mycred_default',
31
+ 'template' => '#%ranking% %user_profile_link% %cred_f%'
32
+ );
33
+ $args = shortcode_atts( $default, $args );
34
+
35
+ return new myCRED_Query_Leaderboard( $args );
36
+ }
37
+ endif;
38
+
39
+ /**
40
+ * Get Users Position
41
+ * Returns a given users position in the leaderboard.
42
+ *
43
+ * @param $user_id (int) required user id
44
+ * @param $type (string) optional points type
45
+ * @returns position (int) or empty if no record could be made
46
+ * @since 1.4
47
+ * @version 1.0
48
+ */
49
+ if ( ! function_exists( 'mycred_leaderboard_position' ) ) :
50
+ function mycred_leaderboard_position( $user_id = '', $type = 'mycred_default' )
51
+ {
52
+ $args = array( 'type' => $type );
53
+ $rankings = mycred_get_leaderboard( $args);
54
+ $leaderboard = new myCRED_Leaderboard( $args, $rankings->get_results() );
55
+ return apply_filters( 'mycred_get_leaderboard_position', $leaderboard->users_position( $user_id ), $user_id, $type );
56
+ }
57
+ endif;
58
+
59
+ /**
60
+ * myCRED Query Leaderboard Class
61
+ * @see http://codex.mycred.me/classes/mycred_query_leaderboard/
62
+ * @since 1.4
63
+ * @version 1.0
64
+ */
65
+ if ( ! class_exists( 'myCRED_Query_Leaderboard' ) ) :
66
+ class myCRED_Query_Leaderboard {
67
+
68
+ public $args;
69
+ public $count = 0;
70
+ public $result;
71
+
72
+ /**
73
+ * Constructor
74
+ */
75
+ public function __construct( $args = '' ) {
76
+ $this->args = shortcode_atts( array(
77
+ 'number' => 10,
78
+ 'order' => 'DESC',
79
+ 'user_fields' => 'user_login,display_name,user_email,user_nicename,user_url',
80
+ 'offset' => 0,
81
+ 'zero' => 1,
82
+ 'type' => 'mycred_default'
83
+ ), $args );
84
+ }
85
+
86
+ /**
87
+ * Have Results
88
+ * @returns true or false
89
+ * @since 1.1.2
90
+ * @version 1.0
91
+ */
92
+ public function have_results() {
93
+ if ( ! empty( $this->result ) ) return true;
94
+
95
+ return false;
96
+ }
97
+
98
+ /**
99
+ * Get Leaderboard
100
+ * Queries the DB for all users in order of their point balance.
101
+ * @since 1.1.2
102
+ * @version 1.0.2
103
+ */
104
+ public function get_results() {
105
+ global $wpdb;
106
+
107
+ // Type can not be empty
108
+ if ( ! empty( $this->args['type'] ) )
109
+ $key = $this->args['type'];
110
+ else
111
+ $key = 'mycred_default';
112
+
113
+ // Order
114
+ if ( ! empty( $this->args['order'] ) )
115
+ $order = $this->args['order'];
116
+ else
117
+ $order = 'DESC';
118
+
119
+ // Number
120
+ if ( $this->args['number'] != '-1' )
121
+ $limit = 'LIMIT ' . abs( $this->args['offset'] ) . ',' . abs( $this->args['number'] );
122
+ else
123
+ $limit = '';
124
+
125
+ // User fields
126
+ if ( empty( $this->args['user_fields'] ) )
127
+ $this->args['user_fields'] = 'display_name,user_login';
128
+
129
+ $user_fields = trim( $this->args['user_fields'] );
130
+ $user_fields = str_replace( ' ', '', $user_fields );
131
+ $user_fields = explode( ',', $user_fields );
132
+
133
+ // SELECT
134
+ $selects = array( "{$wpdb->users}.ID" );
135
+ foreach ( $user_fields as $field ) {
136
+ if ( $field == 'ID' ) continue;
137
+ $selects[] = "{$wpdb->users}." . $field;
138
+ }
139
+ $selects[] = "{$wpdb->usermeta}.meta_value AS cred";
140
+ $select = implode( ', ', $selects );
141
+
142
+ // WHERE
143
+ $where = '';
144
+ if ( $this->args['zero'] )
145
+ $where = "WHERE {$wpdb->usermeta}.meta_value > 0 ";
146
+
147
+ $SQL = apply_filters( 'mycred_ranking_sql', "
148
+ SELECT {$select}
149
+ FROM {$wpdb->users}
150
+ LEFT JOIN {$wpdb->usermeta}
151
+ ON {$wpdb->users}.ID = {$wpdb->usermeta}.user_id
152
+ AND {$wpdb->usermeta}.meta_key = %s
153
+ {$where}
154
+ ORDER BY {$wpdb->usermeta}.meta_value+1 {$order} {$limit};", $this->args, $wpdb );
155
+
156
+ $this->result = $wpdb->get_results( $wpdb->prepare( $SQL, $key ), 'ARRAY_A' );
157
+ $this->count = $wpdb->num_rows;
158
+ }
159
+
160
+ /**
161
+ * Save
162
+ * With the option to reset and bypass any set frequency.
163
+ * If a frequency is set to something other then 'always', then that
164
+ * setting is enforced.
165
+ * @since 1.1.2
166
+ * @version 1.0
167
+ */
168
+ public function save( $reset = false ) {
169
+ // No longer used
170
+ }
171
+ }
172
+ endif;
173
+
174
+ /**
175
+ * myCRED_Rankings class
176
+ * @see http://codex.mycred.me/classes/mycred_leaderboard/
177
+ * @since 1.4
178
+ * @version 1.0
179
+ */
180
+ if ( ! class_exists( 'myCRED_Leaderboard' ) ) :
181
+ class myCRED_Leaderboard {
182
+
183
+ public $core;
184
+ public $args;
185
+ public $result;
186
+
187
+ /**
188
+ * Constructor
189
+ */
190
+ public function __construct( $args = array(), $results = array() ) {
191
+ if ( ! isset( $args['type'] ) || empty( $args['type'] ) )
192
+ $args['type'] = 'mycred_default';
193
+
194
+ // Get settings
195
+ $mycred = mycred( $args['type'] );
196
+ $this->core = $mycred;
197
+ $this->args = $args;
198
+ $this->result = $results;
199
+ }
200
+
201
+ /**
202
+ * Have Results
203
+ * @returns true or false
204
+ * @since 0.1
205
+ * @version 1.1
206
+ */
207
+ public function have_results() {
208
+ if ( ! empty( $this->result ) ) return true;
209
+ return false;
210
+ }
211
+
212
+ /**
213
+ * Users Position
214
+ * @param $user_id (int) required user id
215
+ * @returns position (int)
216
+ * @since 0.1
217
+ * @version 1.1
218
+ */
219
+ public function users_position( $user_id = NULL ) {
220
+ if ( $user_id !== NULL ) {
221
+ if ( $this->have_results() ) {
222
+ foreach ( $this->result as $row_id => $row_data ) {
223
+ if ( ! isset( $row_data['ID'] ) ) $row_uid = $row_data['user_id'];
224
+ else $row_uid = $row_data['ID'];
225
+
226
+ if ( $row_uid == (int) $user_id ) return $row_id+1;
227
+ }
228
+ }
229
+ }
230
+
231
+ return 0;
232
+ }
233
+
234
+ /**
235
+ * Users Creds
236
+ * @param $user_id (int) user id
237
+ * @returns position (int) or empty
238
+ * @since 0.1
239
+ * @version 1.1
240
+ */
241
+ public function users_creds( $user_id = NULL ) {
242
+ if ( $user_id !== NULL ) {
243
+ if ( $this->have_results() ) {
244
+ foreach ( $this->result as $row_id => $row_data ) {
245
+ if ( ! isset( $row_data['ID'] ) ) $row_uid = $row_data['user_id'];
246
+ else $row_uid = $row_data['ID'];
247
+
248
+ if ( $row_uid == (int) $user_id ) return $row_data['creds'];
249
+ }
250
+ }
251
+ }
252
+
253
+ return 0;
254
+ }
255
+
256
+ /**
257
+ * Leaderboard
258
+ * @since 0.1
259
+ * @version 1.0
260
+ */
261
+ public function leaderboard() {
262
+ echo $this->get_leaderboard();
263
+ }
264
+
265
+ /**
266
+ * Get Leaderboard
267
+ * @since 0.1
268
+ * @version 1.1
269
+ */
270
+ public function get_leaderboard() {
271
+ return '<ol class="myCRED-leaderboard">' . $this->loop( 'li' ) . '</ol>';
272
+ }
273
+
274
+ /**
275
+ * Leaderboard Loop
276
+ * @since 1.1.2
277
+ * @version 1.0.2
278
+ */
279
+ public function loop( $wrap = '' ) {
280
+ // Default template
281
+ if ( empty( $this->args['template'] ) ) $this->args['template'] = '#%ranking% %user_profile_link% %cred_f%';
282
+ $output = '';
283
+
284
+ // Loop
285
+ foreach ( $this->result as $position => $row ) {
286
+ // Prep
287
+ $class = array();
288
+
289
+ // Classes
290
+ $class[] = 'item-' . $position;
291
+ if ( $position == 0 )
292
+ $class[] = 'first-item';
293
+
294
+ if ( $position % 2 != 0 )
295
+ $class[] = 'alt';
296
+
297
+ // Template Tags
298
+ if ( ! function_exists( 'mycred_get_users_rank' ) )
299
+ $layout = str_replace( array( '%rank%', '%ranking%' ), $position+1, $this->args['template'] );
300
+ else
301
+ $layout = str_replace( '%ranking%', $position+1, $this->args['template'] );
302
+
303
+ $layout = $this->core->template_tags_amount( $layout, $row['cred'] );
304
+ $layout = $this->core->template_tags_user( $layout, false, $row );
305
+
306
+ // Wrapper
307
+ if ( ! empty( $wrap ) )
308
+ $layout = '<' . $wrap . ' class="%classes%">' . $layout . '</' . $wrap . '>';
309
+
310
+ $layout = str_replace( '%classes%', apply_filters( 'mycred_ranking_classes', implode( ' ', $class ) ), $layout );
311
+ $layout = apply_filters( 'mycred_ranking_row', $layout, $this->args['template'], $row, $position+1 );
312
+
313
+ $output .= $layout . "\n";
314
+ }
315
+
316
+ return $output;
317
+ }
318
+ }
319
+ endif;
320
+ ?>
includes/mycred-log.php ADDED
@@ -0,0 +1,902 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ if ( ! defined( 'myCRED_VERSION' ) ) exit;
3
+
4
+ /**
5
+ * Query Log
6
+ * @see http://codex.mycred.me/classes/mycred_query_log/
7
+ * @since 0.1
8
+ * @version 1.4.1
9
+ */
10
+ if ( ! class_exists( 'myCRED_Query_Log' ) ) :
11
+ class myCRED_Query_Log {
12
+
13
+ public $args;
14
+ public $request;
15
+ public $prep;
16
+ public $num_rows;
17
+ public $max_num_pages;
18
+ public $total_rows;
19
+
20
+ public $results;
21
+
22
+ public $headers;
23
+ public $core;
24
+
25
+ /**
26
+ * Construct
27
+ */
28
+ public function __construct( $args = array(), $array = false ) {
29
+ if ( empty( $args ) ) return false;
30
+
31
+ global $wpdb;
32
+
33
+ $select = $where = $sortby = $limits = '';
34
+ $prep = $wheres = array();
35
+
36
+ // Load General Settings
37
+ if ( isset( $args['ctype'] ) )
38
+ $type = $args['ctype'];
39
+ else
40
+ $type = 'mycred_default';
41
+
42
+ $this->core = mycred( $type );
43
+ if ( $this->core->format['decimals'] > 0 )
44
+ $format = '%f';
45
+ else
46
+ $format = '%d';
47
+
48
+ // Prep Defaults
49
+ $defaults = array(
50
+ 'user_id' => NULL,
51
+ 'ctype' => 'mycred_default',
52
+ 'number' => 25,
53
+ 'time' => NULL,
54
+ 'ref' => NULL,
55
+ 'ref_id' => NULL,
56
+ 'amount' => NULL,
57
+ 's' => NULL,
58
+ 'data' => NULL,
59
+ 'orderby' => 'time',
60
+ 'offset' => '',
61
+ 'order' => 'DESC',
62
+ 'ids' => false,
63
+ 'cache' => '',
64
+ 'paged' => $this->get_pagenum()
65
+ );
66
+ $this->args = mycred_apply_defaults( $defaults, $args );
67
+
68
+ // Difference between default and given args
69
+ $this->diff = array_diff_assoc( $this->args, $defaults );
70
+ if ( isset( $this->diff['number'] ) )
71
+ unset( $this->diff['number'] );
72
+
73
+ $data = false;
74
+ if ( $this->args['cache'] != '' ) {
75
+ $cache_id = substr( $this->args['cache'], 0, 23 );
76
+ if ( is_multisite() )
77
+ $data = get_site_transient( 'mycred_log_query_' . $cache_id );
78
+ else
79
+ $data = get_transient( 'mycred_log_query_' . $cache_id );
80
+ }
81
+ if ( $data === false ) {
82
+
83
+ // Type
84
+ $wheres[] = 'ctype = %s';
85
+ $prep[] = $this->args['ctype'];
86
+
87
+ // User ID
88
+ if ( $this->args['user_id'] !== NULL && $this->args['user_id'] != '' ) {
89
+ $wheres[] = 'user_id = %d';
90
+ $prep[] = abs( $this->args['user_id'] );
91
+ }
92
+
93
+ // Reference
94
+ if ( $this->args['ref'] !== NULL && $this->args['ref'] != '' ) {
95
+ $refs = explode( ',', $this->args['ref'] );
96
+ $ref_count = count( $refs );
97
+ if ( $ref_count > 1 ) {
98
+ $ref_count = $ref_count-1;
99
+ $wheres[] = 'ref IN (%s' . str_repeat( ',%s', $ref_count ) . ')';
100
+ foreach ( $refs as $ref )
101
+ $prep[] = sanitize_text_field( $ref );
102
+ }
103
+ else {
104
+ $wheres[] = 'ref = %s';
105
+ $prep[] = sanitize_text_field( $refs[0] );
106
+ }
107
+ }
108
+
109
+ // Reference ID
110
+ if ( $this->args['ref_id'] !== NULL && $this->args['ref_id'] != '' ) {
111
+ $ref_ids = explode( ',', $this->args['ref_id'] );
112
+ if ( count( $ref_ids ) > 1 ) {
113
+ $ref_id_count = count( $ref_ids )-1;
114
+ $wheres[] = 'ref_id IN (%d' . str_repeat( ',%d', $ref_id_count ) . ')';
115
+ foreach ( $ref_ids as $ref_id )
116
+ $prep[] = (int) sanitize_text_field( $ref_id );
117
+ }
118
+ else {
119
+ $wheres[] = 'ref_id = %d';
120
+ $prep[] = (int) sanitize_text_field( $ref_ids[0] );
121
+ }
122
+ }
123
+
124
+ // Amount
125
+ if ( $this->args['amount'] !== NULL && $this->args['amount'] != '' ) {
126
+ // Advanced query
127
+ if ( is_array( $this->args['amount'] ) ) {
128
+ // Range
129
+ if ( isset( $this->args['amount']['start'] ) && isset( $this->args['amount']['end'] ) ) {
130
+ $wheres[] = 'creds BETWEEN ' . $format . ' AND ' . $format;
131
+ $prep[] = $this->core->number( sanitize_text_field( $this->args['amount']['start'] ) );
132
+ $prep[] = $this->core->number( sanitize_text_field( $this->args['amount']['end'] ) );
133
+ }
134
+ // Compare
135
+ elseif ( isset( $this->args['amount']['num'] ) && isset( $this->args['amount']['compare'] ) ) {
136
+ $compare = urldecode( $this->args['amount']['compare'] );
137
+ $wheres[] = 'creds ' . trim( $compare ) . ' ' . $format;
138
+ $prep[] = $this->core->number( sanitize_text_field( $this->args['amount']['num'] ) );
139
+ }
140
+ }
141
+ // Specific amount(s)
142
+ else {
143
+ $amounts = explode( ',', $this->args['amount'] );
144
+ $amount_count = count( $amounts );
145
+ if ( $amount_count > 1 ) {
146
+ $amount_count = $amount_count-1;
147
+ $wheres[] = 'amount IN (' . $format . str_repeat( ',' . $format, $ref_id_count ) . ')';
148
+ foreach ( $amount_count as $amount )
149
+ $prep[] = $this->core->number( sanitize_text_field( $amount ) );
150
+ }
151
+ else {
152
+ $wheres[] = 'creds = ' . $format;
153
+ $prep[] = $this->core->number( sanitize_text_field( $amounts[0] ) );
154
+ }
155
+ }
156
+ }
157
+
158
+ // Time
159
+ if ( $this->args['time'] !== NULL && $this->args['time'] != '' ) {
160
+ $now = date_i18n( 'U' );
161
+ $today = strtotime( date_i18n( 'Y/m/d' ) . ' midnight' );
162
+ $todays_date = date_i18n( 'd' );
163
+
164
+ // Show todays entries
165
+ if ( $this->args['time'] == 'today' ) {
166
+ $wheres[] = "time BETWEEN $today AND $now";
167
+ }
168
+ // Show yesterdays entries
169
+ elseif ( $this->args['time'] == 'yesterday' ) {
170
+ $yesterday = strtotime( '-1 day midnight' );
171
+ $wheres[] = "time BETWEEN $yesterday AND $today";
172
+ }
173
+ // Show this weeks entries
174
+ elseif ( $this->args['time'] == 'thisweek' ) {
175
+ $weekday = date_i18n( 'w' );
176
+ // New week started today so show only todays
177
+ if ( get_option( 'start_of_week' ) == $weekday ) {
178
+ $wheres[] = "time BETWEEN $today AND $now";
179
+ }
180
+ // Show rest of this week
181
+ else {
182
+ $week_start = strtotime( '-' . ( $weekday+1 ) . ' days midnight' );
183
+ $wheres[] = "time BETWEEN $week_start AND $now";
184
+ }
185
+ }
186
+ // Show this months entries
187
+ elseif ( $this->args['time'] == 'thismonth' ) {
188
+ $start_of_month = strtotime( date_i18n( 'Y/m/01' ) . ' midnight' );
189
+ $wheres[] = "time BETWEEN $start_of_month AND $now";
190
+ }
191
+ else {
192
+ $times = explode( ',', $this->args['time'] );
193
+ if ( count( $times ) == 2 ) {
194
+ $from = sanitize_key( $times[0] );
195
+ $to = sanitize_key( $times[1] );
196
+ $wheres[] = "time BETWEEN $from AND $to";
197
+ }
198
+ }
199
+ }
200
+
201
+ // Entry Search
202
+ if ( $this->args['s'] !== NULL && $this->args['s'] != '' ) {
203
+ $search_query = sanitize_text_field( $this->args['s'] );
204
+
205
+ if ( is_int( $search_query ) )
206
+ $search_query = (string) $search_query;
207
+
208
+ $wheres[] = "entry LIKE %s";
209
+ $prep[] = "%$search_query%";
210
+ }
211
+
212
+ // Data
213
+ if ( $this->args['data'] !== NULL && $this->args['data'] != '' ) {
214
+ $data_query = sanitize_text_field( $this->args['data'] );
215
+
216
+ if ( is_int( $data_query ) )
217
+ $data_query = (string) $data_query;
218
+
219
+ $wheres[] = "data LIKE %s";
220
+ $prep[] = $data_query;
221
+ }
222
+
223
+ // Order by
224
+ if ( $this->args['orderby'] != '' ) {
225
+ // Make sure $sortby is valid
226
+ $sortbys = array( 'id', 'ref', 'ref_id', 'user_id', 'creds', 'ctype', 'entry', 'data', 'time' );
227
+ $allowed = apply_filters( 'mycred_allowed_sortby', $sortbys );
228
+ if ( in_array( $this->args['orderby'], $allowed ) ) {
229
+ $sortby = "ORDER BY " . $this->args['orderby'] . " " . $this->args['order'];
230
+ }
231
+ }
232
+
233
+ // Number of results
234
+ $number = $this->args['number'];
235
+ if ( $number < -1 )
236
+ $number = abs( $number );
237
+ elseif ( $number == 0 || $number == -1 )
238
+ $number = NULL;
239
+
240
+ // Limits
241
+ if ( $number !== NULL ) {
242
+ $page = 1;
243
+ if ( $this->args['paged'] !== NULL ) {
244
+ $page = absint( $this->args['paged'] );
245
+ if ( ! $page )
246
+ $page = 1;
247
+ }
248
+
249
+ if ( $this->args['offset'] != '' ) {
250
+ $pgstrt = ($page - 1) * $number . ', ';
251
+ }
252
+ else {
253
+ $offset = absint( $this->args['offset'] );
254
+ $pgstrt = $offset . ', ';
255
+ }
256
+
257
+ $limits = 'LIMIT ' . $pgstrt . $number;
258
+ }
259
+ else {
260
+ $limits = '';
261
+ }
262
+
263
+ // Prep return
264
+ if ( $this->args['ids'] === true )
265
+ $select = 'id';
266
+ else
267
+ $select = '*';
268
+
269
+ $found_rows = '';
270
+ if ( $limits != '' )
271
+ $found_rows = 'SQL_CALC_FOUND_ROWS';
272
+
273
+ // Filter
274
+ $select = apply_filters( 'mycred_query_log_select', $select, $this->args, $this->core );
275
+ $sortby = apply_filters( 'mycred_query_log_sortby', $sortby, $this->args, $this->core );
276
+ $limits = apply_filters( 'mycred_query_log_limits', $limits, $this->args, $this->core );
277
+ $wheres = apply_filters( 'mycred_query_log_wheres', $wheres, $this->args, $this->core );
278
+
279
+ $prep = apply_filters( 'mycred_query_log_prep', $prep, $this->args, $this->core );
280
+
281
+ $where = 'WHERE ' . implode( ' AND ', $wheres );
282
+
283
+ // Run
284
+ $this->request = $wpdb->prepare( "SELECT {$found_rows} {$select} FROM {$this->core->log_table} {$where} {$sortby} {$limits}", $prep );
285
+ $this->prep = $prep;
286
+
287
+ $this->results = $wpdb->get_results( $this->request, $array ? ARRAY_A : OBJECT );
288
+
289
+ if ( $limits != '' )
290
+ $this->num_rows = $wpdb->get_var( 'SELECT FOUND_ROWS()' );
291
+ else
292
+ $this->num_rows = count( $this->results );
293
+
294
+ if ( $limits != '' )
295
+ $this->max_num_pages = ceil( $this->num_rows / $number );
296
+
297
+ if ( $this->args['cache'] != '' ) {
298
+ if ( is_multisite() )
299
+ set_site_transient( 'mycred_log_query_' . $cache_id, $this->results, DAY_IN_SECONDS * 1 );
300
+ else
301
+ set_transient( 'mycred_log_query_' . $cache_id, $this->results, DAY_IN_SECONDS * 1 );
302
+ }
303
+
304
+ $this->total_rows = $wpdb->get_var( "SELECT COUNT( * ) FROM {$this->core->log_table}" );
305
+ }
306
+
307
+ // Return the transient
308
+ else {
309
+ $this->request = 'transient';
310
+ $this->results = $data;
311
+ $this->prep = '';
312
+
313
+ $this->num_rows = count( $data );
314
+ }
315
+
316
+ $this->headers = $this->table_headers();
317
+ }
318
+
319
+ /**
320
+ * Has Entries
321
+ * @returns true or false
322
+ * @since 0.1
323
+ * @version 1.0
324
+ */
325
+ public function have_entries() {
326
+ if ( ! empty( $this->results ) ) return true;
327
+ return false;
328
+ }
329
+
330
+ /**
331
+ * Table Nav
332
+ * @since 0.1
333
+ * @version 1.1
334
+ */
335
+ public function table_nav( $location = 'top', $is_profile = false ) {
336
+ if ( $location == 'top' ) {
337
+
338
+ $this->filter_options( $is_profile );
339
+ $this->navigation( $location );
340
+
341
+ }
342
+ else {
343
+
344
+ $this->navigation( $location );
345
+
346
+ }
347
+ }
348
+
349
+ /**
350
+ * Item Count
351
+ * @since 0.1
352
+ * @version 1.1
353
+ */
354
+ public function navigation( $location = 'top', $id = '' ) { ?>
355
+
356
+ <div class="tablenav-pages<?php if ( $this->max_num_pages == 1 ) echo ' one-page'; ?>">
357
+ <?php $this->pagination( $location, $id ); ?>
358
+
359
+ </div>
360
+ <?php
361
+ }
362
+
363
+ /**
364
+ * Get Page Number
365
+ * @since 1.4
366
+ * @version 1.0
367
+ */
368
+ public function get_pagenum() {
369
+ global $paged;
370
+
371
+ if ( $paged > 0 )
372
+ $pagenum = absint( $paged );
373
+
374
+ elseif ( isset( $_REQUEST['paged'] ) )
375
+ $pagenum = absint( $_REQUEST['paged'] );
376
+
377
+ else return 1;
378
+
379
+ return max( 1, $pagenum );
380
+ }
381
+
382
+ /**
383
+ * Pagination
384
+ * @since 1.4
385
+ * @version 1.0
386
+ */
387
+ public function pagination( $location = 'top', $id = '' ) {
388
+ $output = '';
389
+ $total_pages = $this->max_num_pages;
390
+ $current = $this->get_pagenum();
391
+ $current_url = set_url_scheme( 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'] . $id );
392
+ if ( ! is_admin() )
393
+ $current_url = str_replace( '/page/' . $current . '/', '/', $current_url );
394
+ $current_url = remove_query_arg( array( 'hotkeys_highlight_last', 'hotkeys_highlight_first' ), $current_url );
395
+
396
+ if ( $this->have_entries() ) {
397
+ $total_number = count( $this->results );
398
+ $output = '<span class="displaying-num">' . sprintf( __( 'Showing %d %s', 'mycred' ), $total_number, _n( 'entry', 'entries', $total_number, 'mycred' ) ) . '</span>';
399
+ }
400
+
401
+ $page_links = array();
402
+
403
+ $disable_first = $disable_last = '';
404
+ if ( $current == 1 )
405
+ $disable_first = ' disabled';
406
+ if ( $current == $total_pages )
407
+ $disable_last = ' disabled';
408
+
409
+ $page_links[] = sprintf( '<a class="%s" title="%s" href="%s">%s</a>',
410
+ 'btn btn-default btn-sm first-page' . $disable_first,
411
+ esc_attr__( 'Go to the first page' ),
412
+ esc_url( remove_query_arg( 'paged', $current_url ) ),
413
+ '&laquo;'
414
+ );
415
+
416
+ $page_links[] = sprintf( '<a class="%s" title="%s" href="%s">%s</a>',
417
+ 'btn btn-default btn-sm prev-page' . $disable_first,
418
+ esc_attr__( 'Go to the previous page' ),
419
+ esc_url( add_query_arg( 'paged', max( 1, $current-1 ), $current_url ) ),
420
+ '&lsaquo;'
421
+ );
422
+
423
+ if ( 'bottom' == $location )
424
+ $html_current_page = $current;
425
+ else
426
+ $html_current_page = sprintf( '<input class="current-page btn btn-sm" title="%s" type="text" name="paged" value="%s" size="%d" />',
427
+ esc_attr__( 'Current page' ),
428
+ $current,
429
+ strlen( $total_pages )
430
+ );
431
+
432
+ $html_total_pages = sprintf( "<span class='total-pages'>%s</span>", number_format_i18n( $total_pages ) );
433
+ $page_links[] = '<span class="paging-input">' . sprintf( _x( '%1$s of %2$s', 'paging' ), $html_current_page, $html_total_pages ) . '</span>';
434
+
435
+ $page_links[] = sprintf( '<a class="%s" title="%s" href="%s">%s</a>',
436
+ 'btn btn-default btn-sm next-page' . $disable_last,
437
+ esc_attr__( 'Go to the next page' ),
438
+ esc_url( add_query_arg( 'paged', min( $total_pages, $current+1 ), $current_url ) ),
439
+ '&rsaquo;'
440
+ );
441
+
442
+ $page_links[] = sprintf( '<a class="%s" title="%s" href="%s">%s</a>',
443
+ 'btn btn-default btn-sm last-page' . $disable_last,
444
+ esc_attr__( 'Go to the last page' ),
445
+ esc_url( add_query_arg( 'paged', $total_pages, $current_url ) ),
446
+ '&raquo;'
447
+ );
448
+
449
+ $pagination_links_class = 'pagination-links';
450
+ $output .= "\n<span class='$pagination_links_class'>" . join( "\n", $page_links ) . '</span>';
451
+
452
+ if ( $total_pages )
453
+ $page_class = $total_pages < 2 ? ' one-page' : '';
454
+ else
455
+ $page_class = ' no-pages';
456
+
457
+ echo "<div class='tablenav-pages{$page_class}'>$output</div>";
458
+ }
459
+
460
+ /**
461
+ * Get References
462
+ * Returns all available references in the database.
463
+ * @since 0.1
464
+ * @version 1.1
465
+ */
466
+ public function get_refs( $req = array() ) {
467
+ $refs = mycred_get_used_references( $this->args['ctype'] );
468
+
469
+ foreach ( $refs as $i => $ref ) {
470
+ if ( ! empty( $req ) && ! in_array( $ref, $req ) )
471
+ unset( $refs[ $i ] );
472
+ }
473
+ $refs = array_values( $refs );
474
+
475
+ return apply_filters( 'mycred_log_get_refs', $refs );
476
+ }
477
+
478
+ /**
479
+ * Get Users
480
+ * Returns an array of user id's and display names.
481
+ * @since 0.1
482
+ * @version 1.0
483
+ */
484
+ protected function get_users() {
485
+ $users = wp_cache_get( 'mycred_users' );
486
+
487
+ if ( false === $users ) {
488
+ $users = array();
489
+ $blog_users = get_users( array( 'orderby' => 'display_name' ) );
490
+ foreach ( $blog_users as $user ) {
491
+ if ( false === $this->core->exclude_user( $user->ID ) )
492
+ $users[ $user->ID ] = $user->display_name;
493
+ }
494
+ wp_cache_set( 'mycred_users', $users );
495
+ }
496
+
497
+ return apply_filters( 'mycred_log_get_users', $users );
498
+ }
499
+
500
+ /**
501
+ * Filter Log options
502
+ * @since 0.1
503
+ * @version 1.3
504
+ */
505
+ public function filter_options( $is_profile = false, $refs = array() ) {
506
+ echo '<div class="alignleft actions">';
507
+ $show = false;
508
+
509
+ // Filter by reference
510
+ $references = $this->get_refs( $refs );
511
+ if ( ! empty( $references ) ) {
512
+ echo '<select name="ref" id="myCRED-reference-filter"><option value="">' . __( 'Show all references', 'mycred' ) . '</option>';
513
+ foreach ( $references as $ref ) {
514
+ $label = str_replace( array( '_', '-' ), ' ', $ref );
515
+ echo '<option value="' . $ref . '"';
516
+ if ( isset( $_GET['ref'] ) && $_GET['ref'] == $ref ) echo ' selected="selected"';
517
+ echo '>' . ucwords( $label ) . '</option>';
518
+ }
519
+ echo '</select>';
520
+ $show = true;
521
+ }
522
+
523
+ // Filter by user
524
+ if ( $this->core->can_edit_creds() && ! $is_profile && $this->num_rows > 0 ) {
525
+ echo '<input type="text" class="form-control" name="user_id" id="myCRED-user-filter" size="12" placeholder="' . __( 'User ID', 'mycred' ) . '" value="' . ( ( isset( $_GET['user_id'] ) ) ? $_GET['user_id'] : '' ) . '" /> ';
526
+ $show = true;
527
+ }
528
+
529
+ // Filter Order
530
+ if ( $this->num_rows > 0 ) {
531
+ echo '<select name="order" id="myCRED-order-filter"><option value="">' . __( 'Show in order', 'mycred' ) . '</option>';
532
+ $options = array( 'ASC' => __( 'Ascending', 'mycred' ), 'DESC' => __( 'Descending', 'mycred' ) );
533
+ foreach ( $options as $value => $label ) {
534
+ echo '<option value="' . $value . '"';
535
+ if ( ! isset( $_GET['order'] ) && $value == 'DESC' ) echo ' selected="selected"';
536
+ elseif ( isset( $_GET['order'] ) && $_GET['order'] == $value ) echo ' selected="selected"';
537
+ echo '>' . $label . '</option>';
538
+ }
539
+ echo '</select>';
540
+ $show = true;
541
+ }
542
+
543
+ // Let others play
544
+ if ( has_action( 'mycred_filter_log_options' ) ) {
545
+ do_action( 'mycred_filter_log_options', $this );
546
+ $show = true;
547
+ }
548
+
549
+ if ( $show === true )
550
+ echo '<input type="submit" class="btn btn-default button button-secondary button-large" value="' . __( 'Filter', 'mycred' ) . '" />';
551
+
552
+ echo '</div>';
553
+ }
554
+
555
+ /**
556
+ * Exporter
557
+ * Displays all available export options.
558
+ * @since 0.1
559
+ * @version 1.0
560
+ */
561
+ public function exporter( $title = '', $is_profile = false ) {
562
+ // Must be logged in
563
+ if ( ! is_user_logged_in() ) return;
564
+
565
+ // Make sure current user can export
566
+ if ( ! apply_filters( 'mycred_user_can_export', false ) && ! $this->core->can_edit_creds() ) return;
567
+
568
+ // Check if we allow export from front end. Disallowed by default
569
+ if ( ! apply_filters( 'mycred_allow_front_export', false ) && ! is_admin() ) return;
570
+
571
+ // Export options
572
+ $exports = mycred_get_log_exports();
573
+
574
+ // A difference in the default aguments should show us "search results"
575
+ if ( empty( $this->diff ) || ( ! empty( $this->diff ) && $this->max_num_pages < 2 ) )
576
+ unset( $exports['search'] );
577
+
578
+ // Entire log export is not available when viewing our own history
579
+ if ( $is_profile )
580
+ unset( $exports['all'] ); ?>
581
+
582
+ <div style="display:none;" class="clear" id="export-log-history">
583
+ <?php if ( ! empty( $title ) ) : ?><h3 class="group-title"><?php echo $title; ?></h3><?php endif; ?>
584
+ <form action="<?php echo add_query_arg( array( 'mycred-export' => 'do' ) ); ?>" method="post">
585
+ <input type="hidden" name="token" value="<?php echo wp_create_nonce( 'mycred-run-log-export' ); ?>" />
586
+ <?php
587
+ if ( ! empty( $exports ) ) {
588
+
589
+ foreach ( (array) $this->args as $arg_key => $arg_value )
590
+ echo '<input type="hidden" name="' . $arg_key . '" value="' . $arg_value . '" />';
591
+
592
+ foreach ( (array) $exports as $id => $data ) {
593
+ // Label
594
+ if ( $is_profile )
595
+ $label = $data['my_label'];
596
+ else
597
+ $label = $data['label'];
598
+
599
+ echo '<input type="submit" class="' . $data['class'] . '" name="action" value="' . $label . '" /> ';
600
+ }
601
+ ?>
602
+ </form>
603
+ <p><span class="description"><?php _e( 'Log entries are exported to a CSV file and depending on the number of entries selected, the process may take a few seconds.', 'mycred' ); ?></span></p>
604
+ <?php
605
+ }
606
+ else {
607
+ echo '<p>' . __( 'No export options available.', 'mycred' ) . '</p>';
608
+ }
609
+ ?>
610
+ </div>
611
+ <script type="text/javascript">
612
+ jQuery(function($) {
613
+ $( '.toggle-exporter' ).click(function(){
614
+ $( '#export-log-history' ).toggle();
615
+ });
616
+ });
617
+ </script>
618
+ <?php
619
+ }
620
+
621
+ /**
622
+ * Table Headers
623
+ * Returns all table column headers.
624
+ *
625
+ * @filter mycred_log_column_headers
626
+ * @since 0.1
627
+ * @version 1.1
628
+ */
629
+ public function table_headers() {
630
+ global $mycred_types;
631
+
632
+ return apply_filters( 'mycred_log_column_headers', array(
633
+ 'column-username' => __( 'User', 'mycred' ),
634
+ 'column-time' => __( 'Date', 'mycred' ),
635
+ 'column-creds' => $this->core->plural(),
636
+ 'column-entry' => __( 'Entry', 'mycred' )
637
+ ), $this );
638
+ }
639
+
640
+ /**
641
+ * Display
642
+ * @since 0.1
643
+ * @version 1.0
644
+ */
645
+ public function display() {
646
+ echo $this->get_display();
647
+ }
648
+
649
+ /**
650
+ * Get Display
651
+ * Generates a table for our results.
652
+ *
653
+ * @since 0.1
654
+ * @version 1.0
655
+ */
656
+ public function get_display() {
657
+ $output = '
658
+ <table class="table mycred-table widefat log-entries table-striped" cellspacing="0">
659
+ <thead>
660
+ <tr>';
661
+
662
+ // Table header
663
+ foreach ( $this->headers as $col_id => $col_title ) {
664
+ $output .= '<th scope="col" id="' . str_replace( 'column-', '', $col_id ) . '" class="manage-column ' . $col_id . '">' . $col_title . '</th>';
665
+ }
666
+
667
+ $output .= '
668
+ </tr>
669
+ </thead>
670
+ <tfoot>';
671
+
672
+ // Table footer
673
+ foreach ( $this->headers as $col_id => $col_title ) {
674
+ $output .= '<th scope="col" class="manage-column ' . $col_id . '">' . $col_title . '</th>';
675
+ }
676
+
677
+ $output .= '
678
+ </tfoot>
679
+ <tbody id="the-list">';
680
+
681
+ // Loop
682
+ if ( $this->have_entries() ) {
683
+ $alt = 0;
684
+
685
+ foreach ( $this->results as $log_entry ) {
686
+ $row_class = apply_filters( 'mycred_log_row_classes', array( 'myCRED-log-row' ), $log_entry );
687
+
688
+ $alt = $alt+1;
689
+ if ( $alt % 2 == 0 )
690
+ $row_class[] = ' alt';
691
+
692
+ $output .= '<tr class="' . implode( ' ', $row_class ) . '">';
693
+ $output .= $this->get_the_entry( $log_entry );
694
+ $output .= '</tr>';
695
+ }
696
+ }
697
+ // No log entry
698
+ else {
699
+ $output .= '<tr><td colspan="' . count( $this->headers ) . '" class="no-entries">' . $this->get_no_entries() . '</td></tr>';
700
+ }
701
+
702
+ $output .= '
703
+ </tbody>
704
+ </table>' . "\n";
705
+
706
+ return $output;
707
+ }
708
+
709
+ /**
710
+ * The Entry
711
+ * @since 0.1
712
+ * @version 1.1
713
+ */
714
+ public function the_entry( $log_entry, $wrap = 'td' ) {
715
+ echo $this->get_the_entry( $log_entry, $wrap );
716
+ }
717
+
718
+ /**
719
+ * Get The Entry
720
+ * Generated a single entry row depending on the columns used / requested.
721
+ * @filter mycred_log_date
722
+ * @since 0.1
723
+ * @version 1.3
724
+ */
725
+ public function get_the_entry( $log_entry, $wrap = 'td' ) {
726
+ $date_format = get_option( 'date_format' ) . ' ' . get_option( 'time_format' );
727
+ $entry_data = '';
728
+
729
+ // Run though columns
730
+ foreach ( $this->headers as $column_id => $column_name ) {
731
+ switch ( $column_id ) {
732
+ // Username Column
733
+ case 'column-username' :
734
+
735
+ $user = get_userdata( $log_entry->user_id );
736
+ if ( $user === false )
737
+ $content = '<span>' . __( 'User Missing', 'mycred' ) . ' (ID: ' . $log_entry->user_id . ')</span>';
738
+ else
739
+ $content = '<span>' . $user->display_name . '</span>';
740
+
741
+ $content = apply_filters( 'mycred_log_username', $content, $log_entry->user_id, $log_entry );
742
+
743
+ break;
744
+ // Date & Time Column
745
+ case 'column-time' :
746
+
747
+ $content = $time = apply_filters( 'mycred_log_date', date_i18n( $date_format, $log_entry->time ), $log_entry->time, $log_entry );
748
+
749
+ break;
750
+ // Amount Column
751
+ case 'column-creds' :
752
+
753
+ $content = $creds = $this->core->format_creds( $log_entry->creds );
754
+ $content = apply_filters( 'mycred_log_creds', $content, $log_entry->creds, $log_entry );
755
+
756
+ break;
757
+ // Log Entry Column
758
+ case 'column-entry' :
759
+
760
+ $content = '<div class="mycred-mobile-log" style="display:none;">' . $time . '<div>' . $creds . '</div></div>';
761
+ $content .= $this->core->parse_template_tags( $log_entry->entry, $log_entry );
762
+ $content = apply_filters( 'mycred_log_entry', $content, $log_entry->entry, $log_entry );
763
+
764
+ break;
765
+ // Let others play
766
+ default :
767
+
768
+ $content = apply_filters( 'mycred_log_' . $column_id, '', $log_entry );
769
+
770
+ break;
771
+ }
772
+ $entry_data .= '<' . $wrap . ' class="' . $column_id . '">' . $content . '</' . $wrap . '>';
773
+ }
774
+ return $entry_data;
775
+ }
776
+
777
+ /**
778
+ * Mobile Support
779
+ * @since 1.4
780
+ * @version 1.0
781
+ */
782
+ public function mobile_support() {
783
+ echo '<style type="text/css">' . apply_filters( 'mycred_log_mobile_support', '
784
+ @media all and (max-width: 480px) {
785
+ .column-time, .column-creds { display: none; }
786
+ .mycred-mobile-log { display: block !important; }
787
+ .mycred-mobile-log div { float: right; font-weight: bold; }
788
+ }
789
+ ' ) . '</style>';
790
+ }
791
+
792
+ /**
793
+ * No Entries
794
+ * @since 0.1
795
+ * @version 1.0
796
+ */
797
+ public function no_entries() {
798
+ echo $this->get_no_entries();
799
+ }
800
+
801
+ /**
802
+ * Get No Entries
803
+ * @since 0.1
804
+ * @version 1.0
805
+ */
806
+ public function get_no_entries() {
807
+ return __( 'No log entries found', 'mycred' );
808
+ }
809
+
810
+ /**
811
+ * Log Search
812
+ * @since 0.1
813
+ * @version 1.0.1
814
+ */
815
+ public function search() {
816
+ if ( isset( $_GET['s'] ) && $_GET['s'] != '' )
817
+ $serarch_string = $_GET['s'];
818
+ else
819
+ $serarch_string = ''; ?>
820
+
821
+ <p class="search-box">
822
+ <label class="screen-reader-text" for=""><?php _e( 'Search Log', 'mycred' ); ?>:</label>
823
+ <input type="search" name="s" value="<?php echo $serarch_string; ?>" placeholder="<?php _e( 'search log entries', 'mycred' ); ?>" />
824
+ <input type="submit" name="mycred-search-log" id="search-submit" class="button button-medium button-secondary" value="<?php _e( 'Search Log', 'mycred' ); ?>" />
825
+ </p>
826
+ <?php
827
+ }
828
+
829
+ /**
830
+ * Filter by Dates
831
+ * @since 0.1
832
+ * @version 1.0
833
+ */
834
+ public function filter_dates( $url = '' ) {
835
+ $date_sorting = apply_filters( 'mycred_sort_by_time', array(
836
+ '' => __( 'All', 'mycred' ),
837
+ 'today' => __( 'Today', 'mycred' ),
838
+ 'yesterday' => __( 'Yesterday', 'mycred' ),
839
+ 'thisweek' => __( 'This Week', 'mycred' ),
840
+ 'thismonth' => __( 'This Month', 'mycred' )
841
+ ) );
842
+
843
+ if ( ! empty( $date_sorting ) ) {
844
+ $total = count( $date_sorting );
845
+ $count = 0;
846
+ echo '<ul class="subsubsub">';
847
+ foreach ( $date_sorting as $sorting_id => $sorting_name ) {
848
+ $count = $count+1;
849
+ echo '<li class="' . $sorting_id . '"><a href="';
850
+
851
+ // Build Query Args
852
+ $url_args = array();
853
+ if ( isset( $_GET['user_id'] ) && $_GET['user_id'] != '' )
854
+ $url_args['user_id'] = $_GET['user_id'];
855
+ if ( isset( $_GET['ref'] ) && $_GET['ref'] != '' )
856
+ $url_args['ref'] = $_GET['ref'];
857
+ if ( isset( $_GET['order'] ) && $_GET['order'] != '' )
858
+ $url_args['order'] = $_GET['order'];
859
+ if ( isset( $_GET['s'] ) && $_GET['s'] != '' )
860
+ $url_args['s'] = $_GET['s'];
861
+ if ( $sorting_id != '' )
862
+ $url_args['show'] = $sorting_id;
863
+
864
+ // Build URL
865
+ if ( ! empty( $url_args ) )
866
+ echo add_query_arg( $url_args, $url );
867
+ else
868
+ echo $url;
869
+
870
+ echo '"';
871
+
872
+ if ( isset( $_GET['show'] ) && $_GET['show'] == $sorting_id ) echo ' class="current"';
873
+ elseif ( ! isset( $_GET['show'] ) && $sorting_id != '' ) echo ' class="current"';
874
+
875
+ echo '>' . $sorting_name . '</a>';
876
+ if ( $count != $total ) echo ' | ';
877
+ echo '</li>';
878
+ }
879
+ echo '</ul>';
880
+ }
881
+ }
882
+
883
+ /**
884
+ * Reset Query
885
+ * @since 1.3
886
+ * @version 1.0
887
+ */
888
+ public function reset_query() {
889
+ $this->args = NULL;
890
+ $this->request = NULL;
891
+ $this->prep = NULL;
892
+ $this->num_rows = NULL;
893
+ $this->max_num_pages = NULL;
894
+ $this->total_rows = NULL;
895
+
896
+ $this->results = NULL;
897
+
898
+ $this->headers = NULL;
899
+ }
900
+ }
901
+ endif;
902
+ ?>
includes/mycred-network.php ADDED
@@ -0,0 +1,243 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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-object.php DELETED
@@ -1,227 +0,0 @@
1
- <?php
2
- if ( ! defined( 'myCRED_VERSION' ) ) exit;
3
-
4
- /**
5
- * myCRED_Account class
6
- * @see http://codex.mycred.me/classes/mycred_account/
7
- * @since 1.7
8
- * @version 1.0
9
- */
10
- if ( ! class_exists( 'myCRED_Account' ) ) :
11
- class myCRED_Account extends myCRED_Object {
12
-
13
- public $user_id = false;
14
- public $point_types = array();
15
-
16
- public $balance = false;
17
-
18
- /**
19
- * Construct
20
- */
21
- function __construct( $user_id = NULL, $type = '' ) {
22
-
23
- parent::__construct();
24
-
25
- if ( $user_id === NULL )
26
- $user_id = get_current_user_id();
27
-
28
- $user_id = absint( $user_id );
29
- if ( $user_id === 0 ) return;
30
-
31
- $type = sanitize_key( $type );
32
-
33
- $this->user_id = $user_id;
34
- $this->point_types = mycred_get_types( true );
35
-
36
- $this->populate( $type );
37
-
38
- }
39
-
40
- protected function populate( $type = '' ) {
41
-
42
- if ( empty( $this->point_types ) ) return;
43
-
44
- $this->balance = array();
45
-
46
- // Populate one particular point type
47
- if ( $type != '' && mycred_point_type_exists( $type ) ) {
48
-
49
- $mycred = mycred( $type );
50
-
51
- if ( $mycred->exclude_user( $this->user_id ) ) return;
52
-
53
- $this->balance[] = $this->get_balance( $type, $mycred );
54
-
55
- }
56
-
57
- // Populate all point types
58
- else {
59
-
60
- foreach ( $this->point_types as $type_id => $type_label ) {
61
-
62
- $mycred = mycred( $type_id );
63
-
64
- if ( $mycred->exclude_user( $this->user_id ) ) continue;
65
-
66
- $this->balance[ $type_id ] = $this->get_balance( $type_id, $mycred );
67
-
68
- }
69
-
70
- }
71
-
72
- }
73
-
74
- public function get_balance( $type_id = MYCRED_DEFAULT_TYPE_KEY, $mycred = NULL ) {
75
-
76
- $mycred = $this->get_mycred( $mycred, $type_id );
77
-
78
- $balance = new myCRED_Balance( $this->user_id, $type_id, $mycred );
79
- $balance->type = $this->get_type( $type_id, $mycred );
80
-
81
- return $balance;
82
-
83
- }
84
-
85
- public function get_type( $type_id = MYCRED_DEFAULT_TYPE_KEY, $mycred = NULL ) {
86
-
87
- $mycred = $this->get_mycred( $mycred, $type_id );
88
-
89
- $type = new myCRED_Point_Type( $type_id, $mycred );
90
-
91
- return $type;
92
-
93
- }
94
-
95
- }
96
- endif;
97
-
98
- /**
99
- * myCRED_Balance class
100
- * @see http://codex.mycred.me/classes/mycred_balance/
101
- * @since 1.7
102
- * @version 1.0
103
- */
104
- if ( ! class_exists( 'myCRED_Balance' ) ) :
105
- class myCRED_Balance extends myCRED_Object {
106
-
107
- public $current = 0;
108
- public $accumulated = 0;
109
- public $type = '';
110
-
111
- /**
112
- * Construct
113
- */
114
- function __construct( $user_id = NULL, $type = '', $mycred = NULL ) {
115
-
116
- parent::__construct();
117
-
118
- if ( $user_id === NULL )
119
- $user_id = get_current_user_id();
120
-
121
- $user_id = absint( $user_id );
122
- if ( $user_id === 0 ) return;
123
-
124
- $type = sanitize_key( $type );
125
-
126
- $this->populate( $user_id, $type, $mycred );
127
-
128
- }
129
-
130
- protected function populate( $user_id = NULL, $type_id = '', $mycred = NULL ) {
131
-
132
- $mycred = $this->get_mycred( $mycred, $type_id );
133
-
134
- $this->current = $mycred->get_users_balance( $user_id, $type_id );
135
- $this->accumulated = mycred_get_users_total( $user_id, $type_id );
136
-
137
- }
138
-
139
- }
140
- endif;
141
-
142
- /**
143
- * myCRED_Point_Type class
144
- * @see http://codex.mycred.me/classes/mycred_point_type/
145
- * @since 1.7
146
- * @version 1.0.1
147
- */
148
- if ( ! class_exists( 'myCRED_Point_Type' ) ) :
149
- class myCRED_Point_Type extends myCRED_Object {
150
-
151
- public $cred_id = '';
152
- public $singular = '';
153
- public $plural = '';
154
- public $prefix = '';
155
- public $suffix = '';
156
- public $format = array();
157
-
158
- /**
159
- * Construct
160
- */
161
- function __construct( $type = '', $mycred = NULL ) {
162
-
163
- parent::__construct();
164
-
165
- $type = sanitize_key( $type );
166
- if ( ! mycred_point_type_exists( $type ) ) return;
167
-
168
- $this->populate( $type, $mycred );
169
-
170
- }
171
-
172
- protected function populate( $type_id = '', $mycred = NULL ) {
173
-
174
- $mycred = $this->get_mycred( $mycred, $type_id );
175
-
176
- $this->cred_id = $type_id;
177
- $this->singular = $mycred->singular();
178
- $this->plural = $mycred->plural();
179
- $this->prefix = $mycred->before;
180
- $this->suffix = $mycred->after;
181
- $this->format = $mycred->format;
182
-
183
- }
184
-
185
- public function number( $number ) {
186
-
187
- $number = str_replace( '+', '', $number );
188
-
189
- if ( ! isset( $this->format['decimals'] ) )
190
- $decimals = (int) $this->core['format']['decimals'];
191
-
192
- else
193
- $decimals = (int) $this->format['decimals'];
194
-
195
- $result = intval( $number );
196
- if ( $decimals > 0 )
197
- $result = floatval( number_format( (float) $number, $decimals, '.', '' ) );
198
-
199
- return apply_filters( 'mycred_type_number', $result, $number, $this );
200
-
201
- }
202
-
203
- public function format( $number ) {
204
-
205
- $number = $this->number( $number );
206
- $decimals = $this->format['decimals'];
207
- $sep_dec = $this->format['separators']['decimal'];
208
- $sep_tho = $this->format['separators']['thousand'];
209
-
210
- // Format
211
- $number = number_format( $number, (int) $decimals, $sep_dec, $sep_tho );
212
-
213
- $prefix = '';
214
- if ( ! empty( $this->prefix ) )
215
- $prefix = $this->prefix . ' ';
216
-
217
- // Suffix
218
- $suffix = '';
219
- if ( ! empty( $this->suffix ) )
220
- $suffix = ' ' . $this->suffix;
221
-
222
- return apply_filters( 'mycred_type_format', $prefix . $number . $suffix, $number, $this );
223
-
224
- }
225
-
226
- }
227
- endif;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
includes/mycred-protect.php CHANGED
@@ -47,12 +47,12 @@ if ( ! class_exists( 'myCRED_Protect' ) ) :
47
 
48
  if ( $value === NULL || empty( $value ) ) return false;
49
 
50
- if ( function_exists( 'mcrypt_encrypt' ) ) {
51
-
52
- $text = $value;
53
- $iv_size = mcrypt_get_iv_size( MCRYPT_RIJNDAEL_256, MCRYPT_MODE_ECB );
54
- $iv = mcrypt_create_iv( $iv_size, MCRYPT_RAND );
55
- $crypttext = mcrypt_encrypt( MCRYPT_RIJNDAEL_256, $this->skey, $text, MCRYPT_MODE_ECB, $iv );
56
 
57
  return trim( $this->do_safe_b64encode( $crypttext ) );
58
 
@@ -69,15 +69,14 @@ if ( ! class_exists( 'myCRED_Protect' ) ) :
69
 
70
  if ( $value === NULL || empty( $value ) ) return false;
71
 
72
- if ( function_exists( 'mcrypt_decrypt' ) ) {
73
-
74
  $crypttext = $this->do_safe_b64decode( $value );
75
- $iv_size = mcrypt_get_iv_size( MCRYPT_RIJNDAEL_256, MCRYPT_MODE_ECB );
76
- $iv = mcrypt_create_iv( $iv_size, MCRYPT_RAND );
77
- $decrypttext = mcrypt_decrypt( MCRYPT_RIJNDAEL_256, $this->skey, $crypttext, MCRYPT_MODE_ECB, $iv );
 
78
 
79
  return trim( $decrypttext );
80
-
81
  }
82
 
83
  return $value;
@@ -91,18 +90,17 @@ if ( ! class_exists( 'myCRED_Protect' ) ) :
91
 
92
  if ( $value === NULL || empty( $value ) ) return false;
93
 
94
- if ( function_exists( 'mcrypt_decrypt' ) ) {
95
-
96
  $crypttext = $this->do_safe_b64decode( $value );
97
- $iv_size = mcrypt_get_iv_size( MCRYPT_RIJNDAEL_256, MCRYPT_MODE_ECB );
98
- $iv = mcrypt_create_iv( $iv_size, MCRYPT_RAND );
99
- $decrypttext = mcrypt_decrypt( MCRYPT_RIJNDAEL_256, $this->skey, $crypttext, MCRYPT_MODE_ECB, $iv );
 
100
  $string = trim( $decrypttext );
101
 
102
  parse_str( $string, $output );
103
 
104
  return $output;
105
-
106
  }
107
 
108
  return $value;
47
 
48
  if ( $value === NULL || empty( $value ) ) return false;
49
 
50
+ if ( function_exists( 'openssl_encrypt' ) ) {
51
+ $cipher="AES-256-CBC";
52
+ $text = $value;
53
+ $ivlen = openssl_cipher_iv_length( $cipher);
54
+ $iv = openssl_random_pseudo_bytes($ivlen);
55
+ $crypttext = openssl_encrypt( $text, $cipher, $this->skey, 0, $iv );
56
 
57
  return trim( $this->do_safe_b64encode( $crypttext ) );
58
 
69
 
70
  if ( $value === NULL || empty( $value ) ) return false;
71
 
72
+ if(function_exists( 'openssl_decrypt' )){
 
73
  $crypttext = $this->do_safe_b64decode( $value );
74
+ $cipher = "AES-256-CBC";
75
+ $iv_size = openssl_cipher_iv_length( $cipher);
76
+ $iv = openssl_random_pseudo_bytes($iv_size);
77
+ $decrypttext = openssl_decrypt( $crypttext, $cipher, $this->skey, 0, $iv );
78
 
79
  return trim( $decrypttext );
 
80
  }
81
 
82
  return $value;
90
 
91
  if ( $value === NULL || empty( $value ) ) return false;
92
 
93
+ if(function_exists( 'openssl_decrypt' )){
 
94
  $crypttext = $this->do_safe_b64decode( $value );
95
+ $cipher = "AES-256-CBC";
96
+ $iv_size = openssl_cipher_iv_length( $cipher);
97
+ $iv = openssl_random_pseudo_bytes($iv_size);
98
+ $decrypttext = openssl_decrypt( $crypttext, $cipher, $this->skey, 0, $iv );
99
  $string = trim( $decrypttext );
100
 
101
  parse_str( $string, $output );
102
 
103
  return $output;
 
104
  }
105
 
106
  return $value;
includes/mycred-referrals.php DELETED
@@ -1,72 +0,0 @@
1
- <?php
2
- if ( ! defined( 'myCRED_VERSION' ) ) exit;
3
-
4
- /**
5
- * Load Referral Program
6
- * @since 1.5.3
7
- * @version 1.0
8
- */
9
- if ( ! function_exists( 'mycred_load_referral_program' ) ) :
10
- function mycred_load_referral_program() {
11
-
12
- // BuddyPress: Hook into user activation
13
- if ( function_exists( 'buddypress' ) && apply_filters( 'bp_core_signup_send_activation_key', true ) === true )
14
- add_action( 'bp_core_activated_user', 'mycred_detect_bp_user_activation' );
15
-
16
- // Logged in users do not get points
17
- if ( is_user_logged_in() && apply_filters( 'mycred_affiliate_allow_members', false ) === false ) return;
18
-
19
- // Points for visits
20
- add_action( 'template_redirect', 'mycred_detect_referred_visits' );
21
-
22
- // Points for signups
23
- add_action( 'user_register', 'mycred_detect_referred_signups' );
24
-
25
- }
26
- endif;
27
- add_action( 'mycred_init', 'mycred_load_referral_program' );
28
-
29
- /**
30
- * Detect Referred Visits
31
- * @since 1.5.3
32
- * @version 1.0.1
33
- */
34
- if ( ! function_exists( 'mycred_detect_referred_visits' ) ) :
35
- function mycred_detect_referred_visits() {
36
-
37
- do_action( 'mycred_referred_visit' );
38
-
39
- $keys = apply_filters( 'mycred_referral_keys', array() );
40
- if ( ! empty( $keys ) ) {
41
- wp_redirect( remove_query_arg( $keys ), 301 );
42
- exit;
43
- }
44
-
45
- }
46
- endif;
47
-
48
- /**
49
- * Detect Referred Signups
50
- * @since 1.5.3
51
- * @version 1.0
52
- */
53
- if ( ! function_exists( 'mycred_detect_referred_signups' ) ) :
54
- function mycred_detect_referred_signups( $new_user_id ) {
55
-
56
- do_action( 'mycred_referred_signup', $new_user_id );
57
-
58
- }
59
- endif;
60
-
61
- /**
62
- * Detect Referred BP User Activation
63
- * @since 1.5.3
64
- * @version 1.0
65
- */
66
- if ( ! function_exists( 'mycred_detect_bp_user_activation' ) ) :
67
- function mycred_detect_bp_user_activation( $user_id ) {
68
-
69
- do_action( 'mycred_bp_user_activated', $user_id );
70
-
71
- }
72
- endif;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
includes/mycred-remote.php CHANGED
@@ -56,7 +56,7 @@ if ( ! class_exists( 'myCRED_Remote' ) ) :
56
  if ( get_magic_quotes_gpc() ) {
57
 
58
  $process = array( &$_GET, &$_POST, &$_COOKIE, &$_REQUEST );
59
- while ( list( $key, $val ) = each( $process ) ) {
60
  foreach ( $val as $k => $v ) {
61
  unset( $process[ $key ][ $k ] );
62
  if ( is_array( $v ) ) {
@@ -68,9 +68,7 @@ if ( ! class_exists( 'myCRED_Remote' ) ) :
68
  }
69
  }
70
  unset( $process );
71
-
72
  }
73
-
74
  // Let others play
75
  do_action_ref_array( 'mycred_remote_magic', array( &$this ) );
76
 
56
  if ( get_magic_quotes_gpc() ) {
57
 
58
  $process = array( &$_GET, &$_POST, &$_COOKIE, &$_REQUEST );
59
+ foreach( $process as $key => $val ) {
60
  foreach ( $val as $k => $v ) {
61
  unset( $process[ $key ][ $k ] );
62
  if ( is_array( $v ) ) {
68
  }
69
  }
70
  unset( $process );
 
71
  }
 
72
  // Let others play
73
  do_action_ref_array( 'mycred_remote_magic', array( &$this ) );
74
 
includes/mycred-setup.php DELETED
@@ -1,481 +0,0 @@
1
- <?php
2
- if ( ! defined( 'myCRED_VERSION' ) ) exit;
3
-
4
- /**
5
- * myCRED_Setup class
6
- * Used when the plugin has been activated for the first time. Handles the setup
7
- * wizard along with temporary admin menus.
8
- * @since 0.1
9
- * @version 1.2
10
- */
11
- if ( ! class_exists( 'myCRED_Setup' ) ) :
12
- class myCRED_Setup {
13
-
14
- public $status = false;
15
- public $core;
16
-
17
- /**
18
- * Construct
19
- */
20
- function __construct() {
21
-
22
- $this->core = mycred();
23
-
24
- }
25
-
26
- /**
27
- * Load Class
28
- * @since 1.7
29
- * @version 1.0
30
- */
31
- public function load() {
32
-
33
- add_action( 'admin_notices', array( $this, 'admin_notice' ) );
34
- add_action( 'admin_menu', array( $this, 'setup_menu' ) );
35
-
36
- add_action( 'wp_ajax_mycred-setup', array( $this, 'ajax_setup' ) );
37
-
38
- }
39
-
40
- /**
41
- * Setup Setup Nag
42
- * @since 0.1
43
- * @version 1.0
44
- */
45
- public function admin_notice() {
46
-
47
- $screen = get_current_screen();
48
- if ( $screen->id == 'plugins_page_' . MYCRED_SLUG . '-setup' || ( isset( $_GET['action'] ) && $_GET['action'] === 'edit' ) || ! mycred_is_admin() ) return;
49
-
50
- echo '<div class="info notice notice-info"><p>' . __( 'myCRED needs your attention.', 'mycred' ) . ' <a href="' . admin_url( 'plugins.php?page=' . MYCRED_SLUG . '-setup' ) . '">' . __( 'Run Setup', 'mycred' ) . '</a></p></div>';
51
-
52
- }
53
-
54
- /**
55
- * Add Setup page under "Plugins"
56
- * @since 0.1
57
- * @version 1.0
58
- */
59
- public function setup_menu() {
60
-
61
- $page = add_submenu_page(
62
- 'plugins.php',
63
- __( 'myCRED Setup', 'mycred' ),
64
- __( 'myCRED Setup', 'mycred' ),
65
- 'manage_options',
66
- MYCRED_SLUG . '-setup',
67
- array( $this, 'setup_page' )
68
- );
69
-
70
- add_action( 'admin_print_styles-' . $page, array( $this, 'settings_header' ) );
71
-
72
- }
73
-
74
- /**
75
- * Setup Header
76
- * @since 0.1
77
- * @version 1.1
78
- */
79
- public function settings_header() {
80
-
81
- wp_enqueue_style( 'mycred-admin' );
82
- wp_enqueue_style( 'mycred-bootstrap-grid' );
83
- wp_enqueue_style( 'mycred-forms' );
84
-
85
- }
86
-
87
- /**
88
- * Setup Screen
89
- * Outputs the setup page.
90
- * @since 0.1
91
- * @version 1.2.1
92
- */
93
- public function setup_page() {
94
-
95
- $whitelabel = mycred_label();
96
-
97
- ?>
98
- <style type="text/css">
99
- #myCRED-wrap p { font-size: 13px; line-height: 17px; }
100
- #mycred-setup-completed, #mycred-setup-progress { padding-top: 48px; }
101
- #mycred-setup-completed h1, #mycred-setup-progress h1 { font-size: 3em; line-height: 3.2em; }
102
- pre { margin: 0 0 12px 0; padding: 10px; background-color: #dedede; }
103
- </style>
104
- <div class="wrap mycred-metabox" id="myCRED-wrap">
105
- <h1><?php printf( __( '%s Setup', 'mycred' ), $whitelabel ); ?></h1>
106
- <p><?php printf( __( 'Before you can begin using %s, you must setup your first point type. This includes what you want to call your points, how these points are presented and who has access to it.', 'mycred' ), $whitelabel ); ?></p>
107
- <form method="post" action="" class="form" id="mycred-setup-form">
108
-
109
- <div class="row">
110
- <div class="col-lg-12 col-md-12 col-sm-12 col-xs-12">
111
- <h1><?php _e( 'Your First Point Type', 'mycred' ); ?></h1>
112
- </div>
113
- </div>
114
-
115
- <div id="mycred-form-content">
116
-
117
- <?php $this->new_point_type(); ?>
118
-
119
- <?php do_action( 'mycred_setup_after_form' ); ?>
120
-
121
- </div>
122
-
123
- <div id="mycred-advanced-setup-options" style="display: none;">
124
-
125
- <div class="row">
126
- <div class="col-lg-12 col-md-12 col-sm-12 col-xs-12">
127
- <h1><?php _e( 'Advanced Settings', 'mycred' ); ?></h1>
128
- </div>
129
- </div>
130
-
131
- <div class="row">
132
- <div class="col-lg-6 col-md-6 col-sm-12 col-xs-12">
133
- <h3><?php _e( 'Change Default Point Type Key', 'mycred' ); ?></h3>
134
- <pre>define( 'MYCRED_DEFAULT_TYPE_KEY', 'yourkey' );</pre>
135
- <p><span class="description"><?php _e( 'You can change the meta key used to store the default point type using the MYCRED_DEFAULT_TYPE_KEY constant. Copy the above code to your wp-config.php file to use.', 'mycred' ); ?></span></p>
136
- <p><span class="description"><?php _e( 'If you intend to change the default meta key, you should do so before continuing on in this setup!', 'mycred' ); ?></span></p>
137
- </div>
138
- <div class="col-lg-6 col-md-6 col-sm-12 col-xs-12">
139
- <h3><?php _e( 'Whitelabel', 'mycred' ); ?></h3>
140
- <pre>define( 'MYCRED_DEFAULT_LABEL', 'SuperPoints' );</pre>
141
- <p><span class="description"><?php _e( 'You can re-label myCRED using the MYCRED_DEFAULT_LABEL constant. Copy the above code to your wp-config.php file to use.', 'mycred' ); ?></span></p>
142
- </div>
143
- </div>
144
-
145
- </div>
146
-
147
- <div class="row">
148
- <div class="col-lg-12 col-md-12 col-sm-12 col-xs-12">
149
- <p><input type="submit" class="button button-primary button-large" value="<?php _e( 'Create Point Type', 'mycred' ); ?>" /><button type="button" id="toggle-advanced-options" class="button button-secondary pull-right" data-hide="<?php _e( 'Hide', 'mycred' ); ?>" data-show="<?php _e( 'Advanced', 'mycred' ); ?>"><?php _e( 'Advanced', 'mycred' ); ?></button></p>
150
- </div>
151
- </div>
152
-
153
- </form>
154
- <div id="mycred-setup-progress" style="display: none;">
155
- <h1 class="text-center"><?php _e( 'Processing ...', 'mycred' ); ?></h1>
156
- </div>
157
- <div id="mycred-setup-completed" style="display: none;">
158
- <div class="row">
159
- <div class="col-lg-12 col-md-12 col-sm-12 col-xs-12">
160
- <h1 class="text-center"><?php _e( 'Setup Complete!', 'mycred' ); ?></h1>
161
- <p class="text-center" style="font-weight: bold; color: green;"><?php _e( 'Congratulations! You are now ready to use myCRED. What\'s next?', 'mycred' ); ?></p>
162
- </div>
163
- </div>
164
- <div class="row">
165
- <div class="col-lg-4 col-md-4 col-sm-12 col-xs-12">
166
- <h3><?php _e( 'Enabling Hooks', 'mycred' ); ?></h3>
167
- <p><span class="description"><?php _e( 'If you intend to give your users points for interacting with your website automatically, your next step should be to enable and setup the hooks you want to use.', 'mycred' ); ?></span></p>
168
- <p><a href="<?php echo esc_url( add_query_arg( array( 'page' => MYCRED_SLUG . '-hooks' ), admin_url( 'admin.php' ) ) ); ?>" class="button button-secondary"><?php _e( 'Setup Hooks', 'mycred' ); ?></a></p>
169
- </div>
170
- <div class="col-lg-4 col-md-4 col-sm-12 col-xs-12">
171
- <h3><?php _e( 'Add-ons', 'mycred' ); ?></h3>
172
- <p><span class="description"><?php _e( 'If you want to use advanced features such as Transfers, Point Purchases etc. your next step should be to enable and setup your add-ons.', 'mycred' ); ?></span></p>
173
- <p><a href="<?php echo esc_url( add_query_arg( array( 'page' => MYCRED_SLUG . '-addons' ), admin_url( 'admin.php' ) ) ); ?>" class="button button-secondary"><?php _e( 'Setup Add-ons', 'mycred' ); ?></a></p>
174
- </div>
175
- <div class="col-lg-4 col-md-4 col-sm-12 col-xs-12">
176
- <h3><?php _e( 'Adjust Settings', 'mycred' ); ?></h3>
177
- <p><span class="description"><?php _e( 'If you need to make further changes to your settings or add new point types, you can visit your default point type\'s settings.', 'mycred' ); ?></span></p>
178
- <p><a href="<?php echo esc_url( add_query_arg( array( 'page' => MYCRED_SLUG . '-settings' ), admin_url( 'admin.php' ) ) ); ?>" class="button button-secondary"><?php _e( 'View Settings', 'mycred' ); ?></a></p>
179
- </div>
180
- </div>
181
- </div>
182
- </div>
183
- <script type="text/javascript">
184
- jQuery(function($) {
185
-
186
- $( '#toggle-advanced-options' ).click(function(){
187
-
188
- var hidelabel = $(this).data( 'hide' );
189
- var showlabel = $(this).data( 'show' );
190
-
191
- if ( ! $(this).hasClass( 'open' ) ) {
192
- $( '#mycred-advanced-setup-options' ).slideDown();
193
- $(this).text( hidelabel ).addClass( 'open' );
194
- }
195
- else {
196
- $( '#mycred-advanced-setup-options' ).slideUp();
197
- $(this).text( showlabel ).removeClass( 'open' );
198
- }
199
-
200
- });
201
-
202
- $( '#myCRED-wrap' ).on( 'submit', 'form#mycred-setup-form', function(e){
203
-
204
- var progressbox = $( '#mycred-setup-progress' );
205
- var completedbox = $( '#mycred-setup-completed' );
206
- var setupform = $(this);
207
-
208
- e.preventDefault();
209
-
210
- $.ajax({
211
- type : "POST",
212
- data : {
213
- action : 'mycred-setup',
214
- setup : $(this).serialize(),
215
- token : '<?php echo wp_create_nonce( 'mycred-run-setup' ); ?>'
216
- },
217
- dataType : "JSON",
218
- url : ajaxurl,
219
- beforeSend : function(){
220
-
221
- setupform.hide();
222
- progressbox.show();
223
-
224
- if ( $( '#toggle-advanced-options' ).hasClass( 'open' ) )
225
- $( '#toggle-advanced-options' ).click();
226
-
227
-
228
- },
229
- success : function( response ) {
230
-
231
- console.log( response );
232
-
233
- if ( response.success === undefined )
234
- location.reload();
235
-
236
- else {
237
-
238
- progressbox.hide();
239
-
240
- if ( response.success ) {
241
- completedbox.slideDown();
242
- setupform.remove();
243
- }
244
- else {
245
- $( '#mycred-form-content' ).empty().append( response.data );
246
- setupform.slideDown();
247
- }
248
-
249
- }
250
-
251
- }
252
- });
253
-
254
- });
255
-
256
- });
257
- </script>
258
- <?php
259
-
260
- }
261
-
262
- /**
263
- * New Point Type Form
264
- * @since 1.7
265
- * @version 1.1
266
- */
267
- protected function new_point_type( $posted = array() ) {
268
-
269
- $mycred = mycred();
270
- $posted = wp_parse_args( $posted, $mycred->defaults() );
271
-
272
- ?>
273
- <div class="row">
274
- <div class="col-lg-6 col-md-6 col-sm-12 col-xs-12">
275
- <h3><?php _e( 'Labels', 'mycred' ); ?></h3>
276
- <div class="row">
277
- <div class="col-lg-6 col-md-6 col-sm-12 col-xs-12">
278
- <div class="form-group">
279
- <label for="mycred-setup-name-singular"><?php _e( 'Singular', 'mycred' ); ?></label>
280
- <input type="text" name="first_type[name][singular]" id="mycred-setup-name-singular" placeholder="<?php _e( 'Required', 'mycred' ); ?>" class="form-control" value="<?php echo esc_attr( $posted['name']['singular'] ); ?>" />
281
- </div>
282
- </div>
283
- <div class="col-lg-6 col-md-6 col-sm-12 col-xs-12">
284
- <div class="form-group">
285
- <label for="mycred-setup-name-plural"><?php _e( 'Plural', 'mycred' ); ?></label>
286
- <input type="text" name="first_type[name][plural]" id="mycred-setup-name-plural" placeholder="<?php _e( 'Required', 'mycred' ); ?>" class="form-control" value="<?php echo esc_attr( $posted['name']['plural'] ); ?>" />
287
- </div>
288
- </div>
289
- </div>
290
- <p><span class="description"><?php _e( 'These labels are used throughout the admin area and when presenting points to your users.', 'mycred' ); ?></span></p>
291
- </div>
292
- <div class="col-lg-6 col-md-6 col-sm-12 col-xs-12">
293
- <h3><?php _e( 'Format', 'mycred' ); ?></h3>
294
- <div class="row">
295
- <div class="col-lg-2 col-md-2 col-sm-12 col-xs-12">
296
- <div class="form-group">
297
- <label for="mycred-setup-before"><?php _e( 'Prefix', 'mycred' ); ?></label>
298
- <input type="text" name="first_type[before]" id="mycred-setup-before" class="form-control" value="<?php echo esc_attr( $posted['before'] ); ?>" />
299
- </div>
300
- </div>
301
- <div class="col-lg-5 col-md-5 col-sm-12 col-xs-12">
302
- <div class="form-group">
303
- <label for="mycred-setup-format-separators-thousand"><?php _e( 'Separators', 'mycred' ); ?></label>
304
- <div class="form-inline">
305
- <label>1</label> <input type="text" name="first_type[format][separators][thousand]" id="mycred-setup-format-separators-thousand" placeholder="," class="form-control" size="2" value="<?php echo esc_attr( $posted['format']['separators']['thousand'] ); ?>" /> <label>000</label> <input type="text" name="first_type[format][separators][decimal]" id="mycred-setup-format-separators-decimal" placeholder="." class="form-control" size="2" value="<?php echo esc_attr( $posted['format']['separators']['decimal'] ); ?>" /> <label>00</label>
306
- </div>
307
- </div>
308
- </div>
309
- <div class="col-lg-3 col-md-3 col-sm-12 col-xs-12">
310
- <div class="form-group">
311
- <label for=""><?php _e( 'Decimals', 'mycred' ); ?></label>
312
- <input type="text" name="first_type[format][decimals]" id="mycred-setup-format-decimals" placeholder="0" class="form-control" value="<?php echo esc_attr( $posted['format']['decimals'] ); ?>" />
313
- </div>
314
- </div>
315
- <div class="col-lg-2 col-md-2 col-sm-12 col-xs-12">
316
- <div class="form-group">
317
- <label for=""><?php _e( 'Suffix', 'mycred' ); ?></label>
318
- <input type="text" name="first_type[after]" id="mycred-setup-after" class="form-control" value="<?php echo esc_attr( $posted['after'] ); ?>" />
319
- </div>
320
- </div>
321
- </div>
322
- <p><span class="description"><?php _e( 'Set to decimals to zero if you prefer to use whole numbers.', 'mycred' ); ?></span></p>
323
- </div>
324
- </div>
325
-
326
- <div class="row">
327
- <div class="col-lg-12 col-md-12 col-sm-12 col-xs-12">
328
- <h3><?php _e( 'Security', 'mycred' ); ?></h3>
329
- <div class="row">
330
- <div class="col-lg-3 col-md-3 col-sm-12 col-xs-12">
331
- <div class="form-group">
332
- <label for="mycred-setup-caps-creds"><?php _e( 'Point Editors', 'mycred' ); ?></label>
333
- <input type="text" name="first_type[caps][creds]" id="mycred-setup-caps-creds" placeholder="<?php _e( 'Required', 'mycred' ); ?>" class="form-control" value="<?php echo esc_attr( $posted['caps']['creds'] ); ?>" />
334
- <p><span class="description"><?php _e( 'The capability of users who can edit balances.', 'mycred' ); ?></span></p>
335
- </div>
336
- </div>
337
- <div class="col-lg-3 col-md-3 col-sm-12 col-xs-12">
338
- <div class="form-group">
339
- <label for="mycred-setup-caps-plugin"><?php _e( 'Point Administrators', 'mycred' ); ?></label>
340
- <input type="text" name="first_type[caps][plugin]" id="mycred-setup-caps-plugin" placeholder="<?php _e( 'Required', 'mycred' ); ?>" class="form-control" value="<?php echo esc_attr( $posted['caps']['plugin'] ); ?>" />
341
- <p><span class="description"><?php _e( 'The capability of users who can edit settings.', 'mycred' ); ?></span></p>
342
- </div>
343
- </div>
344
- <div class="col-lg-2 col-md-2 col-sm-12 col-xs-12">
345
- <div class="form-group">
346
- <label for="mycred-setup-max"><?php _e( 'Max. Amount', 'mycred' ); ?></label>
347
- <input type="text" name="first_type[max]" id="mycred-setup-max" class="form-control" value="<?php echo esc_attr( $posted['max'] ); ?>" />
348
- <p><span class="description"><?php _e( 'The maximum amount allowed to be paid out in a single instance.', 'mycred' ); ?></span></p>
349
- </div>
350
- </div>
351
- <div class="col-lg-4 col-md-4 col-sm-12 col-xs-12">
352
- <div class="form-group">
353
- <label for="mycred-setup-exclude-list"><?php _e( 'Exclude by User ID', 'mycred' ); ?></label>
354
- <input type="text" name="first_type[exclude][list]" id="mycred-setup-exclude-list" placeholder="<?php _e( 'Optional', 'mycred' ); ?>" class="form-control" value="<?php echo esc_attr( $posted['exclude']['list'] ); ?>" />
355
- <p><span class="description"><?php _e( 'Comma separated list of user IDs to exclude from using this point type.', 'mycred' ); ?></span></p>
356
- </div>
357
- <div class="form-group">
358
- <div class="checkbox">
359
- <label for="mycred-setup-exclude-cred-editors"><input type="checkbox" name="first_type[exclude][cred_editors]" id="mycred-setup-exclude-cred-editors"<?php checked( $posted['exclude']['cred_editors'], 1 ); ?> value="1" /> <?php _e( 'Exclude point editors', 'mycred' ); ?></label>
360
- </div>
361
- <div class="checkbox">
362
- <label for="mycred-setup-exclude-plugin-editors"><input type="checkbox" name="first_type[exclude][plugin_editors]" id="mycred-setup-exclude-plugin-editors"<?php checked( $posted['exclude']['plugin_editors'], 1 ); ?> value="1" /> <?php _e( 'Exclude point administrators', 'mycred' ); ?></label>
363
- </div>
364
- </div>
365
- </div>
366
- </div>
367
- </div>
368
- </div>
369
- <?php
370
-
371
- }
372
-
373
- /**
374
- * Process Setup Steps
375
- * @since 0.1
376
- * @version 1.2
377
- */
378
- public function ajax_setup() {
379
-
380
- // Security
381
- check_admin_referer( 'mycred-run-setup', 'token' );
382
-
383
- if ( ! current_user_can( 'manage_options' ) ) wp_send_json_error();
384
-
385
- parse_str( $_POST['setup'], $posted );
386
-
387
- $defaults = $this->core->defaults();
388
- $decimals = 0;
389
-
390
- if ( ! array_key_exists( 'first_type', $posted ) ) {
391
-
392
- ob_start();
393
-
394
- echo '<div class="info notice notice-info"><p>' . __( 'Please make sure you fill out all required fields!', 'mycred' ) . '</a></p></div>';
395
-
396
- $this->new_point_type( $defaults );
397
-
398
- $output = ob_get_contents();
399
- ob_end_clean();
400
-
401
- wp_send_json_error( $output );
402
-
403
- }
404
-
405
- $errors = array();
406
- $setup = mycred_apply_defaults( $defaults, $posted['first_type'] );
407
- $first_type = $defaults;
408
-
409
- $singular_name = sanitize_text_field( $setup['name']['singular'] );
410
- if ( empty( $singular_name ) )
411
- $errors[] = 'empty';
412
-
413
- elseif ( $singular_name != $first_type['name']['singular'] )
414
- $first_type['name']['singular'] = $singular_name;
415
-
416
- $plural_name = sanitize_text_field( $setup['name']['plural'] );
417
- if ( empty( $plural_name ) )
418
- $errors[] = 'empty';
419
-
420
- elseif ( $plural_name != $first_type['name']['plural'] )
421
- $first_type['name']['plural'] = $plural_name;
422
-
423
- $first_type['before'] = sanitize_text_field( $setup['before'] );
424
- $first_type['after'] = sanitize_text_field( $setup['after'] );
425
-
426
- $point_editor_cap = sanitize_key( $setup['caps']['creds'] );
427
- if ( empty( $point_editor_cap ) )
428
- $errors[] = 'empty';
429
-
430
- if ( $point_editor_cap != $first_type['caps']['creds'] )
431
- $first_type['caps']['creds'] = $point_editor_cap;
432
-
433
- $point_admin_cap = sanitize_key( $setup['caps']['plugin'] );
434
- if ( empty( $point_admin_cap ) )
435
- $errors[] = 'empty';
436
-
437
- if ( $point_admin_cap != $first_type['caps']['plugin'] )
438
- $first_type['caps']['plugin'] = $point_admin_cap;
439
-
440
- if ( absint( $setup['format']['decimals'] ) > 0 ) {
441
- $first_type['format']['type'] = 'decimal';
442
- $first_type['format']['decimals'] = absint( $setup['format']['decimals'] );
443
- $decimals = $first_type['format']['decimals'];
444
- }
445
-
446
- $errors = apply_filters( 'mycred_setup_errors', $errors, $posted );
447
-
448
- // Something went wrong
449
- if ( ! empty( $errors ) ) {
450
-
451
- ob_start();
452
-
453
- echo '<div class="info notice notice-info"><p>' . __( 'Please make sure you fill out all required fields!', 'mycred' ) . '</a></p></div>';
454
-
455
- $this->new_point_type( $setup );
456
-
457
- $output = ob_get_contents();
458
- ob_end_clean();
459
-
460
- wp_send_json_error( apply_filters( 'mycred_setup_error_output', $output, $posted ) );
461
-
462
- }
463
-
464
- // Save our first point type
465
- mycred_update_option( 'mycred_pref_core', $first_type );
466
-
467
- // Install database
468
- if ( ! function_exists( 'mycred_install_log' ) )
469
- require_once myCRED_INCLUDES_DIR . 'mycred-functions.php';
470
-
471
- mycred_install_log( $decimals, true );
472
-
473
- mycred_add_option( 'mycred_setup_completed', time() );
474
-
475
- // Return the good news
476
- wp_send_json_success();
477
-
478
- }
479
-
480
- }
481
- endif;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
includes/mycred-shortcodes.php ADDED
@@ -0,0 +1,1056 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ if ( ! defined( 'myCRED_VERSION' ) ) exit;
3
+
4
+ /**
5
+ * myCRED Shortcode: my_balance
6
+ * Returns the current users balance.
7
+ * @see http://codex.mycred.me/shortcodes/mycred_my_balance/
8
+ * @contributor Ian Tasker
9
+ * @since 1.0.9
10
+ * @version 1.2.1
11
+ */
12
+ if ( ! function_exists( 'mycred_render_shortcode_my_balance' ) ) :
13
+ function mycred_render_shortcode_my_balance( $atts )
14
+ {
15
+ extract( shortcode_atts( array(
16
+ 'login' => NULL,
17
+ 'title' => '',
18
+ 'title_el' => 'h1',
19
+ 'balance_el' => 'div',
20
+ 'wrapper' => 1,
21
+ 'type' => 'mycred_default'
22
+ ), $atts ) );
23
+
24
+ $output = '';
25
+
26
+ // Not logged in
27
+ if ( ! is_user_logged_in() ) {
28
+ if ( $login !== NULL ) {
29
+ if ( $wrapper )
30
+ $output .= '<div class="mycred-not-logged-in">';
31
+
32
+ $output .= $login;
33
+
34
+ if ( $wrapper )
35
+ $output .= '</div>';
36
+
37
+ return $output;
38
+ }
39
+ return;
40
+ }
41
+
42
+ $user_id = get_current_user_id();
43
+ $mycred = mycred( $type );
44
+ // Check for exclusion
45
+ if ( $mycred->exclude_user( $user_id ) ) return;
46
+
47
+ if ( ! empty( $type ) )
48
+ $mycred->cred_id = $type;
49
+
50
+ if ( $wrapper )
51
+ $output .= '<div class="mycred-my-balance-wrapper">';
52
+
53
+ // Title
54
+ if ( ! empty( $title ) ) {
55
+ if ( ! empty( $title_el ) )
56
+ $output .= '<' . $title_el . '>';
57
+
58
+ $output .= $title;
59
+
60
+ if ( ! empty( $title_el ) )
61
+ $output .= '</' . $title_el . '>';
62
+ }
63
+
64
+ // Balance
65
+ if ( ! empty( $balance_el ) )
66
+ $output .= '<' . $balance_el . '>';
67
+
68
+ $balance = $mycred->get_users_cred( $user_id, $type );
69
+ $output .= $mycred->format_creds( $balance );
70
+
71
+ if ( ! empty( $balance_el ) )
72
+ $output .= '</' . $balance_el . '>';
73
+
74
+ if ( $wrapper )
75
+ $output .= '</div>';
76
+
77
+ return $output;
78
+ }
79
+ endif;
80
+
81
+ /**
82
+ * myCRED Shortcode: mycred_history
83
+ * Returns the points history.
84
+ * @see http://codex.mycred.me/shortcodes/mycred_history/
85
+ * @since 1.0.9
86
+ * @version 1.1.1
87
+ */
88
+ if ( ! function_exists( 'mycred_render_shortcode_history' ) ) :
89
+ function mycred_render_shortcode_history( $atts )
90
+ {
91
+ extract( shortcode_atts( array(
92
+ 'user_id' => NULL,
93
+ 'number' => NULL,
94
+ 'time' => NULL,
95
+ 'ref' => NULL,
96
+ 'order' => NULL,
97
+ 'show_user' => false,
98
+ 'login' => '',
99
+ 'type' => 'mycred_default'
100
+ ), $atts ) );
101
+
102
+ // If we are not logged in
103
+ if ( ! is_user_logged_in() && ! empty( $login ) ) return '<p class="mycred-history login">' . $login . '</p>';
104
+
105
+ if ( $user_id === NULL )
106
+ $user_id = get_current_user_id();
107
+
108
+ $args = array(
109
+ 'user_id' => $user_id,
110
+ 'ctype' => $type
111
+ );
112
+
113
+ if ( $number !== NULL )
114
+ $args['number'] = $number;
115
+
116
+ if ( $time !== NULL )
117
+ $args['time'] = $time;
118
+
119
+ if ( $ref !== NULL )
120
+ $args['ref'] = $ref;
121
+
122
+ if ( $order !== NULL )
123
+ $args['order'] = $order;
124
+
125
+ $log = new myCRED_Query_Log( $args );
126
+
127
+ if ( $show_user !== true )
128
+ unset( $log->headers['column-username'] );
129
+
130
+ $result = $log->get_display();
131
+ $log->reset_query();
132
+ return $result;
133
+ }
134
+ endif;
135
+
136
+ /**
137
+ * myCRED Shortcode: mycred_leaderboard
138
+ * @see http://codex.mycred.me/shortcodes/mycred_leaderboard/
139
+ * @since 0.1
140
+ * @version 1.4
141
+ */
142
+ if ( ! function_exists( 'mycred_render_shortcode_leaderboard' ) ) :
143
+ function mycred_render_shortcode_leaderboard( $atts, $content = '' )
144
+ {
145
+ extract( shortcode_atts( array(
146
+ 'number' => '-1',
147
+ 'order' => 'DESC',
148
+ 'offset' => 0,
149
+ 'type' => 'mycred_default',
150
+ 'based_on' => 'balance',
151
+ 'wrap' => 'li',
152
+ 'template' => '#%position% %user_profile_link% %cred_f%',
153
+ 'nothing' => __( 'Leaderboard is empty.', 'mycred' ),
154
+ 'current' => 0
155
+ ), $atts ) );
156
+
157
+ if ( ! in_array( $order, array( 'ASC', 'DESC' ) ) )
158
+ $order = 'DESC';
159
+
160
+ if ( $number != '-1' )
161
+ $limit = 'LIMIT ' . absint( $offset ) . ',' . absint( $number );
162
+ else
163
+ $limit = '';
164
+
165
+ $mycred = mycred( $type );
166
+
167
+ global $wpdb;
168
+
169
+ // Leaderboard based on balance
170
+ $based_on = sanitize_text_field( $based_on );
171
+
172
+ if ( $based_on == 'balance' )
173
+ $SQL = $wpdb->prepare( "
174
+ SELECT DISTINCT u.ID, um.meta_value AS cred
175
+ FROM {$wpdb->users} u
176
+ INNER JOIN {$wpdb->usermeta} um
177
+ ON ( u.ID = um.user_id )
178
+ WHERE um.meta_key = %s
179
+ ORDER BY um.meta_value+0 {$order} {$limit};", $type );
180
+ else
181
+ $SQL = $wpdb->prepare( "
182
+ SELECT DISTINCT user_id AS ID, SUM( creds ) AS cred
183
+ FROM {$mycred->log_table}
184
+ WHERE ref = %s
185
+ GROUP BY user_id
186
+ ORDER BY SUM( creds ) {$order} {$limit};", $based_on );
187
+
188
+ $leaderboard = $wpdb->get_results( apply_filters( 'mycred_ranking_sql', $SQL ), 'ARRAY_A' );
189
+
190
+ $output = '';
191
+ $in_list = false;
192
+
193
+ // Get current users object
194
+ $current_user = wp_get_current_user();
195
+
196
+ if ( ! empty( $leaderboard ) ) {
197
+
198
+ // Check if current user is in the leaderboard
199
+ if ( $current == 1 && is_user_logged_in() ) {
200
+
201
+ // Find the current user in the leaderboard
202
+ foreach ( $leaderboard as $position => $user ) {
203
+ if ( $user['ID'] == $current_user->ID ) {
204
+ $in_list = true;
205
+ break;
206
+ }
207
+ }
208
+
209
+ }
210
+
211
+ // Load myCRED
212
+ $mycred = mycred( $type );
213
+
214
+ // Wrapper
215
+ if ( $wrap == 'li' )
216
+ $output .= '<ol class="myCRED-leaderboard">';
217
+
218
+ // Loop
219
+ foreach ( $leaderboard as $position => $user ) {
220
+
221
+ // Prep
222
+ $class = array();
223
+
224
+ // Classes
225
+ $class[] = 'item-' . $position;
226
+ if ( $position == 0 )
227
+ $class[] = 'first-item';
228
+
229
+ if ( $position % 2 != 0 )
230
+ $class[] = 'alt';
231
+
232
+ if ( ! empty( $content ) )
233
+ $template = $content;
234
+
235
+ // Template Tags
236
+ if ( ! function_exists( 'mycred_get_users_rank' ) )
237
+ $layout = str_replace( array( '%rank%', '%ranking%', '%position%' ), $position+1, $template );
238
+ else
239
+ $layout = str_replace( array( '%ranking%', '%position%' ), $position+1, $template );
240
+
241
+ $layout = $mycred->template_tags_amount( $layout, $user['cred'] );
242
+ $layout = $mycred->template_tags_user( $layout, $user['ID'] );
243
+
244
+ // Wrapper
245
+ if ( ! empty( $wrap ) )
246
+ $layout = '<' . $wrap . ' class="%classes%">' . $layout . '</' . $wrap . '>';
247
+
248
+ $layout = str_replace( '%classes%', apply_filters( 'mycred_ranking_classes', implode( ' ', $class ) ), $layout );
249
+ $layout = apply_filters( 'mycred_ranking_row', $layout, $template, $user, $position+1 );
250
+
251
+ $output .= $layout . "\n";
252
+
253
+ }
254
+
255
+ $leaderboard = NULL;
256
+
257
+ // Current user is not in list but we want to show his position
258
+ if ( ! $in_list && $current == 1 && is_user_logged_in() ) {
259
+
260
+ // Flush previous query
261
+ $wpdb->flush();
262
+
263
+ // Get a complete leaderboard with just user IDs
264
+ if ( $based_on == 'balance' )
265
+ $full_SQL = $wpdb->prepare( "
266
+ SELECT DISTINCT u.ID
267
+ FROM {$wpdb->users} u
268
+ INNER JOIN {$wpdb->usermeta} um
269
+ ON ( u.ID = um.user_id )
270
+ WHERE um.meta_key = %s
271
+ ORDER BY um.meta_value+0 {$order};", $type );
272
+ else
273
+ $full_SQL = $wpdb->prepare( "
274
+ SELECT DISTINCT user_id AS ID, SUM( creds ) AS cred
275
+ FROM {$mycred->log_table}
276
+ WHERE ref = %s
277
+ GROUP BY user_id
278
+ ORDER BY SUM( creds ) {$order} {$limit};", $based_on );
279
+
280
+ $full_leaderboard = $wpdb->get_results( $full_SQL, 'ARRAY_A' );
281
+
282
+ if ( ! empty( $full_leaderboard ) ) {
283
+
284
+ // Get current users position
285
+ $current_position = array_search( array( 'ID' => $current_user->ID ), $full_leaderboard );
286
+ $full_leaderboard = NULL;
287
+
288
+ // If position is found
289
+ if ( $current_position !== false ) {
290
+
291
+ // Template Tags
292
+ if ( ! function_exists( 'mycred_get_users_rank' ) )
293
+ $layout = str_replace( array( '%rank%', '%ranking%', '%position%' ), $current_position+1, $template );
294
+ else
295
+ $layout = str_replace( array( '%ranking%', '%position%' ), $current_position+1, $template );
296
+
297
+ $layout = $mycred->template_tags_amount( $layout, $mycred->get_users_cred( $current_user->ID, $type ) );
298
+ $layout = $mycred->template_tags_user( $layout, false, $current_user );
299
+
300
+ // Wrapper
301
+ if ( ! empty( $wrap ) )
302
+ $layout = '<' . $wrap . ' class="%classes%">' . $layout . '</' . $wrap . '>';
303
+
304
+ $layout = str_replace( '%classes%', apply_filters( 'mycred_ranking_classes', implode( ' ', $class ) ), $layout );
305
+ $layout = apply_filters( 'mycred_ranking_row', $layout, $template, $current_user, $current_position+1 );
306
+
307
+ $output .= $layout . "\n";
308
+
309
+ }
310
+ }
311
+
312
+ }
313
+
314
+ if ( $wrap == 'li' )
315
+ $output .= '</ol>';
316
+
317
+ }
318
+
319
+ // No result template is set
320
+ else {
321
+
322
+ $output .= '<p class="mycred-leaderboard-none">' . $nothing . '</p>';
323
+
324
+ }
325
+
326
+ return do_shortcode( apply_filters( 'mycred_leaderboard', $output, $atts ) );
327
+ }
328
+ endif;
329
+
330
+ /**
331
+ * myCRED Shortcode: mycred_my_ranking
332
+ * @see http://codex.mycred.me/shortcodes/mycred_my_ranking/
333
+ * @since 0.1
334
+ * @version 1.4
335
+ */
336
+ if ( ! function_exists( 'mycred_render_shortcode_my_ranking' ) ) :
337
+ function mycred_render_shortcode_my_ranking( $atts )
338
+ {
339
+ extract( shortcode_atts( array(
340
+ 'user_id' => NULL,
341
+ 'ctype' => 'mycred_default',
342
+ 'based_on' => 'balance',
343
+ 'missing' => 0
344
+ ), $atts ) );
345
+
346
+ // If no id is given
347
+ if ( $user_id === NULL ) {
348
+ // Current user must be logged in for this shortcode to work
349
+ if ( ! is_user_logged_in() ) return;
350
+ // Get current user id
351
+ $user_id = get_current_user_id();
352
+ }
353
+
354
+ // If no type is given
355
+ if ( $ctype == '' )
356
+ $ctype = 'mycred_default';
357
+
358
+ $mycred = mycred( $ctype );
359
+
360
+ global $wpdb;
361
+
362
+ $based_on = sanitize_text_field( $based_on );
363
+
364
+ // Get a complete leaderboard with just user IDs
365
+ if ( $based_on == 'balance' )
366
+ $full_SQL = $wpdb->prepare( "
367
+ SELECT DISTINCT u.ID
368
+ FROM {$wpdb->users} u
369
+ INNER JOIN {$wpdb->usermeta} um
370
+ ON ( u.ID = um.user_id )
371
+ WHERE um.meta_key = %s
372
+ ORDER BY um.meta_value+0 {$order};", $ctype );
373
+ else
374
+ $full_SQL = $wpdb->prepare( "
375
+ SELECT DISTINCT user_id AS ID, SUM( creds ) AS cred
376
+ FROM {$mycred->log_table}
377
+ WHERE ref = %s
378
+ GROUP BY user_id
379
+ ORDER BY SUM( creds ) {$order} {$limit};", $based_on );
380
+
381
+ $full_leaderboard = $wpdb->get_results( $full_SQL, 'ARRAY_A' );
382
+
383
+ $position = 0;
384
+ if ( ! empty( $full_leaderboard ) ) {
385
+
386
+ // Get current users position
387
+ $current_position = array_search( array( 'ID' => $user_id ), $full_leaderboard );
388
+ $position = $current_position+1;
389
+
390
+ }
391
+ else $position = $missing;
392
+
393
+ $full_leaderboard = NULL;
394
+
395
+ return apply_filters( 'mycred_get_leaderboard_position', $position, $user_id, $ctype );
396
+ }
397
+ endif;
398
+
399
+ /**
400
+ * myCRED Shortcode: mycred_give
401
+ * This shortcode allows you to award or deduct points from a given user or the current user
402
+ * when this shortcode is executed. You can insert this in page/post content
403
+ * or in a template file. Note that users are awarded/deducted points each time
404
+ * this shortcode exectutes!
405
+ * @see http://codex.mycred.me/shortcodes/mycred_give/
406
+ * @since 1.1
407
+ * @version 1.1.1
408
+ */
409
+ if ( ! function_exists( 'mycred_render_shortcode_give' ) ) :
410
+ function mycred_render_shortcode_give( $atts )
411
+ {
412
+ if ( ! is_user_logged_in() ) return;
413
+
414
+ extract( shortcode_atts( array(
415
+ 'amount' => NULL,
416
+ 'user_id' => '',
417
+ 'log' => '',
418
+ 'ref' => 'gift',
419
+ 'limit' => 0,
420
+ 'type' => 'mycred_default'
421
+ ), $atts ) );
422
+
423
+ if ( $amount === NULL )
424
+ return '<strong>' . __( 'error', 'mycred' ) . '</strong> ' . __( 'Amount missing!', 'mycred' );
425
+
426
+ if ( empty( $log ) )
427
+ return '<strong>' . __( 'error', 'mycred' ) . '</strong> ' . __( 'Log Template Missing!', 'mycred' );
428
+
429
+ $mycred = mycred();
430
+
431
+ if ( empty( $user_id ) )
432
+ $user_id = get_current_user_id();
433
+
434
+ // Check for exclusion
435
+ if ( $mycred->exclude_user( $user_id ) ) return;
436
+
437
+ // Limit
438
+ $limit = abs( $limit );
439
+ if ( $limit != 0 && mycred_count_ref_instances( $ref, $user_id ) >= $limit ) return;
440
+
441
+ $amount = $mycred->number( $amount );
442
+ $mycred->add_creds(
443
+ $ref,
444
+ $user_id,
445
+ $amount,
446
+ $log,
447
+ '',
448
+ '',
449
+ $type
450
+ );
451
+ }
452
+ endif;
453
+
454
+ /**
455
+ * myCRED Shortcode: mycred_link
456
+ * This shortcode allows you to award or deduct points from the current user
457
+ * when their click on a link. The shortcode will generate an anchor element
458
+ * and call the mycred-click-link jQuery script which will award the points.
459
+ *
460
+ * Note! Only HTML5 anchor attributes are supported and this shortcode is only
461
+ * available if the hook is enabled!
462
+ *
463
+ * @see http://codex.mycred.me/shortcodes/mycred_link/
464
+ * @since 1.1
465
+ * @version 1.1
466
+ */
467
+ if ( ! function_exists( 'mycred_render_shortcode_link' ) ) :
468
+ function mycred_render_shortcode_link( $atts, $content = '' )
469
+ {
470
+ global $mycred_link_points;
471
+
472
+ $atts = shortcode_atts( array(
473
+ 'id' => '',
474
+ 'rel' => '',
475
+ 'class' => '',
476
+ 'href' => '',
477
+ 'title' => '',
478
+ 'target' => '',
479
+ 'style' => '',
480
+ 'amount' => 0,
481
+ 'ctype' => 'mycred_default',
482
+ 'hreflang' => '', // for advanced users
483
+ 'media' => '', // for advanced users
484
+ 'type' => '' // for advanced users
485
+ ), $atts );
486
+
487
+ // HREF is required
488
+ if ( empty( $atts['href'] ) )
489
+ return '<strong>' . __( 'error', 'mycred' ) . '</strong> ' . __( 'Anchor missing URL!', 'mycred' );
490
+
491
+ // All links must contain the 'mycred-points-link' class
492
+ if ( empty( $atts['class'] ) )
493
+ $atts['class'] = 'mycred-points-link';
494
+ else
495
+ $atts['class'] = 'mycred-points-link ' . $atts['class'];
496
+
497
+ // If no id exists, make one
498
+ if ( empty( $atts['id'] ) ) {
499
+ $id = str_replace( array( 'http://', 'https://', 'http%3A%2F%2F', 'https%3A%2F%2F' ), 'hs', $atts['href'] );
500
+ $id = str_replace( array( '/', '-', '_', ':', '.', '?', '=', '+', '\\', '%2F' ), '', $id );
501
+ $atts['id'] = $id;
502
+ }
503
+
504
+ // Construct anchor attributes
505
+ $attr = array();
506
+ foreach ( $atts as $attribute => $value ) {
507
+ if ( !empty( $value ) && ! in_array( $attribute, array( 'amount', 'ctype' ) ) ) {
508
+ $attr[] = $attribute . '="' . $value . '"';
509
+ }
510
+ }
511
+
512
+ // Add key
513
+ $token = mycred_create_token( array( $atts['amount'], $atts['ctype'], $atts['id'] ) );
514
+ $attr[] = 'data-token="' . $token . '"';
515
+
516
+ // Make sure jQuery script is called
517
+ $mycred_link_points = true;
518
+
519
+ // Return result
520
+ return '<a ' . implode( ' ', $attr ) . '>' . $content . '</a>';
521
+ }
522
+ endif;
523
+
524
+ /**
525
+ * myCRED Shortcode: mycred_send
526
+ * This shortcode allows the current user to send a pre-set amount of points
527
+ * to a pre-set user. A simpler version of the mycred_transfer shortcode.
528
+ * @see http://codex.mycred.me/shortcodes/mycred_send/
529
+ * @since 1.1
530
+ * @version 1.0
531
+ */
532
+ if ( ! function_exists( 'mycred_render_shortcode_send' ) ) :
533
+ function mycred_render_shortcode_send( $atts, $content = NULL )
534
+ {
535
+ if ( ! is_user_logged_in() ) return;
536
+
537
+ extract( shortcode_atts( array(
538
+ 'amount' => NULL,
539
+ 'to' => NULL,
540
+ 'log' => '',
541
+ 'ref' => 'gift',
542
+ 'type' => 'mycred_default'
543
+ ), $atts ) );
544
+
545
+ // Amount is required
546
+ if ( $amount === NULL )
547
+ return '<strong>' . __( 'error', 'mycred' ) . '</strong> ' . __( 'Amount missing!', 'mycred' );
548
+
549
+ // Recipient is required
550
+ if ( empty( $to ) )
551
+ return '<strong>' . __( 'error', 'mycred' ) . '</strong> ' . __( 'User ID missing for recipient.', 'mycred' );
552
+
553
+ // Log template is required
554
+ if ( empty( $log ) )
555
+ return '<strong>' . __( 'error', 'mycred' ) . '</strong> ' . __( 'Log Template Missing!', 'mycred' );
556
+
557
+ if ( $to == 'author' ) {
558
+ // You can not use this outside the loop
559
+ $author = get_the_author_meta( 'ID' );
560
+ if ( empty( $author ) ) $author = $GLOBALS['post']->post_author;
561
+ $to = $author;
562
+ }
563
+
564
+ global $mycred_sending_points;
565
+
566
+ $mycred = mycred( $type );
567
+ $user_id = get_current_user_id();
568
+
569
+ // Make sure current user or recipient is not excluded!
570
+ if ( $mycred->exclude_user( $to ) || $mycred->exclude_user( $user_id ) ) return;
571
+
572
+ $account_limit = (int) apply_filters( 'mycred_transfer_acc_limit', 0 );
573
+ $balance = $mycred->get_users_cred( $user_id, $type );
574
+ $amount = $mycred->number( $amount );
575
+
576
+ // Insufficient Funds
577
+ if ( $balance-$amount < $account_limit ) return;
578
+
579
+ // We are ready!
580
+ $mycred_sending_points = true;
581
+
582
+ return '<input type="button" class="mycred-send-points-button" data-to="' . $to . '" data-ref="' . $ref . '" data-log="' . $log . '" data-amount="' . $amount . '" data-type="' . $type . '" value="' . $mycred->template_tags_general( $content ) . '" />';
583
+ }
584
+ endif;
585
+
586
+ /**
587
+ * Load myCRED Send Points Footer
588
+ * @since 0.1
589
+ * @version 1.2
590
+ */
591
+ if ( ! function_exists( 'mycred_send_shortcode_footer' ) ) :
592
+ add_action( 'wp_footer', 'mycred_send_shortcode_footer' );
593
+ function mycred_send_shortcode_footer()
594
+ {
595
+ global $mycred_sending_points;
596
+
597
+ if ( $mycred_sending_points === true ) {
598
+ $mycred = mycred();
599
+ $base = array(
600
+ 'ajaxurl' => admin_url( 'admin-ajax.php' ),
601
+ 'token' => wp_create_nonce( 'mycred-send-points' )
602
+ );
603
+
604
+ $language = apply_filters( 'mycred_send_language', array(
605
+ 'working' => __( 'Processing...', 'mycred' ),
606
+ 'done' => __( 'Sent', 'mycred' ),
607
+ 'error' => __( 'Error - Try Again', 'mycred' )
608
+ ) );
609
+ wp_localize_script(
610
+ 'mycred-send-points',
611
+ 'myCREDsend',
612
+ array_merge_recursive( $base, $language )
613
+ );
614
+ wp_enqueue_script( 'mycred-send-points' );
615
+ }
616
+ }
617
+ endif;
618
+
619
+ /**
620
+ * myCRED Send Points Ajax
621
+ * @since 0.1
622
+ * @version 1.3
623
+ */
624
+ if ( ! function_exists( 'mycred_shortcode_send_points_ajax' ) ) :
625
+ add_action( 'wp_ajax_mycred-send-points', 'mycred_shortcode_send_points_ajax' );
626
+ function mycred_shortcode_send_points_ajax()
627
+ {
628
+ // We must be logged in
629
+ if ( ! is_user_logged_in() ) die();
630
+
631
+ // Security
632
+ check_ajax_referer( 'mycred-send-points', 'token' );
633
+
634
+ $mycred_types = mycred_get_types();
635
+ $type = 'mycred_default';
636
+ if ( isset( $_POST['type'] ) )
637
+ $type = sanitize_text_field( $type );
638
+
639
+ if ( ! array_key_exists( $type, $mycred_types ) ) die();
640
+
641
+ $mycred = mycred( $type );
642
+ $user_id = get_current_user_id();
643
+
644
+ $account_limit = (int) apply_filters( 'mycred_transfer_acc_limit', 0 );
645
+ $balance = $mycred->get_users_cred( $user_id, $type );
646
+ $amount = $mycred->number( $_POST['amount'] );
647
+ $new_balance = $balance-$amount;
648
+
649
+ // Insufficient Funds
650
+ if ( $new_balance < $account_limit )
651
+ die();
652
+ // After this transfer our account will reach zero
653
+ elseif ( $new_balance == $account_limit )
654
+ $reply = 'zero';
655
+ // Check if this is the last time we can do these kinds of amounts
656
+ elseif ( $new_balance-$amount < $account_limit )
657
+ $reply = 'minus';
658
+ // Else everything is fine
659
+ else
660
+ $reply = 'done';
661
+
662
+ // First deduct points
663
+ $mycred->add_creds(
664
+ trim( $_POST['reference'] ),
665
+ $user_id,
666
+ 0-$amount,
667
+ trim( $_POST['log'] ),
668
+ $_POST['recipient'],
669
+ array( 'ref_type' => 'user' ),
670
+ $type
671
+ );
672
+
673
+ // Then add to recipient
674
+ $mycred->add_creds(
675
+ trim( $_POST['reference'] ),
676
+ $_POST['recipient'],
677
+ $amount,
678
+ trim( $_POST['log'] ),
679
+ $user_id,
680
+ array( 'ref_type' => 'user' ),
681
+ $type
682
+ );
683
+
684
+ // Share the good news
685
+ wp_send_json( $reply );
686
+ }
687
+ endif;
688
+
689
+ /**
690
+ * myCRED Shortcode: mycred_video
691
+ * This shortcode allows points to be given to the current user
692
+ * for watchinga YouTube video.
693
+ * @see http://codex.mycred.me/shortcodes/mycred_video/
694
+ * @since 1.2
695
+ * @version 1.1.1
696
+ */
697
+ if ( ! function_exists( 'mycred_render_shortcode_video' ) ) :
698
+ function mycred_render_shortcode_video( $atts )
699
+ {
700
+ global $mycred_video_points;
701
+
702
+ $hooks = mycred_get_option( 'mycred_pref_hooks', false );
703
+ if ( $hooks === false ) return;
704
+ $prefs = $hooks['hook_prefs']['video_view'];
705
+
706
+ extract( shortcode_atts( array(
707
+ 'id' => NULL,
708
+ 'width' => 560,
709
+ 'height' => 315,
710
+ 'amount' => $prefs['creds'],
711
+ 'logic' => $prefs['logic'],
712
+ 'interval' => $prefs['interval']
713
+ ), $atts ) );
714
+
715
+ // ID is required
716
+ if ( $id === NULL || empty( $id ) ) return __( 'A video ID is required for this shortcode', 'mycred' );
717
+
718
+ // Interval
719
+ if ( strlen( $interval ) < 3 )
720
+ $interval = abs( $interval * 1000 );
721
+
722
+ // Video ID
723
+ $video_id = str_replace( '-', '__', $id );
724
+
725
+ // Create key
726
+ $key = mycred_create_token( array( 'youtube', $video_id, $amount, $logic, $interval ) );
727
+
728
+ if ( ! isset( $mycred_video_points ) || ! is_array( $mycred_video_points ) )
729
+ $mycred_video_points = array();
730
+
731
+ // Construct YouTube Query
732
+ $query = apply_filters( 'mycred_video_query_youtube', array(
733
+ 'enablejsapi' => 1,
734
+ 'version' => 3,
735
+ 'playerapiid' => 'mycred_vvideo_v' . $video_id,
736
+ 'rel' => 0,
737
+ 'controls' => 1,
738
+ 'showinfo' => 0
739
+ ), $atts, $video_id );
740
+
741
+ // Construct Youtube Query Address
742
+ $url = 'https://www.youtube.com/embed/' . $id;
743
+ $url = add_query_arg( $query, $url );
744
+
745
+ $mycred_video_points[] = 'youtube';
746
+
747
+ // Make sure video source ids are unique
748
+ $mycred_video_points = array_unique( $mycred_video_points );
749
+
750
+ ob_start(); ?>
751
+
752
+ <div class="mycred-video-wrapper youtube-video">
753
+ <iframe id="mycred_vvideo_v<?php echo $video_id; ?>" class="mycred-video mycred-youtube-video" data-vid="<?php echo $video_id; ?>" src="<?php echo $url; ?>" width="<?php echo $width; ?>" height="<?php echo $height; ?>" frameborder="0" webkitallowfullscreen mozallowfullscreen allowfullscreen></iframe>
754
+ <script type="text/javascript">
755
+ function mycred_vvideo_v<?php echo $video_id; ?>( state ) {
756
+ duration[ "<?php echo $video_id; ?>" ] = state.target.getDuration();
757
+ mycred_view_video( "<?php echo $video_id; ?>", state.data, "<?php echo $logic; ?>", "<?php echo $interval; ?>", "<?php echo $key; ?>" );
758
+ }
759
+ </script>
760
+ </div>
761
+ <?php
762
+ $output = ob_get_contents();
763
+ ob_end_clean();
764
+
765
+ // Return the shortcode output
766
+ return apply_filters( 'mycred_video_output', $output, $atts );
767
+ }
768
+ endif;
769
+
770
+ /**
771
+ * myCRED Shortcode: mycred_total_balance
772
+ * This shortcode will return either the current user or a given users
773
+ * total balance based on either all point types or a comma seperated list
774
+ * of types.
775
+ * @see http://codex.mycred.me/shortcodes/mycred_total_balance/
776
+ * @since 1.4.3
777
+ * @version 1.1
778
+ */
779
+ if ( ! function_exists( 'mycred_render_shortcode_total' ) ) :
780
+ function mycred_render_shortcode_total( $atts, $content = '' )
781
+ {
782
+ extract( shortcode_atts( array(
783
+ 'user_id' => NULL,
784
+ 'types' => 'mycred_default',
785
+ 'raw' => 0
786
+ ), $atts ) );
787
+
788
+ // If user ID is not set, get the current users ID
789
+ if ( $user_id === NULL ) {
790
+ // If user is not logged in bail now
791
+ if ( ! is_user_logged_in() ) return $content;
792
+ $user_id = get_current_user_id();
793
+ }
794
+
795
+ // Get types
796
+ $types_to_addup = array();
797
+ $all = false;
798
+ $existing_types = mycred_get_types();
799
+
800
+ if ( $types == 'all' ) {
801
+ $types_to_addup = array_keys( $existing_types );
802
+ }
803
+ else {
804
+ $types = explode( ',', $types );
805
+ if ( ! empty( $types ) ) {
806
+ foreach ( $types as $type_key ) {
807
+ $type_key = sanitize_text_field( $type_key );
808
+ if ( ! array_key_exists( $type_key, $existing_types ) ) continue;
809
+
810
+ if ( ! in_array( $type_key, $types_to_addup ) )
811
+ $types_to_addup[] = $type_key;
812
+ }
813
+ }
814
+ }
815
+
816
+ // In case we still have no types, we add the default one
817
+ if ( empty( $types_to_addup ) )
818
+ $types_to_addup = array( 'mycred_default' );
819
+
820
+ // Add up all point type balances
821
+ $total = 0;
822
+ foreach ( $types_to_addup as $type ) {
823
+ // Get the balance for this type
824
+ $balance = mycred_query_users_total( $user_id, $type );
825
+
826
+ $total = $total+$balance;
827
+ }
828
+
829
+ // If we want the total unformatted return this now
830
+ if ( $raw )
831
+ return $total;
832
+
833
+ // Return formatted
834
+ return apply_filters( 'mycred_total_balances_output', $total, $atts );
835
+ }
836
+ endif;
837
+
838
+ /**
839
+ * myCRED Shortcode: mycred_exchange
840
+ * This shortcode will return an exchange form allowing users to
841
+ * exchange one point type for another.
842
+ * @see http://codex.mycred.me/shortcodes/mycred_exchange/
843
+ * @since 1.5
844
+ * @version 1.0
845
+ */
846
+ if ( ! function_exists( 'mycred_render_shortcode_exchange' ) ) :
847
+ function mycred_render_shortcode_exchange( $atts, $content = '' )
848
+ {
849
+ if ( ! is_user_logged_in() ) return $content;
850
+
851
+ extract( shortcode_atts( array(
852
+ 'from' => '',
853
+ 'to' => '',
854
+ 'rate' => 1,
855
+ 'min' => 1
856
+ ), $atts ) );
857
+
858
+ if ( $from == '' || $to == '' ) return '';
859
+
860
+ $types = mycred_get_types();
861
+ if ( ! array_key_exists( $from, $types ) || ! array_key_exists( $to, $types ) ) return __( 'Point types not found.', 'mycred' );
862
+
863
+ $user_id = get_current_user_id();
864
+
865
+ $mycred_from = mycred( $from );
866
+ if ( $mycred_from->exclude_user( $user_id ) )
867
+ return sprintf( __( 'You are excluded from using %s.', 'mycred' ), $mycred_from->plural() );
868
+
869
+ $balance = $mycred_from->get_users_balance( $user_id, $from );
870
+ if ( $balance < $mycred_from->number( $min ) )
871
+ return __( 'Your balance is too low to use this feature.', 'mycred' );
872
+
873
+ $mycred_to = mycred( $to );
874
+ if ( $mycred_to->exclude_user( $user_id ) )
875
+ return sprintf( __( 'You are excluded from using %s.', 'mycred' ), $mycred_to->plural() );
876
+
877
+ global $mycred_exchange;
878
+
879
+ $token = mycred_create_token( array( $from, $to, $user_id, $rate, $min ) );
880
+
881
+ ob_start(); ?>
882
+
883
+ <style type="text/css">
884
+ #mycred-exchange table tr td { width: 50%; }
885
+ #mycred-exchange table tr td label { display: block; font-weight: bold; font-size: 12px; }
886
+ #mycred-exchange { margin-bottom: 24px; }
887
+ .alert-success { color: green; }
888
+ .alert-warning { color: red; }
889
+ </style>
890
+ <div class="mycred-exchange">
891
+ <form action="" method="post">
892
+ <h3><?php printf( __( 'Convert <span>%s</span> to <span>%s</span>', 'mycred' ), $mycred_from->plural(), $mycred_to->plural() ); ?></h3>
893
+
894
+ <?php if ( isset( $mycred_exchange['message'] ) ) : ?>
895
+ <div class="alert alert-<?php if ( $mycred_exchange['success'] ) echo 'success'; else echo 'warning'; ?>"><?php echo $mycred_exchange['message']; ?></div>
896
+ <?php endif; ?>
897
+
898
+ <table class="table">
899
+ <tr>
900
+ <td colspan="2">
901
+ <label><?php printf( __( 'Your current %s balance', 'mycred' ), $mycred_from->singular() ); ?></label>
902
+ <p><?php echo $mycred_from->format_creds( $balance ); ?></p>
903
+ </td>
904
+ </tr>
905
+ <tr>
906
+ <td>
907
+ <label for="mycred-exchange-amount"><?php _e( 'Amount', 'mycred' ); ?></label>
908
+ <input type="text" size="12" value="0" id="mycred-exchange-amount" name="mycred_exchange[amount]" />
909
+ <?php if ( $min != 0 ) : ?><p><small><?php printf( __( 'Minimum %s', 'mycred' ), $mycred_from->format_creds( $min ) ); ?></small></p><?php endif; ?>
910
+ </td>
911
+ <td>
912
+ <label for="exchange-rate"><?php _e( 'Exchange Rate', 'mycred' ); ?></label>
913
+ <p><?php printf( __( '1 %s = <span class="rate">%s</span> %s', 'mycred' ), $mycred_from->singular(), $rate, $mycred_to->plural() ); ?></p>
914
+ </td>
915
+ </tr>
916
+ </table>
917
+ <input type="hidden" name="mycred_exchange[token]" value="<?php echo $token; ?>" />
918
+ <input type="hidden" name="mycred_exchange[nonce]" value="<?php echo wp_create_nonce( 'mycred-exchange' ); ?>" />
919
+ <input type="submit" class="btn btn-primary button button-primary" value="<?php _e( 'Exchange', 'mycred' ); ?>" />
920
+ <div class="clear clearfix"></div>
921
+ </form>
922
+ </div>
923
+ <?php
924
+ $output = ob_get_contents();
925
+ ob_end_clean();
926
+
927
+ return apply_filters( 'mycred_exchange_output', $output, $atts );
928
+ }
929
+ endif;
930
+
931
+ /**
932
+ * Run Exchange
933
+ * Intercepts and executes exchange requests.
934
+ * @since 1.5
935
+ * @version 1.0
936
+ */
937
+ if ( ! function_exists( 'mycred_run_exchange' ) ) :
938
+ add_filter( 'mycred_init', 'mycred_run_exchange' );
939
+ function mycred_run_exchange()
940
+ {
941
+ if ( ! isset( $_POST['mycred_exchange']['nonce'] ) || ! wp_verify_nonce( $_POST['mycred_exchange']['nonce'], 'mycred-exchange' ) ) return;
942
+
943
+ // Decode token
944
+ $token = mycred_verify_token( $_POST['mycred_exchange']['token'], 5 );
945
+ if ( $token === false ) return;
946
+
947
+ global $mycred_exchange;
948
+ list ( $from, $to, $user_id, $rate, $min ) = $token;
949
+
950
+ // Check point types
951
+ $types = mycred_get_types();
952
+ if ( ! array_key_exists( $from, $types ) || ! array_key_exists( $to, $types ) ) {
953
+ $mycred_exchange = array(
954
+ 'success' => false,
955
+ 'message' => __( 'Point types not found.', 'mycred' )
956
+ );
957
+ return;
958
+ }
959
+
960
+ $user_id = get_current_user_id();
961
+
962
+ // Check for exclusion
963
+ $mycred_from = mycred( $from );
964
+ if ( $mycred_from->exclude_user( $user_id ) ) {
965
+ $mycred_exchange = array(
966
+ 'success' => false,
967
+ 'message' => sprintf( __( 'You are excluded from using %s.', 'mycred' ), $mycred_from->plural() )
968
+ );
969
+ return;
970
+ }
971
+
972
+ // Check balance
973
+ $balance = $mycred_from->get_users_balance( $user_id, $from );
974
+ if ( $balance < $mycred_from->number( $min ) ) {
975
+ $mycred_exchange = array(
976
+ 'success' => false,
977
+ 'message' => __( 'Your balance is too low to use this feature.', 'mycred' )
978
+ );
979
+ return;
980
+ }
981
+
982
+ // Check for exclusion
983
+ $mycred_to = mycred( $to );
984
+ if ( $mycred_to->exclude_user( $user_id ) ) {
985
+ $mycred_exchange = array(
986
+ 'success' => false,
987
+ 'message' => sprintf( __( 'You are excluded from using %s.', 'mycred' ), $mycred_to->plural() )
988
+ );
989
+ return;
990
+ }
991
+
992
+ // Prep Amount
993
+ $amount = abs( $_POST['mycred_exchange']['amount'] );
994
+ $amount = $mycred_from->number( $amount );
995
+
996
+ // Make sure we are sending more then minimum
997
+ if ( $amount < $min ) {
998
+ $mycred_exchange = array(
999
+ 'success' => false,
1000
+ 'message' => sprintf( __( 'You must exchange at least %s!', 'mycred' ), $mycred_from->format_creds( $min ) )
1001
+ );
1002
+ return;
1003
+ }
1004
+
1005
+ // Make sure we have enough points
1006
+ if ( $amount > $balance ) {
1007
+ $mycred_exchange = array(
1008
+ 'success' => false,
1009
+ 'message' => __( 'Insufficient Funds. Please try a lower amount.', 'mycred' )
1010
+ );
1011
+ return;
1012
+ }
1013
+
1014
+ // Let others decline
1015
+ $reply = apply_filters( 'mycred_decline_exchange', false, compact( 'from', 'to', 'user_id', 'rate', 'min', 'amount' ) );
1016
+ if ( $reply === false ) {
1017
+
1018
+ $mycred_from->add_creds(
1019
+ 'exchange',
1020
+ $user_id,
1021
+ 0-$amount,
1022
+ sprintf( __( 'Exchange from %s', 'mycred' ), $mycred_from->plural() ),
1023
+ 0,
1024
+ array( 'from' => $from, 'rate' => $rate, 'min' => $min ),
1025
+ $from
1026
+ );
1027
+
1028
+ $exchanged = $mycred_to->number( ( $amount * $rate ) );
1029
+
1030
+ $mycred_to->add_creds(
1031
+ 'exchange',
1032
+ $user_id,
1033
+ $exchanged,
1034
+ sprintf( __( 'Exchange to %s', 'mycred' ), $mycred_to->plural() ),
1035
+ 0,
1036
+ array( 'to' => $to, 'rate' => $rate, 'min' => $min ),
1037
+ $to
1038
+ );
1039
+
1040
+ $mycred_exchange = array(
1041
+ 'success' => true,
1042
+ 'message' => sprintf( __( 'You have successfully exchanged %s into %s.', 'mycred' ), $mycred_from->format_creds( $amount ), $mycred_to->format_creds( $exchanged ) )
1043
+ );
1044
+
1045
+ }
1046
+ else {
1047
+ $mycred_exchange = array(
1048
+ 'success' => false,
1049
+ 'message' => $reply
1050
+ );
1051
+ return;
1052
+ }
1053
+
1054
+ }
1055
+ endif;
1056
+ ?>
includes/shortcodes/index.php DELETED
@@ -1,3 +0,0 @@
1
- <?php
2
- // Silence is golden.
3
- ?>
 
 
 
includes/shortcodes/mycred_affiliate_id.php DELETED
@@ -1,20 +0,0 @@
1
- <?php
2
- if ( ! defined( 'myCRED_VERSION' ) ) exit;
3
-
4
- /**
5
- * Affiliate ID
6
- * @since 1.5.3
7
- * @version
8
- */
9
- if ( ! function_exists( 'mycred_render_affiliate_id' ) ) :
10
- function mycred_render_affiliate_id( $atts, $content = '' ) {
11
-
12
- $type = MYCRED_DEFAULT_TYPE_KEY;
13
- if ( isset( $atts['type'] ) && $atts['type'] != '' )
14
- $type = $atts['type'];
15
-
16
- return apply_filters( 'mycred_affiliate_id_' . $type, '', $atts, $content );
17
-
18
- }
19
- endif;
20
- add_shortcode( 'mycred_affiliate_id', 'mycred_render_affiliate_id' );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
includes/shortcodes/mycred_affiliate_link.php DELETED
@@ -1,20 +0,0 @@
1
- <?php
2
- if ( ! defined( 'myCRED_VERSION' ) ) exit;
3
-
4
- /**
5
- * Affiliate Link
6
- * @since 1.5.3
7
- * @version
8
- */
9
- if ( ! function_exists( 'mycred_render_affiliate_link' ) ) :
10
- function mycred_render_affiliate_link( $atts, $content = '' ) {
11
-
12
- $type = MYCRED_DEFAULT_TYPE_KEY;
13
- if ( isset( $atts['type'] ) && $atts['type'] != '' )
14
- $type = $atts['type'];
15
-
16
- return apply_filters( 'mycred_affiliate_link_' . $type, '', $atts, $content );
17
-
18
- }
19
- endif;
20
- add_shortcode( 'mycred_affiliate_link', 'mycred_render_affiliate_link' );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
includes/shortcodes/mycred_best_user.php DELETED
@@ -1,137 +0,0 @@
1
- <?php
2
- if ( ! defined( 'myCRED_VERSION' ) ) exit;
3
-
4
- /**
5
- * Best User
6
- * Allows database queries in the history table to determen the
7
- * "best user" based on references, time and point types.
8
- * @since 1.6.7
9
- * @version 1.0.5
10
- */
11
- if ( ! function_exists( 'mycred_render_shortcode_best_user' ) ) :
12
- function mycred_render_shortcode_best_user( $attr, $content = '' ) {
13
-
14
- extract( shortcode_atts( array(
15
- 'ref' => '',
16
- 'from' => '',
17
- 'until' => '',
18
- 'types' => MYCRED_DEFAULT_TYPE_KEY,
19
- 'nothing' => 'No user found',
20
- 'order' => 'DESC',
21
- 'avatar' => 50
22
- ), $attr ) );
23
-
24
- $references = '';
25
- if ( $ref != '' )
26
- $references = explode( ',', $ref );
27
-
28
- $point_types = '';
29
- if ( $types != '' )
30
- $point_types = explode( ',', $types );
31
-
32
- $now = current_time( 'timestamp' );
33
- if ( $from == 'now' )
34
- $from = $now;
35
-
36
- elseif ( $from != '' )
37
- $from = strtotime( $from );
38
-
39
- if ( $from == 0 )
40
- $from = '';
41
-
42
- if ( $until == 'now' )
43
- $until = $now;
44
-
45
- elseif ( $until != '' )
46
- $until = strtotime( $until );
47
-
48
- if ( $until == 0 )
49
- $until = '';
50
-
51
- global $wpdb, $mycred;
52
-
53
- $wheres = $preps = array();
54
-
55
- if ( ! empty( $references ) ) {
56
-
57
- $count = -1;
58
- foreach ( $references as $reference ) {
59
- $reference = sanitize_text_field( $reference );
60
- if ( $reference != '' ) {
61
- $preps[] = $reference;
62
- $count ++;
63
- }
64
- }
65
- if ( $count >= 0 )
66
- $wheres[] = 'ref IN ( %s' . str_repeat( ', %s', $count ) . ' )';
67
-
68
- }
69
-
70
- if ( ! empty( $point_types ) ) {
71
-
72
- $count = -1;
73
- foreach ( $point_types as $type_key ) {
74
- $type_key = sanitize_key( $type_key );
75
- if ( mycred_point_type_exists( $type_key ) ) {
76
- $preps[] = $type_key;
77
- $count ++;
78
- }
79
- }
80
- if ( $count >= 0 )
81
- $wheres[] = 'ctype IN ( %s' . str_repeat( ', %s', $count ) . ' )';
82
-
83
- }
84
-
85
- if ( $from != '' || $until != '' ) {
86
-
87
- if ( $from != '' && $until == '' )
88
- $wheres[] = $wpdb->prepare( "time >= %d", $from );
89
-
90
- elseif ( $from == '' && $until != '' )
91
- $wheres[] = $wpdb->prepare( "time <= %d", $until );
92
-
93
- elseif ( $from != '' && $until != '' )
94
- $wheres[] = $wpdb->prepare( "time BETWEEN %d AND %d", $from, $until );
95
-
96
- }
97
-
98
- if ( empty( $wheres ) ) {
99
- $wheres[] = 'id != %d';
100
- $preps[] = 0;
101
- }
102
-
103
- $where = 'WHERE ' . implode( ' AND ', $wheres );
104
- $where = $wpdb->prepare( $where, $preps );
105
-
106
- if ( ! in_array( $order, array( 'DESC', 'ASC' ) ) )
107
- $order = 'DESC';
108
-
109
- $result = $wpdb->get_row( "SELECT user_id, SUM( creds ) AS total, COUNT(*) AS count FROM {$mycred->log_table} {$where} GROUP BY user_id ORDER BY SUM( creds ) {$order} LIMIT 1;" );
110
- if ( ! isset( $result->user_id ) )
111
- return '<p class="mycred-best-user-no-results text-center">' . $nothing . '</p>';
112
-
113
- $user = get_userdata( $result->user_id );
114
- if ( ! isset( $user->display_name ) )
115
- return '<p class="mycred-best-user-no-results text-center">' . $nothing . '</p>';
116
-
117
- if ( empty( $content ) )
118
- $content = '<div class="mycred-best-user text-center">%avatar%<h4>%display_name%</h4></div>';
119
-
120
- $content = apply_filters( 'mycred_best_user_content', $content, $attr, $mycred->log_table );
121
-
122
- $content = str_replace( '%display_name%', $user->display_name, $content );
123
- $content = str_replace( '%first_name%', $user->first_name, $content );
124
- $content = str_replace( '%last_name%', $user->last_name, $content );
125
- $content = str_replace( '%user_email%', $user->user_email, $content );
126
- $content = str_replace( '%user_login%', $user->user_login, $content );
127
-
128
- $content = str_replace( '%avatar%', get_avatar( $result->user_id, $avatar ), $content );
129
- $content = str_replace( '%total%', $result->total, $content );
130
- $content = str_replace( '%total_abs%', abs( $result->total ), $content );
131
- $content = str_replace( '%count%', $result->count, $content );
132
-
133
- return apply_filters( 'mycred_render_best_user', $content, $result, $attr, $mycred->log_table );
134
-
135
- }
136
- endif;
137
- add_shortcode( 'mycred_best_user', 'mycred_render_shortcode_best_user' );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
includes/shortcodes/mycred_exchange.php DELETED
@@ -1,227 +0,0 @@
1
- <?php
2
- if ( ! defined( 'myCRED_VERSION' ) ) exit;
3
-
4
- /**
5
- * myCRED Shortcode: mycred_exchange
6
- * This shortcode will return an exchange form allowing users to
7
- * exchange one point type for another.
8
- * @see http://codex.mycred.me/shortcodes/mycred_exchange/
9
- * @since 1.5
10
- * @version 1.1
11
- */
12
- if ( ! function_exists( 'mycred_render_shortcode_exchange' ) ) :
13
- function mycred_render_shortcode_exchange( $atts, $content = '' ) {
14
-
15
- if ( ! is_user_logged_in() ) return $content;
16
-
17
- extract( shortcode_atts( array(
18
- 'from' => '',
19
- 'to' => '',
20
- 'rate' => 1,
21
- 'min' => 1,
22
- 'button' => 'Exchange'
23
- ), $atts ) );
24
-
25
- if ( $from == '' || $to == '' ) return '';
26
-
27
- if ( ! mycred_point_type_exists( $from ) || ! mycred_point_type_exists( $to ) ) return __( 'Point type not found.', 'mycred' );
28
-
29
- $user_id = get_current_user_id();
30
-
31
- $mycred_from = mycred( $from );
32
- if ( $mycred_from->exclude_user( $user_id ) )
33
- return sprintf( __( 'You are excluded from using %s.', 'mycred' ), $mycred_from->plural() );
34
-
35
- $balance = $mycred_from->get_users_balance( $user_id, $from );
36
- if ( $balance < $mycred_from->number( $min ) )
37
- return __( 'Your balance is too low to use this feature.', 'mycred' );
38
-
39
- $mycred_to = mycred( $to );
40
- if ( $mycred_to->exclude_user( $user_id ) )
41
- return sprintf( __( 'You are excluded from using %s.', 'mycred' ), $mycred_to->plural() );
42
-
43
- global $mycred_exchange;
44
-
45
- $rate = apply_filters( 'mycred_exchange_rate', $rate, $mycred_from, $mycred_to );
46
- $token = mycred_create_token( array( $from, $to, $user_id, $rate, $min ) );
47
-
48
- ob_start();
49
-
50
- ?>
51
- <div class="mycred-exchange">
52
-
53
- <?php echo $content; ?>
54
-
55
- <?php if ( isset( $mycred_exchange['message'] ) ) : ?>
56
- <div class="alert alert-<?php if ( $mycred_exchange['success'] ) echo 'success'; else echo 'warning'; ?>"><?php echo $mycred_exchange['message']; ?></div>
57
- <?php endif; ?>
58
-
59
- <form action="" method="post" class="form">
60
- <div class="row">
61
- <div class="col-lg-3 col-md-3 col-sm-12 col-xs-12 mycred-exchange-current-balance">
62
- <div class="form-group">
63
- <label><?php printf( __( 'Your current %s balance', 'mycred' ), $mycred_from->singular() ); ?></label>
64
- <p class="form-control-static"><?php echo $mycred_from->format_creds( $balance ); ?></p>
65
- </div>
66
- </div>
67
- <div class="col-lg-3 col-md-3 col-sm-12 col-xs-12 mycred-exchange-current-amount">
68
- <div class="form-group">
69
- <label for="mycred-exchange-amount"><?php _e( 'Amount', 'mycred' ); ?></label>
70
- <input type="text" size="20" placeholder="<?php printf( __( 'Minimum %s', 'mycred' ), $mycred_from->format_creds( $min ) ); ?>" value="" class="form-control" id="mycred-exchange-amount" name="mycred_exchange[amount]" />
71
- </div>
72
- </div>
73
- <div class="col-lg-3 col-md-3 col-sm-12 col-xs-12 mycred-exchange-current-rate">
74
- <div class="form-group">
75
- <label><?php _e( 'Exchange Rate', 'mycred' ); ?></label>
76
- <p class="form-control-static"><?php printf( __( '1 %s = <span class="rate">%s</span> %s', 'mycred' ), $mycred_from->singular(), $rate, ( ( $rate == 1 ) ? $mycred_to->singular() : $mycred_to->plural() ) ); ?></p>
77
- </div>
78
- </div>
79
- <div class="col-lg-3 col-md-3 col-sm-12 col-xs-12mycred-exchange-current-submit">
80
- <div class="form-group">
81
- <input type="submit" class="btn btn-primary btn-lg btn-block" value="<?php echo esc_attr( $button ); ?>" />
82
- </div>
83
- </div>
84
- </div>
85
- <input type="hidden" name="mycred_exchange[token]" value="<?php echo $token; ?>" />
86
- <input type="hidden" name="mycred_exchange[nonce]" value="<?php echo wp_create_nonce( 'mycred-exchange' ); ?>" />
87
- </form>
88
-
89
- </div>
90
- <?php
91
-
92
- $output = ob_get_contents();
93
- ob_end_clean();
94
-
95
- return apply_filters( 'mycred_exchange_output', $output, $atts );
96
-
97
- }
98
- endif;
99
- add_shortcode( 'mycred_exchange', 'mycred_render_shortcode_exchange' );
100
-
101
- /**
102
- * Catch Exchange
103
- * Intercepts and executes exchange requests.
104
- * @since 1.5
105
- * @version 1.1
106
- */
107
- if ( ! function_exists( 'mycred_catch_exchange_requests' ) ) :
108
- function mycred_catch_exchange_requests() {
109
-
110
- if ( ! isset( $_POST['mycred_exchange']['nonce'] ) || ! wp_verify_nonce( $_POST['mycred_exchange']['nonce'], 'mycred-exchange' ) ) return;
111
-
112
- // Decode token
113
- $token = mycred_verify_token( $_POST['mycred_exchange']['token'], 5 );
114
- if ( $token === false ) return;
115
-
116
- global $mycred_exchange;
117
- list ( $from, $to, $user_id, $rate, $min ) = $token;
118
-
119
- // Check point types
120
- $types = mycred_get_types();
121
- if ( ! array_key_exists( $from, $types ) || ! array_key_exists( $to, $types ) ) {
122
- $mycred_exchange = array(
123
- 'success' => false,
124
- 'message' => __( 'Point types not found.', 'mycred' )
125
- );
126
- return;
127
- }
128
-
129
- $user_id = get_current_user_id();
130
-
131
- // Check for exclusion
132
- $mycred_from = mycred( $from );
133
- if ( $mycred_from->exclude_user( $user_id ) ) {
134
- $mycred_exchange = array(
135
- 'success' => false,
136
- 'message' => sprintf( __( 'You are excluded from using %s.', 'mycred' ), $mycred_from->plural() )
137
- );
138
- return;
139
- }
140
-
141
- // Check balance
142
- $balance = $mycred_from->get_users_balance( $user_id, $from );
143
- if ( $balance < $mycred_from->number( $min ) ) {
144
- $mycred_exchange = array(
145
- 'success' => false,
146
- 'message' => __( 'Your balance is too low to use this feature.', 'mycred' )
147
- );
148
- return;
149
- }
150
-
151
- // Check for exclusion
152
- $mycred_to = mycred( $to );
153
- if ( $mycred_to->exclude_user( $user_id ) ) {
154
- $mycred_exchange = array(
155
- 'success' => false,
156
- 'message' => sprintf( __( 'You are excluded from using %s.', 'mycred' ), $mycred_to->plural() )
157
- );
158
- return;
159
- }
160
-
161
- // Prep Amount
162
- $amount = abs( $_POST['mycred_exchange']['amount'] );
163
- $amount = $mycred_from->number( $amount );
164
-
165
- // Make sure we are sending more then minimum
166
- if ( $amount < $min ) {
167
- $mycred_exchange = array(
168
- 'success' => false,
169
- 'message' => sprintf( __( 'You must exchange at least %s!', 'mycred' ), $mycred_from->format_creds( $min ) )
170
- );
171
- return;
172
- }
173
-
174
- // Make sure we have enough points
175
- if ( $amount > $balance ) {
176
- $mycred_exchange = array(
177
- 'success' => false,
178
- 'message' => __( 'Insufficient Funds. Please try a lower amount.', 'mycred' )
179
- );
180
- return;
181
- }
182
-
183
- // Let others decline
184
- $reply = apply_filters( 'mycred_decline_exchange', false, compact( 'from', 'to', 'user_id', 'rate', 'min', 'amount' ) );
185
- if ( $reply === false ) {
186
-
187
- $mycred_from->add_creds(
188
- 'exchange',
189
- $user_id,
190
- 0-$amount,
191
- sprintf( __( 'Exchange from %s', 'mycred' ), $mycred_from->plural() ),
192
- 0,
193
- array( 'from' => $from, 'rate' => $rate, 'min' => $min ),
194
- $from
195
- );
196
-
197
- $exchanged = $mycred_to->number( ( $amount * $rate ) );
198
-
199
- $mycred_to->add_creds(
200
- 'exchange',
201
- $user_id,
202
- $exchanged,
203
- sprintf( __( 'Exchange to %s', 'mycred' ), $mycred_to->plural() ),
204
- 0,
205
- array( 'to' => $to, 'rate' => $rate, 'min' => $min ),
206
- $to
207
- );
208
-
209
- $mycred_exchange = array(
210
- 'success' => true,
211
- 'message' => sprintf( __( 'You have successfully exchanged %s into %s.', 'mycred' ), $mycred_from->format_creds( $amount ), $mycred_to->format_creds( $exchanged ) )
212
- );
213
-
214
- }
215
- else {
216
-
217
- $mycred_exchange = array(
218
- 'success' => false,
219
- 'message' => $reply
220
- );
221
- return;
222
-
223
- }
224
-
225
- }
226
- endif;
227
- add_action( 'mycred_init', 'mycred_catch_exchange_requests', 100 );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
includes/shortcodes/mycred_give.php DELETED
@@ -1,54 +0,0 @@
1
- <?php
2
- if ( ! defined( 'myCRED_VERSION' ) ) exit;
3
-
4
- /**
5
- * myCRED Shortcode: mycred_give
6
- * This shortcode allows you to award or deduct points from a given user or the current user
7
- * when this shortcode is executed. You can insert this in page/post content
8
- * or in a template file. Note that users are awarded/deducted points each time
9
- * this shortcode exectutes!
10
- * @see http://codex.mycred.me/shortcodes/mycred_give/
11
- * @since 1.1
12
- * @version 1.3
13
- */
14
- if ( ! function_exists( 'mycred_render_shortcode_give' ) ) :
15
- function mycred_render_shortcode_give( $atts, $content = '' ) {
16
-
17
- extract( shortcode_atts( array(
18
- 'amount' => '',
19
- 'user_id' => 'current',
20
- 'log' => '',
21
- 'ref' => 'gift',
22
- 'limit' => 0,
23
- 'type' => MYCRED_DEFAULT_TYPE_KEY
24
- ), $atts ) );
25
-
26
- if ( ! is_user_logged_in() && $user_id == 'current' )
27
- return $content;
28
-
29
- if ( ! mycred_point_type_exists( $type ) ) return 'Invalid point type.';
30
-
31
- $mycred = mycred( $type );
32
- $user_id = mycred_get_user_id( $user_id );
33
- $ref = sanitize_key( $ref );
34
- $limit = absint( $limit );
35
-
36
- // Check for exclusion
37
- if ( $mycred->exclude_user( $user_id ) ) return;
38
-
39
- // Limit
40
- if ( $limit > 0 && mycred_count_ref_instances( $ref, $user_id, $type ) >= $limit ) return;
41
-
42
- $mycred->add_creds(
43
- $ref,
44
- $user_id,
45
- $amount,
46
- $log,
47
- '',
48
- '',
49
- $type
50
- );
51
-
52
- }
53
- endif;
54
- add_shortcode( 'mycred_give', 'mycred_render_shortcode_give' );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
includes/shortcodes/mycred_hide_if.php DELETED
@@ -1,122 +0,0 @@
1
- <?php
2
- if ( ! defined( 'myCRED_VERSION' ) ) exit;
3
-
4
- /**
5
- * Hide IF
6
- * Allows content to be shown if a user does not fulfil the set points
7
- * requirements set for this shortcode.
8
- * @since 1.7
9
- * @version 1.0
10
- */
11
- if ( ! function_exists( 'mycred_render_shortcode_hide_if' ) ) :
12
- function mycred_render_shortcode_hide_if( $atts, $content = '' ) {
13
-
14
- extract( shortcode_atts( array(
15
- 'balance' => -1,
16
- 'rank' => -1,
17
- 'ref' => '',
18
- 'count' => -1,
19
- 'ctype' => MYCRED_DEFAULT_TYPE_KEY,
20
- 'visitors' => '',
21
- 'comp' => 'AND',
22
- 'user_id' => 'current'
23
- ), $atts ) );
24
-
25
- // Visitors
26
- if ( ! is_user_logged_in() ) {
27
-
28
- if ( $visitors != '' ) return $visitors;
29
-
30
- return do_shortcode( $content );
31
-
32
- }
33
-
34
- // Get the user ID
35
- $user_id = mycred_get_user_id( $user_id );
36
-
37
- // You can only use AND or OR for comparisons
38
- if ( ! in_array( $comp, array( 'AND', 'OR' ) ) )
39
- $comp = 'AND';
40
-
41
- // Make sure the point type we nominated exists
42
- if ( ! mycred_point_type_exists( $ctype ) ) return 'invalid point type';
43
-
44
- // Load myCRED with the requested point type
45
- $mycred = mycred( $ctype );
46
-
47
- // Make sure user is not excluded
48
- if ( $mycred->exclude_user( $user_id ) ) return do_shortcode( $content );
49
-
50
- // Lets start determening if the content should be hidden from user
51
- $should_hide = false;
52
-
53
- // Balance related requirement
54
- if ( $balance >= 0 ) {
55
-
56
- $users_balance = $mycred->get_users_balance( $user_id, $ctype );
57
- $balance = $mycred->number( $balance );
58
-
59
- // Zero balance requirement
60
- if ( $balance == $mycred->zero() && $users_balance == $mycred->zero() )
61
- $should_hide = true;
62
-
63
- // Balance must be higher or equal to the amount set
64
- elseif ( $users_balance >= $balance )
65
- $should_hide = true;
66
-
67
- }
68
-
69
- // Reference related requirement
70
- if ( strlen( $ref ) > 0 ) {
71
-
72
- $ref_count = mycred_count_ref_instances( $ref, $user_id, $ctype );
73
-
74
- // Combined with a balance requirement we must have references
75
- if ( $balance >= 0 && $ref_count == 0 && $comp === 'AND' )
76
- $should_hide = false;
77
-
78
- // Ref count must be higher or equal to the count set
79
- elseif ( $ref_count >= $count )
80
- $should_hide = true;
81
-
82
- }
83
-
84
- // Rank related requirement
85
- if ( $rank !== -1 && function_exists( 'mycred_get_users_rank' ) ) {
86
-
87
- $rank_id = mycred_get_rank_object_id( $rank );
88
-
89
- // Rank ID provided
90
- if ( is_numeric( $rank ) )
91
- $users_rank = mycred_get_users_rank( $user_id, $ctype );
92
-
93
- // Rank title provided
94
- else
95
- $users_rank = mycred_get_users_rank( $user_id, $ctype );
96
-
97
- if ( isset( $users_rank->post_id ) && $rank_id !== false ) {
98
-
99
- if ( $users_rank->post_id != $rank_id && $comp === 'AND' )
100
- $should_hide = false;
101
-
102
- elseif ( $users_rank->post_id == $rank_id )
103
- $should_hide = true;
104
-
105
- }
106
-
107
- }
108
-
109
- // Allow others to play
110
- $should_hide = apply_filters( 'mycred_hide_if', $should_hide, $user_id, $atts, $content );
111
-
112
- // Sorry, no show
113
- if ( $should_hide !== false ) return;
114
-
115
- $content = '<div class="mycred-hide-this-content">' . $content . '</div>';
116
-
117
- // Return content
118
- return do_shortcode( apply_filters( 'mycred_hide_if_render', $content, $user_id, $atts, $content ) );
119
-
120
- }
121
- endif;
122
- add_shortcode( 'mycred_hide_if', 'mycred_render_shortcode_hide_if' );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
includes/shortcodes/mycred_history.php DELETED
@@ -1,87 +0,0 @@
1
- <?php
2
- if ( ! defined( 'myCRED_VERSION' ) ) exit;
3
-
4
- /**
5
- * myCRED Shortcode: mycred_history
6
- * Returns the points history.
7
- * @see http://codex.mycred.me/shortcodes/mycred_history/
8
- * @since 1.0.9
9
- * @version 1.3.4
10
- */
11
- if ( ! function_exists( 'mycred_render_shortcode_history' ) ) :
12
- function mycred_render_shortcode_history( $atts, $content = '' ) {
13
-
14
- extract( shortcode_atts( array(
15
- 'user_id' => '',
16
- 'number' => 10,
17
- 'time' => '',
18
- 'ref' => '',
19
- 'order' => '',
20
- 'show_user' => 0,
21
- 'show_nav' => 1,
22
- 'login' => '',
23
- 'type' => MYCRED_DEFAULT_TYPE_KEY,
24
- 'pagination' => 10,
25
- 'inlinenav' => 0
26
- ), $atts ) );
27
-
28
- // If we are not logged in
29
- if ( ! is_user_logged_in() && $login != '' )
30
- return $login . $content;
31
-
32
- if ( ! MYCRED_ENABLE_LOGGING ) return '';
33
-
34
- $user_id = mycred_get_user_id( $user_id );
35
-
36
- if ( ! mycred_point_type_exists( $type ) )
37
- $type = MYCRED_DEFAULT_TYPE_KEY;
38
-
39
- $args = array( 'ctype' => $type );
40
-
41
- if ( $user_id != 0 && $user_id != '' )
42
- $args['user_id'] = absint( $user_id );
43
-
44
- if ( absint( $number ) > 0 )
45
- $args['number'] = absint( $number );
46
-
47
- if ( $time != '' )
48
- $args['time'] = $time;
49
-
50
- if ( $ref != '' )
51
- $args['ref'] = $ref;
52
-
53
- if ( $order != '' )
54
- $args['order'] = $order;
55
-
56
- $log = new myCRED_Query_Log( apply_filters( 'mycred_front_history_args', $args, $atts ) );
57
-
58
- ob_start();
59
-
60
- if ( $inlinenav ) echo '<style type="text/css">.mycred-history-wrapper ul li { list-style-type: none; display: inline; padding: 0 6px; }</style>';
61
-
62
- do_action( 'mycred_front_history', $user_id );
63
-
64
- ?>
65
- <div class="mycred-history-wrapper">
66
- <form class="form-inline" role="form" method="get" action="">
67
-
68
- <?php if ( $show_nav == 1 ) $log->front_navigation( 'top', $pagination ); ?>
69
-
70
- <?php $log->display(); ?>
71
-
72
- <?php if ( $show_nav == 1 ) $log->front_navigation( 'bottom', $pagination ); ?>
73
-
74
- </form>
75
- </div>
76
- <?php
77
-
78
- $content = ob_get_contents();
79
- ob_end_clean();
80
-
81
- $log->reset_query();
82
-
83
- return $content;
84
-
85
- }
86
- endif;
87
- add_shortcode( 'mycred_history', 'mycred_render_shortcode_history' );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
includes/shortcodes/mycred_hook_table.php DELETED
@@ -1,130 +0,0 @@
1
- <?php
2
- if ( ! defined( 'myCRED_VERSION' ) ) exit;
3
-
4
- /**
5
- * Hook Table
6
- * Renders a table of all the active hooks and how much a user can
7
- * earn / lose from each hook.
8
- * @since 1.6
9
- * @version 1.1
10
- */
11
- if ( ! function_exists( 'mycred_render_shortcode_hook_table' ) ) :
12
- function mycred_render_shortcode_hook_table( $atts ) {
13
-
14
- extract( shortcode_atts( array(
15
- 'type' => MYCRED_DEFAULT_TYPE_KEY,
16
- 'gains' => 1,
17
- 'user' => '-user-',
18
- 'post' => '-post-',
19
- 'comment' => '-comment-',
20
- 'amount' => '',
21
- 'nothing' => __( 'No instances found for this point type', 'mycred' )
22
- ), $atts ) );
23
-
24
- if ( ! mycred_point_type_exists( $type ) ) return __( 'Point type not found.', 'mycred' );
25
-
26
- $mycred = mycred( $type );
27
- $id = str_replace( '_', '-', $type );
28
- $prefs_key = 'mycred_pref_hooks';
29
-
30
- if ( $type != MYCRED_DEFAULT_TYPE_KEY )
31
- $prefs_key .= '_' . $type;
32
-
33
- $applicable = array();
34
-
35
- $hooks = get_option( $prefs_key, false );
36
- if ( isset( $hooks['active'] ) && ! empty( $hooks['active'] ) ) {
37
-
38
- foreach ( $hooks['active'] as $active_hook_id ) {
39
-
40
- $hook_prefs = $hooks['hook_prefs'][ $active_hook_id ];
41
-
42
- // Single Instance
43
- if ( isset( $hook_prefs['creds'] ) ) {
44
-
45
- if ( ( $gains == 1 && $hook_prefs['creds'] > 0 ) || ( $gains == 0 && $hook_prefs['creds'] < 0 ) )
46
- $applicable[ $active_hook_id ] = $hook_prefs;
47
-
48
- }
49
-
50
- // Multiple Instances
51
- else {
52
-
53
- foreach ( $hook_prefs as $instance_id => $instance_prefs ) {
54
-
55
- if ( ! isset( $instance_prefs['creds'] ) ) continue;
56
-
57
- if ( ( $gains == 1 && $instance_prefs['creds'] > 0 ) || ( $gains == 0 && $instance_prefs['creds'] < 0 ) )
58
- $applicable[ $instance_id ] = $instance_prefs;
59
-
60
- }
61
-
62
- }
63
-
64
- }
65
-
66
- }
67
-
68
- ob_start();
69
-
70
- if ( ! empty( $applicable ) ) {
71
-
72
- ?>
73
- <div class="table-responsive">
74
- <table class="table mycred-hook-table hook-table-<?php echo $id; ?>">
75
- <thead>
76
- <tr>
77
- <th class="column-instance" style="width: 60%;"><?php _e( 'Instance', 'mycred' ); ?></th>
78
- <th class="column-amount" style="width: 20%;"><?php _e( 'Amount', 'mycred' ); ?></th>
79
- <th class="column-limit" style="width: 20%;"><?php _e( 'Limit', 'mycred' ); ?></th>
80
- </tr>
81
- </thead>
82
- <tbody>
83
- <?php
84
-
85
- foreach ( $applicable as $id => $prefs ) {
86
-
87
- $log = $mycred->template_tags_general( $prefs['log'] );
88
-
89
- $log = strip_tags( $log );
90
- $log = str_replace( array( '%user_id%', '%user_name%', '%user_name_en%', '%display_name%', '%user_profile_url%', '%user_profile_link%', '%user_nicename%', '%user_email%', '%user_url%', '%balance%', '%balance_f%' ), $user, $log );
91
- $log = str_replace( array( '%post_title%', '%post_url%', '%link_with_title%', '%post_type%' ), $post, $log );
92
- $log = str_replace( array( 'comment_id', 'c_post_id', 'c_post_title', 'c_post_url', 'c_link_with_title' ), $comment, $log );
93
- $log = str_replace( array( '%cred%', '%cred_f%' ), $amount, $log );
94
- $log = apply_filters( 'mycred_hook_table_log', $log, $id, $prefs, $atts );
95
-
96
- $limit = '';
97
- if ( isset( $prefs['limit'] ) )
98
- $limit = $prefs['limit'];
99
-
100
- $creds = apply_filters( 'mycred_hook_table_creds', $mycred->format_creds( $prefs['creds'] ), $id, $prefs, $atts );
101
-
102
- ?>
103
- <tr>
104
- <td class="column-instance"><?php echo $log; ?></td>
105
- <td class="column-amount"><?php echo $creds; ?></td>
106
- <td class="column-limit"><?php echo mycred_translate_limit_code( $limit ); ?></td>
107
- </tr>
108
- <?php
109
-
110
- }
111
-
112
- ?>
113
- </tbody>
114
- </table>
115
- </div>
116
- <?php
117
-
118
- }
119
- else {
120
- echo '<p>' . $nothing . '</p>';
121
- }
122
-
123
- $content = ob_get_contents();
124
- ob_end_clean();
125
-
126
- return apply_filters( 'mycred_render_hook_table', $content, $atts );
127
-
128
- }
129
- endif;
130
- add_shortcode( 'mycred_hook_table', 'mycred_render_shortcode_hook_table' );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
includes/shortcodes/mycred_leaderboard.php DELETED
@@ -1,42 +0,0 @@
1
- <?php
2
- if ( ! defined( 'myCRED_VERSION' ) ) exit;
3
-
4
- /**
5
- * myCRED Shortcode: mycred_leaderboard
6
- * @see http://codex.mycred.me/shortcodes/mycred_leaderboard/
7
- * @since 0.1
8
- * @version 1.6
9
- */
10
- if ( ! function_exists( 'mycred_render_shortcode_leaderboard' ) ) :
11
- function mycred_render_shortcode_leaderboard( $atts, $content = '' ) {
12
-
13
- $args = shortcode_atts( array(
14
- 'number' => 25,
15
- 'order' => 'DESC',
16
- 'offset' => 0,
17
- 'type' => MYCRED_DEFAULT_TYPE_KEY,
18
- 'based_on' => 'balance',
19
- 'total' => 0,
20
- 'wrap' => 'li',
21
- 'template' => '#%position% %user_profile_link% %cred_f%',
22
- 'nothing' => 'Leaderboard is empty',
23
- 'current' => 0,
24
- 'exclude_zero' => 1,
25
- 'timeframe' => ''
26
- ), $atts );
27
-
28
- if ( ! MYCRED_ENABLE_LOGGING ) return '';
29
-
30
- // Construct the leaderboard class
31
- $leaderboard = mycred_get_leaderboard( $args );
32
-
33
- // Just constructing the class will not yeld any results
34
- // We need to run the query to populate the leaderboard
35
- $leaderboard->get_leaderboard_results( (bool) $args['current'] );
36
-
37
- // Render and return
38
- return do_shortcode( $leaderboard->render( $args, $content ) );
39
-
40
- }
41
- endif;
42
- add_shortcode( 'mycred_leaderboard', 'mycred_render_shortcode_leaderboard' );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
includes/shortcodes/mycred_leaderboard_position.php DELETED
@@ -1,63 +0,0 @@
1
- <?php
2
- if ( ! defined( 'myCRED_VERSION' ) ) exit;
3
-
4
- /**
5
- * myCRED Shortcode: mycred_leaderboard_position
6
- * @see http://codex.mycred.me/shortcodes/mycred_leaderboard_position/
7
- * Replaces the mycred_my_ranking shortcode.
8
- * @since 1.7
9
- * @version 1.2
10
- */
11
- if ( ! function_exists( 'mycred_render_shortcode_leaderbaord_position' ) ) :
12
- function mycred_render_shortcode_leaderbaord_position( $atts, $content = '' ) {
13
-
14
- $args = shortcode_atts( array(
15
- 'user_id' => 'current',
16
- 'ctype' => MYCRED_DEFAULT_TYPE_KEY,
17
- 'type' => '',
18
- 'based_on' => 'balance',
19
- 'total' => 0,
20
- 'missing' => '-',
21
- 'suffix' => 0,
22
- 'timeframe' => ''
23
- ), $atts );
24
-
25
- if ( ! MYCRED_ENABLE_LOGGING ) return $content;
26
-
27
- // Get the user ID we need a position for
28
- $user_id = mycred_get_user_id( $args['user_id'] );
29
-
30
- // Backwards comp.
31
- if ( $args['type'] == '' )
32
- $args['type'] = $args['ctype'];
33
-
34
- // Construct the leaderboard class
35
- $leaderboard = mycred_get_leaderboard( $args );
36
-
37
- // Query the users position
38
- $position = $leaderboard->get_users_current_position( $user_id, $missing );
39
-
40
- if ( $position != $missing && $suffix == 1 )
41
- $position = mycred_ordinal_suffix( $position, true );
42
-
43
- return $position;
44
-
45
- }
46
- endif;
47
- add_shortcode( 'mycred_leaderboard_position', 'mycred_render_shortcode_leaderbaord_position' );
48
-
49
- /**
50
- * myCRED Shortcode: mycred_my_ranking
51
- * @see http://codex.mycred.me/shortcodes/mycred_my_ranking/
52
- * Depreciated since 1.7. Replaced by mycred_leaderboard_position
53
- * @since 0.1
54
- * @version 1.6
55
- */
56
- if ( ! function_exists( 'mycred_render_shortcode_my_ranking' ) ) :
57
- function mycred_render_shortcode_my_ranking( $atts, $content = '' ) {
58
-
59
- return mycred_render_shortcode_leaderbaord_position( $atts, $content );
60
-
61
- }
62
- endif;
63
- add_shortcode( 'mycred_my_ranking', 'mycred_render_shortcode_my_ranking' );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
includes/shortcodes/mycred_link.php DELETED
@@ -1,102 +0,0 @@
1
- <?php
2
- if ( ! defined( 'myCRED_VERSION' ) ) exit;
3
-
4
- /**
5
- * myCRED Shortcode: mycred_link
6
- * This shortcode allows you to award or deduct points from the current user
7
- * when their click on a link. The shortcode will generate an anchor element
8
- * and call the mycred-click-link jQuery script which will award the points.
9
- *
10
- * Note! Only HTML5 anchor attributes are supported and this shortcode is only
11
- * available if the hook is enabled!
12
- *
13
- * @see http://codex.mycred.me/shortcodes/mycred_link/
14
- * @since 1.1
15
- * @version 1.4
16
- */
17
- if ( ! function_exists( 'mycred_render_shortcode_link' ) ) :
18
- function mycred_render_shortcode_link( $atts, $link_title = '' ) {
19
-
20
- global $mycred_link_points;
21
-
22
- $atts = shortcode_atts( array(
23
- 'id' => '',
24
- 'rel' => '',
25
- 'class' => '',
26
- 'href' => '',
27
- 'title' => '',
28
- 'target' => '',
29
- 'style' => '',
30
- 'amount' => 0,
31
- 'ctype' => MYCRED_DEFAULT_TYPE_KEY,
32
- 'hreflang' => '',
33
- 'media' => '',
34
- 'type' => '',
35
- 'onclick' => ''
36
- ), $atts );
37
-
38
- // Make sure point type exists
39
- if ( ! mycred_point_type_exists( $atts['ctype'] ) )
40
- $atts['ctype'] = MYCRED_DEFAULT_TYPE_KEY;
41
-
42
- // HREF is required
43
- if ( empty( $atts['href'] ) )
44
- $atts['href'] = '#';
45
-
46
- // All links must contain the 'mycred-points-link' class
47
- if ( empty( $atts['class'] ) )
48
- $atts['class'] = 'mycred-points-link';
49
- else
50
- $atts['class'] = 'mycred-points-link ' . $atts['class'];
51
-
52
- // If no id exists, make one
53
- if ( empty( $atts['id'] ) ) {
54
- $id = str_replace( array( 'http://', 'https://', 'http%3A%2F%2F', 'https%3A%2F%2F' ), 'hs', $atts['href'] );
55
- $id = str_replace( array( '/', '-', '_', ':', '.', '?', '=', '+', '\\', '%2F' ), '', $id );
56
- $atts['id'] = $id;
57
- }
58
-
59
- // Construct anchor attributes
60
- $attr = array();
61
- foreach ( $atts as $attribute => $value ) {
62
- if ( ! empty( $value ) && ! in_array( $attribute, array( 'amount', 'ctype' ) ) ) {
63
- $attr[] = $attribute . '="' . $value . '"';
64
- }
65
- }
66
-
67
- // Add point type as a data attribute
68
- $attr[] = 'data-type="' . esc_attr( $atts['ctype'] ) . '"';
69
-
70
- // Only usable for members
71
- if ( is_user_logged_in() ) {
72
-
73
- // If amount is zero, use the amount we set in the hooks settings
74
- if ( $atts['amount'] == 0 ) {
75
-
76
- // Get hook settings
77
- $hooks = mycred_get_option( 'mycred_pref_hooks', false );
78
- if ( $atts['ctype'] != MYCRED_DEFAULT_TYPE_KEY )
79
- $hooks = mycred_get_option( 'mycred_pref_hooks_' . sanitize_key( $atts['ctype'] ), false );
80
-
81
- // Apply points value
82
- if ( $hooks !== false && is_array( $hooks ) && array_key_exists( 'link_click', $hooks['hook_prefs'] ) ) {
83
- $atts['amount'] = $hooks['hook_prefs']['link_click']['creds'];
84
- }
85
-
86
- }
87
-
88
- // Add key
89
- $token = mycred_create_token( array( $atts['amount'], $atts['ctype'], $atts['id'], urlencode( $atts['href'] ) ) );
90
- $attr[] = 'data-token="' . $token . '"';
91
-
92
- // Make sure jQuery script is called
93
- $mycred_link_points = true;
94
-
95
- }
96
-
97
- // Return result
98
- return apply_filters( 'mycred_link', '<a ' . implode( ' ', $attr ) . '>' . do_shortcode( $link_title ) . '</a>', $atts, $link_title );
99
-
100
- }
101
- endif;
102
- add_shortcode( 'mycred_link', 'mycred_render_shortcode_link' );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
includes/shortcodes/mycred_my_balance.php DELETED
@@ -1,79 +0,0 @@
1
- <?php
2
- if ( ! defined( 'myCRED_VERSION' ) ) exit;
3
-
4
- /**
5
- * myCRED Shortcode: my_balance
6
- * Returns the current users balance.
7
- * @see http://codex.mycred.me/shortcodes/mycred_my_balance/
8
- * @since 1.0.9
9
- * @version 1.3
10
- */
11
- if ( ! function_exists( 'mycred_render_shortcode_my_balance' ) ) :
12
- function mycred_render_shortcode_my_balance( $atts, $content = '' ) {
13
-
14
- extract( shortcode_atts( array(
15
- 'user_id' => 'current',
16
- 'title' => '',
17
- 'title_el' => 'h1',
18
- 'balance_el' => 'div',
19
- 'wrapper' => 1,
20
- 'formatted' => 1,
21
- 'type' => MYCRED_DEFAULT_TYPE_KEY
22
- ), $atts ) );
23
-
24
- $output = '';
25
-
26
- // Not logged in
27
- if ( ! is_user_logged_in() && $user_id == 'current' )
28
- return $content;
29
-
30
- // Get user ID
31
- $user_id = mycred_get_user_id( $user_id );
32
-
33
- // Make sure we have a valid point type
34
- if ( ! mycred_point_type_exists( $type ) )
35
- $type = MYCRED_DEFAULT_TYPE_KEY;
36
-
37
- // Get the users myCRED account object
38
- $account = mycred_get_account( $user_id );
39
- if ( $account === false ) return;
40
-
41
- // Check for exclusion
42
- if ( empty( $account->balance ) || ! array_key_exists( $type, $account->balance ) ) return;
43
-
44
- $balance = $account->balance[ $type ];
45
-
46
- if ( $wrapper )
47
- $output .= '<div class="mycred-my-balance-wrapper">';
48
-
49
- // Title
50
- if ( ! empty( $title ) ) {
51
- if ( ! empty( $title_el ) )
52
- $output .= '<' . $title_el . '>';
53
-
54
- $output .= $title;
55
-
56
- if ( ! empty( $title_el ) )
57
- $output .= '</' . $title_el . '>';
58
- }
59
-
60
- // Balance
61
- if ( ! empty( $balance_el ) )
62
- $output .= '<' . $balance_el . '>';
63
-
64
- if ( $formatted )
65
- $output .= $balance->type->format( $balance->current );
66
- else
67
- $output .= $balance->type->number( $balance->current );
68
-
69
- if ( ! empty( $balance_el ) )
70
- $output .= '</' . $balance_el . '>';
71
-
72
- if ( $wrapper )
73
- $output .= '</div>';
74
-
75
- return $output;
76
-
77
- }
78
- endif;
79
- add_shortcode( 'mycred_my_balance', 'mycred_render_shortcode_my_balance' );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
includes/shortcodes/mycred_send.php DELETED
@@ -1,163 +0,0 @@
1
- <?php
2
- if ( ! defined( 'myCRED_VERSION' ) ) exit;
3
-
4
- /**
5
- * myCRED Shortcode: mycred_send
6
- * This shortcode allows the current user to send a pre-set amount of points
7
- * to a pre-set user. A simpler version of the mycred_transfer shortcode.
8
- * @see http://codex.mycred.me/shortcodes/mycred_send/
9
- * @since 1.1
10
- * @version 1.3.1
11
- */
12
- if ( ! function_exists( 'mycred_render_shortcode_send' ) ) :
13
- function mycred_render_shortcode_send( $atts, $content = '' ) {
14
-
15
- if ( ! is_user_logged_in() ) return;
16
-
17
- extract( shortcode_atts( array(
18
- 'amount' => 0,
19
- 'to' => '',
20
- 'log' => '',
21
- 'ref' => 'gift',
22
- 'type' => MYCRED_DEFAULT_TYPE_KEY,
23
- 'class' => 'button button-primary btn btn-primary',
24
- 'reload' => 0
25
- ), $atts ) );
26
-
27
- if ( ! mycred_point_type_exists( $type ) ) return 'Point type not found.';
28
-
29
- global $post;
30
-
31
- // Send points to the post author (assuming this shortcode is used inside the loop)
32
- $to = mycred_get_user_id( $to );
33
-
34
- // We will not render for ourselves.
35
- $user_id = get_current_user_id();
36
- $recipient = absint( $to );
37
- if ( $recipient === $user_id || $recipient === 0 ) return;
38
-
39
- global $mycred_sending_points;
40
-
41
- $mycred_sending_points = false;
42
-
43
- $mycred = mycred( $type );
44
-
45
- // Make sure current user or recipient is not excluded!
46
- if ( $mycred->exclude_user( $recipient ) || $mycred->exclude_user( $user_id ) ) return;
47
-
48
- $account_limit = $mycred->number( apply_filters( 'mycred_transfer_acc_limit', 0 ) );
49
- $balance = $mycred->get_users_balance( $user_id, $type );
50
- $amount = $mycred->number( $amount );
51
-
52
- // Insufficient Funds
53
- if ( $balance-$amount < $account_limit ) return;
54
-
55
- // We are ready!
56
- $mycred_sending_points = true;
57
-
58
- if ( $class != '' )
59
- $class = ' ' . sanitize_text_field( $class );
60
-
61
- $reload = absint( $reload );
62
-
63
- $render = '<button type="button" class="mycred-send-points-button btn btn-primary' . $class . '" data-reload="' . $reload . '" data-to="' . $recipient . '" data-ref="' . esc_attr( $ref ) . '" data-log="' . esc_attr( $log ) . '" data-amount="' . $amount . '" data-type="' . esc_attr( $type ) . '">' . $mycred->template_tags_general( $content ) . '</button>';
64
-
65
- return apply_filters( 'mycred_send', $render, $atts, $content );
66
-
67
- }
68
- endif;
69
- add_shortcode( 'mycred_send', 'mycred_render_shortcode_send' );
70
-
71
- /**
72
- * myCRED Send Points Ajax
73
- * @since 0.1
74
- * @version 1.4.1
75
- */
76
- if ( ! function_exists( 'mycred_shortcode_send_points_ajax' ) ) :
77
- function mycred_shortcode_send_points_ajax() {
78
-
79
- // Security
80
- check_ajax_referer( 'mycred-send-points', 'token' );
81
-
82
- $user_id = get_current_user_id();
83
-
84
- if ( mycred_force_singular_session( $user_id, 'mycred-last-send' ) )
85
- wp_send_json( 'error' );
86
-
87
- $point_type = MYCRED_DEFAULT_TYPE_KEY;
88
- if ( isset( $_POST['type'] ) )
89
- $point_type = sanitize_text_field( $_POST['type'] );
90
-
91
- // Make sure the type exists
92
- if ( ! mycred_point_type_exists( $point_type ) ) die();
93
-
94
- // Prep
95
- $recipient = (int) sanitize_text_field( $_POST['recipient'] );
96
- $reference = sanitize_text_field( $_POST['reference'] );
97
- $log_entry = strip_tags( trim( $_POST['log'] ), '<a>' );
98
-
99
- // No sending to ourselves
100
- if ( $user_id == $recipient )
101
- wp_send_json( 'error' );
102
-
103
- // Prep amount
104
- $mycred = mycred( $point_type );
105
- $amount = sanitize_text_field( $_POST['amount'] );
106
- $amount = $mycred->number( abs( $amount ) );
107
-
108
- // Check solvency
109
- $account_limit = $mycred->number( apply_filters( 'mycred_transfer_acc_limit', $mycred->zero() ) );
110
- $balance = $mycred->get_users_balance( $user_id, $point_type );
111
- $new_balance = $balance-$amount;
112
-
113
- // Insufficient Funds
114
- if ( $new_balance < $account_limit )
115
- die();
116
-
117
- // After this transfer our account will reach zero
118
- elseif ( $new_balance == $account_limit )
119
- $reply = 'zero';
120
-
121
- // Check if this is the last time we can do these kinds of amounts
122
- elseif ( $new_balance-$amount < $account_limit )
123
- $reply = 'minus';
124
-
125
- // Else everything is fine
126
- else
127
- $reply = 'done';
128
-
129
- $data = array( 'ref_type' => 'user' );
130
-
131
- // First deduct points
132
- if ( $mycred->add_creds(
133
- $reference,
134
- $user_id,
135
- 0 - $amount,
136
- $log_entry,
137
- $recipient,
138
- $data,
139
- $point_type
140
- ) ) {
141
-
142
- // Then add to recipient
143
- $mycred->add_creds(
144
- $reference,
145
- $recipient,
146
- $amount,
147
- $log_entry,
148
- $user_id,
149
- $data,
150
- $point_type
151
- );
152
-
153
- }
154
- else {
155
- $reply = 'error';
156
- }
157
-
158
- // Share the good news
159
- wp_send_json( $reply );
160
-
161
- }
162
- endif;
163
- add_action( 'wp_ajax_mycred-send-points', 'mycred_shortcode_send_points_ajax' );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
includes/shortcodes/mycred_show_if.php DELETED
@@ -1,122 +0,0 @@
1
- <?php
2
- if ( ! defined( 'myCRED_VERSION' ) ) exit;
3
-
4
- /**
5
- * Show IF
6
- * Allows content to be hidden if a user does not fulfil the set points
7
- * requirements set for this shortcode.
8
- * @since 1.7
9
- * @version 1.0
10
- */
11
- if ( ! function_exists( 'mycred_render_shortcode_show_if' ) ) :
12
- function mycred_render_shortcode_show_if( $atts, $content = '' ) {
13
-
14
- extract( shortcode_atts( array(
15
- 'balance' => -1,
16
- 'rank' => -1,
17
- 'ref' => '',
18
- 'count' => -1,
19
- 'ctype' => MYCRED_DEFAULT_TYPE_KEY,
20
- 'visitors' => '',
21
- 'comp' => 'AND',
22
- 'user_id' => 'current'
23
- ), $atts ) );
24
-
25
- // Visitors
26
- if ( ! is_user_logged_in() ) {
27
-
28
- if ( $visitors != '' ) return $visitors;
29
-
30
- return;
31
-
32
- }
33
-
34
- // Get the user ID
35
- $user_id = mycred_get_user_id( $user_id );
36
-
37
- // You can only use AND or OR for comparisons
38
- if ( ! in_array( $comp, array( 'AND', 'OR' ) ) )
39
- $comp = 'AND';
40
-
41
- // Make sure the point type we nominated exists
42
- if ( ! mycred_point_type_exists( $ctype ) ) return 'invalid point type';
43
-
44
- // Load myCRED with the requested point type
45
- $mycred = mycred( $ctype );
46
-
47
- // Make sure user is not excluded
48
- if ( $mycred->exclude_user( $user_id ) ) return;
49
-
50
- // Lets start determening if the user can see the content
51
- $should_show = false;
52
-
53
- // Balance related requirement
54
- if ( $balance >= 0 ) {
55
-
56
- $users_balance = $mycred->get_users_balance( $user_id, $ctype );
57
- $balance = $mycred->number( $balance );
58
-
59
- // Zero balance requirement
60
- if ( $balance == $mycred->zero() && $users_balance == $mycred->zero() )
61
- $should_show = true;
62
-
63
- // Balance must be higher or equal to the amount set
64
- elseif ( $users_balance >= $balance )
65
- $should_show = true;
66
-
67
- }
68
-
69
- // Reference related requirement
70
- if ( strlen( $ref ) > 0 ) {
71
-
72
- $ref_count = mycred_count_ref_instances( $ref, $user_id, $ctype );
73
-
74
- // Combined with a balance requirement we must have references
75
- if ( $balance >= 0 && $ref_count == 0 && $comp === 'AND' )
76
- $should_show = false;
77
-
78
- // Ref count must be higher or equal to the count set
79
- elseif ( $ref_count >= $count )
80
- $should_show = true;
81
-
82
- }
83
-
84
- // Rank related requirement
85
- if ( $rank !== -1 && function_exists( 'mycred_get_users_rank' ) ) {
86
-
87
- $rank_id = mycred_get_rank_object_id( $rank );
88
-
89
- // Rank ID provided
90
- if ( is_numeric( $rank ) )
91
- $users_rank = mycred_get_users_rank( $user_id, $ctype );
92
-
93
- // Rank title provided
94
- else
95
- $users_rank = mycred_get_users_rank( $user_id, $ctype );
96
-
97
- if ( isset( $users_rank->post_id ) && $rank_id !== false ) {
98
-
99
- if ( $users_rank->post_id != $rank_id && $comp === 'AND' )
100
- $should_show = false;
101
-
102
- elseif ( $users_rank->post_id == $rank_id )
103
- $should_show = true;
104
-
105
- }
106
-
107
- }
108
-
109
- // Allow others to play
110
- $should_show = apply_filters( 'mycred_show_if', $should_show, $user_id, $atts, $content );
111
-
112
- // Sorry, no show
113
- if ( $should_show !== true ) return;
114
-
115
- $content = '<div class="mycred-show-this-content">' . $content . '</div>';
116
-
117
- // Return content
118
- return do_shortcode( apply_filters( 'mycred_show_if_render', $content, $user_id, $atts, $content ) );
119
-
120
- }
121
- endif;
122
- add_shortcode( 'mycred_show_if', 'mycred_render_shortcode_show_if' );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
includes/shortcodes/mycred_total_balance.php DELETED
@@ -1,83 +0,0 @@
1
- <?php
2
- if ( ! defined( 'myCRED_VERSION' ) ) exit;
3
-
4
- /**
5
- * myCRED Shortcode: mycred_total_balance
6
- * This shortcode will return either the current user or a given users
7
- * total balance based on either all point types or a comma seperated list
8
- * of types.
9
- * @see http://codex.mycred.me/shortcodes/mycred_total_balance/
10
- * @since 1.4.3
11
- * @version 1.2.2
12
- */
13
- if ( ! function_exists( 'mycred_render_shortcode_total' ) ) :
14
- function mycred_render_shortcode_total( $atts, $content = '' ) {
15
-
16
- extract( shortcode_atts( array(
17
- 'user_id' => 'current',
18
- 'types' => MYCRED_DEFAULT_TYPE_KEY,
19
- 'raw' => 0,
20
- 'total' => 0
21
- ), $atts ) );
22
-
23
- // If user ID is not set, get the current users ID
24
- if ( ! is_user_logged_in() && $user_id == 'current' )
25
- return $content;
26
-
27
- $user_id = mycred_get_user_id( $user_id );
28
-
29
- // Get types
30
- $types_to_addup = array();
31
- $all = false;
32
- $existing_types = mycred_get_types();
33
-
34
- if ( $types == 'all' )
35
- $types_to_addup = array_keys( $existing_types );
36
-
37
- else {
38
-
39
- $types = explode( ',', $types );
40
- if ( ! empty( $types ) ) {
41
- foreach ( $types as $type_key ) {
42
- $type_key = sanitize_text_field( $type_key );
43
- if ( ! array_key_exists( $type_key, $existing_types ) ) continue;
44
-
45
- if ( ! in_array( $type_key, $types_to_addup ) )
46
- $types_to_addup[] = $type_key;
47
- }
48
- }
49
-
50
- }
51
-
52
- // In case we still have no types, we add the default one
53
- if ( empty( $types_to_addup ) )
54
- $types_to_addup = array( MYCRED_DEFAULT_TYPE_KEY );
55
-
56
- // Add up all point type balances
57
- $total_balance = 0;
58
- foreach ( $types_to_addup as $type ) {
59
-
60
- // Get the balance for this type
61
- $mycred = mycred( $type );
62
- if ( $total == 1 )
63
- $balance = mycred_query_users_total( $user_id, $type );
64
- else
65
- $balance = $mycred->get_users_balance( $user_id, $type );
66
-
67
- $total_balance = $total_balance+$balance;
68
-
69
- }
70
-
71
- // If results should be formatted
72
- if ( $raw == 0 ) {
73
-
74
- $mycred = mycred();
75
- $total_balance = $mycred->format_number( $total_balance );
76
-
77
- }
78
-
79
- return apply_filters( 'mycred_total_balances_output', $total_balance, $atts );
80
-
81
- }
82
- endif;
83
- add_shortcode( 'mycred_total_balance', 'mycred_render_shortcode_total' );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
includes/shortcodes/mycred_total_points.php DELETED
@@ -1,91 +0,0 @@
1
- <?php
2
- if ( ! defined( 'myCRED_VERSION' ) ) exit;
3
-
4
- /**
5
- * Total Points
6
- * Allows to show total points of a specific point type or add up
7
- * points from the log based on reference, reference id or user id.
8
- * @since 1.6.6
9
- * @version 1.1.2
10
- */
11
- if ( ! function_exists( 'mycred_render_shortcode_total_points' ) ) :
12
- function mycred_render_shortcode_total_points( $atts ) {
13
-
14
- extract( shortcode_atts( array(
15
- 'type' => MYCRED_DEFAULT_TYPE_KEY,
16
- 'ref' => '',
17
- 'ref_id' => '',
18
- 'user_id' => 'current',
19
- 'formatted' => 1
20
- ), $atts ) );
21
-
22
- if ( ! mycred_point_type_exists( $type ) )
23
- $type = MYCRED_DEFAULT_TYPE_KEY;
24
-
25
- $user_id = mycred_get_user_id( $user_id );
26
- $mycred = mycred( $type );
27
-
28
- global $wpdb;
29
-
30
- // Simple
31
- if ( $ref == '' && $ref_id == '' && $user_id == '' ) {
32
-
33
- // Add up all balances
34
- $total = $wpdb->get_var( $wpdb->prepare( "SELECT SUM( meta_value ) FROM {$wpdb->usermeta} WHERE meta_key = %s", mycred_get_meta_key( $type ) ) );
35
-
36
- }
37
-
38
- // Complex
39
- else {
40
-
41
- $wheres = array();
42
- $wheres[] = $wpdb->prepare( "ctype = %s", mycred_get_meta_key( $type ) );
43
-
44
- if ( strlen( $ref ) > 0 ) {
45
-
46
- // Either we have just one reference
47
- $multiple = explode( ',', $ref );
48
- if ( count( $multiple ) == 1 )
49
- $wheres[] = $wpdb->prepare( "ref = %s", $ref );
50
-
51
- // Or a comma seperated list of references
52
- else {
53
-
54
- $_clean = array();
55
- foreach ( $multiple as $ref ) {
56
- $ref = sanitize_key( $ref );
57
- if ( strlen( $ref ) > 0 )
58
- $_clean[] = $ref;
59
- }
60
-
61
- if ( ! empty( $_clean ) )
62
- $wheres[] = "ref IN ( '" . implode( "', '", $_clean ) . "' )";
63
-
64
- }
65
-
66
- }
67
-
68
- $ref_id = absint( $ref_id );
69
- if ( $ref_id > 0 )
70
- $wheres[] = $wpdb->prepare( "ref_id = %d", $ref_id );
71
-
72
- $user_id = absint( $user_id );
73
- if ( $user_id != '' && $user_id != 0 )
74
- $wheres[] = $wpdb->prepare( "user_id = %d", $user_id );
75
-
76
- $wheres = implode( " AND ", $wheres );
77
- $total = $wpdb->get_var( "SELECT SUM( creds ) FROM {$mycred->log_table} WHERE {$wheres};" );
78
-
79
- }
80
-
81
- if ( $total === NULL )
82
- $total = 0;
83
-
84
- if ( $formatted == 1 )
85
- return $mycred->format_creds( $total );
86
-
87
- return $total;
88
-
89
- }
90
- endif;
91
- add_shortcode( 'mycred_total_points', 'mycred_render_shortcode_total_points' );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
includes/shortcodes/mycred_total_since.php DELETED
@@ -1,38 +0,0 @@
1
- <?php
2
- if ( ! defined( 'myCRED_VERSION' ) ) exit;
3
-
4
- /**
5
- * Total Since
6
- * Shows the total number of points a user has gained / lost in a given timeframe.
7
- * @since 1.7
8
- * @version 1.0.1
9
- */
10
- if ( ! function_exists( 'mycred_render_shortcode_total_since' ) ) :
11
- function mycred_render_shortcode_total_since( $atts, $content = '' ) {
12
-
13
- extract( shortcode_atts( array(
14
- 'from' => 'today',
15
- 'until' => 'now',
16
- 'type' => MYCRED_DEFAULT_TYPE_KEY,
17
- 'ref' => '',
18
- 'user_id' => 'current',
19
- 'formatted' => 1
20
- ), $atts ) );
21
-
22
- if ( ! mycred_point_type_exists( $type ) )
23
- $type = MYCRED_DEFAULT_TYPE_KEY;
24
-
25
- if ( $ref == '' ) $ref = NULL;
26
-
27
- $user_id = mycred_get_user_id( $user_id );
28
- $mycred = mycred( $type );
29
- $total = mycred_get_total_by_time( $from, $until, $ref, $user_id, $type );
30
-
31
- if ( substr( $total, 0, 7 ) != 'Invalid' && $formatted == 1 )
32
- $total = $mycred->format_creds( $total );
33
-
34
- return $total;
35
-
36
- }
37
- endif;
38
- add_shortcode( 'mycred_total_since', 'mycred_render_shortcode_total_since' );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
includes/shortcodes/mycred_video.php DELETED
@@ -1,107 +0,0 @@
1
- <?php
2
- if ( ! defined( 'myCRED_VERSION' ) ) exit;
3
-
4
- /**
5
- * myCRED Shortcode: mycred_video
6
- * This shortcode allows points to be given to the current user
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' ) ) :
13
- function mycred_render_shortcode_video( $atts ) {
14
-
15
- global $mycred_video_points;
16
-
17
- extract( shortcode_atts( array(
18
- 'id' => NULL,
19
- 'width' => 560,
20
- 'height' => 315,
21
- 'amount' => '',
22
- 'logic' => '',
23
- 'interval' => '',
24
- 'ctype' => MYCRED_DEFAULT_TYPE_KEY
25
- ), $atts ) );
26
-
27
- $hooks = mycred_get_option( 'mycred_pref_hooks', false );
28
- if ( $ctype != MYCRED_DEFAULT_TYPE_KEY )
29
- $hooks = mycred_get_option( 'mycred_pref_hooks_' . sanitize_key( $ctype ), false );
30
-
31
- if ( $hooks === false || ! is_array( $hooks ) || ! array_key_exists( 'video_view', $hooks['hook_prefs'] ) ) return;
32
- $prefs = $hooks['hook_prefs']['video_view'];
33
-
34
- if ( $amount == '' )
35
- $amount = $prefs['creds'];
36
-
37
- if ( $logic == '' )
38
- $logic = $prefs['logic'];
39
-
40
- if ( $interval == '' )
41
- $interval = $prefs['interval'];
42
-
43
- // ID is required
44
- if ( $id === NULL || empty( $id ) ) return __( 'A video ID is required for this shortcode', 'mycred' );
45
-
46
- // Interval
47
- if ( strlen( $interval ) < 3 )
48
- $interval = abs( $interval * 1000 );
49
-
50
- // Video ID
51
- $video_id = str_replace( '-', '__', $id );
52
-
53
- // Create key
54
- $key = mycred_create_token( array( 'youtube', $video_id, $amount, $logic, $interval ) );
55
-
56
- if ( ! isset( $mycred_video_points ) || ! is_array( $mycred_video_points ) )
57
- $mycred_video_points = array();
58
-
59
- // Construct YouTube Query
60
- $query = apply_filters( 'mycred_video_query_youtube', array(
61
- 'enablejsapi' => 1,
62
- 'version' => 3,
63
- 'playerapiid' => 'mycred_vvideo_v' . $video_id,
64
- 'rel' => 0,
65
- 'controls' => 1,
66
- 'showinfo' => 0
67
- ), $atts, $video_id );
68
-
69
- if ( ! is_user_logged_in() )
70
- unset( $query['playerapiid'] );
71
-
72
- // Construct Youtube Query Address
73
- $url = 'https://www.youtube.com/embed/' . $id;
74
- $url = add_query_arg( $query, $url );
75
-
76
- $mycred_video_points[] = 'youtube';
77
-
78
- // Make sure video source ids are unique
79
- $mycred_video_points = array_unique( $mycred_video_points );
80
-
81
- ob_start();
82
-
83
- ?>
84
- <div class="row mycred-video-wrapper youtube-video">
85
- <div class="col-lg-12 col-md-12 col-sm-12 col-xs-12">
86
- <iframe id="mycred_vvideo_v<?php echo $video_id; ?>" class="mycred-video mycred-youtube-video" data-vid="<?php echo $video_id; ?>" src="<?php echo esc_url( $url ); ?>" width="<?php echo $width; ?>" height="<?php echo $height; ?>" frameborder="0" webkitallowfullscreen mozallowfullscreen allowfullscreen></iframe>
87
- </div>
88
- </div>
89
- <?php
90
-
91
- if ( is_user_logged_in() ) :
92
-
93
- ?>
94
- <script type="text/javascript">function mycred_vvideo_v<?php echo $video_id; ?>( state ) { duration[ "<?php echo $video_id; ?>" ] = state.target.getDuration(); mycred_view_video( "<?php echo $video_id; ?>", state.data, "<?php echo $logic; ?>", "<?php echo $interval; ?>", "<?php echo $key; ?>", "<?php echo $ctype; ?>" ); }</script>
95
- <?php
96
-
97
- endif;
98
-
99
- $output = ob_get_contents();
100
- ob_end_clean();
101
-
102
- // Return the shortcode output
103
- return apply_filters( 'mycred_video_output', $output, $atts );
104
-
105
- }
106
- endif;
107
- add_shortcode( 'mycred_video', 'mycred_render_shortcode_video' );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
lang/mycred-fr_FR.mo CHANGED
File without changes
lang/mycred-fr_FR.po CHANGED
File without changes
lang/mycred-ja_JP.mo DELETED
Binary file
lang/mycred-ja_JP.po DELETED
@@ -1,6413 +0,0 @@
1
- msgid ""
2
- msgstr ""
3
- "PO-Revision-Date: 2017-08-29 08:41+0000\n"
4
- "MIME-Version: 1.0\n"
5
- "Content-Type: text/plain; charset=UTF-8\n"
6
- "Content-Transfer-Encoding: 8bit\n"
7
- "Plural-Forms: nplurals=1; plural=0\n"
8
- "X-Generator: Loco - https://localise.biz/\n"
9
- "Language: ja-JP\n"
10
- "Project-Id-Version: Plugins - myCRED - Stable (latest release)\n"
11
- "Report-Msgid-Bugs-To: \n"
12
- "POT-Creation-Date: 2017-08-29 08:41+0000\n"
13
- "Last-Translator: mycredlabs <gabriel.s@merovingi.com>\n"
14
- "Language-Team: Japanese (Japan)"
15
-
16
- #: mycred.php:859 modules/mycred-module-management.php:558
17
- #: addons/transfer/includes/mycred-transfer-shortcodes.php:34
18
- msgid "Balance"
19
- msgstr ""
20
-
21
- #: modules/mycred-module-management.php:184
22
- msgid "Balance successfully updated"
23
- msgstr ""
24
-
25
- #: modules/mycred-module-management.php:189
26
- msgid "Request declined"
27
- msgstr ""
28
-
29
- #: modules/mycred-module-management.php:224
30
- msgid "No recent activity found."
31
- msgstr ""
32
-
33
- #: modules/mycred-module-management.php:280
34
- msgid "View complete history"
35
- msgstr ""
36
-
37
- #: modules/mycred-module-management.php:555
38
- msgid "Balances"
39
- msgstr ""
40
-
41
- #: modules/mycred-module-management.php:759
42
- msgid "Total Balance"
43
- msgstr ""
44
-
45
- #: modules/mycred-module-management.php:785
46
- msgid "Log under a custom reference"
47
- msgstr ""
48
-
49
- #: modules/mycred-module-management.php:791
50
- msgid "lowercase without empty spaces"
51
- msgstr ""
52
-
53
- #: modules/mycred-module-settings.php:431
54
- msgid "Export %singular% Balances"
55
- msgstr ""
56
-
57
- #: modules/mycred-module-settings.php:559 includes/mycred-setup.php:290
58
- msgid ""
59
- "These labels are used throughout the admin area and when presenting points "
60
- "to your users."
61
- msgstr ""
62
-
63
- #: modules/mycred-module-settings.php:591
64
- msgid "Set decimals to zero if you prefer to use whole numbers."
65
- msgstr ""
66
-
67
- #: modules/mycred-module-settings.php:604 includes/mycred-setup.php:332
68
- msgid "Point Editors"
69
- msgstr ""
70
-
71
- #: modules/mycred-module-settings.php:606 includes/mycred-setup.php:334
72
- msgid "The capability of users who can edit balances."
73
- msgstr ""
74
-
75
- #: modules/mycred-module-settings.php:611 includes/mycred-setup.php:339
76
- msgid "Point Administrators"
77
- msgstr ""
78
-
79
- #: modules/mycred-module-settings.php:613 includes/mycred-setup.php:341
80
- msgid "The capability of users who can edit settings."
81
- msgstr ""
82
-
83
- #: modules/mycred-module-settings.php:619 includes/mycred-setup.php:346
84
- msgid "Max. Amount"
85
- msgstr ""
86
-
87
- #: modules/mycred-module-settings.php:621 includes/mycred-setup.php:348
88
- msgid "The maximum amount allowed to be paid out in a single instance."
89
- msgstr ""
90
-
91
- #: modules/mycred-module-settings.php:626 includes/mycred-setup.php:353
92
- msgid "Exclude by User ID"
93
- msgstr ""
94
-
95
- #: modules/mycred-module-settings.php:628 includes/mycred-setup.php:355
96
- msgid "Comma separated list of user IDs to exclude from using this point type."
97
- msgstr ""
98
-
99
- #: modules/mycred-module-settings.php:632 includes/mycred-setup.php:359
100
- msgid "Exclude point editors"
101
- msgstr ""
102
-
103
- #: modules/mycred-module-settings.php:635 includes/mycred-setup.php:362
104
- msgid "Exclude point administrators"
105
- msgstr ""
106
-
107
- #: modules/mycred-module-settings.php:697
108
- msgid "Balance Meta Key"
109
- msgstr ""
110
-
111
- #: modules/mycred-module-settings.php:712
112
- msgid "Export Balances"
113
- msgstr ""
114
-
115
- #: modules/mycred-module-addons.php:197
116
- msgid ""
117
- "The <strong>buy</strong>CRED Add-on allows your users to buy points using "
118
- "PayPal, Skrill (Moneybookers) or NETbilling. <strong>buy</strong>CRED can "
119
- "also let your users buy points for other members."
120
- msgstr ""
121
-
122
- #: modules/mycred-module-addons.php:230
123
- msgid ""
124
- "Let your users pay using their <strong>my</strong>CRED points balance. "
125
- "Supported Carts: WooCommerce, MarketPress and WP E-Commerce. Supported Event "
126
- "Bookings: Event Espresso and Events Manager (free & pro)."
127
- msgstr ""
128
-
129
- #: modules/mycred-module-addons.php:253
130
- msgid ""
131
- "Create ranks for users reaching a certain number of %_plural% with the "
132
- "option to add logos for each rank."
133
- msgstr ""
134
-
135
- #: modules/mycred-module-log.php:215
136
- msgid "Invalid or empty reference"
137
- msgstr ""
138
-
139
- #: modules/mycred-module-log.php:220
140
- msgid "Log Entry cannot be empty"
141
- msgstr ""
142
-
143
- #: modules/mycred-module-log.php:241
144
- msgid "Could not save the new log entry"
145
- msgstr ""
146
-
147
- #: modules/mycred-module-log.php:262
148
- msgid "Log entry successfully updated"
149
- msgstr ""
150
-
151
- #: modules/mycred-module-log.php:307
152
- #, php-format
153
- msgid "1 Entry Deleted"
154
- msgid_plural "%d Entries Deleted"
155
- msgstr[0] ""
156
- msgstr[1] ""
157
-
158
- #: modules/mycred-module-log.php:466
159
- msgid "The log entry was successfully updated."
160
- msgstr ""
161
-
162
- #: modules/mycred-module-log.php:467
163
- msgid "The selected log entry could not be deleted."
164
- msgstr ""
165
-
166
- #: modules/mycred-module-log.php:501
167
- #, php-format
168
- msgctxt "e.g. Log entries from April 12th 2016"
169
- msgid "Log entries from %s"
170
- msgstr ""
171
-
172
- #: modules/mycred-module-log.php:911
173
- msgid "Original Entry"
174
- msgstr ""
175
-
176
- #: modules/mycred-module-log.php:923
177
- msgid "Delete Entry"
178
- msgstr ""
179
-
180
- #: modules/mycred-module-log.php:928
181
- msgid "Update Entry"
182
- msgstr ""
183
-
184
- #: modules/mycred-module-network.php:247
185
- msgid "I am sorry but your network is too big to use these features."
186
- msgstr ""
187
-
188
- #: modules/mycred-module-export.php:390
189
- msgid "Make both format options available."
190
- msgstr ""
191
-
192
- #: modules/mycred-module-export.php:439
193
- msgid ""
194
- "If enabled, users will only be able to export their own log entries! Export "
195
- "tools becomes available wherever you are using the mycred_history shortcode "
196
- "or in the users profile."
197
- msgstr ""
198
-
199
- #: modules/mycred-module-export.php:487
200
- msgid ""
201
- "Raw format should be used when you intend to use the export tool to backup "
202
- "or import entries in another installation. Formatted exports reflect what "
203
- "users see in their history archive."
204
- msgstr ""
205
-
206
- #: modules/mycred-module-buddypress.php:508
207
- msgid "The history page slug. Must be URL friendly."
208
- msgstr ""
209
-
210
- #: plugins/mycred-hook-invite-anyone.php:16
211
- msgid ""
212
- "Awards %_plural% for sending invitations and/or %_plural% if the invite is "
213
- "accepted."
214
- msgstr ""
215
-
216
- #: plugins/mycred-hook-wp-polls.php:16
217
- msgid "Awards %_plural% for users voting in polls."
218
- msgstr ""
219
-
220
- #: plugins/mycred-hook-wp-postratings.php:16
221
- msgid ""
222
- "Awards %_plural% for post ratings. Supports awarding %_plural% both to post "
223
- "author and the user rating."
224
- msgstr ""
225
-
226
- #: plugins/mycred-hook-wp-postratings.php:214
227
- #: plugins/mycred-hook-wp-favorite-posts.php:255
228
- msgid "Content Author Log Template"
229
- msgstr ""
230
-
231
- #: plugins/mycred-hook-gravityforms.php:16
232
- msgid "Awards %_plural% for successful form submissions."
233
- msgstr ""
234
-
235
- #: plugins/mycred-hook-simplepress.php:16
236
- msgid "Awards %_plural% for Simple:Press actions."
237
- msgstr ""
238
-
239
- #: plugins/mycred-hook-simplepress.php:315 plugins/mycred-hook-bbPress.php:508
240
- msgid "Deleted Topic"
241
- msgstr ""
242
-
243
- #: plugins/mycred-hook-buddypress.php:17
244
- msgid "Awards %_plural% for profile related actions."
245
- msgstr ""
246
-
247
- #: plugins/mycred-hook-buddypress.php:26
248
- msgid ""
249
- "Awards %_plural% for group related actions. Use minus to deduct %_plural% or "
250
- "zero to disable a specific hook."
251
- msgstr ""
252
-
253
- #: plugins/mycred-hook-buddypress.php:613
254
- msgid "New Profile Activity"
255
- msgstr ""
256
-
257
- #: plugins/mycred-hook-buddypress.php:637
258
- msgid "Deleted Profile Activity"
259
- msgstr ""
260
-
261
- #: plugins/mycred-hook-buddypress.php:661
262
- msgid "New Profile Avatar Upload"
263
- msgstr ""
264
-
265
- #: plugins/mycred-hook-buddypress.php:685
266
- msgid "New Profile Cover Upload"
267
- msgstr ""
268
-
269
- #: plugins/mycred-hook-buddypress.php:709
270
- msgid "New Friendships"
271
- msgstr ""
272
-
273
- #: plugins/mycred-hook-buddypress.php:735
274
- msgid ""
275
- "Users with zero balance can not add friends. Requires that you deduct "
276
- "%_plural% for adding a new friend."
277
- msgstr ""
278
-
279
- #: plugins/mycred-hook-buddypress.php:742
280
- msgid "Ending Friendships"
281
- msgstr ""
282
-
283
- #: plugins/mycred-hook-buddypress.php:802
284
- msgid "Favorite Activity"
285
- msgstr ""
286
-
287
- #: plugins/mycred-hook-buddypress.php:826
288
- msgid "Removing Favorit Activity"
289
- msgstr ""
290
-
291
- #: plugins/mycred-hook-buddypress.php:844
292
- msgid "New Private Message"
293
- msgstr ""
294
-
295
- #: plugins/mycred-hook-buddypress.php:1513
296
- msgid "No. of Members"
297
- msgstr ""
298
-
299
- #: plugins/mycred-hook-buddypress.php:1515
300
- msgid ""
301
- "The number of members a group must gain before awarding %_plural%. Use zero "
302
- "to award as soon as the group is created."
303
- msgstr ""
304
-
305
- #: plugins/mycred-hook-buddypress.php:1528
306
- msgid "Group Deletions"
307
- msgstr ""
308
-
309
- #: plugins/mycred-hook-buddypress.php:1546
310
- msgid "New Group Avatar Upload"
311
- msgstr ""
312
-
313
- #: plugins/mycred-hook-buddypress.php:1570
314
- msgid "New Group Cover Upload"
315
- msgstr ""
316
-
317
- #: plugins/mycred-hook-buddypress.php:1594
318
- msgid "New Forum Topics"
319
- msgstr ""
320
-
321
- #: plugins/mycred-hook-buddypress.php:1618
322
- msgid "Editing Forum Topics"
323
- msgstr ""
324
-
325
- #: plugins/mycred-hook-buddypress.php:1642
326
- msgid "New Forum Posts"
327
- msgstr ""
328
-
329
- #: plugins/mycred-hook-buddypress.php:1666
330
- msgid "Editing Forum Posts"
331
- msgstr ""
332
-
333
- #: plugins/mycred-hook-affiliatewp.php:293
334
- #: plugins/mycred-hook-affiliatewp.php:312
335
- #: addons/banking/services/mycred-service-payouts.php:768
336
- #: addons/banking/services/mycred-service-payouts.php:775
337
- msgid "Use zero to disable."
338
- msgstr ""
339
-
340
- #: plugins/mycred-hook-affiliatewp.php:338
341
- msgid "Pay a set amount"
342
- msgstr ""
343
-
344
- #: plugins/mycred-hook-affiliatewp.php:342
345
- msgid "All referrals will pay the same amount."
346
- msgstr ""
347
-
348
- #: plugins/mycred-hook-affiliatewp.php:348
349
- msgid "Pay the referral amount"
350
- msgstr ""
351
-
352
- #: plugins/mycred-hook-affiliatewp.php:350
353
- msgid "Points Currency Code"
354
- msgstr ""
355
-
356
- #: plugins/mycred-hook-affiliatewp.php:352
357
- msgid "Requires AffiliateWP and your store to use points as currency."
358
- msgstr ""
359
-
360
- #: plugins/mycred-hook-affiliatewp.php:358
361
- msgid "Apply an exchange rate"
362
- msgstr ""
363
-
364
- #: plugins/mycred-hook-events-manager-light.php:16
365
- msgid "Awards %_plural% for users attending events."
366
- msgstr ""
367
-
368
- #: plugins/mycred-hook-sharethis.php:16
369
- msgid ""
370
- "Awards %_plural% for users sharing / liking your website content to popular "
371
- "social media sites."
372
- msgstr ""
373
-
374
- #: plugins/mycred-hook-sharethis.php:257
375
- msgid "Publishing Posts"
376
- msgstr ""
377
-
378
- #: plugins/mycred-hook-buddypress-media.php:16
379
- msgid ""
380
- "Award / Deduct %_plural% for users creating albums or uploading new photos."
381
- msgstr ""
382
-
383
- #: plugins/mycred-hook-buddypress-media.php:362
384
- msgid "Photo Deletion"
385
- msgstr ""
386
-
387
- #: plugins/mycred-hook-buddypress-media.php:380
388
- msgid "Video Deletion"
389
- msgstr ""
390
-
391
- #: plugins/mycred-hook-buddypress-media.php:398
392
- msgid "Music Deletion"
393
- msgstr ""
394
-
395
- #: plugins/mycred-hook-wp-favorite-posts.php:16
396
- msgid "Awards %_plural% for users adding posts to their favorites."
397
- msgstr ""
398
-
399
- #: plugins/mycred-hook-contact-form7.php:16
400
- msgid "Awards %_plural% for successful form submissions (by logged in users)."
401
- msgstr ""
402
-
403
- #: plugins/mycred-hook-jetpack.php:16
404
- msgid ""
405
- "Awards %_plural% for users signing up for site or comment updates using "
406
- "Jetpack."
407
- msgstr ""
408
-
409
- #: plugins/mycred-hook-bbPress.php:457
410
- msgid "Deleting Forums"
411
- msgstr ""
412
-
413
- #: plugins/mycred-hook-bbPress.php:501
414
- msgid "Forum authors can receive %_plural% for creating new topics."
415
- msgstr ""
416
-
417
- #: plugins/mycred-hook-bbPress.php:526
418
- msgid "Adding Topic to Favorites"
419
- msgstr ""
420
-
421
- #: plugins/mycred-hook-bbPress.php:583
422
- msgid "Deleted Reply"
423
- msgstr ""
424
-
425
- #: plugins/mycred-hook-bbPress.php:605
426
- msgid "Show users %_plural% balance in replies"
427
- msgstr ""
428
-
429
- #: plugins/mycred-hook-bbPress.php:608
430
- msgid "Show users %_plural% balance in their bbPress profiles"
431
- msgstr ""
432
-
433
- #: plugins/mycred-hook-woocommerce.php:158
434
- msgid "Leave empty for no rewards"
435
- msgstr ""
436
-
437
- #: plugins/mycred-hook-woocommerce.php:389
438
- msgid ""
439
- "Awards %_plural% for users leaving reviews on your WooCommerce products."
440
- msgstr ""
441
-
442
- #: plugins/mycred-hook-badgeOS.php:317
443
- #, php-format
444
- msgid "Earning: %s"
445
- msgstr ""
446
-
447
- #: plugins/mycred-hook-badgeOS.php:335
448
- #, php-format
449
- msgid "Revoked: %s"
450
- msgstr ""
451
-
452
- #: includes/mycred-setup.php:106
453
- #, php-format
454
- msgid ""
455
- "Before you can begin using %s, you must setup your first point type. This "
456
- "includes what you want to call your points, how these points are presented "
457
- "and who has access to it."
458
- msgstr ""
459
-
460
- #: includes/mycred-setup.php:133
461
- msgid "Change Default Point Type Key"
462
- msgstr ""
463
-
464
- #: includes/mycred-setup.php:135
465
- msgid ""
466
- "You can change the meta key used to store the default point type using the "
467
- "MYCRED_DEFAULT_TYPE_KEY constant. Copy the above code to your wp-config.php "
468
- "file to use."
469
- msgstr ""
470
-
471
- #: includes/mycred-setup.php:136
472
- msgid ""
473
- "If you intend to change the default meta key, you should do so before "
474
- "continuing on in this setup!"
475
- msgstr ""
476
-
477
- #: includes/mycred-setup.php:141
478
- msgid ""
479
- "You can re-label myCRED using the MYCRED_DEFAULT_LABEL constant. Copy the "
480
- "above code to your wp-config.php file to use."
481
- msgstr ""
482
-
483
- #: includes/mycred-setup.php:155
484
- msgid "Processing ..."
485
- msgstr ""
486
-
487
- #: includes/mycred-setup.php:161
488
- msgid "Congratulations! You are now ready to use myCRED. What's next?"
489
- msgstr ""
490
-
491
- #: includes/mycred-setup.php:166
492
- msgid "Enabling Hooks"
493
- msgstr ""
494
-
495
- #: includes/mycred-setup.php:167
496
- msgid ""
497
- "If you intend to give your users points for interacting with your website "
498
- "automatically, your next step should be to enable and setup the hooks you "
499
- "want to use."
500
- msgstr ""
501
-
502
- #: includes/mycred-setup.php:168
503
- msgid "Setup Hooks"
504
- msgstr ""
505
-
506
- #: includes/mycred-setup.php:176
507
- msgid "Adjust Settings"
508
- msgstr ""
509
-
510
- #: includes/mycred-setup.php:177
511
- msgid ""
512
- "If you need to make further changes to your settings or add new point types, "
513
- "you can visit your default point type's settings."
514
- msgstr ""
515
-
516
- #: includes/mycred-setup.php:394 includes/mycred-setup.php:453
517
- msgid "Please make sure you fill out all required fields!"
518
- msgstr ""
519
-
520
- #: includes/mycred-widgets.php:22
521
- msgid "Show the current users balance and history."
522
- msgstr ""
523
-
524
- #: includes/mycred-widgets.php:192
525
- msgid "Balance Layout"
526
- msgstr ""
527
-
528
- #: includes/mycred-widgets.php:285
529
- msgid "Leaderboard based on instances or balances."
530
- msgstr ""
531
-
532
- #: includes/mycred-widgets.php:421
533
- msgid ""
534
- "Option to limit the leaderboard based on a specific timeframe. Leave empty "
535
- "if not used."
536
- msgstr ""
537
-
538
- #: includes/mycred-widgets.php:472
539
- msgid "Shows multiple balances."
540
- msgstr ""
541
-
542
- #: includes/importers/mycred-balances.php:117
543
- #: includes/importers/mycred-balances.php:144
544
- #: includes/importers/mycred-log-entries.php:117
545
- #: includes/importers/mycred-log-entries.php:142
546
- msgid "The file does not exist or could not be read."
547
- msgstr ""
548
-
549
- #: includes/importers/mycred-balances.php:220
550
- #: includes/importers/mycred-log-entries.php:204
551
- msgid ""
552
- "Invalid CSV file. Please consult the documentation for further assistance."
553
- msgstr ""
554
-
555
- #: includes/classes/class.query-export.php:263
556
- msgid "Reference ID"
557
- msgstr ""
558
-
559
- #: includes/classes/class.query-export.php:464
560
- msgid "Export log entries raw"
561
- msgstr ""
562
-
563
- #: includes/classes/class.query-export.php:465
564
- msgid "Export log entries formatted"
565
- msgstr ""
566
-
567
- #: includes/classes/class.query-export.php:482
568
- msgid "All Log Entries"
569
- msgstr ""
570
-
571
- #: includes/classes/class.query-export.php:492
572
- msgid "Users Log Entries"
573
- msgstr ""
574
-
575
- #: includes/classes/class.query-export.php:493
576
- msgid "Export History"
577
- msgstr ""
578
-
579
- #: includes/classes/class.query-log.php:1017
580
- msgid "Export Raw"
581
- msgstr ""
582
-
583
- #: includes/classes/class.query-log.php:1018
584
- msgid "Export Formatted"
585
- msgstr ""
586
-
587
- #: includes/classes/class.query-log.php:1072
588
- msgid "User ID, Username, Email or Nicename"
589
- msgstr ""
590
-
591
- #: includes/classes/class.query-log.php:1139
592
- msgid "Log entries navigation"
593
- msgstr ""
594
-
595
- #: includes/classes/class.query-log.php:1408
596
- #: includes/classes/class.query-log.php:1458
597
- msgid "Select all"
598
- msgstr ""
599
-
600
- #: includes/classes/class.query-log.php:1518
601
- msgid "Select entry"
602
- msgstr ""
603
-
604
- #: includes/classes/class.query-log.php:1563
605
- msgid "Filter by Date"
606
- msgstr ""
607
-
608
- #: includes/classes/class.query-log.php:1612
609
- msgid "Filter by User"
610
- msgstr ""
611
-
612
- #: includes/classes/class.query-log.php:1614
613
- msgid "Filter by ID"
614
- msgstr ""
615
-
616
- #: includes/classes/class.query-log.php:2200
617
- msgid "Profile Cover Upload"
618
- msgstr ""
619
-
620
- #: includes/classes/class.query-log.php:2205
621
- msgid "Add Activity to Favorites"
622
- msgstr ""
623
-
624
- #: includes/classes/class.query-log.php:2206
625
- msgid "Remove Activity from Favorites"
626
- msgstr ""
627
-
628
- #: includes/classes/class.query-log.php:2218
629
- msgid "New Group Cover"
630
- msgstr ""
631
-
632
- #: includes/classes/class.query-log.php:2281
633
- msgid "Recurring Payout"
634
- msgstr ""
635
-
636
- #: includes/classes/class.query-log.php:2285
637
- msgid "Badge Reward"
638
- msgstr ""
639
-
640
- #: includes/classes/class.query-log.php:2293
641
- msgid "buyCRED Purchase (Bank Transfer)"
642
- msgstr ""
643
-
644
- #: includes/classes/class.query-log.php:2327
645
- msgid "Content Purchase"
646
- msgstr ""
647
-
648
- #: includes/classes/class.query-log.php:2328
649
- msgid "Content Sale"
650
- msgstr ""
651
-
652
- #: addons/banking/myCRED-addon-banking.php:141
653
- msgid "Central Banking"
654
- msgstr ""
655
-
656
- #: addons/banking/myCRED-addon-banking.php:142
657
- msgid ""
658
- "Instead of creating %_plural% out of thin-air, all payouts are made from a "
659
- "nominated \"Central Bank\" account. Any %_plural% a user spends or loses are "
660
- "deposited back into this account. If the central bank runs out of %_plural%, "
661
- "no %_plural% will be paid out."
662
- msgstr ""
663
-
664
- #: addons/banking/myCRED-addon-banking.php:151
665
- msgid ""
666
- "Offer your users interest on the %_plural% they earn on your website. The "
667
- "interest is compounded daily."
668
- msgstr ""
669
-
670
- #: addons/banking/myCRED-addon-banking.php:202
671
- msgid "New Recurring Payout"
672
- msgstr ""
673
-
674
- #: addons/banking/myCRED-addon-banking.php:203
675
- msgid "Edit Recurring Payout"
676
- msgstr ""
677
-
678
- #: addons/banking/myCRED-addon-banking.php:205
679
- msgid "Please fill out all required fields that are highlighted in red."
680
- msgstr ""
681
-
682
- #: addons/banking/myCRED-addon-banking.php:206
683
- msgid "Are you sure you want to remove this schedule? This can not be undone!"
684
- msgstr ""
685
-
686
- #: addons/banking/myCRED-addon-banking.php:271
687
- msgid ""
688
- "This banking service uses the WordPress CRON to schedule events. If the "
689
- "WordPress CRON is disabled, this service will not work correctly."
690
- msgstr ""
691
-
692
- #: addons/transfer/myCRED-addon-transfer.php:177
693
- msgid "The selected point type can not be transferr